budget-ci.c 45 KB

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