3 * Keith Outwater, keith_outwater@mvis.com
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/8xx_immap.h>
11 #include <linux/ctype.h>
14 * Basic beeper support for the GEN860T board. The GEN860T includes
15 * an audio sounder driven by a Phillips TDA8551 amplifier. The
16 * TDA8551 features a digital volume control which uses a "trinary"
17 * input (high/high-Z/low) to set volume. The 860's SPKROUT pin
18 * drives the amplifier input.
22 * Initialize beeper-related hardware. Initialize timer 1 for use with
23 * the beeper. Use 66 MHz internal clock with prescale of 33 to get
24 * 1 uS period per count.
25 * FIXME: we should really compute the prescale based on the reported
26 * core clock frequency.
28 void init_beeper (void)
30 volatile immap_t
*immap
= (immap_t
*) CONFIG_SYS_IMMR
;
32 immap
->im_cpmtimer
.cpmt_tgcr
&= ~TGCR_RST1
| TGCR_STP1
;
33 immap
->im_cpmtimer
.cpmt_tmr1
= ((33 << TMR_PS_SHIFT
) & TMR_PS_MSK
)
34 | TMR_OM
| TMR_FRR
| TMR_ICLK_IN_GEN
;
35 immap
->im_cpmtimer
.cpmt_tcn1
= 0;
36 immap
->im_cpmtimer
.cpmt_ter1
= 0xffff;
37 immap
->im_cpmtimer
.cpmt_tgcr
|= TGCR_RST1
;
41 * Set beeper frequency. Max allowed frequency is 2.5 KHz. This limit
42 * is mostly arbitrary, but the beeper isn't really much good beyond this
45 void set_beeper_frequency (uint frequency
)
47 #define FREQ_LIMIT 2500
49 volatile immap_t
*immap
= (immap_t
*) CONFIG_SYS_IMMR
;
52 * Compute timer ticks given desired frequency. The timer is set up
53 * to count 0.5 uS per tick and it takes two ticks per cycle (Hz).
55 if (frequency
> FREQ_LIMIT
)
56 frequency
= FREQ_LIMIT
;
57 frequency
= 1000000 / frequency
;
58 immap
->im_cpmtimer
.cpmt_trr1
= (ushort
) frequency
;
66 volatile immap_t
*immap
= (immap_t
*) CONFIG_SYS_IMMR
;
68 immap
->im_cpmtimer
.cpmt_tgcr
&= ~TGCR_STP1
;
74 void beeper_off (void)
76 volatile immap_t
*immap
= (immap_t
*) CONFIG_SYS_IMMR
;
78 immap
->im_cpmtimer
.cpmt_tgcr
|= TGCR_STP1
;
82 * Increase or decrease the beeper volume. Volume can be set
83 * from off to full in 64 steps. To increase volume, the output
84 * pin is actively driven high, then returned to tristate.
85 * To decrease volume, output a low on the port pin (no need to
86 * change pin mode to tristate) then output a high to go back to
89 void set_beeper_volume (int steps
)
91 volatile immap_t
*immap
= (immap_t
*) CONFIG_SYS_IMMR
;
95 for (i
= 0; i
< (steps
>= 64 ? 64 : steps
); i
++) {
96 immap
->im_cpm
.cp_pbodr
&= ~(0x80000000 >> 19);
98 immap
->im_cpm
.cp_pbodr
|= (0x80000000 >> 19);
102 for (i
= 0; i
> (steps
<= -64 ? -64 : steps
); i
--) {
103 immap
->im_cpm
.cp_pbdat
&= ~(0x80000000 >> 19);
105 immap
->im_cpm
.cp_pbdat
|= (0x80000000 >> 19);
112 * Check the environment to see if the beeper needs beeping.
113 * Controlled by a sequence of the form:
114 * freq/delta volume/on time/off time;... where:
115 * freq = frequency in Hz (0 - 2500)
116 * delta volume = volume steps up or down (-64 <= vol <= 64)
117 * on time = time in mS
118 * off time = time in mS
120 * Return 1 on success, 0 on failure
122 int do_beeper (char *sequence
)
124 #define DELIMITER ';'
133 * Parse the control sequence. This is a really simple parser
134 * without any real error checking. You can probably blow it
137 if (*p
== '\0' || !isdigit (*p
)) {
138 printf ("%s:%d: null or invalid string (%s)\n",
139 __FILE__
, __LINE__
, p
);
145 while (*p
!= DELIMITER
) {
148 val
= (int) simple_strtol (p
, &tp
, 0);
150 printf ("%s:%d: no digits or bad format\n",
158 if (*tp
== DELIMITER
)
166 * Well, we got something that has a chance of being correct
169 for (i
= 0; i
< 4; i
++) {
170 printf ("%s:%d:arg %d = %d\n", __FILE__
, __LINE__
, i
,
175 set_beeper_frequency (args
[0]);
176 set_beeper_volume (args
[1]);
178 udelay (1000 * args
[2]);
180 udelay (1000 * args
[3]);