linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] power: supply: smb347-charger: Fix interrupt usage if interrupt is unavailable
@ 2021-01-22 19:17 Dmitry Osipenko
  2021-01-28  0:34 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Osipenko @ 2021-01-22 19:17 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-kernel

The IRQ=0 could be a valid interrupt number in kernel because interrupt
numbers are virtual in a modern kernel. Hence fix the interrupt usage in
a case if interrupt is unavailable by not overriding the interrupt number
which is used by the driver.

Note that currently Nexus 7 is the only know device which uses SMB347
kernel diver and it has a properly working interrupt, hence this patch
doesn't fix any real problems, it's a minor cleanup/improvement.

Fixes: 99298de5df92 ("power: supply: smb347-charger: Replace mutex with IRQ disable/enable")
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/power/supply/smb347-charger.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c
index d3bf35ed12ce..8cfbd8d6b478 100644
--- a/drivers/power/supply/smb347-charger.c
+++ b/drivers/power/supply/smb347-charger.c
@@ -137,6 +137,7 @@
  * @mains_online: is AC/DC input connected
  * @usb_online: is USB input connected
  * @charging_enabled: is charging enabled
+ * @irq_unsupported: is interrupt unsupported by SMB hardware
  * @max_charge_current: maximum current (in uA) the battery can be charged
  * @max_charge_voltage: maximum voltage (in uV) the battery can be charged
  * @pre_charge_current: current (in uA) to use in pre-charging phase
@@ -193,6 +194,7 @@ struct smb347_charger {
 	bool			mains_online;
 	bool			usb_online;
 	bool			charging_enabled;
+	bool			irq_unsupported;
 
 	unsigned int		max_charge_current;
 	unsigned int		max_charge_voltage;
@@ -862,6 +864,9 @@ static int smb347_irq_set(struct smb347_charger *smb, bool enable)
 {
 	int ret;
 
+	if (smb->irq_unsupported)
+		return 0;
+
 	ret = smb347_set_writable(smb, true);
 	if (ret < 0)
 		return ret;
@@ -923,8 +928,6 @@ static int smb347_irq_init(struct smb347_charger *smb,
 	ret = regmap_update_bits(smb->regmap, CFG_STAT,
 				 CFG_STAT_ACTIVE_HIGH | CFG_STAT_DISABLED,
 				 CFG_STAT_DISABLED);
-	if (ret < 0)
-		client->irq = 0;
 
 	smb347_set_writable(smb, false);
 
@@ -1345,6 +1348,7 @@ static int smb347_probe(struct i2c_client *client,
 		if (ret < 0) {
 			dev_warn(dev, "failed to initialize IRQ: %d\n", ret);
 			dev_warn(dev, "disabling IRQ support\n");
+			smb->irq_unsupported = true;
 		} else {
 			smb347_irq_enable(smb);
 		}
@@ -1357,8 +1361,8 @@ static int smb347_remove(struct i2c_client *client)
 {
 	struct smb347_charger *smb = i2c_get_clientdata(client);
 
-	if (client->irq)
-		smb347_irq_disable(smb);
+	smb347_irq_disable(smb);
+
 	return 0;
 }
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] power: supply: smb347-charger: Fix interrupt usage if interrupt is unavailable
  2021-01-22 19:17 [PATCH v1] power: supply: smb347-charger: Fix interrupt usage if interrupt is unavailable Dmitry Osipenko
@ 2021-01-28  0:34 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2021-01-28  0:34 UTC (permalink / raw)
  To: Dmitry Osipenko; +Cc: linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2919 bytes --]

Hi,

On Fri, Jan 22, 2021 at 10:17:34PM +0300, Dmitry Osipenko wrote:
> The IRQ=0 could be a valid interrupt number in kernel because interrupt
> numbers are virtual in a modern kernel. Hence fix the interrupt usage in
> a case if interrupt is unavailable by not overriding the interrupt number
> which is used by the driver.
> 
> Note that currently Nexus 7 is the only know device which uses SMB347
> kernel diver and it has a properly working interrupt, hence this patch
> doesn't fix any real problems, it's a minor cleanup/improvement.
> 
> Fixes: 99298de5df92 ("power: supply: smb347-charger: Replace mutex with IRQ disable/enable")
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/smb347-charger.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c
> index d3bf35ed12ce..8cfbd8d6b478 100644
> --- a/drivers/power/supply/smb347-charger.c
> +++ b/drivers/power/supply/smb347-charger.c
> @@ -137,6 +137,7 @@
>   * @mains_online: is AC/DC input connected
>   * @usb_online: is USB input connected
>   * @charging_enabled: is charging enabled
> + * @irq_unsupported: is interrupt unsupported by SMB hardware
>   * @max_charge_current: maximum current (in uA) the battery can be charged
>   * @max_charge_voltage: maximum voltage (in uV) the battery can be charged
>   * @pre_charge_current: current (in uA) to use in pre-charging phase
> @@ -193,6 +194,7 @@ struct smb347_charger {
>  	bool			mains_online;
>  	bool			usb_online;
>  	bool			charging_enabled;
> +	bool			irq_unsupported;
>  
>  	unsigned int		max_charge_current;
>  	unsigned int		max_charge_voltage;
> @@ -862,6 +864,9 @@ static int smb347_irq_set(struct smb347_charger *smb, bool enable)
>  {
>  	int ret;
>  
> +	if (smb->irq_unsupported)
> +		return 0;
> +
>  	ret = smb347_set_writable(smb, true);
>  	if (ret < 0)
>  		return ret;
> @@ -923,8 +928,6 @@ static int smb347_irq_init(struct smb347_charger *smb,
>  	ret = regmap_update_bits(smb->regmap, CFG_STAT,
>  				 CFG_STAT_ACTIVE_HIGH | CFG_STAT_DISABLED,
>  				 CFG_STAT_DISABLED);
> -	if (ret < 0)
> -		client->irq = 0;
>  
>  	smb347_set_writable(smb, false);
>  
> @@ -1345,6 +1348,7 @@ static int smb347_probe(struct i2c_client *client,
>  		if (ret < 0) {
>  			dev_warn(dev, "failed to initialize IRQ: %d\n", ret);
>  			dev_warn(dev, "disabling IRQ support\n");
> +			smb->irq_unsupported = true;
>  		} else {
>  			smb347_irq_enable(smb);
>  		}
> @@ -1357,8 +1361,8 @@ static int smb347_remove(struct i2c_client *client)
>  {
>  	struct smb347_charger *smb = i2c_get_clientdata(client);
>  
> -	if (client->irq)
> -		smb347_irq_disable(smb);
> +	smb347_irq_disable(smb);
> +
>  	return 0;
>  }
>  
> -- 
> 2.29.2
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-28  0:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 19:17 [PATCH v1] power: supply: smb347-charger: Fix interrupt usage if interrupt is unavailable Dmitry Osipenko
2021-01-28  0:34 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).