board-mityomapl138.c 13 KB

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