aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2010-06-09 10:39:50 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-10-20 23:04:45 -0400
commit59f90a01e8f1a377213ae6b6f8e8399975c0dc3b (patch)
tree5a4bb3c8b0efe73c9d68ba292fff76c43d19bc9d /drivers
parent1f33de0f8b91b70ccadb44958f09aa5bee7c1a44 (diff)
V4L/DVB: gspca_xirlink_cit: Add support for Model 1, 2 & 4 cameras
Note this is untested as I don't have hardware to test, but all initsequences were taken over 1 on 1 from the old ibmcam driver so things should work. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/gspca/xirlink_cit.c1225
1 files changed, 1191 insertions, 34 deletions
diff --git a/drivers/media/video/gspca/xirlink_cit.c b/drivers/media/video/gspca/xirlink_cit.c
index 3525e783f7a2..6f2dece12463 100644
--- a/drivers/media/video/gspca/xirlink_cit.c
+++ b/drivers/media/video/gspca/xirlink_cit.c
@@ -57,11 +57,14 @@ struct sd {
57#define CIT_MODEL4 3 57#define CIT_MODEL4 3
58#define CIT_IBM_NETCAM_PRO 4 58#define CIT_IBM_NETCAM_PRO 4
59 u8 input_index; 59 u8 input_index;
60 u8 stop_on_control_change;
60 u8 sof_read; 61 u8 sof_read;
62 u8 sof_len;
61 u8 contrast; 63 u8 contrast;
62 u8 brightness; 64 u8 brightness;
63 u8 hue; 65 u8 hue;
64 u8 sharpness; 66 u8 sharpness;
67 u8 lighting;
65}; 68};
66 69
67/* V4L2 controls supported by the driver */ 70/* V4L2 controls supported by the driver */
@@ -73,6 +76,8 @@ static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
73static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val); 76static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
74static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); 77static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
75static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); 78static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
79static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val);
80static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val);
76static void sd_stop0(struct gspca_dev *gspca_dev); 81static void sd_stop0(struct gspca_dev *gspca_dev);
77 82
78static const struct ctrl sd_ctrls[] = { 83static const struct ctrl sd_ctrls[] = {
@@ -82,10 +87,10 @@ static const struct ctrl sd_ctrls[] = {
82 .id = V4L2_CID_BRIGHTNESS, 87 .id = V4L2_CID_BRIGHTNESS,
83 .type = V4L2_CTRL_TYPE_INTEGER, 88 .type = V4L2_CTRL_TYPE_INTEGER,
84 .name = "Brightness", 89 .name = "Brightness",
85 .minimum = 0x0c, 90 .minimum = 0,
86 .maximum = 0x3f, 91 .maximum = 63,
87 .step = 1, 92 .step = 1,
88#define BRIGHTNESS_DEFAULT 0x20 93#define BRIGHTNESS_DEFAULT 32
89 .default_value = BRIGHTNESS_DEFAULT, 94 .default_value = BRIGHTNESS_DEFAULT,
90 .flags = 0, 95 .flags = 0,
91 }, 96 },
@@ -114,10 +119,10 @@ static const struct ctrl sd_ctrls[] = {
114 .id = V4L2_CID_HUE, 119 .id = V4L2_CID_HUE,
115 .type = V4L2_CTRL_TYPE_INTEGER, 120 .type = V4L2_CTRL_TYPE_INTEGER,
116 .name = "Hue", 121 .name = "Hue",
117 .minimum = 0x05, 122 .minimum = 0,
118 .maximum = 0x37, 123 .maximum = 127,
119 .step = 1, 124 .step = 1,
120#define HUE_DEFAULT 0x20 125#define HUE_DEFAULT 63
121 .default_value = HUE_DEFAULT, 126 .default_value = HUE_DEFAULT,
122 .flags = 0, 127 .flags = 0,
123 }, 128 },
@@ -140,6 +145,33 @@ static const struct ctrl sd_ctrls[] = {
140 .set = sd_setsharpness, 145 .set = sd_setsharpness,
141 .get = sd_getsharpness, 146 .get = sd_getsharpness,
142 }, 147 },
148#define SD_LIGHTING 4
149 {
150 {
151 .id = V4L2_CID_BACKLIGHT_COMPENSATION,
152 .type = V4L2_CTRL_TYPE_INTEGER,
153 .name = "Lighting",
154 .minimum = 0,
155 .maximum = 2,
156 .step = 1,
157#define LIGHTING_DEFAULT 1
158 .default_value = LIGHTING_DEFAULT,
159 .flags = 0,
160 },
161 .set = sd_setlighting,
162 .get = sd_getlighting,
163 },
164};
165
166static const struct v4l2_pix_format cif_yuv_mode[] = {
167 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
168 .bytesperline = 176,
169 .sizeimage = 160 * 144 * 3 / 2,
170 .colorspace = V4L2_COLORSPACE_SRGB},
171 {352, 288, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
172 .bytesperline = 352,
173 .sizeimage = 352 * 288 * 3 / 2,
174 .colorspace = V4L2_COLORSPACE_SRGB},
143}; 175};
144 176
145static const struct v4l2_pix_format vga_yuv_mode[] = { 177static const struct v4l2_pix_format vga_yuv_mode[] = {
@@ -157,6 +189,25 @@ static const struct v4l2_pix_format vga_yuv_mode[] = {
157 .colorspace = V4L2_COLORSPACE_SRGB}, 189 .colorspace = V4L2_COLORSPACE_SRGB},
158}; 190};
159 191
192static const struct v4l2_pix_format model2_mode[] = {
193 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
194 .bytesperline = 160,
195 .sizeimage = 160 * 120 * 3 / 2,
196 .colorspace = V4L2_COLORSPACE_SRGB},
197 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
198 .bytesperline = 176,
199 .sizeimage = 176 * 144 * 3 / 2,
200 .colorspace = V4L2_COLORSPACE_SRGB},
201 {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
202 .bytesperline = 320,
203 .sizeimage = 320 * 240,
204 .colorspace = V4L2_COLORSPACE_SRGB},
205 {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
206 .bytesperline = 352,
207 .sizeimage = 352 * 288,
208 .colorspace = V4L2_COLORSPACE_SRGB},
209};
210
160/* 211/*
161 * 01.01.08 - Added for RCA video in support -LO 212 * 01.01.08 - Added for RCA video in support -LO
162 * This struct is used to init the Model3 cam to use the RCA video in port 213 * This struct is used to init the Model3 cam to use the RCA video in port
@@ -699,6 +750,11 @@ static const u16 rca_initdata[][3] = {
699 {0, 0x0003, 0x0111}, 750 {0, 0x0003, 0x0111},
700}; 751};
701 752
753/* TESTME the old ibmcam driver repeats certain commands to Model1 cameras, we
754 do the same for now (testing needed to see if this is really necessary) */
755static const int cit_model1_ntries = 5;
756static const int cit_model1_ntries2 = 2;
757
702static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index) 758static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index)
703{ 759{
704 struct usb_device *udev = gspca_dev->dev; 760 struct usb_device *udev = gspca_dev->dev;
@@ -739,7 +795,116 @@ static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index)
739} 795}
740 796
741/* 797/*
742 * ibmcam_model3_Packet1() 798 * cit_send_FF_04_02()
799 *
800 * This procedure sends magic 3-command prefix to the camera.
801 * The purpose of this prefix is not known.
802 *
803 * History:
804 * 1/2/00 Created.
805 */
806static void cit_send_FF_04_02(struct gspca_dev *gspca_dev)
807{
808 cit_write_reg(gspca_dev, 0x00FF, 0x0127);
809 cit_write_reg(gspca_dev, 0x0004, 0x0124);
810 cit_write_reg(gspca_dev, 0x0002, 0x0124);
811}
812
813static void cit_send_00_04_06(struct gspca_dev *gspca_dev)
814{
815 cit_write_reg(gspca_dev, 0x0000, 0x0127);
816 cit_write_reg(gspca_dev, 0x0004, 0x0124);
817 cit_write_reg(gspca_dev, 0x0006, 0x0124);
818}
819
820static void cit_send_x_00(struct gspca_dev *gspca_dev, unsigned short x)
821{
822 cit_write_reg(gspca_dev, x, 0x0127);
823 cit_write_reg(gspca_dev, 0x0000, 0x0124);
824}
825
826static void cit_send_x_00_05(struct gspca_dev *gspca_dev, unsigned short x)
827{
828 cit_send_x_00(gspca_dev, x);
829 cit_write_reg(gspca_dev, 0x0005, 0x0124);
830}
831
832static void cit_send_x_00_05_02(struct gspca_dev *gspca_dev, unsigned short x)
833{
834 cit_write_reg(gspca_dev, x, 0x0127);
835 cit_write_reg(gspca_dev, 0x0000, 0x0124);
836 cit_write_reg(gspca_dev, 0x0005, 0x0124);
837 cit_write_reg(gspca_dev, 0x0002, 0x0124);
838}
839
840static void cit_send_x_01_00_05(struct gspca_dev *gspca_dev, u16 x)
841{
842 cit_write_reg(gspca_dev, x, 0x0127);
843 cit_write_reg(gspca_dev, 0x0001, 0x0124);
844 cit_write_reg(gspca_dev, 0x0000, 0x0124);
845 cit_write_reg(gspca_dev, 0x0005, 0x0124);
846}
847
848static void cit_send_x_00_05_02_01(struct gspca_dev *gspca_dev, u16 x)
849{
850 cit_write_reg(gspca_dev, x, 0x0127);
851 cit_write_reg(gspca_dev, 0x0000, 0x0124);
852 cit_write_reg(gspca_dev, 0x0005, 0x0124);
853 cit_write_reg(gspca_dev, 0x0002, 0x0124);
854 cit_write_reg(gspca_dev, 0x0001, 0x0124);
855}
856
857static void cit_send_x_00_05_02_08_01(struct gspca_dev *gspca_dev, u16 x)
858{
859 cit_write_reg(gspca_dev, x, 0x0127);
860 cit_write_reg(gspca_dev, 0x0000, 0x0124);
861 cit_write_reg(gspca_dev, 0x0005, 0x0124);
862 cit_write_reg(gspca_dev, 0x0002, 0x0124);
863 cit_write_reg(gspca_dev, 0x0008, 0x0124);
864 cit_write_reg(gspca_dev, 0x0001, 0x0124);
865}
866
867static void cit_Packet_Format1(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
868{
869 cit_send_x_01_00_05(gspca_dev, 0x0088);
870 cit_send_x_00_05(gspca_dev, fkey);
871 cit_send_x_00_05_02_08_01(gspca_dev, val);
872 cit_send_x_00_05(gspca_dev, 0x0088);
873 cit_send_x_00_05_02_01(gspca_dev, fkey);
874 cit_send_x_00_05(gspca_dev, 0x0089);
875 cit_send_x_00(gspca_dev, fkey);
876 cit_send_00_04_06(gspca_dev);
877 cit_read_reg(gspca_dev, 0x0126);
878 cit_send_FF_04_02(gspca_dev);
879}
880
881static void cit_PacketFormat2(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
882{
883 cit_send_x_01_00_05(gspca_dev, 0x0088);
884 cit_send_x_00_05(gspca_dev, fkey);
885 cit_send_x_00_05_02(gspca_dev, val);
886}
887
888static void cit_model2_Packet2(struct gspca_dev *gspca_dev)
889{
890 cit_write_reg(gspca_dev, 0x00ff, 0x012d);
891 cit_write_reg(gspca_dev, 0xfea3, 0x0124);
892}
893
894static void cit_model2_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
895{
896 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
897 cit_write_reg(gspca_dev, 0x00ff, 0x012e);
898 cit_write_reg(gspca_dev, v1, 0x012f);
899 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
900 cit_write_reg(gspca_dev, 0xc719, 0x0124);
901 cit_write_reg(gspca_dev, v2, 0x0127);
902
903 cit_model2_Packet2(gspca_dev);
904}
905
906/*
907 * cit_model3_Packet1()
743 * 908 *
744 * 00_0078_012d 909 * 00_0078_012d
745 * 00_0097_012f 910 * 00_0097_012f
@@ -756,6 +921,29 @@ static void cit_model3_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
756 cit_write_reg(gspca_dev, 0xfea8, 0x0124); 921 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
757} 922}
758 923
924static void cit_model4_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2)
925{
926 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
927 cit_write_reg(gspca_dev, v1, 0x012f);
928 cit_write_reg(gspca_dev, 0xd141, 0x0124);
929 cit_write_reg(gspca_dev, v2, 0x0127);
930 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
931}
932
933static void cit_model4_BrightnessPacket(struct gspca_dev *gspca_dev, u16 val)
934{
935 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
936 cit_write_reg(gspca_dev, 0x0026, 0x012f);
937 cit_write_reg(gspca_dev, 0xd141, 0x0124);
938 cit_write_reg(gspca_dev, val, 0x0127);
939 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
940 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
941 cit_write_reg(gspca_dev, 0x0038, 0x012d);
942 cit_write_reg(gspca_dev, 0x0004, 0x012f);
943 cit_write_reg(gspca_dev, 0xd145, 0x0124);
944 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
945}
946
759/* this function is called at probe time */ 947/* this function is called at probe time */
760static int sd_config(struct gspca_dev *gspca_dev, 948static int sd_config(struct gspca_dev *gspca_dev,
761 const struct usb_device_id *id) 949 const struct usb_device_id *id)
@@ -769,16 +957,36 @@ static int sd_config(struct gspca_dev *gspca_dev,
769 957
770 cam = &gspca_dev->cam; 958 cam = &gspca_dev->cam;
771 switch (sd->model) { 959 switch (sd->model) {
960 case CIT_MODEL1:
961 cam->cam_mode = cif_yuv_mode;
962 cam->nmodes = ARRAY_SIZE(cif_yuv_mode);
963 gspca_dev->ctrl_dis = (1 << SD_HUE);
964 break;
965 case CIT_MODEL2:
966 cam->cam_mode = model2_mode + 1; /* no 160x120 */
967 cam->nmodes = 3;
968 gspca_dev->ctrl_dis = (1 << SD_CONTRAST) |
969 (1 << SD_SHARPNESS);
970 break;
772 case CIT_MODEL3: 971 case CIT_MODEL3:
773 cam->cam_mode = vga_yuv_mode; 972 cam->cam_mode = vga_yuv_mode;
774 cam->nmodes = ARRAY_SIZE(vga_yuv_mode); 973 cam->nmodes = ARRAY_SIZE(vga_yuv_mode);
775 gspca_dev->ctrl_dis = (1 << SD_HUE); 974 gspca_dev->ctrl_dis = (1 << SD_HUE) | (1 << SD_LIGHTING);
975 sd->stop_on_control_change = 1;
976 break;
977 case CIT_MODEL4:
978 cam->cam_mode = model2_mode;
979 cam->nmodes = ARRAY_SIZE(model2_mode);
980 gspca_dev->ctrl_dis = (1 << SD_CONTRAST) |
981 (1 << SD_SHARPNESS) |
982 (1 << SD_LIGHTING);
776 break; 983 break;
777 case CIT_IBM_NETCAM_PRO: 984 case CIT_IBM_NETCAM_PRO:
778 cam->cam_mode = vga_yuv_mode; 985 cam->cam_mode = vga_yuv_mode;
779 cam->nmodes = 2; /* no 640 x 480 */ 986 cam->nmodes = 2; /* no 640 x 480 */
780 cam->input_flags = V4L2_IN_ST_VFLIP; 987 cam->input_flags = V4L2_IN_ST_VFLIP;
781 gspca_dev->ctrl_dis = ~(1 << SD_CONTRAST); 988 gspca_dev->ctrl_dis = ~(1 << SD_CONTRAST);
989 sd->stop_on_control_change = 1;
782 break; 990 break;
783 } 991 }
784 992
@@ -786,6 +994,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
786 sd->contrast = CONTRAST_DEFAULT; 994 sd->contrast = CONTRAST_DEFAULT;
787 sd->hue = HUE_DEFAULT; 995 sd->hue = HUE_DEFAULT;
788 sd->sharpness = SHARPNESS_DEFAULT; 996 sd->sharpness = SHARPNESS_DEFAULT;
997 sd->lighting = LIGHTING_DEFAULT;
789 998
790 return 0; 999 return 0;
791} 1000}
@@ -988,7 +1197,10 @@ static int sd_init(struct gspca_dev *gspca_dev)
988 struct sd *sd = (struct sd *) gspca_dev; 1197 struct sd *sd = (struct sd *) gspca_dev;
989 1198
990 switch (sd->model) { 1199 switch (sd->model) {
1200 case CIT_MODEL1:
1201 case CIT_MODEL2:
991 case CIT_MODEL3: 1202 case CIT_MODEL3:
1203 case CIT_MODEL4:
992 break; /* All is done in sd_start */ 1204 break; /* All is done in sd_start */
993 case CIT_IBM_NETCAM_PRO: 1205 case CIT_IBM_NETCAM_PRO:
994 cit_init_ibm_netcam_pro(gspca_dev); 1206 cit_init_ibm_netcam_pro(gspca_dev);
@@ -1001,11 +1213,33 @@ static int sd_init(struct gspca_dev *gspca_dev)
1001static int cit_set_brightness(struct gspca_dev *gspca_dev) 1213static int cit_set_brightness(struct gspca_dev *gspca_dev)
1002{ 1214{
1003 struct sd *sd = (struct sd *) gspca_dev; 1215 struct sd *sd = (struct sd *) gspca_dev;
1216 int i;
1004 1217
1005 switch (sd->model) { 1218 switch (sd->model) {
1219 case CIT_MODEL1:
1220 /* Model 1: Brightness range 0 - 63 */
1221 cit_Packet_Format1(gspca_dev, 0x0031, sd->brightness);
1222 cit_Packet_Format1(gspca_dev, 0x0032, sd->brightness);
1223 cit_Packet_Format1(gspca_dev, 0x0033, sd->brightness);
1224 break;
1225 case CIT_MODEL2:
1226 /* Model 2: Brightness range 0x60 - 0xee */
1227 /* Scale 0 - 63 to 0x60 - 0xee */
1228 i = 0x60 + sd->brightness * 2254 / 1000;
1229 cit_model2_Packet1(gspca_dev, 0x001a, i);
1230 break;
1006 case CIT_MODEL3: 1231 case CIT_MODEL3:
1007 /* Model 3: Brightness range 'i' in [0x0C..0x3F] */ 1232 /* Model 3: Brightness range 'i' in [0x0C..0x3F] */
1008 cit_model3_Packet1(gspca_dev, 0x0036, sd->brightness); 1233 i = sd->brightness;
1234 if (i < 0x0c)
1235 i = 0x0c;
1236 cit_model3_Packet1(gspca_dev, 0x0036, i);
1237 break;
1238 case CIT_MODEL4:
1239 /* Model 4: Brightness range 'i' in [0x04..0xb4] */
1240 /* Scale 0 - 63 to 0x04 - 0xb4 */
1241 i = 0x04 + sd->brightness * 2794 / 1000;
1242 cit_model4_BrightnessPacket(gspca_dev, i);
1009 break; 1243 break;
1010 case CIT_IBM_NETCAM_PRO: 1244 case CIT_IBM_NETCAM_PRO:
1011 /* No (known) brightness control for ibm netcam pro */ 1245 /* No (known) brightness control for ibm netcam pro */
@@ -1020,6 +1254,20 @@ static int cit_set_contrast(struct gspca_dev *gspca_dev)
1020 struct sd *sd = (struct sd *) gspca_dev; 1254 struct sd *sd = (struct sd *) gspca_dev;
1021 1255
1022 switch (sd->model) { 1256 switch (sd->model) {
1257 case CIT_MODEL1:
1258 {
1259 /* Scale 0 - 20 to 15 - 0 */
1260 int i, new_contrast = (20 - sd->contrast) * 1000 / 1333;
1261 for (i = 0; i < cit_model1_ntries; i++) {
1262 cit_Packet_Format1(gspca_dev, 0x0014, new_contrast);
1263 cit_send_FF_04_02(gspca_dev);
1264 }
1265 break;
1266 }
1267 case CIT_MODEL2:
1268 case CIT_MODEL4:
1269 /* Models 2, 4 do not have this control. */
1270 break;
1023 case CIT_MODEL3: 1271 case CIT_MODEL3:
1024 { /* Preset hardware values */ 1272 { /* Preset hardware values */
1025 static const struct { 1273 static const struct {
@@ -1053,9 +1301,46 @@ static int cit_set_hue(struct gspca_dev *gspca_dev)
1053 struct sd *sd = (struct sd *) gspca_dev; 1301 struct sd *sd = (struct sd *) gspca_dev;
1054 1302
1055 switch (sd->model) { 1303 switch (sd->model) {
1056 case CIT_MODEL3: 1304 case CIT_MODEL1:
1057 /* according to the ibmcam driver this does not work 8/ 1305 /* No hue control for model1 */
1058 /* cit_model3_Packet1(gspca_dev, 0x007e, sd->hue); */ 1306 break;
1307 case CIT_MODEL2:
1308 cit_model2_Packet1(gspca_dev, 0x0024, sd->hue);
1309 /* cit_model2_Packet1(gspca_dev, 0x0020, sat); */
1310 break;
1311 case CIT_MODEL3: {
1312 /* Model 3: Brightness range 'i' in [0x05..0x37] */
1313 /* TESTME according to the ibmcam driver this does not work */
1314 if (0) {
1315 /* Scale 0 - 127 to 0x05 - 0x37 */
1316 int i = 0x05 + sd->hue * 1000 / 2540;
1317 cit_model3_Packet1(gspca_dev, 0x007e, i);
1318 }
1319 break;
1320 }
1321 case CIT_MODEL4:
1322 /* HDG: taken from ibmcam, setting the color gains does not
1323 * really belong here.
1324 *
1325 * I am not sure r/g/b_gain variables exactly control gain
1326 * of those channels. Most likely they subtly change some
1327 * very internal image processing settings in the camera.
1328 * In any case, here is what they do, and feel free to tweak:
1329 *
1330 * r_gain: seriously affects red gain
1331 * g_gain: seriously affects green gain
1332 * b_gain: seriously affects blue gain
1333 * hue: changes average color from violet (0) to red (0xFF)
1334 */
1335 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
1336 cit_write_reg(gspca_dev, 0x001e, 0x012f);
1337 cit_write_reg(gspca_dev, 0xd141, 0x0124);
1338 cit_write_reg(gspca_dev, 160, 0x0127); /* Green gain */
1339 cit_write_reg(gspca_dev, 160, 0x012e); /* Red gain */
1340 cit_write_reg(gspca_dev, 160, 0x0130); /* Blue gain */
1341 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
1342 cit_write_reg(gspca_dev, sd->hue, 0x012d); /* Hue */
1343 cit_write_reg(gspca_dev, 0xf545, 0x0124);
1059 break; 1344 break;
1060 case CIT_IBM_NETCAM_PRO: 1345 case CIT_IBM_NETCAM_PRO:
1061 /* No hue control for ibm netcam pro */ 1346 /* No hue control for ibm netcam pro */
@@ -1069,6 +1354,19 @@ static int cit_set_sharpness(struct gspca_dev *gspca_dev)
1069 struct sd *sd = (struct sd *) gspca_dev; 1354 struct sd *sd = (struct sd *) gspca_dev;
1070 1355
1071 switch (sd->model) { 1356 switch (sd->model) {
1357 case CIT_MODEL1: {
1358 int i;
1359 const unsigned short sa[] = {
1360 0x11, 0x13, 0x16, 0x18, 0x1a, 0x8, 0x0a };
1361
1362 for (i = 0; i < cit_model1_ntries; i++)
1363 cit_PacketFormat2(gspca_dev, 0x0013, sa[sd->sharpness]);
1364 break;
1365 }
1366 case CIT_MODEL2:
1367 case CIT_MODEL4:
1368 /* Models 2, 4 do not have this control */
1369 break;
1072 case CIT_MODEL3: 1370 case CIT_MODEL3:
1073 { /* 1371 { /*
1074 * "Use a table of magic numbers. 1372 * "Use a table of magic numbers.
@@ -1102,17 +1400,62 @@ static int cit_set_sharpness(struct gspca_dev *gspca_dev)
1102 return 0; 1400 return 0;
1103} 1401}
1104 1402
1403/*
1404 * cit_set_lighting()
1405 *
1406 * Camera model 1:
1407 * We have 3 levels of lighting conditions: 0=Bright, 1=Medium, 2=Low.
1408 *
1409 * Camera model 2:
1410 * We have 16 levels of lighting, 0 for bright light and up to 15 for
1411 * low light. But values above 5 or so are useless because camera is
1412 * not really capable to produce anything worth viewing at such light.
1413 * This setting may be altered only in certain camera state.
1414 *
1415 * Low lighting forces slower FPS.
1416 *
1417 * History:
1418 * 1/5/00 Created.
1419 * 2/20/00 Added support for Model 2 cameras.
1420 */
1421static void cit_set_lighting(struct gspca_dev *gspca_dev)
1422{
1423 struct sd *sd = (struct sd *) gspca_dev;
1424
1425 switch (sd->model) {
1426 case CIT_MODEL1: {
1427 int i;
1428 for (i = 0; i < cit_model1_ntries; i++)
1429 cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
1430 break;
1431 }
1432 case CIT_MODEL2:
1433 case CIT_MODEL3:
1434 case CIT_MODEL4:
1435 case CIT_IBM_NETCAM_PRO:
1436 break;
1437 }
1438}
1439
1105static int cit_restart_stream(struct gspca_dev *gspca_dev) 1440static int cit_restart_stream(struct gspca_dev *gspca_dev)
1106{ 1441{
1107 struct sd *sd = (struct sd *) gspca_dev; 1442 struct sd *sd = (struct sd *) gspca_dev;
1108 1443
1109 switch (sd->model) { 1444 switch (sd->model) {
1445 case CIT_MODEL1:
1110 case CIT_MODEL3: 1446 case CIT_MODEL3:
1111 case CIT_IBM_NETCAM_PRO: 1447 case CIT_IBM_NETCAM_PRO:
1112 cit_write_reg(gspca_dev, 0x0001, 0x0114); 1448 cit_write_reg(gspca_dev, 0x0001, 0x0114);
1449 /* Fall through */
1450 case CIT_MODEL2:
1451 case CIT_MODEL4:
1113 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */ 1452 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1114 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe); 1453 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
1115 cit_write_reg(gspca_dev, 0x0001, 0x0113); 1454 /* This happens repeatedly while streaming with the ibm netcam
1455 pro and the ibmcam driver did it for model3 after changing
1456 settings, but it does not seem to have any effect. */
1457 /* cit_write_reg(gspca_dev, 0x0001, 0x0113); */
1458 break;
1116 } 1459 }
1117 1460
1118 sd->sof_read = 0; 1461 sd->sof_read = 0;
@@ -1120,8 +1463,402 @@ static int cit_restart_stream(struct gspca_dev *gspca_dev)
1120 return 0; 1463 return 0;
1121} 1464}
1122 1465
1466static int cit_start_model1(struct gspca_dev *gspca_dev)
1467{
1468 struct sd *sd = (struct sd *) gspca_dev;
1469 int i, clock_div = 0;
1470
1471 cit_read_reg(gspca_dev, 0x0128);
1472 cit_read_reg(gspca_dev, 0x0100);
1473 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1474 cit_read_reg(gspca_dev, 0x0100);
1475 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
1476 cit_read_reg(gspca_dev, 0x0100);
1477 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1478 cit_write_reg(gspca_dev, 0x01, 0x0108);
1479
1480 cit_write_reg(gspca_dev, 0x03, 0x0112);
1481 cit_read_reg(gspca_dev, 0x0115);
1482 cit_write_reg(gspca_dev, 0x06, 0x0115);
1483 cit_read_reg(gspca_dev, 0x0116);
1484 cit_write_reg(gspca_dev, 0x44, 0x0116);
1485 cit_read_reg(gspca_dev, 0x0116);
1486 cit_write_reg(gspca_dev, 0x40, 0x0116);
1487 cit_read_reg(gspca_dev, 0x0115);
1488 cit_write_reg(gspca_dev, 0x0e, 0x0115);
1489 cit_write_reg(gspca_dev, 0x19, 0x012c);
1490
1491 cit_Packet_Format1(gspca_dev, 0x00, 0x1e);
1492 cit_Packet_Format1(gspca_dev, 0x39, 0x0d);
1493 cit_Packet_Format1(gspca_dev, 0x39, 0x09);
1494 cit_Packet_Format1(gspca_dev, 0x3b, 0x00);
1495 cit_Packet_Format1(gspca_dev, 0x28, 0x22);
1496 cit_Packet_Format1(gspca_dev, 0x27, 0x00);
1497 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1498 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1499
1500 for (i = 0; i < cit_model1_ntries; i++)
1501 cit_Packet_Format1(gspca_dev, 0x2c, 0x00);
1502
1503 for (i = 0; i < cit_model1_ntries; i++)
1504 cit_Packet_Format1(gspca_dev, 0x30, 0x14);
1505
1506 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1507 cit_PacketFormat2(gspca_dev, 0x01, 0xe1);
1508 cit_PacketFormat2(gspca_dev, 0x02, 0xcd);
1509 cit_PacketFormat2(gspca_dev, 0x03, 0xcd);
1510 cit_PacketFormat2(gspca_dev, 0x04, 0xfa);
1511 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1512 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1513
1514 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1515 cit_PacketFormat2(gspca_dev, 0x0a, 0x37);
1516 cit_PacketFormat2(gspca_dev, 0x0b, 0xb8);
1517 cit_PacketFormat2(gspca_dev, 0x0c, 0xf3);
1518 cit_PacketFormat2(gspca_dev, 0x0d, 0xe3);
1519 cit_PacketFormat2(gspca_dev, 0x0e, 0x0d);
1520 cit_PacketFormat2(gspca_dev, 0x0f, 0xf2);
1521 cit_PacketFormat2(gspca_dev, 0x10, 0xd5);
1522 cit_PacketFormat2(gspca_dev, 0x11, 0xba);
1523 cit_PacketFormat2(gspca_dev, 0x12, 0x53);
1524 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1525 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1526
1527 cit_PacketFormat2(gspca_dev, 0x39, 0x02);
1528 cit_PacketFormat2(gspca_dev, 0x16, 0x00);
1529 cit_PacketFormat2(gspca_dev, 0x17, 0x28);
1530 cit_PacketFormat2(gspca_dev, 0x18, 0x7d);
1531 cit_PacketFormat2(gspca_dev, 0x19, 0xbe);
1532 cit_PacketFormat2(gspca_dev, 0x3f, 0xff);
1533 cit_PacketFormat2(gspca_dev, 0x39, 0x00);
1534
1535 for (i = 0; i < cit_model1_ntries; i++)
1536 cit_Packet_Format1(gspca_dev, 0x00, 0x18);
1537 for (i = 0; i < cit_model1_ntries; i++)
1538 cit_Packet_Format1(gspca_dev, 0x13, 0x18);
1539 for (i = 0; i < cit_model1_ntries; i++)
1540 cit_Packet_Format1(gspca_dev, 0x14, 0x06);
1541
1542 /* TESTME These are handled through controls
1543 KEEP until someone can test leaving this out is ok */
1544 if (0) {
1545 /* This is default brightness */
1546 for (i = 0; i < cit_model1_ntries; i++)
1547 cit_Packet_Format1(gspca_dev, 0x31, 0x37);
1548 for (i = 0; i < cit_model1_ntries; i++)
1549 cit_Packet_Format1(gspca_dev, 0x32, 0x46);
1550 for (i = 0; i < cit_model1_ntries; i++)
1551 cit_Packet_Format1(gspca_dev, 0x33, 0x55);
1552 }
1553
1554 cit_Packet_Format1(gspca_dev, 0x2e, 0x04);
1555 for (i = 0; i < cit_model1_ntries; i++)
1556 cit_Packet_Format1(gspca_dev, 0x2d, 0x04);
1557 for (i = 0; i < cit_model1_ntries; i++)
1558 cit_Packet_Format1(gspca_dev, 0x29, 0x80);
1559 cit_Packet_Format1(gspca_dev, 0x2c, 0x01);
1560 cit_Packet_Format1(gspca_dev, 0x30, 0x17);
1561 cit_Packet_Format1(gspca_dev, 0x39, 0x08);
1562 for (i = 0; i < cit_model1_ntries; i++)
1563 cit_Packet_Format1(gspca_dev, 0x34, 0x00);
1564
1565 cit_write_reg(gspca_dev, 0x00, 0x0101);
1566 cit_write_reg(gspca_dev, 0x00, 0x010a);
1567
1568 switch (gspca_dev->width) {
1569 case 128: /* 128x96 */
1570 cit_write_reg(gspca_dev, 0x80, 0x0103);
1571 cit_write_reg(gspca_dev, 0x60, 0x0105);
1572 cit_write_reg(gspca_dev, 0x0c, 0x010b);
1573 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1574 cit_write_reg(gspca_dev, 0x0b, 0x011d);
1575 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1576 cit_write_reg(gspca_dev, 0x00, 0x0129);
1577 clock_div = 3;
1578 break;
1579 case 176: /* 176x144 */
1580 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1581 cit_write_reg(gspca_dev, 0x8f, 0x0105);
1582 cit_write_reg(gspca_dev, 0x06, 0x010b);
1583 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1584 cit_write_reg(gspca_dev, 0x0d, 0x011d);
1585 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1586 cit_write_reg(gspca_dev, 0x03, 0x0129);
1587 clock_div = 3;
1588 break;
1589 case 352: /* 352x288 */
1590 cit_write_reg(gspca_dev, 0xb0, 0x0103);
1591 cit_write_reg(gspca_dev, 0x90, 0x0105);
1592 cit_write_reg(gspca_dev, 0x02, 0x010b);
1593 cit_write_reg(gspca_dev, 0x04, 0x011b); /* Same everywhere */
1594 cit_write_reg(gspca_dev, 0x05, 0x011d);
1595 cit_write_reg(gspca_dev, 0x00, 0x011e); /* Same everywhere */
1596 cit_write_reg(gspca_dev, 0x00, 0x0129);
1597 clock_div = 5;
1598 break;
1599 }
1600
1601 cit_write_reg(gspca_dev, 0xff, 0x012b);
1602
1603 /* TESTME These are handled through controls
1604 KEEP until someone can test leaving this out is ok */
1605 if (0) {
1606 /* This is another brightness - don't know why */
1607 for (i = 0; i < cit_model1_ntries; i++)
1608 cit_Packet_Format1(gspca_dev, 0x31, 0xc3);
1609 for (i = 0; i < cit_model1_ntries; i++)
1610 cit_Packet_Format1(gspca_dev, 0x32, 0xd2);
1611 for (i = 0; i < cit_model1_ntries; i++)
1612 cit_Packet_Format1(gspca_dev, 0x33, 0xe1);
1613
1614 /* Default contrast */
1615 for (i = 0; i < cit_model1_ntries; i++)
1616 cit_Packet_Format1(gspca_dev, 0x14, 0x0a);
1617
1618 /* Default sharpness */
1619 for (i = 0; i < cit_model1_ntries2; i++)
1620 cit_PacketFormat2(gspca_dev, 0x13, 0x1a);
1621
1622 /* Default lighting conditions */
1623 cit_Packet_Format1(gspca_dev, 0x0027, sd->lighting);
1624 }
1625
1626 /* Assorted init */
1627 switch (gspca_dev->width) {
1628 case 128: /* 128x96 */
1629 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1630 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1631 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1632 cit_write_reg(gspca_dev, 0x36, 0x0102);
1633 cit_write_reg(gspca_dev, 0x1a, 0x0104);
1634 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1635 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1636 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1637 break;
1638 case 176: /* 176x144 */
1639 cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
1640 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1641 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1642 cit_write_reg(gspca_dev, 0x04, 0x0102);
1643 cit_write_reg(gspca_dev, 0x02, 0x0104);
1644 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1645 cit_write_reg(gspca_dev, 0x2b, 0x011c);
1646 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1647 break;
1648 case 352: /* 352x288 */
1649 cit_Packet_Format1(gspca_dev, 0x2b, 0x1f);
1650 cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
1651 cit_write_reg(gspca_dev, 0x80, 0x0109); /* Same everywhere */
1652 cit_write_reg(gspca_dev, 0x08, 0x0102);
1653 cit_write_reg(gspca_dev, 0x01, 0x0104);
1654 cit_write_reg(gspca_dev, 0x04, 0x011a); /* Same everywhere */
1655 cit_write_reg(gspca_dev, 0x2f, 0x011c);
1656 cit_write_reg(gspca_dev, 0x23, 0x012a); /* Same everywhere */
1657 break;
1658 }
1659
1660 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1661 cit_write_reg(gspca_dev, clock_div, 0x0111);
1662
1663 sd->sof_len = 4;
1664
1665 return 0;
1666}
1667
1668static int cit_start_model2(struct gspca_dev *gspca_dev)
1669{
1670 struct sd *sd = (struct sd *) gspca_dev;
1671 int clock_div = 0;
1672
1673 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1674 cit_read_reg(gspca_dev, 0x0116);
1675 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1676 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1677 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
1678 cit_write_reg(gspca_dev, 0x0008, 0x012b);
1679 cit_write_reg(gspca_dev, 0x0000, 0x0108);
1680 cit_write_reg(gspca_dev, 0x0001, 0x0133);
1681 cit_write_reg(gspca_dev, 0x0001, 0x0102);
1682 switch (gspca_dev->width) {
1683 case 176: /* 176x144 */
1684 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1685 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1686 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1687 cit_write_reg(gspca_dev, 0x00b9, 0x010a); /* Unique to this mode */
1688 cit_write_reg(gspca_dev, 0x0038, 0x0119); /* Unique to this mode */
1689 /* TESTME HDG: this does not seem right
1690 (it is 2 for all other resolutions) */
1691 sd->sof_len = 10;
1692 break;
1693 case 320: /* 320x240 */
1694 cit_write_reg(gspca_dev, 0x0028, 0x0103); /* Unique to this mode */
1695 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1696 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1697 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1698 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1699 sd->sof_len = 2;
1700 break;
1701 /* case VIDEOSIZE_352x240: */
1702 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1703 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1704 cit_write_reg(gspca_dev, 0x001e, 0x0105); /* 320x240, 352x240 */
1705 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1706 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1707 sd->sof_len = 2;
1708 break;
1709 case 352: /* 352x288 */
1710 cit_write_reg(gspca_dev, 0x002c, 0x0103); /* All except 320x240 */
1711 cit_write_reg(gspca_dev, 0x0000, 0x0104); /* Same */
1712 cit_write_reg(gspca_dev, 0x0024, 0x0105); /* 176x144, 352x288 */
1713 cit_write_reg(gspca_dev, 0x0039, 0x010a); /* All except 176x144 */
1714 cit_write_reg(gspca_dev, 0x0070, 0x0119); /* All except 176x144 */
1715 sd->sof_len = 2;
1716 break;
1717 }
1718
1719 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1720
1721 switch (gspca_dev->width) {
1722 case 176: /* 176x144 */
1723 cit_write_reg(gspca_dev, 0x0050, 0x0111);
1724 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
1725 break;
1726 case 320: /* 320x240 */
1727 case 352: /* 352x288 */
1728 cit_write_reg(gspca_dev, 0x0040, 0x0111);
1729 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
1730 break;
1731 }
1732 cit_write_reg(gspca_dev, 0x009b, 0x010f);
1733 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
1734
1735 /*
1736 * Hardware settings, may affect CMOS sensor; not user controls!
1737 * -------------------------------------------------------------
1738 * 0x0004: no effect
1739 * 0x0006: hardware effect
1740 * 0x0008: no effect
1741 * 0x000a: stops video stream, probably important h/w setting
1742 * 0x000c: changes color in hardware manner (not user setting)
1743 * 0x0012: changes number of colors (does not affect speed)
1744 * 0x002a: no effect
1745 * 0x002c: hardware setting (related to scan lines)
1746 * 0x002e: stops video stream, probably important h/w setting
1747 */
1748 cit_model2_Packet1(gspca_dev, 0x000a, 0x005c);
1749 cit_model2_Packet1(gspca_dev, 0x0004, 0x0000);
1750 cit_model2_Packet1(gspca_dev, 0x0006, 0x00fb);
1751 cit_model2_Packet1(gspca_dev, 0x0008, 0x0000);
1752 cit_model2_Packet1(gspca_dev, 0x000c, 0x0009);
1753 cit_model2_Packet1(gspca_dev, 0x0012, 0x000a);
1754 cit_model2_Packet1(gspca_dev, 0x002a, 0x0000);
1755 cit_model2_Packet1(gspca_dev, 0x002c, 0x0000);
1756 cit_model2_Packet1(gspca_dev, 0x002e, 0x0008);
1757
1758 /*
1759 * Function 0x0030 pops up all over the place. Apparently
1760 * it is a hardware control register, with every bit assigned to
1761 * do something.
1762 */
1763 cit_model2_Packet1(gspca_dev, 0x0030, 0x0000);
1764
1765 /*
1766 * Magic control of CMOS sensor. Only lower values like
1767 * 0-3 work, and picture shifts left or right. Don't change.
1768 */
1769 switch (gspca_dev->width) {
1770 case 176: /* 176x144 */
1771 cit_model2_Packet1(gspca_dev, 0x0014, 0x0002);
1772 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1773 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
1774 clock_div = 6;
1775 break;
1776 case 320: /* 320x240 */
1777 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009);
1778 cit_model2_Packet1(gspca_dev, 0x0016, 0x0005); /* Horizontal shift */
1779 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Another hardware setting */
1780 clock_div = 8;
1781 break;
1782 /* case VIDEOSIZE_352x240: */
1783 /* This mode doesn't work as Windows programs it; changed to work */
1784 cit_model2_Packet1(gspca_dev, 0x0014, 0x0009); /* Windows sets this to 8 */
1785 cit_model2_Packet1(gspca_dev, 0x0016, 0x0003); /* Horizontal shift */
1786 cit_model2_Packet1(gspca_dev, 0x0018, 0x0044); /* Windows sets this to 0x0045 */
1787 clock_div = 10;
1788 break;
1789 case 352: /* 352x288 */
1790 cit_model2_Packet1(gspca_dev, 0x0014, 0x0003);
1791 cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
1792 cit_model2_Packet1(gspca_dev, 0x0018, 0x004a); /* Another hardware setting */
1793 clock_div = 16;
1794 break;
1795 }
1796
1797 /* TESTME These are handled through controls
1798 KEEP until someone can test leaving this out is ok */
1799 if (0)
1800 cit_model2_Packet1(gspca_dev, 0x001a, 0x005a);
1801
1802 /*
1803 * We have our own frame rate setting varying from 0 (slowest) to 6
1804 * (fastest). The camera model 2 allows frame rate in range [0..0x1F]
1805 # where 0 is also the slowest setting. However for all practical
1806 # reasons high settings make no sense because USB is not fast enough
1807 # to support high FPS. Be aware that the picture datastream will be
1808 # severely disrupted if you ask for frame rate faster than allowed
1809 # for the video size - see below:
1810 *
1811 * Allowable ranges (obtained experimentally on OHCI, K6-3, 450 MHz):
1812 * -----------------------------------------------------------------
1813 * 176x144: [6..31]
1814 * 320x240: [8..31]
1815 * 352x240: [10..31]
1816 * 352x288: [16..31] I have to raise lower threshold for stability...
1817 *
1818 * As usual, slower FPS provides better sensitivity.
1819 */
1820 cit_model2_Packet1(gspca_dev, 0x001c, clock_div);
1821
1822 /*
1823 * This setting does not visibly affect pictures; left it here
1824 * because it was present in Windows USB data stream. This function
1825 * does not allow arbitrary values and apparently is a bit mask, to
1826 * be activated only at appropriate time. Don't change it randomly!
1827 */
1828 switch (gspca_dev->width) {
1829 case 176: /* 176x144 */
1830 cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2);
1831 break;
1832 case 320: /* 320x240 */
1833 cit_model2_Packet1(gspca_dev, 0x0026, 0x0044);
1834 break;
1835 /* case VIDEOSIZE_352x240: */
1836 cit_model2_Packet1(gspca_dev, 0x0026, 0x0046);
1837 break;
1838 case 352: /* 352x288 */
1839 cit_model2_Packet1(gspca_dev, 0x0026, 0x0048);
1840 break;
1841 }
1842
1843 /* FIXME this cannot be changed while streaming, so we
1844 should report a grabbed flag for this control. */
1845 cit_model2_Packet1(gspca_dev, 0x0028, sd->lighting);
1846 /* color balance rg2 */
1847 cit_model2_Packet1(gspca_dev, 0x001e, 0x002f);
1848 /* saturation */
1849 cit_model2_Packet1(gspca_dev, 0x0020, 0x0034);
1850 /* color balance yb */
1851 cit_model2_Packet1(gspca_dev, 0x0022, 0x00a0);
1852
1853 /* Hardware control command */
1854 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
1855
1856 return 0;
1857}
1858
1123static int cit_start_model3(struct gspca_dev *gspca_dev) 1859static int cit_start_model3(struct gspca_dev *gspca_dev)
1124{ 1860{
1861 struct sd *sd = (struct sd *) gspca_dev;
1125 const unsigned short compression = 0; /* 0=none, 7=best frame rate */ 1862 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
1126 int i, clock_div = 0; 1863 int i, clock_div = 0;
1127 1864
@@ -1143,7 +1880,7 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
1143 cit_read_reg(gspca_dev, 0x0115); 1880 cit_read_reg(gspca_dev, 0x0115);
1144 cit_write_reg(gspca_dev, 0x000b, 0x0115); 1881 cit_write_reg(gspca_dev, 0x000b, 0x0115);
1145 1882
1146 /* HDG not in ibmcam driver, added to see if it helps with 1883 /* TESTME HDG not in ibmcam driver, added to see if it helps with
1147 auto-detecting between model3 and ibm netcamera pro */ 1884 auto-detecting between model3 and ibm netcamera pro */
1148 if (0) { 1885 if (0) {
1149 cit_write_reg(gspca_dev, 0x0078, 0x012d); 1886 cit_write_reg(gspca_dev, 0x0078, 0x012d);
@@ -1354,11 +2091,339 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
1354 } 2091 }
1355 } 2092 }
1356 2093
2094 sd->sof_len = 4;
2095
2096 return 0;
2097}
2098
2099static int cit_start_model4(struct gspca_dev *gspca_dev)
2100{
2101 struct sd *sd = (struct sd *) gspca_dev;
2102
2103 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2104 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2105 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
2106 cit_write_reg(gspca_dev, 0x0080, 0x012b);
2107 cit_write_reg(gspca_dev, 0x0000, 0x0108);
2108 cit_write_reg(gspca_dev, 0x0001, 0x0133);
2109 cit_write_reg(gspca_dev, 0x009b, 0x010f);
2110 cit_write_reg(gspca_dev, 0x00bb, 0x010f);
2111 cit_model4_Packet1(gspca_dev, 0x0038, 0x0000);
2112 cit_model4_Packet1(gspca_dev, 0x000a, 0x005c);
2113
2114 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2115 cit_write_reg(gspca_dev, 0x0004, 0x012f);
2116 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2117 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2118 cit_write_reg(gspca_dev, 0x00fb, 0x012e);
2119 cit_write_reg(gspca_dev, 0x0000, 0x0130);
2120 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2121 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2122 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2123 cit_write_reg(gspca_dev, 0x000c, 0x0127);
2124 cit_write_reg(gspca_dev, 0x0009, 0x012e);
2125 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2126
2127 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2128 cit_write_reg(gspca_dev, 0x0012, 0x012f);
2129 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2130 cit_write_reg(gspca_dev, 0x0008, 0x0127);
2131 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2132 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2133 cit_write_reg(gspca_dev, 0x002a, 0x012d);
2134 cit_write_reg(gspca_dev, 0x0000, 0x012f);
2135 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2136 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2137 cit_model4_Packet1(gspca_dev, 0x0034, 0x0000);
2138
2139 switch (gspca_dev->width) {
2140 case 128: /* 128x96 */
2141 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2142 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2143 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2144 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2145 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2146 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2147 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2148 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2149 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2150 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2151 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2152 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2153 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2154 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2155 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2156 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2157 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2158 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2159 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2160 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2161 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2162 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2163 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2164 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2165 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2166 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2167 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2168 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2169 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2170 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2171 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2172 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2173 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2174 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2175 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2176 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2177 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2178 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2179 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2180 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2181 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2182 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2183 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2184 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2185 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2186 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2187 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2188 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2189 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2190 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2191 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2192 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2193 sd->sof_len = 2;
2194 break;
2195 case 160: /* 160x120 */
2196 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2197 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2198 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2199 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2200 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2201 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2202 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2203 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2204 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2205 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2206 cit_write_reg(gspca_dev, 0x000b, 0x0127);
2207 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2208 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2209 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2210 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2211 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2212 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2213 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2214 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2215 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2216 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2217 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2218 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2219 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2220 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2221 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2222 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2223 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2224 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2225 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2226 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2227 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2228 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2229 cit_write_reg(gspca_dev, 0x0025, 0x0127);
2230 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2231 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2232 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2233 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2234 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2235 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2236 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2237 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2238 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2239 cit_write_reg(gspca_dev, 0x0048, 0x0127);
2240 cit_write_reg(gspca_dev, 0x0035, 0x012e);
2241 cit_write_reg(gspca_dev, 0x00d0, 0x0130);
2242 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2243 cit_write_reg(gspca_dev, 0x0048, 0x012d);
2244 cit_write_reg(gspca_dev, 0x0090, 0x012f);
2245 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2246 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2247 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2248 sd->sof_len = 2;
2249 break;
2250 case 176: /* 176x144 */
2251 cit_write_reg(gspca_dev, 0x0038, 0x0119);
2252 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2253 cit_write_reg(gspca_dev, 0x00b9, 0x010a);
2254 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2255 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2256 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2257 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2258 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2259 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2260 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2261 cit_write_reg(gspca_dev, 0x0007, 0x0127);
2262 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2263 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2264 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2265 cit_write_reg(gspca_dev, 0x0001, 0x012f);
2266 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2267 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2268 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2269 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2270 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2271 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2272 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2273 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2274 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2275 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2276 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2277 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2278 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2279 cit_write_reg(gspca_dev, 0x00c7, 0x012e);
2280 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2281 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2282 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2283 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2284 cit_write_reg(gspca_dev, 0x0028, 0x0127);
2285 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2286 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2287 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2288 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2289 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2290 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2291 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2292 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2293 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2294 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2295 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2296 cit_write_reg(gspca_dev, 0x002a, 0x0130);
2297 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2298 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2299 cit_write_reg(gspca_dev, 0x006d, 0x012f);
2300 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2301 cit_write_reg(gspca_dev, 0x0001, 0x0127);
2302 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2303 /* TESTME HDG: this does not seem right
2304 (it is 2 for all other resolutions) */
2305 sd->sof_len = 10;
2306 break;
2307 case 320: /* 320x240 */
2308 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2309 cit_write_reg(gspca_dev, 0x00d0, 0x0111);
2310 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2311 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2312 cit_write_reg(gspca_dev, 0x0028, 0x0103);
2313 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2314 cit_write_reg(gspca_dev, 0x001e, 0x0105);
2315 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2316 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2317 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2318 cit_write_reg(gspca_dev, 0x000a, 0x0127);
2319 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2320 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2321 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2322 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2323 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2324 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2325 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2326 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2327 cit_write_reg(gspca_dev, 0x005a, 0x012d);
2328 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2329 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2330 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2331 cit_write_reg(gspca_dev, 0x0043, 0x0130);
2332 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2333 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2334 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2335 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2336 cit_write_reg(gspca_dev, 0x00eb, 0x012e);
2337 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2338 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2339 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2340 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2341 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2342 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2343 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2344 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2345 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2346 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2347 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2348 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2349 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2350 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2351 cit_write_reg(gspca_dev, 0x0017, 0x0127);
2352 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2353 cit_write_reg(gspca_dev, 0x0031, 0x0130);
2354 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2355 cit_write_reg(gspca_dev, 0x0017, 0x012d);
2356 cit_write_reg(gspca_dev, 0x0078, 0x012f);
2357 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2358 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2359 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2360 sd->sof_len = 2;
2361 break;
2362 case 352: /* 352x288 */
2363 cit_write_reg(gspca_dev, 0x0070, 0x0119);
2364 cit_write_reg(gspca_dev, 0x00c0, 0x0111);
2365 cit_write_reg(gspca_dev, 0x0039, 0x010a);
2366 cit_write_reg(gspca_dev, 0x0001, 0x0102);
2367 cit_write_reg(gspca_dev, 0x002c, 0x0103);
2368 cit_write_reg(gspca_dev, 0x0000, 0x0104);
2369 cit_write_reg(gspca_dev, 0x0024, 0x0105);
2370 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2371 cit_write_reg(gspca_dev, 0x0016, 0x012f);
2372 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2373 cit_write_reg(gspca_dev, 0x0006, 0x0127);
2374 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2375 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2376 cit_write_reg(gspca_dev, 0x0014, 0x012d);
2377 cit_write_reg(gspca_dev, 0x0002, 0x012f);
2378 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2379 cit_write_reg(gspca_dev, 0x00aa, 0x012e);
2380 cit_write_reg(gspca_dev, 0x001a, 0x0130);
2381 cit_write_reg(gspca_dev, 0x8a0a, 0x0124);
2382 cit_write_reg(gspca_dev, 0x005e, 0x012d);
2383 cit_write_reg(gspca_dev, 0x9545, 0x0124);
2384 cit_write_reg(gspca_dev, 0x00aa, 0x0127);
2385 cit_write_reg(gspca_dev, 0x0018, 0x012e);
2386 cit_write_reg(gspca_dev, 0x0049, 0x0130);
2387 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2388 cit_write_reg(gspca_dev, 0x00aa, 0x012f);
2389 cit_write_reg(gspca_dev, 0xd055, 0x0124);
2390 cit_write_reg(gspca_dev, 0x001c, 0x0127);
2391 cit_write_reg(gspca_dev, 0x00cf, 0x012e);
2392 cit_write_reg(gspca_dev, 0xaa28, 0x0124);
2393 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2394 cit_write_reg(gspca_dev, 0x0032, 0x012f);
2395 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2396 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2397 cit_write_reg(gspca_dev, 0x00aa, 0x0130);
2398 cit_write_reg(gspca_dev, 0x82a8, 0x0124);
2399 cit_write_reg(gspca_dev, 0x0036, 0x012d);
2400 cit_write_reg(gspca_dev, 0x0008, 0x012f);
2401 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2402 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2403 cit_write_reg(gspca_dev, 0x00aa, 0x012d);
2404 cit_write_reg(gspca_dev, 0x001e, 0x012f);
2405 cit_write_reg(gspca_dev, 0xd141, 0x0124);
2406 cit_write_reg(gspca_dev, 0x0010, 0x0127);
2407 cit_write_reg(gspca_dev, 0x0013, 0x012e);
2408 cit_write_reg(gspca_dev, 0x0025, 0x0130);
2409 cit_write_reg(gspca_dev, 0x8a28, 0x0124);
2410 cit_write_reg(gspca_dev, 0x0010, 0x012d);
2411 cit_write_reg(gspca_dev, 0x0048, 0x012f);
2412 cit_write_reg(gspca_dev, 0xd145, 0x0124);
2413 cit_write_reg(gspca_dev, 0x0000, 0x0127);
2414 cit_write_reg(gspca_dev, 0xfea8, 0x0124);
2415 sd->sof_len = 2;
2416 break;
2417 }
2418
2419 cit_model4_Packet1(gspca_dev, 0x0038, 0x0004);
2420
1357 return 0; 2421 return 0;
1358} 2422}
1359 2423
1360static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev) 2424static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
1361{ 2425{
2426 struct sd *sd = (struct sd *) gspca_dev;
1362 const unsigned short compression = 0; /* 0=none, 7=best frame rate */ 2427 const unsigned short compression = 0; /* 0=none, 7=best frame rate */
1363 int i, clock_div = 0; 2428 int i, clock_div = 0;
1364 2429
@@ -1446,6 +2511,8 @@ static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
1446 } 2511 }
1447 } 2512 }
1448 2513
2514 sd->sof_len = 4;
2515
1449 return 0; 2516 return 0;
1450} 2517}
1451 2518
@@ -1458,9 +2525,18 @@ static int sd_start(struct gspca_dev *gspca_dev)
1458 int packet_size; 2525 int packet_size;
1459 2526
1460 switch (sd->model) { 2527 switch (sd->model) {
2528 case CIT_MODEL1:
2529 cit_start_model1(gspca_dev);
2530 break;
2531 case CIT_MODEL2:
2532 cit_start_model2(gspca_dev);
2533 break;
1461 case CIT_MODEL3: 2534 case CIT_MODEL3:
1462 cit_start_model3(gspca_dev); 2535 cit_start_model3(gspca_dev);
1463 break; 2536 break;
2537 case CIT_MODEL4:
2538 cit_start_model4(gspca_dev);
2539 break;
1464 case CIT_IBM_NETCAM_PRO: 2540 case CIT_IBM_NETCAM_PRO:
1465 cit_start_ibm_netcam_pro(gspca_dev); 2541 cit_start_ibm_netcam_pro(gspca_dev);
1466 break; 2542 break;
@@ -1470,6 +2546,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1470 cit_set_contrast(gspca_dev); 2546 cit_set_contrast(gspca_dev);
1471 cit_set_hue(gspca_dev); 2547 cit_set_hue(gspca_dev);
1472 cit_set_sharpness(gspca_dev); 2548 cit_set_sharpness(gspca_dev);
2549 cit_set_lighting(gspca_dev);
1473 2550
1474 /* Program max isoc packet size, one day we should use this to 2551 /* Program max isoc packet size, one day we should use this to
1475 allow us to work together with other isoc devices on the same 2552 allow us to work together with other isoc devices on the same
@@ -1492,14 +2569,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1492 2569
1493static void sd_stopN(struct gspca_dev *gspca_dev) 2570static void sd_stopN(struct gspca_dev *gspca_dev)
1494{ 2571{
1495 struct sd *sd = (struct sd *) gspca_dev; 2572 cit_write_reg(gspca_dev, 0x0000, 0x010c);
1496
1497 switch (sd->model) {
1498 case CIT_MODEL3:
1499 case CIT_IBM_NETCAM_PRO:
1500 cit_write_reg(gspca_dev, 0x0000, 0x010c);
1501 break;
1502 }
1503} 2573}
1504 2574
1505static void sd_stop0(struct gspca_dev *gspca_dev) 2575static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -1512,6 +2582,24 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
1512 return; 2582 return;
1513 2583
1514 switch (sd->model) { 2584 switch (sd->model) {
2585 case CIT_MODEL1:
2586 cit_send_FF_04_02(gspca_dev);
2587 cit_read_reg(gspca_dev, 0x0100);
2588 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
2589 break;
2590 case CIT_MODEL2:
2591 case CIT_MODEL4:
2592 cit_model2_Packet1(gspca_dev, 0x0030, 0x0004);
2593
2594 cit_write_reg(gspca_dev, 0x0080, 0x0100); /* LED Off */
2595 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2596 cit_write_reg(gspca_dev, 0x00a0, 0x0111);
2597
2598 cit_model2_Packet1(gspca_dev, 0x0030, 0x0002);
2599
2600 cit_write_reg(gspca_dev, 0x0020, 0x0111);
2601 cit_write_reg(gspca_dev, 0x0000, 0x0112);
2602 break;
1515 case CIT_MODEL3: 2603 case CIT_MODEL3:
1516 cit_write_reg(gspca_dev, 0x0006, 0x012c); 2604 cit_write_reg(gspca_dev, 0x0006, 0x012c);
1517 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000); 2605 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
@@ -1547,11 +2635,20 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
1547static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len) 2635static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
1548{ 2636{
1549 struct sd *sd = (struct sd *) gspca_dev; 2637 struct sd *sd = (struct sd *) gspca_dev;
2638 u8 byte3;
1550 int i; 2639 int i;
1551 2640
1552 switch (sd->model) { 2641 switch (sd->model) {
2642 case CIT_MODEL1:
1553 case CIT_MODEL3: 2643 case CIT_MODEL3:
1554 case CIT_IBM_NETCAM_PRO: 2644 case CIT_IBM_NETCAM_PRO:
2645 if (sd->model == CIT_MODEL1)
2646 byte3 = 0x00;
2647 else if (gspca_dev->width == 640)
2648 byte3 = 0x03;
2649 else
2650 byte3 = 0x02;
2651
1555 for (i = 0; i < len; i++) { 2652 for (i = 0; i < len; i++) {
1556 switch (sd->sof_read) { 2653 switch (sd->sof_read) {
1557 case 0: 2654 case 0:
@@ -1566,7 +2663,34 @@ static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
1566 break; 2663 break;
1567 case 2: 2664 case 2:
1568 sd->sof_read = 0; 2665 sd->sof_read = 0;
1569 if (data[i] != 0xff) { 2666 if (data[i] == byte3) {
2667 if (i >= 4)
2668 PDEBUG(D_FRAM,
2669 "header found at offset: %d: %02x %02x 00 ff %02x %02x\n",
2670 i - 2,
2671 data[i - 4],
2672 data[i - 3],
2673 data[i],
2674 data[i + 1]);
2675 return data + i + (sd->sof_len - 2);
2676 }
2677 break;
2678 }
2679 }
2680 break;
2681 case CIT_MODEL2:
2682 case CIT_MODEL4:
2683 /* TESTME we need to find a longer sof signature to avoid
2684 false positives */
2685 for (i = 0; i < len; i++) {
2686 switch (sd->sof_read) {
2687 case 0:
2688 if (data[i] == 0x00)
2689 sd->sof_read++;
2690 break;
2691 case 1:
2692 sd->sof_read = 0;
2693 if (data[i] == 0xff) {
1570 if (i >= 4) 2694 if (i >= 4)
1571 PDEBUG(D_FRAM, 2695 PDEBUG(D_FRAM,
1572 "header found at offset: %d: %02x %02x 00 ff %02x %02x\n", 2696 "header found at offset: %d: %02x %02x 00 ff %02x %02x\n",
@@ -1575,7 +2699,7 @@ static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
1575 data[i - 3], 2699 data[i - 3],
1576 data[i], 2700 data[i],
1577 data[i + 1]); 2701 data[i + 1]);
1578 return data + i + 2; 2702 return data + i + (sd->sof_len - 2);
1579 } 2703 }
1580 break; 2704 break;
1581 } 2705 }
@@ -1588,6 +2712,7 @@ static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
1588static void sd_pkt_scan(struct gspca_dev *gspca_dev, 2712static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1589 u8 *data, int len) 2713 u8 *data, int len)
1590{ 2714{
2715 struct sd *sd = (struct sd *) gspca_dev;
1591 unsigned char *sof; 2716 unsigned char *sof;
1592 2717
1593 sof = cit_find_sof(gspca_dev, data, len); 2718 sof = cit_find_sof(gspca_dev, data, len);
@@ -1596,8 +2721,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1596 2721
1597 /* finish decoding current frame */ 2722 /* finish decoding current frame */
1598 n = sof - data; 2723 n = sof - data;
1599 if (n > 4) 2724 if (n > sd->sof_len)
1600 n -= 4; 2725 n -= sd->sof_len;
1601 else 2726 else
1602 n = 0; 2727 n = 0;
1603 gspca_frame_add(gspca_dev, LAST_PACKET, 2728 gspca_frame_add(gspca_dev, LAST_PACKET,
@@ -1616,9 +2741,11 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1616 2741
1617 sd->brightness = val; 2742 sd->brightness = val;
1618 if (gspca_dev->streaming) { 2743 if (gspca_dev->streaming) {
1619 sd_stopN(gspca_dev); 2744 if (sd->stop_on_control_change)
2745 sd_stopN(gspca_dev);
1620 cit_set_brightness(gspca_dev); 2746 cit_set_brightness(gspca_dev);
1621 cit_restart_stream(gspca_dev); 2747 if (sd->stop_on_control_change)
2748 cit_restart_stream(gspca_dev);
1622 } 2749 }
1623 2750
1624 return 0; 2751 return 0;
@@ -1639,9 +2766,11 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1639 2766
1640 sd->contrast = val; 2767 sd->contrast = val;
1641 if (gspca_dev->streaming) { 2768 if (gspca_dev->streaming) {
1642 sd_stopN(gspca_dev); 2769 if (sd->stop_on_control_change)
2770 sd_stopN(gspca_dev);
1643 cit_set_contrast(gspca_dev); 2771 cit_set_contrast(gspca_dev);
1644 cit_restart_stream(gspca_dev); 2772 if (sd->stop_on_control_change)
2773 cit_restart_stream(gspca_dev);
1645 } 2774 }
1646 2775
1647 return 0; 2776 return 0;
@@ -1662,9 +2791,11 @@ static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
1662 2791
1663 sd->hue = val; 2792 sd->hue = val;
1664 if (gspca_dev->streaming) { 2793 if (gspca_dev->streaming) {
1665 sd_stopN(gspca_dev); 2794 if (sd->stop_on_control_change)
2795 sd_stopN(gspca_dev);
1666 cit_set_hue(gspca_dev); 2796 cit_set_hue(gspca_dev);
1667 cit_restart_stream(gspca_dev); 2797 if (sd->stop_on_control_change)
2798 cit_restart_stream(gspca_dev);
1668 } 2799 }
1669 return 0; 2800 return 0;
1670} 2801}
@@ -1684,9 +2815,11 @@ static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
1684 2815
1685 sd->sharpness = val; 2816 sd->sharpness = val;
1686 if (gspca_dev->streaming) { 2817 if (gspca_dev->streaming) {
1687 sd_stopN(gspca_dev); 2818 if (sd->stop_on_control_change)
2819 sd_stopN(gspca_dev);
1688 cit_set_sharpness(gspca_dev); 2820 cit_set_sharpness(gspca_dev);
1689 cit_restart_stream(gspca_dev); 2821 if (sd->stop_on_control_change)
2822 cit_restart_stream(gspca_dev);
1690 } 2823 }
1691 return 0; 2824 return 0;
1692} 2825}
@@ -1700,6 +2833,30 @@ static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
1700 return 0; 2833 return 0;
1701} 2834}
1702 2835
2836static int sd_setlighting(struct gspca_dev *gspca_dev, __s32 val)
2837{
2838 struct sd *sd = (struct sd *) gspca_dev;
2839
2840 sd->lighting = val;
2841 if (gspca_dev->streaming) {
2842 if (sd->stop_on_control_change)
2843 sd_stopN(gspca_dev);
2844 cit_set_lighting(gspca_dev);
2845 if (sd->stop_on_control_change)
2846 cit_restart_stream(gspca_dev);
2847 }
2848 return 0;
2849}
2850
2851static int sd_getlighting(struct gspca_dev *gspca_dev, __s32 *val)
2852{
2853 struct sd *sd = (struct sd *) gspca_dev;
2854
2855 *val = sd->lighting;
2856
2857 return 0;
2858}
2859
1703 2860
1704/* sub-driver description */ 2861/* sub-driver description */
1705static const struct sd_desc sd_desc = { 2862static const struct sd_desc sd_desc = {