drivers/iio/light/max44009.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/max44009.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/max44009.c- Extension
.c- Size
- 13344 bytes
- Lines
- 555
- 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/init.hlinux/kernel.hlinux/bits.hlinux/i2c.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/interrupt.hlinux/module.hlinux/util_macros.h
Detected Declarations
struct max44009_datafunction max44009_read_int_timefunction max44009_write_int_timefunction max44009_write_rawfunction max44009_write_raw_get_fmtfunction max44009_lux_rawfunction max44009_read_lux_rawfunction max44009_read_rawfunction max44009_threshold_byte_from_fractionfunction max44009_get_thr_regfunction max44009_write_event_valuefunction max44009_read_thresholdfunction max44009_read_event_valuefunction max44009_write_event_configfunction max44009_read_event_configfunction max44009_threaded_irq_handlerfunction max44009_probe
Annotated Snippet
struct max44009_data {
struct i2c_client *client;
struct mutex lock;
};
static const struct iio_event_spec max44009_event_spec[] = {
{
.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 max44009_channels[] = {
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
BIT(IIO_CHAN_INFO_INT_TIME),
.event_spec = max44009_event_spec,
.num_event_specs = ARRAY_SIZE(max44009_event_spec),
},
};
static int max44009_read_int_time(struct max44009_data *data)
{
int ret = i2c_smbus_read_byte_data(data->client, MAX44009_REG_CFG);
if (ret < 0)
return ret;
return max44009_int_time_ns_array[ret & MAX44009_CFG_TIM_MASK];
}
static int max44009_write_int_time(struct max44009_data *data,
int val, int val2)
{
struct i2c_client *client = data->client;
int ret, int_time, config;
s64 ns;
ns = val * NSEC_PER_SEC + val2;
int_time = find_closest_descending(
ns,
max44009_int_time_ns_array,
ARRAY_SIZE(max44009_int_time_ns_array));
ret = i2c_smbus_read_byte_data(client, MAX44009_REG_CFG);
if (ret < 0)
return ret;
config = ret;
config &= int_time;
/*
* To set the integration time, the device must also be in manual
* mode.
*/
config |= MAX44009_CFG_MAN_MODE_MASK;
return i2c_smbus_write_byte_data(client, MAX44009_REG_CFG, config);
}
static int max44009_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int val,
int val2, long mask)
{
struct max44009_data *data = iio_priv(indio_dev);
int ret;
if (mask == IIO_CHAN_INFO_INT_TIME && chan->type == IIO_LIGHT) {
mutex_lock(&data->lock);
ret = max44009_write_int_time(data, val, val2);
mutex_unlock(&data->lock);
return ret;
}
return -EINVAL;
}
static int max44009_write_raw_get_fmt(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
long mask)
{
Annotation
- Immediate include surface: `linux/init.h`, `linux/kernel.h`, `linux/bits.h`, `linux/i2c.h`, `linux/iio/events.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/interrupt.h`.
- Detected declarations: `struct max44009_data`, `function max44009_read_int_time`, `function max44009_write_int_time`, `function max44009_write_raw`, `function max44009_write_raw_get_fmt`, `function max44009_lux_raw`, `function max44009_read_lux_raw`, `function max44009_read_raw`, `function max44009_threshold_byte_from_fraction`, `function max44009_get_thr_reg`.
- 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.