ppc40x: preliminary support for 3.3
[openwrt/openwrt.git] / target / linux / ppc40x / patches-3.3 / 120-usb-isp116x-hcd-add-of-binding.patch
1 --- a/drivers/usb/host/isp116x-hcd.c
2 +++ b/drivers/usb/host/isp116x-hcd.c
3 @@ -1535,6 +1535,7 @@ static struct hc_driver isp116x_hc_drive
4
5 /*----------------------------------------------------------------*/
6
7 +#ifdef CONFIG_USB_ISP116X_HCD_PLATFORM
8 static int isp116x_remove(struct platform_device *pdev)
9 {
10 struct usb_hcd *hcd = platform_get_drvdata(pdev);
11 @@ -1708,22 +1709,249 @@ static struct platform_driver isp116x_dr
12 },
13 };
14
15 +static inline int isp116x_platform_register(void)
16 +{
17 + return platform_driver_register(&isp116x_driver);
18 +}
19 +
20 +static inline void isp116x_platform_unregister(void)
21 +{
22 + platform_driver_unregister(&isp116x_driver);
23 +}
24 +#else
25 +static inline int isp116x_platform_register(void) { return 0; };
26 +static void isp116x_platform_unregister(void) {};
27 +#endif /* CONFIG_USB_ISP116X_PLATFORM */
28 +
29 +/*-----------------------------------------------------------------*/
30 +
31 +#ifdef CONFIG_USB_ISP116X_HCD_OF
32 +
33 +#include <linux/of_platform.h>
34 +
35 +#ifdef USE_PLATFORM_DELAY
36 +static void isp116x_of_delay(struct device *ddev, int delay)
37 +{
38 + ndelay(delay);
39 +}
40 +#else
41 +#define isp116x_of_delay NULL
42 +#endif
43 +
44 +static int __devinit isp116x_of_probe(struct platform_device *op)
45 +{
46 + struct device_node *dn = op->dev.of_node;
47 + struct usb_hcd *hcd;
48 + struct isp116x *isp116x;
49 + struct resource addr, data;
50 + struct isp116x_platform_data *board;
51 + void __iomem *addr_reg;
52 + void __iomem *data_reg;
53 + int irq;
54 + int ret = 0;
55 + unsigned long irqflags;
56 +
57 + ret = of_address_to_resource(dn, 0, &data);
58 + if (ret)
59 + return ret;
60 +
61 + ret = of_address_to_resource(dn, 1, &addr);
62 + if (ret)
63 + return ret;
64 +
65 + board = kzalloc(sizeof(struct isp116x_platform_data), GFP_KERNEL);
66 + if (board == NULL)
67 + return -ENOMEM;
68 +
69 + if (!request_mem_region(addr.start, resource_size(&addr), hcd_name)) {
70 + ret = -EBUSY;
71 + goto err_free_board;
72 + }
73 +
74 + addr_reg = ioremap_nocache(addr.start, resource_size(&addr));
75 + if (addr_reg == NULL) {
76 + ret = -ENOMEM;
77 + goto err_release_addr;
78 + }
79 +
80 + if (!request_mem_region(data.start, resource_size(&data), hcd_name)) {
81 + ret = -EBUSY;
82 + goto err_unmap_addr;
83 + }
84 +
85 + data_reg = ioremap_nocache(data.start, resource_size(&data));
86 + if (data_reg == NULL) {
87 + ret = -ENOMEM;
88 + goto err_release_data;
89 + }
90 +
91 + irq = irq_of_parse_and_map(dn, 0);
92 + if (irq == NO_IRQ) {
93 + ret = -EINVAL;
94 + goto err_unmap_data;
95 + }
96 +
97 + /* allocate and initialize hcd */
98 + hcd = usb_create_hcd(&isp116x_hc_driver, &op->dev, dev_name(&op->dev));
99 + if (!hcd) {
100 + ret = -ENOMEM;
101 + goto err_irq_dispose;
102 + }
103 +
104 + /* this rsrc_start is bogus */
105 + hcd->rsrc_start = addr.start;
106 + isp116x = hcd_to_isp116x(hcd);
107 + isp116x->data_reg = data_reg;
108 + isp116x->addr_reg = addr_reg;
109 + isp116x->board = board;
110 + spin_lock_init(&isp116x->lock);
111 + INIT_LIST_HEAD(&isp116x->async);
112 +
113 + board->delay = isp116x_of_delay;
114 + if (of_get_property(dn, "sel15Kres", NULL))
115 + board->sel15Kres = 1;
116 + if (of_get_property(dn, "oc_enable", NULL))
117 + board->oc_enable = 1;
118 + if (of_get_property(dn, "remote_wakeup_enable", NULL))
119 + board->remote_wakeup_enable = 1;
120 +
121 + if (of_get_property(dn, "int_act_high", NULL))
122 + board->int_act_high = 1;
123 + if (of_get_property(dn, "int_edge_triggered", NULL))
124 + board->int_edge_triggered = 1;
125 +
126 + if (board->int_edge_triggered)
127 + irqflags = board->int_act_high ? IRQF_TRIGGER_RISING :
128 + IRQF_TRIGGER_FALLING;
129 + else
130 + irqflags = board->int_act_high ? IRQF_TRIGGER_HIGH :
131 + IRQF_TRIGGER_LOW;
132 +
133 + ret = usb_add_hcd(hcd, irq, irqflags | IRQF_DISABLED);
134 + if (ret)
135 + goto err_put_hcd;
136 +
137 + ret = create_debug_file(isp116x);
138 + if (ret) {
139 + ERR("Couldn't create debugfs entry\n");
140 + goto err_remove_hcd;
141 + }
142 +
143 + return 0;
144 +
145 + err_remove_hcd:
146 + usb_remove_hcd(hcd);
147 + err_put_hcd:
148 + usb_put_hcd(hcd);
149 + err_irq_dispose:
150 + irq_dispose_mapping(irq);
151 + err_unmap_data:
152 + iounmap(data_reg);
153 + err_release_data:
154 + release_mem_region(data.start, resource_size(&data));
155 + err_unmap_addr:
156 + iounmap(addr_reg);
157 + err_release_addr:
158 + release_mem_region(addr.start, resource_size(&addr));
159 + err_free_board:
160 + kfree(board);
161 + return ret;
162 +}
163 +
164 +static __devexit int isp116x_of_remove(struct platform_device *op)
165 +{
166 + struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
167 + struct isp116x *isp116x;
168 + struct resource res;
169 +
170 + if (!hcd)
171 + return 0;
172 +
173 + dev_set_drvdata(&op->dev, NULL);
174 +
175 + isp116x = hcd_to_isp116x(hcd);
176 + remove_debug_file(isp116x);
177 + usb_remove_hcd(hcd);
178 +
179 + irq_dispose_mapping(hcd->irq);
180 +
181 + iounmap(isp116x->data_reg);
182 + (void) of_address_to_resource(op->dev.of_node, 0, &res);
183 + release_mem_region(res.start, resource_size(&res));
184 +
185 + iounmap(isp116x->addr_reg);
186 + (void) of_address_to_resource(op->dev.of_node, 1, &res);
187 + release_mem_region(res.start, resource_size(&res));
188 +
189 + kfree(isp116x->board);
190 + usb_put_hcd(hcd);
191 +
192 + return 0;
193 +}
194 +
195 +static struct of_device_id isp116x_of_match[] = {
196 + { .compatible = "isp116x-hcd", },
197 + {},
198 +};
199 +
200 +static struct platform_driver isp116x_of_platform_driver = {
201 + .probe = isp116x_of_probe,
202 + .remove = __devexit_p(isp116x_of_remove),
203 + .driver = {
204 + .name = "isp116x-hcd-of",
205 + .owner = THIS_MODULE,
206 + .of_match_table = isp116x_of_match,
207 + },
208 +};
209 +
210 +static int __init isp116x_of_register(void)
211 +{
212 + return platform_driver_register(&isp116x_of_platform_driver);
213 +}
214 +
215 +static void __exit isp116x_of_unregister(void)
216 +{
217 + platform_driver_unregister(&isp116x_of_platform_driver);
218 +}
219 +
220 +MODULE_DEVICE_TABLE(of, isp116x_of_match);
221 +
222 +#else
223 +static inline int isp116x_of_register(void) { return 0; };
224 +static void isp116x_of_unregister(void) {};
225 +#endif /* CONFIG_USB_ISP116X_HCD_OF */
226 +
227 /*-----------------------------------------------------------------*/
228
229 static int __init isp116x_init(void)
230 {
231 + int ret;
232 +
233 if (usb_disabled())
234 return -ENODEV;
235
236 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
237 - return platform_driver_register(&isp116x_driver);
238 + ret = isp116x_platform_register();
239 + if (ret)
240 + return ret;
241 +
242 + ret = isp116x_of_register();
243 + if (ret)
244 + goto err_platform_unregister;
245 +
246 + return 0;
247 +
248 + err_platform_unregister:
249 + isp116x_platform_unregister();
250 + return ret;
251 }
252
253 module_init(isp116x_init);
254
255 static void __exit isp116x_cleanup(void)
256 {
257 - platform_driver_unregister(&isp116x_driver);
258 + isp116x_of_unregister();
259 + isp116x_platform_unregister();
260 }
261
262 module_exit(isp116x_cleanup);
263 --- a/drivers/usb/host/Kconfig
264 +++ b/drivers/usb/host/Kconfig
265 @@ -251,6 +251,24 @@ config USB_ISP116X_HCD
266 To compile this driver as a module, choose M here: the
267 module will be called isp116x-hcd.
268
269 +config USB_ISP116X_HCD_PLATFORM
270 + bool "ISP116X support for controllers on platform bus"
271 + depends on USB_ISP116X_HCD
272 + default n if PPC_OF
273 + default y
274 + ---help---
275 + Enables support for the ISP116x USB controller present on the
276 + platform bus.
277 +
278 +config USB_ISP116X_HCD_OF
279 + bool "ISP116X support for controllers on OF platform bus"
280 + depends on USB_ISP116X_HCD && PPC_OF
281 + default y if PPC_OF
282 + default n
283 + ---help---
284 + Enables support for the ISP116x USB controller present on the
285 + OpenFirmware platform bus.
286 +
287 config USB_ISP1760_HCD
288 tristate "ISP 1760 HCD support"
289 depends on USB && EXPERIMENTAL