budget-ci.c 35 KB

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