grf.c 3.8 KB

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