Skip to content

Commit 99298de

Browse files
digetxsre
authored andcommitted
power: supply: smb347-charger: Replace mutex with IRQ disable/enable
Let's simply disable/enable IRQ rather than use a mutex that protects from racing with the interrupt handler. The result of this patch is that it's a bit easier now to follow the driver's code. Tested-by: David Heidelberg <david@ixit.cz> Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent db14d3b commit 99298de

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

‎drivers/power/supply/smb347-charger.c‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <linux/init.h>
1717
#include <linux/interrupt.h>
1818
#include <linux/i2c.h>
19-
#include <linux/mutex.h>
2019
#include <linux/power_supply.h>
2120
#include <linux/power/smb347-charger.h>
2221
#include <linux/regmap.h>
@@ -122,7 +121,6 @@
122121

123122
/**
124123
* struct smb347_charger - smb347 charger instance
125-
* @lock: protects concurrent access to online variables
126124
* @dev: pointer to device
127125
* @regmap: pointer to driver regmap
128126
* @mains: power_supply instance for AC/DC power
@@ -134,7 +132,6 @@
134132
* @pdata: pointer to platform data
135133
*/
136134
struct smb347_charger {
137-
struct mutex lock;
138135
struct device *dev;
139136
struct regmap *regmap;
140137
struct power_supply *mains;
@@ -243,11 +240,9 @@ static int smb347_update_ps_status(struct smb347_charger *smb)
243240
if (smb->pdata->use_usb)
244241
usb = !(val & IRQSTAT_E_USBIN_UV_STAT);
245242

246-
mutex_lock(&smb->lock);
247243
ret = smb->mains_online != dc || smb->usb_online != usb;
248244
smb->mains_online = dc;
249245
smb->usb_online = usb;
250-
mutex_unlock(&smb->lock);
251246

252247
return ret;
253248
}
@@ -263,13 +258,7 @@ static int smb347_update_ps_status(struct smb347_charger *smb)
263258
*/
264259
static bool smb347_is_ps_online(struct smb347_charger *smb)
265260
{
266-
bool ret;
267-
268-
mutex_lock(&smb->lock);
269-
ret = smb->usb_online || smb->mains_online;
270-
mutex_unlock(&smb->lock);
271-
272-
return ret;
261+
return smb->usb_online || smb->mains_online;
273262
}
274263

275264
/**
@@ -303,14 +292,13 @@ static int smb347_charging_set(struct smb347_charger *smb, bool enable)
303292
return 0;
304293
}
305294

306-
mutex_lock(&smb->lock);
307295
if (smb->charging_enabled != enable) {
308296
ret = regmap_update_bits(smb->regmap, CMD_A, CMD_A_CHG_ENABLED,
309297
enable ? CMD_A_CHG_ENABLED : 0);
310298
if (!ret)
311299
smb->charging_enabled = enable;
312300
}
313-
mutex_unlock(&smb->lock);
301+
314302
return ret;
315303
}
316304

@@ -995,9 +983,9 @@ static int smb347_get_charging_status(struct smb347_charger *smb,
995983
return status;
996984
}
997985

998-
static int smb347_get_property(struct power_supply *psy,
999-
enum power_supply_property prop,
1000-
union power_supply_propval *val)
986+
static int smb347_get_property_locked(struct power_supply *psy,
987+
enum power_supply_property prop,
988+
union power_supply_propval *val)
1001989
{
1002990
struct smb347_charger *smb = power_supply_get_drvdata(psy);
1003991
int ret;
@@ -1064,6 +1052,21 @@ static int smb347_get_property(struct power_supply *psy,
10641052
return 0;
10651053
}
10661054

1055+
static int smb347_get_property(struct power_supply *psy,
1056+
enum power_supply_property prop,
1057+
union power_supply_propval *val)
1058+
{
1059+
struct smb347_charger *smb = power_supply_get_drvdata(psy);
1060+
struct i2c_client *client = to_i2c_client(smb->dev);
1061+
int ret;
1062+
1063+
disable_irq(client->irq);
1064+
ret = smb347_get_property_locked(psy, prop, val);
1065+
enable_irq(client->irq);
1066+
1067+
return ret;
1068+
}
1069+
10671070
static enum power_supply_property smb347_properties[] = {
10681071
POWER_SUPPLY_PROP_STATUS,
10691072
POWER_SUPPLY_PROP_CHARGE_TYPE,
@@ -1273,7 +1276,6 @@ static int smb347_probe(struct i2c_client *client,
12731276

12741277
i2c_set_clientdata(client, smb);
12751278

1276-
mutex_init(&smb->lock);
12771279
smb->dev = &client->dev;
12781280
smb->id = id->driver_data;
12791281

0 commit comments

Comments
 (0)