budget-ci.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  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 "budget.h"
  32. #include <linux/module.h>
  33. #include <linux/errno.h>
  34. #include <linux/slab.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/input.h>
  37. #include <linux/spinlock.h>
  38. #include "dvb_ca_en50221.h"
  39. #include "stv0299.h"
  40. #include "stv0297.h"
  41. #include "tda1004x.h"
  42. #include "lnbp21.h"
  43. #include "bsbe1.h"
  44. #include "bsru6.h"
  45. #define DEBIADDR_IR 0x1234
  46. #define DEBIADDR_CICONTROL 0x0000
  47. #define DEBIADDR_CIVERSION 0x4000
  48. #define DEBIADDR_IO 0x1000
  49. #define DEBIADDR_ATTR 0x3000
  50. #define CICONTROL_RESET 0x01
  51. #define CICONTROL_ENABLETS 0x02
  52. #define CICONTROL_CAMDETECT 0x08
  53. #define DEBICICTL 0x00420000
  54. #define DEBICICAM 0x02420000
  55. #define SLOTSTATUS_NONE 1
  56. #define SLOTSTATUS_PRESENT 2
  57. #define SLOTSTATUS_RESET 4
  58. #define SLOTSTATUS_READY 8
  59. #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
  60. struct budget_ci {
  61. struct budget budget;
  62. struct input_dev *input_dev;
  63. struct tasklet_struct msp430_irq_tasklet;
  64. struct tasklet_struct ciintf_irq_tasklet;
  65. int slot_status;
  66. int ci_irq;
  67. struct dvb_ca_en50221 ca;
  68. char ir_dev_name[50];
  69. u8 tuner_pll_address; /* used for philips_tdm1316l configs */
  70. };
  71. /* from reading the following remotes:
  72. Zenith Universal 7 / TV Mode 807 / VCR Mode 837
  73. Hauppauge (from NOVA-CI-s box product)
  74. i've taken a "middle of the road" approach and note the differences
  75. */
  76. static u16 key_map[64] = {
  77. /* 0x0X */
  78. KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8,
  79. KEY_9,
  80. KEY_ENTER,
  81. KEY_RED,
  82. KEY_POWER, /* RADIO on Hauppauge */
  83. KEY_MUTE,
  84. 0,
  85. KEY_A, /* TV on Hauppauge */
  86. /* 0x1X */
  87. KEY_VOLUMEUP, KEY_VOLUMEDOWN,
  88. 0, 0,
  89. KEY_B,
  90. 0, 0, 0, 0, 0, 0, 0,
  91. KEY_UP, KEY_DOWN,
  92. KEY_OPTION, /* RESERVED on Hauppauge */
  93. KEY_BREAK,
  94. /* 0x2X */
  95. KEY_CHANNELUP, KEY_CHANNELDOWN,
  96. KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */
  97. 0, KEY_RESTART, KEY_OK,
  98. KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */
  99. 0,
  100. KEY_ENTER, /* VCR mode on Zenith */
  101. KEY_PAUSE,
  102. 0,
  103. KEY_RIGHT, KEY_LEFT,
  104. 0,
  105. KEY_MENU, /* FULL SCREEN on Hauppauge */
  106. 0,
  107. /* 0x3X */
  108. KEY_SLOW,
  109. KEY_PREVIOUS, /* VCR mode on Zenith */
  110. KEY_REWIND,
  111. 0,
  112. KEY_FASTFORWARD,
  113. KEY_PLAY, KEY_STOP,
  114. KEY_RECORD,
  115. KEY_TUNER, /* TV/VCR on Zenith */
  116. 0,
  117. KEY_C,
  118. 0,
  119. KEY_EXIT,
  120. KEY_POWER2,
  121. KEY_TUNER, /* VCR mode on Zenith */
  122. 0,
  123. };
  124. static void msp430_ir_debounce(unsigned long data)
  125. {
  126. struct input_dev *dev = (struct input_dev *) data;
  127. if (dev->rep[0] == 0 || dev->rep[0] == ~0) {
  128. input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
  129. return;
  130. }
  131. dev->rep[0] = 0;
  132. dev->timer.expires = jiffies + HZ * 350 / 1000;
  133. add_timer(&dev->timer);
  134. input_event(dev, EV_KEY, key_map[dev->repeat_key], 2); /* REPEAT */
  135. }
  136. static void msp430_ir_interrupt(unsigned long data)
  137. {
  138. struct budget_ci *budget_ci = (struct budget_ci *) data;
  139. struct input_dev *dev = budget_ci->input_dev;
  140. unsigned int code =
  141. ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
  142. if (code & 0x40) {
  143. code &= 0x3f;
  144. if (timer_pending(&dev->timer)) {
  145. if (code == dev->repeat_key) {
  146. ++dev->rep[0];
  147. return;
  148. }
  149. del_timer(&dev->timer);
  150. input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
  151. }
  152. if (!key_map[code]) {
  153. printk("DVB (%s): no key for %02x!\n", __FUNCTION__, code);
  154. return;
  155. }
  156. /* initialize debounce and repeat */
  157. dev->repeat_key = code;
  158. /* Zenith remote _always_ sends 2 sequences */
  159. dev->rep[0] = ~0;
  160. /* 350 milliseconds */
  161. dev->timer.expires = jiffies + HZ * 350 / 1000;
  162. /* MAKE */
  163. input_event(dev, EV_KEY, key_map[code], !0);
  164. add_timer(&dev->timer);
  165. }
  166. }
  167. static int msp430_ir_init(struct budget_ci *budget_ci)
  168. {
  169. struct saa7146_dev *saa = budget_ci->budget.dev;
  170. struct input_dev *input_dev;
  171. int i;
  172. budget_ci->input_dev = input_dev = input_allocate_device();
  173. if (!input_dev)
  174. return -ENOMEM;
  175. sprintf(budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", saa->name);
  176. input_dev->name = budget_ci->ir_dev_name;
  177. set_bit(EV_KEY, input_dev->evbit);
  178. for (i = 0; i < ARRAY_SIZE(key_map); i++)
  179. if (key_map[i])
  180. set_bit(key_map[i], input_dev->keybit);
  181. input_register_device(budget_ci->input_dev);
  182. input_dev->timer.function = msp430_ir_debounce;
  183. saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06);
  184. saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
  185. return 0;
  186. }
  187. static void msp430_ir_deinit(struct budget_ci *budget_ci)
  188. {
  189. struct saa7146_dev *saa = budget_ci->budget.dev;
  190. struct input_dev *dev = budget_ci->input_dev;
  191. saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06);
  192. saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
  193. if (del_timer(&dev->timer))
  194. input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
  195. input_unregister_device(dev);
  196. }
  197. static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
  198. {
  199. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  200. if (slot != 0)
  201. return -EINVAL;
  202. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  203. DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
  204. }
  205. static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
  206. {
  207. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  208. if (slot != 0)
  209. return -EINVAL;
  210. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  211. DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
  212. }
  213. static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
  214. {
  215. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  216. if (slot != 0)
  217. return -EINVAL;
  218. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  219. DEBIADDR_IO | (address & 3), 1, 1, 0);
  220. }
  221. static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
  222. {
  223. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  224. if (slot != 0)
  225. return -EINVAL;
  226. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  227. DEBIADDR_IO | (address & 3), 1, value, 1, 0);
  228. }
  229. static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
  230. {
  231. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  232. struct saa7146_dev *saa = budget_ci->budget.dev;
  233. if (slot != 0)
  234. return -EINVAL;
  235. if (budget_ci->ci_irq) {
  236. // trigger on RISING edge during reset so we know when READY is re-asserted
  237. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  238. }
  239. budget_ci->slot_status = SLOTSTATUS_RESET;
  240. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  241. msleep(1);
  242. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  243. CICONTROL_RESET, 1, 0);
  244. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  245. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  246. return 0;
  247. }
  248. static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
  249. {
  250. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  251. struct saa7146_dev *saa = budget_ci->budget.dev;
  252. if (slot != 0)
  253. return -EINVAL;
  254. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  255. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  256. return 0;
  257. }
  258. static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
  259. {
  260. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  261. struct saa7146_dev *saa = budget_ci->budget.dev;
  262. int tmp;
  263. if (slot != 0)
  264. return -EINVAL;
  265. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
  266. tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  267. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  268. tmp | CICONTROL_ENABLETS, 1, 0);
  269. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
  270. return 0;
  271. }
  272. static void ciintf_interrupt(unsigned long data)
  273. {
  274. struct budget_ci *budget_ci = (struct budget_ci *) data;
  275. struct saa7146_dev *saa = budget_ci->budget.dev;
  276. unsigned int flags;
  277. // ensure we don't get spurious IRQs during initialisation
  278. if (!budget_ci->budget.ci_present)
  279. return;
  280. // read the CAM status
  281. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  282. if (flags & CICONTROL_CAMDETECT) {
  283. // GPIO should be set to trigger on falling edge if a CAM is present
  284. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  285. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  286. // CAM insertion IRQ
  287. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  288. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  289. DVB_CA_EN50221_CAMCHANGE_INSERTED);
  290. } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  291. // CAM ready (reset completed)
  292. budget_ci->slot_status = SLOTSTATUS_READY;
  293. dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
  294. } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
  295. // FR/DA IRQ
  296. dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
  297. }
  298. } else {
  299. // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
  300. // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
  301. // the CAM might not actually be ready yet.
  302. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  303. // generate a CAM removal IRQ if we haven't already
  304. if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
  305. // CAM removal IRQ
  306. budget_ci->slot_status = SLOTSTATUS_NONE;
  307. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  308. DVB_CA_EN50221_CAMCHANGE_REMOVED);
  309. }
  310. }
  311. }
  312. static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
  313. {
  314. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  315. unsigned int flags;
  316. // ensure we don't get spurious IRQs during initialisation
  317. if (!budget_ci->budget.ci_present)
  318. return -EINVAL;
  319. // read the CAM status
  320. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  321. if (flags & CICONTROL_CAMDETECT) {
  322. // mark it as present if it wasn't before
  323. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  324. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  325. }
  326. // during a RESET, we check if we can read from IO memory to see when CAM is ready
  327. if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  328. if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
  329. budget_ci->slot_status = SLOTSTATUS_READY;
  330. }
  331. }
  332. } else {
  333. budget_ci->slot_status = SLOTSTATUS_NONE;
  334. }
  335. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  336. if (budget_ci->slot_status & SLOTSTATUS_READY) {
  337. return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
  338. }
  339. return DVB_CA_EN50221_POLL_CAM_PRESENT;
  340. }
  341. return 0;
  342. }
  343. static int ciintf_init(struct budget_ci *budget_ci)
  344. {
  345. struct saa7146_dev *saa = budget_ci->budget.dev;
  346. int flags;
  347. int result;
  348. int ci_version;
  349. int ca_flags;
  350. memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
  351. // enable DEBI pins
  352. saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800);
  353. // test if it is there
  354. ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
  355. if ((ci_version & 0xa0) != 0xa0) {
  356. result = -ENODEV;
  357. goto error;
  358. }
  359. // determine whether a CAM is present or not
  360. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  361. budget_ci->slot_status = SLOTSTATUS_NONE;
  362. if (flags & CICONTROL_CAMDETECT)
  363. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  364. // version 0xa2 of the CI firmware doesn't generate interrupts
  365. if (ci_version == 0xa2) {
  366. ca_flags = 0;
  367. budget_ci->ci_irq = 0;
  368. } else {
  369. ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
  370. DVB_CA_EN50221_FLAG_IRQ_FR |
  371. DVB_CA_EN50221_FLAG_IRQ_DA;
  372. budget_ci->ci_irq = 1;
  373. }
  374. // register CI interface
  375. budget_ci->ca.owner = THIS_MODULE;
  376. budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
  377. budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
  378. budget_ci->ca.read_cam_control = ciintf_read_cam_control;
  379. budget_ci->ca.write_cam_control = ciintf_write_cam_control;
  380. budget_ci->ca.slot_reset = ciintf_slot_reset;
  381. budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
  382. budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
  383. budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
  384. budget_ci->ca.data = budget_ci;
  385. if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
  386. &budget_ci->ca,
  387. ca_flags, 1)) != 0) {
  388. printk("budget_ci: CI interface detected, but initialisation failed.\n");
  389. goto error;
  390. }
  391. // Setup CI slot IRQ
  392. if (budget_ci->ci_irq) {
  393. tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
  394. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  395. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  396. } else {
  397. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  398. }
  399. saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_03);
  400. }
  401. // enable interface
  402. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  403. CICONTROL_RESET, 1, 0);
  404. // success!
  405. printk("budget_ci: CI interface initialised\n");
  406. budget_ci->budget.ci_present = 1;
  407. // forge a fake CI IRQ so the CAM state is setup correctly
  408. if (budget_ci->ci_irq) {
  409. flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
  410. if (budget_ci->slot_status != SLOTSTATUS_NONE)
  411. flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
  412. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
  413. }
  414. return 0;
  415. error:
  416. saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
  417. return result;
  418. }
  419. static void ciintf_deinit(struct budget_ci *budget_ci)
  420. {
  421. struct saa7146_dev *saa = budget_ci->budget.dev;
  422. // disable CI interrupts
  423. if (budget_ci->ci_irq) {
  424. saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_03);
  425. saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
  426. tasklet_kill(&budget_ci->ciintf_irq_tasklet);
  427. }
  428. // reset interface
  429. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  430. msleep(1);
  431. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  432. CICONTROL_RESET, 1, 0);
  433. // disable TS data stream to CI interface
  434. saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
  435. // release the CA device
  436. dvb_ca_en50221_release(&budget_ci->ca);
  437. // disable DEBI pins
  438. saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16));
  439. }
  440. static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
  441. {
  442. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  443. dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
  444. if (*isr & MASK_06)
  445. tasklet_schedule(&budget_ci->msp430_irq_tasklet);
  446. if (*isr & MASK_10)
  447. ttpci_budget_irq10_handler(dev, isr);
  448. if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
  449. tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
  450. }
  451. static u8 philips_su1278_tt_inittab[] = {
  452. 0x01, 0x0f,
  453. 0x02, 0x30,
  454. 0x03, 0x00,
  455. 0x04, 0x5b,
  456. 0x05, 0x85,
  457. 0x06, 0x02,
  458. 0x07, 0x00,
  459. 0x08, 0x02,
  460. 0x09, 0x00,
  461. 0x0C, 0x01,
  462. 0x0D, 0x81,
  463. 0x0E, 0x44,
  464. 0x0f, 0x14,
  465. 0x10, 0x3c,
  466. 0x11, 0x84,
  467. 0x12, 0xda,
  468. 0x13, 0x97,
  469. 0x14, 0x95,
  470. 0x15, 0xc9,
  471. 0x16, 0x19,
  472. 0x17, 0x8c,
  473. 0x18, 0x59,
  474. 0x19, 0xf8,
  475. 0x1a, 0xfe,
  476. 0x1c, 0x7f,
  477. 0x1d, 0x00,
  478. 0x1e, 0x00,
  479. 0x1f, 0x50,
  480. 0x20, 0x00,
  481. 0x21, 0x00,
  482. 0x22, 0x00,
  483. 0x23, 0x00,
  484. 0x28, 0x00,
  485. 0x29, 0x28,
  486. 0x2a, 0x14,
  487. 0x2b, 0x0f,
  488. 0x2c, 0x09,
  489. 0x2d, 0x09,
  490. 0x31, 0x1f,
  491. 0x32, 0x19,
  492. 0x33, 0xfc,
  493. 0x34, 0x93,
  494. 0xff, 0xff
  495. };
  496. static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
  497. {
  498. stv0299_writereg(fe, 0x0e, 0x44);
  499. if (srate >= 10000000) {
  500. stv0299_writereg(fe, 0x13, 0x97);
  501. stv0299_writereg(fe, 0x14, 0x95);
  502. stv0299_writereg(fe, 0x15, 0xc9);
  503. stv0299_writereg(fe, 0x17, 0x8c);
  504. stv0299_writereg(fe, 0x1a, 0xfe);
  505. stv0299_writereg(fe, 0x1c, 0x7f);
  506. stv0299_writereg(fe, 0x2d, 0x09);
  507. } else {
  508. stv0299_writereg(fe, 0x13, 0x99);
  509. stv0299_writereg(fe, 0x14, 0x8d);
  510. stv0299_writereg(fe, 0x15, 0xce);
  511. stv0299_writereg(fe, 0x17, 0x43);
  512. stv0299_writereg(fe, 0x1a, 0x1d);
  513. stv0299_writereg(fe, 0x1c, 0x12);
  514. stv0299_writereg(fe, 0x2d, 0x05);
  515. }
  516. stv0299_writereg(fe, 0x0e, 0x23);
  517. stv0299_writereg(fe, 0x0f, 0x94);
  518. stv0299_writereg(fe, 0x10, 0x39);
  519. stv0299_writereg(fe, 0x15, 0xc9);
  520. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  521. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  522. stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
  523. return 0;
  524. }
  525. static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe,
  526. struct dvb_frontend_parameters *params)
  527. {
  528. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  529. u32 div;
  530. u8 buf[4];
  531. struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
  532. if ((params->frequency < 950000) || (params->frequency > 2150000))
  533. return -EINVAL;
  534. div = (params->frequency + (500 - 1)) / 500; // round correctly
  535. buf[0] = (div >> 8) & 0x7f;
  536. buf[1] = div & 0xff;
  537. buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
  538. buf[3] = 0x20;
  539. if (params->u.qpsk.symbol_rate < 4000000)
  540. buf[3] |= 1;
  541. if (params->frequency < 1250000)
  542. buf[3] |= 0;
  543. else if (params->frequency < 1550000)
  544. buf[3] |= 0x40;
  545. else if (params->frequency < 2050000)
  546. buf[3] |= 0x80;
  547. else if (params->frequency < 2150000)
  548. buf[3] |= 0xC0;
  549. if (fe->ops.i2c_gate_ctrl)
  550. fe->ops.i2c_gate_ctrl(fe, 1);
  551. if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
  552. return -EIO;
  553. return 0;
  554. }
  555. static struct stv0299_config philips_su1278_tt_config = {
  556. .demod_address = 0x68,
  557. .inittab = philips_su1278_tt_inittab,
  558. .mclk = 64000000UL,
  559. .invert = 0,
  560. .skip_reinit = 1,
  561. .lock_output = STV0229_LOCKOUTPUT_1,
  562. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  563. .min_delay_ms = 50,
  564. .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
  565. };
  566. static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
  567. {
  568. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  569. static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  570. static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
  571. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
  572. sizeof(td1316_init) };
  573. // setup PLL configuration
  574. if (fe->ops.i2c_gate_ctrl)
  575. fe->ops.i2c_gate_ctrl(fe, 1);
  576. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  577. return -EIO;
  578. msleep(1);
  579. // disable the mc44BC374c (do not check for errors)
  580. tuner_msg.addr = 0x65;
  581. tuner_msg.buf = disable_mc44BC374c;
  582. tuner_msg.len = sizeof(disable_mc44BC374c);
  583. if (fe->ops.i2c_gate_ctrl)
  584. fe->ops.i2c_gate_ctrl(fe, 1);
  585. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
  586. if (fe->ops.i2c_gate_ctrl)
  587. fe->ops.i2c_gate_ctrl(fe, 1);
  588. i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
  589. }
  590. return 0;
  591. }
  592. static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  593. {
  594. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  595. u8 tuner_buf[4];
  596. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
  597. int tuner_frequency = 0;
  598. u8 band, cp, filter;
  599. // determine charge pump
  600. tuner_frequency = params->frequency + 36130000;
  601. if (tuner_frequency < 87000000)
  602. return -EINVAL;
  603. else if (tuner_frequency < 130000000)
  604. cp = 3;
  605. else if (tuner_frequency < 160000000)
  606. cp = 5;
  607. else if (tuner_frequency < 200000000)
  608. cp = 6;
  609. else if (tuner_frequency < 290000000)
  610. cp = 3;
  611. else if (tuner_frequency < 420000000)
  612. cp = 5;
  613. else if (tuner_frequency < 480000000)
  614. cp = 6;
  615. else if (tuner_frequency < 620000000)
  616. cp = 3;
  617. else if (tuner_frequency < 830000000)
  618. cp = 5;
  619. else if (tuner_frequency < 895000000)
  620. cp = 7;
  621. else
  622. return -EINVAL;
  623. // determine band
  624. if (params->frequency < 49000000)
  625. return -EINVAL;
  626. else if (params->frequency < 159000000)
  627. band = 1;
  628. else if (params->frequency < 444000000)
  629. band = 2;
  630. else if (params->frequency < 861000000)
  631. band = 4;
  632. else
  633. return -EINVAL;
  634. // setup PLL filter and TDA9889
  635. switch (params->u.ofdm.bandwidth) {
  636. case BANDWIDTH_6_MHZ:
  637. tda1004x_write_byte(fe, 0x0C, 0x14);
  638. filter = 0;
  639. break;
  640. case BANDWIDTH_7_MHZ:
  641. tda1004x_write_byte(fe, 0x0C, 0x80);
  642. filter = 0;
  643. break;
  644. case BANDWIDTH_8_MHZ:
  645. tda1004x_write_byte(fe, 0x0C, 0x14);
  646. filter = 1;
  647. break;
  648. default:
  649. return -EINVAL;
  650. }
  651. // calculate divisor
  652. // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
  653. tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
  654. // setup tuner buffer
  655. tuner_buf[0] = tuner_frequency >> 8;
  656. tuner_buf[1] = tuner_frequency & 0xff;
  657. tuner_buf[2] = 0xca;
  658. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  659. if (fe->ops.i2c_gate_ctrl)
  660. fe->ops.i2c_gate_ctrl(fe, 1);
  661. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  662. return -EIO;
  663. msleep(1);
  664. return 0;
  665. }
  666. static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
  667. const struct firmware **fw, char *name)
  668. {
  669. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  670. return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
  671. }
  672. static struct tda1004x_config philips_tdm1316l_config = {
  673. .demod_address = 0x8,
  674. .invert = 0,
  675. .invert_oclk = 0,
  676. .xtal_freq = TDA10046_XTAL_4M,
  677. .agc_config = TDA10046_AGC_DEFAULT,
  678. .if_freq = TDA10046_FREQ_3617,
  679. .request_firmware = philips_tdm1316l_request_firmware,
  680. };
  681. static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  682. {
  683. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  684. u8 tuner_buf[5];
  685. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
  686. .flags = 0,
  687. .buf = tuner_buf,
  688. .len = sizeof(tuner_buf) };
  689. int tuner_frequency = 0;
  690. u8 band, cp, filter;
  691. // determine charge pump
  692. tuner_frequency = params->frequency + 36125000;
  693. if (tuner_frequency < 87000000)
  694. return -EINVAL;
  695. else if (tuner_frequency < 130000000) {
  696. cp = 3;
  697. band = 1;
  698. } else if (tuner_frequency < 160000000) {
  699. cp = 5;
  700. band = 1;
  701. } else if (tuner_frequency < 200000000) {
  702. cp = 6;
  703. band = 1;
  704. } else if (tuner_frequency < 290000000) {
  705. cp = 3;
  706. band = 2;
  707. } else if (tuner_frequency < 420000000) {
  708. cp = 5;
  709. band = 2;
  710. } else if (tuner_frequency < 480000000) {
  711. cp = 6;
  712. band = 2;
  713. } else if (tuner_frequency < 620000000) {
  714. cp = 3;
  715. band = 4;
  716. } else if (tuner_frequency < 830000000) {
  717. cp = 5;
  718. band = 4;
  719. } else if (tuner_frequency < 895000000) {
  720. cp = 7;
  721. band = 4;
  722. } else
  723. return -EINVAL;
  724. // assume PLL filter should always be 8MHz for the moment.
  725. filter = 1;
  726. // calculate divisor
  727. tuner_frequency = (params->frequency + 36125000 + (62500/2)) / 62500;
  728. // setup tuner buffer
  729. tuner_buf[0] = tuner_frequency >> 8;
  730. tuner_buf[1] = tuner_frequency & 0xff;
  731. tuner_buf[2] = 0xc8;
  732. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  733. tuner_buf[4] = 0x80;
  734. if (fe->ops.i2c_gate_ctrl)
  735. fe->ops.i2c_gate_ctrl(fe, 1);
  736. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  737. return -EIO;
  738. msleep(50);
  739. if (fe->ops.i2c_gate_ctrl)
  740. fe->ops.i2c_gate_ctrl(fe, 1);
  741. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  742. return -EIO;
  743. msleep(1);
  744. return 0;
  745. }
  746. static u8 dvbc_philips_tdm1316l_inittab[] = {
  747. 0x80, 0x01,
  748. 0x80, 0x00,
  749. 0x81, 0x01,
  750. 0x81, 0x00,
  751. 0x00, 0x09,
  752. 0x01, 0x69,
  753. 0x03, 0x00,
  754. 0x04, 0x00,
  755. 0x07, 0x00,
  756. 0x08, 0x00,
  757. 0x20, 0x00,
  758. 0x21, 0x40,
  759. 0x22, 0x00,
  760. 0x23, 0x00,
  761. 0x24, 0x40,
  762. 0x25, 0x88,
  763. 0x30, 0xff,
  764. 0x31, 0x00,
  765. 0x32, 0xff,
  766. 0x33, 0x00,
  767. 0x34, 0x50,
  768. 0x35, 0x7f,
  769. 0x36, 0x00,
  770. 0x37, 0x20,
  771. 0x38, 0x00,
  772. 0x40, 0x1c,
  773. 0x41, 0xff,
  774. 0x42, 0x29,
  775. 0x43, 0x20,
  776. 0x44, 0xff,
  777. 0x45, 0x00,
  778. 0x46, 0x00,
  779. 0x49, 0x04,
  780. 0x4a, 0x00,
  781. 0x4b, 0x7b,
  782. 0x52, 0x30,
  783. 0x55, 0xae,
  784. 0x56, 0x47,
  785. 0x57, 0xe1,
  786. 0x58, 0x3a,
  787. 0x5a, 0x1e,
  788. 0x5b, 0x34,
  789. 0x60, 0x00,
  790. 0x63, 0x00,
  791. 0x64, 0x00,
  792. 0x65, 0x00,
  793. 0x66, 0x00,
  794. 0x67, 0x00,
  795. 0x68, 0x00,
  796. 0x69, 0x00,
  797. 0x6a, 0x02,
  798. 0x6b, 0x00,
  799. 0x70, 0xff,
  800. 0x71, 0x00,
  801. 0x72, 0x00,
  802. 0x73, 0x00,
  803. 0x74, 0x0c,
  804. 0x80, 0x00,
  805. 0x81, 0x00,
  806. 0x82, 0x00,
  807. 0x83, 0x00,
  808. 0x84, 0x04,
  809. 0x85, 0x80,
  810. 0x86, 0x24,
  811. 0x87, 0x78,
  812. 0x88, 0x10,
  813. 0x89, 0x00,
  814. 0x90, 0x01,
  815. 0x91, 0x01,
  816. 0xa0, 0x04,
  817. 0xa1, 0x00,
  818. 0xa2, 0x00,
  819. 0xb0, 0x91,
  820. 0xb1, 0x0b,
  821. 0xc0, 0x53,
  822. 0xc1, 0x70,
  823. 0xc2, 0x12,
  824. 0xd0, 0x00,
  825. 0xd1, 0x00,
  826. 0xd2, 0x00,
  827. 0xd3, 0x00,
  828. 0xd4, 0x00,
  829. 0xd5, 0x00,
  830. 0xde, 0x00,
  831. 0xdf, 0x00,
  832. 0x61, 0x38,
  833. 0x62, 0x0a,
  834. 0x53, 0x13,
  835. 0x59, 0x08,
  836. 0xff, 0xff,
  837. };
  838. static struct stv0297_config dvbc_philips_tdm1316l_config = {
  839. .demod_address = 0x1c,
  840. .inittab = dvbc_philips_tdm1316l_inittab,
  841. .invert = 0,
  842. .stop_during_read = 1,
  843. };
  844. static void frontend_init(struct budget_ci *budget_ci)
  845. {
  846. switch (budget_ci->budget.dev->pci->subsystem_device) {
  847. case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
  848. budget_ci->budget.dvb_frontend =
  849. stv0299_attach(&alps_bsru6_config, &budget_ci->budget.i2c_adap);
  850. if (budget_ci->budget.dvb_frontend) {
  851. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
  852. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  853. break;
  854. }
  855. break;
  856. case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
  857. budget_ci->budget.dvb_frontend =
  858. stv0299_attach(&philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
  859. if (budget_ci->budget.dvb_frontend) {
  860. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
  861. break;
  862. }
  863. break;
  864. case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
  865. budget_ci->tuner_pll_address = 0x61;
  866. budget_ci->budget.dvb_frontend =
  867. stv0297_attach(&dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  868. if (budget_ci->budget.dvb_frontend) {
  869. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
  870. break;
  871. }
  872. break;
  873. case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
  874. budget_ci->tuner_pll_address = 0x63;
  875. budget_ci->budget.dvb_frontend =
  876. tda10045_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  877. if (budget_ci->budget.dvb_frontend) {
  878. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  879. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  880. break;
  881. }
  882. break;
  883. case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
  884. budget_ci->tuner_pll_address = 0x60;
  885. budget_ci->budget.dvb_frontend =
  886. tda10046_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  887. if (budget_ci->budget.dvb_frontend) {
  888. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  889. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  890. break;
  891. }
  892. break;
  893. case 0x1017: // TT S-1500 PCI
  894. budget_ci->budget.dvb_frontend = stv0299_attach(&alps_bsbe1_config, &budget_ci->budget.i2c_adap);
  895. if (budget_ci->budget.dvb_frontend) {
  896. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
  897. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  898. budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
  899. if (lnbp21_attach(budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0)) {
  900. printk("%s: No LNBP21 found!\n", __FUNCTION__);
  901. if (budget_ci->budget.dvb_frontend->ops.release)
  902. budget_ci->budget.dvb_frontend->ops.release(budget_ci->budget.dvb_frontend);
  903. budget_ci->budget.dvb_frontend = NULL;
  904. }
  905. }
  906. break;
  907. }
  908. if (budget_ci->budget.dvb_frontend == NULL) {
  909. printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
  910. budget_ci->budget.dev->pci->vendor,
  911. budget_ci->budget.dev->pci->device,
  912. budget_ci->budget.dev->pci->subsystem_vendor,
  913. budget_ci->budget.dev->pci->subsystem_device);
  914. } else {
  915. if (dvb_register_frontend
  916. (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
  917. printk("budget-ci: Frontend registration failed!\n");
  918. if (budget_ci->budget.dvb_frontend->ops.release)
  919. budget_ci->budget.dvb_frontend->ops.release(budget_ci->budget.dvb_frontend);
  920. budget_ci->budget.dvb_frontend = NULL;
  921. }
  922. }
  923. }
  924. static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
  925. {
  926. struct budget_ci *budget_ci;
  927. int err;
  928. if (!(budget_ci = kmalloc(sizeof(struct budget_ci), GFP_KERNEL)))
  929. return -ENOMEM;
  930. dprintk(2, "budget_ci: %p\n", budget_ci);
  931. budget_ci->budget.ci_present = 0;
  932. dev->ext_priv = budget_ci;
  933. if ((err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE))) {
  934. kfree(budget_ci);
  935. return err;
  936. }
  937. tasklet_init(&budget_ci->msp430_irq_tasklet, msp430_ir_interrupt,
  938. (unsigned long) budget_ci);
  939. msp430_ir_init(budget_ci);
  940. ciintf_init(budget_ci);
  941. budget_ci->budget.dvb_adapter.priv = budget_ci;
  942. frontend_init(budget_ci);
  943. ttpci_budget_init_hooks(&budget_ci->budget);
  944. return 0;
  945. }
  946. static int budget_ci_detach(struct saa7146_dev *dev)
  947. {
  948. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  949. struct saa7146_dev *saa = budget_ci->budget.dev;
  950. int err;
  951. if (budget_ci->budget.ci_present)
  952. ciintf_deinit(budget_ci);
  953. if (budget_ci->budget.dvb_frontend)
  954. dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
  955. err = ttpci_budget_deinit(&budget_ci->budget);
  956. tasklet_kill(&budget_ci->msp430_irq_tasklet);
  957. msp430_ir_deinit(budget_ci);
  958. // disable frontend and CI interface
  959. saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
  960. kfree(budget_ci);
  961. return err;
  962. }
  963. static struct saa7146_extension budget_extension;
  964. MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
  965. MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
  966. MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
  967. MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
  968. MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
  969. static struct pci_device_id pci_tbl[] = {
  970. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
  971. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
  972. MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
  973. MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
  974. MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
  975. MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
  976. {
  977. .vendor = 0,
  978. }
  979. };
  980. MODULE_DEVICE_TABLE(pci, pci_tbl);
  981. static struct saa7146_extension budget_extension = {
  982. .name = "budget_ci dvb\0",
  983. .flags = SAA7146_I2C_SHORT_DELAY,
  984. .module = THIS_MODULE,
  985. .pci_tbl = &pci_tbl[0],
  986. .attach = budget_ci_attach,
  987. .detach = budget_ci_detach,
  988. .irq_mask = MASK_03 | MASK_06 | MASK_10,
  989. .irq_func = budget_ci_irq,
  990. };
  991. static int __init budget_ci_init(void)
  992. {
  993. return saa7146_register_extension(&budget_extension);
  994. }
  995. static void __exit budget_ci_exit(void)
  996. {
  997. saa7146_unregister_extension(&budget_extension);
  998. }
  999. module_init(budget_ci_init);
  1000. module_exit(budget_ci_exit);
  1001. MODULE_LICENSE("GPL");
  1002. MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
  1003. MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
  1004. "budget PCI DVB cards w/ CI-module produced by "
  1005. "Siemens, Technotrend, Hauppauge");