Lines Matching refs:dac
55 static int ad3552r_transfer(struct ad3552r_desc *dac, u8 addr, u32 len, in ad3552r_transfer() argument
64 return spi_write_then_read(dac->spi, buf, 1, data, len); in ad3552r_transfer()
67 return spi_write_then_read(dac->spi, buf, len + 1, NULL, 0); in ad3552r_transfer()
70 static int ad3552r_write_reg(struct ad3552r_desc *dac, u8 addr, u16 val) in ad3552r_write_reg() argument
85 return ad3552r_transfer(dac, addr, reg_len, buf, false); in ad3552r_write_reg()
88 static int ad3552r_read_reg(struct ad3552r_desc *dac, u8 addr, u16 *val) in ad3552r_read_reg() argument
94 err = ad3552r_transfer(dac, addr, reg_len, buf, true); in ad3552r_read_reg()
108 static int ad3552r_update_reg_field(struct ad3552r_desc *dac, u8 addr, u16 mask, in ad3552r_update_reg_field() argument
114 ret = ad3552r_read_reg(dac, addr, ®); in ad3552r_update_reg_field()
121 return ad3552r_write_reg(dac, addr, reg); in ad3552r_update_reg_field()
148 struct ad3552r_desc *dac = iio_priv(indio_dev); in ad3552r_read_raw() local
155 mutex_lock(&dac->lock); in ad3552r_read_raw()
156 err = ad3552r_read_reg(dac, AD3552R_REG_ADDR_CH_DAC_24B(ch), in ad3552r_read_raw()
158 mutex_unlock(&dac->lock); in ad3552r_read_raw()
164 mutex_lock(&dac->lock); in ad3552r_read_raw()
165 err = ad3552r_read_reg(dac, AD3552R_REG_ADDR_POWERDOWN_CONFIG, in ad3552r_read_raw()
167 mutex_unlock(&dac->lock); in ad3552r_read_raw()
174 *val = dac->ch_data[ch].scale_int; in ad3552r_read_raw()
175 *val2 = dac->ch_data[ch].scale_dec; in ad3552r_read_raw()
178 *val = dac->ch_data[ch].offset_int; in ad3552r_read_raw()
179 *val2 = dac->ch_data[ch].offset_dec; in ad3552r_read_raw()
192 struct ad3552r_desc *dac = iio_priv(indio_dev); in ad3552r_write_raw() local
195 mutex_lock(&dac->lock); in ad3552r_write_raw()
198 err = ad3552r_write_reg(dac, in ad3552r_write_raw()
208 err = ad3552r_update_reg_field(dac, AD3552R_REG_ADDR_POWERDOWN_CONFIG, in ad3552r_write_raw()
216 mutex_unlock(&dac->lock); in ad3552r_write_raw()
235 static int ad3552r_write_all_channels(struct ad3552r_desc *dac, u8 *data) in ad3552r_write_all_channels() argument
248 if (!dac->gpio_ldac) { in ad3552r_write_all_channels()
253 err = ad3552r_transfer(dac, addr, len, buff, false); in ad3552r_write_all_channels()
257 if (dac->gpio_ldac) in ad3552r_write_all_channels()
258 return ad3552r_trigger_hw_ldac(dac->gpio_ldac); in ad3552r_write_all_channels()
263 static int ad3552r_write_codes(struct ad3552r_desc *dac, u32 mask, u8 *data) in ad3552r_write_codes() argument
270 return ad3552r_write_all_channels(dac, data); in ad3552r_write_codes()
279 err = ad3552r_transfer(dac, addr, 3, data, false); in ad3552r_write_codes()
283 if (dac->gpio_ldac) in ad3552r_write_codes()
284 return ad3552r_trigger_hw_ldac(dac->gpio_ldac); in ad3552r_write_codes()
286 return ad3552r_write_reg(dac, AD3552R_REG_ADDR_SW_LDAC_24B, mask); in ad3552r_write_codes()
294 struct ad3552r_desc *dac = iio_priv(indio_dev); in ad3552r_trigger_handler() local
304 mutex_lock(&dac->lock); in ad3552r_trigger_handler()
305 ad3552r_write_codes(dac, *indio_dev->active_scan_mask, buff); in ad3552r_trigger_handler()
306 mutex_unlock(&dac->lock); in ad3552r_trigger_handler()
313 static int ad3552r_check_scratch_pad(struct ad3552r_desc *dac) in ad3552r_check_scratch_pad() argument
320 err = ad3552r_write_reg(dac, AD3552R_REG_ADDR_SCRATCH_PAD, val1); in ad3552r_check_scratch_pad()
324 err = ad3552r_read_reg(dac, AD3552R_REG_ADDR_SCRATCH_PAD, &val); in ad3552r_check_scratch_pad()
331 err = ad3552r_write_reg(dac, AD3552R_REG_ADDR_SCRATCH_PAD, val2); in ad3552r_check_scratch_pad()
335 err = ad3552r_read_reg(dac, AD3552R_REG_ADDR_SCRATCH_PAD, &val); in ad3552r_check_scratch_pad()
346 struct ad3552r_desc *dac; member
355 err = ad3552r_read_reg(addr->dac, addr->addr, &val); in ad3552r_read_reg_wrapper()
362 static int ad3552r_reset(struct ad3552r_desc *dac) in ad3552r_reset() argument
368 dac->gpio_reset = devm_gpiod_get_optional(&dac->spi->dev, "reset", in ad3552r_reset()
370 if (IS_ERR(dac->gpio_reset)) in ad3552r_reset()
371 return dev_err_probe(&dac->spi->dev, PTR_ERR(dac->gpio_reset), in ad3552r_reset()
374 if (dac->gpio_reset) { in ad3552r_reset()
377 gpiod_set_value_cansleep(dac->gpio_reset, 1); in ad3552r_reset()
380 ret = ad3552r_update_reg_field(dac, in ad3552r_reset()
389 addr.dac = dac; in ad3552r_reset()
398 dev_err(&dac->spi->dev, "Error while resetting"); in ad3552r_reset()
409 dev_err(&dac->spi->dev, "Error while resetting"); in ad3552r_reset()
413 return ad3552r_update_reg_field(dac, in ad3552r_reset()
419 static int ad3552r_configure_custom_gain(struct ad3552r_desc *dac, in ad3552r_configure_custom_gain() argument
423 struct device *dev = &dac->spi->dev; in ad3552r_configure_custom_gain()
429 &dac->ch_data[ch].p, in ad3552r_configure_custom_gain()
430 &dac->ch_data[ch].n, in ad3552r_configure_custom_gain()
431 &dac->ch_data[ch].rfb, in ad3552r_configure_custom_gain()
432 &dac->ch_data[ch].gain_offset); in ad3552r_configure_custom_gain()
436 dac->ch_data[ch].range_override = 1; in ad3552r_configure_custom_gain()
439 err = ad3552r_write_reg(dac, addr, in ad3552r_configure_custom_gain()
440 abs((s32)dac->ch_data[ch].gain_offset) & in ad3552r_configure_custom_gain()
445 reg = ad3552r_calc_custom_gain(dac->ch_data[ch].p, dac->ch_data[ch].n, in ad3552r_configure_custom_gain()
446 dac->ch_data[ch].gain_offset); in ad3552r_configure_custom_gain()
448 err = ad3552r_write_reg(dac, addr, reg); in ad3552r_configure_custom_gain()
455 static int ad3552r_configure_device(struct ad3552r_desc *dac) in ad3552r_configure_device() argument
457 struct device *dev = &dac->spi->dev; in ad3552r_configure_device()
461 dac->gpio_ldac = devm_gpiod_get_optional(dev, "ldac", GPIOD_OUT_HIGH); in ad3552r_configure_device()
462 if (IS_ERR(dac->gpio_ldac)) in ad3552r_configure_device()
463 return dev_err_probe(dev, PTR_ERR(dac->gpio_ldac), in ad3552r_configure_device()
470 err = ad3552r_update_reg_field(dac, in ad3552r_configure_device()
479 err = ad3552r_update_reg_field(dac, in ad3552r_configure_device()
487 dac->num_ch = device_get_child_node_count(dev); in ad3552r_configure_device()
488 if (!dac->num_ch) { in ad3552r_configure_device()
498 if (ch >= dac->model_data->num_hw_channels) in ad3552r_configure_device()
501 dac->model_data->num_hw_channels); in ad3552r_configure_device()
503 err = ad3552r_get_output_range(dev, dac->model_data, in ad3552r_configure_device()
514 err = ad3552r_update_reg_field(dac, in ad3552r_configure_device()
521 dac->ch_data[ch].range = val; in ad3552r_configure_device()
522 } else if (dac->model_data->requires_output_range) { in ad3552r_configure_device()
525 dac->model_data->model_name); in ad3552r_configure_device()
527 err = ad3552r_configure_custom_gain(dac, child, ch); in ad3552r_configure_device()
532 ad3552r_calc_gain_and_offset(&dac->ch_data[ch], dac->model_data); in ad3552r_configure_device()
533 dac->enabled_ch |= BIT(ch); in ad3552r_configure_device()
540 err = ad3552r_update_reg_field(dac, in ad3552r_configure_device()
546 dac->channels[cnt] = AD3552R_CH_DAC(ch); in ad3552r_configure_device()
552 for_each_clear_bit(ch, &dac->enabled_ch, in ad3552r_configure_device()
553 dac->model_data->num_hw_channels) { in ad3552r_configure_device()
559 err = ad3552r_update_reg_field(dac, in ad3552r_configure_device()
567 dac->num_ch = cnt; in ad3552r_configure_device()
572 static int ad3552r_init(struct ad3552r_desc *dac) in ad3552r_init() argument
577 err = ad3552r_reset(dac); in ad3552r_init()
579 dev_err(&dac->spi->dev, "Reset failed\n"); in ad3552r_init()
583 err = ad3552r_check_scratch_pad(dac); in ad3552r_init()
585 dev_err(&dac->spi->dev, "Scratch pad test failed\n"); in ad3552r_init()
589 err = ad3552r_read_reg(dac, AD3552R_REG_ADDR_PRODUCT_ID_L, &val); in ad3552r_init()
591 dev_err(&dac->spi->dev, "Fail read PRODUCT_ID_L\n"); in ad3552r_init()
596 err = ad3552r_read_reg(dac, AD3552R_REG_ADDR_PRODUCT_ID_H, &val); in ad3552r_init()
598 dev_err(&dac->spi->dev, "Fail read PRODUCT_ID_H\n"); in ad3552r_init()
603 if (id != dac->model_data->chip_id) { in ad3552r_init()
604 dev_err(&dac->spi->dev, "Product id not matching\n"); in ad3552r_init()
608 return ad3552r_configure_device(dac); in ad3552r_init()
613 struct ad3552r_desc *dac; in ad3552r_probe() local
617 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*dac)); in ad3552r_probe()
621 dac = iio_priv(indio_dev); in ad3552r_probe()
622 dac->spi = spi; in ad3552r_probe()
623 dac->model_data = spi_get_device_match_data(spi); in ad3552r_probe()
624 if (!dac->model_data) in ad3552r_probe()
627 mutex_init(&dac->lock); in ad3552r_probe()
629 err = ad3552r_init(dac); in ad3552r_probe()
634 indio_dev->name = dac->model_data->model_name; in ad3552r_probe()
637 indio_dev->num_channels = dac->num_ch; in ad3552r_probe()
638 indio_dev->channels = dac->channels; in ad3552r_probe()