budget-ci.c 35 KB

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