2 * V4L2 Driver for SuperH Mobile CEU interface
4 * Copyright (C) 2008 Magnus Damm
6 * Based on V4L2 Driver for PXA camera host - "pxa_camera.c",
8 * Copyright (C) 2006, Sascha Hauer, Pengutronix
9 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
17 #include <linux/init.h>
18 #include <linux/module.h>
20 #include <linux/completion.h>
21 #include <linux/delay.h>
22 #include <linux/dma-mapping.h>
23 #include <linux/err.h>
24 #include <linux/errno.h>
26 #include <linux/interrupt.h>
27 #include <linux/kernel.h>
29 #include <linux/moduleparam.h>
31 #include <linux/time.h>
32 #include <linux/slab.h>
33 #include <linux/device.h>
34 #include <linux/platform_device.h>
35 #include <linux/videodev2.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/sched.h>
39 #include <media/v4l2-async.h>
40 #include <media/v4l2-common.h>
41 #include <media/v4l2-dev.h>
42 #include <media/soc_camera.h>
43 #include <media/sh_mobile_ceu.h>
44 #include <media/sh_mobile_csi2.h>
45 #include <media/videobuf2-dma-contig.h>
46 #include <media/v4l2-mediabus.h>
47 #include <media/soc_mediabus.h>
49 #include "soc_scale_crop.h"
51 /* register offsets for sh7722 / sh7723 */
53 #define CAPSR 0x00 /* Capture start register */
54 #define CAPCR 0x04 /* Capture control register */
55 #define CAMCR 0x08 /* Capture interface control register */
56 #define CMCYR 0x0c /* Capture interface cycle register */
57 #define CAMOR 0x10 /* Capture interface offset register */
58 #define CAPWR 0x14 /* Capture interface width register */
59 #define CAIFR 0x18 /* Capture interface input format register */
60 #define CSTCR 0x20 /* Camera strobe control register (<= sh7722) */
61 #define CSECR 0x24 /* Camera strobe emission count register (<= sh7722) */
62 #define CRCNTR 0x28 /* CEU register control register */
63 #define CRCMPR 0x2c /* CEU register forcible control register */
64 #define CFLCR 0x30 /* Capture filter control register */
65 #define CFSZR 0x34 /* Capture filter size clip register */
66 #define CDWDR 0x38 /* Capture destination width register */
67 #define CDAYR 0x3c /* Capture data address Y register */
68 #define CDACR 0x40 /* Capture data address C register */
69 #define CDBYR 0x44 /* Capture data bottom-field address Y register */
70 #define CDBCR 0x48 /* Capture data bottom-field address C register */
71 #define CBDSR 0x4c /* Capture bundle destination size register */
72 #define CFWCR 0x5c /* Firewall operation control register */
73 #define CLFCR 0x60 /* Capture low-pass filter control register */
74 #define CDOCR 0x64 /* Capture data output control register */
75 #define CDDCR 0x68 /* Capture data complexity level register */
76 #define CDDAR 0x6c /* Capture data complexity level address register */
77 #define CEIER 0x70 /* Capture event interrupt enable register */
78 #define CETCR 0x74 /* Capture event flag clear register */
79 #define CSTSR 0x7c /* Capture status register */
80 #define CSRTR 0x80 /* Capture software reset register */
81 #define CDSSR 0x84 /* Capture data size register */
82 #define CDAYR2 0x90 /* Capture data address Y register 2 */
83 #define CDACR2 0x94 /* Capture data address C register 2 */
84 #define CDBYR2 0x98 /* Capture data bottom-field address Y register 2 */
85 #define CDBCR2 0x9c /* Capture data bottom-field address C register 2 */
89 #define dev_geo dev_info
91 #define dev_geo dev_dbg
94 /* per video frame buffer */
95 struct sh_mobile_ceu_buffer
{
96 struct vb2_buffer vb
; /* v4l buffer must be first */
97 struct list_head queue
;
100 struct sh_mobile_ceu_dev
{
101 struct soc_camera_host ici
;
102 /* Asynchronous CSI2 linking */
103 struct v4l2_async_subdev
*csi2_asd
;
104 struct v4l2_subdev
*csi2_sd
;
105 /* Synchronous probing compatibility */
106 struct platform_device
*csi2_pdev
;
113 spinlock_t lock
; /* Protects video buffer lists */
114 struct list_head capture
;
115 struct vb2_buffer
*active
;
116 struct vb2_alloc_ctx
*alloc_ctx
;
118 struct sh_mobile_ceu_info
*pdata
;
119 struct completion complete
;
123 /* static max sizes either from platform data or default */
127 enum v4l2_field field
;
131 unsigned int image_mode
:1;
132 unsigned int is_16bit
:1;
133 unsigned int frozen
:1;
136 struct sh_mobile_ceu_cam
{
137 /* CEU offsets within the camera output, before the CEU scaler */
138 unsigned int ceu_left
;
139 unsigned int ceu_top
;
140 /* Client output, as seen by the CEU */
144 * User window from S_CROP / G_CROP, produced by client cropping and
145 * scaling, CEU scaling and CEU cropping, mapped back onto the client
148 struct v4l2_rect subrect
;
149 /* Camera cropping rectangle */
150 struct v4l2_rect rect
;
151 const struct soc_mbus_pixelfmt
*extra_fmt
;
155 static struct sh_mobile_ceu_buffer
*to_ceu_vb(struct vb2_buffer
*vb
)
157 return container_of(vb
, struct sh_mobile_ceu_buffer
, vb
);
160 static void ceu_write(struct sh_mobile_ceu_dev
*priv
,
161 unsigned long reg_offs
, u32 data
)
163 iowrite32(data
, priv
->base
+ reg_offs
);
166 static u32
ceu_read(struct sh_mobile_ceu_dev
*priv
, unsigned long reg_offs
)
168 return ioread32(priv
->base
+ reg_offs
);
171 static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev
*pcdev
)
175 ceu_write(pcdev
, CAPSR
, 1 << 16); /* reset */
177 /* wait CSTSR.CPTON bit */
178 for (i
= 0; i
< 1000; i
++) {
179 if (!(ceu_read(pcdev
, CSTSR
) & 1)) {
186 /* wait CAPSR.CPKIL bit */
187 for (i
= 0; i
< 1000; i
++) {
188 if (!(ceu_read(pcdev
, CAPSR
) & (1 << 16))) {
196 dev_warn(pcdev
->ici
.v4l2_dev
.dev
, "soft reset time out\n");
204 * Videobuf operations
208 * .queue_setup() is called to check, whether the driver can accept the
209 * requested number of buffers and to fill in plane sizes
210 * for the current frame format if required
212 static int sh_mobile_ceu_videobuf_setup(struct vb2_queue
*vq
,
213 const struct v4l2_format
*fmt
,
214 unsigned int *count
, unsigned int *num_planes
,
215 unsigned int sizes
[], void *alloc_ctxs
[])
217 struct soc_camera_device
*icd
= container_of(vq
, struct soc_camera_device
, vb2_vidq
);
218 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
219 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
222 const struct soc_camera_format_xlate
*xlate
= soc_camera_xlate_by_fourcc(icd
,
223 fmt
->fmt
.pix
.pixelformat
);
224 unsigned int bytes_per_line
;
230 ret
= soc_mbus_bytes_per_line(fmt
->fmt
.pix
.width
,
235 bytes_per_line
= max_t(u32
, fmt
->fmt
.pix
.bytesperline
, ret
);
237 ret
= soc_mbus_image_size(xlate
->host_fmt
, bytes_per_line
,
238 fmt
->fmt
.pix
.height
);
242 sizes
[0] = max_t(u32
, fmt
->fmt
.pix
.sizeimage
, ret
);
244 /* Called from VIDIOC_REQBUFS or in compatibility mode */
245 sizes
[0] = icd
->sizeimage
;
248 alloc_ctxs
[0] = pcdev
->alloc_ctx
;
250 if (!vq
->num_buffers
)
256 /* If *num_planes != 0, we have already verified *count. */
257 if (pcdev
->video_limit
&& !*num_planes
) {
258 size_t size
= PAGE_ALIGN(sizes
[0]) * *count
;
260 if (size
+ pcdev
->buf_total
> pcdev
->video_limit
)
261 *count
= (pcdev
->video_limit
- pcdev
->buf_total
) /
262 PAGE_ALIGN(sizes
[0]);
267 dev_dbg(icd
->parent
, "count=%d, size=%u\n", *count
, sizes
[0]);
272 #define CEU_CETCR_MAGIC 0x0317f313 /* acknowledge magical interrupt sources */
273 #define CEU_CETCR_IGRW (1 << 4) /* prohibited register access interrupt bit */
274 #define CEU_CEIER_CPEIE (1 << 0) /* one-frame capture end interrupt */
275 #define CEU_CEIER_VBP (1 << 20) /* vbp error */
276 #define CEU_CAPCR_CTNCP (1 << 16) /* continuous capture mode (if set) */
277 #define CEU_CEIER_MASK (CEU_CEIER_CPEIE | CEU_CEIER_VBP)
281 * return value doesn't reflex the success/failure to queue the new buffer,
282 * but rather the status of the previous buffer.
284 static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev
*pcdev
)
286 struct soc_camera_device
*icd
= pcdev
->ici
.icd
;
287 dma_addr_t phys_addr_top
, phys_addr_bottom
;
288 unsigned long top1
, top2
;
289 unsigned long bottom1
, bottom2
;
295 * The hardware is _very_ picky about this sequence. Especially
296 * the CEU_CETCR_MAGIC value. It seems like we need to acknowledge
297 * several not-so-well documented interrupt sources in CETCR.
299 ceu_write(pcdev
, CEIER
, ceu_read(pcdev
, CEIER
) & ~CEU_CEIER_MASK
);
300 status
= ceu_read(pcdev
, CETCR
);
301 ceu_write(pcdev
, CETCR
, ~status
& CEU_CETCR_MAGIC
);
303 ceu_write(pcdev
, CEIER
, ceu_read(pcdev
, CEIER
) | CEU_CEIER_MASK
);
304 ceu_write(pcdev
, CAPCR
, ceu_read(pcdev
, CAPCR
) & ~CEU_CAPCR_CTNCP
);
305 ceu_write(pcdev
, CETCR
, CEU_CETCR_MAGIC
^ CEU_CETCR_IGRW
);
308 * When a VBP interrupt occurs, a capture end interrupt does not occur
309 * and the image of that frame is not captured correctly. So, soft reset
312 if (status
& CEU_CEIER_VBP
) {
313 sh_mobile_ceu_soft_reset(pcdev
);
318 complete(&pcdev
->complete
);
325 if (V4L2_FIELD_INTERLACED_BT
== pcdev
->field
) {
337 phys_addr_top
= vb2_dma_contig_plane_dma_addr(pcdev
->active
, 0);
339 switch (icd
->current_fmt
->host_fmt
->fourcc
) {
340 case V4L2_PIX_FMT_NV12
:
341 case V4L2_PIX_FMT_NV21
:
342 case V4L2_PIX_FMT_NV16
:
343 case V4L2_PIX_FMT_NV61
:
350 ceu_write(pcdev
, top1
, phys_addr_top
);
351 if (V4L2_FIELD_NONE
!= pcdev
->field
) {
352 phys_addr_bottom
= phys_addr_top
+ icd
->bytesperline
;
353 ceu_write(pcdev
, bottom1
, phys_addr_bottom
);
357 phys_addr_top
+= icd
->bytesperline
* icd
->user_height
;
358 ceu_write(pcdev
, top2
, phys_addr_top
);
359 if (V4L2_FIELD_NONE
!= pcdev
->field
) {
360 phys_addr_bottom
= phys_addr_top
+ icd
->bytesperline
;
361 ceu_write(pcdev
, bottom2
, phys_addr_bottom
);
365 ceu_write(pcdev
, CAPSR
, 0x1); /* start capture */
370 static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer
*vb
)
372 struct sh_mobile_ceu_buffer
*buf
= to_ceu_vb(vb
);
374 /* Added list head initialization on alloc */
375 WARN(!list_empty(&buf
->queue
), "Buffer %p on queue!\n", vb
);
380 static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer
*vb
)
382 struct soc_camera_device
*icd
= container_of(vb
->vb2_queue
, struct soc_camera_device
, vb2_vidq
);
383 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
384 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
385 struct sh_mobile_ceu_buffer
*buf
= to_ceu_vb(vb
);
388 size
= icd
->sizeimage
;
390 if (vb2_plane_size(vb
, 0) < size
) {
391 dev_err(icd
->parent
, "Buffer #%d too small (%lu < %lu)\n",
392 vb
->v4l2_buf
.index
, vb2_plane_size(vb
, 0), size
);
396 vb2_set_plane_payload(vb
, 0, size
);
398 dev_dbg(icd
->parent
, "%s (vb=0x%p) 0x%p %lu\n", __func__
,
399 vb
, vb2_plane_vaddr(vb
, 0), vb2_get_plane_payload(vb
, 0));
403 * This can be useful if you want to see if we actually fill
404 * the buffer with something
406 if (vb2_plane_vaddr(vb
, 0))
407 memset(vb2_plane_vaddr(vb
, 0), 0xaa, vb2_get_plane_payload(vb
, 0));
410 spin_lock_irq(&pcdev
->lock
);
411 list_add_tail(&buf
->queue
, &pcdev
->capture
);
413 if (!pcdev
->active
) {
415 * Because there were no active buffer at this moment,
416 * we are not interested in the return value of
417 * sh_mobile_ceu_capture here.
420 sh_mobile_ceu_capture(pcdev
);
422 spin_unlock_irq(&pcdev
->lock
);
427 vb2_buffer_done(vb
, VB2_BUF_STATE_ERROR
);
430 static void sh_mobile_ceu_videobuf_release(struct vb2_buffer
*vb
)
432 struct soc_camera_device
*icd
= container_of(vb
->vb2_queue
, struct soc_camera_device
, vb2_vidq
);
433 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
434 struct sh_mobile_ceu_buffer
*buf
= to_ceu_vb(vb
);
435 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
437 spin_lock_irq(&pcdev
->lock
);
439 if (pcdev
->active
== vb
) {
440 /* disable capture (release DMA buffer), reset */
441 ceu_write(pcdev
, CAPSR
, 1 << 16);
442 pcdev
->active
= NULL
;
446 * Doesn't hurt also if the list is empty, but it hurts, if queuing the
447 * buffer failed, and .buf_init() hasn't been called
450 list_del_init(&buf
->queue
);
452 pcdev
->buf_total
-= PAGE_ALIGN(vb2_plane_size(vb
, 0));
453 dev_dbg(icd
->parent
, "%s() %zu bytes buffers\n", __func__
,
456 spin_unlock_irq(&pcdev
->lock
);
459 static int sh_mobile_ceu_videobuf_init(struct vb2_buffer
*vb
)
461 struct soc_camera_device
*icd
= container_of(vb
->vb2_queue
, struct soc_camera_device
, vb2_vidq
);
462 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
463 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
465 pcdev
->buf_total
+= PAGE_ALIGN(vb2_plane_size(vb
, 0));
466 dev_dbg(icd
->parent
, "%s() %zu bytes buffers\n", __func__
,
469 /* This is for locking debugging only */
470 INIT_LIST_HEAD(&to_ceu_vb(vb
)->queue
);
474 static void sh_mobile_ceu_stop_streaming(struct vb2_queue
*q
)
476 struct soc_camera_device
*icd
= container_of(q
, struct soc_camera_device
, vb2_vidq
);
477 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
478 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
479 struct list_head
*buf_head
, *tmp
;
481 spin_lock_irq(&pcdev
->lock
);
483 pcdev
->active
= NULL
;
485 list_for_each_safe(buf_head
, tmp
, &pcdev
->capture
)
486 list_del_init(buf_head
);
488 spin_unlock_irq(&pcdev
->lock
);
490 sh_mobile_ceu_soft_reset(pcdev
);
493 static struct vb2_ops sh_mobile_ceu_videobuf_ops
= {
494 .queue_setup
= sh_mobile_ceu_videobuf_setup
,
495 .buf_prepare
= sh_mobile_ceu_videobuf_prepare
,
496 .buf_queue
= sh_mobile_ceu_videobuf_queue
,
497 .buf_cleanup
= sh_mobile_ceu_videobuf_release
,
498 .buf_init
= sh_mobile_ceu_videobuf_init
,
499 .wait_prepare
= vb2_ops_wait_prepare
,
500 .wait_finish
= vb2_ops_wait_finish
,
501 .stop_streaming
= sh_mobile_ceu_stop_streaming
,
504 static irqreturn_t
sh_mobile_ceu_irq(int irq
, void *data
)
506 struct sh_mobile_ceu_dev
*pcdev
= data
;
507 struct vb2_buffer
*vb
;
510 spin_lock(&pcdev
->lock
);
514 /* Stale interrupt from a released buffer */
517 list_del_init(&to_ceu_vb(vb
)->queue
);
519 if (!list_empty(&pcdev
->capture
))
520 pcdev
->active
= &list_entry(pcdev
->capture
.next
,
521 struct sh_mobile_ceu_buffer
, queue
)->vb
;
523 pcdev
->active
= NULL
;
525 ret
= sh_mobile_ceu_capture(pcdev
);
526 v4l2_get_timestamp(&vb
->v4l2_buf
.timestamp
);
528 vb
->v4l2_buf
.field
= pcdev
->field
;
529 vb
->v4l2_buf
.sequence
= pcdev
->sequence
++;
531 vb2_buffer_done(vb
, ret
< 0 ? VB2_BUF_STATE_ERROR
: VB2_BUF_STATE_DONE
);
534 spin_unlock(&pcdev
->lock
);
539 static struct v4l2_subdev
*find_csi2(struct sh_mobile_ceu_dev
*pcdev
)
541 struct v4l2_subdev
*sd
;
544 return pcdev
->csi2_sd
;
546 if (pcdev
->csi2_asd
) {
547 char name
[] = "sh-mobile-csi2";
548 v4l2_device_for_each_subdev(sd
, &pcdev
->ici
.v4l2_dev
)
549 if (!strncmp(name
, sd
->name
, sizeof(name
) - 1)) {
558 static struct v4l2_subdev
*csi2_subdev(struct sh_mobile_ceu_dev
*pcdev
,
559 struct soc_camera_device
*icd
)
561 struct v4l2_subdev
*sd
= pcdev
->csi2_sd
;
563 return sd
&& sd
->grp_id
== soc_camera_grp_id(icd
) ? sd
: NULL
;
566 static int sh_mobile_ceu_add_device(struct soc_camera_device
*icd
)
568 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
569 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
570 struct v4l2_subdev
*csi2_sd
= find_csi2(pcdev
);
574 csi2_sd
->grp_id
= soc_camera_grp_id(icd
);
575 v4l2_set_subdev_hostdata(csi2_sd
, icd
);
578 ret
= v4l2_subdev_call(csi2_sd
, core
, s_power
, 1);
579 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
583 * -ENODEV is special: either csi2_sd == NULL or the CSI-2 driver
584 * has not found this soc-camera device among its clients
586 if (csi2_sd
&& ret
== -ENODEV
)
589 dev_info(icd
->parent
,
590 "SuperH Mobile CEU%s driver attached to camera %d\n",
591 csi2_sd
&& csi2_sd
->grp_id
? "/CSI-2" : "", icd
->devnum
);
596 static void sh_mobile_ceu_remove_device(struct soc_camera_device
*icd
)
598 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
599 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
600 struct v4l2_subdev
*csi2_sd
= find_csi2(pcdev
);
602 dev_info(icd
->parent
,
603 "SuperH Mobile CEU driver detached from camera %d\n",
606 v4l2_subdev_call(csi2_sd
, core
, s_power
, 0);
609 /* Called with .host_lock held */
610 static int sh_mobile_ceu_clock_start(struct soc_camera_host
*ici
)
612 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
614 pm_runtime_get_sync(ici
->v4l2_dev
.dev
);
616 pcdev
->buf_total
= 0;
618 sh_mobile_ceu_soft_reset(pcdev
);
623 /* Called with .host_lock held */
624 static void sh_mobile_ceu_clock_stop(struct soc_camera_host
*ici
)
626 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
628 /* disable capture, disable interrupts */
629 ceu_write(pcdev
, CEIER
, 0);
630 sh_mobile_ceu_soft_reset(pcdev
);
632 /* make sure active buffer is canceled */
633 spin_lock_irq(&pcdev
->lock
);
635 list_del_init(&to_ceu_vb(pcdev
->active
)->queue
);
636 vb2_buffer_done(pcdev
->active
, VB2_BUF_STATE_ERROR
);
637 pcdev
->active
= NULL
;
639 spin_unlock_irq(&pcdev
->lock
);
641 pm_runtime_put(ici
->v4l2_dev
.dev
);
645 * See chapter 29.4.12 "Capture Filter Control Register (CFLCR)"
646 * in SH7722 Hardware Manual
648 static unsigned int size_dst(unsigned int src
, unsigned int scale
)
650 unsigned int mant_pre
= scale
>> 12;
653 return ((mant_pre
+ 2 * (src
- 1)) / (2 * mant_pre
) - 1) *
654 mant_pre
* 4096 / scale
+ 1;
657 static u16
calc_scale(unsigned int src
, unsigned int *dst
)
664 scale
= (src
* 4096 / *dst
) & ~7;
666 while (scale
> 4096 && size_dst(src
, scale
) < *dst
)
669 *dst
= size_dst(src
, scale
);
674 /* rect is guaranteed to not exceed the scaled camera rectangle */
675 static void sh_mobile_ceu_set_rect(struct soc_camera_device
*icd
)
677 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
678 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
679 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
680 unsigned int height
, width
, cdwdr_width
, in_width
, in_height
;
681 unsigned int left_offset
, top_offset
;
684 dev_geo(icd
->parent
, "Crop %ux%u@%u:%u\n",
685 icd
->user_width
, icd
->user_height
, cam
->ceu_left
, cam
->ceu_top
);
687 left_offset
= cam
->ceu_left
;
688 top_offset
= cam
->ceu_top
;
690 WARN_ON(icd
->user_width
& 3 || icd
->user_height
& 3);
692 width
= icd
->user_width
;
694 if (pcdev
->image_mode
) {
695 in_width
= cam
->width
;
696 if (!pcdev
->is_16bit
) {
701 unsigned int w_factor
;
703 switch (icd
->current_fmt
->host_fmt
->packing
) {
704 case SOC_MBUS_PACKING_2X8_PADHI
:
711 in_width
= cam
->width
* w_factor
;
712 left_offset
*= w_factor
;
715 cdwdr_width
= icd
->bytesperline
;
717 height
= icd
->user_height
;
718 in_height
= cam
->height
;
719 if (V4L2_FIELD_NONE
!= pcdev
->field
) {
720 height
= (height
/ 2) & ~3;
726 /* CSI2 special configuration */
727 if (csi2_subdev(pcdev
, icd
)) {
728 in_width
= ((in_width
- 2) * 2);
732 /* Set CAMOR, CAPWR, CFSZR, take care of CDWDR */
733 camor
= left_offset
| (top_offset
<< 16);
736 "CAMOR 0x%x, CAPWR 0x%x, CFSZR 0x%x, CDWDR 0x%x\n", camor
,
737 (in_height
<< 16) | in_width
, (height
<< 16) | width
,
740 ceu_write(pcdev
, CAMOR
, camor
);
741 ceu_write(pcdev
, CAPWR
, (in_height
<< 16) | in_width
);
742 /* CFSZR clipping is applied _after_ the scaling filter (CFLCR) */
743 ceu_write(pcdev
, CFSZR
, (height
<< 16) | width
);
744 ceu_write(pcdev
, CDWDR
, cdwdr_width
);
747 static u32
capture_save_reset(struct sh_mobile_ceu_dev
*pcdev
)
749 u32 capsr
= ceu_read(pcdev
, CAPSR
);
750 ceu_write(pcdev
, CAPSR
, 1 << 16); /* reset, stop capture */
754 static void capture_restore(struct sh_mobile_ceu_dev
*pcdev
, u32 capsr
)
756 unsigned long timeout
= jiffies
+ 10 * HZ
;
759 * Wait until the end of the current frame. It can take a long time,
760 * but if it has been aborted by a CAPSR reset, it shoule exit sooner.
762 while ((ceu_read(pcdev
, CSTSR
) & 1) && time_before(jiffies
, timeout
))
765 if (time_after(jiffies
, timeout
)) {
766 dev_err(pcdev
->ici
.v4l2_dev
.dev
,
767 "Timeout waiting for frame end! Interface problem?\n");
771 /* Wait until reset clears, this shall not hang... */
772 while (ceu_read(pcdev
, CAPSR
) & (1 << 16))
775 /* Anything to restore? */
776 if (capsr
& ~(1 << 16))
777 ceu_write(pcdev
, CAPSR
, capsr
);
780 /* Find the bus subdevice driver, e.g., CSI2 */
781 static struct v4l2_subdev
*find_bus_subdev(struct sh_mobile_ceu_dev
*pcdev
,
782 struct soc_camera_device
*icd
)
784 return csi2_subdev(pcdev
, icd
) ? : soc_camera_to_subdev(icd
);
787 #define CEU_BUS_FLAGS (V4L2_MBUS_MASTER | \
788 V4L2_MBUS_PCLK_SAMPLE_RISING | \
789 V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
790 V4L2_MBUS_HSYNC_ACTIVE_LOW | \
791 V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
792 V4L2_MBUS_VSYNC_ACTIVE_LOW | \
793 V4L2_MBUS_DATA_ACTIVE_HIGH)
795 /* Capture is not running, no interrupts, no locking needed */
796 static int sh_mobile_ceu_set_bus_param(struct soc_camera_device
*icd
)
798 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
799 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
800 struct v4l2_subdev
*sd
= find_bus_subdev(pcdev
, icd
);
801 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
802 struct v4l2_mbus_config cfg
= {.type
= V4L2_MBUS_PARALLEL
,};
803 unsigned long value
, common_flags
= CEU_BUS_FLAGS
;
804 u32 capsr
= capture_save_reset(pcdev
);
805 unsigned int yuv_lineskip
;
809 * If the client doesn't implement g_mbus_config, we just use our
812 ret
= v4l2_subdev_call(sd
, video
, g_mbus_config
, &cfg
);
814 common_flags
= soc_mbus_config_compatible(&cfg
,
818 } else if (ret
!= -ENOIOCTLCMD
) {
822 /* Make choises, based on platform preferences */
823 if ((common_flags
& V4L2_MBUS_HSYNC_ACTIVE_HIGH
) &&
824 (common_flags
& V4L2_MBUS_HSYNC_ACTIVE_LOW
)) {
825 if (pcdev
->flags
& SH_CEU_FLAG_HSYNC_LOW
)
826 common_flags
&= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH
;
828 common_flags
&= ~V4L2_MBUS_HSYNC_ACTIVE_LOW
;
831 if ((common_flags
& V4L2_MBUS_VSYNC_ACTIVE_HIGH
) &&
832 (common_flags
& V4L2_MBUS_VSYNC_ACTIVE_LOW
)) {
833 if (pcdev
->flags
& SH_CEU_FLAG_VSYNC_LOW
)
834 common_flags
&= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH
;
836 common_flags
&= ~V4L2_MBUS_VSYNC_ACTIVE_LOW
;
839 cfg
.flags
= common_flags
;
840 ret
= v4l2_subdev_call(sd
, video
, s_mbus_config
, &cfg
);
841 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
844 if (icd
->current_fmt
->host_fmt
->bits_per_sample
> 8)
849 ceu_write(pcdev
, CRCNTR
, 0);
850 ceu_write(pcdev
, CRCMPR
, 0);
852 value
= 0x00000010; /* data fetch by default */
855 switch (icd
->current_fmt
->host_fmt
->fourcc
) {
856 case V4L2_PIX_FMT_NV12
:
857 case V4L2_PIX_FMT_NV21
:
858 /* convert 4:2:2 -> 4:2:0 */
859 yuv_lineskip
= 0; /* skip for NV12/21, no skip for NV16/61 */
861 case V4L2_PIX_FMT_NV16
:
862 case V4L2_PIX_FMT_NV61
:
864 case MEDIA_BUS_FMT_UYVY8_2X8
:
865 value
= 0x00000000; /* Cb0, Y0, Cr0, Y1 */
867 case MEDIA_BUS_FMT_VYUY8_2X8
:
868 value
= 0x00000100; /* Cr0, Y0, Cb0, Y1 */
870 case MEDIA_BUS_FMT_YUYV8_2X8
:
871 value
= 0x00000200; /* Y0, Cb0, Y1, Cr0 */
873 case MEDIA_BUS_FMT_YVYU8_2X8
:
874 value
= 0x00000300; /* Y0, Cr0, Y1, Cb0 */
881 if (icd
->current_fmt
->host_fmt
->fourcc
== V4L2_PIX_FMT_NV21
||
882 icd
->current_fmt
->host_fmt
->fourcc
== V4L2_PIX_FMT_NV61
)
883 value
^= 0x00000100; /* swap U, V to change from NV1x->NVx1 */
885 value
|= common_flags
& V4L2_MBUS_VSYNC_ACTIVE_LOW
? 1 << 1 : 0;
886 value
|= common_flags
& V4L2_MBUS_HSYNC_ACTIVE_LOW
? 1 << 0 : 0;
888 if (csi2_subdev(pcdev
, icd
)) /* CSI2 mode */
890 else if (pcdev
->is_16bit
)
892 else if (pcdev
->flags
& SH_CEU_FLAG_LOWER_8BIT
)
895 ceu_write(pcdev
, CAMCR
, value
);
897 ceu_write(pcdev
, CAPCR
, 0x00300000);
899 switch (pcdev
->field
) {
900 case V4L2_FIELD_INTERLACED_TB
:
903 case V4L2_FIELD_INTERLACED_BT
:
910 ceu_write(pcdev
, CAIFR
, value
);
912 sh_mobile_ceu_set_rect(icd
);
915 dev_geo(icd
->parent
, "CFLCR 0x%x\n", pcdev
->cflcr
);
916 ceu_write(pcdev
, CFLCR
, pcdev
->cflcr
);
919 * A few words about byte order (observed in Big Endian mode)
921 * In data fetch mode bytes are received in chunks of 8 bytes.
922 * D0, D1, D2, D3, D4, D5, D6, D7 (D0 received first)
924 * The data is however by default written to memory in reverse order:
925 * D7, D6, D5, D4, D3, D2, D1, D0 (D7 written to lowest byte)
927 * The lowest three bits of CDOCR allows us to do swapping,
928 * using 7 we swap the data bytes to match the incoming order:
929 * D0, D1, D2, D3, D4, D5, D6, D7
931 value
= 0x00000007 | yuv_lineskip
;
933 ceu_write(pcdev
, CDOCR
, value
);
934 ceu_write(pcdev
, CFWCR
, 0); /* keep "datafetch firewall" disabled */
936 capture_restore(pcdev
, capsr
);
938 /* not in bundle mode: skip CBDSR, CDAYR2, CDACR2, CDBYR2, CDBCR2 */
942 static int sh_mobile_ceu_try_bus_param(struct soc_camera_device
*icd
,
943 unsigned char buswidth
)
945 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
946 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
947 struct v4l2_subdev
*sd
= find_bus_subdev(pcdev
, icd
);
948 unsigned long common_flags
= CEU_BUS_FLAGS
;
949 struct v4l2_mbus_config cfg
= {.type
= V4L2_MBUS_PARALLEL
,};
952 ret
= v4l2_subdev_call(sd
, video
, g_mbus_config
, &cfg
);
954 common_flags
= soc_mbus_config_compatible(&cfg
,
956 else if (ret
!= -ENOIOCTLCMD
)
959 if (!common_flags
|| buswidth
> 16)
965 static const struct soc_mbus_pixelfmt sh_mobile_ceu_formats
[] = {
967 .fourcc
= V4L2_PIX_FMT_NV12
,
969 .bits_per_sample
= 8,
970 .packing
= SOC_MBUS_PACKING_1_5X8
,
971 .order
= SOC_MBUS_ORDER_LE
,
972 .layout
= SOC_MBUS_LAYOUT_PLANAR_2Y_C
,
974 .fourcc
= V4L2_PIX_FMT_NV21
,
976 .bits_per_sample
= 8,
977 .packing
= SOC_MBUS_PACKING_1_5X8
,
978 .order
= SOC_MBUS_ORDER_LE
,
979 .layout
= SOC_MBUS_LAYOUT_PLANAR_2Y_C
,
981 .fourcc
= V4L2_PIX_FMT_NV16
,
983 .bits_per_sample
= 8,
984 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
985 .order
= SOC_MBUS_ORDER_LE
,
986 .layout
= SOC_MBUS_LAYOUT_PLANAR_Y_C
,
988 .fourcc
= V4L2_PIX_FMT_NV61
,
990 .bits_per_sample
= 8,
991 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
992 .order
= SOC_MBUS_ORDER_LE
,
993 .layout
= SOC_MBUS_LAYOUT_PLANAR_Y_C
,
997 /* This will be corrected as we get more formats */
998 static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt
*fmt
)
1000 return fmt
->packing
== SOC_MBUS_PACKING_NONE
||
1001 (fmt
->bits_per_sample
== 8 &&
1002 fmt
->packing
== SOC_MBUS_PACKING_1_5X8
) ||
1003 (fmt
->bits_per_sample
== 8 &&
1004 fmt
->packing
== SOC_MBUS_PACKING_2X8_PADHI
) ||
1005 (fmt
->bits_per_sample
> 8 &&
1006 fmt
->packing
== SOC_MBUS_PACKING_EXTEND16
);
1009 static struct soc_camera_device
*ctrl_to_icd(struct v4l2_ctrl
*ctrl
)
1011 return container_of(ctrl
->handler
, struct soc_camera_device
,
1015 static int sh_mobile_ceu_s_ctrl(struct v4l2_ctrl
*ctrl
)
1017 struct soc_camera_device
*icd
= ctrl_to_icd(ctrl
);
1018 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1019 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1022 case V4L2_CID_SHARPNESS
:
1023 switch (icd
->current_fmt
->host_fmt
->fourcc
) {
1024 case V4L2_PIX_FMT_NV12
:
1025 case V4L2_PIX_FMT_NV21
:
1026 case V4L2_PIX_FMT_NV16
:
1027 case V4L2_PIX_FMT_NV61
:
1028 ceu_write(pcdev
, CLFCR
, !ctrl
->val
);
1037 static const struct v4l2_ctrl_ops sh_mobile_ceu_ctrl_ops
= {
1038 .s_ctrl
= sh_mobile_ceu_s_ctrl
,
1041 static int sh_mobile_ceu_get_formats(struct soc_camera_device
*icd
, unsigned int idx
,
1042 struct soc_camera_format_xlate
*xlate
)
1044 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1045 struct device
*dev
= icd
->parent
;
1046 struct soc_camera_host
*ici
= to_soc_camera_host(dev
);
1047 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1050 struct sh_mobile_ceu_cam
*cam
;
1051 struct v4l2_subdev_mbus_code_enum code
= {
1052 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
1055 const struct soc_mbus_pixelfmt
*fmt
;
1057 ret
= v4l2_subdev_call(sd
, pad
, enum_mbus_code
, NULL
, &code
);
1059 /* No more formats */
1062 fmt
= soc_mbus_get_fmtdesc(code
.code
);
1064 dev_warn(dev
, "unsupported format code #%u: %d\n", idx
, code
.code
);
1068 if (!csi2_subdev(pcdev
, icd
)) {
1069 /* Are there any restrictions in the CSI-2 case? */
1070 ret
= sh_mobile_ceu_try_bus_param(icd
, fmt
->bits_per_sample
);
1075 if (!icd
->host_priv
) {
1076 struct v4l2_subdev_format fmt
= {
1077 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
1079 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
1080 struct v4l2_rect rect
;
1083 /* Add our control */
1084 v4l2_ctrl_new_std(&icd
->ctrl_handler
, &sh_mobile_ceu_ctrl_ops
,
1085 V4L2_CID_SHARPNESS
, 0, 1, 1, 1);
1086 if (icd
->ctrl_handler
.error
)
1087 return icd
->ctrl_handler
.error
;
1089 /* FIXME: subwindow is lost between close / open */
1091 /* Cache current client geometry */
1092 ret
= soc_camera_client_g_rect(sd
, &rect
);
1097 ret
= v4l2_subdev_call(sd
, pad
, get_fmt
, NULL
, &fmt
);
1102 * All currently existing CEU implementations support 2560x1920
1103 * or larger frames. If the sensor is proposing too big a frame,
1104 * don't bother with possibly supportred by the CEU larger
1105 * sizes, just try VGA multiples. If needed, this can be
1106 * adjusted in the future.
1108 while ((mf
->width
> pcdev
->max_width
||
1109 mf
->height
> pcdev
->max_height
) && shift
< 4) {
1110 /* Try 2560x1920, 1280x960, 640x480, 320x240 */
1111 mf
->width
= 2560 >> shift
;
1112 mf
->height
= 1920 >> shift
;
1113 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
,
1114 soc_camera_grp_id(icd
), pad
,
1115 set_fmt
, NULL
, &fmt
);
1122 dev_err(dev
, "Failed to configure the client below %ux%x\n",
1123 mf
->width
, mf
->height
);
1127 dev_geo(dev
, "camera fmt %ux%u\n", mf
->width
, mf
->height
);
1129 cam
= kzalloc(sizeof(*cam
), GFP_KERNEL
);
1133 /* We are called with current camera crop, initialise subrect with it */
1135 cam
->subrect
= rect
;
1137 cam
->width
= mf
->width
;
1138 cam
->height
= mf
->height
;
1140 icd
->host_priv
= cam
;
1142 cam
= icd
->host_priv
;
1145 /* Beginning of a pass */
1147 cam
->extra_fmt
= NULL
;
1149 switch (code
.code
) {
1150 case MEDIA_BUS_FMT_UYVY8_2X8
:
1151 case MEDIA_BUS_FMT_VYUY8_2X8
:
1152 case MEDIA_BUS_FMT_YUYV8_2X8
:
1153 case MEDIA_BUS_FMT_YVYU8_2X8
:
1158 * Our case is simple so far: for any of the above four camera
1159 * formats we add all our four synthesized NV* formats, so,
1160 * just marking the device with a single flag suffices. If
1161 * the format generation rules are more complex, you would have
1162 * to actually hang your already added / counted formats onto
1163 * the host_priv pointer and check whether the format you're
1164 * going to add now is already there.
1166 cam
->extra_fmt
= sh_mobile_ceu_formats
;
1168 n
= ARRAY_SIZE(sh_mobile_ceu_formats
);
1170 for (k
= 0; xlate
&& k
< n
; k
++) {
1171 xlate
->host_fmt
= &sh_mobile_ceu_formats
[k
];
1172 xlate
->code
= code
.code
;
1174 dev_dbg(dev
, "Providing format %s using code %d\n",
1175 sh_mobile_ceu_formats
[k
].name
, code
.code
);
1179 if (!sh_mobile_ceu_packing_supported(fmt
))
1183 /* Generic pass-through */
1186 xlate
->host_fmt
= fmt
;
1187 xlate
->code
= code
.code
;
1189 dev_dbg(dev
, "Providing format %s in pass-through mode\n",
1196 static void sh_mobile_ceu_put_formats(struct soc_camera_device
*icd
)
1198 kfree(icd
->host_priv
);
1199 icd
->host_priv
= NULL
;
1202 #define scale_down(size, scale) soc_camera_shift_scale(size, 12, scale)
1203 #define calc_generic_scale(in, out) soc_camera_calc_scale(in, 12, out)
1206 * CEU can scale and crop, but we don't want to waste bandwidth and kill the
1207 * framerate by always requesting the maximum image from the client. See
1208 * Documentation/video4linux/sh_mobile_ceu_camera.txt for a description of
1209 * scaling and cropping algorithms and for the meaning of referenced here steps.
1211 static int sh_mobile_ceu_set_crop(struct soc_camera_device
*icd
,
1212 const struct v4l2_crop
*a
)
1214 struct v4l2_crop a_writable
= *a
;
1215 const struct v4l2_rect
*rect
= &a_writable
.c
;
1216 struct device
*dev
= icd
->parent
;
1217 struct soc_camera_host
*ici
= to_soc_camera_host(dev
);
1218 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1219 struct v4l2_crop cam_crop
;
1220 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
1221 struct v4l2_rect
*cam_rect
= &cam_crop
.c
;
1222 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1223 struct v4l2_subdev_format fmt
= {
1224 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
1226 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
1227 unsigned int scale_cam_h
, scale_cam_v
, scale_ceu_h
, scale_ceu_v
,
1228 out_width
, out_height
;
1229 int interm_width
, interm_height
;
1233 dev_geo(dev
, "S_CROP(%ux%u@%u:%u)\n", rect
->width
, rect
->height
,
1234 rect
->left
, rect
->top
);
1236 /* During camera cropping its output window can change too, stop CEU */
1237 capsr
= capture_save_reset(pcdev
);
1238 dev_dbg(dev
, "CAPSR 0x%x, CFLCR 0x%x\n", capsr
, pcdev
->cflcr
);
1241 * 1. - 2. Apply iterative camera S_CROP for new input window, read back
1242 * actual camera rectangle.
1244 ret
= soc_camera_client_s_crop(sd
, &a_writable
, &cam_crop
,
1245 &cam
->rect
, &cam
->subrect
);
1249 dev_geo(dev
, "1-2: camera cropped to %ux%u@%u:%u\n",
1250 cam_rect
->width
, cam_rect
->height
,
1251 cam_rect
->left
, cam_rect
->top
);
1253 /* On success cam_crop contains current camera crop */
1255 /* 3. Retrieve camera output window */
1256 ret
= v4l2_subdev_call(sd
, pad
, get_fmt
, NULL
, &fmt
);
1260 if (mf
->width
> pcdev
->max_width
|| mf
->height
> pcdev
->max_height
)
1263 /* 4. Calculate camera scales */
1264 scale_cam_h
= calc_generic_scale(cam_rect
->width
, mf
->width
);
1265 scale_cam_v
= calc_generic_scale(cam_rect
->height
, mf
->height
);
1267 /* Calculate intermediate window */
1268 interm_width
= scale_down(rect
->width
, scale_cam_h
);
1269 interm_height
= scale_down(rect
->height
, scale_cam_v
);
1271 if (interm_width
< icd
->user_width
) {
1274 new_scale_h
= calc_generic_scale(rect
->width
, icd
->user_width
);
1276 mf
->width
= scale_down(cam_rect
->width
, new_scale_h
);
1279 if (interm_height
< icd
->user_height
) {
1282 new_scale_v
= calc_generic_scale(rect
->height
, icd
->user_height
);
1284 mf
->height
= scale_down(cam_rect
->height
, new_scale_v
);
1287 if (interm_width
< icd
->user_width
|| interm_height
< icd
->user_height
) {
1288 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
,
1289 soc_camera_grp_id(icd
), pad
,
1290 set_fmt
, NULL
, &fmt
);
1294 dev_geo(dev
, "New camera output %ux%u\n", mf
->width
, mf
->height
);
1295 scale_cam_h
= calc_generic_scale(cam_rect
->width
, mf
->width
);
1296 scale_cam_v
= calc_generic_scale(cam_rect
->height
, mf
->height
);
1297 interm_width
= scale_down(rect
->width
, scale_cam_h
);
1298 interm_height
= scale_down(rect
->height
, scale_cam_v
);
1301 /* Cache camera output window */
1302 cam
->width
= mf
->width
;
1303 cam
->height
= mf
->height
;
1305 if (pcdev
->image_mode
) {
1306 out_width
= min(interm_width
, icd
->user_width
);
1307 out_height
= min(interm_height
, icd
->user_height
);
1309 out_width
= interm_width
;
1310 out_height
= interm_height
;
1314 * 5. Calculate CEU scales from camera scales from results of (5) and
1317 scale_ceu_h
= calc_scale(interm_width
, &out_width
);
1318 scale_ceu_v
= calc_scale(interm_height
, &out_height
);
1320 dev_geo(dev
, "5: CEU scales %u:%u\n", scale_ceu_h
, scale_ceu_v
);
1322 /* Apply CEU scales. */
1323 cflcr
= scale_ceu_h
| (scale_ceu_v
<< 16);
1324 if (cflcr
!= pcdev
->cflcr
) {
1325 pcdev
->cflcr
= cflcr
;
1326 ceu_write(pcdev
, CFLCR
, cflcr
);
1329 icd
->user_width
= out_width
& ~3;
1330 icd
->user_height
= out_height
& ~3;
1331 /* Offsets are applied at the CEU scaling filter input */
1332 cam
->ceu_left
= scale_down(rect
->left
- cam_rect
->left
, scale_cam_h
) & ~1;
1333 cam
->ceu_top
= scale_down(rect
->top
- cam_rect
->top
, scale_cam_v
) & ~1;
1335 /* 6. Use CEU cropping to crop to the new window. */
1336 sh_mobile_ceu_set_rect(icd
);
1338 cam
->subrect
= *rect
;
1340 dev_geo(dev
, "6: CEU cropped to %ux%u@%u:%u\n",
1341 icd
->user_width
, icd
->user_height
,
1342 cam
->ceu_left
, cam
->ceu_top
);
1344 /* Restore capture. The CE bit can be cleared by the hardware */
1347 capture_restore(pcdev
, capsr
);
1349 /* Even if only camera cropping succeeded */
1353 static int sh_mobile_ceu_get_crop(struct soc_camera_device
*icd
,
1354 struct v4l2_crop
*a
)
1356 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
1358 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1359 a
->c
= cam
->subrect
;
1364 /* Similar to set_crop multistage iterative algorithm */
1365 static int sh_mobile_ceu_set_fmt(struct soc_camera_device
*icd
,
1366 struct v4l2_format
*f
)
1368 struct device
*dev
= icd
->parent
;
1369 struct soc_camera_host
*ici
= to_soc_camera_host(dev
);
1370 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1371 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
1372 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
1373 struct v4l2_mbus_framefmt mf
;
1374 __u32 pixfmt
= pix
->pixelformat
;
1375 const struct soc_camera_format_xlate
*xlate
;
1376 unsigned int ceu_sub_width
= pcdev
->max_width
,
1377 ceu_sub_height
= pcdev
->max_height
;
1378 u16 scale_v
, scale_h
;
1381 enum v4l2_field field
;
1383 switch (pix
->field
) {
1385 pix
->field
= V4L2_FIELD_NONE
;
1387 case V4L2_FIELD_INTERLACED_TB
:
1388 case V4L2_FIELD_INTERLACED_BT
:
1389 case V4L2_FIELD_NONE
:
1392 case V4L2_FIELD_INTERLACED
:
1393 field
= V4L2_FIELD_INTERLACED_TB
;
1397 xlate
= soc_camera_xlate_by_fourcc(icd
, pixfmt
);
1399 dev_warn(dev
, "Format %x not found\n", pixfmt
);
1403 /* 1.-4. Calculate desired client output geometry */
1404 soc_camera_calc_client_output(icd
, &cam
->rect
, &cam
->subrect
, pix
, &mf
, 12);
1405 mf
.field
= pix
->field
;
1406 mf
.colorspace
= pix
->colorspace
;
1407 mf
.code
= xlate
->code
;
1410 case V4L2_PIX_FMT_NV12
:
1411 case V4L2_PIX_FMT_NV21
:
1412 case V4L2_PIX_FMT_NV16
:
1413 case V4L2_PIX_FMT_NV61
:
1420 dev_geo(dev
, "S_FMT(pix=0x%x, fld 0x%x, code 0x%x, %ux%u)\n", pixfmt
, mf
.field
, mf
.code
,
1421 pix
->width
, pix
->height
);
1423 dev_geo(dev
, "4: request camera output %ux%u\n", mf
.width
, mf
.height
);
1426 ret
= soc_camera_client_scale(icd
, &cam
->rect
, &cam
->subrect
,
1427 &mf
, &ceu_sub_width
, &ceu_sub_height
,
1428 image_mode
&& V4L2_FIELD_NONE
== field
, 12);
1430 dev_geo(dev
, "5-9: client scale return %d\n", ret
);
1432 /* Done with the camera. Now see if we can improve the result */
1434 dev_geo(dev
, "fmt %ux%u, requested %ux%u\n",
1435 mf
.width
, mf
.height
, pix
->width
, pix
->height
);
1439 if (mf
.code
!= xlate
->code
)
1442 /* 9. Prepare CEU crop */
1443 cam
->width
= mf
.width
;
1444 cam
->height
= mf
.height
;
1446 /* 10. Use CEU scaling to scale to the requested user window. */
1448 /* We cannot scale up */
1449 if (pix
->width
> ceu_sub_width
)
1450 ceu_sub_width
= pix
->width
;
1452 if (pix
->height
> ceu_sub_height
)
1453 ceu_sub_height
= pix
->height
;
1455 pix
->colorspace
= mf
.colorspace
;
1458 /* Scale pix->{width x height} down to width x height */
1459 scale_h
= calc_scale(ceu_sub_width
, &pix
->width
);
1460 scale_v
= calc_scale(ceu_sub_height
, &pix
->height
);
1462 pix
->width
= ceu_sub_width
;
1463 pix
->height
= ceu_sub_height
;
1468 pcdev
->cflcr
= scale_h
| (scale_v
<< 16);
1471 * We have calculated CFLCR, the actual configuration will be performed
1472 * in sh_mobile_ceu_set_bus_param()
1475 dev_geo(dev
, "10: W: %u : 0x%x = %u, H: %u : 0x%x = %u\n",
1476 ceu_sub_width
, scale_h
, pix
->width
,
1477 ceu_sub_height
, scale_v
, pix
->height
);
1479 cam
->code
= xlate
->code
;
1480 icd
->current_fmt
= xlate
;
1482 pcdev
->field
= field
;
1483 pcdev
->image_mode
= image_mode
;
1485 /* CFSZR requirement */
1492 #define CEU_CHDW_MAX 8188U /* Maximum line stride */
1494 static int sh_mobile_ceu_try_fmt(struct soc_camera_device
*icd
,
1495 struct v4l2_format
*f
)
1497 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1498 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1499 const struct soc_camera_format_xlate
*xlate
;
1500 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
1501 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1502 struct v4l2_subdev_pad_config pad_cfg
;
1503 struct v4l2_subdev_format format
= {
1504 .which
= V4L2_SUBDEV_FORMAT_TRY
,
1506 struct v4l2_mbus_framefmt
*mf
= &format
.format
;
1507 __u32 pixfmt
= pix
->pixelformat
;
1511 dev_geo(icd
->parent
, "TRY_FMT(pix=0x%x, %ux%u)\n",
1512 pixfmt
, pix
->width
, pix
->height
);
1514 xlate
= soc_camera_xlate_by_fourcc(icd
, pixfmt
);
1516 xlate
= icd
->current_fmt
;
1517 dev_dbg(icd
->parent
, "Format %x not found, keeping %x\n",
1518 pixfmt
, xlate
->host_fmt
->fourcc
);
1519 pixfmt
= xlate
->host_fmt
->fourcc
;
1520 pix
->pixelformat
= pixfmt
;
1521 pix
->colorspace
= icd
->colorspace
;
1524 /* FIXME: calculate using depth and bus width */
1526 /* CFSZR requires height and width to be 4-pixel aligned */
1527 v4l_bound_align_image(&pix
->width
, 2, pcdev
->max_width
, 2,
1528 &pix
->height
, 4, pcdev
->max_height
, 2, 0);
1531 height
= pix
->height
;
1533 /* limit to sensor capabilities */
1534 mf
->width
= pix
->width
;
1535 mf
->height
= pix
->height
;
1536 mf
->field
= pix
->field
;
1537 mf
->code
= xlate
->code
;
1538 mf
->colorspace
= pix
->colorspace
;
1540 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
, soc_camera_grp_id(icd
),
1541 pad
, set_fmt
, &pad_cfg
, &format
);
1545 pix
->width
= mf
->width
;
1546 pix
->height
= mf
->height
;
1547 pix
->field
= mf
->field
;
1548 pix
->colorspace
= mf
->colorspace
;
1551 case V4L2_PIX_FMT_NV12
:
1552 case V4L2_PIX_FMT_NV21
:
1553 case V4L2_PIX_FMT_NV16
:
1554 case V4L2_PIX_FMT_NV61
:
1555 /* FIXME: check against rect_max after converting soc-camera */
1556 /* We can scale precisely, need a bigger image from camera */
1557 if (pix
->width
< width
|| pix
->height
< height
) {
1559 * We presume, the sensor behaves sanely, i.e., if
1560 * requested a bigger rectangle, it will not return a
1563 mf
->width
= pcdev
->max_width
;
1564 mf
->height
= pcdev
->max_height
;
1565 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
,
1566 soc_camera_grp_id(icd
), pad
,
1567 set_fmt
, &pad_cfg
, &format
);
1569 /* Shouldn't actually happen... */
1570 dev_err(icd
->parent
,
1571 "FIXME: client try_fmt() = %d\n", ret
);
1575 /* We will scale exactly */
1576 if (mf
->width
> width
)
1578 if (mf
->height
> height
)
1579 pix
->height
= height
;
1581 pix
->bytesperline
= max(pix
->bytesperline
, pix
->width
);
1582 pix
->bytesperline
= min(pix
->bytesperline
, CEU_CHDW_MAX
);
1583 pix
->bytesperline
&= ~3;
1587 /* Configurable stride isn't supported in pass-through mode. */
1588 pix
->bytesperline
= 0;
1595 dev_geo(icd
->parent
, "%s(): return %d, fmt 0x%x, %ux%u\n",
1596 __func__
, ret
, pix
->pixelformat
, pix
->width
, pix
->height
);
1601 static int sh_mobile_ceu_set_livecrop(struct soc_camera_device
*icd
,
1602 const struct v4l2_crop
*a
)
1604 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1605 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1606 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1607 u32 out_width
= icd
->user_width
, out_height
= icd
->user_height
;
1612 /* Wait for frame */
1613 ret
= wait_for_completion_interruptible(&pcdev
->complete
);
1614 /* Stop the client */
1615 ret
= v4l2_subdev_call(sd
, video
, s_stream
, 0);
1617 dev_warn(icd
->parent
,
1618 "Client failed to stop the stream: %d\n", ret
);
1620 /* Do the crop, if it fails, there's nothing more we can do */
1621 sh_mobile_ceu_set_crop(icd
, a
);
1623 dev_geo(icd
->parent
, "Output after crop: %ux%u\n", icd
->user_width
, icd
->user_height
);
1625 if (icd
->user_width
!= out_width
|| icd
->user_height
!= out_height
) {
1626 struct v4l2_format f
= {
1627 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
1630 .height
= out_height
,
1631 .pixelformat
= icd
->current_fmt
->host_fmt
->fourcc
,
1632 .field
= pcdev
->field
,
1633 .colorspace
= icd
->colorspace
,
1636 ret
= sh_mobile_ceu_set_fmt(icd
, &f
);
1637 if (!ret
&& (out_width
!= f
.fmt
.pix
.width
||
1638 out_height
!= f
.fmt
.pix
.height
))
1641 icd
->user_width
= out_width
& ~3;
1642 icd
->user_height
= out_height
& ~3;
1643 ret
= sh_mobile_ceu_set_bus_param(icd
);
1647 /* Thaw the queue */
1649 spin_lock_irq(&pcdev
->lock
);
1650 sh_mobile_ceu_capture(pcdev
);
1651 spin_unlock_irq(&pcdev
->lock
);
1652 /* Start the client */
1653 ret
= v4l2_subdev_call(sd
, video
, s_stream
, 1);
1657 static unsigned int sh_mobile_ceu_poll(struct file
*file
, poll_table
*pt
)
1659 struct soc_camera_device
*icd
= file
->private_data
;
1661 return vb2_poll(&icd
->vb2_vidq
, file
, pt
);
1664 static int sh_mobile_ceu_querycap(struct soc_camera_host
*ici
,
1665 struct v4l2_capability
*cap
)
1667 strlcpy(cap
->card
, "SuperH_Mobile_CEU", sizeof(cap
->card
));
1668 cap
->device_caps
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
1669 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
1674 static int sh_mobile_ceu_init_videobuf(struct vb2_queue
*q
,
1675 struct soc_camera_device
*icd
)
1677 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1679 q
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1680 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
;
1682 q
->ops
= &sh_mobile_ceu_videobuf_ops
;
1683 q
->mem_ops
= &vb2_dma_contig_memops
;
1684 q
->buf_struct_size
= sizeof(struct sh_mobile_ceu_buffer
);
1685 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1686 q
->lock
= &ici
->host_lock
;
1688 return vb2_queue_init(q
);
1691 static struct soc_camera_host_ops sh_mobile_ceu_host_ops
= {
1692 .owner
= THIS_MODULE
,
1693 .add
= sh_mobile_ceu_add_device
,
1694 .remove
= sh_mobile_ceu_remove_device
,
1695 .clock_start
= sh_mobile_ceu_clock_start
,
1696 .clock_stop
= sh_mobile_ceu_clock_stop
,
1697 .get_formats
= sh_mobile_ceu_get_formats
,
1698 .put_formats
= sh_mobile_ceu_put_formats
,
1699 .get_crop
= sh_mobile_ceu_get_crop
,
1700 .set_crop
= sh_mobile_ceu_set_crop
,
1701 .set_livecrop
= sh_mobile_ceu_set_livecrop
,
1702 .set_fmt
= sh_mobile_ceu_set_fmt
,
1703 .try_fmt
= sh_mobile_ceu_try_fmt
,
1704 .poll
= sh_mobile_ceu_poll
,
1705 .querycap
= sh_mobile_ceu_querycap
,
1706 .set_bus_param
= sh_mobile_ceu_set_bus_param
,
1707 .init_videobuf2
= sh_mobile_ceu_init_videobuf
,
1711 struct notifier_block notifier
;
1712 struct completion completion
;
1716 static int bus_notify(struct notifier_block
*nb
,
1717 unsigned long action
, void *data
)
1719 struct device
*dev
= data
;
1720 struct bus_wait
*wait
= container_of(nb
, struct bus_wait
, notifier
);
1722 if (wait
->dev
!= dev
)
1726 case BUS_NOTIFY_UNBOUND_DRIVER
:
1727 /* Protect from module unloading */
1728 wait_for_completion(&wait
->completion
);
1734 static int sh_mobile_ceu_probe(struct platform_device
*pdev
)
1736 struct sh_mobile_ceu_dev
*pcdev
;
1737 struct resource
*res
;
1741 struct bus_wait wait
= {
1742 .completion
= COMPLETION_INITIALIZER_ONSTACK(wait
.completion
),
1743 .notifier
.notifier_call
= bus_notify
,
1745 struct sh_mobile_ceu_companion
*csi2
;
1747 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1748 irq
= platform_get_irq(pdev
, 0);
1749 if (!res
|| (int)irq
<= 0) {
1750 dev_err(&pdev
->dev
, "Not enough CEU platform resources.\n");
1754 pcdev
= devm_kzalloc(&pdev
->dev
, sizeof(*pcdev
), GFP_KERNEL
);
1756 dev_err(&pdev
->dev
, "Could not allocate pcdev\n");
1760 INIT_LIST_HEAD(&pcdev
->capture
);
1761 spin_lock_init(&pcdev
->lock
);
1762 init_completion(&pcdev
->complete
);
1764 pcdev
->pdata
= pdev
->dev
.platform_data
;
1765 if (!pcdev
->pdata
&& !pdev
->dev
.of_node
) {
1766 dev_err(&pdev
->dev
, "CEU platform data not set.\n");
1770 /* TODO: implement per-device bus flags */
1772 pcdev
->max_width
= pcdev
->pdata
->max_width
;
1773 pcdev
->max_height
= pcdev
->pdata
->max_height
;
1774 pcdev
->flags
= pcdev
->pdata
->flags
;
1777 if (!pcdev
->max_width
) {
1779 err
= of_property_read_u32(pdev
->dev
.of_node
, "renesas,max-width", &v
);
1781 pcdev
->max_width
= v
;
1783 if (!pcdev
->max_width
)
1784 pcdev
->max_width
= 2560;
1786 if (!pcdev
->max_height
) {
1788 err
= of_property_read_u32(pdev
->dev
.of_node
, "renesas,max-height", &v
);
1790 pcdev
->max_height
= v
;
1792 if (!pcdev
->max_height
)
1793 pcdev
->max_height
= 1920;
1796 base
= devm_ioremap_resource(&pdev
->dev
, res
);
1798 return PTR_ERR(base
);
1802 pcdev
->video_limit
= 0; /* only enabled if second resource exists */
1804 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1806 err
= dma_declare_coherent_memory(&pdev
->dev
, res
->start
,
1810 DMA_MEMORY_EXCLUSIVE
);
1812 dev_err(&pdev
->dev
, "Unable to declare CEU memory.\n");
1816 pcdev
->video_limit
= resource_size(res
);
1820 err
= devm_request_irq(&pdev
->dev
, pcdev
->irq
, sh_mobile_ceu_irq
,
1821 0, dev_name(&pdev
->dev
), pcdev
);
1823 dev_err(&pdev
->dev
, "Unable to register CEU interrupt.\n");
1824 goto exit_release_mem
;
1827 pm_suspend_ignore_children(&pdev
->dev
, true);
1828 pm_runtime_enable(&pdev
->dev
);
1829 pm_runtime_resume(&pdev
->dev
);
1831 pcdev
->ici
.priv
= pcdev
;
1832 pcdev
->ici
.v4l2_dev
.dev
= &pdev
->dev
;
1833 pcdev
->ici
.nr
= pdev
->id
;
1834 pcdev
->ici
.drv_name
= dev_name(&pdev
->dev
);
1835 pcdev
->ici
.ops
= &sh_mobile_ceu_host_ops
;
1836 pcdev
->ici
.capabilities
= SOCAM_HOST_CAP_STRIDE
;
1838 pcdev
->alloc_ctx
= vb2_dma_contig_init_ctx(&pdev
->dev
);
1839 if (IS_ERR(pcdev
->alloc_ctx
)) {
1840 err
= PTR_ERR(pcdev
->alloc_ctx
);
1844 if (pcdev
->pdata
&& pcdev
->pdata
->asd_sizes
) {
1845 struct v4l2_async_subdev
**asd
;
1846 char name
[] = "sh-mobile-csi2";
1850 * CSI2 interfacing: several groups can use CSI2, pick up the
1853 asd
= pcdev
->pdata
->asd
;
1854 for (j
= 0; pcdev
->pdata
->asd_sizes
[j
]; j
++) {
1855 for (i
= 0; i
< pcdev
->pdata
->asd_sizes
[j
]; i
++, asd
++) {
1856 dev_dbg(&pdev
->dev
, "%s(): subdev #%d, type %u\n",
1857 __func__
, i
, (*asd
)->match_type
);
1858 if ((*asd
)->match_type
== V4L2_ASYNC_MATCH_DEVNAME
&&
1859 !strncmp(name
, (*asd
)->match
.device_name
.name
,
1860 sizeof(name
) - 1)) {
1861 pcdev
->csi2_asd
= *asd
;
1865 if (pcdev
->csi2_asd
)
1869 pcdev
->ici
.asd
= pcdev
->pdata
->asd
;
1870 pcdev
->ici
.asd_sizes
= pcdev
->pdata
->asd_sizes
;
1873 /* Legacy CSI2 interfacing */
1874 csi2
= pcdev
->pdata
? pcdev
->pdata
->csi2
: NULL
;
1877 * TODO: remove this once all users are converted to
1878 * asynchronous CSI2 probing. If it has to be kept, csi2
1879 * platform device resources have to be added, using
1880 * platform_device_add_resources()
1882 struct platform_device
*csi2_pdev
=
1883 platform_device_alloc("sh-mobile-csi2", csi2
->id
);
1884 struct sh_csi2_pdata
*csi2_pdata
= csi2
->platform_data
;
1891 pcdev
->csi2_pdev
= csi2_pdev
;
1893 err
= platform_device_add_data(csi2_pdev
, csi2_pdata
,
1894 sizeof(*csi2_pdata
));
1898 csi2_pdev
->resource
= csi2
->resource
;
1899 csi2_pdev
->num_resources
= csi2
->num_resources
;
1901 err
= platform_device_add(csi2_pdev
);
1905 wait
.dev
= &csi2_pdev
->dev
;
1907 err
= bus_register_notifier(&platform_bus_type
, &wait
.notifier
);
1909 goto exit_pdev_unregister
;
1912 * From this point the driver module will not unload, until
1913 * we complete the completion.
1916 if (!csi2_pdev
->dev
.driver
) {
1917 complete(&wait
.completion
);
1918 /* Either too late, or probing failed */
1919 bus_unregister_notifier(&platform_bus_type
, &wait
.notifier
);
1921 goto exit_pdev_unregister
;
1925 * The module is still loaded, in the worst case it is hanging
1926 * in device release on our completion. So, _now_ dereferencing
1927 * the "owner" is safe!
1930 err
= try_module_get(csi2_pdev
->dev
.driver
->owner
);
1932 /* Let notifier complete, if it has been locked */
1933 complete(&wait
.completion
);
1934 bus_unregister_notifier(&platform_bus_type
, &wait
.notifier
);
1937 goto exit_pdev_unregister
;
1940 pcdev
->csi2_sd
= platform_get_drvdata(csi2_pdev
);
1943 err
= soc_camera_host_register(&pcdev
->ici
);
1945 goto exit_csi2_unregister
;
1948 err
= v4l2_device_register_subdev(&pcdev
->ici
.v4l2_dev
,
1950 dev_dbg(&pdev
->dev
, "%s(): ret(register_subdev) = %d\n",
1953 goto exit_host_unregister
;
1954 /* v4l2_device_register_subdev() took a reference too */
1955 module_put(pcdev
->csi2_sd
->owner
);
1960 exit_host_unregister
:
1961 soc_camera_host_unregister(&pcdev
->ici
);
1962 exit_csi2_unregister
:
1964 module_put(pcdev
->csi2_pdev
->dev
.driver
->owner
);
1965 exit_pdev_unregister
:
1966 platform_device_del(pcdev
->csi2_pdev
);
1968 pcdev
->csi2_pdev
->resource
= NULL
;
1969 platform_device_put(pcdev
->csi2_pdev
);
1972 vb2_dma_contig_cleanup_ctx(pcdev
->alloc_ctx
);
1974 pm_runtime_disable(&pdev
->dev
);
1976 if (platform_get_resource(pdev
, IORESOURCE_MEM
, 1))
1977 dma_release_declared_memory(&pdev
->dev
);
1981 static int sh_mobile_ceu_remove(struct platform_device
*pdev
)
1983 struct soc_camera_host
*soc_host
= to_soc_camera_host(&pdev
->dev
);
1984 struct sh_mobile_ceu_dev
*pcdev
= container_of(soc_host
,
1985 struct sh_mobile_ceu_dev
, ici
);
1986 struct platform_device
*csi2_pdev
= pcdev
->csi2_pdev
;
1988 soc_camera_host_unregister(soc_host
);
1989 pm_runtime_disable(&pdev
->dev
);
1990 if (platform_get_resource(pdev
, IORESOURCE_MEM
, 1))
1991 dma_release_declared_memory(&pdev
->dev
);
1992 vb2_dma_contig_cleanup_ctx(pcdev
->alloc_ctx
);
1993 if (csi2_pdev
&& csi2_pdev
->dev
.driver
) {
1994 struct module
*csi2_drv
= csi2_pdev
->dev
.driver
->owner
;
1995 platform_device_del(csi2_pdev
);
1996 csi2_pdev
->resource
= NULL
;
1997 platform_device_put(csi2_pdev
);
1998 module_put(csi2_drv
);
2004 static int sh_mobile_ceu_runtime_nop(struct device
*dev
)
2006 /* Runtime PM callback shared between ->runtime_suspend()
2007 * and ->runtime_resume(). Simply returns success.
2009 * This driver re-initializes all registers after
2010 * pm_runtime_get_sync() anyway so there is no need
2011 * to save and restore registers here.
2016 static const struct dev_pm_ops sh_mobile_ceu_dev_pm_ops
= {
2017 .runtime_suspend
= sh_mobile_ceu_runtime_nop
,
2018 .runtime_resume
= sh_mobile_ceu_runtime_nop
,
2021 static const struct of_device_id sh_mobile_ceu_of_match
[] = {
2022 { .compatible
= "renesas,sh-mobile-ceu" },
2025 MODULE_DEVICE_TABLE(of
, sh_mobile_ceu_of_match
);
2027 static struct platform_driver sh_mobile_ceu_driver
= {
2029 .name
= "sh_mobile_ceu",
2030 .pm
= &sh_mobile_ceu_dev_pm_ops
,
2031 .of_match_table
= sh_mobile_ceu_of_match
,
2033 .probe
= sh_mobile_ceu_probe
,
2034 .remove
= sh_mobile_ceu_remove
,
2037 static int __init
sh_mobile_ceu_init(void)
2039 /* Whatever return code */
2040 request_module("sh_mobile_csi2");
2041 return platform_driver_register(&sh_mobile_ceu_driver
);
2044 static void __exit
sh_mobile_ceu_exit(void)
2046 platform_driver_unregister(&sh_mobile_ceu_driver
);
2049 module_init(sh_mobile_ceu_init
);
2050 module_exit(sh_mobile_ceu_exit
);
2052 MODULE_DESCRIPTION("SuperH Mobile CEU driver");
2053 MODULE_AUTHOR("Magnus Damm");
2054 MODULE_LICENSE("GPL");
2055 MODULE_VERSION("0.1.0");
2056 MODULE_ALIAS("platform:sh_mobile_ceu");