clk-mt8173-pericfg.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022 Collabora Ltd.
  4. * Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  5. */
  6. #include <dt-bindings/clock/mt8173-clk.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include "clk-gate.h"
  10. #include "clk-mtk.h"
  11. #include "reset.h"
  12. #define GATE_PERI0(_id, _name, _parent, _shift) \
  13. GATE_MTK(_id, _name, _parent, &peri0_cg_regs, \
  14. _shift, &mtk_clk_gate_ops_setclr)
  15. #define GATE_PERI1(_id, _name, _parent, _shift) \
  16. GATE_MTK(_id, _name, _parent, &peri1_cg_regs, \
  17. _shift, &mtk_clk_gate_ops_setclr)
  18. static DEFINE_SPINLOCK(mt8173_clk_lock);
  19. static const struct mtk_gate_regs peri0_cg_regs = {
  20. .set_ofs = 0x0008,
  21. .clr_ofs = 0x0010,
  22. .sta_ofs = 0x0018,
  23. };
  24. static const struct mtk_gate_regs peri1_cg_regs = {
  25. .set_ofs = 0x000c,
  26. .clr_ofs = 0x0014,
  27. .sta_ofs = 0x001c,
  28. };
  29. static const char * const uart_ck_sel_parents[] = {
  30. "clk26m",
  31. "uart_sel",
  32. };
  33. static const struct mtk_composite peri_clks[] = {
  34. MUX(CLK_PERI_UART0_SEL, "uart0_ck_sel", uart_ck_sel_parents, 0x40c, 0, 1),
  35. MUX(CLK_PERI_UART1_SEL, "uart1_ck_sel", uart_ck_sel_parents, 0x40c, 1, 1),
  36. MUX(CLK_PERI_UART2_SEL, "uart2_ck_sel", uart_ck_sel_parents, 0x40c, 2, 1),
  37. MUX(CLK_PERI_UART3_SEL, "uart3_ck_sel", uart_ck_sel_parents, 0x40c, 3, 1),
  38. };
  39. static const struct mtk_gate peri_gates[] = {
  40. GATE_DUMMY(CLK_DUMMY, "peri_gate_dummy"),
  41. /* PERI0 */
  42. GATE_PERI0(CLK_PERI_NFI, "peri_nfi", "axi_sel", 0),
  43. GATE_PERI0(CLK_PERI_THERM, "peri_therm", "axi_sel", 1),
  44. GATE_PERI0(CLK_PERI_PWM1, "peri_pwm1", "axi_sel", 2),
  45. GATE_PERI0(CLK_PERI_PWM2, "peri_pwm2", "axi_sel", 3),
  46. GATE_PERI0(CLK_PERI_PWM3, "peri_pwm3", "axi_sel", 4),
  47. GATE_PERI0(CLK_PERI_PWM4, "peri_pwm4", "axi_sel", 5),
  48. GATE_PERI0(CLK_PERI_PWM5, "peri_pwm5", "axi_sel", 6),
  49. GATE_PERI0(CLK_PERI_PWM6, "peri_pwm6", "axi_sel", 7),
  50. GATE_PERI0(CLK_PERI_PWM7, "peri_pwm7", "axi_sel", 8),
  51. GATE_PERI0(CLK_PERI_PWM, "peri_pwm", "axi_sel", 9),
  52. GATE_PERI0(CLK_PERI_USB0, "peri_usb0", "usb20_sel", 10),
  53. GATE_PERI0(CLK_PERI_USB1, "peri_usb1", "usb20_sel", 11),
  54. GATE_PERI0(CLK_PERI_AP_DMA, "peri_ap_dma", "axi_sel", 12),
  55. GATE_PERI0(CLK_PERI_MSDC30_0, "peri_msdc30_0", "msdc50_0_sel", 13),
  56. GATE_PERI0(CLK_PERI_MSDC30_1, "peri_msdc30_1", "msdc30_1_sel", 14),
  57. GATE_PERI0(CLK_PERI_MSDC30_2, "peri_msdc30_2", "msdc30_2_sel", 15),
  58. GATE_PERI0(CLK_PERI_MSDC30_3, "peri_msdc30_3", "msdc30_3_sel", 16),
  59. GATE_PERI0(CLK_PERI_NLI_ARB, "peri_nli_arb", "axi_sel", 17),
  60. GATE_PERI0(CLK_PERI_IRDA, "peri_irda", "irda_sel", 18),
  61. GATE_PERI0(CLK_PERI_UART0, "peri_uart0", "axi_sel", 19),
  62. GATE_PERI0(CLK_PERI_UART1, "peri_uart1", "axi_sel", 20),
  63. GATE_PERI0(CLK_PERI_UART2, "peri_uart2", "axi_sel", 21),
  64. GATE_PERI0(CLK_PERI_UART3, "peri_uart3", "axi_sel", 22),
  65. GATE_PERI0(CLK_PERI_I2C0, "peri_i2c0", "axi_sel", 23),
  66. GATE_PERI0(CLK_PERI_I2C1, "peri_i2c1", "axi_sel", 24),
  67. GATE_PERI0(CLK_PERI_I2C2, "peri_i2c2", "axi_sel", 25),
  68. GATE_PERI0(CLK_PERI_I2C3, "peri_i2c3", "axi_sel", 26),
  69. GATE_PERI0(CLK_PERI_I2C4, "peri_i2c4", "axi_sel", 27),
  70. GATE_PERI0(CLK_PERI_AUXADC, "peri_auxadc", "clk26m", 28),
  71. GATE_PERI0(CLK_PERI_SPI0, "peri_spi0", "spi_sel", 29),
  72. GATE_PERI0(CLK_PERI_I2C5, "peri_i2c5", "axi_sel", 30),
  73. GATE_PERI0(CLK_PERI_NFIECC, "peri_nfiecc", "axi_sel", 31),
  74. /* PERI1 */
  75. GATE_PERI1(CLK_PERI_SPI, "peri_spi", "spi_sel", 0),
  76. GATE_PERI1(CLK_PERI_IRRX, "peri_irrx", "spi_sel", 1),
  77. GATE_PERI1(CLK_PERI_I2C6, "peri_i2c6", "axi_sel", 2),
  78. };
  79. static u16 pericfg_rst_ofs[] = { 0x0, 0x4 };
  80. static const struct mtk_clk_rst_desc clk_rst_desc = {
  81. .version = MTK_RST_SIMPLE,
  82. .rst_bank_ofs = pericfg_rst_ofs,
  83. .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
  84. };
  85. static const struct mtk_clk_desc peri_desc = {
  86. .clks = peri_gates,
  87. .num_clks = ARRAY_SIZE(peri_gates),
  88. .composite_clks = peri_clks,
  89. .num_composite_clks = ARRAY_SIZE(peri_clks),
  90. .clk_lock = &mt8173_clk_lock,
  91. .rst_desc = &clk_rst_desc,
  92. };
  93. static const struct of_device_id of_match_clk_mt8173_pericfg[] = {
  94. { .compatible = "mediatek,mt8173-pericfg", .data = &peri_desc },
  95. { /* sentinel */ }
  96. };
  97. MODULE_DEVICE_TABLE(of, of_match_clk_mt8173_pericfg);
  98. static struct platform_driver clk_mt8173_pericfg_drv = {
  99. .driver = {
  100. .name = "clk-mt8173-pericfg",
  101. .of_match_table = of_match_clk_mt8173_pericfg,
  102. },
  103. .probe = mtk_clk_simple_probe,
  104. .remove = mtk_clk_simple_remove,
  105. };
  106. module_platform_driver(clk_mt8173_pericfg_drv);
  107. MODULE_DESCRIPTION("MediaTek MT8173 pericfg clocks driver");
  108. MODULE_LICENSE("GPL");