tda1004x.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. /*
  2. Driver for Philips tda1004xh OFDM Demodulator
  3. (c) 2003, 2004 Andrew de Quincey & Robert Schlabbach
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. /*
  17. * This driver needs external firmware. Please use the commands
  18. * "<kerneldir>/Documentation/dvb/get_dvb_firmware tda10045",
  19. * "<kerneldir>/Documentation/dvb/get_dvb_firmware tda10046" to
  20. * download/extract them, and then copy them to /usr/lib/hotplug/firmware.
  21. */
  22. #define TDA10045_DEFAULT_FIRMWARE "dvb-fe-tda10045.fw"
  23. #define TDA10046_DEFAULT_FIRMWARE "dvb-fe-tda10046.fw"
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/device.h>
  28. #include "dvb_frontend.h"
  29. #include "tda1004x.h"
  30. enum tda1004x_demod {
  31. TDA1004X_DEMOD_TDA10045,
  32. TDA1004X_DEMOD_TDA10046,
  33. };
  34. struct tda1004x_state {
  35. struct i2c_adapter* i2c;
  36. struct dvb_frontend_ops ops;
  37. const struct tda1004x_config* config;
  38. struct dvb_frontend frontend;
  39. /* private demod data */
  40. u8 initialised;
  41. enum tda1004x_demod demod_type;
  42. };
  43. static int debug;
  44. #define dprintk(args...) \
  45. do { \
  46. if (debug) printk(KERN_DEBUG "tda1004x: " args); \
  47. } while (0)
  48. #define TDA1004X_CHIPID 0x00
  49. #define TDA1004X_AUTO 0x01
  50. #define TDA1004X_IN_CONF1 0x02
  51. #define TDA1004X_IN_CONF2 0x03
  52. #define TDA1004X_OUT_CONF1 0x04
  53. #define TDA1004X_OUT_CONF2 0x05
  54. #define TDA1004X_STATUS_CD 0x06
  55. #define TDA1004X_CONFC4 0x07
  56. #define TDA1004X_DSSPARE2 0x0C
  57. #define TDA10045H_CODE_IN 0x0D
  58. #define TDA10045H_FWPAGE 0x0E
  59. #define TDA1004X_SCAN_CPT 0x10
  60. #define TDA1004X_DSP_CMD 0x11
  61. #define TDA1004X_DSP_ARG 0x12
  62. #define TDA1004X_DSP_DATA1 0x13
  63. #define TDA1004X_DSP_DATA2 0x14
  64. #define TDA1004X_CONFADC1 0x15
  65. #define TDA1004X_CONFC1 0x16
  66. #define TDA10045H_S_AGC 0x1a
  67. #define TDA10046H_AGC_TUN_LEVEL 0x1a
  68. #define TDA1004X_SNR 0x1c
  69. #define TDA1004X_CONF_TS1 0x1e
  70. #define TDA1004X_CONF_TS2 0x1f
  71. #define TDA1004X_CBER_RESET 0x20
  72. #define TDA1004X_CBER_MSB 0x21
  73. #define TDA1004X_CBER_LSB 0x22
  74. #define TDA1004X_CVBER_LUT 0x23
  75. #define TDA1004X_VBER_MSB 0x24
  76. #define TDA1004X_VBER_MID 0x25
  77. #define TDA1004X_VBER_LSB 0x26
  78. #define TDA1004X_UNCOR 0x27
  79. #define TDA10045H_CONFPLL_P 0x2D
  80. #define TDA10045H_CONFPLL_M_MSB 0x2E
  81. #define TDA10045H_CONFPLL_M_LSB 0x2F
  82. #define TDA10045H_CONFPLL_N 0x30
  83. #define TDA10046H_CONFPLL1 0x2D
  84. #define TDA10046H_CONFPLL2 0x2F
  85. #define TDA10046H_CONFPLL3 0x30
  86. #define TDA10046H_TIME_WREF1 0x31
  87. #define TDA10046H_TIME_WREF2 0x32
  88. #define TDA10046H_TIME_WREF3 0x33
  89. #define TDA10046H_TIME_WREF4 0x34
  90. #define TDA10046H_TIME_WREF5 0x35
  91. #define TDA10045H_UNSURW_MSB 0x31
  92. #define TDA10045H_UNSURW_LSB 0x32
  93. #define TDA10045H_WREF_MSB 0x33
  94. #define TDA10045H_WREF_MID 0x34
  95. #define TDA10045H_WREF_LSB 0x35
  96. #define TDA10045H_MUXOUT 0x36
  97. #define TDA1004X_CONFADC2 0x37
  98. #define TDA10045H_IOFFSET 0x38
  99. #define TDA10046H_CONF_TRISTATE1 0x3B
  100. #define TDA10046H_CONF_TRISTATE2 0x3C
  101. #define TDA10046H_CONF_POLARITY 0x3D
  102. #define TDA10046H_FREQ_OFFSET 0x3E
  103. #define TDA10046H_GPIO_OUT_SEL 0x41
  104. #define TDA10046H_GPIO_SELECT 0x42
  105. #define TDA10046H_AGC_CONF 0x43
  106. #define TDA10046H_AGC_GAINS 0x46
  107. #define TDA10046H_AGC_TUN_MIN 0x47
  108. #define TDA10046H_AGC_TUN_MAX 0x48
  109. #define TDA10046H_AGC_IF_MIN 0x49
  110. #define TDA10046H_AGC_IF_MAX 0x4A
  111. #define TDA10046H_FREQ_PHY2_MSB 0x4D
  112. #define TDA10046H_FREQ_PHY2_LSB 0x4E
  113. #define TDA10046H_CVBER_CTRL 0x4F
  114. #define TDA10046H_AGC_IF_LEVEL 0x52
  115. #define TDA10046H_CODE_CPT 0x57
  116. #define TDA10046H_CODE_IN 0x58
  117. static int tda1004x_write_byteI(struct tda1004x_state *state, int reg, int data)
  118. {
  119. int ret;
  120. u8 buf[] = { reg, data };
  121. struct i2c_msg msg = { .flags = 0, .buf = buf, .len = 2 };
  122. dprintk("%s: reg=0x%x, data=0x%x\n", __FUNCTION__, reg, data);
  123. msg.addr = state->config->demod_address;
  124. ret = i2c_transfer(state->i2c, &msg, 1);
  125. if (ret != 1)
  126. dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
  127. __FUNCTION__, reg, data, ret);
  128. dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __FUNCTION__,
  129. reg, data, ret);
  130. return (ret != 1) ? -1 : 0;
  131. }
  132. static int tda1004x_read_byte(struct tda1004x_state *state, int reg)
  133. {
  134. int ret;
  135. u8 b0[] = { reg };
  136. u8 b1[] = { 0 };
  137. struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 },
  138. { .flags = I2C_M_RD, .buf = b1, .len = 1 }};
  139. dprintk("%s: reg=0x%x\n", __FUNCTION__, reg);
  140. msg[0].addr = state->config->demod_address;
  141. msg[1].addr = state->config->demod_address;
  142. ret = i2c_transfer(state->i2c, msg, 2);
  143. if (ret != 2) {
  144. dprintk("%s: error reg=0x%x, ret=%i\n", __FUNCTION__, reg,
  145. ret);
  146. return -1;
  147. }
  148. dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __FUNCTION__,
  149. reg, b1[0], ret);
  150. return b1[0];
  151. }
  152. static int tda1004x_write_mask(struct tda1004x_state *state, int reg, int mask, int data)
  153. {
  154. int val;
  155. dprintk("%s: reg=0x%x, mask=0x%x, data=0x%x\n", __FUNCTION__, reg,
  156. mask, data);
  157. // read a byte and check
  158. val = tda1004x_read_byte(state, reg);
  159. if (val < 0)
  160. return val;
  161. // mask if off
  162. val = val & ~mask;
  163. val |= data & 0xff;
  164. // write it out again
  165. return tda1004x_write_byteI(state, reg, val);
  166. }
  167. static int tda1004x_write_buf(struct tda1004x_state *state, int reg, unsigned char *buf, int len)
  168. {
  169. int i;
  170. int result;
  171. dprintk("%s: reg=0x%x, len=0x%x\n", __FUNCTION__, reg, len);
  172. result = 0;
  173. for (i = 0; i < len; i++) {
  174. result = tda1004x_write_byteI(state, reg + i, buf[i]);
  175. if (result != 0)
  176. break;
  177. }
  178. return result;
  179. }
  180. static int tda1004x_enable_tuner_i2c(struct tda1004x_state *state)
  181. {
  182. int result;
  183. dprintk("%s\n", __FUNCTION__);
  184. result = tda1004x_write_mask(state, TDA1004X_CONFC4, 2, 2);
  185. msleep(1);
  186. return result;
  187. }
  188. static int tda1004x_disable_tuner_i2c(struct tda1004x_state *state)
  189. {
  190. dprintk("%s\n", __FUNCTION__);
  191. return tda1004x_write_mask(state, TDA1004X_CONFC4, 2, 0);
  192. }
  193. static int tda10045h_set_bandwidth(struct tda1004x_state *state,
  194. fe_bandwidth_t bandwidth)
  195. {
  196. static u8 bandwidth_6mhz[] = { 0x02, 0x00, 0x3d, 0x00, 0x60, 0x1e, 0xa7, 0x45, 0x4f };
  197. static u8 bandwidth_7mhz[] = { 0x02, 0x00, 0x37, 0x00, 0x4a, 0x2f, 0x6d, 0x76, 0xdb };
  198. static u8 bandwidth_8mhz[] = { 0x02, 0x00, 0x3d, 0x00, 0x48, 0x17, 0x89, 0xc7, 0x14 };
  199. switch (bandwidth) {
  200. case BANDWIDTH_6_MHZ:
  201. tda1004x_write_buf(state, TDA10045H_CONFPLL_P, bandwidth_6mhz, sizeof(bandwidth_6mhz));
  202. break;
  203. case BANDWIDTH_7_MHZ:
  204. tda1004x_write_buf(state, TDA10045H_CONFPLL_P, bandwidth_7mhz, sizeof(bandwidth_7mhz));
  205. break;
  206. case BANDWIDTH_8_MHZ:
  207. tda1004x_write_buf(state, TDA10045H_CONFPLL_P, bandwidth_8mhz, sizeof(bandwidth_8mhz));
  208. break;
  209. default:
  210. return -EINVAL;
  211. }
  212. tda1004x_write_byteI(state, TDA10045H_IOFFSET, 0);
  213. return 0;
  214. }
  215. static int tda10046h_set_bandwidth(struct tda1004x_state *state,
  216. fe_bandwidth_t bandwidth)
  217. {
  218. static u8 bandwidth_6mhz[] = { 0x80, 0x15, 0xfe, 0xab, 0x8e };
  219. static u8 bandwidth_7mhz[] = { 0x6e, 0x02, 0x53, 0xc8, 0x25 };
  220. static u8 bandwidth_8mhz[] = { 0x60, 0x12, 0xa8, 0xe4, 0xbd };
  221. switch (bandwidth) {
  222. case BANDWIDTH_6_MHZ:
  223. tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_6mhz, sizeof(bandwidth_6mhz));
  224. break;
  225. case BANDWIDTH_7_MHZ:
  226. tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_7mhz, sizeof(bandwidth_7mhz));
  227. break;
  228. case BANDWIDTH_8_MHZ:
  229. tda1004x_write_buf(state, TDA10046H_TIME_WREF1, bandwidth_8mhz, sizeof(bandwidth_8mhz));
  230. break;
  231. default:
  232. return -EINVAL;
  233. }
  234. return 0;
  235. }
  236. static int tda1004x_do_upload(struct tda1004x_state *state,
  237. unsigned char *mem, unsigned int len,
  238. u8 dspCodeCounterReg, u8 dspCodeInReg)
  239. {
  240. u8 buf[65];
  241. struct i2c_msg fw_msg = { .flags = 0, .buf = buf, .len = 0 };
  242. int tx_size;
  243. int pos = 0;
  244. /* clear code counter */
  245. tda1004x_write_byteI(state, dspCodeCounterReg, 0);
  246. fw_msg.addr = state->config->demod_address;
  247. buf[0] = dspCodeInReg;
  248. while (pos != len) {
  249. // work out how much to send this time
  250. tx_size = len - pos;
  251. if (tx_size > 0x10)
  252. tx_size = 0x10;
  253. // send the chunk
  254. memcpy(buf + 1, mem + pos, tx_size);
  255. fw_msg.len = tx_size + 1;
  256. if (i2c_transfer(state->i2c, &fw_msg, 1) != 1) {
  257. printk("tda1004x: Error during firmware upload\n");
  258. return -EIO;
  259. }
  260. pos += tx_size;
  261. dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, pos);
  262. }
  263. return 0;
  264. }
  265. static int tda1004x_check_upload_ok(struct tda1004x_state *state, u8 dspVersion)
  266. {
  267. u8 data1, data2;
  268. // check upload was OK
  269. tda1004x_write_mask(state, TDA1004X_CONFC4, 0x10, 0); // we want to read from the DSP
  270. tda1004x_write_byteI(state, TDA1004X_DSP_CMD, 0x67);
  271. data1 = tda1004x_read_byte(state, TDA1004X_DSP_DATA1);
  272. data2 = tda1004x_read_byte(state, TDA1004X_DSP_DATA2);
  273. if ((data1 != 0x67) || (data2 != dspVersion))
  274. return -EIO;
  275. return 0;
  276. }
  277. static int tda10045_fwupload(struct dvb_frontend* fe)
  278. {
  279. struct tda1004x_state* state = fe->demodulator_priv;
  280. int ret;
  281. const struct firmware *fw;
  282. /* don't re-upload unless necessary */
  283. if (tda1004x_check_upload_ok(state, 0x2c) == 0)
  284. return 0;
  285. /* request the firmware, this will block until someone uploads it */
  286. printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE);
  287. ret = state->config->request_firmware(fe, &fw, TDA10045_DEFAULT_FIRMWARE);
  288. if (ret) {
  289. printk("tda1004x: no firmware upload (timeout or file not found?)\n");
  290. return ret;
  291. }
  292. /* reset chip */
  293. tda1004x_write_mask(state, TDA1004X_CONFC4, 0x10, 0);
  294. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8);
  295. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 0);
  296. msleep(10);
  297. /* set parameters */
  298. tda10045h_set_bandwidth(state, BANDWIDTH_8_MHZ);
  299. ret = tda1004x_do_upload(state, fw->data, fw->size, TDA10045H_FWPAGE, TDA10045H_CODE_IN);
  300. if (ret)
  301. return ret;
  302. printk("tda1004x: firmware upload complete\n");
  303. /* wait for DSP to initialise */
  304. /* DSPREADY doesn't seem to work on the TDA10045H */
  305. msleep(100);
  306. return tda1004x_check_upload_ok(state, 0x2c);
  307. }
  308. static int tda10046_fwupload(struct dvb_frontend* fe)
  309. {
  310. struct tda1004x_state* state = fe->demodulator_priv;
  311. unsigned long timeout;
  312. int ret;
  313. const struct firmware *fw;
  314. /* reset + wake up chip */
  315. tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 0);
  316. tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0);
  317. msleep(100);
  318. /* don't re-upload unless necessary */
  319. if (tda1004x_check_upload_ok(state, 0x20) == 0)
  320. return 0;
  321. /* request the firmware, this will block until someone uploads it */
  322. printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10046_DEFAULT_FIRMWARE);
  323. ret = state->config->request_firmware(fe, &fw, TDA10046_DEFAULT_FIRMWARE);
  324. if (ret) {
  325. printk("tda1004x: no firmware upload (timeout or file not found?)\n");
  326. return ret;
  327. }
  328. /* set parameters */
  329. tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10);
  330. tda1004x_write_byteI(state, TDA10046H_CONFPLL3, state->config->n_i2c);
  331. tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99);
  332. tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4);
  333. tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c);
  334. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8); // going to boot from HOST
  335. ret = tda1004x_do_upload(state, fw->data, fw->size, TDA10046H_CODE_CPT, TDA10046H_CODE_IN);
  336. if (ret)
  337. return ret;
  338. printk("tda1004x: firmware upload complete\n");
  339. /* wait for DSP to initialise */
  340. timeout = jiffies + HZ;
  341. while (!(tda1004x_read_byte(state, TDA1004X_STATUS_CD) & 0x20)) {
  342. if (time_after(jiffies, timeout)) {
  343. printk("tda1004x: DSP failed to initialised.\n");
  344. return -EIO;
  345. }
  346. msleep(1);
  347. }
  348. return tda1004x_check_upload_ok(state, 0x20);
  349. }
  350. static int tda1004x_encode_fec(int fec)
  351. {
  352. // convert known FEC values
  353. switch (fec) {
  354. case FEC_1_2:
  355. return 0;
  356. case FEC_2_3:
  357. return 1;
  358. case FEC_3_4:
  359. return 2;
  360. case FEC_5_6:
  361. return 3;
  362. case FEC_7_8:
  363. return 4;
  364. }
  365. // unsupported
  366. return -EINVAL;
  367. }
  368. static int tda1004x_decode_fec(int tdafec)
  369. {
  370. // convert known FEC values
  371. switch (tdafec) {
  372. case 0:
  373. return FEC_1_2;
  374. case 1:
  375. return FEC_2_3;
  376. case 2:
  377. return FEC_3_4;
  378. case 3:
  379. return FEC_5_6;
  380. case 4:
  381. return FEC_7_8;
  382. }
  383. // unsupported
  384. return -1;
  385. }
  386. int tda1004x_write_byte(struct dvb_frontend* fe, int reg, int data)
  387. {
  388. struct tda1004x_state* state = fe->demodulator_priv;
  389. return tda1004x_write_byteI(state, reg, data);
  390. }
  391. static int tda10045_init(struct dvb_frontend* fe)
  392. {
  393. struct tda1004x_state* state = fe->demodulator_priv;
  394. dprintk("%s\n", __FUNCTION__);
  395. if (state->initialised)
  396. return 0;
  397. if (tda10045_fwupload(fe)) {
  398. printk("tda1004x: firmware upload failed\n");
  399. return -EIO;
  400. }
  401. tda1004x_write_mask(state, TDA1004X_CONFADC1, 0x10, 0); // wake up the ADC
  402. // Init the PLL
  403. if (state->config->pll_init) {
  404. tda1004x_enable_tuner_i2c(state);
  405. state->config->pll_init(fe);
  406. tda1004x_disable_tuner_i2c(state);
  407. }
  408. // tda setup
  409. tda1004x_write_mask(state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer
  410. tda1004x_write_mask(state, TDA1004X_AUTO, 8, 0); // select HP stream
  411. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x40, 0); // set polarity of VAGC signal
  412. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x80, 0x80); // enable pulse killer
  413. tda1004x_write_mask(state, TDA1004X_AUTO, 0x10, 0x10); // enable auto offset
  414. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0xC0, 0x0); // no frequency offset
  415. tda1004x_write_byteI(state, TDA1004X_CONF_TS1, 0); // setup MPEG2 TS interface
  416. tda1004x_write_byteI(state, TDA1004X_CONF_TS2, 0); // setup MPEG2 TS interface
  417. tda1004x_write_mask(state, TDA1004X_VBER_MSB, 0xe0, 0xa0); // 10^6 VBER measurement bits
  418. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x10, 0); // VAGC polarity
  419. tda1004x_write_byteI(state, TDA1004X_CONFADC1, 0x2e);
  420. tda1004x_write_mask(state, 0x1f, 0x01, state->config->invert_oclk);
  421. state->initialised = 1;
  422. return 0;
  423. }
  424. static int tda10046_init(struct dvb_frontend* fe)
  425. {
  426. struct tda1004x_state* state = fe->demodulator_priv;
  427. dprintk("%s\n", __FUNCTION__);
  428. if (state->initialised)
  429. return 0;
  430. if (tda10046_fwupload(fe)) {
  431. printk("tda1004x: firmware upload failed\n");
  432. return -EIO;
  433. }
  434. tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 0); // wake up the chip
  435. // Init the PLL
  436. if (state->config->pll_init) {
  437. tda1004x_enable_tuner_i2c(state);
  438. state->config->pll_init(fe);
  439. tda1004x_disable_tuner_i2c(state);
  440. }
  441. // tda setup
  442. tda1004x_write_mask(state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer
  443. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x40, 0x40);
  444. tda1004x_write_mask(state, TDA1004X_AUTO, 8, 0); // select HP stream
  445. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x80, 0); // disable pulse killer
  446. tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10); // PLL M = 10
  447. tda1004x_write_byteI(state, TDA10046H_CONFPLL3, state->config->n_i2c); // PLL P = N = 0
  448. tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99); // FREQOFFS = 99
  449. tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4); // } PHY2 = -11221
  450. tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c); // }
  451. tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0); // AGC setup
  452. tda1004x_write_mask(state, TDA10046H_CONF_POLARITY, 0x60, 0x60); // set AGC polarities
  453. tda1004x_write_byteI(state, TDA10046H_AGC_TUN_MIN, 0); // }
  454. tda1004x_write_byteI(state, TDA10046H_AGC_TUN_MAX, 0xff); // } AGC min/max values
  455. tda1004x_write_byteI(state, TDA10046H_AGC_IF_MIN, 0); // }
  456. tda1004x_write_byteI(state, TDA10046H_AGC_IF_MAX, 0xff); // }
  457. tda1004x_write_mask(state, TDA10046H_CVBER_CTRL, 0x30, 0x10); // 10^6 VBER measurement bits
  458. tda1004x_write_byteI(state, TDA10046H_AGC_GAINS, 1); // IF gain 2, TUN gain 1
  459. tda1004x_write_mask(state, TDA1004X_AUTO, 0x80, 0); // crystal is 50ppm
  460. tda1004x_write_byteI(state, TDA1004X_CONF_TS1, 7); // MPEG2 interface config
  461. tda1004x_write_mask(state, TDA1004X_CONF_TS2, 0x31, 0); // MPEG2 interface config
  462. tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 0x9e, 0); // disable AGC_TUN
  463. tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE2, 0xe1); // tristate setup
  464. tda1004x_write_byteI(state, TDA10046H_GPIO_OUT_SEL, 0xcc); // GPIO output config
  465. tda1004x_write_mask(state, TDA10046H_GPIO_SELECT, 8, 8); // GPIO select
  466. tda10046h_set_bandwidth(state, BANDWIDTH_8_MHZ); // default bandwidth 8 MHz
  467. tda1004x_write_mask(state, 0x3a, 0x80, state->config->invert_oclk << 7);
  468. state->initialised = 1;
  469. return 0;
  470. }
  471. static int tda1004x_set_fe(struct dvb_frontend* fe,
  472. struct dvb_frontend_parameters *fe_params)
  473. {
  474. struct tda1004x_state* state = fe->demodulator_priv;
  475. int tmp;
  476. int inversion;
  477. dprintk("%s\n", __FUNCTION__);
  478. if (state->demod_type == TDA1004X_DEMOD_TDA10046) {
  479. // setup auto offset
  480. tda1004x_write_mask(state, TDA1004X_AUTO, 0x10, 0x10);
  481. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x80, 0);
  482. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0xC0, 0);
  483. // disable agc_conf[2]
  484. tda1004x_write_mask(state, TDA10046H_AGC_CONF, 4, 0);
  485. }
  486. // set frequency
  487. tda1004x_enable_tuner_i2c(state);
  488. state->config->pll_set(fe, fe_params);
  489. tda1004x_disable_tuner_i2c(state);
  490. if (state->demod_type == TDA1004X_DEMOD_TDA10046)
  491. tda1004x_write_mask(state, TDA10046H_AGC_CONF, 4, 4);
  492. // Hardcoded to use auto as much as possible on the TDA10045 as it
  493. // is very unreliable if AUTO mode is _not_ used.
  494. if (state->demod_type == TDA1004X_DEMOD_TDA10045) {
  495. fe_params->u.ofdm.code_rate_HP = FEC_AUTO;
  496. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
  497. fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
  498. }
  499. // Set standard params.. or put them to auto
  500. if ((fe_params->u.ofdm.code_rate_HP == FEC_AUTO) ||
  501. (fe_params->u.ofdm.code_rate_LP == FEC_AUTO) ||
  502. (fe_params->u.ofdm.constellation == QAM_AUTO) ||
  503. (fe_params->u.ofdm.hierarchy_information == HIERARCHY_AUTO)) {
  504. tda1004x_write_mask(state, TDA1004X_AUTO, 1, 1); // enable auto
  505. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x03, 0); // turn off constellation bits
  506. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 0); // turn off hierarchy bits
  507. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0x3f, 0); // turn off FEC bits
  508. } else {
  509. tda1004x_write_mask(state, TDA1004X_AUTO, 1, 0); // disable auto
  510. // set HP FEC
  511. tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_HP);
  512. if (tmp < 0)
  513. return tmp;
  514. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 7, tmp);
  515. // set LP FEC
  516. tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_LP);
  517. if (tmp < 0)
  518. return tmp;
  519. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0x38, tmp << 3);
  520. // set constellation
  521. switch (fe_params->u.ofdm.constellation) {
  522. case QPSK:
  523. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 3, 0);
  524. break;
  525. case QAM_16:
  526. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 3, 1);
  527. break;
  528. case QAM_64:
  529. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 3, 2);
  530. break;
  531. default:
  532. return -EINVAL;
  533. }
  534. // set hierarchy
  535. switch (fe_params->u.ofdm.hierarchy_information) {
  536. case HIERARCHY_NONE:
  537. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 0 << 5);
  538. break;
  539. case HIERARCHY_1:
  540. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 1 << 5);
  541. break;
  542. case HIERARCHY_2:
  543. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 2 << 5);
  544. break;
  545. case HIERARCHY_4:
  546. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 3 << 5);
  547. break;
  548. default:
  549. return -EINVAL;
  550. }
  551. }
  552. // set bandwidth
  553. switch (state->demod_type) {
  554. case TDA1004X_DEMOD_TDA10045:
  555. tda10045h_set_bandwidth(state, fe_params->u.ofdm.bandwidth);
  556. break;
  557. case TDA1004X_DEMOD_TDA10046:
  558. tda10046h_set_bandwidth(state, fe_params->u.ofdm.bandwidth);
  559. break;
  560. }
  561. // set inversion
  562. inversion = fe_params->inversion;
  563. if (state->config->invert)
  564. inversion = inversion ? INVERSION_OFF : INVERSION_ON;
  565. switch (inversion) {
  566. case INVERSION_OFF:
  567. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x20, 0);
  568. break;
  569. case INVERSION_ON:
  570. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x20, 0x20);
  571. break;
  572. default:
  573. return -EINVAL;
  574. }
  575. // set guard interval
  576. switch (fe_params->u.ofdm.guard_interval) {
  577. case GUARD_INTERVAL_1_32:
  578. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 0);
  579. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 0 << 2);
  580. break;
  581. case GUARD_INTERVAL_1_16:
  582. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 0);
  583. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 1 << 2);
  584. break;
  585. case GUARD_INTERVAL_1_8:
  586. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 0);
  587. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 2 << 2);
  588. break;
  589. case GUARD_INTERVAL_1_4:
  590. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 0);
  591. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 3 << 2);
  592. break;
  593. case GUARD_INTERVAL_AUTO:
  594. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 2);
  595. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 0 << 2);
  596. break;
  597. default:
  598. return -EINVAL;
  599. }
  600. // set transmission mode
  601. switch (fe_params->u.ofdm.transmission_mode) {
  602. case TRANSMISSION_MODE_2K:
  603. tda1004x_write_mask(state, TDA1004X_AUTO, 4, 0);
  604. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x10, 0 << 4);
  605. break;
  606. case TRANSMISSION_MODE_8K:
  607. tda1004x_write_mask(state, TDA1004X_AUTO, 4, 0);
  608. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x10, 1 << 4);
  609. break;
  610. case TRANSMISSION_MODE_AUTO:
  611. tda1004x_write_mask(state, TDA1004X_AUTO, 4, 4);
  612. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x10, 0);
  613. break;
  614. default:
  615. return -EINVAL;
  616. }
  617. // start the lock
  618. switch (state->demod_type) {
  619. case TDA1004X_DEMOD_TDA10045:
  620. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8);
  621. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 0);
  622. break;
  623. case TDA1004X_DEMOD_TDA10046:
  624. tda1004x_write_mask(state, TDA1004X_AUTO, 0x40, 0x40);
  625. break;
  626. }
  627. msleep(10);
  628. return 0;
  629. }
  630. static int tda1004x_get_fe(struct dvb_frontend* fe, struct dvb_frontend_parameters *fe_params)
  631. {
  632. struct tda1004x_state* state = fe->demodulator_priv;
  633. dprintk("%s\n", __FUNCTION__);
  634. // inversion status
  635. fe_params->inversion = INVERSION_OFF;
  636. if (tda1004x_read_byte(state, TDA1004X_CONFC1) & 0x20)
  637. fe_params->inversion = INVERSION_ON;
  638. if (state->config->invert)
  639. fe_params->inversion = fe_params->inversion ? INVERSION_OFF : INVERSION_ON;
  640. // bandwidth
  641. switch (state->demod_type) {
  642. case TDA1004X_DEMOD_TDA10045:
  643. switch (tda1004x_read_byte(state, TDA10045H_WREF_LSB)) {
  644. case 0x14:
  645. fe_params->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
  646. break;
  647. case 0xdb:
  648. fe_params->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
  649. break;
  650. case 0x4f:
  651. fe_params->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
  652. break;
  653. }
  654. break;
  655. case TDA1004X_DEMOD_TDA10046:
  656. switch (tda1004x_read_byte(state, TDA10046H_TIME_WREF1)) {
  657. case 0x60:
  658. fe_params->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
  659. break;
  660. case 0x6e:
  661. fe_params->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
  662. break;
  663. case 0x80:
  664. fe_params->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
  665. break;
  666. }
  667. break;
  668. }
  669. // FEC
  670. fe_params->u.ofdm.code_rate_HP =
  671. tda1004x_decode_fec(tda1004x_read_byte(state, TDA1004X_OUT_CONF2) & 7);
  672. fe_params->u.ofdm.code_rate_LP =
  673. tda1004x_decode_fec((tda1004x_read_byte(state, TDA1004X_OUT_CONF2) >> 3) & 7);
  674. // constellation
  675. switch (tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 3) {
  676. case 0:
  677. fe_params->u.ofdm.constellation = QPSK;
  678. break;
  679. case 1:
  680. fe_params->u.ofdm.constellation = QAM_16;
  681. break;
  682. case 2:
  683. fe_params->u.ofdm.constellation = QAM_64;
  684. break;
  685. }
  686. // transmission mode
  687. fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
  688. if (tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x10)
  689. fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
  690. // guard interval
  691. switch ((tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x0c) >> 2) {
  692. case 0:
  693. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
  694. break;
  695. case 1:
  696. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_16;
  697. break;
  698. case 2:
  699. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_8;
  700. break;
  701. case 3:
  702. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_4;
  703. break;
  704. }
  705. // hierarchy
  706. switch ((tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x60) >> 5) {
  707. case 0:
  708. fe_params->u.ofdm.hierarchy_information = HIERARCHY_NONE;
  709. break;
  710. case 1:
  711. fe_params->u.ofdm.hierarchy_information = HIERARCHY_1;
  712. break;
  713. case 2:
  714. fe_params->u.ofdm.hierarchy_information = HIERARCHY_2;
  715. break;
  716. case 3:
  717. fe_params->u.ofdm.hierarchy_information = HIERARCHY_4;
  718. break;
  719. }
  720. return 0;
  721. }
  722. static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status)
  723. {
  724. struct tda1004x_state* state = fe->demodulator_priv;
  725. int status;
  726. int cber;
  727. int vber;
  728. dprintk("%s\n", __FUNCTION__);
  729. // read status
  730. status = tda1004x_read_byte(state, TDA1004X_STATUS_CD);
  731. if (status == -1)
  732. return -EIO;
  733. // decode
  734. *fe_status = 0;
  735. if (status & 4)
  736. *fe_status |= FE_HAS_SIGNAL;
  737. if (status & 2)
  738. *fe_status |= FE_HAS_CARRIER;
  739. if (status & 8)
  740. *fe_status |= FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
  741. // if we don't already have VITERBI (i.e. not LOCKED), see if the viterbi
  742. // is getting anything valid
  743. if (!(*fe_status & FE_HAS_VITERBI)) {
  744. // read the CBER
  745. cber = tda1004x_read_byte(state, TDA1004X_CBER_LSB);
  746. if (cber == -1)
  747. return -EIO;
  748. status = tda1004x_read_byte(state, TDA1004X_CBER_MSB);
  749. if (status == -1)
  750. return -EIO;
  751. cber |= (status << 8);
  752. tda1004x_read_byte(state, TDA1004X_CBER_RESET);
  753. if (cber != 65535)
  754. *fe_status |= FE_HAS_VITERBI;
  755. }
  756. // if we DO have some valid VITERBI output, but don't already have SYNC
  757. // bytes (i.e. not LOCKED), see if the RS decoder is getting anything valid.
  758. if ((*fe_status & FE_HAS_VITERBI) && (!(*fe_status & FE_HAS_SYNC))) {
  759. // read the VBER
  760. vber = tda1004x_read_byte(state, TDA1004X_VBER_LSB);
  761. if (vber == -1)
  762. return -EIO;
  763. status = tda1004x_read_byte(state, TDA1004X_VBER_MID);
  764. if (status == -1)
  765. return -EIO;
  766. vber |= (status << 8);
  767. status = tda1004x_read_byte(state, TDA1004X_VBER_MSB);
  768. if (status == -1)
  769. return -EIO;
  770. vber |= ((status << 16) & 0x0f);
  771. tda1004x_read_byte(state, TDA1004X_CVBER_LUT);
  772. // if RS has passed some valid TS packets, then we must be
  773. // getting some SYNC bytes
  774. if (vber < 16632)
  775. *fe_status |= FE_HAS_SYNC;
  776. }
  777. // success
  778. dprintk("%s: fe_status=0x%x\n", __FUNCTION__, *fe_status);
  779. return 0;
  780. }
  781. static int tda1004x_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
  782. {
  783. struct tda1004x_state* state = fe->demodulator_priv;
  784. int tmp;
  785. int reg = 0;
  786. dprintk("%s\n", __FUNCTION__);
  787. // determine the register to use
  788. switch (state->demod_type) {
  789. case TDA1004X_DEMOD_TDA10045:
  790. reg = TDA10045H_S_AGC;
  791. break;
  792. case TDA1004X_DEMOD_TDA10046:
  793. reg = TDA10046H_AGC_IF_LEVEL;
  794. break;
  795. }
  796. // read it
  797. tmp = tda1004x_read_byte(state, reg);
  798. if (tmp < 0)
  799. return -EIO;
  800. *signal = (tmp << 8) | tmp;
  801. dprintk("%s: signal=0x%x\n", __FUNCTION__, *signal);
  802. return 0;
  803. }
  804. static int tda1004x_read_snr(struct dvb_frontend* fe, u16 * snr)
  805. {
  806. struct tda1004x_state* state = fe->demodulator_priv;
  807. int tmp;
  808. dprintk("%s\n", __FUNCTION__);
  809. // read it
  810. tmp = tda1004x_read_byte(state, TDA1004X_SNR);
  811. if (tmp < 0)
  812. return -EIO;
  813. if (tmp)
  814. tmp = 255 - tmp;
  815. *snr = ((tmp << 8) | tmp);
  816. dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr);
  817. return 0;
  818. }
  819. static int tda1004x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
  820. {
  821. struct tda1004x_state* state = fe->demodulator_priv;
  822. int tmp;
  823. int tmp2;
  824. int counter;
  825. dprintk("%s\n", __FUNCTION__);
  826. // read the UCBLOCKS and reset
  827. counter = 0;
  828. tmp = tda1004x_read_byte(state, TDA1004X_UNCOR);
  829. if (tmp < 0)
  830. return -EIO;
  831. tmp &= 0x7f;
  832. while (counter++ < 5) {
  833. tda1004x_write_mask(state, TDA1004X_UNCOR, 0x80, 0);
  834. tda1004x_write_mask(state, TDA1004X_UNCOR, 0x80, 0);
  835. tda1004x_write_mask(state, TDA1004X_UNCOR, 0x80, 0);
  836. tmp2 = tda1004x_read_byte(state, TDA1004X_UNCOR);
  837. if (tmp2 < 0)
  838. return -EIO;
  839. tmp2 &= 0x7f;
  840. if ((tmp2 < tmp) || (tmp2 == 0))
  841. break;
  842. }
  843. if (tmp != 0x7f)
  844. *ucblocks = tmp;
  845. else
  846. *ucblocks = 0xffffffff;
  847. dprintk("%s: ucblocks=0x%x\n", __FUNCTION__, *ucblocks);
  848. return 0;
  849. }
  850. static int tda1004x_read_ber(struct dvb_frontend* fe, u32* ber)
  851. {
  852. struct tda1004x_state* state = fe->demodulator_priv;
  853. int tmp;
  854. dprintk("%s\n", __FUNCTION__);
  855. // read it in
  856. tmp = tda1004x_read_byte(state, TDA1004X_CBER_LSB);
  857. if (tmp < 0)
  858. return -EIO;
  859. *ber = tmp << 1;
  860. tmp = tda1004x_read_byte(state, TDA1004X_CBER_MSB);
  861. if (tmp < 0)
  862. return -EIO;
  863. *ber |= (tmp << 9);
  864. tda1004x_read_byte(state, TDA1004X_CBER_RESET);
  865. dprintk("%s: ber=0x%x\n", __FUNCTION__, *ber);
  866. return 0;
  867. }
  868. static int tda1004x_sleep(struct dvb_frontend* fe)
  869. {
  870. struct tda1004x_state* state = fe->demodulator_priv;
  871. switch (state->demod_type) {
  872. case TDA1004X_DEMOD_TDA10045:
  873. tda1004x_write_mask(state, TDA1004X_CONFADC1, 0x10, 0x10);
  874. break;
  875. case TDA1004X_DEMOD_TDA10046:
  876. tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 1);
  877. break;
  878. }
  879. state->initialised = 0;
  880. return 0;
  881. }
  882. static int tda1004x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
  883. {
  884. fesettings->min_delay_ms = 800;
  885. fesettings->step_size = 166667;
  886. fesettings->max_drift = 166667*2;
  887. return 0;
  888. }
  889. static void tda1004x_release(struct dvb_frontend* fe)
  890. {
  891. struct tda1004x_state *state = fe->demodulator_priv;
  892. kfree(state);
  893. }
  894. static struct dvb_frontend_ops tda10045_ops = {
  895. .info = {
  896. .name = "Philips TDA10045H DVB-T",
  897. .type = FE_OFDM,
  898. .frequency_min = 51000000,
  899. .frequency_max = 858000000,
  900. .frequency_stepsize = 166667,
  901. .caps =
  902. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  903. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  904. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  905. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
  906. },
  907. .release = tda1004x_release,
  908. .init = tda10045_init,
  909. .sleep = tda1004x_sleep,
  910. .set_frontend = tda1004x_set_fe,
  911. .get_frontend = tda1004x_get_fe,
  912. .get_tune_settings = tda1004x_get_tune_settings,
  913. .read_status = tda1004x_read_status,
  914. .read_ber = tda1004x_read_ber,
  915. .read_signal_strength = tda1004x_read_signal_strength,
  916. .read_snr = tda1004x_read_snr,
  917. .read_ucblocks = tda1004x_read_ucblocks,
  918. };
  919. struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
  920. struct i2c_adapter* i2c)
  921. {
  922. struct tda1004x_state *state;
  923. /* allocate memory for the internal state */
  924. state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
  925. if (!state)
  926. return NULL;
  927. /* setup the state */
  928. state->config = config;
  929. state->i2c = i2c;
  930. memcpy(&state->ops, &tda10045_ops, sizeof(struct dvb_frontend_ops));
  931. state->initialised = 0;
  932. state->demod_type = TDA1004X_DEMOD_TDA10045;
  933. /* check if the demod is there */
  934. if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x25) {
  935. kfree(state);
  936. return NULL;
  937. }
  938. /* create dvb_frontend */
  939. state->frontend.ops = &state->ops;
  940. state->frontend.demodulator_priv = state;
  941. return &state->frontend;
  942. }
  943. static struct dvb_frontend_ops tda10046_ops = {
  944. .info = {
  945. .name = "Philips TDA10046H DVB-T",
  946. .type = FE_OFDM,
  947. .frequency_min = 51000000,
  948. .frequency_max = 858000000,
  949. .frequency_stepsize = 166667,
  950. .caps =
  951. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  952. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  953. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  954. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
  955. },
  956. .release = tda1004x_release,
  957. .init = tda10046_init,
  958. .sleep = tda1004x_sleep,
  959. .set_frontend = tda1004x_set_fe,
  960. .get_frontend = tda1004x_get_fe,
  961. .get_tune_settings = tda1004x_get_tune_settings,
  962. .read_status = tda1004x_read_status,
  963. .read_ber = tda1004x_read_ber,
  964. .read_signal_strength = tda1004x_read_signal_strength,
  965. .read_snr = tda1004x_read_snr,
  966. .read_ucblocks = tda1004x_read_ucblocks,
  967. };
  968. struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
  969. struct i2c_adapter* i2c)
  970. {
  971. struct tda1004x_state *state;
  972. /* allocate memory for the internal state */
  973. state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
  974. if (!state)
  975. return NULL;
  976. /* setup the state */
  977. state->config = config;
  978. state->i2c = i2c;
  979. memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops));
  980. state->initialised = 0;
  981. state->demod_type = TDA1004X_DEMOD_TDA10046;
  982. /* check if the demod is there */
  983. if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) {
  984. kfree(state);
  985. return NULL;
  986. }
  987. /* create dvb_frontend */
  988. state->frontend.ops = &state->ops;
  989. state->frontend.demodulator_priv = state;
  990. return &state->frontend;
  991. }
  992. module_param(debug, int, 0644);
  993. MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
  994. MODULE_DESCRIPTION("Philips TDA10045H & TDA10046H DVB-T Demodulator");
  995. MODULE_AUTHOR("Andrew de Quincey & Robert Schlabbach");
  996. MODULE_LICENSE("GPL");
  997. EXPORT_SYMBOL(tda10045_attach);
  998. EXPORT_SYMBOL(tda10046_attach);
  999. EXPORT_SYMBOL(tda1004x_write_byte);