gxbb-aoclk.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  2. /*
  3. * Copyright (c) 2016 BayLibre, SAS.
  4. * Author: Neil Armstrong <narmstrong@baylibre.com>
  5. */
  6. #include <linux/platform_device.h>
  7. #include <linux/mfd/syscon.h>
  8. #include "clk-regmap.h"
  9. #include "meson-aoclk.h"
  10. #include "gxbb-aoclk.h"
  11. #define GXBB_AO_GATE(_name, _bit) \
  12. static struct clk_regmap _name##_ao = { \
  13. .data = &(struct clk_regmap_gate_data) { \
  14. .offset = AO_RTI_GEN_CNTL_REG0, \
  15. .bit_idx = (_bit), \
  16. }, \
  17. .hw.init = &(struct clk_init_data) { \
  18. .name = #_name "_ao", \
  19. .ops = &clk_regmap_gate_ops, \
  20. .parent_names = (const char *[]){ "clk81" }, \
  21. .num_parents = 1, \
  22. .flags = CLK_IGNORE_UNUSED, \
  23. }, \
  24. }
  25. GXBB_AO_GATE(remote, 0);
  26. GXBB_AO_GATE(i2c_master, 1);
  27. GXBB_AO_GATE(i2c_slave, 2);
  28. GXBB_AO_GATE(uart1, 3);
  29. GXBB_AO_GATE(uart2, 5);
  30. GXBB_AO_GATE(ir_blaster, 6);
  31. static struct aoclk_cec_32k cec_32k_ao = {
  32. .hw.init = &(struct clk_init_data) {
  33. .name = "cec_32k_ao",
  34. .ops = &meson_aoclk_cec_32k_ops,
  35. .parent_names = (const char *[]){ "xtal" },
  36. .num_parents = 1,
  37. .flags = CLK_IGNORE_UNUSED,
  38. },
  39. };
  40. static const unsigned int gxbb_aoclk_reset[] = {
  41. [RESET_AO_REMOTE] = 16,
  42. [RESET_AO_I2C_MASTER] = 18,
  43. [RESET_AO_I2C_SLAVE] = 19,
  44. [RESET_AO_UART1] = 17,
  45. [RESET_AO_UART2] = 22,
  46. [RESET_AO_IR_BLASTER] = 23,
  47. };
  48. static struct clk_regmap *gxbb_aoclk_gate[] = {
  49. [CLKID_AO_REMOTE] = &remote_ao,
  50. [CLKID_AO_I2C_MASTER] = &i2c_master_ao,
  51. [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao,
  52. [CLKID_AO_UART1] = &uart1_ao,
  53. [CLKID_AO_UART2] = &uart2_ao,
  54. [CLKID_AO_IR_BLASTER] = &ir_blaster_ao,
  55. };
  56. static const struct clk_hw_onecell_data gxbb_aoclk_onecell_data = {
  57. .hws = {
  58. [CLKID_AO_REMOTE] = &remote_ao.hw,
  59. [CLKID_AO_I2C_MASTER] = &i2c_master_ao.hw,
  60. [CLKID_AO_I2C_SLAVE] = &i2c_slave_ao.hw,
  61. [CLKID_AO_UART1] = &uart1_ao.hw,
  62. [CLKID_AO_UART2] = &uart2_ao.hw,
  63. [CLKID_AO_IR_BLASTER] = &ir_blaster_ao.hw,
  64. [CLKID_AO_CEC_32K] = &cec_32k_ao.hw,
  65. },
  66. .num = NR_CLKS,
  67. };
  68. static int gxbb_register_cec_ao_32k(struct platform_device *pdev)
  69. {
  70. struct device *dev = &pdev->dev;
  71. struct regmap *regmap;
  72. int ret;
  73. regmap = syscon_node_to_regmap(of_get_parent(dev->of_node));
  74. if (IS_ERR(regmap)) {
  75. dev_err(dev, "failed to get regmap\n");
  76. return PTR_ERR(regmap);
  77. }
  78. /* Specific clocks */
  79. cec_32k_ao.regmap = regmap;
  80. ret = devm_clk_hw_register(dev, &cec_32k_ao.hw);
  81. if (ret) {
  82. dev_err(&pdev->dev, "clk cec_32k_ao register failed.\n");
  83. return ret;
  84. }
  85. return 0;
  86. }
  87. static const struct meson_aoclk_data gxbb_aoclkc_data = {
  88. .reset_reg = AO_RTI_GEN_CNTL_REG0,
  89. .num_reset = ARRAY_SIZE(gxbb_aoclk_reset),
  90. .reset = gxbb_aoclk_reset,
  91. .num_clks = ARRAY_SIZE(gxbb_aoclk_gate),
  92. .clks = gxbb_aoclk_gate,
  93. .hw_data = &gxbb_aoclk_onecell_data,
  94. };
  95. static int gxbb_aoclkc_probe(struct platform_device *pdev)
  96. {
  97. int ret = gxbb_register_cec_ao_32k(pdev);
  98. if (ret)
  99. return ret;
  100. return meson_aoclkc_probe(pdev);
  101. }
  102. static const struct of_device_id gxbb_aoclkc_match_table[] = {
  103. {
  104. .compatible = "amlogic,meson-gx-aoclkc",
  105. .data = &gxbb_aoclkc_data,
  106. },
  107. { }
  108. };
  109. static struct platform_driver gxbb_aoclkc_driver = {
  110. .probe = gxbb_aoclkc_probe,
  111. .driver = {
  112. .name = "gxbb-aoclkc",
  113. .of_match_table = gxbb_aoclkc_match_table,
  114. },
  115. };
  116. builtin_platform_driver(gxbb_aoclkc_driver);