board-overo.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 "sdram-micron-mt46h32m32lf-6.h"
  44. #include "mmc-twl4030.h"
  45. #define OVERO_GPIO_BT_XGATE 15
  46. #define OVERO_GPIO_W2W_NRESET 16
  47. #define OVERO_GPIO_BT_NRESET 164
  48. #define OVERO_GPIO_USBH_CPEN 168
  49. #define OVERO_GPIO_USBH_NRESET 183
  50. #define NAND_BLOCK_SIZE SZ_128K
  51. #define GPMC_CS0_BASE 0x60
  52. #define GPMC_CS_SIZE 0x30
  53. #define OVERO_SMSC911X_CS 5
  54. #define OVERO_SMSC911X_GPIO 176
  55. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
  56. defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  57. #include <mach/mcspi.h>
  58. #include <linux/spi/spi.h>
  59. #include <linux/spi/ads7846.h>
  60. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  61. .turbo_mode = 0,
  62. .single_channel = 1, /* 0: slave, 1: master */
  63. };
  64. static int ads7846_get_pendown_state(void)
  65. {
  66. return !gpio_get_value(OVERO_GPIO_PENDOWN);
  67. }
  68. static struct ads7846_platform_data ads7846_config = {
  69. .x_max = 0x0fff,
  70. .y_max = 0x0fff,
  71. .x_plate_ohms = 180,
  72. .pressure_max = 255,
  73. .debounce_max = 10,
  74. .debounce_tol = 3,
  75. .debounce_rep = 1,
  76. .get_pendown_state = ads7846_get_pendown_state,
  77. .keep_vref_on = 1,
  78. };
  79. static struct spi_board_info overo_spi_board_info[] __initdata = {
  80. {
  81. .modalias = "ads7846",
  82. .bus_num = 1,
  83. .chip_select = 0,
  84. .max_speed_hz = 1500000,
  85. .controller_data = &ads7846_mcspi_config,
  86. .irq = OMAP_GPIO_IRQ(OVERO_GPIO_PENDOWN),
  87. .platform_data = &ads7846_config,
  88. }
  89. };
  90. static void __init overo_ads7846_init(void)
  91. {
  92. if ((gpio_request(OVERO_GPIO_PENDOWN, "ADS7846_PENDOWN") == 0) &&
  93. (gpio_direction_input(OVERO_GPIO_PENDOWN) == 0)) {
  94. gpio_export(OVERO_GPIO_PENDOWN, 0);
  95. } else {
  96. printk(KERN_ERR "could not obtain gpio for ADS7846_PENDOWN\n");
  97. return;
  98. }
  99. spi_register_board_info(overo_spi_board_info,
  100. ARRAY_SIZE(overo_spi_board_info));
  101. }
  102. #else
  103. static inline void __init overo_ads7846_init(void) { return; }
  104. #endif
  105. #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
  106. #include <linux/smsc911x.h>
  107. static struct resource overo_smsc911x_resources[] = {
  108. {
  109. .name = "smsc911x-memory",
  110. .flags = IORESOURCE_MEM,
  111. },
  112. {
  113. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  114. },
  115. };
  116. static struct smsc911x_platform_config overo_smsc911x_config = {
  117. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  118. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  119. .flags = SMSC911X_USE_32BIT ,
  120. .phy_interface = PHY_INTERFACE_MODE_MII,
  121. };
  122. static struct platform_device overo_smsc911x_device = {
  123. .name = "smsc911x",
  124. .id = -1,
  125. .num_resources = ARRAY_SIZE(overo_smsc911x_resources),
  126. .resource = &overo_smsc911x_resources,
  127. .dev = {
  128. .platform_data = &overo_smsc911x_config,
  129. },
  130. };
  131. static inline void __init overo_init_smsc911x(void)
  132. {
  133. unsigned long cs_mem_base;
  134. if (gpmc_cs_request(OVERO_SMSC911X_CS, SZ_16M, &cs_mem_base) < 0) {
  135. printk(KERN_ERR "Failed request for GPMC mem for smsc911x\n");
  136. return;
  137. }
  138. overo_smsc911x_resources[0].start = cs_mem_base + 0x0;
  139. overo_smsc911x_resources[0].end = cs_mem_base + 0xff;
  140. if ((gpio_request(OVERO_SMSC911X_GPIO, "SMSC911X IRQ") == 0) &&
  141. (gpio_direction_input(OVERO_SMSC911X_GPIO) == 0)) {
  142. gpio_export(OVERO_SMSC911X_GPIO, 0);
  143. } else {
  144. printk(KERN_ERR "could not obtain gpio for SMSC911X IRQ\n");
  145. return;
  146. }
  147. overo_smsc911x_resources[1].start = OMAP_GPIO_IRQ(OVERO_SMSC911X_GPIO);
  148. overo_smsc911x_resources[1].end = 0;
  149. platform_device_register(&overo_smsc911x_device);
  150. }
  151. #else
  152. static inline void __init overo_init_smsc911x(void) { return; }
  153. #endif
  154. static struct mtd_partition overo_nand_partitions[] = {
  155. {
  156. .name = "xloader",
  157. .offset = 0, /* Offset = 0x00000 */
  158. .size = 4 * NAND_BLOCK_SIZE,
  159. .mask_flags = MTD_WRITEABLE
  160. },
  161. {
  162. .name = "uboot",
  163. .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
  164. .size = 14 * NAND_BLOCK_SIZE,
  165. },
  166. {
  167. .name = "uboot environment",
  168. .offset = MTDPART_OFS_APPEND, /* Offset = 0x240000 */
  169. .size = 2 * NAND_BLOCK_SIZE,
  170. },
  171. {
  172. .name = "linux",
  173. .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
  174. .size = 32 * NAND_BLOCK_SIZE,
  175. },
  176. {
  177. .name = "rootfs",
  178. .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
  179. .size = MTDPART_SIZ_FULL,
  180. },
  181. };
  182. static struct omap_nand_platform_data overo_nand_data = {
  183. .parts = overo_nand_partitions,
  184. .nr_parts = ARRAY_SIZE(overo_nand_partitions),
  185. .dma_channel = -1, /* disable DMA in OMAP NAND driver */
  186. };
  187. static struct resource overo_nand_resource = {
  188. .flags = IORESOURCE_MEM,
  189. };
  190. static struct platform_device overo_nand_device = {
  191. .name = "omap2-nand",
  192. .id = -1,
  193. .dev = {
  194. .platform_data = &overo_nand_data,
  195. },
  196. .num_resources = 1,
  197. .resource = &overo_nand_resource,
  198. };
  199. static void __init overo_flash_init(void)
  200. {
  201. u8 cs = 0;
  202. u8 nandcs = GPMC_CS_NUM + 1;
  203. u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
  204. /* find out the chip-select on which NAND exists */
  205. while (cs < GPMC_CS_NUM) {
  206. u32 ret = 0;
  207. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  208. if ((ret & 0xC00) == 0x800) {
  209. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  210. if (nandcs > GPMC_CS_NUM)
  211. nandcs = cs;
  212. }
  213. cs++;
  214. }
  215. if (nandcs > GPMC_CS_NUM) {
  216. printk(KERN_INFO "NAND: Unable to find configuration "
  217. "in GPMC\n ");
  218. return;
  219. }
  220. if (nandcs < GPMC_CS_NUM) {
  221. overo_nand_data.cs = nandcs;
  222. overo_nand_data.gpmc_cs_baseaddr = (void *)
  223. (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
  224. overo_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
  225. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  226. if (platform_device_register(&overo_nand_device) < 0)
  227. printk(KERN_ERR "Unable to register NAND device\n");
  228. }
  229. }
  230. static struct omap_uart_config overo_uart_config __initdata = {
  231. .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
  232. };
  233. static struct twl4030_gpio_platform_data overo_gpio_data = {
  234. .gpio_base = OMAP_MAX_GPIO_LINES,
  235. .irq_base = TWL4030_GPIO_IRQ_BASE,
  236. .irq_end = TWL4030_GPIO_IRQ_END,
  237. };
  238. static struct twl4030_platform_data overo_twldata = {
  239. .irq_base = TWL4030_IRQ_BASE,
  240. .irq_end = TWL4030_IRQ_END,
  241. .gpio = &overo_gpio_data,
  242. };
  243. static struct i2c_board_info __initdata overo_i2c_boardinfo[] = {
  244. {
  245. I2C_BOARD_INFO("twl4030", 0x48),
  246. .flags = I2C_CLIENT_WAKE,
  247. .irq = INT_34XX_SYS_NIRQ,
  248. .platform_data = &overo_twldata,
  249. },
  250. };
  251. static int __init overo_i2c_init(void)
  252. {
  253. omap_register_i2c_bus(1, 2600, overo_i2c_boardinfo,
  254. ARRAY_SIZE(overo_i2c_boardinfo));
  255. /* i2c2 pins are used for gpio */
  256. omap_register_i2c_bus(3, 400, NULL, 0);
  257. return 0;
  258. }
  259. static void __init overo_init_irq(void)
  260. {
  261. omap2_init_common_hw(mt46h32m32lf6_sdrc_params);
  262. omap_init_irq();
  263. omap_gpio_init();
  264. }
  265. static struct platform_device overo_lcd_device = {
  266. .name = "overo_lcd",
  267. .id = -1,
  268. };
  269. static struct omap_lcd_config overo_lcd_config __initdata = {
  270. .ctrl_name = "internal",
  271. };
  272. static struct omap_board_config_kernel overo_config[] __initdata = {
  273. { OMAP_TAG_UART, &overo_uart_config },
  274. { OMAP_TAG_LCD, &overo_lcd_config },
  275. };
  276. static struct platform_device *overo_devices[] __initdata = {
  277. &overo_lcd_device,
  278. };
  279. static struct twl4030_hsmmc_info mmc[] __initdata = {
  280. {
  281. .mmc = 1,
  282. .wires = 4,
  283. .gpio_cd = -EINVAL,
  284. .gpio_wp = -EINVAL,
  285. },
  286. {
  287. .mmc = 2,
  288. .wires = 4,
  289. .gpio_cd = -EINVAL,
  290. .gpio_wp = -EINVAL,
  291. .transceiver = true,
  292. },
  293. {} /* Terminator */
  294. };
  295. static void __init overo_init(void)
  296. {
  297. overo_i2c_init();
  298. platform_add_devices(overo_devices, ARRAY_SIZE(overo_devices));
  299. omap_board_config = overo_config;
  300. omap_board_config_size = ARRAY_SIZE(overo_config);
  301. omap_serial_init();
  302. twl4030_mmc_init(mmc);
  303. overo_flash_init();
  304. usb_musb_init();
  305. overo_ads7846_init();
  306. overo_init_smsc911x();
  307. if ((gpio_request(OVERO_GPIO_W2W_NRESET,
  308. "OVERO_GPIO_W2W_NRESET") == 0) &&
  309. (gpio_direction_output(OVERO_GPIO_W2W_NRESET, 1) == 0)) {
  310. gpio_export(OVERO_GPIO_W2W_NRESET, 0);
  311. gpio_set_value(OVERO_GPIO_W2W_NRESET, 0);
  312. udelay(10);
  313. gpio_set_value(OVERO_GPIO_W2W_NRESET, 1);
  314. } else {
  315. printk(KERN_ERR "could not obtain gpio for "
  316. "OVERO_GPIO_W2W_NRESET\n");
  317. }
  318. if ((gpio_request(OVERO_GPIO_BT_XGATE, "OVERO_GPIO_BT_XGATE") == 0) &&
  319. (gpio_direction_output(OVERO_GPIO_BT_XGATE, 0) == 0))
  320. gpio_export(OVERO_GPIO_BT_XGATE, 0);
  321. else
  322. printk(KERN_ERR "could not obtain gpio for OVERO_GPIO_BT_XGATE\n");
  323. if ((gpio_request(OVERO_GPIO_BT_NRESET, "OVERO_GPIO_BT_NRESET") == 0) &&
  324. (gpio_direction_output(OVERO_GPIO_BT_NRESET, 1) == 0)) {
  325. gpio_export(OVERO_GPIO_BT_NRESET, 0);
  326. gpio_set_value(OVERO_GPIO_BT_NRESET, 0);
  327. mdelay(6);
  328. gpio_set_value(OVERO_GPIO_BT_NRESET, 1);
  329. } else {
  330. printk(KERN_ERR "could not obtain gpio for "
  331. "OVERO_GPIO_BT_NRESET\n");
  332. }
  333. if ((gpio_request(OVERO_GPIO_USBH_CPEN, "OVERO_GPIO_USBH_CPEN") == 0) &&
  334. (gpio_direction_output(OVERO_GPIO_USBH_CPEN, 1) == 0))
  335. gpio_export(OVERO_GPIO_USBH_CPEN, 0);
  336. else
  337. printk(KERN_ERR "could not obtain gpio for "
  338. "OVERO_GPIO_USBH_CPEN\n");
  339. if ((gpio_request(OVERO_GPIO_USBH_NRESET,
  340. "OVERO_GPIO_USBH_NRESET") == 0) &&
  341. (gpio_direction_output(OVERO_GPIO_USBH_NRESET, 1) == 0))
  342. gpio_export(OVERO_GPIO_USBH_NRESET, 0);
  343. else
  344. printk(KERN_ERR "could not obtain gpio for "
  345. "OVERO_GPIO_USBH_NRESET\n");
  346. }
  347. static void __init overo_map_io(void)
  348. {
  349. omap2_set_globals_343x();
  350. omap2_map_common_io();
  351. }
  352. MACHINE_START(OVERO, "Gumstix Overo")
  353. .phys_io = 0x48000000,
  354. .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
  355. .boot_params = 0x80000100,
  356. .map_io = overo_map_io,
  357. .init_irq = overo_init_irq,
  358. .init_machine = overo_init,
  359. .timer = &omap_timer,
  360. MACHINE_END