]> bbs.cooldavid.org Git - net-next-2.6.git/blob - arch/arm/mach-omap2/board-am3517evm.c
omap: add mdio platform devices
[net-next-2.6.git] / arch / arm / mach-omap2 / board-am3517evm.c
1 /*
2  * linux/arch/arm/mach-omap2/board-am3517evm.c
3  *
4  * Copyright (C) 2009 Texas Instruments Incorporated
5  * Author: Ranjith Lohithakshan <ranjithl@ti.com>
6  *
7  * Based on mach-omap2/board-omap3evm.c
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as  published by the
11  * Free Software Foundation version 2.
12  *
13  * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
14  * whether express or implied; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  */
18
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/clk.h>
22 #include <linux/platform_device.h>
23 #include <linux/gpio.h>
24 #include <linux/i2c/pca953x.h>
25 #include <linux/can/platform/ti_hecc.h>
26 #include <linux/davinci_emac.h>
27
28 #include <mach/hardware.h>
29 #include <mach/am35xx.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33
34 #include <plat/board.h>
35 #include <plat/common.h>
36 #include <plat/control.h>
37 #include <plat/usb.h>
38 #include <plat/display.h>
39
40 #include "mux.h"
41
42 #define AM35XX_EVM_PHY_MASK             (0xF)
43 #define AM35XX_EVM_MDIO_FREQUENCY       (1000000)
44
45 static struct mdio_platform_data am3517_evm_mdio_pdata = {
46         .bus_freq       = AM35XX_EVM_MDIO_FREQUENCY,
47 };
48
49 static struct resource am3517_mdio_resources[] = {
50         {
51                 .start  = AM35XX_IPSS_EMAC_BASE + AM35XX_EMAC_MDIO_OFFSET,
52                 .end    = AM35XX_IPSS_EMAC_BASE + AM35XX_EMAC_MDIO_OFFSET +
53                           SZ_4K - 1,
54                 .flags  = IORESOURCE_MEM,
55         },
56 };
57
58 static struct platform_device am3517_mdio_device = {
59         .name           = "davinci_mdio",
60         .id             = 0,
61         .num_resources  = ARRAY_SIZE(am3517_mdio_resources),
62         .resource       = am3517_mdio_resources,
63         .dev.platform_data = &am3517_evm_mdio_pdata,
64 };
65
66 static struct emac_platform_data am3517_evm_emac_pdata = {
67         .phy_mask       = AM35XX_EVM_PHY_MASK,
68         .mdio_max_freq  = AM35XX_EVM_MDIO_FREQUENCY,
69         .rmii_en        = 1,
70 };
71
72 static struct resource am3517_emac_resources[] = {
73         {
74                 .start  = AM35XX_IPSS_EMAC_BASE,
75                 .end    = AM35XX_IPSS_EMAC_BASE + 0x2FFFF,
76                 .flags  = IORESOURCE_MEM,
77         },
78         {
79                 .start  = INT_35XX_EMAC_C0_RXTHRESH_IRQ,
80                 .end    = INT_35XX_EMAC_C0_RXTHRESH_IRQ,
81                 .flags  = IORESOURCE_IRQ,
82         },
83         {
84                 .start  = INT_35XX_EMAC_C0_RX_PULSE_IRQ,
85                 .end    = INT_35XX_EMAC_C0_RX_PULSE_IRQ,
86                 .flags  = IORESOURCE_IRQ,
87         },
88         {
89                 .start  = INT_35XX_EMAC_C0_TX_PULSE_IRQ,
90                 .end    = INT_35XX_EMAC_C0_TX_PULSE_IRQ,
91                 .flags  = IORESOURCE_IRQ,
92         },
93         {
94                 .start  = INT_35XX_EMAC_C0_MISC_PULSE_IRQ,
95                 .end    = INT_35XX_EMAC_C0_MISC_PULSE_IRQ,
96                 .flags  = IORESOURCE_IRQ,
97         },
98 };
99
100 static struct platform_device am3517_emac_device = {
101         .name           = "davinci_emac",
102         .id             = -1,
103         .num_resources  = ARRAY_SIZE(am3517_emac_resources),
104         .resource       = am3517_emac_resources,
105 };
106
107 static void am3517_enable_ethernet_int(void)
108 {
109         u32 regval;
110
111         regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
112         regval = (regval | AM35XX_CPGMAC_C0_RX_PULSE_CLR |
113                 AM35XX_CPGMAC_C0_TX_PULSE_CLR |
114                 AM35XX_CPGMAC_C0_MISC_PULSE_CLR |
115                 AM35XX_CPGMAC_C0_RX_THRESH_CLR);
116         omap_ctrl_writel(regval, AM35XX_CONTROL_LVL_INTR_CLEAR);
117         regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
118 }
119
120 static void am3517_disable_ethernet_int(void)
121 {
122         u32 regval;
123
124         regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
125         regval = (regval | AM35XX_CPGMAC_C0_RX_PULSE_CLR |
126                 AM35XX_CPGMAC_C0_TX_PULSE_CLR);
127         omap_ctrl_writel(regval, AM35XX_CONTROL_LVL_INTR_CLEAR);
128         regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
129 }
130
131 void am3517_evm_ethernet_init(struct emac_platform_data *pdata)
132 {
133         unsigned int regval;
134
135         pdata->ctrl_reg_offset          = AM35XX_EMAC_CNTRL_OFFSET;
136         pdata->ctrl_mod_reg_offset      = AM35XX_EMAC_CNTRL_MOD_OFFSET;
137         pdata->ctrl_ram_offset          = AM35XX_EMAC_CNTRL_RAM_OFFSET;
138         pdata->mdio_reg_offset          = AM35XX_EMAC_MDIO_OFFSET;
139         pdata->ctrl_ram_size            = AM35XX_EMAC_CNTRL_RAM_SIZE;
140         pdata->version                  = EMAC_VERSION_2;
141         pdata->hw_ram_addr              = AM35XX_EMAC_HW_RAM_ADDR;
142         pdata->interrupt_enable         = am3517_enable_ethernet_int;
143         pdata->interrupt_disable        = am3517_disable_ethernet_int;
144         am3517_emac_device.dev.platform_data    = pdata;
145         platform_device_register(&am3517_emac_device);
146         platform_device_register(&am3517_mdio_device);
147         clk_add_alias(NULL, dev_name(&am3517_mdio_device.dev),
148                       NULL, &am3517_emac_device.dev);
149
150         regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
151         regval = regval & (~(AM35XX_CPGMACSS_SW_RST));
152         omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
153         regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
154
155         return ;
156 }
157
158
159
160 #define LCD_PANEL_PWR           176
161 #define LCD_PANEL_BKLIGHT_PWR   182
162 #define LCD_PANEL_PWM           181
163
164 static struct i2c_board_info __initdata am3517evm_i2c1_boardinfo[] = {
165         {
166                 I2C_BOARD_INFO("s35390a", 0x30),
167                 .type           = "s35390a",
168         },
169 };
170
171 /*
172  * RTC - S35390A
173  */
174 #define GPIO_RTCS35390A_IRQ     55
175
176 static void __init am3517_evm_rtc_init(void)
177 {
178         int r;
179
180         omap_mux_init_gpio(GPIO_RTCS35390A_IRQ, OMAP_PIN_INPUT_PULLUP);
181         r = gpio_request(GPIO_RTCS35390A_IRQ, "rtcs35390a-irq");
182         if (r < 0) {
183                 printk(KERN_WARNING "failed to request GPIO#%d\n",
184                                 GPIO_RTCS35390A_IRQ);
185                 return;
186         }
187         r = gpio_direction_input(GPIO_RTCS35390A_IRQ);
188         if (r < 0) {
189                 printk(KERN_WARNING "GPIO#%d cannot be configured as input\n",
190                                 GPIO_RTCS35390A_IRQ);
191                 gpio_free(GPIO_RTCS35390A_IRQ);
192                 return;
193         }
194         am3517evm_i2c1_boardinfo[0].irq = gpio_to_irq(GPIO_RTCS35390A_IRQ);
195 }
196
197 /*
198  * I2C GPIO Expander - TCA6416
199  */
200
201 /* Mounted on Base-Board */
202 static struct pca953x_platform_data am3517evm_gpio_expander_info_0 = {
203         .gpio_base      = OMAP_MAX_GPIO_LINES,
204 };
205 static struct i2c_board_info __initdata am3517evm_i2c2_boardinfo[] = {
206         {
207                 I2C_BOARD_INFO("tca6416", 0x21),
208                 .platform_data = &am3517evm_gpio_expander_info_0,
209         },
210 };
211
212 /* Mounted on UI Card */
213 static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_1 = {
214         .gpio_base      = OMAP_MAX_GPIO_LINES + 16,
215 };
216 static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_2 = {
217         .gpio_base      = OMAP_MAX_GPIO_LINES + 32,
218 };
219 static struct i2c_board_info __initdata am3517evm_i2c3_boardinfo[] = {
220         {
221                 I2C_BOARD_INFO("tca6416", 0x20),
222                 .platform_data = &am3517evm_ui_gpio_expander_info_1,
223         },
224         {
225                 I2C_BOARD_INFO("tca6416", 0x21),
226                 .platform_data = &am3517evm_ui_gpio_expander_info_2,
227         },
228 };
229
230 static int __init am3517_evm_i2c_init(void)
231 {
232         omap_register_i2c_bus(1, 400, NULL, 0);
233         omap_register_i2c_bus(2, 400, am3517evm_i2c2_boardinfo,
234                         ARRAY_SIZE(am3517evm_i2c2_boardinfo));
235         omap_register_i2c_bus(3, 400, am3517evm_i2c3_boardinfo,
236                         ARRAY_SIZE(am3517evm_i2c3_boardinfo));
237
238         return 0;
239 }
240
241 static int lcd_enabled;
242 static int dvi_enabled;
243
244 #if defined(CONFIG_PANEL_SHARP_LQ043T1DG01) || \
245                 defined(CONFIG_PANEL_SHARP_LQ043T1DG01_MODULE)
246 static void __init am3517_evm_display_init(void)
247 {
248         int r;
249
250         omap_mux_init_gpio(LCD_PANEL_PWR, OMAP_PIN_INPUT_PULLUP);
251         omap_mux_init_gpio(LCD_PANEL_BKLIGHT_PWR, OMAP_PIN_INPUT_PULLDOWN);
252         omap_mux_init_gpio(LCD_PANEL_PWM, OMAP_PIN_INPUT_PULLDOWN);
253         /*
254          * Enable GPIO 182 = LCD Backlight Power
255          */
256         r = gpio_request(LCD_PANEL_BKLIGHT_PWR, "lcd_backlight_pwr");
257         if (r) {
258                 printk(KERN_ERR "failed to get lcd_backlight_pwr\n");
259                 return;
260         }
261         gpio_direction_output(LCD_PANEL_BKLIGHT_PWR, 1);
262         /*
263          * Enable GPIO 181 = LCD Panel PWM
264          */
265         r = gpio_request(LCD_PANEL_PWM, "lcd_pwm");
266         if (r) {
267                 printk(KERN_ERR "failed to get lcd_pwm\n");
268                 goto err_1;
269         }
270         gpio_direction_output(LCD_PANEL_PWM, 1);
271         /*
272          * Enable GPIO 176 = LCD Panel Power enable pin
273          */
274         r = gpio_request(LCD_PANEL_PWR, "lcd_panel_pwr");
275         if (r) {
276                 printk(KERN_ERR "failed to get lcd_panel_pwr\n");
277                 goto err_2;
278         }
279         gpio_direction_output(LCD_PANEL_PWR, 1);
280
281         printk(KERN_INFO "Display initialized successfully\n");
282         return;
283
284 err_2:
285         gpio_free(LCD_PANEL_PWM);
286 err_1:
287         gpio_free(LCD_PANEL_BKLIGHT_PWR);
288 }
289 #else
290 static void __init am3517_evm_display_init(void) {}
291 #endif
292
293 static int am3517_evm_panel_enable_lcd(struct omap_dss_device *dssdev)
294 {
295         if (dvi_enabled) {
296                 printk(KERN_ERR "cannot enable LCD, DVI is enabled\n");
297                 return -EINVAL;
298         }
299         gpio_set_value(LCD_PANEL_PWR, 1);
300         lcd_enabled = 1;
301
302         return 0;
303 }
304
305 static void am3517_evm_panel_disable_lcd(struct omap_dss_device *dssdev)
306 {
307         gpio_set_value(LCD_PANEL_PWR, 0);
308         lcd_enabled = 0;
309 }
310
311 static struct omap_dss_device am3517_evm_lcd_device = {
312         .type                   = OMAP_DISPLAY_TYPE_DPI,
313         .name                   = "lcd",
314         .driver_name            = "sharp_lq_panel",
315         .phy.dpi.data_lines     = 16,
316         .platform_enable        = am3517_evm_panel_enable_lcd,
317         .platform_disable       = am3517_evm_panel_disable_lcd,
318 };
319
320 static int am3517_evm_panel_enable_tv(struct omap_dss_device *dssdev)
321 {
322         return 0;
323 }
324
325 static void am3517_evm_panel_disable_tv(struct omap_dss_device *dssdev)
326 {
327 }
328
329 static struct omap_dss_device am3517_evm_tv_device = {
330         .type                   = OMAP_DISPLAY_TYPE_VENC,
331         .name                   = "tv",
332         .driver_name            = "venc",
333         .phy.venc.type          = OMAP_DSS_VENC_TYPE_SVIDEO,
334         .platform_enable        = am3517_evm_panel_enable_tv,
335         .platform_disable       = am3517_evm_panel_disable_tv,
336 };
337
338 static int am3517_evm_panel_enable_dvi(struct omap_dss_device *dssdev)
339 {
340         if (lcd_enabled) {
341                 printk(KERN_ERR "cannot enable DVI, LCD is enabled\n");
342                 return -EINVAL;
343         }
344         dvi_enabled = 1;
345
346         return 0;
347 }
348
349 static void am3517_evm_panel_disable_dvi(struct omap_dss_device *dssdev)
350 {
351         dvi_enabled = 0;
352 }
353
354 static struct omap_dss_device am3517_evm_dvi_device = {
355         .type                   = OMAP_DISPLAY_TYPE_DPI,
356         .name                   = "dvi",
357         .driver_name            = "generic_panel",
358         .phy.dpi.data_lines     = 24,
359         .platform_enable        = am3517_evm_panel_enable_dvi,
360         .platform_disable       = am3517_evm_panel_disable_dvi,
361 };
362
363 static struct omap_dss_device *am3517_evm_dss_devices[] = {
364         &am3517_evm_lcd_device,
365         &am3517_evm_tv_device,
366         &am3517_evm_dvi_device,
367 };
368
369 static struct omap_dss_board_info am3517_evm_dss_data = {
370         .num_devices    = ARRAY_SIZE(am3517_evm_dss_devices),
371         .devices        = am3517_evm_dss_devices,
372         .default_device = &am3517_evm_lcd_device,
373 };
374
375 struct platform_device am3517_evm_dss_device = {
376         .name           = "omapdss",
377         .id             = -1,
378         .dev            = {
379                 .platform_data  = &am3517_evm_dss_data,
380         },
381 };
382
383 /*
384  * Board initialization
385  */
386 static struct omap_board_config_kernel am3517_evm_config[] __initdata = {
387 };
388
389 static struct platform_device *am3517_evm_devices[] __initdata = {
390         &am3517_evm_dss_device,
391 };
392
393 static void __init am3517_evm_init_irq(void)
394 {
395         omap_board_config = am3517_evm_config;
396         omap_board_config_size = ARRAY_SIZE(am3517_evm_config);
397
398         omap2_init_common_hw(NULL, NULL);
399         omap_init_irq();
400         omap_gpio_init();
401 }
402
403 static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
404         .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
405 #if defined(CONFIG_PANEL_SHARP_LQ043T1DG01) || \
406                 defined(CONFIG_PANEL_SHARP_LQ043T1DG01_MODULE)
407         .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN,
408 #else
409         .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
410 #endif
411         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
412
413         .phy_reset  = true,
414         .reset_gpio_port[0]  = 57,
415         .reset_gpio_port[1]  = -EINVAL,
416         .reset_gpio_port[2]  = -EINVAL
417 };
418
419 #ifdef CONFIG_OMAP_MUX
420 static struct omap_board_mux board_mux[] __initdata = {
421         { .reg_offset = OMAP_MUX_TERMINATOR },
422 };
423 #else
424 #define board_mux       NULL
425 #endif
426
427
428 static struct resource am3517_hecc_resources[] = {
429         {
430                 .start  = AM35XX_IPSS_HECC_BASE,
431                 .end    = AM35XX_IPSS_HECC_BASE + 0x3FFF,
432                 .flags  = IORESOURCE_MEM,
433         },
434         {
435                 .start  = INT_35XX_HECC0_IRQ,
436                 .end    = INT_35XX_HECC0_IRQ,
437                 .flags  = IORESOURCE_IRQ,
438         },
439 };
440
441 static struct platform_device am3517_hecc_device = {
442         .name           = "ti_hecc",
443         .id             = -1,
444         .num_resources  = ARRAY_SIZE(am3517_hecc_resources),
445         .resource       = am3517_hecc_resources,
446 };
447
448 static struct ti_hecc_platform_data am3517_evm_hecc_pdata = {
449         .scc_hecc_offset        = AM35XX_HECC_SCC_HECC_OFFSET,
450         .scc_ram_offset         = AM35XX_HECC_SCC_RAM_OFFSET,
451         .hecc_ram_offset        = AM35XX_HECC_RAM_OFFSET,
452         .mbx_offset             = AM35XX_HECC_MBOX_OFFSET,
453         .int_line               = AM35XX_HECC_INT_LINE,
454         .version                = AM35XX_HECC_VERSION,
455 };
456
457 static void am3517_evm_hecc_init(struct ti_hecc_platform_data *pdata)
458 {
459         am3517_hecc_device.dev.platform_data = pdata;
460         platform_device_register(&am3517_hecc_device);
461 }
462
463 static void __init am3517_evm_init(void)
464 {
465         omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
466
467         am3517_evm_i2c_init();
468         platform_add_devices(am3517_evm_devices,
469                                 ARRAY_SIZE(am3517_evm_devices));
470
471         omap_serial_init();
472
473         /* Configure GPIO for EHCI port */
474         omap_mux_init_gpio(57, OMAP_PIN_OUTPUT);
475         usb_ehci_init(&ehci_pdata);
476         am3517_evm_hecc_init(&am3517_evm_hecc_pdata);
477         /* DSS */
478         am3517_evm_display_init();
479
480         /* RTC - S35390A */
481         am3517_evm_rtc_init();
482
483         i2c_register_board_info(1, am3517evm_i2c1_boardinfo,
484                                 ARRAY_SIZE(am3517evm_i2c1_boardinfo));
485         /*Ethernet*/
486         am3517_evm_ethernet_init(&am3517_evm_emac_pdata);
487 }
488
489 MACHINE_START(OMAP3517EVM, "OMAP3517/AM3517 EVM")
490         .phys_io        = 0x48000000,
491         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
492         .boot_params    = 0x80000100,
493         .map_io         = omap3_map_io,
494         .reserve        = omap_reserve,
495         .init_irq       = am3517_evm_init_irq,
496         .init_machine   = am3517_evm_init,
497         .timer          = &omap_timer,
498 MACHINE_END