stb0899_drv.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  1. /*
  2. STB0899 Multistandard Frontend driver
  3. Copyright (C) Manu Abraham (abraham.manu@gmail.com)
  4. Copyright (C) ST Microelectronics
  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/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/string.h>
  21. #include <linux/dvb/frontend.h>
  22. #include "dvb_frontend.h"
  23. #include "stb0899_drv.h"
  24. #include "stb0899_priv.h"
  25. #include "stb0899_reg.h"
  26. static unsigned int verbose = 0;//1;
  27. module_param(verbose, int, 0644);
  28. /* C/N in dB/10, NIRM/NIRL */
  29. static const struct stb0899_tab stb0899_cn_tab[] = {
  30. { 200, 2600 },
  31. { 190, 2700 },
  32. { 180, 2860 },
  33. { 170, 3020 },
  34. { 160, 3210 },
  35. { 150, 3440 },
  36. { 140, 3710 },
  37. { 130, 4010 },
  38. { 120, 4360 },
  39. { 110, 4740 },
  40. { 100, 5190 },
  41. { 90, 5670 },
  42. { 80, 6200 },
  43. { 70, 6770 },
  44. { 60, 7360 },
  45. { 50, 7970 },
  46. { 40, 8250 },
  47. { 30, 9000 },
  48. { 20, 9450 },
  49. { 15, 9600 },
  50. };
  51. /* DVB-S AGCIQ_VALUE vs. signal level in dBm/10.
  52. * As measured, connected to a modulator.
  53. * -8.0 to -50.0 dBm directly connected,
  54. * -52.0 to -74.8 with extra attenuation.
  55. * Cut-off to AGCIQ_VALUE = 0x80 below -74.8dBm.
  56. * Crude linear extrapolation below -84.8dBm and above -8.0dBm.
  57. */
  58. static const struct stb0899_tab stb0899_dvbsrf_tab[] = {
  59. { -950, -128 },
  60. { -748, -94 },
  61. { -745, -92 },
  62. { -735, -90 },
  63. { -720, -87 },
  64. { -670, -77 },
  65. { -640, -70 },
  66. { -610, -62 },
  67. { -600, -60 },
  68. { -590, -56 },
  69. { -560, -41 },
  70. { -540, -25 },
  71. { -530, -17 },
  72. { -520, -11 },
  73. { -500, 1 },
  74. { -490, 6 },
  75. { -480, 10 },
  76. { -440, 22 },
  77. { -420, 27 },
  78. { -400, 31 },
  79. { -380, 34 },
  80. { -340, 40 },
  81. { -320, 43 },
  82. { -280, 48 },
  83. { -250, 52 },
  84. { -230, 55 },
  85. { -180, 61 },
  86. { -140, 66 },
  87. { -90, 73 },
  88. { -80, 74 },
  89. { 500, 127 }
  90. };
  91. /* DVB-S2 IF_AGC_GAIN vs. signal level in dBm/10.
  92. * As measured, connected to a modulator.
  93. * -8.0 to -50.1 dBm directly connected,
  94. * -53.0 to -76.6 with extra attenuation.
  95. * Cut-off to IF_AGC_GAIN = 0x3fff below -76.6dBm.
  96. * Crude linear extrapolation below -76.6dBm and above -8.0dBm.
  97. */
  98. static const struct stb0899_tab stb0899_dvbs2rf_tab[] = {
  99. { 700, 0 },
  100. { -80, 3217 },
  101. { -150, 3893 },
  102. { -190, 4217 },
  103. { -240, 4621 },
  104. { -280, 4945 },
  105. { -320, 5273 },
  106. { -350, 5545 },
  107. { -370, 5741 },
  108. { -410, 6147 },
  109. { -450, 6671 },
  110. { -490, 7413 },
  111. { -501, 7665 },
  112. { -530, 8767 },
  113. { -560, 10219 },
  114. { -580, 10939 },
  115. { -590, 11518 },
  116. { -600, 11723 },
  117. { -650, 12659 },
  118. { -690, 13219 },
  119. { -730, 13645 },
  120. { -750, 13909 },
  121. { -766, 14153 },
  122. { -999, 16383 }
  123. };
  124. /* DVB-S2 Es/N0 quant in dB/100 vs read value * 100*/
  125. struct stb0899_tab stb0899_quant_tab[] = {
  126. { 0, 0 },
  127. { 0, 100 },
  128. { 600, 200 },
  129. { 950, 299 },
  130. { 1200, 398 },
  131. { 1400, 501 },
  132. { 1560, 603 },
  133. { 1690, 700 },
  134. { 1810, 804 },
  135. { 1910, 902 },
  136. { 2000, 1000 },
  137. { 2080, 1096 },
  138. { 2160, 1202 },
  139. { 2230, 1303 },
  140. { 2350, 1496 },
  141. { 2410, 1603 },
  142. { 2460, 1698 },
  143. { 2510, 1799 },
  144. { 2600, 1995 },
  145. { 2650, 2113 },
  146. { 2690, 2213 },
  147. { 2720, 2291 },
  148. { 2760, 2399 },
  149. { 2800, 2512 },
  150. { 2860, 2692 },
  151. { 2930, 2917 },
  152. { 2960, 3020 },
  153. { 3010, 3199 },
  154. { 3040, 3311 },
  155. { 3060, 3388 },
  156. { 3120, 3631 },
  157. { 3190, 3936 },
  158. { 3400, 5012 },
  159. { 3610, 6383 },
  160. { 3800, 7943 },
  161. { 4210, 12735 },
  162. { 4500, 17783 },
  163. { 4690, 22131 },
  164. { 4810, 25410 }
  165. };
  166. /* DVB-S2 Es/N0 estimate in dB/100 vs read value */
  167. struct stb0899_tab stb0899_est_tab[] = {
  168. { 0, 0 },
  169. { 0, 1 },
  170. { 301, 2 },
  171. { 1204, 16 },
  172. { 1806, 64 },
  173. { 2408, 256 },
  174. { 2709, 512 },
  175. { 3010, 1023 },
  176. { 3311, 2046 },
  177. { 3612, 4093 },
  178. { 3823, 6653 },
  179. { 3913, 8185 },
  180. { 4010, 10233 },
  181. { 4107, 12794 },
  182. { 4214, 16368 },
  183. { 4266, 18450 },
  184. { 4311, 20464 },
  185. { 4353, 22542 },
  186. { 4391, 24604 },
  187. { 4425, 26607 },
  188. { 4457, 28642 },
  189. { 4487, 30690 },
  190. { 4515, 32734 },
  191. { 4612, 40926 },
  192. { 4692, 49204 },
  193. { 4816, 65464 },
  194. { 4913, 81846 },
  195. { 4993, 98401 },
  196. { 5060, 114815 },
  197. { 5118, 131220 },
  198. { 5200, 158489 },
  199. { 5300, 199526 },
  200. { 5400, 251189 },
  201. { 5500, 316228 },
  202. { 5600, 398107 },
  203. { 5720, 524807 },
  204. { 5721, 526017 },
  205. };
  206. int _stb0899_read_reg(struct stb0899_state *state, unsigned int reg)
  207. {
  208. int ret;
  209. u8 b0[] = { reg >> 8, reg & 0xff };
  210. u8 buf;
  211. struct i2c_msg msg[] = {
  212. {
  213. .addr = state->config->demod_address,
  214. .flags = 0,
  215. .buf = b0,
  216. .len = 2
  217. },{
  218. .addr = state->config->demod_address,
  219. .flags = I2C_M_RD,
  220. .buf = &buf,
  221. .len = 1
  222. }
  223. };
  224. ret = i2c_transfer(state->i2c, msg, 2);
  225. if (ret != 2) {
  226. if (ret != -ERESTARTSYS)
  227. dprintk(state->verbose, FE_ERROR, 1,
  228. "Read error, Reg=[0x%02x], Status=%d",
  229. reg, ret);
  230. return ret < 0 ? ret : -EREMOTEIO;
  231. }
  232. if (unlikely(*state->verbose >= FE_DEBUGREG))
  233. dprintk(state->verbose, FE_ERROR, 1, "Reg=[0x%02x], data=%02x",
  234. reg, buf);
  235. return (unsigned int)buf;
  236. }
  237. int stb0899_read_reg(struct stb0899_state *state, unsigned int reg)
  238. {
  239. int result;
  240. result = _stb0899_read_reg(state, reg);
  241. /*
  242. * Bug ID 9:
  243. * access to 0xf2xx/0xf6xx
  244. * must be followed by read from 0xf2ff/0xf6ff.
  245. */
  246. if ((reg != 0xf2ff) && (reg != 0xf6ff) &&
  247. (((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
  248. _stb0899_read_reg(state, (reg | 0x00ff));
  249. return result;
  250. }
  251. u32 _stb0899_read_s2reg(struct stb0899_state *state,
  252. u32 stb0899_i2cdev,
  253. u32 stb0899_base_addr,
  254. u16 stb0899_reg_offset)
  255. {
  256. int status;
  257. u32 data;
  258. u8 buf[7] = { 0 };
  259. u16 tmpaddr;
  260. u8 buf_0[] = {
  261. GETBYTE(stb0899_i2cdev, BYTE1), /* 0xf3 S2 Base Address (MSB) */
  262. GETBYTE(stb0899_i2cdev, BYTE0), /* 0xfc S2 Base Address (LSB) */
  263. GETBYTE(stb0899_base_addr, BYTE0), /* 0x00 Base Address (LSB) */
  264. GETBYTE(stb0899_base_addr, BYTE1), /* 0x04 Base Address (LSB) */
  265. GETBYTE(stb0899_base_addr, BYTE2), /* 0x00 Base Address (MSB) */
  266. GETBYTE(stb0899_base_addr, BYTE3), /* 0x00 Base Address (MSB) */
  267. };
  268. u8 buf_1[] = {
  269. 0x00, /* 0xf3 Reg Offset */
  270. 0x00, /* 0x44 Reg Offset */
  271. };
  272. struct i2c_msg msg_0 = {
  273. .addr = state->config->demod_address,
  274. .flags = 0,
  275. .buf = buf_0,
  276. .len = 6
  277. };
  278. struct i2c_msg msg_1 = {
  279. .addr = state->config->demod_address,
  280. .flags = 0,
  281. .buf = buf_1,
  282. .len = 2
  283. };
  284. struct i2c_msg msg_r = {
  285. .addr = state->config->demod_address,
  286. .flags = I2C_M_RD,
  287. .buf = buf,
  288. .len = 4
  289. };
  290. tmpaddr = stb0899_reg_offset & 0xff00;
  291. if (!(stb0899_reg_offset & 0x8))
  292. tmpaddr = stb0899_reg_offset | 0x20;
  293. buf_1[0] = GETBYTE(tmpaddr, BYTE1);
  294. buf_1[1] = GETBYTE(tmpaddr, BYTE0);
  295. status = i2c_transfer(state->i2c, &msg_0, 1);
  296. if (status < 1) {
  297. if (status != -ERESTARTSYS)
  298. printk(KERN_ERR "%s ERR(1), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
  299. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
  300. goto err;
  301. }
  302. /* Dummy */
  303. status = i2c_transfer(state->i2c, &msg_1, 1);
  304. if (status < 1)
  305. goto err;
  306. status = i2c_transfer(state->i2c, &msg_r, 1);
  307. if (status < 1)
  308. goto err;
  309. buf_1[0] = GETBYTE(stb0899_reg_offset, BYTE1);
  310. buf_1[1] = GETBYTE(stb0899_reg_offset, BYTE0);
  311. /* Actual */
  312. status = i2c_transfer(state->i2c, &msg_1, 1);
  313. if (status < 1) {
  314. if (status != -ERESTARTSYS)
  315. printk(KERN_ERR "%s ERR(2), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
  316. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
  317. goto err;
  318. }
  319. status = i2c_transfer(state->i2c, &msg_r, 1);
  320. if (status < 1) {
  321. if (status != -ERESTARTSYS)
  322. printk(KERN_ERR "%s ERR(3), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
  323. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
  324. return status < 0 ? status : -EREMOTEIO;
  325. }
  326. data = MAKEWORD32(buf[3], buf[2], buf[1], buf[0]);
  327. if (unlikely(*state->verbose >= FE_DEBUGREG))
  328. printk(KERN_DEBUG "%s Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
  329. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, data);
  330. return data;
  331. err:
  332. return status < 0 ? status : -EREMOTEIO;
  333. }
  334. int stb0899_write_s2reg(struct stb0899_state *state,
  335. u32 stb0899_i2cdev,
  336. u32 stb0899_base_addr,
  337. u16 stb0899_reg_offset,
  338. u32 stb0899_data)
  339. {
  340. int status;
  341. /* Base Address Setup */
  342. u8 buf_0[] = {
  343. GETBYTE(stb0899_i2cdev, BYTE1), /* 0xf3 S2 Base Address (MSB) */
  344. GETBYTE(stb0899_i2cdev, BYTE0), /* 0xfc S2 Base Address (LSB) */
  345. GETBYTE(stb0899_base_addr, BYTE0), /* 0x00 Base Address (LSB) */
  346. GETBYTE(stb0899_base_addr, BYTE1), /* 0x04 Base Address (LSB) */
  347. GETBYTE(stb0899_base_addr, BYTE2), /* 0x00 Base Address (MSB) */
  348. GETBYTE(stb0899_base_addr, BYTE3), /* 0x00 Base Address (MSB) */
  349. };
  350. u8 buf_1[] = {
  351. 0x00, /* 0xf3 Reg Offset */
  352. 0x00, /* 0x44 Reg Offset */
  353. 0x00, /* data */
  354. 0x00, /* data */
  355. 0x00, /* data */
  356. 0x00, /* data */
  357. };
  358. struct i2c_msg msg_0 = {
  359. .addr = state->config->demod_address,
  360. .flags = 0,
  361. .buf = buf_0,
  362. .len = 6
  363. };
  364. struct i2c_msg msg_1 = {
  365. .addr = state->config->demod_address,
  366. .flags = 0,
  367. .buf = buf_1,
  368. .len = 6
  369. };
  370. buf_1[0] = GETBYTE(stb0899_reg_offset, BYTE1);
  371. buf_1[1] = GETBYTE(stb0899_reg_offset, BYTE0);
  372. buf_1[2] = GETBYTE(stb0899_data, BYTE0);
  373. buf_1[3] = GETBYTE(stb0899_data, BYTE1);
  374. buf_1[4] = GETBYTE(stb0899_data, BYTE2);
  375. buf_1[5] = GETBYTE(stb0899_data, BYTE3);
  376. if (unlikely(*state->verbose >= FE_DEBUGREG))
  377. printk(KERN_DEBUG "%s Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
  378. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data);
  379. status = i2c_transfer(state->i2c, &msg_0, 1);
  380. if (unlikely(status < 1)) {
  381. if (status != -ERESTARTSYS)
  382. printk(KERN_ERR "%s ERR (1), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
  383. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data, status);
  384. goto err;
  385. }
  386. status = i2c_transfer(state->i2c, &msg_1, 1);
  387. if (unlikely(status < 1)) {
  388. if (status != -ERESTARTSYS)
  389. printk(KERN_ERR "%s ERR (2), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
  390. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data, status);
  391. return status < 0 ? status : -EREMOTEIO;
  392. }
  393. return 0;
  394. err:
  395. return status < 0 ? status : -EREMOTEIO;
  396. }
  397. int stb0899_read_regs(struct stb0899_state *state, unsigned int reg, u8 *buf, u32 count)
  398. {
  399. int status;
  400. u8 b0[] = { reg >> 8, reg & 0xff };
  401. struct i2c_msg msg[] = {
  402. {
  403. .addr = state->config->demod_address,
  404. .flags = 0,
  405. .buf = b0,
  406. .len = 2
  407. },{
  408. .addr = state->config->demod_address,
  409. .flags = I2C_M_RD,
  410. .buf = buf,
  411. .len = count
  412. }
  413. };
  414. status = i2c_transfer(state->i2c, msg, 2);
  415. if (status != 2) {
  416. if (status != -ERESTARTSYS)
  417. printk(KERN_ERR "%s Read error, Reg=[0x%04x], Count=%u, Status=%d\n",
  418. __func__, reg, count, status);
  419. goto err;
  420. }
  421. /*
  422. * Bug ID 9:
  423. * access to 0xf2xx/0xf6xx
  424. * must be followed by read from 0xf2ff/0xf6ff.
  425. */
  426. if ((reg != 0xf2ff) && (reg != 0xf6ff) &&
  427. (((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
  428. _stb0899_read_reg(state, (reg | 0x00ff));
  429. if (unlikely(*state->verbose >= FE_DEBUGREG)) {
  430. int i;
  431. printk(KERN_DEBUG "%s [0x%04x]:", __func__, reg);
  432. for (i = 0; i < count; i++) {
  433. printk(" %02x", buf[i]);
  434. }
  435. printk("\n");
  436. }
  437. return 0;
  438. err:
  439. return status < 0 ? status : -EREMOTEIO;
  440. }
  441. int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data, u32 count)
  442. {
  443. int ret;
  444. u8 buf[2 + count];
  445. struct i2c_msg i2c_msg = {
  446. .addr = state->config->demod_address,
  447. .flags = 0,
  448. .buf = buf,
  449. .len = 2 + count
  450. };
  451. buf[0] = reg >> 8;
  452. buf[1] = reg & 0xff;
  453. memcpy(&buf[2], data, count);
  454. if (unlikely(*state->verbose >= FE_DEBUGREG)) {
  455. int i;
  456. printk(KERN_DEBUG "%s [0x%04x]:", __func__, reg);
  457. for (i = 0; i < count; i++)
  458. printk(" %02x", data[i]);
  459. printk("\n");
  460. }
  461. ret = i2c_transfer(state->i2c, &i2c_msg, 1);
  462. /*
  463. * Bug ID 9:
  464. * access to 0xf2xx/0xf6xx
  465. * must be followed by read from 0xf2ff/0xf6ff.
  466. */
  467. if ((((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
  468. stb0899_read_reg(state, (reg | 0x00ff));
  469. if (ret != 1) {
  470. if (ret != -ERESTARTSYS)
  471. dprintk(state->verbose, FE_ERROR, 1, "Reg=[0x%04x], Data=[0x%02x ...], Count=%u, Status=%d",
  472. reg, data[0], count, ret);
  473. return ret < 0 ? ret : -EREMOTEIO;
  474. }
  475. return 0;
  476. }
  477. int stb0899_write_reg(struct stb0899_state *state, unsigned int reg, u8 data)
  478. {
  479. return stb0899_write_regs(state, reg, &data, 1);
  480. }
  481. /*
  482. * stb0899_get_mclk
  483. * Get STB0899 master clock frequency
  484. * ExtClk: external clock frequency (Hz)
  485. */
  486. static u32 stb0899_get_mclk(struct stb0899_state *state)
  487. {
  488. u32 mclk = 0, div = 0;
  489. div = stb0899_read_reg(state, STB0899_NCOARSE);
  490. mclk = (div + 1) * state->config->xtal_freq / 6;
  491. dprintk(state->verbose, FE_DEBUG, 1, "div=%d, mclk=%d", div, mclk);
  492. return mclk;
  493. }
  494. /*
  495. * stb0899_set_mclk
  496. * Set STB0899 master Clock frequency
  497. * Mclk: demodulator master clock
  498. * ExtClk: external clock frequency (Hz)
  499. */
  500. static void stb0899_set_mclk(struct stb0899_state *state, u32 Mclk)
  501. {
  502. struct stb0899_internal *internal = &state->internal;
  503. u8 mdiv = 0;
  504. dprintk(state->verbose, FE_DEBUG, 1, "state->config=%p", state->config);
  505. mdiv = ((6 * Mclk) / state->config->xtal_freq) - 1;
  506. dprintk(state->verbose, FE_DEBUG, 1, "mdiv=%d", mdiv);
  507. stb0899_write_reg(state, STB0899_NCOARSE, mdiv);
  508. internal->master_clk = stb0899_get_mclk(state);
  509. dprintk(state->verbose, FE_DEBUG, 1, "MasterCLOCK=%d", internal->master_clk);
  510. }
  511. static int stb0899_postproc(struct stb0899_state *state, u8 ctl, int enable)
  512. {
  513. struct stb0899_config *config = state->config;
  514. const struct stb0899_postproc *postproc = config->postproc;
  515. /* post process event */
  516. if (postproc) {
  517. if (enable) {
  518. if (postproc[ctl].level == STB0899_GPIOPULLUP)
  519. stb0899_write_reg(state, postproc[ctl].gpio, 0x02);
  520. else
  521. stb0899_write_reg(state, postproc[ctl].gpio, 0x82);
  522. } else {
  523. if (postproc[ctl].level == STB0899_GPIOPULLUP)
  524. stb0899_write_reg(state, postproc[ctl].gpio, 0x82);
  525. else
  526. stb0899_write_reg(state, postproc[ctl].gpio, 0x02);
  527. }
  528. }
  529. return 0;
  530. }
  531. static void stb0899_release(struct dvb_frontend *fe)
  532. {
  533. struct stb0899_state *state = fe->demodulator_priv;
  534. dprintk(state->verbose, FE_DEBUG, 1, "Release Frontend");
  535. /* post process event */
  536. stb0899_postproc(state, STB0899_POSTPROC_GPIO_POWER, 0);
  537. kfree(state);
  538. }
  539. /*
  540. * stb0899_get_alpha
  541. * return: rolloff
  542. */
  543. static int stb0899_get_alpha(struct stb0899_state *state)
  544. {
  545. u8 mode_coeff;
  546. mode_coeff = stb0899_read_reg(state, STB0899_DEMOD);
  547. if (STB0899_GETFIELD(MODECOEFF, mode_coeff) == 1)
  548. return 20;
  549. else
  550. return 35;
  551. }
  552. /*
  553. * stb0899_init_calc
  554. */
  555. static void stb0899_init_calc(struct stb0899_state *state)
  556. {
  557. struct stb0899_internal *internal = &state->internal;
  558. int master_clk;
  559. u8 agc[2];
  560. u8 agc1cn;
  561. u32 reg;
  562. /* Read registers (in burst mode) */
  563. agc1cn = stb0899_read_reg(state, STB0899_AGC1CN);
  564. stb0899_read_regs(state, STB0899_AGC1REF, agc, 2); /* AGC1R and AGC2O */
  565. /* Initial calculations */
  566. master_clk = stb0899_get_mclk(state);
  567. internal->t_agc1 = 0;
  568. internal->t_agc2 = 0;
  569. internal->master_clk = master_clk;
  570. internal->mclk = master_clk / 65536L;
  571. internal->rolloff = stb0899_get_alpha(state);
  572. /* DVBS2 Initial calculations */
  573. /* Set AGC value to the middle */
  574. internal->agc_gain = 8154;
  575. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, IF_AGC_CNTRL);
  576. STB0899_SETFIELD_VAL(IF_GAIN_INIT, reg, internal->agc_gain);
  577. stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_IF_AGC_CNTRL, STB0899_OFF0_IF_AGC_CNTRL, reg);
  578. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, RRC_ALPHA);
  579. internal->rrc_alpha = STB0899_GETFIELD(RRC_ALPHA, reg);
  580. internal->center_freq = 0;
  581. internal->av_frame_coarse = 10;
  582. internal->av_frame_fine = 20;
  583. internal->step_size = 2;
  584. /*
  585. if ((pParams->SpectralInv == FE_IQ_NORMAL) || (pParams->SpectralInv == FE_IQ_AUTO))
  586. pParams->IQLocked = 0;
  587. else
  588. pParams->IQLocked = 1;
  589. */
  590. }
  591. static int stb0899_wait_diseqc_fifo_empty(struct stb0899_state *state, int timeout)
  592. {
  593. u8 reg = 0;
  594. unsigned long start = jiffies;
  595. while (1) {
  596. reg = stb0899_read_reg(state, STB0899_DISSTATUS);
  597. if (!STB0899_GETFIELD(FIFOFULL, reg))
  598. break;
  599. if ((jiffies - start) > timeout) {
  600. dprintk(state->verbose, FE_ERROR, 1, "timed out !!");
  601. return -ETIMEDOUT;
  602. }
  603. }
  604. return 0;
  605. }
  606. static int stb0899_send_diseqc_msg(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
  607. {
  608. struct stb0899_state *state = fe->demodulator_priv;
  609. u8 reg, i;
  610. if (cmd->msg_len > 8)
  611. return -EINVAL;
  612. /* enable FIFO precharge */
  613. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  614. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 1);
  615. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  616. for (i = 0; i < cmd->msg_len; i++) {
  617. /* wait for FIFO empty */
  618. if (stb0899_wait_diseqc_fifo_empty(state, 10) < 0)
  619. return -ETIMEDOUT;
  620. stb0899_write_reg(state, STB0899_DISFIFO, cmd->msg[i]);
  621. }
  622. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  623. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0);
  624. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  625. return 0;
  626. }
  627. static int stb0899_wait_diseqc_rxidle(struct stb0899_state *state, int timeout)
  628. {
  629. u8 reg = 0;
  630. unsigned long start = jiffies;
  631. while (!STB0899_GETFIELD(RXEND, reg)) {
  632. reg = stb0899_read_reg(state, STB0899_DISRX_ST0);
  633. if (jiffies - start > timeout) {
  634. dprintk(state->verbose, FE_ERROR, 1, "timed out!!");
  635. return -ETIMEDOUT;
  636. }
  637. msleep(10);
  638. }
  639. return 0;
  640. }
  641. static int stb0899_recv_slave_reply(struct dvb_frontend *fe, struct dvb_diseqc_slave_reply *reply)
  642. {
  643. struct stb0899_state *state = fe->demodulator_priv;
  644. u8 reg, length = 0, i;
  645. int result;
  646. if (stb0899_wait_diseqc_rxidle(state, 100) < 0)
  647. return -ETIMEDOUT;
  648. reg = stb0899_read_reg(state, STB0899_DISRX_ST0);
  649. if (STB0899_GETFIELD(RXEND, reg)) {
  650. reg = stb0899_read_reg(state, STB0899_DISRX_ST1);
  651. length = STB0899_GETFIELD(FIFOBYTENBR, reg);
  652. if (length > sizeof (reply->msg)) {
  653. result = -EOVERFLOW;
  654. goto exit;
  655. }
  656. reply->msg_len = length;
  657. /* extract data */
  658. for (i = 0; i < length; i++)
  659. reply->msg[i] = stb0899_read_reg(state, STB0899_DISFIFO);
  660. }
  661. return 0;
  662. exit:
  663. return result;
  664. }
  665. static int stb0899_wait_diseqc_txidle(struct stb0899_state *state, int timeout)
  666. {
  667. u8 reg = 0;
  668. unsigned long start = jiffies;
  669. while (!STB0899_GETFIELD(TXIDLE, reg)) {
  670. reg = stb0899_read_reg(state, STB0899_DISSTATUS);
  671. if (jiffies - start > timeout) {
  672. dprintk(state->verbose, FE_ERROR, 1, "timed out!!");
  673. return -ETIMEDOUT;
  674. }
  675. msleep(10);
  676. }
  677. return 0;
  678. }
  679. static int stb0899_send_diseqc_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst)
  680. {
  681. struct stb0899_state *state = fe->demodulator_priv;
  682. u8 reg, old_state;
  683. /* wait for diseqc idle */
  684. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  685. return -ETIMEDOUT;
  686. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  687. old_state = reg;
  688. /* set to burst mode */
  689. STB0899_SETFIELD_VAL(DISEQCMODE, reg, 0x02);
  690. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0x01);
  691. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  692. switch (burst) {
  693. case SEC_MINI_A:
  694. /* unmodulated */
  695. stb0899_write_reg(state, STB0899_DISFIFO, 0x00);
  696. break;
  697. case SEC_MINI_B:
  698. /* modulated */
  699. stb0899_write_reg(state, STB0899_DISFIFO, 0xff);
  700. break;
  701. }
  702. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  703. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0x00);
  704. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  705. /* wait for diseqc idle */
  706. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  707. return -ETIMEDOUT;
  708. /* restore state */
  709. stb0899_write_reg(state, STB0899_DISCNTRL1, old_state);
  710. return 0;
  711. }
  712. static int stb0899_diseqc_init(struct stb0899_state *state)
  713. {
  714. struct dvb_diseqc_master_cmd tx_data;
  715. /*
  716. struct dvb_diseqc_slave_reply rx_data;
  717. */
  718. u8 f22_tx, f22_rx, reg;
  719. u32 mclk, tx_freq = 22000;/* count = 0, i; */
  720. tx_data.msg[0] = 0xe2;
  721. tx_data.msg_len = 3;
  722. reg = stb0899_read_reg(state, STB0899_DISCNTRL2);
  723. STB0899_SETFIELD_VAL(ONECHIP_TRX, reg, 0);
  724. stb0899_write_reg(state, STB0899_DISCNTRL2, reg);
  725. /* disable Tx spy */
  726. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  727. STB0899_SETFIELD_VAL(DISEQCRESET, reg, 1);
  728. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  729. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  730. STB0899_SETFIELD_VAL(DISEQCRESET, reg, 0);
  731. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  732. mclk = stb0899_get_mclk(state);
  733. f22_tx = mclk / (tx_freq * 32);
  734. stb0899_write_reg(state, STB0899_DISF22, f22_tx); /* DiSEqC Tx freq */
  735. state->rx_freq = 20000;
  736. f22_rx = mclk / (state->rx_freq * 32);
  737. return 0;
  738. }
  739. static int stb0899_sleep(struct dvb_frontend *fe)
  740. {
  741. struct stb0899_state *state = fe->demodulator_priv;
  742. /*
  743. u8 reg;
  744. */
  745. dprintk(state->verbose, FE_DEBUG, 1, "Going to Sleep .. (Really tired .. :-))");
  746. /* post process event */
  747. stb0899_postproc(state, STB0899_POSTPROC_GPIO_POWER, 0);
  748. return 0;
  749. }
  750. static int stb0899_wakeup(struct dvb_frontend *fe)
  751. {
  752. int rc;
  753. struct stb0899_state *state = fe->demodulator_priv;
  754. if ((rc = stb0899_write_reg(state, STB0899_SYNTCTRL, STB0899_SELOSCI)))
  755. return rc;
  756. /* Activate all clocks; DVB-S2 registers are inaccessible otherwise. */
  757. if ((rc = stb0899_write_reg(state, STB0899_STOPCLK1, 0x00)))
  758. return rc;
  759. if ((rc = stb0899_write_reg(state, STB0899_STOPCLK2, 0x00)))
  760. return rc;
  761. /* post process event */
  762. stb0899_postproc(state, STB0899_POSTPROC_GPIO_POWER, 1);
  763. return 0;
  764. }
  765. static int stb0899_init(struct dvb_frontend *fe)
  766. {
  767. int i;
  768. struct stb0899_state *state = fe->demodulator_priv;
  769. struct stb0899_config *config = state->config;
  770. dprintk(state->verbose, FE_DEBUG, 1, "Initializing STB0899 ... ");
  771. /* init device */
  772. dprintk(state->verbose, FE_DEBUG, 1, "init device");
  773. for (i = 0; config->init_dev[i].address != 0xffff; i++)
  774. stb0899_write_reg(state, config->init_dev[i].address, config->init_dev[i].data);
  775. dprintk(state->verbose, FE_DEBUG, 1, "init S2 demod");
  776. /* init S2 demod */
  777. for (i = 0; config->init_s2_demod[i].offset != 0xffff; i++)
  778. stb0899_write_s2reg(state, STB0899_S2DEMOD,
  779. config->init_s2_demod[i].base_address,
  780. config->init_s2_demod[i].offset,
  781. config->init_s2_demod[i].data);
  782. dprintk(state->verbose, FE_DEBUG, 1, "init S1 demod");
  783. /* init S1 demod */
  784. for (i = 0; config->init_s1_demod[i].address != 0xffff; i++)
  785. stb0899_write_reg(state, config->init_s1_demod[i].address, config->init_s1_demod[i].data);
  786. dprintk(state->verbose, FE_DEBUG, 1, "init S2 FEC");
  787. /* init S2 fec */
  788. for (i = 0; config->init_s2_fec[i].offset != 0xffff; i++)
  789. stb0899_write_s2reg(state, STB0899_S2FEC,
  790. config->init_s2_fec[i].base_address,
  791. config->init_s2_fec[i].offset,
  792. config->init_s2_fec[i].data);
  793. dprintk(state->verbose, FE_DEBUG, 1, "init TST");
  794. /* init test */
  795. for (i = 0; config->init_tst[i].address != 0xffff; i++)
  796. stb0899_write_reg(state, config->init_tst[i].address, config->init_tst[i].data);
  797. stb0899_init_calc(state);
  798. stb0899_diseqc_init(state);
  799. return 0;
  800. }
  801. static int stb0899_table_lookup(const struct stb0899_tab *tab, int max, int val)
  802. {
  803. int res = 0;
  804. int min = 0, med;
  805. if (val < tab[min].read)
  806. res = tab[min].real;
  807. else if (val >= tab[max].read)
  808. res = tab[max].real;
  809. else {
  810. while ((max - min) > 1) {
  811. med = (max + min) / 2;
  812. if (val >= tab[min].read && val < tab[med].read)
  813. max = med;
  814. else
  815. min = med;
  816. }
  817. res = ((val - tab[min].read) *
  818. (tab[max].real - tab[min].real) /
  819. (tab[max].read - tab[min].read)) +
  820. tab[min].real;
  821. }
  822. return res;
  823. }
  824. static int stb0899_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  825. {
  826. struct stb0899_state *state = fe->demodulator_priv;
  827. struct stb0899_internal *internal = &state->internal;
  828. int val;
  829. u32 reg;
  830. switch (state->delsys) {
  831. case SYS_DVBS:
  832. case SYS_DSS:
  833. if (internal->lock) {
  834. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  835. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  836. reg = stb0899_read_reg(state, STB0899_AGCIQIN);
  837. val = (s32)(s8)STB0899_GETFIELD(AGCIQVALUE, reg);
  838. *strength = stb0899_table_lookup(stb0899_dvbsrf_tab, ARRAY_SIZE(stb0899_dvbsrf_tab) - 1, val);
  839. *strength += 750;
  840. dprintk(state->verbose, FE_DEBUG, 1, "AGCIQVALUE = 0x%02x, C = %d * 0.1 dBm",
  841. val & 0xff, *strength);
  842. }
  843. }
  844. break;
  845. case SYS_DVBS2:
  846. if (internal->lock) {
  847. reg = STB0899_READ_S2REG(STB0899_DEMOD, IF_AGC_GAIN);
  848. val = STB0899_GETFIELD(IF_AGC_GAIN, reg);
  849. *strength = stb0899_table_lookup(stb0899_dvbs2rf_tab, ARRAY_SIZE(stb0899_dvbs2rf_tab) - 1, val);
  850. *strength += 750;
  851. dprintk(state->verbose, FE_DEBUG, 1, "IF_AGC_GAIN = 0x%04x, C = %d * 0.1 dBm",
  852. val & 0x3fff, *strength);
  853. }
  854. break;
  855. default:
  856. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  857. return -EINVAL;
  858. }
  859. return 0;
  860. }
  861. static int stb0899_read_snr(struct dvb_frontend *fe, u16 *snr)
  862. {
  863. struct stb0899_state *state = fe->demodulator_priv;
  864. struct stb0899_internal *internal = &state->internal;
  865. unsigned int val, quant, quantn = -1, est, estn = -1;
  866. u8 buf[2];
  867. u32 reg;
  868. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  869. switch (state->delsys) {
  870. case SYS_DVBS:
  871. case SYS_DSS:
  872. if (internal->lock) {
  873. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  874. stb0899_read_regs(state, STB0899_NIRM, buf, 2);
  875. val = MAKEWORD16(buf[0], buf[1]);
  876. *snr = stb0899_table_lookup(stb0899_cn_tab, ARRAY_SIZE(stb0899_cn_tab) - 1, val);
  877. dprintk(state->verbose, FE_DEBUG, 1, "NIR = 0x%02x%02x = %u, C/N = %d * 0.1 dBm\n",
  878. buf[0], buf[1], val, *snr);
  879. }
  880. }
  881. break;
  882. case SYS_DVBS2:
  883. if (internal->lock) {
  884. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, UWP_CNTRL1);
  885. quant = STB0899_GETFIELD(UWP_ESN0_QUANT, reg);
  886. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, UWP_STAT2);
  887. est = STB0899_GETFIELD(ESN0_EST, reg);
  888. if (est == 1)
  889. val = 301; /* C/N = 30.1 dB */
  890. else if (est == 2)
  891. val = 270; /* C/N = 27.0 dB */
  892. else {
  893. /* quantn = 100 * log(quant^2) */
  894. quantn = stb0899_table_lookup(stb0899_quant_tab, ARRAY_SIZE(stb0899_quant_tab) - 1, quant * 100);
  895. /* estn = 100 * log(est) */
  896. estn = stb0899_table_lookup(stb0899_est_tab, ARRAY_SIZE(stb0899_est_tab) - 1, est);
  897. /* snr(dBm/10) = -10*(log(est)-log(quant^2)) => snr(dBm/10) = (100*log(quant^2)-100*log(est))/10 */
  898. val = (quantn - estn) / 10;
  899. }
  900. *snr = val;
  901. dprintk(state->verbose, FE_DEBUG, 1, "Es/N0 quant = %d (%d) estimate = %u (%d), C/N = %d * 0.1 dBm",
  902. quant, quantn, est, estn, val);
  903. }
  904. break;
  905. default:
  906. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  907. return -EINVAL;
  908. }
  909. return 0;
  910. }
  911. static int stb0899_read_status(struct dvb_frontend *fe, enum fe_status *status)
  912. {
  913. struct stb0899_state *state = fe->demodulator_priv;
  914. struct stb0899_internal *internal = &state->internal;
  915. u8 reg;
  916. *status = 0;
  917. switch (state->delsys) {
  918. case SYS_DVBS:
  919. case SYS_DSS:
  920. dprintk(state->verbose, FE_DEBUG, 1, "Delivery system DVB-S/DSS");
  921. if (internal->lock) {
  922. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  923. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  924. dprintk(state->verbose, FE_DEBUG, 1, "--------> FE_HAS_CARRIER | FE_HAS_LOCK");
  925. *status |= FE_HAS_CARRIER | FE_HAS_LOCK;
  926. reg = stb0899_read_reg(state, STB0899_PLPARM);
  927. if (STB0899_GETFIELD(VITCURPUN, reg)) {
  928. dprintk(state->verbose, FE_DEBUG, 1, "--------> FE_HAS_VITERBI | FE_HAS_SYNC");
  929. *status |= FE_HAS_VITERBI | FE_HAS_SYNC;
  930. /* post process event */
  931. stb0899_postproc(state, STB0899_POSTPROC_GPIO_LOCK, 1);
  932. }
  933. }
  934. }
  935. break;
  936. case SYS_DVBS2:
  937. dprintk(state->verbose, FE_DEBUG, 1, "Delivery system DVB-S2");
  938. if (internal->lock) {
  939. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_STAT2);
  940. if (STB0899_GETFIELD(UWP_LOCK, reg) && STB0899_GETFIELD(CSM_LOCK, reg)) {
  941. *status |= FE_HAS_CARRIER;
  942. dprintk(state->verbose, FE_DEBUG, 1,
  943. "UWP & CSM Lock ! ---> DVB-S2 FE_HAS_CARRIER");
  944. reg = stb0899_read_reg(state, STB0899_CFGPDELSTATUS1);
  945. if (STB0899_GETFIELD(CFGPDELSTATUS_LOCK, reg)) {
  946. *status |= FE_HAS_LOCK;
  947. dprintk(state->verbose, FE_DEBUG, 1,
  948. "Packet Delineator Locked ! -----> DVB-S2 FE_HAS_LOCK");
  949. }
  950. if (STB0899_GETFIELD(CONTINUOUS_STREAM, reg)) {
  951. *status |= FE_HAS_VITERBI;
  952. dprintk(state->verbose, FE_DEBUG, 1,
  953. "Packet Delineator found VITERBI ! -----> DVB-S2 FE_HAS_VITERBI");
  954. }
  955. if (STB0899_GETFIELD(ACCEPTED_STREAM, reg)) {
  956. *status |= FE_HAS_SYNC;
  957. dprintk(state->verbose, FE_DEBUG, 1,
  958. "Packet Delineator found SYNC ! -----> DVB-S2 FE_HAS_SYNC");
  959. /* post process event */
  960. stb0899_postproc(state, STB0899_POSTPROC_GPIO_LOCK, 1);
  961. }
  962. }
  963. }
  964. break;
  965. default:
  966. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  967. return -EINVAL;
  968. }
  969. return 0;
  970. }
  971. /*
  972. * stb0899_get_error
  973. * viterbi error for DVB-S/DSS
  974. * packet error for DVB-S2
  975. * Bit Error Rate or Packet Error Rate * 10 ^ 7
  976. */
  977. static int stb0899_read_ber(struct dvb_frontend *fe, u32 *ber)
  978. {
  979. struct stb0899_state *state = fe->demodulator_priv;
  980. struct stb0899_internal *internal = &state->internal;
  981. u8 lsb, msb;
  982. u32 i;
  983. *ber = 0;
  984. switch (state->delsys) {
  985. case SYS_DVBS:
  986. case SYS_DSS:
  987. if (internal->lock) {
  988. /* average 5 BER values */
  989. for (i = 0; i < 5; i++) {
  990. msleep(100);
  991. lsb = stb0899_read_reg(state, STB0899_ECNT1L);
  992. msb = stb0899_read_reg(state, STB0899_ECNT1M);
  993. *ber += MAKEWORD16(msb, lsb);
  994. }
  995. *ber /= 5;
  996. /* Viterbi Check */
  997. if (STB0899_GETFIELD(VSTATUS_PRFVIT, internal->v_status)) {
  998. /* Error Rate */
  999. *ber *= 9766;
  1000. /* ber = ber * 10 ^ 7 */
  1001. *ber /= (-1 + (1 << (2 * STB0899_GETFIELD(NOE, internal->err_ctrl))));
  1002. *ber /= 8;
  1003. }
  1004. }
  1005. break;
  1006. case SYS_DVBS2:
  1007. if (internal->lock) {
  1008. /* Average 5 PER values */
  1009. for (i = 0; i < 5; i++) {
  1010. msleep(100);
  1011. lsb = stb0899_read_reg(state, STB0899_ECNT1L);
  1012. msb = stb0899_read_reg(state, STB0899_ECNT1M);
  1013. *ber += MAKEWORD16(msb, lsb);
  1014. }
  1015. /* ber = ber * 10 ^ 7 */
  1016. *ber *= 10000000;
  1017. *ber /= (-1 + (1 << (4 + 2 * STB0899_GETFIELD(NOE, internal->err_ctrl))));
  1018. }
  1019. break;
  1020. default:
  1021. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  1022. return -EINVAL;
  1023. }
  1024. return 0;
  1025. }
  1026. static int stb0899_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  1027. {
  1028. struct stb0899_state *state = fe->demodulator_priv;
  1029. switch (voltage) {
  1030. case SEC_VOLTAGE_13:
  1031. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x82);
  1032. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x02);
  1033. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x00);
  1034. break;
  1035. case SEC_VOLTAGE_18:
  1036. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x02);
  1037. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x02);
  1038. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x82);
  1039. break;
  1040. case SEC_VOLTAGE_OFF:
  1041. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x82);
  1042. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x82);
  1043. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x82);
  1044. break;
  1045. default:
  1046. return -EINVAL;
  1047. }
  1048. return 0;
  1049. }
  1050. static int stb0899_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
  1051. {
  1052. struct stb0899_state *state = fe->demodulator_priv;
  1053. struct stb0899_internal *internal = &state->internal;
  1054. u8 div, reg;
  1055. /* wait for diseqc idle */
  1056. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  1057. return -ETIMEDOUT;
  1058. switch (tone) {
  1059. case SEC_TONE_ON:
  1060. div = (internal->master_clk / 100) / 5632;
  1061. div = (div + 5) / 10;
  1062. stb0899_write_reg(state, STB0899_DISEQCOCFG, 0x66);
  1063. reg = stb0899_read_reg(state, STB0899_ACRPRESC);
  1064. STB0899_SETFIELD_VAL(ACRPRESC, reg, 0x03);
  1065. stb0899_write_reg(state, STB0899_ACRPRESC, reg);
  1066. stb0899_write_reg(state, STB0899_ACRDIV1, div);
  1067. break;
  1068. case SEC_TONE_OFF:
  1069. stb0899_write_reg(state, STB0899_DISEQCOCFG, 0x20);
  1070. break;
  1071. default:
  1072. return -EINVAL;
  1073. }
  1074. return 0;
  1075. }
  1076. int stb0899_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  1077. {
  1078. int i2c_stat;
  1079. struct stb0899_state *state = fe->demodulator_priv;
  1080. i2c_stat = stb0899_read_reg(state, STB0899_I2CRPT);
  1081. if (i2c_stat < 0)
  1082. goto err;
  1083. if (enable) {
  1084. dprintk(state->verbose, FE_DEBUG, 1, "Enabling I2C Repeater ...");
  1085. i2c_stat |= STB0899_I2CTON;
  1086. if (stb0899_write_reg(state, STB0899_I2CRPT, i2c_stat) < 0)
  1087. goto err;
  1088. } else {
  1089. dprintk(state->verbose, FE_DEBUG, 1, "Disabling I2C Repeater ...");
  1090. i2c_stat &= ~STB0899_I2CTON;
  1091. if (stb0899_write_reg(state, STB0899_I2CRPT, i2c_stat) < 0)
  1092. goto err;
  1093. }
  1094. return 0;
  1095. err:
  1096. dprintk(state->verbose, FE_ERROR, 1, "I2C Repeater control failed");
  1097. return -EREMOTEIO;
  1098. }
  1099. static inline void CONVERT32(u32 x, char *str)
  1100. {
  1101. *str++ = (x >> 24) & 0xff;
  1102. *str++ = (x >> 16) & 0xff;
  1103. *str++ = (x >> 8) & 0xff;
  1104. *str++ = (x >> 0) & 0xff;
  1105. *str = '\0';
  1106. }
  1107. int stb0899_get_dev_id(struct stb0899_state *state)
  1108. {
  1109. u8 chip_id, release;
  1110. u16 id;
  1111. u32 demod_ver = 0, fec_ver = 0;
  1112. char demod_str[5] = { 0 };
  1113. char fec_str[5] = { 0 };
  1114. id = stb0899_read_reg(state, STB0899_DEV_ID);
  1115. dprintk(state->verbose, FE_DEBUG, 1, "ID reg=[0x%02x]", id);
  1116. chip_id = STB0899_GETFIELD(CHIP_ID, id);
  1117. release = STB0899_GETFIELD(CHIP_REL, id);
  1118. dprintk(state->verbose, FE_ERROR, 1, "Device ID=[%d], Release=[%d]",
  1119. chip_id, release);
  1120. CONVERT32(STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_CORE_ID), (char *)&demod_str);
  1121. demod_ver = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_VERSION_ID);
  1122. dprintk(state->verbose, FE_ERROR, 1, "Demodulator Core ID=[%s], Version=[%d]", (char *) &demod_str, demod_ver);
  1123. CONVERT32(STB0899_READ_S2REG(STB0899_S2FEC, FEC_CORE_ID_REG), (char *)&fec_str);
  1124. fec_ver = STB0899_READ_S2REG(STB0899_S2FEC, FEC_VER_ID_REG);
  1125. if (! (chip_id > 0)) {
  1126. dprintk(state->verbose, FE_ERROR, 1, "couldn't find a STB 0899");
  1127. return -ENODEV;
  1128. }
  1129. dprintk(state->verbose, FE_ERROR, 1, "FEC Core ID=[%s], Version=[%d]", (char*) &fec_str, fec_ver);
  1130. return 0;
  1131. }
  1132. static void stb0899_set_delivery(struct stb0899_state *state)
  1133. {
  1134. u8 reg;
  1135. u8 stop_clk[2];
  1136. stop_clk[0] = stb0899_read_reg(state, STB0899_STOPCLK1);
  1137. stop_clk[1] = stb0899_read_reg(state, STB0899_STOPCLK2);
  1138. switch (state->delsys) {
  1139. case SYS_DVBS:
  1140. dprintk(state->verbose, FE_DEBUG, 1, "Delivery System -- DVB-S");
  1141. /* FECM/Viterbi ON */
  1142. reg = stb0899_read_reg(state, STB0899_FECM);
  1143. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 0);
  1144. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 1);
  1145. stb0899_write_reg(state, STB0899_FECM, reg);
  1146. stb0899_write_reg(state, STB0899_RSULC, 0xb1);
  1147. stb0899_write_reg(state, STB0899_TSULC, 0x40);
  1148. stb0899_write_reg(state, STB0899_RSLLC, 0x42);
  1149. stb0899_write_reg(state, STB0899_TSLPL, 0x12);
  1150. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1151. STB0899_SETFIELD_VAL(FRESLDPC, reg, 1);
  1152. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1153. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1154. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 1);
  1155. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 1);
  1156. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 1);
  1157. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 1);
  1158. STB0899_SETFIELD_VAL(STOP_CKINTBUF216, stop_clk[0], 1);
  1159. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1160. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 1);
  1161. break;
  1162. case SYS_DVBS2:
  1163. /* FECM/Viterbi OFF */
  1164. reg = stb0899_read_reg(state, STB0899_FECM);
  1165. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 0);
  1166. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 0);
  1167. stb0899_write_reg(state, STB0899_FECM, reg);
  1168. stb0899_write_reg(state, STB0899_RSULC, 0xb1);
  1169. stb0899_write_reg(state, STB0899_TSULC, 0x42);
  1170. stb0899_write_reg(state, STB0899_RSLLC, 0x40);
  1171. stb0899_write_reg(state, STB0899_TSLPL, 0x02);
  1172. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1173. STB0899_SETFIELD_VAL(FRESLDPC, reg, 0);
  1174. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1175. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1176. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 0);
  1177. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 0);
  1178. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 0);
  1179. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 0);
  1180. STB0899_SETFIELD_VAL(STOP_CKINTBUF216, stop_clk[0], 0);
  1181. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1182. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 0);
  1183. break;
  1184. case SYS_DSS:
  1185. /* FECM/Viterbi ON */
  1186. reg = stb0899_read_reg(state, STB0899_FECM);
  1187. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 1);
  1188. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 1);
  1189. stb0899_write_reg(state, STB0899_FECM, reg);
  1190. stb0899_write_reg(state, STB0899_RSULC, 0xa1);
  1191. stb0899_write_reg(state, STB0899_TSULC, 0x61);
  1192. stb0899_write_reg(state, STB0899_RSLLC, 0x42);
  1193. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1194. STB0899_SETFIELD_VAL(FRESLDPC, reg, 1);
  1195. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1196. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1197. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 1);
  1198. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 1);
  1199. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 1);
  1200. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 1);
  1201. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1202. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 1);
  1203. break;
  1204. default:
  1205. dprintk(state->verbose, FE_ERROR, 1, "Unsupported delivery system");
  1206. break;
  1207. }
  1208. STB0899_SETFIELD_VAL(STOP_CKADCI108, stop_clk[0], 0);
  1209. stb0899_write_regs(state, STB0899_STOPCLK1, stop_clk, 2);
  1210. }
  1211. /*
  1212. * stb0899_set_iterations
  1213. * set the LDPC iteration scale function
  1214. */
  1215. static void stb0899_set_iterations(struct stb0899_state *state)
  1216. {
  1217. struct stb0899_internal *internal = &state->internal;
  1218. struct stb0899_config *config = state->config;
  1219. s32 iter_scale;
  1220. u32 reg;
  1221. iter_scale = 17 * (internal->master_clk / 1000);
  1222. iter_scale += 410000;
  1223. iter_scale /= (internal->srate / 1000000);
  1224. iter_scale /= 1000;
  1225. if (iter_scale > config->ldpc_max_iter)
  1226. iter_scale = config->ldpc_max_iter;
  1227. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, MAX_ITER);
  1228. STB0899_SETFIELD_VAL(MAX_ITERATIONS, reg, iter_scale);
  1229. stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_MAX_ITER, STB0899_OFF0_MAX_ITER, reg);
  1230. }
  1231. static enum dvbfe_search stb0899_search(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1232. {
  1233. struct stb0899_state *state = fe->demodulator_priv;
  1234. struct stb0899_params *i_params = &state->params;
  1235. struct stb0899_internal *internal = &state->internal;
  1236. struct stb0899_config *config = state->config;
  1237. struct dtv_frontend_properties *props = &fe->dtv_property_cache;
  1238. u32 SearchRange, gain;
  1239. i_params->freq = p->frequency;
  1240. i_params->srate = p->u.qpsk.symbol_rate;
  1241. state->delsys = props->delivery_system;
  1242. dprintk(state->verbose, FE_DEBUG, 1, "delivery system=%d", state->delsys);
  1243. SearchRange = 10000000;
  1244. dprintk(state->verbose, FE_DEBUG, 1, "Frequency=%d, Srate=%d", i_params->freq, i_params->srate);
  1245. /* checking Search Range is meaningless for a fixed 3 Mhz */
  1246. if (INRANGE(i_params->srate, 1000000, 45000000)) {
  1247. dprintk(state->verbose, FE_DEBUG, 1, "Parameters IN RANGE");
  1248. stb0899_set_delivery(state);
  1249. if (state->config->tuner_set_rfsiggain) {
  1250. if (internal->srate > 15000000)
  1251. gain = 8; /* 15Mb < srate < 45Mb, gain = 8dB */
  1252. else if (internal->srate > 5000000)
  1253. gain = 12; /* 5Mb < srate < 15Mb, gain = 12dB */
  1254. else
  1255. gain = 14; /* 1Mb < srate < 5Mb, gain = 14db */
  1256. state->config->tuner_set_rfsiggain(fe, gain);
  1257. }
  1258. if (i_params->srate <= 5000000)
  1259. stb0899_set_mclk(state, config->lo_clk);
  1260. else
  1261. stb0899_set_mclk(state, config->hi_clk);
  1262. switch (state->delsys) {
  1263. case SYS_DVBS:
  1264. case SYS_DSS:
  1265. dprintk(state->verbose, FE_DEBUG, 1, "DVB-S delivery system");
  1266. internal->freq = i_params->freq;
  1267. internal->srate = i_params->srate;
  1268. /*
  1269. * search = user search range +
  1270. * 500Khz +
  1271. * 2 * Tuner_step_size +
  1272. * 10% of the symbol rate
  1273. */
  1274. internal->srch_range = SearchRange + 1500000 + (i_params->srate / 5);
  1275. internal->derot_percent = 30;
  1276. /* What to do for tuners having no bandwidth setup ? */
  1277. /* enable tuner I/O */
  1278. stb0899_i2c_gate_ctrl(&state->frontend, 1);
  1279. if (state->config->tuner_set_bandwidth)
  1280. state->config->tuner_set_bandwidth(fe, (13 * (stb0899_carr_width(state) + SearchRange)) / 10);
  1281. if (state->config->tuner_get_bandwidth)
  1282. state->config->tuner_get_bandwidth(fe, &internal->tuner_bw);
  1283. /* disable tuner I/O */
  1284. stb0899_i2c_gate_ctrl(&state->frontend, 0);
  1285. /* Set DVB-S1 AGC */
  1286. stb0899_write_reg(state, STB0899_AGCRFCFG, 0x11);
  1287. /* Run the search algorithm */
  1288. dprintk(state->verbose, FE_DEBUG, 1, "running DVB-S search algo ..");
  1289. if (stb0899_dvbs_algo(state) == RANGEOK) {
  1290. internal->lock = 1;
  1291. dprintk(state->verbose, FE_DEBUG, 1,
  1292. "-------------------------------------> DVB-S LOCK !");
  1293. // stb0899_write_reg(state, STB0899_ERRCTRL1, 0x3d); /* Viterbi Errors */
  1294. // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
  1295. // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
  1296. // dprintk(state->verbose, FE_DEBUG, 1, "VSTATUS=0x%02x", internal->v_status);
  1297. // dprintk(state->verbose, FE_DEBUG, 1, "ERR_CTRL=0x%02x", internal->err_ctrl);
  1298. return DVBFE_ALGO_SEARCH_SUCCESS;
  1299. } else {
  1300. internal->lock = 0;
  1301. return DVBFE_ALGO_SEARCH_FAILED;
  1302. }
  1303. break;
  1304. case SYS_DVBS2:
  1305. internal->freq = i_params->freq;
  1306. internal->srate = i_params->srate;
  1307. internal->srch_range = SearchRange;
  1308. /* enable tuner I/O */
  1309. stb0899_i2c_gate_ctrl(&state->frontend, 1);
  1310. if (state->config->tuner_set_bandwidth)
  1311. state->config->tuner_set_bandwidth(fe, (stb0899_carr_width(state) + SearchRange));
  1312. if (state->config->tuner_get_bandwidth)
  1313. state->config->tuner_get_bandwidth(fe, &internal->tuner_bw);
  1314. /* disable tuner I/O */
  1315. stb0899_i2c_gate_ctrl(&state->frontend, 0);
  1316. // pParams->SpectralInv = pSearch->IQ_Inversion;
  1317. /* Set DVB-S2 AGC */
  1318. stb0899_write_reg(state, STB0899_AGCRFCFG, 0x1c);
  1319. /* Set IterScale =f(MCLK,SYMB) */
  1320. stb0899_set_iterations(state);
  1321. /* Run the search algorithm */
  1322. dprintk(state->verbose, FE_DEBUG, 1, "running DVB-S2 search algo ..");
  1323. if (stb0899_dvbs2_algo(state) == DVBS2_FEC_LOCK) {
  1324. internal->lock = 1;
  1325. dprintk(state->verbose, FE_DEBUG, 1,
  1326. "-------------------------------------> DVB-S2 LOCK !");
  1327. // stb0899_write_reg(state, STB0899_ERRCTRL1, 0xb6); /* Packet Errors */
  1328. // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
  1329. // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
  1330. return DVBFE_ALGO_SEARCH_SUCCESS;
  1331. } else {
  1332. internal->lock = 0;
  1333. return DVBFE_ALGO_SEARCH_FAILED;
  1334. }
  1335. break;
  1336. default:
  1337. dprintk(state->verbose, FE_ERROR, 1, "Unsupported delivery system");
  1338. return DVBFE_ALGO_SEARCH_INVALID;
  1339. }
  1340. }
  1341. return DVBFE_ALGO_SEARCH_ERROR;
  1342. }
  1343. /*
  1344. * stb0899_track
  1345. * periodically check the signal level against a specified
  1346. * threshold level and perform derotator centering.
  1347. * called once we have a lock from a succesful search
  1348. * event.
  1349. *
  1350. * Will be called periodically called to maintain the
  1351. * lock.
  1352. *
  1353. * Will be used to get parameters as well as info from
  1354. * the decoded baseband header
  1355. *
  1356. * Once a new lock has established, the internal state
  1357. * frequency (internal->freq) is updated
  1358. */
  1359. static int stb0899_track(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1360. {
  1361. return 0;
  1362. }
  1363. static int stb0899_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1364. {
  1365. struct stb0899_state *state = fe->demodulator_priv;
  1366. struct stb0899_internal *internal = &state->internal;
  1367. dprintk(state->verbose, FE_DEBUG, 1, "Get params");
  1368. p->u.qpsk.symbol_rate = internal->srate;
  1369. return 0;
  1370. }
  1371. static enum dvbfe_algo stb0899_frontend_algo(struct dvb_frontend *fe)
  1372. {
  1373. return DVBFE_ALGO_CUSTOM;
  1374. }
  1375. static struct dvb_frontend_ops stb0899_ops = {
  1376. .info = {
  1377. .name = "STB0899 Multistandard",
  1378. .type = FE_QPSK,
  1379. .frequency_min = 950000,
  1380. .frequency_max = 2150000,
  1381. .frequency_stepsize = 0,
  1382. .frequency_tolerance = 0,
  1383. .symbol_rate_min = 5000000,
  1384. .symbol_rate_max = 45000000,
  1385. .caps = FE_CAN_INVERSION_AUTO |
  1386. FE_CAN_FEC_AUTO |
  1387. FE_CAN_2G_MODULATION |
  1388. FE_CAN_QPSK
  1389. },
  1390. .release = stb0899_release,
  1391. .init = stb0899_init,
  1392. .sleep = stb0899_sleep,
  1393. // .wakeup = stb0899_wakeup,
  1394. .i2c_gate_ctrl = stb0899_i2c_gate_ctrl,
  1395. .get_frontend_algo = stb0899_frontend_algo,
  1396. .search = stb0899_search,
  1397. .track = stb0899_track,
  1398. .get_frontend = stb0899_get_frontend,
  1399. .read_status = stb0899_read_status,
  1400. .read_snr = stb0899_read_snr,
  1401. .read_signal_strength = stb0899_read_signal_strength,
  1402. .read_ber = stb0899_read_ber,
  1403. .set_voltage = stb0899_set_voltage,
  1404. .set_tone = stb0899_set_tone,
  1405. .diseqc_send_master_cmd = stb0899_send_diseqc_msg,
  1406. .diseqc_recv_slave_reply = stb0899_recv_slave_reply,
  1407. .diseqc_send_burst = stb0899_send_diseqc_burst,
  1408. };
  1409. struct dvb_frontend *stb0899_attach(struct stb0899_config *config, struct i2c_adapter *i2c)
  1410. {
  1411. struct stb0899_state *state = NULL;
  1412. enum stb0899_inversion inversion;
  1413. state = kzalloc(sizeof (struct stb0899_state), GFP_KERNEL);
  1414. if (state == NULL)
  1415. goto error;
  1416. inversion = config->inversion;
  1417. state->verbose = &verbose;
  1418. state->config = config;
  1419. state->i2c = i2c;
  1420. state->frontend.ops = stb0899_ops;
  1421. state->frontend.demodulator_priv = state;
  1422. state->internal.inversion = inversion;
  1423. stb0899_wakeup(&state->frontend);
  1424. if (stb0899_get_dev_id(state) == -ENODEV) {
  1425. printk("%s: Exiting .. !\n", __func__);
  1426. goto error;
  1427. }
  1428. printk("%s: Attaching STB0899 \n", __func__);
  1429. return &state->frontend;
  1430. error:
  1431. kfree(state);
  1432. return NULL;
  1433. }
  1434. EXPORT_SYMBOL(stb0899_attach);
  1435. MODULE_PARM_DESC(verbose, "Set Verbosity level");
  1436. MODULE_AUTHOR("Manu Abraham");
  1437. MODULE_DESCRIPTION("STB0899 Multi-Std frontend");
  1438. MODULE_LICENSE("GPL");