tda80xx.c 17 KB

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