summaryrefslogtreecommitdiff
path: root/drivers/mfd/wm831x-i2c.c
diff options
context:
space:
mode:
authorCharles Keepax <ckeepax@opensource.wolfsonmicro.com>2017-03-17 13:05:18 +0300
committerLee Jones <lee.jones@linaro.org>2017-03-23 14:45:50 +0300
commitf6dd8449cd50de25881b76cecf1086bebeb11fe8 (patch)
treefa757139b73dc9a8e79e46952d93db19dd5e8068 /drivers/mfd/wm831x-i2c.c
parentc1ae3cfa0e89fa1a7ecc4c99031f5e9ae99d9201 (diff)
downloadlinux-f6dd8449cd50de25881b76cecf1086bebeb11fe8.tar.xz
mfd: wm831x: Add basic device tree binding
Add the basic ability to register the device through device tree, more work is needed to get each individual sub-driver functioning correctly but this is enough to get the device to probe from device tree. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd/wm831x-i2c.c')
-rw-r--r--drivers/mfd/wm831x-i2c.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c
index 824bcbaa9624..781af060f32d 100644
--- a/drivers/mfd/wm831x-i2c.c
+++ b/drivers/mfd/wm831x-i2c.c
@@ -19,6 +19,8 @@
#include <linux/mfd/core.h>
#include <linux/slab.h>
#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/regmap.h>
#include <linux/mfd/wm831x/core.h>
@@ -27,15 +29,26 @@
static int wm831x_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
+ struct wm831x_pdata *pdata = dev_get_platdata(&i2c->dev);
+ const struct of_device_id *of_id;
struct wm831x *wm831x;
+ enum wm831x_parent type;
int ret;
+ if (i2c->dev.of_node) {
+ of_id = of_match_device(wm831x_of_match, &i2c->dev);
+ type = (enum wm831x_parent)of_id->data;
+ } else {
+ type = (enum wm831x_parent)id->driver_data;
+ }
+
wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL);
if (wm831x == NULL)
return -ENOMEM;
i2c_set_clientdata(i2c, wm831x);
wm831x->dev = &i2c->dev;
+ wm831x->type = type;
wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config);
if (IS_ERR(wm831x->regmap)) {
@@ -45,7 +58,10 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
return ret;
}
- return wm831x_device_init(wm831x, id->driver_data, i2c->irq);
+ if (pdata)
+ memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
+
+ return wm831x_device_init(wm831x, i2c->irq);
}
static int wm831x_i2c_remove(struct i2c_client *i2c)
@@ -94,6 +110,7 @@ static struct i2c_driver wm831x_i2c_driver = {
.driver = {
.name = "wm831x",
.pm = &wm831x_pm_ops,
+ .of_match_table = of_match_ptr(wm831x_of_match),
},
.probe = wm831x_i2c_probe,
.remove = wm831x_i2c_remove,