Changes in 4.9.283 ext4: fix race writing to an inline_data file while its xattrs are changing mtd: nand: atmel_nand: remove build warning in atmel_nand_remove() xtensa: fix kconfig unmet dependency warning for HAVE_FUTEX_CMPXCHG qed: Fix the VF msix vectors flow qede: Fix memset corruption perf/x86/amd/ibs: Work around erratum #1197 cryptoloop: add a deprecation warning ARM: 8918/2: only build return_address() if needed ALSA: pcm: fix divide error in snd_pcm_lib_ioctl ath: Use safer key clearing with key cache entries ath9k: Clear key cache explicitly on disabling hardware ath: Export ath_hw_keysetmac() ath: Modify ath_key_delete() to not need full key entry ath9k: Postpone key cache entry deletion for TXQ frames reference it media: stkwebcam: fix memory leak in stk_camera_probe igmp: Add ip_mc_list lock in ip_check_mc_rcu usb: phy: isp1301: Fix build warning when CONFIG_OF is disabled USB: serial: mos7720: improve OOM-handling in read_mos_reg() net/sched: cls_flower: Use mask for addr_type PM / wakeirq: Enable dedicated wakeirq for suspend tc358743: fix register i2c_rd/wr function fix nvme-pci: Fix an error handling path in 'nvme_probe()' gfs2: Don't clear SGID when inheriting ACLs ipv4/icmp: l3mdev: Perform icmp error route lookup on source device routing table (v2) s390/disassembler: correct disassembly lines alignment mm/kmemleak.c: make cond_resched() rate-limiting more efficient crypto: talitos - reduce max key size for SEC1 powerpc/module64: Fix comment in R_PPC64_ENTRY handling powerpc/boot: Delete unneeded .globl _zimage_start net: ll_temac: Remove left-over debug message mm/page_alloc: speed up the iteration of max_order Revert "btrfs: compression: don't try to compress if we don't have enough pages" x86/reboot: Limit Dell Optiplex 990 quirk to early BIOS versions PCI: Call Max Payload Size-related fixup quirks early regmap: fix the offset of register error log crypto: mxs-dcp - Check for DMA mapping errors power: supply: axp288_fuel_gauge: Report register-address on readb / writeb errors crypto: omap-sham - clear dma flags only after omap_sham_update_dma_stop() udf: Check LVID earlier power: supply: max17042_battery: fix typo in MAx17042_TOFF libata: fix ata_host_start() crypto: qat - do not ignore errors from enable_vf2pf_comms() crypto: qat - handle both source of interrupt in VF ISR crypto: qat - fix reuse of completion variable crypto: qat - fix naming for init/shutdown VF to PF notifications crypto: qat - do not export adf_iov_putmsg() udf_get_extendedattr() had no boundary checks. m68k: emu: Fix invalid free in nfeth_cleanup() spi: spi-pic32: Fix issue with uninitialized dma_slave_config crypto: qat - use proper type for vf_mask certs: Trigger creation of RSA module signing key if it's not an RSA key media: dvb-usb: fix uninit-value in dvb_usb_adapter_dvb_init media: dvb-usb: fix uninit-value in vp702x_read_mac_addr media: go7007: remove redundant initialization Bluetooth: sco: prevent information leak in sco_conn_defer_accept() tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos net: cipso: fix warnings in netlbl_cipsov4_add_std i2c: highlander: add IRQ check PCI: PM: Enable PME if it can be signaled from D3cold soc: qcom: smsm: Fix missed interrupts if state changes while masked Bluetooth: increase BTNAMSIZ to 21 chars to fix potential buffer overflow arm64: dts: exynos: correct GIC CPU interfaces address range on Exynos7 Bluetooth: fix repeated calls to sco_sock_kill drm/msm/dsi: Fix some reference counted resource leaks usb: gadget: udc: at91: add IRQ check usb: phy: fsl-usb: add IRQ check usb: phy: twl6030: add IRQ checks Bluetooth: Move shutdown callback before flushing tx and rx queue usb: host: ohci-tmio: add IRQ check usb: phy: tahvo: add IRQ check usb: gadget: mv_u3d: request_irq() after initializing UDC Bluetooth: add timeout sanity check to hci_inquiry i2c: iop3xx: fix deferred probing i2c: s3c2410: fix IRQ check mmc: dw_mmc: Fix issue with uninitialized dma_slave_config mmc: moxart: Fix issue with uninitialized dma_slave_config CIFS: Fix a potencially linear read overflow i2c: mt65xx: fix IRQ check usb: ehci-orion: Handle errors of clk_prepare_enable() in probe ath6kl: wmi: fix an error code in ath6kl_wmi_sync_point() bcma: Fix memory leak for internally-handled cores ipv4: make exception cache less predictible tty: Fix data race between tiocsti() and flush_to_ldisc() KVM: x86: Update vCPU's hv_clock before back to guest when tsc_offset is adjusted IMA: remove -Wmissing-prototypes warning clk: kirkwood: Fix a clocking boot regression fbmem: don't allow too huge resolutions rtc: tps65910: Correct driver module alias PCI/MSI: Skip masking MSI-X on Xen PV powerpc/perf/hv-gpci: Fix counter value parsing xen: fix setting of max_pfn in shared_info crypto: public_key: fix overflow during implicit conversion power: supply: max17042: handle fails of reading status register VMCI: fix NULL pointer dereference when unmapping queue pair media: uvc: don't do DMA on stack media: rc-loopback: return number of emitters rather than error libata: add ATA_HORKAGE_NO_NCQ_TRIM for Samsung 860 and 870 SSDs ARM: 9105/1: atags_to_fdt: don't warn about stack size PCI: Restrict ASMedia ASM1062 SATA Max Payload Size Supported PCI: Return ~0 data on pciconfig_read() CAP_SYS_ADMIN failure vfio: Use config not menuconfig for VFIO_NOIOMMU openrisc: don't printk() unconditionally pinctrl: single: Fix error return code in pcs_parse_bits_in_pinctrl_entry() MIPS: Malta: fix alignment of the devicetree buffer crypto: mxs-dcp - Use sg_mapping_iter to copy data PCI: Use pci_update_current_state() in pci_enable_device_flags() iio: dac: ad5624r: Fix incorrect handling of an optional regulator. video: fbdev: kyro: fix a DoS bug by restricting user input netlink: Deal with ESRCH error in nlmsg_notify() Smack: Fix wrong semantics in smk_access_entry() usb: host: fotg210: fix the endpoint's transactional opportunities calculation usb: host: fotg210: fix the actual_length of an iso packet usb: gadget: u_ether: fix a potential null pointer dereference usb: gadget: composite: Allow bMaxPower=0 if self-powered staging: board: Fix uninitialized spinlock when attaching genpd tty: serial: jsm: hold port lock when reporting modem line changes bpf/tests: Fix copy-and-paste error in double word test bpf/tests: Do not PASS tests without actually testing the result video: fbdev: asiliantfb: Error out if 'pixclock' equals zero video: fbdev: kyro: Error out if 'pixclock' equals zero video: fbdev: riva: Error out if 'pixclock' equals zero ipv4: ip_output.c: Fix out-of-bounds warning in ip_copy_addrs() flow_dissector: Fix out-of-bounds warnings s390/jump_label: print real address in a case of a jump label bug serial: 8250: Define RX trigger levels for OxSemi 950 devices xtensa: ISS: don't panic in rs_init hvsi: don't panic on tty_register_driver failure serial: 8250_pci: make setup_port() parameters explicitly unsigned staging: ks7010: Fix the initialization of the 'sleep_status' structure ata: sata_dwc_460ex: No need to call phy_exit() befre phy_init() Bluetooth: skip invalid hci_sync_conn_complete_evt ASoC: Intel: bytcr_rt5640: Move "Platform Clock" routes to the maps for the matching in-/output net: ethernet: stmmac: Do not use unreachable() in ipq806x_gmac_probe() Bluetooth: avoid circular locks in sco_sock_connect gpu: drm: amd: amdgpu: amdgpu_i2c: fix possible uninitialized-variable access in amdgpu_i2c_router_select_ddc_port() ARM: tegra: tamonten: Fix UART pad setting rpc: fix gss_svc_init cleanup on failure gfs2: Don't call dlm after protocol is unmounted mmc: rtsx_pci: Fix long reads when clock is prescaled cifs: fix wrong release in sess_alloc_buffer() failed path Revert "USB: xhci: fix U1/U2 handling for hardware with XHCI_INTEL_HOST quirk set" usbip: give back URBs for unsent unlink requests during cleanup parport: remove non-zero check on count ath9k: fix OOB read ar9300_eeprom_restore_internal ath9k: fix sleeping in atomic context net: fix NULL pointer reference in cipso_v4_doi_free net: w5100: check return value after calling platform_get_resource() parisc: fix crash with signals and alloca scsi: BusLogic: Fix missing pr_cont() use mm/hugetlb: initialize hugetlb_usage in mm_init memcg: enable accounting for pids in nested pid namespaces platform/chrome: cros_ec_proto: Send command again when timeout occurs xen: reset legacy rtc flag for PV domU bnx2x: Fix enabling network interfaces without VFs net-caif: avoid user-triggerable WARN_ON(1) ptp: dp83640: don't define PAGE0 dccp: don't duplicate ccid when cloning dccp sock net/l2tp: Fix reference count leak in l2tp_udp_recv_core r6040: Restore MDIO clock frequency after MAC reset tipc: increase timeout in tipc_sk_enqueue() events: Reuse value read using READ_ONCE instead of re-reading it net/af_unix: fix a data-race in unix_dgram_poll tcp: fix tp->undo_retrans accounting in tcp_sacktag_one() x86/mm: Fix kern_addr_valid() to cope with existing but not present entries dt-bindings: mtd: gpmc: Fix the ECC bytes vs. OOB bytes equation mfd: Don't use irq_create_mapping() to resolve a mapping net: usb: cdc_mbim: avoid altsetting toggling for Telit LN920 ethtool: Fix an error code in cxgb2.c PCI: Sync __pci_register_driver() stub for CONFIG_PCI=n mtd: rawnand: cafe: Fix a resource leak in the error handling path of 'cafe_nand_probe()' ARC: export clear_user_page() for modules net: dsa: b53: Fix calculating number of switch ports qlcnic: Remove redundant unlock in qlcnic_pinit_from_rom net: renesas: sh_eth: Fix freeing wrong tx descriptor s390/bpf: Fix 64-bit subtraction of the -0x80000000 constant Linux 4.9.283 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I9e2017cce36805d71566ea1f265974a43bae33d1
745 lines
19 KiB
C
745 lines
19 KiB
C
/*
|
|
* Copyright (C) 2005-2006 Micronas USA 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/delay.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/unistd.h>
|
|
#include <linux/time.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/device.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/firmware.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/videodev2.h>
|
|
#include <media/tuner.h>
|
|
#include <media/v4l2-common.h>
|
|
#include <media/v4l2-event.h>
|
|
|
|
#include "go7007-priv.h"
|
|
|
|
/*
|
|
* Wait for an interrupt to be delivered from the GO7007SB and return
|
|
* the associated value and data.
|
|
*
|
|
* Must be called with the hw_lock held.
|
|
*/
|
|
int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data)
|
|
{
|
|
go->interrupt_available = 0;
|
|
go->hpi_ops->read_interrupt(go);
|
|
if (wait_event_timeout(go->interrupt_waitq,
|
|
go->interrupt_available, 5*HZ) < 0) {
|
|
v4l2_err(&go->v4l2_dev, "timeout waiting for read interrupt\n");
|
|
return -1;
|
|
}
|
|
if (!go->interrupt_available)
|
|
return -1;
|
|
go->interrupt_available = 0;
|
|
*value = go->interrupt_value & 0xfffe;
|
|
*data = go->interrupt_data;
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(go7007_read_interrupt);
|
|
|
|
/*
|
|
* Read a register/address on the GO7007SB.
|
|
*
|
|
* Must be called with the hw_lock held.
|
|
*/
|
|
int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data)
|
|
{
|
|
int count = 100;
|
|
u16 value;
|
|
|
|
if (go7007_write_interrupt(go, 0x0010, addr) < 0)
|
|
return -EIO;
|
|
while (count-- > 0) {
|
|
if (go7007_read_interrupt(go, &value, data) == 0 &&
|
|
value == 0xa000)
|
|
return 0;
|
|
}
|
|
return -EIO;
|
|
}
|
|
EXPORT_SYMBOL(go7007_read_addr);
|
|
|
|
/*
|
|
* Send the boot firmware to the encoder, which just wakes it up and lets
|
|
* us talk to the GPIO pins and on-board I2C adapter.
|
|
*
|
|
* Must be called with the hw_lock held.
|
|
*/
|
|
static int go7007_load_encoder(struct go7007 *go)
|
|
{
|
|
const struct firmware *fw_entry;
|
|
char fw_name[] = "go7007/go7007fw.bin";
|
|
void *bounce;
|
|
int fw_len, rv = 0;
|
|
u16 intr_val, intr_data;
|
|
|
|
if (go->boot_fw == NULL) {
|
|
if (request_firmware(&fw_entry, fw_name, go->dev)) {
|
|
v4l2_err(go, "unable to load firmware from file \"%s\"\n", fw_name);
|
|
return -1;
|
|
}
|
|
if (fw_entry->size < 16 || memcmp(fw_entry->data, "WISGO7007FW", 11)) {
|
|
v4l2_err(go, "file \"%s\" does not appear to be go7007 firmware\n", fw_name);
|
|
release_firmware(fw_entry);
|
|
return -1;
|
|
}
|
|
fw_len = fw_entry->size - 16;
|
|
bounce = kmemdup(fw_entry->data + 16, fw_len, GFP_KERNEL);
|
|
if (bounce == NULL) {
|
|
v4l2_err(go, "unable to allocate %d bytes for firmware transfer\n", fw_len);
|
|
release_firmware(fw_entry);
|
|
return -1;
|
|
}
|
|
release_firmware(fw_entry);
|
|
go->boot_fw_len = fw_len;
|
|
go->boot_fw = bounce;
|
|
}
|
|
if (go7007_interface_reset(go) < 0 ||
|
|
go7007_send_firmware(go, go->boot_fw, go->boot_fw_len) < 0 ||
|
|
go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
|
|
(intr_val & ~0x1) != 0x5a5a) {
|
|
v4l2_err(go, "error transferring firmware\n");
|
|
rv = -1;
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
MODULE_FIRMWARE("go7007/go7007fw.bin");
|
|
|
|
/*
|
|
* Boot the encoder and register the I2C adapter if requested. Do the
|
|
* minimum initialization necessary, since the board-specific code may
|
|
* still need to probe the board ID.
|
|
*
|
|
* Must NOT be called with the hw_lock held.
|
|
*/
|
|
int go7007_boot_encoder(struct go7007 *go, int init_i2c)
|
|
{
|
|
int ret;
|
|
|
|
mutex_lock(&go->hw_lock);
|
|
ret = go7007_load_encoder(go);
|
|
mutex_unlock(&go->hw_lock);
|
|
if (ret < 0)
|
|
return -1;
|
|
if (!init_i2c)
|
|
return 0;
|
|
if (go7007_i2c_init(go) < 0)
|
|
return -1;
|
|
go->i2c_adapter_online = 1;
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(go7007_boot_encoder);
|
|
|
|
/*
|
|
* Configure any hardware-related registers in the GO7007, such as GPIO
|
|
* pins and bus parameters, which are board-specific. This assumes
|
|
* the boot firmware has already been downloaded.
|
|
*
|
|
* Must be called with the hw_lock held.
|
|
*/
|
|
static int go7007_init_encoder(struct go7007 *go)
|
|
{
|
|
if (go->board_info->audio_flags & GO7007_AUDIO_I2S_MASTER) {
|
|
go7007_write_addr(go, 0x1000, 0x0811);
|
|
go7007_write_addr(go, 0x1000, 0x0c11);
|
|
}
|
|
switch (go->board_id) {
|
|
case GO7007_BOARDID_MATRIX_REV:
|
|
/* Set GPIO pin 0 to be an output (audio clock control) */
|
|
go7007_write_addr(go, 0x3c82, 0x0001);
|
|
go7007_write_addr(go, 0x3c80, 0x00fe);
|
|
break;
|
|
case GO7007_BOARDID_ADLINK_MPG24:
|
|
/* set GPIO5 to be an output, currently low */
|
|
go7007_write_addr(go, 0x3c82, 0x0000);
|
|
go7007_write_addr(go, 0x3c80, 0x00df);
|
|
break;
|
|
case GO7007_BOARDID_ADS_USBAV_709:
|
|
/* GPIO pin 0: audio clock control */
|
|
/* pin 2: TW9906 reset */
|
|
/* pin 3: capture LED */
|
|
go7007_write_addr(go, 0x3c82, 0x000d);
|
|
go7007_write_addr(go, 0x3c80, 0x00f2);
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Send the boot firmware to the GO7007 and configure the registers. This
|
|
* is the only way to stop the encoder once it has started streaming video.
|
|
*
|
|
* Must be called with the hw_lock held.
|
|
*/
|
|
int go7007_reset_encoder(struct go7007 *go)
|
|
{
|
|
if (go7007_load_encoder(go) < 0)
|
|
return -1;
|
|
return go7007_init_encoder(go);
|
|
}
|
|
|
|
/*
|
|
* Attempt to instantiate an I2C client by ID, probably loading a module.
|
|
*/
|
|
static int init_i2c_module(struct i2c_adapter *adapter, const struct go_i2c *const i2c)
|
|
{
|
|
struct go7007 *go = i2c_get_adapdata(adapter);
|
|
struct v4l2_device *v4l2_dev = &go->v4l2_dev;
|
|
struct v4l2_subdev *sd;
|
|
struct i2c_board_info info;
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
strlcpy(info.type, i2c->type, sizeof(info.type));
|
|
info.addr = i2c->addr;
|
|
info.flags = i2c->flags;
|
|
|
|
sd = v4l2_i2c_new_subdev_board(v4l2_dev, adapter, &info, NULL);
|
|
if (sd) {
|
|
if (i2c->is_video)
|
|
go->sd_video = sd;
|
|
if (i2c->is_audio)
|
|
go->sd_audio = sd;
|
|
return 0;
|
|
}
|
|
|
|
pr_info("go7007: probing for module i2c:%s failed\n", i2c->type);
|
|
return -EINVAL;
|
|
}
|
|
|
|
/*
|
|
* Detach and unregister the encoder. The go7007 struct won't be freed
|
|
* until v4l2 finishes releasing its resources and all associated fds are
|
|
* closed by applications.
|
|
*/
|
|
static void go7007_remove(struct v4l2_device *v4l2_dev)
|
|
{
|
|
struct go7007 *go = container_of(v4l2_dev, struct go7007, v4l2_dev);
|
|
|
|
v4l2_device_unregister(v4l2_dev);
|
|
if (go->hpi_ops->release)
|
|
go->hpi_ops->release(go);
|
|
if (go->i2c_adapter_online) {
|
|
i2c_del_adapter(&go->i2c_adapter);
|
|
go->i2c_adapter_online = 0;
|
|
}
|
|
|
|
kfree(go->boot_fw);
|
|
go7007_v4l2_remove(go);
|
|
kfree(go);
|
|
}
|
|
|
|
/*
|
|
* Finalize the GO7007 hardware setup, register the on-board I2C adapter
|
|
* (if used on this board), load the I2C client driver for the sensor
|
|
* (SAA7115 or whatever) and other devices, and register the ALSA and V4L2
|
|
* interfaces.
|
|
*
|
|
* Must NOT be called with the hw_lock held.
|
|
*/
|
|
int go7007_register_encoder(struct go7007 *go, unsigned num_i2c_devs)
|
|
{
|
|
int i, ret;
|
|
|
|
dev_info(go->dev, "go7007: registering new %s\n", go->name);
|
|
|
|
go->v4l2_dev.release = go7007_remove;
|
|
ret = v4l2_device_register(go->dev, &go->v4l2_dev);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
mutex_lock(&go->hw_lock);
|
|
ret = go7007_init_encoder(go);
|
|
mutex_unlock(&go->hw_lock);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
ret = go7007_v4l2_ctrl_init(go);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
if (!go->i2c_adapter_online &&
|
|
go->board_info->flags & GO7007_BOARD_USE_ONBOARD_I2C) {
|
|
ret = go7007_i2c_init(go);
|
|
if (ret < 0)
|
|
return ret;
|
|
go->i2c_adapter_online = 1;
|
|
}
|
|
if (go->i2c_adapter_online) {
|
|
if (go->board_id == GO7007_BOARDID_ADS_USBAV_709) {
|
|
/* Reset the TW9906 */
|
|
go7007_write_addr(go, 0x3c82, 0x0009);
|
|
msleep(50);
|
|
go7007_write_addr(go, 0x3c82, 0x000d);
|
|
}
|
|
for (i = 0; i < num_i2c_devs; ++i)
|
|
init_i2c_module(&go->i2c_adapter, &go->board_info->i2c_devs[i]);
|
|
|
|
if (go->tuner_type >= 0) {
|
|
struct tuner_setup setup = {
|
|
.addr = ADDR_UNSET,
|
|
.type = go->tuner_type,
|
|
.mode_mask = T_ANALOG_TV,
|
|
};
|
|
|
|
v4l2_device_call_all(&go->v4l2_dev, 0, tuner,
|
|
s_type_addr, &setup);
|
|
}
|
|
if (go->board_id == GO7007_BOARDID_ADLINK_MPG24)
|
|
v4l2_subdev_call(go->sd_video, video, s_routing,
|
|
0, 0, go->channel_number + 1);
|
|
}
|
|
|
|
ret = go7007_v4l2_init(go);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
if (go->board_info->flags & GO7007_BOARD_HAS_AUDIO) {
|
|
go->audio_enabled = 1;
|
|
go7007_snd_init(go);
|
|
}
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(go7007_register_encoder);
|
|
|
|
/*
|
|
* Send the encode firmware to the encoder, which will cause it
|
|
* to immediately start delivering the video and audio streams.
|
|
*
|
|
* Must be called with the hw_lock held.
|
|
*/
|
|
int go7007_start_encoder(struct go7007 *go)
|
|
{
|
|
u8 *fw;
|
|
int fw_len, rv = 0, i, x, y;
|
|
u16 intr_val, intr_data;
|
|
|
|
go->modet_enable = 0;
|
|
for (i = 0; i < 4; i++)
|
|
go->modet[i].enable = 0;
|
|
|
|
switch (v4l2_ctrl_g_ctrl(go->modet_mode)) {
|
|
case V4L2_DETECT_MD_MODE_GLOBAL:
|
|
memset(go->modet_map, 0, sizeof(go->modet_map));
|
|
go->modet[0].enable = 1;
|
|
go->modet_enable = 1;
|
|
break;
|
|
case V4L2_DETECT_MD_MODE_REGION_GRID:
|
|
for (y = 0; y < go->height / 16; y++) {
|
|
for (x = 0; x < go->width / 16; x++) {
|
|
int idx = y * go->width / 16 + x;
|
|
|
|
go->modet[go->modet_map[idx]].enable = 1;
|
|
}
|
|
}
|
|
go->modet_enable = 1;
|
|
break;
|
|
}
|
|
|
|
if (go->dvd_mode)
|
|
go->modet_enable = 0;
|
|
|
|
if (go7007_construct_fw_image(go, &fw, &fw_len) < 0)
|
|
return -1;
|
|
|
|
if (go7007_send_firmware(go, fw, fw_len) < 0 ||
|
|
go7007_read_interrupt(go, &intr_val, &intr_data) < 0) {
|
|
v4l2_err(&go->v4l2_dev, "error transferring firmware\n");
|
|
rv = -1;
|
|
goto start_error;
|
|
}
|
|
|
|
go->state = STATE_DATA;
|
|
go->parse_length = 0;
|
|
go->seen_frame = 0;
|
|
if (go7007_stream_start(go) < 0) {
|
|
v4l2_err(&go->v4l2_dev, "error starting stream transfer\n");
|
|
rv = -1;
|
|
goto start_error;
|
|
}
|
|
|
|
start_error:
|
|
kfree(fw);
|
|
return rv;
|
|
}
|
|
|
|
/*
|
|
* Store a byte in the current video buffer, if there is one.
|
|
*/
|
|
static inline void store_byte(struct go7007_buffer *vb, u8 byte)
|
|
{
|
|
if (vb && vb->vb.vb2_buf.planes[0].bytesused < GO7007_BUF_SIZE) {
|
|
u8 *ptr = vb2_plane_vaddr(&vb->vb.vb2_buf, 0);
|
|
|
|
ptr[vb->vb.vb2_buf.planes[0].bytesused++] = byte;
|
|
}
|
|
}
|
|
|
|
static void go7007_set_motion_regions(struct go7007 *go, struct go7007_buffer *vb,
|
|
u32 motion_regions)
|
|
{
|
|
if (motion_regions != go->modet_event_status) {
|
|
struct v4l2_event ev = {
|
|
.type = V4L2_EVENT_MOTION_DET,
|
|
.u.motion_det = {
|
|
.flags = V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ,
|
|
.frame_sequence = vb->vb.sequence,
|
|
.region_mask = motion_regions,
|
|
},
|
|
};
|
|
|
|
v4l2_event_queue(&go->vdev, &ev);
|
|
go->modet_event_status = motion_regions;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Determine regions with motion and send a motion detection event
|
|
* in case of changes.
|
|
*/
|
|
static void go7007_motion_regions(struct go7007 *go, struct go7007_buffer *vb)
|
|
{
|
|
u32 *bytesused = &vb->vb.vb2_buf.planes[0].bytesused;
|
|
unsigned motion[4] = { 0, 0, 0, 0 };
|
|
u32 motion_regions = 0;
|
|
unsigned stride = (go->width + 7) >> 3;
|
|
unsigned x, y;
|
|
int i;
|
|
|
|
for (i = 0; i < 216; ++i)
|
|
store_byte(vb, go->active_map[i]);
|
|
for (y = 0; y < go->height / 16; y++) {
|
|
for (x = 0; x < go->width / 16; x++) {
|
|
if (!(go->active_map[y * stride + (x >> 3)] & (1 << (x & 7))))
|
|
continue;
|
|
motion[go->modet_map[y * (go->width / 16) + x]]++;
|
|
}
|
|
}
|
|
motion_regions = ((motion[0] > 0) << 0) |
|
|
((motion[1] > 0) << 1) |
|
|
((motion[2] > 0) << 2) |
|
|
((motion[3] > 0) << 3);
|
|
*bytesused -= 216;
|
|
go7007_set_motion_regions(go, vb, motion_regions);
|
|
}
|
|
|
|
/*
|
|
* Deliver the last video buffer and get a new one to start writing to.
|
|
*/
|
|
static struct go7007_buffer *frame_boundary(struct go7007 *go, struct go7007_buffer *vb)
|
|
{
|
|
u32 *bytesused;
|
|
struct go7007_buffer *vb_tmp = NULL;
|
|
|
|
if (vb == NULL) {
|
|
spin_lock(&go->spinlock);
|
|
if (!list_empty(&go->vidq_active))
|
|
vb = go->active_buf =
|
|
list_first_entry(&go->vidq_active, struct go7007_buffer, list);
|
|
spin_unlock(&go->spinlock);
|
|
go->next_seq++;
|
|
return vb;
|
|
}
|
|
bytesused = &vb->vb.vb2_buf.planes[0].bytesused;
|
|
|
|
vb->vb.sequence = go->next_seq++;
|
|
if (vb->modet_active && *bytesused + 216 < GO7007_BUF_SIZE)
|
|
go7007_motion_regions(go, vb);
|
|
else
|
|
go7007_set_motion_regions(go, vb, 0);
|
|
|
|
vb->vb.vb2_buf.timestamp = ktime_get_ns();
|
|
vb_tmp = vb;
|
|
spin_lock(&go->spinlock);
|
|
list_del(&vb->list);
|
|
if (list_empty(&go->vidq_active))
|
|
vb = NULL;
|
|
else
|
|
vb = list_first_entry(&go->vidq_active,
|
|
struct go7007_buffer, list);
|
|
go->active_buf = vb;
|
|
spin_unlock(&go->spinlock);
|
|
vb2_buffer_done(&vb_tmp->vb.vb2_buf, VB2_BUF_STATE_DONE);
|
|
return vb;
|
|
}
|
|
|
|
static void write_bitmap_word(struct go7007 *go)
|
|
{
|
|
int x, y, i, stride = ((go->width >> 4) + 7) >> 3;
|
|
|
|
for (i = 0; i < 16; ++i) {
|
|
y = (((go->parse_length - 1) << 3) + i) / (go->width >> 4);
|
|
x = (((go->parse_length - 1) << 3) + i) % (go->width >> 4);
|
|
if (stride * y + (x >> 3) < sizeof(go->active_map))
|
|
go->active_map[stride * y + (x >> 3)] |=
|
|
(go->modet_word & 1) << (x & 0x7);
|
|
go->modet_word >>= 1;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Parse a chunk of the video stream into frames. The frames are not
|
|
* delimited by the hardware, so we have to parse the frame boundaries
|
|
* based on the type of video stream we're receiving.
|
|
*/
|
|
void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
|
|
{
|
|
struct go7007_buffer *vb = go->active_buf;
|
|
int i, seq_start_code = -1, gop_start_code = -1, frame_start_code = -1;
|
|
|
|
switch (go->format) {
|
|
case V4L2_PIX_FMT_MPEG4:
|
|
seq_start_code = 0xB0;
|
|
gop_start_code = 0xB3;
|
|
frame_start_code = 0xB6;
|
|
break;
|
|
case V4L2_PIX_FMT_MPEG1:
|
|
case V4L2_PIX_FMT_MPEG2:
|
|
seq_start_code = 0xB3;
|
|
gop_start_code = 0xB8;
|
|
frame_start_code = 0x00;
|
|
break;
|
|
}
|
|
|
|
for (i = 0; i < length; ++i) {
|
|
if (vb && vb->vb.vb2_buf.planes[0].bytesused >=
|
|
GO7007_BUF_SIZE - 3) {
|
|
v4l2_info(&go->v4l2_dev, "dropping oversized frame\n");
|
|
vb->vb.vb2_buf.planes[0].bytesused = 0;
|
|
vb->frame_offset = 0;
|
|
vb->modet_active = 0;
|
|
vb = go->active_buf = NULL;
|
|
}
|
|
|
|
switch (go->state) {
|
|
case STATE_DATA:
|
|
switch (buf[i]) {
|
|
case 0x00:
|
|
go->state = STATE_00;
|
|
break;
|
|
case 0xFF:
|
|
go->state = STATE_FF;
|
|
break;
|
|
default:
|
|
store_byte(vb, buf[i]);
|
|
break;
|
|
}
|
|
break;
|
|
case STATE_00:
|
|
switch (buf[i]) {
|
|
case 0x00:
|
|
go->state = STATE_00_00;
|
|
break;
|
|
case 0xFF:
|
|
store_byte(vb, 0x00);
|
|
go->state = STATE_FF;
|
|
break;
|
|
default:
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, buf[i]);
|
|
go->state = STATE_DATA;
|
|
break;
|
|
}
|
|
break;
|
|
case STATE_00_00:
|
|
switch (buf[i]) {
|
|
case 0x00:
|
|
store_byte(vb, 0x00);
|
|
/* go->state remains STATE_00_00 */
|
|
break;
|
|
case 0x01:
|
|
go->state = STATE_00_00_01;
|
|
break;
|
|
case 0xFF:
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, 0x00);
|
|
go->state = STATE_FF;
|
|
break;
|
|
default:
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, buf[i]);
|
|
go->state = STATE_DATA;
|
|
break;
|
|
}
|
|
break;
|
|
case STATE_00_00_01:
|
|
if (buf[i] == 0xF8 && go->modet_enable == 0) {
|
|
/* MODET start code, but MODET not enabled */
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, 0x01);
|
|
store_byte(vb, 0xF8);
|
|
go->state = STATE_DATA;
|
|
break;
|
|
}
|
|
/* If this is the start of a new MPEG frame,
|
|
* get a new buffer */
|
|
if ((go->format == V4L2_PIX_FMT_MPEG1 ||
|
|
go->format == V4L2_PIX_FMT_MPEG2 ||
|
|
go->format == V4L2_PIX_FMT_MPEG4) &&
|
|
(buf[i] == seq_start_code ||
|
|
buf[i] == gop_start_code ||
|
|
buf[i] == frame_start_code)) {
|
|
if (vb == NULL || go->seen_frame)
|
|
vb = frame_boundary(go, vb);
|
|
go->seen_frame = buf[i] == frame_start_code;
|
|
if (vb && go->seen_frame)
|
|
vb->frame_offset =
|
|
vb->vb.vb2_buf.planes[0].bytesused;
|
|
}
|
|
/* Handle any special chunk types, or just write the
|
|
* start code to the (potentially new) buffer */
|
|
switch (buf[i]) {
|
|
case 0xF5: /* timestamp */
|
|
go->parse_length = 12;
|
|
go->state = STATE_UNPARSED;
|
|
break;
|
|
case 0xF6: /* vbi */
|
|
go->state = STATE_VBI_LEN_A;
|
|
break;
|
|
case 0xF8: /* MD map */
|
|
go->parse_length = 0;
|
|
memset(go->active_map, 0,
|
|
sizeof(go->active_map));
|
|
go->state = STATE_MODET_MAP;
|
|
break;
|
|
case 0xFF: /* Potential JPEG start code */
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, 0x01);
|
|
go->state = STATE_FF;
|
|
break;
|
|
default:
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, 0x00);
|
|
store_byte(vb, 0x01);
|
|
store_byte(vb, buf[i]);
|
|
go->state = STATE_DATA;
|
|
break;
|
|
}
|
|
break;
|
|
case STATE_FF:
|
|
switch (buf[i]) {
|
|
case 0x00:
|
|
store_byte(vb, 0xFF);
|
|
go->state = STATE_00;
|
|
break;
|
|
case 0xFF:
|
|
store_byte(vb, 0xFF);
|
|
/* go->state remains STATE_FF */
|
|
break;
|
|
case 0xD8:
|
|
if (go->format == V4L2_PIX_FMT_MJPEG)
|
|
vb = frame_boundary(go, vb);
|
|
/* fall through */
|
|
default:
|
|
store_byte(vb, 0xFF);
|
|
store_byte(vb, buf[i]);
|
|
go->state = STATE_DATA;
|
|
break;
|
|
}
|
|
break;
|
|
case STATE_VBI_LEN_A:
|
|
go->parse_length = buf[i] << 8;
|
|
go->state = STATE_VBI_LEN_B;
|
|
break;
|
|
case STATE_VBI_LEN_B:
|
|
go->parse_length |= buf[i];
|
|
if (go->parse_length > 0)
|
|
go->state = STATE_UNPARSED;
|
|
else
|
|
go->state = STATE_DATA;
|
|
break;
|
|
case STATE_MODET_MAP:
|
|
if (go->parse_length < 204) {
|
|
if (go->parse_length & 1) {
|
|
go->modet_word |= buf[i];
|
|
write_bitmap_word(go);
|
|
} else
|
|
go->modet_word = buf[i] << 8;
|
|
} else if (go->parse_length == 207 && vb) {
|
|
vb->modet_active = buf[i];
|
|
}
|
|
if (++go->parse_length == 208)
|
|
go->state = STATE_DATA;
|
|
break;
|
|
case STATE_UNPARSED:
|
|
if (--go->parse_length == 0)
|
|
go->state = STATE_DATA;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(go7007_parse_video_stream);
|
|
|
|
/*
|
|
* Allocate a new go7007 struct. Used by the hardware-specific probe.
|
|
*/
|
|
struct go7007 *go7007_alloc(const struct go7007_board_info *board,
|
|
struct device *dev)
|
|
{
|
|
struct go7007 *go;
|
|
|
|
go = kzalloc(sizeof(struct go7007), GFP_KERNEL);
|
|
if (go == NULL)
|
|
return NULL;
|
|
go->dev = dev;
|
|
go->board_info = board;
|
|
go->tuner_type = -1;
|
|
mutex_init(&go->hw_lock);
|
|
init_waitqueue_head(&go->frame_waitq);
|
|
spin_lock_init(&go->spinlock);
|
|
go->status = STATUS_INIT;
|
|
init_waitqueue_head(&go->interrupt_waitq);
|
|
go7007_update_board(go);
|
|
go->format = V4L2_PIX_FMT_MJPEG;
|
|
go->bitrate = 1500000;
|
|
go->fps_scale = 1;
|
|
go->aspect_ratio = GO7007_RATIO_1_1;
|
|
|
|
return go;
|
|
}
|
|
EXPORT_SYMBOL(go7007_alloc);
|
|
|
|
void go7007_update_board(struct go7007 *go)
|
|
{
|
|
const struct go7007_board_info *board = go->board_info;
|
|
|
|
if (board->sensor_flags & GO7007_SENSOR_TV) {
|
|
go->standard = GO7007_STD_NTSC;
|
|
go->std = V4L2_STD_NTSC_M;
|
|
go->width = 720;
|
|
go->height = 480;
|
|
go->sensor_framerate = 30000;
|
|
} else {
|
|
go->standard = GO7007_STD_OTHER;
|
|
go->width = board->sensor_width;
|
|
go->height = board->sensor_height;
|
|
go->sensor_framerate = board->sensor_framerate;
|
|
}
|
|
go->encoder_v_offset = board->sensor_v_offset;
|
|
go->encoder_h_offset = board->sensor_h_offset;
|
|
}
|
|
EXPORT_SYMBOL(go7007_update_board);
|
|
|
|
MODULE_LICENSE("GPL v2");
|