aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/mx1_camera.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/mx1_camera.c')
-rw-r--r--drivers/media/video/mx1_camera.c78
1 files changed, 41 insertions, 37 deletions
diff --git a/drivers/media/video/mx1_camera.c b/drivers/media/video/mx1_camera.c
index 736c31d23194..5f37952c75cf 100644
--- a/drivers/media/video/mx1_camera.c
+++ b/drivers/media/video/mx1_camera.c
@@ -126,7 +126,7 @@ static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
126{ 126{
127 struct soc_camera_device *icd = vq->priv_data; 127 struct soc_camera_device *icd = vq->priv_data;
128 128
129 *size = icd->width * icd->height * 129 *size = icd->user_width * icd->user_height *
130 ((icd->current_fmt->depth + 7) >> 3); 130 ((icd->current_fmt->depth + 7) >> 3);
131 131
132 if (!*count) 132 if (!*count)
@@ -135,7 +135,7 @@ static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
135 while (*size * *count > MAX_VIDEO_MEM * 1024 * 1024) 135 while (*size * *count > MAX_VIDEO_MEM * 1024 * 1024)
136 (*count)--; 136 (*count)--;
137 137
138 dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size); 138 dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size);
139 139
140 return 0; 140 return 0;
141} 141}
@@ -147,7 +147,7 @@ static void free_buffer(struct videobuf_queue *vq, struct mx1_buffer *buf)
147 147
148 BUG_ON(in_interrupt()); 148 BUG_ON(in_interrupt());
149 149
150 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 150 dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
151 vb, vb->baddr, vb->bsize); 151 vb, vb->baddr, vb->bsize);
152 152
153 /* This waits until this buffer is out of danger, i.e., until it is no 153 /* This waits until this buffer is out of danger, i.e., until it is no
@@ -165,7 +165,7 @@ static int mx1_videobuf_prepare(struct videobuf_queue *vq,
165 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb); 165 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
166 int ret; 166 int ret;
167 167
168 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 168 dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
169 vb, vb->baddr, vb->bsize); 169 vb, vb->baddr, vb->bsize);
170 170
171 /* Added list head initialization on alloc */ 171 /* Added list head initialization on alloc */
@@ -178,12 +178,12 @@ static int mx1_videobuf_prepare(struct videobuf_queue *vq,
178 buf->inwork = 1; 178 buf->inwork = 1;
179 179
180 if (buf->fmt != icd->current_fmt || 180 if (buf->fmt != icd->current_fmt ||
181 vb->width != icd->width || 181 vb->width != icd->user_width ||
182 vb->height != icd->height || 182 vb->height != icd->user_height ||
183 vb->field != field) { 183 vb->field != field) {
184 buf->fmt = icd->current_fmt; 184 buf->fmt = icd->current_fmt;
185 vb->width = icd->width; 185 vb->width = icd->user_width;
186 vb->height = icd->height; 186 vb->height = icd->user_height;
187 vb->field = field; 187 vb->field = field;
188 vb->state = VIDEOBUF_NEEDS_INIT; 188 vb->state = VIDEOBUF_NEEDS_INIT;
189 } 189 }
@@ -216,10 +216,11 @@ out:
216static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev) 216static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
217{ 217{
218 struct videobuf_buffer *vbuf = &pcdev->active->vb; 218 struct videobuf_buffer *vbuf = &pcdev->active->vb;
219 struct device *dev = pcdev->icd->dev.parent;
219 int ret; 220 int ret;
220 221
221 if (unlikely(!pcdev->active)) { 222 if (unlikely(!pcdev->active)) {
222 dev_err(pcdev->soc_host.dev, "DMA End IRQ with no active buffer\n"); 223 dev_err(dev, "DMA End IRQ with no active buffer\n");
223 return -EFAULT; 224 return -EFAULT;
224 } 225 }
225 226
@@ -229,7 +230,7 @@ static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
229 vbuf->size, pcdev->res->start + 230 vbuf->size, pcdev->res->start +
230 CSIRXR, DMA_MODE_READ); 231 CSIRXR, DMA_MODE_READ);
231 if (unlikely(ret)) 232 if (unlikely(ret))
232 dev_err(pcdev->soc_host.dev, "Failed to setup DMA sg list\n"); 233 dev_err(dev, "Failed to setup DMA sg list\n");
233 234
234 return ret; 235 return ret;
235} 236}
@@ -243,7 +244,7 @@ static void mx1_videobuf_queue(struct videobuf_queue *vq,
243 struct mx1_camera_dev *pcdev = ici->priv; 244 struct mx1_camera_dev *pcdev = ici->priv;
244 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb); 245 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
245 246
246 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 247 dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
247 vb, vb->baddr, vb->bsize); 248 vb, vb->baddr, vb->bsize);
248 249
249 list_add_tail(&vb->queue, &pcdev->capture); 250 list_add_tail(&vb->queue, &pcdev->capture);
@@ -270,22 +271,23 @@ static void mx1_videobuf_release(struct videobuf_queue *vq,
270 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb); 271 struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
271#ifdef DEBUG 272#ifdef DEBUG
272 struct soc_camera_device *icd = vq->priv_data; 273 struct soc_camera_device *icd = vq->priv_data;
274 struct device *dev = icd->dev.parent;
273 275
274 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 276 dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
275 vb, vb->baddr, vb->bsize); 277 vb, vb->baddr, vb->bsize);
276 278
277 switch (vb->state) { 279 switch (vb->state) {
278 case VIDEOBUF_ACTIVE: 280 case VIDEOBUF_ACTIVE:
279 dev_dbg(&icd->dev, "%s (active)\n", __func__); 281 dev_dbg(dev, "%s (active)\n", __func__);
280 break; 282 break;
281 case VIDEOBUF_QUEUED: 283 case VIDEOBUF_QUEUED:
282 dev_dbg(&icd->dev, "%s (queued)\n", __func__); 284 dev_dbg(dev, "%s (queued)\n", __func__);
283 break; 285 break;
284 case VIDEOBUF_PREPARED: 286 case VIDEOBUF_PREPARED:
285 dev_dbg(&icd->dev, "%s (prepared)\n", __func__); 287 dev_dbg(dev, "%s (prepared)\n", __func__);
286 break; 288 break;
287 default: 289 default:
288 dev_dbg(&icd->dev, "%s (unknown)\n", __func__); 290 dev_dbg(dev, "%s (unknown)\n", __func__);
289 break; 291 break;
290 } 292 }
291#endif 293#endif
@@ -325,6 +327,7 @@ static void mx1_camera_wakeup(struct mx1_camera_dev *pcdev,
325static void mx1_camera_dma_irq(int channel, void *data) 327static void mx1_camera_dma_irq(int channel, void *data)
326{ 328{
327 struct mx1_camera_dev *pcdev = data; 329 struct mx1_camera_dev *pcdev = data;
330 struct device *dev = pcdev->icd->dev.parent;
328 struct mx1_buffer *buf; 331 struct mx1_buffer *buf;
329 struct videobuf_buffer *vb; 332 struct videobuf_buffer *vb;
330 unsigned long flags; 333 unsigned long flags;
@@ -334,14 +337,14 @@ static void mx1_camera_dma_irq(int channel, void *data)
334 imx_dma_disable(channel); 337 imx_dma_disable(channel);
335 338
336 if (unlikely(!pcdev->active)) { 339 if (unlikely(!pcdev->active)) {
337 dev_err(pcdev->soc_host.dev, "DMA End IRQ with no active buffer\n"); 340 dev_err(dev, "DMA End IRQ with no active buffer\n");
338 goto out; 341 goto out;
339 } 342 }
340 343
341 vb = &pcdev->active->vb; 344 vb = &pcdev->active->vb;
342 buf = container_of(vb, struct mx1_buffer, vb); 345 buf = container_of(vb, struct mx1_buffer, vb);
343 WARN_ON(buf->inwork || list_empty(&vb->queue)); 346 WARN_ON(buf->inwork || list_empty(&vb->queue));
344 dev_dbg(pcdev->soc_host.dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 347 dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
345 vb, vb->baddr, vb->bsize); 348 vb, vb->baddr, vb->bsize);
346 349
347 mx1_camera_wakeup(pcdev, vb, buf); 350 mx1_camera_wakeup(pcdev, vb, buf);
@@ -362,7 +365,7 @@ static void mx1_camera_init_videobuf(struct videobuf_queue *q,
362 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 365 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
363 struct mx1_camera_dev *pcdev = ici->priv; 366 struct mx1_camera_dev *pcdev = ici->priv;
364 367
365 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, ici->dev, 368 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, icd->dev.parent,
366 &pcdev->lock, 369 &pcdev->lock,
367 V4L2_BUF_TYPE_VIDEO_CAPTURE, 370 V4L2_BUF_TYPE_VIDEO_CAPTURE,
368 V4L2_FIELD_NONE, 371 V4L2_FIELD_NONE,
@@ -381,8 +384,9 @@ static int mclk_get_divisor(struct mx1_camera_dev *pcdev)
381 * they get a nice Oops */ 384 * they get a nice Oops */
382 div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1; 385 div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1;
383 386
384 dev_dbg(pcdev->soc_host.dev, "System clock %lukHz, target freq %dkHz, " 387 dev_dbg(pcdev->icd->dev.parent,
385 "divisor %lu\n", lcdclk / 1000, mclk / 1000, div); 388 "System clock %lukHz, target freq %dkHz, divisor %lu\n",
389 lcdclk / 1000, mclk / 1000, div);
386 390
387 return div; 391 return div;
388} 392}
@@ -391,7 +395,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
391{ 395{
392 unsigned int csicr1 = CSICR1_EN; 396 unsigned int csicr1 = CSICR1_EN;
393 397
394 dev_dbg(pcdev->soc_host.dev, "Activate device\n"); 398 dev_dbg(pcdev->icd->dev.parent, "Activate device\n");
395 399
396 clk_enable(pcdev->clk); 400 clk_enable(pcdev->clk);
397 401
@@ -407,7 +411,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
407 411
408static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev) 412static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev)
409{ 413{
410 dev_dbg(pcdev->soc_host.dev, "Deactivate device\n"); 414 dev_dbg(pcdev->icd->dev.parent, "Deactivate device\n");
411 415
412 /* Disable all CSI interface */ 416 /* Disable all CSI interface */
413 __raw_writel(0x00, pcdev->base + CSICR1); 417 __raw_writel(0x00, pcdev->base + CSICR1);
@@ -428,14 +432,12 @@ static int mx1_camera_add_device(struct soc_camera_device *icd)
428 goto ebusy; 432 goto ebusy;
429 } 433 }
430 434
431 dev_info(&icd->dev, "MX1 Camera driver attached to camera %d\n", 435 dev_info(icd->dev.parent, "MX1 Camera driver attached to camera %d\n",
432 icd->devnum); 436 icd->devnum);
433 437
434 mx1_camera_activate(pcdev); 438 mx1_camera_activate(pcdev);
435 ret = icd->ops->init(icd);
436 439
437 if (!ret) 440 pcdev->icd = icd;
438 pcdev->icd = icd;
439 441
440ebusy: 442ebusy:
441 return ret; 443 return ret;
@@ -456,20 +458,20 @@ static void mx1_camera_remove_device(struct soc_camera_device *icd)
456 /* Stop DMA engine */ 458 /* Stop DMA engine */
457 imx_dma_disable(pcdev->dma_chan); 459 imx_dma_disable(pcdev->dma_chan);
458 460
459 dev_info(&icd->dev, "MX1 Camera driver detached from camera %d\n", 461 dev_info(icd->dev.parent, "MX1 Camera driver detached from camera %d\n",
460 icd->devnum); 462 icd->devnum);
461 463
462 icd->ops->release(icd);
463
464 mx1_camera_deactivate(pcdev); 464 mx1_camera_deactivate(pcdev);
465 465
466 pcdev->icd = NULL; 466 pcdev->icd = NULL;
467} 467}
468 468
469static int mx1_camera_set_crop(struct soc_camera_device *icd, 469static int mx1_camera_set_crop(struct soc_camera_device *icd,
470 struct v4l2_rect *rect) 470 struct v4l2_crop *a)
471{ 471{
472 return icd->ops->set_crop(icd, rect); 472 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
473
474 return v4l2_subdev_call(sd, video, s_crop, a);
473} 475}
474 476
475static int mx1_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) 477static int mx1_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
@@ -539,18 +541,19 @@ static int mx1_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
539static int mx1_camera_set_fmt(struct soc_camera_device *icd, 541static int mx1_camera_set_fmt(struct soc_camera_device *icd,
540 struct v4l2_format *f) 542 struct v4l2_format *f)
541{ 543{
542 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 544 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
543 const struct soc_camera_format_xlate *xlate; 545 const struct soc_camera_format_xlate *xlate;
544 struct v4l2_pix_format *pix = &f->fmt.pix; 546 struct v4l2_pix_format *pix = &f->fmt.pix;
545 int ret; 547 int ret;
546 548
547 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); 549 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
548 if (!xlate) { 550 if (!xlate) {
549 dev_warn(ici->dev, "Format %x not found\n", pix->pixelformat); 551 dev_warn(icd->dev.parent, "Format %x not found\n",
552 pix->pixelformat);
550 return -EINVAL; 553 return -EINVAL;
551 } 554 }
552 555
553 ret = icd->ops->set_fmt(icd, f); 556 ret = v4l2_subdev_call(sd, video, s_fmt, f);
554 if (!ret) { 557 if (!ret) {
555 icd->buswidth = xlate->buswidth; 558 icd->buswidth = xlate->buswidth;
556 icd->current_fmt = xlate->host_fmt; 559 icd->current_fmt = xlate->host_fmt;
@@ -562,10 +565,11 @@ static int mx1_camera_set_fmt(struct soc_camera_device *icd,
562static int mx1_camera_try_fmt(struct soc_camera_device *icd, 565static int mx1_camera_try_fmt(struct soc_camera_device *icd,
563 struct v4l2_format *f) 566 struct v4l2_format *f)
564{ 567{
568 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
565 /* TODO: limit to mx1 hardware capabilities */ 569 /* TODO: limit to mx1 hardware capabilities */
566 570
567 /* limit to sensor capabilities */ 571 /* limit to sensor capabilities */
568 return icd->ops->try_fmt(icd, f); 572 return v4l2_subdev_call(sd, video, try_fmt, f);
569} 573}
570 574
571static int mx1_camera_reqbufs(struct soc_camera_file *icf, 575static int mx1_camera_reqbufs(struct soc_camera_file *icf,
@@ -737,7 +741,7 @@ static int __init mx1_camera_probe(struct platform_device *pdev)
737 pcdev->soc_host.drv_name = DRIVER_NAME; 741 pcdev->soc_host.drv_name = DRIVER_NAME;
738 pcdev->soc_host.ops = &mx1_soc_camera_host_ops; 742 pcdev->soc_host.ops = &mx1_soc_camera_host_ops;
739 pcdev->soc_host.priv = pcdev; 743 pcdev->soc_host.priv = pcdev;
740 pcdev->soc_host.dev = &pdev->dev; 744 pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
741 pcdev->soc_host.nr = pdev->id; 745 pcdev->soc_host.nr = pdev->id;
742 err = soc_camera_host_register(&pcdev->soc_host); 746 err = soc_camera_host_register(&pcdev->soc_host);
743 if (err) 747 if (err)