]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
V4L/DVB (7321): pvrusb2: Rework context handling and initialization
[linux-2.6-omap-h63xx.git] / drivers / media / video / pvrusb2 / pvrusb2-hdw-internal.h
index 0d6dc33ca32046db2e34cd6aef0f7502af2af968..c725495826ceb895c3c9ab914c22a6e664e3ff85 100644 (file)
 
 */
 
-#include <linux/config.h>
 #include <linux/videodev2.h>
 #include <linux/i2c.h>
+#include <linux/workqueue.h>
 #include <linux/mutex.h>
 #include "pvrusb2-hdw.h"
 #include "pvrusb2-io.h"
 #include <media/cx2341x.h>
-
-/* Legal values for the SRATE state variable */
-#define PVR2_CVAL_SRATE_48 0
-#define PVR2_CVAL_SRATE_44_1 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
-
-/* 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
+#include "pvrusb2-devattr.h"
 
 /* Legal values for PVR2_CID_HSM */
 #define PVR2_CVAL_HSM_FAIL 0
@@ -87,6 +62,7 @@ struct pvr2_decoder;
 
 typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *);
 typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *);
+typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int);
 typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *);
 typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val);
 typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val,
@@ -107,7 +83,10 @@ struct pvr2_ctl_info {
 
        /* Control's implementation */
        pvr2_ctlf_get_value get_value;      /* Get its value */
+       pvr2_ctlf_get_value get_min_value;  /* Get minimum allowed value */
+       pvr2_ctlf_get_value get_max_value;  /* Get maximum allowed value */
        pvr2_ctlf_set_value set_value;      /* Set its value */
+       pvr2_ctlf_check_value check_value;  /* Check that value is valid */
        pvr2_ctlf_val_to_sym val_to_sym;    /* Custom convert value->symbol */
        pvr2_ctlf_sym_to_val sym_to_val;    /* Custom convert symbol->value */
        pvr2_ctlf_is_dirty is_dirty;        /* Return true if dirty */
@@ -160,17 +139,10 @@ struct pvr2_ctrl {
 };
 
 
-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 *);
 };
 
@@ -191,11 +163,10 @@ struct pvr2_decoder_ctrl {
 #define FW1_STATE_RELOAD 3
 #define FW1_STATE_OK 4
 
-/* Known major hardware variants, keyed from device ID */
-#define PVR2_HDW_TYPE_29XXX 0
-#ifdef CONFIG_VIDEO_PVRUSB2_24XXX
-#define PVR2_HDW_TYPE_24XXX 1
-#endif
+/* What state the device is in if it is a hybrid */
+#define PVR2_PATHWAY_UNKNOWN 0
+#define PVR2_PATHWAY_ANALOG 1
+#define PVR2_PATHWAY_DIGITAL 2
 
 typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
 #define PVR2_I2C_FUNC_CNT 128
@@ -208,8 +179,14 @@ struct pvr2_hdw {
        struct usb_device *usb_dev;
        struct usb_interface *usb_intf;
 
-       /* Device type, one of PVR2_HDW_TYPE_xxxxx */
-       unsigned int hdw_type;
+       /* Device description, anything that must adjust behavior based on
+          device specific info will use information held here. */
+       const struct pvr2_device_desc *hdw_desc;
+
+       /* Kernel worker thread handling */
+       struct workqueue_struct *workqueue;
+       struct work_struct workpoll;     /* Update driver state */
+       struct work_struct worki2csync;  /* Update i2c clients */
 
        /* Video spigot */
        struct pvr2_stream *vid_stream;
@@ -218,9 +195,6 @@ struct pvr2_hdw {
        struct mutex big_lock_mutex;
        int big_lock_held;  /* For debugging */
 
-       void (*poll_trigger_func)(void *);
-       void *poll_trigger_data;
-
        char name[32];
 
        /* I2C stuff */
@@ -239,7 +213,6 @@ struct pvr2_hdw {
        /* Frequency table */
        unsigned int freqTable[FREQTABLE_SIZE];
        unsigned int freqProgSlot;
-       unsigned int freqSlot;
 
        /* Stuff for handling low level control interaction with device */
        struct mutex ctl_lock_mutex;
@@ -248,9 +221,9 @@ struct pvr2_hdw {
        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;
+       int ctl_write_pend_flag;
+       int ctl_read_pend_flag;
+       int ctl_timeout_flag;
        struct completion ctl_done;
        unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE];
        int cmd_debug_state;               // Low level command debugging info
@@ -258,25 +231,60 @@ struct pvr2_hdw {
        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;
+       /* Bits of state that describe what is going on with various parts
+          of the driver. */
+       int state_pathway_ok;         /* Pathway config is ok */
+       int state_encoder_ok;         /* Encoder is operational */
+       int state_encoder_run;        /* Encoder is running */
+       int state_encoder_config;     /* Encoder is configured */
+       int state_encoder_waitok;     /* Encoder pre-wait done */
+       int state_decoder_run;        /* Decoder is running */
+       int state_usbstream_run;      /* FX2 is streaming */
+       int state_decoder_quiescent;  /* Decoder idle for > 50msec */
+       int state_pipeline_config;    /* Pipeline is configured */
+       int state_pipeline_req;       /* Somebody wants to stream */
+       int state_pipeline_pause;     /* Pipeline must be paused */
+       int state_pipeline_idle;      /* Pipeline not running */
+
+       /* This is the master state of the driver.  It is the combined
+          result of other bits of state.  Examining this will indicate the
+          overall state of the driver.  Values here are one of
+          PVR2_STATE_xxxx */
+       unsigned int master_state;
+
+       /* True if device led is currently on */
+       int led_on;
+
+       /* True if states must be re-evaluated */
+       int state_stale;
+
+       void (*state_func)(void *);
+       void *state_data;
+
+       /* Timer for measuring decoder settling time */
+       struct timer_list quiescent_timer;
+
+       /* Timer for measuring encoder pre-wait time */
+       struct timer_list encoder_wait_timer;
+
+       /* Place to block while waiting for state changes */
+       wait_queue_head_t state_wait_data;
+
+
+       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 fw1_state;          /* current situation with fw1 */
+       int pathway_state;      /* one of PVR2_PATHWAY_xxx */
+       int flag_decoder_missed;/* We've noticed missing decoder */
+       int flag_tripped;       /* Indicates overall failure to start */
 
        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;
+       int fw_cpu_flag; /* True if we are dealing with the CPU */
 
        // True if there is a request to trigger logging of state in each
        // module.
@@ -285,9 +293,17 @@ struct pvr2_hdw {
        /* Tuner / frequency control stuff */
        unsigned int tuner_type;
        int tuner_updated;
-       unsigned int freqVal;
+       unsigned int freqValTelevision;  /* Current freq for tv mode */
+       unsigned int freqValRadio;       /* Current freq for radio mode */
+       unsigned int freqSlotTelevision; /* Current slot for tv mode */
+       unsigned int freqSlotRadio;      /* Current slot for radio mode */
+       unsigned int freqSelector;       /* 0=radio 1=television */
        int freqDirty;
 
+       /* Current tuner info - this information is polled from the I2C bus */
+       struct v4l2_tuner tuner_signal_info;
+       int tuner_signal_stale;
+
        /* Video standard handling */
        v4l2_std_id std_mask_eeprom; // Hardware supported selections
        v4l2_std_id std_mask_avail;  // Which standards we may select from
@@ -308,25 +324,30 @@ struct pvr2_hdw {
        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;
+       char bus_info[32]; /* Bus location info */
+
+       /* Minor numbers 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_video;
+       int v4l_minor_number_vbi;
+       int v4l_minor_number_radio;
+
+       /* Bit mask of PVR2_CVAL_INPUT choices which are valid */
+       unsigned int input_avail_mask;
 
        /* 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;
+       enum pvr2_config active_stream_type;
+       enum pvr2_config desired_stream_type;
 
        /* Control state needed for cx2341x module */
        struct cx2341x_mpeg_params enc_cur_state;
        struct cx2341x_mpeg_params enc_ctl_state;
        /* True if an encoder attribute has changed */
        int enc_stale;
+       /* True if an unsafe encoder attribute has changed */
+       int enc_unsafe_stale;
        /* True if enc_cur_state is valid */
        int enc_cur_valid;
 
@@ -354,6 +375,10 @@ struct pvr2_hdw {
        unsigned int control_cnt;
 };
 
+/* This function gets the current frequency */
+unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
+void pvr2_hdw_set_decoder(struct pvr2_hdw *,struct pvr2_decoder_ctrl *);
+
 #endif /* __PVRUSB2_HDW_INTERNAL_H */
 
 /*