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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [media/] [video/] [indycam.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
 *  indycam.c - IndyCam digital camera driver
3
 *
4
 *  Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License version 2 as
8
 *  published by the Free Software Foundation.
9
 */
10
 
11
#include <linux/module.h>
12
#include <linux/init.h>
13
#include <linux/delay.h>
14
#include <linux/errno.h>
15
#include <linux/fs.h>
16
#include <linux/kernel.h>
17
#include <linux/major.h>
18
#include <linux/slab.h>
19
#include <linux/mm.h>
20
#include <linux/sched.h>
21
 
22
#include <linux/videodev.h>
23
/* IndyCam decodes stream of photons into digital image representation ;-) */
24
#include <linux/video_decoder.h>
25
#include <linux/i2c.h>
26
 
27
#include "indycam.h"
28
 
29
#define VINO_ADAPTER    (I2C_ALGO_SGI | I2C_HW_SGI_VINO)
30
 
31
struct indycam {
32
        struct i2c_client *client;
33
        int version;
34
};
35
 
36
static struct i2c_driver i2c_driver_indycam;
37
 
38
static int indycam_attach(struct i2c_adapter *adap, int addr, int kind)
39
{
40
        static const unsigned char initseq[] = {
41
                0,
42
                INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */
43
                INDYCAM_SHUTTER_60,     /* INDYCAM_SHUTTER */
44
                0x80,                   /* INDYCAM_GAIN */
45
                0xf0,                   /* INDYCAM_BRIGHTNESS */
46
                0x18,                   /* INDYCAM_RED_BALANCE */
47
                0xa4,                   /* INDYCAM_BLUE_BALANCE */
48
                0x80,                   /* INDYCAM_RED_SATURATION */
49
                0xc0,                   /* INDYCAM_BLUE_SATURATION */
50
                0x80,                   /* INDYCAM_GAMMA */
51
        };
52
 
53
        int err = 0;
54
        struct indycam *camera;
55
        struct i2c_client *client;
56
 
57
        client = kmalloc(sizeof(*client), GFP_KERNEL);
58
        if (!client)
59
                return -ENOMEM;
60
        camera = kmalloc(sizeof(*camera), GFP_KERNEL);
61
        if (!camera) {
62
                err = -ENOMEM;
63
                goto out_free_client;
64
        }
65
 
66
        client->data = camera;
67
        client->adapter = adap;
68
        client->addr = addr;
69
        client->driver = &i2c_driver_indycam;
70
        strcpy(client->name, "IndyCam client");
71
        camera->client = client;
72
 
73
        err = i2c_attach_client(client);
74
        if (err)
75
                goto out_free_camera;
76
 
77
        camera->version = i2c_smbus_read_byte_data(client, INDYCAM_VERSION);
78
        if (camera->version != CAMERA_VERSION_INDY &&
79
            camera->version != CAMERA_VERSION_MOOSE) {
80
                err = -ENODEV;
81
                goto out_detach_client;
82
        }
83
        printk(KERN_INFO "Indycam v%d.%d detected.\n",
84
               INDYCAM_VERSION_MAJOR(camera->version),
85
               INDYCAM_VERSION_MINOR(camera->version));
86
 
87
        err = i2c_master_send(client, initseq, sizeof(initseq));
88
        if (err)
89
                printk(KERN_INFO "IndyCam initalization failed\n");
90
 
91
        MOD_INC_USE_COUNT;
92
        return 0;
93
 
94
out_detach_client:
95
        i2c_detach_client(client);
96
out_free_camera:
97
        kfree(camera);
98
out_free_client:
99
        kfree(client);
100
        return err;
101
}
102
 
103
static int indycam_probe(struct i2c_adapter *adap)
104
{
105
        /* Indy specific crap */
106
        if (adap->id == VINO_ADAPTER)
107
                return indycam_attach(adap, INDYCAM_ADDR, 0);
108
        /* Feel free to add probe here :-) */
109
        return -ENODEV;
110
}
111
 
112
static int indycam_detach(struct i2c_client *client)
113
{
114
        struct indycam *camera = client->data;
115
 
116
        i2c_detach_client(client);
117
        kfree(camera);
118
        kfree(client);
119
        MOD_DEC_USE_COUNT;
120
        return 0;
121
}
122
 
123
static int indycam_command(struct i2c_client *client, unsigned int cmd,
124
                           void *arg)
125
{
126
        struct indycam *camera = client->data;
127
 
128
        switch (cmd) {
129
 
130
        case DECODER_GET_CAPABILITIES: {
131
                struct video_decoder_capability *cap = arg;
132
 
133
                cap->flags  = VIDEO_DECODER_NTSC;
134
                cap->inputs = 1;
135
                cap->outputs = 1;
136
                break;
137
        }
138
#if 0
139
        case DECODER_GET_VERSION: {
140
                int *iarg = arg;
141
 
142
                *iarg = camera->version;
143
                break;
144
        }
145
#endif
146
        case DECODER_GET_STATUS: {
147
                int *iarg = arg;
148
 
149
                *iarg = DECODER_STATUS_GOOD | DECODER_STATUS_NTSC |
150
                        DECODER_STATUS_COLOR;
151
                break;
152
        }
153
        case DECODER_SET_NORM: {
154
                int *iarg = arg;
155
 
156
                switch (*iarg) {
157
                case VIDEO_MODE_NTSC:
158
                        break;
159
                default:
160
                        return -EINVAL;
161
                }
162
                break;
163
        }
164
        case DECODER_SET_INPUT: {
165
                int *iarg = arg;
166
 
167
                if (*iarg != 0)
168
                        return -EINVAL;
169
                break;
170
        }
171
        case DECODER_SET_OUTPUT: {
172
                int *iarg = arg;
173
 
174
                if (*iarg != 0)
175
                        return -EINVAL;
176
                break;
177
        }
178
        case DECODER_ENABLE_OUTPUT: {
179
                /* Always enabled */
180
                break;
181
        }
182
        case DECODER_SET_PICTURE: {
183
                struct video_picture *pic = arg;
184
                /* TODO */
185
                break;
186
        }
187
        default:
188
                return -EINVAL;
189
        }
190
 
191
        return 0;
192
}
193
 
194
static struct i2c_driver i2c_driver_indycam = {
195
        .name           = "indycam",
196
        .id             = I2C_DRIVERID_INDYCAM,
197
        .flags          = I2C_DF_NOTIFY,
198
        .attach_adapter = indycam_probe,
199
        .detach_client  = indycam_detach,
200
        .command        = indycam_command,
201
};
202
 
203
static int indycam_init(void)
204
{
205
        return i2c_add_driver(&i2c_driver_indycam);
206
}
207
 
208
static void indycam_exit(void)
209
{
210
        i2c_del_driver(&i2c_driver_indycam);
211
}
212
 
213
module_init(indycam_init);
214
module_exit(indycam_exit);
215
 
216
MODULE_DESCRIPTION("SGI IndyCam driver");
217
MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>");
218
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

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