drivers/misc/bh1770glc.c
Source file repositories/reference/linux-study-clean/drivers/misc/bh1770glc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/bh1770glc.c- Extension
.c- Size
- 37678 bytes
- Lines
- 1393
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/i2c.hlinux/interrupt.hlinux/mutex.hlinux/platform_data/bh1770glc.hlinux/regulator/consumer.hlinux/pm_runtime.hlinux/workqueue.hlinux/delay.hlinux/wait.hlinux/slab.h
Detected Declarations
struct bh1770_chipfunction bh1770_lux_interrupt_controlfunction bh1770_prox_interrupt_controlfunction bh1770_lux_ratefunction bh1770_prox_ratefunction bh1770_led_cfgfunction bh1770_psraw_to_adjustedfunction bh1770_psadjusted_to_rawfunction bh1770_prox_set_thresholdfunction bh1770_lux_raw_to_adjustedfunction bh1770_lux_adjusted_to_rawfunction bh1770_lux_update_thresholdsfunction bh1770_lux_get_resultfunction bh1770_get_corr_valuefunction bh1770_lux_read_resultfunction bh1770_chip_onfunction bh1770_chip_offfunction bh1770_prox_mode_controlfunction bh1770_prox_read_resultfunction bh1770_detectfunction bh1770_prox_workfunction bh1770_irqfunction bh1770_power_state_storefunction bh1770_power_state_showfunction bh1770_lux_result_showfunction bh1770_lux_range_showfunction bh1770_prox_enable_storefunction bh1770_prox_enable_showfunction bh1770_prox_result_showfunction bh1770_prox_range_showfunction bh1770_get_prox_rate_availfunction bh1770_get_prox_rate_abovefunction bh1770_get_prox_rate_belowfunction bh1770_prox_rate_validatefunction bh1770_set_prox_rate_abovefunction bh1770_set_prox_rate_belowfunction bh1770_get_prox_thresfunction bh1770_set_prox_thresfunction bh1770_prox_persistence_showfunction bh1770_prox_persistence_storefunction bh1770_prox_abs_thres_showfunction bh1770_prox_abs_thres_storefunction bh1770_chip_id_showfunction bh1770_lux_calib_default_showfunction bh1770_lux_calib_showfunction bh1770_lux_calib_storefunction bh1770_get_lux_rate_availfunction bh1770_get_lux_rate
Annotated Snippet
struct bh1770_chip {
struct bh1770_platform_data *pdata;
char chipname[10];
u8 revision;
struct i2c_client *client;
struct regulator_bulk_data regs[2];
struct mutex mutex; /* avoid parallel access */
wait_queue_head_t wait;
bool int_mode_prox;
bool int_mode_lux;
struct delayed_work prox_work;
u32 lux_cf; /* Chip specific factor */
u32 lux_ga;
u32 lux_calib;
int lux_rate_index;
u32 lux_corr;
u16 lux_data_raw;
u16 lux_threshold_hi;
u16 lux_threshold_lo;
u16 lux_thres_hi_onchip;
u16 lux_thres_lo_onchip;
bool lux_wait_result;
int prox_enable_count;
u16 prox_coef;
u16 prox_const;
int prox_rate;
int prox_rate_threshold;
u8 prox_persistence;
u8 prox_persistence_counter;
u8 prox_data;
u8 prox_threshold;
u8 prox_threshold_hw;
bool prox_force_update;
u8 prox_abs_thres;
u8 prox_led;
};
static const char reg_vcc[] = "Vcc";
static const char reg_vleds[] = "Vleds";
/*
* Supported stand alone rates in ms from chip data sheet
* {10, 20, 30, 40, 70, 100, 200, 500, 1000, 2000};
*/
static const s16 prox_rates_hz[] = {100, 50, 33, 25, 14, 10, 5, 2};
static const s16 prox_rates_ms[] = {10, 20, 30, 40, 70, 100, 200, 500};
/*
* Supported stand alone rates in ms from chip data sheet
* {100, 200, 500, 1000, 2000};
*/
static const s16 lux_rates_hz[] = {10, 5, 2, 1, 0};
/*
* interrupt control functions are called while keeping chip->mutex
* excluding module probe / remove
*/
static inline int bh1770_lux_interrupt_control(struct bh1770_chip *chip,
int lux)
{
chip->int_mode_lux = lux;
/* Set interrupt modes, interrupt active low, latched */
return i2c_smbus_write_byte_data(chip->client,
BH1770_INTERRUPT,
(lux << 1) | chip->int_mode_prox);
}
static inline int bh1770_prox_interrupt_control(struct bh1770_chip *chip,
int ps)
{
chip->int_mode_prox = ps;
return i2c_smbus_write_byte_data(chip->client,
BH1770_INTERRUPT,
(chip->int_mode_lux << 1) | (ps << 0));
}
/* chip->mutex is always kept here */
static int bh1770_lux_rate(struct bh1770_chip *chip, int rate_index)
{
/* sysfs may call this when the chip is powered off */
if (pm_runtime_suspended(&chip->client->dev))
return 0;
/* Proper proximity response needs fastest lux rate (100ms) */
if (chip->prox_enable_count)
rate_index = 0;
return i2c_smbus_write_byte_data(chip->client,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/mutex.h`, `linux/platform_data/bh1770glc.h`, `linux/regulator/consumer.h`, `linux/pm_runtime.h`.
- Detected declarations: `struct bh1770_chip`, `function bh1770_lux_interrupt_control`, `function bh1770_prox_interrupt_control`, `function bh1770_lux_rate`, `function bh1770_prox_rate`, `function bh1770_led_cfg`, `function bh1770_psraw_to_adjusted`, `function bh1770_psadjusted_to_raw`, `function bh1770_prox_set_threshold`, `function bh1770_lux_raw_to_adjusted`.
- Atlas domain: Driver Families / drivers/misc.
- 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.