zr36120_i2c.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/video_decoder.h>
  20. #include <asm/uaccess.h>
  21. #include "tuner.h"
  22. #include "zr36120.h"
  23. /* ----------------------------------------------------------------------- */
  24. /* I2C functions */
  25. /* ----------------------------------------------------------------------- */
  26. /* software I2C functions */
  27. #define I2C_DELAY 10
  28. static void i2c_setlines(struct i2c_bus *bus,int ctrl,int data)
  29. {
  30. struct zoran *ztv = (struct zoran*)bus->data;
  31. unsigned int b = 0;
  32. if (data) b |= ztv->card->swapi2c ? ZORAN_I2C_SCL : ZORAN_I2C_SDA;
  33. if (ctrl) b |= ztv->card->swapi2c ? ZORAN_I2C_SDA : ZORAN_I2C_SCL;
  34. zrwrite(b, ZORAN_I2C);
  35. udelay(I2C_DELAY);
  36. }
  37. static int i2c_getdataline(struct i2c_bus *bus)
  38. {
  39. struct zoran *ztv = (struct zoran*)bus->data;
  40. if (ztv->card->swapi2c)
  41. return zrread(ZORAN_I2C) & ZORAN_I2C_SCL;
  42. return zrread(ZORAN_I2C) & ZORAN_I2C_SDA;
  43. }
  44. static
  45. void attach_inform(struct i2c_bus *bus, int id)
  46. {
  47. struct zoran *ztv = (struct zoran*)bus->data;
  48. struct video_decoder_capability dc;
  49. int rv;
  50. switch (id) {
  51. case I2C_DRIVERID_VIDEODECODER:
  52. DEBUG(printk(CARD_INFO "decoder attached\n",CARD));
  53. /* fetch the capabilites of the decoder */
  54. rv = i2c_control_device(&ztv->i2c, I2C_DRIVERID_VIDEODECODER, DECODER_GET_CAPABILITIES, &dc);
  55. if (rv) {
  56. DEBUG(printk(CARD_DEBUG "decoder is not V4L aware!\n",CARD));
  57. break;
  58. }
  59. DEBUG(printk(CARD_DEBUG "capabilities %d %d %d\n",CARD,dc.flags,dc.inputs,dc.outputs));
  60. /* Test if the decoder can de VBI transfers */
  61. if (dc.flags & 16 /*VIDEO_DECODER_VBI*/)
  62. ztv->have_decoder = 2;
  63. else
  64. ztv->have_decoder = 1;
  65. break;
  66. case I2C_DRIVERID_TUNER:
  67. ztv->have_tuner = 1;
  68. DEBUG(printk(CARD_INFO "tuner attached\n",CARD));
  69. if (ztv->tuner_type >= 0)
  70. {
  71. if (i2c_control_device(&ztv->i2c,I2C_DRIVERID_TUNER,TUNER_SET_TYPE,&ztv->tuner_type)<0)
  72. DEBUG(printk(CARD_INFO "attach_inform; tuner won't be set to type %d\n",CARD,ztv->tuner_type));
  73. }
  74. break;
  75. default:
  76. DEBUG(printk(CARD_INFO "attach_inform; unknown device id=%d\n",CARD,id));
  77. break;
  78. }
  79. }
  80. static
  81. void detach_inform(struct i2c_bus *bus, int id)
  82. {
  83. struct zoran *ztv = (struct zoran*)bus->data;
  84. switch (id) {
  85. case I2C_DRIVERID_VIDEODECODER:
  86. ztv->have_decoder = 0;
  87. DEBUG(printk(CARD_INFO "decoder detached\n",CARD));
  88. break;
  89. case I2C_DRIVERID_TUNER:
  90. ztv->have_tuner = 0;
  91. DEBUG(printk(CARD_INFO "tuner detached\n",CARD));
  92. break;
  93. default:
  94. DEBUG(printk(CARD_INFO "detach_inform; unknown device id=%d\n",CARD,id));
  95. break;
  96. }
  97. }
  98. struct i2c_bus zoran_i2c_bus_template =
  99. {
  100. "ZR36120",
  101. I2C_BUSID_ZORAN,
  102. NULL,
  103. SPIN_LOCK_UNLOCKED,
  104. attach_inform,
  105. detach_inform,
  106. i2c_setlines,
  107. i2c_getdataline,
  108. NULL,
  109. NULL
  110. };