From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jun Li Subject: RE: [PATCH 04/21] usb: chipidea: Only read/write OTGSC from one place Date: Mon, 27 Jun 2016 08:04:39 +0000 Message-ID: References: <20160626072838.28082-1-stephen.boyd@linaro.org> <20160626072838.28082-5-stephen.boyd@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT Return-path: In-Reply-To: <20160626072838.28082-5-stephen.boyd@linaro.org> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Stephen Boyd , "linux-usb@vger.kernel.org" Cc: "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-arm-msm@vger.kernel.org" , Andy Gross , Bjorn Andersson , Neil Armstrong , Arnd Bergmann , Felipe Balbi , Peter Chen , Greg Kroah-Hartman , "Ivan T. Ivanov" List-Id: linux-arm-msm@vger.kernel.org Hi > -----Original Message----- > From: linux-usb-owner@vger.kernel.org [mailto:linux-usb- > owner@vger.kernel.org] On Behalf Of Stephen Boyd > Sent: Sunday, June 26, 2016 3:28 PM > To: linux-usb@vger.kernel.org > Cc: linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; > linux-arm-msm@vger.kernel.org; Andy Gross ; Bjorn > Andersson ; Neil Armstrong > ; Arnd Bergmann ; Felipe Balbi > ; Peter Chen ; Greg Kroah-Hartman > ; Ivan T. Ivanov > Subject: [PATCH 04/21] usb: chipidea: Only read/write OTGSC from one place > > With the id and vbus detection done via extcon we need to make sure we > poll the status of OTGSC properly by considering what the extcon is saying, > and not just what the register is saying. Let's move this hw_wait_reg() > function to the only place it's used and simplify it for polling the OTGSC > register. Then we can make certain we only use the hw_read_otgsc() API to > read OTGSC, which will make sure we properly handle extcon events. > > Cc: Peter Chen > Cc: Greg Kroah-Hartman > Cc: "Ivan T. Ivanov" > Fixes: 3ecb3e09b042 ("usb: chipidea: Use extcon framework for VBUS and ID > detect") > Signed-off-by: Stephen Boyd > --- > drivers/usb/chipidea/core.c | 32 -------------------------------- > drivers/usb/chipidea/otg.c | 35 +++++++++++++++++++++++++++++++---- > 2 files changed, 31 insertions(+), 36 deletions(-) > > diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c > index 69426e644d17..01390e02ee53 100644 > --- a/drivers/usb/chipidea/core.c > +++ b/drivers/usb/chipidea/core.c > @@ -516,38 +516,6 @@ int hw_device_reset(struct ci_hdrc *ci) > return 0; > } > > -/** > - * hw_wait_reg: wait the register value > - * > - * Sometimes, it needs to wait register value before going on. > - * Eg, when switch to device mode, the vbus value should be lower > - * than OTGSC_BSV before connects to host. > - * > - * @ci: the controller > - * @reg: register index > - * @mask: mast bit > - * @value: the bit value to wait > - * @timeout_ms: timeout in millisecond > - * > - * This function returns an error code if timeout > - */ > -int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask, > - u32 value, unsigned int timeout_ms) > -{ > - unsigned long elapse = jiffies + msecs_to_jiffies(timeout_ms); > - > - while (hw_read(ci, reg, mask) != value) { > - if (time_after(jiffies, elapse)) { > - dev_err(ci->dev, "timeout waiting for %08x in %d\n", > - mask, reg); > - return -ETIMEDOUT; > - } > - msleep(20); > - } > - > - return 0; > -} > - > static irqreturn_t ci_irq(int irq, void *data) { > struct ci_hdrc *ci = data; > diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index > 03b6743461d1..763a8332b009 100644 > --- a/drivers/usb/chipidea/otg.c > +++ b/drivers/usb/chipidea/otg.c > @@ -104,7 +104,32 @@ void ci_handle_vbus_change(struct ci_hdrc *ci) > usb_gadget_vbus_disconnect(&ci->gadget); > } > > -#define CI_VBUS_STABLE_TIMEOUT_MS 5000 > +/** > + * Sometimes, it needs to wait register value before going on. > + * Eg, when switch to device mode, the vbus value should be lower > + * than OTGSC_BSV before connects to host. This should be updated since this API is dedicated for BSV now. > + * > + * @ci: the controller > + * > + * This function returns an error code if timeout */ static int > +hw_wait_otgsc_bsv(struct ci_hdrc *ci) { > + unsigned long elapse = jiffies + msecs_to_jiffies(5000); > + u32 mask = OTGSC_BSV; > + > + while (!hw_read_otgsc(ci, mask)) { Reverse logic, should be: while (hw_read_otgsc(ci, mask)) { Li Jun > + if (time_after(jiffies, elapse)) { > + dev_err(ci->dev, "timeout waiting for %08x in OTGSC\n", > + mask); > + return -ETIMEDOUT; > + } > + msleep(20); > + } > + > + return 0; > +} > + > static void ci_handle_id_switch(struct ci_hdrc *ci) { > enum ci_role role = ci_otg_role(ci); > @@ -116,9 +141,11 @@ static void ci_handle_id_switch(struct ci_hdrc *ci) > ci_role_stop(ci); > > if (role == CI_ROLE_GADGET) > - /* wait vbus lower than OTGSC_BSV */ > - hw_wait_reg(ci, OP_OTGSC, OTGSC_BSV, 0, > - CI_VBUS_STABLE_TIMEOUT_MS); > + /* > + * wait vbus lower than OTGSC_BSV before connecting > + * to host > + */ > + hw_wait_otgsc_bsv(ci); > > ci_role_start(ci, role); > } > -- > 2.9.0.rc2.8.ga28705d > > -- > To unsubscribe from this list: send the line "unsubscribe linux-usb" in > the body of a message to majordomo@vger.kernel.org More majordomo info at > http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752016AbcF0IEs (ORCPT ); Mon, 27 Jun 2016 04:04:48 -0400 Received: from mail-am1on0094.outbound.protection.outlook.com ([157.56.112.94]:23582 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751830AbcF0IEo convert rfc822-to-8bit (ORCPT ); Mon, 27 Jun 2016 04:04:44 -0400 From: Jun Li To: Stephen Boyd , "linux-usb@vger.kernel.org" CC: "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-arm-msm@vger.kernel.org" , Andy Gross , "Bjorn Andersson" , Neil Armstrong , Arnd Bergmann , Felipe Balbi , Peter Chen , Greg Kroah-Hartman , "Ivan T. Ivanov" Subject: RE: [PATCH 04/21] usb: chipidea: Only read/write OTGSC from one place Thread-Topic: [PATCH 04/21] usb: chipidea: Only read/write OTGSC from one place Thread-Index: AQHRz3yM2H8jhgmrmUeNu1V5llvJ5J/89CCw Date: Mon, 27 Jun 2016 08:04:39 +0000 Message-ID: References: <20160626072838.28082-1-stephen.boyd@linaro.org> <20160626072838.28082-5-stephen.boyd@linaro.org> In-Reply-To: <20160626072838.28082-5-stephen.boyd@linaro.org> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=jun.li@nxp.com; x-originating-ip: [199.59.226.141] x-ms-office365-filtering-correlation-id: 944c0374-4f62-4e2d-6207-08d39e61b02b x-microsoft-exchange-diagnostics: 1;AM4PR04MB2132;6:4y41k/KhsgPGU8lBOhGQJpmHpY6/X7hgJvx8ajFA/pCYVbg7Cv19kG1iF4JVg8o9ezAC8AIeEusaDngWcs/npJDACBbpaEIraayXMb9pXMiZvur++NZvNXNm32RaooY1xl7taeaR++WrTVOVKn0kF/R5AOow1y4+Zx4hKV3IKiN4Vxnd09hV6IgQi6bitehLmF6GBydVWBJCgR3TYRSA0EyUh1VRrKTwk91zCOsIhW8yZcnuJOuHXVwbMFHFa5dke/jBz4hQqZhiGxleH0e7LBO9xrTGfJTz2acgcled69HMOnYTNyyRJyobq8HKQpGjA5MdvY9WKF94Y+JfJ3W1KmXemVI7he8YP/Eh094whCI=;5:6b2Z23eZb7HSGQWwO6Lg7DIZJWXmsFJOUHFxR4ZnYl5VUChyVSlw+lRVmXbGDBWjI62ZGQp2gmzqtEiGIJIdIL3S/4HZlpX2ycYZqoXC9Srmm9sZeYpQX94dun/FLABm44+pQOumAjjymZJnAYqBKQ==;24:507p4DS2glJt9SBsvHwB7IJv9+xZnq0IPimsQ/vKsT9yKJtZdfef4n1qilyVyduGdu+HYK3bPerAf+PobbLVn+aggKrfvpMGLaI1kTEqPCM=;7:olWimOqqEooV5ngjC8ZkI2kW3Dpn8WgpKzdUkiPWV9nfrqvQKQb9h+nEF1Mp4jd5WcP6ylCSaE3xVozp0mx2Ded5wzufnwLdVh11H/BecHL0NPNafWwMDGBXTScGvgN31XaN8i2zKSYa1IYyudb0aExFtMUAR+oGW2Eo/h99DEIHS+Pf1hEaYP6S0L0eyAFUuHXslsv1K8hQK01XeWzpEYIs67meOklr1jMByc3mUOcRqidxCMBuR+1xHfBMuDrB9XE83B33JA74tr0/HCo90g== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM4PR04MB2132; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(185117386973197)(258649278758335); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026);SRVR:AM4PR04MB2132;BCL:0;PCL:0;RULEID:;SRVR:AM4PR04MB2132; x-forefront-prvs: 09860C2161 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(189002)(377454003)(199003)(13464003)(5002640100001)(101416001)(76576001)(77096005)(86362001)(15975445007)(2900100001)(2950100001)(87936001)(3846002)(102836003)(6116002)(81166006)(586003)(33656002)(2501003)(4326007)(74316001)(3660700001)(3280700002)(9686002)(2906002)(122556002)(76176999)(54356999)(50986999)(66066001)(189998001)(5001770100001)(97736004)(8936002)(81156014)(305945005)(8676002)(19580395003)(19580405001)(106116001)(68736007)(106356001)(7846002)(7736002)(5003600100003)(105586002)(92566002)(7696003)(10400500002)(422495003);DIR:OUT;SFP:1101;SCL:1;SRVR:AM4PR04MB2132;H:AM4PR04MB2130.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jun 2016 08:04:39.2370 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR04MB2132 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi > -----Original Message----- > From: linux-usb-owner@vger.kernel.org [mailto:linux-usb- > owner@vger.kernel.org] On Behalf Of Stephen Boyd > Sent: Sunday, June 26, 2016 3:28 PM > To: linux-usb@vger.kernel.org > Cc: linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; > linux-arm-msm@vger.kernel.org; Andy Gross ; Bjorn > Andersson ; Neil Armstrong > ; Arnd Bergmann ; Felipe Balbi > ; Peter Chen ; Greg Kroah-Hartman > ; Ivan T. Ivanov > Subject: [PATCH 04/21] usb: chipidea: Only read/write OTGSC from one place > > With the id and vbus detection done via extcon we need to make sure we > poll the status of OTGSC properly by considering what the extcon is saying, > and not just what the register is saying. Let's move this hw_wait_reg() > function to the only place it's used and simplify it for polling the OTGSC > register. Then we can make certain we only use the hw_read_otgsc() API to > read OTGSC, which will make sure we properly handle extcon events. > > Cc: Peter Chen > Cc: Greg Kroah-Hartman > Cc: "Ivan T. Ivanov" > Fixes: 3ecb3e09b042 ("usb: chipidea: Use extcon framework for VBUS and ID > detect") > Signed-off-by: Stephen Boyd > --- > drivers/usb/chipidea/core.c | 32 -------------------------------- > drivers/usb/chipidea/otg.c | 35 +++++++++++++++++++++++++++++++---- > 2 files changed, 31 insertions(+), 36 deletions(-) > > diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c > index 69426e644d17..01390e02ee53 100644 > --- a/drivers/usb/chipidea/core.c > +++ b/drivers/usb/chipidea/core.c > @@ -516,38 +516,6 @@ int hw_device_reset(struct ci_hdrc *ci) > return 0; > } > > -/** > - * hw_wait_reg: wait the register value > - * > - * Sometimes, it needs to wait register value before going on. > - * Eg, when switch to device mode, the vbus value should be lower > - * than OTGSC_BSV before connects to host. > - * > - * @ci: the controller > - * @reg: register index > - * @mask: mast bit > - * @value: the bit value to wait > - * @timeout_ms: timeout in millisecond > - * > - * This function returns an error code if timeout > - */ > -int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask, > - u32 value, unsigned int timeout_ms) > -{ > - unsigned long elapse = jiffies + msecs_to_jiffies(timeout_ms); > - > - while (hw_read(ci, reg, mask) != value) { > - if (time_after(jiffies, elapse)) { > - dev_err(ci->dev, "timeout waiting for %08x in %d\n", > - mask, reg); > - return -ETIMEDOUT; > - } > - msleep(20); > - } > - > - return 0; > -} > - > static irqreturn_t ci_irq(int irq, void *data) { > struct ci_hdrc *ci = data; > diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index > 03b6743461d1..763a8332b009 100644 > --- a/drivers/usb/chipidea/otg.c > +++ b/drivers/usb/chipidea/otg.c > @@ -104,7 +104,32 @@ void ci_handle_vbus_change(struct ci_hdrc *ci) > usb_gadget_vbus_disconnect(&ci->gadget); > } > > -#define CI_VBUS_STABLE_TIMEOUT_MS 5000 > +/** > + * Sometimes, it needs to wait register value before going on. > + * Eg, when switch to device mode, the vbus value should be lower > + * than OTGSC_BSV before connects to host. This should be updated since this API is dedicated for BSV now. > + * > + * @ci: the controller > + * > + * This function returns an error code if timeout */ static int > +hw_wait_otgsc_bsv(struct ci_hdrc *ci) { > + unsigned long elapse = jiffies + msecs_to_jiffies(5000); > + u32 mask = OTGSC_BSV; > + > + while (!hw_read_otgsc(ci, mask)) { Reverse logic, should be: while (hw_read_otgsc(ci, mask)) { Li Jun > + if (time_after(jiffies, elapse)) { > + dev_err(ci->dev, "timeout waiting for %08x in OTGSC\n", > + mask); > + return -ETIMEDOUT; > + } > + msleep(20); > + } > + > + return 0; > +} > + > static void ci_handle_id_switch(struct ci_hdrc *ci) { > enum ci_role role = ci_otg_role(ci); > @@ -116,9 +141,11 @@ static void ci_handle_id_switch(struct ci_hdrc *ci) > ci_role_stop(ci); > > if (role == CI_ROLE_GADGET) > - /* wait vbus lower than OTGSC_BSV */ > - hw_wait_reg(ci, OP_OTGSC, OTGSC_BSV, 0, > - CI_VBUS_STABLE_TIMEOUT_MS); > + /* > + * wait vbus lower than OTGSC_BSV before connecting > + * to host > + */ > + hw_wait_otgsc_bsv(ci); > > ci_role_start(ci, role); > } > -- > 2.9.0.rc2.8.ga28705d > > -- > To unsubscribe from this list: send the line "unsubscribe linux-usb" in > the body of a message to majordomo@vger.kernel.org More majordomo info at > http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: jun.li@nxp.com (Jun Li) Date: Mon, 27 Jun 2016 08:04:39 +0000 Subject: [PATCH 04/21] usb: chipidea: Only read/write OTGSC from one place In-Reply-To: <20160626072838.28082-5-stephen.boyd@linaro.org> References: <20160626072838.28082-1-stephen.boyd@linaro.org> <20160626072838.28082-5-stephen.boyd@linaro.org> Message-ID: To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org Hi > -----Original Message----- > From: linux-usb-owner at vger.kernel.org [mailto:linux-usb- > owner at vger.kernel.org] On Behalf Of Stephen Boyd > Sent: Sunday, June 26, 2016 3:28 PM > To: linux-usb at vger.kernel.org > Cc: linux-arm-kernel at lists.infradead.org; linux-kernel at vger.kernel.org; > linux-arm-msm at vger.kernel.org; Andy Gross ; Bjorn > Andersson ; Neil Armstrong > ; Arnd Bergmann ; Felipe Balbi > ; Peter Chen ; Greg Kroah-Hartman > ; Ivan T. Ivanov > Subject: [PATCH 04/21] usb: chipidea: Only read/write OTGSC from one place > > With the id and vbus detection done via extcon we need to make sure we > poll the status of OTGSC properly by considering what the extcon is saying, > and not just what the register is saying. Let's move this hw_wait_reg() > function to the only place it's used and simplify it for polling the OTGSC > register. Then we can make certain we only use the hw_read_otgsc() API to > read OTGSC, which will make sure we properly handle extcon events. > > Cc: Peter Chen > Cc: Greg Kroah-Hartman > Cc: "Ivan T. Ivanov" > Fixes: 3ecb3e09b042 ("usb: chipidea: Use extcon framework for VBUS and ID > detect") > Signed-off-by: Stephen Boyd > --- > drivers/usb/chipidea/core.c | 32 -------------------------------- > drivers/usb/chipidea/otg.c | 35 +++++++++++++++++++++++++++++++---- > 2 files changed, 31 insertions(+), 36 deletions(-) > > diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c > index 69426e644d17..01390e02ee53 100644 > --- a/drivers/usb/chipidea/core.c > +++ b/drivers/usb/chipidea/core.c > @@ -516,38 +516,6 @@ int hw_device_reset(struct ci_hdrc *ci) > return 0; > } > > -/** > - * hw_wait_reg: wait the register value > - * > - * Sometimes, it needs to wait register value before going on. > - * Eg, when switch to device mode, the vbus value should be lower > - * than OTGSC_BSV before connects to host. > - * > - * @ci: the controller > - * @reg: register index > - * @mask: mast bit > - * @value: the bit value to wait > - * @timeout_ms: timeout in millisecond > - * > - * This function returns an error code if timeout > - */ > -int hw_wait_reg(struct ci_hdrc *ci, enum ci_hw_regs reg, u32 mask, > - u32 value, unsigned int timeout_ms) > -{ > - unsigned long elapse = jiffies + msecs_to_jiffies(timeout_ms); > - > - while (hw_read(ci, reg, mask) != value) { > - if (time_after(jiffies, elapse)) { > - dev_err(ci->dev, "timeout waiting for %08x in %d\n", > - mask, reg); > - return -ETIMEDOUT; > - } > - msleep(20); > - } > - > - return 0; > -} > - > static irqreturn_t ci_irq(int irq, void *data) { > struct ci_hdrc *ci = data; > diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index > 03b6743461d1..763a8332b009 100644 > --- a/drivers/usb/chipidea/otg.c > +++ b/drivers/usb/chipidea/otg.c > @@ -104,7 +104,32 @@ void ci_handle_vbus_change(struct ci_hdrc *ci) > usb_gadget_vbus_disconnect(&ci->gadget); > } > > -#define CI_VBUS_STABLE_TIMEOUT_MS 5000 > +/** > + * Sometimes, it needs to wait register value before going on. > + * Eg, when switch to device mode, the vbus value should be lower > + * than OTGSC_BSV before connects to host. This should be updated since this API is dedicated for BSV now. > + * > + * @ci: the controller > + * > + * This function returns an error code if timeout */ static int > +hw_wait_otgsc_bsv(struct ci_hdrc *ci) { > + unsigned long elapse = jiffies + msecs_to_jiffies(5000); > + u32 mask = OTGSC_BSV; > + > + while (!hw_read_otgsc(ci, mask)) { Reverse logic, should be: while (hw_read_otgsc(ci, mask)) { Li Jun > + if (time_after(jiffies, elapse)) { > + dev_err(ci->dev, "timeout waiting for %08x in OTGSC\n", > + mask); > + return -ETIMEDOUT; > + } > + msleep(20); > + } > + > + return 0; > +} > + > static void ci_handle_id_switch(struct ci_hdrc *ci) { > enum ci_role role = ci_otg_role(ci); > @@ -116,9 +141,11 @@ static void ci_handle_id_switch(struct ci_hdrc *ci) > ci_role_stop(ci); > > if (role == CI_ROLE_GADGET) > - /* wait vbus lower than OTGSC_BSV */ > - hw_wait_reg(ci, OP_OTGSC, OTGSC_BSV, 0, > - CI_VBUS_STABLE_TIMEOUT_MS); > + /* > + * wait vbus lower than OTGSC_BSV before connecting > + * to host > + */ > + hw_wait_otgsc_bsv(ci); > > ci_role_start(ci, role); > } > -- > 2.9.0.rc2.8.ga28705d > > -- > To unsubscribe from this list: send the line "unsubscribe linux-usb" in > the body of a message to majordomo at vger.kernel.org More majordomo info at > http://vger.kernel.org/majordomo-info.html