dst.c 46 KB

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