Attention is currently required from: Jérémy Compostella.
Hello Jérémy Compostella,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/83372?usp=email
to look at the new patch set (#2).
Change subject: drivers/pc80/pc/spkmodem.c: Use beep() instead of own implementation ......................................................................
drivers/pc80/pc/spkmodem.c: Use beep() instead of own implementation
Commit 23b79483554f (pc80/i8254: Add speaker beep function) added a driver to play beeps using the 8254 PIT chip and the PC speaker, which is essentially the same as the make_tone() function in spkmodem.c. Drop the duplicate functionality provided by make_tone() in favour of the common beep() function, which also has a more intuitive signature.
Converting the make_tone() arguments to beep() arguments is not trivial, as they are different in meaning and requires some background knowledge of PIT programming, explained briefly here.
The `duration` argument to make_tone() is somewhat misleading, as it is not used as a direct number of units of time, but rather the number of PIT counter reloads to wait for. The frequency of the reloads is related to the `freq_count` argument, which is the value the counter is reloaded to when it counts down to 0. Since the counter decrements at 1193181 Hz, dividing this frequency by the desired frequency of the tone gives the counter reload value, which was used to calculate the freq_count argument for the calls to make_tone().
However, since the PIT output toggles at every reload, each full cycle occurs at half the desired frequency. To compensate for this, mode 3 (square wave generator) of the PIT chip actually decrements the counter by 2 each time so that the counter reloads twice as often. Thus, each reload occurs every 1 / (frequency * 2) seconds.
Since `duration` counts reloads, multiplying it by the time between reloads gives the time in seconds, and thus the following formula was used to convert `duration` into a millisecond value to pass as the duration_msec argument for beep(): duration_msec = 1000 * duration/(2*frequency)
Change-Id: If95b518c991a0d700489566e5609344ca2cbbc7a Signed-off-by: Nicholas Chin nic.c3.14@gmail.com --- M src/drivers/pc80/pc/spkmodem.c 1 file changed, 6 insertions(+), 83 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/72/83372/2