Commit 0b11253f authored by Paul Kocialkowski's avatar Paul Kocialkowski Committed by Mauro Carvalho Chehab

media: sun6i-csi: Refactor main driver data structures

Merge contents of structs sun6i_csi and sun6i_csi_dev into a main
sun6i_csi_device structure holding a sun6i_csi_v4l2 struct for things
related to v4l2, as well as the already-existing sun6i_csi_video and
sun6i_csi_config which are left unchanged.

This mostly simplifies accessing stuff by having a single main
structure accessible to every part of the code instead of a private
definition.

Also solve some kerneldoc warnings by describing return codes while
at it.

No functional change is intended in this commit, variables are just
moved around (cosmetics).
Signed-off-by: default avatarPaul Kocialkowski <paul.kocialkowski@bootlin.com>
Reviewed-by: default avatarMaxime Ripard <maxime@cerno.tech>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 6f4d0849
......@@ -17,8 +17,6 @@
#define SUN6I_CSI_NAME "sun6i-csi"
#define SUN6I_CSI_DESCRIPTION "Allwinner A31 CSI Device"
struct sun6i_csi;
/**
* struct sun6i_csi_config - configs for sun6i csi
* @pixelformat: v4l2 pixel format (V4L2_PIX_FMT_*)
......@@ -35,59 +33,75 @@ struct sun6i_csi_config {
u32 height;
};
struct sun6i_csi {
struct device *dev;
struct v4l2_ctrl_handler ctrl_handler;
struct sun6i_csi_v4l2 {
struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler ctrl_handler;
struct media_device media_dev;
struct v4l2_async_notifier notifier;
/* video port settings */
struct v4l2_fwnode_endpoint v4l2_ep;
};
struct sun6i_csi_config config;
struct sun6i_csi_device {
struct device *dev;
struct sun6i_csi_config config;
struct sun6i_csi_v4l2 v4l2;
struct sun6i_video video;
struct regmap *regmap;
struct clk *clk_mod;
struct clk *clk_ram;
struct reset_control *reset;
int planar_offset[3];
};
/**
* sun6i_csi_is_format_supported() - check if the format supported by csi
* @csi: pointer to the csi
* @csi_dev: pointer to the csi device
* @pixformat: v4l2 pixel format (V4L2_PIX_FMT_*)
* @mbus_code: media bus format code (MEDIA_BUS_FMT_*)
*
* Return: true if format is supported, false otherwise.
*/
bool sun6i_csi_is_format_supported(struct sun6i_csi *csi, u32 pixformat,
u32 mbus_code);
bool sun6i_csi_is_format_supported(struct sun6i_csi_device *csi_dev,
u32 pixformat, u32 mbus_code);
/**
* sun6i_csi_set_power() - power on/off the csi
* @csi: pointer to the csi
* @csi_dev: pointer to the csi device
* @enable: on/off
*
* Return: 0 if successful, error code otherwise.
*/
int sun6i_csi_set_power(struct sun6i_csi *csi, bool enable);
int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable);
/**
* sun6i_csi_update_config() - update the csi register settings
* @csi: pointer to the csi
* @csi_dev: pointer to the csi device
* @config: see struct sun6i_csi_config
*
* Return: 0 if successful, error code otherwise.
*/
int sun6i_csi_update_config(struct sun6i_csi *csi,
int sun6i_csi_update_config(struct sun6i_csi_device *csi_dev,
struct sun6i_csi_config *config);
/**
* sun6i_csi_update_buf_addr() - update the csi frame buffer address
* @csi: pointer to the csi
* @csi_dev: pointer to the csi device
* @addr: frame buffer's physical address
*/
void sun6i_csi_update_buf_addr(struct sun6i_csi *csi, dma_addr_t addr);
void sun6i_csi_update_buf_addr(struct sun6i_csi_device *csi_dev,
dma_addr_t addr);
/**
* sun6i_csi_set_stream() - start/stop csi streaming
* @csi: pointer to the csi
* @csi_dev: pointer to the csi device
* @enable: start/stop
*/
void sun6i_csi_set_stream(struct sun6i_csi *csi, bool enable);
void sun6i_csi_set_stream(struct sun6i_csi_device *csi_dev, bool enable);
/* get bpp form v4l2 pixformat */
static inline int sun6i_csi_get_bpp(unsigned int pixformat)
......
......@@ -162,7 +162,7 @@ static int sun6i_video_start_streaming(struct vb2_queue *vq, unsigned int count)
config.width = video->fmt.fmt.pix.width;
config.height = video->fmt.fmt.pix.height;
ret = sun6i_csi_update_config(video->csi, &config);
ret = sun6i_csi_update_config(video->csi_dev, &config);
if (ret < 0)
goto stop_media_pipeline;
......@@ -171,9 +171,9 @@ static int sun6i_video_start_streaming(struct vb2_queue *vq, unsigned int count)
buf = list_first_entry(&video->dma_queue,
struct sun6i_csi_buffer, list);
buf->queued_to_csi = true;
sun6i_csi_update_buf_addr(video->csi, buf->dma_addr);
sun6i_csi_update_buf_addr(video->csi_dev, buf->dma_addr);
sun6i_csi_set_stream(video->csi, true);
sun6i_csi_set_stream(video->csi_dev, true);
/*
* CSI will lookup the next dma buffer for next frame before the
......@@ -194,7 +194,7 @@ static int sun6i_video_start_streaming(struct vb2_queue *vq, unsigned int count)
*/
next_buf = list_next_entry(buf, list);
next_buf->queued_to_csi = true;
sun6i_csi_update_buf_addr(video->csi, next_buf->dma_addr);
sun6i_csi_update_buf_addr(video->csi_dev, next_buf->dma_addr);
spin_unlock_irqrestore(&video->dma_queue_lock, flags);
......@@ -205,7 +205,7 @@ static int sun6i_video_start_streaming(struct vb2_queue *vq, unsigned int count)
return 0;
stop_csi_stream:
sun6i_csi_set_stream(video->csi, false);
sun6i_csi_set_stream(video->csi_dev, false);
stop_media_pipeline:
video_device_pipeline_stop(&video->vdev);
clear_dma_queue:
......@@ -229,7 +229,7 @@ static void sun6i_video_stop_streaming(struct vb2_queue *vq)
if (subdev)
v4l2_subdev_call(subdev, video, s_stream, 0);
sun6i_csi_set_stream(video->csi, false);
sun6i_csi_set_stream(video->csi_dev, false);
video_device_pipeline_stop(&video->vdev);
......@@ -266,7 +266,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, "Frame dropped!\n");
dev_dbg(video->csi_dev->dev, "Frame dropped!\n");
goto unlock;
}
......@@ -278,8 +278,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, next_buf->dma_addr);
dev_dbg(video->csi->dev, "Frame dropped!\n");
sun6i_csi_update_buf_addr(video->csi_dev, next_buf->dma_addr);
dev_dbg(video->csi_dev->dev, "Frame dropped!\n");
goto unlock;
}
......@@ -293,9 +293,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, next_buf->dma_addr);
sun6i_csi_update_buf_addr(video->csi_dev, next_buf->dma_addr);
} else {
dev_dbg(video->csi->dev, "Next frame will be dropped!\n");
dev_dbg(video->csi_dev->dev, "Next frame will be dropped!\n");
}
unlock:
......@@ -321,7 +321,7 @@ static int vidioc_querycap(struct file *file, void *priv,
strscpy(cap->driver, "sun6i-video", sizeof(cap->driver));
strscpy(cap->card, video->vdev.name, sizeof(cap->card));
snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
video->csi->dev->of_node->name);
video->csi_dev->dev->of_node->name);
return 0;
}
......@@ -488,7 +488,7 @@ static int sun6i_video_open(struct file *file)
if (!v4l2_fh_is_singular_file(file))
goto unlock;
ret = sun6i_csi_set_power(video->csi, true);
ret = sun6i_csi_set_power(video->csi_dev, true);
if (ret < 0)
goto fh_release;
......@@ -516,7 +516,7 @@ static int sun6i_video_close(struct file *file)
v4l2_pipeline_pm_put(&video->vdev.entity);
if (last_fh)
sun6i_csi_set_power(video->csi, false);
sun6i_csi_set_power(video->csi_dev, false);
mutex_unlock(&video->lock);
......@@ -561,7 +561,7 @@ static int sun6i_video_link_validate(struct media_link *link)
video->mbus_code = 0;
if (!media_pad_remote_pad_first(link->sink->entity->pads)) {
dev_info(video->csi->dev,
dev_info(video->csi_dev->dev,
"video node %s pad not connected\n", vdev->name);
return -ENOLINK;
}
......@@ -570,10 +570,10 @@ static int sun6i_video_link_validate(struct media_link *link)
if (ret < 0)
return ret;
if (!sun6i_csi_is_format_supported(video->csi,
if (!sun6i_csi_is_format_supported(video->csi_dev,
video->fmt.fmt.pix.pixelformat,
source_fmt.format.code)) {
dev_err(video->csi->dev,
dev_err(video->csi_dev->dev,
"Unsupported pixformat: 0x%x with mbus code: 0x%x!\n",
video->fmt.fmt.pix.pixelformat,
source_fmt.format.code);
......@@ -582,7 +582,7 @@ static int sun6i_video_link_validate(struct media_link *link)
if (source_fmt.format.width != video->fmt.fmt.pix.width ||
source_fmt.format.height != video->fmt.fmt.pix.height) {
dev_err(video->csi->dev,
dev_err(video->csi_dev->dev,
"Wrong width or height %ux%u (%ux%u expected)\n",
video->fmt.fmt.pix.width, video->fmt.fmt.pix.height,
source_fmt.format.width, source_fmt.format.height);
......@@ -598,15 +598,16 @@ static const struct media_entity_operations sun6i_video_media_ops = {
.link_validate = sun6i_video_link_validate
};
int sun6i_video_init(struct sun6i_video *video, struct sun6i_csi *csi,
const char *name)
int sun6i_video_init(struct sun6i_video *video,
struct sun6i_csi_device *csi_dev, const char *name)
{
struct sun6i_csi_v4l2 *v4l2 = &csi_dev->v4l2;
struct video_device *vdev = &video->vdev;
struct vb2_queue *vidq = &video->vb2_vidq;
struct v4l2_format fmt = { 0 };
int ret;
video->csi = csi;
video->csi_dev = csi_dev;
/* Initialize the media entity... */
video->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
......@@ -641,11 +642,12 @@ int sun6i_video_init(struct sun6i_video *video, struct sun6i_csi *csi,
vidq->lock = &video->lock;
/* Make sure non-dropped frame */
vidq->min_buffers_needed = 3;
vidq->dev = csi->dev;
vidq->dev = csi_dev->dev;
ret = vb2_queue_init(vidq);
if (ret) {
v4l2_err(&csi->v4l2_dev, "vb2_queue_init failed: %d\n", ret);
v4l2_err(&v4l2->v4l2_dev, "vb2_queue_init failed: %d\n",
ret);
goto clean_entity;
}
......@@ -656,7 +658,7 @@ int sun6i_video_init(struct sun6i_video *video, struct sun6i_csi *csi,
vdev->ioctl_ops = &sun6i_video_ioctl_ops;
vdev->vfl_type = VFL_TYPE_VIDEO;
vdev->vfl_dir = VFL_DIR_RX;
vdev->v4l2_dev = &csi->v4l2_dev;
vdev->v4l2_dev = &v4l2->v4l2_dev;
vdev->queue = vidq;
vdev->lock = &video->lock;
vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE;
......@@ -664,7 +666,7 @@ int sun6i_video_init(struct sun6i_video *video, struct sun6i_csi *csi,
ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
if (ret < 0) {
v4l2_err(&csi->v4l2_dev,
v4l2_err(&v4l2->v4l2_dev,
"video_register_device failed: %d\n", ret);
goto clean_entity;
}
......
......@@ -11,12 +11,12 @@
#include <media/v4l2-dev.h>
#include <media/videobuf2-core.h>
struct sun6i_csi;
struct sun6i_csi_device;
struct sun6i_video {
struct sun6i_csi_device *csi_dev;
struct video_device vdev;
struct media_pad pad;
struct sun6i_csi *csi;
struct mutex lock;
......@@ -29,8 +29,8 @@ struct sun6i_video {
u32 mbus_code;
};
int sun6i_video_init(struct sun6i_video *video, struct sun6i_csi *csi,
const char *name);
int sun6i_video_init(struct sun6i_video *video,
struct sun6i_csi_device *csi_dev, const char *name);
void sun6i_video_cleanup(struct sun6i_video *video);
void sun6i_video_frame_done(struct sun6i_video *video);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment