budget-ci.c 46 KB

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