aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/gpio-charger.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/gpio-charger.c')
-rw-r--r--drivers/power/gpio-charger.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/drivers/power/gpio-charger.c b/drivers/power/gpio-charger.c
index 47a9e2bd94d9..c5869b1941ac 100644
--- a/drivers/power/gpio-charger.c
+++ b/drivers/power/gpio-charger.c
@@ -32,7 +32,8 @@ struct gpio_charger {
32 unsigned int irq; 32 unsigned int irq;
33 bool wakeup_enabled; 33 bool wakeup_enabled;
34 34
35 struct power_supply charger; 35 struct power_supply *charger;
36 struct power_supply_desc charger_desc;
36}; 37};
37 38
38static irqreturn_t gpio_charger_irq(int irq, void *devid) 39static irqreturn_t gpio_charger_irq(int irq, void *devid)
@@ -46,7 +47,7 @@ static irqreturn_t gpio_charger_irq(int irq, void *devid)
46 47
47static inline struct gpio_charger *psy_to_gpio_charger(struct power_supply *psy) 48static inline struct gpio_charger *psy_to_gpio_charger(struct power_supply *psy)
48{ 49{
49 return container_of(psy, struct gpio_charger, charger); 50 return power_supply_get_drvdata(psy);
50} 51}
51 52
52static int gpio_charger_get_property(struct power_supply *psy, 53static int gpio_charger_get_property(struct power_supply *psy,
@@ -129,7 +130,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
129 const struct gpio_charger_platform_data *pdata = pdev->dev.platform_data; 130 const struct gpio_charger_platform_data *pdata = pdev->dev.platform_data;
130 struct power_supply_config psy_cfg = {}; 131 struct power_supply_config psy_cfg = {};
131 struct gpio_charger *gpio_charger; 132 struct gpio_charger *gpio_charger;
132 struct power_supply *charger; 133 struct power_supply_desc *charger_desc;
133 int ret; 134 int ret;
134 int irq; 135 int irq;
135 136
@@ -155,17 +156,18 @@ static int gpio_charger_probe(struct platform_device *pdev)
155 return -ENOMEM; 156 return -ENOMEM;
156 } 157 }
157 158
158 charger = &gpio_charger->charger; 159 charger_desc = &gpio_charger->charger_desc;
159 160
160 charger->name = pdata->name ? pdata->name : "gpio-charger"; 161 charger_desc->name = pdata->name ? pdata->name : "gpio-charger";
161 charger->type = pdata->type; 162 charger_desc->type = pdata->type;
162 charger->properties = gpio_charger_properties; 163 charger_desc->properties = gpio_charger_properties;
163 charger->num_properties = ARRAY_SIZE(gpio_charger_properties); 164 charger_desc->num_properties = ARRAY_SIZE(gpio_charger_properties);
164 charger->get_property = gpio_charger_get_property; 165 charger_desc->get_property = gpio_charger_get_property;
165 166
166 psy_cfg.supplied_to = pdata->supplied_to; 167 psy_cfg.supplied_to = pdata->supplied_to;
167 psy_cfg.num_supplicants = pdata->num_supplicants; 168 psy_cfg.num_supplicants = pdata->num_supplicants;
168 psy_cfg.of_node = pdev->dev.of_node; 169 psy_cfg.of_node = pdev->dev.of_node;
170 psy_cfg.drv_data = gpio_charger;
169 171
170 ret = gpio_request(pdata->gpio, dev_name(&pdev->dev)); 172 ret = gpio_request(pdata->gpio, dev_name(&pdev->dev));
171 if (ret) { 173 if (ret) {
@@ -180,8 +182,10 @@ static int gpio_charger_probe(struct platform_device *pdev)
180 182
181 gpio_charger->pdata = pdata; 183 gpio_charger->pdata = pdata;
182 184
183 ret = power_supply_register(&pdev->dev, charger, &psy_cfg); 185 gpio_charger->charger = power_supply_register(&pdev->dev,
184 if (ret < 0) { 186 charger_desc, &psy_cfg);
187 if (IS_ERR(gpio_charger->charger)) {
188 ret = PTR_ERR(gpio_charger->charger);
185 dev_err(&pdev->dev, "Failed to register power supply: %d\n", 189 dev_err(&pdev->dev, "Failed to register power supply: %d\n",
186 ret); 190 ret);
187 goto err_gpio_free; 191 goto err_gpio_free;
@@ -191,7 +195,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
191 if (irq > 0) { 195 if (irq > 0) {
192 ret = request_any_context_irq(irq, gpio_charger_irq, 196 ret = request_any_context_irq(irq, gpio_charger_irq,
193 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 197 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
194 dev_name(&pdev->dev), charger); 198 dev_name(&pdev->dev), gpio_charger->charger);
195 if (ret < 0) 199 if (ret < 0)
196 dev_warn(&pdev->dev, "Failed to request irq: %d\n", ret); 200 dev_warn(&pdev->dev, "Failed to request irq: %d\n", ret);
197 else 201 else
@@ -215,9 +219,9 @@ static int gpio_charger_remove(struct platform_device *pdev)
215 struct gpio_charger *gpio_charger = platform_get_drvdata(pdev); 219 struct gpio_charger *gpio_charger = platform_get_drvdata(pdev);
216 220
217 if (gpio_charger->irq) 221 if (gpio_charger->irq)
218 free_irq(gpio_charger->irq, &gpio_charger->charger); 222 free_irq(gpio_charger->irq, gpio_charger->charger);
219 223
220 power_supply_unregister(&gpio_charger->charger); 224 power_supply_unregister(gpio_charger->charger);
221 225
222 gpio_free(gpio_charger->pdata->gpio); 226 gpio_free(gpio_charger->pdata->gpio);
223 227
@@ -243,7 +247,7 @@ static int gpio_charger_resume(struct device *dev)
243 247
244 if (device_may_wakeup(dev) && gpio_charger->wakeup_enabled) 248 if (device_may_wakeup(dev) && gpio_charger->wakeup_enabled)
245 disable_irq_wake(gpio_charger->irq); 249 disable_irq_wake(gpio_charger->irq);
246 power_supply_changed(&gpio_charger->charger); 250 power_supply_changed(gpio_charger->charger);
247 251
248 return 0; 252 return 0;
249} 253}