zr36120_i2c.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.     zr36120_i2c.c - Zoran 36120/36125 based framegrabbers
  3.     Copyright (C) 1998-1999 Pauline Middelink <middelin@polyware.nl>
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.     This program is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.     GNU General Public License for more details.
  12.     You should have received a copy of the GNU General Public License
  13.     along with this program; if not, write to the Free Software
  14.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/delay.h>
  18. #include <asm/io.h>
  19. #include <linux/version.h>
  20. #include <linux/video_decoder.h>
  21. #include <asm/uaccess.h>
  22. #include "tuner.h"
  23. #include "zr36120.h"
  24. /* ----------------------------------------------------------------------- */
  25. /* I2C functions    */
  26. /* ----------------------------------------------------------------------- */
  27. /* software I2C functions */
  28. #define I2C_DELAY   10
  29. static void i2c_setlines(struct i2c_bus *bus,int ctrl,int data)
  30. {
  31. struct zoran *ztv = (struct zoran*)bus->data;
  32. unsigned int b = 0;
  33. if (data) b |= ztv->card->swapi2c ? ZORAN_I2C_SCL : ZORAN_I2C_SDA;
  34. if (ctrl) b |= ztv->card->swapi2c ? ZORAN_I2C_SDA : ZORAN_I2C_SCL;
  35. zrwrite(b, ZORAN_I2C);
  36. udelay(I2C_DELAY);
  37. }
  38. static int i2c_getdataline(struct i2c_bus *bus)
  39. {
  40. struct zoran *ztv = (struct zoran*)bus->data;
  41. if (ztv->card->swapi2c)
  42. return zrread(ZORAN_I2C) & ZORAN_I2C_SCL;
  43. return zrread(ZORAN_I2C) & ZORAN_I2C_SDA;
  44. }
  45. static
  46. void attach_inform(struct i2c_bus *bus, int id)
  47. {
  48. struct zoran *ztv = (struct zoran*)bus->data;
  49. struct video_decoder_capability dc;
  50. int rv;
  51. switch (id) {
  52.  case I2C_DRIVERID_VIDEODECODER:
  53. DEBUG(printk(CARD_INFO "decoder attachedn",CARD));
  54. /* fetch the capabilites of the decoder */
  55. rv = i2c_control_device(&ztv->i2c, I2C_DRIVERID_VIDEODECODER, DECODER_GET_CAPABILITIES, &dc);
  56. if (rv) {
  57. DEBUG(printk(CARD_DEBUG "decoder is not V4L aware!n",CARD));
  58. break;
  59. }
  60. DEBUG(printk(CARD_DEBUG "capabilities %d %d %dn",CARD,dc.flags,dc.inputs,dc.outputs));
  61. /* Test if the decoder can de VBI transfers */
  62. if (dc.flags & 16 /*VIDEO_DECODER_VBI*/)
  63. ztv->have_decoder = 2;
  64. else
  65. ztv->have_decoder = 1;
  66. break;
  67.  case I2C_DRIVERID_TUNER:
  68. ztv->have_tuner = 1;
  69. DEBUG(printk(CARD_INFO "tuner attachedn",CARD));
  70. if (ztv->tuner_type >= 0)
  71. {
  72. if (i2c_control_device(&ztv->i2c,I2C_DRIVERID_TUNER,TUNER_SET_TYPE,&ztv->tuner_type)<0)
  73. DEBUG(printk(CARD_INFO "attach_inform; tuner wont be set to type %dn",CARD,ztv->tuner_type));
  74. }
  75. break;
  76.  default:
  77. DEBUG(printk(CARD_INFO "attach_inform; unknown device id=%dn",CARD,id));
  78. break;
  79. }
  80. }
  81. static
  82. void detach_inform(struct i2c_bus *bus, int id)
  83. {
  84. struct zoran *ztv = (struct zoran*)bus->data;
  85. switch (id) {
  86.  case I2C_DRIVERID_VIDEODECODER:
  87. ztv->have_decoder = 0;
  88. DEBUG(printk(CARD_INFO "decoder detachedn",CARD));
  89. break;
  90.  case I2C_DRIVERID_TUNER:
  91. ztv->have_tuner = 0;
  92. DEBUG(printk(CARD_INFO "tuner detachedn",CARD));
  93. break;
  94.  default:
  95. DEBUG(printk(CARD_INFO "detach_inform; unknown device id=%dn",CARD,id));
  96. break;
  97. }
  98. }
  99. struct i2c_bus zoran_i2c_bus_template =
  100. {
  101. "ZR36120",
  102. I2C_BUSID_ZORAN,
  103. NULL,
  104. SPIN_LOCK_UNLOCKED,
  105. attach_inform,
  106. detach_inform,
  107. i2c_setlines,
  108. i2c_getdataline,
  109. NULL,
  110. NULL
  111. };