1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <mpc8xx.h>
26#include <asm/8xx_immap.h>
27#include <linux/ctype.h>
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44void init_beeper (void)
45{
46 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
47
48 immap->im_cpmtimer.cpmt_tgcr &= ~TGCR_RST1 | TGCR_STP1;
49 immap->im_cpmtimer.cpmt_tmr1 = ((33 << TMR_PS_SHIFT) & TMR_PS_MSK)
50 | TMR_OM | TMR_FRR | TMR_ICLK_IN_GEN;
51 immap->im_cpmtimer.cpmt_tcn1 = 0;
52 immap->im_cpmtimer.cpmt_ter1 = 0xffff;
53 immap->im_cpmtimer.cpmt_tgcr |= TGCR_RST1;
54}
55
56
57
58
59
60
61void set_beeper_frequency (uint frequency)
62{
63#define FREQ_LIMIT 2500
64
65 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
66
67
68
69
70
71 if (frequency > FREQ_LIMIT)
72 frequency = FREQ_LIMIT;
73 frequency = 1000000 / frequency;
74 immap->im_cpmtimer.cpmt_trr1 = (ushort) frequency;
75}
76
77
78
79
80void beeper_on (void)
81{
82 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
83
84 immap->im_cpmtimer.cpmt_tgcr &= ~TGCR_STP1;
85}
86
87
88
89
90void beeper_off (void)
91{
92 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
93
94 immap->im_cpmtimer.cpmt_tgcr |= TGCR_STP1;
95}
96
97
98
99
100
101
102
103
104
105void set_beeper_volume (int steps)
106{
107 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
108 int i;
109
110 if (steps >= 0) {
111 for (i = 0; i < (steps >= 64 ? 64 : steps); i++) {
112 immap->im_cpm.cp_pbodr &= ~(0x80000000 >> 19);
113 udelay (1);
114 immap->im_cpm.cp_pbodr |= (0x80000000 >> 19);
115 udelay (1);
116 }
117 } else {
118 for (i = 0; i > (steps <= -64 ? -64 : steps); i--) {
119 immap->im_cpm.cp_pbdat &= ~(0x80000000 >> 19);
120 udelay (1);
121 immap->im_cpm.cp_pbdat |= (0x80000000 >> 19);
122 udelay (1);
123 }
124 }
125}
126
127
128
129
130
131
132
133
134
135
136
137
138int do_beeper (char *sequence)
139{
140#define DELIMITER ';'
141
142 int args[4];
143 int i;
144 int val;
145 char *p = sequence;
146 char *tp;
147
148
149
150
151
152
153 if (*p == '\0' || !isdigit (*p)) {
154 printf ("%s:%d: null or invalid string (%s)\n",
155 __FILE__, __LINE__, p);
156 return 0;
157 }
158
159 i = 0;
160 while (*p != '\0') {
161 while (*p != DELIMITER) {
162 if (i > 3)
163 i = 0;
164 val = (int) simple_strtol (p, &tp, 0);
165 if (tp == p) {
166 printf ("%s:%d: no digits or bad format\n",
167 __FILE__, __LINE__);
168 return 0;
169 } else {
170 args[i] = val;
171 }
172
173 i++;
174 if (*tp == DELIMITER)
175 p = tp;
176 else
177 p = ++tp;
178 }
179 p++;
180
181
182
183
184#if 0
185 for (i = 0; i < 4; i++) {
186 printf ("%s:%d:arg %d = %d\n", __FILE__, __LINE__, i,
187 args[i]);
188 }
189 printf ("\n");
190#endif
191 set_beeper_frequency (args[0]);
192 set_beeper_volume (args[1]);
193 beeper_on ();
194 udelay (1000 * args[2]);
195 beeper_off ();
196 udelay (1000 * args[3]);
197 }
198 return 1;
199}
200