• Home
  • Raw
  • Download

Lines Matching +full:buffered +full:- +full:positive

1 // SPDX-License-Identifier: GPL-2.0-only
3 * ADS1015 - Texas Instruments Analog-to-Digital Converter
7 * IIO driver for ADS1015 ADC 7-bit I2C slave address:
8 * * 0x48 - ADDR connected to Ground
9 * * 0x49 - ADDR connected to Vdd
10 * * 0x4A - ADDR connected to SDA
11 * * 0x4B - ADDR connected to SCL
106 * Translation from PGA bits to full-scale positive and negative input voltage
178 .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \
220 .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \
238 * Protects ADC ops, e.g: concurrent sysfs/buffered
250 * Set to true when the ADC is switched to the continuous-conversion
251 * mode and exits from a power-down state. This flag is used to avoid
259 return (data->event_channel != ADS1015_CHANNELS); in ads1015_event_channel_enabled()
267 data->event_channel = chan; in ads1015_event_channel_enable()
268 data->comp_mode = comp_mode; in ads1015_event_channel_enable()
273 data->event_channel = ADS1015_CHANNELS; in ads1015_event_channel_disable()
323 struct device *dev = regmap_get_device(data->regmap); in ads1015_set_power_state()
353 return -EINVAL; in ads1015_get_adc_result()
355 ret = regmap_read(data->regmap, ADS1015_CFG_REG, &old); in ads1015_get_adc_result()
359 pga = data->channel_data[chan].pga; in ads1015_get_adc_result()
360 dr = data->channel_data[chan].data_rate; in ads1015_get_adc_result()
368 cfg |= data->thresh_data[chan].comp_queue << in ads1015_get_adc_result()
370 data->comp_mode << in ads1015_get_adc_result()
376 ret = regmap_write(data->regmap, ADS1015_CFG_REG, cfg); in ads1015_get_adc_result()
379 data->conv_invalid = true; in ads1015_get_adc_result()
381 if (data->conv_invalid) { in ads1015_get_adc_result()
383 conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr_old]); in ads1015_get_adc_result()
384 conv_time += DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]); in ads1015_get_adc_result()
387 data->conv_invalid = false; in ads1015_get_adc_result()
390 return regmap_read(data->regmap, ADS1015_CONV_REG, val); in ads1015_get_adc_result()
396 struct iio_dev *indio_dev = pf->indio_dev; in ads1015_trigger_handler()
407 mutex_lock(&data->lock); in ads1015_trigger_handler()
408 chan = find_first_bit(indio_dev->active_scan_mask, in ads1015_trigger_handler()
409 indio_dev->masklength); in ads1015_trigger_handler()
412 mutex_unlock(&data->lock); in ads1015_trigger_handler()
417 mutex_unlock(&data->lock); in ads1015_trigger_handler()
423 iio_trigger_notify_done(indio_dev->trig); in ads1015_trigger_handler()
434 (chan->scan_type.realbits - 1), 1000000); in ads1015_set_scale()
438 data->channel_data[chan->address].pga = i; in ads1015_set_scale()
443 return -EINVAL; in ads1015_set_scale()
451 if (data->data_rate[i] == rate) { in ads1015_set_data_rate()
452 data->channel_data[chan].data_rate = i; in ads1015_set_data_rate()
457 return -EINVAL; in ads1015_set_data_rate()
467 mutex_lock(&data->lock); in ads1015_read_raw()
470 int shift = chan->scan_type.shift; in ads1015_read_raw()
477 data->event_channel != chan->address) { in ads1015_read_raw()
478 ret = -EBUSY; in ads1015_read_raw()
486 ret = ads1015_get_adc_result(data, chan->address, val); in ads1015_read_raw()
492 *val = sign_extend32(*val >> shift, 15 - shift); in ads1015_read_raw()
504 idx = data->channel_data[chan->address].pga; in ads1015_read_raw()
506 *val2 = chan->scan_type.realbits - 1; in ads1015_read_raw()
510 idx = data->channel_data[chan->address].data_rate; in ads1015_read_raw()
511 *val = data->data_rate[idx]; in ads1015_read_raw()
515 ret = -EINVAL; in ads1015_read_raw()
518 mutex_unlock(&data->lock); in ads1015_read_raw()
530 mutex_lock(&data->lock); in ads1015_write_raw()
536 ret = ads1015_set_data_rate(data, chan->address, val); in ads1015_write_raw()
539 ret = -EINVAL; in ads1015_write_raw()
542 mutex_unlock(&data->lock); in ads1015_write_raw()
558 mutex_lock(&data->lock); in ads1015_read_event()
563 data->thresh_data[chan->address].high_thresh : in ads1015_read_event()
564 data->thresh_data[chan->address].low_thresh; in ads1015_read_event()
568 dr = data->channel_data[chan->address].data_rate; in ads1015_read_event()
569 comp_queue = data->thresh_data[chan->address].comp_queue; in ads1015_read_event()
571 USEC_PER_SEC / data->data_rate[dr]; in ads1015_read_event()
578 ret = -EINVAL; in ads1015_read_event()
582 mutex_unlock(&data->lock); in ads1015_read_event()
593 int realbits = chan->scan_type.realbits; in ads1015_write_event()
599 mutex_lock(&data->lock); in ads1015_write_event()
603 if (val >= 1 << (realbits - 1) || val < -1 << (realbits - 1)) { in ads1015_write_event()
604 ret = -EINVAL; in ads1015_write_event()
608 data->thresh_data[chan->address].high_thresh = val; in ads1015_write_event()
610 data->thresh_data[chan->address].low_thresh = val; in ads1015_write_event()
613 dr = data->channel_data[chan->address].data_rate; in ads1015_write_event()
616 for (i = 0; i < ARRAY_SIZE(ads1015_comp_queue) - 1; i++) { in ads1015_write_event()
618 USEC_PER_SEC / data->data_rate[dr]) in ads1015_write_event()
621 data->thresh_data[chan->address].comp_queue = i; in ads1015_write_event()
624 ret = -EINVAL; in ads1015_write_event()
628 mutex_unlock(&data->lock); in ads1015_write_event()
640 mutex_lock(&data->lock); in ads1015_read_event_config()
641 if (data->event_channel == chan->address) { in ads1015_read_event_config()
647 ret = (data->comp_mode == ADS1015_CFG_COMP_MODE_WINDOW); in ads1015_read_event_config()
650 ret = -EINVAL; in ads1015_read_event_config()
654 mutex_unlock(&data->lock); in ads1015_read_event_config()
662 int low_thresh = data->thresh_data[chan->address].low_thresh; in ads1015_enable_event_config()
663 int high_thresh = data->thresh_data[chan->address].high_thresh; in ads1015_enable_event_config()
668 if (data->event_channel != chan->address || in ads1015_enable_event_config()
669 (data->comp_mode == ADS1015_CFG_COMP_MODE_TRAD && in ads1015_enable_event_config()
671 return -EBUSY; in ads1015_enable_event_config()
677 low_thresh = max(-1 << (chan->scan_type.realbits - 1), in ads1015_enable_event_config()
678 high_thresh - 1); in ads1015_enable_event_config()
680 ret = regmap_write(data->regmap, ADS1015_LO_THRESH_REG, in ads1015_enable_event_config()
681 low_thresh << chan->scan_type.shift); in ads1015_enable_event_config()
685 ret = regmap_write(data->regmap, ADS1015_HI_THRESH_REG, in ads1015_enable_event_config()
686 high_thresh << chan->scan_type.shift); in ads1015_enable_event_config()
694 ads1015_event_channel_enable(data, chan->address, comp_mode); in ads1015_enable_event_config()
696 ret = ads1015_get_adc_result(data, chan->address, &val); in ads1015_enable_event_config()
698 ads1015_event_channel_disable(data, chan->address); in ads1015_enable_event_config()
713 if (data->event_channel != chan->address) in ads1015_disable_event_config()
716 if (data->comp_mode == ADS1015_CFG_COMP_MODE_TRAD && in ads1015_disable_event_config()
720 ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG, in ads1015_disable_event_config()
727 ads1015_event_channel_disable(data, chan->address); in ads1015_disable_event_config()
741 mutex_lock(&data->lock); in ads1015_write_event_config()
746 mutex_unlock(&data->lock); in ads1015_write_event_config()
756 mutex_unlock(&data->lock); in ads1015_write_event_config()
769 ret = regmap_read(data->regmap, ADS1015_CONV_REG, &val); in ads1015_event_handler()
777 dir = data->comp_mode == ADS1015_CFG_COMP_MODE_TRAD ? in ads1015_event_handler()
779 code = IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, data->event_channel, in ads1015_event_handler()
793 return -EBUSY; in ads1015_buffer_preenable()
863 struct device *dev = &client->dev; in ads1015_client_get_channels_config()
865 int i = -1; in ads1015_client_get_channels_config()
890 return -EINVAL; in ads1015_client_get_channels_config()
899 return -EINVAL; in ads1015_client_get_channels_config()
903 data->channel_data[channel].pga = pga; in ads1015_client_get_channels_config()
904 data->channel_data[channel].data_rate = data_rate; in ads1015_client_get_channels_config()
909 return i < 0 ? -EINVAL : 0; in ads1015_client_get_channels_config()
924 data->channel_data[k].pga = ADS1015_DEFAULT_PGA; in ads1015_get_channels_config()
925 data->channel_data[k].data_rate = ADS1015_DEFAULT_DATA_RATE; in ads1015_get_channels_config()
931 return regmap_update_bits(data->regmap, ADS1015_CFG_REG, in ads1015_set_conv_mode()
945 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in ads1015_probe()
947 return -ENOMEM; in ads1015_probe()
952 mutex_init(&data->lock); in ads1015_probe()
954 indio_dev->name = ADS1015_DRV_NAME; in ads1015_probe()
955 indio_dev->modes = INDIO_DIRECT_MODE; in ads1015_probe()
957 chip = (enum chip_ids)device_get_match_data(&client->dev); in ads1015_probe()
959 chip = id->driver_data; in ads1015_probe()
962 indio_dev->channels = ads1015_channels; in ads1015_probe()
963 indio_dev->num_channels = ARRAY_SIZE(ads1015_channels); in ads1015_probe()
964 indio_dev->info = &ads1015_info; in ads1015_probe()
965 data->data_rate = (unsigned int *) &ads1015_data_rate; in ads1015_probe()
968 indio_dev->channels = ads1115_channels; in ads1015_probe()
969 indio_dev->num_channels = ARRAY_SIZE(ads1115_channels); in ads1015_probe()
970 indio_dev->info = &ads1115_info; in ads1015_probe()
971 data->data_rate = (unsigned int *) &ads1115_data_rate; in ads1015_probe()
974 dev_err(&client->dev, "Unknown chip %d\n", chip); in ads1015_probe()
975 return -EINVAL; in ads1015_probe()
978 data->event_channel = ADS1015_CHANNELS; in ads1015_probe()
984 int realbits = indio_dev->channels[i].scan_type.realbits; in ads1015_probe()
986 data->thresh_data[i].low_thresh = -1 << (realbits - 1); in ads1015_probe()
987 data->thresh_data[i].high_thresh = (1 << (realbits - 1)) - 1; in ads1015_probe()
993 data->regmap = devm_regmap_init_i2c(client, &ads1015_regmap_config); in ads1015_probe()
994 if (IS_ERR(data->regmap)) { in ads1015_probe()
995 dev_err(&client->dev, "Failed to allocate register map\n"); in ads1015_probe()
996 return PTR_ERR(data->regmap); in ads1015_probe()
999 ret = devm_iio_triggered_buffer_setup(&client->dev, indio_dev, NULL, in ads1015_probe()
1003 dev_err(&client->dev, "iio triggered buffer setup failed\n"); in ads1015_probe()
1007 if (client->irq) { in ads1015_probe()
1009 irqd_get_trigger_type(irq_get_irq_data(client->irq)); in ads1015_probe()
1026 return -EINVAL; in ads1015_probe()
1029 ret = regmap_update_bits(data->regmap, ADS1015_CFG_REG, in ads1015_probe()
1034 ret = devm_request_threaded_irq(&client->dev, client->irq, in ads1015_probe()
1037 client->name, indio_dev); in ads1015_probe()
1046 data->conv_invalid = true; in ads1015_probe()
1048 ret = pm_runtime_set_active(&client->dev); in ads1015_probe()
1051 pm_runtime_set_autosuspend_delay(&client->dev, ADS1015_SLEEP_DELAY_MS); in ads1015_probe()
1052 pm_runtime_use_autosuspend(&client->dev); in ads1015_probe()
1053 pm_runtime_enable(&client->dev); in ads1015_probe()
1057 dev_err(&client->dev, "Failed to register IIO device\n"); in ads1015_probe()
1071 pm_runtime_disable(&client->dev); in ads1015_remove()
1072 pm_runtime_set_suspended(&client->dev); in ads1015_remove()
1073 pm_runtime_put_noidle(&client->dev); in ads1015_remove()
1096 data->conv_invalid = true; in ads1015_runtime_resume()