drivers/hwmon/mc13783-adc.c
Source file repositories/reference/linux-study-clean/drivers/hwmon/mc13783-adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwmon/mc13783-adc.c- Extension
.c- Size
- 8957 bytes
- Lines
- 330
- 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/mfd/mc13xxx.hlinux/platform_device.hlinux/hwmon-sysfs.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/hwmon.hlinux/slab.hlinux/init.hlinux/err.h
Detected Declarations
struct mc13783_adc_privfunction name_showfunction mc13783_adc_readfunction mc13783_adc_bp_showfunction mc13783_adc_gp_showfunction mc13783_adc_uid_showfunction mc13783_adc_temp_showfunction mc13783_adc_use_touchscreenfunction mc13783_adc_probefunction mc13783_adc_remove
Annotated Snippet
struct mc13783_adc_priv {
struct mc13xxx *mc13xxx;
struct device *hwmon_dev;
char name[PLATFORM_NAME_SIZE];
};
static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
char *buf)
{
struct mc13783_adc_priv *priv = dev_get_drvdata(dev);
return sprintf(buf, "%s\n", priv->name);
}
static int mc13783_adc_read(struct device *dev,
struct device_attribute *devattr, unsigned int *val)
{
struct mc13783_adc_priv *priv = dev_get_drvdata(dev);
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
unsigned int channel = attr->index;
unsigned int sample[4];
int ret;
ret = mc13xxx_adc_do_conversion(priv->mc13xxx,
MC13XXX_ADC_MODE_MULT_CHAN,
channel, 0, 0, sample);
if (ret)
return ret;
/* ADIN7 subchannels */
if (channel >= 16)
channel = 7;
channel &= 0x7;
*val = (sample[channel % 4] >> (channel > 3 ? 14 : 2)) & 0x3ff;
return 0;
}
static ssize_t mc13783_adc_bp_show(struct device *dev,
struct device_attribute *devattr,
char *buf)
{
unsigned val;
struct platform_device *pdev = to_platform_device(dev);
kernel_ulong_t driver_data = platform_get_device_id(pdev)->driver_data;
int ret = mc13783_adc_read(dev, devattr, &val);
if (ret)
return ret;
if (driver_data & MC13783_ADC_BPDIV2)
val = DIV_ROUND_CLOSEST(val * 9, 2);
else
/*
* BP (channel 2) reports with offset 2.4V to the actual value
* to fit the input range of the ADC. unit = 2.25mV = 9/4 mV.
*/
val = DIV_ROUND_CLOSEST(val * 9, 4) + 2400;
return sprintf(buf, "%u\n", val);
}
static ssize_t mc13783_adc_gp_show(struct device *dev,
struct device_attribute *devattr,
char *buf)
{
unsigned val;
int ret = mc13783_adc_read(dev, devattr, &val);
if (ret)
return ret;
/*
* input range is [0, 2.3V], val has 10 bits, so each bit
* is worth 9/4 mV.
*/
val = DIV_ROUND_CLOSEST(val * 9, 4);
return sprintf(buf, "%u\n", val);
}
static ssize_t mc13783_adc_uid_show(struct device *dev,
struct device_attribute *devattr,
char *buf)
{
unsigned int val;
struct platform_device *pdev = to_platform_device(dev);
kernel_ulong_t driver_data = platform_get_device_id(pdev)->driver_data;
Annotation
- Immediate include surface: `linux/mfd/mc13xxx.h`, `linux/platform_device.h`, `linux/hwmon-sysfs.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/hwmon.h`, `linux/slab.h`.
- Detected declarations: `struct mc13783_adc_priv`, `function name_show`, `function mc13783_adc_read`, `function mc13783_adc_bp_show`, `function mc13783_adc_gp_show`, `function mc13783_adc_uid_show`, `function mc13783_adc_temp_show`, `function mc13783_adc_use_touchscreen`, `function mc13783_adc_probe`, `function mc13783_adc_remove`.
- 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.