diff options
Diffstat (limited to 'drivers/power/max8903_charger.c')
-rw-r--r-- | drivers/power/max8903_charger.c | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/drivers/power/max8903_charger.c b/drivers/power/max8903_charger.c index 2f769faa85f6..bf2b4b3a7cae 100644 --- a/drivers/power/max8903_charger.c +++ b/drivers/power/max8903_charger.c | |||
@@ -31,7 +31,8 @@ | |||
31 | struct max8903_data { | 31 | struct max8903_data { |
32 | struct max8903_pdata pdata; | 32 | struct max8903_pdata pdata; |
33 | struct device *dev; | 33 | struct device *dev; |
34 | struct power_supply psy; | 34 | struct power_supply *psy; |
35 | struct power_supply_desc psy_desc; | ||
35 | bool fault; | 36 | bool fault; |
36 | bool usb_in; | 37 | bool usb_in; |
37 | bool ta_in; | 38 | bool ta_in; |
@@ -47,8 +48,7 @@ static int max8903_get_property(struct power_supply *psy, | |||
47 | enum power_supply_property psp, | 48 | enum power_supply_property psp, |
48 | union power_supply_propval *val) | 49 | union power_supply_propval *val) |
49 | { | 50 | { |
50 | struct max8903_data *data = container_of(psy, | 51 | struct max8903_data *data = power_supply_get_drvdata(psy); |
51 | struct max8903_data, psy); | ||
52 | 52 | ||
53 | switch (psp) { | 53 | switch (psp) { |
54 | case POWER_SUPPLY_PROP_STATUS: | 54 | case POWER_SUPPLY_PROP_STATUS: |
@@ -104,17 +104,17 @@ static irqreturn_t max8903_dcin(int irq, void *_data) | |||
104 | dev_dbg(data->dev, "TA(DC-IN) Charger %s.\n", ta_in ? | 104 | dev_dbg(data->dev, "TA(DC-IN) Charger %s.\n", ta_in ? |
105 | "Connected" : "Disconnected"); | 105 | "Connected" : "Disconnected"); |
106 | 106 | ||
107 | old_type = data->psy.type; | 107 | old_type = data->psy_desc.type; |
108 | 108 | ||
109 | if (data->ta_in) | 109 | if (data->ta_in) |
110 | data->psy.type = POWER_SUPPLY_TYPE_MAINS; | 110 | data->psy_desc.type = POWER_SUPPLY_TYPE_MAINS; |
111 | else if (data->usb_in) | 111 | else if (data->usb_in) |
112 | data->psy.type = POWER_SUPPLY_TYPE_USB; | 112 | data->psy_desc.type = POWER_SUPPLY_TYPE_USB; |
113 | else | 113 | else |
114 | data->psy.type = POWER_SUPPLY_TYPE_BATTERY; | 114 | data->psy_desc.type = POWER_SUPPLY_TYPE_BATTERY; |
115 | 115 | ||
116 | if (old_type != data->psy.type) | 116 | if (old_type != data->psy_desc.type) |
117 | power_supply_changed(&data->psy); | 117 | power_supply_changed(data->psy); |
118 | 118 | ||
119 | return IRQ_HANDLED; | 119 | return IRQ_HANDLED; |
120 | } | 120 | } |
@@ -143,17 +143,17 @@ static irqreturn_t max8903_usbin(int irq, void *_data) | |||
143 | dev_dbg(data->dev, "USB Charger %s.\n", usb_in ? | 143 | dev_dbg(data->dev, "USB Charger %s.\n", usb_in ? |
144 | "Connected" : "Disconnected"); | 144 | "Connected" : "Disconnected"); |
145 | 145 | ||
146 | old_type = data->psy.type; | 146 | old_type = data->psy_desc.type; |
147 | 147 | ||
148 | if (data->ta_in) | 148 | if (data->ta_in) |
149 | data->psy.type = POWER_SUPPLY_TYPE_MAINS; | 149 | data->psy_desc.type = POWER_SUPPLY_TYPE_MAINS; |
150 | else if (data->usb_in) | 150 | else if (data->usb_in) |
151 | data->psy.type = POWER_SUPPLY_TYPE_USB; | 151 | data->psy_desc.type = POWER_SUPPLY_TYPE_USB; |
152 | else | 152 | else |
153 | data->psy.type = POWER_SUPPLY_TYPE_BATTERY; | 153 | data->psy_desc.type = POWER_SUPPLY_TYPE_BATTERY; |
154 | 154 | ||
155 | if (old_type != data->psy.type) | 155 | if (old_type != data->psy_desc.type) |
156 | power_supply_changed(&data->psy); | 156 | power_supply_changed(data->psy); |
157 | 157 | ||
158 | return IRQ_HANDLED; | 158 | return IRQ_HANDLED; |
159 | } | 159 | } |
@@ -184,6 +184,7 @@ static int max8903_probe(struct platform_device *pdev) | |||
184 | struct max8903_data *data; | 184 | struct max8903_data *data; |
185 | struct device *dev = &pdev->dev; | 185 | struct device *dev = &pdev->dev; |
186 | struct max8903_pdata *pdata = pdev->dev.platform_data; | 186 | struct max8903_pdata *pdata = pdev->dev.platform_data; |
187 | struct power_supply_config psy_cfg = {}; | ||
187 | int ret = 0; | 188 | int ret = 0; |
188 | int gpio; | 189 | int gpio; |
189 | int ta_in = 0; | 190 | int ta_in = 0; |
@@ -280,17 +281,20 @@ static int max8903_probe(struct platform_device *pdev) | |||
280 | data->ta_in = ta_in; | 281 | data->ta_in = ta_in; |
281 | data->usb_in = usb_in; | 282 | data->usb_in = usb_in; |
282 | 283 | ||
283 | data->psy.name = "max8903_charger"; | 284 | data->psy_desc.name = "max8903_charger"; |
284 | data->psy.type = (ta_in) ? POWER_SUPPLY_TYPE_MAINS : | 285 | data->psy_desc.type = (ta_in) ? POWER_SUPPLY_TYPE_MAINS : |
285 | ((usb_in) ? POWER_SUPPLY_TYPE_USB : | 286 | ((usb_in) ? POWER_SUPPLY_TYPE_USB : |
286 | POWER_SUPPLY_TYPE_BATTERY); | 287 | POWER_SUPPLY_TYPE_BATTERY); |
287 | data->psy.get_property = max8903_get_property; | 288 | data->psy_desc.get_property = max8903_get_property; |
288 | data->psy.properties = max8903_charger_props; | 289 | data->psy_desc.properties = max8903_charger_props; |
289 | data->psy.num_properties = ARRAY_SIZE(max8903_charger_props); | 290 | data->psy_desc.num_properties = ARRAY_SIZE(max8903_charger_props); |
290 | 291 | ||
291 | ret = power_supply_register(dev, &data->psy, NULL); | 292 | psy_cfg.drv_data = data; |
292 | if (ret) { | 293 | |
294 | data->psy = power_supply_register(dev, &data->psy_desc, &psy_cfg); | ||
295 | if (IS_ERR(data->psy)) { | ||
293 | dev_err(dev, "failed: power supply register.\n"); | 296 | dev_err(dev, "failed: power supply register.\n"); |
297 | ret = PTR_ERR(data->psy); | ||
294 | goto err; | 298 | goto err; |
295 | } | 299 | } |
296 | 300 | ||
@@ -339,7 +343,7 @@ err_dc_irq: | |||
339 | if (pdata->dc_valid) | 343 | if (pdata->dc_valid) |
340 | free_irq(gpio_to_irq(pdata->dok), data); | 344 | free_irq(gpio_to_irq(pdata->dok), data); |
341 | err_psy: | 345 | err_psy: |
342 | power_supply_unregister(&data->psy); | 346 | power_supply_unregister(data->psy); |
343 | err: | 347 | err: |
344 | return ret; | 348 | return ret; |
345 | } | 349 | } |
@@ -357,7 +361,7 @@ static int max8903_remove(struct platform_device *pdev) | |||
357 | free_irq(gpio_to_irq(pdata->uok), data); | 361 | free_irq(gpio_to_irq(pdata->uok), data); |
358 | if (pdata->dc_valid) | 362 | if (pdata->dc_valid) |
359 | free_irq(gpio_to_irq(pdata->dok), data); | 363 | free_irq(gpio_to_irq(pdata->dok), data); |
360 | power_supply_unregister(&data->psy); | 364 | power_supply_unregister(data->psy); |
361 | } | 365 | } |
362 | 366 | ||
363 | return 0; | 367 | return 0; |