Changes in 4.9.212 xfs: Sanity check flags of Q_XQUOTARM call powerpc/archrandom: fix arch_get_random_seed_int() mt7601u: fix bbp version check in mt7601u_wait_bbp_ready drm/sti: do not remove the drm_bridge that was never added drm/virtio: fix bounds check in virtio_gpu_cmd_get_capset() ALSA: hda: fix unused variable warning IB/rxe: replace kvfree with vfree ALSA: usb-audio: update quirk for B&W PX to remove microphone staging: comedi: ni_mio_common: protect register write overflow pwm: lpss: Release runtime-pm reference from the driver's remove callback mlxsw: reg: QEEC: Add minimum shaper fields pcrypt: use format specifier in kobject_add exportfs: fix 'passing zero to ERR_PTR()' warning drm/dp_mst: Skip validating ports during destruction, just ref net: phy: Fix not to call phy_resume() if PHY is not attached pinctrl: sh-pfc: r8a7740: Add missing REF125CK pin to gether_gmii group pinctrl: sh-pfc: r8a7740: Add missing LCD0 marks to lcd0_data24_1 group pinctrl: sh-pfc: r8a7791: Remove bogus ctrl marks from qspi_data4_b group pinctrl: sh-pfc: r8a7791: Remove bogus marks from vin1_b_data18 group pinctrl: sh-pfc: sh73a0: Add missing TO pin to tpu4_to3 group pinctrl: sh-pfc: r8a7794: Remove bogus IPSR9 field pinctrl: sh-pfc: sh7734: Add missing IPSR11 field pinctrl: sh-pfc: sh7269: Add missing PCIOR0 field pinctrl: sh-pfc: sh7734: Remove bogus IPSR10 value Input: nomadik-ske-keypad - fix a loop timeout test clk: highbank: fix refcount leak in hb_clk_init() clk: qoriq: fix refcount leak in clockgen_init() clk: socfpga: fix refcount leak clk: samsung: exynos4: fix refcount leak in exynos4_get_xom() clk: imx6q: fix refcount leak in imx6q_clocks_init() clk: imx6sx: fix refcount leak in imx6sx_clocks_init() clk: imx7d: fix refcount leak in imx7d_clocks_init() clk: vf610: fix refcount leak in vf610_clocks_init() clk: armada-370: fix refcount leak in a370_clk_init() clk: kirkwood: fix refcount leak in kirkwood_clk_init() clk: armada-xp: fix refcount leak in axp_clk_init() clk: dove: fix refcount leak in dove_clk_init() IB/usnic: Fix out of bounds index check in query pkey RDMA/ocrdma: Fix out of bounds index check in query pkey RDMA/qedr: Fix out of bounds index check in query pkey arm64: dts: apq8016-sbc: Increase load on l11 for SDCARD drm/etnaviv: NULL vs IS_ERR() buf in etnaviv_core_dump() media: s5p-jpeg: Correct step and max values for V4L2_CID_JPEG_RESTART_INTERVAL crypto: tgr192 - fix unaligned memory access ASoC: imx-sgtl5000: put of nodes if finding codec fails IB/iser: Pass the correct number of entries for dma mapped SGL rtc: cmos: ignore bogus century byte clk: sunxi-ng: sun8i-a23: Enable PLL-MIPI LDOs when ungating it iwlwifi: mvm: fix A-MPDU reference assignment tty: ipwireless: Fix potential NULL pointer dereference crypto: crypto4xx - Fix wrong ppc4xx_trng_probe()/ppc4xx_trng_remove() arguments ARM: dts: lpc32xx: add required clocks property to keypad device node ARM: dts: lpc32xx: reparent keypad controller to SIC1 ARM: dts: lpc32xx: fix ARM PrimeCell LCD controller variant ARM: dts: lpc32xx: fix ARM PrimeCell LCD controller clocks property ARM: dts: lpc32xx: phy3250: fix SD card regulator voltage iwlwifi: mvm: fix RSS config command staging: most: cdev: add missing check for cdev_add failure rtc: ds1672: fix unintended sign extension thermal: mediatek: fix register index error net: phy: fixed_phy: Fix fixed_phy not checking GPIO rtc: 88pm860x: fix unintended sign extension rtc: 88pm80x: fix unintended sign extension rtc: pm8xxx: fix unintended sign extension fbdev: chipsfb: remove set but not used variable 'size' iw_cxgb4: use tos when importing the endpoint iw_cxgb4: use tos when finding ipv6 routes pinctrl: sh-pfc: emev2: Add missing pinmux functions pinctrl: sh-pfc: r8a7791: Fix scifb2_data_c pin group pinctrl: sh-pfc: r8a7792: Fix vin1_data18_b pin group pinctrl: sh-pfc: sh73a0: Fix fsic_spdif pin groups usb: phy: twl6030-usb: fix possible use-after-free on remove block: don't use bio->bi_vcnt to figure out segment number keys: Timestamp new keys vfio_pci: Enable memory accesses before calling pci_map_rom dmaengine: mv_xor: Use correct device for DMA API cdc-wdm: pass return value of recover_from_urb_loss regulator: pv88060: Fix array out-of-bounds access regulator: pv88080: Fix array out-of-bounds access regulator: pv88090: Fix array out-of-bounds access net: dsa: qca8k: Enable delay for RGMII_ID mode drm/nouveau/bios/ramcfg: fix missing parentheses when calculating RON drm/nouveau/pmu: don't print reply values if exec is false ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of() fs/nfs: Fix nfs_parse_devname to not modify it's argument NFS: Fix a soft lockup in the delegation recovery code clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable clocksource/drivers/exynos_mct: Fix error path in timer resources initialization mmc: sdhci-brcmstb: handle mmc_of_parse() errors during probe ARM: 8847/1: pm: fix HYP/SVC mode mismatch when MCPM is used ARM: 8848/1: virt: Align GIC version check with arm64 counterpart regulator: wm831x-dcdc: Fix list of wm831x_dcdc_ilim from mA to uA nios2: ksyms: Add missing symbol exports scsi: megaraid_sas: reduce module load time drivers/rapidio/rio_cm.c: fix potential oops in riocm_ch_listen() xen, cpu_hotplug: Prevent an out of bounds access net: sh_eth: fix a missing check of of_get_phy_mode media: ivtv: update *pos correctly in ivtv_read_pos() media: cx18: update *pos correctly in cx18_read_pos() media: wl128x: Fix an error code in fm_download_firmware() media: cx23885: check allocation return regulator: tps65086: Fix tps65086_ldoa1_ranges for selector 0xB jfs: fix bogus variable self-initialization tipc: tipc clang warning m68k: mac: Fix VIA timer counter accesses ARM: OMAP2+: Fix potentially uninitialized return value for _setup_reset() media: davinci-isif: avoid uninitialized variable use media: tw5864: Fix possible NULL pointer dereference in tw5864_handle_frame spi: tegra114: clear packed bit for unpacked mode spi: tegra114: fix for unpacked mode transfers soc/fsl/qe: Fix an error code in qe_pin_request() spi: bcm2835aux: fix driver to not allow 65535 (=-1) cs-gpios ehea: Fix a copy-paste err in ehea_init_port_res scsi: qla2xxx: Unregister chrdev if module initialization fails ARM: pxa: ssp: Fix "WARNING: invalid free of devm_ allocated data" hwmon: (w83627hf) Use request_muxed_region for Super-IO accesses tipc: set sysctl_tipc_rmem and named_timeout right range powerpc: vdso: Make vdso32 installation conditional in vdso_install ARM: dts: ls1021: Fix SGMII PCS link remaining down after PHY disconnect media: ov2659: fix unbalanced mutex_lock/unlock 6lowpan: Off by one handling ->nexthdr dmaengine: axi-dmac: Don't check the number of frames for alignment ALSA: usb-audio: Handle the error from snd_usb_mixer_apply_create_quirk() packet: in recvmsg msg_name return at least sizeof sockaddr_ll ASoC: fix valid stream condition usb: gadget: fsl: fix link error against usb-gadget module IB/mlx5: Add missing XRC options to QP optional params mask iommu/vt-d: Make kernel parameter igfx_off work with vIOMMU net: ena: fix swapped parameters when calling ena_com_indirect_table_fill_entry net: ena: fix: Free napi resources when ena_up() fails net: ena: fix incorrect test of supported hash function net: ena: fix ena_com_fill_hash_function() implementation dmaengine: tegra210-adma: restore channel status l2tp: Fix possible NULL pointer dereference media: omap_vout: potential buffer overflow in vidioc_dqbuf() media: davinci/vpbe: array underflow in vpbe_enum_outputs() platform/x86: alienware-wmi: printing the wrong error code netfilter: ebtables: CONFIG_COMPAT: reject trailing data after last rule pwm: meson: Don't disable PWM when setting duty repeatedly ARM: riscpc: fix lack of keyboard interrupts after irq conversion kdb: do a sanity check on the cpu in kdb_per_cpu() backlight: lm3630a: Return 0 on success in update_status functions thermal: cpu_cooling: Actually trace CPU load in thermal_power_cpu_get_power dmaengine: tegra210-adma: Fix crash during probe spi: spi-fsl-spi: call spi_finalize_current_message() at the end crypto: ccp - fix AES CFB error exposed by new test vectors serial: stm32: fix transmit_chars when tx is stopped misc: sgi-xp: Properly initialize buf in xpc_get_rsvd_page_pa iommu: Use right function to get group for device signal/cifs: Fix cifs_put_tcp_session to call send_sig instead of force_sig inet: frags: call inet_frags_fini() after unregister_pernet_subsys() media: vivid: fix incorrect assignment operation when setting video mode powerpc/cacheinfo: add cacheinfo_teardown, cacheinfo_rebuild drm/msm/mdp5: Fix mdp5_cfg_init error return net: netem: fix backlog accounting for corrupted GSO frames net/af_iucv: always register net_device notifier ASoC: ti: davinci-mcasp: Fix slot mask settings when using multiple AXRs rtc: pcf8563: Clear event flags and disable interrupts before requesting irq drm/msm/a3xx: remove TPL1 regs from snapshot perf/ioctl: Add check for the sample_period value dmaengine: hsu: Revert "set HSU_CH_MTSR to memory width" clk: qcom: Fix -Wunused-const-variable iommu/amd: Make iommu_disable safer mfd: intel-lpss: Release IDA resources rxrpc: Fix uninitialized error code in rxrpc_send_data_packet() devres: allow const resource arguments RDMA/hns: Fixs hw access invalid dma memory error net: pasemi: fix an use-after-free in pasemi_mac_phy_init() scsi: libfc: fix null pointer dereference on a null lport libertas_tf: Use correct channel range in lbtf_geo_init qed: reduce maximum stack frame size usb: host: xhci-hub: fix extra endianness conversion mic: avoid statically declaring a 'struct device'. x86/kgbd: Use NMI_VECTOR not APIC_DM_NMI ALSA: aoa: onyx: always initialize register read value net/mlx5: Fix mlx5_ifc_query_lag_out_bits cifs: fix rmmod regression in cifs.ko caused by force_sig changes crypto: caam - free resources in case caam_rng registration failed ext4: set error return correctly when ext4_htree_store_dirent fails ASoC: es8328: Fix copy-paste error in es8328_right_line_controls ASoC: cs4349: Use PM ops 'cs4349_runtime_pm' ASoC: wm8737: Fix copy-paste error in wm8737_snd_controls signal: Allow cifs and drbd to receive their terminating signals ASoC: sun4i-i2s: RX and TX counter registers are swapped dmaengine: dw: platform: Switch to acpi_dma_controller_register() mac80211: minstrel_ht: fix per-group max throughput rate initialization mips: avoid explicit UB in assignment of mips_io_port_base ahci: Do not export local variable ahci_em_messages Partially revert "kfifo: fix kfifo_alloc() and kfifo_init()" hwmon: (lm75) Fix write operations for negative temperatures power: supply: Init device wakeup after device_add() x86, perf: Fix the dependency of the x86 insn decoder selftest staging: greybus: light: fix a couple double frees bcma: fix incorrect update of BCMA_CORE_PCI_MDIO_DATA iio: dac: ad5380: fix incorrect assignment to val ath9k: dynack: fix possible deadlock in ath_dynack_node_{de}init net: sonic: return NETDEV_TX_OK if failed to map buffer Btrfs: fix hang when loading existing inode cache off disk hwmon: (shtc1) fix shtc1 and shtw1 id mask net: sonic: replace dev_kfree_skb in sonic_send_packet net/rds: Fix 'ib_evt_handler_call' element in 'rds_ib_stat_names' iommu/amd: Wait for completion of IOTLB flush in attach_device net: hisilicon: Fix signedness bug in hix5hd2_dev_probe() net: broadcom/bcmsysport: Fix signedness in bcm_sysport_probe() net: stmmac: dwmac-meson8b: Fix signedness bug in probe of: mdio: Fix a signedness bug in of_phy_get_and_connect() net: ethernet: stmmac: Fix signedness bug in ipq806x_gmac_of_parse() nvme: retain split access workaround for capability reads net: stmmac: gmac4+: Not all Unicast addresses may be available mac80211: accept deauth frames in IBSS mode llc: fix another potential sk_buff leak in llc_ui_sendmsg() llc: fix sk_buff refcounting in llc_conn_state_process() net: stmmac: fix length of PTP clock's name string act_mirred: Fix mirred_init_module error handling drm/msm/dsi: Implement reset correctly dmaengine: imx-sdma: fix size check for sdma script_number net: netem: fix error path for corrupted GSO frames net: netem: correct the parent's backlog when corrupted packet was dropped net: qca_spi: Move reset_count to struct qcaspi afs: Fix large file support media: ov6650: Fix incorrect use of JPEG colorspace media: ov6650: Fix some format attributes not under control media: ov6650: Fix .get_fmt() V4L2_SUBDEV_FORMAT_TRY support MIPS: Loongson: Fix return value of loongson_hwmon_init net: neigh: use long type to store jiffies delta packet: fix data-race in fanout_flow_is_huge() dmaengine: ti: edma: fix missed failure handling drm/radeon: fix bad DMA from INTERRUPT_CNTL2 arm64: dts: juno: Fix UART frequency IB/iser: Fix dma_nents type definition m68k: Call timer_interrupt() with interrupts disabled net: ethtool: Add back transceiver type net: phy: Keep reporting transceiver type can, slip: Protect tty->disc_data in write_wakeup and close with RCU firestream: fix memory leaks net: cxgb3_main: Add CAP_NET_ADMIN check to CHELSIO_GET_MEM net, ip6_tunnel: fix namespaces move net, ip_tunnel: fix namespaces move net_sched: fix datalen for ematch tcp_bbr: improve arithmetic division in bbr_update_bw() net: usb: lan78xx: Add .ndo_features_check gtp: make sure only SOCK_DGRAM UDP sockets are accepted hwmon: (adt7475) Make volt2reg return same reg as reg2volt input hwmon: (core) Simplify sysfs attribute name allocation hwmon: Deal with errors from the thermal subsystem hwmon: (core) Fix double-free in __hwmon_device_register() hwmon: (core) Do not use device managed functions for memory allocations Input: keyspan-remote - fix control-message timeouts ARM: 8950/1: ftrace/recordmcount: filter relocation types mmc: tegra: fix SDR50 tuning override mmc: sdhci: fix minimum clock rate for v3 controller Input: sur40 - fix interface sanity checks Input: gtco - fix endpoint sanity check Input: aiptek - fix endpoint sanity check Input: pegasus_notetaker - fix endpoint sanity check Input: sun4i-ts - add a check for devm_thermal_zone_of_sensor_register hwmon: (nct7802) Fix voltage limits to wrong registers scsi: RDMA/isert: Fix a recently introduced regression related to logout tracing: xen: Ordered comparison of function pointers do_last(): fetch directory ->i_mode and ->i_uid before it's too late Documentation: Document arm64 kpti control arm64: kpti: Whitelist Cortex-A CPUs that don't implement the CSV3 field coresight: etb10: Do not call smp_processor_id from preemptible coresight: tmc-etf: Do not call smp_processor_id from preemptible libertas: Fix two buffer overflows at parsing bss descriptor bcache: silence static checker warning scsi: iscsi: Avoid potential deadlock in iscsi_if_rx func md: Avoid namespace collision with bitmap API bitmap: Add bitmap_alloc(), bitmap_zalloc() and bitmap_free() netfilter: ipset: use bitmap infrastructure completely net/x25: fix nonblocking connect Linux 4.9.212 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I2e83a05c5f119a7467a4d6984045d45d0c06b764
1114 lines
29 KiB
C
1114 lines
29 KiB
C
/*
|
|
* V4L2 SoC Camera driver for OmniVision OV6650 Camera Sensor
|
|
*
|
|
* Copyright (C) 2010 Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
|
|
*
|
|
* Based on OmniVision OV96xx Camera Driver
|
|
* Copyright (C) 2009 Marek Vasut <marek.vasut@gmail.com>
|
|
*
|
|
* Based on ov772x camera driver:
|
|
* Copyright (C) 2008 Renesas Solutions Corp.
|
|
* Kuninori Morimoto <morimoto.kuninori@renesas.com>
|
|
*
|
|
* Based on ov7670 and soc_camera_platform driver,
|
|
* Copyright 2006-7 Jonathan Corbet <corbet@lwn.net>
|
|
* Copyright (C) 2008 Magnus Damm
|
|
* Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
|
|
*
|
|
* Hardware specific bits initialy based on former work by Matt Callow
|
|
* drivers/media/video/omap/sensor_ov6650.c
|
|
* Copyright (C) 2006 Matt Callow
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/bitops.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/v4l2-mediabus.h>
|
|
#include <linux/module.h>
|
|
|
|
#include <media/soc_camera.h>
|
|
#include <media/v4l2-clk.h>
|
|
#include <media/v4l2-ctrls.h>
|
|
|
|
/* Register definitions */
|
|
#define REG_GAIN 0x00 /* range 00 - 3F */
|
|
#define REG_BLUE 0x01
|
|
#define REG_RED 0x02
|
|
#define REG_SAT 0x03 /* [7:4] saturation [0:3] reserved */
|
|
#define REG_HUE 0x04 /* [7:6] rsrvd [5] hue en [4:0] hue */
|
|
|
|
#define REG_BRT 0x06
|
|
|
|
#define REG_PIDH 0x0a
|
|
#define REG_PIDL 0x0b
|
|
|
|
#define REG_AECH 0x10
|
|
#define REG_CLKRC 0x11 /* Data Format and Internal Clock */
|
|
/* [7:6] Input system clock (MHz)*/
|
|
/* 00=8, 01=12, 10=16, 11=24 */
|
|
/* [5:0]: Internal Clock Pre-Scaler */
|
|
#define REG_COMA 0x12 /* [7] Reset */
|
|
#define REG_COMB 0x13
|
|
#define REG_COMC 0x14
|
|
#define REG_COMD 0x15
|
|
#define REG_COML 0x16
|
|
#define REG_HSTRT 0x17
|
|
#define REG_HSTOP 0x18
|
|
#define REG_VSTRT 0x19
|
|
#define REG_VSTOP 0x1a
|
|
#define REG_PSHFT 0x1b
|
|
#define REG_MIDH 0x1c
|
|
#define REG_MIDL 0x1d
|
|
#define REG_HSYNS 0x1e
|
|
#define REG_HSYNE 0x1f
|
|
#define REG_COME 0x20
|
|
#define REG_YOFF 0x21
|
|
#define REG_UOFF 0x22
|
|
#define REG_VOFF 0x23
|
|
#define REG_AEW 0x24
|
|
#define REG_AEB 0x25
|
|
#define REG_COMF 0x26
|
|
#define REG_COMG 0x27
|
|
#define REG_COMH 0x28
|
|
#define REG_COMI 0x29
|
|
|
|
#define REG_FRARL 0x2b
|
|
#define REG_COMJ 0x2c
|
|
#define REG_COMK 0x2d
|
|
#define REG_AVGY 0x2e
|
|
#define REG_REF0 0x2f
|
|
#define REG_REF1 0x30
|
|
#define REG_REF2 0x31
|
|
#define REG_FRAJH 0x32
|
|
#define REG_FRAJL 0x33
|
|
#define REG_FACT 0x34
|
|
#define REG_L1AEC 0x35
|
|
#define REG_AVGU 0x36
|
|
#define REG_AVGV 0x37
|
|
|
|
#define REG_SPCB 0x60
|
|
#define REG_SPCC 0x61
|
|
#define REG_GAM1 0x62
|
|
#define REG_GAM2 0x63
|
|
#define REG_GAM3 0x64
|
|
#define REG_SPCD 0x65
|
|
|
|
#define REG_SPCE 0x68
|
|
#define REG_ADCL 0x69
|
|
|
|
#define REG_RMCO 0x6c
|
|
#define REG_GMCO 0x6d
|
|
#define REG_BMCO 0x6e
|
|
|
|
|
|
/* Register bits, values, etc. */
|
|
#define OV6650_PIDH 0x66 /* high byte of product ID number */
|
|
#define OV6650_PIDL 0x50 /* low byte of product ID number */
|
|
#define OV6650_MIDH 0x7F /* high byte of mfg ID */
|
|
#define OV6650_MIDL 0xA2 /* low byte of mfg ID */
|
|
|
|
#define DEF_GAIN 0x00
|
|
#define DEF_BLUE 0x80
|
|
#define DEF_RED 0x80
|
|
|
|
#define SAT_SHIFT 4
|
|
#define SAT_MASK (0xf << SAT_SHIFT)
|
|
#define SET_SAT(x) (((x) << SAT_SHIFT) & SAT_MASK)
|
|
|
|
#define HUE_EN BIT(5)
|
|
#define HUE_MASK 0x1f
|
|
#define DEF_HUE 0x10
|
|
#define SET_HUE(x) (HUE_EN | ((x) & HUE_MASK))
|
|
|
|
#define DEF_AECH 0x4D
|
|
|
|
#define CLKRC_6MHz 0x00
|
|
#define CLKRC_12MHz 0x40
|
|
#define CLKRC_16MHz 0x80
|
|
#define CLKRC_24MHz 0xc0
|
|
#define CLKRC_DIV_MASK 0x3f
|
|
#define GET_CLKRC_DIV(x) (((x) & CLKRC_DIV_MASK) + 1)
|
|
|
|
#define COMA_RESET BIT(7)
|
|
#define COMA_QCIF BIT(5)
|
|
#define COMA_RAW_RGB BIT(4)
|
|
#define COMA_RGB BIT(3)
|
|
#define COMA_BW BIT(2)
|
|
#define COMA_WORD_SWAP BIT(1)
|
|
#define COMA_BYTE_SWAP BIT(0)
|
|
#define DEF_COMA 0x00
|
|
|
|
#define COMB_FLIP_V BIT(7)
|
|
#define COMB_FLIP_H BIT(5)
|
|
#define COMB_BAND_FILTER BIT(4)
|
|
#define COMB_AWB BIT(2)
|
|
#define COMB_AGC BIT(1)
|
|
#define COMB_AEC BIT(0)
|
|
#define DEF_COMB 0x5f
|
|
|
|
#define COML_ONE_CHANNEL BIT(7)
|
|
|
|
#define DEF_HSTRT 0x24
|
|
#define DEF_HSTOP 0xd4
|
|
#define DEF_VSTRT 0x04
|
|
#define DEF_VSTOP 0x94
|
|
|
|
#define COMF_HREF_LOW BIT(4)
|
|
|
|
#define COMJ_PCLK_RISING BIT(4)
|
|
#define COMJ_VSYNC_HIGH BIT(0)
|
|
|
|
/* supported resolutions */
|
|
#define W_QCIF (DEF_HSTOP - DEF_HSTRT)
|
|
#define W_CIF (W_QCIF << 1)
|
|
#define H_QCIF (DEF_VSTOP - DEF_VSTRT)
|
|
#define H_CIF (H_QCIF << 1)
|
|
|
|
#define FRAME_RATE_MAX 30
|
|
|
|
|
|
struct ov6650_reg {
|
|
u8 reg;
|
|
u8 val;
|
|
};
|
|
|
|
struct ov6650 {
|
|
struct v4l2_subdev subdev;
|
|
struct v4l2_ctrl_handler hdl;
|
|
struct {
|
|
/* exposure/autoexposure cluster */
|
|
struct v4l2_ctrl *autoexposure;
|
|
struct v4l2_ctrl *exposure;
|
|
};
|
|
struct {
|
|
/* gain/autogain cluster */
|
|
struct v4l2_ctrl *autogain;
|
|
struct v4l2_ctrl *gain;
|
|
};
|
|
struct {
|
|
/* blue/red/autowhitebalance cluster */
|
|
struct v4l2_ctrl *autowb;
|
|
struct v4l2_ctrl *blue;
|
|
struct v4l2_ctrl *red;
|
|
};
|
|
struct v4l2_clk *clk;
|
|
bool half_scale; /* scale down output by 2 */
|
|
struct v4l2_rect rect; /* sensor cropping window */
|
|
unsigned long pclk_limit; /* from host */
|
|
unsigned long pclk_max; /* from resolution and format */
|
|
struct v4l2_fract tpf; /* as requested with s_parm */
|
|
u32 code;
|
|
};
|
|
|
|
|
|
static u32 ov6650_codes[] = {
|
|
MEDIA_BUS_FMT_YUYV8_2X8,
|
|
MEDIA_BUS_FMT_UYVY8_2X8,
|
|
MEDIA_BUS_FMT_YVYU8_2X8,
|
|
MEDIA_BUS_FMT_VYUY8_2X8,
|
|
MEDIA_BUS_FMT_SBGGR8_1X8,
|
|
MEDIA_BUS_FMT_Y8_1X8,
|
|
};
|
|
|
|
static const struct v4l2_mbus_framefmt ov6650_def_fmt = {
|
|
.width = W_CIF,
|
|
.height = H_CIF,
|
|
.code = MEDIA_BUS_FMT_SBGGR8_1X8,
|
|
.colorspace = V4L2_COLORSPACE_SRGB,
|
|
.field = V4L2_FIELD_NONE,
|
|
.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT,
|
|
.quantization = V4L2_QUANTIZATION_DEFAULT,
|
|
.xfer_func = V4L2_XFER_FUNC_DEFAULT,
|
|
};
|
|
|
|
/* read a register */
|
|
static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val)
|
|
{
|
|
int ret;
|
|
u8 data = reg;
|
|
struct i2c_msg msg = {
|
|
.addr = client->addr,
|
|
.flags = 0,
|
|
.len = 1,
|
|
.buf = &data,
|
|
};
|
|
|
|
ret = i2c_transfer(client->adapter, &msg, 1);
|
|
if (ret < 0)
|
|
goto err;
|
|
|
|
msg.flags = I2C_M_RD;
|
|
ret = i2c_transfer(client->adapter, &msg, 1);
|
|
if (ret < 0)
|
|
goto err;
|
|
|
|
*val = data;
|
|
return 0;
|
|
|
|
err:
|
|
dev_err(&client->dev, "Failed reading register 0x%02x!\n", reg);
|
|
return ret;
|
|
}
|
|
|
|
/* write a register */
|
|
static int ov6650_reg_write(struct i2c_client *client, u8 reg, u8 val)
|
|
{
|
|
int ret;
|
|
unsigned char data[2] = { reg, val };
|
|
struct i2c_msg msg = {
|
|
.addr = client->addr,
|
|
.flags = 0,
|
|
.len = 2,
|
|
.buf = data,
|
|
};
|
|
|
|
ret = i2c_transfer(client->adapter, &msg, 1);
|
|
udelay(100);
|
|
|
|
if (ret < 0) {
|
|
dev_err(&client->dev, "Failed writing register 0x%02x!\n", reg);
|
|
return ret;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
/* Read a register, alter its bits, write it back */
|
|
static int ov6650_reg_rmw(struct i2c_client *client, u8 reg, u8 set, u8 mask)
|
|
{
|
|
u8 val;
|
|
int ret;
|
|
|
|
ret = ov6650_reg_read(client, reg, &val);
|
|
if (ret) {
|
|
dev_err(&client->dev,
|
|
"[Read]-Modify-Write of register 0x%02x failed!\n",
|
|
reg);
|
|
return ret;
|
|
}
|
|
|
|
val &= ~mask;
|
|
val |= set;
|
|
|
|
ret = ov6650_reg_write(client, reg, val);
|
|
if (ret)
|
|
dev_err(&client->dev,
|
|
"Read-Modify-[Write] of register 0x%02x failed!\n",
|
|
reg);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static struct ov6650 *to_ov6650(const struct i2c_client *client)
|
|
{
|
|
return container_of(i2c_get_clientdata(client), struct ov6650, subdev);
|
|
}
|
|
|
|
/* Start/Stop streaming from the device */
|
|
static int ov6650_s_stream(struct v4l2_subdev *sd, int enable)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
/* Get status of additional camera capabilities */
|
|
static int ov6550_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
|
|
{
|
|
struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
|
|
struct v4l2_subdev *sd = &priv->subdev;
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
uint8_t reg, reg2;
|
|
int ret;
|
|
|
|
switch (ctrl->id) {
|
|
case V4L2_CID_AUTOGAIN:
|
|
ret = ov6650_reg_read(client, REG_GAIN, ®);
|
|
if (!ret)
|
|
priv->gain->val = reg;
|
|
return ret;
|
|
case V4L2_CID_AUTO_WHITE_BALANCE:
|
|
ret = ov6650_reg_read(client, REG_BLUE, ®);
|
|
if (!ret)
|
|
ret = ov6650_reg_read(client, REG_RED, ®2);
|
|
if (!ret) {
|
|
priv->blue->val = reg;
|
|
priv->red->val = reg2;
|
|
}
|
|
return ret;
|
|
case V4L2_CID_EXPOSURE_AUTO:
|
|
ret = ov6650_reg_read(client, REG_AECH, ®);
|
|
if (!ret)
|
|
priv->exposure->val = reg;
|
|
return ret;
|
|
}
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Set status of additional camera capabilities */
|
|
static int ov6550_s_ctrl(struct v4l2_ctrl *ctrl)
|
|
{
|
|
struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
|
|
struct v4l2_subdev *sd = &priv->subdev;
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
int ret;
|
|
|
|
switch (ctrl->id) {
|
|
case V4L2_CID_AUTOGAIN:
|
|
ret = ov6650_reg_rmw(client, REG_COMB,
|
|
ctrl->val ? COMB_AGC : 0, COMB_AGC);
|
|
if (!ret && !ctrl->val)
|
|
ret = ov6650_reg_write(client, REG_GAIN, priv->gain->val);
|
|
return ret;
|
|
case V4L2_CID_AUTO_WHITE_BALANCE:
|
|
ret = ov6650_reg_rmw(client, REG_COMB,
|
|
ctrl->val ? COMB_AWB : 0, COMB_AWB);
|
|
if (!ret && !ctrl->val) {
|
|
ret = ov6650_reg_write(client, REG_BLUE, priv->blue->val);
|
|
if (!ret)
|
|
ret = ov6650_reg_write(client, REG_RED,
|
|
priv->red->val);
|
|
}
|
|
return ret;
|
|
case V4L2_CID_SATURATION:
|
|
return ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->val),
|
|
SAT_MASK);
|
|
case V4L2_CID_HUE:
|
|
return ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->val),
|
|
HUE_MASK);
|
|
case V4L2_CID_BRIGHTNESS:
|
|
return ov6650_reg_write(client, REG_BRT, ctrl->val);
|
|
case V4L2_CID_EXPOSURE_AUTO:
|
|
ret = ov6650_reg_rmw(client, REG_COMB, ctrl->val ==
|
|
V4L2_EXPOSURE_AUTO ? COMB_AEC : 0, COMB_AEC);
|
|
if (!ret && ctrl->val == V4L2_EXPOSURE_MANUAL)
|
|
ret = ov6650_reg_write(client, REG_AECH,
|
|
priv->exposure->val);
|
|
return ret;
|
|
case V4L2_CID_GAMMA:
|
|
return ov6650_reg_write(client, REG_GAM1, ctrl->val);
|
|
case V4L2_CID_VFLIP:
|
|
return ov6650_reg_rmw(client, REG_COMB,
|
|
ctrl->val ? COMB_FLIP_V : 0, COMB_FLIP_V);
|
|
case V4L2_CID_HFLIP:
|
|
return ov6650_reg_rmw(client, REG_COMB,
|
|
ctrl->val ? COMB_FLIP_H : 0, COMB_FLIP_H);
|
|
}
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
#ifdef CONFIG_VIDEO_ADV_DEBUG
|
|
static int ov6650_get_register(struct v4l2_subdev *sd,
|
|
struct v4l2_dbg_register *reg)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
int ret;
|
|
u8 val;
|
|
|
|
if (reg->reg & ~0xff)
|
|
return -EINVAL;
|
|
|
|
reg->size = 1;
|
|
|
|
ret = ov6650_reg_read(client, reg->reg, &val);
|
|
if (!ret)
|
|
reg->val = (__u64)val;
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int ov6650_set_register(struct v4l2_subdev *sd,
|
|
const struct v4l2_dbg_register *reg)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
if (reg->reg & ~0xff || reg->val & ~0xff)
|
|
return -EINVAL;
|
|
|
|
return ov6650_reg_write(client, reg->reg, reg->val);
|
|
}
|
|
#endif
|
|
|
|
static int ov6650_s_power(struct v4l2_subdev *sd, int on)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
|
|
}
|
|
|
|
static int ov6650_get_selection(struct v4l2_subdev *sd,
|
|
struct v4l2_subdev_pad_config *cfg,
|
|
struct v4l2_subdev_selection *sel)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
|
|
return -EINVAL;
|
|
|
|
switch (sel->target) {
|
|
case V4L2_SEL_TGT_CROP_BOUNDS:
|
|
case V4L2_SEL_TGT_CROP_DEFAULT:
|
|
sel->r.left = DEF_HSTRT << 1;
|
|
sel->r.top = DEF_VSTRT << 1;
|
|
sel->r.width = W_CIF;
|
|
sel->r.height = H_CIF;
|
|
return 0;
|
|
case V4L2_SEL_TGT_CROP:
|
|
sel->r = priv->rect;
|
|
return 0;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
static int ov6650_set_selection(struct v4l2_subdev *sd,
|
|
struct v4l2_subdev_pad_config *cfg,
|
|
struct v4l2_subdev_selection *sel)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
struct v4l2_rect rect = sel->r;
|
|
int ret;
|
|
|
|
if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE ||
|
|
sel->target != V4L2_SEL_TGT_CROP)
|
|
return -EINVAL;
|
|
|
|
rect.left = ALIGN(rect.left, 2);
|
|
rect.width = ALIGN(rect.width, 2);
|
|
rect.top = ALIGN(rect.top, 2);
|
|
rect.height = ALIGN(rect.height, 2);
|
|
soc_camera_limit_side(&rect.left, &rect.width,
|
|
DEF_HSTRT << 1, 2, W_CIF);
|
|
soc_camera_limit_side(&rect.top, &rect.height,
|
|
DEF_VSTRT << 1, 2, H_CIF);
|
|
|
|
ret = ov6650_reg_write(client, REG_HSTRT, rect.left >> 1);
|
|
if (!ret) {
|
|
priv->rect.left = rect.left;
|
|
ret = ov6650_reg_write(client, REG_HSTOP,
|
|
(rect.left + rect.width) >> 1);
|
|
}
|
|
if (!ret) {
|
|
priv->rect.width = rect.width;
|
|
ret = ov6650_reg_write(client, REG_VSTRT, rect.top >> 1);
|
|
}
|
|
if (!ret) {
|
|
priv->rect.top = rect.top;
|
|
ret = ov6650_reg_write(client, REG_VSTOP,
|
|
(rect.top + rect.height) >> 1);
|
|
}
|
|
if (!ret)
|
|
priv->rect.height = rect.height;
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int ov6650_get_fmt(struct v4l2_subdev *sd,
|
|
struct v4l2_subdev_pad_config *cfg,
|
|
struct v4l2_subdev_format *format)
|
|
{
|
|
struct v4l2_mbus_framefmt *mf = &format->format;
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
if (format->pad)
|
|
return -EINVAL;
|
|
|
|
/* initialize response with default media bus frame format */
|
|
*mf = ov6650_def_fmt;
|
|
|
|
/* update media bus format code and frame size */
|
|
if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
|
|
mf->width = cfg->try_fmt.width;
|
|
mf->height = cfg->try_fmt.height;
|
|
mf->code = cfg->try_fmt.code;
|
|
|
|
} else {
|
|
mf->width = priv->rect.width >> priv->half_scale;
|
|
mf->height = priv->rect.height >> priv->half_scale;
|
|
mf->code = priv->code;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect)
|
|
{
|
|
return width > rect->width >> 1 || height > rect->height >> 1;
|
|
}
|
|
|
|
static u8 to_clkrc(struct v4l2_fract *timeperframe,
|
|
unsigned long pclk_limit, unsigned long pclk_max)
|
|
{
|
|
unsigned long pclk;
|
|
|
|
if (timeperframe->numerator && timeperframe->denominator)
|
|
pclk = pclk_max * timeperframe->denominator /
|
|
(FRAME_RATE_MAX * timeperframe->numerator);
|
|
else
|
|
pclk = pclk_max;
|
|
|
|
if (pclk_limit && pclk_limit < pclk)
|
|
pclk = pclk_limit;
|
|
|
|
return (pclk_max - 1) / pclk;
|
|
}
|
|
|
|
/* set the format we will capture in */
|
|
static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd);
|
|
struct soc_camera_sense *sense = icd->sense;
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
bool half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect);
|
|
struct v4l2_subdev_selection sel = {
|
|
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
|
|
.target = V4L2_SEL_TGT_CROP,
|
|
.r.left = priv->rect.left + (priv->rect.width >> 1) -
|
|
(mf->width >> (1 - half_scale)),
|
|
.r.top = priv->rect.top + (priv->rect.height >> 1) -
|
|
(mf->height >> (1 - half_scale)),
|
|
.r.width = mf->width << half_scale,
|
|
.r.height = mf->height << half_scale,
|
|
};
|
|
u32 code = mf->code;
|
|
unsigned long mclk, pclk;
|
|
u8 coma_set = 0, coma_mask = 0, coml_set, coml_mask, clkrc;
|
|
int ret;
|
|
|
|
/* select color matrix configuration for given color encoding */
|
|
switch (code) {
|
|
case MEDIA_BUS_FMT_Y8_1X8:
|
|
dev_dbg(&client->dev, "pixel format GREY8_1X8\n");
|
|
coma_mask |= COMA_RGB | COMA_WORD_SWAP | COMA_BYTE_SWAP;
|
|
coma_set |= COMA_BW;
|
|
break;
|
|
case MEDIA_BUS_FMT_YUYV8_2X8:
|
|
dev_dbg(&client->dev, "pixel format YUYV8_2X8_LE\n");
|
|
coma_mask |= COMA_RGB | COMA_BW | COMA_BYTE_SWAP;
|
|
coma_set |= COMA_WORD_SWAP;
|
|
break;
|
|
case MEDIA_BUS_FMT_YVYU8_2X8:
|
|
dev_dbg(&client->dev, "pixel format YVYU8_2X8_LE (untested)\n");
|
|
coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP |
|
|
COMA_BYTE_SWAP;
|
|
break;
|
|
case MEDIA_BUS_FMT_UYVY8_2X8:
|
|
dev_dbg(&client->dev, "pixel format YUYV8_2X8_BE\n");
|
|
if (half_scale) {
|
|
coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP;
|
|
coma_set |= COMA_BYTE_SWAP;
|
|
} else {
|
|
coma_mask |= COMA_RGB | COMA_BW;
|
|
coma_set |= COMA_BYTE_SWAP | COMA_WORD_SWAP;
|
|
}
|
|
break;
|
|
case MEDIA_BUS_FMT_VYUY8_2X8:
|
|
dev_dbg(&client->dev, "pixel format YVYU8_2X8_BE (untested)\n");
|
|
if (half_scale) {
|
|
coma_mask |= COMA_RGB | COMA_BW;
|
|
coma_set |= COMA_BYTE_SWAP | COMA_WORD_SWAP;
|
|
} else {
|
|
coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP;
|
|
coma_set |= COMA_BYTE_SWAP;
|
|
}
|
|
break;
|
|
case MEDIA_BUS_FMT_SBGGR8_1X8:
|
|
dev_dbg(&client->dev, "pixel format SBGGR8_1X8 (untested)\n");
|
|
coma_mask |= COMA_BW | COMA_BYTE_SWAP | COMA_WORD_SWAP;
|
|
coma_set |= COMA_RAW_RGB | COMA_RGB;
|
|
break;
|
|
default:
|
|
dev_err(&client->dev, "Pixel format not handled: 0x%x\n", code);
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (code == MEDIA_BUS_FMT_Y8_1X8 ||
|
|
code == MEDIA_BUS_FMT_SBGGR8_1X8) {
|
|
coml_mask = COML_ONE_CHANNEL;
|
|
coml_set = 0;
|
|
priv->pclk_max = 4000000;
|
|
} else {
|
|
coml_mask = 0;
|
|
coml_set = COML_ONE_CHANNEL;
|
|
priv->pclk_max = 8000000;
|
|
}
|
|
|
|
if (half_scale) {
|
|
dev_dbg(&client->dev, "max resolution: QCIF\n");
|
|
coma_set |= COMA_QCIF;
|
|
priv->pclk_max /= 2;
|
|
} else {
|
|
dev_dbg(&client->dev, "max resolution: CIF\n");
|
|
coma_mask |= COMA_QCIF;
|
|
}
|
|
|
|
if (sense) {
|
|
if (sense->master_clock == 8000000) {
|
|
dev_dbg(&client->dev, "8MHz input clock\n");
|
|
clkrc = CLKRC_6MHz;
|
|
} else if (sense->master_clock == 12000000) {
|
|
dev_dbg(&client->dev, "12MHz input clock\n");
|
|
clkrc = CLKRC_12MHz;
|
|
} else if (sense->master_clock == 16000000) {
|
|
dev_dbg(&client->dev, "16MHz input clock\n");
|
|
clkrc = CLKRC_16MHz;
|
|
} else if (sense->master_clock == 24000000) {
|
|
dev_dbg(&client->dev, "24MHz input clock\n");
|
|
clkrc = CLKRC_24MHz;
|
|
} else {
|
|
dev_err(&client->dev,
|
|
"unsupported input clock, check platform data\n");
|
|
return -EINVAL;
|
|
}
|
|
mclk = sense->master_clock;
|
|
priv->pclk_limit = sense->pixel_clock_max;
|
|
} else {
|
|
clkrc = CLKRC_24MHz;
|
|
mclk = 24000000;
|
|
priv->pclk_limit = 0;
|
|
dev_dbg(&client->dev, "using default 24MHz input clock\n");
|
|
}
|
|
|
|
clkrc |= to_clkrc(&priv->tpf, priv->pclk_limit, priv->pclk_max);
|
|
|
|
pclk = priv->pclk_max / GET_CLKRC_DIV(clkrc);
|
|
dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n",
|
|
mclk / pclk, 10 * mclk % pclk / pclk);
|
|
|
|
ret = ov6650_set_selection(sd, NULL, &sel);
|
|
if (!ret)
|
|
ret = ov6650_reg_rmw(client, REG_COMA, coma_set, coma_mask);
|
|
if (!ret)
|
|
ret = ov6650_reg_write(client, REG_CLKRC, clkrc);
|
|
if (!ret) {
|
|
priv->half_scale = half_scale;
|
|
|
|
ret = ov6650_reg_rmw(client, REG_COML, coml_set, coml_mask);
|
|
}
|
|
if (!ret)
|
|
priv->code = code;
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int ov6650_set_fmt(struct v4l2_subdev *sd,
|
|
struct v4l2_subdev_pad_config *cfg,
|
|
struct v4l2_subdev_format *format)
|
|
{
|
|
struct v4l2_mbus_framefmt *mf = &format->format;
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
if (format->pad)
|
|
return -EINVAL;
|
|
|
|
if (is_unscaled_ok(mf->width, mf->height, &priv->rect))
|
|
v4l_bound_align_image(&mf->width, 2, W_CIF, 1,
|
|
&mf->height, 2, H_CIF, 1, 0);
|
|
|
|
switch (mf->code) {
|
|
case MEDIA_BUS_FMT_Y10_1X10:
|
|
mf->code = MEDIA_BUS_FMT_Y8_1X8;
|
|
case MEDIA_BUS_FMT_Y8_1X8:
|
|
case MEDIA_BUS_FMT_YVYU8_2X8:
|
|
case MEDIA_BUS_FMT_YUYV8_2X8:
|
|
case MEDIA_BUS_FMT_VYUY8_2X8:
|
|
case MEDIA_BUS_FMT_UYVY8_2X8:
|
|
break;
|
|
default:
|
|
mf->code = MEDIA_BUS_FMT_SBGGR8_1X8;
|
|
case MEDIA_BUS_FMT_SBGGR8_1X8:
|
|
break;
|
|
}
|
|
|
|
if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
|
|
/* store media bus format code and frame size in pad config */
|
|
cfg->try_fmt.width = mf->width;
|
|
cfg->try_fmt.height = mf->height;
|
|
cfg->try_fmt.code = mf->code;
|
|
|
|
/* return default mbus frame format updated with pad config */
|
|
*mf = ov6650_def_fmt;
|
|
mf->width = cfg->try_fmt.width;
|
|
mf->height = cfg->try_fmt.height;
|
|
mf->code = cfg->try_fmt.code;
|
|
|
|
} else {
|
|
/* apply new media bus format code and frame size */
|
|
int ret = ov6650_s_fmt(sd, mf);
|
|
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* return default format updated with active size and code */
|
|
*mf = ov6650_def_fmt;
|
|
mf->width = priv->rect.width >> priv->half_scale;
|
|
mf->height = priv->rect.height >> priv->half_scale;
|
|
mf->code = priv->code;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int ov6650_enum_mbus_code(struct v4l2_subdev *sd,
|
|
struct v4l2_subdev_pad_config *cfg,
|
|
struct v4l2_subdev_mbus_code_enum *code)
|
|
{
|
|
if (code->pad || code->index >= ARRAY_SIZE(ov6650_codes))
|
|
return -EINVAL;
|
|
|
|
code->code = ov6650_codes[code->index];
|
|
return 0;
|
|
}
|
|
|
|
static int ov6650_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
struct v4l2_captureparm *cp = &parms->parm.capture;
|
|
|
|
if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
|
return -EINVAL;
|
|
|
|
memset(cp, 0, sizeof(*cp));
|
|
cp->capability = V4L2_CAP_TIMEPERFRAME;
|
|
cp->timeperframe.numerator = GET_CLKRC_DIV(to_clkrc(&priv->tpf,
|
|
priv->pclk_limit, priv->pclk_max));
|
|
cp->timeperframe.denominator = FRAME_RATE_MAX;
|
|
|
|
dev_dbg(&client->dev, "Frame interval: %u/%u s\n",
|
|
cp->timeperframe.numerator, cp->timeperframe.denominator);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ov6650_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
struct v4l2_captureparm *cp = &parms->parm.capture;
|
|
struct v4l2_fract *tpf = &cp->timeperframe;
|
|
int div, ret;
|
|
u8 clkrc;
|
|
|
|
if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
|
return -EINVAL;
|
|
|
|
if (cp->extendedmode != 0)
|
|
return -EINVAL;
|
|
|
|
if (tpf->numerator == 0 || tpf->denominator == 0)
|
|
div = 1; /* Reset to full rate */
|
|
else
|
|
div = (tpf->numerator * FRAME_RATE_MAX) / tpf->denominator;
|
|
|
|
if (div == 0)
|
|
div = 1;
|
|
else if (div > GET_CLKRC_DIV(CLKRC_DIV_MASK))
|
|
div = GET_CLKRC_DIV(CLKRC_DIV_MASK);
|
|
|
|
/*
|
|
* Keep result to be used as tpf limit
|
|
* for subseqent clock divider calculations
|
|
*/
|
|
priv->tpf.numerator = div;
|
|
priv->tpf.denominator = FRAME_RATE_MAX;
|
|
|
|
clkrc = to_clkrc(&priv->tpf, priv->pclk_limit, priv->pclk_max);
|
|
|
|
ret = ov6650_reg_rmw(client, REG_CLKRC, clkrc, CLKRC_DIV_MASK);
|
|
if (!ret) {
|
|
tpf->numerator = GET_CLKRC_DIV(clkrc);
|
|
tpf->denominator = FRAME_RATE_MAX;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* Soft reset the camera. This has nothing to do with the RESET pin! */
|
|
static int ov6650_reset(struct i2c_client *client)
|
|
{
|
|
int ret;
|
|
|
|
dev_dbg(&client->dev, "reset\n");
|
|
|
|
ret = ov6650_reg_rmw(client, REG_COMA, COMA_RESET, 0);
|
|
if (ret)
|
|
dev_err(&client->dev,
|
|
"An error occurred while entering soft reset!\n");
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* program default register values */
|
|
static int ov6650_prog_dflt(struct i2c_client *client)
|
|
{
|
|
int ret;
|
|
|
|
dev_dbg(&client->dev, "initializing\n");
|
|
|
|
ret = ov6650_reg_write(client, REG_COMA, 0); /* ~COMA_RESET */
|
|
if (!ret)
|
|
ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_BAND_FILTER);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int ov6650_video_probe(struct i2c_client *client)
|
|
{
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
u8 pidh, pidl, midh, midl;
|
|
int ret;
|
|
|
|
priv->clk = v4l2_clk_get(&client->dev, NULL);
|
|
if (IS_ERR(priv->clk)) {
|
|
ret = PTR_ERR(priv->clk);
|
|
dev_err(&client->dev, "v4l2_clk request err: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = ov6650_s_power(&priv->subdev, 1);
|
|
if (ret < 0)
|
|
goto eclkput;
|
|
|
|
msleep(20);
|
|
|
|
/*
|
|
* check and show product ID and manufacturer ID
|
|
*/
|
|
ret = ov6650_reg_read(client, REG_PIDH, &pidh);
|
|
if (!ret)
|
|
ret = ov6650_reg_read(client, REG_PIDL, &pidl);
|
|
if (!ret)
|
|
ret = ov6650_reg_read(client, REG_MIDH, &midh);
|
|
if (!ret)
|
|
ret = ov6650_reg_read(client, REG_MIDL, &midl);
|
|
|
|
if (ret)
|
|
goto done;
|
|
|
|
if ((pidh != OV6650_PIDH) || (pidl != OV6650_PIDL)) {
|
|
dev_err(&client->dev, "Product ID error 0x%02x:0x%02x\n",
|
|
pidh, pidl);
|
|
ret = -ENODEV;
|
|
goto done;
|
|
}
|
|
|
|
dev_info(&client->dev,
|
|
"ov6650 Product ID 0x%02x:0x%02x Manufacturer ID 0x%02x:0x%02x\n",
|
|
pidh, pidl, midh, midl);
|
|
|
|
ret = ov6650_reset(client);
|
|
if (!ret)
|
|
ret = ov6650_prog_dflt(client);
|
|
if (!ret)
|
|
ret = v4l2_ctrl_handler_setup(&priv->hdl);
|
|
|
|
done:
|
|
ov6650_s_power(&priv->subdev, 0);
|
|
if (!ret)
|
|
return 0;
|
|
eclkput:
|
|
v4l2_clk_put(priv->clk);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static const struct v4l2_ctrl_ops ov6550_ctrl_ops = {
|
|
.g_volatile_ctrl = ov6550_g_volatile_ctrl,
|
|
.s_ctrl = ov6550_s_ctrl,
|
|
};
|
|
|
|
static struct v4l2_subdev_core_ops ov6650_core_ops = {
|
|
#ifdef CONFIG_VIDEO_ADV_DEBUG
|
|
.g_register = ov6650_get_register,
|
|
.s_register = ov6650_set_register,
|
|
#endif
|
|
.s_power = ov6650_s_power,
|
|
};
|
|
|
|
/* Request bus settings on camera side */
|
|
static int ov6650_g_mbus_config(struct v4l2_subdev *sd,
|
|
struct v4l2_mbus_config *cfg)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
|
|
|
|
cfg->flags = V4L2_MBUS_MASTER |
|
|
V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
|
|
V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
|
|
V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
|
|
V4L2_MBUS_DATA_ACTIVE_HIGH;
|
|
cfg->type = V4L2_MBUS_PARALLEL;
|
|
cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Alter bus settings on camera side */
|
|
static int ov6650_s_mbus_config(struct v4l2_subdev *sd,
|
|
const struct v4l2_mbus_config *cfg)
|
|
{
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
|
|
unsigned long flags = soc_camera_apply_board_flags(ssdd, cfg);
|
|
int ret;
|
|
|
|
if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
|
|
ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_PCLK_RISING, 0);
|
|
else
|
|
ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_PCLK_RISING);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
|
|
ret = ov6650_reg_rmw(client, REG_COMF, COMF_HREF_LOW, 0);
|
|
else
|
|
ret = ov6650_reg_rmw(client, REG_COMF, 0, COMF_HREF_LOW);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
|
|
ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_VSYNC_HIGH, 0);
|
|
else
|
|
ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_VSYNC_HIGH);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static struct v4l2_subdev_video_ops ov6650_video_ops = {
|
|
.s_stream = ov6650_s_stream,
|
|
.g_parm = ov6650_g_parm,
|
|
.s_parm = ov6650_s_parm,
|
|
.g_mbus_config = ov6650_g_mbus_config,
|
|
.s_mbus_config = ov6650_s_mbus_config,
|
|
};
|
|
|
|
static const struct v4l2_subdev_pad_ops ov6650_pad_ops = {
|
|
.enum_mbus_code = ov6650_enum_mbus_code,
|
|
.get_selection = ov6650_get_selection,
|
|
.set_selection = ov6650_set_selection,
|
|
.get_fmt = ov6650_get_fmt,
|
|
.set_fmt = ov6650_set_fmt,
|
|
};
|
|
|
|
static struct v4l2_subdev_ops ov6650_subdev_ops = {
|
|
.core = &ov6650_core_ops,
|
|
.video = &ov6650_video_ops,
|
|
.pad = &ov6650_pad_ops,
|
|
};
|
|
|
|
/*
|
|
* i2c_driver function
|
|
*/
|
|
static int ov6650_probe(struct i2c_client *client,
|
|
const struct i2c_device_id *did)
|
|
{
|
|
struct ov6650 *priv;
|
|
struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
|
|
int ret;
|
|
|
|
if (!ssdd) {
|
|
dev_err(&client->dev, "Missing platform_data for driver\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
|
|
if (!priv) {
|
|
dev_err(&client->dev,
|
|
"Failed to allocate memory for private data!\n");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops);
|
|
v4l2_ctrl_handler_init(&priv->hdl, 13);
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_VFLIP, 0, 1, 1, 0);
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_HFLIP, 0, 1, 1, 0);
|
|
priv->autogain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
|
|
priv->gain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_GAIN, 0, 0x3f, 1, DEF_GAIN);
|
|
priv->autowb = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
|
|
priv->blue = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_BLUE_BALANCE, 0, 0xff, 1, DEF_BLUE);
|
|
priv->red = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_RED_BALANCE, 0, 0xff, 1, DEF_RED);
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_SATURATION, 0, 0xf, 1, 0x8);
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_HUE, 0, HUE_MASK, 1, DEF_HUE);
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_BRIGHTNESS, 0, 0xff, 1, 0x80);
|
|
priv->autoexposure = v4l2_ctrl_new_std_menu(&priv->hdl,
|
|
&ov6550_ctrl_ops, V4L2_CID_EXPOSURE_AUTO,
|
|
V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
|
|
priv->exposure = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_EXPOSURE, 0, 0xff, 1, DEF_AECH);
|
|
v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
|
|
V4L2_CID_GAMMA, 0, 0xff, 1, 0x12);
|
|
|
|
priv->subdev.ctrl_handler = &priv->hdl;
|
|
if (priv->hdl.error)
|
|
return priv->hdl.error;
|
|
|
|
v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true);
|
|
v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true);
|
|
v4l2_ctrl_auto_cluster(2, &priv->autoexposure,
|
|
V4L2_EXPOSURE_MANUAL, true);
|
|
|
|
priv->rect.left = DEF_HSTRT << 1;
|
|
priv->rect.top = DEF_VSTRT << 1;
|
|
priv->rect.width = W_CIF;
|
|
priv->rect.height = H_CIF;
|
|
priv->half_scale = false;
|
|
priv->code = MEDIA_BUS_FMT_YUYV8_2X8;
|
|
|
|
ret = ov6650_video_probe(client);
|
|
if (ret)
|
|
v4l2_ctrl_handler_free(&priv->hdl);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int ov6650_remove(struct i2c_client *client)
|
|
{
|
|
struct ov6650 *priv = to_ov6650(client);
|
|
|
|
v4l2_clk_put(priv->clk);
|
|
v4l2_device_unregister_subdev(&priv->subdev);
|
|
v4l2_ctrl_handler_free(&priv->hdl);
|
|
return 0;
|
|
}
|
|
|
|
static const struct i2c_device_id ov6650_id[] = {
|
|
{ "ov6650", 0 },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(i2c, ov6650_id);
|
|
|
|
static struct i2c_driver ov6650_i2c_driver = {
|
|
.driver = {
|
|
.name = "ov6650",
|
|
},
|
|
.probe = ov6650_probe,
|
|
.remove = ov6650_remove,
|
|
.id_table = ov6650_id,
|
|
};
|
|
|
|
module_i2c_driver(ov6650_i2c_driver);
|
|
|
|
MODULE_DESCRIPTION("SoC Camera driver for OmniVision OV6650");
|
|
MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
|
|
MODULE_LICENSE("GPL v2");
|