From: Hans de Goede <hdegoede@redhat.com>
To: Li Jun <jun.li@nxp.com>,
gregkh@linuxfoundation.org, robh+dt@kernel.org,
mark.rutland@arm.com, heikki.krogerus@linux.intel.com,
linux@roeck-us.net, rmfrfs@gmail.com, yueyao.zhu@gmail.com
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-imx@nxp.com
Subject: Re: [PATCH 1/5] usb: typec: tcpm: source pdo selection update
Date: Tue, 20 Mar 2018 13:26:31 +0100 [thread overview]
Message-ID: <adaf1af5-d8f4-6b8c-7258-3cb75bedc9ad@redhat.com> (raw)
In-Reply-To: <1521541570-25363-2-git-send-email-jun.li@nxp.com>
Hi,
On 20-03-18 11:26, Li Jun wrote:
> Instead of only compare between the same pdo type of sink and source,
> this patch update the source pdo selection by checking the source pdo
> voltage range is within that of sink.
>
> Signed-off-by: Li Jun <jun.li@nxp.com>
This patch applies on top of the broken reverted commit, but the
revert has already been merged by Linus:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/usb/typec?id=6f566af3462897fc743e3af6ea8cc790a13148ba
This commit is not in usb-next because it went into 4.16 as fix
after 4.16-rc1. As already mentioned in another rhread this needs
to be back-merged into usb-next.
So this needs to be respun to apply on top of the revert so that
it can be merged without issues with Torvald's tree later.
Regards,
Hans
> ---
> drivers/usb/typec/tcpm.c | 101 +++++++++++++++++------------------------------
> 1 file changed, 37 insertions(+), 64 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c
> index cd48a99..20f7ca8 100644
> --- a/drivers/usb/typec/tcpm.c
> +++ b/drivers/usb/typec/tcpm.c
> @@ -1765,7 +1765,9 @@ static int tcpm_pd_check_request(struct tcpm_port *port)
> static int tcpm_pd_select_pdo(struct tcpm_port *port, int *sink_pdo,
> int *src_pdo)
> {
> - unsigned int i, j, max_mw = 0, max_mv = 0, mw = 0, mv = 0, ma = 0;
> + unsigned int i, j, max_src_mv = 0, min_src_mv = 0, max_mw = 0,
> + max_mv = 0, src_mw = 0, src_ma = 0, max_snk_mv = 0,
> + min_snk_mv = 0;
> int ret = -EINVAL;
>
> /*
> @@ -1777,70 +1779,41 @@ static int tcpm_pd_select_pdo(struct tcpm_port *port, int *sink_pdo,
> enum pd_pdo_type type = pdo_type(pdo);
>
> if (type == PDO_TYPE_FIXED) {
> - for (j = 0; j < port->nr_fixed; j++) {
> - if (pdo_fixed_voltage(pdo) ==
> - pdo_fixed_voltage(port->snk_pdo[j])) {
> - ma = min_current(pdo, port->snk_pdo[j]);
> - mv = pdo_fixed_voltage(pdo);
> - mw = ma * mv / 1000;
> - if (mw > max_mw ||
> - (mw == max_mw && mv > max_mv)) {
> - ret = 0;
> - *src_pdo = i;
> - *sink_pdo = j;
> - max_mw = mw;
> - max_mv = mv;
> - }
> - /* There could only be one fixed pdo
> - * at a specific voltage level.
> - * So breaking here.
> - */
> - break;
> - }
> - }
> - } else if (type == PDO_TYPE_BATT) {
> - for (j = port->nr_fixed;
> - j < port->nr_fixed +
> - port->nr_batt;
> - j++) {
> - if (pdo_min_voltage(pdo) >=
> - pdo_min_voltage(port->snk_pdo[j]) &&
> - pdo_max_voltage(pdo) <=
> - pdo_max_voltage(port->snk_pdo[j])) {
> - mw = min_power(pdo, port->snk_pdo[j]);
> - mv = pdo_min_voltage(pdo);
> - if (mw > max_mw ||
> - (mw == max_mw && mv > max_mv)) {
> - ret = 0;
> - *src_pdo = i;
> - *sink_pdo = j;
> - max_mw = mw;
> - max_mv = mv;
> - }
> - }
> + max_src_mv = pdo_fixed_voltage(pdo);
> + min_src_mv = max_src_mv;
> + } else {
> + max_src_mv = pdo_max_voltage(pdo);
> + min_src_mv = pdo_min_voltage(pdo);
> + }
> +
> + if (type == PDO_TYPE_BATT) {
> + src_mw = pdo_max_power(pdo);
> + } else {
> + src_ma = pdo_max_current(pdo);
> + src_mw = src_ma * min_src_mv / 1000;
> + }
> +
> + for (j = 0; j < port->nr_snk_pdo; j++) {
> + pdo = port->snk_pdo[j];
> +
> + if (pdo_type(pdo) == PDO_TYPE_FIXED) {
> + min_snk_mv = pdo_fixed_voltage(pdo);
> + max_snk_mv = pdo_fixed_voltage(pdo);
> + } else {
> + min_snk_mv = pdo_min_voltage(pdo);
> + max_snk_mv = pdo_max_voltage(pdo);
> }
> - } else if (type == PDO_TYPE_VAR) {
> - for (j = port->nr_fixed +
> - port->nr_batt;
> - j < port->nr_fixed +
> - port->nr_batt +
> - port->nr_var;
> - j++) {
> - if (pdo_min_voltage(pdo) >=
> - pdo_min_voltage(port->snk_pdo[j]) &&
> - pdo_max_voltage(pdo) <=
> - pdo_max_voltage(port->snk_pdo[j])) {
> - ma = min_current(pdo, port->snk_pdo[j]);
> - mv = pdo_min_voltage(pdo);
> - mw = ma * mv / 1000;
> - if (mw > max_mw ||
> - (mw == max_mw && mv > max_mv)) {
> - ret = 0;
> - *src_pdo = i;
> - *sink_pdo = j;
> - max_mw = mw;
> - max_mv = mv;
> - }
> +
> + if (max_src_mv <= max_snk_mv &&
> + min_src_mv >= min_snk_mv) {
> + /* Prefer higher voltages if available */
> + if ((src_mw == max_mw && min_src_mv > max_mv) ||
> + src_mw > max_mw) {
> + *src_pdo = i;
> + *sink_pdo = j;
> + max_mw = src_mw;
> + max_mv = min_src_mv;
> + ret = 0;
> }
> }
> }
>
next prev parent reply other threads:[~2018-03-20 12:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-20 10:26 [PATCH 0/5] usb: typec: remove max_snk_* Li Jun
2018-03-20 10:26 ` [PATCH 1/5] usb: typec: tcpm: source pdo selection update Li Jun
2018-03-20 12:26 ` Hans de Goede [this message]
2018-03-21 11:13 ` Jun Li
2018-03-23 10:50 ` Jun Li
2018-03-20 10:26 ` [PATCH 2/5] usb: typec: fusb302: remove max_snk_* for sink config Li Jun
2018-03-20 12:29 ` Hans de Goede
2018-03-21 11:19 ` Jun Li
2018-03-21 12:16 ` Hans de Goede
2018-03-20 10:26 ` [PATCH 3/5] dt-bindings: usb: fusb302: remove max-sink-* properties Li Jun
2018-03-20 10:26 ` [PATCH 4/5] usb: typec: wcove: remove max_snk_* for sink config Li Jun
2018-03-20 10:26 ` [PATCH 5/5] usb: typec: tcpm: remove max_snk_mv/ma/mw Li Jun
2018-03-20 10:26 ` [PATCH 5/5] usb: typec: tcpm: remove max_snk_* Li Jun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adaf1af5-d8f4-6b8c-7258-3cb75bedc9ad@redhat.com \
--to=hdegoede@redhat.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jun.li@nxp.com \
--cc=linux-imx@nxp.com \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mark.rutland@arm.com \
--cc=rmfrfs@gmail.com \
--cc=robh+dt@kernel.org \
--cc=yueyao.zhu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).