cx23885-dvb.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 "dvb-pll.h"
  37. #include "tuner-xc2028.h"
  38. #include "tuner-xc2028-types.h"
  39. static unsigned int debug;
  40. #define dprintk(level, fmt, arg...)\
  41. do { if (debug >= level)\
  42. printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
  43. } while (0)
  44. /* ------------------------------------------------------------------ */
  45. static unsigned int alt_tuner;
  46. module_param(alt_tuner, int, 0644);
  47. MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
  48. /* ------------------------------------------------------------------ */
  49. static int dvb_buf_setup(struct videobuf_queue *q,
  50. unsigned int *count, unsigned int *size)
  51. {
  52. struct cx23885_tsport *port = q->priv_data;
  53. port->ts_packet_size = 188 * 4;
  54. port->ts_packet_count = 32;
  55. *size = port->ts_packet_size * port->ts_packet_count;
  56. *count = 32;
  57. return 0;
  58. }
  59. static int dvb_buf_prepare(struct videobuf_queue *q,
  60. struct videobuf_buffer *vb, enum v4l2_field field)
  61. {
  62. struct cx23885_tsport *port = q->priv_data;
  63. return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
  64. }
  65. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  66. {
  67. struct cx23885_tsport *port = q->priv_data;
  68. cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
  69. }
  70. static void dvb_buf_release(struct videobuf_queue *q,
  71. struct videobuf_buffer *vb)
  72. {
  73. cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
  74. }
  75. static struct videobuf_queue_ops dvb_qops = {
  76. .buf_setup = dvb_buf_setup,
  77. .buf_prepare = dvb_buf_prepare,
  78. .buf_queue = dvb_buf_queue,
  79. .buf_release = dvb_buf_release,
  80. };
  81. static struct s5h1409_config hauppauge_generic_config = {
  82. .demod_address = 0x32 >> 1,
  83. .output_mode = S5H1409_SERIAL_OUTPUT,
  84. .gpio = S5H1409_GPIO_ON,
  85. .qam_if = 44000,
  86. .inversion = S5H1409_INVERSION_OFF,
  87. .status_mode = S5H1409_DEMODLOCKING,
  88. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  89. };
  90. static struct s5h1409_config hauppauge_ezqam_config = {
  91. .demod_address = 0x32 >> 1,
  92. .output_mode = S5H1409_SERIAL_OUTPUT,
  93. .gpio = S5H1409_GPIO_OFF,
  94. .qam_if = 4000,
  95. .inversion = S5H1409_INVERSION_ON,
  96. .status_mode = S5H1409_DEMODLOCKING,
  97. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  98. };
  99. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  100. .demod_address = 0x32 >> 1,
  101. .output_mode = S5H1409_SERIAL_OUTPUT,
  102. .gpio = S5H1409_GPIO_OFF,
  103. .qam_if = 44000,
  104. .inversion = S5H1409_INVERSION_OFF,
  105. .status_mode = S5H1409_DEMODLOCKING,
  106. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  107. };
  108. static struct s5h1409_config hauppauge_hvr1500_config = {
  109. .demod_address = 0x32 >> 1,
  110. .output_mode = S5H1409_SERIAL_OUTPUT,
  111. .gpio = S5H1409_GPIO_OFF,
  112. .inversion = S5H1409_INVERSION_OFF,
  113. .status_mode = S5H1409_DEMODLOCKING,
  114. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  115. };
  116. static struct mt2131_config hauppauge_generic_tunerconfig = {
  117. 0x61
  118. };
  119. static struct lgdt330x_config fusionhdtv_5_express = {
  120. .demod_address = 0x0e,
  121. .demod_chip = LGDT3303,
  122. .serial_mpeg = 0x40,
  123. };
  124. static struct s5h1409_config hauppauge_hvr1500q_config = {
  125. .demod_address = 0x32 >> 1,
  126. .output_mode = S5H1409_SERIAL_OUTPUT,
  127. .gpio = S5H1409_GPIO_ON,
  128. .qam_if = 44000,
  129. .inversion = S5H1409_INVERSION_OFF,
  130. .status_mode = S5H1409_DEMODLOCKING,
  131. .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
  132. };
  133. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  134. .i2c_address = 0x61,
  135. .if_khz = 5380,
  136. .tuner_callback = cx23885_tuner_callback
  137. };
  138. static struct tda829x_config tda829x_no_probe = {
  139. .probe_tuner = TDA829X_DONT_PROBE,
  140. };
  141. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  142. .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3 },
  143. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0 },
  144. };
  145. static struct tda18271_config hauppauge_tda18271_config = {
  146. .std_map = &hauppauge_tda18271_std_map,
  147. .gate = TDA18271_GATE_ANALOG,
  148. };
  149. static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
  150. {
  151. struct cx23885_tsport *port = ptr;
  152. struct cx23885_dev *dev = port->dev;
  153. switch (command) {
  154. case XC2028_TUNER_RESET:
  155. /* Send the tuner in then out of reset */
  156. /* GPIO-2 xc3028 tuner */
  157. dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg);
  158. cx_set(GP0_IO, 0x00040000);
  159. cx_clear(GP0_IO, 0x00000004);
  160. msleep(5);
  161. cx_set(GP0_IO, 0x00040004);
  162. msleep(5);
  163. break;
  164. case XC2028_RESET_CLK:
  165. dprintk(1, "%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg);
  166. break;
  167. default:
  168. dprintk(1, "%s: unknown command %d, arg %d\n", __FUNCTION__,
  169. command, arg);
  170. return -EINVAL;
  171. }
  172. return 0;
  173. }
  174. static int dvb_register(struct cx23885_tsport *port)
  175. {
  176. struct cx23885_dev *dev = port->dev;
  177. struct cx23885_i2c *i2c_bus = NULL;
  178. /* init struct videobuf_dvb */
  179. port->dvb.name = dev->name;
  180. /* init frontend */
  181. switch (dev->board) {
  182. case CX23885_BOARD_HAUPPAUGE_HVR1250:
  183. i2c_bus = &dev->i2c_bus[0];
  184. port->dvb.frontend = dvb_attach(s5h1409_attach,
  185. &hauppauge_generic_config,
  186. &i2c_bus->i2c_adap);
  187. if (port->dvb.frontend != NULL) {
  188. dvb_attach(mt2131_attach, port->dvb.frontend,
  189. &i2c_bus->i2c_adap,
  190. &hauppauge_generic_tunerconfig, 0);
  191. }
  192. break;
  193. case CX23885_BOARD_HAUPPAUGE_HVR1800:
  194. i2c_bus = &dev->i2c_bus[0];
  195. switch (alt_tuner) {
  196. case 1:
  197. port->dvb.frontend =
  198. dvb_attach(s5h1409_attach,
  199. &hauppauge_ezqam_config,
  200. &i2c_bus->i2c_adap);
  201. if (port->dvb.frontend != NULL) {
  202. dvb_attach(tda829x_attach, port->dvb.frontend,
  203. &dev->i2c_bus[1].i2c_adap, 0x42,
  204. &tda829x_no_probe);
  205. dvb_attach(tda18271_attach, port->dvb.frontend,
  206. 0x60, &dev->i2c_bus[1].i2c_adap,
  207. &hauppauge_tda18271_config);
  208. }
  209. break;
  210. case 0:
  211. default:
  212. port->dvb.frontend =
  213. dvb_attach(s5h1409_attach,
  214. &hauppauge_generic_config,
  215. &i2c_bus->i2c_adap);
  216. if (port->dvb.frontend != NULL)
  217. dvb_attach(mt2131_attach, port->dvb.frontend,
  218. &i2c_bus->i2c_adap,
  219. &hauppauge_generic_tunerconfig, 0);
  220. break;
  221. }
  222. break;
  223. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  224. i2c_bus = &dev->i2c_bus[0];
  225. port->dvb.frontend = dvb_attach(s5h1409_attach,
  226. &hauppauge_hvr1800lp_config,
  227. &i2c_bus->i2c_adap);
  228. if (port->dvb.frontend != NULL) {
  229. dvb_attach(mt2131_attach, port->dvb.frontend,
  230. &i2c_bus->i2c_adap,
  231. &hauppauge_generic_tunerconfig, 0);
  232. }
  233. break;
  234. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  235. i2c_bus = &dev->i2c_bus[0];
  236. port->dvb.frontend = dvb_attach(lgdt330x_attach,
  237. &fusionhdtv_5_express,
  238. &i2c_bus->i2c_adap);
  239. if (port->dvb.frontend != NULL) {
  240. dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61,
  241. &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
  242. }
  243. break;
  244. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  245. i2c_bus = &dev->i2c_bus[1];
  246. port->dvb.frontend = dvb_attach(s5h1409_attach,
  247. &hauppauge_hvr1500q_config,
  248. &dev->i2c_bus[0].i2c_adap);
  249. if (port->dvb.frontend != NULL) {
  250. hauppauge_hvr1500q_tunerconfig.priv = i2c_bus;
  251. dvb_attach(xc5000_attach, port->dvb.frontend,
  252. &i2c_bus->i2c_adap,
  253. &hauppauge_hvr1500q_tunerconfig);
  254. }
  255. break;
  256. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  257. i2c_bus = &dev->i2c_bus[1];
  258. port->dvb.frontend = dvb_attach(s5h1409_attach,
  259. &hauppauge_hvr1500_config,
  260. &dev->i2c_bus[0].i2c_adap);
  261. if (port->dvb.frontend != NULL) {
  262. struct dvb_frontend *fe;
  263. struct xc2028_config cfg = {
  264. .i2c_adap = &i2c_bus->i2c_adap,
  265. .i2c_addr = 0x61,
  266. .video_dev = port,
  267. .callback = cx23885_hvr1500_xc3028_callback,
  268. };
  269. static struct xc2028_ctrl ctl = {
  270. .fname = "xc3028-v27.fw",
  271. .max_len = 64,
  272. .scode_table = OREN538,
  273. };
  274. fe = dvb_attach(xc2028_attach,
  275. port->dvb.frontend, &cfg);
  276. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  277. fe->ops.tuner_ops.set_config(fe, &ctl);
  278. }
  279. break;
  280. default:
  281. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  282. dev->name);
  283. break;
  284. }
  285. if (NULL == port->dvb.frontend) {
  286. printk("%s: frontend initialization failed\n", dev->name);
  287. return -1;
  288. }
  289. /* Put the analog decoder in standby to keep it quiet */
  290. cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
  291. if (port->dvb.frontend->ops.analog_ops.standby)
  292. port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend);
  293. /* register everything */
  294. return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
  295. &dev->pci->dev);
  296. }
  297. int cx23885_dvb_register(struct cx23885_tsport *port)
  298. {
  299. struct cx23885_dev *dev = port->dev;
  300. int err;
  301. dprintk(1, "%s\n", __FUNCTION__);
  302. dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  303. dev->board,
  304. dev->name,
  305. dev->pci_bus,
  306. dev->pci_slot);
  307. err = -ENODEV;
  308. /* dvb stuff */
  309. printk("%s: cx23885 based dvb card\n", dev->name);
  310. videobuf_queue_sg_init(&port->dvb.dvbq, &dvb_qops, &dev->pci->dev, &port->slock,
  311. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  312. sizeof(struct cx23885_buffer), port);
  313. err = dvb_register(port);
  314. if (err != 0)
  315. printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
  316. return err;
  317. }
  318. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  319. {
  320. /* dvb */
  321. if(port->dvb.frontend)
  322. videobuf_dvb_unregister(&port->dvb);
  323. return 0;
  324. }
  325. /*
  326. * Local variables:
  327. * c-basic-offset: 8
  328. * End:
  329. * 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
  330. */