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)  * Jeilin JL2005B/C/D library
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2011 Theodore Kilgore <kilgota@auburn.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define MODULE_NAME "jl2005bcd"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "gspca.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) MODULE_AUTHOR("Theodore Kilgore <kilgota@auburn.edu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) MODULE_DESCRIPTION("JL2005B/C/D USB Camera Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /* Default timeouts, in ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define JL2005C_CMD_TIMEOUT 500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define JL2005C_DATA_TIMEOUT 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* Maximum transfer size to use. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define JL2005C_MAX_TRANSFER 0x200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define FRAME_HEADER_LEN 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* specific webcam descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) struct sd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct gspca_dev gspca_dev;  /* !! must be the first item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	unsigned char firmware_id[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	const struct v4l2_pix_format *cap_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* Driver stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct work_struct work_struct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	u8 frame_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int block_size;	/* block size of camera */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int vga;	/* 1 if vga cam, 0 if cif cam */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) };
^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) /* Camera has two resolution settings. What they are depends on model. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static const struct v4l2_pix_format cif_mode[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	{176, 144, V4L2_PIX_FMT_JL2005BCD, V4L2_FIELD_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		.bytesperline = 176,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		.sizeimage = 176 * 144,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		.colorspace = V4L2_COLORSPACE_SRGB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		.priv = 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	{352, 288, V4L2_PIX_FMT_JL2005BCD, V4L2_FIELD_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		.bytesperline = 352,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		.sizeimage = 352 * 288,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		.colorspace = V4L2_COLORSPACE_SRGB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		.priv = 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static const struct v4l2_pix_format vga_mode[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	{320, 240, V4L2_PIX_FMT_JL2005BCD, V4L2_FIELD_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		.bytesperline = 320,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		.sizeimage = 320 * 240,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		.colorspace = V4L2_COLORSPACE_SRGB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		.priv = 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	{640, 480, V4L2_PIX_FMT_JL2005BCD, V4L2_FIELD_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		.bytesperline = 640,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		.sizeimage = 640 * 480,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		.colorspace = V4L2_COLORSPACE_SRGB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		.priv = 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * cam uses endpoint 0x03 to send commands, 0x84 for read commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * and 0x82 for bulk data transfer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /* All commands are two bytes only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int jl2005c_write2(struct gspca_dev *gspca_dev, unsigned char *command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	memcpy(gspca_dev->usb_buf, command, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	retval = usb_bulk_msg(gspca_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			usb_sndbulkpipe(gspca_dev->dev, 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			gspca_dev->usb_buf, 2, NULL, 500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		pr_err("command write [%02x] error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		       gspca_dev->usb_buf[0], retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) /* Response to a command is one byte in usb_buf[0], only if requested. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int jl2005c_read1(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	retval = usb_bulk_msg(gspca_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 				usb_rcvbulkpipe(gspca_dev->dev, 0x84),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				gspca_dev->usb_buf, 1, NULL, 500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		pr_err("read command [0x%02x] error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		       gspca_dev->usb_buf[0], retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* Response appears in gspca_dev->usb_buf[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int jl2005c_read_reg(struct gspca_dev *gspca_dev, unsigned char reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	static u8 instruction[2] = {0x95, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* put register to read in byte 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	instruction[1] = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* Send the read request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	retval = jl2005c_write2(gspca_dev, instruction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	retval = jl2005c_read1(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int jl2005c_start_new_frame(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int frame_brightness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	static u8 instruction[2] = {0x7f, 0x01};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	retval = jl2005c_write2(gspca_dev, instruction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	while (i < 20 && !frame_brightness) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		/* If we tried 20 times, give up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		retval = jl2005c_read_reg(gspca_dev, 0x7e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		frame_brightness = gspca_dev->usb_buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		retval = jl2005c_read_reg(gspca_dev, 0x7d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	gspca_dbg(gspca_dev, D_FRAM, "frame_brightness is 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		  gspca_dev->usb_buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static int jl2005c_write_reg(struct gspca_dev *gspca_dev, unsigned char reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 						    unsigned char value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	u8 instruction[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	instruction[0] = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	instruction[1] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	retval = jl2005c_write2(gspca_dev, instruction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int jl2005c_get_firmware_id(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct sd *sd = (struct sd *)gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	unsigned char regs_to_read[] = {0x57, 0x02, 0x03, 0x5d, 0x5e, 0x5f};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	gspca_dbg(gspca_dev, D_PROBE, "Running jl2005c_get_firmware_id\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/* Read the first ID byte once for warmup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	retval = jl2005c_read_reg(gspca_dev, regs_to_read[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	gspca_dbg(gspca_dev, D_PROBE, "response is %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		  gspca_dev->usb_buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* Now actually get the ID string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	for (i = 0; i < 6; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		retval = jl2005c_read_reg(gspca_dev, regs_to_read[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		sd->firmware_id[i] = gspca_dev->usb_buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	gspca_dbg(gspca_dev, D_PROBE, "firmware ID is %02x%02x%02x%02x%02x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		  sd->firmware_id[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		  sd->firmware_id[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		  sd->firmware_id[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		  sd->firmware_id[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		  sd->firmware_id[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		  sd->firmware_id[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static int jl2005c_stream_start_vga_lg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		    (struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int retval = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	static u8 instruction[][2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		{0x05, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		{0x7c, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		{0x7d, 0x18},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		{0x02, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		{0x01, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		{0x04, 0x52},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	for (i = 0; i < ARRAY_SIZE(instruction); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		retval = jl2005c_write2(gspca_dev, instruction[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int jl2005c_stream_start_vga_small(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	int retval = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	static u8 instruction[][2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		{0x06, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		{0x7c, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		{0x7d, 0x1a},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		{0x02, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		{0x01, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		{0x04, 0x52},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	for (i = 0; i < ARRAY_SIZE(instruction); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		retval = jl2005c_write2(gspca_dev, instruction[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int jl2005c_stream_start_cif_lg(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	int retval = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	static u8 instruction[][2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		{0x05, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		{0x7c, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		{0x7d, 0x30},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		{0x02, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		{0x01, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		{0x04, 0x42},
^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 < ARRAY_SIZE(instruction); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		retval = jl2005c_write2(gspca_dev, instruction[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static int jl2005c_stream_start_cif_small(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	int retval = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	static u8 instruction[][2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		{0x06, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		{0x7c, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		{0x7d, 0x32},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		{0x02, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		{0x01, 0x00},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		{0x04, 0x42},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	for (i = 0; i < ARRAY_SIZE(instruction); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		retval = jl2005c_write2(gspca_dev, instruction[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	msleep(60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int jl2005c_stop(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	return jl2005c_write_reg(gspca_dev, 0x07, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * This function is called as a workqueue function and runs whenever the camera
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * is streaming data. Because it is a workqueue function it is allowed to sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  * so we can use synchronous USB calls. To avoid possible collisions with other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * threads attempting to use gspca_dev->usb_buf we take the usb_lock when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * performing USB operations using it. In practice we don't really need this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * as the camera doesn't provide any controls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static void jl2005c_dostream(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct sd *dev = container_of(work, struct sd, work_struct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct gspca_dev *gspca_dev = &dev->gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	int bytes_left = 0; /* bytes remaining in current frame. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	int data_len;   /* size to use for the next read. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	int header_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	unsigned char header_sig[2] = {0x4a, 0x4c};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	int act_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	int packet_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	u8 *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	buffer = kmalloc(JL2005C_MAX_TRANSFER, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		pr_err("Couldn't allocate USB buffer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		goto quit_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	while (gspca_dev->present && gspca_dev->streaming) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		if (gspca_dev->frozen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		/* Check if this is a new frame. If so, start the frame first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		if (!header_read) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			mutex_lock(&gspca_dev->usb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			ret = jl2005c_start_new_frame(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			mutex_unlock(&gspca_dev->usb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				goto quit_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			ret = usb_bulk_msg(gspca_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				usb_rcvbulkpipe(gspca_dev->dev, 0x82),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				buffer, JL2005C_MAX_TRANSFER, &act_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 				JL2005C_DATA_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			gspca_dbg(gspca_dev, D_PACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 				  "Got %d bytes out of %d for header\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 				  act_len, JL2005C_MAX_TRANSFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			if (ret < 0 || act_len < JL2005C_MAX_TRANSFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				goto quit_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			/* Check whether we actually got the first blodk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			if (memcmp(header_sig, buffer, 2) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				pr_err("First block is not the first block\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 				goto quit_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			/* total size to fetch is byte 7, times blocksize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			 * of which we already got act_len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			bytes_left = buffer[0x07] * dev->block_size - act_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			gspca_dbg(gspca_dev, D_PACK, "bytes_left = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 				  bytes_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			/* We keep the header. It has other information, too.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			packet_type = FIRST_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			gspca_frame_add(gspca_dev, packet_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 					buffer, act_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			header_read = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		while (bytes_left > 0 && gspca_dev->present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			data_len = bytes_left > JL2005C_MAX_TRANSFER ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 				JL2005C_MAX_TRANSFER : bytes_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			ret = usb_bulk_msg(gspca_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				usb_rcvbulkpipe(gspca_dev->dev, 0x82),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 				buffer, data_len, &act_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 				JL2005C_DATA_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			if (ret < 0 || act_len < data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				goto quit_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			gspca_dbg(gspca_dev, D_PACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 				  "Got %d bytes out of %d for frame\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 				  data_len, bytes_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			bytes_left -= data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			if (bytes_left == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 				packet_type = LAST_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 				header_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				packet_type = INTER_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			gspca_frame_add(gspca_dev, packet_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 					buffer, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) quit_stream:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (gspca_dev->present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		mutex_lock(&gspca_dev->usb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		jl2005c_stop(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		mutex_unlock(&gspca_dev->usb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* This function is called at probe time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static int sd_config(struct gspca_dev *gspca_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	struct cam *cam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	cam = &gspca_dev->cam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	/* We don't use the buffer gspca allocates so make it small. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	cam->bulk_size = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	cam->bulk = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	/* For the rest, the camera needs to be detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	jl2005c_get_firmware_id(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	/* Here are some known firmware IDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	 * First some JL2005B cameras
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	 * {0x41, 0x07, 0x04, 0x2c, 0xe8, 0xf2}	Sakar KidzCam
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	 * {0x45, 0x02, 0x08, 0xb9, 0x00, 0xd2}	No-name JL2005B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	 * JL2005C cameras
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	 * {0x01, 0x0c, 0x16, 0x10, 0xf8, 0xc8}	Argus DC-1512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	 * {0x12, 0x04, 0x03, 0xc0, 0x00, 0xd8}	ICarly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 * {0x86, 0x08, 0x05, 0x02, 0x00, 0xd4}	Jazz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	 * Based upon this scanty evidence, we can detect a CIF camera by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	 * testing byte 0 for 0x4x.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if ((sd->firmware_id[0] & 0xf0) == 0x40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		cam->cam_mode	= cif_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		cam->nmodes	= ARRAY_SIZE(cif_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		sd->block_size	= 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		cam->cam_mode	= vga_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		cam->nmodes	= ARRAY_SIZE(vga_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		sd->block_size	= 0x200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	INIT_WORK(&sd->work_struct, jl2005c_dostream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return 0;
^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) /* this function is called at probe and resume time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static int sd_init(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static int sd_start(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	struct sd *sd = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	sd->cap_mode = gspca_dev->cam.cam_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	switch (gspca_dev->pixfmt.width) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	case 640:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		gspca_dbg(gspca_dev, D_STREAM, "Start streaming at vga resolution\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		jl2005c_stream_start_vga_lg(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	case 320:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		gspca_dbg(gspca_dev, D_STREAM, "Start streaming at qvga resolution\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		jl2005c_stream_start_vga_small(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	case 352:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		gspca_dbg(gspca_dev, D_STREAM, "Start streaming at cif resolution\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		jl2005c_stream_start_cif_lg(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	case 176:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		gspca_dbg(gspca_dev, D_STREAM, "Start streaming at qcif resolution\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		jl2005c_stream_start_cif_small(gspca_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		pr_err("Unknown resolution specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	schedule_work(&sd->work_struct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	return 0;
^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) /* called on streamoff with alt==0 and on disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /* the usb_lock is held at entry - restore on exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static void sd_stop0(struct gspca_dev *gspca_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	struct sd *dev = (struct sd *) gspca_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	/* wait for the work queue to terminate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	mutex_unlock(&gspca_dev->usb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	/* This waits for sq905c_dostream to finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	flush_work(&dev->work_struct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	mutex_lock(&gspca_dev->usb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^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) /* sub-driver description */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static const struct sd_desc sd_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	.name = MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	.config = sd_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	.init = sd_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	.start = sd_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	.stop0 = sd_stop0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /* -- module initialisation -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) static const struct usb_device_id device_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	{USB_DEVICE(0x0979, 0x0227)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) MODULE_DEVICE_TABLE(usb, device_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /* -- device connect -- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) static int sd_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 				const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 				THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static struct usb_driver sd_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	.name = MODULE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	.id_table = device_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	.probe = sd_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	.disconnect = gspca_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	.suspend = gspca_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	.resume = gspca_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	.reset_resume = gspca_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) module_usb_driver(sd_driver);