dst.c 45 KB

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