From: "Rob Herring (Arm)" <robh@kernel.org>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ASoC: PCM6240: Use of_property_read_reg()
Date: Tue, 2 Jul 2024 15:53:49 -0600 [thread overview]
Message-ID: <20240702215349.839350-1-robh@kernel.org> (raw)
Replace the open-coded parsing of "reg" with of_property_read_reg().
The #ifdef is also easily replaced with IS_ENABLED().
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
sound/soc/codecs/pcm6240.c | 31 ++++++++++---------------------
1 file changed, 10 insertions(+), 21 deletions(-)
diff --git a/sound/soc/codecs/pcm6240.c b/sound/soc/codecs/pcm6240.c
index 86e126783a1d..4a6019ee3d83 100644
--- a/sound/soc/codecs/pcm6240.c
+++ b/sound/soc/codecs/pcm6240.c
@@ -18,6 +18,7 @@
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/of_irq.h>
+#include <linux/of_address.h>
#include <linux/regmap.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
@@ -2081,10 +2082,6 @@ static int pcmdevice_i2c_probe(struct i2c_client *i2c)
struct device_node *np;
unsigned int dev_addrs[PCMDEVICE_MAX_I2C_DEVICES];
int ret = 0, i = 0, ndev = 0;
-#ifdef CONFIG_OF
- const __be32 *reg, *reg_end;
- int len, sw, aw;
-#endif
pcm_dev = devm_kzalloc(&i2c->dev, sizeof(*pcm_dev), GFP_KERNEL);
if (!pcm_dev) {
@@ -2120,27 +2117,19 @@ static int pcmdevice_i2c_probe(struct i2c_client *i2c)
i2c_set_clientdata(i2c, pcm_dev);
mutex_init(&pcm_dev->codec_lock);
np = pcm_dev->dev->of_node;
-#ifdef CONFIG_OF
- aw = of_n_addr_cells(np);
- sw = of_n_size_cells(np);
- if (sw == 0) {
- reg = (const __be32 *)of_get_property(np,
- "reg", &len);
- reg_end = reg + len/sizeof(*reg);
- ndev = 0;
- do {
- dev_addrs[ndev] = of_read_number(reg, aw);
- reg += aw;
- ndev++;
- } while (reg < reg_end);
+
+ if (IS_ENABLED(CONFIG_OF)) {
+ u64 addr;
+
+ for (i = 0; i < PCMDEVICE_MAX_I2C_DEVICES; i++) {
+ if (of_property_read_reg(np, i, &addr, NULL))
+ break;
+ dev_addrs[ndev++] = addr;
+ }
} else {
ndev = 1;
dev_addrs[0] = i2c->addr;
}
-#else
- ndev = 1;
- dev_addrs[0] = i2c->addr;
-#endif
pcm_dev->irq_info.gpio = of_irq_get(np, 0);
for (i = 0; i < ndev; i++)
--
2.43.0
next reply other threads:[~2024-07-02 21:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 21:53 Rob Herring (Arm) [this message]
2024-07-03 14:07 ` [PATCH] ASoC: PCM6240: Use of_property_read_reg() Mark Brown
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=20240702215349.839350-1-robh@kernel.org \
--to=robh@kernel.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox