Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: cs42xx8-i2c.c: add module device table for of

When trying to connect the device with the driver through
device-tree it is not working. The of_device_id is defined in
cs42xx8.c but is not correctly included in cs42xx8-i2c.c.

Move of_device_id table to cs42xx8-i2c.c. Get cs42xx8_driver_data
in cs42xx8_i2c_probe() and pass as argument to cs42xx8_probe(). Move
error check if no driver data found to cs42xx8_i2c_probe().

Signed-off-by: Peter Bergin <peter@berginkonsult.se>
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20221031203723.168177-1-peter@berginkonsult.se
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Peter Bergin and committed by
Mark Brown
e5afc867 f8fbf0dc

+29 -24
+25 -3
sound/soc/codecs/cs42xx8-i2c.c
··· 12 12 13 13 #include <linux/i2c.h> 14 14 #include <linux/module.h> 15 + #include <linux/of_device.h> 15 16 #include <linux/pm_runtime.h> 16 17 #include <sound/soc.h> 17 18 18 19 #include "cs42xx8.h" 19 20 21 + static const struct of_device_id cs42xx8_of_match[]; 22 + 20 23 static int cs42xx8_i2c_probe(struct i2c_client *i2c) 21 24 { 22 - int ret = cs42xx8_probe(&i2c->dev, 23 - devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config)); 25 + int ret; 26 + struct cs42xx8_driver_data *drvdata; 27 + const struct of_device_id *of_id; 28 + 29 + of_id = of_match_device(cs42xx8_of_match, &i2c->dev); 30 + if (!of_id) { 31 + dev_err(&i2c->dev, "failed to find driver data\n"); 32 + return -EINVAL; 33 + } 34 + 35 + drvdata = (struct cs42xx8_driver_data *)of_id->data; 36 + 37 + ret = cs42xx8_probe(&i2c->dev, 38 + devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config), drvdata); 24 39 if (ret) 25 40 return ret; 26 41 ··· 50 35 pm_runtime_disable(&i2c->dev); 51 36 } 52 37 53 - static struct i2c_device_id cs42xx8_i2c_id[] = { 38 + static const struct of_device_id cs42xx8_of_match[] = { 39 + { .compatible = "cirrus,cs42448", .data = &cs42448_data, }, 40 + { .compatible = "cirrus,cs42888", .data = &cs42888_data, }, 41 + { /* sentinel */ } 42 + }; 43 + MODULE_DEVICE_TABLE(of, cs42xx8_of_match); 44 + 45 + static const struct i2c_device_id cs42xx8_i2c_id[] = { 54 46 {"cs42448", (kernel_ulong_t)&cs42448_data}, 55 47 {"cs42888", (kernel_ulong_t)&cs42888_data}, 56 48 {}
+3 -19
sound/soc/codecs/cs42xx8.c
··· 13 13 #include <linux/clk.h> 14 14 #include <linux/delay.h> 15 15 #include <linux/module.h> 16 - #include <linux/of_device.h> 17 16 #include <linux/gpio/consumer.h> 18 17 #include <linux/pm_runtime.h> 19 18 #include <linux/regulator/consumer.h> ··· 510 511 }; 511 512 EXPORT_SYMBOL_GPL(cs42888_data); 512 513 513 - const struct of_device_id cs42xx8_of_match[] = { 514 - { .compatible = "cirrus,cs42448", .data = &cs42448_data, }, 515 - { .compatible = "cirrus,cs42888", .data = &cs42888_data, }, 516 - { /* sentinel */ } 517 - }; 518 - MODULE_DEVICE_TABLE(of, cs42xx8_of_match); 519 - EXPORT_SYMBOL_GPL(cs42xx8_of_match); 520 - 521 - int cs42xx8_probe(struct device *dev, struct regmap *regmap) 514 + int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driver_data *drvdata) 522 515 { 523 - const struct of_device_id *of_id; 524 516 struct cs42xx8_priv *cs42xx8; 525 517 int ret, val, i; 526 518 ··· 525 535 if (cs42xx8 == NULL) 526 536 return -ENOMEM; 527 537 528 - cs42xx8->regmap = regmap; 529 538 dev_set_drvdata(dev, cs42xx8); 530 539 531 - of_id = of_match_device(cs42xx8_of_match, dev); 532 - if (of_id) 533 - cs42xx8->drvdata = of_id->data; 540 + cs42xx8->regmap = regmap; 534 541 535 - if (!cs42xx8->drvdata) { 536 - dev_err(dev, "failed to find driver data\n"); 537 - return -EINVAL; 538 - } 542 + cs42xx8->drvdata = drvdata; 539 543 540 544 cs42xx8->gpiod_reset = devm_gpiod_get_optional(dev, "reset", 541 545 GPIOD_OUT_HIGH);
+1 -2
sound/soc/codecs/cs42xx8.h
··· 22 22 extern const struct cs42xx8_driver_data cs42448_data; 23 23 extern const struct cs42xx8_driver_data cs42888_data; 24 24 extern const struct regmap_config cs42xx8_regmap_config; 25 - extern const struct of_device_id cs42xx8_of_match[]; 26 - int cs42xx8_probe(struct device *dev, struct regmap *regmap); 25 + int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driver_data *drvdata); 27 26 28 27 /* CS42888 register map */ 29 28 #define CS42XX8_CHIPID 0x01 /* Chip ID */