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