generic.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. * (C) Copyright 2009 DENX Software Engineering
  3. * Author: John Rigby <jrigby@gmail.com>
  4. *
  5. * Based on mx27/generic.c:
  6. * Copyright (c) 2008 Eric Jarrige <eric.jarrige@armadeus.org>
  7. * Copyright (c) 2009 Ilya Yanok <yanok@emcraft.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <div64.h>
  26. #include <netdev.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/imx-regs.h>
  29. #include <asm/arch/imx25-pinmux.h>
  30. #include <asm/arch/clock.h>
  31. #ifdef CONFIG_MXC_MMC
  32. #include <asm/arch/mxcmmc.h>
  33. #endif
  34. #ifdef CONFIG_FSL_ESDHC
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #endif
  37. /*
  38. * get the system pll clock in Hz
  39. *
  40. * mfi + mfn / (mfd +1)
  41. * f = 2 * f_ref * --------------------
  42. * pd + 1
  43. */
  44. static unsigned int imx_decode_pll(unsigned int pll, unsigned int f_ref)
  45. {
  46. unsigned int mfi = (pll >> CCM_PLL_MFI_SHIFT)
  47. & CCM_PLL_MFI_MASK;
  48. unsigned int mfn = (pll >> CCM_PLL_MFN_SHIFT)
  49. & CCM_PLL_MFN_MASK;
  50. unsigned int mfd = (pll >> CCM_PLL_MFD_SHIFT)
  51. & CCM_PLL_MFD_MASK;
  52. unsigned int pd = (pll >> CCM_PLL_PD_SHIFT)
  53. & CCM_PLL_PD_MASK;
  54. mfi = mfi <= 5 ? 5 : mfi;
  55. return lldiv(2 * (u64) f_ref * (mfi * (mfd + 1) + mfn),
  56. (mfd + 1) * (pd + 1));
  57. }
  58. static ulong imx_get_mpllclk(void)
  59. {
  60. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  61. ulong fref = MXC_HCLK;
  62. return imx_decode_pll(readl(&ccm->mpctl), fref);
  63. }
  64. ulong imx_get_armclk(void)
  65. {
  66. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  67. ulong cctl = readl(&ccm->cctl);
  68. ulong fref = imx_get_mpllclk();
  69. ulong div;
  70. if (cctl & CCM_CCTL_ARM_SRC)
  71. fref = lldiv((fref * 3), 4);
  72. div = ((cctl >> CCM_CCTL_ARM_DIV_SHIFT)
  73. & CCM_CCTL_ARM_DIV_MASK) + 1;
  74. return lldiv(fref, div);
  75. }
  76. ulong imx_get_ahbclk(void)
  77. {
  78. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  79. ulong cctl = readl(&ccm->cctl);
  80. ulong fref = imx_get_armclk();
  81. ulong div;
  82. div = ((cctl >> CCM_CCTL_AHB_DIV_SHIFT)
  83. & CCM_CCTL_AHB_DIV_MASK) + 1;
  84. return lldiv(fref, div);
  85. }
  86. ulong imx_get_perclk(int clk)
  87. {
  88. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  89. ulong fref = imx_get_ahbclk();
  90. ulong div;
  91. div = readl(&ccm->pcdr[CCM_PERCLK_REG(clk)]);
  92. div = ((div >> CCM_PERCLK_SHIFT(clk)) & CCM_PERCLK_MASK) + 1;
  93. return lldiv(fref, div);
  94. }
  95. unsigned int mxc_get_clock(enum mxc_clock clk)
  96. {
  97. if (clk >= MXC_CLK_NUM)
  98. return -1;
  99. switch (clk) {
  100. case MXC_ARM_CLK:
  101. return imx_get_armclk();
  102. case MXC_FEC_CLK:
  103. return imx_get_ahbclk();
  104. default:
  105. return imx_get_perclk(clk);
  106. }
  107. }
  108. u32 get_cpu_rev(void)
  109. {
  110. u32 srev;
  111. u32 system_rev = 0x25000;
  112. /* read SREV register from IIM module */
  113. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  114. srev = readl(&iim->iim_srev);
  115. switch (srev) {
  116. case 0x00:
  117. system_rev |= CHIP_REV_1_0;
  118. break;
  119. case 0x01:
  120. system_rev |= CHIP_REV_1_1;
  121. break;
  122. default:
  123. system_rev |= 0x8000;
  124. break;
  125. }
  126. return system_rev;
  127. }
  128. #if defined(CONFIG_DISPLAY_CPUINFO)
  129. static char *get_reset_cause(void)
  130. {
  131. /* read RCSR register from CCM module */
  132. struct ccm_regs *ccm =
  133. (struct ccm_regs *)IMX_CCM_BASE;
  134. u32 cause = readl(&ccm->rcsr) & 0x0f;
  135. if (cause == 0)
  136. return "POR";
  137. else if (cause == 1)
  138. return "RST";
  139. else if ((cause & 2) == 2)
  140. return "WDOG";
  141. else if ((cause & 4) == 4)
  142. return "SW RESET";
  143. else if ((cause & 8) == 8)
  144. return "JTAG";
  145. else
  146. return "unknown reset";
  147. }
  148. int print_cpuinfo(void)
  149. {
  150. char buf[32];
  151. u32 cpurev = get_cpu_rev();
  152. printf("CPU: Freescale i.MX25 rev%d.%d%s at %s MHz\n",
  153. (cpurev & 0xF0) >> 4, (cpurev & 0x0F),
  154. ((cpurev & 0x8000) ? " unknown" : ""),
  155. strmhz(buf, imx_get_armclk()));
  156. printf("Reset cause: %s\n\n", get_reset_cause());
  157. return 0;
  158. }
  159. #endif
  160. void enable_caches(void)
  161. {
  162. #ifndef CONFIG_SYS_DCACHE_OFF
  163. /* Enable D-cache. I-cache is already enabled in start.S */
  164. dcache_enable();
  165. #endif
  166. }
  167. int cpu_eth_init(bd_t *bis)
  168. {
  169. #if defined(CONFIG_FEC_MXC)
  170. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  171. ulong val;
  172. val = readl(&ccm->cgr0);
  173. val |= (1 << 23);
  174. writel(val, &ccm->cgr0);
  175. return fecmxc_initialize(bis);
  176. #else
  177. return 0;
  178. #endif
  179. }
  180. int get_clocks(void)
  181. {
  182. #ifdef CONFIG_FSL_ESDHC
  183. gd->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
  184. #endif
  185. return 0;
  186. }
  187. /*
  188. * Initializes on-chip MMC controllers.
  189. * to override, implement board_mmc_init()
  190. */
  191. int cpu_mmc_init(bd_t *bis)
  192. {
  193. #ifdef CONFIG_MXC_MMC
  194. return mxc_mmc_init(bis);
  195. #else
  196. return 0;
  197. #endif
  198. }
  199. #ifdef CONFIG_MXC_UART
  200. void mx25_uart1_init_pins(void)
  201. {
  202. struct iomuxc_mux_ctl *muxctl;
  203. struct iomuxc_pad_ctl *padctl;
  204. u32 inpadctl;
  205. u32 outpadctl;
  206. u32 muxmode0;
  207. muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
  208. padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
  209. muxmode0 = MX25_PIN_MUX_MODE(0);
  210. /*
  211. * set up input pins with hysteresis and 100K pull-ups
  212. */
  213. inpadctl = MX25_PIN_PAD_CTL_HYS
  214. | MX25_PIN_PAD_CTL_PKE
  215. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PU;
  216. /*
  217. * set up output pins with 100K pull-downs
  218. * FIXME: need to revisit this
  219. * PUE is ignored if PKE is not set
  220. * so the right value here is likely
  221. * 0x0 for no pull up/down
  222. * or
  223. * 0xc0 for 100k pull down
  224. */
  225. outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  226. /* UART1 */
  227. /* rxd */
  228. writel(muxmode0, &muxctl->pad_uart1_rxd);
  229. writel(inpadctl, &padctl->pad_uart1_rxd);
  230. /* txd */
  231. writel(muxmode0, &muxctl->pad_uart1_txd);
  232. writel(outpadctl, &padctl->pad_uart1_txd);
  233. /* rts */
  234. writel(muxmode0, &muxctl->pad_uart1_rts);
  235. writel(outpadctl, &padctl->pad_uart1_rts);
  236. /* cts */
  237. writel(muxmode0, &muxctl->pad_uart1_cts);
  238. writel(inpadctl, &padctl->pad_uart1_cts);
  239. }
  240. #endif /* CONFIG_MXC_UART */
  241. #ifdef CONFIG_FEC_MXC
  242. void mx25_fec_init_pins(void)
  243. {
  244. struct iomuxc_mux_ctl *muxctl;
  245. struct iomuxc_pad_ctl *padctl;
  246. u32 inpadctl_100kpd;
  247. u32 inpadctl_22kpu;
  248. u32 outpadctl;
  249. u32 muxmode0;
  250. muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
  251. padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
  252. muxmode0 = MX25_PIN_MUX_MODE(0);
  253. inpadctl_100kpd = MX25_PIN_PAD_CTL_HYS
  254. | MX25_PIN_PAD_CTL_PKE
  255. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  256. inpadctl_22kpu = MX25_PIN_PAD_CTL_HYS
  257. | MX25_PIN_PAD_CTL_PKE
  258. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_22K_PU;
  259. /*
  260. * set up output pins with 100K pull-downs
  261. * FIXME: need to revisit this
  262. * PUE is ignored if PKE is not set
  263. * so the right value here is likely
  264. * 0x0 for no pull
  265. * or
  266. * 0xc0 for 100k pull down
  267. */
  268. outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  269. /* FEC_TX_CLK */
  270. writel(muxmode0, &muxctl->pad_fec_tx_clk);
  271. writel(inpadctl_100kpd, &padctl->pad_fec_tx_clk);
  272. /* FEC_RX_DV */
  273. writel(muxmode0, &muxctl->pad_fec_rx_dv);
  274. writel(inpadctl_100kpd, &padctl->pad_fec_rx_dv);
  275. /* FEC_RDATA0 */
  276. writel(muxmode0, &muxctl->pad_fec_rdata0);
  277. writel(inpadctl_100kpd, &padctl->pad_fec_rdata0);
  278. /* FEC_TDATA0 */
  279. writel(muxmode0, &muxctl->pad_fec_tdata0);
  280. writel(outpadctl, &padctl->pad_fec_tdata0);
  281. /* FEC_TX_EN */
  282. writel(muxmode0, &muxctl->pad_fec_tx_en);
  283. writel(outpadctl, &padctl->pad_fec_tx_en);
  284. /* FEC_MDC */
  285. writel(muxmode0, &muxctl->pad_fec_mdc);
  286. writel(outpadctl, &padctl->pad_fec_mdc);
  287. /* FEC_MDIO */
  288. writel(muxmode0, &muxctl->pad_fec_mdio);
  289. writel(inpadctl_22kpu, &padctl->pad_fec_mdio);
  290. /* FEC_RDATA1 */
  291. writel(muxmode0, &muxctl->pad_fec_rdata1);
  292. writel(inpadctl_100kpd, &padctl->pad_fec_rdata1);
  293. /* FEC_TDATA1 */
  294. writel(muxmode0, &muxctl->pad_fec_tdata1);
  295. writel(outpadctl, &padctl->pad_fec_tdata1);
  296. }
  297. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  298. {
  299. int i;
  300. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  301. struct fuse_bank *bank = &iim->bank[0];
  302. struct fuse_bank0_regs *fuse =
  303. (struct fuse_bank0_regs *)bank->fuse_regs;
  304. for (i = 0; i < 6; i++)
  305. mac[i] = readl(&fuse->mac_addr[i]) & 0xff;
  306. }
  307. #endif /* CONFIG_FEC_MXC */