drivers/iio/light/cm3232.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/cm3232.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/cm3232.c- Extension
.c- Size
- 10554 bytes
- Lines
- 427
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/module.hlinux/mod_devicetable.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/init.h
Detected Declarations
struct cm3232_als_infostruct cm3232_chipfunction cm3232_reg_initfunction cm3232_read_als_itfunction cm3232_write_als_itfunction cm3232_get_luxfunction cm3232_read_rawfunction cm3232_write_rawfunction cm3232_get_it_availablefunction cm3232_probefunction cm3232_removefunction cm3232_suspendfunction cm3232_resume
Annotated Snippet
struct cm3232_als_info {
u8 regs_cmd_default;
u8 hw_id;
int mlux_per_bit;
int mlux_per_bit_base_it;
};
static const struct cm3232_als_info cm3232_als_info_default = {
.regs_cmd_default = CM3232_CMD_DEFAULT,
.hw_id = CM3232_HW_ID,
.mlux_per_bit = CM3232_MLUX_PER_BIT_DEFAULT,
.mlux_per_bit_base_it = CM3232_MLUX_PER_BIT_BASE_IT,
};
struct cm3232_chip {
struct i2c_client *client;
const struct cm3232_als_info *als_info;
int calibscale;
u8 regs_cmd;
u16 regs_als;
};
/**
* cm3232_reg_init() - Initialize CM3232
* @chip: pointer of struct cm3232_chip.
*
* Check and initialize CM3232 ambient light sensor.
*
* Return: 0 for success; otherwise for error code.
*/
static int cm3232_reg_init(struct cm3232_chip *chip)
{
struct i2c_client *client = chip->client;
s32 ret;
chip->als_info = &cm3232_als_info_default;
/* Disable and reset device */
chip->regs_cmd = CM3232_CMD_ALS_DISABLE | CM3232_CMD_ALS_RESET;
ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD,
chip->regs_cmd);
if (ret < 0) {
dev_err(&chip->client->dev, "Error writing reg_cmd\n");
return ret;
}
/* Identify device */
ret = i2c_smbus_read_word_data(client, CM3232_REG_ADDR_ID);
if (ret < 0) {
dev_err(&chip->client->dev, "Error reading addr_id\n");
return ret;
}
if ((ret & 0xFF) != chip->als_info->hw_id)
return -ENODEV;
/* Register default value */
chip->regs_cmd = chip->als_info->regs_cmd_default;
/* Configure register */
ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD,
chip->regs_cmd);
if (ret < 0)
dev_err(&chip->client->dev, "Error writing reg_cmd\n");
return ret;
}
/**
* cm3232_read_als_it() - Get sensor integration time
* @chip: pointer of struct cm3232_chip
* @val: pointer of int to load the integration (sec).
* @val2: pointer of int to load the integration time (microsecond).
*
* Report the current integration time.
*
* Return: IIO_VAL_INT_PLUS_MICRO for success, otherwise -EINVAL.
*/
static int cm3232_read_als_it(struct cm3232_chip *chip, int *val, int *val2)
{
u16 als_it;
int i;
als_it = chip->regs_cmd;
als_it &= CM3232_CMD_ALS_IT_MASK;
als_it >>= CM3232_CMD_ALS_IT_SHIFT;
for (i = 0; i < ARRAY_SIZE(cm3232_als_it_scales); i++) {
if (als_it == cm3232_als_it_scales[i].it) {
*val = cm3232_als_it_scales[i].val;
*val2 = cm3232_als_it_scales[i].val2;
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/init.h`.
- Detected declarations: `struct cm3232_als_info`, `struct cm3232_chip`, `function cm3232_reg_init`, `function cm3232_read_als_it`, `function cm3232_write_als_it`, `function cm3232_get_lux`, `function cm3232_read_raw`, `function cm3232_write_raw`, `function cm3232_get_it_available`, `function cm3232_probe`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
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.