cx23885-dvb.c 10 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 "lgdt330x.h"
  34. #include "xc5000.h"
  35. #include "dvb-pll.h"
  36. #include "tuner-xc2028.h"
  37. #include "tuner-xc2028-types.h"
  38. static unsigned int debug = 0;
  39. #define dprintk(level,fmt, arg...) if (debug >= level) \
  40. printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg)
  41. /* ------------------------------------------------------------------ */
  42. static unsigned int alt_tuner;
  43. module_param(alt_tuner, int, 0644);
  44. MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
  45. /* ------------------------------------------------------------------ */
  46. static int dvb_buf_setup(struct videobuf_queue *q,
  47. unsigned int *count, unsigned int *size)
  48. {
  49. struct cx23885_tsport *port = q->priv_data;
  50. port->ts_packet_size = 188 * 4;
  51. port->ts_packet_count = 32;
  52. *size = port->ts_packet_size * port->ts_packet_count;
  53. *count = 32;
  54. return 0;
  55. }
  56. static int dvb_buf_prepare(struct videobuf_queue *q,
  57. struct videobuf_buffer *vb, enum v4l2_field field)
  58. {
  59. struct cx23885_tsport *port = q->priv_data;
  60. return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
  61. }
  62. static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
  63. {
  64. struct cx23885_tsport *port = q->priv_data;
  65. cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
  66. }
  67. static void dvb_buf_release(struct videobuf_queue *q,
  68. struct videobuf_buffer *vb)
  69. {
  70. cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
  71. }
  72. static int cx23885_request_firmware(struct dvb_frontend *fe,
  73. const struct firmware **fw, char *name)
  74. {
  75. struct cx23885_tsport *port = fe->dvb->priv;
  76. struct cx23885_dev *dev = port->dev;
  77. dprintk(1, "%s(?,?,%s)\n", __FUNCTION__, name);
  78. return request_firmware(fw, name, &dev->pci->dev);
  79. }
  80. static int hauppauge_hvr1500q_tuner_reset(struct dvb_frontend *fe)
  81. {
  82. struct cx23885_tsport *port = fe->dvb->priv;
  83. struct cx23885_dev *dev = port->dev;
  84. dprintk(1, "%s()\n", __FUNCTION__);
  85. /* Drive the tuner into reset back back */
  86. cx_clear(GP0_IO, 0x00000004);
  87. mdelay(200);
  88. cx_set(GP0_IO, 0x00000004);
  89. return 0;
  90. }
  91. static struct videobuf_queue_ops dvb_qops = {
  92. .buf_setup = dvb_buf_setup,
  93. .buf_prepare = dvb_buf_prepare,
  94. .buf_queue = dvb_buf_queue,
  95. .buf_release = dvb_buf_release,
  96. };
  97. static struct s5h1409_config hauppauge_generic_config = {
  98. .demod_address = 0x32 >> 1,
  99. .output_mode = S5H1409_SERIAL_OUTPUT,
  100. .gpio = S5H1409_GPIO_ON,
  101. .qam_if = 44000,
  102. .inversion = S5H1409_INVERSION_OFF,
  103. .status_mode = S5H1409_DEMODLOCKING
  104. };
  105. static struct s5h1409_config hauppauge_ezqam_config = {
  106. .demod_address = 0x32 >> 1,
  107. .output_mode = S5H1409_SERIAL_OUTPUT,
  108. .gpio = S5H1409_GPIO_OFF,
  109. .qam_if = 4000,
  110. .inversion = S5H1409_INVERSION_ON,
  111. .status_mode = S5H1409_DEMODLOCKING
  112. };
  113. static struct s5h1409_config hauppauge_hvr1800lp_config = {
  114. .demod_address = 0x32 >> 1,
  115. .output_mode = S5H1409_SERIAL_OUTPUT,
  116. .gpio = S5H1409_GPIO_OFF,
  117. .qam_if = 44000,
  118. .inversion = S5H1409_INVERSION_OFF,
  119. .status_mode = S5H1409_DEMODLOCKING
  120. };
  121. static struct s5h1409_config hauppauge_hvr1500_config = {
  122. .demod_address = 0x32 >> 1,
  123. .output_mode = S5H1409_SERIAL_OUTPUT,
  124. .gpio = S5H1409_GPIO_OFF,
  125. .inversion = S5H1409_INVERSION_OFF,
  126. .status_mode = S5H1409_DEMODLOCKING
  127. };
  128. static struct mt2131_config hauppauge_generic_tunerconfig = {
  129. 0x61
  130. };
  131. static struct lgdt330x_config fusionhdtv_5_express = {
  132. .demod_address = 0x0e,
  133. .demod_chip = LGDT3303,
  134. .serial_mpeg = 0x40,
  135. };
  136. static struct s5h1409_config hauppauge_hvr1500q_config = {
  137. .demod_address = 0x32 >> 1,
  138. .output_mode = S5H1409_SERIAL_OUTPUT,
  139. .gpio = S5H1409_GPIO_ON,
  140. .qam_if = 44000,
  141. .inversion = S5H1409_INVERSION_OFF,
  142. .status_mode = S5H1409_DEMODLOCKING
  143. };
  144. static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
  145. .i2c_address = 0x61,
  146. .if_khz = 5380,
  147. .request_firmware = cx23885_request_firmware,
  148. .tuner_reset = hauppauge_hvr1500q_tuner_reset
  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. NULL);
  206. }
  207. break;
  208. case 0:
  209. default:
  210. port->dvb.frontend =
  211. dvb_attach(s5h1409_attach,
  212. &hauppauge_generic_config,
  213. &i2c_bus->i2c_adap);
  214. if (port->dvb.frontend != NULL)
  215. dvb_attach(mt2131_attach, port->dvb.frontend,
  216. &i2c_bus->i2c_adap,
  217. &hauppauge_generic_tunerconfig, 0);
  218. break;
  219. }
  220. break;
  221. case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
  222. i2c_bus = &dev->i2c_bus[0];
  223. port->dvb.frontend = dvb_attach(s5h1409_attach,
  224. &hauppauge_hvr1800lp_config,
  225. &i2c_bus->i2c_adap);
  226. if (port->dvb.frontend != NULL) {
  227. dvb_attach(mt2131_attach, port->dvb.frontend,
  228. &i2c_bus->i2c_adap,
  229. &hauppauge_generic_tunerconfig, 0);
  230. }
  231. break;
  232. case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
  233. i2c_bus = &dev->i2c_bus[0];
  234. port->dvb.frontend = dvb_attach(lgdt330x_attach,
  235. &fusionhdtv_5_express,
  236. &i2c_bus->i2c_adap);
  237. if (port->dvb.frontend != NULL) {
  238. dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61,
  239. &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
  240. }
  241. break;
  242. case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
  243. i2c_bus = &dev->i2c_bus[1];
  244. port->dvb.frontend = dvb_attach(s5h1409_attach,
  245. &hauppauge_hvr1500q_config,
  246. &dev->i2c_bus[0].i2c_adap);
  247. if (port->dvb.frontend != NULL) {
  248. dvb_attach(xc5000_attach, port->dvb.frontend,
  249. &i2c_bus->i2c_adap,
  250. &hauppauge_hvr1500q_tunerconfig);
  251. }
  252. break;
  253. case CX23885_BOARD_HAUPPAUGE_HVR1500:
  254. i2c_bus = &dev->i2c_bus[1];
  255. port->dvb.frontend = dvb_attach(s5h1409_attach,
  256. &hauppauge_hvr1500_config,
  257. &dev->i2c_bus[0].i2c_adap);
  258. if (port->dvb.frontend != NULL) {
  259. struct dvb_frontend *fe;
  260. struct xc2028_config cfg = {
  261. .i2c_adap = &i2c_bus->i2c_adap,
  262. .i2c_addr = 0x61,
  263. .video_dev = port,
  264. .callback = cx23885_hvr1500_xc3028_callback,
  265. };
  266. static struct xc2028_ctrl ctl = {
  267. .fname = "xc3028-v27.fw",
  268. .max_len = 64,
  269. .scode_table = OREN538,
  270. };
  271. fe = dvb_attach(xc2028_attach,
  272. port->dvb.frontend, &cfg);
  273. if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
  274. fe->ops.tuner_ops.set_config(fe, &ctl);
  275. }
  276. break;
  277. default:
  278. printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
  279. dev->name);
  280. break;
  281. }
  282. if (NULL == port->dvb.frontend) {
  283. printk("%s: frontend initialization failed\n", dev->name);
  284. return -1;
  285. }
  286. /* Put the analog decoder in standby to keep it quiet */
  287. cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
  288. if (port->dvb.frontend->ops.analog_ops.standby)
  289. port->dvb.frontend->ops.analog_ops.standby(port->dvb.frontend);
  290. /* register everything */
  291. return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
  292. &dev->pci->dev);
  293. }
  294. int cx23885_dvb_register(struct cx23885_tsport *port)
  295. {
  296. struct cx23885_dev *dev = port->dev;
  297. int err;
  298. dprintk(1, "%s\n", __FUNCTION__);
  299. dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
  300. dev->board,
  301. dev->name,
  302. dev->pci_bus,
  303. dev->pci_slot);
  304. err = -ENODEV;
  305. /* dvb stuff */
  306. printk("%s: cx23885 based dvb card\n", dev->name);
  307. videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
  308. V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
  309. sizeof(struct cx23885_buffer), port);
  310. err = dvb_register(port);
  311. if (err != 0)
  312. printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
  313. return err;
  314. }
  315. int cx23885_dvb_unregister(struct cx23885_tsport *port)
  316. {
  317. /* dvb */
  318. if(port->dvb.frontend)
  319. videobuf_dvb_unregister(&port->dvb);
  320. return 0;
  321. }
  322. /*
  323. * Local variables:
  324. * c-basic-offset: 8
  325. * End:
  326. * 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
  327. */