Lines Matching +full:vout +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0-only
4 * multi-channel Digital to Analog Converters driver
50 * struct ad5360_chip_info - chip specific information
65 * struct ad5360_state - driver instance specific data
68 * @vref_reg: vref supply regulators
115 .shift = 16 - (bits), \
177 i = channel / st->chip_info->channels_per_group; in ad5360_get_channel_vref_index()
178 if (i >= st->chip_info->num_vrefs) in ad5360_get_channel_vref_index()
179 i = st->chip_info->num_vrefs - 1; in ad5360_get_channel_vref_index()
189 return regulator_get_voltage(st->vref_reg[i].consumer); in ad5360_get_channel_vref()
201 st->data[0].d32 = cpu_to_be32(val); in ad5360_write_unlocked()
203 return spi_write(st->spi, &st->data[0].d8[1], 3); in ad5360_write_unlocked()
212 mutex_lock(&st->lock); in ad5360_write()
214 mutex_unlock(&st->lock); in ad5360_write()
226 .tx_buf = &st->data[0].d8[1], in ad5360_read()
230 .rx_buf = &st->data[1].d8[1], in ad5360_read()
235 mutex_lock(&st->lock); in ad5360_read()
237 st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) | in ad5360_read()
242 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); in ad5360_read()
244 ret = be32_to_cpu(st->data[1].d32) & 0xffff; in ad5360_read()
246 mutex_unlock(&st->lock); in ad5360_read()
258 return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN)); in ad5360_read_dac_powerdown()
267 mutex_lock(&st->lock); in ad5360_update_ctrl()
269 st->ctrl |= set; in ad5360_update_ctrl()
270 st->ctrl &= ~clr; in ad5360_update_ctrl()
273 AD5360_REG_SF_CTRL, st->ctrl, 0); in ad5360_update_ctrl()
275 mutex_unlock(&st->lock); in ad5360_update_ctrl()
320 int max_val = (1 << chan->scan_type.realbits); in ad5360_write_raw()
326 return -EINVAL; in ad5360_write_raw()
329 chan->address, val, chan->scan_type.shift); in ad5360_write_raw()
333 return -EINVAL; in ad5360_write_raw()
336 chan->address, val, chan->scan_type.shift); in ad5360_write_raw()
340 return -EINVAL; in ad5360_write_raw()
343 chan->address, val, chan->scan_type.shift); in ad5360_write_raw()
346 if (val <= -max_val || val > 0) in ad5360_write_raw()
347 return -EINVAL; in ad5360_write_raw()
349 val = -val; in ad5360_write_raw()
354 val >>= (chan->scan_type.realbits - 14); in ad5360_write_raw()
358 * channels which share the same vref supply. */ in ad5360_write_raw()
359 ofs_index = ad5360_get_channel_vref_index(st, chan->channel); in ad5360_write_raw()
366 return -EINVAL; in ad5360_write_raw()
383 chan->address); in ad5360_read_raw()
386 *val = ret >> chan->scan_type.shift; in ad5360_read_raw()
389 scale_uv = ad5360_get_channel_vref(st, chan->channel); in ad5360_read_raw()
393 /* vout = 4 * vref * dac_code */ in ad5360_read_raw()
395 *val2 = chan->scan_type.realbits; in ad5360_read_raw()
399 chan->address); in ad5360_read_raw()
406 chan->address); in ad5360_read_raw()
412 ofs_index = ad5360_get_channel_vref_index(st, chan->channel); in ad5360_read_raw()
418 ret <<= (chan->scan_type.realbits - 14); in ad5360_read_raw()
419 *val = -ret; in ad5360_read_raw()
423 return -EINVAL; in ad5360_read_raw()
442 channels = kcalloc(st->chip_info->num_channels, in ad5360_alloc_channels()
446 return -ENOMEM; in ad5360_alloc_channels()
448 for (i = 0; i < st->chip_info->num_channels; ++i) { in ad5360_alloc_channels()
449 channels[i] = st->chip_info->channel_template; in ad5360_alloc_channels()
454 indio_dev->channels = channels; in ad5360_alloc_channels()
461 enum ad5360_type type = spi_get_device_id(spi)->driver_data; in ad5360_probe()
467 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad5360_probe()
469 dev_err(&spi->dev, "Failed to allocate iio device\n"); in ad5360_probe()
470 return -ENOMEM; in ad5360_probe()
476 st->chip_info = &ad5360_chip_info_tbl[type]; in ad5360_probe()
477 st->spi = spi; in ad5360_probe()
479 indio_dev->name = spi_get_device_id(spi)->name; in ad5360_probe()
480 indio_dev->info = &ad5360_info; in ad5360_probe()
481 indio_dev->modes = INDIO_DIRECT_MODE; in ad5360_probe()
482 indio_dev->num_channels = st->chip_info->num_channels; in ad5360_probe()
484 mutex_init(&st->lock); in ad5360_probe()
488 dev_err(&spi->dev, "Failed to allocate channel spec: %d\n", ret); in ad5360_probe()
492 for (i = 0; i < st->chip_info->num_vrefs; ++i) in ad5360_probe()
493 st->vref_reg[i].supply = ad5360_vref_name[i]; in ad5360_probe()
495 ret = devm_regulator_bulk_get(&st->spi->dev, st->chip_info->num_vrefs, in ad5360_probe()
496 st->vref_reg); in ad5360_probe()
498 dev_err(&spi->dev, "Failed to request vref regulators: %d\n", ret); in ad5360_probe()
502 ret = regulator_bulk_enable(st->chip_info->num_vrefs, st->vref_reg); in ad5360_probe()
504 dev_err(&spi->dev, "Failed to enable vref regulators: %d\n", ret); in ad5360_probe()
510 dev_err(&spi->dev, "Failed to register iio device: %d\n", ret); in ad5360_probe()
517 regulator_bulk_disable(st->chip_info->num_vrefs, st->vref_reg); in ad5360_probe()
519 kfree(indio_dev->channels); in ad5360_probe()
531 kfree(indio_dev->channels); in ad5360_remove()
533 regulator_bulk_disable(st->chip_info->num_vrefs, st->vref_reg); in ad5360_remove()
559 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");