24 #include <linux/slab.h>
25 #include <linux/input.h>
26 #include <linux/pci.h>
40 struct input_dev *
dev;
60 static short beep_wform[256] = {
61 0, 40, 79, 117, 153, 187, 218, 245,
62 269, 288, 304, 316, 323, 327, 327, 324,
63 318, 310, 299, 288, 275, 262, 249, 236,
64 224, 213, 204, 196, 190, 186, 183, 182,
65 182, 183, 186, 189, 192, 196, 200, 203,
66 206, 208, 209, 209, 209, 207, 204, 201,
67 197, 193, 188, 183, 179, 174, 170, 166,
68 163, 161, 160, 159, 159, 160, 161, 162,
69 164, 166, 168, 169, 171, 171, 171, 170,
70 169, 167, 163, 159, 155, 150, 144, 139,
71 133, 128, 122, 117, 113, 110, 107, 105,
72 103, 103, 103, 103, 104, 104, 105, 105,
73 105, 103, 101, 97, 92, 86, 78, 68,
74 58, 45, 32, 18, 3, -11, -26, -41,
75 -55, -68, -79, -88, -95, -100, -102, -102,
76 -99, -93, -85, -75, -62, -48, -33, -16,
77 0, 16, 33, 48, 62, 75, 85, 93,
78 99, 102, 102, 100, 95, 88, 79, 68,
79 55, 41, 26, 11, -3, -18, -32, -45,
80 -58, -68, -78, -86, -92, -97, -101, -103,
81 -105, -105, -105, -104, -104, -103, -103, -103,
82 -103, -105, -107, -110, -113, -117, -122, -128,
83 -133, -139, -144, -150, -155, -159, -163, -167,
84 -169, -170, -171, -171, -171, -169, -168, -166,
85 -164, -162, -161, -160, -159, -159, -160, -161,
86 -163, -166, -170, -174, -179, -183, -188, -193,
87 -197, -201, -204, -207, -209, -209, -209, -208,
88 -206, -203, -200, -196, -192, -189, -186, -183,
89 -182, -182, -183, -186, -190, -196, -204, -213,
90 -224, -236, -249, -262, -275, -288, -299, -310,
91 -318, -324, -327, -327, -323, -316, -304, -288,
92 -269, -245, -218, -187, -153, -117, -79, -40,
95 #define BEEP_SRATE 22050
96 #define BEEP_BUFLEN 512
97 #define BEEP_VOLUME 15
99 static int snd_pmac_beep_event(
struct input_dev *
dev,
unsigned int type,
100 unsigned int code,
int hz)
120 chip = input_get_drvdata(dev);
121 if (! chip || (beep = chip->
beep) ==
NULL)
128 spin_unlock_irqrestore(&chip->
reg_lock, flags);
135 if (hz <= srate / BEEP_BUFLEN || hz > srate / 2)
140 spin_unlock_irqrestore(&chip->
reg_lock, flags);
144 spin_unlock_irqrestore(&chip->
reg_lock, flags);
149 period = srate * 256 /
hz;
151 nsamples = (period * ncycles) >> 8;
156 p[0] = p[1] = beep_wform[j >> 8] * beep->
volume;
157 j = (j +
f) & 0xffff;
166 spin_unlock_irqrestore(&chip->
reg_lock, flags);
174 static int snd_pmac_info_beep(
struct snd_kcontrol *kcontrol,
184 static int snd_pmac_get_beep(
struct snd_kcontrol *kcontrol,
190 ucontrol->
value.integer.value[0] = chip->
beep->volume;
194 static int snd_pmac_put_beep(
struct snd_kcontrol *kcontrol,
198 unsigned int oval, nval;
201 oval = chip->
beep->volume;
202 nval = ucontrol->
value.integer.value[0];
205 chip->
beep->volume = nval;
206 return oval != chip->
beep->volume;
211 .name =
"Beep Playback Volume",
212 .info = snd_pmac_info_beep,
213 .get = snd_pmac_get_beep,
214 .put = snd_pmac_put_beep,
221 struct input_dev *input_dev;
231 input_dev = input_allocate_device();
232 if (! dmabuf || ! input_dev)
236 input_dev->name =
"PowerMac Beep";
237 input_dev->phys =
"powermac/beep";
238 input_dev->id.bustype =
BUS_ADB;
239 input_dev->id.vendor = 0x001f;
240 input_dev->id.product = 0x0001;
241 input_dev->id.version = 0x0100;
245 input_dev->event = snd_pmac_beep_event;
246 input_dev->dev.parent = &chip->
pdev->dev;
247 input_set_drvdata(input_dev, chip);
249 beep->
dev = input_dev;
261 err = input_register_device(beep->
dev);
268 fail1: input_free_device(input_dev);
279 input_unregister_device(chip->
beep->dev);