summaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorPaul Kocialkowski <paul.kocialkowski@bootlin.com>2022-08-26 20:32:07 +0200
committerMauro Carvalho Chehab <mchehab@kernel.org>2022-09-24 11:21:45 +0200
commit92cc51588225d82a4e3d2358e47367ac52b1661a (patch)
tree4ffaa0cb011f423f8b7a9e1728a4923181d70845 /drivers/media
parentmedia: sun6i-csi: Tidy up video code (diff)
downloadlinux-92cc51588225d82a4e3d2358e47367ac52b1661a.tar.xz
linux-92cc51588225d82a4e3d2358e47367ac52b1661a.zip
media: sun6i-csi: Pass and store csi device directly in video code
The video structure is part of the main csi device structure, so pass pointers to that top-level structure directly. This makes it easier to navigate and access other elements. No functional change intended. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> Reviewed-by: Maxime Ripard <maxime@cerno.tech> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c8
-rw-r--r--drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c91
-rw-r--r--drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h9
3 files changed, 57 insertions, 51 deletions
diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
index b4f90b065a0c..a55347b7a6d6 100644
--- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
+++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
@@ -706,7 +706,7 @@ static int sun6i_csi_v4l2_setup(struct sun6i_csi_device *csi_dev)
/* Video */
- ret = sun6i_video_setup(&csi_dev->video, csi_dev);
+ ret = sun6i_video_setup(csi_dev);
if (ret)
goto error_v4l2_device;
@@ -735,7 +735,7 @@ error_v4l2_async_notifier:
v4l2_async_nf_cleanup(notifier);
error_video:
- sun6i_video_cleanup(&csi_dev->video);
+ sun6i_video_cleanup(csi_dev);
error_v4l2_device:
v4l2_device_unregister(&v4l2->v4l2_dev);
@@ -756,7 +756,7 @@ static void sun6i_csi_v4l2_cleanup(struct sun6i_csi_device *csi_dev)
media_device_unregister(&v4l2->media_dev);
v4l2_async_nf_unregister(&v4l2->notifier);
v4l2_async_nf_cleanup(&v4l2->notifier);
- sun6i_video_cleanup(&csi_dev->video);
+ sun6i_video_cleanup(csi_dev);
v4l2_device_unregister(&v4l2->v4l2_dev);
v4l2_ctrl_handler_free(&v4l2->ctrl_handler);
media_device_cleanup(&v4l2->media_dev);
@@ -787,7 +787,7 @@ static irqreturn_t sun6i_csi_interrupt(int irq, void *private)
}
if (status & CSI_CH_INT_STA_FD_PD)
- sun6i_video_frame_done(&csi_dev->video);
+ sun6i_video_frame_done(csi_dev);
regmap_write(regmap, CSI_CH_INT_STA_REG, status);
diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
index 4710902447ac..50e5136e2281 100644
--- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
+++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
@@ -100,7 +100,8 @@ static int sun6i_video_queue_setup(struct vb2_queue *queue,
unsigned int sizes[],
struct device *alloc_devs[])
{
- struct sun6i_video *video = vb2_get_drv_priv(queue);
+ struct sun6i_csi_device *csi_dev = vb2_get_drv_priv(queue);
+ struct sun6i_video *video = &csi_dev->video;
unsigned int size = video->format.fmt.pix.sizeimage;
if (*planes_count)
@@ -114,8 +115,8 @@ static int sun6i_video_queue_setup(struct vb2_queue *queue,
static int sun6i_video_buffer_prepare(struct vb2_buffer *buffer)
{
- struct sun6i_video *video = vb2_get_drv_priv(buffer->vb2_queue);
- struct sun6i_csi_device *csi_dev = video->csi_dev;
+ struct sun6i_csi_device *csi_dev = vb2_get_drv_priv(buffer->vb2_queue);
+ struct sun6i_video *video = &csi_dev->video;
struct v4l2_device *v4l2_dev = &csi_dev->v4l2.v4l2_dev;
struct vb2_v4l2_buffer *v4l2_buffer = to_vb2_v4l2_buffer(buffer);
struct sun6i_csi_buffer *csi_buffer =
@@ -138,7 +139,8 @@ static int sun6i_video_buffer_prepare(struct vb2_buffer *buffer)
static void sun6i_video_buffer_queue(struct vb2_buffer *buffer)
{
- struct sun6i_video *video = vb2_get_drv_priv(buffer->vb2_queue);
+ struct sun6i_csi_device *csi_dev = vb2_get_drv_priv(buffer->vb2_queue);
+ struct sun6i_video *video = &csi_dev->video;
struct vb2_v4l2_buffer *v4l2_buffer = to_vb2_v4l2_buffer(buffer);
struct sun6i_csi_buffer *csi_buffer =
container_of(v4l2_buffer, struct sun6i_csi_buffer, v4l2_buffer);
@@ -153,7 +155,8 @@ static void sun6i_video_buffer_queue(struct vb2_buffer *buffer)
static int sun6i_video_start_streaming(struct vb2_queue *queue,
unsigned int count)
{
- struct sun6i_video *video = vb2_get_drv_priv(queue);
+ struct sun6i_csi_device *csi_dev = vb2_get_drv_priv(queue);
+ struct sun6i_video *video = &csi_dev->video;
struct video_device *video_dev = &video->video_dev;
struct sun6i_csi_buffer *buf;
struct sun6i_csi_buffer *next_buf;
@@ -185,7 +188,7 @@ static int sun6i_video_start_streaming(struct vb2_queue *queue,
config.width = video->format.fmt.pix.width;
config.height = video->format.fmt.pix.height;
- ret = sun6i_csi_update_config(video->csi_dev, &config);
+ ret = sun6i_csi_update_config(csi_dev, &config);
if (ret < 0)
goto error_media_pipeline;
@@ -194,9 +197,9 @@ static int sun6i_video_start_streaming(struct vb2_queue *queue,
buf = list_first_entry(&video->dma_queue,
struct sun6i_csi_buffer, list);
buf->queued_to_csi = true;
- sun6i_csi_update_buf_addr(video->csi_dev, buf->dma_addr);
+ sun6i_csi_update_buf_addr(csi_dev, buf->dma_addr);
- sun6i_csi_set_stream(video->csi_dev, true);
+ sun6i_csi_set_stream(csi_dev, true);
/*
* CSI will lookup the next dma buffer for next frame before the
@@ -217,7 +220,7 @@ static int sun6i_video_start_streaming(struct vb2_queue *queue,
*/
next_buf = list_next_entry(buf, list);
next_buf->queued_to_csi = true;
- sun6i_csi_update_buf_addr(video->csi_dev, next_buf->dma_addr);
+ sun6i_csi_update_buf_addr(csi_dev, next_buf->dma_addr);
spin_unlock_irqrestore(&video->dma_queue_lock, flags);
@@ -228,7 +231,7 @@ static int sun6i_video_start_streaming(struct vb2_queue *queue,
return 0;
error_stream:
- sun6i_csi_set_stream(video->csi_dev, false);
+ sun6i_csi_set_stream(csi_dev, false);
error_media_pipeline:
video_device_pipeline_stop(video_dev);
@@ -246,7 +249,8 @@ error_dma_queue_flush:
static void sun6i_video_stop_streaming(struct vb2_queue *queue)
{
- struct sun6i_video *video = vb2_get_drv_priv(queue);
+ struct sun6i_csi_device *csi_dev = vb2_get_drv_priv(queue);
+ struct sun6i_video *video = &csi_dev->video;
struct v4l2_subdev *subdev;
unsigned long flags;
struct sun6i_csi_buffer *buf;
@@ -255,7 +259,7 @@ static void sun6i_video_stop_streaming(struct vb2_queue *queue)
if (subdev)
v4l2_subdev_call(subdev, video, s_stream, 0);
- sun6i_csi_set_stream(video->csi_dev, false);
+ sun6i_csi_set_stream(csi_dev, false);
video_device_pipeline_stop(&video->video_dev);
@@ -267,8 +271,9 @@ static void sun6i_video_stop_streaming(struct vb2_queue *queue)
spin_unlock_irqrestore(&video->dma_queue_lock, flags);
}
-void sun6i_video_frame_done(struct sun6i_video *video)
+void sun6i_video_frame_done(struct sun6i_csi_device *csi_dev)
{
+ struct sun6i_video *video = &csi_dev->video;
struct sun6i_csi_buffer *buf;
struct sun6i_csi_buffer *next_buf;
struct vb2_v4l2_buffer *v4l2_buffer;
@@ -278,7 +283,7 @@ void sun6i_video_frame_done(struct sun6i_video *video)
buf = list_first_entry(&video->dma_queue,
struct sun6i_csi_buffer, list);
if (list_is_last(&buf->list, &video->dma_queue)) {
- dev_dbg(video->csi_dev->dev, "Frame dropped!\n");
+ dev_dbg(csi_dev->dev, "Frame dropped!\n");
goto complete;
}
@@ -290,8 +295,8 @@ void sun6i_video_frame_done(struct sun6i_video *video)
*/
if (!next_buf->queued_to_csi) {
next_buf->queued_to_csi = true;
- sun6i_csi_update_buf_addr(video->csi_dev, next_buf->dma_addr);
- dev_dbg(video->csi_dev->dev, "Frame dropped!\n");
+ sun6i_csi_update_buf_addr(csi_dev, next_buf->dma_addr);
+ dev_dbg(csi_dev->dev, "Frame dropped!\n");
goto complete;
}
@@ -305,9 +310,9 @@ void sun6i_video_frame_done(struct sun6i_video *video)
if (!list_is_last(&next_buf->list, &video->dma_queue)) {
next_buf = list_next_entry(next_buf, list);
next_buf->queued_to_csi = true;
- sun6i_csi_update_buf_addr(video->csi_dev, next_buf->dma_addr);
+ sun6i_csi_update_buf_addr(csi_dev, next_buf->dma_addr);
} else {
- dev_dbg(video->csi_dev->dev, "Next frame will be dropped!\n");
+ dev_dbg(csi_dev->dev, "Next frame will be dropped!\n");
}
complete:
@@ -330,9 +335,8 @@ static const struct vb2_ops sun6i_video_queue_ops = {
static int sun6i_video_querycap(struct file *file, void *private,
struct v4l2_capability *capability)
{
- struct sun6i_video *video = video_drvdata(file);
- struct sun6i_csi_device *csi_dev = video->csi_dev;
- struct video_device *video_dev = &video->video_dev;
+ struct sun6i_csi_device *csi_dev = video_drvdata(file);
+ struct video_device *video_dev = &csi_dev->video.video_dev;
strscpy(capability->driver, SUN6I_CSI_NAME, sizeof(capability->driver));
strscpy(capability->card, video_dev->name, sizeof(capability->card));
@@ -358,7 +362,8 @@ static int sun6i_video_enum_fmt(struct file *file, void *private,
static int sun6i_video_g_fmt(struct file *file, void *private,
struct v4l2_format *format)
{
- struct sun6i_video *video = video_drvdata(file);
+ struct sun6i_csi_device *csi_dev = video_drvdata(file);
+ struct sun6i_video *video = &csi_dev->video;
*format = video->format;
@@ -413,7 +418,8 @@ static int sun6i_video_format_set(struct sun6i_video *video,
static int sun6i_video_s_fmt(struct file *file, void *private,
struct v4l2_format *format)
{
- struct sun6i_video *video = video_drvdata(file);
+ struct sun6i_csi_device *csi_dev = video_drvdata(file);
+ struct sun6i_video *video = &csi_dev->video;
if (vb2_is_busy(&video->queue))
return -EBUSY;
@@ -424,7 +430,8 @@ static int sun6i_video_s_fmt(struct file *file, void *private,
static int sun6i_video_try_fmt(struct file *file, void *private,
struct v4l2_format *format)
{
- struct sun6i_video *video = video_drvdata(file);
+ struct sun6i_csi_device *csi_dev = video_drvdata(file);
+ struct sun6i_video *video = &csi_dev->video;
return sun6i_video_format_try(video, format);
}
@@ -489,7 +496,8 @@ static const struct v4l2_ioctl_ops sun6i_video_ioctl_ops = {
static int sun6i_video_open(struct file *file)
{
- struct sun6i_video *video = video_drvdata(file);
+ struct sun6i_csi_device *csi_dev = video_drvdata(file);
+ struct sun6i_video *video = &csi_dev->video;
int ret = 0;
if (mutex_lock_interruptible(&video->lock))
@@ -505,7 +513,7 @@ static int sun6i_video_open(struct file *file)
/* Power on at first open. */
if (v4l2_fh_is_singular_file(file)) {
- ret = sun6i_csi_set_power(video->csi_dev, true);
+ ret = sun6i_csi_set_power(csi_dev, true);
if (ret < 0)
goto error_v4l2_fh;
}
@@ -525,7 +533,8 @@ error_lock:
static int sun6i_video_close(struct file *file)
{
- struct sun6i_video *video = video_drvdata(file);
+ struct sun6i_csi_device *csi_dev = video_drvdata(file);
+ struct sun6i_video *video = &csi_dev->video;
bool last_close;
mutex_lock(&video->lock);
@@ -537,7 +546,7 @@ static int sun6i_video_close(struct file *file)
/* Power off at last close. */
if (last_close)
- sun6i_csi_set_power(video->csi_dev, false);
+ sun6i_csi_set_power(csi_dev, false);
mutex_unlock(&video->lock);
@@ -574,15 +583,16 @@ static int sun6i_video_link_validate(struct media_link *link)
{
struct video_device *vdev = container_of(link->sink->entity,
struct video_device, entity);
- struct sun6i_video *video = video_get_drvdata(vdev);
+ struct sun6i_csi_device *csi_dev = video_get_drvdata(vdev);
+ struct sun6i_video *video = &csi_dev->video;
struct v4l2_subdev_format source_fmt;
int ret;
video->mbus_code = 0;
if (!media_pad_remote_pad_first(link->sink->entity->pads)) {
- dev_info(video->csi_dev->dev,
- "video node %s pad not connected\n", vdev->name);
+ dev_info(csi_dev->dev, "video node %s pad not connected\n",
+ vdev->name);
return -ENOLINK;
}
@@ -590,10 +600,10 @@ static int sun6i_video_link_validate(struct media_link *link)
if (ret < 0)
return ret;
- if (!sun6i_csi_is_format_supported(video->csi_dev,
+ if (!sun6i_csi_is_format_supported(csi_dev,
video->format.fmt.pix.pixelformat,
source_fmt.format.code)) {
- dev_err(video->csi_dev->dev,
+ dev_err(csi_dev->dev,
"Unsupported pixformat: 0x%x with mbus code: 0x%x!\n",
video->format.fmt.pix.pixelformat,
source_fmt.format.code);
@@ -602,7 +612,7 @@ static int sun6i_video_link_validate(struct media_link *link)
if (source_fmt.format.width != video->format.fmt.pix.width ||
source_fmt.format.height != video->format.fmt.pix.height) {
- dev_err(video->csi_dev->dev,
+ dev_err(csi_dev->dev,
"Wrong width or height %ux%u (%ux%u expected)\n",
video->format.fmt.pix.width, video->format.fmt.pix.height,
source_fmt.format.width, source_fmt.format.height);
@@ -620,9 +630,9 @@ static const struct media_entity_operations sun6i_video_media_ops = {
/* Video */
-int sun6i_video_setup(struct sun6i_video *video,
- struct sun6i_csi_device *csi_dev)
+int sun6i_video_setup(struct sun6i_csi_device *csi_dev)
{
+ struct sun6i_video *video = &csi_dev->video;
struct v4l2_device *v4l2_dev = &csi_dev->v4l2.v4l2_dev;
struct video_device *video_dev = &video->video_dev;
struct vb2_queue *queue = &video->queue;
@@ -631,8 +641,6 @@ int sun6i_video_setup(struct sun6i_video *video,
struct v4l2_pix_format *pix_format = &format.fmt.pix;
int ret;
- video->csi_dev = csi_dev;
-
/* Media Entity */
video_dev->entity.ops = &sun6i_video_media_ops;
@@ -664,7 +672,7 @@ int sun6i_video_setup(struct sun6i_video *video,
queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
queue->lock = &video->lock;
queue->dev = csi_dev->dev;
- queue->drv_priv = video;
+ queue->drv_priv = csi_dev;
/* Make sure non-dropped frame. */
queue->min_buffers_needed = 3;
@@ -697,7 +705,7 @@ int sun6i_video_setup(struct sun6i_video *video,
video_dev->queue = queue;
video_dev->lock = &video->lock;
- video_set_drvdata(video_dev, video);
+ video_set_drvdata(video_dev, csi_dev);
ret = video_register_device(video_dev, VFL_TYPE_VIDEO, -1);
if (ret < 0) {
@@ -716,8 +724,9 @@ error_media_entity:
return ret;
}
-void sun6i_video_cleanup(struct sun6i_video *video)
+void sun6i_video_cleanup(struct sun6i_csi_device *csi_dev)
{
+ struct sun6i_video *video = &csi_dev->video;
struct video_device *video_dev = &video->video_dev;
vb2_video_unregister_device(video_dev);
diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h b/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h
index 7864f062d05b..a917d2da6deb 100644
--- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h
+++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h
@@ -14,8 +14,6 @@
struct sun6i_csi_device;
struct sun6i_video {
- struct sun6i_csi_device *csi_dev;
-
struct video_device video_dev;
struct vb2_queue queue;
struct mutex lock; /* Queue lock. */
@@ -29,10 +27,9 @@ struct sun6i_video {
unsigned int sequence;
};
-int sun6i_video_setup(struct sun6i_video *video,
- struct sun6i_csi_device *csi_dev);
-void sun6i_video_cleanup(struct sun6i_video *video);
+int sun6i_video_setup(struct sun6i_csi_device *csi_dev);
+void sun6i_video_cleanup(struct sun6i_csi_device *csi_dev);
-void sun6i_video_frame_done(struct sun6i_video *video);
+void sun6i_video_frame_done(struct sun6i_csi_device *csi_dev);
#endif /* __SUN6I_VIDEO_H__ */