2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-10-20 05:57:56 +08:00
|
|
|
/*
|
|
|
|
* wm831x-i2c.c -- I2C access for Wolfson WM831x PMICs
|
|
|
|
*
|
|
|
|
* Copyright 2009,2010 Wolfson Microelectronics PLC.
|
|
|
|
*
|
|
|
|
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2019-01-14 02:36:45 +08:00
|
|
|
#include <linux/init.h>
|
2010-10-20 05:57:56 +08:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/mfd/core.h>
|
|
|
|
#include <linux/slab.h>
|
2011-06-11 02:28:10 +08:00
|
|
|
#include <linux/err.h>
|
2017-03-17 18:05:18 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2011-06-11 02:28:10 +08:00
|
|
|
#include <linux/regmap.h>
|
2010-10-20 05:57:56 +08:00
|
|
|
|
|
|
|
#include <linux/mfd/wm831x/core.h>
|
|
|
|
#include <linux/mfd/wm831x/pdata.h>
|
|
|
|
|
2022-11-19 06:43:32 +08:00
|
|
|
static int wm831x_i2c_probe(struct i2c_client *i2c)
|
2010-10-20 05:57:56 +08:00
|
|
|
{
|
2022-11-19 06:43:32 +08:00
|
|
|
const struct i2c_device_id *id = i2c_client_get_device_id(i2c);
|
2017-03-17 18:05:18 +08:00
|
|
|
struct wm831x_pdata *pdata = dev_get_platdata(&i2c->dev);
|
|
|
|
const struct of_device_id *of_id;
|
2010-10-20 05:57:56 +08:00
|
|
|
struct wm831x *wm831x;
|
2017-03-17 18:05:18 +08:00
|
|
|
enum wm831x_parent type;
|
2011-06-11 02:28:10 +08:00
|
|
|
int ret;
|
2010-10-20 05:57:56 +08:00
|
|
|
|
2017-03-17 18:05:18 +08:00
|
|
|
if (i2c->dev.of_node) {
|
|
|
|
of_id = of_match_device(wm831x_of_match, &i2c->dev);
|
2017-05-24 17:26:23 +08:00
|
|
|
if (!of_id) {
|
|
|
|
dev_err(&i2c->dev, "Failed to match device\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2023-08-10 17:58:48 +08:00
|
|
|
type = (uintptr_t)of_id->data;
|
2017-03-17 18:05:18 +08:00
|
|
|
} else {
|
|
|
|
type = (enum wm831x_parent)id->driver_data;
|
|
|
|
}
|
|
|
|
|
2011-10-25 20:47:40 +08:00
|
|
|
wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL);
|
2010-10-20 05:57:56 +08:00
|
|
|
if (wm831x == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
i2c_set_clientdata(i2c, wm831x);
|
|
|
|
wm831x->dev = &i2c->dev;
|
2017-03-17 18:05:18 +08:00
|
|
|
wm831x->type = type;
|
2011-06-11 02:28:10 +08:00
|
|
|
|
2012-01-31 04:08:06 +08:00
|
|
|
wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config);
|
2011-06-11 02:28:10 +08:00
|
|
|
if (IS_ERR(wm831x->regmap)) {
|
|
|
|
ret = PTR_ERR(wm831x->regmap);
|
|
|
|
dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-10-20 05:57:56 +08:00
|
|
|
|
2017-03-17 18:05:18 +08:00
|
|
|
if (pdata)
|
|
|
|
memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
|
|
|
|
|
|
|
|
return wm831x_device_init(wm831x, i2c->irq);
|
2010-10-20 05:57:56 +08:00
|
|
|
}
|
|
|
|
|
2011-01-05 23:12:39 +08:00
|
|
|
static int wm831x_i2c_suspend(struct device *dev)
|
2010-10-20 05:57:56 +08:00
|
|
|
{
|
2011-01-05 23:12:39 +08:00
|
|
|
struct wm831x *wm831x = dev_get_drvdata(dev);
|
2010-10-20 05:57:56 +08:00
|
|
|
|
|
|
|
return wm831x_device_suspend(wm831x);
|
|
|
|
}
|
|
|
|
|
2013-11-09 02:51:25 +08:00
|
|
|
static int wm831x_i2c_poweroff(struct device *dev)
|
2011-09-16 00:54:53 +08:00
|
|
|
{
|
2013-11-09 02:51:25 +08:00
|
|
|
struct wm831x *wm831x = dev_get_drvdata(dev);
|
2011-09-16 00:54:53 +08:00
|
|
|
|
|
|
|
wm831x_device_shutdown(wm831x);
|
2013-11-09 02:51:25 +08:00
|
|
|
|
|
|
|
return 0;
|
2011-09-16 00:54:53 +08:00
|
|
|
}
|
|
|
|
|
2010-10-20 05:57:56 +08:00
|
|
|
static const struct i2c_device_id wm831x_i2c_id[] = {
|
|
|
|
{ "wm8310", WM8310 },
|
|
|
|
{ "wm8311", WM8311 },
|
|
|
|
{ "wm8312", WM8312 },
|
|
|
|
{ "wm8320", WM8320 },
|
|
|
|
{ "wm8321", WM8321 },
|
|
|
|
{ "wm8325", WM8325 },
|
2010-11-25 02:01:41 +08:00
|
|
|
{ "wm8326", WM8326 },
|
2010-10-20 05:57:56 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2011-01-05 23:12:39 +08:00
|
|
|
static const struct dev_pm_ops wm831x_pm_ops = {
|
|
|
|
.suspend = wm831x_i2c_suspend,
|
2013-11-09 02:51:25 +08:00
|
|
|
.poweroff = wm831x_i2c_poweroff,
|
2011-01-05 23:12:39 +08:00
|
|
|
};
|
2010-10-20 05:57:56 +08:00
|
|
|
|
|
|
|
static struct i2c_driver wm831x_i2c_driver = {
|
|
|
|
.driver = {
|
2011-01-05 23:12:39 +08:00
|
|
|
.name = "wm831x",
|
|
|
|
.pm = &wm831x_pm_ops,
|
2017-03-17 18:05:18 +08:00
|
|
|
.of_match_table = of_match_ptr(wm831x_of_match),
|
2019-01-14 02:36:45 +08:00
|
|
|
.suppress_bind_attrs = true,
|
2010-10-20 05:57:56 +08:00
|
|
|
},
|
2023-05-16 02:27:52 +08:00
|
|
|
.probe = wm831x_i2c_probe,
|
2010-10-20 05:57:56 +08:00
|
|
|
.id_table = wm831x_i2c_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init wm831x_i2c_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = i2c_add_driver(&wm831x_i2c_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register wm831x I2C driver: %d\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
subsys_initcall(wm831x_i2c_init);
|