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/ioport.h>
19 #include <linux/platform_data/sa11x0-serial.h>
20 #include <linux/regulator/fixed.h>
21 #include <linux/regulator/machine.h>
22 #include <linux/serial_core.h>
23 #include <linux/platform_device.h>
24 #include <linux/mfd/ucb1x00.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/partitions.h>
27 #include <linux/delay.h>
29 #include <linux/leds.h>
30 #include <linux/slab.h>
32 #include <video/sa1100fb.h>
34 #include <mach/hardware.h>
35 #include <asm/mach-types.h>
36 #include <asm/setup.h>
38 #include <asm/pgtable-hwdef.h>
39 #include <asm/pgtable.h>
40 #include <asm/tlbflush.h>
42 #include <asm/mach/arch.h>
43 #include <asm/mach/flash.h>
44 #include <linux/platform_data/irda-sa11x0.h>
45 #include <asm/mach/map.h>
46 #include <mach/assabet.h>
47 #include <linux/platform_data/mfd-mcp-sa11x0.h>
48 #include <mach/irqs.h>
52 #define ASSABET_BCR_DB1110 \
53 (ASSABET_BCR_SPK_OFF | \
54 ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \
55 ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \
58 #define ASSABET_BCR_DB1111 \
59 (ASSABET_BCR_SPK_OFF | \
60 ASSABET_BCR_LED_GREEN | ASSABET_BCR_LED_RED | \
61 ASSABET_BCR_RS232EN | ASSABET_BCR_LCD_12RGB | \
62 ASSABET_BCR_CF_BUS_OFF | ASSABET_BCR_STEREO_LB | \
63 ASSABET_BCR_IRDA_MD0 | ASSABET_BCR_CF_RST)
65 unsigned long SCR_value = ASSABET_SCR_INIT;
66 EXPORT_SYMBOL(SCR_value);
68 static struct gpio_chip *assabet_bcr_gc;
70 static const char *assabet_names[] = {
71 "cf_pwr", "cf_gfx_reset", "nsoft_reset", "irda_fsel",
72 "irda_md0", "irda_md1", "stereo_loopback", "ncf_bus_on",
73 "audio_pwr_on", "light_pwr_on", "lcd16data", "lcd_pwr_on",
74 "rs232_on", "nred_led", "ngreen_led", "vib_on",
75 "com_dtr", "com_rts", "radio_wake_mod", "i2c_enab",
76 "tvir_enab", "qmute", "radio_pwr_on", "spkr_off",
77 "rs232_valid", "com_dcd", "com_cts", "com_dsr",
78 "radio_cts", "radio_dsr", "radio_dcd", "radio_ri",
81 /* The old deprecated interface */
82 void ASSABET_BCR_frob(unsigned int mask, unsigned int val)
84 unsigned long m = mask, v = val;
86 assabet_bcr_gc->set_multiple(assabet_bcr_gc, &m, &v);
88 EXPORT_SYMBOL(ASSABET_BCR_frob);
90 static int __init assabet_init_gpio(void __iomem *reg, u32 def_val)
94 writel_relaxed(def_val, reg);
96 gc = gpio_reg_init(NULL, reg, -1, 32, "assabet", 0xff000000, def_val,
97 assabet_names, NULL, NULL);
108 * The codec reset goes to three devices, so we need to release
109 * the rest when any one of these requests it. However, that
110 * causes the ADV7171 to consume around 100mA - more than half
111 * the LCD-blanked power.
113 * With the ADV7171, LCD and backlight enabled, we go over
114 * budget on the MAX846 Li-Ion charger, and if no Li-Ion battery
115 * is connected, the Assabet crashes.
117 #define RST_UCB1X00 (1 << 0)
118 #define RST_UDA1341 (1 << 1)
119 #define RST_ADV7171 (1 << 2)
121 #define SDA GPIO_GPIO(15)
122 #define SCK GPIO_GPIO(18)
123 #define MOD GPIO_GPIO(17)
125 static void adv7171_start(void)
134 static void adv7171_stop(void)
142 static void adv7171_send(unsigned byte)
146 for (i = 0; i < 8; i++, byte <<= 1) {
165 printk(KERN_WARNING "No ACK from ADV7171\n");
173 static void adv7171_write(unsigned reg, unsigned val)
175 unsigned gpdr = GPDR;
176 unsigned gplr = GPLR;
178 ASSABET_BCR_frob(ASSABET_BCR_AUDIO_ON, ASSABET_BCR_AUDIO_ON);
181 GPCR = SDA | SCK | MOD; /* clear L3 mode to ensure UDA1341 doesn't respond */
182 GPDR = (GPDR | SCK | MOD) & ~SDA;
185 printk(KERN_WARNING "Something dragging SDA down?\n");
194 /* Restore GPIO state for L3 bus */
195 GPSR = gplr & (SDA | SCK | MOD);
196 GPCR = (~gplr) & (SDA | SCK | MOD);
200 static void adv7171_sleep(void)
202 /* Put the ADV7171 into sleep mode */
203 adv7171_write(0x04, 0x40);
206 static unsigned codec_nreset;
208 static void assabet_codec_reset(unsigned mask, int set)
213 local_irq_save(flags);
216 codec_nreset &= ~mask;
218 codec_nreset |= mask;
220 if (old != !codec_nreset) {
222 ASSABET_BCR_set(ASSABET_BCR_NCODEC_RST);
225 ASSABET_BCR_clear(ASSABET_BCR_NCODEC_RST);
228 local_irq_restore(flags);
231 static void assabet_ucb1x00_reset(enum ucb1x00_reset state)
233 int set = state == UCB_RST_REMOVE || state == UCB_RST_SUSPEND ||
234 state == UCB_RST_PROBE_FAIL;
235 assabet_codec_reset(RST_UCB1X00, set);
238 void assabet_uda1341_reset(int set)
240 assabet_codec_reset(RST_UDA1341, set);
242 EXPORT_SYMBOL(assabet_uda1341_reset);
246 * Assabet flash support code.
251 * Phase 4 Assabet has two 28F160B3 flash parts in bank 0:
253 static struct mtd_partition assabet_partitions[] = {
255 .name = "bootloader",
258 .mask_flags = MTD_WRITEABLE,
260 .name = "bootloader params",
262 .offset = MTDPART_OFS_APPEND,
263 .mask_flags = MTD_WRITEABLE,
266 .size = MTDPART_SIZ_FULL,
267 .offset = MTDPART_OFS_APPEND,
272 * Phase 5 Assabet has two 28F128J3A flash parts in bank 0:
274 static struct mtd_partition assabet_partitions[] = {
276 .name = "bootloader",
279 .mask_flags = MTD_WRITEABLE,
281 .name = "bootloader params",
283 .offset = MTDPART_OFS_APPEND,
284 .mask_flags = MTD_WRITEABLE,
287 .size = MTDPART_SIZ_FULL,
288 .offset = MTDPART_OFS_APPEND,
293 static struct flash_platform_data assabet_flash_data = {
294 .map_name = "cfi_probe",
295 .parts = assabet_partitions,
296 .nr_parts = ARRAY_SIZE(assabet_partitions),
299 static struct resource assabet_flash_resources[] = {
300 DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M),
301 DEFINE_RES_MEM(SA1100_CS1_PHYS, SZ_32M),
306 * Assabet IrDA support code.
309 static int assabet_irda_set_power(struct device *dev, unsigned int state)
311 static unsigned int bcr_state[4] = {
312 ASSABET_BCR_IRDA_MD0,
313 ASSABET_BCR_IRDA_MD1|ASSABET_BCR_IRDA_MD0,
314 ASSABET_BCR_IRDA_MD1,
319 ASSABET_BCR_frob(ASSABET_BCR_IRDA_MD1 | ASSABET_BCR_IRDA_MD0,
324 static void assabet_irda_set_speed(struct device *dev, unsigned int speed)
327 ASSABET_BCR_clear(ASSABET_BCR_IRDA_FSEL);
329 ASSABET_BCR_set(ASSABET_BCR_IRDA_FSEL);
332 static struct irda_platform_data assabet_irda_data = {
333 .set_power = assabet_irda_set_power,
334 .set_speed = assabet_irda_set_speed,
337 static struct ucb1x00_plat_data assabet_ucb1x00_data = {
338 .reset = assabet_ucb1x00_reset,
343 static struct mcp_plat_data assabet_mcp_data = {
345 .sclk_rate = 11981000,
346 .codec_pdata = &assabet_ucb1x00_data,
349 static void assabet_lcd_set_visual(u32 visual)
351 u_int is_true_color = visual == FB_VISUAL_TRUECOLOR;
353 if (machine_is_assabet()) {
354 #if 1 // phase 4 or newer Assabet's
356 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
358 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
362 ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
364 ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
369 #ifndef ASSABET_PAL_VIDEO
370 static void assabet_lcd_backlight_power(int on)
373 ASSABET_BCR_set(ASSABET_BCR_LIGHT_ON);
375 ASSABET_BCR_clear(ASSABET_BCR_LIGHT_ON);
379 * Turn on/off the backlight. When turning the backlight on, we wait
380 * 500us after turning it on so we don't cause the supplies to droop
381 * when we enable the LCD controller (and cause a hard reset.)
383 static void assabet_lcd_power(int on)
386 ASSABET_BCR_set(ASSABET_BCR_LCD_ON);
389 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
393 * The assabet uses a sharp LQ039Q2DS54 LCD module. It is actually
394 * takes an RGB666 signal, but we provide it with an RGB565 signal
395 * instead (def_rgb_16).
397 static struct sa1100fb_mach_info lq039q2ds54_info = {
398 .pixclock = 171521, .bpp = 16,
399 .xres = 320, .yres = 240,
401 .hsync_len = 5, .vsync_len = 1,
402 .left_margin = 61, .upper_margin = 3,
403 .right_margin = 9, .lower_margin = 0,
405 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
407 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
408 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
410 .backlight_power = assabet_lcd_backlight_power,
411 .lcd_power = assabet_lcd_power,
412 .set_visual = assabet_lcd_set_visual,
415 static void assabet_pal_backlight_power(int on)
417 ASSABET_BCR_clear(ASSABET_BCR_LIGHT_ON);
420 static void assabet_pal_power(int on)
422 ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
425 static struct sa1100fb_mach_info pal_info = {
426 .pixclock = 67797, .bpp = 16,
427 .xres = 640, .yres = 512,
429 .hsync_len = 64, .vsync_len = 6,
430 .left_margin = 125, .upper_margin = 70,
431 .right_margin = 115, .lower_margin = 36,
433 .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
434 .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
436 .backlight_power = assabet_pal_backlight_power,
437 .lcd_power = assabet_pal_power,
438 .set_visual = assabet_lcd_set_visual,
442 #ifdef CONFIG_ASSABET_NEPONSET
443 static struct resource neponset_resources[] = {
444 DEFINE_RES_MEM(0x10000000, 0x08000000),
445 DEFINE_RES_MEM(0x18000000, 0x04000000),
446 DEFINE_RES_MEM(0x40000000, SZ_8K),
447 DEFINE_RES_IRQ(IRQ_GPIO25),
451 static struct gpiod_lookup_table assabet_cf_gpio_table = {
452 .dev_id = "sa11x0-pcmcia.1",
454 GPIO_LOOKUP("gpio", 21, "ready", GPIO_ACTIVE_HIGH),
455 GPIO_LOOKUP("gpio", 22, "detect", GPIO_ACTIVE_LOW),
456 GPIO_LOOKUP("gpio", 24, "bvd2", GPIO_ACTIVE_HIGH),
457 GPIO_LOOKUP("gpio", 25, "bvd1", GPIO_ACTIVE_HIGH),
458 GPIO_LOOKUP("assabet", 1, "reset", GPIO_ACTIVE_HIGH),
459 GPIO_LOOKUP("assabet", 7, "bus-enable", GPIO_ACTIVE_LOW),
464 static struct regulator_consumer_supply assabet_cf_vcc_consumers[] = {
465 REGULATOR_SUPPLY("vcc", "sa11x0-pcmcia.1"),
468 static struct fixed_voltage_config assabet_cf_vcc_pdata __initdata = {
469 .supply_name = "cf-power",
470 .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 void __init assabet_init(void)
485 * Ensure that the power supply is in "high power" mode.
491 * Ensure that these pins are set as outputs and are driving
492 * logic 0. This ensures that we won't inadvertently toggle
493 * the WS latch in the CPLD, and we don't float causing
494 * excessive power drain. --rmk
496 GPCR = GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
497 GPDR |= GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM;
500 * Also set GPIO27 as an output; this is used to clock UART3
501 * via the FPGA and as otherwise has no pullups or pulldowns,
502 * so stop it floating.
508 * Set up registers for sleep mode.
514 PPDR |= PPC_TXD3 | PPC_TXD1;
515 PPSR |= PPC_TXD3 | PPC_TXD1;
517 sa11x0_ppc_configure_mcp();
519 if (machine_has_neponset()) {
520 #ifndef CONFIG_ASSABET_NEPONSET
521 printk( "Warning: Neponset detected but full support "
522 "hasn't been configured in the kernel\n" );
524 platform_device_register_simple("neponset", 0,
525 neponset_resources, ARRAY_SIZE(neponset_resources));
528 gpiod_add_lookup_table(&assabet_cf_vcc_gpio_table);
529 sa11x0_register_fixed_regulator(0, &assabet_cf_vcc_pdata,
530 assabet_cf_vcc_consumers,
531 ARRAY_SIZE(assabet_cf_vcc_consumers),
536 #ifndef ASSABET_PAL_VIDEO
537 sa11x0_register_lcd(&lq039q2ds54_info);
539 sa11x0_register_lcd(&pal_video);
541 sa11x0_register_mtd(&assabet_flash_data, assabet_flash_resources,
542 ARRAY_SIZE(assabet_flash_resources));
543 sa11x0_register_irda(&assabet_irda_data);
544 sa11x0_register_mcp(&assabet_mcp_data);
546 if (!machine_has_neponset())
547 sa11x0_register_pcmcia(1, &assabet_cf_gpio_table);
551 * On Assabet, we must probe for the Neponset board _before_
552 * paging_init() has occurred to actually determine the amount
553 * of RAM available. To do so, we map the appropriate IO section
554 * in the page table here in order to access GPIO registers.
556 static void __init map_sa1100_gpio_regs( void )
558 unsigned long phys = __PREG(GPLR) & PMD_MASK;
559 unsigned long virt = (unsigned long)io_p2v(phys);
560 int prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_DOMAIN(DOMAIN_IO);
563 pmd = pmd_offset(pud_offset(pgd_offset_k(virt), virt), virt);
564 *pmd = __pmd(phys | prot);
565 flush_pmd_entry(pmd);
569 * Read System Configuration "Register"
570 * (taken from "Intel StrongARM SA-1110 Microprocessor Development Board
571 * User's Guide", section 4.4.1)
573 * This same scan is performed in arch/arm/boot/compressed/head-sa1100.S
574 * to set up the serial port for decompression status messages. We
575 * repeat it here because the kernel may not be loaded as a zImage, and
576 * also because it's a hassle to communicate the SCR value to the kernel
577 * from the decompressor.
579 * Note that IRQs are guaranteed to be disabled.
581 static void __init get_assabet_scr(void)
583 unsigned long uninitialized_var(scr), i;
585 GPDR |= 0x3fc; /* Configure GPIO 9:2 as outputs */
586 GPSR = 0x3fc; /* Write 0xFF to GPIO 9:2 */
587 GPDR &= ~(0x3fc); /* Configure GPIO 9:2 as inputs */
588 for(i = 100; i--; ) /* Read GPIO 9:2 */
590 GPDR |= 0x3fc; /* restore correct pin direction */
591 scr &= 0x3fc; /* save as system configuration byte. */
596 fixup_assabet(struct tag *tags, char **cmdline)
598 /* This must be done before any call to machine_has_neponset() */
599 map_sa1100_gpio_regs();
602 if (machine_has_neponset())
603 printk("Neponset expansion board detected\n");
607 static void assabet_uart_pm(struct uart_port *port, u_int state, u_int oldstate)
609 if (port->mapbase == _Ser1UTCR0) {
611 ASSABET_BCR_clear(ASSABET_BCR_RS232EN |
612 ASSABET_BCR_COM_RTS |
613 ASSABET_BCR_COM_DTR);
615 ASSABET_BCR_set(ASSABET_BCR_RS232EN |
616 ASSABET_BCR_COM_RTS |
617 ASSABET_BCR_COM_DTR);
622 * Assabet uses COM_RTS and COM_DTR for both UART1 (com port)
623 * and UART3 (radio module). We only handle them for UART1 here.
625 static void assabet_set_mctrl(struct uart_port *port, u_int mctrl)
627 if (port->mapbase == _Ser1UTCR0) {
628 u_int set = 0, clear = 0;
630 if (mctrl & TIOCM_RTS)
631 clear |= ASSABET_BCR_COM_RTS;
633 set |= ASSABET_BCR_COM_RTS;
635 if (mctrl & TIOCM_DTR)
636 clear |= ASSABET_BCR_COM_DTR;
638 set |= ASSABET_BCR_COM_DTR;
640 ASSABET_BCR_clear(clear);
641 ASSABET_BCR_set(set);
645 static u_int assabet_get_mctrl(struct uart_port *port)
648 u_int bsr = ASSABET_BSR;
650 /* need 2 reads to read current value */
653 if (port->mapbase == _Ser1UTCR0) {
654 if (bsr & ASSABET_BSR_COM_DCD)
656 if (bsr & ASSABET_BSR_COM_CTS)
658 if (bsr & ASSABET_BSR_COM_DSR)
660 } else if (port->mapbase == _Ser3UTCR0) {
661 if (bsr & ASSABET_BSR_RAD_DCD)
663 if (bsr & ASSABET_BSR_RAD_CTS)
665 if (bsr & ASSABET_BSR_RAD_DSR)
667 if (bsr & ASSABET_BSR_RAD_RI)
670 ret = TIOCM_CD | TIOCM_CTS | TIOCM_DSR;
676 static struct sa1100_port_fns assabet_port_fns __initdata = {
677 .set_mctrl = assabet_set_mctrl,
678 .get_mctrl = assabet_get_mctrl,
679 .pm = assabet_uart_pm,
682 static struct map_desc assabet_io_desc[] __initdata = {
683 { /* Board Control Register */
684 .virtual = 0xf1000000,
685 .pfn = __phys_to_pfn(0x12000000),
686 .length = 0x00100000,
689 .virtual = 0xf2800000,
690 .pfn = __phys_to_pfn(0x4b800000),
691 .length = 0x00800000,
696 static void __init assabet_map_io(void)
699 iotable_init(assabet_io_desc, ARRAY_SIZE(assabet_io_desc));
702 * Set SUS bit in SDCR0 so serial port 1 functions.
703 * Its called GPCLKR0 in my SA1110 manual.
705 Ser1SDCR0 |= SDCR0_SUS;
706 MSC1 = (MSC1 & ~0xffff) |
707 MSC_NonBrst | MSC_32BitStMem |
708 MSC_RdAcc(2) | MSC_WrAcc(2) | MSC_Rec(0);
710 if (!machine_has_neponset())
711 sa1100_register_uart_fns(&assabet_port_fns);
714 * When Neponset is attached, the first UART should be
715 * UART3. That's what Angel is doing and many documents
718 * We do the Neponset mapping even if Neponset support
719 * isn't compiled in so the user will still get something on
720 * the expected physical serial port.
722 * We no longer do this; not all boot loaders support it,
723 * and UART3 appears to be somewhat unreliable with blob.
725 sa1100_register_uart(0, 1);
726 sa1100_register_uart(2, 3);
730 #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
732 struct led_classdev cdev;
737 * The triggers lines up below will only be used if the
738 * LED triggers are compiled in.
740 static const struct {
744 { "assabet:red", "cpu0",},
745 { "assabet:green", "heartbeat", },
749 * The LED control in Assabet is reversed:
750 * - setting bit means turn off LED
751 * - clearing bit means turn on LED
753 static void assabet_led_set(struct led_classdev *cdev,
754 enum led_brightness b)
756 struct assabet_led *led = container_of(cdev,
757 struct assabet_led, cdev);
760 ASSABET_BCR_clear(led->mask);
762 ASSABET_BCR_set(led->mask);
765 static enum led_brightness assabet_led_get(struct led_classdev *cdev)
767 struct assabet_led *led = container_of(cdev,
768 struct assabet_led, cdev);
770 return (ASSABET_BCR & led->mask) ? LED_OFF : LED_FULL;
773 static int __init assabet_leds_init(void)
777 if (!machine_is_assabet())
780 for (i = 0; i < ARRAY_SIZE(assabet_leds); i++) {
781 struct assabet_led *led;
783 led = kzalloc(sizeof(*led), GFP_KERNEL);
787 led->cdev.name = assabet_leds[i].name;
788 led->cdev.brightness_set = assabet_led_set;
789 led->cdev.brightness_get = assabet_led_get;
790 led->cdev.default_trigger = assabet_leds[i].trigger;
793 led->mask = ASSABET_BCR_LED_RED;
795 led->mask = ASSABET_BCR_LED_GREEN;
797 if (led_classdev_register(NULL, &led->cdev) < 0) {
807 * Since we may have triggers on any subsystem, defer registration
808 * until after subsystem_init.
810 fs_initcall(assabet_leds_init);
813 void __init assabet_init_irq(void)
819 if (machine_has_neponset())
820 def_val = ASSABET_BCR_DB1111;
822 def_val = ASSABET_BCR_DB1110;
825 * Angel sets this, but other bootloaders may not.
827 * This must precede any driver calls to BCR_set() or BCR_clear().
829 assabet_init_gpio((void *)&ASSABET_BCR, def_val);
832 MACHINE_START(ASSABET, "Intel-Assabet")
833 .atag_offset = 0x100,
834 .fixup = fixup_assabet,
835 .map_io = assabet_map_io,
836 .nr_irqs = SA1100_NR_IRQS,
837 .init_irq = assabet_init_irq,
838 .init_time = sa1100_timer_init,
839 .init_machine = assabet_init,
840 .init_late = sa11x0_init_late,
842 .dma_zone_size = SZ_1M,
844 .restart = sa11x0_restart,