cx23885-dvb.c 11 KB

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