grf.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 RK3368_GRF_SOC_CON15 0x43c
  47. static const struct rockchip_grf_value rk3368_defaults[] __initconst = {
  48. { "jtag switching", RK3368_GRF_SOC_CON15, HIWORD_UPDATE(0, 1, 13) },
  49. };
  50. static const struct rockchip_grf_info rk3368_grf __initconst = {
  51. .values = rk3368_defaults,
  52. .num_values = ARRAY_SIZE(rk3368_defaults),
  53. };
  54. #define RK3399_GRF_SOC_CON7 0xe21c
  55. static const struct rockchip_grf_value rk3399_defaults[] __initconst = {
  56. { "jtag switching", RK3399_GRF_SOC_CON7, HIWORD_UPDATE(0, 1, 12) },
  57. };
  58. static const struct rockchip_grf_info rk3399_grf __initconst = {
  59. .values = rk3399_defaults,
  60. .num_values = ARRAY_SIZE(rk3399_defaults),
  61. };
  62. static const struct of_device_id rockchip_grf_dt_match[] __initconst = {
  63. {
  64. .compatible = "rockchip,rk3036-grf",
  65. .data = (void *)&rk3036_grf,
  66. }, {
  67. .compatible = "rockchip,rk3288-grf",
  68. .data = (void *)&rk3288_grf,
  69. }, {
  70. .compatible = "rockchip,rk3368-grf",
  71. .data = (void *)&rk3368_grf,
  72. }, {
  73. .compatible = "rockchip,rk3399-grf",
  74. .data = (void *)&rk3399_grf,
  75. },
  76. { /* sentinel */ },
  77. };
  78. static int __init rockchip_grf_init(void)
  79. {
  80. const struct rockchip_grf_info *grf_info;
  81. const struct of_device_id *match;
  82. struct device_node *np;
  83. struct regmap *grf;
  84. int ret, i;
  85. np = of_find_matching_node_and_match(NULL, rockchip_grf_dt_match,
  86. &match);
  87. if (!np)
  88. return -ENODEV;
  89. if (!match || !match->data) {
  90. pr_err("%s: missing grf data\n", __func__);
  91. return -EINVAL;
  92. }
  93. grf_info = match->data;
  94. grf = syscon_node_to_regmap(np);
  95. if (IS_ERR(grf)) {
  96. pr_err("%s: could not get grf syscon\n", __func__);
  97. return PTR_ERR(grf);
  98. }
  99. for (i = 0; i < grf_info->num_values; i++) {
  100. const struct rockchip_grf_value *val = &grf_info->values[i];
  101. pr_debug("%s: adjusting %s in %#6x to %#10x\n", __func__,
  102. val->desc, val->reg, val->val);
  103. ret = regmap_write(grf, val->reg, val->val);
  104. if (ret < 0)
  105. pr_err("%s: write to %#6x failed with %d\n",
  106. __func__, val->reg, ret);
  107. }
  108. return 0;
  109. }
  110. postcore_initcall(rockchip_grf_init);