drivers/comedi/drivers/adq12b.c
Source file repositories/reference/linux-study-clean/drivers/comedi/drivers/adq12b.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/comedi/drivers/adq12b.c- Extension
.c- Size
- 6262 bytes
- Lines
- 244
- Domain
- Driver Families
- Bucket
- drivers/comedi
- 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/module.hlinux/delay.hlinux/comedi/comedidev.h
Detected Declarations
struct adq12b_privatefunction adq12b_ai_eocfunction adq12b_ai_insn_readfunction adq12b_di_insn_bitsfunction adq12b_do_insn_bitsfunction adq12b_attach
Annotated Snippet
struct adq12b_private {
unsigned int last_ctreg;
};
static int adq12b_ai_eoc(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned long context)
{
unsigned char status;
status = inb(dev->iobase + ADQ12B_STINR);
if (status & ADQ12B_STINR_EOC)
return 0;
return -EBUSY;
}
static int adq12b_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data)
{
struct adq12b_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int range = CR_RANGE(insn->chanspec);
unsigned int val;
int ret;
int i;
/* change channel and range only if it is different from the previous */
val = ADQ12B_CTREG_RANGE(range) | ADQ12B_CTREG_CHAN(chan);
if (val != devpriv->last_ctreg) {
outb(val, dev->iobase + ADQ12B_CTREG);
devpriv->last_ctreg = val;
usleep_range(50, 100); /* wait for the mux to settle */
}
val = inb(dev->iobase + ADQ12B_ADLOW); /* trigger A/D */
for (i = 0; i < insn->n; i++) {
ret = comedi_timeout(dev, s, insn, adq12b_ai_eoc, 0);
if (ret)
return ret;
val = inb(dev->iobase + ADQ12B_ADHIG) << 8;
val |= inb(dev->iobase + ADQ12B_ADLOW); /* retriggers A/D */
data[i] = val;
}
return insn->n;
}
static int adq12b_di_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
/* only bits 0-4 have information about digital inputs */
data[1] = (inb(dev->iobase + ADQ12B_STINR) & ADQ12B_STINR_IN_MASK);
return insn->n;
}
static int adq12b_do_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int mask;
unsigned int chan;
unsigned int val;
mask = comedi_dio_update_state(s, data);
if (mask) {
for (chan = 0; chan < 8; chan++) {
if ((mask >> chan) & 0x01) {
val = (s->state >> chan) & 0x01;
outb((val << 3) | chan,
dev->iobase + ADQ12B_OUTBR);
}
}
}
data[1] = s->state;
return insn->n;
}
static int adq12b_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/delay.h`, `linux/comedi/comedidev.h`.
- Detected declarations: `struct adq12b_private`, `function adq12b_ai_eoc`, `function adq12b_ai_insn_read`, `function adq12b_di_insn_bits`, `function adq12b_do_insn_bits`, `function adq12b_attach`.
- Atlas domain: Driver Families / drivers/comedi.
- 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.