dvb_frontend.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173
  1. /*
  2. * dvb_frontend.c: DVB frontend tuning interface/thread
  3. *
  4. *
  5. * Copyright (C) 1999-2001 Ralph Metzler
  6. * Marcus Metzler
  7. * Holger Waechtler
  8. * for convergence integrated media GmbH
  9. *
  10. * Copyright (C) 2004 Andrew de Quincey (tuning thread cleanup)
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  26. */
  27. #include <linux/string.h>
  28. #include <linux/kernel.h>
  29. #include <linux/sched.h>
  30. #include <linux/wait.h>
  31. #include <linux/slab.h>
  32. #include <linux/poll.h>
  33. #include <linux/semaphore.h>
  34. #include <linux/module.h>
  35. #include <linux/list.h>
  36. #include <linux/freezer.h>
  37. #include <linux/jiffies.h>
  38. #include <linux/kthread.h>
  39. #include <asm/processor.h>
  40. #include "dvb_frontend.h"
  41. #include "dvbdev.h"
  42. #include <linux/dvb/version.h>
  43. static int dvb_frontend_debug;
  44. static int dvb_shutdown_timeout;
  45. static int dvb_force_auto_inversion;
  46. static int dvb_override_tune_delay;
  47. static int dvb_powerdown_on_sleep = 1;
  48. static int dvb_mfe_wait_time = 5;
  49. module_param_named(frontend_debug, dvb_frontend_debug, int, 0644);
  50. MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off).");
  51. module_param(dvb_shutdown_timeout, int, 0644);
  52. MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware");
  53. module_param(dvb_force_auto_inversion, int, 0644);
  54. MODULE_PARM_DESC(dvb_force_auto_inversion, "0: normal (default), 1: INVERSION_AUTO forced always");
  55. module_param(dvb_override_tune_delay, int, 0644);
  56. MODULE_PARM_DESC(dvb_override_tune_delay, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
  57. module_param(dvb_powerdown_on_sleep, int, 0644);
  58. MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB voltage off on sleep (default)");
  59. module_param(dvb_mfe_wait_time, int, 0644);
  60. MODULE_PARM_DESC(dvb_mfe_wait_time, "Wait up to <mfe_wait_time> seconds on open() for multi-frontend to become available (default:5 seconds)");
  61. #define dprintk if (dvb_frontend_debug) printk
  62. #define FESTATE_IDLE 1
  63. #define FESTATE_RETUNE 2
  64. #define FESTATE_TUNING_FAST 4
  65. #define FESTATE_TUNING_SLOW 8
  66. #define FESTATE_TUNED 16
  67. #define FESTATE_ZIGZAG_FAST 32
  68. #define FESTATE_ZIGZAG_SLOW 64
  69. #define FESTATE_DISEQC 128
  70. #define FESTATE_ERROR 256
  71. #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
  72. #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
  73. #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
  74. #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
  75. #define FE_ALGO_HW 1
  76. /*
  77. * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
  78. * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
  79. * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
  80. * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
  81. * FESTATE_TUNED. The frontend has successfully locked on.
  82. * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
  83. * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
  84. * FESTATE_DISEQC. A DISEQC command has just been issued.
  85. * FESTATE_WAITFORLOCK. When we're waiting for a lock.
  86. * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
  87. * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
  88. * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
  89. */
  90. #define DVB_FE_NO_EXIT 0
  91. #define DVB_FE_NORMAL_EXIT 1
  92. #define DVB_FE_DEVICE_REMOVED 2
  93. static DEFINE_MUTEX(frontend_mutex);
  94. struct dvb_frontend_private {
  95. /* thread/frontend values */
  96. struct dvb_device *dvbdev;
  97. struct dvb_frontend_parameters parameters_in;
  98. struct dvb_frontend_parameters parameters_out;
  99. struct dvb_fe_events events;
  100. struct semaphore sem;
  101. struct list_head list_head;
  102. wait_queue_head_t wait_queue;
  103. struct task_struct *thread;
  104. unsigned long release_jiffies;
  105. unsigned int exit;
  106. unsigned int wakeup;
  107. fe_status_t status;
  108. unsigned long tune_mode_flags;
  109. unsigned int delay;
  110. unsigned int reinitialise;
  111. int tone;
  112. int voltage;
  113. /* swzigzag values */
  114. unsigned int state;
  115. unsigned int bending;
  116. int lnb_drift;
  117. unsigned int inversion;
  118. unsigned int auto_step;
  119. unsigned int auto_sub_step;
  120. unsigned int started_auto_step;
  121. unsigned int min_delay;
  122. unsigned int max_drift;
  123. unsigned int step_size;
  124. int quality;
  125. unsigned int check_wrapped;
  126. enum dvbfe_search algo_status;
  127. };
  128. static void dvb_frontend_wakeup(struct dvb_frontend *fe);
  129. static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
  130. {
  131. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  132. struct dvb_fe_events *events = &fepriv->events;
  133. struct dvb_frontend_event *e;
  134. int wp;
  135. dprintk ("%s\n", __func__);
  136. if (mutex_lock_interruptible (&events->mtx))
  137. return;
  138. wp = (events->eventw + 1) % MAX_EVENT;
  139. if (wp == events->eventr) {
  140. events->overflow = 1;
  141. events->eventr = (events->eventr + 1) % MAX_EVENT;
  142. }
  143. e = &events->events[events->eventw];
  144. if (status & FE_HAS_LOCK)
  145. if (fe->ops.get_frontend)
  146. fe->ops.get_frontend(fe, &fepriv->parameters_out);
  147. e->parameters = fepriv->parameters_out;
  148. events->eventw = wp;
  149. mutex_unlock(&events->mtx);
  150. e->status = status;
  151. wake_up_interruptible (&events->wait_queue);
  152. }
  153. static int dvb_frontend_get_event(struct dvb_frontend *fe,
  154. struct dvb_frontend_event *event, int flags)
  155. {
  156. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  157. struct dvb_fe_events *events = &fepriv->events;
  158. dprintk ("%s\n", __func__);
  159. if (events->overflow) {
  160. events->overflow = 0;
  161. return -EOVERFLOW;
  162. }
  163. if (events->eventw == events->eventr) {
  164. int ret;
  165. if (flags & O_NONBLOCK)
  166. return -EWOULDBLOCK;
  167. up(&fepriv->sem);
  168. ret = wait_event_interruptible (events->wait_queue,
  169. events->eventw != events->eventr);
  170. if (down_interruptible (&fepriv->sem))
  171. return -ERESTARTSYS;
  172. if (ret < 0)
  173. return ret;
  174. }
  175. if (mutex_lock_interruptible (&events->mtx))
  176. return -ERESTARTSYS;
  177. memcpy (event, &events->events[events->eventr],
  178. sizeof(struct dvb_frontend_event));
  179. events->eventr = (events->eventr + 1) % MAX_EVENT;
  180. mutex_unlock(&events->mtx);
  181. return 0;
  182. }
  183. static void dvb_frontend_init(struct dvb_frontend *fe)
  184. {
  185. dprintk ("DVB: initialising adapter %i frontend %i (%s)...\n",
  186. fe->dvb->num,
  187. fe->id,
  188. fe->ops.info.name);
  189. if (fe->ops.init)
  190. fe->ops.init(fe);
  191. if (fe->ops.tuner_ops.init) {
  192. if (fe->ops.i2c_gate_ctrl)
  193. fe->ops.i2c_gate_ctrl(fe, 1);
  194. fe->ops.tuner_ops.init(fe);
  195. if (fe->ops.i2c_gate_ctrl)
  196. fe->ops.i2c_gate_ctrl(fe, 0);
  197. }
  198. }
  199. void dvb_frontend_reinitialise(struct dvb_frontend *fe)
  200. {
  201. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  202. fepriv->reinitialise = 1;
  203. dvb_frontend_wakeup(fe);
  204. }
  205. EXPORT_SYMBOL(dvb_frontend_reinitialise);
  206. static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepriv, int locked)
  207. {
  208. int q2;
  209. dprintk ("%s\n", __func__);
  210. if (locked)
  211. (fepriv->quality) = (fepriv->quality * 220 + 36*256) / 256;
  212. else
  213. (fepriv->quality) = (fepriv->quality * 220 + 0) / 256;
  214. q2 = fepriv->quality - 128;
  215. q2 *= q2;
  216. fepriv->delay = fepriv->min_delay + q2 * HZ / (128*128);
  217. }
  218. /**
  219. * Performs automatic twiddling of frontend parameters.
  220. *
  221. * @param fe The frontend concerned.
  222. * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT
  223. * @returns Number of complete iterations that have been performed.
  224. */
  225. static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wrapped)
  226. {
  227. int autoinversion;
  228. int ready = 0;
  229. int fe_set_err = 0;
  230. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  231. int original_inversion = fepriv->parameters_in.inversion;
  232. u32 original_frequency = fepriv->parameters_in.frequency;
  233. /* are we using autoinversion? */
  234. autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
  235. (fepriv->parameters_in.inversion == INVERSION_AUTO));
  236. /* setup parameters correctly */
  237. while(!ready) {
  238. /* calculate the lnb_drift */
  239. fepriv->lnb_drift = fepriv->auto_step * fepriv->step_size;
  240. /* wrap the auto_step if we've exceeded the maximum drift */
  241. if (fepriv->lnb_drift > fepriv->max_drift) {
  242. fepriv->auto_step = 0;
  243. fepriv->auto_sub_step = 0;
  244. fepriv->lnb_drift = 0;
  245. }
  246. /* perform inversion and +/- zigzag */
  247. switch(fepriv->auto_sub_step) {
  248. case 0:
  249. /* try with the current inversion and current drift setting */
  250. ready = 1;
  251. break;
  252. case 1:
  253. if (!autoinversion) break;
  254. fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
  255. ready = 1;
  256. break;
  257. case 2:
  258. if (fepriv->lnb_drift == 0) break;
  259. fepriv->lnb_drift = -fepriv->lnb_drift;
  260. ready = 1;
  261. break;
  262. case 3:
  263. if (fepriv->lnb_drift == 0) break;
  264. if (!autoinversion) break;
  265. fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
  266. fepriv->lnb_drift = -fepriv->lnb_drift;
  267. ready = 1;
  268. break;
  269. default:
  270. fepriv->auto_step++;
  271. fepriv->auto_sub_step = -1; /* it'll be incremented to 0 in a moment */
  272. break;
  273. }
  274. if (!ready) fepriv->auto_sub_step++;
  275. }
  276. /* if this attempt would hit where we started, indicate a complete
  277. * iteration has occurred */
  278. if ((fepriv->auto_step == fepriv->started_auto_step) &&
  279. (fepriv->auto_sub_step == 0) && check_wrapped) {
  280. return 1;
  281. }
  282. dprintk("%s: drift:%i inversion:%i auto_step:%i "
  283. "auto_sub_step:%i started_auto_step:%i\n",
  284. __func__, fepriv->lnb_drift, fepriv->inversion,
  285. fepriv->auto_step, fepriv->auto_sub_step, fepriv->started_auto_step);
  286. /* set the frontend itself */
  287. fepriv->parameters_in.frequency += fepriv->lnb_drift;
  288. if (autoinversion)
  289. fepriv->parameters_in.inversion = fepriv->inversion;
  290. if (fe->ops.set_frontend)
  291. fe_set_err = fe->ops.set_frontend(fe, &fepriv->parameters_in);
  292. fepriv->parameters_out = fepriv->parameters_in;
  293. if (fe_set_err < 0) {
  294. fepriv->state = FESTATE_ERROR;
  295. return fe_set_err;
  296. }
  297. fepriv->parameters_in.frequency = original_frequency;
  298. fepriv->parameters_in.inversion = original_inversion;
  299. fepriv->auto_sub_step++;
  300. return 0;
  301. }
  302. static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
  303. {
  304. fe_status_t s = 0;
  305. int retval = 0;
  306. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  307. /* if we've got no parameters, just keep idling */
  308. if (fepriv->state & FESTATE_IDLE) {
  309. fepriv->delay = 3*HZ;
  310. fepriv->quality = 0;
  311. return;
  312. }
  313. /* in SCAN mode, we just set the frontend when asked and leave it alone */
  314. if (fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT) {
  315. if (fepriv->state & FESTATE_RETUNE) {
  316. if (fe->ops.set_frontend)
  317. retval = fe->ops.set_frontend(fe,
  318. &fepriv->parameters_in);
  319. fepriv->parameters_out = fepriv->parameters_in;
  320. if (retval < 0)
  321. fepriv->state = FESTATE_ERROR;
  322. else
  323. fepriv->state = FESTATE_TUNED;
  324. }
  325. fepriv->delay = 3*HZ;
  326. fepriv->quality = 0;
  327. return;
  328. }
  329. /* get the frontend status */
  330. if (fepriv->state & FESTATE_RETUNE) {
  331. s = 0;
  332. } else {
  333. if (fe->ops.read_status)
  334. fe->ops.read_status(fe, &s);
  335. if (s != fepriv->status) {
  336. dvb_frontend_add_event(fe, s);
  337. fepriv->status = s;
  338. }
  339. }
  340. /* if we're not tuned, and we have a lock, move to the TUNED state */
  341. if ((fepriv->state & FESTATE_WAITFORLOCK) && (s & FE_HAS_LOCK)) {
  342. dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
  343. fepriv->state = FESTATE_TUNED;
  344. /* if we're tuned, then we have determined the correct inversion */
  345. if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
  346. (fepriv->parameters_in.inversion == INVERSION_AUTO)) {
  347. fepriv->parameters_in.inversion = fepriv->inversion;
  348. }
  349. return;
  350. }
  351. /* if we are tuned already, check we're still locked */
  352. if (fepriv->state & FESTATE_TUNED) {
  353. dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
  354. /* we're tuned, and the lock is still good... */
  355. if (s & FE_HAS_LOCK) {
  356. return;
  357. } else { /* if we _WERE_ tuned, but now don't have a lock */
  358. fepriv->state = FESTATE_ZIGZAG_FAST;
  359. fepriv->started_auto_step = fepriv->auto_step;
  360. fepriv->check_wrapped = 0;
  361. }
  362. }
  363. /* don't actually do anything if we're in the LOSTLOCK state,
  364. * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
  365. if ((fepriv->state & FESTATE_LOSTLOCK) &&
  366. (fe->ops.info.caps & FE_CAN_RECOVER) && (fepriv->max_drift == 0)) {
  367. dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
  368. return;
  369. }
  370. /* don't do anything if we're in the DISEQC state, since this
  371. * might be someone with a motorized dish controlled by DISEQC.
  372. * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
  373. if (fepriv->state & FESTATE_DISEQC) {
  374. dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
  375. return;
  376. }
  377. /* if we're in the RETUNE state, set everything up for a brand
  378. * new scan, keeping the current inversion setting, as the next
  379. * tune is _very_ likely to require the same */
  380. if (fepriv->state & FESTATE_RETUNE) {
  381. fepriv->lnb_drift = 0;
  382. fepriv->auto_step = 0;
  383. fepriv->auto_sub_step = 0;
  384. fepriv->started_auto_step = 0;
  385. fepriv->check_wrapped = 0;
  386. }
  387. /* fast zigzag. */
  388. if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) {
  389. fepriv->delay = fepriv->min_delay;
  390. /* perform a tune */
  391. retval = dvb_frontend_swzigzag_autotune(fe,
  392. fepriv->check_wrapped);
  393. if (retval < 0) {
  394. return;
  395. } else if (retval) {
  396. /* OK, if we've run out of trials at the fast speed.
  397. * Drop back to slow for the _next_ attempt */
  398. fepriv->state = FESTATE_SEARCHING_SLOW;
  399. fepriv->started_auto_step = fepriv->auto_step;
  400. return;
  401. }
  402. fepriv->check_wrapped = 1;
  403. /* if we've just retuned, enter the ZIGZAG_FAST state.
  404. * This ensures we cannot return from an
  405. * FE_SET_FRONTEND ioctl before the first frontend tune
  406. * occurs */
  407. if (fepriv->state & FESTATE_RETUNE) {
  408. fepriv->state = FESTATE_TUNING_FAST;
  409. }
  410. }
  411. /* slow zigzag */
  412. if (fepriv->state & FESTATE_SEARCHING_SLOW) {
  413. dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
  414. /* Note: don't bother checking for wrapping; we stay in this
  415. * state until we get a lock */
  416. dvb_frontend_swzigzag_autotune(fe, 0);
  417. }
  418. }
  419. static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
  420. {
  421. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  422. if (fepriv->exit != DVB_FE_NO_EXIT)
  423. return 1;
  424. if (fepriv->dvbdev->writers == 1)
  425. if (time_after(jiffies, fepriv->release_jiffies +
  426. dvb_shutdown_timeout * HZ))
  427. return 1;
  428. return 0;
  429. }
  430. static int dvb_frontend_should_wakeup(struct dvb_frontend *fe)
  431. {
  432. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  433. if (fepriv->wakeup) {
  434. fepriv->wakeup = 0;
  435. return 1;
  436. }
  437. return dvb_frontend_is_exiting(fe);
  438. }
  439. static void dvb_frontend_wakeup(struct dvb_frontend *fe)
  440. {
  441. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  442. fepriv->wakeup = 1;
  443. wake_up_interruptible(&fepriv->wait_queue);
  444. }
  445. static int dvb_frontend_thread(void *data)
  446. {
  447. struct dvb_frontend *fe = data;
  448. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  449. unsigned long timeout;
  450. fe_status_t s;
  451. enum dvbfe_algo algo;
  452. struct dvb_frontend_parameters *params;
  453. dprintk("%s\n", __func__);
  454. fepriv->check_wrapped = 0;
  455. fepriv->quality = 0;
  456. fepriv->delay = 3*HZ;
  457. fepriv->status = 0;
  458. fepriv->wakeup = 0;
  459. fepriv->reinitialise = 0;
  460. dvb_frontend_init(fe);
  461. set_freezable();
  462. while (1) {
  463. up(&fepriv->sem); /* is locked when we enter the thread... */
  464. restart:
  465. timeout = wait_event_interruptible_timeout(fepriv->wait_queue,
  466. dvb_frontend_should_wakeup(fe) || kthread_should_stop()
  467. || freezing(current),
  468. fepriv->delay);
  469. if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
  470. /* got signal or quitting */
  471. fepriv->exit = DVB_FE_NORMAL_EXIT;
  472. break;
  473. }
  474. if (try_to_freeze())
  475. goto restart;
  476. if (down_interruptible(&fepriv->sem))
  477. break;
  478. if (fepriv->reinitialise) {
  479. dvb_frontend_init(fe);
  480. if (fepriv->tone != -1) {
  481. fe->ops.set_tone(fe, fepriv->tone);
  482. }
  483. if (fepriv->voltage != -1) {
  484. fe->ops.set_voltage(fe, fepriv->voltage);
  485. }
  486. fepriv->reinitialise = 0;
  487. }
  488. /* do an iteration of the tuning loop */
  489. if (fe->ops.get_frontend_algo) {
  490. algo = fe->ops.get_frontend_algo(fe);
  491. switch (algo) {
  492. case DVBFE_ALGO_HW:
  493. dprintk("%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__);
  494. params = NULL; /* have we been asked to RETUNE ? */
  495. if (fepriv->state & FESTATE_RETUNE) {
  496. dprintk("%s: Retune requested, FESTATE_RETUNE\n", __func__);
  497. params = &fepriv->parameters_in;
  498. fepriv->state = FESTATE_TUNED;
  499. }
  500. if (fe->ops.tune)
  501. fe->ops.tune(fe, params, fepriv->tune_mode_flags, &fepriv->delay, &s);
  502. if (params)
  503. fepriv->parameters_out = *params;
  504. if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) {
  505. dprintk("%s: state changed, adding current state\n", __func__);
  506. dvb_frontend_add_event(fe, s);
  507. fepriv->status = s;
  508. }
  509. break;
  510. case DVBFE_ALGO_SW:
  511. dprintk("%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__);
  512. dvb_frontend_swzigzag(fe);
  513. break;
  514. case DVBFE_ALGO_CUSTOM:
  515. dprintk("%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state);
  516. if (fepriv->state & FESTATE_RETUNE) {
  517. dprintk("%s: Retune requested, FESTAT_RETUNE\n", __func__);
  518. fepriv->state = FESTATE_TUNED;
  519. }
  520. /* Case where we are going to search for a carrier
  521. * User asked us to retune again for some reason, possibly
  522. * requesting a search with a new set of parameters
  523. */
  524. if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) {
  525. if (fe->ops.search) {
  526. fepriv->algo_status = fe->ops.search(fe, &fepriv->parameters_in);
  527. /* We did do a search as was requested, the flags are
  528. * now unset as well and has the flags wrt to search.
  529. */
  530. } else {
  531. fepriv->algo_status &= ~DVBFE_ALGO_SEARCH_AGAIN;
  532. }
  533. }
  534. /* Track the carrier if the search was successful */
  535. if (fepriv->algo_status == DVBFE_ALGO_SEARCH_SUCCESS) {
  536. if (fe->ops.track)
  537. fe->ops.track(fe, &fepriv->parameters_in);
  538. } else {
  539. fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
  540. fepriv->delay = HZ / 2;
  541. }
  542. fepriv->parameters_out = fepriv->parameters_in;
  543. fe->ops.read_status(fe, &s);
  544. if (s != fepriv->status) {
  545. dvb_frontend_add_event(fe, s); /* update event list */
  546. fepriv->status = s;
  547. if (!(s & FE_HAS_LOCK)) {
  548. fepriv->delay = HZ / 10;
  549. fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
  550. } else {
  551. fepriv->delay = 60 * HZ;
  552. }
  553. }
  554. break;
  555. default:
  556. dprintk("%s: UNDEFINED ALGO !\n", __func__);
  557. break;
  558. }
  559. } else {
  560. dvb_frontend_swzigzag(fe);
  561. }
  562. }
  563. if (dvb_powerdown_on_sleep) {
  564. if (fe->ops.set_voltage)
  565. fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF);
  566. if (fe->ops.tuner_ops.sleep) {
  567. if (fe->ops.i2c_gate_ctrl)
  568. fe->ops.i2c_gate_ctrl(fe, 1);
  569. fe->ops.tuner_ops.sleep(fe);
  570. if (fe->ops.i2c_gate_ctrl)
  571. fe->ops.i2c_gate_ctrl(fe, 0);
  572. }
  573. if (fe->ops.sleep)
  574. fe->ops.sleep(fe);
  575. }
  576. fepriv->thread = NULL;
  577. if (kthread_should_stop())
  578. fepriv->exit = DVB_FE_DEVICE_REMOVED;
  579. else
  580. fepriv->exit = DVB_FE_NO_EXIT;
  581. mb();
  582. dvb_frontend_wakeup(fe);
  583. return 0;
  584. }
  585. static void dvb_frontend_stop(struct dvb_frontend *fe)
  586. {
  587. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  588. dprintk ("%s\n", __func__);
  589. fepriv->exit = DVB_FE_NORMAL_EXIT;
  590. mb();
  591. if (!fepriv->thread)
  592. return;
  593. kthread_stop(fepriv->thread);
  594. sema_init(&fepriv->sem, 1);
  595. fepriv->state = FESTATE_IDLE;
  596. /* paranoia check in case a signal arrived */
  597. if (fepriv->thread)
  598. printk("dvb_frontend_stop: warning: thread %p won't exit\n",
  599. fepriv->thread);
  600. }
  601. s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
  602. {
  603. return ((curtime.tv_usec < lasttime.tv_usec) ?
  604. 1000000 - lasttime.tv_usec + curtime.tv_usec :
  605. curtime.tv_usec - lasttime.tv_usec);
  606. }
  607. EXPORT_SYMBOL(timeval_usec_diff);
  608. static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec)
  609. {
  610. curtime->tv_usec += add_usec;
  611. if (curtime->tv_usec >= 1000000) {
  612. curtime->tv_usec -= 1000000;
  613. curtime->tv_sec++;
  614. }
  615. }
  616. /*
  617. * Sleep until gettimeofday() > waketime + add_usec
  618. * This needs to be as precise as possible, but as the delay is
  619. * usually between 2ms and 32ms, it is done using a scheduled msleep
  620. * followed by usleep (normally a busy-wait loop) for the remainder
  621. */
  622. void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec)
  623. {
  624. struct timeval lasttime;
  625. s32 delta, newdelta;
  626. timeval_usec_add(waketime, add_usec);
  627. do_gettimeofday(&lasttime);
  628. delta = timeval_usec_diff(lasttime, *waketime);
  629. if (delta > 2500) {
  630. msleep((delta - 1500) / 1000);
  631. do_gettimeofday(&lasttime);
  632. newdelta = timeval_usec_diff(lasttime, *waketime);
  633. delta = (newdelta > delta) ? 0 : newdelta;
  634. }
  635. if (delta > 0)
  636. udelay(delta);
  637. }
  638. EXPORT_SYMBOL(dvb_frontend_sleep_until);
  639. static int dvb_frontend_start(struct dvb_frontend *fe)
  640. {
  641. int ret;
  642. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  643. struct task_struct *fe_thread;
  644. dprintk ("%s\n", __func__);
  645. if (fepriv->thread) {
  646. if (fepriv->exit == DVB_FE_NO_EXIT)
  647. return 0;
  648. else
  649. dvb_frontend_stop (fe);
  650. }
  651. if (signal_pending(current))
  652. return -EINTR;
  653. if (down_interruptible (&fepriv->sem))
  654. return -EINTR;
  655. fepriv->state = FESTATE_IDLE;
  656. fepriv->exit = DVB_FE_NO_EXIT;
  657. fepriv->thread = NULL;
  658. mb();
  659. fe_thread = kthread_run(dvb_frontend_thread, fe,
  660. "kdvb-ad-%i-fe-%i", fe->dvb->num,fe->id);
  661. if (IS_ERR(fe_thread)) {
  662. ret = PTR_ERR(fe_thread);
  663. printk("dvb_frontend_start: failed to start kthread (%d)\n", ret);
  664. up(&fepriv->sem);
  665. return ret;
  666. }
  667. fepriv->thread = fe_thread;
  668. return 0;
  669. }
  670. static void dvb_frontend_get_frequency_limits(struct dvb_frontend *fe,
  671. u32 *freq_min, u32 *freq_max)
  672. {
  673. *freq_min = max(fe->ops.info.frequency_min, fe->ops.tuner_ops.info.frequency_min);
  674. if (fe->ops.info.frequency_max == 0)
  675. *freq_max = fe->ops.tuner_ops.info.frequency_max;
  676. else if (fe->ops.tuner_ops.info.frequency_max == 0)
  677. *freq_max = fe->ops.info.frequency_max;
  678. else
  679. *freq_max = min(fe->ops.info.frequency_max, fe->ops.tuner_ops.info.frequency_max);
  680. if (*freq_min == 0 || *freq_max == 0)
  681. printk(KERN_WARNING "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
  682. fe->dvb->num,fe->id);
  683. }
  684. static int dvb_frontend_check_parameters(struct dvb_frontend *fe,
  685. struct dvb_frontend_parameters *parms)
  686. {
  687. u32 freq_min;
  688. u32 freq_max;
  689. /* range check: frequency */
  690. dvb_frontend_get_frequency_limits(fe, &freq_min, &freq_max);
  691. if ((freq_min && parms->frequency < freq_min) ||
  692. (freq_max && parms->frequency > freq_max)) {
  693. printk(KERN_WARNING "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
  694. fe->dvb->num, fe->id, parms->frequency, freq_min, freq_max);
  695. return -EINVAL;
  696. }
  697. /* range check: symbol rate */
  698. if (fe->ops.info.type == FE_QPSK) {
  699. if ((fe->ops.info.symbol_rate_min &&
  700. parms->u.qpsk.symbol_rate < fe->ops.info.symbol_rate_min) ||
  701. (fe->ops.info.symbol_rate_max &&
  702. parms->u.qpsk.symbol_rate > fe->ops.info.symbol_rate_max)) {
  703. printk(KERN_WARNING "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
  704. fe->dvb->num, fe->id, parms->u.qpsk.symbol_rate,
  705. fe->ops.info.symbol_rate_min, fe->ops.info.symbol_rate_max);
  706. return -EINVAL;
  707. }
  708. } else if (fe->ops.info.type == FE_QAM) {
  709. if ((fe->ops.info.symbol_rate_min &&
  710. parms->u.qam.symbol_rate < fe->ops.info.symbol_rate_min) ||
  711. (fe->ops.info.symbol_rate_max &&
  712. parms->u.qam.symbol_rate > fe->ops.info.symbol_rate_max)) {
  713. printk(KERN_WARNING "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
  714. fe->dvb->num, fe->id, parms->u.qam.symbol_rate,
  715. fe->ops.info.symbol_rate_min, fe->ops.info.symbol_rate_max);
  716. return -EINVAL;
  717. }
  718. }
  719. /* check for supported modulation */
  720. if (fe->ops.info.type == FE_QAM &&
  721. (parms->u.qam.modulation > QAM_AUTO ||
  722. !((1 << (parms->u.qam.modulation + 10)) & fe->ops.info.caps))) {
  723. printk(KERN_WARNING "DVB: adapter %i frontend %i modulation %u not supported\n",
  724. fe->dvb->num, fe->id, parms->u.qam.modulation);
  725. return -EINVAL;
  726. }
  727. return 0;
  728. }
  729. static int dvb_frontend_clear_cache(struct dvb_frontend *fe)
  730. {
  731. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  732. int i;
  733. memset(c, 0, sizeof(struct dtv_frontend_properties));
  734. c->state = DTV_CLEAR;
  735. c->delivery_system = SYS_UNDEFINED;
  736. c->inversion = INVERSION_AUTO;
  737. c->fec_inner = FEC_AUTO;
  738. c->transmission_mode = TRANSMISSION_MODE_AUTO;
  739. c->bandwidth_hz = BANDWIDTH_AUTO;
  740. c->guard_interval = GUARD_INTERVAL_AUTO;
  741. c->hierarchy = HIERARCHY_AUTO;
  742. c->symbol_rate = QAM_AUTO;
  743. c->code_rate_HP = FEC_AUTO;
  744. c->code_rate_LP = FEC_AUTO;
  745. c->isdbt_partial_reception = -1;
  746. c->isdbt_sb_mode = -1;
  747. c->isdbt_sb_subchannel = -1;
  748. c->isdbt_sb_segment_idx = -1;
  749. c->isdbt_sb_segment_count = -1;
  750. c->isdbt_layer_enabled = 0x7;
  751. for (i = 0; i < 3; i++) {
  752. c->layer[i].fec = FEC_AUTO;
  753. c->layer[i].modulation = QAM_AUTO;
  754. c->layer[i].interleaving = -1;
  755. c->layer[i].segment_count = -1;
  756. }
  757. return 0;
  758. }
  759. #define _DTV_CMD(n, s, b) \
  760. [n] = { \
  761. .name = #n, \
  762. .cmd = n, \
  763. .set = s,\
  764. .buffer = b \
  765. }
  766. static struct dtv_cmds_h dtv_cmds[] = {
  767. _DTV_CMD(DTV_TUNE, 1, 0),
  768. _DTV_CMD(DTV_CLEAR, 1, 0),
  769. /* Set */
  770. _DTV_CMD(DTV_FREQUENCY, 1, 0),
  771. _DTV_CMD(DTV_BANDWIDTH_HZ, 1, 0),
  772. _DTV_CMD(DTV_MODULATION, 1, 0),
  773. _DTV_CMD(DTV_INVERSION, 1, 0),
  774. _DTV_CMD(DTV_DISEQC_MASTER, 1, 1),
  775. _DTV_CMD(DTV_SYMBOL_RATE, 1, 0),
  776. _DTV_CMD(DTV_INNER_FEC, 1, 0),
  777. _DTV_CMD(DTV_VOLTAGE, 1, 0),
  778. _DTV_CMD(DTV_TONE, 1, 0),
  779. _DTV_CMD(DTV_PILOT, 1, 0),
  780. _DTV_CMD(DTV_ROLLOFF, 1, 0),
  781. _DTV_CMD(DTV_DELIVERY_SYSTEM, 1, 0),
  782. _DTV_CMD(DTV_HIERARCHY, 1, 0),
  783. _DTV_CMD(DTV_CODE_RATE_HP, 1, 0),
  784. _DTV_CMD(DTV_CODE_RATE_LP, 1, 0),
  785. _DTV_CMD(DTV_GUARD_INTERVAL, 1, 0),
  786. _DTV_CMD(DTV_TRANSMISSION_MODE, 1, 0),
  787. _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION, 1, 0),
  788. _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING, 1, 0),
  789. _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID, 1, 0),
  790. _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX, 1, 0),
  791. _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT, 1, 0),
  792. _DTV_CMD(DTV_ISDBT_LAYER_ENABLED, 1, 0),
  793. _DTV_CMD(DTV_ISDBT_LAYERA_FEC, 1, 0),
  794. _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION, 1, 0),
  795. _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT, 1, 0),
  796. _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING, 1, 0),
  797. _DTV_CMD(DTV_ISDBT_LAYERB_FEC, 1, 0),
  798. _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION, 1, 0),
  799. _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT, 1, 0),
  800. _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING, 1, 0),
  801. _DTV_CMD(DTV_ISDBT_LAYERC_FEC, 1, 0),
  802. _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION, 1, 0),
  803. _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT, 1, 0),
  804. _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING, 1, 0),
  805. _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION, 0, 0),
  806. _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING, 0, 0),
  807. _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID, 0, 0),
  808. _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX, 0, 0),
  809. _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT, 0, 0),
  810. _DTV_CMD(DTV_ISDBT_LAYER_ENABLED, 0, 0),
  811. _DTV_CMD(DTV_ISDBT_LAYERA_FEC, 0, 0),
  812. _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION, 0, 0),
  813. _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT, 0, 0),
  814. _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING, 0, 0),
  815. _DTV_CMD(DTV_ISDBT_LAYERB_FEC, 0, 0),
  816. _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION, 0, 0),
  817. _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT, 0, 0),
  818. _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING, 0, 0),
  819. _DTV_CMD(DTV_ISDBT_LAYERC_FEC, 0, 0),
  820. _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION, 0, 0),
  821. _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT, 0, 0),
  822. _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING, 0, 0),
  823. _DTV_CMD(DTV_ISDBS_TS_ID, 1, 0),
  824. /* Get */
  825. _DTV_CMD(DTV_DISEQC_SLAVE_REPLY, 0, 1),
  826. _DTV_CMD(DTV_API_VERSION, 0, 0),
  827. _DTV_CMD(DTV_CODE_RATE_HP, 0, 0),
  828. _DTV_CMD(DTV_CODE_RATE_LP, 0, 0),
  829. _DTV_CMD(DTV_GUARD_INTERVAL, 0, 0),
  830. _DTV_CMD(DTV_TRANSMISSION_MODE, 0, 0),
  831. _DTV_CMD(DTV_HIERARCHY, 0, 0),
  832. };
  833. static void dtv_property_dump(struct dtv_property *tvp)
  834. {
  835. int i;
  836. if (tvp->cmd <= 0 || tvp->cmd > DTV_MAX_COMMAND) {
  837. printk(KERN_WARNING "%s: tvp.cmd = 0x%08x undefined\n",
  838. __func__, tvp->cmd);
  839. return;
  840. }
  841. dprintk("%s() tvp.cmd = 0x%08x (%s)\n"
  842. ,__func__
  843. ,tvp->cmd
  844. ,dtv_cmds[ tvp->cmd ].name);
  845. if(dtv_cmds[ tvp->cmd ].buffer) {
  846. dprintk("%s() tvp.u.buffer.len = 0x%02x\n"
  847. ,__func__
  848. ,tvp->u.buffer.len);
  849. for(i = 0; i < tvp->u.buffer.len; i++)
  850. dprintk("%s() tvp.u.buffer.data[0x%02x] = 0x%02x\n"
  851. ,__func__
  852. ,i
  853. ,tvp->u.buffer.data[i]);
  854. } else
  855. dprintk("%s() tvp.u.data = 0x%08x\n", __func__, tvp->u.data);
  856. }
  857. static int is_legacy_delivery_system(fe_delivery_system_t s)
  858. {
  859. if((s == SYS_UNDEFINED) || (s == SYS_DVBC_ANNEX_AC) ||
  860. (s == SYS_DVBC_ANNEX_B) || (s == SYS_DVBT) || (s == SYS_DVBS) ||
  861. (s == SYS_ATSC))
  862. return 1;
  863. return 0;
  864. }
  865. /* Synchronise the legacy tuning parameters into the cache, so that demodulator
  866. * drivers can use a single set_frontend tuning function, regardless of whether
  867. * it's being used for the legacy or new API, reducing code and complexity.
  868. */
  869. static void dtv_property_cache_sync(struct dvb_frontend *fe,
  870. struct dtv_frontend_properties *c,
  871. const struct dvb_frontend_parameters *p)
  872. {
  873. c->frequency = p->frequency;
  874. c->inversion = p->inversion;
  875. switch (fe->ops.info.type) {
  876. case FE_QPSK:
  877. c->modulation = QPSK; /* implied for DVB-S in legacy API */
  878. c->rolloff = ROLLOFF_35;/* implied for DVB-S */
  879. c->symbol_rate = p->u.qpsk.symbol_rate;
  880. c->fec_inner = p->u.qpsk.fec_inner;
  881. c->delivery_system = SYS_DVBS;
  882. break;
  883. case FE_QAM:
  884. c->symbol_rate = p->u.qam.symbol_rate;
  885. c->fec_inner = p->u.qam.fec_inner;
  886. c->modulation = p->u.qam.modulation;
  887. c->delivery_system = SYS_DVBC_ANNEX_AC;
  888. break;
  889. case FE_OFDM:
  890. if (p->u.ofdm.bandwidth == BANDWIDTH_6_MHZ)
  891. c->bandwidth_hz = 6000000;
  892. else if (p->u.ofdm.bandwidth == BANDWIDTH_7_MHZ)
  893. c->bandwidth_hz = 7000000;
  894. else if (p->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  895. c->bandwidth_hz = 8000000;
  896. else
  897. /* Including BANDWIDTH_AUTO */
  898. c->bandwidth_hz = 0;
  899. c->code_rate_HP = p->u.ofdm.code_rate_HP;
  900. c->code_rate_LP = p->u.ofdm.code_rate_LP;
  901. c->modulation = p->u.ofdm.constellation;
  902. c->transmission_mode = p->u.ofdm.transmission_mode;
  903. c->guard_interval = p->u.ofdm.guard_interval;
  904. c->hierarchy = p->u.ofdm.hierarchy_information;
  905. c->delivery_system = SYS_DVBT;
  906. break;
  907. case FE_ATSC:
  908. c->modulation = p->u.vsb.modulation;
  909. if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
  910. c->delivery_system = SYS_ATSC;
  911. else
  912. c->delivery_system = SYS_DVBC_ANNEX_B;
  913. break;
  914. }
  915. }
  916. /* Ensure the cached values are set correctly in the frontend
  917. * legacy tuning structures, for the advanced tuning API.
  918. */
  919. static void dtv_property_legacy_params_sync(struct dvb_frontend *fe)
  920. {
  921. const struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  922. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  923. struct dvb_frontend_parameters *p = &fepriv->parameters_in;
  924. p->frequency = c->frequency;
  925. p->inversion = c->inversion;
  926. switch (fe->ops.info.type) {
  927. case FE_QPSK:
  928. dprintk("%s() Preparing QPSK req\n", __func__);
  929. p->u.qpsk.symbol_rate = c->symbol_rate;
  930. p->u.qpsk.fec_inner = c->fec_inner;
  931. break;
  932. case FE_QAM:
  933. dprintk("%s() Preparing QAM req\n", __func__);
  934. p->u.qam.symbol_rate = c->symbol_rate;
  935. p->u.qam.fec_inner = c->fec_inner;
  936. p->u.qam.modulation = c->modulation;
  937. break;
  938. case FE_OFDM:
  939. dprintk("%s() Preparing OFDM req\n", __func__);
  940. if (c->bandwidth_hz == 6000000)
  941. p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
  942. else if (c->bandwidth_hz == 7000000)
  943. p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
  944. else if (c->bandwidth_hz == 8000000)
  945. p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
  946. else
  947. p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
  948. p->u.ofdm.code_rate_HP = c->code_rate_HP;
  949. p->u.ofdm.code_rate_LP = c->code_rate_LP;
  950. p->u.ofdm.constellation = c->modulation;
  951. p->u.ofdm.transmission_mode = c->transmission_mode;
  952. p->u.ofdm.guard_interval = c->guard_interval;
  953. p->u.ofdm.hierarchy_information = c->hierarchy;
  954. break;
  955. case FE_ATSC:
  956. dprintk("%s() Preparing VSB req\n", __func__);
  957. p->u.vsb.modulation = c->modulation;
  958. break;
  959. }
  960. }
  961. /* Ensure the cached values are set correctly in the frontend
  962. * legacy tuning structures, for the legacy tuning API.
  963. */
  964. static void dtv_property_adv_params_sync(struct dvb_frontend *fe)
  965. {
  966. const struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  967. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  968. struct dvb_frontend_parameters *p = &fepriv->parameters_in;
  969. p->frequency = c->frequency;
  970. p->inversion = c->inversion;
  971. switch(c->modulation) {
  972. case PSK_8:
  973. case APSK_16:
  974. case APSK_32:
  975. case QPSK:
  976. p->u.qpsk.symbol_rate = c->symbol_rate;
  977. p->u.qpsk.fec_inner = c->fec_inner;
  978. break;
  979. default:
  980. break;
  981. }
  982. /* Fake out a generic DVB-T request so we pass validation in the ioctl */
  983. if ((c->delivery_system == SYS_ISDBT) ||
  984. (c->delivery_system == SYS_DVBT2)) {
  985. p->u.ofdm.constellation = QAM_AUTO;
  986. p->u.ofdm.code_rate_HP = FEC_AUTO;
  987. p->u.ofdm.code_rate_LP = FEC_AUTO;
  988. p->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
  989. p->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
  990. p->u.ofdm.hierarchy_information = HIERARCHY_AUTO;
  991. if (c->bandwidth_hz == 8000000)
  992. p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
  993. else if (c->bandwidth_hz == 7000000)
  994. p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
  995. else if (c->bandwidth_hz == 6000000)
  996. p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
  997. else
  998. p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
  999. }
  1000. }
  1001. static void dtv_property_cache_submit(struct dvb_frontend *fe)
  1002. {
  1003. const struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  1004. /* For legacy delivery systems we don't need the delivery_system to
  1005. * be specified, but we populate the older structures from the cache
  1006. * so we can call set_frontend on older drivers.
  1007. */
  1008. if(is_legacy_delivery_system(c->delivery_system)) {
  1009. dprintk("%s() legacy, modulation = %d\n", __func__, c->modulation);
  1010. dtv_property_legacy_params_sync(fe);
  1011. } else {
  1012. dprintk("%s() adv, modulation = %d\n", __func__, c->modulation);
  1013. /* For advanced delivery systems / modulation types ...
  1014. * we seed the lecacy dvb_frontend_parameters structure
  1015. * so that the sanity checking code later in the IOCTL processing
  1016. * can validate our basic frequency ranges, symbolrates, modulation
  1017. * etc.
  1018. */
  1019. dtv_property_adv_params_sync(fe);
  1020. }
  1021. }
  1022. static int dvb_frontend_ioctl_legacy(struct file *file,
  1023. unsigned int cmd, void *parg);
  1024. static int dvb_frontend_ioctl_properties(struct file *file,
  1025. unsigned int cmd, void *parg);
  1026. static int dtv_property_process_get(struct dvb_frontend *fe,
  1027. struct dtv_property *tvp,
  1028. struct file *file)
  1029. {
  1030. const struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  1031. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  1032. struct dtv_frontend_properties cdetected;
  1033. int r;
  1034. /*
  1035. * If the driver implements a get_frontend function, then convert
  1036. * detected parameters to S2API properties.
  1037. */
  1038. if (fe->ops.get_frontend) {
  1039. cdetected = *c;
  1040. dtv_property_cache_sync(fe, &cdetected, &fepriv->parameters_out);
  1041. c = &cdetected;
  1042. }
  1043. switch(tvp->cmd) {
  1044. case DTV_FREQUENCY:
  1045. tvp->u.data = c->frequency;
  1046. break;
  1047. case DTV_MODULATION:
  1048. tvp->u.data = c->modulation;
  1049. break;
  1050. case DTV_BANDWIDTH_HZ:
  1051. tvp->u.data = c->bandwidth_hz;
  1052. break;
  1053. case DTV_INVERSION:
  1054. tvp->u.data = c->inversion;
  1055. break;
  1056. case DTV_SYMBOL_RATE:
  1057. tvp->u.data = c->symbol_rate;
  1058. break;
  1059. case DTV_INNER_FEC:
  1060. tvp->u.data = c->fec_inner;
  1061. break;
  1062. case DTV_PILOT:
  1063. tvp->u.data = c->pilot;
  1064. break;
  1065. case DTV_ROLLOFF:
  1066. tvp->u.data = c->rolloff;
  1067. break;
  1068. case DTV_DELIVERY_SYSTEM:
  1069. tvp->u.data = c->delivery_system;
  1070. break;
  1071. case DTV_VOLTAGE:
  1072. tvp->u.data = c->voltage;
  1073. break;
  1074. case DTV_TONE:
  1075. tvp->u.data = c->sectone;
  1076. break;
  1077. case DTV_API_VERSION:
  1078. tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
  1079. break;
  1080. case DTV_CODE_RATE_HP:
  1081. tvp->u.data = c->code_rate_HP;
  1082. break;
  1083. case DTV_CODE_RATE_LP:
  1084. tvp->u.data = c->code_rate_LP;
  1085. break;
  1086. case DTV_GUARD_INTERVAL:
  1087. tvp->u.data = c->guard_interval;
  1088. break;
  1089. case DTV_TRANSMISSION_MODE:
  1090. tvp->u.data = c->transmission_mode;
  1091. break;
  1092. case DTV_HIERARCHY:
  1093. tvp->u.data = c->hierarchy;
  1094. break;
  1095. /* ISDB-T Support here */
  1096. case DTV_ISDBT_PARTIAL_RECEPTION:
  1097. tvp->u.data = c->isdbt_partial_reception;
  1098. break;
  1099. case DTV_ISDBT_SOUND_BROADCASTING:
  1100. tvp->u.data = c->isdbt_sb_mode;
  1101. break;
  1102. case DTV_ISDBT_SB_SUBCHANNEL_ID:
  1103. tvp->u.data = c->isdbt_sb_subchannel;
  1104. break;
  1105. case DTV_ISDBT_SB_SEGMENT_IDX:
  1106. tvp->u.data = c->isdbt_sb_segment_idx;
  1107. break;
  1108. case DTV_ISDBT_SB_SEGMENT_COUNT:
  1109. tvp->u.data = c->isdbt_sb_segment_count;
  1110. break;
  1111. case DTV_ISDBT_LAYER_ENABLED:
  1112. tvp->u.data = c->isdbt_layer_enabled;
  1113. break;
  1114. case DTV_ISDBT_LAYERA_FEC:
  1115. tvp->u.data = c->layer[0].fec;
  1116. break;
  1117. case DTV_ISDBT_LAYERA_MODULATION:
  1118. tvp->u.data = c->layer[0].modulation;
  1119. break;
  1120. case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
  1121. tvp->u.data = c->layer[0].segment_count;
  1122. break;
  1123. case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
  1124. tvp->u.data = c->layer[0].interleaving;
  1125. break;
  1126. case DTV_ISDBT_LAYERB_FEC:
  1127. tvp->u.data = c->layer[1].fec;
  1128. break;
  1129. case DTV_ISDBT_LAYERB_MODULATION:
  1130. tvp->u.data = c->layer[1].modulation;
  1131. break;
  1132. case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
  1133. tvp->u.data = c->layer[1].segment_count;
  1134. break;
  1135. case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
  1136. tvp->u.data = c->layer[1].interleaving;
  1137. break;
  1138. case DTV_ISDBT_LAYERC_FEC:
  1139. tvp->u.data = c->layer[2].fec;
  1140. break;
  1141. case DTV_ISDBT_LAYERC_MODULATION:
  1142. tvp->u.data = c->layer[2].modulation;
  1143. break;
  1144. case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
  1145. tvp->u.data = c->layer[2].segment_count;
  1146. break;
  1147. case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
  1148. tvp->u.data = c->layer[2].interleaving;
  1149. break;
  1150. case DTV_ISDBS_TS_ID:
  1151. tvp->u.data = c->isdbs_ts_id;
  1152. break;
  1153. case DTV_DVBT2_PLP_ID:
  1154. tvp->u.data = c->dvbt2_plp_id;
  1155. break;
  1156. default:
  1157. return -EINVAL;
  1158. }
  1159. /* Allow the frontend to override outgoing properties */
  1160. if (fe->ops.get_property) {
  1161. r = fe->ops.get_property(fe, tvp);
  1162. if (r < 0)
  1163. return r;
  1164. }
  1165. dtv_property_dump(tvp);
  1166. return 0;
  1167. }
  1168. static int dtv_property_process_set(struct dvb_frontend *fe,
  1169. struct dtv_property *tvp,
  1170. struct file *file)
  1171. {
  1172. int r = 0;
  1173. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  1174. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  1175. dtv_property_dump(tvp);
  1176. /* Allow the frontend to validate incoming properties */
  1177. if (fe->ops.set_property) {
  1178. r = fe->ops.set_property(fe, tvp);
  1179. if (r < 0)
  1180. return r;
  1181. }
  1182. switch(tvp->cmd) {
  1183. case DTV_CLEAR:
  1184. /* Reset a cache of data specific to the frontend here. This does
  1185. * not effect hardware.
  1186. */
  1187. dvb_frontend_clear_cache(fe);
  1188. dprintk("%s() Flushing property cache\n", __func__);
  1189. break;
  1190. case DTV_TUNE:
  1191. /* interpret the cache of data, build either a traditional frontend
  1192. * tunerequest so we can pass validation in the FE_SET_FRONTEND
  1193. * ioctl.
  1194. */
  1195. c->state = tvp->cmd;
  1196. dprintk("%s() Finalised property cache\n", __func__);
  1197. dtv_property_cache_submit(fe);
  1198. r = dvb_frontend_ioctl_legacy(file, FE_SET_FRONTEND,
  1199. &fepriv->parameters_in);
  1200. break;
  1201. case DTV_FREQUENCY:
  1202. c->frequency = tvp->u.data;
  1203. break;
  1204. case DTV_MODULATION:
  1205. c->modulation = tvp->u.data;
  1206. break;
  1207. case DTV_BANDWIDTH_HZ:
  1208. c->bandwidth_hz = tvp->u.data;
  1209. break;
  1210. case DTV_INVERSION:
  1211. c->inversion = tvp->u.data;
  1212. break;
  1213. case DTV_SYMBOL_RATE:
  1214. c->symbol_rate = tvp->u.data;
  1215. break;
  1216. case DTV_INNER_FEC:
  1217. c->fec_inner = tvp->u.data;
  1218. break;
  1219. case DTV_PILOT:
  1220. c->pilot = tvp->u.data;
  1221. break;
  1222. case DTV_ROLLOFF:
  1223. c->rolloff = tvp->u.data;
  1224. break;
  1225. case DTV_DELIVERY_SYSTEM:
  1226. c->delivery_system = tvp->u.data;
  1227. break;
  1228. case DTV_VOLTAGE:
  1229. c->voltage = tvp->u.data;
  1230. r = dvb_frontend_ioctl_legacy(file, FE_SET_VOLTAGE,
  1231. (void *)c->voltage);
  1232. break;
  1233. case DTV_TONE:
  1234. c->sectone = tvp->u.data;
  1235. r = dvb_frontend_ioctl_legacy(file, FE_SET_TONE,
  1236. (void *)c->sectone);
  1237. break;
  1238. case DTV_CODE_RATE_HP:
  1239. c->code_rate_HP = tvp->u.data;
  1240. break;
  1241. case DTV_CODE_RATE_LP:
  1242. c->code_rate_LP = tvp->u.data;
  1243. break;
  1244. case DTV_GUARD_INTERVAL:
  1245. c->guard_interval = tvp->u.data;
  1246. break;
  1247. case DTV_TRANSMISSION_MODE:
  1248. c->transmission_mode = tvp->u.data;
  1249. break;
  1250. case DTV_HIERARCHY:
  1251. c->hierarchy = tvp->u.data;
  1252. break;
  1253. /* ISDB-T Support here */
  1254. case DTV_ISDBT_PARTIAL_RECEPTION:
  1255. c->isdbt_partial_reception = tvp->u.data;
  1256. break;
  1257. case DTV_ISDBT_SOUND_BROADCASTING:
  1258. c->isdbt_sb_mode = tvp->u.data;
  1259. break;
  1260. case DTV_ISDBT_SB_SUBCHANNEL_ID:
  1261. c->isdbt_sb_subchannel = tvp->u.data;
  1262. break;
  1263. case DTV_ISDBT_SB_SEGMENT_IDX:
  1264. c->isdbt_sb_segment_idx = tvp->u.data;
  1265. break;
  1266. case DTV_ISDBT_SB_SEGMENT_COUNT:
  1267. c->isdbt_sb_segment_count = tvp->u.data;
  1268. break;
  1269. case DTV_ISDBT_LAYER_ENABLED:
  1270. c->isdbt_layer_enabled = tvp->u.data;
  1271. break;
  1272. case DTV_ISDBT_LAYERA_FEC:
  1273. c->layer[0].fec = tvp->u.data;
  1274. break;
  1275. case DTV_ISDBT_LAYERA_MODULATION:
  1276. c->layer[0].modulation = tvp->u.data;
  1277. break;
  1278. case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
  1279. c->layer[0].segment_count = tvp->u.data;
  1280. break;
  1281. case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
  1282. c->layer[0].interleaving = tvp->u.data;
  1283. break;
  1284. case DTV_ISDBT_LAYERB_FEC:
  1285. c->layer[1].fec = tvp->u.data;
  1286. break;
  1287. case DTV_ISDBT_LAYERB_MODULATION:
  1288. c->layer[1].modulation = tvp->u.data;
  1289. break;
  1290. case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
  1291. c->layer[1].segment_count = tvp->u.data;
  1292. break;
  1293. case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
  1294. c->layer[1].interleaving = tvp->u.data;
  1295. break;
  1296. case DTV_ISDBT_LAYERC_FEC:
  1297. c->layer[2].fec = tvp->u.data;
  1298. break;
  1299. case DTV_ISDBT_LAYERC_MODULATION:
  1300. c->layer[2].modulation = tvp->u.data;
  1301. break;
  1302. case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
  1303. c->layer[2].segment_count = tvp->u.data;
  1304. break;
  1305. case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
  1306. c->layer[2].interleaving = tvp->u.data;
  1307. break;
  1308. case DTV_ISDBS_TS_ID:
  1309. c->isdbs_ts_id = tvp->u.data;
  1310. break;
  1311. case DTV_DVBT2_PLP_ID:
  1312. c->dvbt2_plp_id = tvp->u.data;
  1313. break;
  1314. default:
  1315. return -EINVAL;
  1316. }
  1317. return r;
  1318. }
  1319. static int dvb_frontend_ioctl(struct file *file,
  1320. unsigned int cmd, void *parg)
  1321. {
  1322. struct dvb_device *dvbdev = file->private_data;
  1323. struct dvb_frontend *fe = dvbdev->priv;
  1324. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  1325. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  1326. int err = -EOPNOTSUPP;
  1327. dprintk("%s (%d)\n", __func__, _IOC_NR(cmd));
  1328. if (fepriv->exit != DVB_FE_NO_EXIT)
  1329. return -ENODEV;
  1330. if ((file->f_flags & O_ACCMODE) == O_RDONLY &&
  1331. (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT ||
  1332. cmd == FE_DISEQC_RECV_SLAVE_REPLY))
  1333. return -EPERM;
  1334. if (down_interruptible (&fepriv->sem))
  1335. return -ERESTARTSYS;
  1336. if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY))
  1337. err = dvb_frontend_ioctl_properties(file, cmd, parg);
  1338. else {
  1339. c->state = DTV_UNDEFINED;
  1340. err = dvb_frontend_ioctl_legacy(file, cmd, parg);
  1341. }
  1342. up(&fepriv->sem);
  1343. return err;
  1344. }
  1345. static int dvb_frontend_ioctl_properties(struct file *file,
  1346. unsigned int cmd, void *parg)
  1347. {
  1348. struct dvb_device *dvbdev = file->private_data;
  1349. struct dvb_frontend *fe = dvbdev->priv;
  1350. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  1351. int err = 0;
  1352. struct dtv_properties *tvps = NULL;
  1353. struct dtv_property *tvp = NULL;
  1354. int i;
  1355. dprintk("%s\n", __func__);
  1356. if(cmd == FE_SET_PROPERTY) {
  1357. tvps = (struct dtv_properties __user *)parg;
  1358. dprintk("%s() properties.num = %d\n", __func__, tvps->num);
  1359. dprintk("%s() properties.props = %p\n", __func__, tvps->props);
  1360. /* Put an arbitrary limit on the number of messages that can
  1361. * be sent at once */
  1362. if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
  1363. return -EINVAL;
  1364. tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL);
  1365. if (!tvp) {
  1366. err = -ENOMEM;
  1367. goto out;
  1368. }
  1369. if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) {
  1370. err = -EFAULT;
  1371. goto out;
  1372. }
  1373. for (i = 0; i < tvps->num; i++) {
  1374. err = dtv_property_process_set(fe, tvp + i, file);
  1375. if (err < 0)
  1376. goto out;
  1377. (tvp + i)->result = err;
  1378. }
  1379. if (c->state == DTV_TUNE)
  1380. dprintk("%s() Property cache is full, tuning\n", __func__);
  1381. } else
  1382. if(cmd == FE_GET_PROPERTY) {
  1383. tvps = (struct dtv_properties __user *)parg;
  1384. dprintk("%s() properties.num = %d\n", __func__, tvps->num);
  1385. dprintk("%s() properties.props = %p\n", __func__, tvps->props);
  1386. /* Put an arbitrary limit on the number of messages that can
  1387. * be sent at once */
  1388. if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
  1389. return -EINVAL;
  1390. tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL);
  1391. if (!tvp) {
  1392. err = -ENOMEM;
  1393. goto out;
  1394. }
  1395. if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) {
  1396. err = -EFAULT;
  1397. goto out;
  1398. }
  1399. for (i = 0; i < tvps->num; i++) {
  1400. err = dtv_property_process_get(fe, tvp + i, file);
  1401. if (err < 0)
  1402. goto out;
  1403. (tvp + i)->result = err;
  1404. }
  1405. if (copy_to_user(tvps->props, tvp, tvps->num * sizeof(struct dtv_property))) {
  1406. err = -EFAULT;
  1407. goto out;
  1408. }
  1409. } else
  1410. err = -EOPNOTSUPP;
  1411. out:
  1412. kfree(tvp);
  1413. return err;
  1414. }
  1415. static int dvb_frontend_ioctl_legacy(struct file *file,
  1416. unsigned int cmd, void *parg)
  1417. {
  1418. struct dvb_device *dvbdev = file->private_data;
  1419. struct dvb_frontend *fe = dvbdev->priv;
  1420. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  1421. int cb_err, err = -EOPNOTSUPP;
  1422. if (fe->dvb->fe_ioctl_override) {
  1423. cb_err = fe->dvb->fe_ioctl_override(fe, cmd, parg,
  1424. DVB_FE_IOCTL_PRE);
  1425. if (cb_err < 0)
  1426. return cb_err;
  1427. if (cb_err > 0)
  1428. return 0;
  1429. /* fe_ioctl_override returning 0 allows
  1430. * dvb-core to continue handling the ioctl */
  1431. }
  1432. switch (cmd) {
  1433. case FE_GET_INFO: {
  1434. struct dvb_frontend_info* info = parg;
  1435. memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info));
  1436. dvb_frontend_get_frequency_limits(fe, &info->frequency_min, &info->frequency_max);
  1437. /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't
  1438. * do it, it is done for it. */
  1439. info->caps |= FE_CAN_INVERSION_AUTO;
  1440. err = 0;
  1441. break;
  1442. }
  1443. case FE_READ_STATUS: {
  1444. fe_status_t* status = parg;
  1445. /* if retune was requested but hasn't occurred yet, prevent
  1446. * that user get signal state from previous tuning */
  1447. if (fepriv->state == FESTATE_RETUNE ||
  1448. fepriv->state == FESTATE_ERROR) {
  1449. err=0;
  1450. *status = 0;
  1451. break;
  1452. }
  1453. if (fe->ops.read_status)
  1454. err = fe->ops.read_status(fe, status);
  1455. break;
  1456. }
  1457. case FE_READ_BER:
  1458. if (fe->ops.read_ber)
  1459. err = fe->ops.read_ber(fe, (__u32*) parg);
  1460. break;
  1461. case FE_READ_SIGNAL_STRENGTH:
  1462. if (fe->ops.read_signal_strength)
  1463. err = fe->ops.read_signal_strength(fe, (__u16*) parg);
  1464. break;
  1465. case FE_READ_SNR:
  1466. if (fe->ops.read_snr)
  1467. err = fe->ops.read_snr(fe, (__u16*) parg);
  1468. break;
  1469. case FE_READ_UNCORRECTED_BLOCKS:
  1470. if (fe->ops.read_ucblocks)
  1471. err = fe->ops.read_ucblocks(fe, (__u32*) parg);
  1472. break;
  1473. case FE_DISEQC_RESET_OVERLOAD:
  1474. if (fe->ops.diseqc_reset_overload) {
  1475. err = fe->ops.diseqc_reset_overload(fe);
  1476. fepriv->state = FESTATE_DISEQC;
  1477. fepriv->status = 0;
  1478. }
  1479. break;
  1480. case FE_DISEQC_SEND_MASTER_CMD:
  1481. if (fe->ops.diseqc_send_master_cmd) {
  1482. err = fe->ops.diseqc_send_master_cmd(fe, (struct dvb_diseqc_master_cmd*) parg);
  1483. fepriv->state = FESTATE_DISEQC;
  1484. fepriv->status = 0;
  1485. }
  1486. break;
  1487. case FE_DISEQC_SEND_BURST:
  1488. if (fe->ops.diseqc_send_burst) {
  1489. err = fe->ops.diseqc_send_burst(fe, (fe_sec_mini_cmd_t) parg);
  1490. fepriv->state = FESTATE_DISEQC;
  1491. fepriv->status = 0;
  1492. }
  1493. break;
  1494. case FE_SET_TONE:
  1495. if (fe->ops.set_tone) {
  1496. err = fe->ops.set_tone(fe, (fe_sec_tone_mode_t) parg);
  1497. fepriv->tone = (fe_sec_tone_mode_t) parg;
  1498. fepriv->state = FESTATE_DISEQC;
  1499. fepriv->status = 0;
  1500. }
  1501. break;
  1502. case FE_SET_VOLTAGE:
  1503. if (fe->ops.set_voltage) {
  1504. err = fe->ops.set_voltage(fe, (fe_sec_voltage_t) parg);
  1505. fepriv->voltage = (fe_sec_voltage_t) parg;
  1506. fepriv->state = FESTATE_DISEQC;
  1507. fepriv->status = 0;
  1508. }
  1509. break;
  1510. case FE_DISHNETWORK_SEND_LEGACY_CMD:
  1511. if (fe->ops.dishnetwork_send_legacy_command) {
  1512. err = fe->ops.dishnetwork_send_legacy_command(fe, (unsigned long) parg);
  1513. fepriv->state = FESTATE_DISEQC;
  1514. fepriv->status = 0;
  1515. } else if (fe->ops.set_voltage) {
  1516. /*
  1517. * NOTE: This is a fallback condition. Some frontends
  1518. * (stv0299 for instance) take longer than 8msec to
  1519. * respond to a set_voltage command. Those switches
  1520. * need custom routines to switch properly. For all
  1521. * other frontends, the following should work ok.
  1522. * Dish network legacy switches (as used by Dish500)
  1523. * are controlled by sending 9-bit command words
  1524. * spaced 8msec apart.
  1525. * the actual command word is switch/port dependent
  1526. * so it is up to the userspace application to send
  1527. * the right command.
  1528. * The command must always start with a '0' after
  1529. * initialization, so parg is 8 bits and does not
  1530. * include the initialization or start bit
  1531. */
  1532. unsigned long swcmd = ((unsigned long) parg) << 1;
  1533. struct timeval nexttime;
  1534. struct timeval tv[10];
  1535. int i;
  1536. u8 last = 1;
  1537. if (dvb_frontend_debug)
  1538. printk("%s switch command: 0x%04lx\n", __func__, swcmd);
  1539. do_gettimeofday(&nexttime);
  1540. if (dvb_frontend_debug)
  1541. memcpy(&tv[0], &nexttime, sizeof(struct timeval));
  1542. /* before sending a command, initialize by sending
  1543. * a 32ms 18V to the switch
  1544. */
  1545. fe->ops.set_voltage(fe, SEC_VOLTAGE_18);
  1546. dvb_frontend_sleep_until(&nexttime, 32000);
  1547. for (i = 0; i < 9; i++) {
  1548. if (dvb_frontend_debug)
  1549. do_gettimeofday(&tv[i + 1]);
  1550. if ((swcmd & 0x01) != last) {
  1551. /* set voltage to (last ? 13V : 18V) */
  1552. fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18);
  1553. last = (last) ? 0 : 1;
  1554. }
  1555. swcmd = swcmd >> 1;
  1556. if (i != 8)
  1557. dvb_frontend_sleep_until(&nexttime, 8000);
  1558. }
  1559. if (dvb_frontend_debug) {
  1560. printk("%s(%d): switch delay (should be 32k followed by all 8k\n",
  1561. __func__, fe->dvb->num);
  1562. for (i = 1; i < 10; i++)
  1563. printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i]));
  1564. }
  1565. err = 0;
  1566. fepriv->state = FESTATE_DISEQC;
  1567. fepriv->status = 0;
  1568. }
  1569. break;
  1570. case FE_DISEQC_RECV_SLAVE_REPLY:
  1571. if (fe->ops.diseqc_recv_slave_reply)
  1572. err = fe->ops.diseqc_recv_slave_reply(fe, (struct dvb_diseqc_slave_reply*) parg);
  1573. break;
  1574. case FE_ENABLE_HIGH_LNB_VOLTAGE:
  1575. if (fe->ops.enable_high_lnb_voltage)
  1576. err = fe->ops.enable_high_lnb_voltage(fe, (long) parg);
  1577. break;
  1578. case FE_SET_FRONTEND: {
  1579. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  1580. struct dvb_frontend_tune_settings fetunesettings;
  1581. if (c->state == DTV_TUNE) {
  1582. if (dvb_frontend_check_parameters(fe, &fepriv->parameters_in) < 0) {
  1583. err = -EINVAL;
  1584. break;
  1585. }
  1586. } else {
  1587. if (dvb_frontend_check_parameters(fe, parg) < 0) {
  1588. err = -EINVAL;
  1589. break;
  1590. }
  1591. memcpy (&fepriv->parameters_in, parg,
  1592. sizeof (struct dvb_frontend_parameters));
  1593. dtv_property_cache_sync(fe, c, &fepriv->parameters_in);
  1594. }
  1595. memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings));
  1596. memcpy(&fetunesettings.parameters, parg,
  1597. sizeof (struct dvb_frontend_parameters));
  1598. /* force auto frequency inversion if requested */
  1599. if (dvb_force_auto_inversion) {
  1600. fepriv->parameters_in.inversion = INVERSION_AUTO;
  1601. fetunesettings.parameters.inversion = INVERSION_AUTO;
  1602. }
  1603. if (fe->ops.info.type == FE_OFDM) {
  1604. /* without hierarchical coding code_rate_LP is irrelevant,
  1605. * so we tolerate the otherwise invalid FEC_NONE setting */
  1606. if (fepriv->parameters_in.u.ofdm.hierarchy_information == HIERARCHY_NONE &&
  1607. fepriv->parameters_in.u.ofdm.code_rate_LP == FEC_NONE)
  1608. fepriv->parameters_in.u.ofdm.code_rate_LP = FEC_AUTO;
  1609. }
  1610. /* get frontend-specific tuning settings */
  1611. if (fe->ops.get_tune_settings && (fe->ops.get_tune_settings(fe, &fetunesettings) == 0)) {
  1612. fepriv->min_delay = (fetunesettings.min_delay_ms * HZ) / 1000;
  1613. fepriv->max_drift = fetunesettings.max_drift;
  1614. fepriv->step_size = fetunesettings.step_size;
  1615. } else {
  1616. /* default values */
  1617. switch(fe->ops.info.type) {
  1618. case FE_QPSK:
  1619. fepriv->min_delay = HZ/20;
  1620. fepriv->step_size = fepriv->parameters_in.u.qpsk.symbol_rate / 16000;
  1621. fepriv->max_drift = fepriv->parameters_in.u.qpsk.symbol_rate / 2000;
  1622. break;
  1623. case FE_QAM:
  1624. fepriv->min_delay = HZ/20;
  1625. fepriv->step_size = 0; /* no zigzag */
  1626. fepriv->max_drift = 0;
  1627. break;
  1628. case FE_OFDM:
  1629. fepriv->min_delay = HZ/20;
  1630. fepriv->step_size = fe->ops.info.frequency_stepsize * 2;
  1631. fepriv->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1;
  1632. break;
  1633. case FE_ATSC:
  1634. fepriv->min_delay = HZ/20;
  1635. fepriv->step_size = 0;
  1636. fepriv->max_drift = 0;
  1637. break;
  1638. }
  1639. }
  1640. if (dvb_override_tune_delay > 0)
  1641. fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000;
  1642. fepriv->state = FESTATE_RETUNE;
  1643. /* Request the search algorithm to search */
  1644. fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
  1645. dvb_frontend_wakeup(fe);
  1646. dvb_frontend_add_event(fe, 0);
  1647. fepriv->status = 0;
  1648. err = 0;
  1649. break;
  1650. }
  1651. case FE_GET_EVENT:
  1652. err = dvb_frontend_get_event (fe, parg, file->f_flags);
  1653. break;
  1654. case FE_GET_FRONTEND:
  1655. if (fe->ops.get_frontend) {
  1656. err = fe->ops.get_frontend(fe, &fepriv->parameters_out);
  1657. memcpy(parg, &fepriv->parameters_out, sizeof(struct dvb_frontend_parameters));
  1658. }
  1659. break;
  1660. case FE_SET_FRONTEND_TUNE_MODE:
  1661. fepriv->tune_mode_flags = (unsigned long) parg;
  1662. err = 0;
  1663. break;
  1664. };
  1665. if (fe->dvb->fe_ioctl_override) {
  1666. cb_err = fe->dvb->fe_ioctl_override(fe, cmd, parg,
  1667. DVB_FE_IOCTL_POST);
  1668. if (cb_err < 0)
  1669. return cb_err;
  1670. }
  1671. return err;
  1672. }
  1673. static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struct *wait)
  1674. {
  1675. struct dvb_device *dvbdev = file->private_data;
  1676. struct dvb_frontend *fe = dvbdev->priv;
  1677. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  1678. dprintk ("%s\n", __func__);
  1679. poll_wait (file, &fepriv->events.wait_queue, wait);
  1680. if (fepriv->events.eventw != fepriv->events.eventr)
  1681. return (POLLIN | POLLRDNORM | POLLPRI);
  1682. return 0;
  1683. }
  1684. static int dvb_frontend_open(struct inode *inode, struct file *file)
  1685. {
  1686. struct dvb_device *dvbdev = file->private_data;
  1687. struct dvb_frontend *fe = dvbdev->priv;
  1688. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  1689. struct dvb_adapter *adapter = fe->dvb;
  1690. int ret;
  1691. dprintk ("%s\n", __func__);
  1692. if (fepriv->exit == DVB_FE_DEVICE_REMOVED)
  1693. return -ENODEV;
  1694. if (adapter->mfe_shared) {
  1695. mutex_lock (&adapter->mfe_lock);
  1696. if (adapter->mfe_dvbdev == NULL)
  1697. adapter->mfe_dvbdev = dvbdev;
  1698. else if (adapter->mfe_dvbdev != dvbdev) {
  1699. struct dvb_device
  1700. *mfedev = adapter->mfe_dvbdev;
  1701. struct dvb_frontend
  1702. *mfe = mfedev->priv;
  1703. struct dvb_frontend_private
  1704. *mfepriv = mfe->frontend_priv;
  1705. int mferetry = (dvb_mfe_wait_time << 1);
  1706. mutex_unlock (&adapter->mfe_lock);
  1707. while (mferetry-- && (mfedev->users != -1 ||
  1708. mfepriv->thread != NULL)) {
  1709. if(msleep_interruptible(500)) {
  1710. if(signal_pending(current))
  1711. return -EINTR;
  1712. }
  1713. }
  1714. mutex_lock (&adapter->mfe_lock);
  1715. if(adapter->mfe_dvbdev != dvbdev) {
  1716. mfedev = adapter->mfe_dvbdev;
  1717. mfe = mfedev->priv;
  1718. mfepriv = mfe->frontend_priv;
  1719. if (mfedev->users != -1 ||
  1720. mfepriv->thread != NULL) {
  1721. mutex_unlock (&adapter->mfe_lock);
  1722. return -EBUSY;
  1723. }
  1724. adapter->mfe_dvbdev = dvbdev;
  1725. }
  1726. }
  1727. }
  1728. if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) {
  1729. if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0)
  1730. goto err0;
  1731. /* If we took control of the bus, we need to force
  1732. reinitialization. This is because many ts_bus_ctrl()
  1733. functions strobe the RESET pin on the demod, and if the
  1734. frontend thread already exists then the dvb_init() routine
  1735. won't get called (which is what usually does initial
  1736. register configuration). */
  1737. fepriv->reinitialise = 1;
  1738. }
  1739. if ((ret = dvb_generic_open (inode, file)) < 0)
  1740. goto err1;
  1741. if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
  1742. /* normal tune mode when opened R/W */
  1743. fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT;
  1744. fepriv->tone = -1;
  1745. fepriv->voltage = -1;
  1746. ret = dvb_frontend_start (fe);
  1747. if (ret)
  1748. goto err2;
  1749. /* empty event queue */
  1750. fepriv->events.eventr = fepriv->events.eventw = 0;
  1751. }
  1752. if (adapter->mfe_shared)
  1753. mutex_unlock (&adapter->mfe_lock);
  1754. return ret;
  1755. err2:
  1756. dvb_generic_release(inode, file);
  1757. err1:
  1758. if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl)
  1759. fe->ops.ts_bus_ctrl(fe, 0);
  1760. err0:
  1761. if (adapter->mfe_shared)
  1762. mutex_unlock (&adapter->mfe_lock);
  1763. return ret;
  1764. }
  1765. static int dvb_frontend_release(struct inode *inode, struct file *file)
  1766. {
  1767. struct dvb_device *dvbdev = file->private_data;
  1768. struct dvb_frontend *fe = dvbdev->priv;
  1769. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  1770. int ret;
  1771. dprintk ("%s\n", __func__);
  1772. if ((file->f_flags & O_ACCMODE) != O_RDONLY)
  1773. fepriv->release_jiffies = jiffies;
  1774. ret = dvb_generic_release (inode, file);
  1775. if (dvbdev->users == -1) {
  1776. if (fepriv->exit != DVB_FE_NO_EXIT) {
  1777. fops_put(file->f_op);
  1778. file->f_op = NULL;
  1779. wake_up(&dvbdev->wait_queue);
  1780. }
  1781. if (fe->ops.ts_bus_ctrl)
  1782. fe->ops.ts_bus_ctrl(fe, 0);
  1783. }
  1784. return ret;
  1785. }
  1786. static const struct file_operations dvb_frontend_fops = {
  1787. .owner = THIS_MODULE,
  1788. .unlocked_ioctl = dvb_generic_ioctl,
  1789. .poll = dvb_frontend_poll,
  1790. .open = dvb_frontend_open,
  1791. .release = dvb_frontend_release,
  1792. .llseek = noop_llseek,
  1793. };
  1794. int dvb_register_frontend(struct dvb_adapter* dvb,
  1795. struct dvb_frontend* fe)
  1796. {
  1797. struct dvb_frontend_private *fepriv;
  1798. static const struct dvb_device dvbdev_template = {
  1799. .users = ~0,
  1800. .writers = 1,
  1801. .readers = (~0)-1,
  1802. .fops = &dvb_frontend_fops,
  1803. .kernel_ioctl = dvb_frontend_ioctl
  1804. };
  1805. dprintk ("%s\n", __func__);
  1806. if (mutex_lock_interruptible(&frontend_mutex))
  1807. return -ERESTARTSYS;
  1808. fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL);
  1809. if (fe->frontend_priv == NULL) {
  1810. mutex_unlock(&frontend_mutex);
  1811. return -ENOMEM;
  1812. }
  1813. fepriv = fe->frontend_priv;
  1814. sema_init(&fepriv->sem, 1);
  1815. init_waitqueue_head (&fepriv->wait_queue);
  1816. init_waitqueue_head (&fepriv->events.wait_queue);
  1817. mutex_init(&fepriv->events.mtx);
  1818. fe->dvb = dvb;
  1819. fepriv->inversion = INVERSION_OFF;
  1820. printk ("DVB: registering adapter %i frontend %i (%s)...\n",
  1821. fe->dvb->num,
  1822. fe->id,
  1823. fe->ops.info.name);
  1824. dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template,
  1825. fe, DVB_DEVICE_FRONTEND);
  1826. mutex_unlock(&frontend_mutex);
  1827. return 0;
  1828. }
  1829. EXPORT_SYMBOL(dvb_register_frontend);
  1830. int dvb_unregister_frontend(struct dvb_frontend* fe)
  1831. {
  1832. struct dvb_frontend_private *fepriv = fe->frontend_priv;
  1833. dprintk ("%s\n", __func__);
  1834. mutex_lock(&frontend_mutex);
  1835. dvb_frontend_stop (fe);
  1836. mutex_unlock(&frontend_mutex);
  1837. if (fepriv->dvbdev->users < -1)
  1838. wait_event(fepriv->dvbdev->wait_queue,
  1839. fepriv->dvbdev->users==-1);
  1840. mutex_lock(&frontend_mutex);
  1841. dvb_unregister_device (fepriv->dvbdev);
  1842. /* fe is invalid now */
  1843. kfree(fepriv);
  1844. mutex_unlock(&frontend_mutex);
  1845. return 0;
  1846. }
  1847. EXPORT_SYMBOL(dvb_unregister_frontend);
  1848. #ifdef CONFIG_MEDIA_ATTACH
  1849. void dvb_frontend_detach(struct dvb_frontend* fe)
  1850. {
  1851. void *ptr;
  1852. if (fe->ops.release_sec) {
  1853. fe->ops.release_sec(fe);
  1854. symbol_put_addr(fe->ops.release_sec);
  1855. }
  1856. if (fe->ops.tuner_ops.release) {
  1857. fe->ops.tuner_ops.release(fe);
  1858. symbol_put_addr(fe->ops.tuner_ops.release);
  1859. }
  1860. if (fe->ops.analog_ops.release) {
  1861. fe->ops.analog_ops.release(fe);
  1862. symbol_put_addr(fe->ops.analog_ops.release);
  1863. }
  1864. ptr = (void*)fe->ops.release;
  1865. if (ptr) {
  1866. fe->ops.release(fe);
  1867. symbol_put_addr(ptr);
  1868. }
  1869. }
  1870. #else
  1871. void dvb_frontend_detach(struct dvb_frontend* fe)
  1872. {
  1873. if (fe->ops.release_sec)
  1874. fe->ops.release_sec(fe);
  1875. if (fe->ops.tuner_ops.release)
  1876. fe->ops.tuner_ops.release(fe);
  1877. if (fe->ops.analog_ops.release)
  1878. fe->ops.analog_ops.release(fe);
  1879. if (fe->ops.release)
  1880. fe->ops.release(fe);
  1881. }
  1882. #endif
  1883. EXPORT_SYMBOL(dvb_frontend_detach);