Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Texas Instruments Inc |
Lad, Prabhakar | 96787eb | 2014-05-16 10:33:55 -0300 | [diff] [blame] | 3 | * Copyright (C) 2014 Lad, Prabhakar <prabhakar.csengg@gmail.com> |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | * |
| 19 | * TODO : add support for VBI & HBI data service |
| 20 | * add static buffer allocation |
| 21 | */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 22 | |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/slab.h> |
| 27 | |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 28 | #include <media/v4l2-ioctl.h> |
| 29 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 30 | #include "vpif.h" |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 31 | #include "vpif_capture.h" |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 32 | |
| 33 | MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver"); |
| 34 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 64dc3c1 | 2011-06-25 11:28:37 -0300 | [diff] [blame] | 35 | MODULE_VERSION(VPIF_CAPTURE_VERSION); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 36 | |
| 37 | #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg) |
| 38 | #define vpif_dbg(level, debug, fmt, arg...) \ |
| 39 | v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg) |
| 40 | |
| 41 | static int debug = 1; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 42 | |
| 43 | module_param(debug, int, 0644); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 44 | |
| 45 | MODULE_PARM_DESC(debug, "Debug level 0-1"); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 46 | |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 47 | #define VPIF_DRIVER_NAME "vpif_capture" |
| 48 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 49 | /* global variables */ |
| 50 | static struct vpif_device vpif_obj = { {NULL} }; |
| 51 | static struct device *vpif_dev; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 52 | static void vpif_calculate_offsets(struct channel_obj *ch); |
| 53 | static void vpif_config_addr(struct channel_obj *ch, int muxmode); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 54 | |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 55 | static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} }; |
| 56 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 57 | /* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */ |
| 58 | static int ycmux_mode; |
| 59 | |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 60 | static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_buffer *vb) |
| 61 | { |
| 62 | return container_of(vb, struct vpif_cap_buffer, vb); |
| 63 | } |
| 64 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 65 | /** |
Lad, Prabhakar | 23e76a2 | 2014-05-16 10:33:37 -0300 | [diff] [blame] | 66 | * vpif_buffer_prepare : callback function for buffer prepare |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 67 | * @vb: ptr to vb2_buffer |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 68 | * |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 69 | * This is the callback function for buffer prepare when vb2_qbuf() |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 70 | * function is called. The buffer is prepared and user space virtual address |
| 71 | * or user address is converted into physical address |
| 72 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 73 | static int vpif_buffer_prepare(struct vb2_buffer *vb) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 74 | { |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 75 | struct vb2_queue *q = vb->vb2_queue; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 76 | struct channel_obj *ch = vb2_get_drv_priv(q); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 77 | struct common_obj *common; |
| 78 | unsigned long addr; |
| 79 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 80 | vpif_dbg(2, debug, "vpif_buffer_prepare\n"); |
| 81 | |
| 82 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 83 | |
Lad, Prabhakar | 23e76a2 | 2014-05-16 10:33:37 -0300 | [diff] [blame] | 84 | vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage); |
| 85 | if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) |
| 86 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 87 | |
Lad, Prabhakar | 23e76a2 | 2014-05-16 10:33:37 -0300 | [diff] [blame] | 88 | vb->v4l2_buf.field = common->fmt.fmt.pix.field; |
| 89 | |
| 90 | addr = vb2_dma_contig_plane_dma_addr(vb, 0); |
| 91 | if (!IS_ALIGNED((addr + common->ytop_off), 8) || |
| 92 | !IS_ALIGNED((addr + common->ybtm_off), 8) || |
| 93 | !IS_ALIGNED((addr + common->ctop_off), 8) || |
| 94 | !IS_ALIGNED((addr + common->cbtm_off), 8)) { |
| 95 | vpif_dbg(1, debug, "offset is not aligned\n"); |
| 96 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 97 | } |
Lad, Prabhakar | 23e76a2 | 2014-05-16 10:33:37 -0300 | [diff] [blame] | 98 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 99 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /** |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 103 | * vpif_buffer_queue_setup : Callback function for buffer setup. |
| 104 | * @vq: vb2_queue ptr |
| 105 | * @fmt: v4l2 format |
| 106 | * @nbuffers: ptr to number of buffers requested by application |
| 107 | * @nplanes:: contains number of distinct video planes needed to hold a frame |
| 108 | * @sizes[]: contains the size (in bytes) of each plane. |
| 109 | * @alloc_ctxs: ptr to allocation context |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 110 | * |
| 111 | * This callback function is called when reqbuf() is called to adjust |
| 112 | * the buffer count and buffer size |
| 113 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 114 | static int vpif_buffer_queue_setup(struct vb2_queue *vq, |
| 115 | const struct v4l2_format *fmt, |
| 116 | unsigned int *nbuffers, unsigned int *nplanes, |
| 117 | unsigned int sizes[], void *alloc_ctxs[]) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 118 | { |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 119 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 120 | struct common_obj *common; |
| 121 | |
| 122 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 123 | |
| 124 | vpif_dbg(2, debug, "vpif_buffer_setup\n"); |
| 125 | |
Lad, Prabhakar | 837939d | 2014-05-16 10:33:38 -0300 | [diff] [blame] | 126 | if (fmt && fmt->fmt.pix.sizeimage < common->fmt.fmt.pix.sizeimage) |
| 127 | return -EINVAL; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 128 | |
Lad, Prabhakar | 837939d | 2014-05-16 10:33:38 -0300 | [diff] [blame] | 129 | if (vq->num_buffers + *nbuffers < 3) |
| 130 | *nbuffers = 3 - vq->num_buffers; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 131 | |
| 132 | *nplanes = 1; |
Lad, Prabhakar | 837939d | 2014-05-16 10:33:38 -0300 | [diff] [blame] | 133 | sizes[0] = fmt ? fmt->fmt.pix.sizeimage : common->fmt.fmt.pix.sizeimage; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 134 | alloc_ctxs[0] = common->alloc_ctx; |
| 135 | |
Lad, Prabhakar | 837939d | 2014-05-16 10:33:38 -0300 | [diff] [blame] | 136 | /* Calculate the offset for Y and C data in the buffer */ |
| 137 | vpif_calculate_offsets(ch); |
| 138 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * vpif_buffer_queue : Callback function to add buffer to DMA queue |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 144 | * @vb: ptr to vb2_buffer |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 145 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 146 | static void vpif_buffer_queue(struct vb2_buffer *vb) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 147 | { |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 148 | struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue); |
| 149 | struct vpif_cap_buffer *buf = to_vpif_buffer(vb); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 150 | struct common_obj *common; |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 151 | unsigned long flags; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 152 | |
| 153 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 154 | |
| 155 | vpif_dbg(2, debug, "vpif_buffer_queue\n"); |
| 156 | |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 157 | spin_lock_irqsave(&common->irqlock, flags); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 158 | /* add the buffer to the DMA queue */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 159 | list_add_tail(&buf->list, &common->dma_queue); |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 160 | spin_unlock_irqrestore(&common->irqlock, flags); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 161 | } |
| 162 | |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 163 | /** |
| 164 | * vpif_start_streaming : Starts the DMA engine for streaming |
| 165 | * @vb: ptr to vb2_buffer |
| 166 | * @count: number of buffers |
| 167 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 168 | static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) |
| 169 | { |
| 170 | struct vpif_capture_config *vpif_config_data = |
| 171 | vpif_dev->platform_data; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 172 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 173 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 174 | struct vpif_params *vpif = &ch->vpifparams; |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 175 | struct vpif_cap_buffer *buf, *tmp; |
| 176 | unsigned long addr, flags; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 177 | int ret; |
| 178 | |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 179 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 180 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 181 | /* Initialize field_id */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 182 | ch->field_id = 0; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 183 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 184 | /* configure 1 or 2 channel mode */ |
Lad, Prabhakar | f4ad8d7 | 2012-09-27 02:33:12 -0300 | [diff] [blame] | 185 | if (vpif_config_data->setup_input_channel_mode) { |
| 186 | ret = vpif_config_data-> |
| 187 | setup_input_channel_mode(vpif->std_info.ycmux_mode); |
| 188 | if (ret < 0) { |
| 189 | vpif_dbg(1, debug, "can't set vpif channel mode\n"); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 190 | goto err; |
Lad, Prabhakar | f4ad8d7 | 2012-09-27 02:33:12 -0300 | [diff] [blame] | 191 | } |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 192 | } |
| 193 | |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 194 | ret = v4l2_subdev_call(ch->sd, video, s_stream, 1); |
| 195 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) { |
| 196 | vpif_dbg(1, debug, "stream on failed in subdev\n"); |
| 197 | goto err; |
| 198 | } |
| 199 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 200 | /* Call vpif_set_params function to set the parameters and addresses */ |
| 201 | ret = vpif_set_video_params(vpif, ch->channel_id); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 202 | if (ret < 0) { |
| 203 | vpif_dbg(1, debug, "can't set video params\n"); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 204 | goto err; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 205 | } |
| 206 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 207 | ycmux_mode = ret; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 208 | vpif_config_addr(ch, ret); |
| 209 | |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 210 | /* Get the next frame from the buffer queue */ |
| 211 | common->cur_frm = common->next_frm = list_entry(common->dma_queue.next, |
| 212 | struct vpif_cap_buffer, list); |
| 213 | /* Remove buffer from the buffer queue */ |
| 214 | list_del(&common->cur_frm->list); |
| 215 | spin_unlock_irqrestore(&common->irqlock, flags); |
| 216 | /* Mark state of the current frame to active */ |
| 217 | common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE; |
| 218 | |
| 219 | addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0); |
| 220 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 221 | common->set_addr(addr + common->ytop_off, |
| 222 | addr + common->ybtm_off, |
| 223 | addr + common->ctop_off, |
| 224 | addr + common->cbtm_off); |
| 225 | |
| 226 | /** |
| 227 | * Set interrupt for both the fields in VPIF Register enable channel in |
| 228 | * VPIF register |
| 229 | */ |
Lad, Prabhakar | 9e18404 | 2012-09-14 10:22:24 -0300 | [diff] [blame] | 230 | channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1; |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 231 | if (VPIF_CHANNEL0_VIDEO == ch->channel_id) { |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 232 | channel0_intr_assert(); |
| 233 | channel0_intr_enable(1); |
| 234 | enable_channel0(1); |
| 235 | } |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 236 | if (VPIF_CHANNEL1_VIDEO == ch->channel_id || |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 237 | ycmux_mode == 2) { |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 238 | channel1_intr_assert(); |
| 239 | channel1_intr_enable(1); |
| 240 | enable_channel1(1); |
| 241 | } |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 242 | |
| 243 | return 0; |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 244 | |
| 245 | err: |
| 246 | list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) { |
| 247 | list_del(&buf->list); |
| 248 | vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED); |
| 249 | } |
Dan Carpenter | 9249196 | 2014-06-12 04:01:45 -0300 | [diff] [blame] | 250 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 251 | |
| 252 | return ret; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 253 | } |
| 254 | |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 255 | /** |
| 256 | * vpif_stop_streaming : Stop the DMA engine |
| 257 | * @vq: ptr to vb2_queue |
| 258 | * |
| 259 | * This callback stops the DMA engine and any remaining buffers |
| 260 | * in the DMA queue are released. |
| 261 | */ |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 262 | static void vpif_stop_streaming(struct vb2_queue *vq) |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 263 | { |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 264 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 265 | struct common_obj *common; |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 266 | unsigned long flags; |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 267 | int ret; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 268 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 269 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 270 | |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 271 | /* Disable channel as per its device type and channel id */ |
| 272 | if (VPIF_CHANNEL0_VIDEO == ch->channel_id) { |
| 273 | enable_channel0(0); |
| 274 | channel0_intr_enable(0); |
| 275 | } |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 276 | if (VPIF_CHANNEL1_VIDEO == ch->channel_id || |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 277 | ycmux_mode == 2) { |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 278 | enable_channel1(0); |
| 279 | channel1_intr_enable(0); |
| 280 | } |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 281 | |
| 282 | ycmux_mode = 0; |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 283 | |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 284 | ret = v4l2_subdev_call(ch->sd, video, s_stream, 0); |
| 285 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) |
| 286 | vpif_dbg(1, debug, "stream off failed in subdev\n"); |
| 287 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 288 | /* release all active buffers */ |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 289 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 290 | if (common->cur_frm == common->next_frm) { |
| 291 | vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR); |
| 292 | } else { |
| 293 | if (common->cur_frm != NULL) |
| 294 | vb2_buffer_done(&common->cur_frm->vb, |
| 295 | VB2_BUF_STATE_ERROR); |
| 296 | if (common->next_frm != NULL) |
| 297 | vb2_buffer_done(&common->next_frm->vb, |
| 298 | VB2_BUF_STATE_ERROR); |
| 299 | } |
| 300 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 301 | while (!list_empty(&common->dma_queue)) { |
| 302 | common->next_frm = list_entry(common->dma_queue.next, |
| 303 | struct vpif_cap_buffer, list); |
| 304 | list_del(&common->next_frm->list); |
| 305 | vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR); |
| 306 | } |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 307 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static struct vb2_ops video_qops = { |
| 311 | .queue_setup = vpif_buffer_queue_setup, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 312 | .buf_prepare = vpif_buffer_prepare, |
| 313 | .start_streaming = vpif_start_streaming, |
| 314 | .stop_streaming = vpif_stop_streaming, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 315 | .buf_queue = vpif_buffer_queue, |
| 316 | }; |
| 317 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 318 | /** |
| 319 | * vpif_process_buffer_complete: process a completed buffer |
| 320 | * @common: ptr to common channel object |
| 321 | * |
| 322 | * This function time stamp the buffer and mark it as DONE. It also |
| 323 | * wake up any process waiting on the QUEUE and set the next buffer |
| 324 | * as current |
| 325 | */ |
| 326 | static void vpif_process_buffer_complete(struct common_obj *common) |
| 327 | { |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 328 | v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 329 | vb2_buffer_done(&common->cur_frm->vb, |
| 330 | VB2_BUF_STATE_DONE); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 331 | /* Make curFrm pointing to nextFrm */ |
| 332 | common->cur_frm = common->next_frm; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * vpif_schedule_next_buffer: set next buffer address for capture |
| 337 | * @common : ptr to common channel object |
| 338 | * |
| 339 | * This function will get next buffer from the dma queue and |
| 340 | * set the buffer address in the vpif register for capture. |
| 341 | * the buffer is marked active |
| 342 | */ |
| 343 | static void vpif_schedule_next_buffer(struct common_obj *common) |
| 344 | { |
| 345 | unsigned long addr = 0; |
| 346 | |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 347 | spin_lock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 348 | common->next_frm = list_entry(common->dma_queue.next, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 349 | struct vpif_cap_buffer, list); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 350 | /* Remove that buffer from the buffer queue */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 351 | list_del(&common->next_frm->list); |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 352 | spin_unlock(&common->irqlock); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 353 | common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE; |
| 354 | addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 355 | |
| 356 | /* Set top and bottom field addresses in VPIF registers */ |
| 357 | common->set_addr(addr + common->ytop_off, |
| 358 | addr + common->ybtm_off, |
| 359 | addr + common->ctop_off, |
| 360 | addr + common->cbtm_off); |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * vpif_channel_isr : ISR handler for vpif capture |
| 365 | * @irq: irq number |
| 366 | * @dev_id: dev_id ptr |
| 367 | * |
| 368 | * 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] | 369 | * and sets its address in VPIF registers |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 370 | */ |
| 371 | static irqreturn_t vpif_channel_isr(int irq, void *dev_id) |
| 372 | { |
| 373 | struct vpif_device *dev = &vpif_obj; |
| 374 | struct common_obj *common; |
| 375 | struct channel_obj *ch; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 376 | int channel_id = 0; |
| 377 | int fid = -1, i; |
| 378 | |
| 379 | channel_id = *(int *)(dev_id); |
Manjunath Hadli | b1fc423 | 2012-04-13 04:43:10 -0300 | [diff] [blame] | 380 | if (!vpif_intr_status(channel_id)) |
| 381 | return IRQ_NONE; |
| 382 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 383 | ch = dev->dev[channel_id]; |
| 384 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 385 | for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) { |
| 386 | common = &ch->common[i]; |
| 387 | /* skip If streaming is not started in this channel */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 388 | /* Check the field format */ |
| 389 | if (1 == ch->vpifparams.std_info.frm_fmt) { |
| 390 | /* Progressive mode */ |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 391 | spin_lock(&common->irqlock); |
| 392 | if (list_empty(&common->dma_queue)) { |
| 393 | spin_unlock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 394 | continue; |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 395 | } |
| 396 | spin_unlock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 397 | |
| 398 | if (!channel_first_int[i][channel_id]) |
| 399 | vpif_process_buffer_complete(common); |
| 400 | |
| 401 | channel_first_int[i][channel_id] = 0; |
| 402 | |
| 403 | vpif_schedule_next_buffer(common); |
| 404 | |
| 405 | |
| 406 | channel_first_int[i][channel_id] = 0; |
| 407 | } else { |
| 408 | /** |
| 409 | * Interlaced mode. If it is first interrupt, ignore |
| 410 | * it |
| 411 | */ |
| 412 | if (channel_first_int[i][channel_id]) { |
| 413 | channel_first_int[i][channel_id] = 0; |
| 414 | continue; |
| 415 | } |
| 416 | if (0 == i) { |
| 417 | ch->field_id ^= 1; |
| 418 | /* Get field id from VPIF registers */ |
| 419 | fid = vpif_channel_getfid(ch->channel_id); |
| 420 | if (fid != ch->field_id) { |
| 421 | /** |
| 422 | * If field id does not match stored |
| 423 | * field id, make them in sync |
| 424 | */ |
| 425 | if (0 == fid) |
| 426 | ch->field_id = fid; |
| 427 | return IRQ_HANDLED; |
| 428 | } |
| 429 | } |
| 430 | /* device field id and local field id are in sync */ |
| 431 | if (0 == fid) { |
| 432 | /* this is even field */ |
| 433 | if (common->cur_frm == common->next_frm) |
| 434 | continue; |
| 435 | |
| 436 | /* mark the current buffer as done */ |
| 437 | vpif_process_buffer_complete(common); |
| 438 | } else if (1 == fid) { |
| 439 | /* odd field */ |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 440 | spin_lock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 441 | if (list_empty(&common->dma_queue) || |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 442 | (common->cur_frm != common->next_frm)) { |
| 443 | spin_unlock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 444 | continue; |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 445 | } |
| 446 | spin_unlock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 447 | |
| 448 | vpif_schedule_next_buffer(common); |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | return IRQ_HANDLED; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * vpif_update_std_info() - update standard related info |
| 457 | * @ch: ptr to channel object |
| 458 | * |
| 459 | * For a given standard selected by application, update values |
| 460 | * in the device data structures |
| 461 | */ |
| 462 | static int vpif_update_std_info(struct channel_obj *ch) |
| 463 | { |
| 464 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 465 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 466 | const struct vpif_channel_config_params *config; |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 467 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 468 | struct video_obj *vid_ch = &ch->video; |
| 469 | int index; |
| 470 | |
| 471 | vpif_dbg(2, debug, "vpif_update_std_info\n"); |
| 472 | |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 473 | for (index = 0; index < vpif_ch_params_count; index++) { |
Lad, Prabhakar | ced9b21 | 2013-03-20 01:28:27 -0300 | [diff] [blame] | 474 | config = &vpif_ch_params[index]; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 475 | if (config->hd_sd == 0) { |
| 476 | vpif_dbg(2, debug, "SD format\n"); |
| 477 | if (config->stdid & vid_ch->stdid) { |
| 478 | memcpy(std_info, config, sizeof(*config)); |
| 479 | break; |
| 480 | } |
| 481 | } else { |
| 482 | vpif_dbg(2, debug, "HD format\n"); |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 483 | if (!memcmp(&config->dv_timings, &vid_ch->dv_timings, |
| 484 | sizeof(vid_ch->dv_timings))) { |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 485 | memcpy(std_info, config, sizeof(*config)); |
| 486 | break; |
| 487 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
| 491 | /* standard not found */ |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 492 | if (index == vpif_ch_params_count) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 493 | return -EINVAL; |
| 494 | |
| 495 | common->fmt.fmt.pix.width = std_info->width; |
| 496 | common->width = std_info->width; |
| 497 | common->fmt.fmt.pix.height = std_info->height; |
| 498 | common->height = std_info->height; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 499 | common->fmt.fmt.pix.sizeimage = common->height * common->width * 2; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 500 | common->fmt.fmt.pix.bytesperline = std_info->width; |
| 501 | vpifparams->video_params.hpitch = std_info->width; |
| 502 | vpifparams->video_params.storage_mode = std_info->frm_fmt; |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 503 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 504 | if (vid_ch->stdid) |
| 505 | common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 506 | else |
| 507 | common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_REC709; |
| 508 | |
| 509 | if (ch->vpifparams.std_info.frm_fmt) |
| 510 | common->fmt.fmt.pix.field = V4L2_FIELD_NONE; |
| 511 | else |
| 512 | common->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 513 | |
| 514 | if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) |
| 515 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8; |
| 516 | else |
| 517 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P; |
| 518 | |
| 519 | common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 520 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * vpif_calculate_offsets : This function calculates buffers offsets |
| 526 | * @ch : ptr to channel object |
| 527 | * |
| 528 | * This function calculates buffer offsets for Y and C in the top and |
| 529 | * bottom field |
| 530 | */ |
| 531 | static void vpif_calculate_offsets(struct channel_obj *ch) |
| 532 | { |
Mauro Carvalho Chehab | 24ab633 | 2014-08-21 15:49:06 -0500 | [diff] [blame^] | 533 | unsigned int hpitch, sizeimage; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 534 | struct video_obj *vid_ch = &(ch->video); |
| 535 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 536 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 537 | enum v4l2_field field = common->fmt.fmt.pix.field; |
| 538 | |
| 539 | vpif_dbg(2, debug, "vpif_calculate_offsets\n"); |
| 540 | |
| 541 | if (V4L2_FIELD_ANY == field) { |
| 542 | if (vpifparams->std_info.frm_fmt) |
| 543 | vid_ch->buf_field = V4L2_FIELD_NONE; |
| 544 | else |
| 545 | vid_ch->buf_field = V4L2_FIELD_INTERLACED; |
| 546 | } else |
| 547 | vid_ch->buf_field = common->fmt.fmt.pix.field; |
| 548 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 549 | sizeimage = common->fmt.fmt.pix.sizeimage; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 550 | |
| 551 | hpitch = common->fmt.fmt.pix.bytesperline; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 552 | |
| 553 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 554 | (V4L2_FIELD_INTERLACED == 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 = hpitch; |
| 558 | common->ctop_off = sizeimage / 2; |
| 559 | common->cbtm_off = sizeimage / 2 + hpitch; |
| 560 | } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) { |
| 561 | /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */ |
| 562 | common->ytop_off = 0; |
| 563 | common->ybtm_off = sizeimage / 4; |
| 564 | common->ctop_off = sizeimage / 2; |
| 565 | common->cbtm_off = common->ctop_off + sizeimage / 4; |
| 566 | } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) { |
| 567 | /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */ |
| 568 | common->ybtm_off = 0; |
| 569 | common->ytop_off = sizeimage / 4; |
| 570 | common->cbtm_off = sizeimage / 2; |
| 571 | common->ctop_off = common->cbtm_off + sizeimage / 4; |
| 572 | } |
| 573 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 574 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) |
| 575 | vpifparams->video_params.storage_mode = 1; |
| 576 | else |
| 577 | vpifparams->video_params.storage_mode = 0; |
| 578 | |
| 579 | if (1 == vpifparams->std_info.frm_fmt) |
| 580 | vpifparams->video_params.hpitch = |
| 581 | common->fmt.fmt.pix.bytesperline; |
| 582 | else { |
| 583 | if ((field == V4L2_FIELD_ANY) |
| 584 | || (field == V4L2_FIELD_INTERLACED)) |
| 585 | vpifparams->video_params.hpitch = |
| 586 | common->fmt.fmt.pix.bytesperline * 2; |
| 587 | else |
| 588 | vpifparams->video_params.hpitch = |
| 589 | common->fmt.fmt.pix.bytesperline; |
| 590 | } |
| 591 | |
| 592 | ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid; |
| 593 | } |
| 594 | |
| 595 | /** |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 596 | * vpif_get_default_field() - Get default field type based on interface |
| 597 | * @vpif_params - ptr to vpif params |
| 598 | */ |
| 599 | static inline enum v4l2_field vpif_get_default_field( |
| 600 | struct vpif_interface *iface) |
| 601 | { |
| 602 | return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE : |
| 603 | V4L2_FIELD_INTERLACED; |
| 604 | } |
| 605 | |
| 606 | /** |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 607 | * vpif_config_addr() - function to configure buffer address in vpif |
| 608 | * @ch - channel ptr |
| 609 | * @muxmode - channel mux mode |
| 610 | */ |
| 611 | static void vpif_config_addr(struct channel_obj *ch, int muxmode) |
| 612 | { |
| 613 | struct common_obj *common; |
| 614 | |
| 615 | vpif_dbg(2, debug, "vpif_config_addr\n"); |
| 616 | |
| 617 | common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 618 | |
| 619 | if (VPIF_CHANNEL1_VIDEO == ch->channel_id) |
| 620 | common->set_addr = ch1_set_videobuf_addr; |
| 621 | else if (2 == muxmode) |
| 622 | common->set_addr = ch0_set_videobuf_addr_yc_nmux; |
| 623 | else |
| 624 | common->set_addr = ch0_set_videobuf_addr; |
| 625 | } |
| 626 | |
| 627 | /** |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 628 | * vpif_input_to_subdev() - Maps input to sub device |
| 629 | * @vpif_cfg - global config ptr |
| 630 | * @chan_cfg - channel config ptr |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 631 | * @input_index - Given input index from application |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 632 | * |
| 633 | * lookup the sub device information for a given input index. |
| 634 | * we report all the inputs to application. inputs table also |
| 635 | * has sub device name for the each input |
| 636 | */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 637 | static int vpif_input_to_subdev( |
| 638 | struct vpif_capture_config *vpif_cfg, |
| 639 | struct vpif_capture_chan_config *chan_cfg, |
| 640 | int input_index) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 641 | { |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 642 | struct vpif_subdev_info *subdev_info; |
| 643 | const char *subdev_name; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 644 | int i; |
| 645 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 646 | vpif_dbg(2, debug, "vpif_input_to_subdev\n"); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 647 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 648 | subdev_name = chan_cfg->inputs[input_index].subdev_name; |
| 649 | if (subdev_name == NULL) |
| 650 | return -1; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 651 | |
| 652 | /* loop through the sub device list to get the sub device info */ |
| 653 | for (i = 0; i < vpif_cfg->subdev_count; i++) { |
| 654 | subdev_info = &vpif_cfg->subdev_info[i]; |
| 655 | if (!strcmp(subdev_info->name, subdev_name)) |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 656 | return i; |
| 657 | } |
| 658 | return -1; |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * vpif_set_input() - Select an input |
| 663 | * @vpif_cfg - global config ptr |
| 664 | * @ch - channel |
| 665 | * @_index - Given input index from application |
| 666 | * |
| 667 | * Select the given input. |
| 668 | */ |
| 669 | static int vpif_set_input( |
| 670 | struct vpif_capture_config *vpif_cfg, |
| 671 | struct channel_obj *ch, |
| 672 | int index) |
| 673 | { |
| 674 | struct vpif_capture_chan_config *chan_cfg = |
| 675 | &vpif_cfg->chan_config[ch->channel_id]; |
| 676 | struct vpif_subdev_info *subdev_info = NULL; |
| 677 | struct v4l2_subdev *sd = NULL; |
| 678 | u32 input = 0, output = 0; |
| 679 | int sd_index; |
| 680 | int ret; |
| 681 | |
| 682 | sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index); |
| 683 | if (sd_index >= 0) { |
| 684 | sd = vpif_obj.sd[sd_index]; |
| 685 | subdev_info = &vpif_cfg->subdev_info[sd_index]; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 686 | } |
| 687 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 688 | /* first setup input path from sub device to vpif */ |
| 689 | if (sd && vpif_cfg->setup_input_path) { |
| 690 | ret = vpif_cfg->setup_input_path(ch->channel_id, |
| 691 | subdev_info->name); |
| 692 | if (ret < 0) { |
| 693 | vpif_dbg(1, debug, "couldn't setup input path for the" \ |
| 694 | " sub device %s, for input index %d\n", |
| 695 | subdev_info->name, index); |
| 696 | return ret; |
| 697 | } |
| 698 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 699 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 700 | if (sd) { |
| 701 | input = chan_cfg->inputs[index].input_route; |
| 702 | output = chan_cfg->inputs[index].output_route; |
| 703 | ret = v4l2_subdev_call(sd, video, s_routing, |
| 704 | input, output, 0); |
| 705 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
| 706 | vpif_dbg(1, debug, "Failed to set input\n"); |
| 707 | return ret; |
| 708 | } |
| 709 | } |
| 710 | ch->input_idx = index; |
| 711 | ch->sd = sd; |
| 712 | /* copy interface parameters to vpif */ |
Hans Verkuil | 0d4f35f | 2012-09-20 09:06:32 -0300 | [diff] [blame] | 713 | ch->vpifparams.iface = chan_cfg->vpif_if; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 714 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 715 | /* update tvnorms from the sub device input info */ |
| 716 | ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std; |
| 717 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /** |
| 721 | * vpif_querystd() - querystd handler |
| 722 | * @file: file ptr |
| 723 | * @priv: file handle |
| 724 | * @std_id: ptr to std id |
| 725 | * |
| 726 | * This function is called to detect standard at the selected input |
| 727 | */ |
| 728 | static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id) |
| 729 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 730 | struct video_device *vdev = video_devdata(file); |
| 731 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 732 | int ret = 0; |
| 733 | |
| 734 | vpif_dbg(2, debug, "vpif_querystd\n"); |
| 735 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 736 | /* Call querystd function of decoder device */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 737 | ret = v4l2_subdev_call(ch->sd, video, querystd, std_id); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 738 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 739 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 740 | return -ENODATA; |
| 741 | if (ret) { |
| 742 | vpif_dbg(1, debug, "Failed to query standard for sub devices\n"); |
| 743 | return ret; |
| 744 | } |
| 745 | |
| 746 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /** |
| 750 | * vpif_g_std() - get STD handler |
| 751 | * @file: file ptr |
| 752 | * @priv: file handle |
| 753 | * @std_id: ptr to std id |
| 754 | */ |
| 755 | static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std) |
| 756 | { |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 757 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 758 | struct video_device *vdev = video_devdata(file); |
| 759 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 760 | struct vpif_capture_chan_config *chan_cfg; |
| 761 | struct v4l2_input input; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 762 | |
| 763 | vpif_dbg(2, debug, "vpif_g_std\n"); |
| 764 | |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 765 | if (config->chan_config[ch->channel_id].inputs == NULL) |
| 766 | return -ENODATA; |
| 767 | |
| 768 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 769 | input = chan_cfg->inputs[ch->input_idx].input; |
| 770 | if (input.capabilities != V4L2_IN_CAP_STD) |
| 771 | return -ENODATA; |
| 772 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 773 | *std = ch->video.stdid; |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * vpif_s_std() - set STD handler |
| 779 | * @file: file ptr |
| 780 | * @priv: file handle |
| 781 | * @std_id: ptr to std id |
| 782 | */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 783 | 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] | 784 | { |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 785 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 786 | struct video_device *vdev = video_devdata(file); |
| 787 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 788 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 789 | struct vpif_capture_chan_config *chan_cfg; |
| 790 | struct v4l2_input input; |
| 791 | int ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 792 | |
| 793 | vpif_dbg(2, debug, "vpif_s_std\n"); |
| 794 | |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 795 | if (config->chan_config[ch->channel_id].inputs == NULL) |
| 796 | return -ENODATA; |
| 797 | |
| 798 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 799 | input = chan_cfg->inputs[ch->input_idx].input; |
| 800 | if (input.capabilities != V4L2_IN_CAP_STD) |
| 801 | return -ENODATA; |
| 802 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 803 | if (vb2_is_busy(&common->buffer_queue)) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 804 | return -EBUSY; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 805 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 806 | /* Call encoder subdevice function to set the standard */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 807 | ch->video.stdid = std_id; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 808 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 809 | |
| 810 | /* Get the information about the standard */ |
| 811 | if (vpif_update_std_info(ch)) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 812 | vpif_err("Error getting the standard info\n"); |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 813 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 814 | } |
| 815 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 816 | /* set standard in the sub device */ |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 817 | ret = v4l2_subdev_call(ch->sd, video, s_std, std_id); |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 818 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 819 | vpif_dbg(1, debug, "Failed to set standard for sub devices\n"); |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 820 | return ret; |
| 821 | } |
| 822 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | /** |
| 826 | * vpif_enum_input() - ENUMINPUT handler |
| 827 | * @file: file ptr |
| 828 | * @priv: file handle |
| 829 | * @input: ptr to input structure |
| 830 | */ |
| 831 | static int vpif_enum_input(struct file *file, void *priv, |
| 832 | struct v4l2_input *input) |
| 833 | { |
| 834 | |
| 835 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 836 | struct video_device *vdev = video_devdata(file); |
| 837 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 838 | struct vpif_capture_chan_config *chan_cfg; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 839 | |
| 840 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 841 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 842 | if (input->index >= chan_cfg->input_count) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 843 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 844 | |
| 845 | memcpy(input, &chan_cfg->inputs[input->index].input, |
| 846 | sizeof(*input)); |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | /** |
| 851 | * vpif_g_input() - Get INPUT handler |
| 852 | * @file: file ptr |
| 853 | * @priv: file handle |
| 854 | * @index: ptr to input index |
| 855 | */ |
| 856 | static int vpif_g_input(struct file *file, void *priv, unsigned int *index) |
| 857 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 858 | struct video_device *vdev = video_devdata(file); |
| 859 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 860 | |
Hans Verkuil | 6f47c6c | 2012-09-20 09:06:22 -0300 | [diff] [blame] | 861 | *index = ch->input_idx; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | /** |
| 866 | * vpif_s_input() - Set INPUT handler |
| 867 | * @file: file ptr |
| 868 | * @priv: file handle |
| 869 | * @index: input index |
| 870 | */ |
| 871 | static int vpif_s_input(struct file *file, void *priv, unsigned int index) |
| 872 | { |
| 873 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 874 | struct video_device *vdev = video_devdata(file); |
| 875 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 876 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 877 | struct vpif_capture_chan_config *chan_cfg; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 878 | |
| 879 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 880 | |
Hans Verkuil | 7aaad13 | 2012-09-20 09:06:25 -0300 | [diff] [blame] | 881 | if (index >= chan_cfg->input_count) |
| 882 | return -EINVAL; |
| 883 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 884 | if (vb2_is_busy(&common->buffer_queue)) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 885 | return -EBUSY; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 886 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 887 | return vpif_set_input(config, ch, index); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | /** |
| 891 | * vpif_enum_fmt_vid_cap() - ENUM_FMT handler |
| 892 | * @file: file ptr |
| 893 | * @priv: file handle |
| 894 | * @index: input index |
| 895 | */ |
| 896 | static int vpif_enum_fmt_vid_cap(struct file *file, void *priv, |
| 897 | struct v4l2_fmtdesc *fmt) |
| 898 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 899 | struct video_device *vdev = video_devdata(file); |
| 900 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 901 | |
| 902 | if (fmt->index != 0) { |
| 903 | vpif_dbg(1, debug, "Invalid format index\n"); |
| 904 | return -EINVAL; |
| 905 | } |
| 906 | |
| 907 | /* Fill in the information about format */ |
| 908 | if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) { |
| 909 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 910 | strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb"); |
| 911 | fmt->pixelformat = V4L2_PIX_FMT_SBGGR8; |
| 912 | } else { |
| 913 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 914 | strcpy(fmt->description, "YCbCr4:2:2 YC Planar"); |
| 915 | fmt->pixelformat = V4L2_PIX_FMT_YUV422P; |
| 916 | } |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * vpif_try_fmt_vid_cap() - TRY_FMT handler |
| 922 | * @file: file ptr |
| 923 | * @priv: file handle |
| 924 | * @fmt: ptr to v4l2 format structure |
| 925 | */ |
| 926 | static int vpif_try_fmt_vid_cap(struct file *file, void *priv, |
| 927 | struct v4l2_format *fmt) |
| 928 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 929 | struct video_device *vdev = video_devdata(file); |
| 930 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 931 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 932 | struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 933 | struct vpif_params *vpif_params = &ch->vpifparams; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 934 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 935 | /* |
| 936 | * to supress v4l-compliance warnings silently correct |
| 937 | * the pixelformat |
| 938 | */ |
| 939 | if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) { |
| 940 | if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8) |
| 941 | pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8; |
| 942 | } else { |
| 943 | if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) |
| 944 | pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P; |
| 945 | } |
| 946 | |
| 947 | common->fmt.fmt.pix.pixelformat = pixfmt->pixelformat; |
| 948 | |
| 949 | vpif_update_std_info(ch); |
| 950 | |
| 951 | pixfmt->field = common->fmt.fmt.pix.field; |
| 952 | pixfmt->colorspace = common->fmt.fmt.pix.colorspace; |
| 953 | pixfmt->bytesperline = common->fmt.fmt.pix.width; |
| 954 | pixfmt->width = common->fmt.fmt.pix.width; |
| 955 | pixfmt->height = common->fmt.fmt.pix.height; |
| 956 | pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height * 2; |
| 957 | pixfmt->priv = 0; |
| 958 | |
| 959 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | |
| 963 | /** |
| 964 | * vpif_g_fmt_vid_cap() - Set INPUT handler |
| 965 | * @file: file ptr |
| 966 | * @priv: file handle |
| 967 | * @fmt: ptr to v4l2 format structure |
| 968 | */ |
| 969 | static int vpif_g_fmt_vid_cap(struct file *file, void *priv, |
| 970 | struct v4l2_format *fmt) |
| 971 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 972 | struct video_device *vdev = video_devdata(file); |
| 973 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 974 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 975 | |
| 976 | /* Check the validity of the buffer type */ |
| 977 | if (common->fmt.type != fmt->type) |
| 978 | return -EINVAL; |
| 979 | |
| 980 | /* Fill in the information about format */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 981 | *fmt = common->fmt; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | /** |
| 986 | * vpif_s_fmt_vid_cap() - Set FMT handler |
| 987 | * @file: file ptr |
| 988 | * @priv: file handle |
| 989 | * @fmt: ptr to v4l2 format structure |
| 990 | */ |
| 991 | static int vpif_s_fmt_vid_cap(struct file *file, void *priv, |
| 992 | struct v4l2_format *fmt) |
| 993 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 994 | struct video_device *vdev = video_devdata(file); |
| 995 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 996 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 997 | int ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 998 | |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 999 | vpif_dbg(2, debug, "%s\n", __func__); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1000 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 1001 | if (vb2_is_busy(&common->buffer_queue)) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1002 | return -EBUSY; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1003 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 1004 | ret = vpif_try_fmt_vid_cap(file, priv, fmt); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1005 | if (ret) |
| 1006 | return ret; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 1007 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1008 | /* store the format in the channel object */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1009 | common->fmt = *fmt; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * vpif_querycap() - QUERYCAP handler |
| 1015 | * @file: file ptr |
| 1016 | * @priv: file handle |
| 1017 | * @cap: ptr to v4l2_capability structure |
| 1018 | */ |
| 1019 | static int vpif_querycap(struct file *file, void *priv, |
| 1020 | struct v4l2_capability *cap) |
| 1021 | { |
| 1022 | struct vpif_capture_config *config = vpif_dev->platform_data; |
| 1023 | |
Lad, Prabhakar | 626d533f | 2012-09-25 11:21:55 -0300 | [diff] [blame] | 1024 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; |
| 1025 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1026 | strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver)); |
Lad, Prabhakar | 626d533f | 2012-09-25 11:21:55 -0300 | [diff] [blame] | 1027 | snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", |
| 1028 | dev_name(vpif_dev)); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1029 | strlcpy(cap->card, config->card_name, sizeof(cap->card)); |
| 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1035 | * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1036 | * @file: file ptr |
| 1037 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1038 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1039 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1040 | static int |
| 1041 | vpif_enum_dv_timings(struct file *file, void *priv, |
| 1042 | struct v4l2_enum_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1043 | { |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1044 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1045 | struct video_device *vdev = video_devdata(file); |
| 1046 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1047 | struct vpif_capture_chan_config *chan_cfg; |
| 1048 | struct v4l2_input input; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1049 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1050 | |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1051 | if (config->chan_config[ch->channel_id].inputs == NULL) |
| 1052 | return -ENODATA; |
| 1053 | |
| 1054 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1055 | input = chan_cfg->inputs[ch->input_idx].input; |
| 1056 | if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS) |
| 1057 | return -ENODATA; |
| 1058 | |
Laurent Pinchart | 10d2146 | 2014-01-31 09:04:19 -0300 | [diff] [blame] | 1059 | timings->pad = 0; |
| 1060 | |
| 1061 | ret = v4l2_subdev_call(ch->sd, pad, enum_dv_timings, timings); |
Wei Yongjun | e070f1b | 2012-10-30 09:45:00 -0300 | [diff] [blame] | 1062 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1063 | return -EINVAL; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1064 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1065 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1069 | * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1070 | * @file: file ptr |
| 1071 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1072 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1073 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1074 | static int |
| 1075 | vpif_query_dv_timings(struct file *file, void *priv, |
| 1076 | struct v4l2_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1077 | { |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1078 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1079 | struct video_device *vdev = video_devdata(file); |
| 1080 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1081 | struct vpif_capture_chan_config *chan_cfg; |
| 1082 | struct v4l2_input input; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1083 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1084 | |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1085 | if (config->chan_config[ch->channel_id].inputs == NULL) |
| 1086 | return -ENODATA; |
| 1087 | |
| 1088 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1089 | input = chan_cfg->inputs[ch->input_idx].input; |
| 1090 | if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS) |
| 1091 | return -ENODATA; |
| 1092 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1093 | ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings); |
Wei Yongjun | e070f1b | 2012-10-30 09:45:00 -0300 | [diff] [blame] | 1094 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1095 | return -ENODATA; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1096 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1097 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1098 | } |
| 1099 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1100 | /** |
| 1101 | * vpif_s_dv_timings() - S_DV_TIMINGS handler |
| 1102 | * @file: file ptr |
| 1103 | * @priv: file handle |
| 1104 | * @timings: digital video timings |
| 1105 | */ |
| 1106 | static int vpif_s_dv_timings(struct file *file, void *priv, |
| 1107 | struct v4l2_dv_timings *timings) |
| 1108 | { |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1109 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1110 | struct video_device *vdev = video_devdata(file); |
| 1111 | struct channel_obj *ch = video_get_drvdata(vdev); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1112 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 1113 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1114 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1115 | struct video_obj *vid_ch = &ch->video; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1116 | struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1117 | struct vpif_capture_chan_config *chan_cfg; |
| 1118 | struct v4l2_input input; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1119 | int ret; |
| 1120 | |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1121 | if (config->chan_config[ch->channel_id].inputs == NULL) |
| 1122 | return -ENODATA; |
| 1123 | |
| 1124 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1125 | input = chan_cfg->inputs[ch->input_idx].input; |
| 1126 | if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS) |
| 1127 | return -ENODATA; |
| 1128 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1129 | if (timings->type != V4L2_DV_BT_656_1120) { |
| 1130 | vpif_dbg(2, debug, "Timing type not defined\n"); |
| 1131 | return -EINVAL; |
| 1132 | } |
| 1133 | |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1134 | if (vb2_is_busy(&common->buffer_queue)) |
| 1135 | return -EBUSY; |
| 1136 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1137 | /* Configure subdevice timings, if any */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1138 | ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings); |
| 1139 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 1140 | ret = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1141 | if (ret < 0) { |
| 1142 | vpif_dbg(2, debug, "Error setting custom DV timings\n"); |
| 1143 | return ret; |
| 1144 | } |
| 1145 | |
| 1146 | if (!(timings->bt.width && timings->bt.height && |
| 1147 | (timings->bt.hbackporch || |
| 1148 | timings->bt.hfrontporch || |
| 1149 | timings->bt.hsync) && |
| 1150 | timings->bt.vfrontporch && |
| 1151 | (timings->bt.vbackporch || |
| 1152 | timings->bt.vsync))) { |
| 1153 | vpif_dbg(2, debug, "Timings for width, height, " |
| 1154 | "horizontal back porch, horizontal sync, " |
| 1155 | "horizontal front porch, vertical back porch, " |
| 1156 | "vertical sync and vertical back porch " |
| 1157 | "must be defined\n"); |
| 1158 | return -EINVAL; |
| 1159 | } |
| 1160 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1161 | vid_ch->dv_timings = *timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1162 | |
| 1163 | /* Configure video port timings */ |
| 1164 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame] | 1165 | std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1166 | std_info->sav2eav = bt->width; |
| 1167 | |
| 1168 | std_info->l1 = 1; |
| 1169 | std_info->l3 = bt->vsync + bt->vbackporch + 1; |
| 1170 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame] | 1171 | std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1172 | if (bt->interlaced) { |
| 1173 | if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1174 | std_info->l5 = std_info->vsize/2 - |
| 1175 | (bt->vfrontporch - 1); |
| 1176 | std_info->l7 = std_info->vsize/2 + 1; |
| 1177 | std_info->l9 = std_info->l7 + bt->il_vsync + |
| 1178 | bt->il_vbackporch + 1; |
| 1179 | std_info->l11 = std_info->vsize - |
| 1180 | (bt->il_vfrontporch - 1); |
| 1181 | } else { |
| 1182 | vpif_dbg(2, debug, "Required timing values for " |
| 1183 | "interlaced BT format missing\n"); |
| 1184 | return -EINVAL; |
| 1185 | } |
| 1186 | } else { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1187 | std_info->l5 = std_info->vsize - (bt->vfrontporch - 1); |
| 1188 | } |
| 1189 | strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME); |
| 1190 | std_info->width = bt->width; |
| 1191 | std_info->height = bt->height; |
| 1192 | std_info->frm_fmt = bt->interlaced ? 0 : 1; |
| 1193 | std_info->ycmux_mode = 0; |
| 1194 | std_info->capture_format = 0; |
| 1195 | std_info->vbi_supported = 0; |
| 1196 | std_info->hd_sd = 1; |
| 1197 | std_info->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1198 | |
| 1199 | vid_ch->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * vpif_g_dv_timings() - G_DV_TIMINGS handler |
| 1205 | * @file: file ptr |
| 1206 | * @priv: file handle |
| 1207 | * @timings: digital video timings |
| 1208 | */ |
| 1209 | static int vpif_g_dv_timings(struct file *file, void *priv, |
| 1210 | struct v4l2_dv_timings *timings) |
| 1211 | { |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1212 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1213 | struct video_device *vdev = video_devdata(file); |
| 1214 | struct channel_obj *ch = video_get_drvdata(vdev); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1215 | struct video_obj *vid_ch = &ch->video; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1216 | struct vpif_capture_chan_config *chan_cfg; |
| 1217 | struct v4l2_input input; |
| 1218 | |
| 1219 | if (config->chan_config[ch->channel_id].inputs == NULL) |
| 1220 | return -ENODATA; |
| 1221 | |
| 1222 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1223 | input = chan_cfg->inputs[ch->input_idx].input; |
| 1224 | if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS) |
| 1225 | return -ENODATA; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1226 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1227 | *timings = vid_ch->dv_timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1228 | |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1232 | /* |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1233 | * vpif_log_status() - Status information |
| 1234 | * @file: file ptr |
| 1235 | * @priv: file handle |
| 1236 | * |
| 1237 | * Returns zero. |
| 1238 | */ |
| 1239 | static int vpif_log_status(struct file *filep, void *priv) |
| 1240 | { |
| 1241 | /* status for sub devices */ |
| 1242 | v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status); |
| 1243 | |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1247 | /* vpif capture ioctl operations */ |
| 1248 | static const struct v4l2_ioctl_ops vpif_ioctl_ops = { |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1249 | .vidioc_querycap = vpif_querycap, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1250 | .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap, |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1251 | .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1252 | .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap, |
| 1253 | .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap, |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1254 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1255 | .vidioc_enum_input = vpif_enum_input, |
| 1256 | .vidioc_s_input = vpif_s_input, |
| 1257 | .vidioc_g_input = vpif_g_input, |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 1258 | |
| 1259 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 1260 | .vidioc_create_bufs = vb2_ioctl_create_bufs, |
| 1261 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 1262 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 1263 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
| 1264 | .vidioc_expbuf = vb2_ioctl_expbuf, |
| 1265 | .vidioc_streamon = vb2_ioctl_streamon, |
| 1266 | .vidioc_streamoff = vb2_ioctl_streamoff, |
| 1267 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1268 | .vidioc_querystd = vpif_querystd, |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1269 | .vidioc_s_std = vpif_s_std, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1270 | .vidioc_g_std = vpif_g_std, |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 1271 | |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1272 | .vidioc_enum_dv_timings = vpif_enum_dv_timings, |
| 1273 | .vidioc_query_dv_timings = vpif_query_dv_timings, |
| 1274 | .vidioc_s_dv_timings = vpif_s_dv_timings, |
| 1275 | .vidioc_g_dv_timings = vpif_g_dv_timings, |
| 1276 | |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1277 | .vidioc_log_status = vpif_log_status, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1278 | }; |
| 1279 | |
| 1280 | /* vpif file operations */ |
| 1281 | static struct v4l2_file_operations vpif_fops = { |
| 1282 | .owner = THIS_MODULE, |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1283 | .open = v4l2_fh_open, |
| 1284 | .release = vb2_fop_release, |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 1285 | .unlocked_ioctl = video_ioctl2, |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1286 | .mmap = vb2_fop_mmap, |
| 1287 | .poll = vb2_fop_poll |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1288 | }; |
| 1289 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1290 | /** |
| 1291 | * initialize_vpif() - Initialize vpif data structures |
| 1292 | * |
| 1293 | * Allocate memory for data structures and initialize them |
| 1294 | */ |
| 1295 | static int initialize_vpif(void) |
| 1296 | { |
Lad, Prabhakar | 4015bef | 2014-05-16 10:33:47 -0300 | [diff] [blame] | 1297 | int err, i, j; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1298 | int free_channel_objects_index; |
| 1299 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1300 | /* Allocate memory for six channel objects */ |
| 1301 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1302 | vpif_obj.dev[i] = |
| 1303 | kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL); |
| 1304 | /* If memory allocation fails, return error */ |
| 1305 | if (!vpif_obj.dev[i]) { |
| 1306 | free_channel_objects_index = i; |
| 1307 | err = -ENOMEM; |
| 1308 | goto vpif_init_free_channel_objects; |
| 1309 | } |
| 1310 | } |
| 1311 | return 0; |
| 1312 | |
| 1313 | vpif_init_free_channel_objects: |
| 1314 | for (j = 0; j < free_channel_objects_index; j++) |
| 1315 | kfree(vpif_obj.dev[j]); |
| 1316 | return err; |
| 1317 | } |
| 1318 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1319 | static int vpif_async_bound(struct v4l2_async_notifier *notifier, |
| 1320 | struct v4l2_subdev *subdev, |
| 1321 | struct v4l2_async_subdev *asd) |
| 1322 | { |
| 1323 | int i; |
| 1324 | |
| 1325 | for (i = 0; i < vpif_obj.config->subdev_count; i++) |
| 1326 | if (!strcmp(vpif_obj.config->subdev_info[i].name, |
| 1327 | subdev->name)) { |
| 1328 | vpif_obj.sd[i] = subdev; |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
| 1332 | return -EINVAL; |
| 1333 | } |
| 1334 | |
| 1335 | static int vpif_probe_complete(void) |
| 1336 | { |
| 1337 | struct common_obj *common; |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1338 | struct video_device *vdev; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1339 | struct channel_obj *ch; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1340 | struct vb2_queue *q; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1341 | int i, j, err, k; |
| 1342 | |
| 1343 | for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) { |
| 1344 | ch = vpif_obj.dev[j]; |
| 1345 | ch->channel_id = j; |
| 1346 | common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 1347 | spin_lock_init(&common->irqlock); |
| 1348 | mutex_init(&common->lock); |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1349 | |
| 1350 | /* select input 0 */ |
| 1351 | err = vpif_set_input(vpif_obj.config, ch, 0); |
| 1352 | if (err) |
| 1353 | goto probe_out; |
| 1354 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 1355 | /* set initial format */ |
| 1356 | ch->video.stdid = V4L2_STD_525_60; |
| 1357 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
| 1358 | vpif_update_std_info(ch); |
| 1359 | |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1360 | /* Initialize vb2 queue */ |
| 1361 | q = &common->buffer_queue; |
| 1362 | q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1363 | q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
| 1364 | q->drv_priv = ch; |
| 1365 | q->ops = &video_qops; |
| 1366 | q->mem_ops = &vb2_dma_contig_memops; |
| 1367 | q->buf_struct_size = sizeof(struct vpif_cap_buffer); |
| 1368 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
| 1369 | q->min_buffers_needed = 1; |
Lad, Prabhakar | 999ba69 | 2014-05-16 10:33:33 -0300 | [diff] [blame] | 1370 | q->lock = &common->lock; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1371 | |
| 1372 | err = vb2_queue_init(q); |
| 1373 | if (err) { |
| 1374 | vpif_err("vpif_capture: vb2_queue_init() failed\n"); |
| 1375 | goto probe_out; |
| 1376 | } |
| 1377 | |
| 1378 | common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev); |
| 1379 | if (IS_ERR(common->alloc_ctx)) { |
| 1380 | vpif_err("Failed to get the context\n"); |
| 1381 | err = PTR_ERR(common->alloc_ctx); |
| 1382 | goto probe_out; |
| 1383 | } |
| 1384 | |
| 1385 | INIT_LIST_HEAD(&common->dma_queue); |
| 1386 | |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1387 | /* Initialize the video_device structure */ |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1388 | vdev = ch->video_dev; |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1389 | strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name)); |
| 1390 | vdev->release = video_device_release; |
| 1391 | vdev->fops = &vpif_fops; |
| 1392 | vdev->ioctl_ops = &vpif_ioctl_ops; |
| 1393 | vdev->v4l2_dev = &vpif_obj.v4l2_dev; |
| 1394 | vdev->vfl_dir = VFL_DIR_RX; |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1395 | vdev->queue = q; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1396 | vdev->lock = &common->lock; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1397 | video_set_drvdata(ch->video_dev, ch); |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1398 | err = video_register_device(vdev, |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1399 | VFL_TYPE_GRABBER, (j ? 1 : 0)); |
| 1400 | if (err) |
| 1401 | goto probe_out; |
| 1402 | } |
| 1403 | |
| 1404 | v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n"); |
| 1405 | return 0; |
| 1406 | |
| 1407 | probe_out: |
| 1408 | for (k = 0; k < j; k++) { |
| 1409 | /* Get the pointer to the channel object */ |
| 1410 | ch = vpif_obj.dev[k]; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1411 | common = &ch->common[k]; |
| 1412 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1413 | /* Unregister video device */ |
| 1414 | video_unregister_device(ch->video_dev); |
| 1415 | } |
| 1416 | kfree(vpif_obj.sd); |
| 1417 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1418 | ch = vpif_obj.dev[i]; |
| 1419 | /* Note: does nothing if ch->video_dev == NULL */ |
| 1420 | video_device_release(ch->video_dev); |
| 1421 | } |
| 1422 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
| 1423 | |
| 1424 | return err; |
| 1425 | } |
| 1426 | |
| 1427 | static int vpif_async_complete(struct v4l2_async_notifier *notifier) |
| 1428 | { |
| 1429 | return vpif_probe_complete(); |
| 1430 | } |
| 1431 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1432 | /** |
| 1433 | * vpif_probe : This function probes the vpif capture driver |
| 1434 | * @pdev: platform device pointer |
| 1435 | * |
| 1436 | * This creates device entries by register itself to the V4L2 driver and |
| 1437 | * initializes fields of each channel objects |
| 1438 | */ |
| 1439 | static __init int vpif_probe(struct platform_device *pdev) |
| 1440 | { |
| 1441 | struct vpif_subdev_info *subdevdata; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1442 | int i, j, err; |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 1443 | int res_idx = 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1444 | struct i2c_adapter *i2c_adap; |
| 1445 | struct channel_obj *ch; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1446 | struct video_device *vfd; |
| 1447 | struct resource *res; |
| 1448 | int subdev_count; |
| 1449 | |
| 1450 | vpif_dev = &pdev->dev; |
| 1451 | |
| 1452 | err = initialize_vpif(); |
| 1453 | if (err) { |
| 1454 | v4l2_err(vpif_dev->driver, "Error initializing vpif\n"); |
| 1455 | return err; |
| 1456 | } |
| 1457 | |
Hans Verkuil | d2f7a1a | 2011-12-13 05:44:42 -0300 | [diff] [blame] | 1458 | err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); |
| 1459 | if (err) { |
| 1460 | v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); |
| 1461 | return err; |
| 1462 | } |
| 1463 | |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 1464 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { |
Lad, Prabhakar | a76a0b3 | 2013-06-17 11:20:47 -0300 | [diff] [blame] | 1465 | err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr, |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1466 | IRQF_SHARED, VPIF_DRIVER_NAME, |
Lad, Prabhakar | a76a0b3 | 2013-06-17 11:20:47 -0300 | [diff] [blame] | 1467 | (void *)(&vpif_obj.dev[res_idx]-> |
| 1468 | channel_id)); |
| 1469 | if (err) { |
| 1470 | err = -EINVAL; |
| 1471 | goto vpif_unregister; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1472 | } |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 1473 | res_idx++; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1477 | /* Get the pointer to the channel object */ |
| 1478 | ch = vpif_obj.dev[i]; |
| 1479 | /* Allocate memory for video device */ |
| 1480 | vfd = video_device_alloc(); |
| 1481 | if (NULL == vfd) { |
| 1482 | for (j = 0; j < i; j++) { |
| 1483 | ch = vpif_obj.dev[j]; |
| 1484 | video_device_release(ch->video_dev); |
| 1485 | } |
| 1486 | err = -ENOMEM; |
Lad, Prabhakar | b2de4f2 | 2013-06-17 11:20:46 -0300 | [diff] [blame] | 1487 | goto vpif_unregister; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1488 | } |
| 1489 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1490 | /* Set video_dev to the video device */ |
| 1491 | ch->video_dev = vfd; |
| 1492 | } |
| 1493 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1494 | vpif_obj.config = pdev->dev.platform_data; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1495 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1496 | subdev_count = vpif_obj.config->subdev_count; |
Mats Randgaard | 1f8766b | 2010-08-30 10:30:37 -0300 | [diff] [blame] | 1497 | vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1498 | GFP_KERNEL); |
| 1499 | if (vpif_obj.sd == NULL) { |
| 1500 | vpif_err("unable to allocate memory for subdevice pointers\n"); |
| 1501 | err = -ENOMEM; |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 1502 | goto vpif_sd_error; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1503 | } |
| 1504 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1505 | if (!vpif_obj.config->asd_sizes) { |
| 1506 | i2c_adap = i2c_get_adapter(1); |
| 1507 | for (i = 0; i < subdev_count; i++) { |
| 1508 | subdevdata = &vpif_obj.config->subdev_info[i]; |
| 1509 | vpif_obj.sd[i] = |
| 1510 | v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, |
| 1511 | i2c_adap, |
| 1512 | &subdevdata-> |
| 1513 | board_info, |
| 1514 | NULL); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1515 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1516 | if (!vpif_obj.sd[i]) { |
| 1517 | vpif_err("Error registering v4l2 subdevice\n"); |
Wei Yongjun | 2fcd9dc | 2013-09-02 05:06:10 -0300 | [diff] [blame] | 1518 | err = -ENODEV; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1519 | goto probe_subdev_out; |
| 1520 | } |
| 1521 | v4l2_info(&vpif_obj.v4l2_dev, |
| 1522 | "registered sub device %s\n", |
| 1523 | subdevdata->name); |
| 1524 | } |
| 1525 | vpif_probe_complete(); |
| 1526 | } else { |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 1527 | vpif_obj.notifier.subdevs = vpif_obj.config->asd; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1528 | vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0]; |
| 1529 | vpif_obj.notifier.bound = vpif_async_bound; |
| 1530 | vpif_obj.notifier.complete = vpif_async_complete; |
| 1531 | err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev, |
| 1532 | &vpif_obj.notifier); |
| 1533 | if (err) { |
| 1534 | vpif_err("Error registering async notifier\n"); |
| 1535 | err = -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1536 | goto probe_subdev_out; |
| 1537 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1538 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1539 | |
| 1540 | return 0; |
| 1541 | |
Hans Verkuil | b65814e | 2012-09-20 09:06:26 -0300 | [diff] [blame] | 1542 | probe_subdev_out: |
| 1543 | /* free sub devices memory */ |
| 1544 | kfree(vpif_obj.sd); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1545 | |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 1546 | vpif_sd_error: |
| 1547 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1548 | ch = vpif_obj.dev[i]; |
| 1549 | /* Note: does nothing if ch->video_dev == NULL */ |
| 1550 | video_device_release(ch->video_dev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1551 | } |
Lad, Prabhakar | b2de4f2 | 2013-06-17 11:20:46 -0300 | [diff] [blame] | 1552 | vpif_unregister: |
Hans Verkuil | d2f7a1a | 2011-12-13 05:44:42 -0300 | [diff] [blame] | 1553 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
Lad, Prabhakar | b2de4f2 | 2013-06-17 11:20:46 -0300 | [diff] [blame] | 1554 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1555 | return err; |
| 1556 | } |
| 1557 | |
| 1558 | /** |
| 1559 | * vpif_remove() - driver remove handler |
| 1560 | * @device: ptr to platform device structure |
| 1561 | * |
| 1562 | * The vidoe device is unregistered |
| 1563 | */ |
| 1564 | static int vpif_remove(struct platform_device *device) |
| 1565 | { |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1566 | struct common_obj *common; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1567 | struct channel_obj *ch; |
Lad, Prabhakar | b2de4f2 | 2013-06-17 11:20:46 -0300 | [diff] [blame] | 1568 | int i; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1569 | |
| 1570 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
| 1571 | |
Lad, Prabhakar | 410ca60 | 2013-06-17 11:20:44 -0300 | [diff] [blame] | 1572 | kfree(vpif_obj.sd); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1573 | /* un-register device */ |
| 1574 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1575 | /* Get the pointer to the channel object */ |
| 1576 | ch = vpif_obj.dev[i]; |
Prabhakar Lad | e9b5872 | 2014-07-18 13:31:51 -0300 | [diff] [blame] | 1577 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1578 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1579 | /* Unregister video device */ |
| 1580 | video_unregister_device(ch->video_dev); |
Lad, Prabhakar | 410ca60 | 2013-06-17 11:20:44 -0300 | [diff] [blame] | 1581 | kfree(vpif_obj.dev[i]); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1582 | } |
| 1583 | return 0; |
| 1584 | } |
| 1585 | |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1586 | #ifdef CONFIG_PM_SLEEP |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1587 | /** |
| 1588 | * vpif_suspend: vpif device suspend |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1589 | */ |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1590 | static int vpif_suspend(struct device *dev) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1591 | { |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1592 | |
| 1593 | struct common_obj *common; |
| 1594 | struct channel_obj *ch; |
| 1595 | int i; |
| 1596 | |
| 1597 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1598 | /* Get the pointer to the channel object */ |
| 1599 | ch = vpif_obj.dev[i]; |
| 1600 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1601 | |
| 1602 | if (!vb2_is_streaming(&common->buffer_queue)) |
| 1603 | continue; |
| 1604 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1605 | mutex_lock(&common->lock); |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1606 | /* Disable channel */ |
| 1607 | if (ch->channel_id == VPIF_CHANNEL0_VIDEO) { |
| 1608 | enable_channel0(0); |
| 1609 | channel0_intr_enable(0); |
| 1610 | } |
| 1611 | if (ch->channel_id == VPIF_CHANNEL1_VIDEO || |
| 1612 | ycmux_mode == 2) { |
| 1613 | enable_channel1(0); |
| 1614 | channel1_intr_enable(0); |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1615 | } |
| 1616 | mutex_unlock(&common->lock); |
| 1617 | } |
| 1618 | |
| 1619 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1620 | } |
| 1621 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1622 | /* |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1623 | * vpif_resume: vpif device suspend |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1624 | */ |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1625 | static int vpif_resume(struct device *dev) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1626 | { |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1627 | struct common_obj *common; |
| 1628 | struct channel_obj *ch; |
| 1629 | int i; |
| 1630 | |
| 1631 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1632 | /* Get the pointer to the channel object */ |
| 1633 | ch = vpif_obj.dev[i]; |
| 1634 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1635 | |
| 1636 | if (!vb2_is_streaming(&common->buffer_queue)) |
| 1637 | continue; |
| 1638 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1639 | mutex_lock(&common->lock); |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1640 | /* Enable channel */ |
| 1641 | if (ch->channel_id == VPIF_CHANNEL0_VIDEO) { |
| 1642 | enable_channel0(1); |
| 1643 | channel0_intr_enable(1); |
| 1644 | } |
| 1645 | if (ch->channel_id == VPIF_CHANNEL1_VIDEO || |
| 1646 | ycmux_mode == 2) { |
| 1647 | enable_channel1(1); |
| 1648 | channel1_intr_enable(1); |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1649 | } |
| 1650 | mutex_unlock(&common->lock); |
| 1651 | } |
| 1652 | |
| 1653 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1654 | } |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1655 | #endif |
| 1656 | |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1657 | static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume); |
| 1658 | |
Mats Randgaard | ffa1b39 | 2010-08-30 10:30:36 -0300 | [diff] [blame] | 1659 | static __refdata struct platform_driver vpif_driver = { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1660 | .driver = { |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1661 | .name = VPIF_DRIVER_NAME, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1662 | .owner = THIS_MODULE, |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1663 | .pm = &vpif_pm_ops, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1664 | }, |
| 1665 | .probe = vpif_probe, |
| 1666 | .remove = vpif_remove, |
| 1667 | }; |
| 1668 | |
Lad, Prabhakar | fe424b2 | 2013-06-17 11:20:45 -0300 | [diff] [blame] | 1669 | module_platform_driver(vpif_driver); |