// SPDX-License-Identifier: GPL-2.0-or-later /* * Pixart PAC7302 driver * * Copyright (C) 2008-2012 Jean-Francois Moine <http://moinejf.free.fr> * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li * * Separated from Pixart PAC7311 library by Márton Németh * Camera button input handling by Márton Németh <nm127@freemail.hu> * Copyright (C) 2009-2010 Márton Németh <nm127@freemail.hu>
*/
/* * Some documentation about various registers as determined by trial and error. * * Register page 0: * * Address Description * 0x01 Red balance control * 0x02 Green balance control * 0x03 Blue balance control * The Windows driver uses a quadratic approach to map * the settable values (0-200) on register values: * min=0x20, default=0x40, max=0x80 * 0x0f-0x20 Color and saturation control * 0xa2-0xab Brightness, contrast and gamma control * 0xb6 Sharpness control (bits 0-4) * * Register page 1: * * Address Description * 0x78 Global control, bit 6 controls the LED (inverted) * 0x80 Compression balance, 2 interesting settings: * 0x0f Default * 0x50 Values >= this switch the camera to a lower compression, * using the same table for both luminance and chrominance. * This gives a sharper picture. Only usable when running * at < 15 fps! 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 * * Register page 3: * * Address Description * 0x02 Clock divider 3-63, fps = 90 / val. Must be a multiple of 3 on * the 7302, so one of 3, 6, 9, ..., except when between 6 and 12? * 0x03 Variable framerate ctrl reg2==3: 0 -> ~30 fps, 255 -> ~22fps * 0x04 Another var framerate ctrl reg2==3, reg3==0: 0 -> ~30 fps, * 63 -> ~27 fps, the 2 msb's must always be 1 !! * 0x05 Another var framerate ctrl reg2==3, reg3==0, reg4==0xc0: * 1 -> ~30 fps, 2 -> ~20 fps * 0x0e Exposure bits 0-7, 0-448, 0 = use full frame time * 0x0f Exposure bit 8, 0-448, 448 = no exposure at all * 0x10 Gain 0-31 * 0x12 Another gain 0-31, unlike 0x10 this one seems to start with an * amplification value of 1 rather then 0 at its lowest setting * 0x21 Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused * 0x80 Another framerate control, best left at 1, moving it from 1 to * 2 causes the framerate to become 3/4th of what it was, and * also seems to cause pixel averaging, resulting in an effective * resolution of 320x240 and thus a much blockier image * * The registers are accessed in the following functions: * * Page | Register | Function * -----+------------+--------------------------------------------------- * 0 | 0x01 | setredbalance() * 0 | 0x03 | setbluebalance() * 0 | 0x0f..0x20 | setcolors() * 0 | 0xa2..0xab | setbrightcont() * 0 | 0xb6 | setsharpness() * 0 | 0xc6 | setwhitebalance() * 0 | 0xdc | setbrightcont(), setcolors() * 3 | 0x02 | setexposure() * 3 | 0x10, 0x12 | setgain() * 3 | 0x11 | setcolors(), setgain(), setexposure(), sethvflip() * 3 | 0x21 | sethvflip()
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/input.h> #include"gspca.h" /* Include pac common sof detection functions */ #include"pac_common.h"
MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>, Thomas Kaiser thomas@kaiser-linux.li");
MODULE_DESCRIPTION("Pixart PAC7302");
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_PAGE3:
reg_w_page(gspca_dev, page3, page3_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 pac7302 */ staticint sd_config(struct gspca_dev *gspca_dev, conststruct usb_device_id *id)
{ struct sd *sd = (struct sd *) gspca_dev; struct cam *cam;
cam = &gspca_dev->cam;
cam->cam_mode = vga_mode; /* only 640x480 */
cam->nmodes = ARRAY_SIZE(vga_mode);
/* * Register 2 of frame 3 contains the clock divider configuring the * no fps according to the formula: 90 / reg. sd->exposure is the * desired exposure time in 0.5 ms.
*/
clockdiv = (90 * gspca_dev->exposure->val + 1999) / 2000;
/* * Note clockdiv = 3 also works, but when running at 30 fps, depending * on the scene being recorded, the camera switches to another * quantization table for certain JPEG blocks, and we don't know how * to decompress these blocks. So we cap the framerate at 15 fps.
*/ if (clockdiv < 6)
clockdiv = 6; elseif (clockdiv > 63)
clockdiv = 63;
/* * Register 2 MUST be a multiple of 3, except when between 6 and 12? * Always round up, otherwise we cannot get the desired frametime * using the partial frame time exposure control.
*/ if (clockdiv < 6 || clockdiv > 12)
clockdiv = ((clockdiv + 2) / 3) * 3;
/* * frame exposure time in ms = 1000 * clockdiv / 90 -> * exposure = (sd->exposure / 2) * 448 / (1000 * clockdiv / 90)
*/
exposure = (gspca_dev->exposure->val * 45 * 448) / (1000 * clockdiv); /* 0 = use full frametime, 448 = no exposure, reverse it */
exposure = 448 - exposure;
/* this function is called at probe and resume time for pac7302 */ staticint sd_init(struct gspca_dev *gspca_dev)
{
reg_w_seq(gspca_dev, init_7302, sizeof(init_7302)/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 = PAC7302_EXPOSURE_DEFAULT;
gspca_dev->gain->val = PAC7302_GAIN_DEFAULT;
sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
}
if (!gspca_dev->streaming) return0;
switch (ctrl->id) { case V4L2_CID_BRIGHTNESS:
setbrightcont(gspca_dev); break; case V4L2_CID_SATURATION:
setcolors(gspca_dev); break; case V4L2_CID_WHITE_BALANCE_TEMPERATURE:
setwhitebalance(gspca_dev); break; case V4L2_CID_RED_BALANCE:
setredbalance(gspca_dev); break; case V4L2_CID_BLUE_BALANCE:
setbluebalance(gspca_dev); break; case V4L2_CID_AUTOGAIN: if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val))
setexposure(gspca_dev); if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val))
setgain(gspca_dev); break; case V4L2_CID_HFLIP:
sethvflip(gspca_dev); break; case V4L2_CID_SHARPNESS:
setsharpness(gspca_dev); 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;
/* called on streamoff with alt 0 and on disconnect for pac7302 */ staticvoid sd_stop0(struct gspca_dev *gspca_dev)
{ if (!gspca_dev->present) return;
reg_w(gspca_dev, 0xff, 0x01);
reg_w(gspca_dev, 0x78, 0x40);
}
/* 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;
u8 *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 = 61 + sizeof pac_sof_marker;
footer_length = 74;
/* 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]);
/* Start the new frame with the jpeg header */ /* The PAC7302 has the image rotated 90 degrees */
gspca_frame_add(gspca_dev, FIRST_PACKET,
jpeg_header, sizeof jpeg_header);
}
gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
}
/* * reg->reg: bit0..15: reserved for register index (wIndex is 16bit * long on the USB bus)
*/ if (reg->match.addr == 0 &&
(reg->reg < 0x000000ff) &&
(reg->val <= 0x000000ff)
) { /* Currently writing to page 0 is only supported. */ /* reg_w() only supports 8bit index */
index = reg->reg;
value = reg->val;
/* * Note that there shall be no access to other page * by any other function between the page switch and * the actual register write.
*/
reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
reg_w(gspca_dev, index, value);
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.