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

staging: iio: tsl2x7x: refactor {read,write}_event_value to allow handling multiple iio_event_infos

tsl2x7x_read_thresh() and tsl2x7x_write_thresh() currently assumes
that IIO_EV_INFO_VALUE is the only iio_event_info that will be
passed in. This patch refactors these two functions so that
additional iio_event_infos can be passed in. The functions are
renamed from tsl2x7x_{read,write}_thresh() to
tsl2x7x_{read,write}_event_value(). This patch also adds the
missing return value check to tsl2x7x_invoke_change() since this
was previously missing. This patch is in preparation for moving
the in_intensity0_thresh_period and in_proximity0_thresh_period sysfs
attributes to be created by iio_event_spec.

Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Brian Masney and committed by
Jonathan Cameron
be78f70c 1b4cbe2e

+90 -67
+90 -67
drivers/staging/iio/light/tsl2x7x.c
··· 1218 1218 return 0; 1219 1219 } 1220 1220 1221 - static int tsl2x7x_write_thresh(struct iio_dev *indio_dev, 1222 - const struct iio_chan_spec *chan, 1223 - enum iio_event_type type, 1224 - enum iio_event_direction dir, 1225 - enum iio_event_info info, 1226 - int val, int val2) 1221 + static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, 1222 + const struct iio_chan_spec *chan, 1223 + enum iio_event_type type, 1224 + enum iio_event_direction dir, 1225 + enum iio_event_info info, 1226 + int val, int val2) 1227 1227 { 1228 1228 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1229 + int ret = -EINVAL; 1229 1230 1230 - if (chan->type == IIO_INTENSITY) { 1231 - switch (dir) { 1232 - case IIO_EV_DIR_RISING: 1233 - chip->tsl2x7x_settings.als_thresh_high = val; 1234 - break; 1235 - case IIO_EV_DIR_FALLING: 1236 - chip->tsl2x7x_settings.als_thresh_low = val; 1237 - break; 1238 - default: 1239 - return -EINVAL; 1231 + switch (info) { 1232 + case IIO_EV_INFO_VALUE: 1233 + if (chan->type == IIO_INTENSITY) { 1234 + switch (dir) { 1235 + case IIO_EV_DIR_RISING: 1236 + chip->tsl2x7x_settings.als_thresh_high = val; 1237 + ret = 0; 1238 + break; 1239 + case IIO_EV_DIR_FALLING: 1240 + chip->tsl2x7x_settings.als_thresh_low = val; 1241 + ret = 0; 1242 + break; 1243 + default: 1244 + break; 1245 + } 1246 + } else { 1247 + switch (dir) { 1248 + case IIO_EV_DIR_RISING: 1249 + chip->tsl2x7x_settings.prox_thres_high = val; 1250 + ret = 0; 1251 + break; 1252 + case IIO_EV_DIR_FALLING: 1253 + chip->tsl2x7x_settings.prox_thres_low = val; 1254 + ret = 0; 1255 + break; 1256 + default: 1257 + break; 1258 + } 1240 1259 } 1241 - } else { 1242 - switch (dir) { 1243 - case IIO_EV_DIR_RISING: 1244 - chip->tsl2x7x_settings.prox_thres_high = val; 1245 - break; 1246 - case IIO_EV_DIR_FALLING: 1247 - chip->tsl2x7x_settings.prox_thres_low = val; 1248 - break; 1249 - default: 1250 - return -EINVAL; 1251 - } 1260 + break; 1261 + default: 1262 + break; 1252 1263 } 1253 1264 1254 - tsl2x7x_invoke_change(indio_dev); 1265 + if (ret < 0) 1266 + return ret; 1255 1267 1256 - return 0; 1268 + return tsl2x7x_invoke_change(indio_dev); 1257 1269 } 1258 1270 1259 - static int tsl2x7x_read_thresh(struct iio_dev *indio_dev, 1260 - const struct iio_chan_spec *chan, 1261 - enum iio_event_type type, 1262 - enum iio_event_direction dir, 1263 - enum iio_event_info info, 1264 - int *val, int *val2) 1271 + static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, 1272 + const struct iio_chan_spec *chan, 1273 + enum iio_event_type type, 1274 + enum iio_event_direction dir, 1275 + enum iio_event_info info, 1276 + int *val, int *val2) 1265 1277 { 1266 1278 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1279 + int ret = -EINVAL; 1267 1280 1268 - if (chan->type == IIO_INTENSITY) { 1269 - switch (dir) { 1270 - case IIO_EV_DIR_RISING: 1271 - *val = chip->tsl2x7x_settings.als_thresh_high; 1272 - break; 1273 - case IIO_EV_DIR_FALLING: 1274 - *val = chip->tsl2x7x_settings.als_thresh_low; 1275 - break; 1276 - default: 1277 - return -EINVAL; 1281 + switch (info) { 1282 + case IIO_EV_INFO_VALUE: 1283 + if (chan->type == IIO_INTENSITY) { 1284 + switch (dir) { 1285 + case IIO_EV_DIR_RISING: 1286 + *val = chip->tsl2x7x_settings.als_thresh_high; 1287 + ret = IIO_VAL_INT; 1288 + break; 1289 + case IIO_EV_DIR_FALLING: 1290 + *val = chip->tsl2x7x_settings.als_thresh_low; 1291 + ret = IIO_VAL_INT; 1292 + break; 1293 + default: 1294 + break; 1295 + } 1296 + } else { 1297 + switch (dir) { 1298 + case IIO_EV_DIR_RISING: 1299 + *val = chip->tsl2x7x_settings.prox_thres_high; 1300 + ret = IIO_VAL_INT; 1301 + break; 1302 + case IIO_EV_DIR_FALLING: 1303 + *val = chip->tsl2x7x_settings.prox_thres_low; 1304 + ret = IIO_VAL_INT; 1305 + break; 1306 + default: 1307 + break; 1308 + } 1278 1309 } 1279 - } else { 1280 - switch (dir) { 1281 - case IIO_EV_DIR_RISING: 1282 - *val = chip->tsl2x7x_settings.prox_thres_high; 1283 - break; 1284 - case IIO_EV_DIR_FALLING: 1285 - *val = chip->tsl2x7x_settings.prox_thres_low; 1286 - break; 1287 - default: 1288 - return -EINVAL; 1289 - } 1310 + break; 1311 + default: 1312 + break; 1290 1313 } 1291 1314 1292 - return IIO_VAL_INT; 1315 + return ret; 1293 1316 } 1294 1317 1295 1318 static int tsl2x7x_read_raw(struct iio_dev *indio_dev, ··· 1637 1614 .driver_module = THIS_MODULE, 1638 1615 .read_raw = &tsl2x7x_read_raw, 1639 1616 .write_raw = &tsl2x7x_write_raw, 1640 - .read_event_value = &tsl2x7x_read_thresh, 1641 - .write_event_value = &tsl2x7x_write_thresh, 1617 + .read_event_value = &tsl2x7x_read_event_value, 1618 + .write_event_value = &tsl2x7x_write_event_value, 1642 1619 .read_event_config = &tsl2x7x_read_interrupt_config, 1643 1620 .write_event_config = &tsl2x7x_write_interrupt_config, 1644 1621 }, ··· 1648 1625 .driver_module = THIS_MODULE, 1649 1626 .read_raw = &tsl2x7x_read_raw, 1650 1627 .write_raw = &tsl2x7x_write_raw, 1651 - .read_event_value = &tsl2x7x_read_thresh, 1652 - .write_event_value = &tsl2x7x_write_thresh, 1628 + .read_event_value = &tsl2x7x_read_event_value, 1629 + .write_event_value = &tsl2x7x_write_event_value, 1653 1630 .read_event_config = &tsl2x7x_read_interrupt_config, 1654 1631 .write_event_config = &tsl2x7x_write_interrupt_config, 1655 1632 }, ··· 1659 1636 .driver_module = THIS_MODULE, 1660 1637 .read_raw = &tsl2x7x_read_raw, 1661 1638 .write_raw = &tsl2x7x_write_raw, 1662 - .read_event_value = &tsl2x7x_read_thresh, 1663 - .write_event_value = &tsl2x7x_write_thresh, 1639 + .read_event_value = &tsl2x7x_read_event_value, 1640 + .write_event_value = &tsl2x7x_write_event_value, 1664 1641 .read_event_config = &tsl2x7x_read_interrupt_config, 1665 1642 .write_event_config = &tsl2x7x_write_interrupt_config, 1666 1643 }, ··· 1670 1647 .driver_module = THIS_MODULE, 1671 1648 .read_raw = &tsl2x7x_read_raw, 1672 1649 .write_raw = &tsl2x7x_write_raw, 1673 - .read_event_value = &tsl2x7x_read_thresh, 1674 - .write_event_value = &tsl2x7x_write_thresh, 1650 + .read_event_value = &tsl2x7x_read_event_value, 1651 + .write_event_value = &tsl2x7x_write_event_value, 1675 1652 .read_event_config = &tsl2x7x_read_interrupt_config, 1676 1653 .write_event_config = &tsl2x7x_write_interrupt_config, 1677 1654 }, ··· 1681 1658 .driver_module = THIS_MODULE, 1682 1659 .read_raw = &tsl2x7x_read_raw, 1683 1660 .write_raw = &tsl2x7x_write_raw, 1684 - .read_event_value = &tsl2x7x_read_thresh, 1685 - .write_event_value = &tsl2x7x_write_thresh, 1661 + .read_event_value = &tsl2x7x_read_event_value, 1662 + .write_event_value = &tsl2x7x_write_event_value, 1686 1663 .read_event_config = &tsl2x7x_read_interrupt_config, 1687 1664 .write_event_config = &tsl2x7x_write_interrupt_config, 1688 1665 },