Lines Matching +full:x +full:- +full:min
1 // SPDX-License-Identifier: GPL-2.0
52 #define AD5758_DAC_CONFIG_RANGE_MODE(x) (((x) & 0xF) << 0) argument
54 #define AD5758_DAC_CONFIG_INT_EN_MODE(x) (((x) & 0x1) << 5) argument
56 #define AD5758_DAC_CONFIG_OUT_EN_MODE(x) (((x) & 0x1) << 6) argument
58 #define AD5758_DAC_CONFIG_SR_EN_MODE(x) (((x) & 0x1) << 8) argument
60 #define AD5758_DAC_CONFIG_SR_CLOCK_MODE(x) (((x) & 0xF) << 9) argument
62 #define AD5758_DAC_CONFIG_SR_STEP_MODE(x) (((x) & 0x7) << 13) argument
73 #define AD5758_DCDC_CONFIG1_DCDC_VPROG_MODE(x) (((x) & 0x1F) << 0) argument
75 #define AD5758_DCDC_CONFIG1_DCDC_MODE_MODE(x) (((x) & 0x3) << 5) argument
79 #define AD5758_DCDC_CONFIG2_ILIMIT_MODE(x) (((x) & 0x7) << 1) argument
87 #define AD5758_ADC_CONFIG_PPC_BUF_EN(x) (((x) & 0x1) << 11) argument
90 #define AD5758_WR_FLAG_MSK(x) (0x80 | ((x) & 0x1F)) argument
96 int min; member
101 * struct ad5758_state - driver instance specific data
107 * @dc_dc_ilim: variable which stores the dc-to-dc converter current limit
135 * 1101: -1 mA to +22 mA current range
160 { AD5758_RANGE_PLUSMINUS_5V, -5000000, 5000000 },
161 { AD5758_RANGE_PLUSMINUS_10V, -10000000, 10000000 }
168 { AD5758_RANGE_PLUSMINUS_20mA, -20000, 20000 },
169 { AD5758_RANGE_PLUSMINUS_24mA, -24000, 24000 },
170 { AD5758_RANGE_MINUS_1mA_PLUS_22mA, -1000, 22000 },
190 .tx_buf = &st->d32[0], in ad5758_spi_reg_read()
194 .tx_buf = &st->d32[1], in ad5758_spi_reg_read()
195 .rx_buf = &st->d32[2], in ad5758_spi_reg_read()
201 st->d32[0] = cpu_to_be32( in ad5758_spi_reg_read()
204 st->d32[1] = cpu_to_be32(AD5758_WR_FLAG_MSK(AD5758_NOP) << 24); in ad5758_spi_reg_read()
206 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); in ad5758_spi_reg_read()
210 return (be32_to_cpu(st->d32[2]) >> 8) & 0xFFFF; in ad5758_spi_reg_read()
217 st->d32[0] = cpu_to_be32((AD5758_WR_FLAG_MSK(addr) << 24) | in ad5758_spi_reg_write()
220 return spi_write(st->spi, &st->d32[0], sizeof(st->d32[0])); in ad5758_spi_reg_write()
242 return *(int *)a - *(int *)b; in cmpfunc()
255 return size - 1; in ad5758_find_closest_match()
275 } while (--timeout); in ad5758_wait_for_task_complete()
277 dev_err(&st->spi->dev, in ad5758_wait_for_task_complete()
278 "Error reading bit 0x%x in 0x%x register\n", mask, reg); in ad5758_wait_for_task_complete()
280 return -EIO; in ad5758_wait_for_task_complete()
290 dev_err(&st->spi->dev, in ad5758_calib_mem_refresh()
341 * This allows the 3-wire interface communication to complete. in ad5758_set_dc_dc_conv_mode()
348 st->dc_dc_mode = mode; in ad5758_set_dc_dc_conv_mode()
364 * This allows the 3-wire interface communication to complete. in ad5758_set_dc_dc_ilim()
406 * Slew Time = (Full Scale Out / (Step Size x Update Clk Freq)) in ad5758_slew_rate_config()
419 do_div(sr_step, st->slew_time); in ad5758_slew_rate_config()
436 diff_new = abs(st->slew_time - calc_slew_time); in ad5758_slew_rate_config()
479 if (st->gpio_reset) { in ad5758_reset()
480 gpiod_set_value(st->gpio_reset, 0); in ad5758_reset()
482 gpiod_set_value(st->gpio_reset, 1); in ad5758_reset()
500 mutex_lock(&st->lock); in ad5758_reg_access()
504 mutex_unlock(&st->lock); in ad5758_reg_access()
513 mutex_unlock(&st->lock); in ad5758_reg_access()
523 int max, min, ret; in ad5758_read_raw() local
527 mutex_lock(&st->lock); in ad5758_read_raw()
529 mutex_unlock(&st->lock); in ad5758_read_raw()
536 min = st->out_range.min; in ad5758_read_raw()
537 max = st->out_range.max; in ad5758_read_raw()
538 *val = (max - min) / 1000; in ad5758_read_raw()
542 min = st->out_range.min; in ad5758_read_raw()
543 max = st->out_range.max; in ad5758_read_raw()
544 *val = ((min * (1 << 16)) / (max - min)) / 1000; in ad5758_read_raw()
547 return -EINVAL; in ad5758_read_raw()
560 mutex_lock(&st->lock); in ad5758_write_raw()
562 mutex_unlock(&st->lock); in ad5758_write_raw()
565 return -EINVAL; in ad5758_write_raw()
576 return sysfs_emit(buf, "%d\n", st->pwr_down); in ad5758_read_powerdown()
594 mutex_lock(&st->lock); in ad5758_write_powerdown()
611 st->pwr_down = pwr_down; in ad5758_write_powerdown()
614 mutex_unlock(&st->lock); in ad5758_write_powerdown()
670 st->d32[0] = cpu_to_be32(mask); in ad5758_crc_disable()
672 return spi_write(st->spi, &st->d32[0], 4); in ad5758_crc_disable()
678 int min, int max) in ad5758_find_out_range() argument
683 if ((min == range[i].min) && (max == range[i].max)) { in ad5758_find_out_range()
684 st->out_range.reg = range[i].reg; in ad5758_find_out_range()
685 st->out_range.min = range[i].min; in ad5758_find_out_range()
686 st->out_range.max = range[i].max; in ad5758_find_out_range()
692 return -EINVAL; in ad5758_find_out_range()
701 st->dc_dc_ilim = 0; in ad5758_parse_dt()
702 ret = device_property_read_u32(&st->spi->dev, in ad5758_parse_dt()
703 "adi,dc-dc-ilim-microamp", &tmp); in ad5758_parse_dt()
705 dev_dbg(&st->spi->dev, in ad5758_parse_dt()
706 "Missing \"dc-dc-ilim-microamp\" property\n"); in ad5758_parse_dt()
712 dev_dbg(&st->spi->dev, "dc-dc-ilim out of range\n"); in ad5758_parse_dt()
714 st->dc_dc_ilim = index - ad5758_dc_dc_ilim; in ad5758_parse_dt()
717 ret = device_property_read_u32(&st->spi->dev, "adi,dc-dc-mode", in ad5758_parse_dt()
718 &st->dc_dc_mode); in ad5758_parse_dt()
720 dev_err(&st->spi->dev, "Missing \"dc-dc-mode\" property\n"); in ad5758_parse_dt()
724 if (!ad5758_is_valid_mode(st->dc_dc_mode)) in ad5758_parse_dt()
725 return -EINVAL; in ad5758_parse_dt()
727 if (st->dc_dc_mode == AD5758_DCDC_MODE_DPC_VOLTAGE) { in ad5758_parse_dt()
728 ret = device_property_read_u32_array(&st->spi->dev, in ad5758_parse_dt()
729 "adi,range-microvolt", in ad5758_parse_dt()
732 dev_err(&st->spi->dev, in ad5758_parse_dt()
733 "Missing \"range-microvolt\" property\n"); in ad5758_parse_dt()
739 ret = device_property_read_u32_array(&st->spi->dev, in ad5758_parse_dt()
740 "adi,range-microamp", in ad5758_parse_dt()
743 dev_err(&st->spi->dev, in ad5758_parse_dt()
744 "Missing \"range-microamp\" property\n"); in ad5758_parse_dt()
753 dev_err(&st->spi->dev, "range invalid\n"); in ad5758_parse_dt()
757 ret = device_property_read_u32(&st->spi->dev, "adi,slew-time-us", &tmp); in ad5758_parse_dt()
759 dev_dbg(&st->spi->dev, "Missing \"slew-time-us\" property\n"); in ad5758_parse_dt()
760 st->slew_time = 0; in ad5758_parse_dt()
762 st->slew_time = tmp; in ad5758_parse_dt()
772 st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset", in ad5758_init()
774 if (IS_ERR(st->gpio_reset)) in ad5758_init()
775 return PTR_ERR(st->gpio_reset); in ad5758_init()
806 /* Set the dc-to-dc current limit */ in ad5758_init()
807 ret = ad5758_set_dc_dc_ilim(st, st->dc_dc_ilim); in ad5758_init()
811 /* Configure the dc-to-dc controller mode */ in ad5758_init()
812 ret = ad5758_set_dc_dc_conv_mode(st, st->dc_dc_mode); in ad5758_init()
817 ret = ad5758_set_out_range(st, st->out_range.reg); in ad5758_init()
822 if (st->slew_time) { in ad5758_init()
845 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad5758_probe()
847 return -ENOMEM; in ad5758_probe()
852 st->spi = spi; in ad5758_probe()
854 mutex_init(&st->lock); in ad5758_probe()
856 indio_dev->name = spi_get_device_id(spi)->name; in ad5758_probe()
857 indio_dev->info = &ad5758_info; in ad5758_probe()
858 indio_dev->modes = INDIO_DIRECT_MODE; in ad5758_probe()
859 indio_dev->num_channels = 1; in ad5758_probe()
865 if (st->dc_dc_mode == AD5758_DCDC_MODE_DPC_VOLTAGE) in ad5758_probe()
866 indio_dev->channels = ad5758_voltage_ch; in ad5758_probe()
868 indio_dev->channels = ad5758_current_ch; in ad5758_probe()
872 dev_err(&spi->dev, "AD5758 init failed\n"); in ad5758_probe()
876 return devm_iio_device_register(&st->spi->dev, indio_dev); in ad5758_probe()