board-mityomapl138.c 14 KB

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