Merge git://git.kernel.org/pub/scm/linux/kernel/git/padovan/bluetooth-2.6 into test
[pandora-kernel.git] / arch / arm / mach-omap2 / board-zoom-debugboard.c
1 /*
2  * Copyright (C) 2009 Texas Instruments Inc.
3  * Mikkel Christensen <mlc@ti.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/gpio.h>
13 #include <linux/serial_8250.h>
14 #include <linux/smsc911x.h>
15 #include <linux/interrupt.h>
16
17 #include <plat/gpmc.h>
18
19 #include <mach/board-zoom.h>
20
21 #define ZOOM_SMSC911X_CS        7
22 #define ZOOM_SMSC911X_GPIO      158
23 #define ZOOM_QUADUART_CS        3
24 #define ZOOM_QUADUART_GPIO      102
25 #define QUART_CLK               1843200
26 #define DEBUG_BASE              0x08000000
27 #define ZOOM_ETHR_START DEBUG_BASE
28
29 static struct resource zoom_smsc911x_resources[] = {
30         [0] = {
31                 .start  = ZOOM_ETHR_START,
32                 .end    = ZOOM_ETHR_START + SZ_4K,
33                 .flags  = IORESOURCE_MEM,
34         },
35         [1] = {
36                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
37         },
38 };
39
40 static struct smsc911x_platform_config zoom_smsc911x_config = {
41         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
42         .irq_type       = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
43         .flags          = SMSC911X_USE_32BIT,
44         .phy_interface  = PHY_INTERFACE_MODE_MII,
45 };
46
47 static struct platform_device zoom_smsc911x_device = {
48         .name           = "smsc911x",
49         .id             = -1,
50         .num_resources  = ARRAY_SIZE(zoom_smsc911x_resources),
51         .resource       = zoom_smsc911x_resources,
52         .dev            = {
53                 .platform_data = &zoom_smsc911x_config,
54         },
55 };
56
57 static inline void __init zoom_init_smsc911x(void)
58 {
59         int eth_cs;
60         unsigned long cs_mem_base;
61         int eth_gpio = 0;
62
63         eth_cs = ZOOM_SMSC911X_CS;
64
65         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
66                 printk(KERN_ERR "Failed to request GPMC mem for smsc911x\n");
67                 return;
68         }
69
70         zoom_smsc911x_resources[0].start = cs_mem_base + 0x0;
71         zoom_smsc911x_resources[0].end   = cs_mem_base + 0xff;
72
73         eth_gpio = ZOOM_SMSC911X_GPIO;
74
75         zoom_smsc911x_resources[1].start = OMAP_GPIO_IRQ(eth_gpio);
76
77         if (gpio_request(eth_gpio, "smsc911x irq") < 0) {
78                 printk(KERN_ERR "Failed to request GPIO%d for smsc911x IRQ\n",
79                                 eth_gpio);
80                 return;
81         }
82         gpio_direction_input(eth_gpio);
83 }
84
85 static struct plat_serial8250_port serial_platform_data[] = {
86         {
87                 .mapbase        = ZOOM_UART_BASE,
88                 .irq            = OMAP_GPIO_IRQ(102),
89                 .flags          = UPF_BOOT_AUTOCONF|UPF_IOREMAP|UPF_SHARE_IRQ,
90                 .irqflags       = IRQF_SHARED | IRQF_TRIGGER_RISING,
91                 .iotype         = UPIO_MEM,
92                 .regshift       = 1,
93                 .uartclk        = QUART_CLK,
94         }, {
95                 .flags          = 0
96         }
97 };
98
99 static struct platform_device zoom_debugboard_serial_device = {
100         .name                   = "serial8250",
101         .id                     = PLAT8250_DEV_PLATFORM,
102         .dev                    = {
103                 .platform_data  = serial_platform_data,
104         },
105 };
106
107 static inline void __init zoom_init_quaduart(void)
108 {
109         int quart_cs;
110         unsigned long cs_mem_base;
111         int quart_gpio = 0;
112
113         quart_cs = ZOOM_QUADUART_CS;
114
115         if (gpmc_cs_request(quart_cs, SZ_1M, &cs_mem_base) < 0) {
116                 printk(KERN_ERR "Failed to request GPMC mem"
117                                 "for Quad UART(TL16CP754C)\n");
118                 return;
119         }
120
121         quart_gpio = ZOOM_QUADUART_GPIO;
122
123         if (gpio_request(quart_gpio, "TL16CP754C GPIO") < 0) {
124                 printk(KERN_ERR "Failed to request GPIO%d for TL16CP754C\n",
125                                                                 quart_gpio);
126                 return;
127         }
128         gpio_direction_input(quart_gpio);
129 }
130
131 static inline int omap_zoom_debugboard_detect(void)
132 {
133         int debug_board_detect = 0;
134         int ret = 1;
135
136         debug_board_detect = ZOOM_SMSC911X_GPIO;
137
138         if (gpio_request(debug_board_detect, "Zoom debug board detect") < 0) {
139                 printk(KERN_ERR "Failed to request GPIO%d for Zoom debug"
140                 "board detect\n", debug_board_detect);
141                 return 0;
142         }
143         gpio_direction_input(debug_board_detect);
144
145         if (!gpio_get_value(debug_board_detect)) {
146                 ret = 0;
147         }
148         gpio_free(debug_board_detect);
149         return ret;
150 }
151
152 static struct platform_device *zoom_devices[] __initdata = {
153         &zoom_smsc911x_device,
154         &zoom_debugboard_serial_device,
155 };
156
157 int __init zoom_debugboard_init(void)
158 {
159         if (!omap_zoom_debugboard_detect())
160                 return 0;
161
162         zoom_init_smsc911x();
163         zoom_init_quaduart();
164         return platform_add_devices(zoom_devices, ARRAY_SIZE(zoom_devices));
165 }