media: rkisp1: csi: Plumb the CSI RX subdev
Connect the CSI receiver subdevice between the sensors and the ISP. This includes: - Calling the subdevice via the v4l2 subdev API - Moving the async notifier for the sensor from the ISP to the CSI receiver - In the ISP, create a media link to the CSI receiver, and remove the media link creation to the sensor - In the CSI receiver, create a media link to the sensor Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Dafna Hirschfeld <dafna@fastmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
This commit is contained in:
committed by
Mauro Carvalho Chehab
parent
b298f059b9
commit
98bfd0cd5d
@@ -47,6 +47,34 @@ rkisp1_csi_get_pad_fmt(struct rkisp1_csi *csi,
|
|||||||
return v4l2_subdev_get_try_format(&csi->sd, &state, pad);
|
return v4l2_subdev_get_try_format(&csi->sd, &state, pad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rkisp1_csi_link_sensor(struct rkisp1_device *rkisp1, struct v4l2_subdev *sd,
|
||||||
|
struct rkisp1_sensor_async *s_asd,
|
||||||
|
unsigned int source_pad)
|
||||||
|
{
|
||||||
|
struct rkisp1_csi *csi = &rkisp1->csi;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
s_asd->pixel_rate_ctrl = v4l2_ctrl_find(sd->ctrl_handler,
|
||||||
|
V4L2_CID_PIXEL_RATE);
|
||||||
|
if (!s_asd->pixel_rate_ctrl) {
|
||||||
|
dev_err(rkisp1->dev, "No pixel rate control in subdev %s\n",
|
||||||
|
sd->name);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create the link from the sensor to the CSI receiver. */
|
||||||
|
ret = media_create_pad_link(&sd->entity, source_pad,
|
||||||
|
&csi->sd.entity, RKISP1_CSI_PAD_SINK,
|
||||||
|
!s_asd->index ? MEDIA_LNK_FL_ENABLED : 0);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(csi->rkisp1->dev, "failed to link src pad of %s\n",
|
||||||
|
sd->name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int rkisp1_csi_config(struct rkisp1_csi *csi,
|
static int rkisp1_csi_config(struct rkisp1_csi *csi,
|
||||||
const struct rkisp1_sensor_async *sensor)
|
const struct rkisp1_sensor_async *sensor)
|
||||||
{
|
{
|
||||||
@@ -122,7 +150,7 @@ static void rkisp1_csi_disable(struct rkisp1_csi *csi)
|
|||||||
val & (~RKISP1_CIF_MIPI_CTRL_OUTPUT_ENA));
|
val & (~RKISP1_CIF_MIPI_CTRL_OUTPUT_ENA));
|
||||||
}
|
}
|
||||||
|
|
||||||
int rkisp1_csi_start(struct rkisp1_csi *csi,
|
static int rkisp1_csi_start(struct rkisp1_csi *csi,
|
||||||
const struct rkisp1_sensor_async *sensor)
|
const struct rkisp1_sensor_async *sensor)
|
||||||
{
|
{
|
||||||
struct rkisp1_device *rkisp1 = csi->rkisp1;
|
struct rkisp1_device *rkisp1 = csi->rkisp1;
|
||||||
@@ -158,7 +186,7 @@ int rkisp1_csi_start(struct rkisp1_csi *csi,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rkisp1_csi_stop(struct rkisp1_csi *csi)
|
static void rkisp1_csi_stop(struct rkisp1_csi *csi)
|
||||||
{
|
{
|
||||||
rkisp1_csi_disable(csi);
|
rkisp1_csi_disable(csi);
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ void rkisp1_csi_cleanup(struct rkisp1_device *rkisp1);
|
|||||||
int rkisp1_csi_register(struct rkisp1_device *rkisp1);
|
int rkisp1_csi_register(struct rkisp1_device *rkisp1);
|
||||||
void rkisp1_csi_unregister(struct rkisp1_device *rkisp1);
|
void rkisp1_csi_unregister(struct rkisp1_device *rkisp1);
|
||||||
|
|
||||||
int rkisp1_csi_start(struct rkisp1_csi *csi,
|
int rkisp1_csi_link_sensor(struct rkisp1_device *rkisp1, struct v4l2_subdev *sd,
|
||||||
const struct rkisp1_sensor_async *sensor);
|
struct rkisp1_sensor_async *s_asd,
|
||||||
void rkisp1_csi_stop(struct rkisp1_csi *csi);
|
unsigned int source_pad);
|
||||||
|
|
||||||
#endif /* _RKISP1_CSI_H */
|
#endif /* _RKISP1_CSI_H */
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <linux/pinctrl/consumer.h>
|
#include <linux/pinctrl/consumer.h>
|
||||||
#include <linux/pm_runtime.h>
|
#include <linux/pm_runtime.h>
|
||||||
#include <media/v4l2-fwnode.h>
|
#include <media/v4l2-fwnode.h>
|
||||||
|
#include <media/v4l2-mc.h>
|
||||||
|
|
||||||
#include "rkisp1-common.h"
|
#include "rkisp1-common.h"
|
||||||
#include "rkisp1-csi.h"
|
#include "rkisp1-csi.h"
|
||||||
@@ -67,18 +68,28 @@
|
|||||||
*
|
*
|
||||||
* Media Topology
|
* Media Topology
|
||||||
* --------------
|
* --------------
|
||||||
|
*
|
||||||
* +----------+ +----------+
|
* +----------+ +----------+
|
||||||
* | Sensor 2 | | Sensor X |
|
* | Sensor 1 | | Sensor X |
|
||||||
* ------------ ... ------------
|
* ------------ ... ------------
|
||||||
* | 0 | | 0 |
|
* | 0 | | 0 |
|
||||||
* +----------+ +----------+ +-----------+
|
* +----------+ +----------+
|
||||||
* \ | | params |
|
* | |
|
||||||
* \ | | (output) |
|
* \----\ /----/
|
||||||
* +----------+ \ | +-----------+
|
* | |
|
||||||
* | Sensor 1 | v v |
|
* v v
|
||||||
* ------------ +------+------+ |
|
* +-------------+
|
||||||
* | 0 |----->| 0 | 1 |<---------+
|
* | 0 |
|
||||||
* +----------+ |------+------|
|
* ---------------
|
||||||
|
* | CSI-2 RX |
|
||||||
|
* --------------- +-----------+
|
||||||
|
* | 1 | | params |
|
||||||
|
* +-------------+ | (output) |
|
||||||
|
* | +-----------+
|
||||||
|
* v |
|
||||||
|
* +------+------+ |
|
||||||
|
* | 0 | 1 |<---------+
|
||||||
|
* |------+------|
|
||||||
* | ISP |
|
* | ISP |
|
||||||
* |------+------|
|
* |------+------|
|
||||||
* +-------------| 2 | 3 |----------+
|
* +-------------| 2 | 3 |----------+
|
||||||
@@ -119,17 +130,8 @@ static int rkisp1_subdev_notifier_bound(struct v4l2_async_notifier *notifier,
|
|||||||
container_of(asd, struct rkisp1_sensor_async, asd);
|
container_of(asd, struct rkisp1_sensor_async, asd);
|
||||||
int source_pad;
|
int source_pad;
|
||||||
|
|
||||||
s_asd->pixel_rate_ctrl = v4l2_ctrl_find(sd->ctrl_handler,
|
|
||||||
V4L2_CID_PIXEL_RATE);
|
|
||||||
if (!s_asd->pixel_rate_ctrl) {
|
|
||||||
dev_err(rkisp1->dev, "No pixel rate control in subdev %s\n",
|
|
||||||
sd->name);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
s_asd->sd = sd;
|
s_asd->sd = sd;
|
||||||
|
|
||||||
/* Create the link to the sensor. */
|
|
||||||
source_pad = media_entity_get_fwnode_pad(&sd->entity, s_asd->source_ep,
|
source_pad = media_entity_get_fwnode_pad(&sd->entity, s_asd->source_ep,
|
||||||
MEDIA_PAD_FL_SOURCE);
|
MEDIA_PAD_FL_SOURCE);
|
||||||
if (source_pad < 0) {
|
if (source_pad < 0) {
|
||||||
@@ -138,10 +140,7 @@ static int rkisp1_subdev_notifier_bound(struct v4l2_async_notifier *notifier,
|
|||||||
return source_pad;
|
return source_pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
return media_create_pad_link(&sd->entity, source_pad,
|
return rkisp1_csi_link_sensor(rkisp1, sd, s_asd, source_pad);
|
||||||
&rkisp1->isp.sd.entity,
|
|
||||||
RKISP1_ISP_PAD_SINK_VIDEO,
|
|
||||||
!s_asd->index ? MEDIA_LNK_FL_ENABLED : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rkisp1_subdev_notifier_complete(struct v4l2_async_notifier *notifier)
|
static int rkisp1_subdev_notifier_complete(struct v4l2_async_notifier *notifier)
|
||||||
@@ -283,6 +282,14 @@ static int rkisp1_create_links(struct rkisp1_device *rkisp1)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Link the CSI receiver to the ISP. */
|
||||||
|
ret = media_create_pad_link(&rkisp1->csi.sd.entity, RKISP1_CSI_PAD_SRC,
|
||||||
|
&rkisp1->isp.sd.entity,
|
||||||
|
RKISP1_ISP_PAD_SINK_VIDEO,
|
||||||
|
MEDIA_LNK_FL_ENABLED);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* create ISP->RSZ->CAP links */
|
/* create ISP->RSZ->CAP links */
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
struct media_entity *resizer =
|
struct media_entity *resizer =
|
||||||
@@ -364,13 +371,6 @@ static int rkisp1_entities_register(struct rkisp1_device *rkisp1)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ret = rkisp1_subdev_notifier_register(rkisp1);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(rkisp1->dev,
|
|
||||||
"Failed to register subdev notifier(%d)\n", ret);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@@ -534,10 +534,16 @@ static int rkisp1_probe(struct platform_device *pdev)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto err_cleanup_csi;
|
goto err_cleanup_csi;
|
||||||
|
|
||||||
|
ret = rkisp1_subdev_notifier_register(rkisp1);
|
||||||
|
if (ret)
|
||||||
|
goto err_unreg_entities;
|
||||||
|
|
||||||
rkisp1_debug_init(rkisp1);
|
rkisp1_debug_init(rkisp1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_unreg_entities:
|
||||||
|
rkisp1_entities_unregister(rkisp1);
|
||||||
err_cleanup_csi:
|
err_cleanup_csi:
|
||||||
rkisp1_csi_cleanup(rkisp1);
|
rkisp1_csi_cleanup(rkisp1);
|
||||||
err_unreg_media_dev:
|
err_unreg_media_dev:
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
#include <media/v4l2-event.h>
|
#include <media/v4l2-event.h>
|
||||||
|
|
||||||
#include "rkisp1-common.h"
|
#include "rkisp1-common.h"
|
||||||
#include "rkisp1-csi.h"
|
|
||||||
|
|
||||||
#define RKISP1_DEF_SINK_PAD_FMT MEDIA_BUS_FMT_SRGGB10_1X10
|
#define RKISP1_DEF_SINK_PAD_FMT MEDIA_BUS_FMT_SRGGB10_1X10
|
||||||
#define RKISP1_DEF_SRC_PAD_FMT MEDIA_BUS_FMT_YUYV8_2X8
|
#define RKISP1_DEF_SRC_PAD_FMT MEDIA_BUS_FMT_YUYV8_2X8
|
||||||
@@ -728,17 +727,13 @@ static int rkisp1_isp_s_stream(struct v4l2_subdev *sd, int enable)
|
|||||||
{
|
{
|
||||||
struct rkisp1_isp *isp = to_rkisp1_isp(sd);
|
struct rkisp1_isp *isp = to_rkisp1_isp(sd);
|
||||||
struct rkisp1_device *rkisp1 = isp->rkisp1;
|
struct rkisp1_device *rkisp1 = isp->rkisp1;
|
||||||
const struct rkisp1_sensor_async *asd;
|
|
||||||
struct media_pad *source_pad;
|
struct media_pad *source_pad;
|
||||||
struct media_pad *sink_pad;
|
struct media_pad *sink_pad;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!enable) {
|
if (!enable) {
|
||||||
v4l2_subdev_call(rkisp1->source, video, s_stream, false);
|
v4l2_subdev_call(rkisp1->source, video, s_stream, false);
|
||||||
|
|
||||||
rkisp1_csi_stop(&rkisp1->csi);
|
|
||||||
rkisp1_isp_stop(isp);
|
rkisp1_isp_stop(isp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -756,30 +751,20 @@ static int rkisp1_isp_s_stream(struct v4l2_subdev *sd, int enable)
|
|||||||
return -EPIPE;
|
return -EPIPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
asd = container_of(rkisp1->source->asd, struct rkisp1_sensor_async,
|
if (rkisp1->source != &rkisp1->csi.sd)
|
||||||
asd);
|
return -EPIPE;
|
||||||
|
|
||||||
if (asd->mbus_type != V4L2_MBUS_CSI2_DPHY)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
isp->frame_sequence = -1;
|
isp->frame_sequence = -1;
|
||||||
mutex_lock(&isp->ops_lock);
|
mutex_lock(&isp->ops_lock);
|
||||||
ret = rkisp1_config_cif(isp, asd->mbus_type, asd->mbus_flags);
|
ret = rkisp1_config_cif(isp, V4L2_MBUS_CSI2_DPHY, 0);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto mutex_unlock;
|
goto mutex_unlock;
|
||||||
|
|
||||||
rkisp1_isp_start(isp);
|
rkisp1_isp_start(isp);
|
||||||
|
|
||||||
ret = rkisp1_csi_start(&rkisp1->csi, asd);
|
|
||||||
if (ret) {
|
|
||||||
rkisp1_isp_stop(isp);
|
|
||||||
goto mutex_unlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = v4l2_subdev_call(rkisp1->source, video, s_stream, true);
|
ret = v4l2_subdev_call(rkisp1->source, video, s_stream, true);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
rkisp1_isp_stop(isp);
|
rkisp1_isp_stop(isp);
|
||||||
rkisp1_csi_stop(&rkisp1->csi);
|
|
||||||
goto mutex_unlock;
|
goto mutex_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user