sound/ppc/beep.c
Source file repositories/reference/linux-study-clean/sound/ppc/beep.c
File Facts
- System
- Linux kernel
- Corpus path
sound/ppc/beep.c- Extension
.c- Size
- 7039 bytes
- Lines
- 271
- Domain
- Driver Families
- Bucket
- sound/ppc
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/io.hasm/irq.hlinux/init.hlinux/slab.hlinux/input.hlinux/pci.hlinux/dma-mapping.hsound/core.hsound/control.hpmac.h
Detected Declarations
struct pmac_beepfunction snd_pmac_beep_stopfunction snd_pmac_beep_eventfunction scoped_guardfunction snd_pmac_info_beepfunction snd_pmac_get_beepfunction snd_pmac_put_beepfunction snd_pmac_attach_beepfunction snd_pmac_detach_beep
Annotated Snippet
struct pmac_beep {
int running; /* boolean */
int volume; /* mixer volume: 0-100 */
int volume_play; /* currently playing volume */
int hz;
int nsamples;
short *buf; /* allocated wave buffer */
dma_addr_t addr; /* physical address of buffer */
struct input_dev *dev;
};
/*
* stop beep if running
*/
void snd_pmac_beep_stop(struct snd_pmac *chip)
{
struct pmac_beep *beep = chip->beep;
if (beep && beep->running) {
beep->running = 0;
snd_pmac_beep_dma_stop(chip);
}
}
/*
* Stuff for outputting a beep. The values range from -327 to +327
* so we can multiply by an amplitude in the range 0..100 to get a
* signed short value to put in the output buffer.
*/
static const short beep_wform[256] = {
0, 40, 79, 117, 153, 187, 218, 245,
269, 288, 304, 316, 323, 327, 327, 324,
318, 310, 299, 288, 275, 262, 249, 236,
224, 213, 204, 196, 190, 186, 183, 182,
182, 183, 186, 189, 192, 196, 200, 203,
206, 208, 209, 209, 209, 207, 204, 201,
197, 193, 188, 183, 179, 174, 170, 166,
163, 161, 160, 159, 159, 160, 161, 162,
164, 166, 168, 169, 171, 171, 171, 170,
169, 167, 163, 159, 155, 150, 144, 139,
133, 128, 122, 117, 113, 110, 107, 105,
103, 103, 103, 103, 104, 104, 105, 105,
105, 103, 101, 97, 92, 86, 78, 68,
58, 45, 32, 18, 3, -11, -26, -41,
-55, -68, -79, -88, -95, -100, -102, -102,
-99, -93, -85, -75, -62, -48, -33, -16,
0, 16, 33, 48, 62, 75, 85, 93,
99, 102, 102, 100, 95, 88, 79, 68,
55, 41, 26, 11, -3, -18, -32, -45,
-58, -68, -78, -86, -92, -97, -101, -103,
-105, -105, -105, -104, -104, -103, -103, -103,
-103, -105, -107, -110, -113, -117, -122, -128,
-133, -139, -144, -150, -155, -159, -163, -167,
-169, -170, -171, -171, -171, -169, -168, -166,
-164, -162, -161, -160, -159, -159, -160, -161,
-163, -166, -170, -174, -179, -183, -188, -193,
-197, -201, -204, -207, -209, -209, -209, -208,
-206, -203, -200, -196, -192, -189, -186, -183,
-182, -182, -183, -186, -190, -196, -204, -213,
-224, -236, -249, -262, -275, -288, -299, -310,
-318, -324, -327, -327, -323, -316, -304, -288,
-269, -245, -218, -187, -153, -117, -79, -40,
};
#define BEEP_SRATE 22050 /* 22050 Hz sample rate */
#define BEEP_BUFLEN 512
#define BEEP_VOLUME 15 /* 0 - 100 */
static int snd_pmac_beep_event(struct input_dev *dev, unsigned int type,
unsigned int code, int hz)
{
struct snd_pmac *chip;
struct pmac_beep *beep;
int beep_speed = 0;
int srate;
int period, ncycles, nsamples;
int i, j, f;
short *p;
if (type != EV_SND)
return -1;
switch (code) {
case SND_BELL: if (hz) hz = 1000; break;
case SND_TONE: break;
default: return -1;
}
chip = input_get_drvdata(dev);
if (!chip)
return -1;
Annotation
- Immediate include surface: `linux/io.h`, `asm/irq.h`, `linux/init.h`, `linux/slab.h`, `linux/input.h`, `linux/pci.h`, `linux/dma-mapping.h`, `sound/core.h`.
- Detected declarations: `struct pmac_beep`, `function snd_pmac_beep_stop`, `function snd_pmac_beep_event`, `function scoped_guard`, `function snd_pmac_info_beep`, `function snd_pmac_get_beep`, `function snd_pmac_put_beep`, `function snd_pmac_attach_beep`, `function snd_pmac_detach_beep`.
- Atlas domain: Driver Families / sound/ppc.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.