drivers/hwmon/isl28022.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/isl28022.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/isl28022.c- Extension
.c- Size
- 11956 bytes
- Lines
- 502
- 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/debugfs.hlinux/err.hlinux/hwmon.hlinux/i2c.hlinux/math64.hlinux/module.hlinux/regmap.h
Detected Declarations
struct isl28022_datafunction isl28022_read_infunction isl28022_read_currentfunction isl28022_read_powerfunction isl28022_readfunction isl28022_is_visiblefunction isl28022_is_writeable_regfunction isl28022_is_volatile_regfunction shunt_voltage_showfunction isl28022_read_propertiesfunction samplesfunction isl28022_probe
Annotated Snippet
struct isl28022_data {
struct regmap *regmap;
u32 shunt;
u32 gain;
u32 average;
};
static int isl28022_read_in(struct device *dev, u32 attr, int channel, long *val)
{
struct isl28022_data *data = dev_get_drvdata(dev);
unsigned int regval;
int err;
u16 sign_bit;
switch (channel) {
case 0:
switch (attr) {
case hwmon_in_input:
err = regmap_read(data->regmap,
ISL28022_REG_BUS, ®val);
if (err < 0)
return err;
/* driver supports only 60V mode (BRNG 11) */
*val = (long)(((u16)regval) & 0xFFFC);
break;
default:
return -EOPNOTSUPP;
}
break;
case 1:
switch (attr) {
case hwmon_in_input:
err = regmap_read(data->regmap,
ISL28022_REG_SHUNT, ®val);
if (err < 0)
return err;
switch (data->gain) {
case 8:
sign_bit = (regval >> 15) & 0x01;
*val = (long)((((u16)regval) & 0x7FFF) -
(sign_bit * 32768)) / 100;
break;
case 4:
sign_bit = (regval >> 14) & 0x01;
*val = (long)((((u16)regval) & 0x3FFF) -
(sign_bit * 16384)) / 100;
break;
case 2:
sign_bit = (regval >> 13) & 0x01;
*val = (long)((((u16)regval) & 0x1FFF) -
(sign_bit * 8192)) / 100;
break;
case 1:
sign_bit = (regval >> 12) & 0x01;
*val = (long)((((u16)regval) & 0x0FFF) -
(sign_bit * 4096)) / 100;
break;
}
break;
default:
return -EOPNOTSUPP;
}
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
static int isl28022_read_current(struct device *dev, u32 attr, long *val)
{
struct isl28022_data *data = dev_get_drvdata(dev);
unsigned int regval;
int err;
u16 sign_bit;
switch (attr) {
case hwmon_curr_input:
err = regmap_read(data->regmap,
ISL28022_REG_CURRENT, ®val);
if (err < 0)
return err;
sign_bit = (regval >> 15) & 0x01;
*val = (((long)(((u16)regval) & 0x7FFF) - (sign_bit * 32768)) *
1250L * (long)data->gain) / (long)data->shunt;
break;
default:
return -EOPNOTSUPP;
}
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/err.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/math64.h`, `linux/module.h`, `linux/regmap.h`.
- Detected declarations: `struct isl28022_data`, `function isl28022_read_in`, `function isl28022_read_current`, `function isl28022_read_power`, `function isl28022_read`, `function isl28022_is_visible`, `function isl28022_is_writeable_reg`, `function isl28022_is_volatile_reg`, `function shunt_voltage_show`, `function isl28022_read_properties`.
- 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.