Commit e5afc867 authored by Peter Bergin's avatar Peter Bergin Committed by Mark Brown

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: default avatarPeter Bergin <peter@berginkonsult.se>
Acked-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20221031203723.168177-1-peter@berginkonsult.seSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent f8fbf0dc
...@@ -12,15 +12,30 @@ ...@@ -12,15 +12,30 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <sound/soc.h> #include <sound/soc.h>
#include "cs42xx8.h" #include "cs42xx8.h"
static const struct of_device_id cs42xx8_of_match[];
static int cs42xx8_i2c_probe(struct i2c_client *i2c) static int cs42xx8_i2c_probe(struct i2c_client *i2c)
{ {
int ret = cs42xx8_probe(&i2c->dev, int ret;
devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config)); struct cs42xx8_driver_data *drvdata;
const struct of_device_id *of_id;
of_id = of_match_device(cs42xx8_of_match, &i2c->dev);
if (!of_id) {
dev_err(&i2c->dev, "failed to find driver data\n");
return -EINVAL;
}
drvdata = (struct cs42xx8_driver_data *)of_id->data;
ret = cs42xx8_probe(&i2c->dev,
devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config), drvdata);
if (ret) if (ret)
return ret; return ret;
...@@ -35,7 +50,14 @@ static void cs42xx8_i2c_remove(struct i2c_client *i2c) ...@@ -35,7 +50,14 @@ static void cs42xx8_i2c_remove(struct i2c_client *i2c)
pm_runtime_disable(&i2c->dev); pm_runtime_disable(&i2c->dev);
} }
static struct i2c_device_id cs42xx8_i2c_id[] = { static const struct of_device_id cs42xx8_of_match[] = {
{ .compatible = "cirrus,cs42448", .data = &cs42448_data, },
{ .compatible = "cirrus,cs42888", .data = &cs42888_data, },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
static const struct i2c_device_id cs42xx8_i2c_id[] = {
{"cs42448", (kernel_ulong_t)&cs42448_data}, {"cs42448", (kernel_ulong_t)&cs42448_data},
{"cs42888", (kernel_ulong_t)&cs42888_data}, {"cs42888", (kernel_ulong_t)&cs42888_data},
{} {}
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
...@@ -511,17 +510,8 @@ const struct cs42xx8_driver_data cs42888_data = { ...@@ -511,17 +510,8 @@ const struct cs42xx8_driver_data cs42888_data = {
}; };
EXPORT_SYMBOL_GPL(cs42888_data); EXPORT_SYMBOL_GPL(cs42888_data);
const struct of_device_id cs42xx8_of_match[] = { int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driver_data *drvdata)
{ .compatible = "cirrus,cs42448", .data = &cs42448_data, },
{ .compatible = "cirrus,cs42888", .data = &cs42888_data, },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
EXPORT_SYMBOL_GPL(cs42xx8_of_match);
int cs42xx8_probe(struct device *dev, struct regmap *regmap)
{ {
const struct of_device_id *of_id;
struct cs42xx8_priv *cs42xx8; struct cs42xx8_priv *cs42xx8;
int ret, val, i; int ret, val, i;
...@@ -535,17 +525,11 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap) ...@@ -535,17 +525,11 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap)
if (cs42xx8 == NULL) if (cs42xx8 == NULL)
return -ENOMEM; return -ENOMEM;
cs42xx8->regmap = regmap;
dev_set_drvdata(dev, cs42xx8); dev_set_drvdata(dev, cs42xx8);
of_id = of_match_device(cs42xx8_of_match, dev); cs42xx8->regmap = regmap;
if (of_id)
cs42xx8->drvdata = of_id->data;
if (!cs42xx8->drvdata) { cs42xx8->drvdata = drvdata;
dev_err(dev, "failed to find driver data\n");
return -EINVAL;
}
cs42xx8->gpiod_reset = devm_gpiod_get_optional(dev, "reset", cs42xx8->gpiod_reset = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_HIGH); GPIOD_OUT_HIGH);
......
...@@ -22,8 +22,7 @@ extern const struct dev_pm_ops cs42xx8_pm; ...@@ -22,8 +22,7 @@ extern const struct dev_pm_ops cs42xx8_pm;
extern const struct cs42xx8_driver_data cs42448_data; extern const struct cs42xx8_driver_data cs42448_data;
extern const struct cs42xx8_driver_data cs42888_data; extern const struct cs42xx8_driver_data cs42888_data;
extern const struct regmap_config cs42xx8_regmap_config; extern const struct regmap_config cs42xx8_regmap_config;
extern const struct of_device_id cs42xx8_of_match[]; int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driver_data *drvdata);
int cs42xx8_probe(struct device *dev, struct regmap *regmap);
/* CS42888 register map */ /* CS42888 register map */
#define CS42XX8_CHIPID 0x01 /* Chip ID */ #define CS42XX8_CHIPID 0x01 /* Chip ID */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment