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