generic.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. #ifdef CONFIG_MXC_MMC
  31. #include <asm/arch/mxcmmc.h>
  32. #endif
  33. /*
  34. * get the system pll clock in Hz
  35. *
  36. * mfi + mfn / (mfd +1)
  37. * f = 2 * f_ref * --------------------
  38. * pd + 1
  39. */
  40. static unsigned int imx_decode_pll(unsigned int pll, unsigned int f_ref)
  41. {
  42. unsigned int mfi = (pll >> CCM_PLL_MFI_SHIFT)
  43. & CCM_PLL_MFI_MASK;
  44. unsigned int mfn = (pll >> CCM_PLL_MFN_SHIFT)
  45. & CCM_PLL_MFN_MASK;
  46. unsigned int mfd = (pll >> CCM_PLL_MFD_SHIFT)
  47. & CCM_PLL_MFD_MASK;
  48. unsigned int pd = (pll >> CCM_PLL_PD_SHIFT)
  49. & CCM_PLL_PD_MASK;
  50. mfi = mfi <= 5 ? 5 : mfi;
  51. return lldiv(2 * (u64) f_ref * (mfi * (mfd + 1) + mfn),
  52. (mfd + 1) * (pd + 1));
  53. }
  54. static ulong imx_get_mpllclk(void)
  55. {
  56. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  57. ulong fref = 24000000;
  58. return imx_decode_pll(readl(&ccm->mpctl), fref);
  59. }
  60. ulong imx_get_armclk(void)
  61. {
  62. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  63. ulong cctl = readl(&ccm->cctl);
  64. ulong fref = imx_get_mpllclk();
  65. ulong div;
  66. if (cctl & CCM_CCTL_ARM_SRC)
  67. fref = lldiv((fref * 3), 4);
  68. div = ((cctl >> CCM_CCTL_ARM_DIV_SHIFT)
  69. & CCM_CCTL_ARM_DIV_MASK) + 1;
  70. return lldiv(fref, div);
  71. }
  72. ulong imx_get_ahbclk(void)
  73. {
  74. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  75. ulong cctl = readl(&ccm->cctl);
  76. ulong fref = imx_get_armclk();
  77. ulong div;
  78. div = ((cctl >> CCM_CCTL_AHB_DIV_SHIFT)
  79. & CCM_CCTL_AHB_DIV_MASK) + 1;
  80. return lldiv(fref, div);
  81. }
  82. ulong imx_get_perclk(int clk)
  83. {
  84. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  85. ulong fref = imx_get_ahbclk();
  86. ulong div;
  87. div = readl(&ccm->pcdr[CCM_PERCLK_REG(clk)]);
  88. div = ((div >> CCM_PERCLK_SHIFT(clk)) & CCM_PERCLK_MASK) + 1;
  89. return lldiv(fref, div);
  90. }
  91. u32 get_cpu_rev(void)
  92. {
  93. u32 srev;
  94. u32 system_rev = 0x25000;
  95. /* read SREV register from IIM module */
  96. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  97. srev = readl(&iim->iim_srev);
  98. switch (srev) {
  99. case 0x00:
  100. system_rev |= CHIP_REV_1_0;
  101. break;
  102. case 0x01:
  103. system_rev |= CHIP_REV_1_1;
  104. break;
  105. default:
  106. system_rev |= 0x8000;
  107. break;
  108. }
  109. return system_rev;
  110. }
  111. #if defined(CONFIG_DISPLAY_CPUINFO)
  112. static char *get_reset_cause(void)
  113. {
  114. /* read RCSR register from CCM module */
  115. struct ccm_regs *ccm =
  116. (struct ccm_regs *)IMX_CCM_BASE;
  117. u32 cause = readl(&ccm->rcsr) & 0x0f;
  118. if (cause == 0)
  119. return "POR";
  120. else if (cause == 1)
  121. return "RST";
  122. else if ((cause & 2) == 2)
  123. return "WDOG";
  124. else if ((cause & 4) == 4)
  125. return "SW RESET";
  126. else if ((cause & 8) == 8)
  127. return "JTAG";
  128. else
  129. return "unknown reset";
  130. }
  131. int print_cpuinfo(void)
  132. {
  133. char buf[32];
  134. u32 cpurev = get_cpu_rev();
  135. printf("CPU: Freescale i.MX25 rev%d.%d%s at %s MHz\n",
  136. (cpurev & 0xF0) >> 4, (cpurev & 0x0F),
  137. ((cpurev & 0x8000) ? " unknown" : ""),
  138. strmhz(buf, imx_get_armclk()));
  139. printf("Reset cause: %s\n\n", get_reset_cause());
  140. return 0;
  141. }
  142. #endif
  143. int cpu_eth_init(bd_t *bis)
  144. {
  145. #if defined(CONFIG_FEC_MXC)
  146. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  147. ulong val;
  148. val = readl(&ccm->cgr0);
  149. val |= (1 << 23);
  150. writel(val, &ccm->cgr0);
  151. return fecmxc_initialize(bis);
  152. #else
  153. return 0;
  154. #endif
  155. }
  156. /*
  157. * Initializes on-chip MMC controllers.
  158. * to override, implement board_mmc_init()
  159. */
  160. int cpu_mmc_init(bd_t *bis)
  161. {
  162. #ifdef CONFIG_MXC_MMC
  163. return mxc_mmc_init(bis);
  164. #else
  165. return 0;
  166. #endif
  167. }
  168. #ifdef CONFIG_MXC_UART
  169. void mx25_uart1_init_pins(void)
  170. {
  171. struct iomuxc_mux_ctl *muxctl;
  172. struct iomuxc_pad_ctl *padctl;
  173. u32 inpadctl;
  174. u32 outpadctl;
  175. u32 muxmode0;
  176. muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
  177. padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
  178. muxmode0 = MX25_PIN_MUX_MODE(0);
  179. /*
  180. * set up input pins with hysteresis and 100K pull-ups
  181. */
  182. inpadctl = MX25_PIN_PAD_CTL_HYS
  183. | MX25_PIN_PAD_CTL_PKE
  184. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PU;
  185. /*
  186. * set up output pins with 100K pull-downs
  187. * FIXME: need to revisit this
  188. * PUE is ignored if PKE is not set
  189. * so the right value here is likely
  190. * 0x0 for no pull up/down
  191. * or
  192. * 0xc0 for 100k pull down
  193. */
  194. outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  195. /* UART1 */
  196. /* rxd */
  197. writel(muxmode0, &muxctl->pad_uart1_rxd);
  198. writel(inpadctl, &padctl->pad_uart1_rxd);
  199. /* txd */
  200. writel(muxmode0, &muxctl->pad_uart1_txd);
  201. writel(outpadctl, &padctl->pad_uart1_txd);
  202. /* rts */
  203. writel(muxmode0, &muxctl->pad_uart1_rts);
  204. writel(outpadctl, &padctl->pad_uart1_rts);
  205. /* cts */
  206. writel(muxmode0, &muxctl->pad_uart1_cts);
  207. writel(inpadctl, &padctl->pad_uart1_cts);
  208. }
  209. #endif /* CONFIG_MXC_UART */
  210. #ifdef CONFIG_FEC_MXC
  211. void mx25_fec_init_pins(void)
  212. {
  213. struct iomuxc_mux_ctl *muxctl;
  214. struct iomuxc_pad_ctl *padctl;
  215. u32 inpadctl_100kpd;
  216. u32 inpadctl_22kpu;
  217. u32 outpadctl;
  218. u32 muxmode0;
  219. muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
  220. padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
  221. muxmode0 = MX25_PIN_MUX_MODE(0);
  222. inpadctl_100kpd = MX25_PIN_PAD_CTL_HYS
  223. | MX25_PIN_PAD_CTL_PKE
  224. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  225. inpadctl_22kpu = MX25_PIN_PAD_CTL_HYS
  226. | MX25_PIN_PAD_CTL_PKE
  227. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_22K_PU;
  228. /*
  229. * set up output pins with 100K pull-downs
  230. * FIXME: need to revisit this
  231. * PUE is ignored if PKE is not set
  232. * so the right value here is likely
  233. * 0x0 for no pull
  234. * or
  235. * 0xc0 for 100k pull down
  236. */
  237. outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  238. /* FEC_TX_CLK */
  239. writel(muxmode0, &muxctl->pad_fec_tx_clk);
  240. writel(inpadctl_100kpd, &padctl->pad_fec_tx_clk);
  241. /* FEC_RX_DV */
  242. writel(muxmode0, &muxctl->pad_fec_rx_dv);
  243. writel(inpadctl_100kpd, &padctl->pad_fec_rx_dv);
  244. /* FEC_RDATA0 */
  245. writel(muxmode0, &muxctl->pad_fec_rdata0);
  246. writel(inpadctl_100kpd, &padctl->pad_fec_rdata0);
  247. /* FEC_TDATA0 */
  248. writel(muxmode0, &muxctl->pad_fec_tdata0);
  249. writel(outpadctl, &padctl->pad_fec_tdata0);
  250. /* FEC_TX_EN */
  251. writel(muxmode0, &muxctl->pad_fec_tx_en);
  252. writel(outpadctl, &padctl->pad_fec_tx_en);
  253. /* FEC_MDC */
  254. writel(muxmode0, &muxctl->pad_fec_mdc);
  255. writel(outpadctl, &padctl->pad_fec_mdc);
  256. /* FEC_MDIO */
  257. writel(muxmode0, &muxctl->pad_fec_mdio);
  258. writel(inpadctl_22kpu, &padctl->pad_fec_mdio);
  259. /* FEC_RDATA1 */
  260. writel(muxmode0, &muxctl->pad_fec_rdata1);
  261. writel(inpadctl_100kpd, &padctl->pad_fec_rdata1);
  262. /* FEC_TDATA1 */
  263. writel(muxmode0, &muxctl->pad_fec_tdata1);
  264. writel(outpadctl, &padctl->pad_fec_tdata1);
  265. }
  266. void imx_get_mac_from_fuse(unsigned char *mac)
  267. {
  268. int i;
  269. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  270. struct fuse_bank *bank = &iim->bank[0];
  271. struct fuse_bank0_regs *fuse =
  272. (struct fuse_bank0_regs *)bank->fuse_regs;
  273. for (i = 0; i < 6; i++)
  274. mac[i] = readl(&fuse->mac_addr[i]) & 0xff;
  275. }
  276. #endif /* CONFIG_FEC_MXC */