drivers/hwmon/max197.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/max197.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/max197.c- Extension
.c- Size
- 8762 bytes
- Lines
- 343
- 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/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/init.hlinux/err.hlinux/slab.hlinux/mutex.hlinux/device.hlinux/sysfs.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/platform_device.hlinux/platform_data/max197.h
Detected Declarations
struct max197_dataenum max197_chipsfunction max197_set_unipolarityfunction max197_set_bipolarityfunction max197_set_half_rangefunction max197_set_full_rangefunction max197_is_bipolarfunction max197_is_full_rangefunction max197_show_rangefunction max197_store_rangefunction max197_show_inputfunction name_showfunction max197_probefunction max197_remove
Annotated Snippet
struct max197_data {
struct max197_platform_data *pdata;
struct device *hwmon_dev;
struct mutex lock;
int limit;
bool scale;
u8 ctrl_bytes[MAX197_NUM_CH];
};
static inline void max197_set_unipolarity(struct max197_data *data, int channel)
{
data->ctrl_bytes[channel] &= ~MAX197_BIP;
}
static inline void max197_set_bipolarity(struct max197_data *data, int channel)
{
data->ctrl_bytes[channel] |= MAX197_BIP;
}
static inline void max197_set_half_range(struct max197_data *data, int channel)
{
data->ctrl_bytes[channel] &= ~MAX197_RNG;
}
static inline void max197_set_full_range(struct max197_data *data, int channel)
{
data->ctrl_bytes[channel] |= MAX197_RNG;
}
static inline bool max197_is_bipolar(struct max197_data *data, int channel)
{
return data->ctrl_bytes[channel] & MAX197_BIP;
}
static inline bool max197_is_full_range(struct max197_data *data, int channel)
{
return data->ctrl_bytes[channel] & MAX197_RNG;
}
/* Function called on read access on in{0,1,2,3,4,5,6,7}_{min,max} */
static ssize_t max197_show_range(struct device *dev,
struct device_attribute *devattr, char *buf)
{
struct max197_data *data = dev_get_drvdata(dev);
struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
int channel = attr->index;
bool is_min = attr->nr;
int range;
if (mutex_lock_interruptible(&data->lock))
return -ERESTARTSYS;
range = max197_is_full_range(data, channel) ?
data->limit : data->limit / 2;
if (is_min) {
if (max197_is_bipolar(data, channel))
range = -range;
else
range = 0;
}
mutex_unlock(&data->lock);
return sprintf(buf, "%d\n", range);
}
/* Function called on write access on in{0,1,2,3,4,5,6,7}_{min,max} */
static ssize_t max197_store_range(struct device *dev,
struct device_attribute *devattr,
const char *buf, size_t count)
{
struct max197_data *data = dev_get_drvdata(dev);
struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
int channel = attr->index;
bool is_min = attr->nr;
long value;
int half = data->limit / 2;
int full = data->limit;
if (kstrtol(buf, 10, &value))
return -EINVAL;
if (is_min) {
if (value <= -full)
value = -full;
else if (value < 0)
value = -half;
else
value = 0;
} else {
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/init.h`, `linux/err.h`, `linux/slab.h`, `linux/mutex.h`, `linux/device.h`.
- Detected declarations: `struct max197_data`, `enum max197_chips`, `function max197_set_unipolarity`, `function max197_set_bipolarity`, `function max197_set_half_range`, `function max197_set_full_range`, `function max197_is_bipolar`, `function max197_is_full_range`, `function max197_show_range`, `function max197_store_range`.
- 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.