Lines Matching +full:write +full:- +full:protect

1 // SPDX-License-Identifier: GPL-2.0
3 * DAC7612 Dual, 12-Bit Serial input Digital-to-Analog Converter
8 * Licensed under the GPL-2.
26 * Lock to protect the state of the device from potential concurrent
27 * write accesses from userspace. The write operation requires an
28 * SPI write, then toggling of a GPIO, so the lock aims to protect
44 priv->data[0] = BIT(DAC7612_START) | (channel << DAC7612_ADDRESS); in dac7612_cmd_single()
45 priv->data[0] |= val >> 8; in dac7612_cmd_single()
46 priv->data[1] = val & 0xff; in dac7612_cmd_single()
48 priv->cache[channel] = val; in dac7612_cmd_single()
50 ret = spi_write(priv->spi, priv->data, sizeof(priv->data)); in dac7612_cmd_single()
54 gpiod_set_value(priv->loaddacs, 1); in dac7612_cmd_single()
55 gpiod_set_value(priv->loaddacs, 0); in dac7612_cmd_single()
84 *val = priv->cache[chan->channel]; in dac7612_read_raw()
92 return -EINVAL; in dac7612_read_raw()
104 return -EINVAL; in dac7612_write_raw()
107 return -EINVAL; in dac7612_write_raw()
109 if (val == priv->cache[chan->channel]) in dac7612_write_raw()
112 mutex_lock(&priv->lock); in dac7612_write_raw()
113 ret = dac7612_cmd_single(priv, chan->channel, val); in dac7612_write_raw()
114 mutex_unlock(&priv->lock); in dac7612_write_raw()
131 iio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*priv)); in dac7612_probe()
133 return -ENOMEM; in dac7612_probe()
139 * every write. in dac7612_probe()
144 priv->loaddacs = devm_gpiod_get_optional(&spi->dev, "ti,loaddacs", in dac7612_probe()
146 if (IS_ERR(priv->loaddacs)) in dac7612_probe()
147 return PTR_ERR(priv->loaddacs); in dac7612_probe()
148 priv->spi = spi; in dac7612_probe()
150 iio_dev->info = &dac7612_info; in dac7612_probe()
151 iio_dev->modes = INDIO_DIRECT_MODE; in dac7612_probe()
152 iio_dev->channels = dac7612_channels; in dac7612_probe()
153 iio_dev->num_channels = ARRAY_SIZE(priv->cache); in dac7612_probe()
154 iio_dev->name = spi_get_device_id(spi)->name; in dac7612_probe()
156 mutex_init(&priv->lock); in dac7612_probe()
158 for (i = 0; i < ARRAY_SIZE(priv->cache); i++) { in dac7612_probe()
164 return devm_iio_device_register(&spi->dev, iio_dev); in dac7612_probe()
168 {"ti-dac7612"},
183 .name = "ti-dac7612",