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