vic7100.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018 Microsemi Corporation.
  4. * Padmarao Begari, Microsemi Corporation <padmarao.begari@microsemi.com>
  5. * Copyright (C) 2018 Joey Hewitt <joey@joeyhewitt.com>
  6. */
  7. #include <asm/mach-types.h>
  8. #include <common.h>
  9. #include <linux/io.h>
  10. #include <dm/uclass.h>
  11. #include <dm/device.h>
  12. #include <misc.h>
  13. #include <inttypes.h>
  14. #include <netdev.h>
  15. #include <phy_interface.h>
  16. #include <flash.h>
  17. #include <asm/arch/global_reg.h>
  18. #include <asm/arch/ezGPIO_fullMux_ctrl_macro.h>
  19. #include <asm/arch/clkgen_ctrl_macro.h>
  20. #include <asm/arch/syscon_sysmain_ctrl_macro.h>
  21. #include <asm/arch/rstgen_ctrl_macro.h>
  22. #include <asm/arch/audio_rst_gen_ctrl_macro.h>
  23. #include <asm/arch/audio_clk_gen_ctrl_macro.h>
  24. #include <asm/arch/audio_sys_ctrl_macro.h>
  25. #include <asm/arch/vic_iopad.h>
  26. #include <asm/arch/vic_module_reset_clkgen.h>
  27. #include <asm/arch/vout_sys_clkgen_ctrl_macro.h>
  28. #include <asm/arch/vout_sys_rstgen_ctrl_macro.h>
  29. #include <asm/arch/vout_sys_syscon_macro.h>
  30. #include <asm/arch/vad.h>
  31. #include <asm/arch/syscon_remap_vp6_noc_macro.h>
  32. #include <asm/arch/syscon_iopad_ctrl_macro.h>
  33. DECLARE_GLOBAL_DATA_PTR;
  34. /* added by chenjieqin for ptc on 20200824 */
  35. /* pwm channel for pwm mode */
  36. enum ptc_pwm_num{
  37. PTC_PWM_NONE = -1,
  38. PTC_PWM_0 = 0,
  39. PTC_PWM_1,
  40. PTC_PWM_2,
  41. PTC_PWM_3,
  42. PTC_PWM_NUM,
  43. };
  44. /* end */
  45. struct sifive_gpio_regs
  46. {
  47. volatile uint32_t INPUT_VAL; /* 0x0000 */
  48. volatile uint32_t INPUT_EN; /* 0x0004 */
  49. volatile uint32_t OUTPUT_VAL; /* 0x0008 */
  50. volatile uint32_t OUTPUT_EN; /* 0x000C */
  51. volatile uint32_t PUE; /* 0x0010 */
  52. volatile uint32_t DS; /* 0x0014 */
  53. volatile uint32_t RISE_IE; /* 0x0018 */
  54. volatile uint32_t RISE_IP; /* 0x001C */
  55. volatile uint32_t FALL_IE; /* 0x0020 */
  56. volatile uint32_t FALL_IP; /* 0x0024 */
  57. volatile uint32_t HIGH_IE; /* 0x0028 */
  58. volatile uint32_t HIGH_IP; /* 0x002C */
  59. volatile uint32_t LOW_IE; /* 0x0030 */
  60. volatile uint32_t LOW_IP; /* 0x0034 */
  61. volatile uint32_t reserved0; /* 0x0038 */
  62. volatile uint32_t reserved1; /* 0x003C */
  63. volatile uint32_t OUT_XOR; /* 0x0040 */
  64. };
  65. #define INIT_FUNC_DEF(name) \
  66. static void _##name##_init(void)
  67. #define INIT_FUNC_CALL(name)\
  68. _##name##_init()
  69. struct sifive_gpio_regs *g_aloe_gpio = (struct sifive_gpio_regs *) SIFIVE_BASE_GPIO;
  70. void _delay(unsigned int cycles)
  71. {
  72. unsigned int i;
  73. for(i = 0; i < cycles; i++);
  74. }
  75. /* end */
  76. INIT_FUNC_DEF(wave511)
  77. {
  78. _ENABLE_CLOCK_clk_vdec_axi_;
  79. _ENABLE_CLOCK_clk_vdecbrg_mainclk_;
  80. _ENABLE_CLOCK_clk_vdec_bclk_;
  81. _ENABLE_CLOCK_clk_vdec_cclk_;
  82. _ENABLE_CLOCK_clk_vdec_apb_;
  83. _CLEAR_RESET_rstgen_rstn_vdecbrg_main_;
  84. _CLEAR_RESET_rstgen_rstn_vdec_axi_;
  85. _CLEAR_RESET_rstgen_rstn_vdec_bclk_;
  86. _CLEAR_RESET_rstgen_rstn_vdec_cclk_;
  87. _CLEAR_RESET_rstgen_rstn_vdec_apb_;
  88. }
  89. INIT_FUNC_DEF(gc300)
  90. {
  91. _SET_SYSCON_REG_register20_u0_syscon_162_SCFG_gc300_csys_req(1);
  92. //nic and noc associate clk rst
  93. _ENABLE_CLOCK_clk_jpeg_axi_;
  94. _ENABLE_CLOCK_clk_jpcgc300_mainclk_;
  95. _ENABLE_CLOCK_clk_vdecbrg_mainclk_;
  96. udelay(2000);
  97. //gc300 clk and rst
  98. _ENABLE_CLOCK_clk_gc300_2x_;
  99. _ENABLE_CLOCK_clk_gc300_ahb_;
  100. _ENABLE_CLOCK_clk_gc300_axi_;
  101. _CLEAR_RESET_rstgen_rstn_gc300_2x_;
  102. _CLEAR_RESET_rstgen_rstn_gc300_axi_;
  103. _CLEAR_RESET_rstgen_rstn_gc300_ahb_;
  104. udelay(2000);
  105. //nic and noc associate clk rst;
  106. _CLEAR_RESET_rstgen_rstn_jpeg_axi_;
  107. _CLEAR_RESET_rstgen_rstn_jpcgc300_main_;
  108. _CLEAR_RESET_rstgen_rstn_vdecbrg_main_;
  109. }
  110. INIT_FUNC_DEF(codaj21)
  111. {
  112. _ENABLE_CLOCK_clk_jpeg_axi_;
  113. _ENABLE_CLOCK_clk_jpeg_cclk_;
  114. _ENABLE_CLOCK_clk_jpeg_apb_;
  115. _CLEAR_RESET_rstgen_rstn_jpeg_axi_;
  116. _CLEAR_RESET_rstgen_rstn_jpeg_cclk_;
  117. _CLEAR_RESET_rstgen_rstn_jpeg_apb_;
  118. }
  119. INIT_FUNC_DEF(nvdla)
  120. {
  121. _SET_SYSCON_REG_register16_SCFG_nbdla_clkgating_en(1);
  122. _ENABLE_CLOCK_clk_dla_bus_;
  123. _ENABLE_CLOCK_clk_dla_axi_;
  124. _ENABLE_CLOCK_clk_dlanoc_axi_;
  125. _ENABLE_CLOCK_clk_dla_apb_;
  126. _ENABLE_CLOCK_clk_nnenoc_axi_;
  127. _ENABLE_CLOCK_clk_dlaslv_axi_;
  128. _CLEAR_RESET_rstgen_rstn_dla_axi_;
  129. _CLEAR_RESET_rstgen_rstn_dlanoc_axi_;
  130. _CLEAR_RESET_rstgen_rstn_dla_apb_;
  131. _CLEAR_RESET_rstgen_rstn_nnenoc_axi_;
  132. _CLEAR_RESET_rstgen_rstn_dlaslv_axi_;
  133. }
  134. INIT_FUNC_DEF(wave521)
  135. {
  136. _ENABLE_CLOCK_clk_venc_axi_;
  137. _ENABLE_CLOCK_clk_vencbrg_mainclk_;
  138. _ENABLE_CLOCK_clk_venc_bclk_;
  139. _ENABLE_CLOCK_clk_venc_cclk_;
  140. _ENABLE_CLOCK_clk_venc_apb_;
  141. _CLEAR_RESET_rstgen_rstn_venc_axi_;
  142. _CLEAR_RESET_rstgen_rstn_vencbrg_main_;
  143. _CLEAR_RESET_rstgen_rstn_venc_bclk_;
  144. _CLEAR_RESET_rstgen_rstn_venc_cclk_;
  145. _CLEAR_RESET_rstgen_rstn_venc_apb_;
  146. }
  147. INIT_FUNC_DEF(gmac)
  148. {
  149. /*phy must use gpio to hardware reset*/
  150. _ENABLE_CLOCK_clk_gmac_ahb_;
  151. _ENABLE_CLOCK_clk_gmac_ptp_refclk_;
  152. _ENABLE_CLOCK_clk_gmac_gtxclk_;
  153. _ASSERT_RESET_rstgen_rstn_gmac_ahb_;
  154. _CLEAR_RESET_rstgen_rstn_gmac_ahb_;
  155. _SET_SYSCON_REG_register89_SCFG_funcshare_pad_ctrl_57(0x00030080);
  156. _SET_SYSCON_REG_register90_SCFG_funcshare_pad_ctrl_58(0x00030080);
  157. _SET_SYSCON_REG_register91_SCFG_funcshare_pad_ctrl_59(0x00030003);
  158. _SET_SYSCON_REG_register92_SCFG_funcshare_pad_ctrl_60(0x00030003);
  159. _SET_SYSCON_REG_register93_SCFG_funcshare_pad_ctrl_61(0x00030003);
  160. _SET_SYSCON_REG_register94_SCFG_funcshare_pad_ctrl_62(0x00030003);
  161. _SET_SYSCON_REG_register95_SCFG_funcshare_pad_ctrl_63(0x00800003);
  162. _SET_SYSCON_REG_register96_SCFG_funcshare_pad_ctrl_64(0x00800080);
  163. _SET_SYSCON_REG_register97_SCFG_funcshare_pad_ctrl_65(0x00800080);
  164. _SET_SYSCON_REG_register98_SCFG_funcshare_pad_ctrl_66(0x00800080);
  165. _SET_SYSCON_REG_register99_SCFG_funcshare_pad_ctrl_67(0x00800080);
  166. _SET_SYSCON_REG_register100_SCFG_funcshare_pad_ctrl_68(0x00800080);
  167. _SET_SYSCON_REG_register101_SCFG_funcshare_pad_ctrl_69(0x00800080);
  168. _SET_SYSCON_REG_register102_SCFG_funcshare_pad_ctrl_70(0x00800080);
  169. SET_GPIO_25_doen_LOW;
  170. SET_GPIO_25_dout_HIGH;
  171. udelay(1000);
  172. SET_GPIO_25_dout_LOW;
  173. udelay(1000);
  174. SET_GPIO_25_dout_HIGH;
  175. _SET_SYSCON_REG_register28_SCFG_gmac_phy_intf_sel(0x1);//rgmii
  176. // _DIVIDE_CLOCK_clk_gmac_gtxclk_(20); //100M clk
  177. _DIVIDE_CLOCK_clk_gmac_gtxclk_(4); //1000M clk
  178. _SET_SYSCON_REG_register49_SCFG_gmac_gtxclk_dlychain_sel(0x4);
  179. _SET_SYSCON_REG_register104_SCFG_io_padshare_sel(0);
  180. }
  181. INIT_FUNC_DEF(nne50)
  182. {
  183. // fix nne50 ram scan fail issue
  184. _SWITCH_CLOCK_clk_nne_bus_SOURCE_clk_cpu_axi_;
  185. _ENABLE_CLOCK_clk_nne_ahb_;
  186. _ENABLE_CLOCK_clk_nne_axi_;
  187. _ENABLE_CLOCK_clk_nnenoc_axi_ ;
  188. _CLEAR_RESET_rstgen_rstn_nne_ahb_ ;
  189. _CLEAR_RESET_rstgen_rstn_nne_axi_ ;
  190. _CLEAR_RESET_rstgen_rstn_nnenoc_axi_ ;
  191. }
  192. INIT_FUNC_DEF(vp6)
  193. {
  194. _ASSERT_RESET_rstgen_rst_vp6_DReset_;
  195. _ASSERT_RESET_rstgen_rst_vp6_Breset_;
  196. _ENABLE_CLOCK_clk_vp6_core_ ;
  197. _ENABLE_CLOCK_clk_vp6_axi_ ;
  198. }
  199. INIT_FUNC_DEF(noc)
  200. {
  201. }
  202. INIT_FUNC_DEF(syscon)
  203. {
  204. }
  205. INIT_FUNC_DEF(gpio)
  206. {
  207. _ENABLE_CLOCK_clk_gpio_apb_;
  208. _CLEAR_RESET_rstgen_rstn_gpio_apb_;
  209. }
  210. INIT_FUNC_DEF(audio_subsys)
  211. {
  212. _ENABLE_CLOCK_clk_audio_root_;
  213. _ENABLE_CLOCK_clk_audio_12288_;
  214. _ENABLE_CLOCK_clk_audio_src_;
  215. _ENABLE_CLOCK_clk_audio_12288_;
  216. _ENABLE_CLOCK_clk_dma1p_ahb_;
  217. _CLEAR_RESET_audio_rst_gen_rstn_apb_bus_;
  218. _CLEAR_RESET_audio_rst_gen_rstn_dma1p_ahb_;
  219. }
  220. INIT_FUNC_DEF(i2srx_3ch)
  221. {
  222. _ENABLE_CLOCK_clk_adc_mclk_;
  223. _ENABLE_CLOCK_clk_apb_i2sadc_;
  224. _CLEAR_RESET_audio_rst_gen_rstn_apb_i2sadc_;
  225. _CLEAR_RESET_audio_rst_gen_rstn_i2sadc_srst_;
  226. }
  227. INIT_FUNC_DEF(pdm)
  228. {
  229. _ENABLE_CLOCK_clk_apb_pdm_;
  230. _ENABLE_CLOCK_clk_pdm_mclk_;
  231. _CLEAR_RESET_audio_rst_gen_rstn_apb_pdm_;
  232. }
  233. INIT_FUNC_DEF(i2svad)
  234. {
  235. _ENABLE_CLOCK_clk_apb_i2svad_ ;
  236. _CLEAR_RESET_audio_rst_gen_rstn_apb_i2svad_ ;
  237. _CLEAR_RESET_audio_rst_gen_rstn_i2svad_srst_ ;
  238. }
  239. INIT_FUNC_DEF(spdif)
  240. {
  241. _ENABLE_CLOCK_clk_spdif_;
  242. _ENABLE_CLOCK_clk_apb_spdif_;
  243. _CLEAR_RESET_audio_rst_gen_rstn_apb_spdif_;
  244. }
  245. INIT_FUNC_DEF(pwmdac)
  246. {
  247. _ENABLE_CLOCK_clk_apb_pwmdac_;
  248. _CLEAR_RESET_audio_rst_gen_rstn_apb_pwmdac_;
  249. }
  250. INIT_FUNC_DEF(i2sdac0)
  251. {
  252. _ENABLE_CLOCK_clk_dac_mclk_;
  253. _ENABLE_CLOCK_clk_apb_i2sdac_;
  254. _CLEAR_RESET_audio_rst_gen_rstn_apb_i2sdac_;
  255. _CLEAR_RESET_audio_rst_gen_rstn_i2sdac_srst_;
  256. }
  257. INIT_FUNC_DEF(i2sdac1)
  258. {
  259. _ENABLE_CLOCK_clk_i2s1_mclk_;
  260. _ENABLE_CLOCK_clk_apb_i2s1_;
  261. _CLEAR_RESET_audio_rst_gen_rstn_apb_i2s1_;
  262. _CLEAR_RESET_audio_rst_gen_rstn_i2s1_srst_;
  263. }
  264. INIT_FUNC_DEF(i2sdac16k)
  265. {
  266. _ENABLE_CLOCK_clk_apb_i2sdac16k_;
  267. _CLEAR_RESET_audio_rst_gen_rstn_apb_i2sdac16k_;
  268. _CLEAR_RESET_audio_rst_gen_rstn_i2sdac16k_srst_;
  269. }
  270. INIT_FUNC_DEF(usb)
  271. {
  272. uint32_t read_v=MA_INW(gpioen_REG_ADDR + 0x48);
  273. writel(0x7ffff, 0x10490000);
  274. udelay(1000);
  275. writel(0, 0x10490000);
  276. _ENABLE_CLOCK_clk_usb_axi_;
  277. _ENABLE_CLOCK_clk_usbphy_125m_;
  278. _ENABLE_CLOCK_clk_usb_lpm_clk_predft_;
  279. _ENABLE_CLOCK_clk_usb_stb_clk_predft_;
  280. _ENABLE_CLOCK_clk_apb_usb_;
  281. _CLEAR_RESET_rstgen_rstn_usb_axi_;
  282. _CLEAR_RESET_audio_rst_gen_rstn_apb_usb_;
  283. _CLEAR_RESET_audio_rst_gen_rst_axi_usb_;
  284. _CLEAR_RESET_audio_rst_gen_rst_usb_pwrup_rst_n_;
  285. _CLEAR_RESET_audio_rst_gen_rst_usb_PONRST_;
  286. /* for host */
  287. SET_GPIO_usb_over_current(-1);
  288. if(!((read_v >> 22) & 0x1)) {
  289. /* config strap */
  290. _SET_SYSCON_REG_SCFG_usb0_mode_strap(0x2);
  291. _SET_SYSCON_REG_SCFG_usb7_PLL_EN(0x1);
  292. //_SET_SYSCON_REG_SCFG_usb7_U3_HOST_PYH(0x1);
  293. _SET_SYSCON_REG_SCFG_usb7_U3_EQ_EN(0x1);
  294. // _SET_SYSCON_REG_SCFG_usb7_U3_SSCG_ON(0x1);
  295. _SET_SYSCON_REG_SCFG_usb7_U3_SSRX_SEL(0x1);
  296. _SET_SYSCON_REG_SCFG_usb7_U3_SSTX_SEL(0x1);
  297. _SET_SYSCON_REG_SCFG_usb3_utmi_iddig(0x1);
  298. }
  299. }
  300. INIT_FUNC_DEF(sgdma1p)
  301. {
  302. _ENABLE_CLOCK_clk_sgdma1p_axi_;
  303. _CLEAR_RESET_rstgen_rstn_sgdma1p_axi_;
  304. }
  305. INIT_FUNC_DEF(qspi)
  306. {
  307. _ENABLE_CLOCK_clk_qspi_ahb_;
  308. _ENABLE_CLOCK_clk_qspi_apb_;
  309. _ENABLE_CLOCK_clk_qspi_refclk_;
  310. _CLEAR_RESET_rstgen_rstn_qspi_ahb_;
  311. _CLEAR_RESET_rstgen_rstn_qspi_core_;
  312. _CLEAR_RESET_rstgen_rstn_qspi_apb_;
  313. }
  314. INIT_FUNC_DEF(sgdma2p)
  315. {
  316. _ENABLE_CLOCK_clk_dma2pnoc_axi_;
  317. _ENABLE_CLOCK_clk_sgdma2p_axi_;
  318. _ENABLE_CLOCK_clk_sgdma2p_ahb_;
  319. _CLEAR_RESET_rstgen_rstn_sgdma2p_ahb_;
  320. _CLEAR_RESET_rstgen_rstn_sgdma2p_axi_;
  321. _CLEAR_RESET_rstgen_rstn_dma2pnoc_aix_;
  322. }
  323. INIT_FUNC_DEF(sdio0)
  324. {
  325. _ENABLE_CLOCK_clk_sdio0_ahb_;
  326. _ENABLE_CLOCK_clk_sdio0_cclkint_;
  327. SET_GPIO_33_dout_sdio0_pad_cclk_out;
  328. SET_GPIO_33_doen_LOW;
  329. SET_GPIO_29_doen_reverse_(1);
  330. SET_GPIO_29_doen_sdio0_pad_ccmd_oe;
  331. SET_GPIO_29_dout_sdio0_pad_ccmd_out;
  332. SET_GPIO_sdio0_pad_ccmd_in(29);
  333. SET_GPIO_36_doen_reverse_(1);
  334. SET_GPIO_30_doen_reverse_(1);
  335. SET_GPIO_34_doen_reverse_(1);
  336. SET_GPIO_31_doen_reverse_(1);
  337. SET_GPIO_36_doen_sdio0_pad_cdata_oe_bit0;
  338. SET_GPIO_36_dout_sdio0_pad_cdata_out_bit0;
  339. SET_GPIO_sdio0_pad_cdata_in_bit0(36);
  340. SET_GPIO_30_doen_sdio0_pad_cdata_oe_bit1;
  341. SET_GPIO_30_dout_sdio0_pad_cdata_out_bit1;
  342. SET_GPIO_sdio0_pad_cdata_in_bit1(30);
  343. SET_GPIO_34_doen_sdio0_pad_cdata_oe_bit2;
  344. SET_GPIO_34_dout_sdio0_pad_cdata_out_bit2;
  345. SET_GPIO_sdio0_pad_cdata_in_bit2(34);
  346. SET_GPIO_31_doen_sdio0_pad_cdata_oe_bit3;
  347. SET_GPIO_31_dout_sdio0_pad_cdata_out_bit3;
  348. SET_GPIO_sdio0_pad_cdata_in_bit3(31);
  349. }
  350. INIT_FUNC_DEF(sdio1)
  351. {
  352. _ENABLE_CLOCK_clk_sdio1_ahb_;
  353. _ENABLE_CLOCK_clk_sdio1_cclkint_;
  354. _CLEAR_RESET_rstgen_rstn_sdio1_ahb_;
  355. }
  356. INIT_FUNC_DEF(spi2ahb)
  357. {
  358. _ENABLE_CLOCK_clk_spi2ahb_ahb_;
  359. _ENABLE_CLOCK_clk_spi2ahb_core_;
  360. _CLEAR_RESET_rstgen_rstn_spi2ahb_ahb_;
  361. _CLEAR_RESET_rstgen_rstn_spi2ahb_core_;
  362. }
  363. INIT_FUNC_DEF(ezmaster)
  364. {
  365. _ENABLE_CLOCK_clk_ezmaster_ahb_;
  366. _CLEAR_RESET_rstgen_rstn_ezmaster_ahb_;
  367. }
  368. INIT_FUNC_DEF(secengine)
  369. {
  370. _ENABLE_CLOCK_clk_sec_ahb_;
  371. _ENABLE_CLOCK_clk_aes_clk_;
  372. _ENABLE_CLOCK_clk_sha_clk_;
  373. _ENABLE_CLOCK_clk_pka_clk_;
  374. _CLEAR_RESET_rstgen_rstn_sec_ahb_;
  375. _CLEAR_RESET_rstgen_rstn_aes_;
  376. _CLEAR_RESET_rstgen_rstn_pka_;
  377. _CLEAR_RESET_rstgen_rstn_sha_;
  378. }
  379. INIT_FUNC_DEF(uart0)
  380. {
  381. _ENABLE_CLOCK_clk_uart0_apb_;
  382. _ENABLE_CLOCK_clk_uart0_core_;
  383. _CLEAR_RESET_rstgen_rstn_uart0_apb_;
  384. _CLEAR_RESET_rstgen_rstn_uart0_core_;
  385. }
  386. INIT_FUNC_DEF(uart1)
  387. {
  388. _ENABLE_CLOCK_clk_uart1_apb_;
  389. _ENABLE_CLOCK_clk_uart1_core_;
  390. _CLEAR_RESET_rstgen_rstn_uart1_apb_;
  391. _CLEAR_RESET_rstgen_rstn_uart1_core_;
  392. }
  393. INIT_FUNC_DEF(spi0)
  394. {
  395. _ENABLE_CLOCK_clk_spi0_apb_;
  396. _ENABLE_CLOCK_clk_spi0_core_;
  397. _CLEAR_RESET_rstgen_rstn_spi0_apb_;
  398. _CLEAR_RESET_rstgen_rstn_spi0_core_;
  399. }
  400. INIT_FUNC_DEF(spi1)
  401. {
  402. _ENABLE_CLOCK_clk_spi1_apb_;
  403. _ENABLE_CLOCK_clk_spi1_core_;
  404. _CLEAR_RESET_rstgen_rstn_spi1_apb_;
  405. _CLEAR_RESET_rstgen_rstn_spi1_core_;
  406. }
  407. INIT_FUNC_DEF(i2c0)
  408. {
  409. _ENABLE_CLOCK_clk_i2c0_apb_;
  410. _ENABLE_CLOCK_clk_i2c0_core_;
  411. _CLEAR_RESET_rstgen_rstn_i2c0_apb_;
  412. _CLEAR_RESET_rstgen_rstn_i2c0_core_;
  413. }
  414. INIT_FUNC_DEF(i2c1)
  415. {
  416. _ENABLE_CLOCK_clk_i2c1_apb_;
  417. _ENABLE_CLOCK_clk_i2c1_core_;
  418. _CLEAR_RESET_rstgen_rstn_i2c1_apb_;
  419. _CLEAR_RESET_rstgen_rstn_i2c1_core_;
  420. }
  421. INIT_FUNC_DEF(trng)
  422. {
  423. _ENABLE_CLOCK_clk_trng_apb_;
  424. _CLEAR_RESET_rstgen_rstn_trng_apb_;
  425. }
  426. INIT_FUNC_DEF(otp)
  427. {
  428. _ENABLE_CLOCK_clk_otp_apb_;
  429. _CLEAR_RESET_rstgen_rstn_otp_apb_;
  430. }
  431. INIT_FUNC_DEF(vp6_intc)
  432. {
  433. _ENABLE_CLOCK_clk_vp6intc_apb_;
  434. _CLEAR_RESET_rstgen_rstn_vp6intc_apb_;
  435. }
  436. INIT_FUNC_DEF(spi2)
  437. {
  438. _ENABLE_CLOCK_clk_spi2_apb_;
  439. _ENABLE_CLOCK_clk_spi2_core_;
  440. _CLEAR_RESET_rstgen_rstn_spi2_apb_;
  441. _CLEAR_RESET_rstgen_rstn_spi2_core_;
  442. }
  443. INIT_FUNC_DEF(spi3)
  444. {
  445. _ENABLE_CLOCK_clk_spi3_apb_;
  446. _ENABLE_CLOCK_clk_spi3_core_;
  447. _CLEAR_RESET_rstgen_rstn_spi3_apb_;
  448. _CLEAR_RESET_rstgen_rstn_spi3_core_;
  449. }
  450. INIT_FUNC_DEF(uart2)
  451. {
  452. _ENABLE_CLOCK_clk_uart2_apb_;
  453. _ENABLE_CLOCK_clk_uart2_core_;
  454. _CLEAR_RESET_rstgen_rstn_uart2_apb_;
  455. _CLEAR_RESET_rstgen_rstn_uart2_core_;
  456. }
  457. INIT_FUNC_DEF(uart3)
  458. {
  459. _ENABLE_CLOCK_clk_uart3_apb_;
  460. _ENABLE_CLOCK_clk_uart3_core_;
  461. _CLEAR_RESET_rstgen_rstn_uart3_apb_;
  462. _CLEAR_RESET_rstgen_rstn_uart3_core_;
  463. }
  464. INIT_FUNC_DEF(i2c2)
  465. {
  466. _ENABLE_CLOCK_clk_i2c2_apb_;
  467. _ENABLE_CLOCK_clk_i2c2_core_;
  468. _CLEAR_RESET_rstgen_rstn_i2c2_apb_;
  469. _CLEAR_RESET_rstgen_rstn_i2c2_core_;
  470. }
  471. INIT_FUNC_DEF(i2c3)
  472. {
  473. _ENABLE_CLOCK_clk_i2c3_apb_;
  474. _ENABLE_CLOCK_clk_i2c3_core_;
  475. _CLEAR_RESET_rstgen_rstn_i2c3_apb_;
  476. _CLEAR_RESET_rstgen_rstn_i2c3_core_;
  477. }
  478. INIT_FUNC_DEF(wdt)
  479. {
  480. _ENABLE_CLOCK_clk_wdtimer_apb_;
  481. _ENABLE_CLOCK_clk_wdt_coreclk_;
  482. _ASSERT_RESET_rstgen_rstn_wdtimer_apb_;
  483. _ASSERT_RESET_rstgen_rstn_wdt_;
  484. _CLEAR_RESET_rstgen_rstn_wdtimer_apb_;
  485. _CLEAR_RESET_rstgen_rstn_wdt_;
  486. }
  487. /* added by chenjieqin for ptc on 20200824 */
  488. INIT_FUNC_DEF(ptc)
  489. {
  490. /* reset clock */
  491. ptc_reset_clock();
  492. /* reset cnt */
  493. ptc_reset();
  494. }
  495. INIT_FUNC_DEF(vout_subsys)
  496. {
  497. _ENABLE_CLOCK_clk_vout_src_ ;
  498. _ENABLE_CLOCK_clk_disp_axi_;
  499. _ENABLE_CLOCK_clk_dispnoc_axi_ ;
  500. _CLEAR_RESET_rstgen_rstn_vout_src_ ;
  501. _CLEAR_RESET_rstgen_rstn_disp_axi_ ;
  502. _CLEAR_RESET_rstgen_rstn_dispnoc_axi_ ;
  503. _ENABLE_CLOCK_clk_vout_apb_ ;
  504. _ENABLE_CLOCK_clk_mapconv_apb_ ;
  505. _ENABLE_CLOCK_clk_mapconv_axi_ ;
  506. _ENABLE_CLOCK_clk_disp0_axi_ ;
  507. _ENABLE_CLOCK_clk_disp1_axi_ ;
  508. _ENABLE_CLOCK_clk_lcdc_oclk_ ;
  509. _ENABLE_CLOCK_clk_lcdc_axi_ ;
  510. _ENABLE_CLOCK_clk_vpp0_axi_ ;
  511. _ENABLE_CLOCK_clk_vpp1_axi_ ;
  512. _ENABLE_CLOCK_clk_vpp2_axi_ ;
  513. _ENABLE_CLOCK_clk_pixrawout_apb_ ;
  514. _ENABLE_CLOCK_clk_pixrawout_axi_ ;
  515. _ENABLE_CLOCK_clk_csi2tx_strm0_pixclk_ ;
  516. _ENABLE_CLOCK_clk_csi2tx_strm0_apb_ ;
  517. _ENABLE_CLOCK_clk_dsi_apb_ ;
  518. _ENABLE_CLOCK_clk_dsi_sys_clk_ ;
  519. _ENABLE_CLOCK_clk_ppi_tx_esc_clk_ ;
  520. _CLEAR_RESET_vout_sys_rstgen_rstn_mapconv_apb_ ;
  521. _CLEAR_RESET_vout_sys_rstgen_rstn_mapconv_axi_ ;
  522. _CLEAR_RESET_vout_sys_rstgen_rstn_disp0_axi_ ;
  523. _CLEAR_RESET_vout_sys_rstgen_rstn_disp1_axi_ ;
  524. _CLEAR_RESET_vout_sys_rstgen_rstn_lcdc_oclk_ ;
  525. _CLEAR_RESET_vout_sys_rstgen_rstn_lcdc_axi_ ;
  526. _CLEAR_RESET_vout_sys_rstgen_rstn_vpp0_axi_ ;
  527. _CLEAR_RESET_vout_sys_rstgen_rstn_vpp1_axi_ ;
  528. _CLEAR_RESET_vout_sys_rstgen_rstn_vpp2_axi_ ;
  529. _CLEAR_RESET_vout_sys_rstgen_rstn_pixrawout_apb_ ;
  530. _CLEAR_RESET_vout_sys_rstgen_rstn_pixrawout_axi_ ;
  531. _CLEAR_RESET_vout_sys_rstgen_rstn_csi2tx_strm0_apb_ ;
  532. _CLEAR_RESET_vout_sys_rstgen_rstn_csi2tx_strm0_pix_ ;
  533. _CLEAR_RESET_vout_sys_rstgen_rstn_csi2tx_ppi_tx_esc_ ;
  534. //_CLEAR_RESET_vout_sys_rstgen_rstn_csi2tx_ppi_txbyte_hs_ ;
  535. _CLEAR_RESET_vout_sys_rstgen_rstn_dsi_apb_ ;
  536. _CLEAR_RESET_vout_sys_rstgen_rstn_dsi_sys_ ;
  537. //TODO:confirm these register
  538. //_CLEAR_RESET_vout_sys_rstgen_rstn_dsi_dpi_pix_ ;
  539. //_CLEAR_RESET_vout_sys_rstgen_rstn_dsi_ppi_txbyte_hs_ ;
  540. _CLEAR_RESET_vout_sys_rstgen_rstn_dsi_ppi_tx_esc_ ;
  541. _CLEAR_RESET_vout_sys_rstgen_rstn_dsi_ppi_rx_esc_ ;
  542. }
  543. INIT_FUNC_DEF(lcdc)
  544. {
  545. }
  546. INIT_FUNC_DEF(pixrawout)
  547. {
  548. }
  549. INIT_FUNC_DEF(vpp0)
  550. {
  551. }
  552. INIT_FUNC_DEF(vpp1)
  553. {
  554. }
  555. INIT_FUNC_DEF(vpp2)
  556. {
  557. }
  558. INIT_FUNC_DEF(map_conv)
  559. {
  560. }
  561. INIT_FUNC_DEF(csi2tx)
  562. {
  563. }
  564. INIT_FUNC_DEF(dsitx)
  565. {
  566. }
  567. /*init system GPIO*/
  568. int board_hw_init(void)
  569. {
  570. INIT_FUNC_CALL(wave511);
  571. INIT_FUNC_CALL(gc300);
  572. INIT_FUNC_CALL(codaj21);
  573. INIT_FUNC_CALL(nvdla);
  574. INIT_FUNC_CALL(wave521);
  575. INIT_FUNC_CALL(gmac);
  576. INIT_FUNC_CALL(nne50);
  577. INIT_FUNC_CALL(vp6);
  578. INIT_FUNC_CALL(noc);
  579. INIT_FUNC_CALL(syscon);
  580. INIT_FUNC_CALL(gpio);
  581. INIT_FUNC_CALL(audio_subsys);
  582. INIT_FUNC_CALL(i2srx_3ch);
  583. INIT_FUNC_CALL(pdm);
  584. INIT_FUNC_CALL(i2svad);
  585. INIT_FUNC_CALL(spdif);
  586. INIT_FUNC_CALL(pwmdac);
  587. INIT_FUNC_CALL(i2sdac0);
  588. INIT_FUNC_CALL(i2sdac1);
  589. INIT_FUNC_CALL(i2sdac16k);
  590. INIT_FUNC_CALL(usb);
  591. INIT_FUNC_CALL(sgdma1p);
  592. INIT_FUNC_CALL(qspi);
  593. INIT_FUNC_CALL(sgdma2p);
  594. INIT_FUNC_CALL(sdio0);
  595. INIT_FUNC_CALL(sdio1);
  596. INIT_FUNC_CALL(spi2ahb);
  597. INIT_FUNC_CALL(ezmaster);
  598. INIT_FUNC_CALL(secengine);
  599. INIT_FUNC_CALL(uart0);
  600. INIT_FUNC_CALL(uart1);
  601. INIT_FUNC_CALL(spi0);
  602. INIT_FUNC_CALL(spi1);
  603. INIT_FUNC_CALL(i2c0);
  604. INIT_FUNC_CALL(i2c1);
  605. INIT_FUNC_CALL(trng);
  606. INIT_FUNC_CALL(otp);
  607. INIT_FUNC_CALL(vp6_intc); /*include intc0 and intc1*/
  608. INIT_FUNC_CALL(spi2);
  609. INIT_FUNC_CALL(spi3);
  610. // INIT_FUNC_CALL(uart2);
  611. INIT_FUNC_CALL(uart3);
  612. INIT_FUNC_CALL(i2c2);
  613. INIT_FUNC_CALL(i2c3);
  614. INIT_FUNC_CALL(wdt);
  615. INIT_FUNC_CALL(ptc);
  616. /** Video Output Subsystem **/
  617. INIT_FUNC_CALL(vout_subsys);
  618. INIT_FUNC_CALL(lcdc);
  619. INIT_FUNC_CALL(pixrawout);
  620. INIT_FUNC_CALL(vpp0);
  621. INIT_FUNC_CALL(vpp1);
  622. INIT_FUNC_CALL(vpp2);
  623. INIT_FUNC_CALL(map_conv);
  624. INIT_FUNC_CALL(csi2tx);
  625. INIT_FUNC_CALL(dsitx);
  626. return 0;
  627. }
  628. /*
  629. * Miscellaneous platform dependent initializations
  630. */
  631. int board_init(void)
  632. {
  633. gd->bd->bi_arch_number = MACH_TYPE_STARFIVE_VIC7100;
  634. gd->bd->bi_boot_params = PHYS_SDRAM_0;
  635. return 0;
  636. }
  637. void reset_phy(void)
  638. {
  639. volatile uint32_t loop;
  640. /*
  641. * Init includes toggling the reset line which is connected to GPIO 0 pin 12.
  642. * This is the only pin I can see on the 16 GPIO which is currently set as an.
  643. * output. We will hard code the setup here to avoid having to have a GPIO
  644. * driver as well...
  645. *
  646. * The Aloe board is strapped for unmanaged mode and needs two pulses of the
  647. * reset line to configure the device properly.
  648. *
  649. * The RX_CLK, TX_CLK and RXD7 pins are strapped high and the remainder low.
  650. * This selects GMII mode with auto 10/100/1000 and 125MHz clkout.
  651. */
  652. g_aloe_gpio->OUTPUT_EN |= 0x00001000ul; /* Configure pin 12 as an output */
  653. g_aloe_gpio->OUTPUT_VAL &= 0x0000EFFFul; /* Clear pin 12 to reset PHY */
  654. for(loop = 0; loop != 1000; loop++) /* Short delay, I'm not sure how much is needed... */
  655. {
  656. ;
  657. }
  658. g_aloe_gpio->OUTPUT_VAL |= 0x00001000ul; /* Take PHY^ out of reset */
  659. for(loop = 0; loop != 1000; loop++) /* Short delay, I'm not sure how much is needed... */
  660. {
  661. ;
  662. }
  663. g_aloe_gpio->OUTPUT_VAL &= 0x0000EFFFul; /* Second reset pulse */
  664. for(loop = 0; loop != 1000; loop++) /* Short delay, I'm not sure how much is needed... */
  665. {
  666. ;
  667. }
  668. g_aloe_gpio->OUTPUT_VAL |= 0x00001000ul; /* Out of reset once more */
  669. /* Need at least 15mS delay before accessing PHY after reset... */
  670. for(loop = 0; loop != 10000; loop++) /* Long delay, I'm not sure how much is needed... */
  671. {
  672. ;
  673. }
  674. }
  675. /* This define is a value used for error/unknown serial. If we really care about distinguishing errors and 0 is valid, we'll need a different one. */
  676. #define ERROR_READING_SERIAL_NUMBER 0
  677. #ifdef CONFIG_MISC_INIT_R
  678. static u32 setup_serialnum(void);
  679. static void setup_macaddr(u32 serialnum);
  680. int misc_init_r(void)
  681. {
  682. if (!env_get("serial#")) {
  683. u32 serialnum = setup_serialnum();
  684. setup_macaddr(serialnum);
  685. }
  686. return 0;
  687. }
  688. #endif
  689. #if defined(CONFIG_ETH_DESIGNWARE) && !defined(CONFIG_DM_ETH)
  690. int board_eth_init(struct bd_info *bd)
  691. {
  692. int rc = 0;
  693. rc = designware_initialize(SIFIVE_BASE_ETHERNET, PHY_INTERFACE_MODE_RGMII_TXID);
  694. return rc;
  695. }
  696. #endif
  697. ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
  698. {
  699. return 0;
  700. }
  701. /*void *board_fdt_blob_setup(void)
  702. {
  703. void **ptr = (void *)CONFIG_SYS_SDRAM_BASE;
  704. if (fdt_magic(*ptr) == FDT_MAGIC)
  705. return (void *)*ptr;
  706. return (void *)CONFIG_SYS_FDT_BASE;
  707. }*/
  708. #if CONFIG_IS_ENABLED(SIFIVE_OTP)
  709. static u32 otp_read_serialnum(struct udevice *dev)
  710. {
  711. u32 serial[2] = {0};
  712. int ret;
  713. for (int i = 0xfe * 4; i > 0; i -= 8) {
  714. ret = misc_read(dev, i, serial, sizeof(serial));
  715. if (ret) {
  716. printf("%s: error reading serial from OTP\n", __func__);
  717. break;
  718. }
  719. if (serial[0] == ~serial[1])
  720. return serial[0];
  721. }
  722. return ERROR_READING_SERIAL_NUMBER;
  723. }
  724. #endif
  725. static u32 setup_serialnum(void)
  726. {
  727. u32 serial = ERROR_READING_SERIAL_NUMBER;
  728. char serial_str[6];
  729. #if CONFIG_IS_ENABLED(SIFIVE_OTP)
  730. struct udevice *dev;
  731. int ret;
  732. // init OTP
  733. ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(hifive_otp), &dev);
  734. if (ret) {
  735. debug("%s: could not find otp device\n", __func__);
  736. return serial;
  737. }
  738. // read serial from OTP and set env var
  739. serial = otp_read_serialnum(dev);
  740. snprintf(serial_str, sizeof(serial_str), "%05"PRIu32, serial);
  741. env_set("serial#", serial_str);
  742. #endif
  743. return serial;
  744. }
  745. static void setup_macaddr(u32 serialnum) {
  746. // OR the serial into the MAC -- see SiFive FSBL
  747. unsigned char mac[6] = {0x66,0x34,0xb0,0x6c,0xde,0xad };
  748. mac[5] |= (serialnum >> 0) & 0xff;
  749. mac[4] |= (serialnum >> 8) & 0xff;
  750. mac[3] |= (serialnum >> 16) & 0xff;
  751. eth_env_set_enetaddr("ethaddr", mac);
  752. }
  753. #ifdef CONFIG_MMC
  754. #include <asm/arch/starfive_vic_dw_mmc.h>
  755. int board_mmc_init(struct bd_info *bis)
  756. {
  757. int ret = 0;
  758. #if CONFIG_IS_ENABLED(STARFIVE_VIC_DWMMC)
  759. ret = starfive_mmc_add_port(0,SDIO0_BASE_ADDR,4);
  760. #endif
  761. if (ret)
  762. debug("init_dwmmc failed\n");
  763. return ret;
  764. }
  765. #endif