Copied sources from OpenWRT project
[hides-driver.git] / src / it951x-core.h
blob73b895d99e582c3246d0ea91b36fe0a6d3091ae3
1 /**
2 * Copyright (c) 2017 ITE Corporation. All rights reserved.
4 * Module Name:
5 * it951x-core.h
7 * Abstract:
8 * The definitions of header for core driver.
12 #ifndef _IT951x_H_
13 #define _IT951x_H_
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
20 #include <linux/kref.h>
21 #include <linux/usb.h>
22 #include <linux/fs.h>
23 #include <linux/file.h>
24 #include <asm/uaccess.h>
25 #include "iocontrol.h"
26 #include "Demodulator.h"
27 #include "IT9510.h"
28 #include "userdef.h"
29 #include "IT9510Firmware.h"
30 #include "modulatorType.h"
31 #include "Common.h"
32 #include <linux/version.h>
33 #include <linux/mutex.h>
34 #include <linux/mm.h>
35 #include <linux/sched.h>
36 #include <linux/kthread.h>
37 #include <linux/err.h>
38 #include <linux/gfp.h>
39 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
40 #include <linux/smp_lock.h>
41 #endif
43 #define DRIVER_RELEASE_VERSION "v17.03.09.1"
45 /** Device Power control for DTVCAM, AVSENDER ,OTHER **/
46 #define DEVICE_POWER_CTRL 1 // 0: PW Control OFF
47 #define RETURN_CHANNEL 1 // Return Channel 0: OFF
48 #define PACKECT_SHIFT 0 // Packet Shift Issue 0: OFF
50 /************** URB DEFINITION *************/
51 #define URB_COUNT_TX 16
52 #define URB_COUNT_TX_LOW_BRATE 32
53 #define URB_COUNT_TX_CMD 50
54 #define URB_COUNT_RX 16
55 #define URB_BUFSIZE_TX 32712
56 #define URB_BUFSIZE_TX_LOW_BRATE 188 * 2
57 #define URB_BUFSIZE_TX_CMD 188
58 #define URB_BUFSIZE_RX 188 * 348
59 #define CLEAN_HARDWARE_BUFFER_SIZE 1000
61 /** Get a minor range for devices from the usb maintainer **/
62 #define USB_it951x_MINOR_RANGE 32
63 #define USB_it91xx_MINOR_RANGE 31
64 #ifdef CONFIG_USB_DYNAMIC_MINORS
65 #define USB_it91xx_MINOR_BASE 0
66 #define USB_it951x_MINOR_BASE USB_it91xx_MINOR_RANGE
67 #else
68 #define USB_it91xx_MINOR_BASE 192
69 #define USB_it951x_MINOR_BASE 192 + USB_it91xx_MINOR_RANGE
70 #endif
72 /** USB Handler table for register kernel. **/
73 #define TX_MAX_USB_HANDLE_NUM USB_it951x_MINOR_RANGE
74 #define RX_MAX_USB_HANDLE_NUM USB_it91xx_MINOR_RANGE
75 #define MAX_USB_HANDLE_NAME_SIZE 20 // Table size for Tx or Rx.
77 /***************** Customization *****************/
79 /***************** from compat.h *****************/
80 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
81 #define true 1
82 #define false 0
83 #endif
84 /***************** from device.h *****************/
85 #define AFA_USB_DEVICE
86 #define SLAVE_DEMOD_2WIREADDR 0x3A
87 #define TS_PACKET_SIZE 188
88 #define TS_PACKET_COUNT_HI 348
89 #define TS_PACKET_COUNT_FU 21
91 /***************** from driver.h *****************/
92 #define TS_FRAMES_HI 128
93 #define TS_FRAMES_FU 128
94 #define MAX_USB20_IRP_NUM 5
95 #define MAX_USB11_IRP_NUM 2
97 /***************** from afdrv.h *****************/
98 #define EEPROM_FLB_OFS 8
100 #define EEPROM_IRMODE (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x10) // 00:disabled, 01:HID
101 #define EEPROM_SELSUSPEND (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x28) // Selective Suspend Mode
102 #define EEPROM_TSMODE (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x28+1) // 0:one ts, 1:dual ts
103 #define EEPROM_2WIREADDR (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x28+2) // MPEG2 2WireAddr
104 #define EEPROM_SUSPEND (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x28+3) // Suspend Mode
105 #define EEPROM_IRTYPE (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x28+4) // 0:NEC, 1:RC6
106 #define EEPROM_SAWBW1 (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x28+5)
107 #define EEPROM_XTAL1 (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x28+6) // 0:28800, 1:20480
108 #define EEPROM_SPECINV1 (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x28+7)
109 #define EEPROM_TUNERID (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x30+4)
110 #define EEPROM_IFFREQL (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x30)
111 #define EEPROM_IFFREQH (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x30+1)
112 #define EEPROM_IF1L (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x30+2)
113 #define EEPROM_IF1H (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x30+3)
114 #define EEPROM_SHIFT (0x10) //EEPROM Addr Shift for slave front end
115 #define EEPROM_SLAVEI2CADDRESS (OVA_EEPROM_CFG+EEPROM_FLB_OFS+0x2A)
116 extern int dvb_usb_it951x_debug;
118 /* Driver Debug */
119 #define DRV_DEBUG 1
120 /* Ring Buffer Debug */
121 #define RB_DEBUG 0
123 #if (DRV_DEBUG || RB_DEBUG)
124 #define deb_data(args...) printk(KERN_NOTICE args)
125 #else
126 #define deb_data(args...)
127 #endif
129 /***************** from device.h *****************/
130 /*AirHD no use, RC, after kernel 38 support*/
131 struct it951x_config {
132 u8 dual_mode:1;
133 u16 mt2060_if1[2];
134 u16 firmware_size;
135 u16 firmware_checksum;
136 u32 eeprom_sum;
139 typedef struct _TUNER_INFO {
140 Bool bTunerInited;
141 Bool bSettingFreq;
142 BYTE TunerId;
143 Bool bTunerOK;
144 Bool bTunerLock;//AirHD
145 Tuner_struct MXL5005_Info;
146 } TUNER_INFO, *PTUNER_INFO;
148 typedef struct _FILTER_CONTEXT_HW {
149 DWORD ulCurrentFrequency;
150 WORD ucCurrentBandWidth;
151 DWORD ulDesiredFrequency;
152 WORD ucDesiredBandWidth;
153 Bool bTimerOn;
154 Byte GraphBuilt;
155 TUNER_INFO tunerinfo;
156 int bEnPID;
157 Bool bApOn;
158 int bResetTs;
159 Byte OvrFlwChk;
160 } FILTER_CONTEXT_HW, *PFILTER_CONTEXT_HW;
164 typedef struct _DEVICE_CONTEXT {
165 FILTER_CONTEXT_HW fc[2];
166 Byte DeviceNo;
167 Bool bBootCode;
168 Bool bEP12Error;
169 Bool bEP45Error;
170 Bool bDualTs;
171 Bool bIrTblDownload;
172 Byte BulkOutData[256];
173 u32 WriteLength;
174 Bool bSurpriseRemoval;
175 Bool bDevNotResp;
176 Bool bEnterSuspend;
177 Bool bSupportSuspend;
178 Bool bSupportSelSuspend;
179 u16 regIdx;
180 Byte eepromIdx;
181 u16 UsbMode;
182 u16 MaxPacketSize;
183 u32 MaxIrpSize;
184 u32 TsFrames;
185 u32 TsFrameSize;
186 u32 TsFrameSizeDw;
187 u32 TsPacketCount;
189 Bool bSelectiveSuspend;
190 u32 ulActiveFilter;
191 Architecture architecture;
192 StreamType StreamType;
193 Bool bDCAPIP;
194 Bool bSwapFilter;
195 Byte FilterCnt;
196 Bool bTunerPowerOff;
197 Byte UsbCtrlTimeOut;
199 IT9510INFO modulator; // IT9510 Modulator struct.
200 DefaultDemodulator demodulator; // IT9133 Modulator struct.
201 Byte deviceType;
202 Byte isUsingDefaultDeviceType;
203 Bool Rx_init_success;
204 Bool Tx_init_success;
206 /* Calibration Table */
207 CalibrationInfo calibrationInfo;
209 /* DC Calibration Info */
210 DCInfo dcInfo;
212 Bool ForceWrite;
213 Byte chip_version;
214 Bool bProprietaryIr;
215 Byte bIrType;
217 Byte *pControlBuffer_WriteReg; /* Malloc Usb2_writeControlBus Write Buffer */
218 Byte *pControlBuffer_ReadReg; /* Malloc Usb2_writeControlBus Read Buffer */
219 } DEVICE_CONTEXT, *PDEVICE_CONTEXT;
222 struct it951x_ofdm_channel {
223 u32 RF_kHz;
224 u8 Bw;
225 s16 nfft;
226 s16 guard;
227 s16 nqam;
228 s16 vit_hrch;
229 s16 vit_select_hp;
230 s16 vit_alpha;
231 s16 vit_code_rate_hp;
232 s16 vit_code_rate_lp;
233 u8 intlv_native;
236 struct tuner_priv {
237 struct tuner_config *cfg;
238 struct i2c_adapter *i2c;
240 u32 frequency;
241 u32 bandwidth;
242 u16 if1_freq;
243 u8 fmfreq;
246 /* Structure for urb context */
247 typedef struct it951x_urb_context{
248 struct it951x_dev *dev;
249 Byte index;
250 } URBContext;
252 /* Structure to hold all of our device specific stuff */
253 struct it951x_dev {
254 struct usb_device * usbdev; /* the usb device for this device */
255 struct usb_interface * interface; /* the interface for this device */
256 struct kref kref;
257 struct file *file;
258 struct file *tx_file;
259 DEVICE_CONTEXT DC;
260 Byte tx_on;
261 Byte rx_on;
262 Byte rx_chip_minor;
263 Byte tx_chip_minor;
264 short tx_handle_num;
265 short rx_handle_num;
267 Byte g_AP_use;
268 atomic_t g_AP_use_tx;
269 atomic_t g_AP_use_rx;
270 atomic_t tx_pw_on;
271 atomic_t rx_pw_on;
272 Bool DeviceReboot, DevicePower;
273 Bool TunerInited0, TunerInited1;
274 Byte is_use_low_brate;
275 int urb_counter_low_brate;
277 /* USB URB Related for TX*/
278 int tx_urb_streaming;
279 struct urb *tx_urbs[URB_COUNT_TX];
280 URBContext tx_urb_context[URB_COUNT_TX];
281 Byte tx_urbstatus[URB_COUNT_TX];
282 Byte tx_urb_index;
283 int tx_urb_counter;
284 spinlock_t TxRBKeyLock;
285 Byte* pTxRingBuffer; // Tx Ring Buffer Address.
286 Dword TxCurrBuffPointAddr; // Output urb addr.
287 Dword TxWriteBuffPointAddr; // Entry of Ring Buffer.
288 Dword dwTxWriteTolBufferSize; // Total ringbuffer size.
289 Dword dwTxRemaingBufferSize; // Remaining size in buffer.
291 /* USB URB Related for TX low bitrate*/
292 int tx_urb_streaming_low_brate;
293 struct urb *tx_urbs_low_brate[URB_COUNT_TX_LOW_BRATE];
294 URBContext tx_urb_context_low_brate[URB_COUNT_TX_LOW_BRATE];
295 Byte tx_urbstatus_low_brate[URB_COUNT_TX_LOW_BRATE];
296 Byte tx_urb_index_low_brate;
297 int tx_urb_counter_low_brate;
298 spinlock_t TxRBKeyLock_low_brate;
299 Byte* pTxRingBuffer_low_brate;
300 Dword TxCurrBuffPointAddr_low_brate;
301 Dword TxWriteBuffPointAddr_low_brate;
302 Dword dwTxWriteTolBufferSize_low_brate;
303 Dword dwTxRemaingBufferSize_low_brate;
304 #if RETURN_CHANNEL
305 /* USB URB Related for TX_CMD */
306 int tx_urb_streaming_cmd;
307 struct urb *tx_urbs_cmd[URB_COUNT_TX_CMD];
308 URBContext tx_urb_context_cmd[URB_COUNT_TX_CMD];
309 Byte tx_urbstatus_cmd[URB_COUNT_TX_CMD];
310 Byte tx_urb_index_cmd;
311 spinlock_t TxRBKeyLock_cmd;
312 Byte* pTxRingBuffer_cmd;
313 Byte* pWriteFrameBuffer_cmd;
314 Dword* pTxCurrBuffPointAddr_cmd;
315 Dword* pTxWriteBuffPointAddr_cmd;
316 Dword dwTxWriteTolBufferSize_cmd;
317 Dword dwTxRemaingBufferSize_cmd;
318 #endif
319 /* USB URB Related for RX */
320 int rx_urb_streaming;
321 struct urb *rx_urbs[URB_COUNT_RX];
322 URBContext rx_urb_context[URB_COUNT_RX];
323 Byte rx_urbstatus[URB_COUNT_RX];
324 atomic_t rx_urb_counter;
325 Byte rx_urb_index;
326 Byte rx_first_urb_reset;
327 spinlock_t RxRBKeylock;
328 Byte *pRxRingBuffer;
329 Dword RxCurrBuffPointAddr;
330 Dword RxReadBuffPointAddr;
331 Dword dwRxTolBufferSize;
332 Dword dwRxReadRemaingBufferSize;
334 /* Patch for packet shift */
335 #if PACKECT_SHIFT
336 int buffer_shift;
337 struct task_struct *reset_thread;
338 wait_queue_head_t reset_wait;
339 #endif
344 extern DWORD Device_init(struct usb_device *udev,PDEVICE_CONTEXT PDCs, Bool bBoot);
345 extern DWORD DL_ApCtrl(void* handle, Byte ucSlaveDemod, Bool bOn);
346 extern DWORD DL_ApPwCtrl(void* handle, Bool ucSlaveDemod, Bool bOn);
347 extern DWORD DL_Tuner_SetFreqBw(void *handle, BYTE ucSlaveDemod,u32 ucFreq,u8 ucBw);
348 extern DWORD DL_isLocked(void *handle,BYTE ucSlaveDemod, Bool *bLock);
349 extern DWORD DL_getSignalStrength(void *handle,BYTE ucSlaveDemod, BYTE* strength);
350 extern DWORD DL_getSignalStrengthDbm(void *handle, BYTE ucSlaveDemod, Long* strengthDbm);
351 extern DWORD DL_getChannelStatistic(BYTE ucSlaveDemod, ChannelStatistic* channelStatistic);
352 extern DWORD DL_getChannelModulation(void *handle, BYTE ucSlaveDemod, ChannelModulation* channelModulation);
353 extern DWORD DL_getSNR(void *handle, BYTE ucSlaveDemod, Constellation* constellation, BYTE* snr);
354 extern DWORD DL_ReSetInterval(void);
355 extern DWORD DL_Reboot(void* handle);
356 extern DWORD DL_CheckTunerInited(void *handle, BYTE ucSlaveDemod, Bool *bOn);
357 extern DWORD DL_DemodIOCTLFun(void* handle, DWORD IOCTLCode, unsigned long pIOBuffer);
358 extern DWORD DL_LoadIQtable_Fromfile(void *handle);
359 extern DWORD DL_ResetBuffer(void *handle);
360 extern DWORD DL_DetectLockSignal(void *handle);
361 extern DWORD DL_SetDCCalibrationTable(void *handle);
363 #endif