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