Re: [PATCH v1 1/5] ASoC: codec: adau1977-i2c: Add OF device match table

From: Shawn Guo

Date: Wed Sep 09 2026 - 12:57:22 EST


On Mon, Sep 07, 2026 at 11:39:42PM +0530, Mohammad Rafi Shaik wrote:
> The ADAU1977 I2C driver lacks an OF device match table, preventing
> it from binding to codec instances described via Device Tree. Systems
> using compatible strings such as "adi,adau1977", "adi,adau1978", or
> "adi,adau1979" fail to probe the driver as a result.

This justification isn't accurate -- DT instances do bind today. The I2C
core matches DT clients by stripping the vendor prefix from the first
compatible and comparing the result against the driver's id_table:

of_i2c_get_board_info() drivers/i2c/i2c-core-of.c
of_alias_from_compatible() -> client->name = "adau1979"
i2c_device_match() drivers/i2c/i2c-core-base.c
i2c_match_id(driver->id_table, client) -> matches

So "adi,adau1979" already probes without this patch, and the patch as
written doesn't fix a probe failure.

What it does fix -- and what I think the changelog should say -- is
module autoloading. For any client with an of_node, the bus emits the
OF modalias, not the I2C one:

static int i2c_device_uevent(...)
{
rc = of_device_uevent_modalias(dev, env);
if (rc != -ENODEV)
return rc;
...
return add_uevent_var(env, "MODALIAS=%s%s", I2C_MODULE_PREFIX,
client->name);
}

The kernel therefore advertises "of:N...Cadi,adau1979", which no module
claims without MODULE_DEVICE_TABLE(of, ...). With SND_SOC_ADAU1977_I2C=m
the codec module never gets loaded and the card stays in -EPROBE_DEFER
with nothing in the log pointing at the cause.

>
> Add a descriptive prompt string for SND_SOC_ADAU1977_I2C/SPI so
> the driver is visible and selectable when running menuconfig.

This should probably be a separate change?

>
> Signed-off-by: Mohammad Rafi Shaik <mohammad.rafi.shaik@xxxxxxxxxxxxxxxx>
> ---
> sound/soc/codecs/Kconfig | 4 ++--
> sound/soc/codecs/adau1977-i2c.c | 9 +++++++++
> 2 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
> index d3730c4da51b..6f481a54313f 100644
> --- a/sound/soc/codecs/Kconfig
> +++ b/sound/soc/codecs/Kconfig
> @@ -526,13 +526,13 @@ config SND_SOC_ADAU1977
> tristate
>
> config SND_SOC_ADAU1977_SPI
> - tristate
> + tristate "Analog Devices ADAU1977 CODEC - SPI"
> depends on SPI_MASTER
> select SND_SOC_ADAU1977
> select REGMAP_SPI
>
> config SND_SOC_ADAU1977_I2C
> - tristate
> + tristate "Analog Devices ADAU1977 CODEC - I2C"
> depends on I2C
> select SND_SOC_ADAU1977
> select REGMAP_I2C
> diff --git a/sound/soc/codecs/adau1977-i2c.c b/sound/soc/codecs/adau1977-i2c.c
> index d1c6c4ddf506..9f54fa8375b1 100644
> --- a/sound/soc/codecs/adau1977-i2c.c
> +++ b/sound/soc/codecs/adau1977-i2c.c
> @@ -34,9 +34,18 @@ static const struct i2c_device_id adau1977_i2c_ids[] = {
> };
> MODULE_DEVICE_TABLE(i2c, adau1977_i2c_ids);
>
> +static const struct of_device_id adau1977_i2c_of_match[] __maybe_unused = {
> + { .compatible = "adi,adau1977" },
> + { .compatible = "adi,adau1978" },
> + { .compatible = "adi,adau1979" },
> + { },
> +};
> +MODULE_DEVICE_TABLE(of, adau1977_i2c_of_match);

Worth noting for whoever touches this next: the variant is still resolved
via i2c_get_match_data()'s fallback to id_table, since ADAU1977 == 0
can't be expressed through .data. That's fine as-is, but it means
adau1977_i2c_ids[] is now load-bearing in a way that isn't obvious --
removing it as "redundant" would silently make every compatible probe as
ADAU1977.

> +
> static struct i2c_driver adau1977_i2c_driver = {
> .driver = {
> .name = "adau1977",
> + .of_match_table = of_match_ptr(adau1977_i2c_of_match),

Drop of_match_ptr() and the __maybe_unused. Upstream has been removing
of_match_ptr() from drivers for years.

Shawn

> },
> .probe = adau1977_i2c_probe,
> .id_table = adau1977_i2c_ids,
>
> --
> 2.34.1
>
>