regulator: fan53555: change fan53555_parse_dt() to read only DT parameters

Currently, fan53555_parse_dt() does a platform data allocation in
addition to reading device tree parameters. Move the memory
allocation out of fan53555_parse_dt() and change it only to parse
device tree parameters to match its name. This helps to expand
the function to read other device tree parameters.

CRs-Fixed: 968575
Change-Id: Id876d54bede15c73a298a6bfa68af7097115e36b
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
This commit is contained in:
Subbaraman Narayanamurthy 2015-12-14 15:42:47 -08:00 committed by David Keitel
parent 3c3c947e71
commit 1138183d9b

View file

@ -302,26 +302,27 @@ static const struct regmap_config fan53555_regmap_config = {
.val_bits = 8, .val_bits = 8,
}; };
static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev, static int fan53555_parse_dt(struct fan53555_device_info *di,
struct device_node *np, struct fan53555_platform_data *pdata,
const struct regulator_desc *desc) const struct regulator_desc *desc)
{ {
struct fan53555_platform_data *pdata; struct device *dev = di->dev;
struct device_node *np = dev->of_node;
int ret; int ret;
u32 tmp; u32 tmp;
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return NULL;
pdata->regulator = of_get_regulator_init_data(dev, np, desc); pdata->regulator = of_get_regulator_init_data(dev, np, desc);
if (!pdata->regulator) {
dev_err(dev, "regulator init data is missing\n");
return -ENODEV;
}
ret = of_property_read_u32(np, "fcs,suspend-voltage-selector", ret = of_property_read_u32(np, "fcs,suspend-voltage-selector",
&tmp); &tmp);
if (!ret) if (!ret)
pdata->sleep_vsel_id = tmp; pdata->sleep_vsel_id = tmp;
return pdata; return ret;
} }
static const struct of_device_id fan53555_dt_ids[] = { static const struct of_device_id fan53555_dt_ids[] = {
@ -342,7 +343,6 @@ 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 = { };
@ -355,14 +355,17 @@ static int fan53555_regulator_probe(struct i2c_client *client,
return -ENOMEM; return -ENOMEM;
pdata = dev_get_platdata(&client->dev); pdata = dev_get_platdata(&client->dev);
if (!pdata) if (!pdata) {
pdata = fan53555_parse_dt(&client->dev, np, &di->desc); pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
if (!pdata || !pdata->regulator) { return -ENOMEM;
dev_err(&client->dev, "Platform data not found!\n");
return -ENODEV;
} }
di->dev = &client->dev;
ret = fan53555_parse_dt(di, pdata, &di->desc);
if (ret)
return ret;
di->regulator = pdata->regulator; di->regulator = pdata->regulator;
if (client->dev.of_node) { if (client->dev.of_node) {
const struct of_device_id *match; const struct of_device_id *match;
@ -391,7 +394,6 @@ static int fan53555_regulator_probe(struct i2c_client *client,
dev_err(&client->dev, "Failed to allocate regmap!\n"); dev_err(&client->dev, "Failed to allocate regmap!\n");
return PTR_ERR(di->regmap); return PTR_ERR(di->regmap);
} }
di->dev = &client->dev;
i2c_set_clientdata(client, di); i2c_set_clientdata(client, di);
/* Get chip ID */ /* Get chip ID */
ret = regmap_read(di->regmap, FAN53555_ID1, &val); ret = regmap_read(di->regmap, FAN53555_ID1, &val);
@ -420,7 +422,7 @@ 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; config.of_node = client->dev.of_node;
ret = fan53555_regulator_register(di, &config); ret = fan53555_regulator_register(di, &config);
if (ret < 0) if (ret < 0)