/*
cx88x-audio.c - Conexant CX23880/23881 audio downstream driver driver
(c) 2001 Michael Eskin, Tom Zakrajsek [Windows version]
(c) 2002 Yurij Sysoev <yurij@naturesoft.net>
(c) 2003 Gerd Knorr <kraxel@bytesex.org>
-----------------------------------------------------------------------
Lot of voodoo here. Even the data sheet doesn't help to
understand what is going on here, the documentation for the audio
part of the cx2388x chip is *very* bad.
Some of this comes from party done linux driver sources I got from
[undocumented].
Some comes from the dscaler sources, one of the dscaler driver guy works
for Conexant ...
-----------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/freezer.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/poll.h>
#include <linux/signal.h>
#include <linux/ioport.h>
#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/kthread.h>
#include "cx88.h"
static unsigned int audio_debug;
module_param(audio_debug, int, 0644);
MODULE_PARM_DESC(audio_debug, "enable debug messages [audio]");
static unsigned int always_analog;
module_param(always_analog,int,0644);
MODULE_PARM_DESC(always_analog,"force analog audio out");
static unsigned int radio_deemphasis;
module_param(radio_deemphasis,int,0644);
MODULE_PARM_DESC(radio_deemphasis, "Radio deemphasis time constant, "
"0=None, 1=50us (elsewhere), 2=75us (USA)");
#define dprintk(fmt, arg...) if (audio_debug) \
printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
/* ----------------------------------------------------------- */
static char *aud_ctl_names[64] = {
[EN_BTSC_FORCE_MONO] = "BTSC_FORCE_MONO",
[EN_BTSC_FORCE_STEREO] = "BTSC_FORCE_STEREO",
[EN_BTSC_FORCE_SAP] = "BTSC_FORCE_SAP",
[EN_BTSC_AUTO_STEREO] = "BTSC_AUTO_STEREO",
[EN_BTSC_AUTO_SAP] = "BTSC_AUTO_SAP",
[EN_A2_FORCE_MONO1] = "A2_FORCE_MONO1",
[EN_A2_FORCE_MONO2] = "A2_FORCE_MONO2",
[EN_A2_FORCE_STEREO] = "A2_FORCE_STEREO",
[EN_A2_AUTO_MONO2] = "A2_AUTO_MONO2",
[EN_A2_AUTO_STEREO] = "A2_AUTO_STEREO",
[EN_EIAJ_FORCE_MONO1] = "EIAJ_FORCE_MONO1",
[EN_EIAJ_FORCE_MONO2] = "EIAJ_FORCE_MONO2",
[EN_EIAJ_FORCE_STEREO] = "EIAJ_FORCE_STEREO",
[EN_EIAJ_AUTO_MONO2] = "EIAJ_AUTO_MONO2",
[EN_EIAJ_AUTO_STEREO] = "EIAJ_AUTO_STEREO",
[EN_NICAM_FORCE_MONO1] = "NICAM_FORCE_MONO1",
[EN_NICAM_FORCE_MONO2] = "NICAM_FORCE_MONO2",
[EN_NICAM_FORCE_STEREO] = "NICAM_FORCE_STEREO",
[EN_NICAM_AUTO_MONO2] = "NICAM_AUTO_MONO2",
[EN_NICAM_AUTO_STEREO] = "NICAM_AUTO_STEREO",
[EN_FMRADIO_FORCE_MONO] = "FMRADIO_FORCE_MONO",
[EN_FMRADIO_FORCE_STEREO] = "FMRADIO_FORCE_STEREO",
[EN_FMRADIO_AUTO_STEREO] = "FMRADIO_AUTO_STEREO",
};
struct rlist {
u32 reg;
u32 val;
};
static void set_audio_registers(struct cx88_core *core, const struct rlist *l)
{
int i;
for (i = 0; l[i].reg; i++) {
switch (l[i].reg) {
case AUD_PDF_DDS_CNST_BYTE2:
case AUD_PDF_DDS_CNST_BYTE1:
case AUD_PDF_DDS_CNST_BYTE0:
case AUD_QAM_MODE:
case AUD_PHACC_FREQ_8MSB:
case AUD_PHACC_FREQ_8LSB:
cx_writeb(l[i].reg, l[i].val);
break;
default:
cx_write(l[i].reg, l[i].val);
break;
}
}
}
static void set_audio_start(struct cx88_core *core, u32 mode)
{
/* mute */
cx_write(AUD_VOL_CTL, (1 << 6));
/* start programming */
cx_write(AUD_INIT, mode);
cx_write(AUD_INIT_LD, 0x0001);
cx_write(AUD_SOFT_RESET, 0x0001);
}
static void set_audio_finish(struct cx88_core *core, u32 ctl)
{
u32 volume;
/* restart dma; This avoids buzz in NICAM and is good in others */
cx88_stop_audio_dma(core);
cx_write(AUD_RATE_THRES_DMD, 0x000000C0);
cx88_start_audio_dma(core);
if (core->board.mpeg & CX88_MPEG_BLACKBIRD) {
cx_write(AUD_I2SINPUTCNTL, 4);
cx_write(AUD_BAUDRATE, 1);
/* 'pass-thru mode': this enables the i2s output to the mpeg encoder */
cx_set(AUD_CTL, EN_I2SOUT_ENABLE);
cx_write(AUD_I2SOUTPUTCNTL, 1);
cx_write(AUD_I2SCNTL, 0);
/* cx_write(AUD_APB_IN_RATE_ADJ, 0); */
}
if ((always_analog) || (!(core->board.mpeg