Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1 | /* |
| 2 | * V4L2 Driver for PXA camera host |
| 3 | * |
| 4 | * Copyright (C) 2006, Sascha Hauer, Pengutronix |
| 5 | * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 15 | #include <linux/io.h> |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/dma-mapping.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/fs.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/moduleparam.h> |
| 24 | #include <linux/time.h> |
| 25 | #include <linux/version.h> |
| 26 | #include <linux/device.h> |
| 27 | #include <linux/platform_device.h> |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 28 | #include <linux/clk.h> |
| 29 | |
| 30 | #include <media/v4l2-common.h> |
| 31 | #include <media/v4l2-dev.h> |
Paulius Zaleckas | 092d392 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 32 | #include <media/videobuf-dma-sg.h> |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 33 | #include <media/soc_camera.h> |
| 34 | |
| 35 | #include <linux/videodev2.h> |
| 36 | |
Eric Miao | cfbaf4d | 2009-01-02 12:16:02 -0300 | [diff] [blame] | 37 | #include <mach/dma.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 38 | #include <mach/camera.h> |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 39 | |
| 40 | #define PXA_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5) |
| 41 | #define PXA_CAM_DRV_NAME "pxa27x-camera" |
| 42 | |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 43 | /* Camera Interface */ |
| 44 | #define CICR0 0x0000 |
| 45 | #define CICR1 0x0004 |
| 46 | #define CICR2 0x0008 |
| 47 | #define CICR3 0x000C |
| 48 | #define CICR4 0x0010 |
| 49 | #define CISR 0x0014 |
| 50 | #define CIFR 0x0018 |
| 51 | #define CITOR 0x001C |
| 52 | #define CIBR0 0x0028 |
| 53 | #define CIBR1 0x0030 |
| 54 | #define CIBR2 0x0038 |
| 55 | |
| 56 | #define CICR0_DMAEN (1 << 31) /* DMA request enable */ |
| 57 | #define CICR0_PAR_EN (1 << 30) /* Parity enable */ |
| 58 | #define CICR0_SL_CAP_EN (1 << 29) /* Capture enable for slave mode */ |
| 59 | #define CICR0_ENB (1 << 28) /* Camera interface enable */ |
| 60 | #define CICR0_DIS (1 << 27) /* Camera interface disable */ |
| 61 | #define CICR0_SIM (0x7 << 24) /* Sensor interface mode mask */ |
| 62 | #define CICR0_TOM (1 << 9) /* Time-out mask */ |
| 63 | #define CICR0_RDAVM (1 << 8) /* Receive-data-available mask */ |
| 64 | #define CICR0_FEM (1 << 7) /* FIFO-empty mask */ |
| 65 | #define CICR0_EOLM (1 << 6) /* End-of-line mask */ |
| 66 | #define CICR0_PERRM (1 << 5) /* Parity-error mask */ |
| 67 | #define CICR0_QDM (1 << 4) /* Quick-disable mask */ |
| 68 | #define CICR0_CDM (1 << 3) /* Disable-done mask */ |
| 69 | #define CICR0_SOFM (1 << 2) /* Start-of-frame mask */ |
| 70 | #define CICR0_EOFM (1 << 1) /* End-of-frame mask */ |
| 71 | #define CICR0_FOM (1 << 0) /* FIFO-overrun mask */ |
| 72 | |
| 73 | #define CICR1_TBIT (1 << 31) /* Transparency bit */ |
| 74 | #define CICR1_RGBT_CONV (0x3 << 29) /* RGBT conversion mask */ |
| 75 | #define CICR1_PPL (0x7ff << 15) /* Pixels per line mask */ |
| 76 | #define CICR1_RGB_CONV (0x7 << 12) /* RGB conversion mask */ |
| 77 | #define CICR1_RGB_F (1 << 11) /* RGB format */ |
| 78 | #define CICR1_YCBCR_F (1 << 10) /* YCbCr format */ |
| 79 | #define CICR1_RGB_BPP (0x7 << 7) /* RGB bis per pixel mask */ |
| 80 | #define CICR1_RAW_BPP (0x3 << 5) /* Raw bis per pixel mask */ |
| 81 | #define CICR1_COLOR_SP (0x3 << 3) /* Color space mask */ |
| 82 | #define CICR1_DW (0x7 << 0) /* Data width mask */ |
| 83 | |
| 84 | #define CICR2_BLW (0xff << 24) /* Beginning-of-line pixel clock |
| 85 | wait count mask */ |
| 86 | #define CICR2_ELW (0xff << 16) /* End-of-line pixel clock |
| 87 | wait count mask */ |
| 88 | #define CICR2_HSW (0x3f << 10) /* Horizontal sync pulse width mask */ |
| 89 | #define CICR2_BFPW (0x3f << 3) /* Beginning-of-frame pixel clock |
| 90 | wait count mask */ |
| 91 | #define CICR2_FSW (0x7 << 0) /* Frame stabilization |
| 92 | wait count mask */ |
| 93 | |
| 94 | #define CICR3_BFW (0xff << 24) /* Beginning-of-frame line clock |
| 95 | wait count mask */ |
| 96 | #define CICR3_EFW (0xff << 16) /* End-of-frame line clock |
| 97 | wait count mask */ |
| 98 | #define CICR3_VSW (0x3f << 10) /* Vertical sync pulse width mask */ |
| 99 | #define CICR3_BFPW (0x3f << 3) /* Beginning-of-frame pixel clock |
| 100 | wait count mask */ |
| 101 | #define CICR3_LPF (0x7ff << 0) /* Lines per frame mask */ |
| 102 | |
| 103 | #define CICR4_MCLK_DLY (0x3 << 24) /* MCLK Data Capture Delay mask */ |
| 104 | #define CICR4_PCLK_EN (1 << 23) /* Pixel clock enable */ |
| 105 | #define CICR4_PCP (1 << 22) /* Pixel clock polarity */ |
| 106 | #define CICR4_HSP (1 << 21) /* Horizontal sync polarity */ |
| 107 | #define CICR4_VSP (1 << 20) /* Vertical sync polarity */ |
| 108 | #define CICR4_MCLK_EN (1 << 19) /* MCLK enable */ |
| 109 | #define CICR4_FR_RATE (0x7 << 8) /* Frame rate mask */ |
| 110 | #define CICR4_DIV (0xff << 0) /* Clock divisor mask */ |
| 111 | |
| 112 | #define CISR_FTO (1 << 15) /* FIFO time-out */ |
| 113 | #define CISR_RDAV_2 (1 << 14) /* Channel 2 receive data available */ |
| 114 | #define CISR_RDAV_1 (1 << 13) /* Channel 1 receive data available */ |
| 115 | #define CISR_RDAV_0 (1 << 12) /* Channel 0 receive data available */ |
| 116 | #define CISR_FEMPTY_2 (1 << 11) /* Channel 2 FIFO empty */ |
| 117 | #define CISR_FEMPTY_1 (1 << 10) /* Channel 1 FIFO empty */ |
| 118 | #define CISR_FEMPTY_0 (1 << 9) /* Channel 0 FIFO empty */ |
| 119 | #define CISR_EOL (1 << 8) /* End of line */ |
| 120 | #define CISR_PAR_ERR (1 << 7) /* Parity error */ |
| 121 | #define CISR_CQD (1 << 6) /* Camera interface quick disable */ |
| 122 | #define CISR_CDD (1 << 5) /* Camera interface disable done */ |
| 123 | #define CISR_SOF (1 << 4) /* Start of frame */ |
| 124 | #define CISR_EOF (1 << 3) /* End of frame */ |
| 125 | #define CISR_IFO_2 (1 << 2) /* FIFO overrun for Channel 2 */ |
| 126 | #define CISR_IFO_1 (1 << 1) /* FIFO overrun for Channel 1 */ |
| 127 | #define CISR_IFO_0 (1 << 0) /* FIFO overrun for Channel 0 */ |
| 128 | |
| 129 | #define CIFR_FLVL2 (0x7f << 23) /* FIFO 2 level mask */ |
| 130 | #define CIFR_FLVL1 (0x7f << 16) /* FIFO 1 level mask */ |
| 131 | #define CIFR_FLVL0 (0xff << 8) /* FIFO 0 level mask */ |
| 132 | #define CIFR_THL_0 (0x3 << 4) /* Threshold Level for Channel 0 FIFO */ |
| 133 | #define CIFR_RESET_F (1 << 3) /* Reset input FIFOs */ |
| 134 | #define CIFR_FEN2 (1 << 2) /* FIFO enable for channel 2 */ |
| 135 | #define CIFR_FEN1 (1 << 1) /* FIFO enable for channel 1 */ |
| 136 | #define CIFR_FEN0 (1 << 0) /* FIFO enable for channel 0 */ |
| 137 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 138 | #define CICR0_SIM_MP (0 << 24) |
| 139 | #define CICR0_SIM_SP (1 << 24) |
| 140 | #define CICR0_SIM_MS (2 << 24) |
| 141 | #define CICR0_SIM_EP (3 << 24) |
| 142 | #define CICR0_SIM_ES (4 << 24) |
| 143 | |
| 144 | #define CICR1_DW_VAL(x) ((x) & CICR1_DW) /* Data bus width */ |
| 145 | #define CICR1_PPL_VAL(x) (((x) << 15) & CICR1_PPL) /* Pixels per line */ |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 146 | #define CICR1_COLOR_SP_VAL(x) (((x) << 3) & CICR1_COLOR_SP) /* color space */ |
| 147 | #define CICR1_RGB_BPP_VAL(x) (((x) << 7) & CICR1_RGB_BPP) /* bpp for rgb */ |
| 148 | #define CICR1_RGBT_CONV_VAL(x) (((x) << 29) & CICR1_RGBT_CONV) /* rgbt conv */ |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 149 | |
| 150 | #define CICR2_BLW_VAL(x) (((x) << 24) & CICR2_BLW) /* Beginning-of-line pixel clock wait count */ |
| 151 | #define CICR2_ELW_VAL(x) (((x) << 16) & CICR2_ELW) /* End-of-line pixel clock wait count */ |
| 152 | #define CICR2_HSW_VAL(x) (((x) << 10) & CICR2_HSW) /* Horizontal sync pulse width */ |
| 153 | #define CICR2_BFPW_VAL(x) (((x) << 3) & CICR2_BFPW) /* Beginning-of-frame pixel clock wait count */ |
| 154 | #define CICR2_FSW_VAL(x) (((x) << 0) & CICR2_FSW) /* Frame stabilization wait count */ |
| 155 | |
| 156 | #define CICR3_BFW_VAL(x) (((x) << 24) & CICR3_BFW) /* Beginning-of-frame line clock wait count */ |
| 157 | #define CICR3_EFW_VAL(x) (((x) << 16) & CICR3_EFW) /* End-of-frame line clock wait count */ |
| 158 | #define CICR3_VSW_VAL(x) (((x) << 11) & CICR3_VSW) /* Vertical sync pulse width */ |
| 159 | #define CICR3_LPF_VAL(x) (((x) << 0) & CICR3_LPF) /* Lines per frame */ |
| 160 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 161 | #define CICR0_IRQ_MASK (CICR0_TOM | CICR0_RDAVM | CICR0_FEM | CICR0_EOLM | \ |
| 162 | CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \ |
| 163 | CICR0_EOFM | CICR0_FOM) |
| 164 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 165 | /* |
| 166 | * Structures |
| 167 | */ |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 168 | enum pxa_camera_active_dma { |
| 169 | DMA_Y = 0x1, |
| 170 | DMA_U = 0x2, |
| 171 | DMA_V = 0x4, |
| 172 | }; |
| 173 | |
| 174 | /* descriptor needed for the PXA DMA engine */ |
| 175 | struct pxa_cam_dma { |
| 176 | dma_addr_t sg_dma; |
| 177 | struct pxa_dma_desc *sg_cpu; |
| 178 | size_t sg_size; |
| 179 | int sglen; |
| 180 | }; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 181 | |
| 182 | /* buffer for one video frame */ |
| 183 | struct pxa_buffer { |
| 184 | /* common v4l buffer stuff -- must be first */ |
| 185 | struct videobuf_buffer vb; |
| 186 | |
| 187 | const struct soc_camera_data_format *fmt; |
| 188 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 189 | /* our descriptor lists for Y, U and V channels */ |
| 190 | struct pxa_cam_dma dmas[3]; |
| 191 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 192 | int inwork; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 193 | |
| 194 | enum pxa_camera_active_dma active_dma; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 195 | }; |
| 196 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 197 | struct pxa_camera_dev { |
Guennadi Liakhovetski | eb6c855 | 2009-04-24 12:55:18 -0300 | [diff] [blame] | 198 | struct soc_camera_host soc_host; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 199 | /* PXA27x is only supposed to handle one camera on its Quick Capture |
| 200 | * interface. If anyone ever builds hardware to enable more than |
| 201 | * one camera, they will have to modify this driver too */ |
| 202 | struct soc_camera_device *icd; |
| 203 | struct clk *clk; |
| 204 | |
| 205 | unsigned int irq; |
| 206 | void __iomem *base; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 207 | |
Guennadi Liakhovetski | e7c5068 | 2008-04-22 10:37:49 -0300 | [diff] [blame] | 208 | int channels; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 209 | unsigned int dma_chans[3]; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 210 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 211 | struct pxacamera_platform_data *pdata; |
| 212 | struct resource *res; |
| 213 | unsigned long platform_flags; |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 214 | unsigned long ciclk; |
| 215 | unsigned long mclk; |
| 216 | u32 mclk_divisor; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 217 | |
| 218 | struct list_head capture; |
| 219 | |
| 220 | spinlock_t lock; |
| 221 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 222 | struct pxa_buffer *active; |
Guennadi Liakhovetski | 5aa2110 | 2008-04-22 10:40:23 -0300 | [diff] [blame] | 223 | struct pxa_dma_desc *sg_tail[3]; |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 224 | |
| 225 | u32 save_cicr[5]; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 226 | }; |
| 227 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 228 | struct pxa_cam { |
| 229 | unsigned long flags; |
| 230 | }; |
| 231 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 232 | static const char *pxa_cam_driver_description = "PXA_Camera"; |
| 233 | |
| 234 | static unsigned int vid_limit = 16; /* Video memory limit, in Mb */ |
| 235 | |
| 236 | /* |
| 237 | * Videobuf operations |
| 238 | */ |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 239 | static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, |
| 240 | unsigned int *size) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 241 | { |
| 242 | struct soc_camera_device *icd = vq->priv_data; |
| 243 | |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 244 | dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 245 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 246 | *size = roundup(icd->user_width * icd->user_height * |
Robert Jarzmik | 92a8337 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 247 | ((icd->current_fmt->depth + 7) >> 3), 8); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 248 | |
| 249 | if (0 == *count) |
| 250 | *count = 32; |
| 251 | while (*size * *count > vid_limit * 1024 * 1024) |
| 252 | (*count)--; |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf) |
| 258 | { |
| 259 | struct soc_camera_device *icd = vq->priv_data; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 260 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 261 | struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 262 | int i; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 263 | |
| 264 | BUG_ON(in_interrupt()); |
| 265 | |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 266 | dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__, |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 267 | &buf->vb, buf->vb.baddr, buf->vb.bsize); |
| 268 | |
| 269 | /* This waits until this buffer is out of danger, i.e., until it is no |
| 270 | * longer in STATE_QUEUED or STATE_ACTIVE */ |
| 271 | videobuf_waiton(&buf->vb, 0, 0); |
| 272 | videobuf_dma_unmap(vq, dma); |
| 273 | videobuf_dma_free(dma); |
| 274 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 275 | for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) { |
| 276 | if (buf->dmas[i].sg_cpu) |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 277 | dma_free_coherent(ici->v4l2_dev.dev, buf->dmas[i].sg_size, |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 278 | buf->dmas[i].sg_cpu, |
| 279 | buf->dmas[i].sg_dma); |
| 280 | buf->dmas[i].sg_cpu = NULL; |
| 281 | } |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 282 | |
| 283 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
| 284 | } |
| 285 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 286 | static int calculate_dma_sglen(struct scatterlist *sglist, int sglen, |
| 287 | int sg_first_ofs, int size) |
| 288 | { |
| 289 | int i, offset, dma_len, xfer_len; |
| 290 | struct scatterlist *sg; |
| 291 | |
| 292 | offset = sg_first_ofs; |
| 293 | for_each_sg(sglist, sg, sglen, i) { |
| 294 | dma_len = sg_dma_len(sg); |
| 295 | |
| 296 | /* PXA27x Developer's Manual 27.4.4.1: round up to 8 bytes */ |
| 297 | xfer_len = roundup(min(dma_len - offset, size), 8); |
| 298 | |
| 299 | size = max(0, size - xfer_len); |
| 300 | offset = 0; |
| 301 | if (size == 0) |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | BUG_ON(size != 0); |
| 306 | return i + 1; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * pxa_init_dma_channel - init dma descriptors |
| 311 | * @pcdev: pxa camera device |
| 312 | * @buf: pxa buffer to find pxa dma channel |
| 313 | * @dma: dma video buffer |
| 314 | * @channel: dma channel (0 => 'Y', 1 => 'U', 2 => 'V') |
| 315 | * @cibr: camera Receive Buffer Register |
| 316 | * @size: bytes to transfer |
| 317 | * @sg_first: first element of sg_list |
| 318 | * @sg_first_ofs: offset in first element of sg_list |
| 319 | * |
| 320 | * Prepares the pxa dma descriptors to transfer one camera channel. |
| 321 | * Beware sg_first and sg_first_ofs are both input and output parameters. |
| 322 | * |
| 323 | * Returns 0 or -ENOMEM if no coherent memory is available |
| 324 | */ |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 325 | static int pxa_init_dma_channel(struct pxa_camera_dev *pcdev, |
| 326 | struct pxa_buffer *buf, |
| 327 | struct videobuf_dmabuf *dma, int channel, |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 328 | int cibr, int size, |
| 329 | struct scatterlist **sg_first, int *sg_first_ofs) |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 330 | { |
| 331 | struct pxa_cam_dma *pxa_dma = &buf->dmas[channel]; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 332 | struct device *dev = pcdev->soc_host.v4l2_dev.dev; |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 333 | struct scatterlist *sg; |
| 334 | int i, offset, sglen; |
| 335 | int dma_len = 0, xfer_len = 0; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 336 | |
| 337 | if (pxa_dma->sg_cpu) |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 338 | dma_free_coherent(dev, pxa_dma->sg_size, |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 339 | pxa_dma->sg_cpu, pxa_dma->sg_dma); |
| 340 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 341 | sglen = calculate_dma_sglen(*sg_first, dma->sglen, |
| 342 | *sg_first_ofs, size); |
| 343 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 344 | pxa_dma->sg_size = (sglen + 1) * sizeof(struct pxa_dma_desc); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 345 | pxa_dma->sg_cpu = dma_alloc_coherent(dev, pxa_dma->sg_size, |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 346 | &pxa_dma->sg_dma, GFP_KERNEL); |
| 347 | if (!pxa_dma->sg_cpu) |
| 348 | return -ENOMEM; |
| 349 | |
| 350 | pxa_dma->sglen = sglen; |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 351 | offset = *sg_first_ofs; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 352 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 353 | dev_dbg(dev, "DMA: sg_first=%p, sglen=%d, ofs=%d, dma.desc=%x\n", |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 354 | *sg_first, sglen, *sg_first_ofs, pxa_dma->sg_dma); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 355 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 356 | |
| 357 | for_each_sg(*sg_first, sg, sglen, i) { |
| 358 | dma_len = sg_dma_len(sg); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 359 | |
| 360 | /* PXA27x Developer's Manual 27.4.4.1: round up to 8 bytes */ |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 361 | xfer_len = roundup(min(dma_len - offset, size), 8); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 362 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 363 | size = max(0, size - xfer_len); |
| 364 | |
| 365 | pxa_dma->sg_cpu[i].dsadr = pcdev->res->start + cibr; |
| 366 | pxa_dma->sg_cpu[i].dtadr = sg_dma_address(sg) + offset; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 367 | pxa_dma->sg_cpu[i].dcmd = |
| 368 | DCMD_FLOWSRC | DCMD_BURST8 | DCMD_INCTRGADDR | xfer_len; |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 369 | #ifdef DEBUG |
| 370 | if (!i) |
| 371 | pxa_dma->sg_cpu[i].dcmd |= DCMD_STARTIRQEN; |
| 372 | #endif |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 373 | pxa_dma->sg_cpu[i].ddadr = |
| 374 | pxa_dma->sg_dma + (i + 1) * sizeof(struct pxa_dma_desc); |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 375 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 376 | dev_vdbg(dev, "DMA: desc.%08x->@phys=0x%08x, len=%d\n", |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 377 | pxa_dma->sg_dma + i * sizeof(struct pxa_dma_desc), |
| 378 | sg_dma_address(sg) + offset, xfer_len); |
| 379 | offset = 0; |
| 380 | |
| 381 | if (size == 0) |
| 382 | break; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 383 | } |
| 384 | |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 385 | pxa_dma->sg_cpu[sglen].ddadr = DDADR_STOP; |
| 386 | pxa_dma->sg_cpu[sglen].dcmd = DCMD_FLOWSRC | DCMD_BURST8 | DCMD_ENDIRQEN; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 387 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 388 | /* |
| 389 | * Handle 1 special case : |
| 390 | * - in 3 planes (YUV422P format), we might finish with xfer_len equal |
| 391 | * to dma_len (end on PAGE boundary). In this case, the sg element |
| 392 | * for next plane should be the next after the last used to store the |
| 393 | * last scatter gather RAM page |
| 394 | */ |
| 395 | if (xfer_len >= dma_len) { |
| 396 | *sg_first_ofs = xfer_len - dma_len; |
| 397 | *sg_first = sg_next(sg); |
| 398 | } else { |
| 399 | *sg_first_ofs = xfer_len; |
| 400 | *sg_first = sg; |
| 401 | } |
| 402 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 403 | return 0; |
| 404 | } |
| 405 | |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 406 | static void pxa_videobuf_set_actdma(struct pxa_camera_dev *pcdev, |
| 407 | struct pxa_buffer *buf) |
| 408 | { |
| 409 | buf->active_dma = DMA_Y; |
| 410 | if (pcdev->channels == 3) |
| 411 | buf->active_dma |= DMA_U | DMA_V; |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * Please check the DMA prepared buffer structure in : |
| 416 | * Documentation/video4linux/pxa_camera.txt |
| 417 | * Please check also in pxa_camera_check_link_miss() to understand why DMA chain |
| 418 | * modification while DMA chain is running will work anyway. |
| 419 | */ |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 420 | static int pxa_videobuf_prepare(struct videobuf_queue *vq, |
| 421 | struct videobuf_buffer *vb, enum v4l2_field field) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 422 | { |
| 423 | struct soc_camera_device *icd = vq->priv_data; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 424 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 425 | struct pxa_camera_dev *pcdev = ici->priv; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 426 | struct device *dev = pcdev->soc_host.v4l2_dev.dev; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 427 | struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 428 | int ret; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 429 | int size_y, size_u = 0, size_v = 0; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 430 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 431 | dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 432 | vb, vb->baddr, vb->bsize); |
| 433 | |
| 434 | /* Added list head initialization on alloc */ |
| 435 | WARN_ON(!list_empty(&vb->queue)); |
| 436 | |
| 437 | #ifdef DEBUG |
| 438 | /* This can be useful if you want to see if we actually fill |
| 439 | * the buffer with something */ |
| 440 | memset((void *)vb->baddr, 0xaa, vb->bsize); |
| 441 | #endif |
| 442 | |
| 443 | BUG_ON(NULL == icd->current_fmt); |
| 444 | |
| 445 | /* I think, in buf_prepare you only have to protect global data, |
| 446 | * the actual buffer is yours */ |
| 447 | buf->inwork = 1; |
| 448 | |
| 449 | if (buf->fmt != icd->current_fmt || |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 450 | vb->width != icd->user_width || |
| 451 | vb->height != icd->user_height || |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 452 | vb->field != field) { |
| 453 | buf->fmt = icd->current_fmt; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 454 | vb->width = icd->user_width; |
| 455 | vb->height = icd->user_height; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 456 | vb->field = field; |
| 457 | vb->state = VIDEOBUF_NEEDS_INIT; |
| 458 | } |
| 459 | |
| 460 | vb->size = vb->width * vb->height * ((buf->fmt->depth + 7) >> 3); |
| 461 | if (0 != vb->baddr && vb->bsize < vb->size) { |
| 462 | ret = -EINVAL; |
| 463 | goto out; |
| 464 | } |
| 465 | |
| 466 | if (vb->state == VIDEOBUF_NEEDS_INIT) { |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 467 | int size = vb->size; |
| 468 | int next_ofs = 0; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 469 | struct videobuf_dmabuf *dma = videobuf_to_dma(vb); |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 470 | struct scatterlist *sg; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 471 | |
| 472 | ret = videobuf_iolock(vq, vb, NULL); |
| 473 | if (ret) |
| 474 | goto fail; |
| 475 | |
Guennadi Liakhovetski | 5aa2110 | 2008-04-22 10:40:23 -0300 | [diff] [blame] | 476 | if (pcdev->channels == 3) { |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 477 | size_y = size / 2; |
| 478 | size_u = size_v = size / 4; |
| 479 | } else { |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 480 | size_y = size; |
| 481 | } |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 482 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 483 | sg = dma->sglist; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 484 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 485 | /* init DMA for Y channel */ |
| 486 | ret = pxa_init_dma_channel(pcdev, buf, dma, 0, CIBR0, size_y, |
| 487 | &sg, &next_ofs); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 488 | if (ret) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 489 | dev_err(dev, "DMA initialization for Y/RGB failed\n"); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 490 | goto fail; |
| 491 | } |
| 492 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 493 | /* init DMA for U channel */ |
| 494 | if (size_u) |
| 495 | ret = pxa_init_dma_channel(pcdev, buf, dma, 1, CIBR1, |
| 496 | size_u, &sg, &next_ofs); |
| 497 | if (ret) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 498 | dev_err(dev, "DMA initialization for U failed\n"); |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 499 | goto fail_u; |
| 500 | } |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 501 | |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 502 | /* init DMA for V channel */ |
| 503 | if (size_v) |
| 504 | ret = pxa_init_dma_channel(pcdev, buf, dma, 2, CIBR2, |
| 505 | size_v, &sg, &next_ofs); |
| 506 | if (ret) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 507 | dev_err(dev, "DMA initialization for V failed\n"); |
Robert Jarzmik | 37f5aef | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 508 | goto fail_v; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 509 | } |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 510 | |
| 511 | vb->state = VIDEOBUF_PREPARED; |
| 512 | } |
| 513 | |
| 514 | buf->inwork = 0; |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 515 | pxa_videobuf_set_actdma(pcdev, buf); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 516 | |
| 517 | return 0; |
| 518 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 519 | fail_v: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 520 | dma_free_coherent(dev, buf->dmas[1].sg_size, |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 521 | buf->dmas[1].sg_cpu, buf->dmas[1].sg_dma); |
| 522 | fail_u: |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 523 | dma_free_coherent(dev, buf->dmas[0].sg_size, |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 524 | buf->dmas[0].sg_cpu, buf->dmas[0].sg_dma); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 525 | fail: |
| 526 | free_buffer(vq, buf); |
| 527 | out: |
| 528 | buf->inwork = 0; |
| 529 | return ret; |
| 530 | } |
| 531 | |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 532 | /** |
| 533 | * pxa_dma_start_channels - start DMA channel for active buffer |
| 534 | * @pcdev: pxa camera device |
| 535 | * |
| 536 | * Initialize DMA channels to the beginning of the active video buffer, and |
| 537 | * start these channels. |
| 538 | */ |
| 539 | static void pxa_dma_start_channels(struct pxa_camera_dev *pcdev) |
| 540 | { |
| 541 | int i; |
| 542 | struct pxa_buffer *active; |
| 543 | |
| 544 | active = pcdev->active; |
| 545 | |
| 546 | for (i = 0; i < pcdev->channels; i++) { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 547 | dev_dbg(pcdev->soc_host.v4l2_dev.dev, |
| 548 | "%s (channel=%d) ddadr=%08x\n", __func__, |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 549 | i, active->dmas[i].sg_dma); |
| 550 | DDADR(pcdev->dma_chans[i]) = active->dmas[i].sg_dma; |
| 551 | DCSR(pcdev->dma_chans[i]) = DCSR_RUN; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | static void pxa_dma_stop_channels(struct pxa_camera_dev *pcdev) |
| 556 | { |
| 557 | int i; |
| 558 | |
| 559 | for (i = 0; i < pcdev->channels; i++) { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 560 | dev_dbg(pcdev->soc_host.v4l2_dev.dev, |
| 561 | "%s (channel=%d)\n", __func__, i); |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 562 | DCSR(pcdev->dma_chans[i]) = 0; |
| 563 | } |
| 564 | } |
| 565 | |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 566 | static void pxa_dma_add_tail_buf(struct pxa_camera_dev *pcdev, |
| 567 | struct pxa_buffer *buf) |
| 568 | { |
| 569 | int i; |
| 570 | struct pxa_dma_desc *buf_last_desc; |
| 571 | |
| 572 | for (i = 0; i < pcdev->channels; i++) { |
| 573 | buf_last_desc = buf->dmas[i].sg_cpu + buf->dmas[i].sglen; |
| 574 | buf_last_desc->ddadr = DDADR_STOP; |
| 575 | |
Guennadi Liakhovetski | ae7410e | 2009-03-31 03:44:22 -0300 | [diff] [blame] | 576 | if (pcdev->sg_tail[i]) |
| 577 | /* Link the new buffer to the old tail */ |
| 578 | pcdev->sg_tail[i]->ddadr = buf->dmas[i].sg_dma; |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 579 | |
Guennadi Liakhovetski | ae7410e | 2009-03-31 03:44:22 -0300 | [diff] [blame] | 580 | /* Update the channel tail */ |
| 581 | pcdev->sg_tail[i] = buf_last_desc; |
| 582 | } |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /** |
| 586 | * pxa_camera_start_capture - start video capturing |
| 587 | * @pcdev: camera device |
| 588 | * |
| 589 | * Launch capturing. DMA channels should not be active yet. They should get |
| 590 | * activated at the end of frame interrupt, to capture only whole frames, and |
| 591 | * never begin the capture of a partial frame. |
| 592 | */ |
| 593 | static void pxa_camera_start_capture(struct pxa_camera_dev *pcdev) |
| 594 | { |
| 595 | unsigned long cicr0, cifr; |
| 596 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 597 | dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s\n", __func__); |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 598 | /* Reset the FIFOs */ |
| 599 | cifr = __raw_readl(pcdev->base + CIFR) | CIFR_RESET_F; |
| 600 | __raw_writel(cifr, pcdev->base + CIFR); |
| 601 | /* Enable End-Of-Frame Interrupt */ |
| 602 | cicr0 = __raw_readl(pcdev->base + CICR0) | CICR0_ENB; |
| 603 | cicr0 &= ~CICR0_EOFM; |
| 604 | __raw_writel(cicr0, pcdev->base + CICR0); |
| 605 | } |
| 606 | |
| 607 | static void pxa_camera_stop_capture(struct pxa_camera_dev *pcdev) |
| 608 | { |
| 609 | unsigned long cicr0; |
| 610 | |
| 611 | pxa_dma_stop_channels(pcdev); |
| 612 | |
| 613 | cicr0 = __raw_readl(pcdev->base + CICR0) & ~CICR0_ENB; |
| 614 | __raw_writel(cicr0, pcdev->base + CICR0); |
| 615 | |
Robert Jarzmik | 8c62e22 | 2009-03-31 03:44:22 -0300 | [diff] [blame] | 616 | pcdev->active = NULL; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 617 | dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s\n", __func__); |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 618 | } |
| 619 | |
Guennadi Liakhovetski | 2dd54a5 | 2009-08-05 20:06:31 -0300 | [diff] [blame] | 620 | /* Called under spinlock_irqsave(&pcdev->lock, ...) */ |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 621 | static void pxa_videobuf_queue(struct videobuf_queue *vq, |
| 622 | struct videobuf_buffer *vb) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 623 | { |
| 624 | struct soc_camera_device *icd = vq->priv_data; |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 625 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 626 | struct pxa_camera_dev *pcdev = ici->priv; |
| 627 | struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 628 | |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 629 | dev_dbg(icd->dev.parent, "%s (vb=0x%p) 0x%08lx %d active=%p\n", |
| 630 | __func__, vb, vb->baddr, vb->bsize, pcdev->active); |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 631 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 632 | list_add_tail(&vb->queue, &pcdev->capture); |
| 633 | |
| 634 | vb->state = VIDEOBUF_ACTIVE; |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 635 | pxa_dma_add_tail_buf(pcdev, buf); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 636 | |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 637 | if (!pcdev->active) |
| 638 | pxa_camera_start_capture(pcdev); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | static void pxa_videobuf_release(struct videobuf_queue *vq, |
| 642 | struct videobuf_buffer *vb) |
| 643 | { |
| 644 | struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); |
| 645 | #ifdef DEBUG |
| 646 | struct soc_camera_device *icd = vq->priv_data; |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 647 | struct device *dev = icd->dev.parent; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 648 | |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 649 | dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 650 | vb, vb->baddr, vb->bsize); |
| 651 | |
| 652 | switch (vb->state) { |
| 653 | case VIDEOBUF_ACTIVE: |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 654 | dev_dbg(dev, "%s (active)\n", __func__); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 655 | break; |
| 656 | case VIDEOBUF_QUEUED: |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 657 | dev_dbg(dev, "%s (queued)\n", __func__); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 658 | break; |
| 659 | case VIDEOBUF_PREPARED: |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 660 | dev_dbg(dev, "%s (prepared)\n", __func__); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 661 | break; |
| 662 | default: |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 663 | dev_dbg(dev, "%s (unknown)\n", __func__); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 664 | break; |
| 665 | } |
| 666 | #endif |
| 667 | |
| 668 | free_buffer(vq, buf); |
| 669 | } |
| 670 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 671 | static void pxa_camera_wakeup(struct pxa_camera_dev *pcdev, |
| 672 | struct videobuf_buffer *vb, |
| 673 | struct pxa_buffer *buf) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 674 | { |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 675 | int i; |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 676 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 677 | /* _init is used to debug races, see comment in pxa_camera_reqbufs() */ |
| 678 | list_del_init(&vb->queue); |
| 679 | vb->state = VIDEOBUF_DONE; |
| 680 | do_gettimeofday(&vb->ts); |
| 681 | vb->field_count++; |
| 682 | wake_up(&vb->done); |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 683 | dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s dequeud buffer (vb=0x%p)\n", |
| 684 | __func__, vb); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 685 | |
| 686 | if (list_empty(&pcdev->capture)) { |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 687 | pxa_camera_stop_capture(pcdev); |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 688 | for (i = 0; i < pcdev->channels; i++) |
| 689 | pcdev->sg_tail[i] = NULL; |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 690 | return; |
| 691 | } |
| 692 | |
| 693 | pcdev->active = list_entry(pcdev->capture.next, |
| 694 | struct pxa_buffer, vb.queue); |
| 695 | } |
| 696 | |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 697 | /** |
| 698 | * pxa_camera_check_link_miss - check missed DMA linking |
| 699 | * @pcdev: camera device |
| 700 | * |
| 701 | * The DMA chaining is done with DMA running. This means a tiny temporal window |
| 702 | * remains, where a buffer is queued on the chain, while the chain is already |
| 703 | * stopped. This means the tailed buffer would never be transfered by DMA. |
| 704 | * This function restarts the capture for this corner case, where : |
| 705 | * - DADR() == DADDR_STOP |
| 706 | * - a videobuffer is queued on the pcdev->capture list |
| 707 | * |
| 708 | * Please check the "DMA hot chaining timeslice issue" in |
| 709 | * Documentation/video4linux/pxa_camera.txt |
| 710 | * |
| 711 | * Context: should only be called within the dma irq handler |
| 712 | */ |
| 713 | static void pxa_camera_check_link_miss(struct pxa_camera_dev *pcdev) |
| 714 | { |
| 715 | int i, is_dma_stopped = 1; |
| 716 | |
| 717 | for (i = 0; i < pcdev->channels; i++) |
| 718 | if (DDADR(pcdev->dma_chans[i]) != DDADR_STOP) |
| 719 | is_dma_stopped = 0; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 720 | dev_dbg(pcdev->soc_host.v4l2_dev.dev, |
| 721 | "%s : top queued buffer=%p, dma_stopped=%d\n", |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 722 | __func__, pcdev->active, is_dma_stopped); |
| 723 | if (pcdev->active && is_dma_stopped) |
| 724 | pxa_camera_start_capture(pcdev); |
| 725 | } |
| 726 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 727 | static void pxa_camera_dma_irq(int channel, struct pxa_camera_dev *pcdev, |
| 728 | enum pxa_camera_active_dma act_dma) |
| 729 | { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 730 | struct device *dev = pcdev->soc_host.v4l2_dev.dev; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 731 | struct pxa_buffer *buf; |
| 732 | unsigned long flags; |
Guennadi Liakhovetski | e7c5068 | 2008-04-22 10:37:49 -0300 | [diff] [blame] | 733 | u32 status, camera_status, overrun; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 734 | struct videobuf_buffer *vb; |
| 735 | |
| 736 | spin_lock_irqsave(&pcdev->lock, flags); |
| 737 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 738 | status = DCSR(channel); |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 739 | DCSR(channel) = status; |
| 740 | |
| 741 | camera_status = __raw_readl(pcdev->base + CISR); |
| 742 | overrun = CISR_IFO_0; |
| 743 | if (pcdev->channels == 3) |
| 744 | overrun |= CISR_IFO_1 | CISR_IFO_2; |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 745 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 746 | if (status & DCSR_BUSERR) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 747 | dev_err(dev, "DMA Bus Error IRQ!\n"); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 748 | goto out; |
| 749 | } |
| 750 | |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 751 | if (!(status & (DCSR_ENDINTR | DCSR_STARTINTR))) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 752 | dev_err(dev, "Unknown DMA IRQ source, status: 0x%08x\n", |
| 753 | status); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 754 | goto out; |
| 755 | } |
| 756 | |
Robert Jarzmik | 8c62e22 | 2009-03-31 03:44:22 -0300 | [diff] [blame] | 757 | /* |
| 758 | * pcdev->active should not be NULL in DMA irq handler. |
| 759 | * |
| 760 | * But there is one corner case : if capture was stopped due to an |
| 761 | * overrun of channel 1, and at that same channel 2 was completed. |
| 762 | * |
| 763 | * When handling the overrun in DMA irq for channel 1, we'll stop the |
| 764 | * capture and restart it (and thus set pcdev->active to NULL). But the |
| 765 | * DMA irq handler will already be pending for channel 2. So on entering |
| 766 | * the DMA irq handler for channel 2 there will be no active buffer, yet |
| 767 | * that is normal. |
| 768 | */ |
| 769 | if (!pcdev->active) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 770 | goto out; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 771 | |
| 772 | vb = &pcdev->active->vb; |
| 773 | buf = container_of(vb, struct pxa_buffer, vb); |
| 774 | WARN_ON(buf->inwork || list_empty(&vb->queue)); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 775 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 776 | dev_dbg(dev, "%s channel=%d %s%s(vb=0x%p) dma.desc=%x\n", |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 777 | __func__, channel, status & DCSR_STARTINTR ? "SOF " : "", |
| 778 | status & DCSR_ENDINTR ? "EOF " : "", vb, DDADR(channel)); |
| 779 | |
| 780 | if (status & DCSR_ENDINTR) { |
Robert Jarzmik | 8c62e22 | 2009-03-31 03:44:22 -0300 | [diff] [blame] | 781 | /* |
| 782 | * It's normal if the last frame creates an overrun, as there |
| 783 | * are no more DMA descriptors to fetch from QCI fifos |
| 784 | */ |
| 785 | if (camera_status & overrun && |
| 786 | !list_is_last(pcdev->capture.next, &pcdev->capture)) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 787 | dev_dbg(dev, "FIFO overrun! CISR: %x\n", |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 788 | camera_status); |
| 789 | pxa_camera_stop_capture(pcdev); |
| 790 | pxa_camera_start_capture(pcdev); |
| 791 | goto out; |
| 792 | } |
| 793 | buf->active_dma &= ~act_dma; |
| 794 | if (!buf->active_dma) { |
| 795 | pxa_camera_wakeup(pcdev, vb, buf); |
| 796 | pxa_camera_check_link_miss(pcdev); |
| 797 | } |
| 798 | } |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 799 | |
| 800 | out: |
| 801 | spin_unlock_irqrestore(&pcdev->lock, flags); |
| 802 | } |
| 803 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 804 | static void pxa_camera_dma_irq_y(int channel, void *data) |
| 805 | { |
| 806 | struct pxa_camera_dev *pcdev = data; |
| 807 | pxa_camera_dma_irq(channel, pcdev, DMA_Y); |
| 808 | } |
| 809 | |
| 810 | static void pxa_camera_dma_irq_u(int channel, void *data) |
| 811 | { |
| 812 | struct pxa_camera_dev *pcdev = data; |
| 813 | pxa_camera_dma_irq(channel, pcdev, DMA_U); |
| 814 | } |
| 815 | |
| 816 | static void pxa_camera_dma_irq_v(int channel, void *data) |
| 817 | { |
| 818 | struct pxa_camera_dev *pcdev = data; |
| 819 | pxa_camera_dma_irq(channel, pcdev, DMA_V); |
| 820 | } |
| 821 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 822 | static struct videobuf_queue_ops pxa_videobuf_ops = { |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 823 | .buf_setup = pxa_videobuf_setup, |
| 824 | .buf_prepare = pxa_videobuf_prepare, |
| 825 | .buf_queue = pxa_videobuf_queue, |
| 826 | .buf_release = pxa_videobuf_release, |
| 827 | }; |
| 828 | |
Magnus Damm | a034d1b | 2008-07-11 20:59:34 -0300 | [diff] [blame] | 829 | static void pxa_camera_init_videobuf(struct videobuf_queue *q, |
Paulius Zaleckas | 092d392 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 830 | struct soc_camera_device *icd) |
| 831 | { |
Magnus Damm | a034d1b | 2008-07-11 20:59:34 -0300 | [diff] [blame] | 832 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 833 | struct pxa_camera_dev *pcdev = ici->priv; |
| 834 | |
Paulius Zaleckas | 092d392 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 835 | /* We must pass NULL as dev pointer, then all pci_* dma operations |
| 836 | * transform to normal dma_* ones. */ |
Magnus Damm | a034d1b | 2008-07-11 20:59:34 -0300 | [diff] [blame] | 837 | videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, &pcdev->lock, |
Paulius Zaleckas | 092d392 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 838 | V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, |
| 839 | sizeof(struct pxa_buffer), icd); |
| 840 | } |
| 841 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 842 | static u32 mclk_get_divisor(struct platform_device *pdev, |
| 843 | struct pxa_camera_dev *pcdev) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 844 | { |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 845 | unsigned long mclk = pcdev->mclk; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 846 | struct device *dev = &pdev->dev; |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 847 | u32 div; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 848 | unsigned long lcdclk; |
| 849 | |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 850 | lcdclk = clk_get_rate(pcdev->clk); |
| 851 | pcdev->ciclk = lcdclk; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 852 | |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 853 | /* mclk <= ciclk / 4 (27.4.2) */ |
| 854 | if (mclk > lcdclk / 4) { |
| 855 | mclk = lcdclk / 4; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 856 | dev_warn(dev, "Limiting master clock to %lu\n", mclk); |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 857 | } |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 858 | |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 859 | /* We verify mclk != 0, so if anyone breaks it, here comes their Oops */ |
| 860 | div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1; |
| 861 | |
| 862 | /* If we're not supplying MCLK, leave it at 0 */ |
| 863 | if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) |
| 864 | pcdev->mclk = lcdclk / (2 * (div + 1)); |
| 865 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 866 | dev_dbg(dev, "LCD clock %luHz, target freq %luHz, divisor %u\n", |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 867 | lcdclk, mclk, div); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 868 | |
| 869 | return div; |
| 870 | } |
| 871 | |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 872 | static void recalculate_fifo_timeout(struct pxa_camera_dev *pcdev, |
| 873 | unsigned long pclk) |
| 874 | { |
| 875 | /* We want a timeout > 1 pixel time, not ">=" */ |
| 876 | u32 ciclk_per_pixel = pcdev->ciclk / pclk + 1; |
| 877 | |
| 878 | __raw_writel(ciclk_per_pixel, pcdev->base + CITOR); |
| 879 | } |
| 880 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 881 | static void pxa_camera_activate(struct pxa_camera_dev *pcdev) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 882 | { |
| 883 | struct pxacamera_platform_data *pdata = pcdev->pdata; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 884 | struct device *dev = pcdev->soc_host.v4l2_dev.dev; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 885 | u32 cicr4 = 0; |
| 886 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 887 | dev_dbg(dev, "Registered platform device at %p data %p\n", |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 888 | pcdev, pdata); |
| 889 | |
| 890 | if (pdata && pdata->init) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 891 | dev_dbg(dev, "%s: Init gpios\n", __func__); |
| 892 | pdata->init(dev); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 893 | } |
| 894 | |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 895 | /* disable all interrupts */ |
| 896 | __raw_writel(0x3ff, pcdev->base + CICR0); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 897 | |
| 898 | if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) |
| 899 | cicr4 |= CICR4_PCLK_EN; |
| 900 | if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) |
| 901 | cicr4 |= CICR4_MCLK_EN; |
| 902 | if (pcdev->platform_flags & PXA_CAMERA_PCP) |
| 903 | cicr4 |= CICR4_PCP; |
| 904 | if (pcdev->platform_flags & PXA_CAMERA_HSP) |
| 905 | cicr4 |= CICR4_HSP; |
| 906 | if (pcdev->platform_flags & PXA_CAMERA_VSP) |
| 907 | cicr4 |= CICR4_VSP; |
| 908 | |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 909 | __raw_writel(pcdev->mclk_divisor | cicr4, pcdev->base + CICR4); |
| 910 | |
| 911 | if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) |
| 912 | /* Initialise the timeout under the assumption pclk = mclk */ |
| 913 | recalculate_fifo_timeout(pcdev, pcdev->mclk); |
| 914 | else |
| 915 | /* "Safe default" - 13MHz */ |
| 916 | recalculate_fifo_timeout(pcdev, 13000000); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 917 | |
| 918 | clk_enable(pcdev->clk); |
| 919 | } |
| 920 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 921 | static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 922 | { |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 923 | clk_disable(pcdev->clk); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | static irqreturn_t pxa_camera_irq(int irq, void *data) |
| 927 | { |
| 928 | struct pxa_camera_dev *pcdev = data; |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 929 | unsigned long status, cicr0; |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 930 | struct pxa_buffer *buf; |
| 931 | struct videobuf_buffer *vb; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 932 | |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 933 | status = __raw_readl(pcdev->base + CISR); |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 934 | dev_dbg(pcdev->soc_host.v4l2_dev.dev, |
| 935 | "Camera interrupt status 0x%lx\n", status); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 936 | |
Guennadi Liakhovetski | e7c5068 | 2008-04-22 10:37:49 -0300 | [diff] [blame] | 937 | if (!status) |
| 938 | return IRQ_NONE; |
| 939 | |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 940 | __raw_writel(status, pcdev->base + CISR); |
Guennadi Liakhovetski | e7c5068 | 2008-04-22 10:37:49 -0300 | [diff] [blame] | 941 | |
| 942 | if (status & CISR_EOF) { |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 943 | pcdev->active = list_first_entry(&pcdev->capture, |
| 944 | struct pxa_buffer, vb.queue); |
| 945 | vb = &pcdev->active->vb; |
| 946 | buf = container_of(vb, struct pxa_buffer, vb); |
| 947 | pxa_videobuf_set_actdma(pcdev, buf); |
| 948 | |
| 949 | pxa_dma_start_channels(pcdev); |
| 950 | |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 951 | cicr0 = __raw_readl(pcdev->base + CICR0) | CICR0_EOFM; |
| 952 | __raw_writel(cicr0, pcdev->base + CICR0); |
Guennadi Liakhovetski | e7c5068 | 2008-04-22 10:37:49 -0300 | [diff] [blame] | 953 | } |
| 954 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 955 | return IRQ_HANDLED; |
| 956 | } |
| 957 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 958 | /* |
| 959 | * The following two functions absolutely depend on the fact, that |
| 960 | * there can be only one camera on PXA quick capture interface |
| 961 | * Called with .video_lock held |
| 962 | */ |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 963 | static int pxa_camera_add_device(struct soc_camera_device *icd) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 964 | { |
| 965 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 966 | struct pxa_camera_dev *pcdev = ici->priv; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 967 | |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 968 | if (pcdev->icd) |
| 969 | return -EBUSY; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 970 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 971 | pxa_camera_activate(pcdev); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 972 | |
| 973 | pcdev->icd = icd; |
| 974 | |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 975 | dev_info(icd->dev.parent, "PXA Camera driver attached to camera %d\n", |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 976 | icd->devnum); |
| 977 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 978 | return 0; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 979 | } |
| 980 | |
Guennadi Liakhovetski | 1c3bb74 | 2008-12-18 12:28:54 -0300 | [diff] [blame] | 981 | /* Called with .video_lock held */ |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 982 | static void pxa_camera_remove_device(struct soc_camera_device *icd) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 983 | { |
| 984 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 985 | struct pxa_camera_dev *pcdev = ici->priv; |
| 986 | |
| 987 | BUG_ON(icd != pcdev->icd); |
| 988 | |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 989 | dev_info(icd->dev.parent, "PXA Camera driver detached from camera %d\n", |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 990 | icd->devnum); |
| 991 | |
| 992 | /* disable capture, disable interrupts */ |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 993 | __raw_writel(0x3ff, pcdev->base + CICR0); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 994 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 995 | /* Stop DMA engine */ |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 996 | DCSR(pcdev->dma_chans[0]) = 0; |
| 997 | DCSR(pcdev->dma_chans[1]) = 0; |
| 998 | DCSR(pcdev->dma_chans[2]) = 0; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 999 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 1000 | pxa_camera_deactivate(pcdev); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1001 | |
| 1002 | pcdev->icd = NULL; |
| 1003 | } |
| 1004 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1005 | static int test_platform_param(struct pxa_camera_dev *pcdev, |
| 1006 | unsigned char buswidth, unsigned long *flags) |
| 1007 | { |
| 1008 | /* |
| 1009 | * Platform specified synchronization and pixel clock polarities are |
| 1010 | * only a recommendation and are only used during probing. The PXA270 |
| 1011 | * quick capture interface supports both. |
| 1012 | */ |
| 1013 | *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ? |
| 1014 | SOCAM_MASTER : SOCAM_SLAVE) | |
| 1015 | SOCAM_HSYNC_ACTIVE_HIGH | |
| 1016 | SOCAM_HSYNC_ACTIVE_LOW | |
| 1017 | SOCAM_VSYNC_ACTIVE_HIGH | |
| 1018 | SOCAM_VSYNC_ACTIVE_LOW | |
Guennadi Liakhovetski | 2d9329f | 2009-02-23 12:12:58 -0300 | [diff] [blame] | 1019 | SOCAM_DATA_ACTIVE_HIGH | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1020 | SOCAM_PCLK_SAMPLE_RISING | |
| 1021 | SOCAM_PCLK_SAMPLE_FALLING; |
| 1022 | |
| 1023 | /* If requested data width is supported by the platform, use it */ |
| 1024 | switch (buswidth) { |
| 1025 | case 10: |
| 1026 | if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10)) |
| 1027 | return -EINVAL; |
| 1028 | *flags |= SOCAM_DATAWIDTH_10; |
| 1029 | break; |
| 1030 | case 9: |
| 1031 | if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9)) |
| 1032 | return -EINVAL; |
| 1033 | *flags |= SOCAM_DATAWIDTH_9; |
| 1034 | break; |
| 1035 | case 8: |
| 1036 | if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8)) |
| 1037 | return -EINVAL; |
| 1038 | *flags |= SOCAM_DATAWIDTH_8; |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1039 | break; |
| 1040 | default: |
| 1041 | return -EINVAL; |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1047 | static void pxa_camera_setup_cicr(struct soc_camera_device *icd, |
| 1048 | unsigned long flags, __u32 pixfmt) |
| 1049 | { |
| 1050 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 1051 | struct pxa_camera_dev *pcdev = ici->priv; |
| 1052 | unsigned long dw, bpp; |
| 1053 | u32 cicr0, cicr1, cicr2, cicr3, cicr4 = 0; |
| 1054 | |
| 1055 | /* Datawidth is now guaranteed to be equal to one of the three values. |
| 1056 | * We fix bit-per-pixel equal to data-width... */ |
| 1057 | switch (flags & SOCAM_DATAWIDTH_MASK) { |
| 1058 | case SOCAM_DATAWIDTH_10: |
| 1059 | dw = 4; |
| 1060 | bpp = 0x40; |
| 1061 | break; |
| 1062 | case SOCAM_DATAWIDTH_9: |
| 1063 | dw = 3; |
| 1064 | bpp = 0x20; |
| 1065 | break; |
| 1066 | default: |
| 1067 | /* Actually it can only be 8 now, |
| 1068 | * default is just to silence compiler warnings */ |
| 1069 | case SOCAM_DATAWIDTH_8: |
| 1070 | dw = 2; |
| 1071 | bpp = 0; |
| 1072 | } |
| 1073 | |
| 1074 | if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) |
| 1075 | cicr4 |= CICR4_PCLK_EN; |
| 1076 | if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) |
| 1077 | cicr4 |= CICR4_MCLK_EN; |
| 1078 | if (flags & SOCAM_PCLK_SAMPLE_FALLING) |
| 1079 | cicr4 |= CICR4_PCP; |
| 1080 | if (flags & SOCAM_HSYNC_ACTIVE_LOW) |
| 1081 | cicr4 |= CICR4_HSP; |
| 1082 | if (flags & SOCAM_VSYNC_ACTIVE_LOW) |
| 1083 | cicr4 |= CICR4_VSP; |
| 1084 | |
| 1085 | cicr0 = __raw_readl(pcdev->base + CICR0); |
| 1086 | if (cicr0 & CICR0_ENB) |
| 1087 | __raw_writel(cicr0 & ~CICR0_ENB, pcdev->base + CICR0); |
| 1088 | |
| 1089 | cicr1 = CICR1_PPL_VAL(icd->user_width - 1) | bpp | dw; |
| 1090 | |
| 1091 | switch (pixfmt) { |
| 1092 | case V4L2_PIX_FMT_YUV422P: |
| 1093 | pcdev->channels = 3; |
| 1094 | cicr1 |= CICR1_YCBCR_F; |
| 1095 | /* |
| 1096 | * Normally, pxa bus wants as input UYVY format. We allow all |
| 1097 | * reorderings of the YUV422 format, as no processing is done, |
| 1098 | * and the YUV stream is just passed through without any |
| 1099 | * transformation. Note that UYVY is the only format that |
| 1100 | * should be used if pxa framebuffer Overlay2 is used. |
| 1101 | */ |
| 1102 | case V4L2_PIX_FMT_UYVY: |
| 1103 | case V4L2_PIX_FMT_VYUY: |
| 1104 | case V4L2_PIX_FMT_YUYV: |
| 1105 | case V4L2_PIX_FMT_YVYU: |
| 1106 | cicr1 |= CICR1_COLOR_SP_VAL(2); |
| 1107 | break; |
| 1108 | case V4L2_PIX_FMT_RGB555: |
| 1109 | cicr1 |= CICR1_RGB_BPP_VAL(1) | CICR1_RGBT_CONV_VAL(2) | |
| 1110 | CICR1_TBIT | CICR1_COLOR_SP_VAL(1); |
| 1111 | break; |
| 1112 | case V4L2_PIX_FMT_RGB565: |
| 1113 | cicr1 |= CICR1_COLOR_SP_VAL(1) | CICR1_RGB_BPP_VAL(2); |
| 1114 | break; |
| 1115 | } |
| 1116 | |
| 1117 | cicr2 = 0; |
| 1118 | cicr3 = CICR3_LPF_VAL(icd->user_height - 1) | |
| 1119 | CICR3_BFW_VAL(min((unsigned short)255, icd->y_skip_top)); |
| 1120 | cicr4 |= pcdev->mclk_divisor; |
| 1121 | |
| 1122 | __raw_writel(cicr1, pcdev->base + CICR1); |
| 1123 | __raw_writel(cicr2, pcdev->base + CICR2); |
| 1124 | __raw_writel(cicr3, pcdev->base + CICR3); |
| 1125 | __raw_writel(cicr4, pcdev->base + CICR4); |
| 1126 | |
| 1127 | /* CIF interrupts are not used, only DMA */ |
| 1128 | cicr0 = (cicr0 & CICR0_ENB) | (pcdev->platform_flags & PXA_CAMERA_MASTER ? |
| 1129 | CICR0_SIM_MP : (CICR0_SL_CAP_EN | CICR0_SIM_SP)); |
| 1130 | cicr0 |= CICR0_DMAEN | CICR0_IRQ_MASK; |
| 1131 | __raw_writel(cicr0, pcdev->base + CICR0); |
| 1132 | } |
| 1133 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1134 | static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1135 | { |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 1136 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1137 | struct pxa_camera_dev *pcdev = ici->priv; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1138 | unsigned long bus_flags, camera_flags, common_flags; |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1139 | int ret = test_platform_param(pcdev, icd->buswidth, &bus_flags); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1140 | struct pxa_cam *cam = icd->host_priv; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1141 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1142 | if (ret < 0) |
| 1143 | return ret; |
| 1144 | |
| 1145 | camera_flags = icd->ops->query_bus_param(icd); |
| 1146 | |
| 1147 | common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags); |
| 1148 | if (!common_flags) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1149 | return -EINVAL; |
| 1150 | |
Guennadi Liakhovetski | e7c5068 | 2008-04-22 10:37:49 -0300 | [diff] [blame] | 1151 | pcdev->channels = 1; |
| 1152 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1153 | /* Make choises, based on platform preferences */ |
| 1154 | if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) && |
| 1155 | (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) { |
| 1156 | if (pcdev->platform_flags & PXA_CAMERA_HSP) |
| 1157 | common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH; |
| 1158 | else |
| 1159 | common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW; |
| 1160 | } |
| 1161 | |
| 1162 | if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) && |
| 1163 | (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) { |
| 1164 | if (pcdev->platform_flags & PXA_CAMERA_VSP) |
| 1165 | common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH; |
| 1166 | else |
| 1167 | common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW; |
| 1168 | } |
| 1169 | |
| 1170 | if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && |
| 1171 | (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { |
| 1172 | if (pcdev->platform_flags & PXA_CAMERA_PCP) |
| 1173 | common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; |
| 1174 | else |
| 1175 | common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; |
| 1176 | } |
| 1177 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1178 | cam->flags = common_flags; |
| 1179 | |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1180 | ret = icd->ops->set_bus_param(icd, common_flags); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1181 | if (ret < 0) |
| 1182 | return ret; |
| 1183 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1184 | pxa_camera_setup_cicr(icd, common_flags, pixfmt); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1185 | |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1189 | static int pxa_camera_try_bus_param(struct soc_camera_device *icd, |
| 1190 | unsigned char buswidth) |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1191 | { |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1192 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1193 | struct pxa_camera_dev *pcdev = ici->priv; |
| 1194 | unsigned long bus_flags, camera_flags; |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1195 | int ret = test_platform_param(pcdev, buswidth, &bus_flags); |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1196 | |
| 1197 | if (ret < 0) |
| 1198 | return ret; |
| 1199 | |
| 1200 | camera_flags = icd->ops->query_bus_param(icd); |
| 1201 | |
| 1202 | return soc_camera_bus_param_compatible(camera_flags, bus_flags) ? 0 : -EINVAL; |
| 1203 | } |
| 1204 | |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1205 | static const struct soc_camera_data_format pxa_camera_formats[] = { |
| 1206 | { |
| 1207 | .name = "Planar YUV422 16 bit", |
| 1208 | .depth = 16, |
| 1209 | .fourcc = V4L2_PIX_FMT_YUV422P, |
| 1210 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 1211 | }, |
| 1212 | }; |
| 1213 | |
| 1214 | static bool buswidth_supported(struct soc_camera_device *icd, int depth) |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1215 | { |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1216 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 1217 | struct pxa_camera_dev *pcdev = ici->priv; |
| 1218 | |
| 1219 | switch (depth) { |
| 1220 | case 8: |
| 1221 | return !!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8); |
| 1222 | case 9: |
| 1223 | return !!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9); |
| 1224 | case 10: |
| 1225 | return !!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10); |
| 1226 | } |
| 1227 | return false; |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1228 | } |
| 1229 | |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1230 | static int required_buswidth(const struct soc_camera_data_format *fmt) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1231 | { |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1232 | switch (fmt->fourcc) { |
| 1233 | case V4L2_PIX_FMT_UYVY: |
| 1234 | case V4L2_PIX_FMT_VYUY: |
| 1235 | case V4L2_PIX_FMT_YUYV: |
| 1236 | case V4L2_PIX_FMT_YVYU: |
| 1237 | case V4L2_PIX_FMT_RGB565: |
| 1238 | case V4L2_PIX_FMT_RGB555: |
| 1239 | return 8; |
| 1240 | default: |
| 1241 | return fmt->depth; |
| 1242 | } |
| 1243 | } |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1244 | |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1245 | static int pxa_camera_get_formats(struct soc_camera_device *icd, int idx, |
| 1246 | struct soc_camera_format_xlate *xlate) |
| 1247 | { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1248 | struct device *dev = icd->dev.parent; |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1249 | int formats = 0, buswidth, ret; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1250 | struct pxa_cam *cam; |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1251 | |
| 1252 | buswidth = required_buswidth(icd->formats + idx); |
| 1253 | |
| 1254 | if (!buswidth_supported(icd, buswidth)) |
| 1255 | return 0; |
| 1256 | |
| 1257 | ret = pxa_camera_try_bus_param(icd, buswidth); |
| 1258 | if (ret < 0) |
| 1259 | return 0; |
| 1260 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1261 | if (!icd->host_priv) { |
| 1262 | cam = kzalloc(sizeof(*cam), GFP_KERNEL); |
| 1263 | if (!cam) |
| 1264 | return -ENOMEM; |
| 1265 | |
| 1266 | icd->host_priv = cam; |
| 1267 | } else { |
| 1268 | cam = icd->host_priv; |
| 1269 | } |
| 1270 | |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1271 | switch (icd->formats[idx].fourcc) { |
| 1272 | case V4L2_PIX_FMT_UYVY: |
| 1273 | formats++; |
| 1274 | if (xlate) { |
| 1275 | xlate->host_fmt = &pxa_camera_formats[0]; |
| 1276 | xlate->cam_fmt = icd->formats + idx; |
| 1277 | xlate->buswidth = buswidth; |
| 1278 | xlate++; |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1279 | dev_dbg(dev, "Providing format %s using %s\n", |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1280 | pxa_camera_formats[0].name, |
| 1281 | icd->formats[idx].name); |
| 1282 | } |
| 1283 | case V4L2_PIX_FMT_VYUY: |
| 1284 | case V4L2_PIX_FMT_YUYV: |
| 1285 | case V4L2_PIX_FMT_YVYU: |
| 1286 | case V4L2_PIX_FMT_RGB565: |
| 1287 | case V4L2_PIX_FMT_RGB555: |
| 1288 | formats++; |
| 1289 | if (xlate) { |
| 1290 | xlate->host_fmt = icd->formats + idx; |
| 1291 | xlate->cam_fmt = icd->formats + idx; |
| 1292 | xlate->buswidth = buswidth; |
| 1293 | xlate++; |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1294 | dev_dbg(dev, "Providing format %s packed\n", |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1295 | icd->formats[idx].name); |
| 1296 | } |
| 1297 | break; |
| 1298 | default: |
| 1299 | /* Generic pass-through */ |
| 1300 | formats++; |
| 1301 | if (xlate) { |
| 1302 | xlate->host_fmt = icd->formats + idx; |
| 1303 | xlate->cam_fmt = icd->formats + idx; |
| 1304 | xlate->buswidth = icd->formats[idx].depth; |
| 1305 | xlate++; |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1306 | dev_dbg(dev, |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1307 | "Providing format %s in pass-through mode\n", |
| 1308 | icd->formats[idx].name); |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | return formats; |
| 1313 | } |
| 1314 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1315 | static void pxa_camera_put_formats(struct soc_camera_device *icd) |
| 1316 | { |
| 1317 | kfree(icd->host_priv); |
| 1318 | icd->host_priv = NULL; |
| 1319 | } |
| 1320 | |
| 1321 | static int pxa_camera_check_frame(struct v4l2_pix_format *pix) |
| 1322 | { |
| 1323 | /* limit to pxa hardware capabilities */ |
| 1324 | return pix->height < 32 || pix->height > 2048 || pix->width < 48 || |
| 1325 | pix->width > 2048 || (pix->width & 0x01); |
| 1326 | } |
| 1327 | |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1328 | static int pxa_camera_set_crop(struct soc_camera_device *icd, |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 1329 | struct v4l2_crop *a) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1330 | { |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 1331 | struct v4l2_rect *rect = &a->c; |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1332 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1333 | struct pxa_camera_dev *pcdev = ici->priv; |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1334 | struct device *dev = icd->dev.parent; |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 1335 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1336 | struct soc_camera_sense sense = { |
| 1337 | .master_clock = pcdev->mclk, |
| 1338 | .pixel_clock_max = pcdev->ciclk / 4, |
| 1339 | }; |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1340 | struct v4l2_format f; |
| 1341 | struct v4l2_pix_format *pix = &f.fmt.pix, pix_tmp; |
| 1342 | struct pxa_cam *cam = icd->host_priv; |
Guennadi Liakhovetski | 0ad675e | 2009-02-23 12:11:25 -0300 | [diff] [blame] | 1343 | int ret; |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 1344 | |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1345 | /* If PCLK is used to latch data from the sensor, check sense */ |
| 1346 | if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) |
| 1347 | icd->sense = &sense; |
| 1348 | |
Guennadi Liakhovetski | 08590b9 | 2009-08-25 11:46:54 -0300 | [diff] [blame] | 1349 | ret = v4l2_subdev_call(sd, video, s_crop, a); |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1350 | |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1351 | icd->sense = NULL; |
| 1352 | |
| 1353 | if (ret < 0) { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1354 | dev_warn(dev, "Failed to crop to %ux%u@%u:%u\n", |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1355 | rect->width, rect->height, rect->left, rect->top); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1356 | return ret; |
| 1357 | } |
| 1358 | |
| 1359 | f.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1360 | |
| 1361 | ret = v4l2_subdev_call(sd, video, g_fmt, &f); |
| 1362 | if (ret < 0) |
| 1363 | return ret; |
| 1364 | |
| 1365 | pix_tmp = *pix; |
| 1366 | if (pxa_camera_check_frame(pix)) { |
| 1367 | /* |
| 1368 | * Camera cropping produced a frame beyond our capabilities. |
| 1369 | * FIXME: just extract a subframe, that we can process. |
| 1370 | */ |
| 1371 | v4l_bound_align_image(&pix->width, 48, 2048, 1, |
| 1372 | &pix->height, 32, 2048, 0, |
| 1373 | icd->current_fmt->fourcc == V4L2_PIX_FMT_YUV422P ? |
| 1374 | 4 : 0); |
| 1375 | ret = v4l2_subdev_call(sd, video, s_fmt, &f); |
| 1376 | if (ret < 0) |
| 1377 | return ret; |
| 1378 | |
| 1379 | if (pxa_camera_check_frame(pix)) { |
| 1380 | dev_warn(icd->dev.parent, |
| 1381 | "Inconsistent state. Use S_FMT to repair\n"); |
| 1382 | return -EINVAL; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1387 | if (sense.pixel_clock > sense.pixel_clock_max) { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1388 | dev_err(dev, |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1389 | "pixel clock %lu set by the camera too high!", |
| 1390 | sense.pixel_clock); |
| 1391 | return -EIO; |
| 1392 | } |
| 1393 | recalculate_fifo_timeout(pcdev, sense.pixel_clock); |
| 1394 | } |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1395 | |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1396 | icd->user_width = pix->width; |
| 1397 | icd->user_height = pix->height; |
| 1398 | |
| 1399 | pxa_camera_setup_cicr(icd, cam->flags, icd->current_fmt->fourcc); |
| 1400 | |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1401 | return ret; |
| 1402 | } |
| 1403 | |
| 1404 | static int pxa_camera_set_fmt(struct soc_camera_device *icd, |
| 1405 | struct v4l2_format *f) |
| 1406 | { |
| 1407 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
| 1408 | struct pxa_camera_dev *pcdev = ici->priv; |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1409 | struct device *dev = icd->dev.parent; |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 1410 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1411 | const struct soc_camera_data_format *cam_fmt = NULL; |
| 1412 | const struct soc_camera_format_xlate *xlate = NULL; |
| 1413 | struct soc_camera_sense sense = { |
| 1414 | .master_clock = pcdev->mclk, |
| 1415 | .pixel_clock_max = pcdev->ciclk / 4, |
| 1416 | }; |
| 1417 | struct v4l2_pix_format *pix = &f->fmt.pix; |
| 1418 | struct v4l2_format cam_f = *f; |
| 1419 | int ret; |
| 1420 | |
| 1421 | xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); |
| 1422 | if (!xlate) { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1423 | dev_warn(dev, "Format %x not found\n", pix->pixelformat); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1424 | return -EINVAL; |
| 1425 | } |
| 1426 | |
| 1427 | cam_fmt = xlate->cam_fmt; |
| 1428 | |
| 1429 | /* If PCLK is used to latch data from the sensor, check sense */ |
| 1430 | if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) |
| 1431 | icd->sense = &sense; |
| 1432 | |
| 1433 | cam_f.fmt.pix.pixelformat = cam_fmt->fourcc; |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 1434 | ret = v4l2_subdev_call(sd, video, s_fmt, f); |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1435 | |
| 1436 | icd->sense = NULL; |
| 1437 | |
| 1438 | if (ret < 0) { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1439 | dev_warn(dev, "Failed to configure for format %x\n", |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1440 | pix->pixelformat); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1441 | } else if (pxa_camera_check_frame(pix)) { |
| 1442 | dev_warn(dev, |
| 1443 | "Camera driver produced an unsupported frame %dx%d\n", |
| 1444 | pix->width, pix->height); |
| 1445 | ret = -EINVAL; |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1446 | } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { |
| 1447 | if (sense.pixel_clock > sense.pixel_clock_max) { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1448 | dev_err(dev, |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1449 | "pixel clock %lu set by the camera too high!", |
| 1450 | sense.pixel_clock); |
| 1451 | return -EIO; |
| 1452 | } |
| 1453 | recalculate_fifo_timeout(pcdev, sense.pixel_clock); |
| 1454 | } |
| 1455 | |
| 1456 | if (!ret) { |
Guennadi Liakhovetski | 0ad675e | 2009-02-23 12:11:25 -0300 | [diff] [blame] | 1457 | icd->buswidth = xlate->buswidth; |
| 1458 | icd->current_fmt = xlate->host_fmt; |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1459 | } |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 1460 | |
| 1461 | return ret; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1462 | } |
| 1463 | |
Guennadi Liakhovetski | d8fac21 | 2008-12-01 09:45:21 -0300 | [diff] [blame] | 1464 | static int pxa_camera_try_fmt(struct soc_camera_device *icd, |
| 1465 | struct v4l2_format *f) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1466 | { |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1467 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 1468 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1469 | const struct soc_camera_format_xlate *xlate; |
| 1470 | struct v4l2_pix_format *pix = &f->fmt.pix; |
| 1471 | __u32 pixfmt = pix->pixelformat; |
Guennadi Liakhovetski | 06daa1a | 2008-12-18 12:52:08 -0300 | [diff] [blame] | 1472 | enum v4l2_field field; |
Guennadi Liakhovetski | bf50715 | 2008-12-18 11:53:51 -0300 | [diff] [blame] | 1473 | int ret; |
Guennadi Liakhovetski | a2c8c68 | 2008-12-01 09:44:53 -0300 | [diff] [blame] | 1474 | |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1475 | xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); |
| 1476 | if (!xlate) { |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1477 | dev_warn(ici->v4l2_dev.dev, "Format %x not found\n", pixfmt); |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 1478 | return -EINVAL; |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1479 | } |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 1480 | |
Robert Jarzmik | 92a8337 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 1481 | /* |
Trent Piepho | 4a6b8df | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1482 | * Limit to pxa hardware capabilities. YUV422P planar format requires |
| 1483 | * images size to be a multiple of 16 bytes. If not, zeros will be |
| 1484 | * inserted between Y and U planes, and U and V planes, which violates |
| 1485 | * the YUV422P standard. |
Robert Jarzmik | 92a8337 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 1486 | */ |
Trent Piepho | 4a6b8df | 2009-05-30 21:45:46 -0300 | [diff] [blame] | 1487 | v4l_bound_align_image(&pix->width, 48, 2048, 1, |
| 1488 | &pix->height, 32, 2048, 0, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1489 | pixfmt == V4L2_PIX_FMT_YUV422P ? 4 : 0); |
Robert Jarzmik | 92a8337 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 1490 | |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1491 | pix->bytesperline = pix->width * |
| 1492 | DIV_ROUND_UP(xlate->host_fmt->depth, 8); |
| 1493 | pix->sizeimage = pix->height * pix->bytesperline; |
Guennadi Liakhovetski | 25c4d74 | 2008-12-01 09:44:59 -0300 | [diff] [blame] | 1494 | |
Guennadi Liakhovetski | bf50715 | 2008-12-18 11:53:51 -0300 | [diff] [blame] | 1495 | /* camera has to see its format, but the user the original one */ |
| 1496 | pix->pixelformat = xlate->cam_fmt->fourcc; |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1497 | /* limit to sensor capabilities */ |
Guennadi Liakhovetski | c9c1f1c | 2009-08-25 11:46:59 -0300 | [diff] [blame] | 1498 | ret = v4l2_subdev_call(sd, video, try_fmt, f); |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1499 | pix->pixelformat = pixfmt; |
Guennadi Liakhovetski | bf50715 | 2008-12-18 11:53:51 -0300 | [diff] [blame] | 1500 | |
Guennadi Liakhovetski | 06daa1a | 2008-12-18 12:52:08 -0300 | [diff] [blame] | 1501 | field = pix->field; |
| 1502 | |
| 1503 | if (field == V4L2_FIELD_ANY) { |
| 1504 | pix->field = V4L2_FIELD_NONE; |
| 1505 | } else if (field != V4L2_FIELD_NONE) { |
Guennadi Liakhovetski | 0166b74 | 2009-08-25 11:47:00 -0300 | [diff] [blame] | 1506 | dev_err(icd->dev.parent, "Field type %d unsupported.\n", field); |
Guennadi Liakhovetski | 06daa1a | 2008-12-18 12:52:08 -0300 | [diff] [blame] | 1507 | return -EINVAL; |
| 1508 | } |
| 1509 | |
Guennadi Liakhovetski | bf50715 | 2008-12-18 11:53:51 -0300 | [diff] [blame] | 1510 | return ret; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1511 | } |
| 1512 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 1513 | static int pxa_camera_reqbufs(struct soc_camera_file *icf, |
| 1514 | struct v4l2_requestbuffers *p) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1515 | { |
| 1516 | int i; |
| 1517 | |
| 1518 | /* This is for locking debugging only. I removed spinlocks and now I |
| 1519 | * check whether .prepare is ever called on a linked buffer, or whether |
| 1520 | * a dma IRQ can occur for an in-work or unlinked buffer. Until now |
| 1521 | * it hadn't triggered */ |
| 1522 | for (i = 0; i < p->count; i++) { |
| 1523 | struct pxa_buffer *buf = container_of(icf->vb_vidq.bufs[i], |
| 1524 | struct pxa_buffer, vb); |
| 1525 | buf->inwork = 0; |
| 1526 | INIT_LIST_HEAD(&buf->vb.queue); |
| 1527 | } |
| 1528 | |
| 1529 | return 0; |
| 1530 | } |
| 1531 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 1532 | static unsigned int pxa_camera_poll(struct file *file, poll_table *pt) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1533 | { |
| 1534 | struct soc_camera_file *icf = file->private_data; |
| 1535 | struct pxa_buffer *buf; |
| 1536 | |
| 1537 | buf = list_entry(icf->vb_vidq.stream.next, struct pxa_buffer, |
| 1538 | vb.stream); |
| 1539 | |
| 1540 | poll_wait(file, &buf->vb.done, pt); |
| 1541 | |
| 1542 | if (buf->vb.state == VIDEOBUF_DONE || |
| 1543 | buf->vb.state == VIDEOBUF_ERROR) |
| 1544 | return POLLIN|POLLRDNORM; |
| 1545 | |
| 1546 | return 0; |
| 1547 | } |
| 1548 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 1549 | static int pxa_camera_querycap(struct soc_camera_host *ici, |
| 1550 | struct v4l2_capability *cap) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1551 | { |
| 1552 | /* cap->name is set by the firendly caller:-> */ |
| 1553 | strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card)); |
| 1554 | cap->version = PXA_CAM_VERSION_CODE; |
| 1555 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; |
| 1556 | |
| 1557 | return 0; |
| 1558 | } |
| 1559 | |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 1560 | static int pxa_camera_suspend(struct soc_camera_device *icd, pm_message_t state) |
| 1561 | { |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 1562 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 1563 | struct pxa_camera_dev *pcdev = ici->priv; |
| 1564 | int i = 0, ret = 0; |
| 1565 | |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 1566 | pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR0); |
| 1567 | pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR1); |
| 1568 | pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR2); |
| 1569 | pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR3); |
| 1570 | pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR4); |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 1571 | |
| 1572 | if ((pcdev->icd) && (pcdev->icd->ops->suspend)) |
| 1573 | ret = pcdev->icd->ops->suspend(pcdev->icd, state); |
| 1574 | |
| 1575 | return ret; |
| 1576 | } |
| 1577 | |
| 1578 | static int pxa_camera_resume(struct soc_camera_device *icd) |
| 1579 | { |
Guennadi Liakhovetski | 64f5905 | 2008-12-18 11:51:55 -0300 | [diff] [blame] | 1580 | struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 1581 | struct pxa_camera_dev *pcdev = ici->priv; |
| 1582 | int i = 0, ret = 0; |
| 1583 | |
Eric Miao | 87f3dd7 | 2008-09-08 15:26:43 +0800 | [diff] [blame] | 1584 | DRCMR(68) = pcdev->dma_chans[0] | DRCMR_MAPVLD; |
| 1585 | DRCMR(69) = pcdev->dma_chans[1] | DRCMR_MAPVLD; |
| 1586 | DRCMR(70) = pcdev->dma_chans[2] | DRCMR_MAPVLD; |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 1587 | |
Eric Miao | 5ca11fa | 2008-12-18 11:15:50 -0300 | [diff] [blame] | 1588 | __raw_writel(pcdev->save_cicr[i++] & ~CICR0_ENB, pcdev->base + CICR0); |
| 1589 | __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR1); |
| 1590 | __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR2); |
| 1591 | __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR3); |
| 1592 | __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR4); |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 1593 | |
| 1594 | if ((pcdev->icd) && (pcdev->icd->ops->resume)) |
| 1595 | ret = pcdev->icd->ops->resume(pcdev->icd); |
| 1596 | |
| 1597 | /* Restart frame capture if active buffer exists */ |
Robert Jarzmik | 256b023 | 2009-03-31 03:44:21 -0300 | [diff] [blame] | 1598 | if (!ret && pcdev->active) |
| 1599 | pxa_camera_start_capture(pcdev); |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 1600 | |
| 1601 | return ret; |
| 1602 | } |
| 1603 | |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 1604 | static struct soc_camera_host_ops pxa_soc_camera_host_ops = { |
| 1605 | .owner = THIS_MODULE, |
| 1606 | .add = pxa_camera_add_device, |
| 1607 | .remove = pxa_camera_remove_device, |
Robert Jarzmik | 3f6ac49 | 2008-08-02 07:10:04 -0300 | [diff] [blame] | 1608 | .suspend = pxa_camera_suspend, |
| 1609 | .resume = pxa_camera_resume, |
Guennadi Liakhovetski | 09e231b | 2009-03-13 06:08:20 -0300 | [diff] [blame] | 1610 | .set_crop = pxa_camera_set_crop, |
Robert Jarzmik | 2a48fc7 | 2008-12-01 09:45:35 -0300 | [diff] [blame] | 1611 | .get_formats = pxa_camera_get_formats, |
Guennadi Liakhovetski | 6a6c878 | 2009-08-25 11:50:46 -0300 | [diff] [blame] | 1612 | .put_formats = pxa_camera_put_formats, |
Guennadi Liakhovetski | d8fac21 | 2008-12-01 09:45:21 -0300 | [diff] [blame] | 1613 | .set_fmt = pxa_camera_set_fmt, |
| 1614 | .try_fmt = pxa_camera_try_fmt, |
Paulius Zaleckas | 092d392 | 2008-07-11 20:50:31 -0300 | [diff] [blame] | 1615 | .init_videobuf = pxa_camera_init_videobuf, |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 1616 | .reqbufs = pxa_camera_reqbufs, |
| 1617 | .poll = pxa_camera_poll, |
| 1618 | .querycap = pxa_camera_querycap, |
Guennadi Liakhovetski | b8d9904 | 2008-04-04 13:41:25 -0300 | [diff] [blame] | 1619 | .set_bus_param = pxa_camera_set_bus_param, |
| 1620 | }; |
| 1621 | |
Jean Delvare | e36bc31 | 2009-06-04 11:07:16 -0300 | [diff] [blame] | 1622 | static int __devinit pxa_camera_probe(struct platform_device *pdev) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1623 | { |
| 1624 | struct pxa_camera_dev *pcdev; |
| 1625 | struct resource *res; |
| 1626 | void __iomem *base; |
Guennadi Liakhovetski | 02da465 | 2008-06-13 09:03:45 -0300 | [diff] [blame] | 1627 | int irq; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1628 | int err = 0; |
| 1629 | |
| 1630 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1631 | irq = platform_get_irq(pdev, 0); |
Guennadi Liakhovetski | 02da465 | 2008-06-13 09:03:45 -0300 | [diff] [blame] | 1632 | if (!res || irq < 0) { |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1633 | err = -ENODEV; |
| 1634 | goto exit; |
| 1635 | } |
| 1636 | |
| 1637 | pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL); |
| 1638 | if (!pcdev) { |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 1639 | dev_err(&pdev->dev, "Could not allocate pcdev\n"); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1640 | err = -ENOMEM; |
| 1641 | goto exit; |
| 1642 | } |
| 1643 | |
Russell King | e0d8b13 | 2008-11-11 17:52:32 +0000 | [diff] [blame] | 1644 | pcdev->clk = clk_get(&pdev->dev, NULL); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1645 | if (IS_ERR(pcdev->clk)) { |
| 1646 | err = PTR_ERR(pcdev->clk); |
| 1647 | goto exit_kfree; |
| 1648 | } |
| 1649 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1650 | pcdev->res = res; |
| 1651 | |
| 1652 | pcdev->pdata = pdev->dev.platform_data; |
| 1653 | pcdev->platform_flags = pcdev->pdata->flags; |
Guennadi Liakhovetski | ad5f2e8 | 2008-03-07 21:57:18 -0300 | [diff] [blame] | 1654 | if (!(pcdev->platform_flags & (PXA_CAMERA_DATAWIDTH_8 | |
| 1655 | PXA_CAMERA_DATAWIDTH_9 | PXA_CAMERA_DATAWIDTH_10))) { |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1656 | /* Platform hasn't set available data widths. This is bad. |
| 1657 | * Warn and use a default. */ |
| 1658 | dev_warn(&pdev->dev, "WARNING! Platform hasn't set available " |
| 1659 | "data widths, using default 10 bit\n"); |
| 1660 | pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10; |
| 1661 | } |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1662 | pcdev->mclk = pcdev->pdata->mclk_10khz * 10000; |
| 1663 | if (!pcdev->mclk) { |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1664 | dev_warn(&pdev->dev, |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1665 | "mclk == 0! Please, fix your platform data. " |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1666 | "Using default 20MHz\n"); |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1667 | pcdev->mclk = 20000000; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1668 | } |
| 1669 | |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1670 | pcdev->mclk_divisor = mclk_get_divisor(pdev, pcdev); |
Guennadi Liakhovetski | cf34cba | 2008-12-18 11:38:03 -0300 | [diff] [blame] | 1671 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1672 | INIT_LIST_HEAD(&pcdev->capture); |
| 1673 | spin_lock_init(&pcdev->lock); |
| 1674 | |
| 1675 | /* |
| 1676 | * Request the regions. |
| 1677 | */ |
Guennadi Liakhovetski | eb6c855 | 2009-04-24 12:55:18 -0300 | [diff] [blame] | 1678 | if (!request_mem_region(res->start, resource_size(res), |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1679 | PXA_CAM_DRV_NAME)) { |
| 1680 | err = -EBUSY; |
| 1681 | goto exit_clk; |
| 1682 | } |
| 1683 | |
Guennadi Liakhovetski | eb6c855 | 2009-04-24 12:55:18 -0300 | [diff] [blame] | 1684 | base = ioremap(res->start, resource_size(res)); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1685 | if (!base) { |
| 1686 | err = -ENOMEM; |
| 1687 | goto exit_release; |
| 1688 | } |
| 1689 | pcdev->irq = irq; |
| 1690 | pcdev->base = base; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1691 | |
| 1692 | /* request dma */ |
roel kluin | de3e3b8 | 2008-09-18 17:50:15 -0300 | [diff] [blame] | 1693 | err = pxa_request_dma("CI_Y", DMA_PRIO_HIGH, |
| 1694 | pxa_camera_dma_irq_y, pcdev); |
| 1695 | if (err < 0) { |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1696 | dev_err(&pdev->dev, "Can't request DMA for Y\n"); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1697 | goto exit_iounmap; |
| 1698 | } |
roel kluin | de3e3b8 | 2008-09-18 17:50:15 -0300 | [diff] [blame] | 1699 | pcdev->dma_chans[0] = err; |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1700 | dev_dbg(&pdev->dev, "got DMA channel %d\n", pcdev->dma_chans[0]); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1701 | |
roel kluin | de3e3b8 | 2008-09-18 17:50:15 -0300 | [diff] [blame] | 1702 | err = pxa_request_dma("CI_U", DMA_PRIO_HIGH, |
| 1703 | pxa_camera_dma_irq_u, pcdev); |
| 1704 | if (err < 0) { |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1705 | dev_err(&pdev->dev, "Can't request DMA for U\n"); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 1706 | goto exit_free_dma_y; |
| 1707 | } |
roel kluin | de3e3b8 | 2008-09-18 17:50:15 -0300 | [diff] [blame] | 1708 | pcdev->dma_chans[1] = err; |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1709 | dev_dbg(&pdev->dev, "got DMA channel (U) %d\n", pcdev->dma_chans[1]); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 1710 | |
roel kluin | de3e3b8 | 2008-09-18 17:50:15 -0300 | [diff] [blame] | 1711 | err = pxa_request_dma("CI_V", DMA_PRIO_HIGH, |
| 1712 | pxa_camera_dma_irq_v, pcdev); |
| 1713 | if (err < 0) { |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1714 | dev_err(&pdev->dev, "Can't request DMA for V\n"); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 1715 | goto exit_free_dma_u; |
| 1716 | } |
roel kluin | de3e3b8 | 2008-09-18 17:50:15 -0300 | [diff] [blame] | 1717 | pcdev->dma_chans[2] = err; |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1718 | dev_dbg(&pdev->dev, "got DMA channel (V) %d\n", pcdev->dma_chans[2]); |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 1719 | |
Eric Miao | 87f3dd7 | 2008-09-08 15:26:43 +0800 | [diff] [blame] | 1720 | DRCMR(68) = pcdev->dma_chans[0] | DRCMR_MAPVLD; |
| 1721 | DRCMR(69) = pcdev->dma_chans[1] | DRCMR_MAPVLD; |
| 1722 | DRCMR(70) = pcdev->dma_chans[2] | DRCMR_MAPVLD; |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1723 | |
| 1724 | /* request irq */ |
| 1725 | err = request_irq(pcdev->irq, pxa_camera_irq, 0, PXA_CAM_DRV_NAME, |
| 1726 | pcdev); |
| 1727 | if (err) { |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1728 | dev_err(&pdev->dev, "Camera interrupt register failed \n"); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1729 | goto exit_free_dma; |
| 1730 | } |
| 1731 | |
Guennadi Liakhovetski | eb6c855 | 2009-04-24 12:55:18 -0300 | [diff] [blame] | 1732 | pcdev->soc_host.drv_name = PXA_CAM_DRV_NAME; |
| 1733 | pcdev->soc_host.ops = &pxa_soc_camera_host_ops; |
| 1734 | pcdev->soc_host.priv = pcdev; |
Guennadi Liakhovetski | 979ea1d | 2009-08-25 11:43:33 -0300 | [diff] [blame] | 1735 | pcdev->soc_host.v4l2_dev.dev = &pdev->dev; |
Guennadi Liakhovetski | eb6c855 | 2009-04-24 12:55:18 -0300 | [diff] [blame] | 1736 | pcdev->soc_host.nr = pdev->id; |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1737 | |
Guennadi Liakhovetski | eb6c855 | 2009-04-24 12:55:18 -0300 | [diff] [blame] | 1738 | err = soc_camera_host_register(&pcdev->soc_host); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1739 | if (err) |
| 1740 | goto exit_free_irq; |
| 1741 | |
| 1742 | return 0; |
| 1743 | |
| 1744 | exit_free_irq: |
| 1745 | free_irq(pcdev->irq, pcdev); |
| 1746 | exit_free_dma: |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 1747 | pxa_free_dma(pcdev->dma_chans[2]); |
| 1748 | exit_free_dma_u: |
| 1749 | pxa_free_dma(pcdev->dma_chans[1]); |
| 1750 | exit_free_dma_y: |
| 1751 | pxa_free_dma(pcdev->dma_chans[0]); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1752 | exit_iounmap: |
| 1753 | iounmap(base); |
| 1754 | exit_release: |
Guennadi Liakhovetski | eb6c855 | 2009-04-24 12:55:18 -0300 | [diff] [blame] | 1755 | release_mem_region(res->start, resource_size(res)); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1756 | exit_clk: |
| 1757 | clk_put(pcdev->clk); |
| 1758 | exit_kfree: |
| 1759 | kfree(pcdev); |
| 1760 | exit: |
| 1761 | return err; |
| 1762 | } |
| 1763 | |
| 1764 | static int __devexit pxa_camera_remove(struct platform_device *pdev) |
| 1765 | { |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1766 | struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); |
| 1767 | struct pxa_camera_dev *pcdev = container_of(soc_host, |
| 1768 | struct pxa_camera_dev, soc_host); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1769 | struct resource *res; |
| 1770 | |
| 1771 | clk_put(pcdev->clk); |
| 1772 | |
Mike Rapoport | a5462e5 | 2008-04-22 10:36:32 -0300 | [diff] [blame] | 1773 | pxa_free_dma(pcdev->dma_chans[0]); |
| 1774 | pxa_free_dma(pcdev->dma_chans[1]); |
| 1775 | pxa_free_dma(pcdev->dma_chans[2]); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1776 | free_irq(pcdev->irq, pcdev); |
| 1777 | |
Guennadi Liakhovetski | eff505f | 2009-04-24 12:55:48 -0300 | [diff] [blame] | 1778 | soc_camera_host_unregister(soc_host); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1779 | |
| 1780 | iounmap(pcdev->base); |
| 1781 | |
| 1782 | res = pcdev->res; |
Guennadi Liakhovetski | eb6c855 | 2009-04-24 12:55:18 -0300 | [diff] [blame] | 1783 | release_mem_region(res->start, resource_size(res)); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1784 | |
| 1785 | kfree(pcdev); |
| 1786 | |
Guennadi Liakhovetski | 7102b77 | 2008-04-15 02:57:48 -0300 | [diff] [blame] | 1787 | dev_info(&pdev->dev, "PXA Camera driver unloaded\n"); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1788 | |
| 1789 | return 0; |
| 1790 | } |
| 1791 | |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1792 | static struct platform_driver pxa_camera_driver = { |
| 1793 | .driver = { |
| 1794 | .name = PXA_CAM_DRV_NAME, |
| 1795 | }, |
| 1796 | .probe = pxa_camera_probe, |
Jean Delvare | e36bc31 | 2009-06-04 11:07:16 -0300 | [diff] [blame] | 1797 | .remove = __devexit_p(pxa_camera_remove), |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1798 | }; |
| 1799 | |
| 1800 | |
Jean Delvare | e36bc31 | 2009-06-04 11:07:16 -0300 | [diff] [blame] | 1801 | static int __init pxa_camera_init(void) |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1802 | { |
| 1803 | return platform_driver_register(&pxa_camera_driver); |
| 1804 | } |
| 1805 | |
| 1806 | static void __exit pxa_camera_exit(void) |
| 1807 | { |
Paul Mundt | 01c1e4c | 2008-08-01 19:48:51 -0300 | [diff] [blame] | 1808 | platform_driver_unregister(&pxa_camera_driver); |
Guennadi Liakhovetski | 3bc4384 | 2008-04-06 21:24:56 -0300 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | module_init(pxa_camera_init); |
| 1812 | module_exit(pxa_camera_exit); |
| 1813 | |
| 1814 | MODULE_DESCRIPTION("PXA27x SoC Camera Host driver"); |
| 1815 | MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>"); |
| 1816 | MODULE_LICENSE("GPL"); |
Guennadi Liakhovetski | 40e2e09 | 2009-08-25 11:28:22 -0300 | [diff] [blame] | 1817 | MODULE_ALIAS("platform:" PXA_CAM_DRV_NAME); |