Lines Matching +full:integer +full:- +full:n

1 // SPDX-License-Identifier: GPL-2.0-only
3 * AFE4404 Heart Rate Monitors and Low-Cost Pulse Oximeters
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
79 * struct afe4404_data - AFE4404 device instance data
144 { .integer = 500000, .fract = 0 },
145 { .integer = 250000, .fract = 0 },
146 { .integer = 100000, .fract = 0 },
147 { .integer = 50000, .fract = 0 },
148 { .integer = 25000, .fract = 0 },
149 { .integer = 10000, .fract = 0 },
150 { .integer = 1000000, .fract = 0 },
151 { .integer = 2000000, .fract = 0 },
156 { .integer = 0, .fract = 5000 },
157 { .integer = 0, .fract = 2500 },
158 { .integer = 0, .fract = 10000 },
159 { .integer = 0, .fract = 7500 },
160 { .integer = 0, .fract = 20000 },
161 { .integer = 0, .fract = 17500 },
162 { .integer = 0, .fract = 25000 },
163 { .integer = 0, .fract = 22500 },
178 ret = regmap_field_read(afe->fields[afe440x_attr->field], &reg_val); in afe440x_show_register()
182 if (reg_val >= afe440x_attr->table_size) in afe440x_show_register()
183 return -EINVAL; in afe440x_show_register()
185 vals[0] = afe440x_attr->val_table[reg_val].integer; in afe440x_show_register()
186 vals[1] = afe440x_attr->val_table[reg_val].fract; in afe440x_show_register()
198 int val, integer, fract, ret; in afe440x_store_register() local
200 ret = iio_str_to_fixpoint(buf, 100000, &integer, &fract); in afe440x_store_register()
204 for (val = 0; val < afe440x_attr->table_size; val++) in afe440x_store_register()
205 if (afe440x_attr->val_table[val].integer == integer && in afe440x_store_register()
206 afe440x_attr->val_table[val].fract == fract) in afe440x_store_register()
208 if (val == afe440x_attr->table_size) in afe440x_store_register()
209 return -EINVAL; in afe440x_store_register()
211 ret = regmap_field_write(afe->fields[afe440x_attr->field], val); in afe440x_store_register()
256 switch (chan->type) { in afe4404_read_raw()
260 value_reg = afe4404_channel_values[chan->address]; in afe4404_read_raw()
261 ret = regmap_read(afe->regmap, value_reg, val); in afe4404_read_raw()
266 offdac_field = afe4404_channel_offdacs[chan->address]; in afe4404_read_raw()
267 ret = regmap_field_read(afe->fields[offdac_field], val); in afe4404_read_raw()
276 led_field = afe4404_channel_leds[chan->address]; in afe4404_read_raw()
277 ret = regmap_field_read(afe->fields[led_field], val); in afe4404_read_raw()
291 return -EINVAL; in afe4404_read_raw()
301 switch (chan->type) { in afe4404_write_raw()
305 offdac_field = afe4404_channel_offdacs[chan->address]; in afe4404_write_raw()
306 return regmap_field_write(afe->fields[offdac_field], val); in afe4404_write_raw()
312 led_field = afe4404_channel_leds[chan->address]; in afe4404_write_raw()
313 return regmap_field_write(afe->fields[led_field], val); in afe4404_write_raw()
320 return -EINVAL; in afe4404_write_raw()
332 struct iio_dev *indio_dev = pf->indio_dev; in afe4404_trigger_handler()
336 for_each_set_bit(bit, indio_dev->active_scan_mask, in afe4404_trigger_handler()
337 indio_dev->masklength) { in afe4404_trigger_handler()
338 ret = regmap_read(afe->regmap, afe4404_channel_values[bit], in afe4404_trigger_handler()
339 &afe->buffer[i++]); in afe4404_trigger_handler()
344 iio_push_to_buffers_with_timestamp(indio_dev, afe->buffer, in afe4404_trigger_handler()
345 pf->timestamp); in afe4404_trigger_handler()
347 iio_trigger_notify_done(indio_dev->trig); in afe4404_trigger_handler()
352 /* Default timings from data-sheet */
426 ret = regmap_update_bits(afe->regmap, AFE440X_CONTROL2, in afe4404_suspend()
432 ret = regulator_disable(afe->regulator); in afe4404_suspend()
434 dev_err(dev, "Unable to disable regulator\n"); in afe4404_suspend()
447 ret = regulator_enable(afe->regulator); in afe4404_resume()
449 dev_err(dev, "Unable to enable regulator\n"); in afe4404_resume()
453 ret = regmap_update_bits(afe->regmap, AFE440X_CONTROL2, in afe4404_resume()
470 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*afe)); in afe4404_probe()
472 return -ENOMEM; in afe4404_probe()
477 afe->dev = &client->dev; in afe4404_probe()
478 afe->irq = client->irq; in afe4404_probe()
480 afe->regmap = devm_regmap_init_i2c(client, &afe4404_regmap_config); in afe4404_probe()
481 if (IS_ERR(afe->regmap)) { in afe4404_probe()
482 dev_err(afe->dev, "Unable to allocate register map\n"); in afe4404_probe()
483 return PTR_ERR(afe->regmap); in afe4404_probe()
487 afe->fields[i] = devm_regmap_field_alloc(afe->dev, afe->regmap, in afe4404_probe()
489 if (IS_ERR(afe->fields[i])) { in afe4404_probe()
490 dev_err(afe->dev, "Unable to allocate regmap fields\n"); in afe4404_probe()
491 return PTR_ERR(afe->fields[i]); in afe4404_probe()
495 afe->regulator = devm_regulator_get(afe->dev, "tx_sup"); in afe4404_probe()
496 if (IS_ERR(afe->regulator)) in afe4404_probe()
497 return dev_err_probe(afe->dev, PTR_ERR(afe->regulator), in afe4404_probe()
498 "Unable to get regulator\n"); in afe4404_probe()
500 ret = regulator_enable(afe->regulator); in afe4404_probe()
502 dev_err(afe->dev, "Unable to enable regulator\n"); in afe4404_probe()
506 ret = regmap_write(afe->regmap, AFE440X_CONTROL0, in afe4404_probe()
509 dev_err(afe->dev, "Unable to reset device\n"); in afe4404_probe()
513 ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences, in afe4404_probe()
516 dev_err(afe->dev, "Unable to set register defaults\n"); in afe4404_probe()
520 indio_dev->modes = INDIO_DIRECT_MODE; in afe4404_probe()
521 indio_dev->channels = afe4404_channels; in afe4404_probe()
522 indio_dev->num_channels = ARRAY_SIZE(afe4404_channels); in afe4404_probe()
523 indio_dev->name = AFE4404_DRIVER_NAME; in afe4404_probe()
524 indio_dev->info = &afe4404_iio_info; in afe4404_probe()
526 if (afe->irq > 0) { in afe4404_probe()
527 afe->trig = devm_iio_trigger_alloc(afe->dev, in afe4404_probe()
528 "%s-dev%d", in afe4404_probe()
529 indio_dev->name, in afe4404_probe()
531 if (!afe->trig) { in afe4404_probe()
532 dev_err(afe->dev, "Unable to allocate IIO trigger\n"); in afe4404_probe()
533 ret = -ENOMEM; in afe4404_probe()
537 iio_trigger_set_drvdata(afe->trig, indio_dev); in afe4404_probe()
539 ret = iio_trigger_register(afe->trig); in afe4404_probe()
541 dev_err(afe->dev, "Unable to register IIO trigger\n"); in afe4404_probe()
545 ret = devm_request_threaded_irq(afe->dev, afe->irq, in afe4404_probe()
549 afe->trig); in afe4404_probe()
551 dev_err(afe->dev, "Unable to request IRQ\n"); in afe4404_probe()
559 dev_err(afe->dev, "Unable to setup buffer\n"); in afe4404_probe()
565 dev_err(afe->dev, "Unable to register IIO device\n"); in afe4404_probe()
574 if (afe->irq > 0) in afe4404_probe()
575 iio_trigger_unregister(afe->trig); in afe4404_probe()
577 regulator_disable(afe->regulator); in afe4404_probe()
592 if (afe->irq > 0) in afe4404_remove()
593 iio_trigger_unregister(afe->trig); in afe4404_remove()
595 ret = regulator_disable(afe->regulator); in afe4404_remove()
597 dev_err(afe->dev, "Unable to disable regulator\n"); in afe4404_remove()