sound/drivers/opl4/opl4_lib.c
Source file repositories/reference/linux-study-clean/sound/drivers/opl4/opl4_lib.c
File Facts
- System
- Linux kernel
- Corpus path
sound/drivers/opl4/opl4_lib.c- Extension
.c- Size
- 6263 bytes
- Lines
- 247
- Domain
- Driver Families
- Bucket
- sound/drivers
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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
opl4_local.hsound/initval.hlinux/ioport.hlinux/slab.hlinux/init.hlinux/module.hlinux/io.h
Detected Declarations
function snd_opl4_waitfunction snd_opl4_writefunction snd_opl4_readfunction snd_opl4_read_memoryfunction snd_opl4_write_memoryfunction snd_opl4_enable_opl4function snd_opl4_detectfunction snd_opl4_seq_dev_freefunction snd_opl4_create_seq_devfunction snd_opl4_freefunction snd_opl4_dev_freefunction snd_opl4_createexport snd_opl4_writeexport snd_opl4_readexport snd_opl4_read_memoryexport snd_opl4_write_memoryexport snd_opl4_create
Annotated Snippet
sizeof(struct snd_opl4 *), &opl4->seq_dev) >= 0) {
strscpy(opl4->seq_dev->name, "OPL4 Wavetable");
*(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(opl4->seq_dev) = opl4;
opl4->seq_dev->private_data = opl4;
opl4->seq_dev->private_free = snd_opl4_seq_dev_free;
}
return 0;
}
#endif
static void snd_opl4_free(struct snd_opl4 *opl4)
{
snd_opl4_free_proc(opl4);
release_and_free_resource(opl4->res_fm_port);
release_and_free_resource(opl4->res_pcm_port);
kfree(opl4);
}
static int snd_opl4_dev_free(struct snd_device *device)
{
struct snd_opl4 *opl4 = device->device_data;
snd_opl4_free(opl4);
return 0;
}
int snd_opl4_create(struct snd_card *card,
unsigned long fm_port, unsigned long pcm_port,
int seq_device,
struct snd_opl3 **ropl3, struct snd_opl4 **ropl4)
{
struct snd_opl4 *opl4;
struct snd_opl3 *opl3;
int err;
static const struct snd_device_ops ops = {
.dev_free = snd_opl4_dev_free
};
if (ropl3)
*ropl3 = NULL;
if (ropl4)
*ropl4 = NULL;
opl4 = kzalloc_obj(*opl4);
if (!opl4)
return -ENOMEM;
opl4->res_fm_port = request_region(fm_port, 8, "OPL4 FM");
opl4->res_pcm_port = request_region(pcm_port, 8, "OPL4 PCM/MIX");
if (!opl4->res_fm_port || !opl4->res_pcm_port) {
dev_err(card->dev, "opl4: can't grab ports 0x%lx, 0x%lx\n", fm_port, pcm_port);
snd_opl4_free(opl4);
return -EBUSY;
}
opl4->card = card;
opl4->fm_port = fm_port;
opl4->pcm_port = pcm_port;
spin_lock_init(&opl4->reg_lock);
mutex_init(&opl4->access_mutex);
err = snd_opl4_detect(opl4);
if (err < 0) {
snd_opl4_free(opl4);
dev_dbg(card->dev, "OPL4 chip not detected at %#lx/%#lx\n", fm_port, pcm_port);
return err;
}
err = snd_device_new(card, SNDRV_DEV_CODEC, opl4, &ops);
if (err < 0) {
snd_opl4_free(opl4);
return err;
}
err = snd_opl3_create(card, fm_port, fm_port + 2, opl4->hardware, 1, &opl3);
if (err < 0) {
snd_device_free(card, opl4);
return err;
}
/* opl3 initialization disabled opl4, so reenable */
snd_opl4_enable_opl4(opl4);
snd_opl4_create_mixer(opl4);
snd_opl4_create_proc(opl4);
#if IS_ENABLED(CONFIG_SND_SEQUENCER)
opl4->seq_client = -1;
if (opl4->hardware < OPL3_HW_OPL4_ML)
snd_opl4_create_seq_dev(opl4, seq_device);
#endif
Annotation
- Immediate include surface: `opl4_local.h`, `sound/initval.h`, `linux/ioport.h`, `linux/slab.h`, `linux/init.h`, `linux/module.h`, `linux/io.h`.
- Detected declarations: `function snd_opl4_wait`, `function snd_opl4_write`, `function snd_opl4_read`, `function snd_opl4_read_memory`, `function snd_opl4_write_memory`, `function snd_opl4_enable_opl4`, `function snd_opl4_detect`, `function snd_opl4_seq_dev_free`, `function snd_opl4_create_seq_dev`, `function snd_opl4_free`.
- Atlas domain: Driver Families / sound/drivers.
- Implementation status: integration 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.