board.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board functions for TI AM335X based draco board
  4. * (C) Copyright 2013 Siemens Schweiz AG
  5. * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
  6. *
  7. * Based on:
  8. *
  9. * Board functions for TI AM335X based boards
  10. * u-boot:/board/ti/am335x/board.c
  11. *
  12. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  13. */
  14. #include <common.h>
  15. #include <errno.h>
  16. #include <spl.h>
  17. #include <asm/arch/cpu.h>
  18. #include <asm/arch/hardware.h>
  19. #include <asm/arch/omap.h>
  20. #include <asm/arch/ddr_defs.h>
  21. #include <asm/arch/clock.h>
  22. #include <asm/arch/gpio.h>
  23. #include <asm/arch/mmc_host_def.h>
  24. #include <asm/arch/sys_proto.h>
  25. #include <asm/arch/mem.h>
  26. #include <asm/io.h>
  27. #include <asm/emif.h>
  28. #include <asm/gpio.h>
  29. #include <i2c.h>
  30. #include <miiphy.h>
  31. #include <cpsw.h>
  32. #include <watchdog.h>
  33. #include "board.h"
  34. #include "../common/factoryset.h"
  35. #include <nand.h>
  36. #ifdef CONFIG_SPL_BUILD
  37. static struct draco_baseboard_id __attribute__((section(".data"))) settings;
  38. #if DDR_PLL_FREQ == 303
  39. #if !defined(CONFIG_TARGET_ETAMIN)
  40. /* Default@303MHz-i0 */
  41. const struct ddr3_data ddr3_default = {
  42. 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F,
  43. 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32,
  44. 0x0000093B, 0x0000014A,
  45. "default name @303MHz \0",
  46. "default marking \0",
  47. };
  48. #else
  49. /* etamin board */
  50. const struct ddr3_data ddr3_default = {
  51. 0x33524444, 0x56312e36, 0x0080, 0x0000, 0x003A, 0x0010, 0x009F,
  52. 0x0050, 0x0888A39B, 0x266D7FDA, 0x501F86AF, 0x00100206, 0x61A44BB2,
  53. 0x0000093B, 0x0000018A,
  54. "test-etamin \0",
  55. "generic-8Gbit \0",
  56. };
  57. #endif
  58. #elif DDR_PLL_FREQ == 400
  59. /* Default@400MHz-i0 */
  60. const struct ddr3_data ddr3_default = {
  61. 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab,
  62. 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232,
  63. 0x00000618, 0x0000014A,
  64. "default name @400MHz \0",
  65. "default marking \0",
  66. };
  67. #endif
  68. static void set_default_ddr3_timings(void)
  69. {
  70. printf("Set default DDR3 settings\n");
  71. settings.ddr3 = ddr3_default;
  72. }
  73. static void print_ddr3_timings(void)
  74. {
  75. printf("\nDDR3\n");
  76. printf("clock:\t\t%d MHz\n", DDR_PLL_FREQ);
  77. printf("device:\t\t%s\n", settings.ddr3.manu_name);
  78. printf("marking:\t%s\n", settings.ddr3.manu_marking);
  79. printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom",
  80. "default", "diff");
  81. PRINTARGS(magic);
  82. PRINTARGS(version);
  83. PRINTARGS(ddr3_sratio);
  84. PRINTARGS(iclkout);
  85. PRINTARGS(dt0rdsratio0);
  86. PRINTARGS(dt0wdsratio0);
  87. PRINTARGS(dt0fwsratio0);
  88. PRINTARGS(dt0wrsratio0);
  89. PRINTARGS(sdram_tim1);
  90. PRINTARGS(sdram_tim2);
  91. PRINTARGS(sdram_tim3);
  92. PRINTARGS(emif_ddr_phy_ctlr_1);
  93. PRINTARGS(sdram_config);
  94. PRINTARGS(ref_ctrl);
  95. PRINTARGS(ioctr_val);
  96. }
  97. static void print_chip_data(void)
  98. {
  99. struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  100. dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
  101. printf("\nCPU BOARD\n");
  102. printf("device: \t'%s'\n", settings.chip.sdevname);
  103. printf("hw version: \t'%s'\n", settings.chip.shwver);
  104. printf("max freq: \t%d MHz\n", dpll_mpu_opp100.m);
  105. }
  106. #endif /* CONFIG_SPL_BUILD */
  107. #define AM335X_NAND_ECC_MASK 0x0f
  108. #define AM335X_NAND_ECC_TYPE_16 0x02
  109. static int ecc_type;
  110. struct am335x_nand_geometry {
  111. u32 magic;
  112. u8 nand_geo_addr;
  113. u8 nand_geo_page;
  114. u8 nand_bus;
  115. };
  116. static int draco_read_nand_geometry(void)
  117. {
  118. struct am335x_nand_geometry geo;
  119. /* Read NAND geometry */
  120. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x80, 2,
  121. (uchar *)&geo, sizeof(struct am335x_nand_geometry))) {
  122. printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n");
  123. return -EIO;
  124. }
  125. if (geo.magic != 0xa657b310) {
  126. printf("%s: bad magic: %x\n", __func__, geo.magic);
  127. return -EFAULT;
  128. }
  129. if ((geo.nand_bus & AM335X_NAND_ECC_MASK) == AM335X_NAND_ECC_TYPE_16)
  130. ecc_type = 16;
  131. else
  132. ecc_type = 8;
  133. return 0;
  134. }
  135. /*
  136. * Read header information from EEPROM into global structure.
  137. */
  138. static int read_eeprom(void)
  139. {
  140. /* Check if baseboard eeprom is available */
  141. if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
  142. printf("Could not probe the EEPROM; something fundamentally wrong on the I2C bus.\n");
  143. return 1;
  144. }
  145. #ifdef CONFIG_SPL_BUILD
  146. /* Read Siemens eeprom data (DDR3) */
  147. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_DDR3, 2,
  148. (uchar *)&settings.ddr3, sizeof(struct ddr3_data))) {
  149. printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n");
  150. set_default_ddr3_timings();
  151. }
  152. /* Read Siemens eeprom data (CHIP) */
  153. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, EEPROM_ADDR_CHIP, 2,
  154. (uchar *)&settings.chip, sizeof(settings.chip)))
  155. printf("Could not read chip settings\n");
  156. if (ddr3_default.magic == settings.ddr3.magic &&
  157. ddr3_default.version == settings.ddr3.version) {
  158. printf("Using DDR3 settings from EEPROM\n");
  159. } else {
  160. if (ddr3_default.magic != settings.ddr3.magic)
  161. printf("Warning: No valid DDR3 data in eeprom.\n");
  162. if (ddr3_default.version != settings.ddr3.version)
  163. printf("Warning: DDR3 data version does not match.\n");
  164. printf("Using default settings\n");
  165. set_default_ddr3_timings();
  166. }
  167. if (MAGIC_CHIP == settings.chip.magic)
  168. print_chip_data();
  169. else
  170. printf("Warning: No chip data in eeprom\n");
  171. print_ddr3_timings();
  172. return draco_read_nand_geometry();
  173. #endif
  174. return 0;
  175. }
  176. #ifdef CONFIG_SPL_BUILD
  177. static void board_init_ddr(void)
  178. {
  179. struct emif_regs draco_ddr3_emif_reg_data = {
  180. .zq_config = 0x50074BE4,
  181. };
  182. struct ddr_data draco_ddr3_data = {
  183. };
  184. struct cmd_control draco_ddr3_cmd_ctrl_data = {
  185. };
  186. struct ctrl_ioregs draco_ddr3_ioregs = {
  187. };
  188. /* pass values from eeprom */
  189. draco_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1;
  190. draco_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2;
  191. draco_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3;
  192. draco_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 =
  193. settings.ddr3.emif_ddr_phy_ctlr_1;
  194. draco_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config;
  195. draco_ddr3_emif_reg_data.sdram_config2 = 0x08000000;
  196. draco_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl;
  197. draco_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0;
  198. draco_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0;
  199. draco_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0;
  200. draco_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0;
  201. draco_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio;
  202. draco_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout;
  203. draco_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio;
  204. draco_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout;
  205. draco_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio;
  206. draco_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout;
  207. draco_ddr3_ioregs.cm0ioctl = settings.ddr3.ioctr_val,
  208. draco_ddr3_ioregs.cm1ioctl = settings.ddr3.ioctr_val,
  209. draco_ddr3_ioregs.cm2ioctl = settings.ddr3.ioctr_val,
  210. draco_ddr3_ioregs.dt0ioctl = settings.ddr3.ioctr_val,
  211. draco_ddr3_ioregs.dt1ioctl = settings.ddr3.ioctr_val,
  212. config_ddr(DDR_PLL_FREQ, &draco_ddr3_ioregs, &draco_ddr3_data,
  213. &draco_ddr3_cmd_ctrl_data, &draco_ddr3_emif_reg_data, 0);
  214. }
  215. static void spl_siemens_board_init(void)
  216. {
  217. return;
  218. }
  219. #endif /* if def CONFIG_SPL_BUILD */
  220. #ifdef CONFIG_BOARD_LATE_INIT
  221. int board_late_init(void)
  222. {
  223. int ret;
  224. ret = draco_read_nand_geometry();
  225. if (ret != 0)
  226. return ret;
  227. nand_curr_device = 0;
  228. omap_nand_switch_ecc(1, ecc_type);
  229. #ifdef CONFIG_TARGET_ETAMIN
  230. nand_curr_device = 1;
  231. omap_nand_switch_ecc(1, ecc_type);
  232. #endif
  233. #ifdef CONFIG_FACTORYSET
  234. /* Set ASN in environment*/
  235. if (factory_dat.asn[0] != 0) {
  236. env_set("dtb_name", (char *)factory_dat.asn);
  237. } else {
  238. /* dtb suffix gets added in load script */
  239. env_set("dtb_name", "am335x-draco");
  240. }
  241. #else
  242. env_set("dtb_name", "am335x-draco");
  243. #endif
  244. return 0;
  245. }
  246. #endif
  247. #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
  248. (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
  249. static void cpsw_control(int enabled)
  250. {
  251. /* VTP can be added here */
  252. return;
  253. }
  254. static struct cpsw_slave_data cpsw_slaves[] = {
  255. {
  256. .slave_reg_ofs = 0x208,
  257. .sliver_reg_ofs = 0xd80,
  258. .phy_addr = 0,
  259. .phy_if = PHY_INTERFACE_MODE_MII,
  260. },
  261. };
  262. static struct cpsw_platform_data cpsw_data = {
  263. .mdio_base = CPSW_MDIO_BASE,
  264. .cpsw_base = CPSW_BASE,
  265. .mdio_div = 0xff,
  266. .channels = 4,
  267. .cpdma_reg_ofs = 0x800,
  268. .slaves = 1,
  269. .slave_data = cpsw_slaves,
  270. .ale_reg_ofs = 0xd00,
  271. .ale_entries = 1024,
  272. .host_port_reg_ofs = 0x108,
  273. .hw_stats_reg_ofs = 0x900,
  274. .bd_ram_ofs = 0x2000,
  275. .mac_control = (1 << 5),
  276. .control = cpsw_control,
  277. .host_port_num = 0,
  278. .version = CPSW_CTRL_VERSION_2,
  279. };
  280. #if defined(CONFIG_DRIVER_TI_CPSW) || \
  281. (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
  282. int board_eth_init(bd_t *bis)
  283. {
  284. struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  285. int n = 0;
  286. int rv;
  287. factoryset_env_set();
  288. /* Set rgmii mode and enable rmii clock to be sourced from chip */
  289. writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
  290. rv = cpsw_register(&cpsw_data);
  291. if (rv < 0)
  292. printf("Error %d registering CPSW switch\n", rv);
  293. else
  294. n += rv;
  295. return n;
  296. }
  297. static int do_switch_reset(cmd_tbl_t *cmdtp, int flag, int argc,
  298. char *const argv[])
  299. {
  300. /* Reset SMSC LAN9303 switch for default configuration */
  301. gpio_request(GPIO_LAN9303_NRST, "nRST");
  302. gpio_direction_output(GPIO_LAN9303_NRST, 0);
  303. /* assert active low reset for 200us */
  304. udelay(200);
  305. gpio_set_value(GPIO_LAN9303_NRST, 1);
  306. return 0;
  307. };
  308. U_BOOT_CMD(
  309. switch_rst, CONFIG_SYS_MAXARGS, 1, do_switch_reset,
  310. "Reset LAN9303 switch via its reset pin",
  311. ""
  312. );
  313. #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
  314. #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
  315. #ifdef CONFIG_NAND_CS_INIT
  316. /* GPMC definitions for second nand cs1 */
  317. static const u32 gpmc_nand_config[] = {
  318. ETAMIN_NAND_GPMC_CONFIG1,
  319. ETAMIN_NAND_GPMC_CONFIG2,
  320. ETAMIN_NAND_GPMC_CONFIG3,
  321. ETAMIN_NAND_GPMC_CONFIG4,
  322. ETAMIN_NAND_GPMC_CONFIG5,
  323. ETAMIN_NAND_GPMC_CONFIG6,
  324. /*CONFIG7- computed as params */
  325. };
  326. static void board_nand_cs_init(void)
  327. {
  328. enable_gpmc_cs_config(gpmc_nand_config, &gpmc_cfg->cs[1],
  329. 0x18000000, GPMC_SIZE_16M);
  330. }
  331. #endif
  332. #include "../common/board.c"