diff mbox series

[4/4] ASoC: wm8940: Read chip ID when wm8940 codec probing

Message ID 20221214123743.3713843-5-lukma@denx.de (mailing list archive)
State New, archived
Headers show
Series ASoC: Fixes for WM8940 codec | expand

Commit Message

Lukasz Majewski Dec. 14, 2022, 12:37 p.m. UTC
The wm8940 provides the chip ID information via I2C. In this
patch this information is read and if not matching expected
value, the probe function is aborted.

This prevents from using (i.e. inserting) other wm89* modules
which use the sam I2C bus address.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
---
 sound/soc/codecs/wm8940.c | 11 +++++++++++
 sound/soc/codecs/wm8940.h |  3 +++
 2 files changed, 14 insertions(+)

Comments

Charles Keepax Dec. 14, 2022, 1:10 p.m. UTC | #1
On Wed, Dec 14, 2022 at 01:37:43PM +0100, Lukasz Majewski wrote:
> The wm8940 provides the chip ID information via I2C. In this
> patch this information is read and if not matching expected
> value, the probe function is aborted.
> 
> This prevents from using (i.e. inserting) other wm89* modules
> which use the sam I2C bus address.
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>
> ---

Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Thanks,
Charles
diff mbox series

Patch

diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index 13cb57210b4b..244998ebab4d 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -769,6 +769,17 @@  static int wm8940_probe(struct snd_soc_component *component)
 	int ret;
 	u16 reg;
 
+	/*
+	 * Check chip ID for wm8940 - value of 0x00 offset
+	 * SOFTWARE_RESET on write
+	 * CHIP_ID on read
+	 */
+	reg = snd_soc_component_read(component, WM8940_SOFTRESET);
+	if (reg != WM8940_CHIP_ID) {
+		dev_err(component->dev, "Wrong wm8940 chip ID: 0x%x\n", reg);
+		return -ENODEV;
+	}
+
 	ret = wm8940_reset(component);
 	if (ret < 0) {
 		dev_err(component->dev, "Failed to issue reset\n");
diff --git a/sound/soc/codecs/wm8940.h b/sound/soc/codecs/wm8940.h
index eb051ed29bb8..8fbddcaa7449 100644
--- a/sound/soc/codecs/wm8940.h
+++ b/sound/soc/codecs/wm8940.h
@@ -98,5 +98,8 @@  struct wm8940_setup_data {
 /* Bit definitions */
 #define WM8940_SPKMUTE BIT(6)
 
+/* Chip ID */
+#define WM8940_CHIP_ID 0x8940
+
 #endif /* _WM8940_H */