board-overo.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*
  2. * board-overo.c (Gumstix Overo)
  3. *
  4. * Initial code: Steve Sakoman <steve@sakoman.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/clk.h>
  22. #include <linux/delay.h>
  23. #include <linux/err.h>
  24. #include <linux/init.h>
  25. #include <linux/io.h>
  26. #include <linux/kernel.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/i2c/twl4030.h>
  29. #include <linux/mtd/mtd.h>
  30. #include <linux/mtd/nand.h>
  31. #include <linux/mtd/partitions.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/flash.h>
  35. #include <asm/mach/map.h>
  36. #include <mach/board.h>
  37. #include <mach/common.h>
  38. #include <mach/gpio.h>
  39. #include <mach/gpmc.h>
  40. #include <mach/hardware.h>
  41. #include <mach/nand.h>
  42. #include <mach/usb.h>
  43. #include "mmc-twl4030.h"
  44. #define OVERO_GPIO_BT_XGATE 15
  45. #define OVERO_GPIO_W2W_NRESET 16
  46. #define OVERO_GPIO_BT_NRESET 164
  47. #define OVERO_GPIO_USBH_CPEN 168
  48. #define OVERO_GPIO_USBH_NRESET 183
  49. #define NAND_BLOCK_SIZE SZ_128K
  50. #define GPMC_CS0_BASE 0x60
  51. #define GPMC_CS_SIZE 0x30
  52. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
  53. defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  54. #include <mach/mcspi.h>
  55. #include <linux/spi/spi.h>
  56. #include <linux/spi/ads7846.h>
  57. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  58. .turbo_mode = 0,
  59. .single_channel = 1, /* 0: slave, 1: master */
  60. };
  61. static int ads7846_get_pendown_state(void)
  62. {
  63. return !gpio_get_value(OVERO_GPIO_PENDOWN);
  64. }
  65. static struct ads7846_platform_data ads7846_config = {
  66. .x_max = 0x0fff,
  67. .y_max = 0x0fff,
  68. .x_plate_ohms = 180,
  69. .pressure_max = 255,
  70. .debounce_max = 10,
  71. .debounce_tol = 3,
  72. .debounce_rep = 1,
  73. .get_pendown_state = ads7846_get_pendown_state,
  74. .keep_vref_on = 1,
  75. };
  76. static struct spi_board_info overo_spi_board_info[] __initdata = {
  77. {
  78. .modalias = "ads7846",
  79. .bus_num = 1,
  80. .chip_select = 0,
  81. .max_speed_hz = 1500000,
  82. .controller_data = &ads7846_mcspi_config,
  83. .irq = OMAP_GPIO_IRQ(OVERO_GPIO_PENDOWN),
  84. .platform_data = &ads7846_config,
  85. }
  86. };
  87. static void __init overo_ads7846_init(void)
  88. {
  89. if ((gpio_request(OVERO_GPIO_PENDOWN, "ADS7846_PENDOWN") == 0) &&
  90. (gpio_direction_input(OVERO_GPIO_PENDOWN) == 0)) {
  91. gpio_export(OVERO_GPIO_PENDOWN, 0);
  92. } else {
  93. printk(KERN_ERR "could not obtain gpio for ADS7846_PENDOWN\n");
  94. return;
  95. }
  96. spi_register_board_info(overo_spi_board_info,
  97. ARRAY_SIZE(overo_spi_board_info));
  98. }
  99. #else
  100. static inline void __init overo_ads7846_init(void) { return; }
  101. #endif
  102. static struct mtd_partition overo_nand_partitions[] = {
  103. {
  104. .name = "xloader",
  105. .offset = 0, /* Offset = 0x00000 */
  106. .size = 4 * NAND_BLOCK_SIZE,
  107. .mask_flags = MTD_WRITEABLE
  108. },
  109. {
  110. .name = "uboot",
  111. .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
  112. .size = 14 * NAND_BLOCK_SIZE,
  113. },
  114. {
  115. .name = "uboot environment",
  116. .offset = MTDPART_OFS_APPEND, /* Offset = 0x240000 */
  117. .size = 2 * NAND_BLOCK_SIZE,
  118. },
  119. {
  120. .name = "linux",
  121. .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
  122. .size = 32 * NAND_BLOCK_SIZE,
  123. },
  124. {
  125. .name = "rootfs",
  126. .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
  127. .size = MTDPART_SIZ_FULL,
  128. },
  129. };
  130. static struct omap_nand_platform_data overo_nand_data = {
  131. .parts = overo_nand_partitions,
  132. .nr_parts = ARRAY_SIZE(overo_nand_partitions),
  133. .dma_channel = -1, /* disable DMA in OMAP NAND driver */
  134. };
  135. static struct resource overo_nand_resource = {
  136. .flags = IORESOURCE_MEM,
  137. };
  138. static struct platform_device overo_nand_device = {
  139. .name = "omap2-nand",
  140. .id = -1,
  141. .dev = {
  142. .platform_data = &overo_nand_data,
  143. },
  144. .num_resources = 1,
  145. .resource = &overo_nand_resource,
  146. };
  147. static void __init overo_flash_init(void)
  148. {
  149. u8 cs = 0;
  150. u8 nandcs = GPMC_CS_NUM + 1;
  151. u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
  152. /* find out the chip-select on which NAND exists */
  153. while (cs < GPMC_CS_NUM) {
  154. u32 ret = 0;
  155. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  156. if ((ret & 0xC00) == 0x800) {
  157. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  158. if (nandcs > GPMC_CS_NUM)
  159. nandcs = cs;
  160. }
  161. cs++;
  162. }
  163. if (nandcs > GPMC_CS_NUM) {
  164. printk(KERN_INFO "NAND: Unable to find configuration "
  165. "in GPMC\n ");
  166. return;
  167. }
  168. if (nandcs < GPMC_CS_NUM) {
  169. overo_nand_data.cs = nandcs;
  170. overo_nand_data.gpmc_cs_baseaddr = (void *)
  171. (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
  172. overo_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
  173. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  174. if (platform_device_register(&overo_nand_device) < 0)
  175. printk(KERN_ERR "Unable to register NAND device\n");
  176. }
  177. }
  178. static struct omap_uart_config overo_uart_config __initdata = {
  179. .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
  180. };
  181. static struct twl4030_gpio_platform_data overo_gpio_data = {
  182. .gpio_base = OMAP_MAX_GPIO_LINES,
  183. .irq_base = TWL4030_GPIO_IRQ_BASE,
  184. .irq_end = TWL4030_GPIO_IRQ_END,
  185. };
  186. static struct twl4030_platform_data overo_twldata = {
  187. .irq_base = TWL4030_IRQ_BASE,
  188. .irq_end = TWL4030_IRQ_END,
  189. .gpio = &overo_gpio_data,
  190. };
  191. static struct i2c_board_info __initdata overo_i2c_boardinfo[] = {
  192. {
  193. I2C_BOARD_INFO("twl4030", 0x48),
  194. .flags = I2C_CLIENT_WAKE,
  195. .irq = INT_34XX_SYS_NIRQ,
  196. .platform_data = &overo_twldata,
  197. },
  198. };
  199. static int __init overo_i2c_init(void)
  200. {
  201. omap_register_i2c_bus(1, 2600, overo_i2c_boardinfo,
  202. ARRAY_SIZE(overo_i2c_boardinfo));
  203. /* i2c2 pins are used for gpio */
  204. omap_register_i2c_bus(3, 400, NULL, 0);
  205. return 0;
  206. }
  207. static void __init overo_init_irq(void)
  208. {
  209. omap2_init_common_hw(NULL);
  210. omap_init_irq();
  211. omap_gpio_init();
  212. }
  213. static struct platform_device overo_lcd_device = {
  214. .name = "overo_lcd",
  215. .id = -1,
  216. };
  217. static struct omap_lcd_config overo_lcd_config __initdata = {
  218. .ctrl_name = "internal",
  219. };
  220. static struct omap_board_config_kernel overo_config[] __initdata = {
  221. { OMAP_TAG_UART, &overo_uart_config },
  222. { OMAP_TAG_LCD, &overo_lcd_config },
  223. };
  224. static struct platform_device *overo_devices[] __initdata = {
  225. &overo_lcd_device,
  226. };
  227. static struct twl4030_hsmmc_info mmc[] __initdata = {
  228. {
  229. .mmc = 1,
  230. .wires = 4,
  231. .gpio_cd = -EINVAL,
  232. .gpio_wp = -EINVAL,
  233. },
  234. {
  235. .mmc = 2,
  236. .wires = 4,
  237. .gpio_cd = -EINVAL,
  238. .gpio_wp = -EINVAL,
  239. .transceiver = true,
  240. },
  241. {} /* Terminator */
  242. };
  243. static void __init overo_init(void)
  244. {
  245. overo_i2c_init();
  246. platform_add_devices(overo_devices, ARRAY_SIZE(overo_devices));
  247. omap_board_config = overo_config;
  248. omap_board_config_size = ARRAY_SIZE(overo_config);
  249. omap_serial_init();
  250. twl4030_mmc_init(mmc);
  251. overo_flash_init();
  252. usb_musb_init();
  253. overo_ads7846_init();
  254. if ((gpio_request(OVERO_GPIO_W2W_NRESET,
  255. "OVERO_GPIO_W2W_NRESET") == 0) &&
  256. (gpio_direction_output(OVERO_GPIO_W2W_NRESET, 1) == 0)) {
  257. gpio_export(OVERO_GPIO_W2W_NRESET, 0);
  258. gpio_set_value(OVERO_GPIO_W2W_NRESET, 0);
  259. udelay(10);
  260. gpio_set_value(OVERO_GPIO_W2W_NRESET, 1);
  261. } else {
  262. printk(KERN_ERR "could not obtain gpio for "
  263. "OVERO_GPIO_W2W_NRESET\n");
  264. }
  265. if ((gpio_request(OVERO_GPIO_BT_XGATE, "OVERO_GPIO_BT_XGATE") == 0) &&
  266. (gpio_direction_output(OVERO_GPIO_BT_XGATE, 0) == 0))
  267. gpio_export(OVERO_GPIO_BT_XGATE, 0);
  268. else
  269. printk(KERN_ERR "could not obtain gpio for OVERO_GPIO_BT_XGATE\n");
  270. if ((gpio_request(OVERO_GPIO_BT_NRESET, "OVERO_GPIO_BT_NRESET") == 0) &&
  271. (gpio_direction_output(OVERO_GPIO_BT_NRESET, 1) == 0)) {
  272. gpio_export(OVERO_GPIO_BT_NRESET, 0);
  273. gpio_set_value(OVERO_GPIO_BT_NRESET, 0);
  274. mdelay(6);
  275. gpio_set_value(OVERO_GPIO_BT_NRESET, 1);
  276. } else {
  277. printk(KERN_ERR "could not obtain gpio for "
  278. "OVERO_GPIO_BT_NRESET\n");
  279. }
  280. if ((gpio_request(OVERO_GPIO_USBH_CPEN, "OVERO_GPIO_USBH_CPEN") == 0) &&
  281. (gpio_direction_output(OVERO_GPIO_USBH_CPEN, 1) == 0))
  282. gpio_export(OVERO_GPIO_USBH_CPEN, 0);
  283. else
  284. printk(KERN_ERR "could not obtain gpio for "
  285. "OVERO_GPIO_USBH_CPEN\n");
  286. if ((gpio_request(OVERO_GPIO_USBH_NRESET,
  287. "OVERO_GPIO_USBH_NRESET") == 0) &&
  288. (gpio_direction_output(OVERO_GPIO_USBH_NRESET, 1) == 0))
  289. gpio_export(OVERO_GPIO_USBH_NRESET, 0);
  290. else
  291. printk(KERN_ERR "could not obtain gpio for "
  292. "OVERO_GPIO_USBH_NRESET\n");
  293. }
  294. static void __init overo_map_io(void)
  295. {
  296. omap2_set_globals_343x();
  297. omap2_map_common_io();
  298. }
  299. MACHINE_START(OVERO, "Gumstix Overo")
  300. .phys_io = 0x48000000,
  301. .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
  302. .boot_params = 0x80000100,
  303. .map_io = overo_map_io,
  304. .init_irq = overo_init_irq,
  305. .init_machine = overo_init,
  306. .timer = &omap_timer,
  307. MACHINE_END