drivers/iio/adc/mt6370-adc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/mt6370-adc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/mt6370-adc.c- Extension
.c- Size
- 8647 bytes
- Lines
- 355
- Domain
- Driver Families
- Bucket
- drivers/iio
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/bitfield.hlinux/iio/iio.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/regmap.hlinux/sysfs.hlinux/units.hdt-bindings/iio/adc/mediatek,mt6370_adc.h
Detected Declarations
struct mt6370_adc_datafunction mt6370_adc_read_channelfunction mt6370_adc_get_ibus_scalefunction mt6370_adc_get_ibat_scalefunction mt6370_adc_read_scalefunction mt6370_adc_read_offsetfunction mt6370_adc_read_rawfunction mt6370_adc_read_labelfunction mt6370_get_vendor_infofunction mt6370_adc_probe
Annotated Snippet
struct mt6370_adc_data {
struct device *dev;
struct regmap *regmap;
/*
* This mutex lock is for preventing the different ADC channels
* from being read at the same time.
*/
struct mutex adc_lock;
unsigned int vid;
};
static int mt6370_adc_read_channel(struct mt6370_adc_data *priv, int chan,
unsigned long addr, int *val)
{
unsigned int reg_val;
__be16 be_val;
int ret;
mutex_lock(&priv->adc_lock);
reg_val = MT6370_ADC_START_MASK |
FIELD_PREP(MT6370_ADC_IN_SEL_MASK, addr);
ret = regmap_write(priv->regmap, MT6370_REG_CHG_ADC, reg_val);
if (ret)
goto adc_unlock;
msleep(ADC_CONV_TIME_MS);
ret = regmap_read_poll_timeout(priv->regmap,
MT6370_REG_CHG_ADC, reg_val,
!(reg_val & MT6370_ADC_START_MASK),
ADC_CONV_POLLING_TIME_US,
ADC_CONV_TIME_MS * MILLI * 3);
if (ret) {
dev_err(priv->dev, "Failed to read ADC register (%d)\n", ret);
goto adc_unlock;
}
ret = regmap_raw_read(priv->regmap, MT6370_REG_ADC_DATA_H,
&be_val, sizeof(be_val));
if (ret)
goto adc_unlock;
*val = be16_to_cpu(be_val);
ret = IIO_VAL_INT;
adc_unlock:
mutex_unlock(&priv->adc_lock);
return ret;
}
static int mt6370_adc_get_ibus_scale(struct mt6370_adc_data *priv)
{
switch (priv->vid) {
case MT6370_VID_RT5081:
case MT6370_VID_RT5081A:
case MT6370_VID_MT6370:
return 3350;
default:
return 3875;
}
}
static int mt6370_adc_get_ibat_scale(struct mt6370_adc_data *priv)
{
switch (priv->vid) {
case MT6370_VID_RT5081:
case MT6370_VID_RT5081A:
case MT6370_VID_MT6370:
return 2680;
default:
return 3870;
}
}
static int mt6370_adc_read_scale(struct mt6370_adc_data *priv,
int chan, int *val1, int *val2)
{
unsigned int reg_val;
int ret;
switch (chan) {
case MT6370_CHAN_VBAT:
case MT6370_CHAN_VSYS:
case MT6370_CHAN_CHG_VDDP:
*val1 = 5;
return IIO_VAL_INT;
case MT6370_CHAN_IBUS:
ret = regmap_read(priv->regmap, MT6370_REG_CHG_CTRL3, ®_val);
Annotation
- Immediate include surface: `linux/bits.h`, `linux/bitfield.h`, `linux/iio/iio.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`, `linux/platform_device.h`.
- Detected declarations: `struct mt6370_adc_data`, `function mt6370_adc_read_channel`, `function mt6370_adc_get_ibus_scale`, `function mt6370_adc_get_ibat_scale`, `function mt6370_adc_read_scale`, `function mt6370_adc_read_offset`, `function mt6370_adc_read_raw`, `function mt6370_adc_read_label`, `function mt6370_get_vendor_info`, `function mt6370_adc_probe`.
- Atlas domain: Driver Families / drivers/iio.
- 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.