drivers/media/usb/gspca/sn9c2028.c

Source file repositories/reference/linux-study-clean/drivers/media/usb/gspca/sn9c2028.c

File Facts

System
Linux kernel
Corpus path
drivers/media/usb/gspca/sn9c2028.c
Extension
.c
Size
31928 bytes
Lines
964
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct sd {
	struct gspca_dev gspca_dev;  /* !! must be the first item */
	u8 sof_read;
	u16 model;

#define MIN_AVG_LUM 8500
#define MAX_AVG_LUM 10000
	int avg_lum;
	u8 avg_lum_l;

	struct { /* autogain and gain control cluster */
		struct v4l2_ctrl *autogain;
		struct v4l2_ctrl *gain;
	};
};

struct init_command {
	unsigned char instruction[6];
	unsigned char to_read; /* length to read. 0 means no reply requested */
};

/* How to change the resolution of any of the VGA cams is unknown */
static const struct v4l2_pix_format vga_mode[] = {
	{640, 480, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
		.bytesperline = 640,
		.sizeimage = 640 * 480 * 3 / 4,
		.colorspace = V4L2_COLORSPACE_SRGB,
		.priv = 0},
};

/* No way to change the resolution of the CIF cams is known */
static const struct v4l2_pix_format cif_mode[] = {
	{352, 288, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
		.bytesperline = 352,
		.sizeimage = 352 * 288 * 3 / 4,
		.colorspace = V4L2_COLORSPACE_SRGB,
		.priv = 0},
};

/* the bytes to write are in gspca_dev->usb_buf */
static int sn9c2028_command(struct gspca_dev *gspca_dev, u8 *command)
{
	int rc;

	gspca_dbg(gspca_dev, D_USBO, "sending command %02x%02x%02x%02x%02x%02x\n",
		  command[0], command[1], command[2],
		  command[3], command[4], command[5]);

	memcpy(gspca_dev->usb_buf, command, 6);
	rc = usb_control_msg(gspca_dev->dev,
			usb_sndctrlpipe(gspca_dev->dev, 0),
			USB_REQ_GET_CONFIGURATION,
			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
			2, 0, gspca_dev->usb_buf, 6, 500);
	if (rc < 0) {
		pr_err("command write [%02x] error %d\n",
		       gspca_dev->usb_buf[0], rc);
		return rc;
	}

	return 0;
}

static int sn9c2028_read1(struct gspca_dev *gspca_dev)
{
	int rc;

	rc = usb_control_msg(gspca_dev->dev,
			usb_rcvctrlpipe(gspca_dev->dev, 0),
			USB_REQ_GET_STATUS,
			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
			1, 0, gspca_dev->usb_buf, 1, 500);
	if (rc != 1) {
		pr_err("read1 error %d\n", rc);
		return (rc < 0) ? rc : -EIO;
	}
	gspca_dbg(gspca_dev, D_USBI, "read1 response %02x\n",
		  gspca_dev->usb_buf[0]);
	return gspca_dev->usb_buf[0];
}

static int sn9c2028_read4(struct gspca_dev *gspca_dev, u8 *reading)
{
	int rc;
	rc = usb_control_msg(gspca_dev->dev,
			usb_rcvctrlpipe(gspca_dev->dev, 0),
			USB_REQ_GET_STATUS,
			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
			4, 0, gspca_dev->usb_buf, 4, 500);
	if (rc != 4) {

Annotation

Implementation Notes