drivers/hwmon/chipcap2.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/chipcap2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/chipcap2.c- Extension
.c- Size
- 18296 bytes
- Lines
- 778
- Domain
- Driver Families
- Bucket
- drivers/hwmon
- 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.
- 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/bitfield.hlinux/bits.hlinux/cleanup.hlinux/completion.hlinux/delay.hlinux/hwmon.hlinux/i2c.hlinux/interrupt.hlinux/irq.hlinux/module.hlinux/regulator/consumer.h
Detected Declarations
struct cc2_rh_alarm_infostruct cc2_dataenum cc2_chan_addrfunction cc2_rh_convertfunction cc2_rh_to_regfunction cc2_temp_convertfunction cc2_enablefunction cc2_disablefunction cc2_cmd_response_diagnosticfunction cc2_read_command_statusfunction cc2_command_mode_startfunction cc2_command_mode_finishfunction cc2_write_regfunction cc2_read_regfunction cc2_get_reg_valfunction cc2_data_fetchfunction cc2_read_measurementfunction cc2_measurementfunction cc2_read_hyst_and_measurefunction cc2_is_visiblefunction cc2_ready_interruptfunction cc2_low_interruptfunction cc2_high_interruptfunction cc2_humidity_min_alarm_statusfunction cc2_humidity_max_alarm_statusfunction cc2_readfunction cc2_writefunction cc2_request_ready_irqfunction cc2_request_alarm_irqsfunction cc2_probefunction cc2_remove
Annotated Snippet
struct cc2_rh_alarm_info {
bool low_alarm;
bool high_alarm;
bool low_alarm_visible;
bool high_alarm_visible;
};
struct cc2_data {
struct cc2_rh_alarm_info rh_alarm;
struct completion complete;
struct device *hwmon;
struct i2c_client *client;
struct regulator *regulator;
const char *name;
int irq_ready;
int irq_low;
int irq_high;
bool process_irqs;
};
enum cc2_chan_addr {
CC2_CHAN_TEMP = 0,
CC2_CHAN_HUMIDITY,
};
/* %RH as a per cent mille from a register value */
static long cc2_rh_convert(u16 data)
{
unsigned long tmp = (data & CC2_RH_DATA_FIELD) * CC2_RH_MAX;
return tmp / ((1 << 14) - 1);
}
/* convert %RH to a register value */
static u16 cc2_rh_to_reg(long data)
{
return data * ((1 << 14) - 1) / CC2_RH_MAX;
}
/* temperature in milli degrees celsius from a register value */
static long cc2_temp_convert(u16 data)
{
unsigned long tmp = ((data >> 2) * 165 * 1000U) / ((1 << 14) - 1);
return tmp - 40 * 1000U;
}
static int cc2_enable(struct cc2_data *data)
{
int ret;
/* exclusive regulator, check in case a disable failed */
if (regulator_is_enabled(data->regulator))
return 0;
/* clear any pending completion */
try_wait_for_completion(&data->complete);
ret = regulator_enable(data->regulator);
if (ret < 0)
return ret;
usleep_range(CC2_STARTUP_TIME_US, CC2_STARTUP_TIME_US + 125);
data->process_irqs = true;
return 0;
}
static void cc2_disable(struct cc2_data *data)
{
int err;
/* ignore alarms triggered by voltage toggling when powering up */
data->process_irqs = false;
/* exclusive regulator, check in case an enable failed */
if (regulator_is_enabled(data->regulator)) {
err = regulator_disable(data->regulator);
if (err)
dev_dbg(&data->client->dev, "Failed to disable device");
}
}
static int cc2_cmd_response_diagnostic(struct device *dev, u8 status)
{
int resp;
if (FIELD_GET(CC2_STATUS_FIELD, status) != CC2_STATUS_CMD_MODE) {
dev_dbg(dev, "Command sent out of command window\n");
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/cleanup.h`, `linux/completion.h`, `linux/delay.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/interrupt.h`.
- Detected declarations: `struct cc2_rh_alarm_info`, `struct cc2_data`, `enum cc2_chan_addr`, `function cc2_rh_convert`, `function cc2_rh_to_reg`, `function cc2_temp_convert`, `function cc2_enable`, `function cc2_disable`, `function cc2_cmd_response_diagnostic`, `function cc2_read_command_status`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.