1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
290b8fc34SJaya Kumar /*
390b8fc34SJaya Kumar * linux/arch/arm/mach-pxa/gumstix.c
490b8fc34SJaya Kumar *
590b8fc34SJaya Kumar * Support for the Gumstix motherboards.
690b8fc34SJaya Kumar *
790b8fc34SJaya Kumar * Original Author: Craig Hughes
890b8fc34SJaya Kumar * Created: Feb 14, 2008
990b8fc34SJaya Kumar * Copyright: Craig Hughes
1090b8fc34SJaya Kumar *
1190b8fc34SJaya Kumar * Implemented based on lubbock.c by Nicolas Pitre and code from Craig
1290b8fc34SJaya Kumar * Hughes
1390b8fc34SJaya Kumar */
1490b8fc34SJaya Kumar
1590b8fc34SJaya Kumar #include <linux/module.h>
1690b8fc34SJaya Kumar #include <linux/kernel.h>
1790b8fc34SJaya Kumar #include <linux/init.h>
1890b8fc34SJaya Kumar #include <linux/platform_device.h>
1990b8fc34SJaya Kumar #include <linux/interrupt.h>
20d8ad7859SJaya Kumar #include <linux/delay.h>
2190b8fc34SJaya Kumar #include <linux/mtd/mtd.h>
2290b8fc34SJaya Kumar #include <linux/mtd/partitions.h>
23fdabc466SLinus Walleij #include <linux/gpio/machine.h>
24d8ad7859SJaya Kumar #include <linux/gpio.h>
25d8ad7859SJaya Kumar #include <linux/err.h>
26d8ad7859SJaya Kumar #include <linux/clk.h>
2790b8fc34SJaya Kumar
2890b8fc34SJaya Kumar #include <asm/setup.h>
29*a9ff6961SLinus Walleij #include <asm/page.h>
3090b8fc34SJaya Kumar #include <asm/mach-types.h>
3190b8fc34SJaya Kumar #include <asm/irq.h>
3287dfb311SMasahiro Yamada #include <linux/sizes.h>
3390b8fc34SJaya Kumar
3490b8fc34SJaya Kumar #include <asm/mach/arch.h>
3590b8fc34SJaya Kumar #include <asm/mach/map.h>
3690b8fc34SJaya Kumar #include <asm/mach/irq.h>
3790b8fc34SJaya Kumar #include <asm/mach/flash.h>
3851c62982SEric Miao
394c25c5d2SArnd Bergmann #include "pxa25x.h"
40293b2da1SArnd Bergmann #include <linux/platform_data/mmc-pxamci.h>
414c25c5d2SArnd Bergmann #include "udc.h"
424c25c5d2SArnd Bergmann #include "gumstix.h"
4390b8fc34SJaya Kumar
4490b8fc34SJaya Kumar #include "generic.h"
4590b8fc34SJaya Kumar
4690b8fc34SJaya Kumar static struct resource flash_resource = {
4790b8fc34SJaya Kumar .start = 0x00000000,
4890b8fc34SJaya Kumar .end = SZ_64M - 1,
4990b8fc34SJaya Kumar .flags = IORESOURCE_MEM,
5090b8fc34SJaya Kumar };
5190b8fc34SJaya Kumar
5290b8fc34SJaya Kumar static struct mtd_partition gumstix_partitions[] = {
5390b8fc34SJaya Kumar {
5490b8fc34SJaya Kumar .name = "Bootloader",
5590b8fc34SJaya Kumar .size = 0x00040000,
5690b8fc34SJaya Kumar .offset = 0,
5790b8fc34SJaya Kumar .mask_flags = MTD_WRITEABLE /* force read-only */
5890b8fc34SJaya Kumar } , {
5990b8fc34SJaya Kumar .name = "rootfs",
6090b8fc34SJaya Kumar .size = MTDPART_SIZ_FULL,
6190b8fc34SJaya Kumar .offset = MTDPART_OFS_APPEND
6290b8fc34SJaya Kumar }
6390b8fc34SJaya Kumar };
6490b8fc34SJaya Kumar
6590b8fc34SJaya Kumar static struct flash_platform_data gumstix_flash_data = {
6690b8fc34SJaya Kumar .map_name = "cfi_probe",
6790b8fc34SJaya Kumar .parts = gumstix_partitions,
6890b8fc34SJaya Kumar .nr_parts = ARRAY_SIZE(gumstix_partitions),
6990b8fc34SJaya Kumar .width = 2,
7090b8fc34SJaya Kumar };
7190b8fc34SJaya Kumar
7290b8fc34SJaya Kumar static struct platform_device gumstix_flash_device = {
7390b8fc34SJaya Kumar .name = "pxa2xx-flash",
7490b8fc34SJaya Kumar .id = 0,
7590b8fc34SJaya Kumar .dev = {
7690b8fc34SJaya Kumar .platform_data = &gumstix_flash_data,
7790b8fc34SJaya Kumar },
7890b8fc34SJaya Kumar .resource = &flash_resource,
7990b8fc34SJaya Kumar .num_resources = 1,
8090b8fc34SJaya Kumar };
8190b8fc34SJaya Kumar
8290b8fc34SJaya Kumar static struct platform_device *devices[] __initdata = {
8390b8fc34SJaya Kumar &gumstix_flash_device,
8490b8fc34SJaya Kumar };
8590b8fc34SJaya Kumar
8690b8fc34SJaya Kumar #ifdef CONFIG_MMC_PXA
8790b8fc34SJaya Kumar static struct pxamci_platform_data gumstix_mci_platform_data = {
8890b8fc34SJaya Kumar .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
8990b8fc34SJaya Kumar };
9090b8fc34SJaya Kumar
gumstix_mmc_init(void)9190b8fc34SJaya Kumar static void __init gumstix_mmc_init(void)
9290b8fc34SJaya Kumar {
9390b8fc34SJaya Kumar pxa_set_mci_info(&gumstix_mci_platform_data);
9490b8fc34SJaya Kumar }
9590b8fc34SJaya Kumar #else
gumstix_mmc_init(void)9690b8fc34SJaya Kumar static void __init gumstix_mmc_init(void)
9790b8fc34SJaya Kumar {
98d8ad7859SJaya Kumar pr_debug("Gumstix mmc disabled\n");
9990b8fc34SJaya Kumar }
10090b8fc34SJaya Kumar #endif
10190b8fc34SJaya Kumar
102c0a39151SHaojian Zhuang #ifdef CONFIG_USB_PXA25X
103fdabc466SLinus Walleij static struct gpiod_lookup_table gumstix_gpio_vbus_gpiod_table = {
104fdabc466SLinus Walleij .dev_id = "gpio-vbus",
105fdabc466SLinus Walleij .table = {
106fdabc466SLinus Walleij GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOn,
107fdabc466SLinus Walleij "vbus", GPIO_ACTIVE_HIGH),
108fdabc466SLinus Walleij GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOx,
109fdabc466SLinus Walleij "pullup", GPIO_ACTIVE_HIGH),
110fdabc466SLinus Walleij { },
111fdabc466SLinus Walleij },
11290b8fc34SJaya Kumar };
11390b8fc34SJaya Kumar
114d19f4cbdSDmitry Eremin-Solenikov static struct platform_device gumstix_gpio_vbus = {
115d19f4cbdSDmitry Eremin-Solenikov .name = "gpio-vbus",
116d19f4cbdSDmitry Eremin-Solenikov .id = -1,
117d19f4cbdSDmitry Eremin-Solenikov };
118d19f4cbdSDmitry Eremin-Solenikov
gumstix_udc_init(void)11990b8fc34SJaya Kumar static void __init gumstix_udc_init(void)
12090b8fc34SJaya Kumar {
121fdabc466SLinus Walleij gpiod_add_lookup_table(&gumstix_gpio_vbus_gpiod_table);
122d19f4cbdSDmitry Eremin-Solenikov platform_device_register(&gumstix_gpio_vbus);
12390b8fc34SJaya Kumar }
12490b8fc34SJaya Kumar #else
gumstix_udc_init(void)12590b8fc34SJaya Kumar static void gumstix_udc_init(void)
12690b8fc34SJaya Kumar {
127d8ad7859SJaya Kumar pr_debug("Gumstix udc is disabled\n");
12890b8fc34SJaya Kumar }
12990b8fc34SJaya Kumar #endif
13090b8fc34SJaya Kumar
131d8ad7859SJaya Kumar #ifdef CONFIG_BT
132d8ad7859SJaya Kumar /* Normally, the bootloader would have enabled this 32kHz clock but many
133d8ad7859SJaya Kumar ** boards still have u-boot 1.1.4 so we check if it has been turned on and
134d8ad7859SJaya Kumar ** if not, we turn it on with a warning message. */
gumstix_setup_bt_clock(void)135d8ad7859SJaya Kumar static void gumstix_setup_bt_clock(void)
136d8ad7859SJaya Kumar {
137d8ad7859SJaya Kumar int timeout = 500;
138d8ad7859SJaya Kumar
139ea7743e2SArnd Bergmann if (!(readl(OSCC) & OSCC_OOK))
1407b472ac7SJoe Perches pr_warn("32kHz clock was not on. Bootloader may need to be updated\n");
141d8ad7859SJaya Kumar else
142d8ad7859SJaya Kumar return;
143d8ad7859SJaya Kumar
144ea7743e2SArnd Bergmann writel(readl(OSCC) | OSCC_OON, OSCC);
145d8ad7859SJaya Kumar do {
146ea7743e2SArnd Bergmann if (readl(OSCC) & OSCC_OOK)
147d8ad7859SJaya Kumar break;
148d8ad7859SJaya Kumar udelay(1);
149d8ad7859SJaya Kumar } while (--timeout);
150d8ad7859SJaya Kumar if (!timeout)
151d8ad7859SJaya Kumar pr_err("Failed to start 32kHz clock\n");
152d8ad7859SJaya Kumar }
153d8ad7859SJaya Kumar
gumstix_bluetooth_init(void)154d8ad7859SJaya Kumar static void __init gumstix_bluetooth_init(void)
155d8ad7859SJaya Kumar {
156d8ad7859SJaya Kumar int err;
157d8ad7859SJaya Kumar
158d8ad7859SJaya Kumar gumstix_setup_bt_clock();
159d8ad7859SJaya Kumar
160d8ad7859SJaya Kumar err = gpio_request(GPIO_GUMSTIX_BTRESET, "BTRST");
161d8ad7859SJaya Kumar if (err) {
162d8ad7859SJaya Kumar pr_err("gumstix: failed request gpio for bluetooth reset\n");
163d8ad7859SJaya Kumar return;
164d8ad7859SJaya Kumar }
165d8ad7859SJaya Kumar
166d8ad7859SJaya Kumar err = gpio_direction_output(GPIO_GUMSTIX_BTRESET, 1);
167d8ad7859SJaya Kumar if (err) {
168d8ad7859SJaya Kumar pr_err("gumstix: can't reset bluetooth\n");
169d8ad7859SJaya Kumar return;
170d8ad7859SJaya Kumar }
171d8ad7859SJaya Kumar gpio_set_value(GPIO_GUMSTIX_BTRESET, 0);
172d8ad7859SJaya Kumar udelay(100);
173d8ad7859SJaya Kumar gpio_set_value(GPIO_GUMSTIX_BTRESET, 1);
174d8ad7859SJaya Kumar }
175d8ad7859SJaya Kumar #else
gumstix_bluetooth_init(void)176d8ad7859SJaya Kumar static void gumstix_bluetooth_init(void)
177d8ad7859SJaya Kumar {
178d8ad7859SJaya Kumar pr_debug("Gumstix Bluetooth is disabled\n");
179d8ad7859SJaya Kumar }
180d8ad7859SJaya Kumar #endif
181d8ad7859SJaya Kumar
182d8ad7859SJaya Kumar static unsigned long gumstix_pin_config[] __initdata = {
183d8ad7859SJaya Kumar GPIO12_32KHz,
184d8ad7859SJaya Kumar /* BTUART */
185d8ad7859SJaya Kumar GPIO42_HWUART_RXD,
186d8ad7859SJaya Kumar GPIO43_HWUART_TXD,
187d8ad7859SJaya Kumar GPIO44_HWUART_CTS,
188d8ad7859SJaya Kumar GPIO45_HWUART_RTS,
189d8ad7859SJaya Kumar /* MMC */
190d8ad7859SJaya Kumar GPIO6_MMC_CLK,
191d8ad7859SJaya Kumar GPIO53_MMC_CLK,
192d8ad7859SJaya Kumar GPIO8_MMC_CS0,
193d8ad7859SJaya Kumar };
194d8ad7859SJaya Kumar
am200_init(void)1953332b0c1SJaya Kumar int __attribute__((weak)) am200_init(void)
1963332b0c1SJaya Kumar {
1973332b0c1SJaya Kumar return 0;
1983332b0c1SJaya Kumar }
1993332b0c1SJaya Kumar
am300_init(void)2004ce255c1SJaya Kumar int __attribute__((weak)) am300_init(void)
2014ce255c1SJaya Kumar {
2024ce255c1SJaya Kumar return 0;
2034ce255c1SJaya Kumar }
2044ce255c1SJaya Kumar
carrier_board_init(void)2053332b0c1SJaya Kumar static void __init carrier_board_init(void)
2063332b0c1SJaya Kumar {
2073332b0c1SJaya Kumar /*
2083332b0c1SJaya Kumar * put carrier/expansion board init here if
2093332b0c1SJaya Kumar * they cannot be detected programatically
2103332b0c1SJaya Kumar */
2113332b0c1SJaya Kumar am200_init();
2124ce255c1SJaya Kumar am300_init();
2133332b0c1SJaya Kumar }
2143332b0c1SJaya Kumar
gumstix_init(void)21590b8fc34SJaya Kumar static void __init gumstix_init(void)
21690b8fc34SJaya Kumar {
217d8ad7859SJaya Kumar pxa2xx_mfp_config(ARRAY_AND_SIZE(gumstix_pin_config));
218d8ad7859SJaya Kumar
219cc155c6fSRussell King pxa_set_ffuart_info(NULL);
220cc155c6fSRussell King pxa_set_btuart_info(NULL);
221cc155c6fSRussell King pxa_set_stuart_info(NULL);
222cc155c6fSRussell King pxa_set_hwuart_info(NULL);
223cc155c6fSRussell King
224d8ad7859SJaya Kumar gumstix_bluetooth_init();
22590b8fc34SJaya Kumar gumstix_udc_init();
22690b8fc34SJaya Kumar gumstix_mmc_init();
22790b8fc34SJaya Kumar (void) platform_add_devices(devices, ARRAY_SIZE(devices));
2283332b0c1SJaya Kumar carrier_board_init();
22990b8fc34SJaya Kumar }
23090b8fc34SJaya Kumar
23190b8fc34SJaya Kumar MACHINE_START(GUMSTIX, "Gumstix")
2327375aba6SNicolas Pitre .atag_offset = 0x100, /* match u-boot bi_boot_params */
233851982c1SMarek Vasut .map_io = pxa25x_map_io,
2344e611091SRob Herring .nr_irqs = PXA_NR_IRQS,
23590b8fc34SJaya Kumar .init_irq = pxa25x_init_irq,
2366bb27d73SStephen Warren .init_time = pxa_timer_init,
23790b8fc34SJaya Kumar .init_machine = gumstix_init,
238271a74fcSRussell King .restart = pxa_restart,
23990b8fc34SJaya Kumar MACHINE_END
240