budget-ci.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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 "lnbp21.h"
  44. #include "bsbe1.h"
  45. #include "bsru6.h"
  46. /*
  47. * Regarding DEBIADDR_IR:
  48. * Some CI modules hang if random addresses are read.
  49. * Using address 0x4000 for the IR read means that we
  50. * use the same address as for CI version, which should
  51. * be a safe default.
  52. */
  53. #define DEBIADDR_IR 0x4000
  54. #define DEBIADDR_CICONTROL 0x0000
  55. #define DEBIADDR_CIVERSION 0x4000
  56. #define DEBIADDR_IO 0x1000
  57. #define DEBIADDR_ATTR 0x3000
  58. #define CICONTROL_RESET 0x01
  59. #define CICONTROL_ENABLETS 0x02
  60. #define CICONTROL_CAMDETECT 0x08
  61. #define DEBICICTL 0x00420000
  62. #define DEBICICAM 0x02420000
  63. #define SLOTSTATUS_NONE 1
  64. #define SLOTSTATUS_PRESENT 2
  65. #define SLOTSTATUS_RESET 4
  66. #define SLOTSTATUS_READY 8
  67. #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
  68. /* Milliseconds during which key presses are regarded as key repeat and during
  69. * which the debounce logic is active
  70. */
  71. #define IR_REPEAT_TIMEOUT 350
  72. /* RC5 device wildcard */
  73. #define IR_DEVICE_ANY 255
  74. /* Some remotes sends multiple sequences per keypress (e.g. Zenith sends two),
  75. * this setting allows the superflous sequences to be ignored
  76. */
  77. static int debounce = 0;
  78. module_param(debounce, int, 0644);
  79. MODULE_PARM_DESC(debounce, "ignore repeated IR sequences (default: 0 = ignore no sequences)");
  80. static int rc5_device = -1;
  81. module_param(rc5_device, int, 0644);
  82. MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");
  83. static int ir_debug = 0;
  84. module_param(ir_debug, int, 0644);
  85. MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
  86. struct budget_ci_ir {
  87. struct input_dev *dev;
  88. struct tasklet_struct msp430_irq_tasklet;
  89. char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
  90. char phys[32];
  91. struct ir_input_state state;
  92. int rc5_device;
  93. };
  94. struct budget_ci {
  95. struct budget budget;
  96. struct tasklet_struct ciintf_irq_tasklet;
  97. int slot_status;
  98. int ci_irq;
  99. struct dvb_ca_en50221 ca;
  100. struct budget_ci_ir ir;
  101. u8 tuner_pll_address; /* used for philips_tdm1316l configs */
  102. };
  103. static void msp430_ir_keyup(unsigned long data)
  104. {
  105. struct budget_ci_ir *ir = (struct budget_ci_ir *) data;
  106. ir_input_nokey(ir->dev, &ir->state);
  107. }
  108. static void msp430_ir_interrupt(unsigned long data)
  109. {
  110. struct budget_ci *budget_ci = (struct budget_ci *) data;
  111. struct input_dev *dev = budget_ci->ir.dev;
  112. static int bounces = 0;
  113. int device;
  114. int toggle;
  115. static int prev_toggle = -1;
  116. static u32 ir_key;
  117. u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
  118. /*
  119. * The msp430 chip can generate two different bytes, command and device
  120. *
  121. * type1: X1CCCCCC, C = command bits (0 - 63)
  122. * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit
  123. *
  124. * More than one command byte may be generated before the device byte
  125. * Only when we have both, a correct keypress is generated
  126. */
  127. /* Is this a RC5 command byte? */
  128. if (command & 0x40) {
  129. if (ir_debug)
  130. printk("budget_ci: received command byte 0x%02x\n", command);
  131. ir_key = command & 0x3f;
  132. return;
  133. }
  134. /* It's a RC5 device byte */
  135. if (ir_debug)
  136. printk("budget_ci: received device byte 0x%02x\n", command);
  137. device = command & 0x1f;
  138. toggle = command & 0x20;
  139. if (budget_ci->ir.rc5_device != IR_DEVICE_ANY && budget_ci->ir.rc5_device != device)
  140. return;
  141. /* Ignore repeated key sequences if requested */
  142. if (toggle == prev_toggle && ir_key == dev->repeat_key &&
  143. bounces > 0 && timer_pending(&dev->timer)) {
  144. if (ir_debug)
  145. printk("budget_ci: debounce logic ignored IR command\n");
  146. bounces--;
  147. return;
  148. }
  149. prev_toggle = toggle;
  150. /* Are we still waiting for a keyup event? */
  151. if (del_timer(&dev->timer))
  152. ir_input_nokey(dev, &budget_ci->ir.state);
  153. /* Generate keypress */
  154. if (ir_debug)
  155. printk("budget_ci: generating keypress 0x%02x\n", ir_key);
  156. ir_input_keydown(dev, &budget_ci->ir.state, ir_key, (ir_key & (command << 8)));
  157. /* Do we want to delay the keyup event? */
  158. if (debounce) {
  159. bounces = debounce;
  160. mod_timer(&dev->timer, jiffies + msecs_to_jiffies(IR_REPEAT_TIMEOUT));
  161. } else {
  162. ir_input_nokey(dev, &budget_ci->ir.state);
  163. }
  164. }
  165. static int msp430_ir_init(struct budget_ci *budget_ci)
  166. {
  167. struct saa7146_dev *saa = budget_ci->budget.dev;
  168. struct input_dev *input_dev = budget_ci->ir.dev;
  169. int error;
  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. error = -ENOMEM;
  174. goto out1;
  175. }
  176. snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
  177. "Budget-CI dvb ir receiver %s", saa->name);
  178. snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
  179. "pci-%s/ir0", pci_name(saa->pci));
  180. input_dev->name = budget_ci->ir.name;
  181. input_dev->phys = budget_ci->ir.phys;
  182. input_dev->id.bustype = BUS_PCI;
  183. input_dev->id.version = 1;
  184. if (saa->pci->subsystem_vendor) {
  185. input_dev->id.vendor = saa->pci->subsystem_vendor;
  186. input_dev->id.product = saa->pci->subsystem_device;
  187. } else {
  188. input_dev->id.vendor = saa->pci->vendor;
  189. input_dev->id.product = saa->pci->device;
  190. }
  191. input_dev->cdev.dev = &saa->pci->dev;
  192. /* Select keymap and address */
  193. switch (budget_ci->budget.dev->pci->subsystem_device) {
  194. case 0x100c:
  195. case 0x100f:
  196. case 0x1011:
  197. case 0x1012:
  198. case 0x1017:
  199. /* The hauppauge keymap is a superset of these remotes */
  200. ir_input_init(input_dev, &budget_ci->ir.state,
  201. IR_TYPE_RC5, ir_codes_hauppauge_new);
  202. if (rc5_device < 0)
  203. budget_ci->ir.rc5_device = 0x1f;
  204. else
  205. budget_ci->ir.rc5_device = rc5_device;
  206. break;
  207. case 0x1010:
  208. /* for the Technotrend 1500 bundled remote */
  209. ir_input_init(input_dev, &budget_ci->ir.state,
  210. IR_TYPE_RC5, ir_codes_tt_1500);
  211. if (rc5_device < 0)
  212. budget_ci->ir.rc5_device = IR_DEVICE_ANY;
  213. else
  214. budget_ci->ir.rc5_device = rc5_device;
  215. break;
  216. default:
  217. /* unknown remote */
  218. ir_input_init(input_dev, &budget_ci->ir.state,
  219. IR_TYPE_RC5, ir_codes_budget_ci_old);
  220. if (rc5_device < 0)
  221. budget_ci->ir.rc5_device = IR_DEVICE_ANY;
  222. else
  223. budget_ci->ir.rc5_device = rc5_device;
  224. break;
  225. }
  226. /* initialise the key-up debounce timeout handler */
  227. input_dev->timer.function = msp430_ir_keyup;
  228. input_dev->timer.data = (unsigned long) &budget_ci->ir;
  229. error = input_register_device(input_dev);
  230. if (error) {
  231. printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
  232. goto out2;
  233. }
  234. tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
  235. (unsigned long) budget_ci);
  236. SAA7146_IER_ENABLE(saa, MASK_06);
  237. saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
  238. return 0;
  239. out2:
  240. input_free_device(input_dev);
  241. out1:
  242. return error;
  243. }
  244. static void msp430_ir_deinit(struct budget_ci *budget_ci)
  245. {
  246. struct saa7146_dev *saa = budget_ci->budget.dev;
  247. struct input_dev *dev = budget_ci->ir.dev;
  248. SAA7146_IER_DISABLE(saa, MASK_06);
  249. saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
  250. tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
  251. if (del_timer(&dev->timer)) {
  252. ir_input_nokey(dev, &budget_ci->ir.state);
  253. input_sync(dev);
  254. }
  255. input_unregister_device(dev);
  256. }
  257. static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
  258. {
  259. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  260. if (slot != 0)
  261. return -EINVAL;
  262. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  263. DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
  264. }
  265. static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
  266. {
  267. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  268. if (slot != 0)
  269. return -EINVAL;
  270. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  271. DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
  272. }
  273. static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
  274. {
  275. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  276. if (slot != 0)
  277. return -EINVAL;
  278. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  279. DEBIADDR_IO | (address & 3), 1, 1, 0);
  280. }
  281. static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
  282. {
  283. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  284. if (slot != 0)
  285. return -EINVAL;
  286. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  287. DEBIADDR_IO | (address & 3), 1, value, 1, 0);
  288. }
  289. static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
  290. {
  291. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  292. struct saa7146_dev *saa = budget_ci->budget.dev;
  293. if (slot != 0)
  294. return -EINVAL;
  295. if (budget_ci->ci_irq) {
  296. // trigger on RISING edge during reset so we know when READY is re-asserted
  297. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  298. }
  299. budget_ci->slot_status = SLOTSTATUS_RESET;
  300. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  301. msleep(1);
  302. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  303. CICONTROL_RESET, 1, 0);
  304. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  305. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  306. return 0;
  307. }
  308. static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
  309. {
  310. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  311. struct saa7146_dev *saa = budget_ci->budget.dev;
  312. if (slot != 0)
  313. return -EINVAL;
  314. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  315. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  316. return 0;
  317. }
  318. static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
  319. {
  320. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  321. struct saa7146_dev *saa = budget_ci->budget.dev;
  322. int tmp;
  323. if (slot != 0)
  324. return -EINVAL;
  325. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
  326. tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  327. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  328. tmp | CICONTROL_ENABLETS, 1, 0);
  329. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
  330. return 0;
  331. }
  332. static void ciintf_interrupt(unsigned long data)
  333. {
  334. struct budget_ci *budget_ci = (struct budget_ci *) data;
  335. struct saa7146_dev *saa = budget_ci->budget.dev;
  336. unsigned int flags;
  337. // ensure we don't get spurious IRQs during initialisation
  338. if (!budget_ci->budget.ci_present)
  339. return;
  340. // read the CAM status
  341. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  342. if (flags & CICONTROL_CAMDETECT) {
  343. // GPIO should be set to trigger on falling edge if a CAM is present
  344. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  345. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  346. // CAM insertion IRQ
  347. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  348. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  349. DVB_CA_EN50221_CAMCHANGE_INSERTED);
  350. } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  351. // CAM ready (reset completed)
  352. budget_ci->slot_status = SLOTSTATUS_READY;
  353. dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
  354. } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
  355. // FR/DA IRQ
  356. dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
  357. }
  358. } else {
  359. // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
  360. // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
  361. // the CAM might not actually be ready yet.
  362. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  363. // generate a CAM removal IRQ if we haven't already
  364. if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
  365. // CAM removal IRQ
  366. budget_ci->slot_status = SLOTSTATUS_NONE;
  367. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  368. DVB_CA_EN50221_CAMCHANGE_REMOVED);
  369. }
  370. }
  371. }
  372. static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
  373. {
  374. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  375. unsigned int flags;
  376. // ensure we don't get spurious IRQs during initialisation
  377. if (!budget_ci->budget.ci_present)
  378. return -EINVAL;
  379. // read the CAM status
  380. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  381. if (flags & CICONTROL_CAMDETECT) {
  382. // mark it as present if it wasn't before
  383. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  384. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  385. }
  386. // during a RESET, we check if we can read from IO memory to see when CAM is ready
  387. if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  388. if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
  389. budget_ci->slot_status = SLOTSTATUS_READY;
  390. }
  391. }
  392. } else {
  393. budget_ci->slot_status = SLOTSTATUS_NONE;
  394. }
  395. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  396. if (budget_ci->slot_status & SLOTSTATUS_READY) {
  397. return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
  398. }
  399. return DVB_CA_EN50221_POLL_CAM_PRESENT;
  400. }
  401. return 0;
  402. }
  403. static int ciintf_init(struct budget_ci *budget_ci)
  404. {
  405. struct saa7146_dev *saa = budget_ci->budget.dev;
  406. int flags;
  407. int result;
  408. int ci_version;
  409. int ca_flags;
  410. memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
  411. // enable DEBI pins
  412. saa7146_write(saa, MC1, MASK_27 | MASK_11);
  413. // test if it is there
  414. ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
  415. if ((ci_version & 0xa0) != 0xa0) {
  416. result = -ENODEV;
  417. goto error;
  418. }
  419. // determine whether a CAM is present or not
  420. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  421. budget_ci->slot_status = SLOTSTATUS_NONE;
  422. if (flags & CICONTROL_CAMDETECT)
  423. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  424. // version 0xa2 of the CI firmware doesn't generate interrupts
  425. if (ci_version == 0xa2) {
  426. ca_flags = 0;
  427. budget_ci->ci_irq = 0;
  428. } else {
  429. ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
  430. DVB_CA_EN50221_FLAG_IRQ_FR |
  431. DVB_CA_EN50221_FLAG_IRQ_DA;
  432. budget_ci->ci_irq = 1;
  433. }
  434. // register CI interface
  435. budget_ci->ca.owner = THIS_MODULE;
  436. budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
  437. budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
  438. budget_ci->ca.read_cam_control = ciintf_read_cam_control;
  439. budget_ci->ca.write_cam_control = ciintf_write_cam_control;
  440. budget_ci->ca.slot_reset = ciintf_slot_reset;
  441. budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
  442. budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
  443. budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
  444. budget_ci->ca.data = budget_ci;
  445. if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
  446. &budget_ci->ca,
  447. ca_flags, 1)) != 0) {
  448. printk("budget_ci: CI interface detected, but initialisation failed.\n");
  449. goto error;
  450. }
  451. // Setup CI slot IRQ
  452. if (budget_ci->ci_irq) {
  453. tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
  454. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  455. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  456. } else {
  457. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  458. }
  459. SAA7146_IER_ENABLE(saa, MASK_03);
  460. }
  461. // enable interface
  462. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  463. CICONTROL_RESET, 1, 0);
  464. // success!
  465. printk("budget_ci: CI interface initialised\n");
  466. budget_ci->budget.ci_present = 1;
  467. // forge a fake CI IRQ so the CAM state is setup correctly
  468. if (budget_ci->ci_irq) {
  469. flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
  470. if (budget_ci->slot_status != SLOTSTATUS_NONE)
  471. flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
  472. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
  473. }
  474. return 0;
  475. error:
  476. saa7146_write(saa, MC1, MASK_27);
  477. return result;
  478. }
  479. static void ciintf_deinit(struct budget_ci *budget_ci)
  480. {
  481. struct saa7146_dev *saa = budget_ci->budget.dev;
  482. // disable CI interrupts
  483. if (budget_ci->ci_irq) {
  484. SAA7146_IER_DISABLE(saa, MASK_03);
  485. saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
  486. tasklet_kill(&budget_ci->ciintf_irq_tasklet);
  487. }
  488. // reset interface
  489. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  490. msleep(1);
  491. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  492. CICONTROL_RESET, 1, 0);
  493. // disable TS data stream to CI interface
  494. saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
  495. // release the CA device
  496. dvb_ca_en50221_release(&budget_ci->ca);
  497. // disable DEBI pins
  498. saa7146_write(saa, MC1, MASK_27);
  499. }
  500. static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
  501. {
  502. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  503. dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
  504. if (*isr & MASK_06)
  505. tasklet_schedule(&budget_ci->ir.msp430_irq_tasklet);
  506. if (*isr & MASK_10)
  507. ttpci_budget_irq10_handler(dev, isr);
  508. if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
  509. tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
  510. }
  511. static u8 philips_su1278_tt_inittab[] = {
  512. 0x01, 0x0f,
  513. 0x02, 0x30,
  514. 0x03, 0x00,
  515. 0x04, 0x5b,
  516. 0x05, 0x85,
  517. 0x06, 0x02,
  518. 0x07, 0x00,
  519. 0x08, 0x02,
  520. 0x09, 0x00,
  521. 0x0C, 0x01,
  522. 0x0D, 0x81,
  523. 0x0E, 0x44,
  524. 0x0f, 0x14,
  525. 0x10, 0x3c,
  526. 0x11, 0x84,
  527. 0x12, 0xda,
  528. 0x13, 0x97,
  529. 0x14, 0x95,
  530. 0x15, 0xc9,
  531. 0x16, 0x19,
  532. 0x17, 0x8c,
  533. 0x18, 0x59,
  534. 0x19, 0xf8,
  535. 0x1a, 0xfe,
  536. 0x1c, 0x7f,
  537. 0x1d, 0x00,
  538. 0x1e, 0x00,
  539. 0x1f, 0x50,
  540. 0x20, 0x00,
  541. 0x21, 0x00,
  542. 0x22, 0x00,
  543. 0x23, 0x00,
  544. 0x28, 0x00,
  545. 0x29, 0x28,
  546. 0x2a, 0x14,
  547. 0x2b, 0x0f,
  548. 0x2c, 0x09,
  549. 0x2d, 0x09,
  550. 0x31, 0x1f,
  551. 0x32, 0x19,
  552. 0x33, 0xfc,
  553. 0x34, 0x93,
  554. 0xff, 0xff
  555. };
  556. static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
  557. {
  558. stv0299_writereg(fe, 0x0e, 0x44);
  559. if (srate >= 10000000) {
  560. stv0299_writereg(fe, 0x13, 0x97);
  561. stv0299_writereg(fe, 0x14, 0x95);
  562. stv0299_writereg(fe, 0x15, 0xc9);
  563. stv0299_writereg(fe, 0x17, 0x8c);
  564. stv0299_writereg(fe, 0x1a, 0xfe);
  565. stv0299_writereg(fe, 0x1c, 0x7f);
  566. stv0299_writereg(fe, 0x2d, 0x09);
  567. } else {
  568. stv0299_writereg(fe, 0x13, 0x99);
  569. stv0299_writereg(fe, 0x14, 0x8d);
  570. stv0299_writereg(fe, 0x15, 0xce);
  571. stv0299_writereg(fe, 0x17, 0x43);
  572. stv0299_writereg(fe, 0x1a, 0x1d);
  573. stv0299_writereg(fe, 0x1c, 0x12);
  574. stv0299_writereg(fe, 0x2d, 0x05);
  575. }
  576. stv0299_writereg(fe, 0x0e, 0x23);
  577. stv0299_writereg(fe, 0x0f, 0x94);
  578. stv0299_writereg(fe, 0x10, 0x39);
  579. stv0299_writereg(fe, 0x15, 0xc9);
  580. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  581. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  582. stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
  583. return 0;
  584. }
  585. static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe,
  586. struct dvb_frontend_parameters *params)
  587. {
  588. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  589. u32 div;
  590. u8 buf[4];
  591. struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
  592. if ((params->frequency < 950000) || (params->frequency > 2150000))
  593. return -EINVAL;
  594. div = (params->frequency + (500 - 1)) / 500; // round correctly
  595. buf[0] = (div >> 8) & 0x7f;
  596. buf[1] = div & 0xff;
  597. buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
  598. buf[3] = 0x20;
  599. if (params->u.qpsk.symbol_rate < 4000000)
  600. buf[3] |= 1;
  601. if (params->frequency < 1250000)
  602. buf[3] |= 0;
  603. else if (params->frequency < 1550000)
  604. buf[3] |= 0x40;
  605. else if (params->frequency < 2050000)
  606. buf[3] |= 0x80;
  607. else if (params->frequency < 2150000)
  608. buf[3] |= 0xC0;
  609. if (fe->ops.i2c_gate_ctrl)
  610. fe->ops.i2c_gate_ctrl(fe, 1);
  611. if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
  612. return -EIO;
  613. return 0;
  614. }
  615. static struct stv0299_config philips_su1278_tt_config = {
  616. .demod_address = 0x68,
  617. .inittab = philips_su1278_tt_inittab,
  618. .mclk = 64000000UL,
  619. .invert = 0,
  620. .skip_reinit = 1,
  621. .lock_output = STV0229_LOCKOUTPUT_1,
  622. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  623. .min_delay_ms = 50,
  624. .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
  625. };
  626. static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
  627. {
  628. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  629. static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  630. static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
  631. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
  632. sizeof(td1316_init) };
  633. // setup PLL configuration
  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. return -EIO;
  638. msleep(1);
  639. // disable the mc44BC374c (do not check for errors)
  640. tuner_msg.addr = 0x65;
  641. tuner_msg.buf = disable_mc44BC374c;
  642. tuner_msg.len = sizeof(disable_mc44BC374c);
  643. if (fe->ops.i2c_gate_ctrl)
  644. fe->ops.i2c_gate_ctrl(fe, 1);
  645. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
  646. if (fe->ops.i2c_gate_ctrl)
  647. fe->ops.i2c_gate_ctrl(fe, 1);
  648. i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
  649. }
  650. return 0;
  651. }
  652. static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
  653. {
  654. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  655. u8 tuner_buf[4];
  656. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
  657. int tuner_frequency = 0;
  658. u8 band, cp, filter;
  659. // determine charge pump
  660. tuner_frequency = params->frequency + 36130000;
  661. if (tuner_frequency < 87000000)
  662. return -EINVAL;
  663. else if (tuner_frequency < 130000000)
  664. cp = 3;
  665. else if (tuner_frequency < 160000000)
  666. cp = 5;
  667. else if (tuner_frequency < 200000000)
  668. cp = 6;
  669. else if (tuner_frequency < 290000000)
  670. cp = 3;
  671. else if (tuner_frequency < 420000000)
  672. cp = 5;
  673. else if (tuner_frequency < 480000000)
  674. cp = 6;
  675. else if (tuner_frequency < 620000000)
  676. cp = 3;
  677. else if (tuner_frequency < 830000000)
  678. cp = 5;
  679. else if (tuner_frequency < 895000000)
  680. cp = 7;
  681. else
  682. return -EINVAL;
  683. // determine band
  684. if (params->frequency < 49000000)
  685. return -EINVAL;
  686. else if (params->frequency < 159000000)
  687. band = 1;
  688. else if (params->frequency < 444000000)
  689. band = 2;
  690. else if (params->frequency < 861000000)
  691. band = 4;
  692. else
  693. return -EINVAL;
  694. // setup PLL filter and TDA9889
  695. switch (params->u.ofdm.bandwidth) {
  696. case BANDWIDTH_6_MHZ:
  697. tda1004x_writereg(fe, 0x0C, 0x14);
  698. filter = 0;
  699. break;
  700. case BANDWIDTH_7_MHZ:
  701. tda1004x_writereg(fe, 0x0C, 0x80);
  702. filter = 0;
  703. break;
  704. case BANDWIDTH_8_MHZ:
  705. tda1004x_writereg(fe, 0x0C, 0x14);
  706. filter = 1;
  707. break;
  708. default:
  709. return -EINVAL;
  710. }
  711. // calculate divisor
  712. // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
  713. tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
  714. // setup tuner buffer
  715. tuner_buf[0] = tuner_frequency >> 8;
  716. tuner_buf[1] = tuner_frequency & 0xff;
  717. tuner_buf[2] = 0xca;
  718. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  719. if (fe->ops.i2c_gate_ctrl)
  720. fe->ops.i2c_gate_ctrl(fe, 1);
  721. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  722. return -EIO;
  723. msleep(1);
  724. return 0;
  725. }
  726. static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
  727. const struct firmware **fw, char *name)
  728. {
  729. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  730. return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
  731. }
  732. static struct tda1004x_config philips_tdm1316l_config = {
  733. .demod_address = 0x8,
  734. .invert = 0,
  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 = 2;
  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 void frontend_init(struct budget_ci *budget_ci)
  905. {
  906. switch (budget_ci->budget.dev->pci->subsystem_device) {
  907. case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
  908. budget_ci->budget.dvb_frontend =
  909. dvb_attach(stv0299_attach, &alps_bsru6_config, &budget_ci->budget.i2c_adap);
  910. if (budget_ci->budget.dvb_frontend) {
  911. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
  912. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  913. break;
  914. }
  915. break;
  916. case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
  917. budget_ci->budget.dvb_frontend =
  918. dvb_attach(stv0299_attach, &philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
  919. if (budget_ci->budget.dvb_frontend) {
  920. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
  921. break;
  922. }
  923. break;
  924. case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
  925. budget_ci->tuner_pll_address = 0x61;
  926. budget_ci->budget.dvb_frontend =
  927. dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  928. if (budget_ci->budget.dvb_frontend) {
  929. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
  930. break;
  931. }
  932. break;
  933. case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
  934. budget_ci->tuner_pll_address = 0x63;
  935. budget_ci->budget.dvb_frontend =
  936. dvb_attach(tda10045_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  937. if (budget_ci->budget.dvb_frontend) {
  938. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  939. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  940. break;
  941. }
  942. break;
  943. case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
  944. budget_ci->tuner_pll_address = 0x60;
  945. philips_tdm1316l_config.invert = 1;
  946. budget_ci->budget.dvb_frontend =
  947. dvb_attach(tda10046_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  948. if (budget_ci->budget.dvb_frontend) {
  949. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  950. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  951. break;
  952. }
  953. break;
  954. case 0x1017: // TT S-1500 PCI
  955. budget_ci->budget.dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config, &budget_ci->budget.i2c_adap);
  956. if (budget_ci->budget.dvb_frontend) {
  957. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
  958. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  959. budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
  960. if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
  961. printk("%s: No LNBP21 found!\n", __FUNCTION__);
  962. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  963. budget_ci->budget.dvb_frontend = NULL;
  964. }
  965. }
  966. break;
  967. }
  968. if (budget_ci->budget.dvb_frontend == NULL) {
  969. printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
  970. budget_ci->budget.dev->pci->vendor,
  971. budget_ci->budget.dev->pci->device,
  972. budget_ci->budget.dev->pci->subsystem_vendor,
  973. budget_ci->budget.dev->pci->subsystem_device);
  974. } else {
  975. if (dvb_register_frontend
  976. (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
  977. printk("budget-ci: Frontend registration failed!\n");
  978. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  979. budget_ci->budget.dvb_frontend = NULL;
  980. }
  981. }
  982. }
  983. static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
  984. {
  985. struct budget_ci *budget_ci;
  986. int err;
  987. budget_ci = kzalloc(sizeof(struct budget_ci), GFP_KERNEL);
  988. if (!budget_ci) {
  989. err = -ENOMEM;
  990. goto out1;
  991. }
  992. dprintk(2, "budget_ci: %p\n", budget_ci);
  993. dev->ext_priv = budget_ci;
  994. err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE);
  995. if (err)
  996. goto out2;
  997. err = msp430_ir_init(budget_ci);
  998. if (err)
  999. goto out3;
  1000. ciintf_init(budget_ci);
  1001. budget_ci->budget.dvb_adapter.priv = budget_ci;
  1002. frontend_init(budget_ci);
  1003. ttpci_budget_init_hooks(&budget_ci->budget);
  1004. return 0;
  1005. out3:
  1006. ttpci_budget_deinit(&budget_ci->budget);
  1007. out2:
  1008. kfree(budget_ci);
  1009. out1:
  1010. return err;
  1011. }
  1012. static int budget_ci_detach(struct saa7146_dev *dev)
  1013. {
  1014. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  1015. struct saa7146_dev *saa = budget_ci->budget.dev;
  1016. int err;
  1017. if (budget_ci->budget.ci_present)
  1018. ciintf_deinit(budget_ci);
  1019. msp430_ir_deinit(budget_ci);
  1020. if (budget_ci->budget.dvb_frontend) {
  1021. dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
  1022. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1023. }
  1024. err = ttpci_budget_deinit(&budget_ci->budget);
  1025. // disable frontend and CI interface
  1026. saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
  1027. kfree(budget_ci);
  1028. return err;
  1029. }
  1030. static struct saa7146_extension budget_extension;
  1031. MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
  1032. MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
  1033. MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
  1034. MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
  1035. MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
  1036. static struct pci_device_id pci_tbl[] = {
  1037. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
  1038. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
  1039. MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
  1040. MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
  1041. MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
  1042. MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
  1043. {
  1044. .vendor = 0,
  1045. }
  1046. };
  1047. MODULE_DEVICE_TABLE(pci, pci_tbl);
  1048. static struct saa7146_extension budget_extension = {
  1049. .name = "budget_ci dvb",
  1050. .flags = SAA7146_USE_I2C_IRQ,
  1051. .module = THIS_MODULE,
  1052. .pci_tbl = &pci_tbl[0],
  1053. .attach = budget_ci_attach,
  1054. .detach = budget_ci_detach,
  1055. .irq_mask = MASK_03 | MASK_06 | MASK_10,
  1056. .irq_func = budget_ci_irq,
  1057. };
  1058. static int __init budget_ci_init(void)
  1059. {
  1060. return saa7146_register_extension(&budget_extension);
  1061. }
  1062. static void __exit budget_ci_exit(void)
  1063. {
  1064. saa7146_unregister_extension(&budget_extension);
  1065. }
  1066. module_init(budget_ci_init);
  1067. module_exit(budget_ci_exit);
  1068. MODULE_LICENSE("GPL");
  1069. MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
  1070. MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
  1071. "budget PCI DVB cards w/ CI-module produced by "
  1072. "Siemens, Technotrend, Hauppauge");