Lines Matching refs:adc

120 static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,  in mcp320x_adc_conversion()  argument
125 if (adc->chip_info->conv_time) { in mcp320x_adc_conversion()
126 ret = spi_sync(adc->spi, &adc->start_conv_msg); in mcp320x_adc_conversion()
130 usleep_range(adc->chip_info->conv_time, in mcp320x_adc_conversion()
131 adc->chip_info->conv_time + 100); in mcp320x_adc_conversion()
134 memset(&adc->rx_buf, 0, sizeof(adc->rx_buf)); in mcp320x_adc_conversion()
135 if (adc->chip_info->num_channels > 1) in mcp320x_adc_conversion()
136 adc->tx_buf = mcp320x_channel_to_tx_data(device_index, channel, in mcp320x_adc_conversion()
139 ret = spi_sync(adc->spi, &adc->msg); in mcp320x_adc_conversion()
145 *val = (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3); in mcp320x_adc_conversion()
150 *val = (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6); in mcp320x_adc_conversion()
153 *val = (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1); in mcp320x_adc_conversion()
158 *val = (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4); in mcp320x_adc_conversion()
161 *val = sign_extend32((adc->rx_buf[0] & 0x1f) << 8 in mcp320x_adc_conversion()
162 | adc->rx_buf[1], 12); in mcp320x_adc_conversion()
168 u32 raw = be32_to_cpup((__be32 *)adc->rx_buf); in mcp320x_adc_conversion()
170 if (!(adc->spi->mode & SPI_CPOL)) in mcp320x_adc_conversion()
198 struct mcp320x *adc = iio_priv(indio_dev); in mcp320x_read_raw() local
202 mutex_lock(&adc->lock); in mcp320x_read_raw()
204 device_index = spi_get_device_id(adc->spi)->driver_data; in mcp320x_read_raw()
208 ret = mcp320x_adc_conversion(adc, channel->address, in mcp320x_read_raw()
217 ret = regulator_get_voltage(adc->reg); in mcp320x_read_raw()
223 *val2 = adc->chip_info->resolution; in mcp320x_read_raw()
229 mutex_unlock(&adc->lock); in mcp320x_read_raw()
377 struct mcp320x *adc; in mcp320x_probe() local
381 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in mcp320x_probe()
385 adc = iio_priv(indio_dev); in mcp320x_probe()
386 adc->spi = spi; in mcp320x_probe()
398 adc->chip_info = chip_info; in mcp320x_probe()
400 adc->transfer[0].tx_buf = &adc->tx_buf; in mcp320x_probe()
401 adc->transfer[0].len = sizeof(adc->tx_buf); in mcp320x_probe()
402 adc->transfer[1].rx_buf = adc->rx_buf; in mcp320x_probe()
403 adc->transfer[1].len = DIV_ROUND_UP(chip_info->resolution, 8); in mcp320x_probe()
407 spi_message_init_with_transfers(&adc->msg, in mcp320x_probe()
408 &adc->transfer[1], 1); in mcp320x_probe()
410 spi_message_init_with_transfers(&adc->msg, adc->transfer, in mcp320x_probe()
411 ARRAY_SIZE(adc->transfer)); in mcp320x_probe()
420 adc->transfer[1].len++; in mcp320x_probe()
423 adc->start_conv_transfer.delay.value = 8; in mcp320x_probe()
424 adc->start_conv_transfer.delay.unit = SPI_DELAY_UNIT_USECS; in mcp320x_probe()
425 spi_message_init_with_transfers(&adc->start_conv_msg, in mcp320x_probe()
426 &adc->start_conv_transfer, 1); in mcp320x_probe()
436 mcp320x_adc_conversion(adc, 0, 1, device_index, &ret); in mcp320x_probe()
437 mcp320x_adc_conversion(adc, 0, 1, device_index, &ret); in mcp320x_probe()
440 adc->reg = devm_regulator_get(&spi->dev, "vref"); in mcp320x_probe()
441 if (IS_ERR(adc->reg)) in mcp320x_probe()
442 return PTR_ERR(adc->reg); in mcp320x_probe()
444 ret = regulator_enable(adc->reg); in mcp320x_probe()
448 mutex_init(&adc->lock); in mcp320x_probe()
457 regulator_disable(adc->reg); in mcp320x_probe()
465 struct mcp320x *adc = iio_priv(indio_dev); in mcp320x_remove() local
468 regulator_disable(adc->reg); in mcp320x_remove()