From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932070AbdJJH5r (ORCPT ); Tue, 10 Oct 2017 03:57:47 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:41407 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755157AbdJJH5o (ORCPT ); Tue, 10 Oct 2017 03:57:44 -0400 X-IronPort-AV: E=Sophos;i="5.42,503,1500908400"; d="scan'208";a="260102304" From: Yoshihiro Shimoda To: Simon Horman CC: "kishon@ti.com" , "robh+dt@kernel.org" , "mark.rutland@arm.com" , "linux-kernel@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-renesas-soc@vger.kernel.org" Subject: RE: [PATCH v4 2/4] phy: rcar-gen3-usb2: cleanup the role_{store,show}() Thread-Topic: [PATCH v4 2/4] phy: rcar-gen3-usb2: cleanup the role_{store,show}() Thread-Index: AQHTQY1eCIyYop0c/kCCoHZJJmCB1KLctIEAgAABJIA= Date: Tue, 10 Oct 2017 07:57:38 +0000 Message-ID: References: <1507615110-26206-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> <1507615110-26206-3-git-send-email-yoshihiro.shimoda.uh@renesas.com> <20171010074556.GM2518@verge.net.au> In-Reply-To: <20171010074556.GM2518@verge.net.au> Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=yoshihiro.shimoda.uh@renesas.com; x-originating-ip: [211.11.155.139] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;TY1PR06MB0991;20:jk2R3tSwy3oByIuadAw9/0ABE7sy5b++/7xxcZJei4t3+/5DHSbzQZCV+2tN/BQP7LV8Vt7k8VY8Pj0UAVlp8xgi8G57ALxkP8Hn6K+MzDOAA8V4UtYdDGaqZhpeBjcpUlNNRlAos/UtKeePne+FMiiEj0atlGkX61Dw2n0UhZY= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 9c2a9d5f-ece5-4059-813a-08d50fb493bd x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254152)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075);SRVR:TY1PR06MB0991; x-ms-traffictypediagnostic: TY1PR06MB0991: x-exchange-antispam-report-test: UriScan:; x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(6055026)(6041248)(20161123558100)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:TY1PR06MB0991;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:TY1PR06MB0991; x-forefront-prvs: 04569283F9 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(346002)(376002)(39860400002)(189002)(199003)(24454002)(377454003)(14454004)(230783001)(6246003)(4326008)(54906003)(345774005)(77096006)(86362001)(33656002)(6436002)(316002)(81156014)(81166006)(8676002)(68736007)(53936002)(97736004)(229853002)(8936002)(6916009)(189998001)(2900100001)(305945005)(7736002)(3660700001)(25786009)(66066001)(105586002)(3280700002)(101416001)(2950100002)(2906002)(5660300001)(54356999)(50986999)(74316002)(76176999)(6506006)(9686003)(3846002)(106356001)(478600001)(6116002)(102836003)(99286003)(55016002)(7696004)(142933001);DIR:OUT;SFP:1102;SCL:1;SRVR:TY1PR06MB0991;H:TY1PR06MB0992.apcprd06.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" MIME-Version: 1.0 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Oct 2017 07:57:38.8430 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1PR06MB0991 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v9A7vr4g024630 Hi Simon-san, Thank you for the comments! > From: Simon Horman, Sent: Tuesday, October 10, 2017 4:46 PM > > On Tue, Oct 10, 2017 at 02:58:28PM +0900, Yoshihiro Shimoda wrote: > > This patch cleanups the role_{store,show}() and replaces the local > > "bool" for host/device mode selection with the "enum phy_mode" in > > the role_store(). > > > > Signed-off-by: Yoshihiro Shimoda > > --- > > drivers/phy/renesas/phy-rcar-gen3-usb2.c | 58 ++++++++++++++++++++++---------- > > 1 file changed, 40 insertions(+), 18 deletions(-) > > > > diff --git a/drivers/phy/renesas/phy-rcar-gen3-usb2.c b/drivers/phy/renesas/phy-rcar-gen3-usb2.c > > index e00e99a..7619468 100644 > > --- a/drivers/phy/renesas/phy-rcar-gen3-usb2.c > > +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c > > @@ -219,14 +219,10 @@ static bool rcar_gen3_is_host(struct rcar_gen3_chan *ch) > > return !(readl(ch->base + USB2_COMMCTRL) & USB2_COMMCTRL_OTG_PERI); > > } > > > > -static ssize_t role_store(struct device *dev, struct device_attribute *attr, > > - const char *buf, size_t count) > > +static ssize_t rcar_gen3_otg_change_role(struct rcar_gen3_chan *ch, > > + enum phy_mode mode) > > { > > - struct rcar_gen3_chan *ch = dev_get_drvdata(dev); > > - bool is_b_device, is_host, new_mode_is_host; > > - > > - if (!ch->has_otg || !ch->phy->init_count) > > - return -EIO; > > + bool is_b_device, is_host; > > > > /* > > * is_b_device: true is B-Device. false is A-Device. > > @@ -234,18 +230,13 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, > > */ > > is_b_device = rcar_gen3_check_id(ch); > > is_host = rcar_gen3_is_host(ch); > > - if (!strncmp(buf, "host", strlen("host"))) > > - new_mode_is_host = true; > > - else if (!strncmp(buf, "peripheral", strlen("peripheral"))) > > - new_mode_is_host = false; > > - else > > - return -EINVAL; > > > > /* If current and new mode is the same, this returns the error */ > > - if (is_host == new_mode_is_host) > > + if ((is_host && mode == PHY_MODE_USB_HOST) || > > + (!is_host && mode == PHY_MODE_USB_DEVICE)) > > Maybe it is not worth the effort, but it seems that if > rcar_gen3_is_host returned enum phy_mode then the above > could be changed into a single comparison. It's a nice idea! Since role_show() below should not be changed, I will add rcar_gen3_is_phy_mode_host() and changed the above code into a single comparison. > > return -EINVAL; > > > > - if (new_mode_is_host) { /* And is_host must be false */ > > + if (mode == PHY_MODE_USB_HOST) { /* And is_host must be false */ > > if (!is_b_device) /* A-Peripheral */ > > rcar_gen3_init_from_a_peri_to_a_host(ch); > > else /* B-Peripheral */ > > @@ -257,6 +248,32 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, > > rcar_gen3_init_for_peri(ch); > > } > > > > + return 0; > > +} > > + > > +static ssize_t role_store(struct device *dev, struct device_attribute *attr, > > + const char *buf, size_t count) > > +{ > > + struct rcar_gen3_chan *ch = dev_get_drvdata(dev); > > + enum phy_mode mode; > > + ssize_t ret = -EIO; > > + > > + if (!ch->phy->init_count) > > + return -EIO; > > + > > + if (!strncmp(buf, "host", strlen("host"))) > > + mode = PHY_MODE_USB_HOST; > > + else if (!strncmp(buf, "peripheral", strlen("peripheral"))) > > + mode = PHY_MODE_USB_DEVICE; > > + else > > + return -EINVAL; > > + > > + if (ch->has_otg) > > + ret = rcar_gen3_otg_change_role(ch, mode); > > + > > + if (ret < 0) > > + return ret; > > + > > return count; > > } > > > > @@ -264,12 +281,17 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr, > > char *buf) > > { > > struct rcar_gen3_chan *ch = dev_get_drvdata(dev); > > + bool is_host; > > > > - if (!ch->has_otg || !ch->phy->init_count) > > + if (!ch->phy->init_count) > > + return -EIO; > > + > > + if (ch->has_otg) > > + is_host = rcar_gen3_is_host(ch); > > + else > > return -EIO; > > > > - return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" : > > - "peripheral"); > > + return sprintf(buf, "%s\n", is_host ? "host" : "peripheral"); > > } > > I'm not sure why the above hunk is necessary. > They function seems logically the same before and after. Indeed. So, I will keep rcar_gen3_is_host() as bool and remove the role_show() modification. Best regards, Yoshihiro Shimoda > > static DEVICE_ATTR_RW(role); > > > > -- > > 1.9.1 > >