aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>2015-11-29 20:44:30 -0500
committerKishon Vijay Abraham I <kishon@ti.com>2015-12-20 04:51:37 -0500
commitf3b5a8d9b50d71b8c9fb72aa9c8ea948ad1a4ef9 (patch)
tree65900f3c4180211a534a8038562261c3febea95e
parent708744628ba96ed4dfcac74a985eb66ad551f164 (diff)
phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver
This patch adds support for R-Car generation 3 USB2 PHY driver. This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared with the HSUSB (USB2.0 peripheral) device. And each channel has independent registers about the PHYs. So, the purpose of this driver is: 1) initializes some registers of SoC specific to use the {ehci,ohci}-platform driver. 2) detects id pin to select host or peripheral on the channel 0. For now, this driver only supports 1) above. Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
-rw-r--r--Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt37
-rw-r--r--drivers/phy/Kconfig7
-rw-r--r--drivers/phy/Makefile1
-rw-r--r--drivers/phy/phy-rcar-gen3-usb2.c217
4 files changed, 262 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
new file mode 100644
index 000000000000..affa0f72658b
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -0,0 +1,37 @@
1* Renesas R-Car generation 3 USB 2.0 PHY
2
3This file provides information on what the device node for the R-Car generation
43 USB 2.0 PHY contains.
5
6Required properties:
7- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795
8 SoC.
9- reg: offset and length of the partial USB 2.0 Host register block.
10- reg-names: must be "usb2_host".
11- clocks: clock phandle and specifier pair(s).
12- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
13
14Optional properties:
15To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are
16combined, the device tree node should set HSUSB properties to reg and reg-names
17properties. This is because HSUSB has registers to select USB 2.0 host or
18peripheral at that channel:
19- reg: offset and length of the partial HSUSB register block.
20- reg-names: must be "hsusb".
21
22Example (R-Car H3):
23
24 usb-phy@ee080200 {
25 compatible = "renesas,usb2-phy-r8a7795";
26 reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
27 reg-names = "usb2_host", "hsusb";
28 clocks = <&mstp7_clks R8A7795_CLK_EHCI0>,
29 <&mstp7_clks R8A7795_CLK_HSUSB>;
30 };
31
32 usb-phy@ee0a0200 {
33 compatible = "renesas,usb2-phy-r8a7795";
34 reg = <0 0xee0a0200 0 0x700>;
35 reg-names = "usb2_host";
36 clocks = <&mstp7_clks R8A7795_CLK_EHCI0>;
37 };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 03cb3ea2d2c0..f90b7660dd3e 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -118,6 +118,13 @@ config PHY_RCAR_GEN2
118 help 118 help
119 Support for USB PHY found on Renesas R-Car generation 2 SoCs. 119 Support for USB PHY found on Renesas R-Car generation 2 SoCs.
120 120
121config PHY_RCAR_GEN3_USB2
122 tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
123 depends on OF && ARCH_SHMOBILE
124 select GENERIC_PHY
125 help
126 Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
127
121config OMAP_CONTROL_PHY 128config OMAP_CONTROL_PHY
122 tristate "OMAP CONTROL PHY Driver" 129 tristate "OMAP CONTROL PHY Driver"
123 depends on ARCH_OMAP2PLUS || COMPILE_TEST 130 depends on ARCH_OMAP2PLUS || COMPILE_TEST
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 075db1a81aa5..91d7a62c6794 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA) += phy-mvebu-sata.o
17obj-$(CONFIG_PHY_MIPHY28LP) += phy-miphy28lp.o 17obj-$(CONFIG_PHY_MIPHY28LP) += phy-miphy28lp.o
18obj-$(CONFIG_PHY_MIPHY365X) += phy-miphy365x.o 18obj-$(CONFIG_PHY_MIPHY365X) += phy-miphy365x.o
19obj-$(CONFIG_PHY_RCAR_GEN2) += phy-rcar-gen2.o 19obj-$(CONFIG_PHY_RCAR_GEN2) += phy-rcar-gen2.o
20obj-$(CONFIG_PHY_RCAR_GEN3_USB2) += phy-rcar-gen3-usb2.o
20obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o 21obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o
21obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o 22obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
22obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o 23obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
new file mode 100644
index 000000000000..269615228b1b
--- /dev/null
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -0,0 +1,217 @@
1/*
2 * Renesas R-Car Gen3 for USB2.0 PHY driver
3 *
4 * Copyright (C) 2015 Renesas Electronics Corporation
5 *
6 * This is based on the phy-rcar-gen2 driver:
7 * Copyright (C) 2014 Renesas Solutions Corp.
8 * Copyright (C) 2014 Cogent Embedded, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/io.h>
16#include <linux/module.h>
17#include <linux/of.h>
18#include <linux/of_address.h>
19#include <linux/phy/phy.h>
20#include <linux/platform_device.h>
21
22/******* USB2.0 Host registers (original offset is +0x200) *******/
23#define USB2_INT_ENABLE 0x000
24#define USB2_USBCTR 0x00c
25#define USB2_SPD_RSM_TIMSET 0x10c
26#define USB2_OC_TIMSET 0x110
27
28/* INT_ENABLE */
29#define USB2_INT_ENABLE_USBH_INTB_EN BIT(2)
30#define USB2_INT_ENABLE_USBH_INTA_EN BIT(1)
31#define USB2_INT_ENABLE_INIT (USB2_INT_ENABLE_USBH_INTB_EN | \
32 USB2_INT_ENABLE_USBH_INTA_EN)
33
34/* USBCTR */
35#define USB2_USBCTR_DIRPD BIT(2)
36#define USB2_USBCTR_PLL_RST BIT(1)
37
38/* SPD_RSM_TIMSET */
39#define USB2_SPD_RSM_TIMSET_INIT 0x014e029b
40
41/* OC_TIMSET */
42#define USB2_OC_TIMSET_INIT 0x000209ab
43
44/******* HSUSB registers (original offset is +0x100) *******/
45#define HSUSB_LPSTS 0x02
46#define HSUSB_UGCTRL2 0x84
47
48/* Low Power Status register (LPSTS) */
49#define HSUSB_LPSTS_SUSPM 0x4000
50
51/* USB General control register 2 (UGCTRL2) */
52#define HSUSB_UGCTRL2_MASK 0x00000031 /* bit[31:6] should be 0 */
53#define HSUSB_UGCTRL2_USB0SEL 0x00000030
54#define HSUSB_UGCTRL2_USB0SEL_HOST 0x00000010
55#define HSUSB_UGCTRL2_USB0SEL_HS_USB 0x00000020
56#define HSUSB_UGCTRL2_USB0SEL_OTG 0x00000030
57
58struct rcar_gen3_data {
59 void __iomem *base;
60 struct clk *clk;
61};
62
63struct rcar_gen3_chan {
64 struct rcar_gen3_data usb2;
65 struct rcar_gen3_data hsusb;
66 struct phy *phy;
67};
68
69static int rcar_gen3_phy_usb2_init(struct phy *p)
70{
71 struct rcar_gen3_chan *channel = phy_get_drvdata(p);
72 void __iomem *usb2_base = channel->usb2.base;
73 void __iomem *hsusb_base = channel->hsusb.base;
74 u32 val;
75
76 /* Initialize USB2 part */
77 writel(USB2_INT_ENABLE_INIT, usb2_base + USB2_INT_ENABLE);
78 writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET);
79 writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET);
80
81 /* Initialize HSUSB part */
82 if (hsusb_base) {
83 /* TODO: support "OTG" mode */
84 val = readl(hsusb_base + HSUSB_UGCTRL2);
85 val = (val & ~HSUSB_UGCTRL2_USB0SEL) |
86 HSUSB_UGCTRL2_USB0SEL_HOST;
87 writel(val & HSUSB_UGCTRL2_MASK, hsusb_base + HSUSB_UGCTRL2);
88 }
89
90 return 0;
91}
92
93static int rcar_gen3_phy_usb2_exit(struct phy *p)
94{
95 struct rcar_gen3_chan *channel = phy_get_drvdata(p);
96
97 writel(0, channel->usb2.base + USB2_INT_ENABLE);
98
99 return 0;
100}
101
102static int rcar_gen3_phy_usb2_power_on(struct phy *p)
103{
104 struct rcar_gen3_chan *channel = phy_get_drvdata(p);
105 void __iomem *usb2_base = channel->usb2.base;
106 void __iomem *hsusb_base = channel->hsusb.base;
107 u32 val;
108
109 val = readl(usb2_base + USB2_USBCTR);
110 val |= USB2_USBCTR_PLL_RST;
111 writel(val, usb2_base + USB2_USBCTR);
112 val &= ~USB2_USBCTR_PLL_RST;
113 writel(val, usb2_base + USB2_USBCTR);
114
115 /*
116 * TODO: To reduce power consuming, this driver should set the SUSPM
117 * after the PHY detects ID pin as peripheral.
118 */
119 if (hsusb_base) {
120 /* Power on HSUSB PHY */
121 val = readw(hsusb_base + HSUSB_LPSTS);
122 val |= HSUSB_LPSTS_SUSPM;
123 writew(val, hsusb_base + HSUSB_LPSTS);
124 }
125
126 return 0;
127}
128
129static int rcar_gen3_phy_usb2_power_off(struct phy *p)
130{
131 struct rcar_gen3_chan *channel = phy_get_drvdata(p);
132 void __iomem *hsusb_base = channel->hsusb.base;
133 u32 val;
134
135 if (hsusb_base) {
136 /* Power off HSUSB PHY */
137 val = readw(hsusb_base + HSUSB_LPSTS);
138 val &= ~HSUSB_LPSTS_SUSPM;
139 writew(val, hsusb_base + HSUSB_LPSTS);
140 }
141
142 return 0;
143}
144
145static struct phy_ops rcar_gen3_phy_usb2_ops = {
146 .init = rcar_gen3_phy_usb2_init,
147 .exit = rcar_gen3_phy_usb2_exit,
148 .power_on = rcar_gen3_phy_usb2_power_on,
149 .power_off = rcar_gen3_phy_usb2_power_off,
150 .owner = THIS_MODULE,
151};
152
153static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
154 { .compatible = "renesas,usb2-phy-r8a7795" },
155 { }
156};
157MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table);
158
159static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
160{
161 struct device *dev = &pdev->dev;
162 struct rcar_gen3_chan *channel;
163 struct phy_provider *provider;
164 struct resource *res;
165
166 if (!dev->of_node) {
167 dev_err(dev, "This driver needs device tree\n");
168 return -EINVAL;
169 }
170
171 channel = devm_kzalloc(dev, sizeof(*channel), GFP_KERNEL);
172 if (!channel)
173 return -ENOMEM;
174
175 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "usb2_host");
176 channel->usb2.base = devm_ioremap_resource(dev, res);
177 if (IS_ERR(channel->usb2.base))
178 return PTR_ERR(channel->usb2.base);
179
180 /* "hsusb" memory resource is optional */
181 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsusb");
182
183 /* To avoid error message by devm_ioremap_resource() */
184 if (res) {
185 channel->hsusb.base = devm_ioremap_resource(dev, res);
186 if (IS_ERR(channel->hsusb.base))
187 channel->hsusb.base = NULL;
188 }
189
190 /* devm_phy_create() will call pm_runtime_enable(dev); */
191 channel->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb2_ops);
192 if (IS_ERR(channel->phy)) {
193 dev_err(dev, "Failed to create USB2 PHY\n");
194 return PTR_ERR(channel->phy);
195 }
196
197 phy_set_drvdata(channel->phy, channel);
198
199 provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
200 if (IS_ERR(provider))
201 dev_err(dev, "Failed to register PHY provider\n");
202
203 return PTR_ERR_OR_ZERO(provider);
204}
205
206static struct platform_driver rcar_gen3_phy_usb2_driver = {
207 .driver = {
208 .name = "phy_rcar_gen3_usb2",
209 .of_match_table = rcar_gen3_phy_usb2_match_table,
210 },
211 .probe = rcar_gen3_phy_usb2_probe,
212};
213module_platform_driver(rcar_gen3_phy_usb2_driver);
214
215MODULE_LICENSE("GPL v2");
216MODULE_DESCRIPTION("Renesas R-Car Gen3 USB 2.0 PHY");
217MODULE_AUTHOR("Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>");