summaryrefslogtreecommitdiff
path: root/kernel/drivers
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-12-08 19:42:28 +0100
committerAnton Kling <anton@kling.gg>2024-12-08 19:42:28 +0100
commit3918a0e92f47f0998fadbc19f0a567e985445407 (patch)
treea25dcf68c3d9659b6d3d86e02d794d6743a6a1f4 /kernel/drivers
parent46f101dcef6c4e4495f8d187e5c31bd10e0eb370 (diff)
audio: Control master volume through /dev/volume
Diffstat (limited to 'kernel/drivers')
-rw-r--r--kernel/drivers/ac97.c34
-rw-r--r--kernel/drivers/ac97.h2
2 files changed, 29 insertions, 7 deletions
diff --git a/kernel/drivers/ac97.c b/kernel/drivers/ac97.c
index acc6dcb..b88a32a 100644
--- a/kernel/drivers/ac97.c
+++ b/kernel/drivers/ac97.c
@@ -136,6 +136,28 @@ int ac97_add_pcm(u8 *buffer, size_t len) {
return wl;
}
+int ac97_current_volume = 100;
+int ac97_get_volume(void) {
+ return ac97_current_volume;
+}
+
+void ac97_set_volume(int volume) {
+ assert(volume <= 100);
+ ac97_current_volume = volume;
+ int s;
+ if (0 == volume) {
+ s = 31;
+ } else {
+ s = (31 * volume) / 100;
+ }
+
+ u8 right_channel = 31 - s;
+ u8 left_channel = 31 - s;
+
+ // Set PCM Output Volume
+ outw(nam.address + 0x18, right_channel | (left_channel << 8));
+}
+
void ac97_init(void) {
if (!pci_populate_device_struct(0x8086, 0x2415, &ac97)) {
assert(0);
@@ -181,19 +203,17 @@ void ac97_init(void) {
card support headhone output.
*/
- outw(nam.address + 0x2C, 32000);
- outw(nam.address + 0x2E, 32000);
- outw(nam.address + 0x30, 32000);
- outw(nam.address + 0x32, 32000);
+ outw(nam.address + 0x2C, 48000);
+ outw(nam.address + 0x2E, 48000);
+ outw(nam.address + 0x30, 48000);
+ outw(nam.address + 0x32, 48000);
/*
As last thing, set maximal volume for
PCM Output by writing value 0 to this register. Now sound card is
ready to use.
*/
-
- // Set PCM Output Volume
- outw(nam.address + 0x18, 0);
+ ac97_set_volume(100);
// Playing sound
/*
diff --git a/kernel/drivers/ac97.h b/kernel/drivers/ac97.h
index d7bacb6..f1089e5 100644
--- a/kernel/drivers/ac97.h
+++ b/kernel/drivers/ac97.h
@@ -4,3 +4,5 @@
void ac97_init(void);
int ac97_add_pcm(u8* buffer, size_t len);
int ac97_can_write(void);
+void ac97_set_volume(int volume);
+int ac97_get_volume(void);