OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [media/] [video/] [bttv-if.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
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)
5
 
6
    bttv - Bt848 frame grabber driver
7
 
8
    Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
9
                           & Marcus Metzler (mocm@thp.uni-koeln.de)
10
    (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
11
 
12
    This program is free software; you can redistribute it and/or modify
13
    it under the terms of the GNU General Public License as published by
14
    the Free Software Foundation; either version 2 of the License, or
15
    (at your option) any later version.
16
 
17
    This program is distributed in the hope that it will be useful,
18
    but WITHOUT ANY WARRANTY; without even the implied warranty of
19
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
    GNU General Public License for more details.
21
 
22
    You should have received a copy of the GNU General Public License
23
    along with this program; if not, write to the Free Software
24
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
 
26
*/
27
 
28
#include <linux/module.h>
29
#include <linux/init.h>
30
 
31
#include <asm/io.h>
32
 
33
#include "bttvp.h"
34
 
35
static struct i2c_algo_bit_data bttv_i2c_algo_template;
36
static struct i2c_adapter bttv_i2c_adap_template;
37
static struct i2c_client bttv_i2c_client_template;
38
 
39
EXPORT_SYMBOL(bttv_get_cardinfo);
40
EXPORT_SYMBOL(bttv_get_pcidev);
41
EXPORT_SYMBOL(bttv_get_id);
42
EXPORT_SYMBOL(bttv_gpio_enable);
43
EXPORT_SYMBOL(bttv_read_gpio);
44
EXPORT_SYMBOL(bttv_write_gpio);
45
EXPORT_SYMBOL(bttv_get_gpio_queue);
46
EXPORT_SYMBOL(bttv_i2c_call);
47
 
48
/* ----------------------------------------------------------------------- */
49
/* Exported functions - for other modules which want to access the         */
50
/*                      gpio ports (IR for example)                        */
51
/*                      see bttv.h for comments                            */
52
 
53
int bttv_get_cardinfo(unsigned int card, int *type, unsigned *cardid)
54
{
55
        if (card >= bttv_num) {
56
                return -1;
57
        }
58
        *type   = bttvs[card].type;
59
        *cardid = bttvs[card].cardid;
60
        return 0;
61
}
62
 
63
struct pci_dev* bttv_get_pcidev(unsigned int card)
64
{
65
        if (card >= bttv_num)
66
                return NULL;
67
        return bttvs[card].dev;
68
}
69
 
70
int bttv_get_id(unsigned int card)
71
{
72
        printk("bttv_get_id is obsolete, use bttv_get_cardinfo instead\n");
73
        if (card >= bttv_num) {
74
                return -1;
75
        }
76
        return bttvs[card].type;
77
}
78
 
79
int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data)
80
{
81
        struct bttv *btv;
82
 
83
        if (card >= bttv_num) {
84
                return -EINVAL;
85
        }
86
 
87
        btv = &bttvs[card];
88
        btaor(data, ~mask, BT848_GPIO_OUT_EN);
89
        if (bttv_gpio)
90
                bttv_gpio_tracking(btv,"extern enable");
91
        return 0;
92
}
93
 
94
int bttv_read_gpio(unsigned int card, unsigned long *data)
95
{
96
        struct bttv *btv;
97
 
98
        if (card >= bttv_num) {
99
                return -EINVAL;
100
        }
101
 
102
        btv = &bttvs[card];
103
 
104
        if(btv->shutdown) {
105
                return -ENODEV;
106
        }
107
 
108
/* prior setting BT848_GPIO_REG_INP is (probably) not needed
109
   because we set direct input on init */
110
        *data = btread(BT848_GPIO_DATA);
111
        return 0;
112
}
113
 
114
int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data)
115
{
116
        struct bttv *btv;
117
 
118
        if (card >= bttv_num) {
119
                return -EINVAL;
120
        }
121
 
122
        btv = &bttvs[card];
123
 
124
/* prior setting BT848_GPIO_REG_INP is (probably) not needed
125
   because direct input is set on init */
126
        btaor(data & mask, ~mask, BT848_GPIO_DATA);
127
        if (bttv_gpio)
128
                bttv_gpio_tracking(btv,"extern write");
129
        return 0;
130
}
131
 
132
wait_queue_head_t* bttv_get_gpio_queue(unsigned int card)
133
{
134
        struct bttv *btv;
135
 
136
        if (card >= bttv_num) {
137
                return NULL;
138
        }
139
 
140
        btv = &bttvs[card];
141
        if (bttvs[card].shutdown) {
142
                return NULL;
143
        }
144
        return &btv->gpioq;
145
}
146
 
147
 
148
/* ----------------------------------------------------------------------- */
149
/* I2C functions                                                           */
150
 
151
void bttv_bit_setscl(void *data, int state)
152
{
153
        struct bttv *btv = (struct bttv*)data;
154
 
155
        if (state)
156
                btv->i2c_state |= 0x02;
157
        else
158
                btv->i2c_state &= ~0x02;
159
        btwrite(btv->i2c_state, BT848_I2C);
160
        btread(BT848_I2C);
161
}
162
 
163
void bttv_bit_setsda(void *data, int state)
164
{
165
        struct bttv *btv = (struct bttv*)data;
166
 
167
        if (state)
168
                btv->i2c_state |= 0x01;
169
        else
170
                btv->i2c_state &= ~0x01;
171
        btwrite(btv->i2c_state, BT848_I2C);
172
        btread(BT848_I2C);
173
}
174
 
175
static int bttv_bit_getscl(void *data)
176
{
177
        struct bttv *btv = (struct bttv*)data;
178
        int state;
179
 
180
        state = btread(BT848_I2C) & 0x02 ? 1 : 0;
181
        return state;
182
}
183
 
184
static int bttv_bit_getsda(void *data)
185
{
186
        struct bttv *btv = (struct bttv*)data;
187
        int state;
188
 
189
        state = btread(BT848_I2C) & 0x01;
190
        return state;
191
}
192
 
193
#ifndef I2C_PEC
194
static void bttv_inc_use(struct i2c_adapter *adap)
195
{
196
        MOD_INC_USE_COUNT;
197
}
198
 
199
static void bttv_dec_use(struct i2c_adapter *adap)
200
{
201
        MOD_DEC_USE_COUNT;
202
}
203
#endif
204
 
205
static int attach_inform(struct i2c_client *client)
206
{
207
        struct bttv *btv = i2c_get_adapdata(client->adapter);
208
 
209
        if (btv->tuner_type != UNSET)
210
                bttv_call_i2c_clients(btv,TUNER_SET_TYPE,&btv->tuner_type);
211
        if (btv->pinnacle_id != UNSET)
212
                bttv_call_i2c_clients(btv,AUDC_CONFIG_PINNACLE,
213
                                      &btv->pinnacle_id);
214
 
215
        if (bttv_debug)
216
                printk("bttv%d: i2c attach [client=%s]\n",
217
                       btv->nr, i2c_clientname(client));
218
        return 0;
219
}
220
 
221
void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg)
222
{
223
        if (0 != btv->i2c_rc)
224
                return;
225
        i2c_clients_command(&btv->i2c_adap, cmd, arg);
226
}
227
 
228
void bttv_i2c_call(unsigned int card, unsigned int cmd, void *arg)
229
{
230
        if (card >= bttv_num)
231
                return;
232
        bttv_call_i2c_clients(&bttvs[card], cmd, arg);
233
}
234
 
235
static struct i2c_algo_bit_data bttv_i2c_algo_template = {
236
        .setsda  = bttv_bit_setsda,
237
        .setscl  = bttv_bit_setscl,
238
        .getsda  = bttv_bit_getsda,
239
        .getscl  = bttv_bit_getscl,
240
        .udelay  = 16,
241
        .mdelay  = 10,
242
        .timeout = 200,
243
};
244
 
245
static struct i2c_adapter bttv_i2c_adap_template = {
246
#ifdef I2C_PEC
247
        .owner             = THIS_MODULE,
248
#else
249
        .inc_use           = bttv_inc_use,
250
        .dec_use           = bttv_dec_use,
251
#endif
252
#ifdef I2C_ADAP_CLASS_TV_ANALOG
253
        .class             = I2C_ADAP_CLASS_TV_ANALOG,
254
#endif
255
        I2C_DEVNAME("bt848"),
256
        .id                = I2C_HW_B_BT848,
257
        .client_register   = attach_inform,
258
};
259
 
260
static struct i2c_client bttv_i2c_client_template = {
261
        I2C_DEVNAME("bttv internal"),
262
        .id       = -1,
263
};
264
 
265
 
266
/* read I2C */
267
int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for)
268
{
269
        unsigned char buffer = 0;
270
 
271
        if (0 != btv->i2c_rc)
272
                return -1;
273
        if (bttv_verbose && NULL != probe_for)
274
                printk(KERN_INFO "bttv%d: i2c: checking for %s @ 0x%02x... ",
275
                       btv->nr,probe_for,addr);
276
        btv->i2c_client.addr = addr >> 1;
277
        if (1 != i2c_master_recv(&btv->i2c_client, &buffer, 1)) {
278
                if (NULL != probe_for) {
279
                        if (bttv_verbose)
280
                                printk("not found\n");
281
                } else
282
                        printk(KERN_WARNING "bttv%d: i2c read 0x%x: error\n",
283
                               btv->nr,addr);
284
                return -1;
285
        }
286
        if (bttv_verbose && NULL != probe_for)
287
                printk("found\n");
288
        return buffer;
289
}
290
 
291
/* write I2C */
292
int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
293
                    unsigned char b2, int both)
294
{
295
        unsigned char buffer[2];
296
        int bytes = both ? 2 : 1;
297
 
298
        if (0 != btv->i2c_rc)
299
                return -1;
300
        btv->i2c_client.addr = addr >> 1;
301
        buffer[0] = b1;
302
        buffer[1] = b2;
303
        if (bytes != i2c_master_send(&btv->i2c_client, buffer, bytes))
304
                return -1;
305
        return 0;
306
}
307
 
308
/* read EEPROM content */
309
void __devinit bttv_readee(struct bttv *btv, unsigned char *eedata, int addr)
310
{
311
        int i;
312
 
313
        if (bttv_I2CWrite(btv, addr, 0, -1, 0)<0) {
314
                printk(KERN_WARNING "bttv: readee error\n");
315
                return;
316
        }
317
        btv->i2c_client.addr = addr >> 1;
318
        for (i=0; i<256; i+=16) {
319
                if (16 != i2c_master_recv(&btv->i2c_client,eedata+i,16)) {
320
                        printk(KERN_WARNING "bttv: readee error\n");
321
                        break;
322
                }
323
        }
324
}
325
 
326
/* init + register i2c algo-bit adapter */
327
int __devinit init_bttv_i2c(struct bttv *btv)
328
{
329
        memcpy(&btv->i2c_adap, &bttv_i2c_adap_template,
330
               sizeof(struct i2c_adapter));
331
        memcpy(&btv->i2c_algo, &bttv_i2c_algo_template,
332
               sizeof(struct i2c_algo_bit_data));
333
        memcpy(&btv->i2c_client, &bttv_i2c_client_template,
334
               sizeof(struct i2c_client));
335
 
336
        sprintf(btv->i2c_adap.name, "bt848 #%d", btv->nr);
337
 
338
        btv->i2c_algo.data = btv;
339
        i2c_set_adapdata(&btv->i2c_adap, btv);
340
        btv->i2c_adap.algo_data = &btv->i2c_algo;
341
        btv->i2c_client.adapter = &btv->i2c_adap;
342
 
343
        bttv_bit_setscl(btv,1);
344
        bttv_bit_setsda(btv,1);
345
 
346
        btv->i2c_rc = i2c_bit_add_bus(&btv->i2c_adap);
347
        return btv->i2c_rc;
348
}
349
 
350
/*
351
 * Local variables:
352
 * c-basic-offset: 8
353
 * End:
354
 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.