ASoC: tlv320aic32x4: add type to device private data struct
authorClaudius Heine <ch@denx.de>
Thu, 17 Jun 2021 08:52:28 +0000 (10:52 +0200)
committerMark Brown <broonie@kernel.org>
Wed, 23 Jun 2021 10:49:34 +0000 (11:49 +0100)
While this driver can already handle different device variants, the
variant information cannot be used in the driver code and therefor
cannot have different code paths depending on the device variant.

This change adds a `type` value into the `aic32x4_priv` structure, that
contains a device variant identifier, which was set when the driver was
bound to the device.

Signed-off-by: Claudius Heine <ch@denx.de>
Link: https://lore.kernel.org/r/20210617085230.1851503-2-ch@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/tlv320aic32x4-i2c.c
sound/soc/codecs/tlv320aic32x4-spi.c
sound/soc/codecs/tlv320aic32x4.c
sound/soc/codecs/tlv320aic32x4.h

index 6d54cbf70a0bf325719ac927457a5f32409da7ce..247fb1e136746d7190042c1900c8fbae3f589dcf 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "tlv320aic32x4.h"
 
+static const struct of_device_id aic32x4_of_id[];
+
 static int aic32x4_i2c_probe(struct i2c_client *i2c,
                             const struct i2c_device_id *id)
 {
@@ -27,6 +29,16 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c,
        config.val_bits = 8;
 
        regmap = devm_regmap_init_i2c(i2c, &config);
+
+       if (i2c->dev.of_node) {
+               const struct of_device_id *oid;
+
+               oid = of_match_node(aic32x4_of_id, i2c->dev.of_node);
+               dev_set_drvdata(&i2c->dev, (void *)oid->data);
+       } else if (id) {
+               dev_set_drvdata(&i2c->dev, (void *)id->driver_data);
+       }
+
        return aic32x4_probe(&i2c->dev, regmap);
 }
 
@@ -36,15 +48,15 @@ static int aic32x4_i2c_remove(struct i2c_client *i2c)
 }
 
 static const struct i2c_device_id aic32x4_i2c_id[] = {
-       { "tlv320aic32x4", 0 },
-       { "tlv320aic32x6", 1 },
+       { "tlv320aic32x4", (kernel_ulong_t)AIC32X4_TYPE_AIC32X4 },
+       { "tlv320aic32x6", (kernel_ulong_t)AIC32X4_TYPE_AIC32X6 },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(i2c, aic32x4_i2c_id);
 
 static const struct of_device_id aic32x4_of_id[] = {
-       { .compatible = "ti,tlv320aic32x4", },
-       { .compatible = "ti,tlv320aic32x6", },
+       { .compatible = "ti,tlv320aic32x4", .data = (void *)AIC32X4_TYPE_AIC32X4 },
+       { .compatible = "ti,tlv320aic32x6", .data = (void *)AIC32X4_TYPE_AIC32X6 },
        { /* senitel */ }
 };
 MODULE_DEVICE_TABLE(of, aic32x4_of_id);
index a22e7700bfc8aca6e2a9323947293aaa3712834e..e81c72958a82cc9107111b2d520320402821d827 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "tlv320aic32x4.h"
 
+static const struct of_device_id aic32x4_of_id[];
+
 static int aic32x4_spi_probe(struct spi_device *spi)
 {
        struct regmap *regmap;
@@ -28,6 +30,19 @@ static int aic32x4_spi_probe(struct spi_device *spi)
        config.read_flag_mask = 0x01;
 
        regmap = devm_regmap_init_spi(spi, &config);
+
+       if (spi->dev.of_node) {
+               const struct of_device_id *oid;
+
+               oid = of_match_node(aic32x4_of_id, spi->dev.of_node);
+               dev_set_drvdata(&spi->dev, (void *)oid->data);
+       } else {
+               const struct spi_device_id *id_entry;
+
+               id_entry = spi_get_device_id(spi);
+               dev_set_drvdata(&spi->dev, (void *)id_entry->driver_data);
+       }
+
        return aic32x4_probe(&spi->dev, regmap);
 }
 
@@ -37,15 +52,15 @@ static int aic32x4_spi_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id aic32x4_spi_id[] = {
-       { "tlv320aic32x4", 0 },
-       { "tlv320aic32x6", 1 },
+       { "tlv320aic32x4", (kernel_ulong_t)AIC32X4_TYPE_AIC32X4 },
+       { "tlv320aic32x6", (kernel_ulong_t)AIC32X4_TYPE_AIC32X6 },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(spi, aic32x4_spi_id);
 
 static const struct of_device_id aic32x4_of_id[] = {
-       { .compatible = "ti,tlv320aic32x4", },
-       { .compatible = "ti,tlv320aic32x6", },
+       { .compatible = "ti,tlv320aic32x4", .data = (void *)AIC32X4_TYPE_AIC32X4 },
+       { .compatible = "ti,tlv320aic32x6", .data = (void *)AIC32X4_TYPE_AIC32X6 },
        { /* senitel */ }
 };
 MODULE_DEVICE_TABLE(of, aic32x4_of_id);
index b689f26fc4be62da9232e320e220729a3cd8a18c..70a1574fb72ad9eb803d3b7d019842314a473d8d 100644 (file)
@@ -48,6 +48,7 @@ struct aic32x4_priv {
 
        struct aic32x4_setup_data *setup;
        struct device *dev;
+       enum aic32x4_type type;
 };
 
 static int aic32x4_reset_adc(struct snd_soc_dapm_widget *w,
@@ -1198,6 +1199,8 @@ int aic32x4_probe(struct device *dev, struct regmap *regmap)
                return -ENOMEM;
 
        aic32x4->dev = dev;
+       aic32x4->type = (enum aic32x4_type)dev_get_drvdata(dev);
+
        dev_set_drvdata(dev, aic32x4);
 
        if (pdata) {
index 7550122e9f8a978f12d1728eb4b3086955e5532e..8a18dbec76a6e6b92512d590c4f98dee906c6ddb 100644 (file)
 struct device;
 struct regmap_config;
 
+enum aic32x4_type {
+       AIC32X4_TYPE_AIC32X4 = 0,
+       AIC32X4_TYPE_AIC32X6,
+};
+
 extern const struct regmap_config aic32x4_regmap_config;
 int aic32x4_probe(struct device *dev, struct regmap *regmap);
 int aic32x4_remove(struct device *dev);