drivers/iio/adc/mcp3564.c
Source file repositories/reference/linux-study-clean/drivers/iio/adc/mcp3564.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/adc/mcp3564.c- Extension
.c- Size
- 42036 bytes
- Lines
- 1484
- 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/bitfield.hlinux/iopoll.hlinux/regulator/consumer.hlinux/spi/spi.hlinux/units.hlinux/util_macros.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct mcp3564_chip_infostruct mcp3564_stateenum mcp3564_idsenum mcp3564_delay_timeenum mcp3564_adc_conversion_modeenum mcp3564_adc_bias_currentenum mcp3564_burnoutenum mcp3564_channel_namesenum mcp3564_oversamplingfunction mcp3564_cmd_writefunction mcp3564_cmd_readfunction mcp3564_read_8bitsfunction mcp3564_read_16bitsfunction mcp3564_read_32bitsfunction mcp3564_write_8bitsfunction mcp3564_write_24bitsfunction mcp3564_fast_cmdfunction mcp3564_update_8bitsfunction mcp3564_set_current_boost_modefunction mcp3564_get_current_boost_modefunction mcp3564_auto_zeroing_mux_showfunction mcp3564_auto_zeroing_mux_storefunction mcp3564_auto_zeroing_ref_showfunction mcp3564_auto_zeroing_ref_storefunction mcp3564_read_single_valuefunction mcp3564_read_availfunction mcp3564_read_rawfunction mcp3564_write_raw_get_fmtfunction mcp3564_write_rawfunction mcp3564_read_labelfunction mcp3564_parse_fw_childrenfunction device_for_each_child_node_scopedfunction mcp3564_fill_scale_tblsfunction mcp3564_configfunction mcp3564_probe
Annotated Snippet
struct mcp3564_chip_info {
const char *name;
unsigned int num_channels;
unsigned int resolution;
bool have_vref;
};
/**
* struct mcp3564_state - working data for a ADC device
* @chip_info: chip specific data
* @spi: SPI device structure
* @vref_mv: voltage reference value in millivolts
* @lock: synchronize access to driver's state members
* @dev_addr: hardware device address
* @oversampling: the index inside oversampling list of the ADC
* @hwgain: the index inside hardware gain list of the ADC
* @scale_tbls: table with precalculated scale
* @calib_bias: calibration bias value
* @calib_scale: calibration scale value
* @current_boost_mode: the index inside current boost list of the ADC
* @burnout_mode: the index inside current bias list of the ADC
* @auto_zeroing_mux: set if ADC auto-zeroing algorithm is enabled
* @auto_zeroing_ref: set if ADC auto-Zeroing Reference Buffer Setting is enabled
* @have_vref: does the ADC have an internal voltage reference?
* @labels: table with channels labels
*/
struct mcp3564_state {
const struct mcp3564_chip_info *chip_info;
struct spi_device *spi;
unsigned short vref_mv;
struct mutex lock; /* Synchronize access to driver's state members */
u8 dev_addr;
enum mcp3564_oversampling oversampling;
unsigned int hwgain;
unsigned int scale_tbls[MCP3564_MAX_PGA][2];
int calib_bias;
int calib_scale;
unsigned int current_boost_mode;
enum mcp3564_burnout burnout_mode;
bool auto_zeroing_mux;
bool auto_zeroing_ref;
bool have_vref;
const char *labels[MCP3564_MAX_CHANNELS];
};
static inline u8 mcp3564_cmd_write(u8 chip_addr, u8 reg)
{
return FIELD_PREP(MCP3564_CMD_HW_ADDR_MASK, chip_addr) |
FIELD_PREP(MCP3564_CMD_ADDR_MASK, reg) |
BIT(1);
}
static inline u8 mcp3564_cmd_read(u8 chip_addr, u8 reg)
{
return FIELD_PREP(MCP3564_CMD_HW_ADDR_MASK, chip_addr) |
FIELD_PREP(MCP3564_CMD_ADDR_MASK, reg) |
BIT(0);
}
static int mcp3564_read_8bits(struct mcp3564_state *adc, u8 reg, u8 *val)
{
int ret;
u8 tx_buf;
u8 rx_buf;
tx_buf = mcp3564_cmd_read(adc->dev_addr, reg);
ret = spi_write_then_read(adc->spi, &tx_buf, sizeof(tx_buf),
&rx_buf, sizeof(rx_buf));
*val = rx_buf;
return ret;
}
static int mcp3564_read_16bits(struct mcp3564_state *adc, u8 reg, u16 *val)
{
int ret;
u8 tx_buf;
__be16 rx_buf;
tx_buf = mcp3564_cmd_read(adc->dev_addr, reg);
ret = spi_write_then_read(adc->spi, &tx_buf, sizeof(tx_buf),
&rx_buf, sizeof(rx_buf));
*val = be16_to_cpu(rx_buf);
return ret;
}
static int mcp3564_read_32bits(struct mcp3564_state *adc, u8 reg, u32 *val)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/iopoll.h`, `linux/regulator/consumer.h`, `linux/spi/spi.h`, `linux/units.h`, `linux/util_macros.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct mcp3564_chip_info`, `struct mcp3564_state`, `enum mcp3564_ids`, `enum mcp3564_delay_time`, `enum mcp3564_adc_conversion_mode`, `enum mcp3564_adc_bias_current`, `enum mcp3564_burnout`, `enum mcp3564_channel_names`, `enum mcp3564_oversampling`, `function mcp3564_cmd_write`.
- 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.