Changes in 4.9.218 spi: qup: call spi_qup_pm_resume_runtime before suspending powerpc: Include .BTF section ARM: dts: dra7: Add "dma-ranges" property to PCIe RC DT nodes spi/zynqmp: remove entry that causes a cs glitch drm/exynos: dsi: propagate error value and silence meaningless warning drm/exynos: dsi: fix workaround for the legacy clock name altera-stapl: altera_get_note: prevent write beyond end of 'key' USB: Disable LPM on WD19's Realtek Hub usb: quirks: add NO_LPM quirk for RTL8153 based ethernet adapters USB: serial: option: add ME910G1 ECM composition 0x110b usb: host: xhci-plat: add a shutdown USB: serial: pl2303: add device-id for HP LD381 ALSA: line6: Fix endless MIDI read loop ALSA: seq: virmidi: Fix running status after receiving sysex ALSA: seq: oss: Fix running status after receiving sysex ALSA: pcm: oss: Avoid plugin buffer overflow ALSA: pcm: oss: Remove WARNING from snd_pcm_plug_alloc() checks iio: magnetometer: ak8974: Fix negative raw values in sysfs mmc: sdhci-of-at91: fix cd-gpios for SAMA5D2 staging: rtl8188eu: Add device id for MERCUSYS MW150US v2 staging/speakup: fix get_word non-space look-ahead intel_th: Fix user-visible error codes rtc: max8907: add missing select REGMAP_IRQ memcg: fix NULL pointer dereference in __mem_cgroup_usage_unregister_event mm: slub: be more careful about the double cmpxchg of freelist mm, slub: prevent kmalloc_node crashes and memory leaks x86/mm: split vmalloc_sync_all() USB: cdc-acm: fix close_delay and closing_wait units in TIOCSSERIAL USB: cdc-acm: fix rounding error in TIOCSSERIAL kbuild: Disable -Wpointer-to-enum-cast futex: Fix inode life-time issue futex: Unbreak futex hashing ALSA: hda/realtek: Fix pop noise on ALC225 arm64: smp: fix smp_send_stop() behaviour staging: greybus: loopback_test: fix potential path truncation staging: greybus: loopback_test: fix potential path truncations Revert "drm/dp_mst: Skip validating ports during destruction, just ref" hsr: fix general protection fault in hsr_addr_is_self() macsec: restrict to ethernet devices net: dsa: Fix duplicate frames flooded by learning net_sched: cls_route: remove the right filter from hashtable net_sched: keep alloc_hash updated after hash allocation NFC: fdp: Fix a signedness bug in fdp_nci_send_patch() slcan: not call free_netdev before rtnl_unlock in slcan_open vxlan: check return value of gro_cells_init() net: mvneta: Fix the case where the last poll did not process all rx hsr: use rcu_read_lock() in hsr_get_node_{list/status}() hsr: add restart routine into hsr_get_node_list() hsr: set .netnsok flag KVM: VMX: Do not allow reexecute_instruction() when skipping MMIO instr net: ipv4: don't let PMTU updates increase route MTU cpupower: avoid multiple definition with gcc -fno-common dt-bindings: net: FMan erratum A050385 scsi: ipr: Fix softlockup when rescanning devices in petitboot mac80211: Do not send mesh HWMP PREQ if HWMP is disabled sxgbe: Fix off by one in samsung driver strncpy size arg i2c: hix5hd2: add missed clk_disable_unprepare in remove ARM: dts: dra7: Add bus_dma_limit for L3 bus ARM: dts: omap5: Add bus_dma_limit for L3 bus perf probe: Do not depend on dwfl_module_addrsym() scripts/dtc: Remove redundant YYLOC global declaration scsi: sd: Fix optimal I/O size for devices that change reported values mac80211: mark station unauthorized before key removal genirq: Fix reference leaks on irq affinity notifiers vti[6]: fix packet tx through bpf_redirect() in XinY cases xfrm: fix uctx len check in verify_sec_ctx_len xfrm: add the missing verify_sec_ctx_len check in xfrm_add_acquire xfrm: policy: Fix doulbe free in xfrm_policy_timer netfilter: nft_fwd_netdev: validate family and chain type vti6: Fix memory leak of skb if input policy check fails Input: raydium_i2c_ts - use true and false for boolean values Input: raydium_i2c_ts - fix error codes in raydium_i2c_boot_trigger() tools: Let O= makes handle a relative path with -C option USB: serial: option: add support for ASKEY WWHC050 USB: serial: option: add BroadMobi BM806U USB: serial: option: add Wistron Neweb D19Q1 USB: cdc-acm: restore capability check order USB: serial: io_edgeport: fix slab-out-of-bounds read in edge_interrupt_callback usb: musb: fix crash with highmen PIO and usbmon media: flexcop-usb: fix endpoint sanity check media: usbtv: fix control-message timeouts staging: rtl8188eu: Add ASUS USB-N10 Nano B1 to device table staging: wlan-ng: fix ODEBUG bug in prism2sta_disconnect_usb staging: wlan-ng: fix use-after-free Read in hfa384x_usbin_callback libfs: fix infoleak in simple_attr_read() media: ov519: add missing endpoint sanity checks media: dib0700: fix rc endpoint lookup media: stv06xx: add missing descriptor sanity checks media: xirlink_cit: add missing descriptor sanity checks mac80211: Check port authorization in the ieee80211_tx_dequeue() case mac80211: fix authentication with iwlwifi/mvm vt: selection, introduce vc_is_sel vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines vt: switch vt_dont_switch to bool vt: vt_ioctl: remove unnecessary console allocation checks vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console locking/atomic, kref: Add kref_read() vt: vt_ioctl: fix use-after-free in vt_in_use() bpf: Explicitly memset the bpf_attr structure net: ks8851-ml: Fix IO operations, again arm64: alternative: fix build with clang integrated assembler perf map: Fix off by one in strncpy() size argument Linux 4.9.218 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I93ee241fe88658b93a22ab85752e8aa9883f6f98
441 lines
12 KiB
C
441 lines
12 KiB
C
/*
|
|
* Copyright (c) 2001 Jean-Fredric Clere, Nikolas Zimmermann, Georg Acher
|
|
* Mark Cave-Ayland, Carlo E Prelz, Dick Streefland
|
|
* Copyright (c) 2002, 2003 Tuukka Toivonen
|
|
* Copyright (c) 2008 Erik Andrén
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
* P/N 861037: Sensor HDCS1000 ASIC STV0600
|
|
* P/N 861050-0010: Sensor HDCS1000 ASIC STV0600
|
|
* P/N 861050-0020: Sensor Photobit PB100 ASIC STV0600-1 - QuickCam Express
|
|
* P/N 861055: Sensor ST VV6410 ASIC STV0610 - LEGO cam
|
|
* P/N 861075-0040: Sensor HDCS1000 ASIC
|
|
* P/N 961179-0700: Sensor ST VV6410 ASIC STV0602 - Dexxa WebCam USB
|
|
* P/N 861040-0000: Sensor ST VV6410 ASIC STV0610 - QuickCam Web
|
|
*/
|
|
|
|
/*
|
|
* The spec file for the PB-0100 suggests the following for best quality
|
|
* images after the sensor has been reset :
|
|
*
|
|
* PB_ADCGAINL = R60 = 0x03 (3 dec) : sets low reference of ADC
|
|
to produce good black level
|
|
* PB_PREADCTRL = R32 = 0x1400 (5120 dec) : Enables global gain changes
|
|
through R53
|
|
* PB_ADCMINGAIN = R52 = 0x10 (16 dec) : Sets the minimum gain for
|
|
auto-exposure
|
|
* PB_ADCGLOBALGAIN = R53 = 0x10 (16 dec) : Sets the global gain
|
|
* PB_EXPGAIN = R14 = 0x11 (17 dec) : Sets the auto-exposure value
|
|
* PB_UPDATEINT = R23 = 0x02 (2 dec) : Sets the speed on
|
|
auto-exposure routine
|
|
* PB_CFILLIN = R5 = 0x0E (14 dec) : Sets the frame rate
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include "stv06xx_pb0100.h"
|
|
|
|
struct pb0100_ctrls {
|
|
struct { /* one big happy control cluster... */
|
|
struct v4l2_ctrl *autogain;
|
|
struct v4l2_ctrl *gain;
|
|
struct v4l2_ctrl *exposure;
|
|
struct v4l2_ctrl *red;
|
|
struct v4l2_ctrl *blue;
|
|
struct v4l2_ctrl *natural;
|
|
};
|
|
struct v4l2_ctrl *target;
|
|
};
|
|
|
|
static struct v4l2_pix_format pb0100_mode[] = {
|
|
/* low res / subsample modes disabled as they are only half res horizontal,
|
|
halving the vertical resolution does not seem to work */
|
|
{
|
|
320,
|
|
240,
|
|
V4L2_PIX_FMT_SGRBG8,
|
|
V4L2_FIELD_NONE,
|
|
.sizeimage = 320 * 240,
|
|
.bytesperline = 320,
|
|
.colorspace = V4L2_COLORSPACE_SRGB,
|
|
.priv = PB0100_CROP_TO_VGA
|
|
},
|
|
{
|
|
352,
|
|
288,
|
|
V4L2_PIX_FMT_SGRBG8,
|
|
V4L2_FIELD_NONE,
|
|
.sizeimage = 352 * 288,
|
|
.bytesperline = 352,
|
|
.colorspace = V4L2_COLORSPACE_SRGB,
|
|
.priv = 0
|
|
}
|
|
};
|
|
|
|
static int pb0100_s_ctrl(struct v4l2_ctrl *ctrl)
|
|
{
|
|
struct gspca_dev *gspca_dev =
|
|
container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
|
|
struct sd *sd = (struct sd *)gspca_dev;
|
|
struct pb0100_ctrls *ctrls = sd->sensor_priv;
|
|
int err = -EINVAL;
|
|
|
|
switch (ctrl->id) {
|
|
case V4L2_CID_AUTOGAIN:
|
|
err = pb0100_set_autogain(gspca_dev, ctrl->val);
|
|
if (err)
|
|
break;
|
|
if (ctrl->val)
|
|
break;
|
|
err = pb0100_set_gain(gspca_dev, ctrls->gain->val);
|
|
if (err)
|
|
break;
|
|
err = pb0100_set_exposure(gspca_dev, ctrls->exposure->val);
|
|
break;
|
|
case V4L2_CTRL_CLASS_USER + 0x1001:
|
|
err = pb0100_set_autogain_target(gspca_dev, ctrl->val);
|
|
break;
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static const struct v4l2_ctrl_ops pb0100_ctrl_ops = {
|
|
.s_ctrl = pb0100_s_ctrl,
|
|
};
|
|
|
|
static int pb0100_init_controls(struct sd *sd)
|
|
{
|
|
struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
|
|
struct pb0100_ctrls *ctrls;
|
|
static const struct v4l2_ctrl_config autogain_target = {
|
|
.ops = &pb0100_ctrl_ops,
|
|
.id = V4L2_CTRL_CLASS_USER + 0x1000,
|
|
.type = V4L2_CTRL_TYPE_INTEGER,
|
|
.name = "Automatic Gain Target",
|
|
.max = 255,
|
|
.step = 1,
|
|
.def = 128,
|
|
};
|
|
static const struct v4l2_ctrl_config natural_light = {
|
|
.ops = &pb0100_ctrl_ops,
|
|
.id = V4L2_CTRL_CLASS_USER + 0x1001,
|
|
.type = V4L2_CTRL_TYPE_BOOLEAN,
|
|
.name = "Natural Light Source",
|
|
.max = 1,
|
|
.step = 1,
|
|
.def = 1,
|
|
};
|
|
|
|
ctrls = kzalloc(sizeof(*ctrls), GFP_KERNEL);
|
|
if (!ctrls)
|
|
return -ENOMEM;
|
|
|
|
v4l2_ctrl_handler_init(hdl, 6);
|
|
ctrls->autogain = v4l2_ctrl_new_std(hdl, &pb0100_ctrl_ops,
|
|
V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
|
|
ctrls->exposure = v4l2_ctrl_new_std(hdl, &pb0100_ctrl_ops,
|
|
V4L2_CID_EXPOSURE, 0, 511, 1, 12);
|
|
ctrls->gain = v4l2_ctrl_new_std(hdl, &pb0100_ctrl_ops,
|
|
V4L2_CID_GAIN, 0, 255, 1, 128);
|
|
ctrls->red = v4l2_ctrl_new_std(hdl, &pb0100_ctrl_ops,
|
|
V4L2_CID_RED_BALANCE, -255, 255, 1, 0);
|
|
ctrls->blue = v4l2_ctrl_new_std(hdl, &pb0100_ctrl_ops,
|
|
V4L2_CID_BLUE_BALANCE, -255, 255, 1, 0);
|
|
ctrls->natural = v4l2_ctrl_new_custom(hdl, &natural_light, NULL);
|
|
ctrls->target = v4l2_ctrl_new_custom(hdl, &autogain_target, NULL);
|
|
if (hdl->error) {
|
|
kfree(ctrls);
|
|
return hdl->error;
|
|
}
|
|
sd->sensor_priv = ctrls;
|
|
v4l2_ctrl_auto_cluster(5, &ctrls->autogain, 0, false);
|
|
return 0;
|
|
}
|
|
|
|
static int pb0100_probe(struct sd *sd)
|
|
{
|
|
u16 sensor;
|
|
int err;
|
|
|
|
err = stv06xx_read_sensor(sd, PB_IDENT, &sensor);
|
|
|
|
if (err < 0)
|
|
return -ENODEV;
|
|
if ((sensor >> 8) != 0x64)
|
|
return -ENODEV;
|
|
|
|
pr_info("Photobit pb0100 sensor detected\n");
|
|
|
|
sd->gspca_dev.cam.cam_mode = pb0100_mode;
|
|
sd->gspca_dev.cam.nmodes = ARRAY_SIZE(pb0100_mode);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pb0100_start(struct sd *sd)
|
|
{
|
|
int err, packet_size, max_packet_size;
|
|
struct usb_host_interface *alt;
|
|
struct usb_interface *intf;
|
|
struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
|
|
struct cam *cam = &sd->gspca_dev.cam;
|
|
u32 mode = cam->cam_mode[sd->gspca_dev.curr_mode].priv;
|
|
|
|
intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
|
|
alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
|
|
if (!alt)
|
|
return -ENODEV;
|
|
|
|
if (alt->desc.bNumEndpoints < 1)
|
|
return -ENODEV;
|
|
|
|
packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
|
|
|
|
/* If we don't have enough bandwidth use a lower framerate */
|
|
max_packet_size = sd->sensor->max_packet_size[sd->gspca_dev.curr_mode];
|
|
if (packet_size < max_packet_size)
|
|
stv06xx_write_sensor(sd, PB_ROWSPEED, BIT(4)|BIT(3)|BIT(1));
|
|
else
|
|
stv06xx_write_sensor(sd, PB_ROWSPEED, BIT(5)|BIT(3)|BIT(1));
|
|
|
|
/* Setup sensor window */
|
|
if (mode & PB0100_CROP_TO_VGA) {
|
|
stv06xx_write_sensor(sd, PB_RSTART, 30);
|
|
stv06xx_write_sensor(sd, PB_CSTART, 20);
|
|
stv06xx_write_sensor(sd, PB_RWSIZE, 240 - 1);
|
|
stv06xx_write_sensor(sd, PB_CWSIZE, 320 - 1);
|
|
} else {
|
|
stv06xx_write_sensor(sd, PB_RSTART, 8);
|
|
stv06xx_write_sensor(sd, PB_CSTART, 4);
|
|
stv06xx_write_sensor(sd, PB_RWSIZE, 288 - 1);
|
|
stv06xx_write_sensor(sd, PB_CWSIZE, 352 - 1);
|
|
}
|
|
|
|
if (mode & PB0100_SUBSAMPLE) {
|
|
stv06xx_write_bridge(sd, STV_Y_CTRL, 0x02); /* Wrong, FIXME */
|
|
stv06xx_write_bridge(sd, STV_X_CTRL, 0x06);
|
|
|
|
stv06xx_write_bridge(sd, STV_SCAN_RATE, 0x10);
|
|
} else {
|
|
stv06xx_write_bridge(sd, STV_Y_CTRL, 0x01);
|
|
stv06xx_write_bridge(sd, STV_X_CTRL, 0x0a);
|
|
/* larger -> slower */
|
|
stv06xx_write_bridge(sd, STV_SCAN_RATE, 0x20);
|
|
}
|
|
|
|
err = stv06xx_write_sensor(sd, PB_CONTROL, BIT(5)|BIT(3)|BIT(1));
|
|
PDEBUG(D_STREAM, "Started stream, status: %d", err);
|
|
|
|
return (err < 0) ? err : 0;
|
|
}
|
|
|
|
static int pb0100_stop(struct sd *sd)
|
|
{
|
|
struct gspca_dev *gspca_dev = (struct gspca_dev *)sd;
|
|
int err;
|
|
|
|
err = stv06xx_write_sensor(sd, PB_ABORTFRAME, 1);
|
|
|
|
if (err < 0)
|
|
goto out;
|
|
|
|
/* Set bit 1 to zero */
|
|
err = stv06xx_write_sensor(sd, PB_CONTROL, BIT(5)|BIT(3));
|
|
|
|
PDEBUG(D_STREAM, "Halting stream");
|
|
out:
|
|
return (err < 0) ? err : 0;
|
|
}
|
|
|
|
/* FIXME: Sort the init commands out and put them into tables,
|
|
this is only for getting the camera to work */
|
|
/* FIXME: No error handling for now,
|
|
add this once the init has been converted to proper tables */
|
|
static int pb0100_init(struct sd *sd)
|
|
{
|
|
stv06xx_write_bridge(sd, STV_REG00, 1);
|
|
stv06xx_write_bridge(sd, STV_SCAN_RATE, 0);
|
|
|
|
/* Reset sensor */
|
|
stv06xx_write_sensor(sd, PB_RESET, 1);
|
|
stv06xx_write_sensor(sd, PB_RESET, 0);
|
|
|
|
/* Disable chip */
|
|
stv06xx_write_sensor(sd, PB_CONTROL, BIT(5)|BIT(3));
|
|
|
|
/* Gain stuff...*/
|
|
stv06xx_write_sensor(sd, PB_PREADCTRL, BIT(12)|BIT(10)|BIT(6));
|
|
stv06xx_write_sensor(sd, PB_ADCGLOBALGAIN, 12);
|
|
|
|
/* Set up auto-exposure */
|
|
/* ADC VREF_HI new setting for a transition
|
|
from the Expose1 to the Expose2 setting */
|
|
stv06xx_write_sensor(sd, PB_R28, 12);
|
|
/* gain max for autoexposure */
|
|
stv06xx_write_sensor(sd, PB_ADCMAXGAIN, 180);
|
|
/* gain min for autoexposure */
|
|
stv06xx_write_sensor(sd, PB_ADCMINGAIN, 12);
|
|
/* Maximum frame integration time (programmed into R8)
|
|
allowed for auto-exposure routine */
|
|
stv06xx_write_sensor(sd, PB_R54, 3);
|
|
/* Minimum frame integration time (programmed into R8)
|
|
allowed for auto-exposure routine */
|
|
stv06xx_write_sensor(sd, PB_R55, 0);
|
|
stv06xx_write_sensor(sd, PB_UPDATEINT, 1);
|
|
/* R15 Expose0 (maximum that auto-exposure may use) */
|
|
stv06xx_write_sensor(sd, PB_R15, 800);
|
|
/* R17 Expose2 (minimum that auto-exposure may use) */
|
|
stv06xx_write_sensor(sd, PB_R17, 10);
|
|
|
|
stv06xx_write_sensor(sd, PB_EXPGAIN, 0);
|
|
|
|
/* 0x14 */
|
|
stv06xx_write_sensor(sd, PB_VOFFSET, 0);
|
|
/* 0x0D */
|
|
stv06xx_write_sensor(sd, PB_ADCGAINH, 11);
|
|
/* Set black level (important!) */
|
|
stv06xx_write_sensor(sd, PB_ADCGAINL, 0);
|
|
|
|
/* ??? */
|
|
stv06xx_write_bridge(sd, STV_REG00, 0x11);
|
|
stv06xx_write_bridge(sd, STV_REG03, 0x45);
|
|
stv06xx_write_bridge(sd, STV_REG04, 0x07);
|
|
|
|
/* Scan/timing for the sensor */
|
|
stv06xx_write_sensor(sd, PB_ROWSPEED, BIT(4)|BIT(3)|BIT(1));
|
|
stv06xx_write_sensor(sd, PB_CFILLIN, 14);
|
|
stv06xx_write_sensor(sd, PB_VBL, 0);
|
|
stv06xx_write_sensor(sd, PB_FINTTIME, 0);
|
|
stv06xx_write_sensor(sd, PB_RINTTIME, 123);
|
|
|
|
stv06xx_write_bridge(sd, STV_REG01, 0xc2);
|
|
stv06xx_write_bridge(sd, STV_REG02, 0xb0);
|
|
return 0;
|
|
}
|
|
|
|
static int pb0100_dump(struct sd *sd)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static int pb0100_set_gain(struct gspca_dev *gspca_dev, __s32 val)
|
|
{
|
|
int err;
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
|
struct pb0100_ctrls *ctrls = sd->sensor_priv;
|
|
|
|
err = stv06xx_write_sensor(sd, PB_G1GAIN, val);
|
|
if (!err)
|
|
err = stv06xx_write_sensor(sd, PB_G2GAIN, val);
|
|
PDEBUG(D_CONF, "Set green gain to %d, status: %d", val, err);
|
|
|
|
if (!err)
|
|
err = pb0100_set_red_balance(gspca_dev, ctrls->red->val);
|
|
if (!err)
|
|
err = pb0100_set_blue_balance(gspca_dev, ctrls->blue->val);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int pb0100_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
|
|
{
|
|
int err;
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
|
struct pb0100_ctrls *ctrls = sd->sensor_priv;
|
|
|
|
val += ctrls->gain->val;
|
|
if (val < 0)
|
|
val = 0;
|
|
else if (val > 255)
|
|
val = 255;
|
|
|
|
err = stv06xx_write_sensor(sd, PB_RGAIN, val);
|
|
PDEBUG(D_CONF, "Set red gain to %d, status: %d", val, err);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int pb0100_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
|
|
{
|
|
int err;
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
|
struct pb0100_ctrls *ctrls = sd->sensor_priv;
|
|
|
|
val += ctrls->gain->val;
|
|
if (val < 0)
|
|
val = 0;
|
|
else if (val > 255)
|
|
val = 255;
|
|
|
|
err = stv06xx_write_sensor(sd, PB_BGAIN, val);
|
|
PDEBUG(D_CONF, "Set blue gain to %d, status: %d", val, err);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int pb0100_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
|
|
{
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
|
int err;
|
|
|
|
err = stv06xx_write_sensor(sd, PB_RINTTIME, val);
|
|
PDEBUG(D_CONF, "Set exposure to %d, status: %d", val, err);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int pb0100_set_autogain(struct gspca_dev *gspca_dev, __s32 val)
|
|
{
|
|
int err;
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
|
struct pb0100_ctrls *ctrls = sd->sensor_priv;
|
|
|
|
if (val) {
|
|
if (ctrls->natural->val)
|
|
val = BIT(6)|BIT(4)|BIT(0);
|
|
else
|
|
val = BIT(4)|BIT(0);
|
|
} else
|
|
val = 0;
|
|
|
|
err = stv06xx_write_sensor(sd, PB_EXPGAIN, val);
|
|
PDEBUG(D_CONF, "Set autogain to %d (natural: %d), status: %d",
|
|
val, ctrls->natural->val, err);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int pb0100_set_autogain_target(struct gspca_dev *gspca_dev, __s32 val)
|
|
{
|
|
int err, totalpixels, brightpixels, darkpixels;
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
|
|
|
/* Number of pixels counted by the sensor when subsampling the pixels.
|
|
* Slightly larger than the real value to avoid oscillation */
|
|
totalpixels = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
|
|
totalpixels = totalpixels/(8*8) + totalpixels/(64*64);
|
|
|
|
brightpixels = (totalpixels * val) >> 8;
|
|
darkpixels = totalpixels - brightpixels;
|
|
err = stv06xx_write_sensor(sd, PB_R21, brightpixels);
|
|
if (!err)
|
|
err = stv06xx_write_sensor(sd, PB_R22, darkpixels);
|
|
|
|
PDEBUG(D_CONF, "Set autogain target to %d, status: %d", val, err);
|
|
|
|
return err;
|
|
}
|