^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Beep using pcm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) by Takashi Iwai <tiwai@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "pmac.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct pmac_beep {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) int running; /* boolean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int volume; /* mixer volume: 0-100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int volume_play; /* currently playing volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int hz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int nsamples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) short *buf; /* allocated wave buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) dma_addr_t addr; /* physical address of buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * stop beep if running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) void snd_pmac_beep_stop(struct snd_pmac *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct pmac_beep *beep = chip->beep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (beep && beep->running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) beep->running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) snd_pmac_beep_dma_stop(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Stuff for outputting a beep. The values range from -327 to +327
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * so we can multiply by an amplitude in the range 0..100 to get a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * signed short value to put in the output buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static const short beep_wform[256] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 0, 40, 79, 117, 153, 187, 218, 245,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 269, 288, 304, 316, 323, 327, 327, 324,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 318, 310, 299, 288, 275, 262, 249, 236,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 224, 213, 204, 196, 190, 186, 183, 182,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 182, 183, 186, 189, 192, 196, 200, 203,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 206, 208, 209, 209, 209, 207, 204, 201,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 197, 193, 188, 183, 179, 174, 170, 166,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 163, 161, 160, 159, 159, 160, 161, 162,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 164, 166, 168, 169, 171, 171, 171, 170,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 169, 167, 163, 159, 155, 150, 144, 139,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 133, 128, 122, 117, 113, 110, 107, 105,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 103, 103, 103, 103, 104, 104, 105, 105,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 105, 103, 101, 97, 92, 86, 78, 68,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 58, 45, 32, 18, 3, -11, -26, -41,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) -55, -68, -79, -88, -95, -100, -102, -102,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) -99, -93, -85, -75, -62, -48, -33, -16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 0, 16, 33, 48, 62, 75, 85, 93,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 99, 102, 102, 100, 95, 88, 79, 68,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 55, 41, 26, 11, -3, -18, -32, -45,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) -58, -68, -78, -86, -92, -97, -101, -103,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) -105, -105, -105, -104, -104, -103, -103, -103,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) -103, -105, -107, -110, -113, -117, -122, -128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) -133, -139, -144, -150, -155, -159, -163, -167,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) -169, -170, -171, -171, -171, -169, -168, -166,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) -164, -162, -161, -160, -159, -159, -160, -161,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) -163, -166, -170, -174, -179, -183, -188, -193,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) -197, -201, -204, -207, -209, -209, -209, -208,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) -206, -203, -200, -196, -192, -189, -186, -183,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) -182, -182, -183, -186, -190, -196, -204, -213,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) -224, -236, -249, -262, -275, -288, -299, -310,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) -318, -324, -327, -327, -323, -316, -304, -288,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) -269, -245, -218, -187, -153, -117, -79, -40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define BEEP_SRATE 22050 /* 22050 Hz sample rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define BEEP_BUFLEN 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define BEEP_VOLUME 15 /* 0 - 100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static int snd_pmac_beep_event(struct input_dev *dev, unsigned int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) unsigned int code, int hz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct snd_pmac *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct pmac_beep *beep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int beep_speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int srate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int period, ncycles, nsamples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int i, j, f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) short *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (type != EV_SND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) switch (code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) case SND_BELL: if (hz) hz = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) case SND_TONE: break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) default: return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) chip = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (! chip || (beep = chip->beep) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (! hz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) spin_lock_irqsave(&chip->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (beep->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) snd_pmac_beep_stop(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) spin_unlock_irqrestore(&chip->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) beep_speed = snd_pmac_rate_index(chip, &chip->playback, BEEP_SRATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) srate = chip->freq_table[beep_speed];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (hz <= srate / BEEP_BUFLEN || hz > srate / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) hz = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) spin_lock_irqsave(&chip->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (chip->playback.running || chip->capture.running || beep->running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) spin_unlock_irqrestore(&chip->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) beep->running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) spin_unlock_irqrestore(&chip->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (hz == beep->hz && beep->volume == beep->volume_play) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) nsamples = beep->nsamples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) period = srate * 256 / hz; /* fixed point */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ncycles = BEEP_BUFLEN * 256 / period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) nsamples = (period * ncycles) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) f = ncycles * 65536 / nsamples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) p = beep->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) for (i = 0; i < nsamples; ++i, p += 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) p[0] = p[1] = beep_wform[j >> 8] * beep->volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) j = (j + f) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) beep->hz = hz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) beep->volume_play = beep->volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) beep->nsamples = nsamples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) spin_lock_irqsave(&chip->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) snd_pmac_beep_dma_start(chip, beep->nsamples * 4, beep->addr, beep_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) spin_unlock_irqrestore(&chip->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * beep volume mixer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int snd_pmac_info_beep(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) uinfo->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) uinfo->value.integer.max = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int snd_pmac_get_beep(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (snd_BUG_ON(!chip->beep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ucontrol->value.integer.value[0] = chip->beep->volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int snd_pmac_put_beep(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned int oval, nval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (snd_BUG_ON(!chip->beep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) oval = chip->beep->volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) nval = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (nval > 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) chip->beep->volume = nval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return oval != chip->beep->volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static const struct snd_kcontrol_new snd_pmac_beep_mixer = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .name = "Beep Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .info = snd_pmac_info_beep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .get = snd_pmac_get_beep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .put = snd_pmac_put_beep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* Initialize beep stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int snd_pmac_attach_beep(struct snd_pmac *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct pmac_beep *beep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct snd_kcontrol *beep_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) void *dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) beep = kzalloc(sizeof(*beep), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (! beep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) dmabuf = dma_alloc_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) &beep->addr, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (! dmabuf || ! input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* FIXME: set more better values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) input_dev->name = "PowerMac Beep";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) input_dev->phys = "powermac/beep";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) input_dev->id.bustype = BUS_ADB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) input_dev->id.vendor = 0x001f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) input_dev->id.product = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) input_dev->evbit[0] = BIT_MASK(EV_SND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) input_dev->event = snd_pmac_beep_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) input_dev->dev.parent = &chip->pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) input_set_drvdata(input_dev, chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) beep->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) beep->buf = dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) beep->volume = BEEP_VOLUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) beep->running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) beep_ctl = snd_ctl_new1(&snd_pmac_beep_mixer, chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) err = snd_ctl_add(chip->card, beep_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) chip->beep = beep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) err = input_register_device(beep->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) fail2: snd_ctl_remove(chip->card, beep_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) fail1: input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (dmabuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) dma_free_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) dmabuf, beep->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) kfree(beep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) void snd_pmac_detach_beep(struct snd_pmac *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (chip->beep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) input_unregister_device(chip->beep->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) dma_free_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) chip->beep->buf, chip->beep->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) kfree(chip->beep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) chip->beep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }