2 bttv-if.c -- interfaces to other kernel modules
3 all the i2c code is here
4 also the gpio interface exported by bttv (used by lirc)
7 bttv - Bt848 frame grabber driver
9 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
10 & Marcus Metzler (mocm@thp.uni-koeln.de)
11 (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define __NO_VERSION__ 1
31 #include <linux/version.h>
32 #include <linux/module.h>
33 #include <linux/init.h>
41 EXPORT_SYMBOL(bttv_get_cardinfo
);
42 EXPORT_SYMBOL(bttv_get_id
);
43 EXPORT_SYMBOL(bttv_gpio_enable
);
44 EXPORT_SYMBOL(bttv_read_gpio
);
45 EXPORT_SYMBOL(bttv_write_gpio
);
46 EXPORT_SYMBOL(bttv_get_gpio_queue
);
48 /* ----------------------------------------------------------------------- */
49 /* Exported functions - for other modules which want to access the */
50 /* gpio ports (IR for example) */
51 /* see bttv.h for comments */
53 int bttv_get_cardinfo(unsigned int card
, int *type
, int *cardid
)
55 if (card
>= bttv_num
) {
58 *type
= bttvs
[card
].type
;
59 *cardid
= bttvs
[card
].cardid
;
63 int bttv_get_id(unsigned int card
)
65 printk("bttv_get_id is obsolete, use bttv_get_cardinfo instead\n");
66 if (card
>= bttv_num
) {
69 return bttvs
[card
].type
;
72 int bttv_gpio_enable(unsigned int card
, unsigned long mask
, unsigned long data
)
76 if (card
>= bttv_num
) {
81 btaor(data
, ~mask
, BT848_GPIO_OUT_EN
);
85 int bttv_read_gpio(unsigned int card
, unsigned long *data
)
89 if (card
>= bttv_num
) {
99 /* prior setting BT848_GPIO_REG_INP is (probably) not needed
100 because we set direct input on init */
101 *data
= btread(BT848_GPIO_DATA
);
105 int bttv_write_gpio(unsigned int card
, unsigned long mask
, unsigned long data
)
109 if (card
>= bttv_num
) {
115 /* prior setting BT848_GPIO_REG_INP is (probably) not needed
116 because direct input is set on init */
117 btaor(data
& mask
, ~mask
, BT848_GPIO_DATA
);
121 wait_queue_head_t
* bttv_get_gpio_queue(unsigned int card
)
125 if (card
>= bttv_num
) {
130 if (bttvs
[card
].shutdown
) {
137 /* ----------------------------------------------------------------------- */
140 void bttv_bit_setscl(void *data
, int state
)
142 struct bttv
*btv
= (struct bttv
*)data
;
145 btv
->i2c_state
|= 0x02;
147 btv
->i2c_state
&= ~0x02;
148 btwrite(btv
->i2c_state
, BT848_I2C
);
152 void bttv_bit_setsda(void *data
, int state
)
154 struct bttv
*btv
= (struct bttv
*)data
;
157 btv
->i2c_state
|= 0x01;
159 btv
->i2c_state
&= ~0x01;
160 btwrite(btv
->i2c_state
, BT848_I2C
);
164 static int bttv_bit_getscl(void *data
)
166 struct bttv
*btv
= (struct bttv
*)data
;
169 state
= btread(BT848_I2C
) & 0x02 ? 1 : 0;
173 static int bttv_bit_getsda(void *data
)
175 struct bttv
*btv
= (struct bttv
*)data
;
178 state
= btread(BT848_I2C
) & 0x01;
182 static void bttv_inc_use(struct i2c_adapter
*adap
)
187 static void bttv_dec_use(struct i2c_adapter
*adap
)
192 static int attach_inform(struct i2c_client
*client
)
194 struct bttv
*btv
= (struct bttv
*)client
->adapter
->data
;
197 for (i
= 0; i
< I2C_CLIENTS_MAX
; i
++) {
198 if (btv
->i2c_clients
[i
] == NULL
||
199 btv
->i2c_clients
[i
]->driver
->id
== client
->driver
->id
) {
200 btv
->i2c_clients
[i
] = client
;
204 if (btv
->tuner_type
!= -1)
205 bttv_call_i2c_clients(btv
,TUNER_SET_TYPE
,&btv
->tuner_type
);
207 printk("bttv%d: i2c attach [%s]\n",btv
->nr
,client
->name
);
211 static int detach_inform(struct i2c_client
*client
)
213 struct bttv
*btv
= (struct bttv
*)client
->adapter
->data
;
217 printk("bttv%d: i2c detach [%s]\n",btv
->nr
,client
->name
);
218 for (i
= 0; i
< I2C_CLIENTS_MAX
; i
++) {
219 if (NULL
!= btv
->i2c_clients
[i
] &&
220 btv
->i2c_clients
[i
]->driver
->id
== client
->driver
->id
) {
221 btv
->i2c_clients
[i
] = NULL
;
228 void bttv_call_i2c_clients(struct bttv
*btv
, unsigned int cmd
, void *arg
)
232 for (i
= 0; i
< I2C_CLIENTS_MAX
; i
++) {
233 if (NULL
== btv
->i2c_clients
[i
])
235 if (NULL
== btv
->i2c_clients
[i
]->driver
->command
)
237 btv
->i2c_clients
[i
]->driver
->command(
238 btv
->i2c_clients
[i
],cmd
,arg
);
242 struct i2c_algo_bit_data bttv_i2c_algo_template
= {
251 struct i2c_adapter bttv_i2c_adap_template
= {
263 struct i2c_client bttv_i2c_client_template
= {
274 int bttv_I2CRead(struct bttv
*btv
, unsigned char addr
, char *probe_for
)
276 unsigned char buffer
= 0;
278 if (0 != btv
->i2c_ok
)
280 if (bttv_verbose
&& NULL
!= probe_for
)
281 printk(KERN_INFO
"bttv%d: i2c: checking for %s @ 0x%02x... ",
282 btv
->nr
,probe_for
,addr
);
283 btv
->i2c_client
.addr
= addr
>> 1;
284 if (1 != i2c_master_recv(&btv
->i2c_client
, &buffer
, 1)) {
285 if (NULL
!= probe_for
) {
287 printk("not found\n");
289 printk(KERN_WARNING
"bttv%d: i2c read 0x%x: error\n",
293 if (bttv_verbose
&& NULL
!= probe_for
)
299 int bttv_I2CWrite(struct bttv
*btv
, unsigned char addr
, unsigned char b1
,
300 unsigned char b2
, int both
)
302 unsigned char buffer
[2];
303 int bytes
= both
? 2 : 1;
305 if (0 != btv
->i2c_ok
)
307 btv
->i2c_client
.addr
= addr
>> 1;
310 if (bytes
!= i2c_master_send(&btv
->i2c_client
, buffer
, bytes
))
315 /* read EEPROM content */
316 void __devinit
bttv_readee(struct bttv
*btv
, unsigned char *eedata
, int addr
)
320 if (bttv_I2CWrite(btv
, addr
, 0, -1, 0)<0) {
321 printk(KERN_WARNING
"bttv: readee error\n");
324 btv
->i2c_client
.addr
= addr
>> 1;
325 for (i
=0; i
<256; i
+=16) {
326 if (16 != i2c_master_recv(&btv
->i2c_client
,eedata
+i
,16)) {
327 printk(KERN_WARNING
"bttv: readee error\n");