drivers/iio/adc/twl4030-madc.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/twl4030-madc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/twl4030-madc.c- Extension
.c- Size
- 25591 bytes
- Lines
- 928
- 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/device.hlinux/interrupt.hlinux/kernel.hlinux/delay.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/slab.hlinux/mfd/twl.hlinux/stddef.hlinux/mutex.hlinux/bitops.hlinux/jiffies.hlinux/types.hlinux/gfp.hlinux/err.hlinux/regulator/consumer.hlinux/iio/iio.h
Detected Declarations
struct twl4030_madc_conversion_methodstruct twl4030_madc_requeststruct twl4030_madc_dataenum conversion_methodsenum sample_typefunction twl4030_madc_readfunction twl4030_madc_channel_raw_readfunction twl4030battery_temperaturefunction twl4030battery_currentfunction twl4030_madc_read_channelsfunction for_each_set_bitfunction twl4030_madc_disable_irqfunction twl4030_madc_threaded_irq_handlerfunction twl4030_madc_start_conversionfunction twl4030_madc_wait_conversion_readyfunction twl4030_madc_conversionfunction twl4030_madc_set_current_generatorfunction twl4030_madc_set_powerfunction twl4030_madc_probefunction twl4030_madc_remove
Annotated Snippet
struct twl4030_madc_conversion_method {
u8 sel;
u8 avg;
u8 rbase;
u8 ctrl;
};
/**
* struct twl4030_madc_request - madc request packet for channel conversion
* @channels: 16 bit bitmap for individual channels
* @do_avg: sample the input channel for 4 consecutive cycles
* @method: RT, SW1, SW2
* @type: Polling or interrupt based method
* @active: Flag if request is active
* @result_pending: Flag from irq handler, that result is ready
* @raw: Return raw value, do not convert it
* @rbuf: Result buffer
*/
struct twl4030_madc_request {
unsigned long channels;
bool do_avg;
u16 method;
u16 type;
bool active;
bool result_pending;
bool raw;
int rbuf[TWL4030_MADC_MAX_CHANNELS];
};
enum conversion_methods {
TWL4030_MADC_RT,
TWL4030_MADC_SW1,
TWL4030_MADC_SW2,
TWL4030_MADC_NUM_METHODS
};
enum sample_type {
TWL4030_MADC_WAIT,
TWL4030_MADC_IRQ_ONESHOT,
TWL4030_MADC_IRQ_REARM
};
/**
* struct twl4030_madc_data - a container for madc info
* @dev: Pointer to device structure for madc
* @lock: Mutex protecting this data structure
* @usb3v1: Pointer to bias regulator for madc
* @requests: Array of request struct corresponding to SW1, SW2 and RT
* @use_second_irq: IRQ selection (main or co-processor)
* @imr: Interrupt mask register of MADC
* @isr: Interrupt status register of MADC
*/
struct twl4030_madc_data {
struct device *dev;
struct mutex lock;
struct regulator *usb3v1;
struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS];
bool use_second_irq;
u8 imr;
u8 isr;
};
static int twl4030_madc_conversion(struct twl4030_madc_request *req);
static int twl4030_madc_read(struct iio_dev *iio_dev,
const struct iio_chan_spec *chan,
int *val, int *val2, long mask)
{
struct twl4030_madc_data *madc = iio_priv(iio_dev);
struct twl4030_madc_request req;
int ret;
req.method = madc->use_second_irq ? TWL4030_MADC_SW2 : TWL4030_MADC_SW1;
req.channels = BIT(chan->channel);
req.active = false;
req.type = TWL4030_MADC_WAIT;
req.raw = !(mask == IIO_CHAN_INFO_PROCESSED);
req.do_avg = (mask == IIO_CHAN_INFO_AVERAGE_RAW);
ret = twl4030_madc_conversion(&req);
if (ret < 0)
return ret;
*val = req.rbuf[chan->channel];
return IIO_VAL_INT;
}
static const struct iio_info twl4030_madc_iio_info = {
Annotation
- Immediate include surface: `linux/device.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/delay.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct twl4030_madc_conversion_method`, `struct twl4030_madc_request`, `struct twl4030_madc_data`, `enum conversion_methods`, `enum sample_type`, `function twl4030_madc_read`, `function twl4030_madc_channel_raw_read`, `function twl4030battery_temperature`, `function twl4030battery_current`, `function twl4030_madc_read_channels`.
- 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.