Lines Matching +full:min +full:- +full:sample +full:- +full:rate +full:- +full:hz
1 // SPDX-License-Identifier: GPL-2.0-or-later
14 #include <linux/dma-mapping.h>
21 int volume; /* mixer volume: 0-100 */
23 int hz; member
35 struct pmac_beep *beep = chip->beep; in snd_pmac_beep_stop()
36 if (beep && beep->running) { in snd_pmac_beep_stop()
37 beep->running = 0; in snd_pmac_beep_stop()
43 * Stuff for outputting a beep. The values range from -327 to +327
61 58, 45, 32, 18, 3, -11, -26, -41,
62 -55, -68, -79, -88, -95, -100, -102, -102,
63 -99, -93, -85, -75, -62, -48, -33, -16,
66 55, 41, 26, 11, -3, -18, -32, -45,
67 -58, -68, -78, -86, -92, -97, -101, -103,
68 -105, -105, -105, -104, -104, -103, -103, -103,
69 -103, -105, -107, -110, -113, -117, -122, -128,
70 -133, -139, -144, -150, -155, -159, -163, -167,
71 -169, -170, -171, -171, -171, -169, -168, -166,
72 -164, -162, -161, -160, -159, -159, -160, -161,
73 -163, -166, -170, -174, -179, -183, -188, -193,
74 -197, -201, -204, -207, -209, -209, -209, -208,
75 -206, -203, -200, -196, -192, -189, -186, -183,
76 -182, -182, -183, -186, -190, -196, -204, -213,
77 -224, -236, -249, -262, -275, -288, -299, -310,
78 -318, -324, -327, -327, -323, -316, -304, -288,
79 -269, -245, -218, -187, -153, -117, -79, -40,
82 #define BEEP_SRATE 22050 /* 22050 Hz sample rate */
84 #define BEEP_VOLUME 15 /* 0 - 100 */
87 unsigned int code, int hz) in snd_pmac_beep_event() argument
99 return -1; in snd_pmac_beep_event()
102 case SND_BELL: if (hz) hz = 1000; break; in snd_pmac_beep_event()
104 default: return -1; in snd_pmac_beep_event()
109 return -1; in snd_pmac_beep_event()
110 beep = chip->beep; in snd_pmac_beep_event()
112 return -1; in snd_pmac_beep_event()
114 if (! hz) { in snd_pmac_beep_event()
115 spin_lock_irqsave(&chip->reg_lock, flags); in snd_pmac_beep_event()
116 if (beep->running) in snd_pmac_beep_event()
118 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_pmac_beep_event()
122 beep_speed = snd_pmac_rate_index(chip, &chip->playback, BEEP_SRATE); in snd_pmac_beep_event()
123 srate = chip->freq_table[beep_speed]; in snd_pmac_beep_event()
125 if (hz <= srate / BEEP_BUFLEN || hz > srate / 2) in snd_pmac_beep_event()
126 hz = 1000; in snd_pmac_beep_event()
128 spin_lock_irqsave(&chip->reg_lock, flags); in snd_pmac_beep_event()
129 if (chip->playback.running || chip->capture.running || beep->running) { in snd_pmac_beep_event()
130 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_pmac_beep_event()
133 beep->running = 1; in snd_pmac_beep_event()
134 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_pmac_beep_event()
136 if (hz == beep->hz && beep->volume == beep->volume_play) { in snd_pmac_beep_event()
137 nsamples = beep->nsamples; in snd_pmac_beep_event()
139 period = srate * 256 / hz; /* fixed point */ in snd_pmac_beep_event()
144 p = beep->buf; in snd_pmac_beep_event()
146 p[0] = p[1] = beep_wform[j >> 8] * beep->volume; in snd_pmac_beep_event()
149 beep->hz = hz; in snd_pmac_beep_event()
150 beep->volume_play = beep->volume; in snd_pmac_beep_event()
151 beep->nsamples = nsamples; in snd_pmac_beep_event()
154 spin_lock_irqsave(&chip->reg_lock, flags); in snd_pmac_beep_event()
155 snd_pmac_beep_dma_start(chip, beep->nsamples * 4, beep->addr, beep_speed); in snd_pmac_beep_event()
156 spin_unlock_irqrestore(&chip->reg_lock, flags); in snd_pmac_beep_event()
167 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_pmac_info_beep()
168 uinfo->count = 1; in snd_pmac_info_beep()
169 uinfo->value.integer.min = 0; in snd_pmac_info_beep()
170 uinfo->value.integer.max = 100; in snd_pmac_info_beep()
178 if (snd_BUG_ON(!chip->beep)) in snd_pmac_get_beep()
179 return -ENXIO; in snd_pmac_get_beep()
180 ucontrol->value.integer.value[0] = chip->beep->volume; in snd_pmac_get_beep()
189 if (snd_BUG_ON(!chip->beep)) in snd_pmac_put_beep()
190 return -ENXIO; in snd_pmac_put_beep()
191 oval = chip->beep->volume; in snd_pmac_put_beep()
192 nval = ucontrol->value.integer.value[0]; in snd_pmac_put_beep()
194 return -EINVAL; in snd_pmac_put_beep()
195 chip->beep->volume = nval; in snd_pmac_put_beep()
196 return oval != chip->beep->volume; in snd_pmac_put_beep()
214 int err = -ENOMEM; in snd_pmac_attach_beep()
218 return -ENOMEM; in snd_pmac_attach_beep()
219 dmabuf = dma_alloc_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4, in snd_pmac_attach_beep()
220 &beep->addr, GFP_KERNEL); in snd_pmac_attach_beep()
226 input_dev->name = "PowerMac Beep"; in snd_pmac_attach_beep()
227 input_dev->phys = "powermac/beep"; in snd_pmac_attach_beep()
228 input_dev->id.bustype = BUS_ADB; in snd_pmac_attach_beep()
229 input_dev->id.vendor = 0x001f; in snd_pmac_attach_beep()
230 input_dev->id.product = 0x0001; in snd_pmac_attach_beep()
231 input_dev->id.version = 0x0100; in snd_pmac_attach_beep()
233 input_dev->evbit[0] = BIT_MASK(EV_SND); in snd_pmac_attach_beep()
234 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); in snd_pmac_attach_beep()
235 input_dev->event = snd_pmac_beep_event; in snd_pmac_attach_beep()
236 input_dev->dev.parent = &chip->pdev->dev; in snd_pmac_attach_beep()
239 beep->dev = input_dev; in snd_pmac_attach_beep()
240 beep->buf = dmabuf; in snd_pmac_attach_beep()
241 beep->volume = BEEP_VOLUME; in snd_pmac_attach_beep()
242 beep->running = 0; in snd_pmac_attach_beep()
245 err = snd_ctl_add(chip->card, beep_ctl); in snd_pmac_attach_beep()
249 chip->beep = beep; in snd_pmac_attach_beep()
251 err = input_register_device(beep->dev); in snd_pmac_attach_beep()
257 fail2: snd_ctl_remove(chip->card, beep_ctl); in snd_pmac_attach_beep()
260 dma_free_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4, in snd_pmac_attach_beep()
261 dmabuf, beep->addr); in snd_pmac_attach_beep()
268 if (chip->beep) { in snd_pmac_detach_beep()
269 input_unregister_device(chip->beep->dev); in snd_pmac_detach_beep()
270 dma_free_coherent(&chip->pdev->dev, BEEP_BUFLEN * 4, in snd_pmac_detach_beep()
271 chip->beep->buf, chip->beep->addr); in snd_pmac_detach_beep()
272 kfree(chip->beep); in snd_pmac_detach_beep()
273 chip->beep = NULL; in snd_pmac_detach_beep()