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