mirror of
https://github.com/ukui/kernel.git
synced 2026-03-09 10:07:04 -07:00
[media] media: Add i.MX media core driver
Add the core media driver for i.MX SOC. Switch from the v4l2_of_ APIs to the v4l2_fwnode_ APIs. Add the bayer formats to imx-media's list of supported pixel and bus formats. Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
committed by
Mauro Carvalho Chehab
parent
a2bce3794a
commit
e130291212
614
Documentation/media/v4l-drivers/imx.rst
Normal file
614
Documentation/media/v4l-drivers/imx.rst
Normal file
File diff suppressed because it is too large
Load Diff
@@ -27,6 +27,8 @@ source "drivers/staging/media/cxd2099/Kconfig"
|
||||
|
||||
source "drivers/staging/media/davinci_vpfe/Kconfig"
|
||||
|
||||
source "drivers/staging/media/imx/Kconfig"
|
||||
|
||||
source "drivers/staging/media/omap4iss/Kconfig"
|
||||
|
||||
# Keep LIRC at the end, as it has sub-menus
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
obj-$(CONFIG_I2C_BCM2048) += bcm2048/
|
||||
obj-$(CONFIG_DVB_CXD2099) += cxd2099/
|
||||
obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx/
|
||||
obj-$(CONFIG_LIRC_STAGING) += lirc/
|
||||
obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/
|
||||
obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/
|
||||
|
||||
7
drivers/staging/media/imx/Kconfig
Normal file
7
drivers/staging/media/imx/Kconfig
Normal file
@@ -0,0 +1,7 @@
|
||||
config VIDEO_IMX_MEDIA
|
||||
tristate "i.MX5/6 V4L2 media core driver"
|
||||
depends on MEDIA_CONTROLLER && VIDEO_V4L2 && ARCH_MXC && IMX_IPUV3_CORE
|
||||
select V4L2_FWNODE
|
||||
---help---
|
||||
Say yes here to enable support for video4linux media controller
|
||||
driver for the i.MX5/6 SOC.
|
||||
5
drivers/staging/media/imx/Makefile
Normal file
5
drivers/staging/media/imx/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
imx-media-objs := imx-media-dev.o imx-media-internal-sd.o imx-media-of.o
|
||||
imx-media-common-objs := imx-media-utils.o imx-media-fim.o
|
||||
|
||||
obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
|
||||
obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
|
||||
667
drivers/staging/media/imx/imx-media-dev.c
Normal file
667
drivers/staging/media/imx/imx-media-dev.c
Normal file
File diff suppressed because it is too large
Load Diff
494
drivers/staging/media/imx/imx-media-fim.c
Normal file
494
drivers/staging/media/imx/imx-media-fim.c
Normal file
@@ -0,0 +1,494 @@
|
||||
/*
|
||||
* Frame Interval Monitor.
|
||||
*
|
||||
* Copyright (c) 2016 Mentor Graphics Inc.
|
||||
*
|
||||
* 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/delay.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <media/v4l2-ctrls.h>
|
||||
#include <media/v4l2-subdev.h>
|
||||
#include <media/imx.h>
|
||||
#include "imx-media.h"
|
||||
|
||||
enum {
|
||||
FIM_CL_ENABLE = 0,
|
||||
FIM_CL_NUM,
|
||||
FIM_CL_TOLERANCE_MIN,
|
||||
FIM_CL_TOLERANCE_MAX,
|
||||
FIM_CL_NUM_SKIP,
|
||||
FIM_NUM_CONTROLS,
|
||||
};
|
||||
|
||||
enum {
|
||||
FIM_CL_ICAP_EDGE = 0,
|
||||
FIM_CL_ICAP_CHANNEL,
|
||||
FIM_NUM_ICAP_CONTROLS,
|
||||
};
|
||||
|
||||
#define FIM_CL_ENABLE_DEF 0 /* FIM disabled by default */
|
||||
#define FIM_CL_NUM_DEF 8 /* average 8 frames */
|
||||
#define FIM_CL_NUM_SKIP_DEF 2 /* skip 2 frames after restart */
|
||||
#define FIM_CL_TOLERANCE_MIN_DEF 50 /* usec */
|
||||
#define FIM_CL_TOLERANCE_MAX_DEF 0 /* no max tolerance (unbounded) */
|
||||
|
||||
struct imx_media_fim {
|
||||
struct imx_media_dev *md;
|
||||
|
||||
/* the owning subdev of this fim instance */
|
||||
struct v4l2_subdev *sd;
|
||||
|
||||
/* FIM's control handler */
|
||||
struct v4l2_ctrl_handler ctrl_handler;
|
||||
|
||||
/* control clusters */
|
||||
struct v4l2_ctrl *ctrl[FIM_NUM_CONTROLS];
|
||||
struct v4l2_ctrl *icap_ctrl[FIM_NUM_ICAP_CONTROLS];
|
||||
|
||||
spinlock_t lock; /* protect control values */
|
||||
|
||||
/* current control values */
|
||||
bool enabled;
|
||||
int num_avg;
|
||||
int num_skip;
|
||||
unsigned long tolerance_min; /* usec */
|
||||
unsigned long tolerance_max; /* usec */
|
||||
/* input capture method of measuring FI */
|
||||
int icap_channel;
|
||||
int icap_flags;
|
||||
|
||||
int counter;
|
||||
struct timespec last_ts;
|
||||
unsigned long sum; /* usec */
|
||||
unsigned long nominal; /* usec */
|
||||
|
||||
struct completion icap_first_event;
|
||||
bool stream_on;
|
||||
};
|
||||
|
||||
#define icap_enabled(fim) ((fim)->icap_flags != IRQ_TYPE_NONE)
|
||||
|
||||
static void update_fim_nominal(struct imx_media_fim *fim,
|
||||
const struct v4l2_fract *fi)
|
||||
{
|
||||
if (fi->denominator == 0) {
|
||||
dev_dbg(fim->sd->dev, "no frame interval, FIM disabled\n");
|
||||
fim->enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
fim->nominal = DIV_ROUND_CLOSEST_ULL(1000000ULL * (u64)fi->numerator,
|
||||
fi->denominator);
|
||||
|
||||
dev_dbg(fim->sd->dev, "FI=%lu usec\n", fim->nominal);
|
||||
}
|
||||
|
||||
static void reset_fim(struct imx_media_fim *fim, bool curval)
|
||||
{
|
||||
struct v4l2_ctrl *icap_chan = fim->icap_ctrl[FIM_CL_ICAP_CHANNEL];
|
||||
struct v4l2_ctrl *icap_edge = fim->icap_ctrl[FIM_CL_ICAP_EDGE];
|
||||
struct v4l2_ctrl *en = fim->ctrl[FIM_CL_ENABLE];
|
||||
struct v4l2_ctrl *num = fim->ctrl[FIM_CL_NUM];
|
||||
struct v4l2_ctrl *skip = fim->ctrl[FIM_CL_NUM_SKIP];
|
||||
struct v4l2_ctrl *tol_min = fim->ctrl[FIM_CL_TOLERANCE_MIN];
|
||||
struct v4l2_ctrl *tol_max = fim->ctrl[FIM_CL_TOLERANCE_MAX];
|
||||
|
||||
if (curval) {
|
||||
fim->enabled = en->cur.val;
|
||||
fim->icap_flags = icap_edge->cur.val;
|
||||
fim->icap_channel = icap_chan->cur.val;
|
||||
fim->num_avg = num->cur.val;
|
||||
fim->num_skip = skip->cur.val;
|
||||
fim->tolerance_min = tol_min->cur.val;
|
||||
fim->tolerance_max = tol_max->cur.val;
|
||||
} else {
|
||||
fim->enabled = en->val;
|
||||
fim->icap_flags = icap_edge->val;
|
||||
fim->icap_channel = icap_chan->val;
|
||||
fim->num_avg = num->val;
|
||||
fim->num_skip = skip->val;
|
||||
fim->tolerance_min = tol_min->val;
|
||||
fim->tolerance_max = tol_max->val;
|
||||
}
|
||||
|
||||
/* disable tolerance range if max <= min */
|
||||
if (fim->tolerance_max <= fim->tolerance_min)
|
||||
fim->tolerance_max = 0;
|
||||
|
||||
/* num_skip must be >= 1 if input capture not used */
|
||||
if (!icap_enabled(fim))
|
||||
fim->num_skip = max_t(int, fim->num_skip, 1);
|
||||
|
||||
fim->counter = -fim->num_skip;
|
||||
fim->sum = 0;
|
||||
}
|
||||
|
||||
static void send_fim_event(struct imx_media_fim *fim, unsigned long error)
|
||||
{
|
||||
static const struct v4l2_event ev = {
|
||||
.type = V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR,
|
||||
};
|
||||
|
||||
v4l2_subdev_notify_event(fim->sd, &ev);
|
||||
}
|
||||
|
||||
/*
|
||||
* Monitor an averaged frame interval. If the average deviates too much
|
||||
* from the nominal frame rate, send the frame interval error event. The
|
||||
* frame intervals are averaged in order to quiet noise from
|
||||
* (presumably random) interrupt latency.
|
||||
*/
|
||||
static void frame_interval_monitor(struct imx_media_fim *fim,
|
||||
struct timespec *ts)
|
||||
{
|
||||
unsigned long interval, error, error_avg;
|
||||
bool send_event = false;
|
||||
struct timespec diff;
|
||||
|
||||
if (!fim->enabled || ++fim->counter <= 0)
|
||||
goto out_update_ts;
|
||||
|
||||
diff = timespec_sub(*ts, fim->last_ts);
|
||||
interval = diff.tv_sec * 1000 * 1000 + diff.tv_nsec / 1000;
|
||||
error = abs(interval - fim->nominal);
|
||||
|
||||
if (fim->tolerance_max && error >= fim->tolerance_max) {
|
||||
dev_dbg(fim->sd->dev,
|
||||
"FIM: %lu ignored, out of tolerance bounds\n",
|
||||
error);
|
||||
fim->counter--;
|
||||
goto out_update_ts;
|
||||
}
|
||||
|
||||
fim->sum += error;
|
||||
|
||||
if (fim->counter == fim->num_avg) {
|
||||
error_avg = DIV_ROUND_CLOSEST(fim->sum, fim->num_avg);
|
||||
|
||||
if (error_avg > fim->tolerance_min)
|
||||
send_event = true;
|
||||
|
||||
dev_dbg(fim->sd->dev, "FIM: error: %lu usec%s\n",
|
||||
error_avg, send_event ? " (!!!)" : "");
|
||||
|
||||
fim->counter = 0;
|
||||
fim->sum = 0;
|
||||
}
|
||||
|
||||
out_update_ts:
|
||||
fim->last_ts = *ts;
|
||||
if (send_event)
|
||||
send_fim_event(fim, error_avg);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IMX_GPT_ICAP
|
||||
/*
|
||||
* Input Capture method of measuring frame intervals. Not subject
|
||||
* to interrupt latency.
|
||||
*/
|
||||
static void fim_input_capture_handler(int channel, void *dev_id,
|
||||
struct timespec *ts)
|
||||
{
|
||||
struct imx_media_fim *fim = dev_id;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&fim->lock, flags);
|
||||
|
||||
frame_interval_monitor(fim, ts);
|
||||
|
||||
if (!completion_done(&fim->icap_first_event))
|
||||
complete(&fim->icap_first_event);
|
||||
|
||||
spin_unlock_irqrestore(&fim->lock, flags);
|
||||
}
|
||||
|
||||
static int fim_request_input_capture(struct imx_media_fim *fim)
|
||||
{
|
||||
init_completion(&fim->icap_first_event);
|
||||
|
||||
return mxc_request_input_capture(fim->icap_channel,
|
||||
fim_input_capture_handler,
|
||||
fim->icap_flags, fim);
|
||||
}
|
||||
|
||||
static void fim_free_input_capture(struct imx_media_fim *fim)
|
||||
{
|
||||
mxc_free_input_capture(fim->icap_channel, fim);
|
||||
}
|
||||
|
||||
#else /* CONFIG_IMX_GPT_ICAP */
|
||||
|
||||
static int fim_request_input_capture(struct imx_media_fim *fim)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fim_free_input_capture(struct imx_media_fim *fim)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* CONFIG_IMX_GPT_ICAP */
|
||||
|
||||
/*
|
||||
* In case we are monitoring the first frame interval after streamon
|
||||
* (when fim->num_skip = 0), we need a valid fim->last_ts before we
|
||||
* can begin. This only applies to the input capture method. It is not
|
||||
* possible to accurately measure the first FI after streamon using the
|
||||
* EOF method, so fim->num_skip minimum is set to 1 in that case, so this
|
||||
* function is a noop when the EOF method is used.
|
||||
*/
|
||||
static void fim_acquire_first_ts(struct imx_media_fim *fim)
|
||||
{
|
||||
unsigned long ret;
|
||||
|
||||
if (!fim->enabled || fim->num_skip > 0)
|
||||
return;
|
||||
|
||||
ret = wait_for_completion_timeout(
|
||||
&fim->icap_first_event,
|
||||
msecs_to_jiffies(IMX_MEDIA_EOF_TIMEOUT));
|
||||
if (ret == 0)
|
||||
v4l2_warn(fim->sd, "wait first icap event timeout\n");
|
||||
}
|
||||
|
||||
/* FIM Controls */
|
||||
static int fim_s_ctrl(struct v4l2_ctrl *ctrl)
|
||||
{
|
||||
struct imx_media_fim *fim = container_of(ctrl->handler,
|
||||
struct imx_media_fim,
|
||||
ctrl_handler);
|
||||
unsigned long flags;
|
||||
int ret = 0;
|
||||
|
||||
spin_lock_irqsave(&fim->lock, flags);
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_IMX_FIM_ENABLE:
|
||||
break;
|
||||
case V4L2_CID_IMX_FIM_ICAP_EDGE:
|
||||
if (fim->stream_on)
|
||||
ret = -EBUSY;
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
reset_fim(fim, false);
|
||||
|
||||
spin_unlock_irqrestore(&fim->lock, flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct v4l2_ctrl_ops fim_ctrl_ops = {
|
||||
.s_ctrl = fim_s_ctrl,
|
||||
};
|
||||
|
||||
static const struct v4l2_ctrl_config fim_ctrl[] = {
|
||||
[FIM_CL_ENABLE] = {
|
||||
.ops = &fim_ctrl_ops,
|
||||
.id = V4L2_CID_IMX_FIM_ENABLE,
|
||||
.name = "FIM Enable",
|
||||
.type = V4L2_CTRL_TYPE_BOOLEAN,
|
||||
.def = FIM_CL_ENABLE_DEF,
|
||||
.min = 0,
|
||||
.max = 1,
|
||||
.step = 1,
|
||||
},
|
||||
[FIM_CL_NUM] = {
|
||||
.ops = &fim_ctrl_ops,
|
||||
.id = V4L2_CID_IMX_FIM_NUM,
|
||||
.name = "FIM Num Average",
|
||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
||||
.def = FIM_CL_NUM_DEF,
|
||||
.min = 1, /* no averaging */
|
||||
.max = 64, /* average 64 frames */
|
||||
.step = 1,
|
||||
},
|
||||
[FIM_CL_TOLERANCE_MIN] = {
|
||||
.ops = &fim_ctrl_ops,
|
||||
.id = V4L2_CID_IMX_FIM_TOLERANCE_MIN,
|
||||
.name = "FIM Tolerance Min",
|
||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
||||
.def = FIM_CL_TOLERANCE_MIN_DEF,
|
||||
.min = 2,
|
||||
.max = 200,
|
||||
.step = 1,
|
||||
},
|
||||
[FIM_CL_TOLERANCE_MAX] = {
|
||||
.ops = &fim_ctrl_ops,
|
||||
.id = V4L2_CID_IMX_FIM_TOLERANCE_MAX,
|
||||
.name = "FIM Tolerance Max",
|
||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
||||
.def = FIM_CL_TOLERANCE_MAX_DEF,
|
||||
.min = 0,
|
||||
.max = 500,
|
||||
.step = 1,
|
||||
},
|
||||
[FIM_CL_NUM_SKIP] = {
|
||||
.ops = &fim_ctrl_ops,
|
||||
.id = V4L2_CID_IMX_FIM_NUM_SKIP,
|
||||
.name = "FIM Num Skip",
|
||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
||||
.def = FIM_CL_NUM_SKIP_DEF,
|
||||
.min = 0, /* skip no frames */
|
||||
.max = 256, /* skip 256 frames */
|
||||
.step = 1,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct v4l2_ctrl_config fim_icap_ctrl[] = {
|
||||
[FIM_CL_ICAP_EDGE] = {
|
||||
.ops = &fim_ctrl_ops,
|
||||
.id = V4L2_CID_IMX_FIM_ICAP_EDGE,
|
||||
.name = "FIM Input Capture Edge",
|
||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
||||
.def = IRQ_TYPE_NONE, /* input capture disabled by default */
|
||||
.min = IRQ_TYPE_NONE,
|
||||
.max = IRQ_TYPE_EDGE_BOTH,
|
||||
.step = 1,
|
||||
},
|
||||
[FIM_CL_ICAP_CHANNEL] = {
|
||||
.ops = &fim_ctrl_ops,
|
||||
.id = V4L2_CID_IMX_FIM_ICAP_CHANNEL,
|
||||
.name = "FIM Input Capture Channel",
|
||||
.type = V4L2_CTRL_TYPE_INTEGER,
|
||||
.def = 0,
|
||||
.min = 0,
|
||||
.max = 1,
|
||||
.step = 1,
|
||||
},
|
||||
};
|
||||
|
||||
static int init_fim_controls(struct imx_media_fim *fim)
|
||||
{
|
||||
struct v4l2_ctrl_handler *hdlr = &fim->ctrl_handler;
|
||||
int i, ret;
|
||||
|
||||
v4l2_ctrl_handler_init(hdlr, FIM_NUM_CONTROLS + FIM_NUM_ICAP_CONTROLS);
|
||||
|
||||
for (i = 0; i < FIM_NUM_CONTROLS; i++)
|
||||
fim->ctrl[i] = v4l2_ctrl_new_custom(hdlr,
|
||||
&fim_ctrl[i],
|
||||
NULL);
|
||||
for (i = 0; i < FIM_NUM_ICAP_CONTROLS; i++)
|
||||
fim->icap_ctrl[i] = v4l2_ctrl_new_custom(hdlr,
|
||||
&fim_icap_ctrl[i],
|
||||
NULL);
|
||||
if (hdlr->error) {
|
||||
ret = hdlr->error;
|
||||
goto err_free;
|
||||
}
|
||||
|
||||
v4l2_ctrl_cluster(FIM_NUM_CONTROLS, fim->ctrl);
|
||||
v4l2_ctrl_cluster(FIM_NUM_ICAP_CONTROLS, fim->icap_ctrl);
|
||||
|
||||
return 0;
|
||||
err_free:
|
||||
v4l2_ctrl_handler_free(hdlr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Monitor frame intervals via EOF interrupt. This method is
|
||||
* subject to uncertainty errors introduced by interrupt latency.
|
||||
*
|
||||
* This is a noop if the Input Capture method is being used, since
|
||||
* the frame_interval_monitor() is called by the input capture event
|
||||
* callback handler in that case.
|
||||
*/
|
||||
void imx_media_fim_eof_monitor(struct imx_media_fim *fim, struct timespec *ts)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&fim->lock, flags);
|
||||
|
||||
if (!icap_enabled(fim))
|
||||
frame_interval_monitor(fim, ts);
|
||||
|
||||
spin_unlock_irqrestore(&fim->lock, flags);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(imx_media_fim_eof_monitor);
|
||||
|
||||
/* Called by the subdev in its s_stream callback */
|
||||
int imx_media_fim_set_stream(struct imx_media_fim *fim,
|
||||
const struct v4l2_fract *fi,
|
||||
bool on)
|
||||
{
|
||||
unsigned long flags;
|
||||
int ret = 0;
|
||||
|
||||
v4l2_ctrl_lock(fim->ctrl[FIM_CL_ENABLE]);
|
||||
|
||||
if (fim->stream_on == on)
|
||||
goto out;
|
||||
|
||||
if (on) {
|
||||
spin_lock_irqsave(&fim->lock, flags);
|
||||
reset_fim(fim, true);
|
||||
update_fim_nominal(fim, fi);
|
||||
spin_unlock_irqrestore(&fim->lock, flags);
|
||||
|
||||
if (icap_enabled(fim)) {
|
||||
ret = fim_request_input_capture(fim);
|
||||
if (ret)
|
||||
goto out;
|
||||
fim_acquire_first_ts(fim);
|
||||
}
|
||||
} else {
|
||||
if (icap_enabled(fim))
|
||||
fim_free_input_capture(fim);
|
||||
}
|
||||
|
||||
fim->stream_on = on;
|
||||
out:
|
||||
v4l2_ctrl_unlock(fim->ctrl[FIM_CL_ENABLE]);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(imx_media_fim_set_stream);
|
||||
|
||||
int imx_media_fim_add_controls(struct imx_media_fim *fim)
|
||||
{
|
||||
/* add the FIM controls to the calling subdev ctrl handler */
|
||||
return v4l2_ctrl_add_handler(fim->sd->ctrl_handler,
|
||||
&fim->ctrl_handler, NULL);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(imx_media_fim_add_controls);
|
||||
|
||||
/* Called by the subdev in its subdev registered callback */
|
||||
struct imx_media_fim *imx_media_fim_init(struct v4l2_subdev *sd)
|
||||
{
|
||||
struct imx_media_fim *fim;
|
||||
int ret;
|
||||
|
||||
fim = devm_kzalloc(sd->dev, sizeof(*fim), GFP_KERNEL);
|
||||
if (!fim)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
/* get media device */
|
||||
fim->md = dev_get_drvdata(sd->v4l2_dev->dev);
|
||||
fim->sd = sd;
|
||||
|
||||
spin_lock_init(&fim->lock);
|
||||
|
||||
ret = init_fim_controls(fim);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
return fim;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(imx_media_fim_init);
|
||||
|
||||
void imx_media_fim_free(struct imx_media_fim *fim)
|
||||
{
|
||||
v4l2_ctrl_handler_free(&fim->ctrl_handler);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(imx_media_fim_free);
|
||||
349
drivers/staging/media/imx/imx-media-internal-sd.c
Normal file
349
drivers/staging/media/imx/imx-media-internal-sd.c
Normal file
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* Media driver for Freescale i.MX5/6 SOC
|
||||
*
|
||||
* Adds the internal subdevices and the media links between them.
|
||||
*
|
||||
* Copyright (c) 2016 Mentor Graphics Inc.
|
||||
*
|
||||
* 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/platform_device.h>
|
||||
#include "imx-media.h"
|
||||
|
||||
enum isd_enum {
|
||||
isd_csi0 = 0,
|
||||
isd_csi1,
|
||||
isd_vdic,
|
||||
isd_ic_prp,
|
||||
isd_ic_prpenc,
|
||||
isd_ic_prpvf,
|
||||
num_isd,
|
||||
};
|
||||
|
||||
static const struct internal_subdev_id {
|
||||
enum isd_enum index;
|
||||
const char *name;
|
||||
u32 grp_id;
|
||||
} isd_id[num_isd] = {
|
||||
[isd_csi0] = {
|
||||
.index = isd_csi0,
|
||||
.grp_id = IMX_MEDIA_GRP_ID_CSI0,
|
||||
.name = "imx-ipuv3-csi",
|
||||
},
|
||||
[isd_csi1] = {
|
||||
.index = isd_csi1,
|
||||
.grp_id = IMX_MEDIA_GRP_ID_CSI1,
|
||||
.name = "imx-ipuv3-csi",
|
||||
},
|
||||
[isd_vdic] = {
|
||||
.index = isd_vdic,
|
||||
.grp_id = IMX_MEDIA_GRP_ID_VDIC,
|
||||
.name = "imx-ipuv3-vdic",
|
||||
},
|
||||
[isd_ic_prp] = {
|
||||
.index = isd_ic_prp,
|
||||
.grp_id = IMX_MEDIA_GRP_ID_IC_PRP,
|
||||
.name = "imx-ipuv3-ic",
|
||||
},
|
||||
[isd_ic_prpenc] = {
|
||||
.index = isd_ic_prpenc,
|
||||
.grp_id = IMX_MEDIA_GRP_ID_IC_PRPENC,
|
||||
.name = "imx-ipuv3-ic",
|
||||
},
|
||||
[isd_ic_prpvf] = {
|
||||
.index = isd_ic_prpvf,
|
||||
.grp_id = IMX_MEDIA_GRP_ID_IC_PRPVF,
|
||||
.name = "imx-ipuv3-ic",
|
||||
},
|
||||
};
|
||||
|
||||
struct internal_link {
|
||||
const struct internal_subdev_id *remote_id;
|
||||
int remote_pad;
|
||||
};
|
||||
|
||||
struct internal_pad {
|
||||
bool devnode; /* does this pad link to a device node */
|
||||
struct internal_link link[IMX_MEDIA_MAX_LINKS];
|
||||
};
|
||||
|
||||
static const struct internal_subdev {
|
||||
const struct internal_subdev_id *id;
|
||||
struct internal_pad pad[IMX_MEDIA_MAX_PADS];
|
||||
int num_sink_pads;
|
||||
int num_src_pads;
|
||||
} internal_subdev[num_isd] = {
|
||||
[isd_csi0] = {
|
||||
.id = &isd_id[isd_csi0],
|
||||
.num_sink_pads = CSI_NUM_SINK_PADS,
|
||||
.num_src_pads = CSI_NUM_SRC_PADS,
|
||||
.pad[CSI_SRC_PAD_DIRECT] = {
|
||||
.link = {
|
||||
{
|
||||
.remote_id = &isd_id[isd_ic_prp],
|
||||
.remote_pad = PRP_SINK_PAD,
|
||||
}, {
|
||||
.remote_id = &isd_id[isd_vdic],
|
||||
.remote_pad = VDIC_SINK_PAD_DIRECT,
|
||||
},
|
||||
},
|
||||
},
|
||||
.pad[CSI_SRC_PAD_IDMAC] = {
|
||||
.devnode = true,
|
||||
},
|
||||
},
|
||||
|
||||
[isd_csi1] = {
|
||||
.id = &isd_id[isd_csi1],
|
||||
.num_sink_pads = CSI_NUM_SINK_PADS,
|
||||
.num_src_pads = CSI_NUM_SRC_PADS,
|
||||
.pad[CSI_SRC_PAD_DIRECT] = {
|
||||
.link = {
|
||||
{
|
||||
.remote_id = &isd_id[isd_ic_prp],
|
||||
.remote_pad = PRP_SINK_PAD,
|
||||
}, {
|
||||
.remote_id = &isd_id[isd_vdic],
|
||||
.remote_pad = VDIC_SINK_PAD_DIRECT,
|
||||
},
|
||||
},
|
||||
},
|
||||
.pad[CSI_SRC_PAD_IDMAC] = {
|
||||
.devnode = true,
|
||||
},
|
||||
},
|
||||
|
||||
[isd_vdic] = {
|
||||
.id = &isd_id[isd_vdic],
|
||||
.num_sink_pads = VDIC_NUM_SINK_PADS,
|
||||
.num_src_pads = VDIC_NUM_SRC_PADS,
|
||||
.pad[VDIC_SINK_PAD_IDMAC] = {
|
||||
.devnode = true,
|
||||
},
|
||||
.pad[VDIC_SRC_PAD_DIRECT] = {
|
||||
.link = {
|
||||
{
|
||||
.remote_id = &isd_id[isd_ic_prp],
|
||||
.remote_pad = PRP_SINK_PAD,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
[isd_ic_prp] = {
|
||||
.id = &isd_id[isd_ic_prp],
|
||||
.num_sink_pads = PRP_NUM_SINK_PADS,
|
||||
.num_src_pads = PRP_NUM_SRC_PADS,
|
||||
.pad[PRP_SRC_PAD_PRPENC] = {
|
||||
.link = {
|
||||
{
|
||||
.remote_id = &isd_id[isd_ic_prpenc],
|
||||
.remote_pad = 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
.pad[PRP_SRC_PAD_PRPVF] = {
|
||||
.link = {
|
||||
{
|
||||
.remote_id = &isd_id[isd_ic_prpvf],
|
||||
.remote_pad = 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
[isd_ic_prpenc] = {
|
||||
.id = &isd_id[isd_ic_prpenc],
|
||||
.num_sink_pads = PRPENCVF_NUM_SINK_PADS,
|
||||
.num_src_pads = PRPENCVF_NUM_SRC_PADS,
|
||||
.pad[PRPENCVF_SRC_PAD] = {
|
||||
.devnode = true,
|
||||
},
|
||||
},
|
||||
|
||||
[isd_ic_prpvf] = {
|
||||
.id = &isd_id[isd_ic_prpvf],
|
||||
.num_sink_pads = PRPENCVF_NUM_SINK_PADS,
|
||||
.num_src_pads = PRPENCVF_NUM_SRC_PADS,
|
||||
.pad[PRPENCVF_SRC_PAD] = {
|
||||
.devnode = true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/* form a device name given a group id and ipu id */
|
||||
static inline void isd_id_to_devname(char *devname, int sz,
|
||||
const struct internal_subdev_id *id,
|
||||
int ipu_id)
|
||||
{
|
||||
int pdev_id = ipu_id * num_isd + id->index;
|
||||
|
||||
snprintf(devname, sz, "%s.%d", id->name, pdev_id);
|
||||
}
|
||||
|
||||
/* adds the links from given internal subdev */
|
||||
static int add_internal_links(struct imx_media_dev *imxmd,
|
||||
const struct internal_subdev *isd,
|
||||
struct imx_media_subdev *imxsd,
|
||||
int ipu_id)
|
||||
{
|
||||
int i, num_pads, ret;
|
||||
|
||||
num_pads = isd->num_sink_pads + isd->num_src_pads;
|
||||
|
||||
for (i = 0; i < num_pads; i++) {
|
||||
const struct internal_pad *intpad = &isd->pad[i];
|
||||
struct imx_media_pad *pad = &imxsd->pad[i];
|
||||
int j;
|
||||
|
||||
/* init the pad flags for this internal subdev */
|
||||
pad->pad.flags = (i < isd->num_sink_pads) ?
|
||||
MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
|
||||
/* export devnode pad flag to the subdevs */
|
||||
pad->devnode = intpad->devnode;
|
||||
|
||||
for (j = 0; ; j++) {
|
||||
const struct internal_link *link;
|
||||
char remote_devname[32];
|
||||
|
||||
link = &intpad->link[j];
|
||||
|
||||
if (!link->remote_id)
|
||||
break;
|
||||
|
||||
isd_id_to_devname(remote_devname,
|
||||
sizeof(remote_devname),
|
||||
link->remote_id, ipu_id);
|
||||
|
||||
ret = imx_media_add_pad_link(imxmd, pad,
|
||||
NULL, remote_devname,
|
||||
i, link->remote_pad);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* register an internal subdev as a platform device */
|
||||
static struct imx_media_subdev *
|
||||
add_internal_subdev(struct imx_media_dev *imxmd,
|
||||
const struct internal_subdev *isd,
|
||||
int ipu_id)
|
||||
{
|
||||
struct imx_media_internal_sd_platformdata pdata;
|
||||
struct platform_device_info pdevinfo = {0};
|
||||
struct imx_media_subdev *imxsd;
|
||||
struct platform_device *pdev;
|
||||
|
||||
pdata.grp_id = isd->id->grp_id;
|
||||
|
||||
/* the id of IPU this subdev will control */
|
||||
pdata.ipu_id = ipu_id;
|
||||
|
||||
/* create subdev name */
|
||||
imx_media_grp_id_to_sd_name(pdata.sd_name, sizeof(pdata.sd_name),
|
||||
pdata.grp_id, ipu_id);
|
||||
|
||||
pdevinfo.name = isd->id->name;
|
||||
pdevinfo.id = ipu_id * num_isd + isd->id->index;
|
||||
pdevinfo.parent = imxmd->md.dev;
|
||||
pdevinfo.data = &pdata;
|
||||
pdevinfo.size_data = sizeof(pdata);
|
||||
pdevinfo.dma_mask = DMA_BIT_MASK(32);
|
||||
|
||||
pdev = platform_device_register_full(&pdevinfo);
|
||||
if (IS_ERR(pdev))
|
||||
return ERR_CAST(pdev);
|
||||
|
||||
imxsd = imx_media_add_async_subdev(imxmd, NULL, pdev);
|
||||
if (IS_ERR(imxsd))
|
||||
return imxsd;
|
||||
|
||||
imxsd->num_sink_pads = isd->num_sink_pads;
|
||||
imxsd->num_src_pads = isd->num_src_pads;
|
||||
|
||||
return imxsd;
|
||||
}
|
||||
|
||||
/* adds the internal subdevs in one ipu */
|
||||
static int add_ipu_internal_subdevs(struct imx_media_dev *imxmd,
|
||||
struct imx_media_subdev *csi0,
|
||||
struct imx_media_subdev *csi1,
|
||||
int ipu_id)
|
||||
{
|
||||
enum isd_enum i;
|
||||
int ret;
|
||||
|
||||
for (i = 0; i < num_isd; i++) {
|
||||
const struct internal_subdev *isd = &internal_subdev[i];
|
||||
struct imx_media_subdev *imxsd;
|
||||
|
||||
/*
|
||||
* the CSIs are represented in the device-tree, so those
|
||||
* devices are added already, and are added to the async
|
||||
* subdev list by of_parse_subdev(), so we are given those
|
||||
* subdevs as csi0 and csi1.
|
||||
*/
|
||||
switch (isd->id->grp_id) {
|
||||
case IMX_MEDIA_GRP_ID_CSI0:
|
||||
imxsd = csi0;
|
||||
break;
|
||||
case IMX_MEDIA_GRP_ID_CSI1:
|
||||
imxsd = csi1;
|
||||
break;
|
||||
default:
|
||||
imxsd = add_internal_subdev(imxmd, isd, ipu_id);
|
||||
break;
|
||||
}
|
||||
|
||||
if (IS_ERR(imxsd))
|
||||
return PTR_ERR(imxsd);
|
||||
|
||||
/* add the links from this subdev */
|
||||
if (imxsd) {
|
||||
ret = add_internal_links(imxmd, isd, imxsd, ipu_id);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int imx_media_add_internal_subdevs(struct imx_media_dev *imxmd,
|
||||
struct imx_media_subdev *csi[4])
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = add_ipu_internal_subdevs(imxmd, csi[0], csi[1], 0);
|
||||
if (ret)
|
||||
goto remove;
|
||||
|
||||
ret = add_ipu_internal_subdevs(imxmd, csi[2], csi[3], 1);
|
||||
if (ret)
|
||||
goto remove;
|
||||
|
||||
return 0;
|
||||
|
||||
remove:
|
||||
imx_media_remove_internal_subdevs(imxmd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void imx_media_remove_internal_subdevs(struct imx_media_dev *imxmd)
|
||||
{
|
||||
struct imx_media_subdev *imxsd;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < imxmd->subdev_notifier.num_subdevs; i++) {
|
||||
imxsd = &imxmd->subdev[i];
|
||||
if (!imxsd->pdev)
|
||||
continue;
|
||||
platform_device_unregister(imxsd->pdev);
|
||||
}
|
||||
}
|
||||
270
drivers/staging/media/imx/imx-media-of.c
Normal file
270
drivers/staging/media/imx/imx-media-of.c
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Media driver for Freescale i.MX5/6 SOC
|
||||
*
|
||||
* Open Firmware parsing.
|
||||
*
|
||||
* Copyright (c) 2016 Mentor Graphics Inc.
|
||||
*
|
||||
* 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/of_platform.h>
|
||||
#include <media/v4l2-ctrls.h>
|
||||
#include <media/v4l2-device.h>
|
||||
#include <media/v4l2-fwnode.h>
|
||||
#include <media/v4l2-subdev.h>
|
||||
#include <media/videobuf2-dma-contig.h>
|
||||
#include <linux/of_graph.h>
|
||||
#include <video/imx-ipu-v3.h>
|
||||
#include "imx-media.h"
|
||||
|
||||
static int of_add_pad_link(struct imx_media_dev *imxmd,
|
||||
struct imx_media_pad *pad,
|
||||
struct device_node *local_sd_node,
|
||||
struct device_node *remote_sd_node,
|
||||
int local_pad, int remote_pad)
|
||||
{
|
||||
dev_dbg(imxmd->md.dev, "%s: adding %s:%d -> %s:%d\n", __func__,
|
||||
local_sd_node->name, local_pad,
|
||||
remote_sd_node->name, remote_pad);
|
||||
|
||||
return imx_media_add_pad_link(imxmd, pad, remote_sd_node, NULL,
|
||||
local_pad, remote_pad);
|
||||
}
|
||||
|
||||
static void of_parse_sensor(struct imx_media_dev *imxmd,
|
||||
struct imx_media_subdev *sensor,
|
||||
struct device_node *sensor_np)
|
||||
{
|
||||
struct device_node *endpoint;
|
||||
|
||||
endpoint = of_graph_get_next_endpoint(sensor_np, NULL);
|
||||
if (endpoint) {
|
||||
v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint),
|
||||
&sensor->sensor_ep);
|
||||
of_node_put(endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
static int of_get_port_count(const struct device_node *np)
|
||||
{
|
||||
struct device_node *ports, *child;
|
||||
int num = 0;
|
||||
|
||||
/* check if this node has a ports subnode */
|
||||
ports = of_get_child_by_name(np, "ports");
|
||||
if (ports)
|
||||
np = ports;
|
||||
|
||||
for_each_child_of_node(np, child)
|
||||
if (of_node_cmp(child->name, "port") == 0)
|
||||
num++;
|
||||
|
||||
of_node_put(ports);
|
||||
return num;
|
||||
}
|
||||
|
||||
/*
|
||||
* find the remote device node and remote port id (remote pad #)
|
||||
* given local endpoint node
|
||||
*/
|
||||
static void of_get_remote_pad(struct device_node *epnode,
|
||||
struct device_node **remote_node,
|
||||
int *remote_pad)
|
||||
{
|
||||
struct device_node *rp, *rpp;
|
||||
struct device_node *remote;
|
||||
|
||||
rp = of_graph_get_remote_port(epnode);
|
||||
rpp = of_graph_get_remote_port_parent(epnode);
|
||||
|
||||
if (of_device_is_compatible(rpp, "fsl,imx6q-ipu")) {
|
||||
/* the remote is one of the CSI ports */
|
||||
remote = rp;
|
||||
*remote_pad = 0;
|
||||
of_node_put(rpp);
|
||||
} else {
|
||||
remote = rpp;
|
||||
if (of_property_read_u32(rp, "reg", remote_pad))
|
||||
*remote_pad = 0;
|
||||
of_node_put(rp);
|
||||
}
|
||||
|
||||
if (!of_device_is_available(remote)) {
|
||||
of_node_put(remote);
|
||||
*remote_node = NULL;
|
||||
} else {
|
||||
*remote_node = remote;
|
||||
}
|
||||
}
|
||||
|
||||
static struct imx_media_subdev *
|
||||
of_parse_subdev(struct imx_media_dev *imxmd, struct device_node *sd_np,
|
||||
bool is_csi_port)
|
||||
{
|
||||
struct imx_media_subdev *imxsd;
|
||||
int i, num_pads, ret;
|
||||
|
||||
if (!of_device_is_available(sd_np)) {
|
||||
dev_dbg(imxmd->md.dev, "%s: %s not enabled\n", __func__,
|
||||
sd_np->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* register this subdev with async notifier */
|
||||
imxsd = imx_media_add_async_subdev(imxmd, sd_np, NULL);
|
||||
if (IS_ERR_OR_NULL(imxsd))
|
||||
return imxsd;
|
||||
|
||||
if (is_csi_port) {
|
||||
/*
|
||||
* the ipu-csi has one sink port and two source ports.
|
||||
* The source ports are not represented in the device tree,
|
||||
* but are described by the internal pads and links later.
|
||||
*/
|
||||
num_pads = CSI_NUM_PADS;
|
||||
imxsd->num_sink_pads = CSI_NUM_SINK_PADS;
|
||||
} else if (of_device_is_compatible(sd_np, "fsl,imx6-mipi-csi2")) {
|
||||
num_pads = of_get_port_count(sd_np);
|
||||
/* the mipi csi2 receiver has only one sink port */
|
||||
imxsd->num_sink_pads = 1;
|
||||
} else if (of_device_is_compatible(sd_np, "video-mux")) {
|
||||
num_pads = of_get_port_count(sd_np);
|
||||
/* for the video mux, all but the last port are sinks */
|
||||
imxsd->num_sink_pads = num_pads - 1;
|
||||
} else {
|
||||
num_pads = of_get_port_count(sd_np);
|
||||
if (num_pads != 1) {
|
||||
dev_warn(imxmd->md.dev,
|
||||
"%s: unknown device %s with %d ports\n",
|
||||
__func__, sd_np->name, num_pads);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* we got to this node from this single source port,
|
||||
* there are no sink pads.
|
||||
*/
|
||||
imxsd->num_sink_pads = 0;
|
||||
}
|
||||
|
||||
if (imxsd->num_sink_pads >= num_pads)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
imxsd->num_src_pads = num_pads - imxsd->num_sink_pads;
|
||||
|
||||
dev_dbg(imxmd->md.dev, "%s: %s has %d pads (%d sink, %d src)\n",
|
||||
__func__, sd_np->name, num_pads,
|
||||
imxsd->num_sink_pads, imxsd->num_src_pads);
|
||||
|
||||
/*
|
||||
* With no sink, this subdev node is the original source
|
||||
* of video, parse it's media bus for use by the pipeline.
|
||||
*/
|
||||
if (imxsd->num_sink_pads == 0)
|
||||
of_parse_sensor(imxmd, imxsd, sd_np);
|
||||
|
||||
for (i = 0; i < num_pads; i++) {
|
||||
struct device_node *epnode = NULL, *port, *remote_np;
|
||||
struct imx_media_subdev *remote_imxsd;
|
||||
struct imx_media_pad *pad;
|
||||
int remote_pad;
|
||||
|
||||
/* init this pad */
|
||||
pad = &imxsd->pad[i];
|
||||
pad->pad.flags = (i < imxsd->num_sink_pads) ?
|
||||
MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
|
||||
|
||||
if (is_csi_port)
|
||||
port = (i < imxsd->num_sink_pads) ? sd_np : NULL;
|
||||
else
|
||||
port = of_graph_get_port_by_id(sd_np, i);
|
||||
if (!port)
|
||||
continue;
|
||||
|
||||
for_each_child_of_node(port, epnode) {
|
||||
of_get_remote_pad(epnode, &remote_np, &remote_pad);
|
||||
if (!remote_np)
|
||||
continue;
|
||||
|
||||
ret = of_add_pad_link(imxmd, pad, sd_np, remote_np,
|
||||
i, remote_pad);
|
||||
if (ret) {
|
||||
imxsd = ERR_PTR(ret);
|
||||
break;
|
||||
}
|
||||
|
||||
if (i < imxsd->num_sink_pads) {
|
||||
/* follow sink endpoints upstream */
|
||||
remote_imxsd = of_parse_subdev(imxmd,
|
||||
remote_np,
|
||||
false);
|
||||
if (IS_ERR(remote_imxsd)) {
|
||||
imxsd = remote_imxsd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
of_node_put(remote_np);
|
||||
}
|
||||
|
||||
if (port != sd_np)
|
||||
of_node_put(port);
|
||||
if (IS_ERR(imxsd)) {
|
||||
of_node_put(remote_np);
|
||||
of_node_put(epnode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return imxsd;
|
||||
}
|
||||
|
||||
int imx_media_of_parse(struct imx_media_dev *imxmd,
|
||||
struct imx_media_subdev *(*csi)[4],
|
||||
struct device_node *np)
|
||||
{
|
||||
struct imx_media_subdev *lcsi;
|
||||
struct device_node *csi_np;
|
||||
u32 ipu_id, csi_id;
|
||||
int i, ret;
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
csi_np = of_parse_phandle(np, "ports", i);
|
||||
if (!csi_np)
|
||||
break;
|
||||
|
||||
lcsi = of_parse_subdev(imxmd, csi_np, true);
|
||||
if (IS_ERR(lcsi)) {
|
||||
ret = PTR_ERR(lcsi);
|
||||
goto err_put;
|
||||
}
|
||||
|
||||
ret = of_property_read_u32(csi_np, "reg", &csi_id);
|
||||
if (ret) {
|
||||
dev_err(imxmd->md.dev,
|
||||
"%s: csi port missing reg property!\n",
|
||||
__func__);
|
||||
goto err_put;
|
||||
}
|
||||
|
||||
ipu_id = of_alias_get_id(csi_np->parent, "ipu");
|
||||
of_node_put(csi_np);
|
||||
|
||||
if (ipu_id > 1 || csi_id > 1) {
|
||||
dev_err(imxmd->md.dev,
|
||||
"%s: invalid ipu/csi id (%u/%u)\n",
|
||||
__func__, ipu_id, csi_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
(*csi)[ipu_id * 2 + csi_id] = lcsi;
|
||||
}
|
||||
|
||||
return 0;
|
||||
err_put:
|
||||
of_node_put(csi_np);
|
||||
return ret;
|
||||
}
|
||||
834
drivers/staging/media/imx/imx-media-utils.c
Normal file
834
drivers/staging/media/imx/imx-media-utils.c
Normal file
File diff suppressed because it is too large
Load Diff
323
drivers/staging/media/imx/imx-media.h
Normal file
323
drivers/staging/media/imx/imx-media.h
Normal file
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
* V4L2 Media Controller Driver for Freescale i.MX5/6 SOC
|
||||
*
|
||||
* Copyright (c) 2016 Mentor Graphics Inc.
|
||||
*
|
||||
* 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 _IMX_MEDIA_H
|
||||
#define _IMX_MEDIA_H
|
||||
|
||||
#include <media/v4l2-ctrls.h>
|
||||
#include <media/v4l2-device.h>
|
||||
#include <media/v4l2-fwnode.h>
|
||||
#include <media/v4l2-subdev.h>
|
||||
#include <media/videobuf2-dma-contig.h>
|
||||
#include <video/imx-ipu-v3.h>
|
||||
|
||||
/*
|
||||
* This is somewhat arbitrary, but we need at least:
|
||||
* - 4 video devices per IPU
|
||||
* - 3 IC subdevs per IPU
|
||||
* - 1 VDIC subdev per IPU
|
||||
* - 2 CSI subdevs per IPU
|
||||
* - 1 mipi-csi2 receiver subdev
|
||||
* - 2 video-mux subdevs
|
||||
* - 2 camera sensor subdevs per IPU (1 parallel, 1 mipi-csi2)
|
||||
*
|
||||
*/
|
||||
/* max video devices */
|
||||
#define IMX_MEDIA_MAX_VDEVS 8
|
||||
/* max subdevices */
|
||||
#define IMX_MEDIA_MAX_SUBDEVS 32
|
||||
/* max pads per subdev */
|
||||
#define IMX_MEDIA_MAX_PADS 16
|
||||
/* max links per pad */
|
||||
#define IMX_MEDIA_MAX_LINKS 8
|
||||
|
||||
/*
|
||||
* Pad definitions for the subdevs with multiple source or
|
||||
* sink pads
|
||||
*/
|
||||
|
||||
/* ipu_csi */
|
||||
enum {
|
||||
CSI_SINK_PAD = 0,
|
||||
CSI_SRC_PAD_DIRECT,
|
||||
CSI_SRC_PAD_IDMAC,
|
||||
CSI_NUM_PADS,
|
||||
};
|
||||
|
||||
#define CSI_NUM_SINK_PADS 1
|
||||
#define CSI_NUM_SRC_PADS 2
|
||||
|
||||
/* ipu_vdic */
|
||||
enum {
|
||||
VDIC_SINK_PAD_DIRECT = 0,
|
||||
VDIC_SINK_PAD_IDMAC,
|
||||
VDIC_SRC_PAD_DIRECT,
|
||||
VDIC_NUM_PADS,
|
||||
};
|
||||
|
||||
#define VDIC_NUM_SINK_PADS 2
|
||||
#define VDIC_NUM_SRC_PADS 1
|
||||
|
||||
/* ipu_ic_prp */
|
||||
enum {
|
||||
PRP_SINK_PAD = 0,
|
||||
PRP_SRC_PAD_PRPENC,
|
||||
PRP_SRC_PAD_PRPVF,
|
||||
PRP_NUM_PADS,
|
||||
};
|
||||
|
||||
#define PRP_NUM_SINK_PADS 1
|
||||
#define PRP_NUM_SRC_PADS 2
|
||||
|
||||
/* ipu_ic_prpencvf */
|
||||
enum {
|
||||
PRPENCVF_SINK_PAD = 0,
|
||||
PRPENCVF_SRC_PAD,
|
||||
PRPENCVF_NUM_PADS,
|
||||
};
|
||||
|
||||
#define PRPENCVF_NUM_SINK_PADS 1
|
||||
#define PRPENCVF_NUM_SRC_PADS 1
|
||||
|
||||
/* How long to wait for EOF interrupts in the buffer-capture subdevs */
|
||||
#define IMX_MEDIA_EOF_TIMEOUT 1000
|
||||
|
||||
struct imx_media_pixfmt {
|
||||
u32 fourcc;
|
||||
u32 codes[4];
|
||||
int bpp; /* total bpp */
|
||||
enum ipu_color_space cs;
|
||||
bool planar; /* is a planar format */
|
||||
bool bayer; /* is a raw bayer format */
|
||||
bool ipufmt; /* is one of the IPU internal formats */
|
||||
};
|
||||
|
||||
struct imx_media_buffer {
|
||||
struct vb2_v4l2_buffer vbuf; /* v4l buffer must be first */
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
struct imx_media_video_dev {
|
||||
struct video_device *vfd;
|
||||
|
||||
/* the user format */
|
||||
struct v4l2_format fmt;
|
||||
const struct imx_media_pixfmt *cc;
|
||||
};
|
||||
|
||||
static inline struct imx_media_buffer *to_imx_media_vb(struct vb2_buffer *vb)
|
||||
{
|
||||
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
|
||||
|
||||
return container_of(vbuf, struct imx_media_buffer, vbuf);
|
||||
}
|
||||
|
||||
struct imx_media_link {
|
||||
struct device_node *remote_sd_node;
|
||||
char remote_devname[32];
|
||||
int local_pad;
|
||||
int remote_pad;
|
||||
};
|
||||
|
||||
struct imx_media_pad {
|
||||
struct media_pad pad;
|
||||
struct imx_media_link link[IMX_MEDIA_MAX_LINKS];
|
||||
bool devnode; /* does this pad link to a device node */
|
||||
int num_links;
|
||||
|
||||
/*
|
||||
* list of video devices that can be reached from this pad,
|
||||
* list is only valid for source pads.
|
||||
*/
|
||||
struct imx_media_video_dev *vdev[IMX_MEDIA_MAX_VDEVS];
|
||||
int num_vdevs;
|
||||
};
|
||||
|
||||
struct imx_media_internal_sd_platformdata {
|
||||
char sd_name[V4L2_SUBDEV_NAME_SIZE];
|
||||
u32 grp_id;
|
||||
int ipu_id;
|
||||
};
|
||||
|
||||
struct imx_media_subdev {
|
||||
struct v4l2_async_subdev asd;
|
||||
struct v4l2_subdev *sd; /* set when bound */
|
||||
|
||||
struct imx_media_pad pad[IMX_MEDIA_MAX_PADS];
|
||||
int num_sink_pads;
|
||||
int num_src_pads;
|
||||
|
||||
/* the platform device if this is an internal subdev */
|
||||
struct platform_device *pdev;
|
||||
/* the devname is needed for async devname match */
|
||||
char devname[32];
|
||||
|
||||
/* if this is a sensor */
|
||||
struct v4l2_fwnode_endpoint sensor_ep;
|
||||
};
|
||||
|
||||
struct imx_media_dev {
|
||||
struct media_device md;
|
||||
struct v4l2_device v4l2_dev;
|
||||
|
||||
/* the pipeline object */
|
||||
struct media_pipeline pipe;
|
||||
|
||||
struct mutex mutex; /* protect elements below */
|
||||
|
||||
/* master subdevice list */
|
||||
struct imx_media_subdev subdev[IMX_MEDIA_MAX_SUBDEVS];
|
||||
int num_subdevs;
|
||||
|
||||
/* master video device list */
|
||||
struct imx_media_video_dev *vdev[IMX_MEDIA_MAX_VDEVS];
|
||||
int num_vdevs;
|
||||
|
||||
/* IPUs this media driver control, valid after subdevs bound */
|
||||
struct ipu_soc *ipu[2];
|
||||
|
||||
/* for async subdev registration */
|
||||
struct v4l2_async_subdev *async_ptrs[IMX_MEDIA_MAX_SUBDEVS];
|
||||
struct v4l2_async_notifier subdev_notifier;
|
||||
};
|
||||
|
||||
enum codespace_sel {
|
||||
CS_SEL_YUV = 0,
|
||||
CS_SEL_RGB,
|
||||
CS_SEL_ANY,
|
||||
};
|
||||
|
||||
const struct imx_media_pixfmt *
|
||||
imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel, bool allow_bayer);
|
||||
int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel);
|
||||
const struct imx_media_pixfmt *
|
||||
imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel,
|
||||
bool allow_bayer);
|
||||
int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel,
|
||||
bool allow_bayer);
|
||||
const struct imx_media_pixfmt *
|
||||
imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel);
|
||||
int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel);
|
||||
|
||||
int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
|
||||
u32 width, u32 height, u32 code, u32 field,
|
||||
const struct imx_media_pixfmt **cc);
|
||||
|
||||
int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
|
||||
struct v4l2_mbus_framefmt *mbus,
|
||||
const struct imx_media_pixfmt *cc);
|
||||
int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image,
|
||||
struct v4l2_mbus_framefmt *mbus);
|
||||
int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
|
||||
struct ipu_image *image);
|
||||
|
||||
struct imx_media_subdev *
|
||||
imx_media_find_async_subdev(struct imx_media_dev *imxmd,
|
||||
struct device_node *np,
|
||||
const char *devname);
|
||||
struct imx_media_subdev *
|
||||
imx_media_add_async_subdev(struct imx_media_dev *imxmd,
|
||||
struct device_node *np,
|
||||
struct platform_device *pdev);
|
||||
int imx_media_add_pad_link(struct imx_media_dev *imxmd,
|
||||
struct imx_media_pad *pad,
|
||||
struct device_node *remote_node,
|
||||
const char *remote_devname,
|
||||
int local_pad, int remote_pad);
|
||||
|
||||
void imx_media_grp_id_to_sd_name(char *sd_name, int sz,
|
||||
u32 grp_id, int ipu_id);
|
||||
|
||||
int imx_media_add_internal_subdevs(struct imx_media_dev *imxmd,
|
||||
struct imx_media_subdev *csi[4]);
|
||||
void imx_media_remove_internal_subdevs(struct imx_media_dev *imxmd);
|
||||
|
||||
struct imx_media_subdev *
|
||||
imx_media_find_subdev_by_sd(struct imx_media_dev *imxmd,
|
||||
struct v4l2_subdev *sd);
|
||||
struct imx_media_subdev *
|
||||
imx_media_find_subdev_by_id(struct imx_media_dev *imxmd,
|
||||
u32 grp_id);
|
||||
int imx_media_add_video_device(struct imx_media_dev *imxmd,
|
||||
struct imx_media_video_dev *vdev);
|
||||
int imx_media_find_mipi_csi2_channel(struct imx_media_dev *imxmd,
|
||||
struct media_entity *start_entity);
|
||||
struct imx_media_subdev *
|
||||
imx_media_find_upstream_subdev(struct imx_media_dev *imxmd,
|
||||
struct media_entity *start_entity,
|
||||
u32 grp_id);
|
||||
struct imx_media_subdev *
|
||||
__imx_media_find_sensor(struct imx_media_dev *imxmd,
|
||||
struct media_entity *start_entity);
|
||||
struct imx_media_subdev *
|
||||
imx_media_find_sensor(struct imx_media_dev *imxmd,
|
||||
struct media_entity *start_entity);
|
||||
|
||||
struct imx_media_dma_buf {
|
||||
void *virt;
|
||||
dma_addr_t phys;
|
||||
unsigned long len;
|
||||
};
|
||||
|
||||
void imx_media_free_dma_buf(struct imx_media_dev *imxmd,
|
||||
struct imx_media_dma_buf *buf);
|
||||
int imx_media_alloc_dma_buf(struct imx_media_dev *imxmd,
|
||||
struct imx_media_dma_buf *buf,
|
||||
int size);
|
||||
|
||||
int imx_media_pipeline_set_stream(struct imx_media_dev *imxmd,
|
||||
struct media_entity *entity,
|
||||
bool on);
|
||||
|
||||
/* imx-media-fim.c */
|
||||
struct imx_media_fim;
|
||||
void imx_media_fim_eof_monitor(struct imx_media_fim *fim, struct timespec *ts);
|
||||
int imx_media_fim_set_stream(struct imx_media_fim *fim,
|
||||
const struct v4l2_fract *frame_interval,
|
||||
bool on);
|
||||
int imx_media_fim_add_controls(struct imx_media_fim *fim);
|
||||
struct imx_media_fim *imx_media_fim_init(struct v4l2_subdev *sd);
|
||||
void imx_media_fim_free(struct imx_media_fim *fim);
|
||||
|
||||
/* imx-media-of.c */
|
||||
struct imx_media_subdev *
|
||||
imx_media_of_find_subdev(struct imx_media_dev *imxmd,
|
||||
struct device_node *np,
|
||||
const char *name);
|
||||
int imx_media_of_parse(struct imx_media_dev *dev,
|
||||
struct imx_media_subdev *(*csi)[4],
|
||||
struct device_node *np);
|
||||
|
||||
/* imx-media-capture.c */
|
||||
struct imx_media_video_dev *
|
||||
imx_media_capture_device_init(struct v4l2_subdev *src_sd, int pad);
|
||||
void imx_media_capture_device_remove(struct imx_media_video_dev *vdev);
|
||||
int imx_media_capture_device_register(struct imx_media_video_dev *vdev);
|
||||
void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev);
|
||||
struct imx_media_buffer *
|
||||
imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev);
|
||||
void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev,
|
||||
struct v4l2_pix_format *pix);
|
||||
void imx_media_capture_device_error(struct imx_media_video_dev *vdev);
|
||||
|
||||
/* subdev group ids */
|
||||
#define IMX_MEDIA_GRP_ID_SENSOR (1 << 8)
|
||||
#define IMX_MEDIA_GRP_ID_VIDMUX (1 << 9)
|
||||
#define IMX_MEDIA_GRP_ID_CSI2 (1 << 10)
|
||||
#define IMX_MEDIA_GRP_ID_CSI_BIT 11
|
||||
#define IMX_MEDIA_GRP_ID_CSI (0x3 << IMX_MEDIA_GRP_ID_CSI_BIT)
|
||||
#define IMX_MEDIA_GRP_ID_CSI0 (1 << IMX_MEDIA_GRP_ID_CSI_BIT)
|
||||
#define IMX_MEDIA_GRP_ID_CSI1 (2 << IMX_MEDIA_GRP_ID_CSI_BIT)
|
||||
#define IMX_MEDIA_GRP_ID_VDIC (1 << 13)
|
||||
#define IMX_MEDIA_GRP_ID_IC_PRP (1 << 14)
|
||||
#define IMX_MEDIA_GRP_ID_IC_PRPENC (1 << 15)
|
||||
#define IMX_MEDIA_GRP_ID_IC_PRPVF (1 << 16)
|
||||
|
||||
#endif
|
||||
15
include/media/imx.h
Normal file
15
include/media/imx.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2017 Mentor Graphics Inc.
|
||||
*
|
||||
* 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 __MEDIA_IMX_H__
|
||||
#define __MEDIA_IMX_H__
|
||||
|
||||
#include <linux/imx-media.h>
|
||||
|
||||
#endif
|
||||
@@ -185,6 +185,10 @@ enum v4l2_colorfx {
|
||||
*/
|
||||
#define V4L2_CID_USER_MAX217X_BASE (V4L2_CID_USER_BASE + 0x1090)
|
||||
|
||||
/* The base for the imx driver controls.
|
||||
* We reserve 16 controls for this driver. */
|
||||
#define V4L2_CID_USER_IMX_BASE (V4L2_CID_USER_BASE + 0x1090)
|
||||
|
||||
/* MPEG-class control IDs */
|
||||
/* The MPEG controls are applicable to all codec controls
|
||||
* and the 'MPEG' part of the define is historical */
|
||||
|
||||
Reference in New Issue
Block a user