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