cxd2841er.c 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731
  1. /*
  2. * cxd2841er.c
  3. *
  4. * Sony CXD2441ER digital demodulator driver
  5. *
  6. * Copyright 2012 Sony Corporation
  7. * Copyright (C) 2014 NetUP Inc.
  8. * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru>
  9. * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/string.h>
  24. #include <linux/slab.h>
  25. #include <linux/bitops.h>
  26. #include <linux/math64.h>
  27. #include <linux/log2.h>
  28. #include <linux/dynamic_debug.h>
  29. #include "dvb_math.h"
  30. #include "dvb_frontend.h"
  31. #include "cxd2841er.h"
  32. #include "cxd2841er_priv.h"
  33. #define MAX_WRITE_REGSIZE 16
  34. enum cxd2841er_state {
  35. STATE_SHUTDOWN = 0,
  36. STATE_SLEEP_S,
  37. STATE_ACTIVE_S,
  38. STATE_SLEEP_TC,
  39. STATE_ACTIVE_TC
  40. };
  41. struct cxd2841er_priv {
  42. struct dvb_frontend frontend;
  43. struct i2c_adapter *i2c;
  44. u8 i2c_addr_slvx;
  45. u8 i2c_addr_slvt;
  46. const struct cxd2841er_config *config;
  47. enum cxd2841er_state state;
  48. u8 system;
  49. };
  50. static const struct cxd2841er_cnr_data s_cn_data[] = {
  51. { 0x033e, 0 }, { 0x0339, 100 }, { 0x0333, 200 },
  52. { 0x032e, 300 }, { 0x0329, 400 }, { 0x0324, 500 },
  53. { 0x031e, 600 }, { 0x0319, 700 }, { 0x0314, 800 },
  54. { 0x030f, 900 }, { 0x030a, 1000 }, { 0x02ff, 1100 },
  55. { 0x02f4, 1200 }, { 0x02e9, 1300 }, { 0x02de, 1400 },
  56. { 0x02d4, 1500 }, { 0x02c9, 1600 }, { 0x02bf, 1700 },
  57. { 0x02b5, 1800 }, { 0x02ab, 1900 }, { 0x02a1, 2000 },
  58. { 0x029b, 2100 }, { 0x0295, 2200 }, { 0x0290, 2300 },
  59. { 0x028a, 2400 }, { 0x0284, 2500 }, { 0x027f, 2600 },
  60. { 0x0279, 2700 }, { 0x0274, 2800 }, { 0x026e, 2900 },
  61. { 0x0269, 3000 }, { 0x0262, 3100 }, { 0x025c, 3200 },
  62. { 0x0255, 3300 }, { 0x024f, 3400 }, { 0x0249, 3500 },
  63. { 0x0242, 3600 }, { 0x023c, 3700 }, { 0x0236, 3800 },
  64. { 0x0230, 3900 }, { 0x022a, 4000 }, { 0x0223, 4100 },
  65. { 0x021c, 4200 }, { 0x0215, 4300 }, { 0x020e, 4400 },
  66. { 0x0207, 4500 }, { 0x0201, 4600 }, { 0x01fa, 4700 },
  67. { 0x01f4, 4800 }, { 0x01ed, 4900 }, { 0x01e7, 5000 },
  68. { 0x01e0, 5100 }, { 0x01d9, 5200 }, { 0x01d2, 5300 },
  69. { 0x01cb, 5400 }, { 0x01c4, 5500 }, { 0x01be, 5600 },
  70. { 0x01b7, 5700 }, { 0x01b1, 5800 }, { 0x01aa, 5900 },
  71. { 0x01a4, 6000 }, { 0x019d, 6100 }, { 0x0196, 6200 },
  72. { 0x018f, 6300 }, { 0x0189, 6400 }, { 0x0182, 6500 },
  73. { 0x017c, 6600 }, { 0x0175, 6700 }, { 0x016f, 6800 },
  74. { 0x0169, 6900 }, { 0x0163, 7000 }, { 0x015c, 7100 },
  75. { 0x0156, 7200 }, { 0x0150, 7300 }, { 0x014a, 7400 },
  76. { 0x0144, 7500 }, { 0x013e, 7600 }, { 0x0138, 7700 },
  77. { 0x0132, 7800 }, { 0x012d, 7900 }, { 0x0127, 8000 },
  78. { 0x0121, 8100 }, { 0x011c, 8200 }, { 0x0116, 8300 },
  79. { 0x0111, 8400 }, { 0x010b, 8500 }, { 0x0106, 8600 },
  80. { 0x0101, 8700 }, { 0x00fc, 8800 }, { 0x00f7, 8900 },
  81. { 0x00f2, 9000 }, { 0x00ee, 9100 }, { 0x00ea, 9200 },
  82. { 0x00e6, 9300 }, { 0x00e2, 9400 }, { 0x00de, 9500 },
  83. { 0x00da, 9600 }, { 0x00d7, 9700 }, { 0x00d3, 9800 },
  84. { 0x00d0, 9900 }, { 0x00cc, 10000 }, { 0x00c7, 10100 },
  85. { 0x00c3, 10200 }, { 0x00bf, 10300 }, { 0x00ba, 10400 },
  86. { 0x00b6, 10500 }, { 0x00b2, 10600 }, { 0x00ae, 10700 },
  87. { 0x00aa, 10800 }, { 0x00a7, 10900 }, { 0x00a3, 11000 },
  88. { 0x009f, 11100 }, { 0x009c, 11200 }, { 0x0098, 11300 },
  89. { 0x0094, 11400 }, { 0x0091, 11500 }, { 0x008e, 11600 },
  90. { 0x008a, 11700 }, { 0x0087, 11800 }, { 0x0084, 11900 },
  91. { 0x0081, 12000 }, { 0x007e, 12100 }, { 0x007b, 12200 },
  92. { 0x0079, 12300 }, { 0x0076, 12400 }, { 0x0073, 12500 },
  93. { 0x0071, 12600 }, { 0x006e, 12700 }, { 0x006c, 12800 },
  94. { 0x0069, 12900 }, { 0x0067, 13000 }, { 0x0065, 13100 },
  95. { 0x0062, 13200 }, { 0x0060, 13300 }, { 0x005e, 13400 },
  96. { 0x005c, 13500 }, { 0x005a, 13600 }, { 0x0058, 13700 },
  97. { 0x0056, 13800 }, { 0x0054, 13900 }, { 0x0052, 14000 },
  98. { 0x0050, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 },
  99. { 0x004b, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 },
  100. { 0x0046, 14700 }, { 0x0044, 14800 }, { 0x0043, 14900 },
  101. { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 },
  102. { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 },
  103. { 0x0037, 15700 }, { 0x0036, 15800 }, { 0x0034, 15900 },
  104. { 0x0033, 16000 }, { 0x0032, 16100 }, { 0x0031, 16200 },
  105. { 0x0030, 16300 }, { 0x002f, 16400 }, { 0x002e, 16500 },
  106. { 0x002d, 16600 }, { 0x002c, 16700 }, { 0x002b, 16800 },
  107. { 0x002a, 16900 }, { 0x0029, 17000 }, { 0x0028, 17100 },
  108. { 0x0027, 17200 }, { 0x0026, 17300 }, { 0x0025, 17400 },
  109. { 0x0024, 17500 }, { 0x0023, 17600 }, { 0x0022, 17800 },
  110. { 0x0021, 17900 }, { 0x0020, 18000 }, { 0x001f, 18200 },
  111. { 0x001e, 18300 }, { 0x001d, 18500 }, { 0x001c, 18700 },
  112. { 0x001b, 18900 }, { 0x001a, 19000 }, { 0x0019, 19200 },
  113. { 0x0018, 19300 }, { 0x0017, 19500 }, { 0x0016, 19700 },
  114. { 0x0015, 19900 }, { 0x0014, 20000 },
  115. };
  116. static const struct cxd2841er_cnr_data s2_cn_data[] = {
  117. { 0x05af, 0 }, { 0x0597, 100 }, { 0x057e, 200 },
  118. { 0x0567, 300 }, { 0x0550, 400 }, { 0x0539, 500 },
  119. { 0x0522, 600 }, { 0x050c, 700 }, { 0x04f6, 800 },
  120. { 0x04e1, 900 }, { 0x04cc, 1000 }, { 0x04b6, 1100 },
  121. { 0x04a1, 1200 }, { 0x048c, 1300 }, { 0x0477, 1400 },
  122. { 0x0463, 1500 }, { 0x044f, 1600 }, { 0x043c, 1700 },
  123. { 0x0428, 1800 }, { 0x0416, 1900 }, { 0x0403, 2000 },
  124. { 0x03ef, 2100 }, { 0x03dc, 2200 }, { 0x03c9, 2300 },
  125. { 0x03b6, 2400 }, { 0x03a4, 2500 }, { 0x0392, 2600 },
  126. { 0x0381, 2700 }, { 0x036f, 2800 }, { 0x035f, 2900 },
  127. { 0x034e, 3000 }, { 0x033d, 3100 }, { 0x032d, 3200 },
  128. { 0x031d, 3300 }, { 0x030d, 3400 }, { 0x02fd, 3500 },
  129. { 0x02ee, 3600 }, { 0x02df, 3700 }, { 0x02d0, 3800 },
  130. { 0x02c2, 3900 }, { 0x02b4, 4000 }, { 0x02a6, 4100 },
  131. { 0x0299, 4200 }, { 0x028c, 4300 }, { 0x027f, 4400 },
  132. { 0x0272, 4500 }, { 0x0265, 4600 }, { 0x0259, 4700 },
  133. { 0x024d, 4800 }, { 0x0241, 4900 }, { 0x0236, 5000 },
  134. { 0x022b, 5100 }, { 0x0220, 5200 }, { 0x0215, 5300 },
  135. { 0x020a, 5400 }, { 0x0200, 5500 }, { 0x01f6, 5600 },
  136. { 0x01ec, 5700 }, { 0x01e2, 5800 }, { 0x01d8, 5900 },
  137. { 0x01cf, 6000 }, { 0x01c6, 6100 }, { 0x01bc, 6200 },
  138. { 0x01b3, 6300 }, { 0x01aa, 6400 }, { 0x01a2, 6500 },
  139. { 0x0199, 6600 }, { 0x0191, 6700 }, { 0x0189, 6800 },
  140. { 0x0181, 6900 }, { 0x0179, 7000 }, { 0x0171, 7100 },
  141. { 0x0169, 7200 }, { 0x0161, 7300 }, { 0x015a, 7400 },
  142. { 0x0153, 7500 }, { 0x014b, 7600 }, { 0x0144, 7700 },
  143. { 0x013d, 7800 }, { 0x0137, 7900 }, { 0x0130, 8000 },
  144. { 0x012a, 8100 }, { 0x0124, 8200 }, { 0x011e, 8300 },
  145. { 0x0118, 8400 }, { 0x0112, 8500 }, { 0x010c, 8600 },
  146. { 0x0107, 8700 }, { 0x0101, 8800 }, { 0x00fc, 8900 },
  147. { 0x00f7, 9000 }, { 0x00f2, 9100 }, { 0x00ec, 9200 },
  148. { 0x00e7, 9300 }, { 0x00e2, 9400 }, { 0x00dd, 9500 },
  149. { 0x00d8, 9600 }, { 0x00d4, 9700 }, { 0x00cf, 9800 },
  150. { 0x00ca, 9900 }, { 0x00c6, 10000 }, { 0x00c2, 10100 },
  151. { 0x00be, 10200 }, { 0x00b9, 10300 }, { 0x00b5, 10400 },
  152. { 0x00b1, 10500 }, { 0x00ae, 10600 }, { 0x00aa, 10700 },
  153. { 0x00a6, 10800 }, { 0x00a3, 10900 }, { 0x009f, 11000 },
  154. { 0x009b, 11100 }, { 0x0098, 11200 }, { 0x0095, 11300 },
  155. { 0x0091, 11400 }, { 0x008e, 11500 }, { 0x008b, 11600 },
  156. { 0x0088, 11700 }, { 0x0085, 11800 }, { 0x0082, 11900 },
  157. { 0x007f, 12000 }, { 0x007c, 12100 }, { 0x007a, 12200 },
  158. { 0x0077, 12300 }, { 0x0074, 12400 }, { 0x0072, 12500 },
  159. { 0x006f, 12600 }, { 0x006d, 12700 }, { 0x006b, 12800 },
  160. { 0x0068, 12900 }, { 0x0066, 13000 }, { 0x0064, 13100 },
  161. { 0x0061, 13200 }, { 0x005f, 13300 }, { 0x005d, 13400 },
  162. { 0x005b, 13500 }, { 0x0059, 13600 }, { 0x0057, 13700 },
  163. { 0x0055, 13800 }, { 0x0053, 13900 }, { 0x0051, 14000 },
  164. { 0x004f, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 },
  165. { 0x004a, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 },
  166. { 0x0045, 14700 }, { 0x0044, 14800 }, { 0x0042, 14900 },
  167. { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 },
  168. { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 },
  169. { 0x0038, 15600 }, { 0x0037, 15700 }, { 0x0036, 15800 },
  170. { 0x0034, 15900 }, { 0x0033, 16000 }, { 0x0032, 16100 },
  171. { 0x0031, 16200 }, { 0x0030, 16300 }, { 0x002f, 16400 },
  172. { 0x002e, 16500 }, { 0x002d, 16600 }, { 0x002c, 16700 },
  173. { 0x002b, 16800 }, { 0x002a, 16900 }, { 0x0029, 17000 },
  174. { 0x0028, 17100 }, { 0x0027, 17200 }, { 0x0026, 17300 },
  175. { 0x0025, 17400 }, { 0x0024, 17500 }, { 0x0023, 17600 },
  176. { 0x0022, 17800 }, { 0x0021, 17900 }, { 0x0020, 18000 },
  177. { 0x001f, 18200 }, { 0x001e, 18300 }, { 0x001d, 18500 },
  178. { 0x001c, 18700 }, { 0x001b, 18900 }, { 0x001a, 19000 },
  179. { 0x0019, 19200 }, { 0x0018, 19300 }, { 0x0017, 19500 },
  180. { 0x0016, 19700 }, { 0x0015, 19900 }, { 0x0014, 20000 },
  181. };
  182. #define MAKE_IFFREQ_CONFIG(iffreq) ((u32)(((iffreq)/41.0)*16777216.0 + 0.5))
  183. static void cxd2841er_i2c_debug(struct cxd2841er_priv *priv,
  184. u8 addr, u8 reg, u8 write,
  185. const u8 *data, u32 len)
  186. {
  187. dev_dbg(&priv->i2c->dev,
  188. "cxd2841er: I2C %s addr %02x reg 0x%02x size %d\n",
  189. (write == 0 ? "read" : "write"), addr, reg, len);
  190. print_hex_dump_bytes("cxd2841er: I2C data: ",
  191. DUMP_PREFIX_OFFSET, data, len);
  192. }
  193. static int cxd2841er_write_regs(struct cxd2841er_priv *priv,
  194. u8 addr, u8 reg, const u8 *data, u32 len)
  195. {
  196. int ret;
  197. u8 buf[MAX_WRITE_REGSIZE + 1];
  198. u8 i2c_addr = (addr == I2C_SLVX ?
  199. priv->i2c_addr_slvx : priv->i2c_addr_slvt);
  200. struct i2c_msg msg[1] = {
  201. {
  202. .addr = i2c_addr,
  203. .flags = 0,
  204. .len = len + 1,
  205. .buf = buf,
  206. }
  207. };
  208. if (len + 1 >= sizeof(buf)) {
  209. dev_warn(&priv->i2c->dev,"wr reg=%04x: len=%d is too big!\n",
  210. reg, len + 1);
  211. return -E2BIG;
  212. }
  213. cxd2841er_i2c_debug(priv, i2c_addr, reg, 1, data, len);
  214. buf[0] = reg;
  215. memcpy(&buf[1], data, len);
  216. ret = i2c_transfer(priv->i2c, msg, 1);
  217. if (ret >= 0 && ret != 1)
  218. ret = -EIO;
  219. if (ret < 0) {
  220. dev_warn(&priv->i2c->dev,
  221. "%s: i2c wr failed=%d addr=%02x reg=%02x len=%d\n",
  222. KBUILD_MODNAME, ret, i2c_addr, reg, len);
  223. return ret;
  224. }
  225. return 0;
  226. }
  227. static int cxd2841er_write_reg(struct cxd2841er_priv *priv,
  228. u8 addr, u8 reg, u8 val)
  229. {
  230. u8 tmp = val; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
  231. return cxd2841er_write_regs(priv, addr, reg, &tmp, 1);
  232. }
  233. static int cxd2841er_read_regs(struct cxd2841er_priv *priv,
  234. u8 addr, u8 reg, u8 *val, u32 len)
  235. {
  236. int ret;
  237. u8 i2c_addr = (addr == I2C_SLVX ?
  238. priv->i2c_addr_slvx : priv->i2c_addr_slvt);
  239. struct i2c_msg msg[2] = {
  240. {
  241. .addr = i2c_addr,
  242. .flags = 0,
  243. .len = 1,
  244. .buf = &reg,
  245. }, {
  246. .addr = i2c_addr,
  247. .flags = I2C_M_RD,
  248. .len = len,
  249. .buf = val,
  250. }
  251. };
  252. ret = i2c_transfer(priv->i2c, &msg[0], 1);
  253. if (ret >= 0 && ret != 1)
  254. ret = -EIO;
  255. if (ret < 0) {
  256. dev_warn(&priv->i2c->dev,
  257. "%s: i2c rw failed=%d addr=%02x reg=%02x\n",
  258. KBUILD_MODNAME, ret, i2c_addr, reg);
  259. return ret;
  260. }
  261. ret = i2c_transfer(priv->i2c, &msg[1], 1);
  262. if (ret >= 0 && ret != 1)
  263. ret = -EIO;
  264. if (ret < 0) {
  265. dev_warn(&priv->i2c->dev,
  266. "%s: i2c rd failed=%d addr=%02x reg=%02x\n",
  267. KBUILD_MODNAME, ret, i2c_addr, reg);
  268. return ret;
  269. }
  270. return 0;
  271. }
  272. static int cxd2841er_read_reg(struct cxd2841er_priv *priv,
  273. u8 addr, u8 reg, u8 *val)
  274. {
  275. return cxd2841er_read_regs(priv, addr, reg, val, 1);
  276. }
  277. static int cxd2841er_set_reg_bits(struct cxd2841er_priv *priv,
  278. u8 addr, u8 reg, u8 data, u8 mask)
  279. {
  280. int res;
  281. u8 rdata;
  282. if (mask != 0xff) {
  283. res = cxd2841er_read_reg(priv, addr, reg, &rdata);
  284. if (res)
  285. return res;
  286. data = ((data & mask) | (rdata & (mask ^ 0xFF)));
  287. }
  288. return cxd2841er_write_reg(priv, addr, reg, data);
  289. }
  290. static int cxd2841er_dvbs2_set_symbol_rate(struct cxd2841er_priv *priv,
  291. u32 symbol_rate)
  292. {
  293. u32 reg_value = 0;
  294. u8 data[3] = {0, 0, 0};
  295. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  296. /*
  297. * regValue = (symbolRateKSps * 2^14 / 1000) + 0.5
  298. * = ((symbolRateKSps * 2^14) + 500) / 1000
  299. * = ((symbolRateKSps * 16384) + 500) / 1000
  300. */
  301. reg_value = DIV_ROUND_CLOSEST(symbol_rate * 16384, 1000);
  302. if ((reg_value == 0) || (reg_value > 0xFFFFF)) {
  303. dev_err(&priv->i2c->dev,
  304. "%s(): reg_value is out of range\n", __func__);
  305. return -EINVAL;
  306. }
  307. data[0] = (u8)((reg_value >> 16) & 0x0F);
  308. data[1] = (u8)((reg_value >> 8) & 0xFF);
  309. data[2] = (u8)(reg_value & 0xFF);
  310. /* Set SLV-T Bank : 0xAE */
  311. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
  312. cxd2841er_write_regs(priv, I2C_SLVT, 0x20, data, 3);
  313. return 0;
  314. }
  315. static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv,
  316. u8 system);
  317. static int cxd2841er_sleep_s_to_active_s(struct cxd2841er_priv *priv,
  318. u8 system, u32 symbol_rate)
  319. {
  320. int ret;
  321. u8 data[4] = { 0, 0, 0, 0 };
  322. if (priv->state != STATE_SLEEP_S) {
  323. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  324. __func__, (int)priv->state);
  325. return -EINVAL;
  326. }
  327. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  328. cxd2841er_set_ts_clock_mode(priv, SYS_DVBS);
  329. /* Set demod mode */
  330. if (system == SYS_DVBS) {
  331. data[0] = 0x0A;
  332. } else if (system == SYS_DVBS2) {
  333. data[0] = 0x0B;
  334. } else {
  335. dev_err(&priv->i2c->dev, "%s(): invalid delsys %d\n",
  336. __func__, system);
  337. return -EINVAL;
  338. }
  339. /* Set SLV-X Bank : 0x00 */
  340. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  341. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, data[0]);
  342. /* DVB-S/S2 */
  343. data[0] = 0x00;
  344. /* Set SLV-T Bank : 0x00 */
  345. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  346. /* Enable S/S2 auto detection 1 */
  347. cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, data[0]);
  348. /* Set SLV-T Bank : 0xAE */
  349. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
  350. /* Enable S/S2 auto detection 2 */
  351. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, data[0]);
  352. /* Set SLV-T Bank : 0x00 */
  353. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  354. /* Enable demod clock */
  355. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  356. /* Enable ADC clock */
  357. cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x01);
  358. /* Enable ADC 1 */
  359. cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
  360. /* Enable ADC 2 */
  361. cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x3f);
  362. /* Set SLV-X Bank : 0x00 */
  363. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  364. /* Enable ADC 3 */
  365. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  366. /* Set SLV-T Bank : 0xA3 */
  367. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa3);
  368. cxd2841er_write_reg(priv, I2C_SLVT, 0xac, 0x00);
  369. data[0] = 0x07;
  370. data[1] = 0x3B;
  371. data[2] = 0x08;
  372. data[3] = 0xC5;
  373. /* Set SLV-T Bank : 0xAB */
  374. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xab);
  375. cxd2841er_write_regs(priv, I2C_SLVT, 0x98, data, 4);
  376. data[0] = 0x05;
  377. data[1] = 0x80;
  378. data[2] = 0x0A;
  379. data[3] = 0x80;
  380. cxd2841er_write_regs(priv, I2C_SLVT, 0xa8, data, 4);
  381. data[0] = 0x0C;
  382. data[1] = 0xCC;
  383. cxd2841er_write_regs(priv, I2C_SLVT, 0xc3, data, 2);
  384. /* Set demod parameter */
  385. ret = cxd2841er_dvbs2_set_symbol_rate(priv, symbol_rate);
  386. if (ret != 0)
  387. return ret;
  388. /* Set SLV-T Bank : 0x00 */
  389. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  390. /* disable Hi-Z setting 1 */
  391. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x10);
  392. /* disable Hi-Z setting 2 */
  393. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  394. priv->state = STATE_ACTIVE_S;
  395. return 0;
  396. }
  397. static int cxd2841er_sleep_tc_to_active_t_band(struct cxd2841er_priv *priv,
  398. u32 bandwidth);
  399. static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv,
  400. u32 bandwidth);
  401. static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv,
  402. u32 bandwidth);
  403. static int cxd2841er_retune_active(struct cxd2841er_priv *priv,
  404. struct dtv_frontend_properties *p)
  405. {
  406. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  407. if (priv->state != STATE_ACTIVE_S &&
  408. priv->state != STATE_ACTIVE_TC) {
  409. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  410. __func__, priv->state);
  411. return -EINVAL;
  412. }
  413. /* Set SLV-T Bank : 0x00 */
  414. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  415. /* disable TS output */
  416. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  417. if (priv->state == STATE_ACTIVE_S)
  418. return cxd2841er_dvbs2_set_symbol_rate(
  419. priv, p->symbol_rate / 1000);
  420. else if (priv->state == STATE_ACTIVE_TC) {
  421. switch (priv->system) {
  422. case SYS_DVBT:
  423. return cxd2841er_sleep_tc_to_active_t_band(
  424. priv, p->bandwidth_hz);
  425. case SYS_DVBT2:
  426. return cxd2841er_sleep_tc_to_active_t2_band(
  427. priv, p->bandwidth_hz);
  428. case SYS_DVBC_ANNEX_A:
  429. return cxd2841er_sleep_tc_to_active_c_band(
  430. priv, 8000000);
  431. }
  432. }
  433. dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
  434. __func__, priv->system);
  435. return -EINVAL;
  436. }
  437. static int cxd2841er_active_s_to_sleep_s(struct cxd2841er_priv *priv)
  438. {
  439. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  440. if (priv->state != STATE_ACTIVE_S) {
  441. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  442. __func__, priv->state);
  443. return -EINVAL;
  444. }
  445. /* Set SLV-T Bank : 0x00 */
  446. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  447. /* disable TS output */
  448. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  449. /* enable Hi-Z setting 1 */
  450. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1f);
  451. /* enable Hi-Z setting 2 */
  452. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  453. /* Set SLV-X Bank : 0x00 */
  454. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  455. /* disable ADC 1 */
  456. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  457. /* Set SLV-T Bank : 0x00 */
  458. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  459. /* disable ADC clock */
  460. cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x00);
  461. /* disable ADC 2 */
  462. cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
  463. /* disable ADC 3 */
  464. cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
  465. /* SADC Bias ON */
  466. cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
  467. /* disable demod clock */
  468. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  469. /* Set SLV-T Bank : 0xAE */
  470. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
  471. /* disable S/S2 auto detection1 */
  472. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  473. /* Set SLV-T Bank : 0x00 */
  474. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  475. /* disable S/S2 auto detection2 */
  476. cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, 0x00);
  477. priv->state = STATE_SLEEP_S;
  478. return 0;
  479. }
  480. static int cxd2841er_sleep_s_to_shutdown(struct cxd2841er_priv *priv)
  481. {
  482. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  483. if (priv->state != STATE_SLEEP_S) {
  484. dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  485. __func__, priv->state);
  486. return -EINVAL;
  487. }
  488. /* Set SLV-T Bank : 0x00 */
  489. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  490. /* Disable DSQOUT */
  491. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  492. /* Disable DSQIN */
  493. cxd2841er_write_reg(priv, I2C_SLVT, 0x9c, 0x00);
  494. /* Set SLV-X Bank : 0x00 */
  495. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  496. /* Disable oscillator */
  497. cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01);
  498. /* Set demod mode */
  499. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
  500. priv->state = STATE_SHUTDOWN;
  501. return 0;
  502. }
  503. static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv *priv)
  504. {
  505. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  506. if (priv->state != STATE_SLEEP_TC) {
  507. dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  508. __func__, priv->state);
  509. return -EINVAL;
  510. }
  511. /* Set SLV-X Bank : 0x00 */
  512. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  513. /* Disable oscillator */
  514. cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01);
  515. /* Set demod mode */
  516. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
  517. priv->state = STATE_SHUTDOWN;
  518. return 0;
  519. }
  520. static int cxd2841er_active_t_to_sleep_tc(struct cxd2841er_priv *priv)
  521. {
  522. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  523. if (priv->state != STATE_ACTIVE_TC) {
  524. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  525. __func__, priv->state);
  526. return -EINVAL;
  527. }
  528. /* Set SLV-T Bank : 0x00 */
  529. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  530. /* disable TS output */
  531. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  532. /* enable Hi-Z setting 1 */
  533. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  534. /* enable Hi-Z setting 2 */
  535. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  536. /* Set SLV-X Bank : 0x00 */
  537. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  538. /* disable ADC 1 */
  539. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  540. /* Set SLV-T Bank : 0x00 */
  541. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  542. /* Disable ADC 2 */
  543. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  544. /* Disable ADC 3 */
  545. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  546. /* Disable ADC clock */
  547. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  548. /* Disable RF level monitor */
  549. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  550. /* Disable demod clock */
  551. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  552. priv->state = STATE_SLEEP_TC;
  553. return 0;
  554. }
  555. static int cxd2841er_active_t2_to_sleep_tc(struct cxd2841er_priv *priv)
  556. {
  557. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  558. if (priv->state != STATE_ACTIVE_TC) {
  559. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  560. __func__, priv->state);
  561. return -EINVAL;
  562. }
  563. /* Set SLV-T Bank : 0x00 */
  564. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  565. /* disable TS output */
  566. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  567. /* enable Hi-Z setting 1 */
  568. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  569. /* enable Hi-Z setting 2 */
  570. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  571. /* Cancel DVB-T2 setting */
  572. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
  573. cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x40);
  574. cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x21);
  575. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f);
  576. cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xfb);
  577. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a);
  578. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x00, 0x0f);
  579. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
  580. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x00, 0x3f);
  581. /* Set SLV-X Bank : 0x00 */
  582. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  583. /* disable ADC 1 */
  584. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  585. /* Set SLV-T Bank : 0x00 */
  586. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  587. /* Disable ADC 2 */
  588. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  589. /* Disable ADC 3 */
  590. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  591. /* Disable ADC clock */
  592. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  593. /* Disable RF level monitor */
  594. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  595. /* Disable demod clock */
  596. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  597. priv->state = STATE_SLEEP_TC;
  598. return 0;
  599. }
  600. static int cxd2841er_active_c_to_sleep_tc(struct cxd2841er_priv *priv)
  601. {
  602. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  603. if (priv->state != STATE_ACTIVE_TC) {
  604. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  605. __func__, priv->state);
  606. return -EINVAL;
  607. }
  608. /* Set SLV-T Bank : 0x00 */
  609. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  610. /* disable TS output */
  611. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  612. /* enable Hi-Z setting 1 */
  613. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  614. /* enable Hi-Z setting 2 */
  615. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  616. /* Cancel DVB-C setting */
  617. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  618. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa3, 0x00, 0x1f);
  619. /* Set SLV-X Bank : 0x00 */
  620. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  621. /* disable ADC 1 */
  622. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  623. /* Set SLV-T Bank : 0x00 */
  624. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  625. /* Disable ADC 2 */
  626. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  627. /* Disable ADC 3 */
  628. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  629. /* Disable ADC clock */
  630. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  631. /* Disable RF level monitor */
  632. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  633. /* Disable demod clock */
  634. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  635. priv->state = STATE_SLEEP_TC;
  636. return 0;
  637. }
  638. static int cxd2841er_shutdown_to_sleep_s(struct cxd2841er_priv *priv)
  639. {
  640. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  641. if (priv->state != STATE_SHUTDOWN) {
  642. dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  643. __func__, priv->state);
  644. return -EINVAL;
  645. }
  646. /* Set SLV-X Bank : 0x00 */
  647. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  648. /* Clear all demodulator registers */
  649. cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00);
  650. usleep_range(3000, 5000);
  651. /* Set SLV-X Bank : 0x00 */
  652. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  653. /* Set demod SW reset */
  654. cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01);
  655. /* Set X'tal clock to 20.5Mhz */
  656. cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x00);
  657. /* Set demod mode */
  658. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x0a);
  659. /* Clear demod SW reset */
  660. cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00);
  661. usleep_range(1000, 2000);
  662. /* Set SLV-T Bank : 0x00 */
  663. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  664. /* enable DSQOUT */
  665. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1F);
  666. /* enable DSQIN */
  667. cxd2841er_write_reg(priv, I2C_SLVT, 0x9C, 0x40);
  668. /* TADC Bias On */
  669. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  670. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  671. /* SADC Bias On */
  672. cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
  673. cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
  674. cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
  675. priv->state = STATE_SLEEP_S;
  676. return 0;
  677. }
  678. static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv *priv)
  679. {
  680. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  681. if (priv->state != STATE_SHUTDOWN) {
  682. dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  683. __func__, priv->state);
  684. return -EINVAL;
  685. }
  686. /* Set SLV-X Bank : 0x00 */
  687. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  688. /* Clear all demodulator registers */
  689. cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00);
  690. usleep_range(3000, 5000);
  691. /* Set SLV-X Bank : 0x00 */
  692. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  693. /* Set demod SW reset */
  694. cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01);
  695. /* Set X'tal clock to 20.5Mhz */
  696. cxd2841er_write_reg(priv, I2C_SLVX, 0x13, 0x00);
  697. cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x00);
  698. /* Clear demod SW reset */
  699. cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00);
  700. usleep_range(1000, 2000);
  701. /* Set SLV-T Bank : 0x00 */
  702. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  703. /* TADC Bias On */
  704. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  705. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  706. /* SADC Bias On */
  707. cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
  708. cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
  709. cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
  710. priv->state = STATE_SLEEP_TC;
  711. return 0;
  712. }
  713. static int cxd2841er_tune_done(struct cxd2841er_priv *priv)
  714. {
  715. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  716. /* Set SLV-T Bank : 0x00 */
  717. cxd2841er_write_reg(priv, I2C_SLVT, 0, 0);
  718. /* SW Reset */
  719. cxd2841er_write_reg(priv, I2C_SLVT, 0xfe, 0x01);
  720. /* Enable TS output */
  721. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x00);
  722. return 0;
  723. }
  724. /* Set TS parallel mode */
  725. static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv,
  726. u8 system)
  727. {
  728. u8 serial_ts, ts_rate_ctrl_off, ts_in_off;
  729. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  730. /* Set SLV-T Bank : 0x00 */
  731. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  732. cxd2841er_read_reg(priv, I2C_SLVT, 0xc4, &serial_ts);
  733. cxd2841er_read_reg(priv, I2C_SLVT, 0xd3, &ts_rate_ctrl_off);
  734. cxd2841er_read_reg(priv, I2C_SLVT, 0xde, &ts_in_off);
  735. dev_dbg(&priv->i2c->dev, "%s(): ser_ts=0x%02x rate_ctrl_off=0x%02x in_off=0x%02x\n",
  736. __func__, serial_ts, ts_rate_ctrl_off, ts_in_off);
  737. /*
  738. * slave Bank Addr Bit default Name
  739. * <SLV-T> 00h D9h [7:0] 8'h08 OTSCKPERIOD
  740. */
  741. cxd2841er_write_reg(priv, I2C_SLVT, 0xd9, 0x08);
  742. /*
  743. * Disable TS IF Clock
  744. * slave Bank Addr Bit default Name
  745. * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN
  746. */
  747. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x00, 0x01);
  748. /*
  749. * slave Bank Addr Bit default Name
  750. * <SLV-T> 00h 33h [1:0] 2'b01 OREG_CKSEL_TSIF
  751. */
  752. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x33, 0x00, 0x03);
  753. /*
  754. * Enable TS IF Clock
  755. * slave Bank Addr Bit default Name
  756. * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN
  757. */
  758. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x01, 0x01);
  759. if (system == SYS_DVBT) {
  760. /* Enable parity period for DVB-T */
  761. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  762. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01);
  763. } else if (system == SYS_DVBC_ANNEX_A) {
  764. /* Enable parity period for DVB-C */
  765. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  766. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01);
  767. }
  768. }
  769. static u8 cxd2841er_chip_id(struct cxd2841er_priv *priv)
  770. {
  771. u8 chip_id;
  772. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  773. cxd2841er_write_reg(priv, I2C_SLVT, 0, 0);
  774. cxd2841er_read_reg(priv, I2C_SLVT, 0xfd, &chip_id);
  775. return chip_id;
  776. }
  777. static int cxd2841er_read_status_s(struct dvb_frontend *fe,
  778. enum fe_status *status)
  779. {
  780. u8 reg = 0;
  781. struct cxd2841er_priv *priv = fe->demodulator_priv;
  782. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  783. *status = 0;
  784. if (priv->state != STATE_ACTIVE_S) {
  785. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  786. __func__, priv->state);
  787. return -EINVAL;
  788. }
  789. /* Set SLV-T Bank : 0xA0 */
  790. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  791. /*
  792. * slave Bank Addr Bit Signal name
  793. * <SLV-T> A0h 11h [2] ITSLOCK
  794. */
  795. cxd2841er_read_reg(priv, I2C_SLVT, 0x11, &reg);
  796. if (reg & 0x04) {
  797. *status = FE_HAS_SIGNAL
  798. | FE_HAS_CARRIER
  799. | FE_HAS_VITERBI
  800. | FE_HAS_SYNC
  801. | FE_HAS_LOCK;
  802. }
  803. dev_dbg(&priv->i2c->dev, "%s(): result 0x%x\n", __func__, *status);
  804. return 0;
  805. }
  806. static int cxd2841er_read_status_t_t2(struct cxd2841er_priv *priv,
  807. u8 *sync, u8 *tslock, u8 *unlock)
  808. {
  809. u8 data = 0;
  810. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  811. if (priv->state != STATE_ACTIVE_TC)
  812. return -EINVAL;
  813. if (priv->system == SYS_DVBT) {
  814. /* Set SLV-T Bank : 0x10 */
  815. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  816. } else {
  817. /* Set SLV-T Bank : 0x20 */
  818. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  819. }
  820. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data);
  821. if ((data & 0x07) == 0x07) {
  822. dev_dbg(&priv->i2c->dev,
  823. "%s(): invalid hardware state detected\n", __func__);
  824. *sync = 0;
  825. *tslock = 0;
  826. *unlock = 0;
  827. } else {
  828. *sync = ((data & 0x07) == 0x6 ? 1 : 0);
  829. *tslock = ((data & 0x20) ? 1 : 0);
  830. *unlock = ((data & 0x10) ? 1 : 0);
  831. }
  832. return 0;
  833. }
  834. static int cxd2841er_read_status_c(struct cxd2841er_priv *priv, u8 *tslock)
  835. {
  836. u8 data;
  837. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  838. if (priv->state != STATE_ACTIVE_TC)
  839. return -EINVAL;
  840. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  841. cxd2841er_read_reg(priv, I2C_SLVT, 0x88, &data);
  842. if ((data & 0x01) == 0) {
  843. *tslock = 0;
  844. } else {
  845. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data);
  846. *tslock = ((data & 0x20) ? 1 : 0);
  847. }
  848. return 0;
  849. }
  850. static int cxd2841er_read_status_tc(struct dvb_frontend *fe,
  851. enum fe_status *status)
  852. {
  853. int ret = 0;
  854. u8 sync = 0;
  855. u8 tslock = 0;
  856. u8 unlock = 0;
  857. struct cxd2841er_priv *priv = fe->demodulator_priv;
  858. *status = 0;
  859. if (priv->state == STATE_ACTIVE_TC) {
  860. if (priv->system == SYS_DVBT || priv->system == SYS_DVBT2) {
  861. ret = cxd2841er_read_status_t_t2(
  862. priv, &sync, &tslock, &unlock);
  863. if (ret)
  864. goto done;
  865. if (unlock)
  866. goto done;
  867. if (sync)
  868. *status = FE_HAS_SIGNAL |
  869. FE_HAS_CARRIER |
  870. FE_HAS_VITERBI |
  871. FE_HAS_SYNC;
  872. if (tslock)
  873. *status |= FE_HAS_LOCK;
  874. } else if (priv->system == SYS_DVBC_ANNEX_A) {
  875. ret = cxd2841er_read_status_c(priv, &tslock);
  876. if (ret)
  877. goto done;
  878. if (tslock)
  879. *status = FE_HAS_SIGNAL |
  880. FE_HAS_CARRIER |
  881. FE_HAS_VITERBI |
  882. FE_HAS_SYNC |
  883. FE_HAS_LOCK;
  884. }
  885. }
  886. done:
  887. dev_dbg(&priv->i2c->dev, "%s(): status 0x%x\n", __func__, *status);
  888. return ret;
  889. }
  890. static int cxd2841er_get_carrier_offset_s_s2(struct cxd2841er_priv *priv,
  891. int *offset)
  892. {
  893. u8 data[3];
  894. u8 is_hs_mode;
  895. s32 cfrl_ctrlval;
  896. s32 temp_div, temp_q, temp_r;
  897. if (priv->state != STATE_ACTIVE_S) {
  898. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  899. __func__, priv->state);
  900. return -EINVAL;
  901. }
  902. /*
  903. * Get High Sampling Rate mode
  904. * slave Bank Addr Bit Signal name
  905. * <SLV-T> A0h 10h [0] ITRL_LOCK
  906. */
  907. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  908. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data[0]);
  909. if (data[0] & 0x01) {
  910. /*
  911. * slave Bank Addr Bit Signal name
  912. * <SLV-T> A0h 50h [4] IHSMODE
  913. */
  914. cxd2841er_read_reg(priv, I2C_SLVT, 0x50, &data[0]);
  915. is_hs_mode = (data[0] & 0x10 ? 1 : 0);
  916. } else {
  917. dev_dbg(&priv->i2c->dev,
  918. "%s(): unable to detect sampling rate mode\n",
  919. __func__);
  920. return -EINVAL;
  921. }
  922. /*
  923. * slave Bank Addr Bit Signal name
  924. * <SLV-T> A0h 45h [4:0] ICFRL_CTRLVAL[20:16]
  925. * <SLV-T> A0h 46h [7:0] ICFRL_CTRLVAL[15:8]
  926. * <SLV-T> A0h 47h [7:0] ICFRL_CTRLVAL[7:0]
  927. */
  928. cxd2841er_read_regs(priv, I2C_SLVT, 0x45, data, 3);
  929. cfrl_ctrlval = sign_extend32((((u32)data[0] & 0x1F) << 16) |
  930. (((u32)data[1] & 0xFF) << 8) |
  931. ((u32)data[2] & 0xFF), 20);
  932. temp_div = (is_hs_mode ? 1048576 : 1572864);
  933. if (cfrl_ctrlval > 0) {
  934. temp_q = div_s64_rem(97375LL * cfrl_ctrlval,
  935. temp_div, &temp_r);
  936. } else {
  937. temp_q = div_s64_rem(-97375LL * cfrl_ctrlval,
  938. temp_div, &temp_r);
  939. }
  940. if (temp_r >= temp_div / 2)
  941. temp_q++;
  942. if (cfrl_ctrlval > 0)
  943. temp_q *= -1;
  944. *offset = temp_q;
  945. return 0;
  946. }
  947. static int cxd2841er_get_carrier_offset_t2(struct cxd2841er_priv *priv,
  948. u32 bandwidth, int *offset)
  949. {
  950. u8 data[4];
  951. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  952. if (priv->state != STATE_ACTIVE_TC) {
  953. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  954. __func__, priv->state);
  955. return -EINVAL;
  956. }
  957. if (priv->system != SYS_DVBT2) {
  958. dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
  959. __func__, priv->system);
  960. return -EINVAL;
  961. }
  962. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  963. cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data));
  964. *offset = -1 * sign_extend32(
  965. ((u32)(data[0] & 0x0F) << 24) | ((u32)data[1] << 16) |
  966. ((u32)data[2] << 8) | (u32)data[3], 27);
  967. switch (bandwidth) {
  968. case 1712000:
  969. *offset /= 582;
  970. break;
  971. case 5000000:
  972. case 6000000:
  973. case 7000000:
  974. case 8000000:
  975. *offset *= (bandwidth / 1000000);
  976. *offset /= 940;
  977. break;
  978. default:
  979. dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n",
  980. __func__, bandwidth);
  981. return -EINVAL;
  982. }
  983. return 0;
  984. }
  985. static int cxd2841er_get_carrier_offset_c(struct cxd2841er_priv *priv,
  986. int *offset)
  987. {
  988. u8 data[2];
  989. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  990. if (priv->state != STATE_ACTIVE_TC) {
  991. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  992. __func__, priv->state);
  993. return -EINVAL;
  994. }
  995. if (priv->system != SYS_DVBC_ANNEX_A) {
  996. dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
  997. __func__, priv->system);
  998. return -EINVAL;
  999. }
  1000. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  1001. cxd2841er_read_regs(priv, I2C_SLVT, 0x15, data, sizeof(data));
  1002. *offset = div_s64(41000LL * sign_extend32((((u32)data[0] & 0x3f) << 8)
  1003. | (u32)data[1], 13), 16384);
  1004. return 0;
  1005. }
  1006. static int cxd2841er_read_packet_errors_t(
  1007. struct cxd2841er_priv *priv, u32 *penum)
  1008. {
  1009. u8 data[3];
  1010. *penum = 0;
  1011. if (priv->state != STATE_ACTIVE_TC) {
  1012. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1013. __func__, priv->state);
  1014. return -EINVAL;
  1015. }
  1016. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1017. cxd2841er_read_regs(priv, I2C_SLVT, 0xea, data, sizeof(data));
  1018. if (data[2] & 0x01)
  1019. *penum = ((u32)data[0] << 8) | (u32)data[1];
  1020. return 0;
  1021. }
  1022. static int cxd2841er_read_packet_errors_t2(
  1023. struct cxd2841er_priv *priv, u32 *penum)
  1024. {
  1025. u8 data[3];
  1026. *penum = 0;
  1027. if (priv->state != STATE_ACTIVE_TC) {
  1028. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1029. __func__, priv->state);
  1030. return -EINVAL;
  1031. }
  1032. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x24);
  1033. cxd2841er_read_regs(priv, I2C_SLVT, 0xfd, data, sizeof(data));
  1034. if (data[0] & 0x01)
  1035. *penum = ((u32)data[1] << 8) | (u32)data[2];
  1036. return 0;
  1037. }
  1038. static u32 cxd2841er_mon_read_ber_s(struct cxd2841er_priv *priv)
  1039. {
  1040. u8 data[11];
  1041. u32 bit_error, bit_count;
  1042. u32 temp_q, temp_r;
  1043. /* Set SLV-T Bank : 0xA0 */
  1044. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  1045. /*
  1046. * slave Bank Addr Bit Signal name
  1047. * <SLV-T> A0h 35h [0] IFVBER_VALID
  1048. * <SLV-T> A0h 36h [5:0] IFVBER_BITERR[21:16]
  1049. * <SLV-T> A0h 37h [7:0] IFVBER_BITERR[15:8]
  1050. * <SLV-T> A0h 38h [7:0] IFVBER_BITERR[7:0]
  1051. * <SLV-T> A0h 3Dh [5:0] IFVBER_BITNUM[21:16]
  1052. * <SLV-T> A0h 3Eh [7:0] IFVBER_BITNUM[15:8]
  1053. * <SLV-T> A0h 3Fh [7:0] IFVBER_BITNUM[7:0]
  1054. */
  1055. cxd2841er_read_regs(priv, I2C_SLVT, 0x35, data, 11);
  1056. if (data[0] & 0x01) {
  1057. bit_error = ((u32)(data[1] & 0x3F) << 16) |
  1058. ((u32)(data[2] & 0xFF) << 8) |
  1059. (u32)(data[3] & 0xFF);
  1060. bit_count = ((u32)(data[8] & 0x3F) << 16) |
  1061. ((u32)(data[9] & 0xFF) << 8) |
  1062. (u32)(data[10] & 0xFF);
  1063. /*
  1064. * BER = bitError / bitCount
  1065. * = (bitError * 10^7) / bitCount
  1066. * = ((bitError * 625 * 125 * 128) / bitCount
  1067. */
  1068. if ((bit_count == 0) || (bit_error > bit_count)) {
  1069. dev_dbg(&priv->i2c->dev,
  1070. "%s(): invalid bit_error %d, bit_count %d\n",
  1071. __func__, bit_error, bit_count);
  1072. return 0;
  1073. }
  1074. temp_q = div_u64_rem(10000000ULL * bit_error,
  1075. bit_count, &temp_r);
  1076. if (bit_count != 1 && temp_r >= bit_count / 2)
  1077. temp_q++;
  1078. return temp_q;
  1079. }
  1080. dev_dbg(&priv->i2c->dev, "%s(): no data available\n", __func__);
  1081. return 0;
  1082. }
  1083. static u32 cxd2841er_mon_read_ber_s2(struct cxd2841er_priv *priv)
  1084. {
  1085. u8 data[5];
  1086. u32 bit_error, period;
  1087. u32 temp_q, temp_r;
  1088. u32 result = 0;
  1089. /* Set SLV-T Bank : 0xB2 */
  1090. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xb2);
  1091. /*
  1092. * slave Bank Addr Bit Signal name
  1093. * <SLV-T> B2h 30h [0] IFLBER_VALID
  1094. * <SLV-T> B2h 31h [3:0] IFLBER_BITERR[27:24]
  1095. * <SLV-T> B2h 32h [7:0] IFLBER_BITERR[23:16]
  1096. * <SLV-T> B2h 33h [7:0] IFLBER_BITERR[15:8]
  1097. * <SLV-T> B2h 34h [7:0] IFLBER_BITERR[7:0]
  1098. */
  1099. cxd2841er_read_regs(priv, I2C_SLVT, 0x30, data, 5);
  1100. if (data[0] & 0x01) {
  1101. /* Bit error count */
  1102. bit_error = ((u32)(data[1] & 0x0F) << 24) |
  1103. ((u32)(data[2] & 0xFF) << 16) |
  1104. ((u32)(data[3] & 0xFF) << 8) |
  1105. (u32)(data[4] & 0xFF);
  1106. /* Set SLV-T Bank : 0xA0 */
  1107. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  1108. cxd2841er_read_reg(priv, I2C_SLVT, 0x7a, data);
  1109. /* Measurement period */
  1110. period = (u32)(1 << (data[0] & 0x0F));
  1111. if (period == 0) {
  1112. dev_dbg(&priv->i2c->dev,
  1113. "%s(): period is 0\n", __func__);
  1114. return 0;
  1115. }
  1116. if (bit_error > (period * 64800)) {
  1117. dev_dbg(&priv->i2c->dev,
  1118. "%s(): invalid bit_err 0x%x period 0x%x\n",
  1119. __func__, bit_error, period);
  1120. return 0;
  1121. }
  1122. /*
  1123. * BER = bitError / (period * 64800)
  1124. * = (bitError * 10^7) / (period * 64800)
  1125. * = (bitError * 10^5) / (period * 648)
  1126. * = (bitError * 12500) / (period * 81)
  1127. * = (bitError * 10) * 1250 / (period * 81)
  1128. */
  1129. temp_q = div_u64_rem(12500ULL * bit_error,
  1130. period * 81, &temp_r);
  1131. if (temp_r >= period * 40)
  1132. temp_q++;
  1133. result = temp_q;
  1134. } else {
  1135. dev_dbg(&priv->i2c->dev,
  1136. "%s(): no data available\n", __func__);
  1137. }
  1138. return result;
  1139. }
  1140. static int cxd2841er_read_ber_t2(struct cxd2841er_priv *priv, u32 *ber)
  1141. {
  1142. u8 data[4];
  1143. u32 div, q, r;
  1144. u32 bit_err, period_exp, n_ldpc;
  1145. *ber = 0;
  1146. if (priv->state != STATE_ACTIVE_TC) {
  1147. dev_dbg(&priv->i2c->dev,
  1148. "%s(): invalid state %d\n", __func__, priv->state);
  1149. return -EINVAL;
  1150. }
  1151. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  1152. cxd2841er_read_regs(priv, I2C_SLVT, 0x39, data, sizeof(data));
  1153. if (!(data[0] & 0x10)) {
  1154. dev_dbg(&priv->i2c->dev,
  1155. "%s(): no valid BER data\n", __func__);
  1156. return 0;
  1157. }
  1158. bit_err = ((u32)(data[0] & 0x0f) << 24) |
  1159. ((u32)data[1] << 16) |
  1160. ((u32)data[2] << 8) |
  1161. (u32)data[3];
  1162. cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data);
  1163. period_exp = data[0] & 0x0f;
  1164. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x22);
  1165. cxd2841er_read_reg(priv, I2C_SLVT, 0x5e, data);
  1166. n_ldpc = ((data[0] & 0x03) == 0 ? 16200 : 64800);
  1167. if (bit_err > ((1U << period_exp) * n_ldpc)) {
  1168. dev_dbg(&priv->i2c->dev,
  1169. "%s(): invalid BER value\n", __func__);
  1170. return -EINVAL;
  1171. }
  1172. if (period_exp >= 4) {
  1173. div = (1U << (period_exp - 4)) * (n_ldpc / 200);
  1174. q = div_u64_rem(3125ULL * bit_err, div, &r);
  1175. } else {
  1176. div = (1U << period_exp) * (n_ldpc / 200);
  1177. q = div_u64_rem(50000ULL * bit_err, div, &r);
  1178. }
  1179. *ber = (r >= div / 2) ? q + 1 : q;
  1180. return 0;
  1181. }
  1182. static int cxd2841er_read_ber_t(struct cxd2841er_priv *priv, u32 *ber)
  1183. {
  1184. u8 data[2];
  1185. u32 div, q, r;
  1186. u32 bit_err, period;
  1187. *ber = 0;
  1188. if (priv->state != STATE_ACTIVE_TC) {
  1189. dev_dbg(&priv->i2c->dev,
  1190. "%s(): invalid state %d\n", __func__, priv->state);
  1191. return -EINVAL;
  1192. }
  1193. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1194. cxd2841er_read_reg(priv, I2C_SLVT, 0x39, data);
  1195. if (!(data[0] & 0x01)) {
  1196. dev_dbg(&priv->i2c->dev,
  1197. "%s(): no valid BER data\n", __func__);
  1198. return 0;
  1199. }
  1200. cxd2841er_read_regs(priv, I2C_SLVT, 0x22, data, sizeof(data));
  1201. bit_err = ((u32)data[0] << 8) | (u32)data[1];
  1202. cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data);
  1203. period = ((data[0] & 0x07) == 0) ? 256 : (4096 << (data[0] & 0x07));
  1204. div = period / 128;
  1205. q = div_u64_rem(78125ULL * bit_err, div, &r);
  1206. *ber = (r >= div / 2) ? q + 1 : q;
  1207. return 0;
  1208. }
  1209. static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv, u8 delsys)
  1210. {
  1211. u8 data[3];
  1212. u32 res = 0, value;
  1213. int min_index, max_index, index;
  1214. static const struct cxd2841er_cnr_data *cn_data;
  1215. /* Set SLV-T Bank : 0xA1 */
  1216. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa1);
  1217. /*
  1218. * slave Bank Addr Bit Signal name
  1219. * <SLV-T> A1h 10h [0] ICPM_QUICKRDY
  1220. * <SLV-T> A1h 11h [4:0] ICPM_QUICKCNDT[12:8]
  1221. * <SLV-T> A1h 12h [7:0] ICPM_QUICKCNDT[7:0]
  1222. */
  1223. cxd2841er_read_regs(priv, I2C_SLVT, 0x10, data, 3);
  1224. if (data[0] & 0x01) {
  1225. value = ((u32)(data[1] & 0x1F) << 8) | (u32)(data[2] & 0xFF);
  1226. min_index = 0;
  1227. if (delsys == SYS_DVBS) {
  1228. cn_data = s_cn_data;
  1229. max_index = sizeof(s_cn_data) /
  1230. sizeof(s_cn_data[0]) - 1;
  1231. } else {
  1232. cn_data = s2_cn_data;
  1233. max_index = sizeof(s2_cn_data) /
  1234. sizeof(s2_cn_data[0]) - 1;
  1235. }
  1236. if (value >= cn_data[min_index].value) {
  1237. res = cn_data[min_index].cnr_x1000;
  1238. goto done;
  1239. }
  1240. if (value <= cn_data[max_index].value) {
  1241. res = cn_data[max_index].cnr_x1000;
  1242. goto done;
  1243. }
  1244. while ((max_index - min_index) > 1) {
  1245. index = (max_index + min_index) / 2;
  1246. if (value == cn_data[index].value) {
  1247. res = cn_data[index].cnr_x1000;
  1248. goto done;
  1249. } else if (value > cn_data[index].value)
  1250. max_index = index;
  1251. else
  1252. min_index = index;
  1253. if ((max_index - min_index) <= 1) {
  1254. if (value == cn_data[max_index].value) {
  1255. res = cn_data[max_index].cnr_x1000;
  1256. goto done;
  1257. } else {
  1258. res = cn_data[min_index].cnr_x1000;
  1259. goto done;
  1260. }
  1261. }
  1262. }
  1263. } else {
  1264. dev_dbg(&priv->i2c->dev,
  1265. "%s(): no data available\n", __func__);
  1266. }
  1267. done:
  1268. return res;
  1269. }
  1270. static int cxd2841er_read_snr_t(struct cxd2841er_priv *priv, u32 *snr)
  1271. {
  1272. u32 reg;
  1273. u8 data[2];
  1274. *snr = 0;
  1275. if (priv->state != STATE_ACTIVE_TC) {
  1276. dev_dbg(&priv->i2c->dev,
  1277. "%s(): invalid state %d\n", __func__, priv->state);
  1278. return -EINVAL;
  1279. }
  1280. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1281. cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data));
  1282. reg = ((u32)data[0] << 8) | (u32)data[1];
  1283. if (reg == 0) {
  1284. dev_dbg(&priv->i2c->dev,
  1285. "%s(): reg value out of range\n", __func__);
  1286. return 0;
  1287. }
  1288. if (reg > 4996)
  1289. reg = 4996;
  1290. *snr = 10000 * ((intlog10(reg) - intlog10(5350 - reg)) >> 24) + 28500;
  1291. return 0;
  1292. }
  1293. static int cxd2841er_read_snr_t2(struct cxd2841er_priv *priv, u32 *snr)
  1294. {
  1295. u32 reg;
  1296. u8 data[2];
  1297. *snr = 0;
  1298. if (priv->state != STATE_ACTIVE_TC) {
  1299. dev_dbg(&priv->i2c->dev,
  1300. "%s(): invalid state %d\n", __func__, priv->state);
  1301. return -EINVAL;
  1302. }
  1303. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  1304. cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data));
  1305. reg = ((u32)data[0] << 8) | (u32)data[1];
  1306. if (reg == 0) {
  1307. dev_dbg(&priv->i2c->dev,
  1308. "%s(): reg value out of range\n", __func__);
  1309. return 0;
  1310. }
  1311. if (reg > 10876)
  1312. reg = 10876;
  1313. *snr = 10000 * ((intlog10(reg) -
  1314. intlog10(12600 - reg)) >> 24) + 32000;
  1315. return 0;
  1316. }
  1317. static u16 cxd2841er_read_agc_gain_t_t2(struct cxd2841er_priv *priv,
  1318. u8 delsys)
  1319. {
  1320. u8 data[2];
  1321. cxd2841er_write_reg(
  1322. priv, I2C_SLVT, 0x00, (delsys == SYS_DVBT ? 0x10 : 0x20));
  1323. cxd2841er_read_regs(priv, I2C_SLVT, 0x26, data, 2);
  1324. return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4;
  1325. }
  1326. static u16 cxd2841er_read_agc_gain_s(struct cxd2841er_priv *priv)
  1327. {
  1328. u8 data[2];
  1329. /* Set SLV-T Bank : 0xA0 */
  1330. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  1331. /*
  1332. * slave Bank Addr Bit Signal name
  1333. * <SLV-T> A0h 1Fh [4:0] IRFAGC_GAIN[12:8]
  1334. * <SLV-T> A0h 20h [7:0] IRFAGC_GAIN[7:0]
  1335. */
  1336. cxd2841er_read_regs(priv, I2C_SLVT, 0x1f, data, 2);
  1337. return ((((u16)data[0] & 0x1F) << 8) | (u16)(data[1] & 0xFF)) << 3;
  1338. }
  1339. static int cxd2841er_read_ber(struct dvb_frontend *fe, u32 *ber)
  1340. {
  1341. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1342. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1343. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1344. *ber = 0;
  1345. switch (p->delivery_system) {
  1346. case SYS_DVBS:
  1347. *ber = cxd2841er_mon_read_ber_s(priv);
  1348. break;
  1349. case SYS_DVBS2:
  1350. *ber = cxd2841er_mon_read_ber_s2(priv);
  1351. break;
  1352. case SYS_DVBT:
  1353. return cxd2841er_read_ber_t(priv, ber);
  1354. case SYS_DVBT2:
  1355. return cxd2841er_read_ber_t2(priv, ber);
  1356. default:
  1357. *ber = 0;
  1358. break;
  1359. }
  1360. return 0;
  1361. }
  1362. static int cxd2841er_read_signal_strength(struct dvb_frontend *fe,
  1363. u16 *strength)
  1364. {
  1365. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1366. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1367. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1368. switch (p->delivery_system) {
  1369. case SYS_DVBT:
  1370. case SYS_DVBT2:
  1371. *strength = 65535 - cxd2841er_read_agc_gain_t_t2(
  1372. priv, p->delivery_system);
  1373. break;
  1374. case SYS_DVBS:
  1375. case SYS_DVBS2:
  1376. *strength = 65535 - cxd2841er_read_agc_gain_s(priv);
  1377. break;
  1378. default:
  1379. *strength = 0;
  1380. break;
  1381. }
  1382. return 0;
  1383. }
  1384. static int cxd2841er_read_snr(struct dvb_frontend *fe, u16 *snr)
  1385. {
  1386. u32 tmp = 0;
  1387. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1388. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1389. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1390. switch (p->delivery_system) {
  1391. case SYS_DVBT:
  1392. cxd2841er_read_snr_t(priv, &tmp);
  1393. break;
  1394. case SYS_DVBT2:
  1395. cxd2841er_read_snr_t2(priv, &tmp);
  1396. break;
  1397. case SYS_DVBS:
  1398. case SYS_DVBS2:
  1399. tmp = cxd2841er_dvbs_read_snr(priv, p->delivery_system);
  1400. break;
  1401. default:
  1402. dev_dbg(&priv->i2c->dev, "%s(): unknown delivery system %d\n",
  1403. __func__, p->delivery_system);
  1404. break;
  1405. }
  1406. *snr = tmp & 0xffff;
  1407. return 0;
  1408. }
  1409. static int cxd2841er_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
  1410. {
  1411. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1412. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1413. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1414. switch (p->delivery_system) {
  1415. case SYS_DVBT:
  1416. cxd2841er_read_packet_errors_t(priv, ucblocks);
  1417. break;
  1418. case SYS_DVBT2:
  1419. cxd2841er_read_packet_errors_t2(priv, ucblocks);
  1420. break;
  1421. default:
  1422. *ucblocks = 0;
  1423. break;
  1424. }
  1425. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1426. return 0;
  1427. }
  1428. static int cxd2841er_dvbt2_set_profile(
  1429. struct cxd2841er_priv *priv, enum cxd2841er_dvbt2_profile_t profile)
  1430. {
  1431. u8 tune_mode;
  1432. u8 seq_not2d_time;
  1433. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1434. switch (profile) {
  1435. case DVBT2_PROFILE_BASE:
  1436. tune_mode = 0x01;
  1437. seq_not2d_time = 12;
  1438. break;
  1439. case DVBT2_PROFILE_LITE:
  1440. tune_mode = 0x05;
  1441. seq_not2d_time = 40;
  1442. break;
  1443. case DVBT2_PROFILE_ANY:
  1444. tune_mode = 0x00;
  1445. seq_not2d_time = 40;
  1446. break;
  1447. default:
  1448. return -EINVAL;
  1449. }
  1450. /* Set SLV-T Bank : 0x2E */
  1451. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2e);
  1452. /* Set profile and tune mode */
  1453. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x10, tune_mode, 0x07);
  1454. /* Set SLV-T Bank : 0x2B */
  1455. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
  1456. /* Set early unlock detection time */
  1457. cxd2841er_write_reg(priv, I2C_SLVT, 0x9d, seq_not2d_time);
  1458. return 0;
  1459. }
  1460. static int cxd2841er_dvbt2_set_plp_config(struct cxd2841er_priv *priv,
  1461. u8 is_auto, u8 plp_id)
  1462. {
  1463. if (is_auto) {
  1464. dev_dbg(&priv->i2c->dev,
  1465. "%s() using auto PLP selection\n", __func__);
  1466. } else {
  1467. dev_dbg(&priv->i2c->dev,
  1468. "%s() using manual PLP selection, ID %d\n",
  1469. __func__, plp_id);
  1470. }
  1471. /* Set SLV-T Bank : 0x23 */
  1472. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x23);
  1473. if (!is_auto) {
  1474. /* Manual PLP selection mode. Set the data PLP Id. */
  1475. cxd2841er_write_reg(priv, I2C_SLVT, 0xaf, plp_id);
  1476. }
  1477. /* Auto PLP select (Scanning mode = 0x00). Data PLP select = 0x01. */
  1478. cxd2841er_write_reg(priv, I2C_SLVT, 0xad, (is_auto ? 0x00 : 0x01));
  1479. return 0;
  1480. }
  1481. static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv,
  1482. u32 bandwidth)
  1483. {
  1484. u32 iffreq;
  1485. u8 b20_9f[5];
  1486. u8 b10_a6[14];
  1487. u8 b10_b6[3];
  1488. u8 b10_d7;
  1489. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1490. switch (bandwidth) {
  1491. case 8000000:
  1492. /* bank 0x20, reg 0x9f */
  1493. b20_9f[0] = 0x11;
  1494. b20_9f[1] = 0xf0;
  1495. b20_9f[2] = 0x00;
  1496. b20_9f[3] = 0x00;
  1497. b20_9f[4] = 0x00;
  1498. /* bank 0x10, reg 0xa6 */
  1499. b10_a6[0] = 0x26;
  1500. b10_a6[1] = 0xaf;
  1501. b10_a6[2] = 0x06;
  1502. b10_a6[3] = 0xcd;
  1503. b10_a6[4] = 0x13;
  1504. b10_a6[5] = 0xbb;
  1505. b10_a6[6] = 0x28;
  1506. b10_a6[7] = 0xba;
  1507. b10_a6[8] = 0x23;
  1508. b10_a6[9] = 0xa9;
  1509. b10_a6[10] = 0x1f;
  1510. b10_a6[11] = 0xa8;
  1511. b10_a6[12] = 0x2c;
  1512. b10_a6[13] = 0xc8;
  1513. iffreq = MAKE_IFFREQ_CONFIG(4.80);
  1514. b10_d7 = 0x00;
  1515. break;
  1516. case 7000000:
  1517. /* bank 0x20, reg 0x9f */
  1518. b20_9f[0] = 0x14;
  1519. b20_9f[1] = 0x80;
  1520. b20_9f[2] = 0x00;
  1521. b20_9f[3] = 0x00;
  1522. b20_9f[4] = 0x00;
  1523. /* bank 0x10, reg 0xa6 */
  1524. b10_a6[0] = 0x2C;
  1525. b10_a6[1] = 0xBD;
  1526. b10_a6[2] = 0x02;
  1527. b10_a6[3] = 0xCF;
  1528. b10_a6[4] = 0x04;
  1529. b10_a6[5] = 0xF8;
  1530. b10_a6[6] = 0x23;
  1531. b10_a6[7] = 0xA6;
  1532. b10_a6[8] = 0x29;
  1533. b10_a6[9] = 0xB0;
  1534. b10_a6[10] = 0x26;
  1535. b10_a6[11] = 0xA9;
  1536. b10_a6[12] = 0x21;
  1537. b10_a6[13] = 0xA5;
  1538. iffreq = MAKE_IFFREQ_CONFIG(4.2);
  1539. b10_d7 = 0x02;
  1540. break;
  1541. case 6000000:
  1542. /* bank 0x20, reg 0x9f */
  1543. b20_9f[0] = 0x17;
  1544. b20_9f[1] = 0xEA;
  1545. b20_9f[2] = 0xAA;
  1546. b20_9f[3] = 0xAA;
  1547. b20_9f[4] = 0xAA;
  1548. /* bank 0x10, reg 0xa6 */
  1549. b10_a6[0] = 0x27;
  1550. b10_a6[1] = 0xA7;
  1551. b10_a6[2] = 0x28;
  1552. b10_a6[3] = 0xB3;
  1553. b10_a6[4] = 0x02;
  1554. b10_a6[5] = 0xF0;
  1555. b10_a6[6] = 0x01;
  1556. b10_a6[7] = 0xE8;
  1557. b10_a6[8] = 0x00;
  1558. b10_a6[9] = 0xCF;
  1559. b10_a6[10] = 0x00;
  1560. b10_a6[11] = 0xE6;
  1561. b10_a6[12] = 0x23;
  1562. b10_a6[13] = 0xA4;
  1563. iffreq = MAKE_IFFREQ_CONFIG(3.6);
  1564. b10_d7 = 0x04;
  1565. break;
  1566. case 5000000:
  1567. /* bank 0x20, reg 0x9f */
  1568. b20_9f[0] = 0x1C;
  1569. b20_9f[1] = 0xB3;
  1570. b20_9f[2] = 0x33;
  1571. b20_9f[3] = 0x33;
  1572. b20_9f[4] = 0x33;
  1573. /* bank 0x10, reg 0xa6 */
  1574. b10_a6[0] = 0x27;
  1575. b10_a6[1] = 0xA7;
  1576. b10_a6[2] = 0x28;
  1577. b10_a6[3] = 0xB3;
  1578. b10_a6[4] = 0x02;
  1579. b10_a6[5] = 0xF0;
  1580. b10_a6[6] = 0x01;
  1581. b10_a6[7] = 0xE8;
  1582. b10_a6[8] = 0x00;
  1583. b10_a6[9] = 0xCF;
  1584. b10_a6[10] = 0x00;
  1585. b10_a6[11] = 0xE6;
  1586. b10_a6[12] = 0x23;
  1587. b10_a6[13] = 0xA4;
  1588. iffreq = MAKE_IFFREQ_CONFIG(3.6);
  1589. b10_d7 = 0x06;
  1590. break;
  1591. case 1712000:
  1592. /* bank 0x20, reg 0x9f */
  1593. b20_9f[0] = 0x58;
  1594. b20_9f[1] = 0xE2;
  1595. b20_9f[2] = 0xAF;
  1596. b20_9f[3] = 0xE0;
  1597. b20_9f[4] = 0xBC;
  1598. /* bank 0x10, reg 0xa6 */
  1599. b10_a6[0] = 0x25;
  1600. b10_a6[1] = 0xA0;
  1601. b10_a6[2] = 0x36;
  1602. b10_a6[3] = 0x8D;
  1603. b10_a6[4] = 0x2E;
  1604. b10_a6[5] = 0x94;
  1605. b10_a6[6] = 0x28;
  1606. b10_a6[7] = 0x9B;
  1607. b10_a6[8] = 0x32;
  1608. b10_a6[9] = 0x90;
  1609. b10_a6[10] = 0x2C;
  1610. b10_a6[11] = 0x9D;
  1611. b10_a6[12] = 0x29;
  1612. b10_a6[13] = 0x99;
  1613. iffreq = MAKE_IFFREQ_CONFIG(3.5);
  1614. b10_d7 = 0x03;
  1615. break;
  1616. default:
  1617. return -EINVAL;
  1618. }
  1619. /* Set SLV-T Bank : 0x20 */
  1620. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x20);
  1621. cxd2841er_write_regs(priv, I2C_SLVT, 0x9f, b20_9f, sizeof(b20_9f));
  1622. /* Set SLV-T Bank : 0x27 */
  1623. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
  1624. cxd2841er_set_reg_bits(
  1625. priv, I2C_SLVT, 0x7a,
  1626. (bandwidth == 1712000 ? 0x03 : 0x00), 0x0f);
  1627. /* Set SLV-T Bank : 0x10 */
  1628. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1629. /* Group delay equaliser sett. for ASCOT2E */
  1630. cxd2841er_write_regs(priv, I2C_SLVT, 0xa6, b10_a6, sizeof(b10_a6));
  1631. /* <IF freq setting> */
  1632. b10_b6[0] = (u8) ((iffreq >> 16) & 0xff);
  1633. b10_b6[1] = (u8)((iffreq >> 8) & 0xff);
  1634. b10_b6[2] = (u8)(iffreq & 0xff);
  1635. cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6));
  1636. /* System bandwidth setting */
  1637. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, b10_d7, 0x07);
  1638. return 0;
  1639. }
  1640. static int cxd2841er_sleep_tc_to_active_t_band(
  1641. struct cxd2841er_priv *priv, u32 bandwidth)
  1642. {
  1643. u8 b13_9c[2] = { 0x01, 0x14 };
  1644. u8 bw8mhz_b10_9f[] = { 0x11, 0xF0, 0x00, 0x00, 0x00 };
  1645. u8 bw8mhz_b10_a6[] = { 0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB,
  1646. 0x28, 0xBA, 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8 };
  1647. u8 bw8mhz_b10_d9[] = { 0x01, 0xE0 };
  1648. u8 bw8mhz_b17_38[] = { 0x01, 0x02 };
  1649. u8 bw7mhz_b10_9f[] = { 0x14, 0x80, 0x00, 0x00, 0x00 };
  1650. u8 bw7mhz_b10_a6[] = { 0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8,
  1651. 0x23, 0xA6, 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5 };
  1652. u8 bw7mhz_b10_d9[] = { 0x12, 0xF8 };
  1653. u8 bw7mhz_b17_38[] = { 0x00, 0x03 };
  1654. u8 bw6mhz_b10_9f[] = { 0x17, 0xEA, 0xAA, 0xAA, 0xAA };
  1655. u8 bw6mhz_b10_a6[] = { 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0,
  1656. 0x01, 0xE8, 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 };
  1657. u8 bw6mhz_b10_d9[] = { 0x1F, 0xDC };
  1658. u8 bw6mhz_b17_38[] = { 0x00, 0x03 };
  1659. u8 bw5mhz_b10_9f[] = { 0x1C, 0xB3, 0x33, 0x33, 0x33 };
  1660. u8 bw5mhz_b10_a6[] = { 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0,
  1661. 0x01, 0xE8, 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 };
  1662. u8 bw5mhz_b10_d9[] = { 0x26, 0x3C };
  1663. u8 bw5mhz_b17_38[] = { 0x00, 0x03 };
  1664. u8 b10_b6[3];
  1665. u8 d7val;
  1666. u32 iffreq;
  1667. u8 *b10_9f;
  1668. u8 *b10_a6;
  1669. u8 *b10_d9;
  1670. u8 *b17_38;
  1671. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1672. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
  1673. /* Echo performance optimization setting */
  1674. cxd2841er_write_regs(priv, I2C_SLVT, 0x9c, b13_9c, sizeof(b13_9c));
  1675. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1676. switch (bandwidth) {
  1677. case 8000000:
  1678. b10_9f = bw8mhz_b10_9f;
  1679. b10_a6 = bw8mhz_b10_a6;
  1680. b10_d9 = bw8mhz_b10_d9;
  1681. b17_38 = bw8mhz_b17_38;
  1682. d7val = 0;
  1683. iffreq = MAKE_IFFREQ_CONFIG(4.80);
  1684. break;
  1685. case 7000000:
  1686. b10_9f = bw7mhz_b10_9f;
  1687. b10_a6 = bw7mhz_b10_a6;
  1688. b10_d9 = bw7mhz_b10_d9;
  1689. b17_38 = bw7mhz_b17_38;
  1690. d7val = 2;
  1691. iffreq = MAKE_IFFREQ_CONFIG(4.20);
  1692. break;
  1693. case 6000000:
  1694. b10_9f = bw6mhz_b10_9f;
  1695. b10_a6 = bw6mhz_b10_a6;
  1696. b10_d9 = bw6mhz_b10_d9;
  1697. b17_38 = bw6mhz_b17_38;
  1698. d7val = 4;
  1699. iffreq = MAKE_IFFREQ_CONFIG(3.60);
  1700. break;
  1701. case 5000000:
  1702. b10_9f = bw5mhz_b10_9f;
  1703. b10_a6 = bw5mhz_b10_a6;
  1704. b10_d9 = bw5mhz_b10_d9;
  1705. b17_38 = bw5mhz_b17_38;
  1706. d7val = 6;
  1707. iffreq = MAKE_IFFREQ_CONFIG(3.60);
  1708. break;
  1709. default:
  1710. dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n",
  1711. __func__, bandwidth);
  1712. return -EINVAL;
  1713. }
  1714. /* <IF freq setting> */
  1715. b10_b6[0] = (u8) ((iffreq >> 16) & 0xff);
  1716. b10_b6[1] = (u8)((iffreq >> 8) & 0xff);
  1717. b10_b6[2] = (u8)(iffreq & 0xff);
  1718. cxd2841er_write_regs(
  1719. priv, I2C_SLVT, 0x9f, b10_9f, sizeof(bw8mhz_b10_9f));
  1720. cxd2841er_write_regs(
  1721. priv, I2C_SLVT, 0xa6, b10_a6, sizeof(bw8mhz_b10_a6));
  1722. cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6));
  1723. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, d7val, 0x7);
  1724. cxd2841er_write_regs(
  1725. priv, I2C_SLVT, 0xd9, b10_d9, sizeof(bw8mhz_b10_d9));
  1726. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
  1727. cxd2841er_write_regs(
  1728. priv, I2C_SLVT, 0x38, b17_38, sizeof(bw8mhz_b17_38));
  1729. return 0;
  1730. }
  1731. static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv,
  1732. u32 bandwidth)
  1733. {
  1734. u8 bw7_8mhz_b10_a6[] = {
  1735. 0x2D, 0xC7, 0x04, 0xF4, 0x07, 0xC5, 0x2A, 0xB8,
  1736. 0x27, 0x9E, 0x27, 0xA4, 0x29, 0xAB };
  1737. u8 bw6mhz_b10_a6[] = {
  1738. 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
  1739. 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 };
  1740. u8 b10_b6[3];
  1741. u32 iffreq;
  1742. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1743. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1744. switch (bandwidth) {
  1745. case 8000000:
  1746. case 7000000:
  1747. cxd2841er_write_regs(
  1748. priv, I2C_SLVT, 0xa6,
  1749. bw7_8mhz_b10_a6, sizeof(bw7_8mhz_b10_a6));
  1750. iffreq = MAKE_IFFREQ_CONFIG(4.9);
  1751. break;
  1752. case 6000000:
  1753. cxd2841er_write_regs(
  1754. priv, I2C_SLVT, 0xa6,
  1755. bw6mhz_b10_a6, sizeof(bw6mhz_b10_a6));
  1756. iffreq = MAKE_IFFREQ_CONFIG(3.7);
  1757. break;
  1758. default:
  1759. dev_dbg(&priv->i2c->dev, "%s(): unsupported bandwidth %d\n",
  1760. __func__, bandwidth);
  1761. return -EINVAL;
  1762. }
  1763. /* <IF freq setting> */
  1764. b10_b6[0] = (u8) ((iffreq >> 16) & 0xff);
  1765. b10_b6[1] = (u8)((iffreq >> 8) & 0xff);
  1766. b10_b6[2] = (u8)(iffreq & 0xff);
  1767. cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6));
  1768. /* Set SLV-T Bank : 0x11 */
  1769. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  1770. switch (bandwidth) {
  1771. case 8000000:
  1772. case 7000000:
  1773. cxd2841er_set_reg_bits(
  1774. priv, I2C_SLVT, 0xa3, 0x00, 0x1f);
  1775. break;
  1776. case 6000000:
  1777. cxd2841er_set_reg_bits(
  1778. priv, I2C_SLVT, 0xa3, 0x14, 0x1f);
  1779. break;
  1780. }
  1781. /* Set SLV-T Bank : 0x40 */
  1782. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  1783. switch (bandwidth) {
  1784. case 8000000:
  1785. cxd2841er_set_reg_bits(
  1786. priv, I2C_SLVT, 0x26, 0x0b, 0x0f);
  1787. cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x3e);
  1788. break;
  1789. case 7000000:
  1790. cxd2841er_set_reg_bits(
  1791. priv, I2C_SLVT, 0x26, 0x09, 0x0f);
  1792. cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0xd6);
  1793. break;
  1794. case 6000000:
  1795. cxd2841er_set_reg_bits(
  1796. priv, I2C_SLVT, 0x26, 0x08, 0x0f);
  1797. cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x6e);
  1798. break;
  1799. }
  1800. return 0;
  1801. }
  1802. static int cxd2841er_sleep_tc_to_active_t(struct cxd2841er_priv *priv,
  1803. u32 bandwidth)
  1804. {
  1805. u8 data[2] = { 0x09, 0x54 };
  1806. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1807. cxd2841er_set_ts_clock_mode(priv, SYS_DVBT);
  1808. /* Set SLV-X Bank : 0x00 */
  1809. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  1810. /* Set demod mode */
  1811. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
  1812. /* Set SLV-T Bank : 0x00 */
  1813. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1814. /* Enable demod clock */
  1815. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  1816. /* Disable RF level monitor */
  1817. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  1818. /* Enable ADC clock */
  1819. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  1820. /* Enable ADC 1 */
  1821. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
  1822. /* xtal freq 20.5MHz */
  1823. cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
  1824. /* Enable ADC 4 */
  1825. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  1826. /* Set SLV-T Bank : 0x10 */
  1827. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1828. /* IFAGC gain settings */
  1829. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f);
  1830. /* Set SLV-T Bank : 0x11 */
  1831. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  1832. /* BBAGC TARGET level setting */
  1833. cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50);
  1834. /* Set SLV-T Bank : 0x10 */
  1835. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1836. /* ASCOT setting ON */
  1837. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01);
  1838. /* Set SLV-T Bank : 0x18 */
  1839. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x18);
  1840. /* Pre-RS BER moniter setting */
  1841. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x36, 0x40, 0x07);
  1842. /* FEC Auto Recovery setting */
  1843. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x30, 0x01, 0x01);
  1844. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x31, 0x01, 0x01);
  1845. /* Set SLV-T Bank : 0x00 */
  1846. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1847. /* TSIF setting */
  1848. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
  1849. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
  1850. cxd2841er_sleep_tc_to_active_t_band(priv, bandwidth);
  1851. /* Set SLV-T Bank : 0x00 */
  1852. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1853. /* Disable HiZ Setting 1 */
  1854. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
  1855. /* Disable HiZ Setting 2 */
  1856. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  1857. priv->state = STATE_ACTIVE_TC;
  1858. return 0;
  1859. }
  1860. static int cxd2841er_sleep_tc_to_active_t2(struct cxd2841er_priv *priv,
  1861. u32 bandwidth)
  1862. {
  1863. u8 data[2] = { 0x09, 0x54 };
  1864. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1865. cxd2841er_set_ts_clock_mode(priv, SYS_DVBT2);
  1866. /* Set SLV-X Bank : 0x00 */
  1867. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  1868. /* Set demod mode */
  1869. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x02);
  1870. /* Set SLV-T Bank : 0x00 */
  1871. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1872. /* Enable demod clock */
  1873. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  1874. /* Disable RF level monitor */
  1875. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  1876. /* Enable ADC clock */
  1877. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  1878. /* Enable ADC 1 */
  1879. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
  1880. /* xtal freq 20.5MHz */
  1881. cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
  1882. /* Enable ADC 4 */
  1883. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  1884. /* Set SLV-T Bank : 0x10 */
  1885. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1886. /* IFAGC gain settings */
  1887. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f);
  1888. /* Set SLV-T Bank : 0x11 */
  1889. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  1890. /* BBAGC TARGET level setting */
  1891. cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50);
  1892. /* Set SLV-T Bank : 0x10 */
  1893. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1894. /* ASCOT setting ON */
  1895. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01);
  1896. /* Set SLV-T Bank : 0x20 */
  1897. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  1898. /* Acquisition optimization setting */
  1899. cxd2841er_write_reg(priv, I2C_SLVT, 0x8b, 0x3c);
  1900. /* Set SLV-T Bank : 0x2b */
  1901. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
  1902. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x76, 0x20, 0x70);
  1903. /* Set SLV-T Bank : 0x00 */
  1904. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1905. /* TSIF setting */
  1906. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
  1907. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
  1908. /* DVB-T2 initial setting */
  1909. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
  1910. cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x10);
  1911. cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x34);
  1912. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f);
  1913. cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xd8);
  1914. /* Set SLV-T Bank : 0x2a */
  1915. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a);
  1916. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x04, 0x0f);
  1917. /* Set SLV-T Bank : 0x2b */
  1918. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
  1919. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x20, 0x3f);
  1920. cxd2841er_sleep_tc_to_active_t2_band(priv, bandwidth);
  1921. /* Set SLV-T Bank : 0x00 */
  1922. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1923. /* Disable HiZ Setting 1 */
  1924. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
  1925. /* Disable HiZ Setting 2 */
  1926. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  1927. priv->state = STATE_ACTIVE_TC;
  1928. return 0;
  1929. }
  1930. static int cxd2841er_sleep_tc_to_active_c(struct cxd2841er_priv *priv,
  1931. u32 bandwidth)
  1932. {
  1933. u8 data[2] = { 0x09, 0x54 };
  1934. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1935. cxd2841er_set_ts_clock_mode(priv, SYS_DVBC_ANNEX_A);
  1936. /* Set SLV-X Bank : 0x00 */
  1937. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  1938. /* Set demod mode */
  1939. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x04);
  1940. /* Set SLV-T Bank : 0x00 */
  1941. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1942. /* Enable demod clock */
  1943. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  1944. /* Disable RF level monitor */
  1945. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  1946. /* Enable ADC clock */
  1947. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  1948. /* Enable ADC 1 */
  1949. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
  1950. /* xtal freq 20.5MHz */
  1951. cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
  1952. /* Enable ADC 4 */
  1953. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  1954. /* Set SLV-T Bank : 0x10 */
  1955. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1956. /* IFAGC gain settings */
  1957. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x09, 0x1f);
  1958. /* Set SLV-T Bank : 0x11 */
  1959. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  1960. /* BBAGC TARGET level setting */
  1961. cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x48);
  1962. /* Set SLV-T Bank : 0x10 */
  1963. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1964. /* ASCOT setting ON */
  1965. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01);
  1966. /* Set SLV-T Bank : 0x40 */
  1967. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  1968. /* Demod setting */
  1969. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc3, 0x00, 0x04);
  1970. /* Set SLV-T Bank : 0x00 */
  1971. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1972. /* TSIF setting */
  1973. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
  1974. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
  1975. cxd2841er_sleep_tc_to_active_c_band(priv, 8000000);
  1976. /* Set SLV-T Bank : 0x00 */
  1977. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  1978. /* Disable HiZ Setting 1 */
  1979. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
  1980. /* Disable HiZ Setting 2 */
  1981. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  1982. priv->state = STATE_ACTIVE_TC;
  1983. return 0;
  1984. }
  1985. static int cxd2841er_get_frontend(struct dvb_frontend *fe)
  1986. {
  1987. enum fe_status status = 0;
  1988. u16 strength = 0, snr = 0;
  1989. u32 errors = 0, ber = 0;
  1990. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1991. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1992. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1993. if (priv->state == STATE_ACTIVE_S)
  1994. cxd2841er_read_status_s(fe, &status);
  1995. else if (priv->state == STATE_ACTIVE_TC)
  1996. cxd2841er_read_status_tc(fe, &status);
  1997. if (status & FE_HAS_LOCK) {
  1998. cxd2841er_read_signal_strength(fe, &strength);
  1999. p->strength.len = 1;
  2000. p->strength.stat[0].scale = FE_SCALE_RELATIVE;
  2001. p->strength.stat[0].uvalue = strength;
  2002. cxd2841er_read_snr(fe, &snr);
  2003. p->cnr.len = 1;
  2004. p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
  2005. p->cnr.stat[0].svalue = snr;
  2006. cxd2841er_read_ucblocks(fe, &errors);
  2007. p->block_error.len = 1;
  2008. p->block_error.stat[0].scale = FE_SCALE_COUNTER;
  2009. p->block_error.stat[0].uvalue = errors;
  2010. cxd2841er_read_ber(fe, &ber);
  2011. p->post_bit_error.len = 1;
  2012. p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  2013. p->post_bit_error.stat[0].uvalue = ber;
  2014. } else {
  2015. p->strength.len = 1;
  2016. p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  2017. p->cnr.len = 1;
  2018. p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  2019. p->block_error.len = 1;
  2020. p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  2021. p->post_bit_error.len = 1;
  2022. p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  2023. }
  2024. return 0;
  2025. }
  2026. static int cxd2841er_set_frontend_s(struct dvb_frontend *fe)
  2027. {
  2028. int ret = 0, i, timeout, carr_offset;
  2029. enum fe_status status;
  2030. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2031. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  2032. u32 symbol_rate = p->symbol_rate/1000;
  2033. dev_dbg(&priv->i2c->dev, "%s(): %s frequency=%d symbol_rate=%d\n",
  2034. __func__,
  2035. (p->delivery_system == SYS_DVBS ? "DVB-S" : "DVB-S2"),
  2036. p->frequency, symbol_rate);
  2037. switch (priv->state) {
  2038. case STATE_SLEEP_S:
  2039. ret = cxd2841er_sleep_s_to_active_s(
  2040. priv, p->delivery_system, symbol_rate);
  2041. break;
  2042. case STATE_ACTIVE_S:
  2043. ret = cxd2841er_retune_active(priv, p);
  2044. break;
  2045. default:
  2046. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  2047. __func__, priv->state);
  2048. ret = -EINVAL;
  2049. goto done;
  2050. }
  2051. if (ret) {
  2052. dev_dbg(&priv->i2c->dev, "%s(): tune failed\n", __func__);
  2053. goto done;
  2054. }
  2055. if (fe->ops.i2c_gate_ctrl)
  2056. fe->ops.i2c_gate_ctrl(fe, 1);
  2057. if (fe->ops.tuner_ops.set_params)
  2058. fe->ops.tuner_ops.set_params(fe);
  2059. if (fe->ops.i2c_gate_ctrl)
  2060. fe->ops.i2c_gate_ctrl(fe, 0);
  2061. cxd2841er_tune_done(priv);
  2062. timeout = ((3000000 + (symbol_rate - 1)) / symbol_rate) + 150;
  2063. for (i = 0; i < timeout / CXD2841ER_DVBS_POLLING_INVL; i++) {
  2064. usleep_range(CXD2841ER_DVBS_POLLING_INVL*1000,
  2065. (CXD2841ER_DVBS_POLLING_INVL + 2) * 1000);
  2066. cxd2841er_read_status_s(fe, &status);
  2067. if (status & FE_HAS_LOCK)
  2068. break;
  2069. }
  2070. if (status & FE_HAS_LOCK) {
  2071. if (cxd2841er_get_carrier_offset_s_s2(
  2072. priv, &carr_offset)) {
  2073. ret = -EINVAL;
  2074. goto done;
  2075. }
  2076. dev_dbg(&priv->i2c->dev, "%s(): carrier_offset=%d\n",
  2077. __func__, carr_offset);
  2078. }
  2079. done:
  2080. return ret;
  2081. }
  2082. static int cxd2841er_set_frontend_tc(struct dvb_frontend *fe)
  2083. {
  2084. int ret = 0, timeout;
  2085. enum fe_status status;
  2086. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2087. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  2088. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2089. if (p->delivery_system == SYS_DVBT) {
  2090. priv->system = SYS_DVBT;
  2091. switch (priv->state) {
  2092. case STATE_SLEEP_TC:
  2093. ret = cxd2841er_sleep_tc_to_active_t(
  2094. priv, p->bandwidth_hz);
  2095. break;
  2096. case STATE_ACTIVE_TC:
  2097. ret = cxd2841er_retune_active(priv, p);
  2098. break;
  2099. default:
  2100. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  2101. __func__, priv->state);
  2102. ret = -EINVAL;
  2103. }
  2104. } else if (p->delivery_system == SYS_DVBT2) {
  2105. priv->system = SYS_DVBT2;
  2106. cxd2841er_dvbt2_set_plp_config(priv,
  2107. (int)(p->stream_id > 255), p->stream_id);
  2108. cxd2841er_dvbt2_set_profile(priv, DVBT2_PROFILE_BASE);
  2109. switch (priv->state) {
  2110. case STATE_SLEEP_TC:
  2111. ret = cxd2841er_sleep_tc_to_active_t2(priv,
  2112. p->bandwidth_hz);
  2113. break;
  2114. case STATE_ACTIVE_TC:
  2115. ret = cxd2841er_retune_active(priv, p);
  2116. break;
  2117. default:
  2118. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  2119. __func__, priv->state);
  2120. ret = -EINVAL;
  2121. }
  2122. } else if (p->delivery_system == SYS_DVBC_ANNEX_A ||
  2123. p->delivery_system == SYS_DVBC_ANNEX_C) {
  2124. priv->system = SYS_DVBC_ANNEX_A;
  2125. switch (priv->state) {
  2126. case STATE_SLEEP_TC:
  2127. ret = cxd2841er_sleep_tc_to_active_c(
  2128. priv, p->bandwidth_hz);
  2129. break;
  2130. case STATE_ACTIVE_TC:
  2131. ret = cxd2841er_retune_active(priv, p);
  2132. break;
  2133. default:
  2134. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  2135. __func__, priv->state);
  2136. ret = -EINVAL;
  2137. }
  2138. } else {
  2139. dev_dbg(&priv->i2c->dev,
  2140. "%s(): invalid delivery system %d\n",
  2141. __func__, p->delivery_system);
  2142. ret = -EINVAL;
  2143. }
  2144. if (ret)
  2145. goto done;
  2146. if (fe->ops.i2c_gate_ctrl)
  2147. fe->ops.i2c_gate_ctrl(fe, 1);
  2148. if (fe->ops.tuner_ops.set_params)
  2149. fe->ops.tuner_ops.set_params(fe);
  2150. if (fe->ops.i2c_gate_ctrl)
  2151. fe->ops.i2c_gate_ctrl(fe, 0);
  2152. cxd2841er_tune_done(priv);
  2153. timeout = 2500;
  2154. while (timeout > 0) {
  2155. ret = cxd2841er_read_status_tc(fe, &status);
  2156. if (ret)
  2157. goto done;
  2158. if (status & FE_HAS_LOCK)
  2159. break;
  2160. msleep(20);
  2161. timeout -= 20;
  2162. }
  2163. if (timeout < 0)
  2164. dev_dbg(&priv->i2c->dev,
  2165. "%s(): LOCK wait timeout\n", __func__);
  2166. done:
  2167. return ret;
  2168. }
  2169. static int cxd2841er_tune_s(struct dvb_frontend *fe,
  2170. bool re_tune,
  2171. unsigned int mode_flags,
  2172. unsigned int *delay,
  2173. enum fe_status *status)
  2174. {
  2175. int ret, carrier_offset;
  2176. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2177. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  2178. dev_dbg(&priv->i2c->dev, "%s() re_tune=%d\n", __func__, re_tune);
  2179. if (re_tune) {
  2180. ret = cxd2841er_set_frontend_s(fe);
  2181. if (ret)
  2182. return ret;
  2183. cxd2841er_read_status_s(fe, status);
  2184. if (*status & FE_HAS_LOCK) {
  2185. if (cxd2841er_get_carrier_offset_s_s2(
  2186. priv, &carrier_offset))
  2187. return -EINVAL;
  2188. p->frequency += carrier_offset;
  2189. ret = cxd2841er_set_frontend_s(fe);
  2190. if (ret)
  2191. return ret;
  2192. }
  2193. }
  2194. *delay = HZ / 5;
  2195. return cxd2841er_read_status_s(fe, status);
  2196. }
  2197. static int cxd2841er_tune_tc(struct dvb_frontend *fe,
  2198. bool re_tune,
  2199. unsigned int mode_flags,
  2200. unsigned int *delay,
  2201. enum fe_status *status)
  2202. {
  2203. int ret, carrier_offset;
  2204. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2205. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  2206. dev_dbg(&priv->i2c->dev, "%s(): re_tune %d\n", __func__, re_tune);
  2207. if (re_tune) {
  2208. ret = cxd2841er_set_frontend_tc(fe);
  2209. if (ret)
  2210. return ret;
  2211. cxd2841er_read_status_tc(fe, status);
  2212. if (*status & FE_HAS_LOCK) {
  2213. switch (priv->system) {
  2214. case SYS_DVBT:
  2215. case SYS_DVBT2:
  2216. ret = cxd2841er_get_carrier_offset_t2(
  2217. priv, p->bandwidth_hz,
  2218. &carrier_offset);
  2219. break;
  2220. case SYS_DVBC_ANNEX_A:
  2221. ret = cxd2841er_get_carrier_offset_c(
  2222. priv, &carrier_offset);
  2223. break;
  2224. default:
  2225. dev_dbg(&priv->i2c->dev,
  2226. "%s(): invalid delivery system %d\n",
  2227. __func__, priv->system);
  2228. return -EINVAL;
  2229. }
  2230. if (ret)
  2231. return ret;
  2232. dev_dbg(&priv->i2c->dev, "%s(): carrier offset %d\n",
  2233. __func__, carrier_offset);
  2234. p->frequency += carrier_offset;
  2235. ret = cxd2841er_set_frontend_tc(fe);
  2236. if (ret)
  2237. return ret;
  2238. }
  2239. }
  2240. *delay = HZ / 5;
  2241. return cxd2841er_read_status_tc(fe, status);
  2242. }
  2243. static int cxd2841er_sleep_s(struct dvb_frontend *fe)
  2244. {
  2245. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2246. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2247. cxd2841er_active_s_to_sleep_s(fe->demodulator_priv);
  2248. cxd2841er_sleep_s_to_shutdown(fe->demodulator_priv);
  2249. return 0;
  2250. }
  2251. static int cxd2841er_sleep_tc(struct dvb_frontend *fe)
  2252. {
  2253. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2254. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2255. if (priv->state == STATE_ACTIVE_TC) {
  2256. switch (priv->system) {
  2257. case SYS_DVBT:
  2258. cxd2841er_active_t_to_sleep_tc(priv);
  2259. break;
  2260. case SYS_DVBT2:
  2261. cxd2841er_active_t2_to_sleep_tc(priv);
  2262. break;
  2263. case SYS_DVBC_ANNEX_A:
  2264. cxd2841er_active_c_to_sleep_tc(priv);
  2265. break;
  2266. default:
  2267. dev_warn(&priv->i2c->dev,
  2268. "%s(): unknown delivery system %d\n",
  2269. __func__, priv->system);
  2270. }
  2271. }
  2272. if (priv->state != STATE_SLEEP_TC) {
  2273. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  2274. __func__, priv->state);
  2275. return -EINVAL;
  2276. }
  2277. cxd2841er_sleep_tc_to_shutdown(priv);
  2278. return 0;
  2279. }
  2280. static int cxd2841er_send_burst(struct dvb_frontend *fe,
  2281. enum fe_sec_mini_cmd burst)
  2282. {
  2283. u8 data;
  2284. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2285. dev_dbg(&priv->i2c->dev, "%s(): burst mode %s\n", __func__,
  2286. (burst == SEC_MINI_A ? "A" : "B"));
  2287. if (priv->state != STATE_SLEEP_S &&
  2288. priv->state != STATE_ACTIVE_S) {
  2289. dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  2290. __func__, priv->state);
  2291. return -EINVAL;
  2292. }
  2293. data = (burst == SEC_MINI_A ? 0 : 1);
  2294. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
  2295. cxd2841er_write_reg(priv, I2C_SLVT, 0x34, 0x01);
  2296. cxd2841er_write_reg(priv, I2C_SLVT, 0x35, data);
  2297. return 0;
  2298. }
  2299. static int cxd2841er_set_tone(struct dvb_frontend *fe,
  2300. enum fe_sec_tone_mode tone)
  2301. {
  2302. u8 data;
  2303. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2304. dev_dbg(&priv->i2c->dev, "%s(): tone %s\n", __func__,
  2305. (tone == SEC_TONE_ON ? "On" : "Off"));
  2306. if (priv->state != STATE_SLEEP_S &&
  2307. priv->state != STATE_ACTIVE_S) {
  2308. dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  2309. __func__, priv->state);
  2310. return -EINVAL;
  2311. }
  2312. data = (tone == SEC_TONE_ON ? 1 : 0);
  2313. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
  2314. cxd2841er_write_reg(priv, I2C_SLVT, 0x36, data);
  2315. return 0;
  2316. }
  2317. static int cxd2841er_send_diseqc_msg(struct dvb_frontend *fe,
  2318. struct dvb_diseqc_master_cmd *cmd)
  2319. {
  2320. int i;
  2321. u8 data[12];
  2322. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2323. if (priv->state != STATE_SLEEP_S &&
  2324. priv->state != STATE_ACTIVE_S) {
  2325. dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  2326. __func__, priv->state);
  2327. return -EINVAL;
  2328. }
  2329. dev_dbg(&priv->i2c->dev,
  2330. "%s(): cmd->len %d\n", __func__, cmd->msg_len);
  2331. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
  2332. /* DiDEqC enable */
  2333. cxd2841er_write_reg(priv, I2C_SLVT, 0x33, 0x01);
  2334. /* cmd1 length & data */
  2335. cxd2841er_write_reg(priv, I2C_SLVT, 0x3d, cmd->msg_len);
  2336. memset(data, 0, sizeof(data));
  2337. for (i = 0; i < cmd->msg_len && i < sizeof(data); i++)
  2338. data[i] = cmd->msg[i];
  2339. cxd2841er_write_regs(priv, I2C_SLVT, 0x3e, data, sizeof(data));
  2340. /* repeat count for cmd1 */
  2341. cxd2841er_write_reg(priv, I2C_SLVT, 0x37, 1);
  2342. /* repeat count for cmd2: always 0 */
  2343. cxd2841er_write_reg(priv, I2C_SLVT, 0x38, 0);
  2344. /* start transmit */
  2345. cxd2841er_write_reg(priv, I2C_SLVT, 0x32, 0x01);
  2346. /* wait for 1 sec timeout */
  2347. for (i = 0; i < 50; i++) {
  2348. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, data);
  2349. if (!data[0]) {
  2350. dev_dbg(&priv->i2c->dev,
  2351. "%s(): DiSEqC cmd has been sent\n", __func__);
  2352. return 0;
  2353. }
  2354. msleep(20);
  2355. }
  2356. dev_dbg(&priv->i2c->dev,
  2357. "%s(): DiSEqC cmd transmit timeout\n", __func__);
  2358. return -ETIMEDOUT;
  2359. }
  2360. static void cxd2841er_release(struct dvb_frontend *fe)
  2361. {
  2362. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2363. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2364. kfree(priv);
  2365. }
  2366. static int cxd2841er_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  2367. {
  2368. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2369. dev_dbg(&priv->i2c->dev, "%s(): enable=%d\n", __func__, enable);
  2370. cxd2841er_set_reg_bits(
  2371. priv, I2C_SLVX, 0x8, (enable ? 0x01 : 0x00), 0x01);
  2372. return 0;
  2373. }
  2374. static enum dvbfe_algo cxd2841er_get_algo(struct dvb_frontend *fe)
  2375. {
  2376. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2377. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2378. return DVBFE_ALGO_HW;
  2379. }
  2380. static int cxd2841er_init_s(struct dvb_frontend *fe)
  2381. {
  2382. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2383. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2384. cxd2841er_shutdown_to_sleep_s(priv);
  2385. /* SONY_DEMOD_CONFIG_SAT_IFAGCNEG set to 1 */
  2386. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  2387. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xb9, 0x01, 0x01);
  2388. return 0;
  2389. }
  2390. static int cxd2841er_init_tc(struct dvb_frontend *fe)
  2391. {
  2392. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2393. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2394. cxd2841er_shutdown_to_sleep_tc(priv);
  2395. /* SONY_DEMOD_CONFIG_IFAGCNEG = 1 */
  2396. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2397. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcb, 0x40, 0x40);
  2398. /* SONY_DEMOD_CONFIG_IFAGC_ADC_FS = 0 */
  2399. cxd2841er_write_reg(priv, I2C_SLVT, 0xcd, 0x50);
  2400. /* SONY_DEMOD_CONFIG_PARALLEL_SEL = 1 */
  2401. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2402. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4, 0x00, 0x80);
  2403. return 0;
  2404. }
  2405. static struct dvb_frontend_ops cxd2841er_dvbs_s2_ops;
  2406. static struct dvb_frontend_ops cxd2841er_dvbt_t2_ops;
  2407. static struct dvb_frontend_ops cxd2841er_dvbc_ops;
  2408. static struct dvb_frontend *cxd2841er_attach(struct cxd2841er_config *cfg,
  2409. struct i2c_adapter *i2c,
  2410. u8 system)
  2411. {
  2412. u8 chip_id = 0;
  2413. const char *type;
  2414. struct cxd2841er_priv *priv = NULL;
  2415. /* allocate memory for the internal state */
  2416. priv = kzalloc(sizeof(struct cxd2841er_priv), GFP_KERNEL);
  2417. if (!priv)
  2418. return NULL;
  2419. priv->i2c = i2c;
  2420. priv->config = cfg;
  2421. priv->i2c_addr_slvx = (cfg->i2c_addr + 4) >> 1;
  2422. priv->i2c_addr_slvt = (cfg->i2c_addr) >> 1;
  2423. /* create dvb_frontend */
  2424. switch (system) {
  2425. case SYS_DVBS:
  2426. memcpy(&priv->frontend.ops,
  2427. &cxd2841er_dvbs_s2_ops,
  2428. sizeof(struct dvb_frontend_ops));
  2429. type = "S/S2";
  2430. break;
  2431. case SYS_DVBT:
  2432. memcpy(&priv->frontend.ops,
  2433. &cxd2841er_dvbt_t2_ops,
  2434. sizeof(struct dvb_frontend_ops));
  2435. type = "T/T2";
  2436. break;
  2437. case SYS_DVBC_ANNEX_A:
  2438. memcpy(&priv->frontend.ops,
  2439. &cxd2841er_dvbc_ops,
  2440. sizeof(struct dvb_frontend_ops));
  2441. type = "C/C2";
  2442. break;
  2443. default:
  2444. kfree(priv);
  2445. return NULL;
  2446. }
  2447. priv->frontend.demodulator_priv = priv;
  2448. dev_info(&priv->i2c->dev,
  2449. "%s(): attaching CXD2841ER DVB-%s frontend\n",
  2450. __func__, type);
  2451. dev_info(&priv->i2c->dev,
  2452. "%s(): I2C adapter %p SLVX addr %x SLVT addr %x\n",
  2453. __func__, priv->i2c,
  2454. priv->i2c_addr_slvx, priv->i2c_addr_slvt);
  2455. chip_id = cxd2841er_chip_id(priv);
  2456. if (chip_id != CXD2841ER_CHIP_ID) {
  2457. dev_err(&priv->i2c->dev, "%s(): invalid chip ID 0x%02x\n",
  2458. __func__, chip_id);
  2459. priv->frontend.demodulator_priv = NULL;
  2460. kfree(priv);
  2461. return NULL;
  2462. }
  2463. dev_info(&priv->i2c->dev, "%s(): chip ID 0x%02x OK.\n",
  2464. __func__, chip_id);
  2465. return &priv->frontend;
  2466. }
  2467. struct dvb_frontend *cxd2841er_attach_s(struct cxd2841er_config *cfg,
  2468. struct i2c_adapter *i2c)
  2469. {
  2470. return cxd2841er_attach(cfg, i2c, SYS_DVBS);
  2471. }
  2472. EXPORT_SYMBOL(cxd2841er_attach_s);
  2473. struct dvb_frontend *cxd2841er_attach_t(struct cxd2841er_config *cfg,
  2474. struct i2c_adapter *i2c)
  2475. {
  2476. return cxd2841er_attach(cfg, i2c, SYS_DVBT);
  2477. }
  2478. EXPORT_SYMBOL(cxd2841er_attach_t);
  2479. struct dvb_frontend *cxd2841er_attach_c(struct cxd2841er_config *cfg,
  2480. struct i2c_adapter *i2c)
  2481. {
  2482. return cxd2841er_attach(cfg, i2c, SYS_DVBC_ANNEX_A);
  2483. }
  2484. EXPORT_SYMBOL(cxd2841er_attach_c);
  2485. static struct dvb_frontend_ops cxd2841er_dvbs_s2_ops = {
  2486. .delsys = { SYS_DVBS, SYS_DVBS2 },
  2487. .info = {
  2488. .name = "Sony CXD2841ER DVB-S/S2 demodulator",
  2489. .frequency_min = 500000,
  2490. .frequency_max = 2500000,
  2491. .frequency_stepsize = 0,
  2492. .symbol_rate_min = 1000000,
  2493. .symbol_rate_max = 45000000,
  2494. .symbol_rate_tolerance = 500,
  2495. .caps = FE_CAN_INVERSION_AUTO |
  2496. FE_CAN_FEC_AUTO |
  2497. FE_CAN_QPSK,
  2498. },
  2499. .init = cxd2841er_init_s,
  2500. .sleep = cxd2841er_sleep_s,
  2501. .release = cxd2841er_release,
  2502. .set_frontend = cxd2841er_set_frontend_s,
  2503. .get_frontend = cxd2841er_get_frontend,
  2504. .read_status = cxd2841er_read_status_s,
  2505. .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl,
  2506. .get_frontend_algo = cxd2841er_get_algo,
  2507. .set_tone = cxd2841er_set_tone,
  2508. .diseqc_send_burst = cxd2841er_send_burst,
  2509. .diseqc_send_master_cmd = cxd2841er_send_diseqc_msg,
  2510. .tune = cxd2841er_tune_s
  2511. };
  2512. static struct dvb_frontend_ops cxd2841er_dvbt_t2_ops = {
  2513. .delsys = { SYS_DVBT, SYS_DVBT2 },
  2514. .info = {
  2515. .name = "Sony CXD2841ER DVB-T/T2 demodulator",
  2516. .caps = FE_CAN_FEC_1_2 |
  2517. FE_CAN_FEC_2_3 |
  2518. FE_CAN_FEC_3_4 |
  2519. FE_CAN_FEC_5_6 |
  2520. FE_CAN_FEC_7_8 |
  2521. FE_CAN_FEC_AUTO |
  2522. FE_CAN_QPSK |
  2523. FE_CAN_QAM_16 |
  2524. FE_CAN_QAM_32 |
  2525. FE_CAN_QAM_64 |
  2526. FE_CAN_QAM_128 |
  2527. FE_CAN_QAM_256 |
  2528. FE_CAN_QAM_AUTO |
  2529. FE_CAN_TRANSMISSION_MODE_AUTO |
  2530. FE_CAN_GUARD_INTERVAL_AUTO |
  2531. FE_CAN_HIERARCHY_AUTO |
  2532. FE_CAN_MUTE_TS |
  2533. FE_CAN_2G_MODULATION,
  2534. .frequency_min = 42000000,
  2535. .frequency_max = 1002000000,
  2536. .symbol_rate_min = 870000,
  2537. .symbol_rate_max = 11700000
  2538. },
  2539. .init = cxd2841er_init_tc,
  2540. .sleep = cxd2841er_sleep_tc,
  2541. .release = cxd2841er_release,
  2542. .set_frontend = cxd2841er_set_frontend_tc,
  2543. .get_frontend = cxd2841er_get_frontend,
  2544. .read_status = cxd2841er_read_status_tc,
  2545. .tune = cxd2841er_tune_tc,
  2546. .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl,
  2547. .get_frontend_algo = cxd2841er_get_algo
  2548. };
  2549. static struct dvb_frontend_ops cxd2841er_dvbc_ops = {
  2550. .delsys = { SYS_DVBC_ANNEX_A },
  2551. .info = {
  2552. .name = "Sony CXD2841ER DVB-C demodulator",
  2553. .caps = FE_CAN_FEC_1_2 |
  2554. FE_CAN_FEC_2_3 |
  2555. FE_CAN_FEC_3_4 |
  2556. FE_CAN_FEC_5_6 |
  2557. FE_CAN_FEC_7_8 |
  2558. FE_CAN_FEC_AUTO |
  2559. FE_CAN_QAM_16 |
  2560. FE_CAN_QAM_32 |
  2561. FE_CAN_QAM_64 |
  2562. FE_CAN_QAM_128 |
  2563. FE_CAN_QAM_256 |
  2564. FE_CAN_QAM_AUTO |
  2565. FE_CAN_INVERSION_AUTO,
  2566. .frequency_min = 42000000,
  2567. .frequency_max = 1002000000
  2568. },
  2569. .init = cxd2841er_init_tc,
  2570. .sleep = cxd2841er_sleep_tc,
  2571. .release = cxd2841er_release,
  2572. .set_frontend = cxd2841er_set_frontend_tc,
  2573. .get_frontend = cxd2841er_get_frontend,
  2574. .read_status = cxd2841er_read_status_tc,
  2575. .tune = cxd2841er_tune_tc,
  2576. .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl,
  2577. .get_frontend_algo = cxd2841er_get_algo,
  2578. };
  2579. MODULE_DESCRIPTION("Sony CXD2841ER DVB-C/C2/T/T2/S/S2 demodulator driver");
  2580. MODULE_AUTHOR("Sergey Kozlov <serjk@netup.ru>");
  2581. MODULE_LICENSE("GPL");