budget-ci.c 45 KB

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