summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/power_supply_extcon.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/power/power_supply_extcon.c b/drivers/power/power_supply_extcon.c
index 5d5cb1a9efd6..eda9c69014d6 100644
--- a/drivers/power/power_supply_extcon.c
+++ b/drivers/power/power_supply_extcon.c
@@ -30,6 +30,7 @@
#include <linux/power/power_supply_extcon.h>
#include <linux/slab.h>
#include <linux/extcon.h>
+#include <linux/mutex.h>
#define CHARGER_TYPE_DETECTION_DEFAULT_DEBOUNCE_TIME_MS 500
@@ -41,6 +42,7 @@ struct power_supply_extcon {
uint8_t ac_online;
uint8_t usb_online;
struct power_supply_extcon_plat_data *pdata;
+ struct mutex lock;
};
struct power_supply_cables {
@@ -192,11 +194,17 @@ static int psy_extcon_extcon_notifier(struct notifier_block *self,
{
struct power_supply_cables *cable = container_of(self,
struct power_supply_cables, nb);
+ struct power_supply_extcon *psy_extcon = cable->psy_extcon;
+ struct extcon_dev *edev = cable->extcon_dev->edev;
+ mutex_lock(&psy_extcon->lock);
cable->event = event;
- cancel_delayed_work(&cable->extcon_notifier_work);
- schedule_delayed_work(&cable->extcon_notifier_work,
- msecs_to_jiffies(CHARGER_TYPE_DETECTION_DEFAULT_DEBOUNCE_TIME_MS));
+ if (cable->event == 0)
+ power_supply_extcon_remove_cable(psy_extcon, edev);
+ else if (cable->event == 1)
+ power_supply_extcon_attach_cable(psy_extcon, edev);
+
+ mutex_unlock(&psy_extcon->lock);
return NOTIFY_DONE;
}
@@ -248,6 +256,7 @@ static int psy_extcon_probe(struct platform_device *pdev)
psy_extcon->dev = &pdev->dev;
dev_set_drvdata(&pdev->dev, psy_extcon);
+ mutex_init(&psy_extcon->lock);
dev_info(psy_extcon->dev, "Extcon name %s\n", pdata->extcon_name);
@@ -304,7 +313,9 @@ static int psy_extcon_probe(struct platform_device *pdev)
goto econ_err;
}
+ mutex_lock(&psy_extcon->lock);
power_supply_extcon_attach_cable(psy_extcon, psy_extcon->edev);
+ mutex_unlock(&psy_extcon->lock);
dev_info(&pdev->dev, "%s() get success\n", __func__);
return 0;