drivers/media/usb/stk1160/stk1160-ac97.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/stk1160/stk1160-ac97.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/stk1160/stk1160-ac97.c- Extension
.c- Size
- 4136 bytes
- Lines
- 156
- Domain
- Driver Families
- Bucket
- drivers/media
- 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/delay.hstk1160.hstk1160-reg.h
Detected Declarations
function Copyrightfunction stk1160_write_ac97function stk1160_read_ac97function stk1160_ac97_dump_regsfunction stk1160_has_audiofunction stk1160_has_ac97function stk1160_ac97_setup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* STK1160 driver
*
* Copyright (C) 2012 Ezequiel Garcia
* <elezegarcia--a.t--gmail.com>
*
* Copyright (C) 2016 Marcel Hasler
* <mahasler--a.t--gmail.com>
*
* Based on Easycap driver by R.M. Thomas
* Copyright (C) 2010 R.M. Thomas
* <rmthomas--a.t--sciolus.org>
*/
#include <linux/delay.h>
#include "stk1160.h"
#include "stk1160-reg.h"
static int stk1160_ac97_wait_transfer_complete(struct stk1160 *dev)
{
unsigned long timeout = jiffies + msecs_to_jiffies(STK1160_AC97_TIMEOUT);
u8 value;
/* Wait for AC97 transfer to complete */
while (time_is_after_jiffies(timeout)) {
stk1160_read_reg(dev, STK1160_AC97CTL_0, &value);
if (!(value & (STK1160_AC97CTL_0_CR | STK1160_AC97CTL_0_CW)))
return 0;
usleep_range(50, 100);
}
stk1160_err("AC97 transfer took too long, this should never happen!");
return -EBUSY;
}
static void stk1160_write_ac97(struct stk1160 *dev, u16 reg, u16 value)
{
/* Set codec register address */
stk1160_write_reg(dev, STK1160_AC97_ADDR, reg);
/* Set codec command */
stk1160_write_reg(dev, STK1160_AC97_CMD, value & 0xff);
stk1160_write_reg(dev, STK1160_AC97_CMD + 1, (value & 0xff00) >> 8);
/* Set command write bit to initiate write operation */
stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x8c);
/* Wait for command write bit to be cleared */
stk1160_ac97_wait_transfer_complete(dev);
}
#ifdef DEBUG
static u16 stk1160_read_ac97(struct stk1160 *dev, u16 reg)
{
u8 vall = 0;
u8 valh = 0;
/* Set codec register address */
stk1160_write_reg(dev, STK1160_AC97_ADDR, reg);
/* Set command read bit to initiate read operation */
stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x8b);
/* Wait for command read bit to be cleared */
if (stk1160_ac97_wait_transfer_complete(dev) < 0)
return 0;
/* Retrieve register value */
stk1160_read_reg(dev, STK1160_AC97_CMD, &vall);
stk1160_read_reg(dev, STK1160_AC97_CMD + 1, &valh);
return (valh << 8) | vall;
}
void stk1160_ac97_dump_regs(struct stk1160 *dev)
{
u16 value;
value = stk1160_read_ac97(dev, 0x12); /* CD volume */
stk1160_dbg("0x12 == 0x%04x", value);
value = stk1160_read_ac97(dev, 0x10); /* Line-in volume */
stk1160_dbg("0x10 == 0x%04x", value);
value = stk1160_read_ac97(dev, 0x0e); /* MIC volume (mono) */
Annotation
- Immediate include surface: `linux/delay.h`, `stk1160.h`, `stk1160-reg.h`.
- Detected declarations: `function Copyright`, `function stk1160_write_ac97`, `function stk1160_read_ac97`, `function stk1160_ac97_dump_regs`, `function stk1160_has_audio`, `function stk1160_has_ac97`, `function stk1160_ac97_setup`.
- Atlas domain: Driver Families / drivers/media.
- 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.