Merge branch 'for-linus-clk' of git://ftp.arm.linux.org.uk/~rmk/linux-arm
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-pxa / lubbock.c
1 /*
2  *  linux/arch/arm/mach-pxa/lubbock.c
3  *
4  *  Support for the Intel DBPXA250 Development Platform.
5  *
6  *  Author:     Nicolas Pitre
7  *  Created:    Jun 15, 2001
8  *  Copyright:  MontaVista Software Inc.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License version 2 as
12  *  published by the Free Software Foundation.
13  */
14 #include <linux/clkdev.h>
15 #include <linux/gpio.h>
16 #include <linux/gpio/machine.h>
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/io.h>
21 #include <linux/platform_device.h>
22 #include <linux/syscore_ops.h>
23 #include <linux/major.h>
24 #include <linux/fb.h>
25 #include <linux/interrupt.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/smc91x.h>
29 #include <linux/slab.h>
30 #include <linux/leds.h>
31
32 #include <linux/spi/spi.h>
33 #include <linux/spi/ads7846.h>
34 #include <linux/spi/pxa2xx_spi.h>
35
36 #include <asm/setup.h>
37 #include <asm/memory.h>
38 #include <asm/mach-types.h>
39 #include <mach/hardware.h>
40 #include <asm/irq.h>
41 #include <asm/sizes.h>
42
43 #include <asm/mach/arch.h>
44 #include <asm/mach/map.h>
45 #include <asm/mach/irq.h>
46 #include <asm/mach/flash.h>
47
48 #include <asm/hardware/sa1111.h>
49
50 #include <mach/pxa25x.h>
51 #include <mach/audio.h>
52 #include <mach/lubbock.h>
53 #include <mach/udc.h>
54 #include <linux/platform_data/irda-pxaficp.h>
55 #include <linux/platform_data/video-pxafb.h>
56 #include <linux/platform_data/mmc-pxamci.h>
57 #include <mach/pm.h>
58 #include <mach/smemc.h>
59
60 #include "generic.h"
61 #include "clock.h"
62 #include "devices.h"
63
64 static unsigned long lubbock_pin_config[] __initdata = {
65         GPIO15_nCS_1,   /* CS1 - Flash */
66         GPIO78_nCS_2,   /* CS2 - Baseboard FGPA */
67         GPIO79_nCS_3,   /* CS3 - SMC ethernet */
68         GPIO80_nCS_4,   /* CS4 - SA1111 */
69
70         /* SSP data pins */
71         GPIO23_SSP1_SCLK,
72         GPIO25_SSP1_TXD,
73         GPIO26_SSP1_RXD,
74
75         /* AC97 */
76         GPIO28_AC97_BITCLK,
77         GPIO29_AC97_SDATA_IN_0,
78         GPIO30_AC97_SDATA_OUT,
79         GPIO31_AC97_SYNC,
80
81         /* LCD - 16bpp DSTN */
82         GPIOxx_LCD_DSTN_16BPP,
83
84         /* BTUART */
85         GPIO42_BTUART_RXD,
86         GPIO43_BTUART_TXD,
87         GPIO44_BTUART_CTS,
88         GPIO45_BTUART_RTS,
89
90         /* PC Card */
91         GPIO48_nPOE,
92         GPIO49_nPWE,
93         GPIO50_nPIOR,
94         GPIO51_nPIOW,
95         GPIO52_nPCE_1,
96         GPIO53_nPCE_2,
97         GPIO54_nPSKTSEL,
98         GPIO55_nPREG,
99         GPIO56_nPWAIT,
100         GPIO57_nIOIS16,
101
102         /* MMC */
103         GPIO6_MMC_CLK,
104         GPIO8_MMC_CS0,
105
106         /* wakeup */
107         GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,
108 };
109
110 #define LUB_HEXLED              __LUB_REG(LUBBOCK_FPGA_PHYS + 0x010)
111 #define LUB_MISC_WR             __LUB_REG(LUBBOCK_FPGA_PHYS + 0x080)
112
113 void lubbock_set_hexled(uint32_t value)
114 {
115         LUB_HEXLED = value;
116 }
117
118 void lubbock_set_misc_wr(unsigned int mask, unsigned int set)
119 {
120         unsigned long flags;
121
122         local_irq_save(flags);
123         LUB_MISC_WR = (LUB_MISC_WR & ~mask) | (set & mask);
124         local_irq_restore(flags);
125 }
126 EXPORT_SYMBOL(lubbock_set_misc_wr);
127
128 static int lubbock_udc_is_connected(void)
129 {
130         return (LUB_MISC_RD & (1 << 9)) == 0;
131 }
132
133 static struct pxa2xx_udc_mach_info udc_info __initdata = {
134         .udc_is_connected       = lubbock_udc_is_connected,
135         // no D+ pullup; lubbock can't connect/disconnect in software
136 };
137
138 static struct resource sa1111_resources[] = {
139         [0] = {
140                 .start  = 0x10000000,
141                 .end    = 0x10001fff,
142                 .flags  = IORESOURCE_MEM,
143         },
144         [1] = {
145                 .start  = LUBBOCK_SA1111_IRQ,
146                 .end    = LUBBOCK_SA1111_IRQ,
147                 .flags  = IORESOURCE_IRQ,
148         },
149 };
150
151 static struct sa1111_platform_data sa1111_info = {
152         .irq_base       = LUBBOCK_SA1111_IRQ_BASE,
153         .disable_devs   = SA1111_DEVID_SAC,
154 };
155
156 static struct platform_device sa1111_device = {
157         .name           = "sa1111",
158         .id             = -1,
159         .num_resources  = ARRAY_SIZE(sa1111_resources),
160         .resource       = sa1111_resources,
161         .dev            = {
162                 .platform_data  = &sa1111_info,
163         },
164 };
165
166 /* ADS7846 is connected through SSP ... and if your board has J5 populated,
167  * you can select it to replace the ucb1400 by switching the touchscreen cable
168  * (to J5) and poking board registers (as done below).  Else it's only useful
169  * for the temperature sensors.
170  */
171 static struct pxa2xx_spi_master pxa_ssp_master_info = {
172         .num_chipselect = 1,
173 };
174
175 static int lubbock_ads7846_pendown_state(void)
176 {
177         /* TS_BUSY is bit 8 in LUB_MISC_RD, but pendown is irq-only */
178         return 0;
179 }
180
181 static struct ads7846_platform_data ads_info = {
182         .model                  = 7846,
183         .vref_delay_usecs       = 100,          /* internal, no cap */
184         .get_pendown_state      = lubbock_ads7846_pendown_state,
185         // .x_plate_ohms                = 500,  /* GUESS! */
186         // .y_plate_ohms                = 500,  /* GUESS! */
187 };
188
189 static void ads7846_cs(u32 command)
190 {
191         static const unsigned   TS_nCS = 1 << 11;
192         lubbock_set_misc_wr(TS_nCS, (command == PXA2XX_CS_ASSERT) ? 0 : TS_nCS);
193 }
194
195 static struct pxa2xx_spi_chip ads_hw = {
196         .tx_threshold           = 1,
197         .rx_threshold           = 2,
198         .cs_control             = ads7846_cs,
199 };
200
201 static struct spi_board_info spi_board_info[] __initdata = { {
202         .modalias       = "ads7846",
203         .platform_data  = &ads_info,
204         .controller_data = &ads_hw,
205         .irq            = LUBBOCK_BB_IRQ,
206         .max_speed_hz   = 120000 /* max sample rate at 3V */
207                                 * 26 /* command + data + overhead */,
208         .bus_num        = 1,
209         .chip_select    = 0,
210 },
211 };
212
213 static struct resource smc91x_resources[] = {
214         [0] = {
215                 .name   = "smc91x-regs",
216                 .start  = 0x0c000c00,
217                 .end    = 0x0c0fffff,
218                 .flags  = IORESOURCE_MEM,
219         },
220         [1] = {
221                 .start  = LUBBOCK_ETH_IRQ,
222                 .end    = LUBBOCK_ETH_IRQ,
223                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
224         },
225         [2] = {
226                 .name   = "smc91x-attrib",
227                 .start  = 0x0e000000,
228                 .end    = 0x0e0fffff,
229                 .flags  = IORESOURCE_MEM,
230         },
231 };
232
233 static struct smc91x_platdata lubbock_smc91x_info = {
234         .flags  = SMC91X_USE_16BIT | SMC91X_NOWAIT | SMC91X_IO_SHIFT_2,
235 };
236
237 static struct platform_device smc91x_device = {
238         .name           = "smc91x",
239         .id             = -1,
240         .num_resources  = ARRAY_SIZE(smc91x_resources),
241         .resource       = smc91x_resources,
242         .dev            = {
243                 .platform_data = &lubbock_smc91x_info,
244         },
245 };
246
247 static struct resource flash_resources[] = {
248         [0] = {
249                 .start  = 0x00000000,
250                 .end    = SZ_64M - 1,
251                 .flags  = IORESOURCE_MEM,
252         },
253         [1] = {
254                 .start  = 0x04000000,
255                 .end    = 0x04000000 + SZ_64M - 1,
256                 .flags  = IORESOURCE_MEM,
257         },
258 };
259
260 static struct mtd_partition lubbock_partitions[] = {
261         {
262                 .name =         "Bootloader",
263                 .size =         0x00040000,
264                 .offset =       0,
265                 .mask_flags =   MTD_WRITEABLE  /* force read-only */
266         },{
267                 .name =         "Kernel",
268                 .size =         0x00100000,
269                 .offset =       0x00040000,
270         },{
271                 .name =         "Filesystem",
272                 .size =         MTDPART_SIZ_FULL,
273                 .offset =       0x00140000
274         }
275 };
276
277 static struct flash_platform_data lubbock_flash_data[2] = {
278         {
279                 .map_name       = "cfi_probe",
280                 .parts          = lubbock_partitions,
281                 .nr_parts       = ARRAY_SIZE(lubbock_partitions),
282         }, {
283                 .map_name       = "cfi_probe",
284                 .parts          = NULL,
285                 .nr_parts       = 0,
286         }
287 };
288
289 static struct platform_device lubbock_flash_device[2] = {
290         {
291                 .name           = "pxa2xx-flash",
292                 .id             = 0,
293                 .dev = {
294                         .platform_data = &lubbock_flash_data[0],
295                 },
296                 .resource = &flash_resources[0],
297                 .num_resources = 1,
298         },
299         {
300                 .name           = "pxa2xx-flash",
301                 .id             = 1,
302                 .dev = {
303                         .platform_data = &lubbock_flash_data[1],
304                 },
305                 .resource = &flash_resources[1],
306                 .num_resources = 1,
307         },
308 };
309
310 static struct resource lubbock_cplds_resources[] = {
311         [0] = {
312                 .start  = LUBBOCK_FPGA_PHYS + 0xc0,
313                 .end    = LUBBOCK_FPGA_PHYS + 0xe0 - 1,
314                 .flags  = IORESOURCE_MEM,
315         },
316         [1] = {
317                 .start  = PXA_GPIO_TO_IRQ(0),
318                 .end    = PXA_GPIO_TO_IRQ(0),
319                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
320         },
321         [2] = {
322                 .start  = LUBBOCK_IRQ(0),
323                 .end    = LUBBOCK_IRQ(6),
324                 .flags  = IORESOURCE_IRQ,
325         },
326 };
327
328 static struct platform_device lubbock_cplds_device = {
329         .name           = "pxa_cplds_irqs",
330         .id             = -1,
331         .resource       = &lubbock_cplds_resources[0],
332         .num_resources  = 3,
333 };
334
335
336 static struct platform_device *devices[] __initdata = {
337         &sa1111_device,
338         &smc91x_device,
339         &lubbock_flash_device[0],
340         &lubbock_flash_device[1],
341         &lubbock_cplds_device,
342 };
343
344 static struct pxafb_mode_info sharp_lm8v31_mode = {
345         .pixclock       = 270000,
346         .xres           = 640,
347         .yres           = 480,
348         .bpp            = 16,
349         .hsync_len      = 1,
350         .left_margin    = 3,
351         .right_margin   = 3,
352         .vsync_len      = 1,
353         .upper_margin   = 0,
354         .lower_margin   = 0,
355         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
356         .cmap_greyscale = 0,
357 };
358
359 static struct pxafb_mach_info sharp_lm8v31 = {
360         .modes          = &sharp_lm8v31_mode,
361         .num_modes      = 1,
362         .cmap_inverse   = 0,
363         .cmap_static    = 0,
364         .lcd_conn       = LCD_COLOR_DSTN_16BPP | LCD_PCLK_EDGE_FALL |
365                           LCD_AC_BIAS_FREQ(255),
366 };
367
368 #define MMC_POLL_RATE           msecs_to_jiffies(1000)
369
370 static void lubbock_mmc_poll(unsigned long);
371 static irq_handler_t mmc_detect_int;
372
373 static struct timer_list mmc_timer = {
374         .function       = lubbock_mmc_poll,
375 };
376
377 static void lubbock_mmc_poll(unsigned long data)
378 {
379         unsigned long flags;
380
381         /* clear any previous irq state, then ... */
382         local_irq_save(flags);
383         LUB_IRQ_SET_CLR &= ~(1 << 0);
384         local_irq_restore(flags);
385
386         /* poll until mmc/sd card is removed */
387         if (LUB_IRQ_SET_CLR & (1 << 0))
388                 mod_timer(&mmc_timer, jiffies + MMC_POLL_RATE);
389         else {
390                 (void) mmc_detect_int(LUBBOCK_SD_IRQ, (void *)data);
391                 enable_irq(LUBBOCK_SD_IRQ);
392         }
393 }
394
395 static irqreturn_t lubbock_detect_int(int irq, void *data)
396 {
397         /* IRQ is level triggered; disable, and poll for removal */
398         disable_irq(irq);
399         mod_timer(&mmc_timer, jiffies + MMC_POLL_RATE);
400
401         return mmc_detect_int(irq, data);
402 }
403
404 static int lubbock_mci_init(struct device *dev,
405                 irq_handler_t detect_int,
406                 void *data)
407 {
408         /* detect card insert/eject */
409         mmc_detect_int = detect_int;
410         init_timer(&mmc_timer);
411         mmc_timer.data = (unsigned long) data;
412         return request_irq(LUBBOCK_SD_IRQ, lubbock_detect_int,
413                            0, "lubbock-sd-detect", data);
414 }
415
416 static int lubbock_mci_get_ro(struct device *dev)
417 {
418         return (LUB_MISC_RD & (1 << 2)) != 0;
419 }
420
421 static void lubbock_mci_exit(struct device *dev, void *data)
422 {
423         free_irq(LUBBOCK_SD_IRQ, data);
424         del_timer_sync(&mmc_timer);
425 }
426
427 static struct pxamci_platform_data lubbock_mci_platform_data = {
428         .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
429         .detect_delay_ms        = 10,
430         .init                   = lubbock_mci_init,
431         .get_ro                 = lubbock_mci_get_ro,
432         .exit                   = lubbock_mci_exit,
433         .gpio_card_detect       = -1,
434         .gpio_card_ro           = -1,
435         .gpio_power             = -1,
436 };
437
438 static void lubbock_irda_transceiver_mode(struct device *dev, int mode)
439 {
440         unsigned long flags;
441
442         local_irq_save(flags);
443         if (mode & IR_SIRMODE) {
444                 LUB_MISC_WR &= ~(1 << 4);
445         } else if (mode & IR_FIRMODE) {
446                 LUB_MISC_WR |= 1 << 4;
447         }
448         pxa2xx_transceiver_mode(dev, mode);
449         local_irq_restore(flags);
450 }
451
452 static struct pxaficp_platform_data lubbock_ficp_platform_data = {
453         .gpio_pwdown            = -1,
454         .transceiver_cap        = IR_SIRMODE | IR_FIRMODE,
455         .transceiver_mode       = lubbock_irda_transceiver_mode,
456 };
457
458 static void __init lubbock_init(void)
459 {
460         int flashboot = (LUB_CONF_SWITCHES & 1);
461
462         pxa2xx_mfp_config(ARRAY_AND_SIZE(lubbock_pin_config));
463
464         pxa_set_ffuart_info(NULL);
465         pxa_set_btuart_info(NULL);
466         pxa_set_stuart_info(NULL);
467
468         clk_add_alias("SA1111_CLK", NULL, "GPIO11_CLK", NULL);
469         pxa_set_udc_info(&udc_info);
470         pxa_set_fb_info(NULL, &sharp_lm8v31);
471         pxa_set_mci_info(&lubbock_mci_platform_data);
472         pxa_set_ficp_info(&lubbock_ficp_platform_data);
473         pxa_set_ac97_info(NULL);
474
475         lubbock_flash_data[0].width = lubbock_flash_data[1].width =
476                 (__raw_readl(BOOT_DEF) & 1) ? 2 : 4;
477         /* Compensate for the nROMBT switch which swaps the flash banks */
478         printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
479                flashboot?"Flash":"ROM", flashboot);
480
481         lubbock_flash_data[flashboot^1].name = "application-flash";
482         lubbock_flash_data[flashboot].name = "boot-rom";
483         (void) platform_add_devices(devices, ARRAY_SIZE(devices));
484
485         pxa2xx_set_spi_info(1, &pxa_ssp_master_info);
486         spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
487 }
488
489 static struct map_desc lubbock_io_desc[] __initdata = {
490         {       /* CPLD */
491                 .virtual        =  LUBBOCK_FPGA_VIRT,
492                 .pfn            = __phys_to_pfn(LUBBOCK_FPGA_PHYS),
493                 .length         = 0x00100000,
494                 .type           = MT_DEVICE
495         }
496 };
497
498 static void __init lubbock_map_io(void)
499 {
500         pxa25x_map_io();
501         iotable_init(lubbock_io_desc, ARRAY_SIZE(lubbock_io_desc));
502
503         PCFR |= PCFR_OPDE;
504 }
505
506 /*
507  * Driver for the 8 discrete LEDs available for general use:
508  * Note: bits [15-8] are used to enable/blank the 8 7 segment hex displays
509  * so be sure to not monkey with them here.
510  */
511
512 #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
513 struct lubbock_led {
514         struct led_classdev     cdev;
515         u8                      mask;
516 };
517
518 /*
519  * The triggers lines up below will only be used if the
520  * LED triggers are compiled in.
521  */
522 static const struct {
523         const char *name;
524         const char *trigger;
525 } lubbock_leds[] = {
526         { "lubbock:D28", "default-on", },
527         { "lubbock:D27", "cpu0", },
528         { "lubbock:D26", "heartbeat" },
529         { "lubbock:D25", },
530         { "lubbock:D24", },
531         { "lubbock:D23", },
532         { "lubbock:D22", },
533         { "lubbock:D21", },
534 };
535
536 static void lubbock_led_set(struct led_classdev *cdev,
537                               enum led_brightness b)
538 {
539         struct lubbock_led *led = container_of(cdev,
540                                          struct lubbock_led, cdev);
541         u32 reg = LUB_DISC_BLNK_LED;
542
543         if (b != LED_OFF)
544                 reg |= led->mask;
545         else
546                 reg &= ~led->mask;
547
548         LUB_DISC_BLNK_LED = reg;
549 }
550
551 static enum led_brightness lubbock_led_get(struct led_classdev *cdev)
552 {
553         struct lubbock_led *led = container_of(cdev,
554                                          struct lubbock_led, cdev);
555         u32 reg = LUB_DISC_BLNK_LED;
556
557         return (reg & led->mask) ? LED_FULL : LED_OFF;
558 }
559
560 static int __init lubbock_leds_init(void)
561 {
562         int i;
563
564         if (!machine_is_lubbock())
565                 return -ENODEV;
566
567         /* All ON */
568         LUB_DISC_BLNK_LED |= 0xff;
569         for (i = 0; i < ARRAY_SIZE(lubbock_leds); i++) {
570                 struct lubbock_led *led;
571
572                 led = kzalloc(sizeof(*led), GFP_KERNEL);
573                 if (!led)
574                         break;
575
576                 led->cdev.name = lubbock_leds[i].name;
577                 led->cdev.brightness_set = lubbock_led_set;
578                 led->cdev.brightness_get = lubbock_led_get;
579                 led->cdev.default_trigger = lubbock_leds[i].trigger;
580                 led->mask = BIT(i);
581
582                 if (led_classdev_register(NULL, &led->cdev) < 0) {
583                         kfree(led);
584                         break;
585                 }
586         }
587
588         return 0;
589 }
590
591 /*
592  * Since we may have triggers on any subsystem, defer registration
593  * until after subsystem_init.
594  */
595 fs_initcall(lubbock_leds_init);
596 #endif
597
598 MACHINE_START(LUBBOCK, "Intel DBPXA250 Development Platform (aka Lubbock)")
599         /* Maintainer: MontaVista Software Inc. */
600         .map_io         = lubbock_map_io,
601         .nr_irqs        = LUBBOCK_NR_IRQS,
602         .init_irq       = pxa25x_init_irq,
603         .handle_irq     = pxa25x_handle_irq,
604         .init_time      = pxa_timer_init,
605         .init_machine   = lubbock_init,
606         .restart        = pxa_restart,
607 MACHINE_END