drivers/iio/light/bh1745.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/bh1745.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/bh1745.c- Extension
.c- Size
- 22548 bytes
- Lines
- 902
- 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.
- 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/i2c.hlinux/mutex.hlinux/util_macros.hlinux/iio/events.hlinux/regmap.hlinux/bits.hlinux/bitfield.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/iio/iio-gts-helper.h
Detected Declarations
struct bh1745_dataenum bh1745_int_sourceenum bh1745_gainenum bh1745_measurement_timeenum bh1745_presistence_valuefunction bh1745_resetfunction bh1745_power_onfunction bh1745_power_offfunction bh1745_get_scalefunction bh1745_set_scalefunction bh1745_get_int_timefunction bh1745_set_int_timefunction bh1745_read_rawfunction bh1745_write_rawfunction bh1745_write_raw_get_fmtfunction bh1745_read_threshfunction bh1745_write_threshfunction bh1745_read_event_configfunction bh1745_write_event_configfunction bh1745_read_availfunction bh1745_interrupt_handlerfunction bh1745_trigger_handlerfunction iio_for_each_active_channelfunction bh1745_setup_triggered_bufferfunction bh1745_initfunction bh1745_probe
Annotated Snippet
struct bh1745_data {
/*
* Lock to prevent device setting update or read before
* related calculations are completed
*/
struct mutex lock;
struct regmap *regmap;
struct device *dev;
struct iio_trigger *trig;
struct iio_gts gts;
};
static const struct regmap_range bh1745_volatile_ranges[] = {
regmap_reg_range(BH1745_MODE_CTRL2, BH1745_MODE_CTRL2), /* VALID */
regmap_reg_range(BH1745_RED_LSB, BH1745_CLEAR_MSB), /* Data */
regmap_reg_range(BH1745_INTR, BH1745_INTR), /* Interrupt */
};
static const struct regmap_access_table bh1745_volatile_regs = {
.yes_ranges = bh1745_volatile_ranges,
.n_yes_ranges = ARRAY_SIZE(bh1745_volatile_ranges),
};
static const struct regmap_range bh1745_readable_ranges[] = {
regmap_reg_range(BH1745_SYS_CTRL, BH1745_MODE_CTRL2),
regmap_reg_range(BH1745_RED_LSB, BH1745_CLEAR_MSB),
regmap_reg_range(BH1745_INTR, BH1745_INTR),
regmap_reg_range(BH1745_PERSISTENCE, BH1745_TL_MSB),
regmap_reg_range(BH1745_MANU_ID_REG, BH1745_MANU_ID_REG),
};
static const struct regmap_access_table bh1745_readable_regs = {
.yes_ranges = bh1745_readable_ranges,
.n_yes_ranges = ARRAY_SIZE(bh1745_readable_ranges),
};
static const struct regmap_range bh1745_writable_ranges[] = {
regmap_reg_range(BH1745_SYS_CTRL, BH1745_MODE_CTRL2),
regmap_reg_range(BH1745_INTR, BH1745_INTR),
regmap_reg_range(BH1745_PERSISTENCE, BH1745_TL_MSB),
};
static const struct regmap_access_table bh1745_writable_regs = {
.yes_ranges = bh1745_writable_ranges,
.n_yes_ranges = ARRAY_SIZE(bh1745_writable_ranges),
};
static const struct regmap_config bh1745_regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = BH1745_MANU_ID_REG,
.cache_type = REGCACHE_RBTREE,
.volatile_table = &bh1745_volatile_regs,
.wr_table = &bh1745_writable_regs,
.rd_table = &bh1745_readable_regs,
};
static const struct iio_event_spec bh1745_event_spec[] = {
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_RISING,
.mask_shared_by_type = BIT(IIO_EV_INFO_VALUE),
},
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_FALLING,
.mask_shared_by_type = BIT(IIO_EV_INFO_VALUE),
},
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_EITHER,
.mask_shared_by_type = BIT(IIO_EV_INFO_PERIOD),
.mask_separate = BIT(IIO_EV_INFO_ENABLE),
},
};
#define BH1745_CHANNEL(_colour, _si, _addr) \
{ \
.type = IIO_INTENSITY, .modified = 1, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE) | \
BIT(IIO_CHAN_INFO_INT_TIME), \
.info_mask_shared_by_all_available = \
BIT(IIO_CHAN_INFO_SCALE) | \
BIT(IIO_CHAN_INFO_INT_TIME), \
.event_spec = bh1745_event_spec, \
.num_event_specs = ARRAY_SIZE(bh1745_event_spec), \
.channel2 = IIO_MOD_LIGHT_##_colour, .address = _addr, \
.scan_index = _si, \
.scan_type = { \
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/mutex.h`, `linux/util_macros.h`, `linux/iio/events.h`, `linux/regmap.h`, `linux/bits.h`, `linux/bitfield.h`, `linux/iio/iio.h`.
- Detected declarations: `struct bh1745_data`, `enum bh1745_int_source`, `enum bh1745_gain`, `enum bh1745_measurement_time`, `enum bh1745_presistence_value`, `function bh1745_reset`, `function bh1745_power_on`, `function bh1745_power_off`, `function bh1745_get_scale`, `function bh1745_set_scale`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- 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.