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