mbox series

[v2,0/3] Enable named interrupt smbus-alert for ACPI

Message ID 1641996862-26960-1-git-send-email-akhilrajeev@nvidia.com
Headers show
Series Enable named interrupt smbus-alert for ACPI | expand

Message

Akhil R Jan. 12, 2022, 2:14 p.m. UTC
I2C - SMBus core drivers use named interrupts to support smbus_alert.
As named interrupts are not available for ACPI based systems, it was
required to change the i2c bus controller driver if to use smbus alert.
These patches provide option for named interrupts in ACPI and  make the
implementation similar to DT. This will enable use of interrupt named
'smbus-alert' in ACPI as well which will be taken during i2c adapter
register.

v1->v2:
  * Added firmware guide documentation for ACPI named interrupts
  * Updates in function description comments

Akhil R (3):
  device property: Add device_irq_get_byname
  docs: firmware-guide: ACPI: Add named interrupt doc
  i2c: smbus: Use device_*() functions instead of of_*()

 Documentation/firmware-guide/acpi/enumeration.rst | 38 +++++++++++++++++++++++
 drivers/base/property.c                           | 35 +++++++++++++++++++++
 drivers/i2c/i2c-core-base.c                       |  2 +-
 drivers/i2c/i2c-core-smbus.c                      | 10 +++---
 drivers/i2c/i2c-smbus.c                           |  2 +-
 include/linux/i2c-smbus.h                         |  6 ++--
 include/linux/property.h                          |  3 ++
 7 files changed, 86 insertions(+), 10 deletions(-)

Comments

Andy Shevchenko Jan. 12, 2022, 3:41 p.m. UTC | #1
On Wed, Jan 12, 2022 at 4:15 PM Akhil R <akhilrajeev@nvidia.com> wrote:
>
> Change of_*() functions to device_*() for firmware agnostic usage.
> This allows to have smbus_alert interrupt without any changes

the smbus_alert

> in the controller drivers using ACPI table.

the ACPI

...

This change reveals potential issue:

> -               irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
> +               irq = device_irq_get_byname(adapter->dev.parent, "smbus_alert");

>                 if (irq <= 0)

I guess this '= 0' part should be fixed first.

>                         return irq;
Andy Shevchenko Jan. 12, 2022, 3:55 p.m. UTC | #2
On Wed, Jan 12, 2022 at 4:14 PM Akhil R <akhilrajeev@nvidia.com> wrote:
>
> I2C - SMBus core drivers use named interrupts to support smbus_alert.
> As named interrupts are not available for ACPI based systems, it was
> required to change the i2c bus controller driver if to use smbus alert.
> These patches provide option for named interrupts in ACPI and  make the
> implementation similar to DT. This will enable use of interrupt named
> 'smbus-alert' in ACPI as well which will be taken during i2c adapter
> register.

Most of my comments are regarding spelling and documentation.
The code looks almost good enough. That said, if maintainers will be
okay, I'm sure the next version will be upstream-ready.

Thanks!
Akhil R Jan. 13, 2022, 4:41 a.m. UTC | #3
> On Wed, Jan 12, 2022 at 3:14 PM Akhil R <akhilrajeev@nvidia.com> wrote:
> >
> > Get interrupt by name from ACPI table as well.
> >
> > Add option to use 'interrupt-names' in _DSD which can map to interrupt
> > by index. The implementation is similar to 'interrupt-names' in devicetree.
> > Also add a common routine to get irq by name from devicetree and ACPI
> > table.
> >
> > Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
> > ---
> >  drivers/base/property.c  | 35 +++++++++++++++++++++++++++++++++++
> >  include/linux/property.h |  3 +++
> >  2 files changed, 38 insertions(+)
> >
> > diff --git a/drivers/base/property.c b/drivers/base/property.c index
> > cbe4fa2..414c316 100644
> > --- a/drivers/base/property.c
> > +++ b/drivers/base/property.c
> > @@ -920,6 +920,41 @@ int fwnode_irq_get(const struct fwnode_handle
> > *fwnode, unsigned int index)  EXPORT_SYMBOL(fwnode_irq_get);
> >
> >  /**
> > + * fwnode_irq_get_byname - Get IRQ from a fwnode using its name
> > + * @fwnode:    Pointer to the firmware node
> > + * @name:      IRQ name in interrupt-names property in fwnode
> > + *
> > + * Returns Linux IRQ number on success, errno otherwise.
> > + */
> > +int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const
> > +char *name) {
> > +       int index;
> > +
> > +       if (unlikely(!name))
> > +               return -EINVAL;
> > +
> > +       index = fwnode_property_match_string(fwnode, "interrupt-names",
> name);
> > +       if (index < 0)
> > +               return index;
> > +
> > +       return fwnode_irq_get(fwnode, index); }
> > +EXPORT_SYMBOL(fwnode_irq_get_byname);
> > +
> > +/**
> > + * device_irq_get_byname - Get IRQ of a device using interrupt name
> > + * @dev:       Device to get the interrupt
> > + * @name:      IRQ name in interrupt-names property in fwnode
> 
> Which fwnode?
> 
> > + *
> > + * Returns Linux IRQ number on success, errno otherwise.
> > + */
> > +int device_irq_get_byname(struct device *dev, const char *name) {
> > +       return fwnode_irq_get_byname(dev_fwnode(dev), name); }
> > +EXPORT_SYMBOL_GPL(device_irq_get_byname);
> 
> This can be confusing, because it pretends to be super-generic and in fact it
> depends on an fwnode to be there.
> 
> I guess I'd rather not have it at all, or use a more precise name for it.
But, I suppose, the other device_*() functions also depend on the fwnode.
Wouldn't it make the naming inconsistent if we add a different one here?
Would it be better if I add more details in the description comment?
Akhil R Jan. 20, 2022, 9:48 a.m. UTC | #4
> On Wed, Jan 12, 2022 at 4:15 PM Akhil R <akhilrajeev@nvidia.com> wrote:
> >
> > Change of_*() functions to device_*() for firmware agnostic usage.
> > This allows to have smbus_alert interrupt without any changes
> 
> the smbus_alert
> 
> > in the controller drivers using ACPI table.
> 
> the ACPI
> 
> ...
> 
> This change reveals potential issue:
> 
> > -               irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
> > +               irq = device_irq_get_byname(adapter->dev.parent, "smbus_alert");
> 
> >                 if (irq <= 0)
> 
> I guess this '= 0' part should be fixed first.

'0' is a failure as per the documentation of of_irq_get_byname() as well as
of_irq_get(). The case is different for acpi_irq_get(), but it is handled in
fwnode_irq_get(). If I understood it right, a return value of '0' should be 
considered a failure here.

Thanks,
Akhil
Andy Shevchenko Jan. 20, 2022, 10:12 a.m. UTC | #5
On Thu, Jan 20, 2022 at 11:48 AM Akhil R <akhilrajeev@nvidia.com> wrote:
> > On Wed, Jan 12, 2022 at 4:15 PM Akhil R <akhilrajeev@nvidia.com> wrote:

...

> > This change reveals potential issue:
> >
> > > -               irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
> > > +               irq = device_irq_get_byname(adapter->dev.parent, "smbus_alert");
> >
> > >                 if (irq <= 0)
> >
> > I guess this '= 0' part should be fixed first.
>
> '0' is a failure as per the documentation of of_irq_get_byname() as well as
> of_irq_get(). The case is different for acpi_irq_get(), but it is handled in
> fwnode_irq_get(). If I understood it right, a return value of '0' should be
> considered a failure here.

Depends. I have no idea what the original code does here. But
returning an error or 0 from this function seems confusing to me.
Akhil R Jan. 20, 2022, 10:29 a.m. UTC | #6
> ...
> 
> > > This change reveals potential issue:
> > >
> > > > -               irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
> > > > +               irq = device_irq_get_byname(adapter->dev.parent,
> "smbus_alert");
> > >
> > > >                 if (irq <= 0)
> > >
> > > I guess this '= 0' part should be fixed first.
> >
> > '0' is a failure as per the documentation of of_irq_get_byname() as well as
> > of_irq_get(). The case is different for acpi_irq_get(), but it is handled in
> > fwnode_irq_get(). If I understood it right, a return value of '0' should be
> > considered a failure here.
> 
> Depends. I have no idea what the original code does here. But
> returning an error or 0 from this function seems confusing to me.
> 
The description in of_irq_get*() says - 
/* Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or
 * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case
 * of any other failure.
 */
As I see from the code of fwnode_irq_get(), which is used in this case, returns 
either the return value of of_irq_get() or error code from acpi_irq_get() when
it fails, or res.start if it didn't fail. I guess, any of these would not be 0 unless
there is an error.

Thanks,
Akhil
Andy Shevchenko Jan. 20, 2022, 10:43 a.m. UTC | #7
On Thu, Jan 20, 2022 at 12:29 PM Akhil R <akhilrajeev@nvidia.com> wrote:
>
> > ...
> >
> > > > This change reveals potential issue:
> > > >
> > > > > -               irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
> > > > > +               irq = device_irq_get_byname(adapter->dev.parent,
> > "smbus_alert");
> > > >
> > > > >                 if (irq <= 0)
> > > >
> > > > I guess this '= 0' part should be fixed first.
> > >
> > > '0' is a failure as per the documentation of of_irq_get_byname() as well as
> > > of_irq_get(). The case is different for acpi_irq_get(), but it is handled in
> > > fwnode_irq_get(). If I understood it right, a return value of '0' should be
> > > considered a failure here.
> >
> > Depends. I have no idea what the original code does here. But
> > returning an error or 0 from this function seems confusing to me.
> >
> The description in of_irq_get*() says -
> /* Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or
>  * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case
>  * of any other failure.
>  */
> As I see from the code of fwnode_irq_get(), which is used in this case, returns
> either the return value of of_irq_get() or error code from acpi_irq_get() when
> it fails, or res.start if it didn't fail. I guess, any of these would not be 0 unless
> there is an error.

of_irq_get*() seems inconsistent...

Uwe, what do you think?
Akhil R Jan. 20, 2022, 11:30 a.m. UTC | #8
> > > ...
> > >
> > > > > This change reveals potential issue:
> > > > >
> > > > > > -               irq = of_irq_get_byname(adapter->dev.of_node,
> "smbus_alert");
> > > > > > +               irq =
> > > > > > + device_irq_get_byname(adapter->dev.parent,
> > > "smbus_alert");
> > > > >
> > > > > >                 if (irq <= 0)
> > > > >
> > > > > I guess this '= 0' part should be fixed first.
> > > >
> > > > '0' is a failure as per the documentation of of_irq_get_byname()
> > > > as well as of_irq_get(). The case is different for acpi_irq_get(),
> > > > but it is handled in fwnode_irq_get(). If I understood it right, a
> > > > return value of '0' should be considered a failure here.
> > >
> > > Depends. I have no idea what the original code does here. But
> > > returning an error or 0 from this function seems confusing to me.
> > >
> > The description in of_irq_get*() says -
> > /* Return: Linux IRQ number on success, or 0 on the IRQ mapping
> > failure, or
> >  * -EPROBE_DEFER if the IRQ domain is not yet created, or error code
> > in case
> >  * of any other failure.
> >  */
> > As I see from the code of fwnode_irq_get(), which is used in this
> > case, returns either the return value of of_irq_get() or error code
> > from acpi_irq_get() when it fails, or res.start if it didn't fail. I
> > guess, any of these would not be 0 unless there is an error.
> 
> of_irq_get*() seems inconsistent...
> 
> Uwe, what do you think?
> 
A bit tricky. You are right, as we don't often see a return value of '0' as
an error in Linux. But here since it is a number which is expected, it might
be reasonable to allot 0 to an error as well. Not sure of the exact rationale
in those functions though.

Thanks,
Akhil
Uwe Kleine-König Jan. 20, 2022, 11:30 a.m. UTC | #9
On Thu, Jan 20, 2022 at 12:43:02PM +0200, Andy Shevchenko wrote:
> On Thu, Jan 20, 2022 at 12:29 PM Akhil R <akhilrajeev@nvidia.com> wrote:
> >
> > > ...
> > >
> > > > > This change reveals potential issue:
> > > > >
> > > > > > -               irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
> > > > > > +               irq = device_irq_get_byname(adapter->dev.parent,
> > > "smbus_alert");
> > > > >
> > > > > >                 if (irq <= 0)
> > > > >
> > > > > I guess this '= 0' part should be fixed first.
> > > >
> > > > '0' is a failure as per the documentation of of_irq_get_byname() as well as
> > > > of_irq_get(). The case is different for acpi_irq_get(), but it is handled in
> > > > fwnode_irq_get(). If I understood it right, a return value of '0' should be
> > > > considered a failure here.
> > >
> > > Depends. I have no idea what the original code does here. But
> > > returning an error or 0 from this function seems confusing to me.
> > >
> > The description in of_irq_get*() says -
> > /* Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or
> >  * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case
> >  * of any other failure.
> >  */
> > As I see from the code of fwnode_irq_get(), which is used in this case, returns
> > either the return value of of_irq_get() or error code from acpi_irq_get() when
> > it fails, or res.start if it didn't fail. I guess, any of these would not be 0 unless
> > there is an error.
> 
> of_irq_get*() seems inconsistent...
> 
> Uwe, what do you think?

Yeah, this is something I stumbled over during the platform_get_irq*()
discussion. But I don't feel like investing any more energy there.

Best regards
Uwe