diff options
-rw-r--r-- | Documentation/devicetree/bindings/usb/ci13xxx-imx.txt | 5 | ||||
-rw-r--r-- | Documentation/devicetree/bindings/usb/usbmisc-imx.txt | 14 | ||||
-rw-r--r-- | drivers/usb/chipidea/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/chipidea/ci13xxx_imx.c | 64 | ||||
-rw-r--r-- | drivers/usb/chipidea/ci13xxx_imx.h | 28 | ||||
-rw-r--r-- | drivers/usb/chipidea/usbmisc_imx6q.c | 162 |
6 files changed, 274 insertions, 1 deletions
diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt index 2c290418bb2d..5778b9c83bd8 100644 --- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt +++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt | |||
@@ -7,7 +7,10 @@ Required properties: | |||
7 | 7 | ||
8 | Optional properties: | 8 | Optional properties: |
9 | - fsl,usbphy: phandler of usb phy that connects to the only one port | 9 | - fsl,usbphy: phandler of usb phy that connects to the only one port |
10 | - fsl,usbmisc: phandler of non-core register device, with one argument | ||
11 | that indicate usb controller index | ||
10 | - vbus-supply: regulator for vbus | 12 | - vbus-supply: regulator for vbus |
13 | - disable-over-current: disable over current detect | ||
11 | 14 | ||
12 | Examples: | 15 | Examples: |
13 | usb@02184000 { /* USB OTG */ | 16 | usb@02184000 { /* USB OTG */ |
@@ -15,4 +18,6 @@ usb@02184000 { /* USB OTG */ | |||
15 | reg = <0x02184000 0x200>; | 18 | reg = <0x02184000 0x200>; |
16 | interrupts = <0 43 0x04>; | 19 | interrupts = <0 43 0x04>; |
17 | fsl,usbphy = <&usbphy1>; | 20 | fsl,usbphy = <&usbphy1>; |
21 | fsl,usbmisc = <&usbmisc 0>; | ||
22 | disable-over-current; | ||
18 | }; | 23 | }; |
diff --git a/Documentation/devicetree/bindings/usb/usbmisc-imx.txt b/Documentation/devicetree/bindings/usb/usbmisc-imx.txt new file mode 100644 index 000000000000..97ce94e1a6cc --- /dev/null +++ b/Documentation/devicetree/bindings/usb/usbmisc-imx.txt | |||
@@ -0,0 +1,14 @@ | |||
1 | * Freescale i.MX non-core registers | ||
2 | |||
3 | Required properties: | ||
4 | - #index-cells: Cells used to descibe usb controller index. Should be <1> | ||
5 | - compatible: Should be one of below: | ||
6 | "fsl,imx6q-usbmisc" for imx6q | ||
7 | - reg: Should contain registers location and length | ||
8 | |||
9 | Examples: | ||
10 | usbmisc@02184800 { | ||
11 | #index-cells = <1>; | ||
12 | compatible = "fsl,imx6q-usbmisc"; | ||
13 | reg = <0x02184800 0x200>; | ||
14 | }; | ||
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile index 5c66d9c330ca..57e510f6c245 100644 --- a/drivers/usb/chipidea/Makefile +++ b/drivers/usb/chipidea/Makefile | |||
@@ -15,5 +15,5 @@ ifneq ($(CONFIG_PCI),) | |||
15 | endif | 15 | endif |
16 | 16 | ||
17 | ifneq ($(CONFIG_OF_DEVICE),) | 17 | ifneq ($(CONFIG_OF_DEVICE),) |
18 | obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o | 18 | obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o usbmisc_imx6q.o |
19 | endif | 19 | endif |
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c index ef60d06835d0..96ac67bbd2db 100644 --- a/drivers/usb/chipidea/ci13xxx_imx.c +++ b/drivers/usb/chipidea/ci13xxx_imx.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/regulator/consumer.h> | 22 | #include <linux/regulator/consumer.h> |
23 | 23 | ||
24 | #include "ci.h" | 24 | #include "ci.h" |
25 | #include "ci13xxx_imx.h" | ||
25 | 26 | ||
26 | #define pdev_to_phy(pdev) \ | 27 | #define pdev_to_phy(pdev) \ |
27 | ((struct usb_phy *)platform_get_drvdata(pdev)) | 28 | ((struct usb_phy *)platform_get_drvdata(pdev)) |
@@ -34,6 +35,55 @@ struct ci13xxx_imx_data { | |||
34 | struct regulator *reg_vbus; | 35 | struct regulator *reg_vbus; |
35 | }; | 36 | }; |
36 | 37 | ||
38 | static const struct usbmisc_ops *usbmisc_ops; | ||
39 | |||
40 | /* Common functions shared by usbmisc drivers */ | ||
41 | |||
42 | int usbmisc_set_ops(const struct usbmisc_ops *ops) | ||
43 | { | ||
44 | if (usbmisc_ops) | ||
45 | return -EBUSY; | ||
46 | |||
47 | usbmisc_ops = ops; | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | EXPORT_SYMBOL_GPL(usbmisc_set_ops); | ||
52 | |||
53 | void usbmisc_unset_ops(const struct usbmisc_ops *ops) | ||
54 | { | ||
55 | usbmisc_ops = NULL; | ||
56 | } | ||
57 | EXPORT_SYMBOL_GPL(usbmisc_unset_ops); | ||
58 | |||
59 | int usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device *usbdev) | ||
60 | { | ||
61 | struct device_node *np = dev->of_node; | ||
62 | struct of_phandle_args args; | ||
63 | int ret; | ||
64 | |||
65 | usbdev->dev = dev; | ||
66 | |||
67 | ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells", | ||
68 | 0, &args); | ||
69 | if (ret) { | ||
70 | dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n", | ||
71 | ret); | ||
72 | memset(usbdev, 0, sizeof(*usbdev)); | ||
73 | return ret; | ||
74 | } | ||
75 | usbdev->index = args.args[0]; | ||
76 | of_node_put(args.np); | ||
77 | |||
78 | if (of_find_property(np, "disable-over-current", NULL)) | ||
79 | usbdev->disable_oc = 1; | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | EXPORT_SYMBOL_GPL(usbmisc_get_init_data); | ||
84 | |||
85 | /* End of common functions shared by usbmisc drivers*/ | ||
86 | |||
37 | static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata = { | 87 | static struct ci13xxx_platform_data ci13xxx_imx_platdata __devinitdata = { |
38 | .name = "ci13xxx_imx", | 88 | .name = "ci13xxx_imx", |
39 | .flags = CI13XXX_REQUIRE_TRANSCEIVER | | 89 | .flags = CI13XXX_REQUIRE_TRANSCEIVER | |
@@ -51,6 +101,10 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev) | |||
51 | struct regulator *reg_vbus; | 101 | struct regulator *reg_vbus; |
52 | int ret; | 102 | int ret; |
53 | 103 | ||
104 | if (of_find_property(pdev->dev.of_node, "fsl,usbmisc", NULL) | ||
105 | && !usbmisc_ops) | ||
106 | return -EPROBE_DEFER; | ||
107 | |||
54 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | 108 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
55 | if (!data) { | 109 | if (!data) { |
56 | dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n"); | 110 | dev_err(&pdev->dev, "Failed to allocate CI13xxx-IMX data!\n"); |
@@ -120,6 +174,16 @@ static int __devinit ci13xxx_imx_probe(struct platform_device *pdev) | |||
120 | *pdev->dev.dma_mask = DMA_BIT_MASK(32); | 174 | *pdev->dev.dma_mask = DMA_BIT_MASK(32); |
121 | dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask); | 175 | dma_set_coherent_mask(&pdev->dev, *pdev->dev.dma_mask); |
122 | } | 176 | } |
177 | |||
178 | if (usbmisc_ops && usbmisc_ops->init) { | ||
179 | ret = usbmisc_ops->init(&pdev->dev); | ||
180 | if (ret) { | ||
181 | dev_err(&pdev->dev, | ||
182 | "usbmisc init failed, ret=%d\n", ret); | ||
183 | goto err; | ||
184 | } | ||
185 | } | ||
186 | |||
123 | plat_ci = ci13xxx_add_device(&pdev->dev, | 187 | plat_ci = ci13xxx_add_device(&pdev->dev, |
124 | pdev->resource, pdev->num_resources, | 188 | pdev->resource, pdev->num_resources, |
125 | &ci13xxx_imx_platdata); | 189 | &ci13xxx_imx_platdata); |
diff --git a/drivers/usb/chipidea/ci13xxx_imx.h b/drivers/usb/chipidea/ci13xxx_imx.h new file mode 100644 index 000000000000..2e88accb3d67 --- /dev/null +++ b/drivers/usb/chipidea/ci13xxx_imx.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | |||
12 | /* Used to set SoC specific callbacks */ | ||
13 | struct usbmisc_ops { | ||
14 | /* It's called once when probe a usb device */ | ||
15 | int (*init)(struct device *dev); | ||
16 | }; | ||
17 | |||
18 | struct usbmisc_usb_device { | ||
19 | struct device *dev; /* usb controller device */ | ||
20 | int index; | ||
21 | |||
22 | int disable_oc:1; /* over current detect disabled */ | ||
23 | }; | ||
24 | |||
25 | int usbmisc_set_ops(const struct usbmisc_ops *ops); | ||
26 | void usbmisc_unset_ops(const struct usbmisc_ops *ops); | ||
27 | int | ||
28 | usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device *usbdev); | ||
diff --git a/drivers/usb/chipidea/usbmisc_imx6q.c b/drivers/usb/chipidea/usbmisc_imx6q.c new file mode 100644 index 000000000000..416e3fc58fd0 --- /dev/null +++ b/drivers/usb/chipidea/usbmisc_imx6q.c | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * The code contained herein is licensed under the GNU General Public | ||
5 | * License. You may obtain a copy of the GNU General Public License | ||
6 | * Version 2 or later at the following locations: | ||
7 | * | ||
8 | * http://www.opensource.org/licenses/gpl-license.html | ||
9 | * http://www.gnu.org/copyleft/gpl.html | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/of_platform.h> | ||
14 | #include <linux/clk.h> | ||
15 | #include <linux/err.h> | ||
16 | #include <linux/io.h> | ||
17 | |||
18 | #include "ci13xxx_imx.h" | ||
19 | |||
20 | #define USB_DEV_MAX 4 | ||
21 | |||
22 | #define BM_OVER_CUR_DIS BIT(7) | ||
23 | |||
24 | struct imx6q_usbmisc { | ||
25 | void __iomem *base; | ||
26 | spinlock_t lock; | ||
27 | struct clk *clk; | ||
28 | struct usbmisc_usb_device usbdev[USB_DEV_MAX]; | ||
29 | }; | ||
30 | |||
31 | static struct imx6q_usbmisc *usbmisc; | ||
32 | |||
33 | static struct usbmisc_usb_device *get_usbdev(struct device *dev) | ||
34 | { | ||
35 | int i, ret; | ||
36 | |||
37 | for (i = 0; i < USB_DEV_MAX; i++) { | ||
38 | if (usbmisc->usbdev[i].dev == dev) | ||
39 | return &usbmisc->usbdev[i]; | ||
40 | else if (!usbmisc->usbdev[i].dev) | ||
41 | break; | ||
42 | } | ||
43 | |||
44 | if (i >= USB_DEV_MAX) | ||
45 | return ERR_PTR(-EBUSY); | ||
46 | |||
47 | ret = usbmisc_get_init_data(dev, &usbmisc->usbdev[i]); | ||
48 | if (ret) | ||
49 | return ERR_PTR(ret); | ||
50 | |||
51 | return &usbmisc->usbdev[i]; | ||
52 | } | ||
53 | |||
54 | static int usbmisc_imx6q_init(struct device *dev) | ||
55 | { | ||
56 | |||
57 | struct usbmisc_usb_device *usbdev; | ||
58 | unsigned long flags; | ||
59 | u32 reg; | ||
60 | |||
61 | usbdev = get_usbdev(dev); | ||
62 | if (IS_ERR(usbdev)) | ||
63 | return PTR_ERR(usbdev); | ||
64 | |||
65 | if (usbdev->disable_oc) { | ||
66 | spin_lock_irqsave(&usbmisc->lock, flags); | ||
67 | reg = readl(usbmisc->base + usbdev->index * 4); | ||
68 | writel(reg | BM_OVER_CUR_DIS, | ||
69 | usbmisc->base + usbdev->index * 4); | ||
70 | spin_unlock_irqrestore(&usbmisc->lock, flags); | ||
71 | } | ||
72 | |||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | static const struct usbmisc_ops imx6q_usbmisc_ops = { | ||
77 | .init = usbmisc_imx6q_init, | ||
78 | }; | ||
79 | |||
80 | static const struct of_device_id usbmisc_imx6q_dt_ids[] = { | ||
81 | { .compatible = "fsl,imx6q-usbmisc"}, | ||
82 | { /* sentinel */ } | ||
83 | }; | ||
84 | |||
85 | static int __devinit usbmisc_imx6q_probe(struct platform_device *pdev) | ||
86 | { | ||
87 | struct resource *res; | ||
88 | struct imx6q_usbmisc *data; | ||
89 | int ret; | ||
90 | |||
91 | if (usbmisc) | ||
92 | return -EBUSY; | ||
93 | |||
94 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | ||
95 | if (!data) | ||
96 | return -ENOMEM; | ||
97 | |||
98 | spin_lock_init(&data->lock); | ||
99 | |||
100 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
101 | data->base = devm_request_and_ioremap(&pdev->dev, res); | ||
102 | if (!data->base) | ||
103 | return -EADDRNOTAVAIL; | ||
104 | |||
105 | data->clk = devm_clk_get(&pdev->dev, NULL); | ||
106 | if (IS_ERR(data->clk)) { | ||
107 | dev_err(&pdev->dev, | ||
108 | "failed to get clock, err=%ld\n", PTR_ERR(data->clk)); | ||
109 | return PTR_ERR(data->clk); | ||
110 | } | ||
111 | |||
112 | ret = clk_prepare_enable(data->clk); | ||
113 | if (ret) { | ||
114 | dev_err(&pdev->dev, | ||
115 | "clk_prepare_enable failed, err=%d\n", ret); | ||
116 | return ret; | ||
117 | } | ||
118 | |||
119 | ret = usbmisc_set_ops(&imx6q_usbmisc_ops); | ||
120 | if (ret) { | ||
121 | clk_disable_unprepare(data->clk); | ||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | usbmisc = data; | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static int __devexit usbmisc_imx6q_remove(struct platform_device *pdev) | ||
131 | { | ||
132 | usbmisc_unset_ops(&imx6q_usbmisc_ops); | ||
133 | clk_disable_unprepare(usbmisc->clk); | ||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | static struct platform_driver usbmisc_imx6q_driver = { | ||
138 | .probe = usbmisc_imx6q_probe, | ||
139 | .remove = __devexit_p(usbmisc_imx6q_remove), | ||
140 | .driver = { | ||
141 | .name = "usbmisc_imx6q", | ||
142 | .owner = THIS_MODULE, | ||
143 | .of_match_table = usbmisc_imx6q_dt_ids, | ||
144 | }, | ||
145 | }; | ||
146 | |||
147 | int __init usbmisc_imx6q_drv_init(void) | ||
148 | { | ||
149 | return platform_driver_register(&usbmisc_imx6q_driver); | ||
150 | } | ||
151 | subsys_initcall(usbmisc_imx6q_drv_init); | ||
152 | |||
153 | void __exit usbmisc_imx6q_drv_exit(void) | ||
154 | { | ||
155 | platform_driver_unregister(&usbmisc_imx6q_driver); | ||
156 | } | ||
157 | module_exit(usbmisc_imx6q_drv_exit); | ||
158 | |||
159 | MODULE_ALIAS("platform:usbmisc-imx6q"); | ||
160 | MODULE_LICENSE("GPL v2"); | ||
161 | MODULE_DESCRIPTION("driver for imx6q usb non-core registers"); | ||
162 | MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>"); | ||