dvb_frontend.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. struct dvb_frontend_tune_settings {
  40. int min_delay_ms;
  41. int step_size;
  42. int max_drift;
  43. struct dvb_frontend_parameters parameters;
  44. };
  45. struct dvb_frontend;
  46. struct dvb_tuner_info {
  47. char name[128];
  48. u32 frequency_min;
  49. u32 frequency_max;
  50. u32 frequency_step;
  51. u32 bandwidth_min;
  52. u32 bandwidth_max;
  53. u32 bandwidth_step;
  54. };
  55. struct analog_parameters {
  56. unsigned int frequency;
  57. unsigned int mode;
  58. unsigned int audmode;
  59. u64 std;
  60. };
  61. enum dvbfe_modcod {
  62. DVBFE_MODCOD_DUMMY_PLFRAME = 0,
  63. DVBFE_MODCOD_QPSK_1_4,
  64. DVBFE_MODCOD_QPSK_1_3,
  65. DVBFE_MODCOD_QPSK_2_5,
  66. DVBFE_MODCOD_QPSK_1_2,
  67. DVBFE_MODCOD_QPSK_3_5,
  68. DVBFE_MODCOD_QPSK_2_3,
  69. DVBFE_MODCOD_QPSK_3_4,
  70. DVBFE_MODCOD_QPSK_4_5,
  71. DVBFE_MODCOD_QPSK_5_6,
  72. DVBFE_MODCOD_QPSK_8_9,
  73. DVBFE_MODCOD_QPSK_9_10,
  74. DVBFE_MODCOD_8PSK_3_5,
  75. DVBFE_MODCOD_8PSK_2_3,
  76. DVBFE_MODCOD_8PSK_3_4,
  77. DVBFE_MODCOD_8PSK_5_6,
  78. DVBFE_MODCOD_8PSK_8_9,
  79. DVBFE_MODCOD_8PSK_9_10,
  80. DVBFE_MODCOD_16APSK_2_3,
  81. DVBFE_MODCOD_16APSK_3_4,
  82. DVBFE_MODCOD_16APSK_4_5,
  83. DVBFE_MODCOD_16APSK_5_6,
  84. DVBFE_MODCOD_16APSK_8_9,
  85. DVBFE_MODCOD_16APSK_9_10,
  86. DVBFE_MODCOD_32APSK_3_4,
  87. DVBFE_MODCOD_32APSK_4_5,
  88. DVBFE_MODCOD_32APSK_5_6,
  89. DVBFE_MODCOD_32APSK_8_9,
  90. DVBFE_MODCOD_32APSK_9_10,
  91. DVBFE_MODCOD_RESERVED_1,
  92. DVBFE_MODCOD_BPSK_1_3,
  93. DVBFE_MODCOD_BPSK_1_4,
  94. DVBFE_MODCOD_RESERVED_2
  95. };
  96. enum tuner_param {
  97. DVBFE_TUNER_FREQUENCY = (1 << 0),
  98. DVBFE_TUNER_TUNERSTEP = (1 << 1),
  99. DVBFE_TUNER_IFFREQ = (1 << 2),
  100. DVBFE_TUNER_BANDWIDTH = (1 << 3),
  101. DVBFE_TUNER_REFCLOCK = (1 << 4),
  102. DVBFE_TUNER_IQSENSE = (1 << 5),
  103. DVBFE_TUNER_DUMMY = (1 << 31)
  104. };
  105. /*
  106. * ALGO_HW: (Hardware Algorithm)
  107. * ----------------------------------------------------------------
  108. * Devices that support this algorithm do everything in hardware
  109. * and no software support is needed to handle them.
  110. * Requesting these devices to LOCK is the only thing required,
  111. * device is supposed to do everything in the hardware.
  112. *
  113. * ALGO_SW: (Software Algorithm)
  114. * ----------------------------------------------------------------
  115. * These are dumb devices, that require software to do everything
  116. *
  117. * ALGO_CUSTOM: (Customizable Agorithm)
  118. * ----------------------------------------------------------------
  119. * Devices having this algorithm can be customized to have specific
  120. * algorithms in the frontend driver, rather than simply doing a
  121. * software zig-zag. In this case the zigzag maybe hardware assisted
  122. * or it maybe completely done in hardware. In all cases, usage of
  123. * this algorithm, in conjunction with the search and track
  124. * callbacks, utilizes the driver specific algorithm.
  125. *
  126. * ALGO_RECOVERY: (Recovery Algorithm)
  127. * ----------------------------------------------------------------
  128. * These devices have AUTO recovery capabilities from LOCK failure
  129. */
  130. enum dvbfe_algo {
  131. DVBFE_ALGO_HW = (1 << 0),
  132. DVBFE_ALGO_SW = (1 << 1),
  133. DVBFE_ALGO_CUSTOM = (1 << 2),
  134. DVBFE_ALGO_RECOVERY = (1 << 31)
  135. };
  136. struct tuner_state {
  137. u32 frequency;
  138. u32 tunerstep;
  139. u32 ifreq;
  140. u32 bandwidth;
  141. u32 iqsense;
  142. u32 refclock;
  143. };
  144. /*
  145. * search callback possible return status
  146. *
  147. * DVBFE_ALGO_SEARCH_SUCCESS
  148. * The frontend search algorithm completed and returned successfully
  149. *
  150. * DVBFE_ALGO_SEARCH_ASLEEP
  151. * The frontend search algorithm is sleeping
  152. *
  153. * DVBFE_ALGO_SEARCH_FAILED
  154. * The frontend search for a signal failed
  155. *
  156. * DVBFE_ALGO_SEARCH_INVALID
  157. * The frontend search algorith was probably supplied with invalid
  158. * parameters and the search is an invalid one
  159. *
  160. * DVBFE_ALGO_SEARCH_ERROR
  161. * The frontend search algorithm failed due to some error
  162. *
  163. * DVBFE_ALGO_SEARCH_AGAIN
  164. * The frontend search algorithm was requested to search again
  165. */
  166. enum dvbfe_search {
  167. DVBFE_ALGO_SEARCH_SUCCESS = (1 << 0),
  168. DVBFE_ALGO_SEARCH_ASLEEP = (1 << 1),
  169. DVBFE_ALGO_SEARCH_FAILED = (1 << 2),
  170. DVBFE_ALGO_SEARCH_INVALID = (1 << 3),
  171. DVBFE_ALGO_SEARCH_AGAIN = (1 << 4),
  172. DVBFE_ALGO_SEARCH_ERROR = (1 << 31),
  173. };
  174. struct dvb_tuner_ops {
  175. struct dvb_tuner_info info;
  176. int (*release)(struct dvb_frontend *fe);
  177. int (*init)(struct dvb_frontend *fe);
  178. int (*sleep)(struct dvb_frontend *fe);
  179. /** This is for simple PLLs - set all parameters in one go. */
  180. int (*set_params)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p);
  181. int (*set_analog_params)(struct dvb_frontend *fe, struct analog_parameters *p);
  182. /** This is support for demods like the mt352 - fills out the supplied buffer with what to write. */
  183. int (*calc_regs)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p, u8 *buf, int buf_len);
  184. /** This is to allow setting tuner-specific configs */
  185. int (*set_config)(struct dvb_frontend *fe, void *priv_cfg);
  186. int (*get_frequency)(struct dvb_frontend *fe, u32 *frequency);
  187. int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
  188. #define TUNER_STATUS_LOCKED 1
  189. #define TUNER_STATUS_STEREO 2
  190. int (*get_status)(struct dvb_frontend *fe, u32 *status);
  191. int (*get_rf_strength)(struct dvb_frontend *fe, u16 *strength);
  192. /** These are provided separately from set_params in order to facilitate silicon
  193. * tuners which require sophisticated tuning loops, controlling each parameter separately. */
  194. int (*set_frequency)(struct dvb_frontend *fe, u32 frequency);
  195. int (*set_bandwidth)(struct dvb_frontend *fe, u32 bandwidth);
  196. /*
  197. * These are provided separately from set_params in order to facilitate silicon
  198. * tuners which require sophisticated tuning loops, controlling each parameter separately.
  199. */
  200. int (*set_state)(struct dvb_frontend *fe, enum tuner_param param, struct tuner_state *state);
  201. int (*get_state)(struct dvb_frontend *fe, enum tuner_param param, struct tuner_state *state);
  202. };
  203. struct analog_demod_info {
  204. char *name;
  205. };
  206. struct analog_demod_ops {
  207. struct analog_demod_info info;
  208. void (*set_params)(struct dvb_frontend *fe,
  209. struct analog_parameters *params);
  210. int (*has_signal)(struct dvb_frontend *fe);
  211. int (*get_afc)(struct dvb_frontend *fe);
  212. void (*tuner_status)(struct dvb_frontend *fe);
  213. void (*standby)(struct dvb_frontend *fe);
  214. void (*release)(struct dvb_frontend *fe);
  215. int (*i2c_gate_ctrl)(struct dvb_frontend *fe, int enable);
  216. /** This is to allow setting tuner-specific configuration */
  217. int (*set_config)(struct dvb_frontend *fe, void *priv_cfg);
  218. };
  219. struct dvb_frontend_ops {
  220. struct dvb_frontend_info info;
  221. void (*release)(struct dvb_frontend* fe);
  222. void (*release_sec)(struct dvb_frontend* fe);
  223. int (*init)(struct dvb_frontend* fe);
  224. int (*sleep)(struct dvb_frontend* fe);
  225. int (*write)(struct dvb_frontend* fe, const u8 buf[], int len);
  226. /* if this is set, it overrides the default swzigzag */
  227. int (*tune)(struct dvb_frontend* fe,
  228. struct dvb_frontend_parameters* params,
  229. unsigned int mode_flags,
  230. unsigned int *delay,
  231. fe_status_t *status);
  232. /* get frontend tuning algorithm from the module */
  233. enum dvbfe_algo (*get_frontend_algo)(struct dvb_frontend *fe);
  234. /* these two are only used for the swzigzag code */
  235. int (*set_frontend)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params);
  236. int (*get_tune_settings)(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* settings);
  237. int (*get_frontend)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params);
  238. int (*read_status)(struct dvb_frontend* fe, fe_status_t* status);
  239. int (*read_ber)(struct dvb_frontend* fe, u32* ber);
  240. int (*read_signal_strength)(struct dvb_frontend* fe, u16* strength);
  241. int (*read_snr)(struct dvb_frontend* fe, u16* snr);
  242. int (*read_ucblocks)(struct dvb_frontend* fe, u32* ucblocks);
  243. int (*diseqc_reset_overload)(struct dvb_frontend* fe);
  244. int (*diseqc_send_master_cmd)(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd);
  245. int (*diseqc_recv_slave_reply)(struct dvb_frontend* fe, struct dvb_diseqc_slave_reply* reply);
  246. int (*diseqc_send_burst)(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd);
  247. int (*set_tone)(struct dvb_frontend* fe, fe_sec_tone_mode_t tone);
  248. int (*set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
  249. int (*enable_high_lnb_voltage)(struct dvb_frontend* fe, long arg);
  250. int (*dishnetwork_send_legacy_command)(struct dvb_frontend* fe, unsigned long cmd);
  251. int (*i2c_gate_ctrl)(struct dvb_frontend* fe, int enable);
  252. int (*ts_bus_ctrl)(struct dvb_frontend* fe, int acquire);
  253. /* These callbacks are for devices that implement their own
  254. * tuning algorithms, rather than a simple swzigzag
  255. */
  256. enum dvbfe_search (*search)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p);
  257. int (*track)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p);
  258. struct dvb_tuner_ops tuner_ops;
  259. struct analog_demod_ops analog_ops;
  260. int (*set_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
  261. int (*get_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
  262. };
  263. #define MAX_EVENT 8
  264. struct dvb_fe_events {
  265. struct dvb_frontend_event events[MAX_EVENT];
  266. int eventw;
  267. int eventr;
  268. int overflow;
  269. wait_queue_head_t wait_queue;
  270. struct mutex mtx;
  271. };
  272. struct dtv_frontend_properties {
  273. /* Cache State */
  274. u32 state;
  275. u32 frequency;
  276. fe_modulation_t modulation;
  277. fe_sec_voltage_t voltage;
  278. fe_sec_tone_mode_t sectone;
  279. fe_spectral_inversion_t inversion;
  280. fe_code_rate_t fec_inner;
  281. fe_transmit_mode_t transmission_mode;
  282. u32 bandwidth_hz; /* 0 = AUTO */
  283. fe_guard_interval_t guard_interval;
  284. fe_hierarchy_t hierarchy;
  285. u32 symbol_rate;
  286. fe_code_rate_t code_rate_HP;
  287. fe_code_rate_t code_rate_LP;
  288. fe_pilot_t pilot;
  289. fe_rolloff_t rolloff;
  290. fe_delivery_system_t delivery_system;
  291. /* ISDB-T specifics */
  292. u8 isdbt_partial_reception;
  293. u8 isdbt_sb_mode;
  294. u8 isdbt_sb_subchannel;
  295. u32 isdbt_sb_segment_idx;
  296. u32 isdbt_sb_segment_count;
  297. u8 isdbt_layer_enabled;
  298. struct {
  299. u8 segment_count;
  300. fe_code_rate_t fec;
  301. fe_modulation_t modulation;
  302. u8 interleaving;
  303. } layer[3];
  304. /* ISDB-T specifics */
  305. u32 isdbs_ts_id;
  306. /* DVB-T2 specifics */
  307. u32 dvbt2_plp_id;
  308. };
  309. struct dvb_frontend {
  310. struct dvb_frontend_ops ops;
  311. struct dvb_adapter *dvb;
  312. void *demodulator_priv;
  313. void *tuner_priv;
  314. void *frontend_priv;
  315. void *sec_priv;
  316. void *analog_demod_priv;
  317. struct dtv_frontend_properties dtv_property_cache;
  318. #define DVB_FRONTEND_COMPONENT_TUNER 0
  319. int (*callback)(void *adapter_priv, int component, int cmd, int arg);
  320. int id;
  321. };
  322. extern int dvb_register_frontend(struct dvb_adapter *dvb,
  323. struct dvb_frontend *fe);
  324. extern int dvb_unregister_frontend(struct dvb_frontend *fe);
  325. extern void dvb_frontend_detach(struct dvb_frontend *fe);
  326. extern void dvb_frontend_reinitialise(struct dvb_frontend *fe);
  327. extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec);
  328. extern s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime);
  329. #endif