dst.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  1. /*
  2. Frontend/Card driver for TwinHan DST Frontend
  3. Copyright (C) 2003 Jamie Honan
  4. Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/string.h>
  21. #include <linux/slab.h>
  22. #include <linux/vmalloc.h>
  23. #include <linux/delay.h>
  24. #include <asm/div64.h>
  25. #include "dvb_frontend.h"
  26. #include "dst_priv.h"
  27. #include "dst_common.h"
  28. static unsigned int verbose = 1;
  29. module_param(verbose, int, 0644);
  30. MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
  31. static unsigned int debug = 1;
  32. module_param(debug, int, 0644);
  33. MODULE_PARM_DESC(debug, "debug messages, default is 0 (yes)");
  34. static unsigned int dst_addons;
  35. module_param(dst_addons, int, 0644);
  36. MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
  37. #define dprintk if (debug) printk
  38. #define HAS_LOCK 1
  39. #define ATTEMPT_TUNE 2
  40. #define HAS_POWER 4
  41. static void dst_packsize(struct dst_state* state, int psize)
  42. {
  43. union dst_gpio_packet bits;
  44. bits.psize = psize;
  45. bt878_device_control(state->bt, DST_IG_TS, &bits);
  46. }
  47. int dst_gpio_outb(struct dst_state* state, u32 mask, u32 enbb, u32 outhigh, int delay)
  48. {
  49. union dst_gpio_packet enb;
  50. union dst_gpio_packet bits;
  51. int err;
  52. enb.enb.mask = mask;
  53. enb.enb.enable = enbb;
  54. if (verbose > 4)
  55. dprintk("%s: mask=[%04x], enbb=[%04x], outhigh=[%04x]\n", __FUNCTION__, mask, enbb, outhigh);
  56. if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
  57. dprintk("%s: dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)\n", __FUNCTION__, err, mask, enbb);
  58. return -EREMOTEIO;
  59. }
  60. udelay(1000);
  61. /* because complete disabling means no output, no need to do output packet */
  62. if (enbb == 0)
  63. return 0;
  64. if (delay)
  65. msleep(10);
  66. bits.outp.mask = enbb;
  67. bits.outp.highvals = outhigh;
  68. if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
  69. dprintk("%s: dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)\n", __FUNCTION__, err, enbb, outhigh);
  70. return -EREMOTEIO;
  71. }
  72. return 0;
  73. }
  74. EXPORT_SYMBOL(dst_gpio_outb);
  75. int dst_gpio_inb(struct dst_state *state, u8 * result)
  76. {
  77. union dst_gpio_packet rd_packet;
  78. int err;
  79. *result = 0;
  80. if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) {
  81. dprintk("%s: dst_gpio_inb error (err == %i)\n", __FUNCTION__, err);
  82. return -EREMOTEIO;
  83. }
  84. *result = (u8) rd_packet.rd.value;
  85. return 0;
  86. }
  87. EXPORT_SYMBOL(dst_gpio_inb);
  88. int rdc_reset_state(struct dst_state *state)
  89. {
  90. if (verbose > 1)
  91. dprintk("%s: Resetting state machine\n", __FUNCTION__);
  92. if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
  93. dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
  94. return -1;
  95. }
  96. msleep(10);
  97. if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
  98. dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
  99. msleep(10);
  100. return -1;
  101. }
  102. return 0;
  103. }
  104. EXPORT_SYMBOL(rdc_reset_state);
  105. int rdc_8820_reset(struct dst_state *state)
  106. {
  107. if (verbose > 1)
  108. dprintk("%s: Resetting DST\n", __FUNCTION__);
  109. if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
  110. dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
  111. return -1;
  112. }
  113. udelay(1000);
  114. if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
  115. dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
  116. return -1;
  117. }
  118. return 0;
  119. }
  120. EXPORT_SYMBOL(rdc_8820_reset);
  121. int dst_pio_enable(struct dst_state *state)
  122. {
  123. if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
  124. dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
  125. return -1;
  126. }
  127. udelay(1000);
  128. return 0;
  129. }
  130. EXPORT_SYMBOL(dst_pio_enable);
  131. int dst_pio_disable(struct dst_state *state)
  132. {
  133. if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) {
  134. dprintk("%s: dst_gpio_outb ERROR !\n", __FUNCTION__);
  135. return -1;
  136. }
  137. if (state->type_flags & DST_TYPE_HAS_FW_1)
  138. udelay(1000);
  139. return 0;
  140. }
  141. EXPORT_SYMBOL(dst_pio_disable);
  142. int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
  143. {
  144. u8 reply;
  145. int i;
  146. for (i = 0; i < 200; i++) {
  147. if (dst_gpio_inb(state, &reply) < 0) {
  148. dprintk("%s: dst_gpio_inb ERROR !\n", __FUNCTION__);
  149. return -1;
  150. }
  151. if ((reply & RDC_8820_PIO_0_ENABLE) == 0) {
  152. if (verbose > 4)
  153. dprintk("%s: dst wait ready after %d\n", __FUNCTION__, i);
  154. return 1;
  155. }
  156. msleep(10);
  157. }
  158. if (verbose > 1)
  159. dprintk("%s: dst wait NOT ready after %d\n", __FUNCTION__, i);
  160. return 0;
  161. }
  162. EXPORT_SYMBOL(dst_wait_dst_ready);
  163. int dst_error_recovery(struct dst_state *state)
  164. {
  165. dprintk("%s: Trying to return from previous errors...\n", __FUNCTION__);
  166. dst_pio_disable(state);
  167. msleep(10);
  168. dst_pio_enable(state);
  169. msleep(10);
  170. return 0;
  171. }
  172. EXPORT_SYMBOL(dst_error_recovery);
  173. int dst_error_bailout(struct dst_state *state)
  174. {
  175. dprintk("%s: Trying to bailout from previous error...\n", __FUNCTION__);
  176. rdc_8820_reset(state);
  177. dst_pio_disable(state);
  178. msleep(10);
  179. return 0;
  180. }
  181. EXPORT_SYMBOL(dst_error_bailout);
  182. int dst_comm_init(struct dst_state* state)
  183. {
  184. if (verbose > 1)
  185. dprintk ("%s: Initializing DST..\n", __FUNCTION__);
  186. if ((dst_pio_enable(state)) < 0) {
  187. dprintk("%s: PIO Enable Failed.\n", __FUNCTION__);
  188. return -1;
  189. }
  190. if ((rdc_reset_state(state)) < 0) {
  191. dprintk("%s: RDC 8820 State RESET Failed.\n", __FUNCTION__);
  192. return -1;
  193. }
  194. if (state->type_flags & DST_TYPE_HAS_FW_1)
  195. msleep(100);
  196. else
  197. msleep(5);
  198. return 0;
  199. }
  200. EXPORT_SYMBOL(dst_comm_init);
  201. int write_dst(struct dst_state *state, u8 *data, u8 len)
  202. {
  203. struct i2c_msg msg = {
  204. .addr = state->config->demod_address,.flags = 0,.buf = data,.len = len
  205. };
  206. int err;
  207. int cnt;
  208. if (debug && (verbose > 4)) {
  209. u8 i;
  210. if (verbose > 4) {
  211. dprintk("%s writing [ ", __FUNCTION__);
  212. for (i = 0; i < len; i++)
  213. dprintk("%02x ", data[i]);
  214. dprintk("]\n");
  215. }
  216. }
  217. for (cnt = 0; cnt < 2; cnt++) {
  218. if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
  219. dprintk("%s: _write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]);
  220. dst_error_recovery(state);
  221. continue;
  222. } else
  223. break;
  224. }
  225. if (cnt >= 2) {
  226. if (verbose > 1)
  227. printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
  228. dst_error_bailout(state);
  229. return -1;
  230. }
  231. return 0;
  232. }
  233. EXPORT_SYMBOL(write_dst);
  234. int read_dst(struct dst_state *state, u8 * ret, u8 len)
  235. {
  236. struct i2c_msg msg = {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = ret,.len = len };
  237. int err;
  238. int cnt;
  239. for (cnt = 0; cnt < 2; cnt++) {
  240. if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
  241. dprintk("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]);
  242. dst_error_recovery(state);
  243. continue;
  244. } else
  245. break;
  246. }
  247. if (cnt >= 2) {
  248. if (verbose > 1)
  249. printk("%s: RDC 8820 RESET...\n", __FUNCTION__);
  250. dst_error_bailout(state);
  251. return -1;
  252. }
  253. if (debug && (verbose > 4)) {
  254. dprintk("%s reply is 0x%x\n", __FUNCTION__, ret[0]);
  255. for (err = 1; err < len; err++)
  256. dprintk(" 0x%x", ret[err]);
  257. if (err > 1)
  258. dprintk("\n");
  259. }
  260. return 0;
  261. }
  262. EXPORT_SYMBOL(read_dst);
  263. static int dst_set_polarization(struct dst_state *state)
  264. {
  265. switch (state->voltage) {
  266. case SEC_VOLTAGE_13: // vertical
  267. printk("%s: Polarization=[Vertical]\n", __FUNCTION__);
  268. state->tx_tuna[8] &= ~0x40; //1
  269. break;
  270. case SEC_VOLTAGE_18: // horizontal
  271. printk("%s: Polarization=[Horizontal]\n", __FUNCTION__);
  272. state->tx_tuna[8] |= 0x40; // 0
  273. break;
  274. case SEC_VOLTAGE_OFF:
  275. break;
  276. }
  277. return 0;
  278. }
  279. static int dst_set_freq(struct dst_state *state, u32 freq)
  280. {
  281. state->frequency = freq;
  282. if (debug > 4)
  283. dprintk("%s: set Frequency %u\n", __FUNCTION__, freq);
  284. if (state->dst_type == DST_TYPE_IS_SAT) {
  285. freq = freq / 1000;
  286. if (freq < 950 || freq > 2150)
  287. return -EINVAL;
  288. state->tx_tuna[2] = (freq >> 8);
  289. state->tx_tuna[3] = (u8) freq;
  290. state->tx_tuna[4] = 0x01;
  291. state->tx_tuna[8] &= ~0x04;
  292. if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
  293. if (freq < 1531)
  294. state->tx_tuna[8] |= 0x04;
  295. }
  296. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  297. freq = freq / 1000;
  298. if (freq < 137000 || freq > 858000)
  299. return -EINVAL;
  300. state->tx_tuna[2] = (freq >> 16) & 0xff;
  301. state->tx_tuna[3] = (freq >> 8) & 0xff;
  302. state->tx_tuna[4] = (u8) freq;
  303. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  304. state->tx_tuna[2] = (freq >> 16) & 0xff;
  305. state->tx_tuna[3] = (freq >> 8) & 0xff;
  306. state->tx_tuna[4] = (u8) freq;
  307. } else
  308. return -EINVAL;
  309. return 0;
  310. }
  311. static int dst_set_bandwidth(struct dst_state* state, fe_bandwidth_t bandwidth)
  312. {
  313. state->bandwidth = bandwidth;
  314. if (state->dst_type != DST_TYPE_IS_TERR)
  315. return 0;
  316. switch (bandwidth) {
  317. case BANDWIDTH_6_MHZ:
  318. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  319. state->tx_tuna[7] = 0x06;
  320. else {
  321. state->tx_tuna[6] = 0x06;
  322. state->tx_tuna[7] = 0x00;
  323. }
  324. break;
  325. case BANDWIDTH_7_MHZ:
  326. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  327. state->tx_tuna[7] = 0x07;
  328. else {
  329. state->tx_tuna[6] = 0x07;
  330. state->tx_tuna[7] = 0x00;
  331. }
  332. break;
  333. case BANDWIDTH_8_MHZ:
  334. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  335. state->tx_tuna[7] = 0x08;
  336. else {
  337. state->tx_tuna[6] = 0x08;
  338. state->tx_tuna[7] = 0x00;
  339. }
  340. break;
  341. default:
  342. return -EINVAL;
  343. }
  344. return 0;
  345. }
  346. static int dst_set_inversion(struct dst_state* state, fe_spectral_inversion_t inversion)
  347. {
  348. state->inversion = inversion;
  349. switch (inversion) {
  350. case INVERSION_OFF: // Inversion = Normal
  351. state->tx_tuna[8] &= ~0x80;
  352. break;
  353. case INVERSION_ON:
  354. state->tx_tuna[8] |= 0x80;
  355. break;
  356. default:
  357. return -EINVAL;
  358. }
  359. return 0;
  360. }
  361. static int dst_set_fec(struct dst_state* state, fe_code_rate_t fec)
  362. {
  363. state->fec = fec;
  364. return 0;
  365. }
  366. static fe_code_rate_t dst_get_fec(struct dst_state* state)
  367. {
  368. return state->fec;
  369. }
  370. static int dst_set_symbolrate(struct dst_state* state, u32 srate)
  371. {
  372. u8 *val;
  373. u32 symcalc;
  374. u64 sval;
  375. state->symbol_rate = srate;
  376. if (state->dst_type == DST_TYPE_IS_TERR) {
  377. return 0;
  378. }
  379. if (debug > 4)
  380. dprintk("%s: set symrate %u\n", __FUNCTION__, srate);
  381. srate /= 1000;
  382. val = &state->tx_tuna[0];
  383. if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
  384. sval = srate;
  385. sval <<= 20;
  386. do_div(sval, 88000);
  387. symcalc = (u32) sval;
  388. if (debug > 4)
  389. dprintk("%s: set symcalc %u\n", __FUNCTION__, symcalc);
  390. val[5] = (u8) (symcalc >> 12);
  391. val[6] = (u8) (symcalc >> 4);
  392. val[7] = (u8) (symcalc << 4);
  393. } else {
  394. val[5] = (u8) (srate >> 16) & 0x7f;
  395. val[6] = (u8) (srate >> 8);
  396. val[7] = (u8) srate;
  397. }
  398. val[8] &= ~0x20;
  399. if (srate > 8000)
  400. val[8] |= 0x20;
  401. return 0;
  402. }
  403. static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
  404. {
  405. if (state->dst_type != DST_TYPE_IS_CABLE)
  406. return 0;
  407. state->modulation = modulation;
  408. switch (modulation) {
  409. case QAM_16:
  410. state->tx_tuna[8] = 0x10;
  411. break;
  412. case QAM_32:
  413. state->tx_tuna[8] = 0x20;
  414. break;
  415. case QAM_64:
  416. state->tx_tuna[8] = 0x40;
  417. break;
  418. case QAM_128:
  419. state->tx_tuna[8] = 0x80;
  420. break;
  421. case QAM_256:
  422. state->tx_tuna[8] = 0x00;
  423. break;
  424. case QPSK:
  425. case QAM_AUTO:
  426. case VSB_8:
  427. case VSB_16:
  428. default:
  429. return -EINVAL;
  430. }
  431. return 0;
  432. }
  433. static fe_modulation_t dst_get_modulation(struct dst_state *state)
  434. {
  435. return state->modulation;
  436. }
  437. u8 dst_check_sum(u8 * buf, u32 len)
  438. {
  439. u32 i;
  440. u8 val = 0;
  441. if (!len)
  442. return 0;
  443. for (i = 0; i < len; i++) {
  444. val += buf[i];
  445. }
  446. return ((~val) + 1);
  447. }
  448. EXPORT_SYMBOL(dst_check_sum);
  449. static void dst_type_flags_print(u32 type_flags)
  450. {
  451. printk("DST type flags :");
  452. if (type_flags & DST_TYPE_HAS_NEWTUNE)
  453. printk(" 0x%x newtuner", DST_TYPE_HAS_NEWTUNE);
  454. if (type_flags & DST_TYPE_HAS_TS204)
  455. printk(" 0x%x ts204", DST_TYPE_HAS_TS204);
  456. if (type_flags & DST_TYPE_HAS_SYMDIV)
  457. printk(" 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
  458. if (type_flags & DST_TYPE_HAS_FW_1)
  459. printk(" 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
  460. if (type_flags & DST_TYPE_HAS_FW_2)
  461. printk(" 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
  462. if (type_flags & DST_TYPE_HAS_FW_3)
  463. printk(" 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
  464. // if ((type_flags & DST_TYPE_HAS_FW_BUILD) && new_fw)
  465. printk("\n");
  466. }
  467. static int dst_type_print (u8 type)
  468. {
  469. char *otype;
  470. switch (type) {
  471. case DST_TYPE_IS_SAT:
  472. otype = "satellite";
  473. break;
  474. case DST_TYPE_IS_TERR:
  475. otype = "terrestrial";
  476. break;
  477. case DST_TYPE_IS_CABLE:
  478. otype = "cable";
  479. break;
  480. default:
  481. printk("%s: invalid dst type %d\n", __FUNCTION__, type);
  482. return -EINVAL;
  483. }
  484. printk("DST type : %s\n", otype);
  485. return 0;
  486. }
  487. /*
  488. Known cards list
  489. Satellite
  490. -------------------
  491. 200103A
  492. VP-1020 DST-MOT LG(old), TS=188
  493. VP-1020 DST-03T LG(new), TS=204
  494. VP-1022 DST-03T LG(new), TS=204
  495. VP-1025 DST-03T LG(new), TS=204
  496. VP-1030 DSTMCI, LG(new), TS=188
  497. VP-1032 DSTMCI, LG(new), TS=188
  498. Cable
  499. -------------------
  500. VP-2030 DCT-CI, Samsung, TS=204
  501. VP-2021 DCT-CI, Unknown, TS=204
  502. VP-2031 DCT-CI, Philips, TS=188
  503. VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
  504. VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
  505. Terrestrial
  506. -------------------
  507. VP-3050 DTTNXT TS=188
  508. VP-3040 DTT-CI, Philips, TS=188
  509. VP-3040 DTT-CI, Philips, TS=204
  510. ATSC
  511. -------------------
  512. VP-3220 ATSCDI, TS=188
  513. VP-3250 ATSCAD, TS=188
  514. */
  515. struct dst_types dst_tlist[] = {
  516. {
  517. .device_id = "200103A",
  518. .offset = 0,
  519. .dst_type = DST_TYPE_IS_SAT,
  520. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
  521. .dst_feature = 0
  522. }, /* obsolete */
  523. {
  524. .device_id = "DST-020",
  525. .offset = 0,
  526. .dst_type = DST_TYPE_IS_SAT,
  527. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
  528. .dst_feature = 0
  529. }, /* obsolete */
  530. {
  531. .device_id = "DST-030",
  532. .offset = 0,
  533. .dst_type = DST_TYPE_IS_SAT,
  534. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  535. .dst_feature = 0
  536. }, /* obsolete */
  537. {
  538. .device_id = "DST-03T",
  539. .offset = 0,
  540. .dst_type = DST_TYPE_IS_SAT,
  541. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
  542. .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
  543. | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO
  544. },
  545. {
  546. .device_id = "DST-MOT",
  547. .offset = 0,
  548. .dst_type = DST_TYPE_IS_SAT,
  549. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
  550. .dst_feature = 0
  551. }, /* obsolete */
  552. {
  553. .device_id = "DST-CI",
  554. .offset = 1,
  555. .dst_type = DST_TYPE_IS_SAT,
  556. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  557. .dst_feature = DST_TYPE_HAS_CA
  558. }, /* An OEM board */
  559. {
  560. .device_id = "DSTMCI",
  561. .offset = 1,
  562. .dst_type = DST_TYPE_IS_SAT,
  563. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
  564. .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
  565. | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
  566. },
  567. {
  568. .device_id = "DSTFCI",
  569. .offset = 1,
  570. .dst_type = DST_TYPE_IS_SAT,
  571. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  572. .dst_feature = 0
  573. }, /* unknown to vendor */
  574. {
  575. .device_id = "DCT-CI",
  576. .offset = 1,
  577. .dst_type = DST_TYPE_IS_CABLE,
  578. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1
  579. | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
  580. .dst_feature = DST_TYPE_HAS_CA
  581. },
  582. {
  583. .device_id = "DCTNEW",
  584. .offset = 1,
  585. .dst_type = DST_TYPE_IS_CABLE,
  586. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3,
  587. .dst_feature = 0
  588. },
  589. {
  590. .device_id = "DTT-CI",
  591. .offset = 1,
  592. .dst_type = DST_TYPE_IS_TERR,
  593. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
  594. .dst_feature = 0
  595. },
  596. {
  597. .device_id = "DTTDIG",
  598. .offset = 1,
  599. .dst_type = DST_TYPE_IS_TERR,
  600. .type_flags = DST_TYPE_HAS_FW_2,
  601. .dst_feature = 0
  602. },
  603. {
  604. .device_id = "DTTNXT",
  605. .offset = 1,
  606. .dst_type = DST_TYPE_IS_TERR,
  607. .type_flags = DST_TYPE_HAS_FW_2,
  608. .dst_feature = DST_TYPE_HAS_ANALOG
  609. },
  610. {
  611. .device_id = "ATSCDI",
  612. .offset = 1,
  613. .dst_type = DST_TYPE_IS_ATSC,
  614. .type_flags = DST_TYPE_HAS_FW_2,
  615. .dst_feature = 0
  616. },
  617. {
  618. .device_id = "ATSCAD",
  619. .offset = 1,
  620. .dst_type = DST_TYPE_IS_ATSC,
  621. .type_flags = DST_TYPE_HAS_FW_2,
  622. .dst_feature = 0
  623. },
  624. { }
  625. };
  626. static int dst_get_device_id(struct dst_state *state)
  627. {
  628. u8 reply;
  629. int i;
  630. struct dst_types *p_dst_type;
  631. u8 use_dst_type = 0;
  632. u32 use_type_flags = 0;
  633. static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
  634. device_type[7] = dst_check_sum(device_type, 7);
  635. if (write_dst(state, device_type, FIXED_COMM))
  636. return -1; /* Write failed */
  637. if ((dst_pio_disable(state)) < 0)
  638. return -1;
  639. if (read_dst(state, &reply, GET_ACK))
  640. return -1; /* Read failure */
  641. if (reply != ACK) {
  642. dprintk("%s: Write not Acknowledged! [Reply=0x%02x]\n", __FUNCTION__, reply);
  643. return -1; /* Unack'd write */
  644. }
  645. if (!dst_wait_dst_ready(state, DEVICE_INIT))
  646. return -1; /* DST not ready yet */
  647. if (read_dst(state, state->rxbuffer, FIXED_COMM))
  648. return -1;
  649. dst_pio_disable(state);
  650. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  651. dprintk("%s: Checksum failure! \n", __FUNCTION__);
  652. return -1; /* Checksum failure */
  653. }
  654. state->rxbuffer[7] = '\0';
  655. for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE (dst_tlist); i++, p_dst_type++) {
  656. if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
  657. use_type_flags = p_dst_type->type_flags;
  658. use_dst_type = p_dst_type->dst_type;
  659. /* Card capabilities */
  660. state->dst_hw_cap = p_dst_type->dst_feature;
  661. printk ("%s: Recognise [%s]\n", __FUNCTION__, p_dst_type->device_id);
  662. break;
  663. }
  664. }
  665. if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
  666. printk("%s: Unable to recognize %s or %s\n", __FUNCTION__, &state->rxbuffer[0], &state->rxbuffer[1]);
  667. printk("%s: please email linux-dvb@linuxtv.org with this type in\n", __FUNCTION__);
  668. use_dst_type = DST_TYPE_IS_SAT;
  669. use_type_flags = DST_TYPE_HAS_SYMDIV;
  670. }
  671. dst_type_print(use_dst_type);
  672. state->type_flags = use_type_flags;
  673. state->dst_type = use_dst_type;
  674. dst_type_flags_print(state->type_flags);
  675. if (state->type_flags & DST_TYPE_HAS_TS204) {
  676. dst_packsize(state, 204);
  677. }
  678. return 0;
  679. }
  680. static int dst_probe(struct dst_state *state)
  681. {
  682. if ((rdc_8820_reset(state)) < 0) {
  683. dprintk("%s: RDC 8820 RESET Failed.\n", __FUNCTION__);
  684. return -1;
  685. }
  686. if (dst_addons & DST_TYPE_HAS_CA)
  687. msleep(4000);
  688. else
  689. msleep(100);
  690. if ((dst_comm_init(state)) < 0) {
  691. dprintk("%s: DST Initialization Failed.\n", __FUNCTION__);
  692. return -1;
  693. }
  694. msleep(100);
  695. if (dst_get_device_id(state) < 0) {
  696. dprintk("%s: unknown device.\n", __FUNCTION__);
  697. return -1;
  698. }
  699. return 0;
  700. }
  701. int dst_command(struct dst_state* state, u8 * data, u8 len)
  702. {
  703. u8 reply;
  704. if ((dst_comm_init(state)) < 0) {
  705. dprintk("%s: DST Communication Initialization Failed.\n", __FUNCTION__);
  706. return -1;
  707. }
  708. if (write_dst(state, data, len)) {
  709. if (verbose > 1)
  710. dprintk("%s: Tring to recover.. \n", __FUNCTION__);
  711. if ((dst_error_recovery(state)) < 0) {
  712. dprintk("%s: Recovery Failed.\n", __FUNCTION__);
  713. return -1;
  714. }
  715. return -1;
  716. }
  717. if ((dst_pio_disable(state)) < 0) {
  718. dprintk("%s: PIO Disable Failed.\n", __FUNCTION__);
  719. return -1;
  720. }
  721. if (state->type_flags & DST_TYPE_HAS_FW_1)
  722. udelay(3000);
  723. if (read_dst(state, &reply, GET_ACK)) {
  724. if (verbose > 1)
  725. dprintk("%s: Trying to recover.. \n", __FUNCTION__);
  726. if ((dst_error_recovery(state)) < 0) {
  727. dprintk("%s: Recovery Failed.\n", __FUNCTION__);
  728. return -1;
  729. }
  730. return -1;
  731. }
  732. if (reply != ACK) {
  733. dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply);
  734. return -1;
  735. }
  736. if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
  737. return 0;
  738. // udelay(3000);
  739. if (state->type_flags & DST_TYPE_HAS_FW_1)
  740. udelay(3000);
  741. else
  742. udelay(2000);
  743. if (!dst_wait_dst_ready(state, NO_DELAY))
  744. return -1;
  745. if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
  746. if (verbose > 1)
  747. dprintk("%s: Trying to recover.. \n", __FUNCTION__);
  748. if ((dst_error_recovery(state)) < 0) {
  749. dprintk("%s: Recovery failed.\n", __FUNCTION__);
  750. return -1;
  751. }
  752. return -1;
  753. }
  754. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  755. dprintk("%s: checksum failure\n", __FUNCTION__);
  756. return -1;
  757. }
  758. return 0;
  759. }
  760. EXPORT_SYMBOL(dst_command);
  761. static int dst_get_signal(struct dst_state* state)
  762. {
  763. int retval;
  764. u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
  765. printk("%s: Getting Signal strength and other parameters !!!!!!!!\n", __FUNCTION__);
  766. if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
  767. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  768. return 0;
  769. }
  770. if (0 == (state->diseq_flags & HAS_LOCK)) {
  771. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  772. return 0;
  773. }
  774. if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
  775. retval = dst_command(state, get_signal, 8);
  776. if (retval < 0)
  777. return retval;
  778. if (state->dst_type == DST_TYPE_IS_SAT) {
  779. state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
  780. state->decode_strength = state->rxbuffer[5] << 8;
  781. state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
  782. } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
  783. state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
  784. state->decode_strength = state->rxbuffer[4] << 8;
  785. state->decode_snr = state->rxbuffer[3] << 8;
  786. }
  787. state->cur_jiff = jiffies;
  788. }
  789. return 0;
  790. }
  791. static int dst_tone_power_cmd(struct dst_state* state)
  792. {
  793. u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
  794. if (state->dst_type == DST_TYPE_IS_TERR)
  795. return 0;
  796. paket[4] = state->tx_tuna[4];
  797. paket[2] = state->tx_tuna[2];
  798. paket[3] = state->tx_tuna[3];
  799. paket[7] = dst_check_sum (paket, 7);
  800. dst_command(state, paket, 8);
  801. return 0;
  802. }
  803. static int dst_get_tuna(struct dst_state* state)
  804. {
  805. int retval;
  806. if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
  807. return 0;
  808. state->diseq_flags &= ~(HAS_LOCK);
  809. if (!dst_wait_dst_ready(state, NO_DELAY))
  810. return 0;
  811. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  812. /* how to get variable length reply ???? */
  813. retval = read_dst(state, state->rx_tuna, 10);
  814. } else {
  815. retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
  816. }
  817. if (retval < 0) {
  818. dprintk("%s: read not successful\n", __FUNCTION__);
  819. return 0;
  820. }
  821. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  822. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
  823. dprintk("%s: checksum failure?\n", __FUNCTION__);
  824. return 0;
  825. }
  826. } else {
  827. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
  828. dprintk("%s: checksum failure?\n", __FUNCTION__);
  829. return 0;
  830. }
  831. }
  832. if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
  833. return 0;
  834. state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
  835. state->decode_lock = 1;
  836. state->diseq_flags |= HAS_LOCK;
  837. return 1;
  838. }
  839. static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
  840. static int dst_write_tuna(struct dvb_frontend* fe)
  841. {
  842. struct dst_state* state = fe->demodulator_priv;
  843. int retval;
  844. u8 reply;
  845. if (debug > 4)
  846. dprintk("%s: type_flags 0x%x \n", __FUNCTION__, state->type_flags);
  847. state->decode_freq = 0;
  848. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  849. if (state->dst_type == DST_TYPE_IS_SAT) {
  850. if (!(state->diseq_flags & HAS_POWER))
  851. dst_set_voltage(fe, SEC_VOLTAGE_13);
  852. }
  853. state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
  854. if ((dst_comm_init(state)) < 0) {
  855. dprintk("%s: DST Communication initialization failed.\n", __FUNCTION__);
  856. return -1;
  857. }
  858. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  859. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
  860. retval = write_dst(state, &state->tx_tuna[0], 10);
  861. } else {
  862. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
  863. retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
  864. }
  865. if (retval < 0) {
  866. dst_pio_disable(state);
  867. dprintk("%s: write not successful\n", __FUNCTION__);
  868. return retval;
  869. }
  870. if ((dst_pio_disable(state)) < 0) {
  871. dprintk("%s: DST PIO disable failed !\n", __FUNCTION__);
  872. return -1;
  873. }
  874. if ((read_dst(state, &reply, GET_ACK) < 0)) {
  875. dprintk("%s: read verify not successful.\n", __FUNCTION__);
  876. return -1;
  877. }
  878. if (reply != ACK) {
  879. dprintk("%s: write not acknowledged 0x%02x \n", __FUNCTION__, reply);
  880. return 0;
  881. }
  882. state->diseq_flags |= ATTEMPT_TUNE;
  883. return dst_get_tuna(state);
  884. }
  885. /*
  886. * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
  887. * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
  888. * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
  889. * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
  890. * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
  891. * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
  892. * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
  893. * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
  894. * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
  895. * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
  896. * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
  897. */
  898. static int dst_set_diseqc(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
  899. {
  900. struct dst_state* state = fe->demodulator_priv;
  901. u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
  902. if (state->dst_type != DST_TYPE_IS_SAT)
  903. return 0;
  904. if (cmd->msg_len == 0 || cmd->msg_len > 4)
  905. return -EINVAL;
  906. memcpy(&paket[3], cmd->msg, cmd->msg_len);
  907. paket[7] = dst_check_sum(&paket[0], 7);
  908. dst_command(state, paket, 8);
  909. return 0;
  910. }
  911. static int dst_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  912. {
  913. int need_cmd;
  914. struct dst_state* state = fe->demodulator_priv;
  915. state->voltage = voltage;
  916. if (state->dst_type != DST_TYPE_IS_SAT)
  917. return 0;
  918. need_cmd = 0;
  919. switch (voltage) {
  920. case SEC_VOLTAGE_13:
  921. case SEC_VOLTAGE_18:
  922. if ((state->diseq_flags & HAS_POWER) == 0)
  923. need_cmd = 1;
  924. state->diseq_flags |= HAS_POWER;
  925. state->tx_tuna[4] = 0x01;
  926. break;
  927. case SEC_VOLTAGE_OFF:
  928. need_cmd = 1;
  929. state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
  930. state->tx_tuna[4] = 0x00;
  931. break;
  932. default:
  933. return -EINVAL;
  934. }
  935. if (need_cmd)
  936. dst_tone_power_cmd(state);
  937. return 0;
  938. }
  939. static int dst_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  940. {
  941. struct dst_state* state = fe->demodulator_priv;
  942. state->tone = tone;
  943. if (state->dst_type != DST_TYPE_IS_SAT)
  944. return 0;
  945. switch (tone) {
  946. case SEC_TONE_OFF:
  947. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  948. state->tx_tuna[2] = 0x00;
  949. else
  950. state->tx_tuna[2] = 0xff;
  951. break;
  952. case SEC_TONE_ON:
  953. state->tx_tuna[2] = 0x02;
  954. break;
  955. default:
  956. return -EINVAL;
  957. }
  958. dst_tone_power_cmd(state);
  959. return 0;
  960. }
  961. static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
  962. {
  963. struct dst_state *state = fe->demodulator_priv;
  964. if (state->dst_type != DST_TYPE_IS_SAT)
  965. return 0;
  966. state->minicmd = minicmd;
  967. switch (minicmd) {
  968. case SEC_MINI_A:
  969. state->tx_tuna[3] = 0x02;
  970. break;
  971. case SEC_MINI_B:
  972. state->tx_tuna[3] = 0xff;
  973. break;
  974. }
  975. dst_tone_power_cmd(state);
  976. return 0;
  977. }
  978. static int dst_init(struct dvb_frontend* fe)
  979. {
  980. struct dst_state* state = fe->demodulator_priv;
  981. static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 };
  982. static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 };
  983. static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
  984. static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
  985. static u8 ini_cabfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
  986. static u8 ini_cabci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 };
  987. // state->inversion = INVERSION_ON;
  988. state->inversion = INVERSION_OFF;
  989. state->voltage = SEC_VOLTAGE_13;
  990. state->tone = SEC_TONE_OFF;
  991. state->symbol_rate = 29473000;
  992. state->fec = FEC_AUTO;
  993. state->diseq_flags = 0;
  994. state->k22 = 0x02;
  995. state->bandwidth = BANDWIDTH_7_MHZ;
  996. state->cur_jiff = jiffies;
  997. if (state->dst_type == DST_TYPE_IS_SAT) {
  998. state->frequency = 950000;
  999. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_satci_tuna : ini_satfta_tuna), sizeof(ini_satfta_tuna));
  1000. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  1001. state->frequency = 137000000;
  1002. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_tvci_tuna : ini_tvfta_tuna), sizeof(ini_tvfta_tuna));
  1003. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1004. state->frequency = 51000000;
  1005. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ini_cabci_tuna : ini_cabfta_tuna), sizeof(ini_cabfta_tuna));
  1006. }
  1007. return 0;
  1008. }
  1009. static int dst_read_status(struct dvb_frontend* fe, fe_status_t* status)
  1010. {
  1011. struct dst_state* state = fe->demodulator_priv;
  1012. *status = 0;
  1013. if (state->diseq_flags & HAS_LOCK) {
  1014. // dst_get_signal(state); // don't require(?) to ask MCU
  1015. if (state->decode_lock)
  1016. *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
  1017. }
  1018. return 0;
  1019. }
  1020. static int dst_read_signal_strength(struct dvb_frontend* fe, u16* strength)
  1021. {
  1022. struct dst_state* state = fe->demodulator_priv;
  1023. dst_get_signal(state);
  1024. *strength = state->decode_strength;
  1025. return 0;
  1026. }
  1027. static int dst_read_snr(struct dvb_frontend* fe, u16* snr)
  1028. {
  1029. struct dst_state* state = fe->demodulator_priv;
  1030. dst_get_signal(state);
  1031. *snr = state->decode_snr;
  1032. return 0;
  1033. }
  1034. static int dst_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  1035. {
  1036. struct dst_state* state = fe->demodulator_priv;
  1037. dst_set_freq(state, p->frequency);
  1038. if (verbose > 4)
  1039. dprintk("Set Frequency=[%d]\n", p->frequency);
  1040. // dst_set_inversion(state, p->inversion);
  1041. if (state->dst_type == DST_TYPE_IS_SAT) {
  1042. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1043. dst_set_inversion(state, p->inversion);
  1044. dst_set_fec(state, p->u.qpsk.fec_inner);
  1045. dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
  1046. dst_set_polarization(state);
  1047. if (verbose > 4)
  1048. dprintk("Set Symbolrate=[%d]\n", p->u.qpsk.symbol_rate);
  1049. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  1050. dst_set_bandwidth(state, p->u.ofdm.bandwidth);
  1051. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1052. dst_set_fec(state, p->u.qam.fec_inner);
  1053. dst_set_symbolrate(state, p->u.qam.symbol_rate);
  1054. dst_set_modulation(state, p->u.qam.modulation);
  1055. }
  1056. dst_write_tuna(fe);
  1057. return 0;
  1058. }
  1059. static int dst_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  1060. {
  1061. struct dst_state* state = fe->demodulator_priv;
  1062. p->frequency = state->decode_freq;
  1063. // p->inversion = state->inversion;
  1064. if (state->dst_type == DST_TYPE_IS_SAT) {
  1065. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1066. p->inversion = state->inversion;
  1067. p->u.qpsk.symbol_rate = state->symbol_rate;
  1068. p->u.qpsk.fec_inner = dst_get_fec(state);
  1069. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  1070. p->u.ofdm.bandwidth = state->bandwidth;
  1071. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1072. p->u.qam.symbol_rate = state->symbol_rate;
  1073. p->u.qam.fec_inner = dst_get_fec(state);
  1074. // p->u.qam.modulation = QAM_AUTO;
  1075. p->u.qam.modulation = dst_get_modulation(state);
  1076. }
  1077. return 0;
  1078. }
  1079. static void dst_release(struct dvb_frontend* fe)
  1080. {
  1081. struct dst_state* state = fe->demodulator_priv;
  1082. kfree(state);
  1083. }
  1084. static struct dvb_frontend_ops dst_dvbt_ops;
  1085. static struct dvb_frontend_ops dst_dvbs_ops;
  1086. static struct dvb_frontend_ops dst_dvbc_ops;
  1087. struct dst_state* dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
  1088. {
  1089. /* check if the ASIC is there */
  1090. if (dst_probe(state) < 0) {
  1091. if (state)
  1092. kfree(state);
  1093. return NULL;
  1094. }
  1095. /* determine settings based on type */
  1096. switch (state->dst_type) {
  1097. case DST_TYPE_IS_TERR:
  1098. memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
  1099. break;
  1100. case DST_TYPE_IS_CABLE:
  1101. memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
  1102. break;
  1103. case DST_TYPE_IS_SAT:
  1104. memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
  1105. break;
  1106. default:
  1107. printk("%s: unknown DST type. please report to the LinuxTV.org DVB mailinglist.\n", __FUNCTION__);
  1108. if (state)
  1109. kfree(state);
  1110. return NULL;
  1111. }
  1112. /* create dvb_frontend */
  1113. state->frontend.ops = &state->ops;
  1114. state->frontend.demodulator_priv = state;
  1115. return state; /* Manu (DST is a card not a frontend) */
  1116. }
  1117. EXPORT_SYMBOL(dst_attach);
  1118. static struct dvb_frontend_ops dst_dvbt_ops = {
  1119. .info = {
  1120. .name = "DST DVB-T",
  1121. .type = FE_OFDM,
  1122. .frequency_min = 137000000,
  1123. .frequency_max = 858000000,
  1124. .frequency_stepsize = 166667,
  1125. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
  1126. },
  1127. .release = dst_release,
  1128. .init = dst_init,
  1129. .set_frontend = dst_set_frontend,
  1130. .get_frontend = dst_get_frontend,
  1131. .read_status = dst_read_status,
  1132. .read_signal_strength = dst_read_signal_strength,
  1133. .read_snr = dst_read_snr,
  1134. };
  1135. static struct dvb_frontend_ops dst_dvbs_ops = {
  1136. .info = {
  1137. .name = "DST DVB-S",
  1138. .type = FE_QPSK,
  1139. .frequency_min = 950000,
  1140. .frequency_max = 2150000,
  1141. .frequency_stepsize = 1000, /* kHz for QPSK frontends */
  1142. .frequency_tolerance = 29500,
  1143. .symbol_rate_min = 1000000,
  1144. .symbol_rate_max = 45000000,
  1145. /* . symbol_rate_tolerance = ???,*/
  1146. .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
  1147. },
  1148. .release = dst_release,
  1149. .init = dst_init,
  1150. .set_frontend = dst_set_frontend,
  1151. .get_frontend = dst_get_frontend,
  1152. .read_status = dst_read_status,
  1153. .read_signal_strength = dst_read_signal_strength,
  1154. .read_snr = dst_read_snr,
  1155. .diseqc_send_burst = dst_send_burst,
  1156. .diseqc_send_master_cmd = dst_set_diseqc,
  1157. .set_voltage = dst_set_voltage,
  1158. .set_tone = dst_set_tone,
  1159. };
  1160. static struct dvb_frontend_ops dst_dvbc_ops = {
  1161. .info = {
  1162. .name = "DST DVB-C",
  1163. .type = FE_QAM,
  1164. .frequency_stepsize = 62500,
  1165. .frequency_min = 51000000,
  1166. .frequency_max = 858000000,
  1167. .symbol_rate_min = 1000000,
  1168. .symbol_rate_max = 45000000,
  1169. /* . symbol_rate_tolerance = ???,*/
  1170. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO
  1171. },
  1172. .release = dst_release,
  1173. .init = dst_init,
  1174. .set_frontend = dst_set_frontend,
  1175. .get_frontend = dst_get_frontend,
  1176. .read_status = dst_read_status,
  1177. .read_signal_strength = dst_read_signal_strength,
  1178. .read_snr = dst_read_snr,
  1179. };
  1180. MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
  1181. MODULE_AUTHOR("Jamie Honan, Manu Abraham");
  1182. MODULE_LICENSE("GPL");