tda1004x.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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(KERN_ERR "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. // give the DSP a chance to settle 03/10/05 Hac
  264. msleep(100);
  265. return 0;
  266. }
  267. static int tda1004x_check_upload_ok(struct tda1004x_state *state)
  268. {
  269. u8 data1, data2;
  270. unsigned long timeout;
  271. if (state->demod_type == TDA1004X_DEMOD_TDA10046) {
  272. timeout = jiffies + 2 * HZ;
  273. while(!(tda1004x_read_byte(state, TDA1004X_STATUS_CD) & 0x20)) {
  274. if (time_after(jiffies, timeout)) {
  275. printk(KERN_ERR "tda1004x: timeout waiting for DSP ready\n");
  276. break;
  277. }
  278. msleep(1);
  279. }
  280. } else
  281. msleep(100);
  282. // check upload was OK
  283. tda1004x_write_mask(state, TDA1004X_CONFC4, 0x10, 0); // we want to read from the DSP
  284. tda1004x_write_byteI(state, TDA1004X_DSP_CMD, 0x67);
  285. data1 = tda1004x_read_byte(state, TDA1004X_DSP_DATA1);
  286. data2 = tda1004x_read_byte(state, TDA1004X_DSP_DATA2);
  287. if (data1 != 0x67 || data2 < 0x20 || data2 > 0x2e) {
  288. printk(KERN_INFO "tda1004x: found firmware revision %x -- invalid\n", data2);
  289. return -EIO;
  290. }
  291. printk(KERN_INFO "tda1004x: found firmware revision %x -- ok\n", data2);
  292. return 0;
  293. }
  294. static int tda10045_fwupload(struct dvb_frontend* fe)
  295. {
  296. struct tda1004x_state* state = fe->demodulator_priv;
  297. int ret;
  298. const struct firmware *fw;
  299. /* don't re-upload unless necessary */
  300. if (tda1004x_check_upload_ok(state) == 0)
  301. return 0;
  302. /* request the firmware, this will block until someone uploads it */
  303. printk(KERN_INFO "tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE);
  304. ret = state->config->request_firmware(fe, &fw, TDA10045_DEFAULT_FIRMWARE);
  305. if (ret) {
  306. printk(KERN_ERR "tda1004x: no firmware upload (timeout or file not found?)\n");
  307. return ret;
  308. }
  309. /* reset chip */
  310. tda1004x_write_mask(state, TDA1004X_CONFC4, 0x10, 0);
  311. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8);
  312. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 0);
  313. msleep(10);
  314. /* set parameters */
  315. tda10045h_set_bandwidth(state, BANDWIDTH_8_MHZ);
  316. ret = tda1004x_do_upload(state, fw->data, fw->size, TDA10045H_FWPAGE, TDA10045H_CODE_IN);
  317. if (ret)
  318. return ret;
  319. printk(KERN_INFO "tda1004x: firmware upload complete\n");
  320. /* wait for DSP to initialise */
  321. /* DSPREADY doesn't seem to work on the TDA10045H */
  322. msleep(100);
  323. return tda1004x_check_upload_ok(state);
  324. }
  325. static void tda10046_init_plls(struct dvb_frontend* fe)
  326. {
  327. struct tda1004x_state* state = fe->demodulator_priv;
  328. tda1004x_write_byteI(state, TDA10046H_CONFPLL1, 0xf0);
  329. tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 10); // PLL M = 10
  330. if (state->config->xtal_freq == TDA10046_XTAL_4M ) {
  331. dprintk("%s: setting up PLLs for a 4 MHz Xtal\n", __FUNCTION__);
  332. tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 0); // PLL P = N = 0
  333. } else {
  334. dprintk("%s: setting up PLLs for a 16 MHz Xtal\n", __FUNCTION__);
  335. tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 3); // PLL P = 0, N = 3
  336. }
  337. tda1004x_write_byteI(state, TDA10046H_FREQ_OFFSET, 99);
  338. switch (state->config->if_freq) {
  339. case TDA10046_FREQ_3617:
  340. tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4);
  341. tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x2c);
  342. break;
  343. case TDA10046_FREQ_3613:
  344. tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_MSB, 0xd4);
  345. tda1004x_write_byteI(state, TDA10046H_FREQ_PHY2_LSB, 0x13);
  346. break;
  347. }
  348. tda10046h_set_bandwidth(state, BANDWIDTH_8_MHZ); // default bandwidth 8 MHz
  349. }
  350. static int tda10046_fwupload(struct dvb_frontend* fe)
  351. {
  352. struct tda1004x_state* state = fe->demodulator_priv;
  353. int ret;
  354. const struct firmware *fw;
  355. /* reset + wake up chip */
  356. tda1004x_write_byteI(state, TDA1004X_CONFC4, 0);
  357. tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0);
  358. /* let the clocks recover from sleep */
  359. msleep(5);
  360. /* don't re-upload unless necessary */
  361. if (tda1004x_check_upload_ok(state) == 0)
  362. return 0;
  363. /* set parameters */
  364. tda10046_init_plls(fe);
  365. if (state->config->request_firmware != NULL) {
  366. /* request the firmware, this will block until someone uploads it */
  367. printk(KERN_INFO "tda1004x: waiting for firmware upload...\n");
  368. ret = state->config->request_firmware(fe, &fw, TDA10046_DEFAULT_FIRMWARE);
  369. if (ret) {
  370. printk(KERN_ERR "tda1004x: no firmware upload (timeout or file not found?)\n");
  371. return ret;
  372. }
  373. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8); // going to boot from HOST
  374. ret = tda1004x_do_upload(state, fw->data, fw->size, TDA10046H_CODE_CPT, TDA10046H_CODE_IN);
  375. if (ret)
  376. return ret;
  377. } else {
  378. /* boot from firmware eeprom */
  379. /* Hac Note: we might need to do some GPIO Magic here */
  380. printk(KERN_INFO "tda1004x: booting from eeprom\n");
  381. tda1004x_write_mask(state, TDA1004X_CONFC4, 4, 4);
  382. msleep(300);
  383. }
  384. return tda1004x_check_upload_ok(state);
  385. }
  386. static int tda1004x_encode_fec(int fec)
  387. {
  388. // convert known FEC values
  389. switch (fec) {
  390. case FEC_1_2:
  391. return 0;
  392. case FEC_2_3:
  393. return 1;
  394. case FEC_3_4:
  395. return 2;
  396. case FEC_5_6:
  397. return 3;
  398. case FEC_7_8:
  399. return 4;
  400. }
  401. // unsupported
  402. return -EINVAL;
  403. }
  404. static int tda1004x_decode_fec(int tdafec)
  405. {
  406. // convert known FEC values
  407. switch (tdafec) {
  408. case 0:
  409. return FEC_1_2;
  410. case 1:
  411. return FEC_2_3;
  412. case 2:
  413. return FEC_3_4;
  414. case 3:
  415. return FEC_5_6;
  416. case 4:
  417. return FEC_7_8;
  418. }
  419. // unsupported
  420. return -1;
  421. }
  422. int tda1004x_write_byte(struct dvb_frontend* fe, int reg, int data)
  423. {
  424. struct tda1004x_state* state = fe->demodulator_priv;
  425. return tda1004x_write_byteI(state, reg, data);
  426. }
  427. static int tda10045_init(struct dvb_frontend* fe)
  428. {
  429. struct tda1004x_state* state = fe->demodulator_priv;
  430. dprintk("%s\n", __FUNCTION__);
  431. if (state->initialised)
  432. return 0;
  433. if (tda10045_fwupload(fe)) {
  434. printk("tda1004x: firmware upload failed\n");
  435. return -EIO;
  436. }
  437. tda1004x_write_mask(state, TDA1004X_CONFADC1, 0x10, 0); // wake up the ADC
  438. // Init the PLL
  439. if (state->config->pll_init) {
  440. tda1004x_enable_tuner_i2c(state);
  441. state->config->pll_init(fe);
  442. tda1004x_disable_tuner_i2c(state);
  443. }
  444. // tda setup
  445. tda1004x_write_mask(state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer
  446. tda1004x_write_mask(state, TDA1004X_AUTO, 8, 0); // select HP stream
  447. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x40, 0); // set polarity of VAGC signal
  448. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x80, 0x80); // enable pulse killer
  449. tda1004x_write_mask(state, TDA1004X_AUTO, 0x10, 0x10); // enable auto offset
  450. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0xC0, 0x0); // no frequency offset
  451. tda1004x_write_byteI(state, TDA1004X_CONF_TS1, 0); // setup MPEG2 TS interface
  452. tda1004x_write_byteI(state, TDA1004X_CONF_TS2, 0); // setup MPEG2 TS interface
  453. tda1004x_write_mask(state, TDA1004X_VBER_MSB, 0xe0, 0xa0); // 10^6 VBER measurement bits
  454. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x10, 0); // VAGC polarity
  455. tda1004x_write_byteI(state, TDA1004X_CONFADC1, 0x2e);
  456. tda1004x_write_mask(state, 0x1f, 0x01, state->config->invert_oclk);
  457. state->initialised = 1;
  458. return 0;
  459. }
  460. static int tda10046_init(struct dvb_frontend* fe)
  461. {
  462. struct tda1004x_state* state = fe->demodulator_priv;
  463. dprintk("%s\n", __FUNCTION__);
  464. if (state->initialised)
  465. return 0;
  466. if (tda10046_fwupload(fe)) {
  467. printk("tda1004x: firmware upload failed\n");
  468. return -EIO;
  469. }
  470. // Init the tuner PLL
  471. if (state->config->pll_init) {
  472. tda1004x_enable_tuner_i2c(state);
  473. state->config->pll_init(fe);
  474. tda1004x_disable_tuner_i2c(state);
  475. }
  476. // tda setup
  477. tda1004x_write_mask(state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer
  478. tda1004x_write_byteI(state, TDA1004X_AUTO, 7); // select HP stream
  479. tda1004x_write_byteI(state, TDA1004X_CONFC1, 8); // disable pulse killer
  480. tda10046_init_plls(fe);
  481. switch (state->config->agc_config) {
  482. case TDA10046_AGC_DEFAULT:
  483. tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x00); // AGC setup
  484. tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x60); // set AGC polarities
  485. break;
  486. case TDA10046_AGC_IFO_AUTO_NEG:
  487. tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x0a); // AGC setup
  488. tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x60); // set AGC polarities
  489. break;
  490. }
  491. tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE1, 0x61); // Turn both AGC outputs on
  492. tda1004x_write_byteI(state, TDA10046H_AGC_TUN_MIN, 0); // }
  493. tda1004x_write_byteI(state, TDA10046H_AGC_TUN_MAX, 0xff); // } AGC min/max values
  494. tda1004x_write_byteI(state, TDA10046H_AGC_IF_MIN, 0); // }
  495. tda1004x_write_byteI(state, TDA10046H_AGC_IF_MAX, 0xff); // }
  496. tda1004x_write_byteI(state, TDA10046H_AGC_GAINS, 1); // IF gain 2, TUN gain 1
  497. tda1004x_write_byteI(state, TDA10046H_CVBER_CTRL, 0x1a); // 10^6 VBER measurement bits
  498. tda1004x_write_byteI(state, TDA1004X_CONF_TS1, 7); // MPEG2 interface config
  499. tda1004x_write_byteI(state, TDA1004X_CONF_TS2, 0xc0); // MPEG2 interface config
  500. tda1004x_write_mask(state, 0x3a, 0x80, state->config->invert_oclk << 7);
  501. tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE2, 0xe1); // tristate setup
  502. tda1004x_write_byteI(state, TDA10046H_GPIO_OUT_SEL, 0xcc); // GPIO output config
  503. tda1004x_write_byteI(state, TDA10046H_GPIO_SELECT, 8); // GPIO select
  504. state->initialised = 1;
  505. return 0;
  506. }
  507. static int tda1004x_set_fe(struct dvb_frontend* fe,
  508. struct dvb_frontend_parameters *fe_params)
  509. {
  510. struct tda1004x_state* state = fe->demodulator_priv;
  511. int tmp;
  512. int inversion;
  513. dprintk("%s\n", __FUNCTION__);
  514. if (state->demod_type == TDA1004X_DEMOD_TDA10046) {
  515. // setup auto offset
  516. tda1004x_write_mask(state, TDA1004X_AUTO, 0x10, 0x10);
  517. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x80, 0);
  518. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0xC0, 0);
  519. // disable agc_conf[2]
  520. tda1004x_write_mask(state, TDA10046H_AGC_CONF, 4, 0);
  521. }
  522. // set frequency
  523. tda1004x_enable_tuner_i2c(state);
  524. state->config->pll_set(fe, fe_params);
  525. tda1004x_disable_tuner_i2c(state);
  526. // Hardcoded to use auto as much as possible on the TDA10045 as it
  527. // is very unreliable if AUTO mode is _not_ used.
  528. if (state->demod_type == TDA1004X_DEMOD_TDA10045) {
  529. fe_params->u.ofdm.code_rate_HP = FEC_AUTO;
  530. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
  531. fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
  532. }
  533. // Set standard params.. or put them to auto
  534. if ((fe_params->u.ofdm.code_rate_HP == FEC_AUTO) ||
  535. (fe_params->u.ofdm.code_rate_LP == FEC_AUTO) ||
  536. (fe_params->u.ofdm.constellation == QAM_AUTO) ||
  537. (fe_params->u.ofdm.hierarchy_information == HIERARCHY_AUTO)) {
  538. tda1004x_write_mask(state, TDA1004X_AUTO, 1, 1); // enable auto
  539. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x03, 0); // turn off constellation bits
  540. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 0); // turn off hierarchy bits
  541. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0x3f, 0); // turn off FEC bits
  542. } else {
  543. tda1004x_write_mask(state, TDA1004X_AUTO, 1, 0); // disable auto
  544. // set HP FEC
  545. tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_HP);
  546. if (tmp < 0)
  547. return tmp;
  548. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 7, tmp);
  549. // set LP FEC
  550. tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_LP);
  551. if (tmp < 0)
  552. return tmp;
  553. tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0x38, tmp << 3);
  554. // set constellation
  555. switch (fe_params->u.ofdm.constellation) {
  556. case QPSK:
  557. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 3, 0);
  558. break;
  559. case QAM_16:
  560. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 3, 1);
  561. break;
  562. case QAM_64:
  563. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 3, 2);
  564. break;
  565. default:
  566. return -EINVAL;
  567. }
  568. // set hierarchy
  569. switch (fe_params->u.ofdm.hierarchy_information) {
  570. case HIERARCHY_NONE:
  571. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 0 << 5);
  572. break;
  573. case HIERARCHY_1:
  574. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 1 << 5);
  575. break;
  576. case HIERARCHY_2:
  577. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 2 << 5);
  578. break;
  579. case HIERARCHY_4:
  580. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x60, 3 << 5);
  581. break;
  582. default:
  583. return -EINVAL;
  584. }
  585. }
  586. // set bandwidth
  587. switch (state->demod_type) {
  588. case TDA1004X_DEMOD_TDA10045:
  589. tda10045h_set_bandwidth(state, fe_params->u.ofdm.bandwidth);
  590. break;
  591. case TDA1004X_DEMOD_TDA10046:
  592. tda10046h_set_bandwidth(state, fe_params->u.ofdm.bandwidth);
  593. break;
  594. }
  595. // set inversion
  596. inversion = fe_params->inversion;
  597. if (state->config->invert)
  598. inversion = inversion ? INVERSION_OFF : INVERSION_ON;
  599. switch (inversion) {
  600. case INVERSION_OFF:
  601. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x20, 0);
  602. break;
  603. case INVERSION_ON:
  604. tda1004x_write_mask(state, TDA1004X_CONFC1, 0x20, 0x20);
  605. break;
  606. default:
  607. return -EINVAL;
  608. }
  609. // set guard interval
  610. switch (fe_params->u.ofdm.guard_interval) {
  611. case GUARD_INTERVAL_1_32:
  612. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 0);
  613. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 0 << 2);
  614. break;
  615. case GUARD_INTERVAL_1_16:
  616. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 0);
  617. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 1 << 2);
  618. break;
  619. case GUARD_INTERVAL_1_8:
  620. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 0);
  621. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 2 << 2);
  622. break;
  623. case GUARD_INTERVAL_1_4:
  624. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 0);
  625. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 3 << 2);
  626. break;
  627. case GUARD_INTERVAL_AUTO:
  628. tda1004x_write_mask(state, TDA1004X_AUTO, 2, 2);
  629. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x0c, 0 << 2);
  630. break;
  631. default:
  632. return -EINVAL;
  633. }
  634. // set transmission mode
  635. switch (fe_params->u.ofdm.transmission_mode) {
  636. case TRANSMISSION_MODE_2K:
  637. tda1004x_write_mask(state, TDA1004X_AUTO, 4, 0);
  638. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x10, 0 << 4);
  639. break;
  640. case TRANSMISSION_MODE_8K:
  641. tda1004x_write_mask(state, TDA1004X_AUTO, 4, 0);
  642. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x10, 1 << 4);
  643. break;
  644. case TRANSMISSION_MODE_AUTO:
  645. tda1004x_write_mask(state, TDA1004X_AUTO, 4, 4);
  646. tda1004x_write_mask(state, TDA1004X_IN_CONF1, 0x10, 0);
  647. break;
  648. default:
  649. return -EINVAL;
  650. }
  651. // start the lock
  652. switch (state->demod_type) {
  653. case TDA1004X_DEMOD_TDA10045:
  654. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8);
  655. tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 0);
  656. break;
  657. case TDA1004X_DEMOD_TDA10046:
  658. tda1004x_write_mask(state, TDA1004X_AUTO, 0x40, 0x40);
  659. break;
  660. }
  661. msleep(10);
  662. return 0;
  663. }
  664. static int tda1004x_get_fe(struct dvb_frontend* fe, struct dvb_frontend_parameters *fe_params)
  665. {
  666. struct tda1004x_state* state = fe->demodulator_priv;
  667. dprintk("%s\n", __FUNCTION__);
  668. // inversion status
  669. fe_params->inversion = INVERSION_OFF;
  670. if (tda1004x_read_byte(state, TDA1004X_CONFC1) & 0x20)
  671. fe_params->inversion = INVERSION_ON;
  672. if (state->config->invert)
  673. fe_params->inversion = fe_params->inversion ? INVERSION_OFF : INVERSION_ON;
  674. // bandwidth
  675. switch (state->demod_type) {
  676. case TDA1004X_DEMOD_TDA10045:
  677. switch (tda1004x_read_byte(state, TDA10045H_WREF_LSB)) {
  678. case 0x14:
  679. fe_params->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
  680. break;
  681. case 0xdb:
  682. fe_params->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
  683. break;
  684. case 0x4f:
  685. fe_params->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
  686. break;
  687. }
  688. break;
  689. case TDA1004X_DEMOD_TDA10046:
  690. switch (tda1004x_read_byte(state, TDA10046H_TIME_WREF1)) {
  691. case 0x60:
  692. fe_params->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
  693. break;
  694. case 0x6e:
  695. fe_params->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
  696. break;
  697. case 0x80:
  698. fe_params->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
  699. break;
  700. }
  701. break;
  702. }
  703. // FEC
  704. fe_params->u.ofdm.code_rate_HP =
  705. tda1004x_decode_fec(tda1004x_read_byte(state, TDA1004X_OUT_CONF2) & 7);
  706. fe_params->u.ofdm.code_rate_LP =
  707. tda1004x_decode_fec((tda1004x_read_byte(state, TDA1004X_OUT_CONF2) >> 3) & 7);
  708. // constellation
  709. switch (tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 3) {
  710. case 0:
  711. fe_params->u.ofdm.constellation = QPSK;
  712. break;
  713. case 1:
  714. fe_params->u.ofdm.constellation = QAM_16;
  715. break;
  716. case 2:
  717. fe_params->u.ofdm.constellation = QAM_64;
  718. break;
  719. }
  720. // transmission mode
  721. fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
  722. if (tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x10)
  723. fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
  724. // guard interval
  725. switch ((tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x0c) >> 2) {
  726. case 0:
  727. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
  728. break;
  729. case 1:
  730. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_16;
  731. break;
  732. case 2:
  733. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_8;
  734. break;
  735. case 3:
  736. fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_4;
  737. break;
  738. }
  739. // hierarchy
  740. switch ((tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x60) >> 5) {
  741. case 0:
  742. fe_params->u.ofdm.hierarchy_information = HIERARCHY_NONE;
  743. break;
  744. case 1:
  745. fe_params->u.ofdm.hierarchy_information = HIERARCHY_1;
  746. break;
  747. case 2:
  748. fe_params->u.ofdm.hierarchy_information = HIERARCHY_2;
  749. break;
  750. case 3:
  751. fe_params->u.ofdm.hierarchy_information = HIERARCHY_4;
  752. break;
  753. }
  754. return 0;
  755. }
  756. static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status)
  757. {
  758. struct tda1004x_state* state = fe->demodulator_priv;
  759. int status;
  760. int cber;
  761. int vber;
  762. dprintk("%s\n", __FUNCTION__);
  763. // read status
  764. status = tda1004x_read_byte(state, TDA1004X_STATUS_CD);
  765. if (status == -1)
  766. return -EIO;
  767. // decode
  768. *fe_status = 0;
  769. if (status & 4)
  770. *fe_status |= FE_HAS_SIGNAL;
  771. if (status & 2)
  772. *fe_status |= FE_HAS_CARRIER;
  773. if (status & 8)
  774. *fe_status |= FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
  775. // if we don't already have VITERBI (i.e. not LOCKED), see if the viterbi
  776. // is getting anything valid
  777. if (!(*fe_status & FE_HAS_VITERBI)) {
  778. // read the CBER
  779. cber = tda1004x_read_byte(state, TDA1004X_CBER_LSB);
  780. if (cber == -1)
  781. return -EIO;
  782. status = tda1004x_read_byte(state, TDA1004X_CBER_MSB);
  783. if (status == -1)
  784. return -EIO;
  785. cber |= (status << 8);
  786. tda1004x_read_byte(state, TDA1004X_CBER_RESET);
  787. if (cber != 65535)
  788. *fe_status |= FE_HAS_VITERBI;
  789. }
  790. // if we DO have some valid VITERBI output, but don't already have SYNC
  791. // bytes (i.e. not LOCKED), see if the RS decoder is getting anything valid.
  792. if ((*fe_status & FE_HAS_VITERBI) && (!(*fe_status & FE_HAS_SYNC))) {
  793. // read the VBER
  794. vber = tda1004x_read_byte(state, TDA1004X_VBER_LSB);
  795. if (vber == -1)
  796. return -EIO;
  797. status = tda1004x_read_byte(state, TDA1004X_VBER_MID);
  798. if (status == -1)
  799. return -EIO;
  800. vber |= (status << 8);
  801. status = tda1004x_read_byte(state, TDA1004X_VBER_MSB);
  802. if (status == -1)
  803. return -EIO;
  804. vber |= ((status << 16) & 0x0f);
  805. tda1004x_read_byte(state, TDA1004X_CVBER_LUT);
  806. // if RS has passed some valid TS packets, then we must be
  807. // getting some SYNC bytes
  808. if (vber < 16632)
  809. *fe_status |= FE_HAS_SYNC;
  810. }
  811. // success
  812. dprintk("%s: fe_status=0x%x\n", __FUNCTION__, *fe_status);
  813. return 0;
  814. }
  815. static int tda1004x_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
  816. {
  817. struct tda1004x_state* state = fe->demodulator_priv;
  818. int tmp;
  819. int reg = 0;
  820. dprintk("%s\n", __FUNCTION__);
  821. // determine the register to use
  822. switch (state->demod_type) {
  823. case TDA1004X_DEMOD_TDA10045:
  824. reg = TDA10045H_S_AGC;
  825. break;
  826. case TDA1004X_DEMOD_TDA10046:
  827. reg = TDA10046H_AGC_IF_LEVEL;
  828. break;
  829. }
  830. // read it
  831. tmp = tda1004x_read_byte(state, reg);
  832. if (tmp < 0)
  833. return -EIO;
  834. *signal = (tmp << 8) | tmp;
  835. dprintk("%s: signal=0x%x\n", __FUNCTION__, *signal);
  836. return 0;
  837. }
  838. static int tda1004x_read_snr(struct dvb_frontend* fe, u16 * snr)
  839. {
  840. struct tda1004x_state* state = fe->demodulator_priv;
  841. int tmp;
  842. dprintk("%s\n", __FUNCTION__);
  843. // read it
  844. tmp = tda1004x_read_byte(state, TDA1004X_SNR);
  845. if (tmp < 0)
  846. return -EIO;
  847. if (tmp)
  848. tmp = 255 - tmp;
  849. *snr = ((tmp << 8) | tmp);
  850. dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr);
  851. return 0;
  852. }
  853. static int tda1004x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
  854. {
  855. struct tda1004x_state* state = fe->demodulator_priv;
  856. int tmp;
  857. int tmp2;
  858. int counter;
  859. dprintk("%s\n", __FUNCTION__);
  860. // read the UCBLOCKS and reset
  861. counter = 0;
  862. tmp = tda1004x_read_byte(state, TDA1004X_UNCOR);
  863. if (tmp < 0)
  864. return -EIO;
  865. tmp &= 0x7f;
  866. while (counter++ < 5) {
  867. tda1004x_write_mask(state, TDA1004X_UNCOR, 0x80, 0);
  868. tda1004x_write_mask(state, TDA1004X_UNCOR, 0x80, 0);
  869. tda1004x_write_mask(state, TDA1004X_UNCOR, 0x80, 0);
  870. tmp2 = tda1004x_read_byte(state, TDA1004X_UNCOR);
  871. if (tmp2 < 0)
  872. return -EIO;
  873. tmp2 &= 0x7f;
  874. if ((tmp2 < tmp) || (tmp2 == 0))
  875. break;
  876. }
  877. if (tmp != 0x7f)
  878. *ucblocks = tmp;
  879. else
  880. *ucblocks = 0xffffffff;
  881. dprintk("%s: ucblocks=0x%x\n", __FUNCTION__, *ucblocks);
  882. return 0;
  883. }
  884. static int tda1004x_read_ber(struct dvb_frontend* fe, u32* ber)
  885. {
  886. struct tda1004x_state* state = fe->demodulator_priv;
  887. int tmp;
  888. dprintk("%s\n", __FUNCTION__);
  889. // read it in
  890. tmp = tda1004x_read_byte(state, TDA1004X_CBER_LSB);
  891. if (tmp < 0)
  892. return -EIO;
  893. *ber = tmp << 1;
  894. tmp = tda1004x_read_byte(state, TDA1004X_CBER_MSB);
  895. if (tmp < 0)
  896. return -EIO;
  897. *ber |= (tmp << 9);
  898. tda1004x_read_byte(state, TDA1004X_CBER_RESET);
  899. dprintk("%s: ber=0x%x\n", __FUNCTION__, *ber);
  900. return 0;
  901. }
  902. static int tda1004x_sleep(struct dvb_frontend* fe)
  903. {
  904. struct tda1004x_state* state = fe->demodulator_priv;
  905. switch (state->demod_type) {
  906. case TDA1004X_DEMOD_TDA10045:
  907. tda1004x_write_mask(state, TDA1004X_CONFADC1, 0x10, 0x10);
  908. break;
  909. case TDA1004X_DEMOD_TDA10046:
  910. tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 1);
  911. if (state->config->pll_sleep != NULL)
  912. state->config->pll_sleep(fe);
  913. break;
  914. }
  915. state->initialised = 0;
  916. return 0;
  917. }
  918. static int tda1004x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
  919. {
  920. fesettings->min_delay_ms = 800;
  921. fesettings->step_size = 166667;
  922. fesettings->max_drift = 166667*2;
  923. return 0;
  924. }
  925. static void tda1004x_release(struct dvb_frontend* fe)
  926. {
  927. struct tda1004x_state *state = fe->demodulator_priv;
  928. kfree(state);
  929. }
  930. static struct dvb_frontend_ops tda10045_ops = {
  931. .info = {
  932. .name = "Philips TDA10045H DVB-T",
  933. .type = FE_OFDM,
  934. .frequency_min = 51000000,
  935. .frequency_max = 858000000,
  936. .frequency_stepsize = 166667,
  937. .caps =
  938. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  939. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  940. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  941. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
  942. },
  943. .release = tda1004x_release,
  944. .init = tda10045_init,
  945. .sleep = tda1004x_sleep,
  946. .set_frontend = tda1004x_set_fe,
  947. .get_frontend = tda1004x_get_fe,
  948. .get_tune_settings = tda1004x_get_tune_settings,
  949. .read_status = tda1004x_read_status,
  950. .read_ber = tda1004x_read_ber,
  951. .read_signal_strength = tda1004x_read_signal_strength,
  952. .read_snr = tda1004x_read_snr,
  953. .read_ucblocks = tda1004x_read_ucblocks,
  954. };
  955. struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
  956. struct i2c_adapter* i2c)
  957. {
  958. struct tda1004x_state *state;
  959. /* allocate memory for the internal state */
  960. state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
  961. if (!state)
  962. return NULL;
  963. /* setup the state */
  964. state->config = config;
  965. state->i2c = i2c;
  966. memcpy(&state->ops, &tda10045_ops, sizeof(struct dvb_frontend_ops));
  967. state->initialised = 0;
  968. state->demod_type = TDA1004X_DEMOD_TDA10045;
  969. /* check if the demod is there */
  970. if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x25) {
  971. kfree(state);
  972. return NULL;
  973. }
  974. /* create dvb_frontend */
  975. state->frontend.ops = &state->ops;
  976. state->frontend.demodulator_priv = state;
  977. return &state->frontend;
  978. }
  979. static struct dvb_frontend_ops tda10046_ops = {
  980. .info = {
  981. .name = "Philips TDA10046H DVB-T",
  982. .type = FE_OFDM,
  983. .frequency_min = 51000000,
  984. .frequency_max = 858000000,
  985. .frequency_stepsize = 166667,
  986. .caps =
  987. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  988. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  989. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  990. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
  991. },
  992. .release = tda1004x_release,
  993. .init = tda10046_init,
  994. .sleep = tda1004x_sleep,
  995. .set_frontend = tda1004x_set_fe,
  996. .get_frontend = tda1004x_get_fe,
  997. .get_tune_settings = tda1004x_get_tune_settings,
  998. .read_status = tda1004x_read_status,
  999. .read_ber = tda1004x_read_ber,
  1000. .read_signal_strength = tda1004x_read_signal_strength,
  1001. .read_snr = tda1004x_read_snr,
  1002. .read_ucblocks = tda1004x_read_ucblocks,
  1003. };
  1004. struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
  1005. struct i2c_adapter* i2c)
  1006. {
  1007. struct tda1004x_state *state;
  1008. /* allocate memory for the internal state */
  1009. state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL);
  1010. if (!state)
  1011. return NULL;
  1012. /* setup the state */
  1013. state->config = config;
  1014. state->i2c = i2c;
  1015. memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops));
  1016. state->initialised = 0;
  1017. state->demod_type = TDA1004X_DEMOD_TDA10046;
  1018. /* check if the demod is there */
  1019. if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) {
  1020. kfree(state);
  1021. return NULL;
  1022. }
  1023. /* create dvb_frontend */
  1024. state->frontend.ops = &state->ops;
  1025. state->frontend.demodulator_priv = state;
  1026. return &state->frontend;
  1027. }
  1028. module_param(debug, int, 0644);
  1029. MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
  1030. MODULE_DESCRIPTION("Philips TDA10045H & TDA10046H DVB-T Demodulator");
  1031. MODULE_AUTHOR("Andrew de Quincey & Robert Schlabbach");
  1032. MODULE_LICENSE("GPL");
  1033. EXPORT_SYMBOL(tda10045_attach);
  1034. EXPORT_SYMBOL(tda10046_attach);
  1035. EXPORT_SYMBOL(tda1004x_write_byte);