aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorBryan Freed <bfreed@chromium.org>2011-07-07 15:01:56 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-07-08 17:11:49 -0400
commit01e57c5742fcd4d08eddab59ef1c3b3e1f60610c (patch)
tree9ae988427d3f65901d561124cd0b66a77b26fa24 /drivers/staging
parentf09f2c8142d275b0d9321d2ea93c8bd0d8dc32ec (diff)
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>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/iio/light/isl29018.c168
1 files changed, 78 insertions, 90 deletions
diff --git a/drivers/staging/iio/light/isl29018.c b/drivers/staging/iio/light/isl29018.c
index 1e751459fbb..426b6af7080 100644
--- a/drivers/staging/iio/light/isl29018.c
+++ b/drivers/staging/iio/light/isl29018.c
@@ -224,74 +224,7 @@ static int isl29018_read_proximity_ir(struct i2c_client *client, int scheme,
224 return 0; 224 return 0;
225} 225}
226 226
227static 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/* Sysfs interface */ 227/* Sysfs interface */
267/* lux_scale */
268static 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
277static 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/* range */ 228/* range */
296static ssize_t show_range(struct device *dev, 229static ssize_t show_range(struct device *dev,
297 struct device_attribute *attr, char *buf) 230 struct device_attribute *attr, char *buf)
@@ -409,27 +342,87 @@ static ssize_t store_prox_infrared_supression(struct device *dev,
409 return count; 342 return count;
410} 343}
411 344
412/* Read lux */ 345/* Channel IO */
413static ssize_t show_lux(struct device *dev, 346static int isl29018_write_raw(struct iio_dev *indio_dev,
414 struct device_attribute *devattr, char *buf) 347 struct iio_chan_spec const *chan,
348 int val,
349 int val2,
350 long mask)
415{ 351{
416 return get_sensor_data(dev, buf, COMMMAND1_OPMODE_ALS_ONCE); 352 struct isl29018_chip *chip = iio_priv(indio_dev);
417} 353 int ret = -EINVAL;
418 354
419/* Read ir */ 355 mutex_lock(&chip->lock);
420static ssize_t show_ir(struct device *dev, 356 if (mask == (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE) &&
421 struct device_attribute *devattr, char *buf) 357 chan->type == IIO_LIGHT) {
422{ 358 chip->lux_scale = val;
423 return get_sensor_data(dev, buf, COMMMAND1_OPMODE_IR_ONCE); 359 ret = 0;
360 }
361 mutex_unlock(&chip->lock);
362
363 return 0;
424} 364}
425 365
426/* Read nearest ir */ 366static int isl29018_read_raw(struct iio_dev *indio_dev,
427static ssize_t show_proxim_ir(struct device *dev, 367 struct iio_chan_spec const *chan,
428 struct device_attribute *devattr, char *buf) 368 int *val,
369 int *val2,
370 long mask)
429{ 371{
430 return get_sensor_data(dev, buf, COMMMAND1_OPMODE_PROX_ONCE); 372 int ret = -EINVAL;
373 struct isl29018_chip *chip = iio_priv(indio_dev);
374 struct i2c_client *client = chip->client;
375
376 mutex_lock(&chip->lock);
377 switch (mask) {
378 case 0:
379 switch (chan->type) {
380 case IIO_LIGHT:
381 ret = isl29018_read_lux(client, val);
382 break;
383 case IIO_INTENSITY:
384 ret = isl29018_read_ir(client, val);
385 break;
386 case IIO_PROXIMITY:
387 ret = isl29018_read_proximity_ir(client,
388 chip->prox_scheme, val);
389 break;
390 default:
391 break;
392 }
393 if (!ret)
394 ret = IIO_VAL_INT;
395 break;
396 case (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE):
397 if (chan->type == IIO_LIGHT) {
398 *val = chip->lux_scale;
399 ret = IIO_VAL_INT;
400 }
401 break;
402 default:
403 break;
404 }
405 mutex_unlock(&chip->lock);
406 return ret;
431} 407}
432 408
409static const struct iio_chan_spec isl29018_channels[] = {
410 {
411 .type = IIO_LIGHT,
412 .indexed = 1,
413 .channel = 0,
414 .processed_val = 1,
415 .info_mask = (1 << IIO_CHAN_INFO_CALIBSCALE_SEPARATE),
416 }, {
417 .type = IIO_INTENSITY,
418 .modified = 1,
419 .channel2 = IIO_MOD_LIGHT_IR,
420 }, {
421 /* Unindexed in current ABI. But perhaps it should be. */
422 .type = IIO_PROXIMITY,
423 }
424};
425
433static IIO_DEVICE_ATTR(range, S_IRUGO | S_IWUSR, show_range, store_range, 0); 426static IIO_DEVICE_ATTR(range, S_IRUGO | S_IWUSR, show_range, store_range, 0);
434static IIO_CONST_ATTR(range_available, "1000 4000 16000 64000"); 427static IIO_CONST_ATTR(range_available, "1000 4000 16000 64000");
435static IIO_CONST_ATTR(adc_resolution_available, "4 8 12 16"); 428static IIO_CONST_ATTR(adc_resolution_available, "4 8 12 16");
@@ -439,11 +432,6 @@ static IIO_DEVICE_ATTR(proximity_on_chip_ambient_infrared_supression,
439 S_IRUGO | S_IWUSR, 432 S_IRUGO | S_IWUSR,
440 show_prox_infrared_supression, 433 show_prox_infrared_supression,
441 store_prox_infrared_supression, 0); 434 store_prox_infrared_supression, 0);
442static IIO_DEVICE_ATTR(illuminance0_input, S_IRUGO, show_lux, NULL, 0);
443static IIO_DEVICE_ATTR(illuminance0_calibscale, S_IRUGO | S_IWUSR,
444 show_lux_scale, store_lux_scale, 0);
445static IIO_DEVICE_ATTR(intensity_infrared_raw, S_IRUGO, show_ir, NULL, 0);
446static IIO_DEVICE_ATTR(proximity_raw, S_IRUGO, show_proxim_ir, NULL, 0);
447 435
448#define ISL29018_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr) 436#define ISL29018_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr)
449#define ISL29018_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr) 437#define ISL29018_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr)
@@ -453,10 +441,6 @@ static struct attribute *isl29018_attributes[] = {
453 ISL29018_DEV_ATTR(adc_resolution), 441 ISL29018_DEV_ATTR(adc_resolution),
454 ISL29018_CONST_ATTR(adc_resolution_available), 442 ISL29018_CONST_ATTR(adc_resolution_available),
455 ISL29018_DEV_ATTR(proximity_on_chip_ambient_infrared_supression), 443 ISL29018_DEV_ATTR(proximity_on_chip_ambient_infrared_supression),
456 ISL29018_DEV_ATTR(illuminance0_input),
457 ISL29018_DEV_ATTR(illuminance0_calibscale),
458 ISL29018_DEV_ATTR(intensity_infrared_raw),
459 ISL29018_DEV_ATTR(proximity_raw),
460 NULL 444 NULL
461}; 445};
462 446
@@ -489,6 +473,8 @@ static int isl29018_chip_init(struct i2c_client *client)
489static const struct iio_info isl29108_info = { 473static const struct iio_info isl29108_info = {
490 .attrs = &isl29108_group, 474 .attrs = &isl29108_group,
491 .driver_module = THIS_MODULE, 475 .driver_module = THIS_MODULE,
476 .read_raw = &isl29018_read_raw,
477 .write_raw = &isl29018_write_raw,
492}; 478};
493 479
494static int __devinit isl29018_probe(struct i2c_client *client, 480static int __devinit isl29018_probe(struct i2c_client *client,
@@ -520,6 +506,8 @@ static int __devinit isl29018_probe(struct i2c_client *client,
520 goto exit_iio_free; 506 goto exit_iio_free;
521 507
522 indio_dev->info = &isl29108_info; 508 indio_dev->info = &isl29108_info;
509 indio_dev->channels = isl29018_channels;
510 indio_dev->num_channels = ARRAY_SIZE(isl29018_channels);
523 indio_dev->name = id->name; 511 indio_dev->name = id->name;
524 indio_dev->dev.parent = &client->dev; 512 indio_dev->dev.parent = &client->dev;
525 indio_dev->modes = INDIO_DIRECT_MODE; 513 indio_dev->modes = INDIO_DIRECT_MODE;