// SPDX-License-Identifier: GPL-2.0-or-later /* * Pixart PAC7311 library * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li * * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
*/
/* Some documentation about various registers as determined by trial and error. * * Register page 1: * * Address Description * 0x08 Unknown compressor related, must always be 8 except when not * in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 ! * 0x1b Auto white balance related, bit 0 is AWB enable (inverted) * bits 345 seem to toggle per color gains on/off (inverted) * 0x78 Global control, bit 6 controls the LED (inverted) * 0x80 Compression balance, interesting settings: * 0x01 Use this to allow the camera to switch to higher compr. * on the fly. Needed to stay within bandwidth @ 640x480@30 * 0x1c From usb captures under Windows for 640x480 * 0x2a Values >= this switch the camera to a lower compression, * using the same table for both luminance and chrominance. * This gives a sharper picture. Usable only at 640x480@ < * 15 fps or 320x240 / 160x120. Note currently the driver * does not use this as the quality gain is small and the * generated JPG-s are only understood by v4l-utils >= 0.8.9 * 0x3f From usb captures under Windows for 320x240 * 0x69 From usb captures under Windows for 160x120 * * Register page 4: * * Address Description * 0x02 Clock divider 2-63, fps =~ 60 / val. Must be a multiple of 3 on * the 7302, so one of 3, 6, 9, ..., except when between 6 and 12? * 0x0f Master gain 1-245, low value = high gain * 0x10 Another gain 0-15, limited influence (1-2x gain I guess) * 0x21 Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused * Note setting vflip disabled leads to a much lower image quality, * so we always vflip, and tell userspace to flip it back * 0x27 Seems to toggle various gains on / off, Setting bit 7 seems to * completely disable the analog amplification block. Set to 0x68 * for max gain, 0x14 for minimal gain.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define MODULE_NAME "pac7311"
#include <linux/input.h> #include"gspca.h" /* Include pac common sof detection functions */ #include"pac_common.h"
#define PAC7311_GAIN_DEFAULT 122 #define PAC7311_EXPOSURE_DEFAULT 3/* 20 fps, avoid using high compr. */
MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li");
MODULE_DESCRIPTION("Pixart PAC7311");
MODULE_LICENSE("GPL");
struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */
for (;;) {
index = *seq++;
len = *seq++; switch (len) { case END_OF_SEQUENCE: return; case LOAD_PAGE4:
reg_w_page(gspca_dev, page4, page4_len); break; default: if (len > USB_BUF_SZ) {
gspca_err(gspca_dev, "Incorrect variable sequence\n"); return;
} while (len > 0) { if (len < 8) {
reg_w_buf(gspca_dev,
index, seq, len);
seq += len; break;
}
reg_w_buf(gspca_dev, index, seq, 8);
seq += 8;
index += 8;
len -= 8;
}
}
} /* not reached */
}
/* this function is called at probe time for pac7311 */ staticint sd_config(struct gspca_dev *gspca_dev, conststruct usb_device_id *id)
{ struct cam *cam = &gspca_dev->cam;
/* load registers to sensor (Bit 0, auto clear) */
reg_w(gspca_dev, 0x11, 0x01);
/* * Page 1 register 8 must always be 0x08 except when not in * 640x480 mode and page 4 reg 2 <= 3 then it must be 9
*/
reg_w(gspca_dev, 0xff, 0x01); if (gspca_dev->pixfmt.width != 640 && val <= 3)
reg_w(gspca_dev, 0x08, 0x09); else
reg_w(gspca_dev, 0x08, 0x08);
/* * Page1 register 80 sets the compression balance, normally we * want / use 0x1c, but for 640x480@30fps we must allow the * camera to use higher compression or we may run out of * bandwidth.
*/ if (gspca_dev->pixfmt.width == 640 && val == 2)
reg_w(gspca_dev, 0x80, 0x01); else
reg_w(gspca_dev, 0x80, 0x1c);
/* load registers to sensor (Bit 0, auto clear) */
reg_w(gspca_dev, 0x11, 0x01);
}
/* load registers to sensor (Bit 0, auto clear) */
reg_w(gspca_dev, 0x11, 0x01);
}
/* this function is called at probe and resume time for pac7311 */ staticint sd_init(struct gspca_dev *gspca_dev)
{
reg_w_seq(gspca_dev, init_7311, sizeof(init_7311)/2); return gspca_dev->usb_err;
}
if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) { /* when switching to autogain set defaults to make sure we are on a valid point of the autogain gain / exposure knee graph, and give this change time to
take effect before doing autogain. */
gspca_dev->exposure->val = PAC7311_EXPOSURE_DEFAULT;
gspca_dev->gain->val = PAC7311_GAIN_DEFAULT;
sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
}
if (!gspca_dev->streaming) return0;
switch (ctrl->id) { case V4L2_CID_CONTRAST:
setcontrast(gspca_dev, ctrl->val); break; case V4L2_CID_AUTOGAIN: if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val))
setexposure(gspca_dev, gspca_dev->exposure->val); if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val))
setgain(gspca_dev, gspca_dev->gain->val); break; case V4L2_CID_HFLIP:
sethvflip(gspca_dev, sd->hflip->val, 1); break; default: return -EINVAL;
} return gspca_dev->usb_err;
}
/* this function is called at probe time */ staticint sd_init_controls(struct gspca_dev *gspca_dev)
{ struct sd *sd = (struct sd *) gspca_dev; struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
/* this function is run at interrupt level */ staticvoid sd_pkt_scan(struct gspca_dev *gspca_dev,
u8 *data, /* isoc packet */ int len) /* iso packet length */
{ struct sd *sd = (struct sd *) gspca_dev;
u8 *image; unsignedchar *sof;
sof = pac_find_sof(gspca_dev, &sd->sof_read, data, len); if (sof) { int n, lum_offset, footer_length;
/* * 6 bytes after the FF D9 EOF marker a number of lumination * bytes are send corresponding to different parts of the * image, the 14th and 15th byte after the EOF seem to * correspond to the center of the image.
*/
lum_offset = 24 + sizeof pac_sof_marker;
footer_length = 26;
/* Get average lumination */ if (gspca_dev->last_packet_type == LAST_PACKET &&
n >= lum_offset)
atomic_set(&sd->avg_lum, data[-lum_offset] +
data[-lum_offset + 1]); else
atomic_set(&sd->avg_lum, -1);
/* Start the new frame with the jpeg header */
pac_start_frame(gspca_dev,
gspca_dev->pixfmt.height, gspca_dev->pixfmt.width);
}
gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
}
#if IS_ENABLED(CONFIG_INPUT) staticint sd_int_pkt_scan(struct gspca_dev *gspca_dev,
u8 *data, /* interrupt packet data */ int len) /* interrupt packet length */
{ int ret = -EINVAL;
u8 data0, data1;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.