omap3evm: ehci: Update EHCI support on OMAP3EVM (Rev >= E)
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-omap2 / board-omap3evm.c
1 /*
2  * linux/arch/arm/mach-omap2/board-omap3evm.c
3  *
4  * Copyright (C) 2008 Texas Instruments
5  *
6  * Modified from mach-omap2/board-3430sdp.c
7  *
8  * Initial code: Syed Mohammed Khasim
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/clk.h>
21 #include <linux/gpio.h>
22 #include <linux/input.h>
23 #include <linux/input/matrix_keypad.h>
24 #include <linux/leds.h>
25
26 #include <linux/spi/spi.h>
27 #include <linux/spi/ads7846.h>
28 #include <linux/i2c/twl4030.h>
29 #include <linux/usb/otg.h>
30
31 #include <mach/hardware.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35
36 #include <plat/board.h>
37 #include <plat/mux.h>
38 #include <plat/usb.h>
39 #include <plat/common.h>
40 #include <plat/mcspi.h>
41
42 #include "sdram-micron-mt46h32m32lf-6.h"
43 #include "mmc-twl4030.h"
44
45 #define OMAP3_EVM_TS_GPIO       175
46 #define OMAP3_EVM_EHCI_VBUS     22
47 #define OMAP3_EVM_EHCI_SELECT   61
48
49 #define OMAP3EVM_ETHR_START     0x2c000000
50 #define OMAP3EVM_ETHR_SIZE      1024
51 #define OMAP3EVM_ETHR_ID_REV    0x50
52 #define OMAP3EVM_ETHR_GPIO_IRQ  176
53 #define OMAP3EVM_SMC911X_CS     5
54
55 static u8 omap3_evm_version;
56
57 u8 get_omap3_evm_rev(void)
58 {
59         return omap3_evm_version;
60 }
61 EXPORT_SYMBOL(get_omap3_evm_rev);
62
63 static void __init omap3_evm_get_revision(void)
64 {
65         void __iomem *ioaddr;
66         unsigned int smsc_id;
67
68         /* Ethernet PHY ID is stored at ID_REV register */
69         ioaddr = ioremap_nocache(OMAP3EVM_ETHR_START, SZ_1K);
70         if (!ioaddr)
71                 return;
72         smsc_id = readl(ioaddr + OMAP3EVM_ETHR_ID_REV) & 0xFFFF0000;
73         iounmap(ioaddr);
74
75         switch (smsc_id) {
76         /*SMSC9115 chipset*/
77         case 0x01150000:
78                 omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
79                 break;
80         /*SMSC 9220 chipset*/
81         case 0x92200000:
82         default:
83                 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
84         }
85 }
86
87 static struct resource omap3evm_smc911x_resources[] = {
88         [0] =   {
89                 .start  = OMAP3EVM_ETHR_START,
90                 .end    = (OMAP3EVM_ETHR_START + OMAP3EVM_ETHR_SIZE - 1),
91                 .flags  = IORESOURCE_MEM,
92         },
93         [1] =   {
94                 .start  = OMAP_GPIO_IRQ(OMAP3EVM_ETHR_GPIO_IRQ),
95                 .end    = OMAP_GPIO_IRQ(OMAP3EVM_ETHR_GPIO_IRQ),
96                 .flags  = IORESOURCE_IRQ,
97         },
98 };
99
100 static struct platform_device omap3evm_smc911x_device = {
101         .name           = "smc911x",
102         .id             = -1,
103         .num_resources  = ARRAY_SIZE(omap3evm_smc911x_resources),
104         .resource       = &omap3evm_smc911x_resources[0],
105 };
106
107 static inline void __init omap3evm_init_smc911x(void)
108 {
109         int eth_cs;
110         struct clk *l3ck;
111         unsigned int rate;
112
113         eth_cs = OMAP3EVM_SMC911X_CS;
114
115         l3ck = clk_get(NULL, "l3_ck");
116         if (IS_ERR(l3ck))
117                 rate = 100000000;
118         else
119                 rate = clk_get_rate(l3ck);
120
121         if (gpio_request(OMAP3EVM_ETHR_GPIO_IRQ, "SMC911x irq") < 0) {
122                 printk(KERN_ERR "Failed to request GPIO%d for smc911x IRQ\n",
123                         OMAP3EVM_ETHR_GPIO_IRQ);
124                 return;
125         }
126
127         gpio_direction_input(OMAP3EVM_ETHR_GPIO_IRQ);
128 }
129
130 static struct twl4030_hsmmc_info mmc[] = {
131         {
132                 .mmc            = 1,
133                 .wires          = 4,
134                 .gpio_cd        = -EINVAL,
135                 .gpio_wp        = 63,
136         },
137         {}      /* Terminator */
138 };
139
140 static struct gpio_led gpio_leds[] = {
141         {
142                 .name                   = "omap3evm::ledb",
143                 /* normally not visible (board underside) */
144                 .default_trigger        = "default-on",
145                 .gpio                   = -EINVAL,      /* gets replaced */
146                 .active_low             = true,
147         },
148 };
149
150 static struct gpio_led_platform_data gpio_led_info = {
151         .leds           = gpio_leds,
152         .num_leds       = ARRAY_SIZE(gpio_leds),
153 };
154
155 static struct platform_device leds_gpio = {
156         .name   = "leds-gpio",
157         .id     = -1,
158         .dev    = {
159                 .platform_data  = &gpio_led_info,
160         },
161 };
162
163
164 static int omap3evm_twl_gpio_setup(struct device *dev,
165                 unsigned gpio, unsigned ngpio)
166 {
167         /* gpio + 0 is "mmc0_cd" (input/IRQ) */
168         omap_cfg_reg(L8_34XX_GPIO63);
169         mmc[0].gpio_cd = gpio + 0;
170         twl4030_mmc_init(mmc);
171
172         /*
173          * Most GPIOs are for USB OTG.  Some are mostly sent to
174          * the P2 connector; notably LEDA for the LCD backlight.
175          */
176
177         /* TWL4030_GPIO_MAX + 1 == ledB (out, active low LED) */
178         gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
179
180         platform_device_register(&leds_gpio);
181
182         return 0;
183 }
184
185 static struct twl4030_gpio_platform_data omap3evm_gpio_data = {
186         .gpio_base      = OMAP_MAX_GPIO_LINES,
187         .irq_base       = TWL4030_GPIO_IRQ_BASE,
188         .irq_end        = TWL4030_GPIO_IRQ_END,
189         .use_leds       = true,
190         .setup          = omap3evm_twl_gpio_setup,
191 };
192
193 static struct twl4030_usb_data omap3evm_usb_data = {
194         .usb_mode       = T2_USB_MODE_ULPI,
195 };
196
197 static int board_keymap[] = {
198         KEY(0, 0, KEY_LEFT),
199         KEY(0, 1, KEY_RIGHT),
200         KEY(0, 2, KEY_A),
201         KEY(0, 3, KEY_B),
202         KEY(1, 0, KEY_DOWN),
203         KEY(1, 1, KEY_UP),
204         KEY(1, 2, KEY_E),
205         KEY(1, 3, KEY_F),
206         KEY(2, 0, KEY_ENTER),
207         KEY(2, 1, KEY_I),
208         KEY(2, 2, KEY_J),
209         KEY(2, 3, KEY_K),
210         KEY(3, 0, KEY_M),
211         KEY(3, 1, KEY_N),
212         KEY(3, 2, KEY_O),
213         KEY(3, 3, KEY_P)
214 };
215
216 static struct matrix_keymap_data board_map_data = {
217         .keymap                 = board_keymap,
218         .keymap_size            = ARRAY_SIZE(board_keymap),
219 };
220
221 static struct twl4030_keypad_data omap3evm_kp_data = {
222         .keymap_data    = &board_map_data,
223         .rows           = 4,
224         .cols           = 4,
225         .rep            = 1,
226 };
227
228 static struct twl4030_madc_platform_data omap3evm_madc_data = {
229         .irq_line       = 1,
230 };
231
232 static struct twl4030_codec_audio_data omap3evm_audio_data = {
233         .audio_mclk = 26000000,
234 };
235
236 static struct twl4030_codec_data omap3evm_codec_data = {
237         .audio_mclk = 26000000,
238         .audio = &omap3evm_audio_data,
239 };
240
241 static struct twl4030_platform_data omap3evm_twldata = {
242         .irq_base       = TWL4030_IRQ_BASE,
243         .irq_end        = TWL4030_IRQ_END,
244
245         /* platform_data for children goes here */
246         .keypad         = &omap3evm_kp_data,
247         .madc           = &omap3evm_madc_data,
248         .usb            = &omap3evm_usb_data,
249         .gpio           = &omap3evm_gpio_data,
250         .codec          = &omap3evm_codec_data,
251 };
252
253 static struct i2c_board_info __initdata omap3evm_i2c_boardinfo[] = {
254         {
255                 I2C_BOARD_INFO("twl4030", 0x48),
256                 .flags = I2C_CLIENT_WAKE,
257                 .irq = INT_34XX_SYS_NIRQ,
258                 .platform_data = &omap3evm_twldata,
259         },
260 };
261
262 static int __init omap3_evm_i2c_init(void)
263 {
264         omap_register_i2c_bus(1, 2600, omap3evm_i2c_boardinfo,
265                         ARRAY_SIZE(omap3evm_i2c_boardinfo));
266         omap_register_i2c_bus(2, 400, NULL, 0);
267         omap_register_i2c_bus(3, 400, NULL, 0);
268         return 0;
269 }
270
271 static struct platform_device omap3_evm_lcd_device = {
272         .name           = "omap3evm_lcd",
273         .id             = -1,
274 };
275
276 static struct omap_lcd_config omap3_evm_lcd_config __initdata = {
277         .ctrl_name      = "internal",
278 };
279
280 static void ads7846_dev_init(void)
281 {
282         if (gpio_request(OMAP3_EVM_TS_GPIO, "ADS7846 pendown") < 0)
283                 printk(KERN_ERR "can't get ads7846 pen down GPIO\n");
284
285         gpio_direction_input(OMAP3_EVM_TS_GPIO);
286
287         omap_set_gpio_debounce(OMAP3_EVM_TS_GPIO, 1);
288         omap_set_gpio_debounce_time(OMAP3_EVM_TS_GPIO, 0xa);
289 }
290
291 static int ads7846_get_pendown_state(void)
292 {
293         return !gpio_get_value(OMAP3_EVM_TS_GPIO);
294 }
295
296 struct ads7846_platform_data ads7846_config = {
297         .x_max                  = 0x0fff,
298         .y_max                  = 0x0fff,
299         .x_plate_ohms           = 180,
300         .pressure_max           = 255,
301         .debounce_max           = 10,
302         .debounce_tol           = 3,
303         .debounce_rep           = 1,
304         .get_pendown_state      = ads7846_get_pendown_state,
305         .keep_vref_on           = 1,
306         .settle_delay_usecs     = 150,
307 };
308
309 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
310         .turbo_mode     = 0,
311         .single_channel = 1,    /* 0: slave, 1: master */
312 };
313
314 struct spi_board_info omap3evm_spi_board_info[] = {
315         [0] = {
316                 .modalias               = "ads7846",
317                 .bus_num                = 1,
318                 .chip_select            = 0,
319                 .max_speed_hz           = 1500000,
320                 .controller_data        = &ads7846_mcspi_config,
321                 .irq                    = OMAP_GPIO_IRQ(OMAP3_EVM_TS_GPIO),
322                 .platform_data          = &ads7846_config,
323         },
324 };
325
326 static struct omap_board_config_kernel omap3_evm_config[] __initdata = {
327         { OMAP_TAG_LCD,         &omap3_evm_lcd_config },
328 };
329
330 static void __init omap3_evm_init_irq(void)
331 {
332         omap_board_config = omap3_evm_config;
333         omap_board_config_size = ARRAY_SIZE(omap3_evm_config);
334         omap2_init_common_hw(mt46h32m32lf6_sdrc_params, NULL);
335         omap_init_irq();
336         omap_gpio_init();
337         omap3evm_init_smc911x();
338 }
339
340 static struct platform_device *omap3_evm_devices[] __initdata = {
341         &omap3_evm_lcd_device,
342         &omap3evm_smc911x_device,
343 };
344
345 static struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
346
347         .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN,
348         .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
349         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
350
351         .phy_reset  = true,
352         /* PHY reset GPIO will be runtime programmed based on EVM version */
353         .reset_gpio_port[0]  = -EINVAL,
354         .reset_gpio_port[1]  = -EINVAL,
355         .reset_gpio_port[2]  = -EINVAL
356 };
357
358 static void __init omap3_evm_init(void)
359 {
360         omap3_evm_get_revision();
361
362         omap3_evm_i2c_init();
363
364         platform_add_devices(omap3_evm_devices, ARRAY_SIZE(omap3_evm_devices));
365
366         spi_register_board_info(omap3evm_spi_board_info,
367                                 ARRAY_SIZE(omap3evm_spi_board_info));
368
369         omap_serial_init();
370 #ifdef CONFIG_NOP_USB_XCEIV
371         /* OMAP3EVM uses ISP1504 phy and so register nop transceiver */
372         usb_nop_xceiv_register();
373 #endif
374         if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2) {
375                 /* enable EHCI VBUS using GPIO22 */
376                 omap_cfg_reg(AF9_34XX_GPIO22);
377                 gpio_request(OMAP3_EVM_EHCI_VBUS, "enable EHCI VBUS");
378                 gpio_direction_output(OMAP3_EVM_EHCI_VBUS, 0);
379                 gpio_set_value(OMAP3_EVM_EHCI_VBUS, 1);
380
381                 /* Select EHCI port on main board */
382                 omap_cfg_reg(U3_34XX_GPIO61);
383                 gpio_request(OMAP3_EVM_EHCI_SELECT, "select EHCI port");
384                 gpio_direction_output(OMAP3_EVM_EHCI_SELECT, 0);
385                 gpio_set_value(OMAP3_EVM_EHCI_SELECT, 0);
386
387                 /* setup EHCI phy reset config */
388                 omap_cfg_reg(AH14_34XX_GPIO21);
389                 ehci_pdata.reset_gpio_port[1] = 21;
390
391         } else {
392                 /* setup EHCI phy reset on MDC */
393                 omap_cfg_reg(AF4_34XX_GPIO135_OUT);
394                 ehci_pdata.reset_gpio_port[1] = 135;
395         }
396         usb_musb_init();
397         usb_ehci_init(&ehci_pdata);
398         ads7846_dev_init();
399 }
400
401 static void __init omap3_evm_map_io(void)
402 {
403         omap2_set_globals_343x();
404         omap2_map_common_io();
405 }
406
407 MACHINE_START(OMAP3EVM, "OMAP3 EVM")
408         /* Maintainer: Syed Mohammed Khasim - Texas Instruments */
409         .phys_io        = 0x48000000,
410         .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
411         .boot_params    = 0x80000100,
412         .map_io         = omap3_evm_map_io,
413         .init_irq       = omap3_evm_init_irq,
414         .init_machine   = omap3_evm_init,
415         .timer          = &omap_timer,
416 MACHINE_END