SyntekUSBVideoCamera
stk11xx-dev-6a54.c
Go to the documentation of this file.
00001 
00034 #include <linux/module.h>
00035 #include <linux/init.h>
00036 #include <linux/kernel.h>
00037 #include <linux/version.h>
00038 #include <linux/errno.h>
00039 #include <linux/slab.h>
00040 #include <linux/kref.h>
00041 
00042 #include <linux/usb.h>
00043 #include <media/v4l2-common.h>
00044 #include <media/v4l2-ioctl.h>
00045 
00046 #include "stk11xx.h"
00047 #include "stk11xx-dev.h"
00048 
00049 
00050 //=============================================================================
00051 //
00052 // STK-6A54 API
00053 //
00054 //=============================================================================
00055 
00056 
00070 int dev_stk6a54_initialize_device(struct usb_stk11xx *dev)
00071 {
00072     int retok;
00073     int value;
00074 
00075     STK_INFO("Initialize USB2.0 Syntek Camera\n");
00076 
00077     usb_stk11xx_write_registry(dev, 0x0000, 0x00e0);
00078     usb_stk11xx_write_registry(dev, 0x0002, 0x00f8);
00079     usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
00080     usb_stk11xx_write_registry(dev, 0x0000, 0x0020);
00081 
00082     dev_stk6a54_configure_device(dev, 0);
00083     retok = dev_stk11xx_check_device(dev, 65);
00084     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00085     usb_stk11xx_read_registry(dev, 0x02ff, &value);
00086     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00087     usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
00088     usb_stk11xx_write_registry(dev, 0x0208, 0x000a);
00089     usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
00090     retok = dev_stk11xx_check_device(dev, 65);
00091     usb_stk11xx_read_registry(dev, 0x0209, &value);
00092     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00093     usb_stk11xx_read_registry(dev, 0x02ff, &value);
00094     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00095     usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
00096     usb_stk11xx_write_registry(dev, 0x0208, 0x000b);
00097     usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
00098     retok = dev_stk11xx_check_device(dev, 65);
00099     usb_stk11xx_read_registry(dev, 0x0209, &value);
00100     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00101     usb_stk11xx_read_registry(dev, 0x02ff, &value);
00102     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00103     usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
00104     usb_stk11xx_write_registry(dev, 0x0208, 0x001c);
00105     usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
00106     retok = dev_stk11xx_check_device(dev, 65);
00107     usb_stk11xx_read_registry(dev, 0x0209, &value);
00108     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00109     usb_stk11xx_read_registry(dev, 0x02ff, &value);
00110     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00111     usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
00112     usb_stk11xx_write_registry(dev, 0x0208, 0x001d);
00113     usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
00114     retok = dev_stk11xx_check_device(dev, 65);
00115     usb_stk11xx_read_registry(dev, 0x0209, &value);
00116     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00117     usb_stk11xx_write_registry(dev, 0x0000, 0x00e0);
00118     usb_stk11xx_write_registry(dev, 0x0002, 0x00f8);
00119     usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
00120     usb_stk11xx_write_registry(dev, 0x0000, 0x0020);
00121     usb_stk11xx_write_registry(dev, 0x0100, 0x0021);
00122     usb_stk11xx_read_registry(dev, 0x0000, &value);
00123     usb_stk11xx_write_registry(dev, 0x0000, 0x004b);
00124 
00125 
00126     dev_stk6a54_configure_device(dev, 1);
00127 
00128     usb_stk11xx_set_feature(dev, 0);
00129 
00130     // Device is initialized and is ready !!!
00131     STK_INFO("Syntek USB2.0 Camera is ready\n");
00132 
00133     return 0;
00134 }
00135 
00136 
00150 int dev_stk6a54_configure_device(struct usb_stk11xx *dev, int step)
00151 {
00152     int value;
00153 
00154     //     0,    1
00155     static const int values_001B[] = {
00156         0x0e, 0x0e
00157     };
00158     static const int values_001C[] = {
00159         0x46, 0x46
00160     };
00161     static const int values_0202[] = {
00162         0x1e, 0x1e
00163     };
00164     static const int values_0110[] = {
00165         0x00, 0x00
00166     };
00167     static const int values_0112[] = {
00168         0x00, 0x00
00169     };
00170     static const int values_0114[] = {
00171         0x00, 0x00
00172     };
00173     static const int values_0115[] = {
00174         0x00, 0x05
00175     };
00176     static const int values_0116[] = {
00177         0x00, 0xe0
00178     };
00179     static const int values_0117[] = {
00180         0x00, 0x01
00181     };
00182     static const int values_0100[] = {
00183         0x21, 0x21
00184     };
00185 
00186 
00187     STK_DEBUG("dev_stk6a54_configure_device : %d\n", step);
00188 
00189     usb_stk11xx_write_registry(dev, 0x0000, 0x0024);
00190     usb_stk11xx_write_registry(dev, 0x0002, 0x0078);
00191     usb_stk11xx_write_registry(dev, 0x0003, 0x0080);
00192     usb_stk11xx_write_registry(dev, 0x0005, 0x0000);
00193     
00194     usb_stk11xx_write_registry(dev, 0x0007, 0x0003);
00195     usb_stk11xx_write_registry(dev, 0x000d, 0x0000);
00196     usb_stk11xx_write_registry(dev, 0x000f, 0x0002);
00197     usb_stk11xx_write_registry(dev, 0x0300, 0x0012);
00198     usb_stk11xx_write_registry(dev, 0x0350, 0x0041);
00199     
00200     usb_stk11xx_write_registry(dev, 0x0351, 0x0000);
00201     usb_stk11xx_write_registry(dev, 0x0352, 0x0000);
00202     usb_stk11xx_write_registry(dev, 0x0353, 0x0000);
00203     usb_stk11xx_write_registry(dev, 0x0018, 0x0010);
00204     usb_stk11xx_write_registry(dev, 0x0019, 0x0000);
00205     
00206     usb_stk11xx_write_registry(dev, 0x001b, values_001B[step]);
00207     usb_stk11xx_write_registry(dev, 0x001c, values_001C[step]);
00208     usb_stk11xx_write_registry(dev, 0x0300, 0x0080);
00209     usb_stk11xx_write_registry(dev, 0x001a, 0x0004);
00210     usb_stk11xx_write_registry(dev, 0x0202, values_0202[step]);
00211     
00212     usb_stk11xx_write_registry(dev, 0x0110, values_0110[step]);
00213     usb_stk11xx_write_registry(dev, 0x0111, 0x0000);
00214     usb_stk11xx_write_registry(dev, 0x0112, values_0112[step]);
00215     usb_stk11xx_write_registry(dev, 0x0113, 0x0000);
00216     usb_stk11xx_write_registry(dev, 0x0114, values_0114[step]);
00217     
00218     usb_stk11xx_write_registry(dev, 0x0115, values_0115[step]);
00219     usb_stk11xx_write_registry(dev, 0x0116, values_0116[step]);
00220     usb_stk11xx_write_registry(dev, 0x0117, values_0117[step]);
00221 
00222     usb_stk11xx_read_registry(dev, 0x0100, &value);
00223     usb_stk11xx_write_registry(dev, 0x0100, values_0100[step]);
00224 
00225     usb_stk11xx_write_registry(dev, 0x02ff, 0x0000); 
00226 
00227 
00228     switch (step) {
00229         case 0:
00230             usb_stk11xx_write_registry(dev, 0x0203, 0x0060); 
00231 
00232             usb_stk11xx_read_registry(dev, 0x02ff, &value);
00233             usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00234 
00235             usb_stk11xx_write_registry(dev, 0x0203, 0x0060); 
00236 
00237             usb_stk11xx_write_registry(dev, 0x0204, 0x00ff); 
00238             usb_stk11xx_write_registry(dev, 0x0205, 0x0001); 
00239 
00240             usb_stk11xx_write_registry(dev, 0x0200, 0x0001); 
00241 
00242             break;
00243     
00244         case 1:
00245             usb_stk11xx_write_registry(dev, 0x0203, 0x0060); 
00246 
00247             dev_stk6a54_sensor_settings(dev);
00248 
00249             usb_stk11xx_read_registry(dev, 0x0209, &value);
00250             usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00251 
00252             break;
00253     }
00254 
00255     return 0;
00256 }
00257 
00258 
00268 int dev_stk6a54_camera_asleep(struct usb_stk11xx *dev)
00269 {
00270     int value;
00271 
00272     usb_stk11xx_read_registry(dev, 0x0104, &value);
00273     usb_stk11xx_read_registry(dev, 0x0105, &value);
00274     usb_stk11xx_read_registry(dev, 0x0106, &value);
00275 
00276     usb_stk11xx_write_registry(dev, 0x0100, 0x0021);
00277     usb_stk11xx_write_registry(dev, 0x0116, 0x0000);
00278     usb_stk11xx_write_registry(dev, 0x0117, 0x0000);
00279     usb_stk11xx_write_registry(dev, 0x0018, 0x0000);
00280 
00281     usb_stk11xx_read_registry(dev, 0x0000, &value);
00282     usb_stk11xx_write_registry(dev, 0x0000, 0x0049);
00283 
00284     return 0;
00285 }
00286 
00287 
00298 int dev_stk6a54_init_camera(struct usb_stk11xx *dev)
00299 {
00300     return 0;
00301 }
00302 
00303 
00314 int dev_stk6a54_sensor_settings(struct usb_stk11xx *dev)
00315 {
00316     int i;
00317     int retok;
00318     int value;
00319 
00320     int asize;
00321 
00322     static const int values_204[] = {
00323         0xff, 0x12, 0xff, 0x2c, 0x2e, 0xff, 0x3c, 0x11, 0x09, 0x04, 
00324         0x13, 0x14, 0x2c, 0x33, 0x3a, 0x3b, 0x3e, 0x43, 0x16, 0x39, 
00325         0x35, 0x22, 0x37, 0x23, 0x34, 0x36, 0x06, 0x07, 0x0d, 0x0e, 
00326         0x4c, 0x4a, 0x21, 0x24, 0x25, 0x26, 0x5c, 0x63, 0x46, 0x0c, 
00327         0x61, 0x62, 0x7c, 0x20, 0x28, 0x6c, 0x6d, 0x6e, 0x70, 0x71, 
00328         0x73, 0x3d, 0x5a, 0x4f, 0x50, 0xff, 0xe5, 0xf9, 0x41, 0xe0, 
00329         0x76, 0x33, 0x42, 0x43, 0x4c, 0x87, 0x88, 0xd7, 0xd9, 0xd3, 
00330         0xc8, 0xc9, 0x7c, 0x7d, 0x7c, 0x7d, 0x7d, 0x7c, 0x7d, 0x7d, 
00331         0x7d, 0x90, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 
00332         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x92, 0x93, 
00333         0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 0x93, 
00334         0x93, 0x93, 0x96, 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 
00335         0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0xc3, 0xa4, 0xa8, 0xc5, 
00336         0xc6, 0xbf, 0xc7, 0xb6, 0xb8, 0xb7, 0xb9, 0xb3, 0xb4, 0xb5, 
00337         0xb0, 0xb1, 0xb2, 0xc4, 0xc0, 0xc1, 0x86, 0x50, 0x51, 0x52, 
00338         0x53, 0x54, 0x55, 0x57, 0x5a, 0x5b, 0x5c, 0xc3, 0x7f, 0xda, 
00339         0xd7, 0xe5, 0xe1, 0xe0, 0xdd, 0x05, 0xff, 0x12, 0x11, 0x17, 
00340         0x18, 0x19, 0x1a, 0x32, 0x37, 0x4f, 0x50, 0x5a, 0x6d, 0x3d, 
00341         0x39, 0x35, 0x22, 0x37, 0x23, 0x34, 0x36, 0x06, 0x07, 0x0d, 
00342         0x0e, 0x4c, 0xff, 0xe0, 0xc0, 0xc1, 0x8c, 0x86, 0x50, 0x51, 
00343         0x52, 0x53, 0x54, 0x55, 0x5a, 0x5b, 0x5c, 0xd3, 0xe0, 0xff, 
00344         0xe0, 0xc0, 0xc1, 0x8c, 0x86, 0x50, 0x51, 0x52, 0x53, 0x54, 
00345         0x55, 0x5a, 0x5b, 0x5c, 0xd3, 0xe0, 0xff, 0xff, 0x04, 0xff, 
00346         0xff, 0xff, 0x7c, 0x7d, 0x7c, 0x7c, 0x7d, 0x7c, 0x7d, 0x7c, 
00347         0xff, 0x7c, 0x7d, 0x7c, 0x7d, 0x7c, 0xff, 0x7c, 0x7d, 0x7c, 
00348         0x7d, 0x7c, 0x7d, 0x7c, 0x7c, 0xff, 0x7c, 0x7d, 0x7c, 0x7d, 
00349         0x7c, 0x7d, 0xff, 0x92, 0x93, 0xff, 0x90, 0x91, 0x91, 0x91, 
00350         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 
00351         0x91, 0x91, 0x91, 0xff, 0xc3, 0xc7, 0xce, 0xcc, 0xcd, 0xff, 
00352         0x04, 0xff, 0x04
00353     };
00354 
00355     static const int values_205[] = {
00356         0x01, 0x80, 0x00, 0xff, 0xdf, 0x01, 0x32, 0x00, 0x02, 0x28, 
00357         0xe5, 0x48, 0x0c, 0x78, 0x33, 0xfb, 0x00, 0x11, 0x10, 0x02, 
00358         0x88, 0x0a, 0x40, 0x00, 0xa0, 0x1a, 0x02, 0xc0, 0xb7, 0x01, 
00359         0x00, 0x81, 0x99, 0x40, 0x38, 0x82, 0x00, 0x00, 0x3f, 0x3c, 
00360         0x70, 0x80, 0x05, 0x80, 0x30, 0x00, 0x80, 0x00, 0x02, 0x94, 
00361         0xc1, 0x34, 0x57, 0xbb, 0x9c, 0x00, 0x7f, 0xc0, 0x24, 0x14, 
00362         0xff, 0xa0, 0x20, 0x18, 0x00, 0xd0, 0x3f, 0x03, 0x10, 0x82, 
00363         0x08, 0x80, 0x00, 0x00, 0x03, 0x48, 0x48, 0x08, 0x20, 0x10, 
00364         0x0e, 0x00, 0x0e, 0x1a, 0x31, 0x5a, 0x69, 0x75, 0x7e, 0x88, 
00365         0x8f, 0x96, 0xa3, 0xaf, 0xc4, 0xd7, 0xe8, 0x20, 0x00, 0x06, 
00366         0xe3, 0x05, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 
00367         0x00, 0x00, 0x00, 0x08, 0x19, 0x02, 0x0c, 0x24, 0x30, 0x28, 
00368         0x26, 0x02, 0x98, 0x80, 0x00, 0x00, 0xed, 0x00, 0x00, 0x11, 
00369         0x51, 0x80, 0x10, 0x66, 0xa5, 0x64, 0x7c, 0xaf, 0x97, 0xff, 
00370         0xc5, 0x94, 0x0f, 0x5c, 0xc8, 0x96, 0x3d, 0x00, 0x90, 0x18, 
00371         0x00, 0x00, 0x88, 0x00, 0x90, 0x18, 0x05, 0xed, 0x00, 0x00, 
00372         0x01, 0x1f, 0x67, 0x00, 0xff, 0x00, 0x01, 0x40, 0x00, 0x11, 
00373         0x43, 0x00, 0x4b, 0x09, 0xc0, 0xca, 0xa8, 0x23, 0x00, 0x38, 
00374         0x12, 0xda, 0x1a, 0xc3, 0x00, 0xc0, 0x1a, 0x88, 0xc0, 0x87, 
00375         0x41, 0x00, 0x00, 0x04, 0x64, 0x4b, 0x00, 0x1d, 0x00, 0xc8, 
00376         0x96, 0x00, 0x00, 0x00, 0xc8, 0x96, 0x00, 0x82, 0x00, 0x00, 
00377         0x04, 0x64, 0x4b, 0x00, 0x3d, 0x00, 0xc8, 0x96, 0x00, 0x00, 
00378         0x00, 0xa0, 0x78, 0x00, 0x82, 0x00, 0x00, 0x01, 0xfa, 0x01, 
00379         0x00, 0x00, 0x00, 0x04, 0x0a, 0x09, 0x16, 0x0a, 0x06, 0x09, 
00380         0x00, 0x00, 0x04, 0x08, 0x28, 0x08, 0x00, 0x00, 0x05, 0x01, 
00381         0x7f, 0x02, 0x00, 0x0a, 0x05, 0x00, 0x00, 0x07, 0x03, 0x4d, 
00382         0x04, 0x4d, 0x00, 0x01, 0xc5, 0x00, 0x00, 0x00, 0x23, 0x3c, 
00383         0x50, 0x63, 0x73, 0x83, 0x92, 0xa0, 0xad, 0xba, 0xc6, 0xd2, 
00384         0xde, 0xe9, 0xf5, 0x01, 0x0c, 0x00, 0x80, 0x80, 0x80, 0x01, 
00385         0xfa, 0x01, 0xfa
00386     };
00387 
00388     asize = ARRAY_SIZE(values_204);
00389 
00390     for(i=0; i<asize; i++) {
00391         usb_stk11xx_read_registry(dev, 0x02ff, &value);
00392         usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00393 
00394         usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
00395 
00396         usb_stk11xx_write_registry(dev, 0x0204, values_204[i]);
00397         usb_stk11xx_write_registry(dev, 0x0205, values_205[i]);
00398         usb_stk11xx_write_registry(dev, 0x0200, 0x0001);
00399 
00400         retok = dev_stk11xx_check_device(dev, 500);
00401 
00402         if (retok != 1) {
00403             STK_ERROR("Load default sensor settings fail !\n");
00404             return -1;
00405         }
00406 
00407         usb_stk11xx_write_registry(dev, 0x02ff, 0x0000);
00408     }
00409 
00410     usb_stk11xx_read_registry(dev, 0x02ff, &value);
00411 
00412     usb_stk11xx_write_registry(dev, 0x0203, 0x0060);
00413 
00414     usb_stk11xx_write_registry(dev, 0x0208, 0x0004);
00415 
00416     usb_stk11xx_write_registry(dev, 0x0200, 0x0020);
00417 
00418     retok = dev_stk11xx_check_device(dev, 500);
00419 
00420     return 0;
00421 }
00422 
00423 
00437 int dev_stk6a54_camera_settings(struct usb_stk11xx *dev)
00438 {
00439     return 0;
00440 }
00441 
00442 
00456 int dev_stk6a54_set_camera_quality(struct usb_stk11xx *dev)
00457 {
00458     return 0;
00459 }
00460 
00461 
00471 int dev_stk6a54_set_camera_fps(struct usb_stk11xx *dev)
00472 {
00473     return 0;
00474 }
00475 
00476 
00487 int dev_stk6a54_start_stream(struct usb_stk11xx *dev)
00488 {
00489     return 0;
00490 }
00491 
00492 
00502 int dev_stk6a54_reconf_camera(struct usb_stk11xx *dev)
00503 {
00504     dev_stk11xx_camera_settings(dev);
00505 
00506     return 0;
00507 }
00508 
00509 
00520 int dev_stk6a54_stop_stream(struct usb_stk11xx *dev)
00521 {
00522     return 0;
00523 }
00524 
00525