drivers/iio/light/stk3310.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/stk3310.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/stk3310.c- Extension
.c- Size
- 19021 bytes
- Lines
- 741
- 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/i2c.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/regmap.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct stk3310_datafunction stk3310_read_near_levelfunction stk3310_check_chip_idfunction stk3310_get_indexfunction stk3310_read_eventfunction stk3310_write_eventfunction stk3310_read_event_configfunction stk3310_write_event_configfunction stk3310_read_rawfunction stk3310_write_rawfunction stk3310_set_statefunction stk3310_initfunction stk3310_is_volatile_regfunction stk3310_regmap_initfunction stk3310_irq_handlerfunction stk3310_irq_event_handlerfunction stk3310_probefunction stk3310_removefunction stk3310_suspendfunction stk3310_resume
Annotated Snippet
struct stk3310_data {
struct i2c_client *client;
struct mutex lock;
bool als_enabled;
bool ps_enabled;
uint32_t ps_near_level;
u64 timestamp;
struct regmap *regmap;
struct regmap_field *reg_state;
struct regmap_field *reg_als_gain;
struct regmap_field *reg_ps_gain;
struct regmap_field *reg_als_it;
struct regmap_field *reg_ps_it;
struct regmap_field *reg_int_ps;
struct regmap_field *reg_flag_psint;
struct regmap_field *reg_flag_nf;
};
static const struct iio_event_spec stk3310_events[] = {
/* Proximity event */
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_RISING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
},
/* Out-of-proximity event */
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_FALLING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_ENABLE),
},
};
static ssize_t stk3310_read_near_level(struct iio_dev *indio_dev,
uintptr_t priv,
const struct iio_chan_spec *chan,
char *buf)
{
struct stk3310_data *data = iio_priv(indio_dev);
return sprintf(buf, "%u\n", data->ps_near_level);
}
static const struct iio_chan_spec_ext_info stk3310_ext_info[] = {
{
.name = "nearlevel",
.shared = IIO_SEPARATE,
.read = stk3310_read_near_level,
},
{ }
};
static const struct iio_chan_spec stk3310_channels[] = {
{
.type = IIO_LIGHT,
.info_mask_separate =
BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_INT_TIME),
},
{
.type = IIO_PROXIMITY,
.info_mask_separate =
BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_INT_TIME),
.event_spec = stk3310_events,
.num_event_specs = ARRAY_SIZE(stk3310_events),
.ext_info = stk3310_ext_info,
}
};
static IIO_CONST_ATTR(in_illuminance_scale_available, STK3310_SCALE_AVAILABLE);
static IIO_CONST_ATTR(in_proximity_scale_available, STK3310_SCALE_AVAILABLE);
static IIO_CONST_ATTR(in_illuminance_integration_time_available,
STK3310_IT_AVAILABLE);
static IIO_CONST_ATTR(in_proximity_integration_time_available,
STK3310_IT_AVAILABLE);
static struct attribute *stk3310_attributes[] = {
&iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
&iio_const_attr_in_proximity_scale_available.dev_attr.attr,
&iio_const_attr_in_illuminance_integration_time_available.dev_attr.attr,
&iio_const_attr_in_proximity_integration_time_available.dev_attr.attr,
NULL,
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/regmap.h`, `linux/iio/events.h`, `linux/iio/iio.h`.
- Detected declarations: `struct stk3310_data`, `function stk3310_read_near_level`, `function stk3310_check_chip_id`, `function stk3310_get_index`, `function stk3310_read_event`, `function stk3310_write_event`, `function stk3310_read_event_config`, `function stk3310_write_event_config`, `function stk3310_read_raw`, `function stk3310_write_raw`.
- 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.