drivers/media/usb/gspca/stk1135.c

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

File Facts

System
Linux kernel
Corpus path
drivers/media/usb/gspca/stk1135.c
Extension
.c
Size
19551 bytes
Lines
677
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 pkt_seq;
	u8 sensor_page;

	bool flip_status;
	u8 flip_debounce;

	struct v4l2_ctrl *hflip;
	struct v4l2_ctrl *vflip;
};

static const struct v4l2_pix_format stk1135_modes[] = {
	/* default mode (this driver supports variable resolution) */
	{640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
		.bytesperline = 640,
		.sizeimage = 640 * 480,
		.colorspace = V4L2_COLORSPACE_SRGB},
};

/* -- read a register -- */
static u8 reg_r(struct gspca_dev *gspca_dev, u16 index)
{
	struct usb_device *dev = gspca_dev->dev;
	int ret;

	if (gspca_dev->usb_err < 0)
		return 0;
	ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
			0x00,
			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
			0x00,
			index,
			gspca_dev->usb_buf, 1,
			500);

	gspca_dbg(gspca_dev, D_USBI, "reg_r 0x%x=0x%02x\n",
		  index, gspca_dev->usb_buf[0]);
	if (ret < 0) {
		pr_err("reg_r 0x%x err %d\n", index, ret);
		gspca_dev->usb_err = ret;
		return 0;
	}

	return gspca_dev->usb_buf[0];
}

/* -- write a register -- */
static void reg_w(struct gspca_dev *gspca_dev, u16 index, u8 val)
{
	int ret;
	struct usb_device *dev = gspca_dev->dev;

	if (gspca_dev->usb_err < 0)
		return;
	ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
			0x01,
			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
			val,
			index,
			NULL,
			0,
			500);
	gspca_dbg(gspca_dev, D_USBO, "reg_w 0x%x:=0x%02x\n", index, val);
	if (ret < 0) {
		pr_err("reg_w 0x%x err %d\n", index, ret);
		gspca_dev->usb_err = ret;
	}
}

static void reg_w_mask(struct gspca_dev *gspca_dev, u16 index, u8 val, u8 mask)
{
	val = (reg_r(gspca_dev, index) & ~mask) | (val & mask);
	reg_w(gspca_dev, index, val);
}

/* this function is called at probe time */
static int sd_config(struct gspca_dev *gspca_dev,
			const struct usb_device_id *id)
{
	gspca_dev->cam.cam_mode = stk1135_modes;
	gspca_dev->cam.nmodes = ARRAY_SIZE(stk1135_modes);
	return 0;
}

static int stk1135_serial_wait_ready(struct gspca_dev *gspca_dev)
{
	int i = 0;
	u8 val;

Annotation

Implementation Notes