All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Álvaro Fernández Rojas" <noltari@gmail.com>
To: f.fainelli@gmail.com, Pavel Machek <pavel@ucw.cz>,
	Dan Murphy <dmurphy@ti.com>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Álvaro Fernández Rojas" <noltari@gmail.com>
Subject: [PATCH 1/2] leds: bcm6328: improve write and read functions
Date: Tue, 23 Feb 2021 09:17:31 +0100	[thread overview]
Message-ID: <20210223081732.9362-2-noltari@gmail.com> (raw)
In-Reply-To: <20210223081732.9362-1-noltari@gmail.com>

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>
---
 drivers/leds/leds-bcm6328.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/leds/leds-bcm6328.c b/drivers/leds/leds-bcm6328.c
index 226d17d253ed..112c9c858432 100644
--- a/drivers/leds/leds-bcm6328.c
+++ b/drivers/leds/leds-bcm6328.c
@@ -75,22 +75,23 @@ struct bcm6328_led {
 	bool active_low;
 };
 
-static void bcm6328_led_write(void __iomem *reg, unsigned long data)
+static inline void bcm6328_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 bcm6328_led_read(void __iomem *reg)
+static inline unsigned long bcm6328_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);
 }
 
 /**
-- 
2.20.1


  reply	other threads:[~2021-02-23  8:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-23  8:17 [PATCH 0/2] leds: bcm63x8: improve read and write functions Álvaro Fernández Rojas
2021-02-23  8:17 ` Álvaro Fernández Rojas [this message]
2021-02-23  8:34   ` [PATCH 1/2] leds: bcm6328: improve write and read functions Pavel Machek
2021-02-23  8:42     ` Álvaro Fernández Rojas
2021-02-23  8:58       ` Pavel Machek
2021-02-23  9:05         ` Álvaro Fernández Rojas
2021-02-23 17:00           ` Florian Fainelli
2021-02-24 17:36             ` Pavel Machek
2021-02-24 17:45               ` Florian Fainelli
2021-02-24 21:45                 ` Pavel Machek
2021-02-23  8:17 ` [PATCH 2/2] leds: bcm6358: " Álvaro Fernández Rojas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210223081732.9362-2-noltari@gmail.com \
    --to=noltari@gmail.com \
    --cc=dmurphy@ti.com \
    --cc=f.fainelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.