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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/atomic.hlinux/fs.hlinux/interrupt.hlinux/io.hlinux/iio/events.hlinux/iio/iio.hlinux/module.hlinux/mutex.hlinux/mfd/core.hlinux/platform_device.hlinux/slab.hlinux/uaccess.hlinux/mfd/lm3533.h
Detected Declarations
struct lm3533_alsstruct lm3533_als_attributeenum lm3533_als_attribute_typefunction lm3533_als_get_adcfunction _lm3533_als_get_zonefunction lm3533_als_get_zonefunction lm3533_als_get_target_regfunction lm3533_als_get_targetfunction lm3533_als_set_targetfunction lm3533_als_get_currentfunction lm3533_als_read_rawfunction lm3533_als_isrfunction lm3533_als_set_int_modefunction lm3533_als_get_int_modefunction lm3533_als_get_threshold_regfunction lm3533_als_get_thresholdfunction lm3533_als_set_thresholdfunction hysteresisfunction lm3533_als_get_hysteresisfunction show_thresh_either_enfunction store_thresh_either_enfunction show_zonefunction to_lm3533_als_attrfunction show_als_attrfunction store_als_attrfunction lm3533_als_set_input_modefunction lm3533_als_set_resistorfunction lm3533_als_setupfunction lm3533_als_setup_irqfunction lm3533_als_enablefunction lm3533_als_disablefunction lm3533_als_probefunction lm3533_als_remove
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
- Immediate include surface: `linux/atomic.h`, `linux/fs.h`, `linux/interrupt.h`, `linux/io.h`, `linux/iio/events.h`, `linux/iio/iio.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct lm3533_als`, `struct lm3533_als_attribute`, `enum lm3533_als_attribute_type`, `function lm3533_als_get_adc`, `function _lm3533_als_get_zone`, `function lm3533_als_get_zone`, `function lm3533_als_get_target_reg`, `function lm3533_als_get_target`, `function lm3533_als_set_target`, `function lm3533_als_get_current`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.