xref: /openbmc/linux/arch/arm/mach-pxa/gumstix.c (revision 7b472ac75689af196d868b3f2322edb44b8096d3)
190b8fc34SJaya Kumar /*
290b8fc34SJaya Kumar  *  linux/arch/arm/mach-pxa/gumstix.c
390b8fc34SJaya Kumar  *
490b8fc34SJaya Kumar  *  Support for the Gumstix motherboards.
590b8fc34SJaya Kumar  *
690b8fc34SJaya Kumar  *  Original Author:	Craig Hughes
790b8fc34SJaya Kumar  *  Created:	Feb 14, 2008
890b8fc34SJaya Kumar  *  Copyright:	Craig Hughes
990b8fc34SJaya Kumar  *
1090b8fc34SJaya Kumar  *  This program is free software; you can redistribute it and/or modify
1190b8fc34SJaya Kumar  *  it under the terms of the GNU General Public License version 2 as
1290b8fc34SJaya Kumar  *  published by the Free Software Foundation.
1390b8fc34SJaya Kumar  *
1490b8fc34SJaya Kumar  *  Implemented based on lubbock.c by Nicolas Pitre and code from Craig
1590b8fc34SJaya Kumar  *  Hughes
1690b8fc34SJaya Kumar  */
1790b8fc34SJaya Kumar 
1890b8fc34SJaya Kumar #include <linux/module.h>
1990b8fc34SJaya Kumar #include <linux/kernel.h>
2090b8fc34SJaya Kumar #include <linux/init.h>
2190b8fc34SJaya Kumar #include <linux/platform_device.h>
2290b8fc34SJaya Kumar #include <linux/interrupt.h>
23d8ad7859SJaya Kumar #include <linux/delay.h>
2490b8fc34SJaya Kumar #include <linux/mtd/mtd.h>
2590b8fc34SJaya Kumar #include <linux/mtd/partitions.h>
26d8ad7859SJaya Kumar #include <linux/gpio.h>
27d8ad7859SJaya Kumar #include <linux/err.h>
28d8ad7859SJaya Kumar #include <linux/clk.h>
29d19f4cbdSDmitry Eremin-Solenikov #include <linux/usb/gpio_vbus.h>
3090b8fc34SJaya Kumar 
3190b8fc34SJaya Kumar #include <asm/setup.h>
3290b8fc34SJaya Kumar #include <asm/memory.h>
3390b8fc34SJaya Kumar #include <asm/mach-types.h>
34a09e64fbSRussell King #include <mach/hardware.h>
3590b8fc34SJaya Kumar #include <asm/irq.h>
3690b8fc34SJaya Kumar #include <asm/sizes.h>
3790b8fc34SJaya Kumar 
3890b8fc34SJaya Kumar #include <asm/mach/arch.h>
3990b8fc34SJaya Kumar #include <asm/mach/map.h>
4090b8fc34SJaya Kumar #include <asm/mach/irq.h>
4190b8fc34SJaya Kumar #include <asm/mach/flash.h>
4251c62982SEric Miao 
4351c62982SEric Miao #include <mach/pxa25x.h>
44293b2da1SArnd Bergmann #include <linux/platform_data/mmc-pxamci.h>
45a09e64fbSRussell King #include <mach/udc.h>
46a09e64fbSRussell King #include <mach/gumstix.h>
4790b8fc34SJaya Kumar 
4890b8fc34SJaya Kumar #include "generic.h"
4990b8fc34SJaya Kumar 
5090b8fc34SJaya Kumar static struct resource flash_resource = {
5190b8fc34SJaya Kumar 	.start	= 0x00000000,
5290b8fc34SJaya Kumar 	.end	= SZ_64M - 1,
5390b8fc34SJaya Kumar 	.flags	= IORESOURCE_MEM,
5490b8fc34SJaya Kumar };
5590b8fc34SJaya Kumar 
5690b8fc34SJaya Kumar static struct mtd_partition gumstix_partitions[] = {
5790b8fc34SJaya Kumar 	{
5890b8fc34SJaya Kumar 		.name =		"Bootloader",
5990b8fc34SJaya Kumar 		.size =		0x00040000,
6090b8fc34SJaya Kumar 		.offset =	0,
6190b8fc34SJaya Kumar 		.mask_flags =	MTD_WRITEABLE  /* force read-only */
6290b8fc34SJaya Kumar 	} , {
6390b8fc34SJaya Kumar 		.name =		"rootfs",
6490b8fc34SJaya Kumar 		.size =		MTDPART_SIZ_FULL,
6590b8fc34SJaya Kumar 		.offset =	MTDPART_OFS_APPEND
6690b8fc34SJaya Kumar 	}
6790b8fc34SJaya Kumar };
6890b8fc34SJaya Kumar 
6990b8fc34SJaya Kumar static struct flash_platform_data gumstix_flash_data = {
7090b8fc34SJaya Kumar 	.map_name	= "cfi_probe",
7190b8fc34SJaya Kumar 	.parts		= gumstix_partitions,
7290b8fc34SJaya Kumar 	.nr_parts	= ARRAY_SIZE(gumstix_partitions),
7390b8fc34SJaya Kumar 	.width		= 2,
7490b8fc34SJaya Kumar };
7590b8fc34SJaya Kumar 
7690b8fc34SJaya Kumar static struct platform_device gumstix_flash_device = {
7790b8fc34SJaya Kumar 	.name		= "pxa2xx-flash",
7890b8fc34SJaya Kumar 	.id		= 0,
7990b8fc34SJaya Kumar 	.dev = {
8090b8fc34SJaya Kumar 		.platform_data = &gumstix_flash_data,
8190b8fc34SJaya Kumar 	},
8290b8fc34SJaya Kumar 	.resource = &flash_resource,
8390b8fc34SJaya Kumar 	.num_resources = 1,
8490b8fc34SJaya Kumar };
8590b8fc34SJaya Kumar 
8690b8fc34SJaya Kumar static struct platform_device *devices[] __initdata = {
8790b8fc34SJaya Kumar 	&gumstix_flash_device,
8890b8fc34SJaya Kumar };
8990b8fc34SJaya Kumar 
9090b8fc34SJaya Kumar #ifdef CONFIG_MMC_PXA
9190b8fc34SJaya Kumar static struct pxamci_platform_data gumstix_mci_platform_data = {
9290b8fc34SJaya Kumar 	.ocr_mask		= MMC_VDD_32_33|MMC_VDD_33_34,
937a648256SRobert Jarzmik 	.gpio_card_detect 	= -1,
947a648256SRobert Jarzmik 	.gpio_card_ro		= -1,
957a648256SRobert Jarzmik 	.gpio_power		= -1,
9690b8fc34SJaya Kumar };
9790b8fc34SJaya Kumar 
9890b8fc34SJaya Kumar static void __init gumstix_mmc_init(void)
9990b8fc34SJaya Kumar {
10090b8fc34SJaya Kumar 	pxa_set_mci_info(&gumstix_mci_platform_data);
10190b8fc34SJaya Kumar }
10290b8fc34SJaya Kumar #else
10390b8fc34SJaya Kumar static void __init gumstix_mmc_init(void)
10490b8fc34SJaya Kumar {
105d8ad7859SJaya Kumar 	pr_debug("Gumstix mmc disabled\n");
10690b8fc34SJaya Kumar }
10790b8fc34SJaya Kumar #endif
10890b8fc34SJaya Kumar 
109c0a39151SHaojian Zhuang #ifdef CONFIG_USB_PXA25X
110d19f4cbdSDmitry Eremin-Solenikov static struct gpio_vbus_mach_info gumstix_udc_info = {
11190b8fc34SJaya Kumar 	.gpio_vbus		= GPIO_GUMSTIX_USB_GPIOn,
11290b8fc34SJaya Kumar 	.gpio_pullup		= GPIO_GUMSTIX_USB_GPIOx,
11390b8fc34SJaya Kumar };
11490b8fc34SJaya Kumar 
115d19f4cbdSDmitry Eremin-Solenikov static struct platform_device gumstix_gpio_vbus = {
116d19f4cbdSDmitry Eremin-Solenikov 	.name	= "gpio-vbus",
117d19f4cbdSDmitry Eremin-Solenikov 	.id	= -1,
118d19f4cbdSDmitry Eremin-Solenikov 	.dev	= {
119d19f4cbdSDmitry Eremin-Solenikov 		.platform_data	= &gumstix_udc_info,
120d19f4cbdSDmitry Eremin-Solenikov 	},
121d19f4cbdSDmitry Eremin-Solenikov };
122d19f4cbdSDmitry Eremin-Solenikov 
12390b8fc34SJaya Kumar static void __init gumstix_udc_init(void)
12490b8fc34SJaya Kumar {
125d19f4cbdSDmitry Eremin-Solenikov 	platform_device_register(&gumstix_gpio_vbus);
12690b8fc34SJaya Kumar }
12790b8fc34SJaya Kumar #else
12890b8fc34SJaya Kumar static void gumstix_udc_init(void)
12990b8fc34SJaya Kumar {
130d8ad7859SJaya Kumar 	pr_debug("Gumstix udc is disabled\n");
13190b8fc34SJaya Kumar }
13290b8fc34SJaya Kumar #endif
13390b8fc34SJaya Kumar 
134d8ad7859SJaya Kumar #ifdef CONFIG_BT
135d8ad7859SJaya Kumar /* Normally, the bootloader would have enabled this 32kHz clock but many
136d8ad7859SJaya Kumar ** boards still have u-boot 1.1.4 so we check if it has been turned on and
137d8ad7859SJaya Kumar ** if not, we turn it on with a warning message. */
138d8ad7859SJaya Kumar static void gumstix_setup_bt_clock(void)
139d8ad7859SJaya Kumar {
140d8ad7859SJaya Kumar 	int timeout = 500;
141d8ad7859SJaya Kumar 
142d8ad7859SJaya Kumar 	if (!(OSCC & OSCC_OOK))
143*7b472ac7SJoe Perches 		pr_warn("32kHz clock was not on. Bootloader may need to be updated\n");
144d8ad7859SJaya Kumar 	else
145d8ad7859SJaya Kumar 		return;
146d8ad7859SJaya Kumar 
147d8ad7859SJaya Kumar 	OSCC |= OSCC_OON;
148d8ad7859SJaya Kumar 	do {
149d8ad7859SJaya Kumar 		if (OSCC & OSCC_OOK)
150d8ad7859SJaya Kumar 			break;
151d8ad7859SJaya Kumar 		udelay(1);
152d8ad7859SJaya Kumar 	} while (--timeout);
153d8ad7859SJaya Kumar 	if (!timeout)
154d8ad7859SJaya Kumar 		pr_err("Failed to start 32kHz clock\n");
155d8ad7859SJaya Kumar }
156d8ad7859SJaya Kumar 
157d8ad7859SJaya Kumar static void __init gumstix_bluetooth_init(void)
158d8ad7859SJaya Kumar {
159d8ad7859SJaya Kumar 	int err;
160d8ad7859SJaya Kumar 
161d8ad7859SJaya Kumar 	gumstix_setup_bt_clock();
162d8ad7859SJaya Kumar 
163d8ad7859SJaya Kumar 	err = gpio_request(GPIO_GUMSTIX_BTRESET, "BTRST");
164d8ad7859SJaya Kumar 	if (err) {
165d8ad7859SJaya Kumar 		pr_err("gumstix: failed request gpio for bluetooth reset\n");
166d8ad7859SJaya Kumar 		return;
167d8ad7859SJaya Kumar 	}
168d8ad7859SJaya Kumar 
169d8ad7859SJaya Kumar 	err = gpio_direction_output(GPIO_GUMSTIX_BTRESET, 1);
170d8ad7859SJaya Kumar 	if (err) {
171d8ad7859SJaya Kumar 		pr_err("gumstix: can't reset bluetooth\n");
172d8ad7859SJaya Kumar 		return;
173d8ad7859SJaya Kumar 	}
174d8ad7859SJaya Kumar 	gpio_set_value(GPIO_GUMSTIX_BTRESET, 0);
175d8ad7859SJaya Kumar 	udelay(100);
176d8ad7859SJaya Kumar 	gpio_set_value(GPIO_GUMSTIX_BTRESET, 1);
177d8ad7859SJaya Kumar }
178d8ad7859SJaya Kumar #else
179d8ad7859SJaya Kumar static void gumstix_bluetooth_init(void)
180d8ad7859SJaya Kumar {
181d8ad7859SJaya Kumar 	pr_debug("Gumstix Bluetooth is disabled\n");
182d8ad7859SJaya Kumar }
183d8ad7859SJaya Kumar #endif
184d8ad7859SJaya Kumar 
185d8ad7859SJaya Kumar static unsigned long gumstix_pin_config[] __initdata = {
186d8ad7859SJaya Kumar 	GPIO12_32KHz,
187d8ad7859SJaya Kumar 	/* BTUART */
188d8ad7859SJaya Kumar 	GPIO42_HWUART_RXD,
189d8ad7859SJaya Kumar 	GPIO43_HWUART_TXD,
190d8ad7859SJaya Kumar 	GPIO44_HWUART_CTS,
191d8ad7859SJaya Kumar 	GPIO45_HWUART_RTS,
192d8ad7859SJaya Kumar 	/* MMC */
193d8ad7859SJaya Kumar 	GPIO6_MMC_CLK,
194d8ad7859SJaya Kumar 	GPIO53_MMC_CLK,
195d8ad7859SJaya Kumar 	GPIO8_MMC_CS0,
196d8ad7859SJaya Kumar };
197d8ad7859SJaya Kumar 
1983332b0c1SJaya Kumar int __attribute__((weak)) am200_init(void)
1993332b0c1SJaya Kumar {
2003332b0c1SJaya Kumar 	return 0;
2013332b0c1SJaya Kumar }
2023332b0c1SJaya Kumar 
2034ce255c1SJaya Kumar int __attribute__((weak)) am300_init(void)
2044ce255c1SJaya Kumar {
2054ce255c1SJaya Kumar 	return 0;
2064ce255c1SJaya Kumar }
2074ce255c1SJaya Kumar 
2083332b0c1SJaya Kumar static void __init carrier_board_init(void)
2093332b0c1SJaya Kumar {
2103332b0c1SJaya Kumar 	/*
2113332b0c1SJaya Kumar 	 * put carrier/expansion board init here if
2123332b0c1SJaya Kumar 	 * they cannot be detected programatically
2133332b0c1SJaya Kumar 	 */
2143332b0c1SJaya Kumar 	am200_init();
2154ce255c1SJaya Kumar 	am300_init();
2163332b0c1SJaya Kumar }
2173332b0c1SJaya Kumar 
21890b8fc34SJaya Kumar static void __init gumstix_init(void)
21990b8fc34SJaya Kumar {
220d8ad7859SJaya Kumar 	pxa2xx_mfp_config(ARRAY_AND_SIZE(gumstix_pin_config));
221d8ad7859SJaya Kumar 
222cc155c6fSRussell King 	pxa_set_ffuart_info(NULL);
223cc155c6fSRussell King 	pxa_set_btuart_info(NULL);
224cc155c6fSRussell King 	pxa_set_stuart_info(NULL);
225cc155c6fSRussell King 	pxa_set_hwuart_info(NULL);
226cc155c6fSRussell King 
227d8ad7859SJaya Kumar 	gumstix_bluetooth_init();
22890b8fc34SJaya Kumar 	gumstix_udc_init();
22990b8fc34SJaya Kumar 	gumstix_mmc_init();
23090b8fc34SJaya Kumar 	(void) platform_add_devices(devices, ARRAY_SIZE(devices));
2313332b0c1SJaya Kumar 	carrier_board_init();
23290b8fc34SJaya Kumar }
23390b8fc34SJaya Kumar 
23490b8fc34SJaya Kumar MACHINE_START(GUMSTIX, "Gumstix")
2357375aba6SNicolas Pitre 	.atag_offset	= 0x100, /* match u-boot bi_boot_params */
236851982c1SMarek Vasut 	.map_io		= pxa25x_map_io,
2374e611091SRob Herring 	.nr_irqs	= PXA_NR_IRQS,
23890b8fc34SJaya Kumar 	.init_irq	= pxa25x_init_irq,
2398a97ae2fSEric Miao 	.handle_irq	= pxa25x_handle_irq,
2406bb27d73SStephen Warren 	.init_time	= pxa_timer_init,
24190b8fc34SJaya Kumar 	.init_machine	= gumstix_init,
242271a74fcSRussell King 	.restart	= pxa_restart,
24390b8fc34SJaya Kumar MACHINE_END
244