V4L/DVB (9243): video: add byte swap to sh_mobile_ceu driver
[deliverable/linux.git] / drivers / media / video / sh_mobile_ceu_camera.c
1 /*
2 * V4L2 Driver for SuperH Mobile CEU interface
3 *
4 * Copyright (C) 2008 Magnus Damm
5 *
6 * Based on V4L2 Driver for PXA camera host - "pxa_camera.c",
7 *
8 * Copyright (C) 2006, Sascha Hauer, Pengutronix
9 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
10 *
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.
15 */
16
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/io.h>
20 #include <linux/delay.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/errno.h>
23 #include <linux/fs.h>
24 #include <linux/interrupt.h>
25 #include <linux/kernel.h>
26 #include <linux/mm.h>
27 #include <linux/moduleparam.h>
28 #include <linux/time.h>
29 #include <linux/version.h>
30 #include <linux/device.h>
31 #include <linux/platform_device.h>
32 #include <linux/mutex.h>
33 #include <linux/videodev2.h>
34
35 #include <media/v4l2-common.h>
36 #include <media/v4l2-dev.h>
37 #include <media/soc_camera.h>
38 #include <media/sh_mobile_ceu.h>
39 #include <media/videobuf-dma-contig.h>
40
41 /* register offsets for sh7722 / sh7723 */
42
43 #define CAPSR 0x00 /* Capture start register */
44 #define CAPCR 0x04 /* Capture control register */
45 #define CAMCR 0x08 /* Capture interface control register */
46 #define CMCYR 0x0c /* Capture interface cycle register */
47 #define CAMOR 0x10 /* Capture interface offset register */
48 #define CAPWR 0x14 /* Capture interface width register */
49 #define CAIFR 0x18 /* Capture interface input format register */
50 #define CSTCR 0x20 /* Camera strobe control register (<= sh7722) */
51 #define CSECR 0x24 /* Camera strobe emission count register (<= sh7722) */
52 #define CRCNTR 0x28 /* CEU register control register */
53 #define CRCMPR 0x2c /* CEU register forcible control register */
54 #define CFLCR 0x30 /* Capture filter control register */
55 #define CFSZR 0x34 /* Capture filter size clip register */
56 #define CDWDR 0x38 /* Capture destination width register */
57 #define CDAYR 0x3c /* Capture data address Y register */
58 #define CDACR 0x40 /* Capture data address C register */
59 #define CDBYR 0x44 /* Capture data bottom-field address Y register */
60 #define CDBCR 0x48 /* Capture data bottom-field address C register */
61 #define CBDSR 0x4c /* Capture bundle destination size register */
62 #define CFWCR 0x5c /* Firewall operation control register */
63 #define CLFCR 0x60 /* Capture low-pass filter control register */
64 #define CDOCR 0x64 /* Capture data output control register */
65 #define CDDCR 0x68 /* Capture data complexity level register */
66 #define CDDAR 0x6c /* Capture data complexity level address register */
67 #define CEIER 0x70 /* Capture event interrupt enable register */
68 #define CETCR 0x74 /* Capture event flag clear register */
69 #define CSTSR 0x7c /* Capture status register */
70 #define CSRTR 0x80 /* Capture software reset register */
71 #define CDSSR 0x84 /* Capture data size register */
72 #define CDAYR2 0x90 /* Capture data address Y register 2 */
73 #define CDACR2 0x94 /* Capture data address C register 2 */
74 #define CDBYR2 0x98 /* Capture data bottom-field address Y register 2 */
75 #define CDBCR2 0x9c /* Capture data bottom-field address C register 2 */
76
77 static DEFINE_MUTEX(camera_lock);
78
79 /* per video frame buffer */
80 struct sh_mobile_ceu_buffer {
81 struct videobuf_buffer vb; /* v4l buffer must be first */
82 const struct soc_camera_data_format *fmt;
83 };
84
85 struct sh_mobile_ceu_dev {
86 struct device *dev;
87 struct soc_camera_host ici;
88 struct soc_camera_device *icd;
89
90 unsigned int irq;
91 void __iomem *base;
92 unsigned long video_limit;
93
94 /* lock used to protect videobuf */
95 spinlock_t lock;
96 struct list_head capture;
97 struct videobuf_buffer *active;
98
99 struct sh_mobile_ceu_info *pdata;
100 };
101
102 static void ceu_write(struct sh_mobile_ceu_dev *priv,
103 unsigned long reg_offs, unsigned long data)
104 {
105 iowrite32(data, priv->base + reg_offs);
106 }
107
108 static unsigned long ceu_read(struct sh_mobile_ceu_dev *priv,
109 unsigned long reg_offs)
110 {
111 return ioread32(priv->base + reg_offs);
112 }
113
114 /*
115 * Videobuf operations
116 */
117 static int sh_mobile_ceu_videobuf_setup(struct videobuf_queue *vq,
118 unsigned int *count,
119 unsigned int *size)
120 {
121 struct soc_camera_device *icd = vq->priv_data;
122 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
123 struct sh_mobile_ceu_dev *pcdev = ici->priv;
124 int bytes_per_pixel = (icd->current_fmt->depth + 7) >> 3;
125
126 *size = PAGE_ALIGN(icd->width * icd->height * bytes_per_pixel);
127
128 if (0 == *count)
129 *count = 2;
130
131 if (pcdev->video_limit) {
132 while (*size * *count > pcdev->video_limit)
133 (*count)--;
134 }
135
136 dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
137
138 return 0;
139 }
140
141 static void free_buffer(struct videobuf_queue *vq,
142 struct sh_mobile_ceu_buffer *buf)
143 {
144 struct soc_camera_device *icd = vq->priv_data;
145
146 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %zd\n", __func__,
147 &buf->vb, buf->vb.baddr, buf->vb.bsize);
148
149 if (in_interrupt())
150 BUG();
151
152 videobuf_dma_contig_free(vq, &buf->vb);
153 dev_dbg(&icd->dev, "%s freed\n", __func__);
154 buf->vb.state = VIDEOBUF_NEEDS_INIT;
155 }
156
157 static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
158 {
159 ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) & ~1);
160 ceu_write(pcdev, CETCR, ~ceu_read(pcdev, CETCR) & 0x0317f313);
161 ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) | 1);
162
163 ceu_write(pcdev, CAPCR, ceu_read(pcdev, CAPCR) & ~0x10000);
164
165 ceu_write(pcdev, CETCR, 0x0317f313 ^ 0x10);
166
167 if (pcdev->active) {
168 ceu_write(pcdev, CDAYR, videobuf_to_dma_contig(pcdev->active));
169 ceu_write(pcdev, CAPSR, 0x1); /* start capture */
170 }
171 }
172
173 static int sh_mobile_ceu_videobuf_prepare(struct videobuf_queue *vq,
174 struct videobuf_buffer *vb,
175 enum v4l2_field field)
176 {
177 struct soc_camera_device *icd = vq->priv_data;
178 struct sh_mobile_ceu_buffer *buf;
179 int ret;
180
181 buf = container_of(vb, struct sh_mobile_ceu_buffer, vb);
182
183 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %zd\n", __func__,
184 vb, vb->baddr, vb->bsize);
185
186 /* Added list head initialization on alloc */
187 WARN_ON(!list_empty(&vb->queue));
188
189 #ifdef DEBUG
190 /* This can be useful if you want to see if we actually fill
191 * the buffer with something */
192 memset((void *)vb->baddr, 0xaa, vb->bsize);
193 #endif
194
195 BUG_ON(NULL == icd->current_fmt);
196
197 if (buf->fmt != icd->current_fmt ||
198 vb->width != icd->width ||
199 vb->height != icd->height ||
200 vb->field != field) {
201 buf->fmt = icd->current_fmt;
202 vb->width = icd->width;
203 vb->height = icd->height;
204 vb->field = field;
205 vb->state = VIDEOBUF_NEEDS_INIT;
206 }
207
208 vb->size = vb->width * vb->height * ((buf->fmt->depth + 7) >> 3);
209 if (0 != vb->baddr && vb->bsize < vb->size) {
210 ret = -EINVAL;
211 goto out;
212 }
213
214 if (vb->state == VIDEOBUF_NEEDS_INIT) {
215 ret = videobuf_iolock(vq, vb, NULL);
216 if (ret)
217 goto fail;
218 vb->state = VIDEOBUF_PREPARED;
219 }
220
221 return 0;
222 fail:
223 free_buffer(vq, buf);
224 out:
225 return ret;
226 }
227
228 static void sh_mobile_ceu_videobuf_queue(struct videobuf_queue *vq,
229 struct videobuf_buffer *vb)
230 {
231 struct soc_camera_device *icd = vq->priv_data;
232 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
233 struct sh_mobile_ceu_dev *pcdev = ici->priv;
234 unsigned long flags;
235
236 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %zd\n", __func__,
237 vb, vb->baddr, vb->bsize);
238
239 vb->state = VIDEOBUF_ACTIVE;
240 spin_lock_irqsave(&pcdev->lock, flags);
241 list_add_tail(&vb->queue, &pcdev->capture);
242
243 if (!pcdev->active) {
244 pcdev->active = vb;
245 sh_mobile_ceu_capture(pcdev);
246 }
247
248 spin_unlock_irqrestore(&pcdev->lock, flags);
249 }
250
251 static void sh_mobile_ceu_videobuf_release(struct videobuf_queue *vq,
252 struct videobuf_buffer *vb)
253 {
254 free_buffer(vq, container_of(vb, struct sh_mobile_ceu_buffer, vb));
255 }
256
257 static struct videobuf_queue_ops sh_mobile_ceu_videobuf_ops = {
258 .buf_setup = sh_mobile_ceu_videobuf_setup,
259 .buf_prepare = sh_mobile_ceu_videobuf_prepare,
260 .buf_queue = sh_mobile_ceu_videobuf_queue,
261 .buf_release = sh_mobile_ceu_videobuf_release,
262 };
263
264 static irqreturn_t sh_mobile_ceu_irq(int irq, void *data)
265 {
266 struct sh_mobile_ceu_dev *pcdev = data;
267 struct videobuf_buffer *vb;
268 unsigned long flags;
269
270 spin_lock_irqsave(&pcdev->lock, flags);
271
272 vb = pcdev->active;
273 list_del_init(&vb->queue);
274
275 if (!list_empty(&pcdev->capture))
276 pcdev->active = list_entry(pcdev->capture.next,
277 struct videobuf_buffer, queue);
278 else
279 pcdev->active = NULL;
280
281 sh_mobile_ceu_capture(pcdev);
282
283 vb->state = VIDEOBUF_DONE;
284 do_gettimeofday(&vb->ts);
285 vb->field_count++;
286 wake_up(&vb->done);
287 spin_unlock_irqrestore(&pcdev->lock, flags);
288
289 return IRQ_HANDLED;
290 }
291
292 static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
293 {
294 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
295 struct sh_mobile_ceu_dev *pcdev = ici->priv;
296 int ret = -EBUSY;
297
298 mutex_lock(&camera_lock);
299
300 if (pcdev->icd)
301 goto err;
302
303 dev_info(&icd->dev,
304 "SuperH Mobile CEU driver attached to camera %d\n",
305 icd->devnum);
306
307 ret = icd->ops->init(icd);
308 if (ret)
309 goto err;
310
311 ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
312 while (ceu_read(pcdev, CSTSR) & 1)
313 msleep(1);
314
315 pcdev->icd = icd;
316 err:
317 mutex_unlock(&camera_lock);
318
319 return ret;
320 }
321
322 static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
323 {
324 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
325 struct sh_mobile_ceu_dev *pcdev = ici->priv;
326
327 BUG_ON(icd != pcdev->icd);
328
329 /* disable capture, disable interrupts */
330 ceu_write(pcdev, CEIER, 0);
331 ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
332 icd->ops->release(icd);
333
334 dev_info(&icd->dev,
335 "SuperH Mobile CEU driver detached from camera %d\n",
336 icd->devnum);
337
338 pcdev->icd = NULL;
339 }
340
341 static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
342 __u32 pixfmt)
343 {
344 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
345 struct sh_mobile_ceu_dev *pcdev = ici->priv;
346 int ret, buswidth, width, cfszr_width, cdwdr_width;
347 unsigned long camera_flags, common_flags, value;
348
349 camera_flags = icd->ops->query_bus_param(icd);
350 common_flags = soc_camera_bus_param_compatible(camera_flags,
351 pcdev->pdata->flags);
352 if (!common_flags)
353 return -EINVAL;
354
355 ret = icd->ops->set_bus_param(icd, common_flags);
356 if (ret < 0)
357 return ret;
358
359 switch (common_flags & SOCAM_DATAWIDTH_MASK) {
360 case SOCAM_DATAWIDTH_8:
361 buswidth = 8;
362 break;
363 case SOCAM_DATAWIDTH_16:
364 buswidth = 16;
365 break;
366 default:
367 return -EINVAL;
368 }
369
370 ceu_write(pcdev, CRCNTR, 0);
371 ceu_write(pcdev, CRCMPR, 0);
372
373 value = 0x00000010;
374 value |= (common_flags & SOCAM_VSYNC_ACTIVE_LOW) ? (1 << 1) : 0;
375 value |= (common_flags & SOCAM_HSYNC_ACTIVE_LOW) ? (1 << 0) : 0;
376 value |= (buswidth == 16) ? (1 << 12) : 0;
377 ceu_write(pcdev, CAMCR, value);
378
379 ceu_write(pcdev, CAPCR, 0x00300000);
380 ceu_write(pcdev, CAIFR, 0);
381
382 mdelay(1);
383
384 width = icd->width * (icd->current_fmt->depth / 8);
385 width = (buswidth == 16) ? width / 2 : width;
386 cfszr_width = (buswidth == 8) ? width / 2 : width;
387 cdwdr_width = (buswidth == 16) ? width * 2 : width;
388
389 ceu_write(pcdev, CAMOR, 0);
390 ceu_write(pcdev, CAPWR, (icd->height << 16) | width);
391 ceu_write(pcdev, CFLCR, 0); /* data fetch mode - no scaling */
392 ceu_write(pcdev, CFSZR, (icd->height << 16) | cfszr_width);
393 ceu_write(pcdev, CLFCR, 0); /* data fetch mode - no lowpass filter */
394
395 /* A few words about byte order (observed in Big Endian mode)
396 *
397 * In data fetch mode bytes are received in chunks of 8 bytes.
398 * D0, D1, D2, D3, D4, D5, D6, D7 (D0 received first)
399 *
400 * The data is however by default written to memory in reverse order:
401 * D7, D6, D5, D4, D3, D2, D1, D0 (D7 written to lowest byte)
402 *
403 * The lowest three bits of CDOCR allows us to do swapping,
404 * using 7 we swap the data bytes to match the incoming order:
405 * D0, D1, D2, D3, D4, D5, D6, D7
406 */
407 ceu_write(pcdev, CDOCR, 0x00000017);
408
409 ceu_write(pcdev, CDWDR, cdwdr_width);
410 ceu_write(pcdev, CFWCR, 0); /* keep "datafetch firewall" disabled */
411
412 /* not in bundle mode: skip CBDSR, CDAYR2, CDACR2, CDBYR2, CDBCR2 */
413 /* in data fetch mode: no need for CDACR, CDBYR, CDBCR */
414
415 return 0;
416 }
417
418 static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd,
419 __u32 pixfmt)
420 {
421 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
422 struct sh_mobile_ceu_dev *pcdev = ici->priv;
423 unsigned long camera_flags, common_flags;
424
425 camera_flags = icd->ops->query_bus_param(icd);
426 common_flags = soc_camera_bus_param_compatible(camera_flags,
427 pcdev->pdata->flags);
428 if (!common_flags)
429 return -EINVAL;
430
431 return 0;
432 }
433
434 static int sh_mobile_ceu_set_fmt_cap(struct soc_camera_device *icd,
435 __u32 pixfmt, struct v4l2_rect *rect)
436 {
437 return icd->ops->set_fmt_cap(icd, pixfmt, rect);
438 }
439
440 static int sh_mobile_ceu_try_fmt_cap(struct soc_camera_device *icd,
441 struct v4l2_format *f)
442 {
443 /* FIXME: calculate using depth and bus width */
444
445 if (f->fmt.pix.height < 4)
446 f->fmt.pix.height = 4;
447 if (f->fmt.pix.height > 1920)
448 f->fmt.pix.height = 1920;
449 if (f->fmt.pix.width < 2)
450 f->fmt.pix.width = 2;
451 if (f->fmt.pix.width > 2560)
452 f->fmt.pix.width = 2560;
453 f->fmt.pix.width &= ~0x01;
454 f->fmt.pix.height &= ~0x03;
455
456 /* limit to sensor capabilities */
457 return icd->ops->try_fmt_cap(icd, f);
458 }
459
460 static int sh_mobile_ceu_reqbufs(struct soc_camera_file *icf,
461 struct v4l2_requestbuffers *p)
462 {
463 int i;
464
465 /* This is for locking debugging only. I removed spinlocks and now I
466 * check whether .prepare is ever called on a linked buffer, or whether
467 * a dma IRQ can occur for an in-work or unlinked buffer. Until now
468 * it hadn't triggered */
469 for (i = 0; i < p->count; i++) {
470 struct sh_mobile_ceu_buffer *buf;
471
472 buf = container_of(icf->vb_vidq.bufs[i],
473 struct sh_mobile_ceu_buffer, vb);
474 INIT_LIST_HEAD(&buf->vb.queue);
475 }
476
477 return 0;
478 }
479
480 static unsigned int sh_mobile_ceu_poll(struct file *file, poll_table *pt)
481 {
482 struct soc_camera_file *icf = file->private_data;
483 struct sh_mobile_ceu_buffer *buf;
484
485 buf = list_entry(icf->vb_vidq.stream.next,
486 struct sh_mobile_ceu_buffer, vb.stream);
487
488 poll_wait(file, &buf->vb.done, pt);
489
490 if (buf->vb.state == VIDEOBUF_DONE ||
491 buf->vb.state == VIDEOBUF_ERROR)
492 return POLLIN|POLLRDNORM;
493
494 return 0;
495 }
496
497 static int sh_mobile_ceu_querycap(struct soc_camera_host *ici,
498 struct v4l2_capability *cap)
499 {
500 strlcpy(cap->card, "SuperH_Mobile_CEU", sizeof(cap->card));
501 cap->version = KERNEL_VERSION(0, 0, 5);
502 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
503 return 0;
504 }
505
506 static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q,
507 struct soc_camera_device *icd)
508 {
509 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
510 struct sh_mobile_ceu_dev *pcdev = ici->priv;
511
512 videobuf_queue_dma_contig_init(q,
513 &sh_mobile_ceu_videobuf_ops,
514 &ici->dev, &pcdev->lock,
515 V4L2_BUF_TYPE_VIDEO_CAPTURE,
516 V4L2_FIELD_NONE,
517 sizeof(struct sh_mobile_ceu_buffer),
518 icd);
519 }
520
521 static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
522 .owner = THIS_MODULE,
523 .add = sh_mobile_ceu_add_device,
524 .remove = sh_mobile_ceu_remove_device,
525 .set_fmt_cap = sh_mobile_ceu_set_fmt_cap,
526 .try_fmt_cap = sh_mobile_ceu_try_fmt_cap,
527 .reqbufs = sh_mobile_ceu_reqbufs,
528 .poll = sh_mobile_ceu_poll,
529 .querycap = sh_mobile_ceu_querycap,
530 .try_bus_param = sh_mobile_ceu_try_bus_param,
531 .set_bus_param = sh_mobile_ceu_set_bus_param,
532 .init_videobuf = sh_mobile_ceu_init_videobuf,
533 };
534
535 static int sh_mobile_ceu_probe(struct platform_device *pdev)
536 {
537 struct sh_mobile_ceu_dev *pcdev;
538 struct resource *res;
539 void __iomem *base;
540 unsigned int irq;
541 int err = 0;
542
543 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
544 irq = platform_get_irq(pdev, 0);
545 if (!res || !irq) {
546 dev_err(&pdev->dev, "Not enough CEU platform resources.\n");
547 err = -ENODEV;
548 goto exit;
549 }
550
551 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
552 if (!pcdev) {
553 dev_err(&pdev->dev, "Could not allocate pcdev\n");
554 err = -ENOMEM;
555 goto exit;
556 }
557
558 platform_set_drvdata(pdev, pcdev);
559 INIT_LIST_HEAD(&pcdev->capture);
560 spin_lock_init(&pcdev->lock);
561
562 pcdev->pdata = pdev->dev.platform_data;
563 if (!pcdev->pdata) {
564 err = -EINVAL;
565 dev_err(&pdev->dev, "CEU platform data not set.\n");
566 goto exit_kfree;
567 }
568
569 base = ioremap_nocache(res->start, res->end - res->start + 1);
570 if (!base) {
571 err = -ENXIO;
572 dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n");
573 goto exit_kfree;
574 }
575
576 pcdev->irq = irq;
577 pcdev->base = base;
578 pcdev->video_limit = 0; /* only enabled if second resource exists */
579 pcdev->dev = &pdev->dev;
580
581 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
582 if (res) {
583 err = dma_declare_coherent_memory(&pdev->dev, res->start,
584 res->start,
585 (res->end - res->start) + 1,
586 DMA_MEMORY_MAP |
587 DMA_MEMORY_EXCLUSIVE);
588 if (!err) {
589 dev_err(&pdev->dev, "Unable to declare CEU memory.\n");
590 err = -ENXIO;
591 goto exit_iounmap;
592 }
593
594 pcdev->video_limit = (res->end - res->start) + 1;
595 }
596
597 /* request irq */
598 err = request_irq(pcdev->irq, sh_mobile_ceu_irq, IRQF_DISABLED,
599 pdev->dev.bus_id, pcdev);
600 if (err) {
601 dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
602 goto exit_release_mem;
603 }
604
605 pcdev->ici.priv = pcdev;
606 pcdev->ici.dev.parent = &pdev->dev;
607 pcdev->ici.nr = pdev->id;
608 pcdev->ici.drv_name = pdev->dev.bus_id,
609 pcdev->ici.ops = &sh_mobile_ceu_host_ops,
610
611 err = soc_camera_host_register(&pcdev->ici);
612 if (err)
613 goto exit_free_irq;
614
615 return 0;
616
617 exit_free_irq:
618 free_irq(pcdev->irq, pcdev);
619 exit_release_mem:
620 if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
621 dma_release_declared_memory(&pdev->dev);
622 exit_iounmap:
623 iounmap(base);
624 exit_kfree:
625 kfree(pcdev);
626 exit:
627 return err;
628 }
629
630 static int sh_mobile_ceu_remove(struct platform_device *pdev)
631 {
632 struct sh_mobile_ceu_dev *pcdev = platform_get_drvdata(pdev);
633
634 soc_camera_host_unregister(&pcdev->ici);
635 free_irq(pcdev->irq, pcdev);
636 if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
637 dma_release_declared_memory(&pdev->dev);
638 iounmap(pcdev->base);
639 kfree(pcdev);
640 return 0;
641 }
642
643 static struct platform_driver sh_mobile_ceu_driver = {
644 .driver = {
645 .name = "sh_mobile_ceu",
646 },
647 .probe = sh_mobile_ceu_probe,
648 .remove = sh_mobile_ceu_remove,
649 };
650
651 static int __init sh_mobile_ceu_init(void)
652 {
653 return platform_driver_register(&sh_mobile_ceu_driver);
654 }
655
656 static void __exit sh_mobile_ceu_exit(void)
657 {
658 platform_driver_unregister(&sh_mobile_ceu_driver);
659 }
660
661 module_init(sh_mobile_ceu_init);
662 module_exit(sh_mobile_ceu_exit);
663
664 MODULE_DESCRIPTION("SuperH Mobile CEU driver");
665 MODULE_AUTHOR("Magnus Damm");
666 MODULE_LICENSE("GPL");
This page took 0.048373 seconds and 6 git commands to generate.