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