main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2012 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. */
  9. #include <linux/mm.h>
  10. #include <linux/delay.h>
  11. #include <linux/clk.h>
  12. #include <linux/io.h>
  13. #include <linux/clkdev.h>
  14. #include <linux/of.h>
  15. #include <linux/err.h>
  16. #include "crmregs-imx3.h"
  17. #include "clk.h"
  18. #include "common.h"
  19. #include "hardware.h"
  20. struct arm_ahb_div {
  21. unsigned char arm, ahb, sel;
  22. };
  23. static struct arm_ahb_div clk_consumer[] = {
  24. { .arm = 1, .ahb = 4, .sel = 0},
  25. { .arm = 1, .ahb = 3, .sel = 1},
  26. { .arm = 2, .ahb = 2, .sel = 0},
  27. { .arm = 0, .ahb = 0, .sel = 0},
  28. { .arm = 0, .ahb = 0, .sel = 0},
  29. { .arm = 0, .ahb = 0, .sel = 0},
  30. { .arm = 4, .ahb = 1, .sel = 0},
  31. { .arm = 1, .ahb = 5, .sel = 0},
  32. { .arm = 1, .ahb = 8, .sel = 0},
  33. { .arm = 1, .ahb = 6, .sel = 1},
  34. { .arm = 2, .ahb = 4, .sel = 0},
  35. { .arm = 0, .ahb = 0, .sel = 0},
  36. { .arm = 0, .ahb = 0, .sel = 0},
  37. { .arm = 0, .ahb = 0, .sel = 0},
  38. { .arm = 4, .ahb = 2, .sel = 0},
  39. { .arm = 0, .ahb = 0, .sel = 0},
  40. };
  41. static char hsp_div_532[] = { 4, 8, 3, 0 };
  42. static char hsp_div_400[] = { 3, 6, 3, 0 };
  43. static const char *std_sel[] = {"ppll", "arm"};
  44. static const char *ipg_per_sel[] = {"ahb_per_div", "arm_per_div"};
  45. enum mx35_clks {
  46. ckih, mpll, ppll, mpll_075, arm, hsp, hsp_div, hsp_sel, ahb, ipg,
  47. arm_per_div, ahb_per_div, ipg_per, uart_sel, uart_div, esdhc_sel,
  48. esdhc1_div, esdhc2_div, esdhc3_div, spdif_sel, spdif_div_pre,
  49. spdif_div_post, ssi_sel, ssi1_div_pre, ssi1_div_post, ssi2_div_pre,
  50. ssi2_div_post, usb_sel, usb_div, nfc_div, asrc_gate, pata_gate,
  51. audmux_gate, can1_gate, can2_gate, cspi1_gate, cspi2_gate, ect_gate,
  52. edio_gate, emi_gate, epit1_gate, epit2_gate, esai_gate, esdhc1_gate,
  53. esdhc2_gate, esdhc3_gate, fec_gate, gpio1_gate, gpio2_gate, gpio3_gate,
  54. gpt_gate, i2c1_gate, i2c2_gate, i2c3_gate, iomuxc_gate, ipu_gate,
  55. kpp_gate, mlb_gate, mshc_gate, owire_gate, pwm_gate, rngc_gate,
  56. rtc_gate, rtic_gate, scc_gate, sdma_gate, spba_gate, spdif_gate,
  57. ssi1_gate, ssi2_gate, uart1_gate, uart2_gate, uart3_gate, usbotg_gate,
  58. wdog_gate, max_gate, admux_gate, csi_gate, csi_div, csi_sel, iim_gate,
  59. gpu2d_gate, clk_max
  60. };
  61. static struct clk *clk[clk_max];
  62. int __init mx35_clocks_init()
  63. {
  64. void __iomem *base = MX35_IO_ADDRESS(MX35_CCM_BASE_ADDR);
  65. u32 pdr0, consumer_sel, hsp_sel;
  66. struct arm_ahb_div *aad;
  67. unsigned char *hsp_div;
  68. int i;
  69. pdr0 = __raw_readl(base + MXC_CCM_PDR0);
  70. consumer_sel = (pdr0 >> 16) & 0xf;
  71. aad = &clk_consumer[consumer_sel];
  72. if (!aad->arm) {
  73. pr_err("i.MX35 clk: illegal consumer mux selection 0x%x\n", consumer_sel);
  74. /*
  75. * We are basically stuck. Continue with a default entry and hope we
  76. * get far enough to actually show the above message
  77. */
  78. aad = &clk_consumer[0];
  79. }
  80. clk[ckih] = imx_clk_fixed("ckih", 24000000);
  81. clk[mpll] = imx_clk_pllv1("mpll", "ckih", base + MX35_CCM_MPCTL);
  82. clk[ppll] = imx_clk_pllv1("ppll", "ckih", base + MX35_CCM_PPCTL);
  83. clk[mpll] = imx_clk_fixed_factor("mpll_075", "mpll", 3, 4);
  84. if (aad->sel)
  85. clk[arm] = imx_clk_fixed_factor("arm", "mpll_075", 1, aad->arm);
  86. else
  87. clk[arm] = imx_clk_fixed_factor("arm", "mpll", 1, aad->arm);
  88. if (clk_get_rate(clk[arm]) > 400000000)
  89. hsp_div = hsp_div_532;
  90. else
  91. hsp_div = hsp_div_400;
  92. hsp_sel = (pdr0 >> 20) & 0x3;
  93. if (!hsp_div[hsp_sel]) {
  94. pr_err("i.MX35 clk: illegal hsp clk selection 0x%x\n", hsp_sel);
  95. hsp_sel = 0;
  96. }