smscoreapi.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. /****************************************************************
  2. Siano Mobile Silicon, Inc.
  3. MDTV receiver kernel modules.
  4. Copyright (C) 2006-2008, Uri Shkolnik, Anatoly Greenblat
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ****************************************************************/
  16. #ifndef __SMS_CORE_API_H__
  17. #define __SMS_CORE_API_H__
  18. #include <linux/version.h>
  19. #include <linux/device.h>
  20. #include <linux/list.h>
  21. #include <linux/mm.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/types.h>
  24. #include <asm/page.h>
  25. #include <linux/mutex.h>
  26. #include "dmxdev.h"
  27. #include "dvbdev.h"
  28. #include "dvb_demux.h"
  29. #include "dvb_frontend.h"
  30. #define kmutex_init(_p_) mutex_init(_p_)
  31. #define kmutex_lock(_p_) mutex_lock(_p_)
  32. #define kmutex_trylock(_p_) mutex_trylock(_p_)
  33. #define kmutex_unlock(_p_) mutex_unlock(_p_)
  34. #ifndef min
  35. #define min(a, b) (((a) < (b)) ? (a) : (b))
  36. #endif
  37. #define SMS_PROTOCOL_MAX_RAOUNDTRIP_MS (10000)
  38. #define SMS_ALLOC_ALIGNMENT 128
  39. #define SMS_DMA_ALIGNMENT 16
  40. #define SMS_ALIGN_ADDRESS(addr) \
  41. ((((uintptr_t)(addr)) + (SMS_DMA_ALIGNMENT-1)) & ~(SMS_DMA_ALIGNMENT-1))
  42. #define SMS_DEVICE_FAMILY2 1
  43. #define SMS_ROM_NO_RESPONSE 2
  44. #define SMS_DEVICE_NOT_READY 0x8000000
  45. enum sms_device_type_st {
  46. SMS_STELLAR = 0,
  47. SMS_NOVA_A0,
  48. SMS_NOVA_B0,
  49. SMS_VEGA,
  50. SMS_NUM_OF_DEVICE_TYPES
  51. };
  52. struct smscore_device_t;
  53. struct smscore_client_t;
  54. struct smscore_buffer_t;
  55. typedef int (*hotplug_t)(struct smscore_device_t *coredev,
  56. struct device *device, int arrival);
  57. typedef int (*setmode_t)(void *context, int mode);
  58. typedef void (*detectmode_t)(void *context, int *mode);
  59. typedef int (*sendrequest_t)(void *context, void *buffer, size_t size);
  60. typedef int (*loadfirmware_t)(void *context, void *buffer, size_t size);
  61. typedef int (*preload_t)(void *context);
  62. typedef int (*postload_t)(void *context);
  63. typedef int (*onresponse_t)(void *context, struct smscore_buffer_t *cb);
  64. typedef void (*onremove_t)(void *context);
  65. struct smscore_buffer_t {
  66. /* public members, once passed to clients can be changed freely */
  67. struct list_head entry;
  68. int size;
  69. int offset;
  70. /* private members, read-only for clients */
  71. void *p;
  72. dma_addr_t phys;
  73. unsigned long offset_in_common;
  74. };
  75. struct smsdevice_params_t {
  76. struct device *device;
  77. int buffer_size;
  78. int num_buffers;
  79. char devpath[32];
  80. unsigned long flags;
  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;
  86. void *context;
  87. enum sms_device_type_st device_type;
  88. };
  89. struct smsclient_params_t {
  90. int initial_id;
  91. int data_type;
  92. onresponse_t onresponse_handler;
  93. onremove_t onremove_handler;
  94. void *context;
  95. };
  96. struct smscore_device_t {
  97. struct list_head entry;
  98. struct list_head clients;
  99. struct list_head subclients;
  100. spinlock_t clientslock;
  101. struct list_head buffers;
  102. spinlock_t bufferslock;
  103. int num_buffers;
  104. void *common_buffer;
  105. int common_buffer_size;
  106. dma_addr_t common_buffer_phys;
  107. void *context;
  108. struct device *device;
  109. char devpath[32];
  110. unsigned long device_flags;
  111. setmode_t setmode_handler;
  112. detectmode_t detectmode_handler;
  113. sendrequest_t sendrequest_handler;
  114. preload_t preload_handler;
  115. postload_t postload_handler;
  116. int mode, modes_supported;
  117. /* host <--> device messages */
  118. struct completion version_ex_done, data_download_done, trigger_done;
  119. struct completion init_device_done, reload_start_done, resume_done;
  120. struct completion gpio_configuration_done, gpio_set_level_done;
  121. struct completion gpio_get_level_done, ir_init_done;
  122. /* Buffer management */
  123. wait_queue_head_t buffer_mng_waitq;
  124. /* GPIO */
  125. int gpio_get_res;
  126. /* Target hardware board */
  127. int board_id;
  128. /* Firmware */
  129. u8 *fw_buf;
  130. u32 fw_buf_size;
  131. /* Infrared (IR) */
  132. /* struct ir_t ir; */
  133. int led_state;
  134. };
  135. /* GPIO definitions for antenna frequency domain control (SMS8021) */
  136. #define SMS_ANTENNA_GPIO_0 1
  137. #define SMS_ANTENNA_GPIO_1 0
  138. #define BW_8_MHZ 0
  139. #define BW_7_MHZ 1
  140. #define BW_6_MHZ 2
  141. #define BW_5_MHZ 3
  142. #define BW_ISDBT_1SEG 4
  143. #define BW_ISDBT_3SEG 5
  144. #define MSG_HDR_FLAG_SPLIT_MSG 4
  145. #define MAX_GPIO_PIN_NUMBER 31
  146. #define HIF_TASK 11
  147. #define SMS_HOST_LIB 150
  148. #define DVBT_BDA_CONTROL_MSG_ID 201
  149. #define SMS_MAX_PAYLOAD_SIZE 240
  150. #define SMS_TUNE_TIMEOUT 500
  151. #define MSG_SMS_GPIO_CONFIG_REQ 507
  152. #define MSG_SMS_GPIO_CONFIG_RES 508
  153. #define MSG_SMS_GPIO_SET_LEVEL_REQ 509
  154. #define MSG_SMS_GPIO_SET_LEVEL_RES 510
  155. #define MSG_SMS_GPIO_GET_LEVEL_REQ 511
  156. #define MSG_SMS_GPIO_GET_LEVEL_RES 512
  157. #define MSG_SMS_RF_TUNE_REQ 561
  158. #define MSG_SMS_RF_TUNE_RES 562
  159. #define MSG_SMS_INIT_DEVICE_REQ 578
  160. #define MSG_SMS_INIT_DEVICE_RES 579
  161. #define MSG_SMS_ADD_PID_FILTER_REQ 601
  162. #define MSG_SMS_ADD_PID_FILTER_RES 602
  163. #define MSG_SMS_REMOVE_PID_FILTER_REQ 603
  164. #define MSG_SMS_REMOVE_PID_FILTER_RES 604
  165. #define MSG_SMS_DAB_CHANNEL 607
  166. #define MSG_SMS_GET_PID_FILTER_LIST_REQ 608
  167. #define MSG_SMS_GET_PID_FILTER_LIST_RES 609
  168. #define MSG_SMS_GET_STATISTICS_REQ 615
  169. #define MSG_SMS_GET_STATISTICS_RES 616
  170. #define MSG_SMS_HO_PER_SLICES_IND 630
  171. #define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651
  172. #define MSG_SMS_SET_ANTENNA_CONFIG_RES 652
  173. #define MSG_SMS_GET_STATISTICS_EX_REQ 653
  174. #define MSG_SMS_GET_STATISTICS_EX_RES 654
  175. #define MSG_SMS_SLEEP_RESUME_COMP_IND 655
  176. #define MSG_SMS_DATA_DOWNLOAD_REQ 660
  177. #define MSG_SMS_DATA_DOWNLOAD_RES 661
  178. #define MSG_SMS_SWDOWNLOAD_TRIGGER_REQ 664
  179. #define MSG_SMS_SWDOWNLOAD_TRIGGER_RES 665
  180. #define MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ 666
  181. #define MSG_SMS_SWDOWNLOAD_BACKDOOR_RES 667
  182. #define MSG_SMS_GET_VERSION_EX_REQ 668
  183. #define MSG_SMS_GET_VERSION_EX_RES 669
  184. #define MSG_SMS_SET_CLOCK_OUTPUT_REQ 670
  185. #define MSG_SMS_I2C_SET_FREQ_REQ 685
  186. #define MSG_SMS_GENERIC_I2C_REQ 687
  187. #define MSG_SMS_GENERIC_I2C_RES 688
  188. #define MSG_SMS_DVBT_BDA_DATA 693
  189. #define MSG_SW_RELOAD_REQ 697
  190. #define MSG_SMS_DATA_MSG 699
  191. #define MSG_SW_RELOAD_START_REQ 702
  192. #define MSG_SW_RELOAD_START_RES 703
  193. #define MSG_SW_RELOAD_EXEC_REQ 704
  194. #define MSG_SW_RELOAD_EXEC_RES 705
  195. #define MSG_SMS_SPI_INT_LINE_SET_REQ 710
  196. #define MSG_SMS_GPIO_CONFIG_EX_REQ 712
  197. #define MSG_SMS_GPIO_CONFIG_EX_RES 713
  198. #define MSG_SMS_ISDBT_TUNE_REQ 776
  199. #define MSG_SMS_ISDBT_TUNE_RES 777
  200. #define MSG_SMS_TRANSMISSION_IND 782
  201. #define MSG_SMS_START_IR_REQ 800
  202. #define MSG_SMS_START_IR_RES 801
  203. #define MSG_SMS_IR_SAMPLES_IND 802
  204. #define MSG_SMS_SIGNAL_DETECTED_IND 827
  205. #define MSG_SMS_NO_SIGNAL_IND 828
  206. #define SMS_INIT_MSG_EX(ptr, type, src, dst, len) do { \
  207. (ptr)->msgType = type; (ptr)->msgSrcId = src; (ptr)->msgDstId = dst; \
  208. (ptr)->msgLength = len; (ptr)->msgFlags = 0; \
  209. } while (0)
  210. #define SMS_INIT_MSG(ptr, type, len) \
  211. SMS_INIT_MSG_EX(ptr, type, 0, HIF_TASK, len)
  212. enum SMS_DVB3_EVENTS {
  213. DVB3_EVENT_INIT = 0,
  214. DVB3_EVENT_SLEEP,
  215. DVB3_EVENT_HOTPLUG,
  216. DVB3_EVENT_FE_LOCK,
  217. DVB3_EVENT_FE_UNLOCK,
  218. DVB3_EVENT_UNC_OK,
  219. DVB3_EVENT_UNC_ERR
  220. };
  221. enum SMS_DEVICE_MODE {
  222. DEVICE_MODE_NONE = -1,
  223. DEVICE_MODE_DVBT = 0,
  224. DEVICE_MODE_DVBH,
  225. DEVICE_MODE_DAB_TDMB,
  226. DEVICE_MODE_DAB_TDMB_DABIP,
  227. DEVICE_MODE_DVBT_BDA,
  228. DEVICE_MODE_ISDBT,
  229. DEVICE_MODE_ISDBT_BDA,
  230. DEVICE_MODE_CMMB,
  231. DEVICE_MODE_RAW_TUNER,
  232. DEVICE_MODE_MAX,
  233. };
  234. struct SmsMsgHdr_ST {
  235. u16 msgType;
  236. u8 msgSrcId;
  237. u8 msgDstId;
  238. u16 msgLength; /* Length of entire message, including header */
  239. u16 msgFlags;
  240. };
  241. struct SmsMsgData_ST {
  242. struct SmsMsgHdr_ST xMsgHeader;
  243. u32 msgData[1];
  244. };
  245. struct SmsMsgData_ST2 {
  246. struct SmsMsgHdr_ST xMsgHeader;
  247. u32 msgData[2];
  248. };
  249. struct SmsDataDownload_ST {
  250. struct SmsMsgHdr_ST xMsgHeader;
  251. u32 MemAddr;
  252. u8 Payload[SMS_MAX_PAYLOAD_SIZE];
  253. };
  254. struct SmsVersionRes_ST {
  255. struct SmsMsgHdr_ST xMsgHeader;
  256. u16 ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */
  257. u8 Step; /* 0 - Step A */
  258. u8 MetalFix; /* 0 - Metal 0 */
  259. /* FirmwareId 0xFF if ROM, otherwise the
  260. * value indicated by SMSHOSTLIB_DEVICE_MODES_E */
  261. u8 FirmwareId;
  262. /* SupportedProtocols Bitwise OR combination of
  263. * supported protocols */
  264. u8 SupportedProtocols;
  265. u8 VersionMajor;
  266. u8 VersionMinor;
  267. u8 VersionPatch;
  268. u8 VersionFieldPatch;
  269. u8 RomVersionMajor;
  270. u8 RomVersionMinor;
  271. u8 RomVersionPatch;
  272. u8 RomVersionFieldPatch;
  273. u8 TextLabel[34];
  274. };
  275. struct SmsFirmware_ST {
  276. u32 CheckSum;
  277. u32 Length;
  278. u32 StartAddress;
  279. u8 Payload[1];
  280. };
  281. struct SMSHOSTLIB_STATISTICS_ST {
  282. u32 Reserved; /* Reserved */
  283. /* Common parameters */
  284. u32 IsRfLocked; /* 0 - not locked, 1 - locked */
  285. u32 IsDemodLocked; /* 0 - not locked, 1 - locked */
  286. u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
  287. /* Reception quality */
  288. s32 SNR; /* dB */
  289. u32 BER; /* Post Viterbi BER [1E-5] */
  290. u32 FIB_CRC; /* CRC errors percentage, valid only for DAB */
  291. /* Transport stream PER, 0xFFFFFFFF indicate N/A,
  292. * valid only for DVB-T/H */
  293. u32 TS_PER;
  294. /* DVB-H frame error rate in percentage,
  295. * 0xFFFFFFFF indicate N/A, valid only for DVB-H */
  296. u32 MFER;
  297. s32 RSSI; /* dBm */
  298. s32 InBandPwr; /* In band power in dBM */
  299. s32 CarrierOffset; /* Carrier Offset in bin/1024 */
  300. /* Transmission parameters, valid only for DVB-T/H */
  301. u32 Frequency; /* Frequency in Hz */
  302. u32 Bandwidth; /* Bandwidth in MHz */
  303. /* Transmission Mode, for DAB modes 1-4,
  304. * for DVB-T/H FFT mode carriers in Kilos */
  305. u32 TransmissionMode;
  306. u32 ModemState; /* from SMS_DvbModemState_ET */
  307. u32 GuardInterval; /* Guard Interval, 1 divided by value */
  308. u32 CodeRate; /* Code Rate from SMS_DvbModemState_ET */
  309. u32 LPCodeRate; /* Low Priority Code Rate from SMS_DvbModemState_ET */
  310. u32 Hierarchy; /* Hierarchy from SMS_Hierarchy_ET */
  311. u32 Constellation; /* Constellation from SMS_Constellation_ET */
  312. /* Burst parameters, valid only for DVB-H */
  313. u32 BurstSize; /* Current burst size in bytes */
  314. u32 BurstDuration; /* Current burst duration in mSec */
  315. u32 BurstCycleTime; /* Current burst cycle time in mSec */
  316. u32 CalculatedBurstCycleTime; /* Current burst cycle time in mSec,
  317. * as calculated by demodulator */
  318. u32 NumOfRows; /* Number of rows in MPE table */
  319. u32 NumOfPaddCols; /* Number of padding columns in MPE table */
  320. u32 NumOfPunctCols; /* Number of puncturing columns in MPE table */
  321. /* Burst parameters */
  322. u32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
  323. u32 TotalTSPackets; /* Total number of transport-stream packets */
  324. u32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include
  325. * errors after MPE RS decoding */
  326. u32 NumOfInvalidMpeTlbs; /* Number of MPE tables which include errors
  327. * after MPE RS decoding */
  328. u32 NumOfCorrectedMpeTlbs; /* Number of MPE tables which were corrected
  329. * by MPE RS decoding */
  330. /* Common params */
  331. u32 BERErrorCount; /* Number of errornous SYNC bits. */
  332. u32 BERBitCount; /* Total number of SYNC bits. */
  333. /* Interface information */
  334. u32 SmsToHostTxErrors; /* Total number of transmission errors. */
  335. /* DAB/T-DMB */
  336. u32 PreBER; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
  337. /* DVB-H TPS parameters */
  338. u32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero;
  339. * if set to 0xFFFFFFFF cell_id not yet recovered */
  340. };
  341. struct SmsMsgStatisticsInfo_ST {
  342. u32 RequestResult;
  343. struct SMSHOSTLIB_STATISTICS_ST Stat;
  344. /* Split the calc of the SNR in DAB */
  345. u32 Signal; /* dB */
  346. u32 Noise; /* dB */
  347. };
  348. struct smscore_gpio_config {
  349. #define SMS_GPIO_DIRECTION_INPUT 0
  350. #define SMS_GPIO_DIRECTION_OUTPUT 1
  351. u8 direction;
  352. #define SMS_GPIO_PULLUPDOWN_NONE 0
  353. #define SMS_GPIO_PULLUPDOWN_PULLDOWN 1
  354. #define SMS_GPIO_PULLUPDOWN_PULLUP 2
  355. #define SMS_GPIO_PULLUPDOWN_KEEPER 3
  356. u8 pullupdown;
  357. #define SMS_GPIO_INPUTCHARACTERISTICS_NORMAL 0
  358. #define SMS_GPIO_INPUTCHARACTERISTICS_SCHMITT 1
  359. u8 inputcharacteristics;
  360. #define SMS_GPIO_OUTPUTSLEWRATE_FAST 0
  361. #define SMS_GPIO_OUTPUTSLEWRATE_SLOW 1
  362. u8 outputslewrate;
  363. #define SMS_GPIO_OUTPUTDRIVING_4mA 0
  364. #define SMS_GPIO_OUTPUTDRIVING_8mA 1
  365. #define SMS_GPIO_OUTPUTDRIVING_12mA 2
  366. #define SMS_GPIO_OUTPUTDRIVING_16mA 3
  367. u8 outputdriving;
  368. };
  369. extern void smscore_registry_setmode(char *devpath, int mode);
  370. extern int smscore_registry_getmode(char *devpath);
  371. extern int smscore_register_hotplug(hotplug_t hotplug);
  372. extern void smscore_unregister_hotplug(hotplug_t hotplug);
  373. extern int smscore_register_device(struct smsdevice_params_t *params,
  374. struct smscore_device_t **coredev);
  375. extern void smscore_unregister_device(struct smscore_device_t *coredev);
  376. extern int smscore_start_device(struct smscore_device_t *coredev);
  377. extern int smscore_load_firmware(struct smscore_device_t *coredev,
  378. char *filename,
  379. loadfirmware_t loadfirmware_handler);
  380. extern int smscore_set_device_mode(struct smscore_device_t *coredev, int mode);
  381. 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);
  386. extern int smsclient_sendrequest(struct smscore_client_t *client,
  387. void *buffer, size_t size);
  388. extern void smscore_onresponse(struct smscore_device_t *coredev,
  389. struct smscore_buffer_t *cb);
  390. extern int smscore_get_common_buffer_size(struct smscore_device_t *coredev);
  391. extern int smscore_map_common_buffer(struct smscore_device_t *coredev,
  392. struct vm_area_struct *vma);
  393. extern int smscore_get_fw_filename(struct smscore_device_t *coredev,
  394. int mode, char *filename);
  395. extern int smscore_send_fw_file(struct smscore_device_t *coredev,
  396. u8 *ufwbuf, int size);
  397. extern
  398. struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev);
  399. extern void smscore_putbuffer(struct smscore_device_t *coredev,
  400. struct smscore_buffer_t *cb);
  401. int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
  402. struct smscore_gpio_config *pinconfig);
  403. int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level);
  404. void smscore_set_board_id(struct smscore_device_t *core, int id);
  405. int smscore_get_board_id(struct smscore_device_t *core);
  406. int smscore_led_state(struct smscore_device_t *core, int led);
  407. /* ------------------------------------------------------------------------ */
  408. #define DBG_INFO 1
  409. #define DBG_ADV 2
  410. #define sms_printk(kern, fmt, arg...) \
  411. printk(kern "%s: " fmt "\n", __func__, ##arg)
  412. #define dprintk(kern, lvl, fmt, arg...) do {\
  413. if (sms_dbg & lvl) \
  414. sms_printk(kern, fmt, ##arg); } while (0)
  415. #define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
  416. #define sms_err(fmt, arg...) \
  417. sms_printk(KERN_ERR, "line: %d: " fmt, __LINE__, ##arg)
  418. #define sms_warn(fmt, arg...) sms_printk(KERN_WARNING, fmt, ##arg)
  419. #define sms_info(fmt, arg...) \
  420. dprintk(KERN_INFO, DBG_INFO, fmt, ##arg)
  421. #define sms_debug(fmt, arg...) \
  422. dprintk(KERN_DEBUG, DBG_ADV, fmt, ##arg)
  423. #endif /* __SMS_CORE_API_H__ */