Lines Matching +full:0 +full:- +full:indexed
1 // SPDX-License-Identifier: GPL-2.0-only
31 * struct iio_dummy_accel_calibscale - realworld to register mapping
32 * @val: first value in read_raw - here integer part.
33 * @val2: second value in read_raw etc - here micro part.
34 * @regval: register value - magic device specific numbers.
43 { 0, 100, 0x8 }, /* 0.000100 */
44 { 0, 133, 0x7 }, /* 0.000133 */
45 { 733, 13, 0x9 }, /* 733.000013 */
51 * simple event - triggered when value rises above
61 * simple step detect event - triggered when a step is detected
70 * simple transition event - triggered when the reported running confidence
80 * simple transition event - triggered when the reported walking confidence
91 * iio_dummy_channels - Description of available channels
97 /* indexed ADC channel in_voltage0_raw etc */
100 /* Channel has a numeric index of 0 */
101 .indexed = 1,
102 .channel = 0,
134 .shift = 0, /* zero shift */
141 /* Differential ADC channel in_voltage1-voltage2_raw etc*/
149 .indexed = 1,
153 * in_voltage1-voltage2_raw
159 * in_voltage-voltage_scale
160 * Shared version of scale - shared by differential
173 .shift = 0, /* zero shift */
176 /* Differential ADC channel in_voltage3-voltage4_raw etc*/
180 .indexed = 1,
191 .shift = 0,
218 .shift = 0, /* zero shift */
230 .scan_index = -1, /* No buffer support */
232 .indexed = 1,
233 .channel = 0,
240 .scan_index = -1, /* No buffer support */
251 .scan_index = -1, /* No buffer support */
262 .scan_index = -1, /* No buffer support */
271 * iio_dummy_read_raw() - data read function.
288 case IIO_CHAN_INFO_RAW: /* magic value - channel value read */ in iio_dummy_read_raw()
289 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { in iio_dummy_read_raw()
290 guard(mutex)(&st->lock); in iio_dummy_read_raw()
291 switch (chan->type) { in iio_dummy_read_raw()
293 if (chan->output) { in iio_dummy_read_raw()
295 *val = st->dac_val; in iio_dummy_read_raw()
297 } else if (chan->differential) { in iio_dummy_read_raw()
298 if (chan->channel == 1) in iio_dummy_read_raw()
299 *val = st->differential_adc_val[0]; in iio_dummy_read_raw()
301 *val = st->differential_adc_val[1]; in iio_dummy_read_raw()
304 *val = st->single_ended_adc_val; in iio_dummy_read_raw()
309 *val = st->accel_val; in iio_dummy_read_raw()
312 return -EINVAL; in iio_dummy_read_raw()
317 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { in iio_dummy_read_raw()
318 guard(mutex)(&st->lock); in iio_dummy_read_raw()
319 switch (chan->type) { in iio_dummy_read_raw()
321 *val = st->steps; in iio_dummy_read_raw()
324 switch (chan->channel2) { in iio_dummy_read_raw()
326 *val = st->activity_running; in iio_dummy_read_raw()
329 *val = st->activity_walking; in iio_dummy_read_raw()
332 return -EINVAL; in iio_dummy_read_raw()
335 return -EINVAL; in iio_dummy_read_raw()
340 /* only single ended adc -> 7 */ in iio_dummy_read_raw()
344 switch (chan->type) { in iio_dummy_read_raw()
346 switch (chan->differential) { in iio_dummy_read_raw()
347 case 0: in iio_dummy_read_raw()
348 /* only single ended adc -> 0.001333 */ in iio_dummy_read_raw()
349 *val = 0; in iio_dummy_read_raw()
353 /* all differential adc -> 0.000001344 */ in iio_dummy_read_raw()
354 *val = 0; in iio_dummy_read_raw()
358 return -EINVAL; in iio_dummy_read_raw()
361 return -EINVAL; in iio_dummy_read_raw()
364 guard(mutex)(&st->lock); in iio_dummy_read_raw()
365 /* only the acceleration axis - read from cache */ in iio_dummy_read_raw()
366 *val = st->accel_calibbias; in iio_dummy_read_raw()
370 guard(mutex)(&st->lock); in iio_dummy_read_raw()
371 *val = st->accel_calibscale->val; in iio_dummy_read_raw()
372 *val2 = st->accel_calibscale->val2; in iio_dummy_read_raw()
380 guard(mutex)(&st->lock); in iio_dummy_read_raw()
381 switch (chan->type) { in iio_dummy_read_raw()
383 *val = st->steps_enabled; in iio_dummy_read_raw()
386 return -EINVAL; in iio_dummy_read_raw()
390 guard(mutex)(&st->lock); in iio_dummy_read_raw()
391 switch (chan->type) { in iio_dummy_read_raw()
393 *val = st->height; in iio_dummy_read_raw()
396 return -EINVAL; in iio_dummy_read_raw()
400 return -EINVAL; in iio_dummy_read_raw()
405 * iio_dummy_write_raw() - data write function.
428 switch (chan->type) { in iio_dummy_write_raw()
430 if (chan->output == 0) in iio_dummy_write_raw()
431 return -EINVAL; in iio_dummy_write_raw()
433 scoped_guard(mutex, &st->lock) { in iio_dummy_write_raw()
435 st->dac_val = val; in iio_dummy_write_raw()
437 return 0; in iio_dummy_write_raw()
439 return -EINVAL; in iio_dummy_write_raw()
442 switch (chan->type) { in iio_dummy_write_raw()
444 scoped_guard(mutex, &st->lock) { in iio_dummy_write_raw()
445 st->steps = val; in iio_dummy_write_raw()
447 return 0; in iio_dummy_write_raw()
449 if (val < 0) in iio_dummy_write_raw()
450 val = 0; in iio_dummy_write_raw()
453 switch (chan->channel2) { in iio_dummy_write_raw()
455 st->activity_running = val; in iio_dummy_write_raw()
456 return 0; in iio_dummy_write_raw()
458 st->activity_walking = val; in iio_dummy_write_raw()
459 return 0; in iio_dummy_write_raw()
461 return -EINVAL; in iio_dummy_write_raw()
465 return -EINVAL; in iio_dummy_write_raw()
468 guard(mutex)(&st->lock); in iio_dummy_write_raw()
469 /* Compare against table - hard matching here */ in iio_dummy_write_raw()
470 for (i = 0; i < ARRAY_SIZE(dummy_scales); i++) in iio_dummy_write_raw()
475 return -EINVAL; in iio_dummy_write_raw()
476 st->accel_calibscale = &dummy_scales[i]; in iio_dummy_write_raw()
477 return 0; in iio_dummy_write_raw()
480 scoped_guard(mutex, &st->lock) { in iio_dummy_write_raw()
481 st->accel_calibbias = val; in iio_dummy_write_raw()
483 return 0; in iio_dummy_write_raw()
485 switch (chan->type) { in iio_dummy_write_raw()
487 scoped_guard(mutex, &st->lock) { in iio_dummy_write_raw()
488 st->steps_enabled = val; in iio_dummy_write_raw()
490 return 0; in iio_dummy_write_raw()
492 return -EINVAL; in iio_dummy_write_raw()
495 switch (chan->type) { in iio_dummy_write_raw()
497 st->height = val; in iio_dummy_write_raw()
498 return 0; in iio_dummy_write_raw()
500 return -EINVAL; in iio_dummy_write_raw()
504 return -EINVAL; in iio_dummy_write_raw()
523 * iio_dummy_init_device() - device instance specific init
533 st->dac_val = 0; in iio_dummy_init_device()
534 st->single_ended_adc_val = 73; in iio_dummy_init_device()
535 st->differential_adc_val[0] = 33; in iio_dummy_init_device()
536 st->differential_adc_val[1] = -34; in iio_dummy_init_device()
537 st->accel_val = 34; in iio_dummy_init_device()
538 st->accel_calibbias = -7; in iio_dummy_init_device()
539 st->accel_calibscale = &dummy_scales[0]; in iio_dummy_init_device()
540 st->steps = 47; in iio_dummy_init_device()
541 st->activity_running = 98; in iio_dummy_init_device()
542 st->activity_walking = 4; in iio_dummy_init_device()
544 return 0; in iio_dummy_init_device()
548 * iio_dummy_probe() - device instance probe
566 * parent = &spi->dev; in iio_dummy_probe()
567 * parent = &client->dev; in iio_dummy_probe()
572 return ERR_PTR(-ENOMEM); in iio_dummy_probe()
584 ret = -ENOMEM; in iio_dummy_probe()
589 mutex_init(&st->lock); in iio_dummy_probe()
599 swd->device = indio_dev; in iio_dummy_probe()
607 * indio_dev->name = id->name; in iio_dummy_probe()
608 * indio_dev->name = spi_get_device_id(spi)->name; in iio_dummy_probe()
610 indio_dev->name = kstrdup(name, GFP_KERNEL); in iio_dummy_probe()
611 if (!indio_dev->name) { in iio_dummy_probe()
612 ret = -ENOMEM; in iio_dummy_probe()
617 indio_dev->channels = iio_dummy_channels; in iio_dummy_probe()
618 indio_dev->num_channels = ARRAY_SIZE(iio_dummy_channels); in iio_dummy_probe()
624 indio_dev->info = &iio_dummy_info; in iio_dummy_probe()
627 indio_dev->modes = INDIO_DIRECT_MODE; in iio_dummy_probe()
630 if (ret < 0) in iio_dummy_probe()
634 if (ret < 0) in iio_dummy_probe()
638 if (ret < 0) in iio_dummy_probe()
649 kfree(indio_dev->name); in iio_dummy_probe()
658 * iio_dummy_remove() - device instance removal function
671 struct iio_dev *indio_dev = swd->device; in iio_dummy_remove()
684 kfree(indio_dev->name); in iio_dummy_remove()
687 return 0; in iio_dummy_remove()
691 * module_iio_sw_device_driver() - device driver registration
696 * Documentation/i2c/writing-clients.rst
698 * Documentation/spi/spi-summary.rst