linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number.
@ 2011-09-19 21:57 Stephen Warren
  2011-09-19 21:57 ` [PATCH 2/3] staging:iio:magnetometer:ak8975: Don't assume 0 is an invalid GPIO Stephen Warren
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stephen Warren @ 2011-09-19 21:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jonathan Cameron, Arnd Bergmann
  Cc: Andrew Chew, linux-iio, devel, linux-kernel, linux-tegra,
	Jonathan Cameron, Stephen Warren

From: Jonathan Cameron <jic23@cam.ac.uk>

Tegra doesn't have irq_to_gpio() any more, and ak8975 is included in
tegra_defconfig. This causes a build failure. Instead, pass the GPIO name
through platform data.

[swarren: Rewrote commit description when I squashed this with my patch
to remove the irq_to_gpio() call]

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 drivers/staging/iio/magnetometer/ak8975.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/magnetometer/ak8975.c b/drivers/staging/iio/magnetometer/ak8975.c
index a17fa9f..6d17ae5 100644
--- a/drivers/staging/iio/magnetometer/ak8975.c
+++ b/drivers/staging/iio/magnetometer/ak8975.c
@@ -477,7 +477,10 @@ static int ak8975_probe(struct i2c_client *client,
 	int err;
 
 	/* Grab and set up the supplied GPIO. */
-	eoc_gpio = irq_to_gpio(client->irq);
+	if (client->dev.platform_data == NULL)
+		eoc_gpio = -1;
+	else
+		eoc_gpio = *(int *)(client->dev.platform_data);
 
 	/* We may not have a GPIO based IRQ to scan, that is fine, we will
 	   poll if so */
-- 
1.7.0.4

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

* [PATCH 2/3] staging:iio:magnetometer:ak8975: Don't assume 0 is an invalid GPIO
  2011-09-19 21:57 [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number Stephen Warren
@ 2011-09-19 21:57 ` Stephen Warren
  2011-09-19 21:57 ` [PATCH 3/3] staging:iio:magnetometer:ak8975: Fix probe() error-handling Stephen Warren
  2011-09-20  9:06 ` [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number Jonathan Cameron
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Warren @ 2011-09-19 21:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jonathan Cameron, Arnd Bergmann
  Cc: Andrew Chew, linux-iio, devel, linux-kernel, linux-tegra,
	Stephen Warren

gpio_is_valid() is the defined mechanism to determine whether a GPIO is
valid. Use this instead of assuming that 0 is an invalid GPIO.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Andrew Chew <achew@nvidia.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/magnetometer/ak8975.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/iio/magnetometer/ak8975.c b/drivers/staging/iio/magnetometer/ak8975.c
index 6d17ae5..930ddef 100644
--- a/drivers/staging/iio/magnetometer/ak8975.c
+++ b/drivers/staging/iio/magnetometer/ak8975.c
@@ -373,7 +373,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
 	}
 
 	/* Wait for the conversion to complete. */
-	if (data->eoc_gpio)
+	if (gpio_is_valid(data->eoc_gpio))
 		ret = wait_conversion_complete_gpio(data);
 	else
 		ret = wait_conversion_complete_polled(data);
@@ -484,7 +484,7 @@ static int ak8975_probe(struct i2c_client *client,
 
 	/* We may not have a GPIO based IRQ to scan, that is fine, we will
 	   poll if so */
-	if (eoc_gpio > 0) {
+	if (gpio_is_valid(eoc_gpio)) {
 		err = gpio_request(eoc_gpio, "ak_8975");
 		if (err < 0) {
 			dev_err(&client->dev,
@@ -500,8 +500,7 @@ static int ak8975_probe(struct i2c_client *client,
 						eoc_gpio, err);
 			goto exit_gpio;
 		}
-	} else
-		eoc_gpio = 0;	/* No GPIO available */
+	}
 
 	/* Register with IIO */
 	indio_dev = iio_allocate_device(sizeof(*data));
@@ -537,7 +536,7 @@ static int ak8975_probe(struct i2c_client *client,
 exit_free_iio:
 	iio_free_device(indio_dev);
 exit_gpio:
-	if (eoc_gpio)
+	if (gpio_is_valid(eoc_gpio))
 		gpio_free(eoc_gpio);
 exit:
 	return err;
@@ -552,7 +551,7 @@ static int ak8975_remove(struct i2c_client *client)
 	iio_device_unregister(indio_dev);
 	iio_free_device(indio_dev);
 
-	if (eoc_gpio)
+	if (gpio_is_valid(eoc_gpio))
 		gpio_free(eoc_gpio);
 
 	return 0;
-- 
1.7.0.4

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

* [PATCH 3/3] staging:iio:magnetometer:ak8975: Fix probe() error-handling
  2011-09-19 21:57 [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number Stephen Warren
  2011-09-19 21:57 ` [PATCH 2/3] staging:iio:magnetometer:ak8975: Don't assume 0 is an invalid GPIO Stephen Warren
@ 2011-09-19 21:57 ` Stephen Warren
  2011-09-20  9:06 ` [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number Jonathan Cameron
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Warren @ 2011-09-19 21:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jonathan Cameron, Arnd Bergmann
  Cc: Andrew Chew, linux-iio, devel, linux-kernel, linux-tegra,
	Stephen Warren

Fix ak8975_probe() to jump to the appropriate exit labels when an error
occurs. With the previous code, some cleanup actions were being skipped
for some error conditions.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Andrew Chew <achew@nvidia.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/magnetometer/ak8975.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/magnetometer/ak8975.c b/drivers/staging/iio/magnetometer/ak8975.c
index 930ddef..8097384 100644
--- a/drivers/staging/iio/magnetometer/ak8975.c
+++ b/drivers/staging/iio/magnetometer/ak8975.c
@@ -513,7 +513,7 @@ static int ak8975_probe(struct i2c_client *client,
 	err = ak8975_setup(client);
 	if (err < 0) {
 		dev_err(&client->dev, "AK8975 initialization fails\n");
-		goto exit_gpio;
+		goto exit_free_iio;
 	}
 
 	i2c_set_clientdata(client, indio_dev);
-- 
1.7.0.4

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

* Re: [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number.
  2011-09-19 21:57 [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number Stephen Warren
  2011-09-19 21:57 ` [PATCH 2/3] staging:iio:magnetometer:ak8975: Don't assume 0 is an invalid GPIO Stephen Warren
  2011-09-19 21:57 ` [PATCH 3/3] staging:iio:magnetometer:ak8975: Fix probe() error-handling Stephen Warren
@ 2011-09-20  9:06 ` Jonathan Cameron
  2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2011-09-20  9:06 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Greg Kroah-Hartman, Arnd Bergmann, Andrew Chew, linux-iio, devel,
	linux-kernel, linux-tegra

On 09/19/11 22:57, Stephen Warren wrote:
> From: Jonathan Cameron <jic23@cam.ac.uk>
> 
> Tegra doesn't have irq_to_gpio() any more, and ak8975 is included in
> tegra_defconfig. This causes a build failure. Instead, pass the GPIO name
> through platform data.
> 
> [swarren: Rewrote commit description when I squashed this with my patch
> to remove the irq_to_gpio() call]

As I've stated elsewhere, this is the wrong fix for this particular driver,
but it is the one with minimal impact and as such I'm happy for it
to go in as a stop gap until someone has time (and hardware) to clean
this driver up to make 'correct' use of interrupts.  Note it's not going
to leave staging until that is done or someone explains why it can't be!
> 
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
Second one has some trivial one line fuzz against what I think is
the current state of Greg's tree - I'll push these on in the series I'll be
sending to Greg later today.  Obviously fine if Greg has already merged
them and fixed it up!

Thanks,

Jonathan
> ---
>  drivers/staging/iio/magnetometer/ak8975.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/staging/iio/magnetometer/ak8975.c b/drivers/staging/iio/magnetometer/ak8975.c
> index a17fa9f..6d17ae5 100644
> --- a/drivers/staging/iio/magnetometer/ak8975.c
> +++ b/drivers/staging/iio/magnetometer/ak8975.c
> @@ -477,7 +477,10 @@ static int ak8975_probe(struct i2c_client *client,
>  	int err;
>  
>  	/* Grab and set up the supplied GPIO. */
> -	eoc_gpio = irq_to_gpio(client->irq);
> +	if (client->dev.platform_data == NULL)
> +		eoc_gpio = -1;
> +	else
> +		eoc_gpio = *(int *)(client->dev.platform_data);
>  
>  	/* We may not have a GPIO based IRQ to scan, that is fine, we will
>  	   poll if so */


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

end of thread, other threads:[~2011-09-20  9:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-19 21:57 [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number Stephen Warren
2011-09-19 21:57 ` [PATCH 2/3] staging:iio:magnetometer:ak8975: Don't assume 0 is an invalid GPIO Stephen Warren
2011-09-19 21:57 ` [PATCH 3/3] staging:iio:magnetometer:ak8975: Fix probe() error-handling Stephen Warren
2011-09-20  9:06 ` [PATCH 1/3] staging:iio:magnetometer:ak8975 use platform_data to pass the gpio number Jonathan Cameron

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