diff mbox series

[v2,2/2] leds: bcm6358: improve write and read functions

Message ID 20210224101110.20179-3-noltari@gmail.com
State New
Headers show
Series leds: bcm63x8: improve read and write functions | expand

Commit Message

Álvaro Fernández Rojas Feb. 24, 2021, 10:11 a.m. UTC
This is proven to work in BMIPS BE/LE and ARM BE/LE, as used in bcm2835-rng
and bcmgenet drivers.
Both should also be inline functions.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 v2: Fix comment style.

 drivers/leds/leds-bcm6358.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

Comments

Florian Fainelli Feb. 24, 2021, 3:43 p.m. UTC | #1
On 2/24/2021 2:11 AM, Álvaro Fernández Rojas wrote:
> This is proven to work in BMIPS BE/LE and ARM BE/LE, as used in bcm2835-rng
> and bcmgenet drivers.
> Both should also be inline functions.
> 
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
diff mbox series

Patch

diff --git a/drivers/leds/leds-bcm6358.c b/drivers/leds/leds-bcm6358.c
index 9d2e487fa08a..37d27b7c58a8 100644
--- a/drivers/leds/leds-bcm6358.c
+++ b/drivers/leds/leds-bcm6358.c
@@ -43,22 +43,24 @@  struct bcm6358_led {
 	bool active_low;
 };
 
-static void bcm6358_led_write(void __iomem *reg, unsigned long data)
+static inline void bcm6358_led_write(void __iomem *reg, unsigned long data)
 {
-#ifdef CONFIG_CPU_BIG_ENDIAN
-	iowrite32be(data, reg);
-#else
-	writel(data, reg);
-#endif
+	/*
+	 * MIPS chips strapped for BE will automagically configure the
+	 * peripheral registers for CPU-native byte order.
+	 */
+	if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		__raw_writel(data, reg);
+	else
+		writel_relaxed(data, reg);
 }
 
-static unsigned long bcm6358_led_read(void __iomem *reg)
+static inline unsigned long bcm6358_led_read(void __iomem *reg)
 {
-#ifdef CONFIG_CPU_BIG_ENDIAN
-	return ioread32be(reg);
-#else
-	return readl(reg);
-#endif
+	if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		return __raw_readl(reg);
+	else
+		return readl_relaxed(reg);
 }
 
 static unsigned long bcm6358_led_busy(void __iomem *mem)