Commit 47726656 authored by Sean Paul's avatar Sean Paul Committed by Lee Jones

backlight: lp855x: Refactor DT parsing code

This patch refactors the dt parsing code to avoid setting platform_data,
instead just setting lp->pdata directly. This facilitates easier
probe deferral since the current scheme would require us to clear out
dev->platform_data before deferring.

Cc: Stéphane Marchesin <marcheu@chromium.org>
Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
Acked-by: default avatarMilo Kim <milo.kim@ti.com>
Acked-by: default avatarBryan Wu <cooloney@gmail.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent edf387b6
...@@ -341,8 +341,10 @@ static const struct attribute_group lp855x_attr_group = { ...@@ -341,8 +341,10 @@ static const struct attribute_group lp855x_attr_group = {
}; };
#ifdef CONFIG_OF #ifdef CONFIG_OF
static int lp855x_parse_dt(struct device *dev, struct device_node *node) static int lp855x_parse_dt(struct lp855x *lp)
{ {
struct device *dev = lp->dev;
struct device_node *node = dev->of_node;
struct lp855x_platform_data *pdata; struct lp855x_platform_data *pdata;
int rom_length; int rom_length;
...@@ -381,12 +383,12 @@ static int lp855x_parse_dt(struct device *dev, struct device_node *node) ...@@ -381,12 +383,12 @@ static int lp855x_parse_dt(struct device *dev, struct device_node *node)
pdata->rom_data = &rom[0]; pdata->rom_data = &rom[0];
} }
dev->platform_data = pdata; lp->pdata = pdata;
return 0; return 0;
} }
#else #else
static int lp855x_parse_dt(struct device *dev, struct device_node *node) static int lp855x_parse_dt(struct lp855x *lp)
{ {
return -EINVAL; return -EINVAL;
} }
...@@ -395,18 +397,8 @@ static int lp855x_parse_dt(struct device *dev, struct device_node *node) ...@@ -395,18 +397,8 @@ static int lp855x_parse_dt(struct device *dev, struct device_node *node)
static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
{ {
struct lp855x *lp; struct lp855x *lp;
struct lp855x_platform_data *pdata = dev_get_platdata(&cl->dev);
struct device_node *node = cl->dev.of_node;
int ret; int ret;
if (!pdata) {
ret = lp855x_parse_dt(&cl->dev, node);
if (ret < 0)
return ret;
pdata = dev_get_platdata(&cl->dev);
}
if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
return -EIO; return -EIO;
...@@ -414,16 +406,23 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) ...@@ -414,16 +406,23 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
if (!lp) if (!lp)
return -ENOMEM; return -ENOMEM;
if (pdata->period_ns > 0)
lp->mode = PWM_BASED;
else
lp->mode = REGISTER_BASED;
lp->client = cl; lp->client = cl;
lp->dev = &cl->dev; lp->dev = &cl->dev;
lp->pdata = pdata;
lp->chipname = id->name; lp->chipname = id->name;
lp->chip_id = id->driver_data; lp->chip_id = id->driver_data;
lp->pdata = dev_get_platdata(&cl->dev);
if (!lp->pdata) {
ret = lp855x_parse_dt(lp);
if (ret < 0)
return ret;
}
if (lp->pdata->period_ns > 0)
lp->mode = PWM_BASED;
else
lp->mode = REGISTER_BASED;
i2c_set_clientdata(cl, lp); i2c_set_clientdata(cl, lp);
ret = lp855x_configure(lp); ret = lp855x_configure(lp);
......
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