aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKishon Vijay Abraham I <kishon@ti.com>2013-01-25 05:23:57 -0500
committerFelipe Balbi <balbi@ti.com>2013-01-25 05:25:36 -0500
commit01658f0f8d1322dbf94f289aa610731d539bf888 (patch)
tree16bc8fc55d5ef86f062097a9bd28de6c6e8d0dac
parent5d3c28b5a42df5ceaa854901ba2cccb76883c77e (diff)
usb: phy: add a new driver for usb part of control module
Added a new driver for the usb part of control module. This has an API to power on the USB2 phy and an API to write to the mailbox depending on whether MUSB has to act in host mode or in device mode. Writing to control module registers for doing the above task which was previously done in omap glue and in omap-usb2 phy will be removed. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r--Documentation/devicetree/bindings/usb/omap-usb.txt30
-rw-r--r--Documentation/devicetree/bindings/usb/usb-phy.txt5
-rw-r--r--drivers/usb/phy/Kconfig10
-rw-r--r--drivers/usb/phy/Makefile1
-rw-r--r--drivers/usb/phy/omap-control-usb.c295
-rw-r--r--include/linux/usb/omap_control_usb.h92
6 files changed, 432 insertions, 1 deletions
diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
index 29a043ecda52..3d78cc2b486e 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -1,4 +1,4 @@
1OMAP GLUE 1OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
2 2
3OMAP MUSB GLUE 3OMAP MUSB GLUE
4 - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb" 4 - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
@@ -16,6 +16,10 @@ OMAP MUSB GLUE
16 - power : Should be "50". This signifies the controller can supply upto 16 - power : Should be "50". This signifies the controller can supply upto
17 100mA when operating in host mode. 17 100mA when operating in host mode.
18 18
19Optional properties:
20 - ctrl-module : phandle of the control module this glue uses to write to
21 mailbox
22
19SOC specific device node entry 23SOC specific device node entry
20usb_otg_hs: usb_otg_hs@4a0ab000 { 24usb_otg_hs: usb_otg_hs@4a0ab000 {
21 compatible = "ti,omap4-musb"; 25 compatible = "ti,omap4-musb";
@@ -23,6 +27,7 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
23 multipoint = <1>; 27 multipoint = <1>;
24 num_eps = <16>; 28 num_eps = <16>;
25 ram_bits = <12>; 29 ram_bits = <12>;
30 ctrl-module = <&omap_control_usb>;
26}; 31};
27 32
28Board specific device node entry 33Board specific device node entry
@@ -31,3 +36,26 @@ Board specific device node entry
31 mode = <3>; 36 mode = <3>;
32 power = <50>; 37 power = <50>;
33}; 38};
39
40OMAP CONTROL USB
41
42Required properties:
43 - compatible: Should be "ti,omap-control-usb"
44 - reg : Address and length of the register set for the device. It contains
45 the address of "control_dev_conf" and "otghs_control" or "phy_power_usb"
46 depending upon omap4 or omap5.
47 - reg-names: The names of the register addresses corresponding to the registers
48 filled in "reg".
49 - ti,type: This is used to differentiate whether the control module has
50 usb mailbox or usb3 phy power. omap4 has usb mailbox in control module to
51 notify events to the musb core and omap5 has usb3 phy power register to
52 power on usb3 phy. Should be "1" if it has mailbox and "2" if it has usb3
53 phy power.
54
55omap_control_usb: omap-control-usb@4a002300 {
56 compatible = "ti,omap-control-usb";
57 reg = <0x4a002300 0x4>,
58 <0x4a00233c 0x4>;
59 reg-names = "control_dev_conf", "otghs_control";
60 ti,type = <1>;
61};
diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
index 80d4148cb661..4234105302db 100644
--- a/Documentation/devicetree/bindings/usb/usb-phy.txt
+++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
@@ -8,10 +8,15 @@ Required properties:
8add the address of control module dev conf register until a driver for 8add the address of control module dev conf register until a driver for
9control module is added 9control module is added
10 10
11Optional properties:
12 - ctrl-module : phandle of the control module used by PHY driver to power on
13 the PHY.
14
11This is usually a subnode of ocp2scp to which it is connected. 15This is usually a subnode of ocp2scp to which it is connected.
12 16
13usb2phy@4a0ad080 { 17usb2phy@4a0ad080 {
14 compatible = "ti,omap-usb2"; 18 compatible = "ti,omap-usb2";
15 reg = <0x4a0ad080 0x58>, 19 reg = <0x4a0ad080 0x58>,
16 <0x4a002300 0x4>; 20 <0x4a002300 0x4>;
21 ctrl-module = <&omap_control_usb>;
17}; 22};
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index fae4d08c0ddd..053696a2b6ef 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -14,6 +14,16 @@ config OMAP_USB2
14 The USB OTG controller communicates with the comparator using this 14 The USB OTG controller communicates with the comparator using this
15 driver. 15 driver.
16 16
17config OMAP_CONTROL_USB
18 tristate "OMAP CONTROL USB Driver"
19 depends on ARCH_OMAP2PLUS
20 help
21 Enable this to add support for the USB part present in the control
22 module. This driver has API to power on the USB2 PHY and to write to
23 the mailbox. The mailbox is present only in omap4 and the register to
24 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an
25 additional register to power on USB3 PHY.
26
17config USB_ISP1301 27config USB_ISP1301
18 tristate "NXP ISP1301 USB transceiver support" 28 tristate "NXP ISP1301 USB transceiver support"
19 depends on USB || USB_GADGET 29 depends on USB || USB_GADGET
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index ec304f642402..ee977671f530 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -5,6 +5,7 @@
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG 5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6 6
7obj-$(CONFIG_OMAP_USB2) += omap-usb2.o 7obj-$(CONFIG_OMAP_USB2) += omap-usb2.o
8obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o
8obj-$(CONFIG_USB_ISP1301) += isp1301.o 9obj-$(CONFIG_USB_ISP1301) += isp1301.o
9obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o 10obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o
10obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o 11obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o
diff --git a/drivers/usb/phy/omap-control-usb.c b/drivers/usb/phy/omap-control-usb.c
new file mode 100644
index 000000000000..5323b71c3521
--- /dev/null
+++ b/drivers/usb/phy/omap-control-usb.c
@@ -0,0 +1,295 @@
1/*
2 * omap-control-usb.c - The USB part of control module.
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Author: Kishon Vijay Abraham I <kishon@ti.com>
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/slab.h>
22#include <linux/of.h>
23#include <linux/err.h>
24#include <linux/io.h>
25#include <linux/clk.h>
26#include <linux/usb/omap_control_usb.h>
27
28static struct omap_control_usb *control_usb;
29
30/**
31 * omap_get_control_dev - returns the device pointer for this control device
32 *
33 * This API should be called to get the device pointer for this control
34 * module device. This device pointer should be used for called other
35 * exported API's in this driver.
36 *
37 * To be used by PHY driver and glue driver.
38 */
39struct device *omap_get_control_dev(void)
40{
41 if (!control_usb)
42 return ERR_PTR(-ENODEV);
43
44 return control_usb->dev;
45}
46EXPORT_SYMBOL_GPL(omap_get_control_dev);
47
48/**
49 * omap_control_usb3_phy_power - power on/off the serializer using control
50 * module
51 * @dev: the control module device
52 * @on: 0 to off and 1 to on based on powering on or off the PHY
53 *
54 * usb3 PHY driver should call this API to power on or off the PHY.
55 */
56void omap_control_usb3_phy_power(struct device *dev, bool on)
57{
58 u32 val;
59 unsigned long rate;
60 struct omap_control_usb *control_usb = dev_get_drvdata(dev);
61
62 if (control_usb->type != OMAP_CTRL_DEV_TYPE2)
63 return;
64
65 rate = clk_get_rate(control_usb->sys_clk);
66 rate = rate/1000000;
67
68 val = readl(control_usb->phy_power);
69
70 if (on) {
71 val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK |
72 OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK);
73 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON <<
74 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
75 val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT;
76 } else {
77 val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK;
78 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
79 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
80 }
81
82 writel(val, control_usb->phy_power);
83}
84EXPORT_SYMBOL_GPL(omap_control_usb3_phy_power);
85
86/**
87 * omap_control_usb_phy_power - power on/off the phy using control module reg
88 * @dev: the control module device
89 * @on: 0 or 1, based on powering on or off the PHY
90 */
91void omap_control_usb_phy_power(struct device *dev, int on)
92{
93 u32 val;
94 struct omap_control_usb *control_usb = dev_get_drvdata(dev);
95
96 val = readl(control_usb->dev_conf);
97
98 if (on)
99 val &= ~OMAP_CTRL_DEV_PHY_PD;
100 else
101 val |= OMAP_CTRL_DEV_PHY_PD;
102
103 writel(val, control_usb->dev_conf);
104}
105EXPORT_SYMBOL_GPL(omap_control_usb_phy_power);
106
107/**
108 * omap_control_usb_host_mode - set AVALID, VBUSVALID and ID pin in grounded
109 * @ctrl_usb: struct omap_control_usb *
110 *
111 * Writes to the mailbox register to notify the usb core that a usb
112 * device has been connected.
113 */
114static void omap_control_usb_host_mode(struct omap_control_usb *ctrl_usb)
115{
116 u32 val;
117
118 val = readl(ctrl_usb->otghs_control);
119 val &= ~(OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_SESSEND);
120 val |= OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID;
121 writel(val, ctrl_usb->otghs_control);
122}
123
124/**
125 * omap_control_usb_device_mode - set AVALID, VBUSVALID and ID pin in high
126 * impedance
127 * @ctrl_usb: struct omap_control_usb *
128 *
129 * Writes to the mailbox register to notify the usb core that it has been
130 * connected to a usb host.
131 */
132static void omap_control_usb_device_mode(struct omap_control_usb *ctrl_usb)
133{
134 u32 val;
135
136 val = readl(ctrl_usb->otghs_control);
137 val &= ~OMAP_CTRL_DEV_SESSEND;
138 val |= OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_AVALID |
139 OMAP_CTRL_DEV_VBUSVALID;
140 writel(val, ctrl_usb->otghs_control);
141}
142
143/**
144 * omap_control_usb_set_sessionend - Enable SESSIONEND and IDIG to high
145 * impedance
146 * @ctrl_usb: struct omap_control_usb *
147 *
148 * Writes to the mailbox register to notify the usb core it's now in
149 * disconnected state.
150 */
151static void omap_control_usb_set_sessionend(struct omap_control_usb *ctrl_usb)
152{
153 u32 val;
154
155 val = readl(ctrl_usb->otghs_control);
156 val &= ~(OMAP_CTRL_DEV_AVALID | OMAP_CTRL_DEV_VBUSVALID);
157 val |= OMAP_CTRL_DEV_IDDIG | OMAP_CTRL_DEV_SESSEND;
158 writel(val, ctrl_usb->otghs_control);
159}
160
161/**
162 * omap_control_usb_set_mode - Calls to functions to set USB in one of host mode
163 * or device mode or to denote disconnected state
164 * @dev: the control module device
165 * @mode: The mode to which usb should be configured
166 *
167 * This is an API to write to the mailbox register to notify the usb core that
168 * a usb device has been connected.
169 */
170void omap_control_usb_set_mode(struct device *dev,
171 enum omap_control_usb_mode mode)
172{
173 struct omap_control_usb *ctrl_usb;
174
175 if (IS_ERR(dev) || control_usb->type != OMAP_CTRL_DEV_TYPE1)
176 return;
177
178 ctrl_usb = dev_get_drvdata(dev);
179
180 switch (mode) {
181 case USB_MODE_HOST:
182 omap_control_usb_host_mode(ctrl_usb);
183 break;
184 case USB_MODE_DEVICE:
185 omap_control_usb_device_mode(ctrl_usb);
186 break;
187 case USB_MODE_DISCONNECT:
188 omap_control_usb_set_sessionend(ctrl_usb);
189 break;
190 default:
191 dev_vdbg(dev, "invalid omap control usb mode\n");
192 }
193}
194EXPORT_SYMBOL_GPL(omap_control_usb_set_mode);
195
196static int omap_control_usb_probe(struct platform_device *pdev)
197{
198 struct resource *res;
199 struct device_node *np = pdev->dev.of_node;
200 struct omap_control_usb_platform_data *pdata = pdev->dev.platform_data;
201
202 control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
203 GFP_KERNEL);
204 if (!control_usb) {
205 dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
206 return -ENOMEM;
207 }
208
209 if (np) {
210 of_property_read_u32(np, "ti,type", &control_usb->type);
211 } else if (pdata) {
212 control_usb->type = pdata->type;
213 } else {
214 dev_err(&pdev->dev, "no pdata present\n");
215 return -EINVAL;
216 }
217
218 control_usb->dev = &pdev->dev;
219
220 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
221 "control_dev_conf");
222 control_usb->dev_conf = devm_request_and_ioremap(&pdev->dev, res);
223 if (!control_usb->dev_conf) {
224 dev_err(&pdev->dev, "Failed to obtain io memory\n");
225 return -EADDRNOTAVAIL;
226 }
227
228 if (control_usb->type == OMAP_CTRL_DEV_TYPE1) {
229 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
230 "otghs_control");
231 control_usb->otghs_control = devm_request_and_ioremap(
232 &pdev->dev, res);
233 if (!control_usb->otghs_control) {
234 dev_err(&pdev->dev, "Failed to obtain io memory\n");
235 return -EADDRNOTAVAIL;
236 }
237 }
238
239 if (control_usb->type == OMAP_CTRL_DEV_TYPE2) {
240 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
241 "phy_power_usb");
242 control_usb->phy_power = devm_request_and_ioremap(
243 &pdev->dev, res);
244 if (!control_usb->phy_power) {
245 dev_dbg(&pdev->dev, "Failed to obtain io memory\n");
246 return -EADDRNOTAVAIL;
247 }
248
249 control_usb->sys_clk = devm_clk_get(control_usb->dev,
250 "sys_clkin");
251 if (IS_ERR(control_usb->sys_clk)) {
252 pr_err("%s: unable to get sys_clkin\n", __func__);
253 return -EINVAL;
254 }
255 }
256
257
258 dev_set_drvdata(control_usb->dev, control_usb);
259
260 return 0;
261}
262
263#ifdef CONFIG_OF
264static const struct of_device_id omap_control_usb_id_table[] = {
265 { .compatible = "ti,omap-control-usb" },
266 {}
267};
268MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
269#endif
270
271static struct platform_driver omap_control_usb_driver = {
272 .probe = omap_control_usb_probe,
273 .driver = {
274 .name = "omap-control-usb",
275 .owner = THIS_MODULE,
276 .of_match_table = of_match_ptr(omap_control_usb_id_table),
277 },
278};
279
280static int __init omap_control_usb_init(void)
281{
282 return platform_driver_register(&omap_control_usb_driver);
283}
284subsys_initcall(omap_control_usb_init);
285
286static void __exit omap_control_usb_exit(void)
287{
288 platform_driver_unregister(&omap_control_usb_driver);
289}
290module_exit(omap_control_usb_exit);
291
292MODULE_ALIAS("platform: omap_control_usb");
293MODULE_AUTHOR("Texas Instruments Inc.");
294MODULE_DESCRIPTION("OMAP Control Module USB Driver");
295MODULE_LICENSE("GPL v2");
diff --git a/include/linux/usb/omap_control_usb.h b/include/linux/usb/omap_control_usb.h
new file mode 100644
index 000000000000..f306db7149ca
--- /dev/null
+++ b/include/linux/usb/omap_control_usb.h
@@ -0,0 +1,92 @@
1/*
2 * omap_control_usb.h - Header file for the USB part of control module.
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Author: Kishon Vijay Abraham I <kishon@ti.com>
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#ifndef __OMAP_CONTROL_USB_H__
20#define __OMAP_CONTROL_USB_H__
21
22struct omap_control_usb {
23 struct device *dev;
24
25 u32 __iomem *dev_conf;
26 u32 __iomem *otghs_control;
27 u32 __iomem *phy_power;
28
29 struct clk *sys_clk;
30
31 u32 type;
32};
33
34struct omap_control_usb_platform_data {
35 u8 type;
36};
37
38enum omap_control_usb_mode {
39 USB_MODE_UNDEFINED = 0,
40 USB_MODE_HOST,
41 USB_MODE_DEVICE,
42 USB_MODE_DISCONNECT,
43};
44
45/* To differentiate ctrl module IP having either mailbox or USB3 PHY power */
46#define OMAP_CTRL_DEV_TYPE1 0x1
47#define OMAP_CTRL_DEV_TYPE2 0x2
48
49#define OMAP_CTRL_DEV_PHY_PD BIT(0)
50
51#define OMAP_CTRL_DEV_AVALID BIT(0)
52#define OMAP_CTRL_DEV_BVALID BIT(1)
53#define OMAP_CTRL_DEV_VBUSVALID BIT(2)
54#define OMAP_CTRL_DEV_SESSEND BIT(3)
55#define OMAP_CTRL_DEV_IDDIG BIT(4)
56
57#define OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK 0x003FC000
58#define OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT 0xE
59
60#define OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK 0xFFC00000
61#define OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT 0x16
62
63#define OMAP_CTRL_USB3_PHY_TX_RX_POWERON 0x3
64#define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF 0x0
65
66#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)
67extern struct device *omap_get_control_dev(void);
68extern void omap_control_usb_phy_power(struct device *dev, int on);
69extern void omap_control_usb3_phy_power(struct device *dev, bool on);
70extern void omap_control_usb_set_mode(struct device *dev,
71 enum omap_control_usb_mode mode);
72#else
73static inline struct device *omap_get_control_dev()
74{
75 return ERR_PTR(-ENODEV);
76}
77
78static inline void omap_control_usb_phy_power(struct device *dev, int on)
79{
80}
81
82static inline void omap_control_usb3_phy_power(struct device *dev, int on)
83{
84}
85
86static inline void omap_control_usb_set_mode(struct device *dev,
87 enum omap_control_usb_mode mode)
88{
89}
90#endif
91
92#endif /* __OMAP_CONTROL_USB_H__ */