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