cx23885-dvb.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * Driver for the Conexant CX23885 PCIe bridge
  3. *
  4. * Copyright (c) 2006 Steven Toth <stoth@hauppauge.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/device.h>
  24. #include <linux/fs.h>
  25. #include <linux/kthread.h>
  26. #include <linux/file.h>
  27. #include <linux/suspend.h>
  28. #include "cx23885.h"
  29. #include <media/v4l2-common.h>
  30. #include "s5h1409.h"
  31. #include "mt2131.h"
  32. #include "tda8290.h"
  33. #include "tda18271.h"
  34. #include "lgdt330x.h"
  35. #include "xc5000.h"
  36. #include "tda10048.h"
  37. #include "dvb-pll.h"
  38. #include "tuner-xc2028.h"
  39. #include "tuner-xc2028-types.h"
  40. #include "tuner-simple.h"
  41. static unsigned int debug;
  42. #define dprintk(level, fmt, arg...)\
  43. do { if (debug >= level)\
  44. printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
  45. } while (0)
  46. /* ------------------------------------------------------------------ */
  47. static unsigned int alt_tuner;
  48. module_param(alt_tuner, int, 0644);
  49. MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
  50. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  51. /* ------------------------------------------------------------------ */
  52. static int dvb_buf_setup(struct videobuf_queue *q,
  53. unsigned int *count, unsigned int *size)
  54. {
  55. struct cx23885_tsport *port = q->priv_data;
  56. port->ts_packet_size = 188 * 4;
  57. port->ts_packet_count = 32;
  58. *size = port->ts_packet_size * port->ts_packet_count;
  59. *count = 32;
  60. return 0;
  61. }
  62. static int dvb_buf_prepare(struct videobuf_queue *q,
  63. struct videobuf_buffer *vb, enum v4l2_field field)
  64. {
  65. struct cx23885_tsport *port = q->priv_data;
  66. return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
  67. }
  68. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  69. {
  70. struct cx23885_tsport *port = q->priv_data;
  71. cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
  72. }
  73. static void dvb_buf_release(struct videobuf_queue *q,
  74. struct videobuf_buffer *vb)
  75. {
  76. cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
  77. }
  78. static struct videobuf_queue_ops dvb_qops = {
  79. .buf_setup = dvb_buf_setup,
  80. .buf_prepare = dvb_buf_prepare,
  81. .buf_queue = dvb_buf_queue,
  82. .buf_release = dvb_buf_release,
  83. };
  84. static struct s5h1409_config hauppauge_generic_config = {
  85. .demod_address = 0x32 >> 1,
  86. .output_mode = S5H1409_SERIAL_OUTPUT,
  87. .gpio = S5H1409_GPIO_ON,
  88. .qam_if = 44000,
  89. .inversion = S5H1409_INVERSION_OFF,
  90. .status_mode = S5H1409_DEMODLOCKING,
  91. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  92. };
  93. static struct tda10048_config hauppauge_hvr1200_config = {
  94. .demod_address = 0x10 >> 1,
  95. .output_mode = TDA10048_SERIAL_OUTPUT,
  96. .fwbulkwritelen = TDA10048_BULKWRITE_200,
  97. .inversion = TDA10048_INVERSION_ON
  98. };
  99. static struct s5h1409_config hauppauge_ezqam_config = {
  100. .demod_address = 0x32 >> 1,
  101. .output_mode = S5H1409_SERIAL_OUTPUT,
  102. .gpio = S5H1409_GPIO_OFF,
  103. .qam_if = 4000,
  104. .inversion = S5H1409_INVERSION_ON,
  105. .status_mode = S5H1409_DEMODLOCKING,
  106. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  107. };
  108. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  109. .demod_address = 0x32 >> 1,
  110. .output_mode = S5H1409_SERIAL_OUTPUT,
  111. .gpio = S5H1409_GPIO_OFF,
  112. .qam_if = 44000,
  113. .inversion = S5H1409_INVERSION_OFF,
  114. .status_mode = S5H1409_DEMODLOCKING,
  115. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  116. };
  117. static struct s5h1409_config hauppauge_hvr1500_config = {
  118. .demod_address = 0x32 >> 1,
  119. .output_mode = S5H1409_SERIAL_OUTPUT,
  120. .gpio = S5H1409_GPIO_OFF,
  121. .inversion = S5H1409_INVERSION_OFF,
  122. .status_mode = S5H1409_DEMODLOCKING,
  123. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  124. };
  125. static struct mt2131_config hauppauge_generic_tunerconfig = {
  126. 0x61
  127. };
  128. static struct lgdt330x_config fusionhdtv_5_express = {
  129. .demod_address = 0x0e,
  130. .demod_chip = LGDT3303,
  131. .serial_mpeg = 0x40,
  132. };
  133. static struct s5h1409_config hauppauge_hvr1500q_config = {
  134. .demod_address = 0x32 >> 1,
  135. .output_mode = S5H1409_SERIAL_OUTPUT,
  136. .gpio = S5H1409_GPIO_ON,
  137. .qam_if = 44000,
  138. .inversion = S5H1409_INVERSION_OFF,
  139. .status_mode = S5H1409_DEMODLOCKING,
  140. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  141. };
  142. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  143. .i2c_address = 0x61,
  144. .if_khz = 5380,
  145. .tuner_callback = cx23885_tuner_callback
  146. };
  147. static struct tda829x_config tda829x_no_probe = {
  148. .probe_tuner = TDA829X_DONT_PROBE,
  149. };
  150. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  151. .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
  152. .if_lvl = 6, .rfagc_top = 0x37 },
  153. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
  154. .if_lvl = 6, .rfagc_top = 0x37 },
  155. };
  156. static struct tda18271_config hauppauge_tda18271_config = {
  157. .std_map = &hauppauge_tda18271_std_map,
  158. .gate = TDA18271_GATE_ANALOG,
  159. };
  160. static struct tda18271_config hauppauge_hvr1200_tuner_config = {
  161. .gate = TDA18271_GATE_ANALOG,
  162. };
  163. static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
  164. {
  165. struct cx23885_tsport *port = ptr;
  166. struct cx23885_dev *dev = port->dev;
  167. switch (command) {
  168. case XC2028_TUNER_RESET:
  169. /* Send the tuner in then out of reset */
  170. /* GPIO-2 xc3028 tuner */
  171. dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
  172. cx_set(GP0_IO, 0x00040000);
  173. cx_clear(GP0_IO, 0x00000004);
  174. msleep(5);
  175. cx_set(GP0_IO, 0x00040004);
  176. msleep(5);
  177. break;
  178. case XC2028_RESET_CLK:
  179. dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg);
  180. break;
  181. default:
  182. dprintk(1, "%s: unknown command %d, arg %d\n", __func__,
  183. command, arg);
  184. return -EINVAL;
  185. }
  186. return 0;
  187. }
  188. static int dvb_register(struct cx23885_tsport *port)
  189. {
  190. struct cx23885_dev *dev = port->dev;
  191. struct cx23885_i2c *i2c_bus = NULL;
  192. /* init struct videobuf_dvb */
  193. port->dvb.name = dev->name;
  194. /* init frontend */
  195. switch (dev->board) {
  196. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  197. i2c_bus = &dev->i2c_bus[0];
  198. port->dvb.frontend = dvb_attach(s5h1409_attach,
  199. &hauppauge_generic_config,
  200. &i2c_bus->i2c_adap);
  201. if (port->dvb.frontend != NULL) {
  202. dvb_attach(mt2131_attach, port->dvb.frontend,
  203. &i2c_bus->i2c_adap,
  204. &hauppauge_generic_tunerconfig, 0);
  205. }
  206. break;
  207. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  208. i2c_bus = &dev->i2c_bus[0];
  209. switch (alt_tuner) {
  210. case 1:
  211. port->dvb.frontend =
  212. dvb_attach(s5h1409_attach,
  213. &hauppauge_ezqam_config,
  214. &i2c_bus->i2c_adap);
  215. if (port->dvb.frontend != NULL) {
  216. dvb_attach(tda829x_attach, port->dvb.frontend,
  217. &dev->i2c_bus[1].i2c_adap, 0x42,
  218. &tda829x_no_probe);
  219. dvb_attach(tda18271_attach, port->dvb.frontend,
  220. 0x60, &dev->i2c_bus[1].i2c_adap,
  221. &hauppauge_tda18271_config);
  222. }
  223. break;
  224. case 0:
  225. default:
  226. port->dvb.frontend =
  227. dvb_attach(s5h1409_attach,
  228. &hauppauge_generic_config,
  229. &i2c_bus->i2c_adap);
  230. if (port->dvb.frontend != NULL)
  231. dvb_attach(mt2131_attach, port->dvb.frontend,
  232. &i2c_bus->i2c_adap,
  233. &hauppauge_generic_tunerconfig, 0);
  234. break;
  235. }
  236. break;
  237. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  238. i2c_bus = &dev->i2c_bus[0];
  239. port->dvb.frontend = dvb_attach(s5h1409_attach,
  240. &hauppauge_hvr1800lp_config,
  241. &i2c_bus->i2c_adap);
  242. if (port->dvb.frontend != NULL) {
  243. dvb_attach(mt2131_attach, port->dvb.frontend,
  244. &i2c_bus->i2c_adap,
  245. &hauppauge_generic_tunerconfig, 0);
  246. }
  247. break;
  248. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  249. i2c_bus = &dev->i2c_bus[0];
  250. port->dvb.frontend = dvb_attach(lgdt330x_attach,
  251. &fusionhdtv_5_express,
  252. &i2c_bus->i2c_adap);
  253. if (port->dvb.frontend != NULL) {
  254. dvb_attach(simple_tuner_attach, port->dvb.frontend,
  255. &i2c_bus->i2c_adap, 0x61,
  256. TUNER_LG_TDVS_H06XF);
  257. }
  258. break;
  259. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  260. i2c_bus = &dev->i2c_bus[1];
  261. port->dvb.frontend = dvb_attach(s5h1409_attach,
  262. &hauppauge_hvr1500q_config,
  263. &dev->i2c_bus[0].i2c_adap);
  264. if (port->dvb.frontend != NULL) {
  265. hauppauge_hvr1500q_tunerconfig.priv = i2c_bus;
  266. dvb_attach(xc5000_attach, port->dvb.frontend,
  267. &i2c_bus->i2c_adap,
  268. &hauppauge_hvr1500q_tunerconfig);
  269. }
  270. break;
  271. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  272. i2c_bus = &dev->i2c_bus[1];
  273. port->dvb.frontend = dvb_attach(s5h1409_attach,
  274. &hauppauge_hvr1500_config,
  275. &dev->i2c_bus[0].i2c_adap);
  276. if (port->dvb.frontend != NULL) {
  277. struct dvb_frontend *fe;
  278. struct xc2028_config cfg = {
  279. .i2c_adap = &i2c_bus->i2c_adap,
  280. .i2c_addr = 0x61,
  281. .callback = cx23885_hvr1500_xc3028_callback,
  282. };
  283. static struct xc2028_ctrl ctl = {
  284. .fname = "xc3028-v27.fw",
  285. .max_len = 64,
  286. .scode_table = OREN538,
  287. };
  288. fe = dvb_attach(xc2028_attach,
  289. port->dvb.frontend, &cfg);
  290. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  291. fe->ops.tuner_ops.set_config(fe, &ctl);
  292. }
  293. break;
  294. case CX23885_BOARD_HAUPPAUGE_HVR1200:
  295. case CX23885_BOARD_HAUPPAUGE_HVR1700:
  296. i2c_bus = &dev->i2c_bus[0];
  297. port->dvb.frontend = dvb_attach(tda10048_attach,
  298. &hauppauge_hvr1200_config,
  299. &i2c_bus->i2c_adap);
  300. if (port->dvb.frontend != NULL) {
  301. dvb_attach(tda829x_attach, port->dvb.frontend,
  302. &dev->i2c_bus[1].i2c_adap, 0x42,
  303. &tda829x_no_probe);
  304. dvb_attach(tda18271_attach, port->dvb.frontend,
  305. 0x60, &dev->i2c_bus[1].i2c_adap,
  306. &hauppauge_hvr1200_tuner_config);
  307. }
  308. break;
  309. default:
  310. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  311. dev->name);
  312. break;
  313. }
  314. if (NULL == port->dvb.frontend) {
  315. printk("%s: frontend initialization failed\n", dev->name);
  316. return -1;
  317. }
  318. /* Put the analog decoder in standby to keep it quiet */
  319. cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
  320. if (port->dvb.frontend->ops.analog_ops.standby)
  321. port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend);
  322. /* register everything */
  323. return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
  324. &dev->pci->dev, adapter_nr);
  325. }
  326. int cx23885_dvb_register(struct cx23885_tsport *port)
  327. {
  328. struct cx23885_dev *dev = port->dev;
  329. int err;
  330. dprintk(1, "%s\n", __func__);
  331. dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  332. dev->board,
  333. dev->name,
  334. dev->pci_bus,
  335. dev->pci_slot);
  336. err = -ENODEV;
  337. /* dvb stuff */
  338. printk("%s: cx23885 based dvb card\n", dev->name);
  339. videobuf_queue_sg_init(&port->dvb.dvbq, &dvb_qops, &dev->pci->dev, &port->slock,
  340. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  341. sizeof(struct cx23885_buffer), port);
  342. err = dvb_register(port);
  343. if (err != 0)
  344. printk("%s() dvb_register failed err = %d\n", __func__, err);
  345. return err;
  346. }
  347. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  348. {
  349. /* dvb */
  350. if(port->dvb.frontend)
  351. videobuf_dvb_unregister(&port->dvb);
  352. return 0;
  353. }
  354. /*
  355. * Local variables:
  356. * c-basic-offset: 8
  357. * End:
  358. * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
  359. */