ARM: OMAP2+: Remove omap4 pdata for USB
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / arm / mach-omap2 / usb-host.c
1 /*
2  * usb-host.c - OMAP USB Host
3  *
4  * This file will contain the board specific details for the
5  * Synopsys EHCI/OHCI host controller on OMAP3430 and onwards
6  *
7  * Copyright (C) 2007-2011 Texas Instruments
8  * Author: Vikram Pandita <vikram.pandita@ti.com>
9  * Author: Keshava Munegowda <keshava_mgowda@ti.com>
10  *
11  * Generalization by:
12  * Felipe Balbi <balbi@ti.com>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License version 2 as
16  * published by the Free Software Foundation.
17  */
18
19 #include <linux/types.h>
20 #include <linux/errno.h>
21 #include <linux/delay.h>
22 #include <linux/platform_device.h>
23 #include <linux/slab.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/regulator/machine.h>
26 #include <linux/regulator/fixed.h>
27 #include <linux/string.h>
28 #include <linux/io.h>
29 #include <linux/gpio.h>
30 #include <linux/usb/phy.h>
31
32 #include "soc.h"
33 #include "omap_device.h"
34 #include "mux.h"
35 #include "usb.h"
36
37 #ifdef CONFIG_MFD_OMAP_USB_HOST
38
39 #define OMAP_USBHS_DEVICE       "usbhs_omap"
40 #define OMAP_USBTLL_DEVICE      "usbhs_tll"
41 #define USBHS_UHH_HWMODNAME     "usb_host_hs"
42 #define USBHS_TLL_HWMODNAME     "usb_tll_hs"
43
44 /* MUX settings for EHCI pins */
45 /*
46  * setup_ehci_io_mux - initialize IO pad mux for USBHOST
47  */
48 static void __init setup_ehci_io_mux(const enum usbhs_omap_port_mode *port_mode)
49 {
50         switch (port_mode[0]) {
51         case OMAP_EHCI_PORT_MODE_PHY:
52                 omap_mux_init_signal("hsusb1_stp", OMAP_PIN_OUTPUT);
53                 omap_mux_init_signal("hsusb1_clk", OMAP_PIN_OUTPUT);
54                 omap_mux_init_signal("hsusb1_dir", OMAP_PIN_INPUT_PULLDOWN);
55                 omap_mux_init_signal("hsusb1_nxt", OMAP_PIN_INPUT_PULLDOWN);
56                 omap_mux_init_signal("hsusb1_data0", OMAP_PIN_INPUT_PULLDOWN);
57                 omap_mux_init_signal("hsusb1_data1", OMAP_PIN_INPUT_PULLDOWN);
58                 omap_mux_init_signal("hsusb1_data2", OMAP_PIN_INPUT_PULLDOWN);
59                 omap_mux_init_signal("hsusb1_data3", OMAP_PIN_INPUT_PULLDOWN);
60                 omap_mux_init_signal("hsusb1_data4", OMAP_PIN_INPUT_PULLDOWN);
61                 omap_mux_init_signal("hsusb1_data5", OMAP_PIN_INPUT_PULLDOWN);
62                 omap_mux_init_signal("hsusb1_data6", OMAP_PIN_INPUT_PULLDOWN);
63                 omap_mux_init_signal("hsusb1_data7", OMAP_PIN_INPUT_PULLDOWN);
64                 break;
65         case OMAP_EHCI_PORT_MODE_TLL:
66                 omap_mux_init_signal("hsusb1_tll_stp",
67                         OMAP_PIN_INPUT_PULLUP);
68                 omap_mux_init_signal("hsusb1_tll_clk",
69                         OMAP_PIN_INPUT_PULLDOWN);
70                 omap_mux_init_signal("hsusb1_tll_dir",
71                         OMAP_PIN_INPUT_PULLDOWN);
72                 omap_mux_init_signal("hsusb1_tll_nxt",
73                         OMAP_PIN_INPUT_PULLDOWN);
74                 omap_mux_init_signal("hsusb1_tll_data0",
75                         OMAP_PIN_INPUT_PULLDOWN);
76                 omap_mux_init_signal("hsusb1_tll_data1",
77                         OMAP_PIN_INPUT_PULLDOWN);
78                 omap_mux_init_signal("hsusb1_tll_data2",
79                         OMAP_PIN_INPUT_PULLDOWN);
80                 omap_mux_init_signal("hsusb1_tll_data3",
81                         OMAP_PIN_INPUT_PULLDOWN);
82                 omap_mux_init_signal("hsusb1_tll_data4",
83                         OMAP_PIN_INPUT_PULLDOWN);
84                 omap_mux_init_signal("hsusb1_tll_data5",
85                         OMAP_PIN_INPUT_PULLDOWN);
86                 omap_mux_init_signal("hsusb1_tll_data6",
87                         OMAP_PIN_INPUT_PULLDOWN);
88                 omap_mux_init_signal("hsusb1_tll_data7",
89                         OMAP_PIN_INPUT_PULLDOWN);
90                 break;
91         case OMAP_USBHS_PORT_MODE_UNUSED:
92                 /* FALLTHROUGH */
93         default:
94                 break;
95         }
96
97         switch (port_mode[1]) {
98         case OMAP_EHCI_PORT_MODE_PHY:
99                 omap_mux_init_signal("hsusb2_stp", OMAP_PIN_OUTPUT);
100                 omap_mux_init_signal("hsusb2_clk", OMAP_PIN_OUTPUT);
101                 omap_mux_init_signal("hsusb2_dir", OMAP_PIN_INPUT_PULLDOWN);
102                 omap_mux_init_signal("hsusb2_nxt", OMAP_PIN_INPUT_PULLDOWN);
103                 omap_mux_init_signal("hsusb2_data0",
104                         OMAP_PIN_INPUT_PULLDOWN);
105                 omap_mux_init_signal("hsusb2_data1",
106                         OMAP_PIN_INPUT_PULLDOWN);
107                 omap_mux_init_signal("hsusb2_data2",
108                         OMAP_PIN_INPUT_PULLDOWN);
109                 omap_mux_init_signal("hsusb2_data3",
110                         OMAP_PIN_INPUT_PULLDOWN);
111                 omap_mux_init_signal("hsusb2_data4",
112                         OMAP_PIN_INPUT_PULLDOWN);
113                 omap_mux_init_signal("hsusb2_data5",
114                         OMAP_PIN_INPUT_PULLDOWN);
115                 omap_mux_init_signal("hsusb2_data6",
116                         OMAP_PIN_INPUT_PULLDOWN);
117                 omap_mux_init_signal("hsusb2_data7",
118                         OMAP_PIN_INPUT_PULLDOWN);
119                 break;
120         case OMAP_EHCI_PORT_MODE_TLL:
121                 omap_mux_init_signal("hsusb2_tll_stp",
122                         OMAP_PIN_INPUT_PULLUP);
123                 omap_mux_init_signal("hsusb2_tll_clk",
124                         OMAP_PIN_INPUT_PULLDOWN);
125                 omap_mux_init_signal("hsusb2_tll_dir",
126                         OMAP_PIN_INPUT_PULLDOWN);
127                 omap_mux_init_signal("hsusb2_tll_nxt",
128                         OMAP_PIN_INPUT_PULLDOWN);
129                 omap_mux_init_signal("hsusb2_tll_data0",
130                         OMAP_PIN_INPUT_PULLDOWN);
131                 omap_mux_init_signal("hsusb2_tll_data1",
132                         OMAP_PIN_INPUT_PULLDOWN);
133                 omap_mux_init_signal("hsusb2_tll_data2",
134                         OMAP_PIN_INPUT_PULLDOWN);
135                 omap_mux_init_signal("hsusb2_tll_data3",
136                         OMAP_PIN_INPUT_PULLDOWN);
137                 omap_mux_init_signal("hsusb2_tll_data4",
138                         OMAP_PIN_INPUT_PULLDOWN);
139                 omap_mux_init_signal("hsusb2_tll_data5",
140                         OMAP_PIN_INPUT_PULLDOWN);
141                 omap_mux_init_signal("hsusb2_tll_data6",
142                         OMAP_PIN_INPUT_PULLDOWN);
143                 omap_mux_init_signal("hsusb2_tll_data7",
144                         OMAP_PIN_INPUT_PULLDOWN);
145                 break;
146         case OMAP_USBHS_PORT_MODE_UNUSED:
147                 /* FALLTHROUGH */
148         default:
149                 break;
150         }
151
152         switch (port_mode[2]) {
153         case OMAP_EHCI_PORT_MODE_PHY:
154                 printk(KERN_WARNING "Port3 can't be used in PHY mode\n");
155                 break;
156         case OMAP_EHCI_PORT_MODE_TLL:
157                 omap_mux_init_signal("hsusb3_tll_stp",
158                         OMAP_PIN_INPUT_PULLUP);
159                 omap_mux_init_signal("hsusb3_tll_clk",
160                         OMAP_PIN_INPUT_PULLDOWN);
161                 omap_mux_init_signal("hsusb3_tll_dir",
162                         OMAP_PIN_INPUT_PULLDOWN);
163                 omap_mux_init_signal("hsusb3_tll_nxt",
164                         OMAP_PIN_INPUT_PULLDOWN);
165                 omap_mux_init_signal("hsusb3_tll_data0",
166                         OMAP_PIN_INPUT_PULLDOWN);
167                 omap_mux_init_signal("hsusb3_tll_data1",
168                         OMAP_PIN_INPUT_PULLDOWN);
169                 omap_mux_init_signal("hsusb3_tll_data2",
170                         OMAP_PIN_INPUT_PULLDOWN);
171                 omap_mux_init_signal("hsusb3_tll_data3",
172                         OMAP_PIN_INPUT_PULLDOWN);
173                 omap_mux_init_signal("hsusb3_tll_data4",
174                         OMAP_PIN_INPUT_PULLDOWN);
175                 omap_mux_init_signal("hsusb3_tll_data5",
176                         OMAP_PIN_INPUT_PULLDOWN);
177                 omap_mux_init_signal("hsusb3_tll_data6",
178                         OMAP_PIN_INPUT_PULLDOWN);
179                 omap_mux_init_signal("hsusb3_tll_data7",
180                         OMAP_PIN_INPUT_PULLDOWN);
181                 break;
182         case OMAP_USBHS_PORT_MODE_UNUSED:
183                 /* FALLTHROUGH */
184         default:
185                 break;
186         }
187
188         return;
189 }
190
191 static void __init setup_ohci_io_mux(const enum usbhs_omap_port_mode *port_mode)
192 {
193         switch (port_mode[0]) {
194         case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
195         case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
196         case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
197         case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
198                 omap_mux_init_signal("mm1_rxdp",
199                         OMAP_PIN_INPUT_PULLDOWN);
200                 omap_mux_init_signal("mm1_rxdm",
201                         OMAP_PIN_INPUT_PULLDOWN);
202                 /* FALLTHROUGH */
203         case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
204         case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
205                 omap_mux_init_signal("mm1_rxrcv",
206                         OMAP_PIN_INPUT_PULLDOWN);
207                 /* FALLTHROUGH */
208         case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
209         case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
210                 omap_mux_init_signal("mm1_txen_n", OMAP_PIN_OUTPUT);
211                 /* FALLTHROUGH */
212         case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
213         case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
214                 omap_mux_init_signal("mm1_txse0",
215                         OMAP_PIN_INPUT_PULLDOWN);
216                 omap_mux_init_signal("mm1_txdat",
217                         OMAP_PIN_INPUT_PULLDOWN);
218                 break;
219         case OMAP_USBHS_PORT_MODE_UNUSED:
220                 /* FALLTHROUGH */
221         default:
222                 break;
223         }
224         switch (port_mode[1]) {
225         case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
226         case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
227         case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
228         case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
229                 omap_mux_init_signal("mm2_rxdp",
230                         OMAP_PIN_INPUT_PULLDOWN);
231                 omap_mux_init_signal("mm2_rxdm",
232                         OMAP_PIN_INPUT_PULLDOWN);
233                 /* FALLTHROUGH */
234         case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
235         case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
236                 omap_mux_init_signal("mm2_rxrcv",
237                         OMAP_PIN_INPUT_PULLDOWN);
238                 /* FALLTHROUGH */
239         case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
240         case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
241                 omap_mux_init_signal("mm2_txen_n", OMAP_PIN_OUTPUT);
242                 /* FALLTHROUGH */
243         case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
244         case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
245                 omap_mux_init_signal("mm2_txse0",
246                         OMAP_PIN_INPUT_PULLDOWN);
247                 omap_mux_init_signal("mm2_txdat",
248                         OMAP_PIN_INPUT_PULLDOWN);
249                 break;
250         case OMAP_USBHS_PORT_MODE_UNUSED:
251                 /* FALLTHROUGH */
252         default:
253                 break;
254         }
255         switch (port_mode[2]) {
256         case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
257         case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
258         case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
259         case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
260                 omap_mux_init_signal("mm3_rxdp",
261                         OMAP_PIN_INPUT_PULLDOWN);
262                 omap_mux_init_signal("mm3_rxdm",
263                         OMAP_PIN_INPUT_PULLDOWN);
264                 /* FALLTHROUGH */
265         case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
266         case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
267                 omap_mux_init_signal("mm3_rxrcv",
268                         OMAP_PIN_INPUT_PULLDOWN);
269                 /* FALLTHROUGH */
270         case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
271         case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
272                 omap_mux_init_signal("mm3_txen_n", OMAP_PIN_OUTPUT);
273                 /* FALLTHROUGH */
274         case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
275         case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
276                 omap_mux_init_signal("mm3_txse0",
277                         OMAP_PIN_INPUT_PULLDOWN);
278                 omap_mux_init_signal("mm3_txdat",
279                         OMAP_PIN_INPUT_PULLDOWN);
280                 break;
281         case OMAP_USBHS_PORT_MODE_UNUSED:
282                 /* FALLTHROUGH */
283         default:
284                 break;
285         }
286 }
287
288 void __init usbhs_init(struct usbhs_omap_platform_data *pdata)
289 {
290         struct omap_hwmod       *uhh_hwm, *tll_hwm;
291         struct platform_device  *pdev;
292         int                     bus_id = -1;
293
294         if (cpu_is_omap34xx()) {
295                 setup_ehci_io_mux(pdata->port_mode);
296                 setup_ohci_io_mux(pdata->port_mode);
297
298                 if (omap_rev() <= OMAP3430_REV_ES2_1)
299                         pdata->single_ulpi_bypass = true;
300
301         }
302
303         uhh_hwm = omap_hwmod_lookup(USBHS_UHH_HWMODNAME);
304         if (!uhh_hwm) {
305                 pr_err("Could not look up %s\n", USBHS_UHH_HWMODNAME);
306                 return;
307         }
308
309         tll_hwm = omap_hwmod_lookup(USBHS_TLL_HWMODNAME);
310         if (!tll_hwm) {
311                 pr_err("Could not look up %s\n", USBHS_TLL_HWMODNAME);
312                 return;
313         }
314
315         pdev = omap_device_build(OMAP_USBTLL_DEVICE, bus_id, tll_hwm,
316                                 pdata, sizeof(*pdata));
317         if (IS_ERR(pdev)) {
318                 pr_err("Could not build hwmod device %s\n",
319                        USBHS_TLL_HWMODNAME);
320                 return;
321         }
322
323         pdev = omap_device_build(OMAP_USBHS_DEVICE, bus_id, uhh_hwm,
324                                 pdata, sizeof(*pdata));
325         if (IS_ERR(pdev)) {
326                 pr_err("Could not build hwmod devices %s\n",
327                        USBHS_UHH_HWMODNAME);
328                 return;
329         }
330 }
331
332 #else
333
334 void __init usbhs_init(struct usbhs_omap_platform_data *pdata)
335 {
336 }
337
338 #endif
339
340 /* Template for PHY regulators */
341 static struct fixed_voltage_config hsusb_reg_config = {
342         /* .supply_name filled later */
343         .microvolts = 3300000,
344         .gpio = -1,             /* updated later */
345         .startup_delay = 70000, /* 70msec */
346         .enable_high = 1,       /* updated later */
347         .enabled_at_boot = 0,   /* keep in RESET */
348         /* .init_data filled later */
349 };
350
351 static const char *nop_name = "nop_usb_xceiv"; /* NOP PHY driver */
352 static const char *reg_name = "reg-fixed-voltage"; /* Regulator driver */
353
354 /**
355  * usbhs_add_regulator - Add a gpio based fixed voltage regulator device
356  * @name: name for the regulator
357  * @dev_id: device id of the device this regulator supplies power to
358  * @dev_supply: supply name that the device expects
359  * @gpio: GPIO number
360  * @polarity: 1 - Active high, 0 - Active low
361  */
362 static int usbhs_add_regulator(char *name, char *dev_id, char *dev_supply,
363                                                 int gpio, int polarity)
364 {
365         struct regulator_consumer_supply *supplies;
366         struct regulator_init_data *reg_data;
367         struct fixed_voltage_config *config;
368         struct platform_device *pdev;
369         int ret;
370
371         supplies = kzalloc(sizeof(*supplies), GFP_KERNEL);
372         if (!supplies)
373                 return -ENOMEM;
374
375         supplies->supply = dev_supply;
376         supplies->dev_name = dev_id;
377
378         reg_data = kzalloc(sizeof(*reg_data), GFP_KERNEL);
379         if (!reg_data)
380                 return -ENOMEM;
381
382         reg_data->constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
383         reg_data->consumer_supplies = supplies;
384         reg_data->num_consumer_supplies = 1;
385
386         config = kmemdup(&hsusb_reg_config, sizeof(hsusb_reg_config),
387                         GFP_KERNEL);
388         if (!config)
389                 return -ENOMEM;
390
391         config->supply_name = name;
392         config->gpio = gpio;
393         config->enable_high = polarity;
394         config->init_data = reg_data;
395
396         /* create a regulator device */
397         pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
398         if (!pdev)
399                 return -ENOMEM;
400
401         pdev->id = PLATFORM_DEVID_AUTO;
402         pdev->name = reg_name;
403         pdev->dev.platform_data = config;
404
405         ret = platform_device_register(pdev);
406         if (ret)
407                 pr_err("%s: Failed registering regulator %s for %s\n",
408                                 __func__, name, dev_id);
409
410         return ret;
411 }
412
413 int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys)
414 {
415         char *rail_name;
416         int i, len;
417         struct platform_device *pdev;
418         char *phy_id;
419
420         /* the phy_id will be something like "nop_usb_xceiv.1" */
421         len = strlen(nop_name) + 3; /* 3 -> ".1" and NULL terminator */
422
423         for (i = 0; i < num_phys; i++) {
424
425                 if (!phy->port) {
426                         pr_err("%s: Invalid port 0. Must start from 1\n",
427                                                 __func__);
428                         continue;
429                 }
430
431                 /* do we need a NOP PHY device ? */
432                 if (!gpio_is_valid(phy->reset_gpio) &&
433                         !gpio_is_valid(phy->vcc_gpio))
434                         continue;
435
436                 /* create a NOP PHY device */
437                 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
438                 if (!pdev)
439                         return -ENOMEM;
440
441                 pdev->id = phy->port;
442                 pdev->name = nop_name;
443                 pdev->dev.platform_data = phy->platform_data;
444
445                 phy_id = kmalloc(len, GFP_KERNEL);
446                 if (!phy_id)
447                         return -ENOMEM;
448
449                 scnprintf(phy_id, len, "nop_usb_xceiv.%d\n",
450                                         pdev->id);
451
452                 if (platform_device_register(pdev)) {
453                         pr_err("%s: Failed to register device %s\n",
454                                 __func__,  phy_id);
455                         continue;
456                 }
457
458                 usb_bind_phy("ehci-omap.0", phy->port - 1, phy_id);
459
460                 /* Do we need RESET regulator ? */
461                 if (gpio_is_valid(phy->reset_gpio)) {
462
463                         rail_name = kmalloc(13, GFP_KERNEL);
464                         if (!rail_name)
465                                 return -ENOMEM;
466
467                         scnprintf(rail_name, 13, "hsusb%d_reset", phy->port);
468
469                         usbhs_add_regulator(rail_name, phy_id, "reset",
470                                                 phy->reset_gpio, 1);
471                 }
472
473                 /* Do we need VCC regulator ? */
474                 if (gpio_is_valid(phy->vcc_gpio)) {
475
476                         rail_name = kmalloc(13, GFP_KERNEL);
477                         if (!rail_name)
478                                 return -ENOMEM;
479
480                         scnprintf(rail_name, 13, "hsusb%d_vcc", phy->port);
481
482                         usbhs_add_regulator(rail_name, phy_id, "vcc",
483                                         phy->vcc_gpio, phy->vcc_polarity);
484                 }
485
486                 phy++;
487         }
488
489         return 0;
490 }