drivers/hwmon/w83l785ts.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/w83l785ts.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/w83l785ts.c- Extension
.c- Size
- 7412 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.
- 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/delay.hlinux/init.hlinux/slab.hlinux/jiffies.hlinux/i2c.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/err.hlinux/mutex.h
Detected Declarations
struct w83l785ts_datafunction show_tempfunction w83l785ts_detectfunction w83l785ts_probefunction w83l785ts_removefunction w83l785ts_read_value
Annotated Snippet
struct w83l785ts_data {
struct device *hwmon_dev;
struct mutex update_lock;
bool valid; /* false until following fields are valid */
unsigned long last_updated; /* in jiffies */
/* registers values */
s8 temp[2]; /* 0: input, 1: critical limit */
};
/*
* Sysfs stuff
*/
static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct w83l785ts_data *data = w83l785ts_update_device(dev);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
}
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 1);
/*
* Real code
*/
/* Return 0 if detection is successful, -ENODEV otherwise */
static int w83l785ts_detect(struct i2c_client *client,
struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;
u16 man_id;
u8 chip_id;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV;
/* detection */
if ((w83l785ts_read_value(client, W83L785TS_REG_CONFIG, 0) & 0x80)
|| (w83l785ts_read_value(client, W83L785TS_REG_TYPE, 0) & 0xFC)) {
dev_dbg(&adapter->dev,
"W83L785TS-S detection failed at 0x%02x\n",
client->addr);
return -ENODEV;
}
/* Identification */
man_id = (w83l785ts_read_value(client, W83L785TS_REG_MAN_ID1, 0) << 8)
+ w83l785ts_read_value(client, W83L785TS_REG_MAN_ID2, 0);
chip_id = w83l785ts_read_value(client, W83L785TS_REG_CHIP_ID, 0);
if (man_id != 0x5CA3 /* Winbond */
|| chip_id != 0x70) { /* W83L785TS-S */
dev_dbg(&adapter->dev,
"Unsupported chip (man_id=0x%04X, chip_id=0x%02X)\n",
man_id, chip_id);
return -ENODEV;
}
strscpy(info->type, "w83l785ts", I2C_NAME_SIZE);
return 0;
}
static int w83l785ts_probe(struct i2c_client *client)
{
struct w83l785ts_data *data;
struct device *dev = &client->dev;
int err;
data = devm_kzalloc(dev, sizeof(struct w83l785ts_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);
/*
* Initialize the W83L785TS chip
* Nothing yet, assume it is already started.
*/
err = device_create_file(dev, &sensor_dev_attr_temp1_input.dev_attr);
if (err)
return err;
err = device_create_file(dev, &sensor_dev_attr_temp1_max.dev_attr);
Annotation
- Immediate include surface: `linux/module.h`, `linux/delay.h`, `linux/init.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/hwmon.h`, `linux/hwmon-sysfs.h`.
- Detected declarations: `struct w83l785ts_data`, `function show_temp`, `function w83l785ts_detect`, `function w83l785ts_probe`, `function w83l785ts_remove`, `function w83l785ts_read_value`.
- 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.