drivers/iio/light/max44000.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/max44000.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/max44000.c- Extension
.c- Size
- 16627 bytes
- Lines
- 626
- 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/module.hlinux/mod_devicetable.hlinux/init.hlinux/i2c.hlinux/regmap.hlinux/util_macros.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/buffer.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct max44000_datafunction max44000_read_alstimfunction max44000_write_alstimfunction max44000_read_alspgafunction max44000_write_alspgafunction max44000_read_alsvalfunction max44000_write_led_current_rawfunction max44000_read_led_current_rawfunction max44000_read_rawfunction max44000_write_rawfunction max44000_write_raw_get_fmtfunction max44000_readable_regfunction max44000_writeable_regfunction max44000_volatile_regfunction max44000_precious_regfunction max44000_trigger_handlerfunction max44000_probe
Annotated Snippet
struct max44000_data {
struct mutex lock;
struct regmap *regmap;
};
/* Default scale is set to the minimum of 0.03125 or 1 / (1 << 5) lux */
#define MAX44000_ALS_TO_LUX_DEFAULT_FRACTION_LOG2 5
/* Scale can be multiplied by up to 128x via ALSPGA for measurement gain */
static const int max44000_alspga_shift[] = {0, 2, 4, 7};
#define MAX44000_ALSPGA_MAX_SHIFT 7
/*
* Scale can be multiplied by up to 64x via ALSTIM because of lost resolution
*
* This scaling factor is hidden from userspace and instead accounted for when
* reading raw values from the device.
*
* This makes it possible to cleanly expose ALSPGA as IIO_CHAN_INFO_SCALE and
* ALSTIM as IIO_CHAN_INFO_INT_TIME without the values affecting each other.
*
* Handling this internally is also required for buffer support because the
* channel's scan_type can't be modified dynamically.
*/
#define MAX44000_ALSTIM_SHIFT(alstim) (2 * (alstim))
/* Available integration times with pretty manual alignment: */
static const int max44000_int_time_avail_ns_array[] = {
100000000,
25000000,
6250000,
1562500,
};
static const char max44000_int_time_avail_str[] =
"0.100 "
"0.025 "
"0.00625 "
"0.0015625";
/* Available scales (internal to ulux) with pretty manual alignment: */
static const int max44000_scale_avail_ulux_array[] = {
31250,
125000,
500000,
4000000,
};
static const char max44000_scale_avail_str[] =
"0.03125 "
"0.125 "
"0.5 "
"4";
#define MAX44000_SCAN_INDEX_ALS 0
#define MAX44000_SCAN_INDEX_PRX 1
static const struct iio_chan_spec max44000_channels[] = {
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_INT_TIME),
.scan_index = MAX44000_SCAN_INDEX_ALS,
.scan_type = {
.sign = 'u',
.realbits = 14,
.storagebits = 16,
}
},
{
.type = IIO_PROXIMITY,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.scan_index = MAX44000_SCAN_INDEX_PRX,
.scan_type = {
.sign = 'u',
.realbits = 8,
.storagebits = 16,
}
},
IIO_CHAN_SOFT_TIMESTAMP(2),
{
.type = IIO_CURRENT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE),
.extend_name = "led",
.output = 1,
.scan_index = -1,
},
};
static int max44000_read_alstim(struct max44000_data *data)
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/init.h`, `linux/i2c.h`, `linux/regmap.h`, `linux/util_macros.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct max44000_data`, `function max44000_read_alstim`, `function max44000_write_alstim`, `function max44000_read_alspga`, `function max44000_write_alspga`, `function max44000_read_alsval`, `function max44000_write_led_current_raw`, `function max44000_read_led_current_raw`, `function max44000_read_raw`, `function max44000_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.