Merge branch 'fix' of git://git.kernel.org/pub/scm/linux/kernel/git/ycmiao/pxa-linux-2.6
[linux-2.6] / arch / blackfin / mach-bf533 / boards / blackstamp.c
1 /*
2  * File:         arch/blackfin/mach-bf533/blackstamp.c
3  * Based on:     arch/blackfin/mach-bf533/stamp.c
4  * Author:       Benjamin Matthews <bmat@lle.rochester.edu>
5  *               Aidan Williams <aidan@nicta.com.au>
6  *
7  * Created:      2008
8  * Description:  Board Info File for the BlackStamp
9  *
10  * Copyright 2005 National ICT Australia (NICTA)
11  * Copyright 2004-2008 Analog Devices Inc.
12  *
13  * Enter bugs at http://blackfin.uclinux.org/
14  *
15  * More info about the BlackStamp at:
16  *      http://blackfin.uclinux.org/gf/project/blackstamp/
17  *
18  * Licensed under the GPL-2 or later.
19  */
20
21 #include <linux/device.h>
22 #include <linux/platform_device.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/partitions.h>
25 #include <linux/mtd/physmap.h>
26 #include <linux/spi/spi.h>
27 #include <linux/spi/flash.h>
28 #include <linux/irq.h>
29 #include <linux/i2c.h>
30 #include <asm/dma.h>
31 #include <asm/bfin5xx_spi.h>
32 #include <asm/portmux.h>
33 #include <asm/dpmc.h>
34
35 /*
36  * Name the Board for the /proc/cpuinfo
37  */
38 const char bfin_board_name[] = "BlackStamp";
39
40 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
41 static struct platform_device rtc_device = {
42         .name = "rtc-bfin",
43         .id   = -1,
44 };
45 #endif
46
47 /*
48  *  Driver needs to know address, irq and flag pin.
49  */
50 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
51 static struct resource smc91x_resources[] = {
52         {
53                 .name = "smc91x-regs",
54                 .start = 0x20300300,
55                 .end = 0x20300300 + 16,
56                 .flags = IORESOURCE_MEM,
57         }, {
58                 .start = IRQ_PF3,
59                 .end = IRQ_PF3,
60                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
61         },
62 };
63
64 static struct platform_device smc91x_device = {
65         .name = "smc91x",
66         .id = 0,
67         .num_resources = ARRAY_SIZE(smc91x_resources),
68         .resource = smc91x_resources,
69 };
70 #endif
71
72 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
73 static struct mtd_partition bfin_spi_flash_partitions[] = {
74         {
75                 .name = "bootloader(spi)",
76                 .size = 0x00040000,
77                 .offset = 0,
78                 .mask_flags = MTD_CAP_ROM
79         }, {
80                 .name = "linux kernel(spi)",
81                 .size = 0x180000,
82                 .offset = MTDPART_OFS_APPEND,
83         }, {
84                 .name = "file system(spi)",
85                 .size = MTDPART_SIZ_FULL,
86                 .offset = MTDPART_OFS_APPEND,
87         }
88 };
89
90 static struct flash_platform_data bfin_spi_flash_data = {
91         .name = "m25p80",
92         .parts = bfin_spi_flash_partitions,
93         .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
94         .type = "m25p64",
95 };
96
97 /* SPI flash chip (m25p64) */
98 static struct bfin5xx_spi_chip spi_flash_chip_info = {
99         .enable_dma = 0,         /* use dma transfer with this chip*/
100         .bits_per_word = 8,
101 };
102 #endif
103
104 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
105 static struct bfin5xx_spi_chip mmc_spi_chip_info = {
106         .enable_dma = 0,
107         .bits_per_word = 8,
108 };
109 #endif
110
111 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
112 static struct bfin5xx_spi_chip spidev_chip_info = {
113         .enable_dma = 0,
114         .bits_per_word = 8,
115 };
116 #endif
117
118 static struct spi_board_info bfin_spi_board_info[] __initdata = {
119 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
120         {
121                 /* the modalias must be the same as spi device driver name */
122                 .modalias = "m25p80", /* Name of spi_driver for this device */
123                 .max_speed_hz = 20000000,     /* max spi clock (SCK) speed in HZ */
124                 .bus_num = 0, /* Framework bus number */
125                 .chip_select = 2, /* Framework chip select. */
126                 .platform_data = &bfin_spi_flash_data,
127                 .controller_data = &spi_flash_chip_info,
128                 .mode = SPI_MODE_3,
129         },
130 #endif
131
132 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
133         {
134                 .modalias = "mmc_spi",
135                 .max_speed_hz = 20000000,     /* max spi clock (SCK) speed in HZ */
136                 .bus_num = 0,
137                 .chip_select = 5,
138                 .controller_data = &mmc_spi_chip_info,
139                 .mode = SPI_MODE_3,
140         },
141 #endif
142
143 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
144         {
145                 .modalias = "spidev",
146                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
147                 .bus_num = 0,
148                 .chip_select = 7,
149                 .controller_data = &spidev_chip_info,
150         },
151 #endif
152 };
153
154 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
155 /* SPI (0) */
156 static struct resource bfin_spi0_resource[] = {
157         [0] = {
158                 .start = SPI0_REGBASE,
159                 .end   = SPI0_REGBASE + 0xFF,
160                 .flags = IORESOURCE_MEM,
161         },
162         [1] = {
163                 .start = CH_SPI,
164                 .end   = CH_SPI,
165                 .flags = IORESOURCE_IRQ,
166         }
167 };
168
169 /* SPI controller data */
170 static struct bfin5xx_spi_master bfin_spi0_info = {
171         .num_chipselect = 8,
172         .enable_dma = 1,  /* master has the ability to do dma transfer */
173         .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
174 };
175
176 static struct platform_device bfin_spi0_device = {
177         .name = "bfin-spi",
178         .id = 0, /* Bus number */
179         .num_resources = ARRAY_SIZE(bfin_spi0_resource),
180         .resource = bfin_spi0_resource,
181         .dev = {
182                 .platform_data = &bfin_spi0_info, /* Passed to driver */
183         },
184 };
185 #endif  /* spi master and devices */
186
187 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
188 static struct resource bfin_uart_resources[] = {
189         {
190                 .start = 0xFFC00400,
191                 .end = 0xFFC004FF,
192                 .flags = IORESOURCE_MEM,
193         },
194 };
195
196 static struct platform_device bfin_uart_device = {
197         .name = "bfin-uart",
198         .id = 1,
199         .num_resources = ARRAY_SIZE(bfin_uart_resources),
200         .resource = bfin_uart_resources,
201 };
202 #endif
203
204 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
205 #ifdef CONFIG_BFIN_SIR0
206 static struct resource bfin_sir0_resources[] = {
207         {
208                 .start = 0xFFC00400,
209                 .end = 0xFFC004FF,
210                 .flags = IORESOURCE_MEM,
211         },
212         {
213                 .start = IRQ_UART0_RX,
214                 .end = IRQ_UART0_RX+1,
215                 .flags = IORESOURCE_IRQ,
216         },
217         {
218                 .start = CH_UART0_RX,
219                 .end = CH_UART0_RX+1,
220                 .flags = IORESOURCE_DMA,
221         },
222 };
223
224 static struct platform_device bfin_sir0_device = {
225         .name = "bfin_sir",
226         .id = 0,
227         .num_resources = ARRAY_SIZE(bfin_sir0_resources),
228         .resource = bfin_sir0_resources,
229 };
230 #endif
231 #endif
232
233 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
234 static struct platform_device bfin_sport0_uart_device = {
235         .name = "bfin-sport-uart",
236         .id = 0,
237 };
238
239 static struct platform_device bfin_sport1_uart_device = {
240         .name = "bfin-sport-uart",
241         .id = 1,
242 };
243 #endif
244
245 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
246 #include <linux/input.h>
247 #include <linux/gpio_keys.h>
248
249 static struct gpio_keys_button bfin_gpio_keys_table[] = {
250         {BTN_0, GPIO_PF4, 0, "gpio-keys: BTN0"},
251         {BTN_1, GPIO_PF5, 0, "gpio-keys: BTN1"},
252         {BTN_2, GPIO_PF6, 0, "gpio-keys: BTN2"},
253 }; /* Mapped to the first three PF Test Points */
254
255 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
256         .buttons        = bfin_gpio_keys_table,
257         .nbuttons       = ARRAY_SIZE(bfin_gpio_keys_table),
258 };
259
260 static struct platform_device bfin_device_gpiokeys = {
261         .name      = "gpio-keys",
262         .dev = {
263                 .platform_data = &bfin_gpio_keys_data,
264         },
265 };
266 #endif
267
268 static struct resource bfin_gpios_resources = {
269         .start = 0,
270         .end   = MAX_BLACKFIN_GPIOS - 1,
271         .flags = IORESOURCE_IRQ,
272 };
273
274 static struct platform_device bfin_gpios_device = {
275         .name = "simple-gpio",
276         .id = -1,
277         .num_resources = 1,
278         .resource = &bfin_gpios_resources,
279 };
280
281 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
282 #include <linux/i2c-gpio.h>
283
284 static struct i2c_gpio_platform_data i2c_gpio_data = {
285         .sda_pin                = 8,
286         .scl_pin                = 9,
287         .sda_is_open_drain      = 0,
288         .scl_is_open_drain      = 0,
289         .udelay                 = 40,
290 }; /* This hasn't actually been used these pins
291     * are (currently) free pins on the expansion connector */
292
293 static struct platform_device i2c_gpio_device = {
294         .name           = "i2c-gpio",
295         .id             = 0,
296         .dev            = {
297                 .platform_data  = &i2c_gpio_data,
298         },
299 };
300 #endif
301
302 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
303 };
304
305 static const unsigned int cclk_vlev_datasheet[] =
306 {
307         VRPAIR(VLEV_085, 250000000),
308         VRPAIR(VLEV_090, 376000000),
309         VRPAIR(VLEV_095, 426000000),
310         VRPAIR(VLEV_100, 426000000),
311         VRPAIR(VLEV_105, 476000000),
312         VRPAIR(VLEV_110, 476000000),
313         VRPAIR(VLEV_115, 476000000),
314         VRPAIR(VLEV_120, 600000000),
315         VRPAIR(VLEV_125, 600000000),
316         VRPAIR(VLEV_130, 600000000),
317 };
318
319 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
320         .tuple_tab = cclk_vlev_datasheet,
321         .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
322         .vr_settling_time = 25 /* us */,
323 };
324
325 static struct platform_device bfin_dpmc = {
326         .name = "bfin dpmc",
327         .dev = {
328                 .platform_data = &bfin_dmpc_vreg_data,
329         },
330 };
331
332 static struct platform_device *stamp_devices[] __initdata = {
333
334         &bfin_dpmc,
335
336 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
337         &rtc_device,
338 #endif
339
340 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
341         &smc91x_device,
342 #endif
343
344
345 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
346         &bfin_spi0_device,
347 #endif
348
349 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
350         &bfin_uart_device,
351 #endif
352
353 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
354 #ifdef CONFIG_BFIN_SIR0
355         &bfin_sir0_device,
356 #endif
357 #endif
358
359 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
360         &bfin_sport0_uart_device,
361         &bfin_sport1_uart_device,
362 #endif
363
364 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
365         &bfin_device_gpiokeys,
366 #endif
367
368 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
369         &i2c_gpio_device,
370 #endif
371
372         &bfin_gpios_device,
373 };
374
375 static int __init blackstamp_init(void)
376 {
377         int ret;
378
379         printk(KERN_INFO "%s(): registering device resources\n", __func__);
380
381         i2c_register_board_info(0, bfin_i2c_board_info,
382                                 ARRAY_SIZE(bfin_i2c_board_info));
383
384         ret = platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
385         if (ret < 0)
386                 return ret;
387
388 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
389         /* setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC */
390         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF0);
391         bfin_write_FIO_FLAG_S(PF0);
392         SSYNC();
393 #endif
394
395         spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
396         return 0;
397 }
398
399 arch_initcall(blackstamp_init);