dst.c 49 KB

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