Lines Matching +full:vref +full:- +full:p
1 // SPDX-License-Identifier: GPL-2.0
13 * divided voltage is provided by a vref regulator.
15 * .------.
16 * .-----------. | |
17 * | vref |--' .---.
18 * | regulator |--. | |
19 * '-----------' | | d |
20 * | | p |
22 * | | t |<---------+
24 * | '---' dac output voltage
26 * '------+------------+
38 struct regulator *vref; member
62 return iio_read_channel_raw(dac->dpot, val); in dpot_dac_read_raw()
65 ret = iio_read_channel_scale(dac->dpot, val, val2); in dpot_dac_read_raw()
69 do_div(tmp, dac->max_ohms); in dpot_dac_read_raw()
70 tmp *= regulator_get_voltage(dac->vref) / 1000; in dpot_dac_read_raw()
84 *val *= regulator_get_voltage(dac->vref) / 1000; in dpot_dac_read_raw()
85 *val2 *= dac->max_ohms; in dpot_dac_read_raw()
92 return -EINVAL; in dpot_dac_read_raw()
105 return iio_read_avail_channel_raw(dac->dpot, vals, length); in dpot_dac_read_avail()
108 return -EINVAL; in dpot_dac_read_avail()
119 return iio_write_channel_raw(dac->dpot, val); in dpot_dac_write_raw()
122 return -EINVAL; in dpot_dac_write_raw()
133 struct device *dev = &indio_dev->dev; in dpot_dac_channel_max_ohms()
141 ret = iio_read_max_channel_raw(dac->dpot, &max); in dpot_dac_channel_max_ohms()
147 switch (iio_read_channel_scale(dac->dpot, &val, &val2)) { in dpot_dac_channel_max_ohms()
162 return -EINVAL; in dpot_dac_channel_max_ohms()
167 struct device *dev = &pdev->dev; in dpot_dac_probe()
175 return -ENOMEM; in dpot_dac_probe()
180 indio_dev->name = dev_name(dev); in dpot_dac_probe()
181 indio_dev->info = &dpot_dac_info; in dpot_dac_probe()
182 indio_dev->modes = INDIO_DIRECT_MODE; in dpot_dac_probe()
183 indio_dev->channels = &dpot_dac_iio_channel; in dpot_dac_probe()
184 indio_dev->num_channels = 1; in dpot_dac_probe()
186 dac->vref = devm_regulator_get(dev, "vref"); in dpot_dac_probe()
187 if (IS_ERR(dac->vref)) in dpot_dac_probe()
188 return dev_err_probe(&pdev->dev, PTR_ERR(dac->vref), in dpot_dac_probe()
189 "failed to get vref regulator\n"); in dpot_dac_probe()
191 dac->dpot = devm_iio_channel_get(dev, "dpot"); in dpot_dac_probe()
192 if (IS_ERR(dac->dpot)) in dpot_dac_probe()
193 return dev_err_probe(&pdev->dev, PTR_ERR(dac->dpot), in dpot_dac_probe()
196 ret = iio_get_channel_type(dac->dpot, &type); in dpot_dac_probe()
202 return -EINVAL; in dpot_dac_probe()
208 dac->max_ohms = ret; in dpot_dac_probe()
210 ret = regulator_enable(dac->vref); in dpot_dac_probe()
212 dev_err(dev, "failed to enable the vref regulator\n"); in dpot_dac_probe()
225 regulator_disable(dac->vref); in dpot_dac_probe()
235 regulator_disable(dac->vref); in dpot_dac_remove()
241 { .compatible = "dpot-dac" },
250 .name = "iio-dpot-dac",