diff options
author | 2023-02-21 18:24:12 -0800 | |
---|---|---|
committer | 2023-02-21 18:24:12 -0800 | |
commit | 5b7c4cabbb65f5c469464da6c5f614cbd7f730f2 (patch) | |
tree | cc5c2d0a898769fd59549594fedb3ee6f84e59a0 /drivers/media/usb/go7007/go7007-v4l2.c | |
download | linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.tar.gz linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.zip |
Merge tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-nextgrafted
Pull networking updates from Jakub Kicinski:
"Core:
- Add dedicated kmem_cache for typical/small skb->head, avoid having
to access struct page at kfree time, and improve memory use.
- Introduce sysctl to set default RPS configuration for new netdevs.
- Define Netlink protocol specification format which can be used to
describe messages used by each family and auto-generate parsers.
Add tools for generating kernel data structures and uAPI headers.
- Expose all net/core sysctls inside netns.
- Remove 4s sleep in netpoll if carrier is instantly detected on
boot.
- Add configurable limit of MDB entries per port, and port-vlan.
- Continue populating drop reasons throughout the stack.
- Retire a handful of legacy Qdiscs and classifiers.
Protocols:
- Support IPv4 big TCP (TSO frames larger than 64kB).
- Add IP_LOCAL_PORT_RANGE socket option, to control local port range
on socket by socket basis.
- Track and report in procfs number of MPTCP sockets used.
- Support mixing IPv4 and IPv6 flows in the in-kernel MPTCP path
manager.
- IPv6: don't check net.ipv6.route.max_size and rely on garbage
collection to free memory (similarly to IPv4).
- Support Penultimate Segment Pop (PSP) flavor in SRv6 (RFC8986).
- ICMP: add per-rate limit counters.
- Add support for user scanning requests in ieee802154.
- Remove static WEP support.
- Support minimal Wi-Fi 7 Extremely High Throughput (EHT) rate
reporting.
- WiFi 7 EHT channel puncturing support (client & AP).
BPF:
- Add a rbtree data structure following the "next-gen data structure"
precedent set by recently added linked list, that is, by using
kfunc + kptr instead of adding a new BPF map type.
- Expose XDP hints via kfuncs with initial support for RX hash and
timestamp metadata.
- Add BPF_F_NO_TUNNEL_KEY extension to bpf_skb_set_tunnel_key to
better support decap on GRE tunnel devices not operating in collect
metadata.
- Improve x86 JIT's codegen for PROBE_MEM runtime error checks.
- Remove the need for trace_printk_lock for bpf_trace_printk and
bpf_trace_vprintk helpers.
- Extend libbpf's bpf_tracing.h support for tracing arguments of
kprobes/uprobes and syscall as a special case.
- Significantly reduce the search time for module symbols by
livepatch and BPF.
- Enable cpumasks to be used as kptrs, which is useful for tracing
programs tracking which tasks end up running on which CPUs in
different time intervals.
- Add support for BPF trampoline on s390x and riscv64.
- Add capability to export the XDP features supported by the NIC.
- Add __bpf_kfunc tag for marking kernel functions as kfuncs.
- Add cgroup.memory=nobpf kernel parameter option to disable BPF
memory accounting for container environments.
Netfilter:
- Remove the CLUSTERIP target. It has been marked as obsolete for
years, and we still have WARN splats wrt races of the out-of-band
/proc interface installed by this target.
- Add 'destroy' commands to nf_tables. They are identical to the
existing 'delete' commands, but do not return an error if the
referenced object (set, chain, rule...) did not exist.
Driver API:
- Improve cpumask_local_spread() locality to help NICs set the right
IRQ affinity on AMD platforms.
- Separate C22 and C45 MDIO bus transactions more clearly.
- Introduce new DCB table to control DSCP rewrite on egress.
- Support configuration of Physical Layer Collision Avoidance (PLCA)
Reconciliation Sublayer (RS) (802.3cg-2019). Modern version of
shared medium Ethernet.
- Support for MAC Merge layer (IEEE 802.3-2018 clause 99). Allowing
preemption of low priority frames by high priority frames.
- Add support for controlling MACSec offload using netlink SET.
- Rework devlink instance refcounts to allow registration and
de-registration under the instance lock. Split the code into
multiple files, drop some of the unnecessarily granular locks and
factor out common parts of netlink operation handling.
- Add TX frame aggregation parameters (for USB drivers).
- Add a new attr TCA_EXT_WARN_MSG to report TC (offload) warning
messages with notifications for debug.
- Allow offloading of UDP NEW connections via act_ct.
- Add support for per action HW stats in TC.
- Support hardware miss to TC action (continue processing in SW from
a specific point in the action chain).
- Warn if old Wireless Extension user space interface is used with
modern cfg80211/mac80211 drivers. Do not support Wireless
Extensions for Wi-Fi 7 devices at all. Everyone should switch to
using nl80211 interface instead.
- Improve the CAN bit timing configuration. Use extack to return
error messages directly to user space, update the SJW handling,
including the definition of a new default value that will benefit
CAN-FD controllers, by increasing their oscillator tolerance.
New hardware / drivers:
- Ethernet:
- nVidia BlueField-3 support (control traffic driver)
- Ethernet support for imx93 SoCs
- Motorcomm yt8531 gigabit Ethernet PHY
- onsemi NCN26000 10BASE-T1S PHY (with support for PLCA)
- Microchip LAN8841 PHY (incl. cable diagnostics and PTP)
- Amlogic gxl MDIO mux
- WiFi:
- RealTek RTL8188EU (rtl8xxxu)
- Qualcomm Wi-Fi 7 devices (ath12k)
- CAN:
- Renesas R-Car V4H
Drivers:
- Bluetooth:
- Set Per Platform Antenna Gain (PPAG) for Intel controllers.
- Ethernet NICs:
- Intel (1G, igc):
- support TSN / Qbv / packet scheduling features of i226 model
- Intel (100G, ice):
- use GNSS subsystem instead of TTY
- multi-buffer XDP support
- extend support for GPIO pins to E823 devices
- nVidia/Mellanox:
- update the shared buffer configuration on PFC commands
- implement PTP adjphase function for HW offset control
- TC support for Geneve and GRE with VF tunnel offload
- more efficient crypto key management method
- multi-port eswitch support
- Netronome/Corigine:
- add DCB IEEE support
- support IPsec offloading for NFP3800
- Freescale/NXP (enetc):
- support XDP_REDIRECT for XDP non-linear buffers
- improve reconfig, avoid link flap and waiting for idle
- support MAC Merge layer
- Other NICs:
- sfc/ef100: add basic devlink support for ef100
- ionic: rx_push mode operation (writing descriptors via MMIO)
- bnxt: use the auxiliary bus abstraction for RDMA
- r8169: disable ASPM and reset bus in case of tx timeout
- cpsw: support QSGMII mode for J721e CPSW9G
- cpts: support pulse-per-second output
- ngbe: add an mdio bus driver
- usbnet: optimize usbnet_bh() by avoiding unnecessary queuing
- r8152: handle devices with FW with NCM support
- amd-xgbe: support 10Mbps, 2.5GbE speeds and rx-adaptation
- virtio-net: support multi buffer XDP
- virtio/vsock: replace virtio_vsock_pkt with sk_buff
- tsnep: XDP support
- Ethernet high-speed switches:
- nVidia/Mellanox (mlxsw):
- add support for latency TLV (in FW control messages)
- Microchip (sparx5):
- separate explicit and implicit traffic forwarding rules, make
the implicit rules always active
- add support for egress DSCP rewrite
- IS0 VCAP support (Ingress Classification)
- IS2 VCAP filters (protos, L3 addrs, L4 ports, flags, ToS
etc.)
- ES2 VCAP support (Egress Access Control)
- support for Per-Stream Filtering and Policing (802.1Q,
8.6.5.1)
- Ethernet embedded switches:
- Marvell (mv88e6xxx):
- add MAB (port auth) offload support
- enable PTP receive for mv88e6390
- NXP (ocelot):
- support MAC Merge layer
- support for the the vsc7512 internal copper phys
- Microchip:
- lan9303: convert to PHYLINK
- lan966x: support TC flower filter statistics
- lan937x: PTP support for KSZ9563/KSZ8563 and LAN937x
- lan937x: support Credit Based Shaper configuration
- ksz9477: support Energy Efficient Ethernet
- other:
- qca8k: convert to regmap read/write API, use bulk operations
- rswitch: Improve TX timestamp accuracy
- Intel WiFi (iwlwifi):
- EHT (Wi-Fi 7) rate reporting
- STEP equalizer support: transfer some STEP (connection to radio
on platforms with integrated wifi) related parameters from the
BIOS to the firmware.
- Qualcomm 802.11ax WiFi (ath11k):
- IPQ5018 support
- Fine Timing Measurement (FTM) responder role support
- channel 177 support
- MediaTek WiFi (mt76):
- per-PHY LED support
- mt7996: EHT (Wi-Fi 7) support
- Wireless Ethernet Dispatch (WED) reset support
- switch to using page pool allocator
- RealTek WiFi (rtw89):
- support new version of Bluetooth co-existance
- Mobile:
- rmnet: support TX aggregation"
* tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (1872 commits)
page_pool: add a comment explaining the fragment counter usage
net: ethtool: fix __ethtool_dev_mm_supported() implementation
ethtool: pse-pd: Fix double word in comments
xsk: add linux/vmalloc.h to xsk.c
sefltests: netdevsim: wait for devlink instance after netns removal
selftest: fib_tests: Always cleanup before exit
net/mlx5e: Align IPsec ASO result memory to be as required by hardware
net/mlx5e: TC, Set CT miss to the specific ct action instance
net/mlx5e: Rename CHAIN_TO_REG to MAPPED_OBJ_TO_REG
net/mlx5: Refactor tc miss handling to a single function
net/mlx5: Kconfig: Make tc offload depend on tc skb extension
net/sched: flower: Support hardware miss to tc action
net/sched: flower: Move filter handle initialization earlier
net/sched: cls_api: Support hardware miss to tc action
net/sched: Rename user cookie and act cookie
sfc: fix builds without CONFIG_RTC_LIB
sfc: clean up some inconsistent indentings
net/mlx4_en: Introduce flexible array to silence overflow warning
net: lan966x: Fix possible deadlock inside PTP
net/ulp: Remove redundant ->clone() test in inet_clone_ulp().
...
Diffstat (limited to 'drivers/media/usb/go7007/go7007-v4l2.c')
-rw-r--r-- | drivers/media/usb/go7007/go7007-v4l2.c | 1153 |
1 files changed, 1153 insertions, 0 deletions
diff --git a/drivers/media/usb/go7007/go7007-v4l2.c b/drivers/media/usb/go7007/go7007-v4l2.c new file mode 100644 index 000000000..b2edc4dea --- /dev/null +++ b/drivers/media/usb/go7007/go7007-v4l2.c @@ -0,0 +1,1153 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2005-2006 Micronas USA Inc. + */ + +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/sched.h> +#include <linux/spinlock.h> +#include <linux/slab.h> +#include <linux/fs.h> +#include <linux/unistd.h> +#include <linux/time.h> +#include <linux/vmalloc.h> +#include <linux/pagemap.h> +#include <linux/i2c.h> +#include <linux/mutex.h> +#include <linux/uaccess.h> +#include <linux/videodev2.h> +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-subdev.h> +#include <media/v4l2-event.h> +#include <media/videobuf2-vmalloc.h> +#include <media/i2c/saa7115.h> + +#include "go7007-priv.h" + +#define call_all(dev, o, f, args...) \ + v4l2_device_call_until_err(dev, 0, o, f, ##args) + +static bool valid_pixelformat(u32 pixelformat) +{ + switch (pixelformat) { + case V4L2_PIX_FMT_MJPEG: + case V4L2_PIX_FMT_MPEG1: + case V4L2_PIX_FMT_MPEG2: + case V4L2_PIX_FMT_MPEG4: + return true; + default: + return false; + } +} + +static u32 get_frame_type_flag(struct go7007_buffer *vb, int format) +{ + u8 *ptr = vb2_plane_vaddr(&vb->vb.vb2_buf, 0); + + switch (format) { + case V4L2_PIX_FMT_MJPEG: + return V4L2_BUF_FLAG_KEYFRAME; + case V4L2_PIX_FMT_MPEG4: + switch ((ptr[vb->frame_offset + 4] >> 6) & 0x3) { + case 0: + return V4L2_BUF_FLAG_KEYFRAME; + case 1: + return V4L2_BUF_FLAG_PFRAME; + case 2: + return V4L2_BUF_FLAG_BFRAME; + default: + return 0; + } + case V4L2_PIX_FMT_MPEG1: + case V4L2_PIX_FMT_MPEG2: + switch ((ptr[vb->frame_offset + 5] >> 3) & 0x7) { + case 1: + return V4L2_BUF_FLAG_KEYFRAME; + case 2: + return V4L2_BUF_FLAG_PFRAME; + case 3: + return V4L2_BUF_FLAG_BFRAME; + default: + return 0; + } + } + + return 0; +} + +static void get_resolution(struct go7007 *go, int *width, int *height) +{ + switch (go->standard) { + case GO7007_STD_NTSC: + *width = 720; + *height = 480; + break; + case GO7007_STD_PAL: + *width = 720; + *height = 576; + break; + case GO7007_STD_OTHER: + default: + *width = go->board_info->sensor_width; + *height = go->board_info->sensor_height; + break; + } +} + +static void set_formatting(struct go7007 *go) +{ + if (go->format == V4L2_PIX_FMT_MJPEG) { + go->pali = 0; + go->aspect_ratio = GO7007_RATIO_1_1; + go->gop_size = 0; + go->ipb = 0; + go->closed_gop = 0; + go->repeat_seqhead = 0; + go->seq_header_enable = 0; + go->gop_header_enable = 0; + go->dvd_mode = 0; + return; + } + + switch (go->format) { + case V4L2_PIX_FMT_MPEG1: + go->pali = 0; + break; + default: + case V4L2_PIX_FMT_MPEG2: + go->pali = 0x48; + break; + case V4L2_PIX_FMT_MPEG4: + /* For future reference: this is the list of MPEG4 + * profiles that are available, although they are + * untested: + * + * Profile pali + * -------------- ---- + * PROFILE_S_L0 0x08 + * PROFILE_S_L1 0x01 + * PROFILE_S_L2 0x02 + * PROFILE_S_L3 0x03 + * PROFILE_ARTS_L1 0x91 + * PROFILE_ARTS_L2 0x92 + * PROFILE_ARTS_L3 0x93 + * PROFILE_ARTS_L4 0x94 + * PROFILE_AS_L0 0xf0 + * PROFILE_AS_L1 0xf1 + * PROFILE_AS_L2 0xf2 + * PROFILE_AS_L3 0xf3 + * PROFILE_AS_L4 0xf4 + * PROFILE_AS_L5 0xf5 + */ + go->pali = 0xf5; + break; + } + go->gop_size = v4l2_ctrl_g_ctrl(go->mpeg_video_gop_size); + go->closed_gop = v4l2_ctrl_g_ctrl(go->mpeg_video_gop_closure); + go->ipb = v4l2_ctrl_g_ctrl(go->mpeg_video_b_frames) != 0; + go->bitrate = v4l2_ctrl_g_ctrl(go->mpeg_video_bitrate); + go->repeat_seqhead = v4l2_ctrl_g_ctrl(go->mpeg_video_rep_seqheader); + go->gop_header_enable = 1; + go->dvd_mode = 0; + if (go->format == V4L2_PIX_FMT_MPEG2) + go->dvd_mode = + go->bitrate == 9800000 && + go->gop_size == 15 && + go->ipb == 0 && + go->repeat_seqhead == 1 && + go->closed_gop; + + switch (v4l2_ctrl_g_ctrl(go->mpeg_video_aspect_ratio)) { + default: + case V4L2_MPEG_VIDEO_ASPECT_1x1: + go->aspect_ratio = GO7007_RATIO_1_1; + break; + case V4L2_MPEG_VIDEO_ASPECT_4x3: + go->aspect_ratio = GO7007_RATIO_4_3; + break; + case V4L2_MPEG_VIDEO_ASPECT_16x9: + go->aspect_ratio = GO7007_RATIO_16_9; + break; + } +} + +static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try) +{ + int sensor_height = 0, sensor_width = 0; + int width, height; + + if (fmt != NULL && !valid_pixelformat(fmt->fmt.pix.pixelformat)) + return -EINVAL; + + get_resolution(go, &sensor_width, &sensor_height); + + if (fmt == NULL) { + width = sensor_width; + height = sensor_height; + } else if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) { + if (fmt->fmt.pix.width > sensor_width) + width = sensor_width; + else if (fmt->fmt.pix.width < 144) + width = 144; + else + width = fmt->fmt.pix.width & ~0x0f; + + if (fmt->fmt.pix.height > sensor_height) + height = sensor_height; + else if (fmt->fmt.pix.height < 96) + height = 96; + else + height = fmt->fmt.pix.height & ~0x0f; + } else { + width = fmt->fmt.pix.width; + + if (width <= sensor_width / 4) { + width = sensor_width / 4; + height = sensor_height / 4; + } else if (width <= sensor_width / 2) { + width = sensor_width / 2; + height = sensor_height / 2; + } else { + width = sensor_width; + height = sensor_height; + } + width &= ~0xf; + height &= ~0xf; + } + + if (fmt != NULL) { + u32 pixelformat = fmt->fmt.pix.pixelformat; + + memset(fmt, 0, sizeof(*fmt)); + fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + fmt->fmt.pix.width = width; + fmt->fmt.pix.height = height; + fmt->fmt.pix.pixelformat = pixelformat; + fmt->fmt.pix.field = V4L2_FIELD_NONE; + fmt->fmt.pix.bytesperline = 0; + fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE; + fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; + } + + if (try) + return 0; + + if (fmt) + go->format = fmt->fmt.pix.pixelformat; + go->width = width; + go->height = height; + go->encoder_h_offset = go->board_info->sensor_h_offset; + go->encoder_v_offset = go->board_info->sensor_v_offset; + + if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) { + struct v4l2_subdev_format format = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + + format.format.code = MEDIA_BUS_FMT_FIXED; + format.format.width = fmt ? fmt->fmt.pix.width : width; + format.format.height = height; + go->encoder_h_halve = 0; + go->encoder_v_halve = 0; + go->encoder_subsample = 0; + call_all(&go->v4l2_dev, pad, set_fmt, NULL, &format); + } else { + if (width <= sensor_width / 4) { + go->encoder_h_halve = 1; + go->encoder_v_halve = 1; + go->encoder_subsample = 1; + } else if (width <= sensor_width / 2) { + go->encoder_h_halve = 1; + go->encoder_v_halve = 1; + go->encoder_subsample = 0; + } else { + go->encoder_h_halve = 0; + go->encoder_v_halve = 0; + go->encoder_subsample = 0; + } + } + return 0; +} + +static int vidioc_querycap(struct file *file, void *priv, + struct v4l2_capability *cap) +{ + struct go7007 *go = video_drvdata(file); + + strscpy(cap->driver, "go7007", sizeof(cap->driver)); + strscpy(cap->card, go->name, sizeof(cap->card)); + strscpy(cap->bus_info, go->bus_info, sizeof(cap->bus_info)); + return 0; +} + +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_fmtdesc *fmt) +{ + switch (fmt->index) { + case 0: + fmt->pixelformat = V4L2_PIX_FMT_MJPEG; + break; + case 1: + fmt->pixelformat = V4L2_PIX_FMT_MPEG1; + break; + case 2: + fmt->pixelformat = V4L2_PIX_FMT_MPEG2; + break; + case 3: + fmt->pixelformat = V4L2_PIX_FMT_MPEG4; + break; + default: + return -EINVAL; + } + return 0; +} + +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *fmt) +{ + struct go7007 *go = video_drvdata(file); + + fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + fmt->fmt.pix.width = go->width; + fmt->fmt.pix.height = go->height; + fmt->fmt.pix.pixelformat = go->format; + fmt->fmt.pix.field = V4L2_FIELD_NONE; + fmt->fmt.pix.bytesperline = 0; + fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE; + fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; + + return 0; +} + +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *fmt) +{ + struct go7007 *go = video_drvdata(file); + + return set_capture_size(go, fmt, 1); +} + +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *fmt) +{ + struct go7007 *go = video_drvdata(file); + + if (vb2_is_busy(&go->vidq)) + return -EBUSY; + + return set_capture_size(go, fmt, 0); +} + +static int go7007_queue_setup(struct vb2_queue *q, + unsigned int *num_buffers, unsigned int *num_planes, + unsigned int sizes[], struct device *alloc_devs[]) +{ + sizes[0] = GO7007_BUF_SIZE; + *num_planes = 1; + + if (*num_buffers < 2) + *num_buffers = 2; + + return 0; +} + +static void go7007_buf_queue(struct vb2_buffer *vb) +{ + struct vb2_queue *vq = vb->vb2_queue; + struct go7007 *go = vb2_get_drv_priv(vq); + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct go7007_buffer *go7007_vb = + container_of(vbuf, struct go7007_buffer, vb); + unsigned long flags; + + spin_lock_irqsave(&go->spinlock, flags); + list_add_tail(&go7007_vb->list, &go->vidq_active); + spin_unlock_irqrestore(&go->spinlock, flags); +} + +static int go7007_buf_prepare(struct vb2_buffer *vb) +{ + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct go7007_buffer *go7007_vb = + container_of(vbuf, struct go7007_buffer, vb); + + go7007_vb->modet_active = 0; + go7007_vb->frame_offset = 0; + vb->planes[0].bytesused = 0; + return 0; +} + +static void go7007_buf_finish(struct vb2_buffer *vb) +{ + struct vb2_queue *vq = vb->vb2_queue; + struct go7007 *go = vb2_get_drv_priv(vq); + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct go7007_buffer *go7007_vb = + container_of(vbuf, struct go7007_buffer, vb); + u32 frame_type_flag = get_frame_type_flag(go7007_vb, go->format); + + vbuf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_BFRAME | + V4L2_BUF_FLAG_PFRAME); + vbuf->flags |= frame_type_flag; + vbuf->field = V4L2_FIELD_NONE; +} + +static int go7007_start_streaming(struct vb2_queue *q, unsigned int count) +{ + struct go7007 *go = vb2_get_drv_priv(q); + int ret; + + set_formatting(go); + mutex_lock(&go->hw_lock); + go->next_seq = 0; + go->active_buf = NULL; + go->modet_event_status = 0; + q->streaming = 1; + if (go7007_start_encoder(go) < 0) + ret = -EIO; + else + ret = 0; + mutex_unlock(&go->hw_lock); + if (ret) { + q->streaming = 0; + return ret; + } + call_all(&go->v4l2_dev, video, s_stream, 1); + v4l2_ctrl_grab(go->mpeg_video_gop_size, true); + v4l2_ctrl_grab(go->mpeg_video_gop_closure, true); + v4l2_ctrl_grab(go->mpeg_video_bitrate, true); + v4l2_ctrl_grab(go->mpeg_video_aspect_ratio, true); + /* Turn on Capture LED */ + if (go->board_id == GO7007_BOARDID_ADS_USBAV_709) + go7007_write_addr(go, 0x3c82, 0x0005); + return ret; +} + +static void go7007_stop_streaming(struct vb2_queue *q) +{ + struct go7007 *go = vb2_get_drv_priv(q); + unsigned long flags; + + q->streaming = 0; + go7007_stream_stop(go); + mutex_lock(&go->hw_lock); + go7007_reset_encoder(go); + mutex_unlock(&go->hw_lock); + call_all(&go->v4l2_dev, video, s_stream, 0); + + spin_lock_irqsave(&go->spinlock, flags); + INIT_LIST_HEAD(&go->vidq_active); + spin_unlock_irqrestore(&go->spinlock, flags); + v4l2_ctrl_grab(go->mpeg_video_gop_size, false); + v4l2_ctrl_grab(go->mpeg_video_gop_closure, false); + v4l2_ctrl_grab(go->mpeg_video_bitrate, false); + v4l2_ctrl_grab(go->mpeg_video_aspect_ratio, false); + /* Turn on Capture LED */ + if (go->board_id == GO7007_BOARDID_ADS_USBAV_709) + go7007_write_addr(go, 0x3c82, 0x000d); +} + +static const struct vb2_ops go7007_video_qops = { + .queue_setup = go7007_queue_setup, + .buf_queue = go7007_buf_queue, + .buf_prepare = go7007_buf_prepare, + .buf_finish = go7007_buf_finish, + .start_streaming = go7007_start_streaming, + .stop_streaming = go7007_stop_streaming, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, +}; + +static int vidioc_g_parm(struct file *filp, void *priv, + struct v4l2_streamparm *parm) +{ + struct go7007 *go = video_drvdata(filp); + struct v4l2_fract timeperframe = { + .numerator = 1001 * go->fps_scale, + .denominator = go->sensor_framerate, + }; + + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + parm->parm.capture.readbuffers = 2; + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; + parm->parm.capture.timeperframe = timeperframe; + + return 0; +} + +static int vidioc_s_parm(struct file *filp, void *priv, + struct v4l2_streamparm *parm) +{ + struct go7007 *go = video_drvdata(filp); + unsigned int n, d; + + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + n = go->sensor_framerate * + parm->parm.capture.timeperframe.numerator; + d = 1001 * parm->parm.capture.timeperframe.denominator; + if (n != 0 && d != 0 && n > d) + go->fps_scale = (n + d/2) / d; + else + go->fps_scale = 1; + + return vidioc_g_parm(filp, priv, parm); +} + +/* VIDIOC_ENUMSTD on go7007 were used for enumerating the supported fps and + its resolution, when the device is not connected to TV. + This is were an API abuse, probably used by the lack of specific IOCTL's to + enumerate it, by the time the driver was written. + + However, since kernel 2.6.19, two new ioctls (VIDIOC_ENUM_FRAMEINTERVALS + and VIDIOC_ENUM_FRAMESIZES) were added for this purpose. + + The two functions below implement the newer ioctls +*/ +static int vidioc_enum_framesizes(struct file *filp, void *priv, + struct v4l2_frmsizeenum *fsize) +{ + struct go7007 *go = video_drvdata(filp); + int width, height; + + if (fsize->index > 2) + return -EINVAL; + + if (!valid_pixelformat(fsize->pixel_format)) + return -EINVAL; + + get_resolution(go, &width, &height); + fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; + fsize->discrete.width = (width >> fsize->index) & ~0xf; + fsize->discrete.height = (height >> fsize->index) & ~0xf; + return 0; +} + +static int vidioc_enum_frameintervals(struct file *filp, void *priv, + struct v4l2_frmivalenum *fival) +{ + struct go7007 *go = video_drvdata(filp); + int width, height; + int i; + + if (fival->index > 4) + return -EINVAL; + + if (!valid_pixelformat(fival->pixel_format)) + return -EINVAL; + + if (!(go->board_info->sensor_flags & GO7007_SENSOR_SCALING)) { + get_resolution(go, &width, &height); + for (i = 0; i <= 2; i++) + if (fival->width == ((width >> i) & ~0xf) && + fival->height == ((height >> i) & ~0xf)) + break; + if (i > 2) + return -EINVAL; + } + fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; + fival->discrete.numerator = 1001 * (fival->index + 1); + fival->discrete.denominator = go->sensor_framerate; + return 0; +} + +static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std) +{ + struct go7007 *go = video_drvdata(file); + + *std = go->std; + return 0; +} + +static int go7007_s_std(struct go7007 *go) +{ + if (go->std & V4L2_STD_625_50) { + go->standard = GO7007_STD_PAL; + go->sensor_framerate = 25025; + } else { + go->standard = GO7007_STD_NTSC; + go->sensor_framerate = 30000; + } + + call_all(&go->v4l2_dev, video, s_std, go->std); + set_capture_size(go, NULL, 0); + return 0; +} + +static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id std) +{ + struct go7007 *go = video_drvdata(file); + + if (vb2_is_busy(&go->vidq)) + return -EBUSY; + + go->std = std; + + return go7007_s_std(go); +} + +static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std) +{ + struct go7007 *go = video_drvdata(file); + + return call_all(&go->v4l2_dev, video, querystd, std); +} + +static int vidioc_enum_input(struct file *file, void *priv, + struct v4l2_input *inp) +{ + struct go7007 *go = video_drvdata(file); + + if (inp->index >= go->board_info->num_inputs) + return -EINVAL; + + strscpy(inp->name, go->board_info->inputs[inp->index].name, + sizeof(inp->name)); + + /* If this board has a tuner, it will be the first input */ + if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) && + inp->index == 0) + inp->type = V4L2_INPUT_TYPE_TUNER; + else + inp->type = V4L2_INPUT_TYPE_CAMERA; + + if (go->board_info->num_aud_inputs) + inp->audioset = (1 << go->board_info->num_aud_inputs) - 1; + else + inp->audioset = 0; + inp->tuner = 0; + if (go->board_info->sensor_flags & GO7007_SENSOR_TV) + inp->std = video_devdata(file)->tvnorms; + else + inp->std = 0; + + return 0; +} + + +static int vidioc_g_input(struct file *file, void *priv, unsigned int *input) +{ + struct go7007 *go = video_drvdata(file); + + *input = go->input; + + return 0; +} + +static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a) +{ + struct go7007 *go = video_drvdata(file); + + if (a->index >= go->board_info->num_aud_inputs) + return -EINVAL; + strscpy(a->name, go->board_info->aud_inputs[a->index].name, + sizeof(a->name)); + a->capability = V4L2_AUDCAP_STEREO; + return 0; +} + +static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a) +{ + struct go7007 *go = video_drvdata(file); + + a->index = go->aud_input; + strscpy(a->name, go->board_info->aud_inputs[go->aud_input].name, + sizeof(a->name)); + a->capability = V4L2_AUDCAP_STEREO; + return 0; +} + +static int vidioc_s_audio(struct file *file, void *fh, + const struct v4l2_audio *a) +{ + struct go7007 *go = video_drvdata(file); + + if (a->index >= go->board_info->num_aud_inputs) + return -EINVAL; + go->aud_input = a->index; + v4l2_subdev_call(go->sd_audio, audio, s_routing, + go->board_info->aud_inputs[go->aud_input].audio_input, 0, 0); + return 0; +} + +static void go7007_s_input(struct go7007 *go) +{ + unsigned int input = go->input; + + v4l2_subdev_call(go->sd_video, video, s_routing, + go->board_info->inputs[input].video_input, 0, + go->board_info->video_config); + if (go->board_info->num_aud_inputs) { + int aud_input = go->board_info->inputs[input].audio_index; + + v4l2_subdev_call(go->sd_audio, audio, s_routing, + go->board_info->aud_inputs[aud_input].audio_input, 0, 0); + go->aud_input = aud_input; + } +} + +static int vidioc_s_input(struct file *file, void *priv, unsigned int input) +{ + struct go7007 *go = video_drvdata(file); + + if (input >= go->board_info->num_inputs) + return -EINVAL; + if (vb2_is_busy(&go->vidq)) + return -EBUSY; + + go->input = input; + go7007_s_input(go); + + return 0; +} + +static int vidioc_g_tuner(struct file *file, void *priv, + struct v4l2_tuner *t) +{ + struct go7007 *go = video_drvdata(file); + + if (t->index != 0) + return -EINVAL; + + strscpy(t->name, "Tuner", sizeof(t->name)); + return call_all(&go->v4l2_dev, tuner, g_tuner, t); +} + +static int vidioc_s_tuner(struct file *file, void *priv, + const struct v4l2_tuner *t) +{ + struct go7007 *go = video_drvdata(file); + + if (t->index != 0) + return -EINVAL; + + return call_all(&go->v4l2_dev, tuner, s_tuner, t); +} + +static int vidioc_g_frequency(struct file *file, void *priv, + struct v4l2_frequency *f) +{ + struct go7007 *go = video_drvdata(file); + + if (f->tuner) + return -EINVAL; + + return call_all(&go->v4l2_dev, tuner, g_frequency, f); +} + +static int vidioc_s_frequency(struct file *file, void *priv, + const struct v4l2_frequency *f) +{ + struct go7007 *go = video_drvdata(file); + + if (f->tuner) + return -EINVAL; + + return call_all(&go->v4l2_dev, tuner, s_frequency, f); +} + +static int vidioc_log_status(struct file *file, void *priv) +{ + struct go7007 *go = video_drvdata(file); + + v4l2_ctrl_log_status(file, priv); + return call_all(&go->v4l2_dev, core, log_status); +} + +static int vidioc_subscribe_event(struct v4l2_fh *fh, + const struct v4l2_event_subscription *sub) +{ + + switch (sub->type) { + case V4L2_EVENT_MOTION_DET: + /* Allow for up to 30 events (1 second for NTSC) to be + * stored. */ + return v4l2_event_subscribe(fh, sub, 30, NULL); + default: + return v4l2_ctrl_subscribe_event(fh, sub); + } +} + + +static int go7007_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct go7007 *go = + container_of(ctrl->handler, struct go7007, hdl); + unsigned y; + u8 *mt; + + switch (ctrl->id) { + case V4L2_CID_PIXEL_THRESHOLD0: + go->modet[0].pixel_threshold = ctrl->val; + break; + case V4L2_CID_MOTION_THRESHOLD0: + go->modet[0].motion_threshold = ctrl->val; + break; + case V4L2_CID_MB_THRESHOLD0: + go->modet[0].mb_threshold = ctrl->val; + break; + case V4L2_CID_PIXEL_THRESHOLD1: + go->modet[1].pixel_threshold = ctrl->val; + break; + case V4L2_CID_MOTION_THRESHOLD1: + go->modet[1].motion_threshold = ctrl->val; + break; + case V4L2_CID_MB_THRESHOLD1: + go->modet[1].mb_threshold = ctrl->val; + break; + case V4L2_CID_PIXEL_THRESHOLD2: + go->modet[2].pixel_threshold = ctrl->val; + break; + case V4L2_CID_MOTION_THRESHOLD2: + go->modet[2].motion_threshold = ctrl->val; + break; + case V4L2_CID_MB_THRESHOLD2: + go->modet[2].mb_threshold = ctrl->val; + break; + case V4L2_CID_PIXEL_THRESHOLD3: + go->modet[3].pixel_threshold = ctrl->val; + break; + case V4L2_CID_MOTION_THRESHOLD3: + go->modet[3].motion_threshold = ctrl->val; + break; + case V4L2_CID_MB_THRESHOLD3: + go->modet[3].mb_threshold = ctrl->val; + break; + case V4L2_CID_DETECT_MD_REGION_GRID: + mt = go->modet_map; + for (y = 0; y < go->height / 16; y++, mt += go->width / 16) + memcpy(mt, ctrl->p_new.p_u8 + y * (720 / 16), go->width / 16); + break; + default: + return -EINVAL; + } + return 0; +} + +static const struct v4l2_file_operations go7007_fops = { + .owner = THIS_MODULE, + .open = v4l2_fh_open, + .release = vb2_fop_release, + .unlocked_ioctl = video_ioctl2, + .read = vb2_fop_read, + .mmap = vb2_fop_mmap, + .poll = vb2_fop_poll, +}; + +static const struct v4l2_ioctl_ops video_ioctl_ops = { + .vidioc_querycap = vidioc_querycap, + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_g_std = vidioc_g_std, + .vidioc_s_std = vidioc_s_std, + .vidioc_querystd = vidioc_querystd, + .vidioc_enum_input = vidioc_enum_input, + .vidioc_g_input = vidioc_g_input, + .vidioc_s_input = vidioc_s_input, + .vidioc_enumaudio = vidioc_enumaudio, + .vidioc_g_audio = vidioc_g_audio, + .vidioc_s_audio = vidioc_s_audio, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, + .vidioc_g_tuner = vidioc_g_tuner, + .vidioc_s_tuner = vidioc_s_tuner, + .vidioc_g_frequency = vidioc_g_frequency, + .vidioc_s_frequency = vidioc_s_frequency, + .vidioc_g_parm = vidioc_g_parm, + .vidioc_s_parm = vidioc_s_parm, + .vidioc_enum_framesizes = vidioc_enum_framesizes, + .vidioc_enum_frameintervals = vidioc_enum_frameintervals, + .vidioc_log_status = vidioc_log_status, + .vidioc_subscribe_event = vidioc_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +static const struct video_device go7007_template = { + .name = "go7007", + .fops = &go7007_fops, + .release = video_device_release_empty, + .ioctl_ops = &video_ioctl_ops, + .tvnorms = V4L2_STD_ALL, +}; + +static const struct v4l2_ctrl_ops go7007_ctrl_ops = { + .s_ctrl = go7007_s_ctrl, +}; + +static const struct v4l2_ctrl_config go7007_pixel_threshold0_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_PIXEL_THRESHOLD0, + .name = "Pixel Threshold Region 0", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 20, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_motion_threshold0_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_MOTION_THRESHOLD0, + .name = "Motion Threshold Region 0", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 80, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_mb_threshold0_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_MB_THRESHOLD0, + .name = "MB Threshold Region 0", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 200, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_pixel_threshold1_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_PIXEL_THRESHOLD1, + .name = "Pixel Threshold Region 1", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 20, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_motion_threshold1_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_MOTION_THRESHOLD1, + .name = "Motion Threshold Region 1", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 80, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_mb_threshold1_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_MB_THRESHOLD1, + .name = "MB Threshold Region 1", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 200, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_pixel_threshold2_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_PIXEL_THRESHOLD2, + .name = "Pixel Threshold Region 2", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 20, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_motion_threshold2_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_MOTION_THRESHOLD2, + .name = "Motion Threshold Region 2", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 80, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_mb_threshold2_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_MB_THRESHOLD2, + .name = "MB Threshold Region 2", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 200, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_pixel_threshold3_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_PIXEL_THRESHOLD3, + .name = "Pixel Threshold Region 3", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 20, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_motion_threshold3_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_MOTION_THRESHOLD3, + .name = "Motion Threshold Region 3", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 80, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_mb_threshold3_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_MB_THRESHOLD3, + .name = "MB Threshold Region 3", + .type = V4L2_CTRL_TYPE_INTEGER, + .def = 200, + .max = 32767, + .step = 1, +}; + +static const struct v4l2_ctrl_config go7007_mb_regions_ctrl = { + .ops = &go7007_ctrl_ops, + .id = V4L2_CID_DETECT_MD_REGION_GRID, + .dims = { 576 / 16, 720 / 16 }, + .max = 3, + .step = 1, +}; + +int go7007_v4l2_ctrl_init(struct go7007 *go) +{ + struct v4l2_ctrl_handler *hdl = &go->hdl; + struct v4l2_ctrl *ctrl; + + v4l2_ctrl_handler_init(hdl, 22); + go->mpeg_video_gop_size = v4l2_ctrl_new_std(hdl, NULL, + V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, 34, 1, 15); + go->mpeg_video_gop_closure = v4l2_ctrl_new_std(hdl, NULL, + V4L2_CID_MPEG_VIDEO_GOP_CLOSURE, 0, 1, 1, 1); + go->mpeg_video_bitrate = v4l2_ctrl_new_std(hdl, NULL, + V4L2_CID_MPEG_VIDEO_BITRATE, + 64000, 10000000, 1, 9800000); + go->mpeg_video_b_frames = v4l2_ctrl_new_std(hdl, NULL, + V4L2_CID_MPEG_VIDEO_B_FRAMES, 0, 2, 2, 0); + go->mpeg_video_rep_seqheader = v4l2_ctrl_new_std(hdl, NULL, + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, 0, 1, 1, 1); + + go->mpeg_video_aspect_ratio = v4l2_ctrl_new_std_menu(hdl, NULL, + V4L2_CID_MPEG_VIDEO_ASPECT, + V4L2_MPEG_VIDEO_ASPECT_16x9, 0, + V4L2_MPEG_VIDEO_ASPECT_1x1); + ctrl = v4l2_ctrl_new_std(hdl, NULL, + V4L2_CID_JPEG_ACTIVE_MARKER, 0, + V4L2_JPEG_ACTIVE_MARKER_DQT | + V4L2_JPEG_ACTIVE_MARKER_DHT, 0, + V4L2_JPEG_ACTIVE_MARKER_DQT | + V4L2_JPEG_ACTIVE_MARKER_DHT); + if (ctrl) + ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; + v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold0_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold0_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold0_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold1_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold1_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold1_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold2_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold2_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold2_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold3_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold3_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold3_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &go7007_mb_regions_ctrl, NULL); + go->modet_mode = v4l2_ctrl_new_std_menu(hdl, NULL, + V4L2_CID_DETECT_MD_MODE, + V4L2_DETECT_MD_MODE_REGION_GRID, + 1 << V4L2_DETECT_MD_MODE_THRESHOLD_GRID, + V4L2_DETECT_MD_MODE_DISABLED); + if (hdl->error) { + int rv = hdl->error; + + v4l2_err(&go->v4l2_dev, "Could not register controls\n"); + return rv; + } + go->v4l2_dev.ctrl_handler = hdl; + return 0; +} + +int go7007_v4l2_init(struct go7007 *go) +{ + struct video_device *vdev = &go->vdev; + int rv; + + mutex_init(&go->serialize_lock); + mutex_init(&go->queue_lock); + + INIT_LIST_HEAD(&go->vidq_active); + go->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + go->vidq.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; + go->vidq.ops = &go7007_video_qops; + go->vidq.mem_ops = &vb2_vmalloc_memops; + go->vidq.drv_priv = go; + go->vidq.buf_struct_size = sizeof(struct go7007_buffer); + go->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + go->vidq.lock = &go->queue_lock; + rv = vb2_queue_init(&go->vidq); + if (rv) + return rv; + *vdev = go7007_template; + vdev->lock = &go->serialize_lock; + vdev->queue = &go->vidq; + vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | + V4L2_CAP_STREAMING; + if (go->board_info->num_aud_inputs) + vdev->device_caps |= V4L2_CAP_AUDIO; + if (go->board_info->flags & GO7007_BOARD_HAS_TUNER) + vdev->device_caps |= V4L2_CAP_TUNER; + video_set_drvdata(vdev, go); + vdev->v4l2_dev = &go->v4l2_dev; + if (!v4l2_device_has_op(&go->v4l2_dev, 0, video, querystd)) + v4l2_disable_ioctl(vdev, VIDIOC_QUERYSTD); + if (!(go->board_info->flags & GO7007_BOARD_HAS_TUNER)) { + v4l2_disable_ioctl(vdev, VIDIOC_S_FREQUENCY); + v4l2_disable_ioctl(vdev, VIDIOC_G_FREQUENCY); + v4l2_disable_ioctl(vdev, VIDIOC_S_TUNER); + v4l2_disable_ioctl(vdev, VIDIOC_G_TUNER); + } else { + struct v4l2_frequency f = { + .type = V4L2_TUNER_ANALOG_TV, + .frequency = 980, + }; + + call_all(&go->v4l2_dev, tuner, s_frequency, &f); + } + if (!(go->board_info->sensor_flags & GO7007_SENSOR_TV)) { + v4l2_disable_ioctl(vdev, VIDIOC_G_STD); + v4l2_disable_ioctl(vdev, VIDIOC_S_STD); + vdev->tvnorms = 0; + } + if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) + v4l2_disable_ioctl(vdev, VIDIOC_ENUM_FRAMESIZES); + if (go->board_info->num_aud_inputs == 0) { + v4l2_disable_ioctl(vdev, VIDIOC_G_AUDIO); + v4l2_disable_ioctl(vdev, VIDIOC_S_AUDIO); + v4l2_disable_ioctl(vdev, VIDIOC_ENUMAUDIO); + } + /* Setup correct crystal frequency on this board */ + if (go->board_info->sensor_flags & GO7007_SENSOR_SAA7115) + v4l2_subdev_call(go->sd_video, video, s_crystal_freq, + SAA7115_FREQ_24_576_MHZ, + SAA7115_FREQ_FL_APLL | SAA7115_FREQ_FL_UCGC | + SAA7115_FREQ_FL_DOUBLE_ASCLK); + go7007_s_input(go); + if (go->board_info->sensor_flags & GO7007_SENSOR_TV) + go7007_s_std(go); + rv = video_register_device(vdev, VFL_TYPE_VIDEO, -1); + if (rv < 0) + return rv; + dev_info(go->dev, "registered device %s [v4l2]\n", + video_device_node_name(vdev)); + + return 0; +} + +void go7007_v4l2_remove(struct go7007 *go) +{ + v4l2_ctrl_handler_free(&go->hdl); +} |