Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Texas Instruments Inc |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * TODO : add support for VBI & HBI data service |
| 19 | * add static buffer allocation |
| 20 | */ |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/fs.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/workqueue.h> |
| 29 | #include <linux/string.h> |
| 30 | #include <linux/videodev2.h> |
| 31 | #include <linux/wait.h> |
| 32 | #include <linux/time.h> |
| 33 | #include <linux/i2c.h> |
| 34 | #include <linux/platform_device.h> |
| 35 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 37 | #include <media/v4l2-device.h> |
| 38 | #include <media/v4l2-ioctl.h> |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 39 | #include <media/v4l2-chip-ident.h> |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 40 | |
| 41 | #include "vpif_capture.h" |
| 42 | #include "vpif.h" |
| 43 | |
| 44 | MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver"); |
| 45 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 64dc3c1 | 2011-06-25 11:28:37 -0300 | [diff] [blame] | 46 | MODULE_VERSION(VPIF_CAPTURE_VERSION); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 47 | |
| 48 | #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg) |
| 49 | #define vpif_dbg(level, debug, fmt, arg...) \ |
| 50 | v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg) |
| 51 | |
| 52 | static int debug = 1; |
| 53 | static u32 ch0_numbuffers = 3; |
| 54 | static u32 ch1_numbuffers = 3; |
| 55 | static u32 ch0_bufsize = 1920 * 1080 * 2; |
| 56 | static u32 ch1_bufsize = 720 * 576 * 2; |
| 57 | |
| 58 | module_param(debug, int, 0644); |
| 59 | module_param(ch0_numbuffers, uint, S_IRUGO); |
| 60 | module_param(ch1_numbuffers, uint, S_IRUGO); |
| 61 | module_param(ch0_bufsize, uint, S_IRUGO); |
| 62 | module_param(ch1_bufsize, uint, S_IRUGO); |
| 63 | |
| 64 | MODULE_PARM_DESC(debug, "Debug level 0-1"); |
| 65 | MODULE_PARM_DESC(ch2_numbuffers, "Channel0 buffer count (default:3)"); |
| 66 | MODULE_PARM_DESC(ch3_numbuffers, "Channel1 buffer count (default:3)"); |
| 67 | MODULE_PARM_DESC(ch2_bufsize, "Channel0 buffer size (default:1920 x 1080 x 2)"); |
| 68 | MODULE_PARM_DESC(ch3_bufsize, "Channel1 buffer size (default:720 x 576 x 2)"); |
| 69 | |
| 70 | static struct vpif_config_params config_params = { |
| 71 | .min_numbuffers = 3, |
| 72 | .numbuffers[0] = 3, |
| 73 | .numbuffers[1] = 3, |
| 74 | .min_bufsize[0] = 720 * 480 * 2, |
| 75 | .min_bufsize[1] = 720 * 480 * 2, |
| 76 | .channel_bufsize[0] = 1920 * 1080 * 2, |
| 77 | .channel_bufsize[1] = 720 * 576 * 2, |
| 78 | }; |
| 79 | |
| 80 | /* global variables */ |
| 81 | static struct vpif_device vpif_obj = { {NULL} }; |
| 82 | static struct device *vpif_dev; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 83 | static void vpif_calculate_offsets(struct channel_obj *ch); |
| 84 | static void vpif_config_addr(struct channel_obj *ch, int muxmode); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * buffer_prepare : callback function for buffer prepare |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 88 | * @vb: ptr to vb2_buffer |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 89 | * |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 90 | * This is the callback function for buffer prepare when vb2_qbuf() |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 91 | * function is called. The buffer is prepared and user space virtual address |
| 92 | * or user address is converted into physical address |
| 93 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 94 | static int vpif_buffer_prepare(struct vb2_buffer *vb) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 95 | { |
| 96 | /* Get the file handle object and channel object */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 97 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); |
| 98 | struct vb2_queue *q = vb->vb2_queue; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 99 | struct channel_obj *ch = fh->channel; |
| 100 | struct common_obj *common; |
| 101 | unsigned long addr; |
| 102 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 103 | vpif_dbg(2, debug, "vpif_buffer_prepare\n"); |
| 104 | |
| 105 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 106 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 107 | if (vb->state != VB2_BUF_STATE_ACTIVE && |
| 108 | vb->state != VB2_BUF_STATE_PREPARED) { |
| 109 | vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage); |
| 110 | if (vb2_plane_vaddr(vb, 0) && |
| 111 | vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) |
| 112 | goto exit; |
| 113 | addr = vb2_dma_contig_plane_dma_addr(vb, 0); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 114 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 115 | if (q->streaming) { |
| 116 | if (!IS_ALIGNED((addr + common->ytop_off), 8) || |
| 117 | !IS_ALIGNED((addr + common->ybtm_off), 8) || |
| 118 | !IS_ALIGNED((addr + common->ctop_off), 8) || |
| 119 | !IS_ALIGNED((addr + common->cbtm_off), 8)) |
| 120 | goto exit; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 121 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 122 | } |
| 123 | return 0; |
| 124 | exit: |
| 125 | vpif_dbg(1, debug, "buffer_prepare:offset is not aligned to 8 bytes\n"); |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | |
| 129 | /** |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 130 | * vpif_buffer_queue_setup : Callback function for buffer setup. |
| 131 | * @vq: vb2_queue ptr |
| 132 | * @fmt: v4l2 format |
| 133 | * @nbuffers: ptr to number of buffers requested by application |
| 134 | * @nplanes:: contains number of distinct video planes needed to hold a frame |
| 135 | * @sizes[]: contains the size (in bytes) of each plane. |
| 136 | * @alloc_ctxs: ptr to allocation context |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 137 | * |
| 138 | * This callback function is called when reqbuf() is called to adjust |
| 139 | * the buffer count and buffer size |
| 140 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 141 | static int vpif_buffer_queue_setup(struct vb2_queue *vq, |
| 142 | const struct v4l2_format *fmt, |
| 143 | unsigned int *nbuffers, unsigned int *nplanes, |
| 144 | unsigned int sizes[], void *alloc_ctxs[]) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 145 | { |
| 146 | /* Get the file handle object and channel object */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 147 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 148 | struct channel_obj *ch = fh->channel; |
| 149 | struct common_obj *common; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 150 | unsigned long size; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 151 | |
| 152 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 153 | |
| 154 | vpif_dbg(2, debug, "vpif_buffer_setup\n"); |
| 155 | |
| 156 | /* If memory type is not mmap, return */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 157 | if (V4L2_MEMORY_MMAP == common->memory) { |
| 158 | /* Calculate the size of the buffer */ |
| 159 | size = config_params.channel_bufsize[ch->channel_id]; |
| 160 | /* |
| 161 | * Checking if the buffer size exceeds the available buffer |
| 162 | * ycmux_mode = 0 means 1 channel mode HD and |
| 163 | * ycmux_mode = 1 means 2 channels mode SD |
| 164 | */ |
| 165 | if (ch->vpifparams.std_info.ycmux_mode == 0) { |
| 166 | if (config_params.video_limit[ch->channel_id]) |
| 167 | while (size * *nbuffers > |
| 168 | (config_params.video_limit[0] |
Manjunath Hadli | 764af39 | 2012-04-13 04:49:34 -0300 | [diff] [blame] | 169 | + config_params.video_limit[1])) |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 170 | (*nbuffers)--; |
| 171 | } else { |
| 172 | if (config_params.video_limit[ch->channel_id]) |
| 173 | while (size * *nbuffers > |
Manjunath Hadli | 764af39 | 2012-04-13 04:49:34 -0300 | [diff] [blame] | 174 | config_params.video_limit[ch->channel_id]) |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 175 | (*nbuffers)--; |
| 176 | } |
| 177 | |
| 178 | } else { |
| 179 | size = common->fmt.fmt.pix.sizeimage; |
Manjunath Hadli | 764af39 | 2012-04-13 04:49:34 -0300 | [diff] [blame] | 180 | } |
| 181 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 182 | if (*nbuffers < config_params.min_numbuffers) |
| 183 | *nbuffers = config_params.min_numbuffers; |
| 184 | |
| 185 | *nplanes = 1; |
| 186 | sizes[0] = size; |
| 187 | alloc_ctxs[0] = common->alloc_ctx; |
| 188 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * vpif_buffer_queue : Callback function to add buffer to DMA queue |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 194 | * @vb: ptr to vb2_buffer |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 195 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 196 | static void vpif_buffer_queue(struct vb2_buffer *vb) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 197 | { |
| 198 | /* Get the file handle object and channel object */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 199 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 200 | struct channel_obj *ch = fh->channel; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 201 | struct vpif_cap_buffer *buf = container_of(vb, |
| 202 | struct vpif_cap_buffer, vb); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 203 | struct common_obj *common; |
| 204 | |
| 205 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 206 | |
| 207 | vpif_dbg(2, debug, "vpif_buffer_queue\n"); |
| 208 | |
| 209 | /* add the buffer to the DMA queue */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 210 | list_add_tail(&buf->list, &common->dma_queue); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 214 | * vpif_buf_cleanup : Callback function to free buffer |
| 215 | * @vb: ptr to vb2_buffer |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 216 | * |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 217 | * This function is called from the videobuf2 layer to free memory |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 218 | * allocated to the buffers |
| 219 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 220 | static void vpif_buf_cleanup(struct vb2_buffer *vb) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 221 | { |
| 222 | /* Get the file handle object and channel object */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 223 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); |
| 224 | struct vpif_cap_buffer *buf = container_of(vb, |
| 225 | struct vpif_cap_buffer, vb); |
| 226 | struct channel_obj *ch = fh->channel; |
| 227 | struct common_obj *common; |
| 228 | unsigned long flags; |
| 229 | |
| 230 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 231 | |
| 232 | spin_lock_irqsave(&common->irqlock, flags); |
| 233 | if (vb->state == VB2_BUF_STATE_ACTIVE) |
| 234 | list_del_init(&buf->list); |
| 235 | spin_unlock_irqrestore(&common->irqlock, flags); |
| 236 | |
| 237 | } |
| 238 | |
| 239 | static void vpif_wait_prepare(struct vb2_queue *vq) |
| 240 | { |
| 241 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 242 | struct channel_obj *ch = fh->channel; |
| 243 | struct common_obj *common; |
| 244 | |
| 245 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 246 | mutex_unlock(&common->lock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 247 | } |
| 248 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 249 | static void vpif_wait_finish(struct vb2_queue *vq) |
| 250 | { |
| 251 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
| 252 | struct channel_obj *ch = fh->channel; |
| 253 | struct common_obj *common; |
| 254 | |
| 255 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 256 | mutex_lock(&common->lock); |
| 257 | } |
| 258 | |
| 259 | static int vpif_buffer_init(struct vb2_buffer *vb) |
| 260 | { |
| 261 | struct vpif_cap_buffer *buf = container_of(vb, |
| 262 | struct vpif_cap_buffer, vb); |
| 263 | |
| 264 | INIT_LIST_HEAD(&buf->list); |
| 265 | |
| 266 | return 0; |
| 267 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 268 | |
| 269 | static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = |
| 270 | { {1, 1} }; |
| 271 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 272 | static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) |
| 273 | { |
| 274 | struct vpif_capture_config *vpif_config_data = |
| 275 | vpif_dev->platform_data; |
| 276 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
| 277 | struct channel_obj *ch = fh->channel; |
| 278 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 279 | struct vpif_params *vpif = &ch->vpifparams; |
| 280 | unsigned long addr = 0; |
| 281 | int ret; |
| 282 | |
| 283 | /* If buffer queue is empty, return error */ |
| 284 | if (list_empty(&common->dma_queue)) { |
| 285 | vpif_dbg(1, debug, "buffer queue is empty\n"); |
| 286 | return -EIO; |
| 287 | } |
| 288 | |
| 289 | /* Get the next frame from the buffer queue */ |
| 290 | common->cur_frm = common->next_frm = list_entry(common->dma_queue.next, |
| 291 | struct vpif_cap_buffer, list); |
| 292 | /* Remove buffer from the buffer queue */ |
| 293 | list_del(&common->cur_frm->list); |
| 294 | /* Mark state of the current frame to active */ |
| 295 | common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE; |
| 296 | /* Initialize field_id and started member */ |
| 297 | ch->field_id = 0; |
| 298 | common->started = 1; |
| 299 | addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0); |
| 300 | |
| 301 | /* Calculate the offset for Y and C data in the buffer */ |
| 302 | vpif_calculate_offsets(ch); |
| 303 | |
| 304 | if ((vpif->std_info.frm_fmt && |
| 305 | ((common->fmt.fmt.pix.field != V4L2_FIELD_NONE) && |
| 306 | (common->fmt.fmt.pix.field != V4L2_FIELD_ANY))) || |
| 307 | (!vpif->std_info.frm_fmt && |
| 308 | (common->fmt.fmt.pix.field == V4L2_FIELD_NONE))) { |
| 309 | vpif_dbg(1, debug, "conflict in field format and std format\n"); |
| 310 | return -EINVAL; |
| 311 | } |
| 312 | |
| 313 | /* configure 1 or 2 channel mode */ |
Lad, Prabhakar | f4ad8d7 | 2012-09-27 02:33:12 -0300 | [diff] [blame] | 314 | if (vpif_config_data->setup_input_channel_mode) { |
| 315 | ret = vpif_config_data-> |
| 316 | setup_input_channel_mode(vpif->std_info.ycmux_mode); |
| 317 | if (ret < 0) { |
| 318 | vpif_dbg(1, debug, "can't set vpif channel mode\n"); |
| 319 | return ret; |
| 320 | } |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /* Call vpif_set_params function to set the parameters and addresses */ |
| 324 | ret = vpif_set_video_params(vpif, ch->channel_id); |
| 325 | |
| 326 | if (ret < 0) { |
| 327 | vpif_dbg(1, debug, "can't set video params\n"); |
| 328 | return ret; |
| 329 | } |
| 330 | |
| 331 | common->started = ret; |
| 332 | vpif_config_addr(ch, ret); |
| 333 | |
| 334 | common->set_addr(addr + common->ytop_off, |
| 335 | addr + common->ybtm_off, |
| 336 | addr + common->ctop_off, |
| 337 | addr + common->cbtm_off); |
| 338 | |
| 339 | /** |
| 340 | * Set interrupt for both the fields in VPIF Register enable channel in |
| 341 | * VPIF register |
| 342 | */ |
Lad, Prabhakar | 9e18404 | 2012-09-14 10:22:24 -0300 | [diff] [blame] | 343 | channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 344 | if ((VPIF_CHANNEL0_VIDEO == ch->channel_id)) { |
| 345 | channel0_intr_assert(); |
| 346 | channel0_intr_enable(1); |
| 347 | enable_channel0(1); |
| 348 | } |
| 349 | if ((VPIF_CHANNEL1_VIDEO == ch->channel_id) || |
| 350 | (common->started == 2)) { |
| 351 | channel1_intr_assert(); |
| 352 | channel1_intr_enable(1); |
| 353 | enable_channel1(1); |
| 354 | } |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | /* abort streaming and wait for last buffer */ |
| 360 | static int vpif_stop_streaming(struct vb2_queue *vq) |
| 361 | { |
| 362 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
| 363 | struct channel_obj *ch = fh->channel; |
| 364 | struct common_obj *common; |
| 365 | |
| 366 | if (!vb2_is_streaming(vq)) |
| 367 | return 0; |
| 368 | |
| 369 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 370 | |
| 371 | /* release all active buffers */ |
| 372 | while (!list_empty(&common->dma_queue)) { |
| 373 | common->next_frm = list_entry(common->dma_queue.next, |
| 374 | struct vpif_cap_buffer, list); |
| 375 | list_del(&common->next_frm->list); |
| 376 | vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR); |
| 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static struct vb2_ops video_qops = { |
| 383 | .queue_setup = vpif_buffer_queue_setup, |
| 384 | .wait_prepare = vpif_wait_prepare, |
| 385 | .wait_finish = vpif_wait_finish, |
| 386 | .buf_init = vpif_buffer_init, |
| 387 | .buf_prepare = vpif_buffer_prepare, |
| 388 | .start_streaming = vpif_start_streaming, |
| 389 | .stop_streaming = vpif_stop_streaming, |
| 390 | .buf_cleanup = vpif_buf_cleanup, |
| 391 | .buf_queue = vpif_buffer_queue, |
| 392 | }; |
| 393 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 394 | /** |
| 395 | * vpif_process_buffer_complete: process a completed buffer |
| 396 | * @common: ptr to common channel object |
| 397 | * |
| 398 | * This function time stamp the buffer and mark it as DONE. It also |
| 399 | * wake up any process waiting on the QUEUE and set the next buffer |
| 400 | * as current |
| 401 | */ |
| 402 | static void vpif_process_buffer_complete(struct common_obj *common) |
| 403 | { |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 404 | do_gettimeofday(&common->cur_frm->vb.v4l2_buf.timestamp); |
| 405 | vb2_buffer_done(&common->cur_frm->vb, |
| 406 | VB2_BUF_STATE_DONE); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 407 | /* Make curFrm pointing to nextFrm */ |
| 408 | common->cur_frm = common->next_frm; |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * vpif_schedule_next_buffer: set next buffer address for capture |
| 413 | * @common : ptr to common channel object |
| 414 | * |
| 415 | * This function will get next buffer from the dma queue and |
| 416 | * set the buffer address in the vpif register for capture. |
| 417 | * the buffer is marked active |
| 418 | */ |
| 419 | static void vpif_schedule_next_buffer(struct common_obj *common) |
| 420 | { |
| 421 | unsigned long addr = 0; |
| 422 | |
| 423 | common->next_frm = list_entry(common->dma_queue.next, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 424 | struct vpif_cap_buffer, list); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 425 | /* Remove that buffer from the buffer queue */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 426 | list_del(&common->next_frm->list); |
| 427 | common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE; |
| 428 | addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 429 | |
| 430 | /* Set top and bottom field addresses in VPIF registers */ |
| 431 | common->set_addr(addr + common->ytop_off, |
| 432 | addr + common->ybtm_off, |
| 433 | addr + common->ctop_off, |
| 434 | addr + common->cbtm_off); |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * vpif_channel_isr : ISR handler for vpif capture |
| 439 | * @irq: irq number |
| 440 | * @dev_id: dev_id ptr |
| 441 | * |
| 442 | * It changes status of the captured buffer, takes next buffer from the queue |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 443 | * and sets its address in VPIF registers |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 444 | */ |
| 445 | static irqreturn_t vpif_channel_isr(int irq, void *dev_id) |
| 446 | { |
| 447 | struct vpif_device *dev = &vpif_obj; |
| 448 | struct common_obj *common; |
| 449 | struct channel_obj *ch; |
| 450 | enum v4l2_field field; |
| 451 | int channel_id = 0; |
| 452 | int fid = -1, i; |
| 453 | |
| 454 | channel_id = *(int *)(dev_id); |
Manjunath Hadli | b1fc423 | 2012-04-13 04:43:10 -0300 | [diff] [blame] | 455 | if (!vpif_intr_status(channel_id)) |
| 456 | return IRQ_NONE; |
| 457 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 458 | ch = dev->dev[channel_id]; |
| 459 | |
| 460 | field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field; |
| 461 | |
| 462 | for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) { |
| 463 | common = &ch->common[i]; |
| 464 | /* skip If streaming is not started in this channel */ |
| 465 | if (0 == common->started) |
| 466 | continue; |
| 467 | |
| 468 | /* Check the field format */ |
| 469 | if (1 == ch->vpifparams.std_info.frm_fmt) { |
| 470 | /* Progressive mode */ |
| 471 | if (list_empty(&common->dma_queue)) |
| 472 | continue; |
| 473 | |
| 474 | if (!channel_first_int[i][channel_id]) |
| 475 | vpif_process_buffer_complete(common); |
| 476 | |
| 477 | channel_first_int[i][channel_id] = 0; |
| 478 | |
| 479 | vpif_schedule_next_buffer(common); |
| 480 | |
| 481 | |
| 482 | channel_first_int[i][channel_id] = 0; |
| 483 | } else { |
| 484 | /** |
| 485 | * Interlaced mode. If it is first interrupt, ignore |
| 486 | * it |
| 487 | */ |
| 488 | if (channel_first_int[i][channel_id]) { |
| 489 | channel_first_int[i][channel_id] = 0; |
| 490 | continue; |
| 491 | } |
| 492 | if (0 == i) { |
| 493 | ch->field_id ^= 1; |
| 494 | /* Get field id from VPIF registers */ |
| 495 | fid = vpif_channel_getfid(ch->channel_id); |
| 496 | if (fid != ch->field_id) { |
| 497 | /** |
| 498 | * If field id does not match stored |
| 499 | * field id, make them in sync |
| 500 | */ |
| 501 | if (0 == fid) |
| 502 | ch->field_id = fid; |
| 503 | return IRQ_HANDLED; |
| 504 | } |
| 505 | } |
| 506 | /* device field id and local field id are in sync */ |
| 507 | if (0 == fid) { |
| 508 | /* this is even field */ |
| 509 | if (common->cur_frm == common->next_frm) |
| 510 | continue; |
| 511 | |
| 512 | /* mark the current buffer as done */ |
| 513 | vpif_process_buffer_complete(common); |
| 514 | } else if (1 == fid) { |
| 515 | /* odd field */ |
| 516 | if (list_empty(&common->dma_queue) || |
| 517 | (common->cur_frm != common->next_frm)) |
| 518 | continue; |
| 519 | |
| 520 | vpif_schedule_next_buffer(common); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | return IRQ_HANDLED; |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * vpif_update_std_info() - update standard related info |
| 529 | * @ch: ptr to channel object |
| 530 | * |
| 531 | * For a given standard selected by application, update values |
| 532 | * in the device data structures |
| 533 | */ |
| 534 | static int vpif_update_std_info(struct channel_obj *ch) |
| 535 | { |
| 536 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 537 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 538 | const struct vpif_channel_config_params *config; |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 539 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 540 | struct video_obj *vid_ch = &ch->video; |
| 541 | int index; |
| 542 | |
| 543 | vpif_dbg(2, debug, "vpif_update_std_info\n"); |
| 544 | |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 545 | for (index = 0; index < vpif_ch_params_count; index++) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 546 | config = &ch_params[index]; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 547 | if (config->hd_sd == 0) { |
| 548 | vpif_dbg(2, debug, "SD format\n"); |
| 549 | if (config->stdid & vid_ch->stdid) { |
| 550 | memcpy(std_info, config, sizeof(*config)); |
| 551 | break; |
| 552 | } |
| 553 | } else { |
| 554 | vpif_dbg(2, debug, "HD format\n"); |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 555 | if (!memcmp(&config->dv_timings, &vid_ch->dv_timings, |
| 556 | sizeof(vid_ch->dv_timings))) { |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 557 | memcpy(std_info, config, sizeof(*config)); |
| 558 | break; |
| 559 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
| 563 | /* standard not found */ |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 564 | if (index == vpif_ch_params_count) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 565 | return -EINVAL; |
| 566 | |
| 567 | common->fmt.fmt.pix.width = std_info->width; |
| 568 | common->width = std_info->width; |
| 569 | common->fmt.fmt.pix.height = std_info->height; |
| 570 | common->height = std_info->height; |
| 571 | common->fmt.fmt.pix.bytesperline = std_info->width; |
| 572 | vpifparams->video_params.hpitch = std_info->width; |
| 573 | vpifparams->video_params.storage_mode = std_info->frm_fmt; |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 574 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * vpif_calculate_offsets : This function calculates buffers offsets |
| 580 | * @ch : ptr to channel object |
| 581 | * |
| 582 | * This function calculates buffer offsets for Y and C in the top and |
| 583 | * bottom field |
| 584 | */ |
| 585 | static void vpif_calculate_offsets(struct channel_obj *ch) |
| 586 | { |
| 587 | unsigned int hpitch, vpitch, sizeimage; |
| 588 | struct video_obj *vid_ch = &(ch->video); |
| 589 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 590 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 591 | enum v4l2_field field = common->fmt.fmt.pix.field; |
| 592 | |
| 593 | vpif_dbg(2, debug, "vpif_calculate_offsets\n"); |
| 594 | |
| 595 | if (V4L2_FIELD_ANY == field) { |
| 596 | if (vpifparams->std_info.frm_fmt) |
| 597 | vid_ch->buf_field = V4L2_FIELD_NONE; |
| 598 | else |
| 599 | vid_ch->buf_field = V4L2_FIELD_INTERLACED; |
| 600 | } else |
| 601 | vid_ch->buf_field = common->fmt.fmt.pix.field; |
| 602 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 603 | sizeimage = common->fmt.fmt.pix.sizeimage; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 604 | |
| 605 | hpitch = common->fmt.fmt.pix.bytesperline; |
| 606 | vpitch = sizeimage / (hpitch * 2); |
| 607 | |
| 608 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 609 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) { |
| 610 | /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */ |
| 611 | common->ytop_off = 0; |
| 612 | common->ybtm_off = hpitch; |
| 613 | common->ctop_off = sizeimage / 2; |
| 614 | common->cbtm_off = sizeimage / 2 + hpitch; |
| 615 | } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) { |
| 616 | /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */ |
| 617 | common->ytop_off = 0; |
| 618 | common->ybtm_off = sizeimage / 4; |
| 619 | common->ctop_off = sizeimage / 2; |
| 620 | common->cbtm_off = common->ctop_off + sizeimage / 4; |
| 621 | } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) { |
| 622 | /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */ |
| 623 | common->ybtm_off = 0; |
| 624 | common->ytop_off = sizeimage / 4; |
| 625 | common->cbtm_off = sizeimage / 2; |
| 626 | common->ctop_off = common->cbtm_off + sizeimage / 4; |
| 627 | } |
| 628 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 629 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) |
| 630 | vpifparams->video_params.storage_mode = 1; |
| 631 | else |
| 632 | vpifparams->video_params.storage_mode = 0; |
| 633 | |
| 634 | if (1 == vpifparams->std_info.frm_fmt) |
| 635 | vpifparams->video_params.hpitch = |
| 636 | common->fmt.fmt.pix.bytesperline; |
| 637 | else { |
| 638 | if ((field == V4L2_FIELD_ANY) |
| 639 | || (field == V4L2_FIELD_INTERLACED)) |
| 640 | vpifparams->video_params.hpitch = |
| 641 | common->fmt.fmt.pix.bytesperline * 2; |
| 642 | else |
| 643 | vpifparams->video_params.hpitch = |
| 644 | common->fmt.fmt.pix.bytesperline; |
| 645 | } |
| 646 | |
| 647 | ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * vpif_config_format: configure default frame format in the device |
| 652 | * ch : ptr to channel object |
| 653 | */ |
| 654 | static void vpif_config_format(struct channel_obj *ch) |
| 655 | { |
| 656 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 657 | |
| 658 | vpif_dbg(2, debug, "vpif_config_format\n"); |
| 659 | |
| 660 | common->fmt.fmt.pix.field = V4L2_FIELD_ANY; |
| 661 | if (config_params.numbuffers[ch->channel_id] == 0) |
| 662 | common->memory = V4L2_MEMORY_USERPTR; |
| 663 | else |
| 664 | common->memory = V4L2_MEMORY_MMAP; |
| 665 | |
| 666 | common->fmt.fmt.pix.sizeimage |
| 667 | = config_params.channel_bufsize[ch->channel_id]; |
| 668 | |
| 669 | if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) |
| 670 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8; |
| 671 | else |
| 672 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P; |
| 673 | common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * vpif_get_default_field() - Get default field type based on interface |
| 678 | * @vpif_params - ptr to vpif params |
| 679 | */ |
| 680 | static inline enum v4l2_field vpif_get_default_field( |
| 681 | struct vpif_interface *iface) |
| 682 | { |
| 683 | return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE : |
| 684 | V4L2_FIELD_INTERLACED; |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * vpif_check_format() - check given pixel format for compatibility |
| 689 | * @ch - channel ptr |
| 690 | * @pixfmt - Given pixel format |
| 691 | * @update - update the values as per hardware requirement |
| 692 | * |
| 693 | * Check the application pixel format for S_FMT and update the input |
| 694 | * values as per hardware limits for TRY_FMT. The default pixel and |
| 695 | * field format is selected based on interface type. |
| 696 | */ |
| 697 | static int vpif_check_format(struct channel_obj *ch, |
| 698 | struct v4l2_pix_format *pixfmt, |
| 699 | int update) |
| 700 | { |
| 701 | struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 702 | struct vpif_params *vpif_params = &ch->vpifparams; |
| 703 | enum v4l2_field field = pixfmt->field; |
| 704 | u32 sizeimage, hpitch, vpitch; |
| 705 | int ret = -EINVAL; |
| 706 | |
| 707 | vpif_dbg(2, debug, "vpif_check_format\n"); |
| 708 | /** |
| 709 | * first check for the pixel format. If if_type is Raw bayer, |
| 710 | * only V4L2_PIX_FMT_SBGGR8 format is supported. Otherwise only |
| 711 | * V4L2_PIX_FMT_YUV422P is supported |
| 712 | */ |
| 713 | if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) { |
| 714 | if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8) { |
| 715 | if (!update) { |
| 716 | vpif_dbg(2, debug, "invalid pix format\n"); |
| 717 | goto exit; |
| 718 | } |
| 719 | pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8; |
| 720 | } |
| 721 | } else { |
| 722 | if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) { |
| 723 | if (!update) { |
| 724 | vpif_dbg(2, debug, "invalid pixel format\n"); |
| 725 | goto exit; |
| 726 | } |
| 727 | pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | if (!(VPIF_VALID_FIELD(field))) { |
| 732 | if (!update) { |
| 733 | vpif_dbg(2, debug, "invalid field format\n"); |
| 734 | goto exit; |
| 735 | } |
| 736 | /** |
| 737 | * By default use FIELD_NONE for RAW Bayer capture |
| 738 | * and FIELD_INTERLACED for other interfaces |
| 739 | */ |
| 740 | field = vpif_get_default_field(&vpif_params->iface); |
| 741 | } else if (field == V4L2_FIELD_ANY) |
| 742 | /* unsupported field. Use default */ |
| 743 | field = vpif_get_default_field(&vpif_params->iface); |
| 744 | |
| 745 | /* validate the hpitch */ |
| 746 | hpitch = pixfmt->bytesperline; |
| 747 | if (hpitch < vpif_params->std_info.width) { |
| 748 | if (!update) { |
| 749 | vpif_dbg(2, debug, "invalid hpitch\n"); |
| 750 | goto exit; |
| 751 | } |
| 752 | hpitch = vpif_params->std_info.width; |
| 753 | } |
| 754 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 755 | sizeimage = pixfmt->sizeimage; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 756 | |
| 757 | vpitch = sizeimage / (hpitch * 2); |
| 758 | |
| 759 | /* validate the vpitch */ |
| 760 | if (vpitch < vpif_params->std_info.height) { |
| 761 | if (!update) { |
| 762 | vpif_dbg(2, debug, "Invalid vpitch\n"); |
| 763 | goto exit; |
| 764 | } |
| 765 | vpitch = vpif_params->std_info.height; |
| 766 | } |
| 767 | |
| 768 | /* Check for 8 byte alignment */ |
| 769 | if (!ALIGN(hpitch, 8)) { |
| 770 | if (!update) { |
| 771 | vpif_dbg(2, debug, "invalid pitch alignment\n"); |
| 772 | goto exit; |
| 773 | } |
| 774 | /* adjust to next 8 byte boundary */ |
| 775 | hpitch = (((hpitch + 7) / 8) * 8); |
| 776 | } |
| 777 | /* if update is set, modify the bytesperline and sizeimage */ |
| 778 | if (update) { |
| 779 | pixfmt->bytesperline = hpitch; |
| 780 | pixfmt->sizeimage = hpitch * vpitch * 2; |
| 781 | } |
| 782 | /** |
| 783 | * Image width and height is always based on current standard width and |
| 784 | * height |
| 785 | */ |
| 786 | pixfmt->width = common->fmt.fmt.pix.width; |
| 787 | pixfmt->height = common->fmt.fmt.pix.height; |
| 788 | return 0; |
| 789 | exit: |
| 790 | return ret; |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * vpif_config_addr() - function to configure buffer address in vpif |
| 795 | * @ch - channel ptr |
| 796 | * @muxmode - channel mux mode |
| 797 | */ |
| 798 | static void vpif_config_addr(struct channel_obj *ch, int muxmode) |
| 799 | { |
| 800 | struct common_obj *common; |
| 801 | |
| 802 | vpif_dbg(2, debug, "vpif_config_addr\n"); |
| 803 | |
| 804 | common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 805 | |
| 806 | if (VPIF_CHANNEL1_VIDEO == ch->channel_id) |
| 807 | common->set_addr = ch1_set_videobuf_addr; |
| 808 | else if (2 == muxmode) |
| 809 | common->set_addr = ch0_set_videobuf_addr_yc_nmux; |
| 810 | else |
| 811 | common->set_addr = ch0_set_videobuf_addr; |
| 812 | } |
| 813 | |
| 814 | /** |
Dror Cohen | 6f45b1b | 2012-07-10 05:43:22 -0300 | [diff] [blame] | 815 | * vpif_mmap : It is used to map kernel space buffers into user spaces |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 816 | * @filep: file pointer |
| 817 | * @vma: ptr to vm_area_struct |
| 818 | */ |
| 819 | static int vpif_mmap(struct file *filep, struct vm_area_struct *vma) |
| 820 | { |
| 821 | /* Get the channel object and file handle object */ |
| 822 | struct vpif_fh *fh = filep->private_data; |
| 823 | struct channel_obj *ch = fh->channel; |
| 824 | struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]); |
Hans Verkuil | 7224679 | 2012-07-31 03:48:31 -0300 | [diff] [blame] | 825 | int ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 826 | |
| 827 | vpif_dbg(2, debug, "vpif_mmap\n"); |
| 828 | |
Hans Verkuil | 7224679 | 2012-07-31 03:48:31 -0300 | [diff] [blame] | 829 | if (mutex_lock_interruptible(&common->lock)) |
| 830 | return -ERESTARTSYS; |
| 831 | ret = vb2_mmap(&common->buffer_queue, vma); |
| 832 | mutex_unlock(&common->lock); |
| 833 | return ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /** |
| 837 | * vpif_poll: It is used for select/poll system call |
| 838 | * @filep: file pointer |
| 839 | * @wait: poll table to wait |
| 840 | */ |
| 841 | static unsigned int vpif_poll(struct file *filep, poll_table * wait) |
| 842 | { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 843 | struct vpif_fh *fh = filep->private_data; |
| 844 | struct channel_obj *channel = fh->channel; |
| 845 | struct common_obj *common = &(channel->common[VPIF_VIDEO_INDEX]); |
Hans Verkuil | 7224679 | 2012-07-31 03:48:31 -0300 | [diff] [blame] | 846 | unsigned int res = 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 847 | |
| 848 | vpif_dbg(2, debug, "vpif_poll\n"); |
| 849 | |
Hans Verkuil | 7224679 | 2012-07-31 03:48:31 -0300 | [diff] [blame] | 850 | if (common->started) { |
| 851 | mutex_lock(&common->lock); |
| 852 | res = vb2_poll(&common->buffer_queue, filep, wait); |
| 853 | mutex_unlock(&common->lock); |
| 854 | } |
| 855 | return res; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /** |
| 859 | * vpif_open : vpif open handler |
| 860 | * @filep: file ptr |
| 861 | * |
| 862 | * It creates object of file handle structure and stores it in private_data |
| 863 | * member of filepointer |
| 864 | */ |
| 865 | static int vpif_open(struct file *filep) |
| 866 | { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 867 | struct video_device *vdev = video_devdata(filep); |
| 868 | struct common_obj *common; |
| 869 | struct video_obj *vid_ch; |
| 870 | struct channel_obj *ch; |
| 871 | struct vpif_fh *fh; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 872 | |
| 873 | vpif_dbg(2, debug, "vpif_open\n"); |
| 874 | |
| 875 | ch = video_get_drvdata(vdev); |
| 876 | |
| 877 | vid_ch = &ch->video; |
| 878 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 879 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 880 | /* Allocate memory for the file handle object */ |
Mats Randgaard | 1f8766b | 2010-08-30 10:30:37 -0300 | [diff] [blame] | 881 | fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 882 | if (NULL == fh) { |
| 883 | vpif_err("unable to allocate memory for file handle object\n"); |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 884 | return -ENOMEM; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 885 | } |
| 886 | |
Hans Verkuil | 7224679 | 2012-07-31 03:48:31 -0300 | [diff] [blame] | 887 | if (mutex_lock_interruptible(&common->lock)) { |
| 888 | kfree(fh); |
| 889 | return -ERESTARTSYS; |
| 890 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 891 | /* store pointer to fh in private_data member of filep */ |
| 892 | filep->private_data = fh; |
| 893 | fh->channel = ch; |
| 894 | fh->initialized = 0; |
| 895 | /* If decoder is not initialized. initialize it */ |
| 896 | if (!ch->initialized) { |
| 897 | fh->initialized = 1; |
| 898 | ch->initialized = 1; |
| 899 | memset(&(ch->vpifparams), 0, sizeof(struct vpif_params)); |
| 900 | } |
| 901 | /* Increment channel usrs counter */ |
| 902 | ch->usrs++; |
| 903 | /* Set io_allowed member to false */ |
| 904 | fh->io_allowed[VPIF_VIDEO_INDEX] = 0; |
| 905 | /* Initialize priority of this instance to default priority */ |
| 906 | fh->prio = V4L2_PRIORITY_UNSET; |
| 907 | v4l2_prio_open(&ch->prio, &fh->prio); |
Hans Verkuil | 7224679 | 2012-07-31 03:48:31 -0300 | [diff] [blame] | 908 | mutex_unlock(&common->lock); |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 909 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | /** |
| 913 | * vpif_release : function to clean up file close |
| 914 | * @filep: file pointer |
| 915 | * |
Dror Cohen | 6f45b1b | 2012-07-10 05:43:22 -0300 | [diff] [blame] | 916 | * This function deletes buffer queue, frees the buffers and the vpif file |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 917 | * handle |
| 918 | */ |
| 919 | static int vpif_release(struct file *filep) |
| 920 | { |
| 921 | struct vpif_fh *fh = filep->private_data; |
| 922 | struct channel_obj *ch = fh->channel; |
| 923 | struct common_obj *common; |
| 924 | |
| 925 | vpif_dbg(2, debug, "vpif_release\n"); |
| 926 | |
| 927 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 928 | |
Hans Verkuil | 7224679 | 2012-07-31 03:48:31 -0300 | [diff] [blame] | 929 | mutex_lock(&common->lock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 930 | /* if this instance is doing IO */ |
| 931 | if (fh->io_allowed[VPIF_VIDEO_INDEX]) { |
| 932 | /* Reset io_usrs member of channel object */ |
| 933 | common->io_usrs = 0; |
| 934 | /* Disable channel as per its device type and channel id */ |
| 935 | if (VPIF_CHANNEL0_VIDEO == ch->channel_id) { |
| 936 | enable_channel0(0); |
| 937 | channel0_intr_enable(0); |
| 938 | } |
| 939 | if ((VPIF_CHANNEL1_VIDEO == ch->channel_id) || |
| 940 | (2 == common->started)) { |
| 941 | enable_channel1(0); |
| 942 | channel1_intr_enable(0); |
| 943 | } |
| 944 | common->started = 0; |
| 945 | /* Free buffers allocated */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 946 | vb2_queue_release(&common->buffer_queue); |
| 947 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | /* Decrement channel usrs counter */ |
| 951 | ch->usrs--; |
| 952 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 953 | /* Close the priority */ |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 954 | v4l2_prio_close(&ch->prio, fh->prio); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 955 | |
| 956 | if (fh->initialized) |
| 957 | ch->initialized = 0; |
| 958 | |
Hans Verkuil | 7224679 | 2012-07-31 03:48:31 -0300 | [diff] [blame] | 959 | mutex_unlock(&common->lock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 960 | filep->private_data = NULL; |
| 961 | kfree(fh); |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | /** |
| 966 | * vpif_reqbufs() - request buffer handler |
| 967 | * @file: file ptr |
| 968 | * @priv: file handle |
| 969 | * @reqbuf: request buffer structure ptr |
| 970 | */ |
| 971 | static int vpif_reqbufs(struct file *file, void *priv, |
| 972 | struct v4l2_requestbuffers *reqbuf) |
| 973 | { |
| 974 | struct vpif_fh *fh = priv; |
| 975 | struct channel_obj *ch = fh->channel; |
| 976 | struct common_obj *common; |
| 977 | u8 index = 0; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 978 | struct vb2_queue *q; |
Lad, Prabhakar | b4a711e7 | 2012-10-03 10:01:07 -0300 | [diff] [blame^] | 979 | int ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 980 | |
| 981 | vpif_dbg(2, debug, "vpif_reqbufs\n"); |
| 982 | |
| 983 | /** |
| 984 | * This file handle has not initialized the channel, |
| 985 | * It is not allowed to do settings |
| 986 | */ |
| 987 | if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) |
| 988 | || (VPIF_CHANNEL1_VIDEO == ch->channel_id)) { |
| 989 | if (!fh->initialized) { |
| 990 | vpif_dbg(1, debug, "Channel Busy\n"); |
| 991 | return -EBUSY; |
| 992 | } |
| 993 | } |
| 994 | |
Manjunath Hadli | 764af39 | 2012-04-13 04:49:34 -0300 | [diff] [blame] | 995 | if (V4L2_BUF_TYPE_VIDEO_CAPTURE != reqbuf->type || !vpif_dev) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 996 | return -EINVAL; |
| 997 | |
| 998 | index = VPIF_VIDEO_INDEX; |
| 999 | |
| 1000 | common = &ch->common[index]; |
| 1001 | |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 1002 | if (0 != common->io_usrs) |
| 1003 | return -EBUSY; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1004 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1005 | /* Initialize videobuf2 queue as per the buffer type */ |
| 1006 | common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev); |
| 1007 | if (!common->alloc_ctx) { |
| 1008 | vpif_err("Failed to get the context\n"); |
| 1009 | return -EINVAL; |
| 1010 | } |
| 1011 | q = &common->buffer_queue; |
| 1012 | q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1013 | q->io_modes = VB2_MMAP | VB2_USERPTR; |
| 1014 | q->drv_priv = fh; |
| 1015 | q->ops = &video_qops; |
| 1016 | q->mem_ops = &vb2_dma_contig_memops; |
| 1017 | q->buf_struct_size = sizeof(struct vpif_cap_buffer); |
| 1018 | |
Lad, Prabhakar | b4a711e7 | 2012-10-03 10:01:07 -0300 | [diff] [blame^] | 1019 | ret = vb2_queue_init(q); |
| 1020 | if (ret) { |
| 1021 | vpif_err("vpif_capture: vb2_queue_init() failed\n"); |
| 1022 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
| 1023 | return ret; |
| 1024 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1025 | /* Set io allowed member of file handle to TRUE */ |
| 1026 | fh->io_allowed[index] = 1; |
| 1027 | /* Increment io usrs member of channel object to 1 */ |
| 1028 | common->io_usrs = 1; |
| 1029 | /* Store type of memory requested in channel object */ |
| 1030 | common->memory = reqbuf->memory; |
| 1031 | INIT_LIST_HEAD(&common->dma_queue); |
| 1032 | |
| 1033 | /* Allocate buffers */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1034 | return vb2_reqbufs(&common->buffer_queue, reqbuf); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * vpif_querybuf() - query buffer handler |
| 1039 | * @file: file ptr |
| 1040 | * @priv: file handle |
| 1041 | * @buf: v4l2 buffer structure ptr |
| 1042 | */ |
| 1043 | static int vpif_querybuf(struct file *file, void *priv, |
| 1044 | struct v4l2_buffer *buf) |
| 1045 | { |
| 1046 | struct vpif_fh *fh = priv; |
| 1047 | struct channel_obj *ch = fh->channel; |
| 1048 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1049 | |
| 1050 | vpif_dbg(2, debug, "vpif_querybuf\n"); |
| 1051 | |
| 1052 | if (common->fmt.type != buf->type) |
| 1053 | return -EINVAL; |
| 1054 | |
| 1055 | if (common->memory != V4L2_MEMORY_MMAP) { |
| 1056 | vpif_dbg(1, debug, "Invalid memory\n"); |
| 1057 | return -EINVAL; |
| 1058 | } |
| 1059 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1060 | return vb2_querybuf(&common->buffer_queue, buf); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | /** |
| 1064 | * vpif_qbuf() - query buffer handler |
| 1065 | * @file: file ptr |
| 1066 | * @priv: file handle |
| 1067 | * @buf: v4l2 buffer structure ptr |
| 1068 | */ |
| 1069 | static int vpif_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) |
| 1070 | { |
| 1071 | |
| 1072 | struct vpif_fh *fh = priv; |
| 1073 | struct channel_obj *ch = fh->channel; |
| 1074 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1075 | struct v4l2_buffer tbuf = *buf; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1076 | |
| 1077 | vpif_dbg(2, debug, "vpif_qbuf\n"); |
| 1078 | |
| 1079 | if (common->fmt.type != tbuf.type) { |
| 1080 | vpif_err("invalid buffer type\n"); |
| 1081 | return -EINVAL; |
| 1082 | } |
| 1083 | |
| 1084 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1085 | vpif_err("fh io not allowed\n"); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1086 | return -EACCES; |
| 1087 | } |
| 1088 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1089 | return vb2_qbuf(&common->buffer_queue, buf); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * vpif_dqbuf() - query buffer handler |
| 1094 | * @file: file ptr |
| 1095 | * @priv: file handle |
| 1096 | * @buf: v4l2 buffer structure ptr |
| 1097 | */ |
| 1098 | static int vpif_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) |
| 1099 | { |
| 1100 | struct vpif_fh *fh = priv; |
| 1101 | struct channel_obj *ch = fh->channel; |
| 1102 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1103 | |
| 1104 | vpif_dbg(2, debug, "vpif_dqbuf\n"); |
| 1105 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1106 | return vb2_dqbuf(&common->buffer_queue, buf, |
| 1107 | (file->f_flags & O_NONBLOCK)); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /** |
| 1111 | * vpif_streamon() - streamon handler |
| 1112 | * @file: file ptr |
| 1113 | * @priv: file handle |
| 1114 | * @buftype: v4l2 buffer type |
| 1115 | */ |
| 1116 | static int vpif_streamon(struct file *file, void *priv, |
| 1117 | enum v4l2_buf_type buftype) |
| 1118 | { |
| 1119 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1120 | struct vpif_fh *fh = priv; |
| 1121 | struct channel_obj *ch = fh->channel; |
| 1122 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1123 | struct channel_obj *oth_ch = vpif_obj.dev[!ch->channel_id]; |
| 1124 | struct vpif_params *vpif; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1125 | int ret = 0; |
| 1126 | |
| 1127 | vpif_dbg(2, debug, "vpif_streamon\n"); |
| 1128 | |
| 1129 | vpif = &ch->vpifparams; |
| 1130 | |
| 1131 | if (buftype != V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 1132 | vpif_dbg(1, debug, "buffer type not supported\n"); |
| 1133 | return -EINVAL; |
| 1134 | } |
| 1135 | |
| 1136 | /* If file handle is not allowed IO, return error */ |
| 1137 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { |
| 1138 | vpif_dbg(1, debug, "io not allowed\n"); |
| 1139 | return -EACCES; |
| 1140 | } |
| 1141 | |
| 1142 | /* If Streaming is already started, return error */ |
| 1143 | if (common->started) { |
| 1144 | vpif_dbg(1, debug, "channel->started\n"); |
| 1145 | return -EBUSY; |
| 1146 | } |
| 1147 | |
| 1148 | if ((ch->channel_id == VPIF_CHANNEL0_VIDEO && |
| 1149 | oth_ch->common[VPIF_VIDEO_INDEX].started && |
| 1150 | vpif->std_info.ycmux_mode == 0) || |
| 1151 | ((ch->channel_id == VPIF_CHANNEL1_VIDEO) && |
| 1152 | (2 == oth_ch->common[VPIF_VIDEO_INDEX].started))) { |
| 1153 | vpif_dbg(1, debug, "other channel is being used\n"); |
| 1154 | return -EBUSY; |
| 1155 | } |
| 1156 | |
| 1157 | ret = vpif_check_format(ch, &common->fmt.fmt.pix, 0); |
| 1158 | if (ret) |
| 1159 | return ret; |
| 1160 | |
| 1161 | /* Enable streamon on the sub device */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1162 | ret = v4l2_subdev_call(ch->sd, video, s_stream, 1); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1163 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1164 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1165 | vpif_dbg(1, debug, "stream on failed in subdev\n"); |
| 1166 | return ret; |
| 1167 | } |
| 1168 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1169 | /* Call vb2_streamon to start streaming in videobuf2 */ |
| 1170 | ret = vb2_streamon(&common->buffer_queue, buftype); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1171 | if (ret) { |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1172 | vpif_dbg(1, debug, "vb2_streamon\n"); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1173 | return ret; |
| 1174 | } |
| 1175 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1176 | return ret; |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * vpif_streamoff() - streamoff handler |
| 1181 | * @file: file ptr |
| 1182 | * @priv: file handle |
| 1183 | * @buftype: v4l2 buffer type |
| 1184 | */ |
| 1185 | static int vpif_streamoff(struct file *file, void *priv, |
| 1186 | enum v4l2_buf_type buftype) |
| 1187 | { |
| 1188 | |
| 1189 | struct vpif_fh *fh = priv; |
| 1190 | struct channel_obj *ch = fh->channel; |
| 1191 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1192 | int ret; |
| 1193 | |
| 1194 | vpif_dbg(2, debug, "vpif_streamoff\n"); |
| 1195 | |
| 1196 | if (buftype != V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
| 1197 | vpif_dbg(1, debug, "buffer type not supported\n"); |
| 1198 | return -EINVAL; |
| 1199 | } |
| 1200 | |
| 1201 | /* If io is allowed for this file handle, return error */ |
| 1202 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { |
| 1203 | vpif_dbg(1, debug, "io not allowed\n"); |
| 1204 | return -EACCES; |
| 1205 | } |
| 1206 | |
| 1207 | /* If streaming is not started, return error */ |
| 1208 | if (!common->started) { |
| 1209 | vpif_dbg(1, debug, "channel->started\n"); |
| 1210 | return -EINVAL; |
| 1211 | } |
| 1212 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1213 | /* disable channel */ |
| 1214 | if (VPIF_CHANNEL0_VIDEO == ch->channel_id) { |
| 1215 | enable_channel0(0); |
| 1216 | channel0_intr_enable(0); |
| 1217 | } else { |
| 1218 | enable_channel1(0); |
| 1219 | channel1_intr_enable(0); |
| 1220 | } |
| 1221 | |
| 1222 | common->started = 0; |
| 1223 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1224 | ret = v4l2_subdev_call(ch->sd, video, s_stream, 0); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1225 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1226 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1227 | vpif_dbg(1, debug, "stream off failed in subdev\n"); |
| 1228 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 1229 | return vb2_streamoff(&common->buffer_queue, buftype); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | /** |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1233 | * vpif_input_to_subdev() - Maps input to sub device |
| 1234 | * @vpif_cfg - global config ptr |
| 1235 | * @chan_cfg - channel config ptr |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1236 | * @input_index - Given input index from application |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1237 | * |
| 1238 | * lookup the sub device information for a given input index. |
| 1239 | * we report all the inputs to application. inputs table also |
| 1240 | * has sub device name for the each input |
| 1241 | */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1242 | static int vpif_input_to_subdev( |
| 1243 | struct vpif_capture_config *vpif_cfg, |
| 1244 | struct vpif_capture_chan_config *chan_cfg, |
| 1245 | int input_index) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1246 | { |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1247 | struct vpif_subdev_info *subdev_info; |
| 1248 | const char *subdev_name; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1249 | int i; |
| 1250 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1251 | vpif_dbg(2, debug, "vpif_input_to_subdev\n"); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1252 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1253 | subdev_name = chan_cfg->inputs[input_index].subdev_name; |
| 1254 | if (subdev_name == NULL) |
| 1255 | return -1; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1256 | |
| 1257 | /* loop through the sub device list to get the sub device info */ |
| 1258 | for (i = 0; i < vpif_cfg->subdev_count; i++) { |
| 1259 | subdev_info = &vpif_cfg->subdev_info[i]; |
| 1260 | if (!strcmp(subdev_info->name, subdev_name)) |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1261 | return i; |
| 1262 | } |
| 1263 | return -1; |
| 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * vpif_set_input() - Select an input |
| 1268 | * @vpif_cfg - global config ptr |
| 1269 | * @ch - channel |
| 1270 | * @_index - Given input index from application |
| 1271 | * |
| 1272 | * Select the given input. |
| 1273 | */ |
| 1274 | static int vpif_set_input( |
| 1275 | struct vpif_capture_config *vpif_cfg, |
| 1276 | struct channel_obj *ch, |
| 1277 | int index) |
| 1278 | { |
| 1279 | struct vpif_capture_chan_config *chan_cfg = |
| 1280 | &vpif_cfg->chan_config[ch->channel_id]; |
| 1281 | struct vpif_subdev_info *subdev_info = NULL; |
| 1282 | struct v4l2_subdev *sd = NULL; |
| 1283 | u32 input = 0, output = 0; |
| 1284 | int sd_index; |
| 1285 | int ret; |
| 1286 | |
| 1287 | sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index); |
| 1288 | if (sd_index >= 0) { |
| 1289 | sd = vpif_obj.sd[sd_index]; |
| 1290 | subdev_info = &vpif_cfg->subdev_info[sd_index]; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1291 | } |
| 1292 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1293 | /* first setup input path from sub device to vpif */ |
| 1294 | if (sd && vpif_cfg->setup_input_path) { |
| 1295 | ret = vpif_cfg->setup_input_path(ch->channel_id, |
| 1296 | subdev_info->name); |
| 1297 | if (ret < 0) { |
| 1298 | vpif_dbg(1, debug, "couldn't setup input path for the" \ |
| 1299 | " sub device %s, for input index %d\n", |
| 1300 | subdev_info->name, index); |
| 1301 | return ret; |
| 1302 | } |
| 1303 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1304 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1305 | if (sd) { |
| 1306 | input = chan_cfg->inputs[index].input_route; |
| 1307 | output = chan_cfg->inputs[index].output_route; |
| 1308 | ret = v4l2_subdev_call(sd, video, s_routing, |
| 1309 | input, output, 0); |
| 1310 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
| 1311 | vpif_dbg(1, debug, "Failed to set input\n"); |
| 1312 | return ret; |
| 1313 | } |
| 1314 | } |
| 1315 | ch->input_idx = index; |
| 1316 | ch->sd = sd; |
| 1317 | /* copy interface parameters to vpif */ |
Hans Verkuil | 0d4f35f | 2012-09-20 09:06:32 -0300 | [diff] [blame] | 1318 | ch->vpifparams.iface = chan_cfg->vpif_if; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1319 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1320 | /* update tvnorms from the sub device input info */ |
| 1321 | ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std; |
| 1322 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * vpif_querystd() - querystd handler |
| 1327 | * @file: file ptr |
| 1328 | * @priv: file handle |
| 1329 | * @std_id: ptr to std id |
| 1330 | * |
| 1331 | * This function is called to detect standard at the selected input |
| 1332 | */ |
| 1333 | static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id) |
| 1334 | { |
| 1335 | struct vpif_fh *fh = priv; |
| 1336 | struct channel_obj *ch = fh->channel; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1337 | int ret = 0; |
| 1338 | |
| 1339 | vpif_dbg(2, debug, "vpif_querystd\n"); |
| 1340 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1341 | /* Call querystd function of decoder device */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1342 | ret = v4l2_subdev_call(ch->sd, video, querystd, std_id); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1343 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1344 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 1345 | return -ENODATA; |
| 1346 | if (ret) { |
| 1347 | vpif_dbg(1, debug, "Failed to query standard for sub devices\n"); |
| 1348 | return ret; |
| 1349 | } |
| 1350 | |
| 1351 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /** |
| 1355 | * vpif_g_std() - get STD handler |
| 1356 | * @file: file ptr |
| 1357 | * @priv: file handle |
| 1358 | * @std_id: ptr to std id |
| 1359 | */ |
| 1360 | static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std) |
| 1361 | { |
| 1362 | struct vpif_fh *fh = priv; |
| 1363 | struct channel_obj *ch = fh->channel; |
| 1364 | |
| 1365 | vpif_dbg(2, debug, "vpif_g_std\n"); |
| 1366 | |
| 1367 | *std = ch->video.stdid; |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
| 1371 | /** |
| 1372 | * vpif_s_std() - set STD handler |
| 1373 | * @file: file ptr |
| 1374 | * @priv: file handle |
| 1375 | * @std_id: ptr to std id |
| 1376 | */ |
| 1377 | static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id) |
| 1378 | { |
| 1379 | struct vpif_fh *fh = priv; |
| 1380 | struct channel_obj *ch = fh->channel; |
| 1381 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1382 | int ret = 0; |
| 1383 | |
| 1384 | vpif_dbg(2, debug, "vpif_s_std\n"); |
| 1385 | |
| 1386 | if (common->started) { |
| 1387 | vpif_err("streaming in progress\n"); |
| 1388 | return -EBUSY; |
| 1389 | } |
| 1390 | |
| 1391 | if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) || |
| 1392 | (VPIF_CHANNEL1_VIDEO == ch->channel_id)) { |
| 1393 | if (!fh->initialized) { |
| 1394 | vpif_dbg(1, debug, "Channel Busy\n"); |
| 1395 | return -EBUSY; |
| 1396 | } |
| 1397 | } |
| 1398 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 1399 | ret = v4l2_prio_check(&ch->prio, fh->prio); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1400 | if (0 != ret) |
| 1401 | return ret; |
| 1402 | |
| 1403 | fh->initialized = 1; |
| 1404 | |
| 1405 | /* Call encoder subdevice function to set the standard */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1406 | ch->video.stdid = *std_id; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1407 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1408 | |
| 1409 | /* Get the information about the standard */ |
| 1410 | if (vpif_update_std_info(ch)) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1411 | vpif_err("Error getting the standard info\n"); |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 1412 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /* Configure the default format information */ |
| 1416 | vpif_config_format(ch); |
| 1417 | |
| 1418 | /* set standard in the sub device */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1419 | ret = v4l2_subdev_call(ch->sd, core, s_std, *std_id); |
| 1420 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1421 | vpif_dbg(1, debug, "Failed to set standard for sub devices\n"); |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1422 | return ret; |
| 1423 | } |
| 1424 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | /** |
| 1428 | * vpif_enum_input() - ENUMINPUT handler |
| 1429 | * @file: file ptr |
| 1430 | * @priv: file handle |
| 1431 | * @input: ptr to input structure |
| 1432 | */ |
| 1433 | static int vpif_enum_input(struct file *file, void *priv, |
| 1434 | struct v4l2_input *input) |
| 1435 | { |
| 1436 | |
| 1437 | struct vpif_capture_config *config = vpif_dev->platform_data; |
| 1438 | struct vpif_capture_chan_config *chan_cfg; |
| 1439 | struct vpif_fh *fh = priv; |
| 1440 | struct channel_obj *ch = fh->channel; |
| 1441 | |
| 1442 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1443 | |
| 1444 | if (input->index >= chan_cfg->input_count) { |
| 1445 | vpif_dbg(1, debug, "Invalid input index\n"); |
| 1446 | return -EINVAL; |
| 1447 | } |
| 1448 | |
| 1449 | memcpy(input, &chan_cfg->inputs[input->index].input, |
| 1450 | sizeof(*input)); |
| 1451 | return 0; |
| 1452 | } |
| 1453 | |
| 1454 | /** |
| 1455 | * vpif_g_input() - Get INPUT handler |
| 1456 | * @file: file ptr |
| 1457 | * @priv: file handle |
| 1458 | * @index: ptr to input index |
| 1459 | */ |
| 1460 | static int vpif_g_input(struct file *file, void *priv, unsigned int *index) |
| 1461 | { |
| 1462 | struct vpif_fh *fh = priv; |
| 1463 | struct channel_obj *ch = fh->channel; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1464 | |
Hans Verkuil | 6f47c6c | 2012-09-20 09:06:22 -0300 | [diff] [blame] | 1465 | *index = ch->input_idx; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1466 | return 0; |
| 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * vpif_s_input() - Set INPUT handler |
| 1471 | * @file: file ptr |
| 1472 | * @priv: file handle |
| 1473 | * @index: input index |
| 1474 | */ |
| 1475 | static int vpif_s_input(struct file *file, void *priv, unsigned int index) |
| 1476 | { |
| 1477 | struct vpif_capture_config *config = vpif_dev->platform_data; |
| 1478 | struct vpif_capture_chan_config *chan_cfg; |
| 1479 | struct vpif_fh *fh = priv; |
| 1480 | struct channel_obj *ch = fh->channel; |
| 1481 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1482 | int ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1483 | |
| 1484 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1485 | |
Hans Verkuil | 7aaad13 | 2012-09-20 09:06:25 -0300 | [diff] [blame] | 1486 | if (index >= chan_cfg->input_count) |
| 1487 | return -EINVAL; |
| 1488 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1489 | if (common->started) { |
| 1490 | vpif_err("Streaming in progress\n"); |
| 1491 | return -EBUSY; |
| 1492 | } |
| 1493 | |
| 1494 | if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) || |
| 1495 | (VPIF_CHANNEL1_VIDEO == ch->channel_id)) { |
| 1496 | if (!fh->initialized) { |
| 1497 | vpif_dbg(1, debug, "Channel Busy\n"); |
| 1498 | return -EBUSY; |
| 1499 | } |
| 1500 | } |
| 1501 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 1502 | ret = v4l2_prio_check(&ch->prio, fh->prio); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1503 | if (0 != ret) |
| 1504 | return ret; |
| 1505 | |
| 1506 | fh->initialized = 1; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1507 | return vpif_set_input(config, ch, index); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * vpif_enum_fmt_vid_cap() - ENUM_FMT handler |
| 1512 | * @file: file ptr |
| 1513 | * @priv: file handle |
| 1514 | * @index: input index |
| 1515 | */ |
| 1516 | static int vpif_enum_fmt_vid_cap(struct file *file, void *priv, |
| 1517 | struct v4l2_fmtdesc *fmt) |
| 1518 | { |
| 1519 | struct vpif_fh *fh = priv; |
| 1520 | struct channel_obj *ch = fh->channel; |
| 1521 | |
| 1522 | if (fmt->index != 0) { |
| 1523 | vpif_dbg(1, debug, "Invalid format index\n"); |
| 1524 | return -EINVAL; |
| 1525 | } |
| 1526 | |
| 1527 | /* Fill in the information about format */ |
| 1528 | if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) { |
| 1529 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1530 | strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb"); |
| 1531 | fmt->pixelformat = V4L2_PIX_FMT_SBGGR8; |
| 1532 | } else { |
| 1533 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1534 | strcpy(fmt->description, "YCbCr4:2:2 YC Planar"); |
| 1535 | fmt->pixelformat = V4L2_PIX_FMT_YUV422P; |
| 1536 | } |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * vpif_try_fmt_vid_cap() - TRY_FMT handler |
| 1542 | * @file: file ptr |
| 1543 | * @priv: file handle |
| 1544 | * @fmt: ptr to v4l2 format structure |
| 1545 | */ |
| 1546 | static int vpif_try_fmt_vid_cap(struct file *file, void *priv, |
| 1547 | struct v4l2_format *fmt) |
| 1548 | { |
| 1549 | struct vpif_fh *fh = priv; |
| 1550 | struct channel_obj *ch = fh->channel; |
| 1551 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
| 1552 | |
| 1553 | return vpif_check_format(ch, pixfmt, 1); |
| 1554 | } |
| 1555 | |
| 1556 | |
| 1557 | /** |
| 1558 | * vpif_g_fmt_vid_cap() - Set INPUT handler |
| 1559 | * @file: file ptr |
| 1560 | * @priv: file handle |
| 1561 | * @fmt: ptr to v4l2 format structure |
| 1562 | */ |
| 1563 | static int vpif_g_fmt_vid_cap(struct file *file, void *priv, |
| 1564 | struct v4l2_format *fmt) |
| 1565 | { |
| 1566 | struct vpif_fh *fh = priv; |
| 1567 | struct channel_obj *ch = fh->channel; |
| 1568 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1569 | |
| 1570 | /* Check the validity of the buffer type */ |
| 1571 | if (common->fmt.type != fmt->type) |
| 1572 | return -EINVAL; |
| 1573 | |
| 1574 | /* Fill in the information about format */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1575 | *fmt = common->fmt; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1576 | return 0; |
| 1577 | } |
| 1578 | |
| 1579 | /** |
| 1580 | * vpif_s_fmt_vid_cap() - Set FMT handler |
| 1581 | * @file: file ptr |
| 1582 | * @priv: file handle |
| 1583 | * @fmt: ptr to v4l2 format structure |
| 1584 | */ |
| 1585 | static int vpif_s_fmt_vid_cap(struct file *file, void *priv, |
| 1586 | struct v4l2_format *fmt) |
| 1587 | { |
| 1588 | struct vpif_fh *fh = priv; |
| 1589 | struct channel_obj *ch = fh->channel; |
| 1590 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1591 | struct v4l2_pix_format *pixfmt; |
| 1592 | int ret = 0; |
| 1593 | |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 1594 | vpif_dbg(2, debug, "%s\n", __func__); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1595 | |
| 1596 | /* If streaming is started, return error */ |
| 1597 | if (common->started) { |
| 1598 | vpif_dbg(1, debug, "Streaming is started\n"); |
| 1599 | return -EBUSY; |
| 1600 | } |
| 1601 | |
| 1602 | if ((VPIF_CHANNEL0_VIDEO == ch->channel_id) || |
| 1603 | (VPIF_CHANNEL1_VIDEO == ch->channel_id)) { |
| 1604 | if (!fh->initialized) { |
| 1605 | vpif_dbg(1, debug, "Channel Busy\n"); |
| 1606 | return -EBUSY; |
| 1607 | } |
| 1608 | } |
| 1609 | |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 1610 | ret = v4l2_prio_check(&ch->prio, fh->prio); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1611 | if (0 != ret) |
| 1612 | return ret; |
| 1613 | |
| 1614 | fh->initialized = 1; |
| 1615 | |
| 1616 | pixfmt = &fmt->fmt.pix; |
| 1617 | /* Check for valid field format */ |
| 1618 | ret = vpif_check_format(ch, pixfmt, 0); |
| 1619 | |
| 1620 | if (ret) |
| 1621 | return ret; |
| 1622 | /* store the format in the channel object */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1623 | common->fmt = *fmt; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1624 | return 0; |
| 1625 | } |
| 1626 | |
| 1627 | /** |
| 1628 | * vpif_querycap() - QUERYCAP handler |
| 1629 | * @file: file ptr |
| 1630 | * @priv: file handle |
| 1631 | * @cap: ptr to v4l2_capability structure |
| 1632 | */ |
| 1633 | static int vpif_querycap(struct file *file, void *priv, |
| 1634 | struct v4l2_capability *cap) |
| 1635 | { |
| 1636 | struct vpif_capture_config *config = vpif_dev->platform_data; |
| 1637 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1638 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; |
| 1639 | strlcpy(cap->driver, "vpif capture", sizeof(cap->driver)); |
Manjunath Hadli | 0a63172 | 2012-04-13 04:44:00 -0300 | [diff] [blame] | 1640 | strlcpy(cap->bus_info, "VPIF Platform", sizeof(cap->bus_info)); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1641 | strlcpy(cap->card, config->card_name, sizeof(cap->card)); |
| 1642 | |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | /** |
| 1647 | * vpif_g_priority() - get priority handler |
| 1648 | * @file: file ptr |
| 1649 | * @priv: file handle |
| 1650 | * @prio: ptr to v4l2_priority structure |
| 1651 | */ |
| 1652 | static int vpif_g_priority(struct file *file, void *priv, |
| 1653 | enum v4l2_priority *prio) |
| 1654 | { |
| 1655 | struct vpif_fh *fh = priv; |
| 1656 | struct channel_obj *ch = fh->channel; |
| 1657 | |
| 1658 | *prio = v4l2_prio_max(&ch->prio); |
| 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
| 1663 | /** |
| 1664 | * vpif_s_priority() - set priority handler |
| 1665 | * @file: file ptr |
| 1666 | * @priv: file handle |
| 1667 | * @prio: ptr to v4l2_priority structure |
| 1668 | */ |
| 1669 | static int vpif_s_priority(struct file *file, void *priv, enum v4l2_priority p) |
| 1670 | { |
| 1671 | struct vpif_fh *fh = priv; |
| 1672 | struct channel_obj *ch = fh->channel; |
| 1673 | |
| 1674 | return v4l2_prio_change(&ch->prio, &fh->prio, p); |
| 1675 | } |
| 1676 | |
| 1677 | /** |
| 1678 | * vpif_cropcap() - cropcap handler |
| 1679 | * @file: file ptr |
| 1680 | * @priv: file handle |
| 1681 | * @crop: ptr to v4l2_cropcap structure |
| 1682 | */ |
| 1683 | static int vpif_cropcap(struct file *file, void *priv, |
| 1684 | struct v4l2_cropcap *crop) |
| 1685 | { |
| 1686 | struct vpif_fh *fh = priv; |
| 1687 | struct channel_obj *ch = fh->channel; |
| 1688 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1689 | |
| 1690 | if (V4L2_BUF_TYPE_VIDEO_CAPTURE != crop->type) |
| 1691 | return -EINVAL; |
| 1692 | |
| 1693 | crop->bounds.left = 0; |
| 1694 | crop->bounds.top = 0; |
| 1695 | crop->bounds.height = common->height; |
| 1696 | crop->bounds.width = common->width; |
| 1697 | crop->defrect = crop->bounds; |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1701 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1702 | * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1703 | * @file: file ptr |
| 1704 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1705 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1706 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1707 | static int |
| 1708 | vpif_enum_dv_timings(struct file *file, void *priv, |
| 1709 | struct v4l2_enum_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1710 | { |
| 1711 | struct vpif_fh *fh = priv; |
| 1712 | struct channel_obj *ch = fh->channel; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1713 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1714 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1715 | ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings); |
| 1716 | if (ret == -ENOIOCTLCMD && ret == -ENODEV) |
| 1717 | return -EINVAL; |
| 1718 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1722 | * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1723 | * @file: file ptr |
| 1724 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1725 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1726 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1727 | static int |
| 1728 | vpif_query_dv_timings(struct file *file, void *priv, |
| 1729 | struct v4l2_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1730 | { |
| 1731 | struct vpif_fh *fh = priv; |
| 1732 | struct channel_obj *ch = fh->channel; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1733 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1734 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1735 | ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings); |
| 1736 | if (ret == -ENOIOCTLCMD && ret == -ENODEV) |
| 1737 | return -ENODATA; |
| 1738 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1739 | } |
| 1740 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1741 | /** |
| 1742 | * vpif_s_dv_timings() - S_DV_TIMINGS handler |
| 1743 | * @file: file ptr |
| 1744 | * @priv: file handle |
| 1745 | * @timings: digital video timings |
| 1746 | */ |
| 1747 | static int vpif_s_dv_timings(struct file *file, void *priv, |
| 1748 | struct v4l2_dv_timings *timings) |
| 1749 | { |
| 1750 | struct vpif_fh *fh = priv; |
| 1751 | struct channel_obj *ch = fh->channel; |
| 1752 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 1753 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 1754 | struct video_obj *vid_ch = &ch->video; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1755 | struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1756 | int ret; |
| 1757 | |
| 1758 | if (timings->type != V4L2_DV_BT_656_1120) { |
| 1759 | vpif_dbg(2, debug, "Timing type not defined\n"); |
| 1760 | return -EINVAL; |
| 1761 | } |
| 1762 | |
| 1763 | /* Configure subdevice timings, if any */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1764 | ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings); |
| 1765 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 1766 | ret = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1767 | if (ret < 0) { |
| 1768 | vpif_dbg(2, debug, "Error setting custom DV timings\n"); |
| 1769 | return ret; |
| 1770 | } |
| 1771 | |
| 1772 | if (!(timings->bt.width && timings->bt.height && |
| 1773 | (timings->bt.hbackporch || |
| 1774 | timings->bt.hfrontporch || |
| 1775 | timings->bt.hsync) && |
| 1776 | timings->bt.vfrontporch && |
| 1777 | (timings->bt.vbackporch || |
| 1778 | timings->bt.vsync))) { |
| 1779 | vpif_dbg(2, debug, "Timings for width, height, " |
| 1780 | "horizontal back porch, horizontal sync, " |
| 1781 | "horizontal front porch, vertical back porch, " |
| 1782 | "vertical sync and vertical back porch " |
| 1783 | "must be defined\n"); |
| 1784 | return -EINVAL; |
| 1785 | } |
| 1786 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1787 | vid_ch->dv_timings = *timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1788 | |
| 1789 | /* Configure video port timings */ |
| 1790 | |
| 1791 | std_info->eav2sav = bt->hbackporch + bt->hfrontporch + |
| 1792 | bt->hsync - 8; |
| 1793 | std_info->sav2eav = bt->width; |
| 1794 | |
| 1795 | std_info->l1 = 1; |
| 1796 | std_info->l3 = bt->vsync + bt->vbackporch + 1; |
| 1797 | |
| 1798 | if (bt->interlaced) { |
| 1799 | if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) { |
| 1800 | std_info->vsize = bt->height * 2 + |
| 1801 | bt->vfrontporch + bt->vsync + bt->vbackporch + |
| 1802 | bt->il_vfrontporch + bt->il_vsync + |
| 1803 | bt->il_vbackporch; |
| 1804 | std_info->l5 = std_info->vsize/2 - |
| 1805 | (bt->vfrontporch - 1); |
| 1806 | std_info->l7 = std_info->vsize/2 + 1; |
| 1807 | std_info->l9 = std_info->l7 + bt->il_vsync + |
| 1808 | bt->il_vbackporch + 1; |
| 1809 | std_info->l11 = std_info->vsize - |
| 1810 | (bt->il_vfrontporch - 1); |
| 1811 | } else { |
| 1812 | vpif_dbg(2, debug, "Required timing values for " |
| 1813 | "interlaced BT format missing\n"); |
| 1814 | return -EINVAL; |
| 1815 | } |
| 1816 | } else { |
| 1817 | std_info->vsize = bt->height + bt->vfrontporch + |
| 1818 | bt->vsync + bt->vbackporch; |
| 1819 | std_info->l5 = std_info->vsize - (bt->vfrontporch - 1); |
| 1820 | } |
| 1821 | strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME); |
| 1822 | std_info->width = bt->width; |
| 1823 | std_info->height = bt->height; |
| 1824 | std_info->frm_fmt = bt->interlaced ? 0 : 1; |
| 1825 | std_info->ycmux_mode = 0; |
| 1826 | std_info->capture_format = 0; |
| 1827 | std_info->vbi_supported = 0; |
| 1828 | std_info->hd_sd = 1; |
| 1829 | std_info->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1830 | |
| 1831 | vid_ch->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1832 | return 0; |
| 1833 | } |
| 1834 | |
| 1835 | /** |
| 1836 | * vpif_g_dv_timings() - G_DV_TIMINGS handler |
| 1837 | * @file: file ptr |
| 1838 | * @priv: file handle |
| 1839 | * @timings: digital video timings |
| 1840 | */ |
| 1841 | static int vpif_g_dv_timings(struct file *file, void *priv, |
| 1842 | struct v4l2_dv_timings *timings) |
| 1843 | { |
| 1844 | struct vpif_fh *fh = priv; |
| 1845 | struct channel_obj *ch = fh->channel; |
| 1846 | struct video_obj *vid_ch = &ch->video; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1847 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1848 | *timings = vid_ch->dv_timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1849 | |
| 1850 | return 0; |
| 1851 | } |
| 1852 | |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1853 | /* |
| 1854 | * vpif_g_chip_ident() - Identify the chip |
| 1855 | * @file: file ptr |
| 1856 | * @priv: file handle |
| 1857 | * @chip: chip identity |
| 1858 | * |
| 1859 | * Returns zero or -EINVAL if read operations fails. |
| 1860 | */ |
| 1861 | static int vpif_g_chip_ident(struct file *file, void *priv, |
| 1862 | struct v4l2_dbg_chip_ident *chip) |
| 1863 | { |
| 1864 | chip->ident = V4L2_IDENT_NONE; |
| 1865 | chip->revision = 0; |
| 1866 | if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER && |
| 1867 | chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR) { |
| 1868 | vpif_dbg(2, debug, "match_type is invalid.\n"); |
| 1869 | return -EINVAL; |
| 1870 | } |
| 1871 | |
| 1872 | return v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 0, core, |
| 1873 | g_chip_ident, chip); |
| 1874 | } |
| 1875 | |
| 1876 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1877 | /* |
| 1878 | * vpif_dbg_g_register() - Read register |
| 1879 | * @file: file ptr |
| 1880 | * @priv: file handle |
| 1881 | * @reg: register to be read |
| 1882 | * |
| 1883 | * Debugging only |
| 1884 | * Returns zero or -EINVAL if read operations fails. |
| 1885 | */ |
| 1886 | static int vpif_dbg_g_register(struct file *file, void *priv, |
| 1887 | struct v4l2_dbg_register *reg){ |
| 1888 | struct vpif_fh *fh = priv; |
| 1889 | struct channel_obj *ch = fh->channel; |
| 1890 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1891 | return v4l2_subdev_call(ch->sd, core, g_register, reg); |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | /* |
| 1895 | * vpif_dbg_s_register() - Write to register |
| 1896 | * @file: file ptr |
| 1897 | * @priv: file handle |
| 1898 | * @reg: register to be modified |
| 1899 | * |
| 1900 | * Debugging only |
| 1901 | * Returns zero or -EINVAL if write operations fails. |
| 1902 | */ |
| 1903 | static int vpif_dbg_s_register(struct file *file, void *priv, |
| 1904 | struct v4l2_dbg_register *reg){ |
| 1905 | struct vpif_fh *fh = priv; |
| 1906 | struct channel_obj *ch = fh->channel; |
| 1907 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1908 | return v4l2_subdev_call(ch->sd, core, s_register, reg); |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1909 | } |
| 1910 | #endif |
| 1911 | |
| 1912 | /* |
| 1913 | * vpif_log_status() - Status information |
| 1914 | * @file: file ptr |
| 1915 | * @priv: file handle |
| 1916 | * |
| 1917 | * Returns zero. |
| 1918 | */ |
| 1919 | static int vpif_log_status(struct file *filep, void *priv) |
| 1920 | { |
| 1921 | /* status for sub devices */ |
| 1922 | v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status); |
| 1923 | |
| 1924 | return 0; |
| 1925 | } |
| 1926 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1927 | /* vpif capture ioctl operations */ |
| 1928 | static const struct v4l2_ioctl_ops vpif_ioctl_ops = { |
| 1929 | .vidioc_querycap = vpif_querycap, |
| 1930 | .vidioc_g_priority = vpif_g_priority, |
| 1931 | .vidioc_s_priority = vpif_s_priority, |
| 1932 | .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap, |
| 1933 | .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap, |
| 1934 | .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap, |
| 1935 | .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap, |
| 1936 | .vidioc_enum_input = vpif_enum_input, |
| 1937 | .vidioc_s_input = vpif_s_input, |
| 1938 | .vidioc_g_input = vpif_g_input, |
| 1939 | .vidioc_reqbufs = vpif_reqbufs, |
| 1940 | .vidioc_querybuf = vpif_querybuf, |
| 1941 | .vidioc_querystd = vpif_querystd, |
| 1942 | .vidioc_s_std = vpif_s_std, |
| 1943 | .vidioc_g_std = vpif_g_std, |
| 1944 | .vidioc_qbuf = vpif_qbuf, |
| 1945 | .vidioc_dqbuf = vpif_dqbuf, |
| 1946 | .vidioc_streamon = vpif_streamon, |
| 1947 | .vidioc_streamoff = vpif_streamoff, |
| 1948 | .vidioc_cropcap = vpif_cropcap, |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1949 | .vidioc_enum_dv_timings = vpif_enum_dv_timings, |
| 1950 | .vidioc_query_dv_timings = vpif_query_dv_timings, |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1951 | .vidioc_s_dv_timings = vpif_s_dv_timings, |
| 1952 | .vidioc_g_dv_timings = vpif_g_dv_timings, |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1953 | .vidioc_g_chip_ident = vpif_g_chip_ident, |
| 1954 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1955 | .vidioc_g_register = vpif_dbg_g_register, |
| 1956 | .vidioc_s_register = vpif_dbg_s_register, |
| 1957 | #endif |
| 1958 | .vidioc_log_status = vpif_log_status, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1959 | }; |
| 1960 | |
| 1961 | /* vpif file operations */ |
| 1962 | static struct v4l2_file_operations vpif_fops = { |
| 1963 | .owner = THIS_MODULE, |
| 1964 | .open = vpif_open, |
| 1965 | .release = vpif_release, |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 1966 | .unlocked_ioctl = video_ioctl2, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1967 | .mmap = vpif_mmap, |
| 1968 | .poll = vpif_poll |
| 1969 | }; |
| 1970 | |
| 1971 | /* vpif video template */ |
| 1972 | static struct video_device vpif_video_template = { |
| 1973 | .name = "vpif", |
| 1974 | .fops = &vpif_fops, |
| 1975 | .minor = -1, |
| 1976 | .ioctl_ops = &vpif_ioctl_ops, |
| 1977 | }; |
| 1978 | |
| 1979 | /** |
| 1980 | * initialize_vpif() - Initialize vpif data structures |
| 1981 | * |
| 1982 | * Allocate memory for data structures and initialize them |
| 1983 | */ |
| 1984 | static int initialize_vpif(void) |
| 1985 | { |
| 1986 | int err = 0, i, j; |
| 1987 | int free_channel_objects_index; |
| 1988 | |
| 1989 | /* Default number of buffers should be 3 */ |
| 1990 | if ((ch0_numbuffers > 0) && |
| 1991 | (ch0_numbuffers < config_params.min_numbuffers)) |
| 1992 | ch0_numbuffers = config_params.min_numbuffers; |
| 1993 | if ((ch1_numbuffers > 0) && |
| 1994 | (ch1_numbuffers < config_params.min_numbuffers)) |
| 1995 | ch1_numbuffers = config_params.min_numbuffers; |
| 1996 | |
| 1997 | /* Set buffer size to min buffers size if it is invalid */ |
| 1998 | if (ch0_bufsize < config_params.min_bufsize[VPIF_CHANNEL0_VIDEO]) |
| 1999 | ch0_bufsize = |
| 2000 | config_params.min_bufsize[VPIF_CHANNEL0_VIDEO]; |
| 2001 | if (ch1_bufsize < config_params.min_bufsize[VPIF_CHANNEL1_VIDEO]) |
| 2002 | ch1_bufsize = |
| 2003 | config_params.min_bufsize[VPIF_CHANNEL1_VIDEO]; |
| 2004 | |
| 2005 | config_params.numbuffers[VPIF_CHANNEL0_VIDEO] = ch0_numbuffers; |
| 2006 | config_params.numbuffers[VPIF_CHANNEL1_VIDEO] = ch1_numbuffers; |
| 2007 | if (ch0_numbuffers) { |
| 2008 | config_params.channel_bufsize[VPIF_CHANNEL0_VIDEO] |
| 2009 | = ch0_bufsize; |
| 2010 | } |
| 2011 | if (ch1_numbuffers) { |
| 2012 | config_params.channel_bufsize[VPIF_CHANNEL1_VIDEO] |
| 2013 | = ch1_bufsize; |
| 2014 | } |
| 2015 | |
| 2016 | /* Allocate memory for six channel objects */ |
| 2017 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 2018 | vpif_obj.dev[i] = |
| 2019 | kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL); |
| 2020 | /* If memory allocation fails, return error */ |
| 2021 | if (!vpif_obj.dev[i]) { |
| 2022 | free_channel_objects_index = i; |
| 2023 | err = -ENOMEM; |
| 2024 | goto vpif_init_free_channel_objects; |
| 2025 | } |
| 2026 | } |
| 2027 | return 0; |
| 2028 | |
| 2029 | vpif_init_free_channel_objects: |
| 2030 | for (j = 0; j < free_channel_objects_index; j++) |
| 2031 | kfree(vpif_obj.dev[j]); |
| 2032 | return err; |
| 2033 | } |
| 2034 | |
| 2035 | /** |
| 2036 | * vpif_probe : This function probes the vpif capture driver |
| 2037 | * @pdev: platform device pointer |
| 2038 | * |
| 2039 | * This creates device entries by register itself to the V4L2 driver and |
| 2040 | * initializes fields of each channel objects |
| 2041 | */ |
| 2042 | static __init int vpif_probe(struct platform_device *pdev) |
| 2043 | { |
| 2044 | struct vpif_subdev_info *subdevdata; |
| 2045 | struct vpif_capture_config *config; |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2046 | int i, j, k, err; |
| 2047 | int res_idx = 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2048 | struct i2c_adapter *i2c_adap; |
| 2049 | struct channel_obj *ch; |
| 2050 | struct common_obj *common; |
| 2051 | struct video_device *vfd; |
| 2052 | struct resource *res; |
| 2053 | int subdev_count; |
Manjunath Hadli | 764af39 | 2012-04-13 04:49:34 -0300 | [diff] [blame] | 2054 | size_t size; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2055 | |
| 2056 | vpif_dev = &pdev->dev; |
| 2057 | |
| 2058 | err = initialize_vpif(); |
| 2059 | if (err) { |
| 2060 | v4l2_err(vpif_dev->driver, "Error initializing vpif\n"); |
| 2061 | return err; |
| 2062 | } |
| 2063 | |
Hans Verkuil | d2f7a1a | 2011-12-13 05:44:42 -0300 | [diff] [blame] | 2064 | err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); |
| 2065 | if (err) { |
| 2066 | v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); |
| 2067 | return err; |
| 2068 | } |
| 2069 | |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2070 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2071 | for (i = res->start; i <= res->end; i++) { |
Manjunath Hadli | 0316b89 | 2012-04-13 04:44:31 -0300 | [diff] [blame] | 2072 | if (request_irq(i, vpif_channel_isr, IRQF_SHARED, |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2073 | "VPIF_Capture", (void *) |
| 2074 | (&vpif_obj.dev[res_idx]->channel_id))) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2075 | err = -EBUSY; |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2076 | for (j = 0; j < i; j++) |
| 2077 | free_irq(j, (void *) |
| 2078 | (&vpif_obj.dev[res_idx]->channel_id)); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2079 | goto vpif_int_err; |
| 2080 | } |
| 2081 | } |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2082 | res_idx++; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 2086 | /* Get the pointer to the channel object */ |
| 2087 | ch = vpif_obj.dev[i]; |
| 2088 | /* Allocate memory for video device */ |
| 2089 | vfd = video_device_alloc(); |
| 2090 | if (NULL == vfd) { |
| 2091 | for (j = 0; j < i; j++) { |
| 2092 | ch = vpif_obj.dev[j]; |
| 2093 | video_device_release(ch->video_dev); |
| 2094 | } |
| 2095 | err = -ENOMEM; |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2096 | goto vpif_int_err; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2097 | } |
| 2098 | |
| 2099 | /* Initialize field of video device */ |
| 2100 | *vfd = vpif_video_template; |
| 2101 | vfd->v4l2_dev = &vpif_obj.v4l2_dev; |
| 2102 | vfd->release = video_device_release; |
| 2103 | snprintf(vfd->name, sizeof(vfd->name), |
Manjunath Hadli | 0a63172 | 2012-04-13 04:44:00 -0300 | [diff] [blame] | 2104 | "VPIF_Capture_DRIVER_V%s", |
Mauro Carvalho Chehab | 64dc3c1 | 2011-06-25 11:28:37 -0300 | [diff] [blame] | 2105 | VPIF_CAPTURE_VERSION); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2106 | /* Set video_dev to the video device */ |
| 2107 | ch->video_dev = vfd; |
| 2108 | } |
| 2109 | |
Manjunath Hadli | 764af39 | 2012-04-13 04:49:34 -0300 | [diff] [blame] | 2110 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2111 | if (res) { |
| 2112 | size = resource_size(res); |
| 2113 | /* The resources are divided into two equal memory and when we |
| 2114 | * have HD output we can add them together |
| 2115 | */ |
| 2116 | for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) { |
| 2117 | ch = vpif_obj.dev[j]; |
| 2118 | ch->channel_id = j; |
| 2119 | /* only enabled if second resource exists */ |
| 2120 | config_params.video_limit[ch->channel_id] = 0; |
| 2121 | if (size) |
| 2122 | config_params.video_limit[ch->channel_id] = |
| 2123 | size/2; |
| 2124 | } |
| 2125 | } |
| 2126 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2127 | i2c_adap = i2c_get_adapter(1); |
| 2128 | config = pdev->dev.platform_data; |
| 2129 | |
| 2130 | subdev_count = config->subdev_count; |
Mats Randgaard | 1f8766b | 2010-08-30 10:30:37 -0300 | [diff] [blame] | 2131 | vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2132 | GFP_KERNEL); |
| 2133 | if (vpif_obj.sd == NULL) { |
| 2134 | vpif_err("unable to allocate memory for subdevice pointers\n"); |
| 2135 | err = -ENOMEM; |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2136 | goto vpif_sd_error; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2137 | } |
| 2138 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2139 | for (i = 0; i < subdev_count; i++) { |
| 2140 | subdevdata = &config->subdev_info[i]; |
| 2141 | vpif_obj.sd[i] = |
| 2142 | v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, |
| 2143 | i2c_adap, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2144 | &subdevdata->board_info, |
| 2145 | NULL); |
| 2146 | |
| 2147 | if (!vpif_obj.sd[i]) { |
| 2148 | vpif_err("Error registering v4l2 subdevice\n"); |
| 2149 | goto probe_subdev_out; |
| 2150 | } |
| 2151 | v4l2_info(&vpif_obj.v4l2_dev, "registered sub device %s\n", |
| 2152 | subdevdata->name); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2153 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2154 | |
Hans Verkuil | b65814e | 2012-09-20 09:06:26 -0300 | [diff] [blame] | 2155 | for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) { |
| 2156 | ch = vpif_obj.dev[j]; |
| 2157 | ch->channel_id = j; |
| 2158 | common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 2159 | spin_lock_init(&common->irqlock); |
| 2160 | mutex_init(&common->lock); |
| 2161 | ch->video_dev->lock = &common->lock; |
| 2162 | /* Initialize prio member of channel object */ |
| 2163 | v4l2_prio_init(&ch->prio); |
| 2164 | video_set_drvdata(ch->video_dev, ch); |
| 2165 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 2166 | /* select input 0 */ |
| 2167 | err = vpif_set_input(config, ch, 0); |
| 2168 | if (err) |
| 2169 | goto probe_out; |
| 2170 | |
Hans Verkuil | b65814e | 2012-09-20 09:06:26 -0300 | [diff] [blame] | 2171 | err = video_register_device(ch->video_dev, |
| 2172 | VFL_TYPE_GRABBER, (j ? 1 : 0)); |
| 2173 | if (err) |
| 2174 | goto probe_out; |
| 2175 | } |
Manjunath Hadli | 0a63172 | 2012-04-13 04:44:00 -0300 | [diff] [blame] | 2176 | v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n"); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2177 | return 0; |
| 2178 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2179 | probe_out: |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2180 | for (k = 0; k < j; k++) { |
| 2181 | /* Get the pointer to the channel object */ |
| 2182 | ch = vpif_obj.dev[k]; |
| 2183 | /* Unregister video device */ |
| 2184 | video_unregister_device(ch->video_dev); |
| 2185 | } |
Hans Verkuil | b65814e | 2012-09-20 09:06:26 -0300 | [diff] [blame] | 2186 | probe_subdev_out: |
| 2187 | /* free sub devices memory */ |
| 2188 | kfree(vpif_obj.sd); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2189 | |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2190 | vpif_sd_error: |
| 2191 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 2192 | ch = vpif_obj.dev[i]; |
| 2193 | /* Note: does nothing if ch->video_dev == NULL */ |
| 2194 | video_device_release(ch->video_dev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2195 | } |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2196 | vpif_int_err: |
Hans Verkuil | d2f7a1a | 2011-12-13 05:44:42 -0300 | [diff] [blame] | 2197 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 2198 | for (i = 0; i < res_idx; i++) { |
| 2199 | res = platform_get_resource(pdev, IORESOURCE_IRQ, i); |
| 2200 | for (j = res->start; j <= res->end; j++) |
| 2201 | free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id)); |
| 2202 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2203 | return err; |
| 2204 | } |
| 2205 | |
| 2206 | /** |
| 2207 | * vpif_remove() - driver remove handler |
| 2208 | * @device: ptr to platform device structure |
| 2209 | * |
| 2210 | * The vidoe device is unregistered |
| 2211 | */ |
| 2212 | static int vpif_remove(struct platform_device *device) |
| 2213 | { |
| 2214 | int i; |
| 2215 | struct channel_obj *ch; |
| 2216 | |
| 2217 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
| 2218 | |
| 2219 | /* un-register device */ |
| 2220 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 2221 | /* Get the pointer to the channel object */ |
| 2222 | ch = vpif_obj.dev[i]; |
| 2223 | /* Unregister video device */ |
| 2224 | video_unregister_device(ch->video_dev); |
| 2225 | } |
| 2226 | return 0; |
| 2227 | } |
| 2228 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 2229 | #ifdef CONFIG_PM |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2230 | /** |
| 2231 | * vpif_suspend: vpif device suspend |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2232 | */ |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 2233 | static int vpif_suspend(struct device *dev) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2234 | { |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 2235 | |
| 2236 | struct common_obj *common; |
| 2237 | struct channel_obj *ch; |
| 2238 | int i; |
| 2239 | |
| 2240 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 2241 | /* Get the pointer to the channel object */ |
| 2242 | ch = vpif_obj.dev[i]; |
| 2243 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 2244 | mutex_lock(&common->lock); |
| 2245 | if (ch->usrs && common->io_usrs) { |
| 2246 | /* Disable channel */ |
| 2247 | if (ch->channel_id == VPIF_CHANNEL0_VIDEO) { |
| 2248 | enable_channel0(0); |
| 2249 | channel0_intr_enable(0); |
| 2250 | } |
| 2251 | if (ch->channel_id == VPIF_CHANNEL1_VIDEO || |
| 2252 | common->started == 2) { |
| 2253 | enable_channel1(0); |
| 2254 | channel1_intr_enable(0); |
| 2255 | } |
| 2256 | } |
| 2257 | mutex_unlock(&common->lock); |
| 2258 | } |
| 2259 | |
| 2260 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2261 | } |
| 2262 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 2263 | /* |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2264 | * vpif_resume: vpif device suspend |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2265 | */ |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 2266 | static int vpif_resume(struct device *dev) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2267 | { |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 2268 | struct common_obj *common; |
| 2269 | struct channel_obj *ch; |
| 2270 | int i; |
| 2271 | |
| 2272 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 2273 | /* Get the pointer to the channel object */ |
| 2274 | ch = vpif_obj.dev[i]; |
| 2275 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 2276 | mutex_lock(&common->lock); |
| 2277 | if (ch->usrs && common->io_usrs) { |
| 2278 | /* Disable channel */ |
| 2279 | if (ch->channel_id == VPIF_CHANNEL0_VIDEO) { |
| 2280 | enable_channel0(1); |
| 2281 | channel0_intr_enable(1); |
| 2282 | } |
| 2283 | if (ch->channel_id == VPIF_CHANNEL1_VIDEO || |
| 2284 | common->started == 2) { |
| 2285 | enable_channel1(1); |
| 2286 | channel1_intr_enable(1); |
| 2287 | } |
| 2288 | } |
| 2289 | mutex_unlock(&common->lock); |
| 2290 | } |
| 2291 | |
| 2292 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2293 | } |
| 2294 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 2295 | static const struct dev_pm_ops vpif_dev_pm_ops = { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2296 | .suspend = vpif_suspend, |
| 2297 | .resume = vpif_resume, |
| 2298 | }; |
| 2299 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 2300 | #define vpif_pm_ops (&vpif_dev_pm_ops) |
| 2301 | #else |
| 2302 | #define vpif_pm_ops NULL |
| 2303 | #endif |
| 2304 | |
Mats Randgaard | ffa1b39 | 2010-08-30 10:30:36 -0300 | [diff] [blame] | 2305 | static __refdata struct platform_driver vpif_driver = { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2306 | .driver = { |
| 2307 | .name = "vpif_capture", |
| 2308 | .owner = THIS_MODULE, |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 2309 | .pm = vpif_pm_ops, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 2310 | }, |
| 2311 | .probe = vpif_probe, |
| 2312 | .remove = vpif_remove, |
| 2313 | }; |
| 2314 | |
| 2315 | /** |
| 2316 | * vpif_init: initialize the vpif driver |
| 2317 | * |
| 2318 | * This function registers device and driver to the kernel, requests irq |
| 2319 | * handler and allocates memory |
| 2320 | * for channel objects |
| 2321 | */ |
| 2322 | static __init int vpif_init(void) |
| 2323 | { |
| 2324 | return platform_driver_register(&vpif_driver); |
| 2325 | } |
| 2326 | |
| 2327 | /** |
| 2328 | * vpif_cleanup : This function clean up the vpif capture resources |
| 2329 | * |
| 2330 | * This will un-registers device and driver to the kernel, frees |
| 2331 | * requested irq handler and de-allocates memory allocated for channel |
| 2332 | * objects. |
| 2333 | */ |
| 2334 | static void vpif_cleanup(void) |
| 2335 | { |
| 2336 | struct platform_device *pdev; |
| 2337 | struct resource *res; |
| 2338 | int irq_num; |
| 2339 | int i = 0; |
| 2340 | |
| 2341 | pdev = container_of(vpif_dev, struct platform_device, dev); |
| 2342 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) { |
| 2343 | for (irq_num = res->start; irq_num <= res->end; irq_num++) |
| 2344 | free_irq(irq_num, |
| 2345 | (void *)(&vpif_obj.dev[i]->channel_id)); |
| 2346 | i++; |
| 2347 | } |
| 2348 | |
| 2349 | platform_driver_unregister(&vpif_driver); |
| 2350 | |
| 2351 | kfree(vpif_obj.sd); |
| 2352 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) |
| 2353 | kfree(vpif_obj.dev[i]); |
| 2354 | } |
| 2355 | |
| 2356 | /* Function for module initialization and cleanup */ |
| 2357 | module_init(vpif_init); |
| 2358 | module_exit(vpif_cleanup); |