dvb-bt8xx.c 27 KB

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