Lines Matching refs:adc

57 static int mcp3911_read(struct mcp3911 *adc, u8 reg, u32 *val, u8 len)  in mcp3911_read()  argument
61 reg = MCP3911_REG_READ(reg, adc->dev_addr); in mcp3911_read()
62 ret = spi_write_then_read(adc->spi, &reg, 1, val, len); in mcp3911_read()
68 dev_dbg(&adc->spi->dev, "reading 0x%x from register 0x%x\n", *val, in mcp3911_read()
73 static int mcp3911_write(struct mcp3911 *adc, u8 reg, u32 val, u8 len) in mcp3911_write() argument
75 dev_dbg(&adc->spi->dev, "writing 0x%x to register 0x%x\n", val, reg); in mcp3911_write()
79 val |= MCP3911_REG_WRITE(reg, adc->dev_addr); in mcp3911_write()
81 return spi_write(adc->spi, &val, len + 1); in mcp3911_write()
84 static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, in mcp3911_update() argument
90 ret = mcp3911_read(adc, reg, &tmp, len); in mcp3911_update()
96 return mcp3911_write(adc, reg, val, len); in mcp3911_update()
103 struct mcp3911 *adc = iio_priv(indio_dev); in mcp3911_read_raw() local
106 mutex_lock(&adc->lock); in mcp3911_read_raw()
109 ret = mcp3911_read(adc, in mcp3911_read_raw()
118 ret = mcp3911_read(adc, in mcp3911_read_raw()
127 if (adc->vref) { in mcp3911_read_raw()
128 ret = regulator_get_voltage(adc->vref); in mcp3911_read_raw()
147 mutex_unlock(&adc->lock); in mcp3911_read_raw()
155 struct mcp3911 *adc = iio_priv(indio_dev); in mcp3911_write_raw() local
158 mutex_lock(&adc->lock); in mcp3911_write_raw()
167 ret = mcp3911_write(adc, MCP3911_OFFCAL(channel->channel), val, in mcp3911_write_raw()
173 ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM, in mcp3911_write_raw()
180 mutex_unlock(&adc->lock); in mcp3911_write_raw()
203 static int mcp3911_config(struct mcp3911 *adc, struct device_node *of_node) in mcp3911_config() argument
208 of_property_read_u32(of_node, "device-addr", &adc->dev_addr); in mcp3911_config()
209 if (adc->dev_addr > 3) { in mcp3911_config()
210 dev_err(&adc->spi->dev, in mcp3911_config()
212 adc->dev_addr); in mcp3911_config()
215 dev_dbg(&adc->spi->dev, "use device address %i\n", adc->dev_addr); in mcp3911_config()
217 ret = mcp3911_read(adc, MCP3911_REG_CONFIG, &configreg, 2); in mcp3911_config()
221 if (adc->vref) { in mcp3911_config()
222 dev_dbg(&adc->spi->dev, "use external voltage reference\n"); in mcp3911_config()
225 dev_dbg(&adc->spi->dev, in mcp3911_config()
230 if (adc->clki) { in mcp3911_config()
231 dev_dbg(&adc->spi->dev, "use external clock as clocksource\n"); in mcp3911_config()
234 dev_dbg(&adc->spi->dev, in mcp3911_config()
239 return mcp3911_write(adc, MCP3911_REG_CONFIG, configreg, 2); in mcp3911_config()
245 struct mcp3911 *adc; in mcp3911_probe() local
248 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in mcp3911_probe()
252 adc = iio_priv(indio_dev); in mcp3911_probe()
253 adc->spi = spi; in mcp3911_probe()
255 adc->vref = devm_regulator_get_optional(&adc->spi->dev, "vref"); in mcp3911_probe()
256 if (IS_ERR(adc->vref)) { in mcp3911_probe()
257 if (PTR_ERR(adc->vref) == -ENODEV) { in mcp3911_probe()
258 adc->vref = NULL; in mcp3911_probe()
260 dev_err(&adc->spi->dev, in mcp3911_probe()
262 PTR_ERR(adc->vref)); in mcp3911_probe()
263 return PTR_ERR(adc->vref); in mcp3911_probe()
267 ret = regulator_enable(adc->vref); in mcp3911_probe()
272 adc->clki = devm_clk_get(&adc->spi->dev, NULL); in mcp3911_probe()
273 if (IS_ERR(adc->clki)) { in mcp3911_probe()
274 if (PTR_ERR(adc->clki) == -ENOENT) { in mcp3911_probe()
275 adc->clki = NULL; in mcp3911_probe()
277 dev_err(&adc->spi->dev, in mcp3911_probe()
279 PTR_ERR(adc->clki)); in mcp3911_probe()
280 ret = PTR_ERR(adc->clki); in mcp3911_probe()
284 ret = clk_prepare_enable(adc->clki); in mcp3911_probe()
286 dev_err(&adc->spi->dev, in mcp3911_probe()
292 ret = mcp3911_config(adc, spi->dev.of_node); in mcp3911_probe()
304 mutex_init(&adc->lock); in mcp3911_probe()
313 clk_disable_unprepare(adc->clki); in mcp3911_probe()
315 if (adc->vref) in mcp3911_probe()
316 regulator_disable(adc->vref); in mcp3911_probe()
324 struct mcp3911 *adc = iio_priv(indio_dev); in mcp3911_remove() local
328 clk_disable_unprepare(adc->clki); in mcp3911_remove()
329 if (adc->vref) in mcp3911_remove()
330 regulator_disable(adc->vref); in mcp3911_remove()