/* * * $Id$ * * Copyright (C) 2005 Mike Isely * * 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 * * 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 * */ #ifndef __PVRUSB2_HDW_INTERNAL_H #define __PVRUSB2_HDW_INTERNAL_H /* This header sets up all the internal structures and definitions needed to track and coordinate the driver's interaction with the hardware. ONLY source files which actually implement part of that whole circus should be including this header. Higher levels, like the external layers to the various public APIs (V4L, sysfs, etc) should NOT ever include this private, internal header. This means that pvrusb2-hdw, pvrusb2-encoder, etc will include this, but pvrusb2-v4l should not. */ #include "compat.h" #include #include #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) #include #include #else #include #endif #include "pvrusb2-hdw.h" #include "pvrusb2-io.h" /* Definition of state variables that we can inspect & change. Numbers are assigned from zero counting up with no gaps. */ #define PVR2_CID_BRIGHTNESS 0 #define PVR2_CID_CONTRAST 1 #define PVR2_CID_SATURATION 2 #define PVR2_CID_HUE 3 #define PVR2_CID_VOLUME 4 #define PVR2_CID_BALANCE 5 #define PVR2_CID_BASS 6 #define PVR2_CID_TREBLE 7 #define PVR2_CID_MUTE 8 #define PVR2_CID_SRATE 9 #define PVR2_CID_AUDIOBITRATE 10 #define PVR2_CID_AUDIOCRC 11 #define PVR2_CID_AUDIOEMPHASIS 12 #define PVR2_CID_VBR 13 #define PVR2_CID_AVERAGEVIDEOBITRATE 14 #define PVR2_CID_PEAKVIDEOBITRATE 15 #define PVR2_CID_STDAVAIL 16 // V4L2 video standard bit mask #define PVR2_CID_INPUT 17 #define PVR2_CID_AUDIOMODE 18 // V4L2 standard audio mode enum #define PVR2_CID_FREQUENCY 19 // Units of Hz #define PVR2_CID_HRES 20 #define PVR2_CID_VRES 21 #define PVR2_CID_INTERLACE 22 #define PVR2_CID_AUDIOLAYER 23 #define PVR2_CID_CHANNEL 24 #define PVR2_CID_CHANPROG_ID 25 #define PVR2_CID_CHANPROG_FREQ 26 #define PVR2_CID_SIGNAL_PRESENT 27 #define PVR2_CID_STREAMING_ENABLED 28 #define PVR2_CID_HSM 29 #define PVR2_CID_SUBSYS_MASK 30 #define PVR2_CID_SUBSYS_STREAM_MASK 31 #define PVR2_CID_STDCUR 32 // V4L2 video standard bit mask #define PVR2_CID_STDNAME 33 // Enumeration of available standards /* Legal values for the SRATE state variable */ #define PVR2_CVAL_SRATE_48 0 #define PVR2_CVAL_SRATE_44_1 1 #define PVR2_CVAL_SRATE_MIN PVR2_CVAL_SRATE_48 #define PVR2_CVAL_SRATE_MAX PVR2_CVAL_SRATE_44_1 /* Legal values for the AUDIOBITRATE state variable */ #define PVR2_CVAL_AUDIOBITRATE_384 0 #define PVR2_CVAL_AUDIOBITRATE_320 1 #define PVR2_CVAL_AUDIOBITRATE_256 2 #define PVR2_CVAL_AUDIOBITRATE_224 3 #define PVR2_CVAL_AUDIOBITRATE_192 4 #define PVR2_CVAL_AUDIOBITRATE_160 5 #define PVR2_CVAL_AUDIOBITRATE_128 6 #define PVR2_CVAL_AUDIOBITRATE_112 7 #define PVR2_CVAL_AUDIOBITRATE_96 8 #define PVR2_CVAL_AUDIOBITRATE_80 9 #define PVR2_CVAL_AUDIOBITRATE_64 10 #define PVR2_CVAL_AUDIOBITRATE_56 11 #define PVR2_CVAL_AUDIOBITRATE_48 12 #define PVR2_CVAL_AUDIOBITRATE_32 13 #define PVR2_CVAL_AUDIOBITRATE_VBR 14 #define PVR2_CVAL_AUDIOBITRATE_MIN PVR2_CVAL_AUDIOBITRATE_384 #define PVR2_CVAL_AUDIOBITRATE_MAX PVR2_CVAL_AUDIOBITRATE_VBR /* Legal values for the AUDIOEMPHASIS state variable */ #define PVR2_CVAL_AUDIOEMPHASIS_NONE 0 #define PVR2_CVAL_AUDIOEMPHASIS_50_15 1 #define PVR2_CVAL_AUDIOEMPHASIS_CCITT 2 #define PVR2_CVAL_AUDIOEMPHASIS_MIN PVR2_CVAL_AUDIOEMPHASIS_NONE #define PVR2_CVAL_AUDIOEMPHASIS_MAX PVR2_CVAL_AUDIOEMPHASIS_CCITT /* Legal values for PVR2_CID_HSM */ #define PVR2_CVAL_HSM_FAIL 0 #define PVR2_CVAL_HSM_FULL 1 #define PVR2_CVAL_HSM_HIGH 2 #define PVR2_CVAL_HSM_MIN PVR2_CVAL_HSM_FAIL #define PVR2_CVAL_HSM_MAX PVR2_CVAL_HSM_HIGH #define PVR2_VID_ENDPOINT 0x84 #define PVR2_UNK_ENDPOINT 0x86 /* maybe raw yuv ? */ #define PVR2_VBI_ENDPOINT 0x88 #define PVR2_CTL_BUFFSIZE 64 #define FREQTABLE_SIZE 500 #define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0) #define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0) struct pvr2_decoder; struct pvr2_ctl_def; struct pvr2_ctrl; typedef int (*pvr2_ctl_set_func)(struct pvr2_ctrl *,int val); typedef int (*pvr2_ctl_get_func)(struct pvr2_ctrl *); struct pvr2_ctl_def { int id; const char *name; const char *desc; pvr2_ctl_set_func set_func; pvr2_ctl_get_func get_func; int mask_value; int max_value; int min_value; int skip_init; int default_value; int is_valid; const char **value_defs_ptr; unsigned int value_defs_count; }; struct pvr2_ctrl { struct pvr2_hdw *hdw; const struct pvr2_ctl_def *ctl_def; int is_valid; int value; int dirty; }; struct pvr2_audio_stat { void *ctxt; void (*detach)(void *); int (*status)(void *); }; struct pvr2_decoder_ctrl { void *ctxt; void (*detach)(void *); void (*enable)(void *,int); int (*tuned)(void *); void (*force_reset)(void *); }; #define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */ #define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */ #define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */ #define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */ #define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\ PVR2_I2C_PEND_CLIENT |\ PVR2_I2C_PEND_REFRESH |\ PVR2_I2C_PEND_STALE) /* Disposition of firmware1 loading situation */ #define FW1_STATE_UNKNOWN 0 #define FW1_STATE_MISSING 1 #define FW1_STATE_FAILED 2 #define FW1_STATE_RELOAD 3 #define FW1_STATE_OK 4 /* Known major hardware variants, keyed from device ID */ #define PVR2_HDW_TYPE_29XXX 0 #define PVR2_HDW_TYPE_24XXX 1 /* This structure contains all state data directly needed to manipulate the hardware (as opposed to complying with a kernel interface) */ struct pvr2_hdw { /* Underlying USB device handle */ struct usb_device *usb_dev; struct usb_interface *usb_intf; /* Device type, one of PVR2_HDW_TYPE_xxxxx */ unsigned int hdw_type; /* Video spigot */ struct pvr2_stream *vid_stream; /* Mutex for all hardware state control */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) struct mutex big_lock_mutex; #else struct semaphore big_lock_mutex; #endif int big_lock_held; /* For debugging */ void (*poll_trigger_func)(void *); void *poll_trigger_data; char name[32]; /* I2C stuff */ struct i2c_adapter i2c_adap; struct i2c_algorithm i2c_algo; int i2c_linked; unsigned int i2c_pend_types; /* Which types of update are needed */ unsigned long i2c_pend_mask; /* Change bits we need to scan */ unsigned long i2c_stale_mask; /* Pending broadcast change bits */ unsigned long i2c_active_mask; /* All change bits currently in use */ struct list_head i2c_clients; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) struct mutex i2c_list_lock; #else struct semaphore i2c_list_lock; #endif /* Frequency table */ unsigned int freqTable[FREQTABLE_SIZE]; /* Stuff for handling low level control interaction with device */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) struct mutex ctl_lock_mutex; #else struct semaphore ctl_lock_mutex; #endif int ctl_lock_held; /* For debugging */ struct urb *ctl_write_urb; struct urb *ctl_read_urb; unsigned char *ctl_write_buffer; unsigned char *ctl_read_buffer; volatile int ctl_write_pend_flag; volatile int ctl_read_pend_flag; volatile int ctl_timeout_flag; struct completion ctl_done; unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE]; int cmd_debug_state; // Low level command debugging info unsigned char cmd_debug_code; // unsigned int cmd_debug_write_len; // unsigned int cmd_debug_read_len; // int flag_ok; // device in known good state int flag_disconnected; // flag_ok == 0 due to disconnect int flag_init_ok; // true if structure is fully initialized int flag_streaming_enabled; // true if streaming should be on int fw1_state; // current situation with fw1 int flag_decoder_is_tuned; struct pvr2_decoder_ctrl *decoder_ctrl; // CPU firmware info (used to help find / save firmware data) char *fw_buffer; unsigned int fw_size; // Which subsystem pieces have been enabled / configured unsigned long subsys_enabled_mask; // Which subsystems are manipulated to enable streaming unsigned long subsys_stream_mask; // True if there is a request to trigger logging of state in each // module. int log_requested; /* Tuner / frequency control stuff */ unsigned int tuner_type; int tuner_updated; v4l2_std_id video_std_avail; v4l2_std_id video_std_cur; struct pvr2_ctl_def video_std_enum; struct v4l2_standard *std_defs; const char **video_std_names; unsigned int std_cnt; int std_id; int unit_number; /* ID for driver instance */ unsigned long serial_number; /* ID for hardware itself */ /* Minor number used by v4l logic (yes, this is a hack, as there should be no v4l junk here). Probably a better way to do this. */ int v4l_minor_number; /* Location of eeprom or a negative number if none */ int eeprom_addr; enum pvr2_config config; /* Information about what audio signal we're hearing */ int flag_stereo; int flag_bilingual; struct pvr2_audio_stat *audio_stat; /* Every last bit of controllable state */ struct pvr2_ctrl *controls; }; int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw); int pvr2_ctrl_internal_set_value(struct pvr2_ctrl *cptr,int val); int pvr2_ctrl_internal_get_value(struct pvr2_ctrl *cptr); int pvr2_hdw_internal_set_stdenum_cur(struct pvr2_hdw *hdw,int val); void pvr2_hdw_internal_set_std_cur(struct pvr2_hdw *hdw,int msk); void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw,int msk); #endif /* __PVRUSB2_HDW_INTERNAL_H */ /* Stuff for Emacs to see, in order to encourage consistent editing style: *** Local Variables: *** *** mode: c *** *** fill-column: 75 *** *** tab-width: 8 *** *** c-basic-offset: 8 *** *** End: *** */