stb6100.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. STB6100 Silicon Tuner
  3. Copyright (C) Manu Abraham (abraham.manu@gmail.com)
  4. Copyright (C) ST Microelectronics
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/string.h>
  22. #include "dvb_frontend.h"
  23. #include "stb6100.h"
  24. static unsigned int verbose;
  25. module_param(verbose, int, 0644);
  26. #define FE_ERROR 0
  27. #define FE_NOTICE 1
  28. #define FE_INFO 2
  29. #define FE_DEBUG 3
  30. #define dprintk(x, y, z, format, arg...) do { \
  31. if (z) { \
  32. if ((x > FE_ERROR) && (x > y)) \
  33. printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \
  34. else if ((x > FE_NOTICE) && (x > y)) \
  35. printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \
  36. else if ((x > FE_INFO) && (x > y)) \
  37. printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \
  38. else if ((x > FE_DEBUG) && (x > y)) \
  39. printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \
  40. } else { \
  41. if (x > y) \
  42. printk(format, ##arg); \
  43. } \
  44. } while (0)
  45. struct stb6100_lkup {
  46. u32 val_low;
  47. u32 val_high;
  48. u8 reg;
  49. };
  50. static int stb6100_release(struct dvb_frontend *fe);
  51. static const struct stb6100_lkup lkup[] = {
  52. { 0, 950000, 0x0a },
  53. { 950000, 1000000, 0x0a },
  54. { 1000000, 1075000, 0x0c },
  55. { 1075000, 1200000, 0x00 },
  56. { 1200000, 1300000, 0x01 },
  57. { 1300000, 1370000, 0x02 },
  58. { 1370000, 1470000, 0x04 },
  59. { 1470000, 1530000, 0x05 },
  60. { 1530000, 1650000, 0x06 },
  61. { 1650000, 1800000, 0x08 },
  62. { 1800000, 1950000, 0x0a },
  63. { 1950000, 2150000, 0x0c },
  64. { 2150000, 9999999, 0x0c },
  65. { 0, 0, 0x00 }
  66. };
  67. /* Register names for easy debugging. */
  68. static const char *stb6100_regnames[] = {
  69. [STB6100_LD] = "LD",
  70. [STB6100_VCO] = "VCO",
  71. [STB6100_NI] = "NI",
  72. [STB6100_NF_LSB] = "NF",
  73. [STB6100_K] = "K",
  74. [STB6100_G] = "G",
  75. [STB6100_F] = "F",
  76. [STB6100_DLB] = "DLB",
  77. [STB6100_TEST1] = "TEST1",
  78. [STB6100_FCCK] = "FCCK",
  79. [STB6100_LPEN] = "LPEN",
  80. [STB6100_TEST3] = "TEST3",
  81. };
  82. /* Template for normalisation, i.e. setting unused or undocumented
  83. * bits as required according to the documentation.
  84. */
  85. struct stb6100_regmask {
  86. u8 mask;
  87. u8 set;
  88. };
  89. static const struct stb6100_regmask stb6100_template[] = {
  90. [STB6100_LD] = { 0xff, 0x00 },
  91. [STB6100_VCO] = { 0xff, 0x00 },
  92. [STB6100_NI] = { 0xff, 0x00 },
  93. [STB6100_NF_LSB] = { 0xff, 0x00 },
  94. [STB6100_K] = { 0xc7, 0x38 },
  95. [STB6100_G] = { 0xef, 0x10 },
  96. [STB6100_F] = { 0x1f, 0xc0 },
  97. [STB6100_DLB] = { 0x38, 0xc4 },
  98. [STB6100_TEST1] = { 0x00, 0x8f },
  99. [STB6100_FCCK] = { 0x40, 0x0d },
  100. [STB6100_LPEN] = { 0xf0, 0x0b },
  101. [STB6100_TEST3] = { 0x00, 0xde },
  102. };
  103. /*
  104. * Currently unused. Some boards might need it in the future
  105. */
  106. static inline void stb6100_normalise_regs(u8 regs[])
  107. {
  108. int i;
  109. for (i = 0; i < STB6100_NUMREGS; i++)
  110. regs[i] = (regs[i] & stb6100_template[i].mask) | stb6100_template[i].set;
  111. }
  112. static int stb6100_read_regs(struct stb6100_state *state, u8 regs[])
  113. {
  114. int rc;
  115. struct i2c_msg msg = {
  116. .addr = state->config->tuner_address,
  117. .flags = I2C_M_RD,
  118. .buf = regs,
  119. .len = STB6100_NUMREGS
  120. };
  121. rc = i2c_transfer(state->i2c, &msg, 1);
  122. if (unlikely(rc != 1)) {
  123. dprintk(verbose, FE_ERROR, 1, "Read (0x%x) err, rc=[%d]",
  124. state->config->tuner_address, rc);
  125. return -EREMOTEIO;
  126. }
  127. if (unlikely(verbose > FE_DEBUG)) {
  128. int i;
  129. dprintk(verbose, FE_DEBUG, 1, " Read from 0x%02x", state->config->tuner_address);
  130. for (i = 0; i < STB6100_NUMREGS; i++)
  131. dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[i], regs[i]);
  132. }
  133. return 0;
  134. }
  135. static int stb6100_read_reg(struct stb6100_state *state, u8 reg)
  136. {
  137. u8 regs[STB6100_NUMREGS];
  138. int rc;
  139. struct i2c_msg msg = {
  140. .addr = state->config->tuner_address + reg,
  141. .flags = I2C_M_RD,
  142. .buf = regs,
  143. .len = 1
  144. };
  145. rc = i2c_transfer(state->i2c, &msg, 1);
  146. if (unlikely(reg >= STB6100_NUMREGS)) {
  147. dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg);
  148. return -EINVAL;
  149. }
  150. if (unlikely(verbose > FE_DEBUG)) {
  151. dprintk(verbose, FE_DEBUG, 1, " Read from 0x%02x", state->config->tuner_address);
  152. dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[reg], regs[0]);
  153. }
  154. return (unsigned int)regs[0];
  155. }
  156. static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len)
  157. {
  158. int rc;
  159. u8 cmdbuf[len + 1];
  160. struct i2c_msg msg = {
  161. .addr = state->config->tuner_address,
  162. .flags = 0,
  163. .buf = cmdbuf,
  164. .len = len + 1
  165. };
  166. if (unlikely(start < 1 || start + len > STB6100_NUMREGS)) {
  167. dprintk(verbose, FE_ERROR, 1, "Invalid register range %d:%d",
  168. start, len);
  169. return -EINVAL;
  170. }
  171. memcpy(&cmdbuf[1], buf, len);
  172. cmdbuf[0] = start;
  173. if (unlikely(verbose > FE_DEBUG)) {
  174. int i;
  175. dprintk(verbose, FE_DEBUG, 1, " Write @ 0x%02x: [%d:%d]", state->config->tuner_address, start, len);
  176. for (i = 0; i < len; i++)
  177. dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[start + i], buf[i]);
  178. }
  179. rc = i2c_transfer(state->i2c, &msg, 1);
  180. if (unlikely(rc != 1)) {
  181. dprintk(verbose, FE_ERROR, 1, "(0x%x) write err [%d:%d], rc=[%d]",
  182. (unsigned int)state->config->tuner_address, start, len, rc);
  183. return -EREMOTEIO;
  184. }
  185. return 0;
  186. }
  187. static int stb6100_write_reg(struct stb6100_state *state, u8 reg, u8 data)
  188. {
  189. if (unlikely(reg >= STB6100_NUMREGS)) {
  190. dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg);
  191. return -EREMOTEIO;
  192. }
  193. data = (data & stb6100_template[reg].mask) | stb6100_template[reg].set;
  194. return stb6100_write_reg_range(state, &data, reg, 1);
  195. }
  196. static int stb6100_get_status(struct dvb_frontend *fe, u32 *status)
  197. {
  198. int rc;
  199. struct stb6100_state *state = fe->tuner_priv;
  200. rc = stb6100_read_reg(state, STB6100_LD);
  201. if (rc < 0) {
  202. dprintk(verbose, FE_ERROR, 1, "%s failed", __func__);
  203. return rc;
  204. }
  205. return (rc & STB6100_LD_LOCK) ? TUNER_STATUS_LOCKED : 0;
  206. }
  207. static int stb6100_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
  208. {
  209. int rc;
  210. u8 f;
  211. struct stb6100_state *state = fe->tuner_priv;
  212. rc = stb6100_read_reg(state, STB6100_F);
  213. if (rc < 0)
  214. return rc;
  215. f = rc & STB6100_F_F;
  216. state->status.bandwidth = (f + 5) * 2000; /* x2 for ZIF */
  217. *bandwidth = state->bandwidth = state->status.bandwidth * 1000;
  218. dprintk(verbose, FE_DEBUG, 1, "bandwidth = %u Hz", state->bandwidth);
  219. return 0;
  220. }
  221. static int stb6100_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
  222. {
  223. u32 tmp;
  224. int rc;
  225. struct stb6100_state *state = fe->tuner_priv;
  226. dprintk(verbose, FE_DEBUG, 1, "set bandwidth to %u Hz", bandwidth);
  227. bandwidth /= 2; /* ZIF */
  228. if (bandwidth >= 36000000) /* F[4:0] BW/2 max =31+5=36 mhz for F=31 */
  229. tmp = 31;
  230. else if (bandwidth <= 5000000) /* bw/2 min = 5Mhz for F=0 */
  231. tmp = 0;
  232. else /* if 5 < bw/2 < 36 */
  233. tmp = (bandwidth + 500000) / 1000000 - 5;
  234. /* Turn on LPF bandwidth setting clock control,
  235. * set bandwidth, wait 10ms, turn off.
  236. */
  237. rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d | STB6100_FCCK_FCCK);
  238. if (rc < 0)
  239. return rc;
  240. rc = stb6100_write_reg(state, STB6100_F, 0xc0 | tmp);
  241. if (rc < 0)
  242. return rc;
  243. msleep(5); /* This is dangerous as another (related) thread may start */
  244. rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d);
  245. if (rc < 0)
  246. return rc;
  247. msleep(10); /* This is dangerous as another (related) thread may start */
  248. return 0;
  249. }
  250. static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  251. {
  252. int rc;
  253. u32 nint, nfrac, fvco;
  254. int psd2, odiv;
  255. struct stb6100_state *state = fe->tuner_priv;
  256. u8 regs[STB6100_NUMREGS];
  257. rc = stb6100_read_regs(state, regs);
  258. if (rc < 0)
  259. return rc;
  260. odiv = (regs[STB6100_VCO] & STB6100_VCO_ODIV) >> STB6100_VCO_ODIV_SHIFT;
  261. psd2 = (regs[STB6100_K] & STB6100_K_PSD2) >> STB6100_K_PSD2_SHIFT;
  262. nint = regs[STB6100_NI];
  263. nfrac = ((regs[STB6100_K] & STB6100_K_NF_MSB) << 8) | regs[STB6100_NF_LSB];
  264. fvco = (nfrac * state->reference >> (9 - psd2)) + (nint * state->reference << psd2);
  265. *frequency = state->frequency = fvco >> (odiv + 1);
  266. dprintk(verbose, FE_DEBUG, 1,
  267. "frequency = %u kHz, odiv = %u, psd2 = %u, fxtal = %u kHz, fvco = %u kHz, N(I) = %u, N(F) = %u",
  268. state->frequency, odiv, psd2, state->reference, fvco, nint, nfrac);
  269. return 0;
  270. }
  271. static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
  272. {
  273. int rc;
  274. const struct stb6100_lkup *ptr;
  275. struct stb6100_state *state = fe->tuner_priv;
  276. struct dvb_frontend_parameters p;
  277. u32 srate = 0, fvco, nint, nfrac;
  278. u8 regs[STB6100_NUMREGS];
  279. u8 g, psd2, odiv;
  280. dprintk(verbose, FE_DEBUG, 1, "Version 2010-8-14 13:51");
  281. if (fe->ops.get_frontend) {
  282. dprintk(verbose, FE_DEBUG, 1, "Get frontend parameters");
  283. fe->ops.get_frontend(fe, &p);
  284. }
  285. srate = p.u.qpsk.symbol_rate;
  286. /* Set up tuner cleanly, LPF calibration on */
  287. rc = stb6100_write_reg(state, STB6100_FCCK, 0x4d | STB6100_FCCK_FCCK);
  288. if (rc < 0)
  289. return rc; /* allow LPF calibration */
  290. /* PLL Loop disabled, bias on, VCO on, synth on */
  291. regs[STB6100_LPEN] = 0xeb;
  292. rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN]);
  293. if (rc < 0)
  294. return rc;
  295. /* Program the registers with their data values */
  296. /* VCO divide ratio (LO divide ratio, VCO prescaler enable). */
  297. if (frequency <= 1075000)
  298. odiv = 1;
  299. else
  300. odiv = 0;
  301. /* VCO enabled, search clock off as per LL3.7, 3.4.1 */
  302. regs[STB6100_VCO] = 0xe0 | (odiv << STB6100_VCO_ODIV_SHIFT);
  303. /* OSM */
  304. for (ptr = lkup;
  305. (ptr->val_high != 0) && !CHKRANGE(frequency, ptr->val_low, ptr->val_high);
  306. ptr++);
  307. if (ptr->val_high == 0) {
  308. printk(KERN_ERR "%s: frequency out of range: %u kHz\n", __func__, frequency);
  309. return -EINVAL;
  310. }
  311. regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_OSM) | ptr->reg;
  312. rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
  313. if (rc < 0)
  314. return rc;
  315. if ((frequency > 1075000) && (frequency <= 1325000))
  316. psd2 = 0;
  317. else
  318. psd2 = 1;
  319. /* F(VCO) = F(LO) * (ODIV == 0 ? 2 : 4) */
  320. fvco = frequency << (1 + odiv);
  321. /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */
  322. nint = fvco / (state->reference << psd2);
  323. /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */
  324. nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2))
  325. << (9 - psd2), state->reference);
  326. /* NI */
  327. regs[STB6100_NI] = nint;
  328. rc = stb6100_write_reg(state, STB6100_NI, regs[STB6100_NI]);
  329. if (rc < 0)
  330. return rc;
  331. /* NF */
  332. regs[STB6100_NF_LSB] = nfrac;
  333. rc = stb6100_write_reg(state, STB6100_NF_LSB, regs[STB6100_NF_LSB]);
  334. if (rc < 0)
  335. return rc;
  336. /* K */
  337. regs[STB6100_K] = (0x38 & ~STB6100_K_PSD2) | (psd2 << STB6100_K_PSD2_SHIFT);
  338. regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_NF_MSB) | ((nfrac >> 8) & STB6100_K_NF_MSB);
  339. rc = stb6100_write_reg(state, STB6100_K, regs[STB6100_K]);
  340. if (rc < 0)
  341. return rc;
  342. /* G Baseband gain. */
  343. if (srate >= 15000000)
  344. g = 9; /* +4 dB */
  345. else if (srate >= 5000000)
  346. g = 11; /* +8 dB */
  347. else
  348. g = 14; /* +14 dB */
  349. regs[STB6100_G] = (0x10 & ~STB6100_G_G) | g;
  350. regs[STB6100_G] &= ~STB6100_G_GCT; /* mask GCT */
  351. regs[STB6100_G] |= (1 << 5); /* 2Vp-p Mode */
  352. rc = stb6100_write_reg(state, STB6100_G, regs[STB6100_G]);
  353. if (rc < 0)
  354. return rc;
  355. /* F we don't write as it is set up in BW set */
  356. /* DLB set DC servo loop BW to 160Hz (LLA 3.8 / 2.1) */
  357. regs[STB6100_DLB] = 0xcc;
  358. rc = stb6100_write_reg(state, STB6100_DLB, regs[STB6100_DLB]);
  359. if (rc < 0)
  360. return rc;
  361. dprintk(verbose, FE_DEBUG, 1,
  362. "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u",
  363. frequency, srate, (unsigned int)g, (unsigned int)odiv,
  364. (unsigned int)psd2, state->reference,
  365. ptr->reg, fvco, nint, nfrac);
  366. /* Set up the test registers */
  367. regs[STB6100_TEST1] = 0x8f;
  368. rc = stb6100_write_reg(state, STB6100_TEST1, regs[STB6100_TEST1]);
  369. if (rc < 0)
  370. return rc;
  371. regs[STB6100_TEST3] = 0xde;
  372. rc = stb6100_write_reg(state, STB6100_TEST3, regs[STB6100_TEST3]);
  373. if (rc < 0)
  374. return rc;
  375. /* Bring up tuner according to LLA 3.7 3.4.1, step 2 */
  376. regs[STB6100_LPEN] = 0xfb; /* PLL Loop enabled, bias on, VCO on, synth on */
  377. rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN]);
  378. if (rc < 0)
  379. return rc;
  380. msleep(2);
  381. /* Bring up tuner according to LLA 3.7 3.4.1, step 3 */
  382. regs[STB6100_VCO] &= ~STB6100_VCO_OCK; /* VCO fast search */
  383. rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
  384. if (rc < 0)
  385. return rc;
  386. msleep(10); /* This is dangerous as another (related) thread may start */ /* wait for LO to lock */
  387. regs[STB6100_VCO] &= ~STB6100_VCO_OSCH; /* vco search disabled */
  388. regs[STB6100_VCO] |= STB6100_VCO_OCK; /* search clock off */
  389. rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
  390. if (rc < 0)
  391. return rc;
  392. rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d);
  393. if (rc < 0)
  394. return rc; /* Stop LPF calibration */
  395. msleep(10); /* This is dangerous as another (related) thread may start */
  396. /* wait for stabilisation, (should not be necessary) */
  397. return 0;
  398. }
  399. static int stb6100_sleep(struct dvb_frontend *fe)
  400. {
  401. /* TODO: power down */
  402. return 0;
  403. }
  404. static int stb6100_init(struct dvb_frontend *fe)
  405. {
  406. struct stb6100_state *state = fe->tuner_priv;
  407. struct tuner_state *status = &state->status;
  408. status->tunerstep = 125000;
  409. status->ifreq = 0;
  410. status->refclock = 27000000; /* Hz */
  411. status->iqsense = 1;
  412. status->bandwidth = 36000; /* kHz */
  413. state->bandwidth = status->bandwidth * 1000; /* Hz */
  414. state->reference = status->refclock / 1000; /* kHz */
  415. /* Set default bandwidth. Modified, PN 13-May-10 */
  416. return 0;
  417. }
  418. static int stb6100_get_state(struct dvb_frontend *fe,
  419. enum tuner_param param,
  420. struct tuner_state *state)
  421. {
  422. switch (param) {
  423. case DVBFE_TUNER_FREQUENCY:
  424. stb6100_get_frequency(fe, &state->frequency);
  425. break;
  426. case DVBFE_TUNER_TUNERSTEP:
  427. break;
  428. case DVBFE_TUNER_IFFREQ:
  429. break;
  430. case DVBFE_TUNER_BANDWIDTH:
  431. stb6100_get_bandwidth(fe, &state->bandwidth);
  432. break;
  433. case DVBFE_TUNER_REFCLOCK:
  434. break;
  435. default:
  436. break;
  437. }
  438. return 0;
  439. }
  440. static int stb6100_set_state(struct dvb_frontend *fe,
  441. enum tuner_param param,
  442. struct tuner_state *state)
  443. {
  444. struct stb6100_state *tstate = fe->tuner_priv;
  445. switch (param) {
  446. case DVBFE_TUNER_FREQUENCY:
  447. stb6100_set_frequency(fe, state->frequency);
  448. tstate->frequency = state->frequency;
  449. break;
  450. case DVBFE_TUNER_TUNERSTEP:
  451. break;
  452. case DVBFE_TUNER_IFFREQ:
  453. break;
  454. case DVBFE_TUNER_BANDWIDTH:
  455. stb6100_set_bandwidth(fe, state->bandwidth);
  456. tstate->bandwidth = state->bandwidth;
  457. break;
  458. case DVBFE_TUNER_REFCLOCK:
  459. break;
  460. default:
  461. break;
  462. }
  463. return 0;
  464. }
  465. static struct dvb_tuner_ops stb6100_ops = {
  466. .info = {
  467. .name = "STB6100 Silicon Tuner",
  468. .frequency_min = 950000,
  469. .frequency_max = 2150000,
  470. .frequency_step = 0,
  471. },
  472. .init = stb6100_init,
  473. .sleep = stb6100_sleep,
  474. .get_status = stb6100_get_status,
  475. .get_state = stb6100_get_state,
  476. .set_state = stb6100_set_state,
  477. .release = stb6100_release
  478. };
  479. struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe,
  480. const struct stb6100_config *config,
  481. struct i2c_adapter *i2c)
  482. {
  483. struct stb6100_state *state = NULL;
  484. state = kzalloc(sizeof (struct stb6100_state), GFP_KERNEL);
  485. if (state == NULL)
  486. goto error;
  487. state->config = config;
  488. state->i2c = i2c;
  489. state->frontend = fe;
  490. state->reference = config->refclock / 1000; /* kHz */
  491. fe->tuner_priv = state;
  492. fe->ops.tuner_ops = stb6100_ops;
  493. printk("%s: Attaching STB6100 \n", __func__);
  494. return fe;
  495. error:
  496. kfree(state);
  497. return NULL;
  498. }
  499. static int stb6100_release(struct dvb_frontend *fe)
  500. {
  501. struct stb6100_state *state = fe->tuner_priv;
  502. fe->tuner_priv = NULL;
  503. kfree(state);
  504. return 0;
  505. }
  506. EXPORT_SYMBOL(stb6100_attach);
  507. MODULE_PARM_DESC(verbose, "Set Verbosity level");
  508. MODULE_AUTHOR("Manu Abraham");
  509. MODULE_DESCRIPTION("STB6100 Silicon tuner");
  510. MODULE_LICENSE("GPL");