dst.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  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. #define HAS_LOCK 1
  35. #define ATTEMPT_TUNE 2
  36. #define HAS_POWER 4
  37. #define DST_ERROR 0
  38. #define DST_NOTICE 1
  39. #define DST_INFO 2
  40. #define DST_DEBUG 3
  41. #define dprintk(x, y, z, format, arg...) do { \
  42. if (z) { \
  43. if ((x > DST_ERROR) && (x > y)) \
  44. printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg); \
  45. else if ((x > DST_NOTICE) && (x > y)) \
  46. printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg); \
  47. else if ((x > DST_INFO) && (x > y)) \
  48. printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg); \
  49. else if ((x > DST_DEBUG) && (x > y)) \
  50. printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg); \
  51. } else { \
  52. if (x > y) \
  53. printk(format, ##arg); \
  54. } \
  55. } while(0)
  56. static void dst_packsize(struct dst_state *state, int psize)
  57. {
  58. union dst_gpio_packet bits;
  59. bits.psize = psize;
  60. bt878_device_control(state->bt, DST_IG_TS, &bits);
  61. }
  62. int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb, u32 outhigh, int delay)
  63. {
  64. union dst_gpio_packet enb;
  65. union dst_gpio_packet bits;
  66. int err;
  67. enb.enb.mask = mask;
  68. enb.enb.enable = enbb;
  69. dprintk(verbose, DST_INFO, 1, "mask=[%04x], enbb=[%04x], outhigh=[%04x]", mask, enbb, outhigh);
  70. if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
  71. dprintk(verbose, DST_INFO, 1, "dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)", err, mask, enbb);
  72. return -EREMOTEIO;
  73. }
  74. udelay(1000);
  75. /* because complete disabling means no output, no need to do output packet */
  76. if (enbb == 0)
  77. return 0;
  78. if (delay)
  79. msleep(10);
  80. bits.outp.mask = enbb;
  81. bits.outp.highvals = outhigh;
  82. if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
  83. dprintk(verbose, DST_INFO, 1, "dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)", err, enbb, outhigh);
  84. return -EREMOTEIO;
  85. }
  86. return 0;
  87. }
  88. EXPORT_SYMBOL(dst_gpio_outb);
  89. int dst_gpio_inb(struct dst_state *state, u8 *result)
  90. {
  91. union dst_gpio_packet rd_packet;
  92. int err;
  93. *result = 0;
  94. if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) {
  95. dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb error (err == %i)\n", err);
  96. return -EREMOTEIO;
  97. }
  98. *result = (u8) rd_packet.rd.value;
  99. return 0;
  100. }
  101. EXPORT_SYMBOL(dst_gpio_inb);
  102. int rdc_reset_state(struct dst_state *state)
  103. {
  104. dprintk(verbose, DST_INFO, 1, "Resetting state machine");
  105. if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
  106. dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
  107. return -1;
  108. }
  109. msleep(10);
  110. if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
  111. dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
  112. msleep(10);
  113. return -1;
  114. }
  115. return 0;
  116. }
  117. EXPORT_SYMBOL(rdc_reset_state);
  118. int rdc_8820_reset(struct dst_state *state)
  119. {
  120. dprintk(verbose, DST_DEBUG, 1, "Resetting DST");
  121. if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
  122. dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
  123. return -1;
  124. }
  125. udelay(1000);
  126. if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
  127. dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
  128. return -1;
  129. }
  130. return 0;
  131. }
  132. EXPORT_SYMBOL(rdc_8820_reset);
  133. int dst_pio_enable(struct dst_state *state)
  134. {
  135. if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
  136. dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
  137. return -1;
  138. }
  139. udelay(1000);
  140. return 0;
  141. }
  142. EXPORT_SYMBOL(dst_pio_enable);
  143. int dst_pio_disable(struct dst_state *state)
  144. {
  145. if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) {
  146. dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
  147. return -1;
  148. }
  149. if (state->type_flags & DST_TYPE_HAS_FW_1)
  150. udelay(1000);
  151. return 0;
  152. }
  153. EXPORT_SYMBOL(dst_pio_disable);
  154. int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
  155. {
  156. u8 reply;
  157. int i;
  158. for (i = 0; i < 200; i++) {
  159. if (dst_gpio_inb(state, &reply) < 0) {
  160. dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb ERROR !");
  161. return -1;
  162. }
  163. if ((reply & RDC_8820_PIO_0_ENABLE) == 0) {
  164. dprintk(verbose, DST_INFO, 1, "dst wait ready after %d", i);
  165. return 1;
  166. }
  167. msleep(10);
  168. }
  169. dprintk(verbose, DST_NOTICE, 1, "dst wait NOT ready after %d", i);
  170. return 0;
  171. }
  172. EXPORT_SYMBOL(dst_wait_dst_ready);
  173. int dst_error_recovery(struct dst_state *state)
  174. {
  175. dprintk(verbose, DST_NOTICE, 1, "Trying to return from previous errors.");
  176. dst_pio_disable(state);
  177. msleep(10);
  178. dst_pio_enable(state);
  179. msleep(10);
  180. return 0;
  181. }
  182. EXPORT_SYMBOL(dst_error_recovery);
  183. int dst_error_bailout(struct dst_state *state)
  184. {
  185. dprintk(verbose, DST_INFO, 1, "Trying to bailout from previous error.");
  186. rdc_8820_reset(state);
  187. dst_pio_disable(state);
  188. msleep(10);
  189. return 0;
  190. }
  191. EXPORT_SYMBOL(dst_error_bailout);
  192. int dst_comm_init(struct dst_state *state)
  193. {
  194. dprintk(verbose, DST_INFO, 1, "Initializing DST.");
  195. if ((dst_pio_enable(state)) < 0) {
  196. dprintk(verbose, DST_ERROR, 1, "PIO Enable Failed");
  197. return -1;
  198. }
  199. if ((rdc_reset_state(state)) < 0) {
  200. dprintk(verbose, DST_ERROR, 1, "RDC 8820 State RESET Failed.");
  201. return -1;
  202. }
  203. if (state->type_flags & DST_TYPE_HAS_FW_1)
  204. msleep(100);
  205. else
  206. msleep(5);
  207. return 0;
  208. }
  209. EXPORT_SYMBOL(dst_comm_init);
  210. int write_dst(struct dst_state *state, u8 *data, u8 len)
  211. {
  212. struct i2c_msg msg = {
  213. .addr = state->config->demod_address,
  214. .flags = 0,
  215. .buf = data,
  216. .len = len
  217. };
  218. int err;
  219. u8 cnt, i;
  220. dprintk(verbose, DST_NOTICE, 0, "writing [ ");
  221. for (i = 0; i < len; i++)
  222. dprintk(verbose, DST_NOTICE, 0, "%02x ", data[i]);
  223. dprintk(verbose, DST_NOTICE, 0, "]\n");
  224. for (cnt = 0; cnt < 2; cnt++) {
  225. if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
  226. dprintk(verbose, DST_INFO, 1, "_write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, data[0]);
  227. dst_error_recovery(state);
  228. continue;
  229. } else
  230. break;
  231. }
  232. if (cnt >= 2) {
  233. dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
  234. dst_error_bailout(state);
  235. return -1;
  236. }
  237. return 0;
  238. }
  239. EXPORT_SYMBOL(write_dst);
  240. int read_dst(struct dst_state *state, u8 *ret, u8 len)
  241. {
  242. struct i2c_msg msg = {
  243. .addr = state->config->demod_address,
  244. .flags = I2C_M_RD,
  245. .buf = ret,
  246. .len = len
  247. };
  248. int err;
  249. int cnt;
  250. for (cnt = 0; cnt < 2; cnt++) {
  251. if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
  252. dprintk(verbose, DST_INFO, 1, "read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, ret[0]);
  253. dst_error_recovery(state);
  254. continue;
  255. } else
  256. break;
  257. }
  258. if (cnt >= 2) {
  259. dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
  260. dst_error_bailout(state);
  261. return -1;
  262. }
  263. dprintk(verbose, DST_DEBUG, 1, "reply is 0x%x", ret[0]);
  264. for (err = 1; err < len; err++)
  265. dprintk(verbose, DST_DEBUG, 0, " 0x%x", ret[err]);
  266. if (err > 1)
  267. dprintk(verbose, DST_DEBUG, 0, "\n");
  268. return 0;
  269. }
  270. EXPORT_SYMBOL(read_dst);
  271. static int dst_set_polarization(struct dst_state *state)
  272. {
  273. switch (state->voltage) {
  274. case SEC_VOLTAGE_13: /* Vertical */
  275. dprintk(verbose, DST_INFO, 1, "Polarization=[Vertical]");
  276. state->tx_tuna[8] &= ~0x40;
  277. break;
  278. case SEC_VOLTAGE_18: /* Horizontal */
  279. dprintk(verbose, DST_INFO, 1, "Polarization=[Horizontal]");
  280. state->tx_tuna[8] |= 0x40;
  281. break;
  282. case SEC_VOLTAGE_OFF:
  283. break;
  284. }
  285. return 0;
  286. }
  287. static int dst_set_freq(struct dst_state *state, u32 freq)
  288. {
  289. state->frequency = freq;
  290. dprintk(verbose, DST_INFO, 1, "set Frequency %u", freq);
  291. if (state->dst_type == DST_TYPE_IS_SAT) {
  292. freq = freq / 1000;
  293. if (freq < 950 || freq > 2150)
  294. return -EINVAL;
  295. state->tx_tuna[2] = (freq >> 8);
  296. state->tx_tuna[3] = (u8) freq;
  297. state->tx_tuna[4] = 0x01;
  298. state->tx_tuna[8] &= ~0x04;
  299. if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
  300. if (freq < 1531)
  301. state->tx_tuna[8] |= 0x04;
  302. }
  303. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  304. freq = freq / 1000;
  305. if (freq < 137000 || freq > 858000)
  306. return -EINVAL;
  307. state->tx_tuna[2] = (freq >> 16) & 0xff;
  308. state->tx_tuna[3] = (freq >> 8) & 0xff;
  309. state->tx_tuna[4] = (u8) freq;
  310. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  311. freq = freq / 1000;
  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
  316. return -EINVAL;
  317. return 0;
  318. }
  319. static int dst_set_bandwidth(struct dst_state *state, fe_bandwidth_t bandwidth)
  320. {
  321. state->bandwidth = bandwidth;
  322. if (state->dst_type != DST_TYPE_IS_TERR)
  323. return 0;
  324. switch (bandwidth) {
  325. case BANDWIDTH_6_MHZ:
  326. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  327. state->tx_tuna[7] = 0x06;
  328. else {
  329. state->tx_tuna[6] = 0x06;
  330. state->tx_tuna[7] = 0x00;
  331. }
  332. break;
  333. case BANDWIDTH_7_MHZ:
  334. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  335. state->tx_tuna[7] = 0x07;
  336. else {
  337. state->tx_tuna[6] = 0x07;
  338. state->tx_tuna[7] = 0x00;
  339. }
  340. break;
  341. case BANDWIDTH_8_MHZ:
  342. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  343. state->tx_tuna[7] = 0x08;
  344. else {
  345. state->tx_tuna[6] = 0x08;
  346. state->tx_tuna[7] = 0x00;
  347. }
  348. break;
  349. default:
  350. return -EINVAL;
  351. }
  352. return 0;
  353. }
  354. static int dst_set_inversion(struct dst_state *state, fe_spectral_inversion_t inversion)
  355. {
  356. state->inversion = inversion;
  357. switch (inversion) {
  358. case INVERSION_OFF: /* Inversion = Normal */
  359. state->tx_tuna[8] &= ~0x80;
  360. break;
  361. case INVERSION_ON:
  362. state->tx_tuna[8] |= 0x80;
  363. break;
  364. default:
  365. return -EINVAL;
  366. }
  367. return 0;
  368. }
  369. static int dst_set_fec(struct dst_state *state, fe_code_rate_t fec)
  370. {
  371. state->fec = fec;
  372. return 0;
  373. }
  374. static fe_code_rate_t dst_get_fec(struct dst_state *state)
  375. {
  376. return state->fec;
  377. }
  378. static int dst_set_symbolrate(struct dst_state *state, u32 srate)
  379. {
  380. u32 symcalc;
  381. u64 sval;
  382. state->symbol_rate = srate;
  383. if (state->dst_type == DST_TYPE_IS_TERR) {
  384. return 0;
  385. }
  386. dprintk(verbose, DST_INFO, 1, "set symrate %u", srate);
  387. srate /= 1000;
  388. if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
  389. sval = srate;
  390. sval <<= 20;
  391. do_div(sval, 88000);
  392. symcalc = (u32) sval;
  393. dprintk(verbose, DST_INFO, 1, "set symcalc %u", symcalc);
  394. state->tx_tuna[5] = (u8) (symcalc >> 12);
  395. state->tx_tuna[6] = (u8) (symcalc >> 4);
  396. state->tx_tuna[7] = (u8) (symcalc << 4);
  397. } else {
  398. state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
  399. state->tx_tuna[6] = (u8) (srate >> 8);
  400. state->tx_tuna[7] = (u8) srate;
  401. }
  402. state->tx_tuna[8] &= ~0x20;
  403. if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
  404. if (srate > 8000)
  405. state->tx_tuna[8] |= 0x20;
  406. }
  407. return 0;
  408. }
  409. static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
  410. {
  411. if (state->dst_type != DST_TYPE_IS_CABLE)
  412. return 0;
  413. state->modulation = modulation;
  414. switch (modulation) {
  415. case QAM_16:
  416. state->tx_tuna[8] = 0x10;
  417. break;
  418. case QAM_32:
  419. state->tx_tuna[8] = 0x20;
  420. break;
  421. case QAM_64:
  422. state->tx_tuna[8] = 0x40;
  423. break;
  424. case QAM_128:
  425. state->tx_tuna[8] = 0x80;
  426. break;
  427. case QAM_256:
  428. state->tx_tuna[8] = 0x00;
  429. break;
  430. case QPSK:
  431. case QAM_AUTO:
  432. case VSB_8:
  433. case VSB_16:
  434. default:
  435. return -EINVAL;
  436. }
  437. return 0;
  438. }
  439. static fe_modulation_t dst_get_modulation(struct dst_state *state)
  440. {
  441. return state->modulation;
  442. }
  443. u8 dst_check_sum(u8 *buf, u32 len)
  444. {
  445. u32 i;
  446. u8 val = 0;
  447. if (!len)
  448. return 0;
  449. for (i = 0; i < len; i++) {
  450. val += buf[i];
  451. }
  452. return ((~val) + 1);
  453. }
  454. EXPORT_SYMBOL(dst_check_sum);
  455. static void dst_type_flags_print(u32 type_flags)
  456. {
  457. dprintk(verbose, DST_ERROR, 0, "DST type flags :");
  458. if (type_flags & DST_TYPE_HAS_NEWTUNE)
  459. dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner", DST_TYPE_HAS_NEWTUNE);
  460. if (type_flags & DST_TYPE_HAS_TS204)
  461. dprintk(verbose, DST_ERROR, 0, " 0x%x ts204", DST_TYPE_HAS_TS204);
  462. if (type_flags & DST_TYPE_HAS_SYMDIV)
  463. dprintk(verbose, DST_ERROR, 0, " 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
  464. if (type_flags & DST_TYPE_HAS_FW_1)
  465. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
  466. if (type_flags & DST_TYPE_HAS_FW_2)
  467. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
  468. if (type_flags & DST_TYPE_HAS_FW_3)
  469. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
  470. dprintk(verbose, DST_ERROR, 0, "\n");
  471. }
  472. static int dst_type_print(u8 type)
  473. {
  474. char *otype;
  475. switch (type) {
  476. case DST_TYPE_IS_SAT:
  477. otype = "satellite";
  478. break;
  479. case DST_TYPE_IS_TERR:
  480. otype = "terrestrial";
  481. break;
  482. case DST_TYPE_IS_CABLE:
  483. otype = "cable";
  484. break;
  485. default:
  486. dprintk(verbose, DST_INFO, 1, "invalid dst type %d", type);
  487. return -EINVAL;
  488. }
  489. dprintk(verbose, DST_INFO, 1, "DST type: %s", otype);
  490. return 0;
  491. }
  492. /*
  493. Known cards list
  494. Satellite
  495. -------------------
  496. 200103A
  497. VP-1020 DST-MOT LG(old), TS=188
  498. VP-1020 DST-03T LG(new), TS=204
  499. VP-1022 DST-03T LG(new), TS=204
  500. VP-1025 DST-03T LG(new), TS=204
  501. VP-1030 DSTMCI, LG(new), TS=188
  502. VP-1032 DSTMCI, LG(new), TS=188
  503. Cable
  504. -------------------
  505. VP-2030 DCT-CI, Samsung, TS=204
  506. VP-2021 DCT-CI, Unknown, TS=204
  507. VP-2031 DCT-CI, Philips, TS=188
  508. VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
  509. VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
  510. Terrestrial
  511. -------------------
  512. VP-3050 DTTNXT TS=188
  513. VP-3040 DTT-CI, Philips, TS=188
  514. VP-3040 DTT-CI, Philips, TS=204
  515. ATSC
  516. -------------------
  517. VP-3220 ATSCDI, TS=188
  518. VP-3250 ATSCAD, TS=188
  519. */
  520. struct dst_types dst_tlist[] = {
  521. {
  522. .device_id = "200103A",
  523. .offset = 0,
  524. .dst_type = DST_TYPE_IS_SAT,
  525. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
  526. .dst_feature = 0
  527. }, /* obsolete */
  528. {
  529. .device_id = "DST-020",
  530. .offset = 0,
  531. .dst_type = DST_TYPE_IS_SAT,
  532. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
  533. .dst_feature = 0
  534. }, /* obsolete */
  535. {
  536. .device_id = "DST-030",
  537. .offset = 0,
  538. .dst_type = DST_TYPE_IS_SAT,
  539. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  540. .dst_feature = 0
  541. }, /* obsolete */
  542. {
  543. .device_id = "DST-03T",
  544. .offset = 0,
  545. .dst_type = DST_TYPE_IS_SAT,
  546. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
  547. .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
  548. | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO
  549. },
  550. {
  551. .device_id = "DST-MOT",
  552. .offset = 0,
  553. .dst_type = DST_TYPE_IS_SAT,
  554. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
  555. .dst_feature = 0
  556. }, /* obsolete */
  557. {
  558. .device_id = "DST-CI",
  559. .offset = 1,
  560. .dst_type = DST_TYPE_IS_SAT,
  561. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  562. .dst_feature = DST_TYPE_HAS_CA
  563. }, /* An OEM board */
  564. {
  565. .device_id = "DSTMCI",
  566. .offset = 1,
  567. .dst_type = DST_TYPE_IS_SAT,
  568. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
  569. .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
  570. | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
  571. },
  572. {
  573. .device_id = "DSTFCI",
  574. .offset = 1,
  575. .dst_type = DST_TYPE_IS_SAT,
  576. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  577. .dst_feature = 0
  578. }, /* unknown to vendor */
  579. {
  580. .device_id = "DCT-CI",
  581. .offset = 1,
  582. .dst_type = DST_TYPE_IS_CABLE,
  583. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1
  584. | DST_TYPE_HAS_FW_2,
  585. .dst_feature = DST_TYPE_HAS_CA
  586. },
  587. {
  588. .device_id = "DCTNEW",
  589. .offset = 1,
  590. .dst_type = DST_TYPE_IS_CABLE,
  591. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD,
  592. .dst_feature = 0
  593. },
  594. {
  595. .device_id = "DTT-CI",
  596. .offset = 1,
  597. .dst_type = DST_TYPE_IS_TERR,
  598. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE,
  599. .dst_feature = DST_TYPE_HAS_CA
  600. },
  601. {
  602. .device_id = "DTTDIG",
  603. .offset = 1,
  604. .dst_type = DST_TYPE_IS_TERR,
  605. .type_flags = DST_TYPE_HAS_FW_2,
  606. .dst_feature = 0
  607. },
  608. {
  609. .device_id = "DTTNXT",
  610. .offset = 1,
  611. .dst_type = DST_TYPE_IS_TERR,
  612. .type_flags = DST_TYPE_HAS_FW_2,
  613. .dst_feature = DST_TYPE_HAS_ANALOG
  614. },
  615. {
  616. .device_id = "ATSCDI",
  617. .offset = 1,
  618. .dst_type = DST_TYPE_IS_ATSC,
  619. .type_flags = DST_TYPE_HAS_FW_2,
  620. .dst_feature = 0
  621. },
  622. {
  623. .device_id = "ATSCAD",
  624. .offset = 1,
  625. .dst_type = DST_TYPE_IS_ATSC,
  626. .type_flags = DST_TYPE_HAS_FW_2,
  627. .dst_feature = 0
  628. },
  629. { }
  630. };
  631. static int dst_get_mac(struct dst_state *state)
  632. {
  633. u8 get_mac[] = { 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  634. get_mac[7] = dst_check_sum(get_mac, 7);
  635. if (dst_command(state, get_mac, 8) < 0) {
  636. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  637. return -1;
  638. }
  639. memset(&state->mac_address, '\0', 8);
  640. memcpy(&state->mac_address, &state->rxbuffer, 6);
  641. dprintk(verbose, DST_ERROR, 1, "MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]",
  642. state->mac_address[0], state->mac_address[1], state->mac_address[2],
  643. state->mac_address[4], state->mac_address[5], state->mac_address[6]);
  644. return 0;
  645. }
  646. static int dst_fw_ver(struct dst_state *state)
  647. {
  648. u8 get_ver[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  649. get_ver[7] = dst_check_sum(get_ver, 7);
  650. if (dst_command(state, get_ver, 8) < 0) {
  651. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  652. return -1;
  653. }
  654. memset(&state->fw_version, '\0', 8);
  655. memcpy(&state->fw_version, &state->rxbuffer, 8);
  656. dprintk(verbose, DST_ERROR, 1, "Firmware Ver = %x.%x Build = %02x, on %x:%x, %x-%x-20%02x",
  657. state->fw_version[0] >> 4, state->fw_version[0] & 0x0f,
  658. state->fw_version[1],
  659. state->fw_version[5], state->fw_version[6],
  660. state->fw_version[4], state->fw_version[3], state->fw_version[2]);
  661. return 0;
  662. }
  663. static int dst_card_type(struct dst_state *state)
  664. {
  665. u8 get_type[] = { 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  666. get_type[7] = dst_check_sum(get_type, 7);
  667. if (dst_command(state, get_type, 8) < 0) {
  668. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  669. return -1;
  670. }
  671. memset(&state->card_info, '\0', 8);
  672. memcpy(&state->card_info, &state->rxbuffer, 8);
  673. dprintk(verbose, DST_ERROR, 1, "Device Model=[%s]", &state->card_info[0]);
  674. return 0;
  675. }
  676. static int dst_get_vendor(struct dst_state *state)
  677. {
  678. u8 get_vendor[] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  679. get_vendor[7] = dst_check_sum(get_vendor, 7);
  680. if (dst_command(state, get_vendor, 8) < 0) {
  681. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  682. return -1;
  683. }
  684. memset(&state->vendor, '\0', 8);
  685. memcpy(&state->vendor, &state->rxbuffer, 8);
  686. dprintk(verbose, DST_ERROR, 1, "Vendor=[%s]", &state->vendor[0]);
  687. return 0;
  688. }
  689. static int dst_get_tuner_info(struct dst_state *state)
  690. {
  691. u8 get_tuner_1[] = { 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  692. u8 get_tuner_2[] = { 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  693. get_tuner_1[7] = dst_check_sum(get_tuner_1, 7);
  694. get_tuner_2[7] = dst_check_sum(get_tuner_2, 7);
  695. if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
  696. if (dst_command(state, get_tuner_2, 8) < 0) {
  697. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  698. return -1;
  699. }
  700. } else {
  701. if (dst_command(state, get_tuner_1, 8) < 0) {
  702. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  703. return -1;
  704. }
  705. }
  706. memset(&state->board_info, '\0', 8);
  707. memcpy(&state->board_info, &state->rxbuffer, 8);
  708. if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
  709. if (state->board_info[1] == 0x0b) {
  710. if (state->type_flags & DST_TYPE_HAS_TS204)
  711. state->type_flags &= ~DST_TYPE_HAS_TS204;
  712. state->type_flags |= DST_TYPE_HAS_NEWTUNE;
  713. dprintk(verbose, DST_INFO, 1, "DST type has TS=188");
  714. } else {
  715. if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
  716. state->type_flags &= ~DST_TYPE_HAS_NEWTUNE;
  717. state->type_flags |= DST_TYPE_HAS_TS204;
  718. dprintk(verbose, DST_INFO, 1, "DST type has TS=204");
  719. }
  720. } else {
  721. if (state->board_info[0] == 0xbc) {
  722. if (state->type_flags & DST_TYPE_HAS_TS204)
  723. state->type_flags &= ~DST_TYPE_HAS_TS204;
  724. state->type_flags |= DST_TYPE_HAS_NEWTUNE;
  725. dprintk(verbose, DST_INFO, 1, "DST type has TS=188, Daughterboard=[%d]", state->board_info[1]);
  726. } else if (state->board_info[0] == 0xcc) {
  727. if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
  728. state->type_flags &= ~DST_TYPE_HAS_NEWTUNE;
  729. state->type_flags |= DST_TYPE_HAS_TS204;
  730. dprintk(verbose, DST_INFO, 1, "DST type has TS=204 Daughterboard=[%d]", state->board_info[1]);
  731. }
  732. }
  733. return 0;
  734. }
  735. static int dst_get_device_id(struct dst_state *state)
  736. {
  737. u8 reply;
  738. int i;
  739. struct dst_types *p_dst_type;
  740. u8 use_dst_type = 0;
  741. u32 use_type_flags = 0;
  742. static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
  743. device_type[7] = dst_check_sum(device_type, 7);
  744. if (write_dst(state, device_type, FIXED_COMM))
  745. return -1; /* Write failed */
  746. if ((dst_pio_disable(state)) < 0)
  747. return -1;
  748. if (read_dst(state, &reply, GET_ACK))
  749. return -1; /* Read failure */
  750. if (reply != ACK) {
  751. dprintk(verbose, DST_INFO, 1, "Write not Acknowledged! [Reply=0x%02x]", reply);
  752. return -1; /* Unack'd write */
  753. }
  754. if (!dst_wait_dst_ready(state, DEVICE_INIT))
  755. return -1; /* DST not ready yet */
  756. if (read_dst(state, state->rxbuffer, FIXED_COMM))
  757. return -1;
  758. dst_pio_disable(state);
  759. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  760. dprintk(verbose, DST_INFO, 1, "Checksum failure!");
  761. return -1; /* Checksum failure */
  762. }
  763. state->rxbuffer[7] = '\0';
  764. for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
  765. if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
  766. use_type_flags = p_dst_type->type_flags;
  767. use_dst_type = p_dst_type->dst_type;
  768. /* Card capabilities */
  769. state->dst_hw_cap = p_dst_type->dst_feature;
  770. dprintk(verbose, DST_ERROR, 1, "Recognise [%s]\n", p_dst_type->device_id);
  771. break;
  772. }
  773. }
  774. if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
  775. dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
  776. dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
  777. use_dst_type = DST_TYPE_IS_SAT;
  778. use_type_flags = DST_TYPE_HAS_SYMDIV;
  779. }
  780. dst_type_print(use_dst_type);
  781. state->type_flags = use_type_flags;
  782. state->dst_type = use_dst_type;
  783. dst_type_flags_print(state->type_flags);
  784. if (state->type_flags & DST_TYPE_HAS_TS204) {
  785. dst_packsize(state, 204);
  786. }
  787. return 0;
  788. }
  789. static int dst_probe(struct dst_state *state)
  790. {
  791. if ((rdc_8820_reset(state)) < 0) {
  792. dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
  793. return -1;
  794. }
  795. if (dst_addons & DST_TYPE_HAS_CA)
  796. msleep(4000);
  797. else
  798. msleep(100);
  799. if ((dst_comm_init(state)) < 0) {
  800. dprintk(verbose, DST_ERROR, 1, "DST Initialization Failed.");
  801. return -1;
  802. }
  803. msleep(100);
  804. if (dst_get_device_id(state) < 0) {
  805. dprintk(verbose, DST_ERROR, 1, "unknown device.");
  806. return -1;
  807. }
  808. if (dst_get_mac(state) < 0) {
  809. dprintk(verbose, DST_INFO, 1, "MAC: Unsupported command");
  810. return 0;
  811. }
  812. if ((state->type_flags & DST_TYPE_HAS_MULTI_FE) || (state->type_flags & DST_TYPE_HAS_FW_BUILD)) {
  813. if (dst_get_tuner_info(state) < 0)
  814. dprintk(verbose, DST_INFO, 1, "Tuner: Unsupported command");
  815. }
  816. if (state->type_flags & DST_TYPE_HAS_FW_BUILD) {
  817. if (dst_fw_ver(state) < 0) {
  818. dprintk(verbose, DST_INFO, 1, "FW: Unsupported command");
  819. return 0;
  820. }
  821. if (dst_card_type(state) < 0) {
  822. dprintk(verbose, DST_INFO, 1, "Card: Unsupported command");
  823. return 0;
  824. }
  825. if (dst_get_vendor(state) < 0) {
  826. dprintk(verbose, DST_INFO, 1, "Vendor: Unsupported command");
  827. return 0;
  828. }
  829. }
  830. return 0;
  831. }
  832. int dst_command(struct dst_state *state, u8 *data, u8 len)
  833. {
  834. u8 reply;
  835. if ((dst_comm_init(state)) < 0) {
  836. dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
  837. return -1;
  838. }
  839. if (write_dst(state, data, len)) {
  840. dprintk(verbose, DST_INFO, 1, "Tring to recover.. ");
  841. if ((dst_error_recovery(state)) < 0) {
  842. dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
  843. return -1;
  844. }
  845. return -1;
  846. }
  847. if ((dst_pio_disable(state)) < 0) {
  848. dprintk(verbose, DST_ERROR, 1, "PIO Disable Failed.");
  849. return -1;
  850. }
  851. if (state->type_flags & DST_TYPE_HAS_FW_1)
  852. udelay(3000);
  853. if (read_dst(state, &reply, GET_ACK)) {
  854. dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
  855. if ((dst_error_recovery(state)) < 0) {
  856. dprintk(verbose, DST_INFO, 1, "Recovery Failed.");
  857. return -1;
  858. }
  859. return -1;
  860. }
  861. if (reply != ACK) {
  862. dprintk(verbose, DST_INFO, 1, "write not acknowledged 0x%02x ", reply);
  863. return -1;
  864. }
  865. if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
  866. return 0;
  867. if (state->type_flags & DST_TYPE_HAS_FW_1)
  868. udelay(3000);
  869. else
  870. udelay(2000);
  871. if (!dst_wait_dst_ready(state, NO_DELAY))
  872. return -1;
  873. if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
  874. dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
  875. if ((dst_error_recovery(state)) < 0) {
  876. dprintk(verbose, DST_INFO, 1, "Recovery failed.");
  877. return -1;
  878. }
  879. return -1;
  880. }
  881. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  882. dprintk(verbose, DST_INFO, 1, "checksum failure");
  883. return -1;
  884. }
  885. return 0;
  886. }
  887. EXPORT_SYMBOL(dst_command);
  888. static int dst_get_signal(struct dst_state *state)
  889. {
  890. int retval;
  891. u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
  892. //dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
  893. if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
  894. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  895. return 0;
  896. }
  897. if (0 == (state->diseq_flags & HAS_LOCK)) {
  898. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  899. return 0;
  900. }
  901. if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
  902. retval = dst_command(state, get_signal, 8);
  903. if (retval < 0)
  904. return retval;
  905. if (state->dst_type == DST_TYPE_IS_SAT) {
  906. state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
  907. state->decode_strength = state->rxbuffer[5] << 8;
  908. state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
  909. } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
  910. state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
  911. state->decode_strength = state->rxbuffer[4] << 8;
  912. state->decode_snr = state->rxbuffer[3] << 8;
  913. }
  914. state->cur_jiff = jiffies;
  915. }
  916. return 0;
  917. }
  918. static int dst_tone_power_cmd(struct dst_state *state)
  919. {
  920. u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
  921. if (state->dst_type == DST_TYPE_IS_TERR)
  922. return 0;
  923. paket[4] = state->tx_tuna[4];
  924. paket[2] = state->tx_tuna[2];
  925. paket[3] = state->tx_tuna[3];
  926. paket[7] = dst_check_sum (paket, 7);
  927. dst_command(state, paket, 8);
  928. return 0;
  929. }
  930. static int dst_get_tuna(struct dst_state *state)
  931. {
  932. int retval;
  933. if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
  934. return 0;
  935. state->diseq_flags &= ~(HAS_LOCK);
  936. if (!dst_wait_dst_ready(state, NO_DELAY))
  937. return 0;
  938. if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
  939. /* how to get variable length reply ???? */
  940. retval = read_dst(state, state->rx_tuna, 10);
  941. else
  942. retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
  943. if (retval < 0) {
  944. dprintk(verbose, DST_DEBUG, 1, "read not successful");
  945. return 0;
  946. }
  947. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  948. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
  949. dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
  950. return 0;
  951. }
  952. } else {
  953. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
  954. dprintk(verbose, DST_INFO, 1, "checksum failure? ");
  955. return 0;
  956. }
  957. }
  958. if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
  959. return 0;
  960. state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
  961. state->decode_lock = 1;
  962. state->diseq_flags |= HAS_LOCK;
  963. return 1;
  964. }
  965. static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
  966. static int dst_write_tuna(struct dvb_frontend *fe)
  967. {
  968. struct dst_state *state = fe->demodulator_priv;
  969. int retval;
  970. u8 reply;
  971. dprintk(verbose, DST_INFO, 1, "type_flags 0x%x ", state->type_flags);
  972. state->decode_freq = 0;
  973. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  974. if (state->dst_type == DST_TYPE_IS_SAT) {
  975. if (!(state->diseq_flags & HAS_POWER))
  976. dst_set_voltage(fe, SEC_VOLTAGE_13);
  977. }
  978. state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
  979. if ((dst_comm_init(state)) < 0) {
  980. dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
  981. return -1;
  982. }
  983. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  984. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
  985. retval = write_dst(state, &state->tx_tuna[0], 10);
  986. } else {
  987. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
  988. retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
  989. }
  990. if (retval < 0) {
  991. dst_pio_disable(state);
  992. dprintk(verbose, DST_DEBUG, 1, "write not successful");
  993. return retval;
  994. }
  995. if ((dst_pio_disable(state)) < 0) {
  996. dprintk(verbose, DST_DEBUG, 1, "DST PIO disable failed !");
  997. return -1;
  998. }
  999. if ((read_dst(state, &reply, GET_ACK) < 0)) {
  1000. dprintk(verbose, DST_DEBUG, 1, "read verify not successful.");
  1001. return -1;
  1002. }
  1003. if (reply != ACK) {
  1004. dprintk(verbose, DST_DEBUG, 1, "write not acknowledged 0x%02x ", reply);
  1005. return 0;
  1006. }
  1007. state->diseq_flags |= ATTEMPT_TUNE;
  1008. return dst_get_tuna(state);
  1009. }
  1010. /*
  1011. * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
  1012. * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
  1013. * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
  1014. * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
  1015. * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
  1016. * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
  1017. * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
  1018. * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
  1019. * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
  1020. * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
  1021. * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
  1022. */
  1023. static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
  1024. {
  1025. struct dst_state *state = fe->demodulator_priv;
  1026. u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
  1027. if (state->dst_type != DST_TYPE_IS_SAT)
  1028. return 0;
  1029. if (cmd->msg_len == 0 || cmd->msg_len > 4)
  1030. return -EINVAL;
  1031. memcpy(&paket[3], cmd->msg, cmd->msg_len);
  1032. paket[7] = dst_check_sum(&paket[0], 7);
  1033. dst_command(state, paket, 8);
  1034. return 0;
  1035. }
  1036. static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  1037. {
  1038. int need_cmd;
  1039. struct dst_state *state = fe->demodulator_priv;
  1040. state->voltage = voltage;
  1041. if (state->dst_type != DST_TYPE_IS_SAT)
  1042. return 0;
  1043. need_cmd = 0;
  1044. switch (voltage) {
  1045. case SEC_VOLTAGE_13:
  1046. case SEC_VOLTAGE_18:
  1047. if ((state->diseq_flags & HAS_POWER) == 0)
  1048. need_cmd = 1;
  1049. state->diseq_flags |= HAS_POWER;
  1050. state->tx_tuna[4] = 0x01;
  1051. break;
  1052. case SEC_VOLTAGE_OFF:
  1053. need_cmd = 1;
  1054. state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
  1055. state->tx_tuna[4] = 0x00;
  1056. break;
  1057. default:
  1058. return -EINVAL;
  1059. }
  1060. if (need_cmd)
  1061. dst_tone_power_cmd(state);
  1062. return 0;
  1063. }
  1064. static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
  1065. {
  1066. struct dst_state *state = fe->demodulator_priv;
  1067. state->tone = tone;
  1068. if (state->dst_type != DST_TYPE_IS_SAT)
  1069. return 0;
  1070. switch (tone) {
  1071. case SEC_TONE_OFF:
  1072. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1073. state->tx_tuna[2] = 0x00;
  1074. else
  1075. state->tx_tuna[2] = 0xff;
  1076. break;
  1077. case SEC_TONE_ON:
  1078. state->tx_tuna[2] = 0x02;
  1079. break;
  1080. default:
  1081. return -EINVAL;
  1082. }
  1083. dst_tone_power_cmd(state);
  1084. return 0;
  1085. }
  1086. static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
  1087. {
  1088. struct dst_state *state = fe->demodulator_priv;
  1089. if (state->dst_type != DST_TYPE_IS_SAT)
  1090. return 0;
  1091. state->minicmd = minicmd;
  1092. switch (minicmd) {
  1093. case SEC_MINI_A:
  1094. state->tx_tuna[3] = 0x02;
  1095. break;
  1096. case SEC_MINI_B:
  1097. state->tx_tuna[3] = 0xff;
  1098. break;
  1099. }
  1100. dst_tone_power_cmd(state);
  1101. return 0;
  1102. }
  1103. static int dst_init(struct dvb_frontend *fe)
  1104. {
  1105. struct dst_state *state = fe->demodulator_priv;
  1106. static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
  1107. static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
  1108. static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1109. static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1110. static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1111. static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1112. state->inversion = INVERSION_OFF;
  1113. state->voltage = SEC_VOLTAGE_13;
  1114. state->tone = SEC_TONE_OFF;
  1115. state->diseq_flags = 0;
  1116. state->k22 = 0x02;
  1117. state->bandwidth = BANDWIDTH_7_MHZ;
  1118. state->cur_jiff = jiffies;
  1119. if (state->dst_type == DST_TYPE_IS_SAT)
  1120. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
  1121. else if (state->dst_type == DST_TYPE_IS_TERR)
  1122. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
  1123. else if (state->dst_type == DST_TYPE_IS_CABLE)
  1124. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
  1125. return 0;
  1126. }
  1127. static int dst_read_status(struct dvb_frontend *fe, fe_status_t *status)
  1128. {
  1129. struct dst_state *state = fe->demodulator_priv;
  1130. *status = 0;
  1131. if (state->diseq_flags & HAS_LOCK) {
  1132. // dst_get_signal(state); // don't require(?) to ask MCU
  1133. if (state->decode_lock)
  1134. *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
  1135. }
  1136. return 0;
  1137. }
  1138. static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  1139. {
  1140. struct dst_state *state = fe->demodulator_priv;
  1141. dst_get_signal(state);
  1142. *strength = state->decode_strength;
  1143. return 0;
  1144. }
  1145. static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
  1146. {
  1147. struct dst_state *state = fe->demodulator_priv;
  1148. dst_get_signal(state);
  1149. *snr = state->decode_snr;
  1150. return 0;
  1151. }
  1152. static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1153. {
  1154. struct dst_state *state = fe->demodulator_priv;
  1155. dst_set_freq(state, p->frequency);
  1156. dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
  1157. if (state->dst_type == DST_TYPE_IS_SAT) {
  1158. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1159. dst_set_inversion(state, p->inversion);
  1160. dst_set_fec(state, p->u.qpsk.fec_inner);
  1161. dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
  1162. dst_set_polarization(state);
  1163. dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);
  1164. } else if (state->dst_type == DST_TYPE_IS_TERR)
  1165. dst_set_bandwidth(state, p->u.ofdm.bandwidth);
  1166. else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1167. dst_set_fec(state, p->u.qam.fec_inner);
  1168. dst_set_symbolrate(state, p->u.qam.symbol_rate);
  1169. dst_set_modulation(state, p->u.qam.modulation);
  1170. }
  1171. dst_write_tuna(fe);
  1172. return 0;
  1173. }
  1174. static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1175. {
  1176. struct dst_state *state = fe->demodulator_priv;
  1177. p->frequency = state->decode_freq;
  1178. if (state->dst_type == DST_TYPE_IS_SAT) {
  1179. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1180. p->inversion = state->inversion;
  1181. p->u.qpsk.symbol_rate = state->symbol_rate;
  1182. p->u.qpsk.fec_inner = dst_get_fec(state);
  1183. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  1184. p->u.ofdm.bandwidth = state->bandwidth;
  1185. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1186. p->u.qam.symbol_rate = state->symbol_rate;
  1187. p->u.qam.fec_inner = dst_get_fec(state);
  1188. p->u.qam.modulation = dst_get_modulation(state);
  1189. }
  1190. return 0;
  1191. }
  1192. static void dst_release(struct dvb_frontend *fe)
  1193. {
  1194. struct dst_state *state = fe->demodulator_priv;
  1195. kfree(state);
  1196. }
  1197. static struct dvb_frontend_ops dst_dvbt_ops;
  1198. static struct dvb_frontend_ops dst_dvbs_ops;
  1199. static struct dvb_frontend_ops dst_dvbc_ops;
  1200. struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
  1201. {
  1202. /* check if the ASIC is there */
  1203. if (dst_probe(state) < 0) {
  1204. kfree(state);
  1205. return NULL;
  1206. }
  1207. /* determine settings based on type */
  1208. switch (state->dst_type) {
  1209. case DST_TYPE_IS_TERR:
  1210. memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
  1211. break;
  1212. case DST_TYPE_IS_CABLE:
  1213. memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
  1214. break;
  1215. case DST_TYPE_IS_SAT:
  1216. memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
  1217. break;
  1218. default:
  1219. dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
  1220. kfree(state);
  1221. return NULL;
  1222. }
  1223. /* create dvb_frontend */
  1224. state->frontend.ops = &state->ops;
  1225. state->frontend.demodulator_priv = state;
  1226. return state; /* Manu (DST is a card not a frontend) */
  1227. }
  1228. EXPORT_SYMBOL(dst_attach);
  1229. static struct dvb_frontend_ops dst_dvbt_ops = {
  1230. .info = {
  1231. .name = "DST DVB-T",
  1232. .type = FE_OFDM,
  1233. .frequency_min = 137000000,
  1234. .frequency_max = 858000000,
  1235. .frequency_stepsize = 166667,
  1236. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
  1237. },
  1238. .release = dst_release,
  1239. .init = dst_init,
  1240. .set_frontend = dst_set_frontend,
  1241. .get_frontend = dst_get_frontend,
  1242. .read_status = dst_read_status,
  1243. .read_signal_strength = dst_read_signal_strength,
  1244. .read_snr = dst_read_snr,
  1245. };
  1246. static struct dvb_frontend_ops dst_dvbs_ops = {
  1247. .info = {
  1248. .name = "DST DVB-S",
  1249. .type = FE_QPSK,
  1250. .frequency_min = 950000,
  1251. .frequency_max = 2150000,
  1252. .frequency_stepsize = 1000, /* kHz for QPSK frontends */
  1253. .frequency_tolerance = 29500,
  1254. .symbol_rate_min = 1000000,
  1255. .symbol_rate_max = 45000000,
  1256. /* . symbol_rate_tolerance = ???,*/
  1257. .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
  1258. },
  1259. .release = dst_release,
  1260. .init = dst_init,
  1261. .set_frontend = dst_set_frontend,
  1262. .get_frontend = dst_get_frontend,
  1263. .read_status = dst_read_status,
  1264. .read_signal_strength = dst_read_signal_strength,
  1265. .read_snr = dst_read_snr,
  1266. .diseqc_send_burst = dst_send_burst,
  1267. .diseqc_send_master_cmd = dst_set_diseqc,
  1268. .set_voltage = dst_set_voltage,
  1269. .set_tone = dst_set_tone,
  1270. };
  1271. static struct dvb_frontend_ops dst_dvbc_ops = {
  1272. .info = {
  1273. .name = "DST DVB-C",
  1274. .type = FE_QAM,
  1275. .frequency_stepsize = 62500,
  1276. .frequency_min = 51000000,
  1277. .frequency_max = 858000000,
  1278. .symbol_rate_min = 1000000,
  1279. .symbol_rate_max = 45000000,
  1280. /* . symbol_rate_tolerance = ???,*/
  1281. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO
  1282. },
  1283. .release = dst_release,
  1284. .init = dst_init,
  1285. .set_frontend = dst_set_frontend,
  1286. .get_frontend = dst_get_frontend,
  1287. .read_status = dst_read_status,
  1288. .read_signal_strength = dst_read_signal_strength,
  1289. .read_snr = dst_read_snr,
  1290. };
  1291. MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
  1292. MODULE_AUTHOR("Jamie Honan, Manu Abraham");
  1293. MODULE_LICENSE("GPL");