Changes in 4.9.311 USB: serial: pl2303: add IBM device IDs USB: serial: simple: add Nokia phone driver netdevice: add the case if dev is NULL virtio_console: break out of buf poll on remove ethernet: sun: Free the coherent when failing in probing af_key: add __GFP_ZERO flag for compose_sadb_supported in function pfkey_register block: Add a helper to validate the block size virtio-blk: Use blk_validate_block_size() to validate block size USB: usb-storage: Fix use of bitfields for hardware data in ene_ub6250.c coresight: Fix TRCCONFIGR.QE sysfs interface iio: inkern: apply consumer scale on IIO_VAL_INT cases iio: inkern: make a best effort on offset calculation clk: uniphier: Fix fixed-rate initialization ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE SUNRPC: avoid race between mod_timer() and del_timer_sync() NFSD: prevent underflow in nfssvc_decode_writeargs() can: ems_usb: ems_usb_start_xmit(): fix double dev_kfree_skb() in error path jffs2: fix use-after-free in jffs2_clear_xattr_subsystem jffs2: fix memory leak in jffs2_do_mount_fs jffs2: fix memory leak in jffs2_scan_medium mm/pages_alloc.c: don't create ZONE_MOVABLE beyond the end of a node mempolicy: mbind_range() set_policy() after vma_merge() scsi: libsas: Fix sas_ata_qc_issue() handling of NCQ NON DATA commands Revert "Input: clear BTN_RIGHT/MIDDLE on buttonpads" ALSA: cs4236: fix an incorrect NULL check on list iterator drivers: hamradio: 6pack: fix UAF bug caused by mod_timer() video: fbdev: sm712fb: Fix crash in smtcfb_read() video: fbdev: atari: Atari 2 bpp (STe) palette bugfix ARM: dts: exynos: fix UART3 pins configuration in Exynos5250 ARM: dts: exynos: add missing HDMI supplies on SMDK5250 ARM: dts: exynos: add missing HDMI supplies on SMDK5420 carl9170: fix missing bit-wise or operator for tx_params thermal: int340x: Increase bitmap size lib/raid6/test: fix multiple definition linking error DEC: Limit PMAX memory probing to R3k systems media: davinci: vpif: fix unbalanced runtime PM get brcmfmac: firmware: Allocate space for default boardrev in nvram brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev with memcpy_toio PCI: pciehp: Clear cmd_busy bit in polling mode crypto: authenc - Fix sleep in atomic context in decrypt_tail crypto: mxs-dcp - Fix scatterlist processing spi: tegra114: Add missing IRQ check in tegra_spi_probe selftests/x86: Add validity check and allow field splitting hwmon: (pmbus) Add mutex to regulator ops hwmon: (sch56xx-common) Replace WDOG_ACTIVE with WDOG_HW_RUNNING PM: hibernate: fix __setup handler error handling PM: suspend: fix return value of __setup handler crypto: vmx - add missing dependencies crypto: ccp - ccp_dmaengine_unregister release dma channels hwmon: (pmbus) Add Vin unit off handling clocksource: acpi_pm: fix return value of __setup handler sched/debug: Remove mpol_get/put and task_lock/unlock from sched_show_numa perf/core: Fix address filter parser for multiple filters perf/x86/intel/pt: Fix address filter config for 32-bit kernel video: fbdev: smscufx: Fix null-ptr-deref in ufx_usb_probe() video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name() ARM: dts: qcom: ipq4019: fix sleep clock soc: ti: wkup_m3_ipc: Fix IRQ check in wkup_m3_ipc_probe media: usb: go7007: s2250-board: fix leak in probe() ASoC: ti: davinci-i2s: Add check for clk_enable() ALSA: spi: Add check for clk_enable() arm64: dts: ns2: Fix spi-cpol and spi-cpha property arm64: dts: broadcom: Fix sata nodename printk: fix return value of printk.devkmsg __setup handler ASoC: mxs-saif: Handle errors for clk_enable ASoC: atmel_ssc_dai: Handle errors for clk_enable memory: emif: Add check for setup_interrupts memory: emif: check the pointer temp in get_device_details() ALSA: firewire-lib: fix uninitialized flag for AV/C deferred transaction ASoC: atmel: Add missing of_node_put() in at91sam9g20ek_audio_probe ASoC: wm8350: Handle error for wm8350_register_irq ASoC: fsi: Add check for clk_enable video: fbdev: omapfb: Add missing of_node_put() in dvic_probe_of ASoC: dmaengine: do not use a NULL prepare_slave_config() callback ASoC: mxs: Fix error handling in mxs_sgtl5000_probe ASoC: imx-es8328: Fix error return code in imx_es8328_probe() mtd: onenand: Check for error irq drm/edid: Don't clear formats if using deep color ath9k_htc: fix uninit value bugs ray_cs: Check ioremap return value power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init HID: i2c-hid: fix GET/SET_REPORT for unnumbered reports iwlwifi: Fix -EIO error code that is never returned scsi: pm8001: Fix command initialization in pm80XX_send_read_log() scsi: pm8001: Fix command initialization in pm8001_chip_ssp_tm_req() scsi: pm8001: Fix payload initialization in pm80xx_set_thermal_config() scsi: pm8001: Fix abort all task initialization TOMOYO: fix __setup handlers return values ext2: correct max file size computing drm/tegra: Fix reference leak in tegra_dsi_ganged_probe KVM: x86: Fix emulation in writing cr8 KVM: x86/emulator: Defer not-present segment check in __load_segment_descriptor() i2c: xiic: Make bus names unique power: supply: wm8350-power: Handle error for wm8350_register_irq power: supply: wm8350-power: Add missing free in free_charger_irq powerpc/sysdev: fix incorrect use to determine if list is empty mfd: mc13xxx: Add check for mc13xxx_irq_request MIPS: RB532: fix return value of __setup handler USB: storage: ums-realtek: fix error code in rts51x_read_mem() af_netlink: Fix shift out of bounds in group mask calculation i2c: mux: demux-pinctrl: do not deactivate a master that is not active mfd: asic3: Add missing iounmap() on error asic3_mfd_probe mxser: fix xmit_buf leak in activate when LSR == 0xff pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() iio: adc: Add check for devm_request_threaded_irq clk: qcom: clk-rcg2: Update the frac table for pixel clock remoteproc: qcom_wcnss: Add missing of_node_put() in wcnss_alloc_memory_region clk: loongson1: Terminate clk_div_table with sentinel element clk: clps711x: Terminate clk_div_table with sentinel element clk: tegra: tegra124-emc: Fix missing put_device() call in emc_ensure_emc_driver NFS: remove unneeded check in decode_devicenotify_args() pinctrl: mediatek: Fix missing of_node_put() in mtk_pctrl_init pinctrl: nomadik: Add missing of_node_put() in nmk_pinctrl_probe pinctrl/rockchip: Add missing of_node_put() in rockchip_pinctrl_probe tty: hvc: fix return value of __setup handler kgdboc: fix return value of __setup handler kgdbts: fix return value of __setup handler jfs: fix divide error in dbNextAG netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options net: phy: broadcom: Fix brcm_fet_config_init() qlcnic: dcb: default to returning -EOPNOTSUPP net/x25: Fix null-ptr-deref caused by x25_disconnect selinux: use correct type for context length loop: use sysfs_emit() in the sysfs xxx show() Fix incorrect type in assignment of ipv6 port for audit irqchip/nvic: Release nvic_base upon failure ACPICA: Avoid walking the ACPI Namespace if it is not there ACPI/APEI: Limit printable size of BERT table data PM: core: keep irq flags in device_pm_check_callbacks() spi: tegra20: Use of_device_get_match_data() ext4: don't BUG if someone dirty pages without asking ext4 first ntfs: add sanity check on allocation size video: fbdev: nvidiafb: Use strscpy() to prevent buffer overflow video: fbdev: w100fb: Reset global state video: fbdev: cirrusfb: check pixclock to avoid divide by zero video: fbdev: omapfb: acx565akm: replace snprintf with sysfs_emit ARM: dts: qcom: fix gic_irq_domain_translate warnings for msm8960 ARM: dts: bcm2837: Add the missing L1/L2 cache information video: fbdev: omapfb: panel-dsi-cm: Use sysfs_emit() instead of snprintf() video: fbdev: omapfb: panel-tpo-td043mtea1: Use sysfs_emit() instead of snprintf() ASoC: soc-core: skip zero num_dai component in searching dai name media: cx88-mpeg: clear interrupt status register before streaming video ARM: tegra: tamonten: Fix I2C3 pad setting ARM: mmp: Fix failure to remove sram device video: fbdev: sm712fb: Fix crash in smtcfb_write() media: hdpvr: initialize dev->worker at hdpvr_register_videodev mmc: host: Return an error when ->enable_sdio_irq() ops is missing scsi: qla2xxx: Fix incorrect reporting of task management failure KVM: Prevent module exit until all VMs are freed ubifs: Add missing iput if do_tmpfile() failed in rename whiteout ubifs: setflags: Make dirtied_ino_d 8 bytes aligned gfs2: Make sure FITRIM minlen is rounded up to fs block size pinctrl: pinconf-generic: Print arguments for bias-pull-* ACPI: CPPC: Avoid out of bounds access when parsing _CPC data mm/mmap: return 1 from stack_guard_gap __setup() handler mm/memcontrol: return 1 from cgroup.memory __setup() handler ubi: fastmap: Return error code if memory allocation fails in add_aeb() ASoC: topology: Allow TLV control to be either read or write ARM: dts: spear1340: Update serial node properties ARM: dts: spear13xx: Update SPI dma properties openvswitch: Fixed nd target mask field in the flow dump. KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated rtc: wm8350: Handle error for wm8350_register_irq ARM: 9187/1: JIVE: fix return value of __setup handler KVM: x86/svm: Clear reserved bits written to PerfEvtSeln MSRs ath5k: fix OOB in ath5k_eeprom_read_pcal_info_5111 ptp: replace snprintf with sysfs_emit powerpc: dts: t104xrdb: fix phy type for FMAN 4/5 scsi: mvsas: Replace snprintf() with sysfs_emit() scsi: bfa: Replace snprintf() with sysfs_emit() iommu/arm-smmu-v3: fix event handling soft lockup dm ioctl: prevent potential spectre v1 gadget scsi: pm8001: Fix pm8001_mpi_task_abort_resp() scsi: aha152x: Fix aha152x_setup() __setup handler return value bnxt_en: Eliminate unintended link toggle during FW reset MIPS: fix fortify panic when copying asm exception handlers scsi: libfc: Fix use after free in fc_exch_abts_resp() usb: dwc3: omap: fix "unbalanced disables for smps10_out1" on omap5evm xtensa: fix DTC warning unit_address_format Bluetooth: Fix use after free in hci_send_acl init/main.c: return 1 from handled __setup() functions w1: w1_therm: fixes w1_seq for ds28ea00 sensors SUNRPC/call_alloc: async tasks mustn't block waiting for memory serial: samsung_tty: do not unlock port->lock for uart_write_wakeup() virtio_console: eliminate anonymous module_init & module_exit jfs: prevent NULL deref in diFree mm: fix race between MADV_FREE reclaim and blkdev direct IO read scsi: zorro7xx: Fix a resource leak in zorro7xx_remove_one() net: stmmac: Fix unset max_speed difference between DT and non-DT platforms drm/imx: Fix memory leak in imx_pd_connector_get_modes drbd: Fix five use after free bugs in get_initial_state mmmremap.c: avoid pointless invalidate_range_start/end on mremap(old_size=0) mm/mempolicy: fix mpol_new leak in shared_policy_replace x86/pm: Save the MSR validity status at context setup x86/speculation: Restore speculation related MSRs during S3 resume arm64: patch_text: Fixup last cpu should be master tools build: Use $(shell ) instead of `` to get embedded libperl's ccopts dmaengine: Revert "dmaengine: shdma: Fix runtime PM imbalance on error" mm: don't skip swap entry even if zap_details specified arm64: module: remove (NOLOAD) from linker script xfrm: policy: match with both mark and mask on user interfaces veth: Ensure eth header is in skb's linear part net: ethernet: stmmac: fix altr_tse_pcs function when using a fixed-link nfc: nci: add flush_workqueue to prevent uaf cifs: potential buffer overflow in handling symlinks drm/amdkfd: Check for potential null return of kmalloc_array() scsi: ibmvscsis: Increase INITIAL_SRP_LIMIT to 1024 net: micrel: fix KS8851_MLL Kconfig gpu: ipu-v3: Fix dev_dbg frequency output scsi: mvsas: Add PCI ID of RocketRaid 2640 drivers: net: slip: fix NPD bug in sl_tx_timeout() mm, page_alloc: fix build_zonerefs_node() mm: kmemleak: take a full lowmem check in kmemleak_*_phys() ALSA: pcm: Test for "silence" field in struct "pcm_format_data" ARM: davinci: da850-evm: Avoid NULL pointer dereference smp: Fix offline cpu check in flush_smp_call_function_queue() i2c: pasemi: Wait for write xfers to finish gcc-plugins: latent_entropy: use /dev/urandom Linux 4.9.311 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ia8f55c5ae2f0eb71b0893d8271a10dfd3c78b3b8
638 lines
14 KiB
C
638 lines
14 KiB
C
/*
|
|
* Copyright (C) 2008 Sensoray Company Inc.
|
|
*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/usb.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/videodev2.h>
|
|
#include <linux/slab.h>
|
|
#include <media/v4l2-device.h>
|
|
#include <media/v4l2-common.h>
|
|
#include <media/v4l2-subdev.h>
|
|
#include "go7007-priv.h"
|
|
|
|
MODULE_DESCRIPTION("Sensoray 2250/2251 i2c v4l2 subdev driver");
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
/*
|
|
* Note: this board has two i2c devices: a vpx3226f and a tlv320aic23b.
|
|
* Due to the unusual way these are accessed on this device we do not
|
|
* reuse the i2c drivers, but instead they are implemented in this
|
|
* driver. It would be nice to improve on this, though.
|
|
*/
|
|
|
|
#define TLV320_ADDRESS 0x34
|
|
#define VPX322_ADDR_ANALOGCONTROL1 0x02
|
|
#define VPX322_ADDR_BRIGHTNESS0 0x0127
|
|
#define VPX322_ADDR_BRIGHTNESS1 0x0131
|
|
#define VPX322_ADDR_CONTRAST0 0x0128
|
|
#define VPX322_ADDR_CONTRAST1 0x0132
|
|
#define VPX322_ADDR_HUE 0x00dc
|
|
#define VPX322_ADDR_SAT 0x0030
|
|
|
|
struct go7007_usb_board {
|
|
unsigned int flags;
|
|
struct go7007_board_info main_info;
|
|
};
|
|
|
|
struct go7007_usb {
|
|
struct go7007_usb_board *board;
|
|
struct mutex i2c_lock;
|
|
struct usb_device *usbdev;
|
|
struct urb *video_urbs[8];
|
|
struct urb *audio_urbs[8];
|
|
struct urb *intr_urb;
|
|
};
|
|
|
|
static unsigned char aud_regs[] = {
|
|
0x1e, 0x00,
|
|
0x00, 0x17,
|
|
0x02, 0x17,
|
|
0x04, 0xf9,
|
|
0x06, 0xf9,
|
|
0x08, 0x02,
|
|
0x0a, 0x00,
|
|
0x0c, 0x00,
|
|
0x0a, 0x00,
|
|
0x0c, 0x00,
|
|
0x0e, 0x02,
|
|
0x10, 0x00,
|
|
0x12, 0x01,
|
|
0x00, 0x00,
|
|
};
|
|
|
|
|
|
static unsigned char vid_regs[] = {
|
|
0xF2, 0x0f,
|
|
0xAA, 0x00,
|
|
0xF8, 0xff,
|
|
0x00, 0x00,
|
|
};
|
|
|
|
static u16 vid_regs_fp[] = {
|
|
0x028, 0x067,
|
|
0x120, 0x016,
|
|
0x121, 0xcF2,
|
|
0x122, 0x0F2,
|
|
0x123, 0x00c,
|
|
0x124, 0x2d0,
|
|
0x125, 0x2e0,
|
|
0x126, 0x004,
|
|
0x128, 0x1E0,
|
|
0x12A, 0x016,
|
|
0x12B, 0x0F2,
|
|
0x12C, 0x0F2,
|
|
0x12D, 0x00c,
|
|
0x12E, 0x2d0,
|
|
0x12F, 0x2e0,
|
|
0x130, 0x004,
|
|
0x132, 0x1E0,
|
|
0x140, 0x060,
|
|
0x153, 0x00C,
|
|
0x154, 0x200,
|
|
0x150, 0x801,
|
|
0x000, 0x000
|
|
};
|
|
|
|
/* PAL specific values */
|
|
static u16 vid_regs_fp_pal[] = {
|
|
0x120, 0x017,
|
|
0x121, 0xd22,
|
|
0x122, 0x122,
|
|
0x12A, 0x017,
|
|
0x12B, 0x122,
|
|
0x12C, 0x122,
|
|
0x140, 0x060,
|
|
0x000, 0x000,
|
|
};
|
|
|
|
struct s2250 {
|
|
struct v4l2_subdev sd;
|
|
struct v4l2_ctrl_handler hdl;
|
|
v4l2_std_id std;
|
|
int input;
|
|
int brightness;
|
|
int contrast;
|
|
int saturation;
|
|
int hue;
|
|
int reg12b_val;
|
|
int audio_input;
|
|
struct i2c_client *audio;
|
|
};
|
|
|
|
static inline struct s2250 *to_state(struct v4l2_subdev *sd)
|
|
{
|
|
return container_of(sd, struct s2250, sd);
|
|
}
|
|
|
|
/* from go7007-usb.c which is Copyright (C) 2005-2006 Micronas USA Inc.*/
|
|
static int go7007_usb_vendor_request(struct go7007 *go, u16 request,
|
|
u16 value, u16 index, void *transfer_buffer, int length, int in)
|
|
{
|
|
struct go7007_usb *usb = go->hpi_context;
|
|
int timeout = 5000;
|
|
|
|
if (in) {
|
|
return usb_control_msg(usb->usbdev,
|
|
usb_rcvctrlpipe(usb->usbdev, 0), request,
|
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
|
|
value, index, transfer_buffer, length, timeout);
|
|
} else {
|
|
return usb_control_msg(usb->usbdev,
|
|
usb_sndctrlpipe(usb->usbdev, 0), request,
|
|
USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
|
value, index, transfer_buffer, length, timeout);
|
|
}
|
|
}
|
|
/* end from go7007-usb.c which is Copyright (C) 2005-2006 Micronas USA Inc.*/
|
|
|
|
static int write_reg(struct i2c_client *client, u8 reg, u8 value)
|
|
{
|
|
struct go7007 *go = i2c_get_adapdata(client->adapter);
|
|
struct go7007_usb *usb;
|
|
int rc;
|
|
int dev_addr = client->addr << 1; /* firmware wants 8-bit address */
|
|
u8 *buf;
|
|
|
|
if (go == NULL)
|
|
return -ENODEV;
|
|
|
|
if (go->status == STATUS_SHUTDOWN)
|
|
return -EBUSY;
|
|
|
|
buf = kzalloc(16, GFP_KERNEL);
|
|
if (buf == NULL)
|
|
return -ENOMEM;
|
|
|
|
usb = go->hpi_context;
|
|
if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
|
|
dev_info(&client->dev, "i2c lock failed\n");
|
|
kfree(buf);
|
|
return -EINTR;
|
|
}
|
|
rc = go7007_usb_vendor_request(go, 0x55, dev_addr,
|
|
(reg<<8 | value),
|
|
buf,
|
|
16, 1);
|
|
|
|
mutex_unlock(&usb->i2c_lock);
|
|
kfree(buf);
|
|
return rc;
|
|
}
|
|
|
|
static int write_reg_fp(struct i2c_client *client, u16 addr, u16 val)
|
|
{
|
|
struct go7007 *go = i2c_get_adapdata(client->adapter);
|
|
struct go7007_usb *usb;
|
|
int rc;
|
|
u8 *buf;
|
|
struct s2250 *dec = i2c_get_clientdata(client);
|
|
|
|
if (go == NULL)
|
|
return -ENODEV;
|
|
|
|
if (go->status == STATUS_SHUTDOWN)
|
|
return -EBUSY;
|
|
|
|
buf = kzalloc(16, GFP_KERNEL);
|
|
|
|
if (buf == NULL)
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(buf, 0xcd, 6);
|
|
|
|
usb = go->hpi_context;
|
|
if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
|
|
dev_info(&client->dev, "i2c lock failed\n");
|
|
kfree(buf);
|
|
return -EINTR;
|
|
}
|
|
rc = go7007_usb_vendor_request(go, 0x57, addr, val, buf, 16, 1);
|
|
mutex_unlock(&usb->i2c_lock);
|
|
if (rc < 0) {
|
|
kfree(buf);
|
|
return rc;
|
|
}
|
|
|
|
if (buf[0] == 0) {
|
|
unsigned int subaddr, val_read;
|
|
|
|
subaddr = (buf[4] << 8) + buf[5];
|
|
val_read = (buf[2] << 8) + buf[3];
|
|
kfree(buf);
|
|
if (val_read != val) {
|
|
dev_info(&client->dev, "invalid fp write %x %x\n",
|
|
val_read, val);
|
|
return -EFAULT;
|
|
}
|
|
if (subaddr != addr) {
|
|
dev_info(&client->dev, "invalid fp write addr %x %x\n",
|
|
subaddr, addr);
|
|
return -EFAULT;
|
|
}
|
|
} else {
|
|
kfree(buf);
|
|
return -EFAULT;
|
|
}
|
|
|
|
/* save last 12b value */
|
|
if (addr == 0x12b)
|
|
dec->reg12b_val = val;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int read_reg_fp(struct i2c_client *client, u16 addr, u16 *val)
|
|
{
|
|
struct go7007 *go = i2c_get_adapdata(client->adapter);
|
|
struct go7007_usb *usb;
|
|
int rc;
|
|
u8 *buf;
|
|
|
|
if (go == NULL)
|
|
return -ENODEV;
|
|
|
|
if (go->status == STATUS_SHUTDOWN)
|
|
return -EBUSY;
|
|
|
|
buf = kzalloc(16, GFP_KERNEL);
|
|
|
|
if (buf == NULL)
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(buf, 0xcd, 6);
|
|
usb = go->hpi_context;
|
|
if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
|
|
dev_info(&client->dev, "i2c lock failed\n");
|
|
kfree(buf);
|
|
return -EINTR;
|
|
}
|
|
rc = go7007_usb_vendor_request(go, 0x58, addr, 0, buf, 16, 1);
|
|
mutex_unlock(&usb->i2c_lock);
|
|
if (rc < 0) {
|
|
kfree(buf);
|
|
return rc;
|
|
}
|
|
|
|
*val = (buf[0] << 8) | buf[1];
|
|
kfree(buf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int write_regs(struct i2c_client *client, u8 *regs)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) {
|
|
if (write_reg(client, regs[i], regs[i+1]) < 0) {
|
|
dev_info(&client->dev, "failed\n");
|
|
return -1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int write_regs_fp(struct i2c_client *client, u16 *regs)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) {
|
|
if (write_reg_fp(client, regs[i], regs[i+1]) < 0) {
|
|
dev_info(&client->dev, "failed fp\n");
|
|
return -1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
static int s2250_s_video_routing(struct v4l2_subdev *sd, u32 input, u32 output,
|
|
u32 config)
|
|
{
|
|
struct s2250 *state = to_state(sd);
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
int vidsys;
|
|
|
|
vidsys = (state->std == V4L2_STD_NTSC) ? 0x01 : 0x00;
|
|
if (input == 0) {
|
|
/* composite */
|
|
write_reg_fp(client, 0x20, 0x020 | vidsys);
|
|
write_reg_fp(client, 0x21, 0x662);
|
|
write_reg_fp(client, 0x140, 0x060);
|
|
} else if (input == 1) {
|
|
/* S-Video */
|
|
write_reg_fp(client, 0x20, 0x040 | vidsys);
|
|
write_reg_fp(client, 0x21, 0x666);
|
|
write_reg_fp(client, 0x140, 0x060);
|
|
} else {
|
|
return -EINVAL;
|
|
}
|
|
state->input = input;
|
|
return 0;
|
|
}
|
|
|
|
static int s2250_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
|
|
{
|
|
struct s2250 *state = to_state(sd);
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
u16 vidsource;
|
|
|
|
vidsource = (state->input == 1) ? 0x040 : 0x020;
|
|
if (norm & V4L2_STD_625_50) {
|
|
write_regs_fp(client, vid_regs_fp);
|
|
write_regs_fp(client, vid_regs_fp_pal);
|
|
write_reg_fp(client, 0x20, vidsource);
|
|
} else {
|
|
write_regs_fp(client, vid_regs_fp);
|
|
write_reg_fp(client, 0x20, vidsource | 1);
|
|
}
|
|
state->std = norm;
|
|
return 0;
|
|
}
|
|
|
|
static int s2250_s_ctrl(struct v4l2_ctrl *ctrl)
|
|
{
|
|
struct s2250 *state = container_of(ctrl->handler, struct s2250, hdl);
|
|
struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
|
|
u16 oldvalue;
|
|
|
|
switch (ctrl->id) {
|
|
case V4L2_CID_BRIGHTNESS:
|
|
read_reg_fp(client, VPX322_ADDR_BRIGHTNESS0, &oldvalue);
|
|
write_reg_fp(client, VPX322_ADDR_BRIGHTNESS0,
|
|
ctrl->val | (oldvalue & ~0xff));
|
|
read_reg_fp(client, VPX322_ADDR_BRIGHTNESS1, &oldvalue);
|
|
write_reg_fp(client, VPX322_ADDR_BRIGHTNESS1,
|
|
ctrl->val | (oldvalue & ~0xff));
|
|
write_reg_fp(client, 0x140, 0x60);
|
|
break;
|
|
case V4L2_CID_CONTRAST:
|
|
read_reg_fp(client, VPX322_ADDR_CONTRAST0, &oldvalue);
|
|
write_reg_fp(client, VPX322_ADDR_CONTRAST0,
|
|
ctrl->val | (oldvalue & ~0x3f));
|
|
read_reg_fp(client, VPX322_ADDR_CONTRAST1, &oldvalue);
|
|
write_reg_fp(client, VPX322_ADDR_CONTRAST1,
|
|
ctrl->val | (oldvalue & ~0x3f));
|
|
write_reg_fp(client, 0x140, 0x60);
|
|
break;
|
|
case V4L2_CID_SATURATION:
|
|
write_reg_fp(client, VPX322_ADDR_SAT, ctrl->val);
|
|
break;
|
|
case V4L2_CID_HUE:
|
|
write_reg_fp(client, VPX322_ADDR_HUE, ctrl->val);
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int s2250_set_fmt(struct v4l2_subdev *sd,
|
|
struct v4l2_subdev_pad_config *cfg,
|
|
struct v4l2_subdev_format *format)
|
|
{
|
|
struct v4l2_mbus_framefmt *fmt = &format->format;
|
|
struct s2250 *state = to_state(sd);
|
|
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
|
|
|
if (format->pad)
|
|
return -EINVAL;
|
|
|
|
if (format->which == V4L2_SUBDEV_FORMAT_TRY)
|
|
return 0;
|
|
|
|
if (fmt->height < 640) {
|
|
write_reg_fp(client, 0x12b, state->reg12b_val | 0x400);
|
|
write_reg_fp(client, 0x140, 0x060);
|
|
} else {
|
|
write_reg_fp(client, 0x12b, state->reg12b_val & ~0x400);
|
|
write_reg_fp(client, 0x140, 0x060);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int s2250_s_audio_routing(struct v4l2_subdev *sd, u32 input, u32 output,
|
|
u32 config)
|
|
{
|
|
struct s2250 *state = to_state(sd);
|
|
|
|
switch (input) {
|
|
case 0:
|
|
write_reg(state->audio, 0x08, 0x02); /* Line In */
|
|
break;
|
|
case 1:
|
|
write_reg(state->audio, 0x08, 0x04); /* Mic */
|
|
break;
|
|
case 2:
|
|
write_reg(state->audio, 0x08, 0x05); /* Mic Boost */
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
state->audio_input = input;
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int s2250_log_status(struct v4l2_subdev *sd)
|
|
{
|
|
struct s2250 *state = to_state(sd);
|
|
|
|
v4l2_info(sd, "Standard: %s\n", state->std == V4L2_STD_NTSC ? "NTSC" :
|
|
state->std == V4L2_STD_PAL ? "PAL" :
|
|
state->std == V4L2_STD_SECAM ? "SECAM" :
|
|
"unknown");
|
|
v4l2_info(sd, "Input: %s\n", state->input == 0 ? "Composite" :
|
|
state->input == 1 ? "S-video" :
|
|
"error");
|
|
v4l2_info(sd, "Audio input: %s\n", state->audio_input == 0 ? "Line In" :
|
|
state->audio_input == 1 ? "Mic" :
|
|
state->audio_input == 2 ? "Mic Boost" :
|
|
"error");
|
|
return v4l2_ctrl_subdev_log_status(sd);
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------*/
|
|
|
|
static const struct v4l2_ctrl_ops s2250_ctrl_ops = {
|
|
.s_ctrl = s2250_s_ctrl,
|
|
};
|
|
|
|
static const struct v4l2_subdev_core_ops s2250_core_ops = {
|
|
.log_status = s2250_log_status,
|
|
};
|
|
|
|
static const struct v4l2_subdev_audio_ops s2250_audio_ops = {
|
|
.s_routing = s2250_s_audio_routing,
|
|
};
|
|
|
|
static const struct v4l2_subdev_video_ops s2250_video_ops = {
|
|
.s_std = s2250_s_std,
|
|
.s_routing = s2250_s_video_routing,
|
|
};
|
|
|
|
static const struct v4l2_subdev_pad_ops s2250_pad_ops = {
|
|
.set_fmt = s2250_set_fmt,
|
|
};
|
|
|
|
static const struct v4l2_subdev_ops s2250_ops = {
|
|
.core = &s2250_core_ops,
|
|
.audio = &s2250_audio_ops,
|
|
.video = &s2250_video_ops,
|
|
.pad = &s2250_pad_ops,
|
|
};
|
|
|
|
/* --------------------------------------------------------------------------*/
|
|
|
|
static int s2250_probe(struct i2c_client *client,
|
|
const struct i2c_device_id *id)
|
|
{
|
|
struct i2c_client *audio;
|
|
struct i2c_adapter *adapter = client->adapter;
|
|
struct s2250 *state;
|
|
struct v4l2_subdev *sd;
|
|
u8 *data;
|
|
struct go7007 *go = i2c_get_adapdata(adapter);
|
|
struct go7007_usb *usb = go->hpi_context;
|
|
int err = -EIO;
|
|
|
|
audio = i2c_new_dummy(adapter, TLV320_ADDRESS >> 1);
|
|
if (audio == NULL)
|
|
return -ENOMEM;
|
|
|
|
state = kzalloc(sizeof(struct s2250), GFP_KERNEL);
|
|
if (state == NULL) {
|
|
i2c_unregister_device(audio);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
sd = &state->sd;
|
|
v4l2_i2c_subdev_init(sd, client, &s2250_ops);
|
|
|
|
v4l2_info(sd, "initializing %s at address 0x%x on %s\n",
|
|
"Sensoray 2250/2251", client->addr, client->adapter->name);
|
|
|
|
v4l2_ctrl_handler_init(&state->hdl, 4);
|
|
v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
|
|
V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
|
|
v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
|
|
V4L2_CID_CONTRAST, 0, 0x3f, 1, 0x32);
|
|
v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
|
|
V4L2_CID_SATURATION, 0, 4094, 1, 2070);
|
|
v4l2_ctrl_new_std(&state->hdl, &s2250_ctrl_ops,
|
|
V4L2_CID_HUE, -512, 511, 1, 0);
|
|
sd->ctrl_handler = &state->hdl;
|
|
if (state->hdl.error) {
|
|
err = state->hdl.error;
|
|
goto fail;
|
|
}
|
|
|
|
state->std = V4L2_STD_NTSC;
|
|
state->brightness = 50;
|
|
state->contrast = 50;
|
|
state->saturation = 50;
|
|
state->hue = 0;
|
|
state->audio = audio;
|
|
|
|
/* initialize the audio */
|
|
if (write_regs(audio, aud_regs) < 0) {
|
|
dev_err(&client->dev, "error initializing audio\n");
|
|
goto fail;
|
|
}
|
|
|
|
if (write_regs(client, vid_regs) < 0) {
|
|
dev_err(&client->dev, "error initializing decoder\n");
|
|
goto fail;
|
|
}
|
|
if (write_regs_fp(client, vid_regs_fp) < 0) {
|
|
dev_err(&client->dev, "error initializing decoder\n");
|
|
goto fail;
|
|
}
|
|
/* set default channel */
|
|
/* composite */
|
|
write_reg_fp(client, 0x20, 0x020 | 1);
|
|
write_reg_fp(client, 0x21, 0x662);
|
|
write_reg_fp(client, 0x140, 0x060);
|
|
|
|
/* set default audio input */
|
|
state->audio_input = 0;
|
|
write_reg(client, 0x08, 0x02); /* Line In */
|
|
|
|
if (mutex_lock_interruptible(&usb->i2c_lock) == 0) {
|
|
data = kzalloc(16, GFP_KERNEL);
|
|
if (data != NULL) {
|
|
int rc = go7007_usb_vendor_request(go, 0x41, 0, 0,
|
|
data, 16, 1);
|
|
|
|
if (rc > 0) {
|
|
u8 mask;
|
|
|
|
data[0] = 0;
|
|
mask = 1<<5;
|
|
data[0] &= ~mask;
|
|
data[1] |= mask;
|
|
go7007_usb_vendor_request(go, 0x40, 0,
|
|
(data[1]<<8)
|
|
+ data[1],
|
|
data, 16, 0);
|
|
}
|
|
kfree(data);
|
|
}
|
|
mutex_unlock(&usb->i2c_lock);
|
|
}
|
|
|
|
v4l2_info(sd, "initialized successfully\n");
|
|
return 0;
|
|
|
|
fail:
|
|
i2c_unregister_device(audio);
|
|
v4l2_ctrl_handler_free(&state->hdl);
|
|
kfree(state);
|
|
return err;
|
|
}
|
|
|
|
static int s2250_remove(struct i2c_client *client)
|
|
{
|
|
struct s2250 *state = to_state(i2c_get_clientdata(client));
|
|
|
|
v4l2_device_unregister_subdev(&state->sd);
|
|
v4l2_ctrl_handler_free(&state->hdl);
|
|
kfree(state);
|
|
return 0;
|
|
}
|
|
|
|
static const struct i2c_device_id s2250_id[] = {
|
|
{ "s2250", 0 },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(i2c, s2250_id);
|
|
|
|
static struct i2c_driver s2250_driver = {
|
|
.driver = {
|
|
.name = "s2250",
|
|
},
|
|
.probe = s2250_probe,
|
|
.remove = s2250_remove,
|
|
.id_table = s2250_id,
|
|
};
|
|
|
|
module_i2c_driver(s2250_driver);
|