drivers/comedi/drivers/pcmad.c
Source file repositories/reference/linux-study-clean/drivers/comedi/drivers/pcmad.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/comedi/drivers/pcmad.c- Extension
.c- Size
- 3595 bytes
- Lines
- 151
- 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/comedi/comedidev.h
Detected Declarations
struct pcmad_board_structfunction pcmad_ai_eocfunction pcmad_ai_insn_readfunction pcmad_attach
Annotated Snippet
struct pcmad_board_struct {
const char *name;
unsigned int ai_maxdata;
};
static const struct pcmad_board_struct pcmad_boards[] = {
{
.name = "pcmad12",
.ai_maxdata = 0x0fff,
}, {
.name = "pcmad16",
.ai_maxdata = 0xffff,
},
};
static int pcmad_ai_eoc(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned long context)
{
unsigned int status;
status = inb(dev->iobase + PCMAD_STATUS);
if ((status & 0x3) == 0x3)
return 0;
return -EBUSY;
}
static int pcmad_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int range = CR_RANGE(insn->chanspec);
unsigned int val;
int ret;
int i;
for (i = 0; i < insn->n; i++) {
outb(chan, dev->iobase + PCMAD_CONVERT);
ret = comedi_timeout(dev, s, insn, pcmad_ai_eoc, 0);
if (ret)
return ret;
val = inb(dev->iobase + PCMAD_LSB) |
(inb(dev->iobase + PCMAD_MSB) << 8);
/* data is shifted on the pcmad12, fix it */
if (s->maxdata == 0x0fff)
val >>= 4;
if (comedi_range_is_bipolar(s, range)) {
/* munge the two's complement value */
val ^= ((s->maxdata + 1) >> 1);
}
data[i] = val;
}
return insn->n;
}
static int pcmad_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
const struct pcmad_board_struct *board = dev->board_ptr;
struct comedi_subdevice *s;
int ret;
ret = comedi_check_request_region(dev, it->options[0], 0x04,
0, 0x3ff, 4);
if (ret)
return ret;
ret = comedi_alloc_subdevices(dev, 1);
if (ret)
return ret;
s = &dev->subdevices[0];
s->type = COMEDI_SUBD_AI;
if (it->options[1]) {
/* 8 differential channels */
s->subdev_flags = SDF_READABLE | AREF_DIFF;
s->n_chan = 8;
} else {
/* 16 single-ended channels */
s->subdev_flags = SDF_READABLE | AREF_GROUND;
s->n_chan = 16;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/comedi/comedidev.h`.
- Detected declarations: `struct pcmad_board_struct`, `function pcmad_ai_eoc`, `function pcmad_ai_insn_read`, `function pcmad_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.