treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / iio / imu / adis_trigger.c
blob8b9cd02c0f9f51826792cc2c5e5d5ae1732ef61a
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Common library for ADIS16XXX devices
5 * Copyright 2012 Analog Devices Inc.
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
7 */
9 #include <linux/interrupt.h>
10 #include <linux/kernel.h>
11 #include <linux/spi/spi.h>
12 #include <linux/export.h>
14 #include <linux/iio/iio.h>
15 #include <linux/iio/trigger.h>
16 #include <linux/iio/imu/adis.h>
18 static int adis_data_rdy_trigger_set_state(struct iio_trigger *trig,
19 bool state)
21 struct adis *adis = iio_trigger_get_drvdata(trig);
23 return adis_enable_irq(adis, state);
26 static const struct iio_trigger_ops adis_trigger_ops = {
27 .set_trigger_state = &adis_data_rdy_trigger_set_state,
30 /**
31 * adis_probe_trigger() - Sets up trigger for a adis device
32 * @adis: The adis device
33 * @indio_dev: The IIO device
35 * Returns 0 on success or a negative error code
37 * adis_remove_trigger() should be used to free the trigger.
39 int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
41 int ret;
43 adis->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name,
44 indio_dev->id);
45 if (adis->trig == NULL)
46 return -ENOMEM;
48 adis->trig->dev.parent = &adis->spi->dev;
49 adis->trig->ops = &adis_trigger_ops;
50 iio_trigger_set_drvdata(adis->trig, adis);
52 ret = request_irq(adis->spi->irq,
53 &iio_trigger_generic_data_rdy_poll,
54 IRQF_TRIGGER_RISING,
55 indio_dev->name,
56 adis->trig);
57 if (ret)
58 goto error_free_trig;
60 ret = iio_trigger_register(adis->trig);
62 indio_dev->trig = iio_trigger_get(adis->trig);
63 if (ret)
64 goto error_free_irq;
66 return 0;
68 error_free_irq:
69 free_irq(adis->spi->irq, adis->trig);
70 error_free_trig:
71 iio_trigger_free(adis->trig);
72 return ret;
74 EXPORT_SYMBOL_GPL(adis_probe_trigger);
76 /**
77 * adis_remove_trigger() - Remove trigger for a adis devices
78 * @adis: The adis device
80 * Removes the trigger previously registered with adis_probe_trigger().
82 void adis_remove_trigger(struct adis *adis)
84 iio_trigger_unregister(adis->trig);
85 free_irq(adis->spi->irq, adis->trig);
86 iio_trigger_free(adis->trig);
88 EXPORT_SYMBOL_GPL(adis_remove_trigger);