dst.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874
  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, fe_spectral_inversion_t inversion)
  371. {
  372. state->inversion = inversion;
  373. switch (inversion) {
  374. case INVERSION_OFF: /* Inversion = Normal */
  375. state->tx_tuna[8] &= ~0x80;
  376. break;
  377. case INVERSION_ON:
  378. state->tx_tuna[8] |= 0x80;
  379. break;
  380. default:
  381. return -EINVAL;
  382. }
  383. return 0;
  384. }
  385. static int dst_set_fec(struct dst_state *state, fe_code_rate_t fec)
  386. {
  387. state->fec = fec;
  388. return 0;
  389. }
  390. static fe_code_rate_t dst_get_fec(struct dst_state *state)
  391. {
  392. return state->fec;
  393. }
  394. static int dst_set_symbolrate(struct dst_state *state, u32 srate)
  395. {
  396. u32 symcalc;
  397. u64 sval;
  398. state->symbol_rate = srate;
  399. if (state->dst_type == DST_TYPE_IS_TERR) {
  400. return -EOPNOTSUPP;
  401. }
  402. dprintk(verbose, DST_INFO, 1, "set symrate %u", srate);
  403. srate /= 1000;
  404. if (state->dst_type == DST_TYPE_IS_SAT) {
  405. if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
  406. sval = srate;
  407. sval <<= 20;
  408. do_div(sval, 88000);
  409. symcalc = (u32) sval;
  410. dprintk(verbose, DST_INFO, 1, "set symcalc %u", symcalc);
  411. state->tx_tuna[5] = (u8) (symcalc >> 12);
  412. state->tx_tuna[6] = (u8) (symcalc >> 4);
  413. state->tx_tuna[7] = (u8) (symcalc << 4);
  414. } else {
  415. state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
  416. state->tx_tuna[6] = (u8) (srate >> 8);
  417. state->tx_tuna[7] = (u8) srate;
  418. }
  419. state->tx_tuna[8] &= ~0x20;
  420. if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
  421. if (srate > 8000)
  422. state->tx_tuna[8] |= 0x20;
  423. }
  424. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  425. dprintk(verbose, DST_DEBUG, 1, "%s", state->fw_name);
  426. if (!strncmp(state->fw_name, "DCTNEW", 6)) {
  427. state->tx_tuna[5] = (u8) (srate >> 8);
  428. state->tx_tuna[6] = (u8) srate;
  429. state->tx_tuna[7] = 0x00;
  430. } else if (!strncmp(state->fw_name, "DCT-CI", 6)) {
  431. state->tx_tuna[5] = 0x00;
  432. state->tx_tuna[6] = (u8) (srate >> 8);
  433. state->tx_tuna[7] = (u8) srate;
  434. }
  435. }
  436. return 0;
  437. }
  438. static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
  439. {
  440. if (state->dst_type != DST_TYPE_IS_CABLE)
  441. return -EOPNOTSUPP;
  442. state->modulation = modulation;
  443. switch (modulation) {
  444. case QAM_16:
  445. state->tx_tuna[8] = 0x10;
  446. break;
  447. case QAM_32:
  448. state->tx_tuna[8] = 0x20;
  449. break;
  450. case QAM_64:
  451. state->tx_tuna[8] = 0x40;
  452. break;
  453. case QAM_128:
  454. state->tx_tuna[8] = 0x80;
  455. break;
  456. case QAM_256:
  457. if (!strncmp(state->fw_name, "DCTNEW", 6))
  458. state->tx_tuna[8] = 0xff;
  459. else if (!strncmp(state->fw_name, "DCT-CI", 6))
  460. state->tx_tuna[8] = 0x00;
  461. break;
  462. case QPSK:
  463. case QAM_AUTO:
  464. case VSB_8:
  465. case VSB_16:
  466. default:
  467. return -EINVAL;
  468. }
  469. return 0;
  470. }
  471. static fe_modulation_t dst_get_modulation(struct dst_state *state)
  472. {
  473. return state->modulation;
  474. }
  475. u8 dst_check_sum(u8 *buf, u32 len)
  476. {
  477. u32 i;
  478. u8 val = 0;
  479. if (!len)
  480. return 0;
  481. for (i = 0; i < len; i++) {
  482. val += buf[i];
  483. }
  484. return ((~val) + 1);
  485. }
  486. EXPORT_SYMBOL(dst_check_sum);
  487. static void dst_type_flags_print(struct dst_state *state)
  488. {
  489. u32 type_flags = state->type_flags;
  490. dprintk(verbose, DST_ERROR, 0, "DST type flags :");
  491. if (type_flags & DST_TYPE_HAS_TS188)
  492. dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner", DST_TYPE_HAS_TS188);
  493. if (type_flags & DST_TYPE_HAS_NEWTUNE_2)
  494. dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner 2", DST_TYPE_HAS_NEWTUNE_2);
  495. if (type_flags & DST_TYPE_HAS_TS204)
  496. dprintk(verbose, DST_ERROR, 0, " 0x%x ts204", DST_TYPE_HAS_TS204);
  497. if (type_flags & DST_TYPE_HAS_VLF)
  498. dprintk(verbose, DST_ERROR, 0, " 0x%x VLF", DST_TYPE_HAS_VLF);
  499. if (type_flags & DST_TYPE_HAS_SYMDIV)
  500. dprintk(verbose, DST_ERROR, 0, " 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
  501. if (type_flags & DST_TYPE_HAS_FW_1)
  502. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
  503. if (type_flags & DST_TYPE_HAS_FW_2)
  504. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
  505. if (type_flags & DST_TYPE_HAS_FW_3)
  506. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
  507. dprintk(verbose, DST_ERROR, 0, "\n");
  508. }
  509. static int dst_type_print(struct dst_state *state, u8 type)
  510. {
  511. char *otype;
  512. switch (type) {
  513. case DST_TYPE_IS_SAT:
  514. otype = "satellite";
  515. break;
  516. case DST_TYPE_IS_TERR:
  517. otype = "terrestrial";
  518. break;
  519. case DST_TYPE_IS_CABLE:
  520. otype = "cable";
  521. break;
  522. case DST_TYPE_IS_ATSC:
  523. otype = "atsc";
  524. break;
  525. default:
  526. dprintk(verbose, DST_INFO, 1, "invalid dst type %d", type);
  527. return -EINVAL;
  528. }
  529. dprintk(verbose, DST_INFO, 1, "DST type: %s", otype);
  530. return 0;
  531. }
  532. static struct tuner_types tuner_list[] = {
  533. {
  534. .tuner_type = TUNER_TYPE_L64724,
  535. .tuner_name = "L 64724",
  536. .board_name = "UNKNOWN",
  537. .fw_name = "UNKNOWN"
  538. },
  539. {
  540. .tuner_type = TUNER_TYPE_STV0299,
  541. .tuner_name = "STV 0299",
  542. .board_name = "VP1020",
  543. .fw_name = "DST-MOT"
  544. },
  545. {
  546. .tuner_type = TUNER_TYPE_STV0299,
  547. .tuner_name = "STV 0299",
  548. .board_name = "VP1020",
  549. .fw_name = "DST-03T"
  550. },
  551. {
  552. .tuner_type = TUNER_TYPE_MB86A15,
  553. .tuner_name = "MB 86A15",
  554. .board_name = "VP1022",
  555. .fw_name = "DST-03T"
  556. },
  557. {
  558. .tuner_type = TUNER_TYPE_MB86A15,
  559. .tuner_name = "MB 86A15",
  560. .board_name = "VP1025",
  561. .fw_name = "DST-03T"
  562. },
  563. {
  564. .tuner_type = TUNER_TYPE_STV0299,
  565. .tuner_name = "STV 0299",
  566. .board_name = "VP1030",
  567. .fw_name = "DST-CI"
  568. },
  569. {
  570. .tuner_type = TUNER_TYPE_STV0299,
  571. .tuner_name = "STV 0299",
  572. .board_name = "VP1030",
  573. .fw_name = "DSTMCI"
  574. },
  575. {
  576. .tuner_type = TUNER_TYPE_UNKNOWN,
  577. .tuner_name = "UNKNOWN",
  578. .board_name = "VP2021",
  579. .fw_name = "DCTNEW"
  580. },
  581. {
  582. .tuner_type = TUNER_TYPE_UNKNOWN,
  583. .tuner_name = "UNKNOWN",
  584. .board_name = "VP2030",
  585. .fw_name = "DCT-CI"
  586. },
  587. {
  588. .tuner_type = TUNER_TYPE_UNKNOWN,
  589. .tuner_name = "UNKNOWN",
  590. .board_name = "VP2031",
  591. .fw_name = "DCT-CI"
  592. },
  593. {
  594. .tuner_type = TUNER_TYPE_UNKNOWN,
  595. .tuner_name = "UNKNOWN",
  596. .board_name = "VP2040",
  597. .fw_name = "DCT-CI"
  598. },
  599. {
  600. .tuner_type = TUNER_TYPE_UNKNOWN,
  601. .tuner_name = "UNKNOWN",
  602. .board_name = "VP3020",
  603. .fw_name = "DTTFTA"
  604. },
  605. {
  606. .tuner_type = TUNER_TYPE_UNKNOWN,
  607. .tuner_name = "UNKNOWN",
  608. .board_name = "VP3021",
  609. .fw_name = "DTTFTA"
  610. },
  611. {
  612. .tuner_type = TUNER_TYPE_TDA10046,
  613. .tuner_name = "TDA10046",
  614. .board_name = "VP3040",
  615. .fw_name = "DTT-CI"
  616. },
  617. {
  618. .tuner_type = TUNER_TYPE_UNKNOWN,
  619. .tuner_name = "UNKNOWN",
  620. .board_name = "VP3051",
  621. .fw_name = "DTTNXT"
  622. },
  623. {
  624. .tuner_type = TUNER_TYPE_NXT200x,
  625. .tuner_name = "NXT200x",
  626. .board_name = "VP3220",
  627. .fw_name = "ATSCDI"
  628. },
  629. {
  630. .tuner_type = TUNER_TYPE_NXT200x,
  631. .tuner_name = "NXT200x",
  632. .board_name = "VP3250",
  633. .fw_name = "ATSCAD"
  634. },
  635. };
  636. /*
  637. Known cards list
  638. Satellite
  639. -------------------
  640. 200103A
  641. VP-1020 DST-MOT LG(old), TS=188
  642. VP-1020 DST-03T LG(new), TS=204
  643. VP-1022 DST-03T LG(new), TS=204
  644. VP-1025 DST-03T LG(new), TS=204
  645. VP-1030 DSTMCI, LG(new), TS=188
  646. VP-1032 DSTMCI, LG(new), TS=188
  647. Cable
  648. -------------------
  649. VP-2030 DCT-CI, Samsung, TS=204
  650. VP-2021 DCT-CI, Unknown, TS=204
  651. VP-2031 DCT-CI, Philips, TS=188
  652. VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
  653. VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
  654. Terrestrial
  655. -------------------
  656. VP-3050 DTTNXT TS=188
  657. VP-3040 DTT-CI, Philips, TS=188
  658. VP-3040 DTT-CI, Philips, TS=204
  659. ATSC
  660. -------------------
  661. VP-3220 ATSCDI, TS=188
  662. VP-3250 ATSCAD, TS=188
  663. */
  664. static struct dst_types dst_tlist[] = {
  665. {
  666. .device_id = "200103A",
  667. .offset = 0,
  668. .dst_type = DST_TYPE_IS_SAT,
  669. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
  670. .dst_feature = 0,
  671. .tuner_type = 0
  672. }, /* obsolete */
  673. {
  674. .device_id = "DST-020",
  675. .offset = 0,
  676. .dst_type = DST_TYPE_IS_SAT,
  677. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
  678. .dst_feature = 0,
  679. .tuner_type = 0
  680. }, /* obsolete */
  681. {
  682. .device_id = "DST-030",
  683. .offset = 0,
  684. .dst_type = DST_TYPE_IS_SAT,
  685. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_1,
  686. .dst_feature = 0,
  687. .tuner_type = 0
  688. }, /* obsolete */
  689. {
  690. .device_id = "DST-03T",
  691. .offset = 0,
  692. .dst_type = DST_TYPE_IS_SAT,
  693. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
  694. .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
  695. | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO,
  696. .tuner_type = TUNER_TYPE_MULTI
  697. },
  698. {
  699. .device_id = "DST-MOT",
  700. .offset = 0,
  701. .dst_type = DST_TYPE_IS_SAT,
  702. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
  703. .dst_feature = 0,
  704. .tuner_type = 0
  705. }, /* obsolete */
  706. {
  707. .device_id = "DST-CI",
  708. .offset = 1,
  709. .dst_type = DST_TYPE_IS_SAT,
  710. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_1,
  711. .dst_feature = DST_TYPE_HAS_CA,
  712. .tuner_type = 0
  713. }, /* An OEM board */
  714. {
  715. .device_id = "DSTMCI",
  716. .offset = 1,
  717. .dst_type = DST_TYPE_IS_SAT,
  718. .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,
  719. .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
  720. | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC,
  721. .tuner_type = TUNER_TYPE_MULTI
  722. },
  723. {
  724. .device_id = "DSTFCI",
  725. .offset = 1,
  726. .dst_type = DST_TYPE_IS_SAT,
  727. .type_flags = DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_1,
  728. .dst_feature = 0,
  729. .tuner_type = 0
  730. }, /* unknown to vendor */
  731. {
  732. .device_id = "DCT-CI",
  733. .offset = 1,
  734. .dst_type = DST_TYPE_IS_CABLE,
  735. .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_VLF,
  736. .dst_feature = DST_TYPE_HAS_CA,
  737. .tuner_type = 0
  738. },
  739. {
  740. .device_id = "DCTNEW",
  741. .offset = 1,
  742. .dst_type = DST_TYPE_IS_CABLE,
  743. .type_flags = DST_TYPE_HAS_TS188 | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_MULTI_FE,
  744. .dst_feature = 0,
  745. .tuner_type = 0
  746. },
  747. {
  748. .device_id = "DTT-CI",
  749. .offset = 1,
  750. .dst_type = DST_TYPE_IS_TERR,
  751. .type_flags = DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_VLF,
  752. .dst_feature = DST_TYPE_HAS_CA,
  753. .tuner_type = 0
  754. },
  755. {
  756. .device_id = "DTTDIG",
  757. .offset = 1,
  758. .dst_type = DST_TYPE_IS_TERR,
  759. .type_flags = DST_TYPE_HAS_FW_2,
  760. .dst_feature = 0,
  761. .tuner_type = 0
  762. },
  763. {
  764. .device_id = "DTTNXT",
  765. .offset = 1,
  766. .dst_type = DST_TYPE_IS_TERR,
  767. .type_flags = DST_TYPE_HAS_FW_2,
  768. .dst_feature = DST_TYPE_HAS_ANALOG,
  769. .tuner_type = 0
  770. },
  771. {
  772. .device_id = "ATSCDI",
  773. .offset = 1,
  774. .dst_type = DST_TYPE_IS_ATSC,
  775. .type_flags = DST_TYPE_HAS_FW_2,
  776. .dst_feature = 0,
  777. .tuner_type = 0
  778. },
  779. {
  780. .device_id = "ATSCAD",
  781. .offset = 1,
  782. .dst_type = DST_TYPE_IS_ATSC,
  783. .type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
  784. .dst_feature = DST_TYPE_HAS_MAC | DST_TYPE_HAS_ANALOG,
  785. .tuner_type = 0
  786. },
  787. { }
  788. };
  789. static int dst_get_mac(struct dst_state *state)
  790. {
  791. u8 get_mac[] = { 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  792. get_mac[7] = dst_check_sum(get_mac, 7);
  793. if (dst_command(state, get_mac, 8) < 0) {
  794. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  795. return -1;
  796. }
  797. memset(&state->mac_address, '\0', 8);
  798. memcpy(&state->mac_address, &state->rxbuffer, 6);
  799. dprintk(verbose, DST_ERROR, 1, "MAC Address=[%pM]", state->mac_address);
  800. return 0;
  801. }
  802. static int dst_fw_ver(struct dst_state *state)
  803. {
  804. u8 get_ver[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  805. get_ver[7] = dst_check_sum(get_ver, 7);
  806. if (dst_command(state, get_ver, 8) < 0) {
  807. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  808. return -1;
  809. }
  810. memcpy(&state->fw_version, &state->rxbuffer, 8);
  811. dprintk(verbose, DST_ERROR, 1, "Firmware Ver = %x.%x Build = %02x, on %x:%x, %x-%x-20%02x",
  812. state->fw_version[0] >> 4, state->fw_version[0] & 0x0f,
  813. state->fw_version[1],
  814. state->fw_version[5], state->fw_version[6],
  815. state->fw_version[4], state->fw_version[3], state->fw_version[2]);
  816. return 0;
  817. }
  818. static int dst_card_type(struct dst_state *state)
  819. {
  820. int j;
  821. struct tuner_types *p_tuner_list = NULL;
  822. u8 get_type[] = { 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  823. get_type[7] = dst_check_sum(get_type, 7);
  824. if (dst_command(state, get_type, 8) < 0) {
  825. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  826. return -1;
  827. }
  828. memset(&state->card_info, '\0', 8);
  829. memcpy(&state->card_info, &state->rxbuffer, 7);
  830. dprintk(verbose, DST_ERROR, 1, "Device Model=[%s]", &state->card_info[0]);
  831. for (j = 0, p_tuner_list = tuner_list; j < ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
  832. if (!strcmp(&state->card_info[0], p_tuner_list->board_name)) {
  833. state->tuner_type = p_tuner_list->tuner_type;
  834. dprintk(verbose, DST_ERROR, 1, "DST has [%s] tuner, tuner type=[%d]",
  835. p_tuner_list->tuner_name, p_tuner_list->tuner_type);
  836. }
  837. }
  838. return 0;
  839. }
  840. static int dst_get_vendor(struct dst_state *state)
  841. {
  842. u8 get_vendor[] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  843. get_vendor[7] = dst_check_sum(get_vendor, 7);
  844. if (dst_command(state, get_vendor, 8) < 0) {
  845. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  846. return -1;
  847. }
  848. memset(&state->vendor, '\0', 8);
  849. memcpy(&state->vendor, &state->rxbuffer, 7);
  850. dprintk(verbose, DST_ERROR, 1, "Vendor=[%s]", &state->vendor[0]);
  851. return 0;
  852. }
  853. static void debug_dst_buffer(struct dst_state *state)
  854. {
  855. int i;
  856. if (verbose > 2) {
  857. printk("%s: [", __func__);
  858. for (i = 0; i < 8; i++)
  859. printk(" %02x", state->rxbuffer[i]);
  860. printk("]\n");
  861. }
  862. }
  863. static int dst_check_stv0299(struct dst_state *state)
  864. {
  865. u8 check_stv0299[] = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  866. check_stv0299[7] = dst_check_sum(check_stv0299, 7);
  867. if (dst_command(state, check_stv0299, 8) < 0) {
  868. dprintk(verbose, DST_ERROR, 1, "Cmd=[0x04] failed");
  869. return -1;
  870. }
  871. debug_dst_buffer(state);
  872. if (memcmp(&check_stv0299, &state->rxbuffer, 8)) {
  873. dprintk(verbose, DST_ERROR, 1, "Found a STV0299 NIM");
  874. state->tuner_type = TUNER_TYPE_STV0299;
  875. return 0;
  876. }
  877. return -1;
  878. }
  879. static int dst_check_mb86a15(struct dst_state *state)
  880. {
  881. u8 check_mb86a15[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  882. check_mb86a15[7] = dst_check_sum(check_mb86a15, 7);
  883. if (dst_command(state, check_mb86a15, 8) < 0) {
  884. dprintk(verbose, DST_ERROR, 1, "Cmd=[0x10], failed");
  885. return -1;
  886. }
  887. debug_dst_buffer(state);
  888. if (memcmp(&check_mb86a15, &state->rxbuffer, 8) < 0) {
  889. dprintk(verbose, DST_ERROR, 1, "Found a MB86A15 NIM");
  890. state->tuner_type = TUNER_TYPE_MB86A15;
  891. return 0;
  892. }
  893. return -1;
  894. }
  895. static int dst_get_tuner_info(struct dst_state *state)
  896. {
  897. u8 get_tuner_1[] = { 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  898. u8 get_tuner_2[] = { 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  899. get_tuner_1[7] = dst_check_sum(get_tuner_1, 7);
  900. get_tuner_2[7] = dst_check_sum(get_tuner_2, 7);
  901. dprintk(verbose, DST_ERROR, 1, "DST TYpe = MULTI FE");
  902. if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
  903. if (dst_command(state, get_tuner_1, 8) < 0) {
  904. dprintk(verbose, DST_INFO, 1, "Cmd=[0x13], Unsupported");
  905. goto force;
  906. }
  907. } else {
  908. if (dst_command(state, get_tuner_2, 8) < 0) {
  909. dprintk(verbose, DST_INFO, 1, "Cmd=[0xb], Unsupported");
  910. goto force;
  911. }
  912. }
  913. memcpy(&state->board_info, &state->rxbuffer, 8);
  914. if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
  915. dprintk(verbose, DST_ERROR, 1, "DST type has TS=188");
  916. }
  917. if (state->board_info[0] == 0xbc) {
  918. if (state->dst_type != DST_TYPE_IS_ATSC)
  919. state->type_flags |= DST_TYPE_HAS_TS188;
  920. else
  921. state->type_flags |= DST_TYPE_HAS_NEWTUNE_2;
  922. if (state->board_info[1] == 0x01) {
  923. state->dst_hw_cap |= DST_TYPE_HAS_DBOARD;
  924. dprintk(verbose, DST_ERROR, 1, "DST has Daughterboard");
  925. }
  926. }
  927. return 0;
  928. force:
  929. if (!strncmp(state->fw_name, "DCT-CI", 6)) {
  930. state->type_flags |= DST_TYPE_HAS_TS204;
  931. dprintk(verbose, DST_ERROR, 1, "Forcing [%s] to TS188", state->fw_name);
  932. }
  933. return -1;
  934. }
  935. static int dst_get_device_id(struct dst_state *state)
  936. {
  937. u8 reply;
  938. int i, j;
  939. struct dst_types *p_dst_type = NULL;
  940. struct tuner_types *p_tuner_list = NULL;
  941. u8 use_dst_type = 0;
  942. u32 use_type_flags = 0;
  943. static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
  944. state->tuner_type = 0;
  945. device_type[7] = dst_check_sum(device_type, 7);
  946. if (write_dst(state, device_type, FIXED_COMM))
  947. return -1; /* Write failed */
  948. if ((dst_pio_disable(state)) < 0)
  949. return -1;
  950. if (read_dst(state, &reply, GET_ACK))
  951. return -1; /* Read failure */
  952. if (reply != ACK) {
  953. dprintk(verbose, DST_INFO, 1, "Write not Acknowledged! [Reply=0x%02x]", reply);
  954. return -1; /* Unack'd write */
  955. }
  956. if (!dst_wait_dst_ready(state, DEVICE_INIT))
  957. return -1; /* DST not ready yet */
  958. if (read_dst(state, state->rxbuffer, FIXED_COMM))
  959. return -1;
  960. dst_pio_disable(state);
  961. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  962. dprintk(verbose, DST_INFO, 1, "Checksum failure!");
  963. return -1; /* Checksum failure */
  964. }
  965. state->rxbuffer[7] = '\0';
  966. for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
  967. if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
  968. use_type_flags = p_dst_type->type_flags;
  969. use_dst_type = p_dst_type->dst_type;
  970. /* Card capabilities */
  971. state->dst_hw_cap = p_dst_type->dst_feature;
  972. dprintk(verbose, DST_ERROR, 1, "Recognise [%s]", p_dst_type->device_id);
  973. strncpy(&state->fw_name[0], p_dst_type->device_id, 6);
  974. /* Multiple tuners */
  975. if (p_dst_type->tuner_type & TUNER_TYPE_MULTI) {
  976. switch (use_dst_type) {
  977. case DST_TYPE_IS_SAT:
  978. /* STV0299 check */
  979. if (dst_check_stv0299(state) < 0) {
  980. dprintk(verbose, DST_ERROR, 1, "Unsupported");
  981. state->tuner_type = TUNER_TYPE_MB86A15;
  982. }
  983. break;
  984. default:
  985. break;
  986. }
  987. if (dst_check_mb86a15(state) < 0)
  988. dprintk(verbose, DST_ERROR, 1, "Unsupported");
  989. /* Single tuner */
  990. } else {
  991. state->tuner_type = p_dst_type->tuner_type;
  992. }
  993. for (j = 0, p_tuner_list = tuner_list; j < ARRAY_SIZE(tuner_list); j++, p_tuner_list++) {
  994. if (!(strncmp(p_dst_type->device_id, p_tuner_list->fw_name, 7)) &&
  995. p_tuner_list->tuner_type == state->tuner_type) {
  996. dprintk(verbose, DST_ERROR, 1, "[%s] has a [%s]",
  997. p_dst_type->device_id, p_tuner_list->tuner_name);
  998. }
  999. }
  1000. break;
  1001. }
  1002. }
  1003. if (i >= ARRAY_SIZE(dst_tlist)) {
  1004. dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
  1005. dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
  1006. use_dst_type = DST_TYPE_IS_SAT;
  1007. use_type_flags = DST_TYPE_HAS_SYMDIV;
  1008. }
  1009. dst_type_print(state, use_dst_type);
  1010. state->type_flags = use_type_flags;
  1011. state->dst_type = use_dst_type;
  1012. dst_type_flags_print(state);
  1013. return 0;
  1014. }
  1015. static int dst_probe(struct dst_state *state)
  1016. {
  1017. mutex_init(&state->dst_mutex);
  1018. if (dst_addons & DST_TYPE_HAS_CA) {
  1019. if ((rdc_8820_reset(state)) < 0) {
  1020. dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
  1021. return -1;
  1022. }
  1023. msleep(4000);
  1024. } else {
  1025. msleep(100);
  1026. }
  1027. if ((dst_comm_init(state)) < 0) {
  1028. dprintk(verbose, DST_ERROR, 1, "DST Initialization Failed.");
  1029. return -1;
  1030. }
  1031. msleep(100);
  1032. if (dst_get_device_id(state) < 0) {
  1033. dprintk(verbose, DST_ERROR, 1, "unknown device.");
  1034. return -1;
  1035. }
  1036. if (dst_get_mac(state) < 0) {
  1037. dprintk(verbose, DST_INFO, 1, "MAC: Unsupported command");
  1038. }
  1039. if ((state->type_flags & DST_TYPE_HAS_MULTI_FE) || (state->type_flags & DST_TYPE_HAS_FW_BUILD)) {
  1040. if (dst_get_tuner_info(state) < 0)
  1041. dprintk(verbose, DST_INFO, 1, "Tuner: Unsupported command");
  1042. }
  1043. if (state->type_flags & DST_TYPE_HAS_TS204) {
  1044. dst_packsize(state, 204);
  1045. }
  1046. if (state->type_flags & DST_TYPE_HAS_FW_BUILD) {
  1047. if (dst_fw_ver(state) < 0) {
  1048. dprintk(verbose, DST_INFO, 1, "FW: Unsupported command");
  1049. return 0;
  1050. }
  1051. if (dst_card_type(state) < 0) {
  1052. dprintk(verbose, DST_INFO, 1, "Card: Unsupported command");
  1053. return 0;
  1054. }
  1055. if (dst_get_vendor(state) < 0) {
  1056. dprintk(verbose, DST_INFO, 1, "Vendor: Unsupported command");
  1057. return 0;
  1058. }
  1059. }
  1060. return 0;
  1061. }
  1062. static int dst_command(struct dst_state *state, u8 *data, u8 len)
  1063. {
  1064. u8 reply;
  1065. mutex_lock(&state->dst_mutex);
  1066. if ((dst_comm_init(state)) < 0) {
  1067. dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
  1068. goto error;
  1069. }
  1070. if (write_dst(state, data, len)) {
  1071. dprintk(verbose, DST_INFO, 1, "Trying to recover.. ");
  1072. if ((dst_error_recovery(state)) < 0) {
  1073. dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
  1074. goto error;
  1075. }
  1076. goto error;
  1077. }
  1078. if ((dst_pio_disable(state)) < 0) {
  1079. dprintk(verbose, DST_ERROR, 1, "PIO Disable Failed.");
  1080. goto error;
  1081. }
  1082. if (state->type_flags & DST_TYPE_HAS_FW_1)
  1083. mdelay(3);
  1084. if (read_dst(state, &reply, GET_ACK)) {
  1085. dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
  1086. if ((dst_error_recovery(state)) < 0) {
  1087. dprintk(verbose, DST_INFO, 1, "Recovery Failed.");
  1088. goto error;
  1089. }
  1090. goto error;
  1091. }
  1092. if (reply != ACK) {
  1093. dprintk(verbose, DST_INFO, 1, "write not acknowledged 0x%02x ", reply);
  1094. goto error;
  1095. }
  1096. if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
  1097. goto error;
  1098. if (state->type_flags & DST_TYPE_HAS_FW_1)
  1099. mdelay(3);
  1100. else
  1101. udelay(2000);
  1102. if (!dst_wait_dst_ready(state, NO_DELAY))
  1103. goto error;
  1104. if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
  1105. dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
  1106. if ((dst_error_recovery(state)) < 0) {
  1107. dprintk(verbose, DST_INFO, 1, "Recovery failed.");
  1108. goto error;
  1109. }
  1110. goto error;
  1111. }
  1112. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  1113. dprintk(verbose, DST_INFO, 1, "checksum failure");
  1114. goto error;
  1115. }
  1116. mutex_unlock(&state->dst_mutex);
  1117. return 0;
  1118. error:
  1119. mutex_unlock(&state->dst_mutex);
  1120. return -EIO;
  1121. }
  1122. static int dst_get_signal(struct dst_state *state)
  1123. {
  1124. int retval;
  1125. u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
  1126. //dprintk("%s: Getting Signal strength and other parameters\n", __func__);
  1127. if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
  1128. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  1129. return 0;
  1130. }
  1131. if (0 == (state->diseq_flags & HAS_LOCK)) {
  1132. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  1133. return 0;
  1134. }
  1135. if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
  1136. retval = dst_command(state, get_signal, 8);
  1137. if (retval < 0)
  1138. return retval;
  1139. if (state->dst_type == DST_TYPE_IS_SAT) {
  1140. state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
  1141. state->decode_strength = state->rxbuffer[5] << 8;
  1142. state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
  1143. } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
  1144. state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
  1145. state->decode_strength = state->rxbuffer[4] << 8;
  1146. state->decode_snr = state->rxbuffer[3] << 8;
  1147. } else if (state->dst_type == DST_TYPE_IS_ATSC) {
  1148. state->decode_lock = (state->rxbuffer[6] == 0x00) ? 1 : 0;
  1149. state->decode_strength = state->rxbuffer[4] << 8;
  1150. state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
  1151. }
  1152. state->cur_jiff = jiffies;
  1153. }
  1154. return 0;
  1155. }
  1156. static int dst_tone_power_cmd(struct dst_state *state)
  1157. {
  1158. u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
  1159. if (state->dst_type != DST_TYPE_IS_SAT)
  1160. return -EOPNOTSUPP;
  1161. paket[4] = state->tx_tuna[4];
  1162. paket[2] = state->tx_tuna[2];
  1163. paket[3] = state->tx_tuna[3];
  1164. paket[7] = dst_check_sum (paket, 7);
  1165. return dst_command(state, paket, 8);
  1166. }
  1167. static int dst_get_tuna(struct dst_state *state)
  1168. {
  1169. int retval;
  1170. if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
  1171. return 0;
  1172. state->diseq_flags &= ~(HAS_LOCK);
  1173. if (!dst_wait_dst_ready(state, NO_DELAY))
  1174. return -EIO;
  1175. if ((state->type_flags & DST_TYPE_HAS_VLF) &&
  1176. !(state->dst_type == DST_TYPE_IS_ATSC))
  1177. retval = read_dst(state, state->rx_tuna, 10);
  1178. else
  1179. retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
  1180. if (retval < 0) {
  1181. dprintk(verbose, DST_DEBUG, 1, "read not successful");
  1182. return retval;
  1183. }
  1184. if ((state->type_flags & DST_TYPE_HAS_VLF) &&
  1185. !(state->dst_type == DST_TYPE_IS_ATSC)) {
  1186. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
  1187. dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
  1188. return -EIO;
  1189. }
  1190. } else {
  1191. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
  1192. dprintk(verbose, DST_INFO, 1, "checksum failure? ");
  1193. return -EIO;
  1194. }
  1195. }
  1196. if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
  1197. return 0;
  1198. if (state->dst_type == DST_TYPE_IS_SAT) {
  1199. state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
  1200. } else {
  1201. state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 16) + (state->rx_tuna[3] << 8) + state->rx_tuna[4];
  1202. }
  1203. state->decode_freq = state->decode_freq * 1000;
  1204. state->decode_lock = 1;
  1205. state->diseq_flags |= HAS_LOCK;
  1206. return 1;
  1207. }
  1208. static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
  1209. static int dst_write_tuna(struct dvb_frontend *fe)
  1210. {
  1211. struct dst_state *state = fe->demodulator_priv;
  1212. int retval;
  1213. u8 reply;
  1214. dprintk(verbose, DST_INFO, 1, "type_flags 0x%x ", state->type_flags);
  1215. state->decode_freq = 0;
  1216. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  1217. if (state->dst_type == DST_TYPE_IS_SAT) {
  1218. if (!(state->diseq_flags & HAS_POWER))
  1219. dst_set_voltage(fe, SEC_VOLTAGE_13);
  1220. }
  1221. state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
  1222. mutex_lock(&state->dst_mutex);
  1223. if ((dst_comm_init(state)) < 0) {
  1224. dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
  1225. goto error;
  1226. }
  1227. // if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  1228. if ((state->type_flags & DST_TYPE_HAS_VLF) &&
  1229. (!(state->dst_type == DST_TYPE_IS_ATSC))) {
  1230. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
  1231. retval = write_dst(state, &state->tx_tuna[0], 10);
  1232. } else {
  1233. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
  1234. retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
  1235. }
  1236. if (retval < 0) {
  1237. dst_pio_disable(state);
  1238. dprintk(verbose, DST_DEBUG, 1, "write not successful");
  1239. goto werr;
  1240. }
  1241. if ((dst_pio_disable(state)) < 0) {
  1242. dprintk(verbose, DST_DEBUG, 1, "DST PIO disable failed !");
  1243. goto error;
  1244. }
  1245. if ((read_dst(state, &reply, GET_ACK) < 0)) {
  1246. dprintk(verbose, DST_DEBUG, 1, "read verify not successful.");
  1247. goto error;
  1248. }
  1249. if (reply != ACK) {
  1250. dprintk(verbose, DST_DEBUG, 1, "write not acknowledged 0x%02x ", reply);
  1251. goto error;
  1252. }
  1253. state->diseq_flags |= ATTEMPT_TUNE;
  1254. retval = dst_get_tuna(state);
  1255. werr:
  1256. mutex_unlock(&state->dst_mutex);
  1257. return retval;
  1258. error:
  1259. mutex_unlock(&state->dst_mutex);
  1260. return -EIO;
  1261. }
  1262. /*
  1263. * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
  1264. * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
  1265. * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
  1266. * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
  1267. * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
  1268. * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
  1269. * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
  1270. * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
  1271. * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
  1272. * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
  1273. * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
  1274. */
  1275. static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
  1276. {
  1277. struct dst_state *state = fe->demodulator_priv;
  1278. u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
  1279. if (state->dst_type != DST_TYPE_IS_SAT)
  1280. return -EOPNOTSUPP;
  1281. if (cmd->msg_len > 0 && cmd->msg_len < 5)
  1282. memcpy(&paket[3], cmd->msg, cmd->msg_len);
  1283. else if (cmd->msg_len == 5 && state->dst_hw_cap & DST_TYPE_HAS_DISEQC5)
  1284. memcpy(&paket[2], cmd->msg, cmd->msg_len);
  1285. else
  1286. return -EINVAL;
  1287. paket[7] = dst_check_sum(&paket[0], 7);
  1288. return dst_command(state, paket, 8);
  1289. }
  1290. static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  1291. {
  1292. int need_cmd, retval = 0;
  1293. struct dst_state *state = fe->demodulator_priv;
  1294. state->voltage = voltage;
  1295. if (state->dst_type != DST_TYPE_IS_SAT)
  1296. return -EOPNOTSUPP;
  1297. need_cmd = 0;
  1298. switch (voltage) {
  1299. case SEC_VOLTAGE_13:
  1300. case SEC_VOLTAGE_18:
  1301. if ((state->diseq_flags & HAS_POWER) == 0)
  1302. need_cmd = 1;
  1303. state->diseq_flags |= HAS_POWER;
  1304. state->tx_tuna[4] = 0x01;
  1305. break;
  1306. case SEC_VOLTAGE_OFF:
  1307. need_cmd = 1;
  1308. state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
  1309. state->tx_tuna[4] = 0x00;
  1310. break;
  1311. default:
  1312. return -EINVAL;
  1313. }
  1314. if (need_cmd)
  1315. retval = dst_tone_power_cmd(state);
  1316. return retval;
  1317. }
  1318. static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
  1319. {
  1320. struct dst_state *state = fe->demodulator_priv;
  1321. state->tone = tone;
  1322. if (state->dst_type != DST_TYPE_IS_SAT)
  1323. return -EOPNOTSUPP;
  1324. switch (tone) {
  1325. case SEC_TONE_OFF:
  1326. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1327. state->tx_tuna[2] = 0x00;
  1328. else
  1329. state->tx_tuna[2] = 0xff;
  1330. break;
  1331. case SEC_TONE_ON:
  1332. state->tx_tuna[2] = 0x02;
  1333. break;
  1334. default:
  1335. return -EINVAL;
  1336. }
  1337. return dst_tone_power_cmd(state);
  1338. }
  1339. static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
  1340. {
  1341. struct dst_state *state = fe->demodulator_priv;
  1342. if (state->dst_type != DST_TYPE_IS_SAT)
  1343. return -EOPNOTSUPP;
  1344. state->minicmd = minicmd;
  1345. switch (minicmd) {
  1346. case SEC_MINI_A:
  1347. state->tx_tuna[3] = 0x02;
  1348. break;
  1349. case SEC_MINI_B:
  1350. state->tx_tuna[3] = 0xff;
  1351. break;
  1352. }
  1353. return dst_tone_power_cmd(state);
  1354. }
  1355. static int dst_init(struct dvb_frontend *fe)
  1356. {
  1357. struct dst_state *state = fe->demodulator_priv;
  1358. static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
  1359. static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
  1360. static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1361. static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1362. static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1363. static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1364. static u8 atsc_tuner[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1365. state->inversion = INVERSION_OFF;
  1366. state->voltage = SEC_VOLTAGE_13;
  1367. state->tone = SEC_TONE_OFF;
  1368. state->diseq_flags = 0;
  1369. state->k22 = 0x02;
  1370. state->bandwidth = 7000000;
  1371. state->cur_jiff = jiffies;
  1372. if (state->dst_type == DST_TYPE_IS_SAT)
  1373. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
  1374. else if (state->dst_type == DST_TYPE_IS_TERR)
  1375. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
  1376. else if (state->dst_type == DST_TYPE_IS_CABLE)
  1377. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_VLF) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
  1378. else if (state->dst_type == DST_TYPE_IS_ATSC)
  1379. memcpy(state->tx_tuna, atsc_tuner, sizeof (atsc_tuner));
  1380. return 0;
  1381. }
  1382. static int dst_read_status(struct dvb_frontend *fe, fe_status_t *status)
  1383. {
  1384. struct dst_state *state = fe->demodulator_priv;
  1385. *status = 0;
  1386. if (state->diseq_flags & HAS_LOCK) {
  1387. // dst_get_signal(state); // don't require(?) to ask MCU
  1388. if (state->decode_lock)
  1389. *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
  1390. }
  1391. return 0;
  1392. }
  1393. static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  1394. {
  1395. struct dst_state *state = fe->demodulator_priv;
  1396. int retval = dst_get_signal(state);
  1397. *strength = state->decode_strength;
  1398. return retval;
  1399. }
  1400. static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
  1401. {
  1402. struct dst_state *state = fe->demodulator_priv;
  1403. int retval = dst_get_signal(state);
  1404. *snr = state->decode_snr;
  1405. return retval;
  1406. }
  1407. static int dst_set_frontend(struct dvb_frontend *fe)
  1408. {
  1409. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1410. int retval = -EINVAL;
  1411. struct dst_state *state = fe->demodulator_priv;
  1412. if (p != NULL) {
  1413. retval = dst_set_freq(state, p->frequency);
  1414. if(retval != 0)
  1415. return retval;
  1416. dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
  1417. if (state->dst_type == DST_TYPE_IS_SAT) {
  1418. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1419. dst_set_inversion(state, p->inversion);
  1420. dst_set_fec(state, p->fec_inner);
  1421. dst_set_symbolrate(state, p->symbol_rate);
  1422. dst_set_polarization(state);
  1423. dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->symbol_rate);
  1424. } else if (state->dst_type == DST_TYPE_IS_TERR)
  1425. dst_set_bandwidth(state, p->bandwidth_hz);
  1426. else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1427. dst_set_fec(state, p->fec_inner);
  1428. dst_set_symbolrate(state, p->symbol_rate);
  1429. dst_set_modulation(state, p->modulation);
  1430. }
  1431. retval = dst_write_tuna(fe);
  1432. }
  1433. return retval;
  1434. }
  1435. static int dst_tune_frontend(struct dvb_frontend* fe,
  1436. bool re_tune,
  1437. unsigned int mode_flags,
  1438. unsigned int *delay,
  1439. fe_status_t *status)
  1440. {
  1441. struct dst_state *state = fe->demodulator_priv;
  1442. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1443. if (re_tune) {
  1444. dst_set_freq(state, p->frequency);
  1445. dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
  1446. if (state->dst_type == DST_TYPE_IS_SAT) {
  1447. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1448. dst_set_inversion(state, p->inversion);
  1449. dst_set_fec(state, p->fec_inner);
  1450. dst_set_symbolrate(state, p->symbol_rate);
  1451. dst_set_polarization(state);
  1452. dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->symbol_rate);
  1453. } else if (state->dst_type == DST_TYPE_IS_TERR)
  1454. dst_set_bandwidth(state, p->bandwidth_hz);
  1455. else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1456. dst_set_fec(state, p->fec_inner);
  1457. dst_set_symbolrate(state, p->symbol_rate);
  1458. dst_set_modulation(state, p->modulation);
  1459. }
  1460. dst_write_tuna(fe);
  1461. }
  1462. if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
  1463. dst_read_status(fe, status);
  1464. *delay = HZ/10;
  1465. return 0;
  1466. }
  1467. static int dst_get_tuning_algo(struct dvb_frontend *fe)
  1468. {
  1469. return dst_algo ? DVBFE_ALGO_HW : DVBFE_ALGO_SW;
  1470. }
  1471. static int dst_get_frontend(struct dvb_frontend *fe)
  1472. {
  1473. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1474. struct dst_state *state = fe->demodulator_priv;
  1475. p->frequency = state->decode_freq;
  1476. if (state->dst_type == DST_TYPE_IS_SAT) {
  1477. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1478. p->inversion = state->inversion;
  1479. p->symbol_rate = state->symbol_rate;
  1480. p->fec_inner = dst_get_fec(state);
  1481. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  1482. p->bandwidth_hz = state->bandwidth;
  1483. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1484. p->symbol_rate = state->symbol_rate;
  1485. p->fec_inner = dst_get_fec(state);
  1486. p->modulation = dst_get_modulation(state);
  1487. }
  1488. return 0;
  1489. }
  1490. static void dst_release(struct dvb_frontend *fe)
  1491. {
  1492. struct dst_state *state = fe->demodulator_priv;
  1493. if (state->dst_ca) {
  1494. dvb_unregister_device(state->dst_ca);
  1495. #ifdef CONFIG_MEDIA_ATTACH
  1496. symbol_put(dst_ca_attach);
  1497. #endif
  1498. }
  1499. kfree(state);
  1500. }
  1501. static struct dvb_frontend_ops dst_dvbt_ops;
  1502. static struct dvb_frontend_ops dst_dvbs_ops;
  1503. static struct dvb_frontend_ops dst_dvbc_ops;
  1504. static struct dvb_frontend_ops dst_atsc_ops;
  1505. struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
  1506. {
  1507. /* check if the ASIC is there */
  1508. if (dst_probe(state) < 0) {
  1509. kfree(state);
  1510. return NULL;
  1511. }
  1512. /* determine settings based on type */
  1513. /* create dvb_frontend */
  1514. switch (state->dst_type) {
  1515. case DST_TYPE_IS_TERR:
  1516. memcpy(&state->frontend.ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
  1517. break;
  1518. case DST_TYPE_IS_CABLE:
  1519. memcpy(&state->frontend.ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
  1520. break;
  1521. case DST_TYPE_IS_SAT:
  1522. memcpy(&state->frontend.ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
  1523. break;
  1524. case DST_TYPE_IS_ATSC:
  1525. memcpy(&state->frontend.ops, &dst_atsc_ops, sizeof(struct dvb_frontend_ops));
  1526. break;
  1527. default:
  1528. dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
  1529. kfree(state);
  1530. return NULL;
  1531. }
  1532. state->frontend.demodulator_priv = state;
  1533. return state; /* Manu (DST is a card not a frontend) */
  1534. }
  1535. EXPORT_SYMBOL(dst_attach);
  1536. static struct dvb_frontend_ops dst_dvbt_ops = {
  1537. .delsys = { SYS_DVBT },
  1538. .info = {
  1539. .name = "DST DVB-T",
  1540. .frequency_min = 137000000,
  1541. .frequency_max = 858000000,
  1542. .frequency_stepsize = 166667,
  1543. .caps = FE_CAN_FEC_AUTO |
  1544. FE_CAN_QAM_AUTO |
  1545. FE_CAN_QAM_16 |
  1546. FE_CAN_QAM_32 |
  1547. FE_CAN_QAM_64 |
  1548. FE_CAN_QAM_128 |
  1549. FE_CAN_QAM_256 |
  1550. FE_CAN_TRANSMISSION_MODE_AUTO |
  1551. FE_CAN_GUARD_INTERVAL_AUTO
  1552. },
  1553. .release = dst_release,
  1554. .init = dst_init,
  1555. .tune = dst_tune_frontend,
  1556. .set_frontend = dst_set_frontend,
  1557. .get_frontend = dst_get_frontend,
  1558. .get_frontend_algo = dst_get_tuning_algo,
  1559. .read_status = dst_read_status,
  1560. .read_signal_strength = dst_read_signal_strength,
  1561. .read_snr = dst_read_snr,
  1562. };
  1563. static struct dvb_frontend_ops dst_dvbs_ops = {
  1564. .delsys = { SYS_DVBS },
  1565. .info = {
  1566. .name = "DST DVB-S",
  1567. .frequency_min = 950000,
  1568. .frequency_max = 2150000,
  1569. .frequency_stepsize = 1000, /* kHz for QPSK frontends */
  1570. .frequency_tolerance = 29500,
  1571. .symbol_rate_min = 1000000,
  1572. .symbol_rate_max = 45000000,
  1573. /* . symbol_rate_tolerance = ???,*/
  1574. .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
  1575. },
  1576. .release = dst_release,
  1577. .init = dst_init,
  1578. .tune = dst_tune_frontend,
  1579. .set_frontend = dst_set_frontend,
  1580. .get_frontend = dst_get_frontend,
  1581. .get_frontend_algo = dst_get_tuning_algo,
  1582. .read_status = dst_read_status,
  1583. .read_signal_strength = dst_read_signal_strength,
  1584. .read_snr = dst_read_snr,
  1585. .diseqc_send_burst = dst_send_burst,
  1586. .diseqc_send_master_cmd = dst_set_diseqc,
  1587. .set_voltage = dst_set_voltage,
  1588. .set_tone = dst_set_tone,
  1589. };
  1590. static struct dvb_frontend_ops dst_dvbc_ops = {
  1591. .delsys = { SYS_DVBC_ANNEX_A },
  1592. .info = {
  1593. .name = "DST DVB-C",
  1594. .frequency_stepsize = 62500,
  1595. .frequency_min = 51000000,
  1596. .frequency_max = 858000000,
  1597. .symbol_rate_min = 1000000,
  1598. .symbol_rate_max = 45000000,
  1599. .caps = FE_CAN_FEC_AUTO |
  1600. FE_CAN_QAM_AUTO |
  1601. FE_CAN_QAM_16 |
  1602. FE_CAN_QAM_32 |
  1603. FE_CAN_QAM_64 |
  1604. FE_CAN_QAM_128 |
  1605. FE_CAN_QAM_256
  1606. },
  1607. .release = dst_release,
  1608. .init = dst_init,
  1609. .tune = dst_tune_frontend,
  1610. .set_frontend = dst_set_frontend,
  1611. .get_frontend = dst_get_frontend,
  1612. .get_frontend_algo = dst_get_tuning_algo,
  1613. .read_status = dst_read_status,
  1614. .read_signal_strength = dst_read_signal_strength,
  1615. .read_snr = dst_read_snr,
  1616. };
  1617. static struct dvb_frontend_ops dst_atsc_ops = {
  1618. .delsys = { SYS_ATSC },
  1619. .info = {
  1620. .name = "DST ATSC",
  1621. .frequency_stepsize = 62500,
  1622. .frequency_min = 510000000,
  1623. .frequency_max = 858000000,
  1624. .symbol_rate_min = 1000000,
  1625. .symbol_rate_max = 45000000,
  1626. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
  1627. },
  1628. .release = dst_release,
  1629. .init = dst_init,
  1630. .tune = dst_tune_frontend,
  1631. .set_frontend = dst_set_frontend,
  1632. .get_frontend = dst_get_frontend,
  1633. .get_frontend_algo = dst_get_tuning_algo,
  1634. .read_status = dst_read_status,
  1635. .read_signal_strength = dst_read_signal_strength,
  1636. .read_snr = dst_read_snr,
  1637. };
  1638. MODULE_DESCRIPTION("DST DVB-S/T/C/ATSC Combo Frontend driver");
  1639. MODULE_AUTHOR("Jamie Honan, Manu Abraham");
  1640. MODULE_LICENSE("GPL");