generic.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 = 24000000;
  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. int cpu_eth_init(bd_t *bis)
  161. {
  162. #if defined(CONFIG_FEC_MXC)
  163. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  164. ulong val;
  165. val = readl(&ccm->cgr0);
  166. val |= (1 << 23);
  167. writel(val, &ccm->cgr0);
  168. return fecmxc_initialize(bis);
  169. #else
  170. return 0;
  171. #endif
  172. }
  173. int get_clocks(void)
  174. {
  175. #ifdef CONFIG_FSL_ESDHC
  176. gd->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
  177. #endif
  178. return 0;
  179. }
  180. /*
  181. * Initializes on-chip MMC controllers.
  182. * to override, implement board_mmc_init()
  183. */
  184. int cpu_mmc_init(bd_t *bis)
  185. {
  186. #ifdef CONFIG_MXC_MMC
  187. return mxc_mmc_init(bis);
  188. #else
  189. return 0;
  190. #endif
  191. }
  192. #ifdef CONFIG_MXC_UART
  193. void mx25_uart1_init_pins(void)
  194. {
  195. struct iomuxc_mux_ctl *muxctl;
  196. struct iomuxc_pad_ctl *padctl;
  197. u32 inpadctl;
  198. u32 outpadctl;
  199. u32 muxmode0;
  200. muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
  201. padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
  202. muxmode0 = MX25_PIN_MUX_MODE(0);
  203. /*
  204. * set up input pins with hysteresis and 100K pull-ups
  205. */
  206. inpadctl = MX25_PIN_PAD_CTL_HYS
  207. | MX25_PIN_PAD_CTL_PKE
  208. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PU;
  209. /*
  210. * set up output pins with 100K pull-downs
  211. * FIXME: need to revisit this
  212. * PUE is ignored if PKE is not set
  213. * so the right value here is likely
  214. * 0x0 for no pull up/down
  215. * or
  216. * 0xc0 for 100k pull down
  217. */
  218. outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  219. /* UART1 */
  220. /* rxd */
  221. writel(muxmode0, &muxctl->pad_uart1_rxd);
  222. writel(inpadctl, &padctl->pad_uart1_rxd);
  223. /* txd */
  224. writel(muxmode0, &muxctl->pad_uart1_txd);
  225. writel(outpadctl, &padctl->pad_uart1_txd);
  226. /* rts */
  227. writel(muxmode0, &muxctl->pad_uart1_rts);
  228. writel(outpadctl, &padctl->pad_uart1_rts);
  229. /* cts */
  230. writel(muxmode0, &muxctl->pad_uart1_cts);
  231. writel(inpadctl, &padctl->pad_uart1_cts);
  232. }
  233. #endif /* CONFIG_MXC_UART */
  234. #ifdef CONFIG_FEC_MXC
  235. void mx25_fec_init_pins(void)
  236. {
  237. struct iomuxc_mux_ctl *muxctl;
  238. struct iomuxc_pad_ctl *padctl;
  239. u32 inpadctl_100kpd;
  240. u32 inpadctl_22kpu;
  241. u32 outpadctl;
  242. u32 muxmode0;
  243. muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
  244. padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
  245. muxmode0 = MX25_PIN_MUX_MODE(0);
  246. inpadctl_100kpd = MX25_PIN_PAD_CTL_HYS
  247. | MX25_PIN_PAD_CTL_PKE
  248. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  249. inpadctl_22kpu = MX25_PIN_PAD_CTL_HYS
  250. | MX25_PIN_PAD_CTL_PKE
  251. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_22K_PU;
  252. /*
  253. * set up output pins with 100K pull-downs
  254. * FIXME: need to revisit this
  255. * PUE is ignored if PKE is not set
  256. * so the right value here is likely
  257. * 0x0 for no pull
  258. * or
  259. * 0xc0 for 100k pull down
  260. */
  261. outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  262. /* FEC_TX_CLK */
  263. writel(muxmode0, &muxctl->pad_fec_tx_clk);
  264. writel(inpadctl_100kpd, &padctl->pad_fec_tx_clk);
  265. /* FEC_RX_DV */
  266. writel(muxmode0, &muxctl->pad_fec_rx_dv);
  267. writel(inpadctl_100kpd, &padctl->pad_fec_rx_dv);
  268. /* FEC_RDATA0 */
  269. writel(muxmode0, &muxctl->pad_fec_rdata0);
  270. writel(inpadctl_100kpd, &padctl->pad_fec_rdata0);
  271. /* FEC_TDATA0 */
  272. writel(muxmode0, &muxctl->pad_fec_tdata0);
  273. writel(outpadctl, &padctl->pad_fec_tdata0);
  274. /* FEC_TX_EN */
  275. writel(muxmode0, &muxctl->pad_fec_tx_en);
  276. writel(outpadctl, &padctl->pad_fec_tx_en);
  277. /* FEC_MDC */
  278. writel(muxmode0, &muxctl->pad_fec_mdc);
  279. writel(outpadctl, &padctl->pad_fec_mdc);
  280. /* FEC_MDIO */
  281. writel(muxmode0, &muxctl->pad_fec_mdio);
  282. writel(inpadctl_22kpu, &padctl->pad_fec_mdio);
  283. /* FEC_RDATA1 */
  284. writel(muxmode0, &muxctl->pad_fec_rdata1);
  285. writel(inpadctl_100kpd, &padctl->pad_fec_rdata1);
  286. /* FEC_TDATA1 */
  287. writel(muxmode0, &muxctl->pad_fec_tdata1);
  288. writel(outpadctl, &padctl->pad_fec_tdata1);
  289. }
  290. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  291. {
  292. int i;
  293. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  294. struct fuse_bank *bank = &iim->bank[0];
  295. struct fuse_bank0_regs *fuse =
  296. (struct fuse_bank0_regs *)bank->fuse_regs;
  297. for (i = 0; i < 6; i++)
  298. mac[i] = readl(&fuse->mac_addr[i]) & 0xff;
  299. }
  300. #endif /* CONFIG_FEC_MXC */