or51132.c 18 KB

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