budget-ci.c 48 KB

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