Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934070AbbGHIJP (ORCPT ); Wed, 8 Jul 2015 04:09:15 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:64399 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934926AbbGHIIe convert rfc822-to-8bit (ORCPT ); Wed, 8 Jul 2015 04:08:34 -0400 X-IronPort-AV: E=Sophos;i="5.15,430,1432566000"; d="scan'208";a="191117136" 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 v5] usb: renesas_usbhs: Allow an OTG PHY driver to provide VBUS Thread-Topic: [PATCH v5] usb: renesas_usbhs: Allow an OTG PHY driver to provide VBUS Thread-Index: AQHQuKvD9uVtPzuDdUGYdr7uKQYw7J3QojeAgACTKiA= Date: Wed, 8 Jul 2015 08:08:27 +0000 Message-ID: References: <3446210.Evs1k3c1oP@avalon> <1436269963-25885-1-git-send-email-phil.edworthy@renesas.com> <1989113.aQDiRBvWpG@avalon> In-Reply-To: <1989113.aQDiRBvWpG@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;SIXPR06MB0605;5:VnUW40FPYK8kIjUKpA9/BqKdbTYR08H/iEDDA3TFWvgSOvE+IHTyVaY6qx6qvBYOPwlN4ZZMKFCj25HA1Aw01GFKPUzqO66Yw+C7liru0Z2eZLlyWKlsqecH3s6gMssRyAMdIA8EGI70pCFEfaOAtw==;24:FqVFVjsnEt50gOx+yNSwK2lFvF3D3G4PkvgKttWfde+43F2i66EWnrsHwJVsEcDwf1kECvPXD2NLvwrKK/Xol3GIclvX2yPkCtOxd00M1aU=;20:WjznzXAFsPo/Sa6eqWdBrvV3DdfHX84QVzvy9uwilPdE6RI4vtL648IZZOMmqFLrEx3gJgqxxmp6jxUlglf/9XYRJJfXGOqW7gLLDSybogBZ9J+qPAWT8V+4RMHSEqqhB78dVaEomyV0VcM2AC8MXQrv4B+Gj95o3pb4u3J77Nw= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SIXPR06MB0605; 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:SIXPR06MB0605;BCL:0;PCL:0;RULEID:;SRVR:SIXPR06MB0605; x-forefront-prvs: 0631F0BC3D x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(51704005)(24454002)(33656002)(5003600100002)(54356999)(74316001)(106116001)(122556002)(77156002)(87936001)(76176999)(19580395003)(77096005)(2656002)(19580405001)(2900100001)(102836002)(40100003)(50986999)(86362001)(5001960100002)(110136002)(66066001)(2950100001)(62966003)(189998001)(76576001)(46102003)(5001920100001)(5002640100001)(92566002)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:SIXPR06MB0605;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: 08 Jul 2015 08:08:27.7751 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB0605 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6066 Lines: 196 Hi Laurent, On 08 July 2015 00:08, Laurent wrote: > Hi Phil, > > Thank you for the patch. > > On Tuesday 07 July 2015 12:52:43 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 > > This looks much better to me. I just have two comments, please see below. > > > --- > > v5: > > - Avoid race when vbus_is_indirect may or may not be read > > before the phy has called vbus_session. In doing so, the > > changes have also been isolated to mod_gadget.c > > > > v4: > > - Use true/false with bool vars. > > - Clean up "transceiver found" message. > > > > 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/mod_gadget.c | 62 > +++++++++++++++++++++++++++++++ > > 1 file changed, 62 insertions(+) > > > > diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c > > b/drivers/usb/renesas_usbhs/mod_gadget.c index dc2aa32..19a22a3 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,8 @@ struct usbhsg_gpriv { > > int uep_size; > > > > struct usb_gadget_driver *driver; > > + struct usb_phy *transceiver; > > + bool vbus_indirect_value; > > How about naming this vbus_connected ? A boolean "value" doesn't mean much. Hmm, vbus_connected isn't right either. This variable directly maps to the vbus signal, i.e. this variable is true when the signal is high. I'll change it to vbus_active. > > > > u32 status; > > #define USBHSG_STATUS_STARTED (1 << 0) > > @@ -873,6 +876,27 @@ static int usbhsg_try_stop(struct usbhs_priv *priv, u32 > > status) } > > > > /* > > + * VBUS provided by the PHY > > + */ > > +static int usbhsm_phy_get_vbus(struct platform_device *pdev) > > +{ > > + struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); > > + struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); > > + > > + return gpriv->vbus_indirect_value; > > +} > > + > > +static void usbhs_mod_phy_mode(struct usbhs_priv *priv) > > +{ > > + struct usbhs_mod_info *info = &priv->mod_info; > > + > > + info->irq_vbus = NULL; > > + priv->pfunc.get_vbus = usbhsm_phy_get_vbus; > > + > > + usbhs_irq_callback_update(priv, NULL); > > +} > > + > > +/* > > * > > * linux usb function > > * > > @@ -882,12 +906,28 @@ 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; > > + } > > + > > + /* get vbus using phy versions */ > > + usbhs_mod_phy_mode(priv); > > Given that the presence of an external PHY is known at probe time, couldn't > this call be moved to the probe function ? It would then probably conflict > with the usbhs_mod_autonomy_mode() call from usbhs_probe(), which would > need to be fixed. You could do this, but as you say it would conflict with usbhs_probe(). I can't see a simple way to check for the external phy connection, so I would prefer to keep it here. Is that ok? > > + } > > + > > /* first hook up the driver ... */ > > gpriv->driver = driver; > > > > @@ -900,6 +940,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 +991,26 @@ 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); > > + > > + gpriv->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 +1052,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, "%stransceiver 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/