2 * linux/arch/arm/mach-sa1100/assabet.c
4 * Author: Nicolas Pitre
6 * This file contains all Assabet-specific tweaks.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/errno.h>
16 #include <linux/gpio/gpio-reg.h>
17 #include <linux/gpio/machine.h>
18 #include <linux/gpio_keys.h>
19 #include <linux/ioport.h>
20 #include <linux/platform_data/sa11x0-serial.h>
21 #include <linux/regulator/fixed.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/serial_core.h>
24 #include <linux/platform_device.h>
25 #include <linux/mfd/ucb1x00.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/delay.h>
30 #include <linux/leds.h>
31 #include <linux/slab.h>
33 #include <video/sa1100fb.h>
35 #include <mach/hardware.h>
36 #include <asm/mach-types.h>
37 #include <asm/setup.h>
39 #include <asm/pgtable-hwdef.h>
40 #include <asm/pgtable.h>
41 #include <asm/tlbflush.h>
43 #include <asm/mach/arch.h>
44 #include <asm/mach/flash.h>
45 #include <linux/platform_data/irda-sa11x0.h>
46 #include <asm/mach/map.h>
47 #include <mach/assabet.h>
48 #include <linux/platform_data/mfd-mcp-sa11x0.h>
49 #include <mach/irqs.h>
53 #define ASSABET_BCR_DB1110 \
54 (ASSABET_BCR_SPK_OFF | \
55 ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \
56 ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \
59 #define ASSABET_BCR_DB1111 \
60 (ASSABET_BCR_SPK_OFF | \
61 ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \
62 ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \
63 ASSABET_BCR_CF_BUS_OFF | ASSABET_BCR_STEREO_LB | \
64 ASSABET_BCR_IRDA_MD0 | ASSABET_BCR_CF_RST)
66 unsigned long SCR_value = ASSABET_SCR_INIT;
67 EXPORT_SYMBOL(SCR_value);
69 static struct gpio_chip *assabet_bcr_gc;
71 static const char *assabet_names[] = {
72 "cf_pwr", "cf_gfx_reset", "nsoft_reset", "irda_fsel",
73 "irda_md0", "irda_md1", "stereo_loopback", "ncf_bus_on",
74 "audio_pwr_on", "light_pwr_on", "lcd16data", "lcd_pwr_on",
75 "rs232_on", "nred_led", "ngreen_led", "vib_on",
76 "com_dtr", "com_rts", "radio_wake_mod", "i2c_enab",
77 "tvir_enab", "qmute", "radio_pwr_on", "spkr_off",
78 "rs232_valid", "com_dcd", "com_cts", "com_dsr",
79 "radio_cts", "radio_dsr", "radio_dcd", "radio_ri",
82 /* The old deprecated interface */
83 void ASSABET_BCR_frob(unsigned int mask, unsigned int val)
85 unsigned long m = mask, v = val;
87 assabet_bcr_gc->set_multiple(assabet_bcr_gc, &m, &v);
89 EXPORT_SYMBOL(ASSABET_BCR_frob);
91 static int __init assabet_init_gpio(void __iomem *reg, u32 def_val)
95 writel_relaxed(def_val, reg);
97 gc = gpio_reg_init(NULL, reg, -1, 32, "assabet", 0xff000000, def_val,
98 assabet_names, NULL, NULL);
109 * The codec reset goes to three devices, so we need to release
110 * the rest when any one of these requests it. However, that
111 * causes the ADV7171 to consume around 100mA - more than half
112 * the LCD-blanked power.
114 * With the ADV7171, LCD and backlight enabled, we go over
115 * budget on the MAX846 Li-Ion charger, and if no Li-Ion battery
116 * is connected, the Assabet crashes.
118 #define RST_UCB1X00 (1 << 0)
119 #define RST_UDA1341 (1 << 1)
120 #define RST_ADV7171 (1 << 2)
122 #define SDA GPIO_GPIO(15)
123 #define SCK GPIO_GPIO(18)
124 #define MOD GPIO_GPIO(17)
126 static void adv7171_start(void)
135 static void adv7171_stop(void)
143 static void adv7171_send(unsigned byte)
147 for (i = 0; i < 8; i++, byte <<= 1) {
166 printk(KERN_WARNING "No ACK from ADV7171\n");
174 static void adv7171_write(unsigned reg, unsigned val)
176 unsigned gpdr = GPDR;
177 unsigned gplr = GPLR;
179 ASSABET_BCR_frob(ASSABET_BCR_AUDIO_ON, ASSABET_BCR_AUDIO_ON);
182 GPCR = SDA | SCK | MOD; /* clear L3 mode to ensure UDA1341 doesn't respond */
183 GPDR = (GPDR | SCK | MOD) & ~SDA;
186 printk(KERN_WARNING "Something dragging SDA down?\n");
195 /* Restore GPIO state for L3 bus */
196 GPSR = gplr & (SDA | SCK | MOD);
197 GPCR = (~gplr) & (SDA | SCK | MOD);
201 static void adv7171_sleep(void)
203 /* Put the ADV7171 into sleep mode */
204 adv7171_write(0x04, 0x40);
207 static unsigned codec_nreset;
209 static void assabet_codec_reset(unsigned mask, int set)
214 local_irq_save(flags);
217 codec_nreset &= ~mask;
219 codec_nreset |= mask;
221 if (old != !codec_nreset) {
223 ASSABET_BCR_set(ASSABET_BCR_NCODEC_RST);
226 ASSABET_BCR_clear(ASSABET_BCR_NCODEC_RST);
229 local_irq_restore(flags);
232 static void assabet_ucb1x00_reset(enum ucb1x00_reset state)
234 int set = state == UCB_RST_REMOVE || state == UCB_RST_SUSPEND ||
235 state == UCB_RST_PROBE_FAIL;
236 assabet_codec_reset(RST_UCB1X00, set);
239 void assabet_uda1341_reset(int set)
241 assabet_codec_reset(RST_UDA1341, set);
243 EXPORT_SYMBOL(assabet_uda1341_reset);
247 * Assabet flash support code.
252 * Phase 4 Assabet has two 28F160B3 flash parts in bank 0:
254 static struct mtd_partition assabet_partitions[] = {
256 .name = "bootloader",
259 .mask_flags = MTD_WRITEABLE,
261 .name = "bootloader params",
263 .offset = MTDPART_OFS_APPEND,
264 .mask_flags = MTD_WRITEABLE,
267 .size = MTDPART_SIZ_FULL,
268 .offset = MTDPART_OFS_APPEND,
273 * Phase 5 Assabet has two 28F128J3A flash parts in bank 0:
275 static struct mtd_partition assabet_partitions[] = {
277 .name = "bootloader",
280 .mask_flags = MTD_WRITEABLE,
282 .name = "bootloader params",
284 .offset = MTDPART_OFS_APPEND,
285 .mask_flags = MTD_WRITEABLE,
288 .size = MTDPART_SIZ_FULL,
289 .offset = MTDPART_OFS_APPEND,
294 static struct flash_platform_data assabet_flash_data = {
295 .map_name = "cfi_probe",
296 .parts = assabet_partitions,
297 .nr_parts = ARRAY_SIZE(assabet_partitions),
300 static struct resource assabet_flash_resources[] = {
301 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M),
302 DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_32M),
307 * Assabet IrDA support code.
310 static int assabet_irda_set_power(struct device *dev, unsigned int state)
312 static unsigned int bcr_state[4] = {
313 ASSABET_BCR_IRDA_MD0,
314 ASSABET_BCR_IRDA_MD1|ASSABET_BCR_IRDA_MD0,
315 ASSABET_BCR_IRDA_MD1,
320 ASSABET_BCR_frob(ASSABET_BCR_IRDA_MD1 | ASSABET_BCR_IRDA_MD0,
325 static void assabet_irda_set_speed(struct device *dev, unsigned int speed)
328 ASSABET_BCR_clear(ASSABET_BCR_IRDA_FSEL);
330 ASSABET_BCR_set(ASSABET_BCR_IRDA_FSEL);
333 static struct irda_platform_data assabet_irda_data = {
334 .set_power = assabet_irda_set_power,
335 .set_speed = assabet_irda_set_speed,
338 static struct ucb1x00_plat_data assabet_ucb1x00_data = {
339 .reset = assabet_ucb1x00_reset,
344 static struct mcp_plat_data assabet_mcp_data = {
346 .sclk_rate = 11981000,
347 .codec_pdata = &assabet_ucb1x00_data,
350 static void assabet_lcd_set_visual(u32 visual)
352 u_int is_true_color = visual == FB_VISUAL_TRUECOLOR;
354 if (machine_is_assabet()) {
355 #if 1 // phase 4 or newer Assabet's
357 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
359 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
363 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
365 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
370 #ifndef ASSABET_PAL_VIDEO
371 static void assabet_lcd_backlight_power(int on)
374 ASSABET_BCR_set(ASSABET_BCR_LIGHT_ON);
376 ASSABET_BCR_clear(ASSABET_BCR_LIGHT_ON);
380 * Turn on/off the backlight. When turning the backlight on, we wait
381 * 500us after turning it on so we don't cause the supplies to droop
382 * when we enable the LCD controller (and cause a hard reset.)
384 static void assabet_lcd_power(int on)
387 ASSABET_BCR_set(ASSABET_BCR_LCD_ON);
390 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
394 * The assabet uses a sharp LQ039Q2DS54 LCD module. It is actually
395 * takes an RGB666 signal, but we provide it with an RGB565 signal
396 * instead (def_rgb_16).
398 static struct sa1100fb_mach_info lq039q2ds54_info = {
399 .pixclock = 171521, .bpp = 16,
400 .xres = 320, .yres = 240,
402 .hsync_len = 5, .vsync_len = 1,
403 .left_margin = 61, .upper_margin = 3,
404 .right_margin = 9, .lower_margin = 0,
406 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
408 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
409 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
411 .backlight_power = assabet_lcd_backlight_power,
412 .lcd_power = assabet_lcd_power,
413 .set_visual = assabet_lcd_set_visual,
416 static void assabet_pal_backlight_power(int on)
418 ASSABET_BCR_clear(ASSABET_BCR_LIGHT_ON);
421 static void assabet_pal_power(int on)
423 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
426 static struct sa1100fb_mach_info pal_info = {
427 .pixclock = 67797, .bpp = 16,
428 .xres = 640, .yres = 512,
430 .hsync_len = 64, .vsync_len = 6,
431 .left_margin = 125, .upper_margin = 70,
432 .right_margin = 115, .lower_margin = 36,
434 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
435 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
437 .backlight_power = assabet_pal_backlight_power,
438 .lcd_power = assabet_pal_power,
439 .set_visual = assabet_lcd_set_visual,
443 #ifdef CONFIG_ASSABET_NEPONSET
444 static struct resource neponset_resources[] = {
445 DEFINE_RES_MEM(0x10000000, 0x08000000),
446 DEFINE_RES_MEM(0x18000000, 0x04000000),
447 DEFINE_RES_MEM(0x40000000, SZ_8K),
448 DEFINE_RES_IRQ(IRQ_GPIO25),
452 static struct gpiod_lookup_table assabet_cf_gpio_table = {
453 .dev_id = "sa11x0-pcmcia.1",
455 GPIO_LOOKUP("gpio", 21, "ready", GPIO_ACTIVE_HIGH),
456 GPIO_LOOKUP("gpio", 22, "detect", GPIO_ACTIVE_LOW),
457 GPIO_LOOKUP("gpio", 24, "bvd2", GPIO_ACTIVE_HIGH),
458 GPIO_LOOKUP("gpio", 25, "bvd1", GPIO_ACTIVE_HIGH),
459 GPIO_LOOKUP("assabet", 1, "reset", GPIO_ACTIVE_HIGH),
460 GPIO_LOOKUP("assabet", 7, "bus-enable", GPIO_ACTIVE_LOW),
465 static struct regulator_consumer_supply assabet_cf_vcc_consumers[] = {
466 REGULATOR_SUPPLY("vcc", "sa11x0-pcmcia.1"),
469 static struct fixed_voltage_config assabet_cf_vcc_pdata __initdata = {
470 .supply_name = "cf-power",
471 .microvolts = 3300000,
474 static struct gpiod_lookup_table assabet_cf_vcc_gpio_table = {
475 .dev_id = "reg-fixed-voltage.0",
477 GPIO_LOOKUP("assabet", 0, NULL, GPIO_ACTIVE_HIGH),
482 static struct gpio_led assabet_leds[] __initdata = {
484 .name = "assabet:red",
485 .default_trigger = "cpu0",
487 .default_state = LEDS_GPIO_DEFSTATE_KEEP,
489 .name = "assabet:green",
490 .default_trigger = "heartbeat",
492 .default_state = LEDS_GPIO_DEFSTATE_KEEP,
496 static const struct gpio_led_platform_data assabet_leds_pdata __initconst = {
497 .num_leds = ARRAY_SIZE(assabet_leds),
498 .leds = assabet_leds,
501 static struct gpio_keys_button assabet_keys_buttons[] = {
508 .debounce_interval = 5,
515 .debounce_interval = 5,
519 static const struct gpio_keys_platform_data assabet_keys_pdata = {
520 .buttons = assabet_keys_buttons,
521 .nbuttons = ARRAY_SIZE(assabet_keys_buttons),
525 static void __init assabet_init(void)
528 * Ensure that the power supply is in "high power" mode.
534 * Ensure that these pins are set as outputs and are driving
535 * logic 0. This ensures that we won't inadvertently toggle
536 * the WS latch in the CPLD, and we don't float causing
537 * excessive power drain. --rmk
539 GPCR = GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
540 GPDR |= GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
543 * Also set GPIO27 as an output; this is used to clock UART3
544 * via the FPGA and as otherwise has no pullups or pulldowns,
545 * so stop it floating.
551 * Set up registers for sleep mode.
557 PPDR |= PPC_TXD3 | PPC_TXD1;
558 PPSR |= PPC_TXD3 | PPC_TXD1;
560 sa11x0_ppc_configure_mcp();
562 if (machine_has_neponset()) {
563 #ifndef CONFIG_ASSABET_NEPONSET
564 printk( "Warning: Neponset detected but full support "
565 "hasn't been configured in the kernel\n" );
567 platform_device_register_simple("neponset", 0,
568 neponset_resources, ARRAY_SIZE(neponset_resources));
571 gpiod_add_lookup_table(&assabet_cf_vcc_gpio_table);
572 sa11x0_register_fixed_regulator(0, &assabet_cf_vcc_pdata,
573 assabet_cf_vcc_consumers,
574 ARRAY_SIZE(assabet_cf_vcc_consumers),
579 platform_device_register_resndata(NULL, "gpio-keys", 0,
582 sizeof(assabet_keys_pdata));
584 gpio_led_register_device(-1, &assabet_leds_pdata);
586 #ifndef ASSABET_PAL_VIDEO
587 sa11x0_register_lcd(&lq039q2ds54_info);
589 sa11x0_register_lcd(&pal_video);
591 sa11x0_register_mtd(&assabet_flash_data, assabet_flash_resources,
592 ARRAY_SIZE(assabet_flash_resources));
593 sa11x0_register_irda(&assabet_irda_data);
594 sa11x0_register_mcp(&assabet_mcp_data);
596 if (!machine_has_neponset())
597 sa11x0_register_pcmcia(1, &assabet_cf_gpio_table);
601 * On Assabet, we must probe for the Neponset board _before_
602 * paging_init() has occurred to actually determine the amount
603 * of RAM available. To do so, we map the appropriate IO section
604 * in the page table here in order to access GPIO registers.
606 static void __init map_sa1100_gpio_regs( void )
608 unsigned long phys = __PREG(GPLR) & PMD_MASK;
609 unsigned long virt = (unsigned long)io_p2v(phys);
610 int prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_DOMAIN(DOMAIN_IO);
613 pmd = pmd_offset(pud_offset(pgd_offset_k(virt), virt), virt);
614 *pmd = __pmd(phys | prot);
615 flush_pmd_entry(pmd);
619 * Read System Configuration "Register"
620 * (taken from "Intel StrongARM SA-1110 Microprocessor Development Board
621 * User's Guide", section 4.4.1)
623 * This same scan is performed in arch/arm/boot/compressed/head-sa1100.S
624 * to set up the serial port for decompression status messages. We
625 * repeat it here because the kernel may not be loaded as a zImage, and
626 * also because it's a hassle to communicate the SCR value to the kernel
627 * from the decompressor.
629 * Note that IRQs are guaranteed to be disabled.
631 static void __init get_assabet_scr(void)
633 unsigned long uninitialized_var(scr), i;
635 GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */
636 GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */
637 GPDR &= ~(0x3fc); /* Configure GPIO 9:2 as inputs */
638 for(i = 100; i--; ) /* Read GPIO 9:2 */
640 GPDR |= 0x3fc; /* restore correct pin direction */
641 scr &= 0x3fc; /* save as system configuration byte. */
646 fixup_assabet(struct tag *tags, char **cmdline)
648 /* This must be done before any call to machine_has_neponset() */
649 map_sa1100_gpio_regs();
652 if (machine_has_neponset())
653 printk("Neponset expansion board detected\n");
657 static void assabet_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
659 if (port->mapbase == _Ser1UTCR0) {
661 ASSABET_BCR_clear(ASSABET_BCR_RS232EN |
662 ASSABET_BCR_COM_RTS |
663 ASSABET_BCR_COM_DTR);
665 ASSABET_BCR_set(ASSABET_BCR_RS232EN |
666 ASSABET_BCR_COM_RTS |
667 ASSABET_BCR_COM_DTR);
672 * Assabet uses COM_RTS and COM_DTR for both UART1 (com port)
673 * and UART3 (radio module). We only handle them for UART1 here.
675 static void assabet_set_mctrl(struct uart_port *port, u_int mctrl)
677 if (port->mapbase == _Ser1UTCR0) {
678 u_int set = 0, clear = 0;
680 if (mctrl & TIOCM_RTS)
681 clear |= ASSABET_BCR_COM_RTS;
683 set |= ASSABET_BCR_COM_RTS;
685 if (mctrl & TIOCM_DTR)
686 clear |= ASSABET_BCR_COM_DTR;
688 set |= ASSABET_BCR_COM_DTR;
690 ASSABET_BCR_clear(clear);
691 ASSABET_BCR_set(set);
695 static u_int assabet_get_mctrl(struct uart_port *port)
698 u_int bsr = ASSABET_BSR;
700 /* need 2 reads to read current value */
703 if (port->mapbase == _Ser1UTCR0) {
704 if (bsr & ASSABET_BSR_COM_DCD)
706 if (bsr & ASSABET_BSR_COM_CTS)
708 if (bsr & ASSABET_BSR_COM_DSR)
710 } else if (port->mapbase == _Ser3UTCR0) {
711 if (bsr & ASSABET_BSR_RAD_DCD)
713 if (bsr & ASSABET_BSR_RAD_CTS)
715 if (bsr & ASSABET_BSR_RAD_DSR)
717 if (bsr & ASSABET_BSR_RAD_RI)
720 ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
726 static struct sa1100_port_fns assabet_port_fns __initdata = {
727 .set_mctrl = assabet_set_mctrl,
728 .get_mctrl = assabet_get_mctrl,
729 .pm = assabet_uart_pm,
732 static struct map_desc assabet_io_desc[] __initdata = {
733 { /* Board Control Register */
734 .virtual = 0xf1000000,
735 .pfn = __phys_to_pfn(0x12000000),
736 .length = 0x00100000,
739 .virtual = 0xf2800000,
740 .pfn = __phys_to_pfn(0x4b800000),
741 .length = 0x00800000,
746 static void __init assabet_map_io(void)
749 iotable_init(assabet_io_desc, ARRAY_SIZE(assabet_io_desc));
752 * Set SUS bit in SDCR0 so serial port 1 functions.
753 * Its called GPCLKR0 in my SA1110 manual.
755 Ser1SDCR0 |= SDCR0_SUS;
756 MSC1 = (MSC1 & ~0xffff) |
757 MSC_NonBrst | MSC_32BitStMem |
758 MSC_RdAcc(2) | MSC_WrAcc(2) | MSC_Rec(0);
760 if (!machine_has_neponset())
761 sa1100_register_uart_fns(&assabet_port_fns);
764 * When Neponset is attached, the first UART should be
765 * UART3. That's what Angel is doing and many documents
768 * We do the Neponset mapping even if Neponset support
769 * isn't compiled in so the user will still get something on
770 * the expected physical serial port.
772 * We no longer do this; not all boot loaders support it,
773 * and UART3 appears to be somewhat unreliable with blob.
775 sa1100_register_uart(0, 1);
776 sa1100_register_uart(2, 3);
779 void __init assabet_init_irq(void)
781 unsigned int assabet_gpio_base;
786 if (machine_has_neponset())
787 def_val = ASSABET_BCR_DB1111;
789 def_val = ASSABET_BCR_DB1110;
792 * Angel sets this, but other bootloaders may not.
794 * This must precede any driver calls to BCR_set() or BCR_clear().
796 assabet_gpio_base = assabet_init_gpio((void *)&ASSABET_BCR, def_val);
798 assabet_leds[0].gpio = assabet_gpio_base + 13;
799 assabet_leds[1].gpio = assabet_gpio_base + 14;
802 MACHINE_START(ASSABET, "Intel-Assabet")
803 .atag_offset = 0x100,
804 .fixup = fixup_assabet,
805 .map_io = assabet_map_io,
806 .nr_irqs = SA1100_NR_IRQS,
807 .init_irq = assabet_init_irq,
808 .init_time = sa1100_timer_init,
809 .init_machine = assabet_init,
810 .init_late = sa11x0_init_late,
812 .dma_zone_size = SZ_1M,
814 .restart = sa11x0_restart,