summaryrefslogtreecommitdiffstats
path: root/drivers/extcon/extcon-axp288.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/extcon/extcon-axp288.c')
-rw-r--r--drivers/extcon/extcon-axp288.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 1621f2f7f129..0a44d43802fe 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;
@@ -183,8 +205,8 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
183 cable = EXTCON_CHG_USB_DCP; 205 cable = EXTCON_CHG_USB_DCP;
184 break; 206 break;
185 default: 207 default:
186 dev_warn(info->dev, 208 dev_warn(info->dev, "unknown (reserved) bc detect result\n");
187 "disconnect or unknown or ID event\n"); 209 cable = EXTCON_CHG_USB_SDP;
188 } 210 }
189 211
190no_vbus: 212no_vbus:
@@ -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}