tuner-xc2028.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  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. switch (new_type) {
  782. case V4L2_TUNER_ANALOG_TV:
  783. rc = send_seq(priv, {0x00, 0x00});
  784. /* Analog mode requires offset = 0 */
  785. break;
  786. case V4L2_TUNER_RADIO:
  787. /* Radio mode requires offset = 0 */
  788. break;
  789. case V4L2_TUNER_DIGITAL_TV:
  790. /*
  791. * Digital modes require an offset to adjust to the
  792. * proper frequency. The offset depends on what
  793. * firmware version is used.
  794. */
  795. /*
  796. * Adjust to the center frequency. This is calculated by the
  797. * formula: offset = 1.25MHz - BW/2
  798. * For DTV 7/8, the firmware uses BW = 8000, so it needs a
  799. * further adjustment to get the frequency center on VHF
  800. */
  801. if (priv->cur_fw.type & DTV6)
  802. offset = 1750000;
  803. else if (priv->cur_fw.type & DTV7)
  804. offset = 2250000;
  805. else /* DTV8 or DTV78 */
  806. offset = 2750000;
  807. if ((priv->cur_fw.type & DTV78) && freq < 470000000)
  808. offset -= 500000;
  809. /*
  810. * xc3028 additional "magic"
  811. * Depending on the firmware version, it needs some adjustments
  812. * to properly centralize the frequency. This seems to be
  813. * needed to compensate the SCODE table adjustments made by
  814. * newer firmwares
  815. */
  816. #if 1
  817. /*
  818. * The proper adjustment would be to do it at s-code table.
  819. * However, this didn't work, as reported by
  820. * Robert Lowery <rglowery@exemail.com.au>
  821. */
  822. if (priv->cur_fw.type & DTV7)
  823. offset += 500000;
  824. #else
  825. /*
  826. * Still need tests for XC3028L (firmware 3.2 or upper)
  827. * So, for now, let's just comment the per-firmware
  828. * version of this change. Reports with xc3028l working
  829. * with and without the lines bellow are welcome
  830. */
  831. if (priv->firm_version < 0x0302) {
  832. if (priv->cur_fw.type & DTV7)
  833. offset += 500000;
  834. } else {
  835. if (priv->cur_fw.type & DTV7)
  836. offset -= 300000;
  837. else if (type != ATSC) /* DVB @6MHz, DTV 8 and DTV 7/8 */
  838. offset += 200000;
  839. }
  840. #endif
  841. }
  842. div = (freq - offset + DIV / 2) / DIV;
  843. /* CMD= Set frequency */
  844. if (priv->firm_version < 0x0202)
  845. rc = send_seq(priv, {0x00, 0x02, 0x00, 0x00});
  846. else
  847. rc = send_seq(priv, {0x80, 0x02, 0x00, 0x00});
  848. if (rc < 0)
  849. goto ret;
  850. /* Return code shouldn't be checked.
  851. The reset CLK is needed only with tm6000.
  852. Driver should work fine even if this fails.
  853. */
  854. if (priv->ctrl.msleep)
  855. msleep(priv->ctrl.msleep);
  856. do_tuner_callback(fe, XC2028_RESET_CLK, 1);
  857. msleep(10);
  858. buf[0] = 0xff & (div >> 24);
  859. buf[1] = 0xff & (div >> 16);
  860. buf[2] = 0xff & (div >> 8);
  861. buf[3] = 0xff & (div);
  862. rc = i2c_send(priv, buf, sizeof(buf));
  863. if (rc < 0)
  864. goto ret;
  865. msleep(100);
  866. priv->frequency = freq;
  867. tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n",
  868. buf[0], buf[1], buf[2], buf[3],
  869. freq / 1000000, (freq % 1000000) / 1000);
  870. rc = 0;
  871. ret:
  872. mutex_unlock(&priv->lock);
  873. return rc;
  874. }
  875. static int xc2028_set_analog_freq(struct dvb_frontend *fe,
  876. struct analog_parameters *p)
  877. {
  878. struct xc2028_data *priv = fe->tuner_priv;
  879. unsigned int type=0;
  880. tuner_dbg("%s called\n", __func__);
  881. if (p->mode == V4L2_TUNER_RADIO) {
  882. type |= FM;
  883. if (priv->ctrl.input1)
  884. type |= INPUT1;
  885. return generic_set_freq(fe, (625l * p->frequency) / 10,
  886. V4L2_TUNER_RADIO, type, 0, 0);
  887. }
  888. /* if std is not defined, choose one */
  889. if (!p->std)
  890. p->std = V4L2_STD_MN;
  891. /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */
  892. if (!(p->std & V4L2_STD_MN))
  893. type |= F8MHZ;
  894. /* Add audio hack to std mask */
  895. p->std |= parse_audio_std_option();
  896. return generic_set_freq(fe, 62500l * p->frequency,
  897. V4L2_TUNER_ANALOG_TV, type, p->std, 0);
  898. }
  899. static int xc2028_set_params(struct dvb_frontend *fe,
  900. struct dvb_frontend_parameters *p)
  901. {
  902. struct xc2028_data *priv = fe->tuner_priv;
  903. unsigned int type=0;
  904. fe_bandwidth_t bw = BANDWIDTH_8_MHZ;
  905. u16 demod = 0;
  906. tuner_dbg("%s called\n", __func__);
  907. switch(fe->ops.info.type) {
  908. case FE_OFDM:
  909. bw = p->u.ofdm.bandwidth;
  910. /*
  911. * The only countries with 6MHz seem to be Taiwan/Uruguay.
  912. * Both seem to require QAM firmware for OFDM decoding
  913. * Tested in Taiwan by Terry Wu <terrywu2009@gmail.com>
  914. */
  915. if (bw == BANDWIDTH_6_MHZ)
  916. type |= QAM;
  917. break;
  918. case FE_ATSC:
  919. bw = BANDWIDTH_6_MHZ;
  920. /* The only ATSC firmware (at least on v2.7) is D2633 */
  921. type |= ATSC | D2633;
  922. break;
  923. /* DVB-S and pure QAM (FE_QAM) are not supported */
  924. default:
  925. return -EINVAL;
  926. }
  927. switch (bw) {
  928. case BANDWIDTH_8_MHZ:
  929. if (p->frequency < 470000000)
  930. priv->ctrl.vhfbw7 = 0;
  931. else
  932. priv->ctrl.uhfbw8 = 1;
  933. type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV8;
  934. type |= F8MHZ;
  935. break;
  936. case BANDWIDTH_7_MHZ:
  937. if (p->frequency < 470000000)
  938. priv->ctrl.vhfbw7 = 1;
  939. else
  940. priv->ctrl.uhfbw8 = 0;
  941. type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV7;
  942. type |= F8MHZ;
  943. break;
  944. case BANDWIDTH_6_MHZ:
  945. type |= DTV6;
  946. priv->ctrl.vhfbw7 = 0;
  947. priv->ctrl.uhfbw8 = 0;
  948. break;
  949. default:
  950. tuner_err("error: bandwidth not supported.\n");
  951. };
  952. /*
  953. Selects between D2633 or D2620 firmware.
  954. It doesn't make sense for ATSC, since it should be D2633 on all cases
  955. */
  956. if (fe->ops.info.type != FE_ATSC) {
  957. switch (priv->ctrl.type) {
  958. case XC2028_D2633:
  959. type |= D2633;
  960. break;
  961. case XC2028_D2620:
  962. type |= D2620;
  963. break;
  964. case XC2028_AUTO:
  965. default:
  966. /* Zarlink seems to need D2633 */
  967. if (priv->ctrl.demod == XC3028_FE_ZARLINK456)
  968. type |= D2633;
  969. else
  970. type |= D2620;
  971. }
  972. }
  973. /* All S-code tables need a 200kHz shift */
  974. if (priv->ctrl.demod) {
  975. demod = priv->ctrl.demod;
  976. /*
  977. * Newer firmwares require a 200 kHz offset only for ATSC
  978. */
  979. if (type == ATSC || priv->firm_version < 0x0302)
  980. demod += 200;
  981. /*
  982. * The DTV7 S-code table needs a 700 kHz shift.
  983. *
  984. * DTV7 is only used in Australia. Germany or Italy may also
  985. * use this firmware after initialization, but a tune to a UHF
  986. * channel should then cause DTV78 to be used.
  987. *
  988. * Unfortunately, on real-field tests, the s-code offset
  989. * didn't work as expected, as reported by
  990. * Robert Lowery <rglowery@exemail.com.au>
  991. */
  992. }
  993. return generic_set_freq(fe, p->frequency,
  994. V4L2_TUNER_DIGITAL_TV, type, 0, demod);
  995. }
  996. static int xc2028_sleep(struct dvb_frontend *fe)
  997. {
  998. struct xc2028_data *priv = fe->tuner_priv;
  999. int rc = 0;
  1000. /* Avoid firmware reload on slow devices or if PM disabled */
  1001. if (no_poweroff || priv->ctrl.disable_power_mgmt)
  1002. return 0;
  1003. tuner_dbg("Putting xc2028/3028 into poweroff mode.\n");
  1004. if (debug > 1) {
  1005. tuner_dbg("Printing sleep stack trace:\n");
  1006. dump_stack();
  1007. }
  1008. mutex_lock(&priv->lock);
  1009. if (priv->firm_version < 0x0202)
  1010. rc = send_seq(priv, {0x00, 0x08, 0x00, 0x00});
  1011. else
  1012. rc = send_seq(priv, {0x80, 0x08, 0x00, 0x00});
  1013. priv->cur_fw.type = 0; /* need firmware reload */
  1014. mutex_unlock(&priv->lock);
  1015. return rc;
  1016. }
  1017. static int xc2028_dvb_release(struct dvb_frontend *fe)
  1018. {
  1019. struct xc2028_data *priv = fe->tuner_priv;
  1020. tuner_dbg("%s called\n", __func__);
  1021. mutex_lock(&xc2028_list_mutex);
  1022. /* only perform final cleanup if this is the last instance */
  1023. if (hybrid_tuner_report_instance_count(priv) == 1) {
  1024. kfree(priv->ctrl.fname);
  1025. free_firmware(priv);
  1026. }
  1027. if (priv)
  1028. hybrid_tuner_release_state(priv);
  1029. mutex_unlock(&xc2028_list_mutex);
  1030. fe->tuner_priv = NULL;
  1031. return 0;
  1032. }
  1033. static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  1034. {
  1035. struct xc2028_data *priv = fe->tuner_priv;
  1036. tuner_dbg("%s called\n", __func__);
  1037. *frequency = priv->frequency;
  1038. return 0;
  1039. }
  1040. static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
  1041. {
  1042. struct xc2028_data *priv = fe->tuner_priv;
  1043. struct xc2028_ctrl *p = priv_cfg;
  1044. int rc = 0;
  1045. tuner_dbg("%s called\n", __func__);
  1046. mutex_lock(&priv->lock);
  1047. memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
  1048. if (priv->ctrl.max_len < 9)
  1049. priv->ctrl.max_len = 13;
  1050. if (p->fname) {
  1051. if (priv->ctrl.fname && strcmp(p->fname, priv->ctrl.fname)) {
  1052. kfree(priv->ctrl.fname);
  1053. free_firmware(priv);
  1054. }
  1055. priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
  1056. if (priv->ctrl.fname == NULL)
  1057. rc = -ENOMEM;
  1058. }
  1059. mutex_unlock(&priv->lock);
  1060. return rc;
  1061. }
  1062. static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
  1063. .info = {
  1064. .name = "Xceive XC3028",
  1065. .frequency_min = 42000000,
  1066. .frequency_max = 864000000,
  1067. .frequency_step = 50000,
  1068. },
  1069. .set_config = xc2028_set_config,
  1070. .set_analog_params = xc2028_set_analog_freq,
  1071. .release = xc2028_dvb_release,
  1072. .get_frequency = xc2028_get_frequency,
  1073. .get_rf_strength = xc2028_signal,
  1074. .set_params = xc2028_set_params,
  1075. .sleep = xc2028_sleep,
  1076. };
  1077. struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
  1078. struct xc2028_config *cfg)
  1079. {
  1080. struct xc2028_data *priv;
  1081. int instance;
  1082. if (debug)
  1083. printk(KERN_DEBUG "xc2028: Xcv2028/3028 init called!\n");
  1084. if (NULL == cfg)
  1085. return NULL;
  1086. if (!fe) {
  1087. printk(KERN_ERR "xc2028: No frontend!\n");
  1088. return NULL;
  1089. }
  1090. mutex_lock(&xc2028_list_mutex);
  1091. instance = hybrid_tuner_request_state(struct xc2028_data, priv,
  1092. hybrid_tuner_instance_list,
  1093. cfg->i2c_adap, cfg->i2c_addr,
  1094. "xc2028");
  1095. switch (instance) {
  1096. case 0:
  1097. /* memory allocation failure */
  1098. goto fail;
  1099. break;
  1100. case 1:
  1101. /* new tuner instance */
  1102. priv->ctrl.max_len = 13;
  1103. mutex_init(&priv->lock);
  1104. fe->tuner_priv = priv;
  1105. break;
  1106. case 2:
  1107. /* existing tuner instance */
  1108. fe->tuner_priv = priv;
  1109. break;
  1110. }
  1111. memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops,
  1112. sizeof(xc2028_dvb_tuner_ops));
  1113. tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
  1114. if (cfg->ctrl)
  1115. xc2028_set_config(fe, cfg->ctrl);
  1116. mutex_unlock(&xc2028_list_mutex);
  1117. return fe;
  1118. fail:
  1119. mutex_unlock(&xc2028_list_mutex);
  1120. xc2028_dvb_release(fe);
  1121. return NULL;
  1122. }
  1123. EXPORT_SYMBOL(xc2028_attach);
  1124. MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
  1125. MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>");
  1126. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
  1127. MODULE_LICENSE("GPL");