cx88-dvb.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  1. /*
  2. *
  3. * device driver for Conexant 2388x based TV cards
  4. * MPEG Transport Stream (DVB) routines
  5. *
  6. * (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
  7. * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/device.h>
  26. #include <linux/fs.h>
  27. #include <linux/kthread.h>
  28. #include <linux/file.h>
  29. #include <linux/suspend.h>
  30. #include "cx88.h"
  31. #include "dvb-pll.h"
  32. #include <media/v4l2-common.h>
  33. #include "mt352.h"
  34. #include "mt352_priv.h"
  35. #include "cx88-vp3054-i2c.h"
  36. #include "zl10353.h"
  37. #include "cx22702.h"
  38. #include "or51132.h"
  39. #include "lgdt330x.h"
  40. #include "s5h1409.h"
  41. #include "xc5000.h"
  42. #include "nxt200x.h"
  43. #include "cx24123.h"
  44. #include "isl6421.h"
  45. #include "tuner-simple.h"
  46. #include "tda9887.h"
  47. #include "s5h1411.h"
  48. #include "stv0299.h"
  49. #include "z0194a.h"
  50. #include "stv0288.h"
  51. #include "stb6000.h"
  52. #include "cx24116.h"
  53. MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
  54. MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
  55. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  56. MODULE_LICENSE("GPL");
  57. static unsigned int debug;
  58. module_param(debug, int, 0644);
  59. MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
  60. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  61. #define dprintk(level,fmt, arg...) if (debug >= level) \
  62. printk(KERN_DEBUG "%s/2-dvb: " fmt, core->name, ## arg)
  63. /* ------------------------------------------------------------------ */
  64. static int dvb_buf_setup(struct videobuf_queue *q,
  65. unsigned int *count, unsigned int *size)
  66. {
  67. struct cx8802_dev *dev = q->priv_data;
  68. dev->ts_packet_size = 188 * 4;
  69. dev->ts_packet_count = 32;
  70. *size = dev->ts_packet_size * dev->ts_packet_count;
  71. *count = 32;
  72. return 0;
  73. }
  74. static int dvb_buf_prepare(struct videobuf_queue *q,
  75. struct videobuf_buffer *vb, enum v4l2_field field)
  76. {
  77. struct cx8802_dev *dev = q->priv_data;
  78. return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field);
  79. }
  80. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  81. {
  82. struct cx8802_dev *dev = q->priv_data;
  83. cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
  84. }
  85. static void dvb_buf_release(struct videobuf_queue *q,
  86. struct videobuf_buffer *vb)
  87. {
  88. cx88_free_buffer(q, (struct cx88_buffer*)vb);
  89. }
  90. static struct videobuf_queue_ops dvb_qops = {
  91. .buf_setup = dvb_buf_setup,
  92. .buf_prepare = dvb_buf_prepare,
  93. .buf_queue = dvb_buf_queue,
  94. .buf_release = dvb_buf_release,
  95. };
  96. /* ------------------------------------------------------------------ */
  97. static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire)
  98. {
  99. struct cx8802_dev *dev= fe->dvb->priv;
  100. struct cx8802_driver *drv = NULL;
  101. int ret = 0;
  102. int fe_id;
  103. fe_id = videobuf_dvb_find_frontend(&dev->frontends, fe);
  104. if (!fe_id) {
  105. printk(KERN_ERR "%s() No frontend found\n", __func__);
  106. return -EINVAL;
  107. }
  108. drv = cx8802_get_driver(dev, CX88_MPEG_DVB);
  109. if (drv) {
  110. if (acquire){
  111. dev->frontends.active_fe_id = fe_id;
  112. ret = drv->request_acquire(drv);
  113. } else {
  114. ret = drv->request_release(drv);
  115. dev->frontends.active_fe_id = 0;
  116. }
  117. }
  118. return ret;
  119. }
  120. static void cx88_dvb_gate_ctrl(struct cx88_core *core, int open)
  121. {
  122. struct videobuf_dvb_frontends *f;
  123. struct videobuf_dvb_frontend *fe;
  124. if (!core->dvbdev)
  125. return;
  126. f = &core->dvbdev->frontends;
  127. if (!f)
  128. return;
  129. if (f->gate <= 1) /* undefined or fe0 */
  130. fe = videobuf_dvb_get_frontend(f, 1);
  131. else
  132. fe = videobuf_dvb_get_frontend(f, f->gate);
  133. if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)
  134. fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);
  135. }
  136. /* ------------------------------------------------------------------ */
  137. static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
  138. {
  139. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
  140. static u8 reset [] = { RESET, 0x80 };
  141. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  142. static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
  143. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  144. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  145. mt352_write(fe, clock_config, sizeof(clock_config));
  146. udelay(200);
  147. mt352_write(fe, reset, sizeof(reset));
  148. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  149. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  150. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  151. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  152. return 0;
  153. }
  154. static int dvico_dual_demod_init(struct dvb_frontend *fe)
  155. {
  156. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x38 };
  157. static u8 reset [] = { RESET, 0x80 };
  158. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  159. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };
  160. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  161. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  162. mt352_write(fe, clock_config, sizeof(clock_config));
  163. udelay(200);
  164. mt352_write(fe, reset, sizeof(reset));
  165. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  166. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  167. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  168. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  169. return 0;
  170. }
  171. static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
  172. {
  173. static u8 clock_config [] = { 0x89, 0x38, 0x39 };
  174. static u8 reset [] = { 0x50, 0x80 };
  175. static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  176. static u8 agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
  177. 0x00, 0xFF, 0x00, 0x40, 0x40 };
  178. static u8 dntv_extra[] = { 0xB5, 0x7A };
  179. static u8 capt_range_cfg[] = { 0x75, 0x32 };
  180. mt352_write(fe, clock_config, sizeof(clock_config));
  181. udelay(2000);
  182. mt352_write(fe, reset, sizeof(reset));
  183. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  184. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  185. udelay(2000);
  186. mt352_write(fe, dntv_extra, sizeof(dntv_extra));
  187. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  188. return 0;
  189. }
  190. static struct mt352_config dvico_fusionhdtv = {
  191. .demod_address = 0x0f,
  192. .demod_init = dvico_fusionhdtv_demod_init,
  193. };
  194. static struct mt352_config dntv_live_dvbt_config = {
  195. .demod_address = 0x0f,
  196. .demod_init = dntv_live_dvbt_demod_init,
  197. };
  198. static struct mt352_config dvico_fusionhdtv_dual = {
  199. .demod_address = 0x0f,
  200. .demod_init = dvico_dual_demod_init,
  201. };
  202. static struct zl10353_config cx88_terratec_cinergy_ht_pci_mkii_config = {
  203. .demod_address = (0x1e >> 1),
  204. .no_tuner = 1,
  205. .if2 = 45600,
  206. };
  207. #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
  208. static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)
  209. {
  210. static u8 clock_config [] = { 0x89, 0x38, 0x38 };
  211. static u8 reset [] = { 0x50, 0x80 };
  212. static u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  213. static u8 agc_cfg [] = { 0x67, 0x10, 0x20, 0x00, 0xFF, 0xFF,
  214. 0x00, 0xFF, 0x00, 0x40, 0x40 };
  215. static u8 dntv_extra[] = { 0xB5, 0x7A };
  216. static u8 capt_range_cfg[] = { 0x75, 0x32 };
  217. mt352_write(fe, clock_config, sizeof(clock_config));
  218. udelay(2000);
  219. mt352_write(fe, reset, sizeof(reset));
  220. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  221. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  222. udelay(2000);
  223. mt352_write(fe, dntv_extra, sizeof(dntv_extra));
  224. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  225. return 0;
  226. }
  227. static struct mt352_config dntv_live_dvbt_pro_config = {
  228. .demod_address = 0x0f,
  229. .no_tuner = 1,
  230. .demod_init = dntv_live_dvbt_pro_demod_init,
  231. };
  232. #endif
  233. static struct zl10353_config dvico_fusionhdtv_hybrid = {
  234. .demod_address = 0x0f,
  235. .no_tuner = 1,
  236. };
  237. static struct zl10353_config dvico_fusionhdtv_xc3028 = {
  238. .demod_address = 0x0f,
  239. .if2 = 45600,
  240. .no_tuner = 1,
  241. };
  242. static struct mt352_config dvico_fusionhdtv_mt352_xc3028 = {
  243. .demod_address = 0x0f,
  244. .if2 = 4560,
  245. .no_tuner = 1,
  246. .demod_init = dvico_fusionhdtv_demod_init,
  247. };
  248. static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
  249. .demod_address = 0x0f,
  250. };
  251. static struct cx22702_config connexant_refboard_config = {
  252. .demod_address = 0x43,
  253. .output_mode = CX22702_SERIAL_OUTPUT,
  254. };
  255. static struct cx22702_config hauppauge_hvr_config = {
  256. .demod_address = 0x63,
  257. .output_mode = CX22702_SERIAL_OUTPUT,
  258. };
  259. static int or51132_set_ts_param(struct dvb_frontend* fe, int is_punctured)
  260. {
  261. struct cx8802_dev *dev= fe->dvb->priv;
  262. dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
  263. return 0;
  264. }
  265. static struct or51132_config pchdtv_hd3000 = {
  266. .demod_address = 0x15,
  267. .set_ts_params = or51132_set_ts_param,
  268. };
  269. static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
  270. {
  271. struct cx8802_dev *dev= fe->dvb->priv;
  272. struct cx88_core *core = dev->core;
  273. dprintk(1, "%s: index = %d\n", __func__, index);
  274. if (index == 0)
  275. cx_clear(MO_GP0_IO, 8);
  276. else
  277. cx_set(MO_GP0_IO, 8);
  278. return 0;
  279. }
  280. static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
  281. {
  282. struct cx8802_dev *dev= fe->dvb->priv;
  283. if (is_punctured)
  284. dev->ts_gen_cntrl |= 0x04;
  285. else
  286. dev->ts_gen_cntrl &= ~0x04;
  287. return 0;
  288. }
  289. static struct lgdt330x_config fusionhdtv_3_gold = {
  290. .demod_address = 0x0e,
  291. .demod_chip = LGDT3302,
  292. .serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
  293. .set_ts_params = lgdt330x_set_ts_param,
  294. };
  295. static struct lgdt330x_config fusionhdtv_5_gold = {
  296. .demod_address = 0x0e,
  297. .demod_chip = LGDT3303,
  298. .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
  299. .set_ts_params = lgdt330x_set_ts_param,
  300. };
  301. static struct lgdt330x_config pchdtv_hd5500 = {
  302. .demod_address = 0x59,
  303. .demod_chip = LGDT3303,
  304. .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
  305. .set_ts_params = lgdt330x_set_ts_param,
  306. };
  307. static int nxt200x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
  308. {
  309. struct cx8802_dev *dev= fe->dvb->priv;
  310. dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
  311. return 0;
  312. }
  313. static struct nxt200x_config ati_hdtvwonder = {
  314. .demod_address = 0x0a,
  315. .set_ts_params = nxt200x_set_ts_param,
  316. };
  317. static int cx24123_set_ts_param(struct dvb_frontend* fe,
  318. int is_punctured)
  319. {
  320. struct cx8802_dev *dev= fe->dvb->priv;
  321. dev->ts_gen_cntrl = 0x02;
  322. return 0;
  323. }
  324. static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
  325. fe_sec_voltage_t voltage)
  326. {
  327. struct cx8802_dev *dev= fe->dvb->priv;
  328. struct cx88_core *core = dev->core;
  329. if (voltage == SEC_VOLTAGE_OFF)
  330. cx_write(MO_GP0_IO, 0x000006fb);
  331. else
  332. cx_write(MO_GP0_IO, 0x000006f9);
  333. if (core->prev_set_voltage)
  334. return core->prev_set_voltage(fe, voltage);
  335. return 0;
  336. }
  337. static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
  338. fe_sec_voltage_t voltage)
  339. {
  340. struct cx8802_dev *dev= fe->dvb->priv;
  341. struct cx88_core *core = dev->core;
  342. if (voltage == SEC_VOLTAGE_OFF) {
  343. dprintk(1,"LNB Voltage OFF\n");
  344. cx_write(MO_GP0_IO, 0x0000efff);
  345. }
  346. if (core->prev_set_voltage)
  347. return core->prev_set_voltage(fe, voltage);
  348. return 0;
  349. }
  350. static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
  351. fe_sec_voltage_t voltage)
  352. {
  353. struct cx8802_dev *dev= fe->dvb->priv;
  354. struct cx88_core *core = dev->core;
  355. switch (voltage) {
  356. case SEC_VOLTAGE_13:
  357. printk("LNB Voltage SEC_VOLTAGE_13\n");
  358. cx_write(MO_GP0_IO, 0x00006040);
  359. break;
  360. case SEC_VOLTAGE_18:
  361. printk("LNB Voltage SEC_VOLTAGE_18\n");
  362. cx_write(MO_GP0_IO, 0x00006060);
  363. break;
  364. case SEC_VOLTAGE_OFF:
  365. printk("LNB Voltage SEC_VOLTAGE_off\n");
  366. break;
  367. }
  368. if (core->prev_set_voltage)
  369. return core->prev_set_voltage(fe, voltage);
  370. return 0;
  371. }
  372. static struct cx24123_config geniatech_dvbs_config = {
  373. .demod_address = 0x55,
  374. .set_ts_params = cx24123_set_ts_param,
  375. };
  376. static struct cx24123_config hauppauge_novas_config = {
  377. .demod_address = 0x55,
  378. .set_ts_params = cx24123_set_ts_param,
  379. };
  380. static struct cx24123_config kworld_dvbs_100_config = {
  381. .demod_address = 0x15,
  382. .set_ts_params = cx24123_set_ts_param,
  383. .lnb_polarity = 1,
  384. };
  385. static struct s5h1409_config pinnacle_pctv_hd_800i_config = {
  386. .demod_address = 0x32 >> 1,
  387. .output_mode = S5H1409_PARALLEL_OUTPUT,
  388. .gpio = S5H1409_GPIO_ON,
  389. .qam_if = 44000,
  390. .inversion = S5H1409_INVERSION_OFF,
  391. .status_mode = S5H1409_DEMODLOCKING,
  392. .mpeg_timing = S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
  393. };
  394. static struct s5h1409_config dvico_hdtv5_pci_nano_config = {
  395. .demod_address = 0x32 >> 1,
  396. .output_mode = S5H1409_SERIAL_OUTPUT,
  397. .gpio = S5H1409_GPIO_OFF,
  398. .inversion = S5H1409_INVERSION_OFF,
  399. .status_mode = S5H1409_DEMODLOCKING,
  400. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  401. };
  402. static struct s5h1409_config kworld_atsc_120_config = {
  403. .demod_address = 0x32 >> 1,
  404. .output_mode = S5H1409_SERIAL_OUTPUT,
  405. .gpio = S5H1409_GPIO_OFF,
  406. .inversion = S5H1409_INVERSION_OFF,
  407. .status_mode = S5H1409_DEMODLOCKING,
  408. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  409. };
  410. static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {
  411. .i2c_address = 0x64,
  412. .if_khz = 5380,
  413. };
  414. static struct zl10353_config cx88_pinnacle_hybrid_pctv = {
  415. .demod_address = (0x1e >> 1),
  416. .no_tuner = 1,
  417. .if2 = 45600,
  418. };
  419. static struct zl10353_config cx88_geniatech_x8000_mt = {
  420. .demod_address = (0x1e >> 1),
  421. .no_tuner = 1,
  422. };
  423. static struct s5h1411_config dvico_fusionhdtv7_config = {
  424. .output_mode = S5H1411_SERIAL_OUTPUT,
  425. .gpio = S5H1411_GPIO_ON,
  426. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  427. .qam_if = S5H1411_IF_44000,
  428. .vsb_if = S5H1411_IF_44000,
  429. .inversion = S5H1411_INVERSION_OFF,
  430. .status_mode = S5H1411_DEMODLOCKING
  431. };
  432. static struct xc5000_config dvico_fusionhdtv7_tuner_config = {
  433. .i2c_address = 0xc2 >> 1,
  434. .if_khz = 5380,
  435. };
  436. static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
  437. {
  438. struct dvb_frontend *fe;
  439. struct videobuf_dvb_frontend *fe0 = NULL;
  440. struct xc2028_ctrl ctl;
  441. struct xc2028_config cfg = {
  442. .i2c_adap = &dev->core->i2c_adap,
  443. .i2c_addr = addr,
  444. .ctrl = &ctl,
  445. };
  446. /* Get the first frontend */
  447. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  448. if (!fe0)
  449. return -EINVAL;
  450. if (!fe0->dvb.frontend) {
  451. printk(KERN_ERR "%s/2: dvb frontend not attached. "
  452. "Can't attach xc3028\n",
  453. dev->core->name);
  454. return -EINVAL;
  455. }
  456. /*
  457. * Some xc3028 devices may be hidden by an I2C gate. This is known
  458. * to happen with some s5h1409-based devices.
  459. * Now that I2C gate is open, sets up xc3028 configuration
  460. */
  461. cx88_setup_xc3028(dev->core, &ctl);
  462. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
  463. if (!fe) {
  464. printk(KERN_ERR "%s/2: xc3028 attach failed\n",
  465. dev->core->name);
  466. dvb_frontend_detach(fe0->dvb.frontend);
  467. dvb_unregister_frontend(fe0->dvb.frontend);
  468. fe0->dvb.frontend = NULL;
  469. return -EINVAL;
  470. }
  471. printk(KERN_INFO "%s/2: xc3028 attached\n",
  472. dev->core->name);
  473. return 0;
  474. }
  475. static int cx24116_set_ts_param(struct dvb_frontend *fe,
  476. int is_punctured)
  477. {
  478. struct cx8802_dev *dev = fe->dvb->priv;
  479. dev->ts_gen_cntrl = 0x2;
  480. return 0;
  481. }
  482. static int cx24116_reset_device(struct dvb_frontend *fe)
  483. {
  484. struct cx8802_dev *dev = fe->dvb->priv;
  485. struct cx88_core *core = dev->core;
  486. /* Reset the part */
  487. /* Put the cx24116 into reset */
  488. cx_write(MO_SRST_IO, 0);
  489. msleep(10);
  490. /* Take the cx24116 out of reset */
  491. cx_write(MO_SRST_IO, 1);
  492. msleep(10);
  493. return 0;
  494. }
  495. static struct cx24116_config hauppauge_hvr4000_config = {
  496. .demod_address = 0x05,
  497. .set_ts_params = cx24116_set_ts_param,
  498. .reset_device = cx24116_reset_device,
  499. };
  500. static struct cx24116_config tevii_s460_config = {
  501. .demod_address = 0x55,
  502. .set_ts_params = cx24116_set_ts_param,
  503. .reset_device = cx24116_reset_device,
  504. };
  505. static struct stv0299_config tevii_tuner_sharp_config = {
  506. .demod_address = 0x68,
  507. .inittab = sharp_z0194a_inittab,
  508. .mclk = 88000000UL,
  509. .invert = 1,
  510. .skip_reinit = 0,
  511. .lock_output = 1,
  512. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  513. .min_delay_ms = 100,
  514. .set_symbol_rate = sharp_z0194a_set_symbol_rate,
  515. .set_ts_params = cx24116_set_ts_param,
  516. };
  517. static struct stv0288_config tevii_tuner_earda_config = {
  518. .demod_address = 0x68,
  519. .min_delay_ms = 100,
  520. .set_ts_params = cx24116_set_ts_param,
  521. };
  522. static int cx8802_alloc_frontends(struct cx8802_dev *dev)
  523. {
  524. struct cx88_core *core = dev->core;
  525. struct videobuf_dvb_frontend *fe = NULL;
  526. int i;
  527. mutex_init(&dev->frontends.lock);
  528. INIT_LIST_HEAD(&dev->frontends.felist);
  529. if (!core->board.num_frontends)
  530. return -ENODEV;
  531. printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
  532. core->board.num_frontends);
  533. for (i = 1; i <= core->board.num_frontends; i++) {
  534. fe = videobuf_dvb_alloc_frontend(&dev->frontends, i);
  535. if (!fe) {
  536. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  537. videobuf_dvb_dealloc_frontends(&dev->frontends);
  538. return -ENOMEM;
  539. }
  540. }
  541. return 0;
  542. }
  543. static int dvb_register(struct cx8802_dev *dev)
  544. {
  545. struct cx88_core *core = dev->core;
  546. struct videobuf_dvb_frontend *fe0, *fe1 = NULL;
  547. int mfe_shared = 0; /* bus not shared by default */
  548. if (0 != core->i2c_rc) {
  549. printk(KERN_ERR "%s/2: no i2c-bus available, cannot attach dvb drivers\n", core->name);
  550. goto frontend_detach;
  551. }
  552. /* Get the first frontend */
  553. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  554. if (!fe0)
  555. goto frontend_detach;
  556. /* multi-frontend gate control is undefined or defaults to fe0 */
  557. dev->frontends.gate = 0;
  558. /* Sets the gate control callback to be used by i2c command calls */
  559. core->gate_ctrl = cx88_dvb_gate_ctrl;
  560. /* init frontend(s) */
  561. switch (core->boardnr) {
  562. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  563. fe0->dvb.frontend = dvb_attach(cx22702_attach,
  564. &connexant_refboard_config,
  565. &core->i2c_adap);
  566. if (fe0->dvb.frontend != NULL) {
  567. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  568. 0x61, &core->i2c_adap,
  569. DVB_PLL_THOMSON_DTT759X))
  570. goto frontend_detach;
  571. }
  572. break;
  573. case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
  574. case CX88_BOARD_CONEXANT_DVB_T1:
  575. case CX88_BOARD_KWORLD_DVB_T_CX22702:
  576. case CX88_BOARD_WINFAST_DTV1000:
  577. fe0->dvb.frontend = dvb_attach(cx22702_attach,
  578. &connexant_refboard_config,
  579. &core->i2c_adap);
  580. if (fe0->dvb.frontend != NULL) {
  581. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  582. 0x60, &core->i2c_adap,
  583. DVB_PLL_THOMSON_DTT7579))
  584. goto frontend_detach;
  585. }
  586. break;
  587. case CX88_BOARD_WINFAST_DTV2000H:
  588. case CX88_BOARD_HAUPPAUGE_HVR1100:
  589. case CX88_BOARD_HAUPPAUGE_HVR1100LP:
  590. case CX88_BOARD_HAUPPAUGE_HVR1300:
  591. fe0->dvb.frontend = dvb_attach(cx22702_attach,
  592. &hauppauge_hvr_config,
  593. &core->i2c_adap);
  594. if (fe0->dvb.frontend != NULL) {
  595. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  596. &core->i2c_adap, 0x61,
  597. TUNER_PHILIPS_FMD1216ME_MK3))
  598. goto frontend_detach;
  599. }
  600. break;
  601. case CX88_BOARD_HAUPPAUGE_HVR3000:
  602. /* MFE frontend 1 */
  603. mfe_shared = 1;
  604. dev->frontends.gate = 2;
  605. /* DVB-S init */
  606. fe0->dvb.frontend = dvb_attach(cx24123_attach,
  607. &hauppauge_novas_config,
  608. &dev->core->i2c_adap);
  609. if (fe0->dvb.frontend) {
  610. if (!dvb_attach(isl6421_attach,
  611. fe0->dvb.frontend,
  612. &dev->core->i2c_adap,
  613. 0x08, ISL6421_DCL, 0x00))
  614. goto frontend_detach;
  615. }
  616. /* MFE frontend 2 */
  617. fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2);
  618. if (!fe1)
  619. goto frontend_detach;
  620. /* DVB-T init */
  621. fe1->dvb.frontend = dvb_attach(cx22702_attach,
  622. &hauppauge_hvr_config,
  623. &dev->core->i2c_adap);
  624. if (fe1->dvb.frontend) {
  625. fe1->dvb.frontend->id = 1;
  626. if (!dvb_attach(simple_tuner_attach,
  627. fe1->dvb.frontend,
  628. &dev->core->i2c_adap,
  629. 0x61, TUNER_PHILIPS_FMD1216ME_MK3))
  630. goto frontend_detach;
  631. }
  632. break;
  633. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
  634. fe0->dvb.frontend = dvb_attach(mt352_attach,
  635. &dvico_fusionhdtv,
  636. &core->i2c_adap);
  637. if (fe0->dvb.frontend != NULL) {
  638. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  639. 0x60, NULL, DVB_PLL_THOMSON_DTT7579))
  640. goto frontend_detach;
  641. break;
  642. }
  643. /* ZL10353 replaces MT352 on later cards */
  644. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  645. &dvico_fusionhdtv_plus_v1_1,
  646. &core->i2c_adap);
  647. if (fe0->dvb.frontend != NULL) {
  648. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  649. 0x60, NULL, DVB_PLL_THOMSON_DTT7579))
  650. goto frontend_detach;
  651. }
  652. break;
  653. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
  654. /* The tin box says DEE1601, but it seems to be DTT7579
  655. * compatible, with a slightly different MT352 AGC gain. */
  656. fe0->dvb.frontend = dvb_attach(mt352_attach,
  657. &dvico_fusionhdtv_dual,
  658. &core->i2c_adap);
  659. if (fe0->dvb.frontend != NULL) {
  660. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  661. 0x61, NULL, DVB_PLL_THOMSON_DTT7579))
  662. goto frontend_detach;
  663. break;
  664. }
  665. /* ZL10353 replaces MT352 on later cards */
  666. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  667. &dvico_fusionhdtv_plus_v1_1,
  668. &core->i2c_adap);
  669. if (fe0->dvb.frontend != NULL) {
  670. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  671. 0x61, NULL, DVB_PLL_THOMSON_DTT7579))
  672. goto frontend_detach;
  673. }
  674. break;
  675. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
  676. fe0->dvb.frontend = dvb_attach(mt352_attach,
  677. &dvico_fusionhdtv,
  678. &core->i2c_adap);
  679. if (fe0->dvb.frontend != NULL) {
  680. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  681. 0x61, NULL, DVB_PLL_LG_Z201))
  682. goto frontend_detach;
  683. }
  684. break;
  685. case CX88_BOARD_KWORLD_DVB_T:
  686. case CX88_BOARD_DNTV_LIVE_DVB_T:
  687. case CX88_BOARD_ADSTECH_DVB_T_PCI:
  688. fe0->dvb.frontend = dvb_attach(mt352_attach,
  689. &dntv_live_dvbt_config,
  690. &core->i2c_adap);
  691. if (fe0->dvb.frontend != NULL) {
  692. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  693. 0x61, NULL, DVB_PLL_UNKNOWN_1))
  694. goto frontend_detach;
  695. }
  696. break;
  697. case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
  698. #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
  699. /* MT352 is on a secondary I2C bus made from some GPIO lines */
  700. fe0->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
  701. &dev->vp3054->adap);
  702. if (fe0->dvb.frontend != NULL) {
  703. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  704. &core->i2c_adap, 0x61,
  705. TUNER_PHILIPS_FMD1216ME_MK3))
  706. goto frontend_detach;
  707. }
  708. #else
  709. printk(KERN_ERR "%s/2: built without vp3054 support\n",
  710. core->name);
  711. #endif
  712. break;
  713. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
  714. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  715. &dvico_fusionhdtv_hybrid,
  716. &core->i2c_adap);
  717. if (fe0->dvb.frontend != NULL) {
  718. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  719. &core->i2c_adap, 0x61,
  720. TUNER_THOMSON_FE6600))
  721. goto frontend_detach;
  722. }
  723. break;
  724. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
  725. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  726. &dvico_fusionhdtv_xc3028,
  727. &core->i2c_adap);
  728. if (fe0->dvb.frontend == NULL)
  729. fe0->dvb.frontend = dvb_attach(mt352_attach,
  730. &dvico_fusionhdtv_mt352_xc3028,
  731. &core->i2c_adap);
  732. /*
  733. * On this board, the demod provides the I2C bus pullup.
  734. * We must not permit gate_ctrl to be performed, or
  735. * the xc3028 cannot communicate on the bus.
  736. */
  737. if (fe0->dvb.frontend)
  738. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  739. if (attach_xc3028(0x61, dev) < 0)
  740. goto frontend_detach;
  741. break;
  742. case CX88_BOARD_PCHDTV_HD3000:
  743. fe0->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,
  744. &core->i2c_adap);
  745. if (fe0->dvb.frontend != NULL) {
  746. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  747. &core->i2c_adap, 0x61,
  748. TUNER_THOMSON_DTT761X))
  749. goto frontend_detach;
  750. }
  751. break;
  752. case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
  753. dev->ts_gen_cntrl = 0x08;
  754. /* Do a hardware reset of chip before using it. */
  755. cx_clear(MO_GP0_IO, 1);
  756. mdelay(100);
  757. cx_set(MO_GP0_IO, 1);
  758. mdelay(200);
  759. /* Select RF connector callback */
  760. fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
  761. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  762. &fusionhdtv_3_gold,
  763. &core->i2c_adap);
  764. if (fe0->dvb.frontend != NULL) {
  765. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  766. &core->i2c_adap, 0x61,
  767. TUNER_MICROTUNE_4042FI5))
  768. goto frontend_detach;
  769. }
  770. break;
  771. case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
  772. dev->ts_gen_cntrl = 0x08;
  773. /* Do a hardware reset of chip before using it. */
  774. cx_clear(MO_GP0_IO, 1);
  775. mdelay(100);
  776. cx_set(MO_GP0_IO, 9);
  777. mdelay(200);
  778. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  779. &fusionhdtv_3_gold,
  780. &core->i2c_adap);
  781. if (fe0->dvb.frontend != NULL) {
  782. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  783. &core->i2c_adap, 0x61,
  784. TUNER_THOMSON_DTT761X))
  785. goto frontend_detach;
  786. }
  787. break;
  788. case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
  789. dev->ts_gen_cntrl = 0x08;
  790. /* Do a hardware reset of chip before using it. */
  791. cx_clear(MO_GP0_IO, 1);
  792. mdelay(100);
  793. cx_set(MO_GP0_IO, 1);
  794. mdelay(200);
  795. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  796. &fusionhdtv_5_gold,
  797. &core->i2c_adap);
  798. if (fe0->dvb.frontend != NULL) {
  799. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  800. &core->i2c_adap, 0x61,
  801. TUNER_LG_TDVS_H06XF))
  802. goto frontend_detach;
  803. if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,
  804. &core->i2c_adap, 0x43))
  805. goto frontend_detach;
  806. }
  807. break;
  808. case CX88_BOARD_PCHDTV_HD5500:
  809. dev->ts_gen_cntrl = 0x08;
  810. /* Do a hardware reset of chip before using it. */
  811. cx_clear(MO_GP0_IO, 1);
  812. mdelay(100);
  813. cx_set(MO_GP0_IO, 1);
  814. mdelay(200);
  815. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  816. &pchdtv_hd5500,
  817. &core->i2c_adap);
  818. if (fe0->dvb.frontend != NULL) {
  819. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  820. &core->i2c_adap, 0x61,
  821. TUNER_LG_TDVS_H06XF))
  822. goto frontend_detach;
  823. if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,
  824. &core->i2c_adap, 0x43))
  825. goto frontend_detach;
  826. }
  827. break;
  828. case CX88_BOARD_ATI_HDTVWONDER:
  829. fe0->dvb.frontend = dvb_attach(nxt200x_attach,
  830. &ati_hdtvwonder,
  831. &core->i2c_adap);
  832. if (fe0->dvb.frontend != NULL) {
  833. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  834. &core->i2c_adap, 0x61,
  835. TUNER_PHILIPS_TUV1236D))
  836. goto frontend_detach;
  837. }
  838. break;
  839. case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
  840. case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
  841. fe0->dvb.frontend = dvb_attach(cx24123_attach,
  842. &hauppauge_novas_config,
  843. &core->i2c_adap);
  844. if (fe0->dvb.frontend) {
  845. if (!dvb_attach(isl6421_attach, fe0->dvb.frontend,
  846. &core->i2c_adap, 0x08, ISL6421_DCL, 0x00))
  847. goto frontend_detach;
  848. }
  849. break;
  850. case CX88_BOARD_KWORLD_DVBS_100:
  851. fe0->dvb.frontend = dvb_attach(cx24123_attach,
  852. &kworld_dvbs_100_config,
  853. &core->i2c_adap);
  854. if (fe0->dvb.frontend) {
  855. core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
  856. fe0->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage;
  857. }
  858. break;
  859. case CX88_BOARD_GENIATECH_DVBS:
  860. fe0->dvb.frontend = dvb_attach(cx24123_attach,
  861. &geniatech_dvbs_config,
  862. &core->i2c_adap);
  863. if (fe0->dvb.frontend) {
  864. core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
  865. fe0->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
  866. }
  867. break;
  868. case CX88_BOARD_PINNACLE_PCTV_HD_800i:
  869. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  870. &pinnacle_pctv_hd_800i_config,
  871. &core->i2c_adap);
  872. if (fe0->dvb.frontend != NULL) {
  873. if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,
  874. &core->i2c_adap,
  875. &pinnacle_pctv_hd_800i_tuner_config))
  876. goto frontend_detach;
  877. }
  878. break;
  879. case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
  880. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  881. &dvico_hdtv5_pci_nano_config,
  882. &core->i2c_adap);
  883. if (fe0->dvb.frontend != NULL) {
  884. struct dvb_frontend *fe;
  885. struct xc2028_config cfg = {
  886. .i2c_adap = &core->i2c_adap,
  887. .i2c_addr = 0x61,
  888. };
  889. static struct xc2028_ctrl ctl = {
  890. .fname = XC2028_DEFAULT_FIRMWARE,
  891. .max_len = 64,
  892. .scode_table = XC3028_FE_OREN538,
  893. };
  894. fe = dvb_attach(xc2028_attach,
  895. fe0->dvb.frontend, &cfg);
  896. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  897. fe->ops.tuner_ops.set_config(fe, &ctl);
  898. }
  899. break;
  900. case CX88_BOARD_PINNACLE_HYBRID_PCTV:
  901. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  902. &cx88_pinnacle_hybrid_pctv,
  903. &core->i2c_adap);
  904. if (fe0->dvb.frontend) {
  905. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  906. if (attach_xc3028(0x61, dev) < 0)
  907. goto frontend_detach;
  908. }
  909. break;
  910. case CX88_BOARD_GENIATECH_X8000_MT:
  911. dev->ts_gen_cntrl = 0x00;
  912. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  913. &cx88_geniatech_x8000_mt,
  914. &core->i2c_adap);
  915. if (attach_xc3028(0x61, dev) < 0)
  916. goto frontend_detach;
  917. break;
  918. case CX88_BOARD_KWORLD_ATSC_120:
  919. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  920. &kworld_atsc_120_config,
  921. &core->i2c_adap);
  922. if (attach_xc3028(0x61, dev) < 0)
  923. goto frontend_detach;
  924. break;
  925. case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
  926. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  927. &dvico_fusionhdtv7_config,
  928. &core->i2c_adap);
  929. if (fe0->dvb.frontend != NULL) {
  930. if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,
  931. &core->i2c_adap,
  932. &dvico_fusionhdtv7_tuner_config))
  933. goto frontend_detach;
  934. }
  935. break;
  936. case CX88_BOARD_HAUPPAUGE_HVR4000:
  937. /* MFE frontend 1 */
  938. mfe_shared = 1;
  939. dev->frontends.gate = 2;
  940. /* DVB-S/S2 Init */
  941. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  942. &hauppauge_hvr4000_config,
  943. &dev->core->i2c_adap);
  944. if (fe0->dvb.frontend) {
  945. if (!dvb_attach(isl6421_attach,
  946. fe0->dvb.frontend,
  947. &dev->core->i2c_adap,
  948. 0x08, ISL6421_DCL, 0x00))
  949. goto frontend_detach;
  950. }
  951. /* MFE frontend 2 */
  952. fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2);
  953. if (!fe1)
  954. goto frontend_detach;
  955. /* DVB-T Init */
  956. fe1->dvb.frontend = dvb_attach(cx22702_attach,
  957. &hauppauge_hvr_config,
  958. &dev->core->i2c_adap);
  959. if (fe1->dvb.frontend) {
  960. fe1->dvb.frontend->id = 1;
  961. if (!dvb_attach(simple_tuner_attach,
  962. fe1->dvb.frontend,
  963. &dev->core->i2c_adap,
  964. 0x61, TUNER_PHILIPS_FMD1216ME_MK3))
  965. goto frontend_detach;
  966. }
  967. break;
  968. case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
  969. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  970. &hauppauge_hvr4000_config,
  971. &dev->core->i2c_adap);
  972. if (fe0->dvb.frontend) {
  973. if (!dvb_attach(isl6421_attach,
  974. fe0->dvb.frontend,
  975. &dev->core->i2c_adap,
  976. 0x08, ISL6421_DCL, 0x00))
  977. goto frontend_detach;
  978. }
  979. break;
  980. case CX88_BOARD_PROF_6200:
  981. case CX88_BOARD_TBS_8910:
  982. case CX88_BOARD_TEVII_S420:
  983. fe0->dvb.frontend = dvb_attach(stv0299_attach,
  984. &tevii_tuner_sharp_config,
  985. &core->i2c_adap);
  986. if (fe0->dvb.frontend != NULL) {
  987. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
  988. &core->i2c_adap, DVB_PLL_OPERA1))
  989. goto frontend_detach;
  990. core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
  991. fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
  992. } else {
  993. fe0->dvb.frontend = dvb_attach(stv0288_attach,
  994. &tevii_tuner_earda_config,
  995. &core->i2c_adap);
  996. if (fe0->dvb.frontend != NULL) {
  997. if (!dvb_attach(stb6000_attach, fe0->dvb.frontend, 0x61,
  998. &core->i2c_adap))
  999. goto frontend_detach;
  1000. core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
  1001. fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
  1002. }
  1003. }
  1004. break;
  1005. case CX88_BOARD_TEVII_S460:
  1006. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1007. &tevii_s460_config,
  1008. &core->i2c_adap);
  1009. if (fe0->dvb.frontend != NULL)
  1010. fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
  1011. break;
  1012. case CX88_BOARD_OMICOM_SS4_PCI:
  1013. case CX88_BOARD_TBS_8920:
  1014. case CX88_BOARD_PROF_7300:
  1015. case CX88_BOARD_SATTRADE_ST4200:
  1016. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1017. &hauppauge_hvr4000_config,
  1018. &core->i2c_adap);
  1019. if (fe0->dvb.frontend != NULL)
  1020. fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
  1021. break;
  1022. case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII:
  1023. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1024. &cx88_terratec_cinergy_ht_pci_mkii_config,
  1025. &core->i2c_adap);
  1026. if (fe0->dvb.frontend) {
  1027. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1028. if (attach_xc3028(0x61, dev) < 0)
  1029. goto frontend_detach;
  1030. }
  1031. break;
  1032. default:
  1033. printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
  1034. core->name);
  1035. break;
  1036. }
  1037. if ( (NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend) ) {
  1038. printk(KERN_ERR
  1039. "%s/2: frontend initialization failed\n",
  1040. core->name);
  1041. goto frontend_detach;
  1042. }
  1043. /* define general-purpose callback pointer */
  1044. fe0->dvb.frontend->callback = cx88_tuner_callback;
  1045. /* Ensure all frontends negotiate bus access */
  1046. fe0->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
  1047. if (fe1)
  1048. fe1->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
  1049. /* Put the analog decoder in standby to keep it quiet */
  1050. cx88_call_i2c_clients(core, TUNER_SET_STANDBY, NULL);
  1051. /* register everything */
  1052. return videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1053. &dev->pci->dev, adapter_nr, mfe_shared);
  1054. frontend_detach:
  1055. core->gate_ctrl = NULL;
  1056. videobuf_dvb_dealloc_frontends(&dev->frontends);
  1057. return -EINVAL;
  1058. }
  1059. /* ----------------------------------------------------------- */
  1060. /* CX8802 MPEG -> mini driver - We have been given the hardware */
  1061. static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
  1062. {
  1063. struct cx88_core *core = drv->core;
  1064. int err = 0;
  1065. dprintk( 1, "%s\n", __func__);
  1066. switch (core->boardnr) {
  1067. case CX88_BOARD_HAUPPAUGE_HVR1300:
  1068. /* We arrive here with either the cx23416 or the cx22702
  1069. * on the bus. Take the bus from the cx23416 and enable the
  1070. * cx22702 demod
  1071. */
  1072. /* Toggle reset on cx22702 leaving i2c active */
  1073. cx_set(MO_GP0_IO, 0x00000080);
  1074. udelay(1000);
  1075. cx_clear(MO_GP0_IO, 0x00000080);
  1076. udelay(50);
  1077. cx_set(MO_GP0_IO, 0x00000080);
  1078. udelay(1000);
  1079. /* enable the cx22702 pins */
  1080. cx_clear(MO_GP0_IO, 0x00000004);
  1081. udelay(1000);
  1082. break;
  1083. case CX88_BOARD_HAUPPAUGE_HVR3000:
  1084. case CX88_BOARD_HAUPPAUGE_HVR4000:
  1085. /* Toggle reset on cx22702 leaving i2c active */
  1086. cx_set(MO_GP0_IO, 0x00000080);
  1087. udelay(1000);
  1088. cx_clear(MO_GP0_IO, 0x00000080);
  1089. udelay(50);
  1090. cx_set(MO_GP0_IO, 0x00000080);
  1091. udelay(1000);
  1092. switch (core->dvbdev->frontends.active_fe_id) {
  1093. case 1: /* DVB-S/S2 Enabled */
  1094. /* tri-state the cx22702 pins */
  1095. cx_set(MO_GP0_IO, 0x00000004);
  1096. /* Take the cx24116/cx24123 out of reset */
  1097. cx_write(MO_SRST_IO, 1);
  1098. core->dvbdev->ts_gen_cntrl = 0x02; /* Parallel IO */
  1099. break;
  1100. case 2: /* DVB-T Enabled */
  1101. /* Put the cx24116/cx24123 into reset */
  1102. cx_write(MO_SRST_IO, 0);
  1103. /* enable the cx22702 pins */
  1104. cx_clear(MO_GP0_IO, 0x00000004);
  1105. core->dvbdev->ts_gen_cntrl = 0x0c; /* Serial IO */
  1106. break;
  1107. }
  1108. udelay(1000);
  1109. break;
  1110. default:
  1111. err = -ENODEV;
  1112. }
  1113. return err;
  1114. }
  1115. /* CX8802 MPEG -> mini driver - We no longer have the hardware */
  1116. static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
  1117. {
  1118. struct cx88_core *core = drv->core;
  1119. int err = 0;
  1120. dprintk( 1, "%s\n", __func__);
  1121. switch (core->boardnr) {
  1122. case CX88_BOARD_HAUPPAUGE_HVR1300:
  1123. /* Do Nothing, leave the cx22702 on the bus. */
  1124. break;
  1125. case CX88_BOARD_HAUPPAUGE_HVR3000:
  1126. case CX88_BOARD_HAUPPAUGE_HVR4000:
  1127. break;
  1128. default:
  1129. err = -ENODEV;
  1130. }
  1131. return err;
  1132. }
  1133. static int cx8802_dvb_probe(struct cx8802_driver *drv)
  1134. {
  1135. struct cx88_core *core = drv->core;
  1136. struct cx8802_dev *dev = drv->core->dvbdev;
  1137. int err;
  1138. struct videobuf_dvb_frontend *fe;
  1139. int i;
  1140. dprintk( 1, "%s\n", __func__);
  1141. dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  1142. core->boardnr,
  1143. core->name,
  1144. core->pci_bus,
  1145. core->pci_slot);
  1146. err = -ENODEV;
  1147. if (!(core->board.mpeg & CX88_MPEG_DVB))
  1148. goto fail_core;
  1149. /* If vp3054 isn't enabled, a stub will just return 0 */
  1150. err = vp3054_i2c_probe(dev);
  1151. if (0 != err)
  1152. goto fail_core;
  1153. /* dvb stuff */
  1154. printk(KERN_INFO "%s/2: cx2388x based DVB/ATSC card\n", core->name);
  1155. dev->ts_gen_cntrl = 0x0c;
  1156. err = cx8802_alloc_frontends(dev);
  1157. if (err)
  1158. goto fail_core;
  1159. err = -ENODEV;
  1160. for (i = 1; i <= core->board.num_frontends; i++) {
  1161. fe = videobuf_dvb_get_frontend(&core->dvbdev->frontends, i);
  1162. if (fe == NULL) {
  1163. printk(KERN_ERR "%s() failed to get frontend(%d)\n",
  1164. __func__, i);
  1165. goto fail_probe;
  1166. }
  1167. videobuf_queue_sg_init(&fe->dvb.dvbq, &dvb_qops,
  1168. &dev->pci->dev, &dev->slock,
  1169. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  1170. V4L2_FIELD_TOP,
  1171. sizeof(struct cx88_buffer),
  1172. dev);
  1173. /* init struct videobuf_dvb */
  1174. fe->dvb.name = dev->core->name;
  1175. }
  1176. err = dvb_register(dev);
  1177. if (err)
  1178. /* frontends/adapter de-allocated in dvb_register */
  1179. printk(KERN_ERR "%s/2: dvb_register failed (err = %d)\n",
  1180. core->name, err);
  1181. return err;
  1182. fail_probe:
  1183. videobuf_dvb_dealloc_frontends(&core->dvbdev->frontends);
  1184. fail_core:
  1185. return err;
  1186. }
  1187. static int cx8802_dvb_remove(struct cx8802_driver *drv)
  1188. {
  1189. struct cx88_core *core = drv->core;
  1190. struct cx8802_dev *dev = drv->core->dvbdev;
  1191. dprintk( 1, "%s\n", __func__);
  1192. videobuf_dvb_unregister_bus(&dev->frontends);
  1193. vp3054_i2c_remove(dev);
  1194. core->gate_ctrl = NULL;
  1195. return 0;
  1196. }
  1197. static struct cx8802_driver cx8802_dvb_driver = {
  1198. .type_id = CX88_MPEG_DVB,
  1199. .hw_access = CX8802_DRVCTL_SHARED,
  1200. .probe = cx8802_dvb_probe,
  1201. .remove = cx8802_dvb_remove,
  1202. .advise_acquire = cx8802_dvb_advise_acquire,
  1203. .advise_release = cx8802_dvb_advise_release,
  1204. };
  1205. static int dvb_init(void)
  1206. {
  1207. printk(KERN_INFO "cx88/2: cx2388x dvb driver version %d.%d.%d loaded\n",
  1208. (CX88_VERSION_CODE >> 16) & 0xff,
  1209. (CX88_VERSION_CODE >> 8) & 0xff,
  1210. CX88_VERSION_CODE & 0xff);
  1211. #ifdef SNAPSHOT
  1212. printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
  1213. SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
  1214. #endif
  1215. return cx8802_register_driver(&cx8802_dvb_driver);
  1216. }
  1217. static void dvb_fini(void)
  1218. {
  1219. cx8802_unregister_driver(&cx8802_dvb_driver);
  1220. }
  1221. module_init(dvb_init);
  1222. module_exit(dvb_fini);
  1223. /*
  1224. * Local variables:
  1225. * c-basic-offset: 8
  1226. * compile-command: "make DVB=1"
  1227. * End:
  1228. */