tda80xx.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /*
  2. * tda80xx.c
  3. *
  4. * Philips TDA8044 / TDA8083 QPSK demodulator driver
  5. *
  6. * Copyright (C) 2001 Felix Domke <tmbinc@elitedvb.net>
  7. * Copyright (C) 2002-2004 Andreas Oberritter <obi@linuxtv.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <linux/config.h>
  24. #include <linux/delay.h>
  25. #include <linux/init.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/threads.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/slab.h>
  32. #include <asm/div64.h>
  33. #include "dvb_frontend.h"
  34. #include "tda80xx.h"
  35. enum {
  36. ID_TDA8044 = 0x04,
  37. ID_TDA8083 = 0x05,
  38. };
  39. struct tda80xx_state {
  40. struct i2c_adapter* i2c;
  41. struct dvb_frontend_ops ops;
  42. /* configuration settings */
  43. const struct tda80xx_config* config;
  44. struct dvb_frontend frontend;
  45. u32 clk;
  46. int afc_loop;
  47. struct work_struct worklet;
  48. fe_code_rate_t code_rate;
  49. fe_spectral_inversion_t spectral_inversion;
  50. fe_status_t status;
  51. u8 id;
  52. };
  53. static int debug = 1;
  54. #define dprintk if (debug) printk
  55. static u8 tda8044_inittab_pre[] = {
  56. 0x02, 0x00, 0x6f, 0xb5, 0x86, 0x22, 0x00, 0xea,
  57. 0x30, 0x42, 0x98, 0x68, 0x70, 0x42, 0x99, 0x58,
  58. 0x95, 0x10, 0xf5, 0xe7, 0x93, 0x0b, 0x15, 0x68,
  59. 0x9a, 0x90, 0x61, 0x80, 0x00, 0xe0, 0x40, 0x00,
  60. 0x0f, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  61. 0x00, 0x00
  62. };
  63. static u8 tda8044_inittab_post[] = {
  64. 0x04, 0x00, 0x6f, 0xb5, 0x86, 0x22, 0x00, 0xea,
  65. 0x30, 0x42, 0x98, 0x68, 0x70, 0x42, 0x99, 0x50,
  66. 0x95, 0x10, 0xf5, 0xe7, 0x93, 0x0b, 0x15, 0x68,
  67. 0x9a, 0x90, 0x61, 0x80, 0x00, 0xe0, 0x40, 0x6c,
  68. 0x0f, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  69. 0x00, 0x00
  70. };
  71. static u8 tda8083_inittab[] = {
  72. 0x04, 0x00, 0x4a, 0x79, 0x04, 0x00, 0xff, 0xea,
  73. 0x48, 0x42, 0x79, 0x60, 0x70, 0x52, 0x9a, 0x10,
  74. 0x0e, 0x10, 0xf2, 0xa7, 0x93, 0x0b, 0x05, 0xc8,
  75. 0x9d, 0x00, 0x42, 0x80, 0x00, 0x60, 0x40, 0x00,
  76. 0x00, 0x75, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00,
  77. 0x00, 0x00, 0x00, 0x00
  78. };
  79. static __inline__ u32 tda80xx_div(u32 a, u32 b)
  80. {
  81. return (a + (b / 2)) / b;
  82. }
  83. static __inline__ u32 tda80xx_gcd(u32 a, u32 b)
  84. {
  85. u32 r;
  86. while ((r = a % b)) {
  87. a = b;
  88. b = r;
  89. }
  90. return b;
  91. }
  92. static int tda80xx_read(struct tda80xx_state* state, u8 reg, u8 *buf, u8 len)
  93. {
  94. int ret;
  95. struct i2c_msg msg[] = { { .addr = state->config->demod_address, .flags = 0, .buf = &reg, .len = 1 },
  96. { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = buf, .len = len } };
  97. ret = i2c_transfer(state->i2c, msg, 2);
  98. if (ret != 2)
  99. dprintk("%s: readreg error (reg %02x, ret == %i)\n",
  100. __FUNCTION__, reg, ret);
  101. mdelay(10);
  102. return (ret == 2) ? 0 : -EREMOTEIO;
  103. }
  104. static int tda80xx_write(struct tda80xx_state* state, u8 reg, const u8 *buf, u8 len)
  105. {
  106. int ret;
  107. u8 wbuf[len + 1];
  108. struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = wbuf, .len = len + 1 };
  109. wbuf[0] = reg;
  110. memcpy(&wbuf[1], buf, len);
  111. ret = i2c_transfer(state->i2c, &msg, 1);
  112. if (ret != 1)
  113. dprintk("%s: i2c xfer error (ret == %i)\n", __FUNCTION__, ret);
  114. mdelay(10);
  115. return (ret == 1) ? 0 : -EREMOTEIO;
  116. }
  117. static __inline__ u8 tda80xx_readreg(struct tda80xx_state* state, u8 reg)
  118. {
  119. u8 val;
  120. tda80xx_read(state, reg, &val, 1);
  121. return val;
  122. }
  123. static __inline__ int tda80xx_writereg(struct tda80xx_state* state, u8 reg, u8 data)
  124. {
  125. return tda80xx_write(state, reg, &data, 1);
  126. }
  127. static int tda80xx_set_parameters(struct tda80xx_state* state,
  128. fe_spectral_inversion_t inversion,
  129. u32 symbol_rate,
  130. fe_code_rate_t fec_inner)
  131. {
  132. u8 buf[15];
  133. u64 ratio;
  134. u32 clk;
  135. u32 k;
  136. u32 sr = symbol_rate;
  137. u32 gcd;
  138. u8 scd;
  139. if (symbol_rate > (state->clk * 3) / 16)
  140. scd = 0;
  141. else if (symbol_rate > (state->clk * 3) / 32)
  142. scd = 1;
  143. else if (symbol_rate > (state->clk * 3) / 64)
  144. scd = 2;
  145. else
  146. scd = 3;
  147. clk = scd ? (state->clk / (scd * 2)) : state->clk;
  148. /*
  149. * Viterbi decoder:
  150. * Differential decoding off
  151. * Spectral inversion unknown
  152. * QPSK modulation
  153. */
  154. if (inversion == INVERSION_ON)
  155. buf[0] = 0x60;
  156. else if (inversion == INVERSION_OFF)
  157. buf[0] = 0x20;
  158. else
  159. buf[0] = 0x00;
  160. /*
  161. * CLK ratio:
  162. * system clock frequency is up to 64 or 96 MHz
  163. *
  164. * formula:
  165. * r = k * clk / symbol_rate
  166. *
  167. * k: 2^21 for caa 0..3,
  168. * 2^20 for caa 4..5,
  169. * 2^19 for caa 6..7
  170. */
  171. if (symbol_rate <= (clk * 3) / 32)
  172. k = (1 << 19);
  173. else if (symbol_rate <= (clk * 3) / 16)
  174. k = (1 << 20);
  175. else
  176. k = (1 << 21);
  177. gcd = tda80xx_gcd(clk, sr);
  178. clk /= gcd;
  179. sr /= gcd;
  180. gcd = tda80xx_gcd(k, sr);
  181. k /= gcd;
  182. sr /= gcd;
  183. ratio = (u64)k * (u64)clk;
  184. do_div(ratio, sr);
  185. buf[1] = ratio >> 16;
  186. buf[2] = ratio >> 8;
  187. buf[3] = ratio;
  188. /* nyquist filter roll-off factor 35% */
  189. buf[4] = 0x20;
  190. clk = scd ? (state->clk / (scd * 2)) : state->clk;
  191. /* Anti Alias Filter */
  192. if (symbol_rate < (clk * 3) / 64)
  193. printk("tda80xx: unsupported symbol rate: %u\n", symbol_rate);
  194. else if (symbol_rate <= clk / 16)
  195. buf[4] |= 0x07;
  196. else if (symbol_rate <= (clk * 3) / 32)
  197. buf[4] |= 0x06;
  198. else if (symbol_rate <= clk / 8)
  199. buf[4] |= 0x05;
  200. else if (symbol_rate <= (clk * 3) / 16)
  201. buf[4] |= 0x04;
  202. else if (symbol_rate <= clk / 4)
  203. buf[4] |= 0x03;
  204. else if (symbol_rate <= (clk * 3) / 8)
  205. buf[4] |= 0x02;
  206. else if (symbol_rate <= clk / 2)
  207. buf[4] |= 0x01;
  208. else
  209. buf[4] |= 0x00;
  210. /* Sigma Delta converter */
  211. buf[5] = 0x00;
  212. /* FEC: Possible puncturing rates */
  213. if (fec_inner == FEC_NONE)
  214. buf[6] = 0x00;
  215. else if ((fec_inner >= FEC_1_2) && (fec_inner <= FEC_8_9))
  216. buf[6] = (1 << (8 - fec_inner));
  217. else if (fec_inner == FEC_AUTO)
  218. buf[6] = 0xff;
  219. else
  220. return -EINVAL;
  221. /* carrier lock detector threshold value */
  222. buf[7] = 0x30;
  223. /* AFC1: proportional part settings */
  224. buf[8] = 0x42;
  225. /* AFC1: integral part settings */
  226. buf[9] = 0x98;
  227. /* PD: Leaky integrator SCPC mode */
  228. buf[10] = 0x28;
  229. /* AFC2, AFC1 controls */
  230. buf[11] = 0x30;
  231. /* PD: proportional part settings */
  232. buf[12] = 0x42;
  233. /* PD: integral part settings */
  234. buf[13] = 0x99;
  235. /* AGC */
  236. buf[14] = 0x50 | scd;
  237. printk("symbol_rate=%u clk=%u\n", symbol_rate, clk);
  238. return tda80xx_write(state, 0x01, buf, sizeof(buf));
  239. }
  240. static int tda80xx_set_clk(struct tda80xx_state* state)
  241. {
  242. u8 buf[2];
  243. /* CLK proportional part */
  244. buf[0] = (0x06 << 5) | 0x08; /* CMP[2:0], CSP[4:0] */
  245. /* CLK integral part */
  246. buf[1] = (0x04 << 5) | 0x1a; /* CMI[2:0], CSI[4:0] */
  247. return tda80xx_write(state, 0x17, buf, sizeof(buf));
  248. }
  249. #if 0
  250. static int tda80xx_set_scpc_freq_offset(struct tda80xx_state* state)
  251. {
  252. /* a constant value is nonsense here imho */
  253. return tda80xx_writereg(state, 0x22, 0xf9);
  254. }
  255. #endif
  256. static int tda80xx_close_loop(struct tda80xx_state* state)
  257. {
  258. u8 buf[2];
  259. /* PD: Loop closed, LD: lock detect enable, SCPC: Sweep mode - AFC1 loop closed */
  260. buf[0] = 0x68;
  261. /* AFC1: Loop closed, CAR Feedback: 8192 */
  262. buf[1] = 0x70;
  263. return tda80xx_write(state, 0x0b, buf, sizeof(buf));
  264. }
  265. static irqreturn_t tda80xx_irq(int irq, void *priv, struct pt_regs *pt)
  266. {
  267. schedule_work(priv);
  268. return IRQ_HANDLED;
  269. }
  270. static void tda80xx_read_status_int(struct tda80xx_state* state)
  271. {
  272. u8 val;
  273. static const fe_spectral_inversion_t inv_tab[] = {
  274. INVERSION_OFF, INVERSION_ON
  275. };
  276. static const fe_code_rate_t fec_tab[] = {
  277. FEC_8_9, FEC_1_2, FEC_2_3, FEC_3_4,
  278. FEC_4_5, FEC_5_6, FEC_6_7, FEC_7_8,
  279. };
  280. val = tda80xx_readreg(state, 0x02);
  281. state->status = 0;
  282. if (val & 0x01) /* demodulator lock */
  283. state->status |= FE_HAS_SIGNAL;
  284. if (val & 0x02) /* clock recovery lock */
  285. state->status |= FE_HAS_CARRIER;
  286. if (val & 0x04) /* viterbi lock */
  287. state->status |= FE_HAS_VITERBI;
  288. if (val & 0x08) /* deinterleaver lock (packet sync) */
  289. state->status |= FE_HAS_SYNC;
  290. if (val & 0x10) /* derandomizer lock (frame sync) */
  291. state->status |= FE_HAS_LOCK;
  292. if (val & 0x20) /* frontend can not lock */
  293. state->status |= FE_TIMEDOUT;
  294. if ((state->status & (FE_HAS_CARRIER)) && (state->afc_loop)) {
  295. printk("tda80xx: closing loop\n");
  296. tda80xx_close_loop(state);
  297. state->afc_loop = 0;
  298. }
  299. if (state->status & (FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK)) {
  300. val = tda80xx_readreg(state, 0x0e);
  301. state->code_rate = fec_tab[val & 0x07];
  302. if (state->status & (FE_HAS_SYNC | FE_HAS_LOCK))
  303. state->spectral_inversion = inv_tab[(val >> 7) & 0x01];
  304. else
  305. state->spectral_inversion = INVERSION_AUTO;
  306. }
  307. else {
  308. state->code_rate = FEC_AUTO;
  309. }
  310. }
  311. static void tda80xx_worklet(void *priv)
  312. {
  313. struct tda80xx_state *state = priv;
  314. tda80xx_writereg(state, 0x00, 0x04);
  315. enable_irq(state->config->irq);
  316. tda80xx_read_status_int(state);
  317. }
  318. static void tda80xx_wait_diseqc_fifo(struct tda80xx_state* state)
  319. {
  320. size_t i;
  321. for (i = 0; i < 100; i++) {
  322. if (tda80xx_readreg(state, 0x02) & 0x80)
  323. break;
  324. msleep(10);
  325. }
  326. }
  327. static int tda8044_init(struct dvb_frontend* fe)
  328. {
  329. struct tda80xx_state* state = fe->demodulator_priv;
  330. int ret;
  331. /*
  332. * this function is a mess...
  333. */
  334. if ((ret = tda80xx_write(state, 0x00, tda8044_inittab_pre, sizeof(tda8044_inittab_pre))))
  335. return ret;
  336. tda80xx_writereg(state, 0x0f, 0x50);
  337. #if 1
  338. tda80xx_writereg(state, 0x20, 0x8F); /* FIXME */
  339. tda80xx_writereg(state, 0x20, state->config->volt18setting); /* FIXME */
  340. //tda80xx_writereg(state, 0x00, 0x04);
  341. tda80xx_writereg(state, 0x00, 0x0C);
  342. #endif
  343. //tda80xx_writereg(state, 0x00, 0x08); /* Reset AFC1 loop filter */
  344. tda80xx_write(state, 0x00, tda8044_inittab_post, sizeof(tda8044_inittab_post));
  345. if (state->config->pll_init) {
  346. tda80xx_writereg(state, 0x1c, 0x80);
  347. state->config->pll_init(fe);
  348. tda80xx_writereg(state, 0x1c, 0x00);
  349. }
  350. return 0;
  351. }
  352. static int tda8083_init(struct dvb_frontend* fe)
  353. {
  354. struct tda80xx_state* state = fe->demodulator_priv;
  355. tda80xx_write(state, 0x00, tda8083_inittab, sizeof(tda8083_inittab));
  356. if (state->config->pll_init) {
  357. tda80xx_writereg(state, 0x1c, 0x80);
  358. state->config->pll_init(fe);
  359. tda80xx_writereg(state, 0x1c, 0x00);
  360. }
  361. return 0;
  362. }
  363. static int tda80xx_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  364. {
  365. struct tda80xx_state* state = fe->demodulator_priv;
  366. switch (voltage) {
  367. case SEC_VOLTAGE_13:
  368. return tda80xx_writereg(state, 0x20, state->config->volt13setting);
  369. case SEC_VOLTAGE_18:
  370. return tda80xx_writereg(state, 0x20, state->config->volt18setting);
  371. case SEC_VOLTAGE_OFF:
  372. return tda80xx_writereg(state, 0x20, 0);
  373. default:
  374. return -EINVAL;
  375. }
  376. }
  377. static int tda80xx_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  378. {
  379. struct tda80xx_state* state = fe->demodulator_priv;
  380. switch (tone) {
  381. case SEC_TONE_OFF:
  382. return tda80xx_writereg(state, 0x29, 0x00);
  383. case SEC_TONE_ON:
  384. return tda80xx_writereg(state, 0x29, 0x80);
  385. default:
  386. return -EINVAL;
  387. }
  388. }
  389. static int tda80xx_send_diseqc_msg(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
  390. {
  391. struct tda80xx_state* state = fe->demodulator_priv;
  392. if (cmd->msg_len > 6)
  393. return -EINVAL;
  394. tda80xx_writereg(state, 0x29, 0x08 | (cmd->msg_len - 3));
  395. tda80xx_write(state, 0x23, cmd->msg, cmd->msg_len);
  396. tda80xx_writereg(state, 0x29, 0x0c | (cmd->msg_len - 3));
  397. tda80xx_wait_diseqc_fifo(state);
  398. return 0;
  399. }
  400. static int tda80xx_send_diseqc_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t cmd)
  401. {
  402. struct tda80xx_state* state = fe->demodulator_priv;
  403. switch (cmd) {
  404. case SEC_MINI_A:
  405. tda80xx_writereg(state, 0x29, 0x14);
  406. break;
  407. case SEC_MINI_B:
  408. tda80xx_writereg(state, 0x29, 0x1c);
  409. break;
  410. default:
  411. return -EINVAL;
  412. }
  413. tda80xx_wait_diseqc_fifo(state);
  414. return 0;
  415. }
  416. static int tda80xx_sleep(struct dvb_frontend* fe)
  417. {
  418. struct tda80xx_state* state = fe->demodulator_priv;
  419. tda80xx_writereg(state, 0x00, 0x02); /* enter standby */
  420. return 0;
  421. }
  422. static int tda80xx_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  423. {
  424. struct tda80xx_state* state = fe->demodulator_priv;
  425. tda80xx_writereg(state, 0x1c, 0x80);
  426. state->config->pll_set(fe, p);
  427. tda80xx_writereg(state, 0x1c, 0x00);
  428. tda80xx_set_parameters(state, p->inversion, p->u.qpsk.symbol_rate, p->u.qpsk.fec_inner);
  429. tda80xx_set_clk(state);
  430. //tda80xx_set_scpc_freq_offset(state);
  431. state->afc_loop = 1;
  432. return 0;
  433. }
  434. static int tda80xx_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  435. {
  436. struct tda80xx_state* state = fe->demodulator_priv;
  437. if (!state->config->irq)
  438. tda80xx_read_status_int(state);
  439. p->inversion = state->spectral_inversion;
  440. p->u.qpsk.fec_inner = state->code_rate;
  441. return 0;
  442. }
  443. static int tda80xx_read_status(struct dvb_frontend* fe, fe_status_t* status)
  444. {
  445. struct tda80xx_state* state = fe->demodulator_priv;
  446. if (!state->config->irq)
  447. tda80xx_read_status_int(state);
  448. *status = state->status;
  449. return 0;
  450. }
  451. static int tda80xx_read_ber(struct dvb_frontend* fe, u32* ber)
  452. {
  453. struct tda80xx_state* state = fe->demodulator_priv;
  454. int ret;
  455. u8 buf[3];
  456. if ((ret = tda80xx_read(state, 0x0b, buf, sizeof(buf))))
  457. return ret;
  458. *ber = ((buf[0] & 0x1f) << 16) | (buf[1] << 8) | buf[2];
  459. return 0;
  460. }
  461. static int tda80xx_read_signal_strength(struct dvb_frontend* fe, u16* strength)
  462. {
  463. struct tda80xx_state* state = fe->demodulator_priv;
  464. u8 gain = ~tda80xx_readreg(state, 0x01);
  465. *strength = (gain << 8) | gain;
  466. return 0;
  467. }
  468. static int tda80xx_read_snr(struct dvb_frontend* fe, u16* snr)
  469. {
  470. struct tda80xx_state* state = fe->demodulator_priv;
  471. u8 quality = tda80xx_readreg(state, 0x08);
  472. *snr = (quality << 8) | quality;
  473. return 0;
  474. }
  475. static int tda80xx_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
  476. {
  477. struct tda80xx_state* state = fe->demodulator_priv;
  478. *ucblocks = tda80xx_readreg(state, 0x0f);
  479. if (*ucblocks == 0xff)
  480. *ucblocks = 0xffffffff;
  481. return 0;
  482. }
  483. static int tda80xx_init(struct dvb_frontend* fe)
  484. {
  485. struct tda80xx_state* state = fe->demodulator_priv;
  486. switch(state->id) {
  487. case ID_TDA8044:
  488. return tda8044_init(fe);
  489. case ID_TDA8083:
  490. return tda8083_init(fe);
  491. }
  492. return 0;
  493. }
  494. static void tda80xx_release(struct dvb_frontend* fe)
  495. {
  496. struct tda80xx_state* state = fe->demodulator_priv;
  497. if (state->config->irq)
  498. free_irq(state->config->irq, &state->worklet);
  499. kfree(state);
  500. }
  501. static struct dvb_frontend_ops tda80xx_ops;
  502. struct dvb_frontend* tda80xx_attach(const struct tda80xx_config* config,
  503. struct i2c_adapter* i2c)
  504. {
  505. struct tda80xx_state* state = NULL;
  506. int ret;
  507. /* allocate memory for the internal state */
  508. state = kmalloc(sizeof(struct tda80xx_state), GFP_KERNEL);
  509. if (state == NULL) goto error;
  510. /* setup the state */
  511. state->config = config;
  512. state->i2c = i2c;
  513. memcpy(&state->ops, &tda80xx_ops, sizeof(struct dvb_frontend_ops));
  514. state->spectral_inversion = INVERSION_AUTO;
  515. state->code_rate = FEC_AUTO;
  516. state->status = 0;
  517. state->afc_loop = 0;
  518. /* check if the demod is there */
  519. if (tda80xx_writereg(state, 0x89, 0x00) < 0) goto error;
  520. state->id = tda80xx_readreg(state, 0x00);
  521. switch (state->id) {
  522. case ID_TDA8044:
  523. state->clk = 96000000;
  524. printk("tda80xx: Detected tda8044\n");
  525. break;
  526. case ID_TDA8083:
  527. state->clk = 64000000;
  528. printk("tda80xx: Detected tda8083\n");
  529. break;
  530. default:
  531. goto error;
  532. }
  533. /* setup IRQ */
  534. if (state->config->irq) {
  535. INIT_WORK(&state->worklet, tda80xx_worklet, state);
  536. if ((ret = request_irq(state->config->irq, tda80xx_irq, SA_ONESHOT, "tda80xx", &state->worklet)) < 0) {
  537. printk(KERN_ERR "tda80xx: request_irq failed (%d)\n", ret);
  538. goto error;
  539. }
  540. }
  541. /* create dvb_frontend */
  542. state->frontend.ops = &state->ops;
  543. state->frontend.demodulator_priv = state;
  544. return &state->frontend;
  545. error:
  546. kfree(state);
  547. return NULL;
  548. }
  549. static struct dvb_frontend_ops tda80xx_ops = {
  550. .info = {
  551. .name = "Philips TDA80xx DVB-S",
  552. .type = FE_QPSK,
  553. .frequency_min = 500000,
  554. .frequency_max = 2700000,
  555. .frequency_stepsize = 125,
  556. .symbol_rate_min = 4500000,
  557. .symbol_rate_max = 45000000,
  558. .caps = FE_CAN_INVERSION_AUTO |
  559. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  560. FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
  561. FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO |
  562. FE_CAN_QPSK |
  563. FE_CAN_MUTE_TS
  564. },
  565. .release = tda80xx_release,
  566. .init = tda80xx_init,
  567. .sleep = tda80xx_sleep,
  568. .set_frontend = tda80xx_set_frontend,
  569. .get_frontend = tda80xx_get_frontend,
  570. .read_status = tda80xx_read_status,
  571. .read_ber = tda80xx_read_ber,
  572. .read_signal_strength = tda80xx_read_signal_strength,
  573. .read_snr = tda80xx_read_snr,
  574. .read_ucblocks = tda80xx_read_ucblocks,
  575. .diseqc_send_master_cmd = tda80xx_send_diseqc_msg,
  576. .diseqc_send_burst = tda80xx_send_diseqc_burst,
  577. .set_tone = tda80xx_set_tone,
  578. .set_voltage = tda80xx_set_voltage,
  579. };
  580. module_param(debug, int, 0644);
  581. MODULE_DESCRIPTION("Philips TDA8044 / TDA8083 DVB-S Demodulator driver");
  582. MODULE_AUTHOR("Felix Domke, Andreas Oberritter");
  583. MODULE_LICENSE("GPL");
  584. EXPORT_SYMBOL(tda80xx_attach);