Commit a05d7ce3 authored by Michael Hennerich's avatar Michael Hennerich Committed by Greg Kroah-Hartman

Staging: iio: iio-trig-gpio: Remove redundant gpio_request

Remove redundant gpio_request:
The GPIO used as trigger IRQ, is also requested as gpio, but actually never read.

Use platform resource facility to get IRQs numbers and flags.
Make sure this driver can be used with any system IRQ, not necessarily limited to GPIO-IRQs.
Use dev_err(dev...) and friends instead of printk(KERN_ERR...)
Signed-off-by: default avatarMichael Hennerich <Michael.Hennerich@analog.com>
Acked-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ceb0525c
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
* TODO: * TODO:
* *
* Add board config elements to allow specification of startup settings. * Add board config elements to allow specification of startup settings.
* Add configuration settings (irq type etc)
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -31,7 +30,7 @@ DEFINE_MUTEX(iio_gpio_trigger_list_lock); ...@@ -31,7 +30,7 @@ DEFINE_MUTEX(iio_gpio_trigger_list_lock);
struct iio_gpio_trigger_info { struct iio_gpio_trigger_info {
struct mutex in_use; struct mutex in_use;
int gpio; unsigned int irq;
}; };
/* /*
* Need to reference count these triggers and only enable gpio interrupts * Need to reference count these triggers and only enable gpio interrupts
...@@ -58,78 +57,77 @@ static const struct attribute_group iio_gpio_trigger_attr_group = { ...@@ -58,78 +57,77 @@ static const struct attribute_group iio_gpio_trigger_attr_group = {
.attrs = iio_gpio_trigger_attrs, .attrs = iio_gpio_trigger_attrs,
}; };
static int iio_gpio_trigger_probe(struct platform_device *dev) static int iio_gpio_trigger_probe(struct platform_device *pdev)
{ {
int *pdata = dev->dev.platform_data;
struct iio_gpio_trigger_info *trig_info; struct iio_gpio_trigger_info *trig_info;
struct iio_trigger *trig, *trig2; struct iio_trigger *trig, *trig2;
int i, irq, ret = 0; unsigned long irqflags;
if (!pdata) { struct resource *irq_res;
printk(KERN_ERR "No IIO gpio trigger platform data found\n"); int irq, ret = 0, irq_res_cnt = 0;
goto error_ret;
}
for (i = 0;; i++) {
if (!gpio_is_valid(pdata[i]))
break;
trig = iio_allocate_trigger();
if (!trig) {
ret = -ENOMEM;
goto error_free_completed_registrations;
}
trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL); do {
if (!trig_info) { irq_res = platform_get_resource(pdev,
ret = -ENOMEM; IORESOURCE_IRQ, irq_res_cnt);
goto error_put_trigger;
} if (irq_res == NULL) {
trig->control_attrs = &iio_gpio_trigger_attr_group; if (irq_res_cnt == 0)
trig->private_data = trig_info; dev_err(&pdev->dev, "No GPIO IRQs specified");
trig_info->gpio = pdata[i]; break;
trig->owner = THIS_MODULE;
trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH, GFP_KERNEL);
if (!trig->name) {
ret = -ENOMEM;
goto error_free_trig_info;
} }
snprintf((char *)trig->name, irqflags = (irq_res->flags & IRQF_TRIGGER_MASK) | IRQF_SHARED;
IIO_TRIGGER_NAME_LENGTH,
"gpiotrig%d", for (irq = irq_res->start; irq <= irq_res->end; irq++) {
pdata[i]);
ret = gpio_request(trig_info->gpio, trig->name); trig = iio_allocate_trigger();
if (ret) if (!trig) {
goto error_free_name; ret = -ENOMEM;
goto error_free_completed_registrations;
ret = gpio_direction_input(trig_info->gpio); }
if (ret)
goto error_release_gpio; trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL);
if (!trig_info) {
irq = gpio_to_irq(trig_info->gpio); ret = -ENOMEM;
if (irq < 0) { goto error_put_trigger;
ret = irq; }
goto error_release_gpio; trig->control_attrs = &iio_gpio_trigger_attr_group;
trig->private_data = trig_info;
trig_info->irq = irq;
trig->owner = THIS_MODULE;
trig->name = kmalloc(IIO_TRIGGER_NAME_LENGTH,
GFP_KERNEL);
if (!trig->name) {
ret = -ENOMEM;
goto error_free_trig_info;
}
snprintf((char *)trig->name,
IIO_TRIGGER_NAME_LENGTH,
"irqtrig%d", irq);
ret = request_irq(irq, iio_gpio_trigger_poll,
irqflags, trig->name, trig);
if (ret) {
dev_err(&pdev->dev,
"request IRQ-%d failed", irq);
goto error_free_name;
}
ret = iio_trigger_register(trig);
if (ret)
goto error_release_irq;
list_add_tail(&trig->alloc_list,
&iio_gpio_trigger_list);
} }
ret = request_irq(irq, iio_gpio_trigger_poll, irq_res_cnt++;
IRQF_TRIGGER_RISING, } while (irq_res != NULL);
trig->name,
trig);
if (ret)
goto error_release_gpio;
ret = iio_trigger_register(trig);
if (ret)
goto error_release_irq;
list_add_tail(&trig->alloc_list, &iio_gpio_trigger_list);
}
return 0; return 0;
/* First clean up the partly allocated trigger */ /* First clean up the partly allocated trigger */
error_release_irq: error_release_irq:
free_irq(irq, trig); free_irq(irq, trig);
error_release_gpio:
gpio_free(trig_info->gpio);
error_free_name: error_free_name:
kfree(trig->name); kfree(trig->name);
error_free_trig_info: error_free_trig_info:
...@@ -143,18 +141,16 @@ static int iio_gpio_trigger_probe(struct platform_device *dev) ...@@ -143,18 +141,16 @@ static int iio_gpio_trigger_probe(struct platform_device *dev)
&iio_gpio_trigger_list, &iio_gpio_trigger_list,
alloc_list) { alloc_list) {
trig_info = trig->private_data; trig_info = trig->private_data;
free_irq(gpio_to_irq(trig_info->gpio), trig); free_irq(gpio_to_irq(trig_info->irq), trig);
gpio_free(trig_info->gpio);
kfree(trig->name); kfree(trig->name);
kfree(trig_info); kfree(trig_info);
iio_trigger_unregister(trig); iio_trigger_unregister(trig);
} }
error_ret:
return ret; return ret;
} }
static int iio_gpio_trigger_remove(struct platform_device *dev) static int iio_gpio_trigger_remove(struct platform_device *pdev)
{ {
struct iio_trigger *trig, *trig2; struct iio_trigger *trig, *trig2;
struct iio_gpio_trigger_info *trig_info; struct iio_gpio_trigger_info *trig_info;
...@@ -166,8 +162,7 @@ static int iio_gpio_trigger_remove(struct platform_device *dev) ...@@ -166,8 +162,7 @@ static int iio_gpio_trigger_remove(struct platform_device *dev)
alloc_list) { alloc_list) {
trig_info = trig->private_data; trig_info = trig->private_data;
iio_trigger_unregister(trig); iio_trigger_unregister(trig);
free_irq(gpio_to_irq(trig_info->gpio), trig); free_irq(trig_info->irq, trig);
gpio_free(trig_info->gpio);
kfree(trig->name); kfree(trig->name);
kfree(trig_info); kfree(trig_info);
iio_put_trigger(trig); iio_put_trigger(trig);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment