diff options
Diffstat (limited to 'drivers/power/tps65090-charger.c')
-rw-r--r-- | drivers/power/tps65090-charger.c | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/drivers/power/tps65090-charger.c b/drivers/power/tps65090-charger.c index 9fbca310a2ad..bdd7b9b2546a 100644 --- a/drivers/power/tps65090-charger.c +++ b/drivers/power/tps65090-charger.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/mfd/tps65090.h> | 27 | #include <linux/mfd/tps65090.h> |
28 | 28 | ||
29 | #define TPS65090_REG_INTR_STS 0x00 | 29 | #define TPS65090_REG_INTR_STS 0x00 |
30 | #define TPS65090_REG_INTR_MASK 0x02 | ||
30 | #define TPS65090_REG_CG_CTRL0 0x04 | 31 | #define TPS65090_REG_CG_CTRL0 0x04 |
31 | #define TPS65090_REG_CG_CTRL1 0x05 | 32 | #define TPS65090_REG_CG_CTRL1 0x05 |
32 | #define TPS65090_REG_CG_CTRL2 0x06 | 33 | #define TPS65090_REG_CG_CTRL2 0x06 |
@@ -67,8 +68,7 @@ static int tps65090_low_chrg_current(struct tps65090_charger *charger) | |||
67 | return 0; | 68 | return 0; |
68 | } | 69 | } |
69 | 70 | ||
70 | static int tps65090_enable_charging(struct tps65090_charger *charger, | 71 | static int tps65090_enable_charging(struct tps65090_charger *charger) |
71 | uint8_t enable) | ||
72 | { | 72 | { |
73 | int ret; | 73 | int ret; |
74 | uint8_t ctrl0 = 0; | 74 | uint8_t ctrl0 = 0; |
@@ -84,7 +84,7 @@ static int tps65090_enable_charging(struct tps65090_charger *charger, | |||
84 | ret = tps65090_write(charger->dev->parent, TPS65090_REG_CG_CTRL0, | 84 | ret = tps65090_write(charger->dev->parent, TPS65090_REG_CG_CTRL0, |
85 | (ctrl0 | TPS65090_CHARGER_ENABLE)); | 85 | (ctrl0 | TPS65090_CHARGER_ENABLE)); |
86 | if (ret < 0) { | 86 | if (ret < 0) { |
87 | dev_err(charger->dev, "%s(): error reading in register 0x%x\n", | 87 | dev_err(charger->dev, "%s(): error writing in register 0x%x\n", |
88 | __func__, TPS65090_REG_CG_CTRL0); | 88 | __func__, TPS65090_REG_CG_CTRL0); |
89 | return ret; | 89 | return ret; |
90 | } | 90 | } |
@@ -93,6 +93,7 @@ static int tps65090_enable_charging(struct tps65090_charger *charger, | |||
93 | 93 | ||
94 | static int tps65090_config_charger(struct tps65090_charger *charger) | 94 | static int tps65090_config_charger(struct tps65090_charger *charger) |
95 | { | 95 | { |
96 | uint8_t intrmask = 0; | ||
96 | int ret; | 97 | int ret; |
97 | 98 | ||
98 | if (charger->pdata->enable_low_current_chrg) { | 99 | if (charger->pdata->enable_low_current_chrg) { |
@@ -104,6 +105,23 @@ static int tps65090_config_charger(struct tps65090_charger *charger) | |||
104 | } | 105 | } |
105 | } | 106 | } |
106 | 107 | ||
108 | /* Enable the VACG interrupt for AC power detect */ | ||
109 | ret = tps65090_read(charger->dev->parent, TPS65090_REG_INTR_MASK, | ||
110 | &intrmask); | ||
111 | if (ret < 0) { | ||
112 | dev_err(charger->dev, "%s(): error reading in register 0x%x\n", | ||
113 | __func__, TPS65090_REG_INTR_MASK); | ||
114 | return ret; | ||
115 | } | ||
116 | |||
117 | ret = tps65090_write(charger->dev->parent, TPS65090_REG_INTR_MASK, | ||
118 | (intrmask | TPS65090_VACG)); | ||
119 | if (ret < 0) { | ||
120 | dev_err(charger->dev, "%s(): error writing in register 0x%x\n", | ||
121 | __func__, TPS65090_REG_CG_CTRL0); | ||
122 | return ret; | ||
123 | } | ||
124 | |||
107 | return 0; | 125 | return 0; |
108 | } | 126 | } |
109 | 127 | ||
@@ -146,7 +164,7 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id) | |||
146 | } | 164 | } |
147 | 165 | ||
148 | if (intrsts & TPS65090_VACG) { | 166 | if (intrsts & TPS65090_VACG) { |
149 | ret = tps65090_enable_charging(charger, 1); | 167 | ret = tps65090_enable_charging(charger); |
150 | if (ret < 0) | 168 | if (ret < 0) |
151 | return IRQ_HANDLED; | 169 | return IRQ_HANDLED; |
152 | charger->ac_online = 1; | 170 | charger->ac_online = 1; |
@@ -154,6 +172,13 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id) | |||
154 | charger->ac_online = 0; | 172 | charger->ac_online = 0; |
155 | } | 173 | } |
156 | 174 | ||
175 | /* Clear interrupts. */ | ||
176 | ret = tps65090_write(charger->dev->parent, TPS65090_REG_INTR_STS, 0x00); | ||
177 | if (ret < 0) { | ||
178 | dev_err(charger->dev, "%s(): Error in writing reg 0x%x\n", | ||
179 | __func__, TPS65090_REG_INTR_STS); | ||
180 | } | ||
181 | |||
157 | if (charger->prev_ac_online != charger->ac_online) | 182 | if (charger->prev_ac_online != charger->ac_online) |
158 | power_supply_changed(&charger->ac); | 183 | power_supply_changed(&charger->ac); |
159 | 184 | ||
@@ -218,7 +243,7 @@ static int tps65090_charger_probe(struct platform_device *pdev) | |||
218 | return -ENOMEM; | 243 | return -ENOMEM; |
219 | } | 244 | } |
220 | 245 | ||
221 | dev_set_drvdata(&pdev->dev, cdata); | 246 | platform_set_drvdata(pdev, cdata); |
222 | 247 | ||
223 | cdata->dev = &pdev->dev; | 248 | cdata->dev = &pdev->dev; |
224 | cdata->pdata = pdata; | 249 | cdata->pdata = pdata; |
@@ -230,6 +255,7 @@ static int tps65090_charger_probe(struct platform_device *pdev) | |||
230 | cdata->ac.num_properties = ARRAY_SIZE(tps65090_ac_props); | 255 | cdata->ac.num_properties = ARRAY_SIZE(tps65090_ac_props); |
231 | cdata->ac.supplied_to = pdata->supplied_to; | 256 | cdata->ac.supplied_to = pdata->supplied_to; |
232 | cdata->ac.num_supplicants = pdata->num_supplicants; | 257 | cdata->ac.num_supplicants = pdata->num_supplicants; |
258 | cdata->ac.of_node = pdev->dev.of_node; | ||
233 | 259 | ||
234 | ret = power_supply_register(&pdev->dev, &cdata->ac); | 260 | ret = power_supply_register(&pdev->dev, &cdata->ac); |
235 | if (ret) { | 261 | if (ret) { |
@@ -270,7 +296,7 @@ static int tps65090_charger_probe(struct platform_device *pdev) | |||
270 | } | 296 | } |
271 | 297 | ||
272 | if (status1 != 0) { | 298 | if (status1 != 0) { |
273 | ret = tps65090_enable_charging(cdata, 1); | 299 | ret = tps65090_enable_charging(cdata); |
274 | if (ret < 0) { | 300 | if (ret < 0) { |
275 | dev_err(cdata->dev, "error enabling charger\n"); | 301 | dev_err(cdata->dev, "error enabling charger\n"); |
276 | goto fail_free_irq; | 302 | goto fail_free_irq; |
@@ -291,7 +317,7 @@ fail_unregister_supply: | |||
291 | 317 | ||
292 | static int tps65090_charger_remove(struct platform_device *pdev) | 318 | static int tps65090_charger_remove(struct platform_device *pdev) |
293 | { | 319 | { |
294 | struct tps65090_charger *cdata = dev_get_drvdata(&pdev->dev); | 320 | struct tps65090_charger *cdata = platform_get_drvdata(pdev); |
295 | 321 | ||
296 | devm_free_irq(cdata->dev, cdata->irq, cdata); | 322 | devm_free_irq(cdata->dev, cdata->irq, cdata); |
297 | power_supply_unregister(&cdata->ac); | 323 | power_supply_unregister(&cdata->ac); |