tuner-xc2028.c 32 KB

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