stb0899_drv.c 45 KB

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