Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *
0004  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
0005  */
0006 #ifndef __PVRUSB2_HDW_INTERNAL_H
0007 #define __PVRUSB2_HDW_INTERNAL_H
0008 
0009 /*
0010 
0011   This header sets up all the internal structures and definitions needed to
0012   track and coordinate the driver's interaction with the hardware.  ONLY
0013   source files which actually implement part of that whole circus should be
0014   including this header.  Higher levels, like the external layers to the
0015   various public APIs (V4L, sysfs, etc) should NOT ever include this
0016   private, internal header.  This means that pvrusb2-hdw, pvrusb2-encoder,
0017   etc will include this, but pvrusb2-v4l should not.
0018 
0019 */
0020 
0021 #include <linux/videodev2.h>
0022 #include <linux/i2c.h>
0023 #include <linux/workqueue.h>
0024 #include <linux/mutex.h>
0025 #include "pvrusb2-hdw.h"
0026 #include "pvrusb2-io.h"
0027 #include <media/v4l2-device.h>
0028 #include <media/drv-intf/cx2341x.h>
0029 #include <media/i2c/ir-kbd-i2c.h>
0030 #include "pvrusb2-devattr.h"
0031 
0032 /* Legal values for PVR2_CID_HSM */
0033 #define PVR2_CVAL_HSM_FAIL 0
0034 #define PVR2_CVAL_HSM_FULL 1
0035 #define PVR2_CVAL_HSM_HIGH 2
0036 
0037 #define PVR2_VID_ENDPOINT        0x84
0038 #define PVR2_UNK_ENDPOINT        0x86    /* maybe raw yuv ? */
0039 #define PVR2_VBI_ENDPOINT        0x88
0040 
0041 #define PVR2_CTL_BUFFSIZE        64
0042 
0043 #define FREQTABLE_SIZE 500
0044 
0045 #define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0)
0046 #define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0)
0047 
0048 typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *);
0049 typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *);
0050 typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int);
0051 typedef int (*pvr2_ctlf_get_value)(struct pvr2_ctrl *,int *);
0052 typedef int (*pvr2_ctlf_set_value)(struct pvr2_ctrl *,int msk,int val);
0053 typedef int (*pvr2_ctlf_val_to_sym)(struct pvr2_ctrl *,int msk,int val,
0054                     char *,unsigned int,unsigned int *);
0055 typedef int (*pvr2_ctlf_sym_to_val)(struct pvr2_ctrl *,
0056                     const char *,unsigned int,
0057                     int *mskp,int *valp);
0058 typedef unsigned int (*pvr2_ctlf_get_v4lflags)(struct pvr2_ctrl *);
0059 
0060 /* This structure describes a specific control.  A table of these is set up
0061    in pvrusb2-hdw.c. */
0062 struct pvr2_ctl_info {
0063     /* Control's name suitable for use as an identifier */
0064     const char *name;
0065 
0066     /* Short description of control */
0067     const char *desc;
0068 
0069     /* Control's implementation */
0070     pvr2_ctlf_get_value get_value;      /* Get its value */
0071     pvr2_ctlf_get_value get_def_value;  /* Get its default value */
0072     pvr2_ctlf_get_value get_min_value;  /* Get minimum allowed value */
0073     pvr2_ctlf_get_value get_max_value;  /* Get maximum allowed value */
0074     pvr2_ctlf_set_value set_value;      /* Set its value */
0075     pvr2_ctlf_check_value check_value;  /* Check that value is valid */
0076     pvr2_ctlf_val_to_sym val_to_sym;    /* Custom convert value->symbol */
0077     pvr2_ctlf_sym_to_val sym_to_val;    /* Custom convert symbol->value */
0078     pvr2_ctlf_is_dirty is_dirty;        /* Return true if dirty */
0079     pvr2_ctlf_clear_dirty clear_dirty;  /* Clear dirty state */
0080     pvr2_ctlf_get_v4lflags get_v4lflags;/* Retrieve v4l flags */
0081 
0082     /* Control's type (int, enum, bitmask) */
0083     enum pvr2_ctl_type type;
0084 
0085     /* Associated V4L control ID, if any */
0086     int v4l_id;
0087 
0088     /* Associated driver internal ID, if any */
0089     int internal_id;
0090 
0091     /* Don't implicitly initialize this control's value */
0092     int skip_init;
0093 
0094     /* Starting value for this control */
0095     int default_value;
0096 
0097     /* Type-specific control information */
0098     union {
0099         struct { /* Integer control */
0100             long min_value; /* lower limit */
0101             long max_value; /* upper limit */
0102         } type_int;
0103         struct { /* enumerated control */
0104             unsigned int count;       /* enum value count */
0105             const char * const *value_names; /* symbol names */
0106         } type_enum;
0107         struct { /* bitmask control */
0108             unsigned int valid_bits; /* bits in use */
0109             const char **bit_names;  /* symbol name/bit */
0110         } type_bitmask;
0111     } def;
0112 };
0113 
0114 
0115 /* Same as pvr2_ctl_info, but includes storage for the control description */
0116 #define PVR2_CTLD_INFO_DESC_SIZE 32
0117 struct pvr2_ctld_info {
0118     struct pvr2_ctl_info info;
0119     char desc[PVR2_CTLD_INFO_DESC_SIZE];
0120 };
0121 
0122 struct pvr2_ctrl {
0123     const struct pvr2_ctl_info *info;
0124     struct pvr2_hdw *hdw;
0125 };
0126 
0127 
0128 
0129 /* Disposition of firmware1 loading situation */
0130 #define FW1_STATE_UNKNOWN 0
0131 #define FW1_STATE_MISSING 1
0132 #define FW1_STATE_FAILED 2
0133 #define FW1_STATE_RELOAD 3
0134 #define FW1_STATE_OK 4
0135 
0136 /* What state the device is in if it is a hybrid */
0137 #define PVR2_PATHWAY_UNKNOWN 0
0138 #define PVR2_PATHWAY_ANALOG 1
0139 #define PVR2_PATHWAY_DIGITAL 2
0140 
0141 typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
0142 #define PVR2_I2C_FUNC_CNT 128
0143 
0144 /* This structure contains all state data directly needed to
0145    manipulate the hardware (as opposed to complying with a kernel
0146    interface) */
0147 struct pvr2_hdw {
0148     /* Underlying USB device handle */
0149     struct usb_device *usb_dev;
0150     struct usb_interface *usb_intf;
0151 
0152     /* Our handle into the v4l2 sub-device architecture */
0153     struct v4l2_device v4l2_dev;
0154     /* Device description, anything that must adjust behavior based on
0155        device specific info will use information held here. */
0156     const struct pvr2_device_desc *hdw_desc;
0157 
0158     /* Kernel worker thread handling */
0159     struct work_struct workpoll;     /* Update driver state */
0160 
0161     /* Video spigot */
0162     struct pvr2_stream *vid_stream;
0163 
0164     /* Mutex for all hardware state control */
0165     struct mutex big_lock_mutex;
0166     int big_lock_held;  /* For debugging */
0167 
0168     /* This is a simple string which identifies the instance of this
0169        driver.  It is unique within the set of existing devices, but
0170        there is no attempt to keep the name consistent with the same
0171        physical device each time. */
0172     char name[32];
0173 
0174     /* This is a simple string which identifies the physical device
0175        instance itself - if possible.  (If not possible, then it is
0176        based on the specific driver instance, similar to name above.)
0177        The idea here is that userspace might hopefully be able to use
0178        this recognize specific tuners.  It will encode a serial number,
0179        if available. */
0180     char identifier[32];
0181 
0182     /* I2C stuff */
0183     struct i2c_adapter i2c_adap;
0184     struct i2c_algorithm i2c_algo;
0185     pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
0186     int i2c_cx25840_hack_state;
0187     int i2c_linked;
0188 
0189     /* IR related */
0190     unsigned int ir_scheme_active; /* IR scheme as seen from the outside */
0191     struct IR_i2c_init_data ir_init_data; /* params passed to IR modules */
0192 
0193     /* Frequency table */
0194     unsigned int freqTable[FREQTABLE_SIZE];
0195     unsigned int freqProgSlot;
0196 
0197     /* Stuff for handling low level control interaction with device */
0198     struct mutex ctl_lock_mutex;
0199     int ctl_lock_held;  /* For debugging */
0200     struct urb *ctl_write_urb;
0201     struct urb *ctl_read_urb;
0202     unsigned char *ctl_write_buffer;
0203     unsigned char *ctl_read_buffer;
0204     int ctl_write_pend_flag;
0205     int ctl_read_pend_flag;
0206     int ctl_timeout_flag;
0207     struct completion ctl_done;
0208     unsigned char cmd_buffer[PVR2_CTL_BUFFSIZE];
0209     int cmd_debug_state;               // Low level command debugging info
0210     unsigned char cmd_debug_code;      //
0211     unsigned int cmd_debug_write_len;  //
0212     unsigned int cmd_debug_read_len;   //
0213 
0214     /* Bits of state that describe what is going on with various parts
0215        of the driver. */
0216     int state_pathway_ok;         /* Pathway config is ok */
0217     int state_encoder_ok;         /* Encoder is operational */
0218     int state_encoder_run;        /* Encoder is running */
0219     int state_encoder_config;     /* Encoder is configured */
0220     int state_encoder_waitok;     /* Encoder pre-wait done */
0221     int state_encoder_runok;      /* Encoder has run for >= .25 sec */
0222     int state_decoder_run;        /* Decoder is running */
0223     int state_decoder_ready;      /* Decoder is stabilized & streamable */
0224     int state_usbstream_run;      /* FX2 is streaming */
0225     int state_decoder_quiescent;  /* Decoder idle for minimal interval */
0226     int state_pipeline_config;    /* Pipeline is configured */
0227     int state_pipeline_req;       /* Somebody wants to stream */
0228     int state_pipeline_pause;     /* Pipeline must be paused */
0229     int state_pipeline_idle;      /* Pipeline not running */
0230 
0231     /* This is the master state of the driver.  It is the combined
0232        result of other bits of state.  Examining this will indicate the
0233        overall state of the driver.  Values here are one of
0234        PVR2_STATE_xxxx */
0235     unsigned int master_state;
0236 
0237     /* True if device led is currently on */
0238     int led_on;
0239 
0240     /* True if states must be re-evaluated */
0241     int state_stale;
0242 
0243     void (*state_func)(void *);
0244     void *state_data;
0245 
0246     /* Timer for measuring required decoder settling time before we're
0247        allowed to fire it up again. */
0248     struct timer_list quiescent_timer;
0249 
0250     /* Timer for measuring decoder stabilization time, which is the
0251        amount of time we need to let the decoder run before we can
0252        trust its output (otherwise the encoder might see garbage and
0253        then fail to start correctly). */
0254     struct timer_list decoder_stabilization_timer;
0255 
0256     /* Timer for measuring encoder pre-wait time */
0257     struct timer_list encoder_wait_timer;
0258 
0259     /* Timer for measuring encoder minimum run time */
0260     struct timer_list encoder_run_timer;
0261 
0262     /* Place to block while waiting for state changes */
0263     wait_queue_head_t state_wait_data;
0264 
0265 
0266     int force_dirty;        /* consider all controls dirty if true */
0267     int flag_ok;            /* device in known good state */
0268     int flag_modulefail;    /* true if at least one module failed to load */
0269     int flag_disconnected;  /* flag_ok == 0 due to disconnect */
0270     int flag_init_ok;       /* true if structure is fully initialized */
0271     int fw1_state;          /* current situation with fw1 */
0272     int pathway_state;      /* one of PVR2_PATHWAY_xxx */
0273     int flag_decoder_missed;/* We've noticed missing decoder */
0274     int flag_tripped;       /* Indicates overall failure to start */
0275 
0276     unsigned int decoder_client_id;
0277 
0278     // CPU firmware info (used to help find / save firmware data)
0279     char *fw_buffer;
0280     unsigned int fw_size;
0281     int fw_cpu_flag; /* True if we are dealing with the CPU */
0282 
0283     /* Tuner / frequency control stuff */
0284     unsigned int tuner_type;
0285     int tuner_updated;
0286     unsigned int freqValTelevision;  /* Current freq for tv mode */
0287     unsigned int freqValRadio;       /* Current freq for radio mode */
0288     unsigned int freqSlotTelevision; /* Current slot for tv mode */
0289     unsigned int freqSlotRadio;      /* Current slot for radio mode */
0290     unsigned int freqSelector;       /* 0=radio 1=television */
0291     int freqDirty;
0292 
0293     /* Current tuner info - this information is polled from the I2C bus */
0294     struct v4l2_tuner tuner_signal_info;
0295     int tuner_signal_stale;
0296 
0297     /* Cropping capability info */
0298     struct v4l2_cropcap cropcap_info;
0299     int cropcap_stale;
0300 
0301     /* Video standard handling */
0302     v4l2_std_id std_mask_eeprom; // Hardware supported selections
0303     v4l2_std_id std_mask_avail;  // Which standards we may select from
0304     v4l2_std_id std_mask_cur;    // Currently selected standard(s)
0305     int std_enum_cur;            // selected standard enumeration value
0306     int std_dirty;               // True if std_mask_cur has changed
0307     struct pvr2_ctl_info std_info_enum;
0308     struct pvr2_ctl_info std_info_avail;
0309     struct pvr2_ctl_info std_info_cur;
0310     struct pvr2_ctl_info std_info_detect;
0311 
0312     // Generated string names, one per actual V4L2 standard
0313     const char *std_mask_ptrs[32];
0314     char std_mask_names[32][16];
0315 
0316     int unit_number;             /* ID for driver instance */
0317     unsigned long serial_number; /* ID for hardware itself */
0318 
0319     char bus_info[32]; /* Bus location info */
0320 
0321     /* Minor numbers used by v4l logic (yes, this is a hack, as there
0322        should be no v4l junk here).  Probably a better way to do this. */
0323     int v4l_minor_number_video;
0324     int v4l_minor_number_vbi;
0325     int v4l_minor_number_radio;
0326 
0327     /* Bit mask of PVR2_CVAL_INPUT choices which are valid for the hardware */
0328     unsigned int input_avail_mask;
0329     /* Bit mask of PVR2_CVAL_INPUT choices which are currently allowed */
0330     unsigned int input_allowed_mask;
0331 
0332     /* Location of eeprom or a negative number if none */
0333     int eeprom_addr;
0334 
0335     enum pvr2_config active_stream_type;
0336     enum pvr2_config desired_stream_type;
0337 
0338     /* Control state needed for cx2341x module */
0339     struct cx2341x_mpeg_params enc_cur_state;
0340     struct cx2341x_mpeg_params enc_ctl_state;
0341     /* True if an encoder attribute has changed */
0342     int enc_stale;
0343     /* True if an unsafe encoder attribute has changed */
0344     int enc_unsafe_stale;
0345     /* True if enc_cur_state is valid */
0346     int enc_cur_valid;
0347 
0348     /* Control state */
0349 #define VCREATE_DATA(lab) int lab##_val; int lab##_dirty
0350     VCREATE_DATA(brightness);
0351     VCREATE_DATA(contrast);
0352     VCREATE_DATA(saturation);
0353     VCREATE_DATA(hue);
0354     VCREATE_DATA(volume);
0355     VCREATE_DATA(balance);
0356     VCREATE_DATA(bass);
0357     VCREATE_DATA(treble);
0358     VCREATE_DATA(mute);
0359     VCREATE_DATA(cropl);
0360     VCREATE_DATA(cropt);
0361     VCREATE_DATA(cropw);
0362     VCREATE_DATA(croph);
0363     VCREATE_DATA(input);
0364     VCREATE_DATA(audiomode);
0365     VCREATE_DATA(res_hor);
0366     VCREATE_DATA(res_ver);
0367     VCREATE_DATA(srate);
0368 #undef VCREATE_DATA
0369 
0370     struct pvr2_ctld_info *mpeg_ctrl_info;
0371 
0372     struct pvr2_ctrl *controls;
0373     unsigned int control_cnt;
0374 };
0375 
0376 /* This function gets the current frequency */
0377 unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
0378 
0379 void pvr2_hdw_status_poll(struct pvr2_hdw *);
0380 
0381 #endif /* __PVRUSB2_HDW_INTERNAL_H */