Commit 87d931d5 authored by Milo Kim's avatar Milo Kim Committed by Sebastian Reichel

power:lp8727_charger: use the private data instead of updating I2C device platform data

Currently, lp8727 charger driver parses the DT and copies values into the
'cl->dev.platform_data' if 'of_node' exists.
This may have architectural issue. Platform data is configurable through
the DT or I2C board info inside the platform area.
However, lp8727 driver changes this configuration when it is loaded.

The driver should get data from the platform side and use the private
data, 'lp8727_chg->pdata' instead of changing the original platform data.

_probe() procedure is changed as follows.
  1. lp8727_parse_dt() returns the pointer of lp8727_platform_data.
     The driver uses this allocated platform data. So it should keep
     original platform data, 'dev->platform_data'.
  2. In _probe(), check the return value of lp8727_parse_dt().
     If an error is found, then exit as PTR_ERR(pdata).
  3. If 'of_node' is not found, then the driver just gets the platform data
     from the I2C device structure.
  4. Map the platform data to private data structure.

Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarMilo Kim <milo.kim@ti.com>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent c01576c8
...@@ -508,7 +508,7 @@ static struct lp8727_chg_param ...@@ -508,7 +508,7 @@ static struct lp8727_chg_param
return param; return param;
} }
static int lp8727_parse_dt(struct device *dev) static struct lp8727_platform_data *lp8727_parse_dt(struct device *dev)
{ {
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct device_node *child; struct device_node *child;
...@@ -517,11 +517,11 @@ static int lp8727_parse_dt(struct device *dev) ...@@ -517,11 +517,11 @@ static int lp8727_parse_dt(struct device *dev)
/* If charging parameter is not defined, just skip parsing the dt */ /* If charging parameter is not defined, just skip parsing the dt */
if (of_get_child_count(np) == 0) if (of_get_child_count(np) == 0)
goto out; return NULL;
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) if (!pdata)
return -ENOMEM; return ERR_PTR(-ENOMEM);
of_property_read_u32(np, "debounce-ms", &pdata->debounce_msec); of_property_read_u32(np, "debounce-ms", &pdata->debounce_msec);
...@@ -535,29 +535,30 @@ static int lp8727_parse_dt(struct device *dev) ...@@ -535,29 +535,30 @@ static int lp8727_parse_dt(struct device *dev)
pdata->usb = lp8727_parse_charge_pdata(dev, child); pdata->usb = lp8727_parse_charge_pdata(dev, child);
} }
dev->platform_data = pdata; return pdata;
out:
return 0;
} }
#else #else
static int lp8727_parse_dt(struct device *dev) static struct lp8727_platform_data *lp8727_parse_dt(struct device *dev)
{ {
return 0; return NULL;
} }
#endif #endif
static int lp8727_probe(struct i2c_client *cl, const struct i2c_device_id *id) static int lp8727_probe(struct i2c_client *cl, const struct i2c_device_id *id)
{ {
struct lp8727_chg *pchg; struct lp8727_chg *pchg;
struct lp8727_platform_data *pdata;
int ret; int ret;
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;
if (cl->dev.of_node) { if (cl->dev.of_node) {
ret = lp8727_parse_dt(&cl->dev); pdata = lp8727_parse_dt(&cl->dev);
if (ret) if (IS_ERR(pdata))
return ret; return PTR_ERR(pdata);
} else {
pdata = dev_get_platdata(&cl->dev);
} }
pchg = devm_kzalloc(&cl->dev, sizeof(*pchg), GFP_KERNEL); pchg = devm_kzalloc(&cl->dev, sizeof(*pchg), GFP_KERNEL);
...@@ -566,7 +567,7 @@ static int lp8727_probe(struct i2c_client *cl, const struct i2c_device_id *id) ...@@ -566,7 +567,7 @@ static int lp8727_probe(struct i2c_client *cl, const struct i2c_device_id *id)
pchg->client = cl; pchg->client = cl;
pchg->dev = &cl->dev; pchg->dev = &cl->dev;
pchg->pdata = cl->dev.platform_data; pchg->pdata = pdata;
i2c_set_clientdata(cl, pchg); i2c_set_clientdata(cl, pchg);
mutex_init(&pchg->xfer_lock); mutex_init(&pchg->xfer_lock);
......
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