1 From b7c453de65310924a81a9fb902727a7d8f39c36b Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 23 Jun 2020 15:14:05 +0100
4 Subject: [PATCH] media: bcm2835-unicam: Fixup review comments from
7 Updates the driver based on the upstream review comments from
8 Hans Verkuil at https://patchwork.linuxtv.org/patch/63531/
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 .../media/platform/bcm2835/bcm2835-unicam.c | 70 ++++++++-----------
13 1 file changed, 31 insertions(+), 39 deletions(-)
15 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
16 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
18 // SPDX-License-Identifier: GPL-2.0-only
20 - * BCM2835 Unicam Capture Driver
21 + * BCM283x / BCM271x Unicam Capture Driver
23 * Copyright (C) 2017-2020 - Raspberry Pi (Trading) Ltd.
25 @@ -573,9 +573,8 @@ static const struct unicam_fmt *find_for
29 -static inline unsigned int bytes_per_line(u32 width,
30 - const struct unicam_fmt *fmt,
32 +static unsigned int bytes_per_line(u32 width, const struct unicam_fmt *fmt,
35 if (v4l2_fourcc == fmt->repacked_fourcc)
36 /* Repacking always goes to 16bpp */
37 @@ -720,7 +719,7 @@ static void unicam_wr_dma_addr(struct un
41 -static inline unsigned int unicam_get_lines_done(struct unicam_device *dev)
42 +static unsigned int unicam_get_lines_done(struct unicam_device *dev)
44 dma_addr_t start_addr, cur_addr;
45 unsigned int stride = dev->node[IMAGE_PAD].v_fmt.fmt.pix.bytesperline;
46 @@ -734,7 +733,7 @@ static inline unsigned int unicam_get_li
47 return (unsigned int)(cur_addr - start_addr) / stride;
50 -static inline void unicam_schedule_next_buffer(struct unicam_node *node)
51 +static void unicam_schedule_next_buffer(struct unicam_node *node)
53 struct unicam_device *dev = node->dev;
54 struct unicam_buffer *buf;
55 @@ -753,7 +752,7 @@ static inline void unicam_schedule_next_
56 unicam_wr_dma_addr(dev, addr, size, node->pad_id);
59 -static inline void unicam_schedule_dummy_buffer(struct unicam_node *node)
60 +static void unicam_schedule_dummy_buffer(struct unicam_node *node)
62 struct unicam_device *dev = node->dev;
64 @@ -765,8 +764,8 @@ static inline void unicam_schedule_dummy
65 node->next_frm = NULL;
68 -static inline void unicam_process_buffer_complete(struct unicam_node *node,
69 - unsigned int sequence)
70 +static void unicam_process_buffer_complete(struct unicam_node *node,
71 + unsigned int sequence)
73 node->cur_frm->vb.field = node->m_fmt.field;
74 node->cur_frm->vb.sequence = sequence;
75 @@ -774,16 +773,6 @@ static inline void unicam_process_buffer
76 vb2_buffer_done(&node->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE);
79 -static bool unicam_all_nodes_streaming(struct unicam_device *dev)
83 - ret = dev->node[IMAGE_PAD].open && dev->node[IMAGE_PAD].streaming;
84 - ret &= !dev->node[METADATA_PAD].open ||
85 - dev->node[METADATA_PAD].streaming;
89 static void unicam_queue_event_sof(struct unicam_device *unicam)
91 struct v4l2_event event = {
92 @@ -906,8 +895,8 @@ static int unicam_querycap(struct file *
93 struct unicam_node *node = video_drvdata(file);
94 struct unicam_device *dev = node->dev;
96 - strlcpy(cap->driver, UNICAM_MODULE_NAME, sizeof(cap->driver));
97 - strlcpy(cap->card, UNICAM_MODULE_NAME, sizeof(cap->card));
98 + strscpy(cap->driver, UNICAM_MODULE_NAME, sizeof(cap->driver));
99 + strscpy(cap->card, UNICAM_MODULE_NAME, sizeof(cap->card));
101 snprintf(cap->bus_info, sizeof(cap->bus_info),
102 "platform:%s", dev_name(&dev->pdev->dev));
103 @@ -1000,8 +989,8 @@ static int unicam_g_fmt_vid_cap(struct f
108 -const struct unicam_fmt *get_first_supported_format(struct unicam_device *dev)
109 +static const struct unicam_fmt *
110 +get_first_supported_format(struct unicam_device *dev)
112 struct v4l2_subdev_mbus_code_enum mbus_code;
113 const struct unicam_fmt *fmt = NULL;
114 @@ -1591,7 +1580,8 @@ static void unicam_disable(struct unicam
118 -static void unicam_return_buffers(struct unicam_node *node)
119 +static void unicam_return_buffers(struct unicam_node *node,
120 + enum vb2_buffer_state state)
122 struct unicam_buffer *buf, *tmp;
124 @@ -1599,15 +1589,15 @@ static void unicam_return_buffers(struct
125 spin_lock_irqsave(&node->dma_queue_lock, flags);
126 list_for_each_entry_safe(buf, tmp, &node->dma_queue, list) {
127 list_del(&buf->list);
128 - vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
129 + vb2_buffer_done(&buf->vb.vb2_buf, state);
133 vb2_buffer_done(&node->cur_frm->vb.vb2_buf,
134 - VB2_BUF_STATE_ERROR);
136 if (node->next_frm && node->cur_frm != node->next_frm)
137 vb2_buffer_done(&node->next_frm->vb.vb2_buf,
138 - VB2_BUF_STATE_ERROR);
141 node->cur_frm = NULL;
142 node->next_frm = NULL;
143 @@ -1624,7 +1614,13 @@ static int unicam_start_streaming(struct
146 node->streaming = true;
147 - if (!unicam_all_nodes_streaming(dev)) {
148 + if (!(dev->node[IMAGE_PAD].open && dev->node[IMAGE_PAD].streaming &&
149 + (!dev->node[METADATA_PAD].open ||
150 + dev->node[METADATA_PAD].streaming))) {
152 + * Metadata pad must be enabled before image pad if it is
155 unicam_dbg(3, dev, "Not all nodes are streaming yet.");
158 @@ -1728,7 +1724,7 @@ err_vpu_clock:
160 unicam_runtime_put(dev);
162 - unicam_return_buffers(node);
163 + unicam_return_buffers(node, VB2_BUF_STATE_QUEUED);
164 node->streaming = false;
167 @@ -1773,7 +1769,7 @@ static void unicam_stop_streaming(struct
170 /* Clear all queued buffers for the node */
171 - unicam_return_buffers(node);
172 + unicam_return_buffers(node, VB2_BUF_STATE_ERROR);
175 static int unicam_enum_input(struct file *file, void *priv,
176 @@ -1791,14 +1787,13 @@ static int unicam_enum_input(struct file
178 } else if (v4l2_subdev_has_op(dev->sensor, video, s_std)) {
179 inp->capabilities = V4L2_IN_CAP_STD;
180 - if (v4l2_subdev_call(dev->sensor, video, g_tvnorms, &inp->std)
182 + if (v4l2_subdev_call(dev->sensor, video, g_tvnorms, &inp->std) < 0)
183 inp->std = V4L2_STD_ALL;
185 inp->capabilities = 0;
188 - sprintf(inp->name, "Camera 0");
189 + snprintf(inp->name, sizeof(inp->name), "Camera 0");
193 @@ -2027,6 +2022,9 @@ static int unicam_s_dv_timings(struct fi
194 ret = v4l2_subdev_call(dev->sensor, video, g_dv_timings,
200 if (v4l2_match_dv_timings(timings, ¤t_timings, 0, false))
203 @@ -2457,12 +2455,6 @@ static int register_node(struct unicam_d
204 unicam_err(unicam, "Unable to allocate dummy buffer.\n");
208 - if (pad_id == METADATA_PAD) {
209 - v4l2_disable_ioctl(vdev, VIDIOC_DQEVENT);
210 - v4l2_disable_ioctl(vdev, VIDIOC_SUBSCRIBE_EVENT);
211 - v4l2_disable_ioctl(vdev, VIDIOC_UNSUBSCRIBE_EVENT);
213 if (pad_id == METADATA_PAD ||
214 !v4l2_subdev_has_op(unicam->sensor, video, s_std)) {
215 v4l2_disable_ioctl(&node->video_dev, VIDIOC_S_STD);