]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/media/dvb/siano/smscoreapi.h
V4L/DVB (11554): Siano: core header - add definitions and structures
[mv-sheeva.git] / drivers / media / dvb / siano / smscoreapi.h
1 /*
2  *  Driver for the Siano SMS1xxx USB dongle
3  *
4  *  author: Anatoly Greenblat
5  *
6  *  Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License version 2 as
10  *  published by the Free Software Foundation;
11  *
12  *  Software distributed under the License is distributed on an "AS IS"
13  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
14  *
15  *  See the GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef __smscoreapi_h__
23 #define __smscoreapi_h__
24
25 #include <linux/version.h>
26 #include <linux/device.h>
27 #include <linux/list.h>
28 #include <linux/mm.h>
29 #include <linux/scatterlist.h>
30 #include <linux/types.h>
31 #include <asm/page.h>
32 #include <linux/mutex.h>
33
34 #include "dmxdev.h"
35 #include "dvbdev.h"
36 #include "dvb_demux.h"
37 #include "dvb_frontend.h"
38
39
40 #define kmutex_init(_p_) mutex_init(_p_)
41 #define kmutex_lock(_p_) mutex_lock(_p_)
42 #define kmutex_trylock(_p_) mutex_trylock(_p_)
43 #define kmutex_unlock(_p_) mutex_unlock(_p_)
44
45 #ifndef min
46 #define min(a, b) (((a) < (b)) ? (a) : (b))
47 #endif
48
49 #define SMS_PROTOCOL_MAX_RAOUNDTRIP_MS                          (10000)
50 #define SMS_ALLOC_ALIGNMENT                                     128
51 #define SMS_DMA_ALIGNMENT                                       16
52 #define SMS_ALIGN_ADDRESS(addr) \
53         ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
54
55 #define SMS_DEVICE_FAMILY2                                      1
56 #define SMS_ROM_NO_RESPONSE                                     2
57 #define SMS_DEVICE_NOT_READY                            0x8000000
58
59 enum sms_device_type_st {
60         SMS_STELLAR = 0,
61         SMS_NOVA_A0,
62         SMS_NOVA_B0,
63         SMS_VEGA,
64         SMS_NUM_OF_DEVICE_TYPES
65 };
66
67 struct smscore_device_t;
68 struct smscore_client_t;
69 struct smscore_buffer_t;
70
71 typedef int (*hotplug_t)(struct smscore_device_t *coredev,
72                          struct device *device, int arrival);
73
74 typedef int (*setmode_t)(void *context, int mode);
75 typedef void (*detectmode_t)(void *context, int *mode);
76 typedef int (*sendrequest_t)(void *context, void *buffer, size_t size);
77 typedef int (*loadfirmware_t)(void *context, void *buffer, size_t size);
78 typedef int (*preload_t)(void *context);
79 typedef int (*postload_t)(void *context);
80
81 typedef int (*onresponse_t)(void *context, struct smscore_buffer_t *cb);
82 typedef void (*onremove_t)(void *context);
83
84 struct smscore_buffer_t {
85         /* public members, once passed to clients can be changed freely */
86         struct list_head entry;
87         int                             size;
88         int                             offset;
89
90         /* private members, read-only for clients */
91         void                    *p;
92         dma_addr_t              phys;
93         unsigned long   offset_in_common;
94 };
95
96 struct smsdevice_params_t {
97         struct device   *device;
98
99         int                             buffer_size;
100         int                             num_buffers;
101
102         char                    devpath[32];
103         unsigned long   flags;
104
105         setmode_t               setmode_handler;
106         detectmode_t    detectmode_handler;
107         sendrequest_t   sendrequest_handler;
108         preload_t               preload_handler;
109         postload_t              postload_handler;
110
111         void                    *context;
112         enum sms_device_type_st device_type;
113 };
114
115 struct smsclient_params_t {
116         int                             initial_id;
117         int                             data_type;
118         onresponse_t    onresponse_handler;
119         onremove_t              onremove_handler;
120
121         void                    *context;
122 };
123
124 /* GPIO definitions for antenna frequency domain control (SMS8021) */
125 #define SMS_ANTENNA_GPIO_0                                      1
126 #define SMS_ANTENNA_GPIO_1                                      0
127
128 #define BW_8_MHZ                                                        0
129 #define BW_7_MHZ                                                        1
130 #define BW_6_MHZ                                                        2
131 #define BW_5_MHZ                                                        3
132 #define BW_ISDBT_1SEG                                           4
133 #define BW_ISDBT_3SEG                                           5
134
135 #define MSG_HDR_FLAG_SPLIT_MSG                          4
136
137 #define MAX_GPIO_PIN_NUMBER                                     31
138
139 #define HIF_TASK                                                        11
140 #define SMS_HOST_LIB                                            150
141 #define DVBT_BDA_CONTROL_MSG_ID                         201
142
143 #define SMS_MAX_PAYLOAD_SIZE                            240
144 #define SMS_TUNE_TIMEOUT                                        500
145
146 #define MSG_SMS_GPIO_CONFIG_REQ                         507
147 #define MSG_SMS_GPIO_CONFIG_RES                         508
148 #define MSG_SMS_GPIO_SET_LEVEL_REQ                      509
149 #define MSG_SMS_GPIO_SET_LEVEL_RES                      510
150 #define MSG_SMS_GPIO_GET_LEVEL_REQ                      511
151 #define MSG_SMS_GPIO_GET_LEVEL_RES                      512
152 #define MSG_SMS_RF_TUNE_REQ                                     561
153 #define MSG_SMS_RF_TUNE_RES                                     562
154 #define MSG_SMS_INIT_DEVICE_REQ                         578
155 #define MSG_SMS_INIT_DEVICE_RES                         579
156 #define MSG_SMS_ADD_PID_FILTER_REQ                      601
157 #define MSG_SMS_ADD_PID_FILTER_RES                      602
158 #define MSG_SMS_REMOVE_PID_FILTER_REQ           603
159 #define MSG_SMS_REMOVE_PID_FILTER_RES           604
160 #define MSG_SMS_DAB_CHANNEL                                     607
161 #define MSG_SMS_GET_PID_FILTER_LIST_REQ         608
162 #define MSG_SMS_GET_PID_FILTER_LIST_RES         609
163 #define MSG_SMS_GET_STATISTICS_REQ                      615
164 #define MSG_SMS_GET_STATISTICS_RES                      616
165 #define MSG_SMS_HO_PER_SLICES_IND                       630
166 #define MSG_SMS_SET_ANTENNA_CONFIG_REQ          651
167 #define MSG_SMS_SET_ANTENNA_CONFIG_RES          652
168 #define MSG_SMS_GET_STATISTICS_EX_REQ           653
169 #define MSG_SMS_GET_STATISTICS_EX_RES           654
170 #define MSG_SMS_SLEEP_RESUME_COMP_IND           655
171 #define MSG_SMS_DATA_DOWNLOAD_REQ                       660
172 #define MSG_SMS_DATA_DOWNLOAD_RES                       661
173 #define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ          664
174 #define MSG_SMS_SWDOWNLOAD_TRIGGER_RES          665
175 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ         666
176 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES         667
177 #define MSG_SMS_GET_VERSION_EX_REQ                      668
178 #define MSG_SMS_GET_VERSION_EX_RES                      669
179 #define MSG_SMS_SET_CLOCK_OUTPUT_REQ            670
180 #define MSG_SMS_I2C_SET_FREQ_REQ                        685
181 #define MSG_SMS_GENERIC_I2C_REQ                         687
182 #define MSG_SMS_GENERIC_I2C_RES                         688
183 #define MSG_SMS_DVBT_BDA_DATA                           693
184 #define MSG_SW_RELOAD_REQ                                       697
185 #define MSG_SMS_DATA_MSG                                        699
186 #define MSG_SW_RELOAD_START_REQ                         702
187 #define MSG_SW_RELOAD_START_RES                         703
188 #define MSG_SW_RELOAD_EXEC_REQ                          704
189 #define MSG_SW_RELOAD_EXEC_RES                          705
190 #define MSG_SMS_SPI_INT_LINE_SET_REQ            710
191 #define MSG_SMS_GPIO_CONFIG_EX_REQ                      712
192 #define MSG_SMS_GPIO_CONFIG_EX_RES                      713
193 #define MSG_SMS_ISDBT_TUNE_REQ                          776
194 #define MSG_SMS_ISDBT_TUNE_RES                          777
195 #define MSG_SMS_TRANSMISSION_IND                        782
196 #define MSG_SMS_START_IR_REQ                            800
197 #define MSG_SMS_START_IR_RES                            801
198 #define MSG_SMS_IR_SAMPLES_IND                          802
199 #define MSG_SMS_SIGNAL_DETECTED_IND                     827
200 #define MSG_SMS_NO_SIGNAL_IND                           828
201
202
203 #define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
204         (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
205         (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
206 } while (0)
207 #define SMS_INIT_MSG(ptr, type, len) \
208         SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
209 enum SMS_DVB3_EVENTS {
210         DVB3_EVENT_INIT = 0,
211         DVB3_EVENT_SLEEP,
212         DVB3_EVENT_HOTPLUG,
213         DVB3_EVENT_FE_LOCK,
214         DVB3_EVENT_FE_UNLOCK,
215         DVB3_EVENT_UNC_OK,
216         DVB3_EVENT_UNC_ERR
217 };
218
219 enum SMS_DEVICE_MODE {
220         DEVICE_MODE_NONE = -1,
221         DEVICE_MODE_DVBT = 0,
222         DEVICE_MODE_DVBH,
223         DEVICE_MODE_DAB_TDMB,
224         DEVICE_MODE_DAB_TDMB_DABIP,
225         DEVICE_MODE_DVBT_BDA,
226         DEVICE_MODE_ISDBT,
227         DEVICE_MODE_ISDBT_BDA,
228         DEVICE_MODE_CMMB,
229         DEVICE_MODE_RAW_TUNER,
230         DEVICE_MODE_MAX,
231 };
232
233 struct SmsMsgHdr_ST {
234         u16     msgType;
235         u8      msgSrcId;
236         u8      msgDstId;
237         u16     msgLength; /* Length of entire message, including header */
238         u16     msgFlags;
239 };
240
241 struct SmsMsgData_ST {
242         struct SmsMsgHdr_ST xMsgHeader;
243         u32 msgData[1];
244 };
245
246 struct SmsMsgData_ST2 {
247         struct SmsMsgHdr_ST xMsgHeader;
248         u32 msgData[2];
249 };
250
251 struct SmsDataDownload_ST {
252         struct SmsMsgHdr_ST     xMsgHeader;
253         u32                     MemAddr;
254         u8                      Payload[SMS_MAX_PAYLOAD_SIZE];
255 };
256
257 struct SmsVersionRes_ST {
258         struct SmsMsgHdr_ST     xMsgHeader;
259
260         u16             ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */
261         u8              Step; /* 0 - Step A */
262         u8              MetalFix; /* 0 - Metal 0 */
263
264         u8              FirmwareId; /* 0xFF ï¿½ ROM, otherwise the
265                                      * value indicated by
266                                      * SMSHOSTLIB_DEVICE_MODES_E */
267         u8              SupportedProtocols; /* Bitwise OR combination of
268                                              * supported protocols */
269
270         u8              VersionMajor;
271         u8              VersionMinor;
272         u8              VersionPatch;
273         u8              VersionFieldPatch;
274
275         u8              RomVersionMajor;
276         u8              RomVersionMinor;
277         u8              RomVersionPatch;
278         u8              RomVersionFieldPatch;
279
280         u8              TextLabel[34];
281 };
282
283 struct SmsFirmware_ST {
284         u32                     CheckSum;
285         u32                     Length;
286         u32                     StartAddress;
287         u8                      Payload[1];
288 };
289
290 struct SMSHOSTLIB_STATISTICS_ST {
291         u32 Reserved; /* Reserved */
292
293         /* Common parameters */
294         u32 IsRfLocked; /* 0 - not locked, 1 - locked */
295         u32 IsDemodLocked; /* 0 - not locked, 1 - locked */
296         u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
297
298         /* Reception quality */
299         s32  SNR; /* dB */
300         u32 BER; /* Post Viterbi BER [1E-5] */
301         u32 FIB_CRC;    /* CRC errors percentage, valid only for DAB */
302         u32 TS_PER; /* Transport stream PER, 0xFFFFFFFF indicate N/A,
303                      * valid only for DVB-T/H */
304         u32 MFER; /* DVB-H frame error rate in percentage,
305                    * 0xFFFFFFFF indicate N/A, valid only for DVB-H */
306         s32  RSSI; /* dBm */
307         s32  InBandPwr; /* In band power in dBM */
308         s32  CarrierOffset; /* Carrier Offset in bin/1024 */
309
310         /* Transmission parameters, valid only for DVB-T/H */
311         u32 Frequency; /* Frequency in Hz */
312         u32 Bandwidth; /* Bandwidth in MHz */
313         u32 TransmissionMode; /* Transmission Mode, for DAB modes 1-4,
314                                * for DVB-T/H FFT mode carriers in Kilos */
315         u32 ModemState; /* from SMS_DvbModemState_ET */
316         u32 GuardInterval; /* Guard Interval, 1 divided by value */
317         u32 CodeRate; /* Code Rate from SMS_DvbModemState_ET */
318         u32 LPCodeRate; /* Low Priority Code Rate from SMS_DvbModemState_ET */
319         u32 Hierarchy; /* Hierarchy from SMS_Hierarchy_ET */
320         u32 Constellation; /* Constellation from SMS_Constellation_ET */
321
322         /* Burst parameters, valid only for DVB-H */
323         u32 BurstSize; /* Current burst size in bytes */
324         u32 BurstDuration; /* Current burst duration in mSec */
325         u32 BurstCycleTime; /* Current burst cycle time in mSec */
326         u32 CalculatedBurstCycleTime; /* Current burst cycle time in mSec,
327                                        * as calculated by demodulator */
328         u32 NumOfRows; /* Number of rows in MPE table */
329         u32 NumOfPaddCols; /* Number of padding columns in MPE table */
330         u32 NumOfPunctCols; /* Number of puncturing columns in MPE table */
331         /* Burst parameters */
332         u32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
333         u32 TotalTSPackets; /* Total number of transport-stream packets */
334         u32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include
335                                 * errors after MPE RS decoding */
336         u32 NumOfInvalidMpeTlbs; /* Number of MPE tables which include errors
337                                   * after MPE RS decoding */
338         u32 NumOfCorrectedMpeTlbs; /* Number of MPE tables which were corrected
339                                     * by MPE RS decoding */
340
341         /* Common params */
342         u32 BERErrorCount; /* Number of errornous SYNC bits. */
343         u32 BERBitCount; /* Total number of SYNC bits. */
344
345         /* Interface information */
346         u32 SmsToHostTxErrors; /* Total number of transmission errors. */
347
348         /* DAB/T-DMB */
349         u32 PreBER; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
350
351         /* DVB-H TPS parameters */
352         u32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero;
353                      * if set to 0xFFFFFFFF cell_id not yet recovered */
354
355 };
356
357 struct SmsMsgStatisticsInfo_ST {
358         u32 RequestResult;
359
360         struct SMSHOSTLIB_STATISTICS_ST Stat;
361
362         /* Split the calc of the SNR in DAB */
363         u32 Signal; /* dB */
364         u32 Noise; /* dB */
365
366 };
367
368
369 struct smscore_gpio_config {
370 #define SMS_GPIO_DIRECTION_INPUT  0
371 #define SMS_GPIO_DIRECTION_OUTPUT 1
372         u8 direction;
373
374 #define SMS_GPIO_PULLUPDOWN_NONE     0
375 #define SMS_GPIO_PULLUPDOWN_PULLDOWN 1
376 #define SMS_GPIO_PULLUPDOWN_PULLUP   2
377 #define SMS_GPIO_PULLUPDOWN_KEEPER   3
378         u8 pullupdown;
379
380 #define SMS_GPIO_INPUTCHARACTERISTICS_NORMAL  0
381 #define SMS_GPIO_INPUTCHARACTERISTICS_SCHMITT 1
382         u8 inputcharacteristics;
383
384 #define SMS_GPIO_OUTPUTSLEWRATE_FAST 0
385 #define SMS_GPIO_OUTPUTSLEWRATE_SLOW 1
386         u8 outputslewrate;
387
388 #define SMS_GPIO_OUTPUTDRIVING_4mA  0
389 #define SMS_GPIO_OUTPUTDRIVING_8mA  1
390 #define SMS_GPIO_OUTPUTDRIVING_12mA 2
391 #define SMS_GPIO_OUTPUTDRIVING_16mA 3
392         u8 outputdriving;
393 };
394
395 extern void smscore_registry_setmode(char *devpath, int mode);
396 extern int smscore_registry_getmode(char *devpath);
397
398 extern int smscore_register_hotplug(hotplug_t hotplug);
399 extern void smscore_unregister_hotplug(hotplug_t hotplug);
400
401 extern int smscore_register_device(struct smsdevice_params_t *params,
402                                    struct smscore_device_t **coredev);
403 extern void smscore_unregister_device(struct smscore_device_t *coredev);
404
405 extern int smscore_start_device(struct smscore_device_t *coredev);
406 extern int smscore_load_firmware(struct smscore_device_t *coredev,
407                                  char *filename,
408                                  loadfirmware_t loadfirmware_handler);
409
410 extern int smscore_set_device_mode(struct smscore_device_t *coredev, int mode);
411 extern int smscore_get_device_mode(struct smscore_device_t *coredev);
412
413 extern int smscore_register_client(struct smscore_device_t *coredev,
414                                     struct smsclient_params_t *params,
415                                     struct smscore_client_t **client);
416 extern void smscore_unregister_client(struct smscore_client_t *client);
417
418 extern int smsclient_sendrequest(struct smscore_client_t *client,
419                                  void *buffer, size_t size);
420 extern void smscore_onresponse(struct smscore_device_t *coredev,
421                                struct smscore_buffer_t *cb);
422
423 extern int smscore_get_common_buffer_size(struct smscore_device_t *coredev);
424 extern int smscore_map_common_buffer(struct smscore_device_t *coredev,
425                                       struct vm_area_struct *vma);
426 extern int smscore_get_fw_filename(struct smscore_device_t *coredev,
427                                    int mode, char *filename);
428 extern int smscore_send_fw_file(struct smscore_device_t *coredev,
429                                 u8 *ufwbuf, int size);
430
431 extern
432 struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev);
433 extern void smscore_putbuffer(struct smscore_device_t *coredev,
434                               struct smscore_buffer_t *cb);
435
436 int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
437                            struct smscore_gpio_config *pinconfig);
438 int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level);
439
440 void smscore_set_board_id(struct smscore_device_t *core, int id);
441 int smscore_get_board_id(struct smscore_device_t *core);
442
443 int smscore_led_state(struct smscore_device_t *core, int led);
444
445
446 /* ------------------------------------------------------------------------ */
447
448 #define DBG_INFO 1
449 #define DBG_ADV  2
450
451 #define sms_printk(kern, fmt, arg...) \
452         printk(kern "%s: " fmt "\n", __func__, ##arg)
453
454 #define dprintk(kern, lvl, fmt, arg...) do {\
455         if (sms_dbg & lvl) \
456                 sms_printk(kern, fmt, ##arg); } while (0)
457
458 #define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
459 #define sms_err(fmt, arg...) \
460         sms_printk(KERN_ERR, "line: %d: " fmt, __LINE__, ##arg)
461 #define sms_warn(fmt, arg...)  sms_printk(KERN_WARNING, fmt, ##arg)
462 #define sms_info(fmt, arg...) \
463         dprintk(KERN_INFO, DBG_INFO, fmt, ##arg)
464 #define sms_debug(fmt, arg...) \
465         dprintk(KERN_DEBUG, DBG_ADV, fmt, ##arg)
466
467
468 #endif /* __smscoreapi_h__ */