PM / Suspend: Fix bug in suspend statistics update
[pandora-kernel.git] / arch / blackfin / mach-bf561 / boards / ezkit.c
1 /*
2  * Copyright 2004-2009 Analog Devices Inc.
3  *               2005 National ICT Australia (NICTA)
4  *                    Aidan Williams <aidan@nicta.com.au>
5  *
6  * Licensed under the GPL-2 or later.
7  */
8
9 #include <linux/device.h>
10 #include <linux/platform_device.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/partitions.h>
13 #include <linux/mtd/physmap.h>
14 #include <linux/spi/spi.h>
15 #include <linux/irq.h>
16 #include <linux/interrupt.h>
17 #include <linux/delay.h>
18 #include <asm/dma.h>
19 #include <asm/bfin5xx_spi.h>
20 #include <asm/portmux.h>
21 #include <asm/dpmc.h>
22
23 /*
24  * Name the Board for the /proc/cpuinfo
25  */
26 const char bfin_board_name[] = "ADI BF561-EZKIT";
27
28 #if defined(CONFIG_USB_ISP1760_HCD) || defined(CONFIG_USB_ISP1760_HCD_MODULE)
29 #include <linux/usb/isp1760.h>
30 static struct resource bfin_isp1760_resources[] = {
31         [0] = {
32                 .start  = 0x2C0F0000,
33                 .end    = 0x203C0000 + 0xfffff,
34                 .flags  = IORESOURCE_MEM,
35         },
36         [1] = {
37                 .start  = IRQ_PF10,
38                 .end    = IRQ_PF10,
39                 .flags  = IORESOURCE_IRQ,
40         },
41 };
42
43 static struct isp1760_platform_data isp1760_priv = {
44         .is_isp1761 = 0,
45         .bus_width_16 = 1,
46         .port1_otg = 0,
47         .analog_oc = 0,
48         .dack_polarity_high = 0,
49         .dreq_polarity_high = 0,
50 };
51
52 static struct platform_device bfin_isp1760_device = {
53         .name           = "isp1760",
54         .id             = 0,
55         .dev = {
56                 .platform_data = &isp1760_priv,
57         },
58         .num_resources  = ARRAY_SIZE(bfin_isp1760_resources),
59         .resource       = bfin_isp1760_resources,
60 };
61 #endif
62
63 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
64 #include <linux/usb/isp1362.h>
65
66 static struct resource isp1362_hcd_resources[] = {
67         {
68                 .start = 0x2c060000,
69                 .end = 0x2c060000,
70                 .flags = IORESOURCE_MEM,
71         }, {
72                 .start = 0x2c060004,
73                 .end = 0x2c060004,
74                 .flags = IORESOURCE_MEM,
75         }, {
76                 .start = IRQ_PF8,
77                 .end = IRQ_PF8,
78                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
79         },
80 };
81
82 static struct isp1362_platform_data isp1362_priv = {
83         .sel15Kres = 1,
84         .clknotstop = 0,
85         .oc_enable = 0,
86         .int_act_high = 0,
87         .int_edge_triggered = 0,
88         .remote_wakeup_connected = 0,
89         .no_power_switching = 1,
90         .power_switching_mode = 0,
91 };
92
93 static struct platform_device isp1362_hcd_device = {
94         .name = "isp1362-hcd",
95         .id = 0,
96         .dev = {
97                 .platform_data = &isp1362_priv,
98         },
99         .num_resources = ARRAY_SIZE(isp1362_hcd_resources),
100         .resource = isp1362_hcd_resources,
101 };
102 #endif
103
104 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
105 static struct resource net2272_bfin_resources[] = {
106         {
107                 .start = 0x2C000000,
108                 .end = 0x2C000000 + 0x7F,
109                 .flags = IORESOURCE_MEM,
110         }, {
111                 .start = 1,
112                 .flags = IORESOURCE_BUS,
113         }, {
114                 .start = IRQ_PF10,
115                 .end = IRQ_PF10,
116                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
117         },
118 };
119
120 static struct platform_device net2272_bfin_device = {
121         .name = "net2272",
122         .id = -1,
123         .num_resources = ARRAY_SIZE(net2272_bfin_resources),
124         .resource = net2272_bfin_resources,
125 };
126 #endif
127
128 /*
129  *  USB-LAN EzExtender board
130  *  Driver needs to know address, irq and flag pin.
131  */
132 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
133 #include <linux/smc91x.h>
134
135 static struct smc91x_platdata smc91x_info = {
136         .flags = SMC91X_USE_32BIT | SMC91X_NOWAIT,
137         .leda = RPC_LED_100_10,
138         .ledb = RPC_LED_TX_RX,
139 };
140
141 static struct resource smc91x_resources[] = {
142         {
143                 .name = "smc91x-regs",
144                 .start = 0x2C010300,
145                 .end = 0x2C010300 + 16,
146                 .flags = IORESOURCE_MEM,
147         }, {
148
149                 .start = IRQ_PF9,
150                 .end = IRQ_PF9,
151                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
152         },
153 };
154
155 static struct platform_device smc91x_device = {
156         .name = "smc91x",
157         .id = 0,
158         .num_resources = ARRAY_SIZE(smc91x_resources),
159         .resource = smc91x_resources,
160         .dev    = {
161                 .platform_data  = &smc91x_info,
162         },
163 };
164 #endif
165
166 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
167 #ifdef CONFIG_SERIAL_BFIN_UART0
168 static struct resource bfin_uart0_resources[] = {
169         {
170                 .start = BFIN_UART_THR,
171                 .end = BFIN_UART_GCTL+2,
172                 .flags = IORESOURCE_MEM,
173         },
174         {
175                 .start = IRQ_UART_RX,
176                 .end = IRQ_UART_RX+1,
177                 .flags = IORESOURCE_IRQ,
178         },
179         {
180                 .start = IRQ_UART_ERROR,
181                 .end = IRQ_UART_ERROR,
182                 .flags = IORESOURCE_IRQ,
183         },
184         {
185                 .start = CH_UART_TX,
186                 .end = CH_UART_TX,
187                 .flags = IORESOURCE_DMA,
188         },
189         {
190                 .start = CH_UART_RX,
191                 .end = CH_UART_RX,
192                 .flags = IORESOURCE_DMA,
193         },
194 };
195
196 static unsigned short bfin_uart0_peripherals[] = {
197         P_UART0_TX, P_UART0_RX, 0
198 };
199
200 static struct platform_device bfin_uart0_device = {
201         .name = "bfin-uart",
202         .id = 0,
203         .num_resources = ARRAY_SIZE(bfin_uart0_resources),
204         .resource = bfin_uart0_resources,
205         .dev = {
206                 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
207         },
208 };
209 #endif
210 #endif
211
212 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
213 #ifdef CONFIG_BFIN_SIR0
214 static struct resource bfin_sir0_resources[] = {
215         {
216                 .start = 0xFFC00400,
217                 .end = 0xFFC004FF,
218                 .flags = IORESOURCE_MEM,
219         },
220         {
221                 .start = IRQ_UART0_RX,
222                 .end = IRQ_UART0_RX+1,
223                 .flags = IORESOURCE_IRQ,
224         },
225         {
226                 .start = CH_UART0_RX,
227                 .end = CH_UART0_RX+1,
228                 .flags = IORESOURCE_DMA,
229         },
230 };
231
232 static struct platform_device bfin_sir0_device = {
233         .name = "bfin_sir",
234         .id = 0,
235         .num_resources = ARRAY_SIZE(bfin_sir0_resources),
236         .resource = bfin_sir0_resources,
237 };
238 #endif
239 #endif
240
241 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
242 static struct mtd_partition ezkit_partitions[] = {
243         {
244                 .name       = "bootloader(nor)",
245                 .size       = 0x40000,
246                 .offset     = 0,
247         }, {
248                 .name       = "linux kernel(nor)",
249                 .size       = 0x1C0000,
250                 .offset     = MTDPART_OFS_APPEND,
251         }, {
252                 .name       = "file system(nor)",
253                 .size       = 0x800000 - 0x40000 - 0x1C0000 - 0x2000 * 8,
254                 .offset     = MTDPART_OFS_APPEND,
255         }, {
256                 .name       = "config(nor)",
257                 .size       = 0x2000 * 7,
258                 .offset     = MTDPART_OFS_APPEND,
259         }, {
260                 .name       = "u-boot env(nor)",
261                 .size       = 0x2000,
262                 .offset     = MTDPART_OFS_APPEND,
263         }
264 };
265
266 static struct physmap_flash_data ezkit_flash_data = {
267         .width      = 2,
268         .parts      = ezkit_partitions,
269         .nr_parts   = ARRAY_SIZE(ezkit_partitions),
270 };
271
272 static struct resource ezkit_flash_resource = {
273         .start = 0x20000000,
274         .end   = 0x207fffff,
275         .flags = IORESOURCE_MEM,
276 };
277
278 static struct platform_device ezkit_flash_device = {
279         .name          = "physmap-flash",
280         .id            = 0,
281         .dev = {
282                 .platform_data = &ezkit_flash_data,
283         },
284         .num_resources = 1,
285         .resource      = &ezkit_flash_resource,
286 };
287 #endif
288
289 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
290 /* SPI (0) */
291 static struct resource bfin_spi0_resource[] = {
292         [0] = {
293                 .start = SPI0_REGBASE,
294                 .end   = SPI0_REGBASE + 0xFF,
295                 .flags = IORESOURCE_MEM,
296         },
297         [1] = {
298                 .start = CH_SPI,
299                 .end   = CH_SPI,
300                 .flags = IORESOURCE_DMA,
301         },
302         [2] = {
303                 .start = IRQ_SPI,
304                 .end   = IRQ_SPI,
305                 .flags = IORESOURCE_IRQ,
306         }
307 };
308
309 /* SPI controller data */
310 static struct bfin5xx_spi_master bfin_spi0_info = {
311         .num_chipselect = 8,
312         .enable_dma = 1,  /* master has the ability to do dma transfer */
313         .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
314 };
315
316 static struct platform_device bfin_spi0_device = {
317         .name = "bfin-spi",
318         .id = 0, /* Bus number */
319         .num_resources = ARRAY_SIZE(bfin_spi0_resource),
320         .resource = bfin_spi0_resource,
321         .dev = {
322                 .platform_data = &bfin_spi0_info, /* Passed to driver */
323         },
324 };
325 #endif
326
327 static struct spi_board_info bfin_spi_board_info[] __initdata = {
328 #if defined(CONFIG_SND_BF5XX_SOC_AD183X) \
329         || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE)
330         {
331                 .modalias = "ad183x",
332                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
333                 .bus_num = 0,
334                 .chip_select = 4,
335                 .platform_data = "ad1836", /* only includes chip name for the moment */
336                 .mode = SPI_MODE_3,
337         },
338 #endif
339 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
340         {
341                 .modalias = "spidev",
342                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
343                 .bus_num = 0,
344                 .chip_select = 1,
345         },
346 #endif
347 };
348
349 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
350 #include <linux/input.h>
351 #include <linux/gpio_keys.h>
352
353 static struct gpio_keys_button bfin_gpio_keys_table[] = {
354         {BTN_0, GPIO_PF5, 1, "gpio-keys: BTN0"},
355         {BTN_1, GPIO_PF6, 1, "gpio-keys: BTN1"},
356         {BTN_2, GPIO_PF7, 1, "gpio-keys: BTN2"},
357         {BTN_3, GPIO_PF8, 1, "gpio-keys: BTN3"},
358 };
359
360 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
361         .buttons        = bfin_gpio_keys_table,
362         .nbuttons       = ARRAY_SIZE(bfin_gpio_keys_table),
363 };
364
365 static struct platform_device bfin_device_gpiokeys = {
366         .name      = "gpio-keys",
367         .dev = {
368                 .platform_data = &bfin_gpio_keys_data,
369         },
370 };
371 #endif
372
373 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
374 #include <linux/i2c-gpio.h>
375
376 static struct i2c_gpio_platform_data i2c_gpio_data = {
377         .sda_pin                = GPIO_PF1,
378         .scl_pin                = GPIO_PF0,
379         .sda_is_open_drain      = 0,
380         .scl_is_open_drain      = 0,
381         .udelay                 = 40,
382 };
383
384 static struct platform_device i2c_gpio_device = {
385         .name           = "i2c-gpio",
386         .id             = 0,
387         .dev            = {
388                 .platform_data  = &i2c_gpio_data,
389         },
390 };
391 #endif
392
393 static const unsigned int cclk_vlev_datasheet[] =
394 {
395         VRPAIR(VLEV_085, 250000000),
396         VRPAIR(VLEV_090, 300000000),
397         VRPAIR(VLEV_095, 313000000),
398         VRPAIR(VLEV_100, 350000000),
399         VRPAIR(VLEV_105, 400000000),
400         VRPAIR(VLEV_110, 444000000),
401         VRPAIR(VLEV_115, 450000000),
402         VRPAIR(VLEV_120, 475000000),
403         VRPAIR(VLEV_125, 500000000),
404         VRPAIR(VLEV_130, 600000000),
405 };
406
407 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
408         .tuple_tab = cclk_vlev_datasheet,
409         .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
410         .vr_settling_time = 25 /* us */,
411 };
412
413 static struct platform_device bfin_dpmc = {
414         .name = "bfin dpmc",
415         .dev = {
416                 .platform_data = &bfin_dmpc_vreg_data,
417         },
418 };
419
420 #if defined(CONFIG_SND_BF5XX_I2S) || defined(CONFIG_SND_BF5XX_I2S_MODULE)
421 static struct platform_device bfin_i2s = {
422         .name = "bfin-i2s",
423         .id = CONFIG_SND_BF5XX_SPORT_NUM,
424         /* TODO: add platform data here */
425 };
426 #endif
427
428 #if defined(CONFIG_SND_BF5XX_TDM) || defined(CONFIG_SND_BF5XX_TDM_MODULE)
429 static struct platform_device bfin_tdm = {
430         .name = "bfin-tdm",
431         .id = CONFIG_SND_BF5XX_SPORT_NUM,
432         /* TODO: add platform data here */
433 };
434 #endif
435
436 #if defined(CONFIG_SND_BF5XX_AC97) || defined(CONFIG_SND_BF5XX_AC97_MODULE)
437 static struct platform_device bfin_ac97 = {
438         .name = "bfin-ac97",
439         .id = CONFIG_SND_BF5XX_SPORT_NUM,
440         /* TODO: add platform data here */
441 };
442 #endif
443
444 static struct platform_device *ezkit_devices[] __initdata = {
445
446         &bfin_dpmc,
447
448 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
449         &smc91x_device,
450 #endif
451
452 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
453         &net2272_bfin_device,
454 #endif
455
456 #if defined(CONFIG_USB_ISP1760_HCD) || defined(CONFIG_USB_ISP1760_HCD_MODULE)
457         &bfin_isp1760_device,
458 #endif
459
460 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
461         &bfin_spi0_device,
462 #endif
463
464 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
465 #ifdef CONFIG_SERIAL_BFIN_UART0
466         &bfin_uart0_device,
467 #endif
468 #endif
469
470 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
471 #ifdef CONFIG_BFIN_SIR0
472         &bfin_sir0_device,
473 #endif
474 #endif
475
476 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
477         &bfin_device_gpiokeys,
478 #endif
479
480 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
481         &i2c_gpio_device,
482 #endif
483
484 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
485         &isp1362_hcd_device,
486 #endif
487
488 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
489         &ezkit_flash_device,
490 #endif
491
492 #if defined(CONFIG_SND_BF5XX_I2S) || defined(CONFIG_SND_BF5XX_I2S_MODULE)
493         &bfin_i2s,
494 #endif
495
496 #if defined(CONFIG_SND_BF5XX_TDM) || defined(CONFIG_SND_BF5XX_TDM_MODULE)
497         &bfin_tdm,
498 #endif
499
500 #if defined(CONFIG_SND_BF5XX_AC97) || defined(CONFIG_SND_BF5XX_AC97_MODULE)
501         &bfin_ac97,
502 #endif
503 };
504
505 static int __init net2272_init(void)
506 {
507 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
508         int ret;
509
510         ret = gpio_request(GPIO_PF11, "net2272");
511         if (ret)
512                 return ret;
513
514         /* Reset the USB chip */
515         gpio_direction_output(GPIO_PF11, 0);
516         mdelay(2);
517         gpio_set_value(GPIO_PF11, 1);
518 #endif
519
520         return 0;
521 }
522
523 static int __init ezkit_init(void)
524 {
525         int ret;
526
527         printk(KERN_INFO "%s(): registering device resources\n", __func__);
528
529         ret = platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
530         if (ret < 0)
531                 return ret;
532
533 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
534         bfin_write_FIO0_DIR(bfin_read_FIO0_DIR() | (1 << 12));
535         SSYNC();
536 #endif
537
538 #if defined(CONFIG_SND_BF5XX_SOC_AD183X) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE)
539         bfin_write_FIO0_DIR(bfin_read_FIO0_DIR() | (1 << 15));
540         bfin_write_FIO0_FLAG_S(1 << 15);
541         SSYNC();
542         /*
543          * This initialization lasts for approximately 4500 MCLKs.
544          * MCLK = 12.288MHz
545          */
546         udelay(400);
547 #endif
548
549         if (net2272_init())
550                 pr_warning("unable to configure net2272; it probably won't work\n");
551
552         spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
553         return 0;
554 }
555
556 arch_initcall(ezkit_init);
557
558 static struct platform_device *ezkit_early_devices[] __initdata = {
559 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
560 #ifdef CONFIG_SERIAL_BFIN_UART0
561         &bfin_uart0_device,
562 #endif
563 #endif
564 };
565
566 void __init native_machine_early_platform_add_devices(void)
567 {
568         printk(KERN_INFO "register early platform devices\n");
569         early_platform_add_devices(ezkit_early_devices,
570                 ARRAY_SIZE(ezkit_early_devices));
571 }