dvb_frontend.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*
  2. * dvb_frontend.h
  3. *
  4. * Copyright (C) 2001 convergence integrated media GmbH
  5. * Copyright (C) 2004 convergence GmbH
  6. *
  7. * Written by Ralph Metzler
  8. * Overhauled by Holger Waechtler
  9. * Kernel I2C stuff by Michael Hunold <hunold@convergence.de>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public License
  13. * as published by the Free Software Foundation; either version 2.1
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. *
  25. */
  26. #ifndef _DVB_FRONTEND_H_
  27. #define _DVB_FRONTEND_H_
  28. #include <linux/types.h>
  29. #include <linux/sched.h>
  30. #include <linux/ioctl.h>
  31. #include <linux/i2c.h>
  32. #include <linux/module.h>
  33. #include <linux/errno.h>
  34. #include <linux/delay.h>
  35. #include <linux/mutex.h>
  36. #include <linux/slab.h>
  37. #include <linux/dvb/frontend.h>
  38. #include "dvbdev.h"
  39. /*
  40. * Maximum number of Delivery systems per frontend. It
  41. * should be smaller or equal to 32
  42. */
  43. #define MAX_DELSYS 8
  44. /**
  45. * struct dvb_frontend_tune_settings - parameters to adjust frontend tuning
  46. *
  47. * @min_delay_ms: minimum delay for tuning, in ms
  48. * @step_size: step size between two consecutive frequencies
  49. * @max_drift: maximum drift
  50. *
  51. * NOTE: step_size is in Hz, for terrestrial/cable or kHz for satellite
  52. */
  53. struct dvb_frontend_tune_settings {
  54. int min_delay_ms;
  55. int step_size;
  56. int max_drift;
  57. };
  58. struct dvb_frontend;
  59. /**
  60. * struct dvb_tuner_info - Frontend name and min/max ranges/bandwidths
  61. *
  62. * @name: name of the Frontend
  63. * @frequency_min: minimal frequency supported
  64. * @frequency_max: maximum frequency supported
  65. * @frequency_step: frequency step
  66. * @bandwidth_min: minimal frontend bandwidth supported
  67. * @bandwidth_max: maximum frontend bandwidth supported
  68. * @bandwidth_step: frontend bandwidth step
  69. *
  70. * NOTE: frequency parameters are in Hz, for terrestrial/cable or kHz for
  71. * satellite.
  72. */
  73. struct dvb_tuner_info {
  74. char name[128];
  75. u32 frequency_min;
  76. u32 frequency_max;
  77. u32 frequency_step;
  78. u32 bandwidth_min;
  79. u32 bandwidth_max;
  80. u32 bandwidth_step;
  81. };
  82. struct analog_parameters {
  83. unsigned int frequency;
  84. unsigned int mode;
  85. unsigned int audmode;
  86. u64 std;
  87. };
  88. enum dvbfe_modcod {
  89. DVBFE_MODCOD_DUMMY_PLFRAME = 0,
  90. DVBFE_MODCOD_QPSK_1_4,
  91. DVBFE_MODCOD_QPSK_1_3,
  92. DVBFE_MODCOD_QPSK_2_5,
  93. DVBFE_MODCOD_QPSK_1_2,
  94. DVBFE_MODCOD_QPSK_3_5,
  95. DVBFE_MODCOD_QPSK_2_3,
  96. DVBFE_MODCOD_QPSK_3_4,
  97. DVBFE_MODCOD_QPSK_4_5,
  98. DVBFE_MODCOD_QPSK_5_6,
  99. DVBFE_MODCOD_QPSK_8_9,
  100. DVBFE_MODCOD_QPSK_9_10,
  101. DVBFE_MODCOD_8PSK_3_5,
  102. DVBFE_MODCOD_8PSK_2_3,
  103. DVBFE_MODCOD_8PSK_3_4,
  104. DVBFE_MODCOD_8PSK_5_6,
  105. DVBFE_MODCOD_8PSK_8_9,
  106. DVBFE_MODCOD_8PSK_9_10,
  107. DVBFE_MODCOD_16APSK_2_3,
  108. DVBFE_MODCOD_16APSK_3_4,
  109. DVBFE_MODCOD_16APSK_4_5,
  110. DVBFE_MODCOD_16APSK_5_6,
  111. DVBFE_MODCOD_16APSK_8_9,
  112. DVBFE_MODCOD_16APSK_9_10,
  113. DVBFE_MODCOD_32APSK_3_4,
  114. DVBFE_MODCOD_32APSK_4_5,
  115. DVBFE_MODCOD_32APSK_5_6,
  116. DVBFE_MODCOD_32APSK_8_9,
  117. DVBFE_MODCOD_32APSK_9_10,
  118. DVBFE_MODCOD_RESERVED_1,
  119. DVBFE_MODCOD_BPSK_1_3,
  120. DVBFE_MODCOD_BPSK_1_4,
  121. DVBFE_MODCOD_RESERVED_2
  122. };
  123. enum tuner_param {
  124. DVBFE_TUNER_FREQUENCY = (1 << 0),
  125. DVBFE_TUNER_TUNERSTEP = (1 << 1),
  126. DVBFE_TUNER_IFFREQ = (1 << 2),
  127. DVBFE_TUNER_BANDWIDTH = (1 << 3),
  128. DVBFE_TUNER_REFCLOCK = (1 << 4),
  129. DVBFE_TUNER_IQSENSE = (1 << 5),
  130. DVBFE_TUNER_DUMMY = (1 << 31)
  131. };
  132. /**
  133. * enum dvbfe_algo - defines the algorithm used to tune into a channel
  134. *
  135. * @DVBFE_ALGO_HW: (Hardware Algorithm)
  136. * Devices that support this algorithm do everything in hardware
  137. * and no software support is needed to handle them.
  138. * Requesting these devices to LOCK is the only thing required,
  139. * device is supposed to do everything in the hardware.
  140. *
  141. * @DVBFE_ALGO_SW: (Software Algorithm)
  142. * These are dumb devices, that require software to do everything
  143. *
  144. * @DVBFE_ALGO_CUSTOM: (Customizable Agorithm)
  145. * Devices having this algorithm can be customized to have specific
  146. * algorithms in the frontend driver, rather than simply doing a
  147. * software zig-zag. In this case the zigzag maybe hardware assisted
  148. * or it maybe completely done in hardware. In all cases, usage of
  149. * this algorithm, in conjunction with the search and track
  150. * callbacks, utilizes the driver specific algorithm.
  151. *
  152. * @DVBFE_ALGO_RECOVERY: (Recovery Algorithm)
  153. * These devices have AUTO recovery capabilities from LOCK failure
  154. */
  155. enum dvbfe_algo {
  156. DVBFE_ALGO_HW = (1 << 0),
  157. DVBFE_ALGO_SW = (1 << 1),
  158. DVBFE_ALGO_CUSTOM = (1 << 2),
  159. DVBFE_ALGO_RECOVERY = (1 << 31)
  160. };
  161. struct tuner_state {
  162. u32 frequency;
  163. u32 tunerstep;
  164. u32 ifreq;
  165. u32 bandwidth;
  166. u32 iqsense;
  167. u32 refclock;
  168. };
  169. /**
  170. * enum dvbfe_search - search callback possible return status
  171. *
  172. * @DVBFE_ALGO_SEARCH_SUCCESS:
  173. * The frontend search algorithm completed and returned successfully
  174. *
  175. * @DVBFE_ALGO_SEARCH_ASLEEP:
  176. * The frontend search algorithm is sleeping
  177. *
  178. * @DVBFE_ALGO_SEARCH_FAILED:
  179. * The frontend search for a signal failed
  180. *
  181. * @DVBFE_ALGO_SEARCH_INVALID:
  182. * The frontend search algorith was probably supplied with invalid
  183. * parameters and the search is an invalid one
  184. *
  185. * @DVBFE_ALGO_SEARCH_ERROR:
  186. * The frontend search algorithm failed due to some error
  187. *
  188. * @DVBFE_ALGO_SEARCH_AGAIN:
  189. * The frontend search algorithm was requested to search again
  190. */
  191. enum dvbfe_search {
  192. DVBFE_ALGO_SEARCH_SUCCESS = (1 << 0),
  193. DVBFE_ALGO_SEARCH_ASLEEP = (1 << 1),
  194. DVBFE_ALGO_SEARCH_FAILED = (1 << 2),
  195. DVBFE_ALGO_SEARCH_INVALID = (1 << 3),
  196. DVBFE_ALGO_SEARCH_AGAIN = (1 << 4),
  197. DVBFE_ALGO_SEARCH_ERROR = (1 << 31),
  198. };
  199. struct dvb_tuner_ops {
  200. struct dvb_tuner_info info;
  201. int (*release)(struct dvb_frontend *fe);
  202. int (*init)(struct dvb_frontend *fe);
  203. int (*sleep)(struct dvb_frontend *fe);
  204. int (*suspend)(struct dvb_frontend *fe);
  205. int (*resume)(struct dvb_frontend *fe);
  206. /** This is for simple PLLs - set all parameters in one go. */
  207. int (*set_params)(struct dvb_frontend *fe);
  208. int (*set_analog_params)(struct dvb_frontend *fe, struct analog_parameters *p);
  209. /** This is support for demods like the mt352 - fills out the supplied buffer with what to write. */
  210. int (*calc_regs)(struct dvb_frontend *fe, u8 *buf, int buf_len);
  211. /** This is to allow setting tuner-specific configs */
  212. int (*set_config)(struct dvb_frontend *fe, void *priv_cfg);
  213. int (*get_frequency)(struct dvb_frontend *fe, u32 *frequency);
  214. int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
  215. int (*get_if_frequency)(struct dvb_frontend *fe, u32 *frequency);
  216. #define TUNER_STATUS_LOCKED 1
  217. #define TUNER_STATUS_STEREO 2
  218. int (*get_status)(struct dvb_frontend *fe, u32 *status);
  219. int (*get_rf_strength)(struct dvb_frontend *fe, u16 *strength);
  220. int (*get_afc)(struct dvb_frontend *fe, s32 *afc);
  221. /** These are provided separately from set_params in order to facilitate silicon
  222. * tuners which require sophisticated tuning loops, controlling each parameter separately. */
  223. int (*set_frequency)(struct dvb_frontend *fe, u32 frequency);
  224. int (*set_bandwidth)(struct dvb_frontend *fe, u32 bandwidth);
  225. /*
  226. * These are provided separately from set_params in order to facilitate silicon
  227. * tuners which require sophisticated tuning loops, controlling each parameter separately.
  228. */
  229. int (*set_state)(struct dvb_frontend *fe, enum tuner_param param, struct tuner_state *state);
  230. int (*get_state)(struct dvb_frontend *fe, enum tuner_param param, struct tuner_state *state);
  231. };
  232. struct analog_demod_info {
  233. char *name;
  234. };
  235. struct analog_demod_ops {
  236. struct analog_demod_info info;
  237. void (*set_params)(struct dvb_frontend *fe,
  238. struct analog_parameters *params);
  239. int (*has_signal)(struct dvb_frontend *fe, u16 *signal);
  240. int (*get_afc)(struct dvb_frontend *fe, s32 *afc);
  241. void (*tuner_status)(struct dvb_frontend *fe);
  242. void (*standby)(struct dvb_frontend *fe);
  243. void (*release)(struct dvb_frontend *fe);
  244. int (*i2c_gate_ctrl)(struct dvb_frontend *fe, int enable);
  245. /** This is to allow setting tuner-specific configuration */
  246. int (*set_config)(struct dvb_frontend *fe, void *priv_cfg);
  247. };
  248. struct dtv_frontend_properties;
  249. struct dvb_frontend_ops {
  250. struct dvb_frontend_info info;
  251. u8 delsys[MAX_DELSYS];
  252. void (*release)(struct dvb_frontend* fe);
  253. void (*release_sec)(struct dvb_frontend* fe);
  254. int (*init)(struct dvb_frontend* fe);
  255. int (*sleep)(struct dvb_frontend* fe);
  256. int (*write)(struct dvb_frontend* fe, const u8 buf[], int len);
  257. /* if this is set, it overrides the default swzigzag */
  258. int (*tune)(struct dvb_frontend* fe,
  259. bool re_tune,
  260. unsigned int mode_flags,
  261. unsigned int *delay,
  262. enum fe_status *status);
  263. /* get frontend tuning algorithm from the module */
  264. enum dvbfe_algo (*get_frontend_algo)(struct dvb_frontend *fe);
  265. /* these two are only used for the swzigzag code */
  266. int (*set_frontend)(struct dvb_frontend *fe);
  267. int (*get_tune_settings)(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* settings);
  268. int (*get_frontend)(struct dvb_frontend *fe);
  269. int (*read_status)(struct dvb_frontend *fe, enum fe_status *status);
  270. int (*read_ber)(struct dvb_frontend* fe, u32* ber);
  271. int (*read_signal_strength)(struct dvb_frontend* fe, u16* strength);
  272. int (*read_snr)(struct dvb_frontend* fe, u16* snr);
  273. int (*read_ucblocks)(struct dvb_frontend* fe, u32* ucblocks);
  274. int (*diseqc_reset_overload)(struct dvb_frontend* fe);
  275. int (*diseqc_send_master_cmd)(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd);
  276. int (*diseqc_recv_slave_reply)(struct dvb_frontend* fe, struct dvb_diseqc_slave_reply* reply);
  277. int (*diseqc_send_burst)(struct dvb_frontend *fe,
  278. enum fe_sec_mini_cmd minicmd);
  279. int (*set_tone)(struct dvb_frontend *fe, enum fe_sec_tone_mode tone);
  280. int (*set_voltage)(struct dvb_frontend *fe,
  281. enum fe_sec_voltage voltage);
  282. int (*enable_high_lnb_voltage)(struct dvb_frontend* fe, long arg);
  283. int (*dishnetwork_send_legacy_command)(struct dvb_frontend* fe, unsigned long cmd);
  284. int (*i2c_gate_ctrl)(struct dvb_frontend* fe, int enable);
  285. int (*ts_bus_ctrl)(struct dvb_frontend* fe, int acquire);
  286. int (*set_lna)(struct dvb_frontend *);
  287. /* These callbacks are for devices that implement their own
  288. * tuning algorithms, rather than a simple swzigzag
  289. */
  290. enum dvbfe_search (*search)(struct dvb_frontend *fe);
  291. struct dvb_tuner_ops tuner_ops;
  292. struct analog_demod_ops analog_ops;
  293. int (*set_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
  294. int (*get_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
  295. };
  296. #ifdef __DVB_CORE__
  297. #define MAX_EVENT 8
  298. struct dvb_fe_events {
  299. struct dvb_frontend_event events[MAX_EVENT];
  300. int eventw;
  301. int eventr;
  302. int overflow;
  303. wait_queue_head_t wait_queue;
  304. struct mutex mtx;
  305. };
  306. #endif
  307. struct dtv_frontend_properties {
  308. /* Cache State */
  309. u32 state;
  310. u32 frequency;
  311. enum fe_modulation modulation;
  312. enum fe_sec_voltage voltage;
  313. enum fe_sec_tone_mode sectone;
  314. enum fe_spectral_inversion inversion;
  315. enum fe_code_rate fec_inner;
  316. enum fe_transmit_mode transmission_mode;
  317. u32 bandwidth_hz; /* 0 = AUTO */
  318. enum fe_guard_interval guard_interval;
  319. enum fe_hierarchy hierarchy;
  320. u32 symbol_rate;
  321. enum fe_code_rate code_rate_HP;
  322. enum fe_code_rate code_rate_LP;
  323. enum fe_pilot pilot;
  324. enum fe_rolloff rolloff;
  325. enum fe_delivery_system delivery_system;
  326. enum fe_interleaving interleaving;
  327. /* ISDB-T specifics */
  328. u8 isdbt_partial_reception;
  329. u8 isdbt_sb_mode;
  330. u8 isdbt_sb_subchannel;
  331. u32 isdbt_sb_segment_idx;
  332. u32 isdbt_sb_segment_count;
  333. u8 isdbt_layer_enabled;
  334. struct {
  335. u8 segment_count;
  336. enum fe_code_rate fec;
  337. enum fe_modulation modulation;
  338. u8 interleaving;
  339. } layer[3];
  340. /* Multistream specifics */
  341. u32 stream_id;
  342. /* ATSC-MH specifics */
  343. u8 atscmh_fic_ver;
  344. u8 atscmh_parade_id;
  345. u8 atscmh_nog;
  346. u8 atscmh_tnog;
  347. u8 atscmh_sgn;
  348. u8 atscmh_prc;
  349. u8 atscmh_rs_frame_mode;
  350. u8 atscmh_rs_frame_ensemble;
  351. u8 atscmh_rs_code_mode_pri;
  352. u8 atscmh_rs_code_mode_sec;
  353. u8 atscmh_sccc_block_mode;
  354. u8 atscmh_sccc_code_mode_a;
  355. u8 atscmh_sccc_code_mode_b;
  356. u8 atscmh_sccc_code_mode_c;
  357. u8 atscmh_sccc_code_mode_d;
  358. u32 lna;
  359. /* statistics data */
  360. struct dtv_fe_stats strength;
  361. struct dtv_fe_stats cnr;
  362. struct dtv_fe_stats pre_bit_error;
  363. struct dtv_fe_stats pre_bit_count;
  364. struct dtv_fe_stats post_bit_error;
  365. struct dtv_fe_stats post_bit_count;
  366. struct dtv_fe_stats block_error;
  367. struct dtv_fe_stats block_count;
  368. };
  369. #define DVB_FE_NO_EXIT 0
  370. #define DVB_FE_NORMAL_EXIT 1
  371. #define DVB_FE_DEVICE_REMOVED 2
  372. #define DVB_FE_DEVICE_RESUME 3
  373. struct dvb_frontend {
  374. struct dvb_frontend_ops ops;
  375. struct dvb_adapter *dvb;
  376. void *demodulator_priv;
  377. void *tuner_priv;
  378. void *frontend_priv;
  379. void *sec_priv;
  380. void *analog_demod_priv;
  381. struct dtv_frontend_properties dtv_property_cache;
  382. #define DVB_FRONTEND_COMPONENT_TUNER 0
  383. #define DVB_FRONTEND_COMPONENT_DEMOD 1
  384. int (*callback)(void *adapter_priv, int component, int cmd, int arg);
  385. int id;
  386. unsigned int exit;
  387. };
  388. extern int dvb_register_frontend(struct dvb_adapter *dvb,
  389. struct dvb_frontend *fe);
  390. extern int dvb_unregister_frontend(struct dvb_frontend *fe);
  391. extern void dvb_frontend_detach(struct dvb_frontend *fe);
  392. extern void dvb_frontend_reinitialise(struct dvb_frontend *fe);
  393. extern int dvb_frontend_suspend(struct dvb_frontend *fe);
  394. extern int dvb_frontend_resume(struct dvb_frontend *fe);
  395. extern void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec);
  396. #endif