budget-ci.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689
  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 "stb0899_cfg.h"
  46. #include "stb6100.h"
  47. #include "stb6100_cfg.h"
  48. #include "lnbp21.h"
  49. #include "bsbe1.h"
  50. #include "bsru6.h"
  51. #include "tda1002x.h"
  52. #include "tda827x.h"
  53. #include "stv6110x.h"
  54. #include "stv090x.h"
  55. #include "isl6423.h"
  56. /*
  57. * Regarding DEBIADDR_IR:
  58. * Some CI modules hang if random addresses are read.
  59. * Using address 0x4000 for the IR read means that we
  60. * use the same address as for CI version, which should
  61. * be a safe default.
  62. */
  63. #define DEBIADDR_IR 0x4000
  64. #define DEBIADDR_CICONTROL 0x0000
  65. #define DEBIADDR_CIVERSION 0x4000
  66. #define DEBIADDR_IO 0x1000
  67. #define DEBIADDR_ATTR 0x3000
  68. #define CICONTROL_RESET 0x01
  69. #define CICONTROL_ENABLETS 0x02
  70. #define CICONTROL_CAMDETECT 0x08
  71. #define DEBICICTL 0x00420000
  72. #define DEBICICAM 0x02420000
  73. #define SLOTSTATUS_NONE 1
  74. #define SLOTSTATUS_PRESENT 2
  75. #define SLOTSTATUS_RESET 4
  76. #define SLOTSTATUS_READY 8
  77. #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
  78. /*
  79. * Milliseconds during which a key is regarded as pressed.
  80. * If an identical command arrives within this time, the timer will start over.
  81. */
  82. #define IR_KEYPRESS_TIMEOUT 250
  83. /* RC5 device wildcard */
  84. #define IR_DEVICE_ANY 255
  85. static int rc5_device = -1;
  86. module_param(rc5_device, int, 0644);
  87. MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");
  88. static int ir_debug;
  89. module_param(ir_debug, int, 0644);
  90. MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
  91. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  92. struct budget_ci_ir {
  93. struct input_dev *dev;
  94. struct tasklet_struct msp430_irq_tasklet;
  95. struct timer_list timer_keyup;
  96. char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
  97. char phys[32];
  98. struct ir_input_state state;
  99. int rc5_device;
  100. u32 last_raw;
  101. u32 ir_key;
  102. bool have_command;
  103. };
  104. struct budget_ci {
  105. struct budget budget;
  106. struct tasklet_struct ciintf_irq_tasklet;
  107. int slot_status;
  108. int ci_irq;
  109. struct dvb_ca_en50221 ca;
  110. struct budget_ci_ir ir;
  111. u8 tuner_pll_address; /* used for philips_tdm1316l configs */
  112. };
  113. static void msp430_ir_keyup(unsigned long data)
  114. {
  115. struct budget_ci_ir *ir = (struct budget_ci_ir *) data;
  116. ir_input_nokey(ir->dev, &ir->state);
  117. }
  118. static void msp430_ir_interrupt(unsigned long data)
  119. {
  120. struct budget_ci *budget_ci = (struct budget_ci *) data;
  121. struct input_dev *dev = budget_ci->ir.dev;
  122. u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
  123. u32 raw;
  124. /*
  125. * The msp430 chip can generate two different bytes, command and device
  126. *
  127. * type1: X1CCCCCC, C = command bits (0 - 63)
  128. * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit
  129. *
  130. * Each signal from the remote control can generate one or more command
  131. * bytes and one or more device bytes. For the repeated bytes, the
  132. * highest bit (X) is set. The first command byte is always generated
  133. * before the first device byte. Other than that, no specific order
  134. * seems to apply. To make life interesting, bytes can also be lost.
  135. *
  136. * Only when we have a command and device byte, a keypress is
  137. * generated.
  138. */
  139. if (ir_debug)
  140. printk("budget_ci: received byte 0x%02x\n", command);
  141. /* Remove repeat bit, we use every command */
  142. command = command & 0x7f;
  143. /* Is this a RC5 command byte? */
  144. if (command & 0x40) {
  145. budget_ci->ir.have_command = true;
  146. budget_ci->ir.ir_key = command & 0x3f;
  147. return;
  148. }
  149. /* It's a RC5 device byte */
  150. if (!budget_ci->ir.have_command)
  151. return;
  152. budget_ci->ir.have_command = false;
  153. if (budget_ci->ir.rc5_device != IR_DEVICE_ANY &&
  154. budget_ci->ir.rc5_device != (command & 0x1f))
  155. return;
  156. /* Is this a repeated key sequence? (same device, command, toggle) */
  157. raw = budget_ci->ir.ir_key | (command << 8);
  158. if (budget_ci->ir.last_raw != raw || !timer_pending(&budget_ci->ir.timer_keyup)) {
  159. ir_input_nokey(dev, &budget_ci->ir.state);
  160. ir_input_keydown(dev, &budget_ci->ir.state,
  161. budget_ci->ir.ir_key, raw);
  162. budget_ci->ir.last_raw = raw;
  163. }
  164. mod_timer(&budget_ci->ir.timer_keyup, jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT));
  165. }
  166. static int msp430_ir_init(struct budget_ci *budget_ci)
  167. {
  168. struct saa7146_dev *saa = budget_ci->budget.dev;
  169. struct input_dev *input_dev = budget_ci->ir.dev;
  170. int error;
  171. budget_ci->ir.dev = input_dev = input_allocate_device();
  172. if (!input_dev) {
  173. printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
  174. error = -ENOMEM;
  175. goto out1;
  176. }
  177. snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
  178. "Budget-CI dvb ir receiver %s", saa->name);
  179. snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
  180. "pci-%s/ir0", pci_name(saa->pci));
  181. input_dev->name = budget_ci->ir.name;
  182. input_dev->phys = budget_ci->ir.phys;
  183. input_dev->id.bustype = BUS_PCI;
  184. input_dev->id.version = 1;
  185. if (saa->pci->subsystem_vendor) {
  186. input_dev->id.vendor = saa->pci->subsystem_vendor;
  187. input_dev->id.product = saa->pci->subsystem_device;
  188. } else {
  189. input_dev->id.vendor = saa->pci->vendor;
  190. input_dev->id.product = saa->pci->device;
  191. }
  192. input_dev->dev.parent = &saa->pci->dev;
  193. /* Select keymap and address */
  194. switch (budget_ci->budget.dev->pci->subsystem_device) {
  195. case 0x100c:
  196. case 0x100f:
  197. case 0x1011:
  198. case 0x1012:
  199. /* The hauppauge keymap is a superset of these remotes */
  200. ir_input_init(input_dev, &budget_ci->ir.state,
  201. IR_TYPE_RC5, ir_codes_hauppauge_new);
  202. if (rc5_device < 0)
  203. budget_ci->ir.rc5_device = 0x1f;
  204. else
  205. budget_ci->ir.rc5_device = rc5_device;
  206. break;
  207. case 0x1010:
  208. case 0x1017:
  209. case 0x101a:
  210. /* for the Technotrend 1500 bundled remote */
  211. ir_input_init(input_dev, &budget_ci->ir.state,
  212. IR_TYPE_RC5, ir_codes_tt_1500);
  213. if (rc5_device < 0)
  214. budget_ci->ir.rc5_device = IR_DEVICE_ANY;
  215. else
  216. budget_ci->ir.rc5_device = rc5_device;
  217. break;
  218. default:
  219. /* unknown remote */
  220. ir_input_init(input_dev, &budget_ci->ir.state,
  221. IR_TYPE_RC5, ir_codes_budget_ci_old);
  222. if (rc5_device < 0)
  223. budget_ci->ir.rc5_device = IR_DEVICE_ANY;
  224. else
  225. budget_ci->ir.rc5_device = rc5_device;
  226. break;
  227. }
  228. /* initialise the key-up timeout handler */
  229. init_timer(&budget_ci->ir.timer_keyup);
  230. budget_ci->ir.timer_keyup.function = msp430_ir_keyup;
  231. budget_ci->ir.timer_keyup.data = (unsigned long) &budget_ci->ir;
  232. budget_ci->ir.last_raw = 0xffff; /* An impossible value */
  233. error = input_register_device(input_dev);
  234. if (error) {
  235. printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
  236. goto out2;
  237. }
  238. /* note: these must be after input_register_device */
  239. input_dev->rep[REP_DELAY] = 400;
  240. input_dev->rep[REP_PERIOD] = 250;
  241. tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
  242. (unsigned long) budget_ci);
  243. SAA7146_IER_ENABLE(saa, MASK_06);
  244. saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
  245. return 0;
  246. out2:
  247. input_free_device(input_dev);
  248. out1:
  249. return error;
  250. }
  251. static void msp430_ir_deinit(struct budget_ci *budget_ci)
  252. {
  253. struct saa7146_dev *saa = budget_ci->budget.dev;
  254. struct input_dev *dev = budget_ci->ir.dev;
  255. SAA7146_IER_DISABLE(saa, MASK_06);
  256. saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
  257. tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
  258. del_timer_sync(&dev->timer);
  259. ir_input_nokey(dev, &budget_ci->ir.state);
  260. input_unregister_device(dev);
  261. }
  262. static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
  263. {
  264. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  265. if (slot != 0)
  266. return -EINVAL;
  267. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  268. DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
  269. }
  270. static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
  271. {
  272. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  273. if (slot != 0)
  274. return -EINVAL;
  275. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  276. DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
  277. }
  278. static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
  279. {
  280. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  281. if (slot != 0)
  282. return -EINVAL;
  283. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  284. DEBIADDR_IO | (address & 3), 1, 1, 0);
  285. }
  286. static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
  287. {
  288. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  289. if (slot != 0)
  290. return -EINVAL;
  291. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  292. DEBIADDR_IO | (address & 3), 1, value, 1, 0);
  293. }
  294. static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
  295. {
  296. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  297. struct saa7146_dev *saa = budget_ci->budget.dev;
  298. if (slot != 0)
  299. return -EINVAL;
  300. if (budget_ci->ci_irq) {
  301. // trigger on RISING edge during reset so we know when READY is re-asserted
  302. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  303. }
  304. budget_ci->slot_status = SLOTSTATUS_RESET;
  305. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  306. msleep(1);
  307. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  308. CICONTROL_RESET, 1, 0);
  309. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  310. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  311. return 0;
  312. }
  313. static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
  314. {
  315. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  316. struct saa7146_dev *saa = budget_ci->budget.dev;
  317. if (slot != 0)
  318. return -EINVAL;
  319. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  320. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  321. return 0;
  322. }
  323. static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
  324. {
  325. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  326. struct saa7146_dev *saa = budget_ci->budget.dev;
  327. int tmp;
  328. if (slot != 0)
  329. return -EINVAL;
  330. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
  331. tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  332. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  333. tmp | CICONTROL_ENABLETS, 1, 0);
  334. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
  335. return 0;
  336. }
  337. static void ciintf_interrupt(unsigned long data)
  338. {
  339. struct budget_ci *budget_ci = (struct budget_ci *) data;
  340. struct saa7146_dev *saa = budget_ci->budget.dev;
  341. unsigned int flags;
  342. // ensure we don't get spurious IRQs during initialisation
  343. if (!budget_ci->budget.ci_present)
  344. return;
  345. // read the CAM status
  346. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  347. if (flags & CICONTROL_CAMDETECT) {
  348. // GPIO should be set to trigger on falling edge if a CAM is present
  349. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  350. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  351. // CAM insertion IRQ
  352. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  353. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  354. DVB_CA_EN50221_CAMCHANGE_INSERTED);
  355. } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  356. // CAM ready (reset completed)
  357. budget_ci->slot_status = SLOTSTATUS_READY;
  358. dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
  359. } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
  360. // FR/DA IRQ
  361. dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
  362. }
  363. } else {
  364. // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
  365. // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
  366. // the CAM might not actually be ready yet.
  367. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  368. // generate a CAM removal IRQ if we haven't already
  369. if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
  370. // CAM removal IRQ
  371. budget_ci->slot_status = SLOTSTATUS_NONE;
  372. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  373. DVB_CA_EN50221_CAMCHANGE_REMOVED);
  374. }
  375. }
  376. }
  377. static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
  378. {
  379. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  380. unsigned int flags;
  381. // ensure we don't get spurious IRQs during initialisation
  382. if (!budget_ci->budget.ci_present)
  383. return -EINVAL;
  384. // read the CAM status
  385. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  386. if (flags & CICONTROL_CAMDETECT) {
  387. // mark it as present if it wasn't before
  388. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  389. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  390. }
  391. // during a RESET, we check if we can read from IO memory to see when CAM is ready
  392. if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  393. if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
  394. budget_ci->slot_status = SLOTSTATUS_READY;
  395. }
  396. }
  397. } else {
  398. budget_ci->slot_status = SLOTSTATUS_NONE;
  399. }
  400. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  401. if (budget_ci->slot_status & SLOTSTATUS_READY) {
  402. return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
  403. }
  404. return DVB_CA_EN50221_POLL_CAM_PRESENT;
  405. }
  406. return 0;
  407. }
  408. static int ciintf_init(struct budget_ci *budget_ci)
  409. {
  410. struct saa7146_dev *saa = budget_ci->budget.dev;
  411. int flags;
  412. int result;
  413. int ci_version;
  414. int ca_flags;
  415. memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
  416. // enable DEBI pins
  417. saa7146_write(saa, MC1, MASK_27 | MASK_11);
  418. // test if it is there
  419. ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
  420. if ((ci_version & 0xa0) != 0xa0) {
  421. result = -ENODEV;
  422. goto error;
  423. }
  424. // determine whether a CAM is present or not
  425. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  426. budget_ci->slot_status = SLOTSTATUS_NONE;
  427. if (flags & CICONTROL_CAMDETECT)
  428. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  429. // version 0xa2 of the CI firmware doesn't generate interrupts
  430. if (ci_version == 0xa2) {
  431. ca_flags = 0;
  432. budget_ci->ci_irq = 0;
  433. } else {
  434. ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
  435. DVB_CA_EN50221_FLAG_IRQ_FR |
  436. DVB_CA_EN50221_FLAG_IRQ_DA;
  437. budget_ci->ci_irq = 1;
  438. }
  439. // register CI interface
  440. budget_ci->ca.owner = THIS_MODULE;
  441. budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
  442. budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
  443. budget_ci->ca.read_cam_control = ciintf_read_cam_control;
  444. budget_ci->ca.write_cam_control = ciintf_write_cam_control;
  445. budget_ci->ca.slot_reset = ciintf_slot_reset;
  446. budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
  447. budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
  448. budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
  449. budget_ci->ca.data = budget_ci;
  450. if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
  451. &budget_ci->ca,
  452. ca_flags, 1)) != 0) {
  453. printk("budget_ci: CI interface detected, but initialisation failed.\n");
  454. goto error;
  455. }
  456. // Setup CI slot IRQ
  457. if (budget_ci->ci_irq) {
  458. tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
  459. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  460. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  461. } else {
  462. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  463. }
  464. SAA7146_IER_ENABLE(saa, MASK_03);
  465. }
  466. // enable interface
  467. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  468. CICONTROL_RESET, 1, 0);
  469. // success!
  470. printk("budget_ci: CI interface initialised\n");
  471. budget_ci->budget.ci_present = 1;
  472. // forge a fake CI IRQ so the CAM state is setup correctly
  473. if (budget_ci->ci_irq) {
  474. flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
  475. if (budget_ci->slot_status != SLOTSTATUS_NONE)
  476. flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
  477. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
  478. }
  479. return 0;
  480. error:
  481. saa7146_write(saa, MC1, MASK_27);
  482. return result;
  483. }
  484. static void ciintf_deinit(struct budget_ci *budget_ci)
  485. {
  486. struct saa7146_dev *saa = budget_ci->budget.dev;
  487. // disable CI interrupts
  488. if (budget_ci->ci_irq) {
  489. SAA7146_IER_DISABLE(saa, MASK_03);
  490. saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
  491. tasklet_kill(&budget_ci->ciintf_irq_tasklet);
  492. }
  493. // reset interface
  494. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  495. msleep(1);
  496. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  497. CICONTROL_RESET, 1, 0);
  498. // disable TS data stream to CI interface
  499. saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
  500. // release the CA device
  501. dvb_ca_en50221_release(&budget_ci->ca);
  502. // disable DEBI pins
  503. saa7146_write(saa, MC1, MASK_27);
  504. }
  505. static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
  506. {
  507. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  508. dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
  509. if (*isr & MASK_06)
  510. tasklet_schedule(&budget_ci->ir.msp430_irq_tasklet);
  511. if (*isr & MASK_10)
  512. ttpci_budget_irq10_handler(dev, isr);
  513. if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
  514. tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
  515. }
  516. static u8 philips_su1278_tt_inittab[] = {
  517. 0x01, 0x0f,
  518. 0x02, 0x30,
  519. 0x03, 0x00,
  520. 0x04, 0x5b,
  521. 0x05, 0x85,
  522. 0x06, 0x02,
  523. 0x07, 0x00,
  524. 0x08, 0x02,
  525. 0x09, 0x00,
  526. 0x0C, 0x01,
  527. 0x0D, 0x81,
  528. 0x0E, 0x44,
  529. 0x0f, 0x14,
  530. 0x10, 0x3c,
  531. 0x11, 0x84,
  532. 0x12, 0xda,
  533. 0x13, 0x97,
  534. 0x14, 0x95,
  535. 0x15, 0xc9,
  536. 0x16, 0x19,
  537. 0x17, 0x8c,
  538. 0x18, 0x59,
  539. 0x19, 0xf8,
  540. 0x1a, 0xfe,
  541. 0x1c, 0x7f,
  542. 0x1d, 0x00,
  543. 0x1e, 0x00,
  544. 0x1f, 0x50,
  545. 0x20, 0x00,
  546. 0x21, 0x00,
  547. 0x22, 0x00,
  548. 0x23, 0x00,
  549. 0x28, 0x00,
  550. 0x29, 0x28,
  551. 0x2a, 0x14,
  552. 0x2b, 0x0f,
  553. 0x2c, 0x09,
  554. 0x2d, 0x09,
  555. 0x31, 0x1f,
  556. 0x32, 0x19,
  557. 0x33, 0xfc,
  558. 0x34, 0x93,
  559. 0xff, 0xff
  560. };
  561. static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
  562. {
  563. stv0299_writereg(fe, 0x0e, 0x44);
  564. if (srate >= 10000000) {
  565. stv0299_writereg(fe, 0x13, 0x97);
  566. stv0299_writereg(fe, 0x14, 0x95);
  567. stv0299_writereg(fe, 0x15, 0xc9);
  568. stv0299_writereg(fe, 0x17, 0x8c);
  569. stv0299_writereg(fe, 0x1a, 0xfe);
  570. stv0299_writereg(fe, 0x1c, 0x7f);
  571. stv0299_writereg(fe, 0x2d, 0x09);
  572. } else {
  573. stv0299_writereg(fe, 0x13, 0x99);
  574. stv0299_writereg(fe, 0x14, 0x8d);
  575. stv0299_writereg(fe, 0x15, 0xce);
  576. stv0299_writereg(fe, 0x17, 0x43);
  577. stv0299_writereg(fe, 0x1a, 0x1d);
  578. stv0299_writereg(fe, 0x1c, 0x12);
  579. stv0299_writereg(fe, 0x2d, 0x05);
  580. }
  581. stv0299_writereg(fe, 0x0e, 0x23);
  582. stv0299_writereg(fe, 0x0f, 0x94);
  583. stv0299_writereg(fe, 0x10, 0x39);
  584. stv0299_writereg(fe, 0x15, 0xc9);
  585. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  586. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  587. stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
  588. return 0;
  589. }
  590. static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe,
  591. struct dvb_frontend_parameters *params)
  592. {
  593. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  594. u32 div;
  595. u8 buf[4];
  596. struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
  597. if ((params->frequency < 950000) || (params->frequency > 2150000))
  598. return -EINVAL;
  599. div = (params->frequency + (500 - 1)) / 500; // round correctly
  600. buf[0] = (div >> 8) & 0x7f;
  601. buf[1] = div & 0xff;
  602. buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
  603. buf[3] = 0x20;
  604. if (params->u.qpsk.symbol_rate < 4000000)
  605. buf[3] |= 1;
  606. if (params->frequency < 1250000)
  607. buf[3] |= 0;
  608. else if (params->frequency < 1550000)
  609. buf[3] |= 0x40;
  610. else if (params->frequency < 2050000)
  611. buf[3] |= 0x80;
  612. else if (params->frequency < 2150000)
  613. buf[3] |= 0xC0;
  614. if (fe->ops.i2c_gate_ctrl)
  615. fe->ops.i2c_gate_ctrl(fe, 1);
  616. if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
  617. return -EIO;
  618. return 0;
  619. }
  620. static struct stv0299_config philips_su1278_tt_config = {
  621. .demod_address = 0x68,
  622. .inittab = philips_su1278_tt_inittab,
  623. .mclk = 64000000UL,
  624. .invert = 0,
  625. .skip_reinit = 1,
  626. .lock_output = STV0299_LOCKOUTPUT_1,
  627. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  628. .min_delay_ms = 50,
  629. .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
  630. };
  631. static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
  632. {
  633. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  634. static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  635. static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
  636. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
  637. sizeof(td1316_init) };
  638. // setup PLL configuration
  639. if (fe->ops.i2c_gate_ctrl)
  640. fe->ops.i2c_gate_ctrl(fe, 1);
  641. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  642. return -EIO;
  643. msleep(1);
  644. // disable the mc44BC374c (do not check for errors)
  645. tuner_msg.addr = 0x65;
  646. tuner_msg.buf = disable_mc44BC374c;
  647. tuner_msg.len = sizeof(disable_mc44BC374c);
  648. if (fe->ops.i2c_gate_ctrl)
  649. fe->ops.i2c_gate_ctrl(fe, 1);
  650. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
  651. if (fe->ops.i2c_gate_ctrl)
  652. fe->ops.i2c_gate_ctrl(fe, 1);
  653. i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
  654. }
  655. return 0;
  656. }
  657. static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  658. {
  659. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  660. u8 tuner_buf[4];
  661. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
  662. int tuner_frequency = 0;
  663. u8 band, cp, filter;
  664. // determine charge pump
  665. tuner_frequency = params->frequency + 36130000;
  666. if (tuner_frequency < 87000000)
  667. return -EINVAL;
  668. else if (tuner_frequency < 130000000)
  669. cp = 3;
  670. else if (tuner_frequency < 160000000)
  671. cp = 5;
  672. else if (tuner_frequency < 200000000)
  673. cp = 6;
  674. else if (tuner_frequency < 290000000)
  675. cp = 3;
  676. else if (tuner_frequency < 420000000)
  677. cp = 5;
  678. else if (tuner_frequency < 480000000)
  679. cp = 6;
  680. else if (tuner_frequency < 620000000)
  681. cp = 3;
  682. else if (tuner_frequency < 830000000)
  683. cp = 5;
  684. else if (tuner_frequency < 895000000)
  685. cp = 7;
  686. else
  687. return -EINVAL;
  688. // determine band
  689. if (params->frequency < 49000000)
  690. return -EINVAL;
  691. else if (params->frequency < 159000000)
  692. band = 1;
  693. else if (params->frequency < 444000000)
  694. band = 2;
  695. else if (params->frequency < 861000000)
  696. band = 4;
  697. else
  698. return -EINVAL;
  699. // setup PLL filter and TDA9889
  700. switch (params->u.ofdm.bandwidth) {
  701. case BANDWIDTH_6_MHZ:
  702. tda1004x_writereg(fe, 0x0C, 0x14);
  703. filter = 0;
  704. break;
  705. case BANDWIDTH_7_MHZ:
  706. tda1004x_writereg(fe, 0x0C, 0x80);
  707. filter = 0;
  708. break;
  709. case BANDWIDTH_8_MHZ:
  710. tda1004x_writereg(fe, 0x0C, 0x14);
  711. filter = 1;
  712. break;
  713. default:
  714. return -EINVAL;
  715. }
  716. // calculate divisor
  717. // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
  718. tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
  719. // setup tuner buffer
  720. tuner_buf[0] = tuner_frequency >> 8;
  721. tuner_buf[1] = tuner_frequency & 0xff;
  722. tuner_buf[2] = 0xca;
  723. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  724. if (fe->ops.i2c_gate_ctrl)
  725. fe->ops.i2c_gate_ctrl(fe, 1);
  726. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  727. return -EIO;
  728. msleep(1);
  729. return 0;
  730. }
  731. static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
  732. const struct firmware **fw, char *name)
  733. {
  734. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  735. return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
  736. }
  737. static struct tda1004x_config philips_tdm1316l_config = {
  738. .demod_address = 0x8,
  739. .invert = 0,
  740. .invert_oclk = 0,
  741. .xtal_freq = TDA10046_XTAL_4M,
  742. .agc_config = TDA10046_AGC_DEFAULT,
  743. .if_freq = TDA10046_FREQ_3617,
  744. .request_firmware = philips_tdm1316l_request_firmware,
  745. };
  746. static struct tda1004x_config philips_tdm1316l_config_invert = {
  747. .demod_address = 0x8,
  748. .invert = 1,
  749. .invert_oclk = 0,
  750. .xtal_freq = TDA10046_XTAL_4M,
  751. .agc_config = TDA10046_AGC_DEFAULT,
  752. .if_freq = TDA10046_FREQ_3617,
  753. .request_firmware = philips_tdm1316l_request_firmware,
  754. };
  755. static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  756. {
  757. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  758. u8 tuner_buf[5];
  759. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
  760. .flags = 0,
  761. .buf = tuner_buf,
  762. .len = sizeof(tuner_buf) };
  763. int tuner_frequency = 0;
  764. u8 band, cp, filter;
  765. // determine charge pump
  766. tuner_frequency = params->frequency + 36125000;
  767. if (tuner_frequency < 87000000)
  768. return -EINVAL;
  769. else if (tuner_frequency < 130000000) {
  770. cp = 3;
  771. band = 1;
  772. } else if (tuner_frequency < 160000000) {
  773. cp = 5;
  774. band = 1;
  775. } else if (tuner_frequency < 200000000) {
  776. cp = 6;
  777. band = 1;
  778. } else if (tuner_frequency < 290000000) {
  779. cp = 3;
  780. band = 2;
  781. } else if (tuner_frequency < 420000000) {
  782. cp = 5;
  783. band = 2;
  784. } else if (tuner_frequency < 480000000) {
  785. cp = 6;
  786. band = 2;
  787. } else if (tuner_frequency < 620000000) {
  788. cp = 3;
  789. band = 4;
  790. } else if (tuner_frequency < 830000000) {
  791. cp = 5;
  792. band = 4;
  793. } else if (tuner_frequency < 895000000) {
  794. cp = 7;
  795. band = 4;
  796. } else
  797. return -EINVAL;
  798. // assume PLL filter should always be 8MHz for the moment.
  799. filter = 1;
  800. // calculate divisor
  801. tuner_frequency = (params->frequency + 36125000 + (62500/2)) / 62500;
  802. // setup tuner buffer
  803. tuner_buf[0] = tuner_frequency >> 8;
  804. tuner_buf[1] = tuner_frequency & 0xff;
  805. tuner_buf[2] = 0xc8;
  806. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  807. tuner_buf[4] = 0x80;
  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(50);
  813. if (fe->ops.i2c_gate_ctrl)
  814. fe->ops.i2c_gate_ctrl(fe, 1);
  815. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  816. return -EIO;
  817. msleep(1);
  818. return 0;
  819. }
  820. static u8 dvbc_philips_tdm1316l_inittab[] = {
  821. 0x80, 0x01,
  822. 0x80, 0x00,
  823. 0x81, 0x01,
  824. 0x81, 0x00,
  825. 0x00, 0x09,
  826. 0x01, 0x69,
  827. 0x03, 0x00,
  828. 0x04, 0x00,
  829. 0x07, 0x00,
  830. 0x08, 0x00,
  831. 0x20, 0x00,
  832. 0x21, 0x40,
  833. 0x22, 0x00,
  834. 0x23, 0x00,
  835. 0x24, 0x40,
  836. 0x25, 0x88,
  837. 0x30, 0xff,
  838. 0x31, 0x00,
  839. 0x32, 0xff,
  840. 0x33, 0x00,
  841. 0x34, 0x50,
  842. 0x35, 0x7f,
  843. 0x36, 0x00,
  844. 0x37, 0x20,
  845. 0x38, 0x00,
  846. 0x40, 0x1c,
  847. 0x41, 0xff,
  848. 0x42, 0x29,
  849. 0x43, 0x20,
  850. 0x44, 0xff,
  851. 0x45, 0x00,
  852. 0x46, 0x00,
  853. 0x49, 0x04,
  854. 0x4a, 0x00,
  855. 0x4b, 0x7b,
  856. 0x52, 0x30,
  857. 0x55, 0xae,
  858. 0x56, 0x47,
  859. 0x57, 0xe1,
  860. 0x58, 0x3a,
  861. 0x5a, 0x1e,
  862. 0x5b, 0x34,
  863. 0x60, 0x00,
  864. 0x63, 0x00,
  865. 0x64, 0x00,
  866. 0x65, 0x00,
  867. 0x66, 0x00,
  868. 0x67, 0x00,
  869. 0x68, 0x00,
  870. 0x69, 0x00,
  871. 0x6a, 0x02,
  872. 0x6b, 0x00,
  873. 0x70, 0xff,
  874. 0x71, 0x00,
  875. 0x72, 0x00,
  876. 0x73, 0x00,
  877. 0x74, 0x0c,
  878. 0x80, 0x00,
  879. 0x81, 0x00,
  880. 0x82, 0x00,
  881. 0x83, 0x00,
  882. 0x84, 0x04,
  883. 0x85, 0x80,
  884. 0x86, 0x24,
  885. 0x87, 0x78,
  886. 0x88, 0x10,
  887. 0x89, 0x00,
  888. 0x90, 0x01,
  889. 0x91, 0x01,
  890. 0xa0, 0x04,
  891. 0xa1, 0x00,
  892. 0xa2, 0x00,
  893. 0xb0, 0x91,
  894. 0xb1, 0x0b,
  895. 0xc0, 0x53,
  896. 0xc1, 0x70,
  897. 0xc2, 0x12,
  898. 0xd0, 0x00,
  899. 0xd1, 0x00,
  900. 0xd2, 0x00,
  901. 0xd3, 0x00,
  902. 0xd4, 0x00,
  903. 0xd5, 0x00,
  904. 0xde, 0x00,
  905. 0xdf, 0x00,
  906. 0x61, 0x38,
  907. 0x62, 0x0a,
  908. 0x53, 0x13,
  909. 0x59, 0x08,
  910. 0xff, 0xff,
  911. };
  912. static struct stv0297_config dvbc_philips_tdm1316l_config = {
  913. .demod_address = 0x1c,
  914. .inittab = dvbc_philips_tdm1316l_inittab,
  915. .invert = 0,
  916. .stop_during_read = 1,
  917. };
  918. static struct tda10023_config tda10023_config = {
  919. .demod_address = 0xc,
  920. .invert = 0,
  921. .xtal = 16000000,
  922. .pll_m = 11,
  923. .pll_p = 3,
  924. .pll_n = 1,
  925. .deltaf = 0xa511,
  926. };
  927. static struct tda827x_config tda827x_config = {
  928. .config = 0,
  929. };
  930. /* TT S2-3200 DVB-S (STB0899) Inittab */
  931. static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = {
  932. { STB0899_DEV_ID , 0x81 },
  933. { STB0899_DISCNTRL1 , 0x32 },
  934. { STB0899_DISCNTRL2 , 0x80 },
  935. { STB0899_DISRX_ST0 , 0x04 },
  936. { STB0899_DISRX_ST1 , 0x00 },
  937. { STB0899_DISPARITY , 0x00 },
  938. { STB0899_DISFIFO , 0x00 },
  939. { STB0899_DISSTATUS , 0x20 },
  940. { STB0899_DISF22 , 0x8c },
  941. { STB0899_DISF22RX , 0x9a },
  942. { STB0899_SYSREG , 0x0b },
  943. { STB0899_ACRPRESC , 0x11 },
  944. { STB0899_ACRDIV1 , 0x0a },
  945. { STB0899_ACRDIV2 , 0x05 },
  946. { STB0899_DACR1 , 0x00 },
  947. { STB0899_DACR2 , 0x00 },
  948. { STB0899_OUTCFG , 0x00 },
  949. { STB0899_MODECFG , 0x00 },
  950. { STB0899_IRQSTATUS_3 , 0x30 },
  951. { STB0899_IRQSTATUS_2 , 0x00 },
  952. { STB0899_IRQSTATUS_1 , 0x00 },
  953. { STB0899_IRQSTATUS_0 , 0x00 },
  954. { STB0899_IRQMSK_3 , 0xf3 },
  955. { STB0899_IRQMSK_2 , 0xfc },
  956. { STB0899_IRQMSK_1 , 0xff },
  957. { STB0899_IRQMSK_0 , 0xff },
  958. { STB0899_IRQCFG , 0x00 },
  959. { STB0899_I2CCFG , 0x88 },
  960. { STB0899_I2CRPT , 0x48 }, /* 12k Pullup, Repeater=16, Stop=disabled */
  961. { STB0899_IOPVALUE5 , 0x00 },
  962. { STB0899_IOPVALUE4 , 0x20 },
  963. { STB0899_IOPVALUE3 , 0xc9 },
  964. { STB0899_IOPVALUE2 , 0x90 },
  965. { STB0899_IOPVALUE1 , 0x40 },
  966. { STB0899_IOPVALUE0 , 0x00 },
  967. { STB0899_GPIO00CFG , 0x82 },
  968. { STB0899_GPIO01CFG , 0x82 },
  969. { STB0899_GPIO02CFG , 0x82 },
  970. { STB0899_GPIO03CFG , 0x82 },
  971. { STB0899_GPIO04CFG , 0x82 },
  972. { STB0899_GPIO05CFG , 0x82 },
  973. { STB0899_GPIO06CFG , 0x82 },
  974. { STB0899_GPIO07CFG , 0x82 },
  975. { STB0899_GPIO08CFG , 0x82 },
  976. { STB0899_GPIO09CFG , 0x82 },
  977. { STB0899_GPIO10CFG , 0x82 },
  978. { STB0899_GPIO11CFG , 0x82 },
  979. { STB0899_GPIO12CFG , 0x82 },
  980. { STB0899_GPIO13CFG , 0x82 },
  981. { STB0899_GPIO14CFG , 0x82 },
  982. { STB0899_GPIO15CFG , 0x82 },
  983. { STB0899_GPIO16CFG , 0x82 },
  984. { STB0899_GPIO17CFG , 0x82 },
  985. { STB0899_GPIO18CFG , 0x82 },
  986. { STB0899_GPIO19CFG , 0x82 },
  987. { STB0899_GPIO20CFG , 0x82 },
  988. { STB0899_SDATCFG , 0xb8 },
  989. { STB0899_SCLTCFG , 0xba },
  990. { STB0899_AGCRFCFG , 0x1c }, /* 0x11 */
  991. { STB0899_GPIO22 , 0x82 }, /* AGCBB2CFG */
  992. { STB0899_GPIO21 , 0x91 }, /* AGCBB1CFG */
  993. { STB0899_DIRCLKCFG , 0x82 },
  994. { STB0899_CLKOUT27CFG , 0x7e },
  995. { STB0899_STDBYCFG , 0x82 },
  996. { STB0899_CS0CFG , 0x82 },
  997. { STB0899_CS1CFG , 0x82 },
  998. { STB0899_DISEQCOCFG , 0x20 },
  999. { STB0899_GPIO32CFG , 0x82 },
  1000. { STB0899_GPIO33CFG , 0x82 },
  1001. { STB0899_GPIO34CFG , 0x82 },
  1002. { STB0899_GPIO35CFG , 0x82 },
  1003. { STB0899_GPIO36CFG , 0x82 },
  1004. { STB0899_GPIO37CFG , 0x82 },
  1005. { STB0899_GPIO38CFG , 0x82 },
  1006. { STB0899_GPIO39CFG , 0x82 },
  1007. { STB0899_NCOARSE , 0x15 }, /* 0x15 = 27 Mhz Clock, F/3 = 198MHz, F/6 = 99MHz */
  1008. { STB0899_SYNTCTRL , 0x02 }, /* 0x00 = CLK from CLKI, 0x02 = CLK from XTALI */
  1009. { STB0899_FILTCTRL , 0x00 },
  1010. { STB0899_SYSCTRL , 0x00 },
  1011. { STB0899_STOPCLK1 , 0x20 },
  1012. { STB0899_STOPCLK2 , 0x00 },
  1013. { STB0899_INTBUFSTATUS , 0x00 },
  1014. { STB0899_INTBUFCTRL , 0x0a },
  1015. { 0xffff , 0xff },
  1016. };
  1017. static const struct stb0899_s1_reg tt3200_stb0899_s1_init_3[] = {
  1018. { STB0899_DEMOD , 0x00 },
  1019. { STB0899_RCOMPC , 0xc9 },
  1020. { STB0899_AGC1CN , 0x41 },
  1021. { STB0899_AGC1REF , 0x10 },
  1022. { STB0899_RTC , 0x7a },
  1023. { STB0899_TMGCFG , 0x4e },
  1024. { STB0899_AGC2REF , 0x34 },
  1025. { STB0899_TLSR , 0x84 },
  1026. { STB0899_CFD , 0xc7 },
  1027. { STB0899_ACLC , 0x87 },
  1028. { STB0899_BCLC , 0x94 },
  1029. { STB0899_EQON , 0x41 },
  1030. { STB0899_LDT , 0xdd },
  1031. { STB0899_LDT2 , 0xc9 },
  1032. { STB0899_EQUALREF , 0xb4 },
  1033. { STB0899_TMGRAMP , 0x10 },
  1034. { STB0899_TMGTHD , 0x30 },
  1035. { STB0899_IDCCOMP , 0xfb },
  1036. { STB0899_QDCCOMP , 0x03 },
  1037. { STB0899_POWERI , 0x3b },
  1038. { STB0899_POWERQ , 0x3d },
  1039. { STB0899_RCOMP , 0x81 },
  1040. { STB0899_AGCIQIN , 0x80 },
  1041. { STB0899_AGC2I1 , 0x04 },
  1042. { STB0899_AGC2I2 , 0xf5 },
  1043. { STB0899_TLIR , 0x25 },
  1044. { STB0899_RTF , 0x80 },
  1045. { STB0899_DSTATUS , 0x00 },
  1046. { STB0899_LDI , 0xca },
  1047. { STB0899_CFRM , 0xf1 },
  1048. { STB0899_CFRL , 0xf3 },
  1049. { STB0899_NIRM , 0x2a },
  1050. { STB0899_NIRL , 0x05 },
  1051. { STB0899_ISYMB , 0x17 },
  1052. { STB0899_QSYMB , 0xfa },
  1053. { STB0899_SFRH , 0x2f },
  1054. { STB0899_SFRM , 0x68 },
  1055. { STB0899_SFRL , 0x40 },
  1056. { STB0899_SFRUPH , 0x2f },
  1057. { STB0899_SFRUPM , 0x68 },
  1058. { STB0899_SFRUPL , 0x40 },
  1059. { STB0899_EQUAI1 , 0xfd },
  1060. { STB0899_EQUAQ1 , 0x04 },
  1061. { STB0899_EQUAI2 , 0x0f },
  1062. { STB0899_EQUAQ2 , 0xff },
  1063. { STB0899_EQUAI3 , 0xdf },
  1064. { STB0899_EQUAQ3 , 0xfa },
  1065. { STB0899_EQUAI4 , 0x37 },
  1066. { STB0899_EQUAQ4 , 0x0d },
  1067. { STB0899_EQUAI5 , 0xbd },
  1068. { STB0899_EQUAQ5 , 0xf7 },
  1069. { STB0899_DSTATUS2 , 0x00 },
  1070. { STB0899_VSTATUS , 0x00 },
  1071. { STB0899_VERROR , 0xff },
  1072. { STB0899_IQSWAP , 0x2a },
  1073. { STB0899_ECNT1M , 0x00 },
  1074. { STB0899_ECNT1L , 0x00 },
  1075. { STB0899_ECNT2M , 0x00 },
  1076. { STB0899_ECNT2L , 0x00 },
  1077. { STB0899_ECNT3M , 0x00 },
  1078. { STB0899_ECNT3L , 0x00 },
  1079. { STB0899_FECAUTO1 , 0x06 },
  1080. { STB0899_FECM , 0x01 },
  1081. { STB0899_VTH12 , 0xf0 },
  1082. { STB0899_VTH23 , 0xa0 },
  1083. { STB0899_VTH34 , 0x78 },
  1084. { STB0899_VTH56 , 0x4e },
  1085. { STB0899_VTH67 , 0x48 },
  1086. { STB0899_VTH78 , 0x38 },
  1087. { STB0899_PRVIT , 0xff },
  1088. { STB0899_VITSYNC , 0x19 },
  1089. { STB0899_RSULC , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
  1090. { STB0899_TSULC , 0x42 },
  1091. { STB0899_RSLLC , 0x40 },
  1092. { STB0899_TSLPL , 0x12 },
  1093. { STB0899_TSCFGH , 0x0c },
  1094. { STB0899_TSCFGM , 0x00 },
  1095. { STB0899_TSCFGL , 0x0c },
  1096. { STB0899_TSOUT , 0x0d }, /* 0x0d for CAM */
  1097. { STB0899_RSSYNCDEL , 0x00 },
  1098. { STB0899_TSINHDELH , 0x02 },
  1099. { STB0899_TSINHDELM , 0x00 },
  1100. { STB0899_TSINHDELL , 0x00 },
  1101. { STB0899_TSLLSTKM , 0x00 },
  1102. { STB0899_TSLLSTKL , 0x00 },
  1103. { STB0899_TSULSTKM , 0x00 },
  1104. { STB0899_TSULSTKL , 0xab },
  1105. { STB0899_PCKLENUL , 0x00 },
  1106. { STB0899_PCKLENLL , 0xcc },
  1107. { STB0899_RSPCKLEN , 0xcc },
  1108. { STB0899_TSSTATUS , 0x80 },
  1109. { STB0899_ERRCTRL1 , 0xb6 },
  1110. { STB0899_ERRCTRL2 , 0x96 },
  1111. { STB0899_ERRCTRL3 , 0x89 },
  1112. { STB0899_DMONMSK1 , 0x27 },
  1113. { STB0899_DMONMSK0 , 0x03 },
  1114. { STB0899_DEMAPVIT , 0x5c },
  1115. { STB0899_PLPARM , 0x1f },
  1116. { STB0899_PDELCTRL , 0x48 },
  1117. { STB0899_PDELCTRL2 , 0x00 },
  1118. { STB0899_BBHCTRL1 , 0x00 },
  1119. { STB0899_BBHCTRL2 , 0x00 },
  1120. { STB0899_HYSTTHRESH , 0x77 },
  1121. { STB0899_MATCSTM , 0x00 },
  1122. { STB0899_MATCSTL , 0x00 },
  1123. { STB0899_UPLCSTM , 0x00 },
  1124. { STB0899_UPLCSTL , 0x00 },
  1125. { STB0899_DFLCSTM , 0x00 },
  1126. { STB0899_DFLCSTL , 0x00 },
  1127. { STB0899_SYNCCST , 0x00 },
  1128. { STB0899_SYNCDCSTM , 0x00 },
  1129. { STB0899_SYNCDCSTL , 0x00 },
  1130. { STB0899_ISI_ENTRY , 0x00 },
  1131. { STB0899_ISI_BIT_EN , 0x00 },
  1132. { STB0899_MATSTRM , 0x00 },
  1133. { STB0899_MATSTRL , 0x00 },
  1134. { STB0899_UPLSTRM , 0x00 },
  1135. { STB0899_UPLSTRL , 0x00 },
  1136. { STB0899_DFLSTRM , 0x00 },
  1137. { STB0899_DFLSTRL , 0x00 },
  1138. { STB0899_SYNCSTR , 0x00 },
  1139. { STB0899_SYNCDSTRM , 0x00 },
  1140. { STB0899_SYNCDSTRL , 0x00 },
  1141. { STB0899_CFGPDELSTATUS1 , 0x10 },
  1142. { STB0899_CFGPDELSTATUS2 , 0x00 },
  1143. { STB0899_BBFERRORM , 0x00 },
  1144. { STB0899_BBFERRORL , 0x00 },
  1145. { STB0899_UPKTERRORM , 0x00 },
  1146. { STB0899_UPKTERRORL , 0x00 },
  1147. { 0xffff , 0xff },
  1148. };
  1149. static struct stb0899_config tt3200_config = {
  1150. .init_dev = tt3200_stb0899_s1_init_1,
  1151. .init_s2_demod = stb0899_s2_init_2,
  1152. .init_s1_demod = tt3200_stb0899_s1_init_3,
  1153. .init_s2_fec = stb0899_s2_init_4,
  1154. .init_tst = stb0899_s1_init_5,
  1155. .postproc = NULL,
  1156. .demod_address = 0x68,
  1157. .xtal_freq = 27000000,
  1158. .inversion = IQ_SWAP_ON, /* 1 */
  1159. .lo_clk = 76500000,
  1160. .hi_clk = 99000000,
  1161. .esno_ave = STB0899_DVBS2_ESNO_AVE,
  1162. .esno_quant = STB0899_DVBS2_ESNO_QUANT,
  1163. .avframes_coarse = STB0899_DVBS2_AVFRAMES_COARSE,
  1164. .avframes_fine = STB0899_DVBS2_AVFRAMES_FINE,
  1165. .miss_threshold = STB0899_DVBS2_MISS_THRESHOLD,
  1166. .uwp_threshold_acq = STB0899_DVBS2_UWP_THRESHOLD_ACQ,
  1167. .uwp_threshold_track = STB0899_DVBS2_UWP_THRESHOLD_TRACK,
  1168. .uwp_threshold_sof = STB0899_DVBS2_UWP_THRESHOLD_SOF,
  1169. .sof_search_timeout = STB0899_DVBS2_SOF_SEARCH_TIMEOUT,
  1170. .btr_nco_bits = STB0899_DVBS2_BTR_NCO_BITS,
  1171. .btr_gain_shift_offset = STB0899_DVBS2_BTR_GAIN_SHIFT_OFFSET,
  1172. .crl_nco_bits = STB0899_DVBS2_CRL_NCO_BITS,
  1173. .ldpc_max_iter = STB0899_DVBS2_LDPC_MAX_ITER,
  1174. .tuner_get_frequency = stb6100_get_frequency,
  1175. .tuner_set_frequency = stb6100_set_frequency,
  1176. .tuner_set_bandwidth = stb6100_set_bandwidth,
  1177. .tuner_get_bandwidth = stb6100_get_bandwidth,
  1178. .tuner_set_rfsiggain = NULL
  1179. };
  1180. static struct stb6100_config tt3200_stb6100_config = {
  1181. .tuner_address = 0x60,
  1182. .refclock = 27000000,
  1183. };
  1184. static struct stv090x_config tt1600_stv090x_config = {
  1185. .device = STV0903,
  1186. .demod_mode = STV090x_SINGLE,
  1187. .clk_mode = STV090x_CLK_INT,
  1188. .xtal = 8000000,
  1189. .address = 0x68,
  1190. .ref_clk = 16000000,
  1191. .ts1_mode = STV090x_TSMODE_DVBCI,
  1192. .ts2_mode = STV090x_TSMODE_DVBCI,
  1193. .tuner_init = NULL,
  1194. .tuner_set_mode = NULL,
  1195. .tuner_set_frequency = NULL,
  1196. .tuner_get_frequency = NULL,
  1197. .tuner_set_bandwidth = NULL,
  1198. .tuner_get_bandwidth = NULL,
  1199. .tuner_set_bbgain = NULL,
  1200. .tuner_get_bbgain = NULL,
  1201. .tuner_set_refclk = NULL,
  1202. .tuner_get_status = NULL,
  1203. };
  1204. static struct stv6110x_config tt1600_stv6110x_config = {
  1205. .addr = 0x60,
  1206. .refclk = 16000000,
  1207. };
  1208. static struct isl6423_config tt1600_isl6423_config = {
  1209. .current_max = SEC_CURRENT_800m,
  1210. .curlim = SEC_CURRENT_LIM_ON,
  1211. .addr = 0x08,
  1212. };
  1213. static void frontend_init(struct budget_ci *budget_ci)
  1214. {
  1215. switch (budget_ci->budget.dev->pci->subsystem_device) {
  1216. case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
  1217. budget_ci->budget.dvb_frontend =
  1218. dvb_attach(stv0299_attach, &alps_bsru6_config, &budget_ci->budget.i2c_adap);
  1219. if (budget_ci->budget.dvb_frontend) {
  1220. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
  1221. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  1222. break;
  1223. }
  1224. break;
  1225. case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
  1226. budget_ci->budget.dvb_frontend =
  1227. dvb_attach(stv0299_attach, &philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
  1228. if (budget_ci->budget.dvb_frontend) {
  1229. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
  1230. break;
  1231. }
  1232. break;
  1233. case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
  1234. budget_ci->tuner_pll_address = 0x61;
  1235. budget_ci->budget.dvb_frontend =
  1236. dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  1237. if (budget_ci->budget.dvb_frontend) {
  1238. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
  1239. break;
  1240. }
  1241. break;
  1242. case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
  1243. budget_ci->tuner_pll_address = 0x63;
  1244. budget_ci->budget.dvb_frontend =
  1245. dvb_attach(tda10045_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  1246. if (budget_ci->budget.dvb_frontend) {
  1247. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  1248. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  1249. break;
  1250. }
  1251. break;
  1252. case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
  1253. budget_ci->tuner_pll_address = 0x60;
  1254. budget_ci->budget.dvb_frontend =
  1255. dvb_attach(tda10046_attach, &philips_tdm1316l_config_invert, &budget_ci->budget.i2c_adap);
  1256. if (budget_ci->budget.dvb_frontend) {
  1257. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  1258. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  1259. break;
  1260. }
  1261. break;
  1262. case 0x1017: // TT S-1500 PCI
  1263. budget_ci->budget.dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config, &budget_ci->budget.i2c_adap);
  1264. if (budget_ci->budget.dvb_frontend) {
  1265. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
  1266. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  1267. budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
  1268. if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
  1269. printk("%s: No LNBP21 found!\n", __func__);
  1270. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1271. budget_ci->budget.dvb_frontend = NULL;
  1272. }
  1273. }
  1274. break;
  1275. case 0x101a: /* TT Budget-C-1501 (philips tda10023/philips tda8274A) */
  1276. budget_ci->budget.dvb_frontend = dvb_attach(tda10023_attach, &tda10023_config, &budget_ci->budget.i2c_adap, 0x48);
  1277. if (budget_ci->budget.dvb_frontend) {
  1278. if (dvb_attach(tda827x_attach, budget_ci->budget.dvb_frontend, 0x61, &budget_ci->budget.i2c_adap, &tda827x_config) == NULL) {
  1279. printk(KERN_ERR "%s: No tda827x found!\n", __func__);
  1280. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1281. budget_ci->budget.dvb_frontend = NULL;
  1282. }
  1283. }
  1284. break;
  1285. case 0x1019: // TT S2-3200 PCI
  1286. /*
  1287. * NOTE! on some STB0899 versions, the internal PLL takes a longer time
  1288. * to settle, aka LOCK. On the older revisions of the chip, we don't see
  1289. * this, as a result on the newer chips the entire clock tree, will not
  1290. * be stable after a freshly POWER 'ed up situation.
  1291. * In this case, we should RESET the STB0899 (Active LOW) and wait for
  1292. * PLL stabilization.
  1293. *
  1294. * On the TT S2 3200 and clones, the STB0899 demodulator's RESETB is
  1295. * connected to the SAA7146 GPIO, GPIO2, Pin 142
  1296. */
  1297. /* Reset Demodulator */
  1298. saa7146_setgpio(budget_ci->budget.dev, 2, SAA7146_GPIO_OUTLO);
  1299. /* Wait for everything to die */
  1300. msleep(50);
  1301. /* Pull it up out of Reset state */
  1302. saa7146_setgpio(budget_ci->budget.dev, 2, SAA7146_GPIO_OUTHI);
  1303. /* Wait for PLL to stabilize */
  1304. msleep(250);
  1305. /*
  1306. * PLL state should be stable now. Ideally, we should check
  1307. * for PLL LOCK status. But well, never mind!
  1308. */
  1309. budget_ci->budget.dvb_frontend = dvb_attach(stb0899_attach, &tt3200_config, &budget_ci->budget.i2c_adap);
  1310. if (budget_ci->budget.dvb_frontend) {
  1311. if (dvb_attach(stb6100_attach, budget_ci->budget.dvb_frontend, &tt3200_stb6100_config, &budget_ci->budget.i2c_adap)) {
  1312. if (!dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, 0, 0)) {
  1313. printk("%s: No LNBP21 found!\n", __func__);
  1314. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1315. budget_ci->budget.dvb_frontend = NULL;
  1316. }
  1317. } else {
  1318. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1319. budget_ci->budget.dvb_frontend = NULL;
  1320. }
  1321. }
  1322. break;
  1323. case 0x101c: { /* TT S2-1600 */
  1324. struct stv6110x_devctl *ctl;
  1325. /* TODO! must verify with Andreas */
  1326. saa7146_setgpio(budget_ci->budget.dev, 2, SAA7146_GPIO_OUTLO);
  1327. msleep(50);
  1328. saa7146_setgpio(budget_ci->budget.dev, 2, SAA7146_GPIO_OUTHI);
  1329. msleep(250);
  1330. budget_ci->budget.dvb_frontend = dvb_attach(stv090x_attach,
  1331. &tt1600_stv090x_config,
  1332. &budget_ci->budget.i2c_adap,
  1333. STV090x_DEMODULATOR_0);
  1334. if (budget_ci->budget.dvb_frontend) {
  1335. ctl = dvb_attach(stv6110x_attach,
  1336. budget_ci->budget.dvb_frontend,
  1337. &tt1600_stv6110x_config,
  1338. &budget_ci->budget.i2c_adap);
  1339. tt1600_stv090x_config.tuner_init = ctl->tuner_init;
  1340. tt1600_stv090x_config.tuner_set_mode = ctl->tuner_set_mode;
  1341. tt1600_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
  1342. tt1600_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
  1343. tt1600_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
  1344. tt1600_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
  1345. tt1600_stv090x_config.tuner_set_bbgain = ctl->tuner_set_bbgain;
  1346. tt1600_stv090x_config.tuner_get_bbgain = ctl->tuner_get_bbgain;
  1347. tt1600_stv090x_config.tuner_set_refclk = ctl->tuner_set_refclk;
  1348. tt1600_stv090x_config.tuner_get_status = ctl->tuner_get_status;
  1349. dvb_attach(isl6423_attach,
  1350. budget_ci->budget.dvb_frontend,
  1351. &budget_ci->budget.i2c_adap,
  1352. &tt1600_isl6423_config);
  1353. } else {
  1354. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1355. budget_ci->budget.dvb_frontend = NULL;
  1356. }
  1357. }
  1358. break;
  1359. }
  1360. if (budget_ci->budget.dvb_frontend == NULL) {
  1361. printk("budget-ci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
  1362. budget_ci->budget.dev->pci->vendor,
  1363. budget_ci->budget.dev->pci->device,
  1364. budget_ci->budget.dev->pci->subsystem_vendor,
  1365. budget_ci->budget.dev->pci->subsystem_device);
  1366. } else {
  1367. if (dvb_register_frontend
  1368. (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
  1369. printk("budget-ci: Frontend registration failed!\n");
  1370. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1371. budget_ci->budget.dvb_frontend = NULL;
  1372. }
  1373. }
  1374. }
  1375. static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
  1376. {
  1377. struct budget_ci *budget_ci;
  1378. int err;
  1379. budget_ci = kzalloc(sizeof(struct budget_ci), GFP_KERNEL);
  1380. if (!budget_ci) {
  1381. err = -ENOMEM;
  1382. goto out1;
  1383. }
  1384. dprintk(2, "budget_ci: %p\n", budget_ci);
  1385. dev->ext_priv = budget_ci;
  1386. err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE,
  1387. adapter_nr);
  1388. if (err)
  1389. goto out2;
  1390. err = msp430_ir_init(budget_ci);
  1391. if (err)
  1392. goto out3;
  1393. ciintf_init(budget_ci);
  1394. budget_ci->budget.dvb_adapter.priv = budget_ci;
  1395. frontend_init(budget_ci);
  1396. ttpci_budget_init_hooks(&budget_ci->budget);
  1397. return 0;
  1398. out3:
  1399. ttpci_budget_deinit(&budget_ci->budget);
  1400. out2:
  1401. kfree(budget_ci);
  1402. out1:
  1403. return err;
  1404. }
  1405. static int budget_ci_detach(struct saa7146_dev *dev)
  1406. {
  1407. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  1408. struct saa7146_dev *saa = budget_ci->budget.dev;
  1409. int err;
  1410. if (budget_ci->budget.ci_present)
  1411. ciintf_deinit(budget_ci);
  1412. msp430_ir_deinit(budget_ci);
  1413. if (budget_ci->budget.dvb_frontend) {
  1414. dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
  1415. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1416. }
  1417. err = ttpci_budget_deinit(&budget_ci->budget);
  1418. // disable frontend and CI interface
  1419. saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
  1420. kfree(budget_ci);
  1421. return err;
  1422. }
  1423. static struct saa7146_extension budget_extension;
  1424. MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
  1425. MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
  1426. MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
  1427. MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
  1428. MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
  1429. MAKE_BUDGET_INFO(ttc1501, "TT-Budget C-1501 PCI", BUDGET_TT);
  1430. MAKE_BUDGET_INFO(tt3200, "TT-Budget S2-3200 PCI", BUDGET_TT);
  1431. MAKE_BUDGET_INFO(tt1600, "TT-Budget S2-1600 PCI", BUDGET_TT);
  1432. static struct pci_device_id pci_tbl[] = {
  1433. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
  1434. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
  1435. MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
  1436. MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
  1437. MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
  1438. MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
  1439. MAKE_EXTENSION_PCI(ttc1501, 0x13c2, 0x101a),
  1440. MAKE_EXTENSION_PCI(tt3200, 0x13c2, 0x1019),
  1441. MAKE_EXTENSION_PCI(tt1600, 0x13c2, 0x101c),
  1442. {
  1443. .vendor = 0,
  1444. }
  1445. };
  1446. MODULE_DEVICE_TABLE(pci, pci_tbl);
  1447. static struct saa7146_extension budget_extension = {
  1448. .name = "budget_ci dvb",
  1449. .flags = SAA7146_USE_I2C_IRQ,
  1450. .module = THIS_MODULE,
  1451. .pci_tbl = &pci_tbl[0],
  1452. .attach = budget_ci_attach,
  1453. .detach = budget_ci_detach,
  1454. .irq_mask = MASK_03 | MASK_06 | MASK_10,
  1455. .irq_func = budget_ci_irq,
  1456. };
  1457. static int __init budget_ci_init(void)
  1458. {
  1459. return saa7146_register_extension(&budget_extension);
  1460. }
  1461. static void __exit budget_ci_exit(void)
  1462. {
  1463. saa7146_unregister_extension(&budget_extension);
  1464. }
  1465. module_init(budget_ci_init);
  1466. module_exit(budget_ci_exit);
  1467. MODULE_LICENSE("GPL");
  1468. MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
  1469. MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
  1470. "budget PCI DVB cards w/ CI-module produced by "
  1471. "Siemens, Technotrend, Hauppauge");