drivers/iio/light/bh1780.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/bh1780.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/bh1780.c- Extension
.c- Size
- 7060 bytes
- Lines
- 286
- 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/slab.hlinux/platform_device.hlinux/delay.hlinux/module.hlinux/mod_devicetable.hlinux/pm_runtime.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/bitops.h
Detected Declarations
struct bh1780_datafunction bh1780_writefunction bh1780_readfunction bh1780_read_wordfunction bh1780_debugfs_reg_accessfunction bh1780_read_rawfunction bh1780_probefunction bh1780_removefunction bh1780_runtime_suspendfunction bh1780_runtime_resume
Annotated Snippet
struct bh1780_data {
struct i2c_client *client;
};
static int bh1780_write(struct bh1780_data *bh1780, u8 reg, u8 val)
{
int ret = i2c_smbus_write_byte_data(bh1780->client,
BH1780_CMD_BIT | reg,
val);
if (ret < 0)
dev_err(&bh1780->client->dev,
"i2c_smbus_write_byte_data failed error "
"%d, register %01x\n",
ret, reg);
return ret;
}
static int bh1780_read(struct bh1780_data *bh1780, u8 reg)
{
int ret = i2c_smbus_read_byte_data(bh1780->client,
BH1780_CMD_BIT | reg);
if (ret < 0)
dev_err(&bh1780->client->dev,
"i2c_smbus_read_byte_data failed error "
"%d, register %01x\n",
ret, reg);
return ret;
}
static int bh1780_read_word(struct bh1780_data *bh1780, u8 reg)
{
int ret = i2c_smbus_read_word_data(bh1780->client,
BH1780_CMD_BIT | reg);
if (ret < 0)
dev_err(&bh1780->client->dev,
"i2c_smbus_read_word_data failed error "
"%d, register %01x\n",
ret, reg);
return ret;
}
static int bh1780_debugfs_reg_access(struct iio_dev *indio_dev,
unsigned int reg, unsigned int writeval,
unsigned int *readval)
{
struct bh1780_data *bh1780 = iio_priv(indio_dev);
int ret;
if (!readval)
return bh1780_write(bh1780, (u8)reg, (u8)writeval);
ret = bh1780_read(bh1780, (u8)reg);
if (ret < 0)
return ret;
*readval = ret;
return 0;
}
static int bh1780_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct bh1780_data *bh1780 = iio_priv(indio_dev);
int value;
switch (mask) {
case IIO_CHAN_INFO_RAW:
switch (chan->type) {
case IIO_LIGHT:
pm_runtime_get_sync(&bh1780->client->dev);
value = bh1780_read_word(bh1780, BH1780_REG_DLOW);
pm_runtime_put_autosuspend(&bh1780->client->dev);
if (value < 0)
return value;
*val = value;
return IIO_VAL_INT;
default:
return -EINVAL;
}
case IIO_CHAN_INFO_INT_TIME:
*val = 0;
*val2 = BH1780_INTERVAL * 1000;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
}
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/slab.h`, `linux/platform_device.h`, `linux/delay.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/pm_runtime.h`, `linux/iio/iio.h`.
- Detected declarations: `struct bh1780_data`, `function bh1780_write`, `function bh1780_read`, `function bh1780_read_word`, `function bh1780_debugfs_reg_access`, `function bh1780_read_raw`, `function bh1780_probe`, `function bh1780_remove`, `function bh1780_runtime_suspend`, `function bh1780_runtime_resume`.
- 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.