regulator: fan53555: add devicetree support
Add the ability to parse regulator-data from the devicetree. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
ed801b4046
commit
91f23d8fb6
|
@ -18,6 +18,8 @@
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/regulator/driver.h>
|
#include <linux/regulator/driver.h>
|
||||||
#include <linux/regulator/machine.h>
|
#include <linux/regulator/machine.h>
|
||||||
|
#include <linux/regulator/of_regulator.h>
|
||||||
|
#include <linux/of_device.h>
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
|
@ -252,9 +254,39 @@ static struct regmap_config fan53555_regmap_config = {
|
||||||
.val_bits = 8,
|
.val_bits = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
|
||||||
|
struct device_node *np)
|
||||||
|
{
|
||||||
|
struct fan53555_platform_data *pdata;
|
||||||
|
int ret;
|
||||||
|
u32 tmp;
|
||||||
|
|
||||||
|
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
|
||||||
|
if (!pdata)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
pdata->regulator = of_get_regulator_init_data(dev, np);
|
||||||
|
|
||||||
|
ret = of_property_read_u32(np, "fcs,suspend-voltage-selector",
|
||||||
|
&tmp);
|
||||||
|
if (!ret)
|
||||||
|
pdata->sleep_vsel_id = tmp;
|
||||||
|
|
||||||
|
return pdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct of_device_id fan53555_dt_ids[] = {
|
||||||
|
{
|
||||||
|
.compatible = "fcs,fan53555",
|
||||||
|
},
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(of, fan53555_dt_ids);
|
||||||
|
|
||||||
static int fan53555_regulator_probe(struct i2c_client *client,
|
static int fan53555_regulator_probe(struct i2c_client *client,
|
||||||
const struct i2c_device_id *id)
|
const struct i2c_device_id *id)
|
||||||
{
|
{
|
||||||
|
struct device_node *np = client->dev.of_node;
|
||||||
struct fan53555_device_info *di;
|
struct fan53555_device_info *di;
|
||||||
struct fan53555_platform_data *pdata;
|
struct fan53555_platform_data *pdata;
|
||||||
struct regulator_config config = { };
|
struct regulator_config config = { };
|
||||||
|
@ -262,6 +294,9 @@ static int fan53555_regulator_probe(struct i2c_client *client,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pdata = dev_get_platdata(&client->dev);
|
pdata = dev_get_platdata(&client->dev);
|
||||||
|
if (!pdata)
|
||||||
|
pdata = fan53555_parse_dt(&client->dev, np);
|
||||||
|
|
||||||
if (!pdata || !pdata->regulator) {
|
if (!pdata || !pdata->regulator) {
|
||||||
dev_err(&client->dev, "Platform data not found!\n");
|
dev_err(&client->dev, "Platform data not found!\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
@ -272,11 +307,15 @@ static int fan53555_regulator_probe(struct i2c_client *client,
|
||||||
if (!di)
|
if (!di)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (!client->dev.of_node) {
|
||||||
/* if no ramp constraint set, get the pdata ramp_delay */
|
/* if no ramp constraint set, get the pdata ramp_delay */
|
||||||
if (!di->regulator->constraints.ramp_delay) {
|
if (!di->regulator->constraints.ramp_delay) {
|
||||||
int slew_idx = (pdata->slew_rate & 0x7) ? pdata->slew_rate : 0;
|
int slew_idx = (pdata->slew_rate & 0x7)
|
||||||
|
? pdata->slew_rate : 0;
|
||||||
|
|
||||||
di->regulator->constraints.ramp_delay = slew_rates[slew_idx];
|
di->regulator->constraints.ramp_delay
|
||||||
|
= slew_rates[slew_idx];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
|
di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
|
||||||
|
@ -314,6 +353,8 @@ static int fan53555_regulator_probe(struct i2c_client *client,
|
||||||
config.init_data = di->regulator;
|
config.init_data = di->regulator;
|
||||||
config.regmap = di->regmap;
|
config.regmap = di->regmap;
|
||||||
config.driver_data = di;
|
config.driver_data = di;
|
||||||
|
config.of_node = np;
|
||||||
|
|
||||||
ret = fan53555_regulator_register(di, &config);
|
ret = fan53555_regulator_register(di, &config);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
dev_err(&client->dev, "Failed to register regulator!\n");
|
dev_err(&client->dev, "Failed to register regulator!\n");
|
||||||
|
@ -329,6 +370,7 @@ static const struct i2c_device_id fan53555_id[] = {
|
||||||
static struct i2c_driver fan53555_regulator_driver = {
|
static struct i2c_driver fan53555_regulator_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "fan53555-regulator",
|
.name = "fan53555-regulator",
|
||||||
|
.of_match_table = of_match_ptr(fan53555_dt_ids),
|
||||||
},
|
},
|
||||||
.probe = fan53555_regulator_probe,
|
.probe = fan53555_regulator_probe,
|
||||||
.id_table = fan53555_id,
|
.id_table = fan53555_id,
|
||||||
|
|
Loading…
Reference in New Issue