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