Lines Matching +full:dac +full:- +full:mode +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ti-dac082s085.c - Texas Instruments 8/10/12-bit 2/4-channel DAC driver
38 * struct ti_dac_chip - TI DAC chip
64 #define POWERDOWN(mode) (0x30 | ((mode) + 1) << 6) argument
68 u8 shift = 12 - ti_dac->resolution; in ti_dac_cmd()
70 ti_dac->buf[0] = cmd | (val >> (8 - shift)); in ti_dac_cmd()
71 ti_dac->buf[1] = (val << shift) & 0xff; in ti_dac_cmd()
72 return spi_sync(ti_dac->mesg.spi, &ti_dac->mesg); in ti_dac_cmd()
84 return ti_dac->powerdown_mode; in ti_dac_get_powerdown_mode()
89 unsigned int mode) in ti_dac_set_powerdown_mode() argument
94 if (ti_dac->powerdown_mode == mode) in ti_dac_set_powerdown_mode()
97 mutex_lock(&ti_dac->lock); in ti_dac_set_powerdown_mode()
98 if (ti_dac->powerdown) { in ti_dac_set_powerdown_mode()
99 ret = ti_dac_cmd(ti_dac, POWERDOWN(mode), 0); in ti_dac_set_powerdown_mode()
103 ti_dac->powerdown_mode = mode; in ti_dac_set_powerdown_mode()
106 mutex_unlock(&ti_dac->lock); in ti_dac_set_powerdown_mode()
124 return sysfs_emit(buf, "%d\n", ti_dac->powerdown); in ti_dac_read_powerdown()
140 if (ti_dac->powerdown == powerdown) in ti_dac_write_powerdown()
143 mutex_lock(&ti_dac->lock); in ti_dac_write_powerdown()
145 ret = ti_dac_cmd(ti_dac, POWERDOWN(ti_dac->powerdown_mode), 0); in ti_dac_write_powerdown()
147 ret = ti_dac_cmd(ti_dac, WRITE_AND_UPDATE(0), ti_dac->val[0]); in ti_dac_write_powerdown()
149 ti_dac->powerdown = powerdown; in ti_dac_write_powerdown()
150 mutex_unlock(&ti_dac->lock); in ti_dac_write_powerdown()
188 int *val, int *val2, long mask) in ti_dac_read_raw() argument
193 switch (mask) { in ti_dac_read_raw()
195 *val = ti_dac->val[chan->channel]; in ti_dac_read_raw()
200 ret = regulator_get_voltage(ti_dac->vref); in ti_dac_read_raw()
205 *val2 = ti_dac->resolution; in ti_dac_read_raw()
210 ret = -EINVAL; in ti_dac_read_raw()
218 int val, int val2, long mask) in ti_dac_write_raw() argument
223 switch (mask) { in ti_dac_write_raw()
225 if (ti_dac->val[chan->channel] == val) in ti_dac_write_raw()
228 if (val >= (1 << ti_dac->resolution) || val < 0) in ti_dac_write_raw()
229 return -EINVAL; in ti_dac_write_raw()
231 if (ti_dac->powerdown) in ti_dac_write_raw()
232 return -EBUSY; in ti_dac_write_raw()
234 mutex_lock(&ti_dac->lock); in ti_dac_write_raw()
235 ret = ti_dac_cmd(ti_dac, WRITE_AND_UPDATE(chan->channel), val); in ti_dac_write_raw()
237 ti_dac->val[chan->channel] = val; in ti_dac_write_raw()
238 mutex_unlock(&ti_dac->lock); in ti_dac_write_raw()
242 ret = -EINVAL; in ti_dac_write_raw()
249 struct iio_chan_spec const *chan, long mask) in ti_dac_write_raw_get_fmt() argument
262 struct device *dev = &spi->dev; in ti_dac_probe()
270 return -ENOMEM; in ti_dac_probe()
272 indio_dev->info = &ti_dac_info; in ti_dac_probe()
273 indio_dev->name = spi->modalias; in ti_dac_probe()
274 indio_dev->modes = INDIO_DIRECT_MODE; in ti_dac_probe()
275 indio_dev->channels = ti_dac_channels; in ti_dac_probe()
279 ti_dac->xfer.tx_buf = &ti_dac->buf; in ti_dac_probe()
280 ti_dac->xfer.len = sizeof(ti_dac->buf); in ti_dac_probe()
281 spi_message_init_with_transfers(&ti_dac->mesg, &ti_dac->xfer, 1); in ti_dac_probe()
282 ti_dac->mesg.spi = spi; in ti_dac_probe()
284 spec = &ti_dac_spec[spi_get_device_id(spi)->driver_data]; in ti_dac_probe()
285 indio_dev->num_channels = spec->num_channels; in ti_dac_probe()
286 ti_dac->resolution = spec->resolution; in ti_dac_probe()
288 ti_dac->vref = devm_regulator_get(dev, "vref"); in ti_dac_probe()
289 if (IS_ERR(ti_dac->vref)) in ti_dac_probe()
290 return PTR_ERR(ti_dac->vref); in ti_dac_probe()
292 ret = regulator_enable(ti_dac->vref); in ti_dac_probe()
296 mutex_init(&ti_dac->lock); in ti_dac_probe()
311 mutex_destroy(&ti_dac->lock); in ti_dac_probe()
312 regulator_disable(ti_dac->vref); in ti_dac_probe()
322 mutex_destroy(&ti_dac->lock); in ti_dac_remove()
323 regulator_disable(ti_dac->vref); in ti_dac_remove()
350 .name = "ti-dac082s085",
360 MODULE_DESCRIPTION("Texas Instruments 8/10/12-bit 2/4-channel DAC driver");