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
,
126 .offset
= SZ_256K
+ SZ_128K
,
130 static struct physmap_flash_data laguna_nor_pdata
= {
132 .parts
= laguna_nor_partitions
,
133 .nr_parts
= ARRAY_SIZE(laguna_nor_partitions
),
136 static struct resource laguna_nor_res
= {
137 .start
= CNS3XXX_FLASH_BASE
,
138 .end
= CNS3XXX_FLASH_BASE
+ SZ_128M
- 1,
139 .flags
= IORESOURCE_MEM
| IORESOURCE_MEM_32BIT
,
142 static struct platform_device laguna_nor_pdev
= {
143 .name
= "physmap-flash",
145 .resource
= &laguna_nor_res
,
148 .platform_data
= &laguna_nor_pdata
,
155 static struct mtd_partition laguna_spi_partitions
[] = {
160 .mask_flags
= MTD_WRITEABLE
,
171 static struct flash_platform_data laguna_spi_pdata
= {
172 .parts
= laguna_spi_partitions
,
173 .nr_parts
= ARRAY_SIZE(laguna_spi_partitions
),
176 static struct spi_board_info __initdata laguna_spi_devices
[] = {
178 .modalias
= "m25p80",
179 .platform_data
= &laguna_spi_pdata
,
180 .max_speed_hz
= 50000000,
186 static struct resource laguna_spi_resource
= {
187 .start
= CNS3XXX_SSP_BASE
+ 0x40,
188 .end
= CNS3XXX_SSP_BASE
+ 0x6f,
189 .flags
= IORESOURCE_MEM
,
192 static struct platform_device laguna_spi_controller
= {
193 .name
= "cns3xxx_spi",
194 .resource
= &laguna_spi_resource
,
201 static struct gpio_led laguna_gpio_leds
[] = {
203 .name
= "user1", /* Green Led */
207 .name
= "user2", /* Red Led */
211 .name
= "pwr1", /* Green Led */
215 .name
= "pwr2", /* Yellow Led */
219 .name
= "txd1", /* Green Led */
223 .name
= "txd2", /* Yellow Led */
227 .name
= "rxd1", /* Green Led */
231 .name
= "rxd2", /* Yellow Led */
235 .name
= "ser1", /* Green Led */
239 .name
= "ser2", /* Yellow Led */
243 .name
= "enet1", /* Green Led */
247 .name
= "enet2", /* Yellow Led */
251 .name
= "sig1_1", /* Green Led */
255 .name
= "sig1_2", /* Yellow Led */
259 .name
= "sig2_1", /* Green Led */
263 .name
= "sig2_2", /* Yellow Led */
267 .name
= "sig3_1", /* Green Led */
271 .name
= "sig3_2", /* Yellow Led */
275 .name
= "net1", /*Green Led */
279 .name
= "net2", /* Red Led */
283 .name
= "mod1", /* Green Led */
287 .name
= "mod2", /* Red Led */
293 static struct gpio_led_platform_data laguna_gpio_leds_data
= {
295 .leds
= laguna_gpio_leds
,
298 static struct platform_device laguna_gpio_leds_device
= {
300 .id
= PLATFORM_DEVID_NONE
,
301 .dev
.platform_data
= &laguna_gpio_leds_data
,
307 static struct cns3xxx_plat_info laguna_net_data
= {
316 static struct resource laguna_net_resource
[] = {
319 .start
= CNS3XXX_SWITCH_BASE
,
320 .end
= CNS3XXX_SWITCH_BASE
+ SZ_4K
- 1,
321 .flags
= IORESOURCE_MEM
324 .start
= IRQ_CNS3XXX_SW_R0RXC
,
325 .end
= IRQ_CNS3XXX_SW_R0RXC
,
326 .flags
= IORESOURCE_IRQ
329 .start
= IRQ_CNS3XXX_SW_STATUS
,
330 .end
= IRQ_CNS3XXX_SW_STATUS
,
331 .flags
= IORESOURCE_IRQ
335 static u64 laguna_net_dmamask
= DMA_BIT_MASK(32);
336 static struct platform_device laguna_net_device
= {
337 .name
= "cns3xxx_eth",
339 .resource
= laguna_net_resource
,
340 .num_resources
= ARRAY_SIZE(laguna_net_resource
),
342 .dma_mask
= &laguna_net_dmamask
,
343 .coherent_dma_mask
= DMA_BIT_MASK(32),
344 .platform_data
= &laguna_net_data
,
351 static void __init
laguna_early_serial_setup(void)
353 #ifdef CONFIG_SERIAL_8250_CONSOLE
354 static struct uart_port laguna_serial_port
= {
355 .membase
= (void __iomem
*)CNS3XXX_UART0_BASE_VIRT
,
356 .mapbase
= CNS3XXX_UART0_BASE
,
357 .irq
= IRQ_CNS3XXX_UART0
,
359 .flags
= UPF_BOOT_AUTOCONF
| UPF_FIXED_TYPE
,
367 early_serial_setup(&laguna_serial_port
);
371 static struct resource laguna_uart_resources
[] = {
373 .start
= CNS3XXX_UART0_BASE
,
374 .end
= CNS3XXX_UART0_BASE
+ SZ_4K
- 1,
375 .flags
= IORESOURCE_MEM
377 .start
= CNS3XXX_UART1_BASE
,
378 .end
= CNS3XXX_UART1_BASE
+ SZ_4K
- 1,
379 .flags
= IORESOURCE_MEM
381 .start
= CNS3XXX_UART2_BASE
,
382 .end
= CNS3XXX_UART2_BASE
+ SZ_4K
- 1,
383 .flags
= IORESOURCE_MEM
387 static struct plat_serial8250_port laguna_uart_data
[] = {
389 .mapbase
= (CNS3XXX_UART0_BASE
),
390 .irq
= IRQ_CNS3XXX_UART0
,
392 .flags
= UPF_BOOT_AUTOCONF
| UPF_FIXED_TYPE
| UPF_IOREMAP
,
397 .mapbase
= (CNS3XXX_UART1_BASE
),
398 .irq
= IRQ_CNS3XXX_UART1
,
400 .flags
= UPF_BOOT_AUTOCONF
| UPF_FIXED_TYPE
| UPF_IOREMAP
,
405 .mapbase
= (CNS3XXX_UART2_BASE
),
406 .irq
= IRQ_CNS3XXX_UART2
,
408 .flags
= UPF_BOOT_AUTOCONF
| UPF_FIXED_TYPE
| UPF_IOREMAP
,
416 static struct platform_device laguna_uart
= {
417 .name
= "serial8250",
418 .id
= PLAT8250_DEV_PLATFORM
,
419 .dev
.platform_data
= laguna_uart_data
,
421 .resource
= laguna_uart_resources
427 static struct resource cns3xxx_usb_ehci_resources
[] = {
429 .start
= CNS3XXX_USB_BASE
,
430 .end
= CNS3XXX_USB_BASE
+ SZ_16M
- 1,
431 .flags
= IORESOURCE_MEM
,
434 .start
= IRQ_CNS3XXX_USB_EHCI
,
435 .flags
= IORESOURCE_IRQ
,
439 static u64 cns3xxx_usb_ehci_dma_mask
= DMA_BIT_MASK(32);
441 static int csn3xxx_usb_power_on(struct platform_device
*pdev
)
444 * EHCI and OHCI share the same clock and power,
445 * resetting twice would cause the 1st controller been reset.
446 * Therefore only do power up at the first up device, and
447 * power down at the last down device.
449 * Set USB AHB INCR length to 16
451 if (atomic_inc_return(&usb_pwr_ref
) == 1) {
452 cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB
);
453 cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST
);
454 cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST
);
455 __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG
) | (0X2 << 24)),
456 MISC_CHIP_CONFIG_REG
);
462 static void csn3xxx_usb_power_off(struct platform_device
*pdev
)
465 * EHCI and OHCI share the same clock and power,
466 * resetting twice would cause the 1st controller been reset.
467 * Therefore only do power up at the first up device, and
468 * power down at the last down device.
470 if (atomic_dec_return(&usb_pwr_ref
) == 0)
471 cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST
);
474 static struct usb_ehci_pdata cns3xxx_usb_ehci_pdata
= {
475 .power_on
= csn3xxx_usb_power_on
,
476 .power_off
= csn3xxx_usb_power_off
,
479 static struct platform_device cns3xxx_usb_ehci_device
= {
480 .name
= "ehci-platform",
481 .num_resources
= ARRAY_SIZE(cns3xxx_usb_ehci_resources
),
482 .resource
= cns3xxx_usb_ehci_resources
,
484 .dma_mask
= &cns3xxx_usb_ehci_dma_mask
,
485 .coherent_dma_mask
= DMA_BIT_MASK(32),
486 .platform_data
= &cns3xxx_usb_ehci_pdata
,
490 static struct resource cns3xxx_usb_ohci_resources
[] = {
492 .start
= CNS3XXX_USB_OHCI_BASE
,
493 .end
= CNS3XXX_USB_OHCI_BASE
+ SZ_16M
- 1,
494 .flags
= IORESOURCE_MEM
,
497 .start
= IRQ_CNS3XXX_USB_OHCI
,
498 .flags
= IORESOURCE_IRQ
,
502 static u64 cns3xxx_usb_ohci_dma_mask
= DMA_BIT_MASK(32);
504 static struct usb_ohci_pdata cns3xxx_usb_ohci_pdata
= {
506 .power_on
= csn3xxx_usb_power_on
,
507 .power_off
= csn3xxx_usb_power_off
,
510 static struct platform_device cns3xxx_usb_ohci_device
= {
511 .name
= "ohci-platform",
512 .num_resources
= ARRAY_SIZE(cns3xxx_usb_ohci_resources
),
513 .resource
= cns3xxx_usb_ohci_resources
,
515 .dma_mask
= &cns3xxx_usb_ohci_dma_mask
,
516 .coherent_dma_mask
= DMA_BIT_MASK(32),
517 .platform_data
= &cns3xxx_usb_ohci_pdata
,
521 static struct resource cns3xxx_usb_otg_resources
[] = {
523 .start
= CNS3XXX_USBOTG_BASE
,
524 .end
= CNS3XXX_USBOTG_BASE
+ SZ_16M
- 1,
525 .flags
= IORESOURCE_MEM
,
528 .start
= IRQ_CNS3XXX_USB_OTG
,
529 .flags
= IORESOURCE_IRQ
,
533 static u64 cns3xxx_usb_otg_dma_mask
= DMA_BIT_MASK(32);
535 static struct platform_device cns3xxx_usb_otg_device
= {
537 .num_resources
= ARRAY_SIZE(cns3xxx_usb_otg_resources
),
538 .resource
= cns3xxx_usb_otg_resources
,
540 .dma_mask
= &cns3xxx_usb_otg_dma_mask
,
541 .coherent_dma_mask
= DMA_BIT_MASK(32),
548 static struct resource laguna_i2c_resource
[] = {
550 .start
= CNS3XXX_SSP_BASE
+ 0x20,
551 .end
= CNS3XXX_SSP_BASE
+ 0x3f,
552 .flags
= IORESOURCE_MEM
,
554 .start
= IRQ_CNS3XXX_I2C
,
555 .flags
= IORESOURCE_IRQ
,
559 static struct platform_device laguna_i2c_controller
= {
560 .name
= "cns3xxx-i2c",
562 .resource
= laguna_i2c_resource
,
565 static struct nvmem_device
*at24_nvmem
;
567 static void at24_setup(struct nvmem_device
*mem_acc
, void *context
)
571 at24_nvmem
= mem_acc
;
573 /* Read MAC addresses */
574 if (nvmem_device_read(at24_nvmem
, 0x100, 6, buf
) == 6)
575 memcpy(&laguna_net_data
.hwaddr
[0], buf
, ETH_ALEN
);
576 if (nvmem_device_read(at24_nvmem
, 0x106, 6, buf
) == 6)
577 memcpy(&laguna_net_data
.hwaddr
[1], buf
, ETH_ALEN
);
578 if (nvmem_device_read(at24_nvmem
, 0x10C, 6, buf
) == 6)
579 memcpy(&laguna_net_data
.hwaddr
[2], buf
, ETH_ALEN
);
580 if (nvmem_device_read(at24_nvmem
, 0x112, 6, buf
) == 6)
581 memcpy(&laguna_net_data
.hwaddr
[3], buf
, ETH_ALEN
);
583 /* Read out Model Information */
584 if (nvmem_device_read(at24_nvmem
, 0x130, 16, buf
) == 16)
585 memcpy(&laguna_info
.model
, buf
, 16);
586 if (nvmem_device_read(at24_nvmem
, 0x140, 1, buf
) == 1)
587 memcpy(&laguna_info
.nor_flash_size
, buf
, 1);
588 if (nvmem_device_read(at24_nvmem
, 0x141, 1, buf
) == 1)
589 memcpy(&laguna_info
.spi_flash_size
, buf
, 1);
590 if (nvmem_device_read(at24_nvmem
, 0x142, 4, buf
) == 4)
591 memcpy(&laguna_info
.config_bitmap
, buf
, 4);
592 if (nvmem_device_read(at24_nvmem
, 0x146, 4, buf
) == 4)
593 memcpy(&laguna_info
.config2_bitmap
, buf
, 4);
596 static struct at24_platform_data laguna_eeprom_info
= {
599 .flags
= AT24_FLAG_READONLY
,
603 static struct pca953x_platform_data laguna_pca_data
= {
608 static struct pca953x_platform_data laguna_pca2_data
= {
613 static struct i2c_board_info __initdata laguna_i2c_devices
[] = {
615 I2C_BOARD_INFO("pca9555", 0x23),
616 .platform_data
= &laguna_pca_data
,
618 I2C_BOARD_INFO("pca9555", 0x27),
619 .platform_data
= &laguna_pca2_data
,
621 I2C_BOARD_INFO("gsp", 0x29),
623 I2C_BOARD_INFO ("24c08",0x50),
624 .platform_data
= &laguna_eeprom_info
,
626 I2C_BOARD_INFO("ds1672", 0x68),
634 static struct resource laguna_watchdog_resources
[] = {
636 .start
= CNS3XXX_TC11MP_TWD_BASE
+ 0x100, // CPU0 watchdog
637 .end
= CNS3XXX_TC11MP_TWD_BASE
+ SZ_4K
- 1,
638 .flags
= IORESOURCE_MEM
,
642 static struct platform_device laguna_watchdog
= {
643 .name
= "mpcore_wdt",
644 .id
= PLATFORM_DEVID_NONE
,
645 .num_resources
= ARRAY_SIZE(laguna_watchdog_resources
),
646 .resource
= laguna_watchdog_resources
,
652 static struct pps_gpio_platform_data laguna_pps_data
= {
654 .gpio_label
= "GPS_PPS",
655 .assert_falling_edge
= 0,
659 static struct platform_device laguna_pps_device
= {
661 .id
= PLATFORM_DEVID_NONE
,
662 .dev
.platform_data
= &laguna_pps_data
,
669 static struct gpio laguna_gpio_gw2391
[] = {
670 { 0, GPIOF_IN
, "*GPS_PPS" },
671 { 1, GPIOF_IN
, "*GSC_IRQ#" },
672 { 2, GPIOF_IN
, "*USB_FAULT#" },
673 { 5, GPIOF_OUT_INIT_LOW
, "*USB0_PCI_SEL" },
674 { 6, GPIOF_OUT_INIT_HIGH
, "*USB_VBUS_EN" },
675 { 7, GPIOF_OUT_INIT_LOW
, "*USB1_PCI_SEL" },
676 { 8, GPIOF_OUT_INIT_HIGH
, "*PERST#" },
677 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN#" },
678 { 100, GPIOF_IN
, "*USER_PB#" },
679 { 103, GPIOF_OUT_INIT_HIGH
, "*V5_EN" },
680 { 108, GPIOF_IN
, "DIO0" },
681 { 109, GPIOF_IN
, "DIO1" },
682 { 110, GPIOF_IN
, "DIO2" },
683 { 111, GPIOF_IN
, "DIO3" },
684 { 112, GPIOF_IN
, "DIO4" },
687 static struct gpio laguna_gpio_gw2388
[] = {
688 { 0, GPIOF_IN
, "*GPS_PPS" },
689 { 1, GPIOF_IN
, "*GSC_IRQ#" },
690 { 3, GPIOF_IN
, "*USB_FAULT#" },
691 { 6, GPIOF_OUT_INIT_HIGH
, "*USB_VBUS_EN" },
692 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
693 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
694 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN" },
695 { 100, GPIOF_OUT_INIT_HIGH
, "*USER_PB#" },
696 { 108, GPIOF_IN
, "DIO0" },
697 { 109, GPIOF_IN
, "DIO1" },
698 { 110, GPIOF_IN
, "DIO2" },
699 { 111, GPIOF_IN
, "DIO3" },
700 { 112, GPIOF_IN
, "DIO4" },
703 static struct gpio laguna_gpio_gw2387
[] = {
704 { 0, GPIOF_IN
, "*GPS_PPS" },
705 { 1, GPIOF_IN
, "*GSC_IRQ#" },
706 { 2, GPIOF_IN
, "*USB_FAULT#" },
707 { 5, GPIOF_OUT_INIT_LOW
, "*USB_PCI_SEL" },
708 { 6, GPIOF_OUT_INIT_HIGH
, "*USB_VBUS_EN" },
709 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
710 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
711 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN" },
712 { 100, GPIOF_IN
, "*USER_PB#" },
713 { 103, GPIOF_OUT_INIT_HIGH
, "*V5_EN" },
714 { 108, GPIOF_IN
, "DIO0" },
715 { 109, GPIOF_IN
, "DIO1" },
716 { 110, GPIOF_IN
, "DIO2" },
717 { 111, GPIOF_IN
, "DIO3" },
718 { 112, GPIOF_IN
, "DIO4" },
719 { 113, GPIOF_IN
, "DIO5" },
722 static struct gpio laguna_gpio_gw2386
[] = {
723 { 0, GPIOF_IN
, "*GPS_PPS" },
724 { 2, GPIOF_IN
, "*USB_FAULT#" },
725 { 6, GPIOF_OUT_INIT_LOW
, "*USB_PCI_SEL" },
726 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
727 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
728 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN" },
729 { 108, GPIOF_IN
, "DIO0" },
730 { 109, GPIOF_IN
, "DIO1" },
731 { 110, GPIOF_IN
, "DIO2" },
732 { 111, GPIOF_IN
, "DIO3" },
733 { 112, GPIOF_IN
, "DIO4" },
734 { 113, GPIOF_IN
, "DIO5" },
737 static struct gpio laguna_gpio_gw2385
[] = {
738 { 0, GPIOF_IN
, "*GSC_IRQ#" },
739 { 1, GPIOF_OUT_INIT_HIGH
, "*USB_HST_VBUS_EN" },
740 { 2, GPIOF_IN
, "*USB_HST_FAULT#" },
741 { 5, GPIOF_IN
, "*USB_OTG_FAULT#" },
742 { 6, GPIOF_OUT_INIT_LOW
, "*USB_HST_PCI_SEL" },
743 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
744 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
745 { 9, GPIOF_OUT_INIT_LOW
, "*SER_EN" },
746 { 10, GPIOF_IN
, "*USER_PB#" },
747 { 11, GPIOF_OUT_INIT_HIGH
, "*PERST#" },
748 { 100, GPIOF_IN
, "*USER_PB#" },
749 { 103, GPIOF_OUT_INIT_HIGH
, "V5_EN" },
752 static struct gpio laguna_gpio_gw2384
[] = {
753 { 0, GPIOF_IN
, "*GSC_IRQ#" },
754 { 1, GPIOF_OUT_INIT_HIGH
, "*USB_HST_VBUS_EN" },
755 { 2, GPIOF_IN
, "*USB_HST_FAULT#" },
756 { 5, GPIOF_IN
, "*USB_OTG_FAULT#" },
757 { 6, GPIOF_OUT_INIT_LOW
, "*USB_HST_PCI_SEL" },
758 { 7, GPIOF_OUT_INIT_LOW
, "*GSM_SEL0" },
759 { 8, GPIOF_OUT_INIT_LOW
, "*GSM_SEL1" },
760 { 9, GPIOF_OUT_INIT_LOW
, "*FP_SER_EN" },
761 { 12, GPIOF_OUT_INIT_LOW
, "J10_DIOLED0" },
762 { 13, GPIOF_OUT_INIT_HIGH
, "*I2CMUX_RST#" },
763 { 14, GPIOF_OUT_INIT_LOW
, "J10_DIOLED1" },
764 { 15, GPIOF_OUT_INIT_LOW
, "J10_DIOLED2" },
765 { 100, GPIOF_IN
, "*USER_PB#" },
766 { 103, GPIOF_OUT_INIT_HIGH
, "V5_EN" },
767 { 108, GPIOF_IN
, "J9_DIOGSC0" },
770 static struct gpio laguna_gpio_gw2383
[] = {
771 { 0, GPIOF_IN
, "*GPS_PPS" },
772 { 1, GPIOF_IN
, "*GSC_IRQ#" },
773 { 2, GPIOF_OUT_INIT_HIGH
, "*PCIE_RST#" },
774 { 3, GPIOF_IN
, "GPIO0" },
775 { 8, GPIOF_IN
, "GPIO1" },
776 { 100, GPIOF_IN
, "DIO0" },
777 { 101, GPIOF_IN
, "DIO1" },
778 { 108, GPIOF_IN
, "*USER_PB#" },
781 static struct gpio laguna_gpio_gw2382
[] = {
782 { 0, GPIOF_IN
, "*GPS_PPS" },
783 { 1, GPIOF_IN
, "*GSC_IRQ#" },
784 { 2, GPIOF_OUT_INIT_HIGH
, "*PCIE_RST#" },
785 { 3, GPIOF_IN
, "GPIO0" },
786 { 4, GPIOF_IN
, "GPIO1" },
787 { 9, GPIOF_OUT_INIT_HIGH
, "*USB_VBUS_EN" },
788 { 10, GPIOF_OUT_INIT_HIGH
, "*USB_PCI_SEL#" },
789 { 100, GPIOF_IN
, "DIO0" },
790 { 101, GPIOF_IN
, "DIO1" },
791 { 108, GPIOF_IN
, "*USER_PB#" },
794 static struct gpio laguna_gpio_gw2380
[] = {
795 { 0, GPIOF_IN
, "*GPS_PPS" },
796 { 1, GPIOF_IN
, "*GSC_IRQ#" },
797 { 3, GPIOF_IN
, "GPIO0" },
798 { 8, GPIOF_IN
, "GPIO1" },
799 { 100, GPIOF_IN
, "DIO0" },
800 { 101, GPIOF_IN
, "DIO1" },
801 { 102, GPIOF_IN
, "DIO2" },
802 { 103, GPIOF_IN
, "DIO3" },
803 { 108, GPIOF_IN
, "*USER_PB#" },
809 static void __init
laguna_init(void)
814 clk
= clk_register_fixed_rate(NULL
, "cpu", NULL
,
816 cns3xxx_cpu_clock() * (1000000 / 8));
817 clk_register_clkdev(clk
, "cpu", NULL
);
819 platform_device_register(&laguna_watchdog
);
821 platform_device_register(&laguna_i2c_controller
);
823 /* Set I2C 0-3 drive strength to 21 mA */
824 reg
= MISC_IO_PAD_DRIVE_STRENGTH_CTRL_B
;
827 /* Enable SCL/SDA for I2C */
828 reg
= MISC_GPIOB_PIN_ENABLE_REG
;
829 *reg
|= BIT(12) | BIT(13);
831 /* Enable MMC/SD pins */
832 *reg
|= BIT(7) | BIT(8) | BIT(9) | BIT(10) | BIT(11);
834 cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C
);
835 cns3xxx_pwr_power_up(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C
);
836 cns3xxx_pwr_soft_rst(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C
);
838 cns3xxx_pwr_clk_en(CNS3XXX_PWR_CLK_EN(SPI_PCM_I2C
));
839 cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SPI_PCM_I2C
));
841 i2c_register_board_info(0, ARRAY_AND_SIZE(laguna_i2c_devices
));
843 pm_power_off
= cns3xxx_power_off
;
846 static struct map_desc laguna_io_desc
[] __initdata
= {
848 .virtual = CNS3XXX_UART0_BASE_VIRT
,
849 .pfn
= __phys_to_pfn(CNS3XXX_UART0_BASE
),
855 static void __init
laguna_map_io(void)
858 iotable_init(ARRAY_AND_SIZE(laguna_io_desc
));
859 laguna_early_serial_setup();
862 static int laguna_register_gpio(struct gpio
*array
, size_t num
)
867 for (i
= 0; i
< num
; i
++, array
++) {
868 const char *label
= array
->label
;
871 err
= gpio_request_one(array
->gpio
, array
->flags
, label
);
875 err
= gpio_export(array
->gpio
, array
->label
[0] != '*');
881 /* allow disabling of external isolated PCIe IRQs */
882 static int cns3xxx_pciextirq
= 1;
883 static int __init
cns3xxx_pciextirq_disable(char *s
)
885 cns3xxx_pciextirq
= 0;
888 __setup("noextirq", cns3xxx_pciextirq_disable
);
890 static int __init
laguna_pcie_init_irq(void)
892 u32 __iomem
*mem
= (void __iomem
*)(CNS3XXX_GPIOB_BASE_VIRT
+ 0x0004);
893 u32 reg
= (__raw_readl(mem
) >> 26) & 0xf;
895 IRQ_CNS3XXX_EXTERNAL_PIN0
,
896 IRQ_CNS3XXX_EXTERNAL_PIN1
,
897 IRQ_CNS3XXX_EXTERNAL_PIN2
,
901 if (!machine_is_gw2388())
904 /* Verify GPIOB[26:29] == 0001b indicating support for ext irqs */
905 if (cns3xxx_pciextirq
&& reg
!= 1)
906 cns3xxx_pciextirq
= 0;
908 if (cns3xxx_pciextirq
) {
909 printk("laguna: using isolated PCI interrupts:"
910 " irq%d/irq%d/irq%d/irq%d\n",
911 irqs
[0], irqs
[1], irqs
[2], irqs
[3]);
912 cns3xxx_pcie_set_irqs(0, irqs
);
914 printk("laguna: using shared PCI interrupts: irq%d\n",
915 IRQ_CNS3XXX_PCIE0_DEVICE
);
920 subsys_initcall(laguna_pcie_init_irq
);
922 static int __init
laguna_model_setup(void)
927 if (!machine_is_gw2388())
930 printk("Running on Gateworks Laguna %s\n", laguna_info
.model
);
931 cns3xxx_gpio_init( 0, 32, CNS3XXX_GPIOA_BASE_VIRT
, IRQ_CNS3XXX_GPIOA
,
935 * If pcie external interrupts are supported and desired
936 * configure IRQ types and configure pin function.
937 * Note that cns3xxx_pciextirq is enabled by default, but can be
938 * unset via the 'noextirq' kernel param or by laguna_pcie_init() if
939 * the baseboard model does not support this hardware feature.
941 if (cns3xxx_pciextirq
) {
942 mem
= (void __iomem
*)(CNS3XXX_MISC_BASE_VIRT
+ 0x0018);
943 reg
= __raw_readl(mem
);
944 /* GPIO26 is gpio, EXT_INT[0:2] not gpio func */
947 __raw_writel(reg
, mem
);
949 cns3xxx_gpio_init(32, 32, CNS3XXX_GPIOB_BASE_VIRT
,
950 IRQ_CNS3XXX_GPIOB
, NR_IRQS_CNS3XXX
+ 32);
952 irq_set_irq_type(154, IRQ_TYPE_LEVEL_LOW
);
953 irq_set_irq_type(93, IRQ_TYPE_LEVEL_HIGH
);
954 irq_set_irq_type(94, IRQ_TYPE_LEVEL_HIGH
);
955 irq_set_irq_type(95, IRQ_TYPE_LEVEL_HIGH
);
957 cns3xxx_gpio_init(32, 32, CNS3XXX_GPIOB_BASE_VIRT
,
958 IRQ_CNS3XXX_GPIOB
, NR_IRQS_CNS3XXX
+ 32);
961 if (strncmp(laguna_info
.model
, "GW", 2) == 0) {
962 if (laguna_info
.config_bitmap
& ETH0_LOAD
)
963 laguna_net_data
.ports
|= BIT(0);
964 if (laguna_info
.config_bitmap
& ETH1_LOAD
)
965 laguna_net_data
.ports
|= BIT(1);
966 if (laguna_info
.config_bitmap
& ETH2_LOAD
)
967 laguna_net_data
.ports
|= BIT(2);
968 if (laguna_net_data
.ports
)
969 platform_device_register(&laguna_net_device
);
971 if ((laguna_info
.config_bitmap
& SATA0_LOAD
) ||
972 (laguna_info
.config_bitmap
& SATA1_LOAD
))
975 if (laguna_info
.config_bitmap
& (USB0_LOAD
)) {
976 cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB
);
978 /* DRVVBUS pins share with GPIOA */
979 mem
= (void __iomem
*)(CNS3XXX_MISC_BASE_VIRT
+ 0x0014);
980 reg
= __raw_readl(mem
);
982 __raw_writel(reg
, mem
);
985 mem
= (void __iomem
*)(CNS3XXX_MISC_BASE_VIRT
+ 0x0808);
986 reg
= __raw_readl(mem
);
988 __raw_writel(reg
, mem
);
990 platform_device_register(&cns3xxx_usb_otg_device
);
993 if (laguna_info
.config_bitmap
& (USB1_LOAD
)) {
994 platform_device_register(&cns3xxx_usb_ehci_device
);
995 platform_device_register(&cns3xxx_usb_ohci_device
);
998 if (laguna_info
.config_bitmap
& (SD_LOAD
))
999 cns3xxx_sdhci_init();
1001 if (laguna_info
.config_bitmap
& (UART0_LOAD
))
1002 laguna_uart
.num_resources
= 1;
1003 if (laguna_info
.config_bitmap
& (UART1_LOAD
))
1004 laguna_uart
.num_resources
= 2;
1005 if (laguna_info
.config_bitmap
& (UART2_LOAD
))
1006 laguna_uart
.num_resources
= 3;
1007 platform_device_register(&laguna_uart
);
1009 if (laguna_info
.config2_bitmap
& (NOR_FLASH_LOAD
)) {
1010 laguna_nor_partitions
[2].size
=
1011 (SZ_4M
<< laguna_info
.nor_flash_size
) -
1012 laguna_nor_partitions
[2].offset
;
1013 laguna_nor_res
.end
= CNS3XXX_FLASH_BASE
+
1014 laguna_nor_partitions
[2].offset
+
1015 laguna_nor_partitions
[2].size
- 1;
1016 platform_device_register(&laguna_nor_pdev
);
1019 if (laguna_info
.config2_bitmap
& (SPI_FLASH_LOAD
)) {
1020 laguna_spi_partitions
[2].size
=
1021 (SZ_2M
<< laguna_info
.spi_flash_size
) -
1022 laguna_spi_partitions
[2].offset
;
1023 spi_register_board_info(ARRAY_AND_SIZE(laguna_spi_devices
));
1026 if ((laguna_info
.config_bitmap
& SPI0_LOAD
) ||
1027 (laguna_info
.config_bitmap
& SPI1_LOAD
))
1028 platform_device_register(&laguna_spi_controller
);
1030 if (laguna_info
.config2_bitmap
& GPS_LOAD
)
1031 platform_device_register(&laguna_pps_device
);
1034 * Do any model specific setup not known by the bitmap by matching
1035 * the first 6 characters of the model name
1038 if ( (strncmp(laguna_info
.model
, "GW2388", 6) == 0)
1039 || (strncmp(laguna_info
.model
, "GW2389", 6) == 0) )
1042 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2388
));
1044 laguna_gpio_leds_data
.num_leds
= 2;
1045 } else if (strncmp(laguna_info
.model
, "GW2387", 6) == 0) {
1047 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2387
));
1049 laguna_gpio_leds_data
.num_leds
= 2;
1050 } else if (strncmp(laguna_info
.model
, "GW2386", 6) == 0) {
1052 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2386
));
1054 laguna_gpio_leds_data
.num_leds
= 2;
1055 } else if (strncmp(laguna_info
.model
, "GW2385", 6) == 0) {
1057 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2385
));
1059 laguna_gpio_leds
[0].gpio
= 115;
1060 laguna_gpio_leds
[1].gpio
= 12;
1061 laguna_gpio_leds
[1].name
= "red";
1062 laguna_gpio_leds
[1].active_low
= 0,
1063 laguna_gpio_leds
[2].gpio
= 14;
1064 laguna_gpio_leds
[2].name
= "green";
1065 laguna_gpio_leds
[2].active_low
= 0,
1066 laguna_gpio_leds
[3].gpio
= 15;
1067 laguna_gpio_leds
[3].name
= "blue";
1068 laguna_gpio_leds
[3].active_low
= 0,
1069 laguna_gpio_leds_data
.num_leds
= 4;
1070 } else if ( (strncmp(laguna_info
.model
, "GW2384", 6) == 0)
1071 || (strncmp(laguna_info
.model
, "GW2394", 6) == 0) )
1074 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2384
));
1076 laguna_gpio_leds_data
.num_leds
= 1;
1077 } else if (strncmp(laguna_info
.model
, "GW2383", 6) == 0) {
1079 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2383
));
1081 laguna_gpio_leds
[0].gpio
= 107;
1082 laguna_gpio_leds_data
.num_leds
= 1;
1083 } else if (strncmp(laguna_info
.model
, "GW2382", 6) == 0) {
1085 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2382
));
1087 laguna_gpio_leds
[0].gpio
= 107;
1088 laguna_gpio_leds_data
.num_leds
= 1;
1089 } else if (strncmp(laguna_info
.model
, "GW2380", 6) == 0) {
1091 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2380
));
1093 laguna_gpio_leds
[0].gpio
= 107;
1094 laguna_gpio_leds
[1].gpio
= 106;
1095 laguna_gpio_leds_data
.num_leds
= 2;
1096 } else if ( (strncmp(laguna_info
.model
, "GW2391", 6) == 0)
1097 || (strncmp(laguna_info
.model
, "GW2393", 6) == 0) )
1100 laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2391
));
1102 laguna_gpio_leds_data
.num_leds
= 2;
1104 platform_device_register(&laguna_gpio_leds_device
);
1106 // Do some defaults here, not sure what yet
1110 late_initcall(laguna_model_setup
);
1112 MACHINE_START(GW2388
, "Gateworks Corporation Laguna Platform")
1113 .smp
= smp_ops(cns3xxx_smp_ops
),
1114 .atag_offset
= 0x100,
1115 .map_io
= laguna_map_io
,
1116 .init_irq
= cns3xxx_init_irq
,
1117 .init_time
= cns3xxx_timer_init
,
1118 .init_machine
= laguna_init
,
1119 .init_late
= cns3xxx_pcie_init_late
,
1120 .restart
= cns3xxx_restart
,