tuner-xc2028.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. /* tuner-xc2028
  2. *
  3. * Copyright (c) 2007-2008 Mauro Carvalho Chehab (mchehab@infradead.org)
  4. *
  5. * Copyright (c) 2007 Michel Ludwig (michel.ludwig@gmail.com)
  6. * - frontend interface
  7. *
  8. * This code is placed under the terms of the GNU General Public License v2
  9. */
  10. #include <linux/i2c.h>
  11. #include <asm/div64.h>
  12. #include <linux/firmware.h>
  13. #include <linux/videodev2.h>
  14. #include <linux/delay.h>
  15. #include <media/tuner.h>
  16. #include <linux/mutex.h>
  17. #include <linux/slab.h>
  18. #include <asm/unaligned.h>
  19. #include "tuner-i2c.h"
  20. #include "tuner-xc2028.h"
  21. #include "tuner-xc2028-types.h"
  22. #include <linux/dvb/frontend.h>
  23. #include "dvb_frontend.h"
  24. static int debug;
  25. module_param(debug, int, 0644);
  26. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  27. static int no_poweroff;
  28. module_param(no_poweroff, int, 0644);
  29. MODULE_PARM_DESC(no_poweroff, "0 (default) powers device off when not used.\n"
  30. "1 keep device energized and with tuner ready all the times.\n"
  31. " Faster, but consumes more power and keeps the device hotter\n");
  32. static char audio_std[8];
  33. module_param_string(audio_std, audio_std, sizeof(audio_std), 0);
  34. MODULE_PARM_DESC(audio_std,
  35. "Audio standard. XC3028 audio decoder explicitly "
  36. "needs to know what audio\n"
  37. "standard is needed for some video standards with audio A2 or NICAM.\n"
  38. "The valid values are:\n"
  39. "A2\n"
  40. "A2/A\n"
  41. "A2/B\n"
  42. "NICAM\n"
  43. "NICAM/A\n"
  44. "NICAM/B\n");
  45. static char firmware_name[30];
  46. module_param_string(firmware_name, firmware_name, sizeof(firmware_name), 0);
  47. MODULE_PARM_DESC(firmware_name, "Firmware file name. Allows overriding the "
  48. "default firmware name\n");
  49. static LIST_HEAD(hybrid_tuner_instance_list);
  50. static DEFINE_MUTEX(xc2028_list_mutex);
  51. /* struct for storing firmware table */
  52. struct firmware_description {
  53. unsigned int type;
  54. v4l2_std_id id;
  55. __u16 int_freq;
  56. unsigned char *ptr;
  57. unsigned int size;
  58. };
  59. struct firmware_properties {
  60. unsigned int type;
  61. v4l2_std_id id;
  62. v4l2_std_id std_req;
  63. __u16 int_freq;
  64. unsigned int scode_table;
  65. int scode_nr;
  66. };
  67. struct xc2028_data {
  68. struct list_head hybrid_tuner_instance_list;
  69. struct tuner_i2c_props i2c_props;
  70. __u32 frequency;
  71. struct firmware_description *firm;
  72. int firm_size;
  73. __u16 firm_version;
  74. __u16 hwmodel;
  75. __u16 hwvers;
  76. struct xc2028_ctrl ctrl;
  77. struct firmware_properties cur_fw;
  78. struct mutex lock;
  79. };
  80. #define i2c_send(priv, buf, size) ({ \
  81. int _rc; \
  82. _rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \
  83. if (size != _rc) \
  84. tuner_info("i2c output error: rc = %d (should be %d)\n",\
  85. _rc, (int)size); \
  86. if (priv->ctrl.msleep) \
  87. msleep(priv->ctrl.msleep); \
  88. _rc; \
  89. })
  90. #define i2c_rcv(priv, buf, size) ({ \
  91. int _rc; \
  92. _rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \
  93. if (size != _rc) \
  94. tuner_err("i2c input error: rc = %d (should be %d)\n", \
  95. _rc, (int)size); \
  96. _rc; \
  97. })
  98. #define i2c_send_recv(priv, obuf, osize, ibuf, isize) ({ \
  99. int _rc; \
  100. _rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, obuf, osize, \
  101. ibuf, isize); \
  102. if (isize != _rc) \
  103. tuner_err("i2c input error: rc = %d (should be %d)\n", \
  104. _rc, (int)isize); \
  105. if (priv->ctrl.msleep) \
  106. msleep(priv->ctrl.msleep); \
  107. _rc; \
  108. })
  109. #define send_seq(priv, data...) ({ \
  110. static u8 _val[] = data; \
  111. int _rc; \
  112. if (sizeof(_val) != \
  113. (_rc = tuner_i2c_xfer_send(&priv->i2c_props, \
  114. _val, sizeof(_val)))) { \
  115. tuner_err("Error on line %d: %d\n", __LINE__, _rc); \
  116. } else if (priv->ctrl.msleep) \
  117. msleep(priv->ctrl.msleep); \
  118. _rc; \
  119. })
  120. static int xc2028_get_reg(struct xc2028_data *priv, u16 reg, u16 *val)
  121. {
  122. unsigned char buf[2];
  123. unsigned char ibuf[2];
  124. tuner_dbg("%s %04x called\n", __func__, reg);
  125. buf[0] = reg >> 8;
  126. buf[1] = (unsigned char) reg;
  127. if (i2c_send_recv(priv, buf, 2, ibuf, 2) != 2)
  128. return -EIO;
  129. *val = (ibuf[1]) | (ibuf[0] << 8);
  130. return 0;
  131. }
  132. #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0)
  133. static void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq)
  134. {
  135. if (type & BASE)
  136. printk("BASE ");
  137. if (type & INIT1)
  138. printk("INIT1 ");
  139. if (type & F8MHZ)
  140. printk("F8MHZ ");
  141. if (type & MTS)
  142. printk("MTS ");
  143. if (type & D2620)
  144. printk("D2620 ");
  145. if (type & D2633)
  146. printk("D2633 ");
  147. if (type & DTV6)
  148. printk("DTV6 ");
  149. if (type & QAM)
  150. printk("QAM ");
  151. if (type & DTV7)
  152. printk("DTV7 ");
  153. if (type & DTV78)
  154. printk("DTV78 ");
  155. if (type & DTV8)
  156. printk("DTV8 ");
  157. if (type & FM)
  158. printk("FM ");
  159. if (type & INPUT1)
  160. printk("INPUT1 ");
  161. if (type & LCD)
  162. printk("LCD ");
  163. if (type & NOGD)
  164. printk("NOGD ");
  165. if (type & MONO)
  166. printk("MONO ");
  167. if (type & ATSC)
  168. printk("ATSC ");
  169. if (type & IF)
  170. printk("IF ");
  171. if (type & LG60)
  172. printk("LG60 ");
  173. if (type & ATI638)
  174. printk("ATI638 ");
  175. if (type & OREN538)
  176. printk("OREN538 ");
  177. if (type & OREN36)
  178. printk("OREN36 ");
  179. if (type & TOYOTA388)
  180. printk("TOYOTA388 ");
  181. if (type & TOYOTA794)
  182. printk("TOYOTA794 ");
  183. if (type & DIBCOM52)
  184. printk("DIBCOM52 ");
  185. if (type & ZARLINK456)
  186. printk("ZARLINK456 ");
  187. if (type & CHINA)
  188. printk("CHINA ");
  189. if (type & F6MHZ)
  190. printk("F6MHZ ");
  191. if (type & INPUT2)
  192. printk("INPUT2 ");
  193. if (type & SCODE)
  194. printk("SCODE ");
  195. if (type & HAS_IF)
  196. printk("HAS_IF_%d ", int_freq);
  197. }
  198. static v4l2_std_id parse_audio_std_option(void)
  199. {
  200. if (strcasecmp(audio_std, "A2") == 0)
  201. return V4L2_STD_A2;
  202. if (strcasecmp(audio_std, "A2/A") == 0)
  203. return V4L2_STD_A2_A;
  204. if (strcasecmp(audio_std, "A2/B") == 0)
  205. return V4L2_STD_A2_B;
  206. if (strcasecmp(audio_std, "NICAM") == 0)
  207. return V4L2_STD_NICAM;
  208. if (strcasecmp(audio_std, "NICAM/A") == 0)
  209. return V4L2_STD_NICAM_A;
  210. if (strcasecmp(audio_std, "NICAM/B") == 0)
  211. return V4L2_STD_NICAM_B;
  212. return 0;
  213. }
  214. static void free_firmware(struct xc2028_data *priv)
  215. {
  216. int i;
  217. tuner_dbg("%s called\n", __func__);
  218. if (!priv->firm)
  219. return;
  220. for (i = 0; i < priv->firm_size; i++)
  221. kfree(priv->firm[i].ptr);
  222. kfree(priv->firm);
  223. priv->firm = NULL;
  224. priv->firm_size = 0;
  225. memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
  226. }
  227. static int load_all_firmwares(struct dvb_frontend *fe)
  228. {
  229. struct xc2028_data *priv = fe->tuner_priv;
  230. const struct firmware *fw = NULL;
  231. const unsigned char *p, *endp;
  232. int rc = 0;
  233. int n, n_array;
  234. char name[33];
  235. char *fname;
  236. tuner_dbg("%s called\n", __func__);
  237. if (!firmware_name[0])
  238. fname = priv->ctrl.fname;
  239. else
  240. fname = firmware_name;
  241. tuner_dbg("Reading firmware %s\n", fname);
  242. rc = request_firmware(&fw, fname, priv->i2c_props.adap->dev.parent);
  243. if (rc < 0) {
  244. if (rc == -ENOENT)
  245. tuner_err("Error: firmware %s not found.\n",
  246. fname);
  247. else
  248. tuner_err("Error %d while requesting firmware %s \n",
  249. rc, fname);
  250. return rc;
  251. }
  252. p = fw->data;
  253. endp = p + fw->size;
  254. if (fw->size < sizeof(name) - 1 + 2 + 2) {
  255. tuner_err("Error: firmware file %s has invalid size!\n",
  256. fname);
  257. goto corrupt;
  258. }
  259. memcpy(name, p, sizeof(name) - 1);
  260. name[sizeof(name) - 1] = 0;
  261. p += sizeof(name) - 1;
  262. priv->firm_version = get_unaligned_le16(p);
  263. p += 2;
  264. n_array = get_unaligned_le16(p);
  265. p += 2;
  266. tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
  267. n_array, fname, name,
  268. priv->firm_version >> 8, priv->firm_version & 0xff);
  269. priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL);
  270. if (priv->firm == NULL) {
  271. tuner_err("Not enough memory to load firmware file.\n");
  272. rc = -ENOMEM;
  273. goto err;
  274. }
  275. priv->firm_size = n_array;
  276. n = -1;
  277. while (p < endp) {
  278. __u32 type, size;
  279. v4l2_std_id id;
  280. __u16 int_freq = 0;
  281. n++;
  282. if (n >= n_array) {
  283. tuner_err("More firmware images in file than "
  284. "were expected!\n");
  285. goto corrupt;
  286. }
  287. /* Checks if there's enough bytes to read */
  288. if (endp - p < sizeof(type) + sizeof(id) + sizeof(size))
  289. goto header;
  290. type = get_unaligned_le32(p);
  291. p += sizeof(type);
  292. id = get_unaligned_le64(p);
  293. p += sizeof(id);
  294. if (type & HAS_IF) {
  295. int_freq = get_unaligned_le16(p);
  296. p += sizeof(int_freq);
  297. if (endp - p < sizeof(size))
  298. goto header;
  299. }
  300. size = get_unaligned_le32(p);
  301. p += sizeof(size);
  302. if (!size || size > endp - p) {
  303. tuner_err("Firmware type ");
  304. dump_firm_type(type);
  305. printk("(%x), id %llx is corrupted "
  306. "(size=%d, expected %d)\n",
  307. type, (unsigned long long)id,
  308. (unsigned)(endp - p), size);
  309. goto corrupt;
  310. }
  311. priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
  312. if (priv->firm[n].ptr == NULL) {
  313. tuner_err("Not enough memory to load firmware file.\n");
  314. rc = -ENOMEM;
  315. goto err;
  316. }
  317. tuner_dbg("Reading firmware type ");
  318. if (debug) {
  319. dump_firm_type_and_int_freq(type, int_freq);
  320. printk("(%x), id %llx, size=%d.\n",
  321. type, (unsigned long long)id, size);
  322. }
  323. memcpy(priv->firm[n].ptr, p, size);
  324. priv->firm[n].type = type;
  325. priv->firm[n].id = id;
  326. priv->firm[n].size = size;
  327. priv->firm[n].int_freq = int_freq;
  328. p += size;
  329. }
  330. if (n + 1 != priv->firm_size) {
  331. tuner_err("Firmware file is incomplete!\n");
  332. goto corrupt;
  333. }
  334. goto done;
  335. header:
  336. tuner_err("Firmware header is incomplete!\n");
  337. corrupt:
  338. rc = -EINVAL;
  339. tuner_err("Error: firmware file is corrupted!\n");
  340. err:
  341. tuner_info("Releasing partially loaded firmware file.\n");
  342. free_firmware(priv);
  343. done:
  344. release_firmware(fw);
  345. if (rc == 0)
  346. tuner_dbg("Firmware files loaded.\n");
  347. return rc;
  348. }
  349. static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
  350. v4l2_std_id *id)
  351. {
  352. struct xc2028_data *priv = fe->tuner_priv;
  353. int i, best_i = -1, best_nr_matches = 0;
  354. unsigned int type_mask = 0;
  355. tuner_dbg("%s called, want type=", __func__);
  356. if (debug) {
  357. dump_firm_type(type);
  358. printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
  359. }
  360. if (!priv->firm) {
  361. tuner_err("Error! firmware not loaded\n");
  362. return -EINVAL;
  363. }
  364. if (((type & ~SCODE) == 0) && (*id == 0))
  365. *id = V4L2_STD_PAL;
  366. if (type & BASE)
  367. type_mask = BASE_TYPES;
  368. else if (type & SCODE) {
  369. type &= SCODE_TYPES;
  370. type_mask = SCODE_TYPES & ~HAS_IF;
  371. } else if (type & DTV_TYPES)
  372. type_mask = DTV_TYPES;
  373. else if (type & STD_SPECIFIC_TYPES)
  374. type_mask = STD_SPECIFIC_TYPES;
  375. type &= type_mask;
  376. if (!(type & SCODE))
  377. type_mask = ~0;
  378. /* Seek for exact match */
  379. for (i = 0; i < priv->firm_size; i++) {
  380. if ((type == (priv->firm[i].type & type_mask)) &&
  381. (*id == priv->firm[i].id))
  382. goto found;
  383. }
  384. /* Seek for generic video standard match */
  385. for (i = 0; i < priv->firm_size; i++) {
  386. v4l2_std_id match_mask;
  387. int nr_matches;
  388. if (type != (priv->firm[i].type & type_mask))
  389. continue;
  390. match_mask = *id & priv->firm[i].id;
  391. if (!match_mask)
  392. continue;
  393. if ((*id & match_mask) == *id)
  394. goto found; /* Supports all the requested standards */
  395. nr_matches = hweight64(match_mask);
  396. if (nr_matches > best_nr_matches) {
  397. best_nr_matches = nr_matches;
  398. best_i = i;
  399. }
  400. }
  401. if (best_nr_matches > 0) {
  402. tuner_dbg("Selecting best matching firmware (%d bits) for "
  403. "type=", best_nr_matches);
  404. dump_firm_type(type);
  405. printk("(%x), id %016llx:\n", type, (unsigned long long)*id);
  406. i = best_i;
  407. goto found;
  408. }
  409. /*FIXME: Would make sense to seek for type "hint" match ? */
  410. i = -ENOENT;
  411. goto ret;
  412. found:
  413. *id = priv->firm[i].id;
  414. ret:
  415. tuner_dbg("%s firmware for type=", (i < 0) ? "Can't find" : "Found");
  416. if (debug) {
  417. dump_firm_type(type);
  418. printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
  419. }
  420. return i;
  421. }
  422. static inline int do_tuner_callback(struct dvb_frontend *fe, int cmd, int arg)
  423. {
  424. struct xc2028_data *priv = fe->tuner_priv;
  425. /* analog side (tuner-core) uses i2c_adap->algo_data.
  426. * digital side is not guaranteed to have algo_data defined.
  427. *
  428. * digital side will always have fe->dvb defined.
  429. * analog side (tuner-core) doesn't (yet) define fe->dvb.
  430. */
  431. return (!fe->callback) ? -EINVAL :
  432. fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
  433. fe->dvb->priv : priv->i2c_props.adap->algo_data,
  434. DVB_FRONTEND_COMPONENT_TUNER, cmd, arg);
  435. }
  436. static int load_firmware(struct dvb_frontend *fe, unsigned int type,
  437. v4l2_std_id *id)
  438. {
  439. struct xc2028_data *priv = fe->tuner_priv;
  440. int pos, rc;
  441. unsigned char *p, *endp, buf[priv->ctrl.max_len];
  442. tuner_dbg("%s called\n", __func__);
  443. pos = seek_firmware(fe, type, id);
  444. if (pos < 0)
  445. return pos;
  446. tuner_info("Loading firmware for type=");
  447. dump_firm_type(priv->firm[pos].type);
  448. printk("(%x), id %016llx.\n", priv->firm[pos].type,
  449. (unsigned long long)*id);
  450. p = priv->firm[pos].ptr;
  451. endp = p + priv->firm[pos].size;
  452. while (p < endp) {
  453. __u16 size;
  454. /* Checks if there's enough bytes to read */
  455. if (p + sizeof(size) > endp) {
  456. tuner_err("Firmware chunk size is wrong\n");
  457. return -EINVAL;
  458. }
  459. size = le16_to_cpu(*(__u16 *) p);
  460. p += sizeof(size);
  461. if (size == 0xffff)
  462. return 0;
  463. if (!size) {
  464. /* Special callback command received */
  465. rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
  466. if (rc < 0) {
  467. tuner_err("Error at RESET code %d\n",
  468. (*p) & 0x7f);
  469. return -EINVAL;
  470. }
  471. continue;
  472. }
  473. if (size >= 0xff00) {
  474. switch (size) {
  475. case 0xff00:
  476. rc = do_tuner_callback(fe, XC2028_RESET_CLK, 0);
  477. if (rc < 0) {
  478. tuner_err("Error at RESET code %d\n",
  479. (*p) & 0x7f);
  480. return -EINVAL;
  481. }
  482. break;
  483. default:
  484. tuner_info("Invalid RESET code %d\n",
  485. size & 0x7f);
  486. return -EINVAL;
  487. }
  488. continue;
  489. }
  490. /* Checks for a sleep command */
  491. if (size & 0x8000) {
  492. msleep(size & 0x7fff);
  493. continue;
  494. }
  495. if ((size + p > endp)) {
  496. tuner_err("missing bytes: need %d, have %d\n",
  497. size, (int)(endp - p));
  498. return -EINVAL;
  499. }
  500. buf[0] = *p;
  501. p++;
  502. size--;
  503. /* Sends message chunks */
  504. while (size > 0) {
  505. int len = (size < priv->ctrl.max_len - 1) ?
  506. size : priv->ctrl.max_len - 1;
  507. memcpy(buf + 1, p, len);
  508. rc = i2c_send(priv, buf, len + 1);
  509. if (rc < 0) {
  510. tuner_err("%d returned from send\n", rc);
  511. return -EINVAL;
  512. }
  513. p += len;
  514. size -= len;
  515. }
  516. /* silently fail if the frontend doesn't support I2C flush */
  517. rc = do_tuner_callback(fe, XC2028_I2C_FLUSH, 0);
  518. if ((rc < 0) && (rc != -EINVAL)) {
  519. tuner_err("error executing flush: %d\n", rc);
  520. return rc;
  521. }
  522. }
  523. return 0;
  524. }
  525. static int load_scode(struct dvb_frontend *fe, unsigned int type,
  526. v4l2_std_id *id, __u16 int_freq, int scode)
  527. {
  528. struct xc2028_data *priv = fe->tuner_priv;
  529. int pos, rc;
  530. unsigned char *p;
  531. tuner_dbg("%s called\n", __func__);
  532. if (!int_freq) {
  533. pos = seek_firmware(fe, type, id);
  534. if (pos < 0)
  535. return pos;
  536. } else {
  537. for (pos = 0; pos < priv->firm_size; pos++) {
  538. if ((priv->firm[pos].int_freq == int_freq) &&
  539. (priv->firm[pos].type & HAS_IF))
  540. break;
  541. }
  542. if (pos == priv->firm_size)
  543. return -ENOENT;
  544. }
  545. p = priv->firm[pos].ptr;
  546. if (priv->firm[pos].type & HAS_IF) {
  547. if (priv->firm[pos].size != 12 * 16 || scode >= 16)
  548. return -EINVAL;
  549. p += 12 * scode;
  550. } else {
  551. /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
  552. * has a 2-byte size header in the firmware format. */
  553. if (priv->firm[pos].size != 14 * 16 || scode >= 16 ||
  554. le16_to_cpu(*(__u16 *)(p + 14 * scode)) != 12)
  555. return -EINVAL;
  556. p += 14 * scode + 2;
  557. }
  558. tuner_info("Loading SCODE for type=");
  559. dump_firm_type_and_int_freq(priv->firm[pos].type,
  560. priv->firm[pos].int_freq);
  561. printk("(%x), id %016llx.\n", priv->firm[pos].type,
  562. (unsigned long long)*id);
  563. if (priv->firm_version < 0x0202)
  564. rc = send_seq(priv, {0x20, 0x00, 0x00, 0x00});
  565. else
  566. rc = send_seq(priv, {0xa0, 0x00, 0x00, 0x00});
  567. if (rc < 0)
  568. return -EIO;
  569. rc = i2c_send(priv, p, 12);
  570. if (rc < 0)
  571. return -EIO;
  572. rc = send_seq(priv, {0x00, 0x8c});
  573. if (rc < 0)
  574. return -EIO;
  575. return 0;
  576. }
  577. static int check_firmware(struct dvb_frontend *fe, unsigned int type,
  578. v4l2_std_id std, __u16 int_freq)
  579. {
  580. struct xc2028_data *priv = fe->tuner_priv;
  581. struct firmware_properties new_fw;
  582. int rc = 0, retry_count = 0;
  583. u16 version, hwmodel;
  584. v4l2_std_id std0;
  585. tuner_dbg("%s called\n", __func__);
  586. if (!priv->firm) {
  587. if (!priv->ctrl.fname) {
  588. tuner_info("xc2028/3028 firmware name not set!\n");
  589. return -EINVAL;
  590. }
  591. rc = load_all_firmwares(fe);
  592. if (rc < 0)
  593. return rc;
  594. }
  595. if (priv->ctrl.mts && !(type & FM))
  596. type |= MTS;
  597. retry:
  598. new_fw.type = type;
  599. new_fw.id = std;
  600. new_fw.std_req = std;
  601. new_fw.scode_table = SCODE | priv->ctrl.scode_table;
  602. new_fw.scode_nr = 0;
  603. new_fw.int_freq = int_freq;
  604. tuner_dbg("checking firmware, user requested type=");
  605. if (debug) {
  606. dump_firm_type(new_fw.type);
  607. printk("(%x), id %016llx, ", new_fw.type,
  608. (unsigned long long)new_fw.std_req);
  609. if (!int_freq) {
  610. printk("scode_tbl ");
  611. dump_firm_type(priv->ctrl.scode_table);
  612. printk("(%x), ", priv->ctrl.scode_table);
  613. } else
  614. printk("int_freq %d, ", new_fw.int_freq);
  615. printk("scode_nr %d\n", new_fw.scode_nr);
  616. }
  617. /* No need to reload base firmware if it matches */
  618. if (((BASE | new_fw.type) & BASE_TYPES) ==
  619. (priv->cur_fw.type & BASE_TYPES)) {
  620. tuner_dbg("BASE firmware not changed.\n");
  621. goto skip_base;
  622. }
  623. /* Updating BASE - forget about all currently loaded firmware */
  624. memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
  625. /* Reset is needed before loading firmware */
  626. rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
  627. if (rc < 0)
  628. goto fail;
  629. /* BASE firmwares are all std0 */
  630. std0 = 0;
  631. rc = load_firmware(fe, BASE | new_fw.type, &std0);
  632. if (rc < 0) {
  633. tuner_err("Error %d while loading base firmware\n",
  634. rc);
  635. goto fail;
  636. }
  637. /* Load INIT1, if needed */
  638. tuner_dbg("Load init1 firmware, if exists\n");
  639. rc = load_firmware(fe, BASE | INIT1 | new_fw.type, &std0);
  640. if (rc == -ENOENT)
  641. rc = load_firmware(fe, (BASE | INIT1 | new_fw.type) & ~F8MHZ,
  642. &std0);
  643. if (rc < 0 && rc != -ENOENT) {
  644. tuner_err("Error %d while loading init1 firmware\n",
  645. rc);
  646. goto fail;
  647. }
  648. skip_base:
  649. /*
  650. * No need to reload standard specific firmware if base firmware
  651. * was not reloaded and requested video standards have not changed.
  652. */
  653. if (priv->cur_fw.type == (BASE | new_fw.type) &&
  654. priv->cur_fw.std_req == std) {
  655. tuner_dbg("Std-specific firmware already loaded.\n");
  656. goto skip_std_specific;
  657. }
  658. /* Reloading std-specific firmware forces a SCODE update */
  659. priv->cur_fw.scode_table = 0;
  660. rc = load_firmware(fe, new_fw.type, &new_fw.id);
  661. if (rc == -ENOENT)
  662. rc = load_firmware(fe, new_fw.type & ~F8MHZ, &new_fw.id);
  663. if (rc < 0)
  664. goto fail;
  665. skip_std_specific:
  666. if (priv->cur_fw.scode_table == new_fw.scode_table &&
  667. priv->cur_fw.scode_nr == new_fw.scode_nr) {
  668. tuner_dbg("SCODE firmware already loaded.\n");
  669. goto check_device;
  670. }
  671. if (new_fw.type & FM)
  672. goto check_device;
  673. /* Load SCODE firmware, if exists */
  674. tuner_dbg("Trying to load scode %d\n", new_fw.scode_nr);
  675. rc = load_scode(fe, new_fw.type | new_fw.scode_table, &new_fw.id,
  676. new_fw.int_freq, new_fw.scode_nr);
  677. check_device:
  678. if (xc2028_get_reg(priv, 0x0004, &version) < 0 ||
  679. xc2028_get_reg(priv, 0x0008, &hwmodel) < 0) {
  680. tuner_err("Unable to read tuner registers.\n");
  681. goto fail;
  682. }
  683. tuner_dbg("Device is Xceive %d version %d.%d, "
  684. "firmware version %d.%d\n",
  685. hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8,
  686. (version & 0xf0) >> 4, version & 0xf);
  687. if (priv->ctrl.read_not_reliable)
  688. goto read_not_reliable;
  689. /* Check firmware version against what we downloaded. */
  690. if (priv->firm_version != ((version & 0xf0) << 4 | (version & 0x0f))) {
  691. if (!priv->ctrl.read_not_reliable) {
  692. tuner_err("Incorrect readback of firmware version.\n");
  693. goto fail;
  694. } else {
  695. tuner_err("Returned an incorrect version. However, "
  696. "read is not reliable enough. Ignoring it.\n");
  697. hwmodel = 3028;
  698. }
  699. }
  700. /* Check that the tuner hardware model remains consistent over time. */
  701. if (priv->hwmodel == 0 && (hwmodel == 2028 || hwmodel == 3028)) {
  702. priv->hwmodel = hwmodel;
  703. priv->hwvers = version & 0xff00;
  704. } else if (priv->hwmodel == 0 || priv->hwmodel != hwmodel ||
  705. priv->hwvers != (version & 0xff00)) {
  706. tuner_err("Read invalid device hardware information - tuner "
  707. "hung?\n");
  708. goto fail;
  709. }
  710. read_not_reliable:
  711. memcpy(&priv->cur_fw, &new_fw, sizeof(priv->cur_fw));
  712. /*
  713. * By setting BASE in cur_fw.type only after successfully loading all
  714. * firmwares, we can:
  715. * 1. Identify that BASE firmware with type=0 has been loaded;
  716. * 2. Tell whether BASE firmware was just changed the next time through.
  717. */
  718. priv->cur_fw.type |= BASE;
  719. return 0;
  720. fail:
  721. memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
  722. if (retry_count < 8) {
  723. msleep(50);
  724. retry_count++;
  725. tuner_dbg("Retrying firmware load\n");
  726. goto retry;
  727. }
  728. if (rc == -ENOENT)
  729. rc = -EINVAL;
  730. return rc;
  731. }
  732. static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
  733. {
  734. struct xc2028_data *priv = fe->tuner_priv;
  735. u16 frq_lock, signal = 0;
  736. int rc;
  737. tuner_dbg("%s called\n", __func__);
  738. mutex_lock(&priv->lock);
  739. /* Sync Lock Indicator */
  740. rc = xc2028_get_reg(priv, 0x0002, &frq_lock);
  741. if (rc < 0)
  742. goto ret;
  743. /* Frequency is locked */
  744. if (frq_lock == 1)
  745. signal = 32768;
  746. /* Get SNR of the video signal */
  747. rc = xc2028_get_reg(priv, 0x0040, &signal);
  748. if (rc < 0)
  749. goto ret;
  750. /* Use both frq_lock and signal to generate the result */
  751. signal = signal || ((signal & 0x07) << 12);
  752. ret:
  753. mutex_unlock(&priv->lock);
  754. *strength = signal;
  755. tuner_dbg("signal strength is %d\n", signal);
  756. return rc;
  757. }
  758. #define DIV 15625
  759. static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
  760. enum v4l2_tuner_type new_type,
  761. unsigned int type,
  762. v4l2_std_id std,
  763. u16 int_freq)
  764. {
  765. struct xc2028_data *priv = fe->tuner_priv;
  766. int rc = -EINVAL;
  767. unsigned char buf[4];
  768. u32 div, offset = 0;
  769. tuner_dbg("%s called\n", __func__);
  770. mutex_lock(&priv->lock);
  771. tuner_dbg("should set frequency %d kHz\n", freq / 1000);
  772. if (check_firmware(fe, type, std, int_freq) < 0)
  773. goto ret;
  774. /* On some cases xc2028 can disable video output, if
  775. * very weak signals are received. By sending a soft
  776. * reset, this is re-enabled. So, it is better to always
  777. * send a soft reset before changing channels, to be sure
  778. * that xc2028 will be in a safe state.
  779. * Maybe this might also be needed for DTV.
  780. */
  781. if (new_type == V4L2_TUNER_ANALOG_TV) {
  782. rc = send_seq(priv, {0x00, 0x00});
  783. /* Analog modes require offset = 0 */
  784. } else {
  785. /*
  786. * Digital modes require an offset to adjust to the
  787. * proper frequency. The offset depends on what
  788. * firmware version is used.
  789. */
  790. /*
  791. * Adjust to the center frequency. This is calculated by the
  792. * formula: offset = 1.25MHz - BW/2
  793. * For DTV 7/8, the firmware uses BW = 8000, so it needs a
  794. * further adjustment to get the frequency center on VHF
  795. */
  796. if (priv->cur_fw.type & DTV6)
  797. offset = 1750000;
  798. else if (priv->cur_fw.type & DTV7)
  799. offset = 2250000;
  800. else /* DTV8 or DTV78 */
  801. offset = 2750000;
  802. if ((priv->cur_fw.type & DTV78) && freq < 470000000)
  803. offset -= 500000;
  804. /*
  805. * xc3028 additional "magic"
  806. * Depending on the firmware version, it needs some adjustments
  807. * to properly centralize the frequency. This seems to be
  808. * needed to compensate the SCODE table adjustments made by
  809. * newer firmwares
  810. */
  811. #if 1
  812. /*
  813. * The proper adjustment would be to do it at s-code table.
  814. * However, this didn't work, as reported by
  815. * Robert Lowery <rglowery@exemail.com.au>
  816. */
  817. if (priv->cur_fw.type & DTV7)
  818. offset += 500000;
  819. #else
  820. /*
  821. * Still need tests for XC3028L (firmware 3.2 or upper)
  822. * So, for now, let's just comment the per-firmware
  823. * version of this change. Reports with xc3028l working
  824. * with and without the lines bellow are welcome
  825. */
  826. if (priv->firm_version < 0x0302) {
  827. if (priv->cur_fw.type & DTV7)
  828. offset += 500000;
  829. } else {
  830. if (priv->cur_fw.type & DTV7)
  831. offset -= 300000;
  832. else if (type != ATSC) /* DVB @6MHz, DTV 8 and DTV 7/8 */
  833. offset += 200000;
  834. }
  835. #endif
  836. }
  837. div = (freq - offset + DIV / 2) / DIV;
  838. /* CMD= Set frequency */
  839. if (priv->firm_version < 0x0202)
  840. rc = send_seq(priv, {0x00, 0x02, 0x00, 0x00});
  841. else
  842. rc = send_seq(priv, {0x80, 0x02, 0x00, 0x00});
  843. if (rc < 0)
  844. goto ret;
  845. /* Return code shouldn't be checked.
  846. The reset CLK is needed only with tm6000.
  847. Driver should work fine even if this fails.
  848. */
  849. if (priv->ctrl.msleep)
  850. msleep(priv->ctrl.msleep);
  851. do_tuner_callback(fe, XC2028_RESET_CLK, 1);
  852. msleep(10);
  853. buf[0] = 0xff & (div >> 24);
  854. buf[1] = 0xff & (div >> 16);
  855. buf[2] = 0xff & (div >> 8);
  856. buf[3] = 0xff & (div);
  857. rc = i2c_send(priv, buf, sizeof(buf));
  858. if (rc < 0)
  859. goto ret;
  860. msleep(100);
  861. priv->frequency = freq;
  862. tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n",
  863. buf[0], buf[1], buf[2], buf[3],
  864. freq / 1000000, (freq % 1000000) / 1000);
  865. rc = 0;
  866. ret:
  867. mutex_unlock(&priv->lock);
  868. return rc;
  869. }
  870. static int xc2028_set_analog_freq(struct dvb_frontend *fe,
  871. struct analog_parameters *p)
  872. {
  873. struct xc2028_data *priv = fe->tuner_priv;
  874. unsigned int type=0;
  875. tuner_dbg("%s called\n", __func__);
  876. if (p->mode == V4L2_TUNER_RADIO) {
  877. type |= FM;
  878. if (priv->ctrl.input1)
  879. type |= INPUT1;
  880. return generic_set_freq(fe, (625l * p->frequency) / 10,
  881. V4L2_TUNER_RADIO, type, 0, 0);
  882. }
  883. /* if std is not defined, choose one */
  884. if (!p->std)
  885. p->std = V4L2_STD_MN;
  886. /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */
  887. if (!(p->std & V4L2_STD_MN))
  888. type |= F8MHZ;
  889. /* Add audio hack to std mask */
  890. p->std |= parse_audio_std_option();
  891. return generic_set_freq(fe, 62500l * p->frequency,
  892. V4L2_TUNER_ANALOG_TV, type, p->std, 0);
  893. }
  894. static int xc2028_set_params(struct dvb_frontend *fe,
  895. struct dvb_frontend_parameters *p)
  896. {
  897. struct xc2028_data *priv = fe->tuner_priv;
  898. unsigned int type=0;
  899. fe_bandwidth_t bw = BANDWIDTH_8_MHZ;
  900. u16 demod = 0;
  901. tuner_dbg("%s called\n", __func__);
  902. switch(fe->ops.info.type) {
  903. case FE_OFDM:
  904. bw = p->u.ofdm.bandwidth;
  905. /*
  906. * The only countries with 6MHz seem to be Taiwan/Uruguay.
  907. * Both seem to require QAM firmware for OFDM decoding
  908. * Tested in Taiwan by Terry Wu <terrywu2009@gmail.com>
  909. */
  910. if (bw == BANDWIDTH_6_MHZ)
  911. type |= QAM;
  912. break;
  913. case FE_ATSC:
  914. bw = BANDWIDTH_6_MHZ;
  915. /* The only ATSC firmware (at least on v2.7) is D2633 */
  916. type |= ATSC | D2633;
  917. break;
  918. /* DVB-S and pure QAM (FE_QAM) are not supported */
  919. default:
  920. return -EINVAL;
  921. }
  922. switch (bw) {
  923. case BANDWIDTH_8_MHZ:
  924. if (p->frequency < 470000000)
  925. priv->ctrl.vhfbw7 = 0;
  926. else
  927. priv->ctrl.uhfbw8 = 1;
  928. type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV8;
  929. type |= F8MHZ;
  930. break;
  931. case BANDWIDTH_7_MHZ:
  932. if (p->frequency < 470000000)
  933. priv->ctrl.vhfbw7 = 1;
  934. else
  935. priv->ctrl.uhfbw8 = 0;
  936. type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV7;
  937. type |= F8MHZ;
  938. break;
  939. case BANDWIDTH_6_MHZ:
  940. type |= DTV6;
  941. priv->ctrl.vhfbw7 = 0;
  942. priv->ctrl.uhfbw8 = 0;
  943. break;
  944. default:
  945. tuner_err("error: bandwidth not supported.\n");
  946. };
  947. /*
  948. Selects between D2633 or D2620 firmware.
  949. It doesn't make sense for ATSC, since it should be D2633 on all cases
  950. */
  951. if (fe->ops.info.type != FE_ATSC) {
  952. switch (priv->ctrl.type) {
  953. case XC2028_D2633:
  954. type |= D2633;
  955. break;
  956. case XC2028_D2620:
  957. type |= D2620;
  958. break;
  959. case XC2028_AUTO:
  960. default:
  961. /* Zarlink seems to need D2633 */
  962. if (priv->ctrl.demod == XC3028_FE_ZARLINK456)
  963. type |= D2633;
  964. else
  965. type |= D2620;
  966. }
  967. }
  968. /* All S-code tables need a 200kHz shift */
  969. if (priv->ctrl.demod) {
  970. demod = priv->ctrl.demod;
  971. /*
  972. * Newer firmwares require a 200 kHz offset only for ATSC
  973. */
  974. if (type == ATSC || priv->firm_version < 0x0302)
  975. demod += 200;
  976. /*
  977. * The DTV7 S-code table needs a 700 kHz shift.
  978. *
  979. * DTV7 is only used in Australia. Germany or Italy may also
  980. * use this firmware after initialization, but a tune to a UHF
  981. * channel should then cause DTV78 to be used.
  982. *
  983. * Unfortunately, on real-field tests, the s-code offset
  984. * didn't work as expected, as reported by
  985. * Robert Lowery <rglowery@exemail.com.au>
  986. */
  987. }
  988. return generic_set_freq(fe, p->frequency,
  989. V4L2_TUNER_DIGITAL_TV, type, 0, demod);
  990. }
  991. static int xc2028_sleep(struct dvb_frontend *fe)
  992. {
  993. struct xc2028_data *priv = fe->tuner_priv;
  994. int rc = 0;
  995. /* Avoid firmware reload on slow devices or if PM disabled */
  996. if (no_poweroff || priv->ctrl.disable_power_mgmt)
  997. return 0;
  998. tuner_dbg("Putting xc2028/3028 into poweroff mode.\n");
  999. if (debug > 1) {
  1000. tuner_dbg("Printing sleep stack trace:\n");
  1001. dump_stack();
  1002. }
  1003. mutex_lock(&priv->lock);
  1004. if (priv->firm_version < 0x0202)
  1005. rc = send_seq(priv, {0x00, 0x08, 0x00, 0x00});
  1006. else
  1007. rc = send_seq(priv, {0x80, 0x08, 0x00, 0x00});
  1008. priv->cur_fw.type = 0; /* need firmware reload */
  1009. mutex_unlock(&priv->lock);
  1010. return rc;
  1011. }
  1012. static int xc2028_dvb_release(struct dvb_frontend *fe)
  1013. {
  1014. struct xc2028_data *priv = fe->tuner_priv;
  1015. tuner_dbg("%s called\n", __func__);
  1016. mutex_lock(&xc2028_list_mutex);
  1017. /* only perform final cleanup if this is the last instance */
  1018. if (hybrid_tuner_report_instance_count(priv) == 1) {
  1019. kfree(priv->ctrl.fname);
  1020. free_firmware(priv);
  1021. }
  1022. if (priv)
  1023. hybrid_tuner_release_state(priv);
  1024. mutex_unlock(&xc2028_list_mutex);
  1025. fe->tuner_priv = NULL;
  1026. return 0;
  1027. }
  1028. static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  1029. {
  1030. struct xc2028_data *priv = fe->tuner_priv;
  1031. tuner_dbg("%s called\n", __func__);
  1032. *frequency = priv->frequency;
  1033. return 0;
  1034. }
  1035. static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
  1036. {
  1037. struct xc2028_data *priv = fe->tuner_priv;
  1038. struct xc2028_ctrl *p = priv_cfg;
  1039. int rc = 0;
  1040. tuner_dbg("%s called\n", __func__);
  1041. mutex_lock(&priv->lock);
  1042. memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
  1043. if (priv->ctrl.max_len < 9)
  1044. priv->ctrl.max_len = 13;
  1045. if (p->fname) {
  1046. if (priv->ctrl.fname && strcmp(p->fname, priv->ctrl.fname)) {
  1047. kfree(priv->ctrl.fname);
  1048. free_firmware(priv);
  1049. }
  1050. priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
  1051. if (priv->ctrl.fname == NULL)
  1052. rc = -ENOMEM;
  1053. }
  1054. mutex_unlock(&priv->lock);
  1055. return rc;
  1056. }
  1057. static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
  1058. .info = {
  1059. .name = "Xceive XC3028",
  1060. .frequency_min = 42000000,
  1061. .frequency_max = 864000000,
  1062. .frequency_step = 50000,
  1063. },
  1064. .set_config = xc2028_set_config,
  1065. .set_analog_params = xc2028_set_analog_freq,
  1066. .release = xc2028_dvb_release,
  1067. .get_frequency = xc2028_get_frequency,
  1068. .get_rf_strength = xc2028_signal,
  1069. .set_params = xc2028_set_params,
  1070. .sleep = xc2028_sleep,
  1071. };
  1072. struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
  1073. struct xc2028_config *cfg)
  1074. {
  1075. struct xc2028_data *priv;
  1076. int instance;
  1077. if (debug)
  1078. printk(KERN_DEBUG "xc2028: Xcv2028/3028 init called!\n");
  1079. if (NULL == cfg)
  1080. return NULL;
  1081. if (!fe) {
  1082. printk(KERN_ERR "xc2028: No frontend!\n");
  1083. return NULL;
  1084. }
  1085. mutex_lock(&xc2028_list_mutex);
  1086. instance = hybrid_tuner_request_state(struct xc2028_data, priv,
  1087. hybrid_tuner_instance_list,
  1088. cfg->i2c_adap, cfg->i2c_addr,
  1089. "xc2028");
  1090. switch (instance) {
  1091. case 0:
  1092. /* memory allocation failure */
  1093. goto fail;
  1094. break;
  1095. case 1:
  1096. /* new tuner instance */
  1097. priv->ctrl.max_len = 13;
  1098. mutex_init(&priv->lock);
  1099. fe->tuner_priv = priv;
  1100. break;
  1101. case 2:
  1102. /* existing tuner instance */
  1103. fe->tuner_priv = priv;
  1104. break;
  1105. }
  1106. memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops,
  1107. sizeof(xc2028_dvb_tuner_ops));
  1108. tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
  1109. if (cfg->ctrl)
  1110. xc2028_set_config(fe, cfg->ctrl);
  1111. mutex_unlock(&xc2028_list_mutex);
  1112. return fe;
  1113. fail:
  1114. mutex_unlock(&xc2028_list_mutex);
  1115. xc2028_dvb_release(fe);
  1116. return NULL;
  1117. }
  1118. EXPORT_SYMBOL(xc2028_attach);
  1119. MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
  1120. MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>");
  1121. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  1122. MODULE_LICENSE("GPL");