| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  *  linux/arch/arm/mach-pxa/gumstix.c | 
 | 3 |  * | 
 | 4 |  *  Support for the Gumstix motherboards. | 
 | 5 |  * | 
 | 6 |  *  Original Author:	Craig Hughes | 
 | 7 |  *  Created:	Feb 14, 2008 | 
 | 8 |  *  Copyright:	Craig Hughes | 
 | 9 |  * | 
 | 10 |  *  This program is free software; you can redistribute it and/or modify | 
 | 11 |  *  it under the terms of the GNU General Public License version 2 as | 
 | 12 |  *  published by the Free Software Foundation. | 
 | 13 |  * | 
 | 14 |  *  Implemented based on lubbock.c by Nicolas Pitre and code from Craig | 
 | 15 |  *  Hughes | 
 | 16 |  */ | 
 | 17 |  | 
 | 18 | #include <linux/module.h> | 
 | 19 | #include <linux/kernel.h> | 
 | 20 | #include <linux/init.h> | 
 | 21 | #include <linux/platform_device.h> | 
 | 22 | #include <linux/interrupt.h> | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 23 | #include <linux/delay.h> | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 24 | #include <linux/mtd/mtd.h> | 
 | 25 | #include <linux/mtd/partitions.h> | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 26 | #include <linux/gpio.h> | 
 | 27 | #include <linux/err.h> | 
 | 28 | #include <linux/clk.h> | 
| Dmitry Eremin-Solenikov | d19f4cb | 2011-02-14 15:33:17 +0300 | [diff] [blame] | 29 | #include <linux/usb/gpio_vbus.h> | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 30 |  | 
 | 31 | #include <asm/setup.h> | 
 | 32 | #include <asm/memory.h> | 
 | 33 | #include <asm/mach-types.h> | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/hardware.h> | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 35 | #include <asm/irq.h> | 
 | 36 | #include <asm/sizes.h> | 
 | 37 |  | 
 | 38 | #include <asm/mach/arch.h> | 
 | 39 | #include <asm/mach/map.h> | 
 | 40 | #include <asm/mach/irq.h> | 
 | 41 | #include <asm/mach/flash.h> | 
| Eric Miao | 51c6298 | 2009-01-02 23:17:22 +0800 | [diff] [blame] | 42 |  | 
 | 43 | #include <mach/pxa25x.h> | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 44 | #include <mach/mmc.h> | 
 | 45 | #include <mach/udc.h> | 
 | 46 | #include <mach/gumstix.h> | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 47 |  | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 48 | #include "generic.h" | 
 | 49 |  | 
 | 50 | static struct resource flash_resource = { | 
 | 51 | 	.start	= 0x00000000, | 
 | 52 | 	.end	= SZ_64M - 1, | 
 | 53 | 	.flags	= IORESOURCE_MEM, | 
 | 54 | }; | 
 | 55 |  | 
 | 56 | static struct mtd_partition gumstix_partitions[] = { | 
 | 57 | 	{ | 
 | 58 | 		.name =		"Bootloader", | 
 | 59 | 		.size =		0x00040000, | 
 | 60 | 		.offset =	0, | 
 | 61 | 		.mask_flags =	MTD_WRITEABLE  /* force read-only */ | 
 | 62 | 	} , { | 
 | 63 | 		.name =		"rootfs", | 
 | 64 | 		.size =		MTDPART_SIZ_FULL, | 
 | 65 | 		.offset =	MTDPART_OFS_APPEND | 
 | 66 | 	} | 
 | 67 | }; | 
 | 68 |  | 
 | 69 | static struct flash_platform_data gumstix_flash_data = { | 
 | 70 | 	.map_name	= "cfi_probe", | 
 | 71 | 	.parts		= gumstix_partitions, | 
 | 72 | 	.nr_parts	= ARRAY_SIZE(gumstix_partitions), | 
 | 73 | 	.width		= 2, | 
 | 74 | }; | 
 | 75 |  | 
 | 76 | static struct platform_device gumstix_flash_device = { | 
 | 77 | 	.name		= "pxa2xx-flash", | 
 | 78 | 	.id		= 0, | 
 | 79 | 	.dev = { | 
 | 80 | 		.platform_data = &gumstix_flash_data, | 
 | 81 | 	}, | 
 | 82 | 	.resource = &flash_resource, | 
 | 83 | 	.num_resources = 1, | 
 | 84 | }; | 
 | 85 |  | 
 | 86 | static struct platform_device *devices[] __initdata = { | 
 | 87 | 	&gumstix_flash_device, | 
 | 88 | }; | 
 | 89 |  | 
 | 90 | #ifdef CONFIG_MMC_PXA | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 91 | static struct pxamci_platform_data gumstix_mci_platform_data = { | 
| Robert Jarzmik | 7a64825 | 2009-07-06 22:16:42 +0200 | [diff] [blame] | 92 | 	.ocr_mask		= MMC_VDD_32_33|MMC_VDD_33_34, | 
 | 93 | 	.gpio_card_detect 	= -1, | 
 | 94 | 	.gpio_card_ro		= -1, | 
 | 95 | 	.gpio_power		= -1, | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 96 | }; | 
 | 97 |  | 
 | 98 | static void __init gumstix_mmc_init(void) | 
 | 99 | { | 
 | 100 | 	pxa_set_mci_info(&gumstix_mci_platform_data); | 
 | 101 | } | 
 | 102 | #else | 
 | 103 | static void __init gumstix_mmc_init(void) | 
 | 104 | { | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 105 | 	pr_debug("Gumstix mmc disabled\n"); | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 106 | } | 
 | 107 | #endif | 
 | 108 |  | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 109 | #ifdef CONFIG_USB_GADGET_PXA25X | 
| Dmitry Eremin-Solenikov | d19f4cb | 2011-02-14 15:33:17 +0300 | [diff] [blame] | 110 | static struct gpio_vbus_mach_info gumstix_udc_info = { | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 111 | 	.gpio_vbus		= GPIO_GUMSTIX_USB_GPIOn, | 
 | 112 | 	.gpio_pullup		= GPIO_GUMSTIX_USB_GPIOx, | 
 | 113 | }; | 
 | 114 |  | 
| Dmitry Eremin-Solenikov | d19f4cb | 2011-02-14 15:33:17 +0300 | [diff] [blame] | 115 | static struct platform_device gumstix_gpio_vbus = { | 
 | 116 | 	.name	= "gpio-vbus", | 
 | 117 | 	.id	= -1, | 
 | 118 | 	.dev	= { | 
 | 119 | 		.platform_data	= &gumstix_udc_info, | 
 | 120 | 	}, | 
 | 121 | }; | 
 | 122 |  | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 123 | static void __init gumstix_udc_init(void) | 
 | 124 | { | 
| Dmitry Eremin-Solenikov | d19f4cb | 2011-02-14 15:33:17 +0300 | [diff] [blame] | 125 | 	platform_device_register(&gumstix_gpio_vbus); | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 126 | } | 
 | 127 | #else | 
 | 128 | static void gumstix_udc_init(void) | 
 | 129 | { | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 130 | 	pr_debug("Gumstix udc is disabled\n"); | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 131 | } | 
 | 132 | #endif | 
 | 133 |  | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 134 | #ifdef CONFIG_BT | 
 | 135 | /* Normally, the bootloader would have enabled this 32kHz clock but many | 
 | 136 | ** boards still have u-boot 1.1.4 so we check if it has been turned on and | 
 | 137 | ** if not, we turn it on with a warning message. */ | 
 | 138 | static void gumstix_setup_bt_clock(void) | 
 | 139 | { | 
 | 140 | 	int timeout = 500; | 
 | 141 |  | 
 | 142 | 	if (!(OSCC & OSCC_OOK)) | 
 | 143 | 		pr_warning("32kHz clock was not on. Bootloader may need to " | 
 | 144 | 				"be updated\n"); | 
 | 145 | 	else | 
 | 146 | 		return; | 
 | 147 |  | 
 | 148 | 	OSCC |= OSCC_OON; | 
 | 149 | 	do { | 
 | 150 | 		if (OSCC & OSCC_OOK) | 
 | 151 | 			break; | 
 | 152 | 		udelay(1); | 
 | 153 | 	} while (--timeout); | 
 | 154 | 	if (!timeout) | 
 | 155 | 		pr_err("Failed to start 32kHz clock\n"); | 
 | 156 | } | 
 | 157 |  | 
 | 158 | static void __init gumstix_bluetooth_init(void) | 
 | 159 | { | 
 | 160 | 	int err; | 
 | 161 |  | 
 | 162 | 	gumstix_setup_bt_clock(); | 
 | 163 |  | 
 | 164 | 	err = gpio_request(GPIO_GUMSTIX_BTRESET, "BTRST"); | 
 | 165 | 	if (err) { | 
 | 166 | 		pr_err("gumstix: failed request gpio for bluetooth reset\n"); | 
 | 167 | 		return; | 
 | 168 | 	} | 
 | 169 |  | 
 | 170 | 	err = gpio_direction_output(GPIO_GUMSTIX_BTRESET, 1); | 
 | 171 | 	if (err) { | 
 | 172 | 		pr_err("gumstix: can't reset bluetooth\n"); | 
 | 173 | 		return; | 
 | 174 | 	} | 
 | 175 | 	gpio_set_value(GPIO_GUMSTIX_BTRESET, 0); | 
 | 176 | 	udelay(100); | 
 | 177 | 	gpio_set_value(GPIO_GUMSTIX_BTRESET, 1); | 
 | 178 | } | 
 | 179 | #else | 
 | 180 | static void gumstix_bluetooth_init(void) | 
 | 181 | { | 
 | 182 | 	pr_debug("Gumstix Bluetooth is disabled\n"); | 
 | 183 | } | 
 | 184 | #endif | 
 | 185 |  | 
 | 186 | static unsigned long gumstix_pin_config[] __initdata = { | 
 | 187 | 	GPIO12_32KHz, | 
 | 188 | 	/* BTUART */ | 
 | 189 | 	GPIO42_HWUART_RXD, | 
 | 190 | 	GPIO43_HWUART_TXD, | 
 | 191 | 	GPIO44_HWUART_CTS, | 
 | 192 | 	GPIO45_HWUART_RTS, | 
 | 193 | 	/* MMC */ | 
 | 194 | 	GPIO6_MMC_CLK, | 
 | 195 | 	GPIO53_MMC_CLK, | 
 | 196 | 	GPIO8_MMC_CS0, | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 197 | }; | 
 | 198 |  | 
| Jaya Kumar | 3332b0c | 2008-12-09 22:14:29 +0800 | [diff] [blame] | 199 | int __attribute__((weak)) am200_init(void) | 
 | 200 | { | 
 | 201 | 	return 0; | 
 | 202 | } | 
 | 203 |  | 
| Jaya Kumar | 4ce255c | 2009-01-01 17:51:01 +0100 | [diff] [blame] | 204 | int __attribute__((weak)) am300_init(void) | 
 | 205 | { | 
 | 206 | 	return 0; | 
 | 207 | } | 
 | 208 |  | 
| Jaya Kumar | 3332b0c | 2008-12-09 22:14:29 +0800 | [diff] [blame] | 209 | static void __init carrier_board_init(void) | 
 | 210 | { | 
 | 211 | 	/* | 
 | 212 | 	 * put carrier/expansion board init here if | 
 | 213 | 	 * they cannot be detected programatically | 
 | 214 | 	 */ | 
 | 215 | 	am200_init(); | 
| Jaya Kumar | 4ce255c | 2009-01-01 17:51:01 +0100 | [diff] [blame] | 216 | 	am300_init(); | 
| Jaya Kumar | 3332b0c | 2008-12-09 22:14:29 +0800 | [diff] [blame] | 217 | } | 
 | 218 |  | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 219 | static void __init gumstix_init(void) | 
 | 220 | { | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 221 | 	pxa2xx_mfp_config(ARRAY_AND_SIZE(gumstix_pin_config)); | 
 | 222 |  | 
| Russell King | cc155c6 | 2009-11-09 13:34:08 +0800 | [diff] [blame] | 223 | 	pxa_set_ffuart_info(NULL); | 
 | 224 | 	pxa_set_btuart_info(NULL); | 
 | 225 | 	pxa_set_stuart_info(NULL); | 
 | 226 | 	pxa_set_hwuart_info(NULL); | 
 | 227 |  | 
| Jaya Kumar | d8ad785 | 2008-08-16 04:07:18 +0100 | [diff] [blame] | 228 | 	gumstix_bluetooth_init(); | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 229 | 	gumstix_udc_init(); | 
 | 230 | 	gumstix_mmc_init(); | 
 | 231 | 	(void) platform_add_devices(devices, ARRAY_SIZE(devices)); | 
| Jaya Kumar | 3332b0c | 2008-12-09 22:14:29 +0800 | [diff] [blame] | 232 | 	carrier_board_init(); | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 233 | } | 
 | 234 |  | 
 | 235 | MACHINE_START(GUMSTIX, "Gumstix") | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 236 | 	.boot_params	= 0xa0000100, /* match u-boot bi_boot_params */ | 
| Marek Vasut | 851982c | 2010-10-11 02:20:19 +0200 | [diff] [blame] | 237 | 	.map_io		= pxa25x_map_io, | 
| Jaya Kumar | 90b8fc3 | 2008-03-15 05:11:07 +0100 | [diff] [blame] | 238 | 	.init_irq	= pxa25x_init_irq, | 
 | 239 | 	.timer		= &pxa_timer, | 
 | 240 | 	.init_machine	= gumstix_init, | 
 | 241 | MACHINE_END |