dst.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  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. state->tx_tuna[2] = (freq >> 16) & 0xff;
  312. state->tx_tuna[3] = (freq >> 8) & 0xff;
  313. state->tx_tuna[4] = (u8) freq;
  314. } else
  315. return -EINVAL;
  316. return 0;
  317. }
  318. static int dst_set_bandwidth(struct dst_state *state, fe_bandwidth_t bandwidth)
  319. {
  320. state->bandwidth = bandwidth;
  321. if (state->dst_type != DST_TYPE_IS_TERR)
  322. return 0;
  323. switch (bandwidth) {
  324. case BANDWIDTH_6_MHZ:
  325. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  326. state->tx_tuna[7] = 0x06;
  327. else {
  328. state->tx_tuna[6] = 0x06;
  329. state->tx_tuna[7] = 0x00;
  330. }
  331. break;
  332. case BANDWIDTH_7_MHZ:
  333. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  334. state->tx_tuna[7] = 0x07;
  335. else {
  336. state->tx_tuna[6] = 0x07;
  337. state->tx_tuna[7] = 0x00;
  338. }
  339. break;
  340. case BANDWIDTH_8_MHZ:
  341. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  342. state->tx_tuna[7] = 0x08;
  343. else {
  344. state->tx_tuna[6] = 0x08;
  345. state->tx_tuna[7] = 0x00;
  346. }
  347. break;
  348. default:
  349. return -EINVAL;
  350. }
  351. return 0;
  352. }
  353. static int dst_set_inversion(struct dst_state *state, fe_spectral_inversion_t inversion)
  354. {
  355. state->inversion = inversion;
  356. switch (inversion) {
  357. case INVERSION_OFF: /* Inversion = Normal */
  358. state->tx_tuna[8] &= ~0x80;
  359. break;
  360. case INVERSION_ON:
  361. state->tx_tuna[8] |= 0x80;
  362. break;
  363. default:
  364. return -EINVAL;
  365. }
  366. return 0;
  367. }
  368. static int dst_set_fec(struct dst_state *state, fe_code_rate_t fec)
  369. {
  370. state->fec = fec;
  371. return 0;
  372. }
  373. static fe_code_rate_t dst_get_fec(struct dst_state *state)
  374. {
  375. return state->fec;
  376. }
  377. static int dst_set_symbolrate(struct dst_state *state, u32 srate)
  378. {
  379. u32 symcalc;
  380. u64 sval;
  381. state->symbol_rate = srate;
  382. if (state->dst_type == DST_TYPE_IS_TERR) {
  383. return 0;
  384. }
  385. dprintk(verbose, DST_INFO, 1, "set symrate %u", srate);
  386. srate /= 1000;
  387. if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
  388. sval = srate;
  389. sval <<= 20;
  390. do_div(sval, 88000);
  391. symcalc = (u32) sval;
  392. dprintk(verbose, DST_INFO, 1, "set symcalc %u", symcalc);
  393. state->tx_tuna[5] = (u8) (symcalc >> 12);
  394. state->tx_tuna[6] = (u8) (symcalc >> 4);
  395. state->tx_tuna[7] = (u8) (symcalc << 4);
  396. } else {
  397. state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
  398. state->tx_tuna[6] = (u8) (srate >> 8);
  399. state->tx_tuna[7] = (u8) srate;
  400. }
  401. state->tx_tuna[8] &= ~0x20;
  402. if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
  403. if (srate > 8000)
  404. state->tx_tuna[8] |= 0x20;
  405. }
  406. return 0;
  407. }
  408. static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
  409. {
  410. if (state->dst_type != DST_TYPE_IS_CABLE)
  411. return 0;
  412. state->modulation = modulation;
  413. switch (modulation) {
  414. case QAM_16:
  415. state->tx_tuna[8] = 0x10;
  416. break;
  417. case QAM_32:
  418. state->tx_tuna[8] = 0x20;
  419. break;
  420. case QAM_64:
  421. state->tx_tuna[8] = 0x40;
  422. break;
  423. case QAM_128:
  424. state->tx_tuna[8] = 0x80;
  425. break;
  426. case QAM_256:
  427. state->tx_tuna[8] = 0x00;
  428. break;
  429. case QPSK:
  430. case QAM_AUTO:
  431. case VSB_8:
  432. case VSB_16:
  433. default:
  434. return -EINVAL;
  435. }
  436. return 0;
  437. }
  438. static fe_modulation_t dst_get_modulation(struct dst_state *state)
  439. {
  440. return state->modulation;
  441. }
  442. u8 dst_check_sum(u8 *buf, u32 len)
  443. {
  444. u32 i;
  445. u8 val = 0;
  446. if (!len)
  447. return 0;
  448. for (i = 0; i < len; i++) {
  449. val += buf[i];
  450. }
  451. return ((~val) + 1);
  452. }
  453. EXPORT_SYMBOL(dst_check_sum);
  454. static void dst_type_flags_print(u32 type_flags)
  455. {
  456. dprintk(verbose, DST_ERROR, 0, "DST type flags :");
  457. if (type_flags & DST_TYPE_HAS_NEWTUNE)
  458. dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner", DST_TYPE_HAS_NEWTUNE);
  459. if (type_flags & DST_TYPE_HAS_TS204)
  460. dprintk(verbose, DST_ERROR, 0, " 0x%x ts204", DST_TYPE_HAS_TS204);
  461. if (type_flags & DST_TYPE_HAS_SYMDIV)
  462. dprintk(verbose, DST_ERROR, 0, " 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
  463. if (type_flags & DST_TYPE_HAS_FW_1)
  464. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
  465. if (type_flags & DST_TYPE_HAS_FW_2)
  466. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
  467. if (type_flags & DST_TYPE_HAS_FW_3)
  468. dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
  469. dprintk(verbose, DST_ERROR, 0, "\n");
  470. }
  471. static int dst_type_print(u8 type)
  472. {
  473. char *otype;
  474. switch (type) {
  475. case DST_TYPE_IS_SAT:
  476. otype = "satellite";
  477. break;
  478. case DST_TYPE_IS_TERR:
  479. otype = "terrestrial";
  480. break;
  481. case DST_TYPE_IS_CABLE:
  482. otype = "cable";
  483. break;
  484. default:
  485. dprintk(verbose, DST_INFO, 1, "invalid dst type %d", type);
  486. return -EINVAL;
  487. }
  488. dprintk(verbose, DST_INFO, 1, "DST type: %s", otype);
  489. return 0;
  490. }
  491. /*
  492. Known cards list
  493. Satellite
  494. -------------------
  495. 200103A
  496. VP-1020 DST-MOT LG(old), TS=188
  497. VP-1020 DST-03T LG(new), TS=204
  498. VP-1022 DST-03T LG(new), TS=204
  499. VP-1025 DST-03T LG(new), TS=204
  500. VP-1030 DSTMCI, LG(new), TS=188
  501. VP-1032 DSTMCI, LG(new), TS=188
  502. Cable
  503. -------------------
  504. VP-2030 DCT-CI, Samsung, TS=204
  505. VP-2021 DCT-CI, Unknown, TS=204
  506. VP-2031 DCT-CI, Philips, TS=188
  507. VP-2040 DCT-CI, Philips, TS=188, with CA daughter board
  508. VP-2040 DCT-CI, Philips, TS=204, without CA daughter board
  509. Terrestrial
  510. -------------------
  511. VP-3050 DTTNXT TS=188
  512. VP-3040 DTT-CI, Philips, TS=188
  513. VP-3040 DTT-CI, Philips, TS=204
  514. ATSC
  515. -------------------
  516. VP-3220 ATSCDI, TS=188
  517. VP-3250 ATSCAD, TS=188
  518. */
  519. struct dst_types dst_tlist[] = {
  520. {
  521. .device_id = "200103A",
  522. .offset = 0,
  523. .dst_type = DST_TYPE_IS_SAT,
  524. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
  525. .dst_feature = 0
  526. }, /* obsolete */
  527. {
  528. .device_id = "DST-020",
  529. .offset = 0,
  530. .dst_type = DST_TYPE_IS_SAT,
  531. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
  532. .dst_feature = 0
  533. }, /* obsolete */
  534. {
  535. .device_id = "DST-030",
  536. .offset = 0,
  537. .dst_type = DST_TYPE_IS_SAT,
  538. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  539. .dst_feature = 0
  540. }, /* obsolete */
  541. {
  542. .device_id = "DST-03T",
  543. .offset = 0,
  544. .dst_type = DST_TYPE_IS_SAT,
  545. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
  546. .dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
  547. | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO
  548. },
  549. {
  550. .device_id = "DST-MOT",
  551. .offset = 0,
  552. .dst_type = DST_TYPE_IS_SAT,
  553. .type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
  554. .dst_feature = 0
  555. }, /* obsolete */
  556. {
  557. .device_id = "DST-CI",
  558. .offset = 1,
  559. .dst_type = DST_TYPE_IS_SAT,
  560. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  561. .dst_feature = DST_TYPE_HAS_CA
  562. }, /* An OEM board */
  563. {
  564. .device_id = "DSTMCI",
  565. .offset = 1,
  566. .dst_type = DST_TYPE_IS_SAT,
  567. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
  568. .dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
  569. | DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC
  570. },
  571. {
  572. .device_id = "DSTFCI",
  573. .offset = 1,
  574. .dst_type = DST_TYPE_IS_SAT,
  575. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
  576. .dst_feature = 0
  577. }, /* unknown to vendor */
  578. {
  579. .device_id = "DCT-CI",
  580. .offset = 1,
  581. .dst_type = DST_TYPE_IS_CABLE,
  582. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1
  583. | DST_TYPE_HAS_FW_2,
  584. .dst_feature = DST_TYPE_HAS_CA
  585. },
  586. {
  587. .device_id = "DCTNEW",
  588. .offset = 1,
  589. .dst_type = DST_TYPE_IS_CABLE,
  590. .type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD,
  591. .dst_feature = 0
  592. },
  593. {
  594. .device_id = "DTT-CI",
  595. .offset = 1,
  596. .dst_type = DST_TYPE_IS_TERR,
  597. .type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
  598. .dst_feature = 0
  599. },
  600. {
  601. .device_id = "DTTDIG",
  602. .offset = 1,
  603. .dst_type = DST_TYPE_IS_TERR,
  604. .type_flags = DST_TYPE_HAS_FW_2,
  605. .dst_feature = 0
  606. },
  607. {
  608. .device_id = "DTTNXT",
  609. .offset = 1,
  610. .dst_type = DST_TYPE_IS_TERR,
  611. .type_flags = DST_TYPE_HAS_FW_2,
  612. .dst_feature = DST_TYPE_HAS_ANALOG
  613. },
  614. {
  615. .device_id = "ATSCDI",
  616. .offset = 1,
  617. .dst_type = DST_TYPE_IS_ATSC,
  618. .type_flags = DST_TYPE_HAS_FW_2,
  619. .dst_feature = 0
  620. },
  621. {
  622. .device_id = "ATSCAD",
  623. .offset = 1,
  624. .dst_type = DST_TYPE_IS_ATSC,
  625. .type_flags = DST_TYPE_HAS_FW_2,
  626. .dst_feature = 0
  627. },
  628. { }
  629. };
  630. static int dst_get_mac(struct dst_state *state)
  631. {
  632. u8 get_mac[] = { 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  633. get_mac[7] = dst_check_sum(get_mac, 7);
  634. if (dst_command(state, get_mac, 8) < 0) {
  635. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  636. return -1;
  637. }
  638. memset(&state->mac_address, '\0', 8);
  639. memcpy(&state->mac_address, &state->rxbuffer, 6);
  640. dprintk(verbose, DST_ERROR, 1, "MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]",
  641. state->mac_address[0], state->mac_address[1], state->mac_address[2],
  642. state->mac_address[4], state->mac_address[5], state->mac_address[6]);
  643. return 0;
  644. }
  645. static int dst_fw_ver(struct dst_state *state)
  646. {
  647. u8 get_ver[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  648. get_ver[7] = dst_check_sum(get_ver, 7);
  649. if (dst_command(state, get_ver, 8) < 0) {
  650. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  651. return -1;
  652. }
  653. memset(&state->fw_version, '\0', 8);
  654. memcpy(&state->fw_version, &state->rxbuffer, 8);
  655. dprintk(verbose, DST_ERROR, 1, "Firmware Ver = %x.%x Build = %02x, on %x:%x, %x-%x-20%02x",
  656. state->fw_version[0] >> 4, state->fw_version[0] & 0x0f,
  657. state->fw_version[1],
  658. state->fw_version[5], state->fw_version[6],
  659. state->fw_version[4], state->fw_version[3], state->fw_version[2]);
  660. return 0;
  661. }
  662. static int dst_card_type(struct dst_state *state)
  663. {
  664. u8 get_type[] = { 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  665. get_type[7] = dst_check_sum(get_type, 7);
  666. if (dst_command(state, get_type, 8) < 0) {
  667. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  668. return -1;
  669. }
  670. memset(&state->card_info, '\0', 8);
  671. memcpy(&state->card_info, &state->rxbuffer, 8);
  672. dprintk(verbose, DST_ERROR, 1, "Device Model=[%s]", &state->card_info[0]);
  673. return 0;
  674. }
  675. static int dst_get_vendor(struct dst_state *state)
  676. {
  677. u8 get_vendor[] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  678. get_vendor[7] = dst_check_sum(get_vendor, 7);
  679. if (dst_command(state, get_vendor, 8) < 0) {
  680. dprintk(verbose, DST_INFO, 1, "Unsupported Command");
  681. return -1;
  682. }
  683. memset(&state->vendor, '\0', 8);
  684. memcpy(&state->vendor, &state->rxbuffer, 8);
  685. dprintk(verbose, DST_ERROR, 1, "Vendor=[%s]", &state->vendor[0]);
  686. return 0;
  687. }
  688. static int dst_get_device_id(struct dst_state *state)
  689. {
  690. u8 reply;
  691. int i;
  692. struct dst_types *p_dst_type;
  693. u8 use_dst_type = 0;
  694. u32 use_type_flags = 0;
  695. static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
  696. device_type[7] = dst_check_sum(device_type, 7);
  697. if (write_dst(state, device_type, FIXED_COMM))
  698. return -1; /* Write failed */
  699. if ((dst_pio_disable(state)) < 0)
  700. return -1;
  701. if (read_dst(state, &reply, GET_ACK))
  702. return -1; /* Read failure */
  703. if (reply != ACK) {
  704. dprintk(verbose, DST_INFO, 1, "Write not Acknowledged! [Reply=0x%02x]", reply);
  705. return -1; /* Unack'd write */
  706. }
  707. if (!dst_wait_dst_ready(state, DEVICE_INIT))
  708. return -1; /* DST not ready yet */
  709. if (read_dst(state, state->rxbuffer, FIXED_COMM))
  710. return -1;
  711. dst_pio_disable(state);
  712. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  713. dprintk(verbose, DST_INFO, 1, "Checksum failure!");
  714. return -1; /* Checksum failure */
  715. }
  716. state->rxbuffer[7] = '\0';
  717. for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
  718. if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
  719. use_type_flags = p_dst_type->type_flags;
  720. use_dst_type = p_dst_type->dst_type;
  721. /* Card capabilities */
  722. state->dst_hw_cap = p_dst_type->dst_feature;
  723. dprintk(verbose, DST_ERROR, 1, "Recognise [%s]\n", p_dst_type->device_id);
  724. break;
  725. }
  726. }
  727. if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
  728. dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
  729. dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
  730. use_dst_type = DST_TYPE_IS_SAT;
  731. use_type_flags = DST_TYPE_HAS_SYMDIV;
  732. }
  733. dst_type_print(use_dst_type);
  734. state->type_flags = use_type_flags;
  735. state->dst_type = use_dst_type;
  736. dst_type_flags_print(state->type_flags);
  737. if (state->type_flags & DST_TYPE_HAS_TS204) {
  738. dst_packsize(state, 204);
  739. }
  740. return 0;
  741. }
  742. static int dst_probe(struct dst_state *state)
  743. {
  744. if ((rdc_8820_reset(state)) < 0) {
  745. dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
  746. return -1;
  747. }
  748. if (dst_addons & DST_TYPE_HAS_CA)
  749. msleep(4000);
  750. else
  751. msleep(100);
  752. if ((dst_comm_init(state)) < 0) {
  753. dprintk(verbose, DST_ERROR, 1, "DST Initialization Failed.");
  754. return -1;
  755. }
  756. msleep(100);
  757. if (dst_get_device_id(state) < 0) {
  758. dprintk(verbose, DST_ERROR, 1, "unknown device.");
  759. return -1;
  760. }
  761. if (dst_get_mac(state) < 0) {
  762. dprintk(verbose, DST_INFO, 1, "MAC: Unsupported command");
  763. return 0;
  764. }
  765. if (state->type_flags & DST_TYPE_HAS_FW_BUILD) {
  766. if (dst_fw_ver(state) < 0) {
  767. dprintk(verbose, DST_INFO, 1, "FW: Unsupported command");
  768. return 0;
  769. }
  770. if (dst_card_type(state) < 0) {
  771. dprintk(verbose, DST_INFO, 1, "Card: Unsupported command");
  772. return 0;
  773. }
  774. if (dst_get_vendor(state) < 0) {
  775. dprintk(verbose, DST_INFO, 1, "Vendor: Unsupported command");
  776. return 0;
  777. }
  778. }
  779. return 0;
  780. }
  781. int dst_command(struct dst_state *state, u8 *data, u8 len)
  782. {
  783. u8 reply;
  784. if ((dst_comm_init(state)) < 0) {
  785. dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
  786. return -1;
  787. }
  788. if (write_dst(state, data, len)) {
  789. dprintk(verbose, DST_INFO, 1, "Tring to recover.. ");
  790. if ((dst_error_recovery(state)) < 0) {
  791. dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
  792. return -1;
  793. }
  794. return -1;
  795. }
  796. if ((dst_pio_disable(state)) < 0) {
  797. dprintk(verbose, DST_ERROR, 1, "PIO Disable Failed.");
  798. return -1;
  799. }
  800. if (state->type_flags & DST_TYPE_HAS_FW_1)
  801. udelay(3000);
  802. if (read_dst(state, &reply, GET_ACK)) {
  803. dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
  804. if ((dst_error_recovery(state)) < 0) {
  805. dprintk(verbose, DST_INFO, 1, "Recovery Failed.");
  806. return -1;
  807. }
  808. return -1;
  809. }
  810. if (reply != ACK) {
  811. dprintk(verbose, DST_INFO, 1, "write not acknowledged 0x%02x ", reply);
  812. return -1;
  813. }
  814. if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
  815. return 0;
  816. if (state->type_flags & DST_TYPE_HAS_FW_1)
  817. udelay(3000);
  818. else
  819. udelay(2000);
  820. if (!dst_wait_dst_ready(state, NO_DELAY))
  821. return -1;
  822. if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
  823. dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
  824. if ((dst_error_recovery(state)) < 0) {
  825. dprintk(verbose, DST_INFO, 1, "Recovery failed.");
  826. return -1;
  827. }
  828. return -1;
  829. }
  830. if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
  831. dprintk(verbose, DST_INFO, 1, "checksum failure");
  832. return -1;
  833. }
  834. return 0;
  835. }
  836. EXPORT_SYMBOL(dst_command);
  837. static int dst_get_signal(struct dst_state *state)
  838. {
  839. int retval;
  840. u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
  841. //dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
  842. if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
  843. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  844. return 0;
  845. }
  846. if (0 == (state->diseq_flags & HAS_LOCK)) {
  847. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  848. return 0;
  849. }
  850. if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
  851. retval = dst_command(state, get_signal, 8);
  852. if (retval < 0)
  853. return retval;
  854. if (state->dst_type == DST_TYPE_IS_SAT) {
  855. state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
  856. state->decode_strength = state->rxbuffer[5] << 8;
  857. state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
  858. } else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
  859. state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
  860. state->decode_strength = state->rxbuffer[4] << 8;
  861. state->decode_snr = state->rxbuffer[3] << 8;
  862. }
  863. state->cur_jiff = jiffies;
  864. }
  865. return 0;
  866. }
  867. static int dst_tone_power_cmd(struct dst_state *state)
  868. {
  869. u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };
  870. if (state->dst_type == DST_TYPE_IS_TERR)
  871. return 0;
  872. paket[4] = state->tx_tuna[4];
  873. paket[2] = state->tx_tuna[2];
  874. paket[3] = state->tx_tuna[3];
  875. paket[7] = dst_check_sum (paket, 7);
  876. dst_command(state, paket, 8);
  877. return 0;
  878. }
  879. static int dst_get_tuna(struct dst_state *state)
  880. {
  881. int retval;
  882. if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
  883. return 0;
  884. state->diseq_flags &= ~(HAS_LOCK);
  885. if (!dst_wait_dst_ready(state, NO_DELAY))
  886. return 0;
  887. if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
  888. /* how to get variable length reply ???? */
  889. retval = read_dst(state, state->rx_tuna, 10);
  890. else
  891. retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
  892. if (retval < 0) {
  893. dprintk(verbose, DST_DEBUG, 1, "read not successful");
  894. return 0;
  895. }
  896. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  897. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
  898. dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
  899. return 0;
  900. }
  901. } else {
  902. if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
  903. dprintk(verbose, DST_INFO, 1, "checksum failure? ");
  904. return 0;
  905. }
  906. }
  907. if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
  908. return 0;
  909. state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
  910. state->decode_lock = 1;
  911. state->diseq_flags |= HAS_LOCK;
  912. return 1;
  913. }
  914. static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
  915. static int dst_write_tuna(struct dvb_frontend *fe)
  916. {
  917. struct dst_state *state = fe->demodulator_priv;
  918. int retval;
  919. u8 reply;
  920. dprintk(verbose, DST_INFO, 1, "type_flags 0x%x ", state->type_flags);
  921. state->decode_freq = 0;
  922. state->decode_lock = state->decode_strength = state->decode_snr = 0;
  923. if (state->dst_type == DST_TYPE_IS_SAT) {
  924. if (!(state->diseq_flags & HAS_POWER))
  925. dst_set_voltage(fe, SEC_VOLTAGE_13);
  926. }
  927. state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
  928. if ((dst_comm_init(state)) < 0) {
  929. dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
  930. return -1;
  931. }
  932. if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
  933. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
  934. retval = write_dst(state, &state->tx_tuna[0], 10);
  935. } else {
  936. state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
  937. retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
  938. }
  939. if (retval < 0) {
  940. dst_pio_disable(state);
  941. dprintk(verbose, DST_DEBUG, 1, "write not successful");
  942. return retval;
  943. }
  944. if ((dst_pio_disable(state)) < 0) {
  945. dprintk(verbose, DST_DEBUG, 1, "DST PIO disable failed !");
  946. return -1;
  947. }
  948. if ((read_dst(state, &reply, GET_ACK) < 0)) {
  949. dprintk(verbose, DST_DEBUG, 1, "read verify not successful.");
  950. return -1;
  951. }
  952. if (reply != ACK) {
  953. dprintk(verbose, DST_DEBUG, 1, "write not acknowledged 0x%02x ", reply);
  954. return 0;
  955. }
  956. state->diseq_flags |= ATTEMPT_TUNE;
  957. return dst_get_tuna(state);
  958. }
  959. /*
  960. * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
  961. * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
  962. * line22k2 0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
  963. * tone 0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
  964. * data 0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
  965. * power_off 0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
  966. * power_on 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
  967. * Diseqc 1 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
  968. * Diseqc 2 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
  969. * Diseqc 3 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
  970. * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
  971. */
  972. static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
  973. {
  974. struct dst_state *state = fe->demodulator_priv;
  975. u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };
  976. if (state->dst_type != DST_TYPE_IS_SAT)
  977. return 0;
  978. if (cmd->msg_len == 0 || cmd->msg_len > 4)
  979. return -EINVAL;
  980. memcpy(&paket[3], cmd->msg, cmd->msg_len);
  981. paket[7] = dst_check_sum(&paket[0], 7);
  982. dst_command(state, paket, 8);
  983. return 0;
  984. }
  985. static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  986. {
  987. int need_cmd;
  988. struct dst_state *state = fe->demodulator_priv;
  989. state->voltage = voltage;
  990. if (state->dst_type != DST_TYPE_IS_SAT)
  991. return 0;
  992. need_cmd = 0;
  993. switch (voltage) {
  994. case SEC_VOLTAGE_13:
  995. case SEC_VOLTAGE_18:
  996. if ((state->diseq_flags & HAS_POWER) == 0)
  997. need_cmd = 1;
  998. state->diseq_flags |= HAS_POWER;
  999. state->tx_tuna[4] = 0x01;
  1000. break;
  1001. case SEC_VOLTAGE_OFF:
  1002. need_cmd = 1;
  1003. state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
  1004. state->tx_tuna[4] = 0x00;
  1005. break;
  1006. default:
  1007. return -EINVAL;
  1008. }
  1009. if (need_cmd)
  1010. dst_tone_power_cmd(state);
  1011. return 0;
  1012. }
  1013. static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
  1014. {
  1015. struct dst_state *state = fe->demodulator_priv;
  1016. state->tone = tone;
  1017. if (state->dst_type != DST_TYPE_IS_SAT)
  1018. return 0;
  1019. switch (tone) {
  1020. case SEC_TONE_OFF:
  1021. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1022. state->tx_tuna[2] = 0x00;
  1023. else
  1024. state->tx_tuna[2] = 0xff;
  1025. break;
  1026. case SEC_TONE_ON:
  1027. state->tx_tuna[2] = 0x02;
  1028. break;
  1029. default:
  1030. return -EINVAL;
  1031. }
  1032. dst_tone_power_cmd(state);
  1033. return 0;
  1034. }
  1035. static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
  1036. {
  1037. struct dst_state *state = fe->demodulator_priv;
  1038. if (state->dst_type != DST_TYPE_IS_SAT)
  1039. return 0;
  1040. state->minicmd = minicmd;
  1041. switch (minicmd) {
  1042. case SEC_MINI_A:
  1043. state->tx_tuna[3] = 0x02;
  1044. break;
  1045. case SEC_MINI_B:
  1046. state->tx_tuna[3] = 0xff;
  1047. break;
  1048. }
  1049. dst_tone_power_cmd(state);
  1050. return 0;
  1051. }
  1052. static int dst_init(struct dvb_frontend *fe)
  1053. {
  1054. struct dst_state *state = fe->demodulator_priv;
  1055. static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
  1056. static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
  1057. static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1058. static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1059. static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1060. static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
  1061. state->inversion = INVERSION_OFF;
  1062. state->voltage = SEC_VOLTAGE_13;
  1063. state->tone = SEC_TONE_OFF;
  1064. state->diseq_flags = 0;
  1065. state->k22 = 0x02;
  1066. state->bandwidth = BANDWIDTH_7_MHZ;
  1067. state->cur_jiff = jiffies;
  1068. if (state->dst_type == DST_TYPE_IS_SAT)
  1069. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
  1070. else if (state->dst_type == DST_TYPE_IS_TERR)
  1071. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
  1072. else if (state->dst_type == DST_TYPE_IS_CABLE)
  1073. memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
  1074. return 0;
  1075. }
  1076. static int dst_read_status(struct dvb_frontend *fe, fe_status_t *status)
  1077. {
  1078. struct dst_state *state = fe->demodulator_priv;
  1079. *status = 0;
  1080. if (state->diseq_flags & HAS_LOCK) {
  1081. // dst_get_signal(state); // don't require(?) to ask MCU
  1082. if (state->decode_lock)
  1083. *status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
  1084. }
  1085. return 0;
  1086. }
  1087. static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  1088. {
  1089. struct dst_state *state = fe->demodulator_priv;
  1090. dst_get_signal(state);
  1091. *strength = state->decode_strength;
  1092. return 0;
  1093. }
  1094. static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
  1095. {
  1096. struct dst_state *state = fe->demodulator_priv;
  1097. dst_get_signal(state);
  1098. *snr = state->decode_snr;
  1099. return 0;
  1100. }
  1101. static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1102. {
  1103. struct dst_state *state = fe->demodulator_priv;
  1104. dst_set_freq(state, p->frequency);
  1105. dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
  1106. if (state->dst_type == DST_TYPE_IS_SAT) {
  1107. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1108. dst_set_inversion(state, p->inversion);
  1109. dst_set_fec(state, p->u.qpsk.fec_inner);
  1110. dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
  1111. dst_set_polarization(state);
  1112. dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);
  1113. } else if (state->dst_type == DST_TYPE_IS_TERR)
  1114. dst_set_bandwidth(state, p->u.ofdm.bandwidth);
  1115. else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1116. dst_set_fec(state, p->u.qam.fec_inner);
  1117. dst_set_symbolrate(state, p->u.qam.symbol_rate);
  1118. dst_set_modulation(state, p->u.qam.modulation);
  1119. }
  1120. dst_write_tuna(fe);
  1121. return 0;
  1122. }
  1123. static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1124. {
  1125. struct dst_state *state = fe->demodulator_priv;
  1126. p->frequency = state->decode_freq;
  1127. if (state->dst_type == DST_TYPE_IS_SAT) {
  1128. if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
  1129. p->inversion = state->inversion;
  1130. p->u.qpsk.symbol_rate = state->symbol_rate;
  1131. p->u.qpsk.fec_inner = dst_get_fec(state);
  1132. } else if (state->dst_type == DST_TYPE_IS_TERR) {
  1133. p->u.ofdm.bandwidth = state->bandwidth;
  1134. } else if (state->dst_type == DST_TYPE_IS_CABLE) {
  1135. p->u.qam.symbol_rate = state->symbol_rate;
  1136. p->u.qam.fec_inner = dst_get_fec(state);
  1137. p->u.qam.modulation = dst_get_modulation(state);
  1138. }
  1139. return 0;
  1140. }
  1141. static void dst_release(struct dvb_frontend *fe)
  1142. {
  1143. struct dst_state *state = fe->demodulator_priv;
  1144. kfree(state);
  1145. }
  1146. static struct dvb_frontend_ops dst_dvbt_ops;
  1147. static struct dvb_frontend_ops dst_dvbs_ops;
  1148. static struct dvb_frontend_ops dst_dvbc_ops;
  1149. struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
  1150. {
  1151. /* check if the ASIC is there */
  1152. if (dst_probe(state) < 0) {
  1153. if (state)
  1154. kfree(state);
  1155. return NULL;
  1156. }
  1157. /* determine settings based on type */
  1158. switch (state->dst_type) {
  1159. case DST_TYPE_IS_TERR:
  1160. memcpy(&state->ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
  1161. break;
  1162. case DST_TYPE_IS_CABLE:
  1163. memcpy(&state->ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
  1164. break;
  1165. case DST_TYPE_IS_SAT:
  1166. memcpy(&state->ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
  1167. break;
  1168. default:
  1169. dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
  1170. if (state)
  1171. kfree(state);
  1172. return NULL;
  1173. }
  1174. /* create dvb_frontend */
  1175. state->frontend.ops = &state->ops;
  1176. state->frontend.demodulator_priv = state;
  1177. return state; /* Manu (DST is a card not a frontend) */
  1178. }
  1179. EXPORT_SYMBOL(dst_attach);
  1180. static struct dvb_frontend_ops dst_dvbt_ops = {
  1181. .info = {
  1182. .name = "DST DVB-T",
  1183. .type = FE_OFDM,
  1184. .frequency_min = 137000000,
  1185. .frequency_max = 858000000,
  1186. .frequency_stepsize = 166667,
  1187. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
  1188. },
  1189. .release = dst_release,
  1190. .init = dst_init,
  1191. .set_frontend = dst_set_frontend,
  1192. .get_frontend = dst_get_frontend,
  1193. .read_status = dst_read_status,
  1194. .read_signal_strength = dst_read_signal_strength,
  1195. .read_snr = dst_read_snr,
  1196. };
  1197. static struct dvb_frontend_ops dst_dvbs_ops = {
  1198. .info = {
  1199. .name = "DST DVB-S",
  1200. .type = FE_QPSK,
  1201. .frequency_min = 950000,
  1202. .frequency_max = 2150000,
  1203. .frequency_stepsize = 1000, /* kHz for QPSK frontends */
  1204. .frequency_tolerance = 29500,
  1205. .symbol_rate_min = 1000000,
  1206. .symbol_rate_max = 45000000,
  1207. /* . symbol_rate_tolerance = ???,*/
  1208. .caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
  1209. },
  1210. .release = dst_release,
  1211. .init = dst_init,
  1212. .set_frontend = dst_set_frontend,
  1213. .get_frontend = dst_get_frontend,
  1214. .read_status = dst_read_status,
  1215. .read_signal_strength = dst_read_signal_strength,
  1216. .read_snr = dst_read_snr,
  1217. .diseqc_send_burst = dst_send_burst,
  1218. .diseqc_send_master_cmd = dst_set_diseqc,
  1219. .set_voltage = dst_set_voltage,
  1220. .set_tone = dst_set_tone,
  1221. };
  1222. static struct dvb_frontend_ops dst_dvbc_ops = {
  1223. .info = {
  1224. .name = "DST DVB-C",
  1225. .type = FE_QAM,
  1226. .frequency_stepsize = 62500,
  1227. .frequency_min = 51000000,
  1228. .frequency_max = 858000000,
  1229. .symbol_rate_min = 1000000,
  1230. .symbol_rate_max = 45000000,
  1231. /* . symbol_rate_tolerance = ???,*/
  1232. .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO
  1233. },
  1234. .release = dst_release,
  1235. .init = dst_init,
  1236. .set_frontend = dst_set_frontend,
  1237. .get_frontend = dst_get_frontend,
  1238. .read_status = dst_read_status,
  1239. .read_signal_strength = dst_read_signal_strength,
  1240. .read_snr = dst_read_snr,
  1241. };
  1242. MODULE_DESCRIPTION("DST DVB-S/T/C Combo Frontend driver");
  1243. MODULE_AUTHOR("Jamie Honan, Manu Abraham");
  1244. MODULE_LICENSE("GPL");