xref: /openbmc/linux/arch/arm/mach-pxa/gumstix.c (revision 3332b0c17969d91d8868d2d003e685c420d84262)
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>
2990b8fc34SJaya Kumar 
3090b8fc34SJaya Kumar #include <asm/setup.h>
3190b8fc34SJaya Kumar #include <asm/memory.h>
3290b8fc34SJaya Kumar #include <asm/mach-types.h>
33a09e64fbSRussell King #include <mach/hardware.h>
3490b8fc34SJaya Kumar #include <asm/irq.h>
3590b8fc34SJaya Kumar #include <asm/sizes.h>
3690b8fc34SJaya Kumar 
3790b8fc34SJaya Kumar #include <asm/mach/arch.h>
3890b8fc34SJaya Kumar #include <asm/mach/map.h>
3990b8fc34SJaya Kumar #include <asm/mach/irq.h>
4090b8fc34SJaya Kumar #include <asm/mach/flash.h>
41a09e64fbSRussell King #include <mach/mmc.h>
42a09e64fbSRussell King #include <mach/udc.h>
43a09e64fbSRussell King #include <mach/gumstix.h>
4490b8fc34SJaya Kumar 
45a09e64fbSRussell King #include <mach/pxa-regs.h>
46a09e64fbSRussell King #include <mach/pxa2xx-regs.h>
47d8ad7859SJaya Kumar #include <mach/mfp-pxa25x.h>
4890b8fc34SJaya Kumar 
4990b8fc34SJaya Kumar #include "generic.h"
5090b8fc34SJaya Kumar 
5190b8fc34SJaya Kumar static struct resource flash_resource = {
5290b8fc34SJaya Kumar 	.start	= 0x00000000,
5390b8fc34SJaya Kumar 	.end	= SZ_64M - 1,
5490b8fc34SJaya Kumar 	.flags	= IORESOURCE_MEM,
5590b8fc34SJaya Kumar };
5690b8fc34SJaya Kumar 
5790b8fc34SJaya Kumar static struct mtd_partition gumstix_partitions[] = {
5890b8fc34SJaya Kumar 	{
5990b8fc34SJaya Kumar 		.name =		"Bootloader",
6090b8fc34SJaya Kumar 		.size =		0x00040000,
6190b8fc34SJaya Kumar 		.offset =	0,
6290b8fc34SJaya Kumar 		.mask_flags =	MTD_WRITEABLE  /* force read-only */
6390b8fc34SJaya Kumar 	} , {
6490b8fc34SJaya Kumar 		.name =		"rootfs",
6590b8fc34SJaya Kumar 		.size =		MTDPART_SIZ_FULL,
6690b8fc34SJaya Kumar 		.offset =	MTDPART_OFS_APPEND
6790b8fc34SJaya Kumar 	}
6890b8fc34SJaya Kumar };
6990b8fc34SJaya Kumar 
7090b8fc34SJaya Kumar static struct flash_platform_data gumstix_flash_data = {
7190b8fc34SJaya Kumar 	.map_name	= "cfi_probe",
7290b8fc34SJaya Kumar 	.parts		= gumstix_partitions,
7390b8fc34SJaya Kumar 	.nr_parts	= ARRAY_SIZE(gumstix_partitions),
7490b8fc34SJaya Kumar 	.width		= 2,
7590b8fc34SJaya Kumar };
7690b8fc34SJaya Kumar 
7790b8fc34SJaya Kumar static struct platform_device gumstix_flash_device = {
7890b8fc34SJaya Kumar 	.name		= "pxa2xx-flash",
7990b8fc34SJaya Kumar 	.id		= 0,
8090b8fc34SJaya Kumar 	.dev = {
8190b8fc34SJaya Kumar 		.platform_data = &gumstix_flash_data,
8290b8fc34SJaya Kumar 	},
8390b8fc34SJaya Kumar 	.resource = &flash_resource,
8490b8fc34SJaya Kumar 	.num_resources = 1,
8590b8fc34SJaya Kumar };
8690b8fc34SJaya Kumar 
8790b8fc34SJaya Kumar static struct platform_device *devices[] __initdata = {
8890b8fc34SJaya Kumar 	&gumstix_flash_device,
8990b8fc34SJaya Kumar };
9090b8fc34SJaya Kumar 
9190b8fc34SJaya Kumar #ifdef CONFIG_MMC_PXA
9290b8fc34SJaya Kumar static struct pxamci_platform_data gumstix_mci_platform_data = {
9390b8fc34SJaya Kumar 	.ocr_mask	= MMC_VDD_32_33|MMC_VDD_33_34,
9490b8fc34SJaya Kumar };
9590b8fc34SJaya Kumar 
9690b8fc34SJaya Kumar static void __init gumstix_mmc_init(void)
9790b8fc34SJaya Kumar {
9890b8fc34SJaya Kumar 	pxa_set_mci_info(&gumstix_mci_platform_data);
9990b8fc34SJaya Kumar }
10090b8fc34SJaya Kumar #else
10190b8fc34SJaya Kumar static void __init gumstix_mmc_init(void)
10290b8fc34SJaya Kumar {
103d8ad7859SJaya Kumar 	pr_debug("Gumstix mmc disabled\n");
10490b8fc34SJaya Kumar }
10590b8fc34SJaya Kumar #endif
10690b8fc34SJaya Kumar 
107d8ad7859SJaya Kumar #ifdef CONFIG_USB_GADGET_PXA25X
10890b8fc34SJaya Kumar static struct pxa2xx_udc_mach_info gumstix_udc_info __initdata = {
10990b8fc34SJaya Kumar 	.gpio_vbus		= GPIO_GUMSTIX_USB_GPIOn,
11090b8fc34SJaya Kumar 	.gpio_pullup		= GPIO_GUMSTIX_USB_GPIOx,
11190b8fc34SJaya Kumar };
11290b8fc34SJaya Kumar 
11390b8fc34SJaya Kumar static void __init gumstix_udc_init(void)
11490b8fc34SJaya Kumar {
11590b8fc34SJaya Kumar 	pxa_set_udc_info(&gumstix_udc_info);
11690b8fc34SJaya Kumar }
11790b8fc34SJaya Kumar #else
11890b8fc34SJaya Kumar static void gumstix_udc_init(void)
11990b8fc34SJaya Kumar {
120d8ad7859SJaya Kumar 	pr_debug("Gumstix udc is disabled\n");
12190b8fc34SJaya Kumar }
12290b8fc34SJaya Kumar #endif
12390b8fc34SJaya Kumar 
124d8ad7859SJaya Kumar #ifdef CONFIG_BT
125d8ad7859SJaya Kumar /* Normally, the bootloader would have enabled this 32kHz clock but many
126d8ad7859SJaya Kumar ** boards still have u-boot 1.1.4 so we check if it has been turned on and
127d8ad7859SJaya Kumar ** if not, we turn it on with a warning message. */
128d8ad7859SJaya Kumar static void gumstix_setup_bt_clock(void)
129d8ad7859SJaya Kumar {
130d8ad7859SJaya Kumar 	int timeout = 500;
131d8ad7859SJaya Kumar 
132d8ad7859SJaya Kumar 	if (!(OSCC & OSCC_OOK))
133d8ad7859SJaya Kumar 		pr_warning("32kHz clock was not on. Bootloader may need to "
134d8ad7859SJaya Kumar 				"be updated\n");
135d8ad7859SJaya Kumar 	else
136d8ad7859SJaya Kumar 		return;
137d8ad7859SJaya Kumar 
138d8ad7859SJaya Kumar 	OSCC |= OSCC_OON;
139d8ad7859SJaya Kumar 	do {
140d8ad7859SJaya Kumar 		if (OSCC & OSCC_OOK)
141d8ad7859SJaya Kumar 			break;
142d8ad7859SJaya Kumar 		udelay(1);
143d8ad7859SJaya Kumar 	} while (--timeout);
144d8ad7859SJaya Kumar 	if (!timeout)
145d8ad7859SJaya Kumar 		pr_err("Failed to start 32kHz clock\n");
146d8ad7859SJaya Kumar }
147d8ad7859SJaya Kumar 
148d8ad7859SJaya Kumar static void __init gumstix_bluetooth_init(void)
149d8ad7859SJaya Kumar {
150d8ad7859SJaya Kumar 	int err;
151d8ad7859SJaya Kumar 
152d8ad7859SJaya Kumar 	gumstix_setup_bt_clock();
153d8ad7859SJaya Kumar 
154d8ad7859SJaya Kumar 	err = gpio_request(GPIO_GUMSTIX_BTRESET, "BTRST");
155d8ad7859SJaya Kumar 	if (err) {
156d8ad7859SJaya Kumar 		pr_err("gumstix: failed request gpio for bluetooth reset\n");
157d8ad7859SJaya Kumar 		return;
158d8ad7859SJaya Kumar 	}
159d8ad7859SJaya Kumar 
160d8ad7859SJaya Kumar 	err = gpio_direction_output(GPIO_GUMSTIX_BTRESET, 1);
161d8ad7859SJaya Kumar 	if (err) {
162d8ad7859SJaya Kumar 		pr_err("gumstix: can't reset bluetooth\n");
163d8ad7859SJaya Kumar 		return;
164d8ad7859SJaya Kumar 	}
165d8ad7859SJaya Kumar 	gpio_set_value(GPIO_GUMSTIX_BTRESET, 0);
166d8ad7859SJaya Kumar 	udelay(100);
167d8ad7859SJaya Kumar 	gpio_set_value(GPIO_GUMSTIX_BTRESET, 1);
168d8ad7859SJaya Kumar }
169d8ad7859SJaya Kumar #else
170d8ad7859SJaya Kumar static void gumstix_bluetooth_init(void)
171d8ad7859SJaya Kumar {
172d8ad7859SJaya Kumar 	pr_debug("Gumstix Bluetooth is disabled\n");
173d8ad7859SJaya Kumar }
174d8ad7859SJaya Kumar #endif
175d8ad7859SJaya Kumar 
176d8ad7859SJaya Kumar static unsigned long gumstix_pin_config[] __initdata = {
177d8ad7859SJaya Kumar 	GPIO12_32KHz,
178d8ad7859SJaya Kumar 	/* BTUART */
179d8ad7859SJaya Kumar 	GPIO42_HWUART_RXD,
180d8ad7859SJaya Kumar 	GPIO43_HWUART_TXD,
181d8ad7859SJaya Kumar 	GPIO44_HWUART_CTS,
182d8ad7859SJaya Kumar 	GPIO45_HWUART_RTS,
183d8ad7859SJaya Kumar 	/* MMC */
184d8ad7859SJaya Kumar 	GPIO6_MMC_CLK,
185d8ad7859SJaya Kumar 	GPIO53_MMC_CLK,
186d8ad7859SJaya Kumar 	GPIO8_MMC_CS0,
187d8ad7859SJaya Kumar 	/* these are used by AM200EPD */
188d8ad7859SJaya Kumar 	GPIO51_GPIO,
189d8ad7859SJaya Kumar 	GPIO49_GPIO,
190d8ad7859SJaya Kumar 	GPIO48_GPIO,
191d8ad7859SJaya Kumar 	GPIO32_GPIO,
192d8ad7859SJaya Kumar 	GPIO17_GPIO,
193d8ad7859SJaya Kumar 	GPIO16_GPIO,
194d8ad7859SJaya Kumar };
195d8ad7859SJaya Kumar 
196*3332b0c1SJaya Kumar int __attribute__((weak)) am200_init(void)
197*3332b0c1SJaya Kumar {
198*3332b0c1SJaya Kumar 	return 0;
199*3332b0c1SJaya Kumar }
200*3332b0c1SJaya Kumar 
201*3332b0c1SJaya Kumar static void __init carrier_board_init(void)
202*3332b0c1SJaya Kumar {
203*3332b0c1SJaya Kumar 	/*
204*3332b0c1SJaya Kumar 	 * put carrier/expansion board init here if
205*3332b0c1SJaya Kumar 	 * they cannot be detected programatically
206*3332b0c1SJaya Kumar 	 */
207*3332b0c1SJaya Kumar 	am200_init();
208*3332b0c1SJaya Kumar }
209*3332b0c1SJaya Kumar 
21090b8fc34SJaya Kumar static void __init gumstix_init(void)
21190b8fc34SJaya Kumar {
212d8ad7859SJaya Kumar 	pxa2xx_mfp_config(ARRAY_AND_SIZE(gumstix_pin_config));
213d8ad7859SJaya Kumar 
214d8ad7859SJaya Kumar 	gumstix_bluetooth_init();
21590b8fc34SJaya Kumar 	gumstix_udc_init();
21690b8fc34SJaya Kumar 	gumstix_mmc_init();
21790b8fc34SJaya Kumar 	(void) platform_add_devices(devices, ARRAY_SIZE(devices));
218*3332b0c1SJaya Kumar 	carrier_board_init();
21990b8fc34SJaya Kumar }
22090b8fc34SJaya Kumar 
22190b8fc34SJaya Kumar MACHINE_START(GUMSTIX, "Gumstix")
22290b8fc34SJaya Kumar 	.phys_io	= 0x40000000,
22390b8fc34SJaya Kumar 	.boot_params	= 0xa0000100, /* match u-boot bi_boot_params */
22490b8fc34SJaya Kumar 	.io_pg_offst	= (io_p2v(0x40000000) >> 18) & 0xfffc,
22590b8fc34SJaya Kumar 	.map_io		= pxa_map_io,
22690b8fc34SJaya Kumar 	.init_irq	= pxa25x_init_irq,
22790b8fc34SJaya Kumar 	.timer		= &pxa_timer,
22890b8fc34SJaya Kumar 	.init_machine	= gumstix_init,
22990b8fc34SJaya Kumar MACHINE_END
230