budget-ci.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  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 https://linuxtv.org
  30. */
  31. #include <linux/module.h>
  32. #include <linux/errno.h>
  33. #include <linux/slab.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/spinlock.h>
  36. #include <media/rc-core.h>
  37. #include "budget.h"
  38. #include "dvb_ca_en50221.h"
  39. #include "stv0299.h"
  40. #include "stv0297.h"
  41. #include "tda1004x.h"
  42. #include "stb0899_drv.h"
  43. #include "stb0899_reg.h"
  44. #include "stb0899_cfg.h"
  45. #include "stb6100.h"
  46. #include "stb6100_cfg.h"
  47. #include "lnbp21.h"
  48. #include "bsbe1.h"
  49. #include "bsru6.h"
  50. #include "tda1002x.h"
  51. #include "tda827x.h"
  52. #include "bsbe1-d01a.h"
  53. #define MODULE_NAME "budget_ci"
  54. /*
  55. * Regarding DEBIADDR_IR:
  56. * Some CI modules hang if random addresses are read.
  57. * Using address 0x4000 for the IR read means that we
  58. * use the same address as for CI version, which should
  59. * be a safe default.
  60. */
  61. #define DEBIADDR_IR 0x4000
  62. #define DEBIADDR_CICONTROL 0x0000
  63. #define DEBIADDR_CIVERSION 0x4000
  64. #define DEBIADDR_IO 0x1000
  65. #define DEBIADDR_ATTR 0x3000
  66. #define CICONTROL_RESET 0x01
  67. #define CICONTROL_ENABLETS 0x02
  68. #define CICONTROL_CAMDETECT 0x08
  69. #define DEBICICTL 0x00420000
  70. #define DEBICICAM 0x02420000
  71. #define SLOTSTATUS_NONE 1
  72. #define SLOTSTATUS_PRESENT 2
  73. #define SLOTSTATUS_RESET 4
  74. #define SLOTSTATUS_READY 8
  75. #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
  76. /* RC5 device wildcard */
  77. #define IR_DEVICE_ANY 255
  78. static int rc5_device = -1;
  79. module_param(rc5_device, int, 0644);
  80. MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");
  81. static int ir_debug;
  82. module_param(ir_debug, int, 0644);
  83. MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
  84. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  85. struct budget_ci_ir {
  86. struct rc_dev *dev;
  87. struct tasklet_struct msp430_irq_tasklet;
  88. char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
  89. char phys[32];
  90. int rc5_device;
  91. u32 ir_key;
  92. bool have_command;
  93. bool full_rc5; /* Outputs a full RC5 code */
  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_interrupt(unsigned long data)
  105. {
  106. struct budget_ci *budget_ci = (struct budget_ci *) data;
  107. struct rc_dev *dev = budget_ci->ir.dev;
  108. u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
  109. /*
  110. * The msp430 chip can generate two different bytes, command and device
  111. *
  112. * type1: X1CCCCCC, C = command bits (0 - 63)
  113. * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit
  114. *
  115. * Each signal from the remote control can generate one or more command
  116. * bytes and one or more device bytes. For the repeated bytes, the
  117. * highest bit (X) is set. The first command byte is always generated
  118. * before the first device byte. Other than that, no specific order
  119. * seems to apply. To make life interesting, bytes can also be lost.
  120. *
  121. * Only when we have a command and device byte, a keypress is
  122. * generated.
  123. */
  124. if (ir_debug)
  125. printk("budget_ci: received byte 0x%02x\n", command);
  126. /* Remove repeat bit, we use every command */
  127. command = command & 0x7f;
  128. /* Is this a RC5 command byte? */
  129. if (command & 0x40) {
  130. budget_ci->ir.have_command = true;
  131. budget_ci->ir.ir_key = command & 0x3f;
  132. return;
  133. }
  134. /* It's a RC5 device byte */
  135. if (!budget_ci->ir.have_command)
  136. return;
  137. budget_ci->ir.have_command = false;
  138. if (budget_ci->ir.rc5_device != IR_DEVICE_ANY &&
  139. budget_ci->ir.rc5_device != (command & 0x1f))
  140. return;
  141. if (budget_ci->ir.full_rc5) {
  142. rc_keydown(dev, RC_TYPE_RC5,
  143. RC_SCANCODE_RC5(budget_ci->ir.rc5_device, budget_ci->ir.ir_key),
  144. !!(command & 0x20));
  145. return;
  146. }
  147. /* FIXME: We should generate complete scancodes for all devices */
  148. rc_keydown(dev, RC_TYPE_UNKNOWN, budget_ci->ir.ir_key, !!(command & 0x20));
  149. }
  150. static int msp430_ir_init(struct budget_ci *budget_ci)
  151. {
  152. struct saa7146_dev *saa = budget_ci->budget.dev;
  153. struct rc_dev *dev;
  154. int error;
  155. dev = rc_allocate_device();
  156. if (!dev) {
  157. printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
  158. return -ENOMEM;
  159. }
  160. snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
  161. "Budget-CI dvb ir receiver %s", saa->name);
  162. snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
  163. "pci-%s/ir0", pci_name(saa->pci));
  164. dev->driver_name = MODULE_NAME;
  165. dev->input_name = budget_ci->ir.name;
  166. dev->input_phys = budget_ci->ir.phys;
  167. dev->input_id.bustype = BUS_PCI;
  168. dev->input_id.version = 1;
  169. if (saa->pci->subsystem_vendor) {
  170. dev->input_id.vendor = saa->pci->subsystem_vendor;
  171. dev->input_id.product = saa->pci->subsystem_device;
  172. } else {
  173. dev->input_id.vendor = saa->pci->vendor;
  174. dev->input_id.product = saa->pci->device;
  175. }
  176. dev->dev.parent = &saa->pci->dev;
  177. if (rc5_device < 0)
  178. budget_ci->ir.rc5_device = IR_DEVICE_ANY;
  179. else
  180. budget_ci->ir.rc5_device = rc5_device;
  181. /* Select keymap and address */
  182. switch (budget_ci->budget.dev->pci->subsystem_device) {
  183. case 0x100c:
  184. case 0x100f:
  185. case 0x1011:
  186. case 0x1012:
  187. /* The hauppauge keymap is a superset of these remotes */
  188. dev->map_name = RC_MAP_HAUPPAUGE;
  189. budget_ci->ir.full_rc5 = true;
  190. if (rc5_device < 0)
  191. budget_ci->ir.rc5_device = 0x1f;
  192. break;
  193. case 0x1010:
  194. case 0x1017:
  195. case 0x1019:
  196. case 0x101a:
  197. case 0x101b:
  198. /* for the Technotrend 1500 bundled remote */
  199. dev->map_name = RC_MAP_TT_1500;
  200. break;
  201. default:
  202. /* unknown remote */
  203. dev->map_name = RC_MAP_BUDGET_CI_OLD;
  204. break;
  205. }
  206. if (!budget_ci->ir.full_rc5)
  207. dev->scancode_mask = 0xff;
  208. error = rc_register_device(dev);
  209. if (error) {
  210. printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
  211. rc_free_device(dev);
  212. return error;
  213. }
  214. budget_ci->ir.dev = dev;
  215. tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
  216. (unsigned long) budget_ci);
  217. SAA7146_IER_ENABLE(saa, MASK_06);
  218. saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
  219. return 0;
  220. }
  221. static void msp430_ir_deinit(struct budget_ci *budget_ci)
  222. {
  223. struct saa7146_dev *saa = budget_ci->budget.dev;
  224. SAA7146_IER_DISABLE(saa, MASK_06);
  225. saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
  226. tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
  227. rc_unregister_device(budget_ci->ir.dev);
  228. }
  229. static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
  230. {
  231. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  232. if (slot != 0)
  233. return -EINVAL;
  234. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  235. DEBIADDR_ATTR | (address & 0xfff), 1, 1, 0);
  236. }
  237. static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value)
  238. {
  239. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  240. if (slot != 0)
  241. return -EINVAL;
  242. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  243. DEBIADDR_ATTR | (address & 0xfff), 1, value, 1, 0);
  244. }
  245. static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address)
  246. {
  247. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  248. if (slot != 0)
  249. return -EINVAL;
  250. return ttpci_budget_debiread(&budget_ci->budget, DEBICICAM,
  251. DEBIADDR_IO | (address & 3), 1, 1, 0);
  252. }
  253. static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value)
  254. {
  255. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  256. if (slot != 0)
  257. return -EINVAL;
  258. return ttpci_budget_debiwrite(&budget_ci->budget, DEBICICAM,
  259. DEBIADDR_IO | (address & 3), 1, value, 1, 0);
  260. }
  261. static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
  262. {
  263. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  264. struct saa7146_dev *saa = budget_ci->budget.dev;
  265. if (slot != 0)
  266. return -EINVAL;
  267. if (budget_ci->ci_irq) {
  268. // trigger on RISING edge during reset so we know when READY is re-asserted
  269. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  270. }
  271. budget_ci->slot_status = SLOTSTATUS_RESET;
  272. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  273. msleep(1);
  274. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  275. CICONTROL_RESET, 1, 0);
  276. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  277. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  278. return 0;
  279. }
  280. static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
  281. {
  282. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  283. struct saa7146_dev *saa = budget_ci->budget.dev;
  284. if (slot != 0)
  285. return -EINVAL;
  286. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI);
  287. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB);
  288. return 0;
  289. }
  290. static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
  291. {
  292. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  293. struct saa7146_dev *saa = budget_ci->budget.dev;
  294. int tmp;
  295. if (slot != 0)
  296. return -EINVAL;
  297. saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO);
  298. tmp = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  299. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  300. tmp | CICONTROL_ENABLETS, 1, 0);
  301. ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA);
  302. return 0;
  303. }
  304. static void ciintf_interrupt(unsigned long data)
  305. {
  306. struct budget_ci *budget_ci = (struct budget_ci *) data;
  307. struct saa7146_dev *saa = budget_ci->budget.dev;
  308. unsigned int flags;
  309. // ensure we don't get spurious IRQs during initialisation
  310. if (!budget_ci->budget.ci_present)
  311. return;
  312. // read the CAM status
  313. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  314. if (flags & CICONTROL_CAMDETECT) {
  315. // GPIO should be set to trigger on falling edge if a CAM is present
  316. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  317. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  318. // CAM insertion IRQ
  319. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  320. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  321. DVB_CA_EN50221_CAMCHANGE_INSERTED);
  322. } else if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  323. // CAM ready (reset completed)
  324. budget_ci->slot_status = SLOTSTATUS_READY;
  325. dvb_ca_en50221_camready_irq(&budget_ci->ca, 0);
  326. } else if (budget_ci->slot_status & SLOTSTATUS_READY) {
  327. // FR/DA IRQ
  328. dvb_ca_en50221_frda_irq(&budget_ci->ca, 0);
  329. }
  330. } else {
  331. // trigger on rising edge if a CAM is not present - when a CAM is inserted, we
  332. // only want to get the IRQ when it sets READY. If we trigger on the falling edge,
  333. // the CAM might not actually be ready yet.
  334. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  335. // generate a CAM removal IRQ if we haven't already
  336. if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) {
  337. // CAM removal IRQ
  338. budget_ci->slot_status = SLOTSTATUS_NONE;
  339. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0,
  340. DVB_CA_EN50221_CAMCHANGE_REMOVED);
  341. }
  342. }
  343. }
  344. static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
  345. {
  346. struct budget_ci *budget_ci = (struct budget_ci *) ca->data;
  347. unsigned int flags;
  348. // ensure we don't get spurious IRQs during initialisation
  349. if (!budget_ci->budget.ci_present)
  350. return -EINVAL;
  351. // read the CAM status
  352. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  353. if (flags & CICONTROL_CAMDETECT) {
  354. // mark it as present if it wasn't before
  355. if (budget_ci->slot_status & SLOTSTATUS_NONE) {
  356. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  357. }
  358. // during a RESET, we check if we can read from IO memory to see when CAM is ready
  359. if (budget_ci->slot_status & SLOTSTATUS_RESET) {
  360. if (ciintf_read_attribute_mem(ca, slot, 0) == 0x1d) {
  361. budget_ci->slot_status = SLOTSTATUS_READY;
  362. }
  363. }
  364. } else {
  365. budget_ci->slot_status = SLOTSTATUS_NONE;
  366. }
  367. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  368. if (budget_ci->slot_status & SLOTSTATUS_READY) {
  369. return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY;
  370. }
  371. return DVB_CA_EN50221_POLL_CAM_PRESENT;
  372. }
  373. return 0;
  374. }
  375. static int ciintf_init(struct budget_ci *budget_ci)
  376. {
  377. struct saa7146_dev *saa = budget_ci->budget.dev;
  378. int flags;
  379. int result;
  380. int ci_version;
  381. int ca_flags;
  382. memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
  383. // enable DEBI pins
  384. saa7146_write(saa, MC1, MASK_27 | MASK_11);
  385. // test if it is there
  386. ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
  387. if ((ci_version & 0xa0) != 0xa0) {
  388. result = -ENODEV;
  389. goto error;
  390. }
  391. // determine whether a CAM is present or not
  392. flags = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 1, 0);
  393. budget_ci->slot_status = SLOTSTATUS_NONE;
  394. if (flags & CICONTROL_CAMDETECT)
  395. budget_ci->slot_status = SLOTSTATUS_PRESENT;
  396. // version 0xa2 of the CI firmware doesn't generate interrupts
  397. if (ci_version == 0xa2) {
  398. ca_flags = 0;
  399. budget_ci->ci_irq = 0;
  400. } else {
  401. ca_flags = DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE |
  402. DVB_CA_EN50221_FLAG_IRQ_FR |
  403. DVB_CA_EN50221_FLAG_IRQ_DA;
  404. budget_ci->ci_irq = 1;
  405. }
  406. // register CI interface
  407. budget_ci->ca.owner = THIS_MODULE;
  408. budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem;
  409. budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem;
  410. budget_ci->ca.read_cam_control = ciintf_read_cam_control;
  411. budget_ci->ca.write_cam_control = ciintf_write_cam_control;
  412. budget_ci->ca.slot_reset = ciintf_slot_reset;
  413. budget_ci->ca.slot_shutdown = ciintf_slot_shutdown;
  414. budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable;
  415. budget_ci->ca.poll_slot_status = ciintf_poll_slot_status;
  416. budget_ci->ca.data = budget_ci;
  417. if ((result = dvb_ca_en50221_init(&budget_ci->budget.dvb_adapter,
  418. &budget_ci->ca,
  419. ca_flags, 1)) != 0) {
  420. printk("budget_ci: CI interface detected, but initialisation failed.\n");
  421. goto error;
  422. }
  423. // Setup CI slot IRQ
  424. if (budget_ci->ci_irq) {
  425. tasklet_init(&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci);
  426. if (budget_ci->slot_status != SLOTSTATUS_NONE) {
  427. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO);
  428. } else {
  429. saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
  430. }
  431. SAA7146_IER_ENABLE(saa, MASK_03);
  432. }
  433. // enable interface
  434. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  435. CICONTROL_RESET, 1, 0);
  436. // success!
  437. printk("budget_ci: CI interface initialised\n");
  438. budget_ci->budget.ci_present = 1;
  439. // forge a fake CI IRQ so the CAM state is setup correctly
  440. if (budget_ci->ci_irq) {
  441. flags = DVB_CA_EN50221_CAMCHANGE_REMOVED;
  442. if (budget_ci->slot_status != SLOTSTATUS_NONE)
  443. flags = DVB_CA_EN50221_CAMCHANGE_INSERTED;
  444. dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags);
  445. }
  446. return 0;
  447. error:
  448. saa7146_write(saa, MC1, MASK_27);
  449. return result;
  450. }
  451. static void ciintf_deinit(struct budget_ci *budget_ci)
  452. {
  453. struct saa7146_dev *saa = budget_ci->budget.dev;
  454. // disable CI interrupts
  455. if (budget_ci->ci_irq) {
  456. SAA7146_IER_DISABLE(saa, MASK_03);
  457. saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
  458. tasklet_kill(&budget_ci->ciintf_irq_tasklet);
  459. }
  460. // reset interface
  461. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0, 1, 0);
  462. msleep(1);
  463. ttpci_budget_debiwrite(&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1,
  464. CICONTROL_RESET, 1, 0);
  465. // disable TS data stream to CI interface
  466. saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT);
  467. // release the CA device
  468. dvb_ca_en50221_release(&budget_ci->ca);
  469. // disable DEBI pins
  470. saa7146_write(saa, MC1, MASK_27);
  471. }
  472. static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
  473. {
  474. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  475. dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
  476. if (*isr & MASK_06)
  477. tasklet_schedule(&budget_ci->ir.msp430_irq_tasklet);
  478. if (*isr & MASK_10)
  479. ttpci_budget_irq10_handler(dev, isr);
  480. if ((*isr & MASK_03) && (budget_ci->budget.ci_present) && (budget_ci->ci_irq))
  481. tasklet_schedule(&budget_ci->ciintf_irq_tasklet);
  482. }
  483. static u8 philips_su1278_tt_inittab[] = {
  484. 0x01, 0x0f,
  485. 0x02, 0x30,
  486. 0x03, 0x00,
  487. 0x04, 0x5b,
  488. 0x05, 0x85,
  489. 0x06, 0x02,
  490. 0x07, 0x00,
  491. 0x08, 0x02,
  492. 0x09, 0x00,
  493. 0x0C, 0x01,
  494. 0x0D, 0x81,
  495. 0x0E, 0x44,
  496. 0x0f, 0x14,
  497. 0x10, 0x3c,
  498. 0x11, 0x84,
  499. 0x12, 0xda,
  500. 0x13, 0x97,
  501. 0x14, 0x95,
  502. 0x15, 0xc9,
  503. 0x16, 0x19,
  504. 0x17, 0x8c,
  505. 0x18, 0x59,
  506. 0x19, 0xf8,
  507. 0x1a, 0xfe,
  508. 0x1c, 0x7f,
  509. 0x1d, 0x00,
  510. 0x1e, 0x00,
  511. 0x1f, 0x50,
  512. 0x20, 0x00,
  513. 0x21, 0x00,
  514. 0x22, 0x00,
  515. 0x23, 0x00,
  516. 0x28, 0x00,
  517. 0x29, 0x28,
  518. 0x2a, 0x14,
  519. 0x2b, 0x0f,
  520. 0x2c, 0x09,
  521. 0x2d, 0x09,
  522. 0x31, 0x1f,
  523. 0x32, 0x19,
  524. 0x33, 0xfc,
  525. 0x34, 0x93,
  526. 0xff, 0xff
  527. };
  528. static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, u32 ratio)
  529. {
  530. stv0299_writereg(fe, 0x0e, 0x44);
  531. if (srate >= 10000000) {
  532. stv0299_writereg(fe, 0x13, 0x97);
  533. stv0299_writereg(fe, 0x14, 0x95);
  534. stv0299_writereg(fe, 0x15, 0xc9);
  535. stv0299_writereg(fe, 0x17, 0x8c);
  536. stv0299_writereg(fe, 0x1a, 0xfe);
  537. stv0299_writereg(fe, 0x1c, 0x7f);
  538. stv0299_writereg(fe, 0x2d, 0x09);
  539. } else {
  540. stv0299_writereg(fe, 0x13, 0x99);
  541. stv0299_writereg(fe, 0x14, 0x8d);
  542. stv0299_writereg(fe, 0x15, 0xce);
  543. stv0299_writereg(fe, 0x17, 0x43);
  544. stv0299_writereg(fe, 0x1a, 0x1d);
  545. stv0299_writereg(fe, 0x1c, 0x12);
  546. stv0299_writereg(fe, 0x2d, 0x05);
  547. }
  548. stv0299_writereg(fe, 0x0e, 0x23);
  549. stv0299_writereg(fe, 0x0f, 0x94);
  550. stv0299_writereg(fe, 0x10, 0x39);
  551. stv0299_writereg(fe, 0x15, 0xc9);
  552. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  553. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  554. stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
  555. return 0;
  556. }
  557. static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe)
  558. {
  559. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  560. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  561. u32 div;
  562. u8 buf[4];
  563. struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
  564. if ((p->frequency < 950000) || (p->frequency > 2150000))
  565. return -EINVAL;
  566. div = (p->frequency + (500 - 1)) / 500; /* round correctly */
  567. buf[0] = (div >> 8) & 0x7f;
  568. buf[1] = div & 0xff;
  569. buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2;
  570. buf[3] = 0x20;
  571. if (p->symbol_rate < 4000000)
  572. buf[3] |= 1;
  573. if (p->frequency < 1250000)
  574. buf[3] |= 0;
  575. else if (p->frequency < 1550000)
  576. buf[3] |= 0x40;
  577. else if (p->frequency < 2050000)
  578. buf[3] |= 0x80;
  579. else if (p->frequency < 2150000)
  580. buf[3] |= 0xC0;
  581. if (fe->ops.i2c_gate_ctrl)
  582. fe->ops.i2c_gate_ctrl(fe, 1);
  583. if (i2c_transfer(&budget_ci->budget.i2c_adap, &msg, 1) != 1)
  584. return -EIO;
  585. return 0;
  586. }
  587. static struct stv0299_config philips_su1278_tt_config = {
  588. .demod_address = 0x68,
  589. .inittab = philips_su1278_tt_inittab,
  590. .mclk = 64000000UL,
  591. .invert = 0,
  592. .skip_reinit = 1,
  593. .lock_output = STV0299_LOCKOUTPUT_1,
  594. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  595. .min_delay_ms = 50,
  596. .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
  597. };
  598. static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe)
  599. {
  600. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  601. static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
  602. static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
  603. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len =
  604. sizeof(td1316_init) };
  605. // setup PLL configuration
  606. if (fe->ops.i2c_gate_ctrl)
  607. fe->ops.i2c_gate_ctrl(fe, 1);
  608. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  609. return -EIO;
  610. msleep(1);
  611. // disable the mc44BC374c (do not check for errors)
  612. tuner_msg.addr = 0x65;
  613. tuner_msg.buf = disable_mc44BC374c;
  614. tuner_msg.len = sizeof(disable_mc44BC374c);
  615. if (fe->ops.i2c_gate_ctrl)
  616. fe->ops.i2c_gate_ctrl(fe, 1);
  617. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) {
  618. if (fe->ops.i2c_gate_ctrl)
  619. fe->ops.i2c_gate_ctrl(fe, 1);
  620. i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1);
  621. }
  622. return 0;
  623. }
  624. static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe)
  625. {
  626. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  627. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  628. u8 tuner_buf[4];
  629. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) };
  630. int tuner_frequency = 0;
  631. u8 band, cp, filter;
  632. // determine charge pump
  633. tuner_frequency = p->frequency + 36130000;
  634. if (tuner_frequency < 87000000)
  635. return -EINVAL;
  636. else if (tuner_frequency < 130000000)
  637. cp = 3;
  638. else if (tuner_frequency < 160000000)
  639. cp = 5;
  640. else if (tuner_frequency < 200000000)
  641. cp = 6;
  642. else if (tuner_frequency < 290000000)
  643. cp = 3;
  644. else if (tuner_frequency < 420000000)
  645. cp = 5;
  646. else if (tuner_frequency < 480000000)
  647. cp = 6;
  648. else if (tuner_frequency < 620000000)
  649. cp = 3;
  650. else if (tuner_frequency < 830000000)
  651. cp = 5;
  652. else if (tuner_frequency < 895000000)
  653. cp = 7;
  654. else
  655. return -EINVAL;
  656. // determine band
  657. if (p->frequency < 49000000)
  658. return -EINVAL;
  659. else if (p->frequency < 159000000)
  660. band = 1;
  661. else if (p->frequency < 444000000)
  662. band = 2;
  663. else if (p->frequency < 861000000)
  664. band = 4;
  665. else
  666. return -EINVAL;
  667. // setup PLL filter and TDA9889
  668. switch (p->bandwidth_hz) {
  669. case 6000000:
  670. tda1004x_writereg(fe, 0x0C, 0x14);
  671. filter = 0;
  672. break;
  673. case 7000000:
  674. tda1004x_writereg(fe, 0x0C, 0x80);
  675. filter = 0;
  676. break;
  677. case 8000000:
  678. tda1004x_writereg(fe, 0x0C, 0x14);
  679. filter = 1;
  680. break;
  681. default:
  682. return -EINVAL;
  683. }
  684. // calculate divisor
  685. // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
  686. tuner_frequency = (((p->frequency / 1000) * 6) + 217280) / 1000;
  687. // setup tuner buffer
  688. tuner_buf[0] = tuner_frequency >> 8;
  689. tuner_buf[1] = tuner_frequency & 0xff;
  690. tuner_buf[2] = 0xca;
  691. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  692. if (fe->ops.i2c_gate_ctrl)
  693. fe->ops.i2c_gate_ctrl(fe, 1);
  694. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  695. return -EIO;
  696. msleep(1);
  697. return 0;
  698. }
  699. static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe,
  700. const struct firmware **fw, char *name)
  701. {
  702. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  703. return reject_firmware(fw, name, &budget_ci->budget.dev->pci->dev);
  704. }
  705. static struct tda1004x_config philips_tdm1316l_config = {
  706. .demod_address = 0x8,
  707. .invert = 0,
  708. .invert_oclk = 0,
  709. .xtal_freq = TDA10046_XTAL_4M,
  710. .agc_config = TDA10046_AGC_DEFAULT,
  711. .if_freq = TDA10046_FREQ_3617,
  712. .request_firmware = philips_tdm1316l_request_firmware,
  713. };
  714. static struct tda1004x_config philips_tdm1316l_config_invert = {
  715. .demod_address = 0x8,
  716. .invert = 1,
  717. .invert_oclk = 0,
  718. .xtal_freq = TDA10046_XTAL_4M,
  719. .agc_config = TDA10046_AGC_DEFAULT,
  720. .if_freq = TDA10046_FREQ_3617,
  721. .request_firmware = philips_tdm1316l_request_firmware,
  722. };
  723. static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe)
  724. {
  725. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  726. struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv;
  727. u8 tuner_buf[5];
  728. struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,
  729. .flags = 0,
  730. .buf = tuner_buf,
  731. .len = sizeof(tuner_buf) };
  732. int tuner_frequency = 0;
  733. u8 band, cp, filter;
  734. // determine charge pump
  735. tuner_frequency = p->frequency + 36125000;
  736. if (tuner_frequency < 87000000)
  737. return -EINVAL;
  738. else if (tuner_frequency < 130000000) {
  739. cp = 3;
  740. band = 1;
  741. } else if (tuner_frequency < 160000000) {
  742. cp = 5;
  743. band = 1;
  744. } else if (tuner_frequency < 200000000) {
  745. cp = 6;
  746. band = 1;
  747. } else if (tuner_frequency < 290000000) {
  748. cp = 3;
  749. band = 2;
  750. } else if (tuner_frequency < 420000000) {
  751. cp = 5;
  752. band = 2;
  753. } else if (tuner_frequency < 480000000) {
  754. cp = 6;
  755. band = 2;
  756. } else if (tuner_frequency < 620000000) {
  757. cp = 3;
  758. band = 4;
  759. } else if (tuner_frequency < 830000000) {
  760. cp = 5;
  761. band = 4;
  762. } else if (tuner_frequency < 895000000) {
  763. cp = 7;
  764. band = 4;
  765. } else
  766. return -EINVAL;
  767. // assume PLL filter should always be 8MHz for the moment.
  768. filter = 1;
  769. // calculate divisor
  770. tuner_frequency = (p->frequency + 36125000 + (62500/2)) / 62500;
  771. // setup tuner buffer
  772. tuner_buf[0] = tuner_frequency >> 8;
  773. tuner_buf[1] = tuner_frequency & 0xff;
  774. tuner_buf[2] = 0xc8;
  775. tuner_buf[3] = (cp << 5) | (filter << 3) | band;
  776. tuner_buf[4] = 0x80;
  777. if (fe->ops.i2c_gate_ctrl)
  778. fe->ops.i2c_gate_ctrl(fe, 1);
  779. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  780. return -EIO;
  781. msleep(50);
  782. if (fe->ops.i2c_gate_ctrl)
  783. fe->ops.i2c_gate_ctrl(fe, 1);
  784. if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1)
  785. return -EIO;
  786. msleep(1);
  787. return 0;
  788. }
  789. static u8 dvbc_philips_tdm1316l_inittab[] = {
  790. 0x80, 0x01,
  791. 0x80, 0x00,
  792. 0x81, 0x01,
  793. 0x81, 0x00,
  794. 0x00, 0x09,
  795. 0x01, 0x69,
  796. 0x03, 0x00,
  797. 0x04, 0x00,
  798. 0x07, 0x00,
  799. 0x08, 0x00,
  800. 0x20, 0x00,
  801. 0x21, 0x40,
  802. 0x22, 0x00,
  803. 0x23, 0x00,
  804. 0x24, 0x40,
  805. 0x25, 0x88,
  806. 0x30, 0xff,
  807. 0x31, 0x00,
  808. 0x32, 0xff,
  809. 0x33, 0x00,
  810. 0x34, 0x50,
  811. 0x35, 0x7f,
  812. 0x36, 0x00,
  813. 0x37, 0x20,
  814. 0x38, 0x00,
  815. 0x40, 0x1c,
  816. 0x41, 0xff,
  817. 0x42, 0x29,
  818. 0x43, 0x20,
  819. 0x44, 0xff,
  820. 0x45, 0x00,
  821. 0x46, 0x00,
  822. 0x49, 0x04,
  823. 0x4a, 0x00,
  824. 0x4b, 0x7b,
  825. 0x52, 0x30,
  826. 0x55, 0xae,
  827. 0x56, 0x47,
  828. 0x57, 0xe1,
  829. 0x58, 0x3a,
  830. 0x5a, 0x1e,
  831. 0x5b, 0x34,
  832. 0x60, 0x00,
  833. 0x63, 0x00,
  834. 0x64, 0x00,
  835. 0x65, 0x00,
  836. 0x66, 0x00,
  837. 0x67, 0x00,
  838. 0x68, 0x00,
  839. 0x69, 0x00,
  840. 0x6a, 0x02,
  841. 0x6b, 0x00,
  842. 0x70, 0xff,
  843. 0x71, 0x00,
  844. 0x72, 0x00,
  845. 0x73, 0x00,
  846. 0x74, 0x0c,
  847. 0x80, 0x00,
  848. 0x81, 0x00,
  849. 0x82, 0x00,
  850. 0x83, 0x00,
  851. 0x84, 0x04,
  852. 0x85, 0x80,
  853. 0x86, 0x24,
  854. 0x87, 0x78,
  855. 0x88, 0x10,
  856. 0x89, 0x00,
  857. 0x90, 0x01,
  858. 0x91, 0x01,
  859. 0xa0, 0x04,
  860. 0xa1, 0x00,
  861. 0xa2, 0x00,
  862. 0xb0, 0x91,
  863. 0xb1, 0x0b,
  864. 0xc0, 0x53,
  865. 0xc1, 0x70,
  866. 0xc2, 0x12,
  867. 0xd0, 0x00,
  868. 0xd1, 0x00,
  869. 0xd2, 0x00,
  870. 0xd3, 0x00,
  871. 0xd4, 0x00,
  872. 0xd5, 0x00,
  873. 0xde, 0x00,
  874. 0xdf, 0x00,
  875. 0x61, 0x38,
  876. 0x62, 0x0a,
  877. 0x53, 0x13,
  878. 0x59, 0x08,
  879. 0xff, 0xff,
  880. };
  881. static struct stv0297_config dvbc_philips_tdm1316l_config = {
  882. .demod_address = 0x1c,
  883. .inittab = dvbc_philips_tdm1316l_inittab,
  884. .invert = 0,
  885. .stop_during_read = 1,
  886. };
  887. static struct tda10023_config tda10023_config = {
  888. .demod_address = 0xc,
  889. .invert = 0,
  890. .xtal = 16000000,
  891. .pll_m = 11,
  892. .pll_p = 3,
  893. .pll_n = 1,
  894. .deltaf = 0xa511,
  895. };
  896. static struct tda827x_config tda827x_config = {
  897. .config = 0,
  898. };
  899. /* TT S2-3200 DVB-S (STB0899) Inittab */
  900. static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = {
  901. { STB0899_DEV_ID , 0x81 },
  902. { STB0899_DISCNTRL1 , 0x32 },
  903. { STB0899_DISCNTRL2 , 0x80 },
  904. { STB0899_DISRX_ST0 , 0x04 },
  905. { STB0899_DISRX_ST1 , 0x00 },
  906. { STB0899_DISPARITY , 0x00 },
  907. { STB0899_DISSTATUS , 0x20 },
  908. { STB0899_DISF22 , 0x8c },
  909. { STB0899_DISF22RX , 0x9a },
  910. { STB0899_SYSREG , 0x0b },
  911. { STB0899_ACRPRESC , 0x11 },
  912. { STB0899_ACRDIV1 , 0x0a },
  913. { STB0899_ACRDIV2 , 0x05 },
  914. { STB0899_DACR1 , 0x00 },
  915. { STB0899_DACR2 , 0x00 },
  916. { STB0899_OUTCFG , 0x00 },
  917. { STB0899_MODECFG , 0x00 },
  918. { STB0899_IRQSTATUS_3 , 0x30 },
  919. { STB0899_IRQSTATUS_2 , 0x00 },
  920. { STB0899_IRQSTATUS_1 , 0x00 },
  921. { STB0899_IRQSTATUS_0 , 0x00 },
  922. { STB0899_IRQMSK_3 , 0xf3 },
  923. { STB0899_IRQMSK_2 , 0xfc },
  924. { STB0899_IRQMSK_1 , 0xff },
  925. { STB0899_IRQMSK_0 , 0xff },
  926. { STB0899_IRQCFG , 0x00 },
  927. { STB0899_I2CCFG , 0x88 },
  928. { STB0899_I2CRPT , 0x48 }, /* 12k Pullup, Repeater=16, Stop=disabled */
  929. { STB0899_IOPVALUE5 , 0x00 },
  930. { STB0899_IOPVALUE4 , 0x20 },
  931. { STB0899_IOPVALUE3 , 0xc9 },
  932. { STB0899_IOPVALUE2 , 0x90 },
  933. { STB0899_IOPVALUE1 , 0x40 },
  934. { STB0899_IOPVALUE0 , 0x00 },
  935. { STB0899_GPIO00CFG , 0x82 },
  936. { STB0899_GPIO01CFG , 0x82 },
  937. { STB0899_GPIO02CFG , 0x82 },
  938. { STB0899_GPIO03CFG , 0x82 },
  939. { STB0899_GPIO04CFG , 0x82 },
  940. { STB0899_GPIO05CFG , 0x82 },
  941. { STB0899_GPIO06CFG , 0x82 },
  942. { STB0899_GPIO07CFG , 0x82 },
  943. { STB0899_GPIO08CFG , 0x82 },
  944. { STB0899_GPIO09CFG , 0x82 },
  945. { STB0899_GPIO10CFG , 0x82 },
  946. { STB0899_GPIO11CFG , 0x82 },
  947. { STB0899_GPIO12CFG , 0x82 },
  948. { STB0899_GPIO13CFG , 0x82 },
  949. { STB0899_GPIO14CFG , 0x82 },
  950. { STB0899_GPIO15CFG , 0x82 },
  951. { STB0899_GPIO16CFG , 0x82 },
  952. { STB0899_GPIO17CFG , 0x82 },
  953. { STB0899_GPIO18CFG , 0x82 },
  954. { STB0899_GPIO19CFG , 0x82 },
  955. { STB0899_GPIO20CFG , 0x82 },
  956. { STB0899_SDATCFG , 0xb8 },
  957. { STB0899_SCLTCFG , 0xba },
  958. { STB0899_AGCRFCFG , 0x1c }, /* 0x11 */
  959. { STB0899_GPIO22 , 0x82 }, /* AGCBB2CFG */
  960. { STB0899_GPIO21 , 0x91 }, /* AGCBB1CFG */
  961. { STB0899_DIRCLKCFG , 0x82 },
  962. { STB0899_CLKOUT27CFG , 0x7e },
  963. { STB0899_STDBYCFG , 0x82 },
  964. { STB0899_CS0CFG , 0x82 },
  965. { STB0899_CS1CFG , 0x82 },
  966. { STB0899_DISEQCOCFG , 0x20 },
  967. { STB0899_GPIO32CFG , 0x82 },
  968. { STB0899_GPIO33CFG , 0x82 },
  969. { STB0899_GPIO34CFG , 0x82 },
  970. { STB0899_GPIO35CFG , 0x82 },
  971. { STB0899_GPIO36CFG , 0x82 },
  972. { STB0899_GPIO37CFG , 0x82 },
  973. { STB0899_GPIO38CFG , 0x82 },
  974. { STB0899_GPIO39CFG , 0x82 },
  975. { STB0899_NCOARSE , 0x15 }, /* 0x15 = 27 Mhz Clock, F/3 = 198MHz, F/6 = 99MHz */
  976. { STB0899_SYNTCTRL , 0x02 }, /* 0x00 = CLK from CLKI, 0x02 = CLK from XTALI */
  977. { STB0899_FILTCTRL , 0x00 },
  978. { STB0899_SYSCTRL , 0x00 },
  979. { STB0899_STOPCLK1 , 0x20 },
  980. { STB0899_STOPCLK2 , 0x00 },
  981. { STB0899_INTBUFSTATUS , 0x00 },
  982. { STB0899_INTBUFCTRL , 0x0a },
  983. { 0xffff , 0xff },
  984. };
  985. static const struct stb0899_s1_reg tt3200_stb0899_s1_init_3[] = {
  986. { STB0899_DEMOD , 0x00 },
  987. { STB0899_RCOMPC , 0xc9 },
  988. { STB0899_AGC1CN , 0x41 },
  989. { STB0899_AGC1REF , 0x10 },
  990. { STB0899_RTC , 0x7a },
  991. { STB0899_TMGCFG , 0x4e },
  992. { STB0899_AGC2REF , 0x34 },
  993. { STB0899_TLSR , 0x84 },
  994. { STB0899_CFD , 0xc7 },
  995. { STB0899_ACLC , 0x87 },
  996. { STB0899_BCLC , 0x94 },
  997. { STB0899_EQON , 0x41 },
  998. { STB0899_LDT , 0xdd },
  999. { STB0899_LDT2 , 0xc9 },
  1000. { STB0899_EQUALREF , 0xb4 },
  1001. { STB0899_TMGRAMP , 0x10 },
  1002. { STB0899_TMGTHD , 0x30 },
  1003. { STB0899_IDCCOMP , 0xfb },
  1004. { STB0899_QDCCOMP , 0x03 },
  1005. { STB0899_POWERI , 0x3b },
  1006. { STB0899_POWERQ , 0x3d },
  1007. { STB0899_RCOMP , 0x81 },
  1008. { STB0899_AGCIQIN , 0x80 },
  1009. { STB0899_AGC2I1 , 0x04 },
  1010. { STB0899_AGC2I2 , 0xf5 },
  1011. { STB0899_TLIR , 0x25 },
  1012. { STB0899_RTF , 0x80 },
  1013. { STB0899_DSTATUS , 0x00 },
  1014. { STB0899_LDI , 0xca },
  1015. { STB0899_CFRM , 0xf1 },
  1016. { STB0899_CFRL , 0xf3 },
  1017. { STB0899_NIRM , 0x2a },
  1018. { STB0899_NIRL , 0x05 },
  1019. { STB0899_ISYMB , 0x17 },
  1020. { STB0899_QSYMB , 0xfa },
  1021. { STB0899_SFRH , 0x2f },
  1022. { STB0899_SFRM , 0x68 },
  1023. { STB0899_SFRL , 0x40 },
  1024. { STB0899_SFRUPH , 0x2f },
  1025. { STB0899_SFRUPM , 0x68 },
  1026. { STB0899_SFRUPL , 0x40 },
  1027. { STB0899_EQUAI1 , 0xfd },
  1028. { STB0899_EQUAQ1 , 0x04 },
  1029. { STB0899_EQUAI2 , 0x0f },
  1030. { STB0899_EQUAQ2 , 0xff },
  1031. { STB0899_EQUAI3 , 0xdf },
  1032. { STB0899_EQUAQ3 , 0xfa },
  1033. { STB0899_EQUAI4 , 0x37 },
  1034. { STB0899_EQUAQ4 , 0x0d },
  1035. { STB0899_EQUAI5 , 0xbd },
  1036. { STB0899_EQUAQ5 , 0xf7 },
  1037. { STB0899_DSTATUS2 , 0x00 },
  1038. { STB0899_VSTATUS , 0x00 },
  1039. { STB0899_VERROR , 0xff },
  1040. { STB0899_IQSWAP , 0x2a },
  1041. { STB0899_ECNT1M , 0x00 },
  1042. { STB0899_ECNT1L , 0x00 },
  1043. { STB0899_ECNT2M , 0x00 },
  1044. { STB0899_ECNT2L , 0x00 },
  1045. { STB0899_ECNT3M , 0x00 },
  1046. { STB0899_ECNT3L , 0x00 },
  1047. { STB0899_FECAUTO1 , 0x06 },
  1048. { STB0899_FECM , 0x01 },
  1049. { STB0899_VTH12 , 0xf0 },
  1050. { STB0899_VTH23 , 0xa0 },
  1051. { STB0899_VTH34 , 0x78 },
  1052. { STB0899_VTH56 , 0x4e },
  1053. { STB0899_VTH67 , 0x48 },
  1054. { STB0899_VTH78 , 0x38 },
  1055. { STB0899_PRVIT , 0xff },
  1056. { STB0899_VITSYNC , 0x19 },
  1057. { STB0899_RSULC , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
  1058. { STB0899_TSULC , 0x42 },
  1059. { STB0899_RSLLC , 0x40 },
  1060. { STB0899_TSLPL , 0x12 },
  1061. { STB0899_TSCFGH , 0x0c },
  1062. { STB0899_TSCFGM , 0x00 },
  1063. { STB0899_TSCFGL , 0x0c },
  1064. { STB0899_TSOUT , 0x4d }, /* 0x0d for CAM */
  1065. { STB0899_RSSYNCDEL , 0x00 },
  1066. { STB0899_TSINHDELH , 0x02 },
  1067. { STB0899_TSINHDELM , 0x00 },
  1068. { STB0899_TSINHDELL , 0x00 },
  1069. { STB0899_TSLLSTKM , 0x00 },
  1070. { STB0899_TSLLSTKL , 0x00 },
  1071. { STB0899_TSULSTKM , 0x00 },
  1072. { STB0899_TSULSTKL , 0xab },
  1073. { STB0899_PCKLENUL , 0x00 },
  1074. { STB0899_PCKLENLL , 0xcc },
  1075. { STB0899_RSPCKLEN , 0xcc },
  1076. { STB0899_TSSTATUS , 0x80 },
  1077. { STB0899_ERRCTRL1 , 0xb6 },
  1078. { STB0899_ERRCTRL2 , 0x96 },
  1079. { STB0899_ERRCTRL3 , 0x89 },
  1080. { STB0899_DMONMSK1 , 0x27 },
  1081. { STB0899_DMONMSK0 , 0x03 },
  1082. { STB0899_DEMAPVIT , 0x5c },
  1083. { STB0899_PLPARM , 0x1f },
  1084. { STB0899_PDELCTRL , 0x48 },
  1085. { STB0899_PDELCTRL2 , 0x00 },
  1086. { STB0899_BBHCTRL1 , 0x00 },
  1087. { STB0899_BBHCTRL2 , 0x00 },
  1088. { STB0899_HYSTTHRESH , 0x77 },
  1089. { STB0899_MATCSTM , 0x00 },
  1090. { STB0899_MATCSTL , 0x00 },
  1091. { STB0899_UPLCSTM , 0x00 },
  1092. { STB0899_UPLCSTL , 0x00 },
  1093. { STB0899_DFLCSTM , 0x00 },
  1094. { STB0899_DFLCSTL , 0x00 },
  1095. { STB0899_SYNCCST , 0x00 },
  1096. { STB0899_SYNCDCSTM , 0x00 },
  1097. { STB0899_SYNCDCSTL , 0x00 },
  1098. { STB0899_ISI_ENTRY , 0x00 },
  1099. { STB0899_ISI_BIT_EN , 0x00 },
  1100. { STB0899_MATSTRM , 0x00 },
  1101. { STB0899_MATSTRL , 0x00 },
  1102. { STB0899_UPLSTRM , 0x00 },
  1103. { STB0899_UPLSTRL , 0x00 },
  1104. { STB0899_DFLSTRM , 0x00 },
  1105. { STB0899_DFLSTRL , 0x00 },
  1106. { STB0899_SYNCSTR , 0x00 },
  1107. { STB0899_SYNCDSTRM , 0x00 },
  1108. { STB0899_SYNCDSTRL , 0x00 },
  1109. { STB0899_CFGPDELSTATUS1 , 0x10 },
  1110. { STB0899_CFGPDELSTATUS2 , 0x00 },
  1111. { STB0899_BBFERRORM , 0x00 },
  1112. { STB0899_BBFERRORL , 0x00 },
  1113. { STB0899_UPKTERRORM , 0x00 },
  1114. { STB0899_UPKTERRORL , 0x00 },
  1115. { 0xffff , 0xff },
  1116. };
  1117. static struct stb0899_config tt3200_config = {
  1118. .init_dev = tt3200_stb0899_s1_init_1,
  1119. .init_s2_demod = stb0899_s2_init_2,
  1120. .init_s1_demod = tt3200_stb0899_s1_init_3,
  1121. .init_s2_fec = stb0899_s2_init_4,
  1122. .init_tst = stb0899_s1_init_5,
  1123. .postproc = NULL,
  1124. .demod_address = 0x68,
  1125. .xtal_freq = 27000000,
  1126. .inversion = IQ_SWAP_ON,
  1127. .lo_clk = 76500000,
  1128. .hi_clk = 99000000,
  1129. .esno_ave = STB0899_DVBS2_ESNO_AVE,
  1130. .esno_quant = STB0899_DVBS2_ESNO_QUANT,
  1131. .avframes_coarse = STB0899_DVBS2_AVFRAMES_COARSE,
  1132. .avframes_fine = STB0899_DVBS2_AVFRAMES_FINE,
  1133. .miss_threshold = STB0899_DVBS2_MISS_THRESHOLD,
  1134. .uwp_threshold_acq = STB0899_DVBS2_UWP_THRESHOLD_ACQ,
  1135. .uwp_threshold_track = STB0899_DVBS2_UWP_THRESHOLD_TRACK,
  1136. .uwp_threshold_sof = STB0899_DVBS2_UWP_THRESHOLD_SOF,
  1137. .sof_search_timeout = STB0899_DVBS2_SOF_SEARCH_TIMEOUT,
  1138. .btr_nco_bits = STB0899_DVBS2_BTR_NCO_BITS,
  1139. .btr_gain_shift_offset = STB0899_DVBS2_BTR_GAIN_SHIFT_OFFSET,
  1140. .crl_nco_bits = STB0899_DVBS2_CRL_NCO_BITS,
  1141. .ldpc_max_iter = STB0899_DVBS2_LDPC_MAX_ITER,
  1142. .tuner_get_frequency = stb6100_get_frequency,
  1143. .tuner_set_frequency = stb6100_set_frequency,
  1144. .tuner_set_bandwidth = stb6100_set_bandwidth,
  1145. .tuner_get_bandwidth = stb6100_get_bandwidth,
  1146. .tuner_set_rfsiggain = NULL
  1147. };
  1148. static struct stb6100_config tt3200_stb6100_config = {
  1149. .tuner_address = 0x60,
  1150. .refclock = 27000000,
  1151. };
  1152. static void frontend_init(struct budget_ci *budget_ci)
  1153. {
  1154. switch (budget_ci->budget.dev->pci->subsystem_device) {
  1155. case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059))
  1156. budget_ci->budget.dvb_frontend =
  1157. dvb_attach(stv0299_attach, &alps_bsru6_config, &budget_ci->budget.i2c_adap);
  1158. if (budget_ci->budget.dvb_frontend) {
  1159. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
  1160. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  1161. break;
  1162. }
  1163. break;
  1164. case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059))
  1165. budget_ci->budget.dvb_frontend =
  1166. dvb_attach(stv0299_attach, &philips_su1278_tt_config, &budget_ci->budget.i2c_adap);
  1167. if (budget_ci->budget.dvb_frontend) {
  1168. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_su1278_tt_tuner_set_params;
  1169. break;
  1170. }
  1171. break;
  1172. case 0x1010: // TT DVB-C CI budget (stv0297/Philips tdm1316l(tda6651tt))
  1173. budget_ci->tuner_pll_address = 0x61;
  1174. budget_ci->budget.dvb_frontend =
  1175. dvb_attach(stv0297_attach, &dvbc_philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  1176. if (budget_ci->budget.dvb_frontend) {
  1177. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = dvbc_philips_tdm1316l_tuner_set_params;
  1178. break;
  1179. }
  1180. break;
  1181. case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889)
  1182. budget_ci->tuner_pll_address = 0x63;
  1183. budget_ci->budget.dvb_frontend =
  1184. dvb_attach(tda10045_attach, &philips_tdm1316l_config, &budget_ci->budget.i2c_adap);
  1185. if (budget_ci->budget.dvb_frontend) {
  1186. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  1187. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  1188. break;
  1189. }
  1190. break;
  1191. case 0x1012: // TT DVB-T CI budget (tda10046/Philips tdm1316l(tda6651tt))
  1192. budget_ci->tuner_pll_address = 0x60;
  1193. budget_ci->budget.dvb_frontend =
  1194. dvb_attach(tda10046_attach, &philips_tdm1316l_config_invert, &budget_ci->budget.i2c_adap);
  1195. if (budget_ci->budget.dvb_frontend) {
  1196. budget_ci->budget.dvb_frontend->ops.tuner_ops.init = philips_tdm1316l_tuner_init;
  1197. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = philips_tdm1316l_tuner_set_params;
  1198. break;
  1199. }
  1200. break;
  1201. case 0x1017: // TT S-1500 PCI
  1202. budget_ci->budget.dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config, &budget_ci->budget.i2c_adap);
  1203. if (budget_ci->budget.dvb_frontend) {
  1204. budget_ci->budget.dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
  1205. budget_ci->budget.dvb_frontend->tuner_priv = &budget_ci->budget.i2c_adap;
  1206. budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
  1207. if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
  1208. printk("%s: No LNBP21 found!\n", __func__);
  1209. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1210. budget_ci->budget.dvb_frontend = NULL;
  1211. }
  1212. }
  1213. break;
  1214. case 0x101a: /* TT Budget-C-1501 (philips tda10023/philips tda8274A) */
  1215. budget_ci->budget.dvb_frontend = dvb_attach(tda10023_attach, &tda10023_config, &budget_ci->budget.i2c_adap, 0x48);
  1216. if (budget_ci->budget.dvb_frontend) {
  1217. if (dvb_attach(tda827x_attach, budget_ci->budget.dvb_frontend, 0x61, &budget_ci->budget.i2c_adap, &tda827x_config) == NULL) {
  1218. printk(KERN_ERR "%s: No tda827x found!\n", __func__);
  1219. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1220. budget_ci->budget.dvb_frontend = NULL;
  1221. }
  1222. }
  1223. break;
  1224. case 0x101b: /* TT S-1500B (BSBE1-D01A - STV0288/STB6000/LNBP21) */
  1225. budget_ci->budget.dvb_frontend = dvb_attach(stv0288_attach, &stv0288_bsbe1_d01a_config, &budget_ci->budget.i2c_adap);
  1226. if (budget_ci->budget.dvb_frontend) {
  1227. if (dvb_attach(stb6000_attach, budget_ci->budget.dvb_frontend, 0x63, &budget_ci->budget.i2c_adap)) {
  1228. if (!dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, 0, 0)) {
  1229. printk(KERN_ERR "%s: No LNBP21 found!\n", __func__);
  1230. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1231. budget_ci->budget.dvb_frontend = NULL;
  1232. }
  1233. } else {
  1234. printk(KERN_ERR "%s: No STB6000 found!\n", __func__);
  1235. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1236. budget_ci->budget.dvb_frontend = NULL;
  1237. }
  1238. }
  1239. break;
  1240. case 0x1019: // TT S2-3200 PCI
  1241. /*
  1242. * NOTE! on some STB0899 versions, the internal PLL takes a longer time
  1243. * to settle, aka LOCK. On the older revisions of the chip, we don't see
  1244. * this, as a result on the newer chips the entire clock tree, will not
  1245. * be stable after a freshly POWER 'ed up situation.
  1246. * In this case, we should RESET the STB0899 (Active LOW) and wait for
  1247. * PLL stabilization.
  1248. *
  1249. * On the TT S2 3200 and clones, the STB0899 demodulator's RESETB is
  1250. * connected to the SAA7146 GPIO, GPIO2, Pin 142
  1251. */
  1252. /* Reset Demodulator */
  1253. saa7146_setgpio(budget_ci->budget.dev, 2, SAA7146_GPIO_OUTLO);
  1254. /* Wait for everything to die */
  1255. msleep(50);
  1256. /* Pull it up out of Reset state */
  1257. saa7146_setgpio(budget_ci->budget.dev, 2, SAA7146_GPIO_OUTHI);
  1258. /* Wait for PLL to stabilize */
  1259. msleep(250);
  1260. /*
  1261. * PLL state should be stable now. Ideally, we should check
  1262. * for PLL LOCK status. But well, never mind!
  1263. */
  1264. budget_ci->budget.dvb_frontend = dvb_attach(stb0899_attach, &tt3200_config, &budget_ci->budget.i2c_adap);
  1265. if (budget_ci->budget.dvb_frontend) {
  1266. if (dvb_attach(stb6100_attach, budget_ci->budget.dvb_frontend, &tt3200_stb6100_config, &budget_ci->budget.i2c_adap)) {
  1267. if (!dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, 0, 0)) {
  1268. printk("%s: No LNBP21 found!\n", __func__);
  1269. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1270. budget_ci->budget.dvb_frontend = NULL;
  1271. }
  1272. } else {
  1273. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1274. budget_ci->budget.dvb_frontend = NULL;
  1275. }
  1276. }
  1277. break;
  1278. }
  1279. if (budget_ci->budget.dvb_frontend == NULL) {
  1280. printk("budget-ci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
  1281. budget_ci->budget.dev->pci->vendor,
  1282. budget_ci->budget.dev->pci->device,
  1283. budget_ci->budget.dev->pci->subsystem_vendor,
  1284. budget_ci->budget.dev->pci->subsystem_device);
  1285. } else {
  1286. if (dvb_register_frontend
  1287. (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
  1288. printk("budget-ci: Frontend registration failed!\n");
  1289. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1290. budget_ci->budget.dvb_frontend = NULL;
  1291. }
  1292. }
  1293. }
  1294. static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
  1295. {
  1296. struct budget_ci *budget_ci;
  1297. int err;
  1298. budget_ci = kzalloc(sizeof(struct budget_ci), GFP_KERNEL);
  1299. if (!budget_ci) {
  1300. err = -ENOMEM;
  1301. goto out1;
  1302. }
  1303. dprintk(2, "budget_ci: %p\n", budget_ci);
  1304. dev->ext_priv = budget_ci;
  1305. err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE,
  1306. adapter_nr);
  1307. if (err)
  1308. goto out2;
  1309. err = msp430_ir_init(budget_ci);
  1310. if (err)
  1311. goto out3;
  1312. ciintf_init(budget_ci);
  1313. budget_ci->budget.dvb_adapter.priv = budget_ci;
  1314. frontend_init(budget_ci);
  1315. ttpci_budget_init_hooks(&budget_ci->budget);
  1316. return 0;
  1317. out3:
  1318. ttpci_budget_deinit(&budget_ci->budget);
  1319. out2:
  1320. kfree(budget_ci);
  1321. out1:
  1322. return err;
  1323. }
  1324. static int budget_ci_detach(struct saa7146_dev *dev)
  1325. {
  1326. struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv;
  1327. struct saa7146_dev *saa = budget_ci->budget.dev;
  1328. int err;
  1329. if (budget_ci->budget.ci_present)
  1330. ciintf_deinit(budget_ci);
  1331. msp430_ir_deinit(budget_ci);
  1332. if (budget_ci->budget.dvb_frontend) {
  1333. dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
  1334. dvb_frontend_detach(budget_ci->budget.dvb_frontend);
  1335. }
  1336. err = ttpci_budget_deinit(&budget_ci->budget);
  1337. // disable frontend and CI interface
  1338. saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
  1339. kfree(budget_ci);
  1340. return err;
  1341. }
  1342. static struct saa7146_extension budget_extension;
  1343. MAKE_BUDGET_INFO(ttbs2, "TT-Budget/S-1500 PCI", BUDGET_TT);
  1344. MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC);
  1345. MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT);
  1346. MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
  1347. MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
  1348. MAKE_BUDGET_INFO(ttc1501, "TT-Budget C-1501 PCI", BUDGET_TT);
  1349. MAKE_BUDGET_INFO(tt3200, "TT-Budget S2-3200 PCI", BUDGET_TT);
  1350. MAKE_BUDGET_INFO(ttbs1500b, "TT-Budget S-1500B PCI", BUDGET_TT);
  1351. static struct pci_device_id pci_tbl[] = {
  1352. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
  1353. MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
  1354. MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
  1355. MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011),
  1356. MAKE_EXTENSION_PCI(ttbtci, 0x13c2, 0x1012),
  1357. MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
  1358. MAKE_EXTENSION_PCI(ttc1501, 0x13c2, 0x101a),
  1359. MAKE_EXTENSION_PCI(tt3200, 0x13c2, 0x1019),
  1360. MAKE_EXTENSION_PCI(ttbs1500b, 0x13c2, 0x101b),
  1361. {
  1362. .vendor = 0,
  1363. }
  1364. };
  1365. MODULE_DEVICE_TABLE(pci, pci_tbl);
  1366. static struct saa7146_extension budget_extension = {
  1367. .name = "budget_ci dvb",
  1368. .flags = SAA7146_USE_I2C_IRQ,
  1369. .module = THIS_MODULE,
  1370. .pci_tbl = &pci_tbl[0],
  1371. .attach = budget_ci_attach,
  1372. .detach = budget_ci_detach,
  1373. .irq_mask = MASK_03 | MASK_06 | MASK_10,
  1374. .irq_func = budget_ci_irq,
  1375. };
  1376. static int __init budget_ci_init(void)
  1377. {
  1378. return saa7146_register_extension(&budget_extension);
  1379. }
  1380. static void __exit budget_ci_exit(void)
  1381. {
  1382. saa7146_unregister_extension(&budget_extension);
  1383. }
  1384. module_init(budget_ci_init);
  1385. module_exit(budget_ci_exit);
  1386. MODULE_LICENSE("GPL");
  1387. MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others");
  1388. MODULE_DESCRIPTION("driver for the SAA7146 based so-called "
  1389. "budget PCI DVB cards w/ CI-module produced by "
  1390. "Siemens, Technotrend, Hauppauge");