board-overo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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/twl.h>
  29. #include <linux/regulator/machine.h>
  30. #include <linux/mtd/mtd.h>
  31. #include <linux/mtd/nand.h>
  32. #include <linux/mtd/partitions.h>
  33. #include <linux/mmc/host.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/mach/flash.h>
  37. #include <asm/mach/map.h>
  38. #include <plat/board.h>
  39. #include <plat/common.h>
  40. #include <mach/gpio.h>
  41. #include <plat/gpmc.h>
  42. #include <mach/hardware.h>
  43. #include <plat/nand.h>
  44. #include <plat/usb.h>
  45. #include "mux.h"
  46. #include "sdram-micron-mt46h32m32lf-6.h"
  47. #include "hsmmc.h"
  48. #define OVERO_GPIO_BT_XGATE 15
  49. #define OVERO_GPIO_W2W_NRESET 16
  50. #define OVERO_GPIO_PENDOWN 114
  51. #define OVERO_GPIO_BT_NRESET 164
  52. #define OVERO_GPIO_USBH_CPEN 168
  53. #define OVERO_GPIO_USBH_NRESET 183
  54. #define NAND_BLOCK_SIZE SZ_128K
  55. #define OVERO_SMSC911X_CS 5
  56. #define OVERO_SMSC911X_GPIO 176
  57. #define OVERO_SMSC911X2_CS 4
  58. #define OVERO_SMSC911X2_GPIO 65
  59. #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
  60. defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
  61. #include <plat/mcspi.h>
  62. #include <linux/spi/spi.h>
  63. #include <linux/spi/ads7846.h>
  64. static struct omap2_mcspi_device_config ads7846_mcspi_config = {
  65. .turbo_mode = 0,
  66. .single_channel = 1, /* 0: slave, 1: master */
  67. };
  68. static int ads7846_get_pendown_state(void)
  69. {
  70. return !gpio_get_value(OVERO_GPIO_PENDOWN);
  71. }
  72. static struct ads7846_platform_data ads7846_config = {
  73. .x_max = 0x0fff,
  74. .y_max = 0x0fff,
  75. .x_plate_ohms = 180,
  76. .pressure_max = 255,
  77. .debounce_max = 10,
  78. .debounce_tol = 3,
  79. .debounce_rep = 1,
  80. .get_pendown_state = ads7846_get_pendown_state,
  81. .keep_vref_on = 1,
  82. };
  83. static struct spi_board_info overo_spi_board_info[] __initdata = {
  84. {
  85. .modalias = "ads7846",
  86. .bus_num = 1,
  87. .chip_select = 0,
  88. .max_speed_hz = 1500000,
  89. .controller_data = &ads7846_mcspi_config,
  90. .irq = OMAP_GPIO_IRQ(OVERO_GPIO_PENDOWN),
  91. .platform_data = &ads7846_config,
  92. }
  93. };
  94. static void __init overo_ads7846_init(void)
  95. {
  96. if ((gpio_request(OVERO_GPIO_PENDOWN, "ADS7846_PENDOWN") == 0) &&
  97. (gpio_direction_input(OVERO_GPIO_PENDOWN) == 0)) {
  98. gpio_export(OVERO_GPIO_PENDOWN, 0);
  99. } else {
  100. printk(KERN_ERR "could not obtain gpio for ADS7846_PENDOWN\n");
  101. return;
  102. }
  103. spi_register_board_info(overo_spi_board_info,
  104. ARRAY_SIZE(overo_spi_board_info));
  105. }
  106. #else
  107. static inline void __init overo_ads7846_init(void) { return; }
  108. #endif
  109. #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
  110. #include <linux/smsc911x.h>
  111. static struct resource overo_smsc911x_resources[] = {
  112. {
  113. .name = "smsc911x-memory",
  114. .flags = IORESOURCE_MEM,
  115. },
  116. {
  117. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  118. },
  119. };
  120. static struct resource overo_smsc911x2_resources[] = {
  121. {
  122. .name = "smsc911x2-memory",
  123. .flags = IORESOURCE_MEM,
  124. },
  125. {
  126. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  127. },
  128. };
  129. static struct smsc911x_platform_config overo_smsc911x_config = {
  130. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  131. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  132. .flags = SMSC911X_USE_32BIT ,
  133. .phy_interface = PHY_INTERFACE_MODE_MII,
  134. };
  135. static struct platform_device overo_smsc911x_device = {
  136. .name = "smsc911x",
  137. .id = 0,
  138. .num_resources = ARRAY_SIZE(overo_smsc911x_resources),
  139. .resource = overo_smsc911x_resources,
  140. .dev = {
  141. .platform_data = &overo_smsc911x_config,
  142. },
  143. };
  144. static struct platform_device overo_smsc911x2_device = {
  145. .name = "smsc911x",
  146. .id = 1,
  147. .num_resources = ARRAY_SIZE(overo_smsc911x2_resources),
  148. .resource = overo_smsc911x2_resources,
  149. .dev = {
  150. .platform_data = &overo_smsc911x_config,
  151. },
  152. };
  153. static struct platform_device *smsc911x_devices[] = {
  154. &overo_smsc911x_device,
  155. &overo_smsc911x2_device,
  156. };
  157. static inline void __init overo_init_smsc911x(void)
  158. {
  159. unsigned long cs_mem_base, cs_mem_base2;
  160. /* set up first smsc911x chip */
  161. if (gpmc_cs_request(OVERO_SMSC911X_CS, SZ_16M, &cs_mem_base) < 0) {
  162. printk(KERN_ERR "Failed request for GPMC mem for smsc911x\n");
  163. return;
  164. }
  165. overo_smsc911x_resources[0].start = cs_mem_base + 0x0;
  166. overo_smsc911x_resources[0].end = cs_mem_base + 0xff;
  167. if ((gpio_request(OVERO_SMSC911X_GPIO, "SMSC911X IRQ") == 0) &&
  168. (gpio_direction_input(OVERO_SMSC911X_GPIO) == 0)) {
  169. gpio_export(OVERO_SMSC911X_GPIO, 0);
  170. } else {
  171. printk(KERN_ERR "could not obtain gpio for SMSC911X IRQ\n");
  172. return;
  173. }
  174. overo_smsc911x_resources[1].start = OMAP_GPIO_IRQ(OVERO_SMSC911X_GPIO);
  175. overo_smsc911x_resources[1].end = 0;
  176. /* set up second smsc911x chip */
  177. if (gpmc_cs_request(OVERO_SMSC911X2_CS, SZ_16M, &cs_mem_base2) < 0) {
  178. printk(KERN_ERR "Failed request for GPMC mem for smsc911x2\n");
  179. return;
  180. }
  181. overo_smsc911x2_resources[0].start = cs_mem_base2 + 0x0;
  182. overo_smsc911x2_resources[0].end = cs_mem_base2 + 0xff;
  183. if ((gpio_request(OVERO_SMSC911X2_GPIO, "SMSC911X2 IRQ") == 0) &&
  184. (gpio_direction_input(OVERO_SMSC911X2_GPIO) == 0)) {
  185. gpio_export(OVERO_SMSC911X2_GPIO, 0);
  186. } else {
  187. printk(KERN_ERR "could not obtain gpio for SMSC911X2 IRQ\n");
  188. return;
  189. }
  190. overo_smsc911x2_resources[1].start = OMAP_GPIO_IRQ(OVERO_SMSC911X2_GPIO);
  191. overo_smsc911x2_resources[1].end = 0;
  192. platform_add_devices(smsc911x_devices, ARRAY_SIZE(smsc911x_devices));
  193. }
  194. #else
  195. static inline void __init overo_init_smsc911x(void) { return; }
  196. #endif
  197. static struct mtd_partition overo_nand_partitions[] = {
  198. {
  199. .name = "xloader",
  200. .offset = 0, /* Offset = 0x00000 */
  201. .size = 4 * NAND_BLOCK_SIZE,
  202. .mask_flags = MTD_WRITEABLE
  203. },
  204. {
  205. .name = "uboot",
  206. .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
  207. .size = 14 * NAND_BLOCK_SIZE,
  208. },
  209. {
  210. .name = "uboot environment",
  211. .offset = MTDPART_OFS_APPEND, /* Offset = 0x240000 */
  212. .size = 2 * NAND_BLOCK_SIZE,
  213. },
  214. {
  215. .name = "linux",
  216. .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
  217. .size = 32 * NAND_BLOCK_SIZE,
  218. },
  219. {
  220. .name = "rootfs",
  221. .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
  222. .size = MTDPART_SIZ_FULL,
  223. },
  224. };
  225. static struct omap_nand_platform_data overo_nand_data = {
  226. .parts = overo_nand_partitions,
  227. .nr_parts = ARRAY_SIZE(overo_nand_partitions),
  228. .dma_channel = -1, /* disable DMA in OMAP NAND driver */
  229. };
  230. static void __init overo_flash_init(void)
  231. {
  232. u8 cs = 0;
  233. u8 nandcs = GPMC_CS_NUM + 1;
  234. /* find out the chip-select on which NAND exists */
  235. while (cs < GPMC_CS_NUM) {
  236. u32 ret = 0;
  237. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  238. if ((ret & 0xC00) == 0x800) {
  239. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  240. if (nandcs > GPMC_CS_NUM)
  241. nandcs = cs;
  242. }
  243. cs++;
  244. }
  245. if (nandcs > GPMC_CS_NUM) {
  246. printk(KERN_INFO "NAND: Unable to find configuration "
  247. "in GPMC\n ");
  248. return;
  249. }
  250. if (nandcs < GPMC_CS_NUM) {
  251. overo_nand_data.cs = nandcs;
  252. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  253. if (gpmc_nand_init(&overo_nand_data) < 0)
  254. printk(KERN_ERR "Unable to register NAND device\n");
  255. }
  256. }
  257. static struct omap2_hsmmc_info mmc[] = {
  258. {
  259. .mmc = 1,
  260. .caps = MMC_CAP_4_BIT_DATA,
  261. .gpio_cd = -EINVAL,
  262. .gpio_wp = -EINVAL,
  263. },
  264. {
  265. .mmc = 2,
  266. .caps = MMC_CAP_4_BIT_DATA,
  267. .gpio_cd = -EINVAL,
  268. .gpio_wp = -EINVAL,
  269. .transceiver = true,
  270. .ocr_mask = 0x00100000, /* 3.3V */
  271. },
  272. {} /* Terminator */
  273. };
  274. static struct regulator_consumer_supply overo_vmmc1_supply = {
  275. .supply = "vmmc",
  276. };
  277. static int overo_twl_gpio_setup(struct device *dev,
  278. unsigned gpio, unsigned ngpio)
  279. {
  280. omap2_hsmmc_init(mmc);
  281. overo_vmmc1_supply.dev = mmc[0].dev;
  282. return 0;
  283. }
  284. static struct twl4030_gpio_platform_data overo_gpio_data = {
  285. .gpio_base = OMAP_MAX_GPIO_LINES,
  286. .irq_base = TWL4030_GPIO_IRQ_BASE,
  287. .irq_end = TWL4030_GPIO_IRQ_END,
  288. .setup = overo_twl_gpio_setup,
  289. };
  290. static struct twl4030_usb_data overo_usb_data = {
  291. .usb_mode = T2_USB_MODE_ULPI,
  292. };
  293. static struct regulator_init_data overo_vmmc1 = {
  294. .constraints = {
  295. .min_uV = 1850000,
  296. .max_uV = 3150000,
  297. .valid_modes_mask = REGULATOR_MODE_NORMAL
  298. | REGULATOR_MODE_STANDBY,
  299. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  300. | REGULATOR_CHANGE_MODE
  301. | REGULATOR_CHANGE_STATUS,
  302. },
  303. .num_consumer_supplies = 1,
  304. .consumer_supplies = &overo_vmmc1_supply,
  305. };
  306. static struct twl4030_codec_audio_data overo_audio_data = {
  307. .audio_mclk = 26000000,
  308. };
  309. static struct twl4030_codec_data overo_codec_data = {
  310. .audio_mclk = 26000000,
  311. .audio = &overo_audio_data,
  312. };
  313. /* mmc2 (WLAN) and Bluetooth don't use twl4030 regulators */
  314. static struct twl4030_platform_data overo_twldata = {
  315. .irq_base = TWL4030_IRQ_BASE,
  316. .irq_end = TWL4030_IRQ_END,
  317. .gpio = &overo_gpio_data,
  318. .usb = &overo_usb_data,
  319. .codec = &overo_codec_data,
  320. .vmmc1 = &overo_vmmc1,
  321. };
  322. static struct i2c_board_info __initdata overo_i2c_boardinfo[] = {
  323. {
  324. I2C_BOARD_INFO("tps65950", 0x48),
  325. .flags = I2C_CLIENT_WAKE,
  326. .irq = INT_34XX_SYS_NIRQ,
  327. .platform_data = &overo_twldata,
  328. },
  329. };
  330. static int __init overo_i2c_init(void)
  331. {
  332. omap_register_i2c_bus(1, 2600, overo_i2c_boardinfo,
  333. ARRAY_SIZE(overo_i2c_boardinfo));
  334. /* i2c2 pins are used for gpio */
  335. omap_register_i2c_bus(3, 400, NULL, 0);
  336. return 0;
  337. }
  338. static struct platform_device overo_lcd_device = {
  339. .name = "overo_lcd",
  340. .id = -1,
  341. };
  342. static struct omap_lcd_config overo_lcd_config __initdata = {
  343. .ctrl_name = "internal",
  344. };
  345. static struct omap_board_config_kernel overo_config[] __initdata = {
  346. { OMAP_TAG_LCD, &overo_lcd_config },
  347. };
  348. static void __init overo_init_irq(void)
  349. {
  350. omap_board_config = overo_config;
  351. omap_board_config_size = ARRAY_SIZE(overo_config);
  352. omap2_init_common_hw(mt46h32m32lf6_sdrc_params,
  353. mt46h32m32lf6_sdrc_params);
  354. omap_init_irq();
  355. omap_gpio_init();
  356. }
  357. static struct platform_device *overo_devices[] __initdata = {
  358. &overo_lcd_device,
  359. };
  360. static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
  361. .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN,
  362. .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY,
  363. .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
  364. .phy_reset = true,
  365. .reset_gpio_port[0] = -EINVAL,
  366. .reset_gpio_port[1] = OVERO_GPIO_USBH_NRESET,
  367. .reset_gpio_port[2] = -EINVAL
  368. };
  369. #ifdef CONFIG_OMAP_MUX
  370. static struct omap_board_mux board_mux[] __initdata = {
  371. { .reg_offset = OMAP_MUX_TERMINATOR },
  372. };
  373. #else
  374. #define board_mux NULL
  375. #endif
  376. static struct omap_musb_board_data musb_board_data = {
  377. .interface_type = MUSB_INTERFACE_ULPI,
  378. .mode = MUSB_OTG,
  379. .power = 100,
  380. };
  381. static void __init overo_init(void)
  382. {
  383. omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
  384. overo_i2c_init();
  385. platform_add_devices(overo_devices, ARRAY_SIZE(overo_devices));
  386. omap_serial_init();
  387. overo_flash_init();
  388. usb_musb_init(&musb_board_data);
  389. usb_ehci_init(&ehci_pdata);
  390. overo_ads7846_init();
  391. overo_init_smsc911x();
  392. /* Ensure SDRC pins are mux'd for self-refresh */
  393. omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT);
  394. omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT);
  395. if ((gpio_request(OVERO_GPIO_W2W_NRESET,
  396. "OVERO_GPIO_W2W_NRESET") == 0) &&
  397. (gpio_direction_output(OVERO_GPIO_W2W_NRESET, 1) == 0)) {
  398. gpio_export(OVERO_GPIO_W2W_NRESET, 0);
  399. gpio_set_value(OVERO_GPIO_W2W_NRESET, 0);
  400. udelay(10);
  401. gpio_set_value(OVERO_GPIO_W2W_NRESET, 1);
  402. } else {
  403. printk(KERN_ERR "could not obtain gpio for "
  404. "OVERO_GPIO_W2W_NRESET\n");
  405. }
  406. if ((gpio_request(OVERO_GPIO_BT_XGATE, "OVERO_GPIO_BT_XGATE") == 0) &&
  407. (gpio_direction_output(OVERO_GPIO_BT_XGATE, 0) == 0))
  408. gpio_export(OVERO_GPIO_BT_XGATE, 0);
  409. else
  410. printk(KERN_ERR "could not obtain gpio for OVERO_GPIO_BT_XGATE\n");
  411. if ((gpio_request(OVERO_GPIO_BT_NRESET, "OVERO_GPIO_BT_NRESET") == 0) &&
  412. (gpio_direction_output(OVERO_GPIO_BT_NRESET, 1) == 0)) {
  413. gpio_export(OVERO_GPIO_BT_NRESET, 0);
  414. gpio_set_value(OVERO_GPIO_BT_NRESET, 0);
  415. mdelay(6);
  416. gpio_set_value(OVERO_GPIO_BT_NRESET, 1);
  417. } else {
  418. printk(KERN_ERR "could not obtain gpio for "
  419. "OVERO_GPIO_BT_NRESET\n");
  420. }
  421. if ((gpio_request(OVERO_GPIO_USBH_CPEN, "OVERO_GPIO_USBH_CPEN") == 0) &&
  422. (gpio_direction_output(OVERO_GPIO_USBH_CPEN, 1) == 0))
  423. gpio_export(OVERO_GPIO_USBH_CPEN, 0);
  424. else
  425. printk(KERN_ERR "could not obtain gpio for "
  426. "OVERO_GPIO_USBH_CPEN\n");
  427. }
  428. MACHINE_START(OVERO, "Gumstix Overo")
  429. .boot_params = 0x80000100,
  430. .map_io = omap3_map_io,
  431. .reserve = omap_reserve,
  432. .init_irq = overo_init_irq,
  433. .init_machine = overo_init,
  434. .timer = &omap_timer,
  435. MACHINE_END