drivers/iio/dac/ad5624r_spi.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/ad5624r_spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/ad5624r_spi.c- Extension
.c- Size
- 7091 bytes
- Lines
- 285
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/interrupt.hlinux/fs.hlinux/device.hlinux/kernel.hlinux/spi/spi.hlinux/slab.hlinux/sysfs.hlinux/regulator/consumer.hlinux/module.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/unaligned.had5624r.h
Detected Declarations
function ad5624r_spi_writefunction ad5624r_read_rawfunction ad5624r_write_rawfunction ad5624r_get_powerdown_modefunction ad5624r_set_powerdown_modefunction ad5624r_read_dac_powerdownfunction ad5624r_write_dac_powerdownfunction ad5624r_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* AD5624R, AD5644R, AD5664R Digital to analog convertors spi driver
*
* Copyright 2010-2011 Analog Devices Inc.
*/
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/spi/spi.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/regulator/consumer.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/unaligned.h>
#include "ad5624r.h"
static int ad5624r_spi_write(struct spi_device *spi,
u8 cmd, u8 addr, u16 val, u8 shift)
{
u32 data;
u8 msg[3];
/*
* The input shift register is 24 bits wide. The first two bits are
* don't care bits. The next three are the command bits, C2 to C0,
* followed by the 3-bit DAC address, A2 to A0, and then the
* 16-, 14-, 12-bit data-word. The data-word comprises the 16-,
* 14-, 12-bit input code followed by 0, 2, or 4 don't care bits,
* for the AD5664R, AD5644R, and AD5624R, respectively.
*/
data = (0 << 22) | (cmd << 19) | (addr << 16) | (val << shift);
put_unaligned_be24(data, &msg[0]);
return spi_write(spi, msg, sizeof(msg));
}
static int ad5624r_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long m)
{
struct ad5624r_state *st = iio_priv(indio_dev);
switch (m) {
case IIO_CHAN_INFO_SCALE:
*val = st->vref_mv;
*val2 = chan->scan_type.realbits;
return IIO_VAL_FRACTIONAL_LOG2;
}
return -EINVAL;
}
static int ad5624r_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
int val2,
long mask)
{
struct ad5624r_state *st = iio_priv(indio_dev);
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (val >= (1 << chan->scan_type.realbits) || val < 0)
return -EINVAL;
return ad5624r_spi_write(st->us,
AD5624R_CMD_WRITE_INPUT_N_UPDATE_N,
chan->address, val,
chan->scan_type.shift);
default:
return -EINVAL;
}
}
static const char * const ad5624r_powerdown_modes[] = {
"1kohm_to_gnd",
"100kohm_to_gnd",
"three_state"
};
static int ad5624r_get_powerdown_mode(struct iio_dev *indio_dev,
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/fs.h`, `linux/device.h`, `linux/kernel.h`, `linux/spi/spi.h`, `linux/slab.h`, `linux/sysfs.h`, `linux/regulator/consumer.h`.
- Detected declarations: `function ad5624r_spi_write`, `function ad5624r_read_raw`, `function ad5624r_write_raw`, `function ad5624r_get_powerdown_mode`, `function ad5624r_set_powerdown_mode`, `function ad5624r_read_dac_powerdown`, `function ad5624r_write_dac_powerdown`, `function ad5624r_probe`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
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.