drivers/comedi/drivers/comedi_bond.c
Source file repositories/reference/linux-study-clean/drivers/comedi/drivers/comedi_bond.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/comedi/drivers/comedi_bond.c- Extension
.c- Size
- 9417 bytes
- Lines
- 348
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/string.hlinux/slab.hlinux/comedi.hlinux/comedi/comedilib.hlinux/comedi/comedidev.h
Detected Declarations
struct bonded_devicestruct comedi_bond_privatefunction bonding_dio_insn_bitsfunction bonding_dio_insn_configfunction do_dev_configfunction bonding_attachfunction bonding_detach
Annotated Snippet
struct bonded_device {
struct comedi_device *dev;
unsigned int minor;
unsigned int subdev;
unsigned int nchans;
};
struct comedi_bond_private {
char name[256];
struct bonded_device **devs;
unsigned int ndevs;
unsigned int nchans;
};
static int bonding_dio_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct comedi_bond_private *devpriv = dev->private;
unsigned int n_left, n_done, base_chan;
unsigned int write_mask, data_bits;
struct bonded_device **devs;
write_mask = data[0];
data_bits = data[1];
base_chan = CR_CHAN(insn->chanspec);
/* do a maximum of 32 channels, starting from base_chan. */
n_left = devpriv->nchans - base_chan;
if (n_left > 32)
n_left = 32;
n_done = 0;
devs = devpriv->devs;
do {
struct bonded_device *bdev = *devs++;
if (base_chan < bdev->nchans) {
/* base channel falls within bonded device */
unsigned int b_chans, b_mask, b_write_mask, b_data_bits;
int ret;
/*
* Get num channels to do for bonded device and set
* up mask and data bits for bonded device.
*/
b_chans = bdev->nchans - base_chan;
if (b_chans > n_left)
b_chans = n_left;
b_mask = (b_chans < 32) ? ((1 << b_chans) - 1)
: 0xffffffff;
b_write_mask = (write_mask >> n_done) & b_mask;
b_data_bits = (data_bits >> n_done) & b_mask;
/* Read/Write the new digital lines. */
ret = comedi_dio_bitfield2(bdev->dev, bdev->subdev,
b_write_mask, &b_data_bits,
base_chan);
if (ret < 0)
return ret;
/* Place read bits into data[1]. */
data[1] &= ~(b_mask << n_done);
data[1] |= (b_data_bits & b_mask) << n_done;
/*
* Set up for following bonded device (if still have
* channels to read/write).
*/
base_chan = 0;
n_done += b_chans;
n_left -= b_chans;
} else {
/* Skip bonded devices before base channel. */
base_chan -= bdev->nchans;
}
} while (n_left);
return insn->n;
}
static int bonding_dio_insn_config(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct comedi_bond_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
int ret;
struct bonded_device *bdev;
struct bonded_device **devs;
/*
* Locate bonded subdevice and adjust channel.
*/
Annotation
- Immediate include surface: `linux/module.h`, `linux/string.h`, `linux/slab.h`, `linux/comedi.h`, `linux/comedi/comedilib.h`, `linux/comedi/comedidev.h`.
- Detected declarations: `struct bonded_device`, `struct comedi_bond_private`, `function bonding_dio_insn_bits`, `function bonding_dio_insn_config`, `function do_dev_config`, `function bonding_attach`, `function bonding_detach`.
- 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.