1 #ifndef __smscoreapi_h__
2 #define __smscoreapi_h__
7 #include "dvb_frontend.h"
11 #include <linux/version.h>
12 #include <linux/device.h>
13 #include <linux/list.h>
15 #include <asm/scatterlist.h>
18 #include <linux/mutex.h>
20 typedef struct mutex kmutex_t
;
22 #define kmutex_init(_p_) mutex_init(_p_)
23 #define kmutex_lock(_p_) mutex_lock(_p_)
24 #define kmutex_trylock(_p_) mutex_trylock(_p_)
25 #define kmutex_unlock(_p_) mutex_unlock(_p_)
31 #define min(a,b) (((a) < (b)) ? (a) : (b))
34 #define SMS_ALLOC_ALIGNMENT 128
35 #define SMS_DMA_ALIGNMENT 16
36 #define SMS_ALIGN_ADDRESS(addr) ((((u32)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
38 #define SMS_DEVICE_FAMILY2 1
39 #define SMS_ROM_NO_RESPONSE 2
40 #define SMS_DEVICE_NOT_READY 0x8000000
42 typedef struct _smscore_device smscore_device_t
;
43 typedef struct _smscore_client smscore_client_t
;
44 typedef struct _smscore_buffer smscore_buffer_t
;
46 typedef int (*hotplug_t
)(smscore_device_t
*coredev
, struct device
*device
, int arrival
);
48 typedef int (*setmode_t
)(void *context
, int mode
);
49 typedef void (*detectmode_t
)(void *context
, int *mode
);
50 typedef int (*sendrequest_t
)(void *context
, void *buffer
, size_t size
);
51 typedef int (*loadfirmware_t
)(void *context
, void *buffer
, size_t size
);
52 typedef int (*preload_t
)(void *context
);
53 typedef int (*postload_t
)(void *context
);
55 typedef int (*onresponse_t
)(void *context
, smscore_buffer_t
*cb
);
56 typedef void (*onremove_t
)(void *context
);
58 typedef struct _smscore_buffer
60 // public members, once passed to clients can be changed freely
61 struct list_head entry
;
65 // private members, read-only for clients
68 unsigned long offset_in_common
;
71 typedef struct _smsdevice_params
73 struct device
*device
;
81 setmode_t setmode_handler
;
82 detectmode_t detectmode_handler
;
83 sendrequest_t sendrequest_handler
;
84 preload_t preload_handler
;
85 postload_t postload_handler
;
90 typedef struct _smsclient_params
94 onresponse_t onresponse_handler
;
95 onremove_t onremove_handler
;
102 // GPIO definitions for antenna frequency domain control (SMS8021)
103 #define SMS_ANTENNA_GPIO_0 1
104 #define SMS_ANTENNA_GPIO_1 0
110 #define BW_ISDBT_1SEG 4
111 #define BW_ISDBT_3SEG 5
113 #define MSG_HDR_FLAG_SPLIT_MSG 4
115 #define MAX_GPIO_PIN_NUMBER 31
118 #define SMS_HOST_LIB 150
119 #define DVBT_BDA_CONTROL_MSG_ID 201
121 #define SMS_MAX_PAYLOAD_SIZE 240
122 #define SMS_TUNE_TIMEOUT 500
124 #define MSG_SMS_GPIO_CONFIG_REQ 507
125 #define MSG_SMS_GPIO_CONFIG_RES 508
126 #define MSG_SMS_GPIO_SET_LEVEL_REQ 509
127 #define MSG_SMS_GPIO_SET_LEVEL_RES 510
128 #define MSG_SMS_GPIO_GET_LEVEL_REQ 511
129 #define MSG_SMS_GPIO_GET_LEVEL_RES 512
130 #define MSG_SMS_RF_TUNE_REQ 561
131 #define MSG_SMS_RF_TUNE_RES 562
132 #define MSG_SMS_INIT_DEVICE_REQ 578
133 #define MSG_SMS_INIT_DEVICE_RES 579
134 #define MSG_SMS_ADD_PID_FILTER_REQ 601
135 #define MSG_SMS_ADD_PID_FILTER_RES 602
136 #define MSG_SMS_REMOVE_PID_FILTER_REQ 603
137 #define MSG_SMS_REMOVE_PID_FILTER_RES 604
138 #define MSG_SMS_DAB_CHANNEL 607
139 #define MSG_SMS_GET_PID_FILTER_LIST_REQ 608
140 #define MSG_SMS_GET_PID_FILTER_LIST_RES 609
141 #define MSG_SMS_GET_STATISTICS_REQ 615
142 #define MSG_SMS_GET_STATISTICS_RES 616
143 #define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651
144 #define MSG_SMS_SET_ANTENNA_CONFIG_RES 652
145 #define MSG_SMS_GET_STATISTICS_EX_REQ 653
146 #define MSG_SMS_GET_STATISTICS_EX_RES 654
147 #define MSG_SMS_SLEEP_RESUME_COMP_IND 655
148 #define MSG_SMS_DATA_DOWNLOAD_REQ 660
149 #define MSG_SMS_DATA_DOWNLOAD_RES 661
150 #define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ 664
151 #define MSG_SMS_SWDOWNLOAD_TRIGGER_RES 665
152 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ 666
153 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES 667
154 #define MSG_SMS_GET_VERSION_EX_REQ 668
155 #define MSG_SMS_GET_VERSION_EX_RES 669
156 #define MSG_SMS_SET_CLOCK_OUTPUT_REQ 670
157 #define MSG_SMS_I2C_SET_FREQ_REQ 685
158 #define MSG_SMS_GENERIC_I2C_REQ 687
159 #define MSG_SMS_GENERIC_I2C_RES 688
160 #define MSG_SMS_DVBT_BDA_DATA 693
161 #define MSG_SW_RELOAD_REQ 697
162 #define MSG_SMS_DATA_MSG 699
163 #define MSG_SW_RELOAD_START_REQ 702
164 #define MSG_SW_RELOAD_START_RES 703
165 #define MSG_SW_RELOAD_EXEC_REQ 704
166 #define MSG_SW_RELOAD_EXEC_RES 705
167 #define MSG_SMS_SPI_INT_LINE_SET_REQ 710
168 #define MSG_SMS_ISDBT_TUNE_REQ 776
169 #define MSG_SMS_ISDBT_TUNE_RES 777
171 #define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
172 (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
173 (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
175 #define SMS_INIT_MSG(ptr, type, len) SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
179 DEVICE_MODE_NONE
= -1,
180 DEVICE_MODE_DVBT
= 0,
182 DEVICE_MODE_DAB_TDMB
,
183 DEVICE_MODE_DAB_TDMB_DABIP
,
184 DEVICE_MODE_DVBT_BDA
,
186 DEVICE_MODE_ISDBT_BDA
,
188 DEVICE_MODE_RAW_TUNER
,
192 typedef unsigned char UINT8
;
193 typedef unsigned short UINT16
;
194 typedef unsigned int UINT32
;
197 typedef struct SmsMsgHdr_S
202 UINT16 msgLength
; // Length is of the entire message, including header
206 typedef struct SmsMsgData_S
208 SmsMsgHdr_ST xMsgHeader
;
212 typedef struct SmsDataDownload_S
214 SmsMsgHdr_ST xMsgHeader
;
216 UINT8 Payload
[SMS_MAX_PAYLOAD_SIZE
];
217 } SmsDataDownload_ST
;
219 typedef struct SmsVersionRes_S
221 SmsMsgHdr_ST xMsgHeader
;
223 UINT16 ChipModel
; // e.g. 0x1102 for SMS-1102 "Nova"
224 UINT8 Step
; // 0 - Step A
225 UINT8 MetalFix
; // 0 - Metal 0
227 UINT8 FirmwareId
; // 0xFF � ROM, otherwise the value indicated by SMSHOSTLIB_DEVICE_MODES_E
228 UINT8 SupportedProtocols
; // Bitwise OR combination of supported protocols
233 UINT8 VersionFieldPatch
;
235 UINT8 RomVersionMajor
;
236 UINT8 RomVersionMinor
;
237 UINT8 RomVersionPatch
;
238 UINT8 RomVersionFieldPatch
;
243 typedef struct SmsFirmware_S
251 typedef struct SMSHOSTLIB_STATISTICS_S
253 UINT32 Reserved
; //!< Reserved
255 /// Common parameters
256 UINT32 IsRfLocked
; //!< 0 - not locked, 1 - locked
257 UINT32 IsDemodLocked
; //!< 0 - not locked, 1 - locked
258 UINT32 IsExternalLNAOn
; //!< 0 - external LNA off, 1 - external LNA on
260 /// Reception quality
262 UINT32 BER
; //!< Post Viterbi BER [1E-5]
263 UINT32 FIB_CRC
; //!< CRC errors percentage, valid only for DAB
264 UINT32 TS_PER
; //!< Transport stream PER, 0xFFFFFFFF indicate N/A, valid only for DVB-T/H
265 UINT32 MFER
; //!< DVB-H frame error rate in percentage, 0xFFFFFFFF indicate N/A, valid only for DVB-H
267 INT32 InBandPwr
; //!< In band power in dBM
268 INT32 CarrierOffset
; //!< Carrier Offset in bin/1024
270 /// Transmission parameters
271 UINT32 Frequency
; //!< Frequency in Hz
272 UINT32 Bandwidth
; //!< Bandwidth in MHz, valid only for DVB-T/H
273 UINT32 TransmissionMode
; //!< Transmission Mode, for DAB modes 1-4, for DVB-T/H FFT mode carriers in Kilos
274 UINT32 ModemState
; //!< from SMS_DvbModemState_ET , valid only for DVB-T/H
275 UINT32 GuardInterval
; //!< Guard Interval, 1 divided by value , valid only for DVB-T/H
276 UINT32 CodeRate
; //!< Code Rate from SMS_DvbModemState_ET, valid only for DVB-T/H
277 UINT32 LPCodeRate
; //!< Low Priority Code Rate from SMS_DvbModemState_ET, valid only for DVB-T/H
278 UINT32 Hierarchy
; //!< Hierarchy from SMS_Hierarchy_ET, valid only for DVB-T/H
279 UINT32 Constellation
; //!< Constellation from SMS_Constellation_ET, valid only for DVB-T/H
281 /// Burst parameters, valid only for DVB-H
282 UINT32 BurstSize
; //!< Current burst size in bytes, valid only for DVB-H
283 UINT32 BurstDuration
; //!< Current burst duration in mSec, valid only for DVB-H
284 UINT32 BurstCycleTime
; //!< Current burst cycle time in mSec, valid only for DVB-H
285 UINT32 CalculatedBurstCycleTime
;//!< Current burst cycle time in mSec, as calculated by demodulator, valid only for DVB-H
286 UINT32 NumOfRows
; //!< Number of rows in MPE table, valid only for DVB-H
287 UINT32 NumOfPaddCols
; //!< Number of padding columns in MPE table, valid only for DVB-H
288 UINT32 NumOfPunctCols
; //!< Number of puncturing columns in MPE table, valid only for DVB-H
289 UINT32 ErrorTSPackets
; //!< Number of erroneous transport-stream packets
290 UINT32 TotalTSPackets
; //!< Total number of transport-stream packets
291 UINT32 NumOfValidMpeTlbs
; //!< Number of MPE tables which do not include errors after MPE RS decoding
292 UINT32 NumOfInvalidMpeTlbs
; //!< Number of MPE tables which include errors after MPE RS decoding
293 UINT32 NumOfCorrectedMpeTlbs
; //!< Number of MPE tables which were corrected by MPE RS decoding
295 UINT32 BERErrorCount
; //!< Number of errornous SYNC bits.
296 UINT32 BERBitCount
; //!< Total number of SYNC bits.
298 /// Interface information
299 UINT32 SmsToHostTxErrors
; //!< Total number of transmission errors.
302 UINT32 PreBER
; //!< DAB/T-DMB only: Pre Viterbi BER [1E-5]
304 /// DVB-H TPS parameters
305 UINT32 CellId
; //!< TPS Cell ID in bits 15..0, bits 31..16 zero; if set to 0xFFFFFFFF cell_id not yet recovered
307 } SMSHOSTLIB_STATISTICS_ST
;
311 UINT32 RequestResult
;
313 SMSHOSTLIB_STATISTICS_ST Stat
;
315 // Split the calc of the SNR in DAB
316 UINT32 Signal
; //!< dB
317 UINT32 Noise
; //!< dB
319 } SmsMsgStatisticsInfo_ST
;
321 typedef struct SMSHOSTLIB_ISDBT_LAYER_STAT_S
323 // Per-layer information
324 UINT32 CodeRate
; //!< Code Rate from SMSHOSTLIB_CODE_RATE_ET, 255 means layer does not exist
325 UINT32 Constellation
; //!< Constellation from SMSHOSTLIB_CONSTELLATION_ET, 255 means layer does not exist
326 UINT32 BER
; //!< Post Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A
327 UINT32 BERErrorCount
; //!< Post Viterbi Error Bits Count
328 UINT32 BERBitCount
; //!< Post Viterbi Total Bits Count
329 UINT32 PreBER
; //!< Pre Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A
330 UINT32 TS_PER
; //!< Transport stream PER [%], 0xFFFFFFFF indicate N/A
331 UINT32 ErrorTSPackets
; //!< Number of erroneous transport-stream packets
332 UINT32 TotalTSPackets
; //!< Total number of transport-stream packets
333 UINT32 TILdepthI
; //!< Time interleaver depth I parameter, 255 means layer does not exist
334 UINT32 NumberOfSegments
; //!< Number of segments in layer A, 255 means layer does not exist
335 UINT32 TMCCErrors
; //!< TMCC errors
336 } SMSHOSTLIB_ISDBT_LAYER_STAT_ST
;
338 typedef struct SMSHOSTLIB_STATISTICS_ISDBT_S
340 UINT32 StatisticsType
; //!< Enumerator identifying the type of the structure. Values are the same as SMSHOSTLIB_DEVICE_MODES_E
341 //!< This fiels MUST always first in any statistics structure
343 UINT32 FullSize
; //!< Total size of the structure returned by the modem. If the size requested by
344 //!< the host is smaller than FullSize, the struct will be truncated
347 UINT32 IsRfLocked
; //!< 0 - not locked, 1 - locked
348 UINT32 IsDemodLocked
; //!< 0 - not locked, 1 - locked
349 UINT32 IsExternalLNAOn
; //!< 0 - external LNA off, 1 - external LNA on
354 INT32 InBandPwr
; //!< In band power in dBM
355 INT32 CarrierOffset
; //!< Carrier Offset in Hz
357 // Transmission parameters
358 UINT32 Frequency
; //!< Frequency in Hz
359 UINT32 Bandwidth
; //!< Bandwidth in MHz
360 UINT32 TransmissionMode
; //!< ISDB-T transmission mode
361 UINT32 ModemState
; //!< 0 - Acquisition, 1 - Locked
362 UINT32 GuardInterval
; //!< Guard Interval, 1 divided by value
363 UINT32 SystemType
; //!< ISDB-T system type (ISDB-T / ISDB-Tsb)
364 UINT32 PartialReception
; //!< TRUE - partial reception, FALSE otherwise
365 UINT32 NumOfLayers
; //!< Number of ISDB-T layers in the network
367 // Per-layer information
369 SMSHOSTLIB_ISDBT_LAYER_STAT_ST LayerInfo
[3]; //!< Per-layer statistics, see SMSHOSTLIB_ISDBT_LAYER_STAT_ST
371 // Interface information
372 UINT32 SmsToHostTxErrors
; //!< Total number of transmission errors.
374 } SMSHOSTLIB_STATISTICS_ISDBT_ST
;
376 typedef struct SMSHOSTLIB_STATISTICS_DVB_S
378 UINT32 StatisticsType
; //!< Enumerator identifying the type of the structure. Values are the same as SMSHOSTLIB_DEVICE_MODES_E
379 //!< This fiels MUST always first in any statistics structure
381 UINT32 FullSize
; //!< Total size of the structure returned by the modem. If the size requested by
382 //!< the host is smaller than FullSize, the struct will be truncated
384 UINT32 IsRfLocked
; //!< 0 - not locked, 1 - locked
385 UINT32 IsDemodLocked
; //!< 0 - not locked, 1 - locked
386 UINT32 IsExternalLNAOn
; //!< 0 - external LNA off, 1 - external LNA on
390 UINT32 BER
; //!< Post Viterbi BER [1E-5]
391 UINT32 BERErrorCount
; //!< Number of errornous SYNC bits.
392 UINT32 BERBitCount
; //!< Total number of SYNC bits.
393 UINT32 TS_PER
; //!< Transport stream PER, 0xFFFFFFFF indicate N/A
394 UINT32 MFER
; //!< DVB-H frame error rate in percentage, 0xFFFFFFFF indicate N/A, valid only for DVB-H
396 INT32 InBandPwr
; //!< In band power in dBM
397 INT32 CarrierOffset
; //!< Carrier Offset in bin/1024
399 // Transmission parameters
400 UINT32 Frequency
; //!< Frequency in Hz
401 UINT32 Bandwidth
; //!< Bandwidth in MHz
402 UINT32 ModemState
; //!< from SMSHOSTLIB_DVB_MODEM_STATE_ET
403 UINT32 TransmissionMode
; //!< FFT mode carriers in Kilos
404 UINT32 GuardInterval
; //!< Guard Interval, 1 divided by value
405 UINT32 CodeRate
; //!< Code Rate from SMSHOSTLIB_CODE_RATE_ET
406 UINT32 LPCodeRate
; //!< Low Priority Code Rate from SMSHOSTLIB_CODE_RATE_ET
407 UINT32 Hierarchy
; //!< Hierarchy from SMSHOSTLIB_HIERARCHY_ET
408 UINT32 Constellation
; //!< Constellation from SMSHOSTLIB_CONSTELLATION_ET
410 // Burst parameters, valid only for DVB-H
411 UINT32 BurstSize
; //!< Current burst size in bytes, valid only for DVB-H
412 UINT32 BurstDuration
; //!< Current burst duration in mSec, valid only for DVB-H
413 UINT32 BurstCycleTime
; //!< Current burst cycle time in mSec, valid only for DVB-H
414 UINT32 CalculatedBurstCycleTime
;//!< Current burst cycle time in mSec, as calculated by demodulator, valid only for DVB-H
415 UINT32 NumOfRows
; //!< Number of rows in MPE table, valid only for DVB-H
416 UINT32 NumOfPaddCols
; //!< Number of padding columns in MPE table, valid only for DVB-H
417 UINT32 NumOfPunctCols
; //!< Number of puncturing columns in MPE table, valid only for DVB-H
418 UINT32 ErrorTSPackets
; //!< Number of erroneous transport-stream packets
419 UINT32 TotalTSPackets
; //!< Total number of transport-stream packets
420 UINT32 NumOfValidMpeTlbs
; //!< Number of MPE tables which do not include errors after MPE RS decoding, valid only for DVB-H
421 UINT32 NumOfInvalidMpeTlbs
; //!< Number of MPE tables which include errors after MPE RS decoding, valid only for DVB-H
422 UINT32 NumOfCorrectedMpeTlbs
; //!< Number of MPE tables which were corrected by MPE RS decoding, valid only for DVB-H
423 UINT32 NumMPEReceived
; //!< DVB-H, Num MPE section received
425 // DVB-H TPS parameters
426 UINT32 CellId
; //!< TPS Cell ID in bits 15..0, bits 31..16 zero; if set to 0xFFFFFFFF cell_id not yet recovered
427 UINT32 DvbhSrvIndHP
; //!< DVB-H service indication info, bit 1 - Time Slicing indicator, bit 0 - MPE-FEC indicator
428 UINT32 DvbhSrvIndLP
; //!< DVB-H service indication info, bit 1 - Time Slicing indicator, bit 0 - MPE-FEC indicator
430 // Interface information
431 UINT32 SmsToHostTxErrors
; //!< Total number of transmission errors.
433 } SMSHOSTLIB_STATISTICS_DVB_ST
;
435 typedef struct SMSHOSTLIB_GPIO_CONFIG_S
437 UINT8 Direction
; //!< GPIO direction: Input - 0, Output - 1
438 UINT8 PullUpDown
; //!< PullUp/PullDown: None - 0, PullDown - 1, PullUp - 2, Keeper - 3
439 UINT8 InputCharacteristics
; //!< Input Characteristics: Normal - 0, Schmitt trigger - 1
440 UINT8 OutputSlewRate
; //!< Output Slew Rate: Fast slew rate - 0, Slow slew rate - 1
441 UINT8 OutputDriving
; //!< Output driving capability: 4mA - 0, 8mA - 1, 12mA - 2, 16mA - 3
442 } SMSHOSTLIB_GPIO_CONFIG_ST
;
444 typedef struct SMSHOSTLIB_I2C_REQ_S
446 UINT32 DeviceAddress
; // I2c device address
447 UINT32 WriteCount
; // number of bytes to write
448 UINT32 ReadCount
; // number of bytes to read
450 } SMSHOSTLIB_I2C_REQ_ST
;
452 typedef struct SMSHOSTLIB_I2C_RES_S
454 UINT32 Status
; // non-zero value in case of failure
455 UINT32 ReadCount
; // number of bytes read
457 } SMSHOSTLIB_I2C_RES_ST
;
461 typedef struct _smsdvb_client
463 struct list_head entry
;
465 smscore_device_t
*coredev
;
466 smscore_client_t
*smsclient
;
468 struct dvb_adapter adapter
;
469 struct dvb_demux demux
;
470 struct dmxdev dmxdev
;
471 struct dvb_frontend frontend
;
473 fe_status_t fe_status
;
474 int fe_ber
, fe_snr
, fe_signal_strength
;
476 struct completion tune_done
, stat_done
;
478 // todo: save freq/band instead whole struct
479 struct dvb_frontend_parameters fe_params
;
483 extern void smscore_registry_setmode(char *devpath
, int mode
);
484 extern int smscore_registry_getmode(char *devpath
);
486 extern int smscore_register_hotplug(hotplug_t hotplug
);
487 extern void smscore_unregister_hotplug(hotplug_t hotplug
);
489 extern int smscore_register_device(smsdevice_params_t
*params
, smscore_device_t
**coredev
);
490 extern void smscore_unregister_device(smscore_device_t
*coredev
);
492 extern int smscore_start_device(smscore_device_t
*coredev
);
493 extern int smscore_load_firmware(smscore_device_t
*coredev
, char* filename
, loadfirmware_t loadfirmware_handler
);
495 extern int smscore_set_device_mode(smscore_device_t
*coredev
, int mode
);
496 extern int smscore_get_device_mode(smscore_device_t
*coredev
);
498 extern int smscore_register_client(smscore_device_t
*coredev
, smsclient_params_t
* params
, smscore_client_t
**client
);
499 extern void smscore_unregister_client(smscore_client_t
*client
);
501 extern int smsclient_sendrequest(smscore_client_t
*client
, void *buffer
, size_t size
);
502 extern void smscore_onresponse(smscore_device_t
*coredev
, smscore_buffer_t
*cb
);
504 extern int smscore_get_common_buffer_size(smscore_device_t
*coredev
);
505 extern int smscore_map_common_buffer(smscore_device_t
*coredev
, struct vm_area_struct
* vma
);
507 extern smscore_buffer_t
*smscore_getbuffer(smscore_device_t
*coredev
);
508 extern void smscore_putbuffer(smscore_device_t
*coredev
, smscore_buffer_t
*cb
);
511 int smsdvb_register(void);
512 void smsdvb_unregister(void);
515 int smsusb_register(void);
516 void smsusb_unregister(void);
518 #endif // __smscoreapi_h__