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>
25 #include <linux/video_decoder.h>
26 #include <asm/uaccess.h>
31 /* ----------------------------------------------------------------------- */
33 /* ----------------------------------------------------------------------- */
35 /* software I2C functions */
39 static void i2c_setlines(struct i2c_bus
*bus
,int ctrl
,int data
)
41 struct zoran
*ztv
= (struct zoran
*)bus
->data
;
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
);
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
;
58 void attach_inform(struct i2c_bus
*bus
, int id
)
60 struct zoran
*ztv
= (struct zoran
*)bus
->data
;
61 struct video_decoder_capability dc
;
65 case I2C_DRIVERID_VIDEODECODER
:
66 DEBUG(printk(CARD_INFO
"decoder attached\n",CARD
));
68 /* fetch the capabilities of the decoder */
69 rv
= i2c_control_device(&ztv
->i2c
, I2C_DRIVERID_VIDEODECODER
, DECODER_GET_CAPABILITIES
, &dc
);
71 DEBUG(printk(CARD_DEBUG
"decoder is not V4L aware!\n",CARD
));
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;
80 ztv
->have_decoder
= 1;
82 case I2C_DRIVERID_TUNER
:
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
));
92 DEBUG(printk(CARD_INFO
"attach_inform; unknown device id=%d\n",CARD
,id
));
98 void detach_inform(struct i2c_bus
*bus
, int id
)
100 struct zoran
*ztv
= (struct zoran
*)bus
->data
;
103 case I2C_DRIVERID_VIDEODECODER
:
104 ztv
->have_decoder
= 0;
105 DEBUG(printk(CARD_INFO
"decoder detached\n",CARD
));
107 case I2C_DRIVERID_TUNER
:
109 DEBUG(printk(CARD_INFO
"tuner detached\n",CARD
));
112 DEBUG(printk(CARD_INFO
"detach_inform; unknown device id=%d\n",CARD
,id
));
117 struct i2c_bus zoran_i2c_bus_template
=