RE: [PATCH 1/5] usb: typec: tcpm: source pdo selection update

2018-03-23 Thread Jun Li
Hi
> -Original Message-
> From: Jun Li
> Sent: 2018年3月21日 19:14
> To: Hans de Goede <hdego...@redhat.com>; gre...@linuxfoundation.org;
> robh...@kernel.org; mark.rutl...@arm.com;
> heikki.kroge...@linux.intel.com; li...@roeck-us.net; rmf...@gmail.com;
> yueyao@gmail.com
> Cc: linux-usb@vger.kernel.org; devicet...@vger.kernel.org; dl-linux-imx
> <linux-...@nxp.com>
> Subject: RE: [PATCH 1/5] usb: typec: tcpm: source pdo selection update
> 
> Hi
> > -Original Message-
> > From: Hans de Goede [mailto:hdego...@redhat.com]
> > Sent: 2018年3月20日 20:27
> > To: Jun Li <jun...@nxp.com>; gre...@linuxfoundation.org;
> > robh...@kernel.org; mark.rutl...@arm.com;
> > heikki.kroge...@linux.intel.com; li...@roeck-us.net; rmf...@gmail.com;
> > yueyao@gmail.com
> > Cc: linux-usb@vger.kernel.org; devicet...@vger.kernel.org;
> > dl-linux-imx <linux-...@nxp.com>
> > Subject: Re: [PATCH 1/5] usb: typec: tcpm: source pdo selection update
> >
> > 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...@nxp.com>
> >
> > This patch applies on top of the broken reverted commit, but the
> > revert has already been merged by Linus:
> >
> > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit
> > .ke
> >
> rnel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2
> >
> Fcommit%2Fdrivers%2Fusb%2Ftypec%3Fid%3D6f566af3462897fc743e3af6ea
> >
> 8cc790a13148ba=02%7C01%7Cjun.li%40nxp.com%7C188f2cdfa5eb44af
> >
> d27808d58e5dd13c%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> >
> C636571455959361056=CjnsG0rxIfJnm0K2tQyDbFxIP4Als%2BTT243Fh
> > y7UYyI%3D=0
> >
> > 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.

What's the proper way to do this, should I re-post the original reverted
patch and my update one based on it(so 2 patches), or just a combination
(one patch)?

Jun
> 
> OK, I will do the rebase in v2.
> 
> Thanks
> Jun


RE: [PATCH 1/5] usb: typec: tcpm: source pdo selection update

2018-03-21 Thread Jun Li
Hi
> -Original Message-
> From: Hans de Goede [mailto:hdego...@redhat.com]
> Sent: 2018年3月20日 20:27
> To: Jun Li <jun...@nxp.com>; gre...@linuxfoundation.org;
> robh...@kernel.org; mark.rutl...@arm.com;
> heikki.kroge...@linux.intel.com; li...@roeck-us.net; rmf...@gmail.com;
> yueyao@gmail.com
> Cc: linux-usb@vger.kernel.org; devicet...@vger.kernel.org; dl-linux-imx
> <linux-...@nxp.com>
> Subject: Re: [PATCH 1/5] usb: typec: tcpm: source pdo selection update
> 
> 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...@nxp.com>
> 
> This patch applies on top of the broken reverted commit, but the revert has
> already been merged by Linus:
> 
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.ke
> rnel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2
> Fcommit%2Fdrivers%2Fusb%2Ftypec%3Fid%3D6f566af3462897fc743e3af6ea
> 8cc790a13148ba=02%7C01%7Cjun.li%40nxp.com%7C188f2cdfa5eb44af
> d27808d58e5dd13c%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> C636571455959361056=CjnsG0rxIfJnm0K2tQyDbFxIP4Als%2BTT243Fh
> y7UYyI%3D=0
> 
> 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.

OK, I will do the rebase in v2.

Thanks
Jun


Re: [PATCH 1/5] usb: typec: tcpm: source pdo selection update

2018-03-20 Thread Hans de Goede

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 


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);
+