smscoreapi.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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 3 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. #ifndef __smscoreapi_h__
  22. #define __smscoreapi_h__
  23. #include <linux/version.h>
  24. #include <linux/device.h>
  25. #include <linux/list.h>
  26. #include <linux/mm.h>
  27. #include <asm/scatterlist.h>
  28. #include <asm/page.h>
  29. #include "dmxdev.h"
  30. #include "dvbdev.h"
  31. #include "dvb_demux.h"
  32. #include "dvb_frontend.h"
  33. #include <linux/mutex.h>
  34. #define kmutex_init(_p_) mutex_init(_p_)
  35. #define kmutex_lock(_p_) mutex_lock(_p_)
  36. #define kmutex_trylock(_p_) mutex_trylock(_p_)
  37. #define kmutex_unlock(_p_) mutex_unlock(_p_)
  38. #ifndef min
  39. #define min(a, b) (((a) < (b)) ? (a) : (b))
  40. #endif
  41. #define SMS_ALLOC_ALIGNMENT 128
  42. #define SMS_DMA_ALIGNMENT 16
  43. #define SMS_ALIGN_ADDRESS(addr) \
  44. ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
  45. #define SMS_DEVICE_FAMILY2 1
  46. #define SMS_ROM_NO_RESPONSE 2
  47. #define SMS_DEVICE_NOT_READY 0x8000000
  48. enum sms_device_type_st {
  49. SMS_STELLAR = 0,
  50. SMS_NOVA_A0,
  51. SMS_NOVA_B0,
  52. SMS_VEGA,
  53. SMS_NUM_OF_DEVICE_TYPES
  54. };
  55. struct smscore_device_t;
  56. struct smscore_client_t;
  57. struct smscore_buffer_t;
  58. typedef int (*hotplug_t)(struct smscore_device_t *coredev,
  59. struct device *device, int arrival);
  60. typedef int (*setmode_t)(void *context, int mode);
  61. typedef void (*detectmode_t)(void *context, int *mode);
  62. typedef int (*sendrequest_t)(void *context, void *buffer, size_t size);
  63. typedef int (*loadfirmware_t)(void *context, void *buffer, size_t size);
  64. typedef int (*preload_t)(void *context);
  65. typedef int (*postload_t)(void *context);
  66. typedef int (*onresponse_t)(void *context, struct smscore_buffer_t *cb);
  67. typedef void (*onremove_t)(void *context);
  68. struct smscore_buffer_t {
  69. /* public members, once passed to clients can be changed freely */
  70. struct list_head entry;
  71. int size;
  72. int offset;
  73. /* private members, read-only for clients */
  74. void *p;
  75. dma_addr_t phys;
  76. unsigned long offset_in_common;
  77. };
  78. struct smsdevice_params_t {
  79. struct device *device;
  80. int buffer_size;
  81. int num_buffers;
  82. char devpath[32];
  83. unsigned long flags;
  84. setmode_t setmode_handler;
  85. detectmode_t detectmode_handler;
  86. sendrequest_t sendrequest_handler;
  87. preload_t preload_handler;
  88. postload_t postload_handler;
  89. void *context;
  90. enum sms_device_type_st device_type;
  91. };
  92. struct smsclient_params_t {
  93. int initial_id;
  94. int data_type;
  95. onresponse_t onresponse_handler;
  96. onremove_t onremove_handler;
  97. void *context;
  98. };
  99. /* GPIO definitions for antenna frequency domain control (SMS8021) */
  100. #define SMS_ANTENNA_GPIO_0 1
  101. #define SMS_ANTENNA_GPIO_1 0
  102. #define BW_8_MHZ 0
  103. #define BW_7_MHZ 1
  104. #define BW_6_MHZ 2
  105. #define BW_5_MHZ 3
  106. #define BW_ISDBT_1SEG 4
  107. #define BW_ISDBT_3SEG 5
  108. #define MSG_HDR_FLAG_SPLIT_MSG 4
  109. #define MAX_GPIO_PIN_NUMBER 31
  110. #define HIF_TASK 11
  111. #define SMS_HOST_LIB 150
  112. #define DVBT_BDA_CONTROL_MSG_ID 201
  113. #define SMS_MAX_PAYLOAD_SIZE 240
  114. #define SMS_TUNE_TIMEOUT 500
  115. #define MSG_SMS_GPIO_CONFIG_REQ 507
  116. #define MSG_SMS_GPIO_CONFIG_RES 508
  117. #define MSG_SMS_GPIO_SET_LEVEL_REQ 509
  118. #define MSG_SMS_GPIO_SET_LEVEL_RES 510
  119. #define MSG_SMS_GPIO_GET_LEVEL_REQ 511
  120. #define MSG_SMS_GPIO_GET_LEVEL_RES 512
  121. #define MSG_SMS_RF_TUNE_REQ 561
  122. #define MSG_SMS_RF_TUNE_RES 562
  123. #define MSG_SMS_INIT_DEVICE_REQ 578
  124. #define MSG_SMS_INIT_DEVICE_RES 579
  125. #define MSG_SMS_ADD_PID_FILTER_REQ 601
  126. #define MSG_SMS_ADD_PID_FILTER_RES 602
  127. #define MSG_SMS_REMOVE_PID_FILTER_REQ 603
  128. #define MSG_SMS_REMOVE_PID_FILTER_RES 604
  129. #define MSG_SMS_DAB_CHANNEL 607
  130. #define MSG_SMS_GET_PID_FILTER_LIST_REQ 608
  131. #define MSG_SMS_GET_PID_FILTER_LIST_RES 609
  132. #define MSG_SMS_GET_STATISTICS_REQ 615
  133. #define MSG_SMS_GET_STATISTICS_RES 616
  134. #define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651
  135. #define MSG_SMS_SET_ANTENNA_CONFIG_RES 652
  136. #define MSG_SMS_GET_STATISTICS_EX_REQ 653
  137. #define MSG_SMS_GET_STATISTICS_EX_RES 654
  138. #define MSG_SMS_SLEEP_RESUME_COMP_IND 655
  139. #define MSG_SMS_DATA_DOWNLOAD_REQ 660
  140. #define MSG_SMS_DATA_DOWNLOAD_RES 661
  141. #define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ 664
  142. #define MSG_SMS_SWDOWNLOAD_TRIGGER_RES 665
  143. #define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ 666
  144. #define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES 667
  145. #define MSG_SMS_GET_VERSION_EX_REQ 668
  146. #define MSG_SMS_GET_VERSION_EX_RES 669
  147. #define MSG_SMS_SET_CLOCK_OUTPUT_REQ 670
  148. #define MSG_SMS_I2C_SET_FREQ_REQ 685
  149. #define MSG_SMS_GENERIC_I2C_REQ 687
  150. #define MSG_SMS_GENERIC_I2C_RES 688
  151. #define MSG_SMS_DVBT_BDA_DATA 693
  152. #define MSG_SW_RELOAD_REQ 697
  153. #define MSG_SMS_DATA_MSG 699
  154. #define MSG_SW_RELOAD_START_REQ 702
  155. #define MSG_SW_RELOAD_START_RES 703
  156. #define MSG_SW_RELOAD_EXEC_REQ 704
  157. #define MSG_SW_RELOAD_EXEC_RES 705
  158. #define MSG_SMS_SPI_INT_LINE_SET_REQ 710
  159. #define MSG_SMS_ISDBT_TUNE_REQ 776
  160. #define MSG_SMS_ISDBT_TUNE_RES 777
  161. #define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
  162. (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
  163. (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
  164. } while (0)
  165. #define SMS_INIT_MSG(ptr, type, len) \
  166. SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
  167. enum SMS_DEVICE_MODE {
  168. DEVICE_MODE_NONE = -1,
  169. DEVICE_MODE_DVBT = 0,
  170. DEVICE_MODE_DVBH,
  171. DEVICE_MODE_DAB_TDMB,
  172. DEVICE_MODE_DAB_TDMB_DABIP,
  173. DEVICE_MODE_DVBT_BDA,
  174. DEVICE_MODE_ISDBT,
  175. DEVICE_MODE_ISDBT_BDA,
  176. DEVICE_MODE_CMMB,
  177. DEVICE_MODE_RAW_TUNER,
  178. DEVICE_MODE_MAX,
  179. };
  180. struct SmsMsgHdr_ST {
  181. u16 msgType;
  182. u8 msgSrcId;
  183. u8 msgDstId;
  184. u16 msgLength; /* Length of entire message, including header */
  185. u16 msgFlags;
  186. };
  187. struct SmsMsgData_ST {
  188. struct SmsMsgHdr_ST xMsgHeader;
  189. u32 msgData[1];
  190. };
  191. struct SmsDataDownload_ST {
  192. struct SmsMsgHdr_ST xMsgHeader;
  193. u32 MemAddr;
  194. u8 Payload[SMS_MAX_PAYLOAD_SIZE];
  195. };
  196. struct SmsVersionRes_ST {
  197. struct SmsMsgHdr_ST xMsgHeader;
  198. u16 ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */
  199. u8 Step; /* 0 - Step A */
  200. u8 MetalFix; /* 0 - Metal 0 */
  201. u8 FirmwareId; /* 0xFF � ROM, otherwise the
  202. * value indicated by
  203. * SMSHOSTLIB_DEVICE_MODES_E */
  204. u8 SupportedProtocols; /* Bitwise OR combination of
  205. * supported protocols */
  206. u8 VersionMajor;
  207. u8 VersionMinor;
  208. u8 VersionPatch;
  209. u8 VersionFieldPatch;
  210. u8 RomVersionMajor;
  211. u8 RomVersionMinor;
  212. u8 RomVersionPatch;
  213. u8 RomVersionFieldPatch;
  214. u8 TextLabel[34];
  215. };
  216. struct SmsFirmware_ST {
  217. u32 CheckSum;
  218. u32 Length;
  219. u32 StartAddress;
  220. u8 Payload[1];
  221. };
  222. struct SMSHOSTLIB_STATISTICS_ST {
  223. u32 Reserved; /* Reserved */
  224. /* Common parameters */
  225. u32 IsRfLocked; /* 0 - not locked, 1 - locked */
  226. u32 IsDemodLocked; /* 0 - not locked, 1 - locked */
  227. u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
  228. /* Reception quality */
  229. s32 SNR; /* dB */
  230. u32 BER; /* Post Viterbi BER [1E-5] */
  231. u32 FIB_CRC; /* CRC errors percentage, valid only for DAB */
  232. u32 TS_PER; /* Transport stream PER, 0xFFFFFFFF indicate N/A,
  233. * valid only for DVB-T/H */
  234. u32 MFER; /* DVB-H frame error rate in percentage,
  235. * 0xFFFFFFFF indicate N/A, valid only for DVB-H */
  236. s32 RSSI; /* dBm */
  237. s32 InBandPwr; /* In band power in dBM */
  238. s32 CarrierOffset; /* Carrier Offset in bin/1024 */
  239. /* Transmission parameters, valid only for DVB-T/H */
  240. u32 Frequency; /* Frequency in Hz */
  241. u32 Bandwidth; /* Bandwidth in MHz */
  242. u32 TransmissionMode; /* Transmission Mode, for DAB modes 1-4,
  243. * for DVB-T/H FFT mode carriers in Kilos */
  244. u32 ModemState; /* from SMS_DvbModemState_ET */
  245. u32 GuardInterval; /* Guard Interval, 1 divided by value */
  246. u32 CodeRate; /* Code Rate from SMS_DvbModemState_ET */
  247. u32 LPCodeRate; /* Low Priority Code Rate from SMS_DvbModemState_ET */
  248. u32 Hierarchy; /* Hierarchy from SMS_Hierarchy_ET */
  249. u32 Constellation; /* Constellation from SMS_Constellation_ET */
  250. /* Burst parameters, valid only for DVB-H */
  251. u32 BurstSize; /* Current burst size in bytes */
  252. u32 BurstDuration; /* Current burst duration in mSec */
  253. u32 BurstCycleTime; /* Current burst cycle time in mSec */
  254. u32 CalculatedBurstCycleTime; /* Current burst cycle time in mSec,
  255. * as calculated by demodulator */
  256. u32 NumOfRows; /* Number of rows in MPE table */
  257. u32 NumOfPaddCols; /* Number of padding columns in MPE table */
  258. u32 NumOfPunctCols; /* Number of puncturing columns in MPE table */
  259. /* Burst parameters */
  260. u32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
  261. u32 TotalTSPackets; /* Total number of transport-stream packets */
  262. u32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include
  263. * errors after MPE RS decoding */
  264. u32 NumOfInvalidMpeTlbs; /* Number of MPE tables which include errors
  265. * after MPE RS decoding */
  266. u32 NumOfCorrectedMpeTlbs; /* Number of MPE tables which were corrected
  267. * by MPE RS decoding */
  268. /* Common params */
  269. u32 BERErrorCount; /* Number of errornous SYNC bits. */
  270. u32 BERBitCount; /* Total number of SYNC bits. */
  271. /* Interface information */
  272. u32 SmsToHostTxErrors; /* Total number of transmission errors. */
  273. /* DAB/T-DMB */
  274. u32 PreBER; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
  275. /* DVB-H TPS parameters */
  276. u32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero;
  277. * if set to 0xFFFFFFFF cell_id not yet recovered */
  278. };
  279. struct SmsMsgStatisticsInfo_ST {
  280. u32 RequestResult;
  281. struct SMSHOSTLIB_STATISTICS_ST Stat;
  282. /* Split the calc of the SNR in DAB */
  283. u32 Signal; /* dB */
  284. u32 Noise; /* dB */
  285. };
  286. struct smsdvb_client_t {
  287. struct list_head entry;
  288. struct smscore_device_t *coredev;
  289. struct smscore_client_t *smsclient;
  290. struct dvb_adapter adapter;
  291. struct dvb_demux demux;
  292. struct dmxdev dmxdev;
  293. struct dvb_frontend frontend;
  294. fe_status_t fe_status;
  295. int fe_ber, fe_snr, fe_signal_strength;
  296. struct completion tune_done, stat_done;
  297. /* todo: save freq/band instead whole struct */
  298. struct dvb_frontend_parameters fe_params;
  299. };
  300. extern void smscore_registry_setmode(char *devpath, int mode);
  301. extern int smscore_registry_getmode(char *devpath);
  302. extern int smscore_register_hotplug(hotplug_t hotplug);
  303. extern void smscore_unregister_hotplug(hotplug_t hotplug);
  304. extern int smscore_register_device(struct smsdevice_params_t *params,
  305. struct smscore_device_t **coredev);
  306. extern void smscore_unregister_device(struct smscore_device_t *coredev);
  307. extern int smscore_start_device(struct smscore_device_t *coredev);
  308. extern int smscore_load_firmware(struct smscore_device_t *coredev,
  309. char *filename,
  310. loadfirmware_t loadfirmware_handler);
  311. extern int smscore_set_device_mode(struct smscore_device_t *coredev, int mode);
  312. extern int smscore_get_device_mode(struct smscore_device_t *coredev);
  313. extern int smscore_register_client(struct smscore_device_t *coredev,
  314. struct smsclient_params_t *params,
  315. struct smscore_client_t **client);
  316. extern void smscore_unregister_client(struct smscore_client_t *client);
  317. extern int smsclient_sendrequest(struct smscore_client_t *client,
  318. void *buffer, size_t size);
  319. extern void smscore_onresponse(struct smscore_device_t *coredev,
  320. struct smscore_buffer_t *cb);
  321. extern
  322. struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev);
  323. extern void smscore_putbuffer(struct smscore_device_t *coredev,
  324. struct smscore_buffer_t *cb);
  325. void smscore_set_board_id(struct smscore_device_t *core, int id);
  326. int smscore_get_board_id(struct smscore_device_t *core);
  327. /* smsdvb.c */
  328. int smsdvb_register(void);
  329. void smsdvb_unregister(void);
  330. /* smsusb.c */
  331. int smsusb_register(void);
  332. void smsusb_unregister(void);
  333. /* ------------------------------------------------------------------------ */
  334. extern int sms_debug;
  335. #define DBG_INFO 1
  336. #define DBG_ADV 2
  337. #define sms_printk(kern, fmt, arg...) \
  338. printk(kern "%s: " fmt "\n", __func__, ##arg)
  339. #define dprintk(kern, lvl, fmt, arg...) do {\
  340. if (sms_debug & lvl) \
  341. sms_printk(kern, fmt, ##arg); } while (0)
  342. #define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
  343. #define sms_err(fmt, arg...) \
  344. sms_printk(KERN_ERR, "line: %d: " fmt, __LINE__, ##arg)
  345. #define sms_warn(fmt, arg...) sms_printk(KERN_WARNING, fmt, ##arg)
  346. #define sms_info(fmt, arg...) \
  347. dprintk(KERN_INFO, DBG_INFO, fmt, ##arg)
  348. #define sms_debug(fmt, arg...) \
  349. dprintk(KERN_DEBUG, DBG_ADV, fmt, ##arg)
  350. #endif /* __smscoreapi_h__ */