Commit bd403b67 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] dvb: av7110 driver splitup

From: Michael Hunold <hunold@linuxtv.org>

- after the firmware removal, split av7110.c into separate modules:

  - av7110.c: initialization and demux stuff

  - av7110_hw.c: lowlevel hardware access and firmware interface

  - av7110_ca.c: CI and ECD

  - av7110_av.c: audio/video MPEG decoder and remuxing stuff

  - av7110_v4l.c: v4l interface

- av7110 fixes that were notcies during splitup

  - rename some non-static functions to enhance readability

  - lots of coding style & whitespace fixes

  - return -ERESTARTSYS from ci_ll_read/write() if interrupted

  - use time_after() for timeouts

  - added some comments about firmware interface

  - removed some unused fields from struct av7110, retabbing

- follow driver splitup in Makefile
parent 485237d6
......@@ -3,7 +3,7 @@
# and the AV7110 DVB device driver
#
dvb-ttpci-objs := av7110.o av7110_ipack.o av7110_ir.o
dvb-ttpci-objs := av7110_hw.o av7110_v4l.o av7110_av.o av7110_ca.o av7110.o av7110_ipack.o av7110_ir.o
obj-$(CONFIG_DVB_BUDGET) += budget-core.o budget.o ttpci-eeprom.o
obj-$(CONFIG_DVB_BUDGET_AV) += budget-core.o budget-av.o ttpci-eeprom.o
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -11,18 +11,6 @@
#include <media/saa7146_vv.h>
/* DEBI transfer mode defs */
#define DEBINOSWAP 0x000e0000
#define DEBISWAB 0x001e0000
#define DEBISWAP 0x002e0000
#define ARM_WAIT_FREE (HZ)
#define ARM_WAIT_SHAKE (HZ/5)
#define ARM_WAIT_OSD (HZ)
#define WAIT_QUEUE wait_queue_head_t
#include <linux/dvb/video.h>
#include <linux/dvb/audio.h>
#include <linux/dvb/dmx.h>
......@@ -38,336 +26,9 @@
#include "dvb_net.h"
#include "dvb_ringbuffer.h"
enum av7110_bootstate
{
BOOTSTATE_BUFFER_EMPTY = 0,
BOOTSTATE_BUFFER_FULL = 1,
BOOTSTATE_BOOT_COMPLETE = 2
};
enum av7110_type_rec_play_format
{ RP_None,
AudioPES,
AudioMp2,
AudioPCM,
VideoPES,
AV_PES
};
enum av7110_osd_palette_type
{
NoPalet = 0, /* No palette */
Pal1Bit = 2, /* 2 colors for 1 Bit Palette */
Pal2Bit = 4, /* 4 colors for 2 bit palette */
Pal4Bit = 16, /* 16 colors for 4 bit palette */
Pal8Bit = 256 /* 256 colors for 16 bit palette */
};
enum av7110_window_display_type {
BITMAP1, /* 1 bit bitmap */
BITMAP2, /* 2 bit bitmap */
BITMAP4, /* 4 bit bitmap */
BITMAP8, /* 8 bit bitmap */
BITMAP1HR, /* 1 Bit bitmap half resolution */
BITMAP2HR, /* 2 bit bitmap half resolution */
BITMAP4HR, /* 4 bit bitmap half resolution */
BITMAP8HR, /* 8 bit bitmap half resolution */
YCRCB422, /* 4:2:2 YCRCB Graphic Display */
YCRCB444, /* 4:4:4 YCRCB Graphic Display */
YCRCB444HR, /* 4:4:4 YCRCB graphic half resolution */
VIDEOTSIZE, /* True Size Normal MPEG Video Display */
VIDEOHSIZE, /* MPEG Video Display Half Resolution */
VIDEOQSIZE, /* MPEG Video Display Quarter Resolution */
VIDEODSIZE, /* MPEG Video Display Double Resolution */
VIDEOTHSIZE, /* True Size MPEG Video Display Half Resolution */
VIDEOTQSIZE, /* True Size MPEG Video Display Quarter Resolution*/
VIDEOTDSIZE, /* True Size MPEG Video Display Double Resolution */
VIDEONSIZE, /* Full Size MPEG Video Display */
CURSOR /* Cursor */
};
/* switch defines */
#define SB_GPIO 3
#define SB_OFF SAA7146_GPIO_OUTLO //SlowBlank aus (TV-Mode)
#define SB_ON SAA7146_GPIO_INPUT //SlowBlank an (AV-Mode)
#define SB_WIDE SAA7146_GPIO_OUTHI //SlowBlank 6V (16/9-Mode) nicht realisiert
#define FB_GPIO 1
#define FB_OFF SAA7146_GPIO_LO //FastBlank aus (CVBS-Mode)
#define FB_ON SAA7146_GPIO_OUTHI //FastBlank an (RGB-Mode)
#define FB_LOOP SAA7146_GPIO_INPUT //FastBlank der PC-Grafik durchschleifen
enum av7110_video_output_mode
{
NO_OUT = 0, //disable analog Output
CVBS_RGB_OUT = 1,
CVBS_YC_OUT = 2,
YC_OUT = 3
};
#define GPMQFull 0x0001 //Main Message Queue Full
#define GPMQOver 0x0002 //Main Message Queue Overflow
#define HPQFull 0x0004 //High Priority Msg Queue Full
#define HPQOver 0x0008
#define OSDQFull 0x0010 //OSD Queue Full
#define OSDQOver 0x0020
#define SECTION_EIT 0x01
#define SECTION_SINGLE 0x00
#define SECTION_CYCLE 0x02
#define SECTION_CONTINUOS 0x04
#define SECTION_MODE 0x06
#define SECTION_IPMPE 0x0C // bis zu 4k gro
#define SECTION_HIGH_SPEED 0x1C // vergrerter Puffer fr High Speed Filter
#define DATA_PIPING_FLAG 0x20 // fr Data Piping Filter
#define PBUFSIZE_NONE 0x0000
#define PBUFSIZE_1P 0x0100
#define PBUFSIZE_2P 0x0200
#define PBUFSIZE_1K 0x0300
#define PBUFSIZE_2K 0x0400
#define PBUFSIZE_4K 0x0500
#define PBUFSIZE_8K 0x0600
#define PBUFSIZE_16K 0x0700
#define PBUFSIZE_32K 0x0800
enum av7110_osd_command {
WCreate,
WDestroy,
WMoveD,
WMoveA,
WHide,
WTop,
DBox,
DLine,
DText,
Set_Font,
SetColor,
SetBlend,
SetWBlend,
SetCBlend,
SetNonBlend,
LoadBmp,
BlitBmp,
ReleaseBmp,
SetWTrans,
SetWNoTrans,
Set_Palette
};
enum av7110_pid_command {
MultiPID,
VideoPID,
AudioPID,
InitFilt,
FiltError,
NewVersion,
CacheError,
AddPIDFilter,
DelPIDFilter,
Scan,
SetDescr,
SetIR,
FlushTSQueue
};
enum av7110_mpeg_command {
SelAudChannels
};
enum av7110_audio_command {
AudioDAC,
CabADAC,
ON22K,
OFF22K,
MainSwitch,
ADSwitch,
SendDiSEqC,
SetRegister
};
enum av7110_request_command {
AudioState,
AudioBuffState,
VideoState1,
VideoState2,
VideoState3,
CrashCounter,
ReqVersion,
ReqVCXO,
ReqRegister,
ReqSecFilterError,
ReqSTC
};
enum av7110_encoder_command {
SetVidMode,
SetTestMode,
LoadVidCode,
SetMonitorType,
SetPanScanType,
SetFreezeMode
};
enum av7110_rec_play_state {
__Record,
__Stop,
__Play,
__Pause,
__Slow,
__FF_IP,
__Scan_I,
__Continue
};
enum av7110_command_type {
COMTYPE_NOCOM,
COMTYPE_PIDFILTER,
COMTYPE_MPEGDECODER,
COMTYPE_OSD,
COMTYPE_BMP,
COMTYPE_ENCODER,
COMTYPE_AUDIODAC,
COMTYPE_REQUEST,
COMTYPE_SYSTEM,
COMTYPE_REC_PLAY,
COMTYPE_COMMON_IF,
COMTYPE_PID_FILTER,
COMTYPE_PES,
COMTYPE_TS,
COMTYPE_VIDEO,
COMTYPE_AUDIO,
COMTYPE_CI_LL,
};
#define VID_NONE_PREF 0x00 /* No aspect ration processing preferred */
#define VID_PAN_SCAN_PREF 0x01 /* Pan and Scan Display preferred */
#define VID_VERT_COMP_PREF 0x02 /* Vertical compression display preferred */
#define VID_VC_AND_PS_PREF 0x03 /* PanScan and vertical Compression if allowed */
#define VID_CENTRE_CUT_PREF 0x05 /* PanScan with zero vector */
#define DATA_NONE 0x00
#define DATA_FSECTION 0x01
#define DATA_IPMPE 0x02
#define DATA_MPEG_RECORD 0x03
#define DATA_DEBUG_MESSAGE 0x04
#define DATA_COMMON_INTERFACE 0x05
#define DATA_MPEG_PLAY 0x06
#define DATA_BMP_LOAD 0x07
#define DATA_IRCOMMAND 0x08
#define DATA_PIPING 0x09
#define DATA_STREAMING 0x0a
#define DATA_CI_GET 0x0b
#define DATA_CI_PUT 0x0c
#define DATA_MPEG_VIDEO_EVENT 0x0d
#define DATA_PES_RECORD 0x10
#define DATA_PES_PLAY 0x11
#define DATA_TS_RECORD 0x12
#define DATA_TS_PLAY 0x13
#define CI_CMD_ERROR 0x00
#define CI_CMD_ACK 0x01
#define CI_CMD_SYSTEM_READY 0x02
#define CI_CMD_KEYPRESS 0x03
#define CI_CMD_ON_TUNED 0x04
#define CI_CMD_ON_SWITCH_PROGRAM 0x05
#define CI_CMD_SECTION_ARRIVED 0x06
#define CI_CMD_SECTION_TIMEOUT 0x07
#define CI_CMD_TIME 0x08
#define CI_CMD_ENTER_MENU 0x09
#define CI_CMD_FAST_PSI 0x0a
#define CI_CMD_GET_SLOT_INFO 0x0b
#define CI_MSG_NONE 0x00
#define CI_MSG_CI_INFO 0x01
#define CI_MSG_MENU 0x02
#define CI_MSG_LIST 0x03
#define CI_MSG_TEXT 0x04
#define CI_MSG_REQUEST_INPUT 0x05
#define CI_MSG_INPUT_COMPLETE 0x06
#define CI_MSG_LIST_MORE 0x07
#define CI_MSG_MENU_MORE 0x08
#define CI_MSG_CLOSE_MMI_IMM 0x09
#define CI_MSG_SECTION_REQUEST 0x0a
#define CI_MSG_CLOSE_FILTER 0x0b
#define CI_PSI_COMPLETE 0x0c
#define CI_MODULE_READY 0x0d
#define CI_SWITCH_PRG_REPLY 0x0e
#define CI_MSG_TEXT_MORE 0x0f
#define CI_MSG_CA_PMT 0xe0
#define CI_MSG_ERROR 0xf0
#define PROG_STREAM_MAP 0xBC
#define PRIVATE_STREAM1 0xBD
#define PADDING_STREAM 0xBE
#define PRIVATE_STREAM2 0xBF
#define AUDIO_STREAM_S 0xC0
#define AUDIO_STREAM_E 0xDF
#define VIDEO_STREAM_S 0xE0
#define VIDEO_STREAM_E 0xEF
#define ECM_STREAM 0xF0
#define EMM_STREAM 0xF1
#define DSM_CC_STREAM 0xF2
#define ISO13522_STREAM 0xF3
#define PROG_STREAM_DIR 0xFF
#define PTS_DTS_FLAGS 0xC0
//pts_dts flags
#define PTS_ONLY 0x80
#define PTS_DTS 0xC0
#define TS_SIZE 188
#define TRANS_ERROR 0x80
#define PAY_START 0x40
#define TRANS_PRIO 0x20
#define PID_MASK_HI 0x1F
//flags
#define TRANS_SCRMBL1 0x80
#define TRANS_SCRMBL2 0x40
#define ADAPT_FIELD 0x20
#define PAYLOAD 0x10
#define COUNT_MASK 0x0F
// adaptation flags
#define DISCON_IND 0x80
#define RAND_ACC_IND 0x40
#define ES_PRI_IND 0x20
#define PCR_FLAG 0x10
#define OPCR_FLAG 0x08
#define SPLICE_FLAG 0x04
#define TRANS_PRIV 0x02
#define ADAP_EXT_FLAG 0x01
// adaptation extension flags
#define LTW_FLAG 0x80
#define PIECE_RATE 0x40
#define SEAM_SPLICE 0x20
#define MAX_PLENGTH 0xFFFF
#define MAX_VID_PES 0x1FFF
#define MY_STATE_PES_START 1
#define MY_STATE_PES_STARTED 2
#define MY_STATE_FULL 4
#define MASKL DMX_MAX_FILTER_SIZE
#define MAXFILT 32
struct dvb_filter {
int state;
int flags;
int type;
u8 ts_state;
u16 pid;
u8 value[MASKL];
u8 mask[MASKL];
};
enum {AV_PES_STREAM, PS_STREAM, TS_STREAM, PES_STREAM};
struct av7110_p2t {
......@@ -436,15 +97,12 @@ struct av7110 {
int bmpp;
int bmplen;
int bmp_win;
u16 bmp_x, bmp_y;
int bmp_trans;
int bmp_state;
#define BMP_NONE 0
#define BMP_LOADING 1
#define BMP_LOADINGS 2
#define BMP_LOADED 3
WAIT_QUEUE bmpq;
wait_queue_head_t bmpq;
/* DEBI and polled command interface */
......@@ -453,7 +111,6 @@ struct av7110 {
struct semaphore dcomlock;
int debitype;
int debilen;
int debibuf;
/* Recording and playback flags */
......@@ -518,7 +175,7 @@ struct av7110 {
u32 avtype;
int arm_ready;
struct task_struct *arm_thread;
WAIT_QUEUE arm_wait;
wait_queue_head_t arm_wait;
u16 arm_loops;
int arm_rmmod;
......@@ -540,8 +197,6 @@ struct av7110 {
struct dvb_video_events video_events;
video_size_t video_size;
int dsp_dev;
u32 ir_config;
/* firmware stuff */
......@@ -558,81 +213,8 @@ struct av7110 {
};
#define DPRAM_BASE 0x4000
#define BOOT_STATE (DPRAM_BASE + 0x3F8)
#define BOOT_SIZE (DPRAM_BASE + 0x3FA)
#define BOOT_BASE (DPRAM_BASE + 0x3FC)
#define BOOT_BLOCK (DPRAM_BASE + 0x400)
#define BOOT_MAX_SIZE 0xc00
#define IRQ_STATE (DPRAM_BASE + 0x0F4)
#define IRQ_STATE_EXT (DPRAM_BASE + 0x0F6)
#define MSGSTATE (DPRAM_BASE + 0x0F8)
#define FILT_STATE (DPRAM_BASE + 0x0FA)
#define COMMAND (DPRAM_BASE + 0x0FC)
#define COM_BUFF (DPRAM_BASE + 0x100)
#define COM_BUFF_SIZE 0x20
#define BUFF1_BASE (DPRAM_BASE + 0x120)
#define BUFF1_SIZE 0xE0
#define DATA_BUFF_BASE (DPRAM_BASE + 0x200)
#define DATA_BUFF_SIZE 0x1C00
/* new buffers */
#define DATA_BUFF0_BASE (DPRAM_BASE + 0x200)
#define DATA_BUFF0_SIZE 0x0800
#define DATA_BUFF1_BASE (DATA_BUFF0_BASE+DATA_BUFF0_SIZE)
#define DATA_BUFF1_SIZE 0x0800
#define DATA_BUFF2_BASE (DATA_BUFF1_BASE+DATA_BUFF1_SIZE)
#define DATA_BUFF2_SIZE 0x0800
#define DATA_BUFF3_BASE (DATA_BUFF2_BASE+DATA_BUFF2_SIZE)
#define DATA_BUFF3_SIZE 0x0400
#define Reserved (DPRAM_BASE + 0x1E00)
#define Reserved_SIZE 0x1C0
#define STATUS_BASE (DPRAM_BASE + 0x1FC0)
#define STATUS_SCR (STATUS_BASE + 0x00)
#define STATUS_MODES (STATUS_BASE + 0x04)
#define STATUS_LOOPS (STATUS_BASE + 0x08)
#define STATUS_MPEG_WIDTH (STATUS_BASE + 0x0C)
/* ((aspect_ratio & 0xf) << 12) | (height & 0xfff) */
#define STATUS_MPEG_HEIGHT_AR (STATUS_BASE + 0x0E)
#define RX_TYPE (DPRAM_BASE + 0x1FE8)
#define RX_LEN (DPRAM_BASE + 0x1FEA)
#define TX_TYPE (DPRAM_BASE + 0x1FEC)
#define TX_LEN (DPRAM_BASE + 0x1FEE)
#define RX_BUFF (DPRAM_BASE + 0x1FF4)
#define TX_BUFF (DPRAM_BASE + 0x1FF6)
#define HANDSHAKE_REG (DPRAM_BASE + 0x1FF8)
#define COM_IF_LOCK (DPRAM_BASE + 0x1FFA)
#define IRQ_RX (DPRAM_BASE + 0x1FFC)
#define IRQ_TX (DPRAM_BASE + 0x1FFE)
#define DRAM_START_CODE 0x2e000404
#define DRAM_MAX_CODE_SIZE 0x00100000
#define RESET_LINE 2
#define DEBI_DONE_LINE 1
#define ARM_IRQ_LINE 0
#define DAC_CS 0x8000
#define DAC_CDS 0x0000
extern unsigned char *av7110_dpram_addr, *av7110_root_addr;
extern int av7110_dpram_len, av7110_root_len;
extern void ChangePIDs(struct av7110 *av7110, u16 vpid, u16 apid, u16 ttpid,
u16 subpid, u16 pcrpid);
extern void av7110_register_irc_handler(void (*func)(u32));
extern void av7110_unregister_irc_handler(void (*func)(u32));
......@@ -641,6 +223,21 @@ extern void av7110_setup_irc_config (struct av7110 *av7110, u32 ir_config);
extern int av7110_ir_init (void);
extern void av7110_ir_exit (void);
/* msp3400 i2c subaddresses */
#define MSP_WR_DEM 0x10
#define MSP_RD_DEM 0x11
#define MSP_WR_DSP 0x12
#define MSP_RD_DSP 0x13
extern int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val);
extern u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg);
extern int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val);
extern int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val);
extern int av7110_init_analog_module(struct av7110 *av7110);
extern int av7110_init_v4l(struct av7110 *av7110);
extern int av7110_exit_v4l(struct av7110 *av7110);
#endif /* _AV7110_H_ */
/*
* av7110_av.c: audio and video MPEG decoder stuff
*
* Copyright (C) 1999-2002 Ralph Metzler
* & Marcus Metzler for convergence integrated media GmbH
*
* originally based on code by:
* Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*
*
* the project's page is at http://www.linuxtv.org/dvb/
*/
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/byteorder/swabb.h>
#include <linux/smp_lock.h>
#include <linux/fs.h>
#define DEBUG_VARIABLE av7110_debug
extern int av7110_debug;
#include "av7110.h"
#include "av7110_hw.h"
#include "av7110_av.h"
#include "av7110_ipack.h"
#include "dvb_functions.h"
/* MPEG-2 (ISO 13818 / H.222.0) stream types */
#define PROG_STREAM_MAP 0xBC
#define PRIVATE_STREAM1 0xBD
#define PADDING_STREAM 0xBE
#define PRIVATE_STREAM2 0xBF
#define AUDIO_STREAM_S 0xC0
#define AUDIO_STREAM_E 0xDF
#define VIDEO_STREAM_S 0xE0
#define VIDEO_STREAM_E 0xEF
#define ECM_STREAM 0xF0
#define EMM_STREAM 0xF1
#define DSM_CC_STREAM 0xF2
#define ISO13522_STREAM 0xF3
#define PROG_STREAM_DIR 0xFF
#define PTS_DTS_FLAGS 0xC0
//pts_dts flags
#define PTS_ONLY 0x80
#define PTS_DTS 0xC0
#define TS_SIZE 188
#define TRANS_ERROR 0x80
#define PAY_START 0x40
#define TRANS_PRIO 0x20
#define PID_MASK_HI 0x1F
//flags
#define TRANS_SCRMBL1 0x80
#define TRANS_SCRMBL2 0x40
#define ADAPT_FIELD 0x20
#define PAYLOAD 0x10
#define COUNT_MASK 0x0F
// adaptation flags
#define DISCON_IND 0x80
#define RAND_ACC_IND 0x40
#define ES_PRI_IND 0x20
#define PCR_FLAG 0x10
#define OPCR_FLAG 0x08
#define SPLICE_FLAG 0x04
#define TRANS_PRIV 0x02
#define ADAP_EXT_FLAG 0x01
// adaptation extension flags
#define LTW_FLAG 0x80
#define PIECE_RATE 0x40
#define SEAM_SPLICE 0x20
static void p_to_t(u8 const *buf, long int length, u16 pid,
u8 *counter, struct dvb_demux_feed *feed);
int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len)
{
struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) p2t->priv;
// DEB_EE(("struct dvb_filter_pes2ts:%p\n", p2t));
if (!(dvbdmxfeed->ts_type & TS_PACKET))
return 0;
if (buf[3] == 0xe0) // video PES do not have a length in TS
buf[4] = buf[5] = 0;
if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
return dvbdmxfeed->cb.ts(buf, len, 0, 0,
&dvbdmxfeed->feed.ts, DMX_OK);
else
return dvb_filter_pes2ts(p2t, buf, len, 1);
}
static int dvb_filter_pes2ts_cb(void *priv, unsigned char *data)
{
struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) priv;
// DEB_EE(("dvb_demux_feed:%p\n", dvbdmxfeed));
dvbdmxfeed->cb.ts(data, 188, 0, 0,
&dvbdmxfeed->feed.ts, DMX_OK);
return 0;
}
int av7110_av_start_record(struct av7110 *av7110, int av,
struct dvb_demux_feed *dvbdmxfeed)
{
struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
DEB_EE(("av7110: %p, dvb_demux_feed:%p\n", av7110, dvbdmxfeed));
if (av7110->playing || (av7110->rec_mode & av))
return -EBUSY;
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
dvbdmx->recording = 1;
av7110->rec_mode |= av;
switch (av7110->rec_mode) {
case RP_AUDIO:
dvb_filter_pes2ts_init(&av7110->p2t[0],
dvbdmx->pesfilter[0]->pid,
dvb_filter_pes2ts_cb,
(void *) dvbdmx->pesfilter[0]);
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0);
break;
case RP_VIDEO:
dvb_filter_pes2ts_init(&av7110->p2t[1],
dvbdmx->pesfilter[1]->pid,
dvb_filter_pes2ts_cb,
(void *) dvbdmx->pesfilter[1]);
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0);
break;
case RP_AV:
dvb_filter_pes2ts_init(&av7110->p2t[0],
dvbdmx->pesfilter[0]->pid,
dvb_filter_pes2ts_cb,
(void *) dvbdmx->pesfilter[0]);
dvb_filter_pes2ts_init(&av7110->p2t[1],
dvbdmx->pesfilter[1]->pid,
dvb_filter_pes2ts_cb,
(void *) dvbdmx->pesfilter[1]);
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AV_PES, 0);
break;
}
return 0;
}
int av7110_av_start_play(struct av7110 *av7110, int av)
{
DEB_EE(("av7110: %p\n", av7110));
if (av7110->rec_mode)
return -EBUSY;
if (av7110->playing & av)
return -EBUSY;
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
if (av7110->playing == RP_NONE) {
av7110_ipack_reset(&av7110->ipack[0]);
av7110_ipack_reset(&av7110->ipack[1]);
}
av7110->playing |= av;
switch (av7110->playing) {
case RP_AUDIO:
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0);
break;
case RP_VIDEO:
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0);
av7110->sinfo = 0;
break;
case RP_AV:
av7110->sinfo = 0;
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AV_PES, 0);
break;
}
return av7110->playing;
}
void av7110_av_stop(struct av7110 *av7110, int av)
{
DEB_EE(("av7110: %p\n", av7110));
if (!(av7110->playing & av) && !(av7110->rec_mode & av))
return;
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
if (av7110->playing) {
av7110->playing &= ~av;
switch (av7110->playing) {
case RP_AUDIO:
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, AudioPES, 0);
break;
case RP_VIDEO:
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Play, 2, VideoPES, 0);
break;
case RP_NONE:
av7110_set_vidmode(av7110, av7110->vidmode);
break;
}
} else {
av7110->rec_mode &= ~av;
switch (av7110->rec_mode) {
case RP_AUDIO:
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, AudioPES, 0);
break;
case RP_VIDEO:
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Record, 2, VideoPES, 0);
break;
case RP_NONE:
break;
}
}
}
int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen)
{
int len;
u32 sync;
u16 blen;
DEB_EE(("dvb_ring_buffer_t: %p\n", buf));
if (!dlen) {
wake_up(&buf->queue);
return -1;
}
while (1) {
if ((len = dvb_ringbuffer_avail(buf)) < 6)
return -1;
sync = DVB_RINGBUFFER_PEEK(buf, 0) << 24;
sync |= DVB_RINGBUFFER_PEEK(buf, 1) << 16;
sync |= DVB_RINGBUFFER_PEEK(buf, 2) << 8;
sync |= DVB_RINGBUFFER_PEEK(buf, 3);
if (((sync &~ 0x0f) == 0x000001e0) ||
((sync &~ 0x1f) == 0x000001c0) ||
(sync == 0x000001bd))
break;
printk("resync\n");
DVB_RINGBUFFER_SKIP(buf, 1);
}
blen = DVB_RINGBUFFER_PEEK(buf, 4) << 8;
blen |= DVB_RINGBUFFER_PEEK(buf, 5);
blen += 6;
if (len < blen || blen > dlen) {
//printk("buffer empty - avail %d blen %u dlen %d\n", len, blen, dlen);
wake_up(&buf->queue);
return -1;
}
dvb_ringbuffer_read(buf, dest, (size_t) blen, 0);
DEB_S(("pread=0x%08lx, pwrite=0x%08lx\n",
(unsigned long) buf->pread, (unsigned long) buf->pwrite));
wake_up(&buf->queue);
return blen;
}
int av7110_set_volume(struct av7110 *av7110, int volleft, int volright)
{
int err, vol, val, balance = 0;
DEB_EE(("av7110: %p\n", av7110));
switch (av7110->adac_type) {
case DVB_ADAC_TI:
volleft = (volleft * 256) / 1036;
volright = (volright * 256) / 1036;
if (volleft > 0x3f)
volleft = 0x3f;
if (volright > 0x3f)
volright = 0x3f;
if ((err = SendDAC(av7110, 3, 0x80 + volleft)))
return err;
return SendDAC(av7110, 4, volright);
case DVB_ADAC_CRYSTAL:
volleft = 127 - volleft / 2;
volright = 127 - volright / 2;
i2c_writereg(av7110, 0x20, 0x03, volleft);
i2c_writereg(av7110, 0x20, 0x04, volright);
return 0;
case DVB_ADAC_MSP:
vol = (volleft > volright) ? volleft : volright;
val = (vol * 0x73 / 255) << 8;
if (vol > 0)
balance = ((volright - volleft) * 127) / vol;
msp_writereg(av7110, MSP_WR_DSP, 0x0001, balance << 8);
msp_writereg(av7110, MSP_WR_DSP, 0x0000, val); /* loudspeaker */
msp_writereg(av7110, MSP_WR_DSP, 0x0006, val); /* headphonesr */
return 0;
}
return 0;
}
void av7110_set_vidmode(struct av7110 *av7110, int mode)
{
DEB_EE(("av7110: %p\n", av7110));
av7110_fw_cmd(av7110, COMTYPE_ENCODER, LoadVidCode, 1, mode);
if (!av7110->playing) {
ChangePIDs(av7110, av7110->pids[DMX_PES_VIDEO],
av7110->pids[DMX_PES_AUDIO],
av7110->pids[DMX_PES_TELETEXT],
0, av7110->pids[DMX_PES_PCR]);
av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, Scan, 0);
}
}
static int sw2mode[16] = {
VIDEO_MODE_PAL, VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, VIDEO_MODE_PAL,
VIDEO_MODE_NTSC, VIDEO_MODE_NTSC, VIDEO_MODE_PAL, VIDEO_MODE_NTSC,
VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL,
VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL, VIDEO_MODE_PAL,
};
static void get_video_format(struct av7110 *av7110, u8 *buf, int count)
{
int i;
int hsize, vsize;
int sw;
u8 *p;
DEB_EE(("av7110: %p\n", av7110));
if (av7110->sinfo)
return;
for (i = 7; i < count - 10; i++) {
p = buf + i;
if (p[0] || p[1] || p[2] != 0x01 || p[3] != 0xb3)
continue;
p += 4;
hsize = ((p[1] &0xF0) >> 4) | (p[0] << 4);
vsize = ((p[1] &0x0F) << 8) | (p[2]);
sw = (p[3] & 0x0F);
av7110_set_vidmode(av7110, sw2mode[sw]);
DEB_S(("dvb: playback %dx%d fr=%d\n", hsize, vsize, sw));
av7110->sinfo = 1;
break;
}
}
/****************************************************************************
* I/O buffer management and control
****************************************************************************/
static inline long aux_ring_buffer_write(struct dvb_ringbuffer *rbuf,
const char *buf, unsigned long count)
{
unsigned long todo = count;
int free;
while (todo > 0) {
if (dvb_ringbuffer_free(rbuf) < 2048) {
if (wait_event_interruptible(rbuf->queue,
(dvb_ringbuffer_free(rbuf) >= 2048)))
return count - todo;
}
free = dvb_ringbuffer_free(rbuf);
if (free > todo)
free = todo;
dvb_ringbuffer_write(rbuf, buf, free, 0);
todo -= free;
buf += free;
}
return count - todo;
}
static void play_video_cb(u8 *buf, int count, void *priv)
{
struct av7110 *av7110 = (struct av7110 *) priv;
DEB_EE(("av7110: %p\n", av7110));
if ((buf[3] & 0xe0) == 0xe0) {
get_video_format(av7110, buf, count);
aux_ring_buffer_write(&av7110->avout, buf, count);
} else
aux_ring_buffer_write(&av7110->aout, buf, count);
}
static void play_audio_cb(u8 *buf, int count, void *priv)
{
struct av7110 *av7110 = (struct av7110 *) priv;
DEB_EE(("av7110: %p\n", av7110));
aux_ring_buffer_write(&av7110->aout, buf, count);
}
#define FREE_COND (dvb_ringbuffer_free(&av7110->avout) >= 20 * 1024 && \
dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
static ssize_t dvb_play(struct av7110 *av7110, const u8 *buf,
unsigned long count, int nonblock, int type, int umem)
{
unsigned long todo = count, n;
DEB_EE(("av7110: %p\n", av7110));
if (!av7110->kbuf[type])
return -ENOBUFS;
if (nonblock && !FREE_COND)
return -EWOULDBLOCK;
while (todo > 0) {
if (!FREE_COND) {
if (nonblock)
return count - todo;
if (wait_event_interruptible(av7110->avout.queue,
FREE_COND))
return count - todo;
}
n = todo;
if (n > IPACKS * 2)
n = IPACKS * 2;
if (umem) {
if (copy_from_user(av7110->kbuf[type], buf, n))
return -EFAULT;
av7110_ipack_instant_repack(av7110->kbuf[type], n,
&av7110->ipack[type]);
} else {
av7110_ipack_instant_repack(buf, n,
&av7110->ipack[type]);
}
todo -= n;
buf += n;
}
return count - todo;
}
static ssize_t dvb_aplay(struct av7110 *av7110, const u8 *buf,
unsigned long count, int nonblock, int type)
{
unsigned long todo = count, n;
DEB_EE(("av7110: %p\n", av7110));
if (!av7110->kbuf[type])
return -ENOBUFS;
if (nonblock && dvb_ringbuffer_free(&av7110->aout) < 20 * 1024)
return -EWOULDBLOCK;
while (todo > 0) {
if (dvb_ringbuffer_free(&av7110->aout) < 20 * 1024) {
if (nonblock)
return count - todo;
if (wait_event_interruptible(av7110->aout.queue,
(dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)))
return count-todo;
}
n = todo;
if (n > IPACKS * 2)
n = IPACKS * 2;
if (copy_from_user(av7110->kbuf[type], buf, n))
return -EFAULT;
av7110_ipack_instant_repack(av7110->kbuf[type], n,
&av7110->ipack[type]);
todo -= n;
buf += n;
}
return count - todo;
}
void av7110_p2t_init(struct av7110_p2t *p, struct dvb_demux_feed *feed)
{
memset(p->pes, 0, TS_SIZE);
p->counter = 0;
p->pos = 0;
p->frags = 0;
if (feed)
p->feed = feed;
}
static void clear_p2t(struct av7110_p2t *p)
{
memset(p->pes, 0, TS_SIZE);
// p->counter = 0;
p->pos = 0;
p->frags = 0;
}
static int find_pes_header(u8 const *buf, long int length, int *frags)
{
int c = 0;
int found = 0;
*frags = 0;
while (c < length - 3 && !found) {
if (buf[c] == 0x00 && buf[c + 1] == 0x00 &&
buf[c + 2] == 0x01) {
switch ( buf[c + 3] ) {
case PROG_STREAM_MAP:
case PRIVATE_STREAM2:
case PROG_STREAM_DIR:
case ECM_STREAM :
case EMM_STREAM :
case PADDING_STREAM :
case DSM_CC_STREAM :
case ISO13522_STREAM:
case PRIVATE_STREAM1:
case AUDIO_STREAM_S ... AUDIO_STREAM_E:
case VIDEO_STREAM_S ... VIDEO_STREAM_E:
found = 1;
break;
default:
c++;
break;
}
} else
c++;
}
if (c == length - 3 && !found) {
if (buf[length - 1] == 0x00)
*frags = 1;
if (buf[length - 2] == 0x00 &&
buf[length - 1] == 0x00)
*frags = 2;
if (buf[length - 3] == 0x00 &&
buf[length - 2] == 0x00 &&
buf[length - 1] == 0x01)
*frags = 3;
return -1;
}
return c;
}
void av7110_p2t_write(u8 const *buf, long int length, u16 pid, struct av7110_p2t *p)
{
int c, c2, l, add;
int check, rest;
c = 0;
c2 = 0;
if (p->frags){
check = 0;
switch(p->frags) {
case 1:
if (buf[c] == 0x00 && buf[c + 1] == 0x01) {
check = 1;
c += 2;
}
break;
case 2:
if (buf[c] == 0x01) {
check = 1;
c++;
}
break;
case 3:
check = 1;
}
if (check) {
switch (buf[c]) {
case PROG_STREAM_MAP:
case PRIVATE_STREAM2:
case PROG_STREAM_DIR:
case ECM_STREAM :
case EMM_STREAM :
case PADDING_STREAM :
case DSM_CC_STREAM :
case ISO13522_STREAM:
case PRIVATE_STREAM1:
case AUDIO_STREAM_S ... AUDIO_STREAM_E:
case VIDEO_STREAM_S ... VIDEO_STREAM_E:
p->pes[0] = 0x00;
p->pes[1] = 0x00;
p->pes[2] = 0x01;
p->pes[3] = buf[c];
p->pos = 4;
memcpy(p->pes + p->pos, buf + c, (TS_SIZE - 4) - p->pos);
c += (TS_SIZE - 4) - p->pos;
p_to_t(p->pes, (TS_SIZE - 4), pid, &p->counter, p->feed);
clear_p2t(p);
break;
default:
c = 0;
break;
}
}
p->frags = 0;
}
if (p->pos) {
c2 = find_pes_header(buf + c, length - c, &p->frags);
if (c2 >= 0 && c2 < (TS_SIZE - 4) - p->pos)
l = c2+c;
else
l = (TS_SIZE - 4) - p->pos;
memcpy(p->pes + p->pos, buf, l);
c += l;
p->pos += l;
p_to_t(p->pes, p->pos, pid, &p->counter, p->feed);
clear_p2t(p);
}
add = 0;
while (c < length) {
c2 = find_pes_header(buf + c + add, length - c - add, &p->frags);
if (c2 >= 0) {
c2 += c + add;
if (c2 > c){
p_to_t(buf + c, c2 - c, pid, &p->counter, p->feed);
c = c2;
clear_p2t(p);
add = 0;
} else
add = 1;
} else {
l = length - c;
rest = l % (TS_SIZE - 4);
l -= rest;
p_to_t(buf + c, l, pid, &p->counter, p->feed);
memcpy(p->pes, buf + c + l, rest);
p->pos = rest;
c = length;
}
}
}
int write_ts_header2(u16 pid, u8 *counter, int pes_start, u8 *buf, u8 length)
{
int i;
int c = 0;
int fill;
u8 tshead[4] = { 0x47, 0x00, 0x00, 0x10 };
fill = (TS_SIZE - 4) - length;
if (pes_start)
tshead[1] = 0x40;
if (fill)
tshead[3] = 0x30;
tshead[1] |= (u8)((pid & 0x1F00) >> 8);
tshead[2] |= (u8)(pid & 0x00FF);
tshead[3] |= ((*counter)++ & 0x0F);
memcpy(buf, tshead, 4);
c += 4;
if (fill) {
buf[4] = fill - 1;
c++;
if (fill > 1) {
buf[5] = 0x00;
c++;
}
for (i = 6; i < fill + 4; i++) {
buf[i] = 0xFF;
c++;
}
}
return c;
}
static void p_to_t(u8 const *buf, long int length, u16 pid, u8 *counter,
struct dvb_demux_feed *feed)
{
int l, pes_start;
u8 obuf[TS_SIZE];
long c = 0;
pes_start = 0;
if (length > 3 &&
buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x01)
switch (buf[3]) {
case PROG_STREAM_MAP:
case PRIVATE_STREAM2:
case PROG_STREAM_DIR:
case ECM_STREAM :
case EMM_STREAM :
case PADDING_STREAM :
case DSM_CC_STREAM :
case ISO13522_STREAM:
case PRIVATE_STREAM1:
case AUDIO_STREAM_S ... AUDIO_STREAM_E:
case VIDEO_STREAM_S ... VIDEO_STREAM_E:
pes_start = 1;
break;
default:
break;
}
while (c < length) {
memset(obuf, 0, TS_SIZE);
if (length - c >= (TS_SIZE - 4)){
l = write_ts_header2(pid, counter, pes_start,
obuf, (TS_SIZE - 4));
memcpy(obuf + l, buf + c, TS_SIZE - l);
c += TS_SIZE - l;
} else {
l = write_ts_header2(pid, counter, pes_start,
obuf, length - c);
memcpy(obuf + l, buf + c, TS_SIZE - l);
c = length;
}
feed->cb.ts(obuf, 188, 0, 0, &feed->feed.ts, DMX_OK);
pes_start = 0;
}
}
int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t len)
{
struct dvb_demux *demux = feed->demux;
struct av7110 *av7110 = (struct av7110 *) demux->priv;
struct ipack *ipack = &av7110->ipack[feed->pes_type];
DEB_EE(("av7110: %p\n", av7110));
switch (feed->pes_type) {
case 0:
if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
return -EINVAL;
break;
case 1:
if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY)
return -EINVAL;
break;
default:
return -1;
}
if (!(buf[3] & 0x10)) /* no payload? */
return -1;
if (buf[1] & 0x40)
av7110_ipack_flush(ipack);
if (buf[3] & 0x20) { /* adaptation field? */
len -= buf[4] + 1;
buf += buf[4] + 1;
if (!len)
return 0;
}
av7110_ipack_instant_repack(buf + 4, len - 4, &av7110->ipack[feed->pes_type]);
return 0;
}
/******************************************************************************
* Video MPEG decoder events
******************************************************************************/
void dvb_video_add_event(struct av7110 *av7110, struct video_event *event)
{
struct dvb_video_events *events = &av7110->video_events;
int wp;
DEB_D(("\n"));
spin_lock_bh(&events->lock);
wp = (events->eventw + 1) % MAX_VIDEO_EVENT;
if (wp == events->eventr) {
events->overflow = 1;
events->eventr = (events->eventr + 1) % MAX_VIDEO_EVENT;
}
//FIXME: timestamp?
memcpy(&events->events[events->eventw], event, sizeof(struct video_event));
events->eventw = wp;
spin_unlock_bh(&events->lock);
wake_up_interruptible(&events->wait_queue);
}
static int dvb_video_get_event (struct av7110 *av7110, struct video_event *event, int flags)
{
struct dvb_video_events *events = &av7110->video_events;
DEB_D(("\n"));
if (events->overflow) {
events->overflow = 0;
return -EOVERFLOW;
}
if (events->eventw == events->eventr) {
int ret;
if (flags & O_NONBLOCK)
return -EWOULDBLOCK;
ret = wait_event_interruptible(events->wait_queue,
events->eventw != events->eventr);
if (ret < 0)
return ret;
}
spin_lock_bh(&events->lock);
memcpy(event, &events->events[events->eventr],
sizeof(struct video_event));
events->eventr = (events->eventr + 1) % MAX_VIDEO_EVENT;
spin_unlock_bh(&events->lock);
return 0;
}
/******************************************************************************
* DVB device file operations
******************************************************************************/
static unsigned int dvb_video_poll(struct file *file, poll_table *wait)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
unsigned int mask = 0;
DEB_EE(("av7110: %p\n", av7110));
if ((file->f_flags & O_ACCMODE) != O_RDONLY)
poll_wait(file, &av7110->avout.queue, wait);
poll_wait(file, &av7110->video_events.wait_queue, wait);
if (av7110->video_events.eventw != av7110->video_events.eventr)
mask = POLLPRI;
if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
if (av7110->playing) {
if (FREE_COND)
mask |= (POLLOUT | POLLWRNORM);
} else /* if not playing: may play if asked for */
mask |= (POLLOUT | POLLWRNORM);
}
return mask;
}
static ssize_t dvb_video_write(struct file *file, const char *buf,
size_t count, loff_t *ppos)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
DEB_EE(("av7110: %p\n", av7110));
if ((file->f_flags & O_ACCMODE) == O_RDONLY)
return -EPERM;
if (av7110->videostate.stream_source != VIDEO_SOURCE_MEMORY)
return -EPERM;
return dvb_play(av7110, buf, count, file->f_flags & O_NONBLOCK, 1, 1);
}
static unsigned int dvb_audio_poll(struct file *file, poll_table *wait)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
unsigned int mask = 0;
DEB_EE(("av7110: %p\n", av7110));
poll_wait(file, &av7110->aout.queue, wait);
if (av7110->playing) {
if (dvb_ringbuffer_free(&av7110->aout) >= 20 * 1024)
mask |= (POLLOUT | POLLWRNORM);
} else /* if not playing: may play if asked for */
mask = (POLLOUT | POLLWRNORM);
return mask;
}
static ssize_t dvb_audio_write(struct file *file, const char *buf,
size_t count, loff_t *ppos)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
DEB_EE(("av7110: %p\n", av7110));
if (av7110->audiostate.stream_source != AUDIO_SOURCE_MEMORY) {
printk(KERN_ERR "not audio source memory\n");
return -EPERM;
}
return dvb_aplay(av7110, buf, count, file->f_flags & O_NONBLOCK, 0);
}
u8 iframe_header[] = { 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x80, 0x00, 0x00 };
#define MIN_IFRAME 400000
static int play_iframe(struct av7110 *av7110, u8 *buf, unsigned int len, int nonblock)
{
int i, n;
DEB_EE(("av7110: %p\n", av7110));
if (!(av7110->playing & RP_VIDEO)) {
if (av7110_av_start_play(av7110, RP_VIDEO) < 0)
return -EBUSY;
}
/* setting n always > 1, fixes problems when playing stillframes
consisting of I- and P-Frames */
n = MIN_IFRAME / len + 1;
/* FIXME: nonblock? */
dvb_play(av7110, iframe_header, sizeof(iframe_header), 0, 1, 0);
for (i = 0; i < n; i++)
dvb_play(av7110, buf, len, 0, 1, 1);
av7110_ipack_flush(&av7110->ipack[1]);
return 0;
}
static int dvb_video_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
unsigned long arg = (unsigned long) parg;
int ret = 0;
DEB_EE(("av7110: %p\n", av7110));
if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
if ( cmd != VIDEO_GET_STATUS && cmd != VIDEO_GET_EVENT &&
cmd != VIDEO_GET_SIZE ) {
return -EPERM;
}
}
switch (cmd) {
case VIDEO_STOP:
av7110->videostate.play_state = VIDEO_STOPPED;
if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY)
av7110_av_stop(av7110, RP_VIDEO);
else
vidcom(av7110, 0x000e,
av7110->videostate.video_blank ? 0 : 1);
av7110->trickmode = TRICK_NONE;
break;
case VIDEO_PLAY:
av7110->trickmode = TRICK_NONE;
if (av7110->videostate.play_state == VIDEO_FREEZED) {
av7110->videostate.play_state = VIDEO_PLAYING;
vidcom(av7110, 0x000d, 0);
}
if (av7110->videostate.stream_source == VIDEO_SOURCE_MEMORY) {
if (av7110->playing == RP_AV) {
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Stop, 0);
av7110->playing &= ~RP_VIDEO;
}
av7110_av_start_play(av7110, RP_VIDEO);
vidcom(av7110, 0x000d, 0);
} else {
//av7110_av_stop(av7110, RP_VIDEO);
vidcom(av7110, 0x000d, 0);
}
av7110->videostate.play_state = VIDEO_PLAYING;
break;
case VIDEO_FREEZE:
av7110->videostate.play_state = VIDEO_FREEZED;
if (av7110->playing & RP_VIDEO)
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Pause, 0);
else
vidcom(av7110, 0x0102, 1);
av7110->trickmode = TRICK_FREEZE;
break;
case VIDEO_CONTINUE:
if (av7110->playing & RP_VIDEO)
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Continue, 0);
vidcom(av7110, 0x000d, 0);
av7110->videostate.play_state = VIDEO_PLAYING;
av7110->trickmode = TRICK_NONE;
break;
case VIDEO_SELECT_SOURCE:
av7110->videostate.stream_source = (video_stream_source_t) arg;
break;
case VIDEO_SET_BLANK:
av7110->videostate.video_blank = (int) arg;
break;
case VIDEO_GET_STATUS:
memcpy(parg, &av7110->videostate, sizeof(struct video_status));
break;
case VIDEO_GET_EVENT:
ret=dvb_video_get_event(av7110, parg, file->f_flags);
break;
case VIDEO_GET_SIZE:
memcpy(parg, &av7110->video_size, sizeof(video_size_t));
break;
case VIDEO_SET_DISPLAY_FORMAT:
{
video_displayformat_t format = (video_displayformat_t) arg;
u16 val = 0;
switch (format) {
case VIDEO_PAN_SCAN:
val = VID_PAN_SCAN_PREF;
break;
case VIDEO_LETTER_BOX:
val = VID_VC_AND_PS_PREF;
break;
case VIDEO_CENTER_CUT_OUT:
val = VID_CENTRE_CUT_PREF;
break;
default:
ret = -EINVAL;
}
if (ret < 0)
break;
av7110->videostate.video_format = format;
ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetPanScanType,
1, (u16) val);
break;
}
case VIDEO_SET_FORMAT:
if (arg > 1) {
ret = -EINVAL;
break;
}
av7110->display_ar = arg;
ret = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetMonitorType,
1, (u16) arg);
break;
case VIDEO_STILLPICTURE:
{
struct video_still_picture *pic =
(struct video_still_picture *) parg;
av7110->videostate.stream_source = VIDEO_SOURCE_MEMORY;
dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
ret = play_iframe(av7110, pic->iFrame, pic->size,
file->f_flags & O_NONBLOCK);
break;
}
case VIDEO_FAST_FORWARD:
//note: arg is ignored by firmware
if (av7110->playing & RP_VIDEO)
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
__Scan_I, 2, AV_PES, 0);
else
vidcom(av7110, 0x16, arg);
av7110->trickmode = TRICK_FAST;
av7110->videostate.play_state = VIDEO_PLAYING;
break;
case VIDEO_SLOWMOTION:
if (av7110->playing&RP_VIDEO) {
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY, __Slow, 2, 0, 0);
vidcom(av7110, 0x22, arg);
} else {
vidcom(av7110, 0x0d, 0);
vidcom(av7110, 0x0e, 0);
vidcom(av7110, 0x22, arg);
}
av7110->trickmode = TRICK_SLOW;
av7110->videostate.play_state = VIDEO_PLAYING;
break;
case VIDEO_GET_CAPABILITIES:
*(int *)parg = VIDEO_CAP_MPEG1 | VIDEO_CAP_MPEG2 |
VIDEO_CAP_SYS | VIDEO_CAP_PROG;
break;
case VIDEO_CLEAR_BUFFER:
dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
av7110_ipack_reset(&av7110->ipack[1]);
if (av7110->playing == RP_AV) {
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
__Play, 2, AV_PES, 0);
if (av7110->trickmode == TRICK_FAST)
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
__Scan_I, 2, AV_PES, 0);
if (av7110->trickmode == TRICK_SLOW) {
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
__Slow, 2, 0, 0);
vidcom(av7110, 0x22, arg);
}
if (av7110->trickmode == TRICK_FREEZE)
vidcom(av7110, 0x000e, 1);
}
break;
case VIDEO_SET_STREAMTYPE:
break;
default:
ret = -ENOIOCTLCMD;
break;
}
return ret;
}
static int dvb_audio_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
unsigned long arg = (unsigned long) parg;
int ret = 0;
DEB_EE(("av7110: %p\n", av7110));
if (((file->f_flags & O_ACCMODE) == O_RDONLY) &&
(cmd != AUDIO_GET_STATUS))
return -EPERM;
switch (cmd) {
case AUDIO_STOP:
if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
av7110_av_stop(av7110, RP_AUDIO);
else
audcom(av7110, 1);
av7110->audiostate.play_state = AUDIO_STOPPED;
break;
case AUDIO_PLAY:
if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
av7110_av_start_play(av7110, RP_AUDIO);
audcom(av7110, 2);
av7110->audiostate.play_state = AUDIO_PLAYING;
break;
case AUDIO_PAUSE:
audcom(av7110, 1);
av7110->audiostate.play_state = AUDIO_PAUSED;
break;
case AUDIO_CONTINUE:
if (av7110->audiostate.play_state == AUDIO_PAUSED) {
av7110->audiostate.play_state = AUDIO_PLAYING;
audcom(av7110, 0x12);
}
break;
case AUDIO_SELECT_SOURCE:
av7110->audiostate.stream_source = (audio_stream_source_t) arg;
break;
case AUDIO_SET_MUTE:
{
audcom(av7110, arg ? 1 : 2);
av7110->audiostate.mute_state = (int) arg;
break;
}
case AUDIO_SET_AV_SYNC:
av7110->audiostate.AV_sync_state = (int) arg;
audcom(av7110, arg ? 0x0f : 0x0e);
break;
case AUDIO_SET_BYPASS_MODE:
ret = -EINVAL;
break;
case AUDIO_CHANNEL_SELECT:
av7110->audiostate.channel_select = (audio_channel_select_t) arg;
switch(av7110->audiostate.channel_select) {
case AUDIO_STEREO:
audcom(av7110, 0x80);
break;
case AUDIO_MONO_LEFT:
audcom(av7110, 0x100);
break;
case AUDIO_MONO_RIGHT:
audcom(av7110, 0x200);
break;
default:
ret = -EINVAL;
break;
}
break;
case AUDIO_GET_STATUS:
memcpy(parg, &av7110->audiostate, sizeof(struct audio_status));
break;
case AUDIO_GET_CAPABILITIES:
*(int *)parg = AUDIO_CAP_LPCM | AUDIO_CAP_MP1 | AUDIO_CAP_MP2;
break;
case AUDIO_CLEAR_BUFFER:
dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
av7110_ipack_reset(&av7110->ipack[0]);
if (av7110->playing == RP_AV)
av7110_fw_cmd(av7110, COMTYPE_REC_PLAY,
__Play, 2, AV_PES, 0);
break;
case AUDIO_SET_ID:
break;
case AUDIO_SET_MIXER:
{
struct audio_mixer *amix = (struct audio_mixer *)parg;
av7110_set_volume(av7110, amix->volume_left, amix->volume_right);
break;
}
case AUDIO_SET_STREAMTYPE:
break;
default:
ret = -ENOIOCTLCMD;
}
return ret;
}
static int dvb_video_open(struct inode *inode, struct file *file)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
int err;
DEB_EE(("av7110: %p\n", av7110));
if ((err = dvb_generic_open(inode, file)) < 0)
return err;
if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
dvb_ringbuffer_flush_spinlock_wakeup(&av7110->avout);
av7110->video_blank = 1;
av7110->audiostate.AV_sync_state = 1;
av7110->videostate.stream_source = VIDEO_SOURCE_DEMUX;
/* empty event queue */
av7110->video_events.eventr = av7110->video_events.eventw = 0;
}
return 0;
}
static int dvb_video_release(struct inode *inode, struct file *file)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
DEB_EE(("av7110: %p\n", av7110));
if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
av7110_av_stop(av7110, RP_VIDEO);
}
return dvb_generic_release(inode, file);
}
static int dvb_audio_open(struct inode *inode, struct file *file)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
int err=dvb_generic_open(inode, file);
DEB_EE(("av7110: %p\n", av7110));
if (err < 0)
return err;
dvb_ringbuffer_flush_spinlock_wakeup(&av7110->aout);
av7110->audiostate.stream_source = AUDIO_SOURCE_DEMUX;
return 0;
}
static int dvb_audio_release(struct inode *inode, struct file *file)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
DEB_EE(("av7110: %p\n", av7110));
av7110_av_stop(av7110, RP_AUDIO);
return dvb_generic_release(inode, file);
}
/******************************************************************************
* driver registration
******************************************************************************/
static struct file_operations dvb_video_fops = {
.owner = THIS_MODULE,
.write = dvb_video_write,
.ioctl = dvb_generic_ioctl,
.open = dvb_video_open,
.release = dvb_video_release,
.poll = dvb_video_poll,
};
static struct dvb_device dvbdev_video = {
.priv = 0,
.users = 6,
.readers = 5, /* arbitrary */
.writers = 1,
.fops = &dvb_video_fops,
.kernel_ioctl = dvb_video_ioctl,
};
static struct file_operations dvb_audio_fops = {
.owner = THIS_MODULE,
.write = dvb_audio_write,
.ioctl = dvb_generic_ioctl,
.open = dvb_audio_open,
.release = dvb_audio_release,
.poll = dvb_audio_poll,
};
static struct dvb_device dvbdev_audio = {
.priv = 0,
.users = 1,
.writers = 1,
.fops = &dvb_audio_fops,
.kernel_ioctl = dvb_audio_ioctl,
};
int av7110_av_register(struct av7110 *av7110)
{
av7110->audiostate.AV_sync_state = 0;
av7110->audiostate.mute_state = 0;
av7110->audiostate.play_state = AUDIO_STOPPED;
av7110->audiostate.stream_source = AUDIO_SOURCE_DEMUX;
av7110->audiostate.channel_select = AUDIO_STEREO;
av7110->audiostate.bypass_mode = 0;
av7110->videostate.video_blank = 0;
av7110->videostate.play_state = VIDEO_STOPPED;
av7110->videostate.stream_source = VIDEO_SOURCE_DEMUX;
av7110->videostate.video_format = VIDEO_FORMAT_4_3;
av7110->videostate.display_format = VIDEO_CENTER_CUT_OUT;
av7110->display_ar = VIDEO_FORMAT_4_3;
init_waitqueue_head(&av7110->video_events.wait_queue);
spin_lock_init(&av7110->video_events.lock);
av7110->video_events.eventw = av7110->video_events.eventr = 0;
av7110->video_events.overflow = 0;
memset(&av7110->video_size, 0, sizeof (video_size_t));
dvb_register_device(av7110->dvb_adapter, &av7110->video_dev,
&dvbdev_video, av7110, DVB_DEVICE_VIDEO);
dvb_register_device(av7110->dvb_adapter, &av7110->audio_dev,
&dvbdev_audio, av7110, DVB_DEVICE_AUDIO);
return 0;
}
void av7110_av_unregister(struct av7110 *av7110)
{
dvb_unregister_device(av7110->audio_dev);
dvb_unregister_device(av7110->video_dev);
}
int av7110_av_init(struct av7110 *av7110)
{
av7110->vidmode = VIDEO_MODE_PAL;
av7110_ipack_init(&av7110->ipack[0], IPACKS, play_audio_cb);
av7110->ipack[0].data = (void *) av7110;
av7110_ipack_init(&av7110->ipack[1], IPACKS, play_video_cb);
av7110->ipack[1].data = (void *) av7110;
dvb_ringbuffer_init(&av7110->avout, av7110->iobuf, AVOUTLEN);
dvb_ringbuffer_init(&av7110->aout, av7110->iobuf + AVOUTLEN, AOUTLEN);
av7110->kbuf[0] = (u8 *)(av7110->iobuf + AVOUTLEN + AOUTLEN + BMPLEN);
av7110->kbuf[1] = av7110->kbuf[0] + 2 * IPACKS;
return 0;
}
int av7110_av_exit(struct av7110 *av7110)
{
av7110_ipack_free(&av7110->ipack[0]);
av7110_ipack_free(&av7110->ipack[1]);
return 0;
}
#ifndef _AV7110_AV_H_
#define _AV7110_AV_H_
struct av7110;
extern void av7110_set_vidmode(struct av7110 *av7110, int mode);
extern int av7110_record_cb(struct dvb_filter_pes2ts *p2t, u8 *buf, size_t len);
extern int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen);
extern int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t len);
extern int av7110_set_volume(struct av7110 *av7110, int volleft, int volright);
extern void av7110_av_stop(struct av7110 *av7110, int av);
extern int av7110_av_start_record(struct av7110 *av7110, int av,
struct dvb_demux_feed *dvbdmxfeed);
extern int av7110_av_start_play(struct av7110 *av7110, int av);
extern void dvb_video_add_event(struct av7110 *av7110, struct video_event *event);
extern void av7110_p2t_init(struct av7110_p2t *p, struct dvb_demux_feed *feed);
extern void av7110_p2t_write(u8 const *buf, long int length, u16 pid, struct av7110_p2t *p);
extern int av7110_av_register(struct av7110 *av7110);
extern void av7110_av_unregister(struct av7110 *av7110);
extern int av7110_av_init(struct av7110 *av7110);
extern int av7110_av_exit(struct av7110 *av7110);
#endif /* _AV7110_AV_H_ */
/*
* av7110_ca.c: CA and CI stuff
*
* Copyright (C) 1999-2002 Ralph Metzler
* & Marcus Metzler for convergence integrated media GmbH
*
* originally based on code by:
* Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*
*
* the project's page is at http://www.linuxtv.org/dvb/
*/
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/timer.h>
#include <linux/poll.h>
#include <linux/byteorder/swabb.h>
#include <linux/smp_lock.h>
#define DEBUG_VARIABLE av7110_debug
extern int av7110_debug;
#include "dvb_i2c.h"
#include "av7110.h"
#include "av7110_hw.h"
#include "dvb_functions.h"
void CI_handle(struct av7110 *av7110, u8 *data, u16 len)
{
DEB_EE(("av7110: %p\n", av7110));
if (len < 3)
return;
switch (data[0]) {
case CI_MSG_CI_INFO:
if (data[2] != 1 && data[2] != 2)
break;
switch (data[1]) {
case 0:
av7110->ci_slot[data[2] - 1].flags = 0;
break;
case 1:
av7110->ci_slot[data[2] - 1].flags |= CA_CI_MODULE_PRESENT;
break;
case 2:
av7110->ci_slot[data[2] - 1].flags |= CA_CI_MODULE_READY;
break;
}
break;
case CI_SWITCH_PRG_REPLY:
//av7110->ci_stat=data[1];
break;
default:
break;
}
}
void ci_get_data(struct dvb_ringbuffer *cibuf, u8 *data, int len)
{
if (dvb_ringbuffer_free(cibuf) < len + 2)
return;
DVB_RINGBUFFER_WRITE_BYTE(cibuf, len >> 8);
DVB_RINGBUFFER_WRITE_BYTE(cibuf, len & 0xff);
dvb_ringbuffer_write(cibuf, data, len, 0);
wake_up_interruptible(&cibuf->queue);
}
/******************************************************************************
* CI link layer file ops
******************************************************************************/
int ci_ll_init(struct dvb_ringbuffer *cirbuf, struct dvb_ringbuffer *ciwbuf, int size)
{
dvb_ringbuffer_init(cirbuf, vmalloc(size), size);
dvb_ringbuffer_init(ciwbuf, vmalloc(size), size);
return 0;
}
void ci_ll_flush(struct dvb_ringbuffer *cirbuf, struct dvb_ringbuffer *ciwbuf)
{
dvb_ringbuffer_flush_spinlock_wakeup(cirbuf);
dvb_ringbuffer_flush_spinlock_wakeup(ciwbuf);
}
void ci_ll_release(struct dvb_ringbuffer *cirbuf, struct dvb_ringbuffer *ciwbuf)
{
vfree(cirbuf->data);
cirbuf->data = 0;
vfree(ciwbuf->data);
ciwbuf->data = 0;
}
int ci_ll_reset(struct dvb_ringbuffer *cibuf, struct file *file,
int slots, ca_slot_info_t *slot)
{
int i;
int len = 0;
u8 msg[8] = { 0x00, 0x06, 0x00, 0x00, 0xff, 0x02, 0x00, 0x00 };
for (i = 0; i < 2; i++) {
if (slots & (1 << i))
len += 8;
}
if (dvb_ringbuffer_free(cibuf) < len)
return -EBUSY;
for (i = 0; i < 2; i++) {
if (slots & (1 << i)) {
msg[2] = i;
dvb_ringbuffer_write(cibuf, msg, 8, 0);
slot[i].flags = 0;
}
}
return 0;
}
static ssize_t ci_ll_write(struct dvb_ringbuffer *cibuf, struct file *file,
const char *buf, size_t count, loff_t *ppos)
{
int free;
int non_blocking = file->f_flags & O_NONBLOCK;
if (count > 2048)
return -EINVAL;
free = dvb_ringbuffer_free(cibuf);
if (count + 2 > free) {
if (non_blocking)
return -EWOULDBLOCK;
if (wait_event_interruptible(cibuf->queue,
(dvb_ringbuffer_free(cibuf) >= count + 2)))
return -ERESTARTSYS;
}
DVB_RINGBUFFER_WRITE_BYTE(cibuf, count >> 8);
DVB_RINGBUFFER_WRITE_BYTE(cibuf, count & 0xff);
return dvb_ringbuffer_write(cibuf, buf, count, 1);
}
static ssize_t ci_ll_read(struct dvb_ringbuffer *cibuf, struct file *file,
char *buf, size_t count, loff_t *ppos)
{
int avail;
int non_blocking = file->f_flags & O_NONBLOCK;
ssize_t len;
if (!cibuf->data || !count)
return 0;
if (non_blocking && (dvb_ringbuffer_empty(cibuf)))
return -EWOULDBLOCK;
if (wait_event_interruptible(cibuf->queue,
!dvb_ringbuffer_empty(cibuf)))
return -ERESTARTSYS;
avail = dvb_ringbuffer_avail(cibuf);
if (avail < 4)
return 0;
len = DVB_RINGBUFFER_PEEK(cibuf, 0) << 8;
len |= DVB_RINGBUFFER_PEEK(cibuf, 1);
if (avail < len + 2 || count < len)
return -EINVAL;
DVB_RINGBUFFER_SKIP(cibuf, 2);
return dvb_ringbuffer_read(cibuf, buf, len, 1);
}
static int dvb_ca_open(struct inode *inode, struct file *file)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
int err = dvb_generic_open(inode, file);
DEB_EE(("av7110: %p\n", av7110));
if (err < 0)
return err;
ci_ll_flush(&av7110->ci_rbuffer, &av7110->ci_wbuffer);
return 0;
}
static unsigned int dvb_ca_poll (struct file *file, poll_table *wait)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
struct dvb_ringbuffer *rbuf = &av7110->ci_rbuffer;
struct dvb_ringbuffer *wbuf = &av7110->ci_wbuffer;
unsigned int mask = 0;
DEB_EE(("av7110: %p\n", av7110));
poll_wait(file, &rbuf->queue, wait);
if (!dvb_ringbuffer_empty(rbuf))
mask |= POLLIN;
if (dvb_ringbuffer_avail(wbuf) > 1024)
mask |= POLLOUT;
return mask;
}
static int dvb_ca_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *parg)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
unsigned long arg = (unsigned long) parg;
DEB_EE(("av7110: %p\n", av7110));
switch (cmd) {
case CA_RESET:
return ci_ll_reset(&av7110->ci_wbuffer, file, arg, &av7110->ci_slot[0]);
break;
case CA_GET_CAP:
{
ca_caps_t cap;
cap.slot_num = 2;
cap.slot_type = (FW_CI_LL_SUPPORT(av7110->arm_app) ?
CA_CI_LINK : CA_CI) | CA_DESCR;
cap.descr_num = 16;
cap.descr_type = CA_ECD;
memcpy(parg, &cap, sizeof(cap));
break;
}
case CA_GET_SLOT_INFO:
{
ca_slot_info_t *info=(ca_slot_info_t *)parg;
if (info->num > 1)
return -EINVAL;
av7110->ci_slot[info->num].num = info->num;
av7110->ci_slot[info->num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ?
CA_CI_LINK : CA_CI;
memcpy(info, &av7110->ci_slot[info->num], sizeof(ca_slot_info_t));
break;
}
case CA_GET_MSG:
break;
case CA_SEND_MSG:
break;
case CA_GET_DESCR_INFO:
{
ca_descr_info_t info;
info.num = 16;
info.type = CA_ECD;
memcpy(parg, &info, sizeof (info));
break;
}
case CA_SET_DESCR:
{
ca_descr_t *descr = (ca_descr_t*) parg;
if (descr->index >= 16)
return -EINVAL;
if (descr->parity > 1)
return -EINVAL;
av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetDescr, 5,
(descr->index<<8)|descr->parity,
(descr->cw[0]<<8)|descr->cw[1],
(descr->cw[2]<<8)|descr->cw[3],
(descr->cw[4]<<8)|descr->cw[5],
(descr->cw[6]<<8)|descr->cw[7]);
break;
}
default:
return -EINVAL;
}
return 0;
}
static ssize_t dvb_ca_write(struct file *file, const char *buf,
size_t count, loff_t *ppos)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
DEB_EE(("av7110: %p\n", av7110));
return ci_ll_write(&av7110->ci_wbuffer, file, buf, count, ppos);
}
static ssize_t dvb_ca_read(struct file *file, char *buf,
size_t count, loff_t *ppos)
{
struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
struct av7110 *av7110 = (struct av7110 *) dvbdev->priv;
DEB_EE(("av7110: %p\n", av7110));
return ci_ll_read(&av7110->ci_rbuffer, file, buf, count, ppos);
}
static struct file_operations dvb_ca_fops = {
.owner = THIS_MODULE,
.read = dvb_ca_read,
.write = dvb_ca_write,
.ioctl = dvb_generic_ioctl,
.open = dvb_ca_open,
.release = dvb_generic_release,
.poll = dvb_ca_poll,
};
static struct dvb_device dvbdev_ca = {
.priv = 0,
.users = 1,
.writers = 1,
.fops = &dvb_ca_fops,
.kernel_ioctl = dvb_ca_ioctl,
};
int av7110_ca_register(struct av7110 *av7110)
{
return dvb_register_device(av7110->dvb_adapter, &av7110->ca_dev,
&dvbdev_ca, av7110, DVB_DEVICE_CA);
}
void av7110_ca_unregister(struct av7110 *av7110)
{
dvb_unregister_device(av7110->ca_dev);
}
void av7110_ca_init(struct av7110* av7110)
{
ci_ll_init(&av7110->ci_rbuffer, &av7110->ci_wbuffer, 8192);
}
void av7110_ca_exit(struct av7110* av7110)
{
ci_ll_release(&av7110->ci_rbuffer, &av7110->ci_wbuffer);
}
#ifndef _AV7110_CA_H_
#define _AV7110_CA_H_
struct av7110;
extern void CI_handle(struct av7110 *av7110, u8 *data, u16 len);
extern void ci_get_data(struct dvb_ringbuffer *cibuf, u8 *data, int len);
extern int av7110_ca_register(struct av7110 *av7110);
extern void av7110_ca_unregister(struct av7110 *av7110);
extern void av7110_ca_init(struct av7110* av7110);
extern void av7110_ca_exit(struct av7110* av7110);
#endif /* _AV7110_CA_H_ */
/*
* av7110_hw.c: av7110 low level hardware access and firmware interface
*
* Copyright (C) 1999-2002 Ralph Metzler
* & Marcus Metzler for convergence integrated media GmbH
*
* originally based on code by:
* Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*
* the project's page is at http://www.linuxtv.org/dvb/
*/
/* for debugging ARM communication: */
//#define COM_DEBUG
#include <stdarg.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/byteorder/swabb.h>
#include <linux/smp_lock.h>
#include <linux/fs.h>
#define DEBUG_VARIABLE av7110_debug
extern int av7110_debug;
#include "av7110.h"
#include "av7110_hw.h"
#include "dvb_functions.h"
/****************************************************************************
* DEBI functions
****************************************************************************/
/* This DEBI code is based on the Stradis driver
by Nathan Laredo <laredo@gnu.org> */
int av7110_debiwrite(struct av7110 *av7110, u32 config,
int addr, u32 val, int count)
{
struct saa7146_dev *dev = av7110->dev;
if (count <= 0 || count > 32764)
return -1;
if (saa7146_wait_for_debi_done(av7110->dev) < 0)
return -1;
saa7146_write(dev, DEBI_CONFIG, config);
if (count <= 4) /* immediate transfer */
saa7146_write(dev, DEBI_AD, val);
else /* block transfer */
saa7146_write(dev, DEBI_AD, av7110->debi_bus);
saa7146_write(dev, DEBI_COMMAND, (count << 17) | (addr & 0xffff));
saa7146_write(dev, MC2, (2 << 16) | 2);
return 0;
}
u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, int count)
{
struct saa7146_dev *dev = av7110->dev;
u32 result = 0;
if (count > 32764 || count <= 0)
return 0;
if (saa7146_wait_for_debi_done(av7110->dev) < 0)
return 0;
saa7146_write(dev, DEBI_AD, av7110->debi_bus);
saa7146_write(dev, DEBI_COMMAND, (count << 17) | 0x10000 | (addr & 0xffff));
saa7146_write(dev, DEBI_CONFIG, config);
saa7146_write(dev, MC2, (2 << 16) | 2);
if (count > 4)
return count;
saa7146_wait_for_debi_done(av7110->dev);
result = saa7146_read(dev, DEBI_AD);
result &= (0xffffffffUL >> ((4 - count) * 8));
return result;
}
/* av7110 ARM core boot stuff */
void av7110_reset_arm(struct av7110 *av7110)
{
saa7146_setgpio(av7110->dev, RESET_LINE, SAA7146_GPIO_OUTLO);
/* Disable DEBI and GPIO irq */
IER_DISABLE(av7110->dev, (MASK_19 | MASK_03));
saa7146_write(av7110->dev, ISR, (MASK_19 | MASK_03));
//FIXME: are those mdelays really necessary?
mdelay(800);
saa7146_setgpio(av7110->dev, RESET_LINE, SAA7146_GPIO_OUTHI);
mdelay(800);
ARM_ResetMailBox(av7110);
saa7146_write(av7110->dev, ISR, (MASK_19 | MASK_03));
IER_ENABLE(av7110->dev, MASK_03);
av7110->arm_ready = 1;
printk("av7110: ARM RESET\n");
}
static int waitdebi(struct av7110 *av7110, int adr, int state)
{
int k;
DEB_EE(("av7110: %p\n", av7110));
for (k = 0; k < 100; k++) {
if (irdebi(av7110, DEBINOSWAP, adr, 0, 2) == state)
return 0;
udelay(500);
}
return -1;
}
static int load_dram(struct av7110 *av7110, u32 *data, int len)
{
int i;
int blocks, rest;
u32 base, bootblock = BOOT_BLOCK;
DEB_EE(("av7110: %p\n", av7110));
blocks = len / BOOT_MAX_SIZE;
rest = len % BOOT_MAX_SIZE;
base = DRAM_START_CODE;
for (i = 0; i < blocks; i++) {
if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0)
return -1;
DEB_D(("Writing DRAM block %d\n", i));
mwdebi(av7110, DEBISWAB, bootblock,
((char*)data) + i * BOOT_MAX_SIZE, BOOT_MAX_SIZE);
bootblock ^= 0x1400;
iwdebi(av7110, DEBISWAB, BOOT_BASE, swab32(base), 4);
iwdebi(av7110, DEBINOSWAP, BOOT_SIZE, BOOT_MAX_SIZE, 2);
iwdebi(av7110, DEBINOSWAP, BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
base += BOOT_MAX_SIZE;
}
if (rest > 0) {
if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0)
return -1;
if (rest > 4)
mwdebi(av7110, DEBISWAB, bootblock,
((char*)data) + i * BOOT_MAX_SIZE, rest);
else
mwdebi(av7110, DEBISWAB, bootblock,
((char*)data) + i * BOOT_MAX_SIZE - 4, rest + 4);
iwdebi(av7110, DEBISWAB, BOOT_BASE, swab32(base), 4);
iwdebi(av7110, DEBINOSWAP, BOOT_SIZE, rest, 2);
iwdebi(av7110, DEBINOSWAP, BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
}
if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0)
return -1;
iwdebi(av7110, DEBINOSWAP, BOOT_SIZE, 0, 2);
iwdebi(av7110, DEBINOSWAP, BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
if (waitdebi(av7110, BOOT_STATE, BOOTSTATE_BOOT_COMPLETE) < 0)
return -1;
return 0;
}
/* we cannot write av7110 DRAM directly, so load a bootloader into
* the DPRAM which implements a simple boot protocol */
static u8 bootcode[] = {
0xea, 0x00, 0x00, 0x0e, 0xe1, 0xb0, 0xf0, 0x0e, /* 0x0000 */
0xe2, 0x5e, 0xf0, 0x04, 0xe2, 0x5e, 0xf0, 0x04,
0xe2, 0x5e, 0xf0, 0x08, 0xe2, 0x5e, 0xf0, 0x04,
0xe2, 0x5e, 0xf0, 0x04, 0xe2, 0x5e, 0xf0, 0x04,
0x2c, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0c,
0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x34,
0x00, 0x00, 0x00, 0x00, 0xa5, 0xa5, 0x5a, 0x5a,
0x00, 0x1f, 0x15, 0x55, 0x00, 0x00, 0x00, 0x09,
0xe5, 0x9f, 0xd0, 0x5c, 0xe5, 0x9f, 0x40, 0x54, /* 0x0040 */
0xe3, 0xa0, 0x00, 0x00, 0xe5, 0x84, 0x00, 0x00,
0xe5, 0x84, 0x00, 0x04, 0xe1, 0xd4, 0x10, 0xb0,
0xe3, 0x51, 0x00, 0x00, 0x0a, 0xff, 0xff, 0xfc,
0xe1, 0xa0, 0x10, 0x0d, 0xe5, 0x94, 0x30, 0x04,
0xe1, 0xd4, 0x20, 0xb2, 0xe2, 0x82, 0x20, 0x3f,
0xe1, 0xb0, 0x23, 0x22, 0x03, 0xa0, 0x00, 0x02,
0xe1, 0xc4, 0x00, 0xb0, 0x0a, 0xff, 0xff, 0xf4,
0xe8, 0xb1, 0x1f, 0xe0, 0xe8, 0xa3, 0x1f, 0xe0, /* 0x0080 */
0xe8, 0xb1, 0x1f, 0xe0, 0xe8, 0xa3, 0x1f, 0xe0,
0xe2, 0x52, 0x20, 0x01, 0x1a, 0xff, 0xff, 0xf9,
0xe2, 0x2d, 0xdb, 0x05, 0xea, 0xff, 0xff, 0xec,
0x2c, 0x00, 0x03, 0xf8, 0x2c, 0x00, 0x04, 0x00,
};
int av7110_bootarm(struct av7110 *av7110)
{
struct saa7146_dev *dev = av7110->dev;
u32 ret;
int i;
DEB_EE(("av7110: %p\n", av7110));
saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTLO);
/* Disable DEBI and GPIO irq */
IER_DISABLE(av7110->dev, MASK_03 | MASK_19);
saa7146_write(av7110->dev, ISR, (MASK_19 | MASK_03));
/* enable DEBI */
saa7146_write(av7110->dev, MC1, 0x08800880);
saa7146_write(av7110->dev, DD1_STREAM_B, 0x00000000);
saa7146_write(av7110->dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
/* test DEBI */
iwdebi(av7110, DEBISWAP, DPRAM_BASE, 0x76543210, 4);
if ((ret=irdebi(av7110, DEBINOSWAP, DPRAM_BASE, 0, 4)) != 0x10325476) {
printk(KERN_ERR "dvb: debi test in av7110_bootarm() failed: "
"%08x != %08x (check your BIOS notplug settings)\n",
ret, 0x10325476);
return -1;
}
for (i = 0; i < 8192; i += 4)
iwdebi(av7110, DEBISWAP, DPRAM_BASE + i, 0x00, 4);
DEB_D(("av7110_bootarm: debi test OK\n"));
/* boot */
DEB_D(("av7110_bootarm: load boot code\n"));
saa7146_setgpio(dev, ARM_IRQ_LINE, SAA7146_GPIO_IRQLO);
//saa7146_setgpio(dev, DEBI_DONE_LINE, SAA7146_GPIO_INPUT);
//saa7146_setgpio(dev, 3, SAA7146_GPIO_INPUT);
mwdebi(av7110, DEBISWAB, DPRAM_BASE, bootcode, sizeof(bootcode));
iwdebi(av7110, DEBINOSWAP, BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
saa7146_wait_for_debi_done(av7110->dev);
saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI);
//FIXME: necessary?
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ);
DEB_D(("av7110_bootarm: load dram code\n"));
if (load_dram(av7110, (u32 *)av7110->bin_root, av7110->size_root) < 0)
return -1;
saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTLO);
mdelay(1);
DEB_D(("av7110_bootarm: load dpram code\n"));
mwdebi(av7110, DEBISWAB, DPRAM_BASE, av7110->bin_dpram, av7110->size_dpram);
saa7146_wait_for_debi_done(av7110->dev);
saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI);
//FIXME: necessary?
mdelay(800);
//ARM_ClearIrq(av7110);
ARM_ResetMailBox(av7110);
saa7146_write(av7110->dev, ISR, (MASK_19 | MASK_03));
IER_ENABLE(av7110->dev, MASK_03);
av7110->arm_errors = 0;
av7110->arm_ready = 1;
return 0;
}
/****************************************************************************
* DEBI command polling
****************************************************************************/
int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
{
int i;
unsigned long start;
#ifdef COM_DEBUG
u32 stat;
#endif
// DEB_EE(("av7110: %p\n", av7110));
if (!av7110->arm_ready) {
DEB_D(("arm not ready.\n"));
return -1;
}
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2 )) {
dvb_delay(1);
if (time_after(jiffies, start + ARM_WAIT_FREE)) {
printk(KERN_ERR "%s: timeout waiting for COMMAND idle\n", __FUNCTION__);
return -1;
}
}
#ifndef _NOHANDSHAKE
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2 )) {
dvb_delay(1);
if (time_after(jiffies, start + ARM_WAIT_SHAKE)) {
printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
return -1;
}
}
#endif
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2) & OSDQFull) {
dvb_delay(1);
if (time_after(jiffies, start + ARM_WAIT_OSD)) {
printk(KERN_ERR "%s: timeout waiting for !OSDQFull\n", __FUNCTION__);
return -1;
}
}
for (i = 2; i < length; i++)
wdebi(av7110, DEBINOSWAP, COMMAND + 2 * i, (u32) buf[i], 2);
if (length)
wdebi(av7110, DEBINOSWAP, COMMAND + 2, (u32) buf[1], 2);
else
wdebi(av7110, DEBINOSWAP, COMMAND + 2, 0, 2);
wdebi(av7110, DEBINOSWAP, COMMAND, (u32) buf[0], 2);
#ifdef COM_DEBUG
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2 )) {
dvb_delay(1);
if (time_after(jiffies, start + ARM_WAIT_FREE)) {
printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n",
__FUNCTION__);
return -1;
}
}
stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
if (stat & GPMQOver) {
printk(KERN_ERR "%s: GPMQOver\n", __FUNCTION__);
return -1;
}
else if (stat & OSDQOver) {
printk(KERN_ERR "%s: OSDQOver\n", __FUNCTION__);
return -1;
}
#endif
return 0;
}
int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
{
int ret;
// DEB_EE(("av7110: %p\n", av7110));
if (!av7110->arm_ready) {
DEB_D(("arm not ready.\n"));
return -1;
}
if (down_interruptible(&av7110->dcomlock))
return -ERESTARTSYS;
ret = __av7110_send_fw_cmd(av7110, buf, length);
up(&av7110->dcomlock);
if (ret)
printk("av7110_send_fw_cmd error\n");
return ret;
}
int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...)
{
va_list args;
u16 buf[num + 2];
int i, ret;
// DEB_EE(("av7110: %p\n",av7110));
buf[0] = ((type << 8) | com);
buf[1] = num;
if (num) {
va_start(args, num);
for (i = 0; i < num; i++)
buf[i + 2] = va_arg(args, u32);
va_end(args);
}
ret = av7110_send_fw_cmd(av7110, buf, num + 2);
if (ret)
printk("av7110_fw_cmd error\n");
return ret;
}
int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len)
{
int i, ret;
u16 cmd[18] = { ((COMTYPE_COMMON_IF << 8) + subcom),
16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
DEB_EE(("av7110: %p\n", av7110));
for(i = 0; i < len && i < 32; i++)
{
if(i % 2 == 0)
cmd[(i / 2) + 2] = (u16)(buf[i]) << 8;
else
cmd[(i / 2) + 2] |= buf[i];
}
ret = av7110_send_fw_cmd(av7110, cmd, 18);
if (ret)
printk("av7110_send_ci_cmd error\n");
return ret;
}
int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
int request_buf_len, u16 *reply_buf, int reply_buf_len)
{
int err;
s16 i;
unsigned long start;
#ifdef COM_DEBUG
u32 stat;
#endif
DEB_EE(("av7110: %p\n", av7110));
if (!av7110->arm_ready) {
DEB_D(("arm not ready.\n"));
return -1;
}
if (down_interruptible(&av7110->dcomlock))
return -ERESTARTSYS;
if ((err = __av7110_send_fw_cmd(av7110, request_buf, request_buf_len)) < 0) {
up(&av7110->dcomlock);
printk("av7110_fw_request error\n");
return err;
}
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2)) {
#ifdef _NOHANDSHAKE
dvb_delay(1);
#endif
if (time_after(jiffies, start + ARM_WAIT_FREE)) {
printk("%s: timeout waiting for COMMAND to complete\n", __FUNCTION__);
up(&av7110->dcomlock);
return -1;
}
}
#ifndef _NOHANDSHAKE
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2 )) {
dvb_delay(1);
if (time_after(jiffies, start + ARM_WAIT_SHAKE)) {
printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
up(&av7110->dcomlock);
return -1;
}
}
#endif
#ifdef COM_DEBUG
stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
if (stat & GPMQOver) {
printk(KERN_ERR "%s: GPMQOver\n", __FUNCTION__);
up(&av7110->dcomlock);
return -1;
}
else if (stat & OSDQOver) {
printk(KERN_ERR "%s: OSDQOver\n", __FUNCTION__);
up(&av7110->dcomlock);
return -1;
}
#endif
for (i = 0; i < reply_buf_len; i++)
reply_buf[i] = rdebi(av7110, DEBINOSWAP, COM_BUFF + 2 * i, 0, 2);
up(&av7110->dcomlock);
return 0;
}
int av7110_fw_query(struct av7110 *av7110, u16 tag, u16* buf, s16 length)
{
int ret;
ret = av7110_fw_request(av7110, &tag, 0, buf, length);
if (ret)
printk("av7110_fw_query error\n");
return ret;
}
/****************************************************************************
* Firmware commands
****************************************************************************/
/* get version of the firmware ROM, RTSL, video ucode and ARM application */
void av7110_firmversion(struct av7110 *av7110)
{
u16 buf[20];
u16 tag = ((COMTYPE_REQUEST << 8) + ReqVersion);
DEB_EE(("av7110: %p\n", av7110));
av7110_fw_query(av7110, tag, buf, 16);
av7110->arm_fw = (buf[0] << 16) + buf[1];
av7110->arm_rtsl = (buf[2] << 16) + buf[3];
av7110->arm_vid = (buf[4] << 16) + buf[5];
av7110->arm_app = (buf[6] << 16) + buf[7];
av7110->avtype = (buf[8] << 16) + buf[9];
printk("DVB: AV711%d(%d) - firm %08x, rtsl %08x, vid %08x, app %08x\n",
av7110->avtype, av7110->dvb_adapter->num, av7110->arm_fw,
av7110->arm_rtsl, av7110->arm_vid, av7110->arm_app);
/* print firmware capabilities */
if (FW_CI_LL_SUPPORT(av7110->arm_app))
printk("DVB: AV711%d(%d) - firmware supports CI link layer interface\n",
av7110->avtype, av7110->dvb_adapter->num);
else
printk("DVB: AV711%d(%d) - no firmware support for CI link layer interface\n",
av7110->avtype, av7110->dvb_adapter->num);
return;
}
int av7110_diseqc_send(struct av7110 *av7110, int len, u8 *msg, unsigned long burst)
{
int i;
u16 buf[18] = { ((COMTYPE_AUDIODAC << 8) + SendDiSEqC),
16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
DEB_EE(("av7110: %p\n", av7110));
if (len > 10)
len = 10;
buf[1] = len + 2;
buf[2] = len;
if (burst != -1)
buf[3] = burst ? 0x01 : 0x00;
else
buf[3] = 0xffff;
for (i = 0; i < len; i++)
buf[i + 4] = msg[i];
if (av7110_send_fw_cmd(av7110, buf, 18))
printk("av7110_diseqc_send error\n");
return 0;
}
#ifdef CONFIG_DVB_AV7110_OSD
static inline int ResetBlend(struct av7110 *av7110, u8 windownr)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, SetNonBlend, 1, windownr);
}
static inline int SetColorBlend(struct av7110 *av7110, u8 windownr)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, SetCBlend, 1, windownr);
}
static inline int SetWindowBlend(struct av7110 *av7110, u8 windownr, u8 blending)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, SetWBlend, 2, windownr, blending);
}
static inline int SetBlend_(struct av7110 *av7110, u8 windownr,
enum av7110_osd_palette_type colordepth, u16 index, u8 blending)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, SetBlend, 4,
windownr, colordepth, index, blending);
}
static inline int SetColor_(struct av7110 *av7110, u8 windownr,
enum av7110_osd_palette_type colordepth, u16 index, u16 colorhi, u16 colorlo)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, SetColor, 5,
windownr, colordepth, index, colorhi, colorlo);
}
static inline int BringToTop(struct av7110 *av7110, u8 windownr)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, WTop, 1, windownr);
}
static inline int SetFont(struct av7110 *av7110, u8 windownr, u8 fontsize,
u16 colorfg, u16 colorbg)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Font, 4,
windownr, fontsize, colorfg, colorbg);
}
static int FlushText(struct av7110 *av7110)
{
unsigned long start;
if (down_interruptible(&av7110->dcomlock))
return -ERESTARTSYS;
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2)) {
dvb_delay(1);
if (time_after(jiffies, start + ARM_WAIT_OSD)) {
printk(KERN_ERR "%s: timeout waiting for BUFF1_BASE == 0\n",
__FUNCTION__);
up(&av7110->dcomlock);
return -1;
}
}
up(&av7110->dcomlock);
return 0;
}
static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, u8* buf)
{
int i, ret;
unsigned long start;
int length = strlen(buf) + 1;
u16 cbuf[5] = { (COMTYPE_OSD << 8) + DText, 3, win, x, y };
if (down_interruptible(&av7110->dcomlock))
return -ERESTARTSYS;
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2)) {
dvb_delay(1);
if (time_after(jiffies, start + ARM_WAIT_OSD)) {
printk(KERN_ERR "%s: timeout waiting for BUFF1_BASE == 0\n",
__FUNCTION__);
up(&av7110->dcomlock);
return -1;
}
}
#ifndef _NOHANDSHAKE
start = jiffies;
while (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2)) {
dvb_delay(1);
if (time_after(jiffies, start + ARM_WAIT_SHAKE)) {
printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n",
__FUNCTION__);
up(&av7110->dcomlock);
return -1;
}
}
#endif
for (i = 0; i < length / 2; i++)
wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2,
swab16(*(u16 *)(buf + 2 * i)), 2);
if (length & 1)
wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2, 0, 2);
ret = __av7110_send_fw_cmd(av7110, cbuf, 5);
up(&av7110->dcomlock);
if (ret)
printk("WriteText error\n");
return ret;
}
static inline int DrawLine(struct av7110 *av7110, u8 windownr,
u16 x, u16 y, u16 dx, u16 dy, u16 color)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, DLine, 6,
windownr, x, y, dx, dy, color);
}
static inline int DrawBlock(struct av7110 *av7110, u8 windownr,
u16 x, u16 y, u16 dx, u16 dy, u16 color)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, DBox, 6,
windownr, x, y, dx, dy, color);
}
static inline int HideWindow(struct av7110 *av7110, u8 windownr)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, WHide, 1, windownr);
}
static inline int MoveWindowRel(struct av7110 *av7110, u8 windownr, u16 x, u16 y)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, WMoveD, 3, windownr, x, y);
}
static inline int MoveWindowAbs(struct av7110 *av7110, u8 windownr, u16 x, u16 y)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, WMoveA, 3, windownr, x, y);
}
static inline int DestroyOSDWindow(struct av7110 *av7110, u8 windownr)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, WDestroy, 1, windownr);
}
static inline int CreateOSDWindow(struct av7110 *av7110, u8 windownr,
enum av7110_window_display_type disptype,
u16 width, u16 height)
{
return av7110_fw_cmd(av7110, COMTYPE_OSD, WCreate, 4,
windownr, disptype, width, height);
}
static enum av7110_osd_palette_type bpp2pal[8] = {
Pal1Bit, Pal2Bit, 0, Pal4Bit, 0, 0, 0, Pal8Bit
};
static enum av7110_window_display_type bpp2bit[8] = {
BITMAP1, BITMAP2, 0, BITMAP4, 0, 0, 0, BITMAP8
};
static inline int LoadBitmap(struct av7110 *av7110, u16 format,
u16 dx, u16 dy, int inc, u8* data)
{
int bpp;
int i;
int d, delta;
u8 c;
DECLARE_WAITQUEUE(wait, current);
DEB_EE(("av7110: %p\n", av7110));
if (av7110->bmp_state == BMP_LOADING) {
add_wait_queue(&av7110->bmpq, &wait);
while (1) {
set_current_state(TASK_INTERRUPTIBLE);
if (av7110->bmp_state != BMP_LOADING
|| signal_pending(current))
break;
schedule();
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&av7110->bmpq, &wait);
}
if (av7110->bmp_state == BMP_LOADING)
return -1;
av7110->bmp_state = BMP_LOADING;
if (format == BITMAP8) {
bpp=8; delta = 1;
} else if (format == BITMAP4) {
bpp=4; delta = 2;
} else if (format == BITMAP2) {
bpp=2; delta = 4;
} else if (format == BITMAP1) {
bpp=1; delta = 8;
} else {
av7110->bmp_state = BMP_NONE;
return -1;
}
av7110->bmplen = ((dx * dy * bpp + 7) & ~7) / 8;
av7110->bmpp = 0;
if (av7110->bmplen > 32768) {
av7110->bmp_state = BMP_NONE;
return -1;
}
for (i = 0; i < dy; i++) {
if (copy_from_user(av7110->bmpbuf + 1024 + i * dx, data + i * inc, dx)) {
av7110->bmp_state = BMP_NONE;
return -1;
}
}
if (format != BITMAP8) {
for (i = 0; i < dx * dy / delta; i++) {
c = ((u8 *)av7110->bmpbuf)[1024 + i * delta + delta - 1];
for (d = delta - 2; d >= 0; d--) {
c |= (((u8 *)av7110->bmpbuf)[1024 + i * delta + d]
<< ((delta - d - 1) * bpp));
((u8 *)av7110->bmpbuf)[1024 + i] = c;
}
}
}
av7110->bmplen += 1024;
return av7110_fw_cmd(av7110, COMTYPE_OSD, LoadBmp, 3, format, dx, dy);
}
static int BlitBitmap(struct av7110 *av7110, u16 win, u16 x, u16 y, u16 trans)
{
DECLARE_WAITQUEUE(wait, current);
DEB_EE(("av7110: %p\n", av7110));
if (av7110->bmp_state == BMP_NONE)
return -1;
if (av7110->bmp_state == BMP_LOADING) {
add_wait_queue(&av7110->bmpq, &wait);
while (1) {
set_current_state(TASK_INTERRUPTIBLE);
if (av7110->bmp_state != BMP_LOADING
|| signal_pending(current))
break;
schedule();
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&av7110->bmpq, &wait);
}
if (av7110->bmp_state == BMP_LOADED)
return av7110_fw_cmd(av7110, COMTYPE_OSD, BlitBmp, 4, win, x, y, trans);
return -1;
}
static inline int ReleaseBitmap(struct av7110 *av7110)
{
DEB_EE(("av7110: %p\n",av7110));
if (av7110->bmp_state != BMP_LOADED)
return -1;
av7110->bmp_state = BMP_NONE;
return av7110_fw_cmd(av7110, COMTYPE_OSD, ReleaseBmp, 0);
}
static u32 RGB2YUV(u16 R, u16 G, u16 B)
{
u16 y, u, v;
u16 Y, Cr, Cb;
y = R * 77 + G * 150 + B * 29; /* Luma=0.299R+0.587G+0.114B 0..65535 */
u = 2048 + B * 8 -(y >> 5); /* Cr 0..4095 */
v = 2048 + R * 8 -(y >> 5); /* Cb 0..4095 */
Y = y / 256;
Cb = u / 16;
Cr = v / 16;
return Cr | (Cb << 16) | (Y << 8);
}
static void OSDSetColor(struct av7110 *av7110, u8 color, u8 r, u8 g, u8 b, u8 blend)
{
u16 ch, cl;
u32 yuv;
yuv = blend ? RGB2YUV(r,g,b) : 0;
cl = (yuv & 0xffff);
ch = ((yuv >> 16) & 0xffff);
SetColor_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
color, ch, cl);
SetBlend_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
color, ((blend >> 4) & 0x0f));
}
static int OSDSetPalette(struct av7110 *av7110, u32 *colors, u8 first, u8 last)
{
int i;
int length = last - first + 1;
if (length * 4 > DATA_BUFF3_SIZE)
return -1;
for (i = 0; i < length; i++) {
u32 blend = (colors[i] & 0xF0000000) >> 4;
u32 yuv = blend ? RGB2YUV(colors[i] & 0xFF, (colors[i] >> 8) & 0xFF,
(colors[i] >> 16) & 0xFF) | blend : 0;
yuv = ((yuv & 0xFFFF0000) >> 16) | ((yuv & 0x0000FFFF) << 16);
wdebi(av7110, DEBINOSWAP, DATA_BUFF3_BASE + i * 4, yuv, 4);
}
return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Palette, 4,
av7110->osdwin,
bpp2pal[av7110->osdbpp[av7110->osdwin]],
first, last);
}
static int OSDSetBlock(struct av7110 *av7110, int x0, int y0,
int x1, int y1, int inc, u8 *data)
{
uint w, h, bpp, bpl, size, lpb, bnum, brest;
int i;
w = x1 - x0 + 1;
h = y1 - y0 + 1;
if (inc <= 0)
inc = w;
if (w <= 0 || w > 720 || h <= 0 || h > 576)
return -1;
bpp = av7110->osdbpp[av7110->osdwin] + 1;
bpl = ((w * bpp + 7) & ~7) / 8;
size = h * bpl;
lpb = (32 * 1024) / bpl;
bnum = size / (lpb * bpl);
brest = size - bnum * lpb * bpl;
for (i = 0; i < bnum; i++) {
LoadBitmap(av7110, bpp2bit[av7110->osdbpp[av7110->osdwin]],
w, lpb, inc, data);
BlitBitmap(av7110, av7110->osdwin, x0, y0 + i * lpb, 0);
data += lpb * inc;
}
if (brest) {
LoadBitmap(av7110, bpp2bit[av7110->osdbpp[av7110->osdwin]],
w, brest / bpl, inc, data);
BlitBitmap(av7110, av7110->osdwin, x0, y0 + bnum * lpb, 0);
}
ReleaseBitmap(av7110);
return 0;
}
int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc)
{
switch (dc->cmd) {
case OSD_Close:
DestroyOSDWindow(av7110, av7110->osdwin);
return 0;
case OSD_Open:
av7110->osdbpp[av7110->osdwin] = (dc->color - 1) & 7;
CreateOSDWindow(av7110, av7110->osdwin,
bpp2bit[av7110->osdbpp[av7110->osdwin]],
dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
if (!dc->data) {
MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
SetColorBlend(av7110, av7110->osdwin);
}
return 0;
case OSD_Show:
MoveWindowRel(av7110, av7110->osdwin, 0, 0);
return 0;
case OSD_Hide:
HideWindow(av7110, av7110->osdwin);
return 0;
case OSD_Clear:
DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, 0);
return 0;
case OSD_Fill:
DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, dc->color);
return 0;
case OSD_SetColor:
OSDSetColor(av7110, dc->color, dc->x0, dc->y0, dc->x1, dc->y1);
return 0;
case OSD_SetPalette:
{
if (FW_VERSION(av7110->arm_app) >= 0x2618)
OSDSetPalette(av7110, (u32 *)dc->data, dc->color, dc->x0);
else {
int i, len = dc->x0-dc->color+1;
u8 *colors = (u8 *)dc->data;
for (i = 0; i<len; i++)
OSDSetColor(av7110, dc->color + i,
colors[i * 4], colors[i * 4 + 1],
colors[i * 4 + 2], colors[i * 4 + 3]);
}
return 0;
}
case OSD_SetTrans:
return 0;
case OSD_SetPixel:
DrawLine(av7110, av7110->osdwin,
dc->x0, dc->y0, 0, 0, dc->color);
return 0;
case OSD_GetPixel:
return 0;
case OSD_SetRow:
dc->y1 = dc->y0;
/* fall through */
case OSD_SetBlock:
OSDSetBlock(av7110, dc->x0, dc->y0, dc->x1, dc->y1, dc->color, dc->data);
return 0;
case OSD_FillRow:
DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
dc->x1-dc->x0+1, dc->y1, dc->color);
return 0;
case OSD_FillBlock:
DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1, dc->color);
return 0;
case OSD_Line:
DrawLine(av7110, av7110->osdwin,
dc->x0, dc->y0, dc->x1 - dc->x0, dc->y1 - dc->y0, dc->color);
return 0;
case OSD_Query:
return 0;
case OSD_Test:
return 0;
case OSD_Text:
{
char textbuf[240];
if (strncpy_from_user(textbuf, dc->data, 240) < 0)
return -EFAULT;
textbuf[239] = 0;
if (dc->x1 > 3)
dc->x1 = 3;
SetFont(av7110, av7110->osdwin, dc->x1,
(u16) (dc->color & 0xffff), (u16) (dc->color >> 16));
FlushText(av7110);
WriteText(av7110, av7110->osdwin, dc->x0, dc->y0, textbuf);
return 0;
}
case OSD_SetWindow:
if (dc->x0 < 1 || dc->x0 > 7)
return -EINVAL;
av7110->osdwin = dc->x0;
return 0;
case OSD_MoveWindow:
MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
SetColorBlend(av7110, av7110->osdwin);
return 0;
default:
return -EINVAL;
}
}
#endif /* CONFIG_DVB_AV7110_OSD */
#ifndef _AV7110_HW_H_
#define _AV7110_HW_H_
#include "av7110.h"
/* DEBI transfer mode defs */
#define DEBINOSWAP 0x000e0000
#define DEBISWAB 0x001e0000
#define DEBISWAP 0x002e0000
#define ARM_WAIT_FREE (HZ)
#define ARM_WAIT_SHAKE (HZ/5)
#define ARM_WAIT_OSD (HZ)
enum av7110_bootstate
{
BOOTSTATE_BUFFER_EMPTY = 0,
BOOTSTATE_BUFFER_FULL = 1,
BOOTSTATE_BOOT_COMPLETE = 2
};
enum av7110_type_rec_play_format
{ RP_None,
AudioPES,
AudioMp2,
AudioPCM,
VideoPES,
AV_PES
};
enum av7110_osd_palette_type
{
NoPalet = 0, /* No palette */
Pal1Bit = 2, /* 2 colors for 1 Bit Palette */
Pal2Bit = 4, /* 4 colors for 2 bit palette */
Pal4Bit = 16, /* 16 colors for 4 bit palette */
Pal8Bit = 256 /* 256 colors for 16 bit palette */
};
enum av7110_window_display_type {
BITMAP1, /* 1 bit bitmap */
BITMAP2, /* 2 bit bitmap */
BITMAP4, /* 4 bit bitmap */
BITMAP8, /* 8 bit bitmap */
BITMAP1HR, /* 1 Bit bitmap half resolution */
BITMAP2HR, /* 2 bit bitmap half resolution */
BITMAP4HR, /* 4 bit bitmap half resolution */
BITMAP8HR, /* 8 bit bitmap half resolution */
YCRCB422, /* 4:2:2 YCRCB Graphic Display */
YCRCB444, /* 4:4:4 YCRCB Graphic Display */
YCRCB444HR, /* 4:4:4 YCRCB graphic half resolution */
VIDEOTSIZE, /* True Size Normal MPEG Video Display */
VIDEOHSIZE, /* MPEG Video Display Half Resolution */
VIDEOQSIZE, /* MPEG Video Display Quarter Resolution */
VIDEODSIZE, /* MPEG Video Display Double Resolution */
VIDEOTHSIZE, /* True Size MPEG Video Display Half Resolution */
VIDEOTQSIZE, /* True Size MPEG Video Display Quarter Resolution*/
VIDEOTDSIZE, /* True Size MPEG Video Display Double Resolution */
VIDEONSIZE, /* Full Size MPEG Video Display */
CURSOR /* Cursor */
};
/* switch defines */
#define SB_GPIO 3
#define SB_OFF SAA7146_GPIO_OUTLO /* SlowBlank off (TV-Mode) */
#define SB_ON SAA7146_GPIO_INPUT /* SlowBlank on (AV-Mode) */
#define SB_WIDE SAA7146_GPIO_OUTHI /* SlowBlank 6V (16/9-Mode) (not implemented) */
#define FB_GPIO 1
#define FB_OFF SAA7146_GPIO_LO /* FastBlank off (CVBS-Mode) */
#define FB_ON SAA7146_GPIO_OUTHI /* FastBlank on (RGB-Mode) */
#define FB_LOOP SAA7146_GPIO_INPUT /* FastBlank loop-through (PC graphics ???) */
enum av7110_video_output_mode
{
NO_OUT = 0, /* disable analog output */
CVBS_RGB_OUT = 1,
CVBS_YC_OUT = 2,
YC_OUT = 3
};
/* firmware internal msg q status: */
#define GPMQFull 0x0001 /* Main Message Queue Full */
#define GPMQOver 0x0002 /* Main Message Queue Overflow */
#define HPQFull 0x0004 /* High Priority Msg Queue Full */
#define HPQOver 0x0008
#define OSDQFull 0x0010 /* OSD Queue Full */
#define OSDQOver 0x0020
/* hw section filter flags */
#define SECTION_EIT 0x01
#define SECTION_SINGLE 0x00
#define SECTION_CYCLE 0x02
#define SECTION_CONTINUOS 0x04
#define SECTION_MODE 0x06
#define SECTION_IPMPE 0x0C /* size up to 4k */
#define SECTION_HIGH_SPEED 0x1C /* larger buffer */
#define DATA_PIPING_FLAG 0x20 /* for Data Piping Filter */
#define PBUFSIZE_NONE 0x0000
#define PBUFSIZE_1P 0x0100
#define PBUFSIZE_2P 0x0200
#define PBUFSIZE_1K 0x0300
#define PBUFSIZE_2K 0x0400
#define PBUFSIZE_4K 0x0500
#define PBUFSIZE_8K 0x0600
#define PBUFSIZE_16K 0x0700
#define PBUFSIZE_32K 0x0800
/* firmware command codes */
enum av7110_osd_command {
WCreate,
WDestroy,
WMoveD,
WMoveA,
WHide,
WTop,
DBox,
DLine,
DText,
Set_Font,
SetColor,
SetBlend,
SetWBlend,
SetCBlend,
SetNonBlend,
LoadBmp,
BlitBmp,
ReleaseBmp,
SetWTrans,
SetWNoTrans,
Set_Palette
};
enum av7110_pid_command {
MultiPID,
VideoPID,
AudioPID,
InitFilt,
FiltError,
NewVersion,
CacheError,
AddPIDFilter,
DelPIDFilter,
Scan,
SetDescr,
SetIR,
FlushTSQueue
};
enum av7110_mpeg_command {
SelAudChannels
};
enum av7110_audio_command {
AudioDAC,
CabADAC,
ON22K,
OFF22K,
MainSwitch,
ADSwitch,
SendDiSEqC,
SetRegister
};
enum av7110_request_command {
AudioState,
AudioBuffState,
VideoState1,
VideoState2,
VideoState3,
CrashCounter,
ReqVersion,
ReqVCXO,
ReqRegister,
ReqSecFilterError,
ReqSTC
};
enum av7110_encoder_command {
SetVidMode,
SetTestMode,
LoadVidCode,
SetMonitorType,
SetPanScanType,
SetFreezeMode
};
enum av7110_rec_play_state {
__Record,
__Stop,
__Play,
__Pause,
__Slow,
__FF_IP,
__Scan_I,
__Continue
};
enum av7110_command_type {
COMTYPE_NOCOM,
COMTYPE_PIDFILTER,
COMTYPE_MPEGDECODER,
COMTYPE_OSD,
COMTYPE_BMP,
COMTYPE_ENCODER,
COMTYPE_AUDIODAC,
COMTYPE_REQUEST,
COMTYPE_SYSTEM,
COMTYPE_REC_PLAY,
COMTYPE_COMMON_IF,
COMTYPE_PID_FILTER,
COMTYPE_PES,
COMTYPE_TS,
COMTYPE_VIDEO,
COMTYPE_AUDIO,
COMTYPE_CI_LL,
};
#define VID_NONE_PREF 0x00 /* No aspect ration processing preferred */
#define VID_PAN_SCAN_PREF 0x01 /* Pan and Scan Display preferred */
#define VID_VERT_COMP_PREF 0x02 /* Vertical compression display preferred */
#define VID_VC_AND_PS_PREF 0x03 /* PanScan and vertical Compression if allowed */
#define VID_CENTRE_CUT_PREF 0x05 /* PanScan with zero vector */
/* firmware data interface codes */
#define DATA_NONE 0x00
#define DATA_FSECTION 0x01
#define DATA_IPMPE 0x02
#define DATA_MPEG_RECORD 0x03
#define DATA_DEBUG_MESSAGE 0x04
#define DATA_COMMON_INTERFACE 0x05
#define DATA_MPEG_PLAY 0x06
#define DATA_BMP_LOAD 0x07
#define DATA_IRCOMMAND 0x08
#define DATA_PIPING 0x09
#define DATA_STREAMING 0x0a
#define DATA_CI_GET 0x0b
#define DATA_CI_PUT 0x0c
#define DATA_MPEG_VIDEO_EVENT 0x0d
#define DATA_PES_RECORD 0x10
#define DATA_PES_PLAY 0x11
#define DATA_TS_RECORD 0x12
#define DATA_TS_PLAY 0x13
/* ancient CI command codes, only two are actually still used
* by the link level CI firmware */
#define CI_CMD_ERROR 0x00
#define CI_CMD_ACK 0x01
#define CI_CMD_SYSTEM_READY 0x02
#define CI_CMD_KEYPRESS 0x03
#define CI_CMD_ON_TUNED 0x04
#define CI_CMD_ON_SWITCH_PROGRAM 0x05
#define CI_CMD_SECTION_ARRIVED 0x06
#define CI_CMD_SECTION_TIMEOUT 0x07
#define CI_CMD_TIME 0x08
#define CI_CMD_ENTER_MENU 0x09
#define CI_CMD_FAST_PSI 0x0a
#define CI_CMD_GET_SLOT_INFO 0x0b
#define CI_MSG_NONE 0x00
#define CI_MSG_CI_INFO 0x01
#define CI_MSG_MENU 0x02
#define CI_MSG_LIST 0x03
#define CI_MSG_TEXT 0x04
#define CI_MSG_REQUEST_INPUT 0x05
#define CI_MSG_INPUT_COMPLETE 0x06
#define CI_MSG_LIST_MORE 0x07
#define CI_MSG_MENU_MORE 0x08
#define CI_MSG_CLOSE_MMI_IMM 0x09
#define CI_MSG_SECTION_REQUEST 0x0a
#define CI_MSG_CLOSE_FILTER 0x0b
#define CI_PSI_COMPLETE 0x0c
#define CI_MODULE_READY 0x0d
#define CI_SWITCH_PRG_REPLY 0x0e
#define CI_MSG_TEXT_MORE 0x0f
#define CI_MSG_CA_PMT 0xe0
#define CI_MSG_ERROR 0xf0
/* base address of the dual ported RAM which serves as communication
* area between PCI bus and av7110,
* as seen by the DEBI bus of the saa7146 */
#define DPRAM_BASE 0x4000
/* boot protocol area */
#define BOOT_STATE (DPRAM_BASE + 0x3F8)
#define BOOT_SIZE (DPRAM_BASE + 0x3FA)
#define BOOT_BASE (DPRAM_BASE + 0x3FC)
#define BOOT_BLOCK (DPRAM_BASE + 0x400)
#define BOOT_MAX_SIZE 0xc00
/* firmware command protocol area */
#define IRQ_STATE (DPRAM_BASE + 0x0F4)
#define IRQ_STATE_EXT (DPRAM_BASE + 0x0F6)
#define MSGSTATE (DPRAM_BASE + 0x0F8)
#define FILT_STATE (DPRAM_BASE + 0x0FA)
#define COMMAND (DPRAM_BASE + 0x0FC)
#define COM_BUFF (DPRAM_BASE + 0x100)
#define COM_BUFF_SIZE 0x20
/* various data buffers */
#define BUFF1_BASE (DPRAM_BASE + 0x120)
#define BUFF1_SIZE 0xE0
#define DATA_BUFF0_BASE (DPRAM_BASE + 0x200)
#define DATA_BUFF0_SIZE 0x0800
#define DATA_BUFF1_BASE (DATA_BUFF0_BASE+DATA_BUFF0_SIZE)
#define DATA_BUFF1_SIZE 0x0800
#define DATA_BUFF2_BASE (DATA_BUFF1_BASE+DATA_BUFF1_SIZE)
#define DATA_BUFF2_SIZE 0x0800
#define DATA_BUFF3_BASE (DATA_BUFF2_BASE+DATA_BUFF2_SIZE)
#define DATA_BUFF3_SIZE 0x0400
#define Reserved (DPRAM_BASE + 0x1E00)
#define Reserved_SIZE 0x1C0
/* firmware status area */
#define STATUS_BASE (DPRAM_BASE + 0x1FC0)
#define STATUS_SCR (STATUS_BASE + 0x00)
#define STATUS_MODES (STATUS_BASE + 0x04)
#define STATUS_LOOPS (STATUS_BASE + 0x08)
#define STATUS_MPEG_WIDTH (STATUS_BASE + 0x0C)
/* ((aspect_ratio & 0xf) << 12) | (height & 0xfff) */
#define STATUS_MPEG_HEIGHT_AR (STATUS_BASE + 0x0E)
/* firmware data protocol area */
#define RX_TYPE (DPRAM_BASE + 0x1FE8)
#define RX_LEN (DPRAM_BASE + 0x1FEA)
#define TX_TYPE (DPRAM_BASE + 0x1FEC)
#define TX_LEN (DPRAM_BASE + 0x1FEE)
#define RX_BUFF (DPRAM_BASE + 0x1FF4)
#define TX_BUFF (DPRAM_BASE + 0x1FF6)
#define HANDSHAKE_REG (DPRAM_BASE + 0x1FF8)
#define COM_IF_LOCK (DPRAM_BASE + 0x1FFA)
#define IRQ_RX (DPRAM_BASE + 0x1FFC)
#define IRQ_TX (DPRAM_BASE + 0x1FFE)
/* used by boot protocol to load firmware into av7110 DRAM */
#define DRAM_START_CODE 0x2e000404
#define DRAM_MAX_CODE_SIZE 0x00100000
/* saa7146 gpio lines */
#define RESET_LINE 2
#define DEBI_DONE_LINE 1
#define ARM_IRQ_LINE 0
extern void av7110_reset_arm(struct av7110 *av7110);
extern int av7110_bootarm(struct av7110 *av7110);
extern void av7110_firmversion(struct av7110 *av7110);
#define FW_CI_LL_SUPPORT(arm_app) ((arm_app) & 0x80000000)
#define FW_VERSION(arm_app) ((arm_app) & 0x0000FFFF)
extern int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...);
extern int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length);
extern int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length);
extern int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len);
extern int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
int request_buf_len, u16 *reply_buf, int reply_buf_len);
extern int av7110_fw_query(struct av7110 *av7110, u16 tag, u16* Buff, s16 length);
/* DEBI (saa7146 data extension bus interface) access */
extern int av7110_debiwrite(struct av7110 *av7110, u32 config,
int addr, u32 val, int count);
extern u32 av7110_debiread(struct av7110 *av7110, u32 config,
int addr, int count);
/* DEBI during interrupt */
/* single word writes */
static inline void iwdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
{
av7110_debiwrite(av7110, config, addr, val, count);
}
/* buffer writes */
static inline void mwdebi(struct av7110 *av7110, u32 config, int addr, char *val, int count)
{
memcpy(av7110->debi_virt, val, count);
av7110_debiwrite(av7110, config, addr, 0, count);
}
static inline u32 irdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
{
u32 res;
res=av7110_debiread(av7110, config, addr, count);
if (count<=4)
memcpy(av7110->debi_virt, (char *) &res, count);
return res;
}
/* DEBI outside interrupts, only for count <= 4! */
static inline void wdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
{
unsigned long flags;
spin_lock_irqsave(&av7110->debilock, flags);
av7110_debiwrite(av7110, config, addr, val, count);
spin_unlock_irqrestore(&av7110->debilock, flags);
}
static inline u32 rdebi(struct av7110 *av7110, u32 config, int addr, u32 val, int count)
{
unsigned long flags;
u32 res;
spin_lock_irqsave(&av7110->debilock, flags);
res=av7110_debiread(av7110, config, addr, count);
spin_unlock_irqrestore(&av7110->debilock, flags);
return res;
}
/* handle mailbox registers of the dual ported RAM */
static inline void ARM_ResetMailBox(struct av7110 *av7110)
{
unsigned long flags;
spin_lock_irqsave(&av7110->debilock, flags);
av7110_debiread(av7110, DEBINOSWAP, IRQ_RX, 2);
av7110_debiwrite(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
spin_unlock_irqrestore(&av7110->debilock, flags);
}
static inline void ARM_ClearMailBox(struct av7110 *av7110)
{
iwdebi(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
}
static inline void ARM_ClearIrq(struct av7110 *av7110)
{
irdebi(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
}
/****************************************************************************
* Firmware commands
****************************************************************************/
static inline int SendDAC(struct av7110 *av7110, u8 addr, u8 data)
{
return av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, AudioDAC, 2, addr, data);
}
static inline void VidMode(struct av7110 *av7110, int mode)
{
av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetVidMode, 1, mode);
}
static int inline vidcom(struct av7110 *av7110, u32 com, u32 arg)
{
return av7110_fw_cmd(av7110, 0x80, 0x02, 4,
(com>>16), (com&0xffff),
(arg>>16), (arg&0xffff));
}
static int inline audcom(struct av7110 *av7110, u32 com)
{
return av7110_fw_cmd(av7110, 0x80, 0x03, 4,
(com>>16), (com&0xffff));
}
static inline void Set22K(struct av7110 *av7110, int state)
{
av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, (state ? ON22K : OFF22K), 0);
}
extern int av7110_diseqc_send(struct av7110 *av7110, int len, u8 *msg, unsigned long burst);
#ifdef CONFIG_DVB_AV7110_OSD
extern int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc);
#endif /* CONFIG_DVB_AV7110_OSD */
#endif /* _AV7110_HW_H_ */
......@@ -20,16 +20,18 @@ void av7110_ipack_reset(struct ipack *p)
}
void av7110_ipack_init(struct ipack *p, int size,
int av7110_ipack_init(struct ipack *p, int size,
void (*func)(u8 *buf, int size, void *priv))
{
if ( !(p->buf = vmalloc(size*sizeof(u8))) ){
printk ("Couldn't allocate memory for ipack\n");
return -ENOMEM;
}
p->size = size;
p->func = func;
p->repack_subids = 0;
av7110_ipack_reset(p);
return 0;
}
......@@ -51,16 +53,15 @@ static void send_ipack(struct ipack *p)
switch ( p->mpeg ){
case 2:
if (p->count < 10) return;
if (p->count < 10)
return;
p->buf[3] = p->cid;
p->buf[4] = (u8)(((p->count-6) & 0xFF00) >> 8);
p->buf[5] = (u8)((p->count-6) & 0x00FF);
p->buf[4] = (u8)(((p->count - 6) & 0xff00) >> 8);
p->buf[5] = (u8)((p->count - 6) & 0x00ff);
if (p->repack_subids && p->cid == PRIVATE_STREAM1){
off = 9+p->buf[8];
streamid = p->buf[off];
if ((streamid & 0xF8) == 0x80){
if ((streamid & 0xf8) == 0x80) {
ai.off = 0;
ac3_off = ((p->buf[off+2] << 8)|
p->buf[off+3]);
......@@ -70,12 +71,10 @@ static void send_ipack(struct ipack *p)
if ( !f ){
nframes = (p->count-off-3-ac3_off)/
ai.framesize + 1;
p->buf[off+2] = (ac3_off >> 8)& 0xFF;
p->buf[off+3] = (ac3_off)& 0xFF;
p->buf[off + 2] = (ac3_off >> 8) & 0xff;
p->buf[off + 3] = (ac3_off) & 0xff;
p->buf[off+1] = nframes;
ac3_off += nframes * ai.framesize -
p->count;
ac3_off += nframes * ai.framesize - p->count;
}
}
}
......@@ -86,24 +85,24 @@ static void send_ipack(struct ipack *p)
p->buf[8] = 0x00;
p->count = 9;
if (p->repack_subids && p->cid == PRIVATE_STREAM1
&& (streamid & 0xF8)==0x80 ){
&& (streamid & 0xf8) == 0x80) {
p->count += 4;
p->buf[9] = streamid;
p->buf[10] = (ac3_off >> 8)& 0xFF;
p->buf[11] = (ac3_off)& 0xFF;
p->buf[10] = (ac3_off >> 8) & 0xff;
p->buf[11] = (ac3_off) & 0xff;
p->buf[12] = 0;
}
break;
case 1:
if (p->count < 8) return;
if (p->count < 8)
return;
p->buf[3] = p->cid;
p->buf[4] = (u8)(((p->count-6) & 0xFF00) >> 8);
p->buf[5] = (u8)((p->count-6) & 0x00FF);
p->buf[4] = (u8)(((p->count - 6) & 0xff00) >> 8);
p->buf[5] = (u8)((p->count - 6) & 0x00ff);
p->func(p->buf, p->count, p->data);
p->buf[6] = 0x0F;
p->buf[6] = 0x0f;
p->count = 7;
break;
}
......@@ -156,15 +155,19 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
switch ( p->found ){
case 0:
case 1:
if (buf[c] == 0x00) p->found++;
else p->found = 0;
if (buf[c] == 0x00)
p->found++;
else
p->found = 0;
c++;
break;
case 2:
if (buf[c] == 0x01) p->found++;
else if (buf[c] == 0) {
if (buf[c] == 0x01)
p->found++;
else if (buf[c] == 0)
p->found = 2;
} else p->found = 0;
else
p->found = 0;
c++;
break;
case 3:
......@@ -179,6 +182,7 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
case DSM_CC_STREAM :
case ISO13522_STREAM:
p->done = 1;
/* fall through */
case PRIVATE_STREAM1:
case VIDEO_STREAM_S ... VIDEO_STREAM_E:
case AUDIO_STREAM_S ... AUDIO_STREAM_E:
......@@ -217,7 +221,8 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
p->flag1 = buf[c];
c++;
p->found++;
if ( (p->flag1 & 0xC0) == 0x80 ) p->mpeg = 2;
if ((p->flag1 & 0xc0) == 0x80)
p->mpeg = 2;
else {
p->hlength = 0;
p->which = 0;
......@@ -242,16 +247,14 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
p->found++;
}
break;
default:
break;
}
}
if (c == count) return count;
if (c == count)
return count;
if (!p->plength) p->plength = MMAX_PLENGTH-6;
if (!p->plength)
p->plength = MMAX_PLENGTH - 6;
if ( p->done || ((p->mpeg == 2 && p->found >= 9) ||
(p->mpeg == 1 && p->found >= 7)) ){
......@@ -278,7 +281,8 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
c++;
p->found++;
}
if (c == count) return count;
if (c == count)
return count;
}
if (p->mpeg == 1 && p->which < 2000) {
......@@ -289,7 +293,7 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
}
while (!p->which && c < count &&
p->check == 0xFF){
p->check == 0xff){
p->check = buf[c];
write_ipack(p, buf+c, 1);
c++;
......@@ -297,9 +301,10 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
p->hlength++;
}
if ( c == count) return count;
if (c == count)
return count;
if ( (p->check & 0xC0) == 0x40 && !p->which){
if ((p->check & 0xc0) == 0x40 && !p->which) {
p->check = buf[c];
write_ipack(p, buf+c, 1);
c++;
......@@ -307,14 +312,16 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
p->hlength++;
p->which = 1;
if ( c == count) return count;
if (c == count)
return count;
p->check = buf[c];
write_ipack(p, buf+c, 1);
c++;
p->found++;
p->hlength++;
p->which = 2;
if ( c == count) return count;
if (c == count)
return count;
}
if (p->which == 1){
......@@ -324,45 +331,42 @@ int av7110_ipack_instant_repack (const u8 *buf, int count, struct ipack *p)
p->found++;
p->hlength++;
p->which = 2;
if ( c == count) return count;
if (c == count)
return count;
}
if ( (p->check & 0x30) && p->check != 0xFF){
p->flag2 = (p->check & 0xF0) << 2;
if ((p->check & 0x30) && p->check != 0xff) {
p->flag2 = (p->check & 0xf0) << 2;
p->pts[0] = p->check;
p->which = 3;
}
if ( c == count) return count;
if (c == count)
return count;
if (p->which > 2){
if ((p->flag2 & PTS_DTS_FLAGS)
== PTS_ONLY){
while (c < count &&
p->which < 7){
p->pts[p->which-2] =
buf[c];
if ((p->flag2 & PTS_DTS_FLAGS) == PTS_ONLY) {
while (c < count && p->which < 7) {
p->pts[p->which - 2] = buf[c];
write_ipack(p,buf+c,1);
c++;
p->found++;
p->which++;
p->hlength++;
}
if ( c == count) return count;
} else if ((p->flag2 & PTS_DTS_FLAGS)
== PTS_DTS){
while (c < count &&
p->which< 12){
if (c == count)
return count;
} else if ((p->flag2 & PTS_DTS_FLAGS) == PTS_DTS) {
while (c < count && p->which < 12) {
if (p->which< 7)
p->pts[p->which
-2] =
buf[c];
p->pts[p->which - 2] = buf[c];
write_ipack(p,buf+c,1);
c++;
p->found++;
p->which++;
p->hlength++;
}
if ( c == count) return count;
if (c == count)
return count;
}
p->which = 2000;
}
......
#ifndef _AV7110_IPACK_H_
#define _AV7110_IPACK_H_
extern void av7110_ipack_init(struct ipack *p, int size,
extern int av7110_ipack_init(struct ipack *p, int size,
void (*func)(u8 *buf, int size, void *priv));
extern void av7110_ipack_reset(struct ipack *p);
......
......@@ -7,6 +7,11 @@
#include "av7110.h"
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
#include "input_fake.h"
#endif
#define UP_TIMEOUT (HZ/4)
static int av7110_ir_debug = 0;
......@@ -51,7 +56,7 @@ static void av7110_emit_keyup (unsigned long data)
}
static struct timer_list keyup_timer = { function: av7110_emit_keyup };
static struct timer_list keyup_timer = { .function = av7110_emit_keyup };
static void av7110_emit_key (u32 ircom)
......@@ -84,8 +89,7 @@ static void av7110_emit_key (u32 ircom)
return;
if (!keycode) {
printk ("%s: unknown key 0x%02x!!\n",
__FUNCTION__, data);
printk ("%s: unknown key 0x%02x!!\n", __FUNCTION__, data);
return;
}
......@@ -144,9 +148,8 @@ static int av7110_ir_write_proc (struct file *file, const char *buffer,
return -EINVAL;
page = (char *)vmalloc(size);
if( NULL == page ) {
if (!page)
return -ENOMEM;
}
if (copy_from_user(page, buffer, size)) {
vfree(page);
......
/*
* av7110_v4l.c: av7110 video4linux interface for DVB and Siemens DVB-C analog module
*
* Copyright (C) 1999-2002 Ralph Metzler
* & Marcus Metzler for convergence integrated media GmbH
*
* originally based on code by:
* Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*
* the project's page is at http://www.linuxtv.org/dvb/
*/
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/timer.h>
#include <linux/poll.h>
#include <linux/byteorder/swabb.h>
#include <linux/smp_lock.h>
#define DEBUG_VARIABLE av7110_debug
extern int av7110_debug;
#include "dvb_i2c.h"
#include "av7110.h"
#include "av7110_hw.h"
#include "av7110_av.h"
#include "dvb_functions.h"
int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val)
{
u8 msg[5] = { dev, reg >> 8, reg & 0xff, val >> 8 , val & 0xff };
struct dvb_i2c_bus *i2c = av7110->i2c_bus;
struct i2c_msg msgs = { .flags = 0, .addr = 0x40, .len = 5, .buf = msg };
if (i2c->xfer(i2c, &msgs, 1) != 1) {
printk("av7110(%d): %s(%u = %u) failed\n",
av7110->dvb_adapter->num, __FUNCTION__, reg, val);
return -EIO;
}
return 0;
}
int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val)
{
u8 msg1[3] = { dev, reg >> 8, reg & 0xff };
u8 msg2[2];
struct dvb_i2c_bus *i2c = av7110->i2c_bus;
struct i2c_msg msgs[2] = {
{ .flags = 0, .addr = 0x40, .len = 3, .buf = msg1 },
{ .flags = I2C_M_RD, .addr = 0x40, .len = 2, .buf = msg2 }
};
if (i2c->xfer(i2c, msgs, 2) != 2) {
printk("av7110(%d): %s(%u) failed\n",
av7110->dvb_adapter->num, __FUNCTION__, reg);
return -EIO;
}
*val = (msg2[0] << 8) | msg2[1];
return 0;
}
static struct v4l2_input inputs[2] = {
{
.index = 0,
.name = "DVB",
.type = V4L2_INPUT_TYPE_CAMERA,
.audioset = 1,
.tuner = 0, /* ignored */
.std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
.status = 0,
}, {
.index = 1,
.name = "Television",
.type = V4L2_INPUT_TYPE_TUNER,
.audioset = 2,
.tuner = 0,
.std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
.status = 0,
}
};
/* for Siemens DVB-C analog module: (taken from ves1820.c) */
static int ves1820_writereg(struct saa7146_dev *dev, u8 reg, u8 data)
{
u8 addr = 0x09;
u8 buf[] = { 0x00, reg, data };
struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = 3 };
DEB_EE(("av7710: dev: %p\n", dev));
if (1 != saa7146_i2c_transfer(dev, &msg, 1, 1))
return -1;
return 0;
}
static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4])
{
struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 };
DEB_EE(("av7710: dev: %p\n", dev));
if (1 != saa7146_i2c_transfer(dev, &msg, 1, 1))
return -1;
return 0;
}
/**
* set up the downconverter frequency divisor for a
* reference clock comparision frequency of 62.5 kHz.
*/
static int tuner_set_tv_freq(struct saa7146_dev *dev, u32 freq)
{
u32 div;
u8 config;
u8 buf[4];
DEB_EE(("av7710: freq: 0x%08x\n", freq));
/* magic number: 614. tuning with the frequency given by v4l2
is always off by 614*62.5 = 38375 kHz...*/
div = freq + 614;
buf[0] = (div >> 8) & 0x7f;
buf[1] = div & 0xff;
buf[2] = 0x8e;
if (freq < (u32) (16 * 168.25))
config = 0xa0;
else if (freq < (u32) (16 * 447.25))
config = 0x90;
else
config = 0x30;
config &= ~0x02;
buf[3] = config;
return tuner_write(dev, 0x61, buf);
}
static struct saa7146_standard analog_standard[];
static struct saa7146_standard dvb_standard[];
static struct saa7146_standard standard[];
static struct v4l2_audio msp3400_v4l2_audio = {
.index = 0,
.name = "Television",
.capability = V4L2_AUDCAP_STEREO
};
int av7110_dvb_c_switch(struct saa7146_fh *fh)
{
struct saa7146_dev *dev = fh->dev;
struct saa7146_vv *vv = dev->vv_data;
struct av7110 *av7110 = (struct av7110*)dev->ext_priv;
u16 adswitch;
u8 band = 0;
int source, sync;
struct saa7146_fh *ov_fh = NULL;
int restart_overlay = 0;
DEB_EE(("av7110: %p\n", av7110));
if (vv->ov_data != NULL) {
ov_fh = vv->ov_data->fh;
saa7146_stop_preview(ov_fh);
restart_overlay = 1;
}
if (0 != av7110->current_input) {
adswitch = 1;
band = 0x68; /* analog band */
source = SAA7146_HPS_SOURCE_PORT_B;
sync = SAA7146_HPS_SYNC_PORT_B;
memcpy(standard, analog_standard, sizeof(struct saa7146_standard) * 2);
DEB_S(("av7110: switching to analog TV\n"));
msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0000); // loudspeaker source
msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0000); // headphone source
msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0000); // SCART 1 source
msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono
msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); // loudspeaker + headphone
msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); // SCART 1 volume
} else {
adswitch = 0;
band = 0x28; /* digital band */
source = SAA7146_HPS_SOURCE_PORT_A;
sync = SAA7146_HPS_SYNC_PORT_A;
memcpy(standard, dvb_standard, sizeof(struct saa7146_standard) * 2);
DEB_S(("av7110: switching DVB mode\n"));
msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source
msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0220); // headphone source
msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0220); // SCART 1 source
msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono
msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone
msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x7f00); // SCART 1 volume
}
/* hmm, this does not do anything!? */
if (av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, ADSwitch, 1, adswitch))
printk("ADSwitch error\n");
if (ves1820_writereg(dev, 0x0f, band))
printk("setting band in demodulator failed.\n");
saa7146_set_hps_source_and_sync(dev, source, sync);
if (restart_overlay)
saa7146_start_preview(ov_fh);
return 0;
}
int av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
{
struct saa7146_dev *dev = fh->dev;
struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
DEB_EE(("saa7146_dev: %p\n", dev));
switch (cmd) {
case VIDIOC_G_TUNER:
{
struct v4l2_tuner *t = arg;
u16 stereo_det;
s8 stereo;
DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));
if (!av7110->has_analog_tuner || t->index != 0)
return -EINVAL;
memset(t, 0, sizeof(*t));
strcpy(t->name, "Television");
t->type = V4L2_TUNER_ANALOG_TV;
t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
t->rangelow = 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
/* FIXME: add the real signal strength here */
t->signal = 0xffff;
t->afc = 0;
// FIXME: standard / stereo detection is still broken
msp_readreg(av7110, MSP_RD_DEM, 0x007e, &stereo_det);
DEB_S(("VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det));
msp_readreg(av7110, MSP_RD_DSP, 0x0018, &stereo_det);
DEB_S(("VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det));
stereo = (s8)(stereo_det >> 8);
if (stereo > 0x10) {
/* stereo */
t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
t->audmode = V4L2_TUNER_MODE_STEREO;
}
else if (stereo < -0x10) {
/* bilingual*/
t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
t->audmode = V4L2_TUNER_MODE_LANG1;
}
else /* mono */
t->rxsubchans = V4L2_TUNER_SUB_MONO;
return 0;
}
case VIDIOC_S_TUNER:
{
struct v4l2_tuner *t = arg;
u16 fm_matrix, src;
DEB_EE(("VIDIOC_S_TUNER: %d\n", t->index));
if (!av7110->has_analog_tuner || av7110->current_input != 1)
return -EINVAL;
switch (t->audmode) {
case V4L2_TUNER_MODE_STEREO:
DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n"));
fm_matrix = 0x3001; // stereo
src = 0x0020;
break;
case V4L2_TUNER_MODE_LANG1:
DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n"));
fm_matrix = 0x3000; // mono
src = 0x0000;
break;
case V4L2_TUNER_MODE_LANG2:
DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n"));
fm_matrix = 0x3000; // mono
src = 0x0010;
break;
default: /* case V4L2_TUNER_MODE_MONO: {*/
DEB_D(("VIDIOC_S_TUNER: TDA9840_SET_MONO\n"));
fm_matrix = 0x3000; // mono
src = 0x0030;
break;
}
msp_writereg(av7110, MSP_WR_DSP, 0x000e, fm_matrix);
msp_writereg(av7110, MSP_WR_DSP, 0x0008, src);
msp_writereg(av7110, MSP_WR_DSP, 0x0009, src);
msp_writereg(av7110, MSP_WR_DSP, 0x000a, src);
return 0;
}
case VIDIOC_G_FREQUENCY:
{
struct v4l2_frequency *f = arg;
DEB_EE(("VIDIOC_G_FREQ: freq:0x%08x.\n", f->frequency));
if (!av7110->has_analog_tuner || av7110->current_input != 1)
return -EINVAL;
memset(f, 0, sizeof(*f));
f->type = V4L2_TUNER_ANALOG_TV;
f->frequency = av7110->current_freq;
return 0;
}
case VIDIOC_S_FREQUENCY:
{
struct v4l2_frequency *f = arg;
DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", f->frequency));
if (!av7110->has_analog_tuner || av7110->current_input != 1)
return -EINVAL;
if (V4L2_TUNER_ANALOG_TV != f->type)
return -EINVAL;
msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0xffe0); // fast mute
msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0xffe0);
/* tune in desired frequency */
tuner_set_tv_freq(dev, f->frequency);
av7110->current_freq = f->frequency;
msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x003f); // start stereo detection
msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x0000);
msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); // loudspeaker + headphone
msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); // SCART 1 volume
return 0;
}
case VIDIOC_ENUMINPUT:
{
struct v4l2_input *i = arg;
DEB_EE(("VIDIOC_ENUMINPUT: %d\n", i->index));
if (av7110->has_analog_tuner ) {
if (i->index < 0 || i->index >= 2)
return -EINVAL;
} else {
if (i->index != 0)
return -EINVAL;
}
memcpy(i, &inputs[i->index], sizeof(struct v4l2_input));
return 0;
}
case VIDIOC_G_INPUT:
{
int *input = (int *)arg;
*input = av7110->current_input;
DEB_EE(("VIDIOC_G_INPUT: %d\n", *input));
return 0;
}
case VIDIOC_S_INPUT:
{
int input = *(int *)arg;
DEB_EE(("VIDIOC_S_INPUT: %d\n", input));
if (!av7110->has_analog_tuner )
return 0;
if (input < 0 || input >= 2)
return -EINVAL;
/* FIXME: switch inputs here */
av7110->current_input = input;
return av7110_dvb_c_switch(fh);
}
case VIDIOC_G_AUDIO:
{
struct v4l2_audio *a = arg;
DEB_EE(("VIDIOC_G_AUDIO: %d\n", a->index));
if (a->index != 0)
return -EINVAL;
memcpy(a, &msp3400_v4l2_audio, sizeof(struct v4l2_audio));
break;
}
case VIDIOC_S_AUDIO:
{
struct v4l2_audio *a = arg;
DEB_EE(("VIDIOC_S_AUDIO: %d\n", a->index));
break;
}
default:
printk("no such ioctl\n");
return -ENOIOCTLCMD;
}
return 0;
}
/****************************************************************************
* INITIALIZATION
****************************************************************************/
struct saa7146_extension_ioctls ioctls[] = {
{ VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE },
{ VIDIOC_G_INPUT, SAA7146_EXCLUSIVE },
{ VIDIOC_S_INPUT, SAA7146_EXCLUSIVE },
{ VIDIOC_G_FREQUENCY, SAA7146_EXCLUSIVE },
{ VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE },
{ VIDIOC_G_TUNER, SAA7146_EXCLUSIVE },
{ VIDIOC_S_TUNER, SAA7146_EXCLUSIVE },
{ VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE },
{ VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE },
{ 0, 0 }
};
static u8 saa7113_init_regs[] = {
0x02, 0xd0,
0x03, 0x23,
0x04, 0x00,
0x05, 0x00,
0x06, 0xe9,
0x07, 0x0d,
0x08, 0x98,
0x09, 0x02,
0x0a, 0x80,
0x0b, 0x40,
0x0c, 0x40,
0x0d, 0x00,
0x0e, 0x01,
0x0f, 0x7c,
0x10, 0x48,
0x11, 0x0c,
0x12, 0x8b,
0x13, 0x1a,
0x14, 0x00,
0x15, 0x00,
0x16, 0x00,
0x17, 0x00,
0x18, 0x00,
0x19, 0x00,
0x1a, 0x00,
0x1b, 0x00,
0x1c, 0x00,
0x1d, 0x00,
0x1e, 0x00,
0x41, 0x77,
0x42, 0x77,
0x43, 0x77,
0x44, 0x77,
0x45, 0x77,
0x46, 0x77,
0x47, 0x77,
0x48, 0x77,
0x49, 0x77,
0x4a, 0x77,
0x4b, 0x77,
0x4c, 0x77,
0x4d, 0x77,
0x4e, 0x77,
0x4f, 0x77,
0x50, 0x77,
0x51, 0x77,
0x52, 0x77,
0x53, 0x77,
0x54, 0x77,
0x55, 0x77,
0x56, 0x77,
0x57, 0xff,
0xff
};
static struct saa7146_ext_vv av7110_vv_data_st;
static struct saa7146_ext_vv av7110_vv_data_c;
int av7110_init_analog_module(struct av7110 *av7110)
{
u16 version1, version2;
if (i2c_writereg(av7110, 0x80, 0x0, 0x80) != 1
|| i2c_writereg(av7110, 0x80, 0x0, 0) != 1)
return -ENODEV;
printk("av7110(%d): DVB-C analog module detected, initializing MSP3400\n",
av7110->dvb_adapter->num);
av7110->adac_type = DVB_ADAC_MSP;
dvb_delay(100); // the probing above resets the msp...
msp_readreg(av7110, MSP_RD_DSP, 0x001e, &version1);
msp_readreg(av7110, MSP_RD_DSP, 0x001f, &version2);
printk("av7110(%d): MSP3400 version 0x%04x 0x%04x\n",
av7110->dvb_adapter->num, version1, version2);
msp_writereg(av7110, MSP_WR_DSP, 0x0013, 0x0c00);
msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone
msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source
msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0220); // headphone source
msp_writereg(av7110, MSP_WR_DSP, 0x0004, 0x7f00); // loudspeaker volume
msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0220); // SCART 1 source
msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x7f00); // SCART 1 volume
msp_writereg(av7110, MSP_WR_DSP, 0x000d, 0x4800); // prescale SCART
if (i2c_writereg(av7110, 0x48, 0x01, 0x00)!=1) {
INFO(("saa7113 not accessible.\n"));
} else {
u8 *i = saa7113_init_regs;
av7110->has_analog_tuner = 1;
/* init the saa7113 */
while (*i != 0xff) {
if (i2c_writereg(av7110, 0x48, i[0], i[1]) != 1) {
printk("av7110(%d): saa7113 initialization failed",
av7110->dvb_adapter->num);
break;
}
i += 2;
}
/* setup msp for analog sound: B/G Dual-FM */
msp_writereg(av7110, MSP_WR_DEM, 0x00bb, 0x02d0); // AD_CV
msp_writereg(av7110, MSP_WR_DEM, 0x0001, 3); // FIR1
msp_writereg(av7110, MSP_WR_DEM, 0x0001, 18); // FIR1
msp_writereg(av7110, MSP_WR_DEM, 0x0001, 27); // FIR1
msp_writereg(av7110, MSP_WR_DEM, 0x0001, 48); // FIR1
msp_writereg(av7110, MSP_WR_DEM, 0x0001, 66); // FIR1
msp_writereg(av7110, MSP_WR_DEM, 0x0001, 72); // FIR1
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 4); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 64); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 0); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 3); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 18); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 27); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 48); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 66); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0005, 72); // FIR2
msp_writereg(av7110, MSP_WR_DEM, 0x0083, 0xa000); // MODE_REG
msp_writereg(av7110, MSP_WR_DEM, 0x0093, 0x00aa); // DCO1_LO 5.74MHz
msp_writereg(av7110, MSP_WR_DEM, 0x009b, 0x04fc); // DCO1_HI
msp_writereg(av7110, MSP_WR_DEM, 0x00a3, 0x038e); // DCO2_LO 5.5MHz
msp_writereg(av7110, MSP_WR_DEM, 0x00ab, 0x04c6); // DCO2_HI
msp_writereg(av7110, MSP_WR_DEM, 0x0056, 0); // LOAD_REG 1/2
}
memcpy(standard, dvb_standard, sizeof(struct saa7146_standard) * 2);
/* set dd1 stream a & b */
saa7146_write(av7110->dev, DD1_STREAM_B, 0x00000000);
saa7146_write(av7110->dev, DD1_INIT, 0x03000700);
saa7146_write(av7110->dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
return 0;
}
int av7110_init_v4l(struct av7110 *av7110)
{
struct saa7146_dev* dev = av7110->dev;
int ret;
/* special case DVB-C: these cards have an analog tuner
plus need some special handling, so we have separate
saa7146_ext_vv data for these... */
if (av7110->has_analog_tuner)
ret = saa7146_vv_init(dev, &av7110_vv_data_c);
else
ret = saa7146_vv_init(dev, &av7110_vv_data_st);
if (ret) {
ERR(("cannot init capture device. skipping.\n"));
return -ENODEV;
}
if (saa7146_register_device(&av7110->v4l_dev, dev, "av7110", VFL_TYPE_GRABBER)) {
ERR(("cannot register capture device. skipping.\n"));
saa7146_vv_release(dev);
return -ENODEV;
}
if (av7110->has_analog_tuner) {
if (saa7146_register_device(&av7110->vbi_dev, dev, "av7110", VFL_TYPE_VBI)) {
ERR(("cannot register vbi v4l2 device. skipping.\n"));
} else
/* we use this to remember that this dvb-c card can do vbi */
av7110->has_analog_tuner = 2;
}
return 0;
}
int av7110_exit_v4l(struct av7110 *av7110)
{
saa7146_unregister_device(&av7110->v4l_dev, av7110->dev);
if (2 == av7110->has_analog_tuner)
saa7146_unregister_device(&av7110->vbi_dev, av7110->dev);
return 0;
}
/* FIXME: these values are experimental values that look better than the
values from the latest "official" driver -- at least for me... (MiHu) */
static struct saa7146_standard standard[] = {
{
.name = "PAL", .id = V4L2_STD_PAL_BG,
.v_offset = 0x15, .v_field = 288, .v_calc = 576,
.h_offset = 0x4a, .h_pixels = 708, .h_calc = 709,
.v_max_out = 576, .h_max_out = 768,
}, {
.name = "NTSC", .id = V4L2_STD_NTSC,
.v_offset = 0x10, .v_field = 244, .v_calc = 480,
.h_offset = 0x40, .h_pixels = 708, .h_calc = 709,
.v_max_out = 480, .h_max_out = 640,
}
};
static struct saa7146_standard analog_standard[] = {
{
.name = "PAL", .id = V4L2_STD_PAL_BG,
.v_offset = 0x18 /* 0 */ , .v_field = 288, .v_calc = 576,
.h_offset = 0x08, .h_pixels = 708, .h_calc = 709,
.v_max_out = 576, .h_max_out = 768,
}, {
.name = "NTSC", .id = V4L2_STD_NTSC,
.v_offset = 0x10, .v_field = 244, .v_calc = 480,
.h_offset = 0x40, .h_pixels = 708, .h_calc = 709,
.v_max_out = 480, .h_max_out = 640,
}
};
static struct saa7146_standard dvb_standard[] = {
{
.name = "PAL", .id = V4L2_STD_PAL_BG,
.v_offset = 0x14, .v_field = 288, .v_calc = 576,
.h_offset = 0x4a, .h_pixels = 708, .h_calc = 709,
.v_max_out = 576, .h_max_out = 768,
}, {
.name = "NTSC", .id = V4L2_STD_NTSC,
.v_offset = 0x10, .v_field = 244, .v_calc = 480,
.h_offset = 0x40, .h_pixels = 708, .h_calc = 709,
.v_max_out = 480, .h_max_out = 640,
}
};
static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
{
struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
if (std->id == V4L2_STD_PAL) {
av7110->vidmode = VIDEO_MODE_PAL;
av7110_set_vidmode(av7110, av7110->vidmode);
}
else if (std->id == V4L2_STD_NTSC) {
av7110->vidmode = VIDEO_MODE_NTSC;
av7110_set_vidmode(av7110, av7110->vidmode);
}
else
return -1;
return 0;
}
static struct saa7146_ext_vv av7110_vv_data_st = {
.inputs = 1,
.audios = 1,
.capabilities = 0,
.flags = 0,
.stds = &standard[0],
.num_stds = sizeof(standard) / sizeof(struct saa7146_standard),
.std_callback = &std_callback,
.ioctls = &ioctls[0],
.ioctl = av7110_ioctl,
};
static struct saa7146_ext_vv av7110_vv_data_c = {
.inputs = 1,
.audios = 1,
.capabilities = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE,
.flags = SAA7146_USE_PORT_B_FOR_VBI,
.stds = &standard[0],
.num_stds = sizeof(standard) / sizeof(struct saa7146_standard),
.std_callback = &std_callback,
.ioctls = &ioctls[0],
.ioctl = av7110_ioctl,
};
......@@ -32,6 +32,7 @@
#include "budget.h"
#include "av7110.h"
#include "av7110_hw.h"
#define budget_patch budget
......@@ -46,7 +47,7 @@ static struct pci_device_id pci_tbl[] = {
}
};
static int wdebi(struct budget_patch *budget, u32 config, int addr, u32 val, int count)
static int budget_wdebi(struct budget_patch *budget, u32 config, int addr, u32 val, int count)
{
struct saa7146_dev *dev=budget->dev;
......@@ -66,21 +67,21 @@ static int wdebi(struct budget_patch *budget, u32 config, int addr, u32 val, int
}
static int SOutCommand(struct budget_patch *budget, u16* buf, int length)
static int budget_av7110_send_fw_cmd(struct budget_patch *budget, u16* buf, int length)
{
int i;
DEB_EE(("budget: %p\n", budget));
for (i = 2; i < length; i++)
wdebi(budget, DEBINOSWAP, COMMAND + 2*i, (u32) buf[i], 2);
budget_wdebi(budget, DEBINOSWAP, COMMAND + 2*i, (u32) buf[i], 2);
if (length)
wdebi(budget, DEBINOSWAP, COMMAND + 2, (u32) buf[1], 2);
budget_wdebi(budget, DEBINOSWAP, COMMAND + 2, (u32) buf[1], 2);
else
wdebi(budget, DEBINOSWAP, COMMAND + 2, 0, 2);
budget_wdebi(budget, DEBINOSWAP, COMMAND + 2, 0, 2);
wdebi(budget, DEBINOSWAP, COMMAND, (u32) buf[0], 2);
budget_wdebi(budget, DEBINOSWAP, COMMAND, (u32) buf[0], 2);
return 0;
}
......@@ -90,7 +91,7 @@ static void av7110_set22k(struct budget_patch *budget, int state)
u16 buf[2] = {( COMTYPE_AUDIODAC << 8) | (state ? ON22K : OFF22K), 0};
DEB_EE(("budget: %p\n", budget));
SOutCommand(budget, buf, 2);
budget_av7110_send_fw_cmd(budget, buf, 2);
}
......@@ -116,7 +117,7 @@ static int av7110_send_diseqc_msg(struct budget_patch *budget, int len, u8 *msg,
for (i=0; i<len; i++)
buf[i+4]=msg[i];
SOutCommand(budget, buf, 18);
budget_av7110_send_fw_cmd(budget, buf, 18);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment