grf.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Rockchip Generic Register Files setup
  4. *
  5. * Copyright (c) 2016 Heiko Stuebner <heiko@sntech.de>
  6. */
  7. #include <linux/err.h>
  8. #include <linux/mfd/syscon.h>
  9. #include <linux/of_device.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/regmap.h>
  12. #define HIWORD_UPDATE(val, mask, shift) \
  13. ((val) << (shift) | (mask) << ((shift) + 16))
  14. struct rockchip_grf_value {
  15. const char *desc;
  16. u32 reg;
  17. u32 val;
  18. };
  19. struct rockchip_grf_info {
  20. const struct rockchip_grf_value *values;
  21. int num_values;
  22. };
  23. #define RK3036_GRF_SOC_CON0 0x140
  24. static const struct rockchip_grf_value rk3036_defaults[] __initconst = {
  25. /*
  26. * Disable auto jtag/sdmmc switching that causes issues with the
  27. * clock-framework and the mmc controllers making them unreliable.
  28. */
  29. { "jtag switching", RK3036_GRF_SOC_CON0, HIWORD_UPDATE(0, 1, 11) },
  30. };
  31. static const struct rockchip_grf_info rk3036_grf __initconst = {
  32. .values = rk3036_defaults,
  33. .num_values = ARRAY_SIZE(rk3036_defaults),
  34. };
  35. #define RK3128_GRF_SOC_CON0 0x140
  36. static const struct rockchip_grf_value rk3128_defaults[] __initconst = {
  37. { "jtag switching", RK3128_GRF_SOC_CON0, HIWORD_UPDATE(0, 1, 8) },
  38. };
  39. static const struct rockchip_grf_info rk3128_grf __initconst = {
  40. .values = rk3128_defaults,
  41. .num_values = ARRAY_SIZE(rk3128_defaults),
  42. };
  43. #define RK3228_GRF_SOC_CON6 0x418
  44. static const struct rockchip_grf_value rk3228_defaults[] __initconst = {
  45. { "jtag switching", RK3228_GRF_SOC_CON6, HIWORD_UPDATE(0, 1, 8) },
  46. };
  47. static const struct rockchip_grf_info rk3228_grf __initconst = {
  48. .values = rk3228_defaults,
  49. .num_values = ARRAY_SIZE(rk3228_defaults),
  50. };
  51. #define RK3288_GRF_SOC_CON0 0x244
  52. #define RK3288_GRF_SOC_CON2 0x24c
  53. static const struct rockchip_grf_value rk3288_defaults[] __initconst = {
  54. { "jtag switching", RK3288_GRF_SOC_CON0, HIWORD_UPDATE(0, 1, 12) },
  55. { "pwm select", RK3288_GRF_SOC_CON2, HIWORD_UPDATE(1, 1, 0) },
  56. };
  57. static const struct rockchip_grf_info rk3288_grf __initconst = {
  58. .values = rk3288_defaults,
  59. .num_values = ARRAY_SIZE(rk3288_defaults),
  60. };
  61. #define RK3328_GRF_SOC_CON4 0x410
  62. static const struct rockchip_grf_value rk3328_defaults[] __initconst = {
  63. { "jtag switching", RK3328_GRF_SOC_CON4, HIWORD_UPDATE(0, 1, 12) },
  64. };
  65. static const struct rockchip_grf_info rk3328_grf __initconst = {
  66. .values = rk3328_defaults,
  67. .num_values = ARRAY_SIZE(rk3328_defaults),
  68. };
  69. #define RK3368_GRF_SOC_CON15 0x43c
  70. static const struct rockchip_grf_value rk3368_defaults[] __initconst = {
  71. { "jtag switching", RK3368_GRF_SOC_CON15, HIWORD_UPDATE(0, 1, 13) },
  72. };
  73. static const struct rockchip_grf_info rk3368_grf __initconst = {
  74. .values = rk3368_defaults,
  75. .num_values = ARRAY_SIZE(rk3368_defaults),
  76. };
  77. #define RK3399_GRF_SOC_CON7 0xe21c
  78. static const struct rockchip_grf_value rk3399_defaults[] __initconst = {
  79. { "jtag switching", RK3399_GRF_SOC_CON7, HIWORD_UPDATE(0, 1, 12) },
  80. };
  81. static const struct rockchip_grf_info rk3399_grf __initconst = {
  82. .values = rk3399_defaults,
  83. .num_values = ARRAY_SIZE(rk3399_defaults),
  84. };
  85. static const struct of_device_id rockchip_grf_dt_match[] __initconst = {
  86. {
  87. .compatible = "rockchip,rk3036-grf",
  88. .data = (void *)&rk3036_grf,
  89. }, {
  90. .compatible = "rockchip,rk3128-grf",
  91. .data = (void *)&rk3128_grf,
  92. }, {
  93. .compatible = "rockchip,rk3228-grf",
  94. .data = (void *)&rk3228_grf,
  95. }, {
  96. .compatible = "rockchip,rk3288-grf",
  97. .data = (void *)&rk3288_grf,
  98. }, {
  99. .compatible = "rockchip,rk3328-grf",
  100. .data = (void *)&rk3328_grf,
  101. }, {
  102. .compatible = "rockchip,rk3368-grf",
  103. .data = (void *)&rk3368_grf,
  104. }, {
  105. .compatible = "rockchip,rk3399-grf",
  106. .data = (void *)&rk3399_grf,
  107. },
  108. { /* sentinel */ },
  109. };
  110. static int __init rockchip_grf_init(void)
  111. {
  112. const struct rockchip_grf_info *grf_info;
  113. const struct of_device_id *match;
  114. struct device_node *np;
  115. struct regmap *grf;
  116. int ret, i;
  117. np = of_find_matching_node_and_match(NULL, rockchip_grf_dt_match,
  118. &match);
  119. if (!np)
  120. return -ENODEV;
  121. if (!match || !match->data) {
  122. pr_err("%s: missing grf data\n", __func__);
  123. return -EINVAL;
  124. }
  125. grf_info = match->data;
  126. grf = syscon_node_to_regmap(np);
  127. if (IS_ERR(grf)) {
  128. pr_err("%s: could not get grf syscon\n", __func__);
  129. return PTR_ERR(grf);
  130. }
  131. for (i = 0; i < grf_info->num_values; i++) {
  132. const struct rockchip_grf_value *val = &grf_info->values[i];
  133. pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
  134. val->desc, val->reg, val->val);
  135. ret = regmap_write(grf, val->reg, val->val);
  136. if (ret < 0)
  137. pr_err("%s: write to %#6x failed with %d\n",
  138. __func__, val->reg, ret);
  139. }
  140. return 0;
  141. }
  142. postcore_initcall(rockchip_grf_init);