budget-ci.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  1. /*
  2. * budget-ci.c: driver for the SAA7146 based Budget DVB cards
  3. *
  4. * Compiled from various sources by Michael Hunold <michael@mihu.de>
  5. *
  6. * msp430 IR support contributed by Jack Thomasson <jkt@Helius.COM>
  7. * partially based on the Siemens DVB driver by Ralph+Marcus Metzler
  8. *
  9. * CI interface support (c) 2004 Andrew de Quincey <adq_dvb@lidskialf.net>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  26. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  27. *
  28. *
  29. * the project's page is at http://www.linuxtv.org/dvb/
  30. */
  31. #include <linux/module.h>
  32. #include <linux/errno.h>
  33. #include <linux/slab.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/input.h>
  36. #include <linux/spinlock.h>
  37. #include <media/ir-common.h>
  38. #include "budget.h"
  39. #include "dvb_ca_en50221.h"
  40. #include "stv0299.h"
  41. #include "stv0297.h"
  42. #include "tda1004x.h"
  43. #include "stb0899_drv.h"
  44. #include "stb0899_reg.h"
  45. #include "stb6100.h"
  46. #include "lnbp21.h"
  47. #include "bsbe1.h"
  48. #include "bsru6.h"
  49. #include "tda1002x.h"
  50. #include "tda827x.h"
  51. /*
  52. * Regarding DEBIADDR_IR:
  53. * Some CI modules hang if random addresses are read.
  54. * Using address 0x4000 for the IR read means that we
  55. * use the same address as for CI version, which should
  56. * be a safe default.
  57. */
  58. #define DEBIADDR_IR 0x4000
  59. #define DEBIADDR_CICONTROL 0x0000
  60. #define DEBIADDR_CIVERSION 0x4000
  61. #define DEBIADDR_IO 0x1000
  62. #define DEBIADDR_ATTR 0x3000
  63. #define CICONTROL_RESET 0x01
  64. #define CICONTROL_ENABLETS 0x02
  65. #define CICONTROL_CAMDETECT 0x08
  66. #define DEBICICTL 0x00420000
  67. #define DEBICICAM 0x02420000
  68. #define SLOTSTATUS_NONE 1
  69. #define SLOTSTATUS_PRESENT 2
  70. #define SLOTSTATUS_RESET 4
  71. #define SLOTSTATUS_READY 8
  72. #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
  73. /*
  74. * Milliseconds during which a key is regarded as pressed.
  75. * If an identical command arrives within this time, the timer will start over.
  76. */
  77. #define IR_KEYPRESS_TIMEOUT 250
  78. /* RC5 device wildcard */
  79. #define IR_DEVICE_ANY 255
  80. static int rc5_device = -1;
  81. module_param(rc5_device, int, 0644);
  82. MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");
  83. static int ir_debug;
  84. module_param(ir_debug, int, 0644);
  85. MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
  86. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  87. struct budget_ci_ir {
  88. struct input_dev *dev;
  89. struct tasklet_struct msp430_irq_tasklet;
  90. struct timer_list timer_keyup;
  91. char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
  92. char phys[32];
  93. struct ir_input_state state;
  94. int rc5_device;
  95. u32 last_raw;
  96. u32 ir_key;
  97. bool have_command;
  98. };
  99. struct budget_ci {
  100. struct budget budget;
  101. struct tasklet_struct ciintf_irq_tasklet;
  102. int slot_status;
  103. int ci_irq;
  104. struct dvb_ca_en50221 ca;
  105. struct budget_ci_ir ir;
  106. u8 tuner_pll_address; /* used for philips_tdm1316l configs */
  107. };
  108. static void msp430_ir_keyup(unsigned long data)
  109. {
  110. struct budget_ci_ir *ir = (struct budget_ci_ir *) data;
  111. ir_input_nokey(ir->dev, &ir->state);
  112. }
  113. static void msp430_ir_interrupt(unsigned long data)
  114. {
  115. struct budget_ci *budget_ci = (struct budget_ci *) data;
  116. struct input_dev *dev = budget_ci->ir.dev;
  117. u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
  118. u32 raw;
  119. /*
  120. * The msp430 chip can generate two different bytes, command and device
  121. *
  122. * type1: X1CCCCCC, C = command bits (0 - 63)
  123. * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit
  124. *
  125. * Each signal from the remote control can generate one or more command
  126. * bytes and one or more device bytes. For the repeated bytes, the
  127. * highest bit (X) is set. The first command byte is always generated
  128. * before the first device byte. Other than that, no specific order
  129. * seems to apply. To make life interesting, bytes can also be lost.
  130. *
  131. * Only when we have a command and device byte, a keypress is
  132. * generated.
  133. */
  134. if (ir_debug)
  135. printk("budget_ci: received byte 0x%02x\n", command);
  136. /* Remove repeat bit, we use every command */
  137. command = command & 0x7f;
  138. /* Is this a RC5 command byte? */
  139. if (command & 0x40) {
  140. budget_ci->ir.have_command = true;
  141. budget_ci->ir.ir_key = command & 0x3f;
  142. return;
  143. }
  144. /* It's a RC5 device byte */
  145. if (!budget_ci->ir.have_command)
  146. return;
  147. budget_ci->ir.have_command = false;
  148. if (budget_ci->ir.rc5_device != IR_DEVICE_ANY &&
  149. budget_ci->ir.rc5_device != (command & 0x1f))
  150. return;
  151. /* Is this a repeated key sequence? (same device, command, toggle) */
  152. raw = budget_ci->ir.ir_key | (command << 8);
  153. if (budget_ci->ir.last_raw != raw || !timer_pending(&budget_ci->ir.timer_keyup)) {
  154. ir_input_nokey(dev, &budget_ci->ir.state);
  155. ir_input_keydown(dev, &budget_ci->ir.state,
  156. budget_ci->ir.ir_key, raw);
  157. budget_ci->ir.last_raw = raw;
  158. }
  159. mod_timer(&budget_ci->ir.timer_keyup, jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT));
  160. }
  161. static int msp430_ir_init(struct budget_ci *budget_ci)
  162. {
  163. struct saa7146_dev *saa = budget_ci->budget.dev;
  164. struct input_dev *input_dev = budget_ci->ir.dev;
  165. int error;
  166. budget_ci->ir.dev = input_dev = input_allocate_device();
  167. if (!input_dev) {
  168. printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
  169. error = -ENOMEM;
  170. goto out1;
  171. }
  172. snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
  173. "Budget-CI dvb ir receiver %s", saa->name);
  174. snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
  175. "pci-%s/ir0", pci_name(saa->pci));
  176. input_dev->name = budget_ci->ir.name;
  177. input_dev->phys = budget_ci->ir.phys;
  178. input_dev->id.bustype = BUS_PCI;
  179. input_dev->id.version = 1;
  180. if (saa->pci->subsystem_vendor) {
  181. input_dev->id.vendor = saa->pci->subsystem_vendor;
  182. input_dev->id.product = saa->pci->subsystem_device;
  183. } else {
  184. input_dev->id.vendor = saa->pci->vendor;
  185. input_dev->id.product = saa->pci->device;
  186. }
  187. input_dev->dev.parent = &saa->pci->dev;
  188. /* Select keymap and address */
  189. switch (budget_ci->budget.dev->pci->subsystem_device) {
  190. case 0x100c:
  191. case 0x100f:
  192. case 0x1011:
  193. case 0x1012:
  194. /* The hauppauge keymap is a superset of these remotes */
  195. ir_input_init(input_dev, &budget_ci->ir.state,
  196. IR_TYPE_RC5, ir_codes_hauppauge_new);
  197. if (rc5_device < 0)
  198. budget_ci->ir.rc5_device = 0x1f;
  199. else
  200. budget_ci->ir.rc5_device = rc5_device;
  201. break;
  202. case 0x1010:
  203. case 0x1017:
  204. case 0x101a:
  205. /* for the Technotrend 1500 bundled remote */
  206. ir_input_init(input_dev, &budget_ci->ir.state,
  207. IR_TYPE_RC5, ir_codes_tt_1500);
  208. if (rc5_device < 0)
  209. budget_ci->ir.rc5_device = IR_DEVICE_ANY;
  210. else
  211. budget_ci->ir.rc5_device = rc5_device;
  212. break;
  213. default:
  214. /* unknown remote */
  215. ir_input_init(input_dev, &budget_ci->ir.state,
  216. IR_TYPE_RC5, ir_codes_budget_ci_old);
  217. if (rc5_device < 0)
  218. budget_ci->ir.rc5_device = IR_DEVICE_ANY;
  219. else
  220. budget_ci->ir.rc5_device = rc5_device;
  221. break;
  222. }
  223. /* initialise the key-up timeout handler */
  224. init_timer(&budget_ci->ir.timer_keyup);
  225. budget_ci->ir.timer_keyup.function = msp430_ir_keyup;
  226. budget_ci->ir.timer_keyup.data = (unsigned long) &budget_ci->ir;
  227. budget_ci->ir.last_raw = 0xffff; /* An impossible value */
  228. error = input_register_device(input_dev);
  229. if (error) {
  230. printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
  231. goto out2;
  232. }
  233. /* note: these must be after input_register_device */
  234. input_dev->rep[REP_DELAY] = 400;
  235. input_dev->rep[REP_PERIOD] = 250;
  236. tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
  237. (unsigned long) budget_ci);
  238. SAA7146_IER_ENABLE(saa, MASK_06);
  239. saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
  240. return 0;
  241. out2:
  242. input_free_device(input_dev);
  243. out1:
  244. return error;
  245. }
  246. static void msp430_ir_deinit(struct budget_ci *budget_ci)
  247. {
  248. struct saa7146_dev *saa = budget_ci->budget.dev;
  249. struct input_dev *dev = budget_ci->ir.dev;
  250. SAA7146_IER_DISABLE(saa, MASK_06);
  251. saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
  252. tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
  253. del_timer_sync(&dev->timer);
  254. ir_input_nokey(dev, &budget_ci->ir.state);
  255. input_unregister_device(dev);
  256. }
  257. static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
  258. {
  259. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  260. if (slot != 0)
  261. return -EINVAL;
  262. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  263. DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
  264. }
  265. static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
  266. {
  267. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  268. if (slot != 0)
  269. return -EINVAL;
  270. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  271. DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
  272. }
  273. static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
  274. {
  275. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  276. if (slot != 0)
  277. return -EINVAL;
  278. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  279. DEBIADDR_IO | (address & 3), 1, 1, 0);
  280. }
  281. static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
  282. {
  283. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  284. if (slot != 0)
  285. return -EINVAL;
  286. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  287. DEBIADDR_IO | (address & 3), 1, value, 1, 0);
  288. }
  289. static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
  290. {
  291. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  292. struct saa7146_dev *saa = budget_ci->budget.dev;
  293. if (slot != 0)
  294. return -EINVAL;
  295. if (budget_ci->ci_irq) {
  296. // trigger on RISING edge during reset so we know when READY is re-asserted
  297. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  298. }
  299. budget_ci->slot_status = SLOTSTATUS_RESET;
  300. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  301. msleep(1);
  302. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  303. CICONTROL_RESET, 1, 0);
  304. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  305. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  306. return 0;
  307. }
  308. static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
  309. {
  310. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  311. struct saa7146_dev *saa = budget_ci->budget.dev;
  312. if (slot != 0)
  313. return -EINVAL;
  314. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  315. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  316. return 0;
  317. }
  318. static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
  319. {
  320. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  321. struct saa7146_dev *saa = budget_ci->budget.dev;
  322. int tmp;
  323. if (slot != 0)
  324. return -EINVAL;
  325. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
  326. tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  327. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  328. tmp | CICONTROL_ENABLETS, 1, 0);
  329. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
  330. return 0;
  331. }
  332. static void ciintf_interrupt(unsigned long data)
  333. {
  334. struct budget_ci *budget_ci = (struct budget_ci *) data;
  335. struct saa7146_dev *saa = budget_ci->budget.dev;
  336. unsigned int flags;
  337. // ensure we don't get spurious IRQs during initialisation
  338. if (!budget_ci->budget.ci_present)
  339. return;
  340. // read the CAM status
  341. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  342. if (flags & CICONTROL_CAMDETECT) {
  343. // GPIO should be set to trigger on falling edge if a CAM is present
  344. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  345. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  346. // CAM insertion IRQ
  347. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  348. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  349. DVB_CA_EN50221_CAMCHANGE_INSERTED);
  350. } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  351. // CAM ready (reset completed)
  352. budget_ci->slot_status = SLOTSTATUS_READY;
  353. dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
  354. } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
  355. // FR/DA IRQ
  356. dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
  357. }
  358. } else {
  359. // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
  360. // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
  361. // the CAM might not actually be ready yet.
  362. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  363. // generate a CAM removal IRQ if we haven't already
  364. if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
  365. // CAM removal IRQ
  366. budget_ci->slot_status = SLOTSTATUS_NONE;
  367. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  368. DVB_CA_EN50221_CAMCHANGE_REMOVED);
  369. }
  370. }
  371. }
  372. static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
  373. {
  374. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  375. unsigned int flags;
  376. // ensure we don't get spurious IRQs during initialisation
  377. if (!budget_ci->budget.ci_present)
  378. return -EINVAL;
  379. // read the CAM status
  380. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  381. if (flags & CICONTROL_CAMDETECT) {
  382. // mark it as present if it wasn't before
  383. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  384. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  385. }
  386. // during a RESET, we check if we can read from IO memory to see when CAM is ready
  387. if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  388. if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
  389. budget_ci->slot_status = SLOTSTATUS_READY;
  390. }
  391. }
  392. } else {
  393. budget_ci->slot_status = SLOTSTATUS_NONE;
  394. }
  395. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  396. if (budget_ci->slot_status & SLOTSTATUS_READY) {
  397. return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
  398. }
  399. return DVB_CA_EN50221_POLL_CAM_PRESENT;
  400. }
  401. return 0;
  402. }
  403. static int ciintf_init(struct budget_ci *budget_ci)
  404. {
  405. struct saa7146_dev *saa = budget_ci->budget.dev;
  406. int flags;
  407. int result;
  408. int ci_version;
  409. int ca_flags;
  410. memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
  411. // enable DEBI pins
  412. saa7146_write(saa, MC1, MASK_27 | MASK_11);
  413. // test if it is there
  414. ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
  415. if ((ci_version & 0xa0) != 0xa0) {
  416. result = -ENODEV;
  417. goto error;
  418. }
  419. // determine whether a CAM is present or not
  420. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  421. budget_ci->slot_status = SLOTSTATUS_NONE;
  422. if (flags & CICONTROL_CAMDETECT)
  423. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  424. // version 0xa2 of the CI firmware doesn't generate interrupts
  425. if (ci_version == 0xa2) {
  426. ca_flags = 0;
  427. budget_ci->ci_irq = 0;
  428. } else {
  429. ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
  430. DVB_CA_EN50221_FLAG_IRQ_FR |
  431. DVB_CA_EN50221_FLAG_IRQ_DA;
  432. budget_ci->ci_irq = 1;
  433. }
  434. // register CI interface
  435. budget_ci->ca.owner = THIS_MODULE;
  436. budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
  437. budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
  438. budget_ci->ca.read_cam_control = ciintf_read_cam_control;
  439. budget_ci->ca.write_cam_control = ciintf_write_cam_control;
  440. budget_ci->ca.slot_reset = ciintf_slot_reset;
  441. budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
  442. budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
  443. budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
  444. budget_ci->ca.data = budget_ci;
  445. if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
  446. &budget_ci->ca,
  447. ca_flags, 1)) != 0) {
  448. printk("budget_ci: CI interface detected, but initialisation failed.\n");
  449. goto error;
  450. }
  451. // Setup CI slot IRQ
  452. if (budget_ci->ci_irq) {
  453. tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
  454. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  455. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  456. } else {
  457. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  458. }
  459. SAA7146_IER_ENABLE(saa, MASK_03);
  460. }
  461. // enable interface
  462. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  463. CICONTROL_RESET, 1, 0);
  464. // success!
  465. printk("budget_ci: CI interface initialised\n");
  466. budget_ci->budget.ci_present = 1;
  467. // forge a fake CI IRQ so the CAM state is setup correctly
  468. if (budget_ci->ci_irq) {
  469. flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
  470. if (budget_ci->slot_status != SLOTSTATUS_NONE)
  471. flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
  472. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
  473. }
  474. return 0;
  475. error:
  476. saa7146_write(saa, MC1, MASK_27);
  477. return result;
  478. }
  479. static void ciintf_deinit(struct budget_ci *budget_ci)
  480. {
  481. struct saa7146_dev *saa = budget_ci->budget.dev;
  482. // disable CI interrupts
  483. if (budget_ci->ci_irq) {
  484. SAA7146_IER_DISABLE(saa, MASK_03);
  485. saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
  486. tasklet_kill(&budget_ci->ciintf_irq_tasklet);
  487. }
  488. // reset interface
  489. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  490. msleep(1);
  491. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  492. CICONTROL_RESET, 1, 0);
  493. // disable TS data stream to CI interface
  494. saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
  495. // release the CA device
  496. dvb_ca_en50221_release(&budget_ci->ca);
  497. // disable DEBI pins
  498. saa7146_write(saa, MC1, MASK_27);
  499. }
  500. static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
  501. {
  502. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  503. dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
  504. if (*isr & MASK_06)
  505. tasklet_schedule(&budget_ci->ir.msp430_irq_tasklet);
  506. if (*isr & MASK_10)
  507. ttpci_budget_irq10_handler(dev, isr);
  508. if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
  509. tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
  510. }
  511. static u8 philips_su1278_tt_inittab[] = {
  512. 0x01, 0x0f,
  513. 0x02, 0x30,
  514. 0x03, 0x00,
  515. 0x04, 0x5b,
  516. 0x05, 0x85,
  517. 0x06, 0x02,
  518. 0x07, 0x00,
  519. 0x08, 0x02,
  520. 0x09, 0x00,
  521. 0x0C, 0x01,
  522. 0x0D, 0x81,
  523. 0x0E, 0x44,
  524. 0x0f, 0x14,
  525. 0x10, 0x3c,
  526. 0x11, 0x84,
  527. 0x12, 0xda,
  528. 0x13, 0x97,
  529. 0x14, 0x95,
  530. 0x15, 0xc9,
  531. 0x16, 0x19,
  532. 0x17, 0x8c,
  533. 0x18, 0x59,
  534. 0x19, 0xf8,
  535. 0x1a, 0xfe,
  536. 0x1c, 0x7f,
  537. 0x1d, 0x00,
  538. 0x1e, 0x00,
  539. 0x1f, 0x50,
  540. 0x20, 0x00,
  541. 0x21, 0x00,
  542. 0x22, 0x00,
  543. 0x23, 0x00,
  544. 0x28, 0x00,
  545. 0x29, 0x28,
  546. 0x2a, 0x14,
  547. 0x2b, 0x0f,
  548. 0x2c, 0x09,
  549. 0x2d, 0x09,
  550. 0x31, 0x1f,
  551. 0x32, 0x19,
  552. 0x33, 0xfc,
  553. 0x34, 0x93,
  554. 0xff, 0xff
  555. };
  556. static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
  557. {
  558. stv0299_writereg(fe, 0x0e, 0x44);
  559. if (srate >= 10000000) {
  560. stv0299_writereg(fe, 0x13, 0x97);
  561. stv0299_writereg(fe, 0x14, 0x95);
  562. stv0299_writereg(fe, 0x15, 0xc9);
  563. stv0299_writereg(fe, 0x17, 0x8c);
  564. stv0299_writereg(fe, 0x1a, 0xfe);
  565. stv0299_writereg(fe, 0x1c, 0x7f);
  566. stv0299_writereg(fe, 0x2d, 0x09);
  567. } else {
  568. stv0299_writereg(fe, 0x13, 0x99);
  569. stv0299_writereg(fe, 0x14, 0x8d);
  570. stv0299_writereg(fe, 0x15, 0xce);
  571. stv0299_writereg(fe, 0x17, 0x43);
  572. stv0299_writereg(fe, 0x1a, 0x1d);
  573. stv0299_writereg(fe, 0x1c, 0x12);
  574. stv0299_writereg(fe, 0x2d, 0x05);
  575. }
  576. stv0299_writereg(fe, 0x0e, 0x23);
  577. stv0299_writereg(fe, 0x0f, 0x94);
  578. stv0299_writereg(fe, 0x10, 0x39);
  579. stv0299_writereg(fe, 0x15, 0xc9);
  580. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  581. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  582. stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
  583. return 0;
  584. }
  585. static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe,
  586. struct dvb_frontend_parameters *params)
  587. {
  588. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  589. u32 div;
  590. u8 buf[4];
  591. struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
  592. if ((params->frequency < 950000) || (params->frequency > 2150000))
  593. return -EINVAL;
  594. div = (params->frequency + (500 - 1)) / 500; // round correctly
  595. buf[0] = (div >> 8) & 0x7f;
  596. buf[1] = div & 0xff;
  597. buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
  598. buf[3] = 0x20;
  599. if (params->u.qpsk.symbol_rate < 4000000)
  600. buf[3] |= 1;
  601. if (params->frequency < 1250000)
  602. buf[3] |= 0;
  603. else if (params->frequency < 1550000)
  604. buf[3] |= 0x40;
  605. else if (params->frequency < 2050000)
  606. buf[3] |= 0x80;
  607. else if (params->frequency < 2150000)
  608. buf[3] |= 0xC0;
  609. if (fe->ops.i2c_gate_ctrl)
  610. fe->ops.i2c_gate_ctrl(fe, 1);
  611. if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
  612. return -EIO;
  613. return 0;
  614. }
  615. static struct stv0299_config philips_su1278_tt_config = {
  616. .demod_address = 0x68,
  617. .inittab = philips_su1278_tt_inittab,
  618. .mclk = 64000000UL,
  619. .invert = 0,
  620. .skip_reinit = 1,
  621. .lock_output = STV0299_LOCKOUTPUT_1,
  622. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  623. .min_delay_ms = 50,
  624. .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
  625. };
  626. static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
  627. {
  628. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  629. static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  630. static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
  631. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
  632. sizeof(td1316_init) };
  633. // setup PLL configuration
  634. if (fe->ops.i2c_gate_ctrl)
  635. fe->ops.i2c_gate_ctrl(fe, 1);
  636. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  637. return -EIO;
  638. msleep(1);
  639. // disable the mc44BC374c (do not check for errors)
  640. tuner_msg.addr = 0x65;
  641. tuner_msg.buf = disable_mc44BC374c;
  642. tuner_msg.len = sizeof(disable_mc44BC374c);
  643. if (fe->ops.i2c_gate_ctrl)
  644. fe->ops.i2c_gate_ctrl(fe, 1);
  645. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
  646. if (fe->ops.i2c_gate_ctrl)
  647. fe->ops.i2c_gate_ctrl(fe, 1);
  648. i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
  649. }
  650. return 0;
  651. }
  652. static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  653. {
  654. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  655. u8 tuner_buf[4];
  656. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
  657. int tuner_frequency = 0;
  658. u8 band, cp, filter;
  659. // determine charge pump
  660. tuner_frequency = params->frequency + 36130000;
  661. if (tuner_frequency < 87000000)
  662. return -EINVAL;
  663. else if (tuner_frequency < 130000000)
  664. cp = 3;
  665. else if (tuner_frequency < 160000000)
  666. cp = 5;
  667. else if (tuner_frequency < 200000000)
  668. cp = 6;
  669. else if (tuner_frequency < 290000000)
  670. cp = 3;
  671. else if (tuner_frequency < 420000000)
  672. cp = 5;
  673. else if (tuner_frequency < 480000000)
  674. cp = 6;
  675. else if (tuner_frequency < 620000000)
  676. cp = 3;
  677. else if (tuner_frequency < 830000000)
  678. cp = 5;
  679. else if (tuner_frequency < 895000000)
  680. cp = 7;
  681. else
  682. return -EINVAL;
  683. // determine band
  684. if (params->frequency < 49000000)
  685. return -EINVAL;
  686. else if (params->frequency < 159000000)
  687. band = 1;
  688. else if (params->frequency < 444000000)
  689. band = 2;
  690. else if (params->frequency < 861000000)
  691. band = 4;
  692. else
  693. return -EINVAL;
  694. // setup PLL filter and TDA9889
  695. switch (params->u.ofdm.bandwidth) {
  696. case BANDWIDTH_6_MHZ:
  697. tda1004x_writereg(fe, 0x0C, 0x14);
  698. filter = 0;
  699. break;
  700. case BANDWIDTH_7_MHZ:
  701. tda1004x_writereg(fe, 0x0C, 0x80);
  702. filter = 0;
  703. break;
  704. case BANDWIDTH_8_MHZ:
  705. tda1004x_writereg(fe, 0x0C, 0x14);
  706. filter = 1;
  707. break;
  708. default:
  709. return -EINVAL;
  710. }
  711. // calculate divisor
  712. // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
  713. tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
  714. // setup tuner buffer
  715. tuner_buf[0] = tuner_frequency >> 8;
  716. tuner_buf[1] = tuner_frequency & 0xff;
  717. tuner_buf[2] = 0xca;
  718. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  719. if (fe->ops.i2c_gate_ctrl)
  720. fe->ops.i2c_gate_ctrl(fe, 1);
  721. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  722. return -EIO;
  723. msleep(1);
  724. return 0;
  725. }
  726. static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
  727. const struct firmware **fw, char *name)
  728. {
  729. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  730. return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
  731. }
  732. static struct tda1004x_config philips_tdm1316l_config = {
  733. .demod_address = 0x8,
  734. .invert = 0,
  735. .invert_oclk = 0,
  736. .xtal_freq = TDA10046_XTAL_4M,
  737. .agc_config = TDA10046_AGC_DEFAULT,
  738. .if_freq = TDA10046_FREQ_3617,
  739. .request_firmware = philips_tdm1316l_request_firmware,
  740. };
  741. static struct tda1004x_config philips_tdm1316l_config_invert = {
  742. .demod_address = 0x8,
  743. .invert = 1,
  744. .invert_oclk = 0,
  745. .xtal_freq = TDA10046_XTAL_4M,
  746. .agc_config = TDA10046_AGC_DEFAULT,
  747. .if_freq = TDA10046_FREQ_3617,
  748. .request_firmware = philips_tdm1316l_request_firmware,
  749. };
  750. static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  751. {
  752. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  753. u8 tuner_buf[5];
  754. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
  755. .flags = 0,
  756. .buf = tuner_buf,
  757. .len = sizeof(tuner_buf) };
  758. int tuner_frequency = 0;
  759. u8 band, cp, filter;
  760. // determine charge pump
  761. tuner_frequency = params->frequency + 36125000;
  762. if (tuner_frequency < 87000000)
  763. return -EINVAL;
  764. else if (tuner_frequency < 130000000) {
  765. cp = 3;
  766. band = 1;
  767. } else if (tuner_frequency < 160000000) {
  768. cp = 5;
  769. band = 1;
  770. } else if (tuner_frequency < 200000000) {
  771. cp = 6;
  772. band = 1;
  773. } else if (tuner_frequency < 290000000) {
  774. cp = 3;
  775. band = 2;
  776. } else if (tuner_frequency < 420000000) {
  777. cp = 5;
  778. band = 2;
  779. } else if (tuner_frequency < 480000000) {
  780. cp = 6;
  781. band = 2;
  782. } else if (tuner_frequency < 620000000) {
  783. cp = 3;
  784. band = 4;
  785. } else if (tuner_frequency < 830000000) {
  786. cp = 5;
  787. band = 4;
  788. } else if (tuner_frequency < 895000000) {
  789. cp = 7;
  790. band = 4;
  791. } else
  792. return -EINVAL;
  793. // assume PLL filter should always be 8MHz for the moment.
  794. filter = 1;
  795. // calculate divisor
  796. tuner_frequency = (params->frequency + 36125000 + (62500/2)) / 62500;
  797. // setup tuner buffer
  798. tuner_buf[0] = tuner_frequency >> 8;
  799. tuner_buf[1] = tuner_frequency & 0xff;
  800. tuner_buf[2] = 0xc8;
  801. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  802. tuner_buf[4] = 0x80;
  803. if (fe->ops.i2c_gate_ctrl)
  804. fe->ops.i2c_gate_ctrl(fe, 1);
  805. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  806. return -EIO;
  807. msleep(50);
  808. if (fe->ops.i2c_gate_ctrl)
  809. fe->ops.i2c_gate_ctrl(fe, 1);
  810. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  811. return -EIO;
  812. msleep(1);
  813. return 0;
  814. }
  815. static u8 dvbc_philips_tdm1316l_inittab[] = {
  816. 0x80, 0x01,
  817. 0x80, 0x00,
  818. 0x81, 0x01,
  819. 0x81, 0x00,
  820. 0x00, 0x09,
  821. 0x01, 0x69,
  822. 0x03, 0x00,
  823. 0x04, 0x00,
  824. 0x07, 0x00,
  825. 0x08, 0x00,
  826. 0x20, 0x00,
  827. 0x21, 0x40,
  828. 0x22, 0x00,
  829. 0x23, 0x00,
  830. 0x24, 0x40,
  831. 0x25, 0x88,
  832. 0x30, 0xff,
  833. 0x31, 0x00,
  834. 0x32, 0xff,
  835. 0x33, 0x00,
  836. 0x34, 0x50,
  837. 0x35, 0x7f,
  838. 0x36, 0x00,
  839. 0x37, 0x20,
  840. 0x38, 0x00,
  841. 0x40, 0x1c,
  842. 0x41, 0xff,
  843. 0x42, 0x29,
  844. 0x43, 0x20,
  845. 0x44, 0xff,
  846. 0x45, 0x00,
  847. 0x46, 0x00,
  848. 0x49, 0x04,
  849. 0x4a, 0x00,
  850. 0x4b, 0x7b,
  851. 0x52, 0x30,
  852. 0x55, 0xae,
  853. 0x56, 0x47,
  854. 0x57, 0xe1,
  855. 0x58, 0x3a,
  856. 0x5a, 0x1e,
  857. 0x5b, 0x34,
  858. 0x60, 0x00,
  859. 0x63, 0x00,
  860. 0x64, 0x00,
  861. 0x65, 0x00,
  862. 0x66, 0x00,
  863. 0x67, 0x00,
  864. 0x68, 0x00,
  865. 0x69, 0x00,
  866. 0x6a, 0x02,
  867. 0x6b, 0x00,
  868. 0x70, 0xff,
  869. 0x71, 0x00,
  870. 0x72, 0x00,
  871. 0x73, 0x00,
  872. 0x74, 0x0c,
  873. 0x80, 0x00,
  874. 0x81, 0x00,
  875. 0x82, 0x00,
  876. 0x83, 0x00,
  877. 0x84, 0x04,
  878. 0x85, 0x80,
  879. 0x86, 0x24,
  880. 0x87, 0x78,
  881. 0x88, 0x10,
  882. 0x89, 0x00,
  883. 0x90, 0x01,
  884. 0x91, 0x01,
  885. 0xa0, 0x04,
  886. 0xa1, 0x00,
  887. 0xa2, 0x00,
  888. 0xb0, 0x91,
  889. 0xb1, 0x0b,
  890. 0xc0, 0x53,
  891. 0xc1, 0x70,
  892. 0xc2, 0x12,
  893. 0xd0, 0x00,
  894. 0xd1, 0x00,
  895. 0xd2, 0x00,
  896. 0xd3, 0x00,
  897. 0xd4, 0x00,
  898. 0xd5, 0x00,
  899. 0xde, 0x00,
  900. 0xdf, 0x00,
  901. 0x61, 0x38,
  902. 0x62, 0x0a,
  903. 0x53, 0x13,
  904. 0x59, 0x08,
  905. 0xff, 0xff,
  906. };
  907. static struct stv0297_config dvbc_philips_tdm1316l_config = {
  908. .demod_address = 0x1c,
  909. .inittab = dvbc_philips_tdm1316l_inittab,
  910. .invert = 0,
  911. .stop_during_read = 1,
  912. };
  913. static struct tda10023_config tda10023_config = {
  914. .demod_address = 0xc,
  915. .invert = 0,
  916. .xtal = 16000000,
  917. .pll_m = 11,
  918. .pll_p = 3,
  919. .pll_n = 1,
  920. .deltaf = 0xa511,
  921. };
  922. /* TT S2-3200 DVB-S (STB0899) Inittab */
  923. static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = {
  924. // 0x0000000b , /* SYSREG */
  925. { STB0899_DEV_ID , 0x81 },
  926. { STB0899_DISCNTRL1 , 0x32 },
  927. { STB0899_DISCNTRL2 , 0x80 },
  928. { STB0899_DISRX_ST0 , 0x04 },
  929. { STB0899_DISRX_ST1 , 0x00 },
  930. { STB0899_DISPARITY , 0x00 },
  931. { STB0899_DISFIFO , 0x00 },
  932. { STB0899_DISSTATUS , 0x20 },
  933. { STB0899_DISF22 , 0x8c },
  934. { STB0899_DISF22RX , 0x9a },
  935. //SYSREG ?
  936. { STB0899_ACRPRESC , 0x11 },
  937. { STB0899_ACRDIV1 , 0x0a },
  938. { STB0899_ACRDIV2 , 0x05 },
  939. { STB0899_DACR1 , 0x00 },
  940. { STB0899_DACR2 , 0x00 },
  941. { STB0899_OUTCFG , 0x00 },
  942. { STB0899_MODECFG , 0x00 },
  943. { STB0899_IRQSTATUS_3 , 0x30 },
  944. { STB0899_IRQSTATUS_2 , 0x00 },
  945. { STB0899_IRQSTATUS_1 , 0x00 },
  946. { STB0899_IRQSTATUS_0 , 0x00 },
  947. { STB0899_IRQMSK_3 , 0xf3 },
  948. { STB0899_IRQMSK_2 , 0xfc },
  949. { STB0899_IRQMSK_1 , 0xff },
  950. { STB0899_IRQMSK_0 , 0xff },
  951. { STB0899_IRQCFG , 0x00 },
  952. { STB0899_I2CCFG , 0x88 },
  953. { STB0899_I2CRPT , 0x5c },
  954. { STB0899_IOPVALUE5 , 0x00 },
  955. { STB0899_IOPVALUE4 , 0x20 },
  956. { STB0899_IOPVALUE3 , 0xc9 },
  957. { STB0899_IOPVALUE2 , 0x90 },
  958. { STB0899_IOPVALUE1 , 0x40 },
  959. { STB0899_IOPVALUE0 , 0x00 },
  960. { STB0899_GPIO00CFG , 0x82 },
  961. { STB0899_GPIO01CFG , 0x82 },
  962. { STB0899_GPIO02CFG , 0x82 },
  963. { STB0899_GPIO03CFG , 0x82 },
  964. { STB0899_GPIO04CFG , 0x82 },
  965. { STB0899_GPIO05CFG , 0x82 },
  966. { STB0899_GPIO06CFG , 0x82 },
  967. { STB0899_GPIO07CFG , 0x82 },
  968. { STB0899_GPIO08CFG , 0x82 },
  969. { STB0899_GPIO09CFG , 0x82 },
  970. { STB0899_GPIO10CFG , 0x82 },
  971. { STB0899_GPIO11CFG , 0x82 },
  972. { STB0899_GPIO12CFG , 0x82 },
  973. { STB0899_GPIO13CFG , 0x82 },
  974. { STB0899_GPIO14CFG , 0x82 },
  975. { STB0899_GPIO15CFG , 0x82 },
  976. { STB0899_GPIO16CFG , 0x82 },
  977. { STB0899_GPIO17CFG , 0x82 },
  978. { STB0899_GPIO18CFG , 0x82 },
  979. { STB0899_GPIO19CFG , 0x82 },
  980. { STB0899_GPIO20CFG , 0x82 },
  981. { STB0899_SDATCFG , 0xb8 },
  982. { STB0899_SCLTCFG , 0xba },
  983. { STB0899_AGCRFCFG , 0x1c }, /* 0x11 */
  984. { STB0899_GPIO22 , 0x82 }, /* AGCBB2CFG */
  985. { STB0899_GPIO21 , 0x91 }, /* AGCBB1CFG */
  986. { STB0899_DIRCLKCFG , 0x82 },
  987. { STB0899_CLKOUT27CFG , 0x7e },
  988. { STB0899_STDBYCFG , 0x82 },
  989. { STB0899_CS0CFG , 0x82 },
  990. { STB0899_CS1CFG , 0x82 },
  991. { STB0899_DISEQCOCFG , 0x20 },
  992. { STB0899_GPIO32CFG , 0x82 },
  993. { STB0899_GPIO33CFG , 0x82 },
  994. { STB0899_GPIO34CFG , 0x82 },
  995. { STB0899_GPIO35CFG , 0x82 },
  996. { STB0899_GPIO36CFG , 0x82 },
  997. { STB0899_GPIO37CFG , 0x82 },
  998. { STB0899_GPIO38CFG , 0x82 },
  999. { STB0899_GPIO39CFG , 0x82 },
  1000. { STB0899_NCOARSE , 0x15 }, /* 0x15 = 27 Mhz Clock, F/3 = 198MHz, F/6 = 99MHz */
  1001. { STB0899_SYNTCTRL , 0x02 }, /* 0x00 = CLK from CLKI, 0x02 = CLK from XTALI */
  1002. { STB0899_FILTCTRL , 0x00 },
  1003. { STB0899_SYSCTRL , 0x00 },
  1004. { STB0899_STOPCLK1 , 0x20 },
  1005. { STB0899_STOPCLK2 , 0x00 },
  1006. { STB0899_INTBUFSTATUS , 0x00 },
  1007. { STB0899_INTBUFCTRL , 0x0a },
  1008. { 0xffff , 0xff },
  1009. };
  1010. static const struct stb0899_s2_reg tt3200_stb0899_s2_init_2[] = {
  1011. { STB0899_OFF0_DMD_STATUS , STB0899_BASE_DMD_STATUS , 0x00000103 }, /* DMDSTATUS */
  1012. { STB0899_OFF0_CRL_FREQ , STB0899_BASE_CRL_FREQ , 0x3ed1da56 }, /* CRLFREQ */
  1013. { STB0899_OFF0_BTR_FREQ , STB0899_BASE_BTR_FREQ , 0x00004000 }, /* BTRFREQ */
  1014. { STB0899_OFF0_IF_AGC_GAIN , STB0899_BASE_IF_AGC_GAIN , 0x00002ade }, /* IFAGCGAIN */
  1015. { STB0899_OFF0_BB_AGC_GAIN , STB0899_BASE_BB_AGC_GAIN , 0x000001bc }, /* BBAGCGAIN */
  1016. { STB0899_OFF0_DC_OFFSET , STB0899_BASE_DC_OFFSET , 0x00000200 }, /* DCOFFSET */
  1017. { STB0899_OFF0_DMD_CNTRL , STB0899_BASE_DMD_CNTRL , 0x0000000f }, /* DMDCNTRL */
  1018. { STB0899_OFF0_IF_AGC_CNTRL , STB0899_BASE_IF_AGC_CNTRL , 0x03fb4a20 }, /* IFAGCCNTRL */
  1019. { STB0899_OFF0_BB_AGC_CNTRL , STB0899_BASE_BB_AGC_CNTRL , 0x00200c97 }, /* BBAGCCNTRL */
  1020. { STB0899_OFF0_CRL_CNTRL , STB0899_BASE_CRL_CNTRL , 0x00000016 }, /* CRLCNTRL */
  1021. { STB0899_OFF0_CRL_PHS_INIT , STB0899_BASE_CRL_PHS_INIT , 0x00000000 }, /* CRLPHSINIT */
  1022. { STB0899_OFF0_CRL_FREQ_INIT , STB0899_BASE_CRL_FREQ_INIT , 0x00000000 }, /* CRLFREQINIT */
  1023. { STB0899_OFF0_CRL_LOOP_GAIN , STB0899_BASE_CRL_LOOP_GAIN , 0x00000000 }, /* CRLLOOPGAIN */
  1024. { STB0899_OFF0_CRL_NOM_FREQ , STB0899_BASE_CRL_NOM_FREQ , 0x3ed097b6 }, /* CRLNOMFREQ */
  1025. { STB0899_OFF0_CRL_SWP_RATE , STB0899_BASE_CRL_SWP_RATE , 0x00000000 }, /* CRLSWPRATE */
  1026. { STB0899_OFF0_CRL_MAX_SWP , STB0899_BASE_CRL_MAX_SWP , 0x00000000 }, /* CRLMAXSWP */
  1027. { STB0899_OFF0_CRL_LK_CNTRL , STB0899_BASE_CRL_LK_CNTRL , 0x0f6cdc01 }, /* CRLLKCNTRL */
  1028. { STB0899_OFF0_DECIM_CNTRL , STB0899_BASE_DECIM_CNTRL , 0x00000000 }, /* DECIMCNTRL */
  1029. { STB0899_OFF0_BTR_CNTRL , STB0899_BASE_BTR_CNTRL , 0x00003993 }, /* BTRCNTRL */
  1030. { STB0899_OFF0_BTR_LOOP_GAIN , STB0899_BASE_BTR_LOOP_GAIN , 0x000d3c6f }, /* BTRLOOPGAIN */
  1031. { STB0899_OFF0_BTR_PHS_INIT , STB0899_BASE_BTR_PHS_INIT , 0x00000000 }, /* BTRPHSINIT */
  1032. { STB0899_OFF0_BTR_FREQ_INIT , STB0899_BASE_BTR_FREQ_INIT , 0x00000000 }, /* BTRFREQINIT */
  1033. { STB0899_OFF0_BTR_NOM_FREQ , STB0899_BASE_BTR_NOM_FREQ , 0x0238e38e }, /* BTRNOMFREQ */
  1034. { STB0899_OFF0_BTR_LK_CNTRL , STB0899_BASE_BTR_LK_CNTRL , 0x00000000 }, /* BTRLKCNTRL */
  1035. { STB0899_OFF0_DECN_CNTRL , STB0899_BASE_DECN_CNTRL , 0x00000000 }, /* DECNCNTRL */
  1036. { STB0899_OFF0_TP_CNTRL , STB0899_BASE_TP_CNTRL , 0x00000000 }, /* TPCNTRL */
  1037. { STB0899_OFF0_TP_BUF_STATUS , STB0899_BASE_TP_BUF_STATUS , 0x00000000 }, /* TPBUFSTATUS */
  1038. { STB0899_OFF0_DC_ESTIM , STB0899_BASE_DC_ESTIM , 0x00000000 }, /* DCESTIM */
  1039. { STB0899_OFF0_FLL_CNTRL , STB0899_BASE_FLL_CNTRL , 0x00000000 }, /* FLLCNTRL */
  1040. { STB0899_OFF0_FLL_FREQ_WD , STB0899_BASE_FLL_FREQ_WD , 0x40070000 }, /* FLLFREQWD */
  1041. { STB0899_OFF0_ANTI_ALIAS_SEL , STB0899_BASE_ANTI_ALIAS_SEL , 0x00000001 }, /* ANTIALIASSEL */
  1042. { STB0899_OFF0_RRC_ALPHA , STB0899_BASE_RRC_ALPHA , 0x00000002 }, /* RRCALPHA */
  1043. { STB0899_OFF0_DC_ADAPT_LSHFT , STB0899_BASE_DC_ADAPT_LSHFT , 0x00000000 }, /* DCADAPTISHFT */
  1044. { STB0899_OFF0_IMB_OFFSET , STB0899_BASE_IMB_OFFSET , 0x0000fe01 }, /* IMBOFFSET */
  1045. { STB0899_OFF0_IMB_ESTIMATE , STB0899_BASE_IMB_ESTIMATE , 0x00000000 }, /* IMBESTIMATE */
  1046. { STB0899_OFF0_IMB_CNTRL , STB0899_BASE_IMB_CNTRL , 0x00000001 }, /* IMBCNTRL */
  1047. { STB0899_OFF0_IF_AGC_CNTRL2 , STB0899_BASE_IF_AGC_CNTRL2 , 0x00005007 }, /* IFAGCCNTRL2 */
  1048. { STB0899_OFF0_DMD_CNTRL2 , STB0899_BASE_DMD_CNTRL2 , 0x00000002 }, /* DMDCNTRL2 */
  1049. { STB0899_OFF0_TP_BUFFER , STB0899_BASE_TP_BUFFER , 0x00000000 }, /* TPBUFFER */
  1050. { STB0899_OFF0_TP_BUFFER1 , STB0899_BASE_TP_BUFFER1 , 0x00000000 }, /* TPBUFFER1 */
  1051. { STB0899_OFF0_TP_BUFFER2 , STB0899_BASE_TP_BUFFER2 , 0x00000000 }, /* TPBUFFER2 */
  1052. { STB0899_OFF0_TP_BUFFER3 , STB0899_BASE_TP_BUFFER3 , 0x00000000 }, /* TPBUFFER3 */
  1053. { STB0899_OFF0_TP_BUFFER4 , STB0899_BASE_TP_BUFFER4 , 0x00000000 }, /* TPBUFFER4 */
  1054. { STB0899_OFF0_TP_BUFFER5 , STB0899_BASE_TP_BUFFER5 , 0x00000000 }, /* TPBUFFER5 */
  1055. { STB0899_OFF0_TP_BUFFER6 , STB0899_BASE_TP_BUFFER6 , 0x00000000 }, /* TPBUFFER6 */
  1056. { STB0899_OFF0_TP_BUFFER7 , STB0899_BASE_TP_BUFFER7 , 0x00000000 }, /* TPBUFFER7 */
  1057. { STB0899_OFF0_TP_BUFFER8 , STB0899_BASE_TP_BUFFER8 , 0x00000000 }, /* TPBUFFER8 */
  1058. { STB0899_OFF0_TP_BUFFER9 , STB0899_BASE_TP_BUFFER9 , 0x00000000 }, /* TPBUFFER9 */
  1059. { STB0899_OFF0_TP_BUFFER10 , STB0899_BASE_TP_BUFFER10 , 0x00000000 }, /* TPBUFFER10 */
  1060. { STB0899_OFF0_TP_BUFFER11 , STB0899_BASE_TP_BUFFER11 , 0x00000000 }, /* TPBUFFER11 */
  1061. { STB0899_OFF0_TP_BUFFER12 , STB0899_BASE_TP_BUFFER12 , 0x00000000 }, /* TPBUFFER12 */
  1062. { STB0899_OFF0_TP_BUFFER13 , STB0899_BASE_TP_BUFFER13 , 0x00000000 }, /* TPBUFFER13 */
  1063. { STB0899_OFF0_TP_BUFFER14 , STB0899_BASE_TP_BUFFER14 , 0x00000000 }, /* TPBUFFER14 */
  1064. { STB0899_OFF0_TP_BUFFER15 , STB0899_BASE_TP_BUFFER15 , 0x00000000 }, /* TPBUFFER15 */
  1065. { STB0899_OFF0_TP_BUFFER16 , STB0899_BASE_TP_BUFFER16 , 0x0000ff00 }, /* TPBUFFER16 */
  1066. { STB0899_OFF0_TP_BUFFER17 , STB0899_BASE_TP_BUFFER17 , 0x00000100 }, /* TPBUFFER17 */
  1067. { STB0899_OFF0_TP_BUFFER18 , STB0899_BASE_TP_BUFFER18 , 0x0000fe01 }, /* TPBUFFER18 */
  1068. { STB0899_OFF0_TP_BUFFER19 , STB0899_BASE_TP_BUFFER19 , 0x000004fe }, /* TPBUFFER19 */
  1069. { STB0899_OFF0_TP_BUFFER20 , STB0899_BASE_TP_BUFFER20 , 0x0000cfe7 }, /* TPBUFFER20 */
  1070. { STB0899_OFF0_TP_BUFFER21 , STB0899_BASE_TP_BUFFER21 , 0x0000bec6 }, /* TPBUFFER21 */
  1071. { STB0899_OFF0_TP_BUFFER22 , STB0899_BASE_TP_BUFFER22 , 0x0000c2bf }, /* TPBUFFER22 */
  1072. { STB0899_OFF0_TP_BUFFER23 , STB0899_BASE_TP_BUFFER23 , 0x0000c1c1 }, /* TPBUFFER23 */
  1073. { STB0899_OFF0_TP_BUFFER24 , STB0899_BASE_TP_BUFFER24 , 0x0000c1c1 }, /* TPBUFFER24 */
  1074. { STB0899_OFF0_TP_BUFFER25 , STB0899_BASE_TP_BUFFER25 , 0x0000c1c1 }, /* TPBUFFER25 */
  1075. { STB0899_OFF0_TP_BUFFER26 , STB0899_BASE_TP_BUFFER26 , 0x0000c1c1 }, /* TPBUFFER26 */
  1076. { STB0899_OFF0_TP_BUFFER27 , STB0899_BASE_TP_BUFFER27 , 0x0000c1c0 }, /* TPBUFFER27 */
  1077. { STB0899_OFF0_TP_BUFFER28 , STB0899_BASE_TP_BUFFER28 , 0x0000c0c0 }, /* TPBUFFER28 */
  1078. { STB0899_OFF0_TP_BUFFER29 , STB0899_BASE_TP_BUFFER29 , 0x0000c1c1 }, /* TPBUFFER29 */
  1079. { STB0899_OFF0_TP_BUFFER30 , STB0899_BASE_TP_BUFFER30 , 0x0000c1c1 }, /* TPBUFFER30 */
  1080. { STB0899_OFF0_TP_BUFFER31 , STB0899_BASE_TP_BUFFER31 , 0x0000c0c1 }, /* TPBUFFER31 */
  1081. { STB0899_OFF0_TP_BUFFER32 , STB0899_BASE_TP_BUFFER32 , 0x0000c0c1 }, /* TPBUFFER32 */
  1082. { STB0899_OFF0_TP_BUFFER33 , STB0899_BASE_TP_BUFFER33 , 0x0000c1c1 }, /* TPBUFFER33 */
  1083. { STB0899_OFF0_TP_BUFFER34 , STB0899_BASE_TP_BUFFER34 , 0x0000c1c1 }, /* TPBUFFER34 */
  1084. { STB0899_OFF0_TP_BUFFER35 , STB0899_BASE_TP_BUFFER35 , 0x0000c0c1 }, /* TPBUFFER35 */
  1085. { STB0899_OFF0_TP_BUFFER36 , STB0899_BASE_TP_BUFFER36 , 0x0000c1c1 }, /* TPBUFFER36 */
  1086. { STB0899_OFF0_TP_BUFFER37 , STB0899_BASE_TP_BUFFER37 , 0x0000c0c1 }, /* TPBUFFER37 */
  1087. { STB0899_OFF0_TP_BUFFER38 , STB0899_BASE_TP_BUFFER38 , 0x0000c1c1 }, /* TPBUFFER38 */
  1088. { STB0899_OFF0_TP_BUFFER39 , STB0899_BASE_TP_BUFFER39 , 0x0000c0c0 }, /* TPBUFFER39 */
  1089. { STB0899_OFF0_TP_BUFFER40 , STB0899_BASE_TP_BUFFER40 , 0x0000c1c0 }, /* TPBUFFER40 */
  1090. { STB0899_OFF0_TP_BUFFER41 , STB0899_BASE_TP_BUFFER41 , 0x0000c1c1 }, /* TPBUFFER41 */
  1091. { STB0899_OFF0_TP_BUFFER42 , STB0899_BASE_TP_BUFFER42 , 0x0000c0c0 }, /* TPBUFFER42 */
  1092. { STB0899_OFF0_TP_BUFFER43 , STB0899_BASE_TP_BUFFER43 , 0x0000c1c0 }, /* TPBUFFER43 */
  1093. { STB0899_OFF0_TP_BUFFER44 , STB0899_BASE_TP_BUFFER44 , 0x0000c0c1 }, /* TPBUFFER44 */
  1094. { STB0899_OFF0_TP_BUFFER45 , STB0899_BASE_TP_BUFFER45 , 0x0000c1be }, /* TPBUFFER45 */
  1095. { STB0899_OFF0_TP_BUFFER46 , STB0899_BASE_TP_BUFFER46 , 0x0000c1c9 }, /* TPBUFFER46 */
  1096. { STB0899_OFF0_TP_BUFFER47 , STB0899_BASE_TP_BUFFER47 , 0x0000c0da }, /* TPBUFFER47 */
  1097. { STB0899_OFF0_TP_BUFFER48 , STB0899_BASE_TP_BUFFER48 , 0x0000c0ba }, /* TPBUFFER48 */
  1098. { STB0899_OFF0_TP_BUFFER49 , STB0899_BASE_TP_BUFFER49 , 0x0000c1c4 }, /* TPBUFFER49 */
  1099. { STB0899_OFF0_TP_BUFFER50 , STB0899_BASE_TP_BUFFER50 , 0x0000c1bf }, /* TPBUFFER50 */
  1100. { STB0899_OFF0_TP_BUFFER51 , STB0899_BASE_TP_BUFFER51 , 0x0000c0c1 }, /* TPBUFFER51 */
  1101. { STB0899_OFF0_TP_BUFFER52 , STB0899_BASE_TP_BUFFER52 , 0x0000c1c0 }, /* TPBUFFER52 */
  1102. { STB0899_OFF0_TP_BUFFER53 , STB0899_BASE_TP_BUFFER53 , 0x0000c0c1 }, /* TPBUFFER53 */
  1103. { STB0899_OFF0_TP_BUFFER54 , STB0899_BASE_TP_BUFFER54 , 0x0000c1c1 }, /* TPBUFFER54 */
  1104. { STB0899_OFF0_TP_BUFFER55 , STB0899_BASE_TP_BUFFER55 , 0x0000c1c1 }, /* TPBUFFER55 */
  1105. { STB0899_OFF0_TP_BUFFER56 , STB0899_BASE_TP_BUFFER56 , 0x0000c1c1 }, /* TPBUFFER56 */
  1106. { STB0899_OFF0_TP_BUFFER57 , STB0899_BASE_TP_BUFFER57 , 0x0000c1c1 }, /* TPBUFFER57 */
  1107. { STB0899_OFF0_TP_BUFFER58 , STB0899_BASE_TP_BUFFER58 , 0x0000c1c1 }, /* TPBUFFER58 */
  1108. { STB0899_OFF0_TP_BUFFER59 , STB0899_BASE_TP_BUFFER59 , 0x0000c1c1 }, /* TPBUFFER59 */
  1109. { STB0899_OFF0_TP_BUFFER60 , STB0899_BASE_TP_BUFFER60 , 0x0000c1c1 }, /* TPBUFFER60 */
  1110. { STB0899_OFF0_TP_BUFFER61 , STB0899_BASE_TP_BUFFER61 , 0x0000c1c1 }, /* TPBUFFER61 */
  1111. { STB0899_OFF0_TP_BUFFER62 , STB0899_BASE_TP_BUFFER62 , 0x0000c1c1 }, /* TPBUFFER62 */
  1112. { STB0899_OFF0_TP_BUFFER63 , STB0899_BASE_TP_BUFFER63 , 0x0000c1c0 }, /* TPBUFFER63 */
  1113. { STB0899_OFF0_RESET_CNTRL , STB0899_BASE_RESET_CNTRL , 0x00000001 }, /* RESETCNTRL */
  1114. { STB0899_OFF0_ACM_ENABLE , STB0899_BASE_ACM_ENABLE , 0x00005654 }, /* ACMENABLE */
  1115. { STB0899_OFF0_DESCR_CNTRL , STB0899_BASE_DESCR_CNTRL , 0x00000000 }, /* DESCRCNTRL */
  1116. { STB0899_OFF0_CSM_CNTRL1 , STB0899_BASE_CSM_CNTRL1 , 0x00020019 }, /* CSMCNTRL1 */
  1117. { STB0899_OFF0_CSM_CNTRL2 , STB0899_BASE_CSM_CNTRL2 , 0x004b3237 }, /* CSMCNTRL2 */
  1118. { STB0899_OFF0_CSM_CNTRL3 , STB0899_BASE_CSM_CNTRL3 , 0x0003dd17 }, /* CSMCNTRL3 */
  1119. { STB0899_OFF0_CSM_CNTRL4 , STB0899_BASE_CSM_CNTRL4 , 0x00008008 }, /* CSMCNTRL4 */
  1120. { STB0899_OFF0_UWP_CNTRL1 , STB0899_BASE_UWP_CNTRL1 , 0x002a3106 }, /* UWPCNTRL1 */
  1121. { STB0899_OFF0_UWP_CNTRL2 , STB0899_BASE_UWP_CNTRL2 , 0x0006140a }, /* UWPCNTRL2 */
  1122. { STB0899_OFF0_UWP_STAT1 , STB0899_BASE_UWP_STAT1 , 0x00008000 }, /* UWPSTAT1 */
  1123. { STB0899_OFF0_UWP_STAT2 , STB0899_BASE_UWP_STAT2 , 0x00000000 }, /* UWPSTAT2 */
  1124. { STB0899_OFF0_DMD_STAT2 , STB0899_BASE_DMD_STAT2 , 0x00000000 }, /* DMDSTAT2 */
  1125. { STB0899_OFF0_FREQ_ADJ_SCALE , STB0899_BASE_FREQ_ADJ_SCALE , 0x00000471 }, /* FREQADJSCALE */
  1126. { STB0899_OFF0_UWP_CNTRL3 , STB0899_BASE_UWP_CNTRL3 , 0x017b0465 }, /* UWPCNTRL3 */
  1127. { STB0899_OFF0_SYM_CLK_SEL , STB0899_BASE_SYM_CLK_SEL , 0x00000002 }, /* SYMCLKSEL */
  1128. { STB0899_OFF0_SOF_SRCH_TO , STB0899_BASE_SOF_SRCH_TO , 0x00196464 }, /* SOFSRCHTO */
  1129. { STB0899_OFF0_ACQ_CNTRL1 , STB0899_BASE_ACQ_CNTRL1 , 0x00000603 }, /* ACQCNTRL1 */
  1130. { STB0899_OFF0_ACQ_CNTRL2 , STB0899_BASE_ACQ_CNTRL2 , 0x02046666 }, /* ACQCNTRL2 */
  1131. { STB0899_OFF0_ACQ_CNTRL3 , STB0899_BASE_ACQ_CNTRL3 , 0x10046583 }, /* ACQCNTRL3 */
  1132. { STB0899_OFF0_FE_SETTLE , STB0899_BASE_FE_SETTLE , 0x00010404 }, /* FESETTLE */
  1133. { STB0899_OFF0_AC_DWELL , STB0899_BASE_AC_DWELL , 0x0002aa8a }, /* ACDWELL */
  1134. { STB0899_OFF0_ACQUIRE_TRIG , STB0899_BASE_ACQUIRE_TRIG , 0x00000000 }, /* ACQUIRETRIG */
  1135. { STB0899_OFF0_LOCK_LOST , STB0899_BASE_LOCK_LOST , 0x00000001 }, /* LOCKLOST */
  1136. { STB0899_OFF0_ACQ_STAT1 , STB0899_BASE_ACQ_STAT1 , 0x00000500 }, /* ACQSTAT1 */
  1137. { STB0899_OFF0_ACQ_TIMEOUT , STB0899_BASE_ACQ_TIMEOUT , 0x0028a0a0 }, /* ACQTIMEOUT */
  1138. { STB0899_OFF0_ACQ_TIME , STB0899_BASE_ACQ_TIME , 0x00000000 }, /* ACQTIME */
  1139. { STB0899_OFF0_FINAL_AGC_CNTRL , STB0899_BASE_FINAL_AGC_CNTRL , 0x00800c17 }, /* FINALAGCCNTRL*/
  1140. { STB0899_OFF0_FINAL_AGC_GAIN , STB0899_BASE_FINAL_AGC_GAIN , 0x00000000 }, /* FINALAGCCGAIN*/
  1141. { STB0899_OFF0_EQUALIZER_INIT , STB0899_BASE_EQUALIZER_INIT , 0x00000000 }, /* EQUILIZERINIT*/
  1142. { STB0899_OFF0_EQ_CNTRL , STB0899_BASE_EQ_CNTRL , 0x00054802 }, /* EQCNTL */
  1143. { STB0899_OFF0_EQ_I_INIT_COEFF_0, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF0 */
  1144. { STB0899_OFF1_EQ_I_INIT_COEFF_1, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF1 */
  1145. { STB0899_OFF2_EQ_I_INIT_COEFF_2, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF2 */
  1146. { STB0899_OFF3_EQ_I_INIT_COEFF_3, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF3 */
  1147. { STB0899_OFF4_EQ_I_INIT_COEFF_4, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF4 */
  1148. { STB0899_OFF5_EQ_I_INIT_COEFF_5, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000400 }, /* EQIINITCOEFF5 */
  1149. { STB0899_OFF6_EQ_I_INIT_COEFF_6, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF6 */
  1150. { STB0899_OFF7_EQ_I_INIT_COEFF_7, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF7 */
  1151. { STB0899_OFF8_EQ_I_INIT_COEFF_8, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF8 */
  1152. { STB0899_OFF9_EQ_I_INIT_COEFF_9, STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF9 */
  1153. { STB0899_OFFa_EQ_I_INIT_COEFF_10,STB0899_BASE_EQ_I_INIT_COEFF_N, 0x00000000 }, /* EQIINITCOEFF10*/
  1154. { STB0899_OFF0_EQ_Q_INIT_COEFF_0, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF0 */
  1155. { STB0899_OFF1_EQ_Q_INIT_COEFF_1, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF1 */
  1156. { STB0899_OFF2_EQ_Q_INIT_COEFF_2, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF2 */
  1157. { STB0899_OFF3_EQ_Q_INIT_COEFF_3, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF3 */
  1158. { STB0899_OFF4_EQ_Q_INIT_COEFF_4, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF4 */
  1159. { STB0899_OFF5_EQ_Q_INIT_COEFF_5, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF5 */
  1160. { STB0899_OFF6_EQ_Q_INIT_COEFF_6, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF6 */
  1161. { STB0899_OFF7_EQ_Q_INIT_COEFF_7, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF7 */
  1162. { STB0899_OFF8_EQ_Q_INIT_COEFF_8, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF8 */
  1163. { STB0899_OFF9_EQ_Q_INIT_COEFF_9, STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF9 */
  1164. { STB0899_OFFa_EQ_Q_INIT_COEFF_10,STB0899_BASE_EQ_Q_INIT_COEFF_N, 0x00000000 }, /* EQQINITCOEFF10*/
  1165. { STB0899_OFF0_EQ_I_OUT_COEFF_0 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT0 */
  1166. { STB0899_OFF1_EQ_I_OUT_COEFF_1 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT1 */
  1167. { STB0899_OFF2_EQ_I_OUT_COEFF_2 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT2 */
  1168. { STB0899_OFF3_EQ_I_OUT_COEFF_3 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT3 */
  1169. { STB0899_OFF4_EQ_I_OUT_COEFF_4 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT4 */
  1170. { STB0899_OFF5_EQ_I_OUT_COEFF_5 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT5 */
  1171. { STB0899_OFF6_EQ_I_OUT_COEFF_6 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT6 */
  1172. { STB0899_OFF7_EQ_I_OUT_COEFF_7 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT7 */
  1173. { STB0899_OFF8_EQ_I_OUT_COEFF_8 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT8 */
  1174. { STB0899_OFF9_EQ_I_OUT_COEFF_9 , STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT9 */
  1175. { STB0899_OFFa_EQ_I_OUT_COEFF_10,STB0899_BASE_EQ_I_OUT_COEFF_N , 0x00000000 }, /* EQICOEFFSOUT10*/
  1176. { STB0899_OFF0_EQ_Q_OUT_COEFF_0 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT0 */
  1177. { STB0899_OFF1_EQ_Q_OUT_COEFF_1 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT1 */
  1178. { STB0899_OFF2_EQ_Q_OUT_COEFF_2 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT2 */
  1179. { STB0899_OFF3_EQ_Q_OUT_COEFF_3 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT3 */
  1180. { STB0899_OFF4_EQ_Q_OUT_COEFF_4 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT4 */
  1181. { STB0899_OFF5_EQ_Q_OUT_COEFF_5 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT5 */
  1182. { STB0899_OFF6_EQ_Q_OUT_COEFF_6 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT6 */
  1183. { STB0899_OFF7_EQ_Q_OUT_COEFF_7 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT7 */
  1184. { STB0899_OFF8_EQ_Q_OUT_COEFF_8 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT8 */
  1185. { STB0899_OFF9_EQ_Q_OUT_COEFF_9 , STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT9 */
  1186. { STB0899_OFFa_EQ_Q_OUT_COEFF_10, STB0899_BASE_EQ_Q_OUT_COEFF_N , 0x00000000 }, /* EQQCOEFFSOUT10*/
  1187. { 0xffff , 0xffffffff , 0xffffffff },
  1188. };
  1189. static const struct stb0899_s1_reg tt3200_stb0899_s1_init_3[] = {
  1190. { STB0899_DEMOD , 0x00 },
  1191. { STB0899_RCOMPC , 0xc9 },
  1192. { STB0899_AGC1CN , 0x41 },
  1193. { STB0899_AGC1REF , 0x10 },
  1194. { STB0899_RTC , 0x7a },
  1195. { STB0899_TMGCFG , 0x4e },
  1196. { STB0899_AGC2REF , 0x34 },
  1197. { STB0899_TLSR , 0x84 },
  1198. { STB0899_CFD , 0xc7 },
  1199. { STB0899_ACLC , 0x87 },
  1200. { STB0899_BCLC , 0x94 },
  1201. { STB0899_EQON , 0x41 },
  1202. { STB0899_LDT , 0xdd },
  1203. { STB0899_LDT2 , 0xc9 },
  1204. { STB0899_EQUALREF , 0xb4 },
  1205. { STB0899_TMGRAMP , 0x10 },
  1206. { STB0899_TMGTHD , 0x30 },
  1207. { STB0899_IDCCOMP , 0xfb },
  1208. { STB0899_QDCCOMP , 0x03 },
  1209. { STB0899_POWERI , 0x3b },
  1210. { STB0899_POWERQ , 0x3d },
  1211. { STB0899_RCOMP , 0x81 },
  1212. { STB0899_AGCIQIN , 0x80 },
  1213. { STB0899_AGC2I1 , 0x04 },
  1214. { STB0899_AGC2I2 , 0xf5 },
  1215. { STB0899_TLIR , 0x25 },
  1216. { STB0899_RTF , 0x80 },
  1217. { STB0899_DSTATUS , 0x00 },
  1218. { STB0899_LDI , 0xca },
  1219. { STB0899_CFRM , 0xf1 },
  1220. { STB0899_CFRL , 0xf3 },
  1221. { STB0899_NIRM , 0x2a },
  1222. { STB0899_NIRL , 0x05 },
  1223. { STB0899_ISYMB , 0x17 },
  1224. { STB0899_QSYMB , 0xfa },
  1225. { STB0899_SFRH , 0x2f },
  1226. { STB0899_SFRM , 0x68 },
  1227. { STB0899_SFRL , 0x40 },
  1228. { STB0899_SFRUPH , 0x2f },
  1229. { STB0899_SFRUPM , 0x68 },
  1230. { STB0899_SFRUPL , 0x40 },
  1231. { STB0899_EQUAI1 , 0xfd },
  1232. { STB0899_EQUAQ1 , 0x04 },
  1233. { STB0899_EQUAI2 , 0x0f },
  1234. { STB0899_EQUAQ2 , 0xff },
  1235. { STB0899_EQUAI3 , 0xdf },
  1236. { STB0899_EQUAQ3 , 0xfa },
  1237. { STB0899_EQUAI4 , 0x37 },
  1238. { STB0899_EQUAQ4 , 0x0d },
  1239. { STB0899_EQUAI5 , 0xbd },
  1240. { STB0899_EQUAQ5 , 0xf7 },
  1241. { STB0899_DSTATUS2 , 0x00 },
  1242. { STB0899_VSTATUS , 0x00 },
  1243. { STB0899_VERROR , 0xff },
  1244. { STB0899_IQSWAP , 0x2a },
  1245. { STB0899_ECNT1M , 0x00 },
  1246. { STB0899_ECNT1L , 0x00 },
  1247. { STB0899_ECNT2M , 0x00 },
  1248. { STB0899_ECNT2L , 0x00 },
  1249. { STB0899_ECNT3M , 0x00 },
  1250. { STB0899_ECNT3L , 0x00 },
  1251. { STB0899_FECAUTO1 , 0x06 },
  1252. { STB0899_FECM , 0x01 },
  1253. { STB0899_VTH12 , 0xf0 },
  1254. { STB0899_VTH23 , 0xa0 },
  1255. { STB0899_VTH34 , 0x78 },
  1256. { STB0899_VTH56 , 0x4e },
  1257. { STB0899_VTH67 , 0x48 },
  1258. { STB0899_VTH78 , 0x38 },
  1259. { STB0899_PRVIT , 0xff },
  1260. { STB0899_VITSYNC , 0x19 },
  1261. { STB0899_RSULC , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
  1262. { STB0899_TSULC , 0x42 },
  1263. { STB0899_RSLLC , 0x40 },
  1264. { STB0899_TSLPL , 0x12 },
  1265. { STB0899_TSCFGH , 0x0c },
  1266. { STB0899_TSCFGM , 0x00 },
  1267. { STB0899_TSCFGL , 0x0c },
  1268. { STB0899_TSOUT , 0x07 },
  1269. { STB0899_RSSYNCDEL , 0x00 },
  1270. { STB0899_TSINHDELH , 0x02 },
  1271. { STB0899_TSINHDELM , 0x00 },
  1272. { STB0899_TSINHDELL , 0x00 },
  1273. { STB0899_TSLLSTKM , 0x00 },
  1274. { STB0899_TSLLSTKL , 0x00 },
  1275. { STB0899_TSULSTKM , 0x00 },
  1276. { STB0899_TSULSTKL , 0xab },
  1277. { STB0899_PCKLENUL , 0x00 },
  1278. { STB0899_PCKLENLL , 0xcc },
  1279. { STB0899_RSPCKLEN , 0xcc },
  1280. { STB0899_TSSTATUS , 0x80 },
  1281. { STB0899_ERRCTRL1 , 0xb6 },
  1282. { STB0899_ERRCTRL2 , 0x96 },
  1283. { STB0899_ERRCTRL3 , 0x89 },
  1284. { STB0899_DMONMSK1 , 0x27 },
  1285. { STB0899_DMONMSK0 , 0x03 },
  1286. { STB0899_DEMAPVIT , 0x5c },
  1287. { STB0899_PLPARM , 0x1f },
  1288. { STB0899_PDELCTRL , 0x48 },
  1289. { STB0899_PDELCTRL2 , 0x00 },
  1290. { STB0899_BBHCTRL1 , 0x00 },
  1291. { STB0899_BBHCTRL2 , 0x00 },
  1292. { STB0899_HYSTTHRESH , 0x77 },
  1293. { STB0899_MATCSTM , 0x00 },
  1294. { STB0899_MATCSTL , 0x00 },
  1295. { STB0899_UPLCSTM , 0x00 },
  1296. { STB0899_UPLCSTL , 0x00 },
  1297. { STB0899_DFLCSTM , 0x00 },
  1298. { STB0899_DFLCSTL , 0x00 },
  1299. { STB0899_SYNCCST , 0x00 },
  1300. { STB0899_SYNCDCSTM , 0x00 },
  1301. { STB0899_SYNCDCSTL , 0x00 },
  1302. { STB0899_ISI_ENTRY , 0x00 },
  1303. { STB0899_ISI_BIT_EN , 0x00 },
  1304. { STB0899_MATSTRM , 0x00 },
  1305. { STB0899_MATSTRL , 0x00 },
  1306. { STB0899_UPLSTRM , 0x00 },
  1307. { STB0899_UPLSTRL , 0x00 },
  1308. { STB0899_DFLSTRM , 0x00 },
  1309. { STB0899_DFLSTRL , 0x00 },
  1310. { STB0899_SYNCSTR , 0x00 },
  1311. { STB0899_SYNCDSTRM , 0x00 },
  1312. { STB0899_SYNCDSTRL , 0x00 },
  1313. { STB0899_CFGPDELSTATUS1 , 0x10 },
  1314. { STB0899_CFGPDELSTATUS2 , 0x00 },
  1315. { STB0899_BBFERRORM , 0x00 },
  1316. { STB0899_BBFERRORL , 0x00 },
  1317. { STB0899_UPKTERRORM , 0x00 },
  1318. { STB0899_UPKTERRORL , 0x00 },
  1319. { 0xffff , 0xff },
  1320. };
  1321. static const struct stb0899_s2_reg tt3200_stb0899_s2_init_4[] = {
  1322. { STB0899_OFF0_BLOCK_LNGTH , STB0899_BASE_BLOCK_LNGTH , 0x00000008 }, /* BLOCKLNGTH */
  1323. { STB0899_OFF0_ROW_STR , STB0899_BASE_ROW_STR , 0x000000b4 }, /* ROWSTR */
  1324. { STB0899_OFF0_BN_END_ADDR , STB0899_BASE_BN_END_ADDR , 0x000004b5 }, /* BNANDADDR */
  1325. { STB0899_OFF0_CN_END_ADDR , STB0899_BASE_CN_END_ADDR , 0x00000b4b }, /* CNANDADDR */
  1326. { STB0899_OFF0_INFO_LENGTH , STB0899_BASE_INFO_LENGTH , 0x00000078 }, /* INFOLENGTH */
  1327. { STB0899_OFF0_BOT_ADDR , STB0899_BASE_BOT_ADDR , 0x000001e0 }, /* BOT_ADDR */
  1328. { STB0899_OFF0_BCH_BLK_LN , STB0899_BASE_BCH_BLK_LN , 0x0000a8c0 }, /* BCHBLKLN */
  1329. { STB0899_OFF0_BCH_T , STB0899_BASE_BCH_T , 0x0000000c }, /* BCHT */
  1330. { STB0899_OFF0_CNFG_MODE , STB0899_BASE_CNFG_MODE , 0x00000001 }, /* CNFGMODE */
  1331. { STB0899_OFF0_LDPC_STAT , STB0899_BASE_LDPC_STAT , 0x0000000d }, /* LDPCSTAT */
  1332. { STB0899_OFF0_ITER_SCALE , STB0899_BASE_ITER_SCALE , 0x00000040 }, /* ITERSCALE */
  1333. { STB0899_OFF0_INPUT_MODE , STB0899_BASE_INPUT_MODE , 0x00000000 }, /* INPUTMODE */
  1334. { STB0899_OFF0_LDPCDECRST , STB0899_BASE_LDPCDECRST , 0x00000000 }, /* LDPCDECRST */
  1335. { STB0899_OFF0_CLK_PER_BYTE_RW , STB0899_BASE_CLK_PER_BYTE_RW , 0x00000008 }, /* CLKPERBYTE */
  1336. { STB0899_OFF0_BCH_ERRORS , STB0899_BASE_BCH_ERRORS , 0x00000000 }, /* BCHERRORS */
  1337. { STB0899_OFF0_LDPC_ERRORS , STB0899_BASE_LDPC_ERRORS , 0x00000000 }, /* LDPCERRORS */
  1338. { STB0899_OFF0_BCH_MODE , STB0899_BASE_BCH_MODE , 0x00000000 }, /* BCHMODE */
  1339. { STB0899_OFF0_ERR_ACC_PER , STB0899_BASE_ERR_ACC_PER , 0x00000008 }, /* ERRACCPER */
  1340. { STB0899_OFF0_BCH_ERR_ACC , STB0899_BASE_BCH_ERR_ACC , 0x00000000 }, /* BCHERRACC */
  1341. { STB0899_OFF0_FEC_TP_SEL , STB0899_BASE_FEC_TP_SEL , 0x00000000 }, /* FECTPSEL */
  1342. { 0xffff , 0xffffffff , 0xffffffff },
  1343. };
  1344. static const struct stb0899_s1_reg tt3200_stb0899_s1_init_5[] = {
  1345. { STB0899_TSTCK , 0x00 },
  1346. { STB0899_TSTRES , 0x00 },
  1347. { STB0899_TSTOUT , 0x00 },
  1348. { STB0899_TSTIN , 0x00 },
  1349. { STB0899_TSTSYS , 0x00 },
  1350. { STB0899_TSTCHIP , 0x00 },
  1351. { STB0899_TSTFREE , 0x00 },
  1352. { STB0899_TSTI2C , 0x00 },
  1353. { STB0899_BITSPEEDM , 0x00 },
  1354. { STB0899_BITSPEEDL , 0x00 },
  1355. { STB0899_TBUSBIT , 0x00 },
  1356. { STB0899_TSTDIS , 0x00 },
  1357. { STB0899_TSTDISRX , 0x00 },
  1358. { STB0899_TSTJETON , 0x00 },
  1359. { STB0899_TSTDCADJ , 0x00 },
  1360. { STB0899_TSTAGC1 , 0x00 },
  1361. { STB0899_TSTAGC1N , 0x00 },
  1362. { STB0899_TSTPOLYPH , 0x00 },
  1363. { STB0899_TSTR , 0x00 },
  1364. { STB0899_TSTAGC2 , 0x00 },
  1365. { STB0899_TSTCTL1 , 0x00 },
  1366. { STB0899_TSTCTL2 , 0x00 },
  1367. { STB0899_TSTCTL3 , 0x00 },
  1368. { STB0899_TSTDEMAP , 0x00 },
  1369. { STB0899_TSTDEMAP2 , 0x00 },
  1370. { STB0899_TSTDEMMON , 0x00 },
  1371. { STB0899_TSTRATE , 0x00 },
  1372. { STB0899_TSTSELOUT , 0x00 },
  1373. { STB0899_TSYNC , 0x00 },
  1374. { STB0899_TSTERR , 0x00 },
  1375. { STB0899_TSTRAM1 , 0x00 },
  1376. { STB0899_TSTVSELOUT , 0x00 },
  1377. { STB0899_TSTFORCEIN , 0x00 },
  1378. { STB0899_TSTRS1 , 0x00 },
  1379. { STB0899_TSTRS2 , 0x00 },
  1380. { STB0899_TSTRS3 , 0x00 },
  1381. { STB0899_GHOSTREG , 0x81 },
  1382. { 0xffff , 0xff },
  1383. };
  1384. #define TT3200_DVBS2_ESNO_AVE 3
  1385. #define TT3200_DVBS2_ESNO_QUANT 32
  1386. #define TT3200_DVBS2_AVFRAMES_COARSE 10
  1387. #define TT3200_DVBS2_AVFRAMES_FINE 20
  1388. #define TT3200_DVBS2_MISS_THRESHOLD 6
  1389. #define TT3200_DVBS2_UWP_THRESHOLD_ACQ 1125
  1390. #define TT3200_DVBS2_UWP_THRESHOLD_TRACK 758
  1391. #define TT3200_DVBS2_UWP_THRESHOLD_SOF 1350
  1392. #define TT3200_DVBS2_SOF_SEARCH_TIMEOUT 1664100
  1393. #define TT3200_DVBS2_BTR_NCO_BITS 28
  1394. #define TT3200_DVBS2_BTR_GAIN_SHIFT_OFFSET 15
  1395. #define TT3200_DVBS2_CRL_NCO_BITS 30
  1396. #define TT3200_DVBS2_LDPC_MAX_ITER 70
  1397. static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  1398. {
  1399. struct dvb_frontend_ops *frontend_ops = NULL;
  1400. struct dvb_tuner_ops *tuner_ops = NULL;
  1401. struct tuner_state t_state;
  1402. int err = 0;
  1403. if (&fe->ops)
  1404. frontend_ops = &fe->ops;
  1405. if (&frontend_ops->tuner_ops)
  1406. tuner_ops = &frontend_ops->tuner_ops;
  1407. if (tuner_ops->get_state) {
  1408. if ((err = tuner_ops->get_state(fe, DVBFE_TUNER_FREQUENCY, &t_state)) < 0) {
  1409. printk("%s: Invalid parameter\n", __func__);
  1410. return err;
  1411. }
  1412. *frequency = t_state.frequency;
  1413. printk("%s: Frequency=%d\n", __func__, t_state.frequency);
  1414. }
  1415. return 0;
  1416. }
  1417. static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
  1418. {
  1419. struct dvb_frontend_ops *frontend_ops = NULL;
  1420. struct dvb_tuner_ops *tuner_ops = NULL;
  1421. struct tuner_state t_state;
  1422. int err = 0;
  1423. t_state.frequency = frequency;
  1424. if (&fe->ops)
  1425. frontend_ops = &fe->ops;
  1426. if (&frontend_ops->tuner_ops)
  1427. tuner_ops = &frontend_ops->tuner_ops;
  1428. if (tuner_ops->set_state) {
  1429. if ((err = tuner_ops->set_state(fe, DVBFE_TUNER_FREQUENCY, &t_state)) < 0) {
  1430. printk("%s: Invalid parameter\n", __func__);
  1431. return err;
  1432. }
  1433. }
  1434. printk("%s: Frequency=%d\n", __func__, t_state.frequency);
  1435. return 0;
  1436. }
  1437. static int stb6100_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
  1438. {
  1439. struct dvb_frontend_ops *frontend_ops = &fe->ops;
  1440. struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
  1441. struct tuner_state t_state;
  1442. int err = 0;
  1443. if (&fe->ops)
  1444. frontend_ops = &fe->ops;
  1445. if (&frontend_ops->tuner_ops)
  1446. tuner_ops = &frontend_ops->tuner_ops;
  1447. if (tuner_ops->get_state) {
  1448. if ((err = tuner_ops->get_state(fe, DVBFE_TUNER_BANDWIDTH, &t_state)) < 0) {
  1449. printk("%s: Invalid parameter\n", __func__);
  1450. return err;
  1451. }
  1452. *bandwidth = t_state.bandwidth;
  1453. }
  1454. printk("%s: Bandwidth=%d\n", __func__, t_state.bandwidth);
  1455. return 0;
  1456. }
  1457. static int stb6100_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
  1458. {
  1459. struct dvb_frontend_ops *frontend_ops = NULL;
  1460. struct dvb_tuner_ops *tuner_ops = NULL;
  1461. struct tuner_state t_state;
  1462. int err = 0;
  1463. t_state.frequency = bandwidth;
  1464. if (&fe->ops)
  1465. frontend_ops = &fe->ops;
  1466. if (&frontend_ops->tuner_ops)
  1467. tuner_ops = &frontend_ops->tuner_ops;
  1468. if (tuner_ops->set_state) {
  1469. if ((err = tuner_ops->set_state(fe, DVBFE_TUNER_BANDWIDTH, &t_state)) < 0) {
  1470. printk("%s: Invalid parameter\n", __func__);
  1471. return err;
  1472. }
  1473. }
  1474. printk("%s: Bandwidth=%d\n", __func__, t_state.frequency);
  1475. return 0;
  1476. }
  1477. static struct stb0899_config tt3200_config = {
  1478. .init_dev = tt3200_stb0899_s1_init_1,
  1479. .init_s2_demod = tt3200_stb0899_s2_init_2,
  1480. .init_s1_demod = tt3200_stb0899_s1_init_3,
  1481. .init_s2_fec = tt3200_stb0899_s2_init_4,
  1482. .init_tst = tt3200_stb0899_s1_init_5,
  1483. .demod_address = 0x68,
  1484. .xtal_freq = 27000000,
  1485. .inversion = IQ_SWAP_OFF, /* 1 */
  1486. .esno_ave = TT3200_DVBS2_ESNO_AVE,
  1487. .esno_quant = TT3200_DVBS2_ESNO_QUANT,
  1488. .avframes_coarse = TT3200_DVBS2_AVFRAMES_COARSE,
  1489. .avframes_fine = TT3200_DVBS2_AVFRAMES_FINE,
  1490. .miss_threshold = TT3200_DVBS2_MISS_THRESHOLD,
  1491. .uwp_threshold_acq = TT3200_DVBS2_UWP_THRESHOLD_ACQ,
  1492. .uwp_threshold_track = TT3200_DVBS2_UWP_THRESHOLD_TRACK,
  1493. .uwp_threshold_sof = TT3200_DVBS2_UWP_THRESHOLD_SOF,
  1494. .sof_search_timeout = TT3200_DVBS2_SOF_SEARCH_TIMEOUT,
  1495. .btr_nco_bits = TT3200_DVBS2_BTR_NCO_BITS,
  1496. .btr_gain_shift_offset = TT3200_DVBS2_BTR_GAIN_SHIFT_OFFSET,
  1497. .crl_nco_bits = TT3200_DVBS2_CRL_NCO_BITS,
  1498. .ldpc_max_iter = TT3200_DVBS2_LDPC_MAX_ITER,
  1499. .tuner_get_frequency = stb6100_get_frequency,
  1500. .tuner_set_frequency = stb6100_set_frequency,
  1501. .tuner_set_bandwidth = stb6100_set_bandwidth,
  1502. .tuner_get_bandwidth = stb6100_get_bandwidth,
  1503. .tuner_set_rfsiggain = NULL,
  1504. };
  1505. struct stb6100_config tt3200_stb6100_config = {
  1506. .tuner_address = 0x60
  1507. };
  1508. static void frontend_init(struct budget_ci *budget_ci)
  1509. {
  1510. switch (budget_ci->budget.dev->pci->subsystem_device) {
  1511. case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
  1512. budget_ci->budget.dvb_frontend =
  1513. dvb_attach(stv0299_attach, &alps_bsru6_config, &budget_ci->budget.i2c_adap);
  1514. if (budget_ci->budget.dvb_frontend) {
  1515. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
  1516. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  1517. break;
  1518. }
  1519. break;
  1520. case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
  1521. budget_ci->budget.dvb_frontend =
  1522. dvb_attach(stv0299_attach, &philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
  1523. if (budget_ci->budget.dvb_frontend) {
  1524. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
  1525. break;
  1526. }
  1527. break;
  1528. case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
  1529. budget_ci->tuner_pll_address = 0x61;
  1530. budget_ci->budget.dvb_frontend =
  1531. dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  1532. if (budget_ci->budget.dvb_frontend) {
  1533. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
  1534. break;
  1535. }
  1536. break;
  1537. case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
  1538. budget_ci->tuner_pll_address = 0x63;
  1539. budget_ci->budget.dvb_frontend =
  1540. dvb_attach(tda10045_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  1541. if (budget_ci->budget.dvb_frontend) {
  1542. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  1543. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  1544. break;
  1545. }
  1546. break;
  1547. case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
  1548. budget_ci->tuner_pll_address = 0x60;
  1549. budget_ci->budget.dvb_frontend =
  1550. dvb_attach(tda10046_attach, &philips_tdm1316l_config_invert, &budget_ci->budget.i2c_adap);
  1551. if (budget_ci->budget.dvb_frontend) {
  1552. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  1553. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  1554. break;
  1555. }
  1556. break;
  1557. case 0x1017: // TT S-1500 PCI
  1558. budget_ci->budget.dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config, &budget_ci->budget.i2c_adap);
  1559. if (budget_ci->budget.dvb_frontend) {
  1560. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
  1561. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  1562. budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
  1563. if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
  1564. printk("%s: No LNBP21 found!\n", __func__);
  1565. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1566. budget_ci->budget.dvb_frontend = NULL;
  1567. }
  1568. }
  1569. break;
  1570. case 0x101a: /* TT Budget-C-1501 (philips tda10023/philips tda8274A) */
  1571. budget_ci->budget.dvb_frontend = dvb_attach(tda10023_attach, &tda10023_config, &budget_ci->budget.i2c_adap, 0x48);
  1572. if (budget_ci->budget.dvb_frontend) {
  1573. if (dvb_attach(tda827x_attach, budget_ci->budget.dvb_frontend, 0x61, &budget_ci->budget.i2c_adap, NULL) == NULL) {
  1574. printk(KERN_ERR "%s: No tda827x found!\n", __func__);
  1575. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1576. budget_ci->budget.dvb_frontend = NULL;
  1577. }
  1578. }
  1579. break;
  1580. case 0x1019: // TT S2-3200 PCI
  1581. budget_ci->budget.dvb_frontend = stb0899_attach(&tt3200_config, &budget_ci->budget.i2c_adap);
  1582. if (budget_ci->budget.dvb_frontend) {
  1583. if (stb6100_attach(budget_ci->budget.dvb_frontend, &tt3200_stb6100_config, &budget_ci->budget.i2c_adap)) {
  1584. if (lnbp21_attach(budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, 0, 0)) {
  1585. printk("%s: No LNBP21 found!\n", __FUNCTION__);
  1586. if (budget_ci->budget.dvb_frontend->ops.tuner_ops.release)
  1587. budget_ci->budget.dvb_frontend->ops.tuner_ops.release(budget_ci->budget.dvb_frontend);
  1588. if (budget_ci->budget.dvb_frontend->ops.release)
  1589. budget_ci->budget.dvb_frontend->ops.release(budget_ci->budget.dvb_frontend);
  1590. budget_ci->budget.dvb_frontend = NULL;
  1591. }
  1592. } else {
  1593. if (budget_ci->budget.dvb_frontend->ops.release)
  1594. budget_ci->budget.dvb_frontend->ops.release(budget_ci->budget.dvb_frontend);
  1595. }
  1596. }
  1597. break;
  1598. }
  1599. if (budget_ci->budget.dvb_frontend == NULL) {
  1600. printk("budget-ci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
  1601. budget_ci->budget.dev->pci->vendor,
  1602. budget_ci->budget.dev->pci->device,
  1603. budget_ci->budget.dev->pci->subsystem_vendor,
  1604. budget_ci->budget.dev->pci->subsystem_device);
  1605. } else {
  1606. if (dvb_register_frontend
  1607. (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
  1608. printk("budget-ci: Frontend registration failed!\n");
  1609. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1610. budget_ci->budget.dvb_frontend = NULL;
  1611. }
  1612. }
  1613. }
  1614. static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
  1615. {
  1616. struct budget_ci *budget_ci;
  1617. int err;
  1618. budget_ci = kzalloc(sizeof(struct budget_ci), GFP_KERNEL);
  1619. if (!budget_ci) {
  1620. err = -ENOMEM;
  1621. goto out1;
  1622. }
  1623. dprintk(2, "budget_ci: %p\n", budget_ci);
  1624. dev->ext_priv = budget_ci;
  1625. err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE,
  1626. adapter_nr);
  1627. if (err)
  1628. goto out2;
  1629. err = msp430_ir_init(budget_ci);
  1630. if (err)
  1631. goto out3;
  1632. ciintf_init(budget_ci);
  1633. budget_ci->budget.dvb_adapter.priv = budget_ci;
  1634. frontend_init(budget_ci);
  1635. ttpci_budget_init_hooks(&budget_ci->budget);
  1636. return 0;
  1637. out3:
  1638. ttpci_budget_deinit(&budget_ci->budget);
  1639. out2:
  1640. kfree(budget_ci);
  1641. out1:
  1642. return err;
  1643. }
  1644. static int budget_ci_detach(struct saa7146_dev *dev)
  1645. {
  1646. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  1647. struct saa7146_dev *saa = budget_ci->budget.dev;
  1648. int err;
  1649. if (budget_ci->budget.ci_present)
  1650. ciintf_deinit(budget_ci);
  1651. msp430_ir_deinit(budget_ci);
  1652. if (budget_ci->budget.dvb_frontend) {
  1653. dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
  1654. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1655. }
  1656. err = ttpci_budget_deinit(&budget_ci->budget);
  1657. // disable frontend and CI interface
  1658. saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
  1659. kfree(budget_ci);
  1660. return err;
  1661. }
  1662. static struct saa7146_extension budget_extension;
  1663. MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
  1664. MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
  1665. MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
  1666. MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
  1667. MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
  1668. MAKE_BUDGET_INFO(ttc1501, "TT-Budget C-1501 PCI", BUDGET_TT);
  1669. MAKE_BUDGET_INFO(tt3200, "TT-Budget S2-3200 PCI", BUDGET_TT);
  1670. static struct pci_device_id pci_tbl[] = {
  1671. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
  1672. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
  1673. MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
  1674. MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
  1675. MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
  1676. MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
  1677. MAKE_EXTENSION_PCI(ttc1501, 0x13c2, 0x101a),
  1678. MAKE_EXTENSION_PCI(tt3200, 0x13c2, 0x1019),
  1679. {
  1680. .vendor = 0,
  1681. }
  1682. };
  1683. MODULE_DEVICE_TABLE(pci, pci_tbl);
  1684. static struct saa7146_extension budget_extension = {
  1685. .name = "budget_ci dvb",
  1686. .flags = SAA7146_USE_I2C_IRQ,
  1687. .module = THIS_MODULE,
  1688. .pci_tbl = &pci_tbl[0],
  1689. .attach = budget_ci_attach,
  1690. .detach = budget_ci_detach,
  1691. .irq_mask = MASK_03 | MASK_06 | MASK_10,
  1692. .irq_func = budget_ci_irq,
  1693. };
  1694. static int __init budget_ci_init(void)
  1695. {
  1696. return saa7146_register_extension(&budget_extension);
  1697. }
  1698. static void __exit budget_ci_exit(void)
  1699. {
  1700. saa7146_unregister_extension(&budget_extension);
  1701. }
  1702. module_init(budget_ci_init);
  1703. module_exit(budget_ci_exit);
  1704. MODULE_LICENSE("GPL");
  1705. MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
  1706. MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
  1707. "budget PCI DVB cards w/ CI-module produced by "
  1708. "Siemens, Technotrend, Hauppauge");