saa7134-dvb.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * $Id: saa7134-dvb.c,v 1.13 2005/06/12 04:19:19 mchehab Exp $
  3. *
  4. * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
  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. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/list.h>
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/slab.h>
  25. #include <linux/delay.h>
  26. #include <linux/kthread.h>
  27. #include <linux/suspend.h>
  28. #include "saa7134-reg.h"
  29. #include "saa7134.h"
  30. #include "dvb-pll.h"
  31. #include "mt352.h"
  32. #include "mt352_priv.h" /* FIXME */
  33. #include "tda1004x.h"
  34. MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
  35. MODULE_LICENSE("GPL");
  36. static unsigned int antenna_pwr = 0;
  37. module_param(antenna_pwr, int, 0444);
  38. MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
  39. /* ------------------------------------------------------------------ */
  40. static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
  41. {
  42. u32 ok;
  43. if (!on) {
  44. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  45. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  46. return 0;
  47. }
  48. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
  49. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  50. udelay(10);
  51. saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
  52. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  53. udelay(10);
  54. saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
  55. udelay(10);
  56. ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
  57. printk("%s: %s %s\n", dev->name, __FUNCTION__,
  58. ok ? "on" : "off");
  59. if (!ok)
  60. saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
  61. return ok;
  62. }
  63. static int mt352_pinnacle_init(struct dvb_frontend* fe)
  64. {
  65. static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
  66. static u8 reset [] = { RESET, 0x80 };
  67. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  68. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
  69. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
  70. static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
  71. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
  72. static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
  73. static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
  74. struct saa7134_dev *dev= fe->dvb->priv;
  75. printk("%s: %s called\n",dev->name,__FUNCTION__);
  76. mt352_write(fe, clock_config, sizeof(clock_config));
  77. udelay(200);
  78. mt352_write(fe, reset, sizeof(reset));
  79. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  80. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  81. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  82. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  83. mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
  84. mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
  85. mt352_write(fe, irq_cfg, sizeof(irq_cfg));
  86. return 0;
  87. }
  88. static int mt352_pinnacle_pll_set(struct dvb_frontend* fe,
  89. struct dvb_frontend_parameters* params,
  90. u8* pllbuf)
  91. {
  92. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  93. static int off = TDA9887_PRESENT | TDA9887_PORT2_ACTIVE;
  94. struct saa7134_dev *dev = fe->dvb->priv;
  95. struct v4l2_frequency f;
  96. /* set frequency (mt2050) */
  97. f.tuner = 0;
  98. f.type = V4L2_TUNER_DIGITAL_TV;
  99. f.frequency = params->frequency / 1000 * 16 / 1000;
  100. saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
  101. saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
  102. saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&off);
  103. pinnacle_antenna_pwr(dev, antenna_pwr);
  104. /* mt352 setup */
  105. mt352_pinnacle_init(fe);
  106. pllbuf[0] = 0xc2;
  107. pllbuf[1] = 0x00;
  108. pllbuf[2] = 0x00;
  109. pllbuf[3] = 0x80;
  110. pllbuf[4] = 0x00;
  111. return 0;
  112. }
  113. static struct mt352_config pinnacle_300i = {
  114. .demod_address = 0x3c >> 1,
  115. .adc_clock = 20333,
  116. .if2 = 36150,
  117. .no_tuner = 1,
  118. .demod_init = mt352_pinnacle_init,
  119. .pll_set = mt352_pinnacle_pll_set,
  120. };
  121. /* ------------------------------------------------------------------ */
  122. static int medion_cardbus_init(struct dvb_frontend* fe)
  123. {
  124. /* anything to do here ??? */
  125. return 0;
  126. }
  127. static int medion_cardbus_pll_set(struct dvb_frontend* fe,
  128. struct dvb_frontend_parameters* params)
  129. {
  130. struct saa7134_dev *dev = fe->dvb->priv;
  131. struct v4l2_frequency f;
  132. /*
  133. * this instructs tuner.o to set the frequency, the call will
  134. * end up in tuner_command(), VIDIOC_S_FREQUENCY switch.
  135. * tda9887.o will see that as well.
  136. */
  137. f.tuner = 0;
  138. f.type = V4L2_TUNER_DIGITAL_TV;
  139. f.frequency = params->frequency / 1000 * 16 / 1000;
  140. saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
  141. return 0;
  142. }
  143. static int fe_request_firmware(struct dvb_frontend* fe,
  144. const struct firmware **fw, char* name)
  145. {
  146. struct saa7134_dev *dev = fe->dvb->priv;
  147. return request_firmware(fw, name, &dev->pci->dev);
  148. }
  149. static struct tda1004x_config medion_cardbus = {
  150. .demod_address = 0x08, /* not sure this is correct */
  151. .invert = 0,
  152. .invert_oclk = 0,
  153. .pll_init = medion_cardbus_init,
  154. .pll_set = medion_cardbus_pll_set,
  155. .request_firmware = fe_request_firmware,
  156. };
  157. /* ------------------------------------------------------------------ */
  158. static int dvb_init(struct saa7134_dev *dev)
  159. {
  160. /* init struct videobuf_dvb */
  161. dev->ts.nr_bufs = 32;
  162. dev->ts.nr_packets = 32*4;
  163. dev->dvb.name = dev->name;
  164. videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops,
  165. dev->pci, &dev->slock,
  166. V4L2_BUF_TYPE_VIDEO_CAPTURE,
  167. V4L2_FIELD_ALTERNATE,
  168. sizeof(struct saa7134_buf),
  169. dev);
  170. switch (dev->board) {
  171. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  172. printk("%s: pinnacle 300i dvb setup\n",dev->name);
  173. dev->dvb.frontend = mt352_attach(&pinnacle_300i,
  174. &dev->i2c_adap);
  175. break;
  176. case SAA7134_BOARD_MD7134:
  177. dev->dvb.frontend = tda10046_attach(&medion_cardbus,
  178. &dev->i2c_adap);
  179. if (NULL == dev->dvb.frontend)
  180. printk("%s: Hmm, looks like this is the old MD7134 "
  181. "version without DVB-T support\n",dev->name);
  182. break;
  183. default:
  184. printk("%s: Huh? unknown DVB card?\n",dev->name);
  185. break;
  186. }
  187. if (NULL == dev->dvb.frontend) {
  188. printk("%s: frontend initialization failed\n",dev->name);
  189. return -1;
  190. }
  191. /* register everything else */
  192. return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev);
  193. }
  194. static int dvb_fini(struct saa7134_dev *dev)
  195. {
  196. static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
  197. printk("%s: %s\n",dev->name,__FUNCTION__);
  198. switch (dev->board) {
  199. case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
  200. /* otherwise we don't detect the tuner on next insmod */
  201. saa7134_i2c_call_clients(dev,TDA9887_SET_CONFIG,&on);
  202. break;
  203. };
  204. videobuf_dvb_unregister(&dev->dvb);
  205. return 0;
  206. }
  207. static struct saa7134_mpeg_ops dvb_ops = {
  208. .type = SAA7134_MPEG_DVB,
  209. .init = dvb_init,
  210. .fini = dvb_fini,
  211. };
  212. static int __init dvb_register(void)
  213. {
  214. return saa7134_ts_register(&dvb_ops);
  215. }
  216. static void __exit dvb_unregister(void)
  217. {
  218. saa7134_ts_unregister(&dvb_ops);
  219. }
  220. module_init(dvb_register);
  221. module_exit(dvb_unregister);
  222. /* ------------------------------------------------------------------ */
  223. /*
  224. * Local variables:
  225. * c-basic-offset: 8
  226. * End:
  227. */