From patchwork Tue Dec 18 13:56:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 1892041 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id EDA4D3FCD4 for ; Tue, 18 Dec 2012 13:53:48 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TkxZJ-0007Kl-Is; Tue, 18 Dec 2012 13:50:49 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TkxZE-0007K1-Cb for linux-arm-kernel@lists.infradead.org; Tue, 18 Dec 2012 13:50:46 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MF800LUHBQ3IZZ0@mailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 18 Dec 2012 22:50:41 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.123]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id C9.A5.01231.1B470D05; Tue, 18 Dec 2012 22:50:41 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-bb-50d074b16506 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 78.A5.01231.0B470D05; Tue, 18 Dec 2012 22:50:40 +0900 (KST) Received: from vivekkumarg-linuxpc.sisodomain.com ([107.108.73.134]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MF800NNCBQF1I10@mmp1.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 18 Dec 2012 22:50:40 +0900 (KST) From: Vivek Gautam To: linux-usb@vger.kernel.org Subject: [PATCH v2] usb: phy: samsung: Add support to set pmu isolation Date: Tue, 18 Dec 2012 19:26:06 +0530 Message-id: <1355838966-11269-1-git-send-email-gautam.vivek@samsung.com> X-Mailer: git-send-email 1.7.6.5 In-reply-to: <1355810167-18425-2-git-send-email-gautam.vivek@samsung.com> References: <1355810167-18425-2-git-send-email-gautam.vivek@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNLMWRmVeSWpSXmKPExsWyRsSkWndjyYUAg11T+C02Pb7G6sDosXlJ fQBjFJdNSmpOZllqkb5dAlfG63mXmAtuGVT0HXzJ2MB4Xr2LkZNDQsBE4tjT28wQtpjEhXvr 2UBsIYGljBLv7zt0MXKA1fw/wdPFyAUUXsQocf3acxYIZw+TxKq2yWDNbAK6Ek1vdzGC2CIC shKHr/xmBiliFtjJLLH0Xj/YVGEBd4kJj1+CNbAIqEp83PmZCcTmFfCQ+HdzORPEFQoSb24/ A6vhFPCUuNfawApxkYfElVP3WSF6BSS+TT7EAnGdrMSmA2C7JASus0mcaepihJgjKXFwxQ2W CYzCCxgZVjGKphYkFxQnpeca6hUn5haX5qXrJefnbmIEhuDpf8+kdjCubLA4xCjAwajEw3sj /0KAEGtiWXFl7iFGCQ5mJRHeN3FAId6UxMqq1KL8+KLSnNTiQ4w+QJdMZJYSTc4HxkdeSbyh sYm5qbGppZGRmakpDmElcd5mj5QAIYH0xJLU7NTUgtQimHFMHJxSDYxlYnu2fhL10Uw68GfV y3MrMq72PvKZ4eqz/bXPYm6W6N9Ls8LZYx9x6LB8neOTe5v3zV77zXLOrhYXk7ZvjF7tWDxl oWTF2h/rdr/ouCr7MW3++bry5kCOW0wTpP02zlOclhcqsG73urgD144+sX+0Y4ugWmXskwJ5 AY9ZB9776XhuV0l5EjJPiaU4I9FQi7moOBEA/sfOJm4CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmkeLIzCtJLcpLzFFi42I5/e+xgO6GkgsBBh8mWFpsenyN1YHRY/OS +gDGqAZGm4zUxJTUIoXUvOT8lMy8dFsl7+B453hTMwNDXUNLC3MlhbzE3FRbJRefAF23zByg qUoKZYk5pUChgMTiYiV9O0wTQkPcdC1gGiN0fUOC4HqMDNBAwhrGjNfzLjEX3DKo6Dv4krGB 8bx6FyMHh4SAicT/EzxdjJxAppjEhXvr2boYuTiEBBYxSly/9pwFwtnDJLGqbTIzSBWbgK5E 09tdjCC2iICsxOErv5lBipgFdjJLLL3XzwaSEBZwl5jw+CVYA4uAqsTHnZ+ZQGxeAQ+JfzeX M0GsU5B4c/sZWA2ngKfEvdYGVhBbCKjmyqn7rBMYeRcwMqxiFE0tSC4oTkrPNdQrTswtLs1L 10vOz93ECA7xZ1I7GFc2WBxiFOBgVOLhvZF/IUCINbGsuDL3EKMEB7OSCO+bOKAQb0piZVVq UX58UWlOavEhRh+gqyYyS4km5wPjL68k3tDYxNzU2NTSxMLEzBKHsJI4b7NHSoCQQHpiSWp2 ampBahHMOCYOTqkGRr4lzEJOt+8E8Dd+T3t50X4r7/JbcfP9VI9bTdJwl8wXnvbScvXhs1Wu E1jX1tqKbpggKV75uOfk7mCvgvnBzBunJL+UZVqw2CDwjJN+/Anet8V/OTeabgq4/Nk16kdY nsybc8xFd85IZLmIP7hjbjljetTb10ukso9sUN/deZFFZ+V0nbY7f5VYijMSDbWYi4oTAcUT erOeAgAA X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121218_085044_982089_CB590577 X-CRM114-Status: GOOD ( 18.41 ) X-Spam-Score: -4.6 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [203.254.224.34 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: l.majewski@samsung.com, linux-samsung-soc@vger.kernel.org, heiko@sntech.de, p.paneri@samsung.com, gregkh@linuxfoundation.org, devicetree-discuss@lists.ozlabs.org, broonie@opensource.wolfsonmicro.com, linux-kernel@vger.kernel.org, balbi@ti.com, grant.likely@secretlab.ca, kyungmin.park@samsung.com, kgene.kim@samsung.com, thomas.abraham@linaro.org, ben-linux@fluff.org, t.figa@samsung.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Adding support to parse device node data in order to get required properties to set pmu isolation for usb-phy. Signed-off-by: Vivek Gautam --- Changes from v1: - Changed the name of property for phy handler from'samsung,usb-phyctrl' to 'samsung,usb-phyhandle' to make it look more generic. - Similarly 'samsung,phyctrl-reg' is changed to 'samsung,phyhandle-reg' - Added a check for 'samsung,usb-phyhandle' before getting node from phandle. - Putting the node using 'of_node_put()' which had been missed. - Adding necessary check for the pointer in 'samsung_usbphy_set_isolation()' to avoid any NULL pointer dereferencing. - Unmapping the register ioremapped in 'samsung_usbphy_parse_dt_param()'. .../devicetree/bindings/usb/samsung-usbphy.txt | 12 +++ drivers/usb/phy/samsung-usbphy.c | 94 ++++++++++++++++++-- 2 files changed, 98 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/samsung-usbphy.txt b/Documentation/devicetree/bindings/usb/samsung-usbphy.txt index 7b26e2d..a7b28b2 100644 --- a/Documentation/devicetree/bindings/usb/samsung-usbphy.txt +++ b/Documentation/devicetree/bindings/usb/samsung-usbphy.txt @@ -9,3 +9,15 @@ Required properties: - compatible : should be "samsung,exynos4210-usbphy" - reg : base physical address of the phy registers and length of memory mapped region. + +Optional properties: +- samsung,usb-phyhandle : should point to usb-phyhandle sub-node which provides + binding data to enable/disable device PHY handled by + PMU register. + + Required properties: + - compatible : should be "samsung,usbdev-phyctrl" for + DEVICE type phy. + - samsung,phyhandle-reg: base physical address of + PHY_CONTROL register in PMU. +- samsung,enable-mask : should be '1' diff --git a/drivers/usb/phy/samsung-usbphy.c b/drivers/usb/phy/samsung-usbphy.c index 5c5e1bb5..4ceabe3 100644 --- a/drivers/usb/phy/samsung-usbphy.c +++ b/drivers/usb/phy/samsung-usbphy.c @@ -72,6 +72,8 @@ enum samsung_cpu_type { * @dev: The parent device supplied to the probe function * @clk: usb phy clock * @regs: usb phy register memory base + * @devctrl_reg: usb device phy-control pmu register memory base + * @en_mask: enable mask * @ref_clk_freq: reference clock frequency selection * @cpu_type: machine identifier */ @@ -81,12 +83,73 @@ struct samsung_usbphy { struct device *dev; struct clk *clk; void __iomem *regs; + void __iomem *devctrl_reg; + u32 en_mask; int ref_clk_freq; int cpu_type; }; #define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy) +static int samsung_usbphy_parse_dt_param(struct samsung_usbphy *sphy) +{ + struct device_node *usb_phyctrl; + u32 reg; + int lenp; + + if (!sphy->dev->of_node) { + sphy->devctrl_reg = NULL; + return -ENODEV; + } + + if (of_get_property(sphy->dev->of_node, "samsung,usb-phyhandle", &lenp)) { + usb_phyctrl = of_parse_phandle(sphy->dev->of_node, + "samsung,usb-phyhandle", 0); + if (!usb_phyctrl) { + dev_warn(sphy->dev, "Can't get usb-phy handle\n"); + sphy->devctrl_reg = NULL; + } + + of_property_read_u32(usb_phyctrl, "samsung,phyhandle-reg", ®); + + sphy->devctrl_reg = ioremap(reg, SZ_4); + + of_property_read_u32(sphy->dev->of_node, "samsung,enable-mask", + &sphy->en_mask); + of_node_put(usb_phyctrl); + } else { + dev_warn(sphy->dev, "Can't get usb-phy handle\n"); + sphy->devctrl_reg = NULL; + } + + return 0; +} + +/* + * Set isolation here for phy. + * SOCs control this by controlling corresponding PMU registers + */ +static void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, int on) +{ + void __iomem *usb_phyctrl_reg; + u32 en_mask = sphy->en_mask; + u32 reg; + + usb_phyctrl_reg = sphy->devctrl_reg; + + if (!usb_phyctrl_reg) { + dev_warn(sphy->dev, "Can't set pmu isolation\n"); + return; + } + + reg = readl(usb_phyctrl_reg); + + if (on) + writel(reg & ~en_mask, usb_phyctrl_reg); + else + writel(reg | en_mask, usb_phyctrl_reg); +} + /* * Returns reference clock frequency selection value */ @@ -199,6 +262,8 @@ static int samsung_usbphy_init(struct usb_phy *phy) /* Disable phy isolation */ if (sphy->plat && sphy->plat->pmu_isolation) sphy->plat->pmu_isolation(false); + else + samsung_usbphy_set_isolation(sphy, false); /* Initialize usb phy registers */ samsung_usbphy_enable(sphy); @@ -228,6 +293,8 @@ static void samsung_usbphy_shutdown(struct usb_phy *phy) /* Enable phy isolation */ if (sphy->plat && sphy->plat->pmu_isolation) sphy->plat->pmu_isolation(true); + else + samsung_usbphy_set_isolation(sphy, true); clk_disable_unprepare(sphy->clk); } @@ -249,17 +316,12 @@ static inline int samsung_usbphy_get_driver_data(struct platform_device *pdev) static int __devinit samsung_usbphy_probe(struct platform_device *pdev) { struct samsung_usbphy *sphy; - struct samsung_usbphy_data *pdata; + struct samsung_usbphy_data *pdata = pdev->dev.platform_data; struct device *dev = &pdev->dev; struct resource *phy_mem; void __iomem *phy_base; struct clk *clk; - - pdata = pdev->dev.platform_data; - if (!pdata) { - dev_err(&pdev->dev, "%s: no platform data defined\n", __func__); - return -EINVAL; - } + int ret; phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!phy_mem) { @@ -283,7 +345,20 @@ static int __devinit samsung_usbphy_probe(struct platform_device *pdev) return PTR_ERR(clk); } - sphy->dev = &pdev->dev; + sphy->dev = &pdev->dev; + + ret = samsung_usbphy_parse_dt_param(sphy); + if (ret) { + /* fallback to pdata */ + if (!pdata) { + dev_err(&pdev->dev, + "%s: no device data found\n", __func__); + return -ENODEV; + } else { + sphy->plat = pdata; + } + } + sphy->plat = pdata; sphy->regs = phy_base; sphy->clk = clk; @@ -305,6 +380,9 @@ static int __exit samsung_usbphy_remove(struct platform_device *pdev) usb_remove_phy(&sphy->phy); + if (sphy->devctrl_reg) + iounmap(sphy->devctrl_reg); + return 0; }