Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932899AbcKNSjM (ORCPT ); Mon, 14 Nov 2016 13:39:12 -0500 Received: from mail-db5eur01on0050.outbound.protection.outlook.com ([104.47.2.50]:24544 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933571AbcKNSjG (ORCPT ); Mon, 14 Nov 2016 13:39:06 -0500 From: Scott Wood To: Sriram Dash , "linux-kernel@vger.kernel.org" , "linux-usb@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" CC: "mark.rutland@arm.com" , "felipe.balbi@linux.intel.com" , "mathias.nyman@intel.com" , "catalin.marinas@arm.com" , "will.deacon@arm.com" , "kishon@ti.com" , "robh+dt@kernel.org" , "stern@rowland.harvard.edu" , Suresh Gupta , "gregkh@linuxfoundation.org" , "pku.leo@gmail.com" Subject: Re: [upstream-release] [PATCH 1/2] drivers: usb: phy: Add qoriq usb 3.0 phy driver support Thread-Topic: [upstream-release] [PATCH 1/2] drivers: usb: phy: Add qoriq usb 3.0 phy driver support Thread-Index: AQHSPjfIdBocuEaXMU2jHpnkfUNzKg== Date: Mon, 14 Nov 2016 16:07:55 +0000 Message-ID: References: <1479101215-26954-1-git-send-email-sriram.dash@nxp.com> <1479101215-26954-2-git-send-email-sriram.dash@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=scott.wood@nxp.com; x-originating-ip: [2601:449:8400:923b:12bf:48ff:fe84:c9a0] x-microsoft-exchange-diagnostics: 1;DB5PR0401MB1928;7:1HS3nY3ljkUGljkr7M25jyvKEja1s37OAUrBG4FUut0fIrOnYQ0RQ4LOwMf1TJmSmAiHdx8a9hvOEm3ppKsPhlaBP2790dwf46P2wr+z8H2DiQwp2R5FpLU1ceaa1wjAVy/RfrkFPuhoQ465EGneH6erwYRheTLrT9FcnlIilNn+2PhV912yb5JuIcOKFrwgUfs7WBGpjGSFBQO2XeQxHjuMFljWgrCurFFZe9Toqk9ZU8fSZhfo2GR5fhm0CA/jM9SR6FhzagCorVr8oc/QzObuf86XV/YrjNYhdoKJ1VRT12vOPly74cOIWrJfOGk1W8OHxy0okyhiaPDgqLmkm1CtNlVKSRbvhXiTaxzyyew= x-ms-office365-filtering-correlation-id: 495fccef-ff6f-4d63-e1ba-08d40ca864ec x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB5PR0401MB1928; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6045074)(6060326)(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6046074)(6072148);SRVR:DB5PR0401MB1928;BCL:0;PCL:0;RULEID:;SRVR:DB5PR0401MB1928; x-forefront-prvs: 0126A32F74 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(336003)(189002)(24454002)(199003)(377454003)(7416002)(4326007)(101416001)(33656002)(7696004)(2201001)(575784001)(86362001)(5660300001)(76576001)(50986999)(76176999)(122556002)(54356999)(68736007)(102836003)(9686002)(2906002)(87936001)(586003)(6116002)(77096005)(81166006)(92566002)(8936002)(81156014)(2900100001)(5001770100001)(3280700002)(2501003)(105586002)(229853002)(106356001)(106116001)(74316002)(7846002)(97736004)(7736002)(305945005)(189998001)(3660700001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB5PR0401MB1928;H:DB5PR0401MB1928.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" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Nov 2016 16:07:55.1906 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR0401MB1928 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 mail.home.local id uAEIdHH4022361 Content-Length: 5171 Lines: 172 On 11/13/2016 11:27 PM, Sriram Dash wrote: > diff --git a/Documentation/devicetree/bindings/phy/phy-qoriq-usb3.txt b/Documentation/devicetree/bindings/phy/phy-qoriq-usb3.txt > new file mode 100644 > index 0000000..d934c80 > --- /dev/null > +++ b/Documentation/devicetree/bindings/phy/phy-qoriq-usb3.txt > @@ -0,0 +1,36 @@ > +Driver for Freescale USB 3.0 PHY > + > +Required properties: > + > +- compatible : fsl,qoriq-usb3-phy This is a very vague compatible. Are there versioning registers within this register block? > +/* Parameter control */ > +#define USB3PRM1CR 0x000 > +#define USB3PRM1CR_VAL 0x27672b2a > + > +/* > + * struct qoriq_usb3_phy - driver data for USB 3.0 PHY > + * @dev: pointer to device instance of this platform device > + * @param_ctrl: usb3 phy parameter control register base > + * @phy_base: usb3 phy register memory base > + * @has_erratum_flag: keeps track of erratum applicable on device > + */ > +struct qoriq_usb3_phy { > + struct device *dev; > + void __iomem *param_ctrl; > + void __iomem *phy_base; > + u32 has_erratum_flag; > +}; > + > +static inline u32 qoriq_usb3_phy_readl(void __iomem *addr, u32 offset) > +{ > + return __raw_readl(addr + offset); > +} > + > +static inline void qoriq_usb3_phy_writel(void __iomem *addr, u32 offset, > + u32 data) > +{ > + __raw_writel(data, addr + offset); > +} Why raw? Besides missing barriers, this will cause the accesses to be native-endian which is not correct. > +/* > + * Erratum A008751 > + * SCFG USB3PRM1CR has incorrect default value > + * SCFG USB3PRM1CR reset value should be 32'h27672B2A instead of 32'h25E72B2A. When documenting C code, can you stick with C-style numeric constants? For that matter, just put the constant in the code instead of hiding it in an overly-generically-named USB3PRM1CR_VAL and then you won't need to redundantly state the value in a comment. Normally putting magic numbers in symbolic constants is a good thing, but in this case it's not actually describing anything and the number is of no meaning outside of this one erratum workaround (it might even be a different value if another chip has a similar erratum). > + */ > +static void erratum_a008751(struct qoriq_usb3_phy *phy) > +{ > + qoriq_usb3_phy_writel(phy->param_ctrl, USB3PRM1CR, > + USB3PRM1CR_VAL); > +} > + > +/* > + * qoriq_usb3_phy_erratum - List of phy erratum > + * @qoriq_phy_erratum - erratum application > + * @compat - comapt string for erratum > + */ > + > +struct qoriq_usb3_phy_erratum { > + void (*qoriq_phy_erratum)(struct qoriq_usb3_phy *phy); > + char *compat; > +}; > + > +/* Erratum list */ > +struct qoriq_usb3_phy_erratum phy_erratum_tbl[] = { > + {&erratum_a008751, "fsl,usb-erratum-a008751"}, > + /* Add init time erratum here */ > +}; This needs to be static. Unnecessary & on the function pointer. > +static int qoriq_usb3_phy_init(struct phy *x) > +{ > + struct qoriq_usb3_phy *phy = phy_get_drvdata(x); > + int i; > + > + for (i = 0; i < ARRAY_SIZE(phy_erratum_tbl); i++) > + if (phy->has_erratum_flag & 1 << i) > + phy_erratum_tbl[i].qoriq_phy_erratum(phy); > + return 0; > +} > + > +static const struct phy_ops ops = { > + .init = qoriq_usb3_phy_init, > + .owner = THIS_MODULE, > +}; > + > +static int qoriq_usb3_phy_probe(struct platform_device *pdev) > +{ > + struct qoriq_usb3_phy *phy; > + struct phy *generic_phy; > + struct phy_provider *phy_provider; > + const struct of_device_id *of_id; > + struct device *dev = &pdev->dev; > + struct resource *res; > + int i, ret; > + > + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); > + if (!phy) > + return -ENOMEM; > + phy->dev = dev; > + > + of_id = of_match_device(dev->driver->of_match_table, dev); > + if (!of_id) { > + dev_err(dev, "failed to get device match\n"); > + ret = -EINVAL; > + goto err_out; > + } > + > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "param_ctrl"); > + if (!res) { > + dev_err(dev, "failed to get param_ctrl memory\n"); > + ret = -ENOENT; > + goto err_out; > + } > + > + phy->param_ctrl = devm_ioremap_resource(dev, res); > + if (!phy->param_ctrl) { > + dev_err(dev, "failed to remap param_ctrl memory\n"); > + ret = -ENOMEM; > + goto err_out; > + } > + > + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_base"); > + if (!res) { > + dev_err(dev, "failed to get phy_base memory\n"); > + ret = -ENOENT; > + goto err_out; > + } > + > + phy->phy_base = devm_ioremap_resource(dev, res); > + if (!phy->phy_base) { > + dev_err(dev, "failed to remap phy_base memory\n"); > + ret = -ENOMEM; > + goto err_out; > + } > + > + phy->has_erratum_flag = 0; > + for (i = 0; i < ARRAY_SIZE(phy_erratum_tbl); i++) > + phy->has_erratum_flag |= device_property_read_bool(dev, > + phy_erratum_tbl[i].compat) << i; I don't see the erratum property in either the binding or the device tree. Also, a property name is not a "compat". Is there a reason why this flag and array mechanism is needed, rather than just checking the erratum properties from the init function -- or, if you have a good reason to not want to do device tree accesses from init, just using a bool per erratum? How many errata are you expecting? -Scott