Skip to content

Commit

Permalink
ipu6: ipu-isys-video video node support for camera subdev
Browse files Browse the repository at this point in the history
        - ipu-isys-video.c:
            - control for enhanced node support by pipeline subdevices enumerating
            - inheritance of sub-device controls within same vc
            - s/g_parm ioctl ops to set/get fps on subdev
            - vidioc_enum_framesizes - implement remote sensor polling
            - vidioc_enum_frameintervals - implement remote sensor polling
            - vidioc_enum_fmt - select only sub-device formats
            - vidioc_s_fmt_vid_cap_mplane - set remote link format
            - vidioc_try_fmt_vid_cap_mplane - try remote format
            - set format for internal entities on stream start

        - ipu-isys.h: V4L2_CID_IPU_ENUMERATE_LINK
        - ipu-isys-video.h: ipu_isys_video.enum_link_state state for link enumeration by vc

Signed-off-by: Dmitry Perchanov <[email protected]>
  • Loading branch information
dmipx committed Mar 27, 2023
1 parent c61e2c8 commit c69d0fe
Show file tree
Hide file tree
Showing 9 changed files with 801 additions and 115 deletions.
1 change: 1 addition & 0 deletions drivers/media/pci/intel/ipu-isys-csi2-be-soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static const u32 csi2_be_soc_supported_codes_pad[] = {
MEDIA_BUS_FMT_RGB888_1X24,
MEDIA_BUS_FMT_UYVY8_1X16,
MEDIA_BUS_FMT_YUYV8_1X16,
MEDIA_BUS_FMT_VYUY8_1X16,
MEDIA_BUS_FMT_SBGGR12_1X12,
MEDIA_BUS_FMT_SGBRG12_1X12,
MEDIA_BUS_FMT_SGRBG12_1X12,
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/pci/intel/ipu-isys-csi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static const u32 csi2_supported_codes_pad_sink[] = {
MEDIA_BUS_FMT_RGB888_1X24,
MEDIA_BUS_FMT_UYVY8_1X16,
MEDIA_BUS_FMT_YUYV8_1X16,
MEDIA_BUS_FMT_VYUY8_1X16,
MEDIA_BUS_FMT_YUYV10_1X20,
MEDIA_BUS_FMT_SBGGR10_1X10,
MEDIA_BUS_FMT_SGBRG10_1X10,
Expand Down Expand Up @@ -52,6 +53,7 @@ static const u32 csi2_supported_codes_pad_source[] = {
MEDIA_BUS_FMT_RGB888_1X24,
MEDIA_BUS_FMT_UYVY8_1X16,
MEDIA_BUS_FMT_YUYV8_1X16,
MEDIA_BUS_FMT_VYUY8_1X16,
MEDIA_BUS_FMT_YUYV10_1X20,
MEDIA_BUS_FMT_SBGGR10_1X10,
MEDIA_BUS_FMT_SGBRG10_1X10,
Expand Down
142 changes: 136 additions & 6 deletions drivers/media/pci/intel/ipu-isys-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/module.h>
#include <linux/string.h>
#include <linux/delay.h>
#include <linux/pm_runtime.h>

#include <media/media-entity.h>
#include <media/videobuf2-dma-contig.h>
Expand Down Expand Up @@ -611,7 +612,7 @@ static void buf_queue(struct vb2_buffer *vb)
"error: buffer list get failed\n");
WARN_ON(1);
} else {
dev_info(&av->isys->adev->dev,
dev_dbg(&av->isys->adev->dev,
"not enough buffers available\n");
}
goto out;
Expand Down Expand Up @@ -818,14 +819,15 @@ static int __start_streaming(struct vb2_queue *q, unsigned int count)
}

mutex_unlock(&av->isys->stream_mutex);

if (!count) { // link validation fail if we restart stream triggered by fw
rval = aq->link_fmt_validate(aq);
if (rval) {
dev_err(&av->isys->adev->dev,
"%s: link format validation failed (%d)\n",
av->vdev.name, rval);
goto out_unprepare_streaming;
}
}

ip = to_ipu_isys_pipeline(media_entity_pipeline(&av->vdev.entity));
pipe_av = container_of(ip, struct ipu_isys_video, ip);
Expand Down Expand Up @@ -894,12 +896,136 @@ static int __start_streaming(struct vb2_queue *q, unsigned int count)
return rval;
}

static int isys_fw_open(struct ipu_isys_video *av)
{
struct ipu_isys *isys = av->isys;
struct ipu_bus_device *adev = to_ipu_bus_device(&isys->adev->dev);
struct ipu_device *isp = adev->isp;
int rval;
const struct ipu_isys_internal_pdata *ipdata;

dev_warn(&isys->adev->dev, "%s:%d %s: enter\n",
__func__, __LINE__, av->vdev.name);

mutex_lock(&isys->mutex);

if (isys->reset_needed || isp->flr_done) {
mutex_unlock(&isys->mutex);
dev_warn(&isys->adev->dev, "%s:%d %s: isys power cycle required\n",
__func__, __LINE__, av->vdev.name);
return -EIO;
}
mutex_unlock(&isys->mutex);

rval = pm_runtime_get_sync(&isys->adev->dev);
if (rval < 0) {
pm_runtime_put_noidle(&isys->adev->dev);
return rval;
}

mutex_lock(&isys->mutex);
if (isys->video_opened++) {
/* Already open */
mutex_unlock(&isys->mutex);
dev_warn(&isys->adev->dev, "%s:%d %s: Already open, exit %d\n",
__func__, __LINE__, av->vdev.name, isys->video_opened);
return 0;
}

ipdata = isys->pdata->ipdata;
ipu_configure_spc(adev->isp,
&ipdata->hw_variant,
IPU_CPD_PKG_DIR_ISYS_SERVER_IDX,
isys->pdata->base, isys->pkg_dir,
isys->pkg_dir_dma_addr);

/*
* Buffers could have been left to wrong queue at last closure.
* Move them now back to empty buffer queue.
*/
ipu_cleanup_fw_msg_bufs(isys);

if (isys->fwcom) {
/*
* Something went wrong in previous shutdown. As we are now
* restarting isys we can safely delete old context.
*/
dev_err(&isys->adev->dev, "%s:%d %s Clearing old context\n",
__func__, __LINE__, av->vdev.name);
ipu_fw_isys_cleanup(isys);
}

rval = ipu_fw_isys_init(av->isys, ipdata->num_parallel_streams);
if (rval < 0)
goto out_lib_init;

mutex_unlock(&isys->mutex);

dev_warn(&isys->adev->dev, "%s:%d %s: exit\n",
__func__, __LINE__, av->vdev.name);
return 0;

out_lib_init:
isys->video_opened--;
mutex_unlock(&isys->mutex);
pm_runtime_put(&isys->adev->dev);

return rval;
}

static int isys_fw_release(struct ipu_isys_video *av)
{
struct ipu_isys *isys = av->isys;
int ret = 0;

dev_warn(&isys->adev->dev, "%s:%d %s: enter\n",
__func__, __LINE__, av->vdev.name);
mutex_lock(&isys->reset_mutex);
while (isys->in_reset) {
mutex_unlock(&isys->reset_mutex);
dev_warn(&isys->adev->dev, "%s:%d %s: wait for reset\n",
__func__, __LINE__, av->vdev.name);
usleep_range(10000, 11000);
mutex_lock(&isys->reset_mutex);
}
mutex_unlock(&isys->reset_mutex);

mutex_lock(&isys->mutex);
dev_warn(&isys->adev->dev, "%s:%d %s: close fw video_opened: %d\n",
__func__, __LINE__, av->vdev.name, isys->video_opened);
if (!--isys->video_opened) {
dev_warn(&isys->adev->dev, "%s:%d %s: close fw\n",
__func__, __LINE__, av->vdev.name);
ipu_fw_isys_close(isys);

if (isys->fwcom) {
isys->reset_needed = true;
ret = -EIO;
}
}

mutex_unlock(&isys->mutex);

if (isys->reset_needed)
pm_runtime_put_sync(&isys->adev->dev);
else
pm_runtime_put(&isys->adev->dev);

dev_warn(&isys->adev->dev, "%s:%d %s: exit\n",
__func__, __LINE__, av->vdev.name);
return ret;
}

static int start_streaming(struct vb2_queue *q, unsigned int count)
{
struct ipu_isys_queue *aq = vb2_queue_to_ipu_isys_queue(q);
struct ipu_isys_video *av = ipu_isys_queue_to_video(aq);
int rval;

rval = isys_fw_open(av);
if (rval < 0) {
dev_err(&av->isys->adev->dev, "isys_fw_open failed: %d\n", rval);
}
mutex_unlock(&av->mutex);
mutex_lock(&av->isys->reset_mutex);
while (av->isys->in_stop_streaming) {
Expand All @@ -914,7 +1040,8 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
mutex_lock(&av->mutex);

rval = __start_streaming(q, count);

if (rval)
isys_fw_release(av);
return rval;
}

Expand All @@ -923,7 +1050,8 @@ static void reset_stop_streaming(struct ipu_isys_video *av)
struct ipu_isys_pipeline *ip = &av->ip;
struct ipu_isys_queue *aq = &av->aq;

dev_dbg(&av->isys->adev->dev, "%s: stop streaming\n", av->vdev.name);
dev_warn(&av->isys->adev->dev, "%s():%d %s: stop streaming\n",
__func__, __LINE__, av->vdev.name);

mutex_lock(&av->isys->stream_mutex);
if (ip->nr_streaming == ip->nr_queues && ip->streaming)
Expand All @@ -943,7 +1071,8 @@ static int reset_start_streaming(struct ipu_isys_video *av)
unsigned long flags;
int rval;

dev_dbg(&av->isys->adev->dev, "%s: start streaming\n", av->vdev.name);
dev_warn(&av->isys->adev->dev, "%s():%d %s: start streaming\n",
__func__, __LINE__, av->vdev.name);

spin_lock_irqsave(&aq->lock, flags);
while (!list_empty(&aq->active)) {
Expand Down Expand Up @@ -1182,7 +1311,8 @@ static void stop_streaming(struct vb2_queue *q)
mutex_lock(&av->isys->reset_mutex);
av->isys->in_stop_streaming = false;
mutex_unlock(&av->isys->reset_mutex);

if (0 == ip->nr_streaming)
isys_fw_release(av);
}

static unsigned int
Expand Down
4 changes: 4 additions & 0 deletions drivers/media/pci/intel/ipu-isys-subdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ unsigned int ipu_isys_mbus_code_to_bpp(u32 code)
case MEDIA_BUS_FMT_RGB565_1X16:
case MEDIA_BUS_FMT_UYVY8_1X16:
case MEDIA_BUS_FMT_YUYV8_1X16:
case MEDIA_BUS_FMT_VYUY8_1X16:
return 16;
case MEDIA_BUS_FMT_SBGGR12_1X12:
case MEDIA_BUS_FMT_SGBRG12_1X12:
Expand All @@ -34,6 +35,7 @@ unsigned int ipu_isys_mbus_code_to_bpp(u32 code)
case MEDIA_BUS_FMT_SGRBG10_1X10:
case MEDIA_BUS_FMT_SRGGB10_1X10:
return 10;
case MEDIA_BUS_FMT_Y8_1X8:
case MEDIA_BUS_FMT_SBGGR8_1X8:
case MEDIA_BUS_FMT_SGBRG8_1X8:
case MEDIA_BUS_FMT_SGRBG8_1X8:
Expand All @@ -60,6 +62,7 @@ unsigned int ipu_isys_mbus_code_to_mipi(u32 code)
return IPU_ISYS_MIPI_CSI2_TYPE_YUV422_10;
case MEDIA_BUS_FMT_UYVY8_1X16:
case MEDIA_BUS_FMT_YUYV8_1X16:
case MEDIA_BUS_FMT_VYUY8_1X16:
return IPU_ISYS_MIPI_CSI2_TYPE_YUV422_8;
case MEDIA_BUS_FMT_SBGGR12_1X12:
case MEDIA_BUS_FMT_SGBRG12_1X12:
Expand All @@ -72,6 +75,7 @@ unsigned int ipu_isys_mbus_code_to_mipi(u32 code)
case MEDIA_BUS_FMT_SGRBG10_1X10:
case MEDIA_BUS_FMT_SRGGB10_1X10:
return IPU_ISYS_MIPI_CSI2_TYPE_RAW10;
case MEDIA_BUS_FMT_Y8_1X8:
case MEDIA_BUS_FMT_SBGGR8_1X8:
case MEDIA_BUS_FMT_SGBRG8_1X8:
case MEDIA_BUS_FMT_SGRBG8_1X8:
Expand Down
Loading

0 comments on commit c69d0fe

Please sign in to comment.