PageRenderTime 114ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel-2.6.29/arch/arm/mach-omap2/board-omap3beagle.c

https://github.com/robots/Beagleboard-OSy2010
C | 596 lines | 467 code | 86 blank | 43 comment | 12 complexity | 45442e17da4163136adc9c122042c9d6 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*
  2. * linux/arch/arm/mach-omap2/board-omap3beagle.c
  3. *
  4. * Copyright (C) 2008 Texas Instruments
  5. *
  6. * Modified from mach-omap2/board-3430sdp.c
  7. *
  8. * Initial code: Syed Mohammed Khasim
  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. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/delay.h>
  18. #include <linux/err.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/leds.h>
  22. #include <linux/gpio.h>
  23. #include <linux/input.h>
  24. #include <linux/gpio_keys.h>
  25. #include <linux/mtd/mtd.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <linux/mtd/nand.h>
  28. #include <linux/regulator/machine.h>
  29. #include <linux/i2c/twl4030.h>
  30. #include <linux/omapfb.h>
  31. #include <mach/hardware.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/map.h>
  35. #include <asm/mach/flash.h>
  36. #include <mach/board.h>
  37. #include <mach/usb.h>
  38. #include <mach/common.h>
  39. #include <mach/gpmc.h>
  40. #include <mach/nand.h>
  41. #include <mach/mux.h>
  42. #include <mach/display.h>
  43. #include <linux/spi/spi.h>
  44. #include <socketcan/can/platform/stm32bb.h>
  45. #include "twl4030-generic-scripts.h"
  46. #include "mmc-twl4030.h"
  47. #define GPMC_CS0_BASE 0x60
  48. #define GPMC_CS_SIZE 0x30
  49. #define NAND_BLOCK_SIZE SZ_128K
  50. static struct mtd_partition omap3beagle_nand_partitions[] = {
  51. /* All the partition sizes are listed in terms of NAND block size */
  52. {
  53. .name = "X-Loader",
  54. .offset = 0,
  55. .size = 4 * NAND_BLOCK_SIZE,
  56. .mask_flags = MTD_WRITEABLE, /* force read-only */
  57. },
  58. {
  59. .name = "U-Boot",
  60. .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */
  61. .size = 15 * NAND_BLOCK_SIZE,
  62. .mask_flags = MTD_WRITEABLE, /* force read-only */
  63. },
  64. {
  65. .name = "U-Boot Env",
  66. .offset = MTDPART_OFS_APPEND, /* Offset = 0x260000 */
  67. .size = 1 * NAND_BLOCK_SIZE,
  68. },
  69. {
  70. .name = "Kernel",
  71. .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */
  72. .size = 32 * NAND_BLOCK_SIZE,
  73. },
  74. {
  75. .name = "File System",
  76. .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */
  77. .size = MTDPART_SIZ_FULL,
  78. },
  79. };
  80. static struct omap_nand_platform_data omap3beagle_nand_data = {
  81. .options = NAND_BUSWIDTH_16,
  82. .parts = omap3beagle_nand_partitions,
  83. .nr_parts = ARRAY_SIZE(omap3beagle_nand_partitions),
  84. .dma_channel = -1, /* disable DMA in OMAP NAND driver */
  85. .nand_setup = NULL,
  86. .dev_ready = NULL,
  87. };
  88. static struct resource omap3beagle_nand_resource = {
  89. .flags = IORESOURCE_MEM,
  90. };
  91. static struct platform_device omap3beagle_nand_device = {
  92. .name = "omap2-nand",
  93. .id = -1,
  94. .dev = {
  95. .platform_data = &omap3beagle_nand_data,
  96. },
  97. .num_resources = 1,
  98. .resource = &omap3beagle_nand_resource,
  99. };
  100. #include "sdram-micron-mt46h32m32lf-6.h"
  101. static struct omap_uart_config omap3_beagle_uart_config __initdata = {
  102. .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)),
  103. };
  104. static struct twl4030_usb_data beagle_usb_data = {
  105. .usb_mode = T2_USB_MODE_ULPI,
  106. };
  107. static struct twl4030_hsmmc_info mmc[] = {
  108. {
  109. .mmc = 1,
  110. .wires = 8,
  111. .gpio_wp = 29,
  112. },
  113. {} /* Terminator */
  114. };
  115. static struct regulator_consumer_supply beagle_vmmc1_supply = {
  116. .supply = "vmmc",
  117. };
  118. static struct regulator_consumer_supply beagle_vsim_supply = {
  119. .supply = "vmmc_aux",
  120. };
  121. static struct gpio_led gpio_leds[];
  122. static int beagle_twl_gpio_setup(struct device *dev,
  123. unsigned gpio, unsigned ngpio)
  124. {
  125. /* gpio + 0 is "mmc0_cd" (input/IRQ) */
  126. omap_cfg_reg(AH8_34XX_GPIO29);
  127. mmc[0].gpio_cd = gpio + 0;
  128. twl4030_mmc_init(mmc);
  129. /* link regulators to MMC adapters */
  130. beagle_vmmc1_supply.dev = mmc[0].dev;
  131. beagle_vsim_supply.dev = mmc[0].dev;
  132. /* REVISIT: need ehci-omap hooks for external VBUS
  133. * power switch and overcurrent detect
  134. */
  135. #if 0 /* TODO: This needs to be modified to not rely on u-boot */
  136. gpio_request(gpio + 1, "EHCI_nOC");
  137. gpio_direction_input(gpio + 1);
  138. /* TWL4030_GPIO_MAX + 0 == ledA, EHCI nEN_USB_PWR (out, active low) */
  139. gpio_request(gpio + TWL4030_GPIO_MAX, "nEN_USB_PWR");
  140. gpio_direction_output(gpio + TWL4030_GPIO_MAX, 1);
  141. #endif
  142. /* TWL4030_GPIO_MAX + 1 == ledB, PMU_STAT (out, active low LED) */
  143. gpio_leds[2].gpio = gpio + TWL4030_GPIO_MAX + 1;
  144. return 0;
  145. }
  146. static struct twl4030_gpio_platform_data beagle_gpio_data = {
  147. .gpio_base = OMAP_MAX_GPIO_LINES,
  148. .irq_base = TWL4030_GPIO_IRQ_BASE,
  149. .irq_end = TWL4030_GPIO_IRQ_END,
  150. .use_leds = true,
  151. .pullups = BIT(1),
  152. .pulldowns = BIT(2) | BIT(6) | BIT(7) | BIT(8) | BIT(13)
  153. | BIT(15) | BIT(16) | BIT(17),
  154. .setup = beagle_twl_gpio_setup,
  155. };
  156. static struct platform_device omap3_beagle_lcd_device = {
  157. .name = "omap3beagle_lcd",
  158. .id = -1,
  159. };
  160. static struct regulator_consumer_supply beagle_vdac_supply = {
  161. .supply = "vdac",
  162. .dev = &omap3_beagle_lcd_device.dev,
  163. };
  164. static struct regulator_consumer_supply beagle_vdvi_supply = {
  165. .supply = "vdvi",
  166. .dev = &omap3_beagle_lcd_device.dev,
  167. };
  168. /* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
  169. static struct regulator_init_data beagle_vmmc1 = {
  170. .constraints = {
  171. .min_uV = 1850000,
  172. .max_uV = 3150000,
  173. .valid_modes_mask = REGULATOR_MODE_NORMAL
  174. | REGULATOR_MODE_STANDBY,
  175. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  176. | REGULATOR_CHANGE_MODE
  177. | REGULATOR_CHANGE_STATUS,
  178. },
  179. .num_consumer_supplies = 1,
  180. .consumer_supplies = &beagle_vmmc1_supply,
  181. };
  182. /* VSIM for MMC1 pins DAT4..DAT7 (2 mA, plus card == max 50 mA) */
  183. static struct regulator_init_data beagle_vsim = {
  184. .constraints = {
  185. .min_uV = 1800000,
  186. .max_uV = 3000000,
  187. .valid_modes_mask = REGULATOR_MODE_NORMAL
  188. | REGULATOR_MODE_STANDBY,
  189. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE
  190. | REGULATOR_CHANGE_MODE
  191. | REGULATOR_CHANGE_STATUS,
  192. },
  193. .num_consumer_supplies = 1,
  194. .consumer_supplies = &beagle_vsim_supply,
  195. };
  196. /* VDAC for DSS driving S-Video (8 mA unloaded, max 65 mA) */
  197. static struct regulator_init_data beagle_vdac = {
  198. .constraints = {
  199. .min_uV = 1800000,
  200. .max_uV = 1800000,
  201. .valid_modes_mask = REGULATOR_MODE_NORMAL
  202. | REGULATOR_MODE_STANDBY,
  203. .valid_ops_mask = REGULATOR_CHANGE_MODE
  204. | REGULATOR_CHANGE_STATUS,
  205. },
  206. .num_consumer_supplies = 1,
  207. .consumer_supplies = &beagle_vdac_supply,
  208. };
  209. /* VPLL2 for digital video outputs */
  210. static struct regulator_init_data beagle_vpll2 = {
  211. .constraints = {
  212. .name = "VDVI",
  213. .min_uV = 1800000,
  214. .max_uV = 1800000,
  215. .valid_modes_mask = REGULATOR_MODE_NORMAL
  216. | REGULATOR_MODE_STANDBY,
  217. .valid_ops_mask = REGULATOR_CHANGE_MODE
  218. | REGULATOR_CHANGE_STATUS,
  219. },
  220. .num_consumer_supplies = 1,
  221. .consumer_supplies = &beagle_vdvi_supply,
  222. };
  223. static const struct twl4030_resconfig beagle_resconfig[] = {
  224. /* disable regulators that u-boot left enabled; the
  225. * devices' drivers should be managing these.
  226. */
  227. { .resource = RES_VAUX3, }, /* not even connected! */
  228. { .resource = RES_VMMC1, },
  229. { .resource = RES_VSIM, },
  230. { .resource = RES_VPLL2, },
  231. { .resource = RES_VDAC, },
  232. { .resource = RES_VUSB_1V5, },
  233. { .resource = RES_VUSB_1V8, },
  234. { .resource = RES_VUSB_3V1, },
  235. { 0, },
  236. };
  237. static struct twl4030_power_data beagle_power_data = {
  238. .resource_config = beagle_resconfig,
  239. /* REVISIT can't use GENERIC3430_T2SCRIPTS_DATA;
  240. * among other things, it makes reboot fail.
  241. */
  242. };
  243. static struct twl4030_platform_data beagle_twldata = {
  244. .irq_base = TWL4030_IRQ_BASE,
  245. .irq_end = TWL4030_IRQ_END,
  246. /* platform_data for children goes here */
  247. .usb = &beagle_usb_data,
  248. .gpio = &beagle_gpio_data,
  249. .power = &beagle_power_data,
  250. .vmmc1 = &beagle_vmmc1,
  251. .vsim = &beagle_vsim,
  252. .vdac = &beagle_vdac,
  253. .vpll2 = &beagle_vpll2,
  254. };
  255. static struct i2c_board_info __initdata beagle_i2c_rtc[] = {
  256. {
  257. I2C_BOARD_INFO("pcf8563", 0x51),
  258. },
  259. };
  260. static struct i2c_board_info __initdata beagle_i2c_boardinfo[] = {
  261. {
  262. I2C_BOARD_INFO("twl4030", 0x48),
  263. .flags = I2C_CLIENT_WAKE,
  264. .irq = INT_34XX_SYS_NIRQ,
  265. .platform_data = &beagle_twldata,
  266. },
  267. };
  268. static int __init omap3_beagle_i2c_init(void)
  269. {
  270. omap_register_i2c_bus(1, 2600, beagle_i2c_boardinfo,
  271. ARRAY_SIZE(beagle_i2c_boardinfo));
  272. omap_register_i2c_bus(2, 100, beagle_i2c_rtc,
  273. ARRAY_SIZE(beagle_i2c_rtc));
  274. /* Bus 3 is attached to the DVI port where devices like the pico DLP
  275. * projector don't work reliably with 400kHz */
  276. omap_register_i2c_bus(3, 100, NULL, 0);
  277. return 0;
  278. }
  279. /* SPI */
  280. static int stm32bb_setup(struct spi_device *spi)
  281. {
  282. /* irq pin */
  283. gpio_request(157, "stm32bb_irq");
  284. gpio_direction_input(157);
  285. /* data ready pin */
  286. gpio_request(140, "stm32bb_dr");
  287. gpio_direction_input(140);
  288. return 0;
  289. }
  290. static struct stm32bb_platform_data stm32bb_info = {
  291. .board_specific_setup = &stm32bb_setup,
  292. .transfer_ready = OMAP_GPIO_IRQ(140)
  293. };
  294. static struct spi_board_info beagle_spi_board_info[] = {
  295. {
  296. .modalias = "stm32bb",
  297. .platform_data = &stm32bb_info,
  298. .irq = OMAP_GPIO_IRQ(157),
  299. .max_speed_hz = 20*1000*1000,
  300. .chip_select = 0,
  301. .bus_num = 3,
  302. .mode = SPI_MODE_0,
  303. },
  304. {
  305. .modalias = "enc424j600",
  306. .chip_select = 0,
  307. .irq = OMAP_GPIO_IRQ(141),
  308. .max_speed_hz = 14*1000*1000,
  309. .bus_num = 4,
  310. .mode = SPI_MODE_0 | SPI_CS_HIGH,
  311. },
  312. };
  313. static void __init omap3_beagle_init_irq(void)
  314. {
  315. omap2_init_common_hw(mt46h32m32lf6_sdrc_params);
  316. omap_init_irq();
  317. omap_gpio_init();
  318. }
  319. static struct gpio_led gpio_leds[] = {
  320. {
  321. .name = "beagleboard::usr0",
  322. .default_trigger = "heartbeat",
  323. .gpio = 150,
  324. },
  325. {
  326. .name = "beagleboard::usr1",
  327. .default_trigger = "mmc0",
  328. .gpio = 149,
  329. },
  330. {
  331. .name = "beagleboard::pmu_stat",
  332. .gpio = -EINVAL, /* gets replaced */
  333. .active_low = true,
  334. },
  335. };
  336. static struct gpio_led_platform_data gpio_led_info = {
  337. .leds = gpio_leds,
  338. .num_leds = ARRAY_SIZE(gpio_leds),
  339. };
  340. static struct platform_device leds_gpio = {
  341. .name = "leds-gpio",
  342. .id = -1,
  343. .dev = {
  344. .platform_data = &gpio_led_info,
  345. },
  346. };
  347. static struct gpio_keys_button gpio_buttons[] = {
  348. {
  349. .code = BTN_EXTRA,
  350. .gpio = 7,
  351. .desc = "user",
  352. .wakeup = 1,
  353. },
  354. };
  355. static struct gpio_keys_platform_data gpio_key_info = {
  356. .buttons = gpio_buttons,
  357. .nbuttons = ARRAY_SIZE(gpio_buttons),
  358. };
  359. static struct platform_device keys_gpio = {
  360. .name = "gpio-keys",
  361. .id = -1,
  362. .dev = {
  363. .platform_data = &gpio_key_info,
  364. },
  365. };
  366. /* DSS */
  367. static int beagle_enable_dvi(struct omap_display *display)
  368. {
  369. if (display->hw_config.panel_reset_gpio != -1)
  370. gpio_set_value(display->hw_config.panel_reset_gpio, 1);
  371. return 0;
  372. }
  373. static void beagle_disable_dvi(struct omap_display *display)
  374. {
  375. if (display->hw_config.panel_reset_gpio != -1)
  376. gpio_set_value(display->hw_config.panel_reset_gpio, 0);
  377. }
  378. static struct omap_dss_display_config beagle_display_data_dvi = {
  379. .type = OMAP_DISPLAY_TYPE_DPI,
  380. .name = "dvi",
  381. .panel_name = "panel-generic",
  382. .u.dpi.data_lines = 24,
  383. .panel_reset_gpio = 170,
  384. .panel_enable = beagle_enable_dvi,
  385. .panel_disable = beagle_disable_dvi,
  386. };
  387. static int beagle_panel_enable_tv(struct omap_display *display)
  388. {
  389. #define ENABLE_VDAC_DEDICATED 0x03
  390. #define ENABLE_VDAC_DEV_GRP 0x20
  391. twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
  392. ENABLE_VDAC_DEDICATED,
  393. TWL4030_VDAC_DEDICATED);
  394. twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
  395. ENABLE_VDAC_DEV_GRP, TWL4030_VDAC_DEV_GRP);
  396. return 0;
  397. }
  398. static void beagle_panel_disable_tv(struct omap_display *display)
  399. {
  400. twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
  401. TWL4030_VDAC_DEDICATED);
  402. twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x00,
  403. TWL4030_VDAC_DEV_GRP);
  404. }
  405. static struct omap_dss_display_config beagle_display_data_tv = {
  406. .type = OMAP_DISPLAY_TYPE_VENC,
  407. .name = "tv",
  408. .u.venc.type = OMAP_DSS_VENC_TYPE_SVIDEO,
  409. .panel_enable = beagle_panel_enable_tv,
  410. .panel_disable = beagle_panel_disable_tv,
  411. };
  412. static struct omap_dss_board_info beagle_dss_data = {
  413. .num_displays = 2,
  414. .displays = {
  415. &beagle_display_data_dvi,
  416. &beagle_display_data_tv,
  417. }
  418. };
  419. static struct platform_device beagle_dss_device = {
  420. .name = "omapdss",
  421. .id = -1,
  422. .dev = {
  423. .platform_data = &beagle_dss_data,
  424. },
  425. };
  426. static void __init beagle_display_init(void)
  427. {
  428. int r;
  429. r = gpio_request(beagle_display_data_dvi.panel_reset_gpio, "DVI reset");
  430. if (r < 0) {
  431. printk(KERN_ERR "Unable to get DVI reset GPIO\n");
  432. return;
  433. }
  434. gpio_direction_output(beagle_display_data_dvi.panel_reset_gpio, 0);
  435. }
  436. static struct omap_board_config_kernel omap3_beagle_config[] __initdata = {
  437. { OMAP_TAG_UART, &omap3_beagle_uart_config },
  438. };
  439. static struct platform_device *omap3_beagle_devices[] __initdata = {
  440. &beagle_dss_device,
  441. &leds_gpio,
  442. &keys_gpio,
  443. };
  444. static void __init omap3beagle_flash_init(void)
  445. {
  446. u8 cs = 0;
  447. u8 nandcs = GPMC_CS_NUM + 1;
  448. u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
  449. /* find out the chip-select on which NAND exists */
  450. while (cs < GPMC_CS_NUM) {
  451. u32 ret = 0;
  452. ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
  453. if ((ret & 0xC00) == 0x800) {
  454. printk(KERN_INFO "Found NAND on CS%d\n", cs);
  455. if (nandcs > GPMC_CS_NUM)
  456. nandcs = cs;
  457. }
  458. cs++;
  459. }
  460. if (nandcs > GPMC_CS_NUM) {
  461. printk(KERN_INFO "NAND: Unable to find configuration "
  462. "in GPMC\n ");
  463. return;
  464. }
  465. if (nandcs < GPMC_CS_NUM) {
  466. omap3beagle_nand_data.cs = nandcs;
  467. omap3beagle_nand_data.gpmc_cs_baseaddr = (void *)
  468. (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
  469. omap3beagle_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
  470. printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
  471. if (platform_device_register(&omap3beagle_nand_device) < 0)
  472. printk(KERN_ERR "Unable to register NAND device\n");
  473. }
  474. }
  475. static void __init omap3_beagle_init(void)
  476. {
  477. omap3_beagle_i2c_init();
  478. platform_add_devices(omap3_beagle_devices,
  479. ARRAY_SIZE(omap3_beagle_devices));
  480. omap_board_config = omap3_beagle_config;
  481. omap_board_config_size = ARRAY_SIZE(omap3_beagle_config);
  482. omap_serial_init();
  483. omap_cfg_reg(J25_34XX_GPIO170);
  484. usb_musb_init();
  485. usb_ehci_init();
  486. omap3beagle_flash_init();
  487. beagle_display_init();
  488. /* TODO: these have to be moved to device specific init
  489. * once the drivers are ready
  490. */
  491. gpio_request(141, "enc424j600_irq");
  492. gpio_direction_input(141);
  493. spi_register_board_info(beagle_spi_board_info,
  494. ARRAY_SIZE(beagle_spi_board_info));
  495. }
  496. static void __init omap3_beagle_map_io(void)
  497. {
  498. omap2_set_globals_343x();
  499. omap2_map_common_io();
  500. }
  501. MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
  502. /* Maintainer: Syed Mohammed Khasim - http://beagleboard.org */
  503. .phys_io = 0x48000000,
  504. .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc,
  505. .boot_params = 0x80000100,
  506. .map_io = omap3_beagle_map_io,
  507. .init_irq = omap3_beagle_init_irq,
  508. .init_machine = omap3_beagle_init,
  509. .timer = &omap_timer,
  510. MACHINE_END