Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * STV0680 USB Camera Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2009 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)  * This module is adapted from the in kernel v4l1 stv680 driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  STV0680 USB Camera Driver, by Kevin Sisson (kjsisson@bellsouth.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Thanks to STMicroelectronics for information on the usb commands, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * to Steve Miller at STM for his help and encouragement while I was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * writing this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define MODULE_NAME "stv0680"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "gspca.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) MODULE_DESCRIPTION("STV0680 USB Camera Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* specific webcam descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct sd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct gspca_dev gspca_dev;		/* !! must be the first item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct v4l2_pix_format mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	u8 orig_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	u8 video_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	u8 current_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static int stv_sndctrl(struct gspca_dev *gspca_dev, int set, u8 req, u16 val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		       int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u8 req_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned int pipe = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	switch (set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	case 0: /*  0xc1  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		pipe = usb_rcvctrlpipe(gspca_dev->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	case 1: /*  0x41  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		req_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		pipe = usb_sndctrlpipe(gspca_dev->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	case 2:	/*  0x80  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		req_type = USB_DIR_IN | USB_RECIP_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		pipe = usb_rcvctrlpipe(gspca_dev->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	case 3:	/*  0x40  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		req_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		pipe = usb_sndctrlpipe(gspca_dev->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		break;
^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) 	ret = usb_control_msg(gspca_dev->dev, pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			      req, req_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			      val, 0, gspca_dev->usb_buf, size, 500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if ((ret < 0) && (req != 0x0a))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		pr_err("usb_control_msg error %i, request = 0x%x, error = %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		       set, req, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static int stv0680_handle_error(struct gspca_dev *gspca_dev, int ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	stv_sndctrl(gspca_dev, 0, 0x80, 0, 0x02); /* Get Last Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	gspca_err(gspca_dev, "last error: %i,  command = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		  gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static int stv0680_get_video_mode(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* Note not sure if this init of usb_buf is really necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	memset(gspca_dev->usb_buf, 0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	gspca_dev->usb_buf[0] = 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (stv_sndctrl(gspca_dev, 0, 0x87, 0, 0x08) != 0x08) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		gspca_err(gspca_dev, "Get_Camera_Mode failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return stv0680_handle_error(gspca_dev, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return gspca_dev->usb_buf[0]; /* 01 = VGA, 03 = QVGA, 00 = CIF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static int stv0680_set_video_mode(struct gspca_dev *gspca_dev, u8 mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (sd->current_mode == mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	memset(gspca_dev->usb_buf, 0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	gspca_dev->usb_buf[0] = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (stv_sndctrl(gspca_dev, 3, 0x07, 0x0100, 0x08) != 0x08) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		gspca_err(gspca_dev, "Set_Camera_Mode failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return stv0680_handle_error(gspca_dev, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	/* Verify we got what we've asked for */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (stv0680_get_video_mode(gspca_dev) != mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		gspca_err(gspca_dev, "Error setting camera video mode!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	sd->current_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* this function is called at probe time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int sd_config(struct gspca_dev *gspca_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct cam *cam = &gspca_dev->cam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/* Give the camera some time to settle, otherwise initialization will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	   fail on hotplug, and yes it really needs a full second. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* ping camera to be sure STV0680 is present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (stv_sndctrl(gspca_dev, 0, 0x88, 0x5678, 0x02) != 0x02 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	    gspca_dev->usb_buf[0] != 0x56 || gspca_dev->usb_buf[1] != 0x78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		gspca_err(gspca_dev, "STV(e): camera ping failed!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return stv0680_handle_error(gspca_dev, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	/* get camera descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (stv_sndctrl(gspca_dev, 2, 0x06, 0x0200, 0x09) != 0x09)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return stv0680_handle_error(gspca_dev, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (stv_sndctrl(gspca_dev, 2, 0x06, 0x0200, 0x22) != 0x22 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	    gspca_dev->usb_buf[7] != 0xa0 || gspca_dev->usb_buf[8] != 0x23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		gspca_err(gspca_dev, "Could not get descriptor 0200\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return stv0680_handle_error(gspca_dev, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (stv_sndctrl(gspca_dev, 0, 0x8a, 0, 0x02) != 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return stv0680_handle_error(gspca_dev, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (stv_sndctrl(gspca_dev, 0, 0x8b, 0, 0x24) != 0x24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return stv0680_handle_error(gspca_dev, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (stv_sndctrl(gspca_dev, 0, 0x85, 0, 0x10) != 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return stv0680_handle_error(gspca_dev, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (!(gspca_dev->usb_buf[7] & 0x09)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		gspca_err(gspca_dev, "Camera supports neither CIF nor QVGA mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (gspca_dev->usb_buf[7] & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		gspca_dbg(gspca_dev, D_PROBE, "Camera supports CIF mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (gspca_dev->usb_buf[7] & 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		gspca_dbg(gspca_dev, D_PROBE, "Camera supports VGA mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (gspca_dev->usb_buf[7] & 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		gspca_dbg(gspca_dev, D_PROBE, "Camera supports QCIF mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (gspca_dev->usb_buf[7] & 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		gspca_dbg(gspca_dev, D_PROBE, "Camera supports QVGA mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (gspca_dev->usb_buf[7] & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		sd->video_mode = 0x00; /* CIF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		sd->video_mode = 0x03; /* QVGA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	/* FW rev, ASIC rev, sensor ID  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	gspca_dbg(gspca_dev, D_PROBE, "Firmware rev is %i.%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		  gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	gspca_dbg(gspca_dev, D_PROBE, "ASIC rev is %i.%i",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		  gspca_dev->usb_buf[2], gspca_dev->usb_buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	gspca_dbg(gspca_dev, D_PROBE, "Sensor ID is %i",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		  (gspca_dev->usb_buf[4]*16) + (gspca_dev->usb_buf[5]>>4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	ret = stv0680_get_video_mode(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	sd->current_mode = sd->orig_mode = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	ret = stv0680_set_video_mode(gspca_dev, sd->video_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	/* Get mode details */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (stv_sndctrl(gspca_dev, 0, 0x8f, 0, 0x10) != 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return stv0680_handle_error(gspca_dev, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	cam->bulk = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	cam->bulk_nurbs = 1; /* The cam cannot handle more */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	cam->bulk_size = (gspca_dev->usb_buf[0] << 24) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			 (gspca_dev->usb_buf[1] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			 (gspca_dev->usb_buf[2] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			 (gspca_dev->usb_buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	sd->mode.width = (gspca_dev->usb_buf[4] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			 (gspca_dev->usb_buf[5]);  /* 322, 356, 644 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	sd->mode.height = (gspca_dev->usb_buf[6] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			  (gspca_dev->usb_buf[7]); /* 242, 292, 484 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	sd->mode.pixelformat = V4L2_PIX_FMT_STV0680;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	sd->mode.field = V4L2_FIELD_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	sd->mode.bytesperline = sd->mode.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	sd->mode.sizeimage = cam->bulk_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	sd->mode.colorspace = V4L2_COLORSPACE_SRGB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	/* origGain = gspca_dev->usb_buf[12]; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	cam->cam_mode = &sd->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	cam->nmodes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	ret = stv0680_set_video_mode(gspca_dev, sd->orig_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (stv_sndctrl(gspca_dev, 2, 0x06, 0x0100, 0x12) != 0x12 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	    gspca_dev->usb_buf[8] != 0x53 || gspca_dev->usb_buf[9] != 0x05) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		pr_err("Could not get descriptor 0100\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return stv0680_handle_error(gspca_dev, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* this function is called at probe and resume time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int sd_init(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	return 0;
^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) /* -- start the camera -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int sd_start(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	ret = stv0680_set_video_mode(gspca_dev, sd->video_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (stv_sndctrl(gspca_dev, 0, 0x85, 0, 0x10) != 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return stv0680_handle_error(gspca_dev, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/* Start stream at:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	   0x0000 = CIF (352x288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	   0x0100 = VGA (640x480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	   0x0300 = QVGA (320x240) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (stv_sndctrl(gspca_dev, 1, 0x09, sd->video_mode << 8, 0x0) != 0x0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return stv0680_handle_error(gspca_dev, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static void sd_stopN(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/* This is a high priority command; it stops all lower order cmds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (stv_sndctrl(gspca_dev, 1, 0x04, 0x0000, 0x0) != 0x0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		stv0680_handle_error(gspca_dev, -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static void sd_stop0(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!sd->gspca_dev.present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	stv0680_set_video_mode(gspca_dev, sd->orig_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static void sd_pkt_scan(struct gspca_dev *gspca_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	/* Every now and then the camera sends a 16 byte packet, no idea
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	   what it contains, but it is not image data, when this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	   happens the frame received before this packet is corrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	   so discard it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (len != sd->mode.sizeimage) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		gspca_dev->last_packet_type = DISCARD_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	/* Finish the previous frame, we do this upon reception of the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	   packet, even though it is already complete so that the strange 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	   byte packets send after a corrupt frame can discard it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	/* Store the just received frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* sub-driver description */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static const struct sd_desc sd_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	.name = MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	.config = sd_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	.init = sd_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	.start = sd_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	.stopN = sd_stopN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	.stop0 = sd_stop0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	.pkt_scan = sd_pkt_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* -- module initialisation -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static const struct usb_device_id device_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	{USB_DEVICE(0x0553, 0x0202)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	{USB_DEVICE(0x041e, 0x4007)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) MODULE_DEVICE_TABLE(usb, device_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /* -- device connect -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static int sd_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				THIS_MODULE);
^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) static struct usb_driver sd_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	.name = MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.id_table = device_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.probe = sd_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.disconnect = gspca_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.suspend = gspca_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.resume = gspca_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	.reset_resume = gspca_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) module_usb_driver(sd_driver);