drivers/iio/light/cm36651.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/cm36651.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/cm36651.c- Extension
.c- Size
- 19742 bytes
- Lines
- 743
- 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/delay.hlinux/err.hlinux/i2c.hlinux/mutex.hlinux/module.hlinux/interrupt.hlinux/regulator/consumer.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/events.h
Detected Declarations
struct cm36651_dataenum cm36651_operation_modeenum cm36651_light_channel_idxenum cm36651_commandfunction cm36651_setup_regfunction cm36651_read_outputfunction cm36651_irq_handlerfunction cm36651_set_operation_modefunction cm36651_read_channelfunction cm36651_read_int_timefunction cm36651_write_int_timefunction cm36651_read_rawfunction cm36651_write_rawfunction cm36651_read_prox_threshfunction cm36651_write_prox_threshfunction cm36651_write_prox_event_configfunction cm36651_read_prox_event_configfunction cm36651_probefunction cm36651_remove
Annotated Snippet
struct cm36651_data {
const struct cm36651_platform_data *pdata;
struct i2c_client *client;
struct i2c_client *ps_client;
struct i2c_client *ara_client;
struct mutex lock;
struct regulator *vled_reg;
unsigned long flags;
int cs_int_time[CM36651_CS_COLOR_NUM];
int ps_int_time;
u8 cs_ctrl_regs[CM36651_CS_CONF_REG_NUM];
u8 ps_ctrl_regs[CM36651_PS_REG_NUM];
u16 color[CM36651_CS_COLOR_NUM];
};
static int cm36651_setup_reg(struct cm36651_data *cm36651)
{
struct i2c_client *client = cm36651->client;
struct i2c_client *ps_client = cm36651->ps_client;
int i, ret;
/* CS initialization */
cm36651->cs_ctrl_regs[CM36651_CS_CONF1] = CM36651_ALS_ENABLE |
CM36651_ALS_THRES;
cm36651->cs_ctrl_regs[CM36651_CS_CONF2] = CM36651_CS_CONF2_DEFAULT_BIT;
for (i = 0; i < CM36651_CS_CONF_REG_NUM; i++) {
ret = i2c_smbus_write_byte_data(client, cm36651_cs_reg[i],
cm36651->cs_ctrl_regs[i]);
if (ret < 0)
return ret;
}
/* PS initialization */
cm36651->ps_ctrl_regs[CM36651_PS_CONF1] = CM36651_PS_ENABLE |
CM36651_PS_IT2;
cm36651->ps_ctrl_regs[CM36651_PS_THD] = CM36651_PS_INITIAL_THD;
cm36651->ps_ctrl_regs[CM36651_PS_CANC] = CM36651_PS_CANC_DEFAULT;
cm36651->ps_ctrl_regs[CM36651_PS_CONF2] = CM36651_PS_HYS2 |
CM36651_PS_DIR_INT | CM36651_PS_SMART_PERS_EN;
for (i = 0; i < CM36651_PS_REG_NUM; i++) {
ret = i2c_smbus_write_byte_data(ps_client, cm36651_ps_reg[i],
cm36651->ps_ctrl_regs[i]);
if (ret < 0)
return ret;
}
/* Set shutdown mode */
ret = i2c_smbus_write_byte_data(client, CM36651_CS_CONF1,
CM36651_ALS_DISABLE);
if (ret < 0)
return ret;
ret = i2c_smbus_write_byte_data(cm36651->ps_client,
CM36651_PS_CONF1, CM36651_PS_DISABLE);
if (ret < 0)
return ret;
return 0;
}
static int cm36651_read_output(struct cm36651_data *cm36651,
struct iio_chan_spec const *chan, int *val)
{
struct i2c_client *client = cm36651->client;
int ret = -EINVAL;
switch (chan->type) {
case IIO_LIGHT:
*val = i2c_smbus_read_word_data(client, chan->address);
if (*val < 0)
return ret;
ret = i2c_smbus_write_byte_data(client, CM36651_CS_CONF1,
CM36651_ALS_DISABLE);
if (ret < 0)
return ret;
ret = IIO_VAL_INT;
break;
case IIO_PROXIMITY:
*val = i2c_smbus_read_byte(cm36651->ps_client);
if (*val < 0)
return ret;
if (!test_bit(CM36651_PROXIMITY_EV_EN, &cm36651->flags)) {
ret = i2c_smbus_write_byte_data(cm36651->ps_client,
CM36651_PS_CONF1, CM36651_PS_DISABLE);
if (ret < 0)
Annotation
- Immediate include surface: `linux/delay.h`, `linux/err.h`, `linux/i2c.h`, `linux/mutex.h`, `linux/module.h`, `linux/interrupt.h`, `linux/regulator/consumer.h`, `linux/iio/iio.h`.
- Detected declarations: `struct cm36651_data`, `enum cm36651_operation_mode`, `enum cm36651_light_channel_idx`, `enum cm36651_command`, `function cm36651_setup_reg`, `function cm36651_read_output`, `function cm36651_irq_handler`, `function cm36651_set_operation_mode`, `function cm36651_read_channel`, `function cm36651_read_int_time`.
- 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.