drivers/iio/light/lm3533-als.c

Source file repositories/reference/linux-study-clean/drivers/iio/light/lm3533-als.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/lm3533-als.c
Extension
.c
Size
22051 bytes
Lines
923
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 lm3533_als {
	struct lm3533 *lm3533;
	struct platform_device *pdev;

	unsigned long flags;
	int irq;

	atomic_t zone;
	struct mutex thresh_mutex;
};


static int lm3533_als_get_adc(struct iio_dev *indio_dev, bool average,
								int *adc)
{
	struct lm3533_als *als = iio_priv(indio_dev);
	u8 reg;
	u8 val;
	int ret;

	if (average)
		reg = LM3533_REG_ALS_READ_ADC_AVERAGE;
	else
		reg = LM3533_REG_ALS_READ_ADC_RAW;

	ret = lm3533_read(als->lm3533, reg, &val);
	if (ret) {
		dev_err(&indio_dev->dev, "failed to read adc\n");
		return ret;
	}

	*adc = val;

	return 0;
}

static int _lm3533_als_get_zone(struct iio_dev *indio_dev, u8 *zone)
{
	struct lm3533_als *als = iio_priv(indio_dev);
	u8 val;
	int ret;

	ret = lm3533_read(als->lm3533, LM3533_REG_ALS_ZONE_INFO, &val);
	if (ret) {
		dev_err(&indio_dev->dev, "failed to read zone\n");
		return ret;
	}

	val = (val & LM3533_ALS_ZONE_MASK) >> LM3533_ALS_ZONE_SHIFT;
	*zone = min_t(u8, val, LM3533_ALS_ZONE_MAX);

	return 0;
}

static int lm3533_als_get_zone(struct iio_dev *indio_dev, u8 *zone)
{
	struct lm3533_als *als = iio_priv(indio_dev);
	int ret;

	if (test_bit(LM3533_ALS_FLAG_INT_ENABLED, &als->flags)) {
		*zone = atomic_read(&als->zone);
	} else {
		ret = _lm3533_als_get_zone(indio_dev, zone);
		if (ret)
			return ret;
	}

	return 0;
}

/*
 * channel	output channel 0..2
 * zone		zone 0..4
 */
static inline u8 lm3533_als_get_target_reg(unsigned channel, unsigned zone)
{
	return LM3533_REG_ALS_TARGET_BASE + 5 * channel + zone;
}

static int lm3533_als_get_target(struct iio_dev *indio_dev, unsigned channel,
							unsigned zone, u8 *val)
{
	struct lm3533_als *als = iio_priv(indio_dev);
	u8 reg;
	int ret;

	if (channel > LM3533_ALS_CHANNEL_CURRENT_MAX)
		return -EINVAL;

	if (zone > LM3533_ALS_ZONE_MAX)

Annotation

Implementation Notes