summaryrefslogtreecommitdiffstats
path: root/drivers/extcon/extcon-axp288.c
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2017-12-22 07:36:15 -0500
committerChanwoo Choi <cw00.choi@samsung.com>2018-01-02 20:12:57 -0500
commit60ed99961469a3683b52d09bc0771053fb484ae0 (patch)
treec123edb959f9310f9c017e018b0974a6a8864bca /drivers/extcon/extcon-axp288.c
parentd61b814ab958cdd119eac76e9aa3455b908c51cd (diff)
extcon: axp288: Redo charger type detection a couple of seconds after probe()
The axp288 extcon code depends on other drivers to do things like mux the data lines, enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has not set these things up correctly resulting in the initial charger cable type detection giving a wrong result and we end up not charging or charging at only 0.5A. This commit starts a second charger-detection cycle a couple of seconds after the first one finishes, giving the other drivers time to load and do their thing. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Diffstat (limited to 'drivers/extcon/extcon-axp288.c')
-rw-r--r--drivers/extcon/extcon-axp288.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 1621f2f7f129..74d5be0b1f35 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver 2 * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
3 * 3 *
4 * Copyright (C) 2016-2017 Hans de Goede <hdegoede@redhat.com>
4 * Copyright (C) 2015 Intel Corporation 5 * Copyright (C) 2015 Intel Corporation
5 * Author: Ramakrishna Pallala <ramakrishna.pallala@intel.com> 6 * Author: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
6 * 7 *
@@ -97,9 +98,11 @@ struct axp288_extcon_info {
97 struct device *dev; 98 struct device *dev;
98 struct regmap *regmap; 99 struct regmap *regmap;
99 struct regmap_irq_chip_data *regmap_irqc; 100 struct regmap_irq_chip_data *regmap_irqc;
101 struct delayed_work det_work;
100 int irq[EXTCON_IRQ_END]; 102 int irq[EXTCON_IRQ_END];
101 struct extcon_dev *edev; 103 struct extcon_dev *edev;
102 unsigned int previous_cable; 104 unsigned int previous_cable;
105 bool first_detect_done;
103}; 106};
104 107
105/* Power up/down reason string array */ 108/* Power up/down reason string array */
@@ -137,6 +140,25 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
137 regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask); 140 regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
138} 141}
139 142
143static void axp288_chrg_detect_complete(struct axp288_extcon_info *info)
144{
145 /*
146 * We depend on other drivers to do things like mux the data lines,
147 * enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has
148 * not set these things up correctly resulting in the initial charger
149 * cable type detection giving a wrong result and we end up not charging
150 * or charging at only 0.5A.
151 *
152 * So we schedule a second cable type detection after 2 seconds to
153 * give the other drivers time to load and do their thing.
154 */
155 if (!info->first_detect_done) {
156 queue_delayed_work(system_wq, &info->det_work,
157 msecs_to_jiffies(2000));
158 info->first_detect_done = true;
159 }
160}
161
140static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) 162static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
141{ 163{
142 int ret, stat, cfg, pwr_stat; 164 int ret, stat, cfg, pwr_stat;
@@ -201,6 +223,8 @@ no_vbus:
201 info->previous_cable = cable; 223 info->previous_cable = cable;
202 } 224 }
203 225
226 axp288_chrg_detect_complete(info);
227
204 return 0; 228 return 0;
205 229
206dev_det_ret: 230dev_det_ret:
@@ -222,8 +246,11 @@ static irqreturn_t axp288_extcon_isr(int irq, void *data)
222 return IRQ_HANDLED; 246 return IRQ_HANDLED;
223} 247}
224 248
225static void axp288_extcon_enable(struct axp288_extcon_info *info) 249static void axp288_extcon_det_work(struct work_struct *work)
226{ 250{
251 struct axp288_extcon_info *info =
252 container_of(work, struct axp288_extcon_info, det_work.work);
253
227 regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG, 254 regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG,
228 BC_GLOBAL_RUN, 0); 255 BC_GLOBAL_RUN, 0);
229 /* Enable the charger detection logic */ 256 /* Enable the charger detection logic */
@@ -245,6 +272,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
245 info->regmap = axp20x->regmap; 272 info->regmap = axp20x->regmap;
246 info->regmap_irqc = axp20x->regmap_irqc; 273 info->regmap_irqc = axp20x->regmap_irqc;
247 info->previous_cable = EXTCON_NONE; 274 info->previous_cable = EXTCON_NONE;
275 INIT_DELAYED_WORK(&info->det_work, axp288_extcon_det_work);
248 276
249 platform_set_drvdata(pdev, info); 277 platform_set_drvdata(pdev, info);
250 278
@@ -290,7 +318,7 @@ static int axp288_extcon_probe(struct platform_device *pdev)
290 } 318 }
291 319
292 /* Start charger cable type detection */ 320 /* Start charger cable type detection */
293 axp288_extcon_enable(info); 321 queue_delayed_work(system_wq, &info->det_work, 0);
294 322
295 return 0; 323 return 0;
296} 324}