[media] rcar-vin: add Renesas R-Car VIN driver
A V4L2 driver for Renesas R-Car VIN driver that do not depend on soc_camera. The driver is heavily based on its predecessor and aims to replace it. Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
parent
83934b75c3
commit
f00add9655
|
@ -110,6 +110,7 @@ source "drivers/media/platform/exynos4-is/Kconfig"
|
|||
source "drivers/media/platform/s5p-tv/Kconfig"
|
||||
source "drivers/media/platform/am437x/Kconfig"
|
||||
source "drivers/media/platform/xilinx/Kconfig"
|
||||
source "drivers/media/platform/rcar-vin/Kconfig"
|
||||
|
||||
config VIDEO_TI_CAL
|
||||
tristate "TI CAL (Camera Adaptation Layer) driver"
|
||||
|
|
|
@ -55,4 +55,6 @@ obj-$(CONFIG_VIDEO_AM437X_VPFE) += am437x/
|
|||
|
||||
obj-$(CONFIG_VIDEO_XILINX) += xilinx/
|
||||
|
||||
obj-$(CONFIG_VIDEO_RCAR_VIN) += rcar-vin/
|
||||
|
||||
ccflags-y += -I$(srctree)/drivers/media/i2c
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
config VIDEO_RCAR_VIN
|
||||
tristate "R-Car Video Input (VIN) Driver"
|
||||
depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && OF && HAS_DMA
|
||||
depends on ARCH_RENESAS || COMPILE_TEST
|
||||
select VIDEOBUF2_DMA_CONTIG
|
||||
---help---
|
||||
Support for Renesas R-Car Video Input (VIN) driver.
|
||||
Supports R-Car Gen2 SoCs.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called rcar-vin.
|
|
@ -0,0 +1,3 @@
|
|||
rcar-vin-objs = rcar-core.o rcar-dma.o rcar-v4l2.o
|
||||
|
||||
obj-$(CONFIG_VIDEO_RCAR_VIN) += rcar-vin.o
|
|
@ -0,0 +1,337 @@
|
|||
/*
|
||||
* Driver for Renesas R-Car VIN
|
||||
*
|
||||
* Copyright (C) 2016 Renesas Electronics Corp.
|
||||
* Copyright (C) 2011-2013 Renesas Solutions Corp.
|
||||
* Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
|
||||
* Copyright (C) 2008 Magnus Damm
|
||||
*
|
||||
* Based on the soc-camera rcar_vin driver
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/of_graph.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
|
||||
#include <media/v4l2-of.h>
|
||||
|
||||
#include "rcar-vin.h"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Async notifier
|
||||
*/
|
||||
|
||||
#define notifier_to_vin(n) container_of(n, struct rvin_dev, notifier)
|
||||
|
||||
static int rvin_mbus_supported(struct rvin_dev *vin)
|
||||
{
|
||||
struct v4l2_subdev *sd;
|
||||
struct v4l2_subdev_mbus_code_enum code = {
|
||||
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
|
||||
};
|
||||
|
||||
sd = vin_to_source(vin);
|
||||
|
||||
code.index = 0;
|
||||
while (!v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code)) {
|
||||
code.index++;
|
||||
switch (code.code) {
|
||||
case MEDIA_BUS_FMT_YUYV8_1X16:
|
||||
case MEDIA_BUS_FMT_YUYV8_2X8:
|
||||
case MEDIA_BUS_FMT_YUYV10_2X10:
|
||||
case MEDIA_BUS_FMT_RGB888_1X24:
|
||||
vin->source.code = code.code;
|
||||
vin_dbg(vin, "Found supported media bus format: %d\n",
|
||||
vin->source.code);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int rvin_graph_notify_complete(struct v4l2_async_notifier *notifier)
|
||||
{
|
||||
struct v4l2_subdev *sd;
|
||||
struct rvin_dev *vin = notifier_to_vin(notifier);
|
||||
int ret;
|
||||
|
||||
sd = vin_to_source(vin);
|
||||
|
||||
ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev);
|
||||
if (ret < 0) {
|
||||
vin_err(vin, "Failed to register subdev nodes\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!rvin_mbus_supported(vin)) {
|
||||
vin_err(vin, "No supported mediabus format found\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return rvin_v4l2_probe(vin);
|
||||
}
|
||||
|
||||
static void rvin_graph_notify_unbind(struct v4l2_async_notifier *notifier,
|
||||
struct v4l2_subdev *sd,
|
||||
struct v4l2_async_subdev *asd)
|
||||
{
|
||||
struct rvin_dev *vin = notifier_to_vin(notifier);
|
||||
|
||||
rvin_v4l2_remove(vin);
|
||||
}
|
||||
|
||||
static int rvin_graph_notify_bound(struct v4l2_async_notifier *notifier,
|
||||
struct v4l2_subdev *subdev,
|
||||
struct v4l2_async_subdev *asd)
|
||||
{
|
||||
struct rvin_dev *vin = notifier_to_vin(notifier);
|
||||
|
||||
vin_dbg(vin, "subdev %s bound\n", subdev->name);
|
||||
|
||||
vin->entity.entity = &subdev->entity;
|
||||
vin->entity.subdev = subdev;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_graph_parse(struct rvin_dev *vin,
|
||||
struct device_node *node)
|
||||
{
|
||||
struct device_node *remote;
|
||||
struct device_node *ep = NULL;
|
||||
struct device_node *next;
|
||||
int ret = 0;
|
||||
|
||||
while (1) {
|
||||
next = of_graph_get_next_endpoint(node, ep);
|
||||
if (!next)
|
||||
break;
|
||||
|
||||
of_node_put(ep);
|
||||
ep = next;
|
||||
|
||||
remote = of_graph_get_remote_port_parent(ep);
|
||||
if (!remote) {
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Skip entities that we have already processed. */
|
||||
if (remote == vin->dev->of_node) {
|
||||
of_node_put(remote);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Remote node to connect */
|
||||
if (!vin->entity.node) {
|
||||
vin->entity.node = remote;
|
||||
vin->entity.asd.match_type = V4L2_ASYNC_MATCH_OF;
|
||||
vin->entity.asd.match.of.node = remote;
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
|
||||
of_node_put(ep);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rvin_graph_init(struct rvin_dev *vin)
|
||||
{
|
||||
struct v4l2_async_subdev **subdevs = NULL;
|
||||
int ret;
|
||||
|
||||
/* Parse the graph to extract a list of subdevice DT nodes. */
|
||||
ret = rvin_graph_parse(vin, vin->dev->of_node);
|
||||
if (ret < 0) {
|
||||
vin_err(vin, "Graph parsing failed\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
vin_err(vin, "No subdev found in graph\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ret != 1) {
|
||||
vin_err(vin, "More then one subdev found in graph\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Register the subdevices notifier. */
|
||||
subdevs = devm_kzalloc(vin->dev, sizeof(*subdevs), GFP_KERNEL);
|
||||
if (subdevs == NULL) {
|
||||
ret = -ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
subdevs[0] = &vin->entity.asd;
|
||||
|
||||
vin->notifier.subdevs = subdevs;
|
||||
vin->notifier.num_subdevs = 1;
|
||||
vin->notifier.bound = rvin_graph_notify_bound;
|
||||
vin->notifier.unbind = rvin_graph_notify_unbind;
|
||||
vin->notifier.complete = rvin_graph_notify_complete;
|
||||
|
||||
ret = v4l2_async_notifier_register(&vin->v4l2_dev, &vin->notifier);
|
||||
if (ret < 0) {
|
||||
vin_err(vin, "Notifier registration failed\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
done:
|
||||
if (ret < 0) {
|
||||
v4l2_async_notifier_unregister(&vin->notifier);
|
||||
of_node_put(vin->entity.node);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Platform Device Driver
|
||||
*/
|
||||
|
||||
static const struct of_device_id rvin_of_id_table[] = {
|
||||
{ .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 },
|
||||
{ .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 },
|
||||
{ .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
|
||||
{ .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
|
||||
{ .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
|
||||
{ .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, rvin_of_id_table);
|
||||
|
||||
static int rvin_parse_dt(struct rvin_dev *vin)
|
||||
{
|
||||
const struct of_device_id *match;
|
||||
struct v4l2_of_endpoint ep;
|
||||
struct device_node *np;
|
||||
int ret;
|
||||
|
||||
match = of_match_device(of_match_ptr(rvin_of_id_table), vin->dev);
|
||||
if (!match)
|
||||
return -ENODEV;
|
||||
|
||||
vin->chip = (enum chip_id)match->data;
|
||||
|
||||
np = of_graph_get_next_endpoint(vin->dev->of_node, NULL);
|
||||
if (!np) {
|
||||
vin_err(vin, "Could not find endpoint\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = v4l2_of_parse_endpoint(np, &ep);
|
||||
if (ret) {
|
||||
vin_err(vin, "Could not parse endpoint\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
of_node_put(np);
|
||||
|
||||
vin->mbus_cfg.type = ep.bus_type;
|
||||
|
||||
switch (vin->mbus_cfg.type) {
|
||||
case V4L2_MBUS_PARALLEL:
|
||||
vin->mbus_cfg.flags = ep.bus.parallel.flags;
|
||||
break;
|
||||
case V4L2_MBUS_BT656:
|
||||
vin->mbus_cfg.flags = 0;
|
||||
break;
|
||||
default:
|
||||
vin_err(vin, "Unknown media bus type\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rcar_vin_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct rvin_dev *vin;
|
||||
struct resource *mem;
|
||||
int irq, ret;
|
||||
|
||||
vin = devm_kzalloc(&pdev->dev, sizeof(*vin), GFP_KERNEL);
|
||||
if (!vin)
|
||||
return -ENOMEM;
|
||||
|
||||
vin->dev = &pdev->dev;
|
||||
|
||||
ret = rvin_parse_dt(vin);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
if (mem == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
vin->base = devm_ioremap_resource(vin->dev, mem);
|
||||
if (IS_ERR(vin->base))
|
||||
return PTR_ERR(vin->base);
|
||||
|
||||
irq = platform_get_irq(pdev, 0);
|
||||
if (irq <= 0)
|
||||
return ret;
|
||||
|
||||
ret = rvin_dma_probe(vin, irq);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = rvin_graph_init(vin);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
pm_suspend_ignore_children(&pdev->dev, true);
|
||||
pm_runtime_enable(&pdev->dev);
|
||||
|
||||
platform_set_drvdata(pdev, vin);
|
||||
|
||||
return 0;
|
||||
error:
|
||||
rvin_dma_remove(vin);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rcar_vin_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct rvin_dev *vin = platform_get_drvdata(pdev);
|
||||
|
||||
pm_runtime_disable(&pdev->dev);
|
||||
|
||||
v4l2_async_notifier_unregister(&vin->notifier);
|
||||
|
||||
rvin_dma_remove(vin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver rcar_vin_driver = {
|
||||
.driver = {
|
||||
.name = "rcar-vin",
|
||||
.of_match_table = rvin_of_id_table,
|
||||
},
|
||||
.probe = rcar_vin_probe,
|
||||
.remove = rcar_vin_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(rcar_vin_driver);
|
||||
|
||||
MODULE_AUTHOR("Niklas Söderlund <niklas.soderlund@ragnatech.se>");
|
||||
MODULE_DESCRIPTION("Renesas R-Car VIN camera host driver");
|
||||
MODULE_LICENSE("GPL v2");
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,768 @@
|
|||
/*
|
||||
* Driver for Renesas R-Car VIN
|
||||
*
|
||||
* Copyright (C) 2016 Renesas Electronics Corp.
|
||||
* Copyright (C) 2011-2013 Renesas Solutions Corp.
|
||||
* Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
|
||||
* Copyright (C) 2008 Magnus Damm
|
||||
*
|
||||
* Based on the soc-camera rcar_vin driver
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*/
|
||||
|
||||
#include <linux/pm_runtime.h>
|
||||
|
||||
#include <media/v4l2-event.h>
|
||||
#include <media/v4l2-ioctl.h>
|
||||
#include <media/v4l2-rect.h>
|
||||
|
||||
#include "rcar-vin.h"
|
||||
|
||||
#define RVIN_DEFAULT_FORMAT V4L2_PIX_FMT_YUYV
|
||||
#define RVIN_MAX_WIDTH 2048
|
||||
#define RVIN_MAX_HEIGHT 2048
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Format Conversions
|
||||
*/
|
||||
|
||||
static const struct rvin_video_format rvin_formats[] = {
|
||||
{
|
||||
.fourcc = V4L2_PIX_FMT_NV16,
|
||||
.bpp = 1,
|
||||
},
|
||||
{
|
||||
.fourcc = V4L2_PIX_FMT_YUYV,
|
||||
.bpp = 2,
|
||||
},
|
||||
{
|
||||
.fourcc = V4L2_PIX_FMT_UYVY,
|
||||
.bpp = 2,
|
||||
},
|
||||
{
|
||||
.fourcc = V4L2_PIX_FMT_RGB565,
|
||||
.bpp = 2,
|
||||
},
|
||||
{
|
||||
.fourcc = V4L2_PIX_FMT_XRGB555,
|
||||
.bpp = 2,
|
||||
},
|
||||
{
|
||||
.fourcc = V4L2_PIX_FMT_XBGR32,
|
||||
.bpp = 4,
|
||||
},
|
||||
};
|
||||
|
||||
const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(rvin_formats); i++)
|
||||
if (rvin_formats[i].fourcc == pixelformat)
|
||||
return rvin_formats + i;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static u32 rvin_format_bytesperline(struct v4l2_pix_format *pix)
|
||||
{
|
||||
const struct rvin_video_format *fmt;
|
||||
|
||||
fmt = rvin_format_from_pixel(pix->pixelformat);
|
||||
|
||||
if (WARN_ON(!fmt))
|
||||
return -EINVAL;
|
||||
|
||||
return pix->width * fmt->bpp;
|
||||
}
|
||||
|
||||
static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
|
||||
{
|
||||
if (pix->pixelformat == V4L2_PIX_FMT_NV16)
|
||||
return pix->bytesperline * pix->height * 2;
|
||||
|
||||
return pix->bytesperline * pix->height;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* V4L2
|
||||
*/
|
||||
|
||||
static int __rvin_try_format_source(struct rvin_dev *vin,
|
||||
u32 which,
|
||||
struct v4l2_pix_format *pix,
|
||||
struct rvin_source_fmt *source)
|
||||
{
|
||||
struct v4l2_subdev *sd;
|
||||
struct v4l2_subdev_pad_config pad_cfg;
|
||||
struct v4l2_subdev_format format = {
|
||||
.which = which,
|
||||
};
|
||||
int ret;
|
||||
|
||||
sd = vin_to_source(vin);
|
||||
|
||||
v4l2_fill_mbus_format(&format.format, pix, vin->source.code);
|
||||
|
||||
ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, pad, set_fmt,
|
||||
&pad_cfg, &format);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
v4l2_fill_pix_format(pix, &format.format);
|
||||
|
||||
source->width = pix->width;
|
||||
source->height = pix->height;
|
||||
|
||||
vin_dbg(vin, "Source resolution: %ux%u\n", source->width,
|
||||
source->height);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __rvin_try_format(struct rvin_dev *vin,
|
||||
u32 which,
|
||||
struct v4l2_pix_format *pix,
|
||||
struct rvin_source_fmt *source)
|
||||
{
|
||||
const struct rvin_video_format *info;
|
||||
u32 rwidth, rheight, walign;
|
||||
|
||||
/* Requested */
|
||||
rwidth = pix->width;
|
||||
rheight = pix->height;
|
||||
|
||||
/*
|
||||
* Retrieve format information and select the current format if the
|
||||
* requested format isn't supported.
|
||||
*/
|
||||
info = rvin_format_from_pixel(pix->pixelformat);
|
||||
if (!info) {
|
||||
vin_dbg(vin, "Format %x not found, keeping %x\n",
|
||||
pix->pixelformat, vin->format.pixelformat);
|
||||
*pix = vin->format;
|
||||
pix->width = rwidth;
|
||||
pix->height = rheight;
|
||||
}
|
||||
|
||||
/* Always recalculate */
|
||||
pix->bytesperline = 0;
|
||||
pix->sizeimage = 0;
|
||||
|
||||
/* Limit to source capabilities */
|
||||
__rvin_try_format_source(vin, which, pix, source);
|
||||
|
||||
/* If source can't match format try if VIN can scale */
|
||||
if (source->width != rwidth || source->height != rheight)
|
||||
rvin_scale_try(vin, pix, rwidth, rheight);
|
||||
|
||||
/* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
|
||||
walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
|
||||
|
||||
/* Limit to VIN capabilities */
|
||||
v4l_bound_align_image(&pix->width, 2, RVIN_MAX_WIDTH, walign,
|
||||
&pix->height, 4, RVIN_MAX_HEIGHT, 2, 0);
|
||||
|
||||
switch (pix->field) {
|
||||
case V4L2_FIELD_NONE:
|
||||
case V4L2_FIELD_TOP:
|
||||
case V4L2_FIELD_BOTTOM:
|
||||
case V4L2_FIELD_INTERLACED_TB:
|
||||
case V4L2_FIELD_INTERLACED_BT:
|
||||
case V4L2_FIELD_INTERLACED:
|
||||
break;
|
||||
default:
|
||||
pix->field = V4L2_FIELD_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
pix->bytesperline = max_t(u32, pix->bytesperline,
|
||||
rvin_format_bytesperline(pix));
|
||||
pix->sizeimage = max_t(u32, pix->sizeimage,
|
||||
rvin_format_sizeimage(pix));
|
||||
|
||||
vin_dbg(vin, "Requested %ux%u Got %ux%u bpl: %d size: %d\n",
|
||||
rwidth, rheight, pix->width, pix->height,
|
||||
pix->bytesperline, pix->sizeimage);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_querycap(struct file *file, void *priv,
|
||||
struct v4l2_capability *cap)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
|
||||
strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
|
||||
strlcpy(cap->card, "R_Car_VIN", sizeof(cap->card));
|
||||
snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
|
||||
dev_name(vin->dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_try_fmt_vid_cap(struct file *file, void *priv,
|
||||
struct v4l2_format *f)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
struct rvin_source_fmt source;
|
||||
|
||||
return __rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, &f->fmt.pix,
|
||||
&source);
|
||||
}
|
||||
|
||||
static int rvin_s_fmt_vid_cap(struct file *file, void *priv,
|
||||
struct v4l2_format *f)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
struct rvin_source_fmt source;
|
||||
int ret;
|
||||
|
||||
if (vb2_is_busy(&vin->queue))
|
||||
return -EBUSY;
|
||||
|
||||
ret = __rvin_try_format(vin, V4L2_SUBDEV_FORMAT_ACTIVE, &f->fmt.pix,
|
||||
&source);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
vin->source.width = source.width;
|
||||
vin->source.height = source.height;
|
||||
|
||||
vin->format = f->fmt.pix;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_g_fmt_vid_cap(struct file *file, void *priv,
|
||||
struct v4l2_format *f)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
|
||||
f->fmt.pix = vin->format;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_enum_fmt_vid_cap(struct file *file, void *priv,
|
||||
struct v4l2_fmtdesc *f)
|
||||
{
|
||||
if (f->index >= ARRAY_SIZE(rvin_formats))
|
||||
return -EINVAL;
|
||||
|
||||
f->pixelformat = rvin_formats[f->index].fourcc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_g_selection(struct file *file, void *fh,
|
||||
struct v4l2_selection *s)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
|
||||
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
||||
return -EINVAL;
|
||||
|
||||
switch (s->target) {
|
||||
case V4L2_SEL_TGT_CROP_BOUNDS:
|
||||
case V4L2_SEL_TGT_CROP_DEFAULT:
|
||||
s->r.left = s->r.top = 0;
|
||||
s->r.width = vin->source.width;
|
||||
s->r.height = vin->source.height;
|
||||
break;
|
||||
case V4L2_SEL_TGT_CROP:
|
||||
s->r = vin->crop;
|
||||
break;
|
||||
case V4L2_SEL_TGT_COMPOSE_BOUNDS:
|
||||
case V4L2_SEL_TGT_COMPOSE_DEFAULT:
|
||||
s->r.left = s->r.top = 0;
|
||||
s->r.width = vin->format.width;
|
||||
s->r.height = vin->format.height;
|
||||
break;
|
||||
case V4L2_SEL_TGT_COMPOSE:
|
||||
s->r = vin->compose;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_s_selection(struct file *file, void *fh,
|
||||
struct v4l2_selection *s)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
const struct rvin_video_format *fmt;
|
||||
struct v4l2_rect r = s->r;
|
||||
struct v4l2_rect max_rect;
|
||||
struct v4l2_rect min_rect = {
|
||||
.width = 6,
|
||||
.height = 2,
|
||||
};
|
||||
|
||||
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
||||
return -EINVAL;
|
||||
|
||||
v4l2_rect_set_min_size(&r, &min_rect);
|
||||
|
||||
switch (s->target) {
|
||||
case V4L2_SEL_TGT_CROP:
|
||||
/* Can't crop outside of source input */
|
||||
max_rect.top = max_rect.left = 0;
|
||||
max_rect.width = vin->source.width;
|
||||
max_rect.height = vin->source.height;
|
||||
v4l2_rect_map_inside(&r, &max_rect);
|
||||
|
||||
v4l_bound_align_image(&r.width, 2, vin->source.width, 1,
|
||||
&r.height, 4, vin->source.height, 2, 0);
|
||||
|
||||
r.top = clamp_t(s32, r.top, 0, vin->source.height - r.height);
|
||||
r.left = clamp_t(s32, r.left, 0, vin->source.width - r.width);
|
||||
|
||||
vin->crop = s->r = r;
|
||||
|
||||
vin_dbg(vin, "Cropped %dx%d@%d:%d of %dx%d\n",
|
||||
r.width, r.height, r.left, r.top,
|
||||
vin->source.width, vin->source.height);
|
||||
break;
|
||||
case V4L2_SEL_TGT_COMPOSE:
|
||||
/* Make sure compose rect fits inside output format */
|
||||
max_rect.top = max_rect.left = 0;
|
||||
max_rect.width = vin->format.width;
|
||||
max_rect.height = vin->format.height;
|
||||
v4l2_rect_map_inside(&r, &max_rect);
|
||||
|
||||
/*
|
||||
* Composing is done by adding a offset to the buffer address,
|
||||
* the HW wants this address to be aligned to HW_BUFFER_MASK.
|
||||
* Make sure the top and left values meets this requirement.
|
||||
*/
|
||||
while ((r.top * vin->format.bytesperline) & HW_BUFFER_MASK)
|
||||
r.top--;
|
||||
|
||||
fmt = rvin_format_from_pixel(vin->format.pixelformat);
|
||||
while ((r.left * fmt->bpp) & HW_BUFFER_MASK)
|
||||
r.left--;
|
||||
|
||||
vin->compose = s->r = r;
|
||||
|
||||
vin_dbg(vin, "Compose %dx%d@%d:%d in %dx%d\n",
|
||||
r.width, r.height, r.left, r.top,
|
||||
vin->format.width, vin->format.height);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* HW supports modifying configuration while running */
|
||||
rvin_crop_scale_comp(vin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_cropcap(struct file *file, void *priv,
|
||||
struct v4l2_cropcap *crop)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
struct v4l2_subdev *sd = vin_to_source(vin);
|
||||
|
||||
if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
||||
return -EINVAL;
|
||||
|
||||
return v4l2_subdev_call(sd, video, cropcap, crop);
|
||||
}
|
||||
|
||||
static int rvin_enum_input(struct file *file, void *priv,
|
||||
struct v4l2_input *i)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
struct v4l2_subdev *sd = vin_to_source(vin);
|
||||
int ret;
|
||||
|
||||
if (i->index != 0)
|
||||
return -EINVAL;
|
||||
|
||||
ret = v4l2_subdev_call(sd, video, g_input_status, &i->status);
|
||||
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
|
||||
return ret;
|
||||
|
||||
i->type = V4L2_INPUT_TYPE_CAMERA;
|
||||
i->std = vin->vdev.tvnorms;
|
||||
strlcpy(i->name, "Camera", sizeof(i->name));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_g_input(struct file *file, void *priv, unsigned int *i)
|
||||
{
|
||||
*i = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_s_input(struct file *file, void *priv, unsigned int i)
|
||||
{
|
||||
if (i > 0)
|
||||
return -EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_querystd(struct file *file, void *priv, v4l2_std_id *a)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
struct v4l2_subdev *sd = vin_to_source(vin);
|
||||
|
||||
return v4l2_subdev_call(sd, video, querystd, a);
|
||||
}
|
||||
|
||||
static int rvin_s_std(struct file *file, void *priv, v4l2_std_id a)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
struct v4l2_subdev *sd = vin_to_source(vin);
|
||||
struct v4l2_subdev_format fmt = {
|
||||
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
|
||||
};
|
||||
struct v4l2_mbus_framefmt *mf = &fmt.format;
|
||||
int ret = v4l2_subdev_call(sd, video, s_std, a);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Changing the standard will change the width/height */
|
||||
ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
|
||||
if (ret) {
|
||||
vin_err(vin, "Failed to get initial format\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
vin->format.width = mf->width;
|
||||
vin->format.height = mf->height;
|
||||
|
||||
vin->crop.top = vin->crop.left = 0;
|
||||
vin->crop.width = mf->width;
|
||||
vin->crop.height = mf->height;
|
||||
|
||||
vin->compose.top = vin->compose.left = 0;
|
||||
vin->compose.width = mf->width;
|
||||
vin->compose.height = mf->height;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_g_std(struct file *file, void *priv, v4l2_std_id *a)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
struct v4l2_subdev *sd = vin_to_source(vin);
|
||||
|
||||
return v4l2_subdev_call(sd, video, g_std, a);
|
||||
}
|
||||
|
||||
static int rvin_subscribe_event(struct v4l2_fh *fh,
|
||||
const struct v4l2_event_subscription *sub)
|
||||
{
|
||||
switch (sub->type) {
|
||||
case V4L2_EVENT_SOURCE_CHANGE:
|
||||
return v4l2_event_subscribe(fh, sub, 4, NULL);
|
||||
}
|
||||
return v4l2_ctrl_subscribe_event(fh, sub);
|
||||
}
|
||||
|
||||
static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
|
||||
.vidioc_querycap = rvin_querycap,
|
||||
.vidioc_try_fmt_vid_cap = rvin_try_fmt_vid_cap,
|
||||
.vidioc_g_fmt_vid_cap = rvin_g_fmt_vid_cap,
|
||||
.vidioc_s_fmt_vid_cap = rvin_s_fmt_vid_cap,
|
||||
.vidioc_enum_fmt_vid_cap = rvin_enum_fmt_vid_cap,
|
||||
|
||||
.vidioc_g_selection = rvin_g_selection,
|
||||
.vidioc_s_selection = rvin_s_selection,
|
||||
|
||||
.vidioc_cropcap = rvin_cropcap,
|
||||
|
||||
.vidioc_enum_input = rvin_enum_input,
|
||||
.vidioc_g_input = rvin_g_input,
|
||||
.vidioc_s_input = rvin_s_input,
|
||||
|
||||
.vidioc_querystd = rvin_querystd,
|
||||
.vidioc_g_std = rvin_g_std,
|
||||
.vidioc_s_std = rvin_s_std,
|
||||
|
||||
.vidioc_reqbufs = vb2_ioctl_reqbufs,
|
||||
.vidioc_create_bufs = vb2_ioctl_create_bufs,
|
||||
.vidioc_querybuf = vb2_ioctl_querybuf,
|
||||
.vidioc_qbuf = vb2_ioctl_qbuf,
|
||||
.vidioc_dqbuf = vb2_ioctl_dqbuf,
|
||||
.vidioc_expbuf = vb2_ioctl_expbuf,
|
||||
.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
|
||||
.vidioc_streamon = vb2_ioctl_streamon,
|
||||
.vidioc_streamoff = vb2_ioctl_streamoff,
|
||||
|
||||
.vidioc_log_status = v4l2_ctrl_log_status,
|
||||
.vidioc_subscribe_event = rvin_subscribe_event,
|
||||
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* File Operations
|
||||
*/
|
||||
|
||||
static int rvin_power_on(struct rvin_dev *vin)
|
||||
{
|
||||
int ret;
|
||||
struct v4l2_subdev *sd = vin_to_source(vin);
|
||||
|
||||
pm_runtime_get_sync(vin->v4l2_dev.dev);
|
||||
|
||||
ret = v4l2_subdev_call(sd, core, s_power, 1);
|
||||
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_power_off(struct rvin_dev *vin)
|
||||
{
|
||||
int ret;
|
||||
struct v4l2_subdev *sd = vin_to_source(vin);
|
||||
|
||||
ret = v4l2_subdev_call(sd, core, s_power, 0);
|
||||
|
||||
pm_runtime_put(vin->v4l2_dev.dev);
|
||||
|
||||
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rvin_initialize_device(struct file *file)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
int ret;
|
||||
|
||||
struct v4l2_format f = {
|
||||
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
||||
.fmt.pix = {
|
||||
.width = vin->format.width,
|
||||
.height = vin->format.height,
|
||||
.field = vin->format.field,
|
||||
.colorspace = vin->format.colorspace,
|
||||
.pixelformat = vin->format.pixelformat,
|
||||
},
|
||||
};
|
||||
|
||||
ret = rvin_power_on(vin);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
pm_runtime_enable(&vin->vdev.dev);
|
||||
ret = pm_runtime_resume(&vin->vdev.dev);
|
||||
if (ret < 0 && ret != -ENOSYS)
|
||||
goto eresume;
|
||||
|
||||
/*
|
||||
* Try to configure with default parameters. Notice: this is the
|
||||
* very first open, so, we cannot race against other calls,
|
||||
* apart from someone else calling open() simultaneously, but
|
||||
* .host_lock is protecting us against it.
|
||||
*/
|
||||
ret = rvin_s_fmt_vid_cap(file, NULL, &f);
|
||||
if (ret < 0)
|
||||
goto esfmt;
|
||||
|
||||
v4l2_ctrl_handler_setup(&vin->ctrl_handler);
|
||||
|
||||
return 0;
|
||||
esfmt:
|
||||
pm_runtime_disable(&vin->vdev.dev);
|
||||
eresume:
|
||||
rvin_power_off(vin);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rvin_open(struct file *file)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
int ret;
|
||||
|
||||
mutex_lock(&vin->lock);
|
||||
|
||||
file->private_data = vin;
|
||||
|
||||
ret = v4l2_fh_open(file);
|
||||
if (ret)
|
||||
goto unlock;
|
||||
|
||||
if (!v4l2_fh_is_singular_file(file))
|
||||
goto unlock;
|
||||
|
||||
if (rvin_initialize_device(file)) {
|
||||
v4l2_fh_release(file);
|
||||
ret = -ENODEV;
|
||||
}
|
||||
|
||||
unlock:
|
||||
mutex_unlock(&vin->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rvin_release(struct file *file)
|
||||
{
|
||||
struct rvin_dev *vin = video_drvdata(file);
|
||||
bool fh_singular;
|
||||
int ret;
|
||||
|
||||
mutex_lock(&vin->lock);
|
||||
|
||||
/* Save the singular status before we call the clean-up helper */
|
||||
fh_singular = v4l2_fh_is_singular_file(file);
|
||||
|
||||
/* the release helper will cleanup any on-going streaming */
|
||||
ret = _vb2_fop_release(file, NULL);
|
||||
|
||||
/*
|
||||
* If this was the last open file.
|
||||
* Then de-initialize hw module.
|
||||
*/
|
||||
if (fh_singular) {
|
||||
pm_runtime_suspend(&vin->vdev.dev);
|
||||
pm_runtime_disable(&vin->vdev.dev);
|
||||
rvin_power_off(vin);
|
||||
}
|
||||
|
||||
mutex_unlock(&vin->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct v4l2_file_operations rvin_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.unlocked_ioctl = video_ioctl2,
|
||||
.open = rvin_open,
|
||||
.release = rvin_release,
|
||||
.poll = vb2_fop_poll,
|
||||
.mmap = vb2_fop_mmap,
|
||||
.read = vb2_fop_read,
|
||||
};
|
||||
|
||||
void rvin_v4l2_remove(struct rvin_dev *vin)
|
||||
{
|
||||
v4l2_info(&vin->v4l2_dev, "Removing %s\n",
|
||||
video_device_node_name(&vin->vdev));
|
||||
|
||||
/* Checks internaly if handlers have been init or not */
|
||||
v4l2_ctrl_handler_free(&vin->ctrl_handler);
|
||||
|
||||
/* Checks internaly if vdev have been init or not */
|
||||
video_unregister_device(&vin->vdev);
|
||||
}
|
||||
|
||||
static void rvin_notify(struct v4l2_subdev *sd,
|
||||
unsigned int notification, void *arg)
|
||||
{
|
||||
struct rvin_dev *vin =
|
||||
container_of(sd->v4l2_dev, struct rvin_dev, v4l2_dev);
|
||||
|
||||
switch (notification) {
|
||||
case V4L2_DEVICE_NOTIFY_EVENT:
|
||||
v4l2_event_queue(&vin->vdev, arg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int rvin_v4l2_probe(struct rvin_dev *vin)
|
||||
{
|
||||
struct v4l2_subdev_format fmt = {
|
||||
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
|
||||
};
|
||||
struct v4l2_mbus_framefmt *mf = &fmt.format;
|
||||
struct video_device *vdev = &vin->vdev;
|
||||
struct v4l2_subdev *sd = vin_to_source(vin);
|
||||
int ret;
|
||||
|
||||
v4l2_set_subdev_hostdata(sd, vin);
|
||||
|
||||
vin->v4l2_dev.notify = rvin_notify;
|
||||
|
||||
ret = v4l2_subdev_call(sd, video, g_tvnorms, &vin->vdev.tvnorms);
|
||||
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
|
||||
return ret;
|
||||
|
||||
if (vin->vdev.tvnorms == 0) {
|
||||
/* Disable the STD API if there are no tvnorms defined */
|
||||
v4l2_disable_ioctl(&vin->vdev, VIDIOC_G_STD);
|
||||
v4l2_disable_ioctl(&vin->vdev, VIDIOC_S_STD);
|
||||
v4l2_disable_ioctl(&vin->vdev, VIDIOC_QUERYSTD);
|
||||
v4l2_disable_ioctl(&vin->vdev, VIDIOC_ENUMSTD);
|
||||
}
|
||||
|
||||
/* Add the controls */
|
||||
/*
|
||||
* Currently the subdev with the largest number of controls (13) is
|
||||
* ov6550. So let's pick 16 as a hint for the control handler. Note
|
||||
* that this is a hint only: too large and you waste some memory, too
|
||||
* small and there is a (very) small performance hit when looking up
|
||||
* controls in the internal hash.
|
||||
*/
|
||||
ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, sd->ctrl_handler, NULL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* video node */
|
||||
vdev->fops = &rvin_fops;
|
||||
vdev->v4l2_dev = &vin->v4l2_dev;
|
||||
vdev->queue = &vin->queue;
|
||||
strlcpy(vdev->name, KBUILD_MODNAME, sizeof(vdev->name));
|
||||
vdev->release = video_device_release_empty;
|
||||
vdev->ioctl_ops = &rvin_ioctl_ops;
|
||||
vdev->lock = &vin->lock;
|
||||
vdev->ctrl_handler = &vin->ctrl_handler;
|
||||
vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
|
||||
V4L2_CAP_READWRITE;
|
||||
|
||||
/* Try to improve our guess of a reasonable window format */
|
||||
ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
|
||||
if (ret) {
|
||||
vin_err(vin, "Failed to get initial format\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Set default format */
|
||||
vin->format.width = mf->width;
|
||||
vin->format.height = mf->height;
|
||||
vin->format.colorspace = mf->colorspace;
|
||||
vin->format.field = mf->field;
|
||||
vin->format.pixelformat = RVIN_DEFAULT_FORMAT;
|
||||
|
||||
|
||||
/* Set initial crop and compose */
|
||||
vin->crop.top = vin->crop.left = 0;
|
||||
vin->crop.width = mf->width;
|
||||
vin->crop.height = mf->height;
|
||||
|
||||
vin->compose.top = vin->compose.left = 0;
|
||||
vin->compose.width = mf->width;
|
||||
vin->compose.height = mf->height;
|
||||
|
||||
ret = video_register_device(&vin->vdev, VFL_TYPE_GRABBER, -1);
|
||||
if (ret) {
|
||||
vin_err(vin, "Failed to register video device\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
video_set_drvdata(&vin->vdev, vin);
|
||||
|
||||
v4l2_info(&vin->v4l2_dev, "Device registered as %s\n",
|
||||
video_device_node_name(&vin->vdev));
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* Driver for Renesas R-Car VIN
|
||||
*
|
||||
* Copyright (C) 2016 Renesas Electronics Corp.
|
||||
* Copyright (C) 2011-2013 Renesas Solutions Corp.
|
||||
* Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
|
||||
* Copyright (C) 2008 Magnus Damm
|
||||
*
|
||||
* Based on the soc-camera rcar_vin driver
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef __RCAR_VIN__
|
||||
#define __RCAR_VIN__
|
||||
|
||||
#include <media/v4l2-async.h>
|
||||
#include <media/v4l2-ctrls.h>
|
||||
#include <media/v4l2-dev.h>
|
||||
#include <media/v4l2-device.h>
|
||||
#include <media/videobuf2-v4l2.h>
|
||||
|
||||
/* Number of HW buffers */
|
||||
#define HW_BUFFER_NUM 3
|
||||
|
||||
/* Address alignment mask for HW buffers */
|
||||
#define HW_BUFFER_MASK 0x7f
|
||||
|
||||
enum chip_id {
|
||||
RCAR_GEN2,
|
||||
RCAR_H1,
|
||||
RCAR_M1,
|
||||
};
|
||||
|
||||
/**
|
||||
* STOPPED - No operation in progress
|
||||
* RUNNING - Operation in progress have buffers
|
||||
* STALLED - No operation in progress have no buffers
|
||||
* STOPPING - Stopping operation
|
||||
*/
|
||||
enum rvin_dma_state {
|
||||
STOPPED = 0,
|
||||
RUNNING,
|
||||
STALLED,
|
||||
STOPPING,
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rvin_source_fmt - Source information
|
||||
* @code: Media bus format from source
|
||||
* @width: Width from source
|
||||
* @height: Height from source
|
||||
*/
|
||||
struct rvin_source_fmt {
|
||||
u32 code;
|
||||
u32 width;
|
||||
u32 height;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rvin_video_format - Data format stored in memory
|
||||
* @fourcc: Pixelformat
|
||||
* @bpp: Bytes per pixel
|
||||
*/
|
||||
struct rvin_video_format {
|
||||
u32 fourcc;
|
||||
u8 bpp;
|
||||
};
|
||||
|
||||
struct rvin_graph_entity {
|
||||
struct device_node *node;
|
||||
struct media_entity *entity;
|
||||
|
||||
struct v4l2_async_subdev asd;
|
||||
struct v4l2_subdev *subdev;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct rvin_dev - Renesas VIN device structure
|
||||
* @dev: (OF) device
|
||||
* @base: device I/O register space remapped to virtual memory
|
||||
* @chip: type of VIN chip
|
||||
* @mbus_cfg media bus configuration
|
||||
*
|
||||
* @vdev: V4L2 video device associated with VIN
|
||||
* @v4l2_dev: V4L2 device
|
||||
* @ctrl_handler: V4L2 control handler
|
||||
* @notifier: V4L2 asynchronous subdevs notifier
|
||||
* @entity: entity in the DT for subdevice
|
||||
*
|
||||
* @lock: protects @queue
|
||||
* @queue: vb2 buffers queue
|
||||
* @alloc_ctx: allocation context for the vb2 @queue
|
||||
*
|
||||
* @qlock: protects @queue_buf, @buf_list, @continuous, @sequence
|
||||
* @state
|
||||
* @queue_buf: Keeps track of buffers given to HW slot
|
||||
* @buf_list: list of queued buffers
|
||||
* @continuous: tracks if active operation is continuous or single mode
|
||||
* @sequence: V4L2 buffers sequence number
|
||||
* @state: keeps track of operation state
|
||||
*
|
||||
* @source: active format from the video source
|
||||
* @format: active V4L2 pixel format
|
||||
*
|
||||
* @crop: active cropping
|
||||
* @compose: active composing
|
||||
*/
|
||||
struct rvin_dev {
|
||||
struct device *dev;
|
||||
void __iomem *base;
|
||||
enum chip_id chip;
|
||||
struct v4l2_mbus_config mbus_cfg;
|
||||
|
||||
struct video_device vdev;
|
||||
struct v4l2_device v4l2_dev;
|
||||
struct v4l2_ctrl_handler ctrl_handler;
|
||||
struct v4l2_async_notifier notifier;
|
||||
struct rvin_graph_entity entity;
|
||||
|
||||
struct mutex lock;
|
||||
struct vb2_queue queue;
|
||||
struct vb2_alloc_ctx *alloc_ctx;
|
||||
|
||||
spinlock_t qlock;
|
||||
struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];
|
||||
struct list_head buf_list;
|
||||
bool continuous;
|
||||
unsigned int sequence;
|
||||
enum rvin_dma_state state;
|
||||
|
||||
struct rvin_source_fmt source;
|
||||
struct v4l2_pix_format format;
|
||||
|
||||
struct v4l2_rect crop;
|
||||
struct v4l2_rect compose;
|
||||
};
|
||||
|
||||
#define vin_to_source(vin) vin->entity.subdev
|
||||
|
||||
/* Debug */
|
||||
#define vin_dbg(d, fmt, arg...) dev_dbg(d->dev, fmt, ##arg)
|
||||
#define vin_info(d, fmt, arg...) dev_info(d->dev, fmt, ##arg)
|
||||
#define vin_warn(d, fmt, arg...) dev_warn(d->dev, fmt, ##arg)
|
||||
#define vin_err(d, fmt, arg...) dev_err(d->dev, fmt, ##arg)
|
||||
|
||||
int rvin_dma_probe(struct rvin_dev *vin, int irq);
|
||||
void rvin_dma_remove(struct rvin_dev *vin);
|
||||
|
||||
int rvin_v4l2_probe(struct rvin_dev *vin);
|
||||
void rvin_v4l2_remove(struct rvin_dev *vin);
|
||||
|
||||
const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat);
|
||||
|
||||
/* Cropping, composing and scaling */
|
||||
void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
|
||||
u32 width, u32 height);
|
||||
void rvin_crop_scale_comp(struct rvin_dev *vin);
|
||||
|
||||
#endif
|
|
@ -25,8 +25,8 @@ config VIDEO_PXA27x
|
|||
---help---
|
||||
This is a v4l2 driver for the PXA27x Quick Capture Interface
|
||||
|
||||
config VIDEO_RCAR_VIN
|
||||
tristate "R-Car Video Input (VIN) support"
|
||||
config VIDEO_RCAR_VIN_OLD
|
||||
tristate "R-Car Video Input (VIN) support (DEPRECATED)"
|
||||
depends on VIDEO_DEV && SOC_CAMERA
|
||||
depends on ARCH_RENESAS || COMPILE_TEST
|
||||
depends on HAS_DMA
|
||||
|
|
|
@ -10,4 +10,4 @@ obj-$(CONFIG_VIDEO_ATMEL_ISI) += atmel-isi.o
|
|||
obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
|
||||
obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
|
||||
obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o
|
||||
obj-$(CONFIG_VIDEO_RCAR_VIN) += rcar_vin.o
|
||||
obj-$(CONFIG_VIDEO_RCAR_VIN_OLD) += rcar_vin.o
|
||||
|
|
Loading…
Reference in New Issue