budget-patch.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * budget-patch.c: driver for Budget Patch,
  3. * hardware modification of DVB-S cards enabling full TS
  4. *
  5. * Written by Emard <emard@softhome.net>
  6. *
  7. * Original idea by Roberto Deza <rdeza@unav.es>
  8. *
  9. * Special thanks to Holger Waechtler, Michael Hunold, Marian Durkovic
  10. * and Metzlerbros
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  28. *
  29. *
  30. * the project's page is at https://linuxtv.org
  31. */
  32. #include "av7110.h"
  33. #include "av7110_hw.h"
  34. #include "budget.h"
  35. #include "stv0299.h"
  36. #include "ves1x93.h"
  37. #include "tda8083.h"
  38. #include "bsru6.h"
  39. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  40. #define budget_patch budget
  41. static struct saa7146_extension budget_extension;
  42. MAKE_BUDGET_INFO(ttbp, "TT-Budget/Patch DVB-S 1.x PCI", BUDGET_PATCH);
  43. //MAKE_BUDGET_INFO(satel,"TT-Budget/Patch SATELCO PCI", BUDGET_TT_HW_DISEQC);
  44. static struct pci_device_id pci_tbl[] = {
  45. MAKE_EXTENSION_PCI(ttbp,0x13c2, 0x0000),
  46. // MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
  47. {
  48. .vendor = 0,
  49. }
  50. };
  51. /* those lines are for budget-patch to be tried
  52. ** on a true budget card and observe the
  53. ** behaviour of VSYNC generated by rps1.
  54. ** this code was shamelessly copy/pasted from budget.c
  55. */
  56. static void gpio_Set22K (struct budget *budget, int state)
  57. {
  58. struct saa7146_dev *dev=budget->dev;
  59. dprintk(2, "budget: %p\n", budget);
  60. saa7146_setgpio(dev, 3, (state ? SAA7146_GPIO_OUTHI : SAA7146_GPIO_OUTLO));
  61. }
  62. /* Diseqc functions only for TT Budget card */
  63. /* taken from the Skyvision DVB driver by
  64. Ralph Metzler <rjkm@metzlerbros.de> */
  65. static void DiseqcSendBit (struct budget *budget, int data)
  66. {
  67. struct saa7146_dev *dev=budget->dev;
  68. dprintk(2, "budget: %p\n", budget);
  69. saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
  70. udelay(data ? 500 : 1000);
  71. saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
  72. udelay(data ? 1000 : 500);
  73. }
  74. static void DiseqcSendByte (struct budget *budget, int data)
  75. {
  76. int i, par=1, d;
  77. dprintk(2, "budget: %p\n", budget);
  78. for (i=7; i>=0; i--) {
  79. d = (data>>i)&1;
  80. par ^= d;
  81. DiseqcSendBit(budget, d);
  82. }
  83. DiseqcSendBit(budget, par);
  84. }
  85. static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
  86. {
  87. struct saa7146_dev *dev=budget->dev;
  88. int i;
  89. dprintk(2, "budget: %p\n", budget);
  90. saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
  91. mdelay(16);
  92. for (i=0; i<len; i++)
  93. DiseqcSendByte(budget, msg[i]);
  94. mdelay(16);
  95. if (burst!=-1) {
  96. if (burst)
  97. DiseqcSendByte(budget, 0xff);
  98. else {
  99. saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
  100. mdelay(12);
  101. udelay(500);
  102. saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
  103. }
  104. msleep(20);
  105. }
  106. return 0;
  107. }
  108. /* shamelessly copy/pasted from budget.c */
  109. static int budget_set_tone(struct dvb_frontend *fe,
  110. enum fe_sec_tone_mode tone)
  111. {
  112. struct budget* budget = (struct budget*) fe->dvb->priv;
  113. switch (tone) {
  114. case SEC_TONE_ON:
  115. gpio_Set22K (budget, 1);
  116. break;
  117. case SEC_TONE_OFF:
  118. gpio_Set22K (budget, 0);
  119. break;
  120. default:
  121. return -EINVAL;
  122. }
  123. return 0;
  124. }
  125. static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
  126. {
  127. struct budget* budget = (struct budget*) fe->dvb->priv;
  128. SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
  129. return 0;
  130. }
  131. static int budget_diseqc_send_burst(struct dvb_frontend *fe,
  132. enum fe_sec_mini_cmd minicmd)
  133. {
  134. struct budget* budget = (struct budget*) fe->dvb->priv;
  135. SendDiSEqCMsg (budget, 0, NULL, minicmd);
  136. return 0;
  137. }
  138. static int budget_av7110_send_fw_cmd(struct budget_patch *budget, u16* buf, int length)
  139. {
  140. int i;
  141. dprintk(2, "budget: %p\n", budget);
  142. for (i = 2; i < length; i++)
  143. {
  144. ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2*i, 2, (u32) buf[i], 0,0);
  145. msleep(5);
  146. }
  147. if (length)
  148. ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2, 2, (u32) buf[1], 0,0);
  149. else
  150. ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2, 2, 0, 0,0);
  151. msleep(5);
  152. ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND, 2, (u32) buf[0], 0,0);
  153. msleep(5);
  154. return 0;
  155. }
  156. static void av7110_set22k(struct budget_patch *budget, int state)
  157. {
  158. u16 buf[2] = {( COMTYPE_AUDIODAC << 8) | (state ? ON22K : OFF22K), 0};
  159. dprintk(2, "budget: %p\n", budget);
  160. budget_av7110_send_fw_cmd(budget, buf, 2);
  161. }
  162. static int av7110_send_diseqc_msg(struct budget_patch *budget, int len, u8 *msg, int burst)
  163. {
  164. int i;
  165. u16 buf[18] = { ((COMTYPE_AUDIODAC << 8) | SendDiSEqC),
  166. 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  167. dprintk(2, "budget: %p\n", budget);
  168. if (len>10)
  169. len=10;
  170. buf[1] = len+2;
  171. buf[2] = len;
  172. if (burst != -1)
  173. buf[3]=burst ? 0x01 : 0x00;
  174. else
  175. buf[3]=0xffff;
  176. for (i=0; i<len; i++)
  177. buf[i+4]=msg[i];
  178. budget_av7110_send_fw_cmd(budget, buf, 18);
  179. return 0;
  180. }
  181. static int budget_patch_set_tone(struct dvb_frontend *fe,
  182. enum fe_sec_tone_mode tone)
  183. {
  184. struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
  185. switch (tone) {
  186. case SEC_TONE_ON:
  187. av7110_set22k (budget, 1);
  188. break;
  189. case SEC_TONE_OFF:
  190. av7110_set22k (budget, 0);
  191. break;
  192. default:
  193. return -EINVAL;
  194. }
  195. return 0;
  196. }
  197. static int budget_patch_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
  198. {
  199. struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
  200. av7110_send_diseqc_msg (budget, cmd->msg_len, cmd->msg, 0);
  201. return 0;
  202. }
  203. static int budget_patch_diseqc_send_burst(struct dvb_frontend *fe,
  204. enum fe_sec_mini_cmd minicmd)
  205. {
  206. struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
  207. av7110_send_diseqc_msg (budget, 0, NULL, minicmd);
  208. return 0;
  209. }
  210. static int alps_bsrv2_tuner_set_params(struct dvb_frontend *fe)
  211. {
  212. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  213. struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
  214. u8 pwr = 0;
  215. u8 buf[4];
  216. struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
  217. u32 div = (p->frequency + 479500) / 125;
  218. if (p->frequency > 2000000)
  219. pwr = 3;
  220. else if (p->frequency > 1800000)
  221. pwr = 2;
  222. else if (p->frequency > 1600000)
  223. pwr = 1;
  224. else if (p->frequency > 1200000)
  225. pwr = 0;
  226. else if (p->frequency >= 1100000)
  227. pwr = 1;
  228. else pwr = 2;
  229. buf[0] = (div >> 8) & 0x7f;
  230. buf[1] = div & 0xff;
  231. buf[2] = ((div & 0x18000) >> 10) | 0x95;
  232. buf[3] = (pwr << 6) | 0x30;
  233. // NOTE: since we're using a prescaler of 2, we set the
  234. // divisor frequency to 62.5kHz and divide by 125 above
  235. if (fe->ops.i2c_gate_ctrl)
  236. fe->ops.i2c_gate_ctrl(fe, 1);
  237. if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1)
  238. return -EIO;
  239. return 0;
  240. }
  241. static struct ves1x93_config alps_bsrv2_config = {
  242. .demod_address = 0x08,
  243. .xin = 90100000UL,
  244. .invert_pwm = 0,
  245. };
  246. static int grundig_29504_451_tuner_set_params(struct dvb_frontend *fe)
  247. {
  248. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  249. struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
  250. u32 div;
  251. u8 data[4];
  252. struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
  253. div = p->frequency / 125;
  254. data[0] = (div >> 8) & 0x7f;
  255. data[1] = div & 0xff;
  256. data[2] = 0x8e;
  257. data[3] = 0x00;
  258. if (fe->ops.i2c_gate_ctrl)
  259. fe->ops.i2c_gate_ctrl(fe, 1);
  260. if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1)
  261. return -EIO;
  262. return 0;
  263. }
  264. static struct tda8083_config grundig_29504_451_config = {
  265. .demod_address = 0x68,
  266. };
  267. static void frontend_init(struct budget_patch* budget)
  268. {
  269. switch(budget->dev->pci->subsystem_device) {
  270. case 0x0000: // Hauppauge/TT WinTV DVB-S rev1.X
  271. case 0x1013: // SATELCO Multimedia PCI
  272. // try the ALPS BSRV2 first of all
  273. budget->dvb_frontend = dvb_attach(ves1x93_attach, &alps_bsrv2_config, &budget->i2c_adap);
  274. if (budget->dvb_frontend) {
  275. budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsrv2_tuner_set_params;
  276. budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_patch_diseqc_send_master_cmd;
  277. budget->dvb_frontend->ops.diseqc_send_burst = budget_patch_diseqc_send_burst;
  278. budget->dvb_frontend->ops.set_tone = budget_patch_set_tone;
  279. break;
  280. }
  281. // try the ALPS BSRU6 now
  282. budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap);
  283. if (budget->dvb_frontend) {
  284. budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
  285. budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
  286. budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
  287. budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
  288. budget->dvb_frontend->ops.set_tone = budget_set_tone;
  289. break;
  290. }
  291. // Try the grundig 29504-451
  292. budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
  293. if (budget->dvb_frontend) {
  294. budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_451_tuner_set_params;
  295. budget->dvb_frontend->ops.diseqc_send_master_cmd = budget_diseqc_send_master_cmd;
  296. budget->dvb_frontend->ops.diseqc_send_burst = budget_diseqc_send_burst;
  297. budget->dvb_frontend->ops.set_tone = budget_set_tone;
  298. break;
  299. }
  300. break;
  301. }
  302. if (budget->dvb_frontend == NULL) {
  303. printk("dvb-ttpci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
  304. budget->dev->pci->vendor,
  305. budget->dev->pci->device,
  306. budget->dev->pci->subsystem_vendor,
  307. budget->dev->pci->subsystem_device);
  308. } else {
  309. if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) {
  310. printk("budget-av: Frontend registration failed!\n");
  311. dvb_frontend_detach(budget->dvb_frontend);
  312. budget->dvb_frontend = NULL;
  313. }
  314. }
  315. }
  316. /* written by Emard */
  317. static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
  318. {
  319. struct budget_patch *budget;
  320. int err;
  321. int count = 0;
  322. int detected = 0;
  323. #define PATCH_RESET 0
  324. #define RPS_IRQ 0
  325. #define HPS_SETUP 0
  326. #if PATCH_RESET
  327. saa7146_write(dev, MC1, MASK_31);
  328. msleep(40);
  329. #endif
  330. #if HPS_SETUP
  331. // initialize registers. Better to have it like this
  332. // than leaving something unconfigured
  333. saa7146_write(dev, DD1_STREAM_B, 0);
  334. // port B VSYNC at rising edge
  335. saa7146_write(dev, DD1_INIT, 0x00000200); // have this in budget-core too!
  336. saa7146_write(dev, BRS_CTRL, 0x00000000); // VBI
  337. // debi config
  338. // saa7146_write(dev, DEBI_CONFIG, MASK_30|MASK_28|MASK_18);
  339. // zero all HPS registers
  340. saa7146_write(dev, HPS_H_PRESCALE, 0); // r68
  341. saa7146_write(dev, HPS_H_SCALE, 0); // r6c
  342. saa7146_write(dev, BCS_CTRL, 0); // r70
  343. saa7146_write(dev, HPS_V_SCALE, 0); // r60
  344. saa7146_write(dev, HPS_V_GAIN, 0); // r64
  345. saa7146_write(dev, CHROMA_KEY_RANGE, 0); // r74
  346. saa7146_write(dev, CLIP_FORMAT_CTRL, 0); // r78
  347. // Set HPS prescaler for port B input
  348. saa7146_write(dev, HPS_CTRL, (1<<30) | (0<<29) | (1<<28) | (0<<12) );
  349. saa7146_write(dev, MC2,
  350. 0 * (MASK_08 | MASK_24) | // BRS control
  351. 0 * (MASK_09 | MASK_25) | // a
  352. 0 * (MASK_10 | MASK_26) | // b
  353. 1 * (MASK_06 | MASK_22) | // HPS_CTRL1
  354. 1 * (MASK_05 | MASK_21) | // HPS_CTRL2
  355. 0 * (MASK_01 | MASK_15) // DEBI
  356. );
  357. #endif
  358. // Disable RPS1 and RPS0
  359. saa7146_write(dev, MC1, ( MASK_29 | MASK_28));
  360. // RPS1 timeout disable
  361. saa7146_write(dev, RPS_TOV1, 0);
  362. // code for autodetection
  363. // will wait for VBI_B event (vertical blank at port B)
  364. // and will reset GPIO3 after VBI_B is detected.
  365. // (GPIO3 should be raised high by CPU to
  366. // test if GPIO3 will generate vertical blank signal
  367. // in budget patch GPIO3 is connected to VSYNC_B
  368. count = 0;
  369. #if 0
  370. WRITE_RPS1(CMD_UPLOAD |
  371. MASK_10 | MASK_09 | MASK_08 | MASK_06 | MASK_05 | MASK_04 | MASK_03 | MASK_02 );
  372. #endif
  373. WRITE_RPS1(CMD_PAUSE | EVT_VBI_B);
  374. WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
  375. WRITE_RPS1(GPIO3_MSK);
  376. WRITE_RPS1(SAA7146_GPIO_OUTLO<<24);
  377. #if RPS_IRQ
  378. // issue RPS1 interrupt to increment counter
  379. WRITE_RPS1(CMD_INTERRUPT);
  380. // at least a NOP is neede between two interrupts
  381. WRITE_RPS1(CMD_NOP);
  382. // interrupt again
  383. WRITE_RPS1(CMD_INTERRUPT);
  384. #endif
  385. WRITE_RPS1(CMD_STOP);
  386. #if RPS_IRQ
  387. // set event counter 1 source as RPS1 interrupt (0x03) (rE4 p53)
  388. // use 0x03 to track RPS1 interrupts - increase by 1 every gpio3 is toggled
  389. // use 0x15 to track VPE interrupts - increase by 1 every vpeirq() is called
  390. saa7146_write(dev, EC1SSR, (0x03<<2) | 3 );
  391. // set event counter 1 threshold to maximum allowed value (rEC p55)
  392. saa7146_write(dev, ECT1R, 0x3fff );
  393. #endif
  394. // Fix VSYNC level
  395. saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
  396. // Set RPS1 Address register to point to RPS code (r108 p42)
  397. saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
  398. // Enable RPS1, (rFC p33)
  399. saa7146_write(dev, MC1, (MASK_13 | MASK_29 ));
  400. mdelay(50);
  401. saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
  402. mdelay(150);
  403. if( (saa7146_read(dev, GPIO_CTRL) & 0x10000000) == 0)
  404. detected = 1;
  405. #if RPS_IRQ
  406. printk("Event Counter 1 0x%04x\n", saa7146_read(dev, EC1R) & 0x3fff );
  407. #endif
  408. // Disable RPS1
  409. saa7146_write(dev, MC1, ( MASK_29 ));
  410. if(detected == 0)
  411. printk("budget-patch not detected or saa7146 in non-default state.\n"
  412. "try enabling resetting of 7146 with MASK_31 in MC1 register\n");
  413. else
  414. printk("BUDGET-PATCH DETECTED.\n");
  415. /* OLD (Original design by Roberto Deza):
  416. ** This code will setup the SAA7146_RPS1 to generate a square
  417. ** wave on GPIO3, changing when a field (TS_HEIGHT/2 "lines" of
  418. ** TS_WIDTH packets) has been acquired on SAA7146_D1B video port;
  419. ** then, this GPIO3 output which is connected to the D1B_VSYNC
  420. ** input, will trigger the acquisition of the alternate field
  421. ** and so on.
  422. ** Currently, the TT_budget / WinTV_Nova cards have two ICs
  423. ** (74HCT4040, LVC74) for the generation of this VSYNC signal,
  424. ** which seems that can be done perfectly without this :-)).
  425. */
  426. /* New design (By Emard)
  427. ** this rps1 code will copy internal HS event to GPIO3 pin.
  428. ** GPIO3 is in budget-patch hardware connected to port B VSYNC
  429. ** HS is an internal event of 7146, accessible with RPS
  430. ** and temporarily raised high every n lines
  431. ** (n in defined in the RPS_THRESH1 counter threshold)
  432. ** I think HS is raised high on the beginning of the n-th line
  433. ** and remains high until this n-th line that triggered
  434. ** it is completely received. When the reception of n-th line
  435. ** ends, HS is lowered.
  436. ** To transmit data over DMA, 7146 needs changing state at
  437. ** port B VSYNC pin. Any changing of port B VSYNC will
  438. ** cause some DMA data transfer, with more or less packets loss.
  439. ** It depends on the phase and frequency of VSYNC and
  440. ** the way of 7146 is instructed to trigger on port B (defined
  441. ** in DD1_INIT register, 3rd nibble from the right valid
  442. ** numbers are 0-7, see datasheet)
  443. **
  444. ** The correct triggering can minimize packet loss,
  445. ** dvbtraffic should give this stable bandwidths:
  446. ** 22k transponder = 33814 kbit/s
  447. ** 27.5k transponder = 38045 kbit/s
  448. ** by experiment it is found that the best results
  449. ** (stable bandwidths and almost no packet loss)
  450. ** are obtained using DD1_INIT triggering number 2
  451. ** (Va at rising edge of VS Fa = HS x VS-failing forced toggle)
  452. ** and a VSYNC phase that occurs in the middle of DMA transfer
  453. ** (about byte 188*512=96256 in the DMA window).
  454. **
  455. ** Phase of HS is still not clear to me how to control,
  456. ** It just happens to be so. It can be seen if one enables
  457. ** RPS_IRQ and print Event Counter 1 in vpeirq(). Every
  458. ** time RPS_INTERRUPT is called, the Event Counter 1 will
  459. ** increment. That's how the 7146 is programmed to do event
  460. ** counting in this budget-patch.c
  461. ** I *think* HPS setting has something to do with the phase
  462. ** of HS but I can't be 100% sure in that.
  463. ** hardware debug note: a working budget card (including budget patch)
  464. ** with vpeirq() interrupt setup in mode "0x90" (every 64K) will
  465. ** generate 3 interrupts per 25-Hz DMA frame of 2*188*512 bytes
  466. ** and that means 3*25=75 Hz of interrupt frequency, as seen by
  467. ** watch cat /proc/interrupts
  468. **
  469. ** If this frequency is 3x lower (and data received in the DMA
  470. ** buffer don't start with 0x47, but in the middle of packets,
  471. ** whose lengths appear to be like 188 292 188 104 etc.
  472. ** this means VSYNC line is not connected in the hardware.
  473. ** (check soldering pcb and pins)
  474. ** The same behaviour of missing VSYNC can be duplicated on budget
  475. ** cards, by setting DD1_INIT trigger mode 7 in 3rd nibble.
  476. */
  477. // Setup RPS1 "program" (p35)
  478. count = 0;
  479. // Wait Source Line Counter Threshold (p36)
  480. WRITE_RPS1(CMD_PAUSE | EVT_HS);
  481. // Set GPIO3=1 (p42)
  482. WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
  483. WRITE_RPS1(GPIO3_MSK);
  484. WRITE_RPS1(SAA7146_GPIO_OUTHI<<24);
  485. #if RPS_IRQ
  486. // issue RPS1 interrupt
  487. WRITE_RPS1(CMD_INTERRUPT);
  488. #endif
  489. // Wait reset Source Line Counter Threshold (p36)
  490. WRITE_RPS1(CMD_PAUSE | RPS_INV | EVT_HS);
  491. // Set GPIO3=0 (p42)
  492. WRITE_RPS1(CMD_WR_REG_MASK | (GPIO_CTRL>>2));
  493. WRITE_RPS1(GPIO3_MSK);
  494. WRITE_RPS1(SAA7146_GPIO_OUTLO<<24);
  495. #if RPS_IRQ
  496. // issue RPS1 interrupt
  497. WRITE_RPS1(CMD_INTERRUPT);
  498. #endif
  499. // Jump to begin of RPS program (p37)
  500. WRITE_RPS1(CMD_JUMP);
  501. WRITE_RPS1(dev->d_rps1.dma_handle);
  502. // Fix VSYNC level
  503. saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
  504. // Set RPS1 Address register to point to RPS code (r108 p42)
  505. saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
  506. if (!(budget = kmalloc (sizeof(struct budget_patch), GFP_KERNEL)))
  507. return -ENOMEM;
  508. dprintk(2, "budget: %p\n", budget);
  509. err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
  510. if (err) {
  511. kfree(budget);
  512. return err;
  513. }
  514. // Set Source Line Counter Threshold, using BRS (rCC p43)
  515. // It generates HS event every TS_HEIGHT lines
  516. // this is related to TS_WIDTH set in register
  517. // NUM_LINE_BYTE3 in budget-core.c. If NUM_LINE_BYTE
  518. // low 16 bits are set to TS_WIDTH bytes (TS_WIDTH=2*188
  519. //,then RPS_THRESH1
  520. // should be set to trigger every TS_HEIGHT (512) lines.
  521. //
  522. saa7146_write(dev, RPS_THRESH1, budget->buffer_height | MASK_12 );
  523. // saa7146_write(dev, RPS_THRESH0, ((TS_HEIGHT/2)<<16) |MASK_28| (TS_HEIGHT/2) |MASK_12 );
  524. // Enable RPS1 (rFC p33)
  525. saa7146_write(dev, MC1, (MASK_13 | MASK_29));
  526. dev->ext_priv = budget;
  527. budget->dvb_adapter.priv = budget;
  528. frontend_init(budget);
  529. ttpci_budget_init_hooks(budget);
  530. return 0;
  531. }
  532. static int budget_patch_detach (struct saa7146_dev* dev)
  533. {
  534. struct budget_patch *budget = (struct budget_patch*) dev->ext_priv;
  535. int err;
  536. if (budget->dvb_frontend) {
  537. dvb_unregister_frontend(budget->dvb_frontend);
  538. dvb_frontend_detach(budget->dvb_frontend);
  539. }
  540. err = ttpci_budget_deinit (budget);
  541. kfree (budget);
  542. return err;
  543. }
  544. static int __init budget_patch_init(void)
  545. {
  546. return saa7146_register_extension(&budget_extension);
  547. }
  548. static void __exit budget_patch_exit(void)
  549. {
  550. saa7146_unregister_extension(&budget_extension);
  551. }
  552. static struct saa7146_extension budget_extension = {
  553. .name = "budget_patch dvb",
  554. .flags = 0,
  555. .module = THIS_MODULE,
  556. .pci_tbl = pci_tbl,
  557. .attach = budget_patch_attach,
  558. .detach = budget_patch_detach,
  559. .irq_mask = MASK_10,
  560. .irq_func = ttpci_budget_irq10_handler,
  561. };
  562. module_init(budget_patch_init);
  563. module_exit(budget_patch_exit);
  564. MODULE_LICENSE("GPL");
  565. MODULE_AUTHOR("Emard, Roberto Deza, Holger Waechtler, Michael Hunold, others");
  566. MODULE_DESCRIPTION("Driver for full TS modified DVB-S SAA7146+AV7110 "
  567. "based so-called Budget Patch cards");