Lines Matching +full:mux +full:- +full:delay +full:- +full:config +full:- +full:us

1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/delay.h>
41 /* Config register */
82 /* Timeout based on the minimum sample rate of 20 SPS (50000us) */
91 int mux; member
121 unsigned int config = st->cached_config; in ads1119_upd_cfg_reg() local
124 config &= ~fields; in ads1119_upd_cfg_reg()
125 config |= val; in ads1119_upd_cfg_reg()
127 ret = i2c_smbus_write_byte_data(st->client, ADS1119_CMD_WREG, config); in ads1119_upd_cfg_reg()
131 st->cached_config = config; in ads1119_upd_cfg_reg()
140 status = i2c_smbus_read_byte_data(st->client, ADS1119_CMD_RREG_STATUS); in ads1119_data_ready()
149 st->cached_config = 0; in ads1119_reset()
151 if (!st->reset_gpio) in ads1119_reset()
152 return i2c_smbus_write_byte(st->client, ADS1119_CMD_RESET); in ads1119_reset()
154 gpiod_set_value_cansleep(st->reset_gpio, 1); in ads1119_reset()
156 gpiod_set_value_cansleep(st->reset_gpio, 0); in ads1119_reset()
198 static int ads1119_configure_channel(struct ads1119_state *st, int mux, in ads1119_configure_channel() argument
204 FIELD_PREP(ADS1119_CONFIG_MUX_FIELD, mux)); in ads1119_configure_channel()
222 unsigned int datarate = st->channels_cfg[chan->address].datarate; in ads1119_poll_data_ready()
243 if (!st->client->irq) { in ads1119_read_data()
247 } else if (!wait_for_completion_timeout(&st->completion, timeout)) { in ads1119_read_data()
248 return -ETIMEDOUT; in ads1119_read_data()
251 ret = i2c_smbus_read_word_swapped(st->client, ADS1119_CMD_RDATA); in ads1119_read_data()
265 struct device *dev = &st->client->dev; in ads1119_single_conversion()
266 int mux = st->channels_cfg[chan->address].mux; in ads1119_single_conversion() local
267 int gain = st->channels_cfg[chan->address].gain; in ads1119_single_conversion()
268 int datarate = st->channels_cfg[chan->address].datarate; in ads1119_single_conversion()
273 mux = ADS1119_MUX_SHORTED; in ads1119_single_conversion()
279 ret = ads1119_configure_channel(st, mux, gain, datarate); in ads1119_single_conversion()
283 ret = i2c_smbus_write_byte(st->client, ADS1119_CMD_START_SYNC); in ads1119_single_conversion()
291 *val = sign_extend32(sample, chan->scan_type.realbits - 1); in ads1119_single_conversion()
308 return -EINVAL; in ads1119_validate_datarate()
329 return -EINVAL; in ads1119_read_avail()
338 unsigned int index = chan->address; in ads1119_read_raw()
340 if (index >= st->num_channels_cfg) in ads1119_read_raw()
341 return -EINVAL; in ads1119_read_raw()
345 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) in ads1119_read_raw()
349 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) in ads1119_read_raw()
353 *val = st->vref_uV / 1000; in ads1119_read_raw()
354 *val /= st->channels_cfg[index].gain; in ads1119_read_raw()
355 *val2 = chan->scan_type.realbits - 1; in ads1119_read_raw()
358 *val = st->channels_cfg[index].datarate; in ads1119_read_raw()
361 return -EINVAL; in ads1119_read_raw()
370 unsigned int index = chan->address; in ads1119_write_raw()
373 if (index >= st->num_channels_cfg) in ads1119_write_raw()
374 return -EINVAL; in ads1119_write_raw()
380 return -EINVAL; in ads1119_write_raw()
382 st->channels_cfg[index].gain = ret; in ads1119_write_raw()
389 st->channels_cfg[index].datarate = ret; in ads1119_write_raw()
392 return -EINVAL; in ads1119_write_raw()
404 return -EINVAL; in ads1119_debugfs_reg_access()
407 ret = i2c_smbus_read_byte_data(st->client, in ads1119_debugfs_reg_access()
417 return -EINVAL; in ads1119_debugfs_reg_access()
419 return i2c_smbus_write_byte_data(st->client, ADS1119_CMD_WREG, in ads1119_debugfs_reg_access()
433 struct device *dev = &st->client->dev; in ads1119_triggered_buffer_preenable()
437 index = find_first_bit(indio_dev->active_scan_mask, in ads1119_triggered_buffer_preenable()
445 st->channels_cfg[index].mux, in ads1119_triggered_buffer_preenable()
446 st->channels_cfg[index].gain, in ads1119_triggered_buffer_preenable()
447 st->channels_cfg[index].datarate); in ads1119_triggered_buffer_preenable()
455 return i2c_smbus_write_byte(st->client, ADS1119_CMD_START_SYNC); in ads1119_triggered_buffer_preenable()
461 struct device *dev = &st->client->dev; in ads1119_triggered_buffer_postdisable()
490 iio_trigger_poll(indio_dev->trig); in ads1119_irq_handler()
492 complete(&st->completion); in ads1119_irq_handler()
500 struct iio_dev *indio_dev = pf->indio_dev; in ads1119_trigger_handler()
510 index = find_first_bit(indio_dev->active_scan_mask, in ads1119_trigger_handler()
513 ret = ads1119_poll_data_ready(st, &indio_dev->channels[index]); in ads1119_trigger_handler()
515 dev_err(&st->client->dev, in ads1119_trigger_handler()
521 ret = i2c_smbus_read_word_swapped(st->client, ADS1119_CMD_RDATA); in ads1119_trigger_handler()
523 dev_err(&st->client->dev, in ads1119_trigger_handler()
533 iio_trigger_notify_done(indio_dev->trig); in ads1119_trigger_handler()
557 return -EINVAL; in ads1119_map_analog_inputs_mux()
569 return -EINVAL; in ads1119_map_analog_inputs_mux()
595 struct device *dev = &st->client->dev; in ads1119_alloc_and_config_channels()
601 st->num_channels_cfg = device_get_child_node_count(dev); in ads1119_alloc_and_config_channels()
602 if (st->num_channels_cfg > ADS1119_MAX_CHANNELS) in ads1119_alloc_and_config_channels()
603 return dev_err_probe(dev, -EINVAL, in ads1119_alloc_and_config_channels()
605 st->num_channels_cfg, in ads1119_alloc_and_config_channels()
608 st->channels_cfg = devm_kcalloc(dev, st->num_channels_cfg, in ads1119_alloc_and_config_channels()
609 sizeof(*st->channels_cfg), GFP_KERNEL); in ads1119_alloc_and_config_channels()
610 if (!st->channels_cfg) in ads1119_alloc_and_config_channels()
611 return -ENOMEM; in ads1119_alloc_and_config_channels()
614 num_channels = st->num_channels_cfg + 1; in ads1119_alloc_and_config_channels()
618 return -ENOMEM; in ads1119_alloc_and_config_channels()
625 differential = fwnode_property_present(child, "diff-channels"); in ads1119_alloc_and_config_channels()
628 "diff-channels", in ads1119_alloc_and_config_channels()
631 ret = fwnode_property_read_u32(child, "single-channel", in ads1119_alloc_and_config_channels()
644 st->channels_cfg[i].mux = ret; in ads1119_alloc_and_config_channels()
645 st->channels_cfg[i].gain = ADS1119_DEFAULT_GAIN; in ads1119_alloc_and_config_channels()
646 st->channels_cfg[i].datarate = ADS1119_DEFAULT_DATARATE; in ads1119_alloc_and_config_channels()
649 chan->channel = ain[0]; in ads1119_alloc_and_config_channels()
650 chan->address = i; in ads1119_alloc_and_config_channels()
651 chan->scan_index = i; in ads1119_alloc_and_config_channels()
654 chan->channel2 = ain[1]; in ads1119_alloc_and_config_channels()
655 chan->differential = 1; in ads1119_alloc_and_config_channels()
658 dev_dbg(dev, "channel: index %d, mux %d\n", i, in ads1119_alloc_and_config_channels()
659 st->channels_cfg[i].mux); in ads1119_alloc_and_config_channels()
668 indio_dev->channels = iio_channels; in ads1119_alloc_and_config_channels()
669 indio_dev->num_channels = num_channels; in ads1119_alloc_and_config_channels()
678 i2c_smbus_write_byte(st->client, ADS1119_CMD_POWERDOWN); in ads1119_powerdown()
685 struct device *dev = &client->dev; in ads1119_probe()
691 return dev_err_probe(dev, -ENOMEM, in ads1119_probe()
695 st->client = client; in ads1119_probe()
697 indio_dev->name = "ads1119"; in ads1119_probe()
698 indio_dev->info = &ads1119_info; in ads1119_probe()
699 indio_dev->modes = INDIO_DIRECT_MODE; in ads1119_probe()
710 st->vref_uV = devm_regulator_get_enable_read_voltage(dev, "vref"); in ads1119_probe()
711 if (st->vref_uV == -ENODEV) { in ads1119_probe()
713 st->vref_uV = ADS1119_VREF_INTERNAL_VAL; in ads1119_probe()
714 } else if (st->vref_uV < 0) { in ads1119_probe()
715 return dev_err_probe(dev, st->vref_uV, "Failed to get vref\n"); in ads1119_probe()
718 st->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in ads1119_probe()
719 if (IS_ERR(st->reset_gpio)) in ads1119_probe()
720 return dev_err_probe(dev, PTR_ERR(st->reset_gpio), in ads1119_probe()
727 init_completion(&st->completion); in ads1119_probe()
735 if (client->irq > 0) { in ads1119_probe()
736 ret = devm_request_threaded_irq(dev, client->irq, in ads1119_probe()
744 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in ads1119_probe()
745 indio_dev->name, in ads1119_probe()
747 if (!st->trig) in ads1119_probe()
748 return dev_err_probe(dev, -ENOMEM, in ads1119_probe()
751 st->trig->ops = &ads1119_trigger_ops; in ads1119_probe()
752 iio_trigger_set_drvdata(st->trig, indio_dev); in ads1119_probe()
754 ret = devm_iio_trigger_register(dev, st->trig); in ads1119_probe()
787 return i2c_smbus_write_byte(st->client, ADS1119_CMD_POWERDOWN); in ads1119_runtime_suspend()