176a3a557f750a246b4fc8899c553ed5ec545fab
[openwrt/staging/jow.git] /
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
5 Hans.
6
7 Updates the driver based on the upstream review comments from
8 Hans Verkuil at https://patchwork.linuxtv.org/patch/63531/
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12 .../media/platform/bcm2835/bcm2835-unicam.c | 70 ++++++++-----------
13 1 file changed, 31 insertions(+), 39 deletions(-)
14
15 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
16 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
17 @@ -1,6 +1,6 @@
18 // SPDX-License-Identifier: GPL-2.0-only
19 /*
20 - * BCM2835 Unicam Capture Driver
21 + * BCM283x / BCM271x Unicam Capture Driver
22 *
23 * Copyright (C) 2017-2020 - Raspberry Pi (Trading) Ltd.
24 *
25 @@ -573,9 +573,8 @@ static const struct unicam_fmt *find_for
26 return NULL;
27 }
28
29 -static inline unsigned int bytes_per_line(u32 width,
30 - const struct unicam_fmt *fmt,
31 - u32 v4l2_fourcc)
32 +static unsigned int bytes_per_line(u32 width, const struct unicam_fmt *fmt,
33 + u32 v4l2_fourcc)
34 {
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
38 }
39 }
40
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)
43 {
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;
48 }
49
50 -static inline void unicam_schedule_next_buffer(struct unicam_node *node)
51 +static void unicam_schedule_next_buffer(struct unicam_node *node)
52 {
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);
57 }
58
59 -static inline void unicam_schedule_dummy_buffer(struct unicam_node *node)
60 +static void unicam_schedule_dummy_buffer(struct unicam_node *node)
61 {
62 struct unicam_device *dev = node->dev;
63
64 @@ -765,8 +764,8 @@ static inline void unicam_schedule_dummy
65 node->next_frm = NULL;
66 }
67
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)
72 {
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);
77 }
78
79 -static bool unicam_all_nodes_streaming(struct unicam_device *dev)
80 -{
81 - bool ret;
82 -
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;
86 - return ret;
87 -}
88 -
89 static void unicam_queue_event_sof(struct unicam_device *unicam)
90 {
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;
95
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));
100
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
104 return 0;
105 }
106
107 -static
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)
111 {
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
115 clk_write(dev, 0);
116 }
117
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)
121 {
122 struct unicam_buffer *buf, *tmp;
123 unsigned long flags;
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);
130 }
131
132 if (node->cur_frm)
133 vb2_buffer_done(&node->cur_frm->vb.vb2_buf,
134 - VB2_BUF_STATE_ERROR);
135 + state);
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);
139 + state);
140
141 node->cur_frm = NULL;
142 node->next_frm = NULL;
143 @@ -1624,7 +1614,13 @@ static int unicam_start_streaming(struct
144 int ret;
145
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))) {
151 + /*
152 + * Metadata pad must be enabled before image pad if it is
153 + * wanted.
154 + */
155 unicam_dbg(3, dev, "Not all nodes are streaming yet.");
156 return 0;
157 }
158 @@ -1728,7 +1724,7 @@ err_vpu_clock:
159 err_pm_put:
160 unicam_runtime_put(dev);
161 err_streaming:
162 - unicam_return_buffers(node);
163 + unicam_return_buffers(node, VB2_BUF_STATE_QUEUED);
164 node->streaming = false;
165
166 return ret;
167 @@ -1773,7 +1769,7 @@ static void unicam_stop_streaming(struct
168 }
169
170 /* Clear all queued buffers for the node */
171 - unicam_return_buffers(node);
172 + unicam_return_buffers(node, VB2_BUF_STATE_ERROR);
173 }
174
175 static int unicam_enum_input(struct file *file, void *priv,
176 @@ -1791,14 +1787,13 @@ static int unicam_enum_input(struct file
177 inp->std = 0;
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)
181 - < 0)
182 + if (v4l2_subdev_call(dev->sensor, video, g_tvnorms, &inp->std) < 0)
183 inp->std = V4L2_STD_ALL;
184 } else {
185 inp->capabilities = 0;
186 inp->std = 0;
187 }
188 - sprintf(inp->name, "Camera 0");
189 + snprintf(inp->name, sizeof(inp->name), "Camera 0");
190 return 0;
191 }
192
193 @@ -2027,6 +2022,9 @@ static int unicam_s_dv_timings(struct fi
194 ret = v4l2_subdev_call(dev->sensor, video, g_dv_timings,
195 &current_timings);
196
197 + if (ret < 0)
198 + return ret;
199 +
200 if (v4l2_match_dv_timings(timings, &current_timings, 0, false))
201 return 0;
202
203 @@ -2457,12 +2455,6 @@ static int register_node(struct unicam_d
204 unicam_err(unicam, "Unable to allocate dummy buffer.\n");
205 return -ENOMEM;
206 }
207 -
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);
212 - }
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);