22 #include <linux/module.h>
23 #include <linux/kernel.h>
26 #include <mach/hardware.h>
36 #define _SIOC_TYPE(x) _IOC_TYPE(x)
39 #define _SIOC_NR(x) _IOC_NR(x)
42 #define VIDC_SOUND_CLOCK (250000)
43 #define VIDC_SOUND_CLOCK_EXT (176400)
51 static int vidc_audio_rate;
52 static char vidc_audio_format;
53 static char vidc_audio_channels;
81 static unsigned int vidc_audio_volume_l;
82 static unsigned int vidc_audio_volume_r;
88 vidc_mixer_set(
int mdev,
unsigned int level)
90 unsigned int lev_l = level & 0x007f;
91 unsigned int lev_r = (level & 0x7f00) >> 8;
92 unsigned int mlev_l, mlev_r;
99 #define SCALE(lev,master) ((lev) * (master) * 65536 / 10000)
107 vidc_level_l[mdev] = lev_l;
108 vidc_level_r[mdev] = lev_r;
110 vidc_audio_volume_l =
SCALE(lev_l, mlev_l);
111 vidc_audio_volume_r =
SCALE(lev_r, mlev_r);
118 static int vidc_mixer_ioctl(
int dev,
unsigned int cmd,
void __user *
arg)
129 if (
get_user(val, (
unsigned int __user *)arg))
133 vidc_mixer_set(mdev, val);
164 val = vidc_level_l[mdev] | vidc_level_r[mdev] << 8;
172 static unsigned int vidc_audio_set_format(
int dev,
unsigned int fmt)
180 vidc_audio_format =
fmt;
185 return vidc_audio_format;
188 #define my_abs(i) ((i)<0 ? -(i) : (i))
190 static int vidc_audio_set_speed(
int dev,
int rate)
193 unsigned int hwctrl, hwrate, hwrate_ext, rate_int, rate_ext;
194 unsigned int diff_int, diff_ext;
195 unsigned int newsize, new2size;
210 if (hwrate_ext > 255)
217 diff_int =
my_abs(rate_ext-rate);
218 diff_ext =
my_abs(rate_int-rate);
219 if (diff_ext < diff_int) {
224 if (diff_ext > (rate/256))
230 if (diff_int > (rate/256))
237 newsize = (10000 / hwrate) & ~3;
242 for (new2size = 128; new2size < newsize; new2size <<= 1);
243 if (new2size - newsize > newsize - (new2size >> 1))
245 if (new2size > 4096) {
252 vidc_audio_rate =
rate;
254 return vidc_audio_rate;
257 static short vidc_audio_set_channels(
int dev,
short channels)
269 return vidc_audio_channels;
275 static int vidc_audio_open(
int dev,
int mode)
291 static void vidc_audio_close(
int dev)
305 vidc_audio_output_block(
int dev,
unsigned long buf,
int total_count,
int one)
317 vidc_audio_start_input(
int dev,
unsigned long buf,
int count,
int intrflag)
321 static int vidc_audio_prepare_for_input(
int dev,
int bsize,
int bcount)
338 static int vidc_audio_prepare_for_output(
int dev,
int bsize,
int bcount)
351 static void vidc_audio_reset(
int dev)
356 static int vidc_audio_local_qlen(
int dev)
361 static void vidc_audio_trigger(
int dev,
int enable_bits)
386 .open = vidc_audio_open,
387 .close = vidc_audio_close,
388 .output_block = vidc_audio_output_block,
389 .start_input = vidc_audio_start_input,
390 .prepare_for_input = vidc_audio_prepare_for_input,
391 .prepare_for_output = vidc_audio_prepare_for_output,
392 .halt_io = vidc_audio_reset,
393 .local_qlen = vidc_audio_local_qlen,
394 .trigger = vidc_audio_trigger,
395 .set_speed = vidc_audio_set_speed,
396 .set_bits = vidc_audio_set_format,
397 .set_channels = vidc_audio_set_channels
404 .ioctl = vidc_mixer_ioctl
409 #define TYPE(fmt,ch) (((fmt)<<2) | ((ch)&3))
411 switch (
TYPE(format, channels)) {
449 &vidc_audio_driver,
sizeof(vidc_audio_driver),
464 name, &vidc_mixer_operations,
465 sizeof(vidc_mixer_operations),
NULL);
470 for (i = 0; i < 2; i++) {
486 hw_config->
name, &dma_start)) {
499 for (i = 0; i < 2; i++)
512 hw_config->
dma2 = -1;
514 hw_config->
name =
"VIDC20";
520 int i, adev = vidc_adev;
530 for (i = 0; i < 2; i++)
537 static int __init init_vidc(
void)
539 if (probe_vidc(&
cfg) == 0)
547 static void __exit cleanup_vidc(
void)