drivers/iio/adc/pac1921.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/pac1921.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/pac1921.c- Extension
.c- Size
- 35610 bytes
- Lines
- 1346
- 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.
- 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/unaligned.hlinux/bitfield.hlinux/cleanup.hlinux/i2c.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/limits.hlinux/regmap.hlinux/units.h
Detected Declarations
struct pac1921_privenum pac1921_mxslenum pac1921_channelsfunction pac1921_data_readyfunction pac1921_calc_scalefunction LSBfunction pac1921_check_push_overflowfunction pac1921_read_resfunction pac1921_read_rawfunction pac1921_read_availfunction pac1921_update_cfg_regfunction scalefunction gainfunction pac1921_update_gain_from_scalefunction indexfunction pac1921_update_int_num_samplesfunction pac1921_write_raw_get_fmtfunction pac1921_write_rawfunction pac1921_read_labelfunction pac1921_read_event_configfunction pac1921_write_event_configfunction pac1921_read_event_valuefunction pac1921_read_shunt_resistorfunction pac1921_write_shunt_resistorfunction runtimefunction pac1921_read_scale_availfunction pac1921_trigger_handlerfunction iio_for_each_active_channelfunction pac1921_initfunction pac1921_suspendfunction pac1921_resumefunction pac1921_regulator_disablefunction pac1921_match_acpi_devicefunction pac1921_parse_of_fwfunction pac1921_probe
Annotated Snippet
struct pac1921_priv {
struct i2c_client *client;
struct regmap *regmap;
struct regulator *vdd;
struct iio_info iio_info;
/*
* Synchronize access to private members, and ensure atomicity of
* consecutive regmap operations.
*/
struct mutex lock;
u32 rshunt_uohm; /* uOhm */
u8 dv_gain;
u8 di_gain;
u8 n_samples;
u8 prev_ovf_flags;
u8 ovf_enabled_events;
bool first_integr_started;
bool first_integr_done;
unsigned long integr_started_time_jiffies;
unsigned int integr_period_usecs;
int current_scales[ARRAY_SIZE(pac1921_vsense_scales)][2];
struct {
u16 chan[PAC1921_NUM_MEAS_CHANS];
aligned_s64 timestamp;
} scan;
};
/*
* Check if first integration after configuration update has completed.
*
* Must be called with lock held.
*/
static bool pac1921_data_ready(struct pac1921_priv *priv)
{
if (!priv->first_integr_started)
return false;
if (!priv->first_integr_done) {
unsigned long t_ready;
/*
* Data valid after the device entered into integration state,
* considering worst case where the device was in sleep state,
* and completed the first integration period.
*/
t_ready = priv->integr_started_time_jiffies +
usecs_to_jiffies(PAC1921_SLEEP_TO_INT_TIME_US) +
usecs_to_jiffies(priv->integr_period_usecs);
if (time_before(jiffies, t_ready))
return false;
priv->first_integr_done = true;
}
return true;
}
static inline void pac1921_calc_scale(int dividend, int divisor, int *val,
int *val2)
{
s64 tmp;
tmp = div_s64(dividend * (s64)NANO, divisor);
*val = div_s64_rem(tmp, NANO, val2);
}
/*
* Fill the table of scale factors for current
* format: IIO_VAL_INT_PLUS_NANO
* unit: mA
*
* Vsense LSB (nV) = max_vsense (nV) * di_gain / resolution
* Current scale (mA) = Vsense LSB (nV) / shunt (uOhm)
*
* Must be called with held lock when updating after first initialization.
*/
static void pac1921_calc_current_scales(struct pac1921_priv *priv)
{
for (unsigned int i = 0; i < ARRAY_SIZE(priv->current_scales); i++) {
int max = (PAC1921_MAX_VSENSE_MV * MICRO) >> i;
int vsense_lsb = DIV_ROUND_CLOSEST(max, PAC1921_RES_RESOLUTION);
pac1921_calc_scale(vsense_lsb, priv->rshunt_uohm,
&priv->current_scales[i][0],
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/bitfield.h`, `linux/cleanup.h`, `linux/i2c.h`, `linux/iio/events.h`, `linux/iio/iio.h`, `linux/iio/trigger_consumer.h`, `linux/iio/triggered_buffer.h`.
- Detected declarations: `struct pac1921_priv`, `enum pac1921_mxsl`, `enum pac1921_channels`, `function pac1921_data_ready`, `function pac1921_calc_scale`, `function LSB`, `function pac1921_check_push_overflow`, `function pac1921_read_res`, `function pac1921_read_raw`, `function pac1921_read_avail`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- 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.