0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0016
0017 #include "stv06xx_st6422.h"
0018
0019 static struct v4l2_pix_format st6422_mode[] = {
0020
0021
0022 {
0023 162,
0024 120,
0025 V4L2_PIX_FMT_SGRBG8,
0026 V4L2_FIELD_NONE,
0027 .sizeimage = 162 * 120,
0028 .bytesperline = 162,
0029 .colorspace = V4L2_COLORSPACE_SRGB,
0030 .priv = 1
0031 },
0032
0033
0034
0035
0036 {
0037 324,
0038 240,
0039 V4L2_PIX_FMT_SGRBG8,
0040 V4L2_FIELD_NONE,
0041 .sizeimage = 324 * 244,
0042 .bytesperline = 324,
0043 .colorspace = V4L2_COLORSPACE_SRGB,
0044 .priv = 0
0045 },
0046 };
0047
0048
0049 static int setbrightness(struct sd *sd, s32 val);
0050 static int setcontrast(struct sd *sd, s32 val);
0051 static int setgain(struct sd *sd, u8 gain);
0052 static int setexposure(struct sd *sd, s16 expo);
0053
0054 static int st6422_s_ctrl(struct v4l2_ctrl *ctrl)
0055 {
0056 struct gspca_dev *gspca_dev =
0057 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
0058 struct sd *sd = (struct sd *)gspca_dev;
0059 int err = -EINVAL;
0060
0061 switch (ctrl->id) {
0062 case V4L2_CID_BRIGHTNESS:
0063 err = setbrightness(sd, ctrl->val);
0064 break;
0065 case V4L2_CID_CONTRAST:
0066 err = setcontrast(sd, ctrl->val);
0067 break;
0068 case V4L2_CID_GAIN:
0069 err = setgain(sd, ctrl->val);
0070 break;
0071 case V4L2_CID_EXPOSURE:
0072 err = setexposure(sd, ctrl->val);
0073 break;
0074 }
0075
0076
0077 if (err >= 0)
0078 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
0079 sd->gspca_dev.usb_err = err;
0080 return err;
0081 }
0082
0083 static const struct v4l2_ctrl_ops st6422_ctrl_ops = {
0084 .s_ctrl = st6422_s_ctrl,
0085 };
0086
0087 static int st6422_init_controls(struct sd *sd)
0088 {
0089 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
0090
0091 v4l2_ctrl_handler_init(hdl, 4);
0092 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
0093 V4L2_CID_BRIGHTNESS, 0, 31, 1, 3);
0094 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
0095 V4L2_CID_CONTRAST, 0, 15, 1, 11);
0096 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
0097 V4L2_CID_EXPOSURE, 0, 1023, 1, 256);
0098 v4l2_ctrl_new_std(hdl, &st6422_ctrl_ops,
0099 V4L2_CID_GAIN, 0, 255, 1, 64);
0100
0101 return hdl->error;
0102 }
0103
0104 static int st6422_probe(struct sd *sd)
0105 {
0106 if (sd->bridge != BRIDGE_ST6422)
0107 return -ENODEV;
0108
0109 pr_info("st6422 sensor detected\n");
0110
0111 sd->gspca_dev.cam.cam_mode = st6422_mode;
0112 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(st6422_mode);
0113 return 0;
0114 }
0115
0116 static int st6422_init(struct sd *sd)
0117 {
0118 int err = 0, i;
0119
0120 static const u16 st6422_bridge_init[][2] = {
0121 { STV_ISO_ENABLE, 0x00 },
0122 { 0x1436, 0x00 },
0123 { 0x1432, 0x03 },
0124 { 0x143a, 0xf9 },
0125 { 0x0509, 0x38 },
0126 { 0x050a, 0x38 },
0127 { 0x050b, 0x38 },
0128 { 0x050c, 0x2a },
0129 { 0x050d, 0x01 },
0130
0131
0132 { 0x1431, 0x00 },
0133 { 0x1433, 0x34 },
0134 { 0x1438, 0x18 },
0135
0136
0137
0138 { 0x1439, 0x00 },
0139
0140
0141 { 0x143b, 0x05 },
0142 { 0x143c, 0x00 },
0143
0144
0145
0146
0147
0148 { 0x143e, 0x01 },
0149 { 0x143d, 0x00 },
0150
0151 { 0x1442, 0xe2 },
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 { 0x1500, 0xd0 },
0166 { 0x1500, 0xd0 },
0167 { 0x1500, 0x50 },
0168
0169 { 0x1501, 0xaf },
0170
0171
0172 { 0x1502, 0xc2 },
0173
0174
0175 { 0x1503, 0x45 },
0176
0177
0178 { 0x1505, 0x02 },
0179
0180
0181
0182
0183 { 0x150e, 0x8e },
0184 { 0x150f, 0x37 },
0185 { 0x15c0, 0x00 },
0186 { 0x15c3, 0x08 },
0187
0188
0189 { 0x143f, 0x01 },
0190
0191 };
0192
0193 for (i = 0; i < ARRAY_SIZE(st6422_bridge_init) && !err; i++) {
0194 err = stv06xx_write_bridge(sd, st6422_bridge_init[i][0],
0195 st6422_bridge_init[i][1]);
0196 }
0197
0198 return err;
0199 }
0200
0201 static int setbrightness(struct sd *sd, s32 val)
0202 {
0203
0204 return stv06xx_write_bridge(sd, 0x1432, val);
0205 }
0206
0207 static int setcontrast(struct sd *sd, s32 val)
0208 {
0209
0210 return stv06xx_write_bridge(sd, 0x143a, val | 0xf0);
0211 }
0212
0213 static int setgain(struct sd *sd, u8 gain)
0214 {
0215 int err;
0216
0217
0218 err = stv06xx_write_bridge(sd, 0x0509, gain);
0219 if (err < 0)
0220 return err;
0221
0222 err = stv06xx_write_bridge(sd, 0x050a, gain);
0223 if (err < 0)
0224 return err;
0225
0226 err = stv06xx_write_bridge(sd, 0x050b, gain);
0227 if (err < 0)
0228 return err;
0229
0230
0231 err = stv06xx_write_bridge(sd, 0x050c, 0x2a);
0232 if (err < 0)
0233 return err;
0234
0235 return stv06xx_write_bridge(sd, 0x050d, 0x01);
0236 }
0237
0238 static int setexposure(struct sd *sd, s16 expo)
0239 {
0240 int err;
0241
0242 err = stv06xx_write_bridge(sd, 0x143d, expo & 0xff);
0243 if (err < 0)
0244 return err;
0245
0246 return stv06xx_write_bridge(sd, 0x143e, expo >> 8);
0247 }
0248
0249 static int st6422_start(struct sd *sd)
0250 {
0251 int err;
0252 struct cam *cam = &sd->gspca_dev.cam;
0253
0254 if (cam->cam_mode[sd->gspca_dev.curr_mode].priv)
0255 err = stv06xx_write_bridge(sd, 0x1505, 0x0f);
0256 else
0257 err = stv06xx_write_bridge(sd, 0x1505, 0x02);
0258 if (err < 0)
0259 return err;
0260
0261
0262 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
0263 return (err < 0) ? err : 0;
0264 }
0265
0266 static int st6422_stop(struct sd *sd)
0267 {
0268 struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
0269
0270 gspca_dbg(gspca_dev, D_STREAM, "Halting stream\n");
0271
0272 return 0;
0273 }