drivers/iio/adc/mt6577_auxadc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/mt6577_auxadc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/mt6577_auxadc.c- Extension
.c- Size
- 9145 bytes
- Lines
- 337
- 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/clk.hlinux/delay.hlinux/err.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/property.hlinux/iopoll.hlinux/io.hlinux/iio/iio.h
Detected Declarations
struct mtk_auxadc_compatiblestruct mt6577_auxadc_devicefunction mt_auxadc_get_cali_datafunction mt6577_auxadc_mod_regfunction mt6577_auxadc_readfunction mt6577_auxadc_read_rawfunction mt6577_auxadc_resumefunction mt6577_auxadc_suspendfunction mt6577_power_offfunction mt6577_auxadc_probe
Annotated Snippet
struct mtk_auxadc_compatible {
bool sample_data_cali;
bool check_global_idle;
};
struct mt6577_auxadc_device {
void __iomem *reg_base;
struct clk *adc_clk;
struct mutex lock;
const struct mtk_auxadc_compatible *dev_comp;
};
static const struct mtk_auxadc_compatible mt8186_compat = {
.sample_data_cali = false,
.check_global_idle = false,
};
static const struct mtk_auxadc_compatible mt8173_compat = {
.sample_data_cali = false,
.check_global_idle = true,
};
static const struct mtk_auxadc_compatible mt6765_compat = {
.sample_data_cali = true,
.check_global_idle = false,
};
#define MT6577_AUXADC_CHANNEL(idx) { \
.type = IIO_VOLTAGE, \
.indexed = 1, \
.channel = (idx), \
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
}
static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
MT6577_AUXADC_CHANNEL(0),
MT6577_AUXADC_CHANNEL(1),
MT6577_AUXADC_CHANNEL(2),
MT6577_AUXADC_CHANNEL(3),
MT6577_AUXADC_CHANNEL(4),
MT6577_AUXADC_CHANNEL(5),
MT6577_AUXADC_CHANNEL(6),
MT6577_AUXADC_CHANNEL(7),
MT6577_AUXADC_CHANNEL(8),
MT6577_AUXADC_CHANNEL(9),
MT6577_AUXADC_CHANNEL(10),
MT6577_AUXADC_CHANNEL(11),
MT6577_AUXADC_CHANNEL(12),
MT6577_AUXADC_CHANNEL(13),
MT6577_AUXADC_CHANNEL(14),
MT6577_AUXADC_CHANNEL(15),
};
/* For Voltage calculation */
#define VOLTAGE_FULL_RANGE 1500 /* VA voltage */
#define AUXADC_PRECISE 4096 /* 12 bits */
static int mt_auxadc_get_cali_data(int rawdata, bool enable_cali)
{
return rawdata;
}
static inline void mt6577_auxadc_mod_reg(void __iomem *reg,
u32 or_mask, u32 and_mask)
{
u32 val;
val = readl(reg);
val |= or_mask;
val &= ~and_mask;
writel(val, reg);
}
static int mt6577_auxadc_read(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan)
{
u32 val;
void __iomem *reg_channel;
int ret;
struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev);
reg_channel = adc_dev->reg_base + MT6577_AUXADC_DAT0 +
chan->channel * 0x04;
mutex_lock(&adc_dev->lock);
mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_CON1,
0, 1 << chan->channel);
/* read channel and make sure old ready bit == 0 */
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/err.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct mtk_auxadc_compatible`, `struct mt6577_auxadc_device`, `function mt_auxadc_get_cali_data`, `function mt6577_auxadc_mod_reg`, `function mt6577_auxadc_read`, `function mt6577_auxadc_read_raw`, `function mt6577_auxadc_resume`, `function mt6577_auxadc_suspend`, `function mt6577_power_off`, `function mt6577_auxadc_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.