or51132.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Support for OR51132 (pcHDTV HD-3000) - VSB/QAM
  3. *
  4. * Copyright (C) 2005 Kirk Lapray <kirk_lapray@bigfoot.com>
  5. *
  6. * Based on code from Jack Kelliher (kelliher@xmission.com)
  7. * Copyright (C) 2002 & pcHDTV, inc.
  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. */
  24. /*
  25. * This driver needs two external firmware files. Please copy
  26. * "dvb-fe-or51132-vsb.fw" and "dvb-fe-or51132-qam.fw" to
  27. * /usr/lib/hotplug/firmware/ or /lib/firmware/
  28. * (depending on configuration of firmware hotplug).
  29. */
  30. #define OR51132_VSB_FIRMWARE "dvb-fe-or51132-vsb.fw"
  31. #define OR51132_QAM_FIRMWARE "dvb-fe-or51132-qam.fw"
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/init.h>
  36. #include <linux/delay.h>
  37. #include <linux/string.h>
  38. #include <linux/slab.h>
  39. #include <asm/byteorder.h>
  40. #include "dvb_frontend.h"
  41. #include "dvb-pll.h"
  42. #include "or51132.h"
  43. static int debug;
  44. #define dprintk(args...) \
  45. do { \
  46. if (debug) printk(KERN_DEBUG "or51132: " args); \
  47. } while (0)
  48. struct or51132_state
  49. {
  50. struct i2c_adapter* i2c;
  51. struct dvb_frontend_ops ops;
  52. /* Configuration settings */
  53. const struct or51132_config* config;
  54. struct dvb_frontend frontend;
  55. /* Demodulator private data */
  56. fe_modulation_t current_modulation;
  57. /* Tuner private data */
  58. u32 current_frequency;
  59. };
  60. static int i2c_writebytes (struct or51132_state* state, u8 reg, u8 *buf, int len)
  61. {
  62. int err;
  63. struct i2c_msg msg;
  64. msg.addr = reg;
  65. msg.flags = 0;
  66. msg.len = len;
  67. msg.buf = buf;
  68. if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
  69. printk(KERN_WARNING "or51132: i2c_writebytes error (addr %02x, err == %i)\n", reg, err);
  70. return -EREMOTEIO;
  71. }
  72. return 0;
  73. }
  74. static u8 i2c_readbytes (struct or51132_state* state, u8 reg, u8* buf, int len)
  75. {
  76. int err;
  77. struct i2c_msg msg;
  78. msg.addr = reg;
  79. msg.flags = I2C_M_RD;
  80. msg.len = len;
  81. msg.buf = buf;
  82. if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
  83. printk(KERN_WARNING "or51132: i2c_readbytes error (addr %02x, err == %i)\n", reg, err);
  84. return -EREMOTEIO;
  85. }
  86. return 0;
  87. }
  88. static int or51132_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
  89. {
  90. struct or51132_state* state = fe->demodulator_priv;
  91. static u8 run_buf[] = {0x7F,0x01};
  92. static u8 get_ver_buf[] = {0x04,0x00,0x30,0x00,0x00};
  93. u8 rec_buf[14];
  94. u8 cmd_buf[14];
  95. u32 firmwareAsize, firmwareBsize;
  96. int i,ret;
  97. dprintk("Firmware is %Zd bytes\n",fw->size);
  98. /* Get size of firmware A and B */
  99. firmwareAsize = le32_to_cpu(*((u32*)fw->data));
  100. dprintk("FirmwareA is %i bytes\n",firmwareAsize);
  101. firmwareBsize = le32_to_cpu(*((u32*)(fw->data+4)));
  102. dprintk("FirmwareB is %i bytes\n",firmwareBsize);
  103. /* Upload firmware */
  104. if ((ret = i2c_writebytes(state,state->config->demod_address,
  105. &fw->data[8],firmwareAsize))) {
  106. printk(KERN_WARNING "or51132: load_firmware error 1\n");
  107. return ret;
  108. }
  109. msleep(1); /* 1ms */
  110. if ((ret = i2c_writebytes(state,state->config->demod_address,
  111. &fw->data[8+firmwareAsize],firmwareBsize))) {
  112. printk(KERN_WARNING "or51132: load_firmware error 2\n");
  113. return ret;
  114. }
  115. msleep(1); /* 1ms */
  116. if ((ret = i2c_writebytes(state,state->config->demod_address,
  117. run_buf,2))) {
  118. printk(KERN_WARNING "or51132: load_firmware error 3\n");
  119. return ret;
  120. }
  121. /* Wait at least 5 msec */
  122. msleep(20); /* 10ms */
  123. if ((ret = i2c_writebytes(state,state->config->demod_address,
  124. run_buf,2))) {
  125. printk(KERN_WARNING "or51132: load_firmware error 4\n");
  126. return ret;
  127. }
  128. /* 50ms for operation to begin */
  129. msleep(50);
  130. /* Read back ucode version to besure we loaded correctly and are really up and running */
  131. /* Get uCode version */
  132. cmd_buf[0] = 0x10;
  133. cmd_buf[1] = 0x10;
  134. cmd_buf[2] = 0x00;
  135. cmd_buf[3] = 0x00;
  136. msleep(20); /* 20ms */
  137. if ((ret = i2c_writebytes(state,state->config->demod_address,
  138. cmd_buf,3))) {
  139. printk(KERN_WARNING "or51132: load_firmware error a\n");
  140. return ret;
  141. }
  142. cmd_buf[0] = 0x04;
  143. cmd_buf[1] = 0x17;
  144. cmd_buf[2] = 0x00;
  145. cmd_buf[3] = 0x00;
  146. msleep(20); /* 20ms */
  147. if ((ret = i2c_writebytes(state,state->config->demod_address,
  148. cmd_buf,2))) {
  149. printk(KERN_WARNING "or51132: load_firmware error b\n");
  150. return ret;
  151. }
  152. cmd_buf[0] = 0x00;
  153. cmd_buf[1] = 0x00;
  154. cmd_buf[2] = 0x00;
  155. cmd_buf[3] = 0x00;
  156. msleep(20); /* 20ms */
  157. if ((ret = i2c_writebytes(state,state->config->demod_address,
  158. cmd_buf,2))) {
  159. printk(KERN_WARNING "or51132: load_firmware error c\n");
  160. return ret;
  161. }
  162. for(i=0;i<4;i++) {
  163. msleep(20); /* 20ms */
  164. get_ver_buf[4] = i+1;
  165. if ((ret = i2c_readbytes(state,state->config->demod_address,
  166. &rec_buf[i*2],2))) {
  167. printk(KERN_WARNING
  168. "or51132: load_firmware error d - %d\n",i);
  169. return ret;
  170. }
  171. }
  172. printk(KERN_WARNING
  173. "or51132: Version: %02X%02X%02X%02X-%02X%02X%02X%02X (%02X%01X-%01X-%02X%01X-%01X)\n",
  174. rec_buf[1],rec_buf[0],rec_buf[3],rec_buf[2],
  175. rec_buf[5],rec_buf[4],rec_buf[7],rec_buf[6],
  176. rec_buf[3],rec_buf[2]>>4,rec_buf[2]&0x0f,
  177. rec_buf[5],rec_buf[4]>>4,rec_buf[4]&0x0f);
  178. cmd_buf[0] = 0x10;
  179. cmd_buf[1] = 0x00;
  180. cmd_buf[2] = 0x00;
  181. cmd_buf[3] = 0x00;
  182. msleep(20); /* 20ms */
  183. if ((ret = i2c_writebytes(state,state->config->demod_address,
  184. cmd_buf,3))) {
  185. printk(KERN_WARNING "or51132: load_firmware error e\n");
  186. return ret;
  187. }
  188. return 0;
  189. };
  190. static int or51132_init(struct dvb_frontend* fe)
  191. {
  192. return 0;
  193. }
  194. static int or51132_read_ber(struct dvb_frontend* fe, u32* ber)
  195. {
  196. *ber = 0;
  197. return 0;
  198. }
  199. static int or51132_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
  200. {
  201. *ucblocks = 0;
  202. return 0;
  203. }
  204. static int or51132_sleep(struct dvb_frontend* fe)
  205. {
  206. return 0;
  207. }
  208. static int or51132_setmode(struct dvb_frontend* fe)
  209. {
  210. struct or51132_state* state = fe->demodulator_priv;
  211. unsigned char cmd_buf[4];
  212. dprintk("setmode %d\n",(int)state->current_modulation);
  213. /* set operation mode in Receiver 1 register; */
  214. cmd_buf[0] = 0x04;
  215. cmd_buf[1] = 0x01;
  216. switch (state->current_modulation) {
  217. case QAM_256:
  218. case QAM_64:
  219. case QAM_AUTO:
  220. /* Auto-deinterleave; MPEG ser, MPEG2tr, phase noise-high*/
  221. cmd_buf[2] = 0x5F;
  222. break;
  223. case VSB_8:
  224. /* Auto CH, Auto NTSC rej, MPEGser, MPEG2tr, phase noise-high*/
  225. cmd_buf[2] = 0x50;
  226. break;
  227. default:
  228. printk("setmode:Modulation set to unsupported value\n");
  229. };
  230. cmd_buf[3] = 0x00;
  231. if (i2c_writebytes(state,state->config->demod_address,
  232. cmd_buf,3)) {
  233. printk(KERN_WARNING "or51132: set_mode error 1\n");
  234. return -1;
  235. }
  236. dprintk("or51132: set #1 to %02x\n", cmd_buf[2]);
  237. /* Set operation mode in Receiver 6 register */
  238. cmd_buf[0] = 0x1C;
  239. switch (state->current_modulation) {
  240. case QAM_AUTO:
  241. /* REC MODE Normal Carrier Lock */
  242. cmd_buf[1] = 0x00;
  243. /* Channel MODE Auto QAM64/256 */
  244. cmd_buf[2] = 0x4f;
  245. break;
  246. case QAM_256:
  247. /* REC MODE Normal Carrier Lock */
  248. cmd_buf[1] = 0x00;
  249. /* Channel MODE QAM256 */
  250. cmd_buf[2] = 0x45;
  251. break;
  252. case QAM_64:
  253. /* REC MODE Normal Carrier Lock */
  254. cmd_buf[1] = 0x00;
  255. /* Channel MODE QAM64 */
  256. cmd_buf[2] = 0x43;
  257. break;
  258. case VSB_8:
  259. /* REC MODE inv IF spectrum, Normal */
  260. cmd_buf[1] = 0x03;
  261. /* Channel MODE ATSC/VSB8 */
  262. cmd_buf[2] = 0x06;
  263. break;
  264. default:
  265. printk("setmode: Modulation set to unsupported value\n");
  266. };
  267. cmd_buf[3] = 0x00;
  268. msleep(20); /* 20ms */
  269. if (i2c_writebytes(state,state->config->demod_address,
  270. cmd_buf,3)) {
  271. printk(KERN_WARNING "or51132: set_mode error 2\n");
  272. return -1;
  273. }
  274. dprintk("or51132: set #6 to 0x%02x%02x\n", cmd_buf[1], cmd_buf[2]);
  275. return 0;
  276. }
  277. static int or51132_set_parameters(struct dvb_frontend* fe,
  278. struct dvb_frontend_parameters *param)
  279. {
  280. int ret;
  281. u8 buf[4];
  282. struct or51132_state* state = fe->demodulator_priv;
  283. const struct firmware *fw;
  284. /* Change only if we are actually changing the modulation */
  285. if (state->current_modulation != param->u.vsb.modulation) {
  286. switch(param->u.vsb.modulation) {
  287. case VSB_8:
  288. dprintk("set_parameters VSB MODE\n");
  289. printk("or51132: Waiting for firmware upload(%s)...\n",
  290. OR51132_VSB_FIRMWARE);
  291. ret = request_firmware(&fw, OR51132_VSB_FIRMWARE,
  292. &state->i2c->dev);
  293. if (ret){
  294. printk(KERN_WARNING "or51132: No firmware up"
  295. "loaded(timeout or file not found?)\n");
  296. return ret;
  297. }
  298. /* Set non-punctured clock for VSB */
  299. state->config->set_ts_params(fe, 0);
  300. break;
  301. case QAM_AUTO:
  302. case QAM_64:
  303. case QAM_256:
  304. dprintk("set_parameters QAM MODE\n");
  305. printk("or51132: Waiting for firmware upload(%s)...\n",
  306. OR51132_QAM_FIRMWARE);
  307. ret = request_firmware(&fw, OR51132_QAM_FIRMWARE,
  308. &state->i2c->dev);
  309. if (ret){
  310. printk(KERN_WARNING "or51132: No firmware up"
  311. "loaded(timeout or file not found?)\n");
  312. return ret;
  313. }
  314. /* Set punctured clock for QAM */
  315. state->config->set_ts_params(fe, 1);
  316. break;
  317. default:
  318. printk("or51132:Modulation type(%d) UNSUPPORTED\n",
  319. param->u.vsb.modulation);
  320. return -1;
  321. };
  322. ret = or51132_load_firmware(fe, fw);
  323. release_firmware(fw);
  324. if (ret) {
  325. printk(KERN_WARNING "or51132: Writing firmware to "
  326. "device failed!\n");
  327. return ret;
  328. }
  329. printk("or51132: Firmware upload complete.\n");
  330. state->current_modulation = param->u.vsb.modulation;
  331. or51132_setmode(fe);
  332. }
  333. dvb_pll_configure(state->config->pll_desc, buf,
  334. param->frequency, 0);
  335. dprintk("set_parameters tuner bytes: 0x%02x 0x%02x "
  336. "0x%02x 0x%02x\n",buf[0],buf[1],buf[2],buf[3]);
  337. if (i2c_writebytes(state, state->config->pll_address ,buf, 4))
  338. printk(KERN_WARNING "or51132: set_parameters error "
  339. "writing to tuner\n");
  340. /* Set to current mode */
  341. or51132_setmode(fe);
  342. /* Update current frequency */
  343. state->current_frequency = param->frequency;
  344. return 0;
  345. }
  346. static int or51132_read_status(struct dvb_frontend* fe, fe_status_t* status)
  347. {
  348. struct or51132_state* state = fe->demodulator_priv;
  349. unsigned char rec_buf[2];
  350. unsigned char snd_buf[2];
  351. *status = 0;
  352. /* Receiver Status */
  353. snd_buf[0]=0x04;
  354. snd_buf[1]=0x00;
  355. msleep(30); /* 30ms */
  356. if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
  357. printk(KERN_WARNING "or51132: read_status write error\n");
  358. return -1;
  359. }
  360. msleep(30); /* 30ms */
  361. if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
  362. printk(KERN_WARNING "or51132: read_status read error\n");
  363. return -1;
  364. }
  365. dprintk("read_status %x %x\n",rec_buf[0],rec_buf[1]);
  366. if (rec_buf[1] & 0x01) { /* Receiver Lock */
  367. *status |= FE_HAS_SIGNAL;
  368. *status |= FE_HAS_CARRIER;
  369. *status |= FE_HAS_VITERBI;
  370. *status |= FE_HAS_SYNC;
  371. *status |= FE_HAS_LOCK;
  372. }
  373. return 0;
  374. }
  375. /* log10-1 table at .5 increments from 1 to 100.5 */
  376. static unsigned int i100x20log10[] = {
  377. 0, 352, 602, 795, 954, 1088, 1204, 1306, 1397, 1480,
  378. 1556, 1625, 1690, 1750, 1806, 1858, 1908, 1955, 2000, 2042,
  379. 2082, 2121, 2158, 2193, 2227, 2260, 2292, 2322, 2352, 2380,
  380. 2408, 2434, 2460, 2486, 2510, 2534, 2557, 2580, 2602, 2623,
  381. 2644, 2664, 2684, 2704, 2723, 2742, 2760, 2778, 2795, 2813,
  382. 2829, 2846, 2862, 2878, 2894, 2909, 2924, 2939, 2954, 2968,
  383. 2982, 2996, 3010, 3023, 3037, 3050, 3062, 3075, 3088, 3100,
  384. 3112, 3124, 3136, 3148, 3159, 3170, 3182, 3193, 3204, 3214,
  385. 3225, 3236, 3246, 3256, 3266, 3276, 3286, 3296, 3306, 3316,
  386. 3325, 3334, 3344, 3353, 3362, 3371, 3380, 3389, 3397, 3406,
  387. 3415, 3423, 3432, 3440, 3448, 3456, 3464, 3472, 3480, 3488,
  388. 3496, 3504, 3511, 3519, 3526, 3534, 3541, 3549, 3556, 3563,
  389. 3570, 3577, 3584, 3591, 3598, 3605, 3612, 3619, 3625, 3632,
  390. 3639, 3645, 3652, 3658, 3665, 3671, 3677, 3683, 3690, 3696,
  391. 3702, 3708, 3714, 3720, 3726, 3732, 3738, 3744, 3750, 3755,
  392. 3761, 3767, 3772, 3778, 3784, 3789, 3795, 3800, 3806, 3811,
  393. 3816, 3822, 3827, 3832, 3838, 3843, 3848, 3853, 3858, 3863,
  394. 3868, 3874, 3879, 3884, 3888, 3893, 3898, 3903, 3908, 3913,
  395. 3918, 3922, 3927, 3932, 3936, 3941, 3946, 3950, 3955, 3960,
  396. 3964, 3969, 3973, 3978, 3982, 3986, 3991, 3995, 4000, 4004,
  397. };
  398. static unsigned int denom[] = {1,1,100,1000,10000,100000,1000000,10000000,100000000};
  399. static unsigned int i20Log10(unsigned short val)
  400. {
  401. unsigned int rntval = 100;
  402. unsigned int tmp = val;
  403. unsigned int exp = 1;
  404. while(tmp > 100) {tmp /= 100; exp++;}
  405. val = (2 * val)/denom[exp];
  406. if (exp > 1) rntval = 2000*exp;
  407. rntval += i100x20log10[val];
  408. return rntval;
  409. }
  410. static int or51132_read_signal_strength(struct dvb_frontend* fe, u16* strength)
  411. {
  412. struct or51132_state* state = fe->demodulator_priv;
  413. unsigned char rec_buf[2];
  414. unsigned char snd_buf[2];
  415. u8 rcvr_stat;
  416. u16 snr_equ;
  417. u32 signal_strength;
  418. int usK;
  419. snd_buf[0]=0x04;
  420. snd_buf[1]=0x02; /* SNR after Equalizer */
  421. msleep(30); /* 30ms */
  422. if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
  423. printk(KERN_WARNING "or51132: read_status write error\n");
  424. return -1;
  425. }
  426. msleep(30); /* 30ms */
  427. if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
  428. printk(KERN_WARNING "or51132: read_status read error\n");
  429. return -1;
  430. }
  431. snr_equ = rec_buf[0] | (rec_buf[1] << 8);
  432. dprintk("read_signal_strength snr_equ %x %x (%i)\n",rec_buf[0],rec_buf[1],snr_equ);
  433. /* Receiver Status */
  434. snd_buf[0]=0x04;
  435. snd_buf[1]=0x00;
  436. msleep(30); /* 30ms */
  437. if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
  438. printk(KERN_WARNING "or51132: read_signal_strength read_status write error\n");
  439. return -1;
  440. }
  441. msleep(30); /* 30ms */
  442. if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
  443. printk(KERN_WARNING "or51132: read_signal_strength read_status read error\n");
  444. return -1;
  445. }
  446. dprintk("read_signal_strength read_status %x %x\n",rec_buf[0],rec_buf[1]);
  447. rcvr_stat = rec_buf[1];
  448. usK = (rcvr_stat & 0x10) ? 3 : 0;
  449. /* The value reported back from the frontend will be FFFF=100% 0000=0% */
  450. signal_strength = (((8952 - i20Log10(snr_equ) - usK*100)/3+5)*65535)/1000;
  451. if (signal_strength > 0xffff)
  452. *strength = 0xffff;
  453. else
  454. *strength = signal_strength;
  455. dprintk("read_signal_strength %i\n",*strength);
  456. return 0;
  457. }
  458. static int or51132_read_snr(struct dvb_frontend* fe, u16* snr)
  459. {
  460. struct or51132_state* state = fe->demodulator_priv;
  461. unsigned char rec_buf[2];
  462. unsigned char snd_buf[2];
  463. u16 snr_equ;
  464. snd_buf[0]=0x04;
  465. snd_buf[1]=0x02; /* SNR after Equalizer */
  466. msleep(30); /* 30ms */
  467. if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
  468. printk(KERN_WARNING "or51132: read_snr write error\n");
  469. return -1;
  470. }
  471. msleep(30); /* 30ms */
  472. if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
  473. printk(KERN_WARNING "or51132: read_snr dvr read error\n");
  474. return -1;
  475. }
  476. snr_equ = rec_buf[0] | (rec_buf[1] << 8);
  477. dprintk("read_snr snr_equ %x %x (%i)\n",rec_buf[0],rec_buf[1],snr_equ);
  478. *snr = 0xFFFF - snr_equ;
  479. dprintk("read_snr %i\n",*snr);
  480. return 0;
  481. }
  482. static int or51132_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fe_tune_settings)
  483. {
  484. fe_tune_settings->min_delay_ms = 500;
  485. fe_tune_settings->step_size = 0;
  486. fe_tune_settings->max_drift = 0;
  487. return 0;
  488. }
  489. static void or51132_release(struct dvb_frontend* fe)
  490. {
  491. struct or51132_state* state = fe->demodulator_priv;
  492. kfree(state);
  493. }
  494. static struct dvb_frontend_ops or51132_ops;
  495. struct dvb_frontend* or51132_attach(const struct or51132_config* config,
  496. struct i2c_adapter* i2c)
  497. {
  498. struct or51132_state* state = NULL;
  499. /* Allocate memory for the internal state */
  500. state = kmalloc(sizeof(struct or51132_state), GFP_KERNEL);
  501. if (state == NULL)
  502. goto error;
  503. /* Setup the state */
  504. state->config = config;
  505. state->i2c = i2c;
  506. memcpy(&state->ops, &or51132_ops, sizeof(struct dvb_frontend_ops));
  507. state->current_frequency = -1;
  508. state->current_modulation = -1;
  509. /* Create dvb_frontend */
  510. state->frontend.ops = &state->ops;
  511. state->frontend.demodulator_priv = state;
  512. return &state->frontend;
  513. error:
  514. kfree(state);
  515. return NULL;
  516. }
  517. static struct dvb_frontend_ops or51132_ops = {
  518. .info = {
  519. .name = "Oren OR51132 VSB/QAM Frontend",
  520. .type = FE_ATSC,
  521. .frequency_min = 44000000,
  522. .frequency_max = 958000000,
  523. .frequency_stepsize = 166666,
  524. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  525. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  526. FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_QAM_AUTO |
  527. FE_CAN_8VSB
  528. },
  529. .release = or51132_release,
  530. .init = or51132_init,
  531. .sleep = or51132_sleep,
  532. .set_frontend = or51132_set_parameters,
  533. .get_tune_settings = or51132_get_tune_settings,
  534. .read_status = or51132_read_status,
  535. .read_ber = or51132_read_ber,
  536. .read_signal_strength = or51132_read_signal_strength,
  537. .read_snr = or51132_read_snr,
  538. .read_ucblocks = or51132_read_ucblocks,
  539. };
  540. module_param(debug, int, 0644);
  541. MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
  542. MODULE_DESCRIPTION("OR51132 ATSC [pcHDTV HD-3000] (8VSB & ITU J83 AnnexB FEC QAM64/256) Demodulator Driver");
  543. MODULE_AUTHOR("Kirk Lapray");
  544. MODULE_LICENSE("GPL");
  545. EXPORT_SYMBOL(or51132_attach);
  546. /*
  547. * Local variables:
  548. * c-basic-offset: 8
  549. * End:
  550. */