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/ |
Lad, Prabhakar | 96787eb | 2014-05-16 10:33:55 -0300 | [diff] [blame] | 6 | * Copyright (C) 2014 Lad, Prabhakar <prabhakar.csengg@gmail.com> |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation version 2. |
| 11 | * |
| 12 | * This program is distributed .as is. WITHOUT ANY WARRANTY of any |
| 13 | * kind, whether express or implied; without even the implied warranty |
| 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 18 | #include <linux/interrupt.h> |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 19 | #include <linux/module.h> |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 22 | |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 23 | #include <media/v4l2-ioctl.h> |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 24 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 25 | #include "vpif.h" |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 26 | #include "vpif_display.h" |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 27 | |
| 28 | MODULE_DESCRIPTION("TI DaVinci VPIF Display driver"); |
| 29 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 64dc3c1 | 2011-06-25 11:28:37 -0300 | [diff] [blame] | 30 | MODULE_VERSION(VPIF_DISPLAY_VERSION); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 31 | |
Manjunath Hadli | 0a63172 | 2012-04-13 04:44:00 -0300 | [diff] [blame] | 32 | #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] | 33 | |
| 34 | #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg) |
| 35 | #define vpif_dbg(level, debug, fmt, arg...) \ |
| 36 | v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg) |
| 37 | |
| 38 | static int debug = 1; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 39 | |
| 40 | module_param(debug, int, 0644); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 41 | |
| 42 | MODULE_PARM_DESC(debug, "Debug level 0-1"); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 43 | |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 44 | #define VPIF_DRIVER_NAME "vpif_display" |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 45 | |
| 46 | /* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */ |
| 47 | static int ycmux_mode; |
| 48 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 49 | static u8 channel_first_int[VPIF_NUMOBJECTS][2] = { {1, 1} }; |
| 50 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 51 | static struct vpif_device vpif_obj = { {NULL} }; |
| 52 | static struct device *vpif_dev; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 53 | static void vpif_calculate_offsets(struct channel_obj *ch); |
| 54 | static void vpif_config_addr(struct channel_obj *ch, int muxmode); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 55 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 56 | static inline |
| 57 | struct vpif_disp_buffer *to_vpif_buffer(struct vb2_v4l2_buffer *vb) |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 58 | { |
| 59 | return container_of(vb, struct vpif_disp_buffer, vb); |
| 60 | } |
| 61 | |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 62 | /** |
| 63 | * vpif_buffer_prepare : callback function for buffer prepare |
| 64 | * @vb: ptr to vb2_buffer |
| 65 | * |
| 66 | * This is the callback function for buffer prepare when vb2_qbuf() |
| 67 | * function is called. The buffer is prepared and user space virtual address |
| 68 | * or user address is converted into physical address |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 69 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 70 | static int vpif_buffer_prepare(struct vb2_buffer *vb) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 71 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 72 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 73 | struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 74 | struct common_obj *common; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 75 | |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 76 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 77 | |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 78 | vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage); |
| 79 | if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) |
| 80 | return -EINVAL; |
| 81 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 82 | vbuf->field = common->fmt.fmt.pix.field; |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 83 | |
| 84 | if (vb->vb2_queue->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) { |
| 85 | unsigned long addr = vb2_dma_contig_plane_dma_addr(vb, 0); |
| 86 | |
| 87 | if (!ISALIGNED(addr + common->ytop_off) || |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 88 | !ISALIGNED(addr + common->ybtm_off) || |
| 89 | !ISALIGNED(addr + common->ctop_off) || |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 90 | !ISALIGNED(addr + common->cbtm_off)) { |
| 91 | vpif_err("buffer offset not aligned to 8 bytes\n"); |
| 92 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 93 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 94 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 95 | |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 96 | return 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 97 | } |
| 98 | |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 99 | /** |
| 100 | * vpif_buffer_queue_setup : Callback function for buffer setup. |
| 101 | * @vq: vb2_queue ptr |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 102 | * @nbuffers: ptr to number of buffers requested by application |
| 103 | * @nplanes:: contains number of distinct video planes needed to hold a frame |
| 104 | * @sizes[]: contains the size (in bytes) of each plane. |
| 105 | * @alloc_ctxs: ptr to allocation context |
| 106 | * |
| 107 | * This callback function is called when reqbuf() is called to adjust |
| 108 | * the buffer count and buffer size |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 109 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 110 | static int vpif_buffer_queue_setup(struct vb2_queue *vq, |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 111 | unsigned int *nbuffers, unsigned int *nplanes, |
| 112 | unsigned int sizes[], void *alloc_ctxs[]) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 113 | { |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 114 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 115 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 116 | unsigned size = common->fmt.fmt.pix.sizeimage; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 117 | |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 118 | if (*nplanes) { |
| 119 | if (sizes[0] < size) |
| 120 | return -EINVAL; |
| 121 | size = sizes[0]; |
| 122 | } |
Manjunath Hadli | fc613d4 | 2012-04-13 04:49:10 -0300 | [diff] [blame] | 123 | |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 124 | if (vq->num_buffers + *nbuffers < 3) |
| 125 | *nbuffers = 3 - vq->num_buffers; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 126 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 127 | *nplanes = 1; |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 128 | sizes[0] = size; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 129 | alloc_ctxs[0] = common->alloc_ctx; |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 130 | |
| 131 | /* Calculate the offset for Y and C data in the buffer */ |
| 132 | vpif_calculate_offsets(ch); |
| 133 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 137 | /** |
| 138 | * vpif_buffer_queue : Callback function to add buffer to DMA queue |
| 139 | * @vb: ptr to vb2_buffer |
| 140 | * |
| 141 | * This callback fucntion queues the buffer to DMA engine |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 142 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 143 | static void vpif_buffer_queue(struct vb2_buffer *vb) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 144 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 145 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
| 146 | struct vpif_disp_buffer *buf = to_vpif_buffer(vbuf); |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 147 | struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 148 | struct common_obj *common; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 149 | unsigned long flags; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 150 | |
| 151 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 152 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 153 | /* add the buffer to the DMA queue */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 154 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 155 | list_add_tail(&buf->list, &common->dma_queue); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 156 | spin_unlock_irqrestore(&common->irqlock, flags); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 157 | } |
| 158 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 159 | /** |
| 160 | * vpif_start_streaming : Starts the DMA engine for streaming |
| 161 | * @vb: ptr to vb2_buffer |
| 162 | * @count: number of buffers |
| 163 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 164 | static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) |
| 165 | { |
| 166 | struct vpif_display_config *vpif_config_data = |
| 167 | vpif_dev->platform_data; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 168 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 169 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 170 | struct vpif_params *vpif = &ch->vpifparams; |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 171 | struct vpif_disp_buffer *buf, *tmp; |
| 172 | unsigned long addr, flags; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 173 | int ret; |
| 174 | |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 175 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 176 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 177 | /* Initialize field_id */ |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 178 | ch->field_id = 0; |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 179 | |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 180 | /* clock settings */ |
| 181 | if (vpif_config_data->set_clock) { |
| 182 | ret = vpif_config_data->set_clock(ch->vpifparams.std_info. |
| 183 | ycmux_mode, ch->vpifparams.std_info.hd_sd); |
| 184 | if (ret < 0) { |
| 185 | vpif_err("can't set clock\n"); |
| 186 | goto err; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /* set the parameters and addresses */ |
| 191 | ret = vpif_set_video_params(vpif, ch->channel_id + 2); |
| 192 | if (ret < 0) |
| 193 | goto err; |
| 194 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 195 | ycmux_mode = ret; |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 196 | vpif_config_addr(ch, ret); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 197 | /* Get the next frame from the buffer queue */ |
| 198 | common->next_frm = common->cur_frm = |
| 199 | list_entry(common->dma_queue.next, |
| 200 | struct vpif_disp_buffer, list); |
| 201 | |
| 202 | list_del(&common->cur_frm->list); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 203 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 204 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 205 | addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb.vb2_buf, 0); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 206 | common->set_addr((addr + common->ytop_off), |
| 207 | (addr + common->ybtm_off), |
| 208 | (addr + common->ctop_off), |
| 209 | (addr + common->cbtm_off)); |
| 210 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 211 | /* |
| 212 | * Set interrupt for both the fields in VPIF |
| 213 | * Register enable channel in VPIF register |
| 214 | */ |
Lad, Prabhakar | 9e18404 | 2012-09-14 10:22:24 -0300 | [diff] [blame] | 215 | channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 216 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { |
| 217 | channel2_intr_assert(); |
| 218 | channel2_intr_enable(1); |
| 219 | enable_channel2(1); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 220 | if (vpif_config_data->chan_config[VPIF_CHANNEL2_VIDEO].clip_en) |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 221 | channel2_clipping_enable(1); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 222 | } |
| 223 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 224 | if (VPIF_CHANNEL3_VIDEO == ch->channel_id || ycmux_mode == 2) { |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 225 | channel3_intr_assert(); |
| 226 | channel3_intr_enable(1); |
| 227 | enable_channel3(1); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 228 | if (vpif_config_data->chan_config[VPIF_CHANNEL3_VIDEO].clip_en) |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 229 | channel3_clipping_enable(1); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 230 | } |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 231 | |
| 232 | return 0; |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 233 | |
| 234 | err: |
| 235 | list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) { |
| 236 | list_del(&buf->list); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 237 | vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED); |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 238 | } |
Dan Carpenter | 9249196 | 2014-06-12 04:01:45 -0300 | [diff] [blame] | 239 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 240 | |
| 241 | return ret; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 242 | } |
| 243 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 244 | /** |
| 245 | * vpif_stop_streaming : Stop the DMA engine |
| 246 | * @vq: ptr to vb2_queue |
| 247 | * |
| 248 | * This callback stops the DMA engine and any remaining buffers |
| 249 | * in the DMA queue are released. |
| 250 | */ |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 251 | static void vpif_stop_streaming(struct vb2_queue *vq) |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 252 | { |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 253 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 254 | struct common_obj *common; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 255 | unsigned long flags; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 256 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 257 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 258 | |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 259 | /* Disable channel */ |
| 260 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { |
| 261 | enable_channel2(0); |
| 262 | channel2_intr_enable(0); |
| 263 | } |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 264 | if (VPIF_CHANNEL3_VIDEO == ch->channel_id || ycmux_mode == 2) { |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 265 | enable_channel3(0); |
| 266 | channel3_intr_enable(0); |
| 267 | } |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 268 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 269 | /* release all active buffers */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 270 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 271 | if (common->cur_frm == common->next_frm) { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 272 | vb2_buffer_done(&common->cur_frm->vb.vb2_buf, |
| 273 | VB2_BUF_STATE_ERROR); |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 274 | } else { |
| 275 | if (common->cur_frm != NULL) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 276 | vb2_buffer_done(&common->cur_frm->vb.vb2_buf, |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 277 | VB2_BUF_STATE_ERROR); |
| 278 | if (common->next_frm != NULL) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 279 | vb2_buffer_done(&common->next_frm->vb.vb2_buf, |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 280 | VB2_BUF_STATE_ERROR); |
| 281 | } |
| 282 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 283 | while (!list_empty(&common->dma_queue)) { |
| 284 | common->next_frm = list_entry(common->dma_queue.next, |
| 285 | struct vpif_disp_buffer, list); |
| 286 | list_del(&common->next_frm->list); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 287 | vb2_buffer_done(&common->next_frm->vb.vb2_buf, |
| 288 | VB2_BUF_STATE_ERROR); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 289 | } |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 290 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static struct vb2_ops video_qops = { |
| 294 | .queue_setup = vpif_buffer_queue_setup, |
Lad, Prabhakar | d10ed5c | 2014-05-16 10:33:08 -0300 | [diff] [blame] | 295 | .wait_prepare = vb2_ops_wait_prepare, |
| 296 | .wait_finish = vb2_ops_wait_finish, |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 297 | .buf_prepare = vpif_buffer_prepare, |
| 298 | .start_streaming = vpif_start_streaming, |
| 299 | .stop_streaming = vpif_stop_streaming, |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 300 | .buf_queue = vpif_buffer_queue, |
| 301 | }; |
| 302 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 303 | static void process_progressive_mode(struct common_obj *common) |
| 304 | { |
| 305 | unsigned long addr = 0; |
| 306 | |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 307 | spin_lock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 308 | /* Get the next buffer from buffer queue */ |
| 309 | common->next_frm = list_entry(common->dma_queue.next, |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 310 | struct vpif_disp_buffer, list); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 311 | /* Remove that buffer from the buffer queue */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 312 | list_del(&common->next_frm->list); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 313 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 314 | |
| 315 | /* Set top and bottom field addrs in VPIF registers */ |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 316 | addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb.vb2_buf, 0); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 317 | common->set_addr(addr + common->ytop_off, |
| 318 | addr + common->ybtm_off, |
| 319 | addr + common->ctop_off, |
| 320 | addr + common->cbtm_off); |
| 321 | } |
| 322 | |
| 323 | static void process_interlaced_mode(int fid, struct common_obj *common) |
| 324 | { |
| 325 | /* device field id and local field id are in sync */ |
| 326 | /* If this is even field */ |
| 327 | if (0 == fid) { |
| 328 | if (common->cur_frm == common->next_frm) |
| 329 | return; |
| 330 | |
| 331 | /* one frame is displayed If next frame is |
| 332 | * available, release cur_frm and move on */ |
| 333 | /* Copy frame display time */ |
Junghak Sung | d6dd645 | 2015-11-03 08:16:37 -0200 | [diff] [blame] | 334 | common->cur_frm->vb.vb2_buf.timestamp = ktime_get_ns(); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 335 | /* Change status of the cur_frm */ |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 336 | vb2_buffer_done(&common->cur_frm->vb.vb2_buf, |
| 337 | VB2_BUF_STATE_DONE); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 338 | /* Make cur_frm pointing to next_frm */ |
| 339 | common->cur_frm = common->next_frm; |
| 340 | |
| 341 | } else if (1 == fid) { /* odd field */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 342 | spin_lock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 343 | if (list_empty(&common->dma_queue) |
| 344 | || (common->cur_frm != common->next_frm)) { |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 345 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 346 | return; |
| 347 | } |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 348 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 349 | /* one field is displayed configure the next |
| 350 | * frame if it is available else hold on current |
| 351 | * frame */ |
| 352 | /* Get next from the buffer queue */ |
| 353 | process_progressive_mode(common); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * vpif_channel_isr: It changes status of the displayed buffer, takes next |
| 359 | * buffer from the queue and sets its address in VPIF registers |
| 360 | */ |
| 361 | static irqreturn_t vpif_channel_isr(int irq, void *dev_id) |
| 362 | { |
| 363 | struct vpif_device *dev = &vpif_obj; |
| 364 | struct channel_obj *ch; |
| 365 | struct common_obj *common; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 366 | int fid = -1, i; |
| 367 | int channel_id = 0; |
| 368 | |
| 369 | channel_id = *(int *)(dev_id); |
Manjunath Hadli | b1fc423 | 2012-04-13 04:43:10 -0300 | [diff] [blame] | 370 | if (!vpif_intr_status(channel_id + 2)) |
| 371 | return IRQ_NONE; |
| 372 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 373 | ch = dev->dev[channel_id]; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 374 | for (i = 0; i < VPIF_NUMOBJECTS; i++) { |
| 375 | common = &ch->common[i]; |
| 376 | /* If streaming is started in this channel */ |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 377 | |
| 378 | if (1 == ch->vpifparams.std_info.frm_fmt) { |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 379 | spin_lock(&common->irqlock); |
| 380 | if (list_empty(&common->dma_queue)) { |
| 381 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 382 | continue; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 383 | } |
| 384 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 385 | |
| 386 | /* Progressive mode */ |
| 387 | if (!channel_first_int[i][channel_id]) { |
| 388 | /* Mark status of the cur_frm to |
| 389 | * done and unlock semaphore on it */ |
Junghak Sung | d6dd645 | 2015-11-03 08:16:37 -0200 | [diff] [blame] | 390 | common->cur_frm->vb.vb2_buf.timestamp = |
| 391 | ktime_get_ns(); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 392 | vb2_buffer_done(&common->cur_frm->vb.vb2_buf, |
| 393 | VB2_BUF_STATE_DONE); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 394 | /* Make cur_frm pointing to next_frm */ |
| 395 | common->cur_frm = common->next_frm; |
| 396 | } |
| 397 | |
| 398 | channel_first_int[i][channel_id] = 0; |
| 399 | process_progressive_mode(common); |
| 400 | } else { |
| 401 | /* Interlaced mode */ |
| 402 | /* If it is first interrupt, ignore it */ |
| 403 | |
| 404 | if (channel_first_int[i][channel_id]) { |
| 405 | channel_first_int[i][channel_id] = 0; |
| 406 | continue; |
| 407 | } |
| 408 | |
| 409 | if (0 == i) { |
| 410 | ch->field_id ^= 1; |
| 411 | /* Get field id from VPIF registers */ |
| 412 | fid = vpif_channel_getfid(ch->channel_id + 2); |
| 413 | /* If fid does not match with stored field id */ |
| 414 | if (fid != ch->field_id) { |
| 415 | /* Make them in sync */ |
| 416 | if (0 == fid) |
| 417 | ch->field_id = fid; |
| 418 | |
| 419 | return IRQ_HANDLED; |
| 420 | } |
| 421 | } |
| 422 | process_interlaced_mode(fid, common); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | return IRQ_HANDLED; |
| 427 | } |
| 428 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 429 | static int vpif_update_std_info(struct channel_obj *ch) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 430 | { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 431 | struct video_obj *vid_ch = &ch->video; |
| 432 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 433 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 434 | const struct vpif_channel_config_params *config; |
| 435 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 436 | int i; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 437 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 438 | for (i = 0; i < vpif_ch_params_count; i++) { |
Lad, Prabhakar | ced9b21 | 2013-03-20 01:28:27 -0300 | [diff] [blame] | 439 | config = &vpif_ch_params[i]; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 440 | if (config->hd_sd == 0) { |
| 441 | vpif_dbg(2, debug, "SD format\n"); |
| 442 | if (config->stdid & vid_ch->stdid) { |
| 443 | memcpy(std_info, config, sizeof(*config)); |
| 444 | break; |
| 445 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 449 | if (i == vpif_ch_params_count) { |
| 450 | vpif_dbg(1, debug, "Format not found\n"); |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 451 | return -EINVAL; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static int vpif_update_resolution(struct channel_obj *ch) |
| 458 | { |
| 459 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 460 | struct video_obj *vid_ch = &ch->video; |
| 461 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 462 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 463 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 464 | if (!vid_ch->stdid && !vid_ch->dv_timings.bt.height) |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 465 | return -EINVAL; |
| 466 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 467 | if (vid_ch->stdid) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 468 | if (vpif_update_std_info(ch)) |
| 469 | return -EINVAL; |
| 470 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 471 | |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 472 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 473 | common->fmt.fmt.pix.width = std_info->width; |
| 474 | common->fmt.fmt.pix.height = std_info->height; |
| 475 | vpif_dbg(1, debug, "Pixel details: Width = %d,Height = %d\n", |
| 476 | common->fmt.fmt.pix.width, common->fmt.fmt.pix.height); |
| 477 | |
| 478 | /* Set height and width paramateres */ |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 479 | common->height = std_info->height; |
| 480 | common->width = std_info->width; |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 481 | common->fmt.fmt.pix.sizeimage = common->height * common->width * 2; |
| 482 | |
| 483 | if (vid_ch->stdid) |
| 484 | common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 485 | else |
| 486 | common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_REC709; |
| 487 | |
| 488 | if (ch->vpifparams.std_info.frm_fmt) |
| 489 | common->fmt.fmt.pix.field = V4L2_FIELD_NONE; |
| 490 | else |
| 491 | common->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | /* |
| 497 | * vpif_calculate_offsets: This function calculates buffers offset for Y and C |
| 498 | * in the top and bottom field |
| 499 | */ |
| 500 | static void vpif_calculate_offsets(struct channel_obj *ch) |
| 501 | { |
| 502 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 503 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 504 | enum v4l2_field field = common->fmt.fmt.pix.field; |
| 505 | struct video_obj *vid_ch = &ch->video; |
Mauro Carvalho Chehab | a4f20e2 | 2014-08-21 15:46:46 -0500 | [diff] [blame] | 506 | unsigned int hpitch, sizeimage; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 507 | |
| 508 | if (V4L2_FIELD_ANY == common->fmt.fmt.pix.field) { |
| 509 | if (ch->vpifparams.std_info.frm_fmt) |
| 510 | vid_ch->buf_field = V4L2_FIELD_NONE; |
| 511 | else |
| 512 | vid_ch->buf_field = V4L2_FIELD_INTERLACED; |
| 513 | } else { |
| 514 | vid_ch->buf_field = common->fmt.fmt.pix.field; |
| 515 | } |
| 516 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 517 | sizeimage = common->fmt.fmt.pix.sizeimage; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 518 | |
| 519 | hpitch = common->fmt.fmt.pix.bytesperline; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 520 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 521 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) { |
| 522 | common->ytop_off = 0; |
| 523 | common->ybtm_off = hpitch; |
| 524 | common->ctop_off = sizeimage / 2; |
| 525 | common->cbtm_off = sizeimage / 2 + hpitch; |
| 526 | } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) { |
| 527 | common->ytop_off = 0; |
| 528 | common->ybtm_off = sizeimage / 4; |
| 529 | common->ctop_off = sizeimage / 2; |
| 530 | common->cbtm_off = common->ctop_off + sizeimage / 4; |
| 531 | } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) { |
| 532 | common->ybtm_off = 0; |
| 533 | common->ytop_off = sizeimage / 4; |
| 534 | common->cbtm_off = sizeimage / 2; |
| 535 | common->ctop_off = common->cbtm_off + sizeimage / 4; |
| 536 | } |
| 537 | |
| 538 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 539 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) { |
| 540 | vpifparams->video_params.storage_mode = 1; |
| 541 | } else { |
| 542 | vpifparams->video_params.storage_mode = 0; |
| 543 | } |
| 544 | |
| 545 | if (ch->vpifparams.std_info.frm_fmt == 1) { |
| 546 | vpifparams->video_params.hpitch = |
| 547 | common->fmt.fmt.pix.bytesperline; |
| 548 | } else { |
| 549 | if ((field == V4L2_FIELD_ANY) || |
| 550 | (field == V4L2_FIELD_INTERLACED)) |
| 551 | vpifparams->video_params.hpitch = |
| 552 | common->fmt.fmt.pix.bytesperline * 2; |
| 553 | else |
| 554 | vpifparams->video_params.hpitch = |
| 555 | common->fmt.fmt.pix.bytesperline; |
| 556 | } |
| 557 | |
| 558 | ch->vpifparams.video_params.stdid = ch->vpifparams.std_info.stdid; |
| 559 | } |
| 560 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 561 | static void vpif_config_addr(struct channel_obj *ch, int muxmode) |
| 562 | { |
| 563 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 564 | |
| 565 | if (VPIF_CHANNEL3_VIDEO == ch->channel_id) { |
| 566 | common->set_addr = ch3_set_videobuf_addr; |
| 567 | } else { |
| 568 | if (2 == muxmode) |
| 569 | common->set_addr = ch2_set_videobuf_addr_yc_nmux; |
| 570 | else |
| 571 | common->set_addr = ch2_set_videobuf_addr; |
| 572 | } |
| 573 | } |
| 574 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 575 | /* functions implementing ioctls */ |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 576 | /** |
| 577 | * vpif_querycap() - QUERYCAP handler |
| 578 | * @file: file ptr |
| 579 | * @priv: file handle |
| 580 | * @cap: ptr to v4l2_capability structure |
| 581 | */ |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 582 | static int vpif_querycap(struct file *file, void *priv, |
| 583 | struct v4l2_capability *cap) |
| 584 | { |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 585 | struct vpif_display_config *config = vpif_dev->platform_data; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 586 | |
Lad, Prabhakar | 626d533f | 2012-09-25 11:21:55 -0300 | [diff] [blame] | 587 | cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; |
| 588 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 589 | strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver)); |
Lad, Prabhakar | 626d533f | 2012-09-25 11:21:55 -0300 | [diff] [blame] | 590 | snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", |
| 591 | dev_name(vpif_dev)); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 592 | strlcpy(cap->card, config->card_name, sizeof(cap->card)); |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | static int vpif_enum_fmt_vid_out(struct file *file, void *priv, |
| 598 | struct v4l2_fmtdesc *fmt) |
| 599 | { |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 600 | if (fmt->index != 0) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 601 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 602 | |
| 603 | /* Fill in the information about format */ |
| 604 | fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 605 | strcpy(fmt->description, "YCbCr4:2:2 YC Planar"); |
| 606 | fmt->pixelformat = V4L2_PIX_FMT_YUV422P; |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 607 | fmt->flags = 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | static int vpif_g_fmt_vid_out(struct file *file, void *priv, |
| 612 | struct v4l2_format *fmt) |
| 613 | { |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 614 | struct video_device *vdev = video_devdata(file); |
| 615 | struct channel_obj *ch = video_get_drvdata(vdev); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 616 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 617 | |
| 618 | /* Check the validity of the buffer type */ |
| 619 | if (common->fmt.type != fmt->type) |
| 620 | return -EINVAL; |
| 621 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 622 | if (vpif_update_resolution(ch)) |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 623 | return -EINVAL; |
| 624 | *fmt = common->fmt; |
| 625 | return 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 626 | } |
| 627 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 628 | static int vpif_try_fmt_vid_out(struct file *file, void *priv, |
| 629 | struct v4l2_format *fmt) |
| 630 | { |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 631 | struct video_device *vdev = video_devdata(file); |
| 632 | struct channel_obj *ch = video_get_drvdata(vdev); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 633 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 634 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 635 | |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 636 | /* |
| 637 | * to supress v4l-compliance warnings silently correct |
| 638 | * the pixelformat |
| 639 | */ |
| 640 | if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) |
| 641 | pixfmt->pixelformat = common->fmt.fmt.pix.pixelformat; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 642 | |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 643 | if (vpif_update_resolution(ch)) |
| 644 | return -EINVAL; |
| 645 | |
| 646 | pixfmt->colorspace = common->fmt.fmt.pix.colorspace; |
| 647 | pixfmt->field = common->fmt.fmt.pix.field; |
| 648 | pixfmt->bytesperline = common->fmt.fmt.pix.width; |
| 649 | pixfmt->width = common->fmt.fmt.pix.width; |
| 650 | pixfmt->height = common->fmt.fmt.pix.height; |
| 651 | pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height * 2; |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 652 | |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | static int vpif_s_fmt_vid_out(struct file *file, void *priv, |
| 657 | struct v4l2_format *fmt) |
| 658 | { |
| 659 | struct video_device *vdev = video_devdata(file); |
| 660 | struct channel_obj *ch = video_get_drvdata(vdev); |
| 661 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 662 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
| 663 | int ret; |
| 664 | |
| 665 | if (vb2_is_busy(&common->buffer_queue)) |
| 666 | return -EBUSY; |
| 667 | |
| 668 | ret = vpif_try_fmt_vid_out(file, priv, fmt); |
| 669 | if (ret) |
| 670 | return ret; |
| 671 | |
| 672 | /* store the pix format in the channel object */ |
| 673 | common->fmt.fmt.pix = *pixfmt; |
| 674 | |
| 675 | /* store the format in the channel object */ |
| 676 | common->fmt = *fmt; |
| 677 | return 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 678 | } |
| 679 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 680 | static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 681 | { |
Lad, Prabhakar | f27d0f4 | 2014-05-16 10:33:28 -0300 | [diff] [blame] | 682 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 683 | struct video_device *vdev = video_devdata(file); |
| 684 | struct channel_obj *ch = video_get_drvdata(vdev); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 685 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | f27d0f4 | 2014-05-16 10:33:28 -0300 | [diff] [blame] | 686 | struct vpif_display_chan_config *chan_cfg; |
| 687 | struct v4l2_output output; |
| 688 | int ret; |
| 689 | |
| 690 | if (config->chan_config[ch->channel_id].outputs == NULL) |
| 691 | return -ENODATA; |
| 692 | |
| 693 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 694 | output = chan_cfg->outputs[ch->output_idx].output; |
| 695 | if (output.capabilities != V4L2_OUT_CAP_STD) |
| 696 | return -ENODATA; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 697 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 698 | if (vb2_is_busy(&common->buffer_queue)) |
| 699 | return -EBUSY; |
| 700 | |
Lad, Prabhakar | f27d0f4 | 2014-05-16 10:33:28 -0300 | [diff] [blame] | 701 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 702 | if (!(std_id & VPIF_V4L2_STD)) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 703 | return -EINVAL; |
| 704 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 705 | /* Call encoder subdevice function to set the standard */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 706 | ch->video.stdid = std_id; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 707 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 708 | /* Get the information about the standard */ |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 709 | if (vpif_update_resolution(ch)) |
| 710 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 711 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 712 | common->fmt.fmt.pix.bytesperline = common->fmt.fmt.pix.width; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 713 | |
| 714 | ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video, |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 715 | s_std_output, std_id); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 716 | if (ret < 0) { |
| 717 | vpif_err("Failed to set output standard\n"); |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 718 | return ret; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 719 | } |
| 720 | |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 721 | ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video, |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 722 | s_std, std_id); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 723 | if (ret < 0) |
| 724 | vpif_err("Failed to set standard for sub devices\n"); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 725 | return ret; |
| 726 | } |
| 727 | |
| 728 | static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std) |
| 729 | { |
Lad, Prabhakar | f27d0f4 | 2014-05-16 10:33:28 -0300 | [diff] [blame] | 730 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 731 | struct video_device *vdev = video_devdata(file); |
| 732 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | f27d0f4 | 2014-05-16 10:33:28 -0300 | [diff] [blame] | 733 | struct vpif_display_chan_config *chan_cfg; |
| 734 | struct v4l2_output output; |
| 735 | |
| 736 | if (config->chan_config[ch->channel_id].outputs == NULL) |
| 737 | return -ENODATA; |
| 738 | |
| 739 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 740 | output = chan_cfg->outputs[ch->output_idx].output; |
| 741 | if (output.capabilities != V4L2_OUT_CAP_STD) |
| 742 | return -ENODATA; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 743 | |
| 744 | *std = ch->video.stdid; |
| 745 | return 0; |
| 746 | } |
| 747 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 748 | static int vpif_enum_output(struct file *file, void *fh, |
| 749 | struct v4l2_output *output) |
| 750 | { |
| 751 | |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 752 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 753 | struct video_device *vdev = video_devdata(file); |
| 754 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 755 | struct vpif_display_chan_config *chan_cfg; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 756 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 757 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 758 | if (output->index >= chan_cfg->output_count) { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 759 | vpif_dbg(1, debug, "Invalid output index\n"); |
| 760 | return -EINVAL; |
| 761 | } |
| 762 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 763 | *output = chan_cfg->outputs[output->index].output; |
| 764 | return 0; |
| 765 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 766 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 767 | /** |
| 768 | * vpif_output_to_subdev() - Maps output to sub device |
| 769 | * @vpif_cfg - global config ptr |
| 770 | * @chan_cfg - channel config ptr |
| 771 | * @index - Given output index from application |
| 772 | * |
| 773 | * lookup the sub device information for a given output index. |
| 774 | * we report all the output to application. output table also |
| 775 | * has sub device name for the each output |
| 776 | */ |
| 777 | static int |
| 778 | vpif_output_to_subdev(struct vpif_display_config *vpif_cfg, |
| 779 | struct vpif_display_chan_config *chan_cfg, int index) |
| 780 | { |
| 781 | struct vpif_subdev_info *subdev_info; |
| 782 | const char *subdev_name; |
| 783 | int i; |
| 784 | |
| 785 | vpif_dbg(2, debug, "vpif_output_to_subdev\n"); |
| 786 | |
| 787 | if (chan_cfg->outputs == NULL) |
| 788 | return -1; |
| 789 | |
| 790 | subdev_name = chan_cfg->outputs[index].subdev_name; |
| 791 | if (subdev_name == NULL) |
| 792 | return -1; |
| 793 | |
| 794 | /* loop through the sub device list to get the sub device info */ |
| 795 | for (i = 0; i < vpif_cfg->subdev_count; i++) { |
| 796 | subdev_info = &vpif_cfg->subdevinfo[i]; |
| 797 | if (!strcmp(subdev_info->name, subdev_name)) |
| 798 | return i; |
| 799 | } |
| 800 | return -1; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * vpif_set_output() - Select an output |
| 805 | * @vpif_cfg - global config ptr |
| 806 | * @ch - channel |
| 807 | * @index - Given output index from application |
| 808 | * |
| 809 | * Select the given output. |
| 810 | */ |
| 811 | static int vpif_set_output(struct vpif_display_config *vpif_cfg, |
| 812 | struct channel_obj *ch, int index) |
| 813 | { |
| 814 | struct vpif_display_chan_config *chan_cfg = |
| 815 | &vpif_cfg->chan_config[ch->channel_id]; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 816 | struct v4l2_subdev *sd = NULL; |
| 817 | u32 input = 0, output = 0; |
| 818 | int sd_index; |
| 819 | int ret; |
| 820 | |
| 821 | sd_index = vpif_output_to_subdev(vpif_cfg, chan_cfg, index); |
Mauro Carvalho Chehab | a4f20e2 | 2014-08-21 15:46:46 -0500 | [diff] [blame] | 822 | if (sd_index >= 0) |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 823 | sd = vpif_obj.sd[sd_index]; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 824 | |
| 825 | if (sd) { |
| 826 | input = chan_cfg->outputs[index].input_route; |
| 827 | output = chan_cfg->outputs[index].output_route; |
| 828 | ret = v4l2_subdev_call(sd, video, s_routing, input, output, 0); |
| 829 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
| 830 | vpif_err("Failed to set output\n"); |
| 831 | return ret; |
| 832 | } |
| 833 | |
| 834 | } |
| 835 | ch->output_idx = index; |
| 836 | ch->sd = sd; |
| 837 | if (chan_cfg->outputs != NULL) |
| 838 | /* update tvnorms from the sub device output info */ |
Lad, Prabhakar | e933c6b | 2015-03-08 18:57:24 -0300 | [diff] [blame] | 839 | ch->video_dev.tvnorms = chan_cfg->outputs[index].output.std; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static int vpif_s_output(struct file *file, void *priv, unsigned int i) |
| 844 | { |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 845 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 846 | struct video_device *vdev = video_devdata(file); |
| 847 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 848 | struct vpif_display_chan_config *chan_cfg; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 849 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 850 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 851 | if (vb2_is_busy(&common->buffer_queue)) |
| 852 | return -EBUSY; |
| 853 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 854 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 855 | |
| 856 | if (i >= chan_cfg->output_count) |
| 857 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 858 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 859 | return vpif_set_output(config, ch, i); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | static int vpif_g_output(struct file *file, void *priv, unsigned int *i) |
| 863 | { |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 864 | struct video_device *vdev = video_devdata(file); |
| 865 | struct channel_obj *ch = video_get_drvdata(vdev); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 866 | |
Hans Verkuil | 311673e | 2012-09-20 09:06:23 -0300 | [diff] [blame] | 867 | *i = ch->output_idx; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 872 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 873 | * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 874 | * @file: file ptr |
| 875 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 876 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 877 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 878 | static int |
| 879 | vpif_enum_dv_timings(struct file *file, void *priv, |
| 880 | struct v4l2_enum_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 881 | { |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 882 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 883 | struct video_device *vdev = video_devdata(file); |
| 884 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 885 | struct vpif_display_chan_config *chan_cfg; |
| 886 | struct v4l2_output output; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 887 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 888 | |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 889 | if (config->chan_config[ch->channel_id].outputs == NULL) |
| 890 | return -ENODATA; |
| 891 | |
| 892 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 893 | output = chan_cfg->outputs[ch->output_idx].output; |
| 894 | if (output.capabilities != V4L2_OUT_CAP_DV_TIMINGS) |
| 895 | return -ENODATA; |
| 896 | |
Laurent Pinchart | 10d2146 | 2014-01-31 09:04:19 -0300 | [diff] [blame] | 897 | timings->pad = 0; |
| 898 | |
| 899 | ret = v4l2_subdev_call(ch->sd, pad, enum_dv_timings, timings); |
Wei Yongjun | 63af4af | 2012-10-30 09:49:38 -0300 | [diff] [blame] | 900 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 901 | return -EINVAL; |
| 902 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | /** |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 906 | * vpif_s_dv_timings() - S_DV_TIMINGS handler |
| 907 | * @file: file ptr |
| 908 | * @priv: file handle |
| 909 | * @timings: digital video timings |
| 910 | */ |
| 911 | static int vpif_s_dv_timings(struct file *file, void *priv, |
| 912 | struct v4l2_dv_timings *timings) |
| 913 | { |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 914 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 915 | struct video_device *vdev = video_devdata(file); |
| 916 | struct channel_obj *ch = video_get_drvdata(vdev); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 917 | struct vpif_params *vpifparams = &ch->vpifparams; |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 918 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 919 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 920 | struct video_obj *vid_ch = &ch->video; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 921 | struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt; |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 922 | struct vpif_display_chan_config *chan_cfg; |
| 923 | struct v4l2_output output; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 924 | int ret; |
| 925 | |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 926 | if (config->chan_config[ch->channel_id].outputs == NULL) |
| 927 | return -ENODATA; |
| 928 | |
| 929 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 930 | output = chan_cfg->outputs[ch->output_idx].output; |
| 931 | if (output.capabilities != V4L2_OUT_CAP_DV_TIMINGS) |
| 932 | return -ENODATA; |
| 933 | |
| 934 | if (vb2_is_busy(&common->buffer_queue)) |
| 935 | return -EBUSY; |
| 936 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 937 | if (timings->type != V4L2_DV_BT_656_1120) { |
| 938 | vpif_dbg(2, debug, "Timing type not defined\n"); |
| 939 | return -EINVAL; |
| 940 | } |
| 941 | |
| 942 | /* Configure subdevice timings, if any */ |
Hans Verkuil | 882084a | 2012-09-20 09:06:31 -0300 | [diff] [blame] | 943 | ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 944 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 945 | ret = 0; |
| 946 | if (ret < 0) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 947 | vpif_dbg(2, debug, "Error setting custom DV timings\n"); |
| 948 | return ret; |
| 949 | } |
| 950 | |
| 951 | if (!(timings->bt.width && timings->bt.height && |
| 952 | (timings->bt.hbackporch || |
| 953 | timings->bt.hfrontporch || |
| 954 | timings->bt.hsync) && |
| 955 | timings->bt.vfrontporch && |
| 956 | (timings->bt.vbackporch || |
| 957 | timings->bt.vsync))) { |
| 958 | vpif_dbg(2, debug, "Timings for width, height, " |
| 959 | "horizontal back porch, horizontal sync, " |
| 960 | "horizontal front porch, vertical back porch, " |
| 961 | "vertical sync and vertical back porch " |
| 962 | "must be defined\n"); |
| 963 | return -EINVAL; |
| 964 | } |
| 965 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 966 | vid_ch->dv_timings = *timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 967 | |
| 968 | /* Configure video port timings */ |
| 969 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame] | 970 | std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 971 | std_info->sav2eav = bt->width; |
| 972 | |
| 973 | std_info->l1 = 1; |
| 974 | std_info->l3 = bt->vsync + bt->vbackporch + 1; |
| 975 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame] | 976 | std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 977 | if (bt->interlaced) { |
| 978 | if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 979 | std_info->l5 = std_info->vsize/2 - |
| 980 | (bt->vfrontporch - 1); |
| 981 | std_info->l7 = std_info->vsize/2 + 1; |
| 982 | std_info->l9 = std_info->l7 + bt->il_vsync + |
| 983 | bt->il_vbackporch + 1; |
| 984 | std_info->l11 = std_info->vsize - |
| 985 | (bt->il_vfrontporch - 1); |
| 986 | } else { |
| 987 | vpif_dbg(2, debug, "Required timing values for " |
| 988 | "interlaced BT format missing\n"); |
| 989 | return -EINVAL; |
| 990 | } |
| 991 | } else { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 992 | std_info->l5 = std_info->vsize - (bt->vfrontporch - 1); |
| 993 | } |
| 994 | strncpy(std_info->name, "Custom timings BT656/1120", |
| 995 | VPIF_MAX_NAME); |
| 996 | std_info->width = bt->width; |
| 997 | std_info->height = bt->height; |
| 998 | std_info->frm_fmt = bt->interlaced ? 0 : 1; |
| 999 | std_info->ycmux_mode = 0; |
| 1000 | std_info->capture_format = 0; |
| 1001 | std_info->vbi_supported = 0; |
| 1002 | std_info->hd_sd = 1; |
| 1003 | std_info->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1004 | vid_ch->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1005 | |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * vpif_g_dv_timings() - G_DV_TIMINGS handler |
| 1011 | * @file: file ptr |
| 1012 | * @priv: file handle |
| 1013 | * @timings: digital video timings |
| 1014 | */ |
| 1015 | static int vpif_g_dv_timings(struct file *file, void *priv, |
| 1016 | struct v4l2_dv_timings *timings) |
| 1017 | { |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 1018 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 1019 | struct video_device *vdev = video_devdata(file); |
| 1020 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 1021 | struct vpif_display_chan_config *chan_cfg; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1022 | struct video_obj *vid_ch = &ch->video; |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 1023 | struct v4l2_output output; |
| 1024 | |
| 1025 | if (config->chan_config[ch->channel_id].outputs == NULL) |
| 1026 | goto error; |
| 1027 | |
| 1028 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1029 | output = chan_cfg->outputs[ch->output_idx].output; |
| 1030 | |
| 1031 | if (output.capabilities != V4L2_OUT_CAP_DV_TIMINGS) |
| 1032 | goto error; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1033 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1034 | *timings = vid_ch->dv_timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1035 | |
| 1036 | return 0; |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 1037 | error: |
| 1038 | return -ENODATA; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1039 | } |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1040 | |
| 1041 | /* |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1042 | * vpif_log_status() - Status information |
| 1043 | * @file: file ptr |
| 1044 | * @priv: file handle |
| 1045 | * |
| 1046 | * Returns zero. |
| 1047 | */ |
| 1048 | static int vpif_log_status(struct file *filep, void *priv) |
| 1049 | { |
| 1050 | /* status for sub devices */ |
| 1051 | v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status); |
| 1052 | |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1056 | /* vpif display ioctl operations */ |
| 1057 | static const struct v4l2_ioctl_ops vpif_ioctl_ops = { |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1058 | .vidioc_querycap = vpif_querycap, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1059 | .vidioc_enum_fmt_vid_out = vpif_enum_fmt_vid_out, |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1060 | .vidioc_g_fmt_vid_out = vpif_g_fmt_vid_out, |
| 1061 | .vidioc_s_fmt_vid_out = vpif_s_fmt_vid_out, |
| 1062 | .vidioc_try_fmt_vid_out = vpif_try_fmt_vid_out, |
Lad, Prabhakar | b92cde1 | 2014-05-16 10:33:16 -0300 | [diff] [blame] | 1063 | |
| 1064 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 1065 | .vidioc_create_bufs = vb2_ioctl_create_bufs, |
| 1066 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 1067 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 1068 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
| 1069 | .vidioc_expbuf = vb2_ioctl_expbuf, |
| 1070 | .vidioc_streamon = vb2_ioctl_streamon, |
| 1071 | .vidioc_streamoff = vb2_ioctl_streamoff, |
| 1072 | |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1073 | .vidioc_s_std = vpif_s_std, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1074 | .vidioc_g_std = vpif_g_std, |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1075 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1076 | .vidioc_enum_output = vpif_enum_output, |
| 1077 | .vidioc_s_output = vpif_s_output, |
| 1078 | .vidioc_g_output = vpif_g_output, |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1079 | |
| 1080 | .vidioc_enum_dv_timings = vpif_enum_dv_timings, |
| 1081 | .vidioc_s_dv_timings = vpif_s_dv_timings, |
| 1082 | .vidioc_g_dv_timings = vpif_g_dv_timings, |
| 1083 | |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1084 | .vidioc_log_status = vpif_log_status, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1085 | }; |
| 1086 | |
| 1087 | static const struct v4l2_file_operations vpif_fops = { |
| 1088 | .owner = THIS_MODULE, |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 1089 | .open = v4l2_fh_open, |
| 1090 | .release = vb2_fop_release, |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 1091 | .unlocked_ioctl = video_ioctl2, |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1092 | .mmap = vb2_fop_mmap, |
| 1093 | .poll = vb2_fop_poll |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1094 | }; |
| 1095 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1096 | /*Configure the channels, buffer sizei, request irq */ |
| 1097 | static int initialize_vpif(void) |
| 1098 | { |
| 1099 | int free_channel_objects_index; |
Lad, Prabhakar | d5b94b9 | 2014-05-16 10:33:23 -0300 | [diff] [blame] | 1100 | int err, i, j; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1101 | |
| 1102 | /* Allocate memory for six channel objects */ |
| 1103 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1104 | vpif_obj.dev[i] = |
Mats Randgaard | 1f8766b | 2010-08-30 10:30:37 -0300 | [diff] [blame] | 1105 | kzalloc(sizeof(struct channel_obj), GFP_KERNEL); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1106 | /* If memory allocation fails, return error */ |
| 1107 | if (!vpif_obj.dev[i]) { |
| 1108 | free_channel_objects_index = i; |
| 1109 | err = -ENOMEM; |
| 1110 | goto vpif_init_free_channel_objects; |
| 1111 | } |
| 1112 | } |
| 1113 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1114 | return 0; |
| 1115 | |
| 1116 | vpif_init_free_channel_objects: |
| 1117 | for (j = 0; j < free_channel_objects_index; j++) |
| 1118 | kfree(vpif_obj.dev[j]); |
| 1119 | return err; |
| 1120 | } |
| 1121 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1122 | static int vpif_async_bound(struct v4l2_async_notifier *notifier, |
| 1123 | struct v4l2_subdev *subdev, |
| 1124 | struct v4l2_async_subdev *asd) |
| 1125 | { |
| 1126 | int i; |
| 1127 | |
| 1128 | for (i = 0; i < vpif_obj.config->subdev_count; i++) |
| 1129 | if (!strcmp(vpif_obj.config->subdevinfo[i].name, |
| 1130 | subdev->name)) { |
| 1131 | vpif_obj.sd[i] = subdev; |
| 1132 | vpif_obj.sd[i]->grp_id = 1 << i; |
| 1133 | return 0; |
| 1134 | } |
| 1135 | |
| 1136 | return -EINVAL; |
| 1137 | } |
| 1138 | |
| 1139 | static int vpif_probe_complete(void) |
| 1140 | { |
| 1141 | struct common_obj *common; |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1142 | struct video_device *vdev; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1143 | struct channel_obj *ch; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1144 | struct vb2_queue *q; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1145 | int j, err, k; |
| 1146 | |
| 1147 | for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) { |
| 1148 | ch = vpif_obj.dev[j]; |
| 1149 | /* Initialize field of the channel objects */ |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1150 | for (k = 0; k < VPIF_NUMOBJECTS; k++) { |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1151 | common = &ch->common[k]; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1152 | spin_lock_init(&common->irqlock); |
| 1153 | mutex_init(&common->lock); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1154 | common->set_addr = NULL; |
| 1155 | common->ytop_off = 0; |
| 1156 | common->ybtm_off = 0; |
| 1157 | common->ctop_off = 0; |
| 1158 | common->cbtm_off = 0; |
| 1159 | common->cur_frm = NULL; |
| 1160 | common->next_frm = NULL; |
| 1161 | memset(&common->fmt, 0, sizeof(common->fmt)); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1162 | } |
| 1163 | ch->initialized = 0; |
| 1164 | if (vpif_obj.config->subdev_count) |
| 1165 | ch->sd = vpif_obj.sd[0]; |
| 1166 | ch->channel_id = j; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1167 | |
| 1168 | memset(&ch->vpifparams, 0, sizeof(ch->vpifparams)); |
| 1169 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1170 | ch->common[VPIF_VIDEO_INDEX].fmt.type = |
| 1171 | V4L2_BUF_TYPE_VIDEO_OUTPUT; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1172 | |
| 1173 | /* select output 0 */ |
| 1174 | err = vpif_set_output(vpif_obj.config, ch, 0); |
| 1175 | if (err) |
| 1176 | goto probe_out; |
| 1177 | |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 1178 | /* set initial format */ |
| 1179 | ch->video.stdid = V4L2_STD_525_60; |
| 1180 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
| 1181 | vpif_update_resolution(ch); |
| 1182 | |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1183 | /* Initialize vb2 queue */ |
| 1184 | q = &common->buffer_queue; |
| 1185 | q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 1186 | q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
| 1187 | q->drv_priv = ch; |
| 1188 | q->ops = &video_qops; |
| 1189 | q->mem_ops = &vb2_dma_contig_memops; |
| 1190 | q->buf_struct_size = sizeof(struct vpif_disp_buffer); |
| 1191 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
| 1192 | q->min_buffers_needed = 1; |
Lad, Prabhakar | d10ed5c | 2014-05-16 10:33:08 -0300 | [diff] [blame] | 1193 | q->lock = &common->lock; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1194 | err = vb2_queue_init(q); |
| 1195 | if (err) { |
| 1196 | vpif_err("vpif_display: vb2_queue_init() failed\n"); |
| 1197 | goto probe_out; |
| 1198 | } |
| 1199 | |
| 1200 | common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev); |
| 1201 | if (IS_ERR(common->alloc_ctx)) { |
| 1202 | vpif_err("Failed to get the context\n"); |
| 1203 | err = PTR_ERR(common->alloc_ctx); |
| 1204 | goto probe_out; |
| 1205 | } |
| 1206 | |
| 1207 | INIT_LIST_HEAD(&common->dma_queue); |
| 1208 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1209 | /* register video device */ |
Mauro Carvalho Chehab | 212bdba | 2014-08-22 06:38:14 -0500 | [diff] [blame] | 1210 | vpif_dbg(1, debug, "channel=%p,channel->video_dev=%p\n", |
| 1211 | ch, &ch->video_dev); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1212 | |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1213 | /* Initialize the video_device structure */ |
Lad, Prabhakar | e933c6b | 2015-03-08 18:57:24 -0300 | [diff] [blame] | 1214 | vdev = &ch->video_dev; |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1215 | strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name)); |
Lad, Prabhakar | e933c6b | 2015-03-08 18:57:24 -0300 | [diff] [blame] | 1216 | vdev->release = video_device_release_empty; |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1217 | vdev->fops = &vpif_fops; |
| 1218 | vdev->ioctl_ops = &vpif_ioctl_ops; |
| 1219 | vdev->v4l2_dev = &vpif_obj.v4l2_dev; |
| 1220 | vdev->vfl_dir = VFL_DIR_TX; |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1221 | vdev->queue = q; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 1222 | vdev->lock = &common->lock; |
Lad, Prabhakar | e933c6b | 2015-03-08 18:57:24 -0300 | [diff] [blame] | 1223 | video_set_drvdata(&ch->video_dev, ch); |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1224 | err = video_register_device(vdev, VFL_TYPE_GRABBER, |
| 1225 | (j ? 3 : 2)); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1226 | if (err < 0) |
| 1227 | goto probe_out; |
| 1228 | } |
| 1229 | |
| 1230 | return 0; |
| 1231 | |
| 1232 | probe_out: |
| 1233 | for (k = 0; k < j; k++) { |
| 1234 | ch = vpif_obj.dev[k]; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1235 | common = &ch->common[k]; |
| 1236 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
Lad, Prabhakar | e933c6b | 2015-03-08 18:57:24 -0300 | [diff] [blame] | 1237 | video_unregister_device(&ch->video_dev); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1238 | } |
| 1239 | return err; |
| 1240 | } |
| 1241 | |
| 1242 | static int vpif_async_complete(struct v4l2_async_notifier *notifier) |
| 1243 | { |
| 1244 | return vpif_probe_complete(); |
| 1245 | } |
| 1246 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1247 | /* |
| 1248 | * vpif_probe: This function creates device entries by register itself to the |
| 1249 | * V4L2 driver and initializes fields of each channel objects |
| 1250 | */ |
| 1251 | static __init int vpif_probe(struct platform_device *pdev) |
| 1252 | { |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 1253 | struct vpif_subdev_info *subdevdata; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1254 | struct i2c_adapter *i2c_adap; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1255 | struct resource *res; |
| 1256 | int subdev_count; |
Lad, Prabhakar | e933c6b | 2015-03-08 18:57:24 -0300 | [diff] [blame] | 1257 | int res_idx = 0; |
| 1258 | int i, err; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1259 | |
| 1260 | vpif_dev = &pdev->dev; |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 1261 | err = initialize_vpif(); |
| 1262 | |
| 1263 | if (err) { |
| 1264 | v4l2_err(vpif_dev->driver, "Error initializing vpif\n"); |
| 1265 | return err; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1266 | } |
| 1267 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1268 | err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); |
| 1269 | if (err) { |
| 1270 | v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); |
| 1271 | return err; |
| 1272 | } |
| 1273 | |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1274 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { |
Lad, Prabhakar | 379d2cf | 2013-06-17 11:20:51 -0300 | [diff] [blame] | 1275 | err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr, |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1276 | IRQF_SHARED, VPIF_DRIVER_NAME, |
Lad, Prabhakar | 379d2cf | 2013-06-17 11:20:51 -0300 | [diff] [blame] | 1277 | (void *)(&vpif_obj.dev[res_idx]-> |
| 1278 | channel_id)); |
| 1279 | if (err) { |
| 1280 | err = -EINVAL; |
| 1281 | vpif_err("VPIF IRQ request failed\n"); |
| 1282 | goto vpif_unregister; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1283 | } |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1284 | res_idx++; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1285 | } |
| 1286 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1287 | vpif_obj.config = pdev->dev.platform_data; |
| 1288 | subdev_count = vpif_obj.config->subdev_count; |
| 1289 | subdevdata = vpif_obj.config->subdevinfo; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1290 | vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count, |
| 1291 | GFP_KERNEL); |
| 1292 | if (vpif_obj.sd == NULL) { |
| 1293 | vpif_err("unable to allocate memory for subdevice pointers\n"); |
| 1294 | err = -ENOMEM; |
Lad, Prabhakar | e933c6b | 2015-03-08 18:57:24 -0300 | [diff] [blame] | 1295 | goto vpif_unregister; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1296 | } |
| 1297 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1298 | if (!vpif_obj.config->asd_sizes) { |
| 1299 | i2c_adap = i2c_get_adapter(1); |
| 1300 | for (i = 0; i < subdev_count; i++) { |
| 1301 | vpif_obj.sd[i] = |
| 1302 | v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, |
| 1303 | i2c_adap, |
| 1304 | &subdevdata[i]. |
| 1305 | board_info, |
| 1306 | NULL); |
| 1307 | if (!vpif_obj.sd[i]) { |
| 1308 | vpif_err("Error registering v4l2 subdevice\n"); |
Wei Yongjun | 9d3e976 | 2013-08-22 22:59:44 -0300 | [diff] [blame] | 1309 | err = -ENODEV; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1310 | goto probe_subdev_out; |
| 1311 | } |
| 1312 | |
| 1313 | if (vpif_obj.sd[i]) |
| 1314 | vpif_obj.sd[i]->grp_id = 1 << i; |
| 1315 | } |
| 1316 | vpif_probe_complete(); |
| 1317 | } else { |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 1318 | vpif_obj.notifier.subdevs = vpif_obj.config->asd; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1319 | vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0]; |
| 1320 | vpif_obj.notifier.bound = vpif_async_bound; |
| 1321 | vpif_obj.notifier.complete = vpif_async_complete; |
| 1322 | err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev, |
| 1323 | &vpif_obj.notifier); |
| 1324 | if (err) { |
| 1325 | vpif_err("Error registering async notifier\n"); |
| 1326 | err = -EINVAL; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1327 | goto probe_subdev_out; |
| 1328 | } |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1329 | } |
| 1330 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1331 | return 0; |
| 1332 | |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1333 | probe_subdev_out: |
| 1334 | kfree(vpif_obj.sd); |
Lad, Prabhakar | 9c63e01 | 2013-06-17 11:20:50 -0300 | [diff] [blame] | 1335 | vpif_unregister: |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1336 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1337 | |
| 1338 | return err; |
| 1339 | } |
| 1340 | |
| 1341 | /* |
| 1342 | * vpif_remove: It un-register channels from V4L2 driver |
| 1343 | */ |
| 1344 | static int vpif_remove(struct platform_device *device) |
| 1345 | { |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1346 | struct common_obj *common; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1347 | struct channel_obj *ch; |
Lad, Prabhakar | 9c63e01 | 2013-06-17 11:20:50 -0300 | [diff] [blame] | 1348 | int i; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1349 | |
| 1350 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
| 1351 | |
Lad, Prabhakar | 0b36158 | 2013-06-17 11:20:48 -0300 | [diff] [blame] | 1352 | kfree(vpif_obj.sd); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1353 | /* un-register device */ |
| 1354 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1355 | /* Get the pointer to the channel object */ |
| 1356 | ch = vpif_obj.dev[i]; |
Prabhakar Lad | e9b5872 | 2014-07-18 13:31:51 -0300 | [diff] [blame] | 1357 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1358 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1359 | /* Unregister video device */ |
Lad, Prabhakar | e933c6b | 2015-03-08 18:57:24 -0300 | [diff] [blame] | 1360 | video_unregister_device(&ch->video_dev); |
Lad, Prabhakar | 0b36158 | 2013-06-17 11:20:48 -0300 | [diff] [blame] | 1361 | kfree(vpif_obj.dev[i]); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | return 0; |
| 1365 | } |
| 1366 | |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1367 | #ifdef CONFIG_PM_SLEEP |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1368 | static int vpif_suspend(struct device *dev) |
| 1369 | { |
| 1370 | struct common_obj *common; |
| 1371 | struct channel_obj *ch; |
| 1372 | int i; |
| 1373 | |
| 1374 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1375 | /* Get the pointer to the channel object */ |
| 1376 | ch = vpif_obj.dev[i]; |
| 1377 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1378 | |
Prabhakar Lad | 8157892 | 2014-09-06 12:26:50 -0300 | [diff] [blame] | 1379 | if (!vb2_start_streaming_called(&common->buffer_queue)) |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1380 | continue; |
| 1381 | |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1382 | mutex_lock(&common->lock); |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1383 | /* Disable channel */ |
| 1384 | if (ch->channel_id == VPIF_CHANNEL2_VIDEO) { |
| 1385 | enable_channel2(0); |
| 1386 | channel2_intr_enable(0); |
| 1387 | } |
| 1388 | if (ch->channel_id == VPIF_CHANNEL3_VIDEO || |
| 1389 | ycmux_mode == 2) { |
| 1390 | enable_channel3(0); |
| 1391 | channel3_intr_enable(0); |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1392 | } |
| 1393 | mutex_unlock(&common->lock); |
| 1394 | } |
| 1395 | |
| 1396 | return 0; |
| 1397 | } |
| 1398 | |
| 1399 | static int vpif_resume(struct device *dev) |
| 1400 | { |
| 1401 | |
| 1402 | struct common_obj *common; |
| 1403 | struct channel_obj *ch; |
| 1404 | int i; |
| 1405 | |
| 1406 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1407 | /* Get the pointer to the channel object */ |
| 1408 | ch = vpif_obj.dev[i]; |
| 1409 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1410 | |
Prabhakar Lad | 8157892 | 2014-09-06 12:26:50 -0300 | [diff] [blame] | 1411 | if (!vb2_start_streaming_called(&common->buffer_queue)) |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1412 | continue; |
| 1413 | |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1414 | mutex_lock(&common->lock); |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1415 | /* Enable channel */ |
| 1416 | if (ch->channel_id == VPIF_CHANNEL2_VIDEO) { |
| 1417 | enable_channel2(1); |
| 1418 | channel2_intr_enable(1); |
| 1419 | } |
| 1420 | if (ch->channel_id == VPIF_CHANNEL3_VIDEO || |
| 1421 | ycmux_mode == 2) { |
| 1422 | enable_channel3(1); |
| 1423 | channel3_intr_enable(1); |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1424 | } |
| 1425 | mutex_unlock(&common->lock); |
| 1426 | } |
| 1427 | |
| 1428 | return 0; |
| 1429 | } |
| 1430 | |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1431 | #endif |
| 1432 | |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1433 | static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume); |
| 1434 | |
Mats Randgaard | ffa1b39 | 2010-08-30 10:30:36 -0300 | [diff] [blame] | 1435 | static __refdata struct platform_driver vpif_driver = { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1436 | .driver = { |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1437 | .name = VPIF_DRIVER_NAME, |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1438 | .pm = &vpif_pm_ops, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1439 | }, |
| 1440 | .probe = vpif_probe, |
| 1441 | .remove = vpif_remove, |
| 1442 | }; |
| 1443 | |
Lad, Prabhakar | b8d067b | 2013-06-17 11:20:49 -0300 | [diff] [blame] | 1444 | module_platform_driver(vpif_driver); |