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

staging:iio:light:isl29018: Convert some of the isl29018 driver to the new iio_chan_spec framework.

Remove the driver's get_sensor_data() interfaces and replace them with
iio_chan_spec channels. This converts 4 files to the new framework.
Driver ABI change: The intensity_infrared_raw file is now intensity_ir_raw.

Signed-off-by: Bryan Freed <bfreed@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Bryan Freed and committed by
Greg Kroah-Hartman
01e57c57 f09f2c81

+78 -90
+78 -90
drivers/staging/iio/light/isl29018.c
··· 224 224 return 0; 225 225 } 226 226 227 - static ssize_t get_sensor_data(struct device *dev, char *buf, int mode) 228 - { 229 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 230 - struct isl29018_chip *chip = iio_priv(indio_dev); 231 - struct i2c_client *client = chip->client; 232 - int value = 0; 233 - int status; 234 - 235 - mutex_lock(&chip->lock); 236 - switch (mode) { 237 - case COMMMAND1_OPMODE_PROX_ONCE: 238 - status = isl29018_read_proximity_ir(client, 239 - chip->prox_scheme, &value); 240 - break; 241 - 242 - case COMMMAND1_OPMODE_ALS_ONCE: 243 - status = isl29018_read_lux(client, &value); 244 - break; 245 - 246 - case COMMMAND1_OPMODE_IR_ONCE: 247 - status = isl29018_read_ir(client, &value); 248 - break; 249 - 250 - default: 251 - dev_err(&client->dev, "Mode %d is not supported\n", mode); 252 - mutex_unlock(&chip->lock); 253 - return -EBUSY; 254 - } 255 - if (status < 0) { 256 - dev_err(&client->dev, "Error in Reading data"); 257 - mutex_unlock(&chip->lock); 258 - return status; 259 - } 260 - 261 - mutex_unlock(&chip->lock); 262 - 263 - return sprintf(buf, "%d\n", value); 264 - } 265 - 266 227 /* Sysfs interface */ 267 - /* lux_scale */ 268 - static ssize_t show_lux_scale(struct device *dev, 269 - struct device_attribute *attr, char *buf) 270 - { 271 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 272 - struct isl29018_chip *chip = indio_dev->dev_data; 273 - 274 - return sprintf(buf, "%d\n", chip->lux_scale); 275 - } 276 - 277 - static ssize_t store_lux_scale(struct device *dev, 278 - struct device_attribute *attr, const char *buf, size_t count) 279 - { 280 - struct iio_dev *indio_dev = dev_get_drvdata(dev); 281 - struct isl29018_chip *chip = indio_dev->dev_data; 282 - unsigned long lval; 283 - 284 - lval = simple_strtoul(buf, NULL, 10); 285 - if (lval == 0) 286 - return -EINVAL; 287 - 288 - mutex_lock(&chip->lock); 289 - chip->lux_scale = lval; 290 - mutex_unlock(&chip->lock); 291 - 292 - return count; 293 - } 294 - 295 228 /* range */ 296 229 static ssize_t show_range(struct device *dev, 297 230 struct device_attribute *attr, char *buf) ··· 342 409 return count; 343 410 } 344 411 345 - /* Read lux */ 346 - static ssize_t show_lux(struct device *dev, 347 - struct device_attribute *devattr, char *buf) 412 + /* Channel IO */ 413 + static int isl29018_write_raw(struct iio_dev *indio_dev, 414 + struct iio_chan_spec const *chan, 415 + int val, 416 + int val2, 417 + long mask) 348 418 { 349 - return get_sensor_data(dev, buf, COMMMAND1_OPMODE_ALS_ONCE); 419 + struct isl29018_chip *chip = iio_priv(indio_dev); 420 + int ret = -EINVAL; 421 + 422 + mutex_lock(&chip->lock); 423 + if (mask == (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE) && 424 + chan->type == IIO_LIGHT) { 425 + chip->lux_scale = val; 426 + ret = 0; 427 + } 428 + mutex_unlock(&chip->lock); 429 + 430 + return 0; 350 431 } 351 432 352 - /* Read ir */ 353 - static ssize_t show_ir(struct device *dev, 354 - struct device_attribute *devattr, char *buf) 433 + static int isl29018_read_raw(struct iio_dev *indio_dev, 434 + struct iio_chan_spec const *chan, 435 + int *val, 436 + int *val2, 437 + long mask) 355 438 { 356 - return get_sensor_data(dev, buf, COMMMAND1_OPMODE_IR_ONCE); 439 + int ret = -EINVAL; 440 + struct isl29018_chip *chip = iio_priv(indio_dev); 441 + struct i2c_client *client = chip->client; 442 + 443 + mutex_lock(&chip->lock); 444 + switch (mask) { 445 + case 0: 446 + switch (chan->type) { 447 + case IIO_LIGHT: 448 + ret = isl29018_read_lux(client, val); 449 + break; 450 + case IIO_INTENSITY: 451 + ret = isl29018_read_ir(client, val); 452 + break; 453 + case IIO_PROXIMITY: 454 + ret = isl29018_read_proximity_ir(client, 455 + chip->prox_scheme, val); 456 + break; 457 + default: 458 + break; 459 + } 460 + if (!ret) 461 + ret = IIO_VAL_INT; 462 + break; 463 + case (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE): 464 + if (chan->type == IIO_LIGHT) { 465 + *val = chip->lux_scale; 466 + ret = IIO_VAL_INT; 467 + } 468 + break; 469 + default: 470 + break; 471 + } 472 + mutex_unlock(&chip->lock); 473 + return ret; 357 474 } 358 475 359 - /* Read nearest ir */ 360 - static ssize_t show_proxim_ir(struct device *dev, 361 - struct device_attribute *devattr, char *buf) 362 - { 363 - return get_sensor_data(dev, buf, COMMMAND1_OPMODE_PROX_ONCE); 364 - } 476 + static const struct iio_chan_spec isl29018_channels[] = { 477 + { 478 + .type = IIO_LIGHT, 479 + .indexed = 1, 480 + .channel = 0, 481 + .processed_val = 1, 482 + .info_mask = (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE), 483 + }, { 484 + .type = IIO_INTENSITY, 485 + .modified = 1, 486 + .channel2 = IIO_MOD_LIGHT_IR, 487 + }, { 488 + /* Unindexed in current ABI. But perhaps it should be. */ 489 + .type = IIO_PROXIMITY, 490 + } 491 + }; 365 492 366 493 static IIO_DEVICE_ATTR(range, S_IRUGO | S_IWUSR, show_range, store_range, 0); 367 494 static IIO_CONST_ATTR(range_available, "1000 4000 16000 64000"); ··· 432 439 S_IRUGO | S_IWUSR, 433 440 show_prox_infrared_supression, 434 441 store_prox_infrared_supression, 0); 435 - static IIO_DEVICE_ATTR(illuminance0_input, S_IRUGO, show_lux, NULL, 0); 436 - static IIO_DEVICE_ATTR(illuminance0_calibscale, S_IRUGO | S_IWUSR, 437 - show_lux_scale, store_lux_scale, 0); 438 - static IIO_DEVICE_ATTR(intensity_infrared_raw, S_IRUGO, show_ir, NULL, 0); 439 - static IIO_DEVICE_ATTR(proximity_raw, S_IRUGO, show_proxim_ir, NULL, 0); 440 442 441 443 #define ISL29018_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr) 442 444 #define ISL29018_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr) ··· 441 453 ISL29018_DEV_ATTR(adc_resolution), 442 454 ISL29018_CONST_ATTR(adc_resolution_available), 443 455 ISL29018_DEV_ATTR(proximity_on_chip_ambient_infrared_supression), 444 - ISL29018_DEV_ATTR(illuminance0_input), 445 - ISL29018_DEV_ATTR(illuminance0_calibscale), 446 - ISL29018_DEV_ATTR(intensity_infrared_raw), 447 - ISL29018_DEV_ATTR(proximity_raw), 448 456 NULL 449 457 }; 450 458 ··· 473 489 static const struct iio_info isl29108_info = { 474 490 .attrs = &isl29108_group, 475 491 .driver_module = THIS_MODULE, 492 + .read_raw = &isl29018_read_raw, 493 + .write_raw = &isl29018_write_raw, 476 494 }; 477 495 478 496 static int __devinit isl29018_probe(struct i2c_client *client, ··· 506 520 goto exit_iio_free; 507 521 508 522 indio_dev->info = &isl29108_info; 523 + indio_dev->channels = isl29018_channels; 524 + indio_dev->num_channels = ARRAY_SIZE(isl29018_channels); 509 525 indio_dev->name = id->name; 510 526 indio_dev->dev.parent = &client->dev; 511 527 indio_dev->modes = INDIO_DIRECT_MODE;