drivers/hwmon/powr1220.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/powr1220.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/powr1220.c- Extension
.c- Size
- 7176 bytes
- Lines
- 329
- 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.
- 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/module.hlinux/init.hlinux/slab.hlinux/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/delay.h
Detected Declarations
struct powr1220_dataenum powr1xxx_chipsenum powr1220_regsenum powr1220_adc_valuesfunction powr1220_read_adcfunction powr1220_is_visiblefunction powr1220_read_stringfunction powr1220_readfunction powr1220_probe
Annotated Snippet
struct powr1220_data {
struct i2c_client *client;
u8 max_channels;
bool adc_valid[MAX_POWR1220_ADC_VALUES];
/* the next value is in jiffies */
unsigned long adc_last_updated[MAX_POWR1220_ADC_VALUES];
/* values */
int adc_maxes[MAX_POWR1220_ADC_VALUES];
int adc_values[MAX_POWR1220_ADC_VALUES];
};
static const char * const input_names[] = {
[VMON1] = "vmon1",
[VMON2] = "vmon2",
[VMON3] = "vmon3",
[VMON4] = "vmon4",
[VMON5] = "vmon5",
[VMON6] = "vmon6",
[VMON7] = "vmon7",
[VMON8] = "vmon8",
[VMON9] = "vmon9",
[VMON10] = "vmon10",
[VMON11] = "vmon11",
[VMON12] = "vmon12",
[VCCA] = "vcca",
[VCCINP] = "vccinp",
};
/* Reads the specified ADC channel */
static int powr1220_read_adc(struct device *dev, int ch_num)
{
struct powr1220_data *data = dev_get_drvdata(dev);
int reading;
int result;
int adc_range = 0;
if (time_after(jiffies, data->adc_last_updated[ch_num] + HZ) ||
!data->adc_valid[ch_num]) {
/*
* figure out if we need to use the attenuator for
* high inputs or inputs that we don't yet have a measurement
* for. We dynamically set the attenuator depending on the
* max reading.
*/
if (data->adc_maxes[ch_num] > ADC_MAX_LOW_MEASUREMENT_MV ||
data->adc_maxes[ch_num] == 0)
adc_range = 1 << 4;
/* set the attenuator and mux */
result = i2c_smbus_write_byte_data(data->client, ADC_MUX,
adc_range | ch_num);
if (result < 0)
return result;
/*
* wait at least Tconvert time (200 us) for the
* conversion to complete
*/
udelay(200);
/* get the ADC reading */
result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_LOW);
if (result < 0)
return result;
reading = result >> 4;
/* get the upper half of the reading */
result = i2c_smbus_read_byte_data(data->client, ADC_VALUE_HIGH);
if (result < 0)
return result;
reading |= result << 4;
/* now convert the reading to a voltage */
reading *= ADC_STEP_MV;
data->adc_values[ch_num] = reading;
data->adc_valid[ch_num] = true;
data->adc_last_updated[ch_num] = jiffies;
result = reading;
if (reading > data->adc_maxes[ch_num])
data->adc_maxes[ch_num] = reading;
} else {
result = data->adc_values[ch_num];
}
return result;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/err.h`.
- Detected declarations: `struct powr1220_data`, `enum powr1xxx_chips`, `enum powr1220_regs`, `enum powr1220_adc_values`, `function powr1220_read_adc`, `function powr1220_is_visible`, `function powr1220_read_string`, `function powr1220_read`, `function powr1220_probe`.
- Atlas domain: Driver Families / drivers/hwmon.
- 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.