board-mityomapl138.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /*
  2. * Critical Link MityOMAP-L138 SoM
  3. *
  4. * Copyright (C) 2010 Critical Link LLC - http://www.criticallink.com
  5. *
  6. * This file is licensed under the terms of the GNU General Public License
  7. * version 2. This program is licensed "as is" without any warranty of
  8. * any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/console.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/mtd/partitions.h>
  15. #include <linux/regulator/machine.h>
  16. #include <linux/i2c.h>
  17. #include <linux/i2c/at24.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/spi/flash.h>
  21. #include <asm/io.h>
  22. #include <asm/mach-types.h>
  23. #include <asm/mach/arch.h>
  24. #include <mach/common.h>
  25. #include <mach/cp_intc.h>
  26. #include <mach/da8xx.h>
  27. #include <mach/nand.h>
  28. #include <mach/mux.h>
  29. #include <mach/spi.h>
  30. #define MITYOMAPL138_PHY_ID ""
  31. #define FACTORY_CONFIG_MAGIC 0x012C0138
  32. #define FACTORY_CONFIG_VERSION 0x00010001
  33. /* Data Held in On-Board I2C device */
  34. struct factory_config {
  35. u32 magic;
  36. u32 version;
  37. u8 mac[6];
  38. u32 fpga_type;
  39. u32 spare;
  40. u32 serialnumber;
  41. char partnum[32];
  42. };
  43. static struct factory_config factory_config;
  44. struct part_no_info {
  45. const char *part_no; /* part number string of interest */
  46. int max_freq; /* khz */
  47. };
  48. static struct part_no_info mityomapl138_pn_info[] = {
  49. {
  50. .part_no = "L138-C",
  51. .max_freq = 300000,
  52. },
  53. {
  54. .part_no = "L138-D",
  55. .max_freq = 375000,
  56. },
  57. {
  58. .part_no = "L138-F",
  59. .max_freq = 456000,
  60. },
  61. {
  62. .part_no = "1808-C",
  63. .max_freq = 300000,
  64. },
  65. {
  66. .part_no = "1808-D",
  67. .max_freq = 375000,
  68. },
  69. {
  70. .part_no = "1808-F",
  71. .max_freq = 456000,
  72. },
  73. {
  74. .part_no = "1810-D",
  75. .max_freq = 375000,
  76. },
  77. };
  78. #ifdef CONFIG_CPU_FREQ
  79. static void mityomapl138_cpufreq_init(const char *partnum)
  80. {
  81. int i, ret;
  82. for (i = 0; partnum && i < ARRAY_SIZE(mityomapl138_pn_info); i++) {
  83. /*
  84. * the part number has additional characters beyond what is
  85. * stored in the table. This information is not needed for
  86. * determining the speed grade, and would require several
  87. * more table entries. Only check the first N characters
  88. * for a match.
  89. */
  90. if (!strncmp(partnum, mityomapl138_pn_info[i].part_no,
  91. strlen(mityomapl138_pn_info[i].part_no))) {
  92. da850_max_speed = mityomapl138_pn_info[i].max_freq;
  93. break;
  94. }
  95. }
  96. ret = da850_register_cpufreq("pll0_sysclk3");
  97. if (ret)
  98. pr_warning("cpufreq registration failed: %d\n", ret);
  99. }
  100. #else
  101. static void mityomapl138_cpufreq_init(const char *partnum) { }
  102. #endif
  103. static void read_factory_config(struct memory_accessor *a, void *context)
  104. {
  105. int ret;
  106. const char *partnum = NULL;
  107. struct davinci_soc_info *soc_info = &davinci_soc_info;
  108. ret = a->read(a, (char *)&factory_config, 0, sizeof(factory_config));
  109. if (ret != sizeof(struct factory_config)) {
  110. pr_warning("MityOMAPL138: Read Factory Config Failed: %d\n",
  111. ret);
  112. goto bad_config;
  113. }
  114. if (factory_config.magic != FACTORY_CONFIG_MAGIC) {
  115. pr_warning("MityOMAPL138: Factory Config Magic Wrong (%X)\n",
  116. factory_config.magic);
  117. goto bad_config;
  118. }
  119. if (factory_config.version != FACTORY_CONFIG_VERSION) {
  120. pr_warning("MityOMAPL138: Factory Config Version Wrong (%X)\n",
  121. factory_config.version);
  122. goto bad_config;
  123. }
  124. pr_info("MityOMAPL138: Found MAC = %pM\n", factory_config.mac);
  125. if (is_valid_ether_addr(factory_config.mac))
  126. memcpy(soc_info->emac_pdata->mac_addr,
  127. factory_config.mac, ETH_ALEN);
  128. else
  129. pr_warning("MityOMAPL138: Invalid MAC found "
  130. "in factory config block\n");
  131. partnum = factory_config.partnum;
  132. pr_info("MityOMAPL138: Part Number = %s\n", partnum);
  133. bad_config:
  134. /* default maximum speed is valid for all platforms */
  135. mityomapl138_cpufreq_init(partnum);
  136. }
  137. static struct at24_platform_data mityomapl138_fd_chip = {
  138. .byte_len = 256,
  139. .page_size = 8,
  140. .flags = AT24_FLAG_READONLY | AT24_FLAG_IRUGO,
  141. .setup = read_factory_config,
  142. .context = NULL,
  143. };
  144. static struct davinci_i2c_platform_data mityomap_i2c_0_pdata = {
  145. .bus_freq = 100, /* kHz */
  146. .bus_delay = 0, /* usec */
  147. };
  148. /* TPS65023 voltage regulator support */
  149. /* 1.2V Core */
  150. static struct regulator_consumer_supply tps65023_dcdc1_consumers[] = {
  151. {
  152. .supply = "cvdd",
  153. },
  154. };
  155. /* 1.8V */
  156. static struct regulator_consumer_supply tps65023_dcdc2_consumers[] = {
  157. {
  158. .supply = "usb0_vdda18",
  159. },
  160. {
  161. .supply = "usb1_vdda18",
  162. },
  163. {
  164. .supply = "ddr_dvdd18",
  165. },
  166. {
  167. .supply = "sata_vddr",
  168. },
  169. };
  170. /* 1.2V */
  171. static struct regulator_consumer_supply tps65023_dcdc3_consumers[] = {
  172. {
  173. .supply = "sata_vdd",
  174. },
  175. {
  176. .supply = "usb_cvdd",
  177. },
  178. {
  179. .supply = "pll0_vdda",
  180. },
  181. {
  182. .supply = "pll1_vdda",
  183. },
  184. };
  185. /* 1.8V Aux LDO, not used */
  186. static struct regulator_consumer_supply tps65023_ldo1_consumers[] = {
  187. {
  188. .supply = "1.8v_aux",
  189. },
  190. };
  191. /* FPGA VCC Aux (2.5 or 3.3) LDO */
  192. static struct regulator_consumer_supply tps65023_ldo2_consumers[] = {
  193. {
  194. .supply = "vccaux",
  195. },
  196. };
  197. static struct regulator_init_data tps65023_regulator_data[] = {
  198. /* dcdc1 */
  199. {
  200. .constraints = {
  201. .min_uV = 1150000,
  202. .max_uV = 1350000,
  203. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  204. REGULATOR_CHANGE_STATUS,
  205. .boot_on = 1,
  206. },
  207. .num_consumer_supplies = ARRAY_SIZE(tps65023_dcdc1_consumers),
  208. .consumer_supplies = tps65023_dcdc1_consumers,
  209. },
  210. /* dcdc2 */
  211. {
  212. .constraints = {
  213. .min_uV = 1800000,
  214. .max_uV = 1800000,
  215. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  216. .boot_on = 1,
  217. },
  218. .num_consumer_supplies = ARRAY_SIZE(tps65023_dcdc2_consumers),
  219. .consumer_supplies = tps65023_dcdc2_consumers,
  220. },
  221. /* dcdc3 */
  222. {
  223. .constraints = {
  224. .min_uV = 1200000,
  225. .max_uV = 1200000,
  226. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  227. .boot_on = 1,
  228. },
  229. .num_consumer_supplies = ARRAY_SIZE(tps65023_dcdc3_consumers),
  230. .consumer_supplies = tps65023_dcdc3_consumers,
  231. },
  232. /* ldo1 */
  233. {
  234. .constraints = {
  235. .min_uV = 1800000,
  236. .max_uV = 1800000,
  237. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  238. .boot_on = 1,
  239. },
  240. .num_consumer_supplies = ARRAY_SIZE(tps65023_ldo1_consumers),
  241. .consumer_supplies = tps65023_ldo1_consumers,
  242. },
  243. /* ldo2 */
  244. {
  245. .constraints = {
  246. .min_uV = 2500000,
  247. .max_uV = 3300000,
  248. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  249. REGULATOR_CHANGE_STATUS,
  250. .boot_on = 1,
  251. },
  252. .num_consumer_supplies = ARRAY_SIZE(tps65023_ldo2_consumers),
  253. .consumer_supplies = tps65023_ldo2_consumers,
  254. },
  255. };
  256. static struct i2c_board_info __initdata mityomap_tps65023_info[] = {
  257. {
  258. I2C_BOARD_INFO("tps65023", 0x48),
  259. .platform_data = &tps65023_regulator_data[0],
  260. },
  261. {
  262. I2C_BOARD_INFO("24c02", 0x50),
  263. .platform_data = &mityomapl138_fd_chip,
  264. },
  265. };
  266. static int __init pmic_tps65023_init(void)
  267. {
  268. return i2c_register_board_info(1, mityomap_tps65023_info,
  269. ARRAY_SIZE(mityomap_tps65023_info));
  270. }
  271. /*
  272. * SPI Devices:
  273. * SPI1_CS0: 8M Flash ST-M25P64-VME6G
  274. */
  275. static struct mtd_partition spi_flash_partitions[] = {
  276. [0] = {
  277. .name = "ubl",
  278. .offset = 0,
  279. .size = SZ_64K,
  280. .mask_flags = MTD_WRITEABLE,
  281. },
  282. [1] = {
  283. .name = "u-boot",
  284. .offset = MTDPART_OFS_APPEND,
  285. .size = SZ_512K,
  286. .mask_flags = MTD_WRITEABLE,
  287. },
  288. [2] = {
  289. .name = "u-boot-env",
  290. .offset = MTDPART_OFS_APPEND,
  291. .size = SZ_64K,
  292. .mask_flags = MTD_WRITEABLE,
  293. },
  294. [3] = {
  295. .name = "periph-config",
  296. .offset = MTDPART_OFS_APPEND,
  297. .size = SZ_64K,
  298. .mask_flags = MTD_WRITEABLE,
  299. },
  300. [4] = {
  301. .name = "reserved",
  302. .offset = MTDPART_OFS_APPEND,
  303. .size = SZ_256K + SZ_64K,
  304. },
  305. [5] = {
  306. .name = "kernel",
  307. .offset = MTDPART_OFS_APPEND,
  308. .size = SZ_2M + SZ_1M,
  309. },
  310. [6] = {
  311. .name = "fpga",
  312. .offset = MTDPART_OFS_APPEND,
  313. .size = SZ_2M,
  314. },
  315. [7] = {
  316. .name = "spare",
  317. .offset = MTDPART_OFS_APPEND,
  318. .size = MTDPART_SIZ_FULL,
  319. },
  320. };
  321. static struct flash_platform_data mityomapl138_spi_flash_data = {
  322. .name = "m25p80",
  323. .parts = spi_flash_partitions,
  324. .nr_parts = ARRAY_SIZE(spi_flash_partitions),
  325. .type = "m24p64",
  326. };
  327. static struct davinci_spi_config spi_eprom_config = {
  328. .io_type = SPI_IO_TYPE_DMA,
  329. .c2tdelay = 8,
  330. .t2cdelay = 8,
  331. };
  332. static struct spi_board_info mityomapl138_spi_flash_info[] = {
  333. {
  334. .modalias = "m25p80",
  335. .platform_data = &mityomapl138_spi_flash_data,
  336. .controller_data = &spi_eprom_config,
  337. .mode = SPI_MODE_0,
  338. .max_speed_hz = 30000000,
  339. .bus_num = 1,
  340. .chip_select = 0,
  341. },
  342. };
  343. /*
  344. * MityDSP-L138 includes a 256 MByte large-page NAND flash
  345. * (128K blocks).
  346. */
  347. static struct mtd_partition mityomapl138_nandflash_partition[] = {
  348. {
  349. .name = "rootfs",
  350. .offset = 0,
  351. .size = SZ_128M,
  352. .mask_flags = 0, /* MTD_WRITEABLE, */
  353. },
  354. {
  355. .name = "homefs",
  356. .offset = MTDPART_OFS_APPEND,
  357. .size = MTDPART_SIZ_FULL,
  358. .mask_flags = 0,
  359. },
  360. };
  361. static struct davinci_nand_pdata mityomapl138_nandflash_data = {
  362. .parts = mityomapl138_nandflash_partition,
  363. .nr_parts = ARRAY_SIZE(mityomapl138_nandflash_partition),
  364. .ecc_mode = NAND_ECC_HW,
  365. .bbt_options = NAND_BBT_USE_FLASH,
  366. .options = NAND_BUSWIDTH_16,
  367. .ecc_bits = 1, /* 4 bit mode is not supported with 16 bit NAND */
  368. };
  369. static struct resource mityomapl138_nandflash_resource[] = {
  370. {
  371. .start = DA8XX_AEMIF_CS3_BASE,
  372. .end = DA8XX_AEMIF_CS3_BASE + SZ_512K + 2 * SZ_1K - 1,
  373. .flags = IORESOURCE_MEM,
  374. },
  375. {
  376. .start = DA8XX_AEMIF_CTL_BASE,
  377. .end = DA8XX_AEMIF_CTL_BASE + SZ_32K - 1,
  378. .flags = IORESOURCE_MEM,
  379. },
  380. };
  381. static struct platform_device mityomapl138_nandflash_device = {
  382. .name = "davinci_nand",
  383. .id = 1,
  384. .dev = {
  385. .platform_data = &mityomapl138_nandflash_data,
  386. },
  387. .num_resources = ARRAY_SIZE(mityomapl138_nandflash_resource),
  388. .resource = mityomapl138_nandflash_resource,
  389. };
  390. static struct platform_device *mityomapl138_devices[] __initdata = {
  391. &mityomapl138_nandflash_device,
  392. };
  393. static void __init mityomapl138_setup_nand(void)
  394. {
  395. platform_add_devices(mityomapl138_devices,
  396. ARRAY_SIZE(mityomapl138_devices));
  397. }
  398. static struct davinci_uart_config mityomapl138_uart_config __initdata = {
  399. .enabled_uarts = 0x7,
  400. };
  401. static const short mityomap_mii_pins[] = {
  402. DA850_MII_TXEN, DA850_MII_TXCLK, DA850_MII_COL, DA850_MII_TXD_3,
  403. DA850_MII_TXD_2, DA850_MII_TXD_1, DA850_MII_TXD_0, DA850_MII_RXER,
  404. DA850_MII_CRS, DA850_MII_RXCLK, DA850_MII_RXDV, DA850_MII_RXD_3,
  405. DA850_MII_RXD_2, DA850_MII_RXD_1, DA850_MII_RXD_0, DA850_MDIO_CLK,
  406. DA850_MDIO_D,
  407. -1
  408. };
  409. static const short mityomap_rmii_pins[] = {
  410. DA850_RMII_TXD_0, DA850_RMII_TXD_1, DA850_RMII_TXEN,
  411. DA850_RMII_CRS_DV, DA850_RMII_RXD_0, DA850_RMII_RXD_1,
  412. DA850_RMII_RXER, DA850_RMII_MHZ_50_CLK, DA850_MDIO_CLK,
  413. DA850_MDIO_D,
  414. -1
  415. };
  416. static void __init mityomapl138_config_emac(void)
  417. {
  418. void __iomem *cfg_chip3_base;
  419. int ret;
  420. u32 val;
  421. struct davinci_soc_info *soc_info = &davinci_soc_info;
  422. soc_info->emac_pdata->rmii_en = 0; /* hardcoded for now */
  423. cfg_chip3_base = DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP3_REG);
  424. val = __raw_readl(cfg_chip3_base);
  425. if (soc_info->emac_pdata->rmii_en) {
  426. val |= BIT(8);
  427. ret = davinci_cfg_reg_list(mityomap_rmii_pins);
  428. pr_info("RMII PHY configured\n");
  429. } else {
  430. val &= ~BIT(8);
  431. ret = davinci_cfg_reg_list(mityomap_mii_pins);
  432. pr_info("MII PHY configured\n");
  433. }
  434. if (ret) {
  435. pr_warning("mii/rmii mux setup failed: %d\n", ret);
  436. return;
  437. }
  438. /* configure the CFGCHIP3 register for RMII or MII */
  439. __raw_writel(val, cfg_chip3_base);
  440. soc_info->emac_pdata->phy_id = MITYOMAPL138_PHY_ID;
  441. ret = da8xx_register_emac();
  442. if (ret)
  443. pr_warning("emac registration failed: %d\n", ret);
  444. }
  445. static struct davinci_pm_config da850_pm_pdata = {
  446. .sleepcount = 128,
  447. };
  448. static struct platform_device da850_pm_device = {
  449. .name = "pm-davinci",
  450. .dev = {
  451. .platform_data = &da850_pm_pdata,
  452. },
  453. .id = -1,
  454. };
  455. static void __init mityomapl138_init(void)
  456. {
  457. int ret;
  458. /* for now, no special EDMA channels are reserved */
  459. ret = da850_register_edma(NULL);
  460. if (ret)
  461. pr_warning("edma registration failed: %d\n", ret);
  462. ret = da8xx_register_watchdog();
  463. if (ret)
  464. pr_warning("watchdog registration failed: %d\n", ret);
  465. davinci_serial_init(&mityomapl138_uart_config);
  466. ret = da8xx_register_i2c(0, &mityomap_i2c_0_pdata);
  467. if (ret)
  468. pr_warning("i2c0 registration failed: %d\n", ret);
  469. ret = pmic_tps65023_init();
  470. if (ret)
  471. pr_warning("TPS65023 PMIC init failed: %d\n", ret);
  472. mityomapl138_setup_nand();
  473. ret = da8xx_register_spi(1, mityomapl138_spi_flash_info,
  474. ARRAY_SIZE(mityomapl138_spi_flash_info));
  475. if (ret)
  476. pr_warning("spi 1 registration failed: %d\n", ret);
  477. mityomapl138_config_emac();
  478. ret = da8xx_register_rtc();
  479. if (ret)
  480. pr_warning("rtc setup failed: %d\n", ret);
  481. ret = da8xx_register_cpuidle();
  482. if (ret)
  483. pr_warning("cpuidle registration failed: %d\n", ret);
  484. ret = da850_register_pm(&da850_pm_device);
  485. if (ret)
  486. pr_warning("da850_evm_init: suspend registration failed: %d\n",
  487. ret);
  488. }
  489. #ifdef CONFIG_SERIAL_8250_CONSOLE
  490. static int __init mityomapl138_console_init(void)
  491. {
  492. if (!machine_is_mityomapl138())
  493. return 0;
  494. return add_preferred_console("ttyS", 1, "115200");
  495. }
  496. console_initcall(mityomapl138_console_init);
  497. #endif
  498. static void __init mityomapl138_map_io(void)
  499. {
  500. da850_init();
  501. }
  502. MACHINE_START(MITYOMAPL138, "MityDSP-L138/MityARM-1808")
  503. .atag_offset = 0x100,
  504. .map_io = mityomapl138_map_io,
  505. .init_irq = cp_intc_init,
  506. .timer = &davinci_timer,
  507. .init_machine = mityomapl138_init,
  508. .dma_zone_size = SZ_128M,
  509. .restart = da8xx_restart,
  510. MACHINE_END