Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1 | /* |
| 2 | * vpif-display - VPIF display driver |
| 3 | * Display driver for TI DaVinci VPIF |
| 4 | * |
| 5 | * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation version 2. |
| 10 | * |
| 11 | * This program is distributed .as is. WITHOUT ANY WARRANTY of any |
| 12 | * kind, whether express or implied; without even the implied warranty |
| 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 18 | #include <linux/module.h> |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 21 | |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 22 | #include <media/v4l2-ioctl.h> |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 23 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 24 | #include "vpif.h" |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 25 | #include "vpif_display.h" |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 26 | |
| 27 | MODULE_DESCRIPTION("TI DaVinci VPIF Display driver"); |
| 28 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 64dc3c1 | 2011-06-25 11:28:37 -0300 | [diff] [blame] | 29 | MODULE_VERSION(VPIF_DISPLAY_VERSION); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 30 | |
Manjunath Hadli | 0a63172 | 2012-04-13 04:44:00 -0300 | [diff] [blame] | 31 | #define VPIF_V4L2_STD (V4L2_STD_525_60 | V4L2_STD_625_50) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 32 | |
| 33 | #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg) |
| 34 | #define vpif_dbg(level, debug, fmt, arg...) \ |
| 35 | v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg) |
| 36 | |
| 37 | static int debug = 1; |
| 38 | static u32 ch2_numbuffers = 3; |
| 39 | static u32 ch3_numbuffers = 3; |
| 40 | static u32 ch2_bufsize = 1920 * 1080 * 2; |
| 41 | static u32 ch3_bufsize = 720 * 576 * 2; |
| 42 | |
| 43 | module_param(debug, int, 0644); |
| 44 | module_param(ch2_numbuffers, uint, S_IRUGO); |
| 45 | module_param(ch3_numbuffers, uint, S_IRUGO); |
| 46 | module_param(ch2_bufsize, uint, S_IRUGO); |
| 47 | module_param(ch3_bufsize, uint, S_IRUGO); |
| 48 | |
| 49 | MODULE_PARM_DESC(debug, "Debug level 0-1"); |
| 50 | MODULE_PARM_DESC(ch2_numbuffers, "Channel2 buffer count (default:3)"); |
| 51 | MODULE_PARM_DESC(ch3_numbuffers, "Channel3 buffer count (default:3)"); |
| 52 | MODULE_PARM_DESC(ch2_bufsize, "Channel2 buffer size (default:1920 x 1080 x 2)"); |
| 53 | MODULE_PARM_DESC(ch3_bufsize, "Channel3 buffer size (default:720 x 576 x 2)"); |
| 54 | |
| 55 | static struct vpif_config_params config_params = { |
| 56 | .min_numbuffers = 3, |
| 57 | .numbuffers[0] = 3, |
| 58 | .numbuffers[1] = 3, |
| 59 | .min_bufsize[0] = 720 * 480 * 2, |
| 60 | .min_bufsize[1] = 720 * 480 * 2, |
| 61 | .channel_bufsize[0] = 1920 * 1080 * 2, |
| 62 | .channel_bufsize[1] = 720 * 576 * 2, |
| 63 | }; |
| 64 | |
| 65 | static struct vpif_device vpif_obj = { {NULL} }; |
| 66 | static struct device *vpif_dev; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 67 | static void vpif_calculate_offsets(struct channel_obj *ch); |
| 68 | static void vpif_config_addr(struct channel_obj *ch, int muxmode); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 69 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 70 | /* |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 71 | * buffer_prepare: This is the callback function called from vb2_qbuf() |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 72 | * function the buffer is prepared and user space virtual address is converted |
| 73 | * into physical address |
| 74 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 75 | static int vpif_buffer_prepare(struct vb2_buffer *vb) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 76 | { |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 77 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); |
| 78 | struct vb2_queue *q = vb->vb2_queue; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 79 | struct common_obj *common; |
| 80 | unsigned long addr; |
| 81 | |
| 82 | common = &fh->channel->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 83 | if (vb->state != VB2_BUF_STATE_ACTIVE && |
| 84 | vb->state != VB2_BUF_STATE_PREPARED) { |
| 85 | vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage); |
| 86 | if (vb2_plane_vaddr(vb, 0) && |
| 87 | vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) |
| 88 | goto buf_align_exit; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 89 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 90 | addr = vb2_dma_contig_plane_dma_addr(vb, 0); |
| 91 | if (q->streaming && |
| 92 | (V4L2_BUF_TYPE_SLICED_VBI_OUTPUT != q->type)) { |
| 93 | if (!ISALIGNED(addr + common->ytop_off) || |
| 94 | !ISALIGNED(addr + common->ybtm_off) || |
| 95 | !ISALIGNED(addr + common->ctop_off) || |
| 96 | !ISALIGNED(addr + common->cbtm_off)) |
| 97 | goto buf_align_exit; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 98 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 99 | } |
| 100 | return 0; |
| 101 | |
| 102 | buf_align_exit: |
| 103 | vpif_err("buffer offset not aligned to 8 bytes\n"); |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | |
| 107 | /* |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 108 | * vpif_buffer_queue_setup: This function allocates memory for the buffers |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 109 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 110 | static int vpif_buffer_queue_setup(struct vb2_queue *vq, |
| 111 | const struct v4l2_format *fmt, |
| 112 | unsigned int *nbuffers, unsigned int *nplanes, |
| 113 | unsigned int sizes[], void *alloc_ctxs[]) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 114 | { |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 115 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 116 | struct channel_obj *ch = fh->channel; |
| 117 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 118 | unsigned long size; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 119 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 120 | if (V4L2_MEMORY_MMAP == common->memory) { |
| 121 | size = config_params.channel_bufsize[ch->channel_id]; |
| 122 | /* |
| 123 | * Checking if the buffer size exceeds the available buffer |
| 124 | * ycmux_mode = 0 means 1 channel mode HD and |
| 125 | * ycmux_mode = 1 means 2 channels mode SD |
| 126 | */ |
| 127 | if (ch->vpifparams.std_info.ycmux_mode == 0) { |
| 128 | if (config_params.video_limit[ch->channel_id]) |
| 129 | while (size * *nbuffers > |
| 130 | (config_params.video_limit[0] |
| 131 | + config_params.video_limit[1])) |
| 132 | (*nbuffers)--; |
| 133 | } else { |
| 134 | if (config_params.video_limit[ch->channel_id]) |
| 135 | while (size * *nbuffers > |
Manjunath Hadli | fc613d4 | 2012-04-13 04:49:10 -0300 | [diff] [blame] | 136 | config_params.video_limit[ch->channel_id]) |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 137 | (*nbuffers)--; |
| 138 | } |
| 139 | } else { |
| 140 | size = common->fmt.fmt.pix.sizeimage; |
Manjunath Hadli | fc613d4 | 2012-04-13 04:49:10 -0300 | [diff] [blame] | 141 | } |
| 142 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 143 | if (*nbuffers < config_params.min_numbuffers) |
| 144 | *nbuffers = config_params.min_numbuffers; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 145 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 146 | *nplanes = 1; |
| 147 | sizes[0] = size; |
| 148 | alloc_ctxs[0] = common->alloc_ctx; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * vpif_buffer_queue: This function adds the buffer to DMA queue |
| 154 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 155 | static void vpif_buffer_queue(struct vb2_buffer *vb) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 156 | { |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 157 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); |
| 158 | struct vpif_disp_buffer *buf = container_of(vb, |
| 159 | struct vpif_disp_buffer, vb); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 160 | struct channel_obj *ch = fh->channel; |
| 161 | struct common_obj *common; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 162 | unsigned long flags; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 163 | |
| 164 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 165 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 166 | /* add the buffer to the DMA queue */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 167 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 168 | list_add_tail(&buf->list, &common->dma_queue); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 169 | spin_unlock_irqrestore(&common->irqlock, flags); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 170 | } |
| 171 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 172 | /* |
| 173 | * vpif_buf_cleanup: This function is called from the videobuf2 layer to |
| 174 | * free memory allocated to the buffers |
| 175 | */ |
| 176 | static void vpif_buf_cleanup(struct vb2_buffer *vb) |
| 177 | { |
| 178 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); |
| 179 | struct vpif_disp_buffer *buf = container_of(vb, |
| 180 | struct vpif_disp_buffer, vb); |
| 181 | struct channel_obj *ch = fh->channel; |
| 182 | struct common_obj *common; |
| 183 | unsigned long flags; |
| 184 | |
| 185 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 186 | |
| 187 | spin_lock_irqsave(&common->irqlock, flags); |
| 188 | if (vb->state == VB2_BUF_STATE_ACTIVE) |
| 189 | list_del_init(&buf->list); |
| 190 | spin_unlock_irqrestore(&common->irqlock, flags); |
| 191 | } |
| 192 | |
| 193 | static void vpif_wait_prepare(struct vb2_queue *vq) |
| 194 | { |
| 195 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
| 196 | struct channel_obj *ch = fh->channel; |
| 197 | struct common_obj *common; |
| 198 | |
| 199 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 200 | mutex_unlock(&common->lock); |
| 201 | } |
| 202 | |
| 203 | static void vpif_wait_finish(struct vb2_queue *vq) |
| 204 | { |
| 205 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
| 206 | struct channel_obj *ch = fh->channel; |
| 207 | struct common_obj *common; |
| 208 | |
| 209 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 210 | mutex_lock(&common->lock); |
| 211 | } |
| 212 | |
| 213 | static int vpif_buffer_init(struct vb2_buffer *vb) |
| 214 | { |
| 215 | struct vpif_disp_buffer *buf = container_of(vb, |
| 216 | struct vpif_disp_buffer, vb); |
| 217 | |
| 218 | INIT_LIST_HEAD(&buf->list); |
| 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 223 | static u8 channel_first_int[VPIF_NUMOBJECTS][2] = { {1, 1} }; |
| 224 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 225 | static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) |
| 226 | { |
| 227 | struct vpif_display_config *vpif_config_data = |
| 228 | vpif_dev->platform_data; |
| 229 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
| 230 | struct channel_obj *ch = fh->channel; |
| 231 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 232 | struct vpif_params *vpif = &ch->vpifparams; |
| 233 | unsigned long addr = 0; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 234 | unsigned long flags; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 235 | int ret; |
| 236 | |
| 237 | /* If buffer queue is empty, return error */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 238 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 239 | if (list_empty(&common->dma_queue)) { |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 240 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 241 | vpif_err("buffer queue is empty\n"); |
| 242 | return -EIO; |
| 243 | } |
| 244 | |
| 245 | /* Get the next frame from the buffer queue */ |
| 246 | common->next_frm = common->cur_frm = |
| 247 | list_entry(common->dma_queue.next, |
| 248 | struct vpif_disp_buffer, list); |
| 249 | |
| 250 | list_del(&common->cur_frm->list); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 251 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 252 | /* Mark state of the current frame to active */ |
| 253 | common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE; |
| 254 | |
| 255 | /* Initialize field_id and started member */ |
| 256 | ch->field_id = 0; |
| 257 | common->started = 1; |
| 258 | addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0); |
| 259 | /* Calculate the offset for Y and C data in the buffer */ |
| 260 | vpif_calculate_offsets(ch); |
| 261 | |
| 262 | if ((ch->vpifparams.std_info.frm_fmt && |
| 263 | ((common->fmt.fmt.pix.field != V4L2_FIELD_NONE) |
| 264 | && (common->fmt.fmt.pix.field != V4L2_FIELD_ANY))) |
| 265 | || (!ch->vpifparams.std_info.frm_fmt |
| 266 | && (common->fmt.fmt.pix.field == V4L2_FIELD_NONE))) { |
| 267 | vpif_err("conflict in field format and std format\n"); |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | /* clock settings */ |
Lad, Prabhakar | f4ad8d7 | 2012-09-27 02:33:12 -0300 | [diff] [blame] | 272 | if (vpif_config_data->set_clock) { |
| 273 | ret = vpif_config_data->set_clock(ch->vpifparams.std_info. |
| 274 | ycmux_mode, ch->vpifparams.std_info.hd_sd); |
| 275 | if (ret < 0) { |
| 276 | vpif_err("can't set clock\n"); |
| 277 | return ret; |
| 278 | } |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /* set the parameters and addresses */ |
| 282 | ret = vpif_set_video_params(vpif, ch->channel_id + 2); |
| 283 | if (ret < 0) |
| 284 | return ret; |
| 285 | |
| 286 | common->started = ret; |
| 287 | vpif_config_addr(ch, ret); |
| 288 | common->set_addr((addr + common->ytop_off), |
| 289 | (addr + common->ybtm_off), |
| 290 | (addr + common->ctop_off), |
| 291 | (addr + common->cbtm_off)); |
| 292 | |
| 293 | /* Set interrupt for both the fields in VPIF |
| 294 | Register enable channel in VPIF register */ |
Lad, Prabhakar | 9e18404 | 2012-09-14 10:22:24 -0300 | [diff] [blame] | 295 | channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 296 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { |
| 297 | channel2_intr_assert(); |
| 298 | channel2_intr_enable(1); |
| 299 | enable_channel2(1); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 300 | if (vpif_config_data->chan_config[VPIF_CHANNEL2_VIDEO].clip_en) |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 301 | channel2_clipping_enable(1); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) |
| 305 | || (common->started == 2)) { |
| 306 | channel3_intr_assert(); |
| 307 | channel3_intr_enable(1); |
| 308 | enable_channel3(1); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 309 | if (vpif_config_data->chan_config[VPIF_CHANNEL3_VIDEO].clip_en) |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 310 | channel3_clipping_enable(1); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 311 | } |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /* abort streaming and wait for last buffer */ |
| 317 | static int vpif_stop_streaming(struct vb2_queue *vq) |
| 318 | { |
| 319 | struct vpif_fh *fh = vb2_get_drv_priv(vq); |
| 320 | struct channel_obj *ch = fh->channel; |
| 321 | struct common_obj *common; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 322 | unsigned long flags; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 323 | |
| 324 | if (!vb2_is_streaming(vq)) |
| 325 | return 0; |
| 326 | |
| 327 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 328 | |
| 329 | /* release all active buffers */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 330 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 331 | while (!list_empty(&common->dma_queue)) { |
| 332 | common->next_frm = list_entry(common->dma_queue.next, |
| 333 | struct vpif_disp_buffer, list); |
| 334 | list_del(&common->next_frm->list); |
| 335 | vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR); |
| 336 | } |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 337 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | static struct vb2_ops video_qops = { |
| 343 | .queue_setup = vpif_buffer_queue_setup, |
| 344 | .wait_prepare = vpif_wait_prepare, |
| 345 | .wait_finish = vpif_wait_finish, |
| 346 | .buf_init = vpif_buffer_init, |
| 347 | .buf_prepare = vpif_buffer_prepare, |
| 348 | .start_streaming = vpif_start_streaming, |
| 349 | .stop_streaming = vpif_stop_streaming, |
| 350 | .buf_cleanup = vpif_buf_cleanup, |
| 351 | .buf_queue = vpif_buffer_queue, |
| 352 | }; |
| 353 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 354 | static void process_progressive_mode(struct common_obj *common) |
| 355 | { |
| 356 | unsigned long addr = 0; |
| 357 | |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 358 | spin_lock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 359 | /* Get the next buffer from buffer queue */ |
| 360 | common->next_frm = list_entry(common->dma_queue.next, |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 361 | struct vpif_disp_buffer, list); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 362 | /* Remove that buffer from the buffer queue */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 363 | list_del(&common->next_frm->list); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 364 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 365 | /* Mark status of the buffer as active */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 366 | common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 367 | |
| 368 | /* Set top and bottom field addrs in VPIF registers */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 369 | addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 370 | common->set_addr(addr + common->ytop_off, |
| 371 | addr + common->ybtm_off, |
| 372 | addr + common->ctop_off, |
| 373 | addr + common->cbtm_off); |
| 374 | } |
| 375 | |
| 376 | static void process_interlaced_mode(int fid, struct common_obj *common) |
| 377 | { |
| 378 | /* device field id and local field id are in sync */ |
| 379 | /* If this is even field */ |
| 380 | if (0 == fid) { |
| 381 | if (common->cur_frm == common->next_frm) |
| 382 | return; |
| 383 | |
| 384 | /* one frame is displayed If next frame is |
| 385 | * available, release cur_frm and move on */ |
| 386 | /* Copy frame display time */ |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 387 | v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 388 | /* Change status of the cur_frm */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 389 | vb2_buffer_done(&common->cur_frm->vb, |
| 390 | VB2_BUF_STATE_DONE); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 391 | /* Make cur_frm pointing to next_frm */ |
| 392 | common->cur_frm = common->next_frm; |
| 393 | |
| 394 | } else if (1 == fid) { /* odd field */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 395 | spin_lock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 396 | if (list_empty(&common->dma_queue) |
| 397 | || (common->cur_frm != common->next_frm)) { |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 398 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 399 | return; |
| 400 | } |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 401 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 402 | /* one field is displayed configure the next |
| 403 | * frame if it is available else hold on current |
| 404 | * frame */ |
| 405 | /* Get next from the buffer queue */ |
| 406 | process_progressive_mode(common); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | /* |
| 411 | * vpif_channel_isr: It changes status of the displayed buffer, takes next |
| 412 | * buffer from the queue and sets its address in VPIF registers |
| 413 | */ |
| 414 | static irqreturn_t vpif_channel_isr(int irq, void *dev_id) |
| 415 | { |
| 416 | struct vpif_device *dev = &vpif_obj; |
| 417 | struct channel_obj *ch; |
| 418 | struct common_obj *common; |
| 419 | enum v4l2_field field; |
| 420 | int fid = -1, i; |
| 421 | int channel_id = 0; |
| 422 | |
| 423 | channel_id = *(int *)(dev_id); |
Manjunath Hadli | b1fc423 | 2012-04-13 04:43:10 -0300 | [diff] [blame] | 424 | if (!vpif_intr_status(channel_id + 2)) |
| 425 | return IRQ_NONE; |
| 426 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 427 | ch = dev->dev[channel_id]; |
| 428 | field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field; |
| 429 | for (i = 0; i < VPIF_NUMOBJECTS; i++) { |
| 430 | common = &ch->common[i]; |
| 431 | /* If streaming is started in this channel */ |
| 432 | if (0 == common->started) |
| 433 | continue; |
| 434 | |
| 435 | if (1 == ch->vpifparams.std_info.frm_fmt) { |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 436 | spin_lock(&common->irqlock); |
| 437 | if (list_empty(&common->dma_queue)) { |
| 438 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 439 | continue; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 440 | } |
| 441 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 442 | |
| 443 | /* Progressive mode */ |
| 444 | if (!channel_first_int[i][channel_id]) { |
| 445 | /* Mark status of the cur_frm to |
| 446 | * done and unlock semaphore on it */ |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 447 | v4l2_get_timestamp(&common->cur_frm->vb. |
| 448 | v4l2_buf.timestamp); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 449 | vb2_buffer_done(&common->cur_frm->vb, |
| 450 | VB2_BUF_STATE_DONE); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 451 | /* Make cur_frm pointing to next_frm */ |
| 452 | common->cur_frm = common->next_frm; |
| 453 | } |
| 454 | |
| 455 | channel_first_int[i][channel_id] = 0; |
| 456 | process_progressive_mode(common); |
| 457 | } else { |
| 458 | /* Interlaced mode */ |
| 459 | /* If it is first interrupt, ignore it */ |
| 460 | |
| 461 | if (channel_first_int[i][channel_id]) { |
| 462 | channel_first_int[i][channel_id] = 0; |
| 463 | continue; |
| 464 | } |
| 465 | |
| 466 | if (0 == i) { |
| 467 | ch->field_id ^= 1; |
| 468 | /* Get field id from VPIF registers */ |
| 469 | fid = vpif_channel_getfid(ch->channel_id + 2); |
| 470 | /* If fid does not match with stored field id */ |
| 471 | if (fid != ch->field_id) { |
| 472 | /* Make them in sync */ |
| 473 | if (0 == fid) |
| 474 | ch->field_id = fid; |
| 475 | |
| 476 | return IRQ_HANDLED; |
| 477 | } |
| 478 | } |
| 479 | process_interlaced_mode(fid, common); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | return IRQ_HANDLED; |
| 484 | } |
| 485 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 486 | static int vpif_update_std_info(struct channel_obj *ch) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 487 | { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 488 | struct video_obj *vid_ch = &ch->video; |
| 489 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 490 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 491 | const struct vpif_channel_config_params *config; |
| 492 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 493 | int i; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 494 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 495 | for (i = 0; i < vpif_ch_params_count; i++) { |
Lad, Prabhakar | ced9b21 | 2013-03-20 01:28:27 -0300 | [diff] [blame] | 496 | config = &vpif_ch_params[i]; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 497 | if (config->hd_sd == 0) { |
| 498 | vpif_dbg(2, debug, "SD format\n"); |
| 499 | if (config->stdid & vid_ch->stdid) { |
| 500 | memcpy(std_info, config, sizeof(*config)); |
| 501 | break; |
| 502 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 506 | if (i == vpif_ch_params_count) { |
| 507 | vpif_dbg(1, debug, "Format not found\n"); |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 508 | return -EINVAL; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | static int vpif_update_resolution(struct channel_obj *ch) |
| 515 | { |
| 516 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 517 | struct video_obj *vid_ch = &ch->video; |
| 518 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 519 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 520 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 521 | if (!vid_ch->stdid && !vid_ch->dv_timings.bt.height) |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 522 | return -EINVAL; |
| 523 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 524 | if (vid_ch->stdid) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 525 | if (vpif_update_std_info(ch)) |
| 526 | return -EINVAL; |
| 527 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 528 | |
| 529 | common->fmt.fmt.pix.width = std_info->width; |
| 530 | common->fmt.fmt.pix.height = std_info->height; |
| 531 | vpif_dbg(1, debug, "Pixel details: Width = %d,Height = %d\n", |
| 532 | common->fmt.fmt.pix.width, common->fmt.fmt.pix.height); |
| 533 | |
| 534 | /* Set height and width paramateres */ |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 535 | common->height = std_info->height; |
| 536 | common->width = std_info->width; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 537 | |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * vpif_calculate_offsets: This function calculates buffers offset for Y and C |
| 543 | * in the top and bottom field |
| 544 | */ |
| 545 | static void vpif_calculate_offsets(struct channel_obj *ch) |
| 546 | { |
| 547 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 548 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 549 | enum v4l2_field field = common->fmt.fmt.pix.field; |
| 550 | struct video_obj *vid_ch = &ch->video; |
| 551 | unsigned int hpitch, vpitch, sizeimage; |
| 552 | |
| 553 | if (V4L2_FIELD_ANY == common->fmt.fmt.pix.field) { |
| 554 | if (ch->vpifparams.std_info.frm_fmt) |
| 555 | vid_ch->buf_field = V4L2_FIELD_NONE; |
| 556 | else |
| 557 | vid_ch->buf_field = V4L2_FIELD_INTERLACED; |
| 558 | } else { |
| 559 | vid_ch->buf_field = common->fmt.fmt.pix.field; |
| 560 | } |
| 561 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 562 | sizeimage = common->fmt.fmt.pix.sizeimage; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 563 | |
| 564 | hpitch = common->fmt.fmt.pix.bytesperline; |
| 565 | vpitch = sizeimage / (hpitch * 2); |
| 566 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 567 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) { |
| 568 | common->ytop_off = 0; |
| 569 | common->ybtm_off = hpitch; |
| 570 | common->ctop_off = sizeimage / 2; |
| 571 | common->cbtm_off = sizeimage / 2 + hpitch; |
| 572 | } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) { |
| 573 | common->ytop_off = 0; |
| 574 | common->ybtm_off = sizeimage / 4; |
| 575 | common->ctop_off = sizeimage / 2; |
| 576 | common->cbtm_off = common->ctop_off + sizeimage / 4; |
| 577 | } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) { |
| 578 | common->ybtm_off = 0; |
| 579 | common->ytop_off = sizeimage / 4; |
| 580 | common->cbtm_off = sizeimage / 2; |
| 581 | common->ctop_off = common->cbtm_off + sizeimage / 4; |
| 582 | } |
| 583 | |
| 584 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 585 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) { |
| 586 | vpifparams->video_params.storage_mode = 1; |
| 587 | } else { |
| 588 | vpifparams->video_params.storage_mode = 0; |
| 589 | } |
| 590 | |
| 591 | if (ch->vpifparams.std_info.frm_fmt == 1) { |
| 592 | vpifparams->video_params.hpitch = |
| 593 | common->fmt.fmt.pix.bytesperline; |
| 594 | } else { |
| 595 | if ((field == V4L2_FIELD_ANY) || |
| 596 | (field == V4L2_FIELD_INTERLACED)) |
| 597 | vpifparams->video_params.hpitch = |
| 598 | common->fmt.fmt.pix.bytesperline * 2; |
| 599 | else |
| 600 | vpifparams->video_params.hpitch = |
| 601 | common->fmt.fmt.pix.bytesperline; |
| 602 | } |
| 603 | |
| 604 | ch->vpifparams.video_params.stdid = ch->vpifparams.std_info.stdid; |
| 605 | } |
| 606 | |
| 607 | static void vpif_config_format(struct channel_obj *ch) |
| 608 | { |
| 609 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 610 | |
| 611 | common->fmt.fmt.pix.field = V4L2_FIELD_ANY; |
| 612 | if (config_params.numbuffers[ch->channel_id] == 0) |
| 613 | common->memory = V4L2_MEMORY_USERPTR; |
| 614 | else |
| 615 | common->memory = V4L2_MEMORY_MMAP; |
| 616 | |
| 617 | common->fmt.fmt.pix.sizeimage = |
| 618 | config_params.channel_bufsize[ch->channel_id]; |
| 619 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P; |
| 620 | common->fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 621 | } |
| 622 | |
| 623 | static int vpif_check_format(struct channel_obj *ch, |
| 624 | struct v4l2_pix_format *pixfmt) |
| 625 | { |
| 626 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 627 | enum v4l2_field field = pixfmt->field; |
| 628 | u32 sizeimage, hpitch, vpitch; |
| 629 | |
| 630 | if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) |
| 631 | goto invalid_fmt_exit; |
| 632 | |
| 633 | if (!(VPIF_VALID_FIELD(field))) |
| 634 | goto invalid_fmt_exit; |
| 635 | |
| 636 | if (pixfmt->bytesperline <= 0) |
| 637 | goto invalid_pitch_exit; |
| 638 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 639 | sizeimage = pixfmt->sizeimage; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 640 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 641 | if (vpif_update_resolution(ch)) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 642 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 643 | |
| 644 | hpitch = pixfmt->bytesperline; |
| 645 | vpitch = sizeimage / (hpitch * 2); |
| 646 | |
| 647 | /* Check for valid value of pitch */ |
| 648 | if ((hpitch < ch->vpifparams.std_info.width) || |
| 649 | (vpitch < ch->vpifparams.std_info.height)) |
| 650 | goto invalid_pitch_exit; |
| 651 | |
| 652 | /* Check for 8 byte alignment */ |
| 653 | if (!ISALIGNED(hpitch)) { |
| 654 | vpif_err("invalid pitch alignment\n"); |
| 655 | return -EINVAL; |
| 656 | } |
| 657 | pixfmt->width = common->fmt.fmt.pix.width; |
| 658 | pixfmt->height = common->fmt.fmt.pix.height; |
| 659 | |
| 660 | return 0; |
| 661 | |
| 662 | invalid_fmt_exit: |
| 663 | vpif_err("invalid field format\n"); |
| 664 | return -EINVAL; |
| 665 | |
| 666 | invalid_pitch_exit: |
| 667 | vpif_err("invalid pitch\n"); |
| 668 | return -EINVAL; |
| 669 | } |
| 670 | |
| 671 | static void vpif_config_addr(struct channel_obj *ch, int muxmode) |
| 672 | { |
| 673 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 674 | |
| 675 | if (VPIF_CHANNEL3_VIDEO == ch->channel_id) { |
| 676 | common->set_addr = ch3_set_videobuf_addr; |
| 677 | } else { |
| 678 | if (2 == muxmode) |
| 679 | common->set_addr = ch2_set_videobuf_addr_yc_nmux; |
| 680 | else |
| 681 | common->set_addr = ch2_set_videobuf_addr; |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | /* |
| 686 | * vpif_mmap: It is used to map kernel space buffers into user spaces |
| 687 | */ |
| 688 | static int vpif_mmap(struct file *filep, struct vm_area_struct *vma) |
| 689 | { |
| 690 | struct vpif_fh *fh = filep->private_data; |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 691 | struct channel_obj *ch = fh->channel; |
| 692 | struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]); |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 693 | int ret; |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 694 | |
| 695 | vpif_dbg(2, debug, "vpif_mmap\n"); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 696 | |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 697 | if (mutex_lock_interruptible(&common->lock)) |
| 698 | return -ERESTARTSYS; |
| 699 | ret = vb2_mmap(&common->buffer_queue, vma); |
| 700 | mutex_unlock(&common->lock); |
| 701 | return ret; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /* |
| 705 | * vpif_poll: It is used for select/poll system call |
| 706 | */ |
| 707 | static unsigned int vpif_poll(struct file *filep, poll_table *wait) |
| 708 | { |
| 709 | struct vpif_fh *fh = filep->private_data; |
| 710 | struct channel_obj *ch = fh->channel; |
| 711 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 712 | unsigned int res = 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 713 | |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 714 | if (common->started) { |
| 715 | mutex_lock(&common->lock); |
| 716 | res = vb2_poll(&common->buffer_queue, filep, wait); |
| 717 | mutex_unlock(&common->lock); |
| 718 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 719 | |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 720 | return res; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /* |
| 724 | * vpif_open: It creates object of file handle structure and stores it in |
| 725 | * private_data member of filepointer |
| 726 | */ |
| 727 | static int vpif_open(struct file *filep) |
| 728 | { |
| 729 | struct video_device *vdev = video_devdata(filep); |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 730 | struct channel_obj *ch = video_get_drvdata(vdev); |
| 731 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 732 | struct vpif_fh *fh; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 733 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 734 | /* Allocate memory for the file handle object */ |
Mats Randgaard | 1f8766b | 2010-08-30 10:30:37 -0300 | [diff] [blame] | 735 | fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 736 | if (fh == NULL) { |
| 737 | vpif_err("unable to allocate memory for file handle object\n"); |
| 738 | return -ENOMEM; |
| 739 | } |
| 740 | |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 741 | if (mutex_lock_interruptible(&common->lock)) { |
| 742 | kfree(fh); |
| 743 | return -ERESTARTSYS; |
| 744 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 745 | /* store pointer to fh in private_data member of filep */ |
| 746 | filep->private_data = fh; |
| 747 | fh->channel = ch; |
| 748 | fh->initialized = 0; |
| 749 | if (!ch->initialized) { |
| 750 | fh->initialized = 1; |
| 751 | ch->initialized = 1; |
| 752 | memset(&ch->vpifparams, 0, sizeof(ch->vpifparams)); |
| 753 | } |
| 754 | |
| 755 | /* Increment channel usrs counter */ |
| 756 | atomic_inc(&ch->usrs); |
| 757 | /* Set io_allowed[VPIF_VIDEO_INDEX] member to false */ |
| 758 | fh->io_allowed[VPIF_VIDEO_INDEX] = 0; |
| 759 | /* Initialize priority of this instance to default priority */ |
| 760 | fh->prio = V4L2_PRIORITY_UNSET; |
| 761 | v4l2_prio_open(&ch->prio, &fh->prio); |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 762 | mutex_unlock(&common->lock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | /* |
| 768 | * vpif_release: This function deletes buffer queue, frees the buffers and |
| 769 | * the vpif file handle |
| 770 | */ |
| 771 | static int vpif_release(struct file *filep) |
| 772 | { |
| 773 | struct vpif_fh *fh = filep->private_data; |
| 774 | struct channel_obj *ch = fh->channel; |
| 775 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 776 | |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 777 | mutex_lock(&common->lock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 778 | /* if this instance is doing IO */ |
| 779 | if (fh->io_allowed[VPIF_VIDEO_INDEX]) { |
| 780 | /* Reset io_usrs member of channel object */ |
| 781 | common->io_usrs = 0; |
| 782 | /* Disable channel */ |
| 783 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { |
| 784 | enable_channel2(0); |
| 785 | channel2_intr_enable(0); |
| 786 | } |
| 787 | if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) || |
| 788 | (2 == common->started)) { |
| 789 | enable_channel3(0); |
| 790 | channel3_intr_enable(0); |
| 791 | } |
| 792 | common->started = 0; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 793 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 794 | /* Free buffers allocated */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 795 | vb2_queue_release(&common->buffer_queue); |
| 796 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
| 797 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 798 | common->numbuffers = |
| 799 | config_params.numbuffers[ch->channel_id]; |
| 800 | } |
| 801 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 802 | /* Decrement channel usrs counter */ |
| 803 | atomic_dec(&ch->usrs); |
| 804 | /* If this file handle has initialize encoder device, reset it */ |
| 805 | if (fh->initialized) |
| 806 | ch->initialized = 0; |
| 807 | |
| 808 | /* Close the priority */ |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 809 | v4l2_prio_close(&ch->prio, fh->prio); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 810 | filep->private_data = NULL; |
| 811 | fh->initialized = 0; |
Hans Verkuil | 0b7286d | 2012-07-31 03:47:07 -0300 | [diff] [blame] | 812 | mutex_unlock(&common->lock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 813 | kfree(fh); |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | /* functions implementing ioctls */ |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 819 | /** |
| 820 | * vpif_querycap() - QUERYCAP handler |
| 821 | * @file: file ptr |
| 822 | * @priv: file handle |
| 823 | * @cap: ptr to v4l2_capability structure |
| 824 | */ |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 825 | static int vpif_querycap(struct file *file, void *priv, |
| 826 | struct v4l2_capability *cap) |
| 827 | { |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 828 | struct vpif_display_config *config = vpif_dev->platform_data; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 829 | |
Lad, Prabhakar | 626d533f | 2012-09-25 11:21:55 -0300 | [diff] [blame] | 830 | cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; |
| 831 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
| 832 | snprintf(cap->driver, sizeof(cap->driver), "%s", dev_name(vpif_dev)); |
| 833 | snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", |
| 834 | dev_name(vpif_dev)); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 835 | strlcpy(cap->card, config->card_name, sizeof(cap->card)); |
| 836 | |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | static int vpif_enum_fmt_vid_out(struct file *file, void *priv, |
| 841 | struct v4l2_fmtdesc *fmt) |
| 842 | { |
| 843 | if (fmt->index != 0) { |
| 844 | vpif_err("Invalid format index\n"); |
| 845 | return -EINVAL; |
| 846 | } |
| 847 | |
| 848 | /* Fill in the information about format */ |
| 849 | fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 850 | strcpy(fmt->description, "YCbCr4:2:2 YC Planar"); |
| 851 | fmt->pixelformat = V4L2_PIX_FMT_YUV422P; |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | static int vpif_g_fmt_vid_out(struct file *file, void *priv, |
| 857 | struct v4l2_format *fmt) |
| 858 | { |
| 859 | struct vpif_fh *fh = priv; |
| 860 | struct channel_obj *ch = fh->channel; |
| 861 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 862 | |
| 863 | /* Check the validity of the buffer type */ |
| 864 | if (common->fmt.type != fmt->type) |
| 865 | return -EINVAL; |
| 866 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 867 | if (vpif_update_resolution(ch)) |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 868 | return -EINVAL; |
| 869 | *fmt = common->fmt; |
| 870 | return 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static int vpif_s_fmt_vid_out(struct file *file, void *priv, |
| 874 | struct v4l2_format *fmt) |
| 875 | { |
| 876 | struct vpif_fh *fh = priv; |
| 877 | struct v4l2_pix_format *pixfmt; |
| 878 | struct channel_obj *ch = fh->channel; |
| 879 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 880 | int ret = 0; |
| 881 | |
| 882 | if ((VPIF_CHANNEL2_VIDEO == ch->channel_id) |
| 883 | || (VPIF_CHANNEL3_VIDEO == ch->channel_id)) { |
| 884 | if (!fh->initialized) { |
| 885 | vpif_dbg(1, debug, "Channel Busy\n"); |
| 886 | return -EBUSY; |
| 887 | } |
| 888 | |
| 889 | /* Check for the priority */ |
Hans Verkuil | ffb4877 | 2010-05-01 08:03:24 -0300 | [diff] [blame] | 890 | ret = v4l2_prio_check(&ch->prio, fh->prio); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 891 | if (0 != ret) |
| 892 | return ret; |
| 893 | fh->initialized = 1; |
| 894 | } |
| 895 | |
| 896 | if (common->started) { |
| 897 | vpif_dbg(1, debug, "Streaming in progress\n"); |
| 898 | return -EBUSY; |
| 899 | } |
| 900 | |
| 901 | pixfmt = &fmt->fmt.pix; |
| 902 | /* Check for valid field format */ |
| 903 | ret = vpif_check_format(ch, pixfmt); |
| 904 | if (ret) |
| 905 | return ret; |
| 906 | |
| 907 | /* store the pix format in the channel object */ |
| 908 | common->fmt.fmt.pix = *pixfmt; |
| 909 | /* store the format in the channel object */ |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 910 | common->fmt = *fmt; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | static int vpif_try_fmt_vid_out(struct file *file, void *priv, |
| 915 | struct v4l2_format *fmt) |
| 916 | { |
| 917 | struct vpif_fh *fh = priv; |
| 918 | struct channel_obj *ch = fh->channel; |
| 919 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 920 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
| 921 | int ret = 0; |
| 922 | |
| 923 | ret = vpif_check_format(ch, pixfmt); |
| 924 | if (ret) { |
| 925 | *pixfmt = common->fmt.fmt.pix; |
| 926 | pixfmt->sizeimage = pixfmt->width * pixfmt->height * 2; |
| 927 | } |
| 928 | |
| 929 | return ret; |
| 930 | } |
| 931 | |
| 932 | static int vpif_reqbufs(struct file *file, void *priv, |
| 933 | struct v4l2_requestbuffers *reqbuf) |
| 934 | { |
| 935 | struct vpif_fh *fh = priv; |
| 936 | struct channel_obj *ch = fh->channel; |
| 937 | struct common_obj *common; |
| 938 | enum v4l2_field field; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 939 | struct vb2_queue *q; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 940 | u8 index = 0; |
Lad, Prabhakar | b4a711e7 | 2012-10-03 10:01:07 -0300 | [diff] [blame] | 941 | int ret; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 942 | |
| 943 | /* This file handle has not initialized the channel, |
| 944 | It is not allowed to do settings */ |
| 945 | if ((VPIF_CHANNEL2_VIDEO == ch->channel_id) |
| 946 | || (VPIF_CHANNEL3_VIDEO == ch->channel_id)) { |
| 947 | if (!fh->initialized) { |
| 948 | vpif_err("Channel Busy\n"); |
| 949 | return -EBUSY; |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | if (V4L2_BUF_TYPE_VIDEO_OUTPUT != reqbuf->type) |
| 954 | return -EINVAL; |
| 955 | |
| 956 | index = VPIF_VIDEO_INDEX; |
| 957 | |
| 958 | common = &ch->common[index]; |
Chaithrika U S | 13df4f6 | 2009-06-22 09:02:55 -0300 | [diff] [blame] | 959 | |
Manjunath Hadli | fc613d4 | 2012-04-13 04:49:10 -0300 | [diff] [blame] | 960 | if (common->fmt.type != reqbuf->type || !vpif_dev) |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 961 | return -EINVAL; |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 962 | if (0 != common->io_usrs) |
| 963 | return -EBUSY; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 964 | |
| 965 | if (reqbuf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 966 | if (common->fmt.fmt.pix.field == V4L2_FIELD_ANY) |
| 967 | field = V4L2_FIELD_INTERLACED; |
| 968 | else |
| 969 | field = common->fmt.fmt.pix.field; |
| 970 | } else { |
| 971 | field = V4L2_VBI_INTERLACED; |
| 972 | } |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 973 | /* Initialize videobuf2 queue as per the buffer type */ |
| 974 | common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev); |
Wei Yongjun | 94b76a8 | 2012-11-15 09:18:17 -0300 | [diff] [blame] | 975 | if (IS_ERR(common->alloc_ctx)) { |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 976 | vpif_err("Failed to get the context\n"); |
Wei Yongjun | 94b76a8 | 2012-11-15 09:18:17 -0300 | [diff] [blame] | 977 | return PTR_ERR(common->alloc_ctx); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 978 | } |
| 979 | q = &common->buffer_queue; |
| 980 | q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 981 | q->io_modes = VB2_MMAP | VB2_USERPTR; |
| 982 | q->drv_priv = fh; |
| 983 | q->ops = &video_qops; |
| 984 | q->mem_ops = &vb2_dma_contig_memops; |
| 985 | q->buf_struct_size = sizeof(struct vpif_disp_buffer); |
Kamil Debski | 6aa69f9 | 2013-01-25 06:29:57 -0300 | [diff] [blame] | 986 | q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 987 | |
Lad, Prabhakar | b4a711e7 | 2012-10-03 10:01:07 -0300 | [diff] [blame] | 988 | ret = vb2_queue_init(q); |
| 989 | if (ret) { |
| 990 | vpif_err("vpif_display: vb2_queue_init() failed\n"); |
| 991 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
| 992 | return ret; |
| 993 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 994 | /* Set io allowed member of file handle to TRUE */ |
| 995 | fh->io_allowed[index] = 1; |
| 996 | /* Increment io usrs member of channel object to 1 */ |
| 997 | common->io_usrs = 1; |
| 998 | /* Store type of memory requested in channel object */ |
| 999 | common->memory = reqbuf->memory; |
| 1000 | INIT_LIST_HEAD(&common->dma_queue); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1001 | /* Allocate buffers */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1002 | return vb2_reqbufs(&common->buffer_queue, reqbuf); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | static int vpif_querybuf(struct file *file, void *priv, |
| 1006 | struct v4l2_buffer *tbuf) |
| 1007 | { |
| 1008 | struct vpif_fh *fh = priv; |
| 1009 | struct channel_obj *ch = fh->channel; |
| 1010 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1011 | |
| 1012 | if (common->fmt.type != tbuf->type) |
| 1013 | return -EINVAL; |
| 1014 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1015 | return vb2_querybuf(&common->buffer_queue, tbuf); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | static int vpif_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) |
| 1019 | { |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1020 | struct vpif_fh *fh = NULL; |
| 1021 | struct channel_obj *ch = NULL; |
| 1022 | struct common_obj *common = NULL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1023 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1024 | if (!buf || !priv) |
| 1025 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1026 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1027 | fh = priv; |
| 1028 | ch = fh->channel; |
| 1029 | if (!ch) |
| 1030 | return -EINVAL; |
| 1031 | |
| 1032 | common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 1033 | if (common->fmt.type != buf->type) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1034 | return -EINVAL; |
| 1035 | |
| 1036 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { |
| 1037 | vpif_err("fh->io_allowed\n"); |
| 1038 | return -EACCES; |
| 1039 | } |
| 1040 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1041 | return vb2_qbuf(&common->buffer_queue, buf); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1042 | } |
| 1043 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1044 | static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1045 | { |
| 1046 | struct vpif_fh *fh = priv; |
| 1047 | struct channel_obj *ch = fh->channel; |
| 1048 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1049 | int ret = 0; |
| 1050 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1051 | if (!(std_id & VPIF_V4L2_STD)) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1052 | return -EINVAL; |
| 1053 | |
| 1054 | if (common->started) { |
| 1055 | vpif_err("streaming in progress\n"); |
| 1056 | return -EBUSY; |
| 1057 | } |
| 1058 | |
| 1059 | /* Call encoder subdevice function to set the standard */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1060 | ch->video.stdid = std_id; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1061 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1062 | /* Get the information about the standard */ |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 1063 | if (vpif_update_resolution(ch)) |
| 1064 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1065 | |
| 1066 | if ((ch->vpifparams.std_info.width * |
| 1067 | ch->vpifparams.std_info.height * 2) > |
| 1068 | config_params.channel_bufsize[ch->channel_id]) { |
| 1069 | vpif_err("invalid std for this size\n"); |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 1070 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | common->fmt.fmt.pix.bytesperline = common->fmt.fmt.pix.width; |
| 1074 | /* Configure the default format information */ |
| 1075 | vpif_config_format(ch); |
| 1076 | |
| 1077 | ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video, |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1078 | s_std_output, std_id); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1079 | if (ret < 0) { |
| 1080 | vpif_err("Failed to set output standard\n"); |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 1081 | return ret; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, core, |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 1085 | s_std, std_id); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1086 | if (ret < 0) |
| 1087 | vpif_err("Failed to set standard for sub devices\n"); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1088 | return ret; |
| 1089 | } |
| 1090 | |
| 1091 | static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std) |
| 1092 | { |
| 1093 | struct vpif_fh *fh = priv; |
| 1094 | struct channel_obj *ch = fh->channel; |
| 1095 | |
| 1096 | *std = ch->video.stdid; |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
| 1100 | static int vpif_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
| 1101 | { |
| 1102 | struct vpif_fh *fh = priv; |
| 1103 | struct channel_obj *ch = fh->channel; |
| 1104 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1105 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1106 | return vb2_dqbuf(&common->buffer_queue, p, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1107 | (file->f_flags & O_NONBLOCK)); |
| 1108 | } |
| 1109 | |
| 1110 | static int vpif_streamon(struct file *file, void *priv, |
| 1111 | enum v4l2_buf_type buftype) |
| 1112 | { |
| 1113 | struct vpif_fh *fh = priv; |
| 1114 | struct channel_obj *ch = fh->channel; |
| 1115 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1116 | struct channel_obj *oth_ch = vpif_obj.dev[!ch->channel_id]; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1117 | int ret = 0; |
| 1118 | |
| 1119 | if (buftype != V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 1120 | vpif_err("buffer type not supported\n"); |
| 1121 | return -EINVAL; |
| 1122 | } |
| 1123 | |
| 1124 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { |
| 1125 | vpif_err("fh->io_allowed\n"); |
| 1126 | return -EACCES; |
| 1127 | } |
| 1128 | |
| 1129 | /* If Streaming is already started, return error */ |
| 1130 | if (common->started) { |
| 1131 | vpif_err("channel->started\n"); |
| 1132 | return -EBUSY; |
| 1133 | } |
| 1134 | |
| 1135 | if ((ch->channel_id == VPIF_CHANNEL2_VIDEO |
| 1136 | && oth_ch->common[VPIF_VIDEO_INDEX].started && |
| 1137 | ch->vpifparams.std_info.ycmux_mode == 0) |
| 1138 | || ((ch->channel_id == VPIF_CHANNEL3_VIDEO) |
| 1139 | && (2 == oth_ch->common[VPIF_VIDEO_INDEX].started))) { |
| 1140 | vpif_err("other channel is using\n"); |
| 1141 | return -EBUSY; |
| 1142 | } |
| 1143 | |
| 1144 | ret = vpif_check_format(ch, &common->fmt.fmt.pix); |
| 1145 | if (ret < 0) |
| 1146 | return ret; |
| 1147 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1148 | /* Call vb2_streamon to start streaming in videobuf2 */ |
| 1149 | ret = vb2_streamon(&common->buffer_queue, buftype); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1150 | if (ret < 0) { |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1151 | vpif_err("vb2_streamon\n"); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1152 | return ret; |
| 1153 | } |
| 1154 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1155 | return ret; |
| 1156 | } |
| 1157 | |
| 1158 | static int vpif_streamoff(struct file *file, void *priv, |
| 1159 | enum v4l2_buf_type buftype) |
| 1160 | { |
| 1161 | struct vpif_fh *fh = priv; |
| 1162 | struct channel_obj *ch = fh->channel; |
| 1163 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 1164 | struct vpif_display_config *vpif_config_data = |
| 1165 | vpif_dev->platform_data; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1166 | |
| 1167 | if (buftype != V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 1168 | vpif_err("buffer type not supported\n"); |
| 1169 | return -EINVAL; |
| 1170 | } |
| 1171 | |
| 1172 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { |
| 1173 | vpif_err("fh->io_allowed\n"); |
| 1174 | return -EACCES; |
| 1175 | } |
| 1176 | |
| 1177 | if (!common->started) { |
| 1178 | vpif_err("channel->started\n"); |
| 1179 | return -EINVAL; |
| 1180 | } |
| 1181 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1182 | if (buftype == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 1183 | /* disable channel */ |
| 1184 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1185 | if (vpif_config_data-> |
| 1186 | chan_config[VPIF_CHANNEL2_VIDEO].clip_en) |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 1187 | channel2_clipping_enable(0); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1188 | enable_channel2(0); |
| 1189 | channel2_intr_enable(0); |
| 1190 | } |
| 1191 | if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) || |
| 1192 | (2 == common->started)) { |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1193 | if (vpif_config_data-> |
| 1194 | chan_config[VPIF_CHANNEL3_VIDEO].clip_en) |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 1195 | channel3_clipping_enable(0); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1196 | enable_channel3(0); |
| 1197 | channel3_intr_enable(0); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | common->started = 0; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 1202 | return vb2_streamoff(&common->buffer_queue, buftype); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | static int vpif_cropcap(struct file *file, void *priv, |
| 1206 | struct v4l2_cropcap *crop) |
| 1207 | { |
| 1208 | struct vpif_fh *fh = priv; |
| 1209 | struct channel_obj *ch = fh->channel; |
| 1210 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1211 | if (V4L2_BUF_TYPE_VIDEO_OUTPUT != crop->type) |
| 1212 | return -EINVAL; |
| 1213 | |
| 1214 | crop->bounds.left = crop->bounds.top = 0; |
| 1215 | crop->defrect.left = crop->defrect.top = 0; |
| 1216 | crop->defrect.height = crop->bounds.height = common->height; |
| 1217 | crop->defrect.width = crop->bounds.width = common->width; |
| 1218 | |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
| 1222 | static int vpif_enum_output(struct file *file, void *fh, |
| 1223 | struct v4l2_output *output) |
| 1224 | { |
| 1225 | |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 1226 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1227 | struct vpif_display_chan_config *chan_cfg; |
| 1228 | struct vpif_fh *vpif_handler = fh; |
| 1229 | struct channel_obj *ch = vpif_handler->channel; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1230 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1231 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1232 | if (output->index >= chan_cfg->output_count) { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1233 | vpif_dbg(1, debug, "Invalid output index\n"); |
| 1234 | return -EINVAL; |
| 1235 | } |
| 1236 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1237 | *output = chan_cfg->outputs[output->index].output; |
| 1238 | return 0; |
| 1239 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1240 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1241 | /** |
| 1242 | * vpif_output_to_subdev() - Maps output to sub device |
| 1243 | * @vpif_cfg - global config ptr |
| 1244 | * @chan_cfg - channel config ptr |
| 1245 | * @index - Given output index from application |
| 1246 | * |
| 1247 | * lookup the sub device information for a given output index. |
| 1248 | * we report all the output to application. output table also |
| 1249 | * has sub device name for the each output |
| 1250 | */ |
| 1251 | static int |
| 1252 | vpif_output_to_subdev(struct vpif_display_config *vpif_cfg, |
| 1253 | struct vpif_display_chan_config *chan_cfg, int index) |
| 1254 | { |
| 1255 | struct vpif_subdev_info *subdev_info; |
| 1256 | const char *subdev_name; |
| 1257 | int i; |
| 1258 | |
| 1259 | vpif_dbg(2, debug, "vpif_output_to_subdev\n"); |
| 1260 | |
| 1261 | if (chan_cfg->outputs == NULL) |
| 1262 | return -1; |
| 1263 | |
| 1264 | subdev_name = chan_cfg->outputs[index].subdev_name; |
| 1265 | if (subdev_name == NULL) |
| 1266 | return -1; |
| 1267 | |
| 1268 | /* loop through the sub device list to get the sub device info */ |
| 1269 | for (i = 0; i < vpif_cfg->subdev_count; i++) { |
| 1270 | subdev_info = &vpif_cfg->subdevinfo[i]; |
| 1271 | if (!strcmp(subdev_info->name, subdev_name)) |
| 1272 | return i; |
| 1273 | } |
| 1274 | return -1; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * vpif_set_output() - Select an output |
| 1279 | * @vpif_cfg - global config ptr |
| 1280 | * @ch - channel |
| 1281 | * @index - Given output index from application |
| 1282 | * |
| 1283 | * Select the given output. |
| 1284 | */ |
| 1285 | static int vpif_set_output(struct vpif_display_config *vpif_cfg, |
| 1286 | struct channel_obj *ch, int index) |
| 1287 | { |
| 1288 | struct vpif_display_chan_config *chan_cfg = |
| 1289 | &vpif_cfg->chan_config[ch->channel_id]; |
| 1290 | struct vpif_subdev_info *subdev_info = NULL; |
| 1291 | struct v4l2_subdev *sd = NULL; |
| 1292 | u32 input = 0, output = 0; |
| 1293 | int sd_index; |
| 1294 | int ret; |
| 1295 | |
| 1296 | sd_index = vpif_output_to_subdev(vpif_cfg, chan_cfg, index); |
| 1297 | if (sd_index >= 0) { |
| 1298 | sd = vpif_obj.sd[sd_index]; |
| 1299 | subdev_info = &vpif_cfg->subdevinfo[sd_index]; |
| 1300 | } |
| 1301 | |
| 1302 | if (sd) { |
| 1303 | input = chan_cfg->outputs[index].input_route; |
| 1304 | output = chan_cfg->outputs[index].output_route; |
| 1305 | ret = v4l2_subdev_call(sd, video, s_routing, input, output, 0); |
| 1306 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
| 1307 | vpif_err("Failed to set output\n"); |
| 1308 | return ret; |
| 1309 | } |
| 1310 | |
| 1311 | } |
| 1312 | ch->output_idx = index; |
| 1313 | ch->sd = sd; |
| 1314 | if (chan_cfg->outputs != NULL) |
| 1315 | /* update tvnorms from the sub device output info */ |
| 1316 | ch->video_dev->tvnorms = chan_cfg->outputs[index].output.std; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1317 | return 0; |
| 1318 | } |
| 1319 | |
| 1320 | static int vpif_s_output(struct file *file, void *priv, unsigned int i) |
| 1321 | { |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1322 | struct vpif_display_config *config = vpif_dev->platform_data; |
| 1323 | struct vpif_display_chan_config *chan_cfg; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1324 | struct vpif_fh *fh = priv; |
| 1325 | struct channel_obj *ch = fh->channel; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1326 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1327 | |
| 1328 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1329 | |
| 1330 | if (i >= chan_cfg->output_count) |
| 1331 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1332 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1333 | if (common->started) { |
| 1334 | vpif_err("Streaming in progress\n"); |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 1335 | return -EBUSY; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1336 | } |
| 1337 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1338 | return vpif_set_output(config, ch, i); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | static int vpif_g_output(struct file *file, void *priv, unsigned int *i) |
| 1342 | { |
| 1343 | struct vpif_fh *fh = priv; |
| 1344 | struct channel_obj *ch = fh->channel; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1345 | |
Hans Verkuil | 311673e | 2012-09-20 09:06:23 -0300 | [diff] [blame] | 1346 | *i = ch->output_idx; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1347 | |
| 1348 | return 0; |
| 1349 | } |
| 1350 | |
| 1351 | static int vpif_g_priority(struct file *file, void *priv, enum v4l2_priority *p) |
| 1352 | { |
| 1353 | struct vpif_fh *fh = priv; |
| 1354 | struct channel_obj *ch = fh->channel; |
| 1355 | |
| 1356 | *p = v4l2_prio_max(&ch->prio); |
| 1357 | |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
| 1361 | static int vpif_s_priority(struct file *file, void *priv, enum v4l2_priority p) |
| 1362 | { |
| 1363 | struct vpif_fh *fh = priv; |
| 1364 | struct channel_obj *ch = fh->channel; |
| 1365 | |
| 1366 | return v4l2_prio_change(&ch->prio, &fh->prio, p); |
| 1367 | } |
| 1368 | |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1369 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1370 | * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1371 | * @file: file ptr |
| 1372 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1373 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1374 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1375 | static int |
| 1376 | vpif_enum_dv_timings(struct file *file, void *priv, |
| 1377 | struct v4l2_enum_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1378 | { |
| 1379 | struct vpif_fh *fh = priv; |
| 1380 | struct channel_obj *ch = fh->channel; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1381 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1382 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1383 | ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings); |
Wei Yongjun | 63af4af | 2012-10-30 09:49:38 -0300 | [diff] [blame] | 1384 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1385 | return -EINVAL; |
| 1386 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /** |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1390 | * vpif_s_dv_timings() - S_DV_TIMINGS handler |
| 1391 | * @file: file ptr |
| 1392 | * @priv: file handle |
| 1393 | * @timings: digital video timings |
| 1394 | */ |
| 1395 | static int vpif_s_dv_timings(struct file *file, void *priv, |
| 1396 | struct v4l2_dv_timings *timings) |
| 1397 | { |
| 1398 | struct vpif_fh *fh = priv; |
| 1399 | struct channel_obj *ch = fh->channel; |
| 1400 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 1401 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 1402 | struct video_obj *vid_ch = &ch->video; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1403 | struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1404 | int ret; |
| 1405 | |
| 1406 | if (timings->type != V4L2_DV_BT_656_1120) { |
| 1407 | vpif_dbg(2, debug, "Timing type not defined\n"); |
| 1408 | return -EINVAL; |
| 1409 | } |
| 1410 | |
| 1411 | /* Configure subdevice timings, if any */ |
Hans Verkuil | 882084a | 2012-09-20 09:06:31 -0300 | [diff] [blame] | 1412 | ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 1413 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 1414 | ret = 0; |
| 1415 | if (ret < 0) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1416 | vpif_dbg(2, debug, "Error setting custom DV timings\n"); |
| 1417 | return ret; |
| 1418 | } |
| 1419 | |
| 1420 | if (!(timings->bt.width && timings->bt.height && |
| 1421 | (timings->bt.hbackporch || |
| 1422 | timings->bt.hfrontporch || |
| 1423 | timings->bt.hsync) && |
| 1424 | timings->bt.vfrontporch && |
| 1425 | (timings->bt.vbackporch || |
| 1426 | timings->bt.vsync))) { |
| 1427 | vpif_dbg(2, debug, "Timings for width, height, " |
| 1428 | "horizontal back porch, horizontal sync, " |
| 1429 | "horizontal front porch, vertical back porch, " |
| 1430 | "vertical sync and vertical back porch " |
| 1431 | "must be defined\n"); |
| 1432 | return -EINVAL; |
| 1433 | } |
| 1434 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1435 | vid_ch->dv_timings = *timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1436 | |
| 1437 | /* Configure video port timings */ |
| 1438 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame^] | 1439 | std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1440 | std_info->sav2eav = bt->width; |
| 1441 | |
| 1442 | std_info->l1 = 1; |
| 1443 | std_info->l3 = bt->vsync + bt->vbackporch + 1; |
| 1444 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame^] | 1445 | std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1446 | if (bt->interlaced) { |
| 1447 | if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1448 | std_info->l5 = std_info->vsize/2 - |
| 1449 | (bt->vfrontporch - 1); |
| 1450 | std_info->l7 = std_info->vsize/2 + 1; |
| 1451 | std_info->l9 = std_info->l7 + bt->il_vsync + |
| 1452 | bt->il_vbackporch + 1; |
| 1453 | std_info->l11 = std_info->vsize - |
| 1454 | (bt->il_vfrontporch - 1); |
| 1455 | } else { |
| 1456 | vpif_dbg(2, debug, "Required timing values for " |
| 1457 | "interlaced BT format missing\n"); |
| 1458 | return -EINVAL; |
| 1459 | } |
| 1460 | } else { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1461 | std_info->l5 = std_info->vsize - (bt->vfrontporch - 1); |
| 1462 | } |
| 1463 | strncpy(std_info->name, "Custom timings BT656/1120", |
| 1464 | VPIF_MAX_NAME); |
| 1465 | std_info->width = bt->width; |
| 1466 | std_info->height = bt->height; |
| 1467 | std_info->frm_fmt = bt->interlaced ? 0 : 1; |
| 1468 | std_info->ycmux_mode = 0; |
| 1469 | std_info->capture_format = 0; |
| 1470 | std_info->vbi_supported = 0; |
| 1471 | std_info->hd_sd = 1; |
| 1472 | std_info->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1473 | vid_ch->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1474 | |
| 1475 | return 0; |
| 1476 | } |
| 1477 | |
| 1478 | /** |
| 1479 | * vpif_g_dv_timings() - G_DV_TIMINGS handler |
| 1480 | * @file: file ptr |
| 1481 | * @priv: file handle |
| 1482 | * @timings: digital video timings |
| 1483 | */ |
| 1484 | static int vpif_g_dv_timings(struct file *file, void *priv, |
| 1485 | struct v4l2_dv_timings *timings) |
| 1486 | { |
| 1487 | struct vpif_fh *fh = priv; |
| 1488 | struct channel_obj *ch = fh->channel; |
| 1489 | struct video_obj *vid_ch = &ch->video; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1490 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1491 | *timings = vid_ch->dv_timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1492 | |
| 1493 | return 0; |
| 1494 | } |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1495 | |
| 1496 | /* |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1497 | * vpif_log_status() - Status information |
| 1498 | * @file: file ptr |
| 1499 | * @priv: file handle |
| 1500 | * |
| 1501 | * Returns zero. |
| 1502 | */ |
| 1503 | static int vpif_log_status(struct file *filep, void *priv) |
| 1504 | { |
| 1505 | /* status for sub devices */ |
| 1506 | v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status); |
| 1507 | |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1511 | /* vpif display ioctl operations */ |
| 1512 | static const struct v4l2_ioctl_ops vpif_ioctl_ops = { |
| 1513 | .vidioc_querycap = vpif_querycap, |
| 1514 | .vidioc_g_priority = vpif_g_priority, |
| 1515 | .vidioc_s_priority = vpif_s_priority, |
| 1516 | .vidioc_enum_fmt_vid_out = vpif_enum_fmt_vid_out, |
| 1517 | .vidioc_g_fmt_vid_out = vpif_g_fmt_vid_out, |
| 1518 | .vidioc_s_fmt_vid_out = vpif_s_fmt_vid_out, |
| 1519 | .vidioc_try_fmt_vid_out = vpif_try_fmt_vid_out, |
| 1520 | .vidioc_reqbufs = vpif_reqbufs, |
| 1521 | .vidioc_querybuf = vpif_querybuf, |
| 1522 | .vidioc_qbuf = vpif_qbuf, |
| 1523 | .vidioc_dqbuf = vpif_dqbuf, |
| 1524 | .vidioc_streamon = vpif_streamon, |
| 1525 | .vidioc_streamoff = vpif_streamoff, |
| 1526 | .vidioc_s_std = vpif_s_std, |
| 1527 | .vidioc_g_std = vpif_g_std, |
| 1528 | .vidioc_enum_output = vpif_enum_output, |
| 1529 | .vidioc_s_output = vpif_s_output, |
| 1530 | .vidioc_g_output = vpif_g_output, |
| 1531 | .vidioc_cropcap = vpif_cropcap, |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1532 | .vidioc_enum_dv_timings = vpif_enum_dv_timings, |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1533 | .vidioc_s_dv_timings = vpif_s_dv_timings, |
| 1534 | .vidioc_g_dv_timings = vpif_g_dv_timings, |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1535 | .vidioc_log_status = vpif_log_status, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1536 | }; |
| 1537 | |
| 1538 | static const struct v4l2_file_operations vpif_fops = { |
| 1539 | .owner = THIS_MODULE, |
| 1540 | .open = vpif_open, |
| 1541 | .release = vpif_release, |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 1542 | .unlocked_ioctl = video_ioctl2, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1543 | .mmap = vpif_mmap, |
| 1544 | .poll = vpif_poll |
| 1545 | }; |
| 1546 | |
| 1547 | static struct video_device vpif_video_template = { |
| 1548 | .name = "vpif", |
| 1549 | .fops = &vpif_fops, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1550 | .ioctl_ops = &vpif_ioctl_ops, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1551 | }; |
| 1552 | |
| 1553 | /*Configure the channels, buffer sizei, request irq */ |
| 1554 | static int initialize_vpif(void) |
| 1555 | { |
| 1556 | int free_channel_objects_index; |
| 1557 | int free_buffer_channel_index; |
| 1558 | int free_buffer_index; |
| 1559 | int err = 0, i, j; |
| 1560 | |
| 1561 | /* Default number of buffers should be 3 */ |
| 1562 | if ((ch2_numbuffers > 0) && |
| 1563 | (ch2_numbuffers < config_params.min_numbuffers)) |
| 1564 | ch2_numbuffers = config_params.min_numbuffers; |
| 1565 | if ((ch3_numbuffers > 0) && |
| 1566 | (ch3_numbuffers < config_params.min_numbuffers)) |
| 1567 | ch3_numbuffers = config_params.min_numbuffers; |
| 1568 | |
| 1569 | /* Set buffer size to min buffers size if invalid buffer size is |
| 1570 | * given */ |
| 1571 | if (ch2_bufsize < config_params.min_bufsize[VPIF_CHANNEL2_VIDEO]) |
| 1572 | ch2_bufsize = |
| 1573 | config_params.min_bufsize[VPIF_CHANNEL2_VIDEO]; |
| 1574 | if (ch3_bufsize < config_params.min_bufsize[VPIF_CHANNEL3_VIDEO]) |
| 1575 | ch3_bufsize = |
| 1576 | config_params.min_bufsize[VPIF_CHANNEL3_VIDEO]; |
| 1577 | |
| 1578 | config_params.numbuffers[VPIF_CHANNEL2_VIDEO] = ch2_numbuffers; |
| 1579 | |
| 1580 | if (ch2_numbuffers) { |
| 1581 | config_params.channel_bufsize[VPIF_CHANNEL2_VIDEO] = |
| 1582 | ch2_bufsize; |
| 1583 | } |
| 1584 | config_params.numbuffers[VPIF_CHANNEL3_VIDEO] = ch3_numbuffers; |
| 1585 | |
| 1586 | if (ch3_numbuffers) { |
| 1587 | config_params.channel_bufsize[VPIF_CHANNEL3_VIDEO] = |
| 1588 | ch3_bufsize; |
| 1589 | } |
| 1590 | |
| 1591 | /* Allocate memory for six channel objects */ |
| 1592 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1593 | vpif_obj.dev[i] = |
Mats Randgaard | 1f8766b | 2010-08-30 10:30:37 -0300 | [diff] [blame] | 1594 | kzalloc(sizeof(struct channel_obj), GFP_KERNEL); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1595 | /* If memory allocation fails, return error */ |
| 1596 | if (!vpif_obj.dev[i]) { |
| 1597 | free_channel_objects_index = i; |
| 1598 | err = -ENOMEM; |
| 1599 | goto vpif_init_free_channel_objects; |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | free_channel_objects_index = VPIF_DISPLAY_MAX_DEVICES; |
| 1604 | free_buffer_channel_index = VPIF_DISPLAY_NUM_CHANNELS; |
| 1605 | free_buffer_index = config_params.numbuffers[i - 1]; |
| 1606 | |
| 1607 | return 0; |
| 1608 | |
| 1609 | vpif_init_free_channel_objects: |
| 1610 | for (j = 0; j < free_channel_objects_index; j++) |
| 1611 | kfree(vpif_obj.dev[j]); |
| 1612 | return err; |
| 1613 | } |
| 1614 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1615 | static int vpif_async_bound(struct v4l2_async_notifier *notifier, |
| 1616 | struct v4l2_subdev *subdev, |
| 1617 | struct v4l2_async_subdev *asd) |
| 1618 | { |
| 1619 | int i; |
| 1620 | |
| 1621 | for (i = 0; i < vpif_obj.config->subdev_count; i++) |
| 1622 | if (!strcmp(vpif_obj.config->subdevinfo[i].name, |
| 1623 | subdev->name)) { |
| 1624 | vpif_obj.sd[i] = subdev; |
| 1625 | vpif_obj.sd[i]->grp_id = 1 << i; |
| 1626 | return 0; |
| 1627 | } |
| 1628 | |
| 1629 | return -EINVAL; |
| 1630 | } |
| 1631 | |
| 1632 | static int vpif_probe_complete(void) |
| 1633 | { |
| 1634 | struct common_obj *common; |
| 1635 | struct channel_obj *ch; |
| 1636 | int j, err, k; |
| 1637 | |
| 1638 | for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) { |
| 1639 | ch = vpif_obj.dev[j]; |
| 1640 | /* Initialize field of the channel objects */ |
| 1641 | atomic_set(&ch->usrs, 0); |
| 1642 | for (k = 0; k < VPIF_NUMOBJECTS; k++) { |
| 1643 | ch->common[k].numbuffers = 0; |
| 1644 | common = &ch->common[k]; |
| 1645 | common->io_usrs = 0; |
| 1646 | common->started = 0; |
| 1647 | spin_lock_init(&common->irqlock); |
| 1648 | mutex_init(&common->lock); |
| 1649 | common->numbuffers = 0; |
| 1650 | common->set_addr = NULL; |
| 1651 | common->ytop_off = 0; |
| 1652 | common->ybtm_off = 0; |
| 1653 | common->ctop_off = 0; |
| 1654 | common->cbtm_off = 0; |
| 1655 | common->cur_frm = NULL; |
| 1656 | common->next_frm = NULL; |
| 1657 | memset(&common->fmt, 0, sizeof(common->fmt)); |
| 1658 | common->numbuffers = config_params.numbuffers[k]; |
| 1659 | } |
| 1660 | ch->initialized = 0; |
| 1661 | if (vpif_obj.config->subdev_count) |
| 1662 | ch->sd = vpif_obj.sd[0]; |
| 1663 | ch->channel_id = j; |
| 1664 | if (j < 2) |
| 1665 | ch->common[VPIF_VIDEO_INDEX].numbuffers = |
| 1666 | config_params.numbuffers[ch->channel_id]; |
| 1667 | else |
| 1668 | ch->common[VPIF_VIDEO_INDEX].numbuffers = 0; |
| 1669 | |
| 1670 | memset(&ch->vpifparams, 0, sizeof(ch->vpifparams)); |
| 1671 | |
| 1672 | /* Initialize prio member of channel object */ |
| 1673 | v4l2_prio_init(&ch->prio); |
| 1674 | ch->common[VPIF_VIDEO_INDEX].fmt.type = |
| 1675 | V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 1676 | ch->video_dev->lock = &common->lock; |
| 1677 | video_set_drvdata(ch->video_dev, ch); |
| 1678 | |
| 1679 | /* select output 0 */ |
| 1680 | err = vpif_set_output(vpif_obj.config, ch, 0); |
| 1681 | if (err) |
| 1682 | goto probe_out; |
| 1683 | |
| 1684 | /* register video device */ |
| 1685 | vpif_dbg(1, debug, "channel=%x,channel->video_dev=%x\n", |
| 1686 | (int)ch, (int)&ch->video_dev); |
| 1687 | |
| 1688 | err = video_register_device(ch->video_dev, |
| 1689 | VFL_TYPE_GRABBER, (j ? 3 : 2)); |
| 1690 | if (err < 0) |
| 1691 | goto probe_out; |
| 1692 | } |
| 1693 | |
| 1694 | return 0; |
| 1695 | |
| 1696 | probe_out: |
| 1697 | for (k = 0; k < j; k++) { |
| 1698 | ch = vpif_obj.dev[k]; |
| 1699 | video_unregister_device(ch->video_dev); |
| 1700 | video_device_release(ch->video_dev); |
| 1701 | ch->video_dev = NULL; |
| 1702 | } |
| 1703 | return err; |
| 1704 | } |
| 1705 | |
| 1706 | static int vpif_async_complete(struct v4l2_async_notifier *notifier) |
| 1707 | { |
| 1708 | return vpif_probe_complete(); |
| 1709 | } |
| 1710 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1711 | /* |
| 1712 | * vpif_probe: This function creates device entries by register itself to the |
| 1713 | * V4L2 driver and initializes fields of each channel objects |
| 1714 | */ |
| 1715 | static __init int vpif_probe(struct platform_device *pdev) |
| 1716 | { |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 1717 | struct vpif_subdev_info *subdevdata; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1718 | int i, j = 0, err = 0; |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1719 | int res_idx = 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1720 | struct i2c_adapter *i2c_adap; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1721 | struct channel_obj *ch; |
| 1722 | struct video_device *vfd; |
| 1723 | struct resource *res; |
| 1724 | int subdev_count; |
Manjunath Hadli | fc613d4 | 2012-04-13 04:49:10 -0300 | [diff] [blame] | 1725 | size_t size; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1726 | |
| 1727 | vpif_dev = &pdev->dev; |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 1728 | err = initialize_vpif(); |
| 1729 | |
| 1730 | if (err) { |
| 1731 | v4l2_err(vpif_dev->driver, "Error initializing vpif\n"); |
| 1732 | return err; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1733 | } |
| 1734 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1735 | err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); |
| 1736 | if (err) { |
| 1737 | v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); |
| 1738 | return err; |
| 1739 | } |
| 1740 | |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1741 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { |
Lad, Prabhakar | 379d2cf | 2013-06-17 11:20:51 -0300 | [diff] [blame] | 1742 | err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr, |
| 1743 | IRQF_SHARED, "VPIF_Display", |
| 1744 | (void *)(&vpif_obj.dev[res_idx]-> |
| 1745 | channel_id)); |
| 1746 | if (err) { |
| 1747 | err = -EINVAL; |
| 1748 | vpif_err("VPIF IRQ request failed\n"); |
| 1749 | goto vpif_unregister; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1750 | } |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1751 | res_idx++; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1755 | /* Get the pointer to the channel object */ |
| 1756 | ch = vpif_obj.dev[i]; |
| 1757 | |
| 1758 | /* Allocate memory for video device */ |
| 1759 | vfd = video_device_alloc(); |
| 1760 | if (vfd == NULL) { |
| 1761 | for (j = 0; j < i; j++) { |
| 1762 | ch = vpif_obj.dev[j]; |
| 1763 | video_device_release(ch->video_dev); |
| 1764 | } |
| 1765 | err = -ENOMEM; |
Lad, Prabhakar | 9c63e01 | 2013-06-17 11:20:50 -0300 | [diff] [blame] | 1766 | goto vpif_unregister; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /* Initialize field of video device */ |
| 1770 | *vfd = vpif_video_template; |
| 1771 | vfd->v4l2_dev = &vpif_obj.v4l2_dev; |
| 1772 | vfd->release = video_device_release; |
Hans Verkuil | 954f340 | 2012-09-05 06:05:50 -0300 | [diff] [blame] | 1773 | vfd->vfl_dir = VFL_DIR_TX; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1774 | snprintf(vfd->name, sizeof(vfd->name), |
Manjunath Hadli | 0a63172 | 2012-04-13 04:44:00 -0300 | [diff] [blame] | 1775 | "VPIF_Display_DRIVER_V%s", |
Mauro Carvalho Chehab | 64dc3c1 | 2011-06-25 11:28:37 -0300 | [diff] [blame] | 1776 | VPIF_DISPLAY_VERSION); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1777 | |
| 1778 | /* Set video_dev to the video device */ |
| 1779 | ch->video_dev = vfd; |
| 1780 | } |
| 1781 | |
Manjunath Hadli | fc613d4 | 2012-04-13 04:49:10 -0300 | [diff] [blame] | 1782 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1783 | if (res) { |
| 1784 | size = resource_size(res); |
| 1785 | /* The resources are divided into two equal memory and when |
| 1786 | * we have HD output we can add them together |
| 1787 | */ |
| 1788 | for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) { |
| 1789 | ch = vpif_obj.dev[j]; |
| 1790 | ch->channel_id = j; |
| 1791 | |
| 1792 | /* only enabled if second resource exists */ |
| 1793 | config_params.video_limit[ch->channel_id] = 0; |
| 1794 | if (size) |
| 1795 | config_params.video_limit[ch->channel_id] = |
| 1796 | size/2; |
| 1797 | } |
| 1798 | } |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1799 | vpif_obj.config = pdev->dev.platform_data; |
| 1800 | subdev_count = vpif_obj.config->subdev_count; |
| 1801 | subdevdata = vpif_obj.config->subdevinfo; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1802 | vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count, |
| 1803 | GFP_KERNEL); |
| 1804 | if (vpif_obj.sd == NULL) { |
| 1805 | vpif_err("unable to allocate memory for subdevice pointers\n"); |
| 1806 | err = -ENOMEM; |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1807 | goto vpif_sd_error; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1808 | } |
| 1809 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1810 | if (!vpif_obj.config->asd_sizes) { |
| 1811 | i2c_adap = i2c_get_adapter(1); |
| 1812 | for (i = 0; i < subdev_count; i++) { |
| 1813 | vpif_obj.sd[i] = |
| 1814 | v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, |
| 1815 | i2c_adap, |
| 1816 | &subdevdata[i]. |
| 1817 | board_info, |
| 1818 | NULL); |
| 1819 | if (!vpif_obj.sd[i]) { |
| 1820 | vpif_err("Error registering v4l2 subdevice\n"); |
| 1821 | goto probe_subdev_out; |
| 1822 | } |
| 1823 | |
| 1824 | if (vpif_obj.sd[i]) |
| 1825 | vpif_obj.sd[i]->grp_id = 1 << i; |
| 1826 | } |
| 1827 | vpif_probe_complete(); |
| 1828 | } else { |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 1829 | vpif_obj.notifier.subdevs = vpif_obj.config->asd; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1830 | vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0]; |
| 1831 | vpif_obj.notifier.bound = vpif_async_bound; |
| 1832 | vpif_obj.notifier.complete = vpif_async_complete; |
| 1833 | err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev, |
| 1834 | &vpif_obj.notifier); |
| 1835 | if (err) { |
| 1836 | vpif_err("Error registering async notifier\n"); |
| 1837 | err = -EINVAL; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1838 | goto probe_subdev_out; |
| 1839 | } |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1840 | } |
| 1841 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1842 | return 0; |
| 1843 | |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1844 | probe_subdev_out: |
| 1845 | kfree(vpif_obj.sd); |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1846 | vpif_sd_error: |
| 1847 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1848 | ch = vpif_obj.dev[i]; |
| 1849 | /* Note: does nothing if ch->video_dev == NULL */ |
| 1850 | video_device_release(ch->video_dev); |
| 1851 | } |
Lad, Prabhakar | 9c63e01 | 2013-06-17 11:20:50 -0300 | [diff] [blame] | 1852 | vpif_unregister: |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1853 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1854 | |
| 1855 | return err; |
| 1856 | } |
| 1857 | |
| 1858 | /* |
| 1859 | * vpif_remove: It un-register channels from V4L2 driver |
| 1860 | */ |
| 1861 | static int vpif_remove(struct platform_device *device) |
| 1862 | { |
| 1863 | struct channel_obj *ch; |
Lad, Prabhakar | 9c63e01 | 2013-06-17 11:20:50 -0300 | [diff] [blame] | 1864 | int i; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1865 | |
| 1866 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
| 1867 | |
Lad, Prabhakar | 0b36158 | 2013-06-17 11:20:48 -0300 | [diff] [blame] | 1868 | kfree(vpif_obj.sd); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1869 | /* un-register device */ |
| 1870 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1871 | /* Get the pointer to the channel object */ |
| 1872 | ch = vpif_obj.dev[i]; |
| 1873 | /* Unregister video device */ |
| 1874 | video_unregister_device(ch->video_dev); |
| 1875 | |
| 1876 | ch->video_dev = NULL; |
Lad, Prabhakar | 0b36158 | 2013-06-17 11:20:48 -0300 | [diff] [blame] | 1877 | kfree(vpif_obj.dev[i]); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | return 0; |
| 1881 | } |
| 1882 | |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1883 | #ifdef CONFIG_PM |
| 1884 | static int vpif_suspend(struct device *dev) |
| 1885 | { |
| 1886 | struct common_obj *common; |
| 1887 | struct channel_obj *ch; |
| 1888 | int i; |
| 1889 | |
| 1890 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1891 | /* Get the pointer to the channel object */ |
| 1892 | ch = vpif_obj.dev[i]; |
| 1893 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1894 | mutex_lock(&common->lock); |
| 1895 | if (atomic_read(&ch->usrs) && common->io_usrs) { |
| 1896 | /* Disable channel */ |
| 1897 | if (ch->channel_id == VPIF_CHANNEL2_VIDEO) { |
| 1898 | enable_channel2(0); |
| 1899 | channel2_intr_enable(0); |
| 1900 | } |
| 1901 | if (ch->channel_id == VPIF_CHANNEL3_VIDEO || |
| 1902 | common->started == 2) { |
| 1903 | enable_channel3(0); |
| 1904 | channel3_intr_enable(0); |
| 1905 | } |
| 1906 | } |
| 1907 | mutex_unlock(&common->lock); |
| 1908 | } |
| 1909 | |
| 1910 | return 0; |
| 1911 | } |
| 1912 | |
| 1913 | static int vpif_resume(struct device *dev) |
| 1914 | { |
| 1915 | |
| 1916 | struct common_obj *common; |
| 1917 | struct channel_obj *ch; |
| 1918 | int i; |
| 1919 | |
| 1920 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1921 | /* Get the pointer to the channel object */ |
| 1922 | ch = vpif_obj.dev[i]; |
| 1923 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 1924 | mutex_lock(&common->lock); |
| 1925 | if (atomic_read(&ch->usrs) && common->io_usrs) { |
| 1926 | /* Enable channel */ |
| 1927 | if (ch->channel_id == VPIF_CHANNEL2_VIDEO) { |
| 1928 | enable_channel2(1); |
| 1929 | channel2_intr_enable(1); |
| 1930 | } |
| 1931 | if (ch->channel_id == VPIF_CHANNEL3_VIDEO || |
| 1932 | common->started == 2) { |
| 1933 | enable_channel3(1); |
| 1934 | channel3_intr_enable(1); |
| 1935 | } |
| 1936 | } |
| 1937 | mutex_unlock(&common->lock); |
| 1938 | } |
| 1939 | |
| 1940 | return 0; |
| 1941 | } |
| 1942 | |
| 1943 | static const struct dev_pm_ops vpif_pm = { |
| 1944 | .suspend = vpif_suspend, |
| 1945 | .resume = vpif_resume, |
| 1946 | }; |
| 1947 | |
| 1948 | #define vpif_pm_ops (&vpif_pm) |
| 1949 | #else |
| 1950 | #define vpif_pm_ops NULL |
| 1951 | #endif |
| 1952 | |
Mats Randgaard | ffa1b39 | 2010-08-30 10:30:36 -0300 | [diff] [blame] | 1953 | static __refdata struct platform_driver vpif_driver = { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1954 | .driver = { |
| 1955 | .name = "vpif_display", |
| 1956 | .owner = THIS_MODULE, |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1957 | .pm = vpif_pm_ops, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1958 | }, |
| 1959 | .probe = vpif_probe, |
| 1960 | .remove = vpif_remove, |
| 1961 | }; |
| 1962 | |
Lad, Prabhakar | b8d067b | 2013-06-17 11:20:49 -0300 | [diff] [blame] | 1963 | module_platform_driver(vpif_driver); |