dst.c 46 KB

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