drivers/hwmon/da9055-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/da9055-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/da9055-hwmon.c- Extension
.c- Size
- 7280 bytes
- Lines
- 284
- 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.
- 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/delay.hlinux/err.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/init.hlinux/kernel.hlinux/module.hlinux/platform_device.hlinux/completion.hlinux/mfd/da9055/core.hlinux/mfd/da9055/reg.h
Detected Declarations
struct da9055_hwmonfunction da9055_adc_manual_readfunction msecs_to_jiffiesfunction da9055_auxadc_irqfunction volt_reg_to_mvfunction da9055_enable_auto_modefunction da9055_disable_auto_modefunction da9055_auto_ch_showfunction da9055_tjunc_showfunction label_showfunction da9055_hwmon_probe
Annotated Snippet
struct da9055_hwmon {
struct da9055 *da9055;
struct mutex hwmon_lock;
struct mutex irq_lock;
struct completion done;
};
static const char * const input_names[] = {
[DA9055_ADC_VSYS] = "VSYS",
[DA9055_ADC_ADCIN1] = "ADC IN1",
[DA9055_ADC_ADCIN2] = "ADC IN2",
[DA9055_ADC_ADCIN3] = "ADC IN3",
[DA9055_ADC_TJUNC] = "CHIP TEMP",
};
static const u8 chan_mux[DA9055_ADC_TJUNC + 1] = {
[DA9055_ADC_VSYS] = DA9055_ADC_MUX_VSYS,
[DA9055_ADC_ADCIN1] = DA9055_ADC_MUX_ADCIN1,
[DA9055_ADC_ADCIN2] = DA9055_ADC_MUX_ADCIN2,
[DA9055_ADC_ADCIN3] = DA9055_ADC_MUX_ADCIN3,
[DA9055_ADC_TJUNC] = DA9055_ADC_MUX_T_SENSE,
};
static int da9055_adc_manual_read(struct da9055_hwmon *hwmon,
unsigned char channel)
{
int ret;
unsigned short calc_data;
unsigned short data;
unsigned char mux_sel;
struct da9055 *da9055 = hwmon->da9055;
if (channel > DA9055_ADC_TJUNC)
return -EINVAL;
mutex_lock(&hwmon->irq_lock);
/* Selects desired MUX for manual conversion */
mux_sel = chan_mux[channel] | DA9055_ADC_MAN_CONV;
ret = da9055_reg_write(da9055, DA9055_REG_ADC_MAN, mux_sel);
if (ret < 0)
goto err;
/* Wait for an interrupt */
if (!wait_for_completion_timeout(&hwmon->done,
msecs_to_jiffies(500))) {
dev_err(da9055->dev,
"timeout waiting for ADC conversion interrupt\n");
ret = -ETIMEDOUT;
goto err;
}
ret = da9055_reg_read(da9055, DA9055_REG_ADC_RES_H);
if (ret < 0)
goto err;
calc_data = (unsigned short)ret;
data = calc_data << 2;
ret = da9055_reg_read(da9055, DA9055_REG_ADC_RES_L);
if (ret < 0)
goto err;
calc_data = (unsigned short)(ret & DA9055_ADC_LSB_MASK);
data |= calc_data;
ret = data;
err:
mutex_unlock(&hwmon->irq_lock);
return ret;
}
static irqreturn_t da9055_auxadc_irq(int irq, void *irq_data)
{
struct da9055_hwmon *hwmon = irq_data;
complete(&hwmon->done);
return IRQ_HANDLED;
}
/* Conversion function for VSYS and ADCINx */
static inline int volt_reg_to_mv(int value, int channel)
{
if (channel == DA9055_ADC_VSYS)
return DIV_ROUND_CLOSEST(value * 1000, DA9055_VSYS_DIV) + 2500;
else
return DIV_ROUND_CLOSEST(value * 1000, DA9055_ADCIN_DIV);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/err.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct da9055_hwmon`, `function da9055_adc_manual_read`, `function msecs_to_jiffies`, `function da9055_auxadc_irq`, `function volt_reg_to_mv`, `function da9055_enable_auto_mode`, `function da9055_disable_auto_mode`, `function da9055_auto_ch_show`, `function da9055_tjunc_show`, `function label_show`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.