|
23 | 23 | * @sdata: Sensor data.
|
24 | 24 | *
|
25 | 25 | * returns:
|
26 |
| - * 0 - no new samples available |
27 |
| - * 1 - new samples available |
28 |
| - * negative - error or unknown |
| 26 | + * false - no new samples available or read error |
| 27 | + * true - new samples available |
29 | 28 | */
|
30 |
| -static int st_sensors_new_samples_available(struct iio_dev *indio_dev, |
31 |
| - struct st_sensor_data *sdata) |
| 29 | +static bool st_sensors_new_samples_available(struct iio_dev *indio_dev, |
| 30 | + struct st_sensor_data *sdata) |
32 | 31 | {
|
33 | 32 | int ret, status;
|
34 | 33 |
|
35 | 34 | /* How would I know if I can't check it? */
|
36 | 35 | if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr)
|
37 |
| - return -EINVAL; |
| 36 | + return true; |
38 | 37 |
|
39 | 38 | /* No scan mask, no interrupt */
|
40 | 39 | if (!indio_dev->active_scan_mask)
|
41 |
| - return 0; |
| 40 | + return false; |
42 | 41 |
|
43 | 42 | ret = regmap_read(sdata->regmap,
|
44 | 43 | sdata->sensor_settings->drdy_irq.stat_drdy.addr,
|
45 | 44 | &status);
|
46 | 45 | if (ret < 0) {
|
47 | 46 | dev_err(sdata->dev, "error checking samples available\n");
|
48 |
| - return ret; |
| 47 | + return false; |
49 | 48 | }
|
50 | 49 |
|
51 |
| - if (status & sdata->sensor_settings->drdy_irq.stat_drdy.mask) |
52 |
| - return 1; |
53 |
| - |
54 |
| - return 0; |
| 50 | + return !!(status & sdata->sensor_settings->drdy_irq.stat_drdy.mask); |
55 | 51 | }
|
56 | 52 |
|
57 | 53 | /**
|
@@ -180,16 +176,23 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
180 | 176 |
|
181 | 177 | /* Tell the interrupt handler that we're dealing with edges */
|
182 | 178 | if (irq_trig == IRQF_TRIGGER_FALLING ||
|
183 |
| - irq_trig == IRQF_TRIGGER_RISING) |
| 179 | + irq_trig == IRQF_TRIGGER_RISING) { |
| 180 | + if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr) { |
| 181 | + dev_err(&indio_dev->dev, |
| 182 | + "edge IRQ not supported w/o stat register.\n"); |
| 183 | + err = -EOPNOTSUPP; |
| 184 | + goto iio_trigger_free; |
| 185 | + } |
184 | 186 | sdata->edge_irq = true;
|
185 |
| - else |
| 187 | + } else { |
186 | 188 | /*
|
187 | 189 | * If we're not using edges (i.e. level interrupts) we
|
188 | 190 | * just mask off the IRQ, handle one interrupt, then
|
189 | 191 | * if the line is still low, we return to the
|
190 | 192 | * interrupt handler top half again and start over.
|
191 | 193 | */
|
192 | 194 | irq_trig |= IRQF_ONESHOT;
|
| 195 | + } |
193 | 196 |
|
194 | 197 | /*
|
195 | 198 | * If the interrupt pin is Open Drain, by definition this
|
|
0 commit comments