stb6100.c 16 KB

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