drivers/iio/light/tsl4531.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/tsl4531.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/tsl4531.c- Extension
.c- Size
- 5720 bytes
- Lines
- 250
- 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/module.hlinux/i2c.hlinux/err.hlinux/delay.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct tsl4531_datafunction tsl4531_read_rawfunction tsl4531_write_rawfunction tsl4531_check_idfunction tsl4531_probefunction tsl4531_powerdownfunction tsl4531_removefunction tsl4531_suspendfunction tsl4531_resume
Annotated Snippet
struct tsl4531_data {
struct i2c_client *client;
struct mutex lock;
int int_time;
};
static IIO_CONST_ATTR_INT_TIME_AVAIL("0.1 0.2 0.4");
static struct attribute *tsl4531_attributes[] = {
&iio_const_attr_integration_time_available.dev_attr.attr,
NULL
};
static const struct attribute_group tsl4531_attribute_group = {
.attrs = tsl4531_attributes,
};
static const struct iio_chan_spec tsl4531_channels[] = {
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) |
BIT(IIO_CHAN_INFO_INT_TIME)
}
};
static int tsl4531_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct tsl4531_data *data = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = i2c_smbus_read_word_data(data->client,
TSL4531_DATA);
if (ret < 0)
return ret;
*val = ret;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
/* 0.. 1x, 1 .. 2x, 2 .. 4x */
*val = 1 << data->int_time;
return IIO_VAL_INT;
case IIO_CHAN_INFO_INT_TIME:
if (data->int_time == 0)
*val2 = 400000;
else if (data->int_time == 1)
*val2 = 200000;
else if (data->int_time == 2)
*val2 = 100000;
else
return -EINVAL;
*val = 0;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
}
static int tsl4531_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
struct tsl4531_data *data = iio_priv(indio_dev);
int int_time, ret;
switch (mask) {
case IIO_CHAN_INFO_INT_TIME:
if (val != 0)
return -EINVAL;
if (val2 == 400000)
int_time = 0;
else if (val2 == 200000)
int_time = 1;
else if (val2 == 100000)
int_time = 2;
else
return -EINVAL;
mutex_lock(&data->lock);
ret = i2c_smbus_write_byte_data(data->client,
TSL4531_CONFIG, int_time);
if (ret >= 0)
data->int_time = int_time;
mutex_unlock(&data->lock);
return ret;
default:
return -EINVAL;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/err.h`, `linux/delay.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct tsl4531_data`, `function tsl4531_read_raw`, `function tsl4531_write_raw`, `function tsl4531_check_id`, `function tsl4531_probe`, `function tsl4531_powerdown`, `function tsl4531_remove`, `function tsl4531_suspend`, `function tsl4531_resume`.
- 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.