cx88-dvb.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  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 "xc4000.h"
  42. #include "xc5000.h"
  43. #include "nxt200x.h"
  44. #include "cx24123.h"
  45. #include "isl6421.h"
  46. #include "tuner-simple.h"
  47. #include "tda9887.h"
  48. #include "s5h1411.h"
  49. #include "stv0299.h"
  50. #include "z0194a.h"
  51. #include "stv0288.h"
  52. #include "stb6000.h"
  53. #include "cx24116.h"
  54. #include "stv0900.h"
  55. #include "stb6100.h"
  56. #include "stb6100_proc.h"
  57. #include "mb86a16.h"
  58. #include "ts2020.h"
  59. #include "ds3000.h"
  60. MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
  61. MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
  62. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  63. MODULE_LICENSE("GPL");
  64. MODULE_VERSION(CX88_VERSION);
  65. static unsigned int debug;
  66. module_param(debug, int, 0644);
  67. MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
  68. static unsigned int dvb_buf_tscnt = 32;
  69. module_param(dvb_buf_tscnt, int, 0644);
  70. MODULE_PARM_DESC(dvb_buf_tscnt, "DVB Buffer TS count [dvb]");
  71. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  72. #define dprintk(level,fmt, arg...) if (debug >= level) \
  73. printk(KERN_DEBUG "%s/2-dvb: " fmt, core->name, ## arg)
  74. /* ------------------------------------------------------------------ */
  75. static int dvb_buf_setup(struct videobuf_queue *q,
  76. unsigned int *count, unsigned int *size)
  77. {
  78. struct cx8802_dev *dev = q->priv_data;
  79. dev->ts_packet_size = 188 * 4;
  80. dev->ts_packet_count = dvb_buf_tscnt;
  81. *size = dev->ts_packet_size * dev->ts_packet_count;
  82. *count = dvb_buf_tscnt;
  83. return 0;
  84. }
  85. static int dvb_buf_prepare(struct videobuf_queue *q,
  86. struct videobuf_buffer *vb, enum v4l2_field field)
  87. {
  88. struct cx8802_dev *dev = q->priv_data;
  89. return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field);
  90. }
  91. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  92. {
  93. struct cx8802_dev *dev = q->priv_data;
  94. cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
  95. }
  96. static void dvb_buf_release(struct videobuf_queue *q,
  97. struct videobuf_buffer *vb)
  98. {
  99. cx88_free_buffer(q, (struct cx88_buffer*)vb);
  100. }
  101. static const struct videobuf_queue_ops dvb_qops = {
  102. .buf_setup = dvb_buf_setup,
  103. .buf_prepare = dvb_buf_prepare,
  104. .buf_queue = dvb_buf_queue,
  105. .buf_release = dvb_buf_release,
  106. };
  107. /* ------------------------------------------------------------------ */
  108. static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire)
  109. {
  110. struct cx8802_dev *dev= fe->dvb->priv;
  111. struct cx8802_driver *drv = NULL;
  112. int ret = 0;
  113. int fe_id;
  114. fe_id = videobuf_dvb_find_frontend(&dev->frontends, fe);
  115. if (!fe_id) {
  116. printk(KERN_ERR "%s() No frontend found\n", __func__);
  117. return -EINVAL;
  118. }
  119. mutex_lock(&dev->core->lock);
  120. drv = cx8802_get_driver(dev, CX88_MPEG_DVB);
  121. if (drv) {
  122. if (acquire){
  123. dev->frontends.active_fe_id = fe_id;
  124. ret = drv->request_acquire(drv);
  125. } else {
  126. ret = drv->request_release(drv);
  127. dev->frontends.active_fe_id = 0;
  128. }
  129. }
  130. mutex_unlock(&dev->core->lock);
  131. return ret;
  132. }
  133. static void cx88_dvb_gate_ctrl(struct cx88_core *core, int open)
  134. {
  135. struct videobuf_dvb_frontends *f;
  136. struct videobuf_dvb_frontend *fe;
  137. if (!core->dvbdev)
  138. return;
  139. f = &core->dvbdev->frontends;
  140. if (!f)
  141. return;
  142. if (f->gate <= 1) /* undefined or fe0 */
  143. fe = videobuf_dvb_get_frontend(f, 1);
  144. else
  145. fe = videobuf_dvb_get_frontend(f, f->gate);
  146. if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)
  147. fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);
  148. }
  149. /* ------------------------------------------------------------------ */
  150. static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
  151. {
  152. static const u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
  153. static const u8 reset [] = { RESET, 0x80 };
  154. static const u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  155. static const u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
  156. static const u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  157. static const u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  158. mt352_write(fe, clock_config, sizeof(clock_config));
  159. udelay(200);
  160. mt352_write(fe, reset, sizeof(reset));
  161. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  162. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  163. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  164. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  165. return 0;
  166. }
  167. static int dvico_dual_demod_init(struct dvb_frontend *fe)
  168. {
  169. static const u8 clock_config [] = { CLOCK_CTL, 0x38, 0x38 };
  170. static const u8 reset [] = { RESET, 0x80 };
  171. static const u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  172. static const u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };
  173. static const u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  174. static const u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  175. mt352_write(fe, clock_config, sizeof(clock_config));
  176. udelay(200);
  177. mt352_write(fe, reset, sizeof(reset));
  178. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  179. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  180. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  181. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  182. return 0;
  183. }
  184. static int dntv_live_dvbt_demod_init(struct dvb_frontend* fe)
  185. {
  186. static const u8 clock_config [] = { 0x89, 0x38, 0x39 };
  187. static const u8 reset [] = { 0x50, 0x80 };
  188. static const u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  189. static const u8 agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
  190. 0x00, 0xFF, 0x00, 0x40, 0x40 };
  191. static const u8 dntv_extra[] = { 0xB5, 0x7A };
  192. static const u8 capt_range_cfg[] = { 0x75, 0x32 };
  193. mt352_write(fe, clock_config, sizeof(clock_config));
  194. udelay(2000);
  195. mt352_write(fe, reset, sizeof(reset));
  196. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  197. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  198. udelay(2000);
  199. mt352_write(fe, dntv_extra, sizeof(dntv_extra));
  200. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  201. return 0;
  202. }
  203. static const struct mt352_config dvico_fusionhdtv = {
  204. .demod_address = 0x0f,
  205. .demod_init = dvico_fusionhdtv_demod_init,
  206. };
  207. static const struct mt352_config dntv_live_dvbt_config = {
  208. .demod_address = 0x0f,
  209. .demod_init = dntv_live_dvbt_demod_init,
  210. };
  211. static const struct mt352_config dvico_fusionhdtv_dual = {
  212. .demod_address = 0x0f,
  213. .demod_init = dvico_dual_demod_init,
  214. };
  215. static const struct zl10353_config cx88_terratec_cinergy_ht_pci_mkii_config = {
  216. .demod_address = (0x1e >> 1),
  217. .no_tuner = 1,
  218. .if2 = 45600,
  219. };
  220. static struct mb86a16_config twinhan_vp1027 = {
  221. .demod_address = 0x08,
  222. };
  223. #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
  224. static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)
  225. {
  226. static const u8 clock_config [] = { 0x89, 0x38, 0x38 };
  227. static const u8 reset [] = { 0x50, 0x80 };
  228. static const u8 adc_ctl_1_cfg [] = { 0x8E, 0x40 };
  229. static const u8 agc_cfg [] = { 0x67, 0x10, 0x20, 0x00, 0xFF, 0xFF,
  230. 0x00, 0xFF, 0x00, 0x40, 0x40 };
  231. static const u8 dntv_extra[] = { 0xB5, 0x7A };
  232. static const u8 capt_range_cfg[] = { 0x75, 0x32 };
  233. mt352_write(fe, clock_config, sizeof(clock_config));
  234. udelay(2000);
  235. mt352_write(fe, reset, sizeof(reset));
  236. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  237. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  238. udelay(2000);
  239. mt352_write(fe, dntv_extra, sizeof(dntv_extra));
  240. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  241. return 0;
  242. }
  243. static const struct mt352_config dntv_live_dvbt_pro_config = {
  244. .demod_address = 0x0f,
  245. .no_tuner = 1,
  246. .demod_init = dntv_live_dvbt_pro_demod_init,
  247. };
  248. #endif
  249. static const struct zl10353_config dvico_fusionhdtv_hybrid = {
  250. .demod_address = 0x0f,
  251. .no_tuner = 1,
  252. };
  253. static const struct zl10353_config dvico_fusionhdtv_xc3028 = {
  254. .demod_address = 0x0f,
  255. .if2 = 45600,
  256. .no_tuner = 1,
  257. };
  258. static const struct mt352_config dvico_fusionhdtv_mt352_xc3028 = {
  259. .demod_address = 0x0f,
  260. .if2 = 4560,
  261. .no_tuner = 1,
  262. .demod_init = dvico_fusionhdtv_demod_init,
  263. };
  264. static const struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
  265. .demod_address = 0x0f,
  266. };
  267. static const struct cx22702_config connexant_refboard_config = {
  268. .demod_address = 0x43,
  269. .output_mode = CX22702_SERIAL_OUTPUT,
  270. };
  271. static const struct cx22702_config hauppauge_hvr_config = {
  272. .demod_address = 0x63,
  273. .output_mode = CX22702_SERIAL_OUTPUT,
  274. };
  275. static int or51132_set_ts_param(struct dvb_frontend* fe, int is_punctured)
  276. {
  277. struct cx8802_dev *dev= fe->dvb->priv;
  278. dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
  279. return 0;
  280. }
  281. static const struct or51132_config pchdtv_hd3000 = {
  282. .demod_address = 0x15,
  283. .set_ts_params = or51132_set_ts_param,
  284. };
  285. static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
  286. {
  287. struct cx8802_dev *dev= fe->dvb->priv;
  288. struct cx88_core *core = dev->core;
  289. dprintk(1, "%s: index = %d\n", __func__, index);
  290. if (index == 0)
  291. cx_clear(MO_GP0_IO, 8);
  292. else
  293. cx_set(MO_GP0_IO, 8);
  294. return 0;
  295. }
  296. static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
  297. {
  298. struct cx8802_dev *dev= fe->dvb->priv;
  299. if (is_punctured)
  300. dev->ts_gen_cntrl |= 0x04;
  301. else
  302. dev->ts_gen_cntrl &= ~0x04;
  303. return 0;
  304. }
  305. static struct lgdt330x_config fusionhdtv_3_gold = {
  306. .demod_address = 0x0e,
  307. .demod_chip = LGDT3302,
  308. .serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
  309. .set_ts_params = lgdt330x_set_ts_param,
  310. };
  311. static const struct lgdt330x_config fusionhdtv_5_gold = {
  312. .demod_address = 0x0e,
  313. .demod_chip = LGDT3303,
  314. .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
  315. .set_ts_params = lgdt330x_set_ts_param,
  316. };
  317. static const struct lgdt330x_config pchdtv_hd5500 = {
  318. .demod_address = 0x59,
  319. .demod_chip = LGDT3303,
  320. .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */
  321. .set_ts_params = lgdt330x_set_ts_param,
  322. };
  323. static int nxt200x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
  324. {
  325. struct cx8802_dev *dev= fe->dvb->priv;
  326. dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
  327. return 0;
  328. }
  329. static const struct nxt200x_config ati_hdtvwonder = {
  330. .demod_address = 0x0a,
  331. .set_ts_params = nxt200x_set_ts_param,
  332. };
  333. static int cx24123_set_ts_param(struct dvb_frontend* fe,
  334. int is_punctured)
  335. {
  336. struct cx8802_dev *dev= fe->dvb->priv;
  337. dev->ts_gen_cntrl = 0x02;
  338. return 0;
  339. }
  340. static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
  341. fe_sec_voltage_t voltage)
  342. {
  343. struct cx8802_dev *dev= fe->dvb->priv;
  344. struct cx88_core *core = dev->core;
  345. if (voltage == SEC_VOLTAGE_OFF)
  346. cx_write(MO_GP0_IO, 0x000006fb);
  347. else
  348. cx_write(MO_GP0_IO, 0x000006f9);
  349. if (core->prev_set_voltage)
  350. return core->prev_set_voltage(fe, voltage);
  351. return 0;
  352. }
  353. static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
  354. fe_sec_voltage_t voltage)
  355. {
  356. struct cx8802_dev *dev= fe->dvb->priv;
  357. struct cx88_core *core = dev->core;
  358. if (voltage == SEC_VOLTAGE_OFF) {
  359. dprintk(1,"LNB Voltage OFF\n");
  360. cx_write(MO_GP0_IO, 0x0000efff);
  361. }
  362. if (core->prev_set_voltage)
  363. return core->prev_set_voltage(fe, voltage);
  364. return 0;
  365. }
  366. static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
  367. fe_sec_voltage_t voltage)
  368. {
  369. struct cx8802_dev *dev= fe->dvb->priv;
  370. struct cx88_core *core = dev->core;
  371. cx_set(MO_GP0_IO, 0x6040);
  372. switch (voltage) {
  373. case SEC_VOLTAGE_13:
  374. cx_clear(MO_GP0_IO, 0x20);
  375. break;
  376. case SEC_VOLTAGE_18:
  377. cx_set(MO_GP0_IO, 0x20);
  378. break;
  379. case SEC_VOLTAGE_OFF:
  380. cx_clear(MO_GP0_IO, 0x20);
  381. break;
  382. }
  383. if (core->prev_set_voltage)
  384. return core->prev_set_voltage(fe, voltage);
  385. return 0;
  386. }
  387. static int vp1027_set_voltage(struct dvb_frontend *fe,
  388. fe_sec_voltage_t voltage)
  389. {
  390. struct cx8802_dev *dev = fe->dvb->priv;
  391. struct cx88_core *core = dev->core;
  392. switch (voltage) {
  393. case SEC_VOLTAGE_13:
  394. dprintk(1, "LNB SEC Voltage=13\n");
  395. cx_write(MO_GP0_IO, 0x00001220);
  396. break;
  397. case SEC_VOLTAGE_18:
  398. dprintk(1, "LNB SEC Voltage=18\n");
  399. cx_write(MO_GP0_IO, 0x00001222);
  400. break;
  401. case SEC_VOLTAGE_OFF:
  402. dprintk(1, "LNB Voltage OFF\n");
  403. cx_write(MO_GP0_IO, 0x00001230);
  404. break;
  405. }
  406. if (core->prev_set_voltage)
  407. return core->prev_set_voltage(fe, voltage);
  408. return 0;
  409. }
  410. static const struct cx24123_config geniatech_dvbs_config = {
  411. .demod_address = 0x55,
  412. .set_ts_params = cx24123_set_ts_param,
  413. };
  414. static const struct cx24123_config hauppauge_novas_config = {
  415. .demod_address = 0x55,
  416. .set_ts_params = cx24123_set_ts_param,
  417. };
  418. static const struct cx24123_config kworld_dvbs_100_config = {
  419. .demod_address = 0x15,
  420. .set_ts_params = cx24123_set_ts_param,
  421. .lnb_polarity = 1,
  422. };
  423. static const struct s5h1409_config pinnacle_pctv_hd_800i_config = {
  424. .demod_address = 0x32 >> 1,
  425. .output_mode = S5H1409_PARALLEL_OUTPUT,
  426. .gpio = S5H1409_GPIO_ON,
  427. .qam_if = 44000,
  428. .inversion = S5H1409_INVERSION_OFF,
  429. .status_mode = S5H1409_DEMODLOCKING,
  430. .mpeg_timing = S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
  431. };
  432. static const struct s5h1409_config dvico_hdtv5_pci_nano_config = {
  433. .demod_address = 0x32 >> 1,
  434. .output_mode = S5H1409_SERIAL_OUTPUT,
  435. .gpio = S5H1409_GPIO_OFF,
  436. .inversion = S5H1409_INVERSION_OFF,
  437. .status_mode = S5H1409_DEMODLOCKING,
  438. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  439. };
  440. static const struct s5h1409_config kworld_atsc_120_config = {
  441. .demod_address = 0x32 >> 1,
  442. .output_mode = S5H1409_SERIAL_OUTPUT,
  443. .gpio = S5H1409_GPIO_OFF,
  444. .inversion = S5H1409_INVERSION_OFF,
  445. .status_mode = S5H1409_DEMODLOCKING,
  446. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  447. };
  448. static const struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {
  449. .i2c_address = 0x64,
  450. .if_khz = 5380,
  451. };
  452. static const struct zl10353_config cx88_pinnacle_hybrid_pctv = {
  453. .demod_address = (0x1e >> 1),
  454. .no_tuner = 1,
  455. .if2 = 45600,
  456. };
  457. static const struct zl10353_config cx88_geniatech_x8000_mt = {
  458. .demod_address = (0x1e >> 1),
  459. .no_tuner = 1,
  460. .disable_i2c_gate_ctrl = 1,
  461. };
  462. static const struct s5h1411_config dvico_fusionhdtv7_config = {
  463. .output_mode = S5H1411_SERIAL_OUTPUT,
  464. .gpio = S5H1411_GPIO_ON,
  465. .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  466. .qam_if = S5H1411_IF_44000,
  467. .vsb_if = S5H1411_IF_44000,
  468. .inversion = S5H1411_INVERSION_OFF,
  469. .status_mode = S5H1411_DEMODLOCKING
  470. };
  471. static const struct xc5000_config dvico_fusionhdtv7_tuner_config = {
  472. .i2c_address = 0xc2 >> 1,
  473. .if_khz = 5380,
  474. };
  475. static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
  476. {
  477. struct dvb_frontend *fe;
  478. struct videobuf_dvb_frontend *fe0 = NULL;
  479. struct xc2028_ctrl ctl;
  480. struct xc2028_config cfg = {
  481. .i2c_adap = &dev->core->i2c_adap,
  482. .i2c_addr = addr,
  483. .ctrl = &ctl,
  484. };
  485. /* Get the first frontend */
  486. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  487. if (!fe0)
  488. return -EINVAL;
  489. if (!fe0->dvb.frontend) {
  490. printk(KERN_ERR "%s/2: dvb frontend not attached. "
  491. "Can't attach xc3028\n",
  492. dev->core->name);
  493. return -EINVAL;
  494. }
  495. /*
  496. * Some xc3028 devices may be hidden by an I2C gate. This is known
  497. * to happen with some s5h1409-based devices.
  498. * Now that I2C gate is open, sets up xc3028 configuration
  499. */
  500. cx88_setup_xc3028(dev->core, &ctl);
  501. fe = dvb_attach(xc2028_attach, fe0->dvb.frontend, &cfg);
  502. if (!fe) {
  503. printk(KERN_ERR "%s/2: xc3028 attach failed\n",
  504. dev->core->name);
  505. dvb_frontend_detach(fe0->dvb.frontend);
  506. dvb_unregister_frontend(fe0->dvb.frontend);
  507. fe0->dvb.frontend = NULL;
  508. return -EINVAL;
  509. }
  510. printk(KERN_INFO "%s/2: xc3028 attached\n",
  511. dev->core->name);
  512. return 0;
  513. }
  514. static int attach_xc4000(struct cx8802_dev *dev, struct xc4000_config *cfg)
  515. {
  516. struct dvb_frontend *fe;
  517. struct videobuf_dvb_frontend *fe0 = NULL;
  518. /* Get the first frontend */
  519. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  520. if (!fe0)
  521. return -EINVAL;
  522. if (!fe0->dvb.frontend) {
  523. printk(KERN_ERR "%s/2: dvb frontend not attached. "
  524. "Can't attach xc4000\n",
  525. dev->core->name);
  526. return -EINVAL;
  527. }
  528. fe = dvb_attach(xc4000_attach, fe0->dvb.frontend, &dev->core->i2c_adap,
  529. cfg);
  530. if (!fe) {
  531. printk(KERN_ERR "%s/2: xc4000 attach failed\n",
  532. dev->core->name);
  533. dvb_frontend_detach(fe0->dvb.frontend);
  534. dvb_unregister_frontend(fe0->dvb.frontend);
  535. fe0->dvb.frontend = NULL;
  536. return -EINVAL;
  537. }
  538. printk(KERN_INFO "%s/2: xc4000 attached\n", dev->core->name);
  539. return 0;
  540. }
  541. static int cx24116_set_ts_param(struct dvb_frontend *fe,
  542. int is_punctured)
  543. {
  544. struct cx8802_dev *dev = fe->dvb->priv;
  545. dev->ts_gen_cntrl = 0x2;
  546. return 0;
  547. }
  548. static int stv0900_set_ts_param(struct dvb_frontend *fe,
  549. int is_punctured)
  550. {
  551. struct cx8802_dev *dev = fe->dvb->priv;
  552. dev->ts_gen_cntrl = 0;
  553. return 0;
  554. }
  555. static int cx24116_reset_device(struct dvb_frontend *fe)
  556. {
  557. struct cx8802_dev *dev = fe->dvb->priv;
  558. struct cx88_core *core = dev->core;
  559. /* Reset the part */
  560. /* Put the cx24116 into reset */
  561. cx_write(MO_SRST_IO, 0);
  562. msleep(10);
  563. /* Take the cx24116 out of reset */
  564. cx_write(MO_SRST_IO, 1);
  565. msleep(10);
  566. return 0;
  567. }
  568. static const struct cx24116_config hauppauge_hvr4000_config = {
  569. .demod_address = 0x05,
  570. .set_ts_params = cx24116_set_ts_param,
  571. .reset_device = cx24116_reset_device,
  572. };
  573. static const struct cx24116_config tevii_s460_config = {
  574. .demod_address = 0x55,
  575. .set_ts_params = cx24116_set_ts_param,
  576. .reset_device = cx24116_reset_device,
  577. };
  578. static int ds3000_set_ts_param(struct dvb_frontend *fe,
  579. int is_punctured)
  580. {
  581. struct cx8802_dev *dev = fe->dvb->priv;
  582. dev->ts_gen_cntrl = 4;
  583. return 0;
  584. }
  585. static struct ds3000_config tevii_ds3000_config = {
  586. .demod_address = 0x68,
  587. .set_ts_params = ds3000_set_ts_param,
  588. };
  589. static struct ts2020_config tevii_ts2020_config = {
  590. .tuner_address = 0x60,
  591. };
  592. static const struct stv0900_config prof_7301_stv0900_config = {
  593. .demod_address = 0x6a,
  594. /* demod_mode = 0,*/
  595. .xtal = 27000000,
  596. .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
  597. .diseqc_mode = 2,/* 2/3 PWM */
  598. .tun1_maddress = 0,/* 0x60 */
  599. .tun1_adc = 0,/* 2 Vpp */
  600. .path1_mode = 3,
  601. .set_ts_params = stv0900_set_ts_param,
  602. };
  603. static const struct stb6100_config prof_7301_stb6100_config = {
  604. .tuner_address = 0x60,
  605. .refclock = 27000000,
  606. };
  607. static const struct stv0299_config tevii_tuner_sharp_config = {
  608. .demod_address = 0x68,
  609. .inittab = sharp_z0194a_inittab,
  610. .mclk = 88000000UL,
  611. .invert = 1,
  612. .skip_reinit = 0,
  613. .lock_output = 1,
  614. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  615. .min_delay_ms = 100,
  616. .set_symbol_rate = sharp_z0194a_set_symbol_rate,
  617. .set_ts_params = cx24116_set_ts_param,
  618. };
  619. static const struct stv0288_config tevii_tuner_earda_config = {
  620. .demod_address = 0x68,
  621. .min_delay_ms = 100,
  622. .set_ts_params = cx24116_set_ts_param,
  623. };
  624. static int cx8802_alloc_frontends(struct cx8802_dev *dev)
  625. {
  626. struct cx88_core *core = dev->core;
  627. struct videobuf_dvb_frontend *fe = NULL;
  628. int i;
  629. mutex_init(&dev->frontends.lock);
  630. INIT_LIST_HEAD(&dev->frontends.felist);
  631. if (!core->board.num_frontends)
  632. return -ENODEV;
  633. printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
  634. core->board.num_frontends);
  635. for (i = 1; i <= core->board.num_frontends; i++) {
  636. fe = videobuf_dvb_alloc_frontend(&dev->frontends, i);
  637. if (!fe) {
  638. printk(KERN_ERR "%s() failed to alloc\n", __func__);
  639. videobuf_dvb_dealloc_frontends(&dev->frontends);
  640. return -ENOMEM;
  641. }
  642. }
  643. return 0;
  644. }
  645. static const u8 samsung_smt_7020_inittab[] = {
  646. 0x01, 0x15,
  647. 0x02, 0x00,
  648. 0x03, 0x00,
  649. 0x04, 0x7D,
  650. 0x05, 0x0F,
  651. 0x06, 0x02,
  652. 0x07, 0x00,
  653. 0x08, 0x60,
  654. 0x0A, 0xC2,
  655. 0x0B, 0x00,
  656. 0x0C, 0x01,
  657. 0x0D, 0x81,
  658. 0x0E, 0x44,
  659. 0x0F, 0x09,
  660. 0x10, 0x3C,
  661. 0x11, 0x84,
  662. 0x12, 0xDA,
  663. 0x13, 0x99,
  664. 0x14, 0x8D,
  665. 0x15, 0xCE,
  666. 0x16, 0xE8,
  667. 0x17, 0x43,
  668. 0x18, 0x1C,
  669. 0x19, 0x1B,
  670. 0x1A, 0x1D,
  671. 0x1C, 0x12,
  672. 0x1D, 0x00,
  673. 0x1E, 0x00,
  674. 0x1F, 0x00,
  675. 0x20, 0x00,
  676. 0x21, 0x00,
  677. 0x22, 0x00,
  678. 0x23, 0x00,
  679. 0x28, 0x02,
  680. 0x29, 0x28,
  681. 0x2A, 0x14,
  682. 0x2B, 0x0F,
  683. 0x2C, 0x09,
  684. 0x2D, 0x05,
  685. 0x31, 0x1F,
  686. 0x32, 0x19,
  687. 0x33, 0xFC,
  688. 0x34, 0x13,
  689. 0xff, 0xff,
  690. };
  691. static int samsung_smt_7020_tuner_set_params(struct dvb_frontend *fe)
  692. {
  693. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  694. struct cx8802_dev *dev = fe->dvb->priv;
  695. u8 buf[4];
  696. u32 div;
  697. struct i2c_msg msg = {
  698. .addr = 0x61,
  699. .flags = 0,
  700. .buf = buf,
  701. .len = sizeof(buf) };
  702. div = c->frequency / 125;
  703. buf[0] = (div >> 8) & 0x7f;
  704. buf[1] = div & 0xff;
  705. buf[2] = 0x84; /* 0xC4 */
  706. buf[3] = 0x00;
  707. if (c->frequency < 1500000)
  708. buf[3] |= 0x10;
  709. if (fe->ops.i2c_gate_ctrl)
  710. fe->ops.i2c_gate_ctrl(fe, 1);
  711. if (i2c_transfer(&dev->core->i2c_adap, &msg, 1) != 1)
  712. return -EIO;
  713. return 0;
  714. }
  715. static int samsung_smt_7020_set_tone(struct dvb_frontend *fe,
  716. fe_sec_tone_mode_t tone)
  717. {
  718. struct cx8802_dev *dev = fe->dvb->priv;
  719. struct cx88_core *core = dev->core;
  720. cx_set(MO_GP0_IO, 0x0800);
  721. switch (tone) {
  722. case SEC_TONE_ON:
  723. cx_set(MO_GP0_IO, 0x08);
  724. break;
  725. case SEC_TONE_OFF:
  726. cx_clear(MO_GP0_IO, 0x08);
  727. break;
  728. default:
  729. return -EINVAL;
  730. }
  731. return 0;
  732. }
  733. static int samsung_smt_7020_set_voltage(struct dvb_frontend *fe,
  734. fe_sec_voltage_t voltage)
  735. {
  736. struct cx8802_dev *dev = fe->dvb->priv;
  737. struct cx88_core *core = dev->core;
  738. u8 data;
  739. struct i2c_msg msg = {
  740. .addr = 8,
  741. .flags = 0,
  742. .buf = &data,
  743. .len = sizeof(data) };
  744. cx_set(MO_GP0_IO, 0x8000);
  745. switch (voltage) {
  746. case SEC_VOLTAGE_OFF:
  747. break;
  748. case SEC_VOLTAGE_13:
  749. data = ISL6421_EN1 | ISL6421_LLC1;
  750. cx_clear(MO_GP0_IO, 0x80);
  751. break;
  752. case SEC_VOLTAGE_18:
  753. data = ISL6421_EN1 | ISL6421_LLC1 | ISL6421_VSEL1;
  754. cx_clear(MO_GP0_IO, 0x80);
  755. break;
  756. default:
  757. return -EINVAL;
  758. }
  759. return (i2c_transfer(&dev->core->i2c_adap, &msg, 1) == 1) ? 0 : -EIO;
  760. }
  761. static int samsung_smt_7020_stv0299_set_symbol_rate(struct dvb_frontend *fe,
  762. u32 srate, u32 ratio)
  763. {
  764. u8 aclk = 0;
  765. u8 bclk = 0;
  766. if (srate < 1500000) {
  767. aclk = 0xb7;
  768. bclk = 0x47;
  769. } else if (srate < 3000000) {
  770. aclk = 0xb7;
  771. bclk = 0x4b;
  772. } else if (srate < 7000000) {
  773. aclk = 0xb7;
  774. bclk = 0x4f;
  775. } else if (srate < 14000000) {
  776. aclk = 0xb7;
  777. bclk = 0x53;
  778. } else if (srate < 30000000) {
  779. aclk = 0xb6;
  780. bclk = 0x53;
  781. } else if (srate < 45000000) {
  782. aclk = 0xb4;
  783. bclk = 0x51;
  784. }
  785. stv0299_writereg(fe, 0x13, aclk);
  786. stv0299_writereg(fe, 0x14, bclk);
  787. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  788. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  789. stv0299_writereg(fe, 0x21, ratio & 0xf0);
  790. return 0;
  791. }
  792. static const struct stv0299_config samsung_stv0299_config = {
  793. .demod_address = 0x68,
  794. .inittab = samsung_smt_7020_inittab,
  795. .mclk = 88000000UL,
  796. .invert = 0,
  797. .skip_reinit = 0,
  798. .lock_output = STV0299_LOCKOUTPUT_LK,
  799. .volt13_op0_op1 = STV0299_VOLT13_OP1,
  800. .min_delay_ms = 100,
  801. .set_symbol_rate = samsung_smt_7020_stv0299_set_symbol_rate,
  802. };
  803. static int dvb_register(struct cx8802_dev *dev)
  804. {
  805. struct cx88_core *core = dev->core;
  806. struct videobuf_dvb_frontend *fe0, *fe1 = NULL;
  807. int mfe_shared = 0; /* bus not shared by default */
  808. int res = -EINVAL;
  809. if (0 != core->i2c_rc) {
  810. printk(KERN_ERR "%s/2: no i2c-bus available, cannot attach dvb drivers\n", core->name);
  811. goto frontend_detach;
  812. }
  813. /* Get the first frontend */
  814. fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
  815. if (!fe0)
  816. goto frontend_detach;
  817. /* multi-frontend gate control is undefined or defaults to fe0 */
  818. dev->frontends.gate = 0;
  819. /* Sets the gate control callback to be used by i2c command calls */
  820. core->gate_ctrl = cx88_dvb_gate_ctrl;
  821. /* init frontend(s) */
  822. switch (core->boardnr) {
  823. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  824. fe0->dvb.frontend = dvb_attach(cx22702_attach,
  825. &connexant_refboard_config,
  826. &core->i2c_adap);
  827. if (fe0->dvb.frontend != NULL) {
  828. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  829. 0x61, &core->i2c_adap,
  830. DVB_PLL_THOMSON_DTT759X))
  831. goto frontend_detach;
  832. }
  833. break;
  834. case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
  835. case CX88_BOARD_CONEXANT_DVB_T1:
  836. case CX88_BOARD_KWORLD_DVB_T_CX22702:
  837. case CX88_BOARD_WINFAST_DTV1000:
  838. fe0->dvb.frontend = dvb_attach(cx22702_attach,
  839. &connexant_refboard_config,
  840. &core->i2c_adap);
  841. if (fe0->dvb.frontend != NULL) {
  842. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  843. 0x60, &core->i2c_adap,
  844. DVB_PLL_THOMSON_DTT7579))
  845. goto frontend_detach;
  846. }
  847. break;
  848. case CX88_BOARD_WINFAST_DTV2000H:
  849. case CX88_BOARD_HAUPPAUGE_HVR1100:
  850. case CX88_BOARD_HAUPPAUGE_HVR1100LP:
  851. case CX88_BOARD_HAUPPAUGE_HVR1300:
  852. fe0->dvb.frontend = dvb_attach(cx22702_attach,
  853. &hauppauge_hvr_config,
  854. &core->i2c_adap);
  855. if (fe0->dvb.frontend != NULL) {
  856. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  857. &core->i2c_adap, 0x61,
  858. TUNER_PHILIPS_FMD1216ME_MK3))
  859. goto frontend_detach;
  860. }
  861. break;
  862. case CX88_BOARD_WINFAST_DTV2000H_J:
  863. fe0->dvb.frontend = dvb_attach(cx22702_attach,
  864. &hauppauge_hvr_config,
  865. &core->i2c_adap);
  866. if (fe0->dvb.frontend != NULL) {
  867. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  868. &core->i2c_adap, 0x61,
  869. TUNER_PHILIPS_FMD1216MEX_MK3))
  870. goto frontend_detach;
  871. }
  872. break;
  873. case CX88_BOARD_HAUPPAUGE_HVR3000:
  874. /* MFE frontend 1 */
  875. mfe_shared = 1;
  876. dev->frontends.gate = 2;
  877. /* DVB-S init */
  878. fe0->dvb.frontend = dvb_attach(cx24123_attach,
  879. &hauppauge_novas_config,
  880. &dev->core->i2c_adap);
  881. if (fe0->dvb.frontend) {
  882. if (!dvb_attach(isl6421_attach,
  883. fe0->dvb.frontend,
  884. &dev->core->i2c_adap,
  885. 0x08, ISL6421_DCL, 0x00))
  886. goto frontend_detach;
  887. }
  888. /* MFE frontend 2 */
  889. fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2);
  890. if (!fe1)
  891. goto frontend_detach;
  892. /* DVB-T init */
  893. fe1->dvb.frontend = dvb_attach(cx22702_attach,
  894. &hauppauge_hvr_config,
  895. &dev->core->i2c_adap);
  896. if (fe1->dvb.frontend) {
  897. fe1->dvb.frontend->id = 1;
  898. if (!dvb_attach(simple_tuner_attach,
  899. fe1->dvb.frontend,
  900. &dev->core->i2c_adap,
  901. 0x61, TUNER_PHILIPS_FMD1216ME_MK3))
  902. goto frontend_detach;
  903. }
  904. break;
  905. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
  906. fe0->dvb.frontend = dvb_attach(mt352_attach,
  907. &dvico_fusionhdtv,
  908. &core->i2c_adap);
  909. if (fe0->dvb.frontend != NULL) {
  910. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  911. 0x60, NULL, DVB_PLL_THOMSON_DTT7579))
  912. goto frontend_detach;
  913. break;
  914. }
  915. /* ZL10353 replaces MT352 on later cards */
  916. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  917. &dvico_fusionhdtv_plus_v1_1,
  918. &core->i2c_adap);
  919. if (fe0->dvb.frontend != NULL) {
  920. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  921. 0x60, NULL, DVB_PLL_THOMSON_DTT7579))
  922. goto frontend_detach;
  923. }
  924. break;
  925. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
  926. /* The tin box says DEE1601, but it seems to be DTT7579
  927. * compatible, with a slightly different MT352 AGC gain. */
  928. fe0->dvb.frontend = dvb_attach(mt352_attach,
  929. &dvico_fusionhdtv_dual,
  930. &core->i2c_adap);
  931. if (fe0->dvb.frontend != NULL) {
  932. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  933. 0x61, NULL, DVB_PLL_THOMSON_DTT7579))
  934. goto frontend_detach;
  935. break;
  936. }
  937. /* ZL10353 replaces MT352 on later cards */
  938. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  939. &dvico_fusionhdtv_plus_v1_1,
  940. &core->i2c_adap);
  941. if (fe0->dvb.frontend != NULL) {
  942. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  943. 0x61, NULL, DVB_PLL_THOMSON_DTT7579))
  944. goto frontend_detach;
  945. }
  946. break;
  947. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
  948. fe0->dvb.frontend = dvb_attach(mt352_attach,
  949. &dvico_fusionhdtv,
  950. &core->i2c_adap);
  951. if (fe0->dvb.frontend != NULL) {
  952. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  953. 0x61, NULL, DVB_PLL_LG_Z201))
  954. goto frontend_detach;
  955. }
  956. break;
  957. case CX88_BOARD_KWORLD_DVB_T:
  958. case CX88_BOARD_DNTV_LIVE_DVB_T:
  959. case CX88_BOARD_ADSTECH_DVB_T_PCI:
  960. fe0->dvb.frontend = dvb_attach(mt352_attach,
  961. &dntv_live_dvbt_config,
  962. &core->i2c_adap);
  963. if (fe0->dvb.frontend != NULL) {
  964. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend,
  965. 0x61, NULL, DVB_PLL_UNKNOWN_1))
  966. goto frontend_detach;
  967. }
  968. break;
  969. case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
  970. #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
  971. /* MT352 is on a secondary I2C bus made from some GPIO lines */
  972. fe0->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
  973. &dev->vp3054->adap);
  974. if (fe0->dvb.frontend != NULL) {
  975. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  976. &core->i2c_adap, 0x61,
  977. TUNER_PHILIPS_FMD1216ME_MK3))
  978. goto frontend_detach;
  979. }
  980. #else
  981. printk(KERN_ERR "%s/2: built without vp3054 support\n",
  982. core->name);
  983. #endif
  984. break;
  985. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
  986. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  987. &dvico_fusionhdtv_hybrid,
  988. &core->i2c_adap);
  989. if (fe0->dvb.frontend != NULL) {
  990. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  991. &core->i2c_adap, 0x61,
  992. TUNER_THOMSON_FE6600))
  993. goto frontend_detach;
  994. }
  995. break;
  996. case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
  997. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  998. &dvico_fusionhdtv_xc3028,
  999. &core->i2c_adap);
  1000. if (fe0->dvb.frontend == NULL)
  1001. fe0->dvb.frontend = dvb_attach(mt352_attach,
  1002. &dvico_fusionhdtv_mt352_xc3028,
  1003. &core->i2c_adap);
  1004. /*
  1005. * On this board, the demod provides the I2C bus pullup.
  1006. * We must not permit gate_ctrl to be performed, or
  1007. * the xc3028 cannot communicate on the bus.
  1008. */
  1009. if (fe0->dvb.frontend)
  1010. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1011. if (attach_xc3028(0x61, dev) < 0)
  1012. goto frontend_detach;
  1013. break;
  1014. case CX88_BOARD_PCHDTV_HD3000:
  1015. fe0->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,
  1016. &core->i2c_adap);
  1017. if (fe0->dvb.frontend != NULL) {
  1018. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1019. &core->i2c_adap, 0x61,
  1020. TUNER_THOMSON_DTT761X))
  1021. goto frontend_detach;
  1022. }
  1023. break;
  1024. case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
  1025. dev->ts_gen_cntrl = 0x08;
  1026. /* Do a hardware reset of chip before using it. */
  1027. cx_clear(MO_GP0_IO, 1);
  1028. mdelay(100);
  1029. cx_set(MO_GP0_IO, 1);
  1030. mdelay(200);
  1031. /* Select RF connector callback */
  1032. fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
  1033. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  1034. &fusionhdtv_3_gold,
  1035. &core->i2c_adap);
  1036. if (fe0->dvb.frontend != NULL) {
  1037. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1038. &core->i2c_adap, 0x61,
  1039. TUNER_MICROTUNE_4042FI5))
  1040. goto frontend_detach;
  1041. }
  1042. break;
  1043. case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
  1044. dev->ts_gen_cntrl = 0x08;
  1045. /* Do a hardware reset of chip before using it. */
  1046. cx_clear(MO_GP0_IO, 1);
  1047. mdelay(100);
  1048. cx_set(MO_GP0_IO, 9);
  1049. mdelay(200);
  1050. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  1051. &fusionhdtv_3_gold,
  1052. &core->i2c_adap);
  1053. if (fe0->dvb.frontend != NULL) {
  1054. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1055. &core->i2c_adap, 0x61,
  1056. TUNER_THOMSON_DTT761X))
  1057. goto frontend_detach;
  1058. }
  1059. break;
  1060. case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
  1061. dev->ts_gen_cntrl = 0x08;
  1062. /* Do a hardware reset of chip before using it. */
  1063. cx_clear(MO_GP0_IO, 1);
  1064. mdelay(100);
  1065. cx_set(MO_GP0_IO, 1);
  1066. mdelay(200);
  1067. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  1068. &fusionhdtv_5_gold,
  1069. &core->i2c_adap);
  1070. if (fe0->dvb.frontend != NULL) {
  1071. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1072. &core->i2c_adap, 0x61,
  1073. TUNER_LG_TDVS_H06XF))
  1074. goto frontend_detach;
  1075. if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,
  1076. &core->i2c_adap, 0x43))
  1077. goto frontend_detach;
  1078. }
  1079. break;
  1080. case CX88_BOARD_PCHDTV_HD5500:
  1081. dev->ts_gen_cntrl = 0x08;
  1082. /* Do a hardware reset of chip before using it. */
  1083. cx_clear(MO_GP0_IO, 1);
  1084. mdelay(100);
  1085. cx_set(MO_GP0_IO, 1);
  1086. mdelay(200);
  1087. fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
  1088. &pchdtv_hd5500,
  1089. &core->i2c_adap);
  1090. if (fe0->dvb.frontend != NULL) {
  1091. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1092. &core->i2c_adap, 0x61,
  1093. TUNER_LG_TDVS_H06XF))
  1094. goto frontend_detach;
  1095. if (!dvb_attach(tda9887_attach, fe0->dvb.frontend,
  1096. &core->i2c_adap, 0x43))
  1097. goto frontend_detach;
  1098. }
  1099. break;
  1100. case CX88_BOARD_ATI_HDTVWONDER:
  1101. fe0->dvb.frontend = dvb_attach(nxt200x_attach,
  1102. &ati_hdtvwonder,
  1103. &core->i2c_adap);
  1104. if (fe0->dvb.frontend != NULL) {
  1105. if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
  1106. &core->i2c_adap, 0x61,
  1107. TUNER_PHILIPS_TUV1236D))
  1108. goto frontend_detach;
  1109. }
  1110. break;
  1111. case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
  1112. case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
  1113. fe0->dvb.frontend = dvb_attach(cx24123_attach,
  1114. &hauppauge_novas_config,
  1115. &core->i2c_adap);
  1116. if (fe0->dvb.frontend) {
  1117. if (!dvb_attach(isl6421_attach, fe0->dvb.frontend,
  1118. &core->i2c_adap, 0x08, ISL6421_DCL, 0x00))
  1119. goto frontend_detach;
  1120. }
  1121. break;
  1122. case CX88_BOARD_KWORLD_DVBS_100:
  1123. fe0->dvb.frontend = dvb_attach(cx24123_attach,
  1124. &kworld_dvbs_100_config,
  1125. &core->i2c_adap);
  1126. if (fe0->dvb.frontend) {
  1127. core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
  1128. fe0->dvb.frontend->ops.set_voltage = kworld_dvbs_100_set_voltage;
  1129. }
  1130. break;
  1131. case CX88_BOARD_GENIATECH_DVBS:
  1132. fe0->dvb.frontend = dvb_attach(cx24123_attach,
  1133. &geniatech_dvbs_config,
  1134. &core->i2c_adap);
  1135. if (fe0->dvb.frontend) {
  1136. core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
  1137. fe0->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
  1138. }
  1139. break;
  1140. case CX88_BOARD_PINNACLE_PCTV_HD_800i:
  1141. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1142. &pinnacle_pctv_hd_800i_config,
  1143. &core->i2c_adap);
  1144. if (fe0->dvb.frontend != NULL) {
  1145. if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1146. &core->i2c_adap,
  1147. &pinnacle_pctv_hd_800i_tuner_config))
  1148. goto frontend_detach;
  1149. }
  1150. break;
  1151. case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
  1152. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1153. &dvico_hdtv5_pci_nano_config,
  1154. &core->i2c_adap);
  1155. if (fe0->dvb.frontend != NULL) {
  1156. struct dvb_frontend *fe;
  1157. struct xc2028_config cfg = {
  1158. .i2c_adap = &core->i2c_adap,
  1159. .i2c_addr = 0x61,
  1160. };
  1161. static struct xc2028_ctrl ctl = {
  1162. .fname = XC2028_DEFAULT_FIRMWARE,
  1163. .max_len = 64,
  1164. .scode_table = XC3028_FE_OREN538,
  1165. };
  1166. fe = dvb_attach(xc2028_attach,
  1167. fe0->dvb.frontend, &cfg);
  1168. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  1169. fe->ops.tuner_ops.set_config(fe, &ctl);
  1170. }
  1171. break;
  1172. case CX88_BOARD_PINNACLE_HYBRID_PCTV:
  1173. case CX88_BOARD_WINFAST_DTV1800H:
  1174. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1175. &cx88_pinnacle_hybrid_pctv,
  1176. &core->i2c_adap);
  1177. if (fe0->dvb.frontend) {
  1178. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1179. if (attach_xc3028(0x61, dev) < 0)
  1180. goto frontend_detach;
  1181. }
  1182. break;
  1183. case CX88_BOARD_WINFAST_DTV1800H_XC4000:
  1184. case CX88_BOARD_WINFAST_DTV2000H_PLUS:
  1185. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1186. &cx88_pinnacle_hybrid_pctv,
  1187. &core->i2c_adap);
  1188. if (fe0->dvb.frontend) {
  1189. struct xc4000_config cfg = {
  1190. .i2c_address = 0x61,
  1191. .default_pm = 0,
  1192. .dvb_amplitude = 134,
  1193. .set_smoothedcvbs = 1,
  1194. .if_khz = 4560
  1195. };
  1196. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1197. if (attach_xc4000(dev, &cfg) < 0)
  1198. goto frontend_detach;
  1199. }
  1200. break;
  1201. case CX88_BOARD_GENIATECH_X8000_MT:
  1202. dev->ts_gen_cntrl = 0x00;
  1203. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1204. &cx88_geniatech_x8000_mt,
  1205. &core->i2c_adap);
  1206. if (attach_xc3028(0x61, dev) < 0)
  1207. goto frontend_detach;
  1208. break;
  1209. case CX88_BOARD_KWORLD_ATSC_120:
  1210. fe0->dvb.frontend = dvb_attach(s5h1409_attach,
  1211. &kworld_atsc_120_config,
  1212. &core->i2c_adap);
  1213. if (attach_xc3028(0x61, dev) < 0)
  1214. goto frontend_detach;
  1215. break;
  1216. case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
  1217. fe0->dvb.frontend = dvb_attach(s5h1411_attach,
  1218. &dvico_fusionhdtv7_config,
  1219. &core->i2c_adap);
  1220. if (fe0->dvb.frontend != NULL) {
  1221. if (!dvb_attach(xc5000_attach, fe0->dvb.frontend,
  1222. &core->i2c_adap,
  1223. &dvico_fusionhdtv7_tuner_config))
  1224. goto frontend_detach;
  1225. }
  1226. break;
  1227. case CX88_BOARD_HAUPPAUGE_HVR4000:
  1228. /* MFE frontend 1 */
  1229. mfe_shared = 1;
  1230. dev->frontends.gate = 2;
  1231. /* DVB-S/S2 Init */
  1232. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1233. &hauppauge_hvr4000_config,
  1234. &dev->core->i2c_adap);
  1235. if (fe0->dvb.frontend) {
  1236. if (!dvb_attach(isl6421_attach,
  1237. fe0->dvb.frontend,
  1238. &dev->core->i2c_adap,
  1239. 0x08, ISL6421_DCL, 0x00))
  1240. goto frontend_detach;
  1241. }
  1242. /* MFE frontend 2 */
  1243. fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2);
  1244. if (!fe1)
  1245. goto frontend_detach;
  1246. /* DVB-T Init */
  1247. fe1->dvb.frontend = dvb_attach(cx22702_attach,
  1248. &hauppauge_hvr_config,
  1249. &dev->core->i2c_adap);
  1250. if (fe1->dvb.frontend) {
  1251. fe1->dvb.frontend->id = 1;
  1252. if (!dvb_attach(simple_tuner_attach,
  1253. fe1->dvb.frontend,
  1254. &dev->core->i2c_adap,
  1255. 0x61, TUNER_PHILIPS_FMD1216ME_MK3))
  1256. goto frontend_detach;
  1257. }
  1258. break;
  1259. case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
  1260. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1261. &hauppauge_hvr4000_config,
  1262. &dev->core->i2c_adap);
  1263. if (fe0->dvb.frontend) {
  1264. if (!dvb_attach(isl6421_attach,
  1265. fe0->dvb.frontend,
  1266. &dev->core->i2c_adap,
  1267. 0x08, ISL6421_DCL, 0x00))
  1268. goto frontend_detach;
  1269. }
  1270. break;
  1271. case CX88_BOARD_PROF_6200:
  1272. case CX88_BOARD_TBS_8910:
  1273. case CX88_BOARD_TEVII_S420:
  1274. fe0->dvb.frontend = dvb_attach(stv0299_attach,
  1275. &tevii_tuner_sharp_config,
  1276. &core->i2c_adap);
  1277. if (fe0->dvb.frontend != NULL) {
  1278. if (!dvb_attach(dvb_pll_attach, fe0->dvb.frontend, 0x60,
  1279. &core->i2c_adap, DVB_PLL_OPERA1))
  1280. goto frontend_detach;
  1281. core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
  1282. fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
  1283. } else {
  1284. fe0->dvb.frontend = dvb_attach(stv0288_attach,
  1285. &tevii_tuner_earda_config,
  1286. &core->i2c_adap);
  1287. if (fe0->dvb.frontend != NULL) {
  1288. if (!dvb_attach(stb6000_attach, fe0->dvb.frontend, 0x61,
  1289. &core->i2c_adap))
  1290. goto frontend_detach;
  1291. core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
  1292. fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
  1293. }
  1294. }
  1295. break;
  1296. case CX88_BOARD_TEVII_S460:
  1297. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1298. &tevii_s460_config,
  1299. &core->i2c_adap);
  1300. if (fe0->dvb.frontend != NULL)
  1301. fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
  1302. break;
  1303. case CX88_BOARD_TEVII_S464:
  1304. fe0->dvb.frontend = dvb_attach(ds3000_attach,
  1305. &tevii_ds3000_config,
  1306. &core->i2c_adap);
  1307. if (fe0->dvb.frontend != NULL) {
  1308. dvb_attach(ts2020_attach, fe0->dvb.frontend,
  1309. &tevii_ts2020_config, &core->i2c_adap);
  1310. fe0->dvb.frontend->ops.set_voltage =
  1311. tevii_dvbs_set_voltage;
  1312. }
  1313. break;
  1314. case CX88_BOARD_OMICOM_SS4_PCI:
  1315. case CX88_BOARD_TBS_8920:
  1316. case CX88_BOARD_PROF_7300:
  1317. case CX88_BOARD_SATTRADE_ST4200:
  1318. fe0->dvb.frontend = dvb_attach(cx24116_attach,
  1319. &hauppauge_hvr4000_config,
  1320. &core->i2c_adap);
  1321. if (fe0->dvb.frontend != NULL)
  1322. fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
  1323. break;
  1324. case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII:
  1325. fe0->dvb.frontend = dvb_attach(zl10353_attach,
  1326. &cx88_terratec_cinergy_ht_pci_mkii_config,
  1327. &core->i2c_adap);
  1328. if (fe0->dvb.frontend) {
  1329. fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
  1330. if (attach_xc3028(0x61, dev) < 0)
  1331. goto frontend_detach;
  1332. }
  1333. break;
  1334. case CX88_BOARD_PROF_7301:{
  1335. struct dvb_tuner_ops *tuner_ops = NULL;
  1336. fe0->dvb.frontend = dvb_attach(stv0900_attach,
  1337. &prof_7301_stv0900_config,
  1338. &core->i2c_adap, 0);
  1339. if (fe0->dvb.frontend != NULL) {
  1340. if (!dvb_attach(stb6100_attach, fe0->dvb.frontend,
  1341. &prof_7301_stb6100_config,
  1342. &core->i2c_adap))
  1343. goto frontend_detach;
  1344. tuner_ops = &fe0->dvb.frontend->ops.tuner_ops;
  1345. tuner_ops->set_frequency = stb6100_set_freq;
  1346. tuner_ops->get_frequency = stb6100_get_freq;
  1347. tuner_ops->set_bandwidth = stb6100_set_bandw;
  1348. tuner_ops->get_bandwidth = stb6100_get_bandw;
  1349. core->prev_set_voltage =
  1350. fe0->dvb.frontend->ops.set_voltage;
  1351. fe0->dvb.frontend->ops.set_voltage =
  1352. tevii_dvbs_set_voltage;
  1353. }
  1354. break;
  1355. }
  1356. case CX88_BOARD_SAMSUNG_SMT_7020:
  1357. dev->ts_gen_cntrl = 0x08;
  1358. cx_set(MO_GP0_IO, 0x0101);
  1359. cx_clear(MO_GP0_IO, 0x01);
  1360. mdelay(100);
  1361. cx_set(MO_GP0_IO, 0x01);
  1362. mdelay(200);
  1363. fe0->dvb.frontend = dvb_attach(stv0299_attach,
  1364. &samsung_stv0299_config,
  1365. &dev->core->i2c_adap);
  1366. if (fe0->dvb.frontend) {
  1367. fe0->dvb.frontend->ops.tuner_ops.set_params =
  1368. samsung_smt_7020_tuner_set_params;
  1369. fe0->dvb.frontend->tuner_priv =
  1370. &dev->core->i2c_adap;
  1371. fe0->dvb.frontend->ops.set_voltage =
  1372. samsung_smt_7020_set_voltage;
  1373. fe0->dvb.frontend->ops.set_tone =
  1374. samsung_smt_7020_set_tone;
  1375. }
  1376. break;
  1377. case CX88_BOARD_TWINHAN_VP1027_DVBS:
  1378. dev->ts_gen_cntrl = 0x00;
  1379. fe0->dvb.frontend = dvb_attach(mb86a16_attach,
  1380. &twinhan_vp1027,
  1381. &core->i2c_adap);
  1382. if (fe0->dvb.frontend) {
  1383. core->prev_set_voltage =
  1384. fe0->dvb.frontend->ops.set_voltage;
  1385. fe0->dvb.frontend->ops.set_voltage =
  1386. vp1027_set_voltage;
  1387. }
  1388. break;
  1389. default:
  1390. printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
  1391. core->name);
  1392. break;
  1393. }
  1394. if ( (NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend) ) {
  1395. printk(KERN_ERR
  1396. "%s/2: frontend initialization failed\n",
  1397. core->name);
  1398. goto frontend_detach;
  1399. }
  1400. /* define general-purpose callback pointer */
  1401. fe0->dvb.frontend->callback = cx88_tuner_callback;
  1402. /* Ensure all frontends negotiate bus access */
  1403. fe0->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
  1404. if (fe1)
  1405. fe1->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
  1406. /* Put the analog decoder in standby to keep it quiet */
  1407. call_all(core, core, s_power, 0);
  1408. /* register everything */
  1409. res = videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
  1410. &dev->pci->dev, adapter_nr, mfe_shared);
  1411. if (res)
  1412. goto frontend_detach;
  1413. return res;
  1414. frontend_detach:
  1415. core->gate_ctrl = NULL;
  1416. videobuf_dvb_dealloc_frontends(&dev->frontends);
  1417. return res;
  1418. }
  1419. /* ----------------------------------------------------------- */
  1420. /* CX8802 MPEG -> mini driver - We have been given the hardware */
  1421. static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
  1422. {
  1423. struct cx88_core *core = drv->core;
  1424. int err = 0;
  1425. dprintk( 1, "%s\n", __func__);
  1426. switch (core->boardnr) {
  1427. case CX88_BOARD_HAUPPAUGE_HVR1300:
  1428. /* We arrive here with either the cx23416 or the cx22702
  1429. * on the bus. Take the bus from the cx23416 and enable the
  1430. * cx22702 demod
  1431. */
  1432. /* Toggle reset on cx22702 leaving i2c active */
  1433. cx_set(MO_GP0_IO, 0x00000080);
  1434. udelay(1000);
  1435. cx_clear(MO_GP0_IO, 0x00000080);
  1436. udelay(50);
  1437. cx_set(MO_GP0_IO, 0x00000080);
  1438. udelay(1000);
  1439. /* enable the cx22702 pins */
  1440. cx_clear(MO_GP0_IO, 0x00000004);
  1441. udelay(1000);
  1442. break;
  1443. case CX88_BOARD_HAUPPAUGE_HVR3000:
  1444. case CX88_BOARD_HAUPPAUGE_HVR4000:
  1445. /* Toggle reset on cx22702 leaving i2c active */
  1446. cx_set(MO_GP0_IO, 0x00000080);
  1447. udelay(1000);
  1448. cx_clear(MO_GP0_IO, 0x00000080);
  1449. udelay(50);
  1450. cx_set(MO_GP0_IO, 0x00000080);
  1451. udelay(1000);
  1452. switch (core->dvbdev->frontends.active_fe_id) {
  1453. case 1: /* DVB-S/S2 Enabled */
  1454. /* tri-state the cx22702 pins */
  1455. cx_set(MO_GP0_IO, 0x00000004);
  1456. /* Take the cx24116/cx24123 out of reset */
  1457. cx_write(MO_SRST_IO, 1);
  1458. core->dvbdev->ts_gen_cntrl = 0x02; /* Parallel IO */
  1459. break;
  1460. case 2: /* DVB-T Enabled */
  1461. /* Put the cx24116/cx24123 into reset */
  1462. cx_write(MO_SRST_IO, 0);
  1463. /* enable the cx22702 pins */
  1464. cx_clear(MO_GP0_IO, 0x00000004);
  1465. core->dvbdev->ts_gen_cntrl = 0x0c; /* Serial IO */
  1466. break;
  1467. }
  1468. udelay(1000);
  1469. break;
  1470. case CX88_BOARD_WINFAST_DTV2000H_PLUS:
  1471. /* set RF input to AIR for DVB-T (GPIO 16) */
  1472. cx_write(MO_GP2_IO, 0x0101);
  1473. break;
  1474. default:
  1475. err = -ENODEV;
  1476. }
  1477. return err;
  1478. }
  1479. /* CX8802 MPEG -> mini driver - We no longer have the hardware */
  1480. static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
  1481. {
  1482. struct cx88_core *core = drv->core;
  1483. int err = 0;
  1484. dprintk( 1, "%s\n", __func__);
  1485. switch (core->boardnr) {
  1486. case CX88_BOARD_HAUPPAUGE_HVR1300:
  1487. /* Do Nothing, leave the cx22702 on the bus. */
  1488. break;
  1489. case CX88_BOARD_HAUPPAUGE_HVR3000:
  1490. case CX88_BOARD_HAUPPAUGE_HVR4000:
  1491. break;
  1492. default:
  1493. err = -ENODEV;
  1494. }
  1495. return err;
  1496. }
  1497. static int cx8802_dvb_probe(struct cx8802_driver *drv)
  1498. {
  1499. struct cx88_core *core = drv->core;
  1500. struct cx8802_dev *dev = drv->core->dvbdev;
  1501. int err;
  1502. struct videobuf_dvb_frontend *fe;
  1503. int i;
  1504. dprintk( 1, "%s\n", __func__);
  1505. dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  1506. core->boardnr,
  1507. core->name,
  1508. core->pci_bus,
  1509. core->pci_slot);
  1510. err = -ENODEV;
  1511. if (!(core->board.mpeg & CX88_MPEG_DVB))
  1512. goto fail_core;
  1513. /* If vp3054 isn't enabled, a stub will just return 0 */
  1514. err = vp3054_i2c_probe(dev);
  1515. if (0 != err)
  1516. goto fail_core;
  1517. /* dvb stuff */
  1518. printk(KERN_INFO "%s/2: cx2388x based DVB/ATSC card\n", core->name);
  1519. dev->ts_gen_cntrl = 0x0c;
  1520. err = cx8802_alloc_frontends(dev);
  1521. if (err)
  1522. goto fail_core;
  1523. err = -ENODEV;
  1524. for (i = 1; i <= core->board.num_frontends; i++) {
  1525. fe = videobuf_dvb_get_frontend(&core->dvbdev->frontends, i);
  1526. if (fe == NULL) {
  1527. printk(KERN_ERR "%s() failed to get frontend(%d)\n",
  1528. __func__, i);
  1529. goto fail_probe;
  1530. }
  1531. videobuf_queue_sg_init(&fe->dvb.dvbq, &dvb_qops,
  1532. &dev->pci->dev, &dev->slock,
  1533. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  1534. V4L2_FIELD_TOP,
  1535. sizeof(struct cx88_buffer),
  1536. dev, NULL);
  1537. /* init struct videobuf_dvb */
  1538. fe->dvb.name = dev->core->name;
  1539. }
  1540. err = dvb_register(dev);
  1541. if (err)
  1542. /* frontends/adapter de-allocated in dvb_register */
  1543. printk(KERN_ERR "%s/2: dvb_register failed (err = %d)\n",
  1544. core->name, err);
  1545. return err;
  1546. fail_probe:
  1547. videobuf_dvb_dealloc_frontends(&core->dvbdev->frontends);
  1548. fail_core:
  1549. return err;
  1550. }
  1551. static int cx8802_dvb_remove(struct cx8802_driver *drv)
  1552. {
  1553. struct cx88_core *core = drv->core;
  1554. struct cx8802_dev *dev = drv->core->dvbdev;
  1555. dprintk( 1, "%s\n", __func__);
  1556. videobuf_dvb_unregister_bus(&dev->frontends);
  1557. vp3054_i2c_remove(dev);
  1558. core->gate_ctrl = NULL;
  1559. return 0;
  1560. }
  1561. static struct cx8802_driver cx8802_dvb_driver = {
  1562. .type_id = CX88_MPEG_DVB,
  1563. .hw_access = CX8802_DRVCTL_SHARED,
  1564. .probe = cx8802_dvb_probe,
  1565. .remove = cx8802_dvb_remove,
  1566. .advise_acquire = cx8802_dvb_advise_acquire,
  1567. .advise_release = cx8802_dvb_advise_release,
  1568. };
  1569. static int __init dvb_init(void)
  1570. {
  1571. printk(KERN_INFO "cx88/2: cx2388x dvb driver version %s loaded\n",
  1572. CX88_VERSION);
  1573. return cx8802_register_driver(&cx8802_dvb_driver);
  1574. }
  1575. static void __exit dvb_fini(void)
  1576. {
  1577. cx8802_unregister_driver(&cx8802_dvb_driver);
  1578. }
  1579. module_init(dvb_init);
  1580. module_exit(dvb_fini);