drivers/hwmon/da9052-hwmon.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/da9052-hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/da9052-hwmon.c- Extension
.c- Size
- 13617 bytes
- Lines
- 488
- 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/err.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/init.hlinux/kernel.hlinux/module.hlinux/slab.hlinux/platform_device.hlinux/property.hlinux/mfd/da9052/da9052.hlinux/mfd/da9052/reg.hlinux/regulator/consumer.h
Detected Declarations
struct da9052_hwmonfunction volt_reg_to_mvfunction input_reg_to_mvfunction vbbat_reg_to_mvfunction input_tsireg_to_mvfunction da9052_enable_vddout_channelfunction da9052_disable_vddout_channelfunction da9052_vddout_showfunction da9052_ich_showfunction da9052_tbat_showfunction da9052_vbat_showfunction da9052_misc_channel_showfunction da9052_request_tsi_readfunction da9052_get_tsi_resultfunction __da9052_read_tsifunction da9052_tsi_showfunction da9052_tjunc_showfunction da9052_vbbat_showfunction label_showfunction da9052_channel_is_visiblefunction da9052_tsi_datardy_irqfunction da9052_hwmon_probefunction da9052_hwmon_remove
Annotated Snippet
struct da9052_hwmon {
struct da9052 *da9052;
struct mutex hwmon_lock;
bool tsi_as_adc;
int tsiref_mv;
struct completion tsidone;
};
static const char * const input_names[] = {
[DA9052_ADC_VDDOUT] = "VDDOUT",
[DA9052_ADC_ICH] = "CHARGING CURRENT",
[DA9052_ADC_TBAT] = "BATTERY TEMP",
[DA9052_ADC_VBAT] = "BATTERY VOLTAGE",
[DA9052_ADC_IN4] = "ADC IN4",
[DA9052_ADC_IN5] = "ADC IN5",
[DA9052_ADC_IN6] = "ADC IN6",
[DA9052_ADC_TSI_XP] = "ADC TS X+",
[DA9052_ADC_TSI_YP] = "ADC TS Y+",
[DA9052_ADC_TSI_XN] = "ADC TS X-",
[DA9052_ADC_TSI_YN] = "ADC TS Y-",
[DA9052_ADC_TJUNC] = "BATTERY JUNCTION TEMP",
[DA9052_ADC_VBBAT] = "BACK-UP BATTERY VOLTAGE",
};
/* Conversion function for VDDOUT and VBAT */
static inline int volt_reg_to_mv(int value)
{
return DIV_ROUND_CLOSEST(value * 2000, 1023) + 2500;
}
/* Conversion function for ADC channels 4, 5 and 6 */
static inline int input_reg_to_mv(int value)
{
return DIV_ROUND_CLOSEST(value * 2500, 1023);
}
/* Conversion function for VBBAT */
static inline int vbbat_reg_to_mv(int value)
{
return DIV_ROUND_CLOSEST(value * 5000, 1023);
}
static inline int input_tsireg_to_mv(struct da9052_hwmon *hwmon, int value)
{
return DIV_ROUND_CLOSEST(value * hwmon->tsiref_mv, 1023);
}
static inline int da9052_enable_vddout_channel(struct da9052 *da9052)
{
return da9052_reg_update(da9052, DA9052_ADC_CONT_REG,
DA9052_ADCCONT_AUTOVDDEN,
DA9052_ADCCONT_AUTOVDDEN);
}
static inline int da9052_disable_vddout_channel(struct da9052 *da9052)
{
return da9052_reg_update(da9052, DA9052_ADC_CONT_REG,
DA9052_ADCCONT_AUTOVDDEN, 0);
}
static ssize_t da9052_vddout_show(struct device *dev,
struct device_attribute *devattr, char *buf)
{
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
int ret, vdd;
mutex_lock(&hwmon->hwmon_lock);
ret = da9052_enable_vddout_channel(hwmon->da9052);
if (ret < 0)
goto hwmon_err;
vdd = da9052_reg_read(hwmon->da9052, DA9052_VDD_RES_REG);
if (vdd < 0) {
ret = vdd;
goto hwmon_err_release;
}
ret = da9052_disable_vddout_channel(hwmon->da9052);
if (ret < 0)
goto hwmon_err;
mutex_unlock(&hwmon->hwmon_lock);
return sprintf(buf, "%d\n", volt_reg_to_mv(vdd));
hwmon_err_release:
da9052_disable_vddout_channel(hwmon->da9052);
hwmon_err:
mutex_unlock(&hwmon->hwmon_lock);
return ret;
Annotation
- Immediate include surface: `linux/err.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/platform_device.h`.
- Detected declarations: `struct da9052_hwmon`, `function volt_reg_to_mv`, `function input_reg_to_mv`, `function vbbat_reg_to_mv`, `function input_tsireg_to_mv`, `function da9052_enable_vddout_channel`, `function da9052_disable_vddout_channel`, `function da9052_vddout_show`, `function da9052_ich_show`, `function da9052_tbat_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.