Lines Matching +full:dc +full:- +full:dc +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
3 * AD5755, AD5755-1, AD5757, AD5735, AD5737 Digital to analog converters driver
128 * struct ad5755_platform_data - AD5755 DAC driver platform data
129 * @ext_dc_dc_compenstation_resistor: Whether an external DC-DC converter
131 * @dc_dc_phase: DC-DC converter phase.
132 * @dc_dc_freq: DC-DC converter frequency.
133 * @dc_dc_maxv: DC-DC maximum allowed boost voltage.
135 * @dac.mode: The mode to be used for the DAC output.
150 enum ad5755_mode mode; member
162 * struct ad5755_chip_info - chip specific information
174 * struct ad5755_state - driver instance specific data
257 st->data[0].d32 = cpu_to_be32((reg << 16) | val); in ad5755_write_unlocked()
259 return spi_write(st->spi, &st->data[0].d8[1], 3); in ad5755_write_unlocked()
275 mutex_lock(&st->lock); in ad5755_write()
277 mutex_unlock(&st->lock); in ad5755_write()
288 mutex_lock(&st->lock); in ad5755_write_ctrl()
290 mutex_unlock(&st->lock); in ad5755_write_ctrl()
301 .tx_buf = &st->data[0].d8[1], in ad5755_read()
305 .tx_buf = &st->data[1].d8[1], in ad5755_read()
306 .rx_buf = &st->data[1].d8[1], in ad5755_read()
311 mutex_lock(&st->lock); in ad5755_read()
313 st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16)); in ad5755_read()
314 st->data[1].d32 = cpu_to_be32(AD5755_NOOP); in ad5755_read()
316 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); in ad5755_read()
318 ret = be32_to_cpu(st->data[1].d32) & 0xffff; in ad5755_read()
320 mutex_unlock(&st->lock); in ad5755_read()
331 st->ctrl[channel] |= set; in ad5755_update_dac_ctrl()
332 st->ctrl[channel] &= ~clr; in ad5755_update_dac_ctrl()
335 AD5755_CTRL_REG_DAC, st->ctrl[channel]); in ad5755_update_dac_ctrl()
346 mutex_lock(&st->lock); in ad5755_set_channel_pwr_down()
348 if ((bool)(st->pwr_down & mask) == pwr_down) in ad5755_set_channel_pwr_down()
352 st->pwr_down &= ~mask; in ad5755_set_channel_pwr_down()
359 st->pwr_down |= mask; in ad5755_set_channel_pwr_down()
366 mutex_unlock(&st->lock); in ad5755_set_channel_pwr_down()
374 [AD5755_MODE_VOLTAGE_PLUSMINUS_5V] = { -5000, 5000 },
375 [AD5755_MODE_VOLTAGE_PLUSMINUS_10V] = { -10000, 10000 },
384 enum ad5755_mode mode = st->ctrl[chan->channel] & 7; in ad5755_get_min_max() local
385 *min = ad5755_min_max_table[mode][0]; in ad5755_get_min_max()
386 *max = ad5755_min_max_table[mode][1]; in ad5755_get_min_max()
395 return (min * (1 << chan->scan_type.realbits)) / (max - min); in ad5755_get_offset()
405 *reg = AD5755_WRITE_REG_DATA(chan->address); in ad5755_chan_reg_info()
407 *reg = AD5755_READ_REG_DATA(chan->address); in ad5755_chan_reg_info()
408 *shift = chan->scan_type.shift; in ad5755_chan_reg_info()
413 *reg = AD5755_WRITE_REG_OFFSET(chan->address); in ad5755_chan_reg_info()
415 *reg = AD5755_READ_REG_OFFSET(chan->address); in ad5755_chan_reg_info()
416 *shift = st->chip_info->calib_shift; in ad5755_chan_reg_info()
421 *reg = AD5755_WRITE_REG_GAIN(chan->address); in ad5755_chan_reg_info()
423 *reg = AD5755_READ_REG_GAIN(chan->address); in ad5755_chan_reg_info()
424 *shift = st->chip_info->calib_shift; in ad5755_chan_reg_info()
428 return -EINVAL; in ad5755_chan_reg_info()
445 *val = max - min; in ad5755_read_raw()
446 *val2 = chan->scan_type.realbits; in ad5755_read_raw()
461 *val = (ret - offset) >> shift; in ad5755_read_raw()
466 return -EINVAL; in ad5755_read_raw()
485 return -EINVAL; in ad5755_write_raw()
496 (bool)(st->pwr_down & (1 << chan->channel))); in ad5755_read_powerdown()
509 ret = ad5755_set_channel_pwr_down(indio_dev, chan->channel, pwr_down); in ad5755_write_powerdown()
540 .shift = 16 - (_bits), \
568 static bool ad5755_is_valid_mode(struct ad5755_state *st, enum ad5755_mode mode) in ad5755_is_valid_mode() argument
570 switch (mode) { in ad5755_is_valid_mode()
575 return st->chip_info->has_voltage_out; in ad5755_is_valid_mode()
593 if (pdata->dc_dc_phase > AD5755_DC_DC_PHASE_90_DEGREE || in ad5755_setup_pdata()
594 pdata->dc_dc_freq > AD5755_DC_DC_FREQ_650kHZ || in ad5755_setup_pdata()
595 pdata->dc_dc_maxv > AD5755_DC_DC_MAXV_29V5) in ad5755_setup_pdata()
596 return -EINVAL; in ad5755_setup_pdata()
598 val = pdata->dc_dc_maxv << AD5755_DC_DC_MAXV; in ad5755_setup_pdata()
599 val |= pdata->dc_dc_freq << AD5755_DC_DC_FREQ_SHIFT; in ad5755_setup_pdata()
600 val |= pdata->dc_dc_phase << AD5755_DC_DC_PHASE_SHIFT; in ad5755_setup_pdata()
601 if (pdata->ext_dc_dc_compenstation_resistor) in ad5755_setup_pdata()
608 for (i = 0; i < ARRAY_SIZE(pdata->dac); ++i) { in ad5755_setup_pdata()
609 val = pdata->dac[i].slew.step_size << in ad5755_setup_pdata()
611 val |= pdata->dac[i].slew.rate << in ad5755_setup_pdata()
613 if (pdata->dac[i].slew.enable) in ad5755_setup_pdata()
622 for (i = 0; i < ARRAY_SIZE(pdata->dac); ++i) { in ad5755_setup_pdata()
623 if (!ad5755_is_valid_mode(st, pdata->dac[i].mode)) in ad5755_setup_pdata()
624 return -EINVAL; in ad5755_setup_pdata()
627 if (!pdata->dac[i].ext_current_sense_resistor) in ad5755_setup_pdata()
629 if (pdata->dac[i].enable_voltage_overrange) in ad5755_setup_pdata()
631 val |= pdata->dac[i].mode; in ad5755_setup_pdata()
641 static bool ad5755_is_voltage_mode(enum ad5755_mode mode) in ad5755_is_voltage_mode() argument
643 switch (mode) { in ad5755_is_voltage_mode()
658 struct iio_chan_spec *channels = st->channels; in ad5755_init_channels()
662 channels[i] = st->chip_info->channel_template; in ad5755_init_channels()
665 if (pdata && ad5755_is_voltage_mode(pdata->dac[i].mode)) in ad5755_init_channels()
671 indio_dev->channels = channels; in ad5755_init_channels()
677 .mode = AD5755_MODE_CURRENT_4mA_20mA, \
715 pdata->ext_dc_dc_compenstation_resistor = in ad5755_parse_fw()
716 device_property_read_bool(dev, "adi,ext-dc-dc-compenstation-resistor"); in ad5755_parse_fw()
718 pdata->dc_dc_phase = AD5755_DC_DC_PHASE_ALL_SAME_EDGE; in ad5755_parse_fw()
719 device_property_read_u32(dev, "adi,dc-dc-phase", &pdata->dc_dc_phase); in ad5755_parse_fw()
721 pdata->dc_dc_freq = AD5755_DC_DC_FREQ_410kHZ; in ad5755_parse_fw()
722 if (!device_property_read_u32(dev, "adi,dc-dc-freq-hz", &tmp)) { in ad5755_parse_fw()
725 pdata->dc_dc_freq = ad5755_dcdc_freq_table[i][1]; in ad5755_parse_fw()
732 "adi,dc-dc-freq out of range selecting 410kHz\n"); in ad5755_parse_fw()
735 pdata->dc_dc_maxv = AD5755_DC_DC_MAXV_23V; in ad5755_parse_fw()
736 if (!device_property_read_u32(dev, "adi,dc-dc-max-microvolt", &tmp)) { in ad5755_parse_fw()
739 pdata->dc_dc_maxv = ad5755_dcdc_maxv_table[i][1]; in ad5755_parse_fw()
745 "adi,dc-dc-maxv out of range selecting 23V\n"); in ad5755_parse_fw()
756 pdata->dac[devnr].mode = AD5755_MODE_CURRENT_4mA_20mA; in ad5755_parse_fw()
757 fwnode_property_read_u32(pp, "adi,mode", &pdata->dac[devnr].mode); in ad5755_parse_fw()
759 pdata->dac[devnr].ext_current_sense_resistor = in ad5755_parse_fw()
760 fwnode_property_read_bool(pp, "adi,ext-current-sense-resistor"); in ad5755_parse_fw()
762 pdata->dac[devnr].enable_voltage_overrange = in ad5755_parse_fw()
763 fwnode_property_read_bool(pp, "adi,enable-voltage-overrange"); in ad5755_parse_fw()
766 pdata->dac[devnr].slew.enable = tmparray[0]; in ad5755_parse_fw()
768 pdata->dac[devnr].slew.rate = AD5755_SLEW_RATE_64k; in ad5755_parse_fw()
771 pdata->dac[devnr].slew.rate = in ad5755_parse_fw()
781 pdata->dac[devnr].slew.step_size = AD5755_SLEW_STEP_SIZE_1; in ad5755_parse_fw()
784 pdata->dac[devnr].slew.step_size = in ad5755_parse_fw()
794 pdata->dac[devnr].slew.enable = false; in ad5755_parse_fw()
795 pdata->dac[devnr].slew.rate = AD5755_SLEW_RATE_64k; in ad5755_parse_fw()
796 pdata->dac[devnr].slew.step_size = in ad5755_parse_fw()
812 enum ad5755_type type = spi_get_device_id(spi)->driver_data; in ad5755_probe()
818 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad5755_probe()
820 dev_err(&spi->dev, "Failed to allocate iio device\n"); in ad5755_probe()
821 return -ENOMEM; in ad5755_probe()
827 st->chip_info = &ad5755_chip_info_tbl[type]; in ad5755_probe()
828 st->spi = spi; in ad5755_probe()
829 st->pwr_down = 0xf; in ad5755_probe()
831 indio_dev->name = spi_get_device_id(spi)->name; in ad5755_probe()
832 indio_dev->info = &ad5755_info; in ad5755_probe()
833 indio_dev->modes = INDIO_DIRECT_MODE; in ad5755_probe()
834 indio_dev->num_channels = AD5755_NUM_CHANNELS; in ad5755_probe()
836 mutex_init(&st->lock); in ad5755_probe()
839 pdata = ad5755_parse_fw(&spi->dev); in ad5755_probe()
841 dev_warn(&spi->dev, "no firmware provided parameters? using default\n"); in ad5755_probe()
853 return devm_iio_device_register(&spi->dev, indio_dev); in ad5755_probe()
858 { "ad5755-1", ID_AD5755 },
868 { .compatible = "adi,ad5755-1" },
885 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
886 MODULE_DESCRIPTION("Analog Devices AD5755/55-1/57/35/37 DAC");