clk-s3c2412.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2013 Heiko Stuebner <[email protected]>
  4. *
  5. * Common Clock Framework support for S3C2412 and S3C2413.
  6. */
  7. #include <linux/clk-provider.h>
  8. #include <linux/clk/samsung.h>
  9. #include <linux/io.h>
  10. #include <linux/of.h>
  11. #include <linux/of_address.h>
  12. #include <linux/reboot.h>
  13. #include <dt-bindings/clock/s3c2412.h>
  14. #include "clk.h"
  15. #include "clk-pll.h"
  16. #define LOCKTIME 0x00
  17. #define MPLLCON 0x04
  18. #define UPLLCON 0x08
  19. #define CLKCON 0x0c
  20. #define CLKDIVN 0x14
  21. #define CLKSRC 0x1c
  22. #define SWRST 0x30
  23. static void __iomem *reg_base;
  24. /*
  25. * list of controller registers to be saved and restored during a
  26. * suspend/resume cycle.
  27. */
  28. static unsigned long s3c2412_clk_regs[] __initdata = {
  29. LOCKTIME,
  30. MPLLCON,
  31. UPLLCON,
  32. CLKCON,
  33. CLKDIVN,
  34. CLKSRC,
  35. };
  36. static struct clk_div_table divxti_d[] = {
  37. { .val = 0, .div = 1 },
  38. { .val = 1, .div = 2 },
  39. { .val = 2, .div = 4 },
  40. { .val = 3, .div = 6 },
  41. { .val = 4, .div = 8 },
  42. { .val = 5, .div = 10 },
  43. { .val = 6, .div = 12 },
  44. { .val = 7, .div = 14 },
  45. { /* sentinel */ },
  46. };
  47. static struct samsung_div_clock s3c2412_dividers[] __initdata = {
  48. DIV_T(0, "div_xti", "xti", CLKSRC, 0, 3, divxti_d),
  49. DIV(0, "div_cam", "mux_cam", CLKDIVN, 16, 4),
  50. DIV(0, "div_i2s", "mux_i2s", CLKDIVN, 12, 4),
  51. DIV(0, "div_uart", "mux_uart", CLKDIVN, 8, 4),
  52. DIV(0, "div_usb", "mux_usb", CLKDIVN, 6, 1),
  53. DIV(0, "div_hclk_half", "hclk", CLKDIVN, 5, 1),
  54. DIV(ARMDIV, "armdiv", "msysclk", CLKDIVN, 3, 1),
  55. DIV(PCLK, "pclk", "hclk", CLKDIVN, 2, 1),
  56. DIV(HCLK, "hclk", "armdiv", CLKDIVN, 0, 2),
  57. };
  58. static struct samsung_fixed_factor_clock s3c2412_ffactor[] __initdata = {
  59. FFACTOR(0, "ff_hclk", "hclk", 2, 1, CLK_SET_RATE_PARENT),
  60. };
  61. /*
  62. * The first two use the OM[4] setting, which is not readable from
  63. * software, so assume it is set to xti.
  64. */
  65. PNAME(erefclk_p) = { "xti", "xti", "xti", "ext" };
  66. PNAME(urefclk_p) = { "xti", "xti", "xti", "ext" };
  67. PNAME(camclk_p) = { "usysclk", "hclk" };
  68. PNAME(usbclk_p) = { "usysclk", "hclk" };
  69. PNAME(i2sclk_p) = { "erefclk", "mpll" };
  70. PNAME(uartclk_p) = { "erefclk", "mpll" };
  71. PNAME(usysclk_p) = { "urefclk", "upll" };
  72. PNAME(msysclk_p) = { "mdivclk", "mpll" };
  73. PNAME(mdivclk_p) = { "xti", "div_xti" };
  74. PNAME(armclk_p) = { "armdiv", "hclk" };
  75. static struct samsung_mux_clock s3c2412_muxes[] __initdata = {
  76. MUX(0, "erefclk", erefclk_p, CLKSRC, 14, 2),
  77. MUX(0, "urefclk", urefclk_p, CLKSRC, 12, 2),
  78. MUX(0, "mux_cam", camclk_p, CLKSRC, 11, 1),
  79. MUX(0, "mux_usb", usbclk_p, CLKSRC, 10, 1),
  80. MUX(0, "mux_i2s", i2sclk_p, CLKSRC, 9, 1),
  81. MUX(0, "mux_uart", uartclk_p, CLKSRC, 8, 1),
  82. MUX(USYSCLK, "usysclk", usysclk_p, CLKSRC, 5, 1),
  83. MUX(MSYSCLK, "msysclk", msysclk_p, CLKSRC, 4, 1),
  84. MUX(MDIVCLK, "mdivclk", mdivclk_p, CLKSRC, 3, 1),
  85. MUX(ARMCLK, "armclk", armclk_p, CLKDIVN, 4, 1),
  86. };
  87. static struct samsung_pll_clock s3c2412_plls[] __initdata = {
  88. PLL(pll_s3c2440_mpll, MPLL, "mpll", "xti", LOCKTIME, MPLLCON, NULL),
  89. PLL(pll_s3c2410_upll, UPLL, "upll", "urefclk", LOCKTIME, UPLLCON, NULL),
  90. };
  91. static struct samsung_gate_clock s3c2412_gates[] __initdata = {
  92. GATE(PCLK_WDT, "wdt", "pclk", CLKCON, 28, 0, 0),
  93. GATE(PCLK_SPI, "spi", "pclk", CLKCON, 27, 0, 0),
  94. GATE(PCLK_I2S, "i2s", "pclk", CLKCON, 26, 0, 0),
  95. GATE(PCLK_I2C, "i2c", "pclk", CLKCON, 25, 0, 0),
  96. GATE(PCLK_ADC, "adc", "pclk", CLKCON, 24, 0, 0),
  97. GATE(PCLK_RTC, "rtc", "pclk", CLKCON, 23, 0, 0),
  98. GATE(PCLK_GPIO, "gpio", "pclk", CLKCON, 22, CLK_IGNORE_UNUSED, 0),
  99. GATE(PCLK_UART2, "uart2", "pclk", CLKCON, 21, 0, 0),
  100. GATE(PCLK_UART1, "uart1", "pclk", CLKCON, 20, 0, 0),
  101. GATE(PCLK_UART0, "uart0", "pclk", CLKCON, 19, 0, 0),
  102. GATE(PCLK_SDI, "sdi", "pclk", CLKCON, 18, 0, 0),
  103. GATE(PCLK_PWM, "pwm", "pclk", CLKCON, 17, 0, 0),
  104. GATE(PCLK_USBD, "usb-device", "pclk", CLKCON, 16, 0, 0),
  105. GATE(SCLK_CAM, "sclk_cam", "div_cam", CLKCON, 15, 0, 0),
  106. GATE(SCLK_UART, "sclk_uart", "div_uart", CLKCON, 14, 0, 0),
  107. GATE(SCLK_I2S, "sclk_i2s", "div_i2s", CLKCON, 13, 0, 0),
  108. GATE(SCLK_USBH, "sclk_usbh", "div_usb", CLKCON, 12, 0, 0),
  109. GATE(SCLK_USBD, "sclk_usbd", "div_usb", CLKCON, 11, 0, 0),
  110. GATE(HCLK_HALF, "hclk_half", "div_hclk_half", CLKCON, 10, CLK_IGNORE_UNUSED, 0),
  111. GATE(HCLK_X2, "hclkx2", "ff_hclk", CLKCON, 9, CLK_IGNORE_UNUSED, 0),
  112. GATE(HCLK_SDRAM, "sdram", "hclk", CLKCON, 8, CLK_IGNORE_UNUSED, 0),
  113. GATE(HCLK_USBH, "usb-host", "hclk", CLKCON, 6, 0, 0),
  114. GATE(HCLK_LCD, "lcd", "hclk", CLKCON, 5, 0, 0),
  115. GATE(HCLK_NAND, "nand", "hclk", CLKCON, 4, 0, 0),
  116. GATE(HCLK_DMA3, "dma3", "hclk", CLKCON, 3, CLK_IGNORE_UNUSED, 0),
  117. GATE(HCLK_DMA2, "dma2", "hclk", CLKCON, 2, CLK_IGNORE_UNUSED, 0),
  118. GATE(HCLK_DMA1, "dma1", "hclk", CLKCON, 1, CLK_IGNORE_UNUSED, 0),
  119. GATE(HCLK_DMA0, "dma0", "hclk", CLKCON, 0, CLK_IGNORE_UNUSED, 0),
  120. };
  121. static struct samsung_clock_alias s3c2412_aliases[] __initdata = {
  122. ALIAS(PCLK_UART0, "s3c2412-uart.0", "uart"),
  123. ALIAS(PCLK_UART1, "s3c2412-uart.1", "uart"),
  124. ALIAS(PCLK_UART2, "s3c2412-uart.2", "uart"),
  125. ALIAS(PCLK_UART0, "s3c2412-uart.0", "clk_uart_baud2"),
  126. ALIAS(PCLK_UART1, "s3c2412-uart.1", "clk_uart_baud2"),
  127. ALIAS(PCLK_UART2, "s3c2412-uart.2", "clk_uart_baud2"),
  128. ALIAS(SCLK_UART, NULL, "clk_uart_baud3"),
  129. ALIAS(PCLK_I2C, "s3c2410-i2c.0", "i2c"),
  130. ALIAS(PCLK_ADC, NULL, "adc"),
  131. ALIAS(PCLK_RTC, NULL, "rtc"),
  132. ALIAS(PCLK_PWM, NULL, "timers"),
  133. ALIAS(HCLK_LCD, NULL, "lcd"),
  134. ALIAS(PCLK_USBD, NULL, "usb-device"),
  135. ALIAS(SCLK_USBD, NULL, "usb-bus-gadget"),
  136. ALIAS(HCLK_USBH, NULL, "usb-host"),
  137. ALIAS(SCLK_USBH, NULL, "usb-bus-host"),
  138. ALIAS(ARMCLK, NULL, "armclk"),
  139. ALIAS(HCLK, NULL, "hclk"),
  140. ALIAS(MPLL, NULL, "mpll"),
  141. ALIAS(MSYSCLK, NULL, "fclk"),
  142. };
  143. static int s3c2412_restart(struct notifier_block *this,
  144. unsigned long mode, void *cmd)
  145. {
  146. /* errata "Watch-dog/Software Reset Problem" specifies that
  147. * this reset must be done with the SYSCLK sourced from
  148. * EXTCLK instead of FOUT to avoid a glitch in the reset
  149. * mechanism.
  150. *
  151. * See the watchdog section of the S3C2412 manual for more
  152. * information on this fix.
  153. */
  154. __raw_writel(0x00, reg_base + CLKSRC);
  155. __raw_writel(0x533C2412, reg_base + SWRST);
  156. return NOTIFY_DONE;
  157. }
  158. static struct notifier_block s3c2412_restart_handler = {
  159. .notifier_call = s3c2412_restart,
  160. .priority = 129,
  161. };
  162. /*
  163. * fixed rate clocks generated outside the soc
  164. * Only necessary until the devicetree-move is complete
  165. */
  166. #define XTI 1
  167. static struct samsung_fixed_rate_clock s3c2412_common_frate_clks[] __initdata = {
  168. FRATE(XTI, "xti", NULL, 0, 0),
  169. FRATE(0, "ext", NULL, 0, 0),
  170. };
  171. static void __init s3c2412_common_clk_register_fixed_ext(
  172. struct samsung_clk_provider *ctx,
  173. unsigned long xti_f, unsigned long ext_f)
  174. {
  175. /* xtal alias is necessary for the current cpufreq driver */
  176. struct samsung_clock_alias xti_alias = ALIAS(XTI, NULL, "xtal");
  177. s3c2412_common_frate_clks[0].fixed_rate = xti_f;
  178. s3c2412_common_frate_clks[1].fixed_rate = ext_f;
  179. samsung_clk_register_fixed_rate(ctx, s3c2412_common_frate_clks,
  180. ARRAY_SIZE(s3c2412_common_frate_clks));
  181. samsung_clk_register_alias(ctx, &xti_alias, 1);
  182. }
  183. void __init s3c2412_common_clk_init(struct device_node *np, unsigned long xti_f,
  184. unsigned long ext_f, void __iomem *base)
  185. {
  186. struct samsung_clk_provider *ctx;
  187. int ret;
  188. reg_base = base;
  189. if (np) {
  190. reg_base = of_iomap(np, 0);
  191. if (!reg_base)
  192. panic("%s: failed to map registers\n", __func__);
  193. }
  194. ctx = samsung_clk_init(np, reg_base, NR_CLKS);
  195. /* Register external clocks only in non-dt cases */
  196. if (!np)
  197. s3c2412_common_clk_register_fixed_ext(ctx, xti_f, ext_f);
  198. /* Register PLLs. */
  199. samsung_clk_register_pll(ctx, s3c2412_plls, ARRAY_SIZE(s3c2412_plls),
  200. reg_base);
  201. /* Register common internal clocks. */
  202. samsung_clk_register_mux(ctx, s3c2412_muxes, ARRAY_SIZE(s3c2412_muxes));
  203. samsung_clk_register_div(ctx, s3c2412_dividers,
  204. ARRAY_SIZE(s3c2412_dividers));
  205. samsung_clk_register_gate(ctx, s3c2412_gates,
  206. ARRAY_SIZE(s3c2412_gates));
  207. samsung_clk_register_fixed_factor(ctx, s3c2412_ffactor,
  208. ARRAY_SIZE(s3c2412_ffactor));
  209. samsung_clk_register_alias(ctx, s3c2412_aliases,
  210. ARRAY_SIZE(s3c2412_aliases));
  211. samsung_clk_sleep_init(reg_base, s3c2412_clk_regs,
  212. ARRAY_SIZE(s3c2412_clk_regs));
  213. samsung_clk_of_add_provider(np, ctx);
  214. ret = register_restart_handler(&s3c2412_restart_handler);
  215. if (ret)
  216. pr_warn("cannot register restart handler, %d\n", ret);
  217. }
  218. static void __init s3c2412_clk_init(struct device_node *np)
  219. {
  220. s3c2412_common_clk_init(np, 0, 0, NULL);
  221. }
  222. CLK_OF_DECLARE(s3c2412_clk, "samsung,s3c2412-clock", s3c2412_clk_init);