tda1004x.c 33 KB

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