]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/arm/mach-pxa/balloon3.c
UBUNTU: Ubuntu-4.15.0-96.97
[mirror_ubuntu-bionic-kernel.git] / arch / arm / mach-pxa / balloon3.c
CommitLineData
2a23ec36
JM
1/*
2 * linux/arch/arm/mach-pxa/balloon3.c
3 *
4 * Support for Balloonboard.org Balloon3 board.
5 *
6 * Author: Nick Bane, Wookey, Jonathan McDowell
7 * Created: June, 2006
8 * Copyright: Toby Churchill Ltd
9 * Derived from mainstone.c, by Nico Pitre
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
61cbaa92 16#include <linux/export.h>
2a23ec36
JM
17#include <linux/init.h>
18#include <linux/platform_device.h>
2a23ec36 19#include <linux/interrupt.h>
40d727a2 20#include <linux/leds.h>
2a23ec36
JM
21#include <linux/sched.h>
22#include <linux/bitops.h>
23#include <linux/fb.h>
24#include <linux/gpio.h>
25#include <linux/ioport.h>
12a2449c 26#include <linux/ucb1400.h>
2a23ec36
JM
27#include <linux/mtd/mtd.h>
28#include <linux/mtd/partitions.h>
29#include <linux/types.h>
b6480fae 30#include <linux/platform_data/pcf857x.h>
b459396e 31#include <linux/i2c/pxa-i2c.h>
d4092d76 32#include <linux/mtd/rawnand.h>
e6a8ef54 33#include <linux/mtd/physmap.h>
3a27f6e0 34#include <linux/regulator/max1586.h>
2a23ec36
JM
35
36#include <asm/setup.h>
37#include <asm/mach-types.h>
38#include <asm/irq.h>
39#include <asm/sizes.h>
40
41#include <asm/mach/arch.h>
42#include <asm/mach/map.h>
43#include <asm/mach/irq.h>
44#include <asm/mach/flash.h>
45
4c25c5d2 46#include "pxa27x.h"
2a23ec36
JM
47#include <mach/balloon3.h>
48#include <mach/audio.h>
293b2da1
AB
49#include <linux/platform_data/video-pxafb.h>
50#include <linux/platform_data/mmc-pxamci.h>
4c25c5d2
AB
51#include "udc.h"
52#include "pxa27x-udc.h"
293b2da1
AB
53#include <linux/platform_data/irda-pxaficp.h>
54#include <linux/platform_data/usb-ohci-pxa27x.h>
2a23ec36 55
2a23ec36
JM
56#include "generic.h"
57#include "devices.h"
58
b0240bf4
MV
59/******************************************************************************
60 * Pin configuration
61 ******************************************************************************/
62static unsigned long balloon3_pin_config[] __initdata = {
63 /* Select BTUART 'COM1/ttyS0' as IO option for pins 42/43/44/45 */
64 GPIO42_BTUART_RXD,
65 GPIO43_BTUART_TXD,
66 GPIO44_BTUART_CTS,
67 GPIO45_BTUART_RTS,
2a23ec36 68
12a2449c 69 /* Reset, configured as GPIO wakeup source */
b0240bf4 70 GPIO1_GPIO | WAKEUP_ON_EDGE_BOTH,
c11b6a42
EM
71};
72
b0240bf4 73/******************************************************************************
12a2449c 74 * Compatibility: Parameter parsing
b0240bf4 75 ******************************************************************************/
12a2449c 76static unsigned long balloon3_irq_enabled;
b0240bf4 77
12a2449c
MV
78static unsigned long balloon3_features_present =
79 (1 << BALLOON3_FEATURE_OHCI) | (1 << BALLOON3_FEATURE_CF) |
80 (1 << BALLOON3_FEATURE_AUDIO) |
81 (1 << BALLOON3_FEATURE_TOPPOLY);
82
83int balloon3_has(enum balloon3_features feature)
2a23ec36 84{
12a2449c
MV
85 return (balloon3_features_present & (1 << feature)) ? 1 : 0;
86}
87EXPORT_SYMBOL_GPL(balloon3_has);
88
89int __init parse_balloon3_features(char *arg)
90{
91 if (!arg)
92 return 0;
93
4fce45b4 94 return kstrtoul(arg, 0, &balloon3_features_present);
2a23ec36 95}
12a2449c 96early_param("balloon3_features", parse_balloon3_features);
2a23ec36 97
b476ef05
MV
98/******************************************************************************
99 * Compact Flash slot
100 ******************************************************************************/
101#if defined(CONFIG_PCMCIA_PXA2XX) || defined(CONFIG_PCMCIA_PXA2XX_MODULE)
102static unsigned long balloon3_cf_pin_config[] __initdata = {
103 GPIO48_nPOE,
104 GPIO49_nPWE,
105 GPIO50_nPIOR,
106 GPIO51_nPIOW,
107 GPIO85_nPCE_1,
108 GPIO54_nPCE_2,
109 GPIO79_PSKTSEL,
110 GPIO55_nPREG,
111 GPIO56_nPWAIT,
112 GPIO57_nIOIS16,
113};
114
115static void __init balloon3_cf_init(void)
116{
117 if (!balloon3_has(BALLOON3_FEATURE_CF))
118 return;
119
120 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_cf_pin_config));
121}
122#else
123static inline void balloon3_cf_init(void) {}
124#endif
125
12a2449c
MV
126/******************************************************************************
127 * NOR Flash
128 ******************************************************************************/
129#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
130static struct mtd_partition balloon3_nor_partitions[] = {
131 {
132 .name = "Flash",
133 .offset = 0x00000000,
134 .size = MTDPART_SIZ_FULL,
135 }
136};
137
138static struct physmap_flash_data balloon3_flash_data[] = {
139 {
140 .width = 2, /* bankwidth in bytes */
141 .parts = balloon3_nor_partitions,
142 .nr_parts = ARRAY_SIZE(balloon3_nor_partitions)
143 }
144};
145
146static struct resource balloon3_flash_resource = {
147 .start = PXA_CS0_PHYS,
148 .end = PXA_CS0_PHYS + SZ_64M - 1,
149 .flags = IORESOURCE_MEM,
150};
151
152static struct platform_device balloon3_flash = {
153 .name = "physmap-flash",
154 .id = 0,
155 .resource = &balloon3_flash_resource,
156 .num_resources = 1,
157 .dev = {
158 .platform_data = balloon3_flash_data,
159 },
160};
161static void __init balloon3_nor_init(void)
162{
163 platform_device_register(&balloon3_flash);
164}
165#else
166static inline void balloon3_nor_init(void) {}
167#endif
168
169/******************************************************************************
170 * Audio and Touchscreen
171 ******************************************************************************/
172#if defined(CONFIG_TOUCHSCREEN_UCB1400) || \
173 defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
b476ef05
MV
174static unsigned long balloon3_ac97_pin_config[] __initdata = {
175 GPIO28_AC97_BITCLK,
176 GPIO29_AC97_SDATA_IN_0,
177 GPIO30_AC97_SDATA_OUT,
178 GPIO31_AC97_SYNC,
179 GPIO113_AC97_nRESET,
180 GPIO95_GPIO,
181};
182
12a2449c 183static struct ucb1400_pdata vpac270_ucb1400_pdata = {
6384fdad 184 .irq = PXA_GPIO_TO_IRQ(BALLOON3_GPIO_CODEC_IRQ),
12a2449c
MV
185};
186
187
188static struct platform_device balloon3_ucb1400_device = {
189 .name = "ucb1400_core",
190 .id = -1,
191 .dev = {
192 .platform_data = &vpac270_ucb1400_pdata,
193 },
194};
195
196static void __init balloon3_ts_init(void)
197{
198 if (!balloon3_has(BALLOON3_FEATURE_AUDIO))
199 return;
200
b476ef05 201 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_ac97_pin_config));
12a2449c
MV
202 pxa_set_ac97_info(NULL);
203 platform_device_register(&balloon3_ucb1400_device);
204}
205#else
206static inline void balloon3_ts_init(void) {}
207#endif
208
209/******************************************************************************
210 * Framebuffer
211 ******************************************************************************/
212#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
b476ef05
MV
213static unsigned long balloon3_lcd_pin_config[] __initdata = {
214 GPIOxx_LCD_TFT_16BPP,
215 GPIO99_GPIO,
216};
217
2a23ec36
JM
218static struct pxafb_mode_info balloon3_lcd_modes[] = {
219 {
220 .pixclock = 38000,
221 .xres = 480,
222 .yres = 640,
223 .bpp = 16,
224 .hsync_len = 8,
225 .left_margin = 8,
226 .right_margin = 8,
227 .vsync_len = 2,
228 .upper_margin = 4,
229 .lower_margin = 5,
230 .sync = 0,
231 },
232};
233
12a2449c 234static struct pxafb_mach_info balloon3_lcd_screen = {
2a23ec36
JM
235 .modes = balloon3_lcd_modes,
236 .num_modes = ARRAY_SIZE(balloon3_lcd_modes),
237 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
2a23ec36
JM
238};
239
12a2449c
MV
240static void balloon3_backlight_power(int on)
241{
242 gpio_set_value(BALLOON3_GPIO_RUN_BACKLIGHT, on);
243}
2a23ec36 244
12a2449c 245static void __init balloon3_lcd_init(void)
2a23ec36 246{
12a2449c
MV
247 int ret;
248
249 if (!balloon3_has(BALLOON3_FEATURE_TOPPOLY))
250 return;
251
b476ef05
MV
252 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_lcd_pin_config));
253
12a2449c
MV
254 ret = gpio_request(BALLOON3_GPIO_RUN_BACKLIGHT, "BKL-ON");
255 if (ret) {
256 pr_err("Requesting BKL-ON GPIO failed!\n");
257 goto err;
258 }
259
260 ret = gpio_direction_output(BALLOON3_GPIO_RUN_BACKLIGHT, 1);
261 if (ret) {
262 pr_err("Setting BKL-ON GPIO direction failed!\n");
263 goto err2;
2a23ec36 264 }
12a2449c
MV
265
266 balloon3_lcd_screen.pxafb_backlight_power = balloon3_backlight_power;
4321e1a1 267 pxa_set_fb_info(NULL, &balloon3_lcd_screen);
12a2449c
MV
268 return;
269
270err2:
271 gpio_free(BALLOON3_GPIO_RUN_BACKLIGHT);
272err:
273 return;
2a23ec36 274}
12a2449c
MV
275#else
276static inline void balloon3_lcd_init(void) {}
277#endif
2a23ec36 278
12a2449c
MV
279/******************************************************************************
280 * SD/MMC card controller
281 ******************************************************************************/
282#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
b476ef05
MV
283static unsigned long balloon3_mmc_pin_config[] __initdata = {
284 GPIO32_MMC_CLK,
285 GPIO92_MMC_DAT_0,
286 GPIO109_MMC_DAT_1,
287 GPIO110_MMC_DAT_2,
288 GPIO111_MMC_DAT_3,
289 GPIO112_MMC_CMD,
290};
291
2a23ec36 292static struct pxamci_platform_data balloon3_mci_platform_data = {
12a2449c
MV
293 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
294 .gpio_card_detect = -1,
295 .gpio_card_ro = -1,
296 .gpio_power = -1,
297 .detect_delay_ms = 200,
2a23ec36
JM
298};
299
12a2449c
MV
300static void __init balloon3_mmc_init(void)
301{
b476ef05 302 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_mmc_pin_config));
12a2449c
MV
303 pxa_set_mci_info(&balloon3_mci_platform_data);
304}
305#else
306static inline void balloon3_mmc_init(void) {}
307#endif
308
b0240bf4
MV
309/******************************************************************************
310 * USB Gadget
311 ******************************************************************************/
c0a39151 312#if defined(CONFIG_USB_PXA27X)||defined(CONFIG_USB_PXA27X_MODULE)
12a2449c 313static void balloon3_udc_command(int cmd)
2a23ec36 314{
12a2449c
MV
315 if (cmd == PXA2XX_UDC_CMD_CONNECT)
316 UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
317 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
318 UP2OCR &= ~UP2OCR_DPPUE;
2a23ec36
JM
319}
320
12a2449c 321static int balloon3_udc_is_connected(void)
2a23ec36 322{
12a2449c 323 return 1;
2a23ec36
JM
324}
325
12a2449c
MV
326static struct pxa2xx_udc_mach_info balloon3_udc_info __initdata = {
327 .udc_command = balloon3_udc_command,
328 .udc_is_connected = balloon3_udc_is_connected,
329 .gpio_pullup = -1,
2a23ec36
JM
330};
331
12a2449c
MV
332static void __init balloon3_udc_init(void)
333{
334 pxa_set_udc_info(&balloon3_udc_info);
12a2449c
MV
335}
336#else
337static inline void balloon3_udc_init(void) {}
338#endif
339
b0240bf4
MV
340/******************************************************************************
341 * IrDA
342 ******************************************************************************/
12a2449c 343#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
2a23ec36 344static struct pxaficp_platform_data balloon3_ficp_platform_data = {
12a2449c 345 .transceiver_cap = IR_FIRMODE | IR_SIRMODE | IR_OFF,
2a23ec36
JM
346};
347
12a2449c
MV
348static void __init balloon3_irda_init(void)
349{
350 pxa_set_ficp_info(&balloon3_ficp_platform_data);
351}
352#else
353static inline void balloon3_irda_init(void) {}
354#endif
355
b0240bf4
MV
356/******************************************************************************
357 * USB Host
358 ******************************************************************************/
12a2449c 359#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
b476ef05
MV
360static unsigned long balloon3_uhc_pin_config[] __initdata = {
361 GPIO88_USBH1_PWR,
362 GPIO89_USBH1_PEN,
363};
364
12a2449c 365static struct pxaohci_platform_data balloon3_ohci_info = {
2a23ec36
JM
366 .port_mode = PMM_PERPORT_MODE,
367 .flags = ENABLE_PORT_ALL | POWER_CONTROL_LOW | POWER_SENSE_LOW,
368};
369
12a2449c
MV
370static void __init balloon3_uhc_init(void)
371{
372 if (!balloon3_has(BALLOON3_FEATURE_OHCI))
373 return;
b476ef05 374 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_uhc_pin_config));
12a2449c
MV
375 pxa_set_ohci_info(&balloon3_ohci_info);
376}
377#else
378static inline void balloon3_uhc_init(void) {}
379#endif
380
b0240bf4 381/******************************************************************************
12a2449c 382 * LEDs
b0240bf4 383 ******************************************************************************/
12a2449c 384#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
b476ef05
MV
385static unsigned long balloon3_led_pin_config[] __initdata = {
386 GPIO9_GPIO, /* NAND activity LED */
387 GPIO10_GPIO, /* Heartbeat LED */
388};
389
12a2449c 390struct gpio_led balloon3_gpio_leds[] = {
2a23ec36
JM
391 {
392 .name = "balloon3:green:idle",
393 .default_trigger = "heartbeat",
394 .gpio = BALLOON3_GPIO_LED_IDLE,
395 .active_low = 1,
12a2449c 396 }, {
2a23ec36
JM
397 .name = "balloon3:green:nand",
398 .default_trigger = "nand-disk",
399 .gpio = BALLOON3_GPIO_LED_NAND,
400 .active_low = 1,
401 },
402};
403
12a2449c 404static struct gpio_led_platform_data balloon3_gpio_led_info = {
2a23ec36
JM
405 .leds = balloon3_gpio_leds,
406 .num_leds = ARRAY_SIZE(balloon3_gpio_leds),
407};
408
12a2449c 409static struct platform_device balloon3_leds = {
2a23ec36 410 .name = "leds-gpio",
02a453e4 411 .id = 0,
2a23ec36 412 .dev = {
12a2449c
MV
413 .platform_data = &balloon3_gpio_led_info,
414 }
2a23ec36
JM
415};
416
02a453e4
MV
417struct gpio_led balloon3_pcf_gpio_leds[] = {
418 {
419 .name = "balloon3:green:led0",
420 .gpio = BALLOON3_PCF_GPIO_LED0,
421 .active_low = 1,
422 }, {
423 .name = "balloon3:green:led1",
424 .gpio = BALLOON3_PCF_GPIO_LED1,
425 .active_low = 1,
426 }, {
427 .name = "balloon3:orange:led2",
428 .gpio = BALLOON3_PCF_GPIO_LED2,
429 .active_low = 1,
430 }, {
431 .name = "balloon3:orange:led3",
432 .gpio = BALLOON3_PCF_GPIO_LED3,
433 .active_low = 1,
434 }, {
435 .name = "balloon3:orange:led4",
436 .gpio = BALLOON3_PCF_GPIO_LED4,
437 .active_low = 1,
438 }, {
439 .name = "balloon3:orange:led5",
440 .gpio = BALLOON3_PCF_GPIO_LED5,
441 .active_low = 1,
442 }, {
443 .name = "balloon3:red:led6",
444 .gpio = BALLOON3_PCF_GPIO_LED6,
445 .active_low = 1,
446 }, {
447 .name = "balloon3:red:led7",
448 .gpio = BALLOON3_PCF_GPIO_LED7,
449 .active_low = 1,
450 },
451};
452
453static struct gpio_led_platform_data balloon3_pcf_gpio_led_info = {
454 .leds = balloon3_pcf_gpio_leds,
455 .num_leds = ARRAY_SIZE(balloon3_pcf_gpio_leds),
456};
457
458static struct platform_device balloon3_pcf_leds = {
459 .name = "leds-gpio",
460 .id = 1,
461 .dev = {
462 .platform_data = &balloon3_pcf_gpio_led_info,
463 }
464};
465
12a2449c 466static void __init balloon3_leds_init(void)
b0240bf4 467{
b476ef05 468 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_led_pin_config));
12a2449c 469 platform_device_register(&balloon3_leds);
02a453e4 470 platform_device_register(&balloon3_pcf_leds);
b0240bf4 471}
12a2449c
MV
472#else
473static inline void balloon3_leds_init(void) {}
474#endif
b0240bf4
MV
475
476/******************************************************************************
477 * FPGA IRQ
478 ******************************************************************************/
a3f4c927 479static void balloon3_mask_irq(struct irq_data *d)
b0240bf4 480{
a3f4c927 481 int balloon3_irq = (d->irq - BALLOON3_IRQ(0));
b0240bf4
MV
482 balloon3_irq_enabled &= ~(1 << balloon3_irq);
483 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
484}
485
a3f4c927 486static void balloon3_unmask_irq(struct irq_data *d)
b0240bf4 487{
a3f4c927 488 int balloon3_irq = (d->irq - BALLOON3_IRQ(0));
b0240bf4
MV
489 balloon3_irq_enabled |= (1 << balloon3_irq);
490 __raw_writel(~balloon3_irq_enabled, BALLOON3_INT_CONTROL_REG);
491}
492
493static struct irq_chip balloon3_irq_chip = {
494 .name = "FPGA",
a3f4c927
LB
495 .irq_ack = balloon3_mask_irq,
496 .irq_mask = balloon3_mask_irq,
497 .irq_unmask = balloon3_unmask_irq,
b0240bf4
MV
498};
499
bd0b9ac4 500static void balloon3_irq_handler(struct irq_desc *desc)
b0240bf4
MV
501{
502 unsigned long pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
503 balloon3_irq_enabled;
b0240bf4 504 do {
9ec97561 505 struct irq_data *d = irq_desc_get_irq_data(desc);
385877c0 506 struct irq_chip *chip = irq_desc_get_chip(desc);
9ec97561 507 unsigned int irq;
a3f4c927 508
9ec97561
TG
509 /* clear useless edge notification */
510 if (chip->irq_ack)
511 chip->irq_ack(d);
a3f4c927 512
b0240bf4
MV
513 while (pending) {
514 irq = BALLOON3_IRQ(0) + __ffs(pending);
515 generic_handle_irq(irq);
516 pending &= pending - 1;
517 }
518 pending = __raw_readl(BALLOON3_INT_CONTROL_REG) &
519 balloon3_irq_enabled;
520 } while (pending);
521}
522
523static void __init balloon3_init_irq(void)
524{
525 int irq;
526
527 pxa27x_init_irq();
528 /* setup extra Balloon3 irqs */
529 for (irq = BALLOON3_IRQ(0); irq <= BALLOON3_IRQ(7); irq++) {
f38c02f3
TG
530 irq_set_chip_and_handler(irq, &balloon3_irq_chip,
531 handle_level_irq);
e8d36d5d 532 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
b0240bf4
MV
533 }
534
6845664a
TG
535 irq_set_chained_handler(BALLOON3_AUX_NIRQ, balloon3_irq_handler);
536 irq_set_irq_type(BALLOON3_AUX_NIRQ, IRQ_TYPE_EDGE_FALLING);
b0240bf4
MV
537
538 pr_debug("%s: chained handler installed - irq %d automatically "
539 "enabled\n", __func__, BALLOON3_AUX_NIRQ);
540}
541
02a453e4
MV
542/******************************************************************************
543 * GPIO expander
544 ******************************************************************************/
545#if defined(CONFIG_GPIO_PCF857X) || defined(CONFIG_GPIO_PCF857X_MODULE)
546static struct pcf857x_platform_data balloon3_pcf857x_pdata = {
547 .gpio_base = BALLOON3_PCF_GPIO_BASE,
548 .n_latch = 0,
549 .setup = NULL,
550 .teardown = NULL,
551 .context = NULL,
552};
553
554static struct i2c_board_info __initdata balloon3_i2c_devs[] = {
555 {
556 I2C_BOARD_INFO("pcf8574a", 0x38),
557 .platform_data = &balloon3_pcf857x_pdata,
558 },
559};
560
561static void __init balloon3_i2c_init(void)
562{
563 pxa_set_i2c_info(NULL);
564 i2c_register_board_info(0, ARRAY_AND_SIZE(balloon3_i2c_devs));
565}
566#else
567static inline void balloon3_i2c_init(void) {}
568#endif
569
e6a8ef54
MV
570/******************************************************************************
571 * NAND
572 ******************************************************************************/
573#if defined(CONFIG_MTD_NAND_PLATFORM)||defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
e6a8ef54
MV
574static void balloon3_nand_cmd_ctl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
575{
c993e095 576 struct nand_chip *this = mtd_to_nand(mtd);
1b9169d8 577 uint8_t balloon3_ctl_set = 0, balloon3_ctl_clr = 0;
e6a8ef54
MV
578
579 if (ctrl & NAND_CTRL_CHANGE) {
580 if (ctrl & NAND_CLE)
1b9169d8 581 balloon3_ctl_set |= BALLOON3_NAND_CONTROL_FLCLE;
e6a8ef54 582 else
1b9169d8 583 balloon3_ctl_clr |= BALLOON3_NAND_CONTROL_FLCLE;
e6a8ef54
MV
584
585 if (ctrl & NAND_ALE)
1b9169d8 586 balloon3_ctl_set |= BALLOON3_NAND_CONTROL_FLALE;
e6a8ef54 587 else
1b9169d8
MV
588 balloon3_ctl_clr |= BALLOON3_NAND_CONTROL_FLALE;
589
590 if (balloon3_ctl_clr)
591 __raw_writel(balloon3_ctl_clr,
592 BALLOON3_NAND_CONTROL_REG);
593 if (balloon3_ctl_set)
594 __raw_writel(balloon3_ctl_set,
97b09da4 595 BALLOON3_NAND_CONTROL_REG +
1b9169d8 596 BALLOON3_FPGA_SETnCLR);
e6a8ef54
MV
597 }
598
599 if (cmd != NAND_CMD_NONE)
600 writeb(cmd, this->IO_ADDR_W);
601}
602
603static void balloon3_nand_select_chip(struct mtd_info *mtd, int chip)
604{
605 if (chip < 0 || chip > 3)
606 return;
607
1b9169d8
MV
608 /* Assert all nCE lines */
609 __raw_writew(
610 BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
611 BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3,
97b09da4 612 BALLOON3_NAND_CONTROL_REG + BALLOON3_FPGA_SETnCLR);
e6a8ef54
MV
613
614 /* Deassert correct nCE line */
1b9169d8
MV
615 __raw_writew(BALLOON3_NAND_CONTROL_FLCE0 << chip,
616 BALLOON3_NAND_CONTROL_REG);
e6a8ef54
MV
617}
618
59bdd133
MV
619static int balloon3_nand_dev_ready(struct mtd_info *mtd)
620{
621 return __raw_readl(BALLOON3_NAND_STAT_REG) & BALLOON3_NAND_STAT_RNB;
622}
623
e6a8ef54
MV
624static int balloon3_nand_probe(struct platform_device *pdev)
625{
e6a8ef54
MV
626 uint16_t ver;
627 int ret;
628
1b9169d8 629 __raw_writew(BALLOON3_NAND_CONTROL2_16BIT,
97b09da4 630 BALLOON3_NAND_CONTROL2_REG + BALLOON3_FPGA_SETnCLR);
e6a8ef54
MV
631
632 ver = __raw_readw(BALLOON3_FPGA_VER);
1b9169d8
MV
633 if (ver < 0x4f08)
634 pr_warn("The FPGA code, version 0x%04x, is too old. "
e6a8ef54
MV
635 "NAND support might be broken in this version!", ver);
636
637 /* Power up the NAND chips */
638 ret = gpio_request(BALLOON3_GPIO_RUN_NAND, "NAND");
639 if (ret)
640 goto err1;
641
642 ret = gpio_direction_output(BALLOON3_GPIO_RUN_NAND, 1);
643 if (ret)
644 goto err2;
645
646 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 1);
647
648 /* Deassert all nCE lines and write protect line */
1b9169d8
MV
649 __raw_writel(
650 BALLOON3_NAND_CONTROL_FLCE0 | BALLOON3_NAND_CONTROL_FLCE1 |
651 BALLOON3_NAND_CONTROL_FLCE2 | BALLOON3_NAND_CONTROL_FLCE3 |
652 BALLOON3_NAND_CONTROL_FLWP,
97b09da4 653 BALLOON3_NAND_CONTROL_REG + BALLOON3_FPGA_SETnCLR);
e6a8ef54
MV
654 return 0;
655
656err2:
657 gpio_free(BALLOON3_GPIO_RUN_NAND);
658err1:
659 return ret;
660}
661
662static void balloon3_nand_remove(struct platform_device *pdev)
663{
664 /* Power down the NAND chips */
665 gpio_set_value(BALLOON3_GPIO_RUN_NAND, 0);
666 gpio_free(BALLOON3_GPIO_RUN_NAND);
667}
668
669static struct mtd_partition balloon3_partition_info[] = {
670 [0] = {
671 .name = "Boot",
672 .offset = 0,
673 .size = SZ_4M,
674 },
675 [1] = {
676 .name = "RootFS",
677 .offset = MTDPART_OFS_APPEND,
678 .size = MTDPART_SIZ_FULL
679 },
680};
681
e6a8ef54
MV
682struct platform_nand_data balloon3_nand_pdata = {
683 .chip = {
684 .nr_chips = 4,
685 .chip_offset = 0,
686 .nr_partitions = ARRAY_SIZE(balloon3_partition_info),
687 .partitions = balloon3_partition_info,
688 .chip_delay = 50,
e6a8ef54
MV
689 },
690 .ctrl = {
691 .hwcontrol = 0,
59bdd133 692 .dev_ready = balloon3_nand_dev_ready,
e6a8ef54
MV
693 .select_chip = balloon3_nand_select_chip,
694 .cmd_ctrl = balloon3_nand_cmd_ctl,
695 .probe = balloon3_nand_probe,
696 .remove = balloon3_nand_remove,
697 },
698};
699
700static struct resource balloon3_nand_resource[] = {
701 [0] = {
702 .start = BALLOON3_NAND_BASE,
703 .end = BALLOON3_NAND_BASE + 0x4,
704 .flags = IORESOURCE_MEM,
705 },
706};
707
708static struct platform_device balloon3_nand = {
709 .name = "gen_nand",
710 .num_resources = ARRAY_SIZE(balloon3_nand_resource),
711 .resource = balloon3_nand_resource,
712 .id = -1,
713 .dev = {
714 .platform_data = &balloon3_nand_pdata,
715 }
716};
717
718static void __init balloon3_nand_init(void)
719{
720 platform_device_register(&balloon3_nand);
721}
722#else
723static inline void balloon3_nand_init(void) {}
724#endif
725
3a27f6e0
MV
726/******************************************************************************
727 * Core power regulator
728 ******************************************************************************/
729#if defined(CONFIG_REGULATOR_MAX1586) || \
730 defined(CONFIG_REGULATOR_MAX1586_MODULE)
731static struct regulator_consumer_supply balloon3_max1587a_consumers[] = {
0bf189ab 732 REGULATOR_SUPPLY("vcc_core", NULL),
3a27f6e0
MV
733};
734
735static struct regulator_init_data balloon3_max1587a_v3_info = {
736 .constraints = {
737 .name = "vcc_core range",
738 .min_uV = 900000,
739 .max_uV = 1705000,
740 .always_on = 1,
741 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
742 },
743 .consumer_supplies = balloon3_max1587a_consumers,
744 .num_consumer_supplies = ARRAY_SIZE(balloon3_max1587a_consumers),
745};
746
747static struct max1586_subdev_data balloon3_max1587a_subdevs[] = {
748 {
749 .name = "vcc_core",
750 .id = MAX1586_V3,
751 .platform_data = &balloon3_max1587a_v3_info,
752 }
753};
754
755static struct max1586_platform_data balloon3_max1587a_info = {
756 .subdevs = balloon3_max1587a_subdevs,
757 .num_subdevs = ARRAY_SIZE(balloon3_max1587a_subdevs),
758 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
759};
760
761static struct i2c_board_info __initdata balloon3_pi2c_board_info[] = {
762 {
763 I2C_BOARD_INFO("max1586", 0x14),
764 .platform_data = &balloon3_max1587a_info,
765 },
766};
767
768static void __init balloon3_pmic_init(void)
769{
770 pxa27x_set_i2c_power_info(NULL);
771 i2c_register_board_info(1, ARRAY_AND_SIZE(balloon3_pi2c_board_info));
772}
773#else
774static inline void balloon3_pmic_init(void) {}
775#endif
776
b0240bf4
MV
777/******************************************************************************
778 * Machine init
779 ******************************************************************************/
2a23ec36
JM
780static void __init balloon3_init(void)
781{
2a23ec36
JM
782 ARB_CNTRL = ARB_CORE_PARK | 0x234;
783
12a2449c
MV
784 pxa2xx_mfp_config(ARRAY_AND_SIZE(balloon3_pin_config));
785
cc155c6f
RK
786 pxa_set_ffuart_info(NULL);
787 pxa_set_btuart_info(NULL);
788 pxa_set_stuart_info(NULL);
789
02a453e4 790 balloon3_i2c_init();
12a2449c
MV
791 balloon3_irda_init();
792 balloon3_lcd_init();
793 balloon3_leds_init();
794 balloon3_mmc_init();
e6a8ef54 795 balloon3_nand_init();
12a2449c 796 balloon3_nor_init();
3a27f6e0 797 balloon3_pmic_init();
12a2449c
MV
798 balloon3_ts_init();
799 balloon3_udc_init();
800 balloon3_uhc_init();
b476ef05 801 balloon3_cf_init();
2a23ec36
JM
802}
803
804static struct map_desc balloon3_io_desc[] __initdata = {
805 { /* CPLD/FPGA */
97b09da4 806 .virtual = (unsigned long)BALLOON3_FPGA_VIRT,
2a23ec36
JM
807 .pfn = __phys_to_pfn(BALLOON3_FPGA_PHYS),
808 .length = BALLOON3_FPGA_LENGTH,
809 .type = MT_DEVICE,
810 },
811};
812
813static void __init balloon3_map_io(void)
814{
851982c1 815 pxa27x_map_io();
2a23ec36
JM
816 iotable_init(balloon3_io_desc, ARRAY_SIZE(balloon3_io_desc));
817}
818
819MACHINE_START(BALLOON3, "Balloon3")
820 /* Maintainer: Nick Bane. */
2a23ec36 821 .map_io = balloon3_map_io,
6ac6b817 822 .nr_irqs = BALLOON3_NR_IRQS,
2a23ec36 823 .init_irq = balloon3_init_irq,
8a97ae2f 824 .handle_irq = pxa27x_handle_irq,
6bb27d73 825 .init_time = pxa_timer_init,
2a23ec36 826 .init_machine = balloon3_init,
7375aba6 827 .atag_offset = 0x100,
271a74fc 828 .restart = pxa_restart,
2a23ec36 829MACHINE_END