Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Texas Instruments Inc |
Lad, Prabhakar | 96787eb | 2014-05-16 10:33:55 -0300 | [diff] [blame] | 3 | * Copyright (C) 2014 Lad, Prabhakar <prabhakar.csengg@gmail.com> |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 15 | * TODO : add support for VBI & HBI data service |
| 16 | * add static buffer allocation |
| 17 | */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 18 | |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/slab.h> |
| 23 | |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 24 | #include <media/v4l2-ioctl.h> |
Kevin Hilman | 4a5f8ae | 2017-06-06 20:37:39 -0300 | [diff] [blame^] | 25 | #include <media/v4l2-of.h> |
| 26 | #include <media/i2c/tvp514x.h> |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 27 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 28 | #include "vpif.h" |
Lad, Prabhakar | 012eef7 | 2013-04-19 05:53:29 -0300 | [diff] [blame] | 29 | #include "vpif_capture.h" |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 30 | |
| 31 | MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver"); |
| 32 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 64dc3c1 | 2011-06-25 11:28:37 -0300 | [diff] [blame] | 33 | MODULE_VERSION(VPIF_CAPTURE_VERSION); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 34 | |
| 35 | #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg) |
| 36 | #define vpif_dbg(level, debug, fmt, arg...) \ |
| 37 | v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg) |
| 38 | |
| 39 | static int debug = 1; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 40 | |
| 41 | module_param(debug, int, 0644); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 42 | |
| 43 | MODULE_PARM_DESC(debug, "Debug level 0-1"); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 44 | |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 45 | #define VPIF_DRIVER_NAME "vpif_capture" |
Kevin Hilman | bff782d | 2016-12-16 22:47:54 -0200 | [diff] [blame] | 46 | MODULE_ALIAS("platform:" VPIF_DRIVER_NAME); |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 47 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 48 | /* global variables */ |
| 49 | static struct vpif_device vpif_obj = { {NULL} }; |
| 50 | static struct device *vpif_dev; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 51 | static void vpif_calculate_offsets(struct channel_obj *ch); |
| 52 | static void vpif_config_addr(struct channel_obj *ch, int muxmode); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 53 | |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 54 | static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} }; |
| 55 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 56 | /* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */ |
| 57 | static int ycmux_mode; |
| 58 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 59 | static inline |
| 60 | struct vpif_cap_buffer *to_vpif_buffer(struct vb2_v4l2_buffer *vb) |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 61 | { |
| 62 | return container_of(vb, struct vpif_cap_buffer, vb); |
| 63 | } |
| 64 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 65 | /** |
Lad, Prabhakar | 23e76a2 | 2014-05-16 10:33:37 -0300 | [diff] [blame] | 66 | * vpif_buffer_prepare : callback function for buffer prepare |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 67 | * @vb: ptr to vb2_buffer |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 68 | * |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 69 | * This is the callback function for buffer prepare when vb2_qbuf() |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 70 | * function is called. The buffer is prepared and user space virtual address |
| 71 | * or user address is converted into physical address |
| 72 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 73 | static int vpif_buffer_prepare(struct vb2_buffer *vb) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 74 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 75 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 76 | struct vb2_queue *q = vb->vb2_queue; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 77 | struct channel_obj *ch = vb2_get_drv_priv(q); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 78 | struct common_obj *common; |
| 79 | unsigned long addr; |
| 80 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 81 | vpif_dbg(2, debug, "vpif_buffer_prepare\n"); |
| 82 | |
| 83 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 84 | |
Lad, Prabhakar | 23e76a2 | 2014-05-16 10:33:37 -0300 | [diff] [blame] | 85 | vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage); |
| 86 | if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) |
| 87 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 88 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 89 | vbuf->field = common->fmt.fmt.pix.field; |
Lad, Prabhakar | 23e76a2 | 2014-05-16 10:33:37 -0300 | [diff] [blame] | 90 | |
| 91 | addr = vb2_dma_contig_plane_dma_addr(vb, 0); |
| 92 | if (!IS_ALIGNED((addr + common->ytop_off), 8) || |
| 93 | !IS_ALIGNED((addr + common->ybtm_off), 8) || |
| 94 | !IS_ALIGNED((addr + common->ctop_off), 8) || |
| 95 | !IS_ALIGNED((addr + common->cbtm_off), 8)) { |
| 96 | vpif_dbg(1, debug, "offset is not aligned\n"); |
| 97 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 98 | } |
Lad, Prabhakar | 23e76a2 | 2014-05-16 10:33:37 -0300 | [diff] [blame] | 99 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 100 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 104 | * vpif_buffer_queue_setup : Callback function for buffer setup. |
| 105 | * @vq: vb2_queue ptr |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 106 | * @nbuffers: ptr to number of buffers requested by application |
| 107 | * @nplanes:: contains number of distinct video planes needed to hold a frame |
| 108 | * @sizes[]: contains the size (in bytes) of each plane. |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame] | 109 | * @alloc_devs: ptr to allocation context |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 110 | * |
| 111 | * This callback function is called when reqbuf() is called to adjust |
| 112 | * the buffer count and buffer size |
| 113 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 114 | static int vpif_buffer_queue_setup(struct vb2_queue *vq, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 115 | unsigned int *nbuffers, unsigned int *nplanes, |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame] | 116 | unsigned int sizes[], struct device *alloc_devs[]) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 117 | { |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 118 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 119 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 120 | unsigned size = common->fmt.fmt.pix.sizeimage; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 121 | |
| 122 | vpif_dbg(2, debug, "vpif_buffer_setup\n"); |
| 123 | |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 124 | if (*nplanes) { |
| 125 | if (sizes[0] < size) |
| 126 | return -EINVAL; |
| 127 | size = sizes[0]; |
| 128 | } |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 129 | |
Lad, Prabhakar | 837939d | 2014-05-16 10:33:38 -0300 | [diff] [blame] | 130 | if (vq->num_buffers + *nbuffers < 3) |
| 131 | *nbuffers = 3 - vq->num_buffers; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 132 | |
| 133 | *nplanes = 1; |
Hans Verkuil | df9ecb0 | 2015-10-28 00:50:37 -0200 | [diff] [blame] | 134 | sizes[0] = size; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 135 | |
Lad, Prabhakar | 837939d | 2014-05-16 10:33:38 -0300 | [diff] [blame] | 136 | /* Calculate the offset for Y and C data in the buffer */ |
| 137 | vpif_calculate_offsets(ch); |
| 138 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * vpif_buffer_queue : Callback function to add buffer to DMA queue |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 144 | * @vb: ptr to vb2_buffer |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 145 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 146 | static void vpif_buffer_queue(struct vb2_buffer *vb) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 147 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 148 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 149 | struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 150 | struct vpif_cap_buffer *buf = to_vpif_buffer(vbuf); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 151 | struct common_obj *common; |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 152 | unsigned long flags; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 153 | |
| 154 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 155 | |
| 156 | vpif_dbg(2, debug, "vpif_buffer_queue\n"); |
| 157 | |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 158 | spin_lock_irqsave(&common->irqlock, flags); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 159 | /* add the buffer to the DMA queue */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 160 | list_add_tail(&buf->list, &common->dma_queue); |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 161 | spin_unlock_irqrestore(&common->irqlock, flags); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 162 | } |
| 163 | |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 164 | /** |
| 165 | * vpif_start_streaming : Starts the DMA engine for streaming |
| 166 | * @vb: ptr to vb2_buffer |
| 167 | * @count: number of buffers |
| 168 | */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 169 | static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) |
| 170 | { |
| 171 | struct vpif_capture_config *vpif_config_data = |
| 172 | vpif_dev->platform_data; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 173 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 174 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 175 | struct vpif_params *vpif = &ch->vpifparams; |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 176 | struct vpif_cap_buffer *buf, *tmp; |
| 177 | unsigned long addr, flags; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 178 | int ret; |
| 179 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 180 | /* Initialize field_id */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 181 | ch->field_id = 0; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 182 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 183 | /* configure 1 or 2 channel mode */ |
Lad, Prabhakar | f4ad8d7 | 2012-09-27 02:33:12 -0300 | [diff] [blame] | 184 | if (vpif_config_data->setup_input_channel_mode) { |
| 185 | ret = vpif_config_data-> |
| 186 | setup_input_channel_mode(vpif->std_info.ycmux_mode); |
| 187 | if (ret < 0) { |
| 188 | vpif_dbg(1, debug, "can't set vpif channel mode\n"); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 189 | goto err; |
Lad, Prabhakar | f4ad8d7 | 2012-09-27 02:33:12 -0300 | [diff] [blame] | 190 | } |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 191 | } |
| 192 | |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 193 | ret = v4l2_subdev_call(ch->sd, video, s_stream, 1); |
| 194 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) { |
| 195 | vpif_dbg(1, debug, "stream on failed in subdev\n"); |
| 196 | goto err; |
| 197 | } |
| 198 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 199 | /* Call vpif_set_params function to set the parameters and addresses */ |
| 200 | ret = vpif_set_video_params(vpif, ch->channel_id); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 201 | if (ret < 0) { |
| 202 | vpif_dbg(1, debug, "can't set video params\n"); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 203 | goto err; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 204 | } |
| 205 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 206 | ycmux_mode = ret; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 207 | vpif_config_addr(ch, ret); |
| 208 | |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 209 | /* Get the next frame from the buffer queue */ |
Kevin Hilman | 62dd4ac | 2016-12-07 16:30:23 -0200 | [diff] [blame] | 210 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 211 | common->cur_frm = common->next_frm = list_entry(common->dma_queue.next, |
| 212 | struct vpif_cap_buffer, list); |
| 213 | /* Remove buffer from the buffer queue */ |
| 214 | list_del(&common->cur_frm->list); |
| 215 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 216 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 217 | addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb.vb2_buf, 0); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 218 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 219 | common->set_addr(addr + common->ytop_off, |
| 220 | addr + common->ybtm_off, |
| 221 | addr + common->ctop_off, |
| 222 | addr + common->cbtm_off); |
| 223 | |
| 224 | /** |
| 225 | * Set interrupt for both the fields in VPIF Register enable channel in |
| 226 | * VPIF register |
| 227 | */ |
Lad, Prabhakar | 9e18404 | 2012-09-14 10:22:24 -0300 | [diff] [blame] | 228 | channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1; |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 229 | if (VPIF_CHANNEL0_VIDEO == ch->channel_id) { |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 230 | channel0_intr_assert(); |
| 231 | channel0_intr_enable(1); |
| 232 | enable_channel0(1); |
| 233 | } |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 234 | if (VPIF_CHANNEL1_VIDEO == ch->channel_id || |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 235 | ycmux_mode == 2) { |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 236 | channel1_intr_assert(); |
| 237 | channel1_intr_enable(1); |
| 238 | enable_channel1(1); |
| 239 | } |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 240 | |
| 241 | return 0; |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 242 | |
| 243 | err: |
Kevin Hilman | 62dd4ac | 2016-12-07 16:30:23 -0200 | [diff] [blame] | 244 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 245 | list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) { |
| 246 | list_del(&buf->list); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 247 | vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 248 | } |
Dan Carpenter | 9249196 | 2014-06-12 04:01:45 -0300 | [diff] [blame] | 249 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | bebd8d1 | 2014-05-16 10:33:35 -0300 | [diff] [blame] | 250 | |
| 251 | return ret; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 252 | } |
| 253 | |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 254 | /** |
| 255 | * vpif_stop_streaming : Stop the DMA engine |
| 256 | * @vq: ptr to vb2_queue |
| 257 | * |
| 258 | * This callback stops the DMA engine and any remaining buffers |
| 259 | * in the DMA queue are released. |
| 260 | */ |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 261 | static void vpif_stop_streaming(struct vb2_queue *vq) |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 262 | { |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 263 | struct channel_obj *ch = vb2_get_drv_priv(vq); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 264 | struct common_obj *common; |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 265 | unsigned long flags; |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 266 | int ret; |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 267 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 268 | common = &ch->common[VPIF_VIDEO_INDEX]; |
| 269 | |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 270 | /* Disable channel as per its device type and channel id */ |
| 271 | if (VPIF_CHANNEL0_VIDEO == ch->channel_id) { |
| 272 | enable_channel0(0); |
| 273 | channel0_intr_enable(0); |
| 274 | } |
Lad, Prabhakar | 41b9f24 | 2014-05-16 10:33:39 -0300 | [diff] [blame] | 275 | if (VPIF_CHANNEL1_VIDEO == ch->channel_id || |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 276 | ycmux_mode == 2) { |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 277 | enable_channel1(0); |
| 278 | channel1_intr_enable(0); |
| 279 | } |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 280 | |
| 281 | ycmux_mode = 0; |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 282 | |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 283 | ret = v4l2_subdev_call(ch->sd, video, s_stream, 0); |
| 284 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) |
| 285 | vpif_dbg(1, debug, "stream off failed in subdev\n"); |
| 286 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 287 | /* release all active buffers */ |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 288 | if (common->cur_frm == common->next_frm) { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 289 | vb2_buffer_done(&common->cur_frm->vb.vb2_buf, |
| 290 | VB2_BUF_STATE_ERROR); |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 291 | } else { |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 292 | if (common->cur_frm) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 293 | vb2_buffer_done(&common->cur_frm->vb.vb2_buf, |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 294 | VB2_BUF_STATE_ERROR); |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 295 | if (common->next_frm) |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 296 | vb2_buffer_done(&common->next_frm->vb.vb2_buf, |
Lad, Prabhakar | e6ba3db | 2014-03-22 08:03:07 -0300 | [diff] [blame] | 297 | VB2_BUF_STATE_ERROR); |
| 298 | } |
| 299 | |
Kevin Hilman | 62dd4ac | 2016-12-07 16:30:23 -0200 | [diff] [blame] | 300 | spin_lock_irqsave(&common->irqlock, flags); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 301 | while (!list_empty(&common->dma_queue)) { |
| 302 | common->next_frm = list_entry(common->dma_queue.next, |
| 303 | struct vpif_cap_buffer, list); |
| 304 | list_del(&common->next_frm->list); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 305 | vb2_buffer_done(&common->next_frm->vb.vb2_buf, |
| 306 | VB2_BUF_STATE_ERROR); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 307 | } |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 308 | spin_unlock_irqrestore(&common->irqlock, flags); |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static struct vb2_ops video_qops = { |
| 312 | .queue_setup = vpif_buffer_queue_setup, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 313 | .buf_prepare = vpif_buffer_prepare, |
| 314 | .start_streaming = vpif_start_streaming, |
| 315 | .stop_streaming = vpif_stop_streaming, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 316 | .buf_queue = vpif_buffer_queue, |
Prabhakar Lad | b41a97a | 2014-11-26 19:42:33 -0300 | [diff] [blame] | 317 | .wait_prepare = vb2_ops_wait_prepare, |
| 318 | .wait_finish = vb2_ops_wait_finish, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 319 | }; |
| 320 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 321 | /** |
| 322 | * vpif_process_buffer_complete: process a completed buffer |
| 323 | * @common: ptr to common channel object |
| 324 | * |
| 325 | * This function time stamp the buffer and mark it as DONE. It also |
| 326 | * wake up any process waiting on the QUEUE and set the next buffer |
| 327 | * as current |
| 328 | */ |
| 329 | static void vpif_process_buffer_complete(struct common_obj *common) |
| 330 | { |
Junghak Sung | d6dd645 | 2015-11-03 08:16:37 -0200 | [diff] [blame] | 331 | common->cur_frm->vb.vb2_buf.timestamp = ktime_get_ns(); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 332 | vb2_buffer_done(&common->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 333 | /* Make curFrm pointing to nextFrm */ |
| 334 | common->cur_frm = common->next_frm; |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * vpif_schedule_next_buffer: set next buffer address for capture |
| 339 | * @common : ptr to common channel object |
| 340 | * |
| 341 | * This function will get next buffer from the dma queue and |
| 342 | * set the buffer address in the vpif register for capture. |
| 343 | * the buffer is marked active |
| 344 | */ |
| 345 | static void vpif_schedule_next_buffer(struct common_obj *common) |
| 346 | { |
| 347 | unsigned long addr = 0; |
| 348 | |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 349 | spin_lock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 350 | common->next_frm = list_entry(common->dma_queue.next, |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 351 | struct vpif_cap_buffer, list); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 352 | /* Remove that buffer from the buffer queue */ |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 353 | list_del(&common->next_frm->list); |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 354 | spin_unlock(&common->irqlock); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 355 | addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb.vb2_buf, 0); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 356 | |
| 357 | /* Set top and bottom field addresses in VPIF registers */ |
| 358 | common->set_addr(addr + common->ytop_off, |
| 359 | addr + common->ybtm_off, |
| 360 | addr + common->ctop_off, |
| 361 | addr + common->cbtm_off); |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * vpif_channel_isr : ISR handler for vpif capture |
| 366 | * @irq: irq number |
| 367 | * @dev_id: dev_id ptr |
| 368 | * |
| 369 | * It changes status of the captured buffer, takes next buffer from the queue |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 370 | * and sets its address in VPIF registers |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 371 | */ |
| 372 | static irqreturn_t vpif_channel_isr(int irq, void *dev_id) |
| 373 | { |
| 374 | struct vpif_device *dev = &vpif_obj; |
| 375 | struct common_obj *common; |
| 376 | struct channel_obj *ch; |
Markus Elfring | c64d61d | 2016-10-12 10:25:08 -0300 | [diff] [blame] | 377 | int channel_id; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 378 | int fid = -1, i; |
| 379 | |
| 380 | channel_id = *(int *)(dev_id); |
Manjunath Hadli | b1fc423 | 2012-04-13 04:43:10 -0300 | [diff] [blame] | 381 | if (!vpif_intr_status(channel_id)) |
| 382 | return IRQ_NONE; |
| 383 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 384 | ch = dev->dev[channel_id]; |
| 385 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 386 | for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) { |
| 387 | common = &ch->common[i]; |
| 388 | /* skip If streaming is not started in this channel */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 389 | /* Check the field format */ |
| 390 | if (1 == ch->vpifparams.std_info.frm_fmt) { |
| 391 | /* Progressive mode */ |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 392 | spin_lock(&common->irqlock); |
| 393 | if (list_empty(&common->dma_queue)) { |
| 394 | spin_unlock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 395 | continue; |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 396 | } |
| 397 | spin_unlock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 398 | |
| 399 | if (!channel_first_int[i][channel_id]) |
| 400 | vpif_process_buffer_complete(common); |
| 401 | |
| 402 | channel_first_int[i][channel_id] = 0; |
| 403 | |
| 404 | vpif_schedule_next_buffer(common); |
| 405 | |
| 406 | |
| 407 | channel_first_int[i][channel_id] = 0; |
| 408 | } else { |
| 409 | /** |
| 410 | * Interlaced mode. If it is first interrupt, ignore |
| 411 | * it |
| 412 | */ |
| 413 | if (channel_first_int[i][channel_id]) { |
| 414 | channel_first_int[i][channel_id] = 0; |
| 415 | continue; |
| 416 | } |
| 417 | if (0 == i) { |
| 418 | ch->field_id ^= 1; |
| 419 | /* Get field id from VPIF registers */ |
| 420 | fid = vpif_channel_getfid(ch->channel_id); |
| 421 | if (fid != ch->field_id) { |
| 422 | /** |
| 423 | * If field id does not match stored |
| 424 | * field id, make them in sync |
| 425 | */ |
| 426 | if (0 == fid) |
| 427 | ch->field_id = fid; |
| 428 | return IRQ_HANDLED; |
| 429 | } |
| 430 | } |
| 431 | /* device field id and local field id are in sync */ |
| 432 | if (0 == fid) { |
| 433 | /* this is even field */ |
| 434 | if (common->cur_frm == common->next_frm) |
| 435 | continue; |
| 436 | |
| 437 | /* mark the current buffer as done */ |
| 438 | vpif_process_buffer_complete(common); |
| 439 | } else if (1 == fid) { |
| 440 | /* odd field */ |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 441 | spin_lock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 442 | if (list_empty(&common->dma_queue) || |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 443 | (common->cur_frm != common->next_frm)) { |
| 444 | spin_unlock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 445 | continue; |
Hans Verkuil | aec9683 | 2012-11-16 12:03:06 -0300 | [diff] [blame] | 446 | } |
| 447 | spin_unlock(&common->irqlock); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 448 | |
| 449 | vpif_schedule_next_buffer(common); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | return IRQ_HANDLED; |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * vpif_update_std_info() - update standard related info |
| 458 | * @ch: ptr to channel object |
| 459 | * |
| 460 | * For a given standard selected by application, update values |
| 461 | * in the device data structures |
| 462 | */ |
| 463 | static int vpif_update_std_info(struct channel_obj *ch) |
| 464 | { |
| 465 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 466 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 467 | const struct vpif_channel_config_params *config; |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 468 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 469 | struct video_obj *vid_ch = &ch->video; |
| 470 | int index; |
| 471 | |
| 472 | vpif_dbg(2, debug, "vpif_update_std_info\n"); |
| 473 | |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 474 | for (index = 0; index < vpif_ch_params_count; index++) { |
Lad, Prabhakar | ced9b21 | 2013-03-20 01:28:27 -0300 | [diff] [blame] | 475 | config = &vpif_ch_params[index]; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 476 | if (config->hd_sd == 0) { |
| 477 | vpif_dbg(2, debug, "SD format\n"); |
| 478 | if (config->stdid & vid_ch->stdid) { |
| 479 | memcpy(std_info, config, sizeof(*config)); |
| 480 | break; |
| 481 | } |
| 482 | } else { |
| 483 | vpif_dbg(2, debug, "HD format\n"); |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 484 | if (!memcmp(&config->dv_timings, &vid_ch->dv_timings, |
| 485 | sizeof(vid_ch->dv_timings))) { |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 486 | memcpy(std_info, config, sizeof(*config)); |
| 487 | break; |
| 488 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
| 492 | /* standard not found */ |
Mats Randgaard | aa44440 | 2010-12-16 12:17:42 -0300 | [diff] [blame] | 493 | if (index == vpif_ch_params_count) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 494 | return -EINVAL; |
| 495 | |
| 496 | common->fmt.fmt.pix.width = std_info->width; |
| 497 | common->width = std_info->width; |
| 498 | common->fmt.fmt.pix.height = std_info->height; |
| 499 | common->height = std_info->height; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 500 | common->fmt.fmt.pix.sizeimage = common->height * common->width * 2; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 501 | common->fmt.fmt.pix.bytesperline = std_info->width; |
| 502 | vpifparams->video_params.hpitch = std_info->width; |
| 503 | vpifparams->video_params.storage_mode = std_info->frm_fmt; |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 504 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 505 | if (vid_ch->stdid) |
| 506 | common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 507 | else |
| 508 | common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_REC709; |
| 509 | |
| 510 | if (ch->vpifparams.std_info.frm_fmt) |
| 511 | common->fmt.fmt.pix.field = V4L2_FIELD_NONE; |
| 512 | else |
| 513 | common->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; |
| 514 | |
| 515 | if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) |
| 516 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8; |
| 517 | else |
Nori, Sekhar | 8946ab3 | 2017-05-26 07:55:27 -0300 | [diff] [blame] | 518 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_NV16; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 519 | |
| 520 | common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 521 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * vpif_calculate_offsets : This function calculates buffers offsets |
| 527 | * @ch : ptr to channel object |
| 528 | * |
| 529 | * This function calculates buffer offsets for Y and C in the top and |
| 530 | * bottom field |
| 531 | */ |
| 532 | static void vpif_calculate_offsets(struct channel_obj *ch) |
| 533 | { |
Mauro Carvalho Chehab | 24ab633 | 2014-08-21 15:49:06 -0500 | [diff] [blame] | 534 | unsigned int hpitch, sizeimage; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 535 | struct video_obj *vid_ch = &(ch->video); |
| 536 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 537 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 538 | enum v4l2_field field = common->fmt.fmt.pix.field; |
| 539 | |
| 540 | vpif_dbg(2, debug, "vpif_calculate_offsets\n"); |
| 541 | |
| 542 | if (V4L2_FIELD_ANY == field) { |
| 543 | if (vpifparams->std_info.frm_fmt) |
| 544 | vid_ch->buf_field = V4L2_FIELD_NONE; |
| 545 | else |
| 546 | vid_ch->buf_field = V4L2_FIELD_INTERLACED; |
| 547 | } else |
| 548 | vid_ch->buf_field = common->fmt.fmt.pix.field; |
| 549 | |
Lad, Prabhakar | 60aa38d | 2012-06-28 09:28:05 -0300 | [diff] [blame] | 550 | sizeimage = common->fmt.fmt.pix.sizeimage; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 551 | |
| 552 | hpitch = common->fmt.fmt.pix.bytesperline; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 553 | |
| 554 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 555 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) { |
| 556 | /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */ |
| 557 | common->ytop_off = 0; |
| 558 | common->ybtm_off = hpitch; |
| 559 | common->ctop_off = sizeimage / 2; |
| 560 | common->cbtm_off = sizeimage / 2 + hpitch; |
| 561 | } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) { |
| 562 | /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */ |
| 563 | common->ytop_off = 0; |
| 564 | common->ybtm_off = sizeimage / 4; |
| 565 | common->ctop_off = sizeimage / 2; |
| 566 | common->cbtm_off = common->ctop_off + sizeimage / 4; |
| 567 | } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) { |
| 568 | /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */ |
| 569 | common->ybtm_off = 0; |
| 570 | common->ytop_off = sizeimage / 4; |
| 571 | common->cbtm_off = sizeimage / 2; |
| 572 | common->ctop_off = common->cbtm_off + sizeimage / 4; |
| 573 | } |
| 574 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || |
| 575 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) |
| 576 | vpifparams->video_params.storage_mode = 1; |
| 577 | else |
| 578 | vpifparams->video_params.storage_mode = 0; |
| 579 | |
| 580 | if (1 == vpifparams->std_info.frm_fmt) |
| 581 | vpifparams->video_params.hpitch = |
| 582 | common->fmt.fmt.pix.bytesperline; |
| 583 | else { |
| 584 | if ((field == V4L2_FIELD_ANY) |
| 585 | || (field == V4L2_FIELD_INTERLACED)) |
| 586 | vpifparams->video_params.hpitch = |
| 587 | common->fmt.fmt.pix.bytesperline * 2; |
| 588 | else |
| 589 | vpifparams->video_params.hpitch = |
| 590 | common->fmt.fmt.pix.bytesperline; |
| 591 | } |
| 592 | |
| 593 | ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid; |
| 594 | } |
| 595 | |
| 596 | /** |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 597 | * vpif_get_default_field() - Get default field type based on interface |
| 598 | * @vpif_params - ptr to vpif params |
| 599 | */ |
| 600 | static inline enum v4l2_field vpif_get_default_field( |
| 601 | struct vpif_interface *iface) |
| 602 | { |
| 603 | return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE : |
| 604 | V4L2_FIELD_INTERLACED; |
| 605 | } |
| 606 | |
| 607 | /** |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 608 | * vpif_config_addr() - function to configure buffer address in vpif |
| 609 | * @ch - channel ptr |
| 610 | * @muxmode - channel mux mode |
| 611 | */ |
| 612 | static void vpif_config_addr(struct channel_obj *ch, int muxmode) |
| 613 | { |
| 614 | struct common_obj *common; |
| 615 | |
| 616 | vpif_dbg(2, debug, "vpif_config_addr\n"); |
| 617 | |
| 618 | common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 619 | |
| 620 | if (VPIF_CHANNEL1_VIDEO == ch->channel_id) |
| 621 | common->set_addr = ch1_set_videobuf_addr; |
| 622 | else if (2 == muxmode) |
| 623 | common->set_addr = ch0_set_videobuf_addr_yc_nmux; |
| 624 | else |
| 625 | common->set_addr = ch0_set_videobuf_addr; |
| 626 | } |
| 627 | |
| 628 | /** |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 629 | * vpif_input_to_subdev() - Maps input to sub device |
| 630 | * @vpif_cfg - global config ptr |
| 631 | * @chan_cfg - channel config ptr |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 632 | * @input_index - Given input index from application |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 633 | * |
| 634 | * lookup the sub device information for a given input index. |
| 635 | * we report all the inputs to application. inputs table also |
| 636 | * has sub device name for the each input |
| 637 | */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 638 | static int vpif_input_to_subdev( |
| 639 | struct vpif_capture_config *vpif_cfg, |
| 640 | struct vpif_capture_chan_config *chan_cfg, |
| 641 | int input_index) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 642 | { |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 643 | struct vpif_subdev_info *subdev_info; |
| 644 | const char *subdev_name; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 645 | int i; |
| 646 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 647 | vpif_dbg(2, debug, "vpif_input_to_subdev\n"); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 648 | |
Kevin Hilman | bff782d | 2016-12-16 22:47:54 -0200 | [diff] [blame] | 649 | if (!chan_cfg) |
| 650 | return -1; |
| 651 | if (input_index >= chan_cfg->input_count) |
| 652 | return -1; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 653 | subdev_name = chan_cfg->inputs[input_index].subdev_name; |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 654 | if (!subdev_name) |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 655 | return -1; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 656 | |
| 657 | /* loop through the sub device list to get the sub device info */ |
| 658 | for (i = 0; i < vpif_cfg->subdev_count; i++) { |
| 659 | subdev_info = &vpif_cfg->subdev_info[i]; |
Kevin Hilman | 4a5f8ae | 2017-06-06 20:37:39 -0300 | [diff] [blame^] | 660 | if (subdev_info && !strcmp(subdev_info->name, subdev_name)) |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 661 | return i; |
| 662 | } |
| 663 | return -1; |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * vpif_set_input() - Select an input |
| 668 | * @vpif_cfg - global config ptr |
| 669 | * @ch - channel |
| 670 | * @_index - Given input index from application |
| 671 | * |
| 672 | * Select the given input. |
| 673 | */ |
| 674 | static int vpif_set_input( |
| 675 | struct vpif_capture_config *vpif_cfg, |
| 676 | struct channel_obj *ch, |
| 677 | int index) |
| 678 | { |
| 679 | struct vpif_capture_chan_config *chan_cfg = |
| 680 | &vpif_cfg->chan_config[ch->channel_id]; |
| 681 | struct vpif_subdev_info *subdev_info = NULL; |
| 682 | struct v4l2_subdev *sd = NULL; |
| 683 | u32 input = 0, output = 0; |
| 684 | int sd_index; |
| 685 | int ret; |
| 686 | |
| 687 | sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index); |
| 688 | if (sd_index >= 0) { |
| 689 | sd = vpif_obj.sd[sd_index]; |
| 690 | subdev_info = &vpif_cfg->subdev_info[sd_index]; |
Kevin Hilman | bff782d | 2016-12-16 22:47:54 -0200 | [diff] [blame] | 691 | } else { |
| 692 | /* no subdevice, no input to setup */ |
| 693 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 694 | } |
| 695 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 696 | /* first setup input path from sub device to vpif */ |
| 697 | if (sd && vpif_cfg->setup_input_path) { |
| 698 | ret = vpif_cfg->setup_input_path(ch->channel_id, |
| 699 | subdev_info->name); |
| 700 | if (ret < 0) { |
| 701 | vpif_dbg(1, debug, "couldn't setup input path for the" \ |
| 702 | " sub device %s, for input index %d\n", |
| 703 | subdev_info->name, index); |
| 704 | return ret; |
| 705 | } |
| 706 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 707 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 708 | if (sd) { |
| 709 | input = chan_cfg->inputs[index].input_route; |
| 710 | output = chan_cfg->inputs[index].output_route; |
| 711 | ret = v4l2_subdev_call(sd, video, s_routing, |
| 712 | input, output, 0); |
| 713 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
| 714 | vpif_dbg(1, debug, "Failed to set input\n"); |
| 715 | return ret; |
| 716 | } |
| 717 | } |
| 718 | ch->input_idx = index; |
| 719 | ch->sd = sd; |
| 720 | /* copy interface parameters to vpif */ |
Hans Verkuil | 0d4f35f | 2012-09-20 09:06:32 -0300 | [diff] [blame] | 721 | ch->vpifparams.iface = chan_cfg->vpif_if; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 722 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 723 | /* update tvnorms from the sub device input info */ |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 724 | ch->video_dev.tvnorms = chan_cfg->inputs[index].input.std; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 725 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /** |
| 729 | * vpif_querystd() - querystd handler |
| 730 | * @file: file ptr |
| 731 | * @priv: file handle |
| 732 | * @std_id: ptr to std id |
| 733 | * |
| 734 | * This function is called to detect standard at the selected input |
| 735 | */ |
| 736 | static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id) |
| 737 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 738 | struct video_device *vdev = video_devdata(file); |
| 739 | struct channel_obj *ch = video_get_drvdata(vdev); |
Markus Elfring | 6a842cc | 2016-10-12 10:22:45 -0300 | [diff] [blame] | 740 | int ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 741 | |
| 742 | vpif_dbg(2, debug, "vpif_querystd\n"); |
| 743 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 744 | /* Call querystd function of decoder device */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 745 | ret = v4l2_subdev_call(ch->sd, video, querystd, std_id); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 746 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 747 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 748 | return -ENODATA; |
| 749 | if (ret) { |
| 750 | vpif_dbg(1, debug, "Failed to query standard for sub devices\n"); |
| 751 | return ret; |
| 752 | } |
| 753 | |
| 754 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /** |
| 758 | * vpif_g_std() - get STD handler |
| 759 | * @file: file ptr |
| 760 | * @priv: file handle |
| 761 | * @std_id: ptr to std id |
| 762 | */ |
| 763 | static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std) |
| 764 | { |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 765 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 766 | struct video_device *vdev = video_devdata(file); |
| 767 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 768 | struct vpif_capture_chan_config *chan_cfg; |
| 769 | struct v4l2_input input; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 770 | |
| 771 | vpif_dbg(2, debug, "vpif_g_std\n"); |
| 772 | |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 773 | if (!config->chan_config[ch->channel_id].inputs) |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 774 | return -ENODATA; |
| 775 | |
| 776 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 777 | input = chan_cfg->inputs[ch->input_idx].input; |
| 778 | if (input.capabilities != V4L2_IN_CAP_STD) |
| 779 | return -ENODATA; |
| 780 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 781 | *std = ch->video.stdid; |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | /** |
| 786 | * vpif_s_std() - set STD handler |
| 787 | * @file: file ptr |
| 788 | * @priv: file handle |
| 789 | * @std_id: ptr to std id |
| 790 | */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 791 | static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 792 | { |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 793 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 794 | struct video_device *vdev = video_devdata(file); |
| 795 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 796 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 797 | struct vpif_capture_chan_config *chan_cfg; |
| 798 | struct v4l2_input input; |
| 799 | int ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 800 | |
| 801 | vpif_dbg(2, debug, "vpif_s_std\n"); |
| 802 | |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 803 | if (!config->chan_config[ch->channel_id].inputs) |
Lad, Prabhakar | d557b7d | 2014-05-16 10:33:52 -0300 | [diff] [blame] | 804 | return -ENODATA; |
| 805 | |
| 806 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 807 | input = chan_cfg->inputs[ch->input_idx].input; |
| 808 | if (input.capabilities != V4L2_IN_CAP_STD) |
| 809 | return -ENODATA; |
| 810 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 811 | if (vb2_is_busy(&common->buffer_queue)) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 812 | return -EBUSY; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 813 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 814 | /* Call encoder subdevice function to set the standard */ |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 815 | ch->video.stdid = std_id; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 816 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 817 | |
| 818 | /* Get the information about the standard */ |
| 819 | if (vpif_update_std_info(ch)) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 820 | vpif_err("Error getting the standard info\n"); |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 821 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 822 | } |
| 823 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 824 | /* set standard in the sub device */ |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 825 | ret = v4l2_subdev_call(ch->sd, video, s_std, std_id); |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 826 | if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 827 | vpif_dbg(1, debug, "Failed to set standard for sub devices\n"); |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 828 | return ret; |
| 829 | } |
| 830 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
| 834 | * vpif_enum_input() - ENUMINPUT handler |
| 835 | * @file: file ptr |
| 836 | * @priv: file handle |
| 837 | * @input: ptr to input structure |
| 838 | */ |
| 839 | static int vpif_enum_input(struct file *file, void *priv, |
| 840 | struct v4l2_input *input) |
| 841 | { |
| 842 | |
| 843 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 844 | struct video_device *vdev = video_devdata(file); |
| 845 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 846 | struct vpif_capture_chan_config *chan_cfg; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 847 | |
| 848 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 849 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 850 | if (input->index >= chan_cfg->input_count) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 851 | return -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 852 | |
| 853 | memcpy(input, &chan_cfg->inputs[input->index].input, |
| 854 | sizeof(*input)); |
| 855 | return 0; |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * vpif_g_input() - Get INPUT handler |
| 860 | * @file: file ptr |
| 861 | * @priv: file handle |
| 862 | * @index: ptr to input index |
| 863 | */ |
| 864 | static int vpif_g_input(struct file *file, void *priv, unsigned int *index) |
| 865 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 866 | struct video_device *vdev = video_devdata(file); |
| 867 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 868 | |
Hans Verkuil | 6f47c6c | 2012-09-20 09:06:22 -0300 | [diff] [blame] | 869 | *index = ch->input_idx; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 870 | return 0; |
| 871 | } |
| 872 | |
| 873 | /** |
| 874 | * vpif_s_input() - Set INPUT handler |
| 875 | * @file: file ptr |
| 876 | * @priv: file handle |
| 877 | * @index: input index |
| 878 | */ |
| 879 | static int vpif_s_input(struct file *file, void *priv, unsigned int index) |
| 880 | { |
| 881 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 882 | struct video_device *vdev = video_devdata(file); |
| 883 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 884 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 885 | struct vpif_capture_chan_config *chan_cfg; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 886 | |
| 887 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 888 | |
Hans Verkuil | 7aaad13 | 2012-09-20 09:06:25 -0300 | [diff] [blame] | 889 | if (index >= chan_cfg->input_count) |
| 890 | return -EINVAL; |
| 891 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 892 | if (vb2_is_busy(&common->buffer_queue)) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 893 | return -EBUSY; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 894 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 895 | return vpif_set_input(config, ch, index); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /** |
| 899 | * vpif_enum_fmt_vid_cap() - ENUM_FMT handler |
| 900 | * @file: file ptr |
| 901 | * @priv: file handle |
| 902 | * @index: input index |
| 903 | */ |
| 904 | static int vpif_enum_fmt_vid_cap(struct file *file, void *priv, |
| 905 | struct v4l2_fmtdesc *fmt) |
| 906 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 907 | struct video_device *vdev = video_devdata(file); |
| 908 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 909 | |
| 910 | if (fmt->index != 0) { |
| 911 | vpif_dbg(1, debug, "Invalid format index\n"); |
| 912 | return -EINVAL; |
| 913 | } |
| 914 | |
| 915 | /* Fill in the information about format */ |
| 916 | if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) { |
| 917 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 918 | strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb"); |
| 919 | fmt->pixelformat = V4L2_PIX_FMT_SBGGR8; |
| 920 | } else { |
| 921 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Nori, Sekhar | 8946ab3 | 2017-05-26 07:55:27 -0300 | [diff] [blame] | 922 | strcpy(fmt->description, "YCbCr4:2:2 Semi-Planar"); |
| 923 | fmt->pixelformat = V4L2_PIX_FMT_NV16; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 924 | } |
| 925 | return 0; |
| 926 | } |
| 927 | |
| 928 | /** |
| 929 | * vpif_try_fmt_vid_cap() - TRY_FMT handler |
| 930 | * @file: file ptr |
| 931 | * @priv: file handle |
| 932 | * @fmt: ptr to v4l2 format structure |
| 933 | */ |
| 934 | static int vpif_try_fmt_vid_cap(struct file *file, void *priv, |
| 935 | struct v4l2_format *fmt) |
| 936 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 937 | struct video_device *vdev = video_devdata(file); |
| 938 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 939 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 940 | struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]); |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 941 | |
| 942 | vpif_update_std_info(ch); |
| 943 | |
| 944 | pixfmt->field = common->fmt.fmt.pix.field; |
| 945 | pixfmt->colorspace = common->fmt.fmt.pix.colorspace; |
| 946 | pixfmt->bytesperline = common->fmt.fmt.pix.width; |
| 947 | pixfmt->width = common->fmt.fmt.pix.width; |
| 948 | pixfmt->height = common->fmt.fmt.pix.height; |
| 949 | pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height * 2; |
| 950 | pixfmt->priv = 0; |
| 951 | |
| 952 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | |
| 956 | /** |
| 957 | * vpif_g_fmt_vid_cap() - Set INPUT handler |
| 958 | * @file: file ptr |
| 959 | * @priv: file handle |
| 960 | * @fmt: ptr to v4l2 format structure |
| 961 | */ |
| 962 | static int vpif_g_fmt_vid_cap(struct file *file, void *priv, |
| 963 | struct v4l2_format *fmt) |
| 964 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 965 | struct video_device *vdev = video_devdata(file); |
| 966 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 967 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
| 968 | |
| 969 | /* Check the validity of the buffer type */ |
| 970 | if (common->fmt.type != fmt->type) |
| 971 | return -EINVAL; |
| 972 | |
| 973 | /* Fill in the information about format */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 974 | *fmt = common->fmt; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * vpif_s_fmt_vid_cap() - Set FMT handler |
| 980 | * @file: file ptr |
| 981 | * @priv: file handle |
| 982 | * @fmt: ptr to v4l2 format structure |
| 983 | */ |
| 984 | static int vpif_s_fmt_vid_cap(struct file *file, void *priv, |
| 985 | struct v4l2_format *fmt) |
| 986 | { |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 987 | struct video_device *vdev = video_devdata(file); |
| 988 | struct channel_obj *ch = video_get_drvdata(vdev); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 989 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 990 | int ret; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 991 | |
Mats Randgaard | 2c0ddd1 | 2010-12-16 12:17:45 -0300 | [diff] [blame] | 992 | vpif_dbg(2, debug, "%s\n", __func__); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 993 | |
Lad, Prabhakar | c66238f | 2014-05-16 10:33:45 -0300 | [diff] [blame] | 994 | if (vb2_is_busy(&common->buffer_queue)) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 995 | return -EBUSY; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 996 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 997 | ret = vpif_try_fmt_vid_cap(file, priv, fmt); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 998 | if (ret) |
| 999 | return ret; |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 1000 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1001 | /* store the format in the channel object */ |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1002 | common->fmt = *fmt; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * vpif_querycap() - QUERYCAP handler |
| 1008 | * @file: file ptr |
| 1009 | * @priv: file handle |
| 1010 | * @cap: ptr to v4l2_capability structure |
| 1011 | */ |
| 1012 | static int vpif_querycap(struct file *file, void *priv, |
| 1013 | struct v4l2_capability *cap) |
| 1014 | { |
| 1015 | struct vpif_capture_config *config = vpif_dev->platform_data; |
| 1016 | |
Lad, Prabhakar | 626d533f | 2012-09-25 11:21:55 -0300 | [diff] [blame] | 1017 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; |
| 1018 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1019 | strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver)); |
Lad, Prabhakar | 626d533f | 2012-09-25 11:21:55 -0300 | [diff] [blame] | 1020 | snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", |
| 1021 | dev_name(vpif_dev)); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1022 | strlcpy(cap->card, config->card_name, sizeof(cap->card)); |
| 1023 | |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1028 | * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1029 | * @file: file ptr |
| 1030 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1031 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1032 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1033 | static int |
| 1034 | vpif_enum_dv_timings(struct file *file, void *priv, |
| 1035 | struct v4l2_enum_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1036 | { |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1037 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1038 | struct video_device *vdev = video_devdata(file); |
| 1039 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1040 | struct vpif_capture_chan_config *chan_cfg; |
| 1041 | struct v4l2_input input; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1042 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1043 | |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 1044 | if (!config->chan_config[ch->channel_id].inputs) |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1045 | return -ENODATA; |
| 1046 | |
| 1047 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1048 | input = chan_cfg->inputs[ch->input_idx].input; |
| 1049 | if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS) |
| 1050 | return -ENODATA; |
| 1051 | |
Laurent Pinchart | 10d2146 | 2014-01-31 09:04:19 -0300 | [diff] [blame] | 1052 | timings->pad = 0; |
| 1053 | |
| 1054 | ret = v4l2_subdev_call(ch->sd, pad, enum_dv_timings, timings); |
Wei Yongjun | e070f1b | 2012-10-30 09:45:00 -0300 | [diff] [blame] | 1055 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1056 | return -EINVAL; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1057 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1058 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | /** |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1062 | * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1063 | * @file: file ptr |
| 1064 | * @priv: file handle |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1065 | * @timings: input timings |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1066 | */ |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1067 | static int |
| 1068 | vpif_query_dv_timings(struct file *file, void *priv, |
| 1069 | struct v4l2_dv_timings *timings) |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1070 | { |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1071 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1072 | struct video_device *vdev = video_devdata(file); |
| 1073 | struct channel_obj *ch = video_get_drvdata(vdev); |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1074 | struct vpif_capture_chan_config *chan_cfg; |
| 1075 | struct v4l2_input input; |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1076 | int ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1077 | |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 1078 | if (!config->chan_config[ch->channel_id].inputs) |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1079 | return -ENODATA; |
| 1080 | |
| 1081 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1082 | input = chan_cfg->inputs[ch->input_idx].input; |
| 1083 | if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS) |
| 1084 | return -ENODATA; |
| 1085 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1086 | ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings); |
Wei Yongjun | e070f1b | 2012-10-30 09:45:00 -0300 | [diff] [blame] | 1087 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1088 | return -ENODATA; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1089 | |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1090 | return ret; |
Mats Randgaard | 40c8bce | 2010-12-16 12:17:43 -0300 | [diff] [blame] | 1091 | } |
| 1092 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1093 | /** |
| 1094 | * vpif_s_dv_timings() - S_DV_TIMINGS handler |
| 1095 | * @file: file ptr |
| 1096 | * @priv: file handle |
| 1097 | * @timings: digital video timings |
| 1098 | */ |
| 1099 | static int vpif_s_dv_timings(struct file *file, void *priv, |
| 1100 | struct v4l2_dv_timings *timings) |
| 1101 | { |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1102 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1103 | struct video_device *vdev = video_devdata(file); |
| 1104 | struct channel_obj *ch = video_get_drvdata(vdev); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1105 | struct vpif_params *vpifparams = &ch->vpifparams; |
| 1106 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1107 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1108 | struct video_obj *vid_ch = &ch->video; |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1109 | struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1110 | struct vpif_capture_chan_config *chan_cfg; |
| 1111 | struct v4l2_input input; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1112 | int ret; |
| 1113 | |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 1114 | if (!config->chan_config[ch->channel_id].inputs) |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1115 | return -ENODATA; |
| 1116 | |
| 1117 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1118 | input = chan_cfg->inputs[ch->input_idx].input; |
| 1119 | if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS) |
| 1120 | return -ENODATA; |
| 1121 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1122 | if (timings->type != V4L2_DV_BT_656_1120) { |
| 1123 | vpif_dbg(2, debug, "Timing type not defined\n"); |
| 1124 | return -EINVAL; |
| 1125 | } |
| 1126 | |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1127 | if (vb2_is_busy(&common->buffer_queue)) |
| 1128 | return -EBUSY; |
| 1129 | |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1130 | /* Configure subdevice timings, if any */ |
Hans Verkuil | 178cce1 | 2012-09-20 09:06:30 -0300 | [diff] [blame] | 1131 | ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings); |
| 1132 | if (ret == -ENOIOCTLCMD || ret == -ENODEV) |
| 1133 | ret = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1134 | if (ret < 0) { |
| 1135 | vpif_dbg(2, debug, "Error setting custom DV timings\n"); |
| 1136 | return ret; |
| 1137 | } |
| 1138 | |
| 1139 | if (!(timings->bt.width && timings->bt.height && |
| 1140 | (timings->bt.hbackporch || |
| 1141 | timings->bt.hfrontporch || |
| 1142 | timings->bt.hsync) && |
| 1143 | timings->bt.vfrontporch && |
| 1144 | (timings->bt.vbackporch || |
| 1145 | timings->bt.vsync))) { |
Mauro Carvalho Chehab | ded026e | 2016-10-18 17:44:08 -0200 | [diff] [blame] | 1146 | 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] | 1147 | return -EINVAL; |
| 1148 | } |
| 1149 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1150 | vid_ch->dv_timings = *timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1151 | |
| 1152 | /* Configure video port timings */ |
| 1153 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame] | 1154 | std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1155 | std_info->sav2eav = bt->width; |
| 1156 | |
| 1157 | std_info->l1 = 1; |
| 1158 | std_info->l3 = bt->vsync + bt->vbackporch + 1; |
| 1159 | |
Hans Verkuil | e365526 | 2013-07-29 08:41:00 -0300 | [diff] [blame] | 1160 | std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1161 | if (bt->interlaced) { |
| 1162 | if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1163 | std_info->l5 = std_info->vsize/2 - |
| 1164 | (bt->vfrontporch - 1); |
| 1165 | std_info->l7 = std_info->vsize/2 + 1; |
| 1166 | std_info->l9 = std_info->l7 + bt->il_vsync + |
| 1167 | bt->il_vbackporch + 1; |
| 1168 | std_info->l11 = std_info->vsize - |
| 1169 | (bt->il_vfrontporch - 1); |
| 1170 | } else { |
Mauro Carvalho Chehab | ded026e | 2016-10-18 17:44:08 -0200 | [diff] [blame] | 1171 | 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] | 1172 | return -EINVAL; |
| 1173 | } |
| 1174 | } else { |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1175 | std_info->l5 = std_info->vsize - (bt->vfrontporch - 1); |
| 1176 | } |
| 1177 | strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME); |
| 1178 | std_info->width = bt->width; |
| 1179 | std_info->height = bt->height; |
| 1180 | std_info->frm_fmt = bt->interlaced ? 0 : 1; |
| 1181 | std_info->ycmux_mode = 0; |
| 1182 | std_info->capture_format = 0; |
| 1183 | std_info->vbi_supported = 0; |
| 1184 | std_info->hd_sd = 1; |
| 1185 | std_info->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1186 | |
| 1187 | vid_ch->stdid = 0; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | /** |
| 1192 | * vpif_g_dv_timings() - G_DV_TIMINGS handler |
| 1193 | * @file: file ptr |
| 1194 | * @priv: file handle |
| 1195 | * @timings: digital video timings |
| 1196 | */ |
| 1197 | static int vpif_g_dv_timings(struct file *file, void *priv, |
| 1198 | struct v4l2_dv_timings *timings) |
| 1199 | { |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1200 | struct vpif_capture_config *config = vpif_dev->platform_data; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1201 | struct video_device *vdev = video_devdata(file); |
| 1202 | struct channel_obj *ch = video_get_drvdata(vdev); |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1203 | struct video_obj *vid_ch = &ch->video; |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1204 | struct vpif_capture_chan_config *chan_cfg; |
| 1205 | struct v4l2_input input; |
| 1206 | |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 1207 | if (!config->chan_config[ch->channel_id].inputs) |
Lad, Prabhakar | 1e8852af | 2014-05-16 10:33:51 -0300 | [diff] [blame] | 1208 | return -ENODATA; |
| 1209 | |
| 1210 | chan_cfg = &config->chan_config[ch->channel_id]; |
| 1211 | input = chan_cfg->inputs[ch->input_idx].input; |
| 1212 | if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS) |
| 1213 | return -ENODATA; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1214 | |
Hans Verkuil | 0598c17 | 2012-09-18 07:18:47 -0300 | [diff] [blame] | 1215 | *timings = vid_ch->dv_timings; |
Mats Randgaard | c027e16 | 2010-12-16 12:17:44 -0300 | [diff] [blame] | 1216 | |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1220 | /* |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1221 | * vpif_log_status() - Status information |
| 1222 | * @file: file ptr |
| 1223 | * @priv: file handle |
| 1224 | * |
| 1225 | * Returns zero. |
| 1226 | */ |
| 1227 | static int vpif_log_status(struct file *filep, void *priv) |
| 1228 | { |
| 1229 | /* status for sub devices */ |
| 1230 | v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status); |
| 1231 | |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1235 | /* vpif capture ioctl operations */ |
| 1236 | static const struct v4l2_ioctl_ops vpif_ioctl_ops = { |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1237 | .vidioc_querycap = vpif_querycap, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1238 | .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap, |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1239 | .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1240 | .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap, |
| 1241 | .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap, |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1242 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1243 | .vidioc_enum_input = vpif_enum_input, |
| 1244 | .vidioc_s_input = vpif_s_input, |
| 1245 | .vidioc_g_input = vpif_g_input, |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 1246 | |
| 1247 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 1248 | .vidioc_create_bufs = vb2_ioctl_create_bufs, |
| 1249 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 1250 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 1251 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
| 1252 | .vidioc_expbuf = vb2_ioctl_expbuf, |
| 1253 | .vidioc_streamon = vb2_ioctl_streamon, |
| 1254 | .vidioc_streamoff = vb2_ioctl_streamoff, |
| 1255 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1256 | .vidioc_querystd = vpif_querystd, |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1257 | .vidioc_s_std = vpif_s_std, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1258 | .vidioc_g_std = vpif_g_std, |
Lad, Prabhakar | d9a3b13 | 2014-05-16 10:33:42 -0300 | [diff] [blame] | 1259 | |
Lad, Prabhakar | 7b4657f | 2014-05-16 10:33:49 -0300 | [diff] [blame] | 1260 | .vidioc_enum_dv_timings = vpif_enum_dv_timings, |
| 1261 | .vidioc_query_dv_timings = vpif_query_dv_timings, |
| 1262 | .vidioc_s_dv_timings = vpif_s_dv_timings, |
| 1263 | .vidioc_g_dv_timings = vpif_g_dv_timings, |
| 1264 | |
Mats Randgaard | 7036d6a | 2010-12-16 12:17:41 -0300 | [diff] [blame] | 1265 | .vidioc_log_status = vpif_log_status, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1266 | }; |
| 1267 | |
| 1268 | /* vpif file operations */ |
| 1269 | static struct v4l2_file_operations vpif_fops = { |
| 1270 | .owner = THIS_MODULE, |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1271 | .open = v4l2_fh_open, |
| 1272 | .release = vb2_fop_release, |
Hans Verkuil | 46656af | 2011-01-04 06:51:35 -0300 | [diff] [blame] | 1273 | .unlocked_ioctl = video_ioctl2, |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1274 | .mmap = vb2_fop_mmap, |
| 1275 | .poll = vb2_fop_poll |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1276 | }; |
| 1277 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1278 | /** |
| 1279 | * initialize_vpif() - Initialize vpif data structures |
| 1280 | * |
| 1281 | * Allocate memory for data structures and initialize them |
| 1282 | */ |
| 1283 | static int initialize_vpif(void) |
| 1284 | { |
Lad, Prabhakar | 4015bef | 2014-05-16 10:33:47 -0300 | [diff] [blame] | 1285 | int err, i, j; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1286 | int free_channel_objects_index; |
| 1287 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1288 | /* Allocate memory for six channel objects */ |
| 1289 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1290 | vpif_obj.dev[i] = |
| 1291 | kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL); |
| 1292 | /* If memory allocation fails, return error */ |
| 1293 | if (!vpif_obj.dev[i]) { |
| 1294 | free_channel_objects_index = i; |
| 1295 | err = -ENOMEM; |
| 1296 | goto vpif_init_free_channel_objects; |
| 1297 | } |
| 1298 | } |
| 1299 | return 0; |
| 1300 | |
| 1301 | vpif_init_free_channel_objects: |
| 1302 | for (j = 0; j < free_channel_objects_index; j++) |
| 1303 | kfree(vpif_obj.dev[j]); |
| 1304 | return err; |
| 1305 | } |
| 1306 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1307 | static int vpif_async_bound(struct v4l2_async_notifier *notifier, |
| 1308 | struct v4l2_subdev *subdev, |
| 1309 | struct v4l2_async_subdev *asd) |
| 1310 | { |
| 1311 | int i; |
| 1312 | |
Kevin Hilman | 4a5f8ae | 2017-06-06 20:37:39 -0300 | [diff] [blame^] | 1313 | for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { |
| 1314 | struct v4l2_async_subdev *_asd = vpif_obj.config->asd[i]; |
| 1315 | const struct device_node *node = _asd->match.of.node; |
| 1316 | |
| 1317 | if (node == subdev->of_node) { |
| 1318 | vpif_obj.sd[i] = subdev; |
| 1319 | vpif_obj.config->chan_config->inputs[i].subdev_name = |
| 1320 | (char *)subdev->of_node->full_name; |
| 1321 | vpif_dbg(2, debug, |
| 1322 | "%s: setting input %d subdev_name = %s\n", |
| 1323 | __func__, i, subdev->of_node->full_name); |
| 1324 | return 0; |
| 1325 | } |
| 1326 | } |
| 1327 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1328 | for (i = 0; i < vpif_obj.config->subdev_count; i++) |
| 1329 | if (!strcmp(vpif_obj.config->subdev_info[i].name, |
| 1330 | subdev->name)) { |
| 1331 | vpif_obj.sd[i] = subdev; |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
| 1335 | return -EINVAL; |
| 1336 | } |
| 1337 | |
| 1338 | static int vpif_probe_complete(void) |
| 1339 | { |
| 1340 | struct common_obj *common; |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1341 | struct video_device *vdev; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1342 | struct channel_obj *ch; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1343 | struct vb2_queue *q; |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 1344 | int j, err, k; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1345 | |
| 1346 | for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) { |
| 1347 | ch = vpif_obj.dev[j]; |
| 1348 | ch->channel_id = j; |
| 1349 | common = &(ch->common[VPIF_VIDEO_INDEX]); |
| 1350 | spin_lock_init(&common->irqlock); |
| 1351 | mutex_init(&common->lock); |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1352 | |
| 1353 | /* select input 0 */ |
| 1354 | err = vpif_set_input(vpif_obj.config, ch, 0); |
| 1355 | if (err) |
| 1356 | goto probe_out; |
| 1357 | |
Lad, Prabhakar | a4965c5 | 2014-05-16 10:33:54 -0300 | [diff] [blame] | 1358 | /* set initial format */ |
| 1359 | ch->video.stdid = V4L2_STD_525_60; |
| 1360 | memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings)); |
| 1361 | vpif_update_std_info(ch); |
| 1362 | |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1363 | /* Initialize vb2 queue */ |
| 1364 | q = &common->buffer_queue; |
| 1365 | q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1366 | q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
| 1367 | q->drv_priv = ch; |
| 1368 | q->ops = &video_qops; |
| 1369 | q->mem_ops = &vb2_dma_contig_memops; |
| 1370 | q->buf_struct_size = sizeof(struct vpif_cap_buffer); |
| 1371 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
| 1372 | q->min_buffers_needed = 1; |
Lad, Prabhakar | 999ba69 | 2014-05-16 10:33:33 -0300 | [diff] [blame] | 1373 | q->lock = &common->lock; |
Hans Verkuil | 53ddcc6 | 2016-02-15 13:09:10 -0200 | [diff] [blame] | 1374 | q->dev = vpif_dev; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1375 | |
| 1376 | err = vb2_queue_init(q); |
| 1377 | if (err) { |
| 1378 | vpif_err("vpif_capture: vb2_queue_init() failed\n"); |
| 1379 | goto probe_out; |
| 1380 | } |
| 1381 | |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1382 | INIT_LIST_HEAD(&common->dma_queue); |
| 1383 | |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1384 | /* Initialize the video_device structure */ |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 1385 | vdev = &ch->video_dev; |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1386 | strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name)); |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 1387 | vdev->release = video_device_release_empty; |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1388 | vdev->fops = &vpif_fops; |
| 1389 | vdev->ioctl_ops = &vpif_ioctl_ops; |
| 1390 | vdev->v4l2_dev = &vpif_obj.v4l2_dev; |
| 1391 | vdev->vfl_dir = VFL_DIR_RX; |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1392 | vdev->queue = q; |
Lad, Prabhakar | 7ff5119 | 2014-05-16 10:33:41 -0300 | [diff] [blame] | 1393 | vdev->lock = &common->lock; |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 1394 | video_set_drvdata(&ch->video_dev, ch); |
Lad, Prabhakar | d26d26b | 2014-05-16 10:33:40 -0300 | [diff] [blame] | 1395 | err = video_register_device(vdev, |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1396 | VFL_TYPE_GRABBER, (j ? 1 : 0)); |
| 1397 | if (err) |
| 1398 | goto probe_out; |
| 1399 | } |
| 1400 | |
| 1401 | v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n"); |
| 1402 | return 0; |
| 1403 | |
| 1404 | probe_out: |
| 1405 | for (k = 0; k < j; k++) { |
| 1406 | /* Get the pointer to the channel object */ |
| 1407 | ch = vpif_obj.dev[k]; |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1408 | common = &ch->common[k]; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1409 | /* Unregister video device */ |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 1410 | video_unregister_device(&ch->video_dev); |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1411 | } |
| 1412 | kfree(vpif_obj.sd); |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1413 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
| 1414 | |
| 1415 | return err; |
| 1416 | } |
| 1417 | |
| 1418 | static int vpif_async_complete(struct v4l2_async_notifier *notifier) |
| 1419 | { |
| 1420 | return vpif_probe_complete(); |
| 1421 | } |
| 1422 | |
Kevin Hilman | 4a5f8ae | 2017-06-06 20:37:39 -0300 | [diff] [blame^] | 1423 | static struct vpif_capture_config * |
| 1424 | vpif_capture_get_pdata(struct platform_device *pdev) |
| 1425 | { |
| 1426 | struct device_node *endpoint = NULL; |
| 1427 | struct v4l2_of_endpoint bus_cfg; |
| 1428 | struct vpif_capture_config *pdata; |
| 1429 | struct vpif_subdev_info *sdinfo; |
| 1430 | struct vpif_capture_chan_config *chan; |
| 1431 | unsigned int i; |
| 1432 | |
| 1433 | /* |
| 1434 | * DT boot: OF node from parent device contains |
| 1435 | * video ports & endpoints data. |
| 1436 | */ |
| 1437 | if (pdev->dev.parent && pdev->dev.parent->of_node) |
| 1438 | pdev->dev.of_node = pdev->dev.parent->of_node; |
| 1439 | if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) |
| 1440 | return pdev->dev.platform_data; |
| 1441 | |
| 1442 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1443 | if (!pdata) |
| 1444 | return NULL; |
| 1445 | pdata->subdev_info = |
| 1446 | devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * |
| 1447 | VPIF_CAPTURE_NUM_CHANNELS, GFP_KERNEL); |
| 1448 | |
| 1449 | if (!pdata->subdev_info) |
| 1450 | return NULL; |
| 1451 | |
| 1452 | for (i = 0; i < VPIF_CAPTURE_NUM_CHANNELS; i++) { |
| 1453 | struct device_node *rem; |
| 1454 | unsigned int flags; |
| 1455 | int err; |
| 1456 | |
| 1457 | endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, |
| 1458 | endpoint); |
| 1459 | if (!endpoint) |
| 1460 | break; |
| 1461 | |
| 1462 | sdinfo = &pdata->subdev_info[i]; |
| 1463 | chan = &pdata->chan_config[i]; |
| 1464 | chan->inputs = devm_kzalloc(&pdev->dev, |
| 1465 | sizeof(*chan->inputs) * |
| 1466 | VPIF_CAPTURE_NUM_CHANNELS, |
| 1467 | GFP_KERNEL); |
| 1468 | |
| 1469 | chan->input_count++; |
| 1470 | chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; |
| 1471 | chan->inputs[i].input.std = V4L2_STD_ALL; |
| 1472 | chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; |
| 1473 | |
| 1474 | err = v4l2_of_parse_endpoint(endpoint, &bus_cfg); |
| 1475 | if (err) { |
| 1476 | dev_err(&pdev->dev, "Could not parse the endpoint\n"); |
| 1477 | goto done; |
| 1478 | } |
| 1479 | dev_dbg(&pdev->dev, "Endpoint %s, bus_width = %d\n", |
| 1480 | endpoint->full_name, bus_cfg.bus.parallel.bus_width); |
| 1481 | flags = bus_cfg.bus.parallel.flags; |
| 1482 | |
| 1483 | if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) |
| 1484 | chan->vpif_if.hd_pol = 1; |
| 1485 | |
| 1486 | if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) |
| 1487 | chan->vpif_if.vd_pol = 1; |
| 1488 | |
| 1489 | rem = of_graph_get_remote_port_parent(endpoint); |
| 1490 | if (!rem) { |
| 1491 | dev_dbg(&pdev->dev, "Remote device at %s not found\n", |
| 1492 | endpoint->full_name); |
| 1493 | goto done; |
| 1494 | } |
| 1495 | |
| 1496 | dev_dbg(&pdev->dev, "Remote device %s, %s found\n", |
| 1497 | rem->name, rem->full_name); |
| 1498 | sdinfo->name = rem->full_name; |
| 1499 | |
| 1500 | pdata->asd[i] = devm_kzalloc(&pdev->dev, |
| 1501 | sizeof(struct v4l2_async_subdev), |
| 1502 | GFP_KERNEL); |
| 1503 | if (!pdata->asd[i]) { |
| 1504 | of_node_put(rem); |
| 1505 | pdata = NULL; |
| 1506 | goto done; |
| 1507 | } |
| 1508 | |
| 1509 | pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF; |
| 1510 | pdata->asd[i]->match.of.node = rem; |
| 1511 | of_node_put(rem); |
| 1512 | } |
| 1513 | |
| 1514 | done: |
| 1515 | pdata->asd_sizes[0] = i; |
| 1516 | pdata->subdev_count = i; |
| 1517 | pdata->card_name = "DA850/OMAP-L138 Video Capture"; |
| 1518 | |
| 1519 | return pdata; |
| 1520 | } |
| 1521 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1522 | /** |
| 1523 | * vpif_probe : This function probes the vpif capture driver |
| 1524 | * @pdev: platform device pointer |
| 1525 | * |
| 1526 | * This creates device entries by register itself to the V4L2 driver and |
| 1527 | * initializes fields of each channel objects |
| 1528 | */ |
| 1529 | static __init int vpif_probe(struct platform_device *pdev) |
| 1530 | { |
| 1531 | struct vpif_subdev_info *subdevdata; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1532 | struct i2c_adapter *i2c_adap; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1533 | struct resource *res; |
| 1534 | int subdev_count; |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 1535 | int res_idx = 0; |
| 1536 | int i, err; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1537 | |
Kevin Hilman | 4a5f8ae | 2017-06-06 20:37:39 -0300 | [diff] [blame^] | 1538 | pdev->dev.platform_data = vpif_capture_get_pdata(pdev); |
| 1539 | if (!pdev->dev.platform_data) { |
| 1540 | dev_warn(&pdev->dev, "Missing platform data. Giving up.\n"); |
| 1541 | return -EINVAL; |
| 1542 | } |
| 1543 | |
Kevin Hilman | bff782d | 2016-12-16 22:47:54 -0200 | [diff] [blame] | 1544 | if (!pdev->dev.platform_data) { |
| 1545 | dev_warn(&pdev->dev, "Missing platform data. Giving up.\n"); |
| 1546 | return -EINVAL; |
| 1547 | } |
| 1548 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1549 | vpif_dev = &pdev->dev; |
| 1550 | |
| 1551 | err = initialize_vpif(); |
| 1552 | if (err) { |
| 1553 | v4l2_err(vpif_dev->driver, "Error initializing vpif\n"); |
| 1554 | return err; |
| 1555 | } |
| 1556 | |
Hans Verkuil | d2f7a1a | 2011-12-13 05:44:42 -0300 | [diff] [blame] | 1557 | err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); |
| 1558 | if (err) { |
| 1559 | v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); |
| 1560 | return err; |
| 1561 | } |
| 1562 | |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 1563 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { |
Lad, Prabhakar | a76a0b3 | 2013-06-17 11:20:47 -0300 | [diff] [blame] | 1564 | err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr, |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1565 | IRQF_SHARED, VPIF_DRIVER_NAME, |
Lad, Prabhakar | a76a0b3 | 2013-06-17 11:20:47 -0300 | [diff] [blame] | 1566 | (void *)(&vpif_obj.dev[res_idx]-> |
| 1567 | channel_id)); |
| 1568 | if (err) { |
| 1569 | err = -EINVAL; |
| 1570 | goto vpif_unregister; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1571 | } |
Hans Verkuil | 5be452c | 2012-09-20 09:06:29 -0300 | [diff] [blame] | 1572 | res_idx++; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1573 | } |
| 1574 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1575 | vpif_obj.config = pdev->dev.platform_data; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1576 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1577 | subdev_count = vpif_obj.config->subdev_count; |
Markus Elfring | b442c46 | 2016-10-12 10:15:34 -0300 | [diff] [blame] | 1578 | vpif_obj.sd = kcalloc(subdev_count, sizeof(*vpif_obj.sd), GFP_KERNEL); |
Markus Elfring | 03161cd | 2016-10-12 10:20:34 -0300 | [diff] [blame] | 1579 | if (!vpif_obj.sd) { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1580 | err = -ENOMEM; |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 1581 | goto vpif_unregister; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1582 | } |
| 1583 | |
Kevin Hilman | 4a5f8ae | 2017-06-06 20:37:39 -0300 | [diff] [blame^] | 1584 | if (!vpif_obj.config->asd_sizes[0]) { |
Kevin Hilman | 2d40cb3 | 2016-12-07 16:30:22 -0200 | [diff] [blame] | 1585 | int i2c_id = vpif_obj.config->i2c_adapter_id; |
| 1586 | |
| 1587 | i2c_adap = i2c_get_adapter(i2c_id); |
| 1588 | WARN_ON(!i2c_adap); |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1589 | for (i = 0; i < subdev_count; i++) { |
| 1590 | subdevdata = &vpif_obj.config->subdev_info[i]; |
| 1591 | vpif_obj.sd[i] = |
| 1592 | v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, |
| 1593 | i2c_adap, |
| 1594 | &subdevdata-> |
| 1595 | board_info, |
| 1596 | NULL); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1597 | |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1598 | if (!vpif_obj.sd[i]) { |
| 1599 | vpif_err("Error registering v4l2 subdevice\n"); |
Wei Yongjun | 2fcd9dc | 2013-09-02 05:06:10 -0300 | [diff] [blame] | 1600 | err = -ENODEV; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1601 | goto probe_subdev_out; |
| 1602 | } |
| 1603 | v4l2_info(&vpif_obj.v4l2_dev, |
| 1604 | "registered sub device %s\n", |
| 1605 | subdevdata->name); |
| 1606 | } |
| 1607 | vpif_probe_complete(); |
| 1608 | } else { |
Sylwester Nawrocki | e8419d0 | 2013-07-19 12:31:10 -0300 | [diff] [blame] | 1609 | vpif_obj.notifier.subdevs = vpif_obj.config->asd; |
Lad, Prabhakar | 873229e | 2013-06-25 11:17:34 -0300 | [diff] [blame] | 1610 | vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0]; |
| 1611 | vpif_obj.notifier.bound = vpif_async_bound; |
| 1612 | vpif_obj.notifier.complete = vpif_async_complete; |
| 1613 | err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev, |
| 1614 | &vpif_obj.notifier); |
| 1615 | if (err) { |
| 1616 | vpif_err("Error registering async notifier\n"); |
| 1617 | err = -EINVAL; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1618 | goto probe_subdev_out; |
| 1619 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1620 | } |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1621 | |
| 1622 | return 0; |
| 1623 | |
Hans Verkuil | b65814e | 2012-09-20 09:06:26 -0300 | [diff] [blame] | 1624 | probe_subdev_out: |
| 1625 | /* free sub devices memory */ |
| 1626 | kfree(vpif_obj.sd); |
Lad, Prabhakar | b2de4f2 | 2013-06-17 11:20:46 -0300 | [diff] [blame] | 1627 | vpif_unregister: |
Hans Verkuil | d2f7a1a | 2011-12-13 05:44:42 -0300 | [diff] [blame] | 1628 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
Lad, Prabhakar | b2de4f2 | 2013-06-17 11:20:46 -0300 | [diff] [blame] | 1629 | |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1630 | return err; |
| 1631 | } |
| 1632 | |
| 1633 | /** |
| 1634 | * vpif_remove() - driver remove handler |
| 1635 | * @device: ptr to platform device structure |
| 1636 | * |
| 1637 | * The vidoe device is unregistered |
| 1638 | */ |
| 1639 | static int vpif_remove(struct platform_device *device) |
| 1640 | { |
Lad, Prabhakar | fa09acc | 2014-05-16 10:33:31 -0300 | [diff] [blame] | 1641 | struct common_obj *common; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1642 | struct channel_obj *ch; |
Lad, Prabhakar | b2de4f2 | 2013-06-17 11:20:46 -0300 | [diff] [blame] | 1643 | int i; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1644 | |
| 1645 | v4l2_device_unregister(&vpif_obj.v4l2_dev); |
| 1646 | |
Lad, Prabhakar | 410ca60 | 2013-06-17 11:20:44 -0300 | [diff] [blame] | 1647 | kfree(vpif_obj.sd); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1648 | /* un-register device */ |
| 1649 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1650 | /* Get the pointer to the channel object */ |
| 1651 | ch = vpif_obj.dev[i]; |
Prabhakar Lad | e9b5872 | 2014-07-18 13:31:51 -0300 | [diff] [blame] | 1652 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1653 | /* Unregister video device */ |
Lad, Prabhakar | 8eef666 | 2015-03-08 18:57:23 -0300 | [diff] [blame] | 1654 | video_unregister_device(&ch->video_dev); |
Lad, Prabhakar | 410ca60 | 2013-06-17 11:20:44 -0300 | [diff] [blame] | 1655 | kfree(vpif_obj.dev[i]); |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1656 | } |
| 1657 | return 0; |
| 1658 | } |
| 1659 | |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1660 | #ifdef CONFIG_PM_SLEEP |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1661 | /** |
| 1662 | * vpif_suspend: vpif device suspend |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1663 | */ |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1664 | static int vpif_suspend(struct device *dev) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1665 | { |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1666 | |
| 1667 | struct common_obj *common; |
| 1668 | struct channel_obj *ch; |
| 1669 | int i; |
| 1670 | |
| 1671 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1672 | /* Get the pointer to the channel object */ |
| 1673 | ch = vpif_obj.dev[i]; |
| 1674 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1675 | |
Prabhakar Lad | c54d4a0 | 2014-09-06 12:26:51 -0300 | [diff] [blame] | 1676 | if (!vb2_start_streaming_called(&common->buffer_queue)) |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1677 | continue; |
| 1678 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1679 | mutex_lock(&common->lock); |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1680 | /* Disable channel */ |
| 1681 | if (ch->channel_id == VPIF_CHANNEL0_VIDEO) { |
| 1682 | enable_channel0(0); |
| 1683 | channel0_intr_enable(0); |
| 1684 | } |
| 1685 | if (ch->channel_id == VPIF_CHANNEL1_VIDEO || |
| 1686 | ycmux_mode == 2) { |
| 1687 | enable_channel1(0); |
| 1688 | channel1_intr_enable(0); |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1689 | } |
| 1690 | mutex_unlock(&common->lock); |
| 1691 | } |
| 1692 | |
| 1693 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1694 | } |
| 1695 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1696 | /* |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1697 | * vpif_resume: vpif device suspend |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1698 | */ |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1699 | static int vpif_resume(struct device *dev) |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1700 | { |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1701 | struct common_obj *common; |
| 1702 | struct channel_obj *ch; |
| 1703 | int i; |
| 1704 | |
| 1705 | for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { |
| 1706 | /* Get the pointer to the channel object */ |
| 1707 | ch = vpif_obj.dev[i]; |
| 1708 | common = &ch->common[VPIF_VIDEO_INDEX]; |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1709 | |
Prabhakar Lad | c54d4a0 | 2014-09-06 12:26:51 -0300 | [diff] [blame] | 1710 | if (!vb2_start_streaming_called(&common->buffer_queue)) |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1711 | continue; |
| 1712 | |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1713 | mutex_lock(&common->lock); |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1714 | /* Enable channel */ |
| 1715 | if (ch->channel_id == VPIF_CHANNEL0_VIDEO) { |
| 1716 | enable_channel0(1); |
| 1717 | channel0_intr_enable(1); |
| 1718 | } |
| 1719 | if (ch->channel_id == VPIF_CHANNEL1_VIDEO || |
| 1720 | ycmux_mode == 2) { |
| 1721 | enable_channel1(1); |
| 1722 | channel1_intr_enable(1); |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1723 | } |
| 1724 | mutex_unlock(&common->lock); |
| 1725 | } |
| 1726 | |
| 1727 | return 0; |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1728 | } |
Manjunath Hadli | 3d5946d | 2012-04-13 04:50:55 -0300 | [diff] [blame] | 1729 | #endif |
| 1730 | |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1731 | static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume); |
| 1732 | |
Mats Randgaard | ffa1b39 | 2010-08-30 10:30:36 -0300 | [diff] [blame] | 1733 | static __refdata struct platform_driver vpif_driver = { |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1734 | .driver = { |
Lad, Prabhakar | e75ea0c | 2014-05-16 10:33:46 -0300 | [diff] [blame] | 1735 | .name = VPIF_DRIVER_NAME, |
Lad, Prabhakar | b704771 | 2014-05-16 10:33:50 -0300 | [diff] [blame] | 1736 | .pm = &vpif_pm_ops, |
Muralidharan Karicheri | 6ffefff | 2009-09-16 14:31:10 -0300 | [diff] [blame] | 1737 | }, |
| 1738 | .probe = vpif_probe, |
| 1739 | .remove = vpif_remove, |
| 1740 | }; |
| 1741 | |
Lad, Prabhakar | fe424b2 | 2013-06-17 11:20:45 -0300 | [diff] [blame] | 1742 | module_platform_driver(vpif_driver); |