Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755419AbbGGJMd (ORCPT ); Tue, 7 Jul 2015 05:12:33 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:52290 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752171AbbGGJMW convert rfc822-to-8bit (ORCPT ); Tue, 7 Jul 2015 05:12:22 -0400 X-IronPort-AV: E=Sophos;i="5.15,422,1432566000"; d="scan'208";a="189862981" From: Phil Edworthy To: Laurent Pinchart CC: Yoshihiro Shimoda , Kuninori Morimoto , Greg Kroah-Hartman , Felipe Balbi , Ulrich Hecht , Kishon Vijay Abraham I , "Sergei Shtylyov" , "linux-kernel@vger.kernel.org" , "linux-usb@vger.kernel.org" , "linux-sh@vger.kernel.org" Subject: RE: [PATCH v3] usb: renesas_usbhs: Allow an OTG PHY driver to provide VBUS Thread-Topic: [PATCH v3] usb: renesas_usbhs: Allow an OTG PHY driver to provide VBUS Thread-Index: AQHQt8SdC1/NhxXKPEKUq1npoPo7PZ3PttZA Date: Tue, 7 Jul 2015 09:12:17 +0000 Message-ID: References: <2896957.Pcl0CbmdvL@avalon> <1435832793-9999-1-git-send-email-phil.edworthy@renesas.com> <3446210.Evs1k3c1oP@avalon> In-Reply-To: <3446210.Evs1k3c1oP@avalon> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: ideasonboard.com; dkim=none (message not signed) header.d=none; x-originating-ip: [193.141.220.21] x-microsoft-exchange-diagnostics: 1;SIXPR06MB0608;5:55wA43o8OARdYodqvGEtdO5+bT/4OrGLSeayZEn9U2XNvyIFnhE255aKM6UYQeoit8wHXTzk0zR1oIlX0/L028jLIGyfG11OevcZgF3qP8y0mJqbllwqiWDGNjSTd4RauFWvR2OPeK80SQt32dFdTQ==;24:J1nbjv2fWRxruDUuwsWJ0YltE/j4DS+4+wFRWOnCpuk0SXB9HIuozdzjZrXXn4ktlwMLFrS1INeFHXg1RdroC4OLtk8viVWvCQVH2gd62so=;20:iTtjLLR00hUVWembme7HO2VANz1nNXP5SSfjPCURd10sjUjGfcQTnYx+tvBprWaxateT3tjXqgTAO0xbN9yKGmZtP5qQGOu3100k35W5A9ORYCiWRJiNKJZJisS0sIKI/FdMg8Wpl1RXsP5bQ1xzd/lw9Roiq9XMxjhIYixDTRY= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SIXPR06MB0608; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:SIXPR06MB0608;BCL:0;PCL:0;RULEID:;SRVR:SIXPR06MB0608; x-forefront-prvs: 0630013541 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(24454002)(51704005)(76176999)(2900100001)(19580405001)(33656002)(40100003)(2656002)(92566002)(54356999)(46102003)(106116001)(74316001)(76576001)(2950100001)(5001960100002)(102836002)(86362001)(62966003)(77156002)(122556002)(66066001)(189998001)(77096005)(5001920100001)(87936001)(50986999)(5002640100001)(5003600100002)(110136002)(19580395003)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:SIXPR06MB0608;H:SIXPR06MB0639.apcprd06.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jul 2015 09:12:17.1281 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB0608 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7129 Lines: 210 Hi Laurent, On 06 July 2015 09:20, Laurent wrote: > Hi Phil, > > Thank you for the patch. Thanks for your review! > On Thursday 02 July 2015 11:26:33 Phil Edworthy wrote: > > These changes allow a PHY driver to trigger a VBUS interrupt and > > to provide the value of VBUS. > > > > Signed-off-by: Phil Edworthy > > > > --- > > v3: > > - Changed how indirect vbus is plumbed in. > > - Removed unnecessary (void) on call to otg_set_peripheral. > > - Moved code that connects to bus through transceiver so it > > is before setting gpriv->driver. > > > > v2: > > - vbus variables changed from int to bool. > > - dev_info() changed to dev_err() > > --- > > drivers/usb/renesas_usbhs/common.c | 8 +++++-- > > drivers/usb/renesas_usbhs/common.h | 2 ++ > > drivers/usb/renesas_usbhs/mod_gadget.c | 38 > +++++++++++++++++++++++++++++++ > > 3 files changed, 46 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/usb/renesas_usbhs/common.c > > b/drivers/usb/renesas_usbhs/common.c index 0f7e850..15e67d8 100644 > > --- a/drivers/usb/renesas_usbhs/common.c > > +++ b/drivers/usb/renesas_usbhs/common.c > > @@ -379,7 +379,10 @@ static void usbhsc_hotplug(struct usbhs_priv *priv) > > /* > > * get vbus status from platform > > */ > > - enable = usbhs_platform_call(priv, get_vbus, pdev); > > + if (priv->vbus_is_indirect) > > + enable = priv->vbus_indirect_value; > > + else > > + enable = usbhs_platform_call(priv, get_vbus, pdev); > > > > /* > > * get id from platform > > @@ -662,7 +665,8 @@ static int usbhs_probe(struct platform_device *pdev) > > pm_runtime_enable(&pdev->dev); > > if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) { > > usbhsc_power_ctrl(priv, 1); > > - usbhs_mod_autonomy_mode(priv); > > + if (!priv->vbus_is_indirect) > > Isn't this racy ? The vbus_session operation is called by transceivers from > interrupt handlers or work queues. Do we have a guarantee that it will be > called at least once before this code is reached ? Please see below for a > possible way to fix this. You are right, it is racy... :( > > + usbhs_mod_autonomy_mode(priv); > > } > > > > /* > > diff --git a/drivers/usb/renesas_usbhs/common.h > > b/drivers/usb/renesas_usbhs/common.h index 8c5fc12..478700c 100644 > > --- a/drivers/usb/renesas_usbhs/common.h > > +++ b/drivers/usb/renesas_usbhs/common.h > > @@ -255,6 +255,8 @@ struct usbhs_priv { > > struct renesas_usbhs_driver_param dparam; > > > > struct delayed_work notify_hotplug_work; > > + bool vbus_is_indirect; > > + bool vbus_indirect_value; > > struct platform_device *pdev; > > > > struct extcon_dev *edev; > > diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c > > b/drivers/usb/renesas_usbhs/mod_gadget.c index dc2aa32..93ad4ea 100644 > > --- a/drivers/usb/renesas_usbhs/mod_gadget.c > > +++ b/drivers/usb/renesas_usbhs/mod_gadget.c > > @@ -21,6 +21,7 @@ > > #include > > #include > > #include > > +#include > > #include "common.h" > > > > /* > > @@ -50,6 +51,7 @@ struct usbhsg_gpriv { > > int uep_size; > > > > struct usb_gadget_driver *driver; > > + struct usb_phy *transceiver; > > > > u32 status; > > #define USBHSG_STATUS_STARTED (1 << 0) > > @@ -882,12 +884,25 @@ static int usbhsg_gadget_start(struct usb_gadget > > *gadget, { > > struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); > > struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); > > + struct device *dev = usbhs_priv_to_dev(priv); > > + int ret; > > > > if (!driver || > > !driver->setup || > > driver->max_speed < USB_SPEED_FULL) > > return -EINVAL; > > > > + /* connect to bus through transceiver */ > > + if (!IS_ERR_OR_NULL(gpriv->transceiver)) { > > + ret = otg_set_peripheral(gpriv->transceiver->otg, > > + &gpriv->gadget); > > + if (ret) { > > + dev_err(dev, "%s: can't bind to transceiver\n", > > + gpriv->gadget.name); > > + return ret; > > + } > > + } > > + > > How is this change related to the topic ? I'm not too familiar with this > driver so I might just have missed something, but then others could as well, > and the commit message could do with a bit more information. I'm not sure what you mean, this code is needed to tell the phy driver if it is in host or gadget mode. I would have thought this is clear as it calls otg_set_peripheral. > > /* first hook up the driver ... */ > > gpriv->driver = driver; > > > > @@ -900,6 +915,10 @@ static int usbhsg_gadget_stop(struct usb_gadget > > *gadget) struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); > > > > usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD); > > + > > + if (!IS_ERR_OR_NULL(gpriv->transceiver)) > > + otg_set_peripheral(gpriv->transceiver->otg, NULL); > > + > > gpriv->driver = NULL; > > > > return 0; > > @@ -947,12 +966,27 @@ static int usbhsg_set_selfpowered(struct usb_gadget > > *gadget, int is_self) return 0; > > } > > > > +static int usbhsg_vbus_session(struct usb_gadget *gadget, int is_active) > > +{ > > + struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); > > + struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv); > > + struct platform_device *pdev = usbhs_priv_to_pdev(priv); > > + > > + priv->vbus_is_indirect = 1; > > vbus_is_indirect is never reset to 0. Shouldn't you set it to 1 (or rather to > true) in usbhs_mod_gadget_probe() if an external transceiver is found ? Yes, I see what you say. > What would you think of implementing and wiring up the get_vbus operation in > usbhs_mod_gadget_probe() in the same way that > usbhs_mod_autonomy_mode() does, > and return the value of vbus_indirect_value there ? You could then get rid of > the vbus_is_indirect field and move the vbus_indirect_value field to struct > usbhsg_gpriv, removing the need to modify > drivers/usb/renesas_usbhs/common.c. > It should also solve the race condition mentioned above. Ok, I'll have a look at that. > > + priv->vbus_indirect_value = !!is_active; > > + > > + renesas_usbhs_call_notify_hotplug(pdev); > > + > > + return 0; > > +} > > + > > static const struct usb_gadget_ops usbhsg_gadget_ops = { > > .get_frame = usbhsg_get_frame, > > .set_selfpowered = usbhsg_set_selfpowered, > > .udc_start = usbhsg_gadget_start, > > .udc_stop = usbhsg_gadget_stop, > > .pullup = usbhsg_pullup, > > + .vbus_session = usbhsg_vbus_session, > > }; > > > > static int usbhsg_start(struct usbhs_priv *priv) > > @@ -994,6 +1028,10 @@ int usbhs_mod_gadget_probe(struct usbhs_priv > *priv) > > goto usbhs_mod_gadget_probe_err_gpriv; > > } > > > > + gpriv->transceiver = usb_get_phy(USB_PHY_TYPE_UNDEFINED); > > + dev_info(dev, "%s transceiver found\n", > > + gpriv->transceiver ? "" : "No"); > > + > > /* > > * CAUTION > > * > > -- > Regards, > > Laurent Pinchart Thanks Phil -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/