0012-reset-starfive-jh71x0-Use-32bit-I-O-on-32bit-registe.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. From 365bb978e5e11a16c362d9c2c64d7bf8d04999df Mon Sep 17 00:00:00 2001
  2. From: Emil Renner Berthing <[email protected]>
  3. Date: Sat, 1 Apr 2023 19:19:24 +0800
  4. Subject: [PATCH 012/122] reset: starfive: jh71x0: Use 32bit I/O on 32bit
  5. registers
  6. We currently use 64bit I/O on the 32bit registers. This works because
  7. there are an even number of assert and status registers, so they're only
  8. ever accessed in pairs on 64bit boundaries.
  9. There are however other reset controllers for audio and video on the
  10. JH7100 SoC with only one status register that isn't 64bit aligned so
  11. 64bit I/O results in an unaligned access exception.
  12. Switch to 32bit I/O in preparation for supporting these resets too.
  13. Tested-by: Tommaso Merciai <[email protected]>
  14. Reviewed-by: Conor Dooley <[email protected]>
  15. Reviewed-by: Emil Renner Berthing <[email protected]>
  16. Signed-off-by: Emil Renner Berthing <[email protected]>
  17. Signed-off-by: Hal Feng <[email protected]>
  18. Signed-off-by: Conor Dooley <[email protected]>
  19. ---
  20. .../reset/starfive/reset-starfive-jh7100.c | 14 ++++-----
  21. .../reset/starfive/reset-starfive-jh71x0.c | 31 +++++++++----------
  22. .../reset/starfive/reset-starfive-jh71x0.h | 2 +-
  23. 3 files changed, 23 insertions(+), 24 deletions(-)
  24. --- a/drivers/reset/starfive/reset-starfive-jh7100.c
  25. +++ b/drivers/reset/starfive/reset-starfive-jh7100.c
  26. @@ -30,16 +30,16 @@
  27. * lines don't though, so store the expected value of the status registers when
  28. * all lines are asserted.
  29. */
  30. -static const u64 jh7100_reset_asserted[2] = {
  31. +static const u32 jh7100_reset_asserted[4] = {
  32. /* STATUS0 */
  33. - BIT_ULL_MASK(JH7100_RST_U74) |
  34. - BIT_ULL_MASK(JH7100_RST_VP6_DRESET) |
  35. - BIT_ULL_MASK(JH7100_RST_VP6_BRESET) |
  36. + BIT(JH7100_RST_U74 % 32) |
  37. + BIT(JH7100_RST_VP6_DRESET % 32) |
  38. + BIT(JH7100_RST_VP6_BRESET % 32),
  39. /* STATUS1 */
  40. - BIT_ULL_MASK(JH7100_RST_HIFI4_DRESET) |
  41. - BIT_ULL_MASK(JH7100_RST_HIFI4_BRESET),
  42. + BIT(JH7100_RST_HIFI4_DRESET % 32) |
  43. + BIT(JH7100_RST_HIFI4_BRESET % 32),
  44. /* STATUS2 */
  45. - BIT_ULL_MASK(JH7100_RST_E24) |
  46. + BIT(JH7100_RST_E24 % 32),
  47. /* STATUS3 */
  48. 0,
  49. };
  50. --- a/drivers/reset/starfive/reset-starfive-jh71x0.c
  51. +++ b/drivers/reset/starfive/reset-starfive-jh71x0.c
  52. @@ -8,7 +8,6 @@
  53. #include <linux/bitmap.h>
  54. #include <linux/device.h>
  55. #include <linux/io.h>
  56. -#include <linux/io-64-nonatomic-lo-hi.h>
  57. #include <linux/iopoll.h>
  58. #include <linux/reset-controller.h>
  59. #include <linux/spinlock.h>
  60. @@ -21,7 +20,7 @@ struct jh71x0_reset {
  61. spinlock_t lock;
  62. void __iomem *assert;
  63. void __iomem *status;
  64. - const u64 *asserted;
  65. + const u32 *asserted;
  66. };
  67. static inline struct jh71x0_reset *
  68. @@ -34,12 +33,12 @@ static int jh71x0_reset_update(struct re
  69. unsigned long id, bool assert)
  70. {
  71. struct jh71x0_reset *data = jh71x0_reset_from(rcdev);
  72. - unsigned long offset = BIT_ULL_WORD(id);
  73. - u64 mask = BIT_ULL_MASK(id);
  74. - void __iomem *reg_assert = data->assert + offset * sizeof(u64);
  75. - void __iomem *reg_status = data->status + offset * sizeof(u64);
  76. - u64 done = data->asserted ? data->asserted[offset] & mask : 0;
  77. - u64 value;
  78. + unsigned long offset = id / 32;
  79. + u32 mask = BIT(id % 32);
  80. + void __iomem *reg_assert = data->assert + offset * sizeof(u32);
  81. + void __iomem *reg_status = data->status + offset * sizeof(u32);
  82. + u32 done = data->asserted ? data->asserted[offset] & mask : 0;
  83. + u32 value;
  84. unsigned long flags;
  85. int ret;
  86. @@ -48,15 +47,15 @@ static int jh71x0_reset_update(struct re
  87. spin_lock_irqsave(&data->lock, flags);
  88. - value = readq(reg_assert);
  89. + value = readl(reg_assert);
  90. if (assert)
  91. value |= mask;
  92. else
  93. value &= ~mask;
  94. - writeq(value, reg_assert);
  95. + writel(value, reg_assert);
  96. /* if the associated clock is gated, deasserting might otherwise hang forever */
  97. - ret = readq_poll_timeout_atomic(reg_status, value, (value & mask) == done, 0, 1000);
  98. + ret = readl_poll_timeout_atomic(reg_status, value, (value & mask) == done, 0, 1000);
  99. spin_unlock_irqrestore(&data->lock, flags);
  100. return ret;
  101. @@ -90,10 +89,10 @@ static int jh71x0_reset_status(struct re
  102. unsigned long id)
  103. {
  104. struct jh71x0_reset *data = jh71x0_reset_from(rcdev);
  105. - unsigned long offset = BIT_ULL_WORD(id);
  106. - u64 mask = BIT_ULL_MASK(id);
  107. - void __iomem *reg_status = data->status + offset * sizeof(u64);
  108. - u64 value = readq(reg_status);
  109. + unsigned long offset = id / 32;
  110. + u32 mask = BIT(id % 32);
  111. + void __iomem *reg_status = data->status + offset * sizeof(u32);
  112. + u32 value = readl(reg_status);
  113. return !((value ^ data->asserted[offset]) & mask);
  114. }
  115. @@ -107,7 +106,7 @@ static const struct reset_control_ops jh
  116. int reset_starfive_jh71x0_register(struct device *dev, struct device_node *of_node,
  117. void __iomem *assert, void __iomem *status,
  118. - const u64 *asserted, unsigned int nr_resets,
  119. + const u32 *asserted, unsigned int nr_resets,
  120. struct module *owner)
  121. {
  122. struct jh71x0_reset *data;
  123. --- a/drivers/reset/starfive/reset-starfive-jh71x0.h
  124. +++ b/drivers/reset/starfive/reset-starfive-jh71x0.h
  125. @@ -8,7 +8,7 @@
  126. int reset_starfive_jh71x0_register(struct device *dev, struct device_node *of_node,
  127. void __iomem *assert, void __iomem *status,
  128. - const u64 *asserted, unsigned int nr_resets,
  129. + const u32 *asserted, unsigned int nr_resets,
  130. struct module *owner);
  131. #endif /* __RESET_STARFIVE_JH71X0_H */