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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [media/] [video/] [bt856.c] - Blame information for rev 1275

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

Line No. Rev Author Line
1 1275 phoenix
/*
2
    bt856 - BT856A Digital Video Encoder (Rockwell Part)
3
 
4
    Copyright (C) 1999 Mike Bernson <mike@mlb.org>
5
    Copyright (C) 1998 Dave Perks <dperks@ibm.net>
6
 
7
    Modifications for LML33/DC10plus unified driver
8
    Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9
 
10
    This code was modify/ported from the saa7111 driver written
11
    by Dave Perks.
12
 
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.
17
 
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.
22
 
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.
26
*/
27
 
28
#include <linux/module.h>
29
#include <linux/init.h>
30
#include <linux/delay.h>
31
#include <linux/errno.h>
32
#include <linux/fs.h>
33
#include <linux/kernel.h>
34
#include <linux/major.h>
35
#include <linux/slab.h>
36
#include <linux/mm.h>
37
#include <linux/pci.h>
38
#include <linux/signal.h>
39
#include <asm/io.h>
40
#include <asm/pgtable.h>
41
#include <asm/page.h>
42
#include <linux/sched.h>
43
#include <asm/segment.h>
44
#include <linux/types.h>
45
#include <linux/wrapper.h>
46
 
47
#include <linux/videodev.h>
48
#include <linux/version.h>
49
#include <asm/uaccess.h>
50
 
51
#include <linux/i2c-old.h>
52
#include <linux/video_encoder.h>
53
 
54
#define DEBUG(x)   x            /* Debug driver */
55
 
56
/* ----------------------------------------------------------------------- */
57
 
58
struct bt856 {
59
        struct i2c_bus *bus;
60
        int addr;
61
        unsigned char reg[128];
62
 
63
        int norm;
64
        int enable;
65
        int bright;
66
        int contrast;
67
        int hue;
68
        int sat;
69
};
70
 
71
#define   I2C_BT856        0x88
72
 
73
#define I2C_DELAY   10
74
 
75
/* ----------------------------------------------------------------------- */
76
 
77
static int bt856_write(struct bt856 *dev, unsigned char subaddr,
78
                       unsigned char data)
79
{
80
        int ack;
81
 
82
        LOCK_I2C_BUS(dev->bus);
83
 
84
        i2c_start(dev->bus);
85
        i2c_sendbyte(dev->bus, dev->addr, I2C_DELAY);
86
        i2c_sendbyte(dev->bus, subaddr, I2C_DELAY);
87
        ack = i2c_sendbyte(dev->bus, data, I2C_DELAY);
88
        dev->reg[subaddr] = data;
89
        i2c_stop(dev->bus);
90
        UNLOCK_I2C_BUS(dev->bus);
91
        return ack;
92
}
93
 
94
static int bt856_setbit(struct bt856 *dev, int subaddr, int bit, int data)
95
{
96
        return bt856_write(dev, subaddr,(dev->reg[subaddr] & ~(1 << bit)) | (data ? (1 << bit) : 0));
97
}
98
 
99
/* ----------------------------------------------------------------------- */
100
 
101
static int bt856_attach(struct i2c_device *device)
102
{
103
        struct bt856 *encoder;
104
 
105
        /* This chip is not on the buz card but at the same address saa7185 */
106
        //if (memcmp(device->bus->name, "buz", 3) == 0 || memcmp(device->bus->name, "zr36057", 6) == 0)
107
        //   return 1;
108
 
109
        MOD_INC_USE_COUNT;
110
        device->data = encoder = kmalloc(sizeof(struct bt856), GFP_KERNEL);
111
 
112
        if (encoder == NULL) {
113
                MOD_DEC_USE_COUNT;
114
                return -ENOMEM;
115
        }
116
 
117
 
118
        memset(encoder, 0, sizeof(struct bt856));
119
        strcpy(device->name, "bt856");
120
        encoder->bus = device->bus;
121
        encoder->addr = device->addr;
122
        encoder->norm = VIDEO_MODE_NTSC;
123
        encoder->enable = 1;
124
 
125
        DEBUG(printk(KERN_INFO "%s-bt856: attach\n", encoder->bus->name));
126
 
127
        bt856_write(encoder, 0xdc, 0x18);
128
        bt856_write(encoder, 0xda, 0);
129
        bt856_write(encoder, 0xde, 0);
130
 
131
        bt856_setbit(encoder, 0xdc, 3, 1);
132
        //bt856_setbit(encoder, 0xdc, 6, 0);
133
        bt856_setbit(encoder, 0xdc, 4, 1);
134
 
135
        switch (encoder->norm) {
136
 
137
        case VIDEO_MODE_NTSC:
138
                bt856_setbit(encoder, 0xdc, 2, 0);
139
                break;
140
 
141
        case VIDEO_MODE_PAL:
142
                bt856_setbit(encoder, 0xdc, 2, 1);
143
                break;
144
        }
145
 
146
        bt856_setbit(encoder, 0xdc, 1, 1);
147
        bt856_setbit(encoder, 0xde, 4, 0);
148
        bt856_setbit(encoder, 0xde, 3, 1);
149
        return 0;
150
}
151
 
152
 
153
static int bt856_detach(struct i2c_device *device)
154
{
155
        kfree(device->data);
156
        MOD_DEC_USE_COUNT;
157
        return 0;
158
}
159
 
160
static int bt856_command(struct i2c_device *device, unsigned int cmd,
161
                         void *arg)
162
{
163
        struct bt856 *encoder = device->data;
164
 
165
        switch (cmd) {
166
 
167
        case ENCODER_GET_CAPABILITIES:
168
                {
169
                        struct video_encoder_capability *cap = arg;
170
 
171
                        DEBUG(printk
172
                              (KERN_INFO "%s-bt856: get capabilities\n",
173
                               encoder->bus->name));
174
 
175
                        cap->flags
176
                            = VIDEO_ENCODER_PAL
177
                            | VIDEO_ENCODER_NTSC | VIDEO_ENCODER_CCIR;
178
                        cap->inputs = 2;
179
                        cap->outputs = 1;
180
                }
181
                break;
182
 
183
        case ENCODER_SET_NORM:
184
                {
185
                        int *iarg = arg;
186
 
187
                        DEBUG(printk(KERN_INFO "%s-bt856: set norm %d\n",
188
                                     encoder->bus->name, *iarg));
189
 
190
                        switch (*iarg) {
191
 
192
                        case VIDEO_MODE_NTSC:
193
                                bt856_setbit(encoder, 0xdc, 2, 0);
194
                                break;
195
 
196
                        case VIDEO_MODE_PAL:
197
                                bt856_setbit(encoder, 0xdc, 2, 1);
198
                                bt856_setbit(encoder, 0xda, 0, 0);
199
                                //bt856_setbit(encoder, 0xda, 0, 1);
200
                                break;
201
 
202
                        default:
203
                                return -EINVAL;
204
 
205
                        }
206
                        encoder->norm = *iarg;
207
                }
208
                break;
209
 
210
        case ENCODER_SET_INPUT:
211
                {
212
                        int *iarg = arg;
213
 
214
                        DEBUG(printk(KERN_INFO "%s-bt856: set input %d\n",
215
                                     encoder->bus->name, *iarg));
216
 
217
                        /*     We only have video bus.
218
                           *iarg = 0: input is from bt819
219
                           *iarg = 1: input is from ZR36060 */
220
 
221
                        switch (*iarg) {
222
 
223
                        case 0:
224
                                bt856_setbit(encoder, 0xde, 4, 0);
225
                                bt856_setbit(encoder, 0xde, 3, 1);
226
                                bt856_setbit(encoder, 0xdc, 3, 1);
227
                                bt856_setbit(encoder, 0xdc, 6, 0);
228
                                break;
229
                        case 1:
230
                                bt856_setbit(encoder, 0xde, 4, 0);
231
                                bt856_setbit(encoder, 0xde, 3, 1);
232
                                bt856_setbit(encoder, 0xdc, 3, 1);
233
                                bt856_setbit(encoder, 0xdc, 6, 1);
234
                                break;
235
                        case 2: // Color bar
236
                                bt856_setbit(encoder, 0xdc, 3, 0);
237
                                bt856_setbit(encoder, 0xde, 4, 1);
238
                                break;
239
                        default:
240
                                return -EINVAL;
241
 
242
                        }
243
                }
244
                break;
245
 
246
        case ENCODER_SET_OUTPUT:
247
                {
248
                        int *iarg = arg;
249
 
250
                        DEBUG(printk(KERN_INFO "%s-bt856: set output %d\n",
251
                                     encoder->bus->name, *iarg));
252
 
253
                        /* not much choice of outputs */
254
                        if (*iarg != 0) {
255
                                return -EINVAL;
256
                        }
257
                }
258
                break;
259
 
260
        case ENCODER_ENABLE_OUTPUT:
261
                {
262
                        int *iarg = arg;
263
 
264
                        encoder->enable = !!*iarg;
265
 
266
                        DEBUG(printk
267
                              (KERN_INFO "%s-bt856: enable output %d\n",
268
                               encoder->bus->name, encoder->enable));
269
                }
270
                break;
271
 
272
        default:
273
                return -EINVAL;
274
        }
275
 
276
        return 0;
277
}
278
 
279
/* ----------------------------------------------------------------------- */
280
 
281
static struct i2c_driver i2c_driver_bt856 = {
282
        "bt856",                /* name */
283
        I2C_DRIVERID_VIDEOENCODER,      /* ID */
284
        I2C_BT856, I2C_BT856 + 1,
285
        bt856_attach,
286
        bt856_detach,
287
        bt856_command
288
};
289
 
290
EXPORT_NO_SYMBOLS;
291
 
292
static int bt856_init(void)
293
{
294
        return i2c_register_driver(&i2c_driver_bt856);
295
}
296
 
297
static void bt856_exit(void)
298
{
299
        i2c_unregister_driver(&i2c_driver_bt856);
300
}
301
 
302
module_init(bt856_init);
303
module_exit(bt856_exit);
304
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

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