Lines Matching +full:vref +full:- +full:out +full:- +full:en
1 // SPDX-License-Identifier: GPL-2.0-only
14 * ------------
20 * ------------
23 * ------------
30 * https://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001
31 * https://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf mcp3002
32 * https://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf mcp3004/08
33 * http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201
34 * http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202
35 * http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08
36 * https://ww1.microchip.com/downloads/en/DeviceDoc/21700E.pdf mcp3301
37 * http://ww1.microchip.com/downloads/en/DeviceDoc/21950D.pdf mcp3550/1/3
72 * struct mcp320x - Microchip SPI ADC instance
78 * @reg: regulator generating Vref
81 * @tx_buf: buffer for @transfer[0] (not used on single-channel converters)
116 return -EINVAL; in mcp320x_channel_to_tx_data()
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()
174 * If the input is within -vref and vref, bit 21 is the sign. in mcp320x_adc_conversion()
180 return -EIO; /* cannot have overrange AND underrange */ in mcp320x_adc_conversion()
190 return -EINVAL; in mcp320x_adc_conversion()
199 int ret = -EINVAL; in mcp320x_read_raw()
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()
209 channel->differential, device_index, val); in mcp320x_read_raw()
211 goto out; in mcp320x_read_raw()
217 ret = regulator_get_voltage(adc->reg); in mcp320x_read_raw()
219 goto out; in mcp320x_read_raw()
223 *val2 = adc->chip_info->resolution; in mcp320x_read_raw()
228 out: in mcp320x_read_raw()
229 mutex_unlock(&adc->lock); in mcp320x_read_raw()
386 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in mcp320x_probe()
388 return -ENOMEM; in mcp320x_probe()
391 adc->spi = spi; in mcp320x_probe()
393 indio_dev->name = spi_get_device_id(spi)->name; in mcp320x_probe()
394 indio_dev->modes = INDIO_DIRECT_MODE; in mcp320x_probe()
395 indio_dev->info = &mcp320x_info; in mcp320x_probe()
397 device_index = spi_get_device_id(spi)->driver_data; in mcp320x_probe()
399 indio_dev->channels = chip_info->channels; in mcp320x_probe()
400 indio_dev->num_channels = chip_info->num_channels; in mcp320x_probe()
402 adc->chip_info = chip_info; in mcp320x_probe()
404 adc->transfer[0].tx_buf = &adc->tx_buf; in mcp320x_probe()
405 adc->transfer[0].len = sizeof(adc->tx_buf); in mcp320x_probe()
406 adc->transfer[1].rx_buf = adc->rx_buf; in mcp320x_probe()
407 adc->transfer[1].len = DIV_ROUND_UP(chip_info->resolution, 8); in mcp320x_probe()
409 if (chip_info->num_channels == 1) in mcp320x_probe()
410 /* single-channel converters are rx only (no MOSI pin) */ in mcp320x_probe()
411 spi_message_init_with_transfers(&adc->msg, in mcp320x_probe()
412 &adc->transfer[1], 1); in mcp320x_probe()
414 spi_message_init_with_transfers(&adc->msg, adc->transfer, in mcp320x_probe()
415 ARRAY_SIZE(adc->transfer)); in mcp320x_probe()
423 if (!(spi->mode & SPI_CPOL)) in mcp320x_probe()
424 adc->transfer[1].len++; in mcp320x_probe()
427 adc->start_conv_transfer.delay.value = 8; in mcp320x_probe()
428 adc->start_conv_transfer.delay.unit = SPI_DELAY_UNIT_USECS; in mcp320x_probe()
429 spi_message_init_with_transfers(&adc->start_conv_msg, in mcp320x_probe()
430 &adc->start_conv_transfer, 1); in mcp320x_probe()
435 * Sometimes it fails to wake from shutdown and clocks out in mcp320x_probe()
444 adc->reg = devm_regulator_get(&spi->dev, "vref"); in mcp320x_probe()
445 if (IS_ERR(adc->reg)) in mcp320x_probe()
446 return PTR_ERR(adc->reg); in mcp320x_probe()
448 ret = regulator_enable(adc->reg); in mcp320x_probe()
452 ret = devm_add_action_or_reset(&spi->dev, mcp320x_regulator_disable, adc->reg); in mcp320x_probe()
456 mutex_init(&adc->lock); in mcp320x_probe()
458 return devm_iio_device_register(&spi->dev, indio_dev); in mcp320x_probe()
471 { .compatible = "microchip,mcp3550-50" },
472 { .compatible = "microchip,mcp3550-60" },
489 { "mcp3550-50", mcp3550_50 },
490 { "mcp3550-60", mcp3550_60 },