~isantop/system76-driver/pkexec

« back to all changes in this revision

Viewing changes to gspcav1/Sunplus/spca505_init.h

  • Committer: Carl Richell
  • Date: 2007-05-29 03:36:10 UTC
  • Revision ID: carl@system76.com-20070529033610-9qeih4btk1oxo6sj
initial bazaar revision - System76 Driver 2.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * SPCA505 chip based cameras initialization data
 
3
 *
 
4
 */
 
5
#ifndef SPCA505_INIT_H
 
6
#define SPCA505_INIT_H
 
7
 
 
8
#define SPCA50X_USB_CTRL 0x0 // spca505
 
9
#define SPCA50X_CUSB_ENABLE 0x1 // spca505
 
10
#define SPCA50X_REG_GLOBAL 0x3 // spca505
 
11
#define SPCA50X_GMISC0_IDSEL 0x1        // Global control device ID select spca505
 
12
#define SPCA50X_GLOBAL_MISC0 0x0        // Global control miscellaneous 0 spca505
 
13
 
 
14
#define SPCA50X_GLOBAL_MISC1 0x1 // 505
 
15
#define SPCA50X_GLOBAL_MISC3 0x3 // 505
 
16
#define SPCA50X_GMISC3_SAA7113RST 0x20  /* Not sure about this one spca505 */
 
17
 
 
18
#include "spca505.dat"
 
19
static int spca505_init(struct usb_spca50x *spca50x);
 
20
static void spca505_start(struct usb_spca50x *spca50x);
 
21
static void spca505_stopN(struct usb_spca50x *spca50x);
 
22
static void spca505_stop0(struct usb_spca50x *spca50x);
 
23
static __u16 spca505_getbrightness(struct usb_spca50x *spca50x);
 
24
static __u16 spca505_getcontrast(struct usb_spca50x *spca50x);
 
25
static __u16 spca505_getcolors(struct usb_spca50x *spca50x);
 
26
static void spca505_setbrightness(struct usb_spca50x *spca50x);
 
27
static void spca505_setcontrast(struct usb_spca50x *spca50x);
 
28
static void spca505_setcolors(struct usb_spca50x *spca50x);
 
29
static int spca505_config(struct usb_spca50x *spca50x);
 
30
static void spca505_shutdown(struct usb_spca50x *spca50x);
 
31
static void spca505_setAutobright(struct usb_spca50x *spca50x);
 
32
static void spca505_setquality(struct usb_spca50x *spca50x);
 
33
static int spca505_sofdetect(struct usb_spca50x *spca50x,struct spca50x_frame *frame, unsigned char *cdata,int *iPix, int seqnum, int *datalength);
 
34
/***************************************************************/
 
35
static void spca505_stop0(struct usb_spca50x *spca50x){}
 
36
static void spca505_setAutobright(struct usb_spca50x *spca50x){}
 
37
static void spca505_setquality(struct usb_spca50x *spca50x){}
 
38
/**************************************************************/
 
39
static struct cam_operation fspca505 = {
 
40
        .initialize = spca505_init,
 
41
        .configure = spca505_config,
 
42
        .start = spca505_start,
 
43
        .stopN = spca505_stopN,
 
44
        .stop0 = spca505_stop0,
 
45
        .get_bright = spca505_getbrightness,
 
46
        .set_bright = spca505_setbrightness,
 
47
        .get_contrast = spca505_getcontrast,
 
48
        .set_contrast = spca505_setcontrast,
 
49
        .get_colors = spca505_getcolors,
 
50
        .set_colors = spca505_setcolors,
 
51
        .set_autobright = spca505_setAutobright,
 
52
        .set_quality = spca505_setquality,
 
53
        .cam_shutdown = spca505_shutdown,
 
54
        .sof_detect = spca505_sofdetect,
 
55
 };
 
56
static int spca505_init(struct usb_spca50x *spca50x)
 
57
{
 
58
int err_code = 0;
 
59
            PDEBUG(2, "Initializing SPCA505");
 
60
            if (spca50x->desc == Nxultra) {
 
61
 
 
62
                spca50x_write_vector(spca50x, spca505b_open_data_ccd);
 
63
 
 
64
            } else {
 
65
 
 
66
                spca50x_write_vector(spca50x, spca505_open_data_ccd);
 
67
 
 
68
            }
 
69
            err_code = 0;
 
70
            err_code = spca50x_reg_read(spca50x->dev, 6, (__u16) 0x16, 2);
 
71
 
 
72
            if (err_code < 0) {
 
73
                PDEBUG(1,
 
74
                       "register read failed for after vector read err = %d",
 
75
                       err_code);
 
76
                return -EIO;
 
77
            } else {
 
78
                PDEBUG(3,
 
79
                       "After vector read returns : 0x%x should be 0x0101",
 
80
                       err_code & 0xFFFF);
 
81
            }
 
82
 
 
83
            err_code =
 
84
                spca50x_reg_write(spca50x->dev, 6, (__u16) 0x16, (__u16) 0xa);
 
85
            if (err_code < 0) {
 
86
                PDEBUG(1, "register write failed for (6,0xa,0x16) err=%d",
 
87
                       err_code);
 
88
                return -EIO;
 
89
            }
 
90
 
 
91
            spca50x_reg_write(spca50x->dev, 5, 0xc2, 18);
 
92
 
 
93
return 0;
 
94
}
 
95
static void spca505_start(struct usb_spca50x *spca50x)
 
96
{
 
97
    struct usb_device *dev = spca50x->dev;
 
98
    int err_code;
 
99
            //nessesary because without it we can see stream only once after loading module
 
100
            //stopping usb registers Tomasz change
 
101
            spca50x_reg_write(dev, 0x2, 0x0, 0x0);
 
102
switch(spca50x->mode){
 
103
    case 0:
 
104
    spca50x_reg_write(dev, 0x04, 0x0,
 
105
                          0);
 
106
    spca50x_reg_write(dev, 0x04, 0x06,
 
107
                          0x10);
 
108
    spca50x_reg_write(dev, 0x04, 0x07,
 
109
                          0x10);                            
 
110
    break;
 
111
    case 1:
 
112
    spca50x_reg_write(dev, 0x04, 0x0,
 
113
                          1);
 
114
    spca50x_reg_write(dev, 0x04, 0x06,
 
115
                          0x1a);
 
116
    spca50x_reg_write(dev, 0x04, 0x07,
 
117
                          0x1a);        
 
118
    break;
 
119
    case 2:
 
120
    spca50x_reg_write(dev, 0x04, 0x0,
 
121
                          2);
 
122
    spca50x_reg_write(dev, 0x04, 0x06,
 
123
                          0x1c);
 
124
    spca50x_reg_write(dev, 0x04, 0x07,
 
125
                          0x1d);        
 
126
    break;
 
127
    case 4:
 
128
    spca50x_reg_write(dev, 0x04, 0x0,
 
129
                          4);
 
130
    spca50x_reg_write(dev, 0x04, 0x06,
 
131
                          0x34);
 
132
    spca50x_reg_write(dev, 0x04, 0x07,
 
133
                          0x34);        
 
134
    break;
 
135
    case 5:
 
136
    spca50x_reg_write(dev, 0x04, 0x0,
 
137
                          5);
 
138
    spca50x_reg_write(dev, 0x04, 0x06,
 
139
                          0x40);
 
140
    spca50x_reg_write(dev, 0x04, 0x07,
 
141
                          0x40);        
 
142
    break;
 
143
    default:
 
144
     spca50x_reg_write(dev, 0x04, 0x0,
 
145
                          5);
 
146
    spca50x_reg_write(dev, 0x04, 0x06,
 
147
                          0x40);
 
148
    spca50x_reg_write(dev, 0x04, 0x07,
 
149
                          0x40);        
 
150
    break;
 
151
    }
 
152
            /* Enable ISO packet machine - should we do this here or in ISOC init ? */
 
153
            err_code = spca50x_reg_write(dev, SPCA50X_REG_USB,
 
154
                                         SPCA50X_USB_CTRL,
 
155
                                         SPCA50X_CUSB_ENABLE);
 
156
 
 
157
//                      spca50x_reg_write(dev, 0x5, 0x0, 0x0);
 
158
//                      spca50x_reg_write(dev, 0x5, 0x0, 0x1);
 
159
//                      spca50x_reg_write(dev, 0x5, 0x11, 0x2);
 
160
}
 
161
static void spca505_stopN(struct usb_spca50x *spca50x)
 
162
{
 
163
            spca50x_reg_write(spca50x->dev, 0x2, 0x0, 0x0);     //Disable ISO packet machine
 
164
}
 
165
static __u16 spca505_getbrightness(struct usb_spca50x *spca50x)
 
166
{
 
167
        spca50x->brightness =
 
168
            65535 - ((spca50x_reg_read(spca50x->dev, 5, 0x01, 1) >> 2) +
 
169
                     (spca50x_reg_read(spca50x->dev, 5, 0x0, 1) << 6));
 
170
return spca50x->brightness;
 
171
}
 
172
static __u16 spca505_getcontrast(struct usb_spca50x *spca50x)
 
173
{
 
174
spca50x->contrast = 0;
 
175
return spca50x->contrast;
 
176
}
 
177
static __u16 spca505_getcolors(struct usb_spca50x *spca50x)
 
178
{
 
179
spca50x->colour = 0;
 
180
return spca50x->colour;
 
181
}
 
182
static void spca505_setbrightness(struct usb_spca50x *spca50x)
 
183
{
 
184
    __u8 brightness = spca50x->brightness >> 8;
 
185
            spca50x_reg_write(spca50x->dev, 5, 0x0,
 
186
                              (255 - brightness) >> 6);
 
187
            spca50x_reg_write(spca50x->dev, 5, 0x01,
 
188
                              (255 - brightness) << 2);
 
189
 
 
190
}
 
191
static void spca505_setcontrast(struct usb_spca50x *spca50x)
 
192
{
 
193
}
 
194
static void spca505_setcolors(struct usb_spca50x *spca50x)
 
195
{
 
196
}
 
197
static int spca505_config(struct usb_spca50x *spca50x)
 
198
{
 
199
    memset(spca50x->mode_cam, 0x00, TOTMODE * sizeof(struct mwebcam));
 
200
  if (spca50x->desc == Nxultra) {  
 
201
    spca50x->mode_cam[VGA].width = 640;
 
202
    spca50x->mode_cam[VGA].height = 480;
 
203
    spca50x->mode_cam[VGA].t_palette =
 
204
        P_RAW | P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16;
 
205
    spca50x->mode_cam[VGA].pipe = 1023;
 
206
    spca50x->mode_cam[VGA].method = 0;
 
207
    spca50x->mode_cam[VGA].mode = 0;
 
208
    
 
209
    spca50x->mode_cam[PAL].width = 384;
 
210
    spca50x->mode_cam[PAL].height = 288;
 
211
    spca50x->mode_cam[PAL].t_palette =
 
212
        P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16;
 
213
    spca50x->mode_cam[PAL].pipe = 1023;
 
214
    spca50x->mode_cam[PAL].method = 1;
 
215
    spca50x->mode_cam[PAL].mode = 0;
 
216
    }
 
217
    spca50x->mode_cam[SIF].width = 352;
 
218
    spca50x->mode_cam[SIF].height = 288;
 
219
    spca50x->mode_cam[SIF].t_palette =
 
220
        P_RAW | P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16;
 
221
    spca50x->mode_cam[SIF].pipe = 1023;
 
222
    spca50x->mode_cam[SIF].method = 0;
 
223
    spca50x->mode_cam[SIF].mode = 1;
 
224
    
 
225
    spca50x->mode_cam[CIF].width = 320;
 
226
    spca50x->mode_cam[CIF].height = 240;
 
227
    spca50x->mode_cam[CIF].t_palette =
 
228
        P_RAW | P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16;
 
229
    spca50x->mode_cam[CIF].pipe = 896;
 
230
    spca50x->mode_cam[CIF].method = 0;
 
231
    spca50x->mode_cam[CIF].mode = 2;
 
232
    
 
233
    spca50x->mode_cam[QPAL].width = 192;
 
234
    spca50x->mode_cam[QPAL].height = 144;
 
235
    spca50x->mode_cam[QPAL].t_palette =
 
236
        P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16;
 
237
    spca50x->mode_cam[QPAL].pipe = 896;
 
238
    spca50x->mode_cam[QPAL].method = 1;
 
239
    spca50x->mode_cam[QPAL].mode = 2;
 
240
    
 
241
    spca50x->mode_cam[QSIF].width = 176;
 
242
    spca50x->mode_cam[QSIF].height = 144;
 
243
    spca50x->mode_cam[QSIF].t_palette =
 
244
        P_RAW | P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16;
 
245
    spca50x->mode_cam[QSIF].pipe = 512;
 
246
    spca50x->mode_cam[QSIF].method = 0;
 
247
    spca50x->mode_cam[QSIF].mode = 4;
 
248
    
 
249
    spca50x->mode_cam[QCIF].width = 160;
 
250
    spca50x->mode_cam[QCIF].height = 120;
 
251
    spca50x->mode_cam[QCIF].t_palette =
 
252
        P_RAW | P_YUV420 | P_RGB32 | P_RGB24 | P_RGB16;
 
253
    spca50x->mode_cam[QCIF].pipe = 384;
 
254
    spca50x->mode_cam[QCIF].method = 0;
 
255
    spca50x->mode_cam[QCIF].mode = 5;
 
256
    
 
257
            if (spca50x->desc == Nxultra) {
 
258
                if (spca50x_write_vector(spca50x, spca505b_init_data))
 
259
                    return -EIO;
 
260
            } else {
 
261
                if (spca50x_write_vector(spca50x, spca505_init_data))
 
262
                    return -EIO;
 
263
            }
 
264
    return 0;
 
265
}
 
266
static void spca505_shutdown(struct usb_spca50x *spca50x)
 
267
{
 
268
            spca50x_reg_write(spca50x->dev, 0x3, 0x3, 0x20);    // This maybe reset or power control
 
269
            spca50x_reg_write(spca50x->dev, 0x3, 0x1, 0x0);
 
270
            spca50x_reg_write(spca50x->dev, 0x3, 0x0, 0x1);
 
271
            spca50x_reg_write(spca50x->dev, 0x5, 0x10, 0x1);
 
272
            spca50x_reg_write(spca50x->dev, 0x5, 0x11, 0xF);
 
273
}
 
274
static int spca505_sofdetect(struct usb_spca50x *spca50x,struct spca50x_frame *frame, unsigned char *cdata,int *iPix, int seqnum, int *datalength)
 
275
{
 
276
        switch (cdata[0]){
 
277
           case 0:
 
278
                *iPix = SPCA50X_OFFSET_DATA;
 
279
                *datalength -= *iPix;
 
280
                return 0;
 
281
           case SPCA50X_SEQUENCE_DROP:
 
282
                return -1;
 
283
           default:
 
284
                *iPix = 1;
 
285
                *datalength -= *iPix;
 
286
                return seqnum+1 ;
 
287
           }
 
288
}
 
289
#endif                          /* SPCA505_INIT_H */
 
290
//eof