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 #define kmutex_init(_p_) mutex_init(_p_)
40 #define kmutex_lock(_p_) mutex_lock(_p_)
41 #define kmutex_trylock(_p_) mutex_trylock(_p_)
42 #define kmutex_unlock(_p_) mutex_unlock(_p_)
45 #define min(a, b) (((a) < (b)) ? (a) : (b))
48 #define SMS_ALLOC_ALIGNMENT 128
49 #define SMS_DMA_ALIGNMENT 16
50 #define SMS_ALIGN_ADDRESS(addr) \
51 ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
53 #define SMS_DEVICE_FAMILY2 1
54 #define SMS_ROM_NO_RESPONSE 2
55 #define SMS_DEVICE_NOT_READY 0x8000000
57 enum sms_device_type_st {
62 SMS_NUM_OF_DEVICE_TYPES
65 struct smscore_device_t;
66 struct smscore_client_t;
67 struct smscore_buffer_t;
69 typedef int (*hotplug_t)(struct smscore_device_t *coredev,
70 struct device *device, int arrival);
72 typedef int (*setmode_t)(void *context, int mode);
73 typedef void (*detectmode_t)(void *context, int *mode);
74 typedef int (*sendrequest_t)(void *context, void *buffer, size_t size);
75 typedef int (*loadfirmware_t)(void *context, void *buffer, size_t size);
76 typedef int (*preload_t)(void *context);
77 typedef int (*postload_t)(void *context);
79 typedef int (*onresponse_t)(void *context, struct smscore_buffer_t *cb);
80 typedef void (*onremove_t)(void *context);
82 struct smscore_buffer_t {
83 /* public members, once passed to clients can be changed freely */
84 struct list_head entry;
88 /* private members, read-only for clients */
91 unsigned long offset_in_common;
94 struct smsdevice_params_t {
95 struct device *device;
103 setmode_t setmode_handler;
104 detectmode_t detectmode_handler;
105 sendrequest_t sendrequest_handler;
106 preload_t preload_handler;
107 postload_t postload_handler;
110 enum sms_device_type_st device_type;
113 struct smsclient_params_t {
116 onresponse_t onresponse_handler;
117 onremove_t onremove_handler;
122 /* GPIO definitions for antenna frequency domain control (SMS8021) */
123 #define SMS_ANTENNA_GPIO_0 1
124 #define SMS_ANTENNA_GPIO_1 0
130 #define BW_ISDBT_1SEG 4
131 #define BW_ISDBT_3SEG 5
133 #define MSG_HDR_FLAG_SPLIT_MSG 4
135 #define MAX_GPIO_PIN_NUMBER 31
138 #define SMS_HOST_LIB 150
139 #define DVBT_BDA_CONTROL_MSG_ID 201
141 #define SMS_MAX_PAYLOAD_SIZE 240
142 #define SMS_TUNE_TIMEOUT 500
144 #define MSG_SMS_GPIO_CONFIG_REQ 507
145 #define MSG_SMS_GPIO_CONFIG_RES 508
146 #define MSG_SMS_GPIO_SET_LEVEL_REQ 509
147 #define MSG_SMS_GPIO_SET_LEVEL_RES 510
148 #define MSG_SMS_GPIO_GET_LEVEL_REQ 511
149 #define MSG_SMS_GPIO_GET_LEVEL_RES 512
150 #define MSG_SMS_RF_TUNE_REQ 561
151 #define MSG_SMS_RF_TUNE_RES 562
152 #define MSG_SMS_INIT_DEVICE_REQ 578
153 #define MSG_SMS_INIT_DEVICE_RES 579
154 #define MSG_SMS_ADD_PID_FILTER_REQ 601
155 #define MSG_SMS_ADD_PID_FILTER_RES 602
156 #define MSG_SMS_REMOVE_PID_FILTER_REQ 603
157 #define MSG_SMS_REMOVE_PID_FILTER_RES 604
158 #define MSG_SMS_DAB_CHANNEL 607
159 #define MSG_SMS_GET_PID_FILTER_LIST_REQ 608
160 #define MSG_SMS_GET_PID_FILTER_LIST_RES 609
161 #define MSG_SMS_GET_STATISTICS_REQ 615
162 #define MSG_SMS_GET_STATISTICS_RES 616
163 #define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651
164 #define MSG_SMS_SET_ANTENNA_CONFIG_RES 652
165 #define MSG_SMS_GET_STATISTICS_EX_REQ 653
166 #define MSG_SMS_GET_STATISTICS_EX_RES 654
167 #define MSG_SMS_SLEEP_RESUME_COMP_IND 655
168 #define MSG_SMS_DATA_DOWNLOAD_REQ 660
169 #define MSG_SMS_DATA_DOWNLOAD_RES 661
170 #define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ 664
171 #define MSG_SMS_SWDOWNLOAD_TRIGGER_RES 665
172 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ 666
173 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES 667
174 #define MSG_SMS_GET_VERSION_EX_REQ 668
175 #define MSG_SMS_GET_VERSION_EX_RES 669
176 #define MSG_SMS_SET_CLOCK_OUTPUT_REQ 670
177 #define MSG_SMS_I2C_SET_FREQ_REQ 685
178 #define MSG_SMS_GENERIC_I2C_REQ 687
179 #define MSG_SMS_GENERIC_I2C_RES 688
180 #define MSG_SMS_DVBT_BDA_DATA 693
181 #define MSG_SW_RELOAD_REQ 697
182 #define MSG_SMS_DATA_MSG 699
183 #define MSG_SW_RELOAD_START_REQ 702
184 #define MSG_SW_RELOAD_START_RES 703
185 #define MSG_SW_RELOAD_EXEC_REQ 704
186 #define MSG_SW_RELOAD_EXEC_RES 705
187 #define MSG_SMS_SPI_INT_LINE_SET_REQ 710
188 #define MSG_SMS_ISDBT_TUNE_REQ 776
189 #define MSG_SMS_ISDBT_TUNE_RES 777
191 #define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
192 (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
193 (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
195 #define SMS_INIT_MSG(ptr, type, len) \
196 SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
198 enum SMS_DEVICE_MODE {
199 DEVICE_MODE_NONE = -1,
200 DEVICE_MODE_DVBT = 0,
202 DEVICE_MODE_DAB_TDMB,
203 DEVICE_MODE_DAB_TDMB_DABIP,
204 DEVICE_MODE_DVBT_BDA,
206 DEVICE_MODE_ISDBT_BDA,
208 DEVICE_MODE_RAW_TUNER,
212 struct SmsMsgHdr_ST {
216 u16 msgLength; /* Length of entire message, including header */
220 struct SmsMsgData_ST {
221 struct SmsMsgHdr_ST xMsgHeader;
225 struct SmsDataDownload_ST {
226 struct SmsMsgHdr_ST xMsgHeader;
228 u8 Payload[SMS_MAX_PAYLOAD_SIZE];
231 struct SmsVersionRes_ST {
232 struct SmsMsgHdr_ST xMsgHeader;
234 u16 ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */
235 u8 Step; /* 0 - Step A */
236 u8 MetalFix; /* 0 - Metal 0 */
238 u8 FirmwareId; /* 0xFF � ROM, otherwise the
240 * SMSHOSTLIB_DEVICE_MODES_E */
241 u8 SupportedProtocols; /* Bitwise OR combination of
242 * supported protocols */
247 u8 VersionFieldPatch;
252 u8 RomVersionFieldPatch;
257 struct SmsFirmware_ST {
264 struct SMSHOSTLIB_STATISTICS_ST {
265 u32 Reserved; /* Reserved */
267 /* Common parameters */
268 u32 IsRfLocked; /* 0 - not locked, 1 - locked */
269 u32 IsDemodLocked; /* 0 - not locked, 1 - locked */
270 u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
272 /* Reception quality */
274 u32 BER; /* Post Viterbi BER [1E-5] */
275 u32 FIB_CRC; /* CRC errors percentage, valid only for DAB */
276 u32 TS_PER; /* Transport stream PER, 0xFFFFFFFF indicate N/A,
277 * valid only for DVB-T/H */
278 u32 MFER; /* DVB-H frame error rate in percentage,
279 * 0xFFFFFFFF indicate N/A, valid only for DVB-H */
281 s32 InBandPwr; /* In band power in dBM */
282 s32 CarrierOffset; /* Carrier Offset in bin/1024 */
284 /* Transmission parameters, valid only for DVB-T/H */
285 u32 Frequency; /* Frequency in Hz */
286 u32 Bandwidth; /* Bandwidth in MHz */
287 u32 TransmissionMode; /* Transmission Mode, for DAB modes 1-4,
288 * for DVB-T/H FFT mode carriers in Kilos */
289 u32 ModemState; /* from SMS_DvbModemState_ET */
290 u32 GuardInterval; /* Guard Interval, 1 divided by value */
291 u32 CodeRate; /* Code Rate from SMS_DvbModemState_ET */
292 u32 LPCodeRate; /* Low Priority Code Rate from SMS_DvbModemState_ET */
293 u32 Hierarchy; /* Hierarchy from SMS_Hierarchy_ET */
294 u32 Constellation; /* Constellation from SMS_Constellation_ET */
296 /* Burst parameters, valid only for DVB-H */
297 u32 BurstSize; /* Current burst size in bytes */
298 u32 BurstDuration; /* Current burst duration in mSec */
299 u32 BurstCycleTime; /* Current burst cycle time in mSec */
300 u32 CalculatedBurstCycleTime; /* Current burst cycle time in mSec,
301 * as calculated by demodulator */
302 u32 NumOfRows; /* Number of rows in MPE table */
303 u32 NumOfPaddCols; /* Number of padding columns in MPE table */
304 u32 NumOfPunctCols; /* Number of puncturing columns in MPE table */
305 /* Burst parameters */
306 u32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
307 u32 TotalTSPackets; /* Total number of transport-stream packets */
308 u32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include
309 * errors after MPE RS decoding */
310 u32 NumOfInvalidMpeTlbs; /* Number of MPE tables which include errors
311 * after MPE RS decoding */
312 u32 NumOfCorrectedMpeTlbs; /* Number of MPE tables which were corrected
313 * by MPE RS decoding */
316 u32 BERErrorCount; /* Number of errornous SYNC bits. */
317 u32 BERBitCount; /* Total number of SYNC bits. */
319 /* Interface information */
320 u32 SmsToHostTxErrors; /* Total number of transmission errors. */
323 u32 PreBER; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
325 /* DVB-H TPS parameters */
326 u32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero;
327 * if set to 0xFFFFFFFF cell_id not yet recovered */
331 struct SmsMsgStatisticsInfo_ST {
334 struct SMSHOSTLIB_STATISTICS_ST Stat;
336 /* Split the calc of the SNR in DAB */
343 struct smsdvb_client_t {
344 struct list_head entry;
346 struct smscore_device_t *coredev;
347 struct smscore_client_t *smsclient;
349 struct dvb_adapter adapter;
350 struct dvb_demux demux;
351 struct dmxdev dmxdev;
352 struct dvb_frontend frontend;
354 fe_status_t fe_status;
355 int fe_ber, fe_snr, fe_signal_strength;
357 struct completion tune_done, stat_done;
359 /* todo: save freq/band instead whole struct */
360 struct dvb_frontend_parameters fe_params;
364 extern void smscore_registry_setmode(char *devpath, int mode);
365 extern int smscore_registry_getmode(char *devpath);
367 extern int smscore_register_hotplug(hotplug_t hotplug);
368 extern void smscore_unregister_hotplug(hotplug_t hotplug);
370 extern int smscore_register_device(struct smsdevice_params_t *params,
371 struct smscore_device_t **coredev);
372 extern void smscore_unregister_device(struct smscore_device_t *coredev);
374 extern int smscore_start_device(struct smscore_device_t *coredev);
375 extern int smscore_load_firmware(struct smscore_device_t *coredev,
377 loadfirmware_t loadfirmware_handler);
379 extern int smscore_set_device_mode(struct smscore_device_t *coredev, int mode);
380 extern int smscore_get_device_mode(struct smscore_device_t *coredev);
382 extern int smscore_register_client(struct smscore_device_t *coredev,
383 struct smsclient_params_t *params,
384 struct smscore_client_t **client);
385 extern void smscore_unregister_client(struct smscore_client_t *client);
387 extern int smsclient_sendrequest(struct smscore_client_t *client,
388 void *buffer, size_t size);
389 extern void smscore_onresponse(struct smscore_device_t *coredev,
390 struct smscore_buffer_t *cb);
394 struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev);
395 extern void smscore_putbuffer(struct smscore_device_t *coredev,
396 struct smscore_buffer_t *cb);
398 void smscore_set_board_id(struct smscore_device_t *core, int id);
399 int smscore_get_board_id(struct smscore_device_t *core);
402 int smsdvb_register(void);
403 void smsdvb_unregister(void);
406 int smsusb_register(void);
407 void smsusb_unregister(void);
409 /* ------------------------------------------------------------------------ */
411 extern int sms_debug;
416 #define sms_printk(kern, fmt, arg...) \
417 printk(kern "%s: " fmt "\n", __func__, ##arg)
419 #define dprintk(kern, lvl, fmt, arg...) do {\
420 if (sms_debug & lvl) \
421 sms_printk(kern, fmt, ##arg); } while (0)
423 #define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
424 #define sms_err(fmt, arg...) \
425 sms_printk(KERN_ERR, "line: %d: " fmt, __LINE__, ##arg)
426 #define sms_warn(fmt, arg...) sms_printk(KERN_WARNING, fmt, ##arg)
427 #define sms_info(fmt, arg...) \
428 dprintk(KERN_INFO, DBG_INFO, fmt, ##arg)
429 #define sms_debug(fmt, arg...) \
430 dprintk(KERN_DEBUG, DBG_ADV, fmt, ##arg)
433 #endif /* __smscoreapi_h__ */