dst.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  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. 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_FW_2,
  599. .dst_feature = 0
  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_device_id(struct dst_state *state)
  690. {
  691. u8 reply;
  692. int i;
  693. struct dst_types *p_dst_type;
  694. u8 use_dst_type = 0;
  695. u32 use_type_flags = 0;
  696. static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
  697. device_type[7] = dst_check_sum(device_type, 7);
  698. if (write_dst(state, device_type, FIXED_COMM))
  699. return -1; /* Write failed */
  700. if ((dst_pio_disable(state)) < 0)
  701. return -1;
  702. if (read_dst(state, &reply, GET_ACK))
  703. return -1; /* Read failure */
  704. if (reply != ACK) {
  705. dprintk(verbose, DST_INFO, 1, "Write not Acknowledged! [Reply=0x%02x]", reply);
  706. return -1; /* Unack'd write */
  707. }
  708. if (!dst_wait_dst_ready(state, DEVICE_INIT))
  709. return -1; /* DST not ready yet */
  710. if (read_dst(state, state->rxbuffer, FIXED_COMM))
  711. return -1;
  712. dst_pio_disable(state);
  713. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  714. dprintk(verbose, DST_INFO, 1, "Checksum failure!");
  715. return -1; /* Checksum failure */
  716. }
  717. state->rxbuffer[7] = '\0';
  718. for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
  719. if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
  720. use_type_flags = p_dst_type->type_flags;
  721. use_dst_type = p_dst_type->dst_type;
  722. /* Card capabilities */
  723. state->dst_hw_cap = p_dst_type->dst_feature;
  724. dprintk(verbose, DST_ERROR, 1, "Recognise [%s]\n", p_dst_type->device_id);
  725. break;
  726. }
  727. }
  728. if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
  729. dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
  730. dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
  731. use_dst_type = DST_TYPE_IS_SAT;
  732. use_type_flags = DST_TYPE_HAS_SYMDIV;
  733. }
  734. dst_type_print(use_dst_type);
  735. state->type_flags = use_type_flags;
  736. state->dst_type = use_dst_type;
  737. dst_type_flags_print(state->type_flags);
  738. if (state->type_flags & DST_TYPE_HAS_TS204) {
  739. dst_packsize(state, 204);
  740. }
  741. return 0;
  742. }
  743. static int dst_probe(struct dst_state *state)
  744. {
  745. if ((rdc_8820_reset(state)) < 0) {
  746. dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
  747. return -1;
  748. }
  749. if (dst_addons & DST_TYPE_HAS_CA)
  750. msleep(4000);
  751. else
  752. msleep(100);
  753. if ((dst_comm_init(state)) < 0) {
  754. dprintk(verbose, DST_ERROR, 1, "DST Initialization Failed.");
  755. return -1;
  756. }
  757. msleep(100);
  758. if (dst_get_device_id(state) < 0) {
  759. dprintk(verbose, DST_ERROR, 1, "unknown device.");
  760. return -1;
  761. }
  762. if (dst_get_mac(state) < 0) {
  763. dprintk(verbose, DST_INFO, 1, "MAC: Unsupported command");
  764. return 0;
  765. }
  766. if (state->type_flags & DST_TYPE_HAS_FW_BUILD) {
  767. if (dst_fw_ver(state) < 0) {
  768. dprintk(verbose, DST_INFO, 1, "FW: Unsupported command");
  769. return 0;
  770. }
  771. if (dst_card_type(state) < 0) {
  772. dprintk(verbose, DST_INFO, 1, "Card: Unsupported command");
  773. return 0;
  774. }
  775. if (dst_get_vendor(state) < 0) {
  776. dprintk(verbose, DST_INFO, 1, "Vendor: Unsupported command");
  777. return 0;
  778. }
  779. }
  780. return 0;
  781. }
  782. int dst_command(struct dst_state *state, u8 *data, u8 len)
  783. {
  784. u8 reply;
  785. if ((dst_comm_init(state)) < 0) {
  786. dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
  787. return -1;
  788. }
  789. if (write_dst(state, data, len)) {
  790. dprintk(verbose, DST_INFO, 1, "Tring to recover.. ");
  791. if ((dst_error_recovery(state)) < 0) {
  792. dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
  793. return -1;
  794. }
  795. return -1;
  796. }
  797. if ((dst_pio_disable(state)) < 0) {
  798. dprintk(verbose, DST_ERROR, 1, "PIO Disable Failed.");
  799. return -1;
  800. }
  801. if (state->type_flags & DST_TYPE_HAS_FW_1)
  802. udelay(3000);
  803. if (read_dst(state, &reply, GET_ACK)) {
  804. dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
  805. if ((dst_error_recovery(state)) < 0) {
  806. dprintk(verbose, DST_INFO, 1, "Recovery Failed.");
  807. return -1;
  808. }
  809. return -1;
  810. }
  811. if (reply != ACK) {
  812. dprintk(verbose, DST_INFO, 1, "write not acknowledged 0x%02x ", reply);
  813. return -1;
  814. }
  815. if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
  816. return 0;
  817. if (state->type_flags & DST_TYPE_HAS_FW_1)
  818. udelay(3000);
  819. else
  820. udelay(2000);
  821. if (!dst_wait_dst_ready(state, NO_DELAY))
  822. return -1;
  823. if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
  824. dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
  825. if ((dst_error_recovery(state)) < 0) {
  826. dprintk(verbose, DST_INFO, 1, "Recovery failed.");
  827. return -1;
  828. }
  829. return -1;
  830. }
  831. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  832. dprintk(verbose, DST_INFO, 1, "checksum failure");
  833. return -1;
  834. }
  835. return 0;
  836. }
  837. EXPORT_SYMBOL(dst_command);
  838. static int dst_get_signal(struct dst_state *state)
  839. {
  840. int retval;
  841. u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
  842. //dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
  843. if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
  844. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  845. return 0;
  846. }
  847. if (0 == (state->diseq_flags & HAS_LOCK)) {
  848. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  849. return 0;
  850. }
  851. if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
  852. retval = dst_command(state, get_signal, 8);
  853. if (retval < 0)
  854. return retval;
  855. if (state->dst_type == DST_TYPE_IS_SAT) {
  856. state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
  857. state->decode_strength = state->rxbuffer[5] << 8;
  858. state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
  859. } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
  860. state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
  861. state->decode_strength = state->rxbuffer[4] << 8;
  862. state->decode_snr = state->rxbuffer[3] << 8;
  863. }
  864. state->cur_jiff = jiffies;
  865. }
  866. return 0;
  867. }
  868. static int dst_tone_power_cmd(struct dst_state *state)
  869. {
  870. u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
  871. if (state->dst_type == DST_TYPE_IS_TERR)
  872. return 0;
  873. paket[4] = state->tx_tuna[4];
  874. paket[2] = state->tx_tuna[2];
  875. paket[3] = state->tx_tuna[3];
  876. paket[7] = dst_check_sum (paket, 7);
  877. dst_command(state, paket, 8);
  878. return 0;
  879. }
  880. static int dst_get_tuna(struct dst_state *state)
  881. {
  882. int retval;
  883. if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
  884. return 0;
  885. state->diseq_flags &= ~(HAS_LOCK);
  886. if (!dst_wait_dst_ready(state, NO_DELAY))
  887. return 0;
  888. if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
  889. /* how to get variable length reply ???? */
  890. retval = read_dst(state, state->rx_tuna, 10);
  891. else
  892. retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
  893. if (retval < 0) {
  894. dprintk(verbose, DST_DEBUG, 1, "read not successful");
  895. return 0;
  896. }
  897. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  898. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
  899. dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
  900. return 0;
  901. }
  902. } else {
  903. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
  904. dprintk(verbose, DST_INFO, 1, "checksum failure? ");
  905. return 0;
  906. }
  907. }
  908. if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
  909. return 0;
  910. state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
  911. state->decode_lock = 1;
  912. state->diseq_flags |= HAS_LOCK;
  913. return 1;
  914. }
  915. static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
  916. static int dst_write_tuna(struct dvb_frontend *fe)
  917. {
  918. struct dst_state *state = fe->demodulator_priv;
  919. int retval;
  920. u8 reply;
  921. dprintk(verbose, DST_INFO, 1, "type_flags 0x%x ", state->type_flags);
  922. state->decode_freq = 0;
  923. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  924. if (state->dst_type == DST_TYPE_IS_SAT) {
  925. if (!(state->diseq_flags & HAS_POWER))
  926. dst_set_voltage(fe, SEC_VOLTAGE_13);
  927. }
  928. state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
  929. if ((dst_comm_init(state)) < 0) {
  930. dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
  931. return -1;
  932. }
  933. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  934. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
  935. retval = write_dst(state, &state->tx_tuna[0], 10);
  936. } else {
  937. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
  938. retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
  939. }
  940. if (retval < 0) {
  941. dst_pio_disable(state);
  942. dprintk(verbose, DST_DEBUG, 1, "write not successful");
  943. return retval;
  944. }
  945. if ((dst_pio_disable(state)) < 0) {
  946. dprintk(verbose, DST_DEBUG, 1, "DST PIO disable failed !");
  947. return -1;
  948. }
  949. if ((read_dst(state, &reply, GET_ACK) < 0)) {
  950. dprintk(verbose, DST_DEBUG, 1, "read verify not successful.");
  951. return -1;
  952. }
  953. if (reply != ACK) {
  954. dprintk(verbose, DST_DEBUG, 1, "write not acknowledged 0x%02x ", reply);
  955. return 0;
  956. }
  957. state->diseq_flags |= ATTEMPT_TUNE;
  958. return dst_get_tuna(state);
  959. }
  960. /*
  961. * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
  962. * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
  963. * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
  964. * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
  965. * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
  966. * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
  967. * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
  968. * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
  969. * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
  970. * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
  971. * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
  972. */
  973. static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
  974. {
  975. struct dst_state *state = fe->demodulator_priv;
  976. u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
  977. if (state->dst_type != DST_TYPE_IS_SAT)
  978. return 0;
  979. if (cmd->msg_len == 0 || cmd->msg_len > 4)
  980. return -EINVAL;
  981. memcpy(&paket[3], cmd->msg, cmd->msg_len);
  982. paket[7] = dst_check_sum(&paket[0], 7);
  983. dst_command(state, paket, 8);
  984. return 0;
  985. }
  986. static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  987. {
  988. int need_cmd;
  989. struct dst_state *state = fe->demodulator_priv;
  990. state->voltage = voltage;
  991. if (state->dst_type != DST_TYPE_IS_SAT)
  992. return 0;
  993. need_cmd = 0;
  994. switch (voltage) {
  995. case SEC_VOLTAGE_13:
  996. case SEC_VOLTAGE_18:
  997. if ((state->diseq_flags & HAS_POWER) == 0)
  998. need_cmd = 1;
  999. state->diseq_flags |= HAS_POWER;
  1000. state->tx_tuna[4] = 0x01;
  1001. break;
  1002. case SEC_VOLTAGE_OFF:
  1003. need_cmd = 1;
  1004. state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
  1005. state->tx_tuna[4] = 0x00;
  1006. break;
  1007. default:
  1008. return -EINVAL;
  1009. }
  1010. if (need_cmd)
  1011. dst_tone_power_cmd(state);
  1012. return 0;
  1013. }
  1014. static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
  1015. {
  1016. struct dst_state *state = fe->demodulator_priv;
  1017. state->tone = tone;
  1018. if (state->dst_type != DST_TYPE_IS_SAT)
  1019. return 0;
  1020. switch (tone) {
  1021. case SEC_TONE_OFF:
  1022. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1023. state->tx_tuna[2] = 0x00;
  1024. else
  1025. state->tx_tuna[2] = 0xff;
  1026. break;
  1027. case SEC_TONE_ON:
  1028. state->tx_tuna[2] = 0x02;
  1029. break;
  1030. default:
  1031. return -EINVAL;
  1032. }
  1033. dst_tone_power_cmd(state);
  1034. return 0;
  1035. }
  1036. static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
  1037. {
  1038. struct dst_state *state = fe->demodulator_priv;
  1039. if (state->dst_type != DST_TYPE_IS_SAT)
  1040. return 0;
  1041. state->minicmd = minicmd;
  1042. switch (minicmd) {
  1043. case SEC_MINI_A:
  1044. state->tx_tuna[3] = 0x02;
  1045. break;
  1046. case SEC_MINI_B:
  1047. state->tx_tuna[3] = 0xff;
  1048. break;
  1049. }
  1050. dst_tone_power_cmd(state);
  1051. return 0;
  1052. }
  1053. static int dst_init(struct dvb_frontend *fe)
  1054. {
  1055. struct dst_state *state = fe->demodulator_priv;
  1056. static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
  1057. static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
  1058. static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1059. static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1060. static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1061. static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1062. state->inversion = INVERSION_OFF;
  1063. state->voltage = SEC_VOLTAGE_13;
  1064. state->tone = SEC_TONE_OFF;
  1065. state->diseq_flags = 0;
  1066. state->k22 = 0x02;
  1067. state->bandwidth = BANDWIDTH_7_MHZ;
  1068. state->cur_jiff = jiffies;
  1069. if (state->dst_type == DST_TYPE_IS_SAT)
  1070. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
  1071. else if (state->dst_type == DST_TYPE_IS_TERR)
  1072. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
  1073. else if (state->dst_type == DST_TYPE_IS_CABLE)
  1074. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
  1075. return 0;
  1076. }
  1077. static int dst_read_status(struct dvb_frontend *fe, fe_status_t *status)
  1078. {
  1079. struct dst_state *state = fe->demodulator_priv;
  1080. *status = 0;
  1081. if (state->diseq_flags & HAS_LOCK) {
  1082. // dst_get_signal(state); // don't require(?) to ask MCU
  1083. if (state->decode_lock)
  1084. *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
  1085. }
  1086. return 0;
  1087. }
  1088. static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  1089. {
  1090. struct dst_state *state = fe->demodulator_priv;
  1091. dst_get_signal(state);
  1092. *strength = state->decode_strength;
  1093. return 0;
  1094. }
  1095. static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
  1096. {
  1097. struct dst_state *state = fe->demodulator_priv;
  1098. dst_get_signal(state);
  1099. *snr = state->decode_snr;
  1100. return 0;
  1101. }
  1102. static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1103. {
  1104. struct dst_state *state = fe->demodulator_priv;
  1105. dst_set_freq(state, p->frequency);
  1106. dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
  1107. if (state->dst_type == DST_TYPE_IS_SAT) {
  1108. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1109. dst_set_inversion(state, p->inversion);
  1110. dst_set_fec(state, p->u.qpsk.fec_inner);
  1111. dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
  1112. dst_set_polarization(state);
  1113. dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);
  1114. } else if (state->dst_type == DST_TYPE_IS_TERR)
  1115. dst_set_bandwidth(state, p->u.ofdm.bandwidth);
  1116. else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1117. dst_set_fec(state, p->u.qam.fec_inner);
  1118. dst_set_symbolrate(state, p->u.qam.symbol_rate);
  1119. dst_set_modulation(state, p->u.qam.modulation);
  1120. }
  1121. dst_write_tuna(fe);
  1122. return 0;
  1123. }
  1124. static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1125. {
  1126. struct dst_state *state = fe->demodulator_priv;
  1127. p->frequency = state->decode_freq;
  1128. if (state->dst_type == DST_TYPE_IS_SAT) {
  1129. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1130. p->inversion = state->inversion;
  1131. p->u.qpsk.symbol_rate = state->symbol_rate;
  1132. p->u.qpsk.fec_inner = dst_get_fec(state);
  1133. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  1134. p->u.ofdm.bandwidth = state->bandwidth;
  1135. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1136. p->u.qam.symbol_rate = state->symbol_rate;
  1137. p->u.qam.fec_inner = dst_get_fec(state);
  1138. p->u.qam.modulation = dst_get_modulation(state);
  1139. }
  1140. return 0;
  1141. }
  1142. static void dst_release(struct dvb_frontend *fe)
  1143. {
  1144. struct dst_state *state = fe->demodulator_priv;
  1145. kfree(state);
  1146. }
  1147. static struct dvb_frontend_ops dst_dvbt_ops;
  1148. static struct dvb_frontend_ops dst_dvbs_ops;
  1149. static struct dvb_frontend_ops dst_dvbc_ops;
  1150. struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
  1151. {
  1152. /* check if the ASIC is there */
  1153. if (dst_probe(state) < 0) {
  1154. if (state)
  1155. kfree(state);
  1156. return NULL;
  1157. }
  1158. /* determine settings based on type */
  1159. switch (state->dst_type) {
  1160. case DST_TYPE_IS_TERR:
  1161. memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
  1162. break;
  1163. case DST_TYPE_IS_CABLE:
  1164. memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
  1165. break;
  1166. case DST_TYPE_IS_SAT:
  1167. memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
  1168. break;
  1169. default:
  1170. dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
  1171. if (state)
  1172. kfree(state);
  1173. return NULL;
  1174. }
  1175. /* create dvb_frontend */
  1176. state->frontend.ops = &state->ops;
  1177. state->frontend.demodulator_priv = state;
  1178. return state; /* Manu (DST is a card not a frontend) */
  1179. }
  1180. EXPORT_SYMBOL(dst_attach);
  1181. static struct dvb_frontend_ops dst_dvbt_ops = {
  1182. .info = {
  1183. .name = "DST DVB-T",
  1184. .type = FE_OFDM,
  1185. .frequency_min = 137000000,
  1186. .frequency_max = 858000000,
  1187. .frequency_stepsize = 166667,
  1188. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
  1189. },
  1190. .release = dst_release,
  1191. .init = dst_init,
  1192. .set_frontend = dst_set_frontend,
  1193. .get_frontend = dst_get_frontend,
  1194. .read_status = dst_read_status,
  1195. .read_signal_strength = dst_read_signal_strength,
  1196. .read_snr = dst_read_snr,
  1197. };
  1198. static struct dvb_frontend_ops dst_dvbs_ops = {
  1199. .info = {
  1200. .name = "DST DVB-S",
  1201. .type = FE_QPSK,
  1202. .frequency_min = 950000,
  1203. .frequency_max = 2150000,
  1204. .frequency_stepsize = 1000, /* kHz for QPSK frontends */
  1205. .frequency_tolerance = 29500,
  1206. .symbol_rate_min = 1000000,
  1207. .symbol_rate_max = 45000000,
  1208. /* . symbol_rate_tolerance = ???,*/
  1209. .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
  1210. },
  1211. .release = dst_release,
  1212. .init = dst_init,
  1213. .set_frontend = dst_set_frontend,
  1214. .get_frontend = dst_get_frontend,
  1215. .read_status = dst_read_status,
  1216. .read_signal_strength = dst_read_signal_strength,
  1217. .read_snr = dst_read_snr,
  1218. .diseqc_send_burst = dst_send_burst,
  1219. .diseqc_send_master_cmd = dst_set_diseqc,
  1220. .set_voltage = dst_set_voltage,
  1221. .set_tone = dst_set_tone,
  1222. };
  1223. static struct dvb_frontend_ops dst_dvbc_ops = {
  1224. .info = {
  1225. .name = "DST DVB-C",
  1226. .type = FE_QAM,
  1227. .frequency_stepsize = 62500,
  1228. .frequency_min = 51000000,
  1229. .frequency_max = 858000000,
  1230. .symbol_rate_min = 1000000,
  1231. .symbol_rate_max = 45000000,
  1232. /* . symbol_rate_tolerance = ???,*/
  1233. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO
  1234. },
  1235. .release = dst_release,
  1236. .init = dst_init,
  1237. .set_frontend = dst_set_frontend,
  1238. .get_frontend = dst_get_frontend,
  1239. .read_status = dst_read_status,
  1240. .read_signal_strength = dst_read_signal_strength,
  1241. .read_snr = dst_read_snr,
  1242. };
  1243. MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
  1244. MODULE_AUTHOR("Jamie Honan, Manu Abraham");
  1245. MODULE_LICENSE("GPL");