aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-02-05 15:46:38 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-02-05 15:46:38 -0500
commitdd6f86af394160f01f8b6c5349752b63b9e95fcb (patch)
tree0dfaec75a5ea67bcbe1f9ad32658653ef912527d
parentea5a273c76f8ba3569705362b00c7d94fb92468e (diff)
parentac75fe5d8fe4a0bf063be18fb29684405279e79e (diff)
Merge tag 'media/v4.5-3' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media fixes from Mauro Carvalho Chehab: - vb2: fix a vb2_thread regression and DVB read() breakages - vsp1: fix compilation and links creation - s5k6a3: Fix VIDIOC_SUBDEV_G_FMT ioctl for TRY format - exynos4-is: fix a build issue, format negotiation and sensor detection - Fix a regression with pvrusb2 and ir-kbd-i2c - atmel-isi: fix debug message which only show the first format - tda1004x: fix a tuning bug if G_PROPERTY is called too early - saa7134-alsa: fix a bug at device unbinding/driver removal - Fix build of one driver if !HAS_DMA - soc_camera: cleanup control device on async_unbind * tag 'media/v4.5-3' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: [media] saa7134-alsa: Only frees registered sound cards [media] vb2-core: call threadio->fnc() if !VB2_BUF_STATE_ERROR [media] vb2: fix nasty vb2_thread regression [media] tda1004x: only update the frontend properties if locked [media] media: i2c: Don't export ir-kbd-i2c module alias [media] exynos4-is: make VIDEO_SAMSUNG_EXYNOS4_IS tristate [media] media: Kconfig: add dependency of HAS_DMA [media] exynos4-is: Wait for 100us before opening sensor [media] exynos4-is: Open shouldn't fail when sensor entity is not linked [media] s5k6a3: Fix VIDIOC_SUBDEV_G_FMT ioctl for TRY format [media] exynos4-is: fix a format string bug [media] drivers/media: vsp1_video: fix compile error [media] atmel-isi: fix debug message which only show the first format [media] soc_camera: cleanup control device on async_unbind [media] v4l: vsp1: Fix wrong entities links creation
-rw-r--r--drivers/media/dvb-frontends/tda1004x.c9
-rw-r--r--drivers/media/i2c/ir-kbd-i2c.c1
-rw-r--r--drivers/media/i2c/s5k6a3.c3
-rw-r--r--drivers/media/pci/saa7134/saa7134-alsa.c5
-rw-r--r--drivers/media/platform/Kconfig1
-rw-r--r--drivers/media/platform/exynos4-is/Kconfig2
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is.c6
-rw-r--r--drivers/media/platform/exynos4-is/fimc-isp-video.c4
-rw-r--r--drivers/media/platform/exynos4-is/media-dev.c95
-rw-r--r--drivers/media/platform/soc_camera/atmel-isi.c2
-rw-r--r--drivers/media/platform/soc_camera/soc_camera.c2
-rw-r--r--drivers/media/platform/vsp1/vsp1_drv.c7
-rw-r--r--drivers/media/platform/vsp1/vsp1_video.c2
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c95
-rw-r--r--drivers/media/v4l2-core/videobuf2-v4l2.c2
-rw-r--r--include/media/videobuf2-core.h3
16 files changed, 155 insertions, 84 deletions
diff --git a/drivers/media/dvb-frontends/tda1004x.c b/drivers/media/dvb-frontends/tda1004x.c
index 0e209b56c76c..c6abeb4fba9d 100644
--- a/drivers/media/dvb-frontends/tda1004x.c
+++ b/drivers/media/dvb-frontends/tda1004x.c
@@ -903,9 +903,18 @@ static int tda1004x_get_fe(struct dvb_frontend *fe)
903{ 903{
904 struct dtv_frontend_properties *fe_params = &fe->dtv_property_cache; 904 struct dtv_frontend_properties *fe_params = &fe->dtv_property_cache;
905 struct tda1004x_state* state = fe->demodulator_priv; 905 struct tda1004x_state* state = fe->demodulator_priv;
906 int status;
906 907
907 dprintk("%s\n", __func__); 908 dprintk("%s\n", __func__);
908 909
910 status = tda1004x_read_byte(state, TDA1004X_STATUS_CD);
911 if (status == -1)
912 return -EIO;
913
914 /* Only update the properties cache if device is locked */
915 if (!(status & 8))
916 return 0;
917
909 // inversion status 918 // inversion status
910 fe_params->inversion = INVERSION_OFF; 919 fe_params->inversion = INVERSION_OFF;
911 if (tda1004x_read_byte(state, TDA1004X_CONFC1) & 0x20) 920 if (tda1004x_read_byte(state, TDA1004X_CONFC1) & 0x20)
diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 830491960add..bf82726fd3f4 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -478,7 +478,6 @@ static const struct i2c_device_id ir_kbd_id[] = {
478 { "ir_rx_z8f0811_hdpvr", 0 }, 478 { "ir_rx_z8f0811_hdpvr", 0 },
479 { } 479 { }
480}; 480};
481MODULE_DEVICE_TABLE(i2c, ir_kbd_id);
482 481
483static struct i2c_driver ir_kbd_driver = { 482static struct i2c_driver ir_kbd_driver = {
484 .driver = { 483 .driver = {
diff --git a/drivers/media/i2c/s5k6a3.c b/drivers/media/i2c/s5k6a3.c
index b9e43ffa5085..cbe4711e9b31 100644
--- a/drivers/media/i2c/s5k6a3.c
+++ b/drivers/media/i2c/s5k6a3.c
@@ -144,8 +144,7 @@ static int s5k6a3_set_fmt(struct v4l2_subdev *sd,
144 mf = __s5k6a3_get_format(sensor, cfg, fmt->pad, fmt->which); 144 mf = __s5k6a3_get_format(sensor, cfg, fmt->pad, fmt->which);
145 if (mf) { 145 if (mf) {
146 mutex_lock(&sensor->lock); 146 mutex_lock(&sensor->lock);
147 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) 147 *mf = fmt->format;
148 *mf = fmt->format;
149 mutex_unlock(&sensor->lock); 148 mutex_unlock(&sensor->lock);
150 } 149 }
151 return 0; 150 return 0;
diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
index 1d2c310ce838..94f816244407 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -1211,6 +1211,8 @@ static int alsa_device_init(struct saa7134_dev *dev)
1211 1211
1212static int alsa_device_exit(struct saa7134_dev *dev) 1212static int alsa_device_exit(struct saa7134_dev *dev)
1213{ 1213{
1214 if (!snd_saa7134_cards[dev->nr])
1215 return 1;
1214 1216
1215 snd_card_free(snd_saa7134_cards[dev->nr]); 1217 snd_card_free(snd_saa7134_cards[dev->nr]);
1216 snd_saa7134_cards[dev->nr] = NULL; 1218 snd_saa7134_cards[dev->nr] = NULL;
@@ -1260,7 +1262,8 @@ static void saa7134_alsa_exit(void)
1260 int idx; 1262 int idx;
1261 1263
1262 for (idx = 0; idx < SNDRV_CARDS; idx++) { 1264 for (idx = 0; idx < SNDRV_CARDS; idx++) {
1263 snd_card_free(snd_saa7134_cards[idx]); 1265 if (snd_saa7134_cards[idx])
1266 snd_card_free(snd_saa7134_cards[idx]);
1264 } 1267 }
1265 1268
1266 saa7134_dmasound_init = NULL; 1269 saa7134_dmasound_init = NULL;
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 526359447ff9..8b89ebe16d94 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -215,6 +215,7 @@ config VIDEO_SAMSUNG_EXYNOS_GSC
215config VIDEO_STI_BDISP 215config VIDEO_STI_BDISP
216 tristate "STMicroelectronics BDISP 2D blitter driver" 216 tristate "STMicroelectronics BDISP 2D blitter driver"
217 depends on VIDEO_DEV && VIDEO_V4L2 217 depends on VIDEO_DEV && VIDEO_V4L2
218 depends on HAS_DMA
218 depends on ARCH_STI || COMPILE_TEST 219 depends on ARCH_STI || COMPILE_TEST
219 select VIDEOBUF2_DMA_CONTIG 220 select VIDEOBUF2_DMA_CONTIG
220 select V4L2_MEM2MEM_DEV 221 select V4L2_MEM2MEM_DEV
diff --git a/drivers/media/platform/exynos4-is/Kconfig b/drivers/media/platform/exynos4-is/Kconfig
index 40423c6c5324..57d42c6172c5 100644
--- a/drivers/media/platform/exynos4-is/Kconfig
+++ b/drivers/media/platform/exynos4-is/Kconfig
@@ -1,6 +1,6 @@
1 1
2config VIDEO_SAMSUNG_EXYNOS4_IS 2config VIDEO_SAMSUNG_EXYNOS4_IS
3 bool "Samsung S5P/EXYNOS4 SoC series Camera Subsystem driver" 3 tristate "Samsung S5P/EXYNOS4 SoC series Camera Subsystem driver"
4 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API 4 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
5 depends on ARCH_S5PV210 || ARCH_EXYNOS || COMPILE_TEST 5 depends on ARCH_S5PV210 || ARCH_EXYNOS || COMPILE_TEST
6 depends on OF && COMMON_CLK 6 depends on OF && COMMON_CLK
diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
index 49658ca39e51..979c388ebf60 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -631,6 +631,12 @@ static int fimc_is_hw_open_sensor(struct fimc_is *is,
631 631
632 fimc_is_mem_barrier(); 632 fimc_is_mem_barrier();
633 633
634 /*
635 * Some user space use cases hang up here without this
636 * empirically chosen delay.
637 */
638 udelay(100);
639
634 mcuctl_write(HIC_OPEN_SENSOR, is, MCUCTL_REG_ISSR(0)); 640 mcuctl_write(HIC_OPEN_SENSOR, is, MCUCTL_REG_ISSR(0));
635 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1)); 641 mcuctl_write(is->sensor_index, is, MCUCTL_REG_ISSR(1));
636 mcuctl_write(sensor->drvdata->id, is, MCUCTL_REG_ISSR(2)); 642 mcuctl_write(sensor->drvdata->id, is, MCUCTL_REG_ISSR(2));
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index bf9261eb57a1..c0816728cbfe 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -218,8 +218,8 @@ static void isp_video_capture_buffer_queue(struct vb2_buffer *vb)
218 ivb->dma_addr[i]; 218 ivb->dma_addr[i];
219 219
220 isp_dbg(2, &video->ve.vdev, 220 isp_dbg(2, &video->ve.vdev,
221 "dma_buf %pad (%d/%d/%d) addr: %pad\n", 221 "dma_buf %d (%d/%d/%d) addr: %pad\n",
222 &buf_index, ivb->index, i, vb->index, 222 buf_index, ivb->index, i, vb->index,
223 &ivb->dma_addr[i]); 223 &ivb->dma_addr[i]);
224 } 224 }
225 225
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index f3b2dd30ec77..e79ddbb1e14f 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -186,6 +186,37 @@ error:
186} 186}
187 187
188/** 188/**
189 * __fimc_pipeline_enable - enable power of all pipeline subdevs
190 * and the sensor clock
191 * @ep: video pipeline structure
192 * @fmd: fimc media device
193 *
194 * Called with the graph mutex held.
195 */
196static int __fimc_pipeline_enable(struct exynos_media_pipeline *ep,
197 struct fimc_md *fmd)
198{
199 struct fimc_pipeline *p = to_fimc_pipeline(ep);
200 int ret;
201
202 /* Enable PXLASYNC clock if this pipeline includes FIMC-IS */
203 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) {
204 ret = clk_prepare_enable(fmd->wbclk[CLK_IDX_WB_B]);
205 if (ret < 0)
206 return ret;
207 }
208
209 ret = fimc_pipeline_s_power(p, 1);
210 if (!ret)
211 return 0;
212
213 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP])
214 clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]);
215
216 return ret;
217}
218
219/**
189 * __fimc_pipeline_open - update the pipeline information, enable power 220 * __fimc_pipeline_open - update the pipeline information, enable power
190 * of all pipeline subdevs and the sensor clock 221 * of all pipeline subdevs and the sensor clock
191 * @me: media entity to start graph walk with 222 * @me: media entity to start graph walk with
@@ -199,7 +230,6 @@ static int __fimc_pipeline_open(struct exynos_media_pipeline *ep,
199 struct fimc_md *fmd = entity_to_fimc_mdev(me); 230 struct fimc_md *fmd = entity_to_fimc_mdev(me);
200 struct fimc_pipeline *p = to_fimc_pipeline(ep); 231 struct fimc_pipeline *p = to_fimc_pipeline(ep);
201 struct v4l2_subdev *sd; 232 struct v4l2_subdev *sd;
202 int ret;
203 233
204 if (WARN_ON(p == NULL || me == NULL)) 234 if (WARN_ON(p == NULL || me == NULL))
205 return -EINVAL; 235 return -EINVAL;
@@ -208,24 +238,16 @@ static int __fimc_pipeline_open(struct exynos_media_pipeline *ep,
208 fimc_pipeline_prepare(p, me); 238 fimc_pipeline_prepare(p, me);
209 239
210 sd = p->subdevs[IDX_SENSOR]; 240 sd = p->subdevs[IDX_SENSOR];
211 if (sd == NULL) 241 if (sd == NULL) {
212 return -EINVAL; 242 pr_warn("%s(): No sensor subdev\n", __func__);
213 243 /*
214 /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */ 244 * Pipeline open cannot fail so as to make it possible
215 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) { 245 * for the user space to configure the pipeline.
216 ret = clk_prepare_enable(fmd->wbclk[CLK_IDX_WB_B]); 246 */
217 if (ret < 0)
218 return ret;
219 }
220
221 ret = fimc_pipeline_s_power(p, 1);
222 if (!ret)
223 return 0; 247 return 0;
248 }
224 249
225 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) 250 return __fimc_pipeline_enable(ep, fmd);
226 clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]);
227
228 return ret;
229} 251}
230 252
231/** 253/**
@@ -269,10 +291,43 @@ static int __fimc_pipeline_s_stream(struct exynos_media_pipeline *ep, bool on)
269 { IDX_CSIS, IDX_FLITE, IDX_FIMC, IDX_SENSOR, IDX_IS_ISP }, 291 { IDX_CSIS, IDX_FLITE, IDX_FIMC, IDX_SENSOR, IDX_IS_ISP },
270 }; 292 };
271 struct fimc_pipeline *p = to_fimc_pipeline(ep); 293 struct fimc_pipeline *p = to_fimc_pipeline(ep);
294 struct fimc_md *fmd = entity_to_fimc_mdev(&p->subdevs[IDX_CSIS]->entity);
295 enum fimc_subdev_index sd_id;
272 int i, ret = 0; 296 int i, ret = 0;
273 297
274 if (p->subdevs[IDX_SENSOR] == NULL) 298 if (p->subdevs[IDX_SENSOR] == NULL) {
275 return -ENODEV; 299 if (!fmd->user_subdev_api) {
300 /*
301 * Sensor must be already discovered if we
302 * aren't in the user_subdev_api mode
303 */
304 return -ENODEV;
305 }
306
307 /* Get pipeline sink entity */
308 if (p->subdevs[IDX_FIMC])
309 sd_id = IDX_FIMC;
310 else if (p->subdevs[IDX_IS_ISP])
311 sd_id = IDX_IS_ISP;
312 else if (p->subdevs[IDX_FLITE])
313 sd_id = IDX_FLITE;
314 else
315 return -ENODEV;
316
317 /*
318 * Sensor could have been linked between open and STREAMON -
319 * check if this is the case.
320 */
321 fimc_pipeline_prepare(p, &p->subdevs[sd_id]->entity);
322
323 if (p->subdevs[IDX_SENSOR] == NULL)
324 return -ENODEV;
325
326 ret = __fimc_pipeline_enable(ep, fmd);
327 if (ret < 0)
328 return ret;
329
330 }
276 331
277 for (i = 0; i < IDX_MAX; i++) { 332 for (i = 0; i < IDX_MAX; i++) {
278 unsigned int idx = seq[on][i]; 333 unsigned int idx = seq[on][i];
@@ -282,8 +337,10 @@ static int __fimc_pipeline_s_stream(struct exynos_media_pipeline *ep, bool on)
282 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) 337 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
283 goto error; 338 goto error;
284 } 339 }
340
285 return 0; 341 return 0;
286error: 342error:
343 fimc_pipeline_s_power(p, !on);
287 for (; i >= 0; i--) { 344 for (; i >= 0; i--) {
288 unsigned int idx = seq[on][i]; 345 unsigned int idx = seq[on][i];
289 v4l2_subdev_call(p->subdevs[idx], video, s_stream, !on); 346 v4l2_subdev_call(p->subdevs[idx], video, s_stream, !on);
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index c398b285180c..1af779ee3c74 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -795,7 +795,7 @@ static int isi_camera_get_formats(struct soc_camera_device *icd,
795 xlate->host_fmt = &isi_camera_formats[i]; 795 xlate->host_fmt = &isi_camera_formats[i];
796 xlate->code = code.code; 796 xlate->code = code.code;
797 dev_dbg(icd->parent, "Providing format %s using code %d\n", 797 dev_dbg(icd->parent, "Providing format %s using code %d\n",
798 isi_camera_formats[0].name, code.code); 798 xlate->host_fmt->name, xlate->code);
799 } 799 }
800 break; 800 break;
801 default: 801 default:
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index cc84c6d6a701..46c7186f7867 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -1493,6 +1493,8 @@ static void soc_camera_async_unbind(struct v4l2_async_notifier *notifier,
1493 struct soc_camera_async_client, notifier); 1493 struct soc_camera_async_client, notifier);
1494 struct soc_camera_device *icd = platform_get_drvdata(sasc->pdev); 1494 struct soc_camera_device *icd = platform_get_drvdata(sasc->pdev);
1495 1495
1496 icd->control = NULL;
1497
1496 if (icd->clk) { 1498 if (icd->clk) {
1497 v4l2_clk_unregister(icd->clk); 1499 v4l2_clk_unregister(icd->clk);
1498 icd->clk = NULL; 1500 icd->clk = NULL;
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 42dff9d020af..533bc796391e 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -256,7 +256,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
256 256
257 /* Create links. */ 257 /* Create links. */
258 list_for_each_entry(entity, &vsp1->entities, list_dev) { 258 list_for_each_entry(entity, &vsp1->entities, list_dev) {
259 if (entity->type == VSP1_ENTITY_LIF) { 259 if (entity->type == VSP1_ENTITY_WPF) {
260 ret = vsp1_wpf_create_links(vsp1, entity); 260 ret = vsp1_wpf_create_links(vsp1, entity);
261 if (ret < 0) 261 if (ret < 0)
262 goto done; 262 goto done;
@@ -264,7 +264,10 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
264 ret = vsp1_rpf_create_links(vsp1, entity); 264 ret = vsp1_rpf_create_links(vsp1, entity);
265 if (ret < 0) 265 if (ret < 0)
266 goto done; 266 goto done;
267 } else { 267 }
268
269 if (entity->type != VSP1_ENTITY_LIF &&
270 entity->type != VSP1_ENTITY_RPF) {
268 ret = vsp1_create_links(vsp1, entity); 271 ret = vsp1_create_links(vsp1, entity);
269 if (ret < 0) 272 if (ret < 0)
270 goto done; 273 goto done;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 637d0d6f79fb..b4dca57d1ae3 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -515,7 +515,7 @@ static bool vsp1_pipeline_stopped(struct vsp1_pipeline *pipe)
515 bool stopped; 515 bool stopped;
516 516
517 spin_lock_irqsave(&pipe->irqlock, flags); 517 spin_lock_irqsave(&pipe->irqlock, flags);
518 stopped = pipe->state == VSP1_PIPELINE_STOPPED, 518 stopped = pipe->state == VSP1_PIPELINE_STOPPED;
519 spin_unlock_irqrestore(&pipe->irqlock, flags); 519 spin_unlock_irqrestore(&pipe->irqlock, flags);
520 520
521 return stopped; 521 return stopped;
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index c5d49d7a0d76..ff8953ae52d1 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1063,8 +1063,11 @@ EXPORT_SYMBOL_GPL(vb2_discard_done);
1063 */ 1063 */
1064static int __qbuf_mmap(struct vb2_buffer *vb, const void *pb) 1064static int __qbuf_mmap(struct vb2_buffer *vb, const void *pb)
1065{ 1065{
1066 int ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, 1066 int ret = 0;
1067 vb, pb, vb->planes); 1067
1068 if (pb)
1069 ret = call_bufop(vb->vb2_queue, fill_vb2_buffer,
1070 vb, pb, vb->planes);
1068 return ret ? ret : call_vb_qop(vb, buf_prepare, vb); 1071 return ret ? ret : call_vb_qop(vb, buf_prepare, vb);
1069} 1072}
1070 1073
@@ -1077,14 +1080,16 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const void *pb)
1077 struct vb2_queue *q = vb->vb2_queue; 1080 struct vb2_queue *q = vb->vb2_queue;
1078 void *mem_priv; 1081 void *mem_priv;
1079 unsigned int plane; 1082 unsigned int plane;
1080 int ret; 1083 int ret = 0;
1081 enum dma_data_direction dma_dir = 1084 enum dma_data_direction dma_dir =
1082 q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE; 1085 q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
1083 bool reacquired = vb->planes[0].mem_priv == NULL; 1086 bool reacquired = vb->planes[0].mem_priv == NULL;
1084 1087
1085 memset(planes, 0, sizeof(planes[0]) * vb->num_planes); 1088 memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
1086 /* Copy relevant information provided by the userspace */ 1089 /* Copy relevant information provided by the userspace */
1087 ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, vb, pb, planes); 1090 if (pb)
1091 ret = call_bufop(vb->vb2_queue, fill_vb2_buffer,
1092 vb, pb, planes);
1088 if (ret) 1093 if (ret)
1089 return ret; 1094 return ret;
1090 1095
@@ -1192,14 +1197,16 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const void *pb)
1192 struct vb2_queue *q = vb->vb2_queue; 1197 struct vb2_queue *q = vb->vb2_queue;
1193 void *mem_priv; 1198 void *mem_priv;
1194 unsigned int plane; 1199 unsigned int plane;
1195 int ret; 1200 int ret = 0;
1196 enum dma_data_direction dma_dir = 1201 enum dma_data_direction dma_dir =
1197 q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE; 1202 q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
1198 bool reacquired = vb->planes[0].mem_priv == NULL; 1203 bool reacquired = vb->planes[0].mem_priv == NULL;
1199 1204
1200 memset(planes, 0, sizeof(planes[0]) * vb->num_planes); 1205 memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
1201 /* Copy relevant information provided by the userspace */ 1206 /* Copy relevant information provided by the userspace */
1202 ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, vb, pb, planes); 1207 if (pb)
1208 ret = call_bufop(vb->vb2_queue, fill_vb2_buffer,
1209 vb, pb, planes);
1203 if (ret) 1210 if (ret)
1204 return ret; 1211 return ret;
1205 1212
@@ -1520,7 +1527,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb)
1520 q->waiting_for_buffers = false; 1527 q->waiting_for_buffers = false;
1521 vb->state = VB2_BUF_STATE_QUEUED; 1528 vb->state = VB2_BUF_STATE_QUEUED;
1522 1529
1523 call_void_bufop(q, copy_timestamp, vb, pb); 1530 if (pb)
1531 call_void_bufop(q, copy_timestamp, vb, pb);
1524 1532
1525 trace_vb2_qbuf(q, vb); 1533 trace_vb2_qbuf(q, vb);
1526 1534
@@ -1532,7 +1540,8 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb)
1532 __enqueue_in_driver(vb); 1540 __enqueue_in_driver(vb);
1533 1541
1534 /* Fill buffer information for the userspace */ 1542 /* Fill buffer information for the userspace */
1535 call_void_bufop(q, fill_user_buffer, vb, pb); 1543 if (pb)
1544 call_void_bufop(q, fill_user_buffer, vb, pb);
1536 1545
1537 /* 1546 /*
1538 * If streamon has been called, and we haven't yet called 1547 * If streamon has been called, and we haven't yet called
@@ -1731,7 +1740,8 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
1731 * The return values from this function are intended to be directly returned 1740 * The return values from this function are intended to be directly returned
1732 * from vidioc_dqbuf handler in driver. 1741 * from vidioc_dqbuf handler in driver.
1733 */ 1742 */
1734int vb2_core_dqbuf(struct vb2_queue *q, void *pb, bool nonblocking) 1743int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,
1744 bool nonblocking)
1735{ 1745{
1736 struct vb2_buffer *vb = NULL; 1746 struct vb2_buffer *vb = NULL;
1737 int ret; 1747 int ret;
@@ -1754,8 +1764,12 @@ int vb2_core_dqbuf(struct vb2_queue *q, void *pb, bool nonblocking)
1754 1764
1755 call_void_vb_qop(vb, buf_finish, vb); 1765 call_void_vb_qop(vb, buf_finish, vb);
1756 1766
1767 if (pindex)
1768 *pindex = vb->index;
1769
1757 /* Fill buffer information for the userspace */ 1770 /* Fill buffer information for the userspace */
1758 call_void_bufop(q, fill_user_buffer, vb, pb); 1771 if (pb)
1772 call_void_bufop(q, fill_user_buffer, vb, pb);
1759 1773
1760 /* Remove from videobuf queue */ 1774 /* Remove from videobuf queue */
1761 list_del(&vb->queued_entry); 1775 list_del(&vb->queued_entry);
@@ -1828,7 +1842,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
1828 * that's done in dqbuf, but that's not going to happen when we 1842 * that's done in dqbuf, but that's not going to happen when we
1829 * cancel the whole queue. Note: this code belongs here, not in 1843 * cancel the whole queue. Note: this code belongs here, not in
1830 * __vb2_dqbuf() since in vb2_internal_dqbuf() there is a critical 1844 * __vb2_dqbuf() since in vb2_internal_dqbuf() there is a critical
1831 * call to __fill_v4l2_buffer() after buf_finish(). That order can't 1845 * call to __fill_user_buffer() after buf_finish(). That order can't
1832 * be changed, so we can't move the buf_finish() to __vb2_dqbuf(). 1846 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
1833 */ 1847 */
1834 for (i = 0; i < q->num_buffers; ++i) { 1848 for (i = 0; i < q->num_buffers; ++i) {
@@ -2357,7 +2371,6 @@ struct vb2_fileio_data {
2357 unsigned int count; 2371 unsigned int count;
2358 unsigned int type; 2372 unsigned int type;
2359 unsigned int memory; 2373 unsigned int memory;
2360 struct vb2_buffer *b;
2361 struct vb2_fileio_buf bufs[VB2_MAX_FRAME]; 2374 struct vb2_fileio_buf bufs[VB2_MAX_FRAME];
2362 unsigned int cur_index; 2375 unsigned int cur_index;
2363 unsigned int initial_index; 2376 unsigned int initial_index;
@@ -2410,12 +2423,6 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
2410 if (fileio == NULL) 2423 if (fileio == NULL)
2411 return -ENOMEM; 2424 return -ENOMEM;
2412 2425
2413 fileio->b = kzalloc(q->buf_struct_size, GFP_KERNEL);
2414 if (fileio->b == NULL) {
2415 kfree(fileio);
2416 return -ENOMEM;
2417 }
2418
2419 fileio->read_once = q->fileio_read_once; 2426 fileio->read_once = q->fileio_read_once;
2420 fileio->write_immediately = q->fileio_write_immediately; 2427 fileio->write_immediately = q->fileio_write_immediately;
2421 2428
@@ -2460,13 +2467,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
2460 * Queue all buffers. 2467 * Queue all buffers.
2461 */ 2468 */
2462 for (i = 0; i < q->num_buffers; i++) { 2469 for (i = 0; i < q->num_buffers; i++) {
2463 struct vb2_buffer *b = fileio->b; 2470 ret = vb2_core_qbuf(q, i, NULL);
2464
2465 memset(b, 0, q->buf_struct_size);
2466 b->type = q->type;
2467 b->memory = q->memory;
2468 b->index = i;
2469 ret = vb2_core_qbuf(q, i, b);
2470 if (ret) 2471 if (ret)
2471 goto err_reqbufs; 2472 goto err_reqbufs;
2472 fileio->bufs[i].queued = 1; 2473 fileio->bufs[i].queued = 1;
@@ -2511,7 +2512,6 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q)
2511 q->fileio = NULL; 2512 q->fileio = NULL;
2512 fileio->count = 0; 2513 fileio->count = 0;
2513 vb2_core_reqbufs(q, fileio->memory, &fileio->count); 2514 vb2_core_reqbufs(q, fileio->memory, &fileio->count);
2514 kfree(fileio->b);
2515 kfree(fileio); 2515 kfree(fileio);
2516 dprintk(3, "file io emulator closed\n"); 2516 dprintk(3, "file io emulator closed\n");
2517 } 2517 }
@@ -2539,7 +2539,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
2539 * else is able to provide this information with the write() operation. 2539 * else is able to provide this information with the write() operation.
2540 */ 2540 */
2541 bool copy_timestamp = !read && q->copy_timestamp; 2541 bool copy_timestamp = !read && q->copy_timestamp;
2542 int ret, index; 2542 unsigned index;
2543 int ret;
2543 2544
2544 dprintk(3, "mode %s, offset %ld, count %zd, %sblocking\n", 2545 dprintk(3, "mode %s, offset %ld, count %zd, %sblocking\n",
2545 read ? "read" : "write", (long)*ppos, count, 2546 read ? "read" : "write", (long)*ppos, count,
@@ -2564,22 +2565,20 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
2564 */ 2565 */
2565 index = fileio->cur_index; 2566 index = fileio->cur_index;
2566 if (index >= q->num_buffers) { 2567 if (index >= q->num_buffers) {
2567 struct vb2_buffer *b = fileio->b; 2568 struct vb2_buffer *b;
2568 2569
2569 /* 2570 /*
2570 * Call vb2_dqbuf to get buffer back. 2571 * Call vb2_dqbuf to get buffer back.
2571 */ 2572 */
2572 memset(b, 0, q->buf_struct_size); 2573 ret = vb2_core_dqbuf(q, &index, NULL, nonblock);
2573 b->type = q->type;
2574 b->memory = q->memory;
2575 ret = vb2_core_dqbuf(q, b, nonblock);
2576 dprintk(5, "vb2_dqbuf result: %d\n", ret); 2574 dprintk(5, "vb2_dqbuf result: %d\n", ret);
2577 if (ret) 2575 if (ret)
2578 return ret; 2576 return ret;
2579 fileio->dq_count += 1; 2577 fileio->dq_count += 1;
2580 2578
2581 fileio->cur_index = index = b->index; 2579 fileio->cur_index = index;
2582 buf = &fileio->bufs[index]; 2580 buf = &fileio->bufs[index];
2581 b = q->bufs[index];
2583 2582
2584 /* 2583 /*
2585 * Get number of bytes filled by the driver 2584 * Get number of bytes filled by the driver
@@ -2630,7 +2629,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
2630 * Queue next buffer if required. 2629 * Queue next buffer if required.
2631 */ 2630 */
2632 if (buf->pos == buf->size || (!read && fileio->write_immediately)) { 2631 if (buf->pos == buf->size || (!read && fileio->write_immediately)) {
2633 struct vb2_buffer *b = fileio->b; 2632 struct vb2_buffer *b = q->bufs[index];
2634 2633
2635 /* 2634 /*
2636 * Check if this is the last buffer to read. 2635 * Check if this is the last buffer to read.
@@ -2643,15 +2642,11 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
2643 /* 2642 /*
2644 * Call vb2_qbuf and give buffer to the driver. 2643 * Call vb2_qbuf and give buffer to the driver.
2645 */ 2644 */
2646 memset(b, 0, q->buf_struct_size);
2647 b->type = q->type;
2648 b->memory = q->memory;
2649 b->index = index;
2650 b->planes[0].bytesused = buf->pos; 2645 b->planes[0].bytesused = buf->pos;
2651 2646
2652 if (copy_timestamp) 2647 if (copy_timestamp)
2653 b->timestamp = ktime_get_ns(); 2648 b->timestamp = ktime_get_ns();
2654 ret = vb2_core_qbuf(q, index, b); 2649 ret = vb2_core_qbuf(q, index, NULL);
2655 dprintk(5, "vb2_dbuf result: %d\n", ret); 2650 dprintk(5, "vb2_dbuf result: %d\n", ret);
2656 if (ret) 2651 if (ret)
2657 return ret; 2652 return ret;
@@ -2713,10 +2708,9 @@ static int vb2_thread(void *data)
2713{ 2708{
2714 struct vb2_queue *q = data; 2709 struct vb2_queue *q = data;
2715 struct vb2_threadio_data *threadio = q->threadio; 2710 struct vb2_threadio_data *threadio = q->threadio;
2716 struct vb2_fileio_data *fileio = q->fileio;
2717 bool copy_timestamp = false; 2711 bool copy_timestamp = false;
2718 int prequeue = 0; 2712 unsigned prequeue = 0;
2719 int index = 0; 2713 unsigned index = 0;
2720 int ret = 0; 2714 int ret = 0;
2721 2715
2722 if (q->is_output) { 2716 if (q->is_output) {
@@ -2728,37 +2722,34 @@ static int vb2_thread(void *data)
2728 2722
2729 for (;;) { 2723 for (;;) {
2730 struct vb2_buffer *vb; 2724 struct vb2_buffer *vb;
2731 struct vb2_buffer *b = fileio->b;
2732 2725
2733 /* 2726 /*
2734 * Call vb2_dqbuf to get buffer back. 2727 * Call vb2_dqbuf to get buffer back.
2735 */ 2728 */
2736 memset(b, 0, q->buf_struct_size);
2737 b->type = q->type;
2738 b->memory = q->memory;
2739 if (prequeue) { 2729 if (prequeue) {
2740 b->index = index++; 2730 vb = q->bufs[index++];
2741 prequeue--; 2731 prequeue--;
2742 } else { 2732 } else {
2743 call_void_qop(q, wait_finish, q); 2733 call_void_qop(q, wait_finish, q);
2744 if (!threadio->stop) 2734 if (!threadio->stop)
2745 ret = vb2_core_dqbuf(q, b, 0); 2735 ret = vb2_core_dqbuf(q, &index, NULL, 0);
2746 call_void_qop(q, wait_prepare, q); 2736 call_void_qop(q, wait_prepare, q);
2747 dprintk(5, "file io: vb2_dqbuf result: %d\n", ret); 2737 dprintk(5, "file io: vb2_dqbuf result: %d\n", ret);
2738 if (!ret)
2739 vb = q->bufs[index];
2748 } 2740 }
2749 if (ret || threadio->stop) 2741 if (ret || threadio->stop)
2750 break; 2742 break;
2751 try_to_freeze(); 2743 try_to_freeze();
2752 2744
2753 vb = q->bufs[b->index]; 2745 if (vb->state != VB2_BUF_STATE_ERROR)
2754 if (b->state == VB2_BUF_STATE_DONE)
2755 if (threadio->fnc(vb, threadio->priv)) 2746 if (threadio->fnc(vb, threadio->priv))
2756 break; 2747 break;
2757 call_void_qop(q, wait_finish, q); 2748 call_void_qop(q, wait_finish, q);
2758 if (copy_timestamp) 2749 if (copy_timestamp)
2759 b->timestamp = ktime_get_ns();; 2750 vb->timestamp = ktime_get_ns();;
2760 if (!threadio->stop) 2751 if (!threadio->stop)
2761 ret = vb2_core_qbuf(q, b->index, b); 2752 ret = vb2_core_qbuf(q, vb->index, NULL);
2762 call_void_qop(q, wait_prepare, q); 2753 call_void_qop(q, wait_prepare, q);
2763 if (ret || threadio->stop) 2754 if (ret || threadio->stop)
2764 break; 2755 break;
diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index c9a28605511a..91f552124050 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -625,7 +625,7 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b,
625 return -EINVAL; 625 return -EINVAL;
626 } 626 }
627 627
628 ret = vb2_core_dqbuf(q, b, nonblocking); 628 ret = vb2_core_dqbuf(q, NULL, b, nonblocking);
629 629
630 return ret; 630 return ret;
631} 631}
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index ef03ae56b1c1..8a0f55b6c2ba 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -533,7 +533,8 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
533 const unsigned int requested_sizes[]); 533 const unsigned int requested_sizes[]);
534int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb); 534int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb);
535int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb); 535int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb);
536int vb2_core_dqbuf(struct vb2_queue *q, void *pb, bool nonblocking); 536int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb,
537 bool nonblocking);
537 538
538int vb2_core_streamon(struct vb2_queue *q, unsigned int type); 539int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
539int vb2_core_streamoff(struct vb2_queue *q, unsigned int type); 540int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);