3 * Keith Outwater, keith_outwater@mvis.com
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/8xx_immap.h>
27 #include <linux/ctype.h>
30 * Basic beeper support for the GEN860T board. The GEN860T includes
31 * an audio sounder driven by a Phillips TDA8551 amplifier. The
32 * TDA8551 features a digital volume control which uses a "trinary"
33 * input (high/high-Z/low) to set volume. The 860's SPKROUT pin
34 * drives the amplifier input.
39 * Initialize beeper-related hardware. Initialize timer 1 for use with
40 * the beeper. Use 66 Mhz internal clock with prescale of 33 to get
41 * 1 uS period per count.
42 * FIXME: we should really compute the prescale based on the reported
43 * core clock frequency.
48 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
50 immap
->im_cpmtimer
.cpmt_tgcr
&= ~TGCR_RST1
| TGCR_STP1
;
51 immap
->im_cpmtimer
.cpmt_tmr1
= ((33 << TMR_PS_SHIFT
) & TMR_PS_MSK
)
52 | TMR_OM
| TMR_FRR
| TMR_ICLK_IN_GEN
;
53 immap
->im_cpmtimer
.cpmt_tcn1
= 0;
54 immap
->im_cpmtimer
.cpmt_ter1
= 0xffff;
55 immap
->im_cpmtimer
.cpmt_tgcr
|= TGCR_RST1
;
60 * Set beeper frequency. Max allowed frequency is 2.5 KHz. This limit
61 * is mostly arbitrary, but the beeper isn't really much good beyond this
65 set_beeper_frequency(uint frequency
)
67 #define FREQ_LIMIT 2500
69 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
72 * Compute timer ticks given desired frequency. The timer is set up
73 * to count 0.5 uS per tick and it takes two ticks per cycle (Hz).
75 if (frequency
> FREQ_LIMIT
) frequency
= FREQ_LIMIT
;
76 frequency
= 1000000/frequency
;
77 immap
->im_cpmtimer
.cpmt_trr1
= (ushort
)frequency
;
87 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
89 immap
->im_cpmtimer
.cpmt_tgcr
&= ~TGCR_STP1
;
99 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
101 immap
->im_cpmtimer
.cpmt_tgcr
|= TGCR_STP1
;
106 * Increase or decrease the beeper volume. Volume can be set
107 * from off to full in 64 steps. To increase volume, the output
108 * pin is actively driven high, then returned to tristate.
109 * To decrease volume, output a low on the port pin (no need to
110 * change pin mode to tristate) then output a high to go back to
114 set_beeper_volume(int steps
)
116 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
120 for (i
= 0; i
< (steps
>= 64 ? 64 : steps
); i
++) {
121 immap
->im_cpm
.cp_pbodr
&= ~(0x80000000 >> 19);
123 immap
->im_cpm
.cp_pbodr
|= (0x80000000 >> 19);
128 for (i
= 0; i
> (steps
<= -64 ? -64 : steps
); i
--) {
129 immap
->im_cpm
.cp_pbdat
&= ~(0x80000000 >> 19);
131 immap
->im_cpm
.cp_pbdat
|= (0x80000000 >> 19);
139 * Check the environment to see if the beeper needs beeping.
140 * Controlled by a sequence of the form:
141 * freq/delta volume/on time/off time;... where:
142 * freq = frequency in Hz (0 - 2500)
143 * delta volume = volume steps up or down (-64 <= vol <= 64)
144 * on time = time in mS
145 * off time = time in mS
147 * Return 1 on success, 0 on failure
150 do_beeper(char *sequence
)
152 #define DELIMITER ';'
161 * Parse the control sequence. This is a really simple parser
162 * without any real error checking. You can probably blow it
165 if (*p
== '\0' || !isdigit(*p
)) {
166 printf("%s:%d: null or invalid string (%s)\n",
167 __FILE__
, __LINE__
, p
);
173 while (*p
!= DELIMITER
) {
175 val
= (int) simple_strtol(p
, &tp
, 0);
177 printf("%s:%d: no digits or bad format\n",
186 if (*tp
== DELIMITER
)
194 * Well, we got something that has a chance of being correct
197 for (i
= 0; i
< 4; i
++) {
198 printf("%s:%d:arg %d = %d\n", __FILE__
, __LINE__
, i
, args
[i
]);
203 set_beeper_frequency(args
[0]);
204 set_beeper_volume(args
[1]);
206 udelay(1000 * args
[2]);
208 udelay(1000 * args
[3]);
213 /* vim: set ts=4 sw=4 tw=78: */