aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorAnda-Maria Nicolae <anda-maria.nicolae@intel.com>2015-07-07 08:25:53 -0400
committerSebastian Reichel <sre@kernel.org>2015-07-08 22:04:56 -0400
commitf5bbc91c88c18a4c518f066cc4e784d7b5fb9735 (patch)
tree1c8f8a69c95ab60c31c7a218b5c1a15c810cd0b7 /drivers/power
parentd770e558e21961ad6cfdf0ff7df0eb5d7d4f0754 (diff)
power_supply: rt9455_charger: Properly notify userspace about charging events
Charging events this patch refers to are: - charger is connected to/disconnected from the power source - battery is reconnected to the charger, after it was absent. When the charger is connected to/disconnected from the power source, CHRVPI interrupt occurs and PWR_RDY bit is either set or cleared. PWR_RDY bit is updated after 1-2 seconds CHRVPI interrupt has occurred. power_supply_changed() should be called after PWR_RDY bit is updated. /sys/class/power_supply/rt9455-charger/online file displays the value of PWR_RDY bit. This way, if the userspace is notified that a charging event has occurred and the userspace reads /sys/class/power_supply/rt9455-charger/online file, this file is properly updated when the userspace reads it. This is the reason why power_supply_changed() is called in rt9455_pwr_rdy_work_callback(), instead of being called in interrupt handler. Since no interrupt is triggered when the battery is reconnected to the charger, the userspace is never notified that the battery is reconnected. This is why power_supply_changed() is called in rt9455_max_charging_time_work_callback(), so that the userspace is notified that the battery is reconnected. Signed-off-by: Anda-Maria Nicolae <anda-maria.nicolae@intel.com> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/rt9455_charger.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
index 08baac6e3ada..a49a9d44bdda 100644
--- a/drivers/power/rt9455_charger.c
+++ b/drivers/power/rt9455_charger.c
@@ -973,7 +973,6 @@ static int rt9455_irq_handler_check_irq2_register(struct rt9455_info *info,
973 973
974 if (irq2 & GET_MASK(F_CHRVPI)) { 974 if (irq2 & GET_MASK(F_CHRVPI)) {
975 dev_dbg(dev, "Charger fault occurred\n"); 975 dev_dbg(dev, "Charger fault occurred\n");
976 alert_userspace = true;
977 /* 976 /*
978 * CHRVPI bit is set in 2 cases: 977 * CHRVPI bit is set in 2 cases:
979 * 1. when the power source is connected to the charger. 978 * 1. when the power source is connected to the charger.
@@ -981,6 +980,9 @@ static int rt9455_irq_handler_check_irq2_register(struct rt9455_info *info,
981 * To identify the case, PWR_RDY bit is checked. Because 980 * To identify the case, PWR_RDY bit is checked. Because
982 * PWR_RDY bit is set / cleared after CHRVPI interrupt is 981 * PWR_RDY bit is set / cleared after CHRVPI interrupt is
983 * triggered, it is used delayed_work to later read PWR_RDY bit. 982 * triggered, it is used delayed_work to later read PWR_RDY bit.
983 * Also, do not set to true alert_userspace, because there is no
984 * need to notify userspace when CHRVPI interrupt has occurred.
985 * Userspace will be notified after PWR_RDY bit is read.
984 */ 986 */
985 queue_delayed_work(system_power_efficient_wq, 987 queue_delayed_work(system_power_efficient_wq,
986 &info->pwr_rdy_work, 988 &info->pwr_rdy_work,
@@ -1178,7 +1180,7 @@ static irqreturn_t rt9455_irq_handler_thread(int irq, void *data)
1178 /* 1180 /*
1179 * Sometimes, an interrupt occurs while rt9455_probe() function 1181 * Sometimes, an interrupt occurs while rt9455_probe() function
1180 * is executing and power_supply_register() is not yet called. 1182 * is executing and power_supply_register() is not yet called.
1181 * Do not call power_supply_charged() in this case. 1183 * Do not call power_supply_changed() in this case.
1182 */ 1184 */
1183 if (info->charger) 1185 if (info->charger)
1184 power_supply_changed(info->charger); 1186 power_supply_changed(info->charger);
@@ -1478,6 +1480,11 @@ static void rt9455_pwr_rdy_work_callback(struct work_struct *work)
1478 RT9455_MAX_CHARGING_TIME * HZ); 1480 RT9455_MAX_CHARGING_TIME * HZ);
1479 break; 1481 break;
1480 } 1482 }
1483 /*
1484 * Notify userspace that the charger has been either connected to or
1485 * disconnected from the power source.
1486 */
1487 power_supply_changed(info->charger);
1481} 1488}
1482 1489
1483static void rt9455_max_charging_time_work_callback(struct work_struct *work) 1490static void rt9455_max_charging_time_work_callback(struct work_struct *work)
@@ -1533,6 +1540,11 @@ static void rt9455_batt_presence_work_callback(struct work_struct *work)
1533 if (ret) 1540 if (ret)
1534 dev_err(dev, "Failed to unmask BATAB interrupt\n"); 1541 dev_err(dev, "Failed to unmask BATAB interrupt\n");
1535 } 1542 }
1543 /*
1544 * Notify userspace that the battery is now connected to the
1545 * charger.
1546 */
1547 power_supply_changed(info->charger);
1536 } 1548 }
1537} 1549}
1538 1550