generic.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. case 0x02:
  123. system_rev |= CHIP_REV_1_2;
  124. break;
  125. default:
  126. system_rev |= 0x8000;
  127. break;
  128. }
  129. return system_rev;
  130. }
  131. #if defined(CONFIG_DISPLAY_CPUINFO)
  132. static char *get_reset_cause(void)
  133. {
  134. /* read RCSR register from CCM module */
  135. struct ccm_regs *ccm =
  136. (struct ccm_regs *)IMX_CCM_BASE;
  137. u32 cause = readl(&ccm->rcsr) & 0x0f;
  138. if (cause == 0)
  139. return "POR";
  140. else if (cause == 1)
  141. return "RST";
  142. else if ((cause & 2) == 2)
  143. return "WDOG";
  144. else if ((cause & 4) == 4)
  145. return "SW RESET";
  146. else if ((cause & 8) == 8)
  147. return "JTAG";
  148. else
  149. return "unknown reset";
  150. }
  151. int print_cpuinfo(void)
  152. {
  153. char buf[32];
  154. u32 cpurev = get_cpu_rev();
  155. printf("CPU: Freescale i.MX25 rev%d.%d%s at %s MHz\n",
  156. (cpurev & 0xF0) >> 4, (cpurev & 0x0F),
  157. ((cpurev & 0x8000) ? " unknown" : ""),
  158. strmhz(buf, imx_get_armclk()));
  159. printf("Reset cause: %s\n\n", get_reset_cause());
  160. return 0;
  161. }
  162. #endif
  163. void enable_caches(void)
  164. {
  165. #ifndef CONFIG_SYS_DCACHE_OFF
  166. /* Enable D-cache. I-cache is already enabled in start.S */
  167. dcache_enable();
  168. #endif
  169. }
  170. int cpu_eth_init(bd_t *bis)
  171. {
  172. #if defined(CONFIG_FEC_MXC)
  173. struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
  174. ulong val;
  175. val = readl(&ccm->cgr0);
  176. val |= (1 << 23);
  177. writel(val, &ccm->cgr0);
  178. return fecmxc_initialize(bis);
  179. #else
  180. return 0;
  181. #endif
  182. }
  183. int get_clocks(void)
  184. {
  185. #ifdef CONFIG_FSL_ESDHC
  186. gd->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
  187. #endif
  188. return 0;
  189. }
  190. /*
  191. * Initializes on-chip MMC controllers.
  192. * to override, implement board_mmc_init()
  193. */
  194. int cpu_mmc_init(bd_t *bis)
  195. {
  196. #ifdef CONFIG_MXC_MMC
  197. return mxc_mmc_init(bis);
  198. #else
  199. return 0;
  200. #endif
  201. }
  202. #ifdef CONFIG_MXC_UART
  203. void mx25_uart1_init_pins(void)
  204. {
  205. struct iomuxc_mux_ctl *muxctl;
  206. struct iomuxc_pad_ctl *padctl;
  207. u32 inpadctl;
  208. u32 outpadctl;
  209. u32 muxmode0;
  210. muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
  211. padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
  212. muxmode0 = MX25_PIN_MUX_MODE(0);
  213. /*
  214. * set up input pins with hysteresis and 100K pull-ups
  215. */
  216. inpadctl = MX25_PIN_PAD_CTL_HYS
  217. | MX25_PIN_PAD_CTL_PKE
  218. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PU;
  219. /*
  220. * set up output pins with 100K pull-downs
  221. * FIXME: need to revisit this
  222. * PUE is ignored if PKE is not set
  223. * so the right value here is likely
  224. * 0x0 for no pull up/down
  225. * or
  226. * 0xc0 for 100k pull down
  227. */
  228. outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  229. /* UART1 */
  230. /* rxd */
  231. writel(muxmode0, &muxctl->pad_uart1_rxd);
  232. writel(inpadctl, &padctl->pad_uart1_rxd);
  233. /* txd */
  234. writel(muxmode0, &muxctl->pad_uart1_txd);
  235. writel(outpadctl, &padctl->pad_uart1_txd);
  236. /* rts */
  237. writel(muxmode0, &muxctl->pad_uart1_rts);
  238. writel(outpadctl, &padctl->pad_uart1_rts);
  239. /* cts */
  240. writel(muxmode0, &muxctl->pad_uart1_cts);
  241. writel(inpadctl, &padctl->pad_uart1_cts);
  242. }
  243. #endif /* CONFIG_MXC_UART */
  244. #ifdef CONFIG_FEC_MXC
  245. void mx25_fec_init_pins(void)
  246. {
  247. struct iomuxc_mux_ctl *muxctl;
  248. struct iomuxc_pad_ctl *padctl;
  249. u32 inpadctl_100kpd;
  250. u32 inpadctl_22kpu;
  251. u32 outpadctl;
  252. u32 muxmode0;
  253. muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
  254. padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
  255. muxmode0 = MX25_PIN_MUX_MODE(0);
  256. inpadctl_100kpd = MX25_PIN_PAD_CTL_HYS
  257. | MX25_PIN_PAD_CTL_PKE
  258. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  259. inpadctl_22kpu = MX25_PIN_PAD_CTL_HYS
  260. | MX25_PIN_PAD_CTL_PKE
  261. | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_22K_PU;
  262. /*
  263. * set up output pins with 100K pull-downs
  264. * FIXME: need to revisit this
  265. * PUE is ignored if PKE is not set
  266. * so the right value here is likely
  267. * 0x0 for no pull
  268. * or
  269. * 0xc0 for 100k pull down
  270. */
  271. outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
  272. /* FEC_TX_CLK */
  273. writel(muxmode0, &muxctl->pad_fec_tx_clk);
  274. writel(inpadctl_100kpd, &padctl->pad_fec_tx_clk);
  275. /* FEC_RX_DV */
  276. writel(muxmode0, &muxctl->pad_fec_rx_dv);
  277. writel(inpadctl_100kpd, &padctl->pad_fec_rx_dv);
  278. /* FEC_RDATA0 */
  279. writel(muxmode0, &muxctl->pad_fec_rdata0);
  280. writel(inpadctl_100kpd, &padctl->pad_fec_rdata0);
  281. /* FEC_TDATA0 */
  282. writel(muxmode0, &muxctl->pad_fec_tdata0);
  283. writel(outpadctl, &padctl->pad_fec_tdata0);
  284. /* FEC_TX_EN */
  285. writel(muxmode0, &muxctl->pad_fec_tx_en);
  286. writel(outpadctl, &padctl->pad_fec_tx_en);
  287. /* FEC_MDC */
  288. writel(muxmode0, &muxctl->pad_fec_mdc);
  289. writel(outpadctl, &padctl->pad_fec_mdc);
  290. /* FEC_MDIO */
  291. writel(muxmode0, &muxctl->pad_fec_mdio);
  292. writel(inpadctl_22kpu, &padctl->pad_fec_mdio);
  293. /* FEC_RDATA1 */
  294. writel(muxmode0, &muxctl->pad_fec_rdata1);
  295. writel(inpadctl_100kpd, &padctl->pad_fec_rdata1);
  296. /* FEC_TDATA1 */
  297. writel(muxmode0, &muxctl->pad_fec_tdata1);
  298. writel(outpadctl, &padctl->pad_fec_tdata1);
  299. }
  300. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  301. {
  302. int i;
  303. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  304. struct fuse_bank *bank = &iim->bank[0];
  305. struct fuse_bank0_regs *fuse =
  306. (struct fuse_bank0_regs *)bank->fuse_regs;
  307. for (i = 0; i < 6; i++)
  308. mac[i] = readl(&fuse->mac_addr[i]) & 0xff;
  309. }
  310. #endif /* CONFIG_FEC_MXC */