Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: light: vcnl4000: Make irq handling more generic

This driver supports 4 chips, by which only one (vcnl4010) handles
interrupts and has support for triggered buffer. The setup of these
functions is hardcoded for vcnl4010 inside the generic vcnl4000_probe,
and thus ignores the chip specific configuration structure where all
other chip specific functions are specified.

This complicates adding interrupt handler and triggered buffer support
to chips which may have support for it.

Add members for irq threads and iio_buffer_setup_ops to the generic
vcnl4000_chip_spec struct, so that instead of checking a chip specific
boolean irq support, we check for a chip specific triggered buffer
handler, and/or a chip specific irq thread handler.

Signed-off-by: Mårten Lindahl <marten.lindahl@axis.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230117190017.3789181-3-marten.lindahl@axis.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Mårten Lindahl and committed by
Jonathan Cameron
bfb6cfee 3a52d32a

+14 -10
+14 -10
drivers/iio/light/vcnl4000.c
··· 150 150 struct iio_chan_spec const *channels; 151 151 const int num_channels; 152 152 const struct iio_info *info; 153 - bool irq_support; 153 + const struct iio_buffer_setup_ops *buffer_setup_ops; 154 154 int (*init)(struct vcnl4000_data *data); 155 155 int (*measure_light)(struct vcnl4000_data *data, int *val); 156 156 int (*measure_proximity)(struct vcnl4000_data *data, int *val); 157 157 int (*set_power_state)(struct vcnl4000_data *data, bool on); 158 + irqreturn_t (*irq_thread)(int irq, void *priv); 159 + irqreturn_t (*trig_buffer_func)(int irq, void *priv); 158 160 }; 159 161 160 162 static const struct i2c_device_id vcnl4000_id[] = { ··· 1123 1121 .channels = vcnl4000_channels, 1124 1122 .num_channels = ARRAY_SIZE(vcnl4000_channels), 1125 1123 .info = &vcnl4000_info, 1126 - .irq_support = false, 1127 1124 }, 1128 1125 [VCNL4010] = { 1129 1126 .prod = "VCNL4010/4020", ··· 1133 1132 .channels = vcnl4010_channels, 1134 1133 .num_channels = ARRAY_SIZE(vcnl4010_channels), 1135 1134 .info = &vcnl4010_info, 1136 - .irq_support = true, 1135 + .irq_thread = vcnl4010_irq_thread, 1136 + .trig_buffer_func = vcnl4010_trigger_handler, 1137 + .buffer_setup_ops = &vcnl4010_buffer_ops, 1137 1138 }, 1138 1139 [VCNL4040] = { 1139 1140 .prod = "VCNL4040", ··· 1146 1143 .channels = vcnl4040_channels, 1147 1144 .num_channels = ARRAY_SIZE(vcnl4040_channels), 1148 1145 .info = &vcnl4040_info, 1149 - .irq_support = false, 1150 1146 }, 1151 1147 [VCNL4200] = { 1152 1148 .prod = "VCNL4200", ··· 1156 1154 .channels = vcnl4000_channels, 1157 1155 .num_channels = ARRAY_SIZE(vcnl4000_channels), 1158 1156 .info = &vcnl4000_info, 1159 - .irq_support = false, 1160 1157 }, 1161 1158 }; 1162 1159 ··· 1215 1214 indio_dev->name = VCNL4000_DRV_NAME; 1216 1215 indio_dev->modes = INDIO_DIRECT_MODE; 1217 1216 1218 - if (client->irq && data->chip_spec->irq_support) { 1217 + if (data->chip_spec->trig_buffer_func && 1218 + data->chip_spec->buffer_setup_ops) { 1219 1219 ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, 1220 1220 NULL, 1221 - vcnl4010_trigger_handler, 1222 - &vcnl4010_buffer_ops); 1221 + data->chip_spec->trig_buffer_func, 1222 + data->chip_spec->buffer_setup_ops); 1223 1223 if (ret < 0) { 1224 1224 dev_err(&client->dev, 1225 1225 "unable to setup iio triggered buffer\n"); 1226 1226 return ret; 1227 1227 } 1228 + } 1228 1229 1230 + if (client->irq && data->chip_spec->irq_thread) { 1229 1231 ret = devm_request_threaded_irq(&client->dev, client->irq, 1230 - NULL, vcnl4010_irq_thread, 1232 + NULL, data->chip_spec->irq_thread, 1231 1233 IRQF_TRIGGER_FALLING | 1232 1234 IRQF_ONESHOT, 1233 - "vcnl4010_irq", 1235 + "vcnl4000_irq", 1234 1236 indio_dev); 1235 1237 if (ret < 0) { 1236 1238 dev_err(&client->dev, "irq request failed\n");