or51132.c 18 KB

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