drivers/hwmon/asb100.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/asb100.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/asb100.c- Extension
.c- Size
- 27797 bytes
- Lines
- 1009
- 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.
- 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/slab.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/hwmon-vid.hlinux/err.hlinux/init.hlinux/jiffies.hlinux/mutex.hlm75.h
Detected Declarations
struct asb100_datafunction IN_TO_REGfunction IN_FROM_REGfunction FAN_TO_REGfunction FAN_FROM_REGfunction TEMP_TO_REGfunction TEMP_FROM_REGfunction ASB100_PWM_TO_REGfunction ASB100_PWM_FROM_REGfunction DIV_TO_REGfunction show_fanfunction show_fan_minfunction show_fan_divfunction set_fan_minfunction set_fan_divfunction sprintf_temp_from_regfunction cpu0_vid_showfunction vrm_showfunction vrm_storefunction alarms_showfunction show_alarmfunction pwm1_showfunction pwm1_storefunction pwm1_enable_showfunction pwm1_enable_storefunction asb100_detect_subclientsfunction asb100_detectfunction asb100_probefunction asb100_removefunction asb100_read_valuefunction asb100_write_valuefunction asb100_init_client
Annotated Snippet
struct asb100_data {
struct device *hwmon_dev;
struct mutex lock;
struct mutex update_lock;
unsigned long last_updated; /* In jiffies */
/* array of 2 pointers to subclients */
struct i2c_client *lm75[2];
bool valid; /* true if following fields are valid */
u8 in[7]; /* Register value */
u8 in_max[7]; /* Register value */
u8 in_min[7]; /* Register value */
u8 fan[3]; /* Register value */
u8 fan_min[3]; /* Register value */
u16 temp[4]; /* Register value (0 and 3 are u8 only) */
u16 temp_max[4]; /* Register value (0 and 3 are u8 only) */
u16 temp_hyst[4]; /* Register value (0 and 3 are u8 only) */
u8 fan_div[3]; /* Register encoding, right justified */
u8 pwm; /* Register encoding */
u8 vid; /* Register encoding, combined */
u32 alarms; /* Register encoding, combined */
u8 vrm;
};
static int asb100_read_value(struct i2c_client *client, u16 reg);
static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val);
static int asb100_probe(struct i2c_client *client);
static int asb100_detect(struct i2c_client *client,
struct i2c_board_info *info);
static void asb100_remove(struct i2c_client *client);
static struct asb100_data *asb100_update_device(struct device *dev);
static void asb100_init_client(struct i2c_client *client);
static const struct i2c_device_id asb100_id[] = {
{ .name = "asb100" },
{ }
};
MODULE_DEVICE_TABLE(i2c, asb100_id);
static struct i2c_driver asb100_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "asb100",
},
.probe = asb100_probe,
.remove = asb100_remove,
.id_table = asb100_id,
.detect = asb100_detect,
.address_list = normal_i2c,
};
/* 7 Voltages */
#define show_in_reg(reg) \
static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
char *buf) \
{ \
int nr = to_sensor_dev_attr(attr)->index; \
struct asb100_data *data = asb100_update_device(dev); \
return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
}
show_in_reg(in)
show_in_reg(in_min)
show_in_reg(in_max)
#define set_in_reg(REG, reg) \
static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \
const char *buf, size_t count) \
{ \
int nr = to_sensor_dev_attr(attr)->index; \
struct i2c_client *client = to_i2c_client(dev); \
struct asb100_data *data = i2c_get_clientdata(client); \
unsigned long val; \
int err = kstrtoul(buf, 10, &val); \
if (err) \
return err; \
mutex_lock(&data->update_lock); \
data->in_##reg[nr] = IN_TO_REG(val); \
asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
data->in_##reg[nr]); \
mutex_unlock(&data->update_lock); \
return count; \
}
set_in_reg(MIN, min)
set_in_reg(MAX, max)
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/hwmon-vid.h`, `linux/err.h`, `linux/init.h`.
- Detected declarations: `struct asb100_data`, `function IN_TO_REG`, `function IN_FROM_REG`, `function FAN_TO_REG`, `function FAN_FROM_REG`, `function TEMP_TO_REG`, `function TEMP_FROM_REG`, `function ASB100_PWM_TO_REG`, `function ASB100_PWM_FROM_REG`, `function DIV_TO_REG`.
- 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.
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.