Message ID | 20210425102638.9511-2-lars@metafoo.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] iio: xilinx-xadc: Remove `irq` field from state struct | expand |
On Sun, 25 Apr 2021 12:26:38 +0200 Lars-Peter Clausen <lars@metafoo.de> wrote: > In some setups the IRQ signal of the XADC might not be wired to the host > system. The driver currently requires that an interrupt is specified. Make > the interrupt optional so the driver can be used in such setups where the > interrupt is not connected. > > Since both buffered capture as well as events depend on the interrupt being > connected both are not available when the interrupt is not connected. > > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Code looks fine to me but raises a question. As there is no validate_trigger callback in this driver, nothing stops it being associated with for example an hrtimer trigger. I don't think that will work so perhaps we should add the callback? If it does work, then the presence or not of an irq should not change whether we register the buffer. Jonathan > --- > drivers/iio/adc/xilinx-xadc-core.c | 39 +++++++++++++++++++----------- > 1 file changed, 25 insertions(+), 14 deletions(-) > > diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c > index dd1c92b2811f..ffefb01a3893 100644 > --- a/drivers/iio/adc/xilinx-xadc-core.c > +++ b/drivers/iio/adc/xilinx-xadc-core.c > @@ -1182,7 +1182,7 @@ static const struct of_device_id xadc_of_match_table[] = { > MODULE_DEVICE_TABLE(of, xadc_of_match_table); > > static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, > - unsigned int *conf) > + unsigned int *conf, int irq) > { > struct device *dev = indio_dev->dev.parent; > struct xadc *xadc = iio_priv(indio_dev); > @@ -1195,6 +1195,7 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, > u32 ext_mux_chan; > u32 reg; > int ret; > + int i; > > *conf = 0; > > @@ -1273,6 +1274,14 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, > } > of_node_put(chan_node); > > + /* No IRQ => no events */ > + if (irq <= 0) { > + for (i = 0; i < num_channels; i++) { > + channels[i].event_spec = NULL; > + channels[i].num_event_specs = 0; > + } > + } > + > indio_dev->num_channels = num_channels; > indio_dev->channels = devm_krealloc(dev, channels, > sizeof(*channels) * num_channels, > @@ -1322,9 +1331,9 @@ static int xadc_probe(struct platform_device *pdev) > if (!id) > return -EINVAL; > > - irq = platform_get_irq(pdev, 0); > - if (irq <= 0) > - return -ENXIO; > + irq = platform_get_irq_optional(pdev, 0); > + if (irq < 0 && irq != -ENXIO) > + return irq; > > indio_dev = devm_iio_device_alloc(dev, sizeof(*xadc)); > if (!indio_dev) > @@ -1345,11 +1354,11 @@ static int xadc_probe(struct platform_device *pdev) > indio_dev->modes = INDIO_DIRECT_MODE; > indio_dev->info = &xadc_info; > > - ret = xadc_parse_dt(indio_dev, dev->of_node, &conf0); > + ret = xadc_parse_dt(indio_dev, dev->of_node, &conf0, irq); > if (ret) > return ret; > > - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { > + if (irq > 0 && (xadc->ops->flags & XADC_FLAGS_BUFFERED)) { > ret = devm_iio_triggered_buffer_setup(dev, indio_dev, > &iio_pollfunc_store_time, > &xadc_trigger_handler, > @@ -1396,15 +1405,17 @@ static int xadc_probe(struct platform_device *pdev) > } > } > > - ret = devm_request_irq(dev, irq, xadc->ops->interrupt_handler, 0, > - dev_name(dev), indio_dev); > - if (ret) > - return ret; > + if (irq > 0) { > + ret = devm_request_irq(dev, irq, xadc->ops->interrupt_handler, > + 0, dev_name(dev), indio_dev); > + if (ret) > + return ret; > > - ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work, > - &xadc->zynq_unmask_work); > - if (ret) > - return ret; > + ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work, > + &xadc->zynq_unmask_work); > + if (ret) > + return ret; > + } > > ret = xadc->ops->setup(pdev, indio_dev, irq); > if (ret)
On 4/25/21 5:25 PM, Jonathan Cameron wrote: > On Sun, 25 Apr 2021 12:26:38 +0200 > Lars-Peter Clausen <lars@metafoo.de> wrote: > >> In some setups the IRQ signal of the XADC might not be wired to the host >> system. The driver currently requires that an interrupt is specified. Make >> the interrupt optional so the driver can be used in such setups where the >> interrupt is not connected. >> >> Since both buffered capture as well as events depend on the interrupt being >> connected both are not available when the interrupt is not connected. >> >> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> > Code looks fine to me but raises a question. As there is no validate_trigger > callback in this driver, nothing stops it being associated with for example > an hrtimer trigger. I don't think that will work so perhaps we should add the > callback? If it does work, then the presence or not of an irq should not > change whether we register the buffer. This is a good point. But the driver can actually work with a hrtimer trigger. You'd get aliasing problems and all that stuff, but if you only care about the instantaneous values it will work. Without an IRQ we should only mask out the events and not register the triggers. Registering the buffer should be fine. - Lars
diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c index dd1c92b2811f..ffefb01a3893 100644 --- a/drivers/iio/adc/xilinx-xadc-core.c +++ b/drivers/iio/adc/xilinx-xadc-core.c @@ -1182,7 +1182,7 @@ static const struct of_device_id xadc_of_match_table[] = { MODULE_DEVICE_TABLE(of, xadc_of_match_table); static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, - unsigned int *conf) + unsigned int *conf, int irq) { struct device *dev = indio_dev->dev.parent; struct xadc *xadc = iio_priv(indio_dev); @@ -1195,6 +1195,7 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, u32 ext_mux_chan; u32 reg; int ret; + int i; *conf = 0; @@ -1273,6 +1274,14 @@ static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, } of_node_put(chan_node); + /* No IRQ => no events */ + if (irq <= 0) { + for (i = 0; i < num_channels; i++) { + channels[i].event_spec = NULL; + channels[i].num_event_specs = 0; + } + } + indio_dev->num_channels = num_channels; indio_dev->channels = devm_krealloc(dev, channels, sizeof(*channels) * num_channels, @@ -1322,9 +1331,9 @@ static int xadc_probe(struct platform_device *pdev) if (!id) return -EINVAL; - irq = platform_get_irq(pdev, 0); - if (irq <= 0) - return -ENXIO; + irq = platform_get_irq_optional(pdev, 0); + if (irq < 0 && irq != -ENXIO) + return irq; indio_dev = devm_iio_device_alloc(dev, sizeof(*xadc)); if (!indio_dev) @@ -1345,11 +1354,11 @@ static int xadc_probe(struct platform_device *pdev) indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &xadc_info; - ret = xadc_parse_dt(indio_dev, dev->of_node, &conf0); + ret = xadc_parse_dt(indio_dev, dev->of_node, &conf0, irq); if (ret) return ret; - if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { + if (irq > 0 && (xadc->ops->flags & XADC_FLAGS_BUFFERED)) { ret = devm_iio_triggered_buffer_setup(dev, indio_dev, &iio_pollfunc_store_time, &xadc_trigger_handler, @@ -1396,15 +1405,17 @@ static int xadc_probe(struct platform_device *pdev) } } - ret = devm_request_irq(dev, irq, xadc->ops->interrupt_handler, 0, - dev_name(dev), indio_dev); - if (ret) - return ret; + if (irq > 0) { + ret = devm_request_irq(dev, irq, xadc->ops->interrupt_handler, + 0, dev_name(dev), indio_dev); + if (ret) + return ret; - ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work, - &xadc->zynq_unmask_work); - if (ret) - return ret; + ret = devm_add_action_or_reset(dev, xadc_cancel_delayed_work, + &xadc->zynq_unmask_work); + if (ret) + return ret; + } ret = xadc->ops->setup(pdev, indio_dev, irq); if (ret)
In some setups the IRQ signal of the XADC might not be wired to the host system. The driver currently requires that an interrupt is specified. Make the interrupt optional so the driver can be used in such setups where the interrupt is not connected. Since both buffered capture as well as events depend on the interrupt being connected both are not available when the interrupt is not connected. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> --- drivers/iio/adc/xilinx-xadc-core.c | 39 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-)