2 * Driver for the Siano SMS1xxx USB dongle
4 * author: Anatoly Greenblat
6 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
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 3 as
10 * published by the Free Software Foundation;
12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
15 * See the GNU General Public License for more details.
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.
22 #ifndef __smscoreapi_h__
23 #define __smscoreapi_h__
25 #include <linux/version.h>
26 #include <linux/device.h>
27 #include <linux/list.h>
29 #include <asm/scatterlist.h>
34 #include "dvb_demux.h"
35 #include "dvb_frontend.h"
37 #include <linux/mutex.h>
39 typedef struct mutex kmutex_t
;
41 #define kmutex_init(_p_) mutex_init(_p_)
42 #define kmutex_lock(_p_) mutex_lock(_p_)
43 #define kmutex_trylock(_p_) mutex_trylock(_p_)
44 #define kmutex_unlock(_p_) mutex_unlock(_p_)
48 #define min(a,b) (((a) < (b)) ? (a) : (b))
51 #define SMS_ALLOC_ALIGNMENT 128
52 #define SMS_DMA_ALIGNMENT 16
53 #define SMS_ALIGN_ADDRESS(addr) ((((u32)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
55 #define SMS_DEVICE_FAMILY2 1
56 #define SMS_ROM_NO_RESPONSE 2
57 #define SMS_DEVICE_NOT_READY 0x8000000
64 SMS_NUM_OF_DEVICE_TYPES
67 typedef struct _smscore_device smscore_device_t
;
68 typedef struct _smscore_client smscore_client_t
;
69 typedef struct _smscore_buffer smscore_buffer_t
;
71 typedef int (*hotplug_t
)(smscore_device_t
*coredev
, struct device
*device
, int arrival
);
73 typedef int (*setmode_t
)(void *context
, int mode
);
74 typedef void (*detectmode_t
)(void *context
, int *mode
);
75 typedef int (*sendrequest_t
)(void *context
, void *buffer
, size_t size
);
76 typedef int (*loadfirmware_t
)(void *context
, void *buffer
, size_t size
);
77 typedef int (*preload_t
)(void *context
);
78 typedef int (*postload_t
)(void *context
);
80 typedef int (*onresponse_t
)(void *context
, smscore_buffer_t
*cb
);
81 typedef void (*onremove_t
)(void *context
);
83 typedef struct _smscore_buffer
85 /* public members, once passed to clients can be changed freely */
86 struct list_head entry
;
90 /* private members, read-only for clients */
93 unsigned long offset_in_common
;
96 typedef struct _smsdevice_params
98 struct device
*device
;
106 setmode_t setmode_handler
;
107 detectmode_t detectmode_handler
;
108 sendrequest_t sendrequest_handler
;
109 preload_t preload_handler
;
110 postload_t postload_handler
;
113 sms_device_type_st device_type
;
114 } smsdevice_params_t
;
116 typedef struct _smsclient_params
120 onresponse_t onresponse_handler
;
121 onremove_t onremove_handler
;
124 } smsclient_params_t
;
126 /* GPIO definitions for antenna frequency domain control (SMS8021) */
127 #define SMS_ANTENNA_GPIO_0 1
128 #define SMS_ANTENNA_GPIO_1 0
134 #define BW_ISDBT_1SEG 4
135 #define BW_ISDBT_3SEG 5
137 #define MSG_HDR_FLAG_SPLIT_MSG 4
139 #define MAX_GPIO_PIN_NUMBER 31
142 #define SMS_HOST_LIB 150
143 #define DVBT_BDA_CONTROL_MSG_ID 201
145 #define SMS_MAX_PAYLOAD_SIZE 240
146 #define SMS_TUNE_TIMEOUT 500
148 #define MSG_SMS_GPIO_CONFIG_REQ 507
149 #define MSG_SMS_GPIO_CONFIG_RES 508
150 #define MSG_SMS_GPIO_SET_LEVEL_REQ 509
151 #define MSG_SMS_GPIO_SET_LEVEL_RES 510
152 #define MSG_SMS_GPIO_GET_LEVEL_REQ 511
153 #define MSG_SMS_GPIO_GET_LEVEL_RES 512
154 #define MSG_SMS_RF_TUNE_REQ 561
155 #define MSG_SMS_RF_TUNE_RES 562
156 #define MSG_SMS_INIT_DEVICE_REQ 578
157 #define MSG_SMS_INIT_DEVICE_RES 579
158 #define MSG_SMS_ADD_PID_FILTER_REQ 601
159 #define MSG_SMS_ADD_PID_FILTER_RES 602
160 #define MSG_SMS_REMOVE_PID_FILTER_REQ 603
161 #define MSG_SMS_REMOVE_PID_FILTER_RES 604
162 #define MSG_SMS_DAB_CHANNEL 607
163 #define MSG_SMS_GET_PID_FILTER_LIST_REQ 608
164 #define MSG_SMS_GET_PID_FILTER_LIST_RES 609
165 #define MSG_SMS_GET_STATISTICS_REQ 615
166 #define MSG_SMS_GET_STATISTICS_RES 616
167 #define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651
168 #define MSG_SMS_SET_ANTENNA_CONFIG_RES 652
169 #define MSG_SMS_GET_STATISTICS_EX_REQ 653
170 #define MSG_SMS_GET_STATISTICS_EX_RES 654
171 #define MSG_SMS_SLEEP_RESUME_COMP_IND 655
172 #define MSG_SMS_DATA_DOWNLOAD_REQ 660
173 #define MSG_SMS_DATA_DOWNLOAD_RES 661
174 #define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ 664
175 #define MSG_SMS_SWDOWNLOAD_TRIGGER_RES 665
176 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ 666
177 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES 667
178 #define MSG_SMS_GET_VERSION_EX_REQ 668
179 #define MSG_SMS_GET_VERSION_EX_RES 669
180 #define MSG_SMS_SET_CLOCK_OUTPUT_REQ 670
181 #define MSG_SMS_I2C_SET_FREQ_REQ 685
182 #define MSG_SMS_GENERIC_I2C_REQ 687
183 #define MSG_SMS_GENERIC_I2C_RES 688
184 #define MSG_SMS_DVBT_BDA_DATA 693
185 #define MSG_SW_RELOAD_REQ 697
186 #define MSG_SMS_DATA_MSG 699
187 #define MSG_SW_RELOAD_START_REQ 702
188 #define MSG_SW_RELOAD_START_RES 703
189 #define MSG_SW_RELOAD_EXEC_REQ 704
190 #define MSG_SW_RELOAD_EXEC_RES 705
191 #define MSG_SMS_SPI_INT_LINE_SET_REQ 710
192 #define MSG_SMS_ISDBT_TUNE_REQ 776
193 #define MSG_SMS_ISDBT_TUNE_RES 777
195 #define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
196 (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
197 (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
199 #define SMS_INIT_MSG(ptr, type, len) SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
203 DEVICE_MODE_NONE
= -1,
204 DEVICE_MODE_DVBT
= 0,
206 DEVICE_MODE_DAB_TDMB
,
207 DEVICE_MODE_DAB_TDMB_DABIP
,
208 DEVICE_MODE_DVBT_BDA
,
210 DEVICE_MODE_ISDBT_BDA
,
212 DEVICE_MODE_RAW_TUNER
,
216 typedef struct SmsMsgHdr_S
221 u16 msgLength
; /* Length of entire message, including header */
225 typedef struct SmsMsgData_S
227 SmsMsgHdr_ST xMsgHeader
;
231 typedef struct SmsDataDownload_S
233 SmsMsgHdr_ST xMsgHeader
;
235 u8 Payload
[SMS_MAX_PAYLOAD_SIZE
];
236 } SmsDataDownload_ST
;
238 typedef struct SmsVersionRes_S
240 SmsMsgHdr_ST xMsgHeader
;
242 u16 ChipModel
; /* e.g. 0x1102 for SMS-1102 "Nova" */
243 u8 Step
; /* 0 - Step A */
244 u8 MetalFix
; /* 0 - Metal 0 */
246 u8 FirmwareId
; /* 0xFF � ROM, otherwise the value indicated by SMSHOSTLIB_DEVICE_MODES_E */
247 u8 SupportedProtocols
; /* Bitwise OR combination of supported protocols */
252 u8 VersionFieldPatch
;
257 u8 RomVersionFieldPatch
;
262 typedef struct SmsFirmware_S
270 typedef struct SMSHOSTLIB_STATISTICS_S
272 u32 Reserved
; /* Reserved */
274 /* Common parameters */
275 u32 IsRfLocked
; /* 0 - not locked, 1 - locked */
276 u32 IsDemodLocked
; /* 0 - not locked, 1 - locked */
277 u32 IsExternalLNAOn
; /* 0 - external LNA off, 1 - external LNA on */
279 /* Reception quality */
281 u32 BER
; /* Post Viterbi BER [1E-5] */
282 u32 FIB_CRC
; /* CRC errors percentage, valid only for DAB */
283 u32 TS_PER
; /* Transport stream PER, 0xFFFFFFFF indicate N/A, valid only for DVB-T/H */
284 u32 MFER
; /* DVB-H frame error rate in percentage, 0xFFFFFFFF indicate N/A, valid only for DVB-H */
286 s32 InBandPwr
; /* In band power in dBM */
287 s32 CarrierOffset
; /* Carrier Offset in bin/1024 */
289 /* Transmission parameters */
290 u32 Frequency
; /* Frequency in Hz */
291 u32 Bandwidth
; /* Bandwidth in MHz, valid only for DVB-T/H */
292 u32 TransmissionMode
; /* Transmission Mode, for DAB modes 1-4, for DVB-T/H FFT mode carriers in Kilos */
293 u32 ModemState
; /* from SMS_DvbModemState_ET , valid only for DVB-T/H */
294 u32 GuardInterval
; /* Guard Interval, 1 divided by value , valid only for DVB-T/H */
295 u32 CodeRate
; /* Code Rate from SMS_DvbModemState_ET, valid only for DVB-T/H */
296 u32 LPCodeRate
; /* Low Priority Code Rate from SMS_DvbModemState_ET, valid only for DVB-T/H */
297 u32 Hierarchy
; /* Hierarchy from SMS_Hierarchy_ET, valid only for DVB-T/H */
298 u32 Constellation
; /* Constellation from SMS_Constellation_ET, valid only for DVB-T/H */
300 /* Burst parameters, valid only for DVB-H */
301 u32 BurstSize
; /* Current burst size in bytes, valid only for DVB-H */
302 u32 BurstDuration
; /* Current burst duration in mSec, valid only for DVB-H */
303 u32 BurstCycleTime
; /* Current burst cycle time in mSec, valid only for DVB-H */
304 u32 CalculatedBurstCycleTime
; /* Current burst cycle time in mSec, as calculated by demodulator, valid only for DVB-H */
305 u32 NumOfRows
; /* Number of rows in MPE table, valid only for DVB-H */
306 u32 NumOfPaddCols
; /* Number of padding columns in MPE table, valid only for DVB-H */
307 u32 NumOfPunctCols
; /* Number of puncturing columns in MPE table, valid only for DVB-H */
308 u32 ErrorTSPackets
; /* Number of erroneous transport-stream packets */
309 u32 TotalTSPackets
; /* Total number of transport-stream packets */
310 u32 NumOfValidMpeTlbs
; /* Number of MPE tables which do not include errors after MPE RS decoding */
311 u32 NumOfInvalidMpeTlbs
; /* Number of MPE tables which include errors after MPE RS decoding */
312 u32 NumOfCorrectedMpeTlbs
; /* Number of MPE tables which were corrected by MPE RS decoding */
315 u32 BERErrorCount
; /* Number of errornous SYNC bits. */
316 u32 BERBitCount
; /* Total number of SYNC bits. */
318 /* Interface information */
319 u32 SmsToHostTxErrors
; /* Total number of transmission errors. */
322 u32 PreBER
; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
324 /* DVB-H TPS parameters */
325 u32 CellId
; /* TPS Cell ID in bits 15..0, bits 31..16 zero; if set to 0xFFFFFFFF cell_id not yet recovered */
327 } SMSHOSTLIB_STATISTICS_ST
;
333 SMSHOSTLIB_STATISTICS_ST Stat
;
335 /* Split the calc of the SNR in DAB */
339 } SmsMsgStatisticsInfo_ST
;
341 typedef struct SMSHOSTLIB_ISDBT_LAYER_STAT_S
343 /* Per-layer information */
344 u32 CodeRate
; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET, 255 means layer does not exist */
345 u32 Constellation
; /* Constellation from SMSHOSTLIB_CONSTELLATION_ET, 255 means layer does not exist */
346 u32 BER
; /* Post Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A */
347 u32 BERErrorCount
; /* Post Viterbi Error Bits Count */
348 u32 BERBitCount
; /* Post Viterbi Total Bits Count */
349 u32 PreBER
; /* Pre Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A */
350 u32 TS_PER
; /* Transport stream PER [%], 0xFFFFFFFF indicate N/A */
351 u32 ErrorTSPackets
; /* Number of erroneous transport-stream packets */
352 u32 TotalTSPackets
; /* Total number of transport-stream packets */
353 u32 TILdepthI
; /* Time interleaver depth I parameter, 255 means layer does not exist */
354 u32 NumberOfSegments
; /* Number of segments in layer A, 255 means layer does not exist */
355 u32 TMCCErrors
; /* TMCC errors */
356 } SMSHOSTLIB_ISDBT_LAYER_STAT_ST
;
358 typedef struct SMSHOSTLIB_STATISTICS_ISDBT_S
360 u32 StatisticsType
; /* Enumerator identifying the type of the
361 * structure. Values are the same as
362 * SMSHOSTLIB_DEVICE_MODES_E
364 * This field MUST always be first in any
365 * statistics structure */
367 u32 FullSize
; /* Total size of the structure returned by the modem. If the size requested by
368 * the host is smaller than FullSize, the struct will be truncated */
370 /* Common parameters */
371 u32 IsRfLocked
; /* 0 - not locked, 1 - locked */
372 u32 IsDemodLocked
; /* 0 - not locked, 1 - locked */
373 u32 IsExternalLNAOn
; /* 0 - external LNA off, 1 - external LNA on */
375 /* Reception quality */
378 s32 InBandPwr
; /* In band power in dBM */
379 s32 CarrierOffset
; /* Carrier Offset in Hz */
381 /* Transmission parameters */
382 u32 Frequency
; /* Frequency in Hz */
383 u32 Bandwidth
; /* Bandwidth in MHz */
384 u32 TransmissionMode
; /* ISDB-T transmission mode */
385 u32 ModemState
; /* 0 - Acquisition, 1 - Locked */
386 u32 GuardInterval
; /* Guard Interval, 1 divided by value */
387 u32 SystemType
; /* ISDB-T system type (ISDB-T / ISDB-Tsb) */
388 u32 PartialReception
; /* TRUE - partial reception, FALSE otherwise */
389 u32 NumOfLayers
; /* Number of ISDB-T layers in the network */
391 /* Per-layer information */
392 /* Layers A, B and C */
393 SMSHOSTLIB_ISDBT_LAYER_STAT_ST LayerInfo
[3]; /* Per-layer statistics, see SMSHOSTLIB_ISDBT_LAYER_STAT_ST */
395 /* Interface information */
396 u32 SmsToHostTxErrors
; /* Total number of transmission errors. */
398 } SMSHOSTLIB_STATISTICS_ISDBT_ST
;
400 typedef struct SMSHOSTLIB_STATISTICS_DVB_S
402 u32 StatisticsType
; /* Enumerator identifying the type of the structure. Values are the same as SMSHOSTLIB_DEVICE_MODES_E
403 * This fiels MUST always first in any statistics structure */
405 u32 FullSize
; /* Total size of the structure returned by the modem. If the size requested by
406 * the host is smaller than FullSize, the struct will be truncated */
407 /* Common parameters */
408 u32 IsRfLocked
; /* 0 - not locked, 1 - locked */
409 u32 IsDemodLocked
; /* 0 - not locked, 1 - locked */
410 u32 IsExternalLNAOn
; /* 0 - external LNA off, 1 - external LNA on */
412 /* Reception quality */
414 u32 BER
; /* Post Viterbi BER [1E-5] */
415 u32 BERErrorCount
; /* Number of errornous SYNC bits. */
416 u32 BERBitCount
; /* Total number of SYNC bits. */
417 u32 TS_PER
; /* Transport stream PER, 0xFFFFFFFF indicate N/A */
418 u32 MFER
; /* DVB-H frame error rate in percentage, 0xFFFFFFFF indicate N/A, valid only for DVB-H */
420 s32 InBandPwr
; /* In band power in dBM */
421 s32 CarrierOffset
; /* Carrier Offset in bin/1024 */
423 /* Transmission parameters */
424 u32 Frequency
; /* Frequency in Hz */
425 u32 Bandwidth
; /* Bandwidth in MHz */
426 u32 ModemState
; /* from SMSHOSTLIB_DVB_MODEM_STATE_ET */
427 u32 TransmissionMode
; /* FFT mode carriers in Kilos */
428 u32 GuardInterval
; /* Guard Interval, 1 divided by value */
429 u32 CodeRate
; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET */
430 u32 LPCodeRate
; /* Low Priority Code Rate from SMSHOSTLIB_CODE_RATE_ET */
431 u32 Hierarchy
; /* Hierarchy from SMSHOSTLIB_HIERARCHY_ET */
432 u32 Constellation
; /* Constellation from SMSHOSTLIB_CONSTELLATION_ET */
434 /* Burst parameters, valid only for DVB-H */
435 u32 BurstSize
; /* Current burst size in bytes, valid only for DVB-H */
436 u32 BurstDuration
; /* Current burst duration in mSec, valid only for DVB-H */
437 u32 BurstCycleTime
; /* Current burst cycle time in mSec, valid only for DVB-H */
438 u32 CalculatedBurstCycleTime
; /* Current burst cycle time in mSec, as calculated by demodulator, valid only for DVB-H */
439 u32 NumOfRows
; /* Number of rows in MPE table, valid only for DVB-H */
440 u32 NumOfPaddCols
; /* Number of padding columns in MPE table, valid only for DVB-H */
441 u32 NumOfPunctCols
; /* Number of puncturing columns in MPE table, valid only for DVB-H */
442 u32 ErrorTSPackets
; /* Number of erroneous transport-stream packets */
443 u32 TotalTSPackets
; /* Total number of transport-stream packets */
444 u32 NumOfValidMpeTlbs
; /* Number of MPE tables which do not include errors after MPE RS decoding, valid only for DVB-H */
445 u32 NumOfInvalidMpeTlbs
; /* Number of MPE tables which include errors after MPE RS decoding, valid only for DVB-H */
446 u32 NumOfCorrectedMpeTlbs
; /* Number of MPE tables which were corrected by MPE RS decoding, valid only for DVB-H */
447 u32 NumMPEReceived
; /* DVB-H, Num MPE section received */
449 /* DVB-H TPS parameters */
450 u32 CellId
; /* TPS Cell ID in bits 15..0, bits 31..16 zero; if set to 0xFFFFFFFF cell_id not yet recovered */
451 u32 DvbhSrvIndHP
; /* DVB-H service indication info, bit 1 - Time Slicing indicator, bit 0 - MPE-FEC indicator */
452 u32 DvbhSrvIndLP
; /* DVB-H service indication info, bit 1 - Time Slicing indicator, bit 0 - MPE-FEC indicator */
454 /* Interface information */
455 u32 SmsToHostTxErrors
; /* Total number of transmission errors. */
457 } SMSHOSTLIB_STATISTICS_DVB_ST
;
459 typedef struct SMSHOSTLIB_GPIO_CONFIG_S
461 u8 Direction
; /* GPIO direction: Input - 0, Output - 1 */
462 u8 PullUpDown
; /* PullUp/PullDown: None - 0, PullDown - 1, PullUp - 2, Keeper - 3 */
463 u8 InputCharacteristics
; /* Input Characteristics: Normal - 0, Schmitt trigger - 1 */
464 u8 OutputSlewRate
; /* Output Slew Rate: Fast slew rate - 0, Slow slew rate - 1 */
465 u8 OutputDriving
; /* Output driving capability: 4mA - 0, 8mA - 1, 12mA - 2, 16mA - 3 */
466 } SMSHOSTLIB_GPIO_CONFIG_ST
;
468 typedef struct SMSHOSTLIB_I2C_REQ_S
470 u32 DeviceAddress
; /* I2c device address */
471 u32 WriteCount
; /* number of bytes to write */
472 u32 ReadCount
; /* number of bytes to read */
474 } SMSHOSTLIB_I2C_REQ_ST
;
476 typedef struct SMSHOSTLIB_I2C_RES_S
478 u32 Status
; /* non-zero value in case of failure */
479 u32 ReadCount
; /* number of bytes read */
481 } SMSHOSTLIB_I2C_RES_ST
;
483 typedef struct _smsdvb_client
485 struct list_head entry
;
487 smscore_device_t
*coredev
;
488 smscore_client_t
*smsclient
;
490 struct dvb_adapter adapter
;
491 struct dvb_demux demux
;
492 struct dmxdev dmxdev
;
493 struct dvb_frontend frontend
;
495 fe_status_t fe_status
;
496 int fe_ber
, fe_snr
, fe_signal_strength
;
498 struct completion tune_done
, stat_done
;
500 /* todo: save freq/band instead whole struct */
501 struct dvb_frontend_parameters fe_params
;
505 extern void smscore_registry_setmode(char *devpath
, int mode
);
506 extern int smscore_registry_getmode(char *devpath
);
508 extern int smscore_register_hotplug(hotplug_t hotplug
);
509 extern void smscore_unregister_hotplug(hotplug_t hotplug
);
511 extern int smscore_register_device(smsdevice_params_t
*params
,
512 smscore_device_t
**coredev
);
513 extern void smscore_unregister_device(smscore_device_t
*coredev
);
515 extern int smscore_start_device(smscore_device_t
*coredev
);
516 extern int smscore_load_firmware(smscore_device_t
*coredev
, char *filename
,
517 loadfirmware_t loadfirmware_handler
);
519 extern int smscore_load_firmware_from_buffer(smscore_device_t
*coredev
,
520 u8
*buffer
, int size
,
523 extern int smscore_set_device_mode(smscore_device_t
*coredev
, int mode
);
524 extern int smscore_get_device_mode(smscore_device_t
*coredev
);
526 extern int smscore_register_client(smscore_device_t
*coredev
,
527 smsclient_params_t
*params
,
528 smscore_client_t
**client
);
529 extern void smscore_unregister_client(smscore_client_t
*client
);
531 extern int smsclient_sendrequest(smscore_client_t
*client
,
532 void *buffer
, size_t size
);
533 extern void smscore_onresponse(smscore_device_t
*coredev
,
534 smscore_buffer_t
*cb
);
536 extern int smscore_get_common_buffer_size(smscore_device_t
*coredev
);
537 extern int smscore_map_common_buffer(smscore_device_t
*coredev
,
538 struct vm_area_struct
*vma
);
540 extern smscore_buffer_t
*smscore_getbuffer(smscore_device_t
*coredev
);
541 extern void smscore_putbuffer(smscore_device_t
*coredev
, smscore_buffer_t
*cb
);
544 int smsdvb_register(void);
545 void smsdvb_unregister(void);
548 int smsusb_register(void);
549 void smsusb_unregister(void);
551 #endif /* __smscoreapi_h__ */