sound/isa/gus/gus_uart.c
Source file repositories/reference/linux-study-clean/sound/isa/gus/gus_uart.c
File Facts
- System
- Linux kernel
- Corpus path
sound/isa/gus/gus_uart.c- Extension
.c- Size
- 8018 bytes
- Lines
- 282
- Domain
- Driver Families
- Bucket
- sound/isa
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/interrupt.hlinux/time.hsound/core.hsound/gus.h
Detected Declarations
function Copyrightfunction snd_gf1_interrupt_midi_outfunction snd_gf1_uart_resetfunction snd_gf1_uart_output_openfunction snd_gf1_uart_input_openfunction snd_gf1_uart_output_closefunction snd_gf1_uart_input_closefunction snd_gf1_uart_input_triggerfunction snd_gf1_uart_output_triggerfunction snd_gf1_rawmidi_newfunction snd_gf1_uart_suspendfunction snd_gf1_uart_resumefunction scoped_guard
Annotated Snippet
if (!(stat & 0x01)) { /* data in Rx FIFO? */
spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
count--;
continue;
}
count = 100; /* arm counter to new value */
data = snd_gf1_uart_get(gus);
if (!(gus->gf1.uart_cmd & 0x80)) {
spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
continue;
}
if (stat & 0x10) { /* framing error */
gus->gf1.uart_framing++;
spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
continue;
}
byte = snd_gf1_uart_get(gus);
spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
snd_rawmidi_receive(gus->midi_substream_input, &byte, 1);
if (stat & 0x20) {
gus->gf1.uart_overrun++;
}
}
}
static void snd_gf1_interrupt_midi_out(struct snd_gus_card * gus)
{
char byte;
/* try unlock output */
if (snd_gf1_uart_stat(gus) & 0x01)
snd_gf1_interrupt_midi_in(gus);
guard(spinlock_irqsave)(&gus->uart_cmd_lock);
if (snd_gf1_uart_stat(gus) & 0x02) { /* Tx FIFO free? */
if (snd_rawmidi_transmit(gus->midi_substream_output, &byte, 1) != 1) { /* no other bytes or error */
snd_gf1_uart_cmd(gus, gus->gf1.uart_cmd & ~0x20); /* disable Tx interrupt */
} else {
snd_gf1_uart_put(gus, byte);
}
}
}
static void snd_gf1_uart_reset(struct snd_gus_card * gus, int close)
{
snd_gf1_uart_cmd(gus, 0x03); /* reset */
if (!close && gus->uart_enable) {
udelay(160);
snd_gf1_uart_cmd(gus, 0x00); /* normal operations */
}
}
static int snd_gf1_uart_output_open(struct snd_rawmidi_substream *substream)
{
struct snd_gus_card *gus;
gus = substream->rmidi->private_data;
guard(spinlock_irqsave)(&gus->uart_cmd_lock);
if (!(gus->gf1.uart_cmd & 0x80)) { /* input active? */
snd_gf1_uart_reset(gus, 0);
}
gus->gf1.interrupt_handler_midi_out = snd_gf1_interrupt_midi_out;
gus->midi_substream_output = substream;
#if 0
dev_dbg(gus->card->dev,
"write init - cmd = 0x%x, stat = 0x%x\n",
gus->gf1.uart_cmd, snd_gf1_uart_stat(gus));
#endif
return 0;
}
static int snd_gf1_uart_input_open(struct snd_rawmidi_substream *substream)
{
struct snd_gus_card *gus;
int i;
gus = substream->rmidi->private_data;
guard(spinlock_irqsave)(&gus->uart_cmd_lock);
if (gus->gf1.interrupt_handler_midi_out != snd_gf1_interrupt_midi_out) {
snd_gf1_uart_reset(gus, 0);
}
gus->gf1.interrupt_handler_midi_in = snd_gf1_interrupt_midi_in;
gus->midi_substream_input = substream;
if (gus->uart_enable) {
for (i = 0; i < 1000 && (snd_gf1_uart_stat(gus) & 0x01); i++)
snd_gf1_uart_get(gus); /* clean Rx */
if (i >= 1000)
dev_err(gus->card->dev, "gus midi uart init read - cleanup error\n");
}
#if 0
Annotation
- Immediate include surface: `linux/delay.h`, `linux/interrupt.h`, `linux/time.h`, `sound/core.h`, `sound/gus.h`.
- Detected declarations: `function Copyright`, `function snd_gf1_interrupt_midi_out`, `function snd_gf1_uart_reset`, `function snd_gf1_uart_output_open`, `function snd_gf1_uart_input_open`, `function snd_gf1_uart_output_close`, `function snd_gf1_uart_input_close`, `function snd_gf1_uart_input_trigger`, `function snd_gf1_uart_output_trigger`, `function snd_gf1_rawmidi_new`.
- Atlas domain: Driver Families / sound/isa.
- Implementation status: source 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.