drivers/iio/adc/rockchip_saradc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/rockchip_saradc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/rockchip_saradc.c- Extension
.c- Size
- 16764 bytes
- Lines
- 627
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/interrupt.hlinux/io.hlinux/of.hlinux/clk.hlinux/completion.hlinux/delay.hlinux/reset.hlinux/regulator/consumer.hlinux/iio/buffer.hlinux/iio/iio.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct rockchip_saradcstruct rockchip_saradc_datastruct rockchip_saradcfunction rockchip_saradc_start_v1function rockchip_saradc_start_v2function rockchip_saradc_startfunction rockchip_saradc_read_v1function rockchip_saradc_read_v2function rockchip_saradc_readfunction rockchip_saradc_power_down_v1function rockchip_saradc_power_downfunction rockchip_saradc_conversionfunction rockchip_saradc_read_rawfunction rockchip_saradc_isrfunction rockchip_saradc_reset_controllerfunction rockchip_saradc_regulator_disablefunction rockchip_saradc_trigger_handlerfunction iio_for_each_active_channelfunction rockchip_saradc_volt_notifyfunction rockchip_saradc_regulator_unreg_notifierfunction rockchip_saradc_probefunction rockchip_saradc_suspendfunction rockchip_saradc_resume
Annotated Snippet
struct rockchip_saradc_data {
const struct iio_chan_spec *channels;
int num_channels;
unsigned long clk_rate;
void (*start)(struct rockchip_saradc *info, int chn);
int (*read)(struct rockchip_saradc *info);
void (*power_down)(struct rockchip_saradc *info);
};
struct rockchip_saradc {
void __iomem *regs;
struct clk *pclk;
struct clk *clk;
struct completion completion;
struct regulator *vref;
/* lock to protect against multiple access to the device */
struct mutex lock;
int uv_vref;
struct reset_control *reset;
const struct rockchip_saradc_data *data;
u16 last_val;
const struct iio_chan_spec *last_chan;
struct notifier_block nb;
};
static void rockchip_saradc_reset_controller(struct reset_control *reset);
static void rockchip_saradc_start_v1(struct rockchip_saradc *info, int chn)
{
/* 8 clock periods as delay between power up and start cmd */
writel_relaxed(8, info->regs + SARADC_DLY_PU_SOC);
/* Select the channel to be used and trigger conversion */
writel(SARADC_CTRL_POWER_CTRL | (chn & SARADC_CTRL_CHN_MASK) |
SARADC_CTRL_IRQ_ENABLE, info->regs + SARADC_CTRL);
}
static void rockchip_saradc_start_v2(struct rockchip_saradc *info, int chn)
{
int val;
if (info->reset)
rockchip_saradc_reset_controller(info->reset);
writel_relaxed(0xc, info->regs + SARADC_T_DAS_SOC);
writel_relaxed(0x20, info->regs + SARADC_T_PD_SOC);
val = FIELD_PREP(SARADC2_EN_END_INT, 1);
val |= SARADC2_EN_END_INT << 16;
writel_relaxed(val, info->regs + SARADC2_END_INT_EN);
val = FIELD_PREP(SARADC2_START, 1) |
FIELD_PREP(SARADC2_SINGLE_MODE, 1) |
FIELD_PREP(SARADC2_CONV_CHANNELS, chn);
val |= (SARADC2_START | SARADC2_SINGLE_MODE | SARADC2_CONV_CHANNELS) << 16;
writel(val, info->regs + SARADC2_CONV_CON);
}
static void rockchip_saradc_start(struct rockchip_saradc *info, int chn)
{
info->data->start(info, chn);
}
static int rockchip_saradc_read_v1(struct rockchip_saradc *info)
{
return readl_relaxed(info->regs + SARADC_DATA);
}
static int rockchip_saradc_read_v2(struct rockchip_saradc *info)
{
int offset;
/* Clear irq */
writel_relaxed(0x1, info->regs + SARADC2_END_INT_ST);
offset = SARADC2_DATA_BASE + info->last_chan->channel * 0x4;
return readl_relaxed(info->regs + offset);
}
static int rockchip_saradc_read(struct rockchip_saradc *info)
{
return info->data->read(info);
}
static void rockchip_saradc_power_down_v1(struct rockchip_saradc *info)
{
writel_relaxed(0, info->regs + SARADC_CTRL);
}
static void rockchip_saradc_power_down(struct rockchip_saradc *info)
{
if (info->data->power_down)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/module.h`, `linux/mutex.h`, `linux/platform_device.h`, `linux/interrupt.h`, `linux/io.h`, `linux/of.h`, `linux/clk.h`.
- Detected declarations: `struct rockchip_saradc`, `struct rockchip_saradc_data`, `struct rockchip_saradc`, `function rockchip_saradc_start_v1`, `function rockchip_saradc_start_v2`, `function rockchip_saradc_start`, `function rockchip_saradc_read_v1`, `function rockchip_saradc_read_v2`, `function rockchip_saradc_read`, `function rockchip_saradc_power_down_v1`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.