1 /****************************************************************
3 Siano Mobile Silicon, Inc.
4 MDTV receiver kernel modules.
5 Copyright (C) 2006-2008, Uri Shkolnik
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 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, see <http://www.gnu.org/licenses/>.
20 ****************************************************************/
22 #ifndef __SMS_CORE_API_H__
23 #define __SMS_CORE_API_H__
25 #include <linux/version.h>
26 #include <linux/device.h>
27 #include <linux/list.h>
29 #include <linux/scatterlist.h>
30 #include <linux/types.h>
32 #include <linux/mutex.h>
35 #ifdef SMS_DVB3_SUBSYS
38 #include "dvb_demux.h"
39 #include "dvb_frontend.h"
42 #define SIANO_HALFDUPLEX 1
44 #define kmutex_init(_p_) mutex_init(_p_)
45 #define kmutex_lock(_p_) mutex_lock(_p_)
46 #define kmutex_trylock(_p_) mutex_trylock(_p_)
47 #define kmutex_unlock(_p_) mutex_unlock(_p_)
50 #define min(a, b) (((a) < (b)) ? (a) : (b))
53 #define SMS_ALLOC_ALIGNMENT 128
54 #define SMS_DMA_ALIGNMENT 16
55 #define SMS_ALIGN_ADDRESS(addr) \
56 ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
58 #define SMS_DEVICE_FAMILY2 1
59 #define SMS_ROM_NO_RESPONSE 2
60 #define SMS_DEVICE_NOT_READY 0x8000000
62 enum sms_device_type_st {
67 SMS_NUM_OF_DEVICE_TYPES
70 struct smscore_device_t;
71 struct smscore_client_t;
72 struct smscore_buffer_t;
74 typedef int (*hotplug_t) (struct smscore_device_t *coredev,
75 struct device *device, int arrival);
77 typedef int (*setmode_t) (void *context, int mode);
78 typedef void (*detectmode_t) (void *context, int *mode);
79 typedef int (*sendrequest_t) (void *context, void *buffer, size_t size);
80 typedef int (*loadfirmware_t) (void *context, void *buffer, size_t size);
81 typedef int (*preload_t) (void *context);
82 typedef int (*postload_t) (void *context);
84 typedef int (*onresponse_t) (void *context, struct smscore_buffer_t *cb);
85 typedef void (*onremove_t) (void *context);
87 struct smscore_buffer_t {
88 /* public members, once passed to clients can be changed freely */
89 struct list_head entry;
93 /* private members, read-only for clients */
96 unsigned long offset_in_common;
99 struct smsdevice_params_t {
100 struct device *device;
108 setmode_t setmode_handler;
109 detectmode_t detectmode_handler;
110 sendrequest_t sendrequest_handler;
111 preload_t preload_handler;
112 postload_t postload_handler;
115 enum sms_device_type_st device_type;
118 struct smsclient_params_t {
121 onresponse_t onresponse_handler;
122 onremove_t onremove_handler;
127 /* GPIO definitions for antenna frequency domain control (SMS8021) */
128 #define SMS_ANTENNA_GPIO_0 1
129 #define SMS_ANTENNA_GPIO_1 0
135 #define BW_ISDBT_1SEG 4
136 #define BW_ISDBT_3SEG 5
138 #define MSG_HDR_FLAG_SPLIT_MSG 4
140 #define MAX_GPIO_PIN_NUMBER 31
143 #define SMS_HOST_LIB 150
144 #define DVBT_BDA_CONTROL_MSG_ID 201
146 #define SMS_MAX_PAYLOAD_SIZE 240
147 #define SMS_TUNE_TIMEOUT 500
149 #define MSG_SMS_GPIO_CONFIG_REQ 507
150 #define MSG_SMS_GPIO_CONFIG_RES 508
151 #define MSG_SMS_GPIO_SET_LEVEL_REQ 509
152 #define MSG_SMS_GPIO_SET_LEVEL_RES 510
153 #define MSG_SMS_GPIO_GET_LEVEL_REQ 511
154 #define MSG_SMS_GPIO_GET_LEVEL_RES 512
155 #define MSG_SMS_RF_TUNE_REQ 561
156 #define MSG_SMS_RF_TUNE_RES 562
157 #define MSG_SMS_INIT_DEVICE_REQ 578
158 #define MSG_SMS_INIT_DEVICE_RES 579
159 #define MSG_SMS_ADD_PID_FILTER_REQ 601
160 #define MSG_SMS_ADD_PID_FILTER_RES 602
161 #define MSG_SMS_REMOVE_PID_FILTER_REQ 603
162 #define MSG_SMS_REMOVE_PID_FILTER_RES 604
163 #define MSG_SMS_DAB_CHANNEL 607
164 #define MSG_SMS_GET_PID_FILTER_LIST_REQ 608
165 #define MSG_SMS_GET_PID_FILTER_LIST_RES 609
166 #define MSG_SMS_GET_STATISTICS_REQ 615
167 #define MSG_SMS_GET_STATISTICS_RES 616
168 #define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651
169 #define MSG_SMS_SET_ANTENNA_CONFIG_RES 652
170 #define MSG_SMS_GET_STATISTICS_EX_REQ 653
171 #define MSG_SMS_GET_STATISTICS_EX_RES 654
172 #define MSG_SMS_SLEEP_RESUME_COMP_IND 655
174 #define MSG_SMS_SET_PERIODIC_STATS_REQ 658
175 #define MSG_SMS_SET_PERIODIC_STATS_RES 659
177 #define MSG_SMS_DATA_DOWNLOAD_REQ 660
178 #define MSG_SMS_DATA_DOWNLOAD_RES 661
179 #define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ 664
180 #define MSG_SMS_SWDOWNLOAD_TRIGGER_RES 665
181 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ 666
182 #define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES 667
183 #define MSG_SMS_GET_VERSION_EX_REQ 668
184 #define MSG_SMS_GET_VERSION_EX_RES 669
185 #define MSG_SMS_SET_CLOCK_OUTPUT_REQ 670
186 #define MSG_SMS_I2C_SET_FREQ_REQ 685
187 #define MSG_SMS_GENERIC_I2C_REQ 687
188 #define MSG_SMS_GENERIC_I2C_RES 688
189 #define MSG_SMS_DVBT_BDA_DATA 693
190 #define MSG_SW_RELOAD_REQ 697
191 #define MSG_SMS_DATA_MSG 699
192 #define MSG_SW_RELOAD_START_REQ 702
193 #define MSG_SW_RELOAD_START_RES 703
194 #define MSG_SW_RELOAD_EXEC_REQ 704
195 #define MSG_SW_RELOAD_EXEC_RES 705
196 #define MSG_SMS_SPI_INT_LINE_SET_REQ 710
197 #define MSG_SMS_GPIO_CONFIG_EX_REQ 712
198 #define MSG_SMS_GPIO_CONFIG_EX_RES 713
199 #define MSG_SMS_ISDBT_TUNE_REQ 776
200 #define MSG_SMS_ISDBT_TUNE_RES 777
202 #define MSG_SMS_LOOPBACK_REQ 718
203 #define MSG_SMS_LOOPBACK_RES 719
206 #define MSG_SMS_SPI_HALFDUPLEX_TOKEN_HOST_TO_DEVICE 518 //, // SPI Half-Duplex protocol
207 #define MSG_SMS_SPI_HALFDUPLEX_TOKEN_DEVICE_TO_HOST 519 //, //
210 #define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
211 (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
212 (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
214 #define SMS_INIT_MSG(ptr, type, len) \
215 SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
217 enum SMS_DVB3_EVENTS {
222 DVB3_EVENT_FE_UNLOCK,
227 enum SMS_DEVICE_MODE {
228 DEVICE_MODE_NONE = -1,
229 DEVICE_MODE_DVBT = 0,
231 DEVICE_MODE_DAB_TDMB,
232 DEVICE_MODE_DAB_TDMB_DABIP,
233 DEVICE_MODE_DVBT_BDA,
235 DEVICE_MODE_ISDBT_BDA,
237 DEVICE_MODE_RAW_TUNER,
241 struct SmsMsgHdr_ST {
245 u16 msgLength; /* Length of entire message, including header */
249 struct SmsMsgData_ST {
250 struct SmsMsgHdr_ST xMsgHeader;
254 struct SmsDataDownload_ST {
255 struct SmsMsgHdr_ST xMsgHeader;
257 u8 Payload[SMS_MAX_PAYLOAD_SIZE];
260 struct SmsVersionRes_ST {
261 struct SmsMsgHdr_ST xMsgHeader;
263 u16 ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */
264 u8 Step; /* 0 - Step A */
265 u8 MetalFix; /* 0 - Metal 0 */
267 u8 FirmwareId; /* 0xFF ROM, otherwise the
269 * SMSHOSTLIB_DEVICE_MODES_E */
270 u8 SupportedProtocols; /* Bitwise OR combination of
271 * supported protocols */
276 u8 VersionFieldPatch;
281 u8 RomVersionFieldPatch;
286 struct SmsFirmware_ST {
293 struct SMSHOSTLIB_STATISTICS_ST {
294 u32 Reserved; /* Reserved */
296 /* Common parameters */
297 u32 IsRfLocked; /* 0 - not locked, 1 - locked */
298 u32 IsDemodLocked; /* 0 - not locked, 1 - locked */
299 u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
301 /* Reception quality */
303 u32 BER; /* Post Viterbi BER [1E-5] */
304 u32 FIB_CRC; /* CRC errors percentage, valid only for DAB */
305 u32 TS_PER; /* Transport stream PER, 0xFFFFFFFF
306 * indicate N/A, valid only for DVB-T/H */
307 u32 MFER; /* DVB-H frame error rate in percentage,
308 * 0xFFFFFFFF indicate N/A, valid
311 s32 InBandPwr; /* In band power in dBM */
312 s32 CarrierOffset; /* Carrier Offset in bin/1024 */
314 /* Transmission parameters, valid only for DVB-T/H */
315 u32 Frequency; /* Frequency in Hz */
316 u32 Bandwidth; /* Bandwidth in MHz */
317 u32 TransmissionMode; /* Transmission Mode, for DAB modes 1-4,
318 * for DVB-T/H FFT mode carriers in Kilos */
319 u32 ModemState; /* from SMS_DvbModemState_ET */
320 u32 GuardInterval; /* Guard Interval, 1 divided by value */
321 u32 CodeRate; /* Code Rate from SMS_DvbModemState_ET */
322 u32 LPCodeRate; /* Low Priority Code Rate from
323 * SMS_DvbModemState_ET */
324 u32 Hierarchy; /* Hierarchy from SMS_Hierarchy_ET */
325 u32 Constellation; /* Constellation from SMS_Constellation_ET */
327 /* Burst parameters, valid only for DVB-H */
328 u32 BurstSize; /* Current burst size in bytes */
329 u32 BurstDuration; /* Current burst duration in mSec */
330 u32 BurstCycleTime; /* Current burst cycle time in mSec */
331 u32 CalculatedBurstCycleTime; /* Current burst cycle time in mSec,
332 * as calculated by demodulator */
333 u32 NumOfRows; /* Number of rows in MPE table */
334 u32 NumOfPaddCols; /* Number of padding columns in MPE table */
335 u32 NumOfPunctCols; /* Number of puncturing columns in MPE table */
336 /* Burst parameters */
337 u32 ErrorTSPackets; /* Number of erroneous transport-stream
339 u32 TotalTSPackets; /* Total number of transport-stream packets */
340 u32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include
341 * errors after MPE RS decoding */
342 u32 NumOfInvalidMpeTlbs;/* Number of MPE tables which include errors
343 * after MPE RS decoding */
344 u32 NumOfCorrectedMpeTlbs; /* Number of MPE tables which were corrected
345 * by MPE RS decoding */
348 u32 BERErrorCount; /* Number of errornous SYNC bits. */
349 u32 BERBitCount; /* Total number of SYNC bits. */
351 /* Interface information */
352 u32 SmsToHostTxErrors; /* Total number of transmission errors. */
355 u32 PreBER; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
357 /* DVB-H TPS parameters */
358 u32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero;
359 * if set to 0xFFFFFFFF cell_id not
364 struct SmsMsgStatisticsInfo_ST {
367 struct SMSHOSTLIB_STATISTICS_ST Stat;
369 /* Split the calc of the SNR in DAB */
375 struct smscore_gpio_config {
376 #define SMS_GPIO_DIRECTION_INPUT 0
377 #define SMS_GPIO_DIRECTION_OUTPUT 1
380 #define SMS_GPIO_PULLUPDOWN_NONE 0
381 #define SMS_GPIO_PULLUPDOWN_PULLDOWN 1
382 #define SMS_GPIO_PULLUPDOWN_PULLUP 2
383 #define SMS_GPIO_PULLUPDOWN_KEEPER 3
386 #define SMS_GPIO_INPUTCHARACTERISTICS_NORMAL 0
387 #define SMS_GPIO_INPUTCHARACTERISTICS_SCHMITT 1
388 u8 InputCharacteristics;
390 #define SMS_GPIO_OUTPUTSLEWRATE_SLOW 0 /* 10xx */
391 #define SMS_GPIO_OUTPUTSLEWRATE_FAST 1 /* 10xx */
393 #define SMS_GPIO_OUTPUTSLEWRATE_0_45_V_NS 0 /* 11xx */
394 #define SMS_GPIO_OUTPUTSLEWRATE_0_9_V_NS 1 /* 11xx */
395 #define SMS_GPIO_OUTPUTSLEWRATE_1_7_V_NS 2 /* 11xx */
396 #define SMS_GPIO_OUTPUTSLEWRATE_3_3_V_NS 3 /* 11xx */
399 #define SMS_GPIO_OUTPUTDRIVING_S_4mA 0 /* 10xx */
400 #define SMS_GPIO_OUTPUTDRIVING_S_8mA 1 /* 10xx */
401 #define SMS_GPIO_OUTPUTDRIVING_S_12mA 2 /* 10xx */
402 #define SMS_GPIO_OUTPUTDRIVING_S_16mA 3 /* 10xx */
404 #define SMS_GPIO_OUTPUTDRIVING_1_5mA 0 /* 11xx */
405 #define SMS_GPIO_OUTPUTDRIVING_2_8mA 1 /* 11xx */
406 #define SMS_GPIO_OUTPUTDRIVING_4mA 2 /* 11xx */
407 #define SMS_GPIO_OUTPUTDRIVING_7mA 3 /* 11xx */
408 #define SMS_GPIO_OUTPUTDRIVING_10mA 4 /* 11xx */
409 #define SMS_GPIO_OUTPUTDRIVING_11mA 5 /* 11xx */
410 #define SMS_GPIO_OUTPUTDRIVING_14mA 6 /* 11xx */
411 #define SMS_GPIO_OUTPUTDRIVING_16mA 7 /* 11xx */
415 #ifdef SMS_DVB3_SUBSYS
417 struct smsdvb_client_t {
418 struct list_head entry;
420 struct smscore_device_t *coredev;
421 struct smscore_client_t *smsclient;
423 struct dvb_adapter adapter;
424 struct dvb_demux demux;
425 struct dmxdev dmxdev;
426 struct dvb_frontend frontend;
428 fe_status_t fe_status;
429 int fe_ber, fe_snr, fe_unc, fe_signal_strength;
431 struct completion tune_done, stat_done;
433 /* todo: save freq/band instead whole struct */
434 struct dvb_frontend_parameters fe_params;
437 #endif /* SMS_DVB3_SUBSYS */
439 extern void smsspi_poweron(void);
440 extern void smsspi_off(void);
441 extern void smscore_registry_setmode(char *devpath, int mode);
442 extern int smscore_registry_getmode(char *devpath);
444 extern int smscore_register_hotplug(hotplug_t hotplug);
445 extern void smscore_unregister_hotplug(hotplug_t hotplug);
447 extern int smscore_register_device(struct smsdevice_params_t *params,
448 struct smscore_device_t **coredev);
449 extern void smscore_unregister_device(struct smscore_device_t *coredev);
451 extern int smscore_start_device(struct smscore_device_t *coredev);
452 extern int smscore_load_firmware(struct smscore_device_t *coredev,
454 loadfirmware_t loadfirmware_handler);
455 extern int smscore_set_device_mode(struct smscore_device_t *coredev, int mode);
456 extern int smscore_get_device_mode(struct smscore_device_t *coredev);
457 // Peter add on June 18, 2009
458 extern int smscore_reset_device_drvs(struct smscore_device_t *coredev);
459 extern int smscore_get_fw_filename(struct smscore_device_t *coredev, int mode,
461 extern int smscore_send_fw_file(struct smscore_device_t *coredev, u8 *ufwbuf,
464 extern int smscore_register_client(struct smscore_device_t *coredev,
465 struct smsclient_params_t *params,
466 struct smscore_client_t **client);
467 extern void smscore_unregister_client(struct smscore_client_t *client);
469 extern int smsclient_sendrequest(struct smscore_client_t *client,
470 void *buffer, size_t size);
471 extern void smscore_onresponse(struct smscore_device_t *coredev,
472 struct smscore_buffer_t *cb);
474 extern int smscore_get_common_buffer_size(struct smscore_device_t *coredev);
475 extern int smscore_map_common_buffer(struct smscore_device_t *coredev,
476 struct vm_area_struct *vma);
478 extern struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t
480 extern void smscore_putbuffer(struct smscore_device_t *coredev,
481 struct smscore_buffer_t *cb);
483 int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
484 struct smscore_gpio_config *pGpioConfig);
485 int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
487 int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum,
490 void smscore_set_board_id(struct smscore_device_t *core, int id);
491 int smscore_get_board_id(struct smscore_device_t *core);
493 #ifdef SMS_HOSTLIB_SUBSYS
494 extern int smschar_register(void);
495 extern void smschar_unregister(void);
498 #ifdef SMS_NET_SUBSYS
499 extern int smsnet_register(void);
500 extern void smsnet_unregister(void);
503 #ifdef SMS_DVB3_SUBSYS
504 extern int smsdvb_register(void);
505 extern void smsdvb_unregister(void);
509 extern int smsusb_register(void);
510 extern void smsusb_unregister(void);
514 extern int smssdio_register(void);
515 extern void smssdio_unregister(void);
518 #ifdef SMS_SPI_ROCKCHIP
519 extern int smsspi_register(void);
520 extern void smsspi_unregister(void);
523 /* ------------------------------------------------------------------------ */
525 extern int sms_debug;
531 #define sms_printk(kern, fmt, arg...) \
532 printk(kern " " fmt "\n", ##arg) // to save log
534 #define dprintk(kern, lvl, fmt, arg...) do {\
535 if (sms_debug & lvl) \
536 sms_printk(kern, fmt, ##arg); } while (0)
538 #define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
539 #define sms_err(fmt, arg...) \
540 sms_printk(KERN_ERR, "line: %d: " fmt, __LINE__, ##arg)
541 #define sms_warn(fmt, arg...) sms_printk(KERN_WARNING, fmt, ##arg)
542 #define sms_info(fmt, arg...) \
543 dprintk(KERN_INFO, DBG_INFO, fmt, ##arg)
544 #define sms_debug(fmt, arg...) \
545 dprintk(KERN_INFO, DBG_INFO, fmt, ##arg)
548 #endif /* __SMS_CORE_API_H__ */