dvb-bt8xx.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. /*
  2. * Bt8xx based DVB adapter driver
  3. *
  4. * Copyright (C) 2002,2003 Florian Schirmer <jolt@tuxbox.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. */
  21. #include <linux/bitops.h>
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <linux/kernel.h>
  25. #include <linux/device.h>
  26. #include <linux/delay.h>
  27. #include <linux/slab.h>
  28. #include <linux/i2c.h>
  29. #include "dmxdev.h"
  30. #include "dvbdev.h"
  31. #include "dvb_demux.h"
  32. #include "dvb_frontend.h"
  33. #include "dvb-bt8xx.h"
  34. #include "bt878.h"
  35. static int debug;
  36. module_param(debug, int, 0644);
  37. MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
  38. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  39. #define dprintk( args... ) \
  40. do { \
  41. if (debug) printk(KERN_DEBUG args); \
  42. } while (0)
  43. #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
  44. static void dvb_bt8xx_task(unsigned long data)
  45. {
  46. struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *)data;
  47. //printk("%d ", card->bt->finished_block);
  48. while (card->bt->last_block != card->bt->finished_block) {
  49. (card->bt->TS_Size ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter)
  50. (&card->demux,
  51. &card->bt->buf_cpu[card->bt->last_block *
  52. card->bt->block_bytes],
  53. card->bt->block_bytes);
  54. card->bt->last_block = (card->bt->last_block + 1) %
  55. card->bt->block_count;
  56. }
  57. }
  58. static int dvb_bt8xx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
  59. {
  60. struct dvb_demux*dvbdmx = dvbdmxfeed->demux;
  61. struct dvb_bt8xx_card *card = dvbdmx->priv;
  62. int rc;
  63. dprintk("dvb_bt8xx: start_feed\n");
  64. if (!dvbdmx->dmx.frontend)
  65. return -EINVAL;
  66. mutex_lock(&card->lock);
  67. card->nfeeds++;
  68. rc = card->nfeeds;
  69. if (card->nfeeds == 1)
  70. bt878_start(card->bt, card->gpio_mode,
  71. card->op_sync_orin, card->irq_err_ignore);
  72. mutex_unlock(&card->lock);
  73. return rc;
  74. }
  75. static int dvb_bt8xx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
  76. {
  77. struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
  78. struct dvb_bt8xx_card *card = dvbdmx->priv;
  79. dprintk("dvb_bt8xx: stop_feed\n");
  80. if (!dvbdmx->dmx.frontend)
  81. return -EINVAL;
  82. mutex_lock(&card->lock);
  83. card->nfeeds--;
  84. if (card->nfeeds == 0)
  85. bt878_stop(card->bt);
  86. mutex_unlock(&card->lock);
  87. return 0;
  88. }
  89. static int is_pci_slot_eq(struct pci_dev* adev, struct pci_dev* bdev)
  90. {
  91. if ((adev->subsystem_vendor == bdev->subsystem_vendor) &&
  92. (adev->subsystem_device == bdev->subsystem_device) &&
  93. (adev->bus->number == bdev->bus->number) &&
  94. (PCI_SLOT(adev->devfn) == PCI_SLOT(bdev->devfn)))
  95. return 1;
  96. return 0;
  97. }
  98. static struct bt878 __devinit *dvb_bt8xx_878_match(unsigned int bttv_nr, struct pci_dev* bttv_pci_dev)
  99. {
  100. unsigned int card_nr;
  101. /* Hmm, n squared. Hope n is small */
  102. for (card_nr = 0; card_nr < bt878_num; card_nr++)
  103. if (is_pci_slot_eq(bt878[card_nr].dev, bttv_pci_dev))
  104. return &bt878[card_nr];
  105. return NULL;
  106. }
  107. static int thomson_dtt7579_demod_init(struct dvb_frontend* fe)
  108. {
  109. static u8 mt352_clock_config [] = { 0x89, 0x38, 0x38 };
  110. static u8 mt352_reset [] = { 0x50, 0x80 };
  111. static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  112. static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0x20 };
  113. static u8 mt352_gpp_ctl_cfg [] = { 0x8C, 0x33 };
  114. static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
  115. mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
  116. udelay(2000);
  117. mt352_write(fe, mt352_reset, sizeof(mt352_reset));
  118. mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
  119. mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
  120. mt352_write(fe, mt352_gpp_ctl_cfg, sizeof(mt352_gpp_ctl_cfg));
  121. mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
  122. return 0;
  123. }
  124. static int thomson_dtt7579_tuner_calc_regs(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf, int buf_len)
  125. {
  126. u32 div;
  127. unsigned char bs = 0;
  128. unsigned char cp = 0;
  129. if (buf_len < 5)
  130. return -EINVAL;
  131. div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
  132. if (params->frequency < 542000000)
  133. cp = 0xb4;
  134. else if (params->frequency < 771000000)
  135. cp = 0xbc;
  136. else
  137. cp = 0xf4;
  138. if (params->frequency == 0)
  139. bs = 0x03;
  140. else if (params->frequency < 443250000)
  141. bs = 0x02;
  142. else
  143. bs = 0x08;
  144. pllbuf[0] = 0x60;
  145. pllbuf[1] = div >> 8;
  146. pllbuf[2] = div & 0xff;
  147. pllbuf[3] = cp;
  148. pllbuf[4] = bs;
  149. return 5;
  150. }
  151. static struct mt352_config thomson_dtt7579_config = {
  152. .demod_address = 0x0f,
  153. .demod_init = thomson_dtt7579_demod_init,
  154. };
  155. static struct zl10353_config thomson_dtt7579_zl10353_config = {
  156. .demod_address = 0x0f,
  157. };
  158. static int cx24108_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
  159. {
  160. u32 freq = params->frequency;
  161. int i, a, n, pump;
  162. u32 band, pll;
  163. u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000,
  164. 1576000,1718000,1856000,2036000,2150000};
  165. u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000,
  166. 0x00102000,0x00104000,0x00108000,0x00110000,
  167. 0x00120000,0x00140000};
  168. #define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */
  169. printk("cx24108 debug: entering SetTunerFreq, freq=%d\n",freq);
  170. /* This is really the bit driving the tuner chip cx24108 */
  171. if (freq<950000)
  172. freq = 950000; /* kHz */
  173. else if (freq>2150000)
  174. freq = 2150000; /* satellite IF is 950..2150MHz */
  175. /* decide which VCO to use for the input frequency */
  176. for(i = 1; (i < ARRAY_SIZE(osci) - 1) && (osci[i] < freq); i++);
  177. printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq);
  178. band=bandsel[i];
  179. /* the gain values must be set by SetSymbolrate */
  180. /* compute the pll divider needed, from Conexant data sheet,
  181. resolved for (n*32+a), remember f(vco) is f(receive) *2 or *4,
  182. depending on the divider bit. It is set to /4 on the 2 lowest
  183. bands */
  184. n=((i<=2?2:1)*freq*10L)/(XTAL/100);
  185. a=n%32; n/=32; if(a==0) n--;
  186. pump=(freq<(osci[i-1]+osci[i])/2);
  187. pll=0xf8000000|
  188. ((pump?1:2)<<(14+11))|
  189. ((n&0x1ff)<<(5+11))|
  190. ((a&0x1f)<<11);
  191. /* everything is shifted left 11 bits to left-align the bits in the
  192. 32bit word. Output to the tuner goes MSB-aligned, after all */
  193. printk("cx24108 debug: pump=%d, n=%d, a=%d\n",pump,n,a);
  194. cx24110_pll_write(fe,band);
  195. /* set vga and vca to their widest-band settings, as a precaution.
  196. SetSymbolrate might not be called to set this up */
  197. cx24110_pll_write(fe,0x500c0000);
  198. cx24110_pll_write(fe,0x83f1f800);
  199. cx24110_pll_write(fe,pll);
  200. //writereg(client,0x56,0x7f);
  201. return 0;
  202. }
  203. static int pinnsat_tuner_init(struct dvb_frontend* fe)
  204. {
  205. struct dvb_bt8xx_card *card = fe->dvb->priv;
  206. bttv_gpio_enable(card->bttv_nr, 1, 1); /* output */
  207. bttv_write_gpio(card->bttv_nr, 1, 1); /* relay on */
  208. return 0;
  209. }
  210. static int pinnsat_tuner_sleep(struct dvb_frontend* fe)
  211. {
  212. struct dvb_bt8xx_card *card = fe->dvb->priv;
  213. bttv_write_gpio(card->bttv_nr, 1, 0); /* relay off */
  214. return 0;
  215. }
  216. static struct cx24110_config pctvsat_config = {
  217. .demod_address = 0x55,
  218. };
  219. static int microtune_mt7202dtf_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
  220. {
  221. struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv;
  222. u8 cfg, cpump, band_select;
  223. u8 data[4];
  224. u32 div;
  225. struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = data, .len = sizeof(data) };
  226. div = (36000000 + params->frequency + 83333) / 166666;
  227. cfg = 0x88;
  228. if (params->frequency < 175000000)
  229. cpump = 2;
  230. else if (params->frequency < 390000000)
  231. cpump = 1;
  232. else if (params->frequency < 470000000)
  233. cpump = 2;
  234. else if (params->frequency < 750000000)
  235. cpump = 2;
  236. else
  237. cpump = 3;
  238. if (params->frequency < 175000000)
  239. band_select = 0x0e;
  240. else if (params->frequency < 470000000)
  241. band_select = 0x05;
  242. else
  243. band_select = 0x03;
  244. data[0] = (div >> 8) & 0x7f;
  245. data[1] = div & 0xff;
  246. data[2] = ((div >> 10) & 0x60) | cfg;
  247. data[3] = (cpump << 6) | band_select;
  248. if (fe->ops.i2c_gate_ctrl)
  249. fe->ops.i2c_gate_ctrl(fe, 1);
  250. i2c_transfer(card->i2c_adapter, &msg, 1);
  251. return (div * 166666 - 36000000);
  252. }
  253. static int microtune_mt7202dtf_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
  254. {
  255. struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv;
  256. return request_firmware(fw, name, &bt->bt->dev->dev);
  257. }
  258. static struct sp887x_config microtune_mt7202dtf_config = {
  259. .demod_address = 0x70,
  260. .request_firmware = microtune_mt7202dtf_request_firmware,
  261. };
  262. static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe)
  263. {
  264. static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d };
  265. static u8 mt352_reset [] = { 0x50, 0x80 };
  266. static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  267. static u8 mt352_agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
  268. 0x00, 0xFF, 0x00, 0x40, 0x40 };
  269. static u8 mt352_av771_extra[] = { 0xB5, 0x7A };
  270. static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
  271. mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
  272. udelay(2000);
  273. mt352_write(fe, mt352_reset, sizeof(mt352_reset));
  274. mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
  275. mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg));
  276. udelay(2000);
  277. mt352_write(fe, mt352_av771_extra,sizeof(mt352_av771_extra));
  278. mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
  279. return 0;
  280. }
  281. static int advbt771_samsung_tdtc9251dh0_tuner_calc_regs(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf, int buf_len)
  282. {
  283. u32 div;
  284. unsigned char bs = 0;
  285. unsigned char cp = 0;
  286. if (buf_len < 5) return -EINVAL;
  287. div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
  288. if (params->frequency < 150000000)
  289. cp = 0xB4;
  290. else if (params->frequency < 173000000)
  291. cp = 0xBC;
  292. else if (params->frequency < 250000000)
  293. cp = 0xB4;
  294. else if (params->frequency < 400000000)
  295. cp = 0xBC;
  296. else if (params->frequency < 420000000)
  297. cp = 0xF4;
  298. else if (params->frequency < 470000000)
  299. cp = 0xFC;
  300. else if (params->frequency < 600000000)
  301. cp = 0xBC;
  302. else if (params->frequency < 730000000)
  303. cp = 0xF4;
  304. else
  305. cp = 0xFC;
  306. if (params->frequency < 150000000)
  307. bs = 0x01;
  308. else if (params->frequency < 173000000)
  309. bs = 0x01;
  310. else if (params->frequency < 250000000)
  311. bs = 0x02;
  312. else if (params->frequency < 400000000)
  313. bs = 0x02;
  314. else if (params->frequency < 420000000)
  315. bs = 0x02;
  316. else if (params->frequency < 470000000)
  317. bs = 0x02;
  318. else if (params->frequency < 600000000)
  319. bs = 0x08;
  320. else if (params->frequency < 730000000)
  321. bs = 0x08;
  322. else
  323. bs = 0x08;
  324. pllbuf[0] = 0x61;
  325. pllbuf[1] = div >> 8;
  326. pllbuf[2] = div & 0xff;
  327. pllbuf[3] = cp;
  328. pllbuf[4] = bs;
  329. return 5;
  330. }
  331. static struct mt352_config advbt771_samsung_tdtc9251dh0_config = {
  332. .demod_address = 0x0f,
  333. .demod_init = advbt771_samsung_tdtc9251dh0_demod_init,
  334. };
  335. static struct dst_config dst_config = {
  336. .demod_address = 0x55,
  337. };
  338. static int or51211_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
  339. {
  340. struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv;
  341. return request_firmware(fw, name, &bt->bt->dev->dev);
  342. }
  343. static void or51211_setmode(struct dvb_frontend * fe, int mode)
  344. {
  345. struct dvb_bt8xx_card *bt = fe->dvb->priv;
  346. bttv_write_gpio(bt->bttv_nr, 0x0002, mode); /* Reset */
  347. msleep(20);
  348. }
  349. static void or51211_reset(struct dvb_frontend * fe)
  350. {
  351. struct dvb_bt8xx_card *bt = fe->dvb->priv;
  352. /* RESET DEVICE
  353. * reset is controlled by GPIO-0
  354. * when set to 0 causes reset and when to 1 for normal op
  355. * must remain reset for 128 clock cycles on a 50Mhz clock
  356. * also PRM1 PRM2 & PRM4 are controlled by GPIO-1,GPIO-2 & GPIO-4
  357. * We assume that the reset has be held low long enough or we
  358. * have been reset by a power on. When the driver is unloaded
  359. * reset set to 0 so if reloaded we have been reset.
  360. */
  361. /* reset & PRM1,2&4 are outputs */
  362. int ret = bttv_gpio_enable(bt->bttv_nr, 0x001F, 0x001F);
  363. if (ret != 0)
  364. printk(KERN_WARNING "or51211: Init Error - Can't Reset DVR (%i)\n", ret);
  365. bttv_write_gpio(bt->bttv_nr, 0x001F, 0x0000); /* Reset */
  366. msleep(20);
  367. /* Now set for normal operation */
  368. bttv_write_gpio(bt->bttv_nr, 0x0001F, 0x0001);
  369. /* wait for operation to begin */
  370. msleep(500);
  371. }
  372. static void or51211_sleep(struct dvb_frontend * fe)
  373. {
  374. struct dvb_bt8xx_card *bt = fe->dvb->priv;
  375. bttv_write_gpio(bt->bttv_nr, 0x0001, 0x0000);
  376. }
  377. static struct or51211_config or51211_config = {
  378. .demod_address = 0x15,
  379. .request_firmware = or51211_request_firmware,
  380. .setmode = or51211_setmode,
  381. .reset = or51211_reset,
  382. .sleep = or51211_sleep,
  383. };
  384. static int vp3021_alps_tded4_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
  385. {
  386. struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv;
  387. u8 buf[4];
  388. u32 div;
  389. struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf) };
  390. div = (params->frequency + 36166667) / 166667;
  391. buf[0] = (div >> 8) & 0x7F;
  392. buf[1] = div & 0xFF;
  393. buf[2] = 0x85;
  394. if ((params->frequency >= 47000000) && (params->frequency < 153000000))
  395. buf[3] = 0x01;
  396. else if ((params->frequency >= 153000000) && (params->frequency < 430000000))
  397. buf[3] = 0x02;
  398. else if ((params->frequency >= 430000000) && (params->frequency < 824000000))
  399. buf[3] = 0x0C;
  400. else if ((params->frequency >= 824000000) && (params->frequency < 863000000))
  401. buf[3] = 0x8C;
  402. else
  403. return -EINVAL;
  404. if (fe->ops.i2c_gate_ctrl)
  405. fe->ops.i2c_gate_ctrl(fe, 1);
  406. i2c_transfer(card->i2c_adapter, &msg, 1);
  407. return 0;
  408. }
  409. static struct nxt6000_config vp3021_alps_tded4_config = {
  410. .demod_address = 0x0a,
  411. .clock_inversion = 1,
  412. };
  413. static int digitv_alps_tded4_demod_init(struct dvb_frontend* fe)
  414. {
  415. static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d };
  416. static u8 mt352_reset [] = { 0x50, 0x80 };
  417. static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  418. static u8 mt352_agc_cfg [] = { 0x67, 0x20, 0xa0 };
  419. static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
  420. mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
  421. udelay(2000);
  422. mt352_write(fe, mt352_reset, sizeof(mt352_reset));
  423. mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
  424. mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg));
  425. mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg));
  426. return 0;
  427. }
  428. static int digitv_alps_tded4_tuner_calc_regs(struct dvb_frontend* fe, struct dvb_frontend_parameters* params, u8* pllbuf, int buf_len)
  429. {
  430. u32 div;
  431. struct dvb_ofdm_parameters *op = &params->u.ofdm;
  432. if (buf_len < 5)
  433. return -EINVAL;
  434. div = (((params->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6;
  435. pllbuf[0] = 0x61;
  436. pllbuf[1] = (div >> 8) & 0x7F;
  437. pllbuf[2] = div & 0xFF;
  438. pllbuf[3] = 0x85;
  439. dprintk("frequency %u, div %u\n", params->frequency, div);
  440. if (params->frequency < 470000000)
  441. pllbuf[4] = 0x02;
  442. else if (params->frequency > 823000000)
  443. pllbuf[4] = 0x88;
  444. else
  445. pllbuf[4] = 0x08;
  446. if (op->bandwidth == 8)
  447. pllbuf[4] |= 0x04;
  448. return 5;
  449. }
  450. static void digitv_alps_tded4_reset(struct dvb_bt8xx_card *bt)
  451. {
  452. /*
  453. * Reset the frontend, must be called before trying
  454. * to initialise the MT352 or mt352_attach
  455. * will fail. Same goes for the nxt6000 frontend.
  456. *
  457. */
  458. int ret = bttv_gpio_enable(bt->bttv_nr, 0x08, 0x08);
  459. if (ret != 0)
  460. printk(KERN_WARNING "digitv_alps_tded4: Init Error - Can't Reset DVR (%i)\n", ret);
  461. /* Pulse the reset line */
  462. bttv_write_gpio(bt->bttv_nr, 0x08, 0x08); /* High */
  463. bttv_write_gpio(bt->bttv_nr, 0x08, 0x00); /* Low */
  464. msleep(100);
  465. bttv_write_gpio(bt->bttv_nr, 0x08, 0x08); /* High */
  466. }
  467. static struct mt352_config digitv_alps_tded4_config = {
  468. .demod_address = 0x0a,
  469. .demod_init = digitv_alps_tded4_demod_init,
  470. };
  471. static struct lgdt330x_config tdvs_tua6034_config = {
  472. .demod_address = 0x0e,
  473. .demod_chip = LGDT3303,
  474. .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
  475. };
  476. static void lgdt330x_reset(struct dvb_bt8xx_card *bt)
  477. {
  478. /* Set pin 27 of the lgdt3303 chip high to reset the frontend */
  479. /* Pulse the reset line */
  480. bttv_write_gpio(bt->bttv_nr, 0x00e00007, 0x00000001); /* High */
  481. bttv_write_gpio(bt->bttv_nr, 0x00e00007, 0x00000000); /* Low */
  482. msleep(100);
  483. bttv_write_gpio(bt->bttv_nr, 0x00e00007, 0x00000001); /* High */
  484. msleep(100);
  485. }
  486. static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
  487. {
  488. struct dst_state* state = NULL;
  489. switch(type) {
  490. case BTTV_BOARD_DVICO_DVBT_LITE:
  491. card->fe = dvb_attach(mt352_attach, &thomson_dtt7579_config, card->i2c_adapter);
  492. if (card->fe == NULL)
  493. card->fe = dvb_attach(zl10353_attach, &thomson_dtt7579_zl10353_config,
  494. card->i2c_adapter);
  495. if (card->fe != NULL) {
  496. card->fe->ops.tuner_ops.calc_regs = thomson_dtt7579_tuner_calc_regs;
  497. card->fe->ops.info.frequency_min = 174000000;
  498. card->fe->ops.info.frequency_max = 862000000;
  499. }
  500. break;
  501. case BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE:
  502. lgdt330x_reset(card);
  503. card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, card->i2c_adapter);
  504. if (card->fe != NULL) {
  505. dvb_attach(simple_tuner_attach, card->fe,
  506. card->i2c_adapter, 0x61,
  507. TUNER_LG_TDVS_H06XF);
  508. dprintk ("dvb_bt8xx: lgdt330x detected\n");
  509. }
  510. break;
  511. case BTTV_BOARD_NEBULA_DIGITV:
  512. /*
  513. * It is possible to determine the correct frontend using the I2C bus (see the Nebula SDK);
  514. * this would be a cleaner solution than trying each frontend in turn.
  515. */
  516. /* Old Nebula (marked (c)2003 on high profile pci card) has nxt6000 demod */
  517. digitv_alps_tded4_reset(card);
  518. card->fe = dvb_attach(nxt6000_attach, &vp3021_alps_tded4_config, card->i2c_adapter);
  519. if (card->fe != NULL) {
  520. card->fe->ops.tuner_ops.set_params = vp3021_alps_tded4_tuner_set_params;
  521. dprintk ("dvb_bt8xx: an nxt6000 was detected on your digitv card\n");
  522. break;
  523. }
  524. /* New Nebula (marked (c)2005 on low profile pci card) has mt352 demod */
  525. digitv_alps_tded4_reset(card);
  526. card->fe = dvb_attach(mt352_attach, &digitv_alps_tded4_config, card->i2c_adapter);
  527. if (card->fe != NULL) {
  528. card->fe->ops.tuner_ops.calc_regs = digitv_alps_tded4_tuner_calc_regs;
  529. dprintk ("dvb_bt8xx: an mt352 was detected on your digitv card\n");
  530. }
  531. break;
  532. case BTTV_BOARD_AVDVBT_761:
  533. card->fe = dvb_attach(sp887x_attach, &microtune_mt7202dtf_config, card->i2c_adapter);
  534. if (card->fe) {
  535. card->fe->ops.tuner_ops.set_params = microtune_mt7202dtf_tuner_set_params;
  536. }
  537. break;
  538. case BTTV_BOARD_AVDVBT_771:
  539. card->fe = dvb_attach(mt352_attach, &advbt771_samsung_tdtc9251dh0_config, card->i2c_adapter);
  540. if (card->fe != NULL) {
  541. card->fe->ops.tuner_ops.calc_regs = advbt771_samsung_tdtc9251dh0_tuner_calc_regs;
  542. card->fe->ops.info.frequency_min = 174000000;
  543. card->fe->ops.info.frequency_max = 862000000;
  544. }
  545. break;
  546. case BTTV_BOARD_TWINHAN_DST:
  547. /* DST is not a frontend driver !!! */
  548. state = kmalloc(sizeof (struct dst_state), GFP_KERNEL);
  549. if (!state) {
  550. printk("dvb_bt8xx: No memory\n");
  551. break;
  552. }
  553. /* Setup the Card */
  554. state->config = &dst_config;
  555. state->i2c = card->i2c_adapter;
  556. state->bt = card->bt;
  557. state->dst_ca = NULL;
  558. /* DST is not a frontend, attaching the ASIC */
  559. if (dvb_attach(dst_attach, state, &card->dvb_adapter) == NULL) {
  560. printk("%s: Could not find a Twinhan DST.\n", __func__);
  561. break;
  562. }
  563. /* Attach other DST peripherals if any */
  564. /* Conditional Access device */
  565. card->fe = &state->frontend;
  566. if (state->dst_hw_cap & DST_TYPE_HAS_CA)
  567. dvb_attach(dst_ca_attach, state, &card->dvb_adapter);
  568. break;
  569. case BTTV_BOARD_PINNACLESAT:
  570. card->fe = dvb_attach(cx24110_attach, &pctvsat_config, card->i2c_adapter);
  571. if (card->fe) {
  572. card->fe->ops.tuner_ops.init = pinnsat_tuner_init;
  573. card->fe->ops.tuner_ops.sleep = pinnsat_tuner_sleep;
  574. card->fe->ops.tuner_ops.set_params = cx24108_tuner_set_params;
  575. }
  576. break;
  577. case BTTV_BOARD_PC_HDTV:
  578. card->fe = dvb_attach(or51211_attach, &or51211_config, card->i2c_adapter);
  579. if (card->fe != NULL)
  580. dvb_attach(simple_tuner_attach, card->fe,
  581. card->i2c_adapter, 0x61,
  582. TUNER_PHILIPS_FCV1236D);
  583. break;
  584. }
  585. if (card->fe == NULL)
  586. printk("dvb-bt8xx: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
  587. card->bt->dev->vendor,
  588. card->bt->dev->device,
  589. card->bt->dev->subsystem_vendor,
  590. card->bt->dev->subsystem_device);
  591. else
  592. if (dvb_register_frontend(&card->dvb_adapter, card->fe)) {
  593. printk("dvb-bt8xx: Frontend registration failed!\n");
  594. dvb_frontend_detach(card->fe);
  595. card->fe = NULL;
  596. }
  597. }
  598. static int __devinit dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
  599. {
  600. int result;
  601. result = dvb_register_adapter(&card->dvb_adapter, card->card_name,
  602. THIS_MODULE, &card->bt->dev->dev,
  603. adapter_nr);
  604. if (result < 0) {
  605. printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result);
  606. return result;
  607. }
  608. card->dvb_adapter.priv = card;
  609. card->bt->adapter = card->i2c_adapter;
  610. memset(&card->demux, 0, sizeof(struct dvb_demux));
  611. card->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING;
  612. card->demux.priv = card;
  613. card->demux.filternum = 256;
  614. card->demux.feednum = 256;
  615. card->demux.start_feed = dvb_bt8xx_start_feed;
  616. card->demux.stop_feed = dvb_bt8xx_stop_feed;
  617. card->demux.write_to_decoder = NULL;
  618. if ((result = dvb_dmx_init(&card->demux)) < 0) {
  619. printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
  620. dvb_unregister_adapter(&card->dvb_adapter);
  621. return result;
  622. }
  623. card->dmxdev.filternum = 256;
  624. card->dmxdev.demux = &card->demux.dmx;
  625. card->dmxdev.capabilities = 0;
  626. if ((result = dvb_dmxdev_init(&card->dmxdev, &card->dvb_adapter)) < 0) {
  627. printk("dvb_bt8xx: dvb_dmxdev_init failed (errno = %d)\n", result);
  628. dvb_dmx_release(&card->demux);
  629. dvb_unregister_adapter(&card->dvb_adapter);
  630. return result;
  631. }
  632. card->fe_hw.source = DMX_FRONTEND_0;
  633. if ((result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_hw)) < 0) {
  634. printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
  635. dvb_dmxdev_release(&card->dmxdev);
  636. dvb_dmx_release(&card->demux);
  637. dvb_unregister_adapter(&card->dvb_adapter);
  638. return result;
  639. }
  640. card->fe_mem.source = DMX_MEMORY_FE;
  641. if ((result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_mem)) < 0) {
  642. printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
  643. card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
  644. dvb_dmxdev_release(&card->dmxdev);
  645. dvb_dmx_release(&card->demux);
  646. dvb_unregister_adapter(&card->dvb_adapter);
  647. return result;
  648. }
  649. if ((result = card->demux.dmx.connect_frontend(&card->demux.dmx, &card->fe_hw)) < 0) {
  650. printk("dvb_bt8xx: dvb_dmx_init failed (errno = %d)\n", result);
  651. card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem);
  652. card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
  653. dvb_dmxdev_release(&card->dmxdev);
  654. dvb_dmx_release(&card->demux);
  655. dvb_unregister_adapter(&card->dvb_adapter);
  656. return result;
  657. }
  658. dvb_net_init(&card->dvb_adapter, &card->dvbnet, &card->demux.dmx);
  659. tasklet_init(&card->bt->tasklet, dvb_bt8xx_task, (unsigned long) card);
  660. frontend_init(card, type);
  661. return 0;
  662. }
  663. static int __devinit dvb_bt8xx_probe(struct bttv_sub_device *sub)
  664. {
  665. struct dvb_bt8xx_card *card;
  666. struct pci_dev* bttv_pci_dev;
  667. int ret;
  668. if (!(card = kzalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL)))
  669. return -ENOMEM;
  670. mutex_init(&card->lock);
  671. card->bttv_nr = sub->core->nr;
  672. strlcpy(card->card_name, sub->core->v4l2_dev.name, sizeof(card->card_name));
  673. card->i2c_adapter = &sub->core->i2c_adap;
  674. switch(sub->core->type) {
  675. case BTTV_BOARD_PINNACLESAT:
  676. card->gpio_mode = 0x0400c060;
  677. /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR,
  678. BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */
  679. card->op_sync_orin = BT878_RISC_SYNC_MASK;
  680. card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
  681. break;
  682. case BTTV_BOARD_DVICO_DVBT_LITE:
  683. card->gpio_mode = 0x0400C060;
  684. card->op_sync_orin = BT878_RISC_SYNC_MASK;
  685. card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
  686. /* 26, 15, 14, 6, 5
  687. * A_PWRDN DA_DPM DA_SBR DA_IOM_DA
  688. * DA_APP(parallel) */
  689. break;
  690. case BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE:
  691. card->gpio_mode = 0x0400c060;
  692. card->op_sync_orin = BT878_RISC_SYNC_MASK;
  693. card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
  694. break;
  695. case BTTV_BOARD_NEBULA_DIGITV:
  696. case BTTV_BOARD_AVDVBT_761:
  697. card->gpio_mode = (1 << 26) | (1 << 14) | (1 << 5);
  698. card->op_sync_orin = BT878_RISC_SYNC_MASK;
  699. card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
  700. /* A_PWRDN DA_SBR DA_APP (high speed serial) */
  701. break;
  702. case BTTV_BOARD_AVDVBT_771: //case 0x07711461:
  703. card->gpio_mode = 0x0400402B;
  704. card->op_sync_orin = BT878_RISC_SYNC_MASK;
  705. card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
  706. /* A_PWRDN DA_SBR DA_APP[0] PKTP=10 RISC_ENABLE FIFO_ENABLE*/
  707. break;
  708. case BTTV_BOARD_TWINHAN_DST:
  709. card->gpio_mode = 0x2204f2c;
  710. card->op_sync_orin = BT878_RISC_SYNC_MASK;
  711. card->irq_err_ignore = BT878_APABORT | BT878_ARIPERR |
  712. BT878_APPERR | BT878_AFBUS;
  713. /* 25,21,14,11,10,9,8,3,2 then
  714. * 0x33 = 5,4,1,0
  715. * A_SEL=SML, DA_MLB, DA_SBR,
  716. * DA_SDR=f, fifo trigger = 32 DWORDS
  717. * IOM = 0 == audio A/D
  718. * DPM = 0 == digital audio mode
  719. * == async data parallel port
  720. * then 0x33 (13 is set by start_capture)
  721. * DA_APP = async data parallel port,
  722. * ACAP_EN = 1,
  723. * RISC+FIFO ENABLE */
  724. break;
  725. case BTTV_BOARD_PC_HDTV:
  726. card->gpio_mode = 0x0100EC7B;
  727. card->op_sync_orin = BT878_RISC_SYNC_MASK;
  728. card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR;
  729. break;
  730. default:
  731. printk(KERN_WARNING "dvb_bt8xx: Unknown bttv card type: %d.\n",
  732. sub->core->type);
  733. kfree(card);
  734. return -ENODEV;
  735. }
  736. dprintk("dvb_bt8xx: identified card%d as %s\n", card->bttv_nr, card->card_name);
  737. if (!(bttv_pci_dev = bttv_get_pcidev(card->bttv_nr))) {
  738. printk("dvb_bt8xx: no pci device for card %d\n", card->bttv_nr);
  739. kfree(card);
  740. return -EFAULT;
  741. }
  742. if (!(card->bt = dvb_bt8xx_878_match(card->bttv_nr, bttv_pci_dev))) {
  743. printk("dvb_bt8xx: unable to determine DMA core of card %d,\n",
  744. card->bttv_nr);
  745. printk("dvb_bt8xx: if you have the ALSA bt87x audio driver "
  746. "installed, try removing it.\n");
  747. kfree(card);
  748. return -EFAULT;
  749. }
  750. mutex_init(&card->bt->gpio_lock);
  751. card->bt->bttv_nr = sub->core->nr;
  752. if ( (ret = dvb_bt8xx_load_card(card, sub->core->type)) ) {
  753. kfree(card);
  754. return ret;
  755. }
  756. dev_set_drvdata(&sub->dev, card);
  757. return 0;
  758. }
  759. static void dvb_bt8xx_remove(struct bttv_sub_device *sub)
  760. {
  761. struct dvb_bt8xx_card *card = dev_get_drvdata(&sub->dev);
  762. dprintk("dvb_bt8xx: unloading card%d\n", card->bttv_nr);
  763. bt878_stop(card->bt);
  764. tasklet_kill(&card->bt->tasklet);
  765. dvb_net_release(&card->dvbnet);
  766. card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem);
  767. card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw);
  768. dvb_dmxdev_release(&card->dmxdev);
  769. dvb_dmx_release(&card->demux);
  770. if (card->fe) {
  771. dvb_unregister_frontend(card->fe);
  772. dvb_frontend_detach(card->fe);
  773. }
  774. dvb_unregister_adapter(&card->dvb_adapter);
  775. kfree(card);
  776. }
  777. static struct bttv_sub_driver driver = {
  778. .drv = {
  779. .name = "dvb-bt8xx",
  780. },
  781. .probe = dvb_bt8xx_probe,
  782. .remove = dvb_bt8xx_remove,
  783. /* FIXME:
  784. * .shutdown = dvb_bt8xx_shutdown,
  785. * .suspend = dvb_bt8xx_suspend,
  786. * .resume = dvb_bt8xx_resume,
  787. */
  788. };
  789. static int __init dvb_bt8xx_init(void)
  790. {
  791. return bttv_sub_register(&driver, "dvb");
  792. }
  793. static void __exit dvb_bt8xx_exit(void)
  794. {
  795. bttv_sub_unregister(&driver);
  796. }
  797. module_init(dvb_bt8xx_init);
  798. module_exit(dvb_bt8xx_exit);
  799. MODULE_DESCRIPTION("Bt8xx based DVB adapter driver");
  800. MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>");
  801. MODULE_LICENSE("GPL");