drivers/iio/adc/meson_saradc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/meson_saradc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/meson_saradc.c- Extension
.c- Size
- 47303 bytes
- Lines
- 1531
- 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/clk.hlinux/clk-provider.hlinux/delay.hlinux/io.hlinux/iio/iio.hlinux/module.hlinux/mutex.hlinux/nvmem-consumer.hlinux/interrupt.hlinux/of.hlinux/of_irq.hlinux/platform_device.hlinux/regmap.hlinux/regulator/consumer.hlinux/mfd/syscon.h
Detected Declarations
struct meson_sar_adc_paramstruct meson_sar_adc_datastruct meson_sar_adc_privenum meson_sar_adc_vref_selenum meson_sar_adc_avg_modeenum meson_sar_adc_num_samplesenum meson_sar_adc_chan7_mux_selenum meson_sar_adc_channel_indexfunction Registerfunction find_channel_by_numfunction meson_sar_adc_get_fifo_countfunction meson_sar_adc_calib_valfunction meson_sar_adc_wait_busy_clearfunction meson_sar_adc_set_chan7_muxfunction meson_sar_adc_read_raw_samplefunction meson_sar_adc_set_averagingfunction meson_sar_adc_enable_channelfunction meson_sar_adc_start_sample_enginefunction meson_sar_adc_stop_sample_enginefunction meson_sar_adc_lockfunction meson_sar_adc_unlockfunction meson_sar_adc_clear_fifofunction meson_sar_adc_get_samplefunction meson_sar_adc_iio_info_read_rawfunction meson_sar_adc_clk_initfunction meson_sar_adc_temp_sensor_initfunction meson_sar_adc_initfunction meson_sar_adc_set_bandgapfunction meson_sar_adc_hw_enablefunction meson_sar_adc_hw_disablefunction meson_sar_adc_irqfunction meson_sar_adc_calibfunction read_labelfunction meson_sar_adc_probefunction meson_sar_adc_removefunction meson_sar_adc_suspendfunction meson_sar_adc_resume
Annotated Snippet
struct meson_sar_adc_param {
bool has_bl30_integration;
unsigned long clock_rate;
unsigned int resolution;
const struct regmap_config *regmap_config;
u8 temperature_trimming_bits;
unsigned int temperature_multiplier;
unsigned int temperature_divider;
u8 disable_ring_counter;
bool has_vref_select;
u8 vref_select;
u8 cmv_select;
u8 adc_eoc;
enum meson_sar_adc_vref_sel vref_voltage;
bool enable_mpll_clock_workaround;
};
struct meson_sar_adc_data {
const struct meson_sar_adc_param *param;
const char *name;
};
struct meson_sar_adc_priv {
struct regmap *regmap;
struct regulator *vref;
const struct meson_sar_adc_param *param;
struct clk *clkin;
struct clk *core_clk;
struct clk *adc_sel_clk;
struct clk *adc_clk;
struct clk_gate clk_gate;
struct clk *adc_div_clk;
struct clk_divider clk_div;
struct completion done;
/* lock to protect against multiple access to the device */
struct mutex lock;
int calibbias;
int calibscale;
struct regmap *tsc_regmap;
bool temperature_sensor_calibrated;
u8 temperature_sensor_coefficient;
u16 temperature_sensor_adc_val;
enum meson_sar_adc_chan7_mux_sel chan7_mux_sel;
};
static const struct regmap_config meson_sar_adc_regmap_config_gxbb = {
.reg_bits = 8,
.val_bits = 32,
.reg_stride = 4,
.max_register = MESON_SAR_ADC_REG13,
};
static const struct regmap_config meson_sar_adc_regmap_config_meson8 = {
.reg_bits = 8,
.val_bits = 32,
.reg_stride = 4,
.max_register = MESON_SAR_ADC_DELTA_10,
};
static const struct iio_chan_spec *
find_channel_by_num(struct iio_dev *indio_dev, int num)
{
int i;
for (i = 0; i < indio_dev->num_channels; i++)
if (indio_dev->channels[i].channel == num)
return &indio_dev->channels[i];
return NULL;
}
static unsigned int meson_sar_adc_get_fifo_count(struct iio_dev *indio_dev)
{
struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
u32 regval;
regmap_read(priv->regmap, MESON_SAR_ADC_REG0, ®val);
return FIELD_GET(MESON_SAR_ADC_REG0_FIFO_COUNT_MASK, regval);
}
static int meson_sar_adc_calib_val(struct iio_dev *indio_dev, int val)
{
struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
int tmp;
/* use val_calib = scale * val_raw + offset calibration function */
tmp = div_s64((s64)val * priv->calibscale, MILLION) + priv->calibbias;
return clamp(tmp, 0, (1 << priv->param->resolution) - 1);
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/clk-provider.h`, `linux/delay.h`, `linux/io.h`, `linux/iio/iio.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct meson_sar_adc_param`, `struct meson_sar_adc_data`, `struct meson_sar_adc_priv`, `enum meson_sar_adc_vref_sel`, `enum meson_sar_adc_avg_mode`, `enum meson_sar_adc_num_samples`, `enum meson_sar_adc_chan7_mux_sel`, `enum meson_sar_adc_channel_index`, `function Register`, `function find_channel_by_num`.
- 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.