1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Support for the sensor part which is integrated (I think) into the
4 * st6422 stv06xx alike bridge, as its integrated there are no i2c writes
5 * but instead direct bridge writes.
7 * Copyright (c) 2009 Hans de Goede <hdegoede@redhat.com>
9 * Strongly based on qc-usb-messenger, which is:
10 * Copyright (c) 2001 Jean-Fredric Clere, Nikolas Zimmermann, Georg Acher
11 * Mark Cave-Ayland, Carlo E Prelz, Dick Streefland
12 * Copyright (c) 2002, 2003 Tuukka Toivonen
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #include "stv06xx_st6422.h"
19 static struct v4l2_pix_format st6422_mode[] = {
20 /* Note we actually get 124 lines of data, of which we skip the 4st
21 4 as they are garbage */
27 .sizeimage = 162 * 120,
29 .colorspace = V4L2_COLORSPACE_SRGB,
32 /* Note we actually get 248 lines of data, of which we skip the 4st
33 4 as they are garbage, and we tell the app it only gets the
34 first 240 of the 244 lines it actually gets, so that it ignores
41 .sizeimage = 324 * 244,
43 .colorspace = V4L2_COLORSPACE_SRGB,
48 /* V4L2 controls supported by the driver */
49 static int setbrightness(struct sd *sd, s32 val);
50 static int setcontrast(struct sd *sd, s32 val);
51 static int setgain(struct sd *sd, u8 gain);
52 static int setexposure(struct sd *sd, s16 expo);
54 static int st6422_s_ctrl(struct v4l2_ctrl *ctrl)
56 struct gspca_dev *gspca_dev =
57 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
58 struct sd *sd = (struct sd *)gspca_dev;
62 case V4L2_CID_BRIGHTNESS:
63 err = setbrightness(sd, ctrl->val);
65 case V4L2_CID_CONTRAST:
66 err = setcontrast(sd, ctrl->val);
69 err = setgain(sd, ctrl->val);
71 case V4L2_CID_EXPOSURE:
72 err = setexposure(sd, ctrl->val);
78 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
79 sd->gspca_dev.usb_err = err;
83 static const struct v4l2_ctrl_ops st6422_ctrl_ops = {
84 .s_ctrl = st6422_s_ctrl,
87 static int st6422_init_controls(struct sd *sd)
89 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
91 v4l2_ctrl_handler_init(hdl, 4);
92 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
93 V4L2_CID_BRIGHTNESS, 0, 31, 1, 3);
94 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
95 V4L2_CID_CONTRAST, 0, 15, 1, 11);
96 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
97 V4L2_CID_EXPOSURE, 0, 1023, 1, 256);
98 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
99 V4L2_CID_GAIN, 0, 255, 1, 64);
104 static int st6422_probe(struct sd *sd)
106 if (sd->bridge != BRIDGE_ST6422)
109 pr_info("st6422 sensor detected\n");
111 sd->gspca_dev.cam.cam_mode = st6422_mode;
112 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(st6422_mode);
116 static int st6422_init(struct sd *sd)
120 const u16 st6422_bridge_init[][2] = {
121 { STV_ISO_ENABLE, 0x00 }, /* disable capture */
123 { 0x1432, 0x03 }, /* 0x00-0x1F brightness */
124 { 0x143a, 0xf9 }, /* 0x00-0x0F contrast */
125 { 0x0509, 0x38 }, /* R */
126 { 0x050a, 0x38 }, /* G */
127 { 0x050b, 0x38 }, /* B */
132 { 0x1431, 0x00 }, /* 0x00-0x07 ??? */
133 { 0x1433, 0x34 }, /* 160x120, 0x00-0x01 night filter */
134 { 0x1438, 0x18 }, /* 640x480 */
139 /* anti-noise? 0xa2 gives a perfect image */
142 { 0x143c, 0x00 }, /* 0x00-0x01 - ??? */
145 /* shutter time 0x0000-0x03FF */
146 /* low value give good picures on moving objects (but requires much light) */
147 /* high value gives good picures in darkness (but tends to be overexposed) */
152 /* write: 1x1x xxxx */
153 /* read: 1x1x xxxx */
154 /* bit 5 == button pressed and hold if 0 */
155 /* write 0xe2,0xea */
159 /* bit 7 == button has been pressed, but not handled */
162 /* if(urb->iso_frame_desc[i].status == 0x80) { */
163 /* if(urb->iso_frame_desc[i].status == 0x88) { */
167 { 0x1500, 0x50 }, /* 0x00 - 0xFF 0x80 == compr ? */
170 /* high val-> light area gets darker */
171 /* low val -> light area gets lighter */
173 /* high val-> light area gets darker */
174 /* low val -> light area gets lighter */
176 /* high val-> light area gets darker */
177 /* low val -> light area gets lighter */
179 /* 2 : 324x248 80352 bytes */
180 /* 7 : 248x162 40176 bytes */
181 /* c+f: 162*124 20088 bytes */
186 { 0x15c3, 0x08 }, /* 0x04/0x14 ... test pictures ??? */
189 { 0x143f, 0x01 }, /* commit settings */
193 for (i = 0; i < ARRAY_SIZE(st6422_bridge_init) && !err; i++) {
194 err = stv06xx_write_bridge(sd, st6422_bridge_init[i][0],
195 st6422_bridge_init[i][1]);
201 static int setbrightness(struct sd *sd, s32 val)
203 /* val goes from 0 -> 31 */
204 return stv06xx_write_bridge(sd, 0x1432, val);
207 static int setcontrast(struct sd *sd, s32 val)
209 /* Val goes from 0 -> 15 */
210 return stv06xx_write_bridge(sd, 0x143a, val | 0xf0);
213 static int setgain(struct sd *sd, u8 gain)
217 /* Set red, green, blue, gain */
218 err = stv06xx_write_bridge(sd, 0x0509, gain);
222 err = stv06xx_write_bridge(sd, 0x050a, gain);
226 err = stv06xx_write_bridge(sd, 0x050b, gain);
230 /* 2 mystery writes */
231 err = stv06xx_write_bridge(sd, 0x050c, 0x2a);
235 return stv06xx_write_bridge(sd, 0x050d, 0x01);
238 static int setexposure(struct sd *sd, s16 expo)
242 err = stv06xx_write_bridge(sd, 0x143d, expo & 0xff);
246 return stv06xx_write_bridge(sd, 0x143e, expo >> 8);
249 static int st6422_start(struct sd *sd)
252 struct cam *cam = &sd->gspca_dev.cam;
254 if (cam->cam_mode[sd->gspca_dev.curr_mode].priv)
255 err = stv06xx_write_bridge(sd, 0x1505, 0x0f);
257 err = stv06xx_write_bridge(sd, 0x1505, 0x02);
261 /* commit settings */
262 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
263 return (err < 0) ? err : 0;
266 static int st6422_stop(struct sd *sd)
268 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
270 gspca_dbg(gspca_dev, D_STREAM, "Halting stream\n");