linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping
@ 2018-10-19  8:59 Charles Keepax
  2018-10-19  8:59 ` [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove Charles Keepax
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Charles Keepax @ 2018-10-19  8:59 UTC (permalink / raw)
  To: wsa; +Cc: linux-i2c, linux-kernel, patches

irq_create_mapping calls irq_find_mapping internally and will use the
found mapping if one exists, so there is no need to manually call this
from i2c_smbus_host_notify_to_irq.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/i2c/i2c-core-base.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index dc78aa7369def..656f0a6fe3adf 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -306,10 +306,7 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client)
 	if (client->flags & I2C_CLIENT_TEN)
 		return -EINVAL;
 
-	irq = irq_find_mapping(adap->host_notify_domain, client->addr);
-	if (!irq)
-		irq = irq_create_mapping(adap->host_notify_domain,
-					 client->addr);
+	irq = irq_create_mapping(adap->host_notify_domain, client->addr);
 
 	return irq > 0 ? irq : -ENXIO;
 }
-- 
2.11.0


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

* [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-19  8:59 [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping Charles Keepax
@ 2018-10-19  8:59 ` Charles Keepax
  2018-10-28 22:31   ` Wolfram Sang
                     ` (2 more replies)
  2018-10-28 22:30 ` [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping Wolfram Sang
  2018-10-31 23:34 ` Wolfram Sang
  2 siblings, 3 replies; 16+ messages in thread
From: Charles Keepax @ 2018-10-19  8:59 UTC (permalink / raw)
  To: wsa; +Cc: linux-i2c, linux-kernel, patches

The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
i2c_device_remove does not clear this. When rebinding an I2C device,
whos IRQ provider has also been rebound this means that an IRQ mapping
will never be created, causing the I2C device to fail to acquire its
IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
forcing i2c_device_probe to lookup the mapping again.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/i2c/i2c-core-base.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 656f0a6fe3adf..28460f6a60cc1 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -430,6 +430,8 @@ static int i2c_device_remove(struct device *dev)
 	dev_pm_clear_wake_irq(&client->dev);
 	device_init_wakeup(&client->dev, false);
 
+	client->irq = 0;
+
 	return status;
 }
 
-- 
2.11.0


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

* Re: [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping
  2018-10-19  8:59 [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping Charles Keepax
  2018-10-19  8:59 ` [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove Charles Keepax
@ 2018-10-28 22:30 ` Wolfram Sang
  2018-10-29 10:13   ` Benjamin Tissoires
  2018-10-31 23:34 ` Wolfram Sang
  2 siblings, 1 reply; 16+ messages in thread
From: Wolfram Sang @ 2018-10-28 22:30 UTC (permalink / raw)
  To: Charles Keepax, Benjamin Tissoires; +Cc: linux-i2c, linux-kernel, patches

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

On Fri, Oct 19, 2018 at 09:59:57AM +0100, Charles Keepax wrote:
> irq_create_mapping calls irq_find_mapping internally and will use the
> found mapping if one exists, so there is no need to manually call this
> from i2c_smbus_host_notify_to_irq.
> 
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Adding Benjamin to recipients. He wrote that code.

> ---
>  drivers/i2c/i2c-core-base.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index dc78aa7369def..656f0a6fe3adf 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -306,10 +306,7 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client)
>  	if (client->flags & I2C_CLIENT_TEN)
>  		return -EINVAL;
>  
> -	irq = irq_find_mapping(adap->host_notify_domain, client->addr);
> -	if (!irq)
> -		irq = irq_create_mapping(adap->host_notify_domain,
> -					 client->addr);
> +	irq = irq_create_mapping(adap->host_notify_domain, client->addr);
>  
>  	return irq > 0 ? irq : -ENXIO;
>  }
> -- 
> 2.11.0
> 

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

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-19  8:59 ` [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove Charles Keepax
@ 2018-10-28 22:31   ` Wolfram Sang
  2018-10-29 10:15     ` Benjamin Tissoires
  2018-10-31 23:35   ` Wolfram Sang
  2019-01-09 21:47   ` Yauhen Kharuzhy
  2 siblings, 1 reply; 16+ messages in thread
From: Wolfram Sang @ 2018-10-28 22:31 UTC (permalink / raw)
  To: Charles Keepax, Benjamin Tissoires; +Cc: linux-i2c, linux-kernel, patches

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

On Fri, Oct 19, 2018 at 09:59:58AM +0100, Charles Keepax wrote:
> The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
> i2c_device_remove does not clear this. When rebinding an I2C device,
> whos IRQ provider has also been rebound this means that an IRQ mapping
> will never be created, causing the I2C device to fail to acquire its
> IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
> forcing i2c_device_probe to lookup the mapping again.
> 
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Adding Benjamin here again. Also, should there be a Fixes: tag?

> ---
>  drivers/i2c/i2c-core-base.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 656f0a6fe3adf..28460f6a60cc1 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -430,6 +430,8 @@ static int i2c_device_remove(struct device *dev)
>  	dev_pm_clear_wake_irq(&client->dev);
>  	device_init_wakeup(&client->dev, false);
>  
> +	client->irq = 0;
> +
>  	return status;
>  }
>  
> -- 
> 2.11.0
> 

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

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

* Re: [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping
  2018-10-28 22:30 ` [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping Wolfram Sang
@ 2018-10-29 10:13   ` Benjamin Tissoires
  0 siblings, 0 replies; 16+ messages in thread
From: Benjamin Tissoires @ 2018-10-29 10:13 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: ckeepax, Linux I2C, lkml, patches

On Sun, Oct 28, 2018 at 11:30 PM Wolfram Sang <wsa@the-dreams.de> wrote:
>
> On Fri, Oct 19, 2018 at 09:59:57AM +0100, Charles Keepax wrote:
> > irq_create_mapping calls irq_find_mapping internally and will use the
> > found mapping if one exists, so there is no need to manually call this
> > from i2c_smbus_host_notify_to_irq.
> >
> > Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
>
> Adding Benjamin to recipients. He wrote that code.

Yep, definitely looking good. For completeness, I just tested it on
the t450s, and it works fine.

This one is
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Cheers,
Benjamin

>
> > ---
> >  drivers/i2c/i2c-core-base.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> >
> > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> > index dc78aa7369def..656f0a6fe3adf 100644
> > --- a/drivers/i2c/i2c-core-base.c
> > +++ b/drivers/i2c/i2c-core-base.c
> > @@ -306,10 +306,7 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client)
> >       if (client->flags & I2C_CLIENT_TEN)
> >               return -EINVAL;
> >
> > -     irq = irq_find_mapping(adap->host_notify_domain, client->addr);
> > -     if (!irq)
> > -             irq = irq_create_mapping(adap->host_notify_domain,
> > -                                      client->addr);
> > +     irq = irq_create_mapping(adap->host_notify_domain, client->addr);
> >
> >       return irq > 0 ? irq : -ENXIO;
> >  }
> > --
> > 2.11.0
> >

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-28 22:31   ` Wolfram Sang
@ 2018-10-29 10:15     ` Benjamin Tissoires
  2018-10-30 11:51       ` Charles Keepax
  0 siblings, 1 reply; 16+ messages in thread
From: Benjamin Tissoires @ 2018-10-29 10:15 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: ckeepax, Linux I2C, lkml, patches

On Sun, Oct 28, 2018 at 11:31 PM Wolfram Sang <wsa@the-dreams.de> wrote:
>
> On Fri, Oct 19, 2018 at 09:59:58AM +0100, Charles Keepax wrote:
> > The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
> > i2c_device_remove does not clear this. When rebinding an I2C device,
> > whos IRQ provider has also been rebound this means that an IRQ mapping
> > will never be created, causing the I2C device to fail to acquire its
> > IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
> > forcing i2c_device_probe to lookup the mapping again.
> >
> > Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
>
> Adding Benjamin here again. Also, should there be a Fixes: tag?

Not sure if the circumstances are preventing me to think straight, but
how can you reprobe the i2c_device?
And in all cases, for the Host notify part, having the IRQ already set
shouldn't be an issue.

So for the host notify case, this patch is fine, not entirely sure
about the acpi or OF part of it.

Cheers,
Benjamin

>
> > ---
> >  drivers/i2c/i2c-core-base.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> > index 656f0a6fe3adf..28460f6a60cc1 100644
> > --- a/drivers/i2c/i2c-core-base.c
> > +++ b/drivers/i2c/i2c-core-base.c
> > @@ -430,6 +430,8 @@ static int i2c_device_remove(struct device *dev)
> >       dev_pm_clear_wake_irq(&client->dev);
> >       device_init_wakeup(&client->dev, false);
> >
> > +     client->irq = 0;
> > +
> >       return status;
> >  }
> >
> > --
> > 2.11.0
> >

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-29 10:15     ` Benjamin Tissoires
@ 2018-10-30 11:51       ` Charles Keepax
  2018-10-30 14:34         ` Benjamin Tissoires
  0 siblings, 1 reply; 16+ messages in thread
From: Charles Keepax @ 2018-10-30 11:51 UTC (permalink / raw)
  To: Benjamin Tissoires; +Cc: Wolfram Sang, Linux I2C, lkml, patches

On Mon, Oct 29, 2018 at 11:15:47AM +0100, Benjamin Tissoires wrote:
> On Sun, Oct 28, 2018 at 11:31 PM Wolfram Sang <wsa@the-dreams.de> wrote:
> >
> > On Fri, Oct 19, 2018 at 09:59:58AM +0100, Charles Keepax wrote:
> > > The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
> > > i2c_device_remove does not clear this. When rebinding an I2C device,
> > > whos IRQ provider has also been rebound this means that an IRQ mapping
> > > will never be created, causing the I2C device to fail to acquire its
> > > IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
> > > forcing i2c_device_probe to lookup the mapping again.
> > >
> > > Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> >
> > Adding Benjamin here again. Also, should there be a Fixes: tag?
> 
> Not sure if the circumstances are preventing me to think straight, but
> how can you reprobe the i2c_device?

You just head into /sys/bus/i2c/drivers/<the_driver> and use the
unbind file to remove the driver. You can then probe the driver
again using the bind file.

> And in all cases, for the Host notify part, having the IRQ already set
> shouldn't be an issue.

To be clear this isn't a theoretical issue this is something I
can replicate very easily. The problem comes in when you unbind
both the I2C device and the device that is providing its IRQ. In
my case the I2C device is a speaker amp and the device providing
IRQs is an audio CODEC.

When the device providing the IRQ is unbound it will delete the
IRQ mapping. For the I2C device to acquire its IRQ something
needs to recreate that mapping, this would normally happen (in a
DT system) as a result of the of_irq_get/_by_name. But as
client->irq is already set this doesn't happen, causing the I2C
device to fail probe because it couldn't locate its IRQ.

I can provide some stack traces or something if that would help
to clarify the issue?

Thanks,
Charles

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-30 11:51       ` Charles Keepax
@ 2018-10-30 14:34         ` Benjamin Tissoires
  2018-10-30 14:55           ` Wolfram Sang
  0 siblings, 1 reply; 16+ messages in thread
From: Benjamin Tissoires @ 2018-10-30 14:34 UTC (permalink / raw)
  To: ckeepax; +Cc: Wolfram Sang, Linux I2C, lkml, patches

On Tue, Oct 30, 2018 at 12:51 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> On Mon, Oct 29, 2018 at 11:15:47AM +0100, Benjamin Tissoires wrote:
> > On Sun, Oct 28, 2018 at 11:31 PM Wolfram Sang <wsa@the-dreams.de> wrote:
> > >
> > > On Fri, Oct 19, 2018 at 09:59:58AM +0100, Charles Keepax wrote:
> > > > The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
> > > > i2c_device_remove does not clear this. When rebinding an I2C device,
> > > > whos IRQ provider has also been rebound this means that an IRQ mapping
> > > > will never be created, causing the I2C device to fail to acquire its
> > > > IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
> > > > forcing i2c_device_probe to lookup the mapping again.
> > > >
> > > > Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> > >
> > > Adding Benjamin here again. Also, should there be a Fixes: tag?
> >
> > Not sure if the circumstances are preventing me to think straight, but
> > how can you reprobe the i2c_device?
>
> You just head into /sys/bus/i2c/drivers/<the_driver> and use the
> unbind file to remove the driver. You can then probe the driver
> again using the bind file.

Right... not sure why I haven't seen that one yesterday

>
> > And in all cases, for the Host notify part, having the IRQ already set
> > shouldn't be an issue.
>
> To be clear this isn't a theoretical issue this is something I
> can replicate very easily. The problem comes in when you unbind
> both the I2C device and the device that is providing its IRQ. In
> my case the I2C device is a speaker amp and the device providing
> IRQs is an audio CODEC.
>
> When the device providing the IRQ is unbound it will delete the
> IRQ mapping. For the I2C device to acquire its IRQ something
> needs to recreate that mapping, this would normally happen (in a
> DT system) as a result of the of_irq_get/_by_name. But as
> client->irq is already set this doesn't happen, causing the I2C
> device to fail probe because it couldn't locate its IRQ.

Right. I completely missed the fact that the driver of the IRQ could
be reset during the period the device is unbound.
That's a pretty strong case for this patch.

>
> I can provide some stack traces or something if that would help
> to clarify the issue?

No, that's fine. Now I get this, and I totally agree with the approach:

Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Cheers,
Benjamin

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-30 14:34         ` Benjamin Tissoires
@ 2018-10-30 14:55           ` Wolfram Sang
  2018-10-31  9:52             ` Charles Keepax
  0 siblings, 1 reply; 16+ messages in thread
From: Wolfram Sang @ 2018-10-30 14:55 UTC (permalink / raw)
  To: Benjamin Tissoires; +Cc: ckeepax, Linux I2C, lkml, patches

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


> No, that's fine. Now I get this, and I totally agree with the approach:
> 
> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Thanks! If one of you could provide me with a Fixes tag (for this. or
both patches?), that would be most helpful.


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

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-30 14:55           ` Wolfram Sang
@ 2018-10-31  9:52             ` Charles Keepax
  2018-10-31  9:59               ` Wolfram Sang
  0 siblings, 1 reply; 16+ messages in thread
From: Charles Keepax @ 2018-10-31  9:52 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Benjamin Tissoires, Linux I2C, lkml, patches

On Tue, Oct 30, 2018 at 02:55:50PM +0000, Wolfram Sang wrote:
> 
> > No, that's fine. Now I get this, and I totally agree with the approach:
> > 
> > Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> 
> Thanks! If one of you could provide me with a Fixes tag (for this. or
> both patches?), that would be most helpful.
> 

It's a bit of a long chain and fairly tricky to say exactly when
the bug was introduced but I think this is probably the closest
match:

Fixes: 2fd36c552649 ("i2c: core: Map OF IRQ at probe time")

I suspect the process of unbinding/rebinding would have also
not worked before that commit but it would have not worked
for different reasons.

Thanks,
Charles

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-31  9:52             ` Charles Keepax
@ 2018-10-31  9:59               ` Wolfram Sang
  0 siblings, 0 replies; 16+ messages in thread
From: Wolfram Sang @ 2018-10-31  9:59 UTC (permalink / raw)
  To: Charles Keepax; +Cc: Benjamin Tissoires, Linux I2C, lkml, patches

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


> It's a bit of a long chain and fairly tricky to say exactly when
> the bug was introduced but I think this is probably the closest
> match:
> 
> Fixes: 2fd36c552649 ("i2c: core: Map OF IRQ at probe time")

Thank you for checking! Then, I'll just leave it and cc stable so it can
be applied as long as it fits.


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

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

* Re: [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping
  2018-10-19  8:59 [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping Charles Keepax
  2018-10-19  8:59 ` [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove Charles Keepax
  2018-10-28 22:30 ` [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping Wolfram Sang
@ 2018-10-31 23:34 ` Wolfram Sang
  2 siblings, 0 replies; 16+ messages in thread
From: Wolfram Sang @ 2018-10-31 23:34 UTC (permalink / raw)
  To: Charles Keepax; +Cc: linux-i2c, linux-kernel, patches

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

On Fri, Oct 19, 2018 at 09:59:57AM +0100, Charles Keepax wrote:
> irq_create_mapping calls irq_find_mapping internally and will use the
> found mapping if one exists, so there is no need to manually call this
> from i2c_smbus_host_notify_to_irq.
> 
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Applied to for-current, thanks!


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

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-19  8:59 ` [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove Charles Keepax
  2018-10-28 22:31   ` Wolfram Sang
@ 2018-10-31 23:35   ` Wolfram Sang
  2019-01-09 21:47   ` Yauhen Kharuzhy
  2 siblings, 0 replies; 16+ messages in thread
From: Wolfram Sang @ 2018-10-31 23:35 UTC (permalink / raw)
  To: Charles Keepax; +Cc: linux-i2c, linux-kernel, patches

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

On Fri, Oct 19, 2018 at 09:59:58AM +0100, Charles Keepax wrote:
> The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
> i2c_device_remove does not clear this. When rebinding an I2C device,
> whos IRQ provider has also been rebound this means that an IRQ mapping
> will never be created, causing the I2C device to fail to acquire its
> IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
> forcing i2c_device_probe to lookup the mapping again.
> 
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Applied to for-current, thanks!


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

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2018-10-19  8:59 ` [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove Charles Keepax
  2018-10-28 22:31   ` Wolfram Sang
  2018-10-31 23:35   ` Wolfram Sang
@ 2019-01-09 21:47   ` Yauhen Kharuzhy
  2019-01-10 13:32     ` Charles Keepax
  2 siblings, 1 reply; 16+ messages in thread
From: Yauhen Kharuzhy @ 2019-01-09 21:47 UTC (permalink / raw)
  To: Charles Keepax; +Cc: wsa, linux-i2c, linux-kernel, patches

On Fri, Oct 19, 2018 at 09:59:58AM +0100, Charles Keepax wrote:
> The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
> i2c_device_remove does not clear this. When rebinding an I2C device,
> whos IRQ provider has also been rebound this means that an IRQ mapping
> will never be created, causing the I2C device to fail to acquire its
> IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
> forcing i2c_device_probe to lookup the mapping again.

Hi.

I found  driver i2c/busses/i2c-cht-wc.c which instantiates I2C device
(battery charger) and passes IRQ to driver not using standard I2C IRQ mapping code.
So if we reprobe I2C device (by reloading I2C device driver module or by
manipulations with sysfs), we get invalid IRQ number for client:

 adap->client_irq = irq_create_mapping(adap->irq_domain, 0);
 ...
 irq_set_chip_data(adap->client_irq, adap);
 irq_set_chip_and_handler(adap->client_irq, &adap->irqchip, handle_simple_irq);
 ...
 board_info.irq = adap->client_irq;
 adap->client = i2c_new_device(&adap->adapter, &board_info);


adap->client->irq will be reset after device removing here.


Any advice to fix this? Maybe move initial i2c_client->irq value to new field
like client->init_irq and copy it to client->irq at probing, for example?

> 
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
> ---
>  drivers/i2c/i2c-core-base.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 656f0a6fe3adf..28460f6a60cc1 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -430,6 +430,8 @@ static int i2c_device_remove(struct device *dev)
>  	dev_pm_clear_wake_irq(&client->dev);
>  	device_init_wakeup(&client->dev, false);
>  
> +	client->irq = 0;
> +
>  	return status;
>  }
>  

-- 
Yauhen Kharuzhy

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2019-01-09 21:47   ` Yauhen Kharuzhy
@ 2019-01-10 13:32     ` Charles Keepax
  2019-01-10 20:35       ` Yauhen Kharuzhy
  0 siblings, 1 reply; 16+ messages in thread
From: Charles Keepax @ 2019-01-10 13:32 UTC (permalink / raw)
  To: Yauhen Kharuzhy; +Cc: wsa, linux-i2c, linux-kernel, patches

On Thu, Jan 10, 2019 at 12:47:56AM +0300, Yauhen Kharuzhy wrote:
> On Fri, Oct 19, 2018 at 09:59:58AM +0100, Charles Keepax wrote:
> > The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
> > i2c_device_remove does not clear this. When rebinding an I2C device,
> > whos IRQ provider has also been rebound this means that an IRQ mapping
> > will never be created, causing the I2C device to fail to acquire its
> > IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
> > forcing i2c_device_probe to lookup the mapping again.
> 
> Hi.
> 
> I found  driver i2c/busses/i2c-cht-wc.c which instantiates I2C device
> (battery charger) and passes IRQ to driver not using standard I2C IRQ mapping code.
> So if we reprobe I2C device (by reloading I2C device driver module or by
> manipulations with sysfs), we get invalid IRQ number for client:
> 
>  adap->client_irq = irq_create_mapping(adap->irq_domain, 0);
>  ...
>  irq_set_chip_data(adap->client_irq, adap);
>  irq_set_chip_and_handler(adap->client_irq, &adap->irqchip, handle_simple_irq);
>  ...
>  board_info.irq = adap->client_irq;
>  adap->client = i2c_new_device(&adap->adapter, &board_info);
> 
> 
> adap->client->irq will be reset after device removing here.
> 
> 
> Any advice to fix this? Maybe move initial i2c_client->irq value to new field
> like client->init_irq and copy it to client->irq at probing, for example?
> 

Could you be a little more specific here, are you saying if you
reprobe the battery charger device or if you reprobe the I2C
controller itself?

Apologies but I am having a little difficulty working out the
path through which the IRQ is not reinitialised. As I would have
through the battery chargers probe would have reset up the IRQ
then the core would pick it up again from there.

Thanks,
Charles

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

* Re: [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove
  2019-01-10 13:32     ` Charles Keepax
@ 2019-01-10 20:35       ` Yauhen Kharuzhy
  0 siblings, 0 replies; 16+ messages in thread
From: Yauhen Kharuzhy @ 2019-01-10 20:35 UTC (permalink / raw)
  To: Charles Keepax; +Cc: wsa, linux-i2c, linux-kernel, patches

On Thu, Jan 10, 2019 at 01:32:36PM +0000, Charles Keepax wrote:
> On Thu, Jan 10, 2019 at 12:47:56AM +0300, Yauhen Kharuzhy wrote:
> > On Fri, Oct 19, 2018 at 09:59:58AM +0100, Charles Keepax wrote:
> > > The IRQ will be mapped in i2c_device_probe only if client->irq is zero and
> > > i2c_device_remove does not clear this. When rebinding an I2C device,
> > > whos IRQ provider has also been rebound this means that an IRQ mapping
> > > will never be created, causing the I2C device to fail to acquire its
> > > IRQ. Fix this issue by clearing client->irq in i2c_device_remove,
> > > forcing i2c_device_probe to lookup the mapping again.
> > 
> > Hi.
> > 
> > I found  driver i2c/busses/i2c-cht-wc.c which instantiates I2C device
> > (battery charger) and passes IRQ to driver not using standard I2C IRQ mapping code.
> > So if we reprobe I2C device (by reloading I2C device driver module or by
> > manipulations with sysfs), we get invalid IRQ number for client:
> > 
> >  adap->client_irq = irq_create_mapping(adap->irq_domain, 0);
> >  ...
> >  irq_set_chip_data(adap->client_irq, adap);
> >  irq_set_chip_and_handler(adap->client_irq, &adap->irqchip, handle_simple_irq);
> >  ...
> >  board_info.irq = adap->client_irq;
> >  adap->client = i2c_new_device(&adap->adapter, &board_info);
> > 
> > 
> > adap->client->irq will be reset after device removing here.
> > 
> > 
> > Any advice to fix this? Maybe move initial i2c_client->irq value to new field
> > like client->init_irq and copy it to client->irq at probing, for example?
> > 
> 
> Could you be a little more specific here, are you saying if you
> reprobe the battery charger device or if you reprobe the I2C
> controller itself?

If I reprobe the battery charger.

> 
> Apologies but I am having a little difficulty working out the
> path through which the IRQ is not reinitialised. As I would have
> through the battery chargers probe would have reset up the IRQ
> then the core would pick it up again from there.

No, this I2C bus driver(i2c-cht-wc) pass the IRQ to charger not throuth
ACPI of OF but by initializing of board_info.irq field, so I2C subsystem
cannot reinitialize irq automatically.

I am not sure if this is right path for IRQ initialization and maybe
should be changed for this driver.

> 
> Thanks,
> Charles

-- 
Yauhen Kharuzhy

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

end of thread, other threads:[~2019-01-10 20:35 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19  8:59 [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping Charles Keepax
2018-10-19  8:59 ` [PATCH 2/2] i2c: Clear client->irq in i2c_device_remove Charles Keepax
2018-10-28 22:31   ` Wolfram Sang
2018-10-29 10:15     ` Benjamin Tissoires
2018-10-30 11:51       ` Charles Keepax
2018-10-30 14:34         ` Benjamin Tissoires
2018-10-30 14:55           ` Wolfram Sang
2018-10-31  9:52             ` Charles Keepax
2018-10-31  9:59               ` Wolfram Sang
2018-10-31 23:35   ` Wolfram Sang
2019-01-09 21:47   ` Yauhen Kharuzhy
2019-01-10 13:32     ` Charles Keepax
2019-01-10 20:35       ` Yauhen Kharuzhy
2018-10-28 22:30 ` [PATCH 1/2] i2c: Remove unnecessary call to irq_find_mapping Wolfram Sang
2018-10-29 10:13   ` Benjamin Tissoires
2018-10-31 23:34 ` Wolfram Sang

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).