drivers/iio/adc/stmpe-adc.c

Source file repositories/reference/linux-study-clean/drivers/iio/adc/stmpe-adc.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/stmpe-adc.c
Extension
.c
Size
8418 bytes
Lines
366
Domain
Driver Families
Bucket
drivers/iio
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct stmpe_adc {
	struct stmpe *stmpe;
	struct clk *clk;
	struct device *dev;
	struct mutex lock;

	/* We are allocating plus one for the temperature channel */
	struct iio_chan_spec stmpe_adc_iio_channels[STMPE_ADC_LAST_NR + 2];

	struct completion completion;

	u8 channel;
	u32 value;
};

static int stmpe_read_voltage(struct stmpe_adc *info,
		struct iio_chan_spec const *chan, int *val)
{
	unsigned long ret;

	mutex_lock(&info->lock);

	reinit_completion(&info->completion);

	info->channel = (u8)chan->channel;

	if (info->channel > STMPE_ADC_LAST_NR) {
		mutex_unlock(&info->lock);
		return -EINVAL;
	}

	stmpe_reg_write(info->stmpe, STMPE_REG_ADC_CAPT,
			STMPE_ADC_CH(info->channel));

	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);

	if (ret == 0) {
		stmpe_reg_write(info->stmpe, STMPE_REG_ADC_INT_STA,
				STMPE_ADC_CH(info->channel));
		mutex_unlock(&info->lock);
		return -ETIMEDOUT;
	}

	*val = info->value;

	mutex_unlock(&info->lock);

	return 0;
}

static int stmpe_read_temp(struct stmpe_adc *info,
		struct iio_chan_spec const *chan, int *val)
{
	unsigned long ret;

	mutex_lock(&info->lock);

	reinit_completion(&info->completion);

	info->channel = (u8)chan->channel;

	if (info->channel != STMPE_TEMP_CHANNEL) {
		mutex_unlock(&info->lock);
		return -EINVAL;
	}

	stmpe_reg_write(info->stmpe, STMPE_REG_TEMP_CTRL,
			STMPE_START_ONE_TEMP_CONV);

	ret = wait_for_completion_timeout(&info->completion, STMPE_ADC_TIMEOUT);

	if (ret == 0) {
		mutex_unlock(&info->lock);
		return -ETIMEDOUT;
	}

	/*
	 * absolute temp = +V3.3 * value /7.51 [K]
	 * scale to [milli °C]
	 */
	*val = ((449960l * info->value) / 1024l) - 273150;

	mutex_unlock(&info->lock);

	return 0;
}

static int stmpe_read_raw(struct iio_dev *indio_dev,
			  struct iio_chan_spec const *chan,
			  int *val,

Annotation

Implementation Notes