// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Auvitek AU8522 QAM/8VSB demodulator driver and video decoder
*
* Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org>
* Copyright (C) 2005-2008 Auvitek International, Ltd.
*/
/* Developer notes:
*
* Enough is implemented here for CVBS and S-Video inputs, but the actual
* analog demodulator code isn't implemented (not needed for xc5000 since it
* has its own demodulator and outputs CVBS)
*
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/videodev2.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <media/v4l2-common.h>
#include <media/v4l2-device.h>
#include "au8522.h"
#include "au8522_priv.h"
MODULE_AUTHOR("Devin Heitmueller" );
MODULE_DESCRIPTION("Auvitek AU8522 QAM/8VSB demodulator driver and video decoder" );
MODULE_LICENSE("GPL" );
static int au8522_analog_debug;
module_param_named(analog_debug, au8522_analog_debug, int , 0644 );
MODULE_PARM_DESC(analog_debug,
"Analog debugging messages [0=Off (default) 1=On]" );
struct au8522_register_config {
u16 reg_name;
u8 reg_val[8 ];
};
/* Video Decoder Filter Coefficients
The values are as follows from left to right
0="ATV RF" 1="ATV RF13" 2="CVBS" 3="S-Video" 4="PAL" 5=CVBS13" 6="SVideo13"
*/
static const struct au8522_register_config filter_coef[] = {
{AU8522_FILTER_COEF_R410, {0 x25, 0 x00, 0 x25, 0 x25, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R411, {0 x20, 0 x00, 0 x20, 0 x20, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R412, {0 x03, 0 x00, 0 x03, 0 x03, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R413, {0 xe6, 0 x00, 0 xe6, 0 xe6, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R414, {0 x40, 0 x00, 0 x40, 0 x40, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R415, {0 x1b, 0 x00, 0 x1b, 0 x1b, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R416, {0 xc0, 0 x00, 0 xc0, 0 x04, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R417, {0 x04, 0 x00, 0 x04, 0 x04, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R418, {0 x8c, 0 x00, 0 x8c, 0 x8c, 0 x00, 0 x00, 0 x00} },
{AU8522_FILTER_COEF_R419, {0 xa0, 0 x40, 0 xa0, 0 xa0, 0 x40, 0 x40, 0 x40} },
{AU8522_FILTER_COEF_R41A, {0 x21, 0 x09, 0 x21, 0 x21, 0 x09, 0 x09, 0 x09} },
{AU8522_FILTER_COEF_R41B, {0 x6c, 0 x38, 0 x6c, 0 x6c, 0 x38, 0 x38, 0 x38} },
{AU8522_FILTER_COEF_R41C, {0 x03, 0 xff, 0 x03, 0 x03, 0 xff, 0 xff, 0 xff} },
{AU8522_FILTER_COEF_R41D, {0 xbf, 0 xc7, 0 xbf, 0 xbf, 0 xc7, 0 xc7, 0 xc7} },
{AU8522_FILTER_COEF_R41E, {0 xa0, 0 xdf, 0 xa0, 0 xa0, 0 xdf, 0 xdf, 0 xdf} },
{AU8522_FILTER_COEF_R41F, {0 x10, 0 x06, 0 x10, 0 x10, 0 x06, 0 x06, 0 x06} },
{AU8522_FILTER_COEF_R420, {0 xae, 0 x30, 0 xae, 0 xae, 0 x30, 0 x30, 0 x30} },
{AU8522_FILTER_COEF_R421, {0 xc4, 0 x01, 0 xc4, 0 xc4, 0 x01, 0 x01, 0 x01} },
{AU8522_FILTER_COEF_R422, {0 x54, 0 xdd, 0 x54, 0 x54, 0 xdd, 0 xdd, 0 xdd} },
{AU8522_FILTER_COEF_R423, {0 xd0, 0 xaf, 0 xd0, 0 xd0, 0 xaf, 0 xaf, 0 xaf} },
{AU8522_FILTER_COEF_R424, {0 x1c, 0 xf7, 0 x1c, 0 x1c, 0 xf7, 0 xf7, 0 xf7} },
{AU8522_FILTER_COEF_R425, {0 x76, 0 xdb, 0 x76, 0 x76, 0 xdb, 0 xdb, 0 xdb} },
{AU8522_FILTER_COEF_R426, {0 x61, 0 xc0, 0 x61, 0 x61, 0 xc0, 0 xc0, 0 xc0} },
{AU8522_FILTER_COEF_R427, {0 xd1, 0 x2f, 0 xd1, 0 xd1, 0 x2f, 0 x2f, 0 x2f} },
{AU8522_FILTER_COEF_R428, {0 x84, 0 xd8, 0 x84, 0 x84, 0 xd8, 0 xd8, 0 xd8} },
{AU8522_FILTER_COEF_R429, {0 x06, 0 xfb, 0 x06, 0 x06, 0 xfb, 0 xfb, 0 xfb} },
{AU8522_FILTER_COEF_R42A, {0 x21, 0 xd5, 0 x21, 0 x21, 0 xd5, 0 xd5, 0 xd5} },
{AU8522_FILTER_COEF_R42B, {0 x0a, 0 x3e, 0 x0a, 0 x0a, 0 x3e, 0 x3e, 0 x3e} },
{AU8522_FILTER_COEF_R42C, {0 xe6, 0 x15, 0 xe6, 0 xe6, 0 x15, 0 x15, 0 x15} },
{AU8522_FILTER_COEF_R42D, {0 x01, 0 x34, 0 x01, 0 x01, 0 x34, 0 x34, 0 x34} },
};
#define NUM_FILTER_COEF (sizeof (filter_coef)\
/ sizeof (struct au8522_register_config))
/* Registers 0x060b through 0x0652 are the LP Filter coefficients
The values are as follows from left to right
0="SIF" 1="ATVRF/ATVRF13"
Note: the "ATVRF/ATVRF13" mode has never been tested
*/
static const struct au8522_register_config lpfilter_coef[] = {
{0 x060b, {0 x21, 0 x0b} },
{0 x060c, {0 xad, 0 xad} },
{0 x060d, {0 x70, 0 xf0} },
{0 x060e, {0 xea, 0 xe9} },
{0 x060f, {0 xdd, 0 xdd} },
{0 x0610, {0 x08, 0 x64} },
{0 x0611, {0 x60, 0 x60} },
{0 x0612, {0 xf8, 0 xb2} },
{0 x0613, {0 x01, 0 x02} },
{0 x0614, {0 xe4, 0 xb4} },
{0 x0615, {0 x19, 0 x02} },
{0 x0616, {0 xae, 0 x2e} },
{0 x0617, {0 xee, 0 xc5} },
{0 x0618, {0 x56, 0 x56} },
{0 x0619, {0 x30, 0 x58} },
{0 x061a, {0 xf9, 0 xf8} },
{0 x061b, {0 x24, 0 x64} },
{0 x061c, {0 x07, 0 x07} },
{0 x061d, {0 x30, 0 x30} },
{0 x061e, {0 xa9, 0 xed} },
{0 x061f, {0 x09, 0 x0b} },
{0 x0620, {0 x42, 0 xc2} },
{0 x0621, {0 x1d, 0 x2a} },
{0 x0622, {0 xd6, 0 x56} },
{0 x0623, {0 x95, 0 x8b} },
{0 x0624, {0 x2b, 0 x2b} },
{0 x0625, {0 x30, 0 x24} },
{0 x0626, {0 x3e, 0 x3e} },
{0 x0627, {0 x62, 0 xe2} },
{0 x0628, {0 xe9, 0 xf5} },
{0 x0629, {0 x99, 0 x19} },
{0 x062a, {0 xd4, 0 x11} },
{0 x062b, {0 x03, 0 x04} },
{0 x062c, {0 xb5, 0 x85} },
{0 x062d, {0 x1e, 0 x20} },
{0 x062e, {0 x2a, 0 xea} },
{0 x062f, {0 xd7, 0 xd2} },
{0 x0630, {0 x15, 0 x15} },
{0 x0631, {0 xa3, 0 xa9} },
{0 x0632, {0 x1f, 0 x1f} },
{0 x0633, {0 xf9, 0 xd1} },
{0 x0634, {0 xc0, 0 xc3} },
{0 x0635, {0 x4d, 0 x8d} },
{0 x0636, {0 x21, 0 x31} },
{0 x0637, {0 x83, 0 x83} },
{0 x0638, {0 x08, 0 x8c} },
{0 x0639, {0 x19, 0 x19} },
{0 x063a, {0 x45, 0 xa5} },
{0 x063b, {0 xef, 0 xec} },
{0 x063c, {0 x8a, 0 x8a} },
{0 x063d, {0 xf4, 0 xf6} },
{0 x063e, {0 x8f, 0 x8f} },
{0 x063f, {0 x44, 0 x0c} },
{0 x0640, {0 xef, 0 xf0} },
{0 x0641, {0 x66, 0 x66} },
{0 x0642, {0 xcc, 0 xd2} },
{0 x0643, {0 x41, 0 x41} },
{0 x0644, {0 x63, 0 x93} },
{0 x0645, {0 x8e, 0 x8e} },
{0 x0646, {0 xa2, 0 x42} },
{0 x0647, {0 x7b, 0 x7b} },
{0 x0648, {0 x04, 0 x04} },
{0 x0649, {0 x00, 0 x00} },
{0 x064a, {0 x40, 0 x40} },
{0 x064b, {0 x8c, 0 x98} },
{0 x064c, {0 x00, 0 x00} },
{0 x064d, {0 x63, 0 xc3} },
{0 x064e, {0 x04, 0 x04} },
{0 x064f, {0 x20, 0 x20} },
{0 x0650, {0 x00, 0 x00} },
{0 x0651, {0 x40, 0 x40} },
{0 x0652, {0 x01, 0 x01} },
};
#define NUM_LPFILTER_COEF (sizeof (lpfilter_coef)\
/ sizeof (struct au8522_register_config))
static inline struct au8522_state *to_state(struct v4l2_subdev *sd)
{
return container_of(sd, struct au8522_state, sd);
}
static void setup_decoder_defaults(struct au8522_state *state, bool is_svideo)
{
int i;
int filter_coef_type;
/* Provide reasonable defaults for picture tuning values */
au8522_writereg(state, AU8522_TVDEC_SHARPNESSREG009H, 0 x07);
au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, 0 xed);
au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, 0 x79);
au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH, 0 x80);
au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH, 0 x80);
au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH, 0 x00);
au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH, 0 x00);
/* Other decoder registers */
au8522_writereg(state, AU8522_TVDEC_INT_MASK_REG010H, 0 x00);
if (is_svideo)
au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0 x04);
else
au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0 x00);
au8522_writereg(state, AU8522_TVDEC_PGA_REG012H,
AU8522_TVDEC_PGA_REG012H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_MODE_REG015H,
AU8522_TVDEC_COMB_MODE_REG015H_CVBS);
au8522_writereg(state, AU8522_TVDED_DBG_MODE_REG060H,
AU8522_TVDED_DBG_MODE_REG060H_CVBS);
if (state->std == V4L2_STD_PAL_M) {
au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H,
AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525 |
AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492 |
AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_AUTO);
au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H,
AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_PAL_M);
} else {
/* NTSC */
au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H,
AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525 |
AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492 |
AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_MN);
au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H,
AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_NTSC);
}
au8522_writereg(state, AU8522_TVDEC_VCR_DET_LLIM_REG063H,
AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS);
au8522_writereg(state, AU8522_TVDEC_VCR_DET_HLIM_REG064H,
AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR1_REG065H,
AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR2_REG066H,
AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR3_REG067H,
AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_NOTCH_THR_REG068H,
AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR1_REG069H,
AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR2_REG06AH,
AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH,
AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS);
if (is_svideo) {
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO);
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO);
} else {
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS);
}
au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH,
AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS);
au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH,
AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H,
AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS);
au8522_writereg(state, AU8522_REG071H, AU8522_REG071H_CVBS);
au8522_writereg(state, AU8522_REG072H, AU8522_REG072H_CVBS);
au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H,
AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS);
au8522_writereg(state, AU8522_REG074H, AU8522_REG074H_CVBS);
au8522_writereg(state, AU8522_REG075H, AU8522_REG075H_CVBS);
au8522_writereg(state, AU8522_TVDEC_DCAGC_CTRL_REG077H,
AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS);
au8522_writereg(state, AU8522_TVDEC_PIC_START_ADJ_REG078H,
AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS);
au8522_writereg(state, AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H,
AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS);
au8522_writereg(state, AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH,
AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS);
au8522_writereg(state, AU8522_TVDEC_INTRP_CTRL_REG07BH,
AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS);
au8522_writereg(state, AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H,
AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS);
au8522_writereg(state, AU8522_TOREGAAGC_REG0E5H,
AU8522_TOREGAAGC_REG0E5H_CVBS);
au8522_writereg(state, AU8522_REG016H, AU8522_REG016H_CVBS);
/*
* Despite what the table says, for the HVR-950q we still need
* to be in CVBS mode for the S-Video input (reason unknown).
*/
/* filter_coef_type = 3; */
filter_coef_type = 5 ;
/* Load the Video Decoder Filter Coefficients */
for (i = 0 ; i < NUM_FILTER_COEF; i++) {
au8522_writereg(state, filter_coef[i].reg_name,
filter_coef[i].reg_val[filter_coef_type]);
}
/* It's not clear what these registers are for, but they are always
set to the same value regardless of what mode we're in */
au8522_writereg(state, AU8522_REG42EH, 0 x87);
au8522_writereg(state, AU8522_REG42FH, 0 xa2);
au8522_writereg(state, AU8522_REG430H, 0 xbf);
au8522_writereg(state, AU8522_REG431H, 0 xcb);
au8522_writereg(state, AU8522_REG432H, 0 xa1);
au8522_writereg(state, AU8522_REG433H, 0 x41);
au8522_writereg(state, AU8522_REG434H, 0 x88);
au8522_writereg(state, AU8522_REG435H, 0 xc2);
au8522_writereg(state, AU8522_REG436H, 0 x3c);
}
static void au8522_setup_cvbs_mode(struct au8522_state *state, u8 input_mode)
{
/* here we're going to try the pre-programmed route */
au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
/* PGA in automatic mode */
au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0 x00);
/* Enable clamping control */
au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0 x00);
au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
setup_decoder_defaults(state, false );
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
}
static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state,
u8 input_mode)
{
/* here we're going to try the pre-programmed route */
au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
/* It's not clear why we have to have the PGA in automatic mode while
enabling clamp control, but it's what Windows does */
au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0 x00);
/* Enable clamping control */
au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0 x0e);
/* Disable automatic PGA (since the CVBS is coming from the tuner) */
au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0 x10);
/* Set input mode to CVBS on channel 4 with SIF audio input enabled */
au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
setup_decoder_defaults(state, false );
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
}
static void au8522_setup_svideo_mode(struct au8522_state *state,
u8 input_mode)
{
au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO);
/* Set input to Y on Channe1, C on Channel 3 */
au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, input_mode);
/* PGA in automatic mode */
au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0 x00);
/* Enable clamping control */
au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0 x00);
setup_decoder_defaults(state, true );
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
}
/* ----------------------------------------------------------------------- */
static void disable_audio_input(struct au8522_state *state)
{
au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0 x00);
au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0 x00);
au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0 x00);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0 x04);
au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0 x02);
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO);
}
/* 0=disable, 1=SIF */
static void set_audio_input(struct au8522_state *state)
{
int aud_input = state->aud_input;
int i;
/* Note that this function needs to be used in conjunction with setting
the input routing via register 0x81 */
if (aud_input == AU8522_AUDIO_NONE) {
disable_audio_input(state);
return ;
}
if (aud_input != AU8522_AUDIO_SIF) {
/* The caller asked for a mode we don't currently support */
printk(KERN_ERR "Unsupported audio mode requested! mode=%d\n" ,
aud_input);
return ;
}
/* Load the Audio Decoder Filter Coefficients */
for (i = 0 ; i < NUM_LPFILTER_COEF; i++) {
au8522_writereg(state, lpfilter_coef[i].reg_name,
lpfilter_coef[i].reg_val[0 ]);
}
/* Set the volume */
au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0 x7F);
au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0 x7F);
au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0 xff);
/* Not sure what this does */
au8522_writereg(state, AU8522_REG0F9H, AU8522_REG0F9H_AUDIO);
/* Setup the audio mode to stereo DBX */
au8522_writereg(state, AU8522_AUDIO_MODE_REG0F1H, 0 x82);
msleep(70 );
/* Start the audio processing module */
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0 x9d);
/* Set the audio frequency to 48 KHz */
au8522_writereg(state, AU8522_AUDIOFREQ_REG606H, 0 x03);
/* Set the I2S parameters (WS, LSB, mode, sample rate */
au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0 xc2);
/* Enable the I2S output */
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0 x09);
}
/* ----------------------------------------------------------------------- */
static int au8522_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct au8522_state *state =
container_of(ctrl->handler, struct au8522_state, hdl);
switch (ctrl->id) {
case V4L2_CID_BRIGHTNESS:
au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH,
ctrl->val - 128 );
break ;
case V4L2_CID_CONTRAST:
au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH,
ctrl->val);
break ;
case V4L2_CID_SATURATION:
au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH,
ctrl->val);
au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH,
ctrl->val);
break ;
case V4L2_CID_HUE:
au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH,
ctrl->val >> 8 );
au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH,
ctrl->val & 0 xFF);
break ;
default :
return -EINVAL;
}
return 0 ;
}
/* ----------------------------------------------------------------------- */
#ifdef CONFIG_VIDEO_ADV_DEBUG
static int au8522_g_register(struct v4l2_subdev *sd,
struct v4l2_dbg_register *reg)
{
struct au8522_state *state = to_state(sd);
reg->val = au8522_readreg(state, reg->reg & 0 xffff);
return 0 ;
}
static int au8522_s_register(struct v4l2_subdev *sd,
const struct v4l2_dbg_register *reg)
{
struct au8522_state *state = to_state(sd);
au8522_writereg(state, reg->reg, reg->val & 0 xff);
return 0 ;
}
#endif
static void au8522_video_set(struct au8522_state *state)
{
u8 input_mode;
au8522_writereg(state, 0 xa4, 1 << 5 );
switch (state->vid_input) {
case AU8522_COMPOSITE_CH1:
input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH1;
au8522_setup_cvbs_mode(state, input_mode);
break ;
case AU8522_COMPOSITE_CH2:
input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH2;
au8522_setup_cvbs_mode(state, input_mode);
break ;
case AU8522_COMPOSITE_CH3:
input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH3;
au8522_setup_cvbs_mode(state, input_mode);
break ;
case AU8522_COMPOSITE_CH4:
input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH4;
au8522_setup_cvbs_mode(state, input_mode);
break ;
case AU8522_SVIDEO_CH13:
input_mode = AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13;
au8522_setup_svideo_mode(state, input_mode);
break ;
case AU8522_SVIDEO_CH24:
input_mode = AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24;
au8522_setup_svideo_mode(state, input_mode);
break ;
default :
case AU8522_COMPOSITE_CH4_SIF:
input_mode = AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF;
au8522_setup_cvbs_tuner_mode(state, input_mode);
break ;
}
}
static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
{
struct au8522_state *state = to_state(sd);
if (enable) {
/*
* Clear out any state associated with the digital side of the
* chip, so that when it gets powered back up it won't think
* that it is already tuned
*/
state->current_frequency = 0 ;
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
0 x01);
msleep(10 );
au8522_video_set(state);
set_audio_input(state);
state->operational_mode = AU8522_ANALOG_MODE;
} else {
/* This does not completely power down the device
(it only reduces it from around 140ma to 80ma) */
au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
1 << 5 );
state->operational_mode = AU8522_SUSPEND_MODE;
}
return 0 ;
}
static int au8522_s_video_routing(struct v4l2_subdev *sd,
u32 input, u32 output, u32 config)
{
struct au8522_state *state = to_state(sd);
switch (input) {
case AU8522_COMPOSITE_CH1:
case AU8522_SVIDEO_CH13:
case AU8522_COMPOSITE_CH4_SIF:
state->vid_input = input;
break ;
default :
printk(KERN_ERR "au8522 mode not currently supported\n" );
return -EINVAL;
}
if (state->operational_mode == AU8522_ANALOG_MODE)
au8522_video_set(state);
return 0 ;
}
static int au8522_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
{
struct au8522_state *state = to_state(sd);
if ((std & (V4L2_STD_PAL_M | V4L2_STD_NTSC_M)) == 0 )
return -EINVAL;
state->std = std;
if (state->operational_mode == AU8522_ANALOG_MODE)
au8522_video_set(state);
return 0 ;
}
static int au8522_s_audio_routing(struct v4l2_subdev *sd,
u32 input, u32 output, u32 config)
{
struct au8522_state *state = to_state(sd);
state->aud_input = input;
if (state->operational_mode == AU8522_ANALOG_MODE)
set_audio_input(state);
return 0 ;
}
static int au8522_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
{
int val = 0 ;
struct au8522_state *state = to_state(sd);
u8 lock_status;
u8 pll_status;
/* Interrogate the decoder to see if we are getting a real signal */
lock_status = au8522_readreg(state, 0 x00);
pll_status = au8522_readreg(state, 0 x7e);
if ((lock_status == 0 xa2) && (pll_status & 0 x10))
vt->signal = 0 xffff;
else
vt->signal = 0 x00;
vt->capability |=
V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
val = V4L2_TUNER_SUB_MONO;
vt->rxsubchans = val;
vt->audmode = V4L2_TUNER_MODE_STEREO;
return 0 ;
}
/* ----------------------------------------------------------------------- */
static const struct v4l2_subdev_core_ops au8522_core_ops = {
.log_status = v4l2_ctrl_subdev_log_status,
#ifdef CONFIG_VIDEO_ADV_DEBUG
.g_register = au8522_g_register,
.s_register = au8522_s_register,
#endif
};
static const struct v4l2_subdev_tuner_ops au8522_tuner_ops = {
.g_tuner = au8522_g_tuner,
};
static const struct v4l2_subdev_audio_ops au8522_audio_ops = {
.s_routing = au8522_s_audio_routing,
};
static const struct v4l2_subdev_video_ops au8522_video_ops = {
.s_routing = au8522_s_video_routing,
.s_stream = au8522_s_stream,
.s_std = au8522_s_std,
};
static const struct v4l2_subdev_ops au8522_ops = {
.core = &au8522_core_ops,
.tuner = &au8522_tuner_ops,
.audio = &au8522_audio_ops,
.video = &au8522_video_ops,
};
static const struct v4l2_ctrl_ops au8522_ctrl_ops = {
.s_ctrl = au8522_s_ctrl,
};
/* ----------------------------------------------------------------------- */
static int au8522_probe(struct i2c_client *client)
{
struct au8522_state *state;
struct v4l2_ctrl_handler *hdl;
struct v4l2_subdev *sd;
int instance;
#ifdef CONFIG_MEDIA_CONTROLLER
int ret;
#endif
/* Check if the adapter supports the needed features */
if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_BYTE_DATA)) {
return -EIO;
}
/* allocate memory for the internal state */
instance = au8522_get_state(&state, client->adapter, client->addr);
switch (instance) {
case 0 :
printk(KERN_ERR "au8522_decoder allocation failed\n" );
return -EIO;
case 1 :
/* new demod instance */
printk(KERN_INFO "au8522_decoder creating new instance...\n" );
break ;
default :
/* existing demod instance */
printk(KERN_INFO "au8522_decoder attach existing instance.\n" );
break ;
}
state->config.demod_address = 0 x8e >> 1 ;
state->i2c = client->adapter;
sd = &state->sd;
v4l2_i2c_subdev_init(sd, client, &au8522_ops);
#if defined (CONFIG_MEDIA_CONTROLLER)
state->pads[AU8522_PAD_IF_INPUT].flags = MEDIA_PAD_FL_SINK;
state->pads[AU8522_PAD_IF_INPUT].sig_type = PAD_SIGNAL_ANALOG;
state->pads[AU8522_PAD_VID_OUT].flags = MEDIA_PAD_FL_SOURCE;
state->pads[AU8522_PAD_VID_OUT].sig_type = PAD_SIGNAL_DV;
state->pads[AU8522_PAD_AUDIO_OUT].flags = MEDIA_PAD_FL_SOURCE;
state->pads[AU8522_PAD_AUDIO_OUT].sig_type = PAD_SIGNAL_AUDIO;
sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
ret = media_entity_pads_init(&sd->entity, ARRAY_SIZE(state->pads),
state->pads);
if (ret < 0 ) {
v4l_info(client, "failed to initialize media entity!\n" );
return ret;
}
#endif
hdl = &state->hdl;
v4l2_ctrl_handler_init(hdl, 4 );
v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
V4L2_CID_BRIGHTNESS, 0 , 255 , 1 , 109 );
v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
V4L2_CID_CONTRAST, 0 , 255 , 1 ,
AU8522_TVDEC_CONTRAST_REG00BH_CVBS);
v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
V4L2_CID_SATURATION, 0 , 255 , 1 , 128 );
v4l2_ctrl_new_std(hdl, &au8522_ctrl_ops,
V4L2_CID_HUE, -32768 , 32767 , 1 , 0 );
sd->ctrl_handler = hdl;
if (hdl->error) {
int err = hdl->error;
v4l2_ctrl_handler_free(hdl);
au8522_release_state(state);
return err;
}
state->c = client;
state->std = V4L2_STD_NTSC_M;
state->vid_input = AU8522_COMPOSITE_CH1;
state->aud_input = AU8522_AUDIO_NONE;
state->id = 8522 ;
state->rev = 0 ;
/* Jam open the i2c gate to the tuner */
au8522_writereg(state, 0 x106, 1 );
return 0 ;
}
static void au8522_remove(struct i2c_client *client)
{
struct v4l2_subdev *sd = i2c_get_clientdata(client);
v4l2_device_unregister_subdev(sd);
v4l2_ctrl_handler_free(sd->ctrl_handler);
au8522_release_state(to_state(sd));
}
static const struct i2c_device_id au8522_id[] = {
{ "au8522" },
{}
};
MODULE_DEVICE_TABLE(i2c, au8522_id);
static struct i2c_driver au8522_driver = {
.driver = {
.name = "au8522" ,
},
.probe = au8522_probe,
.remove = au8522_remove,
.id_table = au8522_id,
};
module_i2c_driver(au8522_driver);
Messung V0.5 in Prozent C=94 H=91 G=92
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-05)
¤
*© Formatika GbR, Deutschland