dst.c 40 KB

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