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 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 56 | static inline struct vpif_disp_buffer *to_vpif_buffer(struct vb2_buffer *vb) |
| 57 | { |
| 58 | return container_of(vb, struct vpif_disp_buffer, vb); |
| 59 | } |
| 60 | |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 61 | /** |
| 62 | * vpif_buffer_prepare : callback function for buffer prepare |
| 63 | * @vb: ptr to vb2_buffer |
| 64 | * |
| 65 | * This is the callback function for buffer prepare when vb2_qbuf() |
| 66 | * function is called. The buffer is prepared and user space virtual address |
| 67 | * or user address is converted into physical address |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 68 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 69 | static int vpif_buffer_prepare(struct vb2_buffer *vb) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 70 | { |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 71 | struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 72 | struct common_obj *common; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 73 | |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 74 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 75 | |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 76 | vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage); |
| 77 | if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) |
| 78 | return -EINVAL; |
| 79 | |
| 80 | vb->v4l2_buf.field = common->fmt.fmt.pix.field; |
| 81 | |
| 82 | if (vb->vb2_queue->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) { |
| 83 | unsigned long addr = vb2_dma_contig_plane_dma_addr(vb, 0); |
| 84 | |
| 85 | if (!ISALIGNED(addr + common->ytop_off) || |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 86 | !ISALIGNED(addr + common->ybtm_off) || |
| 87 | !ISALIGNED(addr + common->ctop_off) || |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 88 | !ISALIGNED(addr + common->cbtm_off)) { |
| 89 | vpif_err("buffer offset not aligned to 8 bytes\n"); |
| 90 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 91 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 92 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 93 | |
Lad, Prabhakar | 27cdf9b | 2014-05-16 10:33:11 -0300 | [diff] [blame] | 94 | return 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 95 | } |
| 96 | |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 97 | /** |
| 98 | * vpif_buffer_queue_setup : Callback function for buffer setup. |
| 99 | * @vq: vb2_queue ptr |
| 100 | * @fmt: v4l2 format |
| 101 | * @nbuffers: ptr to number of buffers requested by application |
| 102 | * @nplanes:: contains number of distinct video planes needed to hold a frame |
| 103 | * @sizes[]: contains the size (in bytes) of each plane. |
| 104 | * @alloc_ctxs: ptr to allocation context |
| 105 | * |
| 106 | * This callback function is called when reqbuf() is called to adjust |
| 107 | * the buffer count and buffer size |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 108 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 109 | static int vpif_buffer_queue_setup(struct vb2_queue *vq, |
| 110 | const struct v4l2_format *fmt, |
| 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]; |
| 116 | |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 117 | if (fmt && fmt->fmt.pix.sizeimage < common->fmt.fmt.pix.sizeimage) |
| 118 | return -EINVAL; |
Manjunath Hadli | fc613d4 | 2012-04-13 04:49:10 -0300 | [diff] [blame] | 119 | |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 120 | if (vq->num_buffers + *nbuffers < 3) |
| 121 | *nbuffers = 3 - vq->num_buffers; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 122 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 123 | *nplanes = 1; |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 124 | sizes[0] = fmt ? fmt->fmt.pix.sizeimage : common->fmt.fmt.pix.sizeimage; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 125 | alloc_ctxs[0] = common->alloc_ctx; |
Lad, Prabhakar | 172392a | 2014-05-16 10:33:12 -0300 | [diff] [blame] | 126 | |
| 127 | /* Calculate the offset for Y and C data in the buffer */ |
| 128 | vpif_calculate_offsets(ch); |
| 129 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 133 | /** |
| 134 | * vpif_buffer_queue : Callback function to add buffer to DMA queue |
| 135 | * @vb: ptr to vb2_buffer |
| 136 | * |
| 137 | * This callback fucntion queues the buffer to DMA engine |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 138 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 139 | static void vpif_buffer_queue(struct vb2_buffer *vb) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 140 | { |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 141 | struct vpif_disp_buffer *buf = to_vpif_buffer(vb); |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 142 | struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 143 | struct common_obj *common; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 144 | unsigned long flags; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 145 | |
| 146 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 147 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 148 | /* add the buffer to the DMA queue */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 149 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 150 | list_add_tail(&buf->list, &common->dma_queue); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 151 | spin_unlock_irqrestore(&common->irqlock, flags); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 152 | } |
| 153 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 154 | /** |
| 155 | * vpif_start_streaming : Starts the DMA engine for streaming |
| 156 | * @vb: ptr to vb2_buffer |
| 157 | * @count: number of buffers |
| 158 | */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 159 | static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) |
| 160 | { |
| 161 | struct vpif_display_config *vpif_config_data = |
| 162 | vpif_dev->platform_data; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 163 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 164 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 165 | struct vpif_params *vpif = &ch->vpifparams; |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 166 | struct vpif_disp_buffer *buf, *tmp; |
| 167 | unsigned long addr, flags; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 168 | int ret; |
| 169 | |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 170 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 171 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 172 | /* Initialize field_id */ |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 173 | ch->field_id = 0; |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 174 | |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 175 | /* clock settings */ |
| 176 | if (vpif_config_data->set_clock) { |
| 177 | ret = vpif_config_data->set_clock(ch->vpifparams.std_info. |
| 178 | ycmux_mode, ch->vpifparams.std_info.hd_sd); |
| 179 | if (ret < 0) { |
| 180 | vpif_err("can't set clock\n"); |
| 181 | goto err; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* set the parameters and addresses */ |
| 186 | ret = vpif_set_video_params(vpif, ch->channel_id + 2); |
| 187 | if (ret < 0) |
| 188 | goto err; |
| 189 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 190 | ycmux_mode = ret; |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 191 | vpif_config_addr(ch, ret); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 192 | /* Get the next frame from the buffer queue */ |
| 193 | common->next_frm = common->cur_frm = |
| 194 | list_entry(common->dma_queue.next, |
| 195 | struct vpif_disp_buffer, list); |
| 196 | |
| 197 | list_del(&common->cur_frm->list); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 198 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 199 | /* Mark state of the current frame to active */ |
| 200 | common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE; |
| 201 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 202 | addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 203 | common->set_addr((addr + common->ytop_off), |
| 204 | (addr + common->ybtm_off), |
| 205 | (addr + common->ctop_off), |
| 206 | (addr + common->cbtm_off)); |
| 207 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 208 | /* |
| 209 | * Set interrupt for both the fields in VPIF |
| 210 | * Register enable channel in VPIF register |
| 211 | */ |
Lad, Prabhakar | 9e18404 | 2012-09-14 10:22:24 -0300 | [diff] [blame] | 212 | channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 213 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { |
| 214 | channel2_intr_assert(); |
| 215 | channel2_intr_enable(1); |
| 216 | enable_channel2(1); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 217 | if (vpif_config_data->chan_config[VPIF_CHANNEL2_VIDEO].clip_en) |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 218 | channel2_clipping_enable(1); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 219 | } |
| 220 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 221 | if (VPIF_CHANNEL3_VIDEO == ch->channel_id || ycmux_mode == 2) { |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 222 | channel3_intr_assert(); |
| 223 | channel3_intr_enable(1); |
| 224 | enable_channel3(1); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 225 | if (vpif_config_data->chan_config[VPIF_CHANNEL3_VIDEO].clip_en) |
Manjunath Hadli | 6964b10 | 2012-06-29 03:20:12 -0300 | [diff] [blame] | 226 | channel3_clipping_enable(1); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 227 | } |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 228 | |
| 229 | return 0; |
Lad, Prabhakar | 54a445a4 | 2014-05-16 10:33:09 -0300 | [diff] [blame] | 230 | |
| 231 | err: |
| 232 | list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) { |
| 233 | list_del(&buf->list); |
| 234 | vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED); |
| 235 | } |
| 236 | |
| 237 | return ret; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 238 | } |
| 239 | |
Lad, Prabhakar | 58334b0 | 2014-05-16 10:33:13 -0300 | [diff] [blame] | 240 | /** |
| 241 | * vpif_stop_streaming : Stop the DMA engine |
| 242 | * @vq: ptr to vb2_queue |
| 243 | * |
| 244 | * This callback stops the DMA engine and any remaining buffers |
| 245 | * in the DMA queue are released. |
| 246 | */ |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 247 | static void vpif_stop_streaming(struct vb2_queue *vq) |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 248 | { |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 249 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 250 | struct common_obj *common; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 251 | unsigned long flags; |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 252 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 253 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 254 | |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 255 | /* Disable channel */ |
| 256 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { |
| 257 | enable_channel2(0); |
| 258 | channel2_intr_enable(0); |
| 259 | } |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 260 | if (VPIF_CHANNEL3_VIDEO == ch->channel_id || ycmux_mode == 2) { |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 261 | enable_channel3(0); |
| 262 | channel3_intr_enable(0); |
| 263 | } |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 264 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 265 | /* release all active buffers */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 266 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 18c7adc | 2014-03-22 08:03:08 -0300 | [diff] [blame] | 267 | if (common->cur_frm == common->next_frm) { |
| 268 | vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR); |
| 269 | } else { |
| 270 | if (common->cur_frm != NULL) |
| 271 | vb2_buffer_done(&common->cur_frm->vb, |
| 272 | VB2_BUF_STATE_ERROR); |
| 273 | if (common->next_frm != NULL) |
| 274 | vb2_buffer_done(&common->next_frm->vb, |
| 275 | VB2_BUF_STATE_ERROR); |
| 276 | } |
| 277 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 278 | while (!list_empty(&common->dma_queue)) { |
| 279 | common->next_frm = list_entry(common->dma_queue.next, |
| 280 | struct vpif_disp_buffer, list); |
| 281 | list_del(&common->next_frm->list); |
| 282 | vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR); |
| 283 | } |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 284 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | static struct vb2_ops video_qops = { |
| 288 | .queue_setup = vpif_buffer_queue_setup, |
Lad, Prabhakar | d10ed5c | 2014-05-16 10:33:08 -0300 | [diff] [blame] | 289 | .wait_prepare = vb2_ops_wait_prepare, |
| 290 | .wait_finish = vb2_ops_wait_finish, |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 291 | .buf_prepare = vpif_buffer_prepare, |
| 292 | .start_streaming = vpif_start_streaming, |
| 293 | .stop_streaming = vpif_stop_streaming, |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 294 | .buf_queue = vpif_buffer_queue, |
| 295 | }; |
| 296 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 297 | static void process_progressive_mode(struct common_obj *common) |
| 298 | { |
| 299 | unsigned long addr = 0; |
| 300 | |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 301 | spin_lock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 302 | /* Get the next buffer from buffer queue */ |
| 303 | common->next_frm = list_entry(common->dma_queue.next, |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 304 | struct vpif_disp_buffer, list); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 305 | /* Remove that buffer from the buffer queue */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 306 | list_del(&common->next_frm->list); |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 307 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 308 | /* Mark status of the buffer as active */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 309 | common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 310 | |
| 311 | /* Set top and bottom field addrs in VPIF registers */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 312 | addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 313 | common->set_addr(addr + common->ytop_off, |
| 314 | addr + common->ybtm_off, |
| 315 | addr + common->ctop_off, |
| 316 | addr + common->cbtm_off); |
| 317 | } |
| 318 | |
| 319 | static void process_interlaced_mode(int fid, struct common_obj *common) |
| 320 | { |
| 321 | /* device field id and local field id are in sync */ |
| 322 | /* If this is even field */ |
| 323 | if (0 == fid) { |
| 324 | if (common->cur_frm == common->next_frm) |
| 325 | return; |
| 326 | |
| 327 | /* one frame is displayed If next frame is |
| 328 | * available, release cur_frm and move on */ |
| 329 | /* Copy frame display time */ |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 330 | v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 331 | /* Change status of the cur_frm */ |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 332 | vb2_buffer_done(&common->cur_frm->vb, |
| 333 | VB2_BUF_STATE_DONE); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 334 | /* Make cur_frm pointing to next_frm */ |
| 335 | common->cur_frm = common->next_frm; |
| 336 | |
| 337 | } else if (1 == fid) { /* odd field */ |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 338 | spin_lock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 339 | if (list_empty(&common->dma_queue) |
| 340 | || (common->cur_frm != common->next_frm)) { |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 341 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 342 | return; |
| 343 | } |
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 | /* one field is displayed configure the next |
| 346 | * frame if it is available else hold on current |
| 347 | * frame */ |
| 348 | /* Get next from the buffer queue */ |
| 349 | process_progressive_mode(common); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
| 353 | /* |
| 354 | * vpif_channel_isr: It changes status of the displayed buffer, takes next |
| 355 | * buffer from the queue and sets its address in VPIF registers |
| 356 | */ |
| 357 | static irqreturn_t vpif_channel_isr(int irq, void *dev_id) |
| 358 | { |
| 359 | struct vpif_device *dev = &vpif_obj; |
| 360 | struct channel_obj *ch; |
| 361 | struct common_obj *common; |
| 362 | enum v4l2_field field; |
| 363 | int fid = -1, i; |
| 364 | int channel_id = 0; |
| 365 | |
| 366 | channel_id = *(int *)(dev_id); |
Manjunath Hadli | b1fc423 | 2012-04-13 04:43:10 -0300 | [diff] [blame] | 367 | if (!vpif_intr_status(channel_id + 2)) |
| 368 | return IRQ_NONE; |
| 369 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 370 | ch = dev->dev[channel_id]; |
| 371 | field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field; |
| 372 | for (i = 0; i < VPIF_NUMOBJECTS; i++) { |
| 373 | common = &ch->common[i]; |
| 374 | /* If streaming is started in this channel */ |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 375 | |
| 376 | if (1 == ch->vpifparams.std_info.frm_fmt) { |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 377 | spin_lock(&common->irqlock); |
| 378 | if (list_empty(&common->dma_queue)) { |
| 379 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 380 | continue; |
Hans Verkuil | c4697d7 | 2012-11-16 12:03:07 -0300 | [diff] [blame] | 381 | } |
| 382 | spin_unlock(&common->irqlock); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 383 | |
| 384 | /* Progressive mode */ |
| 385 | if (!channel_first_int[i][channel_id]) { |
| 386 | /* Mark status of the cur_frm to |
| 387 | * done and unlock semaphore on it */ |
Sakari Ailus | 8e6057b | 2012-09-15 15:14:42 -0300 | [diff] [blame] | 388 | v4l2_get_timestamp(&common->cur_frm->vb. |
| 389 | v4l2_buf.timestamp); |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 390 | vb2_buffer_done(&common->cur_frm->vb, |
| 391 | VB2_BUF_STATE_DONE); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 392 | /* Make cur_frm pointing to next_frm */ |
| 393 | common->cur_frm = common->next_frm; |
| 394 | } |
| 395 | |
| 396 | channel_first_int[i][channel_id] = 0; |
| 397 | process_progressive_mode(common); |
| 398 | } else { |
| 399 | /* Interlaced mode */ |
| 400 | /* If it is first interrupt, ignore it */ |
| 401 | |
| 402 | if (channel_first_int[i][channel_id]) { |
| 403 | channel_first_int[i][channel_id] = 0; |
| 404 | continue; |
| 405 | } |
| 406 | |
| 407 | if (0 == i) { |
| 408 | ch->field_id ^= 1; |
| 409 | /* Get field id from VPIF registers */ |
| 410 | fid = vpif_channel_getfid(ch->channel_id + 2); |
| 411 | /* If fid does not match with stored field id */ |
| 412 | if (fid != ch->field_id) { |
| 413 | /* Make them in sync */ |
| 414 | if (0 == fid) |
| 415 | ch->field_id = fid; |
| 416 | |
| 417 | return IRQ_HANDLED; |
| 418 | } |
| 419 | } |
| 420 | process_interlaced_mode(fid, common); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | return IRQ_HANDLED; |
| 425 | } |
| 426 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 427 | static int vpif_update_std_info(struct channel_obj *ch) |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 428 | { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 429 | struct video_obj *vid_ch = &ch->video; |
| 430 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 431 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 432 | const struct vpif_channel_config_params *config; |
| 433 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 434 | int i; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 435 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 436 | for (i = 0; i < vpif_ch_params_count; i++) { |
Lad, Prabhakar | ced9b21 | 2013-03-20 01:28:27 -0300 | [diff] [blame] | 437 | config = &vpif_ch_params[i]; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 438 | if (config->hd_sd == 0) { |
| 439 | vpif_dbg(2, debug, "SD format\n"); |
| 440 | if (config->stdid & vid_ch->stdid) { |
| 441 | memcpy(std_info, config, sizeof(*config)); |
| 442 | break; |
| 443 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 447 | if (i == vpif_ch_params_count) { |
| 448 | vpif_dbg(1, debug, "Format not found\n"); |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 449 | return -EINVAL; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int vpif_update_resolution(struct channel_obj *ch) |
| 456 | { |
| 457 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 458 | struct video_obj *vid_ch = &ch->video; |
| 459 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 460 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 461 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 462 | if (!vid_ch->stdid && !vid_ch->dv_timings.bt.height) |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 463 | return -EINVAL; |
| 464 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 465 | if (vid_ch->stdid) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 466 | if (vpif_update_std_info(ch)) |
| 467 | return -EINVAL; |
| 468 | } |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 469 | |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 470 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 471 | common->fmt.fmt.pix.width = std_info->width; |
| 472 | common->fmt.fmt.pix.height = std_info->height; |
| 473 | vpif_dbg(1, debug, "Pixel details: Width = %d,Height = %d\n", |
| 474 | common->fmt.fmt.pix.width, common->fmt.fmt.pix.height); |
| 475 | |
| 476 | /* Set height and width paramateres */ |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 477 | common->height = std_info->height; |
| 478 | common->width = std_info->width; |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 479 | common->fmt.fmt.pix.sizeimage = common->height * common->width * 2; |
| 480 | |
| 481 | if (vid_ch->stdid) |
| 482 | common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 483 | else |
| 484 | common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_REC709; |
| 485 | |
| 486 | if (ch->vpifparams.std_info.frm_fmt) |
| 487 | common->fmt.fmt.pix.field = V4L2_FIELD_NONE; |
| 488 | else |
| 489 | common->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * vpif_calculate_offsets: This function calculates buffers offset for Y and C |
| 496 | * in the top and bottom field |
| 497 | */ |
| 498 | static void vpif_calculate_offsets(struct channel_obj *ch) |
| 499 | { |
| 500 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 501 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 502 | enum v4l2_field field = common->fmt.fmt.pix.field; |
| 503 | struct video_obj *vid_ch = &ch->video; |
| 504 | unsigned int hpitch, vpitch, sizeimage; |
| 505 | |
| 506 | if (V4L2_FIELD_ANY == common->fmt.fmt.pix.field) { |
| 507 | if (ch->vpifparams.std_info.frm_fmt) |
| 508 | vid_ch->buf_field = V4L2_FIELD_NONE; |
| 509 | else |
| 510 | vid_ch->buf_field = V4L2_FIELD_INTERLACED; |
| 511 | } else { |
| 512 | vid_ch->buf_field = common->fmt.fmt.pix.field; |
| 513 | } |
| 514 | |
Lad, Prabhakar | 2401dd2 | 2012-06-28 09:28:36 -0300 | [diff] [blame] | 515 | sizeimage = common->fmt.fmt.pix.sizeimage; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 516 | |
| 517 | hpitch = common->fmt.fmt.pix.bytesperline; |
| 518 | vpitch = sizeimage / (hpitch * 2); |
| 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; |
| 651 | pixfmt->priv = 0; |
| 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]; |
| 816 | struct vpif_subdev_info *subdev_info = NULL; |
| 817 | struct v4l2_subdev *sd = NULL; |
| 818 | u32 input = 0, output = 0; |
| 819 | int sd_index; |
| 820 | int ret; |
| 821 | |
| 822 | sd_index = vpif_output_to_subdev(vpif_cfg, chan_cfg, index); |
| 823 | if (sd_index >= 0) { |
| 824 | sd = vpif_obj.sd[sd_index]; |
| 825 | subdev_info = &vpif_cfg->subdevinfo[sd_index]; |
| 826 | } |
| 827 | |
| 828 | if (sd) { |
| 829 | input = chan_cfg->outputs[index].input_route; |
| 830 | output = chan_cfg->outputs[index].output_route; |
| 831 | ret = v4l2_subdev_call(sd, video, s_routing, input, output, 0); |
| 832 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
| 833 | vpif_err("Failed to set output\n"); |
| 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | } |
| 838 | ch->output_idx = index; |
| 839 | ch->sd = sd; |
| 840 | if (chan_cfg->outputs != NULL) |
| 841 | /* update tvnorms from the sub device output info */ |
| 842 | ch->video_dev->tvnorms = chan_cfg->outputs[index].output.std; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 843 | return 0; |
| 844 | } |
| 845 | |
| 846 | static int vpif_s_output(struct file *file, void *priv, unsigned int i) |
| 847 | { |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 848 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 849 | struct video_device *vdev = video_devdata(file); |
| 850 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 851 | struct vpif_display_chan_config *chan_cfg; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 852 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 853 | |
Lad, Prabhakar | 2f5851b | 2014-05-16 10:33:21 -0300 | [diff] [blame] | 854 | if (vb2_is_busy(&common->buffer_queue)) |
| 855 | return -EBUSY; |
| 856 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 857 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 858 | |
| 859 | if (i >= chan_cfg->output_count) |
| 860 | return -EINVAL; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 861 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 862 | return vpif_set_output(config, ch, i); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static int vpif_g_output(struct file *file, void *priv, unsigned int *i) |
| 866 | { |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 867 | struct video_device *vdev = video_devdata(file); |
| 868 | struct channel_obj *ch = video_get_drvdata(vdev); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 869 | |
Hans Verkuil | 311673e | 2012-09-20 09:06:23 -0300 | [diff] [blame] | 870 | *i = ch->output_idx; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 875 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 876 | * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 877 | * @file: file ptr |
| 878 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 879 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 880 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 881 | static int |
| 882 | vpif_enum_dv_timings(struct file *file, void *priv, |
| 883 | struct v4l2_enum_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 884 | { |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 885 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 886 | struct video_device *vdev = video_devdata(file); |
| 887 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 888 | struct vpif_display_chan_config *chan_cfg; |
| 889 | struct v4l2_output output; |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 890 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 891 | |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 892 | if (config->chan_config[ch->channel_id].outputs == NULL) |
| 893 | return -ENODATA; |
| 894 | |
| 895 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 896 | output = chan_cfg->outputs[ch->output_idx].output; |
| 897 | if (output.capabilities != V4L2_OUT_CAP_DV_TIMINGS) |
| 898 | return -ENODATA; |
| 899 | |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 900 | ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings); |
Wei Yongjun | 63af4af | 2012-10-30 09:49:38 -0300 | [diff] [blame] | 901 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 902 | return -EINVAL; |
| 903 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /** |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 907 | * vpif_s_dv_timings() - S_DV_TIMINGS handler |
| 908 | * @file: file ptr |
| 909 | * @priv: file handle |
| 910 | * @timings: digital video timings |
| 911 | */ |
| 912 | static int vpif_s_dv_timings(struct file *file, void *priv, |
| 913 | struct v4l2_dv_timings *timings) |
| 914 | { |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 915 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 916 | struct video_device *vdev = video_devdata(file); |
| 917 | struct channel_obj *ch = video_get_drvdata(vdev); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 918 | struct vpif_params *vpifparams = &ch->vpifparams; |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 919 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 920 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
| 921 | struct video_obj *vid_ch = &ch->video; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 922 | struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt; |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 923 | struct vpif_display_chan_config *chan_cfg; |
| 924 | struct v4l2_output output; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 925 | int ret; |
| 926 | |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 927 | if (config->chan_config[ch->channel_id].outputs == NULL) |
| 928 | return -ENODATA; |
| 929 | |
| 930 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 931 | output = chan_cfg->outputs[ch->output_idx].output; |
| 932 | if (output.capabilities != V4L2_OUT_CAP_DV_TIMINGS) |
| 933 | return -ENODATA; |
| 934 | |
| 935 | if (vb2_is_busy(&common->buffer_queue)) |
| 936 | return -EBUSY; |
| 937 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 938 | if (timings->type != V4L2_DV_BT_656_1120) { |
| 939 | vpif_dbg(2, debug, "Timing type not defined\n"); |
| 940 | return -EINVAL; |
| 941 | } |
| 942 | |
| 943 | /* Configure subdevice timings, if any */ |
Hans Verkuil | 882084a | 2012-09-20 09:06:31 -0300 | [diff] [blame] | 944 | ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings); |
Lad, Prabhakar | 2bd4e58 | 2012-09-25 08:11:49 -0300 | [diff] [blame] | 945 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 946 | ret = 0; |
| 947 | if (ret < 0) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 948 | vpif_dbg(2, debug, "Error setting custom DV timings\n"); |
| 949 | return ret; |
| 950 | } |
| 951 | |
| 952 | if (!(timings->bt.width && timings->bt.height && |
| 953 | (timings->bt.hbackporch || |
| 954 | timings->bt.hfrontporch || |
| 955 | timings->bt.hsync) && |
| 956 | timings->bt.vfrontporch && |
| 957 | (timings->bt.vbackporch || |
| 958 | timings->bt.vsync))) { |
| 959 | vpif_dbg(2, debug, "Timings for width, height, " |
| 960 | "horizontal back porch, horizontal sync, " |
| 961 | "horizontal front porch, vertical back porch, " |
| 962 | "vertical sync and vertical back porch " |
| 963 | "must be defined\n"); |
| 964 | return -EINVAL; |
| 965 | } |
| 966 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 967 | vid_ch->dv_timings = *timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 968 | |
| 969 | /* Configure video port timings */ |
| 970 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame] | 971 | std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 972 | std_info->sav2eav = bt->width; |
| 973 | |
| 974 | std_info->l1 = 1; |
| 975 | std_info->l3 = bt->vsync + bt->vbackporch + 1; |
| 976 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame] | 977 | std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 978 | if (bt->interlaced) { |
| 979 | if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 980 | std_info->l5 = std_info->vsize/2 - |
| 981 | (bt->vfrontporch - 1); |
| 982 | std_info->l7 = std_info->vsize/2 + 1; |
| 983 | std_info->l9 = std_info->l7 + bt->il_vsync + |
| 984 | bt->il_vbackporch + 1; |
| 985 | std_info->l11 = std_info->vsize - |
| 986 | (bt->il_vfrontporch - 1); |
| 987 | } else { |
| 988 | vpif_dbg(2, debug, "Required timing values for " |
| 989 | "interlaced BT format missing\n"); |
| 990 | return -EINVAL; |
| 991 | } |
| 992 | } else { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 993 | std_info->l5 = std_info->vsize - (bt->vfrontporch - 1); |
| 994 | } |
| 995 | strncpy(std_info->name, "Custom timings BT656/1120", |
| 996 | VPIF_MAX_NAME); |
| 997 | std_info->width = bt->width; |
| 998 | std_info->height = bt->height; |
| 999 | std_info->frm_fmt = bt->interlaced ? 0 : 1; |
| 1000 | std_info->ycmux_mode = 0; |
| 1001 | std_info->capture_format = 0; |
| 1002 | std_info->vbi_supported = 0; |
| 1003 | std_info->hd_sd = 1; |
| 1004 | std_info->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1005 | vid_ch->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1006 | |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | /** |
| 1011 | * vpif_g_dv_timings() - G_DV_TIMINGS handler |
| 1012 | * @file: file ptr |
| 1013 | * @priv: file handle |
| 1014 | * @timings: digital video timings |
| 1015 | */ |
| 1016 | static int vpif_g_dv_timings(struct file *file, void *priv, |
| 1017 | struct v4l2_dv_timings *timings) |
| 1018 | { |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 1019 | struct vpif_display_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 1020 | struct video_device *vdev = video_devdata(file); |
| 1021 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 1022 | struct vpif_display_chan_config *chan_cfg; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1023 | struct video_obj *vid_ch = &ch->video; |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 1024 | struct v4l2_output output; |
| 1025 | |
| 1026 | if (config->chan_config[ch->channel_id].outputs == NULL) |
| 1027 | goto error; |
| 1028 | |
| 1029 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1030 | output = chan_cfg->outputs[ch->output_idx].output; |
| 1031 | |
| 1032 | if (output.capabilities != V4L2_OUT_CAP_DV_TIMINGS) |
| 1033 | goto error; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1034 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1035 | *timings = vid_ch->dv_timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1036 | |
| 1037 | return 0; |
Lad, Prabhakar | 1093c59 | 2014-05-16 10:33:27 -0300 | [diff] [blame] | 1038 | error: |
| 1039 | return -ENODATA; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1040 | } |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1041 | |
| 1042 | /* |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1043 | * vpif_log_status() - Status information |
| 1044 | * @file: file ptr |
| 1045 | * @priv: file handle |
| 1046 | * |
| 1047 | * Returns zero. |
| 1048 | */ |
| 1049 | static int vpif_log_status(struct file *filep, void *priv) |
| 1050 | { |
| 1051 | /* status for sub devices */ |
| 1052 | v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status); |
| 1053 | |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1057 | /* vpif display ioctl operations */ |
| 1058 | static const struct v4l2_ioctl_ops vpif_ioctl_ops = { |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1059 | .vidioc_querycap = vpif_querycap, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1060 | .vidioc_enum_fmt_vid_out = vpif_enum_fmt_vid_out, |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1061 | .vidioc_g_fmt_vid_out = vpif_g_fmt_vid_out, |
| 1062 | .vidioc_s_fmt_vid_out = vpif_s_fmt_vid_out, |
| 1063 | .vidioc_try_fmt_vid_out = vpif_try_fmt_vid_out, |
Lad, Prabhakar | b92cde1 | 2014-05-16 10:33:16 -0300 | [diff] [blame] | 1064 | |
| 1065 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 1066 | .vidioc_create_bufs = vb2_ioctl_create_bufs, |
| 1067 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 1068 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 1069 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
| 1070 | .vidioc_expbuf = vb2_ioctl_expbuf, |
| 1071 | .vidioc_streamon = vb2_ioctl_streamon, |
| 1072 | .vidioc_streamoff = vb2_ioctl_streamoff, |
| 1073 | |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1074 | .vidioc_s_std = vpif_s_std, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1075 | .vidioc_g_std = vpif_g_std, |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1076 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1077 | .vidioc_enum_output = vpif_enum_output, |
| 1078 | .vidioc_s_output = vpif_s_output, |
| 1079 | .vidioc_g_output = vpif_g_output, |
Lad, Prabhakar | dcce866 | 2014-05-16 10:33:25 -0300 | [diff] [blame] | 1080 | |
| 1081 | .vidioc_enum_dv_timings = vpif_enum_dv_timings, |
| 1082 | .vidioc_s_dv_timings = vpif_s_dv_timings, |
| 1083 | .vidioc_g_dv_timings = vpif_g_dv_timings, |
| 1084 | |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1085 | .vidioc_log_status = vpif_log_status, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1086 | }; |
| 1087 | |
| 1088 | static const struct v4l2_file_operations vpif_fops = { |
| 1089 | .owner = THIS_MODULE, |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 1090 | .open = v4l2_fh_open, |
| 1091 | .release = vb2_fop_release, |
Hans Verkuil | 9bfaae2 | 2011-01-05 13:35:45 -0300 | [diff] [blame] | 1092 | .unlocked_ioctl = video_ioctl2, |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1093 | .mmap = vb2_fop_mmap, |
| 1094 | .poll = vb2_fop_poll |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1095 | }; |
| 1096 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1097 | /*Configure the channels, buffer sizei, request irq */ |
| 1098 | static int initialize_vpif(void) |
| 1099 | { |
| 1100 | int free_channel_objects_index; |
Lad, Prabhakar | d5b94b9 | 2014-05-16 10:33:23 -0300 | [diff] [blame] | 1101 | int err, i, j; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1102 | |
| 1103 | /* Allocate memory for six channel objects */ |
| 1104 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1105 | vpif_obj.dev[i] = |
Mats Randgaard | 1f8766b | 2010-08-30 10:30:37 -0300 | [diff] [blame] | 1106 | kzalloc(sizeof(struct channel_obj), GFP_KERNEL); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1107 | /* If memory allocation fails, return error */ |
| 1108 | if (!vpif_obj.dev[i]) { |
| 1109 | free_channel_objects_index = i; |
| 1110 | err = -ENOMEM; |
| 1111 | goto vpif_init_free_channel_objects; |
| 1112 | } |
| 1113 | } |
| 1114 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1115 | return 0; |
| 1116 | |
| 1117 | vpif_init_free_channel_objects: |
| 1118 | for (j = 0; j < free_channel_objects_index; j++) |
| 1119 | kfree(vpif_obj.dev[j]); |
| 1120 | return err; |
| 1121 | } |
| 1122 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1123 | static int vpif_async_bound(struct v4l2_async_notifier *notifier, |
| 1124 | struct v4l2_subdev *subdev, |
| 1125 | struct v4l2_async_subdev *asd) |
| 1126 | { |
| 1127 | int i; |
| 1128 | |
| 1129 | for (i = 0; i < vpif_obj.config->subdev_count; i++) |
| 1130 | if (!strcmp(vpif_obj.config->subdevinfo[i].name, |
| 1131 | subdev->name)) { |
| 1132 | vpif_obj.sd[i] = subdev; |
| 1133 | vpif_obj.sd[i]->grp_id = 1 << i; |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
| 1137 | return -EINVAL; |
| 1138 | } |
| 1139 | |
| 1140 | static int vpif_probe_complete(void) |
| 1141 | { |
| 1142 | struct common_obj *common; |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1143 | struct video_device *vdev; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1144 | struct channel_obj *ch; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1145 | struct vb2_queue *q; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1146 | int j, err, k; |
| 1147 | |
| 1148 | for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) { |
| 1149 | ch = vpif_obj.dev[j]; |
| 1150 | /* Initialize field of the channel objects */ |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1151 | for (k = 0; k < VPIF_NUMOBJECTS; k++) { |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1152 | common = &ch->common[k]; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1153 | spin_lock_init(&common->irqlock); |
| 1154 | mutex_init(&common->lock); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1155 | common->set_addr = NULL; |
| 1156 | common->ytop_off = 0; |
| 1157 | common->ybtm_off = 0; |
| 1158 | common->ctop_off = 0; |
| 1159 | common->cbtm_off = 0; |
| 1160 | common->cur_frm = NULL; |
| 1161 | common->next_frm = NULL; |
| 1162 | memset(&common->fmt, 0, sizeof(common->fmt)); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1163 | } |
| 1164 | ch->initialized = 0; |
| 1165 | if (vpif_obj.config->subdev_count) |
| 1166 | ch->sd = vpif_obj.sd[0]; |
| 1167 | ch->channel_id = j; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1168 | |
| 1169 | memset(&ch->vpifparams, 0, sizeof(ch->vpifparams)); |
| 1170 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1171 | ch->common[VPIF_VIDEO_INDEX].fmt.type = |
| 1172 | V4L2_BUF_TYPE_VIDEO_OUTPUT; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1173 | |
| 1174 | /* select output 0 */ |
| 1175 | err = vpif_set_output(vpif_obj.config, ch, 0); |
| 1176 | if (err) |
| 1177 | goto probe_out; |
| 1178 | |
Lad, Prabhakar | 9cba653 | 2014-05-16 10:33:30 -0300 | [diff] [blame] | 1179 | /* set initial format */ |
| 1180 | ch->video.stdid = V4L2_STD_525_60; |
| 1181 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
| 1182 | vpif_update_resolution(ch); |
| 1183 | |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1184 | /* Initialize vb2 queue */ |
| 1185 | q = &common->buffer_queue; |
| 1186 | q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 1187 | q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
| 1188 | q->drv_priv = ch; |
| 1189 | q->ops = &video_qops; |
| 1190 | q->mem_ops = &vb2_dma_contig_memops; |
| 1191 | q->buf_struct_size = sizeof(struct vpif_disp_buffer); |
| 1192 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
| 1193 | q->min_buffers_needed = 1; |
Lad, Prabhakar | d10ed5c | 2014-05-16 10:33:08 -0300 | [diff] [blame] | 1194 | q->lock = &common->lock; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1195 | err = vb2_queue_init(q); |
| 1196 | if (err) { |
| 1197 | vpif_err("vpif_display: vb2_queue_init() failed\n"); |
| 1198 | goto probe_out; |
| 1199 | } |
| 1200 | |
| 1201 | common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev); |
| 1202 | if (IS_ERR(common->alloc_ctx)) { |
| 1203 | vpif_err("Failed to get the context\n"); |
| 1204 | err = PTR_ERR(common->alloc_ctx); |
| 1205 | goto probe_out; |
| 1206 | } |
| 1207 | |
| 1208 | INIT_LIST_HEAD(&common->dma_queue); |
| 1209 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1210 | /* register video device */ |
| 1211 | vpif_dbg(1, debug, "channel=%x,channel->video_dev=%x\n", |
| 1212 | (int)ch, (int)&ch->video_dev); |
| 1213 | |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1214 | /* Initialize the video_device structure */ |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1215 | vdev = ch->video_dev; |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1216 | strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name)); |
| 1217 | vdev->release = video_device_release; |
| 1218 | vdev->fops = &vpif_fops; |
| 1219 | vdev->ioctl_ops = &vpif_ioctl_ops; |
| 1220 | vdev->v4l2_dev = &vpif_obj.v4l2_dev; |
| 1221 | vdev->vfl_dir = VFL_DIR_TX; |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1222 | vdev->queue = q; |
Lad, Prabhakar | fcc22af | 2014-05-16 10:33:15 -0300 | [diff] [blame] | 1223 | vdev->lock = &common->lock; |
| 1224 | set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags); |
| 1225 | video_set_drvdata(ch->video_dev, ch); |
Lad, Prabhakar | 4be2153 | 2014-05-16 10:33:14 -0300 | [diff] [blame] | 1226 | err = video_register_device(vdev, VFL_TYPE_GRABBER, |
| 1227 | (j ? 3 : 2)); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1228 | if (err < 0) |
| 1229 | goto probe_out; |
| 1230 | } |
| 1231 | |
| 1232 | return 0; |
| 1233 | |
| 1234 | probe_out: |
| 1235 | for (k = 0; k < j; k++) { |
| 1236 | ch = vpif_obj.dev[k]; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1237 | common = &ch->common[k]; |
| 1238 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1239 | video_unregister_device(ch->video_dev); |
| 1240 | video_device_release(ch->video_dev); |
| 1241 | ch->video_dev = NULL; |
| 1242 | } |
| 1243 | return err; |
| 1244 | } |
| 1245 | |
| 1246 | static int vpif_async_complete(struct v4l2_async_notifier *notifier) |
| 1247 | { |
| 1248 | return vpif_probe_complete(); |
| 1249 | } |
| 1250 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1251 | /* |
| 1252 | * vpif_probe: This function creates device entries by register itself to the |
| 1253 | * V4L2 driver and initializes fields of each channel objects |
| 1254 | */ |
| 1255 | static __init int vpif_probe(struct platform_device *pdev) |
| 1256 | { |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 1257 | struct vpif_subdev_info *subdevdata; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1258 | int i, j = 0, err = 0; |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1259 | int res_idx = 0; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1260 | struct i2c_adapter *i2c_adap; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1261 | struct channel_obj *ch; |
| 1262 | struct video_device *vfd; |
| 1263 | struct resource *res; |
| 1264 | int subdev_count; |
| 1265 | |
| 1266 | vpif_dev = &pdev->dev; |
Muralidharan Karicheri | 317b2e2 | 2009-09-16 14:30:53 -0300 | [diff] [blame] | 1267 | err = initialize_vpif(); |
| 1268 | |
| 1269 | if (err) { |
| 1270 | v4l2_err(vpif_dev->driver, "Error initializing vpif\n"); |
| 1271 | return err; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1272 | } |
| 1273 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1274 | err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); |
| 1275 | if (err) { |
| 1276 | v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); |
| 1277 | return err; |
| 1278 | } |
| 1279 | |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1280 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { |
Lad, Prabhakar | 379d2cf | 2013-06-17 11:20:51 -0300 | [diff] [blame] | 1281 | err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr, |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1282 | IRQF_SHARED, VPIF_DRIVER_NAME, |
Lad, Prabhakar | 379d2cf | 2013-06-17 11:20:51 -0300 | [diff] [blame] | 1283 | (void *)(&vpif_obj.dev[res_idx]-> |
| 1284 | channel_id)); |
| 1285 | if (err) { |
| 1286 | err = -EINVAL; |
| 1287 | vpif_err("VPIF IRQ request failed\n"); |
| 1288 | goto vpif_unregister; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1289 | } |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1290 | res_idx++; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1294 | /* Get the pointer to the channel object */ |
| 1295 | ch = vpif_obj.dev[i]; |
| 1296 | |
| 1297 | /* Allocate memory for video device */ |
| 1298 | vfd = video_device_alloc(); |
| 1299 | if (vfd == NULL) { |
| 1300 | for (j = 0; j < i; j++) { |
| 1301 | ch = vpif_obj.dev[j]; |
| 1302 | video_device_release(ch->video_dev); |
| 1303 | } |
| 1304 | err = -ENOMEM; |
Lad, Prabhakar | 9c63e01 | 2013-06-17 11:20:50 -0300 | [diff] [blame] | 1305 | goto vpif_unregister; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1306 | } |
| 1307 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1308 | /* Set video_dev to the video device */ |
| 1309 | ch->video_dev = vfd; |
| 1310 | } |
| 1311 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1312 | vpif_obj.config = pdev->dev.platform_data; |
| 1313 | subdev_count = vpif_obj.config->subdev_count; |
| 1314 | subdevdata = vpif_obj.config->subdevinfo; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1315 | vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count, |
| 1316 | GFP_KERNEL); |
| 1317 | if (vpif_obj.sd == NULL) { |
| 1318 | vpif_err("unable to allocate memory for subdevice pointers\n"); |
| 1319 | err = -ENOMEM; |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1320 | goto vpif_sd_error; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1321 | } |
| 1322 | |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1323 | if (!vpif_obj.config->asd_sizes) { |
| 1324 | i2c_adap = i2c_get_adapter(1); |
| 1325 | for (i = 0; i < subdev_count; i++) { |
| 1326 | vpif_obj.sd[i] = |
| 1327 | v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, |
| 1328 | i2c_adap, |
| 1329 | &subdevdata[i]. |
| 1330 | board_info, |
| 1331 | NULL); |
| 1332 | if (!vpif_obj.sd[i]) { |
| 1333 | vpif_err("Error registering v4l2 subdevice\n"); |
Wei Yongjun | 9d3e976 | 2013-08-22 22:59:44 -0300 | [diff] [blame] | 1334 | err = -ENODEV; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1335 | goto probe_subdev_out; |
| 1336 | } |
| 1337 | |
| 1338 | if (vpif_obj.sd[i]) |
| 1339 | vpif_obj.sd[i]->grp_id = 1 << i; |
| 1340 | } |
| 1341 | vpif_probe_complete(); |
| 1342 | } else { |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 1343 | vpif_obj.notifier.subdevs = vpif_obj.config->asd; |
Lad, Prabhakar | 4b8a531 | 2013-06-25 11:17:35 -0300 | [diff] [blame] | 1344 | vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0]; |
| 1345 | vpif_obj.notifier.bound = vpif_async_bound; |
| 1346 | vpif_obj.notifier.complete = vpif_async_complete; |
| 1347 | err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev, |
| 1348 | &vpif_obj.notifier); |
| 1349 | if (err) { |
| 1350 | vpif_err("Error registering async notifier\n"); |
| 1351 | err = -EINVAL; |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1352 | goto probe_subdev_out; |
| 1353 | } |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1354 | } |
| 1355 | |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1356 | return 0; |
| 1357 | |
Hans Verkuil | e6067f8 | 2012-09-20 09:06:27 -0300 | [diff] [blame] | 1358 | probe_subdev_out: |
| 1359 | kfree(vpif_obj.sd); |
Hans Verkuil | 01b1d975 | 2012-09-20 09:06:28 -0300 | [diff] [blame] | 1360 | vpif_sd_error: |
| 1361 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1362 | ch = vpif_obj.dev[i]; |
| 1363 | /* Note: does nothing if ch->video_dev == NULL */ |
| 1364 | video_device_release(ch->video_dev); |
| 1365 | } |
Lad, Prabhakar | 9c63e01 | 2013-06-17 11:20:50 -0300 | [diff] [blame] | 1366 | vpif_unregister: |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1367 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1368 | |
| 1369 | return err; |
| 1370 | } |
| 1371 | |
| 1372 | /* |
| 1373 | * vpif_remove: It un-register channels from V4L2 driver |
| 1374 | */ |
| 1375 | static int vpif_remove(struct platform_device *device) |
| 1376 | { |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1377 | struct common_obj *common; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1378 | struct channel_obj *ch; |
Lad, Prabhakar | 9c63e01 | 2013-06-17 11:20:50 -0300 | [diff] [blame] | 1379 | int i; |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1380 | |
| 1381 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
| 1382 | |
Lad, Prabhakar | 0b36158 | 2013-06-17 11:20:48 -0300 | [diff] [blame] | 1383 | kfree(vpif_obj.sd); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1384 | /* un-register device */ |
| 1385 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1386 | /* Get the pointer to the channel object */ |
| 1387 | ch = vpif_obj.dev[i]; |
Lad, Prabhakar | a2b235c | 2014-05-16 10:33:06 -0300 | [diff] [blame] | 1388 | common = &ch->common[i]; |
| 1389 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1390 | /* Unregister video device */ |
| 1391 | video_unregister_device(ch->video_dev); |
| 1392 | |
| 1393 | ch->video_dev = NULL; |
Lad, Prabhakar | 0b36158 | 2013-06-17 11:20:48 -0300 | [diff] [blame] | 1394 | kfree(vpif_obj.dev[i]); |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1400 | #ifdef CONFIG_PM_SLEEP |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1401 | static int vpif_suspend(struct device *dev) |
| 1402 | { |
| 1403 | struct common_obj *common; |
| 1404 | struct channel_obj *ch; |
| 1405 | int i; |
| 1406 | |
| 1407 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1408 | /* Get the pointer to the channel object */ |
| 1409 | ch = vpif_obj.dev[i]; |
| 1410 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1411 | |
| 1412 | if (!vb2_is_streaming(&common->buffer_queue)) |
| 1413 | continue; |
| 1414 | |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1415 | mutex_lock(&common->lock); |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1416 | /* Disable channel */ |
| 1417 | if (ch->channel_id == VPIF_CHANNEL2_VIDEO) { |
| 1418 | enable_channel2(0); |
| 1419 | channel2_intr_enable(0); |
| 1420 | } |
| 1421 | if (ch->channel_id == VPIF_CHANNEL3_VIDEO || |
| 1422 | ycmux_mode == 2) { |
| 1423 | enable_channel3(0); |
| 1424 | channel3_intr_enable(0); |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1425 | } |
| 1426 | mutex_unlock(&common->lock); |
| 1427 | } |
| 1428 | |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
| 1432 | static int vpif_resume(struct device *dev) |
| 1433 | { |
| 1434 | |
| 1435 | struct common_obj *common; |
| 1436 | struct channel_obj *ch; |
| 1437 | int i; |
| 1438 | |
| 1439 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { |
| 1440 | /* Get the pointer to the channel object */ |
| 1441 | ch = vpif_obj.dev[i]; |
| 1442 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1443 | |
| 1444 | if (!vb2_is_streaming(&common->buffer_queue)) |
| 1445 | continue; |
| 1446 | |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1447 | mutex_lock(&common->lock); |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1448 | /* Enable channel */ |
| 1449 | if (ch->channel_id == VPIF_CHANNEL2_VIDEO) { |
| 1450 | enable_channel2(1); |
| 1451 | channel2_intr_enable(1); |
| 1452 | } |
| 1453 | if (ch->channel_id == VPIF_CHANNEL3_VIDEO || |
| 1454 | ycmux_mode == 2) { |
| 1455 | enable_channel3(1); |
| 1456 | channel3_intr_enable(1); |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1457 | } |
| 1458 | mutex_unlock(&common->lock); |
| 1459 | } |
| 1460 | |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
Manjunath Hadli | e9530da | 2012-04-13 04:50:35 -0300 | [diff] [blame] | 1464 | #endif |
| 1465 | |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1466 | static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume); |
| 1467 | |
Mats Randgaard | ffa1b39 | 2010-08-30 10:30:36 -0300 | [diff] [blame] | 1468 | static __refdata struct platform_driver vpif_driver = { |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1469 | .driver = { |
Lad, Prabhakar | 76c4c2b | 2014-05-16 10:33:22 -0300 | [diff] [blame] | 1470 | .name = VPIF_DRIVER_NAME, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1471 | .owner = THIS_MODULE, |
Lad, Prabhakar | ba1902e | 2014-05-16 10:33:26 -0300 | [diff] [blame] | 1472 | .pm = &vpif_pm_ops, |
Chaithrika U S | e7332e3 | 2009-06-09 05:55:37 -0300 | [diff] [blame] | 1473 | }, |
| 1474 | .probe = vpif_probe, |
| 1475 | .remove = vpif_remove, |
| 1476 | }; |
| 1477 | |
Lad, Prabhakar | b8d067b | 2013-06-17 11:20:49 -0300 | [diff] [blame] | 1478 | module_platform_driver(vpif_driver); |