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