budget-ci.c 33 KB

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