Linux v2.6.15-rc7
[pohmelfs.git] / drivers / media / video / zr36120_i2c.c
blob6bfe84d657f1668a556064cd5b1a4eb545f90ea9
1 /*
2 zr36120_i2c.c - Zoran 36120/36125 based framegrabbers
4 Copyright (C) 1998-1999 Pauline Middelink <middelin@polyware.nl>
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.
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.
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.
21 #include <linux/types.h>
22 #include <linux/delay.h>
23 #include <asm/io.h>
25 #include <linux/video_decoder.h>
26 #include <asm/uaccess.h>
28 #include "tuner.h"
29 #include "zr36120.h"
31 /* ----------------------------------------------------------------------- */
32 /* I2C functions */
33 /* ----------------------------------------------------------------------- */
35 /* software I2C functions */
37 #define I2C_DELAY 10
39 static void i2c_setlines(struct i2c_bus *bus,int ctrl,int data)
41 struct zoran *ztv = (struct zoran*)bus->data;
42 unsigned int b = 0;
43 if (data) b |= ztv->card->swapi2c ? ZORAN_I2C_SCL : ZORAN_I2C_SDA;
44 if (ctrl) b |= ztv->card->swapi2c ? ZORAN_I2C_SDA : ZORAN_I2C_SCL;
45 zrwrite(b, ZORAN_I2C);
46 udelay(I2C_DELAY);
49 static int i2c_getdataline(struct i2c_bus *bus)
51 struct zoran *ztv = (struct zoran*)bus->data;
52 if (ztv->card->swapi2c)
53 return zrread(ZORAN_I2C) & ZORAN_I2C_SCL;
54 return zrread(ZORAN_I2C) & ZORAN_I2C_SDA;
57 static
58 void attach_inform(struct i2c_bus *bus, int id)
60 struct zoran *ztv = (struct zoran*)bus->data;
61 struct video_decoder_capability dc;
62 int rv;
64 switch (id) {
65 case I2C_DRIVERID_VIDEODECODER:
66 DEBUG(printk(CARD_INFO "decoder attached\n",CARD));
68 /* fetch the capabilites of the decoder */
69 rv = i2c_control_device(&ztv->i2c, I2C_DRIVERID_VIDEODECODER, DECODER_GET_CAPABILITIES, &dc);
70 if (rv) {
71 DEBUG(printk(CARD_DEBUG "decoder is not V4L aware!\n",CARD));
72 break;
74 DEBUG(printk(CARD_DEBUG "capabilities %d %d %d\n",CARD,dc.flags,dc.inputs,dc.outputs));
76 /* Test if the decoder can de VBI transfers */
77 if (dc.flags & 16 /*VIDEO_DECODER_VBI*/)
78 ztv->have_decoder = 2;
79 else
80 ztv->have_decoder = 1;
81 break;
82 case I2C_DRIVERID_TUNER:
83 ztv->have_tuner = 1;
84 DEBUG(printk(CARD_INFO "tuner attached\n",CARD));
85 if (ztv->tuner_type >= 0)
87 if (i2c_control_device(&ztv->i2c,I2C_DRIVERID_TUNER,TUNER_SET_TYPE,&ztv->tuner_type)<0)
88 DEBUG(printk(CARD_INFO "attach_inform; tuner won't be set to type %d\n",CARD,ztv->tuner_type));
90 break;
91 default:
92 DEBUG(printk(CARD_INFO "attach_inform; unknown device id=%d\n",CARD,id));
93 break;
97 static
98 void detach_inform(struct i2c_bus *bus, int id)
100 struct zoran *ztv = (struct zoran*)bus->data;
102 switch (id) {
103 case I2C_DRIVERID_VIDEODECODER:
104 ztv->have_decoder = 0;
105 DEBUG(printk(CARD_INFO "decoder detached\n",CARD));
106 break;
107 case I2C_DRIVERID_TUNER:
108 ztv->have_tuner = 0;
109 DEBUG(printk(CARD_INFO "tuner detached\n",CARD));
110 break;
111 default:
112 DEBUG(printk(CARD_INFO "detach_inform; unknown device id=%d\n",CARD,id));
113 break;
117 struct i2c_bus zoran_i2c_bus_template =
119 "ZR36120",
120 I2C_BUSID_ZORAN,
121 NULL,
123 SPIN_LOCK_UNLOCKED,
125 attach_inform,
126 detach_inform,
128 i2c_setlines,
129 i2c_getdataline,
130 NULL,
131 NULL