drivers/iio/light/ltrf216a.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/ltrf216a.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/ltrf216a.c- Extension
.c- Size
- 14481 bytes
- Lines
- 584
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/bits.hlinux/delay.hlinux/i2c.hlinux/init.hlinux/iopoll.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/pm.hlinux/pm_runtime.hlinux/regmap.hlinux/iio/iio.hlinux/unaligned.h
Detected Declarations
struct ltr_chip_infostruct ltrf216a_datafunction ltrf216a_resetfunction ltrf216a_enablefunction ltrf216a_disablefunction ltrf216a_cleanupfunction ltrf216a_set_int_timefunction ltrf216a_get_int_timefunction ltrf216a_set_power_statefunction ltrf216a_read_datafunction ltrf216a_get_luxfunction ltrf216a_read_rawfunction ltrf216a_write_rawfunction ltrf216a_read_availablefunction ltrf216a_readable_regfunction ltrf216a_writable_regfunction ltrf216a_volatile_regfunction ltrf216a_precious_regfunction ltrf216a_probefunction ltrf216a_runtime_suspendfunction ltrf216a_runtime_resume
Annotated Snippet
struct ltr_chip_info {
/* Chip contains CLEAR_DATA_0/1/2 registers at offset 0xa..0xc */
bool has_clear_data;
/* Lux calculation multiplier for ALS data */
int lux_multiplier;
};
/*
* Window Factor is needed when the device is under Window glass
* with coated tinted ink. This is to compensate for the light loss
* due to the lower transmission rate of the window glass and helps
* in calculating lux.
*/
#define LTRF216A_WIN_FAC 1
struct ltrf216a_data {
struct regmap *regmap;
struct i2c_client *client;
const struct ltr_chip_info *info;
u32 int_time;
u16 int_time_fac;
u8 als_gain_fac;
/*
* Protects regmap accesses and makes sure integration time
* remains constant during the measurement of lux.
*/
struct mutex lock;
};
static const struct iio_chan_spec ltrf216a_channels[] = {
{
.type = IIO_LIGHT,
.info_mask_separate =
BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_PROCESSED) |
BIT(IIO_CHAN_INFO_INT_TIME),
.info_mask_separate_available =
BIT(IIO_CHAN_INFO_INT_TIME),
},
};
static void ltrf216a_reset(struct iio_dev *indio_dev)
{
struct ltrf216a_data *data = iio_priv(indio_dev);
/* reset sensor, chip fails to respond to this, so ignore any errors */
regmap_write(data->regmap, LTRF216A_MAIN_CTRL, LTRF216A_ALS_RESET_MASK);
/* reset time */
usleep_range(1000, 2000);
}
static int ltrf216a_enable(struct iio_dev *indio_dev)
{
struct ltrf216a_data *data = iio_priv(indio_dev);
struct device *dev = &data->client->dev;
int ret;
/* enable sensor */
ret = regmap_set_bits(data->regmap,
LTRF216A_MAIN_CTRL, LTRF216A_ALS_ENABLE_MASK);
if (ret) {
dev_err(dev, "failed to enable sensor: %d\n", ret);
return ret;
}
/* sleep for one integration cycle after enabling the device */
msleep(ltrf216a_int_time_reg[0][0]);
return 0;
}
static int ltrf216a_disable(struct iio_dev *indio_dev)
{
struct ltrf216a_data *data = iio_priv(indio_dev);
struct device *dev = &data->client->dev;
int ret;
ret = regmap_write(data->regmap, LTRF216A_MAIN_CTRL, 0);
if (ret)
dev_err(dev, "failed to disable sensor: %d\n", ret);
return ret;
}
static void ltrf216a_cleanup(void *data)
{
struct iio_dev *indio_dev = data;
ltrf216a_disable(indio_dev);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/delay.h`, `linux/i2c.h`, `linux/init.h`, `linux/iopoll.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct ltr_chip_info`, `struct ltrf216a_data`, `function ltrf216a_reset`, `function ltrf216a_enable`, `function ltrf216a_disable`, `function ltrf216a_cleanup`, `function ltrf216a_set_int_time`, `function ltrf216a_get_int_time`, `function ltrf216a_set_power_state`, `function ltrf216a_read_data`.
- 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.
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.