• Home
  • Raw
  • Download

Lines Matching refs:st

170 	struct ad74413r_state *st = context;  in ad74413r_reg_write()  local
172 ad74413r_format_reg_write(reg, val, st->reg_tx_buf); in ad74413r_reg_write()
174 return spi_write(st->spi, st->reg_tx_buf, AD74413R_FRAME_SIZE); in ad74413r_reg_write()
177 static int ad74413r_crc_check(struct ad74413r_state *st, u8 *buf) in ad74413r_crc_check() argument
182 dev_err(st->dev, "Bad CRC %02x for %02x%02x%02x\n", in ad74413r_crc_check()
192 struct ad74413r_state *st = context; in ad74413r_reg_read() local
195 .tx_buf = st->reg_tx_buf, in ad74413r_reg_read()
200 .rx_buf = st->reg_rx_buf, in ad74413r_reg_read()
207 st->reg_tx_buf); in ad74413r_reg_read()
209 ret = spi_sync_transfer(st->spi, reg_read_xfer, in ad74413r_reg_read()
214 ret = ad74413r_crc_check(st, st->reg_rx_buf); in ad74413r_reg_read()
218 *val = get_unaligned_be16(&st->reg_rx_buf[1]); in ad74413r_reg_read()
230 static int ad74413r_set_gpo_config(struct ad74413r_state *st, in ad74413r_set_gpo_config() argument
233 return regmap_update_bits(st->regmap, AD74413R_REG_GPO_CONFIG_X(offset), in ad74413r_set_gpo_config()
244 static int ad74413r_set_comp_debounce(struct ad74413r_state *st, in ad74413r_set_comp_debounce() argument
257 return regmap_update_bits(st->regmap, in ad74413r_set_comp_debounce()
266 struct ad74413r_state *st = gpiochip_get_data(chip); in ad74413r_gpio_set() local
267 unsigned int real_offset = st->gpo_gpio_offsets[offset]; in ad74413r_gpio_set()
270 ret = ad74413r_set_gpo_config(st, real_offset, in ad74413r_gpio_set()
275 regmap_update_bits(st->regmap, AD74413R_REG_GPO_CONFIG_X(real_offset), in ad74413r_gpio_set()
284 struct ad74413r_state *st = gpiochip_get_data(chip); in ad74413r_gpio_set_multiple() local
291 unsigned int real_offset = st->gpo_gpio_offsets[offset]; in ad74413r_gpio_set_multiple()
293 ret = ad74413r_set_gpo_config(st, real_offset, in ad74413r_gpio_set_multiple()
303 regmap_update_bits(st->regmap, AD74413R_REG_GPO_PAR_DATA, in ad74413r_gpio_set_multiple()
309 struct ad74413r_state *st = gpiochip_get_data(chip); in ad74413r_gpio_get() local
310 unsigned int real_offset = st->comp_gpio_offsets[offset]; in ad74413r_gpio_get()
314 ret = regmap_read(st->regmap, AD74413R_REG_DIN_COMP_OUT, &status); in ad74413r_gpio_get()
327 struct ad74413r_state *st = gpiochip_get_data(chip); in ad74413r_gpio_get_multiple() local
332 ret = regmap_read(st->regmap, AD74413R_REG_DIN_COMP_OUT, &val); in ad74413r_gpio_get_multiple()
337 unsigned int real_offset = st->comp_gpio_offsets[offset]; in ad74413r_gpio_get_multiple()
361 struct ad74413r_state *st = gpiochip_get_data(chip); in ad74413r_gpio_set_gpo_config() local
362 unsigned int real_offset = st->gpo_gpio_offsets[offset]; in ad74413r_gpio_set_gpo_config()
366 return ad74413r_set_gpo_config(st, real_offset, in ad74413r_gpio_set_gpo_config()
369 return ad74413r_set_gpo_config(st, real_offset, in ad74413r_gpio_set_gpo_config()
380 struct ad74413r_state *st = gpiochip_get_data(chip); in ad74413r_gpio_set_comp_config() local
381 unsigned int real_offset = st->comp_gpio_offsets[offset]; in ad74413r_gpio_set_comp_config()
385 return ad74413r_set_comp_debounce(st, real_offset, in ad74413r_gpio_set_comp_config()
392 static int ad74413r_reset(struct ad74413r_state *st) in ad74413r_reset() argument
396 ret = regmap_write(st->regmap, AD74413R_REG_CMD_KEY, in ad74413r_reset()
401 return regmap_write(st->regmap, AD74413R_REG_CMD_KEY, in ad74413r_reset()
405 static int ad74413r_set_channel_dac_code(struct ad74413r_state *st, in ad74413r_set_channel_dac_code() argument
413 return regmap_multi_reg_write(st->regmap, reg_seq, 2); in ad74413r_set_channel_dac_code()
416 static int ad74413r_set_channel_function(struct ad74413r_state *st, in ad74413r_set_channel_function() argument
419 return regmap_update_bits(st->regmap, in ad74413r_set_channel_function()
424 static int ad74413r_set_adc_conv_seq(struct ad74413r_state *st, in ad74413r_set_adc_conv_seq() argument
433 ret = regmap_write_bits(st->regmap, AD74413R_REG_ADC_CONV_CTRL, in ad74413r_set_adc_conv_seq()
447 static int ad74413r_set_adc_channel_enable(struct ad74413r_state *st, in ad74413r_set_adc_channel_enable() argument
451 return regmap_update_bits(st->regmap, AD74413R_REG_ADC_CONV_CTRL, in ad74413r_set_adc_channel_enable()
456 static int ad74413r_get_adc_range(struct ad74413r_state *st, in ad74413r_get_adc_range() argument
462 ret = regmap_read(st->regmap, AD74413R_REG_ADC_CONFIG_X(channel), val); in ad74413r_get_adc_range()
471 static int ad74413r_get_adc_rejection(struct ad74413r_state *st, in ad74413r_get_adc_rejection() argument
477 ret = regmap_read(st->regmap, AD74413R_REG_ADC_CONFIG_X(channel), val); in ad74413r_get_adc_rejection()
486 static int ad74413r_set_adc_rejection(struct ad74413r_state *st, in ad74413r_set_adc_rejection() argument
490 return regmap_update_bits(st->regmap, in ad74413r_set_adc_rejection()
497 static int ad74413r_rejection_to_rate(struct ad74413r_state *st, in ad74413r_rejection_to_rate() argument
514 dev_err(st->dev, "ADC rejection invalid\n"); in ad74413r_rejection_to_rate()
519 static int ad74413r_rate_to_rejection(struct ad74413r_state *st, in ad74413r_rate_to_rejection() argument
536 dev_err(st->dev, "ADC rate invalid\n"); in ad74413r_rate_to_rejection()
541 static int ad74413r_range_to_voltage_range(struct ad74413r_state *st, in ad74413r_range_to_voltage_range() argument
556 dev_err(st->dev, "ADC range invalid\n"); in ad74413r_range_to_voltage_range()
561 static int ad74413r_range_to_voltage_offset(struct ad74413r_state *st, in ad74413r_range_to_voltage_offset() argument
574 dev_err(st->dev, "ADC range invalid\n"); in ad74413r_range_to_voltage_offset()
579 static int ad74413r_range_to_voltage_offset_raw(struct ad74413r_state *st, in ad74413r_range_to_voltage_offset_raw() argument
594 dev_err(st->dev, "ADC range invalid\n"); in ad74413r_range_to_voltage_offset_raw()
599 static int ad74413r_get_output_voltage_scale(struct ad74413r_state *st, in ad74413r_get_output_voltage_scale() argument
608 static int ad74413r_get_output_current_scale(struct ad74413r_state *st, in ad74413r_get_output_current_scale() argument
611 *val = regulator_get_voltage(st->refin_reg); in ad74413r_get_output_current_scale()
612 *val2 = st->sense_resistor_ohms * AD74413R_DAC_CODE_MAX * 1000; in ad74413r_get_output_current_scale()
617 static int ad74413r_get_input_voltage_scale(struct ad74413r_state *st, in ad74413r_get_input_voltage_scale() argument
624 ret = ad74413r_get_adc_range(st, channel, &range); in ad74413r_get_input_voltage_scale()
628 ret = ad74413r_range_to_voltage_range(st, range, val); in ad74413r_get_input_voltage_scale()
637 static int ad74413r_get_input_voltage_offset(struct ad74413r_state *st, in ad74413r_get_input_voltage_offset() argument
643 ret = ad74413r_get_adc_range(st, channel, &range); in ad74413r_get_input_voltage_offset()
647 ret = ad74413r_range_to_voltage_offset_raw(st, range, val); in ad74413r_get_input_voltage_offset()
654 static int ad74413r_get_input_current_scale(struct ad74413r_state *st, in ad74413r_get_input_current_scale() argument
661 ret = ad74413r_get_adc_range(st, channel, &range); in ad74413r_get_input_current_scale()
665 ret = ad74413r_range_to_voltage_range(st, range, val); in ad74413r_get_input_current_scale()
669 *val2 = AD74413R_ADC_RESULT_MAX * st->sense_resistor_ohms; in ad74413r_get_input_current_scale()
674 static int ad74413_get_input_current_offset(struct ad74413r_state *st, in ad74413_get_input_current_offset() argument
682 ret = ad74413r_get_adc_range(st, channel, &range); in ad74413_get_input_current_offset()
686 ret = ad74413r_range_to_voltage_range(st, range, &voltage_range); in ad74413_get_input_current_offset()
690 ret = ad74413r_range_to_voltage_offset(st, range, &voltage_offset); in ad74413_get_input_current_offset()
699 static int ad74413r_get_adc_rate(struct ad74413r_state *st, in ad74413r_get_adc_rate() argument
705 ret = ad74413r_get_adc_rejection(st, channel, &rejection); in ad74413r_get_adc_rate()
709 ret = ad74413r_rejection_to_rate(st, rejection, val); in ad74413r_get_adc_rate()
716 static int ad74413r_set_adc_rate(struct ad74413r_state *st, in ad74413r_set_adc_rate() argument
722 ret = ad74413r_rate_to_rejection(st, val, &rejection); in ad74413r_set_adc_rate()
726 return ad74413r_set_adc_rejection(st, channel, rejection); in ad74413r_set_adc_rate()
733 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_trigger_handler() local
734 u8 *rx_buf = st->adc_samples_buf.rx_buf; in ad74413r_trigger_handler()
738 ret = spi_sync(st->spi, &st->adc_samples_msg); in ad74413r_trigger_handler()
742 for (i = 0; i < st->adc_active_channels; i++) in ad74413r_trigger_handler()
743 ad74413r_crc_check(st, &rx_buf[i * AD74413R_FRAME_SIZE]); in ad74413r_trigger_handler()
745 iio_push_to_buffers_with_timestamp(indio_dev, &st->adc_samples_buf, in ad74413r_trigger_handler()
757 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_adc_data_interrupt() local
760 iio_trigger_poll(st->trig); in ad74413r_adc_data_interrupt()
762 complete(&st->adc_data_completion); in ad74413r_adc_data_interrupt()
767 static int _ad74413r_get_single_adc_result(struct ad74413r_state *st, in _ad74413r_get_single_adc_result() argument
773 reinit_completion(&st->adc_data_completion); in _ad74413r_get_single_adc_result()
775 ret = ad74413r_set_adc_channel_enable(st, channel, true); in _ad74413r_get_single_adc_result()
779 ret = ad74413r_set_adc_conv_seq(st, AD74413R_CONV_SEQ_SINGLE); in _ad74413r_get_single_adc_result()
783 ret = wait_for_completion_timeout(&st->adc_data_completion, in _ad74413r_get_single_adc_result()
790 ret = regmap_read(st->regmap, AD74413R_REG_ADC_RESULT_X(channel), in _ad74413r_get_single_adc_result()
795 ret = ad74413r_set_adc_conv_seq(st, AD74413R_CONV_SEQ_OFF); in _ad74413r_get_single_adc_result()
799 ret = ad74413r_set_adc_channel_enable(st, channel, false); in _ad74413r_get_single_adc_result()
811 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_get_single_adc_result() local
818 mutex_lock(&st->lock); in ad74413r_get_single_adc_result()
819 ret = _ad74413r_get_single_adc_result(st, channel, val); in ad74413r_get_single_adc_result()
820 mutex_unlock(&st->lock); in ad74413r_get_single_adc_result()
839 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_update_scan_mode() local
840 struct spi_transfer *xfer = st->adc_samples_xfer; in ad74413r_update_scan_mode()
841 u8 *rx_buf = st->adc_samples_buf.rx_buf; in ad74413r_update_scan_mode()
842 u8 *tx_buf = st->adc_samples_tx_buf; in ad74413r_update_scan_mode()
846 mutex_lock(&st->lock); in ad74413r_update_scan_mode()
848 spi_message_init(&st->adc_samples_msg); in ad74413r_update_scan_mode()
849 st->adc_active_channels = 0; in ad74413r_update_scan_mode()
852 ret = ad74413r_set_adc_channel_enable(st, channel, false); in ad74413r_update_scan_mode()
874 ret = ad74413r_set_adc_channel_enable(st, channel, true); in ad74413r_update_scan_mode()
878 st->adc_active_channels++; in ad74413r_update_scan_mode()
880 if (xfer == st->adc_samples_xfer) in ad74413r_update_scan_mode()
893 spi_message_add_tail(xfer, &st->adc_samples_msg); in ad74413r_update_scan_mode()
896 if (xfer != st->adc_samples_xfer) in ad74413r_update_scan_mode()
906 spi_message_add_tail(xfer, &st->adc_samples_msg); in ad74413r_update_scan_mode()
909 mutex_unlock(&st->lock); in ad74413r_update_scan_mode()
916 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_buffer_postenable() local
918 return ad74413r_set_adc_conv_seq(st, AD74413R_CONV_SEQ_CONTINUOUS); in ad74413r_buffer_postenable()
923 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_buffer_predisable() local
925 return ad74413r_set_adc_conv_seq(st, AD74413R_CONV_SEQ_OFF); in ad74413r_buffer_predisable()
932 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_read_raw() local
939 return ad74413r_get_output_voltage_scale(st, in ad74413r_read_raw()
942 return ad74413r_get_input_voltage_scale(st, in ad74413r_read_raw()
946 return ad74413r_get_output_current_scale(st, in ad74413r_read_raw()
949 return ad74413r_get_input_current_scale(st, in ad74413r_read_raw()
957 return ad74413r_get_input_voltage_offset(st, in ad74413r_read_raw()
960 return ad74413_get_input_current_offset(st, in ad74413r_read_raw()
984 return ad74413r_get_adc_rate(st, chan->channel, val); in ad74413r_read_raw()
994 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_write_raw() local
1002 dev_err(st->dev, "Invalid DAC code\n"); in ad74413r_write_raw()
1006 return ad74413r_set_channel_dac_code(st, chan->channel, val); in ad74413r_write_raw()
1008 return ad74413r_set_adc_rate(st, chan->channel, val); in ad74413r_write_raw()
1019 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_read_avail() local
1023 if (st->chip_info->hart_support) { in ad74413r_read_avail()
1141 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_parse_channel_config() local
1148 dev_err(st->dev, "Failed to read channel reg: %d\n", ret); in ad74413r_parse_channel_config()
1153 dev_err(st->dev, "Channel index %u is too large\n", index); in ad74413r_parse_channel_config()
1157 config = &st->channel_configs[index]; in ad74413r_parse_channel_config()
1159 dev_err(st->dev, "Channel %u already initialized\n", index); in ad74413r_parse_channel_config()
1167 dev_err(st->dev, "Invalid channel function %u\n", config->func); in ad74413r_parse_channel_config()
1171 if (!st->chip_info->hart_support && in ad74413r_parse_channel_config()
1174 dev_err(st->dev, "Unsupported HART function %u\n", config->func); in ad74413r_parse_channel_config()
1180 st->num_comparator_gpios++; in ad74413r_parse_channel_config()
1186 st->num_gpo_gpios++; in ad74413r_parse_channel_config()
1197 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_parse_channel_configs() local
1201 fwnode_for_each_available_child_node(dev_fwnode(st->dev), channel_node) { in ad74413r_parse_channel_configs()
1217 struct ad74413r_state *st = iio_priv(indio_dev); in ad74413r_setup_channels() local
1223 channels = devm_kcalloc(st->dev, sizeof(*channels), in ad74413r_setup_channels()
1231 config = &st->channel_configs[i]; in ad74413r_setup_channels()
1247 ret = ad74413r_set_channel_function(st, i, config->func); in ad74413r_setup_channels()
1257 static int ad74413r_setup_gpios(struct ad74413r_state *st) in ad74413r_setup_gpios() argument
1267 config = &st->channel_configs[i]; in ad74413r_setup_gpios()
1273 st->gpo_gpio_offsets[gpo_gpio_i++] = i; in ad74413r_setup_gpios()
1278 st->comp_gpio_offsets[comp_gpio_i++] = i; in ad74413r_setup_gpios()
1280 ret = ad74413r_set_gpo_config(st, i, gpo_config); in ad74413r_setup_gpios()
1295 struct ad74413r_state *st; in ad74413r_probe() local
1299 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad74413r_probe()
1303 st = iio_priv(indio_dev); in ad74413r_probe()
1305 st->spi = spi; in ad74413r_probe()
1306 st->dev = &spi->dev; in ad74413r_probe()
1307 st->chip_info = device_get_match_data(&spi->dev); in ad74413r_probe()
1308 mutex_init(&st->lock); in ad74413r_probe()
1309 init_completion(&st->adc_data_completion); in ad74413r_probe()
1311 st->regmap = devm_regmap_init(st->dev, NULL, st, in ad74413r_probe()
1313 if (IS_ERR(st->regmap)) in ad74413r_probe()
1314 return PTR_ERR(st->regmap); in ad74413r_probe()
1316 st->refin_reg = devm_regulator_get(st->dev, "refin"); in ad74413r_probe()
1317 if (IS_ERR(st->refin_reg)) in ad74413r_probe()
1318 return dev_err_probe(st->dev, PTR_ERR(st->refin_reg), in ad74413r_probe()
1321 ret = regulator_enable(st->refin_reg); in ad74413r_probe()
1325 ret = devm_add_action_or_reset(st->dev, ad74413r_regulator_disable, in ad74413r_probe()
1326 st->refin_reg); in ad74413r_probe()
1330 st->sense_resistor_ohms = 100000000; in ad74413r_probe()
1331 device_property_read_u32(st->dev, "shunt-resistor-micro-ohms", in ad74413r_probe()
1332 &st->sense_resistor_ohms); in ad74413r_probe()
1333 st->sense_resistor_ohms /= 1000000; in ad74413r_probe()
1335 st->trig = devm_iio_trigger_alloc(st->dev, "%s-dev%d", in ad74413r_probe()
1336 st->chip_info->name, iio_device_id(indio_dev)); in ad74413r_probe()
1337 if (!st->trig) in ad74413r_probe()
1340 st->trig->ops = &ad74413r_trigger_ops; in ad74413r_probe()
1341 iio_trigger_set_drvdata(st->trig, st); in ad74413r_probe()
1343 ret = devm_iio_trigger_register(st->dev, st->trig); in ad74413r_probe()
1347 indio_dev->name = st->chip_info->name; in ad74413r_probe()
1350 indio_dev->trig = iio_trigger_get(st->trig); in ad74413r_probe()
1352 ret = ad74413r_reset(st); in ad74413r_probe()
1364 ret = ad74413r_setup_gpios(st); in ad74413r_probe()
1368 if (st->num_gpo_gpios) { in ad74413r_probe()
1369 st->gpo_gpiochip.owner = THIS_MODULE; in ad74413r_probe()
1370 st->gpo_gpiochip.label = st->chip_info->name; in ad74413r_probe()
1371 st->gpo_gpiochip.base = -1; in ad74413r_probe()
1372 st->gpo_gpiochip.ngpio = st->num_gpo_gpios; in ad74413r_probe()
1373 st->gpo_gpiochip.parent = st->dev; in ad74413r_probe()
1374 st->gpo_gpiochip.can_sleep = true; in ad74413r_probe()
1375 st->gpo_gpiochip.set = ad74413r_gpio_set; in ad74413r_probe()
1376 st->gpo_gpiochip.set_multiple = ad74413r_gpio_set_multiple; in ad74413r_probe()
1377 st->gpo_gpiochip.set_config = ad74413r_gpio_set_gpo_config; in ad74413r_probe()
1378 st->gpo_gpiochip.get_direction = in ad74413r_probe()
1381 ret = devm_gpiochip_add_data(st->dev, &st->gpo_gpiochip, st); in ad74413r_probe()
1386 if (st->num_comparator_gpios) { in ad74413r_probe()
1387 st->comp_gpiochip.owner = THIS_MODULE; in ad74413r_probe()
1388 st->comp_gpiochip.label = st->chip_info->name; in ad74413r_probe()
1389 st->comp_gpiochip.base = -1; in ad74413r_probe()
1390 st->comp_gpiochip.ngpio = st->num_comparator_gpios; in ad74413r_probe()
1391 st->comp_gpiochip.parent = st->dev; in ad74413r_probe()
1392 st->comp_gpiochip.can_sleep = true; in ad74413r_probe()
1393 st->comp_gpiochip.get = ad74413r_gpio_get; in ad74413r_probe()
1394 st->comp_gpiochip.get_multiple = ad74413r_gpio_get_multiple; in ad74413r_probe()
1395 st->comp_gpiochip.set_config = ad74413r_gpio_set_comp_config; in ad74413r_probe()
1396 st->comp_gpiochip.get_direction = in ad74413r_probe()
1399 ret = devm_gpiochip_add_data(st->dev, &st->comp_gpiochip, st); in ad74413r_probe()
1404 ret = ad74413r_set_adc_conv_seq(st, AD74413R_CONV_SEQ_OFF); in ad74413r_probe()
1408 ret = devm_request_irq(st->dev, spi->irq, ad74413r_adc_data_interrupt, in ad74413r_probe()
1409 0, st->chip_info->name, indio_dev); in ad74413r_probe()
1411 return dev_err_probe(st->dev, ret, "Failed to request irq\n"); in ad74413r_probe()
1413 ret = devm_iio_triggered_buffer_setup(st->dev, indio_dev, in ad74413r_probe()
1420 return devm_iio_device_register(st->dev, indio_dev); in ad74413r_probe()