smscoreapi.h 14 KB

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