dst.c 47 KB

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