^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * GSPCA Endpoints (formerly known as AOX) se401 USB Camera sub Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based on the v4l1 se401 driver which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (c) 2000 Jeroen B. Vreeken (pe1rxq@amsat.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define MODULE_NAME "se401"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define BULK_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define PACKET_SIZE 1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define READ_REQ_SIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define MAX_MODES ((READ_REQ_SIZE - 6) / 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* The se401 compression algorithm uses a fixed quant factor, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) can be configured by setting the high nibble of the SE401_OPERATINGMODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) feature. This needs to exactly match what is in libv4l! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define SE401_QUANT_FACT 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "gspca.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "se401.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) MODULE_DESCRIPTION("Endpoints se401");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* exposure change state machine states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) EXPO_CHANGED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) EXPO_DROP_FRAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) EXPO_NO_CHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* specific webcam descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct sd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct gspca_dev gspca_dev; /* !! must be the first item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct { /* exposure/freq control cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct v4l2_ctrl *exposure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct v4l2_ctrl *freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) bool has_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct v4l2_pix_format fmts[MAX_MODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int pixels_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int packet_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 packet[PACKET_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u8 restart_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u8 button_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u8 resetlevel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u8 resetlevel_frame_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int resetlevel_adjust_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int expo_change_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static void se401_write_req(struct gspca_dev *gspca_dev, u16 req, u16 value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (gspca_dev->usb_err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) err = usb_control_msg(gspca_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) usb_sndctrlpipe(gspca_dev->dev, 0), req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) value, 0, NULL, 0, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) pr_err("write req failed req %#04x val %#04x error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) req, value, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) gspca_dev->usb_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void se401_read_req(struct gspca_dev *gspca_dev, u16 req, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (gspca_dev->usb_err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (USB_BUF_SZ < READ_REQ_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) pr_err("USB_BUF_SZ too small!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) gspca_dev->usb_err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) err = usb_control_msg(gspca_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) usb_rcvctrlpipe(gspca_dev->dev, 0), req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) 0, 0, gspca_dev->usb_buf, READ_REQ_SIZE, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) pr_err("read req failed req %#04x error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) req, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) gspca_dev->usb_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * Make sure the buffer is zeroed to avoid uninitialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) memset(gspca_dev->usb_buf, 0, READ_REQ_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void se401_set_feature(struct gspca_dev *gspca_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u16 selector, u16 param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (gspca_dev->usb_err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) err = usb_control_msg(gspca_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) usb_sndctrlpipe(gspca_dev->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) SE401_REQ_SET_EXT_FEATURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) param, selector, NULL, 0, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) pr_err("set feature failed sel %#04x param %#04x error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) selector, param, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) gspca_dev->usb_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static int se401_get_feature(struct gspca_dev *gspca_dev, u16 selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (gspca_dev->usb_err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return gspca_dev->usb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (USB_BUF_SZ < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) pr_err("USB_BUF_SZ too small!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) gspca_dev->usb_err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return gspca_dev->usb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err = usb_control_msg(gspca_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) usb_rcvctrlpipe(gspca_dev->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) SE401_REQ_GET_EXT_FEATURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 0, selector, gspca_dev->usb_buf, 2, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) pr_err("get feature failed sel %#04x error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) selector, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) gspca_dev->usb_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return gspca_dev->usb_buf[0] | (gspca_dev->usb_buf[1] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* HDG: this does not seem to do anything on my cam */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) se401_write_req(gspca_dev, SE401_REQ_SET_BRT, val, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static void setgain(struct gspca_dev *gspca_dev, s32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) u16 gain = 63 - val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* red color gain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) se401_set_feature(gspca_dev, HV7131_REG_ARCG, gain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* green color gain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) se401_set_feature(gspca_dev, HV7131_REG_AGCG, gain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* blue color gain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) se401_set_feature(gspca_dev, HV7131_REG_ABCG, gain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static void setexposure(struct gspca_dev *gspca_dev, s32 val, s32 freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int integration = val << 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) u8 expose_h, expose_m, expose_l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* Do this before the set_feature calls, for proper timing wrt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) the interrupt driven pkt_scan. Note we may still race but that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) is not a big issue, the expo change state machine is merely for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) avoiding underexposed frames getting send out, if one sneaks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) through so be it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) sd->expo_change_state = EXPO_CHANGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (freq == V4L2_CID_POWER_LINE_FREQUENCY_50HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) integration = integration - integration % 106667;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (freq == V4L2_CID_POWER_LINE_FREQUENCY_60HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) integration = integration - integration % 88889;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) expose_h = (integration >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) expose_m = (integration >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) expose_l = integration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* integration time low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) se401_set_feature(gspca_dev, HV7131_REG_TITL, expose_l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* integration time mid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) se401_set_feature(gspca_dev, HV7131_REG_TITM, expose_m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* integration time high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) se401_set_feature(gspca_dev, HV7131_REG_TITU, expose_h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static int sd_config(struct gspca_dev *gspca_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct cam *cam = &gspca_dev->cam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) u8 *cd = gspca_dev->usb_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int i, j, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int widths[MAX_MODES], heights[MAX_MODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Read the camera descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) se401_read_req(gspca_dev, SE401_REQ_GET_CAMERA_DESCRIPTOR, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (gspca_dev->usb_err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* Sometimes after being idle for a while the se401 won't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) respond and needs a good kicking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) usb_reset_device(gspca_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) gspca_dev->usb_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) se401_read_req(gspca_dev, SE401_REQ_GET_CAMERA_DESCRIPTOR, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* Some cameras start with their LED on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (gspca_dev->usb_err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return gspca_dev->usb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (cd[1] != 0x41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) pr_err("Wrong descriptor type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (!(cd[2] & SE401_FORMAT_BAYER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) pr_err("Bayer format not supported!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (cd[3])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) pr_info("ExtraFeatures: %d\n", cd[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) n = cd[4] | (cd[5] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (n > MAX_MODES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) pr_err("Too many frame sizes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) for (i = 0; i < n ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) widths[i] = cd[6 + i * 4 + 0] | (cd[6 + i * 4 + 1] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) heights[i] = cd[6 + i * 4 + 2] | (cd[6 + i * 4 + 3] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) for (i = 0; i < n ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) sd->fmts[i].width = widths[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) sd->fmts[i].height = heights[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) sd->fmts[i].field = V4L2_FIELD_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) sd->fmts[i].colorspace = V4L2_COLORSPACE_SRGB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) sd->fmts[i].priv = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* janggu compression only works for 1/4th or 1/16th res */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) for (j = 0; j < n; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (widths[j] / 2 == widths[i] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) heights[j] / 2 == heights[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) sd->fmts[i].priv = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /* 1/16th if available too is better then 1/4th, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) we then use a larger area of the sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) for (j = 0; j < n; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (widths[j] / 4 == widths[i] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) heights[j] / 4 == heights[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) sd->fmts[i].priv = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (sd->fmts[i].priv == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* Not a 1/4th or 1/16th res, use bayer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) sd->fmts[i].pixelformat = V4L2_PIX_FMT_SBGGR8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) sd->fmts[i].bytesperline = widths[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) sd->fmts[i].sizeimage = widths[i] * heights[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) pr_info("Frame size: %dx%d bayer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) widths[i], heights[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* Found a match use janggu compression */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) sd->fmts[i].pixelformat = V4L2_PIX_FMT_SE401;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) sd->fmts[i].bytesperline = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) sd->fmts[i].sizeimage = widths[i] * heights[i] * 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) pr_info("Frame size: %dx%d 1/%dth janggu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) widths[i], heights[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) sd->fmts[i].priv * sd->fmts[i].priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) cam->cam_mode = sd->fmts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) cam->nmodes = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) cam->bulk = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) cam->bulk_size = BULK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) cam->bulk_nurbs = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) sd->resetlevel = 0x2d; /* Set initial resetlevel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* See if the camera supports brightness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) se401_read_req(gspca_dev, SE401_REQ_GET_BRT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) sd->has_brightness = !!gspca_dev->usb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) gspca_dev->usb_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /* this function is called at probe and resume time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int sd_init(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /* function called at start time before URB creation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static int sd_isoc_init(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) gspca_dev->alt = 1; /* Ignore the bogus isoc alt settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return gspca_dev->usb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /* -- start the camera -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static int sd_start(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) int mult = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (gspca_dev->usb_err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* Sometimes after being idle for a while the se401 won't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) respond and needs a good kicking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) usb_reset_device(gspca_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) gspca_dev->usb_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) se401_set_feature(gspca_dev, HV7131_REG_MODE_B, 0x05);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* set size + mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) se401_write_req(gspca_dev, SE401_REQ_SET_WIDTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) gspca_dev->pixfmt.width * mult, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) se401_write_req(gspca_dev, SE401_REQ_SET_HEIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) gspca_dev->pixfmt.height * mult, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * HDG: disabled this as it does not seem to do anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * se401_write_req(gspca_dev, SE401_REQ_SET_OUTPUT_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * SE401_FORMAT_BAYER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) switch (mult) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) case 1: /* Raw bayer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) mode = 0x03; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) case 2: /* 1/4th janggu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) mode = SE401_QUANT_FACT << 4; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) case 4: /* 1/16th janggu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) mode = (SE401_QUANT_FACT << 4) | 0x02; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) se401_set_feature(gspca_dev, SE401_OPERATINGMODE, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) se401_set_feature(gspca_dev, HV7131_REG_ARLV, sd->resetlevel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) sd->packet_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) sd->pixels_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) sd->restart_stream = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) sd->resetlevel_frame_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) sd->resetlevel_adjust_dir = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) sd->expo_change_state = EXPO_NO_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) se401_write_req(gspca_dev, SE401_REQ_START_CONTINUOUS_CAPTURE, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return gspca_dev->usb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static void sd_stopN(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) se401_write_req(gspca_dev, SE401_REQ_STOP_CONTINUOUS_CAPTURE, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) se401_write_req(gspca_dev, SE401_REQ_LED_CONTROL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) se401_write_req(gspca_dev, SE401_REQ_CAMERA_POWER, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static void sd_dq_callback(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) unsigned int ahrc, alrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) int oldreset, adjust_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* Restart the stream if requested do so by pkt_scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (sd->restart_stream) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) sd_stopN(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) sd_start(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) sd->restart_stream = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /* Automatically adjust sensor reset level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) Hyundai have some really nice docs about this and other sensor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) related stuff on their homepage: www.hei.co.kr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) sd->resetlevel_frame_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (sd->resetlevel_frame_count < 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /* For some reason this normally read-only register doesn't get reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) to zero after reading them just once... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) se401_get_feature(gspca_dev, HV7131_REG_HIREFNOH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) se401_get_feature(gspca_dev, HV7131_REG_HIREFNOL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) se401_get_feature(gspca_dev, HV7131_REG_LOREFNOH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) se401_get_feature(gspca_dev, HV7131_REG_LOREFNOL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ahrc = 256*se401_get_feature(gspca_dev, HV7131_REG_HIREFNOH) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) se401_get_feature(gspca_dev, HV7131_REG_HIREFNOL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) alrc = 256*se401_get_feature(gspca_dev, HV7131_REG_LOREFNOH) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) se401_get_feature(gspca_dev, HV7131_REG_LOREFNOL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* Not an exact science, but it seems to work pretty well... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) oldreset = sd->resetlevel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (alrc > 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) while (alrc >= 10 && sd->resetlevel < 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) sd->resetlevel++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) alrc /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) } else if (ahrc > 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) while (ahrc >= 20 && sd->resetlevel > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) sd->resetlevel--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) ahrc /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* Detect ping-pong-ing and halve adjustment to avoid overshoot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (sd->resetlevel > oldreset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) adjust_dir = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) adjust_dir = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (sd->resetlevel_adjust_dir &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) sd->resetlevel_adjust_dir != adjust_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) sd->resetlevel = oldreset + (sd->resetlevel - oldreset) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (sd->resetlevel != oldreset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) sd->resetlevel_adjust_dir = adjust_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) se401_set_feature(gspca_dev, HV7131_REG_ARLV, sd->resetlevel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) sd->resetlevel_frame_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static void sd_complete_frame(struct gspca_dev *gspca_dev, u8 *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) switch (sd->expo_change_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) case EXPO_CHANGED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* The exposure was changed while this frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) was being send, so this frame is ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) sd->expo_change_state = EXPO_DROP_FRAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) case EXPO_DROP_FRAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /* The exposure was changed while this frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) was being captured, drop it! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) gspca_dev->last_packet_type = DISCARD_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) sd->expo_change_state = EXPO_NO_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) case EXPO_NO_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) gspca_frame_add(gspca_dev, LAST_PACKET, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static void sd_pkt_scan_janggu(struct gspca_dev *gspca_dev, u8 *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) int imagesize = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) int i, plen, bits, pixels, info, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (sd->restart_stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* Sometimes a 1024 bytes garbage bulk packet is send between frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (gspca_dev->last_packet_type == LAST_PACKET && len == 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) gspca_dev->last_packet_type = DISCARD_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) while (i < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* Read header if not already be present from prev bulk pkt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (sd->packet_read < 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) count = 4 - sd->packet_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (count > len - i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) count = len - i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) memcpy(&sd->packet[sd->packet_read], &data[i], count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) sd->packet_read += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) i += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (sd->packet_read < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) bits = sd->packet[3] + (sd->packet[2] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) pixels = sd->packet[1] + ((sd->packet[0] & 0x3f) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) info = (sd->packet[0] & 0xc0) >> 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) plen = ((bits + 47) >> 4) << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /* Sanity checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (plen > 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) pr_err("invalid packet len %d restarting stream\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (info == 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) pr_err("unknown frame info value restarting stream\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /* Read (remainder of) packet contents */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) count = plen - sd->packet_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (count > len - i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) count = len - i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) memcpy(&sd->packet[sd->packet_read], &data[i], count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) sd->packet_read += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) i += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (sd->packet_read < plen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) sd->pixels_read += pixels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) sd->packet_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) switch (info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) case 0: /* Frame data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) gspca_frame_add(gspca_dev, INTER_PACKET, sd->packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) case 1: /* EOF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (sd->pixels_read != imagesize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) pr_err("frame size %d expected %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) sd->pixels_read, imagesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) sd_complete_frame(gspca_dev, sd->packet, plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) return; /* Discard the rest of the bulk packet !! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) case 2: /* SOF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) gspca_frame_add(gspca_dev, FIRST_PACKET, sd->packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) sd->pixels_read = pixels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) sd->restart_stream = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* Give userspace a 0 bytes frame, so our dq callback gets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) called and it can restart the stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static void sd_pkt_scan_bayer(struct gspca_dev *gspca_dev, u8 *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct cam *cam = &gspca_dev->cam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) int imagesize = cam->cam_mode[gspca_dev->curr_mode].sizeimage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (gspca_dev->image_len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (gspca_dev->image_len + len >= imagesize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) sd_complete_frame(gspca_dev, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static void sd_pkt_scan(struct gspca_dev *gspca_dev, u8 *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) int mult = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (mult == 1) /* mult == 1 means raw bayer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) sd_pkt_scan_bayer(gspca_dev, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) sd_pkt_scan_janggu(gspca_dev, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) #if IS_ENABLED(CONFIG_INPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, u8 *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) u8 state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (len != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) switch (data[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) state = data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (sd->button_state != state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) input_sync(gspca_dev->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) sd->button_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct gspca_dev *gspca_dev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) gspca_dev->usb_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (!gspca_dev->streaming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) switch (ctrl->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) case V4L2_CID_BRIGHTNESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) setbrightness(gspca_dev, ctrl->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) case V4L2_CID_GAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) setgain(gspca_dev, ctrl->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) case V4L2_CID_EXPOSURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) setexposure(gspca_dev, ctrl->val, sd->freq->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return gspca_dev->usb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) static const struct v4l2_ctrl_ops sd_ctrl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) .s_ctrl = sd_s_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static int sd_init_controls(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) gspca_dev->vdev.ctrl_handler = hdl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) v4l2_ctrl_handler_init(hdl, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (sd->has_brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) V4L2_CID_BRIGHTNESS, 0, 255, 1, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) /* max is really 63 but > 50 is not pretty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) V4L2_CID_GAIN, 0, 50, 1, 25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) sd->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) V4L2_CID_EXPOSURE, 0, 32767, 1, 15000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) V4L2_CID_POWER_LINE_FREQUENCY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if (hdl->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) pr_err("Could not initialize controls\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return hdl->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) v4l2_ctrl_cluster(2, &sd->exposure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) /* sub-driver description */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) static const struct sd_desc sd_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) .name = MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) .config = sd_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) .init = sd_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) .init_controls = sd_init_controls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) .isoc_init = sd_isoc_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) .start = sd_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) .stopN = sd_stopN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) .dq_callback = sd_dq_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) .pkt_scan = sd_pkt_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) #if IS_ENABLED(CONFIG_INPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) .int_pkt_scan = sd_int_pkt_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* -- module initialisation -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static const struct usb_device_id device_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {USB_DEVICE(0x03e8, 0x0004)}, /* Endpoints/Aox SE401 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) {USB_DEVICE(0x0471, 0x030b)}, /* Philips PCVC665K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) {USB_DEVICE(0x047d, 0x5001)}, /* Kensington 67014 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) {USB_DEVICE(0x047d, 0x5002)}, /* Kensington 6701(5/7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) {USB_DEVICE(0x047d, 0x5003)}, /* Kensington 67016 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) MODULE_DEVICE_TABLE(usb, device_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* -- device connect -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static int sd_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static int sd_pre_reset(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static int sd_post_reset(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) static struct usb_driver sd_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) .name = MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) .id_table = device_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) .probe = sd_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) .disconnect = gspca_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) .suspend = gspca_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) .resume = gspca_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) .reset_resume = gspca_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) .pre_reset = sd_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) .post_reset = sd_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) module_usb_driver(sd_driver);