2 * Gateworks Corporation Laguna Platform
4 * Copyright 2000 Deep Blue Solutions Ltd
5 * Copyright 2008 ARM Limited
6 * Copyright 2008 Cavium Networks
8 * Copyright 2010 MontaVista Software, LLC.
9 * Anton Vorontsov <avorontsov@mvista.com>
10 * Copyright 2011 Gateworks Corporation
11 * Chris Lang <clang@gateworks.com>
12 * Copyright 2012-2013 Gateworks Corporation
13 * Tim Harvey <tharvey@gateworks.com>
15 * This file is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License, Version 2, as
17 * published by the Free Software Foundation.
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/compiler.h>
24 #include <linux/irq.h>
25 #include <linux/gpio.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/serial_core.h>
28 #include <linux/serial_8250.h>
29 #include <linux/platform_device.h>
30 #include <linux/mtd/mtd.h>
31 #include <linux/mtd/physmap.h>
32 #include <linux/mtd/partitions.h>
33 #include <linux/leds.h>
34 #include <linux/i2c.h>
35 #include <linux/platform_data/at24.h>
36 #include <linux/platform_data/pca953x.h>
37 #include <linux/spi/spi.h>
38 #include <linux/spi/flash.h>
39 #include <linux/if_ether.h>
40 #include <linux/pps-gpio.h>
41 #include <linux/usb/ehci_pdriver.h>
42 #include <linux/usb/ohci_pdriver.h>
43 #include <linux/clk-provider.h>
44 #include <linux/clkdev.h>
45 #include <linux/platform_data/cns3xxx.h>
46 #include <asm/setup.h>
47 #include <asm/mach-types.h>
48 #include <asm/mach/arch.h>
49 #include <asm/mach/map.h>
50 #include <asm/mach/time.h>
51 #include <mach/gpio.h>
57 #define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
60 #define ETH0_LOAD BIT(0)
61 #define ETH1_LOAD BIT(1)
62 #define ETH2_LOAD BIT(2)
63 #define SATA0_LOAD BIT(3)
64 #define SATA1_LOAD BIT(4)
65 #define PCM_LOAD BIT(5)
66 #define I2S_LOAD BIT(6)
67 #define SPI0_LOAD BIT(7)
68 #define SPI1_LOAD BIT(8)
69 #define PCIE0_LOAD BIT(9)
70 #define PCIE1_LOAD BIT(10)
71 #define USB0_LOAD BIT(11)
72 #define USB1_LOAD BIT(12)
73 #define USB1_ROUTE BIT(13)
74 #define SD_LOAD BIT(14)
75 #define UART0_LOAD BIT(15)
76 #define UART1_LOAD BIT(16)
77 #define UART2_LOAD BIT(17)
78 #define MPCI0_LOAD BIT(18)
79 #define MPCI1_LOAD BIT(19)
80 #define MPCI2_LOAD BIT(20)
81 #define MPCI3_LOAD BIT(21)
82 #define FP_BUT_LOAD BIT(22)
83 #define FP_BUT_HEADER_LOAD BIT(23)
84 #define FP_LED_LOAD BIT(24)
85 #define FP_LED_HEADER_LOAD BIT(25)
86 #define FP_TAMPER_LOAD BIT(26)
87 #define HEADER_33V_LOAD BIT(27)
88 #define SATA_POWER_LOAD BIT(28)
89 #define FP_POWER_LOAD BIT(29)
90 #define GPIO_HEADER_LOAD BIT(30)
91 #define GSP_BAT_LOAD BIT(31)
94 #define FAN_LOAD BIT(0)
95 #define SPI_FLASH_LOAD BIT(1)
96 #define NOR_FLASH_LOAD BIT(2)
97 #define GPS_LOAD BIT(3)
98 #define SUPPLY_5V_LOAD BIT(6)
99 #define SUPPLY_33V_LOAD BIT(7)
101 struct laguna_board_info
{
109 static struct laguna_board_info laguna_info __initdata
;
114 static struct mtd_partition laguna_nor_partitions
[] = {
119 .mask_flags
= MTD_WRITEABLE
,
122 .offset
= MTDPART_OFS_APPEND
,
126 .offset
= MTDPART_OFS_APPEND
,
127 .size
= MTDPART_SIZ_FULL
,
131 static struct physmap_flash_data laguna_nor_pdata
= {
133 .parts
= laguna_nor_partitions
,
134 .nr_parts
= ARRAY_SIZE(laguna_nor_partitions
),
137 static struct resource laguna_nor_res
= {
138 .start
= CNS3XXX_FLASH_BASE
,
139 .end
= CNS3XXX_FLASH_BASE
+ SZ_128M
- 1,
140 .flags
= IORESOURCE_MEM
| IORESOURCE_MEM_32BIT
,
143 static struct platform_device laguna_nor_pdev
= {
144 .name
= "physmap-flash",
146 .resource
= &laguna_nor_res
,
149 .platform_data
= &laguna_nor_pdata
,
156 static struct mtd_partition laguna_spi_partitions
[] = {
161 .mask_flags
= MTD_WRITEABLE
,
164 .offset
= MTDPART_OFS_APPEND
,
168 .offset
= MTDPART_OFS_APPEND
,
169 .size
= MTDPART_SIZ_FULL
,
173 static struct flash_platform_data laguna_spi_pdata
= {
174 .parts
= laguna_spi_partitions
,
175 .nr_parts
= ARRAY_SIZE(laguna_spi_partitions
),
178 static struct spi_board_info __initdata laguna_spi_devices
[] = {
180 .modalias
= "m25p80",
181 .platform_data
= &laguna_spi_pdata
,
182 .max_speed_hz
= 50000000,
188 static struct resource laguna_spi_resource
= {
189 .start
= CNS3XXX_SSP_BASE
+ 0x40,
190 .end
= CNS3XXX_SSP_BASE
+ 0x6f,
191 .flags
= IORESOURCE_MEM
,
194 static struct platform_device laguna_spi_controller
= {
195 .name
= "cns3xxx_spi",
196 .resource
= &laguna_spi_resource
,
203 static struct gpio_led laguna_gpio_leds
[] = {
205 .name
= "user1", /* Green Led */
209 .name
= "user2", /* Red Led */
213 .name
= "pwr1", /* Green Led */
217 .name
= "pwr2", /* Yellow Led */
221 .name
= "txd1", /* Green Led */
225 .name
= "txd2", /* Yellow Led */
229 .name
= "rxd1", /* Green Led */
233 .name
= "rxd2", /* Yellow Led */
237 .name
= "ser1", /* Green Led */
241 .name
= "ser2", /* Yellow Led */
245 .name
= "enet1", /* Green Led */
249 .name
= "enet2", /* Yellow Led */
253 .name
= "sig1_1", /* Green Led */
257 .name
= "sig1_2", /* Yellow Led */
261 .name
= "sig2_1", /* Green Led */
265 .name
= "sig2_2", /* Yellow Led */
269 .name
= "sig3_1", /* Green Led */
273 .name
= "sig3_2", /* Yellow Led */
277 .name
= "net1", /*Green Led */
281 .name
= "net2", /* Red Led */
285 .name
= "mod1", /* Green Led */
289 .name
= "mod2", /* Red Led */
295 static struct gpio_led_platform_data laguna_gpio_leds_data
= {
297 .leds
= laguna_gpio_leds
,
300 static struct platform_device laguna_gpio_leds_device
= {
302 .id
= PLATFORM_DEVID_NONE
,
303 .dev
.platform_data
= &laguna_gpio_leds_data
,
309 static struct cns3xxx_plat_info laguna_net_data
= {
318 static struct resource laguna_net_resource
[] = {
321 .start
= CNS3XXX_SWITCH_BASE
,
322 .end
= CNS3XXX_SWITCH_BASE
+ SZ_4K
- 1,
323 .flags
= IORESOURCE_MEM
326 .start
= IRQ_CNS3XXX_SW_R0RXC
,
327 .end
= IRQ_CNS3XXX_SW_R0RXC
,
328 .flags
= IORESOURCE_IRQ
331 .start
= IRQ_CNS3XXX_SW_STATUS
,
332 .end
= IRQ_CNS3XXX_SW_STATUS
,
333 .flags
= IORESOURCE_IRQ
337 static u64 laguna_net_dmamask
= DMA_BIT_MASK(32);
338 static struct platform_device laguna_net_device
= {
339 .name
= "cns3xxx_eth",
341 .resource
= laguna_net_resource
,
342 .num_resources
= ARRAY_SIZE(laguna_net_resource
),
344 .dma_mask
= &laguna_net_dmamask
,
345 .coherent_dma_mask
= DMA_BIT_MASK(32),
346 .platform_data
= &laguna_net_data
,
353 static void __init
laguna_early_serial_setup(void)
355 #ifdef CONFIG_SERIAL_8250_CONSOLE
356 static struct uart_port laguna_serial_port
= {
357 .membase
= (void __iomem
*)CNS3XXX_UART0_BASE_VIRT
,
358 .mapbase
= CNS3XXX_UART0_BASE
,
359 .irq
= IRQ_CNS3XXX_UART0
,
361 .flags
= UPF_BOOT_AUTOCONF
| UPF_FIXED_TYPE
,
369 early_serial_setup(&laguna_serial_port
);
373 static struct resource laguna_uart_resources
[] = {
375 .start
= CNS3XXX_UART0_BASE
,
376 .end
= CNS3XXX_UART0_BASE
+ SZ_4K
- 1,
377 .flags
= IORESOURCE_MEM
379 .start
= CNS3XXX_UART1_BASE
,
380 .end
= CNS3XXX_UART1_BASE
+ SZ_4K
- 1,
381 .flags
= IORESOURCE_MEM
383 .start
= CNS3XXX_UART2_BASE
,
384 .end
= CNS3XXX_UART2_BASE
+ SZ_4K
- 1,
385 .flags
= IORESOURCE_MEM
389 static struct plat_serial8250_port laguna_uart_data
[] = {
391 .mapbase
= (CNS3XXX_UART0_BASE
),
392 .irq
= IRQ_CNS3XXX_UART0
,
394 .flags
= UPF_BOOT_AUTOCONF
| UPF_FIXED_TYPE
| UPF_IOREMAP
,
399 .mapbase
= (CNS3XXX_UART1_BASE
),
400 .irq
= IRQ_CNS3XXX_UART1
,
402 .flags
= UPF_BOOT_AUTOCONF
| UPF_FIXED_TYPE
| UPF_IOREMAP
,
407 .mapbase
= (CNS3XXX_UART2_BASE
),
408 .irq
= IRQ_CNS3XXX_UART2
,
410 .flags
= UPF_BOOT_AUTOCONF
| UPF_FIXED_TYPE
| UPF_IOREMAP
,
418 static struct platform_device laguna_uart
= {
419 .name
= "serial8250",
420 .id
= PLAT8250_DEV_PLATFORM
,
421 .dev
.platform_data
= laguna_uart_data
,
423 .resource
= laguna_uart_resources
429 static struct resource cns3xxx_usb_ehci_resources
[] = {
431 .start
= CNS3XXX_USB_BASE
,
432 .end
= CNS3XXX_USB_BASE
+ SZ_16M
- 1,
433 .flags
= IORESOURCE_MEM
,
436 .start
= IRQ_CNS3XXX_USB_EHCI
,
437 .flags
= IORESOURCE_IRQ
,
441 static u64 cns3xxx_usb_ehci_dma_mask
= DMA_BIT_MASK(32);
443 static int csn3xxx_usb_power_on(struct platform_device
*pdev
)
446 * EHCI and OHCI share the same clock and power,
447 * resetting twice would cause the 1st controller been reset.
448 * Therefore only do power up at the first up device, and
449 * power down at the last down device.
451 * Set USB AHB INCR length to 16
453 if (atomic_inc_return(&usb_pwr_ref
) == 1) {
454 cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB
);
455 cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST
);
456 cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST
);
457 __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG
) | (0X2 << 24)),
458 MISC_CHIP_CONFIG_REG
);
464 static void csn3xxx_usb_power_off(struct platform_device
*pdev
)
467 * EHCI and OHCI share the same clock and power,
468 * resetting twice would cause the 1st controller been reset.
469 * Therefore only do power up at the first up device, and
470 * power down at the last down device.
472 if (atomic_dec_return(&usb_pwr_ref
) == 0)
473 cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST
);
476 static struct usb_ehci_pdata cns3xxx_usb_ehci_pdata
= {
477 .power_on
= csn3xxx_usb_power_on
,
478 .power_off
= csn3xxx_usb_power_off
,
481 static struct platform_device cns3xxx_usb_ehci_device
= {
482 .name
= "ehci-platform",
483 .num_resources
= ARRAY_SIZE(cns3xxx_usb_ehci_resources
),
484 .resource
= cns3xxx_usb_ehci_resources
,
486 .dma_mask
= &cns3xxx_usb_ehci_dma_mask
,
487 .coherent_dma_mask
= DMA_BIT_MASK(32),
488 .platform_data
= &cns3xxx_usb_ehci_pdata
,
492 static struct resource cns3xxx_usb_ohci_resources
[] = {
494 .start
= CNS3XXX_USB_OHCI_BASE
,
495 .end
= CNS3XXX_USB_OHCI_BASE
+ SZ_16M
- 1,
496 .flags
= IORESOURCE_MEM
,
499 .start
= IRQ_CNS3XXX_USB_OHCI
,
500 .flags
= IORESOURCE_IRQ
,
504 static u64 cns3xxx_usb_ohci_dma_mask
= DMA_BIT_MASK(32);
506 static struct usb_ohci_pdata cns3xxx_usb_ohci_pdata
= {
508 .power_on
= csn3xxx_usb_power_on
,
509 .power_off
= csn3xxx_usb_power_off
,
512 static struct platform_device cns3xxx_usb_ohci_device
= {
513 .name
= "ohci-platform",
514 .num_resources
= ARRAY_SIZE(cns3xxx_usb_ohci_resources
),
515 .resource
= cns3xxx_usb_ohci_resources
,
517 .dma_mask
= &cns3xxx_usb_ohci_dma_mask
,
518 .coherent_dma_mask
= DMA_BIT_MASK(32),
519 .platform_data
= &cns3xxx_usb_ohci_pdata
,
523 static struct resource cns3xxx_usb_otg_resources
[] = {
525 .start
= CNS3XXX_USBOTG_BASE
,
526 .end
= CNS3XXX_USBOTG_BASE
+ SZ_16M
- 1,
527 .flags
= IORESOURCE_MEM
,
530 .start
= IRQ_CNS3XXX_USB_OTG
,
531 .flags
= IORESOURCE_IRQ
,
535 static u64 cns3xxx_usb_otg_dma_mask
= DMA_BIT_MASK(32);
537 static struct platform_device cns3xxx_usb_otg_device
= {
539 .num_resources
= ARRAY_SIZE(cns3xxx_usb_otg_resources
),
540 .resource
= cns3xxx_usb_otg_resources
,
542 .dma_mask
= &cns3xxx_usb_otg_dma_mask
,
543 .coherent_dma_mask
= DMA_BIT_MASK(32),
550 static struct resource laguna_i2c_resource
[] = {
552 .start
= CNS3XXX_SSP_BASE
+ 0x20,
553 .end
= CNS3XXX_SSP_BASE
+ 0x3f,
554 .flags
= IORESOURCE_MEM
,
556 .start
= IRQ_CNS3XXX_I2C
,
557 .flags
= IORESOURCE_IRQ
,
561 static struct platform_device laguna_i2c_controller
= {
562 .name
= "cns3xxx-i2c",
564 .resource
= laguna_i2c_resource
,
567 static struct nvmem_device
*at24_nvmem
;
569 static void at24_setup(struct nvmem_device
*mem_acc
, void *context
)
573 at24_nvmem
= mem_acc
;
575 /* Read MAC addresses */
576 if (nvmem_device_read(at24_nvmem
, 0x100, 6, buf
) == 6)
577 memcpy(&laguna_net_data
.hwaddr
[0], buf
, ETH_ALEN
);
578 if (nvmem_device_read(at24_nvmem
, 0x106, 6, buf
) == 6)
579 memcpy(&laguna_net_data
.hwaddr
[1], buf
, ETH_ALEN
);
580 if (nvmem_device_read(at24_nvmem
, 0x10C, 6, buf
) == 6)
581 memcpy(&laguna_net_data
.hwaddr
[2], buf
, ETH_ALEN
);
582 if (nvmem_device_read(at24_nvmem
, 0x112, 6, buf
) == 6)
583 memcpy(&laguna_net_data
.hwaddr
[3], buf
, ETH_ALEN
);
585 /* Read out Model Information */
586 if (nvmem_device_read(at24_nvmem
, 0x130, 16, buf
) == 16)
587 memcpy(&laguna_info
.model
, buf
, 16);
588 if (nvmem_device_read(at24_nvmem
, 0x140, 1, buf
) == 1)
589 memcpy(&laguna_info
.nor_flash_size
, buf
, 1);
590 if (nvmem_device_read(at24_nvmem
, 0x141, 1, buf
) == 1)
591 memcpy(&laguna_info
.spi_flash_size
, buf
, 1);
592 if (nvmem_device_read(at24_nvmem
, 0x142, 4, buf
) == 4)
593 memcpy(&laguna_info
.config_bitmap
, buf
, 4);
594 if (nvmem_device_read(at24_nvmem
, 0x146, 4, buf
) == 4)
595 memcpy(&laguna_info
.config2_bitmap
, buf
, 4);
598 static struct at24_platform_data laguna_eeprom_info
= {
601 .flags
= AT24_FLAG_READONLY
,
605 static struct pca953x_platform_data laguna_pca_data
= {
610 static struct pca953x_platform_data laguna_pca2_data
= {
615 static struct i2c_board_info __initdata laguna_i2c_devices
[] = {
617 I2C_BOARD_INFO("pca9555", 0x23),
618 .platform_data
= &laguna_pca_data
,
620 I2C_BOARD_INFO("pca9555", 0x27),
621 .platform_data
= &laguna_pca2_data
,
623 I2C_BOARD_INFO("gsp", 0x29),
625 I2C_BOARD_INFO ("24c08",0x50),
626 .platform_data
= &laguna_eeprom_info
,
628 I2C_BOARD_INFO("ds1672", 0x68),
636 static struct resource laguna_watchdog_resources
[] = {
638 .start
= CNS3XXX_TC11MP_TWD_BASE
+ 0x100, // CPU0 watchdog
639 .end
= CNS3XXX_TC11MP_TWD_BASE
+ SZ_4K
- 1,
640 .flags
= IORESOURCE_MEM
,
644 static struct platform_device laguna_watchdog
= {
645 .name
= "mpcore_wdt",
646 .id
= PLATFORM_DEVID_NONE
,
647 .num_resources
= ARRAY_SIZE(laguna_watchdog_resources
),
648 .resource
= laguna_watchdog_resources
,
654 static struct pps_gpio_platform_data laguna_pps_data
= {
656 .gpio_label
= "GPS_PPS",
657 .assert_falling_edge
= 0,
661 static struct platform_device laguna_pps_device
= {
663 .id
= PLATFORM_DEVID_NONE
,
664 .dev
.platform_data
= &laguna_pps_data
,
671 static struct gpio laguna_gpio_gw2391
[] = {
672 { 0, GPIOF_IN
, "*GPS_PPS" },
673 { 1, GPIOF_IN
, "*GSC_IRQ#" },
674 { 2, GPIOF_IN
, "*USB_FAULT#" },
675 { 5, GPIOF_OUT_INIT_LOW
, "*USB0_PCI_SEL" },
676 { 6, GPIOF_OUT_INIT_HIGH
, "*USB_VBUS_EN" },
677 { 7, GPIOF_OUT_INIT_LOW
, "*USB1_PCI_SEL" },
678 { 8, GPIOF_OUT_INIT_HIGH
, "*PERST#" },
679 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN#" },
680 { 100, GPIOF_IN
, "*USER_PB#" },
681 { 103, GPIOF_OUT_INIT_HIGH
, "*V5_EN" },
682 { 108, GPIOF_IN
, "DIO0" },
683 { 109, GPIOF_IN
, "DIO1" },
684 { 110, GPIOF_IN
, "DIO2" },
685 { 111, GPIOF_IN
, "DIO3" },
686 { 112, GPIOF_IN
, "DIO4" },
689 static struct gpio laguna_gpio_gw2388
[] = {
690 { 0, GPIOF_IN
, "*GPS_PPS" },
691 { 1, GPIOF_IN
, "*GSC_IRQ#" },
692 { 3, GPIOF_IN
, "*USB_FAULT#" },
693 { 6, GPIOF_OUT_INIT_HIGH
, "*USB_VBUS_EN" },
694 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
695 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
696 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN" },
697 { 100, GPIOF_OUT_INIT_HIGH
, "*USER_PB#" },
698 { 108, GPIOF_IN
, "DIO0" },
699 { 109, GPIOF_IN
, "DIO1" },
700 { 110, GPIOF_IN
, "DIO2" },
701 { 111, GPIOF_IN
, "DIO3" },
702 { 112, GPIOF_IN
, "DIO4" },
705 static struct gpio laguna_gpio_gw2387
[] = {
706 { 0, GPIOF_IN
, "*GPS_PPS" },
707 { 1, GPIOF_IN
, "*GSC_IRQ#" },
708 { 2, GPIOF_IN
, "*USB_FAULT#" },
709 { 5, GPIOF_OUT_INIT_LOW
, "*USB_PCI_SEL" },
710 { 6, GPIOF_OUT_INIT_HIGH
, "*USB_VBUS_EN" },
711 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
712 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
713 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN" },
714 { 100, GPIOF_IN
, "*USER_PB#" },
715 { 103, GPIOF_OUT_INIT_HIGH
, "*V5_EN" },
716 { 108, GPIOF_IN
, "DIO0" },
717 { 109, GPIOF_IN
, "DIO1" },
718 { 110, GPIOF_IN
, "DIO2" },
719 { 111, GPIOF_IN
, "DIO3" },
720 { 112, GPIOF_IN
, "DIO4" },
721 { 113, GPIOF_IN
, "DIO5" },
724 static struct gpio laguna_gpio_gw2386
[] = {
725 { 0, GPIOF_IN
, "*GPS_PPS" },
726 { 2, GPIOF_IN
, "*USB_FAULT#" },
727 { 6, GPIOF_OUT_INIT_LOW
, "*USB_PCI_SEL" },
728 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
729 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
730 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN" },
731 { 108, GPIOF_IN
, "DIO0" },
732 { 109, GPIOF_IN
, "DIO1" },
733 { 110, GPIOF_IN
, "DIO2" },
734 { 111, GPIOF_IN
, "DIO3" },
735 { 112, GPIOF_IN
, "DIO4" },
736 { 113, GPIOF_IN
, "DIO5" },
739 static struct gpio laguna_gpio_gw2385
[] = {
740 { 0, GPIOF_IN
, "*GSC_IRQ#" },
741 { 1, GPIOF_OUT_INIT_HIGH
, "*USB_HST_VBUS_EN" },
742 { 2, GPIOF_IN
, "*USB_HST_FAULT#" },
743 { 5, GPIOF_IN
, "*USB_OTG_FAULT#" },
744 { 6, GPIOF_OUT_INIT_LOW
, "*USB_HST_PCI_SEL" },
745 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
746 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
747 { 9, GPIOF_OUT_INIT_LOW
, "*SER_EN" },
748 { 10, GPIOF_IN
, "*USER_PB#" },
749 { 11, GPIOF_OUT_INIT_HIGH
, "*PERST#" },
750 { 100, GPIOF_IN
, "*USER_PB#" },
751 { 103, GPIOF_OUT_INIT_HIGH
, "V5_EN" },
754 static struct gpio laguna_gpio_gw2384
[] = {
755 { 0, GPIOF_IN
, "*GSC_IRQ#" },
756 { 1, GPIOF_OUT_INIT_HIGH
, "*USB_HST_VBUS_EN" },
757 { 2, GPIOF_IN
, "*USB_HST_FAULT#" },
758 { 5, GPIOF_IN
, "*USB_OTG_FAULT#" },
759 { 6, GPIOF_OUT_INIT_LOW
, "*USB_HST_PCI_SEL" },
760 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
761 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
762 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN" },
763 { 12, GPIOF_OUT_INIT_LOW
, "J10_DIOLED0" },
764 { 13, GPIOF_OUT_INIT_HIGH
, "*I2CMUX_RST#" },
765 { 14, GPIOF_OUT_INIT_LOW
, "J10_DIOLED1" },
766 { 15, GPIOF_OUT_INIT_LOW
, "J10_DIOLED2" },
767 { 100, GPIOF_IN
, "*USER_PB#" },
768 { 103, GPIOF_OUT_INIT_HIGH
, "V5_EN" },
769 { 108, GPIOF_IN
, "J9_DIOGSC0" },
772 static struct gpio laguna_gpio_gw2383
[] = {
773 { 0, GPIOF_IN
, "*GPS_PPS" },
774 { 1, GPIOF_IN
, "*GSC_IRQ#" },
775 { 2, GPIOF_OUT_INIT_HIGH
, "*PCIE_RST#" },
776 { 3, GPIOF_IN
, "GPIO0" },
777 { 8, GPIOF_IN
, "GPIO1" },
778 { 100, GPIOF_IN
, "DIO0" },
779 { 101, GPIOF_IN
, "DIO1" },
780 { 108, GPIOF_IN
, "*USER_PB#" },
783 static struct gpio laguna_gpio_gw2382
[] = {
784 { 0, GPIOF_IN
, "*GPS_PPS" },
785 { 1, GPIOF_IN
, "*GSC_IRQ#" },
786 { 2, GPIOF_OUT_INIT_HIGH
, "*PCIE_RST#" },
787 { 3, GPIOF_IN
, "GPIO0" },
788 { 4, GPIOF_IN
, "GPIO1" },
789 { 9, GPIOF_OUT_INIT_HIGH
, "*USB_VBUS_EN" },
790 { 10, GPIOF_OUT_INIT_HIGH
, "*USB_PCI_SEL#" },
791 { 100, GPIOF_IN
, "DIO0" },
792 { 101, GPIOF_IN
, "DIO1" },
793 { 108, GPIOF_IN
, "*USER_PB#" },
796 static struct gpio laguna_gpio_gw2380
[] = {
797 { 0, GPIOF_IN
, "*GPS_PPS" },
798 { 1, GPIOF_IN
, "*GSC_IRQ#" },
799 { 3, GPIOF_IN
, "GPIO0" },
800 { 8, GPIOF_IN
, "GPIO1" },
801 { 100, GPIOF_IN
, "DIO0" },
802 { 101, GPIOF_IN
, "DIO1" },
803 { 102, GPIOF_IN
, "DIO2" },
804 { 103, GPIOF_IN
, "DIO3" },
805 { 108, GPIOF_IN
, "*USER_PB#" },
811 static void __init
laguna_init(void)
816 clk
= clk_register_fixed_rate(NULL
, "cpu", NULL
,
818 cns3xxx_cpu_clock() * (1000000 / 8));
819 clk_register_clkdev(clk
, "cpu", NULL
);
821 platform_device_register(&laguna_watchdog
);
823 platform_device_register(&laguna_i2c_controller
);
825 /* Set I2C 0-3 drive strength to 21 mA */
826 reg
= MISC_IO_PAD_DRIVE_STRENGTH_CTRL_B
;
829 /* Enable SCL/SDA for I2C */
830 reg
= MISC_GPIOB_PIN_ENABLE_REG
;
831 *reg
|= BIT(12) | BIT(13);
833 /* Enable MMC/SD pins */
834 *reg
|= BIT(7) | BIT(8) | BIT(9) | BIT(10) | BIT(11);
836 cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C
);
837 cns3xxx_pwr_power_up(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C
);
838 cns3xxx_pwr_soft_rst(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C
);
840 cns3xxx_pwr_clk_en(CNS3XXX_PWR_CLK_EN(SPI_PCM_I2C
));
841 cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SPI_PCM_I2C
));
843 i2c_register_board_info(0, ARRAY_AND_SIZE(laguna_i2c_devices
));
845 pm_power_off
= cns3xxx_power_off
;
848 static struct map_desc laguna_io_desc
[] __initdata
= {
850 .virtual = CNS3XXX_UART0_BASE_VIRT
,
851 .pfn
= __phys_to_pfn(CNS3XXX_UART0_BASE
),
857 static void __init
laguna_map_io(void)
860 iotable_init(ARRAY_AND_SIZE(laguna_io_desc
));
861 laguna_early_serial_setup();
864 static int laguna_register_gpio(struct gpio
*array
, size_t num
)
869 for (i
= 0; i
< num
; i
++, array
++) {
870 const char *label
= array
->label
;
873 err
= gpio_request_one(array
->gpio
, array
->flags
, label
);
877 err
= gpio_export(array
->gpio
, array
->label
[0] != '*');
883 /* allow disabling of external isolated PCIe IRQs */
884 static int cns3xxx_pciextirq
= 1;
885 static int __init
cns3xxx_pciextirq_disable(char *s
)
887 cns3xxx_pciextirq
= 0;
890 __setup("noextirq", cns3xxx_pciextirq_disable
);
892 static int __init
laguna_pcie_init_irq(void)
894 u32 __iomem
*mem
= (void __iomem
*)(CNS3XXX_GPIOB_BASE_VIRT
+ 0x0004);
895 u32 reg
= (__raw_readl(mem
) >> 26) & 0xf;
897 IRQ_CNS3XXX_EXTERNAL_PIN0
,
898 IRQ_CNS3XXX_EXTERNAL_PIN1
,
899 IRQ_CNS3XXX_EXTERNAL_PIN2
,
903 if (!machine_is_gw2388())
906 /* Verify GPIOB[26:29] == 0001b indicating support for ext irqs */
907 if (cns3xxx_pciextirq
&& reg
!= 1)
908 cns3xxx_pciextirq
= 0;
910 if (cns3xxx_pciextirq
) {
911 printk("laguna: using isolated PCI interrupts:"
912 " irq%d/irq%d/irq%d/irq%d\n",
913 irqs
[0], irqs
[1], irqs
[2], irqs
[3]);
914 cns3xxx_pcie_set_irqs(0, irqs
);
916 printk("laguna: using shared PCI interrupts: irq%d\n",
917 IRQ_CNS3XXX_PCIE0_DEVICE
);
922 subsys_initcall(laguna_pcie_init_irq
);
924 static int __init
laguna_model_setup(void)
929 if (!machine_is_gw2388())
932 printk("Running on Gateworks Laguna %s\n", laguna_info
.model
);
933 cns3xxx_gpio_init( 0, 32, CNS3XXX_GPIOA_BASE_VIRT
, IRQ_CNS3XXX_GPIOA
,
937 * If pcie external interrupts are supported and desired
938 * configure IRQ types and configure pin function.
939 * Note that cns3xxx_pciextirq is enabled by default, but can be
940 * unset via the 'noextirq' kernel param or by laguna_pcie_init() if
941 * the baseboard model does not support this hardware feature.
943 if (cns3xxx_pciextirq
) {
944 mem
= (void __iomem
*)(CNS3XXX_MISC_BASE_VIRT
+ 0x0018);
945 reg
= __raw_readl(mem
);
946 /* GPIO26 is gpio, EXT_INT[0:2] not gpio func */
949 __raw_writel(reg
, mem
);
951 cns3xxx_gpio_init(32, 32, CNS3XXX_GPIOB_BASE_VIRT
,
952 IRQ_CNS3XXX_GPIOB
, NR_IRQS_CNS3XXX
+ 32);
954 irq_set_irq_type(154, IRQ_TYPE_LEVEL_LOW
);
955 irq_set_irq_type(93, IRQ_TYPE_LEVEL_HIGH
);
956 irq_set_irq_type(94, IRQ_TYPE_LEVEL_HIGH
);
957 irq_set_irq_type(95, IRQ_TYPE_LEVEL_HIGH
);
959 cns3xxx_gpio_init(32, 32, CNS3XXX_GPIOB_BASE_VIRT
,
960 IRQ_CNS3XXX_GPIOB
, NR_IRQS_CNS3XXX
+ 32);
963 if (strncmp(laguna_info
.model
, "GW", 2) == 0) {
964 if (laguna_info
.config_bitmap
& ETH0_LOAD
)
965 laguna_net_data
.ports
|= BIT(0);
966 if (laguna_info
.config_bitmap
& ETH1_LOAD
)
967 laguna_net_data
.ports
|= BIT(1);
968 if (laguna_info
.config_bitmap
& ETH2_LOAD
)
969 laguna_net_data
.ports
|= BIT(2);
970 if (laguna_net_data
.ports
)
971 platform_device_register(&laguna_net_device
);
973 if ((laguna_info
.config_bitmap
& SATA0_LOAD
) ||
974 (laguna_info
.config_bitmap
& SATA1_LOAD
))
977 if (laguna_info
.config_bitmap
& (USB0_LOAD
)) {
978 cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB
);
980 /* DRVVBUS pins share with GPIOA */
981 mem
= (void __iomem
*)(CNS3XXX_MISC_BASE_VIRT
+ 0x0014);
982 reg
= __raw_readl(mem
);
984 __raw_writel(reg
, mem
);
987 mem
= (void __iomem
*)(CNS3XXX_MISC_BASE_VIRT
+ 0x0808);
988 reg
= __raw_readl(mem
);
990 __raw_writel(reg
, mem
);
992 platform_device_register(&cns3xxx_usb_otg_device
);
995 if (laguna_info
.config_bitmap
& (USB1_LOAD
)) {
996 platform_device_register(&cns3xxx_usb_ehci_device
);
997 platform_device_register(&cns3xxx_usb_ohci_device
);
1000 if (laguna_info
.config_bitmap
& (SD_LOAD
))
1001 cns3xxx_sdhci_init();
1003 if (laguna_info
.config_bitmap
& (UART0_LOAD
))
1004 laguna_uart
.num_resources
= 1;
1005 if (laguna_info
.config_bitmap
& (UART1_LOAD
))
1006 laguna_uart
.num_resources
= 2;
1007 if (laguna_info
.config_bitmap
& (UART2_LOAD
))
1008 laguna_uart
.num_resources
= 3;
1009 platform_device_register(&laguna_uart
);
1011 if (laguna_info
.config2_bitmap
& (NOR_FLASH_LOAD
)) {
1012 laguna_nor_partitions
[2].size
=
1013 (SZ_4M
<< laguna_info
.nor_flash_size
) -
1014 laguna_nor_partitions
[2].offset
;
1015 laguna_nor_res
.end
= CNS3XXX_FLASH_BASE
+
1016 laguna_nor_partitions
[2].offset
+
1017 laguna_nor_partitions
[2].size
- 1;
1018 platform_device_register(&laguna_nor_pdev
);
1021 if (laguna_info
.config2_bitmap
& (SPI_FLASH_LOAD
)) {
1022 laguna_spi_partitions
[2].size
=
1023 (SZ_2M
<< laguna_info
.spi_flash_size
) -
1024 laguna_spi_partitions
[2].offset
;
1025 spi_register_board_info(ARRAY_AND_SIZE(laguna_spi_devices
));
1028 if ((laguna_info
.config_bitmap
& SPI0_LOAD
) ||
1029 (laguna_info
.config_bitmap
& SPI1_LOAD
))
1030 platform_device_register(&laguna_spi_controller
);
1032 if (laguna_info
.config2_bitmap
& GPS_LOAD
)
1033 platform_device_register(&laguna_pps_device
);
1036 * Do any model specific setup not known by the bitmap by matching
1037 * the first 6 characters of the model name
1040 if ( (strncmp(laguna_info
.model
, "GW2388", 6) == 0)
1041 || (strncmp(laguna_info
.model
, "GW2389", 6) == 0) )
1044 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2388
));
1046 laguna_gpio_leds_data
.num_leds
= 2;
1047 } else if (strncmp(laguna_info
.model
, "GW2387", 6) == 0) {
1049 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2387
));
1051 laguna_gpio_leds_data
.num_leds
= 2;
1052 } else if (strncmp(laguna_info
.model
, "GW2386", 6) == 0) {
1054 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2386
));
1056 laguna_gpio_leds_data
.num_leds
= 2;
1057 } else if (strncmp(laguna_info
.model
, "GW2385", 6) == 0) {
1059 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2385
));
1061 laguna_gpio_leds
[0].gpio
= 115;
1062 laguna_gpio_leds
[1].gpio
= 12;
1063 laguna_gpio_leds
[1].name
= "red";
1064 laguna_gpio_leds
[1].active_low
= 0,
1065 laguna_gpio_leds
[2].gpio
= 14;
1066 laguna_gpio_leds
[2].name
= "green";
1067 laguna_gpio_leds
[2].active_low
= 0,
1068 laguna_gpio_leds
[3].gpio
= 15;
1069 laguna_gpio_leds
[3].name
= "blue";
1070 laguna_gpio_leds
[3].active_low
= 0,
1071 laguna_gpio_leds_data
.num_leds
= 4;
1072 } else if ( (strncmp(laguna_info
.model
, "GW2384", 6) == 0)
1073 || (strncmp(laguna_info
.model
, "GW2394", 6) == 0) )
1076 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2384
));
1078 laguna_gpio_leds_data
.num_leds
= 1;
1079 } else if (strncmp(laguna_info
.model
, "GW2383", 6) == 0) {
1081 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2383
));
1083 laguna_gpio_leds
[0].gpio
= 107;
1084 laguna_gpio_leds_data
.num_leds
= 1;
1085 } else if (strncmp(laguna_info
.model
, "GW2382", 6) == 0) {
1087 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2382
));
1089 laguna_gpio_leds
[0].gpio
= 107;
1090 laguna_gpio_leds_data
.num_leds
= 1;
1091 } else if (strncmp(laguna_info
.model
, "GW2380", 6) == 0) {
1093 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2380
));
1095 laguna_gpio_leds
[0].gpio
= 107;
1096 laguna_gpio_leds
[1].gpio
= 106;
1097 laguna_gpio_leds_data
.num_leds
= 2;
1098 } else if ( (strncmp(laguna_info
.model
, "GW2391", 6) == 0)
1099 || (strncmp(laguna_info
.model
, "GW2393", 6) == 0) )
1102 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2391
));
1104 laguna_gpio_leds_data
.num_leds
= 2;
1106 platform_device_register(&laguna_gpio_leds_device
);
1108 // Do some defaults here, not sure what yet
1112 late_initcall(laguna_model_setup
);
1114 MACHINE_START(GW2388
, "Gateworks Corporation Laguna Platform")
1115 .smp
= smp_ops(cns3xxx_smp_ops
),
1116 .atag_offset
= 0x100,
1117 .map_io
= laguna_map_io
,
1118 .init_irq
= cns3xxx_init_irq
,
1119 .init_time
= cns3xxx_timer_init
,
1120 .init_machine
= laguna_init
,
1121 .init_late
= cns3xxx_pcie_init_late
,
1122 .restart
= cns3xxx_restart
,