cx23885-dvb.c 11 KB

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