aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/tv8532.c
diff options
context:
space:
mode:
authorJean-Francois Moine <moinejf@free.fr>2009-01-09 07:13:26 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:42:31 -0400
commitca5e578f503133a580fbd5bed39cecf1e3c6e3a2 (patch)
treec3655d11bc9ebb24d42acb755b356e9ac7578ee8 /drivers/media/video/gspca/tv8532.c
parent0a32ef3fc81fcebf679139534a9f806cb9ff538c (diff)
V4L/DVB (10350): gspca - tv8532: Cleanup code.
Signed-off-by: Jean-Francois Moine <moinejf@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/gspca/tv8532.c')
-rw-r--r--drivers/media/video/gspca/tv8532.c474
1 files changed, 199 insertions, 275 deletions
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index 86e4f0e3d91..97ffaa7f933 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -31,7 +31,6 @@ struct sd {
31 struct gspca_dev gspca_dev; /* !! must be the first item */ 31 struct gspca_dev gspca_dev; /* !! must be the first item */
32 32
33 __u16 brightness; 33 __u16 brightness;
34 __u16 contrast;
35 34
36 __u8 packet; 35 __u8 packet;
37}; 36};
@@ -39,11 +38,8 @@ struct sd {
39/* V4L2 controls supported by the driver */ 38/* V4L2 controls supported by the driver */
40static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 39static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
41static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 40static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
42static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
43static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
44 41
45static struct ctrl sd_ctrls[] = { 42static struct ctrl sd_ctrls[] = {
46#define SD_BRIGHTNESS 0
47 { 43 {
48 { 44 {
49 .id = V4L2_CID_BRIGHTNESS, 45 .id = V4L2_CID_BRIGHTNESS,
@@ -52,25 +48,12 @@ static struct ctrl sd_ctrls[] = {
52 .minimum = 1, 48 .minimum = 1,
53 .maximum = 0x2ff, 49 .maximum = 0x2ff,
54 .step = 1, 50 .step = 1,
55 .default_value = 0x18f, 51#define BRIGHTNESS_DEF 0x18f
52 .default_value = BRIGHTNESS_DEF,
56 }, 53 },
57 .set = sd_setbrightness, 54 .set = sd_setbrightness,
58 .get = sd_getbrightness, 55 .get = sd_getbrightness,
59 }, 56 },
60#define SD_CONTRAST 1
61 {
62 {
63 .id = V4L2_CID_CONTRAST,
64 .type = V4L2_CTRL_TYPE_INTEGER,
65 .name = "Contrast",
66 .minimum = 0,
67 .maximum = 0xffff,
68 .step = 1,
69 .default_value = 0x7fff,
70 },
71 .set = sd_setcontrast,
72 .get = sd_getcontrast,
73 },
74}; 57};
75 58
76static const struct v4l2_pix_format sif_mode[] = { 59static const struct v4l2_pix_format sif_mode[] = {
@@ -86,78 +69,64 @@ static const struct v4l2_pix_format sif_mode[] = {
86 .priv = 0}, 69 .priv = 0},
87}; 70};
88 71
89/* 72/* TV-8532A (ICM532A) registers (LE) */
90 * Initialization data: this is the first set-up data written to the 73#define R00_PART_CONTROL 0x00
91 * device (before the open data). 74#define LATENT_CHANGE 0x80
92 */ 75#define EXPO_CHANGE 0x04
93#define TESTCLK 0x10 /* reg 0x2c -> 0x12 //10 */ 76#define R01_TIMING_CONTROL_LOW 0x01
94#define TESTCOMP 0x90 /* reg 0x28 -> 0x80 */ 77#define CMD_EEprom_Open 0x30
95#define TESTLINE 0x81 /* reg 0x29 -> 0x81 */ 78#define CMD_EEprom_Close 0x29
96#define QCIFLINE 0x41 /* reg 0x29 -> 0x81 */ 79#define R03_TABLE_ADDR 0x03
97#define TESTPTL 0x14 /* reg 0x2D -> 0x14 */ 80#define R04_WTRAM_DATA_L 0x04
98#define TESTPTH 0x01 /* reg 0x2E -> 0x01 */ 81#define R05_WTRAM_DATA_M 0x05
99#define TESTPTBL 0x12 /* reg 0x2F -> 0x0a */ 82#define R06_WTRAM_DATA_H 0x06
100#define TESTPTBH 0x01 /* reg 0x30 -> 0x01 */ 83#define R07_TABLE_LEN 0x07
101#define ADWIDTHL 0xe8 /* reg 0x0c -> 0xe8 */ 84#define R08_RAM_WRITE_ACTION 0x08
102#define ADWIDTHH 0x03 /* reg 0x0d -> 0x03 */ 85#define R0C_AD_WIDTHL 0x0c
103#define ADHEIGHL 0x90 /* reg 0x0e -> 0x91 //93 */ 86#define R0D_AD_WIDTHH 0x0d
104#define ADHEIGHH 0x01 /* reg 0x0f -> 0x01 */ 87#define R0E_AD_HEIGHTL 0x0e
105#define EXPOL 0x8f /* reg 0x1c -> 0x8f */ 88#define R0F_AD_HEIGHTH 0x0f
106#define EXPOH 0x01 /* reg 0x1d -> 0x01 */ 89#define R10_AD_COL_BEGINL 0x10
107#define ADCBEGINL 0x44 /* reg 0x10 -> 0x46 //47 */ 90#define R11_AD_COL_BEGINH 0x11
108#define ADCBEGINH 0x00 /* reg 0x11 -> 0x00 */ 91#define MIRROR 0x04 /* [10] */
109#define ADRBEGINL 0x0a /* reg 0x14 -> 0x0b //0x0c */ 92#define R14_AD_ROW_BEGINL 0x14
110#define ADRBEGINH 0x00 /* reg 0x15 -> 0x00 */ 93#define R15_AD_ROWBEGINH 0x15
111#define TV8532_CMD_UPDATE 0x84 94#define R1C_AD_EXPOSE_TIMEL 0x1c
112 95#define R28_QUANT 0x28
113#define TV8532_EEprom_Add 0x03 96#define R29_LINE 0x29
114#define TV8532_EEprom_DataL 0x04 97#define R2C_POLARITY 0x2c
115#define TV8532_EEprom_DataM 0x05 98#define R2D_POINT 0x2d
116#define TV8532_EEprom_DataH 0x06 99#define R2E_POINTH 0x2e
117#define TV8532_EEprom_TableLength 0x07 100#define R2F_POINTB 0x2f
118#define TV8532_EEprom_Write 0x08 101#define R30_POINTBH 0x30
119#define TV8532_PART_CTRL 0x00 102#define R31_UPD 0x31
120#define TV8532_CTRL 0x01 103#define R2A_HIGH_BUDGET 0x2a
121#define TV8532_CMD_EEprom_Open 0x30 104#define R2B_LOW_BUDGET 0x2b
122#define TV8532_CMD_EEprom_Close 0x29 105#define R34_VID 0x34
123#define TV8532_UDP_UPDATE 0x31 106#define R35_VIDH 0x35
124#define TV8532_GPIO 0x39 107#define R36_PID 0x36
125#define TV8532_GPIO_OE 0x3B 108#define R37_PIDH 0x37
126#define TV8532_REQ_RegWrite 0x02 109#define R39_Test1 0x39 /* GPIO */
127#define TV8532_REQ_RegRead 0x03 110#define R3B_Test3 0x3B /* GPIO */
128 111#define R83_AD_IDH 0x83
129#define TV8532_ADWIDTH_L 0x0C 112#define R91_AD_SLOPEREG 0x91
130#define TV8532_ADWIDTH_H 0x0D 113#define R94_AD_BITCONTROL 0x94
131#define TV8532_ADHEIGHT_L 0x0E 114
132#define TV8532_ADHEIGHT_H 0x0F 115static const u8 eeprom_data[][3] = {
133#define TV8532_EXPOSURE 0x1C 116/* dataH dataM dataL */
134#define TV8532_QUANT_COMP 0x28 117 {0x01, 0x00, 0x01},
135#define TV8532_MODE_PACKET 0x29 118 {0x01, 0x80, 0x11},
136#define TV8532_SETCLK 0x2C 119 {0x05, 0x00, 0x14},
137#define TV8532_POINT_L 0x2D 120 {0x05, 0x00, 0x1c},
138#define TV8532_POINT_H 0x2E 121 {0x0d, 0x00, 0x1e},
139#define TV8532_POINTB_L 0x2F 122 {0x05, 0x00, 0x1f},
140#define TV8532_POINTB_H 0x30 123 {0x05, 0x05, 0x19},
141#define TV8532_BUDGET_L 0x2A 124 {0x05, 0x01, 0x1b},
142#define TV8532_BUDGET_H 0x2B 125 {0x05, 0x09, 0x1e},
143#define TV8532_VID_L 0x34 126 {0x0d, 0x89, 0x2e},
144#define TV8532_VID_H 0x35 127 {0x05, 0x89, 0x2f},
145#define TV8532_PID_L 0x36 128 {0x05, 0x0d, 0xd9},
146#define TV8532_PID_H 0x37 129 {0x05, 0x09, 0xf1},
147#define TV8532_DeviceID 0x83
148#define TV8532_AD_SLOPE 0x91
149#define TV8532_AD_BITCTRL 0x94
150#define TV8532_AD_COLBEGIN_L 0x10
151#define TV8532_AD_COLBEGIN_H 0x11
152#define TV8532_AD_ROWBEGIN_L 0x14
153#define TV8532_AD_ROWBEGIN_H 0x15
154
155static const __u32 tv_8532_eeprom_data[] = {
156/* add dataL dataM dataH */
157 0x00010001, 0x01018011, 0x02050014, 0x0305001c,
158 0x040d001e, 0x0505001f, 0x06050519, 0x0705011b,
159 0x0805091e, 0x090d892e, 0x0a05892f, 0x0b050dd9,
160 0x0c0509f1, 0
161}; 130};
162 131
163static int reg_r(struct gspca_dev *gspca_dev, 132static int reg_r(struct gspca_dev *gspca_dev,
@@ -165,7 +134,7 @@ static int reg_r(struct gspca_dev *gspca_dev,
165{ 134{
166 usb_control_msg(gspca_dev->dev, 135 usb_control_msg(gspca_dev->dev,
167 usb_rcvctrlpipe(gspca_dev->dev, 0), 136 usb_rcvctrlpipe(gspca_dev->dev, 0),
168 TV8532_REQ_RegRead, 137 0x03,
169 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 138 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
170 0, /* value */ 139 0, /* value */
171 index, gspca_dev->usb_buf, 1, 140 index, gspca_dev->usb_buf, 1,
@@ -174,27 +143,27 @@ static int reg_r(struct gspca_dev *gspca_dev,
174} 143}
175 144
176/* write 1 byte */ 145/* write 1 byte */
177static void reg_w_1(struct gspca_dev *gspca_dev, 146static void reg_w1(struct gspca_dev *gspca_dev,
178 __u16 index, __u8 value) 147 __u16 index, __u8 value)
179{ 148{
180 gspca_dev->usb_buf[0] = value; 149 gspca_dev->usb_buf[0] = value;
181 usb_control_msg(gspca_dev->dev, 150 usb_control_msg(gspca_dev->dev,
182 usb_sndctrlpipe(gspca_dev->dev, 0), 151 usb_sndctrlpipe(gspca_dev->dev, 0),
183 TV8532_REQ_RegWrite, 152 0x02,
184 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 153 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
185 0, /* value */ 154 0, /* value */
186 index, gspca_dev->usb_buf, 1, 500); 155 index, gspca_dev->usb_buf, 1, 500);
187} 156}
188 157
189/* write 2 bytes */ 158/* write 2 bytes */
190static void reg_w_2(struct gspca_dev *gspca_dev, 159static void reg_w2(struct gspca_dev *gspca_dev,
191 __u16 index, __u8 val1, __u8 val2) 160 u16 index, u16 value)
192{ 161{
193 gspca_dev->usb_buf[0] = val1; 162 gspca_dev->usb_buf[0] = value;
194 gspca_dev->usb_buf[1] = val2; 163 gspca_dev->usb_buf[1] = value >> 8;
195 usb_control_msg(gspca_dev->dev, 164 usb_control_msg(gspca_dev->dev,
196 usb_sndctrlpipe(gspca_dev->dev, 0), 165 usb_sndctrlpipe(gspca_dev->dev, 0),
197 TV8532_REQ_RegWrite, 166 0x02,
198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 167 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
199 0, /* value */ 168 0, /* value */
200 index, gspca_dev->usb_buf, 2, 500); 169 index, gspca_dev->usb_buf, 2, 500);
@@ -202,32 +171,18 @@ static void reg_w_2(struct gspca_dev *gspca_dev,
202 171
203static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev) 172static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev)
204{ 173{
205 int i = 0; 174 int i;
206 __u8 reg, data0, data1, data2; 175
207 176 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Open);
208 reg_w_1(gspca_dev, TV8532_GPIO, 0xb0); 177 for (i = 0; i < ARRAY_SIZE(eeprom_data); i++) {
209 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Open); 178 reg_w1(gspca_dev, R03_TABLE_ADDR, i);
210/* msleep(1); */ 179 reg_w1(gspca_dev, R04_WTRAM_DATA_L, eeprom_data[i][2]);
211 while (tv_8532_eeprom_data[i]) { 180 reg_w1(gspca_dev, R05_WTRAM_DATA_M, eeprom_data[i][1]);
212 reg = (tv_8532_eeprom_data[i] & 0xff000000) >> 24; 181 reg_w1(gspca_dev, R06_WTRAM_DATA_H, eeprom_data[i][0]);
213 reg_w_1(gspca_dev, TV8532_EEprom_Add, reg); 182 reg_w1(gspca_dev, R08_RAM_WRITE_ACTION, 0);
214 /* msleep(1); */
215 data0 = (tv_8532_eeprom_data[i] & 0x000000ff);
216 reg_w_1(gspca_dev, TV8532_EEprom_DataL, data0);
217 /* msleep(1); */
218 data1 = (tv_8532_eeprom_data[i] & 0x0000ff00) >> 8;
219 reg_w_1(gspca_dev, TV8532_EEprom_DataM, data1);
220 /* msleep(1); */
221 data2 = (tv_8532_eeprom_data[i] & 0x00ff0000) >> 16;
222 reg_w_1(gspca_dev, TV8532_EEprom_DataH, data2);
223 /* msleep(1); */
224 reg_w_1(gspca_dev, TV8532_EEprom_Write, 0);
225 /* msleep(10); */
226 i++;
227 } 183 }
228 reg_w_1(gspca_dev, TV8532_EEprom_TableLength, i); 184 reg_w1(gspca_dev, R07_TABLE_LEN, i);
229/* msleep(1); */ 185 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Close);
230 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Close);
231 msleep(10); 186 msleep(10);
232} 187}
233 188
@@ -238,78 +193,76 @@ static int sd_config(struct gspca_dev *gspca_dev,
238 struct sd *sd = (struct sd *) gspca_dev; 193 struct sd *sd = (struct sd *) gspca_dev;
239 struct cam *cam; 194 struct cam *cam;
240 195
241 tv_8532WriteEEprom(gspca_dev);
242
243 cam = &gspca_dev->cam; 196 cam = &gspca_dev->cam;
244 cam->cam_mode = sif_mode; 197 cam->cam_mode = sif_mode;
245 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0]; 198 cam->nmodes = ARRAY_SIZE(sif_mode);
246 199
247 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 200 sd->brightness = BRIGHTNESS_DEF;
248 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
249 return 0; 201 return 0;
250} 202}
251 203
252static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev) 204static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev)
253{ 205{
254 __u8 data; 206 int i;
255 207 static u8 reg_tb[] = {
256 data = reg_r(gspca_dev, 0x0001); 208 R0C_AD_WIDTHL,
257 PDEBUG(D_USBI, "register 0x01-> %x", data); 209 R0D_AD_WIDTHH,
258 data = reg_r(gspca_dev, 0x0002); 210 R28_QUANT,
259 PDEBUG(D_USBI, "register 0x02-> %x", data); 211 R29_LINE,
260 reg_r(gspca_dev, TV8532_ADWIDTH_L); 212 R2C_POLARITY,
261 reg_r(gspca_dev, TV8532_ADWIDTH_H); 213 R2D_POINT,
262 reg_r(gspca_dev, TV8532_QUANT_COMP); 214 R2E_POINTH,
263 reg_r(gspca_dev, TV8532_MODE_PACKET); 215 R2F_POINTB,
264 reg_r(gspca_dev, TV8532_SETCLK); 216 R30_POINTBH,
265 reg_r(gspca_dev, TV8532_POINT_L); 217 R2A_HIGH_BUDGET,
266 reg_r(gspca_dev, TV8532_POINT_H); 218 R2B_LOW_BUDGET,
267 reg_r(gspca_dev, TV8532_POINTB_L); 219 R34_VID,
268 reg_r(gspca_dev, TV8532_POINTB_H); 220 R35_VIDH,
269 reg_r(gspca_dev, TV8532_BUDGET_L); 221 R36_PID,
270 reg_r(gspca_dev, TV8532_BUDGET_H); 222 R37_PIDH,
271 reg_r(gspca_dev, TV8532_VID_L); 223 R83_AD_IDH,
272 reg_r(gspca_dev, TV8532_VID_H); 224 R10_AD_COL_BEGINL,
273 reg_r(gspca_dev, TV8532_PID_L); 225 R11_AD_COL_BEGINH,
274 reg_r(gspca_dev, TV8532_PID_H); 226 R14_AD_ROW_BEGINL,
275 reg_r(gspca_dev, TV8532_DeviceID); 227 R15_AD_ROWBEGINH,
276 reg_r(gspca_dev, TV8532_AD_COLBEGIN_L); 228 0
277 reg_r(gspca_dev, TV8532_AD_COLBEGIN_H); 229 };
278 reg_r(gspca_dev, TV8532_AD_ROWBEGIN_L); 230
279 reg_r(gspca_dev, TV8532_AD_ROWBEGIN_H); 231 i = 0;
232 do {
233 reg_r(gspca_dev, reg_tb[i]);
234 i++;
235 } while (reg_tb[i] != 0);
280} 236}
281 237
282static void tv_8532_setReg(struct gspca_dev *gspca_dev) 238static void tv_8532_setReg(struct gspca_dev *gspca_dev)
283{ 239{
284 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_L, 240 reg_w1(gspca_dev, R10_AD_COL_BEGINL, 0x44);
285 ADCBEGINL); /* 0x10 */ 241 /* begin active line */
286 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_H, 242 reg_w1(gspca_dev, R11_AD_COL_BEGINH, 0x00);
287 ADCBEGINH); /* also digital gain */ 243 /* mirror and digital gain */
288 reg_w_1(gspca_dev, TV8532_PART_CTRL, 244 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
289 TV8532_CMD_UPDATE); /* 0x00<-0x84 */ 245 /* = 0x84 */
290 246
291 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0a); 247 reg_w1(gspca_dev, R3B_Test3, 0x0a); /* Test0Sel = 10 */
292 /******************************************************/ 248 /******************************************************/
293 reg_w_1(gspca_dev, TV8532_ADHEIGHT_L, ADHEIGHL); /* 0e */ 249 reg_w1(gspca_dev, R0E_AD_HEIGHTL, 0x90);
294 reg_w_1(gspca_dev, TV8532_ADHEIGHT_H, ADHEIGHH); /* 0f */ 250 reg_w1(gspca_dev, R0F_AD_HEIGHTH, 0x01);
295 reg_w_2(gspca_dev, TV8532_EXPOSURE, 251 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, 0x018f);
296 EXPOL, EXPOH); /* 350d 0x014c; 1c */ 252 reg_w1(gspca_dev, R10_AD_COL_BEGINL, 0x44);
297 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_L, 253 /* begin active line */
298 ADCBEGINL); /* 0x10 */ 254 reg_w1(gspca_dev, R11_AD_COL_BEGINH, 0x00);
299 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_H, 255 /* mirror and digital gain */
300 ADCBEGINH); /* also digital gain */ 256 reg_w1(gspca_dev, R14_AD_ROW_BEGINL, 0x0a);
301 reg_w_1(gspca_dev, TV8532_AD_ROWBEGIN_L, 257
302 ADRBEGINL); /* 0x14 */ 258 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x00);
303 259 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x02);
304 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */ 260
305 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x02); /* 0x94 */ 261 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Close);
306 262
307 reg_w_1(gspca_dev, TV8532_CTRL, 263 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x00);
308 TV8532_CMD_EEprom_Close); /* 0x01 */ 264 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
309 265 /* = 0x84 */
310 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */
311 reg_w_1(gspca_dev, TV8532_PART_CTRL,
312 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
313} 266}
314 267
315static void tv_8532_PollReg(struct gspca_dev *gspca_dev) 268static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
@@ -318,54 +271,55 @@ static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
318 271
319 /* strange polling from tgc */ 272 /* strange polling from tgc */
320 for (i = 0; i < 10; i++) { 273 for (i = 0; i < 10; i++) {
321 reg_w_1(gspca_dev, TV8532_SETCLK, 274 reg_w1(gspca_dev, R2C_POLARITY, 0x10);
322 TESTCLK); /* 0x48; //0x08; 0x2c */ 275 reg_w1(gspca_dev, R00_PART_CONTROL,
323 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE); 276 LATENT_CHANGE | EXPO_CHANGE);
324 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */ 277 reg_w1(gspca_dev, R31_UPD, 0x01);
325 } 278 }
326} 279}
327 280
328/* this function is called at probe and resume time */ 281/* this function is called at probe and resume time */
329static int sd_init(struct gspca_dev *gspca_dev) 282static int sd_init(struct gspca_dev *gspca_dev)
330{ 283{
331 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32); 284 tv_8532WriteEEprom(gspca_dev);
332 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00); 285
286 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x32); /* slope begin 1,7V,
287 * slope rate 2 */
288 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x00);
333 tv_8532ReadRegisters(gspca_dev); 289 tv_8532ReadRegisters(gspca_dev);
334 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 290 reg_w1(gspca_dev, R3B_Test3, 0x0b);
335 reg_w_2(gspca_dev, TV8532_ADHEIGHT_L, ADHEIGHL, 291 reg_w2(gspca_dev, R0E_AD_HEIGHTL, 0x0190);
336 ADHEIGHH); /* 401d 0x0169; 0e */ 292 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, 0x018f);
337 reg_w_2(gspca_dev, TV8532_EXPOSURE, EXPOL, 293 reg_w1(gspca_dev, R0C_AD_WIDTHL, 0xe8);
338 EXPOH); /* 350d 0x014c; 1c */ 294 reg_w1(gspca_dev, R0D_AD_WIDTHH, 0x03);
339 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */
340 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */
341 295
342 /*******************************************************************/ 296 /*******************************************************************/
343 reg_w_1(gspca_dev, TV8532_QUANT_COMP, 297 reg_w1(gspca_dev, R28_QUANT, 0x90);
344 TESTCOMP); /* 0x72 compressed mode 0x28 */ 298 /* no compress - fixed Q - quant 0 */
345 reg_w_1(gspca_dev, TV8532_MODE_PACKET, 299 reg_w1(gspca_dev, R29_LINE, 0x81);
346 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */ 300 /* 0x84; // CIF | 4 packet 0x29 */
347 301
348 /************************************************/ 302 /************************************************/
349 reg_w_1(gspca_dev, TV8532_SETCLK, 303 reg_w1(gspca_dev, R2C_POLARITY, 0x10);
350 TESTCLK); /* 0x48; //0x08; 0x2c */ 304 /* 0x48; //0x08; 0x2c */
351 reg_w_1(gspca_dev, TV8532_POINT_L, 305 reg_w1(gspca_dev, R2D_POINT, 0x14);
352 TESTPTL); /* 0x38; 0x2d */ 306 /* 0x38; 0x2d */
353 reg_w_1(gspca_dev, TV8532_POINT_H, 307 reg_w1(gspca_dev, R2E_POINTH, 0x01);
354 TESTPTH); /* 0x04; 0x2e */ 308 /* 0x04; 0x2e */
355 reg_w_1(gspca_dev, TV8532_POINTB_L, 309 reg_w1(gspca_dev, R2F_POINTB, 0x12);
356 TESTPTBL); /* 0x04; 0x2f */ 310 /* 0x04; 0x2f */
357 reg_w_1(gspca_dev, TV8532_POINTB_H, 311 reg_w1(gspca_dev, R30_POINTBH, 0x01);
358 TESTPTBH); /* 0x04; 0x30 */ 312 /* 0x04; 0x30 */
359 reg_w_1(gspca_dev, TV8532_PART_CTRL, 313 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
360 TV8532_CMD_UPDATE); /* 0x00<-0x84 */ 314 /* 0x00<-0x84 */
361 /*************************************************/ 315 /*************************************************/
362 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */ 316 reg_w1(gspca_dev, R31_UPD, 0x01); /* update registers */
363 msleep(200); 317 msleep(200);
364 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */ 318 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
365 /*************************************************/ 319 /*************************************************/
366 tv_8532_setReg(gspca_dev); 320 tv_8532_setReg(gspca_dev);
367 /*************************************************/ 321 /*************************************************/
368 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 322 reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */
369 /*************************************************/ 323 /*************************************************/
370 tv_8532_setReg(gspca_dev); 324 tv_8532_setReg(gspca_dev);
371 /*************************************************/ 325 /*************************************************/
@@ -376,11 +330,10 @@ static int sd_init(struct gspca_dev *gspca_dev)
376static void setbrightness(struct gspca_dev *gspca_dev) 330static void setbrightness(struct gspca_dev *gspca_dev)
377{ 331{
378 struct sd *sd = (struct sd *) gspca_dev; 332 struct sd *sd = (struct sd *) gspca_dev;
379 int brightness = sd->brightness;
380 333
381 reg_w_2(gspca_dev, TV8532_EXPOSURE, 334 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, sd->brightness);
382 brightness >> 8, brightness); /* 1c */ 335 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
383 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE); 336 /* 0x84 */
384} 337}
385 338
386/* -- start the camera -- */ 339/* -- start the camera -- */
@@ -388,57 +341,50 @@ static int sd_start(struct gspca_dev *gspca_dev)
388{ 341{
389 struct sd *sd = (struct sd *) gspca_dev; 342 struct sd *sd = (struct sd *) gspca_dev;
390 343
391 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32); 344 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x32); /* slope begin 1,7V,
392 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00); 345 * slope rate 2 */
346 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x00);
393 tv_8532ReadRegisters(gspca_dev); 347 tv_8532ReadRegisters(gspca_dev);
394 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 348 reg_w1(gspca_dev, R3B_Test3, 0x0b);
395 reg_w_2(gspca_dev, TV8532_ADHEIGHT_L, 349
396 ADHEIGHL, ADHEIGHH); /* 401d 0x0169; 0e */ 350 reg_w2(gspca_dev, R0E_AD_HEIGHTL, 0x0190);
397/* reg_w_2(gspca_dev, TV8532_EXPOSURE,
398 EXPOL, EXPOH); * 350d 0x014c; 1c */
399 setbrightness(gspca_dev); 351 setbrightness(gspca_dev);
400 352
401 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */ 353 reg_w1(gspca_dev, R0C_AD_WIDTHL, 0xe8); /* 0x20; 0x0c */
402 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */ 354 reg_w1(gspca_dev, R0D_AD_WIDTHH, 0x03);
403 355
404 /************************************************/ 356 /************************************************/
405 reg_w_1(gspca_dev, TV8532_QUANT_COMP, 357 reg_w1(gspca_dev, R28_QUANT, 0x90);
406 TESTCOMP); /* 0x72 compressed mode 0x28 */ 358 /* 0x72 compressed mode 0x28 */
407 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 359 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
408 /* 176x144 */ 360 /* 176x144 */
409 reg_w_1(gspca_dev, TV8532_MODE_PACKET, 361 reg_w1(gspca_dev, R29_LINE, 0x41);
410 QCIFLINE); /* 0x84; // CIF | 4 packet 0x29 */ 362 /* CIF - 2 lines/packet */
411 } else { 363 } else {
412 /* 352x288 */ 364 /* 352x288 */
413 reg_w_1(gspca_dev, TV8532_MODE_PACKET, 365 reg_w1(gspca_dev, R29_LINE, 0x81);
414 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */ 366 /* CIF - 2 lines/packet */
415 } 367 }
416 /************************************************/ 368 /************************************************/
417 reg_w_1(gspca_dev, TV8532_SETCLK, 369 reg_w1(gspca_dev, R2C_POLARITY, 0x10); /* slow clock */
418 TESTCLK); /* 0x48; //0x08; 0x2c */ 370 reg_w1(gspca_dev, R2D_POINT, 0x14);
419 reg_w_1(gspca_dev, TV8532_POINT_L, 371 reg_w1(gspca_dev, R2E_POINTH, 0x01);
420 TESTPTL); /* 0x38; 0x2d */ 372 reg_w1(gspca_dev, R2F_POINTB, 0x12);
421 reg_w_1(gspca_dev, TV8532_POINT_H, 373 reg_w1(gspca_dev, R30_POINTBH, 0x01);
422 TESTPTH); /* 0x04; 0x2e */ 374 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
423 reg_w_1(gspca_dev, TV8532_POINTB_L,
424 TESTPTBL); /* 0x04; 0x2f */
425 reg_w_1(gspca_dev, TV8532_POINTB_H,
426 TESTPTBH); /* 0x04; 0x30 */
427 reg_w_1(gspca_dev, TV8532_PART_CTRL,
428 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
429 /************************************************/ 375 /************************************************/
430 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */ 376 reg_w1(gspca_dev, R31_UPD, 0x01); /* update registers */
431 msleep(200); 377 msleep(200);
432 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */ 378 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
433 /************************************************/ 379 /************************************************/
434 tv_8532_setReg(gspca_dev); 380 tv_8532_setReg(gspca_dev);
435 /************************************************/ 381 /************************************************/
436 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 382 reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */
437 /************************************************/ 383 /************************************************/
438 tv_8532_setReg(gspca_dev); 384 tv_8532_setReg(gspca_dev);
439 /************************************************/ 385 /************************************************/
440 tv_8532_PollReg(gspca_dev); 386 tv_8532_PollReg(gspca_dev);
441 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */ 387 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
442 388
443 gspca_dev->empty_packet = 0; /* check the empty packets */ 389 gspca_dev->empty_packet = 0; /* check the empty packets */
444 sd->packet = 0; /* ignore the first packets */ 390 sd->packet = 0; /* ignore the first packets */
@@ -448,7 +394,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
448 394
449static void sd_stopN(struct gspca_dev *gspca_dev) 395static void sd_stopN(struct gspca_dev *gspca_dev)
450{ 396{
451 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 397 reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */
452} 398}
453 399
454static void sd_pkt_scan(struct gspca_dev *gspca_dev, 400static void sd_pkt_scan(struct gspca_dev *gspca_dev,
@@ -472,9 +418,9 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
472 418
473 /* each packet contains: 419 /* each packet contains:
474 * - header 2 bytes 420 * - header 2 bytes
475 * - RG line 421 * - RGRG line
476 * - 4 bytes 422 * - 4 bytes
477 * - GB line 423 * - GBGB line
478 * - 4 bytes 424 * - 4 bytes
479 */ 425 */
480 gspca_frame_add(gspca_dev, packet_type0, 426 gspca_frame_add(gspca_dev, packet_type0,
@@ -483,10 +429,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
483 frame, data + gspca_dev->width + 6, gspca_dev->width); 429 frame, data + gspca_dev->width + 6, gspca_dev->width);
484} 430}
485 431
486static void setcontrast(struct gspca_dev *gspca_dev)
487{
488}
489
490static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 432static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
491{ 433{
492 struct sd *sd = (struct sd *) gspca_dev; 434 struct sd *sd = (struct sd *) gspca_dev;
@@ -505,24 +447,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
505 return 0; 447 return 0;
506} 448}
507 449
508static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
509{
510 struct sd *sd = (struct sd *) gspca_dev;
511
512 sd->contrast = val;
513 if (gspca_dev->streaming)
514 setcontrast(gspca_dev);
515 return 0;
516}
517
518static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
519{
520 struct sd *sd = (struct sd *) gspca_dev;
521
522 *val = sd->contrast;
523 return 0;
524}
525
526/* sub-driver description */ 450/* sub-driver description */
527static const struct sd_desc sd_desc = { 451static const struct sd_desc sd_desc = {
528 .name = MODULE_NAME, 452 .name = MODULE_NAME,