Merge tag 'for-v4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux...
[sfrench/cifs-2.6.git] / arch / arm / mach-pxa / raumfeld.c
1 /*
2  * arch/arm/mach-pxa/raumfeld.c
3  *
4  * Support for the following Raumfeld devices:
5  *
6  *      * Controller
7  *      * Connector
8  *      * Speaker S/M
9  *
10  * See http://www.raumfeld.com for details.
11  *
12  * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License version 2 as
16  * published by the Free Software Foundation.
17  */
18
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/property.h>
22 #include <linux/platform_device.h>
23 #include <linux/interrupt.h>
24 #include <linux/gpio.h>
25 #include <linux/gpio/machine.h>
26 #include <linux/smsc911x.h>
27 #include <linux/input.h>
28 #include <linux/gpio_keys.h>
29 #include <linux/leds.h>
30 #include <linux/w1-gpio.h>
31 #include <linux/sched.h>
32 #include <linux/pwm.h>
33 #include <linux/pwm_backlight.h>
34 #include <linux/i2c.h>
35 #include <linux/platform_data/i2c-pxa.h>
36 #include <linux/spi/spi.h>
37 #include <linux/spi/spi_gpio.h>
38 #include <linux/lis3lv02d.h>
39 #include <linux/pda_power.h>
40 #include <linux/power_supply.h>
41 #include <linux/regulator/max8660.h>
42 #include <linux/regulator/machine.h>
43 #include <linux/regulator/fixed.h>
44 #include <linux/regulator/consumer.h>
45 #include <linux/delay.h>
46
47 #include <asm/system_info.h>
48
49 #include <asm/mach-types.h>
50 #include <asm/mach/arch.h>
51
52 #include "pxa300.h"
53 #include <linux/platform_data/usb-ohci-pxa27x.h>
54 #include <linux/platform_data/video-pxafb.h>
55 #include <linux/platform_data/mmc-pxamci.h>
56 #include <linux/platform_data/mtd-nand-pxa3xx.h>
57
58 #include "generic.h"
59 #include "devices.h"
60
61 /* common GPIO  definitions */
62
63 /* inputs */
64 #define GPIO_ON_OFF             (14)
65 #define GPIO_VOLENC_A           (19)
66 #define GPIO_VOLENC_B           (20)
67 #define GPIO_CHARGE_DONE        (23)
68 #define GPIO_CHARGE_IND         (27)
69 #define GPIO_TOUCH_IRQ          (32)
70 #define GPIO_ETH_IRQ            (40)
71 #define GPIO_SPI_MISO           (98)
72 #define GPIO_ACCEL_IRQ          (104)
73 #define GPIO_RESCUE_BOOT        (115)
74 #define GPIO_DOCK_DETECT        (116)
75 #define GPIO_KEY1               (117)
76 #define GPIO_KEY2               (118)
77 #define GPIO_KEY3               (119)
78 #define GPIO_CHARGE_USB_OK      (112)
79 #define GPIO_CHARGE_DC_OK       (101)
80 #define GPIO_CHARGE_USB_SUSP    (102)
81
82 /* outputs */
83 #define GPIO_SHUTDOWN_SUPPLY    (16)
84 #define GPIO_SHUTDOWN_BATT      (18)
85 #define GPIO_CHRG_PEN2          (31)
86 #define GPIO_TFT_VA_EN          (33)
87 #define GPIO_SPDIF_CS           (34)
88 #define GPIO_LED2               (35)
89 #define GPIO_LED1               (36)
90 #define GPIO_SPDIF_RESET        (38)
91 #define GPIO_SPI_CLK            (95)
92 #define GPIO_MCLK_DAC_CS        (96)
93 #define GPIO_SPI_MOSI           (97)
94 #define GPIO_W1_PULLUP_ENABLE   (105)
95 #define GPIO_DISPLAY_ENABLE     (106)
96 #define GPIO_MCLK_RESET         (111)
97 #define GPIO_W2W_RESET          (113)
98 #define GPIO_W2W_PDN            (114)
99 #define GPIO_CODEC_RESET        (120)
100 #define GPIO_AUDIO_VA_ENABLE    (124)
101 #define GPIO_ACCEL_CS           (125)
102 #define GPIO_ONE_WIRE           (126)
103
104 /*
105  * GPIO configurations
106  */
107 static mfp_cfg_t raumfeld_controller_pin_config[] __initdata = {
108         /* UART1 */
109         GPIO77_UART1_RXD,
110         GPIO78_UART1_TXD,
111         GPIO79_UART1_CTS,
112         GPIO81_UART1_DSR,
113         GPIO83_UART1_DTR,
114         GPIO84_UART1_RTS,
115
116         /* UART3 */
117         GPIO110_UART3_RXD,
118
119         /* USB Host */
120         GPIO0_2_USBH_PEN,
121         GPIO1_2_USBH_PWR,
122
123         /* I2C */
124         GPIO21_I2C_SCL | MFP_LPM_FLOAT | MFP_PULL_FLOAT,
125         GPIO22_I2C_SDA | MFP_LPM_FLOAT | MFP_PULL_FLOAT,
126
127         /* SPI */
128         GPIO34_GPIO,    /* SPDIF_CS */
129         GPIO96_GPIO,    /* MCLK_CS */
130         GPIO125_GPIO,   /* ACCEL_CS */
131
132         /* MMC */
133         GPIO3_MMC1_DAT0,
134         GPIO4_MMC1_DAT1,
135         GPIO5_MMC1_DAT2,
136         GPIO6_MMC1_DAT3,
137         GPIO7_MMC1_CLK,
138         GPIO8_MMC1_CMD,
139
140         /* One-wire */
141         GPIO126_GPIO | MFP_LPM_FLOAT,
142         GPIO105_GPIO | MFP_PULL_LOW | MFP_LPM_PULL_LOW,
143
144         /* CHRG_USB_OK */
145         GPIO101_GPIO | MFP_PULL_HIGH,
146         /* CHRG_USB_OK */
147         GPIO112_GPIO | MFP_PULL_HIGH,
148         /* CHRG_USB_SUSP */
149         GPIO102_GPIO,
150         /* DISPLAY_ENABLE */
151         GPIO106_GPIO,
152         /* DOCK_DETECT */
153         GPIO116_GPIO | MFP_LPM_FLOAT | MFP_PULL_FLOAT,
154
155         /* LCD */
156         GPIO54_LCD_LDD_0,
157         GPIO55_LCD_LDD_1,
158         GPIO56_LCD_LDD_2,
159         GPIO57_LCD_LDD_3,
160         GPIO58_LCD_LDD_4,
161         GPIO59_LCD_LDD_5,
162         GPIO60_LCD_LDD_6,
163         GPIO61_LCD_LDD_7,
164         GPIO62_LCD_LDD_8,
165         GPIO63_LCD_LDD_9,
166         GPIO64_LCD_LDD_10,
167         GPIO65_LCD_LDD_11,
168         GPIO66_LCD_LDD_12,
169         GPIO67_LCD_LDD_13,
170         GPIO68_LCD_LDD_14,
171         GPIO69_LCD_LDD_15,
172         GPIO70_LCD_LDD_16,
173         GPIO71_LCD_LDD_17,
174         GPIO72_LCD_FCLK,
175         GPIO73_LCD_LCLK,
176         GPIO74_LCD_PCLK,
177         GPIO75_LCD_BIAS,
178 };
179
180 static mfp_cfg_t raumfeld_connector_pin_config[] __initdata = {
181         /* UART1 */
182         GPIO77_UART1_RXD,
183         GPIO78_UART1_TXD,
184         GPIO79_UART1_CTS,
185         GPIO81_UART1_DSR,
186         GPIO83_UART1_DTR,
187         GPIO84_UART1_RTS,
188
189         /* UART3 */
190         GPIO110_UART3_RXD,
191
192         /* USB Host */
193         GPIO0_2_USBH_PEN,
194         GPIO1_2_USBH_PWR,
195
196         /* I2C */
197         GPIO21_I2C_SCL | MFP_LPM_FLOAT | MFP_PULL_FLOAT,
198         GPIO22_I2C_SDA | MFP_LPM_FLOAT | MFP_PULL_FLOAT,
199
200         /* SPI */
201         GPIO34_GPIO,    /* SPDIF_CS */
202         GPIO96_GPIO,    /* MCLK_CS */
203         GPIO125_GPIO,   /* ACCEL_CS */
204
205         /* MMC */
206         GPIO3_MMC1_DAT0,
207         GPIO4_MMC1_DAT1,
208         GPIO5_MMC1_DAT2,
209         GPIO6_MMC1_DAT3,
210         GPIO7_MMC1_CLK,
211         GPIO8_MMC1_CMD,
212
213         /* Ethernet */
214         GPIO1_nCS2,                     /* CS */
215         GPIO40_GPIO | MFP_PULL_HIGH,    /* IRQ */
216
217         /* SSP for I2S */
218         GPIO85_SSP1_SCLK,
219         GPIO89_SSP1_EXTCLK,
220         GPIO86_SSP1_FRM,
221         GPIO87_SSP1_TXD,
222         GPIO88_SSP1_RXD,
223         GPIO90_SSP1_SYSCLK,
224
225         /* SSP2 for S/PDIF */
226         GPIO25_SSP2_SCLK,
227         GPIO26_SSP2_FRM,
228         GPIO27_SSP2_TXD,
229         GPIO29_SSP2_EXTCLK,
230
231         /* LEDs */
232         GPIO35_GPIO | MFP_LPM_PULL_LOW,
233         GPIO36_GPIO | MFP_LPM_DRIVE_HIGH,
234 };
235
236 static mfp_cfg_t raumfeld_speaker_pin_config[] __initdata = {
237         /* UART1 */
238         GPIO77_UART1_RXD,
239         GPIO78_UART1_TXD,
240         GPIO79_UART1_CTS,
241         GPIO81_UART1_DSR,
242         GPIO83_UART1_DTR,
243         GPIO84_UART1_RTS,
244
245         /* UART3 */
246         GPIO110_UART3_RXD,
247
248         /* USB Host */
249         GPIO0_2_USBH_PEN,
250         GPIO1_2_USBH_PWR,
251
252         /* I2C */
253         GPIO21_I2C_SCL | MFP_LPM_FLOAT | MFP_PULL_FLOAT,
254         GPIO22_I2C_SDA | MFP_LPM_FLOAT | MFP_PULL_FLOAT,
255
256         /* SPI */
257         GPIO34_GPIO,    /* SPDIF_CS */
258         GPIO96_GPIO,    /* MCLK_CS */
259         GPIO125_GPIO,   /* ACCEL_CS */
260
261         /* MMC */
262         GPIO3_MMC1_DAT0,
263         GPIO4_MMC1_DAT1,
264         GPIO5_MMC1_DAT2,
265         GPIO6_MMC1_DAT3,
266         GPIO7_MMC1_CLK,
267         GPIO8_MMC1_CMD,
268
269         /* Ethernet */
270         GPIO1_nCS2,                     /* CS */
271         GPIO40_GPIO | MFP_PULL_HIGH,    /* IRQ */
272
273         /* SSP for I2S */
274         GPIO85_SSP1_SCLK,
275         GPIO89_SSP1_EXTCLK,
276         GPIO86_SSP1_FRM,
277         GPIO87_SSP1_TXD,
278         GPIO88_SSP1_RXD,
279         GPIO90_SSP1_SYSCLK,
280
281         /* LEDs */
282         GPIO35_GPIO | MFP_LPM_PULL_LOW,
283         GPIO36_GPIO | MFP_LPM_DRIVE_HIGH,
284 };
285
286 /*
287  * SMSC LAN9220 Ethernet
288  */
289
290 static struct resource smc91x_resources[] = {
291         {
292                 .start  = PXA3xx_CS2_PHYS,
293                 .end    = PXA3xx_CS2_PHYS + 0xfffff,
294                 .flags  = IORESOURCE_MEM,
295         },
296         {
297                 .start  = PXA_GPIO_TO_IRQ(GPIO_ETH_IRQ),
298                 .end    = PXA_GPIO_TO_IRQ(GPIO_ETH_IRQ),
299                 .flags  = IORESOURCE_IRQ | IRQF_TRIGGER_FALLING,
300         }
301 };
302
303 static struct smsc911x_platform_config raumfeld_smsc911x_config = {
304         .phy_interface  = PHY_INTERFACE_MODE_MII,
305         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
306         .irq_type       = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
307         .flags          = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
308 };
309
310 static struct platform_device smc91x_device = {
311         .name           = "smsc911x",
312         .id             = -1,
313         .num_resources  = ARRAY_SIZE(smc91x_resources),
314         .resource       = smc91x_resources,
315         .dev            = {
316                 .platform_data = &raumfeld_smsc911x_config,
317         }
318 };
319
320 /**
321  * NAND
322  */
323
324 static struct mtd_partition raumfeld_nand_partitions[] = {
325         {
326                 .name           = "Bootloader",
327                 .offset         = 0,
328                 .size           = 0xa0000,
329                 .mask_flags     = MTD_WRITEABLE, /* force read-only */
330         },
331         {
332                 .name           = "BootloaderEnvironment",
333                 .offset         = 0xa0000,
334                 .size           = 0x20000,
335         },
336         {
337                 .name           = "BootloaderSplashScreen",
338                 .offset         = 0xc0000,
339                 .size           = 0x60000,
340         },
341         {
342                 .name           = "UBI",
343                 .offset         = 0x120000,
344                 .size           = MTDPART_SIZ_FULL,
345         },
346 };
347
348 static struct pxa3xx_nand_platform_data raumfeld_nand_info = {
349         .keep_config    = 1,
350         .parts          = raumfeld_nand_partitions,
351         .nr_parts       = ARRAY_SIZE(raumfeld_nand_partitions),
352 };
353
354 /**
355  * USB (OHCI) support
356  */
357
358 static struct pxaohci_platform_data raumfeld_ohci_info = {
359         .port_mode      = PMM_GLOBAL_MODE,
360         .flags          = ENABLE_PORT1,
361 };
362
363 /**
364  * Rotary encoder input device
365  */
366
367 static struct gpiod_lookup_table raumfeld_rotary_gpios_table = {
368         .dev_id = "rotary-encoder.0",
369         .table = {
370                 GPIO_LOOKUP_IDX("gpio-0",
371                                 GPIO_VOLENC_A, NULL, 0, GPIO_ACTIVE_LOW),
372                 GPIO_LOOKUP_IDX("gpio-0",
373                                 GPIO_VOLENC_B, NULL, 1, GPIO_ACTIVE_HIGH),
374                 { },
375         },
376 };
377
378 static const struct property_entry raumfeld_rotary_properties[] __initconst = {
379         PROPERTY_ENTRY_U32("rotary-encoder,steps-per-period", 24),
380         PROPERTY_ENTRY_U32("linux,axis",                      REL_X),
381         PROPERTY_ENTRY_U32("rotary-encoder,relative_axis",    1),
382         { },
383 };
384
385 static struct platform_device rotary_encoder_device = {
386         .name           = "rotary-encoder",
387         .id             = 0,
388 };
389
390 /**
391  * GPIO buttons
392  */
393
394 static struct gpio_keys_button gpio_keys_button[] = {
395         {
396                 .code                   = KEY_F1,
397                 .type                   = EV_KEY,
398                 .gpio                   = GPIO_KEY1,
399                 .active_low             = 1,
400                 .wakeup                 = 0,
401                 .debounce_interval      = 5, /* ms */
402                 .desc                   = "Button 1",
403         },
404         {
405                 .code                   = KEY_F2,
406                 .type                   = EV_KEY,
407                 .gpio                   = GPIO_KEY2,
408                 .active_low             = 1,
409                 .wakeup                 = 0,
410                 .debounce_interval      = 5, /* ms */
411                 .desc                   = "Button 2",
412         },
413         {
414                 .code                   = KEY_F3,
415                 .type                   = EV_KEY,
416                 .gpio                   = GPIO_KEY3,
417                 .active_low             = 1,
418                 .wakeup                 = 0,
419                 .debounce_interval      = 5, /* ms */
420                 .desc                   = "Button 3",
421         },
422         {
423                 .code                   = KEY_F4,
424                 .type                   = EV_KEY,
425                 .gpio                   = GPIO_RESCUE_BOOT,
426                 .active_low             = 0,
427                 .wakeup                 = 0,
428                 .debounce_interval      = 5, /* ms */
429                 .desc                   = "rescue boot button",
430         },
431         {
432                 .code                   = KEY_F5,
433                 .type                   = EV_KEY,
434                 .gpio                   = GPIO_DOCK_DETECT,
435                 .active_low             = 1,
436                 .wakeup                 = 0,
437                 .debounce_interval      = 5, /* ms */
438                 .desc                   = "dock detect",
439         },
440         {
441                 .code                   = KEY_F6,
442                 .type                   = EV_KEY,
443                 .gpio                   = GPIO_ON_OFF,
444                 .active_low             = 0,
445                 .wakeup                 = 0,
446                 .debounce_interval      = 5, /* ms */
447                 .desc                   = "on_off button",
448         },
449 };
450
451 static struct gpio_keys_platform_data gpio_keys_platform_data = {
452         .buttons        = gpio_keys_button,
453         .nbuttons       = ARRAY_SIZE(gpio_keys_button),
454         .rep            = 0,
455 };
456
457 static struct platform_device raumfeld_gpio_keys_device = {
458         .name   = "gpio-keys",
459         .id     = -1,
460         .dev    = {
461                 .platform_data  = &gpio_keys_platform_data,
462         }
463 };
464
465 /**
466  * GPIO LEDs
467  */
468
469 static struct gpio_led raumfeld_leds[] = {
470         {
471                 .name           = "raumfeld:1",
472                 .gpio           = GPIO_LED1,
473                 .active_low     = 1,
474                 .default_state  = LEDS_GPIO_DEFSTATE_ON,
475         },
476         {
477                 .name           = "raumfeld:2",
478                 .gpio           = GPIO_LED2,
479                 .active_low     = 0,
480                 .default_state  = LEDS_GPIO_DEFSTATE_OFF,
481         }
482 };
483
484 static struct gpio_led_platform_data raumfeld_led_platform_data = {
485         .leds           = raumfeld_leds,
486         .num_leds       = ARRAY_SIZE(raumfeld_leds),
487 };
488
489 static struct platform_device raumfeld_led_device = {
490         .name   = "leds-gpio",
491         .id     = -1,
492         .dev    = {
493                 .platform_data = &raumfeld_led_platform_data,
494         },
495 };
496
497 /**
498  * One-wire (W1 bus) support
499  */
500
501 static void w1_enable_external_pullup(int enable)
502 {
503         gpio_set_value(GPIO_W1_PULLUP_ENABLE, enable);
504         msleep(100);
505 }
506
507 static struct gpiod_lookup_table raumfeld_w1_gpiod_table = {
508         .dev_id = "w1-gpio",
509         .table = {
510                 GPIO_LOOKUP_IDX("gpio-pxa", GPIO_ONE_WIRE, NULL, 0,
511                                 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
512         },
513 };
514
515 static struct w1_gpio_platform_data w1_gpio_platform_data = {
516         .enable_external_pullup = w1_enable_external_pullup,
517 };
518
519 static struct platform_device raumfeld_w1_gpio_device = {
520         .name   = "w1-gpio",
521         .dev    = {
522                 .platform_data = &w1_gpio_platform_data
523         }
524 };
525
526 static void __init raumfeld_w1_init(void)
527 {
528         int ret = gpio_request(GPIO_W1_PULLUP_ENABLE,
529                                 "W1 external pullup enable");
530
531         if (ret < 0)
532                 pr_warn("Unable to request GPIO_W1_PULLUP_ENABLE\n");
533         else
534                 gpio_direction_output(GPIO_W1_PULLUP_ENABLE, 0);
535
536         gpiod_add_lookup_table(&raumfeld_w1_gpiod_table);
537         platform_device_register(&raumfeld_w1_gpio_device);
538 }
539
540 /**
541  * Framebuffer device
542  */
543
544 static struct pwm_lookup raumfeld_pwm_lookup[] = {
545         PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight", NULL, 10000,
546                    PWM_POLARITY_NORMAL),
547 };
548
549 /* PWM controlled backlight */
550 static struct platform_pwm_backlight_data raumfeld_pwm_backlight_data = {
551         .max_brightness = 100,
552         .dft_brightness = 100,
553         .enable_gpio    = -1,
554 };
555
556 static struct platform_device raumfeld_pwm_backlight_device = {
557         .name   = "pwm-backlight",
558         .dev    = {
559                 .parent         = &pxa27x_device_pwm0.dev,
560                 .platform_data  = &raumfeld_pwm_backlight_data,
561         }
562 };
563
564 /* LT3593 controlled backlight */
565 static struct gpio_led raumfeld_lt3593_led = {
566         .name           = "backlight",
567         .gpio           = mfp_to_gpio(MFP_PIN_GPIO17),
568         .default_state  = LEDS_GPIO_DEFSTATE_ON,
569 };
570
571 static struct gpio_led_platform_data raumfeld_lt3593_platform_data = {
572         .leds           = &raumfeld_lt3593_led,
573         .num_leds       = 1,
574 };
575
576 static struct platform_device raumfeld_lt3593_device = {
577         .name   = "leds-lt3593",
578         .id     = -1,
579         .dev    = {
580                 .platform_data = &raumfeld_lt3593_platform_data,
581         },
582 };
583
584 static struct pxafb_mode_info sharp_lq043t3dx02_mode = {
585         .pixclock       = 111000,
586         .xres           = 480,
587         .yres           = 272,
588         .bpp            = 16,
589         .hsync_len      = 41,
590         .left_margin    = 2,
591         .right_margin   = 1,
592         .vsync_len      = 10,
593         .upper_margin   = 3,
594         .lower_margin   = 1,
595         .sync           = 0,
596 };
597
598 static struct pxafb_mach_info raumfeld_sharp_lcd_info = {
599         .modes          = &sharp_lq043t3dx02_mode,
600         .num_modes      = 1,
601         .video_mem_size = 0x400000,
602         .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
603 #ifdef CONFIG_PXA3XX_GCU
604         .acceleration_enabled = 1,
605 #endif
606 };
607
608 static void __init raumfeld_lcd_init(void)
609 {
610         int ret;
611
612         ret = gpio_request(GPIO_TFT_VA_EN, "display VA enable");
613         if (ret < 0)
614                 pr_warn("Unable to request GPIO_TFT_VA_EN\n");
615         else
616                 gpio_direction_output(GPIO_TFT_VA_EN, 1);
617
618         msleep(100);
619
620         ret = gpio_request(GPIO_DISPLAY_ENABLE, "display enable");
621         if (ret < 0)
622                 pr_warn("Unable to request GPIO_DISPLAY_ENABLE\n");
623         else
624                 gpio_direction_output(GPIO_DISPLAY_ENABLE, 1);
625
626         /* Hardware revision 2 has the backlight regulator controlled
627          * by an LT3593, earlier and later devices use PWM for that. */
628         if ((system_rev & 0xff) == 2) {
629                 platform_device_register(&raumfeld_lt3593_device);
630         } else {
631                 mfp_cfg_t raumfeld_pwm_pin_config = GPIO17_PWM0_OUT;
632                 pxa3xx_mfp_config(&raumfeld_pwm_pin_config, 1);
633                 pwm_add_table(raumfeld_pwm_lookup,
634                               ARRAY_SIZE(raumfeld_pwm_lookup));
635                 platform_device_register(&raumfeld_pwm_backlight_device);
636         }
637
638         pxa_set_fb_info(NULL, &raumfeld_sharp_lcd_info);
639         platform_device_register(&pxa3xx_device_gcu);
640 }
641
642 /**
643  * SPI devices
644  */
645
646 static struct spi_gpio_platform_data raumfeld_spi_platform_data = {
647         .num_chipselect = 3,
648 };
649
650 static struct platform_device raumfeld_spi_device = {
651         .name   = "spi_gpio",
652         .id     = 0,
653         .dev    = {
654                 .platform_data  = &raumfeld_spi_platform_data,
655         }
656 };
657
658 static struct gpiod_lookup_table raumfeld_spi_gpiod_table = {
659         .dev_id         = "spi_gpio",
660         .table          = {
661                 GPIO_LOOKUP("gpio-0", GPIO_SPI_CLK,
662                             "sck", GPIO_ACTIVE_HIGH),
663                 GPIO_LOOKUP("gpio-0", GPIO_SPI_MOSI,
664                             "mosi", GPIO_ACTIVE_HIGH),
665                 GPIO_LOOKUP("gpio-0", GPIO_SPI_MISO,
666                             "miso", GPIO_ACTIVE_HIGH),
667                 GPIO_LOOKUP_IDX("gpio-0", GPIO_SPDIF_CS,
668                                 "cs", 0, GPIO_ACTIVE_HIGH),
669                 GPIO_LOOKUP_IDX("gpio-0", GPIO_ACCEL_CS,
670                                 "cs", 1, GPIO_ACTIVE_HIGH),
671                 GPIO_LOOKUP_IDX("gpio-0", GPIO_MCLK_DAC_CS,
672                                 "cs", 2, GPIO_ACTIVE_HIGH),
673                 { },
674         },
675 };
676
677 static struct lis3lv02d_platform_data lis3_pdata = {
678         .click_flags    = LIS3_CLICK_SINGLE_X |
679                           LIS3_CLICK_SINGLE_Y |
680                           LIS3_CLICK_SINGLE_Z,
681         .irq_cfg        = LIS3_IRQ1_CLICK | LIS3_IRQ2_CLICK,
682         .wakeup_flags   = LIS3_WAKEUP_X_LO | LIS3_WAKEUP_X_HI |
683                           LIS3_WAKEUP_Y_LO | LIS3_WAKEUP_Y_HI |
684                           LIS3_WAKEUP_Z_LO | LIS3_WAKEUP_Z_HI,
685         .wakeup_thresh  = 10,
686         .click_thresh_x = 10,
687         .click_thresh_y = 10,
688         .click_thresh_z = 10,
689 };
690
691 #define SPI_AK4104      \
692 {                       \
693         .modalias       = "ak4104-codec",       \
694         .max_speed_hz   = 10000,                \
695         .bus_num        = 0,                    \
696         .chip_select    = 0,                    \
697 }
698
699 #define SPI_LIS3        \
700 {                       \
701         .modalias       = "lis3lv02d_spi",      \
702         .max_speed_hz   = 1000000,              \
703         .bus_num        = 0,                    \
704         .chip_select    = 1,                    \
705         .platform_data  = &lis3_pdata,          \
706         .irq            = PXA_GPIO_TO_IRQ(GPIO_ACCEL_IRQ),      \
707 }
708
709 #define SPI_DAC7512     \
710 {       \
711         .modalias       = "dac7512",            \
712         .max_speed_hz   = 1000000,              \
713         .bus_num        = 0,                    \
714         .chip_select    = 2,                    \
715 }
716
717 static struct spi_board_info connector_spi_devices[] __initdata = {
718         SPI_AK4104,
719         SPI_DAC7512,
720 };
721
722 static struct spi_board_info speaker_spi_devices[] __initdata = {
723         SPI_DAC7512,
724 };
725
726 static struct spi_board_info controller_spi_devices[] __initdata = {
727         SPI_LIS3,
728 };
729
730 /**
731  * MMC for Marvell Libertas 8688 via SDIO
732  */
733
734 static int raumfeld_mci_init(struct device *dev, irq_handler_t isr, void *data)
735 {
736         gpio_set_value(GPIO_W2W_RESET, 1);
737         gpio_set_value(GPIO_W2W_PDN, 1);
738
739         return 0;
740 }
741
742 static void raumfeld_mci_exit(struct device *dev, void *data)
743 {
744         gpio_set_value(GPIO_W2W_RESET, 0);
745         gpio_set_value(GPIO_W2W_PDN, 0);
746 }
747
748 static struct pxamci_platform_data raumfeld_mci_platform_data = {
749         .init                   = raumfeld_mci_init,
750         .exit                   = raumfeld_mci_exit,
751         .detect_delay_ms        = 200,
752 };
753
754 /*
755  * External power / charge logic
756  */
757
758 static int power_supply_init(struct device *dev)
759 {
760         return 0;
761 }
762
763 static void power_supply_exit(struct device *dev)
764 {
765 }
766
767 static int raumfeld_is_ac_online(void)
768 {
769         return !gpio_get_value(GPIO_CHARGE_DC_OK);
770 }
771
772 static int raumfeld_is_usb_online(void)
773 {
774         return 0;
775 }
776
777 static char *raumfeld_power_supplicants[] = { "ds2760-battery.0" };
778
779 static void raumfeld_power_signal_charged(void)
780 {
781         struct power_supply *psy =
782                 power_supply_get_by_name(raumfeld_power_supplicants[0]);
783
784         if (psy) {
785                 power_supply_set_battery_charged(psy);
786                 power_supply_put(psy);
787         }
788 }
789
790 static int raumfeld_power_resume(void)
791 {
792         /* check if GPIO_CHARGE_DONE went low while we were sleeping */
793         if (!gpio_get_value(GPIO_CHARGE_DONE))
794                 raumfeld_power_signal_charged();
795
796         return 0;
797 }
798
799 static struct pda_power_pdata power_supply_info = {
800         .init                   = power_supply_init,
801         .is_ac_online           = raumfeld_is_ac_online,
802         .is_usb_online          = raumfeld_is_usb_online,
803         .exit                   = power_supply_exit,
804         .supplied_to            = raumfeld_power_supplicants,
805         .num_supplicants        = ARRAY_SIZE(raumfeld_power_supplicants),
806         .resume                 = raumfeld_power_resume,
807 };
808
809 static struct resource power_supply_resources[] = {
810         {
811                 .name  = "ac",
812                 .flags = IORESOURCE_IRQ |
813                          IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
814                 .start = GPIO_CHARGE_DC_OK,
815                 .end   = GPIO_CHARGE_DC_OK,
816         },
817 };
818
819 static irqreturn_t charge_done_irq(int irq, void *dev_id)
820 {
821         raumfeld_power_signal_charged();
822         return IRQ_HANDLED;
823 }
824
825 static struct platform_device raumfeld_power_supply = {
826         .name = "pda-power",
827         .id   = -1,
828         .dev  = {
829                 .platform_data = &power_supply_info,
830         },
831         .resource      = power_supply_resources,
832         .num_resources = ARRAY_SIZE(power_supply_resources),
833 };
834
835 static void __init raumfeld_power_init(void)
836 {
837         int ret;
838
839         /* Set PEN2 high to enable maximum charge current */
840         ret = gpio_request(GPIO_CHRG_PEN2, "CHRG_PEN2");
841         if (ret < 0)
842                 pr_warn("Unable to request GPIO_CHRG_PEN2\n");
843         else
844                 gpio_direction_output(GPIO_CHRG_PEN2, 1);
845
846         ret = gpio_request(GPIO_CHARGE_DC_OK, "CABLE_DC_OK");
847         if (ret < 0)
848                 pr_warn("Unable to request GPIO_CHARGE_DC_OK\n");
849
850         ret = gpio_request(GPIO_CHARGE_USB_SUSP, "CHARGE_USB_SUSP");
851         if (ret < 0)
852                 pr_warn("Unable to request GPIO_CHARGE_USB_SUSP\n");
853         else
854                 gpio_direction_output(GPIO_CHARGE_USB_SUSP, 0);
855
856         power_supply_resources[0].start = gpio_to_irq(GPIO_CHARGE_DC_OK);
857         power_supply_resources[0].end = gpio_to_irq(GPIO_CHARGE_DC_OK);
858
859         ret = request_irq(gpio_to_irq(GPIO_CHARGE_DONE),
860                         &charge_done_irq, IORESOURCE_IRQ_LOWEDGE,
861                         "charge_done", NULL);
862
863         if (ret < 0)
864                 printk(KERN_ERR "%s: unable to register irq %d\n", __func__,
865                         GPIO_CHARGE_DONE);
866         else
867                 platform_device_register(&raumfeld_power_supply);
868 }
869
870 /* Fixed regulator for AUDIO_VA, 0-0048 maps to the cs4270 codec device */
871
872 static struct regulator_consumer_supply audio_va_consumer_supply =
873         REGULATOR_SUPPLY("va", "0-0048");
874
875 static struct regulator_init_data audio_va_initdata = {
876         .consumer_supplies = &audio_va_consumer_supply,
877         .num_consumer_supplies = 1,
878         .constraints = {
879                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
880         },
881 };
882
883 static struct fixed_voltage_config audio_va_config = {
884         .supply_name            = "audio_va",
885         .microvolts             = 5000000,
886         .enable_high            = 1,
887         .enabled_at_boot        = 0,
888         .init_data              = &audio_va_initdata,
889 };
890
891 static struct platform_device audio_va_device = {
892         .name   = "reg-fixed-voltage",
893         .id     = 0,
894         .dev    = {
895                 .platform_data = &audio_va_config,
896         },
897 };
898
899 static struct gpiod_lookup_table audio_va_gpiod_table = {
900         .dev_id = "reg-fixed-voltage.0",
901         .table = {
902                 GPIO_LOOKUP("gpio-pxa", GPIO_AUDIO_VA_ENABLE,
903                             NULL, GPIO_ACTIVE_HIGH),
904                 { },
905         },
906 };
907
908 /* Dummy supplies for Codec's VD/VLC */
909
910 static struct regulator_consumer_supply audio_dummy_supplies[] = {
911         REGULATOR_SUPPLY("vd", "0-0048"),
912         REGULATOR_SUPPLY("vlc", "0-0048"),
913 };
914
915 static struct regulator_init_data audio_dummy_initdata = {
916         .consumer_supplies = audio_dummy_supplies,
917         .num_consumer_supplies = ARRAY_SIZE(audio_dummy_supplies),
918         .constraints = {
919                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
920         },
921 };
922
923 static struct fixed_voltage_config audio_dummy_config = {
924         .supply_name            = "audio_vd",
925         .microvolts             = 3300000,
926         .init_data              = &audio_dummy_initdata,
927 };
928
929 static struct platform_device audio_supply_dummy_device = {
930         .name   = "reg-fixed-voltage",
931         .id     = 1,
932         .dev    = {
933                 .platform_data = &audio_dummy_config,
934         },
935 };
936
937 static struct platform_device *audio_regulator_devices[] = {
938         &audio_va_device,
939         &audio_supply_dummy_device,
940 };
941
942 /**
943  * Regulator support via MAX8660
944  */
945
946 static struct regulator_consumer_supply vcc_mmc_supply =
947         REGULATOR_SUPPLY("vmmc", "pxa2xx-mci.0");
948
949 static struct regulator_init_data vcc_mmc_init_data = {
950         .constraints = {
951                 .min_uV                 = 3300000,
952                 .max_uV                 = 3300000,
953                 .valid_modes_mask       = REGULATOR_MODE_NORMAL,
954                 .valid_ops_mask         = REGULATOR_CHANGE_STATUS |
955                                           REGULATOR_CHANGE_VOLTAGE |
956                                           REGULATOR_CHANGE_MODE,
957         },
958         .consumer_supplies = &vcc_mmc_supply,
959         .num_consumer_supplies = 1,
960 };
961
962 static struct max8660_subdev_data max8660_v6_subdev_data = {
963         .id             = MAX8660_V6,
964         .name           = "vmmc",
965         .platform_data  = &vcc_mmc_init_data,
966 };
967
968 static struct max8660_platform_data max8660_pdata = {
969         .subdevs = &max8660_v6_subdev_data,
970         .num_subdevs = 1,
971 };
972
973 /**
974  * I2C devices
975  */
976
977 static struct i2c_board_info raumfeld_pwri2c_board_info = {
978         .type           = "max8660",
979         .addr           = 0x34,
980         .platform_data  = &max8660_pdata,
981 };
982
983 static struct i2c_board_info raumfeld_connector_i2c_board_info __initdata = {
984         .type   = "cs4270",
985         .addr   = 0x48,
986 };
987
988 static struct gpiod_lookup_table raumfeld_controller_gpios_table = {
989         .dev_id = "0-000a",
990         .table = {
991                 GPIO_LOOKUP("gpio-pxa",
992                             GPIO_TOUCH_IRQ, "attn", GPIO_ACTIVE_HIGH),
993                 { },
994         },
995 };
996
997 static const struct resource raumfeld_controller_resources[] __initconst = {
998         {
999                 .start  = PXA_GPIO_TO_IRQ(GPIO_TOUCH_IRQ),
1000                 .end    = PXA_GPIO_TO_IRQ(GPIO_TOUCH_IRQ),
1001                 .flags  = IORESOURCE_IRQ | IRQF_TRIGGER_HIGH,
1002         },
1003 };
1004
1005 static struct i2c_board_info raumfeld_controller_i2c_board_info __initdata = {
1006         .type   = "eeti_ts",
1007         .addr   = 0x0a,
1008         .resources = raumfeld_controller_resources,
1009         .num_resources = ARRAY_SIZE(raumfeld_controller_resources),
1010 };
1011
1012 static struct platform_device *raumfeld_common_devices[] = {
1013         &raumfeld_gpio_keys_device,
1014         &raumfeld_led_device,
1015         &raumfeld_spi_device,
1016 };
1017
1018 static void __init raumfeld_audio_init(void)
1019 {
1020         int ret;
1021
1022         ret = gpio_request(GPIO_CODEC_RESET, "cs4270 reset");
1023         if (ret < 0)
1024                 pr_warn("unable to request GPIO_CODEC_RESET\n");
1025         else
1026                 gpio_direction_output(GPIO_CODEC_RESET, 1);
1027
1028         ret = gpio_request(GPIO_SPDIF_RESET, "ak4104 s/pdif reset");
1029         if (ret < 0)
1030                 pr_warn("unable to request GPIO_SPDIF_RESET\n");
1031         else
1032                 gpio_direction_output(GPIO_SPDIF_RESET, 1);
1033
1034         ret = gpio_request(GPIO_MCLK_RESET, "MCLK reset");
1035         if (ret < 0)
1036                 pr_warn("unable to request GPIO_MCLK_RESET\n");
1037         else
1038                 gpio_direction_output(GPIO_MCLK_RESET, 1);
1039
1040         gpiod_add_lookup_table(&audio_va_gpiod_table);
1041         platform_add_devices(ARRAY_AND_SIZE(audio_regulator_devices));
1042 }
1043
1044 static void __init raumfeld_common_init(void)
1045 {
1046         int ret;
1047
1048         /* The on/off button polarity has changed after revision 1 */
1049         if ((system_rev & 0xff) > 1) {
1050                 int i;
1051
1052                 for (i = 0; i < ARRAY_SIZE(gpio_keys_button); i++)
1053                         if (!strcmp(gpio_keys_button[i].desc, "on_off button"))
1054                                 gpio_keys_button[i].active_low = 1;
1055         }
1056
1057         enable_irq_wake(IRQ_WAKEUP0);
1058
1059         pxa3xx_set_nand_info(&raumfeld_nand_info);
1060         pxa3xx_set_i2c_power_info(NULL);
1061         pxa_set_ohci_info(&raumfeld_ohci_info);
1062         pxa_set_mci_info(&raumfeld_mci_platform_data);
1063         pxa_set_i2c_info(NULL);
1064         pxa_set_ffuart_info(NULL);
1065
1066         ret = gpio_request(GPIO_W2W_RESET, "Wi2Wi reset");
1067         if (ret < 0)
1068                 pr_warn("Unable to request GPIO_W2W_RESET\n");
1069         else
1070                 gpio_direction_output(GPIO_W2W_RESET, 0);
1071
1072         ret = gpio_request(GPIO_W2W_PDN, "Wi2Wi powerup");
1073         if (ret < 0)
1074                 pr_warn("Unable to request GPIO_W2W_PDN\n");
1075         else
1076                 gpio_direction_output(GPIO_W2W_PDN, 0);
1077
1078         /* this can be used to switch off the device */
1079         ret = gpio_request(GPIO_SHUTDOWN_SUPPLY, "supply shutdown");
1080         if (ret < 0)
1081                 pr_warn("Unable to request GPIO_SHUTDOWN_SUPPLY\n");
1082         else
1083                 gpio_direction_output(GPIO_SHUTDOWN_SUPPLY, 0);
1084
1085         gpiod_add_lookup_table(&raumfeld_spi_gpiod_table);
1086         platform_add_devices(ARRAY_AND_SIZE(raumfeld_common_devices));
1087         i2c_register_board_info(1, &raumfeld_pwri2c_board_info, 1);
1088 }
1089
1090 static void __init __maybe_unused raumfeld_controller_init(void)
1091 {
1092         int ret;
1093
1094         pxa3xx_mfp_config(ARRAY_AND_SIZE(raumfeld_controller_pin_config));
1095
1096         gpiod_add_lookup_table(&raumfeld_rotary_gpios_table);
1097         device_add_properties(&rotary_encoder_device.dev,
1098                               raumfeld_rotary_properties);
1099         platform_device_register(&rotary_encoder_device);
1100
1101         spi_register_board_info(ARRAY_AND_SIZE(controller_spi_devices));
1102
1103         gpiod_add_lookup_table(&raumfeld_controller_gpios_table);
1104         i2c_register_board_info(0, &raumfeld_controller_i2c_board_info, 1);
1105
1106         ret = gpio_request(GPIO_SHUTDOWN_BATT, "battery shutdown");
1107         if (ret < 0)
1108                 pr_warn("Unable to request GPIO_SHUTDOWN_BATT\n");
1109         else
1110                 gpio_direction_output(GPIO_SHUTDOWN_BATT, 0);
1111
1112         raumfeld_common_init();
1113         raumfeld_power_init();
1114         raumfeld_lcd_init();
1115         raumfeld_w1_init();
1116 }
1117
1118 static void __init __maybe_unused raumfeld_connector_init(void)
1119 {
1120         pxa3xx_mfp_config(ARRAY_AND_SIZE(raumfeld_connector_pin_config));
1121         spi_register_board_info(ARRAY_AND_SIZE(connector_spi_devices));
1122         i2c_register_board_info(0, &raumfeld_connector_i2c_board_info, 1);
1123
1124         platform_device_register(&smc91x_device);
1125
1126         raumfeld_audio_init();
1127         raumfeld_common_init();
1128 }
1129
1130 static void __init __maybe_unused raumfeld_speaker_init(void)
1131 {
1132         pxa3xx_mfp_config(ARRAY_AND_SIZE(raumfeld_speaker_pin_config));
1133         spi_register_board_info(ARRAY_AND_SIZE(speaker_spi_devices));
1134         i2c_register_board_info(0, &raumfeld_connector_i2c_board_info, 1);
1135
1136         platform_device_register(&smc91x_device);
1137
1138         gpiod_add_lookup_table(&raumfeld_rotary_gpios_table);
1139         device_add_properties(&rotary_encoder_device.dev,
1140                               raumfeld_rotary_properties);
1141         platform_device_register(&rotary_encoder_device);
1142
1143         raumfeld_audio_init();
1144         raumfeld_common_init();
1145 }
1146
1147 /* physical memory regions */
1148 #define RAUMFELD_SDRAM_BASE     0xa0000000      /* SDRAM region */
1149
1150 #ifdef CONFIG_MACH_RAUMFELD_RC
1151 MACHINE_START(RAUMFELD_RC, "Raumfeld Controller")
1152         .atag_offset    = 0x100,
1153         .init_machine   = raumfeld_controller_init,
1154         .map_io         = pxa3xx_map_io,
1155         .nr_irqs        = PXA_NR_IRQS,
1156         .init_irq       = pxa3xx_init_irq,
1157         .handle_irq     = pxa3xx_handle_irq,
1158         .init_time      = pxa_timer_init,
1159         .restart        = pxa_restart,
1160 MACHINE_END
1161 #endif
1162
1163 #ifdef CONFIG_MACH_RAUMFELD_CONNECTOR
1164 MACHINE_START(RAUMFELD_CONNECTOR, "Raumfeld Connector")
1165         .atag_offset    = 0x100,
1166         .init_machine   = raumfeld_connector_init,
1167         .map_io         = pxa3xx_map_io,
1168         .nr_irqs        = PXA_NR_IRQS,
1169         .init_irq       = pxa3xx_init_irq,
1170         .handle_irq     = pxa3xx_handle_irq,
1171         .init_time      = pxa_timer_init,
1172         .restart        = pxa_restart,
1173 MACHINE_END
1174 #endif
1175
1176 #ifdef CONFIG_MACH_RAUMFELD_SPEAKER
1177 MACHINE_START(RAUMFELD_SPEAKER, "Raumfeld Speaker")
1178         .atag_offset    = 0x100,
1179         .init_machine   = raumfeld_speaker_init,
1180         .map_io         = pxa3xx_map_io,
1181         .nr_irqs        = PXA_NR_IRQS,
1182         .init_irq       = pxa3xx_init_irq,
1183         .handle_irq     = pxa3xx_handle_irq,
1184         .init_time      = pxa_timer_init,
1185         .restart        = pxa_restart,
1186 MACHINE_END
1187 #endif