All of lore.kernel.org
 help / color / mirror / Atom feed
From: sathyanarayanan kuppuswamy <sathyanarayanan.kuppuswamy@linux.intel.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>,
	Linus Walleij <linus.walleij@linaro.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Robert Dolca <robert.dolca@gmail.com>,
	Robert Dolca <robert.dolca@intel.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	Jonathan Cameron <jic23@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	Denis CIOCCA <denis.ciocca@st.com>
Subject: Re: [PATCH] IIO: Adds ACPI support for ST gyroscopes
Date: Wed, 25 Mar 2015 11:05:30 -0700	[thread overview]
Message-ID: <5512F8EA.2040506@linux.intel.com> (raw)
In-Reply-To: <20150325132116.GY1878@lahna.fi.intel.com>

Hi,


On 03/25/2015 06:21 AM, Mika Westerberg wrote:
> On Wed, Mar 25, 2015 at 02:25:05PM +0200, Mika Westerberg wrote:
>> I think we can do the same for ACPI GpioInts so that we introduce
>> acpi_gpio_irq_get() that translates from GpioInt to Linux IRQ
>> numberspace. Then we can do something like below in I2C core:
>>
>> 	if (client->irq <= 0) {
>> 		int irq = -ENOENT;
>>
>>                  if (dev->of_node)
>>                          irq = of_irq_get(dev->of_node, 0);
>>                  else if (ACPI_COMPANION(dev))
>>                          irq = acpi_gpio_irq_get(ACPI_COMPANION(dev), 0);
>>
>> 		if (irq == -EPROBE_DEFER)
>>                          return irq;
>>                  if (irq < 0)
>>                          irq = 0;
>>
>>                  client->irq = irq;
>> 	}
>>
>> Now it has the drawback that the first GpioInt will not be available to
>> the driver anymore (as a GPIO since it is locked) but if DT already does
>> the same we should be fine.
> Below patch should take care of this.
>
> Robert, can you try it out?
>
> If people think this is the right way to go forward, I'll make formal
> patches and submit them for review.
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index c0929d938ced..ed7c40c7b4ab 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -510,6 +510,36 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
>   	return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT);
>   }
>   
> +/**
> + * acpi_dev_gpio_irq_get() - Find GpioInt and translate it to Linux IRQ number
> + * @adev: pointer to a ACPI device to get IRQ from
> + * @index: index of GpioInt resource (starting from %0)
> + *
> + * If the device has one or more GpioInt resources, this function can be
> + * used to translate from the GPIO offset in the resource to the Linux IRQ
> + * number.
> + *
> + * Return: Linux IRQ number (>%0) on success, negative errno on failure.
> + */
> +int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
> +{
> +	struct gpio_desc *desc;
> +	int i = 0;
> +
> +	do {
> +		struct acpi_gpio_info info;
> +
> +		desc = acpi_get_gpiod_by_index(adev, NULL, i, &info);
> +		if (!IS_ERR(desc)) {
> +			if (info.gpioint && i++ == index)
> +				return gpiod_to_irq(desc);
> +		}
> +	} while (!IS_ERR(desc));
> +
> +	return -ENOENT;
> +}
> +EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get);
> +
>   static acpi_status
>   acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
>   			    u32 bits, u64 *value, void *handler_context,
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index edf274cabe81..c12a3f24ada4 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -629,8 +629,13 @@ static int i2c_device_probe(struct device *dev)
>   	if (!client)
>   		return 0;
>   
> -	if (!client->irq && dev->of_node) {
> -		int irq = of_irq_get(dev->of_node, 0);
> +	if (client->irq <= 0) {
Isn't irq 0 a valid interrupt number ? Shouldn't it be client->irq < 0 ?
> +		int irq = -ENOENT;
> +
> +		if (dev->of_node)
> +			irq = of_irq_get(dev->of_node, 0);
> +		else if (ACPI_COMPANION(dev))
> +			irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 0);
>   
>   		if (irq == -EPROBE_DEFER)
>   			return irq;
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 24c7aa8b1d20..826e214ab7d5 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -704,6 +704,8 @@ static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev)
>   	if (adev)
>   		adev->driver_gpios = NULL;
>   }
> +
> +int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index);
>   #else
>   static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
>   			      const struct acpi_gpio_mapping *gpios)
> @@ -711,6 +713,11 @@ static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
>   	return -ENXIO;
>   }
>   static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
> +
> +static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
> +{
> +	return -ENXIO;
> +}
>   #endif
>   
>   /* Device properties */
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

-- 
Sathyanarayanan Kuppuswamy
Android kernel developer


  parent reply	other threads:[~2015-03-25 18:05 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-23 13:40 [PATCH] IIO: Adds ACPI support for ST gyroscopes Robert Dolca
2015-03-23 13:40 ` [PATCH] IIO: Add support for L3GD20H gyroscope Robert Dolca
2015-03-24 10:29   ` Linus Walleij
2015-03-28 11:14     ` Jonathan Cameron
2015-03-23 15:18 ` [PATCH] IIO: Adds ACPI support for ST gyroscopes Mika Westerberg
2015-03-24 11:51   ` Daniel Baluta
2015-03-24 11:51     ` Daniel Baluta
2015-03-24 10:22 ` Linus Walleij
2015-03-24 10:37 ` Linus Walleij
2015-03-24 10:44 ` Linus Walleij
2015-03-24 12:17 ` Lars-Peter Clausen
2015-03-24 13:26   ` Robert Dolca
2015-03-24 13:38     ` Lars-Peter Clausen
2015-03-24 13:57       ` Linus Walleij
2015-03-24 15:06         ` Mika Westerberg
     [not found]           ` <20150324150630.GP1878-3PARRvDOhMZrdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2015-03-24 15:22             ` Lars-Peter Clausen
2015-03-24 15:22               ` Lars-Peter Clausen
2015-03-24 15:28               ` Daniel Baluta
2015-03-24 15:55               ` Mika Westerberg
2015-03-24 16:43                 ` Lars-Peter Clausen
     [not found]                   ` <55119429.6070806-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2015-03-24 16:55                     ` Mika Westerberg
2015-03-24 16:55                       ` Mika Westerberg
2015-03-25  8:44           ` Linus Walleij
2015-03-25  9:43             ` Mika Westerberg
2015-03-25 12:25               ` Mika Westerberg
2015-03-25 13:21                 ` Mika Westerberg
2015-03-25 13:42                   ` Robert Dolca
2015-03-25 18:05                   ` sathyanarayanan kuppuswamy [this message]
2015-03-25 18:08                     ` Lars-Peter Clausen
2015-03-25 21:12                   ` Octavian Purdila
2015-03-26 10:06                     ` Robert Dolca
2015-03-26 10:36                       ` Mika Westerberg
2015-03-26 10:16                     ` Mika Westerberg
2015-03-26 12:04                       ` Octavian Purdila
2015-03-26 14:04                         ` Mika Westerberg
2015-03-26 14:37                           ` Octavian Purdila
2015-03-26 14:47                             ` Mika Westerberg
2015-03-26 15:00                               ` Octavian Purdila
2015-03-26 16:28                                 ` Octavian Purdila
2015-03-27 10:06                                   ` Mika Westerberg
2015-03-27 10:36                                     ` Linus Walleij
2015-03-30  9:52                                       ` Mika Westerberg
2015-03-30 12:55                                         ` Octavian Purdila
2015-03-30 13:33                                           ` Mika Westerberg
2015-03-30 13:52                                             ` Octavian Purdila
2015-03-30 14:18                                               ` Mika Westerberg
2015-04-07  9:35                                               ` Linus Walleij
2015-04-07  9:39                                                 ` Lars-Peter Clausen
2015-03-26 18:32                                 ` Jonathan Cameron
2015-03-26 18:32                                   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5512F8EA.2040506@linux.intel.com \
    --to=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=denis.ciocca@st.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robert.dolca@gmail.com \
    --cc=robert.dolca@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.