board-dm365-evm.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /*
  2. * TI DaVinci DM365 EVM board support
  3. *
  4. * Copyright (C) 2009 Texas Instruments Incorporated
  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 as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/err.h>
  18. #include <linux/i2c.h>
  19. #include <linux/io.h>
  20. #include <linux/clk.h>
  21. #include <linux/i2c/at24.h>
  22. #include <linux/leds.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <linux/mtd/nand.h>
  26. #include <linux/input.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/mach/arch.h>
  29. #include <mach/mux.h>
  30. #include <mach/dm365.h>
  31. #include <mach/common.h>
  32. #include <mach/i2c.h>
  33. #include <mach/serial.h>
  34. #include <mach/mmc.h>
  35. #include <mach/nand.h>
  36. #include <mach/keyscan.h>
  37. static inline int have_imager(void)
  38. {
  39. /* REVISIT when it's supported, trigger via Kconfig */
  40. return 0;
  41. }
  42. static inline int have_tvp7002(void)
  43. {
  44. /* REVISIT when it's supported, trigger via Kconfig */
  45. return 0;
  46. }
  47. #define DM365_ASYNC_EMIF_CONTROL_BASE 0x01d10000
  48. #define DM365_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
  49. #define DM365_ASYNC_EMIF_DATA_CE1_BASE 0x04000000
  50. #define DM365_EVM_PHY_MASK (0x2)
  51. #define DM365_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
  52. /*
  53. * A MAX-II CPLD is used for various board control functions.
  54. */
  55. #define CPLD_OFFSET(a13a8,a2a1) (((a13a8) << 10) + ((a2a1) << 3))
  56. #define CPLD_VERSION CPLD_OFFSET(0,0) /* r/o */
  57. #define CPLD_TEST CPLD_OFFSET(0,1)
  58. #define CPLD_LEDS CPLD_OFFSET(0,2)
  59. #define CPLD_MUX CPLD_OFFSET(0,3)
  60. #define CPLD_SWITCH CPLD_OFFSET(1,0) /* r/o */
  61. #define CPLD_POWER CPLD_OFFSET(1,1)
  62. #define CPLD_VIDEO CPLD_OFFSET(1,2)
  63. #define CPLD_CARDSTAT CPLD_OFFSET(1,3) /* r/o */
  64. #define CPLD_DILC_OUT CPLD_OFFSET(2,0)
  65. #define CPLD_DILC_IN CPLD_OFFSET(2,1) /* r/o */
  66. #define CPLD_IMG_DIR0 CPLD_OFFSET(2,2)
  67. #define CPLD_IMG_MUX0 CPLD_OFFSET(2,3)
  68. #define CPLD_IMG_MUX1 CPLD_OFFSET(3,0)
  69. #define CPLD_IMG_DIR1 CPLD_OFFSET(3,1)
  70. #define CPLD_IMG_MUX2 CPLD_OFFSET(3,2)
  71. #define CPLD_IMG_MUX3 CPLD_OFFSET(3,3)
  72. #define CPLD_IMG_DIR2 CPLD_OFFSET(4,0)
  73. #define CPLD_IMG_MUX4 CPLD_OFFSET(4,1)
  74. #define CPLD_IMG_MUX5 CPLD_OFFSET(4,2)
  75. #define CPLD_RESETS CPLD_OFFSET(4,3)
  76. #define CPLD_CCD_DIR1 CPLD_OFFSET(0x3e,0)
  77. #define CPLD_CCD_IO1 CPLD_OFFSET(0x3e,1)
  78. #define CPLD_CCD_DIR2 CPLD_OFFSET(0x3e,2)
  79. #define CPLD_CCD_IO2 CPLD_OFFSET(0x3e,3)
  80. #define CPLD_CCD_DIR3 CPLD_OFFSET(0x3f,0)
  81. #define CPLD_CCD_IO3 CPLD_OFFSET(0x3f,1)
  82. static void __iomem *cpld;
  83. /* NOTE: this is geared for the standard config, with a socketed
  84. * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors. If you
  85. * swap chips with a different block size, partitioning will
  86. * need to be changed. This NAND chip MT29F16G08FAA is the default
  87. * NAND shipped with the Spectrum Digital DM365 EVM
  88. */
  89. #define NAND_BLOCK_SIZE SZ_128K
  90. static struct mtd_partition davinci_nand_partitions[] = {
  91. {
  92. /* UBL (a few copies) plus U-Boot */
  93. .name = "bootloader",
  94. .offset = 0,
  95. .size = 28 * NAND_BLOCK_SIZE,
  96. .mask_flags = MTD_WRITEABLE, /* force read-only */
  97. }, {
  98. /* U-Boot environment */
  99. .name = "params",
  100. .offset = MTDPART_OFS_APPEND,
  101. .size = 2 * NAND_BLOCK_SIZE,
  102. .mask_flags = 0,
  103. }, {
  104. .name = "kernel",
  105. .offset = MTDPART_OFS_APPEND,
  106. .size = SZ_4M,
  107. .mask_flags = 0,
  108. }, {
  109. .name = "filesystem1",
  110. .offset = MTDPART_OFS_APPEND,
  111. .size = SZ_512M,
  112. .mask_flags = 0,
  113. }, {
  114. .name = "filesystem2",
  115. .offset = MTDPART_OFS_APPEND,
  116. .size = MTDPART_SIZ_FULL,
  117. .mask_flags = 0,
  118. }
  119. /* two blocks with bad block table (and mirror) at the end */
  120. };
  121. static struct davinci_nand_pdata davinci_nand_data = {
  122. .mask_chipsel = BIT(14),
  123. .parts = davinci_nand_partitions,
  124. .nr_parts = ARRAY_SIZE(davinci_nand_partitions),
  125. .ecc_mode = NAND_ECC_HW,
  126. .options = NAND_USE_FLASH_BBT,
  127. .ecc_bits = 4,
  128. };
  129. static struct resource davinci_nand_resources[] = {
  130. {
  131. .start = DM365_ASYNC_EMIF_DATA_CE0_BASE,
  132. .end = DM365_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
  133. .flags = IORESOURCE_MEM,
  134. }, {
  135. .start = DM365_ASYNC_EMIF_CONTROL_BASE,
  136. .end = DM365_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
  137. .flags = IORESOURCE_MEM,
  138. },
  139. };
  140. static struct platform_device davinci_nand_device = {
  141. .name = "davinci_nand",
  142. .id = 0,
  143. .num_resources = ARRAY_SIZE(davinci_nand_resources),
  144. .resource = davinci_nand_resources,
  145. .dev = {
  146. .platform_data = &davinci_nand_data,
  147. },
  148. };
  149. static struct at24_platform_data eeprom_info = {
  150. .byte_len = (256*1024) / 8,
  151. .page_size = 64,
  152. .flags = AT24_FLAG_ADDR16,
  153. .setup = davinci_get_mac_addr,
  154. .context = (void *)0x7f00,
  155. };
  156. static struct snd_platform_data dm365_evm_snd_data;
  157. static struct i2c_board_info i2c_info[] = {
  158. {
  159. I2C_BOARD_INFO("24c256", 0x50),
  160. .platform_data = &eeprom_info,
  161. },
  162. {
  163. I2C_BOARD_INFO("tlv320aic3x", 0x18),
  164. },
  165. };
  166. static struct davinci_i2c_platform_data i2c_pdata = {
  167. .bus_freq = 400 /* kHz */,
  168. .bus_delay = 0 /* usec */,
  169. };
  170. #ifdef CONFIG_KEYBOARD_DAVINCI
  171. static unsigned short dm365evm_keymap[] = {
  172. KEY_KP2,
  173. KEY_LEFT,
  174. KEY_EXIT,
  175. KEY_DOWN,
  176. KEY_ENTER,
  177. KEY_UP,
  178. KEY_KP1,
  179. KEY_RIGHT,
  180. KEY_MENU,
  181. KEY_RECORD,
  182. KEY_REWIND,
  183. KEY_KPMINUS,
  184. KEY_STOP,
  185. KEY_FASTFORWARD,
  186. KEY_KPPLUS,
  187. KEY_PLAYPAUSE,
  188. 0
  189. };
  190. static struct davinci_ks_platform_data dm365evm_ks_data = {
  191. .keymap = dm365evm_keymap,
  192. .keymapsize = ARRAY_SIZE(dm365evm_keymap),
  193. .rep = 1,
  194. /* Scan period = strobe + interval */
  195. .strobe = 0x5,
  196. .interval = 0x2,
  197. .matrix_type = DAVINCI_KEYSCAN_MATRIX_4X4,
  198. };
  199. #endif
  200. static int cpld_mmc_get_cd(int module)
  201. {
  202. if (!cpld)
  203. return -ENXIO;
  204. /* low == card present */
  205. return !(__raw_readb(cpld + CPLD_CARDSTAT) & BIT(module ? 4 : 0));
  206. }
  207. static int cpld_mmc_get_ro(int module)
  208. {
  209. if (!cpld)
  210. return -ENXIO;
  211. /* high == card's write protect switch active */
  212. return !!(__raw_readb(cpld + CPLD_CARDSTAT) & BIT(module ? 5 : 1));
  213. }
  214. static struct davinci_mmc_config dm365evm_mmc_config = {
  215. .get_cd = cpld_mmc_get_cd,
  216. .get_ro = cpld_mmc_get_ro,
  217. .wires = 4,
  218. .max_freq = 50000000,
  219. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  220. .version = MMC_CTLR_VERSION_2,
  221. };
  222. static void dm365evm_emac_configure(void)
  223. {
  224. /*
  225. * EMAC pins are multiplexed with GPIO and UART
  226. * Further details are available at the DM365 ARM
  227. * Subsystem Users Guide(sprufg5.pdf) pages 125 - 127
  228. */
  229. davinci_cfg_reg(DM365_EMAC_TX_EN);
  230. davinci_cfg_reg(DM365_EMAC_TX_CLK);
  231. davinci_cfg_reg(DM365_EMAC_COL);
  232. davinci_cfg_reg(DM365_EMAC_TXD3);
  233. davinci_cfg_reg(DM365_EMAC_TXD2);
  234. davinci_cfg_reg(DM365_EMAC_TXD1);
  235. davinci_cfg_reg(DM365_EMAC_TXD0);
  236. davinci_cfg_reg(DM365_EMAC_RXD3);
  237. davinci_cfg_reg(DM365_EMAC_RXD2);
  238. davinci_cfg_reg(DM365_EMAC_RXD1);
  239. davinci_cfg_reg(DM365_EMAC_RXD0);
  240. davinci_cfg_reg(DM365_EMAC_RX_CLK);
  241. davinci_cfg_reg(DM365_EMAC_RX_DV);
  242. davinci_cfg_reg(DM365_EMAC_RX_ER);
  243. davinci_cfg_reg(DM365_EMAC_CRS);
  244. davinci_cfg_reg(DM365_EMAC_MDIO);
  245. davinci_cfg_reg(DM365_EMAC_MDCLK);
  246. /*
  247. * EMAC interrupts are multiplexed with GPIO interrupts
  248. * Details are available at the DM365 ARM
  249. * Subsystem Users Guide(sprufg5.pdf) pages 133 - 134
  250. */
  251. davinci_cfg_reg(DM365_INT_EMAC_RXTHRESH);
  252. davinci_cfg_reg(DM365_INT_EMAC_RXPULSE);
  253. davinci_cfg_reg(DM365_INT_EMAC_TXPULSE);
  254. davinci_cfg_reg(DM365_INT_EMAC_MISCPULSE);
  255. }
  256. static void dm365evm_mmc_configure(void)
  257. {
  258. /*
  259. * MMC/SD pins are multiplexed with GPIO and EMIF
  260. * Further details are available at the DM365 ARM
  261. * Subsystem Users Guide(sprufg5.pdf) pages 118, 128 - 131
  262. */
  263. davinci_cfg_reg(DM365_SD1_CLK);
  264. davinci_cfg_reg(DM365_SD1_CMD);
  265. davinci_cfg_reg(DM365_SD1_DATA3);
  266. davinci_cfg_reg(DM365_SD1_DATA2);
  267. davinci_cfg_reg(DM365_SD1_DATA1);
  268. davinci_cfg_reg(DM365_SD1_DATA0);
  269. }
  270. static void __init evm_init_i2c(void)
  271. {
  272. davinci_init_i2c(&i2c_pdata);
  273. i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
  274. }
  275. static struct platform_device *dm365_evm_nand_devices[] __initdata = {
  276. &davinci_nand_device,
  277. };
  278. static inline int have_leds(void)
  279. {
  280. #ifdef CONFIG_LEDS_CLASS
  281. return 1;
  282. #else
  283. return 0;
  284. #endif
  285. }
  286. struct cpld_led {
  287. struct led_classdev cdev;
  288. u8 mask;
  289. };
  290. static const struct {
  291. const char *name;
  292. const char *trigger;
  293. } cpld_leds[] = {
  294. { "dm365evm::ds2", },
  295. { "dm365evm::ds3", },
  296. { "dm365evm::ds4", },
  297. { "dm365evm::ds5", },
  298. { "dm365evm::ds6", "nand-disk", },
  299. { "dm365evm::ds7", "mmc1", },
  300. { "dm365evm::ds8", "mmc0", },
  301. { "dm365evm::ds9", "heartbeat", },
  302. };
  303. static void cpld_led_set(struct led_classdev *cdev, enum led_brightness b)
  304. {
  305. struct cpld_led *led = container_of(cdev, struct cpld_led, cdev);
  306. u8 reg = __raw_readb(cpld + CPLD_LEDS);
  307. if (b != LED_OFF)
  308. reg &= ~led->mask;
  309. else
  310. reg |= led->mask;
  311. __raw_writeb(reg, cpld + CPLD_LEDS);
  312. }
  313. static enum led_brightness cpld_led_get(struct led_classdev *cdev)
  314. {
  315. struct cpld_led *led = container_of(cdev, struct cpld_led, cdev);
  316. u8 reg = __raw_readb(cpld + CPLD_LEDS);
  317. return (reg & led->mask) ? LED_OFF : LED_FULL;
  318. }
  319. static int __init cpld_leds_init(void)
  320. {
  321. int i;
  322. if (!have_leds() || !cpld)
  323. return 0;
  324. /* setup LEDs */
  325. __raw_writeb(0xff, cpld + CPLD_LEDS);
  326. for (i = 0; i < ARRAY_SIZE(cpld_leds); i++) {
  327. struct cpld_led *led;
  328. led = kzalloc(sizeof(*led), GFP_KERNEL);
  329. if (!led)
  330. break;
  331. led->cdev.name = cpld_leds[i].name;
  332. led->cdev.brightness_set = cpld_led_set;
  333. led->cdev.brightness_get = cpld_led_get;
  334. led->cdev.default_trigger = cpld_leds[i].trigger;
  335. led->mask = BIT(i);
  336. if (led_classdev_register(NULL, &led->cdev) < 0) {
  337. kfree(led);
  338. break;
  339. }
  340. }
  341. return 0;
  342. }
  343. /* run after subsys_initcall() for LEDs */
  344. fs_initcall(cpld_leds_init);
  345. static void __init evm_init_cpld(void)
  346. {
  347. u8 mux, resets;
  348. const char *label;
  349. struct clk *aemif_clk;
  350. /* Make sure we can configure the CPLD through CS1. Then
  351. * leave it on for later access to MMC and LED registers.
  352. */
  353. aemif_clk = clk_get(NULL, "aemif");
  354. if (IS_ERR(aemif_clk))
  355. return;
  356. clk_enable(aemif_clk);
  357. if (request_mem_region(DM365_ASYNC_EMIF_DATA_CE1_BASE, SECTION_SIZE,
  358. "cpld") == NULL)
  359. goto fail;
  360. cpld = ioremap(DM365_ASYNC_EMIF_DATA_CE1_BASE, SECTION_SIZE);
  361. if (!cpld) {
  362. release_mem_region(DM365_ASYNC_EMIF_DATA_CE1_BASE,
  363. SECTION_SIZE);
  364. fail:
  365. pr_err("ERROR: can't map CPLD\n");
  366. clk_disable(aemif_clk);
  367. return;
  368. }
  369. /* External muxing for some signals */
  370. mux = 0;
  371. /* Read SW5 to set up NAND + keypad _or_ OneNAND (sync read).
  372. * NOTE: SW4 bus width setting must match!
  373. */
  374. if ((__raw_readb(cpld + CPLD_SWITCH) & BIT(5)) == 0) {
  375. /* external keypad mux */
  376. mux |= BIT(7);
  377. platform_add_devices(dm365_evm_nand_devices,
  378. ARRAY_SIZE(dm365_evm_nand_devices));
  379. } else {
  380. /* no OneNAND support yet */
  381. }
  382. /* Leave external chips in reset when unused. */
  383. resets = BIT(3) | BIT(2) | BIT(1) | BIT(0);
  384. /* Static video input config with SN74CBT16214 1-of-3 mux:
  385. * - port b1 == tvp7002 (mux lowbits == 1 or 6)
  386. * - port b2 == imager (mux lowbits == 2 or 7)
  387. * - port b3 == tvp5146 (mux lowbits == 5)
  388. *
  389. * Runtime switching could work too, with limitations.
  390. */
  391. if (have_imager()) {
  392. label = "HD imager";
  393. mux |= 1;
  394. /* externally mux MMC1/ENET/AIC33 to imager */
  395. mux |= BIT(6) | BIT(5) | BIT(3);
  396. } else {
  397. struct davinci_soc_info *soc_info = &davinci_soc_info;
  398. /* we can use MMC1 ... */
  399. dm365evm_mmc_configure();
  400. davinci_setup_mmc(1, &dm365evm_mmc_config);
  401. /* ... and ENET ... */
  402. dm365evm_emac_configure();
  403. soc_info->emac_pdata->phy_mask = DM365_EVM_PHY_MASK;
  404. soc_info->emac_pdata->mdio_max_freq = DM365_EVM_MDIO_FREQUENCY;
  405. resets &= ~BIT(3);
  406. /* ... and AIC33 */
  407. resets &= ~BIT(1);
  408. if (have_tvp7002()) {
  409. mux |= 2;
  410. resets &= ~BIT(2);
  411. label = "tvp7002 HD";
  412. } else {
  413. /* default to tvp5146 */
  414. mux |= 5;
  415. resets &= ~BIT(0);
  416. label = "tvp5146 SD";
  417. }
  418. }
  419. __raw_writeb(mux, cpld + CPLD_MUX);
  420. __raw_writeb(resets, cpld + CPLD_RESETS);
  421. pr_info("EVM: %s video input\n", label);
  422. /* REVISIT export switches: NTSC/PAL (SW5.6), EXTRA1 (SW5.2), etc */
  423. }
  424. static struct davinci_uart_config uart_config __initdata = {
  425. .enabled_uarts = (1 << 0),
  426. };
  427. static void __init dm365_evm_map_io(void)
  428. {
  429. dm365_init();
  430. }
  431. static __init void dm365_evm_init(void)
  432. {
  433. evm_init_i2c();
  434. davinci_serial_init(&uart_config);
  435. dm365evm_emac_configure();
  436. dm365evm_mmc_configure();
  437. davinci_setup_mmc(0, &dm365evm_mmc_config);
  438. /* maybe setup mmc1/etc ... _after_ mmc0 */
  439. evm_init_cpld();
  440. dm365_init_asp(&dm365_evm_snd_data);
  441. dm365_init_rtc();
  442. #ifdef CONFIG_KEYBOARD_DAVINCI
  443. dm365_init_ks(&dm365evm_ks_data);
  444. #endif
  445. }
  446. static __init void dm365_evm_irq_init(void)
  447. {
  448. davinci_irq_init();
  449. }
  450. MACHINE_START(DAVINCI_DM365_EVM, "DaVinci DM365 EVM")
  451. .phys_io = IO_PHYS,
  452. .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
  453. .boot_params = (0x80000100),
  454. .map_io = dm365_evm_map_io,
  455. .init_irq = dm365_evm_irq_init,
  456. .timer = &davinci_timer,
  457. .init_machine = dm365_evm_init,
  458. MACHINE_END