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