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/drv-intf/sh_mobile_ceu.h>
44 #include <media/drv-intf/sh_mobile_csi2.h>
45 #include <media/videobuf2-dma-contig.h>
46 #include <media/v4l2-mediabus.h>
47 #include <media/drv-intf/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_v4l2_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_v4l2_buffer
*active
;
117 struct sh_mobile_ceu_info
*pdata
;
118 struct completion complete
;
122 /* static max sizes either from platform data or default */
126 enum v4l2_field field
;
130 unsigned int image_mode
:1;
131 unsigned int is_16bit
:1;
132 unsigned int frozen
:1;
135 struct sh_mobile_ceu_cam
{
136 /* CEU offsets within the camera output, before the CEU scaler */
137 unsigned int ceu_left
;
138 unsigned int ceu_top
;
139 /* Client output, as seen by the CEU */
143 * User window from S_CROP / G_CROP, produced by client cropping and
144 * scaling, CEU scaling and CEU cropping, mapped back onto the client
147 struct v4l2_rect subrect
;
148 /* Camera cropping rectangle */
149 struct v4l2_rect rect
;
150 const struct soc_mbus_pixelfmt
*extra_fmt
;
154 static struct sh_mobile_ceu_buffer
*to_ceu_vb(struct vb2_v4l2_buffer
*vbuf
)
156 return container_of(vbuf
, struct sh_mobile_ceu_buffer
, vb
);
159 static void ceu_write(struct sh_mobile_ceu_dev
*priv
,
160 unsigned long reg_offs
, u32 data
)
162 iowrite32(data
, priv
->base
+ reg_offs
);
165 static u32
ceu_read(struct sh_mobile_ceu_dev
*priv
, unsigned long reg_offs
)
167 return ioread32(priv
->base
+ reg_offs
);
170 static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev
*pcdev
)
174 ceu_write(pcdev
, CAPSR
, 1 << 16); /* reset */
176 /* wait CSTSR.CPTON bit */
177 for (i
= 0; i
< 1000; i
++) {
178 if (!(ceu_read(pcdev
, CSTSR
) & 1)) {
185 /* wait CAPSR.CPKIL bit */
186 for (i
= 0; i
< 1000; i
++) {
187 if (!(ceu_read(pcdev
, CAPSR
) & (1 << 16))) {
195 dev_warn(pcdev
->ici
.v4l2_dev
.dev
, "soft reset time out\n");
203 * Videobuf operations
207 * .queue_setup() is called to check, whether the driver can accept the
208 * requested number of buffers and to fill in plane sizes
209 * for the current frame format if required
211 static int sh_mobile_ceu_videobuf_setup(struct vb2_queue
*vq
,
212 unsigned int *count
, unsigned int *num_planes
,
213 unsigned int sizes
[], struct device
*alloc_devs
[])
215 struct soc_camera_device
*icd
= soc_camera_from_vb2q(vq
);
216 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
217 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
219 if (!vq
->num_buffers
)
225 /* Called from VIDIOC_REQBUFS or in compatibility mode */
227 sizes
[0] = icd
->sizeimage
;
228 else if (sizes
[0] < icd
->sizeimage
)
231 /* If *num_planes != 0, we have already verified *count. */
232 if (pcdev
->video_limit
) {
233 size_t size
= PAGE_ALIGN(sizes
[0]) * *count
;
235 if (size
+ pcdev
->buf_total
> pcdev
->video_limit
)
236 *count
= (pcdev
->video_limit
- pcdev
->buf_total
) /
237 PAGE_ALIGN(sizes
[0]);
242 dev_dbg(icd
->parent
, "count=%d, size=%u\n", *count
, sizes
[0]);
247 #define CEU_CETCR_MAGIC 0x0317f313 /* acknowledge magical interrupt sources */
248 #define CEU_CETCR_IGRW (1 << 4) /* prohibited register access interrupt bit */
249 #define CEU_CEIER_CPEIE (1 << 0) /* one-frame capture end interrupt */
250 #define CEU_CEIER_VBP (1 << 20) /* vbp error */
251 #define CEU_CAPCR_CTNCP (1 << 16) /* continuous capture mode (if set) */
252 #define CEU_CEIER_MASK (CEU_CEIER_CPEIE | CEU_CEIER_VBP)
256 * return value doesn't reflex the success/failure to queue the new buffer,
257 * but rather the status of the previous buffer.
259 static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev
*pcdev
)
261 struct soc_camera_device
*icd
= pcdev
->ici
.icd
;
262 dma_addr_t phys_addr_top
, phys_addr_bottom
;
263 unsigned long top1
, top2
;
264 unsigned long bottom1
, bottom2
;
270 * The hardware is _very_ picky about this sequence. Especially
271 * the CEU_CETCR_MAGIC value. It seems like we need to acknowledge
272 * several not-so-well documented interrupt sources in CETCR.
274 ceu_write(pcdev
, CEIER
, ceu_read(pcdev
, CEIER
) & ~CEU_CEIER_MASK
);
275 status
= ceu_read(pcdev
, CETCR
);
276 ceu_write(pcdev
, CETCR
, ~status
& CEU_CETCR_MAGIC
);
278 ceu_write(pcdev
, CEIER
, ceu_read(pcdev
, CEIER
) | CEU_CEIER_MASK
);
279 ceu_write(pcdev
, CAPCR
, ceu_read(pcdev
, CAPCR
) & ~CEU_CAPCR_CTNCP
);
280 ceu_write(pcdev
, CETCR
, CEU_CETCR_MAGIC
^ CEU_CETCR_IGRW
);
283 * When a VBP interrupt occurs, a capture end interrupt does not occur
284 * and the image of that frame is not captured correctly. So, soft reset
287 if (status
& CEU_CEIER_VBP
) {
288 sh_mobile_ceu_soft_reset(pcdev
);
293 complete(&pcdev
->complete
);
300 if (V4L2_FIELD_INTERLACED_BT
== pcdev
->field
) {
313 vb2_dma_contig_plane_dma_addr(&pcdev
->active
->vb2_buf
, 0);
315 switch (icd
->current_fmt
->host_fmt
->fourcc
) {
316 case V4L2_PIX_FMT_NV12
:
317 case V4L2_PIX_FMT_NV21
:
318 case V4L2_PIX_FMT_NV16
:
319 case V4L2_PIX_FMT_NV61
:
326 ceu_write(pcdev
, top1
, phys_addr_top
);
327 if (V4L2_FIELD_NONE
!= pcdev
->field
) {
328 phys_addr_bottom
= phys_addr_top
+ icd
->bytesperline
;
329 ceu_write(pcdev
, bottom1
, phys_addr_bottom
);
333 phys_addr_top
+= icd
->bytesperline
* icd
->user_height
;
334 ceu_write(pcdev
, top2
, phys_addr_top
);
335 if (V4L2_FIELD_NONE
!= pcdev
->field
) {
336 phys_addr_bottom
= phys_addr_top
+ icd
->bytesperline
;
337 ceu_write(pcdev
, bottom2
, phys_addr_bottom
);
341 ceu_write(pcdev
, CAPSR
, 0x1); /* start capture */
346 static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer
*vb
)
348 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
349 struct sh_mobile_ceu_buffer
*buf
= to_ceu_vb(vbuf
);
351 /* Added list head initialization on alloc */
352 WARN(!list_empty(&buf
->queue
), "Buffer %p on queue!\n", vb
);
357 static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer
*vb
)
359 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
360 struct soc_camera_device
*icd
= soc_camera_from_vb2q(vb
->vb2_queue
);
361 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
362 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
363 struct sh_mobile_ceu_buffer
*buf
= to_ceu_vb(vbuf
);
366 size
= icd
->sizeimage
;
368 if (vb2_plane_size(vb
, 0) < size
) {
369 dev_err(icd
->parent
, "Buffer #%d too small (%lu < %lu)\n",
370 vb
->index
, vb2_plane_size(vb
, 0), size
);
374 vb2_set_plane_payload(vb
, 0, size
);
376 dev_dbg(icd
->parent
, "%s (vb=0x%p) 0x%p %lu\n", __func__
,
377 vb
, vb2_plane_vaddr(vb
, 0), vb2_get_plane_payload(vb
, 0));
381 * This can be useful if you want to see if we actually fill
382 * the buffer with something
384 if (vb2_plane_vaddr(vb
, 0))
385 memset(vb2_plane_vaddr(vb
, 0), 0xaa, vb2_get_plane_payload(vb
, 0));
388 spin_lock_irq(&pcdev
->lock
);
389 list_add_tail(&buf
->queue
, &pcdev
->capture
);
391 if (!pcdev
->active
) {
393 * Because there were no active buffer at this moment,
394 * we are not interested in the return value of
395 * sh_mobile_ceu_capture here.
397 pcdev
->active
= vbuf
;
398 sh_mobile_ceu_capture(pcdev
);
400 spin_unlock_irq(&pcdev
->lock
);
405 vb2_buffer_done(vb
, VB2_BUF_STATE_ERROR
);
408 static void sh_mobile_ceu_videobuf_release(struct vb2_buffer
*vb
)
410 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
411 struct soc_camera_device
*icd
= soc_camera_from_vb2q(vb
->vb2_queue
);
412 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
413 struct sh_mobile_ceu_buffer
*buf
= to_ceu_vb(vbuf
);
414 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
416 spin_lock_irq(&pcdev
->lock
);
418 if (pcdev
->active
== vbuf
) {
419 /* disable capture (release DMA buffer), reset */
420 ceu_write(pcdev
, CAPSR
, 1 << 16);
421 pcdev
->active
= NULL
;
425 * Doesn't hurt also if the list is empty, but it hurts, if queuing the
426 * buffer failed, and .buf_init() hasn't been called
429 list_del_init(&buf
->queue
);
431 pcdev
->buf_total
-= PAGE_ALIGN(vb2_plane_size(vb
, 0));
432 dev_dbg(icd
->parent
, "%s() %zu bytes buffers\n", __func__
,
435 spin_unlock_irq(&pcdev
->lock
);
438 static int sh_mobile_ceu_videobuf_init(struct vb2_buffer
*vb
)
440 struct vb2_v4l2_buffer
*vbuf
= to_vb2_v4l2_buffer(vb
);
441 struct soc_camera_device
*icd
= soc_camera_from_vb2q(vb
->vb2_queue
);
442 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
443 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
445 pcdev
->buf_total
+= PAGE_ALIGN(vb2_plane_size(vb
, 0));
446 dev_dbg(icd
->parent
, "%s() %zu bytes buffers\n", __func__
,
449 /* This is for locking debugging only */
450 INIT_LIST_HEAD(&to_ceu_vb(vbuf
)->queue
);
454 static void sh_mobile_ceu_stop_streaming(struct vb2_queue
*q
)
456 struct soc_camera_device
*icd
= soc_camera_from_vb2q(q
);
457 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
458 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
459 struct list_head
*buf_head
, *tmp
;
461 spin_lock_irq(&pcdev
->lock
);
463 pcdev
->active
= NULL
;
465 list_for_each_safe(buf_head
, tmp
, &pcdev
->capture
)
466 list_del_init(buf_head
);
468 spin_unlock_irq(&pcdev
->lock
);
470 sh_mobile_ceu_soft_reset(pcdev
);
473 static struct vb2_ops sh_mobile_ceu_videobuf_ops
= {
474 .queue_setup
= sh_mobile_ceu_videobuf_setup
,
475 .buf_prepare
= sh_mobile_ceu_videobuf_prepare
,
476 .buf_queue
= sh_mobile_ceu_videobuf_queue
,
477 .buf_cleanup
= sh_mobile_ceu_videobuf_release
,
478 .buf_init
= sh_mobile_ceu_videobuf_init
,
479 .wait_prepare
= vb2_ops_wait_prepare
,
480 .wait_finish
= vb2_ops_wait_finish
,
481 .stop_streaming
= sh_mobile_ceu_stop_streaming
,
484 static irqreturn_t
sh_mobile_ceu_irq(int irq
, void *data
)
486 struct sh_mobile_ceu_dev
*pcdev
= data
;
487 struct vb2_v4l2_buffer
*vbuf
;
490 spin_lock(&pcdev
->lock
);
492 vbuf
= pcdev
->active
;
494 /* Stale interrupt from a released buffer */
497 list_del_init(&to_ceu_vb(vbuf
)->queue
);
499 if (!list_empty(&pcdev
->capture
))
500 pcdev
->active
= &list_entry(pcdev
->capture
.next
,
501 struct sh_mobile_ceu_buffer
, queue
)->vb
;
503 pcdev
->active
= NULL
;
505 ret
= sh_mobile_ceu_capture(pcdev
);
506 vbuf
->vb2_buf
.timestamp
= ktime_get_ns();
508 vbuf
->field
= pcdev
->field
;
509 vbuf
->sequence
= pcdev
->sequence
++;
511 vb2_buffer_done(&vbuf
->vb2_buf
,
512 ret
< 0 ? VB2_BUF_STATE_ERROR
: VB2_BUF_STATE_DONE
);
515 spin_unlock(&pcdev
->lock
);
520 static struct v4l2_subdev
*find_csi2(struct sh_mobile_ceu_dev
*pcdev
)
522 struct v4l2_subdev
*sd
;
525 return pcdev
->csi2_sd
;
527 if (pcdev
->csi2_asd
) {
528 char name
[] = "sh-mobile-csi2";
529 v4l2_device_for_each_subdev(sd
, &pcdev
->ici
.v4l2_dev
)
530 if (!strncmp(name
, sd
->name
, sizeof(name
) - 1)) {
539 static struct v4l2_subdev
*csi2_subdev(struct sh_mobile_ceu_dev
*pcdev
,
540 struct soc_camera_device
*icd
)
542 struct v4l2_subdev
*sd
= pcdev
->csi2_sd
;
544 return sd
&& sd
->grp_id
== soc_camera_grp_id(icd
) ? sd
: NULL
;
547 static int sh_mobile_ceu_add_device(struct soc_camera_device
*icd
)
549 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
550 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
551 struct v4l2_subdev
*csi2_sd
= find_csi2(pcdev
);
555 csi2_sd
->grp_id
= soc_camera_grp_id(icd
);
556 v4l2_set_subdev_hostdata(csi2_sd
, icd
);
559 ret
= v4l2_subdev_call(csi2_sd
, core
, s_power
, 1);
560 if (ret
< 0 && ret
!= -ENOIOCTLCMD
&& ret
!= -ENODEV
)
564 * -ENODEV is special: either csi2_sd == NULL or the CSI-2 driver
565 * has not found this soc-camera device among its clients
567 if (csi2_sd
&& ret
== -ENODEV
)
570 dev_info(icd
->parent
,
571 "SuperH Mobile CEU%s driver attached to camera %d\n",
572 csi2_sd
&& csi2_sd
->grp_id
? "/CSI-2" : "", icd
->devnum
);
577 static void sh_mobile_ceu_remove_device(struct soc_camera_device
*icd
)
579 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
580 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
581 struct v4l2_subdev
*csi2_sd
= find_csi2(pcdev
);
583 dev_info(icd
->parent
,
584 "SuperH Mobile CEU driver detached from camera %d\n",
587 v4l2_subdev_call(csi2_sd
, core
, s_power
, 0);
590 /* Called with .host_lock held */
591 static int sh_mobile_ceu_clock_start(struct soc_camera_host
*ici
)
593 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
595 pm_runtime_get_sync(ici
->v4l2_dev
.dev
);
597 pcdev
->buf_total
= 0;
599 sh_mobile_ceu_soft_reset(pcdev
);
604 /* Called with .host_lock held */
605 static void sh_mobile_ceu_clock_stop(struct soc_camera_host
*ici
)
607 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
609 /* disable capture, disable interrupts */
610 ceu_write(pcdev
, CEIER
, 0);
611 sh_mobile_ceu_soft_reset(pcdev
);
613 /* make sure active buffer is canceled */
614 spin_lock_irq(&pcdev
->lock
);
616 list_del_init(&to_ceu_vb(pcdev
->active
)->queue
);
617 vb2_buffer_done(&pcdev
->active
->vb2_buf
, VB2_BUF_STATE_ERROR
);
618 pcdev
->active
= NULL
;
620 spin_unlock_irq(&pcdev
->lock
);
622 pm_runtime_put(ici
->v4l2_dev
.dev
);
626 * See chapter 29.4.12 "Capture Filter Control Register (CFLCR)"
627 * in SH7722 Hardware Manual
629 static unsigned int size_dst(unsigned int src
, unsigned int scale
)
631 unsigned int mant_pre
= scale
>> 12;
634 return ((mant_pre
+ 2 * (src
- 1)) / (2 * mant_pre
) - 1) *
635 mant_pre
* 4096 / scale
+ 1;
638 static u16
calc_scale(unsigned int src
, unsigned int *dst
)
645 scale
= (src
* 4096 / *dst
) & ~7;
647 while (scale
> 4096 && size_dst(src
, scale
) < *dst
)
650 *dst
= size_dst(src
, scale
);
655 /* rect is guaranteed to not exceed the scaled camera rectangle */
656 static void sh_mobile_ceu_set_rect(struct soc_camera_device
*icd
)
658 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
659 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
660 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
661 unsigned int height
, width
, cdwdr_width
, in_width
, in_height
;
662 unsigned int left_offset
, top_offset
;
665 dev_geo(icd
->parent
, "Crop %ux%u@%u:%u\n",
666 icd
->user_width
, icd
->user_height
, cam
->ceu_left
, cam
->ceu_top
);
668 left_offset
= cam
->ceu_left
;
669 top_offset
= cam
->ceu_top
;
671 WARN_ON(icd
->user_width
& 3 || icd
->user_height
& 3);
673 width
= icd
->user_width
;
675 if (pcdev
->image_mode
) {
676 in_width
= cam
->width
;
677 if (!pcdev
->is_16bit
) {
682 unsigned int w_factor
;
684 switch (icd
->current_fmt
->host_fmt
->packing
) {
685 case SOC_MBUS_PACKING_2X8_PADHI
:
692 in_width
= cam
->width
* w_factor
;
693 left_offset
*= w_factor
;
696 cdwdr_width
= icd
->bytesperline
;
698 height
= icd
->user_height
;
699 in_height
= cam
->height
;
700 if (V4L2_FIELD_NONE
!= pcdev
->field
) {
701 height
= (height
/ 2) & ~3;
707 /* CSI2 special configuration */
708 if (csi2_subdev(pcdev
, icd
)) {
709 in_width
= ((in_width
- 2) * 2);
713 /* Set CAMOR, CAPWR, CFSZR, take care of CDWDR */
714 camor
= left_offset
| (top_offset
<< 16);
717 "CAMOR 0x%x, CAPWR 0x%x, CFSZR 0x%x, CDWDR 0x%x\n", camor
,
718 (in_height
<< 16) | in_width
, (height
<< 16) | width
,
721 ceu_write(pcdev
, CAMOR
, camor
);
722 ceu_write(pcdev
, CAPWR
, (in_height
<< 16) | in_width
);
723 /* CFSZR clipping is applied _after_ the scaling filter (CFLCR) */
724 ceu_write(pcdev
, CFSZR
, (height
<< 16) | width
);
725 ceu_write(pcdev
, CDWDR
, cdwdr_width
);
728 static u32
capture_save_reset(struct sh_mobile_ceu_dev
*pcdev
)
730 u32 capsr
= ceu_read(pcdev
, CAPSR
);
731 ceu_write(pcdev
, CAPSR
, 1 << 16); /* reset, stop capture */
735 static void capture_restore(struct sh_mobile_ceu_dev
*pcdev
, u32 capsr
)
737 unsigned long timeout
= jiffies
+ 10 * HZ
;
740 * Wait until the end of the current frame. It can take a long time,
741 * but if it has been aborted by a CAPSR reset, it shoule exit sooner.
743 while ((ceu_read(pcdev
, CSTSR
) & 1) && time_before(jiffies
, timeout
))
746 if (time_after(jiffies
, timeout
)) {
747 dev_err(pcdev
->ici
.v4l2_dev
.dev
,
748 "Timeout waiting for frame end! Interface problem?\n");
752 /* Wait until reset clears, this shall not hang... */
753 while (ceu_read(pcdev
, CAPSR
) & (1 << 16))
756 /* Anything to restore? */
757 if (capsr
& ~(1 << 16))
758 ceu_write(pcdev
, CAPSR
, capsr
);
761 /* Find the bus subdevice driver, e.g., CSI2 */
762 static struct v4l2_subdev
*find_bus_subdev(struct sh_mobile_ceu_dev
*pcdev
,
763 struct soc_camera_device
*icd
)
765 return csi2_subdev(pcdev
, icd
) ? : soc_camera_to_subdev(icd
);
768 #define CEU_BUS_FLAGS (V4L2_MBUS_MASTER | \
769 V4L2_MBUS_PCLK_SAMPLE_RISING | \
770 V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
771 V4L2_MBUS_HSYNC_ACTIVE_LOW | \
772 V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
773 V4L2_MBUS_VSYNC_ACTIVE_LOW | \
774 V4L2_MBUS_DATA_ACTIVE_HIGH)
776 /* Capture is not running, no interrupts, no locking needed */
777 static int sh_mobile_ceu_set_bus_param(struct soc_camera_device
*icd
)
779 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
780 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
781 struct v4l2_subdev
*sd
= find_bus_subdev(pcdev
, icd
);
782 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
783 struct v4l2_mbus_config cfg
= {.type
= V4L2_MBUS_PARALLEL
,};
784 unsigned long value
, common_flags
= CEU_BUS_FLAGS
;
785 u32 capsr
= capture_save_reset(pcdev
);
786 unsigned int yuv_lineskip
;
790 * If the client doesn't implement g_mbus_config, we just use our
793 ret
= v4l2_subdev_call(sd
, video
, g_mbus_config
, &cfg
);
795 common_flags
= soc_mbus_config_compatible(&cfg
,
799 } else if (ret
!= -ENOIOCTLCMD
) {
803 /* Make choises, based on platform preferences */
804 if ((common_flags
& V4L2_MBUS_HSYNC_ACTIVE_HIGH
) &&
805 (common_flags
& V4L2_MBUS_HSYNC_ACTIVE_LOW
)) {
806 if (pcdev
->flags
& SH_CEU_FLAG_HSYNC_LOW
)
807 common_flags
&= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH
;
809 common_flags
&= ~V4L2_MBUS_HSYNC_ACTIVE_LOW
;
812 if ((common_flags
& V4L2_MBUS_VSYNC_ACTIVE_HIGH
) &&
813 (common_flags
& V4L2_MBUS_VSYNC_ACTIVE_LOW
)) {
814 if (pcdev
->flags
& SH_CEU_FLAG_VSYNC_LOW
)
815 common_flags
&= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH
;
817 common_flags
&= ~V4L2_MBUS_VSYNC_ACTIVE_LOW
;
820 cfg
.flags
= common_flags
;
821 ret
= v4l2_subdev_call(sd
, video
, s_mbus_config
, &cfg
);
822 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
825 if (icd
->current_fmt
->host_fmt
->bits_per_sample
> 8)
830 ceu_write(pcdev
, CRCNTR
, 0);
831 ceu_write(pcdev
, CRCMPR
, 0);
833 value
= 0x00000010; /* data fetch by default */
836 switch (icd
->current_fmt
->host_fmt
->fourcc
) {
837 case V4L2_PIX_FMT_NV12
:
838 case V4L2_PIX_FMT_NV21
:
839 /* convert 4:2:2 -> 4:2:0 */
840 yuv_lineskip
= 0; /* skip for NV12/21, no skip for NV16/61 */
842 case V4L2_PIX_FMT_NV16
:
843 case V4L2_PIX_FMT_NV61
:
845 case MEDIA_BUS_FMT_UYVY8_2X8
:
846 value
= 0x00000000; /* Cb0, Y0, Cr0, Y1 */
848 case MEDIA_BUS_FMT_VYUY8_2X8
:
849 value
= 0x00000100; /* Cr0, Y0, Cb0, Y1 */
851 case MEDIA_BUS_FMT_YUYV8_2X8
:
852 value
= 0x00000200; /* Y0, Cb0, Y1, Cr0 */
854 case MEDIA_BUS_FMT_YVYU8_2X8
:
855 value
= 0x00000300; /* Y0, Cr0, Y1, Cb0 */
862 if (icd
->current_fmt
->host_fmt
->fourcc
== V4L2_PIX_FMT_NV21
||
863 icd
->current_fmt
->host_fmt
->fourcc
== V4L2_PIX_FMT_NV61
)
864 value
^= 0x00000100; /* swap U, V to change from NV1x->NVx1 */
866 value
|= common_flags
& V4L2_MBUS_VSYNC_ACTIVE_LOW
? 1 << 1 : 0;
867 value
|= common_flags
& V4L2_MBUS_HSYNC_ACTIVE_LOW
? 1 << 0 : 0;
869 if (csi2_subdev(pcdev
, icd
)) /* CSI2 mode */
871 else if (pcdev
->is_16bit
)
873 else if (pcdev
->flags
& SH_CEU_FLAG_LOWER_8BIT
)
876 ceu_write(pcdev
, CAMCR
, value
);
878 ceu_write(pcdev
, CAPCR
, 0x00300000);
880 switch (pcdev
->field
) {
881 case V4L2_FIELD_INTERLACED_TB
:
884 case V4L2_FIELD_INTERLACED_BT
:
891 ceu_write(pcdev
, CAIFR
, value
);
893 sh_mobile_ceu_set_rect(icd
);
896 dev_geo(icd
->parent
, "CFLCR 0x%x\n", pcdev
->cflcr
);
897 ceu_write(pcdev
, CFLCR
, pcdev
->cflcr
);
900 * A few words about byte order (observed in Big Endian mode)
902 * In data fetch mode bytes are received in chunks of 8 bytes.
903 * D0, D1, D2, D3, D4, D5, D6, D7 (D0 received first)
905 * The data is however by default written to memory in reverse order:
906 * D7, D6, D5, D4, D3, D2, D1, D0 (D7 written to lowest byte)
908 * The lowest three bits of CDOCR allows us to do swapping,
909 * using 7 we swap the data bytes to match the incoming order:
910 * D0, D1, D2, D3, D4, D5, D6, D7
912 value
= 0x00000007 | yuv_lineskip
;
914 ceu_write(pcdev
, CDOCR
, value
);
915 ceu_write(pcdev
, CFWCR
, 0); /* keep "datafetch firewall" disabled */
917 capture_restore(pcdev
, capsr
);
919 /* not in bundle mode: skip CBDSR, CDAYR2, CDACR2, CDBYR2, CDBCR2 */
923 static int sh_mobile_ceu_try_bus_param(struct soc_camera_device
*icd
,
924 unsigned char buswidth
)
926 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
927 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
928 struct v4l2_subdev
*sd
= find_bus_subdev(pcdev
, icd
);
929 unsigned long common_flags
= CEU_BUS_FLAGS
;
930 struct v4l2_mbus_config cfg
= {.type
= V4L2_MBUS_PARALLEL
,};
933 ret
= v4l2_subdev_call(sd
, video
, g_mbus_config
, &cfg
);
935 common_flags
= soc_mbus_config_compatible(&cfg
,
937 else if (ret
!= -ENOIOCTLCMD
)
940 if (!common_flags
|| buswidth
> 16)
946 static const struct soc_mbus_pixelfmt sh_mobile_ceu_formats
[] = {
948 .fourcc
= V4L2_PIX_FMT_NV12
,
950 .bits_per_sample
= 8,
951 .packing
= SOC_MBUS_PACKING_1_5X8
,
952 .order
= SOC_MBUS_ORDER_LE
,
953 .layout
= SOC_MBUS_LAYOUT_PLANAR_2Y_C
,
955 .fourcc
= V4L2_PIX_FMT_NV21
,
957 .bits_per_sample
= 8,
958 .packing
= SOC_MBUS_PACKING_1_5X8
,
959 .order
= SOC_MBUS_ORDER_LE
,
960 .layout
= SOC_MBUS_LAYOUT_PLANAR_2Y_C
,
962 .fourcc
= V4L2_PIX_FMT_NV16
,
964 .bits_per_sample
= 8,
965 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
966 .order
= SOC_MBUS_ORDER_LE
,
967 .layout
= SOC_MBUS_LAYOUT_PLANAR_Y_C
,
969 .fourcc
= V4L2_PIX_FMT_NV61
,
971 .bits_per_sample
= 8,
972 .packing
= SOC_MBUS_PACKING_2X8_PADHI
,
973 .order
= SOC_MBUS_ORDER_LE
,
974 .layout
= SOC_MBUS_LAYOUT_PLANAR_Y_C
,
978 /* This will be corrected as we get more formats */
979 static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt
*fmt
)
981 return fmt
->packing
== SOC_MBUS_PACKING_NONE
||
982 (fmt
->bits_per_sample
== 8 &&
983 fmt
->packing
== SOC_MBUS_PACKING_1_5X8
) ||
984 (fmt
->bits_per_sample
== 8 &&
985 fmt
->packing
== SOC_MBUS_PACKING_2X8_PADHI
) ||
986 (fmt
->bits_per_sample
> 8 &&
987 fmt
->packing
== SOC_MBUS_PACKING_EXTEND16
);
990 static struct soc_camera_device
*ctrl_to_icd(struct v4l2_ctrl
*ctrl
)
992 return container_of(ctrl
->handler
, struct soc_camera_device
,
996 static int sh_mobile_ceu_s_ctrl(struct v4l2_ctrl
*ctrl
)
998 struct soc_camera_device
*icd
= ctrl_to_icd(ctrl
);
999 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1000 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1003 case V4L2_CID_SHARPNESS
:
1004 switch (icd
->current_fmt
->host_fmt
->fourcc
) {
1005 case V4L2_PIX_FMT_NV12
:
1006 case V4L2_PIX_FMT_NV21
:
1007 case V4L2_PIX_FMT_NV16
:
1008 case V4L2_PIX_FMT_NV61
:
1009 ceu_write(pcdev
, CLFCR
, !ctrl
->val
);
1018 static const struct v4l2_ctrl_ops sh_mobile_ceu_ctrl_ops
= {
1019 .s_ctrl
= sh_mobile_ceu_s_ctrl
,
1022 static int sh_mobile_ceu_get_formats(struct soc_camera_device
*icd
, unsigned int idx
,
1023 struct soc_camera_format_xlate
*xlate
)
1025 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1026 struct device
*dev
= icd
->parent
;
1027 struct soc_camera_host
*ici
= to_soc_camera_host(dev
);
1028 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1031 struct sh_mobile_ceu_cam
*cam
;
1032 struct v4l2_subdev_mbus_code_enum code
= {
1033 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
1036 const struct soc_mbus_pixelfmt
*fmt
;
1038 ret
= v4l2_subdev_call(sd
, pad
, enum_mbus_code
, NULL
, &code
);
1040 /* No more formats */
1043 fmt
= soc_mbus_get_fmtdesc(code
.code
);
1045 dev_warn(dev
, "unsupported format code #%u: %d\n", idx
, code
.code
);
1049 if (!csi2_subdev(pcdev
, icd
)) {
1050 /* Are there any restrictions in the CSI-2 case? */
1051 ret
= sh_mobile_ceu_try_bus_param(icd
, fmt
->bits_per_sample
);
1056 if (!icd
->host_priv
) {
1057 struct v4l2_subdev_format fmt
= {
1058 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
1060 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
1061 struct v4l2_rect rect
;
1064 /* Add our control */
1065 v4l2_ctrl_new_std(&icd
->ctrl_handler
, &sh_mobile_ceu_ctrl_ops
,
1066 V4L2_CID_SHARPNESS
, 0, 1, 1, 1);
1067 if (icd
->ctrl_handler
.error
)
1068 return icd
->ctrl_handler
.error
;
1070 /* FIXME: subwindow is lost between close / open */
1072 /* Cache current client geometry */
1073 ret
= soc_camera_client_g_rect(sd
, &rect
);
1078 ret
= v4l2_subdev_call(sd
, pad
, get_fmt
, NULL
, &fmt
);
1083 * All currently existing CEU implementations support 2560x1920
1084 * or larger frames. If the sensor is proposing too big a frame,
1085 * don't bother with possibly supportred by the CEU larger
1086 * sizes, just try VGA multiples. If needed, this can be
1087 * adjusted in the future.
1089 while ((mf
->width
> pcdev
->max_width
||
1090 mf
->height
> pcdev
->max_height
) && shift
< 4) {
1091 /* Try 2560x1920, 1280x960, 640x480, 320x240 */
1092 mf
->width
= 2560 >> shift
;
1093 mf
->height
= 1920 >> shift
;
1094 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
,
1095 soc_camera_grp_id(icd
), pad
,
1096 set_fmt
, NULL
, &fmt
);
1103 dev_err(dev
, "Failed to configure the client below %ux%x\n",
1104 mf
->width
, mf
->height
);
1108 dev_geo(dev
, "camera fmt %ux%u\n", mf
->width
, mf
->height
);
1110 cam
= kzalloc(sizeof(*cam
), GFP_KERNEL
);
1114 /* We are called with current camera crop, initialise subrect with it */
1116 cam
->subrect
= rect
;
1118 cam
->width
= mf
->width
;
1119 cam
->height
= mf
->height
;
1121 icd
->host_priv
= cam
;
1123 cam
= icd
->host_priv
;
1126 /* Beginning of a pass */
1128 cam
->extra_fmt
= NULL
;
1130 switch (code
.code
) {
1131 case MEDIA_BUS_FMT_UYVY8_2X8
:
1132 case MEDIA_BUS_FMT_VYUY8_2X8
:
1133 case MEDIA_BUS_FMT_YUYV8_2X8
:
1134 case MEDIA_BUS_FMT_YVYU8_2X8
:
1139 * Our case is simple so far: for any of the above four camera
1140 * formats we add all our four synthesized NV* formats, so,
1141 * just marking the device with a single flag suffices. If
1142 * the format generation rules are more complex, you would have
1143 * to actually hang your already added / counted formats onto
1144 * the host_priv pointer and check whether the format you're
1145 * going to add now is already there.
1147 cam
->extra_fmt
= sh_mobile_ceu_formats
;
1149 n
= ARRAY_SIZE(sh_mobile_ceu_formats
);
1151 for (k
= 0; xlate
&& k
< n
; k
++) {
1152 xlate
->host_fmt
= &sh_mobile_ceu_formats
[k
];
1153 xlate
->code
= code
.code
;
1155 dev_dbg(dev
, "Providing format %s using code %d\n",
1156 sh_mobile_ceu_formats
[k
].name
, code
.code
);
1160 if (!sh_mobile_ceu_packing_supported(fmt
))
1164 /* Generic pass-through */
1167 xlate
->host_fmt
= fmt
;
1168 xlate
->code
= code
.code
;
1170 dev_dbg(dev
, "Providing format %s in pass-through mode\n",
1177 static void sh_mobile_ceu_put_formats(struct soc_camera_device
*icd
)
1179 kfree(icd
->host_priv
);
1180 icd
->host_priv
= NULL
;
1183 #define scale_down(size, scale) soc_camera_shift_scale(size, 12, scale)
1184 #define calc_generic_scale(in, out) soc_camera_calc_scale(in, 12, out)
1187 * CEU can scale and crop, but we don't want to waste bandwidth and kill the
1188 * framerate by always requesting the maximum image from the client. See
1189 * Documentation/video4linux/sh_mobile_ceu_camera.txt for a description of
1190 * scaling and cropping algorithms and for the meaning of referenced here steps.
1192 static int sh_mobile_ceu_set_crop(struct soc_camera_device
*icd
,
1193 const struct v4l2_crop
*a
)
1195 struct v4l2_crop a_writable
= *a
;
1196 const struct v4l2_rect
*rect
= &a_writable
.c
;
1197 struct device
*dev
= icd
->parent
;
1198 struct soc_camera_host
*ici
= to_soc_camera_host(dev
);
1199 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1200 struct v4l2_crop cam_crop
;
1201 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
1202 struct v4l2_rect
*cam_rect
= &cam_crop
.c
;
1203 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1204 struct v4l2_subdev_format fmt
= {
1205 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
1207 struct v4l2_mbus_framefmt
*mf
= &fmt
.format
;
1208 unsigned int scale_cam_h
, scale_cam_v
, scale_ceu_h
, scale_ceu_v
,
1209 out_width
, out_height
;
1210 int interm_width
, interm_height
;
1214 dev_geo(dev
, "S_CROP(%ux%u@%u:%u)\n", rect
->width
, rect
->height
,
1215 rect
->left
, rect
->top
);
1217 /* During camera cropping its output window can change too, stop CEU */
1218 capsr
= capture_save_reset(pcdev
);
1219 dev_dbg(dev
, "CAPSR 0x%x, CFLCR 0x%x\n", capsr
, pcdev
->cflcr
);
1222 * 1. - 2. Apply iterative camera S_CROP for new input window, read back
1223 * actual camera rectangle.
1225 ret
= soc_camera_client_s_crop(sd
, &a_writable
, &cam_crop
,
1226 &cam
->rect
, &cam
->subrect
);
1230 dev_geo(dev
, "1-2: camera cropped to %ux%u@%u:%u\n",
1231 cam_rect
->width
, cam_rect
->height
,
1232 cam_rect
->left
, cam_rect
->top
);
1234 /* On success cam_crop contains current camera crop */
1236 /* 3. Retrieve camera output window */
1237 ret
= v4l2_subdev_call(sd
, pad
, get_fmt
, NULL
, &fmt
);
1241 if (mf
->width
> pcdev
->max_width
|| mf
->height
> pcdev
->max_height
)
1244 /* 4. Calculate camera scales */
1245 scale_cam_h
= calc_generic_scale(cam_rect
->width
, mf
->width
);
1246 scale_cam_v
= calc_generic_scale(cam_rect
->height
, mf
->height
);
1248 /* Calculate intermediate window */
1249 interm_width
= scale_down(rect
->width
, scale_cam_h
);
1250 interm_height
= scale_down(rect
->height
, scale_cam_v
);
1252 if (interm_width
< icd
->user_width
) {
1255 new_scale_h
= calc_generic_scale(rect
->width
, icd
->user_width
);
1257 mf
->width
= scale_down(cam_rect
->width
, new_scale_h
);
1260 if (interm_height
< icd
->user_height
) {
1263 new_scale_v
= calc_generic_scale(rect
->height
, icd
->user_height
);
1265 mf
->height
= scale_down(cam_rect
->height
, new_scale_v
);
1268 if (interm_width
< icd
->user_width
|| interm_height
< icd
->user_height
) {
1269 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
,
1270 soc_camera_grp_id(icd
), pad
,
1271 set_fmt
, NULL
, &fmt
);
1275 dev_geo(dev
, "New camera output %ux%u\n", mf
->width
, mf
->height
);
1276 scale_cam_h
= calc_generic_scale(cam_rect
->width
, mf
->width
);
1277 scale_cam_v
= calc_generic_scale(cam_rect
->height
, mf
->height
);
1278 interm_width
= scale_down(rect
->width
, scale_cam_h
);
1279 interm_height
= scale_down(rect
->height
, scale_cam_v
);
1282 /* Cache camera output window */
1283 cam
->width
= mf
->width
;
1284 cam
->height
= mf
->height
;
1286 if (pcdev
->image_mode
) {
1287 out_width
= min(interm_width
, icd
->user_width
);
1288 out_height
= min(interm_height
, icd
->user_height
);
1290 out_width
= interm_width
;
1291 out_height
= interm_height
;
1295 * 5. Calculate CEU scales from camera scales from results of (5) and
1298 scale_ceu_h
= calc_scale(interm_width
, &out_width
);
1299 scale_ceu_v
= calc_scale(interm_height
, &out_height
);
1301 dev_geo(dev
, "5: CEU scales %u:%u\n", scale_ceu_h
, scale_ceu_v
);
1303 /* Apply CEU scales. */
1304 cflcr
= scale_ceu_h
| (scale_ceu_v
<< 16);
1305 if (cflcr
!= pcdev
->cflcr
) {
1306 pcdev
->cflcr
= cflcr
;
1307 ceu_write(pcdev
, CFLCR
, cflcr
);
1310 icd
->user_width
= out_width
& ~3;
1311 icd
->user_height
= out_height
& ~3;
1312 /* Offsets are applied at the CEU scaling filter input */
1313 cam
->ceu_left
= scale_down(rect
->left
- cam_rect
->left
, scale_cam_h
) & ~1;
1314 cam
->ceu_top
= scale_down(rect
->top
- cam_rect
->top
, scale_cam_v
) & ~1;
1316 /* 6. Use CEU cropping to crop to the new window. */
1317 sh_mobile_ceu_set_rect(icd
);
1319 cam
->subrect
= *rect
;
1321 dev_geo(dev
, "6: CEU cropped to %ux%u@%u:%u\n",
1322 icd
->user_width
, icd
->user_height
,
1323 cam
->ceu_left
, cam
->ceu_top
);
1325 /* Restore capture. The CE bit can be cleared by the hardware */
1328 capture_restore(pcdev
, capsr
);
1330 /* Even if only camera cropping succeeded */
1334 static int sh_mobile_ceu_get_crop(struct soc_camera_device
*icd
,
1335 struct v4l2_crop
*a
)
1337 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
1339 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1340 a
->c
= cam
->subrect
;
1345 /* Similar to set_crop multistage iterative algorithm */
1346 static int sh_mobile_ceu_set_fmt(struct soc_camera_device
*icd
,
1347 struct v4l2_format
*f
)
1349 struct device
*dev
= icd
->parent
;
1350 struct soc_camera_host
*ici
= to_soc_camera_host(dev
);
1351 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1352 struct sh_mobile_ceu_cam
*cam
= icd
->host_priv
;
1353 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
1354 struct v4l2_mbus_framefmt mf
;
1355 __u32 pixfmt
= pix
->pixelformat
;
1356 const struct soc_camera_format_xlate
*xlate
;
1357 unsigned int ceu_sub_width
= pcdev
->max_width
,
1358 ceu_sub_height
= pcdev
->max_height
;
1359 u16 scale_v
, scale_h
;
1362 enum v4l2_field field
;
1364 switch (pix
->field
) {
1366 pix
->field
= V4L2_FIELD_NONE
;
1368 case V4L2_FIELD_INTERLACED_TB
:
1369 case V4L2_FIELD_INTERLACED_BT
:
1370 case V4L2_FIELD_NONE
:
1373 case V4L2_FIELD_INTERLACED
:
1374 field
= V4L2_FIELD_INTERLACED_TB
;
1378 xlate
= soc_camera_xlate_by_fourcc(icd
, pixfmt
);
1380 dev_warn(dev
, "Format %x not found\n", pixfmt
);
1384 /* 1.-4. Calculate desired client output geometry */
1385 soc_camera_calc_client_output(icd
, &cam
->rect
, &cam
->subrect
, pix
, &mf
, 12);
1386 mf
.field
= pix
->field
;
1387 mf
.colorspace
= pix
->colorspace
;
1388 mf
.code
= xlate
->code
;
1391 case V4L2_PIX_FMT_NV12
:
1392 case V4L2_PIX_FMT_NV21
:
1393 case V4L2_PIX_FMT_NV16
:
1394 case V4L2_PIX_FMT_NV61
:
1401 dev_geo(dev
, "S_FMT(pix=0x%x, fld 0x%x, code 0x%x, %ux%u)\n", pixfmt
, mf
.field
, mf
.code
,
1402 pix
->width
, pix
->height
);
1404 dev_geo(dev
, "4: request camera output %ux%u\n", mf
.width
, mf
.height
);
1407 ret
= soc_camera_client_scale(icd
, &cam
->rect
, &cam
->subrect
,
1408 &mf
, &ceu_sub_width
, &ceu_sub_height
,
1409 image_mode
&& V4L2_FIELD_NONE
== field
, 12);
1411 dev_geo(dev
, "5-9: client scale return %d\n", ret
);
1413 /* Done with the camera. Now see if we can improve the result */
1415 dev_geo(dev
, "fmt %ux%u, requested %ux%u\n",
1416 mf
.width
, mf
.height
, pix
->width
, pix
->height
);
1420 if (mf
.code
!= xlate
->code
)
1423 /* 9. Prepare CEU crop */
1424 cam
->width
= mf
.width
;
1425 cam
->height
= mf
.height
;
1427 /* 10. Use CEU scaling to scale to the requested user window. */
1429 /* We cannot scale up */
1430 if (pix
->width
> ceu_sub_width
)
1431 ceu_sub_width
= pix
->width
;
1433 if (pix
->height
> ceu_sub_height
)
1434 ceu_sub_height
= pix
->height
;
1436 pix
->colorspace
= mf
.colorspace
;
1439 /* Scale pix->{width x height} down to width x height */
1440 scale_h
= calc_scale(ceu_sub_width
, &pix
->width
);
1441 scale_v
= calc_scale(ceu_sub_height
, &pix
->height
);
1443 pix
->width
= ceu_sub_width
;
1444 pix
->height
= ceu_sub_height
;
1449 pcdev
->cflcr
= scale_h
| (scale_v
<< 16);
1452 * We have calculated CFLCR, the actual configuration will be performed
1453 * in sh_mobile_ceu_set_bus_param()
1456 dev_geo(dev
, "10: W: %u : 0x%x = %u, H: %u : 0x%x = %u\n",
1457 ceu_sub_width
, scale_h
, pix
->width
,
1458 ceu_sub_height
, scale_v
, pix
->height
);
1460 cam
->code
= xlate
->code
;
1461 icd
->current_fmt
= xlate
;
1463 pcdev
->field
= field
;
1464 pcdev
->image_mode
= image_mode
;
1466 /* CFSZR requirement */
1473 #define CEU_CHDW_MAX 8188U /* Maximum line stride */
1475 static int sh_mobile_ceu_try_fmt(struct soc_camera_device
*icd
,
1476 struct v4l2_format
*f
)
1478 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1479 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1480 const struct soc_camera_format_xlate
*xlate
;
1481 struct v4l2_pix_format
*pix
= &f
->fmt
.pix
;
1482 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1483 struct v4l2_subdev_pad_config pad_cfg
;
1484 struct v4l2_subdev_format format
= {
1485 .which
= V4L2_SUBDEV_FORMAT_TRY
,
1487 struct v4l2_mbus_framefmt
*mf
= &format
.format
;
1488 __u32 pixfmt
= pix
->pixelformat
;
1492 dev_geo(icd
->parent
, "TRY_FMT(pix=0x%x, %ux%u)\n",
1493 pixfmt
, pix
->width
, pix
->height
);
1495 xlate
= soc_camera_xlate_by_fourcc(icd
, pixfmt
);
1497 xlate
= icd
->current_fmt
;
1498 dev_dbg(icd
->parent
, "Format %x not found, keeping %x\n",
1499 pixfmt
, xlate
->host_fmt
->fourcc
);
1500 pixfmt
= xlate
->host_fmt
->fourcc
;
1501 pix
->pixelformat
= pixfmt
;
1502 pix
->colorspace
= icd
->colorspace
;
1505 /* FIXME: calculate using depth and bus width */
1507 /* CFSZR requires height and width to be 4-pixel aligned */
1508 v4l_bound_align_image(&pix
->width
, 2, pcdev
->max_width
, 2,
1509 &pix
->height
, 4, pcdev
->max_height
, 2, 0);
1512 height
= pix
->height
;
1514 /* limit to sensor capabilities */
1515 mf
->width
= pix
->width
;
1516 mf
->height
= pix
->height
;
1517 mf
->field
= pix
->field
;
1518 mf
->code
= xlate
->code
;
1519 mf
->colorspace
= pix
->colorspace
;
1521 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
, soc_camera_grp_id(icd
),
1522 pad
, set_fmt
, &pad_cfg
, &format
);
1526 pix
->width
= mf
->width
;
1527 pix
->height
= mf
->height
;
1528 pix
->field
= mf
->field
;
1529 pix
->colorspace
= mf
->colorspace
;
1532 case V4L2_PIX_FMT_NV12
:
1533 case V4L2_PIX_FMT_NV21
:
1534 case V4L2_PIX_FMT_NV16
:
1535 case V4L2_PIX_FMT_NV61
:
1536 /* FIXME: check against rect_max after converting soc-camera */
1537 /* We can scale precisely, need a bigger image from camera */
1538 if (pix
->width
< width
|| pix
->height
< height
) {
1540 * We presume, the sensor behaves sanely, i.e., if
1541 * requested a bigger rectangle, it will not return a
1544 mf
->width
= pcdev
->max_width
;
1545 mf
->height
= pcdev
->max_height
;
1546 ret
= v4l2_device_call_until_err(sd
->v4l2_dev
,
1547 soc_camera_grp_id(icd
), pad
,
1548 set_fmt
, &pad_cfg
, &format
);
1550 /* Shouldn't actually happen... */
1551 dev_err(icd
->parent
,
1552 "FIXME: client try_fmt() = %d\n", ret
);
1556 /* We will scale exactly */
1557 if (mf
->width
> width
)
1559 if (mf
->height
> height
)
1560 pix
->height
= height
;
1562 pix
->bytesperline
= max(pix
->bytesperline
, pix
->width
);
1563 pix
->bytesperline
= min(pix
->bytesperline
, CEU_CHDW_MAX
);
1564 pix
->bytesperline
&= ~3;
1568 /* Configurable stride isn't supported in pass-through mode. */
1569 pix
->bytesperline
= 0;
1576 dev_geo(icd
->parent
, "%s(): return %d, fmt 0x%x, %ux%u\n",
1577 __func__
, ret
, pix
->pixelformat
, pix
->width
, pix
->height
);
1582 static int sh_mobile_ceu_set_livecrop(struct soc_camera_device
*icd
,
1583 const struct v4l2_crop
*a
)
1585 struct v4l2_subdev
*sd
= soc_camera_to_subdev(icd
);
1586 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1587 struct sh_mobile_ceu_dev
*pcdev
= ici
->priv
;
1588 u32 out_width
= icd
->user_width
, out_height
= icd
->user_height
;
1593 /* Wait for frame */
1594 ret
= wait_for_completion_interruptible(&pcdev
->complete
);
1595 /* Stop the client */
1596 ret
= v4l2_subdev_call(sd
, video
, s_stream
, 0);
1598 dev_warn(icd
->parent
,
1599 "Client failed to stop the stream: %d\n", ret
);
1601 /* Do the crop, if it fails, there's nothing more we can do */
1602 sh_mobile_ceu_set_crop(icd
, a
);
1604 dev_geo(icd
->parent
, "Output after crop: %ux%u\n", icd
->user_width
, icd
->user_height
);
1606 if (icd
->user_width
!= out_width
|| icd
->user_height
!= out_height
) {
1607 struct v4l2_format f
= {
1608 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
1611 .height
= out_height
,
1612 .pixelformat
= icd
->current_fmt
->host_fmt
->fourcc
,
1613 .field
= pcdev
->field
,
1614 .colorspace
= icd
->colorspace
,
1617 ret
= sh_mobile_ceu_set_fmt(icd
, &f
);
1618 if (!ret
&& (out_width
!= f
.fmt
.pix
.width
||
1619 out_height
!= f
.fmt
.pix
.height
))
1622 icd
->user_width
= out_width
& ~3;
1623 icd
->user_height
= out_height
& ~3;
1624 ret
= sh_mobile_ceu_set_bus_param(icd
);
1628 /* Thaw the queue */
1630 spin_lock_irq(&pcdev
->lock
);
1631 sh_mobile_ceu_capture(pcdev
);
1632 spin_unlock_irq(&pcdev
->lock
);
1633 /* Start the client */
1634 ret
= v4l2_subdev_call(sd
, video
, s_stream
, 1);
1638 static unsigned int sh_mobile_ceu_poll(struct file
*file
, poll_table
*pt
)
1640 struct soc_camera_device
*icd
= file
->private_data
;
1642 return vb2_poll(&icd
->vb2_vidq
, file
, pt
);
1645 static int sh_mobile_ceu_querycap(struct soc_camera_host
*ici
,
1646 struct v4l2_capability
*cap
)
1648 strlcpy(cap
->card
, "SuperH_Mobile_CEU", sizeof(cap
->card
));
1649 strlcpy(cap
->driver
, "sh_mobile_ceu", sizeof(cap
->driver
));
1650 strlcpy(cap
->bus_info
, "platform:sh_mobile_ceu", sizeof(cap
->bus_info
));
1651 cap
->device_caps
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_STREAMING
;
1652 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
1657 static int sh_mobile_ceu_init_videobuf(struct vb2_queue
*q
,
1658 struct soc_camera_device
*icd
)
1660 struct soc_camera_host
*ici
= to_soc_camera_host(icd
->parent
);
1662 q
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1663 q
->io_modes
= VB2_MMAP
| VB2_USERPTR
;
1665 q
->ops
= &sh_mobile_ceu_videobuf_ops
;
1666 q
->mem_ops
= &vb2_dma_contig_memops
;
1667 q
->buf_struct_size
= sizeof(struct sh_mobile_ceu_buffer
);
1668 q
->timestamp_flags
= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
;
1669 q
->lock
= &ici
->host_lock
;
1670 q
->dev
= ici
->v4l2_dev
.dev
;
1672 return vb2_queue_init(q
);
1675 static struct soc_camera_host_ops sh_mobile_ceu_host_ops
= {
1676 .owner
= THIS_MODULE
,
1677 .add
= sh_mobile_ceu_add_device
,
1678 .remove
= sh_mobile_ceu_remove_device
,
1679 .clock_start
= sh_mobile_ceu_clock_start
,
1680 .clock_stop
= sh_mobile_ceu_clock_stop
,
1681 .get_formats
= sh_mobile_ceu_get_formats
,
1682 .put_formats
= sh_mobile_ceu_put_formats
,
1683 .get_crop
= sh_mobile_ceu_get_crop
,
1684 .set_crop
= sh_mobile_ceu_set_crop
,
1685 .set_livecrop
= sh_mobile_ceu_set_livecrop
,
1686 .set_fmt
= sh_mobile_ceu_set_fmt
,
1687 .try_fmt
= sh_mobile_ceu_try_fmt
,
1688 .poll
= sh_mobile_ceu_poll
,
1689 .querycap
= sh_mobile_ceu_querycap
,
1690 .set_bus_param
= sh_mobile_ceu_set_bus_param
,
1691 .init_videobuf2
= sh_mobile_ceu_init_videobuf
,
1695 struct notifier_block notifier
;
1696 struct completion completion
;
1700 static int bus_notify(struct notifier_block
*nb
,
1701 unsigned long action
, void *data
)
1703 struct device
*dev
= data
;
1704 struct bus_wait
*wait
= container_of(nb
, struct bus_wait
, notifier
);
1706 if (wait
->dev
!= dev
)
1710 case BUS_NOTIFY_UNBOUND_DRIVER
:
1711 /* Protect from module unloading */
1712 wait_for_completion(&wait
->completion
);
1718 static int sh_mobile_ceu_probe(struct platform_device
*pdev
)
1720 struct sh_mobile_ceu_dev
*pcdev
;
1721 struct resource
*res
;
1725 struct bus_wait wait
= {
1726 .completion
= COMPLETION_INITIALIZER_ONSTACK(wait
.completion
),
1727 .notifier
.notifier_call
= bus_notify
,
1729 struct sh_mobile_ceu_companion
*csi2
;
1731 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1732 irq
= platform_get_irq(pdev
, 0);
1733 if (!res
|| (int)irq
<= 0) {
1734 dev_err(&pdev
->dev
, "Not enough CEU platform resources.\n");
1738 pcdev
= devm_kzalloc(&pdev
->dev
, sizeof(*pcdev
), GFP_KERNEL
);
1740 dev_err(&pdev
->dev
, "Could not allocate pcdev\n");
1744 INIT_LIST_HEAD(&pcdev
->capture
);
1745 spin_lock_init(&pcdev
->lock
);
1746 init_completion(&pcdev
->complete
);
1748 pcdev
->pdata
= pdev
->dev
.platform_data
;
1749 if (!pcdev
->pdata
&& !pdev
->dev
.of_node
) {
1750 dev_err(&pdev
->dev
, "CEU platform data not set.\n");
1754 /* TODO: implement per-device bus flags */
1756 pcdev
->max_width
= pcdev
->pdata
->max_width
;
1757 pcdev
->max_height
= pcdev
->pdata
->max_height
;
1758 pcdev
->flags
= pcdev
->pdata
->flags
;
1760 pcdev
->field
= V4L2_FIELD_NONE
;
1762 if (!pcdev
->max_width
) {
1764 err
= of_property_read_u32(pdev
->dev
.of_node
, "renesas,max-width", &v
);
1766 pcdev
->max_width
= v
;
1768 if (!pcdev
->max_width
)
1769 pcdev
->max_width
= 2560;
1771 if (!pcdev
->max_height
) {
1773 err
= of_property_read_u32(pdev
->dev
.of_node
, "renesas,max-height", &v
);
1775 pcdev
->max_height
= v
;
1777 if (!pcdev
->max_height
)
1778 pcdev
->max_height
= 1920;
1781 base
= devm_ioremap_resource(&pdev
->dev
, res
);
1783 return PTR_ERR(base
);
1787 pcdev
->video_limit
= 0; /* only enabled if second resource exists */
1789 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1791 err
= dma_declare_coherent_memory(&pdev
->dev
, res
->start
,
1795 DMA_MEMORY_EXCLUSIVE
);
1797 dev_err(&pdev
->dev
, "Unable to declare CEU memory.\n");
1801 pcdev
->video_limit
= resource_size(res
);
1805 err
= devm_request_irq(&pdev
->dev
, pcdev
->irq
, sh_mobile_ceu_irq
,
1806 0, dev_name(&pdev
->dev
), pcdev
);
1808 dev_err(&pdev
->dev
, "Unable to register CEU interrupt.\n");
1809 goto exit_release_mem
;
1812 pm_suspend_ignore_children(&pdev
->dev
, true);
1813 pm_runtime_enable(&pdev
->dev
);
1814 pm_runtime_resume(&pdev
->dev
);
1816 pcdev
->ici
.priv
= pcdev
;
1817 pcdev
->ici
.v4l2_dev
.dev
= &pdev
->dev
;
1818 pcdev
->ici
.nr
= pdev
->id
;
1819 pcdev
->ici
.drv_name
= dev_name(&pdev
->dev
);
1820 pcdev
->ici
.ops
= &sh_mobile_ceu_host_ops
;
1821 pcdev
->ici
.capabilities
= SOCAM_HOST_CAP_STRIDE
;
1823 if (pcdev
->pdata
&& pcdev
->pdata
->asd_sizes
) {
1824 struct v4l2_async_subdev
**asd
;
1825 char name
[] = "sh-mobile-csi2";
1829 * CSI2 interfacing: several groups can use CSI2, pick up the
1832 asd
= pcdev
->pdata
->asd
;
1833 for (j
= 0; pcdev
->pdata
->asd_sizes
[j
]; j
++) {
1834 for (i
= 0; i
< pcdev
->pdata
->asd_sizes
[j
]; i
++, asd
++) {
1835 dev_dbg(&pdev
->dev
, "%s(): subdev #%d, type %u\n",
1836 __func__
, i
, (*asd
)->match_type
);
1837 if ((*asd
)->match_type
== V4L2_ASYNC_MATCH_DEVNAME
&&
1838 !strncmp(name
, (*asd
)->match
.device_name
.name
,
1839 sizeof(name
) - 1)) {
1840 pcdev
->csi2_asd
= *asd
;
1844 if (pcdev
->csi2_asd
)
1848 pcdev
->ici
.asd
= pcdev
->pdata
->asd
;
1849 pcdev
->ici
.asd_sizes
= pcdev
->pdata
->asd_sizes
;
1852 /* Legacy CSI2 interfacing */
1853 csi2
= pcdev
->pdata
? pcdev
->pdata
->csi2
: NULL
;
1856 * TODO: remove this once all users are converted to
1857 * asynchronous CSI2 probing. If it has to be kept, csi2
1858 * platform device resources have to be added, using
1859 * platform_device_add_resources()
1861 struct platform_device
*csi2_pdev
=
1862 platform_device_alloc("sh-mobile-csi2", csi2
->id
);
1863 struct sh_csi2_pdata
*csi2_pdata
= csi2
->platform_data
;
1870 pcdev
->csi2_pdev
= csi2_pdev
;
1872 err
= platform_device_add_data(csi2_pdev
, csi2_pdata
,
1873 sizeof(*csi2_pdata
));
1877 csi2_pdev
->resource
= csi2
->resource
;
1878 csi2_pdev
->num_resources
= csi2
->num_resources
;
1880 err
= platform_device_add(csi2_pdev
);
1884 wait
.dev
= &csi2_pdev
->dev
;
1886 err
= bus_register_notifier(&platform_bus_type
, &wait
.notifier
);
1888 goto exit_pdev_unregister
;
1891 * From this point the driver module will not unload, until
1892 * we complete the completion.
1895 if (!csi2_pdev
->dev
.driver
) {
1896 complete(&wait
.completion
);
1897 /* Either too late, or probing failed */
1898 bus_unregister_notifier(&platform_bus_type
, &wait
.notifier
);
1900 goto exit_pdev_unregister
;
1904 * The module is still loaded, in the worst case it is hanging
1905 * in device release on our completion. So, _now_ dereferencing
1906 * the "owner" is safe!
1909 err
= try_module_get(csi2_pdev
->dev
.driver
->owner
);
1911 /* Let notifier complete, if it has been locked */
1912 complete(&wait
.completion
);
1913 bus_unregister_notifier(&platform_bus_type
, &wait
.notifier
);
1916 goto exit_pdev_unregister
;
1919 pcdev
->csi2_sd
= platform_get_drvdata(csi2_pdev
);
1922 err
= soc_camera_host_register(&pcdev
->ici
);
1924 goto exit_csi2_unregister
;
1927 err
= v4l2_device_register_subdev(&pcdev
->ici
.v4l2_dev
,
1929 dev_dbg(&pdev
->dev
, "%s(): ret(register_subdev) = %d\n",
1932 goto exit_host_unregister
;
1933 /* v4l2_device_register_subdev() took a reference too */
1934 module_put(pcdev
->csi2_sd
->owner
);
1939 exit_host_unregister
:
1940 soc_camera_host_unregister(&pcdev
->ici
);
1941 exit_csi2_unregister
:
1943 module_put(pcdev
->csi2_pdev
->dev
.driver
->owner
);
1944 exit_pdev_unregister
:
1945 platform_device_del(pcdev
->csi2_pdev
);
1947 pcdev
->csi2_pdev
->resource
= NULL
;
1948 platform_device_put(pcdev
->csi2_pdev
);
1951 pm_runtime_disable(&pdev
->dev
);
1953 if (platform_get_resource(pdev
, IORESOURCE_MEM
, 1))
1954 dma_release_declared_memory(&pdev
->dev
);
1958 static int sh_mobile_ceu_remove(struct platform_device
*pdev
)
1960 struct soc_camera_host
*soc_host
= to_soc_camera_host(&pdev
->dev
);
1961 struct sh_mobile_ceu_dev
*pcdev
= container_of(soc_host
,
1962 struct sh_mobile_ceu_dev
, ici
);
1963 struct platform_device
*csi2_pdev
= pcdev
->csi2_pdev
;
1965 soc_camera_host_unregister(soc_host
);
1966 pm_runtime_disable(&pdev
->dev
);
1967 if (platform_get_resource(pdev
, IORESOURCE_MEM
, 1))
1968 dma_release_declared_memory(&pdev
->dev
);
1969 if (csi2_pdev
&& csi2_pdev
->dev
.driver
) {
1970 struct module
*csi2_drv
= csi2_pdev
->dev
.driver
->owner
;
1971 platform_device_del(csi2_pdev
);
1972 csi2_pdev
->resource
= NULL
;
1973 platform_device_put(csi2_pdev
);
1974 module_put(csi2_drv
);
1980 static int sh_mobile_ceu_runtime_nop(struct device
*dev
)
1982 /* Runtime PM callback shared between ->runtime_suspend()
1983 * and ->runtime_resume(). Simply returns success.
1985 * This driver re-initializes all registers after
1986 * pm_runtime_get_sync() anyway so there is no need
1987 * to save and restore registers here.
1992 static const struct dev_pm_ops sh_mobile_ceu_dev_pm_ops
= {
1993 .runtime_suspend
= sh_mobile_ceu_runtime_nop
,
1994 .runtime_resume
= sh_mobile_ceu_runtime_nop
,
1997 static const struct of_device_id sh_mobile_ceu_of_match
[] = {
1998 { .compatible
= "renesas,sh-mobile-ceu" },
2001 MODULE_DEVICE_TABLE(of
, sh_mobile_ceu_of_match
);
2003 static struct platform_driver sh_mobile_ceu_driver
= {
2005 .name
= "sh_mobile_ceu",
2006 .pm
= &sh_mobile_ceu_dev_pm_ops
,
2007 .of_match_table
= sh_mobile_ceu_of_match
,
2009 .probe
= sh_mobile_ceu_probe
,
2010 .remove
= sh_mobile_ceu_remove
,
2013 static int __init
sh_mobile_ceu_init(void)
2015 /* Whatever return code */
2016 request_module("sh_mobile_csi2");
2017 return platform_driver_register(&sh_mobile_ceu_driver
);
2020 static void __exit
sh_mobile_ceu_exit(void)
2022 platform_driver_unregister(&sh_mobile_ceu_driver
);
2025 module_init(sh_mobile_ceu_init
);
2026 module_exit(sh_mobile_ceu_exit
);
2028 MODULE_DESCRIPTION("SuperH Mobile CEU driver");
2029 MODULE_AUTHOR("Magnus Damm");
2030 MODULE_LICENSE("GPL");
2031 MODULE_VERSION("0.1.0");
2032 MODULE_ALIAS("platform:sh_mobile_ceu");