budget-ci.c 35 KB

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