]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/linux/openzaurus-sa-2.4.18-rmk7-pxa3-embedix20030509/sound-2.4.18r2.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / linux / openzaurus-sa-2.4.18-rmk7-pxa3-embedix20030509 / sound-2.4.18r2.patch
1 diff -Nuar linux-2.4.18/arch/arm/mach-sa1100/m62332.c linux-2.4.18p/arch/arm/mach-sa1100/m62332.c
2 --- linux-2.4.18/arch/arm/mach-sa1100/m62332.c  2003-05-13 11:18:14.000000000 +0200
3 +++ linux-2.4.18p/arch/arm/mach-sa1100/m62332.c 2004-10-12 22:36:36.000000000 +0200
4 @@ -131,3 +131,5 @@
5  
6         return 0;
7  }
8 +EXPORT_SYMBOL(m62332_senddata);
9 +
10 diff -Nuar linux-2.4.18/arch/arm/mach-sa1100/Makefile linux-2.4.18p/arch/arm/mach-sa1100/Makefile
11 --- linux-2.4.18/arch/arm/mach-sa1100/Makefile  2003-05-13 11:18:14.000000000 +0200
12 +++ linux-2.4.18p/arch/arm/mach-sa1100/Makefile 2004-10-12 22:36:19.000000000 +0200
13 @@ -18,7 +18,7 @@
14  export-objs := assabet.o consus.o badge4.o dma-sa1100.o dma-sa1111.o \
15                 flexanet.o freebird.o generic.o h3600.o \
16                 huw_webpanel.o irq.o pcipool.o sa1111.o sa1111-pcibuf.o \
17 -               system3.o yopy.o usb_ctl.o usb_recv.o usb_send.o
18 +               system3.o yopy.o usb_ctl.o usb_recv.o usb_send.o m62332.o
19  
20  # These aren't present yet, and prevents a plain -ac kernel building.
21  # hwtimer.o
22 @@ -36,7 +36,7 @@
23  obj-$(CONFIG_SA1100_LART) += cpu-sa1100.o
24  endif
25  
26 -obj-$(CONFIG_SA1100_COLLIE) += collie.o m62332.o collie_battery.o collie_led.o collie_buzzer.o
27 +obj-$(CONFIG_SA1100_COLLIE) += collie.o m62332.o collie_battery.o collie_led.o
28  
29  # Next, the SA1111 stuff.
30  obj-$(CONFIG_SA1111) += sa1111.o dma-sa1111.o
31 diff -Nuar linux-2.4.18/drivers/char/Makefile linux-2.4.18p/drivers/char/Makefile
32 --- linux-2.4.18/drivers/char/Makefile  2003-05-13 11:18:18.000000000 +0200
33 +++ linux-2.4.18p/drivers/char/Makefile 2004-10-12 17:26:44.000000000 +0200
34 @@ -228,7 +228,7 @@
35  obj-y += joystick/js.o
36  endif
37  
38 -obj-$(CONFIG_SA1100_COLLIE) += sharp_led.o sharp_kbdctl.o sharp_buzzer.o
39 +obj-$(CONFIG_SA1100_COLLIE) += sharp_led.o sharp_kbdctl.o
40  obj-$(CONFIG_DISCOVERY_LED) += sharp_led.o discovery_led.o
41  obj-$(CONFIG_ARCH_PXA_POODLE) += sharp_led.o sharp_kbdctl.o sharpsl_led.o sharp_buzzer.o
42  obj-$(CONFIG_ARCH_PXA_CORGI) += sharp_led.o sharpsl_led.o sharp_kbdctl.o corgi_rc.o sharp_buzzer.o
43 diff -Nuar linux-2.4.18/drivers/sound/colliebuzzer.h linux-2.4.18p/drivers/sound/colliebuzzer.h
44 --- linux-2.4.18/drivers/sound/colliebuzzer.h   1970-01-01 01:00:00.000000000 +0100
45 +++ linux-2.4.18p/drivers/sound/colliebuzzer.h  2004-10-13 15:24:51.028208808 +0200
46 @@ -0,0 +1,756 @@
47 +unsigned short tap_data[] = {
48 +       0x0000 , 0xff00 , 0xff00 , 0x0000 , 
49 +       0xff00 , 0x0000 , 0x0000 , 0x0100 , 
50 +       0x0000 , 0x0100 , 0x0000 , 0x0100 , 
51 +       0x0100 , 0x0000 , 0x0100 , 0x0100 , 
52 +       0x0100 , 0x0100 , 0x0100 , 0x0100 , 
53 +       0x0100 , 0x0100 , 0x0100 , 0x0100 , 
54 +       0x0100 , 0x0000 , 0x0100 , 0x0000 , 
55 +       0x0100 , 0xff00 , 0x0100 , 0x0000 , 
56 +       0x0100 , 0x0000 , 0x0000 , 0x0100 , 
57 +       0x0000 , 0x0100 , 0x0000 , 0x0100 , 
58 +       0x0000 , 0x0000 , 0x0000 , 0x0000 , 
59 +       0x0000 , 0x0100 , 0x0000 , 0x0100 , 
60 +       0x0000 , 0x0100 , 0x0700 , 0x1c00 , 
61 +       0xc800 , 0xd900 , 0x2b00 , 0x2700 , 
62 +       0xbf00 , 0xe000 , 0x0d00 , 0x1000 , 
63 +       0xf500 , 0xd700 , 0x0100 , 0x0a00 , 
64 +       0xfb00 , 0xfa00 , 0x2200 , 0x0100 , 
65 +       0xeb00 , 0x0300 , 0x0600 , 0x1600 , 
66 +       0xe500 , 0xf500 , 0x0d00 , 0x0a00 , 
67 +       0x0100 , 0xfb00 , 0x0000 , 0x0100 , 
68 +       0xf200 , 0x0400 , 0x0600 , 0x0000 , 
69 +       0xf100 , 0x0300 , 0x1200 , 0xfe00 , 
70 +       0xe900 , 0x0400 , 0x0100 , 0x0d00 , 
71 +       0xf500 , 0x0100 , 0x0100 , 0xfe00 , 
72 +       0x0100 , 0xfb00 , 0x0400 , 0xff00 , 
73 +       0xf700 , 0x0400 , 0x0000 , 0xfe00 , 
74 +       0x0200 , 0x0000 , 0x0100 , 0xfd00 , 
75 +       0x0000 , 0xff00 , 0x0200 , 0x0000 , 
76 +       0xff00 , 0x0000 , 0x0200 , 0xfc00 , 
77 +       0xfe00 , 0xff00 , 0x0100 , 0x0200 , 
78 +       0x0000 , 0xff00 , 0xfc00 , 0x0100 , 
79 +       0x0100 , 0x0100 , 0xff00 , 0x0000 , 
80 +       0x0300 , 0xfe00 , 0xfe00 , 0x0200 , 
81 +       0xff00 , 0x0000 , 0x0000 , 0xfe00 , 
82 +       0x0000 , 0xff00 , 0x0000 , 0x0000 , 
83 +       0x0000 , 0xff00 , 0x0000 , 0x0000 , 
84 +       0xff00 , 0xfe00 , 0xfd00 , 0x0100 , 
85 +       0x0000 , 0xfe00 , 0xff00 , 0xff00 , 
86 +       0x0000 , 0xff00 , 0x0100 , 0xfe00 , 
87 +       0xff00 , 0xff00 , 0x0000 , 0x0000 , 
88 +       0xfe00 , 0xff00 , 0x0100 , 0x0100 , 
89 +       0xff00 , 0x0100 , 0x0100 , 0xfe00 , 
90 +       0x0000 , 0x0000 , 0x0000 , 0x0100 , 
91 +       0x0000 , 0x0000 , 0xff00 , 0x0000 , 
92 +       0x0100 , 0x0000 , 0x0200 };
93 +
94 +
95 +unsigned short click_data[] = {
96 +       0x0100 , 0x0100 , 0x0100 , 0x0000 , 
97 +       0x0100 , 0xff00 , 0x0100 , 0x0000 , 
98 +       0xff00 , 0xff00 , 0xff00 , 0x0000 , 
99 +       0xff00 , 0xff00 , 0xff00 , 0xff00 , 
100 +       0xff00 , 0xff00 , 0x0000 , 0xff00 , 
101 +       0xff00 , 0xff00 , 0x0000 , 0xff00 , 
102 +       0xff00 , 0xff00 , 0xff00 , 0x0100 , 
103 +       0x0000 , 0xff00 , 0xfe00 , 0x0100 , 
104 +       0xff00 , 0x0100 , 0xff00 , 0x0100 , 
105 +       0x0100 , 0x0300 , 0xff00 , 0xff00 , 
106 +       0xff00 , 0x0100 , 0x0100 , 0x0000 , 
107 +       0xfe00 , 0xfe00 , 0xfe00 , 0xfc00 , 
108 +       0xfe00 , 0x0100 , 0xfd00 , 0xff00 , 
109 +       0xff00 , 0xfc00 , 0xfe00 , 0xfd00 , 
110 +       0x0100 , 0xfe00 , 0x0100 , 0xf800 , 
111 +       0xfe00 , 0xfe00 , 0xfc00 , 0xe600 , 
112 +       0xdb00 , 0x2500 , 0xdb00 , 0xee00 , 
113 +       0xdb00 , 0x0600 , 0xeb00 , 0x1f00 , 
114 +       0x1e00 , 0xeb00 , 0xfe00 , 0x0000 , 
115 +       0xff00 , 0x1900 , 0xef00 , 0xf700 , 
116 +       0x2100 , 0xe400 , 0x0100 , 0x0600 , 
117 +       0xff00 , 0x0300 , 0xf900 , 0x0f00 , 
118 +       0xf600 , 0x0100 , 0xfe00 , 0xf900 , 
119 +       0x0500 , 0xf500 , 0x0600 , 0xfb00 , 
120 +       0x0800 , 0x0100 , 0x0300 , 0x0100 , 
121 +       0xf700 , 0xfa00 , 0xfd00 , 0xfc00 , 
122 +       0x0800 , 0xfb00 , 0x0500 , 0xfe00 , 
123 +       0xfc00 , 0xfc00 , 0xfe00 , 0x0400 , 
124 +       0xff00 , 0xff00 , 0x0500 , 0x0100 , 
125 +       0xfc00 , 0xff00 , 0xfe00 , 0xfb00 , 
126 +       0x0200 , 0x0200 , 0xff00 , 0xfe00 , 
127 +       0xfe00 , 0x0600 , 0xfb00 , 0xff00 , 
128 +       0xfc00 , 0x0600 , 0xfb00 , 0xff00 , 
129 +       0xff00 , 0x0100 , 0xff00 , 0x0200 , 
130 +       0xff00 , 0xfb00 , 0xff00 , 0x0200 , 
131 +       0xff00 , 0x0200 , 0x0100 , 0xfe00 , 
132 +       0xfe00 , 0x0100 , 0xfd00 , 0x0200 , 
133 +       0xfc00 , 0x0800 , 0xfe00 , 0xfe00 , 
134 +       0x0400 , 0xfc00 , 0xff00 , 0xfc00 , 
135 +       0x0500 , 0x0200 , 0x0800 , 0x0200 , 
136 +       0x0100 , 0xfe00 , 0x0100 , 0xff00 , 
137 +       0x0700 , 0xfb00 , 0xfc00 , 0x0100 , 
138 +       0xfe00 , 0xfc00 , 0x0b00 , 0xfb00 , 
139 +       0xfb00 , 0x0700 , 0xfb00 , 0xfb00 , 
140 +       0x0100 , 0xff00 , 0xfb00 , 0xfd00 , 
141 +       0x0000 , 0xfe00 , 0xfe00 , 0xff00 , 
142 +       0xfc00 , 0x0400 , 0x0000 , 0xfe00 , 
143 +       0xff00 , 0x0200 , 0xff00 , 0x0000 , 
144 +       0x0500 , 0x0100 , 0x0100 , 0x0100 , 
145 +       0x0100 , 0x0000 , 0x0300 , 0xfe00 , 
146 +       0xff00 , 0x0100 , 0x0100 , 0xfe00 , 
147 +       0x0000 , 0xff00 , 0x0100 , 0xff00 , 
148 +       0x0200 , 0xff00 , 0xff00 , 0xff00 , 
149 +       0xff00 , 0xfe00 , 0x0000 , 0xff00 , 
150 +       0xfe00 , 0xff00 , 0xfd00 , 0x0000 , 
151 +       0xff00 , 0xfe00 , 0xff00 , 0xfc00 , 
152 +       0x0100 , 0xfd00 , 0xff00 , 0xff00 , 
153 +       0x0200 , 0xff00 , 0x0100 , 0xff00 , 
154 +       0xfc00 , 0x0300 , 0xff00 , 0x0200 , 
155 +       0xff00 , 0x0100 , 0xff00 , 0x0100 , 
156 +       0xff00 , 0xff00 , 0x0100 , 0xfe00 , 
157 +       0x0300 , 0xfc00 , 0x0100 , 0xff00 , 
158 +       0x0100 , 0x0100 , 0x0100 , 0xfc00 , 
159 +       0xff00 , 0x0100 , 0x0100 , 0xfe00 , 
160 +       0x0100 , 0xff00 , 0x0100 , 0xfc00 , 
161 +       0x0100 , 0x0200 , 0xff00 , 0x0100 , 
162 +       0xff00 , 0xff00 , 0x0200 , 0xfd00 , 
163 +       0xfe00 , 0x0100 , 0xff00 , 0x0100 , 
164 +       0xfe00 , 0x0100 , 0x0300 , 0xfe00 , 
165 +       0x0300 , 0xfe00 , 0xff00 , 0x0100 , 
166 +       0xff00 , 0x0200 , 0xfd00 , 0x0000 , 
167 +       0xff00 , 0x0200 , 0xff00 , 0x0200 , 
168 +       0xff00 , 0x0100 , 0x0000 , 0xff00 , 
169 +       0x0200 , 0x0100 , 0x0000 , 0xff00 , 
170 +       0x0100 , 0xfe00 , 0x0200 , 0xfe00 , 
171 +       0xfe00 , 0x0100 , 0xfe00 , 0x0100 , 
172 +       0xfd00 , 0xff00 , 0xff00 , 0xfe00 , 
173 +       0xff00 , 0xfc00 , 0x0100 , 0xfe00 , 
174 +       0x0100 , 0xff00 , 0xfe00 , 0xff00 , 
175 +       0xff00 , 0xfe00 , 0x0100 , 0xfe00 , 
176 +       0x0100 , 0xff00 , 0x0100 , 0xfe00 , 
177 +       0xff00 , 0x0200 , 0xfe00 , 0x0000 , 
178 +       0x0100 , 0x0200 , 0xff00 , 0x0200 , 
179 +       0xff00 , 0x0000 , 0x0100 , 0x0100 , 
180 +       0xff00 , 0x0200 , 0xfe00 , 0xff00 , 
181 +       0xff00 , 0xff00 , 0x0100 , 0x0000 , 
182 +       0xff00 , 0x0100 , 0xff00 , 0x0000 , 
183 +       0x0100 , 0xff00 , 0xfe00 , 0xff00 , 
184 +       0xff00 , 0x0100 , 0xff00 , 0x0100 , 
185 +       0xfe00 , 0xff00 , 0xff00 , 0xff00 , 
186 +       0xfe00 , 0xff00 , 0xff00 , 0x0100 , 
187 +       0xff00 , 0x0200 , 0xff00 , 0x0100 , 
188 +       0xff00 , 0xff00 };
189 +
190 +
191 +unsigned short alarm_data[] = {
192 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
193 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
194 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
195 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
196 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
197 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
198 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
199 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
200 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
201 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 0
202 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
203 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
204 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
205 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
206 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
207 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
208 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
209 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
210 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
211 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 1
212 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
213 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
214 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
215 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
216 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
217 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
218 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
219 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
220 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
221 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 2
222 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
223 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
224 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
225 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
226 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
227 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
228 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
229 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
230 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
231 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 3
232 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
233 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
234 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
235 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
236 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
237 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
238 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
239 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
240 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
241 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 4
242 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
243 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
244 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
245 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
246 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
247 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
248 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
249 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
250 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
251 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 5
252 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
253 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
254 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
255 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
256 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
257 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
258 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
259 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
260 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
261 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 0
262 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
263 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
264 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
265 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
266 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
267 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
268 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
269 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
270 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
271 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 1
272 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
273 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
274 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
275 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
276 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
277 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
278 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
279 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
280 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
281 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 2
282 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
283 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
284 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
285 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
286 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
287 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
288 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
289 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
290 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
291 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 3
292 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
293 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
294 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
295 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
296 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
297 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
298 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
299 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
300 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
301 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 4
302 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
303 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
304 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
305 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
306 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
307 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
308 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
309 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
310 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
311 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 5
312 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
313 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
314 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
315 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
316 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
317 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
318 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
319 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
320 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
321 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 0
322 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
323 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
324 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
325 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
326 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
327 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
328 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
329 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
330 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
331 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 1
332 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
333 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
334 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
335 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
336 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
337 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
338 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
339 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
340 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
341 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 2
342 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
343 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
344 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
345 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
346 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
347 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
348 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
349 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
350 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
351 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 3
352 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
353 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
354 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
355 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
356 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
357 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
358 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
359 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
360 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
361 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 4
362 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
363 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
364 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
365 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
366 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
367 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
368 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
369 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
370 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
371 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 5
372 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
373 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
374 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
375 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
376 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
377 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
378 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
379 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
380 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
381 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 0
382 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
383 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
384 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
385 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
386 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
387 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
388 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
389 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
390 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
391 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 1
392 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
393 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
394 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
395 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
396 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
397 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
398 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
399 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
400 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
401 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 2
402 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
403 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
404 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
405 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
406 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
407 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
408 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
409 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
410 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
411 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 3
412 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
413 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
414 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
415 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
416 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
417 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
418 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
419 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
420 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
421 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 4
422 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
423 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
424 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
425 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
426 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
427 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
428 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
429 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
430 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
431 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 5
432 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
433 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
434 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
435 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
436 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
437 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
438 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
439 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
440 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
441 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 0
442 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
443 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
444 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
445 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
446 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
447 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
448 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
449 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
450 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
451 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 1
452 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
453 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
454 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
455 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
456 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
457 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
458 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
459 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
460 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
461 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 2
462 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
463 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
464 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
465 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
466 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
467 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
468 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
469 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
470 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
471 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 3
472 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
473 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
474 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
475 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
476 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
477 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
478 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
479 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
480 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
481 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 4
482 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
483 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
484 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
485 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
486 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
487 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
488 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
489 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
490 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
491 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 5
492 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
493 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
494 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
495 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
496 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
497 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
498 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
499 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
500 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
501 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 0
502 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
503 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
504 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
505 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
506 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
507 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
508 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
509 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
510 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
511 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 1
512 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
513 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
514 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
515 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
516 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
517 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
518 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
519 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
520 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
521 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 2
522 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
523 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
524 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
525 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
526 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
527 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
528 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
529 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
530 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
531 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 3
532 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
533 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
534 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
535 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
536 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
537 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
538 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
539 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
540 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
541 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 4
542 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
543 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
544 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
545 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
546 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
547 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
548 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
549 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
550 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
551 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 5
552 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
553 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
554 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
555 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
556 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
557 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
558 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
559 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
560 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
561 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 0
562 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
563 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
564 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
565 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
566 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
567 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
568 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
569 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
570 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
571 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 1
572 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
573 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
574 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
575 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
576 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
577 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
578 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
579 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
580 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
581 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 2
582 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
583 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
584 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
585 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
586 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
587 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
588 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
589 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
590 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
591 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 3
592 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
593 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
594 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
595 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
596 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
597 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
598 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
599 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
600 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
601 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 4
602 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
603 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
604 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
605 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
606 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
607 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
608 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
609 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
610 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
611 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 5
612 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
613 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
614 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
615 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
616 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
617 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
618 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
619 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
620 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
621 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 0
622 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
623 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
624 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
625 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
626 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
627 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
628 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
629 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
630 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
631 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 1
632 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 0
633 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 1
634 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 2
635 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 3
636 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 4
637 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 5
638 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 6
639 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 7
640 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 8
641 +  0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x7fff , 0x7fff , 0x8000 , 0x8000 , // 9 2
642 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
643 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
644 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
645 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
646 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
647 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
648 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
649 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
650 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
651 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 3
652 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
653 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
654 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
655 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
656 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
657 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
658 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
659 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
660 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
661 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 4
662 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 0
663 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 1
664 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 2
665 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 3
666 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 4
667 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 5
668 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 6
669 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 7
670 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 8
671 +  0x7fff , 0x7fff , 0x7fff , 0x7fff , 0x8000 , 0x8000 , 0x8000 , 0x8000 , // 9 5
672 +
673 +};
674 +
675 +
676 +
677 +
678 +
679 +#define SHARP_BUZ_TOUCHSOUND 1
680 +#define SHARP_BUZ_KEYSOUND 2
681 +#define SHARP_BUZ_ALARM 11
682 +#define SHARP_BUZZER_MAKESOUND 0x5680
683 +
684 +static int collie_ct_s16_buzzer(const u_char *userPtr, size_t userCount,
685 +                          u_char frame[], ssize_t *frameUsed,
686 +                          ssize_t frameLeft)
687 +{
688 +       ssize_t count, used;
689 +       signed short *fp = (unsigned short *) &frame[*frameUsed];
690 +       signed short *up = (unsigned short *) userPtr;
691 +
692 +       DPRINTK("Collie_ct_s16 begin\n");
693 +
694 +       used = count = (userCount < frameLeft) ? userCount/2 : frameLeft/4;
695 +
696 +       DPRINTK("Collie_ct_s16 begin count %d \n",count);
697 +       
698 +       while (count > 0) {
699 +               *fp++ =  *up;
700 +               *fp++ =  *up++;
701 +               count--;
702 +       }
703 +
704 +       *frameUsed+=used*4;     
705 +       DPRINTK("Collie_ct_s16 exit\n");
706 +       return used*2;
707 +}
708 +
709 +
710 +static ssize_t sq_write_buzzer(int soundid)
711 +{
712 +       const char  * src;
713 +       audio_stream_t *s = &output_stream;
714 +       u_char *dest;
715 +       ssize_t uUsed, bUsed, bLeft, uLeft, ret = 0;
716 +
717 +
718 +       if ((collie_tc_status!=NA) && (collie_tc_status!=PLAY)) 
719 +           return -EPERM;
720 +
721 +       collie_tc_status=PLAY;
722 +
723 +       if (!s->buffers && sq_allocate_buffers(s)) {
724 +               return -ENOMEM;
725 +       }
726 +
727 +       
728 +#ifdef CONFIG_PM
729 +       /* Auto Power off cancel */
730 +//     autoPowerCancel = 0;
731 +#endif
732 +       DPRINTK("sq_write_buzzer: id:%d\n", soundid);
733 +
734 +       switch (soundid) {
735 +       case SHARP_BUZ_TOUCHSOUND:
736 +           src=tap_data;
737 +           uLeft=176*2;
738 +           break;
739 +       case SHARP_BUZ_KEYSOUND:
740 +           src=click_data;
741 +           uLeft=360*2;
742 +           break;
743 +       case SHARP_BUZ_ALARM:
744 +           src=alarm_data;
745 +           uLeft=3072*2;
746 +           break;
747 +       default:
748 +           return 0;
749 +       }
750 +       DPRINTK("sq_write_buzzer: uLeft=%d\n", uLeft);
751 +
752 +       collie_tc_mute_off();
753 +       while (uLeft > 0) {
754 +               audio_buf_t *b = s->buf;
755 +
756 +               ret = -ERESTARTSYS;
757 +               if (down_interruptible(&b->sem)) {
758 +                       break;
759 +               }
760 +
761 +               dest = b->start + b->size;
762 +               bUsed = 0;
763 +               bLeft = s->fragsize - b->size;
764 +               uUsed = collie_ct_s16_buzzer(src, uLeft, dest, &bUsed, bLeft);
765 +               cpu_cache_clean_invalidate_range((unsigned long)dest,
766 +                   (unsigned long)(dest+(audio_fragsize)), 0);
767 +               
768 +               DPRINTK("back to sq_write_buzzer %p\n",dest);           
769 +
770 +               if (uUsed < 0) {
771 +                       up(&b->sem);
772 +                       return -EFAULT;
773 +               }
774 +               src += uUsed;
775 +               uLeft -= uUsed;
776 +               b->size += bUsed;
777 +
778 +               if (b->size < s->fragsize) {
779 +                       up(&b->sem);
780 +                       break;
781 +               }
782 +
783 +               /* Send current buffer to dma */
784 +               sa1100_dma_queue_buffer(COLLIE_BUZZER_DMA_CHANNEL,
785 +                                       (void *) b, b->dma_addr, b->size);
786 +
787 +               Collie_volume_set(4);
788 +
789 +               b->size = 0;    /* indicate that the buffer has been sent */
790 +               NEXT_BUF(s, buf);
791 +       }
792 +
793 +       DPRINTK("sq_write_buzzer: return\n");
794 +       return ret;
795 +}
796 +
797 +
798 +
799 +
800 +
801 +
802 +
803 diff -Nuar linux-2.4.18/drivers/sound/collie_ssp.c linux-2.4.18p/drivers/sound/collie_ssp.c
804 --- linux-2.4.18/drivers/sound/collie_ssp.c     2003-05-13 11:18:37.000000000 +0200
805 +++ linux-2.4.18p/drivers/sound/collie_ssp.c    2004-10-13 15:05:36.000000000 +0200
806 @@ -9,6 +9,7 @@
807   *             I/F : Synchronous serial port (SSP) TI mode
808   *
809   * Copyright (C) 2001  SHARP
810 + * p.nis/dolOps messed around with it too!
811   *
812   * This program is free software; you can redistribute it and/or modify
813   * it under the terms of the GNU General Public License as published by
814 @@ -24,7 +25,18 @@
815   *     23-Oct-2001 SHARP
816   *             tune hardware control method
817   *     12-Nov-2001 Lineo Japan, Inc.
818 - *     14-Feb-2003 Sharp Corporation 8bit , GETOSPACE
819 + *
820 + *     26-Dec-2002 getospace added, some unneeded things removed
821 + *     
822 + *     28-Dec-2002 cut out old stuff, reorder stuff
823 + *
824 + *     04-Jan-2003 put in getospace from lineo's collie-tc35143.c
825 + *                 also added collie_record_on off, and exported these symbols
826 + *
827 + *     06-Jan-2003 if mixer ioctl SOUND_MIXER_READ_DEVMASK returns 0 as mask,
828 + *                 than the headphone(/mic) is not connected
829 + *                 
830 + *
831   */
832  #include <linux/module.h>
833  #include <linux/sched.h>
834 @@ -35,7 +47,7 @@
835  #include <linux/fcntl.h>
836  #include <linux/errno.h>
837  #include <linux/mm.h>
838 -#include <linux/malloc.h>
839 +#include <linux/slab.h>
840  #include <linux/sound.h>
841  #include <linux/init.h>
842  #include <linux/delay.h>
843 @@ -48,38 +60,30 @@
844  #include <asm/uaccess.h>
845  #include <asm/io.h>
846  #include <asm/dma.h>
847 -#include <asm/ucb1200.h>
848  
849  #include <linux/soundcard.h>
850  #include <asm/proc/cache.h>
851  
852 -#include <asm/arch/gpio.h>
853 +#include <asm/arch/hardware.h>
854  #include <asm/arch/m62332.h>
855  #include <asm/arch/tc35143.h>
856  
857  #undef DEBUG
858 -//#define DEBUG
859  #ifdef DEBUG
860  #define DPRINTK( x... )  printk( ##x )
861  #else
862  #define DPRINTK( x... )
863  #endif
864  
865 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0) || \
866 -    defined(CONFIG_COLLIE_TR1) || defined(CONFIG_COLLIE_DEV)
867 -#define COLLIE_TRY_ONE
868 -#else
869 -#undef COLLIE_TRY_ONE
870 -#endif
871 +#define        COLLIE_TRY_ONE
872  
873  #ifdef COLLIE_TRY_ONE
874  #ifndef        GPIO_REMOCON_ADC_SW
875  #define        GPIO_REMOCON_ADC_SW     GPIO_GPIO(18)
876  #endif
877  
878 +static int collie_rc_irq;
879  static DECLARE_WAIT_QUEUE_HEAD(audio_on);
880 -
881 -
882  static inline void collie_rc_set_int_mode(void)
883  {
884         GPSR = GPIO_REMOCON_ADC_SW;
885 @@ -91,14 +95,12 @@
886  }
887  #endif
888  
889 -
890  int collie_dmasound_irq = -1;
891 -#define        COLLIE_SOUND_DMA_CHANNEL        (collie_dmasound_irq)
892  
893 +#define        COLLIE_SOUND_DMA_CHANNEL        (collie_dmasound_irq)
894  #define SND_NDEVS      256     /* Number of supported devices */
895  #define SND_DEV_CTL    0       /* Control port /dev/mixer */
896 -#define SND_DEV_SEQ    1       /* Sequencer output /dev/sequencer (FM
897 -                                  synthesizer and MIDI output) */
898 +#define SND_DEV_SEQ    1       /* Sequencer output /dev/sequencer (FM synthesizer and MIDI output) */
899  #define SND_DEV_MIDIN  2       /* Raw midi access */
900  #define SND_DEV_DSP    3       /* Digitized voice /dev/dsp */
901  #define SND_DEV_AUDIO  4       /* Sparc compatible /dev/audio */
902 @@ -121,142 +123,25 @@
903  #endif
904  
905  /*** Some declarations ***********************************************/
906 -#define DMASND_TT      1
907 -#define DMASND_FALCON  2
908 -#define DMASND_AMIGA   3
909 -#define DMASND_AWACS   4
910 -#define DMASND_IRIS    5
911 -#define DMASND_COLLIE  6
912  
913 -#define COLLIE_WAIT_AMP_ON     1       /* 10ms */
914 +
915  #define COLLIE_WAIT_LCM_ACC_XEN        50      /* 500ms */
916 -#ifdef MODULE
917 -static int catchRadius = 0;
918 -#endif
919 +
920  static int collie_amp_init = 0;
921  static int collie_dac_init = 0;
922 -static int collie_op_shdn_on = 0;
923  static int collie_resume = 0;
924  static int collie_hard_mute = 1;
925  static int collie_soft_mute = 1;
926  static int collie_volume = 0;
927 +int collie_recording=0;
928 +static int playing=0;
929 +static int headphone;
930  
931 -int collie_buzzer_volume = 0;
932 -
933 -#if 1
934 -static DECLARE_WAIT_QUEUE_HEAD(open_queue);
935 +#define AUDIO_NBFRAGS_DEFAULT   64
936 +#define AUDIO_FRAGSIZE_DEFAULT  4096
937  
938 -#define SIGNAL_RECEIVED        (signal_pending(current))
939 -#define ONE_SECOND     HZ      /* in jiffies (100ths of a second) */
940 -#define SLEEP(queue, time_limit) \
941 -       interruptible_sleep_on_timeout((wait_queue_head_t*)&queue, (time_limit));
942 -#define WAKE_UP(queue) (wake_up_interruptible((wait_queue_head_t*)&queue))
943 -#endif
944 -
945 -#define AUDIO_NBFRAGS_DEFAULT   8
946 -#define AUDIO_FRAGSIZE_DEFAULT  8192
947 -
948 -
949 -#define TRACE 0
950 -#if TRACE
951 -#define TRACE_ON       1
952 -#define TRACE_SEM      0
953 -#define        TRACE_SENDDATA  0
954 -#define        TRACE_PM        1
955 -#define TRACE_AMP      1
956 -#define TRACE_DAC      1
957 -#define TRACE_OP_SHDN  1
958 -#define TRACE_WRITE    1
959 -#define TRACE_MUTE     1
960 -#define TRACE_CLOCK    1
961 -#define TRACE_PAIF     1
962 -#define TRACE_SSP      1
963 -#define TRACE_VOLUME   1
964 -#define TRACE_MIC      1
965 -#define TRACE_INTERRUPT        0
966 -int    cLevel = 0;
967 -char   *pLevel[16] = {
968 -       /*  0 */"",
969 -       /*  1 */" ",
970 -       /*  2 */"  ",
971 -       /*  3 */"   ",
972 -       /*  4 */"    ",
973 -       /*  5 */"     ",
974 -       /*  6 */"      ",
975 -       /*  7 */"       ",
976 -       /*  8 */"        ",
977 -       /*  9 */"         ",
978 -       /* 10 */"          ",
979 -       /* 11 */"           ",
980 -       /* 12 */"            ",
981 -       /* 13 */"             ",
982 -       /* 14 */"              ",
983 -       /* 15 */"               "
984 -};
985 -char *
986 -indent(int level)
987 -{
988 -  int  i;
989 -  return (level < 16 ) ? pLevel[level] : pLevel[15];
990 -}
991 -
992 -#define        P_ID    (current->tgid)
993 -#define        ENTER(f,fn)     {if(f)printk("%d:%s+[%d]%s\n",jiffies,indent(cLevel),P_ID,(fn));cLevel++;}
994 -#define LEAVE(f,fn)    {cLevel--;if(f>1)printk("%d:%s-[%d]%s\n",jiffies,indent(cLevel),P_ID,(fn));}
995 -#else  /* ! TRACE */
996 -#define        ENTER(f,fn)
997 -#define LEAVE(f,fn)
998 -#endif /* end TRACE */
999  
1000 -/*
1001 - * DAC power management
1002 - */
1003 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0) || \
1004 -    defined(CONFIG_COLLIE_TR1) || defined(CONFIG_COLLIE_DEV)
1005 -#define        DAC_OFF_WITH_DEVICE_OFF         1
1006 -#undef HARD_MUTE_CTRL_DISABLE          
1007 -#else
1008 -#undef DAC_OFF_WITH_DEVICE_OFF
1009  #undef HARD_MUTE_CTRL_DISABLE          
1010 -#endif
1011 -
1012 -
1013 -#define TRY_DELAY_OFF
1014 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP 2001.12.19 */
1015 -static DECLARE_WAIT_QUEUE_HEAD(delay_off);
1016 -struct semaphore df_sem;
1017 -/*
1018 - * delay execution
1019 - */
1020 -static unsigned int    DelayedFlag = 0;
1021 -#define DELAY_DAC_OFF          0x1
1022 -#define DELAY_HARD_MUTE_ON     0x2
1023 -
1024 -static inline void ResetDelayAll(void)
1025 -{
1026 -       DelayedFlag = 0;
1027 -}
1028 -
1029 -static inline int isDelayedExist(void)
1030 -{
1031 -       return DelayedFlag;
1032 -}
1033 -
1034 -static inline void SetDelay(unsigned int flag)
1035 -{
1036 -       DelayedFlag |= flag;
1037 -}
1038 -
1039 -static inline void ResetDelay(unsigned int flag)
1040 -{
1041 -       DelayedFlag &= ~flag;
1042 -}
1043 -
1044 -static inline unsigned int isDelayed(unsigned int flag)
1045 -{
1046 -       return DelayedFlag & flag;
1047 -}
1048 -#endif
1049  
1050  /*
1051   * Buffer Management
1052 @@ -268,6 +153,7 @@
1053         dma_addr_t dma_addr;    /* physical buffer address */
1054         struct semaphore sem;   /* down before touching the buffer */
1055         int master;             /* master owner for buffer allocation */
1056 +       u_int idx;              /* buffer index, so that we know which buffer was sent last*/
1057  } audio_buf_t;
1058  
1059  typedef struct {
1060 @@ -291,16 +177,6 @@
1061  
1062  static volatile int audio_wr_refcount; /* nbr of concurrent open() for playback */
1063  
1064 -static ssize_t (*ct_func)(const u_char *, size_t, u_char *, ssize_t *, ssize_t) = NULL;
1065 -
1066 -#ifdef MODULE
1067 -MODULE_PARM(catchRadius, "i");
1068 -#endif
1069 -MODULE_PARM(numBufs, "i");
1070 -MODULE_PARM(bufSize, "i");
1071 -
1072 -#define min(x, y)      ((x) < (y) ? (x) : (y))
1073 -
1074  #define IOCTL_IN(arg, ret) \
1075         do { int error = get_user(ret, (int *)(arg)); \
1076                 if (error) return error; \
1077 @@ -310,11 +186,7 @@
1078  /*
1079   * SA1110 GPIO (17)
1080   */
1081 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
1082 -#define COLLIE_GPIO_OPSHDN     GPIO_GPIO (17)  /* AMP contorol        */
1083 -#else  /* !CONFIG_COLLIE_TS && !CONFIG_COLLIE_TR0 */
1084  #define COLLIE_GPIO_MIC                GPIO_GPIO (17)  /* MIC contorol        */
1085 -#endif /* !CONFIG_COLLIE_TS && !CONFIG_COLLIE_TR0 */
1086  
1087  /*
1088   * DAC setup data
1089 @@ -352,122 +224,11 @@
1090                 ( LCM_ACC_XSEL1 | LCM_ACC_CLKSEL101 ) ,
1091  };
1092  
1093 +/*** "Translations" ************************************************************/
1094  
1095 -/* 16 bit mu-law */
1096 -
1097 -static short ulaw2dma16[] = {
1098 -       -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
1099 -       -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
1100 -       -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
1101 -       -11900, -11388, -10876, -10364, -9852,  -9340,  -8828,  -8316,
1102 -       -7932,  -7676,  -7420,  -7164,  -6908,  -6652,  -6396,  -6140,
1103 -       -5884,  -5628,  -5372,  -5116,  -4860,  -4604,  -4348,  -4092,
1104 -       -3900,  -3772,  -3644,  -3516,  -3388,  -3260,  -3132,  -3004,
1105 -       -2876,  -2748,  -2620,  -2492,  -2364,  -2236,  -2108,  -1980,
1106 -       -1884,  -1820,  -1756,  -1692,  -1628,  -1564,  -1500,  -1436,
1107 -       -1372,  -1308,  -1244,  -1180,  -1116,  -1052,  -988,   -924,
1108 -       -876,   -844,   -812,   -780,   -748,   -716,   -684,   -652,
1109 -       -620,   -588,   -556,   -524,   -492,   -460,   -428,   -396,
1110 -       -372,   -356,   -340,   -324,   -308,   -292,   -276,   -260,
1111 -       -244,   -228,   -212,   -196,   -180,   -164,   -148,   -132,
1112 -       -120,   -112,   -104,   -96,    -88,    -80,    -72,    -64,
1113 -       -56,    -48,    -40,    -32,    -24,    -16,    -8,     0,
1114 -       32124,  31100,  30076,  29052,  28028,  27004,  25980,  24956,
1115 -       23932,  22908,  21884,  20860,  19836,  18812,  17788,  16764,
1116 -       15996,  15484,  14972,  14460,  13948,  13436,  12924,  12412,
1117 -       11900,  11388,  10876,  10364,  9852,   9340,   8828,   8316,
1118 -       7932,   7676,   7420,   7164,   6908,   6652,   6396,   6140,
1119 -       5884,   5628,   5372,   5116,   4860,   4604,   4348,   4092,
1120 -       3900,   3772,   3644,   3516,   3388,   3260,   3132,   3004,
1121 -       2876,   2748,   2620,   2492,   2364,   2236,   2108,   1980,
1122 -       1884,   1820,   1756,   1692,   1628,   1564,   1500,   1436,
1123 -       1372,   1308,   1244,   1180,   1116,   1052,   988,    924,
1124 -       876,    844,    812,    780,    748,    716,    684,    652,
1125 -       620,    588,    556,    524,    492,    460,    428,    396,
1126 -       372,    356,    340,    324,    308,    292,    276,    260,
1127 -       244,    228,    212,    196,    180,    164,    148,    132,
1128 -       120,    112,    104,    96,     88,     80,     72,     64,
1129 -       56,     48,     40,     32,     24,     16,     8,      0,
1130 -};
1131 -
1132 -/* 16 bit A-law */
1133 -
1134 -static short alaw2dma16[] = {
1135 -       -5504,  -5248,  -6016,  -5760,  -4480,  -4224,  -4992,  -4736,
1136 -       -7552,  -7296,  -8064,  -7808,  -6528,  -6272,  -7040,  -6784,
1137 -       -2752,  -2624,  -3008,  -2880,  -2240,  -2112,  -2496,  -2368,
1138 -       -3776,  -3648,  -4032,  -3904,  -3264,  -3136,  -3520,  -3392,
1139 -       -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944,
1140 -       -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136,
1141 -       -11008, -10496, -12032, -11520, -8960,  -8448,  -9984,  -9472,
1142 -       -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568,
1143 -       -344,   -328,   -376,   -360,   -280,   -264,   -312,   -296,
1144 -       -472,   -456,   -504,   -488,   -408,   -392,   -440,   -424,
1145 -       -88,    -72,    -120,   -104,   -24,    -8,     -56,    -40,
1146 -       -216,   -200,   -248,   -232,   -152,   -136,   -184,   -168,
1147 -       -1376,  -1312,  -1504,  -1440,  -1120,  -1056,  -1248,  -1184,
1148 -       -1888,  -1824,  -2016,  -1952,  -1632,  -1568,  -1760,  -1696,
1149 -       -688,   -656,   -752,   -720,   -560,   -528,   -624,   -592,
1150 -       -944,   -912,   -1008,  -976,   -816,   -784,   -880,   -848,
1151 -       5504,   5248,   6016,   5760,   4480,   4224,   4992,   4736,
1152 -       7552,   7296,   8064,   7808,   6528,   6272,   7040,   6784,
1153 -       2752,   2624,   3008,   2880,   2240,   2112,   2496,   2368,
1154 -       3776,   3648,   4032,   3904,   3264,   3136,   3520,   3392,
1155 -       22016,  20992,  24064,  23040,  17920,  16896,  19968,  18944,
1156 -       30208,  29184,  32256,  31232,  26112,  25088,  28160,  27136,
1157 -       11008,  10496,  12032,  11520,  8960,   8448,   9984,   9472,
1158 -       15104,  14592,  16128,  15616,  13056,  12544,  14080,  13568,
1159 -       344,    328,    376,    360,    280,    264,    312,    296,
1160 -       472,    456,    504,    488,    408,    392,    440,    424,
1161 -       88,     72,     120,    104,    24,     8,      56,     40,
1162 -       216,    200,    248,    232,    152,    136,    184,    168,
1163 -       1376,   1312,   1504,   1440,   1120,   1056,   1248,   1184,
1164 -       1888,   1824,   2016,   1952,   1632,   1568,   1760,   1696,
1165 -       688,    656,    752,    720,    560,    528,    624,    592,
1166 -       944,    912,    1008,   976,    816,    784,    880,    848,
1167 -};
1168 -
1169 -
1170 -
1171 -/*** Translations ************************************************************/
1172 -
1173 -static ssize_t collie_ct_law(const u_char *userPtr, size_t userCount,
1174 -                            u_char frame[], ssize_t *frameUsed,
1175 -                            ssize_t frameLeft);
1176 -static ssize_t collie_ct_s8(const u_char *userPtr, size_t userCount,
1177 -                           u_char frame[], ssize_t *frameUsed,
1178 -                           ssize_t frameLeft);
1179 -static ssize_t collie_ct_u8(const u_char *userPtr, size_t userCount,
1180 -                           u_char frame[], ssize_t *frameUsed,
1181 -                           ssize_t frameLeft);
1182  static ssize_t collie_ct_s16(const u_char *userPtr, size_t userCount,
1183                              u_char frame[], ssize_t *frameUsed,
1184                              ssize_t frameLeft);
1185 -static ssize_t collie_ct_u16(const u_char *userPtr, size_t userCount,
1186 -                            u_char frame[], ssize_t *frameUsed,
1187 -                            ssize_t frameLeft);
1188 -
1189 -/*** Machine definitions *****************************************************/
1190 -
1191 -
1192 -typedef struct {
1193 -       int type;
1194 -       void *(*dma_alloc)(unsigned int, int);
1195 -       void (*dma_free)(void *, unsigned int);
1196 -       int (*irqinit)(void);
1197 -#ifdef MODULE
1198 -       void (*irqcleanup)(void);
1199 -#endif /* MODULE */
1200 -       void (*init)(void);
1201 -       void (*silence)(void);
1202 -       int (*setFormat)(int);
1203 -       int (*setVolume)(int);
1204 -       int (*setBass)(int);
1205 -       int (*setTreble)(int);
1206 -       int (*setGain)(int);
1207 -       void (*play)(void);
1208 -} MACHINE;
1209 -
1210  
1211  /*** Low level stuff *********************************************************/
1212  
1213 @@ -477,71 +238,28 @@
1214         int stereo;             /* 0 = mono, 1 = stereo */
1215         int size;               /* 8/16 bit*/
1216         int speed;              /* speed */
1217 +       int volume;
1218  } SETTINGS;
1219  
1220 -typedef struct {
1221 -       ssize_t (*ct_ulaw)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
1222 -       ssize_t (*ct_alaw)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
1223 -       ssize_t (*ct_s8)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
1224 -       ssize_t (*ct_u8)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
1225 -       ssize_t (*ct_s16be)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
1226 -       ssize_t (*ct_u16be)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
1227 -       ssize_t (*ct_s16le)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
1228 -       ssize_t (*ct_u16le)(const u_char *, size_t, u_char *, ssize_t *, ssize_t);
1229 -} TRANS;
1230 -
1231 -struct sound_settings {
1232 -       MACHINE mach;           /* machine dependent things */
1233 -       SETTINGS hard;          /* hardware settings */
1234 -       SETTINGS soft;          /* software settings */
1235 -       SETTINGS dsp;           /* /dev/dsp default settings */
1236 -       TRANS *trans;           /* supported translations */
1237 -       int volume_left;        /* volume (range is machine dependent) */
1238 -       int volume_right;
1239 -       int bass;               /* tone (range is machine dependent) */
1240 -       int treble;
1241 -       int gain;
1242 -       int minDev;             /* minor device number currently open */
1243 -};
1244 -
1245 -static struct sound_settings sound;
1246 +static SETTINGS sound;
1247  
1248  #ifdef CONFIG_PM
1249 -extern int autoPowerCancel;
1250 +//extern int autoPowerCancel;
1251  #endif
1252 -int collie_main_volume;
1253 -extern int collie_under_recording;      /* collie_buzzer.c */
1254 -#define COLLE_RECORDING        (collie_under_recording)
1255  
1256  static void Collie_Set_Volume(int volume);
1257  static int Collie_Get_Volume(void);
1258 -static void Collie_disable_sound(void);
1259 -#ifdef CONFIG_PM
1260 -#if 0
1261 -static void Collie_clock_stop(void);
1262 -static void Collie_FS8KLPF_stop(void);
1263 -#endif
1264 -#endif
1265  static int CollieIrqInit(void);
1266  static int CollieGetSamp(void);
1267 -static void Collie_OP_SHDN_on(void);
1268 -static void Collie_OP_SHDN_off(void);
1269 -static void Collie_FS8KLPF_start(void);
1270 -#ifdef MODULE
1271 -static void CollieIrqCleanUp(void);
1272 -#endif /* MODULE */
1273 -static void CollieSilence(void);
1274  static void Collie_DAC_sendword(int);
1275 -static void CollieInit(void);
1276  static int CollieSetFormat(int format);
1277  static void Collie_sq_interrupt(void*, int);
1278  static int sq_allocate_buffers(audio_stream_t*);
1279  static void sq_release_buffers(audio_stream_t*);
1280 +static inline void Collie_volume_init(void);
1281 +static void Collie_volume_set(int);
1282  
1283  /*** Mid level stuff *********************************************************/
1284 -static void sound_silence(void);
1285 -static void sound_init(void);
1286 -static int sound_set_format(int format);
1287  static int sound_set_speed(int speed);
1288  static int sound_set_stereo(int stereo);
1289  
1290 @@ -572,468 +290,122 @@
1291  static long long sound_lseek(struct file *file, long long offset, int orig);
1292  static inline int ioctl_return(int *addr, int value)
1293  {
1294 -       ENTER(TRACE_ON,"ioctl_return");
1295         if (value < 0) {
1296 -               LEAVE(TRACE_ON,"ioctl_return");
1297                 return(value);
1298         }
1299 -
1300 -       LEAVE(TRACE_ON,"ioctl_return");
1301         return put_user(value, addr)? -EFAULT: 0;
1302  }
1303  
1304 -
1305 -/*** Config & Setup **********************************************************/
1306 -
1307 -
1308 -void dmasound_init(void);
1309 -void dmasound_setup(char *str, int *ints);
1310 -
1311 -
1312 -/*** Translations ************************************************************/
1313 -
1314 -
1315 -/* ++TeSche: radically changed for new expanding purposes...
1316 - *
1317 - * These two routines now deal with copying/expanding/translating the samples
1318 - * from user space into our buffer at the right frequency. They take care about
1319 - * how much data there's actually to read, how much buffer space there is and
1320 - * to convert samples into the right frequency/encoding. They will only work on
1321 - * complete samples so it may happen they leave some bytes in the input stream
1322 - * if the user didn't write a multiple of the current sample size. They both
1323 - * return the number of bytes they've used from both streams so you may detect
1324 - * such a situation. Luckily all programs should be able to cope with that.
1325 - *
1326 - * I think I've optimized anything as far as one can do in plain C, all
1327 - * variables should fit in registers and the loops are really short. There's
1328 - * one loop for every possible situation. Writing a more generalized and thus
1329 - * parameterized loop would only produce slower code. Feel free to optimize
1330 - * this in assembler if you like. :)
1331 - *
1332 - * I think these routines belong here because they're not yet really hardware
1333 - * independent, especially the fact that the Falcon can play 16bit samples
1334 - * only in stereo is hardcoded in both of them!
1335 - *
1336 - * ++geert: split in even more functions (one per format)
1337 - */
1338 -
1339 -static ssize_t collie_ct_law(const u_char *userPtr, size_t userCount,
1340 -                            u_char frame[], ssize_t *frameUsed,
1341 -                            ssize_t frameLeft)
1342 -{
1343 -       short *table = sound.soft.format == AFMT_MU_LAW ? ulaw2dma16: alaw2dma16;
1344 -       ssize_t count, used;
1345 -       short *p = (short *) &frame[*frameUsed];
1346 -       int val, stereo = sound.soft.stereo;
1347 -
1348 -       ENTER(TRACE_ON,"collie_ct_law");
1349 -       frameLeft >>= 2;
1350 -       if (stereo)
1351 -               userCount >>= 1;
1352 -       used = count = min(userCount, frameLeft);
1353 -       if (!COLLE_RECORDING) {
1354 -               while (count > 0) {
1355 -                       u_char data;
1356 -                       if (get_user(data, userPtr++)) {
1357 -                               LEAVE(TRACE_ON,"collie_ct_law");
1358 -                               return -EFAULT;
1359 -                       }
1360 -                       val = table[data];
1361 -                       *p++ = val;             /* Left Ch. */
1362 -                       if (stereo) {
1363 -                               if (get_user(data, userPtr++)) {
1364 -                               LEAVE(TRACE_ON,"collie_ct_law");
1365 -                               return -EFAULT;
1366 -                               }
1367 -                               val = table[data];
1368 -                       }
1369 -                       *p++ = val;             /* Right Ch. */
1370 -                       count--;
1371 -               }
1372 -       } else {
1373 -               while (count > 0) {
1374 -                       u_char data;
1375 -                       int ave;
1376 -                       if (get_user(data, userPtr++)) {
1377 -                               LEAVE(TRACE_ON,"collie_ct_law");
1378 -                               return -EFAULT;
1379 -                       }
1380 -                       val = table[data];
1381 -                       ave = val;              /* Left Ch. */
1382 -                       if (stereo) {
1383 -                               if (get_user(data, userPtr++)) {
1384 -                                       LEAVE(TRACE_ON,"collie_ct_law");
1385 -                                       return -EFAULT;
1386 -                               }
1387 -                               val = table[data];
1388 -                       }
1389 -                       ave += val;             /* Right Ch. */
1390 -                       ave >>= 1;
1391 -                       *p++ = 0;               /* Left Ch. */
1392 -                       *p++ = ave;             /* Right Ch. */
1393 -                       count--;
1394 -               }
1395 -       }
1396 -       *frameUsed += used * 4;
1397 -       LEAVE(TRACE_ON,"collie_ct_law");
1398 -       return stereo? used * 2: used;
1399 -}
1400 -
1401 -
1402 -static ssize_t collie_ct_s8(const u_char *userPtr, size_t userCount,
1403 -                         u_char frame[], ssize_t *frameUsed,
1404 -                         ssize_t frameLeft)
1405 -{
1406 -       ssize_t count, used;
1407 -       short *p = (short *) &frame[*frameUsed];
1408 -       int stereo = sound.soft.stereo;
1409 -       short val;
1410 -
1411 -       ENTER(TRACE_ON,"collie_ct_s8");
1412 -       frameLeft >>= 2;
1413 -       if (stereo)
1414 -               userCount >>= 1;
1415 -       used = count = min(userCount, frameLeft);
1416 -       if (!COLLE_RECORDING) {
1417 -               while (count > 0) {
1418 -                       u_char data;
1419 -
1420 -                       if (get_user(data, userPtr++)) {
1421 -                               LEAVE(TRACE_ON,"collie_ct_s8");
1422 -                               return -EFAULT;
1423 -                       }
1424 -                       val = ( data - 0x80 ) << 8;
1425 -                       *p++ = val;             /* Left Ch. */
1426 -                       if ( stereo ) {
1427 -                               if ( get_user(data, userPtr++)) {
1428 -                                       LEAVE(TRACE_ON,"collie_ct_s8");
1429 -                                       return -EFAULT;
1430 -                               }
1431 -                               val = ( data - 0x80 ) << 8;
1432 -                       }
1433 -                       *p++ = val;             /* Right Ch. */
1434 -                       count--;
1435 -               }
1436 -       } else {
1437 -               while (count > 0) {
1438 -                       u_char data;
1439 -                       int ave;
1440 -
1441 -                       if (get_user(data, userPtr++)) {
1442 -                               LEAVE(TRACE_ON,"collie_ct_s8");
1443 -                               return -EFAULT;
1444 -                       }
1445 -                       val = ( data - 0x80 ) << 8;
1446 -                       ave = val;              /* Left Ch. */
1447 -                       if ( stereo ) {
1448 -                               if ( get_user(data, userPtr++)) {
1449 -                                       LEAVE(TRACE_ON,"collie_ct_s8");
1450 -                                       return -EFAULT;
1451 -                               }
1452 -                               val = ( data - 0x80 ) << 8;
1453 -                       }
1454 -                       ave += val;             /* Right Ch. */
1455 -                       ave >>= 1;
1456 -                       *p++ = 0;               /* Left Ch. */
1457 -                       *p++ = ave;             /* Right Ch. */
1458 -                       count--;
1459 -               }
1460 -       }
1461 -       *frameUsed += used * 4;
1462 -       LEAVE(TRACE_ON,"collie_ct_s8");
1463 -       return stereo? used * 2: used;
1464 -}
1465 -
1466 -
1467 -static ssize_t collie_ct_u8(const u_char *userPtr, size_t userCount,
1468 -                         u_char frame[], ssize_t *frameUsed,
1469 -                         ssize_t frameLeft)
1470 +static void wait_ms(int ten_ms)
1471  {
1472 -       ssize_t count, used;
1473 -       short *p = (short *) &frame[*frameUsed];
1474 -       int stereo = sound.soft.stereo;
1475 -       short val;
1476 -
1477 -       ENTER(TRACE_ON,"collie_ct_u8");
1478 -       frameLeft >>= 2;
1479 -       if (stereo)
1480 -               userCount >>= 1;
1481 -       used = count = min(userCount, frameLeft);
1482 -       if (!COLLE_RECORDING) {
1483 -               while (count > 0) {
1484 -                       u_char data;
1485 -
1486 -                       if (get_user(data, userPtr++)) {
1487 -                               LEAVE(TRACE_ON,"collie_ct_u8");
1488 -                               return -EFAULT;
1489 -                       }
1490 -                       val = data;
1491 -                       *p++ = (val ^ 0x80) << 8;               /* Left Ch. */
1492 -                       if ( stereo ) {
1493 -                               if ( get_user(data, userPtr++)) {
1494 -                                       LEAVE(TRACE_ON,"collie_ct_u8");
1495 -                                       return -EFAULT;
1496 -                               }
1497 -                               val = data;
1498 -                       }
1499 -                       *p++ = (val ^ 0x80) << 8;               /* Right Ch. */
1500 -                       count--;
1501 -               }
1502 -       } else {
1503 -               while (count > 0) {
1504 -                       u_char data;
1505 -                       int ave;
1506 -
1507 -                       if (get_user(data, userPtr++)) {
1508 -                               LEAVE(TRACE_ON,"collie_ct_u8");
1509 -                               return -EFAULT;
1510 -                       }
1511 -                       val = data;
1512 -                       ave = (val ^ 0x80) << 8;                /* Left Ch. */
1513 -                       if ( stereo ) {
1514 -                               if ( get_user(data, userPtr++)) {
1515 -                                       LEAVE(TRACE_ON,"collie_ct_u8");
1516 -                                       return -EFAULT;
1517 -                               }
1518 -                               val = data;
1519 -                       }
1520 -                       ave += (val ^ 0x80) << 8;               /* Right Ch. */
1521 -                       ave >>= 1;
1522 -                       *p++ = 0;                       /* Left Ch. */
1523 -                       *p++ = ave;                     /* Right Ch. */
1524 -                       count--;
1525 -               }
1526 -       }
1527 -       *frameUsed += used * 4;
1528 -       LEAVE(TRACE_ON,"collie_ct_u8");
1529 -       return stereo? used * 2: used;
1530 +       schedule_timeout(ten_ms);
1531  }
1532  
1533 +/*** Translation ************************************************************/
1534  
1535  static ssize_t collie_ct_s16(const u_char *userPtr, size_t userCount,
1536                            u_char frame[], ssize_t *frameUsed,
1537                            ssize_t frameLeft)
1538  {
1539         ssize_t count, used;
1540 -       int stereo = sound.soft.stereo;
1541         short *fp = (short *) &frame[*frameUsed];
1542 +       short *up = (short *) userPtr;
1543  
1544 -       ENTER(TRACE_ON,"collie_ct_s16");
1545         frameLeft >>= 2;
1546 -       userCount >>= (stereo? 2: 1);
1547 -       used = count = min(userCount, frameLeft);
1548 -       if (!stereo) {
1549 -               short *up = (short *) userPtr;
1550 -               while (count > 0) {
1551 -                       short data;
1552 -                       if (get_user(data, up++)) {
1553 -                               LEAVE(TRACE_ON,"collie_ct_s16");
1554 -                               return -EFAULT;
1555 -                       }
1556 -                       *fp++ = (!COLLE_RECORDING) ? data : 0;  /* Left Ch. */
1557 -                       *fp++ = data;
1558 -                       count--;
1559 +       userCount >>= 2;
1560 +       used = count = (userCount < frameLeft) ? userCount : frameLeft;
1561 +       
1562 +       while (count > 0) {
1563 +
1564 +               short data;
1565 +               if (get_user(data, up++)) {
1566 +                       return -EFAULT;
1567                 }
1568 -       } else {
1569 -               short *up = (short *) userPtr;
1570 -               while (count > 0) {
1571 -                       short data;
1572 -                       short temp;
1573 -                       if (get_user(data, up++)) {
1574 -                               LEAVE(TRACE_ON,"collie_ct_s16");
1575 -                               return -EFAULT;
1576 -                       }
1577 -                       if (get_user(temp, up++)) {
1578 -                               LEAVE(TRACE_ON,"collie_ct_s16");
1579 -                               return -EFAULT;
1580 -                       }
1581 -                       if (!COLLE_RECORDING) {
1582 -                               *fp++ = data;           /* Left Ch. */
1583 -                               *fp++ = temp;           /* Right Ch. */
1584 -                       } else {
1585 -                               data >>= 1;
1586 -                               data += (temp >> 1);
1587 -                               *fp++ = 0;              /* Left Ch. */
1588 -                               *fp++ = data;           /* Right Ch. */
1589 -                       }
1590 -                       count--;
1591 +               if (!collie_recording) *fp++ = data;            
1592 +               else *fp++=0;
1593 +               
1594 +               if (get_user(data, up++)) {
1595 +                       return -EFAULT;
1596                 }
1597 +               *fp++ = data;           
1598 +               count--;
1599         }
1600 +       
1601         *frameUsed += used * 4;
1602 -       LEAVE(TRACE_ON,"collie_ct_s16");
1603 -       return stereo? used * 4: used * 2;
1604 +       return used * 4;
1605  }
1606  
1607 -static ssize_t collie_ct_u16(const u_char *userPtr, size_t userCount,
1608 -                          u_char frame[], ssize_t *frameUsed,
1609 -                          ssize_t frameLeft)
1610 -{
1611 -       ssize_t count, used;
1612 -       int mask = (sound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
1613 -       int stereo = sound.soft.stereo;
1614 -       short *fp = (short *) &frame[*frameUsed];
1615 -       short *up = (short *) userPtr;
1616 +/*** HARDWARE dependent stuff *********************************************************/
1617  
1618 -       ENTER(TRACE_ON,"collie_ct_u16");
1619 -       frameLeft >>= 2;
1620 -       userCount >>= (stereo? 2: 1);
1621 -       used = count = min(userCount, frameLeft);
1622 -       if (!COLLE_RECORDING) {
1623 -               while (count > 0) {
1624 -                       int data;
1625 -                       int temp;
1626 -                       if (get_user(data, up++)) {
1627 -                               LEAVE(TRACE_ON,"collie_ct_u16");
1628 -                               return -EFAULT;
1629 -                       }
1630 -                       data ^= mask;
1631 -                       *fp++ = data;                   /* Left Ch. */
1632 -                       if (stereo) {
1633 -                               if (get_user(temp, up++)) {
1634 -                                       LEAVE(TRACE_ON,"collie_ct_u16");
1635 -                                       return -EFAULT;
1636 -                               }
1637 -                               temp ^= mask;
1638 -                               data  = temp;
1639 -                               data ^= mask;
1640 -                       }
1641 -                       *fp++ = data;                   /* Right Ch. */
1642 -                       count--;
1643 -               }
1644 +static inline void Collie_DAC_sendbit(int bit_data)
1645 +{
1646 +       if (bit_data & 1) {
1647 +               LCM_GPO |=  (LCM_GPIO_DAC_SDATA);
1648         } else {
1649 -               while (count > 0) {
1650 -                       int data;
1651 -                       int temp;
1652 -                       int ave;
1653 -                       if (get_user(data, up++)) {
1654 -                               LEAVE(TRACE_ON,"collie_ct_u16");
1655 -                               return -EFAULT;
1656 -                       }
1657 -                       data ^= mask;
1658 -                       ave = data;                     /* Left Ch. */
1659 -                       if (stereo) {
1660 -                               if (get_user(temp, up++)) {
1661 -                                       LEAVE(TRACE_ON,"collie_ct_u16");
1662 -                                       return -EFAULT;
1663 -                               }
1664 -                               temp ^= mask;
1665 -                               data  = temp;
1666 -                               data ^= mask;
1667 -                       }
1668 -                       ave += data;
1669 -                       ave >>= 1;
1670 -                       *fp++ = 0;                      /* Left Ch. */
1671 -                       *fp++ = ave;                    /* Right Ch. */
1672 -                       count--;
1673 -               }
1674 +               LCM_GPO &= ~(LCM_GPIO_DAC_SDATA);
1675         }
1676 -       *frameUsed += used * 4;
1677 -       LEAVE(TRACE_ON,"collie_ct_u16");
1678 -       return stereo? used * 4: used * 2;
1679 -}
1680  
1681 -static TRANS transCollie = {
1682 -       collie_ct_law, collie_ct_law, collie_ct_s8, collie_ct_u8,
1683 -       collie_ct_s16, collie_ct_u16, collie_ct_s16, collie_ct_u16
1684 -};
1685 +       udelay(1);
1686 +       LCM_GPO |=  (LCM_GPIO_DAC_SCK);
1687  
1688 -/*** Low level stuff *********************************************************/
1689 +       udelay(1);
1690 +       LCM_GPO &= ~(LCM_GPIO_DAC_SCK);
1691 +       udelay(1);
1692 +       LCM_GPO &= ~(LCM_GPIO_DAC_SDATA);
1693 +       udelay(1);
1694 +}
1695  
1696 -static void Collie_Set_Volume(int volume)
1697 +static void Collie_DAC_sendword(int data)
1698  {
1699 -       ENTER(TRACE_ON,"Collie_Set_Volume");
1700 -
1701 -       sound.volume_left = volume & 0xff;
1702 -       if ( sound.volume_left > 100 ) sound.volume_left = 100;
1703 -
1704 -       collie_main_volume = sound.volume_left;
1705 -
1706 -       sound.volume_right = ( volume & 0xff00 >> 8);
1707 -       if ( sound.volume_right > 100 ) sound.volume_right = 100;
1708 -       LEAVE(TRACE_ON,"Collie_Set_Volume");
1709 +       int i;
1710  
1711 -       collie_buzzer_volume = sound.volume_right;
1712 +#if defined(CONFIG_COLLIE_PCM1741)
1713 +       
1714 +       LCM_GPO &= ~(LCM_GPIO_DAC_SCK);
1715 +       udelay(1);
1716 +       LCM_GPO |=  (LCM_GPIO_DAC_SLOAD);
1717 +       udelay(1);
1718  
1719 -}
1720 +       for (i = 0; i < 16; i++)
1721 +               Collie_DAC_sendbit(data >> (15 - i));
1722  
1723 +       LCM_GPO &= ~(LCM_GPIO_DAC_SLOAD);
1724 +       udelay(2);
1725  
1726 -static int Collie_Get_Volume(void)
1727 -{
1728 -       ENTER(TRACE_ON,"Collie_Get_Volume");
1729 -       LEAVE(TRACE_ON,"Collie_Get_Volume");
1730 -       return ( sound.volume_right << 8 | sound.volume_left );
1731 -}
1732 +#elif defined(CONFIG_COLLIE_PCM1717)
1733 +       
1734 +       LCM_GPO &= ~(LCM_GPIO_DAC_SLOAD);
1735 +       udelay(1000);
1736 +       LCM_GPO |=  (LCM_GPIO_DAC_SLOAD);
1737 +       udelay(1000);
1738 +       LCM_GPO &= ~(LCM_GPIO_DAC_SCK);
1739 +       udelay(1000);
1740  
1741 -static void wait_ms(int ten_ms)
1742 -{
1743 -       ENTER(TRACE_ON,"wait_ms");
1744 -       LEAVE(TRACE_ON,"wait_ms");
1745 -       schedule_timeout(ten_ms);
1746 -}
1747 +       for (i = 0; i < 16; i++)
1748 +               Collie_DAC_sendbit(data >> (15 - i));
1749  
1750 -static inline void Collie_AMP_off(void)
1751 -{
1752 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
1753 -       ENTER(TRACE_AMP,"Collie_AMP_off");
1754 -#if 0  /* OBSOLETED: power controled by only OP_SHDN */
1755 -       /* Set up TC35143 GPIO I/O Direction (GPIO4 output mode) */
1756 -       ucb1200_set_io_direction(TC35143_GPIO_AMP_ON,
1757 -                                TC35143_IODIR_OUTPUT);
1758 -       /* AMP OFF */
1759 -       ucb1200_set_io(TC35143_GPIO_AMP_ON,
1760 -                      TC35143_IODAT_LOW);
1761 -       collie_amp_init = 0;
1762 -#endif /* 0 */
1763 -       LEAVE(TRACE_AMP,"Collie_AMP_off");
1764 -#endif /* CONFIG_COLLIE_TS || CONFIG_COLLIE_TR0 */
1765 -}
1766 -
1767 -static inline void Collie_AMP_on(void)
1768 -{
1769 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
1770 -       ENTER(TRACE_AMP,"Collie_AMP_on");
1771 -//     if (!collie_amp_init) {
1772 -               /* Set up TC35143 GPIO I/O Direction (GPIO4 output mode) */
1773 -               ucb1200_set_io_direction(TC35143_GPIO_AMP_ON,
1774 -                                        TC35143_IODIR_OUTPUT);
1775 -               /* AMP ON */
1776 -               ucb1200_set_io(TC35143_GPIO_AMP_ON, TC35143_IODAT_HIGH);
1777 -               SCP_REG_GPWR |= SCP_AMP_ON;
1778 -               wait_ms(COLLIE_WAIT_AMP_ON);
1779 -               collie_amp_init = 1;
1780 -//     }
1781 -       LEAVE(TRACE_AMP,"Collie_AMP_on");
1782 -#endif /* CONFIG_COLLIE_TS || CONFIG_COLLIE_TR0 */
1783 +       LCM_GPO &= ~(LCM_GPIO_DAC_SLOAD);
1784 +       udelay(1000);
1785 +       LCM_GPO |=  (LCM_GPIO_DAC_SLOAD);
1786 +       udelay(1000);
1787 +       LCM_GPO &= ~(LCM_GPIO_DAC_SLOAD);
1788 +       udelay(1000);
1789 +#endif
1790  }
1791  
1792 -static inline void Collie_AMP_init(void)
1793 -{
1794 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
1795 -       ENTER(TRACE_AMP,"Collie_AMP_init");
1796 -       Collie_AMP_off();
1797 -       LEAVE(TRACE_AMP,"Collie_AMP_init");
1798 -#endif /* CONFIG_COLLIE_TS || CONFIG_COLLIE_TR0 */
1799 -}
1800  
1801  static inline void Collie_DAC_off(void)
1802  {
1803 -       ENTER(TRACE_DAC,"Collie_DAC_off");
1804 -       if (!COLLE_RECORDING) {
1805 -               /* DAC OFF */
1806 -               LCM_GPD &= ~(LCM_GPIO_DAC_ON);  /* set up output */
1807 -               LCM_GPO &= ~(LCM_GPIO_DAC_ON);
1808 -
1809 -               /* LoCoMo GPIO disable */
1810 -               LCM_GPE &= ~(LCM_GPIO_DAC_ON);
1811 -               collie_dac_init = 0;
1812 -       }
1813 -       LEAVE(TRACE_DAC,"Collie_DAC_off");
1814 +       /* DAC OFF */
1815 +       LCM_GPD &= ~(LCM_GPIO_DAC_ON);  /* set up output */
1816 +       LCM_GPO &= ~(LCM_GPIO_DAC_ON);
1817 +       /* LoCoMo GPIO disable */
1818 +       LCM_GPE &= ~(LCM_GPIO_DAC_ON);
1819 +       collie_dac_init = 0;
1820  }
1821  
1822  static inline void Collie_DAC_on(void)
1823  {
1824 -       ENTER(TRACE_DAC,"Collie_DAC_on");
1825 -//     if (!collie_dac_init) {
1826         if (!(LCM_GPO & LCM_GPIO_DAC_ON)) {
1827                 /* LoCoMo GPIO enable */
1828                 LCM_GPE &= ~LCM_GPIO_DAC_ON;
1829 @@ -1049,24 +421,10 @@
1830                     schedule();
1831                 }
1832         }
1833 -//     }
1834 -       LEAVE(TRACE_DAC,"Collie_DAC_on");
1835 -}
1836 -
1837 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP */
1838 -static inline void Collie_DAC_delay_off(void)
1839 -{
1840 -       ENTER(TRACE_DAC,"Collie_DAC_deleay_off");
1841 -       down(&df_sem);
1842 -       SetDelay(DELAY_DAC_OFF);
1843 -       up(&df_sem);
1844 -       LEAVE(TRACE_DAC,"Collie_DAC_delay_off");
1845  }
1846 -#endif
1847  
1848  static inline void Collie_DAC_init(void)
1849  {
1850 -       ENTER(TRACE_DAC,"Collie_DAC_init");
1851         /* LoCoMo GPIO enable */
1852         LCM_GPE &=
1853           ~(LCM_GPIO_DAC_SDATA | LCM_GPIO_DAC_SCK | LCM_GPIO_DAC_SLOAD);
1854 @@ -1075,7 +433,6 @@
1855           ~(LCM_GPIO_DAC_SDATA | LCM_GPIO_DAC_SCK | LCM_GPIO_DAC_SLOAD);
1856  
1857  #if defined(CONFIG_COLLIE_PCM1741)
1858 -
1859         Collie_DAC_sendword(DAC_REG16_SetupData);       /* register16 */
1860         Collie_DAC_sendword(DAC_REG17_SetupData);       /* register17 */
1861         Collie_DAC_sendword(DAC_REG18_SetupData);       /* register18 */
1862 @@ -1083,78 +440,53 @@
1863         Collie_DAC_sendword(DAC_REG20_SetupData);       /* register20 */
1864  ////   Collie_DAC_sendword(DAC_REG21_SetupData);       /* register21 */
1865         Collie_DAC_sendword(DAC_REG22_SetupData);       /* register22 */
1866 -
1867  #elif defined(CONFIG_COLLIE_PCM1717)
1868 -
1869         Collie_DAC_sendword(DAC_MODE0_SetupData);       /* MODE0 */
1870         Collie_DAC_sendword(DAC_MODE1_SetupData);       /* MODE1 */
1871         Collie_DAC_sendword(DAC_MODE2_SetupData);       /* MODE2 */
1872         Collie_DAC_sendword(DAC_MODE3_SetupData);       /* MODE3 */
1873 -
1874  #endif
1875 -
1876         /* LoCoMo GPIO disable */
1877         LCM_GPE &=
1878           ~(LCM_GPIO_DAC_SDATA | LCM_GPIO_DAC_SCK | LCM_GPIO_DAC_SLOAD);
1879 -       LEAVE(TRACE_DAC,"Collie_DAC_init");
1880  }
1881  
1882  static inline void Collie_soft_DAC_on(void)
1883  {
1884  #if defined(CONFIG_COLLIE_PCM1741)
1885 -       ENTER(TRACE_DAC, "Collie_soft_DAC_on");
1886         Collie_DAC_sendword(DAC_REG19_DACOn);   /* register19 */
1887 -       LEAVE(TRACE_DAC, "Collie_soft_DAC_on");
1888  #endif /* CONFIG_COLLIE_PCM1741 */
1889  }
1890  
1891  static inline void Collie_soft_DAC_off(void)
1892  {
1893  #if defined(CONFIG_COLLIE_PCM1741)
1894 -       ENTER(TRACE_DAC, "Collie_soft_DAC_off");
1895                 Collie_DAC_sendword(DAC_REG19_DACOff);  /* register19 */
1896 -       LEAVE(TRACE_DAC, "Collie_soft_DAC_off");
1897 -#endif /* CONFIG_COLLIE_PCM1741 */
1898 -}
1899 -
1900 -static inline void Collie_soft_mute_init(void)
1901 -{
1902 -#if defined(CONFIG_COLLIE_PCM1741)
1903 -       ENTER(TRACE_MUTE, "Collie_soft_mute_init");
1904 -       Collie_DAC_sendword(DAC_REG18_MuteOn);  /* register18 */
1905 -       collie_soft_mute = 1;
1906 -       LEAVE(TRACE_MUTE, "Collie_soft_mute_init");
1907  #endif /* CONFIG_COLLIE_PCM1741 */
1908  }
1909  
1910  static inline void Collie_soft_mute_on(void)
1911  {
1912  #if defined(CONFIG_COLLIE_PCM1741)
1913 -       ENTER(TRACE_MUTE, "Collie_soft_mute_on");
1914         if (!collie_soft_mute) {
1915                 Collie_DAC_sendword(DAC_REG18_MuteOn);  /* register18 */
1916                 collie_soft_mute = 1;
1917         }
1918 -       LEAVE(TRACE_MUTE, "Collie_soft_mute_on");
1919  #endif /* CONFIG_COLLIE_PCM1741 */
1920  }
1921  
1922  static inline void Collie_soft_mute_off(void)
1923  {
1924  #if defined(CONFIG_COLLIE_PCM1741)
1925 -       ENTER(TRACE_MUTE, "Collie_soft_mute_off");
1926         if (collie_soft_mute) {
1927                 Collie_DAC_sendword(DAC_REG18_MuteOff); /* register18 */
1928                 collie_soft_mute = 0;
1929         }
1930 -       LEAVE(TRACE_MUTE, "Collie_soft_mute_off");
1931  #endif /* CONFIG_COLLIE_PCM1741 */
1932  }
1933  
1934  static inline void Collie_hard_mute_init(void)
1935  {
1936 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0)
1937 -       ENTER(TRACE_MUTE, "Collie_hard_mute_init");
1938         SCP_REG_GPCR |= (SCP_GPCR_PA14 | SCP_GPCR_PA15);
1939  #ifdef HARD_MUTE_CTRL_DISABLE
1940         SCP_REG_GPWR |= (SCP_GPCR_PA14 | SCP_GPCR_PA15);
1941 @@ -1162,84 +494,107 @@
1942         SCP_REG_GPWR &= ~(SCP_GPCR_PA14 | SCP_GPCR_PA15);
1943  #endif /* HARD_MUTE_CTRL_DISABLE */
1944         collie_hard_mute = 1;
1945 -#if !defined(CONFIG_COLLIE_TR1) && !defined(CONFIG_COLLIE_DEV)
1946 +
1947         {
1948                 int time = jiffies + 5;
1949                 while (jiffies <= time)
1950                         schedule();
1951         }
1952 -#endif
1953 -       LEAVE(TRACE_MUTE, "Collie_hard_mute_init");
1954 -#endif /* !CONFIG_COLLIE_TS && !CONFIG_COLLIE_TR0 */
1955  }
1956  
1957  static inline void Collie_hard_mute_on(void)
1958  {
1959 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0)
1960  #ifndef HARD_MUTE_CTRL_DISABLE
1961 -       ENTER(TRACE_MUTE, "Collie_hard_mute_on");
1962         if (!collie_hard_mute) {
1963                 SCP_REG_GPWR &= ~(SCP_GPCR_PA14 | SCP_GPCR_PA15);
1964                 collie_hard_mute = 1;
1965 -#if !defined(CONFIG_COLLIE_TR1) && !defined(CONFIG_COLLIE_DEV)
1966                 {
1967                         int time = jiffies + 5;
1968                         while (jiffies <= time)
1969                                 schedule();
1970                 }
1971 -#endif
1972         }
1973 -       LEAVE(TRACE_MUTE, "Collie_hard_mute_on");
1974  #endif /* HARD_MUTE_CTRL_DISABLE */
1975 -#endif /* !CONFIG_COLLIE_TS && !CONFIG_COLLIE_TR0 */
1976  }
1977  
1978  static inline void Collie_hard_mute_off(void)
1979  {
1980 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0)
1981  #ifndef HARD_MUTE_CTRL_DISABLE
1982 -       ENTER(TRACE_MUTE, "Collie_hard_mute_off");
1983         if (collie_hard_mute) {
1984 -               if (!COLLE_RECORDING)
1985                         SCP_REG_GPWR |= (SCP_GPCR_PA14 | SCP_GPCR_PA15);
1986 -               else
1987 -                       SCP_REG_GPWR |= (SCP_GPCR_PA15);
1988                 collie_hard_mute = 0;
1989 -#if !defined(CONFIG_COLLIE_TR1) && !defined(CONFIG_COLLIE_DEV)
1990                 {
1991                         int i;
1992                         for (i=0; i<=1000; i++) {
1993                                 udelay(1);
1994                         }
1995                 }
1996 -#endif
1997         }
1998 -       LEAVE(TRACE_MUTE, "Collie_hard_mute_off");
1999  #endif /* HARD_MUTE_CTRL_DISABLE */
2000 -#endif /* !CONFIG_COLLIE_TS && !CONFIG_COLLIE_TR0 */
2001 -}
2002 -
2003 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP 2001.12.19 */
2004 -static inline void Collie_hard_mute_delay_on(void)
2005 -{
2006 -       ENTER(TRACE_MUTE, "Collie_hard_mute_delay_on");
2007 -       down(&df_sem);
2008 -       SetDelay(DELAY_HARD_MUTE_ON);
2009 -       up(&df_sem);
2010 -       LEAVE(TRACE_MUTE, "Collie_hard_mute_delay_on");
2011  }
2012 -#endif
2013  
2014 -static inline void Collie_audio_clock_init(void)
2015 +static inline void Collie_hard_mute_left_on(void)
2016 +{
2017 +#ifndef HARD_MUTE_CTRL_DISABLE
2018 +//     if (!collie_hard_mute) {
2019 +               SCP_REG_GPWR &= ~(SCP_GPCR_PA14);
2020 +               {
2021 +                       int time = jiffies + 5;
2022 +                       while (jiffies <= time)
2023 +                               schedule();
2024 +               }
2025 +//     }
2026 +#endif /* HARD_MUTE_CTRL_DISABLE */
2027 +}
2028 +
2029 +static inline void Collie_hard_mute_left_off(void)
2030 +{
2031 +#ifndef HARD_MUTE_CTRL_DISABLE
2032 +//     if (collie_hard_mute) {
2033 +               SCP_REG_GPWR |= (SCP_GPCR_PA14);
2034 +               {
2035 +                       int i;
2036 +                       for (i=0; i<=1000; i++) {
2037 +                               udelay(1);
2038 +                       }
2039 +               }
2040 +//     }
2041 +#endif /* HARD_MUTE_CTRL_DISABLE */
2042 +}
2043 +
2044 +
2045 +static int CollieGetSamp(void)
2046 +{
2047 +       switch (sound.speed) {
2048 +       case 8000:
2049 +               return clock_set_data[7];
2050 +       case 44100:
2051 +               return clock_set_data[0];
2052 +       case 22050:
2053 +               return clock_set_data[1];
2054 +       case 11025:
2055 +               return clock_set_data[2];
2056 +       case 48000:
2057 +               return clock_set_data[3];
2058 +       case 32000:
2059 +               return clock_set_data[4];
2060 +       case 24000:
2061 +               return clock_set_data[5];
2062 +       case 16000:
2063 +               return clock_set_data[6];
2064 +       default:
2065 +               printk("Collie sound: Illegal sound rate %d\n", sound.speed);
2066 +               return clock_set_data[7];
2067 +       }
2068 +}
2069 +
2070 +static inline void Collie_audio_clock_init(void)
2071  {
2072 -       ENTER(TRACE_CLOCK, "Collie_audio_clock_init");
2073         LCM_ACC = 0;
2074 -       LEAVE(TRACE_CLOCK, "Collie_audio_clock_init");
2075  }
2076  
2077  static inline void Collie_audio_clock_on(void)
2078  {
2079 -       ENTER(TRACE_CLOCK, "Collie_audio_clock_on");
2080         /* LoCoMo Audio clock on */
2081         LCM_ACC  = CollieGetSamp();
2082         barrier();
2083 @@ -1248,263 +603,58 @@
2084         LCM_ACC |= LCM_ACC_XEN;
2085         barrier();
2086         LCM_ACC |= (LCM_ACC_MCLKEN | LCM_ACC_64FSEN);
2087 -       LEAVE(TRACE_CLOCK, "Collie_audio_clock_on");
2088  }
2089  
2090  static inline void Collie_audio_clock_off(void)
2091  {
2092 -       ENTER(TRACE_CLOCK, "Collie_audio_clock_off");
2093         /* LoCoMo Audio clock off */
2094         LCM_ACC &= ~(LCM_ACC_XEN | LCM_ACC_MCLKEN | LCM_ACC_64FSEN);
2095         barrier();
2096         LCM_ACC &= ~(LCM_ACC_XON);
2097 -       LEAVE(TRACE_CLOCK, "Collie_audio_clock_off");
2098 -}
2099 -
2100 -static inline void Collie_paif_init(void)
2101 -{
2102 -       ENTER(TRACE_PAIF, "Collie_paif_init");
2103 -       //      LCM_PAIF  = (LCM_PAIF_SCINV | LCM_PAIF_LRCRST);
2104 -       LCM_PAIF  = (LCM_PAIF_LRCRST);
2105 -       LEAVE(TRACE_PAIF, "Collie_paif_init");
2106  }
2107  
2108  static inline void Collie_paif_on(void)
2109  {
2110 -       ENTER(TRACE_PAIF, "Collie_paif_on");
2111         LCM_PAIF  = (LCM_PAIF_SCINV | LCM_PAIF_LRCRST);
2112         LCM_PAIF &= ~(LCM_PAIF_LRCRST);
2113         LCM_PAIF |= (LCM_PAIF_SCEN | LCM_PAIF_LRCEN);
2114 -       LEAVE(TRACE_PAIF, "Collie_paif_on");
2115  }
2116  
2117  static inline void Collie_paif_off(void)
2118  {
2119 -       ENTER(TRACE_PAIF, "Collie_paif_off");
2120 -       //      LCM_PAIF  = (LCM_PAIF_SCINV | LCM_PAIF_LRCRST);
2121         LCM_PAIF  = (LCM_PAIF_LRCRST);
2122 -       LEAVE(TRACE_PAIF, "Collie_paif_off");
2123  }
2124  
2125  static inline void Collie_MIC_init(void)
2126  {
2127 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0)
2128 -       ENTER(TRACE_MIC, "Collie_MIC_init");
2129         /* MIC to GPIO 17 */
2130         /* alternate functions for the GPIOs */
2131 -       GAFR &= ~( COLLIE_GPIO_MIC );
2132 -       
2133 +       GAFR &= ~( COLLIE_GPIO_MIC );   
2134         /* Set the direction: 17 output */
2135         GPDR |= ( COLLIE_GPIO_MIC );
2136 -       
2137 -#if defined(CONFIG_COLLIE_TR1)
2138 -       /* Set pin level (Low) */
2139 -               GPCR = ( COLLIE_GPIO_MIC );
2140 -#else
2141         /* Set pin level (High) */
2142                 GPSR = ( COLLIE_GPIO_MIC );
2143 -#endif
2144 -       LEAVE(TRACE_MIC, "Collie_MIC_init");
2145 -#endif /* !CONFIG_COLLIE_TS && !CONFIG_COLLIE_TR0 */
2146  }
2147  
2148  static inline void Collie_MIC_on(void)
2149  {
2150 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0)
2151 -       ENTER(TRACE_MIC, "Collie_MIC_on");
2152 -#if defined(CONFIG_COLLIE_TR1)
2153 -       GPSR = ( COLLIE_GPIO_MIC );
2154 -#else
2155         GPCR = ( COLLIE_GPIO_MIC );
2156 -#endif
2157 -       LEAVE(TRACE_MIC, "Collie_MIC_on");
2158 -#endif /* !CONFIG_COLLIE_TS && !CONFIG_COLLIE_TR0 */
2159  }
2160  
2161  static inline void Collie_MIC_off(void)
2162  {
2163 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0)
2164 -       ENTER(TRACE_MIC, "Collie_MIC_off");
2165 -       if (!COLLE_RECORDING) {
2166 -#if defined(CONFIG_COLLIE_TR1)
2167 -               GPCR = ( COLLIE_GPIO_MIC );
2168 -#else
2169 -                       GPSR = ( COLLIE_GPIO_MIC );
2170 -#endif
2171 -       }
2172 -       LEAVE(TRACE_MIC, "Collie_MIC_off");
2173 -#endif /* !CONFIG_COLLIE_TS && !CONFIG_COLLIE_TR0 */
2174 -}
2175 -
2176 -static inline void Collie_volume_init(void)
2177 -{
2178 -       ENTER(TRACE_VOLUME, "Collie_volume_init");
2179 -       m62332_senddata(0, M62332_EVR_CH);
2180 -       collie_volume = 0;
2181 -       LEAVE(TRACE_VOLUME, "Collie_volume_init");
2182 -}
2183 -
2184 -static inline void Collie_volume_on(void)
2185 -{
2186 -       ENTER(TRACE_VOLUME, "Collie_volume_on");
2187 -       if (collie_volume != sound.volume_left) {
2188 -               //Collie_hard_mute_on();
2189 -               m62332_senddata(0xff * sound.volume_left / 100, M62332_EVR_CH);
2190 -               //Collie_hard_mute_off();
2191 -               collie_volume = sound.volume_left;
2192 -       }
2193 -       LEAVE(TRACE_VOLUME, "Collie_volume_on");
2194 -}
2195 -
2196 -static inline void Collie_volume_off(void)
2197 -{
2198 -       ENTER(TRACE_VOLUME, "Collie_volume_off");
2199 -       if (collie_volume) {
2200 -               //Collie_hard_mute_on();
2201 -               m62332_senddata(0, M62332_EVR_CH);
2202 -               //Collie_hard_mute_off();
2203 -               collie_volume = 0;
2204 -       }
2205 -       LEAVE(TRACE_VOLUME, "Collie_volume_off");
2206 -}
2207 -
2208 -#define        VOL_THRES       40
2209 -static void Collie_volume_half_adjust(void)
2210 -{
2211 -       int     volume = collie_volume;
2212 -       ENTER(TRACE_VOLUME, "Collie_volume_half_adjust");
2213 -       if (collie_volume > sound.volume_left) {
2214 -               /* volume down */
2215 -               if (collie_volume > VOL_THRES) {
2216 -                       if (sound.volume_left > VOL_THRES) {
2217 -                               volume = (collie_volume + sound.volume_left)/2;
2218 -                               if (volume == collie_volume) {
2219 -                                       volume = sound.volume_left;
2220 -                               }
2221 -                       } else {
2222 -                               volume = (collie_volume + VOL_THRES)/2;
2223 -                               if (volume == collie_volume) {
2224 -                                       volume = VOL_THRES;
2225 -                               }
2226 -                       }
2227 -               } else {
2228 -                       /* we can pull down without noise */
2229 -                       volume = sound.volume_left;
2230 -               }
2231 -       } else if (collie_volume < sound.volume_left) {
2232 -               /* volume up */
2233 -               if (sound.volume_left > VOL_THRES) {
2234 -                       if (collie_volume < VOL_THRES) {
2235 -                               /* we can pull up to VOL_THRES without noise */
2236 -                               volume = VOL_THRES;;
2237 -                       } else {
2238 -                               volume = (collie_volume + sound.volume_left)/2;
2239 -                               if (volume == collie_volume) {
2240 -                                       volume = sound.volume_left;
2241 -                               }
2242 -                       }
2243 -               } else {
2244 -                       /* we can pull up without noise */
2245 -                       volume = sound.volume_left;
2246 -               }
2247 -       }
2248 -       if (collie_volume != volume) {
2249 -               m62332_senddata(0xff * volume / 100, M62332_EVR_CH);
2250 -               collie_volume = volume;
2251 -       }
2252 -       LEAVE(TRACE_VOLUME, "Collie_volume_half_adjust");
2253 -}
2254 -
2255 -static void Collie_volume_half_off(void)
2256 -{
2257 -       int volume;
2258 -       int delta = 1;
2259 -       ENTER(TRACE_VOLUME, "Collie_volume_half_off");
2260 -       while (0 < collie_volume) {
2261 -               if (collie_volume <= VOL_THRES) {
2262 -                       volume = 0;
2263 -               } else {
2264 -                       if (collie_volume > delta) {
2265 -                               volume = collie_volume - delta;
2266 -                       } else {
2267 -                               volume = 0;
2268 -                       }
2269 -                       if (volume && volume < VOL_THRES) {
2270 -                               volume = VOL_THRES;
2271 -                       }
2272 -                       delta <<= 1;
2273 -               }
2274 -               m62332_senddata(0xff * volume / 100, M62332_EVR_CH);
2275 -               collie_volume = volume;
2276 -               udelay(100);
2277 -       }
2278 -       LEAVE(TRACE_VOLUME, "Collie_volume_half_off");
2279 -}
2280 -
2281 -static void Collie_OP_SHDN_on(void)
2282 -{
2283 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
2284 -       ENTER(TRACE_OP_SHDN,"Collie_OP_SHDN_on");
2285 -       if (!collie_op_shdn_on) {
2286 -               /* set volume */
2287 -               Collie_volume_off();
2288 -
2289 -               /* OP_SHDN to GPIO 17 */
2290 -               /* alternate functions for the GPIOs */
2291 -               GAFR &= ~( COLLIE_GPIO_OPSHDN );
2292 -       
2293 -               /* Set the direction: 17 output */
2294 -               GPDR |= ( COLLIE_GPIO_OPSHDN );
2295 -       
2296 -               /* Set pin level (high) */
2297 -               GPSR |= ( COLLIE_GPIO_OPSHDN );
2298 -               
2299 -               /* set volume */
2300 -               Collie_volume_on();
2301 -
2302 -               collie_op_shdn_on = 1;
2303 -       }
2304 -       LEAVE(TRACE_OP_SHDN,"Collie_OP_SHDN_on");
2305 -#endif /* CONFIG_COLLIE_TS || CONFIG_COLLIE_TR0 */
2306 -}
2307 -
2308 -static void Collie_OP_SHDN_off(void)
2309 -{
2310 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
2311 -       ENTER(TRACE_OP_SHDN,"Collie_OP_SHDN_off");
2312 -       /* OP_SHDN to GPIO 17 */
2313 -       /* alternate functions for the GPIOs */
2314 -       GAFR &= ~( COLLIE_GPIO_OPSHDN );
2315 -       
2316 -       /* Set the direction: 17 output */
2317 -       GPDR |= ( COLLIE_GPIO_OPSHDN );
2318 -       
2319 -       /* Clear pin level (low) */
2320 -       GPCR |= ( COLLIE_GPIO_OPSHDN );
2321 -
2322 -       collie_op_shdn_on = 0;
2323 -       LEAVE(TRACE_OP_SHDN,"Collie_OP_SHDN_off");
2324 -#endif /* CONFIG_COLLIE_TS || CONFIG_COLLIE_TR0 */
2325 +       GPSR = ( COLLIE_GPIO_MIC );
2326  }
2327  
2328  static inline void Collie_ssp_init(void)
2329  {
2330 -       ENTER(TRACE_SSP, "Collie_ssp_init");
2331         /* alternate functions for the GPIOs */
2332         /* SSP port to GPIO 10,12,13, 19 */
2333         GAFR |= ( GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM | GPIO_SSP_CLK );
2334 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
2335 -       /* SSP port to GPIO 11 */
2336 -       GAFR |= GPIO_SSP_RXD;
2337 -#endif /* CONFIG_COLLIE_TS || CONFIG_COLLIE_TR0 */
2338  
2339         /* Set the direction: 10, 12, 13 output; 19 input */
2340         GPDR |= ( GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM );
2341         GPDR &= ~( GPIO_SSP_CLK );
2342 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
2343 -       /* Set the direction: 11 input */
2344 -       GPDR &= ~( GPIO_SSP_RXD );
2345 -#endif /* CONFIG_COLLIE_TS || CONFIG_COLLIE_TR0 */
2346  
2347         /* enable SSP pin swap */
2348         PPAR |= PPAR_SPR;
2349 @@ -1516,400 +666,162 @@
2350         /* the SSP setting */
2351         Ser4SSCR0 = (SSCR0_DataSize(16) | SSCR0_TI | SSCR0_SerClkDiv(2));
2352         Ser4SSCR1 = (SSCR1_SClkIactL | SSCR1_SClk1P | SSCR1_ExtClk);
2353 -
2354 -       LEAVE(TRACE_SSP, "Collie_ssp_init");
2355  }
2356  
2357  static inline void Collie_ssp_on(void)
2358  {
2359 -       ENTER(TRACE_SSP, "Collie_ssp_on");
2360         /* turn on the SSP */
2361         Ser4SSCR0 |= ( SSCR0_SSE );
2362 -       LEAVE(TRACE_SSP, "Collie_ssp_on");
2363  }
2364  
2365  static inline void Collie_ssp_off(void)
2366  {
2367 -       ENTER(TRACE_SSP, "Collie_ssp_off");
2368         /* turn off the SSP */
2369         Ser4SSCR0 &= ~( SSCR0_SSE );
2370 -       LEAVE(TRACE_SSP, "Collie_ssp_off");
2371 -}
2372 -
2373 -static inline void Collie_sound_hard_init(void)
2374 -{
2375 -       ENTER(TRACE_ON, "Collie_sound_hard_init");
2376 -       Collie_hard_mute_init();
2377 -       Collie_audio_clock_init();
2378 -       Collie_paif_init();
2379 -       Collie_volume_init();
2380 -       Collie_ssp_init();
2381 -       Collie_MIC_init();
2382 -
2383 -       Collie_FS8KLPF_start();
2384 -       LEAVE(TRACE_ON, "Collie_sound_hard_init");
2385 -}
2386 -
2387 -static inline void Collie_sound_hard_term(void)
2388 -{
2389 -       ENTER(TRACE_ON, "Collie_sound_hard_term");
2390 -#ifdef DAC_OFF_WITH_DEVICE_OFF
2391 -       /* DAC Off */
2392 -       Collie_DAC_off();
2393 -#endif
2394 -       LEAVE(TRACE_ON, "Collie_sound_hard_term");
2395 -}
2396 -
2397 -static void Collie_FS8KLPF_start(void)
2398 -{
2399 -#if defined(CONFIG_COLLIE_TS) || defined(CONFIG_COLLIE_TR0)
2400 -       ENTER(TRACE_ON,"Collie_FS8KLPF_start");
2401 -       /* Set up TC35143 GPIO I/O Direction (GPIO5 output mode) */
2402 -       ucb1200_set_io_direction(TC35143_GPIO_FS8KLPF,
2403 -                                TC35143_IODIR_OUTPUT);
2404 -       /* Set up TC35143 GPIO 5 (set LOW) */
2405 -       ucb1200_set_io(TC35143_GPIO_FS8KLPF, TC35143_IODAT_LOW);
2406 -       LEAVE(TRACE_ON,"Collie_FS8KLPF_start");
2407 -#endif /* CONFIG_COLLIE_TS || CONFIG_COLLIE_TR0 */
2408 -}
2409 -
2410 -#ifdef CONFIG_PM
2411 -#if 0
2412 -static void Collie_FS8KLPF_stop(void)
2413 -{
2414 -       /* Set up TC35143 GPIO I/O Direction (GPIO5 output mode) */
2415 -       ucb1200_set_io_direction(TC35143_GPIO_FS8KLPF,
2416 -                                TC35143_IODIR_OUTPUT);
2417 -       /* Set up TC35143 GPIO 5 (set LOW) */
2418 -       ucb1200_set_io(TC35143_GPIO_FS8KLPF, TC35143_IODAT_HIGH);
2419 -}
2420 -
2421 -static void Collie_clock_stop(void)
2422 -{
2423 -       /* LoCoMo PCM audio interface */
2424 -       Collie_paif_off();
2425 -
2426 -       /* LoCoMo audio clock off */
2427 -       Collie_audio_clock_off();
2428 -}
2429 -#endif
2430 -#endif
2431 -
2432 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP 2001.12.19 */
2433 -static unsigned long in_timehandle = 0;
2434 -static struct timer_list timer;
2435 -
2436 -static void collieDoDelayedSilence(void)
2437 -{
2438 -       ENTER(TRACE_ON,"collieDoDelayedSilence");
2439 -       down(&df_sem);
2440 -       if(isDelayed(DELAY_HARD_MUTE_ON)) {
2441 -               Collie_hard_mute_on();
2442 -       }
2443 -       if(isDelayed(DELAY_DAC_OFF)) {
2444 -               Collie_DAC_off();
2445 -       }
2446 -       ResetDelayAll();
2447 -       up(&df_sem);
2448 -       LEAVE(TRACE_ON,"colliDoDelayedSilence");
2449 -}
2450 -
2451 -static void collieDelayedSilence(void)
2452 -{
2453 -       ENTER(TRACE_ON,"collieDelayedSilence");
2454 -       while (1) {
2455 -               sleep_on(&delay_off);
2456 -               collieDoDelayedSilence();
2457 -       }
2458 -       LEAVE(TRACE_ON,"collieDelayedSilence");
2459 -}
2460 -
2461 -static void collieStartDelayedSilence(unsigned long data)
2462 -{
2463 -       ENTER(TRACE_ON,"collieStartDelayedSilence");
2464 -       in_timehandle = 0;
2465 -       wake_up(&delay_off);
2466 -       LEAVE(TRACE_ON,"collieStartDelayedSilence");
2467 -}
2468 -
2469 -static void collieTriggerDelayedSilence(void)
2470 -{
2471 -       ENTER(TRACE_ON,"collieTriggerDelayedSilence");
2472 -       in_timehandle = 1;
2473 -       init_timer(&timer);
2474 -       timer.function = collieStartDelayedSilence;
2475 -       timer.expires = jiffies + 5*100;
2476 -       add_timer(&timer);
2477 -       LEAVE(TRACE_ON,"collieTriggerDelayedSilence");
2478 -}
2479 -
2480 -static void collieCancelDelayedSilence(void)
2481 -{
2482 -       ENTER(TRACE_ON,"collieCancelDelayedSilence");
2483 -       down(&df_sem);
2484 -       ResetDelayAll();;
2485 -       up(&df_sem);
2486 -       if (in_timehandle) {
2487 -               del_timer(&timer);
2488 -               in_timehandle = 0;
2489 -       }
2490 -       LEAVE(TRACE_ON,"collieCancelDelayedSilence");
2491 -}
2492 -#endif
2493 -
2494 -static void Collie_disable_sound(void)
2495 -{
2496 -       ENTER(TRACE_ON,"Collie_disable_sound");
2497 -       sa1100_dma_stop(COLLIE_SOUND_DMA_CHANNEL);
2498 -       sa1100_dma_flush_all(COLLIE_SOUND_DMA_CHANNEL);
2499 -#ifndef TRY_DELAY_OFF  /* H.Hayami SHARP 2001.12.18 */
2500 -       Collie_volume_half_off();
2501 -       Collie_hard_mute_on();
2502 -       Collie_soft_mute_on();
2503 -
2504 -       Collie_ssp_off();
2505 -
2506 -       /* Collie_clock_stop(); */
2507 -#endif
2508 -       LEAVE(TRACE_ON,"Collie_disable_sound");
2509 -}
2510 -
2511 -static void CollieSilence(void)
2512 -{
2513 -       ENTER(TRACE_ON,"CollieSilence");
2514 -       /* Disable sound & DMA */
2515 -       Collie_disable_sound();
2516 -
2517 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP 2001.12.18 */
2518 -       Collie_volume_half_off();
2519 -       Collie_hard_mute_delay_on();
2520 -       Collie_soft_mute_on();
2521 -
2522 -       Collie_ssp_off();
2523 -
2524 -       /* Collie_clock_stop(); */
2525 -#endif
2526 -
2527 -#if 0  /* H.Hayami SHARP 2001.12.18 */
2528 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0) && \
2529 -    !defined(CONFIG_COLLIE_TR1) && !defined(CONFIG_COLLIE_DEV)
2530 -       Collie_volume_off();
2531 -#endif
2532 -#endif
2533 -       Collie_OP_SHDN_off();
2534 -       Collie_soft_DAC_off();
2535 -       Collie_paif_off();
2536 -       Collie_audio_clock_off();
2537 -
2538 -       //Collie_MIC_on();
2539 -
2540 -#ifndef DAC_OFF_WITH_DEVICE_OFF
2541 -       /* DAC Off */
2542 -#ifdef TRY_DELAY_OFF   /* H.Hayami 2001.12.15 */
2543 -       Collie_DAC_delay_off();
2544 -#else
2545 -       Collie_DAC_off();
2546 -#endif
2547 -#endif /* end DAC_OFF_WITH_DEVICE_OFF */
2548 -
2549 -       /* AMP Off */
2550 -       Collie_AMP_off();
2551 -
2552 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP 2001.12.18 */
2553 -       collieTriggerDelayedSilence();
2554 -#endif
2555 -       LEAVE(TRACE_ON,"CollieSilence");
2556 -}
2557 -
2558 -static int CollieGetSamp(void)
2559 -{
2560 -       ENTER(TRACE_ON,"CollieGetSamp");
2561 -       switch (sound.soft.speed) {
2562 -       case 8000:
2563 -               LEAVE(TRACE_ON,"CollieGetSamp");
2564 -               return clock_set_data[7];
2565 -       case 44100:
2566 -               LEAVE(TRACE_ON,"CollieGetSamp");
2567 -               return clock_set_data[0];
2568 -       case 22050:
2569 -               LEAVE(TRACE_ON,"CollieGetSamp");
2570 -               return clock_set_data[1];
2571 -       case 11025:
2572 -               LEAVE(TRACE_ON,"CollieGetSamp");
2573 -               return clock_set_data[2];
2574 -       case 48000:
2575 -               LEAVE(TRACE_ON,"CollieGetSamp");
2576 -               return clock_set_data[3];
2577 -       case 32000:
2578 -               LEAVE(TRACE_ON,"CollieGetSamp");
2579 -               return clock_set_data[4];
2580 -       case 24000:
2581 -               LEAVE(TRACE_ON,"CollieGetSamp");
2582 -               return clock_set_data[5];
2583 -       case 16000:
2584 -               LEAVE(TRACE_ON,"CollieGetSamp");
2585 -               return clock_set_data[6];
2586 -       default:
2587 -               printk("Collie sound: Illegal sound rate %d\n", sound.soft.speed);
2588 -               LEAVE(TRACE_ON,"CollieGetSamp");
2589 -               return clock_set_data[7];
2590 -       }
2591 -}
2592 -
2593 -static inline void Collie_DAC_sendbit(int bit_data)
2594 -{
2595 -       ENTER(TRACE_SENDDATA,"Collie_DAC_sendbit");
2596 -       if (bit_data & 1) {
2597 -               LCM_GPO |=  (LCM_GPIO_DAC_SDATA);
2598 -       } else {
2599 -               LCM_GPO &= ~(LCM_GPIO_DAC_SDATA);
2600 -       }
2601 -
2602 -       udelay(1);
2603 -       LCM_GPO |=  (LCM_GPIO_DAC_SCK);
2604 -
2605 -       udelay(1);
2606 -       LCM_GPO &= ~(LCM_GPIO_DAC_SCK);
2607 -       udelay(1);
2608 -       LCM_GPO &= ~(LCM_GPIO_DAC_SDATA);
2609 -       udelay(1);
2610 -       LEAVE(TRACE_SENDDATA,"Collie_DAC_sendbit");
2611 -}
2612 -
2613 -static void Collie_DAC_sendword(int data)
2614 -{
2615 -       int i;
2616 -
2617 -       ENTER(TRACE_SENDDATA,"Collie_DAC_sendword");
2618 -#if defined(CONFIG_COLLIE_PCM1741)
2619 -       
2620 -       LCM_GPO &= ~(LCM_GPIO_DAC_SCK);
2621 -       udelay(1);
2622 -       LCM_GPO |=  (LCM_GPIO_DAC_SLOAD);
2623 -       udelay(1);
2624 -
2625 -       for (i = 0; i < 16; i++)
2626 -               Collie_DAC_sendbit(data >> (15 - i));
2627 -
2628 -       LCM_GPO &= ~(LCM_GPIO_DAC_SLOAD);
2629 -       udelay(2);
2630 -
2631 -#elif defined(CONFIG_COLLIE_PCM1717)
2632 -       
2633 -       LCM_GPO &= ~(LCM_GPIO_DAC_SLOAD);
2634 -       udelay(1000);
2635 -       LCM_GPO |=  (LCM_GPIO_DAC_SLOAD);
2636 -       udelay(1000);
2637 -       LCM_GPO &= ~(LCM_GPIO_DAC_SCK);
2638 -       udelay(1000);
2639 -
2640 -       for (i = 0; i < 16; i++)
2641 -               Collie_DAC_sendbit(data >> (15 - i));
2642 -
2643 -       LCM_GPO &= ~(LCM_GPIO_DAC_SLOAD);
2644 -       udelay(1000);
2645 -       LCM_GPO |=  (LCM_GPIO_DAC_SLOAD);
2646 -       udelay(1000);
2647 -       LCM_GPO &= ~(LCM_GPIO_DAC_SLOAD);
2648 -       udelay(1000);
2649 -       
2650 -#endif
2651 -       LEAVE(TRACE_SENDDATA,"Collie_DAC_sendword");
2652  }
2653  
2654 -void
2655 -Collie_audio_power_on(void)
2656 +
2657 +static inline void Collie_sound_hard_init(void)
2658  {
2659 -       int send_data;
2660 +       Collie_hard_mute_init();
2661 +       Collie_audio_clock_init();
2662 +       Collie_paif_off();
2663 +       Collie_volume_init();
2664 +       Collie_ssp_init();
2665 +       Collie_MIC_init();
2666 +       Collie_soft_mute_on();
2667 +       Collie_DAC_on();
2668 +}
2669  
2670 -       ENTER(TRACE_ON,"Collie_audio_power_on");
2671 +void Collie_recording_on(void)
2672 +{
2673 +       collie_recording=1;
2674 +       if (!playing) 
2675 +           Collie_DAC_on();
2676 +       else
2677 +           Collie_hard_mute_left_on();
2678 +       Collie_MIC_on();
2679 +}
2680  
2681 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP 2001.12.19 */
2682 -       collieCancelDelayedSilence();
2683 -#endif
2684 +void Collie_recording_off(void)
2685 +{
2686 +       collie_recording=0;
2687 +       Collie_MIC_off();
2688 +       if (!playing) 
2689 +           Collie_DAC_off();
2690 +       else 
2691 +           Collie_hard_mute_left_off();
2692 +}
2693  
2694 +static void Collie_audio_power_on(void)
2695 +{
2696 +       playing=1;
2697         collie_amp_init = 0;
2698 -
2699 -       /* OP_SHDN off */
2700 -       Collie_OP_SHDN_off();
2701 -
2702 -       /* AMP on */
2703 -       Collie_AMP_on();
2704 -
2705 -       /* DAC ON */
2706 -       Collie_DAC_on();
2707 -
2708 -       Collie_MIC_off();
2709 -       Collie_ssp_on();
2710 -       
2711 -       /* LoCoMo Audio clock */
2712 -       Collie_audio_clock_off();
2713 +       if (!collie_recording)
2714 +           Collie_DAC_on();
2715 +       Collie_ssp_on();        
2716 +       Collie_audio_clock_off();       /* LoCoMo Audio clock */
2717         Collie_audio_clock_on();
2718 -
2719 -       /* LoCoMo PCM audio interface */
2720 -       Collie_paif_on();
2721 -
2722 +       Collie_paif_on();               /* LoCoMo PCM audio interface */
2723         udelay(1000);
2724 -
2725 -       /* DAC Setting */
2726         Collie_DAC_init();
2727 -
2728         Collie_soft_DAC_on();
2729 -       Collie_soft_mute_init();
2730 +       Collie_soft_mute_off();
2731 +       Collie_hard_mute_off();
2732 +       if (collie_recording)
2733 +           Collie_hard_mute_left_on();
2734 +       Collie_volume_set(sound.volume);
2735 +}
2736  
2737 -       sound.hard = sound.soft;
2738 +static void Collie_audio_power_off(void){      /* Disable sound only */
2739 +    Collie_volume_set(0);
2740 +    Collie_hard_mute_on();
2741 +    Collie_soft_mute_on();
2742 +    Collie_ssp_off();
2743 +    Collie_soft_DAC_off();
2744 +    Collie_paif_off();
2745 +    Collie_audio_clock_off();
2746 +    if (!collie_recording)
2747 +       Collie_DAC_off();
2748 +    playing=0;
2749 +}
2750  
2751 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0) && \
2752 -    !defined(CONFIG_COLLIE_TR1) && !defined(CONFIG_COLLIE_DEV)
2753 -       /* Volume set */
2754 -       Collie_volume_half_adjust();
2755 -       {
2756 -               int i;
2757 -               for (i=0; i<10*1000; i++) {
2758 -                       udelay(1);
2759 +
2760 +static inline void Collie_volume_init(void)
2761 +{
2762 +       m62332_senddata(0, M62332_EVR_CH);
2763 +       collie_volume = 0;
2764 +}
2765 +
2766 +#define        VOL_THRES       10
2767 +
2768 +static void Collie_volume_set(int dest)
2769 +{
2770 +       int     chn;
2771 +       while (dest != collie_volume) {
2772 +               chn = dest-collie_volume;
2773 +               if (chn>VOL_THRES)
2774 +                   chn=VOL_THRES;    
2775 +               else if (chn<-VOL_THRES)
2776 +                   chn=-VOL_THRES;
2777 +               if (chn) {
2778 +                   collie_volume += chn;
2779 +                   m62332_senddata(0xff * collie_volume / 100, M62332_EVR_CH);
2780                 }
2781 +               udelay(100);
2782         }
2783 -#endif
2784 +}
2785  
2786 -       Collie_soft_mute_off();
2787 -       Collie_hard_mute_off();
2788 +static int sound_set_speed(int speed)
2789 +{
2790 +       if (speed < 0) {
2791 +               return(sound.speed);
2792 +       }
2793 +
2794 +       if (speed<8000) sound.speed=8000;
2795 +       else if (speed<=11025) sound.speed=11025;
2796 +       else if (speed<=16000) sound.speed=16000;
2797 +       else if (speed<=22050) sound.speed=22050;
2798 +       else if (speed<=24000) sound.speed=24000;
2799 +       else if (speed<=32000) sound.speed=32000;
2800 +       else if (speed<=44100) sound.speed=44100;
2801 +       else sound.speed=48000;
2802 +
2803 +       /* LoCoMo Audio clock */
2804 +       Collie_audio_clock_off();
2805 +       Collie_audio_clock_on();
2806 +       return(sound.speed);
2807 +}
2808  
2809 -       LEAVE(TRACE_ON,"Collie_audio_power_on");
2810 +/*** Mid level stuff *********************************************************/
2811 +
2812 +static void Collie_Set_Volume(int volume)
2813 +{
2814 +       sound.volume = volume & 0xff;
2815 +       sound.volume += ( volume & 0xff00 >> 8);
2816 +       sound.volume >>=1;
2817 +       if (sound.volume>100) sound.volume=100; 
2818  }
2819  
2820 -static void CollieInit(void)
2821 +static int Collie_Get_Volume(void)
2822  {
2823 -       ENTER(TRACE_ON,"CollieInit");
2824 -       sound.hard = sound.soft;
2825 -       LEAVE(TRACE_ON,"CollieInit");
2826 +       return ( sound.volume << 8 | sound.volume );
2827  }
2828  
2829 +
2830  static void Collie_sq_interrupt(void* id, int size)
2831  {
2832         audio_buf_t *b = (audio_buf_t *) id;
2833 -       ENTER(TRACE_INTERRUPT,"Collie_sq_interrupt");
2834 -/***** DEBUG *****
2835 -printk("Collie_sq_interrupt: Start\n");
2836 -*****************/
2837 +
2838         /*
2839          * Current buffer is sent: wake up any process waiting for it.
2840          */
2841 -       ENTER(TRACE_SEM,"up sem");
2842         up(&b->sem);
2843 -       LEAVE(TRACE_SEM,"up sem");
2844 -/***** DEBUG *****
2845 -printk("Collie_sq_interrupt: up End\n");
2846 -*****************/
2847         /* And any process polling on write. */
2848 -       ENTER(TRACE_SEM,"up wait");
2849 -       wake_up(&b->sem.wait);
2850 -       LEAVE(TRACE_SEM,"up wait");
2851 -/***** DEBUG *****
2852 -printk("Collie_sq_interrupt: wake_up End\n");
2853 -*****************/
2854 +       wake_up_interruptible(&b->sem.wait);
2855 +       /* And indicate which was the last buffer sent */
2856  
2857         DPRINTK("Collie_sq_interrupt \n");
2858 -       LEAVE(TRACE_INTERRUPT,"Collie_sq_interrupt");
2859  }
2860  
2861  
2862 @@ -1917,191 +829,52 @@
2863  {
2864         int err;
2865  
2866 -       ENTER(TRACE_ON,"CollieIrqInit");
2867         err = sa1100_request_dma(&collie_dmasound_irq, "dmasound",
2868                                  DMA_Ser4SSPWr);
2869         if (err) {
2870 -               LEAVE(TRACE_ON,"CollieIrqInit");
2871                 return 0;
2872         }
2873 -       /* printk("collie_dmasound_irq=%d\n", collie_dmasound_irq); */
2874 +       printk("collie_dmasound_irq=%d\n", collie_dmasound_irq); 
2875  
2876         sa1100_dma_set_callback(collie_dmasound_irq,
2877                                (dma_callback_t)Collie_sq_interrupt);
2878  
2879 -
2880 -       /* Disable sound & DMA */
2881 -       Collie_disable_sound();
2882 -
2883 -       LEAVE(TRACE_ON,"CollieIrqInit");
2884 +       sa1100_dma_stop(COLLIE_SOUND_DMA_CHANNEL);
2885 +       sa1100_dma_flush_all(COLLIE_SOUND_DMA_CHANNEL);
2886 +       Collie_audio_power_off();
2887         return(1);
2888 -
2889 -}
2890 -
2891 -#ifdef MODULE
2892 -static void CollieIrqCleanUp(void)
2893 -{
2894 -       ENTER(TRACE_ON,"CollieIrqCleanUp");
2895 -       /* Disable sound & DMA */
2896 -       Collie_disable_sound();
2897 -
2898 -       /* release the interrupt */
2899 -       free_irq(IRQ_DMA, Collie_sq_interrupt);
2900 -       LEAVE(TRACE_ON,"CollieIrqCleanUp");
2901  }
2902 -#endif /* MODULE */
2903 -
2904  
2905  static int CollieSetFormat(int format)
2906  {
2907         int size;
2908  
2909 -       ENTER(TRACE_ON,"CollieSetFormat");
2910 -       /* Falcon sound DMA supports 8bit and 16bit modes */
2911 -
2912         switch (format) {
2913         case AFMT_QUERY:
2914 -               LEAVE(TRACE_ON,"CollieSetFormat");
2915 -               return(sound.soft.format);
2916 -       case AFMT_MU_LAW:
2917 -               size = 8;
2918 -               ct_func = sound.trans->ct_ulaw;
2919 -               break;
2920 -       case AFMT_A_LAW:
2921 -               size = 8;
2922 -               ct_func = sound.trans->ct_alaw;
2923 -               break;
2924 -       case AFMT_S8:
2925 -               size = 8;
2926 -               ct_func = sound.trans->ct_s8;
2927 -               break;
2928 -       case AFMT_U8:
2929 -               size = 8;
2930 -               ct_func = sound.trans->ct_u8;
2931 -               break;
2932 -       case AFMT_S16_BE:
2933 -               size = 16;
2934 -               ct_func = sound.trans->ct_s16be;
2935 -               break;
2936 -       case AFMT_U16_BE:
2937 -               size = 16;
2938 -               ct_func = sound.trans->ct_u16be;
2939 -               break;
2940 -       case AFMT_S16_LE:
2941 -               size = 16;
2942 -               ct_func = sound.trans->ct_s16le;
2943 -               break;
2944 -       case AFMT_U16_LE:
2945 +               return(sound.format);
2946 +       default: /* This is the only one supported by the hardware it seems */
2947                 size = 16;
2948 -               ct_func = sound.trans->ct_u16le;
2949 -               break;
2950 -       default: /* :-) */
2951 -               size = 8;
2952 -               format = AFMT_S8;
2953 -       }
2954 -
2955 -       sound.soft.format = format;
2956 -       sound.soft.size = size;
2957 -       if (sound.minDev == SND_DEV_DSP) {
2958 -               sound.dsp.format = format;
2959 -               sound.dsp.size = sound.soft.size;
2960 +               format = AFMT_S16_LE;
2961         }
2962 +       sound.format = format;
2963 +       sound.size = size;
2964  
2965 -       LEAVE(TRACE_ON,"CollieSetFormat");
2966         return(format);
2967  }
2968  
2969 -/*** Machine definitions *****************************************************/
2970 -
2971 -static MACHINE machCollie = {
2972 -       DMASND_COLLIE,          // int type
2973 -       NULL,                   // void *dma_alloc(uint, int)
2974 -       NULL,                   // void  dma_free(void *, uint)
2975 -       CollieIrqInit,          // void  irqinit(void)
2976 -#ifdef MODULE
2977 -       CollieIrqCleanUp,       // void  irqcleanup(void)
2978 -#endif /* MODULE */
2979 -       CollieInit,             // void  init(void)
2980 -       CollieSilence,          // void  silence(void)
2981 -       CollieSetFormat,        // int   setFormat(int)
2982 -       NULL,                   // int   setVolume(int)
2983 -       NULL,                   // int   setBass(int)
2984 -       NULL,                   // int   setTreble(int)
2985 -       NULL,                   // int   setGain(int)
2986 -       NULL                    // void  play(void)
2987 -};
2988 -
2989 -
2990 -/*** Mid level stuff *********************************************************/
2991 -
2992 -
2993 -static void sound_silence(void)
2994 -{
2995 -       ENTER(TRACE_ON,"sound_silence");
2996 -       /* update hardware settings one more */
2997 -       //(*sound.mach.init)();
2998 -       (*sound.mach.silence)();
2999 -       LEAVE(TRACE_ON,"sound_silence");
3000 -
3001 -}
3002 -
3003 -
3004 -static void sound_init(void)
3005 -{
3006 -       ENTER(TRACE_ON,"sound_init");
3007 -       (*sound.mach.init)();
3008 -       LEAVE(TRACE_ON,"sound_init");
3009 -}
3010 -
3011 -
3012 -static int sound_set_format(int format)
3013 -{
3014 -       ENTER(TRACE_ON,"sound_set_format");
3015 -       LEAVE(TRACE_ON,"sound_set_format");
3016 -       return(*sound.mach.setFormat)(format);
3017 -}
3018 -
3019 -
3020 -static int sound_set_speed(int speed)
3021 -{
3022 -       ENTER(TRACE_ON,"sound_set_speed");
3023 -       if (speed < 0) {
3024 -               LEAVE(TRACE_ON,"sound_set_speed");
3025 -               return(sound.soft.speed);
3026 -       }
3027 -
3028 -       sound.soft.speed = speed;
3029 -       (*sound.mach.init)();
3030 -       if (sound.minDev == SND_DEV_DSP)
3031 -               sound.dsp.speed = sound.soft.speed;
3032 -
3033 -       /* LoCoMo Audio clock */
3034 -       Collie_audio_clock_off();
3035 -       Collie_audio_clock_on();
3036 -
3037 -       LEAVE(TRACE_ON,"sound_set_speed");
3038 -       return(sound.soft.speed);
3039 -}
3040  
3041  
3042  static int sound_set_stereo(int stereo)
3043  {
3044 -       ENTER(TRACE_ON,"sound_set_stereo");
3045 +/* Only stereo is supported by hardware */
3046         if (stereo < 0) {
3047 -               LEAVE(TRACE_ON,"sound_set_stereo");
3048 -               return(sound.soft.stereo);
3049 +               return(sound.stereo);
3050         }
3051 +       return(1);
3052 +}
3053  
3054 -       stereo = !!stereo;    /* should be 0 or 1 now */
3055 -
3056 -       sound.soft.stereo = stereo;
3057 -       if (sound.minDev == SND_DEV_DSP)
3058 -               sound.dsp.stereo = stereo;
3059 -       //(*sound.mach.init)();
3060  
3061 -       LEAVE(TRACE_ON,"sound_set_stereo");
3062 -       return(stereo);
3063 -}
3064 +/* Higher level stuff ************************************************/
3065  
3066  /*
3067   * /dev/mixer abstraction
3068 @@ -2109,20 +882,15 @@
3069  
3070  static int mixer_open(struct inode *inode, struct file *file)
3071  {
3072 -       ENTER(TRACE_ON,"mixer_open");
3073         MOD_INC_USE_COUNT;
3074         mixer.busy = 1;
3075 -       LEAVE(TRACE_ON,"mixer_open");
3076         return 0;
3077  }
3078  
3079 -
3080  static int mixer_release(struct inode *inode, struct file *file)
3081  {
3082 -       ENTER(TRACE_ON,"mixer_release");
3083         mixer.busy = 0;
3084         MOD_DEC_USE_COUNT;
3085 -       LEAVE(TRACE_ON,"mixer_release");
3086         return 0;
3087  }
3088  
3089 @@ -2132,58 +900,37 @@
3090  {
3091         int data;
3092  
3093 -       ENTER(TRACE_ON,"mixer_ioctl");
3094 -       switch (sound.mach.type) {
3095 -       case DMASND_COLLIE:
3096 -       {
3097 -               switch (cmd) {
3098 -                       case SOUND_MIXER_READ_DEVMASK:
3099 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3100 -                               return IOCTL_OUT(arg, SOUND_MASK_VOLUME );
3101 -                       case SOUND_MIXER_READ_RECMASK:
3102 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3103 -                               return IOCTL_OUT(arg, 0);
3104 -                       case SOUND_MIXER_READ_STEREODEVS:
3105 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3106 -                               return IOCTL_OUT(arg, SOUND_MASK_VOLUME);
3107 -                       case SOUND_MIXER_READ_CAPS:
3108 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3109 -                               return IOCTL_OUT(arg, 0);
3110 -
3111 -                       case SOUND_MIXER_WRITE_VOLUME:
3112 -                               IOCTL_IN(arg, data);
3113 -                               Collie_Set_Volume(data);
3114 -                       case SOUND_MIXER_READ_VOLUME:
3115 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3116 -                               return IOCTL_OUT(arg, Collie_Get_Volume());
3117 -
3118 -                       case SOUND_MIXER_READ_TREBLE:
3119 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3120 -                               return IOCTL_OUT(arg, 0);
3121 -                       case SOUND_MIXER_WRITE_TREBLE:
3122 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3123 -                               return IOCTL_OUT(arg, 0);
3124 -
3125 -                       case SOUND_MIXER_WRITE_MIC:
3126 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3127 -                               return IOCTL_OUT(arg, 0);
3128 -                       case SOUND_MIXER_READ_MIC:
3129 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3130 -                               return IOCTL_OUT(arg, 0);
3131 -
3132 -                       case SOUND_MIXER_READ_SPEAKER:
3133 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3134 -                               return IOCTL_OUT(arg, 0);
3135 -                       case SOUND_MIXER_WRITE_SPEAKER:
3136 -                               LEAVE(TRACE_ON,"mixer_ioctl");
3137 -                               return IOCTL_OUT(arg, 0);
3138 -               }
3139 -                       break;
3140 -       }
3141 -       }
3142 -       LEAVE(TRACE_ON,"mixer_ioctl");
3143 +       switch (cmd) {
3144 +               case SOUND_MIXER_READ_DEVMASK:
3145 +                       return IOCTL_OUT(arg, headphone ? SOUND_MASK_VOLUME : 0 );
3146 +               case SOUND_MIXER_READ_RECMASK:
3147 +                       return IOCTL_OUT(arg, 0);
3148 +               case SOUND_MIXER_READ_STEREODEVS:
3149 +                       return IOCTL_OUT(arg, headphone ? SOUND_MASK_VOLUME : 0 );
3150 +               case SOUND_MIXER_READ_CAPS:
3151 +                       return IOCTL_OUT(arg, 0);
3152 +
3153 +               case SOUND_MIXER_WRITE_VOLUME:
3154 +                       IOCTL_IN(arg, data);
3155 +                       Collie_Set_Volume(data);
3156 +               case SOUND_MIXER_READ_VOLUME:
3157 +                       return IOCTL_OUT(arg, Collie_Get_Volume());
3158 +               case SOUND_MIXER_READ_TREBLE:
3159 +                       return IOCTL_OUT(arg, 0);
3160 +               case SOUND_MIXER_WRITE_TREBLE:
3161 +                       return IOCTL_OUT(arg, 0);
3162 +
3163 +               case SOUND_MIXER_WRITE_MIC:
3164 +                       return IOCTL_OUT(arg, 0);
3165 +               case SOUND_MIXER_READ_MIC:
3166 +                       return IOCTL_OUT(arg, 0);
3167 +
3168 +               case SOUND_MIXER_READ_SPEAKER:
3169 +                       return IOCTL_OUT(arg, 0);
3170 +               case SOUND_MIXER_WRITE_SPEAKER:
3171 +                       return IOCTL_OUT(arg, 0);
3172 +       }       
3173         return -EINVAL;
3174 -
3175  }
3176  
3177  
3178 @@ -2198,32 +945,13 @@
3179  
3180  static void __init mixer_init(void)
3181  {
3182 -#ifndef MODULE
3183 -       int mixer_unit;
3184 -#endif
3185 -       ENTER(TRACE_ON,"mixer_init");
3186         mixer_unit = register_sound_mixer(&mixer_fops, -1);
3187         if (mixer_unit < 0) {
3188 -               LEAVE(TRACE_ON,"mixer_init");
3189                 return;
3190         }
3191 -
3192         mixer.busy = 0;
3193 -       sound.treble = 0;
3194 -       sound.bass = 0;
3195 -       switch (sound.mach.type) {
3196 -               case DMASND_COLLIE:
3197 -                 //                    sound.volume_left  = 0x3c;
3198 -                 //                    sound.volume_right = 0x3c;
3199 -                       sound.volume_left  = 80;
3200 -                       sound.volume_right = 80;
3201 -                       collie_main_volume = sound.volume_left;
3202 -                       break;
3203 -       }
3204 -
3205 -       //      printk("mixer_init : ret \n");
3206 -
3207 -       LEAVE(TRACE_ON,"mixer_init");
3208 +       sound.volume  = 80;
3209 +       Collie_volume_set(sound.volume);
3210  }
3211  
3212  /* This function allocates the buffer structure array and buffer data space
3213 @@ -2237,11 +965,9 @@
3214         char *dmabuf = 0;
3215         dma_addr_t dmaphys = 0;
3216  
3217 -       ENTER(TRACE_ON,"sq_allocate_buffers");
3218         DPRINTK("sq_allocate_buffers\n");
3219  
3220         if (s->buffers) {
3221 -               LEAVE(TRACE_ON,"sq_allocate_buffers");
3222                 return -EBUSY;
3223         }
3224  
3225 @@ -2279,10 +1005,8 @@
3226  
3227                 b->start = dmabuf;
3228                 b->dma_addr = dmaphys;
3229 +               b->idx = frag;
3230                 sema_init(&b->sem, 1);
3231 -               DPRINTK("buf %d: start %p dma %p\n", frag, b->start,
3232 -                       b->dma_addr);
3233 -
3234                 dmabuf += s->fragsize;
3235                 dmaphys += s->fragsize;
3236                 dmasize -= s->fragsize;
3237 @@ -2291,13 +1015,12 @@
3238         s->buf_idx = 0;
3239         s->buf = &s->buffers[0];
3240  
3241 -       LEAVE(TRACE_ON,"sq_allocate_buffers");
3242 +
3243         return 0;
3244  
3245  err:
3246         printk("sound driver : unable to allocate audio memory\n ");
3247         sq_release_buffers(s);
3248 -       LEAVE(TRACE_ON,"sq_allocate_buffers");
3249         return -ENOMEM;
3250  }
3251  
3252 @@ -2307,7 +1030,6 @@
3253  
3254  static void sq_release_buffers(audio_stream_t * s)
3255  {
3256 -       ENTER(TRACE_ON,"sq_release_buffers");
3257         DPRINTK("sq_release_buffers\n");
3258  
3259         /* ensure DMA won't run anymore */
3260 @@ -2328,7 +1050,6 @@
3261  
3262         s->buf_idx = 0;
3263         s->buf = NULL;
3264 -       LEAVE(TRACE_ON,"sq_release_buffers");
3265  }
3266  
3267  static ssize_t sq_write(struct file *file, const char *src, size_t uLeft,
3268 @@ -2339,27 +1060,20 @@
3269         u_char *dest;
3270         ssize_t uUsed, bUsed, bLeft, ret = 0;
3271  
3272 -       ENTER(TRACE_WRITE,"sq_write");
3273         DPRINTK("sq_write: uLeft=%d\n", uLeft);
3274  
3275 -       /* OP_SHDN on */
3276 -       Collie_OP_SHDN_on();
3277 -
3278         switch (file->f_flags & O_ACCMODE) {
3279         case O_WRONLY:
3280         case O_RDWR:
3281                 break;
3282         default: 
3283 -               LEAVE(TRACE_WRITE,"sq_write1");
3284                 return -EPERM;
3285         } 
3286  
3287         if (!s->buffers && sq_allocate_buffers(s)) {
3288 -               LEAVE(TRACE_WRITE,"sq_write2");
3289                 return -ENOMEM;
3290         }
3291  
3292 -#if 1
3293         if (collie_resume == 1) {
3294                 int     i;
3295                 collie_resume = 0;
3296 @@ -2367,10 +1081,9 @@
3297                         udelay(1);
3298                 }
3299         }
3300 -#endif
3301  #ifdef CONFIG_PM
3302         /* Auto Power off cancel */
3303 -       autoPowerCancel = 0;
3304 +//     autoPowerCancel = 0;
3305  #endif
3306  
3307         while (uLeft > 0) {
3308 @@ -2379,41 +1092,30 @@
3309                 /* Wait for a buffer to become free */
3310                 if (file->f_flags & O_NONBLOCK) {
3311                         ret = -EAGAIN;
3312 -                       ENTER(TRACE_SEM,"down_try sem");
3313                         if (down_trylock(&b->sem)) {
3314 -                               LEAVE(TRACE_SEM,"down_try1 sem");
3315                                 break;
3316                         }
3317 -                       LEAVE(TRACE_SEM,"down_try2 sem");
3318                 } else {
3319                         ret = -ERESTARTSYS;
3320 -                       ENTER(TRACE_SEM,"down_int sem");
3321 -                       //printk("### 0x%08x:%d\n", &b->sem.count, atomic_read(&b->sem.count));
3322                         if (down_interruptible(&b->sem)) {
3323 -                               LEAVE(TRACE_SEM,"down_int1 sem");
3324                                 break;
3325                         }
3326 -                       LEAVE(TRACE_SEM,"down_int2 sem");
3327                 }
3328  
3329                 dest = b->start + b->size;
3330                 bUsed = 0;
3331                 bLeft = s->fragsize - b->size;
3332  
3333 -               if (ct_func) {
3334 -                       uUsed = ct_func(src, uLeft, dest, &bUsed, bLeft);
3335 +               if (collie_ct_s16) {
3336 +                       uUsed = collie_ct_s16(src, uLeft, dest, &bUsed, bLeft);
3337                         cpu_cache_clean_invalidate_range((unsigned long)dest,
3338                                 (unsigned long)(dest+(audio_fragsize)), 0);
3339                 } else {
3340 -                       LEAVE(TRACE_WRITE,"sq_write3");
3341                         return -EFAULT;
3342                 }
3343  
3344                 if (uUsed < 0) {
3345 -                       ENTER(TRACE_SEM,"up sem");
3346                         up(&b->sem);
3347 -                       LEAVE(TRACE_SEM,"up sem");
3348 -                       LEAVE(TRACE_WRITE,"sq_write4");
3349                         return -EFAULT;
3350                 }
3351                 src += uUsed;
3352 @@ -2421,9 +1123,7 @@
3353                 b->size += bUsed;
3354  
3355                 if (b->size < s->fragsize) {
3356 -                       ENTER(TRACE_SEM,"up sem");
3357                         up(&b->sem);
3358 -                       LEAVE(TRACE_SEM,"up sem");
3359                         break;
3360                 }
3361  
3362 @@ -2431,7 +1131,7 @@
3363                 sa1100_dma_queue_buffer(COLLIE_SOUND_DMA_CHANNEL,
3364                                         (void *) b, b->dma_addr, b->size);
3365  
3366 -               Collie_volume_half_adjust();
3367 +               Collie_volume_set(sound.volume);
3368  
3369                 b->size = 0;    /* indicate that the buffer has been sent */
3370                 NEXT_BUF(s, buf);
3371 @@ -2440,7 +1140,6 @@
3372         if ((src - buffer0))
3373                 ret = src - buffer0;
3374         DPRINTK("sq_write: return=%d\n", ret);
3375 -       LEAVE(TRACE_WRITE,"sq_write0");
3376         return ret;
3377  }
3378  
3379 @@ -2450,7 +1149,6 @@
3380         unsigned int mask = 0;
3381         int i;
3382  
3383 -       ENTER(TRACE_ON,"sq_poll");
3384         DPRINTK("sq_poll(): mode=%s%s\n",
3385                 (file->f_mode & FMODE_READ) ? "r" : "",
3386                 (file->f_mode & FMODE_WRITE) ? "w" : "");
3387 @@ -2458,12 +1156,9 @@
3388         if (file->f_mode & FMODE_WRITE) {
3389                 if (!output_stream.buffers 
3390                     && sq_allocate_buffers(&output_stream)) {
3391 -                       LEAVE(TRACE_ON,"sq_poll");
3392                         return -ENOMEM;
3393                 }
3394 -               ENTER(TRACE_SEM,"poll_wait wait");
3395                 poll_wait(file, &output_stream.buf->sem.wait, wait);
3396 -               LEAVE(TRACE_SEM,"poll_wait wait");
3397         }
3398  
3399         if (file->f_mode & FMODE_WRITE) {
3400 @@ -2477,65 +1172,33 @@
3401                 (mask & POLLIN) ? "r" : "",
3402                 (mask & POLLOUT) ? "w" : "");
3403  
3404 -       LEAVE(TRACE_ON,"sq_poll");
3405         return mask;
3406  }
3407  
3408  static int sq_open(struct inode *inode, struct file *file)
3409  {
3410 -       ENTER(TRACE_ON,"sq_open");
3411         DPRINTK("sq_open\n");
3412  
3413         if (((file->f_flags & O_ACCMODE) == O_WRONLY)
3414          || ((file->f_flags & O_ACCMODE) == O_RDWR)) {
3415 -#if 0
3416 -               MOD_INC_USE_COUNT;
3417 -               while(audio_wr_refcount) {
3418 -                       SLEEP(open_queue, ONE_SECOND);
3419 -                       if (SIGNAL_RECEIVED) {
3420 -                               MOD_DEC_USE_COUNT;
3421 -                               LEAVE(TRACE_ON,"sq_open");
3422 -                               return -EINTR;
3423 -                       }
3424 -               }
3425 -#else
3426                 if (audio_wr_refcount) {
3427                         DPRINTK(" sq_open        EBUSY\n");
3428 -                       LEAVE(TRACE_ON,"sq_open");
3429                         return -EBUSY;
3430                 }
3431                 MOD_INC_USE_COUNT;
3432 -#endif
3433                 audio_wr_refcount++;
3434         } else {
3435                 DPRINTK(" sq_open        EINVAL\n");
3436 -               LEAVE(TRACE_ON,"sq_open");
3437                 return -EINVAL;
3438         }
3439  
3440 -       if (audio_wr_refcount == 1) {
3441 -               DPRINTK("cold\n");
3442 -
3443 -               audio_fragsize = AUDIO_FRAGSIZE_DEFAULT;
3444 -               audio_nbfrags = AUDIO_NBFRAGS_DEFAULT;
3445 -               sq_release_buffers(&output_stream);
3446 -               sound.minDev = MINOR(inode->i_rdev) & 0x0f;
3447 -               sound.soft = sound.dsp;
3448 -               sound.hard = sound.dsp;
3449 -
3450 -               if ((MINOR(inode->i_rdev) & 0x0f) == SND_DEV_AUDIO) {
3451 -                       sound_set_speed(8000);
3452 -                       sound_set_stereo(0);
3453 -                       sound_set_format(AFMT_MU_LAW);
3454 -               }
3455 -               Collie_audio_power_on();
3456 -       }
3457  
3458 -#if 0
3459 -       MOD_INC_USE_COUNT;
3460 -#endif
3461 -       LEAVE(TRACE_ON,"sq_open");
3462 -       return 0;
3463 +       audio_fragsize = AUDIO_FRAGSIZE_DEFAULT;
3464 +       audio_nbfrags = AUDIO_NBFRAGS_DEFAULT;
3465 +       sq_release_buffers(&output_stream);
3466 +       output_stream.buf_idx=0;
3467 +       Collie_audio_power_on();
3468 +       return 0;
3469  }
3470  
3471  static int sq_fsync(struct file *filp, struct dentry *dentry)
3472 @@ -2543,11 +1206,9 @@
3473         audio_stream_t *s = &output_stream;
3474         audio_buf_t *b = s->buf;
3475  
3476 -       ENTER(TRACE_ON,"sq_fsync");
3477         DPRINTK("sq_fsync\n");
3478  
3479         if (!s->buffers) {
3480 -               LEAVE(TRACE_ON,"sq_fsync");
3481                 return 0;
3482         }
3483  
3484 @@ -2557,12 +1218,10 @@
3485  
3486  #ifdef CONFIG_PM
3487                 /* Auto Power off cancel */
3488 -               autoPowerCancel = 0;
3489 +//             autoPowerCancel = 0;
3490  #endif
3491  
3492 -               ENTER(TRACE_SEM,"down sem");
3493                 down(&b->sem);
3494 -               LEAVE(TRACE_SEM,"down sem");
3495                 sa1100_dma_queue_buffer(COLLIE_SOUND_DMA_CHANNEL,
3496                                         (void *) b, b->dma_addr, b->size);
3497                 b->size = 0;
3498 @@ -2576,23 +1235,15 @@
3499          * - the buffer was already free thus nothing else to sync.
3500          */
3501         b = s->buffers + ((s->nbfrags + s->buf_idx - 1) % s->nbfrags);
3502 -       ENTER(TRACE_SEM,"down-int sem");
3503         if (down_interruptible(&b->sem)) {
3504 -               LEAVE(TRACE_SEM,"down-int sem");
3505 -               LEAVE(TRACE_ON,"sq_fsync");
3506                 return -EINTR;
3507         }
3508 -       LEAVE(TRACE_SEM,"down-int sem");
3509 -       ENTER(TRACE_SEM,"up sem");
3510         up(&b->sem);
3511 -       LEAVE(TRACE_SEM,"up sem");
3512 -       LEAVE(TRACE_ON,"sq_fsync");
3513         return 0;
3514  }
3515  
3516  static int sq_release(struct inode *inode, struct file *file)
3517  {
3518 -       ENTER(TRACE_ON,"sq_release");
3519         DPRINTK("sq_release\n");
3520  
3521         switch (file->f_flags & O_ACCMODE) {
3522 @@ -2606,24 +1257,12 @@
3523         }       
3524  
3525         if (!audio_wr_refcount) {
3526 -               sound.soft = sound.dsp;
3527 -               sound.hard = sound.dsp;
3528 -               sound_silence();
3529 -               Collie_OP_SHDN_off();
3530 +               sa1100_dma_stop(COLLIE_SOUND_DMA_CHANNEL);
3531 +               sa1100_dma_flush_all(COLLIE_SOUND_DMA_CHANNEL);
3532 +               Collie_audio_power_off();
3533         } 
3534  
3535 -#if 0
3536 -       switch (file->f_flags & O_ACCMODE) {
3537 -       case O_WRONLY:
3538 -       case O_RDWR:
3539 -               if (!audio_wr_refcount) {
3540 -                       WAKE_UP(open_queue);
3541 -               }
3542 -       }
3543 -#endif
3544 -
3545         MOD_DEC_USE_COUNT;
3546 -       LEAVE(TRACE_ON,"sq_release");
3547         return 0;
3548  }
3549  
3550 @@ -2634,8 +1273,8 @@
3551         u_long fmt;
3552         int data;
3553         long val;
3554 +//     audio_buf_info abinfo;
3555  
3556 -       ENTER(TRACE_ON,"sq_ioctl");
3557         switch (cmd) {
3558         case SNDCTL_DSP_RESET:
3559                 switch (file->f_flags & O_ACCMODE) {
3560 @@ -2643,11 +1282,9 @@
3561                 case O_RDWR:
3562                         sq_release_buffers(&output_stream);
3563                 }
3564 -               LEAVE(TRACE_ON,"sq_ioctl");
3565                 return 0;
3566         case SNDCTL_DSP_POST:
3567         case SNDCTL_DSP_SYNC:
3568 -               LEAVE(TRACE_ON,"sq_ioctl");
3569                 return sq_fsync(file, file->f_dentry);
3570  
3571                 /* ++TeSche: before changing any of these it's
3572 @@ -2656,59 +1293,34 @@
3573         case SNDCTL_DSP_SPEED:
3574                 sq_fsync(file, file->f_dentry);
3575                 IOCTL_IN(arg, data);
3576 -               LEAVE(TRACE_ON,"sq_ioctl");
3577                 return IOCTL_OUT(arg, sound_set_speed(data));
3578         case SNDCTL_DSP_STEREO:
3579                 sq_fsync(file, file->f_dentry);
3580                 IOCTL_IN(arg, data);
3581 -               LEAVE(TRACE_ON,"sq_ioctl");
3582                 return IOCTL_OUT(arg, sound_set_stereo(data));
3583 -       case SOUND_PCM_WRITE_CHANNELS:
3584 +       case SNDCTL_DSP_CHANNELS:
3585                 sq_fsync(file, file->f_dentry);
3586                 IOCTL_IN(arg, data);
3587 -               LEAVE(TRACE_ON,"sq_ioctl");
3588                 return IOCTL_OUT(arg, sound_set_stereo(data-1)+1);
3589         case SNDCTL_DSP_SETFMT:
3590                 sq_fsync(file, file->f_dentry);
3591                 IOCTL_IN(arg, data);
3592 -               LEAVE(TRACE_ON,"sq_ioctl");
3593 -               return IOCTL_OUT(arg, sound_set_format(data));
3594 +               return IOCTL_OUT(arg, CollieSetFormat(data));
3595         case SNDCTL_DSP_GETFMTS:
3596 -               fmt = 0;
3597 -               if (sound.trans) {
3598 -                       if (sound.trans->ct_ulaw)
3599 -                               fmt |= AFMT_MU_LAW;
3600 -                       if (sound.trans->ct_alaw)
3601 -                               fmt |= AFMT_A_LAW;
3602 -                       if (sound.trans->ct_s8)
3603 -                               fmt |= AFMT_S8;
3604 -                       if (sound.trans->ct_u8)
3605 -                               fmt |= AFMT_U8;
3606 -                       if (sound.trans->ct_s16be)
3607 -                               fmt |= AFMT_S16_BE;
3608 -                       if (sound.trans->ct_u16be)
3609 -                               fmt |= AFMT_U16_BE;
3610 -                       if (sound.trans->ct_s16le)
3611 -                               fmt |= AFMT_S16_LE;
3612 -                       if (sound.trans->ct_u16le)
3613 -                               fmt |= AFMT_U16_LE;
3614 -               }
3615 -               LEAVE(TRACE_ON,"sq_ioctl");
3616 +               fmt = AFMT_S16_LE;
3617                 return IOCTL_OUT(arg, fmt);
3618         case SNDCTL_DSP_GETBLKSIZE:
3619 -               LEAVE(TRACE_ON,"sq_ioctl");
3620                 return IOCTL_OUT(arg, audio_fragsize);
3621         case SNDCTL_DSP_SUBDIVIDE:
3622                 break;
3623         case SNDCTL_DSP_SETFRAGMENT:
3624                 if (output_stream.buffers) {
3625 -                       LEAVE(TRACE_ON,"sq_ioctl");
3626                         return -EBUSY;
3627                 }
3628                 get_user(val, (long *) arg);
3629                 audio_fragsize = 1 << (val & 0xFFFF);
3630 -               if (audio_fragsize < 16)
3631 -                       audio_fragsize = 16;
3632 +               if (audio_fragsize < 256)
3633 +                       audio_fragsize = 256;
3634                 if (audio_fragsize > 16384)
3635                         audio_fragsize = 16384;
3636                 audio_nbfrags = (val >> 16) & 0x7FFF;
3637 @@ -2717,46 +1329,54 @@
3638                 if (audio_nbfrags * audio_fragsize > 128 * 1024)
3639                         audio_nbfrags = 128 * 1024 / audio_fragsize;
3640                 if (sq_allocate_buffers(&output_stream)) {
3641 -                       LEAVE(TRACE_ON,"sq_ioctl");
3642                         return -ENOMEM;
3643                 }
3644 -               LEAVE(TRACE_ON,"sq_ioctl");
3645                 return 0;
3646  
3647 -#if 1 // 2003.2.14
3648 +/*     case SNDCTL_DSP_GETOSPACE:
3649 +               abinfo.fragsize   = audio_fragsize;
3650 +               abinfo.fragstotal = audio_nbfrags;
3651 +               abinfo.fragments  = lastsent-output_stream.buf_idx;
3652 +               if (abinfo.fragments<0)
3653 +                   abinfo.fragments += abinfo.fragstotal;                  
3654 +               abinfo.bytes      = abinfo.fragments*abinfo.fragsize;
3655 +               return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
3656 +*/
3657         case SNDCTL_DSP_GETOSPACE:
3658             {
3659 -               audio_buf_info inf = { 0, };
3660 +               audio_stream_t *s = &output_stream;
3661 +               audio_buf_info *inf = (audio_buf_info *) arg;
3662 +               int err = verify_area(VERIFY_WRITE, inf, sizeof(*inf));
3663                 int i;
3664 +               int frags = 0, bytes = 0;
3665  
3666 -               if (!(file->f_mode & FMODE_WRITE))
3667 -                       return -EINVAL;
3668 -               if (!output_stream.buffers && sq_allocate_buffers(&output_stream))
3669 -                       return -ENOMEM;
3670 -               for (i = 0; i < output_stream.nbfrags; i++) {
3671 -                       if (atomic_read(&output_stream.buffers[i].sem.count) > 0) {
3672 -                               if (output_stream.buffers[i].size == 0)
3673 -                                       inf.fragments++;
3674 -                               inf.bytes += output_stream.fragsize - output_stream.buffers[i].size;
3675 -                       }
3676 +               if (err)
3677 +                       return err;
3678 +               if (output_stream.buffers)  {
3679 +                   for (i = 0; i < s->nbfrags; i++) {
3680 +                       if (atomic_read(&s->buffers[i].sem.count) > 0) {
3681 +                               if (s->buffers[i].size == 0) frags++;
3682 +                               bytes += s->fragsize - s->buffers[i].size;
3683 +                       }
3684 +                   }
3685 +                   put_user(s->nbfrags, &inf->fragstotal);
3686 +                   put_user(s->fragsize, &inf->fragsize);
3687 +               } else {
3688 +                   frags=audio_nbfrags;
3689 +                   bytes=frags*audio_fragsize;
3690 +                   put_user(frags, &inf->fragstotal);
3691 +                   put_user(audio_fragsize, &inf->fragsize);
3692                 }
3693 -               inf.fragstotal = output_stream.nbfrags;
3694 -               inf.fragsize = output_stream.fragsize;
3695 -               return copy_to_user((void *)arg, &inf, sizeof(inf));
3696 +               put_user(frags, &inf->fragments);
3697 +               return put_user(bytes, &inf->bytes);
3698             }
3699 -#endif
3700 -
3701  
3702         default:
3703 -               LEAVE(TRACE_ON,"sq_ioctl");
3704                 return mixer_ioctl(inode, file, cmd, arg);
3705         }
3706 -       LEAVE(TRACE_ON,"sq_ioctl");
3707         return -EINVAL;
3708  }
3709  
3710 -
3711 -
3712  static struct file_operations sq_fops =
3713  {
3714         llseek: sound_lseek,
3715 @@ -2770,40 +1390,18 @@
3716  
3717  static void __init sq_init(void)
3718  {
3719 -#ifndef MODULE
3720 -       int sq_unit;
3721 -#endif
3722 -       ENTER(TRACE_ON,"sq_init");
3723         sq_unit = register_sound_dsp(&sq_fops, -1);
3724         if (sq_unit < 0) {
3725 -               LEAVE(TRACE_ON,"sq_init");
3726                 return;
3727         }
3728  
3729 -       /* whatever you like as startup mode for /dev/dsp,
3730 -        * (/dev/audio hasn't got a startup mode). note that
3731 -        * once changed a new open() will *not* restore these!
3732 -        */
3733 -       sound.dsp.format = AFMT_S16_LE;
3734 -
3735 -       sound.dsp.stereo = 0;
3736 -       sound.dsp.size = 16;
3737 -
3738 -       /* set minimum rate possible without expanding */
3739 -       switch (sound.mach.type) {
3740 -               case DMASND_COLLIE:
3741 -                       sound.dsp.speed = 8000;
3742 -                       break;
3743 -       }
3744 -
3745 -       /* before the first open to /dev/dsp this wouldn't be set */
3746 -       sound.soft = sound.dsp;
3747 -       sound.hard = sound.dsp;
3748 -       sound.trans = &transCollie;
3749 -
3750 -       CollieSetFormat(sound.dsp.format);
3751 -       sound_silence();
3752 -       LEAVE(TRACE_ON,"sq_init");
3753 +       sound.format = AFMT_S16_LE;
3754 +       sound.stereo = 1;
3755 +       sound.speed = 44100;
3756 +
3757 +       CollieSetFormat(AFMT_S16_LE);
3758 +       Collie_audio_power_off();
3759 +       output_stream.buf=output_stream.buffers=NULL;
3760  }
3761  
3762  /*
3763 @@ -2816,9 +1414,7 @@
3764         char *buffer = state.buf;
3765         int len = 0;
3766  
3767 -       ENTER(TRACE_ON,"state_open");
3768         if (state.busy) {
3769 -               LEAVE(TRACE_ON,"state_open");
3770                 return -EBUSY;
3771         }
3772  
3773 @@ -2828,8 +1424,8 @@
3774  
3775         len += sprintf(buffer+len, "  COLLIE DMA sound driver:\n");
3776  
3777 -       len += sprintf(buffer+len, "\tsound.format = 0x%x", sound.soft.format);
3778 -       switch (sound.soft.format) {
3779 +       len += sprintf(buffer+len, "\tsound.format = 0x%x", sound.format);
3780 +       switch (sound.format) {
3781         case AFMT_MU_LAW:
3782                 len += sprintf(buffer+len, " (mu-law)");
3783                 break;
3784 @@ -2857,22 +1453,19 @@
3785         }
3786         len += sprintf(buffer+len, "\n");
3787         len += sprintf(buffer+len, "\tsound.speed = %dHz (phys. %dHz)\n",
3788 -                      sound.soft.speed, sound.hard.speed);
3789 +                      sound.speed, sound.speed);
3790         len += sprintf(buffer+len, "\tsound.stereo = 0x%x (%s)\n",
3791 -                      sound.soft.stereo,
3792 -                      sound.soft.stereo ? "stereo" : "mono");
3793 +                      sound.stereo,
3794 +                      sound.stereo ? "stereo" : "mono");
3795         state.len = len;
3796 -       LEAVE(TRACE_ON,"state_open");
3797         return 0;
3798  }
3799  
3800  
3801  static int state_release(struct inode *inode, struct file *file)
3802  {
3803 -       ENTER(TRACE_ON,"state_release");
3804         state.busy = 0;
3805         MOD_DEC_USE_COUNT;
3806 -       LEAVE(TRACE_ON,"state_release");
3807         return 0;
3808  }
3809  
3810 @@ -2881,19 +1474,15 @@
3811                           loff_t *ppos)
3812  {
3813         int n = state.len - state.ptr;
3814 -       ENTER(TRACE_ON,"state_read");
3815         if (n > count)
3816                 n = count;
3817         if (n <= 0) {
3818 -               LEAVE(TRACE_ON,"state_read");
3819                 return 0;
3820         }
3821         if (copy_to_user(buf, &state.buf[state.ptr], n)) {
3822 -               LEAVE(TRACE_ON,"state_read");
3823                 return -EFAULT;
3824         }
3825         state.ptr += n;
3826 -       LEAVE(TRACE_ON,"state_read");
3827         return n;
3828  }
3829  
3830 @@ -2909,20 +1498,11 @@
3831  
3832  static void __init state_init(void)
3833  {
3834 -#ifndef MODULE
3835 -       int state_unit;
3836 -#endif
3837 -       ENTER(TRACE_ON,"state_unit");
3838         state_unit = register_sound_special(&state_fops, SND_DEV_STATUS);
3839         if (state_unit < 0) {
3840 -               LEAVE(TRACE_ON,"state_unit");
3841                 return;
3842         }
3843         state.busy = 0;
3844 -
3845 -       //      printk("state_init : ret \n");
3846 -       LEAVE(TRACE_ON,"state_unit");
3847 -
3848  }
3849  
3850  
3851 @@ -2930,8 +1510,6 @@
3852  
3853  static long long sound_lseek(struct file *file, long long offset, int orig)
3854  {
3855 -       ENTER(TRACE_ON,"sound_lseek");
3856 -       LEAVE(TRACE_ON,"sound_lseek");
3857         return -ESPIPE;
3858  }
3859  
3860 @@ -2941,96 +1519,41 @@
3861  static int collie_sound_pm_callback(struct pm_dev *pm_dev,
3862                                     pm_request_t req, void *data)
3863  {
3864 -       ENTER(TRACE_PM,"collie_sound_pm_callback");
3865         switch (req) {
3866         case PM_SUSPEND:
3867  #ifdef COLLIE_TRY_ONE
3868                 disable_irq(IRQ_GPIO_nREMOCON_INT);
3869  #endif
3870 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP 2001.12.19 */
3871 -               collieDoDelayedSilence();
3872 -               collieCancelDelayedSilence();
3873 -#endif
3874 -               if (audio_wr_refcount == 1) {
3875 -                       Collie_volume_off();
3876 -                       Collie_hard_mute_on();
3877 -                       Collie_soft_mute_on();
3878 -                       sa1100_dma_sleep((dmach_t)COLLIE_SOUND_DMA_CHANNEL);
3879 -
3880 -#if 0  /* H.Hayami SHARP 2001.12.18 */
3881 -#if !defined(CONFIG_COLLIE_TS) && !defined(CONFIG_COLLIE_TR0) && \
3882 -    !defined(CONFIG_COLLIE_TR1) && !defined(CONFIG_COLLIE_DEV)
3883 -                       Collie_volume_off();
3884 -#endif
3885 -#endif
3886 -                       Collie_OP_SHDN_off();
3887 -                       Collie_soft_DAC_off();
3888 -                       Collie_paif_off();
3889 -                       Collie_audio_clock_off();
3890 -                       //Collie_MIC_on();
3891 -                       Collie_DAC_off();
3892 -                       Collie_AMP_off();
3893 -               } else {
3894 -                       sa1100_dma_sleep((dmach_t)COLLIE_SOUND_DMA_CHANNEL);
3895 -               }
3896 -               Collie_sound_hard_term();
3897 +               sa1100_dma_sleep((dmach_t)COLLIE_SOUND_DMA_CHANNEL);
3898 +               Collie_audio_power_off();
3899                 break;
3900         case PM_RESUME:
3901 -/***** DEBUG *****g
3902 -printk("collie_sound_pm_callback: audio_wr_refcount=%d\n", audio_wr_refcount);
3903 -*****************/
3904 +
3905  #ifdef COLLIE_TRY_ONE
3906                 enable_irq(IRQ_GPIO_nREMOCON_INT);
3907  #endif
3908 -
3909 -               Collie_sound_hard_init();
3910 -
3911 -               if (audio_wr_refcount == 1) {
3912 -                       collie_resume = 1;
3913 -
3914 -                       Collie_audio_power_on();
3915 -
3916 -                       sa1100_dma_wakeup((dmach_t)COLLIE_SOUND_DMA_CHANNEL);
3917 -#if 0  /* H.Hayami SHARP 2001.12.18 */
3918 -                       Collie_soft_mute_off();
3919 -                       Collie_hard_mute_off();
3920 -#endif
3921 -               } else {
3922 +               Collie_sound_hard_init();    /* this needs to be done! */
3923 +               collie_resume = 1;
3924 +               Collie_audio_power_off();
3925 +               if (audio_wr_refcount) Collie_audio_power_on();
3926 +               if (collie_recording) Collie_recording_on();
3927 +               sa1100_dma_wakeup((dmach_t)COLLIE_SOUND_DMA_CHANNEL);
3928  #ifdef COLLIE_TRY_ONE
3929 -                 if ( !( GPLR & GPIO_nREMOCON_INT ) )
3930 +               if ( !( GPLR & GPIO_nREMOCON_INT ) )
3931                     Collie_DAC_on();
3932  #endif
3933 -                       sa1100_dma_wakeup((dmach_t)COLLIE_SOUND_DMA_CHANNEL);
3934 -               }
3935 -
3936 -
3937                 break;
3938 -
3939         }
3940 -       LEAVE(TRACE_PM,"collie_sound_pm_callback");
3941         return 0;
3942  }
3943  #endif
3944  
3945  
3946  #ifdef COLLIE_TRY_ONE
3947 -
3948 -static void collie_audio_on(void)
3949 -{
3950 -    while(1) {
3951 -      sleep_on(&audio_on);
3952 -
3953 -      /* DAC ON */
3954 -      Collie_DAC_on();
3955 -      //      printk("call audio on \n");
3956 -
3957 -    }
3958 -}
3959 -
3960  void Collie_rc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3961  {
3962 -  //  printk("int !\n");
3963 -  wake_up(&audio_on);
3964 +  headphone=!headphone;
3965 +  printk("%s headphone \n",headphone ? "connected" : "disconnected");
3966  }
3967  #endif
3968  
3969 @@ -3038,113 +1561,85 @@
3970  
3971  int __init Collie_sound_init(void)
3972  {
3973 -       int has_sound = 0;
3974 -
3975 -
3976 -       ENTER(TRACE_ON,"Collie_sound_init");
3977 -       has_sound = 1;
3978 -       sound.mach = machCollie;
3979 -
3980 -       if (!has_sound) {
3981 -               LEAVE(TRACE_ON,"Collie_sound_init");
3982 -               return -1;
3983 -       }
3984 -
3985 -#ifdef TRY_DELAY_OFF   /* H.Hayami SHARP 2001.12.19 */
3986 -       sema_init(&df_sem, 1);
3987 -       kernel_thread(collieDelayedSilence, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD);
3988 -#endif
3989 -
3990         Collie_sound_hard_init();
3991 -
3992 -       if (!sound.mach.irqinit()) {
3993 +       if (!CollieIrqInit()) {
3994                 printk("Sound driver: Interrupt initialization failed\n");
3995 -               LEAVE(TRACE_ON,"Collie_sound_init");
3996                 return -1;
3997         }
3998 -
3999 -       /* Set up sound queue, /dev/audio and /dev/dsp. */
4000 -
4001         /* Set default settings. */
4002         sq_init();
4003 -
4004         /* Set up /dev/sndstat. */
4005         state_init();
4006 -
4007         /* Set up /dev/mixer. */
4008         mixer_init();
4009 -
4010  #ifdef MODULE
4011         irq_installed = 1;
4012  #endif
4013 -
4014         printk("Collie Sound Driver Installed\n");
4015 -
4016  #ifdef CONFIG_PM
4017         collie_sound_pm_dev = pm_register(PM_SYS_DEV, 0,
4018                                                 collie_sound_pm_callback);
4019  #endif
4020 -
4021 -
4022  #ifdef COLLIE_TRY_ONE
4023         /* enable int sw */
4024         collie_rc_set_int_mode();
4025 -
4026         /* GPIO15(int):IN, GPIO18(sw):OUT */
4027         GPDR = ((GPDR)&~GPIO_nREMOCON_INT)|GPIO_REMOCON_ADC_SW;
4028 -
4029         /* GPIO15,18:not Alternate */
4030         GAFR &= ~(GPIO_nREMOCON_INT|GPIO_REMOCON_ADC_SW);
4031 -
4032 +       /* Initialize headphone state */
4033 +       headphone=!(GPLR & GPIO_nREMOCON_INT);
4034         /* GPIO15:Falling Edge */
4035 -       set_GPIO_IRQ_edge(GPIO_nREMOCON_INT, GPIO_FALLING_EDGE);
4036 -
4037 +       set_GPIO_IRQ_edge(GPIO_nREMOCON_INT, GPIO_BOTH_EDGES);
4038         /* Register interrupt handler */
4039         if ( request_irq(IRQ_GPIO_nREMOCON_INT, Collie_rc_interrupt,
4040 -                              SA_INTERRUPT, "INSERT-HEADPHONE", Collie_rc_interrupt))  {
4041 -               printk("%s: request_irq(%d) failed.\n",
4042 -                       __FUNCTION__, IRQ_GPIO_nREMOCON_INT);
4043 -       }
4044 +                              SA_INTERRUPT, "headphone", 0))   {
4045 +               printk("headphone: request_irq failed.\n");
4046  
4047 -       /* Make threads */
4048 -       kernel_thread(collie_audio_on,  NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD);
4049 +       }
4050 +       printk("Requested irq collie_rc succesfully (headphone) \n");
4051 +       printk("Headphone is now %s\n",headphone ? "connected" : "disconnected");
4052  #endif
4053  
4054 -
4055 -       LEAVE(TRACE_ON,"Collie_sound_init");
4056 +       Collie_audio_power_on();  // decreasing rec. noise?
4057 +       Collie_audio_power_off();
4058         return 0;
4059  }
4060  
4061 -module_init(Collie_sound_init);
4062 -
4063 -
4064  #ifdef MODULE
4065 -
4066 -int init_module(void)
4067 +static int collie_ssp_init_module(void)
4068  {
4069 -       ENTER(TRACE_ON,"init_module");
4070         Collie_sound_init();
4071 -       LEAVE(TRACE_ON,"init_module");
4072         return 0;
4073  }
4074  
4075 -void cleanup_module(void)
4076 +static void collie_ssp_cleanup_module(void)
4077  {
4078 -       ENTER(TRACE_ON,"cleanup_module");
4079 +#ifdef CONFIG_PM
4080 +       pm_unregister(collie_sound_pm_dev);
4081 +#endif
4082         if (irq_installed) {
4083 -               sound_silence();
4084 -               sound.mach.irqcleanup();
4085 +               sa1100_dma_stop(COLLIE_SOUND_DMA_CHANNEL);
4086 +               sa1100_dma_flush_all(COLLIE_SOUND_DMA_CHANNEL);
4087 +               Collie_audio_power_off();               
4088 +               sa1100_free_dma(COLLIE_SOUND_DMA_CHANNEL);
4089         }
4090 -
4091 -       sq_release_buffers();
4092 -
4093 -       if (mixer_unit >= 0)
4094 -               unregister_sound_mixer(mixer_unit);
4095 -       if (state_unit >= 0)
4096 -               unregister_sound_special(state_unit);
4097 -       if (sq_unit >= 0)
4098 -               unregister_sound_dsp(sq_unit);
4099 -       LEAVE(TRACE_ON,"cleanup_module");
4100 -}
4101 -
4102 +#ifdef COLLIE_TRY_ONE
4103 +       free_irq(IRQ_GPIO_nREMOCON_INT,0);
4104 +#endif
4105 +       unregister_sound_mixer(mixer_unit);
4106 +       unregister_sound_special(state_unit);
4107 +       unregister_sound_dsp(sq_unit);
4108 +       printk("collie_ssp has to go now, see you later!\n");
4109 +}
4110 +
4111 +module_init(collie_ssp_init_module);
4112 +module_exit(collie_ssp_cleanup_module);
4113 +MODULE_DESCRIPTION("Collie 16bit sound driver");
4114 +MODULE_AUTHOR("SHARP");
4115 +MODULE_LICENSE("GPL");
4116 +EXPORT_SYMBOL(Collie_recording_off);
4117 +EXPORT_SYMBOL(Collie_recording_on);
4118 +EXPORT_SYMBOL(collie_recording);
4119  #endif /* MODULE */
4120 +
4121 diff -Nuar linux-2.4.18/drivers/sound/collie_tc35143af.c linux-2.4.18p/drivers/sound/collie_tc35143af.c
4122 --- linux-2.4.18/drivers/sound/collie_tc35143af.c       1970-01-01 01:00:00.000000000 +0100
4123 +++ linux-2.4.18p/drivers/sound/collie_tc35143af.c      2004-10-13 15:26:20.336631864 +0200
4124 @@ -0,0 +1,1457 @@
4125 +/*
4126 +    TODO
4127 +
4128 +    buzzer compatibility is not fool proof - if an app starts sending buzzer ioctls
4129 +    and then write or read, nothing good will happen    / but this api is obsolote anyway
4130 +        
4131 +    mixer_ioctls missing: write/read_mic/igain  (there are sane defaults for those)
4132 +    
4133 +    fixed samplerate at 22050hz (mono,s16_le), although it can be changed
4134 +    between 8000-22050hz hardwarewise 
4135 +
4136 +    
4137 +    DONE
4138 +
4139 +    buffers are only allocated once, and freed when module is unloaded
4140 +    mute left channel when duplex playing & recording    
4141 +    cleanup
4142 +    depend on collie_ssp, and call needed functions when needed 
4143 +    (recording noise should be gone too as a consequence)
4144 +    lineo's getospace incorporated (getispace left alone)
4145 +    "optimized" default fragsize and number, so there is now no clicking all the time
4146 +    commented out scndctl_dsp_setfragment so that no application can set bad settings (eg.xmms)
4147 +    if you start reading from this device, than it won't let you write later unless you close it first
4148 +    (and vica-versa)    
4149 +    speaker is muted if nothing is playing, so noise is gone
4150 +    
4151 +*/
4152 +
4153 +#include <linux/module.h>
4154 +#include <linux/sched.h>
4155 +#include <linux/timer.h>
4156 +#include <linux/poll.h>
4157 +#include <linux/major.h>
4158 +#include <linux/config.h>
4159 +#include <linux/fcntl.h>
4160 +#include <linux/errno.h>
4161 +#include <linux/mm.h>
4162 +#include <linux/slab.h>
4163 +#include <linux/sound.h>
4164 +#include <linux/init.h>
4165 +#include <linux/delay.h>
4166 +
4167 +#include <linux/pm.h>
4168 +
4169 +#include <asm/system.h>
4170 +#include <asm/irq.h>
4171 +#include <asm/pgtable.h>
4172 +#include <asm/uaccess.h>
4173 +#include <asm/io.h>
4174 +#include <asm/dma.h>
4175 +
4176 +#include <asm/ucb1200.h>
4177 +#include <linux/soundcard.h>
4178 +#include <asm/proc/cache.h>
4179 +
4180 +#include <asm/arch/hardware.h>
4181 +#include <asm/arch/tc35143.h>
4182 +
4183 +#undef DEBUG
4184 +#ifdef DEBUG
4185 +#define DPRINTK( x... )  printk( ##x )
4186 +#else
4187 +#define DPRINTK( x... )
4188 +#endif
4189 +
4190 +extern int collie_recording;
4191 +extern void Collie_recording_on(void);
4192 +extern void Collie_recording_off(void);
4193 +
4194 +int collie_tc35143f_irq = -1;
4195 +int collie_tc35143f_input_irq = -1;
4196 +
4197 +#define        COLLIE_BUZZER_DMA_CHANNEL       (collie_tc35143f_irq)
4198 +#define        COLLIE_BUZZER_DMA_CHANNEL_INPUT (collie_tc35143f_input_irq)
4199 +#define COLLIE_GPIO_MIC                        GPIO_GPIO (17)
4200 +
4201 +#define SND_NDEVS      256     /* Number of supported devices */
4202 +#define SND_DEV_CTL    0       /* Control port /dev/mixer */
4203 +#define SND_DEV_SEQ    1       /* Sequencer output /dev/sequencer (FM synthesizer and MIDI output) */
4204 +#define SND_DEV_MIDIN  2       /* Raw midi access */
4205 +#define SND_DEV_DSP    3       /* Digitized voice /dev/dsp */
4206 +#define SND_DEV_AUDIO  4       /* Sparc compatible /dev/audio */
4207 +#define SND_DEV_DSP16  5       /* Like /dev/dsp but 16 bits/sample */
4208 +#define SND_DEV_STATUS 6       /* /dev/sndstat */
4209 +/* #7 not in use now. Was in 2.4. Free for use after v3.0. */
4210 +#define SND_DEV_SEQ2   8       /* /dev/sequencer, level 2 interface */
4211 +#define SND_DEV_SNDPROC 9      /* /dev/sndproc for programmable devices */
4212 +#define SND_DEV_PSS    SND_DEV_SNDPROC
4213 +
4214 +#ifdef MODULE
4215 +static int sq_unit = -1;
4216 +static int mixer_unit = -1;
4217 +static int state_unit = -1;
4218 +static int irq_installed = 0;
4219 +#endif /* MODULE */
4220 +
4221 +#ifdef CONFIG_PM
4222 +static struct pm_dev* collie_sound_pm_dev;
4223 +#endif
4224 +
4225 +/*** Some declarations ***********************************************/
4226 +static int collie_buzzer_volume = 100;
4227 +static int audio_igain = 0;
4228 +static int audio_iamp = 0x05;
4229 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4230 +static struct ucb1x00 * ucbstruct;
4231 +#endif
4232 +static int TC35143f_control_reg_a;
4233 +static int TC35143f_control_reg_b;
4234 +static int TC35143f_mode;
4235 +
4236 +#define AUDIO_NBFRAGS_DEFAULT   32
4237 +#define AUDIO_FRAGSIZE_DEFAULT  2048
4238 +
4239 +typedef struct {
4240 +       int size;               /* buffer size */
4241 +       char *start;            /* points to actual buffer */
4242 +       dma_addr_t dma_addr;    /* physical buffer address */
4243 +       struct semaphore sem;   /* down before touching the buffer */
4244 +       int master;             /* master owner for buffer allocation */
4245 +       u_int idx;              /* buffer index, so that we know which buffer was sent last*/
4246 +} audio_buf_t;
4247 +
4248 +typedef struct {
4249 +       audio_buf_t *buffers;   /* pointer to audio buffer structures */
4250 +       audio_buf_t *buf;       /* current buffer used by read/write */
4251 +       u_int buf_idx;          /* index for the pointer above... */
4252 +       u_int fragsize;         /* fragment i.e. buffer size */
4253 +       u_int nbfrags;          /* nbr of fragments i.e. buffers */
4254 +} audio_stream_t;
4255 +
4256 +static audio_stream_t output_stream, input_stream;
4257 +
4258 +#define NEXT_BUF(_s_,_b_) { \
4259 +       (_s_)->_b_##_idx++; \
4260 +       (_s_)->_b_##_idx %= (_s_)->nbfrags; \
4261 +       (_s_)->_b_ = (_s_)->buffers + (_s_)->_b_##_idx; }
4262 +                                       
4263 +/* Current specs for incoming audio data */
4264 +static u_int audio_fragsize=AUDIO_FRAGSIZE_DEFAULT;
4265 +static u_int audio_nbfrags=AUDIO_NBFRAGS_DEFAULT;
4266 +
4267 +static volatile int audio_refcount;    /* nbr of concurrent open() for playback */
4268 +typedef enum { REC,PLAY,NA,BUZZ } collie_tc_status_t;
4269 +static collie_tc_status_t collie_tc_status;
4270 +int collie_tc_muted;
4271 +
4272 +#define IOCTL_IN(arg, ret) \
4273 +       do { int error = get_user(ret, (int *)(arg)); \
4274 +               if (error) return error; \
4275 +       } while (0)
4276 +#define IOCTL_OUT(arg, ret)    ioctl_return((int *)(arg), ret)
4277 +
4278 +/*** "Translations" ************************************************************/
4279 +
4280 +static ssize_t collie_ct_s16(const u_char *userPtr, size_t userCount,
4281 +                            u_char frame[], ssize_t *frameUsed,
4282 +                            ssize_t frameLeft);
4283 +static signed short ct_out=0;
4284 +/*** Low level stuff *********************************************************/
4285 +
4286 +
4287 +typedef struct {
4288 +       int format;             /* AFMT_* */
4289 +       int stereo;             /* 0 = mono, 1 = stereo */
4290 +       int size;               /* 8/16 bit*/
4291 +       int speed;              /* speed */
4292 +       int volume;
4293 +} SETTINGS;
4294 +
4295 +static SETTINGS sound;
4296 +
4297 +#ifdef CONFIG_PM
4298 +//extern int autoPowerCancel;
4299 +#endif
4300 +
4301 +static void Collie_Set_Volume(int volume);
4302 +static int Collie_Get_Volume(void);
4303 +static int CollieIrqInit(void);
4304 +static int CollieSetFormat(int format);
4305 +static void Collie_sq_interrupt(void*, int);
4306 +static int sq_allocate_buffers(audio_stream_t*);
4307 +static void sq_release_buffers(audio_stream_t*);
4308 +
4309 +/*** Mid level stuff *********************************************************/
4310 +static int sound_set_speed(int speed);
4311 +
4312 +/*
4313 + * /dev/mixer abstraction
4314 + */
4315 +
4316 +struct sound_mixer {
4317 +    int busy;
4318 +};
4319 +
4320 +static struct sound_mixer mixer;
4321 +
4322 +/*
4323 + * /dev/sndstat
4324 + */
4325 +
4326 +/*** Common stuff ********************************************************/
4327 +
4328 +static long long sound_lseek(struct file *file, long long offset, int orig);
4329 +static inline int ioctl_return(int *addr, int value)
4330 +{
4331 +       if (value < 0) {
4332 +               return(value);
4333 +       }
4334 +       return put_user(value, addr)? -EFAULT: 0;
4335 +}
4336 +
4337 +static void wait_ms(int ten_ms)
4338 +{
4339 +       schedule_timeout(ten_ms);
4340 +}
4341 +
4342 +/*** Translation ************************************************************/
4343 +
4344 +static ssize_t collie_ct_s16(const u_char *userPtr, size_t userCount,
4345 +                          u_char frame[], ssize_t *frameUsed,
4346 +                          ssize_t frameLeft)
4347 +{
4348 +       ssize_t count, used;
4349 +       signed short *fp = (unsigned short *) &frame[*frameUsed];
4350 +       signed short *up = (unsigned short *) userPtr;
4351 +
4352 +       frameLeft >>= 1;
4353 +       userCount >>= 1;
4354 +       used = count = (userCount < frameLeft) ? userCount : frameLeft;
4355 +       
4356 +       while (count > 0) {
4357 +               signed short data;
4358 +               if (get_user(data, up++)) {
4359 +                       return -EFAULT;
4360 +               } /* lowpass filtering, not that it matters much - something is resonating inside the Zaurus at high frequencies ? */
4361 +               *fp++ =  ct_out = (short)( ( (long)data  + (long)ct_out ) >> 1LL );
4362 +               count--;
4363 +       }
4364 +       
4365 +       *frameUsed += used * 2;
4366 +       return used * 2;
4367 +}
4368 +
4369 +/*** HARDWARE dependent stuff *********************************************************/
4370 +#define        VOL_THRES       10
4371 +#define        CODEC_ASD_NUMERATOR 13
4372 +/*~ (9216000 / ( 32 * 22050 )) */
4373 +
4374 +static int Collie_Sampling_value(void)
4375 +{
4376 +  int asd = CODEC_ASD_NUMERATOR;
4377 +  DPRINTK("Collie_Sampling_value %x\n",asd);
4378 +  return asd;
4379 +}
4380 +
4381 +static void Collie_sound_hard_init(void)
4382 +{
4383 +  int asd;
4384 +
4385 +  DPRINTK("CollieInit\n");
4386 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4387 +  ucb1x00_enable(ucbstruct);
4388 +  ucb1x00_io_set_dir(ucbstruct,0, TC35143_GPIO_BUZZER_BIAS); 
4389 +  ucb1x00_disable(ucbstruct);
4390 +#else
4391 +  ucb1200_set_io_direction(TC35143_GPIO_BUZZER_BIAS, TC35143_IODIR_OUTPUT); 
4392 +#endif
4393 +
4394 +  DPRINTK("TC35143F Init");
4395 +
4396 +  // init MCP
4397 +  asd = Collie_Sampling_value();
4398 +  Ser4MCCR0 &= ~MCCR0_MCE;
4399 +  Ser4MCCR0 &= ~0xff;
4400 +  Ser4MCCR0 |= (MCCR0_ARE | MCCR0_ATE |MCCR0_ADM | MCCR0_ECS | asd);
4401 +  Ser4MCCR0 |= MCCR0_MCE;
4402 +  Ser4MCSR   = 0xffffffff;
4403 +
4404 +  DPRINTK("Init MCP %x\n",Ser4MCCR0);
4405 +}
4406 +
4407 +static void Collie_audio_power_on(void)
4408 +{
4409 +  if ( collie_buzzer_volume > 100 ) collie_buzzer_volume = 100;
4410 +  if ( collie_buzzer_volume < 0   ) collie_buzzer_volume = 0;
4411 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4412 +  ucb1x00_enable(ucbstruct);
4413 +#endif
4414 +  TC35143f_control_reg_a = ( TC35143_VDIV_22KHZ );
4415 +  TC35143f_control_reg_b = ( TC35143_VADMUTE | TC35143_VHSMUTE | ( 7 - collie_buzzer_volume / 13));
4416 +  TC35143f_mode = ( TC35143_VOFFCAN | TC35143_VCOF_22_OR_16KHZ );
4417 +  TC35143f_control_reg_a &= ~(TC35143_VINSEL_MASK | TC35143_VGAIN_MASK | TC35143_VAMP_MASK);
4418 +  TC35143f_control_reg_a |= (TC35143_VINSEL_VBIN2 | ((audio_igain & 0x3)<<11) | ((audio_iamp & 0x0f)<<7));
4419 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4420 +  ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_B , TC35143f_control_reg_b);
4421 +  ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_A , TC35143f_control_reg_a);
4422 +  ucb1x00_reg_write(ucbstruct,TC35143_MODE_REG      , TC35143f_mode );
4423 +  ucb1x00_io_write(ucbstruct, TC35143_GPIO_BUZZER_BIAS,0);
4424 +  ucb1x00_disable(ucbstruct);
4425 +#else
4426 +  ucb1200_write_reg(TC35143_CONTROL_REG_B , TC35143f_control_reg_b );
4427 +  ucb1200_write_reg(TC35143_MODE_REG      , TC35143f_mode );
4428 +  ucb1200_write_reg(TC35143_CONTROL_REG_A , TC35143f_control_reg_a );
4429 +  ucb1200_set_io(TC35143_GPIO_BUZZER_BIAS, TC35143_IODAT_HIGH);
4430 +#endif
4431 +  collie_tc_muted=1;
4432 +}
4433 +
4434 +static void Collie_audio_power_off(void){      /* Disable sound only */
4435 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4436 +  ucb1x00_enable(ucbstruct);
4437 +  ucb1x00_io_write(ucbstruct,0, TC35143_GPIO_BUZZER_BIAS);
4438 +#else
4439 +  ucb1200_set_io(TC35143_GPIO_BUZZER_BIAS, TC35143_IODAT_LOW);
4440 +#endif
4441 +
4442 +  TC35143f_control_reg_a = ( TC35143_VDIV_22KHZ );
4443 +  TC35143f_control_reg_b = ( TC35143_ALL_MUTE );
4444 +
4445 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4446 +  ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_B , TC35143f_control_reg_b);
4447 +  ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_A , TC35143f_control_reg_a);
4448 +  ucb1x00_disable(ucbstruct);
4449 +#else
4450 +  ucb1200_write_reg(TC35143_CONTROL_REG_B , TC35143f_control_reg_b );
4451 +  ucb1200_write_reg(TC35143_CONTROL_REG_A , TC35143f_control_reg_a );
4452 +#endif
4453 +}
4454 +
4455 +static void collie_tc_mute_on(void){
4456 +    unsigned int reg_b;
4457 +    unsigned int reg_a;
4458 +
4459 +    if (!collie_tc_muted) {
4460 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4461 +       ucb1x00_enable(ucbstruct);
4462 +       reg_b  = ucb1x00_reg_read(ucbstruct,TC35143_CONTROL_REG_B);
4463 +       reg_a  = ucb1x00_reg_read(ucbstruct,TC35143_CONTROL_REG_A);
4464 +#else
4465 +       reg_b  = ucb1200_read_reg(TC35143_CONTROL_REG_B);
4466 +       reg_a  = ucb1200_read_reg(TC35143_CONTROL_REG_A);
4467 +#endif
4468 +       reg_b &= ~TC35143_VOUT1_EN;
4469 +       reg_a &= ~TC35143_VOUT2_EN;
4470 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4471 +       ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_A, reg_a);
4472 +       ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_B, reg_b);
4473 +       ucb1x00_disable(ucbstruct);
4474 +#else
4475 +       ucb1200_write_reg(TC35143_CONTROL_REG_A, reg_a);
4476 +       ucb1200_write_reg(TC35143_CONTROL_REG_B, reg_b);
4477 +#endif
4478 +       collie_tc_muted=1;
4479 +    }
4480 +}
4481 +
4482 +static void collie_tc_mute_off(void){
4483 +    unsigned int reg_b;
4484 +    unsigned int reg_a;
4485 +
4486 +    if (collie_tc_muted) {
4487 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4488 +       ucb1x00_enable(ucbstruct);
4489 +       reg_b  = ucb1x00_reg_read(ucbstruct,TC35143_CONTROL_REG_B);
4490 +       reg_a  = ucb1x00_reg_read(ucbstruct,TC35143_CONTROL_REG_A);
4491 +#else
4492 +       reg_b  = ucb1200_read_reg(TC35143_CONTROL_REG_B);
4493 +       reg_a  = ucb1200_read_reg(TC35143_CONTROL_REG_A);       
4494 +#endif
4495 +       reg_b |= TC35143_VOUT1_EN ;
4496 +       reg_b &= ~7;
4497 +       reg_b |= ( 7 - collie_buzzer_volume / 13);
4498 +       reg_a |= TC35143_VOUT2_EN;
4499 +       reg_a &= ~(TC35143_VGAIN_MASK | TC35143_VAMP_MASK);
4500 +       reg_a |= (((audio_igain & 0x3)<<11) | ((audio_iamp & 0x0f)<<7));
4501 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4502 +       ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_A, reg_a);
4503 +       ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_B, reg_b);
4504 +       ucb1x00_disable(ucbstruct);
4505 +#else
4506 +       ucb1200_write_reg(TC35143_CONTROL_REG_A, reg_a);
4507 +       ucb1200_write_reg(TC35143_CONTROL_REG_B, reg_b);
4508 +#endif
4509 +       collie_tc_muted=0;
4510 +    }
4511 +}
4512 +
4513 +
4514 +static void Collie_volume_set(int dest)
4515 +{
4516 +    if (collie_buzzer_volume==dest) return;
4517 +    collie_buzzer_volume=dest;
4518 +    collie_tc_mute_on();    
4519 +    collie_tc_mute_off();    
4520 +}
4521 +
4522 +
4523 +/*********** GENERAL stuff, same as collie_ssp *******************************/
4524 +
4525 +
4526 +static void Collie_Set_Volume(int volume)
4527 +{
4528 +       sound.volume = volume & 0xff;
4529 +       sound.volume += ( volume & 0xff00 >> 8);
4530 +       sound.volume >>=1;
4531 +       if (sound.volume>100) sound.volume=100; 
4532 +}
4533 +
4534 +static int Collie_Get_Volume(void)
4535 +{
4536 +       return ( sound.volume << 8 | sound.volume );
4537 +}
4538 +
4539 +static void Collie_sq_interrupt(void* id, int size)
4540 +{
4541 +       audio_buf_t *b  = (audio_buf_t *) id;
4542 +       audio_buf_t *b2 = output_stream.buffers + ((b->idx + 1) % output_stream.nbfrags);
4543 +
4544 +       /* If this is the last buffer for know, let's mute the speaker */
4545 +       if (!down_trylock(&b2->sem)) {
4546 +               collie_tc_mute_on();
4547 +               up(&b2->sem);
4548 +       }
4549 +       
4550 +       /*
4551 +        * Current buffer is sent: wake up any process waiting for it.
4552 +        */
4553 +       up(&b->sem);
4554 +       /* And any process polling on write. */
4555 +       wake_up_interruptible(&b->sem.wait);
4556 +
4557 +       DPRINTK("Collie_sq_interrupt \n");
4558 +}
4559 +
4560 +static void Collie_sq_input_interrupt(void* id, int size)
4561 +{
4562 +       audio_buf_t *b = (audio_buf_t *) id;
4563 +       /*
4564 +        * Current buffer is sent: wake up any process waiting for it.
4565 +        */
4566 +       b->size = size;
4567 +       up(&b->sem);
4568 +       /* And any process polling on write. */
4569 +       wake_up_interruptible(&b->sem.wait);
4570 +       /* And indicate which was the last buffer sent */
4571 +
4572 +       DPRINTK("Collie_sq_input_interrupt \n");
4573 +}
4574 +
4575 +
4576 +static int __init CollieIrqInit(void)
4577 +{
4578 +       int err;
4579 +
4580 +       err = sa1100_request_dma(&COLLIE_BUZZER_DMA_CHANNEL, "buzzer output",
4581 +                          DMA_Ser4MCP0Wr);
4582 +
4583 +       if (err) {
4584 +               return 0;
4585 +       }
4586 +       printk("collie_tc35143f_irq=%d\n", collie_tc35143f_irq); 
4587 +
4588 +       err = sa1100_request_dma(&COLLIE_BUZZER_DMA_CHANNEL_INPUT, "buzzer input",
4589 +                          DMA_Ser4MCP0Rd);
4590 +
4591 +       if (err) {
4592 +               return 0;
4593 +       }
4594 +       printk("collie_tc35143f_input_irq=%d\n", collie_tc35143f_input_irq); 
4595 +
4596 +
4597 +       sa1100_dma_set_callback(COLLIE_BUZZER_DMA_CHANNEL,
4598 +                              (dma_callback_t)Collie_sq_interrupt);
4599 +
4600 +       sa1100_dma_set_callback(COLLIE_BUZZER_DMA_CHANNEL_INPUT,
4601 +                              (dma_callback_t)Collie_sq_input_interrupt);
4602 +
4603 +
4604 +       sa1100_dma_stop(COLLIE_BUZZER_DMA_CHANNEL);
4605 +       Collie_audio_power_off();
4606 +       sa1100_dma_stop(COLLIE_BUZZER_DMA_CHANNEL_INPUT);
4607 +       sa1100_dma_flush_all(COLLIE_BUZZER_DMA_CHANNEL);
4608 +       return(1);
4609 +}
4610 +
4611 +static int CollieSetFormat(int format)
4612 +{
4613 +       int size;
4614 +
4615 +       switch (format) {
4616 +       case AFMT_QUERY:
4617 +               return(sound.format);
4618 +       default: /* This is the only one supported by the hardware it seems */
4619 +               size = 16;
4620 +               format = AFMT_S16_LE;
4621 +       }
4622 +       sound.format = format;
4623 +       sound.size = size;
4624 +
4625 +       return(format);
4626 +}
4627 +
4628 +
4629 +static int sound_set_speed(int speed)
4630 +{
4631 +       if (speed < 0) {
4632 +               return(sound.speed);
4633 +       }
4634 +       sound.speed=22050;
4635 +       return(sound.speed);
4636 +}
4637 +
4638 +/* Higher level stuff ************************************************/
4639 +
4640 +/*
4641 + * /dev/mixer abstraction
4642 + */
4643 +
4644 +static int mixer_open(struct inode *inode, struct file *file)
4645 +{
4646 +       MOD_INC_USE_COUNT;
4647 +       mixer.busy = 1;
4648 +       return 0;
4649 +}
4650 +
4651 +static int mixer_release(struct inode *inode, struct file *file)
4652 +{
4653 +       mixer.busy = 0;
4654 +       MOD_DEC_USE_COUNT;
4655 +       return 0;
4656 +}
4657 +
4658 +
4659 +static int mixer_ioctl(struct inode *inode, struct file *file, u_int cmd,
4660 +                      u_long arg)
4661 +{
4662 +       int data;
4663 +
4664 +       DPRINTK("Got mixer ioctl \n");
4665 +
4666 +       switch (cmd) {
4667 +               case SOUND_MIXER_INFO:
4668 +                       DPRINTK("0\n");
4669 +                       return 0;
4670 +               case SOUND_OLD_MIXER_INFO:
4671 +                       DPRINTK("0\n");
4672 +                       return 0;
4673 +
4674 +               case SOUND_MIXER_READ_DEVMASK:
4675 +                       DPRINTK("1\n");
4676 +                       return IOCTL_OUT(arg, SOUND_MASK_VOLUME | SOUND_MASK_MIC | SOUND_MASK_IGAIN );
4677 +               case SOUND_MIXER_READ_RECMASK:
4678 +                       DPRINTK("2\n");
4679 +                       return IOCTL_OUT(arg, SOUND_MASK_MIC);
4680 +               case SOUND_MIXER_READ_STEREODEVS:
4681 +                       DPRINTK("3\n");
4682 +                       return IOCTL_OUT(arg, 0);
4683 +               case SOUND_MIXER_READ_CAPS:
4684 +                       DPRINTK("4\n");
4685 +                       return IOCTL_OUT(arg, 0);
4686 +
4687 +               case SOUND_MIXER_WRITE_VOLUME:
4688 +                       IOCTL_IN(arg, data);
4689 +                       Collie_Set_Volume(data);
4690 +                       DPRINTK("mix_io returning\n");
4691 +                       return IOCTL_OUT(arg, data);
4692 +               case SOUND_MIXER_READ_VOLUME:
4693 +                       DPRINTK("5\n");
4694 +                       return IOCTL_OUT(arg, Collie_Get_Volume());
4695 +               case SOUND_MIXER_READ_TREBLE:
4696 +                       DPRINTK("6\n");
4697 +                       return IOCTL_OUT(arg, 0);
4698 +               case SOUND_MIXER_WRITE_TREBLE:
4699 +                       DPRINTK("7\n");
4700 +                       return IOCTL_OUT(arg, 0);
4701 +
4702 +               case SOUND_MIXER_READ_BASS:
4703 +                       DPRINTK("6b\n");
4704 +                       return IOCTL_OUT(arg, 0);
4705 +               case SOUND_MIXER_WRITE_BASS:
4706 +                       DPRINTK("7b\n");
4707 +                       return IOCTL_OUT(arg, 0);
4708 +
4709 +
4710 +               case SOUND_MIXER_WRITE_MIC:
4711 +               case SOUND_MIXER_WRITE_IGAIN:
4712 +                       DPRINTK("8\n");
4713 +                       return IOCTL_OUT(arg, 100);
4714 +               case SOUND_MIXER_READ_MIC:
4715 +               case SOUND_MIXER_READ_IGAIN:
4716 +                       DPRINTK("9\n");
4717 +                       return IOCTL_OUT(arg, 0);
4718 +
4719 +               case SOUND_MIXER_READ_SPEAKER:
4720 +                       DPRINTK("10\n");
4721 +                       return IOCTL_OUT(arg, 0);
4722 +               case SOUND_MIXER_WRITE_SPEAKER:
4723 +                       DPRINTK("11\n");
4724 +                       return IOCTL_OUT(arg, 0);
4725 +               default:
4726 +                       DPRINTK("12 %d\n",cmd);
4727 +                       return -ENOSYS;
4728 +       }       
4729 +       DPRINTK("EINVAL %d??\n",cmd);
4730 +       return -EINVAL;
4731 +}
4732 +
4733 +
4734 +static struct file_operations mixer_fops =
4735 +{
4736 +       llseek:  sound_lseek,
4737 +       ioctl:   mixer_ioctl,
4738 +       open:    mixer_open,
4739 +       release: mixer_release,
4740 +};
4741 +
4742 +
4743 +static void __init mixer_init(void)
4744 +{
4745 +       mixer_unit = register_sound_mixer(&mixer_fops, -1);
4746 +       if (mixer_unit < 0) {
4747 +               return;
4748 +       }
4749 +       mixer.busy = 0;
4750 +       sound.volume  = 100;
4751 +       Collie_volume_set(sound.volume);
4752 +}
4753 +
4754 +/* This function initializes the buffer
4755 + */
4756 +
4757 +static void sq_clean_buffers(audio_stream_t * s)
4758 +{
4759 +       int frag;
4760 +
4761 +       sa1100_dma_flush_all(COLLIE_BUZZER_DMA_CHANNEL);
4762 +       sa1100_dma_flush_all(COLLIE_BUZZER_DMA_CHANNEL_INPUT);
4763 +
4764 +       s->nbfrags = audio_nbfrags;
4765 +       s->fragsize = audio_fragsize;
4766 +
4767 +       if (!s->buffers)
4768 +           goto err;
4769 +
4770 +       for (frag = 0; frag < s->nbfrags; frag++) {
4771 +               audio_buf_t *b = &s->buffers[frag];
4772 +               b->size=0;
4773 +               sema_init(&b->sem, 1);
4774 +       }
4775 +       s->buf_idx = 0;
4776 +       s->buf = &s->buffers[0];
4777 +       return;
4778 +
4779 +err:
4780 +       printk("sound driver : where did the buffer go ??\n ");
4781 +}
4782 +
4783 +/* This function allocates the buffer structure array and buffer data space
4784 + * according to the current number of fragments and fragment size.
4785 + */
4786
4787 +static int sq_allocate_buffers(audio_stream_t * s)
4788 +{
4789 +       int frag;
4790 +       int dmasize = 0;
4791 +       char *dmabuf = 0;
4792 +       dma_addr_t dmaphys = 0;
4793 +
4794 +       DPRINTK("sq_allocate_buffers\n");
4795 +
4796 +       if (s->buffers) {
4797 +               return -EBUSY;
4798 +       }
4799 +
4800 +       s->nbfrags = audio_nbfrags;
4801 +       s->fragsize = audio_fragsize;
4802 +
4803 +       s->buffers = (audio_buf_t *)
4804 +               kmalloc(sizeof(audio_buf_t) * s->nbfrags, GFP_KERNEL);
4805 +       if (!s->buffers)
4806 +       goto err;
4807 +       memset(s->buffers, 0, sizeof(audio_buf_t) * s->nbfrags);
4808 +
4809 +       for (frag = 0; frag < s->nbfrags; frag++) {
4810 +               audio_buf_t *b = &s->buffers[frag];
4811 +
4812 +               /*
4813 +                * Let's allocate non-cached memory for DMA buffers.
4814 +                * We try to allocate all memory at once.
4815 +                * If this fails (a common reason is memory fragmentation),
4816 +                * then we allocate more smaller buffers.
4817 +                */
4818 +               if (!dmasize) {
4819 +                       dmasize = (s->nbfrags - frag) * s->fragsize;
4820 +                       do {
4821 +                               dmabuf = consistent_alloc(GFP_KERNEL|GFP_DMA,
4822 +                                                         dmasize,
4823 +                                                         &dmaphys);
4824 +                               if (!dmabuf)
4825 +                                       dmasize -= s->fragsize;
4826 +                       } while (!dmabuf && dmasize);
4827 +                       if (!dmabuf)
4828 +                               goto err;
4829 +                       b->master = dmasize;
4830 +               }
4831 +
4832 +               b->start = dmabuf;
4833 +               b->dma_addr = dmaphys;
4834 +               b->idx = frag;
4835 +               sema_init(&b->sem, 1);
4836 +               dmabuf += s->fragsize;
4837 +               dmaphys += s->fragsize;
4838 +               dmasize -= s->fragsize;
4839 +       }
4840 +
4841 +       s->buf_idx = 0;
4842 +       s->buf = &s->buffers[0];
4843 +
4844 +       return 0;
4845 +
4846 +err:
4847 +       printk("sound driver : unable to allocate audio memory\n ");
4848 +       sq_release_buffers(s);
4849 +       return -ENOMEM;
4850 +}
4851 +
4852 +/*
4853 + * This function frees all buffers
4854 + */
4855 +
4856 +static void sq_release_buffers(audio_stream_t * s)
4857 +{
4858 +       DPRINTK("sq_release_buffers\n");
4859 +
4860 +       /* ensure DMA won't run anymore */
4861 +       sa1100_dma_flush_all(COLLIE_BUZZER_DMA_CHANNEL);
4862 +       sa1100_dma_flush_all(COLLIE_BUZZER_DMA_CHANNEL_INPUT);
4863 +
4864 +       if (s->buffers) {
4865 +               int frag;
4866 +               for (frag = 0; frag < s->nbfrags; frag++) {
4867 +                       if (!s->buffers[frag].master)
4868 +                               continue;
4869 +                       consistent_free(s->buffers[frag].start,
4870 +                                       s->buffers[frag].master,
4871 +                                       s->buffers[frag].dma_addr);
4872 +               }
4873 +               kfree(s->buffers);
4874 +               s->buffers = NULL;
4875 +       }
4876 +
4877 +       s->buf_idx = 0;
4878 +       s->buf = NULL;
4879 +}
4880 +
4881 +static int audio_recording(audio_stream_t * s)
4882 +{
4883 +       int i;
4884 +       unsigned int reg_b;
4885 +
4886 +       if (!collie_recording) {
4887 +               /*
4888 +                * Set TC35143 Audio in enable
4889 +                */
4890 +////           DPRINTK("audio_recording : audio in enable\n");
4891 +////           reg_b  = ucb1200_read_reg(TC35143_CONTROL_REG_B);
4892 +////           reg_b &= ~(TC35143_VADMUTE);
4893 +////           reg_b |=  (TC35143_VIN_EN | TC35143_VCLP_CLR);
4894 +////           ucb1200_write_reg(TC35143_CONTROL_REG_B, reg_b);
4895 +
4896 +               /*
4897 +                * We must ensure there is an output stream at any time while 
4898 +                * recording since this is how the TC35143 gets its clock.
4899 +                * So if there is no playback data to send, the output DMA will
4900 +                * spin with all zeroes.
4901 +                */
4902 +
4903 +               Collie_recording_on();
4904 +               collie_tc_mute_off();  /* This is needed for good volume */
4905 +               DPRINTK("audio_recording : sa1100_dma_set_spin\n");
4906 +               sa1100_dma_set_spin(COLLIE_BUZZER_DMA_CHANNEL,
4907 +                                           (dma_addr_t) FLUSH_BASE_PHYS, 2048);
4908 +
4909 +               /* 
4910 +                * Since we just allocated all buffers, we must send them to
4911 +                * the DMA code before receiving data.
4912 +                */
4913 +               DPRINTK("audio_recording : for loop\n");
4914 +               for (i = 0; i < s->nbfrags; i++) {
4915 +                       audio_buf_t *b = s->buf;
4916 +                       down(&b->sem);
4917 +                       sa1100_dma_queue_buffer(COLLIE_BUZZER_DMA_CHANNEL_INPUT, (void *) b,
4918 +                                               b->dma_addr, s->fragsize);
4919 +                       NEXT_BUF(s, buf);
4920 +               }
4921 +               DPRINTK("audio_recording : End for loop\n");
4922 +
4923 +               /*
4924 +                * Set TC35143 Audio in enable
4925 +                */
4926 +               DPRINTK("audio_recording : audio in enable\n");
4927 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4928 +               ucb1x00_enable(ucbstruct);
4929 +               ucb1x00_io_write(ucbstruct, 0, TC35143_GPIO_BUZZER_BIAS);
4930 +               reg_b  = ucb1x00_reg_read(ucbstruct,TC35143_CONTROL_REG_B);
4931 +#else
4932 +               ucb1200_set_io(TC35143_GPIO_BUZZER_BIAS, TC35143_IODAT_LOW);
4933 +               reg_b  = ucb1200_read_reg(TC35143_CONTROL_REG_B);
4934 +#endif
4935 +               reg_b &= ~(TC35143_VADMUTE);
4936 +               reg_b |=  (TC35143_VIN_EN | TC35143_VCLP_CLR);
4937 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
4938 +               ucb1x00_reg_write(ucbstruct,TC35143_CONTROL_REG_B, reg_b);
4939 +               ucb1x00_disable(ucbstruct);
4940 +#else
4941 +               ucb1200_write_reg(TC35143_CONTROL_REG_B, reg_b);
4942 +#endif
4943 +       }
4944 +       return 0;
4945 +}
4946 +
4947 +
4948 +static int sq_read(struct file *file, char *buffer,
4949 +                     size_t count, loff_t * ppos)
4950 +{
4951 +       char *buffer0 = buffer;
4952 +       audio_stream_t *s = &input_stream;
4953 +       int chunksize, ret = 0;
4954 +
4955 +       DPRINTK("audio_read: count=%d\n", count);
4956 +
4957 +
4958 +       ret = audio_recording(s);
4959 +
4960 +       if ((collie_tc_status!=NA) && (collie_tc_status!=REC)) 
4961 +           return -EPERM;
4962 +       collie_tc_status=REC;
4963 +
4964 +       if (ret)
4965 +               return ret;
4966 +
4967 +       /* be sure to have a full sample byte count */
4968 +       count &= ~0x03;
4969 +
4970 +//     DPRINTK("audio_read : Start while loop\n");
4971 +       while (count > 0) {
4972 +               audio_buf_t *b = s->buf;
4973 +
4974 +               /* Wait for a buffer to become full */
4975 +               if (file->f_flags & O_NONBLOCK) {
4976 +//                     DPRINTK("audio_read : down_trylock\n");
4977 +                       ret = -EAGAIN;
4978 +                       if (down_trylock(&b->sem))
4979 +                               break;
4980 +               } else {
4981 +//                     DPRINTK("audio_read : down_interruptible\n");
4982 +                       ret = -ERESTARTSYS;
4983 +                       if (down_interruptible(&b->sem))
4984 +                               break;
4985 +               }
4986 +
4987 +               /* Grab data from the current buffer */
4988 +               chunksize = b->size;
4989 +               if (chunksize > count)
4990 +                   chunksize = count;
4991 +               DPRINTK("read %d from %d\n", chunksize, s->buf_idx);
4992 +               
4993 +               if (copy_to_user(buffer, b->start + s->fragsize - b->size, chunksize)) {
4994 +                   up(&b->sem);
4995 +                   DPRINTK("not copied to buffer \n");
4996 +                   return -EFAULT;
4997 +               }
4998 +               DPRINTK("copied to buffer \n");
4999 +
5000 +               b->size -= chunksize;
5001 +               buffer += chunksize;
5002 +               count -= chunksize;
5003 +               
5004 +               if (b->size > 0) {
5005 +                       up(&b->sem);
5006 +                       break;
5007 +               }
5008 +
5009 +               /* Make current buffer available for DMA again */
5010 +               sa1100_dma_queue_buffer(COLLIE_BUZZER_DMA_CHANNEL_INPUT, (void *) b,
5011 +                                       b->dma_addr, s->fragsize);
5012 +               NEXT_BUF(s, buf);
5013 +       }
5014 +//     DPRINTK("audio_read : End while loop\n");
5015 +
5016 +       if ((buffer - buffer0))
5017 +               ret = buffer - buffer0;
5018 +//     DPRINTK("audio_read: return=%d\n", ret);
5019 +       return ret;
5020 +}
5021 +
5022 +static ssize_t sq_write(struct file *file, const char *src, size_t uLeft,
5023 +                       loff_t *ppos)
5024 +{
5025 +       const char *buffer0 = src;
5026 +       audio_stream_t *s = &output_stream;
5027 +       u_char *dest;
5028 +       ssize_t uUsed, bUsed, bLeft, ret = 0;
5029 +
5030 +       DPRINTK("sq_write: uLeft=%d\n", uLeft);
5031 +
5032 +       if ((collie_tc_status!=NA) && (collie_tc_status!=PLAY)) 
5033 +           return -EPERM;
5034 +
5035 +       collie_tc_status=PLAY;
5036 +
5037 +       if (!s->buffers && sq_allocate_buffers(s)) {
5038 +               return -ENOMEM;
5039 +       }
5040 +
5041 +
5042 +#ifdef CONFIG_PM
5043 +       /* Auto Power off cancel */
5044 +//     autoPowerCancel = 0;
5045 +#endif
5046 +
5047 +       collie_tc_mute_off();
5048 +       while (uLeft > 0) {
5049 +               audio_buf_t *b = s->buf;
5050 +
5051 +               /* Wait for a buffer to become free */
5052 +               if (file->f_flags & O_NONBLOCK) {
5053 +                       ret = -EAGAIN;
5054 +                       if (down_trylock(&b->sem)) {
5055 +                               break;
5056 +                       }
5057 +               } else {
5058 +                       ret = -ERESTARTSYS;
5059 +                       if (down_interruptible(&b->sem)) {
5060 +                               break;
5061 +                       }
5062 +               }
5063 +
5064 +               dest = b->start + b->size;
5065 +               bUsed = 0;
5066 +               bLeft = s->fragsize - b->size;
5067 +
5068 +               if (collie_ct_s16) {
5069 +                       uUsed = collie_ct_s16(src, uLeft, dest, &bUsed, bLeft);
5070 +                       cpu_cache_clean_invalidate_range((unsigned long)dest,
5071 +                               (unsigned long)(dest+(audio_fragsize)), 0);
5072 +               } else {
5073 +                       return -EFAULT;
5074 +               }
5075 +
5076 +               if (uUsed < 0) {
5077 +                       up(&b->sem);
5078 +                       return -EFAULT;
5079 +               }
5080 +               src += uUsed;
5081 +               uLeft -= uUsed;
5082 +               b->size += bUsed;
5083 +
5084 +               if (b->size < s->fragsize) {
5085 +                       up(&b->sem);
5086 +                       break;
5087 +               }
5088 +
5089 +               /* Send current buffer to dma */
5090 +               sa1100_dma_queue_buffer(COLLIE_BUZZER_DMA_CHANNEL,
5091 +                                       (void *) b, b->dma_addr, b->size);
5092 +
5093 +               Collie_volume_set(sound.volume);
5094 +
5095 +               b->size = 0;    /* indicate that the buffer has been sent */
5096 +               NEXT_BUF(s, buf);
5097 +       }
5098 +
5099 +       if ((src - buffer0))
5100 +               ret = src - buffer0;
5101 +       DPRINTK("sq_write: return=%d\n", ret);
5102 +       return ret;
5103 +}
5104 +
5105 +static unsigned int sq_poll(struct file *file, 
5106 +                              struct poll_table_struct *wait)
5107 +{
5108 +       unsigned int mask = 0;
5109 +       int i,ret;
5110 +
5111 +       DPRINTK("sq_poll(): mode=%s%s\n",
5112 +               (file->f_mode & FMODE_READ) ? "r" : "",
5113 +               (file->f_mode & FMODE_WRITE) ? "w" : "");
5114 +
5115 +       if ((file->f_mode & FMODE_READ) && (file->f_mode & FMODE_WRITE) && (collie_tc_status==NA))
5116 +           return mask;
5117 +       
5118 +       if ((file->f_mode & FMODE_WRITE) && (collie_tc_status!=REC)) {
5119 +               if (!output_stream.buffers 
5120 +                   && sq_allocate_buffers(&output_stream)) {
5121 +                       return -ENOMEM;
5122 +               }
5123 +               poll_wait(file, &output_stream.buf->sem.wait, wait);
5124 +       }
5125 +
5126 +       if ((file->f_mode & FMODE_WRITE) && (collie_tc_status!=REC)) {
5127 +               for (i = 0; i < output_stream.nbfrags; i++) {
5128 +                       if (atomic_read(&output_stream.buffers[i].sem.count) > 0)
5129 +                               mask |= POLLOUT | POLLWRNORM;
5130 +               }
5131 +       }
5132 +
5133 +       if ((file->f_mode & FMODE_READ) && (collie_tc_status!=PLAY)) {
5134 +               ret = audio_recording(&input_stream);
5135 +               if (ret<0) {
5136 +                       return ret;
5137 +               }
5138 +               poll_wait(file, &input_stream.buf->sem.wait, wait);
5139 +       }
5140 +
5141 +       if ((file->f_mode & FMODE_READ) && (collie_tc_status!=PLAY)) {
5142 +               for (i = 0; i < input_stream.nbfrags; i++) {
5143 +                       if (atomic_read(&input_stream.buffers[i].sem.count) > 0)
5144 +                               mask |= POLLIN | POLLRDNORM;
5145 +               }
5146 +       }
5147 +
5148 +       DPRINTK("sq_poll() returned mask of %s%s\n",
5149 +               (mask & POLLIN) ? "r" : "",
5150 +               (mask & POLLOUT) ? "w" : "");
5151 +
5152 +       return mask;
5153 +}
5154 +
5155 +static int sq_open(struct inode *inode, struct file *file)
5156 +{
5157 +       DPRINTK("sq_open\n");
5158 +
5159 +       if (audio_refcount) {
5160 +               DPRINTK(" sq_open        EBUSY\n");
5161 +               return -EBUSY;
5162 +       }
5163 +
5164 +       switch (file->f_flags & O_ACCMODE) {
5165 +           case O_WRONLY:
5166 +               collie_tc_status=PLAY;
5167 +               sa1100_dma_stop(COLLIE_BUZZER_DMA_CHANNEL_INPUT);
5168 +               break;
5169 +           case O_RDONLY:
5170 +               collie_tc_status=REC;
5171 +               break;
5172 +           case O_RDWR:
5173 +               collie_tc_status=NA;
5174 +               break;
5175 +           default:
5176 +               DPRINTK(" sq_open        EINVAL\n");
5177 +               return -EINVAL;
5178 +       }
5179 +       
5180 +       MOD_INC_USE_COUNT;
5181 +       audio_refcount++;
5182 +
5183 +       audio_fragsize = AUDIO_FRAGSIZE_DEFAULT;
5184 +       audio_nbfrags = AUDIO_NBFRAGS_DEFAULT;
5185 +       sq_clean_buffers(&input_stream);
5186 +       sq_clean_buffers(&output_stream);
5187 +       Collie_audio_power_on();
5188 +       DPRINTK("Going back\n");
5189 +       return 0;
5190 +}
5191 +
5192 +static int sq_post(void)
5193 +{
5194 +       audio_stream_t *s = &output_stream;
5195 +       audio_buf_t *b = s->buf;
5196 +
5197 +       DPRINTK("sq_post\n");
5198 +
5199 +       if (!s->buffers) {
5200 +               return 0;
5201 +       }
5202 +
5203 +       /* Send half-full buffers */
5204 +       if (b->size != 0) {
5205 +               DPRINTK("half-full_buf\n");
5206 +
5207 +#ifdef CONFIG_PM
5208 +               /* Auto Power off cancel */
5209 +//             autoPowerCancel = 0;
5210 +#endif
5211 +
5212 +               down(&b->sem);
5213 +               sa1100_dma_queue_buffer(COLLIE_BUZZER_DMA_CHANNEL,
5214 +                                       (void *) b, b->dma_addr, b->size);
5215 +               b->size = 0;
5216 +               NEXT_BUF(s, buf);
5217 +       }
5218 +       return 0;
5219 +}
5220 +
5221 +static int sq_fsync(void)
5222 +{
5223 +       audio_stream_t *s = &output_stream;
5224 +       audio_buf_t *b = s->buf;
5225 +
5226 +       DPRINTK("sq_fsync\n");
5227 +
5228 +       if (!s->buffers) {
5229 +               return 0;
5230 +       }
5231 +
5232 +       /* Send half-full buffers */
5233 +       if (b->size != 0) {
5234 +               DPRINTK("half-full_buf\n");
5235 +
5236 +#ifdef CONFIG_PM
5237 +               /* Auto Power off cancel */
5238 +//             autoPowerCancel = 0;
5239 +#endif
5240 +
5241 +               down(&b->sem);
5242 +               sa1100_dma_queue_buffer(COLLIE_BUZZER_DMA_CHANNEL,
5243 +                                       (void *) b, b->dma_addr, b->size);
5244 +               b->size = 0;
5245 +               NEXT_BUF(s, buf);
5246 +       }
5247 +
5248 +       /*
5249 +        * Let's wait for the last buffer we sent i.e. the one before the
5250 +        * current buf_idx.  When we acquire the semaphore, this means either:
5251 +        * - DMA on the buffer completed or
5252 +        * - the buffer was already free thus nothing else to sync.
5253 +        */
5254 +       b = s->buffers + ((s->nbfrags + s->buf_idx - 1) % s->nbfrags);
5255 +       if (down_interruptible(&b->sem)) {
5256 +               return -EINTR;
5257 +       }
5258 +       up(&b->sem);
5259 +       return 0;
5260 +}
5261 +
5262 +static int sq_release(struct inode *inode, struct file *file)
5263 +{
5264 +       DPRINTK("speaker_sq_release\n");
5265 +
5266 +       switch (collie_tc_status) {
5267 +
5268 +       case REC:
5269 +           sa1100_dma_set_spin(COLLIE_BUZZER_DMA_CHANNEL,0,0);
5270 +           sq_clean_buffers(&input_stream);
5271 +           Collie_recording_off();
5272 +           break;
5273 +       case PLAY:
5274 +           sq_fsync();
5275 +           sq_clean_buffers(&output_stream);
5276 +           break;
5277 +       default:
5278 +           break;              
5279 +       }       
5280 +       audio_refcount = 0;
5281 +       collie_tc_status=NA;
5282 +       sa1100_dma_stop(COLLIE_BUZZER_DMA_CHANNEL);
5283 +       Collie_audio_power_off();
5284 +       sa1100_dma_stop(COLLIE_BUZZER_DMA_CHANNEL_INPUT);       
5285 +       MOD_DEC_USE_COUNT;
5286 +       return 0;
5287 +}
5288 +
5289 +/* Buzzer compatibility */
5290 +#include "colliebuzzer.h"   
5291 +
5292 +
5293 +static int sq_ioctl(struct inode *inode, struct file *file, u_int cmd,
5294 +                   u_long arg)
5295 +{
5296 +       u_long fmt;
5297 +       int data,ret;
5298 +//     audio_buf_info abinfo;
5299 +
5300 +       DPRINTK("Got ioctl %ld \n",cmd);
5301 +       
5302 +       switch (cmd) {
5303 +       case 22144:
5304 +               sq_write_buzzer(arg);
5305 +               sq_fsync();
5306 +               return 0;       
5307 +       case SNDCTL_DSP_RESET:
5308 +               switch (collie_tc_status) {
5309 +               case REC:
5310 +                   sq_clean_buffers(&input_stream);
5311 +               case PLAY:
5312 +                   sq_fsync();
5313 +                   sq_clean_buffers(&output_stream);
5314 +               default:
5315 +                   break;
5316 +               }
5317 +               return 0;
5318 +       case SNDCTL_DSP_POST:
5319 +               sq_post();
5320 +               return 0;
5321 +       case SNDCTL_DSP_SYNC:
5322 +               sq_fsync();
5323 +               return 0;
5324 +
5325 +               /* ++TeSche: before changing any of these it's
5326 +                * probably wise to wait until sound playing has
5327 +                * settled down. */
5328 +       case SNDCTL_DSP_SPEED:
5329 +//             sq_fsync(file, file->f_dentry);
5330 +               IOCTL_IN(arg, data);
5331 +               return IOCTL_OUT(arg, sound_set_speed(data));
5332 +
5333 +       case SOUND_PCM_READ_RATE:
5334 +               return 0;
5335 +
5336 +       case SNDCTL_DSP_STEREO:
5337 +//             sq_fsync(file, file->f_dentry);
5338 +               IOCTL_IN(arg, data);
5339 +               return IOCTL_OUT(arg, 0);
5340 +       case SNDCTL_DSP_CHANNELS:
5341 +//             sq_fsync(file, file->f_dentry);
5342 +               IOCTL_IN(arg, data);
5343 +               return IOCTL_OUT(arg, 1);
5344 +       case SNDCTL_DSP_SETFMT:
5345 +//             sq_fsync(file, file->f_dentry);
5346 +               IOCTL_IN(arg, data);
5347 +               return IOCTL_OUT(arg, CollieSetFormat(data));
5348 +       case SNDCTL_DSP_GETFMTS:
5349 +               fmt = AFMT_S16_LE;
5350 +               return IOCTL_OUT(arg, fmt);
5351 +       case SNDCTL_DSP_GETBLKSIZE:
5352 +               return IOCTL_OUT(arg, audio_fragsize);
5353 +       case SNDCTL_DSP_SUBDIVIDE:
5354 +               break;
5355 +       case SNDCTL_DSP_SETFRAGMENT:
5356 +/*             if (output_stream.buffers) {
5357 +                       return -EBUSY;
5358 +               }
5359 +               get_user(val, (long *) arg);
5360 +               audio_fragsize = 1 << (val & 0xFFFF);
5361 +               if (audio_fragsize < 256)
5362 +                       audio_fragsize = 256;
5363 +               if (audio_fragsize > 16384)
5364 +                       audio_fragsize = 16384;
5365 +               audio_nbfrags = (val >> 16) & 0x7FFF;
5366 +               if (audio_nbfrags < 2)
5367 +                       audio_nbfrags = 2;
5368 +               if (audio_nbfrags * audio_fragsize > 128 * 1024)
5369 +                       audio_nbfrags = 128 * 1024 / audio_fragsize;
5370 +               if (sq_allocate_buffers(&output_stream)) {
5371 +                       return -ENOMEM;
5372 +               }
5373 +               return 0;
5374 +       case SNDCTL_DSP_GETOSPACE:
5375 +               abinfo.fragsize   = audio_fragsize;
5376 +               abinfo.fragstotal = audio_nbfrags;
5377 +               abinfo.fragments  = lastsent-output_stream.buf_idx;
5378 +               if (abinfo.fragments<0)
5379 +                   abinfo.fragments += abinfo.fragstotal;                  
5380 +               abinfo.bytes      = abinfo.fragments*abinfo.fragsize;
5381 +               return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
5382 +*/
5383 +
5384 +       case SNDCTL_DSP_GETOSPACE:
5385 +           {
5386 +               audio_stream_t *s = &output_stream;
5387 +               audio_buf_info *inf = (audio_buf_info *) arg;
5388 +               int err = verify_area(VERIFY_WRITE, inf, sizeof(*inf));
5389 +               int i;
5390 +               int frags = 0, bytes = 0;
5391 +
5392 +               if (err)
5393 +                       return err;
5394 +               if (output_stream.buffers)  {
5395 +                   for (i = 0; i < s->nbfrags; i++) {
5396 +                       if (atomic_read(&s->buffers[i].sem.count) > 0) {
5397 +                               if (s->buffers[i].size == 0) frags++;
5398 +                               bytes += s->fragsize - s->buffers[i].size;
5399 +                       }
5400 +                   }
5401 +                   put_user(s->nbfrags, &inf->fragstotal);
5402 +                   put_user(s->fragsize, &inf->fragsize);
5403 +               } else {
5404 +                   frags=audio_nbfrags;
5405 +                   bytes=frags*audio_fragsize;
5406 +                   put_user(frags, &inf->fragstotal);
5407 +                   put_user(audio_fragsize, &inf->fragsize);
5408 +               }
5409 +               put_user(frags, &inf->fragments);
5410 +               return put_user(bytes, &inf->bytes);
5411 +           }
5412 +
5413 +       case SNDCTL_DSP_GETISPACE:
5414 +           {
5415 +               audio_stream_t *s = &input_stream;
5416 +               audio_buf_info *inf = (audio_buf_info *) arg;
5417 +               int err = verify_area(VERIFY_WRITE, inf, sizeof(*inf));
5418 +               int i;
5419 +               int frags = 0, bytes = 0;
5420 +
5421 +               if (err)
5422 +                       return err;
5423 +               if (input_stream.buffers) 
5424 +                   for (i = 0; i < s->nbfrags; i++) {
5425 +                       if (atomic_read(&s->buffers[i].sem.count) > 0) {
5426 +                               if (s->buffers[i].size == s->fragsize) frags++;
5427 +                               bytes += s->buffers[i].size;
5428 +                       }
5429 +                   }
5430 +               else {
5431 +                   frags=0;
5432 +                   bytes=0;
5433 +               }
5434 +               put_user(frags, &inf->fragments);
5435 +               put_user(s->nbfrags, &inf->fragstotal);
5436 +               put_user(s->fragsize, &inf->fragsize);
5437 +               return put_user(bytes, &inf->bytes);            
5438 +           }
5439 +
5440 +       default:
5441 +               ret = mixer_ioctl(inode, file, cmd, arg);
5442 +               DPRINTK("Returning after mixer_ioctl\n");
5443 +               return ret;
5444 +       }
5445 +       return -EINVAL;
5446 +}
5447 +
5448 +static struct file_operations sq_fops =
5449 +{
5450 +       llseek: sound_lseek,
5451 +       write: sq_write,
5452 +       read: sq_read,
5453 +       poll: sq_poll,
5454 +       ioctl: sq_ioctl,
5455 +       open: sq_open,
5456 +       release: sq_release,
5457 +};
5458 +
5459 +
5460 +static void __init sq_init(void)
5461 +{
5462 +       sq_unit = register_sound_dsp(&sq_fops, -1);
5463 +       if (sq_unit < 0) {
5464 +               return;
5465 +       }
5466 +
5467 +       sound.format = AFMT_S16_LE;
5468 +       sound.stereo = 0;
5469 +       sound.speed = 22050;
5470 +
5471 +       CollieSetFormat(sound.format);
5472 +       Collie_audio_power_off();
5473 +       input_stream.buf=input_stream.buffers=output_stream.buf=output_stream.buffers=NULL;
5474 +}
5475 +
5476 +
5477 +/*** Common stuff ********************************************************/
5478 +
5479 +static long long sound_lseek(struct file *file, long long offset, int orig)
5480 +{
5481 +       return -ESPIPE;
5482 +}
5483 +
5484 +/*** Power Management ****************************************************/
5485 +
5486 +#ifdef CONFIG_PM
5487 +static int collie_sound_pm_callback(struct pm_dev *pm_dev,
5488 +                                   pm_request_t req, void *data)
5489 +{
5490 +       switch (req) {
5491 +       case PM_SUSPEND:
5492 +               if (audio_refcount == 1) {
5493 +                       sa1100_dma_sleep((dmach_t)COLLIE_BUZZER_DMA_CHANNEL);
5494 +                       sa1100_dma_sleep((dmach_t)COLLIE_BUZZER_DMA_CHANNEL_INPUT);
5495 +                       Collie_audio_power_off();
5496 +               } else {
5497 +                       sa1100_dma_sleep((dmach_t)COLLIE_BUZZER_DMA_CHANNEL);
5498 +                       sa1100_dma_sleep((dmach_t)COLLIE_BUZZER_DMA_CHANNEL_INPUT);
5499 +               }
5500 +               break;
5501 +       case PM_RESUME:
5502 +               Collie_sound_hard_init();
5503 +//             Collie_audio_power_off();
5504 +               if (audio_refcount == 1) {
5505 +                       Collie_audio_power_on();
5506 +                       sa1100_dma_wakeup((dmach_t)COLLIE_BUZZER_DMA_CHANNEL);
5507 +                       sa1100_dma_wakeup((dmach_t)COLLIE_BUZZER_DMA_CHANNEL_INPUT);
5508 +               } else {
5509 +                       sa1100_dma_wakeup((dmach_t)COLLIE_BUZZER_DMA_CHANNEL);
5510 +                       sa1100_dma_wakeup((dmach_t)COLLIE_BUZZER_DMA_CHANNEL_INPUT);
5511 +               }
5512 +               break;
5513 +       }
5514 +       return 0;
5515 +}
5516 +#endif
5517 +
5518 +/*** Config & Setup ******************************************************/
5519 +
5520 +int __init Collie_sound_init(void)
5521 +{
5522 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19))
5523 +       ucbstruct = ucb1x00_get();
5524 +#endif
5525 +       if (!CollieIrqInit()) {
5526 +           printk("Sound driver: Interrupt initialization failed\n");
5527 +           return -1;
5528 +       }
5529 +       Ser4MCDR0 = 0; /* ucb1200_sa1100_set_mcdr0(0); */   
5530 +
5531 +       Collie_sound_hard_init();
5532 +       
5533 +       /* Set default settings. */
5534 +       sq_init();
5535 +       /* Set up /dev/mixer. */
5536 +       mixer_init();
5537 +#ifdef MODULE
5538 +       irq_installed = 1;
5539 +#endif
5540 +       printk("Collie tc35143af Sound Driver Installed\n");
5541 +#ifdef CONFIG_PM
5542 +       collie_sound_pm_dev = pm_register(PM_SYS_DEV, 0,
5543 +                                               collie_sound_pm_callback);
5544 +#endif
5545 +       return 0;
5546 +}
5547 +
5548 +#ifdef MODULE
5549 +static int collie_tc35143_init_module(void)
5550 +{
5551 +       Collie_sound_init();
5552 +       sq_allocate_buffers(&output_stream);
5553 +       sq_allocate_buffers(&input_stream);
5554 +       return 0;
5555 +}
5556 +
5557 +static void collie_tc35143_cleanup_module(void)
5558 +{
5559 +#ifdef CONFIG_PM
5560 +       pm_unregister(collie_sound_pm_dev);
5561 +#endif
5562 +       if (irq_installed) {
5563 +               sa1100_free_dma(COLLIE_BUZZER_DMA_CHANNEL);
5564 +               sa1100_free_dma(COLLIE_BUZZER_DMA_CHANNEL_INPUT);
5565 +       }
5566 +
5567 +       sq_release_buffers(&output_stream);
5568 +       sq_release_buffers(&input_stream);
5569 +       unregister_sound_mixer(mixer_unit);
5570 +       unregister_sound_special(state_unit);
5571 +       unregister_sound_dsp(sq_unit);
5572 +       printk("collie_tc35143af has to go now, see you later!\n");
5573 +}
5574 +
5575 +module_init(collie_tc35143_init_module);
5576 +module_exit(collie_tc35143_cleanup_module);
5577 +MODULE_DESCRIPTION("Collie tc35143af 16bit sound driver");
5578 +MODULE_AUTHOR("SHARP");
5579 +MODULE_LICENSE("GPL");
5580 +#endif /* MODULE */
5581 +
5582 diff -Nuar linux-2.4.18/drivers/sound/Makefile linux-2.4.18p/drivers/sound/Makefile
5583 --- linux-2.4.18/drivers/sound/Makefile 2003-05-13 11:18:36.000000000 +0200
5584 +++ linux-2.4.18p/drivers/sound/Makefile        2004-10-12 23:11:29.000000000 +0200
5585 @@ -11,7 +11,7 @@
5586                     msnd.o opl3.o sb_common.o sequencer_syms.o \
5587                     sound_core.o sound_syms.o uart401.o \
5588                     nm256_audio.o ac97.o ac97_codec.o aci.o \
5589 -                   sa1100-audio.o pxa-audio.o pxa-ac97.o
5590 +                   sa1100-audio.o pxa-audio.o pxa-ac97.o collie_ssp.o
5591  
5592  # Each configuration option enables a list of files.
5593  
5594 @@ -78,7 +78,7 @@
5595  obj-$(CONFIG_SOUND_SA1111_UDA1341) += sa1111-uda1341.o
5596  obj-$(CONFIG_SOUND_SA1100SSP)  += sa1100ssp.o
5597  obj-$(CONFIG_SOUND_COLLIE_SSP) += collie_ssp.o
5598 -obj-$(CONFIG_SOUND_COLLIE_TC35143) += collie-tc35143.o
5599 +obj-$(CONFIG_SOUND_COLLIE_TC35143) += collie_tc35143af.o
5600  obj-$(CONFIG_SOUND_PXA_AC97)+= pxa-ac97.o pxa-audio.o ac97_codec.o
5601  obj-$(CONFIG_SOUND_EMU10K1)    += ac97_codec.o
5602  obj-$(CONFIG_SOUND_RME96XX)     += rme96xx.o