Merge tag 'xfs-4.15-merge-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[sfrench/cifs-2.6.git] / arch / blackfin / mach-bf533 / 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/plat-ram.h>
14 #include <linux/mtd/physmap.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #if IS_ENABLED(CONFIG_USB_ISP1362_HCD)
18 #include <linux/usb/isp1362.h>
19 #endif
20 #include <linux/irq.h>
21 #include <linux/i2c.h>
22 #include <linux/gpio/machine.h>
23 #include <asm/dma.h>
24 #include <asm/bfin5xx_spi.h>
25 #include <asm/portmux.h>
26 #include <asm/dpmc.h>
27
28 /*
29  * Name the Board for the /proc/cpuinfo
30  */
31 const char bfin_board_name[] = "ADI BF533-EZKIT";
32
33 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
34 static struct platform_device rtc_device = {
35         .name = "rtc-bfin",
36         .id   = -1,
37 };
38 #endif
39
40 /*
41  *  USB-LAN EzExtender board
42  *  Driver needs to know address, irq and flag pin.
43  */
44 #if IS_ENABLED(CONFIG_SMC91X)
45 #include <linux/smc91x.h>
46
47 static struct smc91x_platdata smc91x_info = {
48         .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
49         .leda = RPC_LED_100_10,
50         .ledb = RPC_LED_TX_RX,
51 };
52
53 static struct resource smc91x_resources[] = {
54         {
55                 .name = "smc91x-regs",
56                 .start = 0x20310300,
57                 .end = 0x20310300 + 16,
58                 .flags = IORESOURCE_MEM,
59         }, {
60                 .start = IRQ_PF9,
61                 .end = IRQ_PF9,
62                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
63         },
64 };
65 static struct platform_device smc91x_device = {
66         .name = "smc91x",
67         .id = 0,
68         .num_resources = ARRAY_SIZE(smc91x_resources),
69         .resource = smc91x_resources,
70         .dev    = {
71                 .platform_data  = &smc91x_info,
72         },
73 };
74 #endif
75
76 #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
77 static struct mtd_partition ezkit_partitions_a[] = {
78         {
79                 .name       = "bootloader(nor a)",
80                 .size       = 0x40000,
81                 .offset     = 0,
82         }, {
83                 .name       = "linux kernel(nor a)",
84                 .size       = MTDPART_SIZ_FULL,
85                 .offset     = MTDPART_OFS_APPEND,
86         },
87 };
88
89 static struct physmap_flash_data ezkit_flash_data_a = {
90         .width      = 2,
91         .parts      = ezkit_partitions_a,
92         .nr_parts   = ARRAY_SIZE(ezkit_partitions_a),
93 };
94
95 static struct resource ezkit_flash_resource_a = {
96         .start = 0x20000000,
97         .end   = 0x200fffff,
98         .flags = IORESOURCE_MEM,
99 };
100
101 static struct platform_device ezkit_flash_device_a = {
102         .name          = "physmap-flash",
103         .id            = 0,
104         .dev = {
105                 .platform_data = &ezkit_flash_data_a,
106         },
107         .num_resources = 1,
108         .resource      = &ezkit_flash_resource_a,
109 };
110
111 static struct mtd_partition ezkit_partitions_b[] = {
112         {
113                 .name   = "file system(nor b)",
114                 .size   = MTDPART_SIZ_FULL,
115                 .offset = MTDPART_OFS_APPEND,
116         },
117 };
118
119 static struct physmap_flash_data ezkit_flash_data_b = {
120         .width      = 2,
121         .parts      = ezkit_partitions_b,
122         .nr_parts   = ARRAY_SIZE(ezkit_partitions_b),
123 };
124
125 static struct resource ezkit_flash_resource_b = {
126         .start = 0x20100000,
127         .end   = 0x201fffff,
128         .flags = IORESOURCE_MEM,
129 };
130
131 static struct platform_device ezkit_flash_device_b = {
132         .name          = "physmap-flash",
133         .id            = 4,
134         .dev = {
135                 .platform_data = &ezkit_flash_data_b,
136         },
137         .num_resources = 1,
138         .resource      = &ezkit_flash_resource_b,
139 };
140 #endif
141
142 #if IS_ENABLED(CONFIG_MTD_PLATRAM)
143 static struct platdata_mtd_ram sram_data_a = {
144         .mapname   = "Flash A SRAM",
145         .bankwidth = 2,
146 };
147
148 static struct resource sram_resource_a = {
149         .start = 0x20240000,
150         .end   = 0x2024ffff,
151         .flags = IORESOURCE_MEM,
152 };
153
154 static struct platform_device sram_device_a = {
155         .name          = "mtd-ram",
156         .id            = 8,
157         .dev = {
158                 .platform_data = &sram_data_a,
159         },
160         .num_resources = 1,
161         .resource      = &sram_resource_a,
162 };
163
164 static struct platdata_mtd_ram sram_data_b = {
165         .mapname   = "Flash B SRAM",
166         .bankwidth = 2,
167 };
168
169 static struct resource sram_resource_b = {
170         .start = 0x202c0000,
171         .end   = 0x202cffff,
172         .flags = IORESOURCE_MEM,
173 };
174
175 static struct platform_device sram_device_b = {
176         .name          = "mtd-ram",
177         .id            = 9,
178         .dev = {
179                 .platform_data = &sram_data_b,
180         },
181         .num_resources = 1,
182         .resource      = &sram_resource_b,
183 };
184 #endif
185
186 #if IS_ENABLED(CONFIG_MTD_M25P80)
187 static struct mtd_partition bfin_spi_flash_partitions[] = {
188         {
189                 .name = "bootloader(spi)",
190                 .size = 0x00020000,
191                 .offset = 0,
192                 .mask_flags = MTD_CAP_ROM
193         }, {
194                 .name = "linux kernel(spi)",
195                 .size = 0xe0000,
196                 .offset = MTDPART_OFS_APPEND,
197         }, {
198                 .name = "file system(spi)",
199                 .size = MTDPART_SIZ_FULL,
200                 .offset = MTDPART_OFS_APPEND,
201         }
202 };
203
204 static struct flash_platform_data bfin_spi_flash_data = {
205         .name = "m25p80",
206         .parts = bfin_spi_flash_partitions,
207         .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
208         .type = "m25p64",
209 };
210
211 /* SPI flash chip (m25p64) */
212 static struct bfin5xx_spi_chip spi_flash_chip_info = {
213         .enable_dma = 0,         /* use dma transfer with this chip*/
214 };
215 #endif
216
217 static struct spi_board_info bfin_spi_board_info[] __initdata = {
218 #if IS_ENABLED(CONFIG_MTD_M25P80)
219         {
220                 /* the modalias must be the same as spi device driver name */
221                 .modalias = "m25p80", /* Name of spi_driver for this device */
222                 .max_speed_hz = 25000000,     /* max spi clock (SCK) speed in HZ */
223                 .bus_num = 0, /* Framework bus number */
224                 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
225                 .platform_data = &bfin_spi_flash_data,
226                 .controller_data = &spi_flash_chip_info,
227                 .mode = SPI_MODE_3,
228         },
229 #endif
230
231 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD183X)
232         {
233                 .modalias = "ad183x",
234                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
235                 .bus_num = 0,
236                 .chip_select = 4,
237         },
238 #endif
239 #if IS_ENABLED(CONFIG_SPI_SPIDEV)
240         {
241                 .modalias = "spidev",
242                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
243                 .bus_num = 0,
244                 .chip_select = 1,
245         },
246 #endif
247 };
248
249 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
250 /* SPI (0) */
251 static struct resource bfin_spi0_resource[] = {
252         [0] = {
253                 .start = SPI0_REGBASE,
254                 .end   = SPI0_REGBASE + 0xFF,
255                 .flags = IORESOURCE_MEM,
256         },
257         [1] = {
258                 .start = CH_SPI,
259                 .end   = CH_SPI,
260                 .flags = IORESOURCE_DMA,
261         },
262         [2] = {
263                 .start = IRQ_SPI,
264                 .end   = IRQ_SPI,
265                 .flags = IORESOURCE_IRQ,
266         }
267 };
268
269 /* SPI controller data */
270 static struct bfin5xx_spi_master bfin_spi0_info = {
271         .num_chipselect = 8,
272         .enable_dma = 1,  /* master has the ability to do dma transfer */
273         .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
274 };
275
276 static struct platform_device bfin_spi0_device = {
277         .name = "bfin-spi",
278         .id = 0, /* Bus number */
279         .num_resources = ARRAY_SIZE(bfin_spi0_resource),
280         .resource = bfin_spi0_resource,
281         .dev = {
282                 .platform_data = &bfin_spi0_info, /* Passed to driver */
283         },
284 };
285 #endif  /* spi master and devices */
286
287 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
288 #ifdef CONFIG_SERIAL_BFIN_UART0
289 static struct resource bfin_uart0_resources[] = {
290         {
291                 .start = BFIN_UART_THR,
292                 .end = BFIN_UART_GCTL+2,
293                 .flags = IORESOURCE_MEM,
294         },
295         {
296                 .start = IRQ_UART0_TX,
297                 .end = IRQ_UART0_TX,
298                 .flags = IORESOURCE_IRQ,
299         },
300         {
301                 .start = IRQ_UART0_RX,
302                 .end = IRQ_UART0_RX,
303                 .flags = IORESOURCE_IRQ,
304         },
305         {
306                 .start = IRQ_UART0_ERROR,
307                 .end = IRQ_UART0_ERROR,
308                 .flags = IORESOURCE_IRQ,
309         },
310         {
311                 .start = CH_UART0_TX,
312                 .end = CH_UART0_TX,
313                 .flags = IORESOURCE_DMA,
314         },
315         {
316                 .start = CH_UART0_RX,
317                 .end = CH_UART0_RX,
318                 .flags = IORESOURCE_DMA,
319         },
320 };
321
322 static unsigned short bfin_uart0_peripherals[] = {
323         P_UART0_TX, P_UART0_RX, 0
324 };
325
326 static struct platform_device bfin_uart0_device = {
327         .name = "bfin-uart",
328         .id = 0,
329         .num_resources = ARRAY_SIZE(bfin_uart0_resources),
330         .resource = bfin_uart0_resources,
331         .dev = {
332                 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
333         },
334 };
335 #endif
336 #endif
337
338 #if IS_ENABLED(CONFIG_BFIN_SIR)
339 #ifdef CONFIG_BFIN_SIR0
340 static struct resource bfin_sir0_resources[] = {
341         {
342                 .start = 0xFFC00400,
343                 .end = 0xFFC004FF,
344                 .flags = IORESOURCE_MEM,
345         },
346         {
347                 .start = IRQ_UART0_RX,
348                 .end = IRQ_UART0_RX+1,
349                 .flags = IORESOURCE_IRQ,
350         },
351         {
352                 .start = CH_UART0_RX,
353                 .end = CH_UART0_RX+1,
354                 .flags = IORESOURCE_DMA,
355         },
356 };
357
358 static struct platform_device bfin_sir0_device = {
359         .name = "bfin_sir",
360         .id = 0,
361         .num_resources = ARRAY_SIZE(bfin_sir0_resources),
362         .resource = bfin_sir0_resources,
363 };
364 #endif
365 #endif
366
367 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
368 #include <linux/input.h>
369 #include <linux/gpio_keys.h>
370
371 static struct gpio_keys_button bfin_gpio_keys_table[] = {
372         {BTN_0, GPIO_PF7, 1, "gpio-keys: BTN0"},
373         {BTN_1, GPIO_PF8, 1, "gpio-keys: BTN1"},
374         {BTN_2, GPIO_PF9, 1, "gpio-keys: BTN2"},
375         {BTN_3, GPIO_PF10, 1, "gpio-keys: BTN3"},
376 };
377
378 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
379         .buttons        = bfin_gpio_keys_table,
380         .nbuttons       = ARRAY_SIZE(bfin_gpio_keys_table),
381 };
382
383 static struct platform_device bfin_device_gpiokeys = {
384         .name      = "gpio-keys",
385         .dev = {
386                 .platform_data = &bfin_gpio_keys_data,
387         },
388 };
389 #endif
390
391 #if IS_ENABLED(CONFIG_I2C_GPIO)
392 #include <linux/i2c-gpio.h>
393
394 static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
395         .dev_id = "i2c-gpio",
396         .table = {
397                 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0,
398                                 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
399                 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1,
400                                 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
401         },
402 };
403
404 static struct i2c_gpio_platform_data i2c_gpio_data = {
405         .udelay                 = 40,
406 };
407
408 static struct platform_device i2c_gpio_device = {
409         .name           = "i2c-gpio",
410         .id             = 0,
411         .dev            = {
412                 .platform_data  = &i2c_gpio_data,
413         },
414 };
415 #endif
416
417 static const unsigned int cclk_vlev_datasheet[] =
418 {
419         VRPAIR(VLEV_085, 250000000),
420         VRPAIR(VLEV_090, 376000000),
421         VRPAIR(VLEV_095, 426000000),
422         VRPAIR(VLEV_100, 426000000),
423         VRPAIR(VLEV_105, 476000000),
424         VRPAIR(VLEV_110, 476000000),
425         VRPAIR(VLEV_115, 476000000),
426         VRPAIR(VLEV_120, 600000000),
427         VRPAIR(VLEV_125, 600000000),
428         VRPAIR(VLEV_130, 600000000),
429 };
430
431 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
432         .tuple_tab = cclk_vlev_datasheet,
433         .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
434         .vr_settling_time = 25 /* us */,
435 };
436
437 static struct platform_device bfin_dpmc = {
438         .name = "bfin dpmc",
439         .dev = {
440                 .platform_data = &bfin_dmpc_vreg_data,
441         },
442 };
443
444 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
445 #if IS_ENABLED(CONFIG_FB_BFIN_7393)
446         {
447                 I2C_BOARD_INFO("bfin-adv7393", 0x2B),
448         },
449 #endif
450 };
451
452 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S)
453 static struct platform_device bfin_i2s = {
454         .name = "bfin-i2s",
455         .id = CONFIG_SND_BF5XX_SPORT_NUM,
456         /* TODO: add platform data here */
457 };
458 #endif
459
460 #if IS_ENABLED(CONFIG_SND_BF5XX_AC97)
461 static struct platform_device bfin_ac97 = {
462         .name = "bfin-ac97",
463         .id = CONFIG_SND_BF5XX_SPORT_NUM,
464         /* TODO: add platform data here */
465 };
466 #endif
467
468 static struct platform_device *ezkit_devices[] __initdata = {
469
470         &bfin_dpmc,
471
472 #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
473         &ezkit_flash_device_a,
474         &ezkit_flash_device_b,
475 #endif
476
477 #if IS_ENABLED(CONFIG_MTD_PLATRAM)
478         &sram_device_a,
479         &sram_device_b,
480 #endif
481
482 #if IS_ENABLED(CONFIG_SMC91X)
483         &smc91x_device,
484 #endif
485
486 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
487         &bfin_spi0_device,
488 #endif
489
490 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
491         &rtc_device,
492 #endif
493
494 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
495 #ifdef CONFIG_SERIAL_BFIN_UART0
496         &bfin_uart0_device,
497 #endif
498 #endif
499
500 #if IS_ENABLED(CONFIG_BFIN_SIR)
501 #ifdef CONFIG_BFIN_SIR0
502         &bfin_sir0_device,
503 #endif
504 #endif
505
506 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
507         &bfin_device_gpiokeys,
508 #endif
509
510 #if IS_ENABLED(CONFIG_I2C_GPIO)
511         &i2c_gpio_device,
512 #endif
513
514 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S)
515         &bfin_i2s,
516 #endif
517
518 #if IS_ENABLED(CONFIG_SND_BF5XX_AC97)
519         &bfin_ac97,
520 #endif
521 };
522
523 static int __init ezkit_init(void)
524 {
525         printk(KERN_INFO "%s(): registering device resources\n", __func__);
526 #if IS_ENABLED(CONFIG_I2C_GPIO)
527         gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
528 #endif
529         platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
530         spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
531         i2c_register_board_info(0, bfin_i2c_board_info,
532                                 ARRAY_SIZE(bfin_i2c_board_info));
533         return 0;
534 }
535
536 arch_initcall(ezkit_init);
537
538 static struct platform_device *ezkit_early_devices[] __initdata = {
539 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
540 #ifdef CONFIG_SERIAL_BFIN_UART0
541         &bfin_uart0_device,
542 #endif
543 #endif
544 };
545
546 void __init native_machine_early_platform_add_devices(void)
547 {
548         printk(KERN_INFO "register early platform devices\n");
549         early_platform_add_devices(ezkit_early_devices,
550                 ARRAY_SIZE(ezkit_early_devices));
551 }