au8522.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*
  2. Auvitek AU8522 QAM/8VSB demodulator driver
  3. Copyright (C) 2008 Steven Toth <stoth@linuxtv.org>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <linux/string.h>
  20. #include <linux/slab.h>
  21. #include <linux/delay.h>
  22. #include "dvb_frontend.h"
  23. #include "au8522.h"
  24. struct au8522_state {
  25. struct i2c_adapter *i2c;
  26. /* configuration settings */
  27. const struct au8522_config *config;
  28. struct dvb_frontend frontend;
  29. u32 current_frequency;
  30. fe_modulation_t current_modulation;
  31. };
  32. static int debug;
  33. #define dprintk(arg...) do { \
  34. if (debug) \
  35. printk(arg); \
  36. } while (0)
  37. /* 16 bit registers, 8 bit values */
  38. static int au8522_writereg(struct au8522_state *state, u16 reg, u8 data)
  39. {
  40. int ret;
  41. u8 buf [] = { reg >> 8, reg & 0xff, data };
  42. struct i2c_msg msg = { .addr = state->config->demod_address,
  43. .flags = 0, .buf = buf, .len = 3 };
  44. ret = i2c_transfer(state->i2c, &msg, 1);
  45. if (ret != 1)
  46. printk("%s: writereg error (reg == 0x%02x, val == 0x%04x, "
  47. "ret == %i)\n", __func__, reg, data, ret);
  48. return (ret != 1) ? -1 : 0;
  49. }
  50. static u8 au8522_readreg(struct au8522_state *state, u16 reg)
  51. {
  52. int ret;
  53. u8 b0 [] = { reg >> 8, reg & 0xff };
  54. u8 b1 [] = { 0 };
  55. struct i2c_msg msg [] = {
  56. { .addr = state->config->demod_address, .flags = 0,
  57. .buf = b0, .len = 2 },
  58. { .addr = state->config->demod_address, .flags = I2C_M_RD,
  59. .buf = b1, .len = 1 } };
  60. ret = i2c_transfer(state->i2c, msg, 2);
  61. if (ret != 2)
  62. printk(KERN_ERR "%s: readreg error (ret == %i)\n",
  63. __func__, ret);
  64. return b1[0];
  65. }
  66. static int au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  67. {
  68. struct au8522_state *state = fe->demodulator_priv;
  69. dprintk("%s(%d)\n", __func__, enable);
  70. if (enable)
  71. return au8522_writereg(state, 0x106, 1);
  72. else
  73. return au8522_writereg(state, 0x106, 0);
  74. }
  75. struct mse2snr_tab {
  76. u16 val;
  77. u16 data;
  78. };
  79. /* VSB SNR lookup table */
  80. static struct mse2snr_tab vsb_mse2snr_tab[] = {
  81. { 0, 270 },
  82. { 2, 250 },
  83. { 3, 240 },
  84. { 5, 230 },
  85. { 7, 220 },
  86. { 9, 210 },
  87. { 12, 200 },
  88. { 13, 195 },
  89. { 15, 190 },
  90. { 17, 185 },
  91. { 19, 180 },
  92. { 21, 175 },
  93. { 24, 170 },
  94. { 27, 165 },
  95. { 31, 160 },
  96. { 32, 158 },
  97. { 33, 156 },
  98. { 36, 152 },
  99. { 37, 150 },
  100. { 39, 148 },
  101. { 40, 146 },
  102. { 41, 144 },
  103. { 43, 142 },
  104. { 44, 140 },
  105. { 48, 135 },
  106. { 50, 130 },
  107. { 43, 142 },
  108. { 53, 125 },
  109. { 56, 120 },
  110. { 256, 115 },
  111. };
  112. /* QAM64 SNR lookup table */
  113. static struct mse2snr_tab qam64_mse2snr_tab[] = {
  114. { 15, 0 },
  115. { 16, 290 },
  116. { 17, 288 },
  117. { 18, 286 },
  118. { 19, 284 },
  119. { 20, 282 },
  120. { 21, 281 },
  121. { 22, 279 },
  122. { 23, 277 },
  123. { 24, 275 },
  124. { 25, 273 },
  125. { 26, 271 },
  126. { 27, 269 },
  127. { 28, 268 },
  128. { 29, 266 },
  129. { 30, 264 },
  130. { 31, 262 },
  131. { 32, 260 },
  132. { 33, 259 },
  133. { 34, 258 },
  134. { 35, 256 },
  135. { 36, 255 },
  136. { 37, 254 },
  137. { 38, 252 },
  138. { 39, 251 },
  139. { 40, 250 },
  140. { 41, 249 },
  141. { 42, 248 },
  142. { 43, 246 },
  143. { 44, 245 },
  144. { 45, 244 },
  145. { 46, 242 },
  146. { 47, 241 },
  147. { 48, 240 },
  148. { 50, 239 },
  149. { 51, 238 },
  150. { 53, 237 },
  151. { 54, 236 },
  152. { 56, 235 },
  153. { 57, 234 },
  154. { 59, 233 },
  155. { 60, 232 },
  156. { 62, 231 },
  157. { 63, 230 },
  158. { 65, 229 },
  159. { 67, 228 },
  160. { 68, 227 },
  161. { 70, 226 },
  162. { 71, 225 },
  163. { 73, 224 },
  164. { 74, 223 },
  165. { 76, 222 },
  166. { 78, 221 },
  167. { 80, 220 },
  168. { 82, 219 },
  169. { 85, 218 },
  170. { 88, 217 },
  171. { 90, 216 },
  172. { 92, 215 },
  173. { 93, 214 },
  174. { 94, 212 },
  175. { 95, 211 },
  176. { 97, 210 },
  177. { 99, 209 },
  178. { 101, 208 },
  179. { 102, 207 },
  180. { 104, 206 },
  181. { 107, 205 },
  182. { 111, 204 },
  183. { 114, 203 },
  184. { 118, 202 },
  185. { 122, 201 },
  186. { 125, 200 },
  187. { 128, 199 },
  188. { 130, 198 },
  189. { 132, 197 },
  190. { 256, 190 },
  191. };
  192. /* QAM256 SNR lookup table */
  193. static struct mse2snr_tab qam256_mse2snr_tab[] = {
  194. { 16, 0 },
  195. { 17, 400 },
  196. { 18, 398 },
  197. { 19, 396 },
  198. { 20, 394 },
  199. { 21, 392 },
  200. { 22, 390 },
  201. { 23, 388 },
  202. { 24, 386 },
  203. { 25, 384 },
  204. { 26, 382 },
  205. { 27, 380 },
  206. { 28, 379 },
  207. { 29, 378 },
  208. { 30, 377 },
  209. { 31, 376 },
  210. { 32, 375 },
  211. { 33, 374 },
  212. { 34, 373 },
  213. { 35, 372 },
  214. { 36, 371 },
  215. { 37, 370 },
  216. { 38, 362 },
  217. { 39, 354 },
  218. { 40, 346 },
  219. { 41, 338 },
  220. { 42, 330 },
  221. { 43, 328 },
  222. { 44, 326 },
  223. { 45, 324 },
  224. { 46, 322 },
  225. { 47, 320 },
  226. { 48, 319 },
  227. { 49, 318 },
  228. { 50, 317 },
  229. { 51, 316 },
  230. { 52, 315 },
  231. { 53, 314 },
  232. { 54, 313 },
  233. { 55, 312 },
  234. { 56, 311 },
  235. { 57, 310 },
  236. { 58, 308 },
  237. { 59, 306 },
  238. { 60, 304 },
  239. { 61, 302 },
  240. { 62, 300 },
  241. { 63, 298 },
  242. { 65, 295 },
  243. { 68, 294 },
  244. { 70, 293 },
  245. { 73, 292 },
  246. { 76, 291 },
  247. { 78, 290 },
  248. { 79, 289 },
  249. { 81, 288 },
  250. { 82, 287 },
  251. { 83, 286 },
  252. { 84, 285 },
  253. { 85, 284 },
  254. { 86, 283 },
  255. { 88, 282 },
  256. { 89, 281 },
  257. { 256, 280 },
  258. };
  259. static int au8522_mse2snr_lookup(struct mse2snr_tab *tab, int sz, int mse,
  260. u16 *snr)
  261. {
  262. int i, ret = -EINVAL;
  263. dprintk("%s()\n", __func__);
  264. for (i = 0; i < sz; i++) {
  265. if (mse < tab[i].val) {
  266. *snr = tab[i].data;
  267. ret = 0;
  268. break;
  269. }
  270. }
  271. dprintk("%s() snr=%d\n", __func__, *snr);
  272. return ret;
  273. }
  274. static int au8522_set_if(struct dvb_frontend *fe, enum au8522_if_freq if_freq)
  275. {
  276. struct au8522_state *state = fe->demodulator_priv;
  277. u8 r0b5, r0b6, r0b7;
  278. char *ifmhz;
  279. switch (if_freq) {
  280. case AU8522_IF_3_25MHZ:
  281. ifmhz = "3.25";
  282. r0b5 = 0x00;
  283. r0b6 = 0x3d;
  284. r0b7 = 0xa0;
  285. break;
  286. case AU8522_IF_4MHZ:
  287. ifmhz = "4.00";
  288. r0b5 = 0x00;
  289. r0b6 = 0x4b;
  290. r0b7 = 0xd9;
  291. break;
  292. case AU8522_IF_6MHZ:
  293. ifmhz = "6.00";
  294. r0b5 = 0xfb;
  295. r0b6 = 0x8e;
  296. r0b7 = 0x39;
  297. break;
  298. default:
  299. dprintk("%s() IF Frequency not supported\n", __func__);
  300. return -EINVAL;
  301. }
  302. dprintk("%s() %s MHz\n", __func__, ifmhz);
  303. au8522_writereg(state, 0x80b5, r0b5);
  304. au8522_writereg(state, 0x80b6, r0b6);
  305. au8522_writereg(state, 0x80b7, r0b7);
  306. return 0;
  307. }
  308. /* VSB Modulation table */
  309. static struct {
  310. u16 reg;
  311. u16 data;
  312. } VSB_mod_tab[] = {
  313. { 0x8090, 0x84 },
  314. { 0x4092, 0x11 },
  315. { 0x2005, 0x00 },
  316. { 0x8091, 0x80 },
  317. { 0x80a3, 0x0c },
  318. { 0x80a4, 0xe8 },
  319. { 0x8081, 0xc4 },
  320. { 0x80a5, 0x40 },
  321. { 0x80a7, 0x40 },
  322. { 0x80a6, 0x67 },
  323. { 0x8262, 0x20 },
  324. { 0x821c, 0x30 },
  325. { 0x80d8, 0x1a },
  326. { 0x8227, 0xa0 },
  327. { 0x8121, 0xff },
  328. { 0x80a8, 0xf0 },
  329. { 0x80a9, 0x05 },
  330. { 0x80aa, 0x77 },
  331. { 0x80ab, 0xf0 },
  332. { 0x80ac, 0x05 },
  333. { 0x80ad, 0x77 },
  334. { 0x80ae, 0x41 },
  335. { 0x80af, 0x66 },
  336. { 0x821b, 0xcc },
  337. { 0x821d, 0x80 },
  338. { 0x80a4, 0xe8 },
  339. { 0x8231, 0x13 },
  340. };
  341. /* QAM Modulation table */
  342. static struct {
  343. u16 reg;
  344. u16 data;
  345. } QAM_mod_tab[] = {
  346. { 0x80a3, 0x09 },
  347. { 0x80a4, 0x00 },
  348. { 0x8081, 0xc4 },
  349. { 0x80a5, 0x40 },
  350. { 0x80aa, 0x77 },
  351. { 0x80ad, 0x77 },
  352. { 0x80a6, 0x67 },
  353. { 0x8262, 0x20 },
  354. { 0x821c, 0x30 },
  355. { 0x80b8, 0x3e },
  356. { 0x80b9, 0xf0 },
  357. { 0x80ba, 0x01 },
  358. { 0x80bb, 0x18 },
  359. { 0x80bc, 0x50 },
  360. { 0x80bd, 0x00 },
  361. { 0x80be, 0xea },
  362. { 0x80bf, 0xef },
  363. { 0x80c0, 0xfc },
  364. { 0x80c1, 0xbd },
  365. { 0x80c2, 0x1f },
  366. { 0x80c3, 0xfc },
  367. { 0x80c4, 0xdd },
  368. { 0x80c5, 0xaf },
  369. { 0x80c6, 0x00 },
  370. { 0x80c7, 0x38 },
  371. { 0x80c8, 0x30 },
  372. { 0x80c9, 0x05 },
  373. { 0x80ca, 0x4a },
  374. { 0x80cb, 0xd0 },
  375. { 0x80cc, 0x01 },
  376. { 0x80cd, 0xd9 },
  377. { 0x80ce, 0x6f },
  378. { 0x80cf, 0xf9 },
  379. { 0x80d0, 0x70 },
  380. { 0x80d1, 0xdf },
  381. { 0x80d2, 0xf7 },
  382. { 0x80d3, 0xc2 },
  383. { 0x80d4, 0xdf },
  384. { 0x80d5, 0x02 },
  385. { 0x80d6, 0x9a },
  386. { 0x80d7, 0xd0 },
  387. { 0x8250, 0x0d },
  388. { 0x8251, 0xcd },
  389. { 0x8252, 0xe0 },
  390. { 0x8253, 0x05 },
  391. { 0x8254, 0xa7 },
  392. { 0x8255, 0xff },
  393. { 0x8256, 0xed },
  394. { 0x8257, 0x5b },
  395. { 0x8258, 0xae },
  396. { 0x8259, 0xe6 },
  397. { 0x825a, 0x3d },
  398. { 0x825b, 0x0f },
  399. { 0x825c, 0x0d },
  400. { 0x825d, 0xea },
  401. { 0x825e, 0xf2 },
  402. { 0x825f, 0x51 },
  403. { 0x8260, 0xf5 },
  404. { 0x8261, 0x06 },
  405. { 0x821a, 0x00 },
  406. { 0x8546, 0x40 },
  407. { 0x8210, 0x26 },
  408. { 0x8211, 0xf6 },
  409. { 0x8212, 0x84 },
  410. { 0x8213, 0x02 },
  411. { 0x8502, 0x01 },
  412. { 0x8121, 0x04 },
  413. { 0x8122, 0x04 },
  414. { 0x852e, 0x10 },
  415. { 0x80a4, 0xca },
  416. { 0x80a7, 0x40 },
  417. { 0x8526, 0x01 },
  418. };
  419. static int au8522_enable_modulation(struct dvb_frontend *fe,
  420. fe_modulation_t m)
  421. {
  422. struct au8522_state *state = fe->demodulator_priv;
  423. int i;
  424. dprintk("%s(0x%08x)\n", __func__, m);
  425. switch (m) {
  426. case VSB_8:
  427. dprintk("%s() VSB_8\n", __func__);
  428. for (i = 0; i < ARRAY_SIZE(VSB_mod_tab); i++)
  429. au8522_writereg(state,
  430. VSB_mod_tab[i].reg,
  431. VSB_mod_tab[i].data);
  432. au8522_set_if(fe, state->config->vsb_if);
  433. break;
  434. case QAM_64:
  435. case QAM_256:
  436. dprintk("%s() QAM 64/256\n", __func__);
  437. for (i = 0; i < ARRAY_SIZE(QAM_mod_tab); i++)
  438. au8522_writereg(state,
  439. QAM_mod_tab[i].reg,
  440. QAM_mod_tab[i].data);
  441. au8522_set_if(fe, state->config->qam_if);
  442. break;
  443. default:
  444. dprintk("%s() Invalid modulation\n", __func__);
  445. return -EINVAL;
  446. }
  447. state->current_modulation = m;
  448. return 0;
  449. }
  450. /* Talk to the demod, set the FEC, GUARD, QAM settings etc */
  451. static int au8522_set_frontend(struct dvb_frontend *fe,
  452. struct dvb_frontend_parameters *p)
  453. {
  454. struct au8522_state *state = fe->demodulator_priv;
  455. int ret = -EINVAL;
  456. dprintk("%s(frequency=%d)\n", __func__, p->frequency);
  457. if ((state->current_frequency == p->frequency) &&
  458. (state->current_modulation == p->u.vsb.modulation))
  459. return 0;
  460. au8522_enable_modulation(fe, p->u.vsb.modulation);
  461. /* Allow the demod to settle */
  462. msleep(100);
  463. if (fe->ops.tuner_ops.set_params) {
  464. if (fe->ops.i2c_gate_ctrl)
  465. fe->ops.i2c_gate_ctrl(fe, 1);
  466. ret = fe->ops.tuner_ops.set_params(fe, p);
  467. if (fe->ops.i2c_gate_ctrl)
  468. fe->ops.i2c_gate_ctrl(fe, 0);
  469. }
  470. if (ret < 0)
  471. return ret;
  472. state->current_frequency = p->frequency;
  473. return 0;
  474. }
  475. /* Reset the demod hardware and reset all of the configuration registers
  476. to a default state. */
  477. static int au8522_init(struct dvb_frontend *fe)
  478. {
  479. struct au8522_state *state = fe->demodulator_priv;
  480. dprintk("%s()\n", __func__);
  481. au8522_writereg(state, 0xa4, 1 << 5);
  482. au8522_i2c_gate_ctrl(fe, 1);
  483. return 0;
  484. }
  485. static int au8522_sleep(struct dvb_frontend *fe)
  486. {
  487. struct au8522_state *state = fe->demodulator_priv;
  488. dprintk("%s()\n", __func__);
  489. state->current_frequency = 0;
  490. return 0;
  491. }
  492. static int au8522_read_status(struct dvb_frontend *fe, fe_status_t *status)
  493. {
  494. struct au8522_state *state = fe->demodulator_priv;
  495. u8 reg;
  496. u32 tuner_status = 0;
  497. *status = 0;
  498. if (state->current_modulation == VSB_8) {
  499. dprintk("%s() Checking VSB_8\n", __func__);
  500. reg = au8522_readreg(state, 0x4088);
  501. if ((reg & 0x03) == 0x03)
  502. *status |= FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI;
  503. } else {
  504. dprintk("%s() Checking QAM\n", __func__);
  505. reg = au8522_readreg(state, 0x4541);
  506. if (reg & 0x80)
  507. *status |= FE_HAS_VITERBI;
  508. if (reg & 0x20)
  509. *status |= FE_HAS_LOCK | FE_HAS_SYNC;
  510. }
  511. switch (state->config->status_mode) {
  512. case AU8522_DEMODLOCKING:
  513. dprintk("%s() DEMODLOCKING\n", __func__);
  514. if (*status & FE_HAS_VITERBI)
  515. *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
  516. break;
  517. case AU8522_TUNERLOCKING:
  518. /* Get the tuner status */
  519. dprintk("%s() TUNERLOCKING\n", __func__);
  520. if (fe->ops.tuner_ops.get_status) {
  521. if (fe->ops.i2c_gate_ctrl)
  522. fe->ops.i2c_gate_ctrl(fe, 1);
  523. fe->ops.tuner_ops.get_status(fe, &tuner_status);
  524. if (fe->ops.i2c_gate_ctrl)
  525. fe->ops.i2c_gate_ctrl(fe, 0);
  526. }
  527. if (tuner_status)
  528. *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
  529. break;
  530. }
  531. dprintk("%s() status 0x%08x\n", __func__, *status);
  532. return 0;
  533. }
  534. static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr)
  535. {
  536. struct au8522_state *state = fe->demodulator_priv;
  537. int ret = -EINVAL;
  538. dprintk("%s()\n", __func__);
  539. if (state->current_modulation == QAM_256)
  540. ret = au8522_mse2snr_lookup(qam256_mse2snr_tab,
  541. ARRAY_SIZE(qam256_mse2snr_tab),
  542. au8522_readreg(state, 0x4522),
  543. snr);
  544. else if (state->current_modulation == QAM_64)
  545. ret = au8522_mse2snr_lookup(qam64_mse2snr_tab,
  546. ARRAY_SIZE(qam64_mse2snr_tab),
  547. au8522_readreg(state, 0x4522),
  548. snr);
  549. else /* VSB_8 */
  550. ret = au8522_mse2snr_lookup(vsb_mse2snr_tab,
  551. ARRAY_SIZE(vsb_mse2snr_tab),
  552. au8522_readreg(state, 0x4311),
  553. snr);
  554. return ret;
  555. }
  556. static int au8522_read_signal_strength(struct dvb_frontend *fe,
  557. u16 *signal_strength)
  558. {
  559. return au8522_read_snr(fe, signal_strength);
  560. }
  561. static int au8522_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
  562. {
  563. struct au8522_state *state = fe->demodulator_priv;
  564. if (state->current_modulation == VSB_8)
  565. *ucblocks = au8522_readreg(state, 0x4087);
  566. else
  567. *ucblocks = au8522_readreg(state, 0x4543);
  568. return 0;
  569. }
  570. static int au8522_read_ber(struct dvb_frontend *fe, u32 *ber)
  571. {
  572. return au8522_read_ucblocks(fe, ber);
  573. }
  574. static int au8522_get_frontend(struct dvb_frontend *fe,
  575. struct dvb_frontend_parameters *p)
  576. {
  577. struct au8522_state *state = fe->demodulator_priv;
  578. p->frequency = state->current_frequency;
  579. p->u.vsb.modulation = state->current_modulation;
  580. return 0;
  581. }
  582. static int au8522_get_tune_settings(struct dvb_frontend *fe,
  583. struct dvb_frontend_tune_settings *tune)
  584. {
  585. tune->min_delay_ms = 1000;
  586. return 0;
  587. }
  588. static void au8522_release(struct dvb_frontend *fe)
  589. {
  590. struct au8522_state *state = fe->demodulator_priv;
  591. kfree(state);
  592. }
  593. static struct dvb_frontend_ops au8522_ops;
  594. struct dvb_frontend *au8522_attach(const struct au8522_config *config,
  595. struct i2c_adapter *i2c)
  596. {
  597. struct au8522_state *state = NULL;
  598. /* allocate memory for the internal state */
  599. state = kmalloc(sizeof(struct au8522_state), GFP_KERNEL);
  600. if (state == NULL)
  601. goto error;
  602. /* setup the state */
  603. state->config = config;
  604. state->i2c = i2c;
  605. /* create dvb_frontend */
  606. memcpy(&state->frontend.ops, &au8522_ops,
  607. sizeof(struct dvb_frontend_ops));
  608. state->frontend.demodulator_priv = state;
  609. if (au8522_init(&state->frontend) != 0) {
  610. printk(KERN_ERR "%s: Failed to initialize correctly\n",
  611. __func__);
  612. goto error;
  613. }
  614. /* Note: Leaving the I2C gate open here. */
  615. au8522_i2c_gate_ctrl(&state->frontend, 1);
  616. return &state->frontend;
  617. error:
  618. kfree(state);
  619. return NULL;
  620. }
  621. EXPORT_SYMBOL(au8522_attach);
  622. static struct dvb_frontend_ops au8522_ops = {
  623. .info = {
  624. .name = "Auvitek AU8522 QAM/8VSB Frontend",
  625. .type = FE_ATSC,
  626. .frequency_min = 54000000,
  627. .frequency_max = 858000000,
  628. .frequency_stepsize = 62500,
  629. .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
  630. },
  631. .init = au8522_init,
  632. .sleep = au8522_sleep,
  633. .i2c_gate_ctrl = au8522_i2c_gate_ctrl,
  634. .set_frontend = au8522_set_frontend,
  635. .get_frontend = au8522_get_frontend,
  636. .get_tune_settings = au8522_get_tune_settings,
  637. .read_status = au8522_read_status,
  638. .read_ber = au8522_read_ber,
  639. .read_signal_strength = au8522_read_signal_strength,
  640. .read_snr = au8522_read_snr,
  641. .read_ucblocks = au8522_read_ucblocks,
  642. .release = au8522_release,
  643. };
  644. module_param(debug, int, 0644);
  645. MODULE_PARM_DESC(debug, "Enable verbose debug messages");
  646. MODULE_DESCRIPTION("Auvitek AU8522 QAM-B/ATSC Demodulator driver");
  647. MODULE_AUTHOR("Steven Toth");
  648. MODULE_LICENSE("GPL");