drivers/iio/light/us5182d.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/us5182d.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/us5182d.c- Extension
.c- Size
- 22924 bytes
- Lines
- 981
- 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/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/delay.hlinux/i2c.hlinux/iio/events.hlinux/iio/iio.hlinux/interrupt.hlinux/irq.hlinux/iio/sysfs.hlinux/mutex.hlinux/pm.hlinux/pm_runtime.h
Detected Declarations
struct us5182d_dataenum modeenum pmodefunction us5182d_oneshot_enfunction us5182d_set_opmodefunction us5182d_als_enablefunction us5182d_px_enablefunction us5182d_get_alsfunction us5182d_get_pxfunction us5182d_shutdown_enfunction us5182d_set_power_statefunction us5182d_read_valuefunction us5182d_read_rawfunction registersfunction us5182d_apply_scalefunction us5182d_write_rawfunction us5182d_setup_proxfunction us5182d_read_threshfunction us5182d_write_threshfunction us5182d_read_event_configfunction us5182d_write_event_configfunction us5182d_resetfunction us5182d_initfunction us5182d_get_platform_datafunction us5182d_dark_gain_configfunction us5182d_irq_thread_handlerfunction us5182d_probefunction us5182d_removefunction us5182d_suspendfunction us5182d_resume
Annotated Snippet
struct us5182d_data {
struct i2c_client *client;
struct mutex lock;
/* Glass attenuation factor */
u32 ga;
/* Dark gain tuning */
u8 lower_dark_gain;
u8 upper_dark_gain;
u16 *us5182d_dark_ths;
u16 px_low_th;
u16 px_high_th;
int rising_en;
int falling_en;
u8 opmode;
u8 power_mode;
bool als_enabled;
bool px_enabled;
bool default_continuous;
};
static IIO_CONST_ATTR(in_illuminance_scale_available,
"0.0021 0.0039 0.0076 0.0196 0.0336 0.061 0.1078 0.1885");
static struct attribute *us5182d_attrs[] = {
&iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
NULL
};
static const struct attribute_group us5182d_attr_group = {
.attrs = us5182d_attrs,
};
static const struct {
u8 reg;
u8 val;
} us5182d_regvals[] = {
{US5182D_REG_CFG0, US5182D_CFG0_WORD_ENABLE},
{US5182D_REG_CFG1, US5182D_CFG1_ALS_RES16},
{US5182D_REG_CFG2, (US5182D_CFG2_PX_RES16 |
US5182D_CFG2_PXGAIN_DEFAULT)},
{US5182D_REG_CFG3, US5182D_CFG3_LED_CURRENT100 |
US5182D_CFG3_INT_SOURCE_PX},
{US5182D_REG_CFG4, 0x00},
};
static const struct iio_event_spec us5182d_events[] = {
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_RISING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
},
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_FALLING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
},
};
static const struct iio_chan_spec us5182d_channels[] = {
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE),
},
{
.type = IIO_PROXIMITY,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.event_spec = us5182d_events,
.num_event_specs = ARRAY_SIZE(us5182d_events),
}
};
static int us5182d_oneshot_en(struct us5182d_data *data)
{
int ret;
ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0);
if (ret < 0)
return ret;
/*
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/delay.h`, `linux/i2c.h`, `linux/iio/events.h`, `linux/iio/iio.h`, `linux/interrupt.h`.
- Detected declarations: `struct us5182d_data`, `enum mode`, `enum pmode`, `function us5182d_oneshot_en`, `function us5182d_set_opmode`, `function us5182d_als_enable`, `function us5182d_px_enable`, `function us5182d_get_als`, `function us5182d_get_px`, `function us5182d_shutdown_en`.
- 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.