stv6111.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for the ST STV6111 tuner
  4. *
  5. * Copyright (C) 2014 Digital Devices GmbH
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 only, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/init.h>
  20. #include <linux/delay.h>
  21. #include <linux/firmware.h>
  22. #include <linux/i2c.h>
  23. #include <asm/div64.h>
  24. #include "stv6111.h"
  25. #include <media/dvb_frontend.h>
  26. struct stv {
  27. struct i2c_adapter *i2c;
  28. u8 adr;
  29. u8 reg[11];
  30. u32 ref_freq;
  31. u32 frequency;
  32. };
  33. struct slookup {
  34. s16 value;
  35. u16 reg_value;
  36. };
  37. static const struct slookup lnagain_nf_lookup[] = {
  38. /* Gain *100dB // Reg */
  39. { 2572, 0 },
  40. { 2575, 1 },
  41. { 2580, 2 },
  42. { 2588, 3 },
  43. { 2596, 4 },
  44. { 2611, 5 },
  45. { 2633, 6 },
  46. { 2664, 7 },
  47. { 2701, 8 },
  48. { 2753, 9 },
  49. { 2816, 10 },
  50. { 2902, 11 },
  51. { 2995, 12 },
  52. { 3104, 13 },
  53. { 3215, 14 },
  54. { 3337, 15 },
  55. { 3492, 16 },
  56. { 3614, 17 },
  57. { 3731, 18 },
  58. { 3861, 19 },
  59. { 3988, 20 },
  60. { 4124, 21 },
  61. { 4253, 22 },
  62. { 4386, 23 },
  63. { 4505, 24 },
  64. { 4623, 25 },
  65. { 4726, 26 },
  66. { 4821, 27 },
  67. { 4903, 28 },
  68. { 4979, 29 },
  69. { 5045, 30 },
  70. { 5102, 31 }
  71. };
  72. static const struct slookup lnagain_iip3_lookup[] = {
  73. /* Gain *100dB // reg */
  74. { 1548, 0 },
  75. { 1552, 1 },
  76. { 1569, 2 },
  77. { 1565, 3 },
  78. { 1577, 4 },
  79. { 1594, 5 },
  80. { 1627, 6 },
  81. { 1656, 7 },
  82. { 1700, 8 },
  83. { 1748, 9 },
  84. { 1805, 10 },
  85. { 1896, 11 },
  86. { 1995, 12 },
  87. { 2113, 13 },
  88. { 2233, 14 },
  89. { 2366, 15 },
  90. { 2543, 16 },
  91. { 2687, 17 },
  92. { 2842, 18 },
  93. { 2999, 19 },
  94. { 3167, 20 },
  95. { 3342, 21 },
  96. { 3507, 22 },
  97. { 3679, 23 },
  98. { 3827, 24 },
  99. { 3970, 25 },
  100. { 4094, 26 },
  101. { 4210, 27 },
  102. { 4308, 28 },
  103. { 4396, 29 },
  104. { 4468, 30 },
  105. { 4535, 31 }
  106. };
  107. static const struct slookup gain_rfagc_lookup[] = {
  108. /* Gain *100dB // reg */
  109. { 4870, 0x3000 },
  110. { 4850, 0x3C00 },
  111. { 4800, 0x4500 },
  112. { 4750, 0x4800 },
  113. { 4700, 0x4B00 },
  114. { 4650, 0x4D00 },
  115. { 4600, 0x4F00 },
  116. { 4550, 0x5100 },
  117. { 4500, 0x5200 },
  118. { 4420, 0x5500 },
  119. { 4316, 0x5800 },
  120. { 4200, 0x5B00 },
  121. { 4119, 0x5D00 },
  122. { 3999, 0x6000 },
  123. { 3950, 0x6100 },
  124. { 3876, 0x6300 },
  125. { 3755, 0x6600 },
  126. { 3641, 0x6900 },
  127. { 3567, 0x6B00 },
  128. { 3425, 0x6F00 },
  129. { 3350, 0x7100 },
  130. { 3236, 0x7400 },
  131. { 3118, 0x7700 },
  132. { 3004, 0x7A00 },
  133. { 2917, 0x7C00 },
  134. { 2776, 0x7F00 },
  135. { 2635, 0x8200 },
  136. { 2516, 0x8500 },
  137. { 2406, 0x8800 },
  138. { 2290, 0x8B00 },
  139. { 2170, 0x8E00 },
  140. { 2073, 0x9100 },
  141. { 1949, 0x9400 },
  142. { 1836, 0x9700 },
  143. { 1712, 0x9A00 },
  144. { 1631, 0x9C00 },
  145. { 1515, 0x9F00 },
  146. { 1400, 0xA200 },
  147. { 1323, 0xA400 },
  148. { 1203, 0xA700 },
  149. { 1091, 0xAA00 },
  150. { 1011, 0xAC00 },
  151. { 904, 0xAF00 },
  152. { 787, 0xB200 },
  153. { 685, 0xB500 },
  154. { 571, 0xB800 },
  155. { 464, 0xBB00 },
  156. { 374, 0xBE00 },
  157. { 275, 0xC200 },
  158. { 181, 0xC600 },
  159. { 102, 0xCC00 },
  160. { 49, 0xD900 }
  161. };
  162. /*
  163. * This table is 6 dB too low comapred to the others (probably created with
  164. * a different BB_MAG setting)
  165. */
  166. static const struct slookup gain_channel_agc_nf_lookup[] = {
  167. /* Gain *100dB // reg */
  168. { 7082, 0x3000 },
  169. { 7052, 0x4000 },
  170. { 7007, 0x4600 },
  171. { 6954, 0x4A00 },
  172. { 6909, 0x4D00 },
  173. { 6833, 0x5100 },
  174. { 6753, 0x5400 },
  175. { 6659, 0x5700 },
  176. { 6561, 0x5A00 },
  177. { 6472, 0x5C00 },
  178. { 6366, 0x5F00 },
  179. { 6259, 0x6100 },
  180. { 6151, 0x6400 },
  181. { 6026, 0x6700 },
  182. { 5920, 0x6900 },
  183. { 5835, 0x6B00 },
  184. { 5770, 0x6C00 },
  185. { 5681, 0x6E00 },
  186. { 5596, 0x7000 },
  187. { 5503, 0x7200 },
  188. { 5429, 0x7300 },
  189. { 5319, 0x7500 },
  190. { 5220, 0x7700 },
  191. { 5111, 0x7900 },
  192. { 4983, 0x7B00 },
  193. { 4876, 0x7D00 },
  194. { 4755, 0x7F00 },
  195. { 4635, 0x8100 },
  196. { 4499, 0x8300 },
  197. { 4405, 0x8500 },
  198. { 4323, 0x8600 },
  199. { 4233, 0x8800 },
  200. { 4156, 0x8A00 },
  201. { 4038, 0x8C00 },
  202. { 3935, 0x8E00 },
  203. { 3823, 0x9000 },
  204. { 3712, 0x9200 },
  205. { 3601, 0x9500 },
  206. { 3511, 0x9700 },
  207. { 3413, 0x9900 },
  208. { 3309, 0x9B00 },
  209. { 3213, 0x9D00 },
  210. { 3088, 0x9F00 },
  211. { 2992, 0xA100 },
  212. { 2878, 0xA400 },
  213. { 2769, 0xA700 },
  214. { 2645, 0xAA00 },
  215. { 2538, 0xAD00 },
  216. { 2441, 0xB000 },
  217. { 2350, 0xB600 },
  218. { 2237, 0xBA00 },
  219. { 2137, 0xBF00 },
  220. { 2039, 0xC500 },
  221. { 1938, 0xDF00 },
  222. { 1927, 0xFF00 }
  223. };
  224. static const struct slookup gain_channel_agc_iip3_lookup[] = {
  225. /* Gain *100dB // reg */
  226. { 7070, 0x3000 },
  227. { 7028, 0x4000 },
  228. { 7019, 0x4600 },
  229. { 6900, 0x4A00 },
  230. { 6811, 0x4D00 },
  231. { 6763, 0x5100 },
  232. { 6690, 0x5400 },
  233. { 6644, 0x5700 },
  234. { 6617, 0x5A00 },
  235. { 6598, 0x5C00 },
  236. { 6462, 0x5F00 },
  237. { 6348, 0x6100 },
  238. { 6197, 0x6400 },
  239. { 6154, 0x6700 },
  240. { 6098, 0x6900 },
  241. { 5893, 0x6B00 },
  242. { 5812, 0x6C00 },
  243. { 5773, 0x6E00 },
  244. { 5723, 0x7000 },
  245. { 5661, 0x7200 },
  246. { 5579, 0x7300 },
  247. { 5460, 0x7500 },
  248. { 5308, 0x7700 },
  249. { 5099, 0x7900 },
  250. { 4910, 0x7B00 },
  251. { 4800, 0x7D00 },
  252. { 4785, 0x7F00 },
  253. { 4635, 0x8100 },
  254. { 4466, 0x8300 },
  255. { 4314, 0x8500 },
  256. { 4295, 0x8600 },
  257. { 4144, 0x8800 },
  258. { 3920, 0x8A00 },
  259. { 3889, 0x8C00 },
  260. { 3771, 0x8E00 },
  261. { 3655, 0x9000 },
  262. { 3446, 0x9200 },
  263. { 3298, 0x9500 },
  264. { 3083, 0x9700 },
  265. { 3015, 0x9900 },
  266. { 2833, 0x9B00 },
  267. { 2746, 0x9D00 },
  268. { 2632, 0x9F00 },
  269. { 2598, 0xA100 },
  270. { 2480, 0xA400 },
  271. { 2236, 0xA700 },
  272. { 2171, 0xAA00 },
  273. { 2060, 0xAD00 },
  274. { 1999, 0xB000 },
  275. { 1974, 0xB600 },
  276. { 1820, 0xBA00 },
  277. { 1741, 0xBF00 },
  278. { 1655, 0xC500 },
  279. { 1444, 0xDF00 },
  280. { 1325, 0xFF00 },
  281. };
  282. static inline u32 muldiv32(u32 a, u32 b, u32 c)
  283. {
  284. u64 tmp64;
  285. tmp64 = (u64)a * (u64)b;
  286. do_div(tmp64, c);
  287. return (u32)tmp64;
  288. }
  289. static int i2c_read(struct i2c_adapter *adap,
  290. u8 adr, u8 *msg, int len, u8 *answ, int alen)
  291. {
  292. struct i2c_msg msgs[2] = { { .addr = adr, .flags = 0,
  293. .buf = msg, .len = len},
  294. { .addr = adr, .flags = I2C_M_RD,
  295. .buf = answ, .len = alen } };
  296. if (i2c_transfer(adap, msgs, 2) != 2) {
  297. dev_err(&adap->dev, "i2c read error\n");
  298. return -EIO;
  299. }
  300. return 0;
  301. }
  302. static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
  303. {
  304. struct i2c_msg msg = {.addr = adr, .flags = 0,
  305. .buf = data, .len = len};
  306. if (i2c_transfer(adap, &msg, 1) != 1) {
  307. dev_err(&adap->dev, "i2c write error\n");
  308. return -EIO;
  309. }
  310. return 0;
  311. }
  312. static int write_regs(struct stv *state, int reg, int len)
  313. {
  314. u8 d[12];
  315. memcpy(&d[1], &state->reg[reg], len);
  316. d[0] = reg;
  317. return i2c_write(state->i2c, state->adr, d, len + 1);
  318. }
  319. static int write_reg(struct stv *state, u8 reg, u8 val)
  320. {
  321. u8 d[2] = {reg, val};
  322. return i2c_write(state->i2c, state->adr, d, 2);
  323. }
  324. static int read_reg(struct stv *state, u8 reg, u8 *val)
  325. {
  326. return i2c_read(state->i2c, state->adr, &reg, 1, val, 1);
  327. }
  328. static int wait_for_call_done(struct stv *state, u8 mask)
  329. {
  330. int status = 0;
  331. u32 lock_retry_count = 10;
  332. while (lock_retry_count > 0) {
  333. u8 regval;
  334. status = read_reg(state, 9, &regval);
  335. if (status < 0)
  336. return status;
  337. if ((regval & mask) == 0)
  338. break;
  339. usleep_range(4000, 6000);
  340. lock_retry_count -= 1;
  341. status = -EIO;
  342. }
  343. return status;
  344. }
  345. static void init_state(struct stv *state)
  346. {
  347. u32 clkdiv = 0;
  348. u32 agcmode = 0;
  349. u32 agcref = 2;
  350. u32 agcset = 0xffffffff;
  351. u32 bbmode = 0xffffffff;
  352. state->reg[0] = 0x08;
  353. state->reg[1] = 0x41;
  354. state->reg[2] = 0x8f;
  355. state->reg[3] = 0x00;
  356. state->reg[4] = 0xce;
  357. state->reg[5] = 0x54;
  358. state->reg[6] = 0x55;
  359. state->reg[7] = 0x45;
  360. state->reg[8] = 0x46;
  361. state->reg[9] = 0xbd;
  362. state->reg[10] = 0x11;
  363. state->ref_freq = 16000;
  364. if (clkdiv <= 3)
  365. state->reg[0x00] |= (clkdiv & 0x03);
  366. if (agcmode <= 3) {
  367. state->reg[0x03] |= (agcmode << 5);
  368. if (agcmode == 0x01)
  369. state->reg[0x01] |= 0x30;
  370. }
  371. if (bbmode <= 3)
  372. state->reg[0x01] = (state->reg[0x01] & ~0x30) | (bbmode << 4);
  373. if (agcref <= 7)
  374. state->reg[0x03] |= agcref;
  375. if (agcset <= 31)
  376. state->reg[0x02] = (state->reg[0x02] & ~0x1F) | agcset | 0x40;
  377. }
  378. static int attach_init(struct stv *state)
  379. {
  380. if (write_regs(state, 0, 11))
  381. return -ENODEV;
  382. return 0;
  383. }
  384. static void release(struct dvb_frontend *fe)
  385. {
  386. kfree(fe->tuner_priv);
  387. fe->tuner_priv = NULL;
  388. }
  389. static int set_bandwidth(struct dvb_frontend *fe, u32 cutoff_frequency)
  390. {
  391. struct stv *state = fe->tuner_priv;
  392. u32 index = (cutoff_frequency + 999999) / 1000000;
  393. int stat = 0;
  394. if (index < 6)
  395. index = 6;
  396. if (index > 50)
  397. index = 50;
  398. if ((state->reg[0x08] & ~0xFC) == ((index - 6) << 2))
  399. return 0;
  400. state->reg[0x08] = (state->reg[0x08] & ~0xFC) | ((index - 6) << 2);
  401. state->reg[0x09] = (state->reg[0x09] & ~0x0C) | 0x08;
  402. if (fe->ops.i2c_gate_ctrl)
  403. stat = fe->ops.i2c_gate_ctrl(fe, 1);
  404. if (!stat) {
  405. write_regs(state, 0x08, 2);
  406. wait_for_call_done(state, 0x08);
  407. }
  408. if (fe->ops.i2c_gate_ctrl && !stat)
  409. fe->ops.i2c_gate_ctrl(fe, 0);
  410. return stat;
  411. }
  412. static int set_lof(struct stv *state, u32 local_frequency, u32 cutoff_frequency)
  413. {
  414. u32 index = (cutoff_frequency + 999999) / 1000000;
  415. u32 frequency = (local_frequency + 500) / 1000;
  416. u32 p = 1, psel = 0, fvco, div, frac;
  417. u8 icp, tmp;
  418. if (index < 6)
  419. index = 6;
  420. if (index > 50)
  421. index = 50;
  422. if (frequency <= 1300000) {
  423. p = 4;
  424. psel = 1;
  425. } else {
  426. p = 2;
  427. psel = 0;
  428. }
  429. fvco = frequency * p;
  430. div = fvco / state->ref_freq;
  431. frac = fvco % state->ref_freq;
  432. frac = muldiv32(frac, 0x40000, state->ref_freq);
  433. icp = 0;
  434. if (fvco < 2700000)
  435. icp = 0;
  436. else if (fvco < 2950000)
  437. icp = 1;
  438. else if (fvco < 3300000)
  439. icp = 2;
  440. else if (fvco < 3700000)
  441. icp = 3;
  442. else if (fvco < 4200000)
  443. icp = 5;
  444. else if (fvco < 4800000)
  445. icp = 6;
  446. else
  447. icp = 7;
  448. state->reg[0x02] |= 0x80; /* LNA IIP3 Mode */
  449. state->reg[0x03] = (state->reg[0x03] & ~0x80) | (psel << 7);
  450. state->reg[0x04] = (div & 0xFF);
  451. state->reg[0x05] = (((div >> 8) & 0x01) | ((frac & 0x7F) << 1)) & 0xff;
  452. state->reg[0x06] = ((frac >> 7) & 0xFF);
  453. state->reg[0x07] = (state->reg[0x07] & ~0x07) | ((frac >> 15) & 0x07);
  454. state->reg[0x07] = (state->reg[0x07] & ~0xE0) | (icp << 5);
  455. state->reg[0x08] = (state->reg[0x08] & ~0xFC) | ((index - 6) << 2);
  456. /* Start cal vco,CF */
  457. state->reg[0x09] = (state->reg[0x09] & ~0x0C) | 0x0C;
  458. write_regs(state, 2, 8);
  459. wait_for_call_done(state, 0x0C);
  460. usleep_range(10000, 12000);
  461. read_reg(state, 0x03, &tmp);
  462. if (tmp & 0x10) {
  463. state->reg[0x02] &= ~0x80; /* LNA NF Mode */
  464. write_regs(state, 2, 1);
  465. }
  466. read_reg(state, 0x08, &tmp);
  467. state->frequency = frequency;
  468. return 0;
  469. }
  470. static int set_params(struct dvb_frontend *fe)
  471. {
  472. struct stv *state = fe->tuner_priv;
  473. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  474. u32 freq, cutoff;
  475. int stat = 0;
  476. if (p->delivery_system != SYS_DVBS && p->delivery_system != SYS_DVBS2)
  477. return -EINVAL;
  478. freq = p->frequency * 1000;
  479. cutoff = 5000000 + muldiv32(p->symbol_rate, 135, 200);
  480. if (fe->ops.i2c_gate_ctrl)
  481. stat = fe->ops.i2c_gate_ctrl(fe, 1);
  482. if (!stat)
  483. set_lof(state, freq, cutoff);
  484. if (fe->ops.i2c_gate_ctrl && !stat)
  485. fe->ops.i2c_gate_ctrl(fe, 0);
  486. return 0;
  487. }
  488. static s32 table_lookup(const struct slookup *table,
  489. int table_size, u16 reg_value)
  490. {
  491. s32 gain;
  492. s32 reg_diff;
  493. int imin = 0;
  494. int imax = table_size - 1;
  495. int i;
  496. /* Assumes Table[0].RegValue < Table[imax].RegValue */
  497. if (reg_value <= table[0].reg_value) {
  498. gain = table[0].value;
  499. } else if (reg_value >= table[imax].reg_value) {
  500. gain = table[imax].value;
  501. } else {
  502. while ((imax - imin) > 1) {
  503. i = (imax + imin) / 2;
  504. if ((table[imin].reg_value <= reg_value) &&
  505. (reg_value <= table[i].reg_value))
  506. imax = i;
  507. else
  508. imin = i;
  509. }
  510. reg_diff = table[imax].reg_value - table[imin].reg_value;
  511. gain = table[imin].value;
  512. if (reg_diff != 0)
  513. gain += ((s32)(reg_value - table[imin].reg_value) *
  514. (s32)(table[imax].value
  515. - table[imin].value)) / reg_diff;
  516. }
  517. return gain;
  518. }
  519. static int get_rf_strength(struct dvb_frontend *fe, u16 *st)
  520. {
  521. struct stv *state = fe->tuner_priv;
  522. u16 rfagc = *st;
  523. s32 gain;
  524. if ((state->reg[0x03] & 0x60) == 0) {
  525. /* RF Mode, Read AGC ADC */
  526. u8 reg = 0;
  527. int stat = 0;
  528. if (fe->ops.i2c_gate_ctrl)
  529. stat = fe->ops.i2c_gate_ctrl(fe, 1);
  530. if (!stat) {
  531. write_reg(state, 0x02, state->reg[0x02] | 0x20);
  532. read_reg(state, 2, &reg);
  533. if (reg & 0x20)
  534. read_reg(state, 2, &reg);
  535. }
  536. if (fe->ops.i2c_gate_ctrl && !stat)
  537. fe->ops.i2c_gate_ctrl(fe, 0);
  538. if ((state->reg[0x02] & 0x80) == 0)
  539. /* NF */
  540. gain = table_lookup(lnagain_nf_lookup,
  541. ARRAY_SIZE(lnagain_nf_lookup),
  542. reg & 0x1F);
  543. else
  544. /* IIP3 */
  545. gain = table_lookup(lnagain_iip3_lookup,
  546. ARRAY_SIZE(lnagain_iip3_lookup),
  547. reg & 0x1F);
  548. gain += table_lookup(gain_rfagc_lookup,
  549. ARRAY_SIZE(gain_rfagc_lookup), rfagc);
  550. gain -= 2400;
  551. } else {
  552. /* Channel Mode */
  553. if ((state->reg[0x02] & 0x80) == 0) {
  554. /* NF */
  555. gain = table_lookup(
  556. gain_channel_agc_nf_lookup,
  557. ARRAY_SIZE(gain_channel_agc_nf_lookup), rfagc);
  558. gain += 600;
  559. } else {
  560. /* IIP3 */
  561. gain = table_lookup(
  562. gain_channel_agc_iip3_lookup,
  563. ARRAY_SIZE(gain_channel_agc_iip3_lookup),
  564. rfagc);
  565. }
  566. }
  567. if (state->frequency > 0)
  568. /* Tilt correction ( 0.00016 dB/MHz ) */
  569. gain -= ((((s32)(state->frequency / 1000) - 1550) * 2) / 12);
  570. /* + (BBGain * 10); */
  571. gain += (s32)((state->reg[0x01] & 0xC0) >> 6) * 600 - 1300;
  572. if (gain < 0)
  573. gain = 0;
  574. else if (gain > 10000)
  575. gain = 10000;
  576. *st = 10000 - gain;
  577. return 0;
  578. }
  579. static const struct dvb_tuner_ops tuner_ops = {
  580. .info = {
  581. .name = "ST STV6111",
  582. .frequency_min_hz = 950 * MHz,
  583. .frequency_max_hz = 2150 * MHz,
  584. },
  585. .set_params = set_params,
  586. .release = release,
  587. .get_rf_strength = get_rf_strength,
  588. .set_bandwidth = set_bandwidth,
  589. };
  590. struct dvb_frontend *stv6111_attach(struct dvb_frontend *fe,
  591. struct i2c_adapter *i2c, u8 adr)
  592. {
  593. struct stv *state;
  594. int stat = -ENODEV;
  595. int gatestat = 0;
  596. state = kzalloc(sizeof(*state), GFP_KERNEL);
  597. if (!state)
  598. return NULL;
  599. state->adr = adr;
  600. state->i2c = i2c;
  601. memcpy(&fe->ops.tuner_ops, &tuner_ops, sizeof(struct dvb_tuner_ops));
  602. init_state(state);
  603. if (fe->ops.i2c_gate_ctrl)
  604. gatestat = fe->ops.i2c_gate_ctrl(fe, 1);
  605. if (!gatestat)
  606. stat = attach_init(state);
  607. if (fe->ops.i2c_gate_ctrl && !gatestat)
  608. fe->ops.i2c_gate_ctrl(fe, 0);
  609. if (stat < 0) {
  610. kfree(state);
  611. return NULL;
  612. }
  613. fe->tuner_priv = state;
  614. return fe;
  615. }
  616. EXPORT_SYMBOL_GPL(stv6111_attach);
  617. MODULE_DESCRIPTION("ST STV6111 satellite tuner driver");
  618. MODULE_AUTHOR("Ralph Metzler, Manfred Voelkel");
  619. MODULE_LICENSE("GPL v2");