Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Coda multi-standard codec IP |
| 3 | * |
| 4 | * Copyright (C) 2012 Vista Silicon S.L. |
| 5 | * Javier Martin, <javier.martin@vista-silicon.com> |
| 6 | * Xavier Duret |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/clk.h> |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 15 | #include <linux/debugfs.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/firmware.h> |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 18 | #include <linux/genalloc.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/irq.h> |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 22 | #include <linux/kfifo.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/of_device.h> |
| 25 | #include <linux/platform_device.h> |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 27 | #include <linux/slab.h> |
| 28 | #include <linux/videodev2.h> |
| 29 | #include <linux/of.h> |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 30 | #include <linux/platform_data/coda.h> |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 31 | #include <linux/reset.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 32 | |
| 33 | #include <media/v4l2-ctrls.h> |
| 34 | #include <media/v4l2-device.h> |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 35 | #include <media/v4l2-event.h> |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 36 | #include <media/v4l2-ioctl.h> |
| 37 | #include <media/v4l2-mem2mem.h> |
| 38 | #include <media/videobuf2-core.h> |
| 39 | #include <media/videobuf2-dma-contig.h> |
| 40 | |
| 41 | #include "coda.h" |
| 42 | |
| 43 | #define CODA_NAME "coda" |
| 44 | |
Philipp Zabel | 0cddc7e | 2013-09-30 10:34:44 -0300 | [diff] [blame] | 45 | #define CODADX6_MAX_INSTANCES 4 |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 46 | |
| 47 | #define CODA_FMO_BUF_SIZE 32 |
| 48 | #define CODADX6_WORK_BUF_SIZE (288 * 1024 + CODA_FMO_BUF_SIZE * 8 * 1024) |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 49 | #define CODA7_WORK_BUF_SIZE (128 * 1024) |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 50 | #define CODA9_WORK_BUF_SIZE (80 * 1024) |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 51 | #define CODA7_TEMP_BUF_SIZE (304 * 1024) |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 52 | #define CODA9_TEMP_BUF_SIZE (204 * 1024) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 53 | #define CODA_PARA_BUF_SIZE (10 * 1024) |
| 54 | #define CODA_ISRAM_SIZE (2048 * 2) |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 55 | #define CODADX6_IRAM_SIZE 0xb000 |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 56 | #define CODA7_IRAM_SIZE 0x14000 |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 57 | #define CODA9_IRAM_SIZE 0x21000 |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 58 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 59 | #define CODA7_PS_BUF_SIZE 0x28000 |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 60 | #define CODA9_PS_SAVE_SIZE (512 * 1024) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 61 | |
| 62 | #define CODA_MAX_FRAMEBUFFERS 8 |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 63 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 64 | #define CODA_MAX_FRAME_SIZE 0x100000 |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 65 | #define FMO_SLICE_SAVE_BUF_SIZE (32) |
| 66 | #define CODA_DEFAULT_GAMMA 4096 |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 67 | #define CODA9_DEFAULT_GAMMA 24576 /* 0.75 * 32768 */ |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 68 | |
| 69 | #define MIN_W 176 |
| 70 | #define MIN_H 144 |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 71 | |
| 72 | #define S_ALIGN 1 /* multiple of 2 */ |
| 73 | #define W_ALIGN 1 /* multiple of 2 */ |
| 74 | #define H_ALIGN 1 /* multiple of 2 */ |
| 75 | |
| 76 | #define fh_to_ctx(__fh) container_of(__fh, struct coda_ctx, fh) |
| 77 | |
| 78 | static int coda_debug; |
Philipp Zabel | c4eb1bfc | 2013-05-21 04:24:16 -0300 | [diff] [blame] | 79 | module_param(coda_debug, int, 0644); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 80 | MODULE_PARM_DESC(coda_debug, "Debug level (0-1)"); |
| 81 | |
| 82 | enum { |
| 83 | V4L2_M2M_SRC = 0, |
| 84 | V4L2_M2M_DST = 1, |
| 85 | }; |
| 86 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 87 | enum coda_inst_type { |
| 88 | CODA_INST_ENCODER, |
| 89 | CODA_INST_DECODER, |
| 90 | }; |
| 91 | |
| 92 | enum coda_product { |
| 93 | CODA_DX6 = 0xf001, |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 94 | CODA_7541 = 0xf012, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 95 | CODA_960 = 0xf020, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | struct coda_fmt { |
| 99 | char *name; |
| 100 | u32 fourcc; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | struct coda_codec { |
| 104 | u32 mode; |
| 105 | u32 src_fourcc; |
| 106 | u32 dst_fourcc; |
| 107 | u32 max_w; |
| 108 | u32 max_h; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | struct coda_devtype { |
| 112 | char *firmware; |
| 113 | enum coda_product product; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 114 | struct coda_codec *codecs; |
| 115 | unsigned int num_codecs; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 116 | size_t workbuf_size; |
| 117 | }; |
| 118 | |
| 119 | /* Per-queue, driver-specific private data */ |
| 120 | struct coda_q_data { |
| 121 | unsigned int width; |
| 122 | unsigned int height; |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 123 | unsigned int bytesperline; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 124 | unsigned int sizeimage; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 125 | unsigned int fourcc; |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 126 | struct v4l2_rect rect; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | struct coda_aux_buf { |
| 130 | void *vaddr; |
| 131 | dma_addr_t paddr; |
| 132 | u32 size; |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 133 | struct debugfs_blob_wrapper blob; |
| 134 | struct dentry *dentry; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | struct coda_dev { |
| 138 | struct v4l2_device v4l2_dev; |
| 139 | struct video_device vfd; |
| 140 | struct platform_device *plat_dev; |
Emil Goode | c06d875 | 2012-08-14 17:44:42 -0300 | [diff] [blame] | 141 | const struct coda_devtype *devtype; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 142 | |
| 143 | void __iomem *regs_base; |
| 144 | struct clk *clk_per; |
| 145 | struct clk *clk_ahb; |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 146 | struct reset_control *rstc; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 147 | |
| 148 | struct coda_aux_buf codebuf; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 149 | struct coda_aux_buf tempbuf; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 150 | struct coda_aux_buf workbuf; |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 151 | struct gen_pool *iram_pool; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 152 | struct coda_aux_buf iram; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 153 | |
| 154 | spinlock_t irqlock; |
| 155 | struct mutex dev_mutex; |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 156 | struct mutex coda_mutex; |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 157 | struct workqueue_struct *workqueue; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 158 | struct v4l2_m2m_dev *m2m_dev; |
| 159 | struct vb2_alloc_ctx *alloc_ctx; |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 160 | struct list_head instances; |
| 161 | unsigned long instance_mask; |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 162 | struct dentry *debugfs_root; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | struct coda_params { |
Philipp Zabel | 8f35c7b | 2012-07-09 04:25:52 -0300 | [diff] [blame] | 166 | u8 rot_mode; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 167 | u8 h264_intra_qp; |
| 168 | u8 h264_inter_qp; |
Philipp Zabel | 1a5567e | 2014-07-11 06:36:26 -0300 | [diff] [blame] | 169 | u8 h264_min_qp; |
| 170 | u8 h264_max_qp; |
Philipp Zabel | de23b1d | 2014-07-11 06:36:27 -0300 | [diff] [blame] | 171 | u8 h264_deblk_enabled; |
| 172 | u8 h264_deblk_alpha; |
| 173 | u8 h264_deblk_beta; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 174 | u8 mpeg4_intra_qp; |
| 175 | u8 mpeg4_inter_qp; |
| 176 | u8 gop_size; |
Philipp Zabel | f38f79d5 | 2014-07-11 06:36:28 -0300 | [diff] [blame] | 177 | int intra_refresh; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 178 | int codec_mode; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 179 | int codec_mode_aux; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 180 | enum v4l2_mpeg_video_multi_slice_mode slice_mode; |
| 181 | u32 framerate; |
| 182 | u16 bitrate; |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 183 | u32 slice_max_bits; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 184 | u32 slice_max_mb; |
| 185 | }; |
| 186 | |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 187 | struct coda_iram_info { |
| 188 | u32 axi_sram_use; |
| 189 | phys_addr_t buf_bit_use; |
| 190 | phys_addr_t buf_ip_ac_dc_use; |
| 191 | phys_addr_t buf_dbk_y_use; |
| 192 | phys_addr_t buf_dbk_c_use; |
| 193 | phys_addr_t buf_ovl_use; |
| 194 | phys_addr_t buf_btp_use; |
| 195 | phys_addr_t search_ram_paddr; |
| 196 | int search_ram_size; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 197 | int remaining; |
| 198 | phys_addr_t next_paddr; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 199 | }; |
| 200 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 201 | struct gdi_tiled_map { |
| 202 | int xy2ca_map[16]; |
| 203 | int xy2ba_map[16]; |
| 204 | int xy2ra_map[16]; |
| 205 | int rbc2axi_map[32]; |
| 206 | int xy2rbc_config; |
| 207 | int map_type; |
| 208 | #define GDI_LINEAR_FRAME_MAP 0 |
| 209 | }; |
| 210 | |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 211 | struct coda_timestamp { |
| 212 | struct list_head list; |
| 213 | u32 sequence; |
| 214 | struct v4l2_timecode timecode; |
| 215 | struct timeval timestamp; |
| 216 | }; |
| 217 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 218 | struct coda_ctx { |
| 219 | struct coda_dev *dev; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 220 | struct mutex buffer_mutex; |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 221 | struct list_head list; |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 222 | struct work_struct pic_run_work; |
| 223 | struct work_struct seq_end_work; |
| 224 | struct completion completion; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 225 | int aborting; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 226 | int initialized; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 227 | int streamon_out; |
| 228 | int streamon_cap; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 229 | u32 isequence; |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 230 | u32 qsequence; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 231 | u32 osequence; |
Philipp Zabel | cb2c028 | 2014-07-11 06:36:33 -0300 | [diff] [blame] | 232 | u32 sequence_offset; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 233 | struct coda_q_data q_data[2]; |
| 234 | enum coda_inst_type inst_type; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 235 | struct coda_codec *codec; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 236 | enum v4l2_colorspace colorspace; |
| 237 | struct coda_params params; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 238 | struct v4l2_ctrl_handler ctrls; |
| 239 | struct v4l2_fh fh; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 240 | int gopcounter; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 241 | int runcounter; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 242 | char vpu_header[3][64]; |
| 243 | int vpu_header_size[3]; |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 244 | struct kfifo bitstream_fifo; |
| 245 | struct mutex bitstream_mutex; |
| 246 | struct coda_aux_buf bitstream; |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 247 | bool hold; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 248 | struct coda_aux_buf parabuf; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 249 | struct coda_aux_buf psbuf; |
| 250 | struct coda_aux_buf slicebuf; |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 251 | struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS]; |
Philipp Zabel | 1a8b381 | 2014-07-11 06:36:12 -0300 | [diff] [blame] | 252 | u32 frame_types[CODA_MAX_FRAMEBUFFERS]; |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 253 | struct coda_timestamp frame_timestamps[CODA_MAX_FRAMEBUFFERS]; |
Philipp Zabel | 410e5e4 | 2014-07-11 06:36:32 -0300 | [diff] [blame] | 254 | u32 frame_errors[CODA_MAX_FRAMEBUFFERS]; |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 255 | struct list_head timestamp_list; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 256 | struct coda_aux_buf workbuf; |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 257 | int num_internal_frames; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 258 | int idx; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 259 | int reg_idx; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 260 | struct coda_iram_info iram_info; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 261 | struct gdi_tiled_map tiled_map; |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 262 | u32 bit_stream_param; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 263 | u32 frm_dis_flg; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 264 | u32 frame_mem_ctrl; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 265 | int display_idx; |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 266 | struct dentry *debugfs_entry; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 267 | }; |
| 268 | |
Javier Martin | 832fbb5 | 2012-10-29 08:34:59 -0300 | [diff] [blame] | 269 | static const u8 coda_filler_nal[14] = { 0x00, 0x00, 0x00, 0x01, 0x0c, 0xff, |
| 270 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 }; |
| 271 | static const u8 coda_filler_size[8] = { 0, 7, 14, 13, 12, 11, 10, 9 }; |
Javier Martin | 3f3f5c7 | 2012-10-29 05:20:29 -0300 | [diff] [blame] | 272 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 273 | static inline void coda_write(struct coda_dev *dev, u32 data, u32 reg) |
| 274 | { |
| 275 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 276 | "%s: data=0x%x, reg=0x%x\n", __func__, data, reg); |
| 277 | writel(data, dev->regs_base + reg); |
| 278 | } |
| 279 | |
| 280 | static inline unsigned int coda_read(struct coda_dev *dev, u32 reg) |
| 281 | { |
| 282 | u32 data; |
| 283 | data = readl(dev->regs_base + reg); |
| 284 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 285 | "%s: data=0x%x, reg=0x%x\n", __func__, data, reg); |
| 286 | return data; |
| 287 | } |
| 288 | |
| 289 | static inline unsigned long coda_isbusy(struct coda_dev *dev) |
| 290 | { |
| 291 | return coda_read(dev, CODA_REG_BIT_BUSY); |
| 292 | } |
| 293 | |
| 294 | static inline int coda_is_initialized(struct coda_dev *dev) |
| 295 | { |
| 296 | return (coda_read(dev, CODA_REG_BIT_CUR_PC) != 0); |
| 297 | } |
| 298 | |
| 299 | static int coda_wait_timeout(struct coda_dev *dev) |
| 300 | { |
| 301 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
| 302 | |
| 303 | while (coda_isbusy(dev)) { |
| 304 | if (time_after(jiffies, timeout)) |
| 305 | return -ETIMEDOUT; |
| 306 | } |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static void coda_command_async(struct coda_ctx *ctx, int cmd) |
| 311 | { |
| 312 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 313 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 314 | if (dev->devtype->product == CODA_960 || |
| 315 | dev->devtype->product == CODA_7541) { |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 316 | /* Restore context related registers to CODA */ |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 317 | coda_write(dev, ctx->bit_stream_param, |
| 318 | CODA_REG_BIT_BIT_STREAM_PARAM); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 319 | coda_write(dev, ctx->frm_dis_flg, |
| 320 | CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 321 | coda_write(dev, ctx->frame_mem_ctrl, |
| 322 | CODA_REG_BIT_FRAME_MEM_CTRL); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 323 | coda_write(dev, ctx->workbuf.paddr, CODA_REG_BIT_WORK_BUF_ADDR); |
| 324 | } |
| 325 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 326 | if (dev->devtype->product == CODA_960) { |
| 327 | coda_write(dev, 1, CODA9_GDI_WPROT_ERR_CLR); |
| 328 | coda_write(dev, 0, CODA9_GDI_WPROT_RGN_EN); |
| 329 | } |
| 330 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 331 | coda_write(dev, CODA_REG_BIT_BUSY_FLAG, CODA_REG_BIT_BUSY); |
| 332 | |
| 333 | coda_write(dev, ctx->idx, CODA_REG_BIT_RUN_INDEX); |
| 334 | coda_write(dev, ctx->params.codec_mode, CODA_REG_BIT_RUN_COD_STD); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 335 | coda_write(dev, ctx->params.codec_mode_aux, CODA7_REG_BIT_RUN_AUX_STD); |
| 336 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 337 | coda_write(dev, cmd, CODA_REG_BIT_RUN_COMMAND); |
| 338 | } |
| 339 | |
| 340 | static int coda_command_sync(struct coda_ctx *ctx, int cmd) |
| 341 | { |
| 342 | struct coda_dev *dev = ctx->dev; |
| 343 | |
| 344 | coda_command_async(ctx, cmd); |
| 345 | return coda_wait_timeout(dev); |
| 346 | } |
| 347 | |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 348 | static int coda_hw_reset(struct coda_ctx *ctx) |
| 349 | { |
| 350 | struct coda_dev *dev = ctx->dev; |
| 351 | unsigned long timeout; |
| 352 | unsigned int idx; |
| 353 | int ret; |
| 354 | |
| 355 | if (!dev->rstc) |
| 356 | return -ENOENT; |
| 357 | |
| 358 | idx = coda_read(dev, CODA_REG_BIT_RUN_INDEX); |
| 359 | |
| 360 | timeout = jiffies + msecs_to_jiffies(100); |
| 361 | coda_write(dev, 0x11, CODA9_GDI_BUS_CTRL); |
| 362 | while (coda_read(dev, CODA9_GDI_BUS_STATUS) != 0x77) { |
| 363 | if (time_after(jiffies, timeout)) |
| 364 | return -ETIME; |
| 365 | cpu_relax(); |
| 366 | } |
| 367 | |
| 368 | ret = reset_control_reset(dev->rstc); |
| 369 | if (ret < 0) |
| 370 | return ret; |
| 371 | |
| 372 | coda_write(dev, 0x00, CODA9_GDI_BUS_CTRL); |
| 373 | coda_write(dev, CODA_REG_BIT_BUSY_FLAG, CODA_REG_BIT_BUSY); |
| 374 | coda_write(dev, CODA_REG_RUN_ENABLE, CODA_REG_BIT_CODE_RUN); |
| 375 | ret = coda_wait_timeout(dev); |
| 376 | coda_write(dev, idx, CODA_REG_BIT_RUN_INDEX); |
| 377 | |
| 378 | return ret; |
| 379 | } |
| 380 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 381 | static struct coda_q_data *get_q_data(struct coda_ctx *ctx, |
| 382 | enum v4l2_buf_type type) |
| 383 | { |
| 384 | switch (type) { |
| 385 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 386 | return &(ctx->q_data[V4L2_M2M_SRC]); |
| 387 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 388 | return &(ctx->q_data[V4L2_M2M_DST]); |
| 389 | default: |
Philipp Zabel | b973629 | 2014-07-11 06:36:18 -0300 | [diff] [blame] | 390 | return NULL; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 391 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 395 | * Array of all formats supported by any version of Coda: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 396 | */ |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 397 | static struct coda_fmt coda_formats[] = { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 398 | { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 399 | .name = "YUV 4:2:0 Planar, YCbCr", |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 400 | .fourcc = V4L2_PIX_FMT_YUV420, |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 401 | }, |
| 402 | { |
| 403 | .name = "YUV 4:2:0 Planar, YCrCb", |
| 404 | .fourcc = V4L2_PIX_FMT_YVU420, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 405 | }, |
| 406 | { |
| 407 | .name = "H264 Encoded Stream", |
| 408 | .fourcc = V4L2_PIX_FMT_H264, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 409 | }, |
| 410 | { |
| 411 | .name = "MPEG4 Encoded Stream", |
| 412 | .fourcc = V4L2_PIX_FMT_MPEG4, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 413 | }, |
| 414 | }; |
| 415 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 416 | #define CODA_CODEC(mode, src_fourcc, dst_fourcc, max_w, max_h) \ |
| 417 | { mode, src_fourcc, dst_fourcc, max_w, max_h } |
| 418 | |
| 419 | /* |
| 420 | * Arrays of codecs supported by each given version of Coda: |
| 421 | * i.MX27 -> codadx6 |
| 422 | * i.MX5x -> coda7 |
| 423 | * i.MX6 -> coda960 |
| 424 | * Use V4L2_PIX_FMT_YUV420 as placeholder for all supported YUV 4:2:0 variants |
| 425 | */ |
| 426 | static struct coda_codec codadx6_codecs[] = { |
| 427 | CODA_CODEC(CODADX6_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 720, 576), |
| 428 | CODA_CODEC(CODADX6_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 720, 576), |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 429 | }; |
| 430 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 431 | static struct coda_codec coda7_codecs[] = { |
| 432 | CODA_CODEC(CODA7_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1280, 720), |
| 433 | CODA_CODEC(CODA7_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1280, 720), |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 434 | CODA_CODEC(CODA7_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1080), |
| 435 | CODA_CODEC(CODA7_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1080), |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 436 | }; |
| 437 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 438 | static struct coda_codec coda9_codecs[] = { |
| 439 | CODA_CODEC(CODA9_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1920, 1080), |
| 440 | CODA_CODEC(CODA9_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1920, 1080), |
| 441 | CODA_CODEC(CODA9_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1080), |
| 442 | CODA_CODEC(CODA9_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1080), |
| 443 | }; |
| 444 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 445 | static bool coda_format_is_yuv(u32 fourcc) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 446 | { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 447 | switch (fourcc) { |
| 448 | case V4L2_PIX_FMT_YUV420: |
| 449 | case V4L2_PIX_FMT_YVU420: |
| 450 | return true; |
| 451 | default: |
| 452 | return false; |
| 453 | } |
| 454 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 455 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 456 | /* |
| 457 | * Normalize all supported YUV 4:2:0 formats to the value used in the codec |
| 458 | * tables. |
| 459 | */ |
| 460 | static u32 coda_format_normalize_yuv(u32 fourcc) |
| 461 | { |
| 462 | return coda_format_is_yuv(fourcc) ? V4L2_PIX_FMT_YUV420 : fourcc; |
| 463 | } |
| 464 | |
| 465 | static struct coda_codec *coda_find_codec(struct coda_dev *dev, int src_fourcc, |
| 466 | int dst_fourcc) |
| 467 | { |
| 468 | struct coda_codec *codecs = dev->devtype->codecs; |
| 469 | int num_codecs = dev->devtype->num_codecs; |
| 470 | int k; |
| 471 | |
| 472 | src_fourcc = coda_format_normalize_yuv(src_fourcc); |
| 473 | dst_fourcc = coda_format_normalize_yuv(dst_fourcc); |
| 474 | if (src_fourcc == dst_fourcc) |
| 475 | return NULL; |
| 476 | |
| 477 | for (k = 0; k < num_codecs; k++) { |
| 478 | if (codecs[k].src_fourcc == src_fourcc && |
| 479 | codecs[k].dst_fourcc == dst_fourcc) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 480 | break; |
| 481 | } |
| 482 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 483 | if (k == num_codecs) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 484 | return NULL; |
| 485 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 486 | return &codecs[k]; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 487 | } |
| 488 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 489 | static void coda_get_max_dimensions(struct coda_dev *dev, |
| 490 | struct coda_codec *codec, |
| 491 | int *max_w, int *max_h) |
| 492 | { |
| 493 | struct coda_codec *codecs = dev->devtype->codecs; |
| 494 | int num_codecs = dev->devtype->num_codecs; |
| 495 | unsigned int w, h; |
| 496 | int k; |
| 497 | |
| 498 | if (codec) { |
| 499 | w = codec->max_w; |
| 500 | h = codec->max_h; |
| 501 | } else { |
| 502 | for (k = 0, w = 0, h = 0; k < num_codecs; k++) { |
| 503 | w = max(w, codecs[k].max_w); |
| 504 | h = max(h, codecs[k].max_h); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | if (max_w) |
| 509 | *max_w = w; |
| 510 | if (max_h) |
| 511 | *max_h = h; |
| 512 | } |
| 513 | |
Philipp Zabel | 927933f | 2013-09-30 10:34:48 -0300 | [diff] [blame] | 514 | static char *coda_product_name(int product) |
| 515 | { |
| 516 | static char buf[9]; |
| 517 | |
| 518 | switch (product) { |
| 519 | case CODA_DX6: |
| 520 | return "CodaDx6"; |
| 521 | case CODA_7541: |
| 522 | return "CODA7541"; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 523 | case CODA_960: |
| 524 | return "CODA960"; |
Philipp Zabel | 927933f | 2013-09-30 10:34:48 -0300 | [diff] [blame] | 525 | default: |
| 526 | snprintf(buf, sizeof(buf), "(0x%04x)", product); |
| 527 | return buf; |
| 528 | } |
| 529 | } |
| 530 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 531 | /* |
| 532 | * V4L2 ioctl() operations. |
| 533 | */ |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 534 | static int coda_querycap(struct file *file, void *priv, |
| 535 | struct v4l2_capability *cap) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 536 | { |
Philipp Zabel | 927933f | 2013-09-30 10:34:48 -0300 | [diff] [blame] | 537 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 538 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 539 | strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver)); |
Philipp Zabel | 927933f | 2013-09-30 10:34:48 -0300 | [diff] [blame] | 540 | strlcpy(cap->card, coda_product_name(ctx->dev->devtype->product), |
| 541 | sizeof(cap->card)); |
Philipp Zabel | dad0e1c | 2013-05-21 04:18:22 -0300 | [diff] [blame] | 542 | strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info)); |
Sylwester Nawrocki | c3aac8b | 2012-08-22 18:00:19 -0300 | [diff] [blame] | 543 | /* |
| 544 | * This is only a mem-to-mem video device. The capture and output |
| 545 | * device capability flags are left only for backward compatibility |
| 546 | * and are scheduled for removal. |
| 547 | */ |
| 548 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT | |
| 549 | V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 550 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
| 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | static int enum_fmt(void *priv, struct v4l2_fmtdesc *f, |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 556 | enum v4l2_buf_type type, int src_fourcc) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 557 | { |
| 558 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 559 | struct coda_codec *codecs = ctx->dev->devtype->codecs; |
| 560 | struct coda_fmt *formats = coda_formats; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 561 | struct coda_fmt *fmt; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 562 | int num_codecs = ctx->dev->devtype->num_codecs; |
| 563 | int num_formats = ARRAY_SIZE(coda_formats); |
| 564 | int i, k, num = 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 565 | |
| 566 | for (i = 0; i < num_formats; i++) { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 567 | /* Both uncompressed formats are always supported */ |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 568 | if (coda_format_is_yuv(formats[i].fourcc) && |
| 569 | !coda_format_is_yuv(src_fourcc)) { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 570 | if (num == f->index) |
| 571 | break; |
| 572 | ++num; |
| 573 | continue; |
| 574 | } |
| 575 | /* Compressed formats may be supported, check the codec list */ |
| 576 | for (k = 0; k < num_codecs; k++) { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 577 | /* if src_fourcc is set, only consider matching codecs */ |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 578 | if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE && |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 579 | formats[i].fourcc == codecs[k].dst_fourcc && |
| 580 | (!src_fourcc || src_fourcc == codecs[k].src_fourcc)) |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 581 | break; |
| 582 | if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT && |
| 583 | formats[i].fourcc == codecs[k].src_fourcc) |
| 584 | break; |
| 585 | } |
| 586 | if (k < num_codecs) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 587 | if (num == f->index) |
| 588 | break; |
| 589 | ++num; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | if (i < num_formats) { |
| 594 | fmt = &formats[i]; |
| 595 | strlcpy(f->description, fmt->name, sizeof(f->description)); |
| 596 | f->pixelformat = fmt->fourcc; |
Philipp Zabel | baf7021 | 2013-09-30 10:34:46 -0300 | [diff] [blame] | 597 | if (!coda_format_is_yuv(fmt->fourcc)) |
| 598 | f->flags |= V4L2_FMT_FLAG_COMPRESSED; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | /* Format not found */ |
| 603 | return -EINVAL; |
| 604 | } |
| 605 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 606 | static int coda_enum_fmt_vid_cap(struct file *file, void *priv, |
| 607 | struct v4l2_fmtdesc *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 608 | { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 609 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 610 | struct vb2_queue *src_vq; |
| 611 | struct coda_q_data *q_data_src; |
| 612 | |
| 613 | /* If the source format is already fixed, only list matching formats */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 614 | src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 615 | if (vb2_is_streaming(src_vq)) { |
| 616 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 617 | |
| 618 | return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 619 | q_data_src->fourcc); |
| 620 | } |
| 621 | |
| 622 | return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 623 | } |
| 624 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 625 | static int coda_enum_fmt_vid_out(struct file *file, void *priv, |
| 626 | struct v4l2_fmtdesc *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 627 | { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 628 | return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_OUTPUT, 0); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 629 | } |
| 630 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 631 | static int coda_g_fmt(struct file *file, void *priv, |
| 632 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 633 | { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 634 | struct coda_q_data *q_data; |
| 635 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 636 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 637 | q_data = get_q_data(ctx, f->type); |
Philipp Zabel | b973629 | 2014-07-11 06:36:18 -0300 | [diff] [blame] | 638 | if (!q_data) |
| 639 | return -EINVAL; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 640 | |
| 641 | f->fmt.pix.field = V4L2_FIELD_NONE; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 642 | f->fmt.pix.pixelformat = q_data->fourcc; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 643 | f->fmt.pix.width = q_data->width; |
| 644 | f->fmt.pix.height = q_data->height; |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 645 | f->fmt.pix.bytesperline = q_data->bytesperline; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 646 | |
| 647 | f->fmt.pix.sizeimage = q_data->sizeimage; |
| 648 | f->fmt.pix.colorspace = ctx->colorspace; |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 653 | static int coda_try_fmt(struct coda_ctx *ctx, struct coda_codec *codec, |
| 654 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 655 | { |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 656 | struct coda_dev *dev = ctx->dev; |
| 657 | struct coda_q_data *q_data; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 658 | unsigned int max_w, max_h; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 659 | enum v4l2_field field; |
| 660 | |
| 661 | field = f->fmt.pix.field; |
| 662 | if (field == V4L2_FIELD_ANY) |
| 663 | field = V4L2_FIELD_NONE; |
| 664 | else if (V4L2_FIELD_NONE != field) |
| 665 | return -EINVAL; |
| 666 | |
| 667 | /* V4L2 specification suggests the driver corrects the format struct |
| 668 | * if any of the dimensions is unsupported */ |
| 669 | f->fmt.pix.field = field; |
| 670 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 671 | coda_get_max_dimensions(dev, codec, &max_w, &max_h); |
| 672 | v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w, W_ALIGN, |
| 673 | &f->fmt.pix.height, MIN_H, max_h, H_ALIGN, |
| 674 | S_ALIGN); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 675 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 676 | switch (f->fmt.pix.pixelformat) { |
| 677 | case V4L2_PIX_FMT_YUV420: |
| 678 | case V4L2_PIX_FMT_YVU420: |
| 679 | case V4L2_PIX_FMT_H264: |
| 680 | case V4L2_PIX_FMT_MPEG4: |
| 681 | case V4L2_PIX_FMT_JPEG: |
| 682 | break; |
| 683 | default: |
| 684 | q_data = get_q_data(ctx, f->type); |
Philipp Zabel | b973629 | 2014-07-11 06:36:18 -0300 | [diff] [blame] | 685 | if (!q_data) |
| 686 | return -EINVAL; |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 687 | f->fmt.pix.pixelformat = q_data->fourcc; |
| 688 | } |
| 689 | |
| 690 | switch (f->fmt.pix.pixelformat) { |
| 691 | case V4L2_PIX_FMT_YUV420: |
| 692 | case V4L2_PIX_FMT_YVU420: |
Philipp Zabel | 451dfe5 | 2014-07-11 06:36:39 -0300 | [diff] [blame] | 693 | /* Frame stride must be multiple of 8, but 16 for h.264 */ |
| 694 | f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16); |
Philipp Zabel | 47cf0c6 | 2013-05-23 10:42:54 -0300 | [diff] [blame] | 695 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * |
Philipp Zabel | 451d43a | 2012-07-26 09:18:27 -0300 | [diff] [blame] | 696 | f->fmt.pix.height * 3 / 2; |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 697 | break; |
| 698 | case V4L2_PIX_FMT_H264: |
| 699 | case V4L2_PIX_FMT_MPEG4: |
| 700 | case V4L2_PIX_FMT_JPEG: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 701 | f->fmt.pix.bytesperline = 0; |
| 702 | f->fmt.pix.sizeimage = CODA_MAX_FRAME_SIZE; |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 703 | break; |
| 704 | default: |
| 705 | BUG(); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 711 | static int coda_try_fmt_vid_cap(struct file *file, void *priv, |
| 712 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 713 | { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 714 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 715 | struct coda_codec *codec; |
| 716 | struct vb2_queue *src_vq; |
| 717 | int ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 718 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 719 | /* |
| 720 | * If the source format is already fixed, try to find a codec that |
| 721 | * converts to the given destination format |
| 722 | */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 723 | src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 724 | if (vb2_is_streaming(src_vq)) { |
| 725 | struct coda_q_data *q_data_src; |
| 726 | |
| 727 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 728 | codec = coda_find_codec(ctx->dev, q_data_src->fourcc, |
| 729 | f->fmt.pix.pixelformat); |
| 730 | if (!codec) |
| 731 | return -EINVAL; |
| 732 | } else { |
| 733 | /* Otherwise determine codec by encoded format, if possible */ |
| 734 | codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420, |
| 735 | f->fmt.pix.pixelformat); |
| 736 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 737 | |
| 738 | f->fmt.pix.colorspace = ctx->colorspace; |
| 739 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 740 | ret = coda_try_fmt(ctx, codec, f); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 741 | if (ret < 0) |
| 742 | return ret; |
| 743 | |
| 744 | /* The h.264 decoder only returns complete 16x16 macroblocks */ |
| 745 | if (codec && codec->src_fourcc == V4L2_PIX_FMT_H264) { |
Philipp Zabel | 1b0ed7b | 2014-07-11 06:36:37 -0300 | [diff] [blame] | 746 | f->fmt.pix.width = f->fmt.pix.width; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 747 | f->fmt.pix.height = round_up(f->fmt.pix.height, 16); |
Philipp Zabel | 1b0ed7b | 2014-07-11 06:36:37 -0300 | [diff] [blame] | 748 | f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 16); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 749 | f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * |
| 750 | f->fmt.pix.height * 3 / 2; |
| 751 | } |
| 752 | |
| 753 | return 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 754 | } |
| 755 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 756 | static int coda_try_fmt_vid_out(struct file *file, void *priv, |
| 757 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 758 | { |
| 759 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 760 | struct coda_codec *codec; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 761 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 762 | /* Determine codec by encoded format, returns NULL if raw or invalid */ |
| 763 | codec = coda_find_codec(ctx->dev, f->fmt.pix.pixelformat, |
| 764 | V4L2_PIX_FMT_YUV420); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 765 | |
| 766 | if (!f->fmt.pix.colorspace) |
| 767 | f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; |
| 768 | |
Philipp Zabel | 5762559 | 2013-09-30 10:34:51 -0300 | [diff] [blame] | 769 | return coda_try_fmt(ctx, codec, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 770 | } |
| 771 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 772 | static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 773 | { |
| 774 | struct coda_q_data *q_data; |
| 775 | struct vb2_queue *vq; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 776 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 777 | vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 778 | if (!vq) |
| 779 | return -EINVAL; |
| 780 | |
| 781 | q_data = get_q_data(ctx, f->type); |
| 782 | if (!q_data) |
| 783 | return -EINVAL; |
| 784 | |
| 785 | if (vb2_is_busy(vq)) { |
| 786 | v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__); |
| 787 | return -EBUSY; |
| 788 | } |
| 789 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 790 | q_data->fourcc = f->fmt.pix.pixelformat; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 791 | q_data->width = f->fmt.pix.width; |
| 792 | q_data->height = f->fmt.pix.height; |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 793 | q_data->bytesperline = f->fmt.pix.bytesperline; |
Philipp Zabel | 451d43a | 2012-07-26 09:18:27 -0300 | [diff] [blame] | 794 | q_data->sizeimage = f->fmt.pix.sizeimage; |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 795 | q_data->rect.left = 0; |
| 796 | q_data->rect.top = 0; |
| 797 | q_data->rect.width = f->fmt.pix.width; |
| 798 | q_data->rect.height = f->fmt.pix.height; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 799 | |
| 800 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 801 | "Setting format for type %d, wxh: %dx%d, fmt: %d\n", |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 802 | f->type, q_data->width, q_data->height, q_data->fourcc); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 803 | |
| 804 | return 0; |
| 805 | } |
| 806 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 807 | static int coda_s_fmt_vid_cap(struct file *file, void *priv, |
| 808 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 809 | { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 810 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 811 | int ret; |
| 812 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 813 | ret = coda_try_fmt_vid_cap(file, priv, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 814 | if (ret) |
| 815 | return ret; |
| 816 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 817 | return coda_s_fmt(ctx, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 818 | } |
| 819 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 820 | static int coda_s_fmt_vid_out(struct file *file, void *priv, |
| 821 | struct v4l2_format *f) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 822 | { |
| 823 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 824 | int ret; |
| 825 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 826 | ret = coda_try_fmt_vid_out(file, priv, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 827 | if (ret) |
| 828 | return ret; |
| 829 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 830 | ret = coda_s_fmt(ctx, f); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 831 | if (ret) |
| 832 | ctx->colorspace = f->fmt.pix.colorspace; |
| 833 | |
| 834 | return ret; |
| 835 | } |
| 836 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 837 | static int coda_qbuf(struct file *file, void *priv, |
| 838 | struct v4l2_buffer *buf) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 839 | { |
| 840 | struct coda_ctx *ctx = fh_to_ctx(priv); |
| 841 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 842 | return v4l2_m2m_qbuf(file, ctx->fh.m2m_ctx, buf); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 843 | } |
| 844 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 845 | static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx, |
| 846 | struct v4l2_buffer *buf) |
| 847 | { |
| 848 | struct vb2_queue *src_vq; |
| 849 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 850 | src_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 851 | |
| 852 | return ((ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) && |
| 853 | (buf->sequence == (ctx->qsequence - 1))); |
| 854 | } |
| 855 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 856 | static int coda_dqbuf(struct file *file, void *priv, |
| 857 | struct v4l2_buffer *buf) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 858 | { |
| 859 | struct coda_ctx *ctx = fh_to_ctx(priv); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 860 | int ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 861 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 862 | ret = v4l2_m2m_dqbuf(file, ctx->fh.m2m_ctx, buf); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 863 | |
| 864 | /* If this is the last capture buffer, emit an end-of-stream event */ |
| 865 | if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && |
| 866 | coda_buf_is_end_of_stream(ctx, buf)) { |
| 867 | const struct v4l2_event eos_event = { |
| 868 | .type = V4L2_EVENT_EOS |
| 869 | }; |
| 870 | |
| 871 | v4l2_event_queue_fh(&ctx->fh, &eos_event); |
| 872 | } |
| 873 | |
| 874 | return ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 875 | } |
| 876 | |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 877 | static int coda_g_selection(struct file *file, void *fh, |
| 878 | struct v4l2_selection *s) |
| 879 | { |
| 880 | struct coda_ctx *ctx = fh_to_ctx(fh); |
| 881 | struct coda_q_data *q_data; |
| 882 | struct v4l2_rect r, *rsel; |
| 883 | |
| 884 | q_data = get_q_data(ctx, s->type); |
| 885 | if (!q_data) |
| 886 | return -EINVAL; |
| 887 | |
| 888 | r.left = 0; |
| 889 | r.top = 0; |
| 890 | r.width = q_data->width; |
| 891 | r.height = q_data->height; |
| 892 | rsel = &q_data->rect; |
| 893 | |
| 894 | switch (s->target) { |
| 895 | case V4L2_SEL_TGT_CROP_DEFAULT: |
| 896 | case V4L2_SEL_TGT_CROP_BOUNDS: |
| 897 | rsel = &r; |
| 898 | /* fallthrough */ |
| 899 | case V4L2_SEL_TGT_CROP: |
| 900 | if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) |
| 901 | return -EINVAL; |
| 902 | break; |
| 903 | case V4L2_SEL_TGT_COMPOSE_BOUNDS: |
| 904 | case V4L2_SEL_TGT_COMPOSE_PADDED: |
| 905 | rsel = &r; |
| 906 | /* fallthrough */ |
| 907 | case V4L2_SEL_TGT_COMPOSE: |
| 908 | case V4L2_SEL_TGT_COMPOSE_DEFAULT: |
| 909 | if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 910 | return -EINVAL; |
| 911 | break; |
| 912 | default: |
| 913 | return -EINVAL; |
| 914 | } |
| 915 | |
| 916 | s->r = *rsel; |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 921 | static int coda_try_decoder_cmd(struct file *file, void *fh, |
| 922 | struct v4l2_decoder_cmd *dc) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 923 | { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 924 | if (dc->cmd != V4L2_DEC_CMD_STOP) |
| 925 | return -EINVAL; |
| 926 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 927 | if (dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 928 | return -EINVAL; |
| 929 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 930 | if (!(dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) && (dc->stop.pts != 0)) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 931 | return -EINVAL; |
| 932 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | static int coda_decoder_cmd(struct file *file, void *fh, |
| 937 | struct v4l2_decoder_cmd *dc) |
| 938 | { |
| 939 | struct coda_ctx *ctx = fh_to_ctx(fh); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 940 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 941 | int ret; |
| 942 | |
| 943 | ret = coda_try_decoder_cmd(file, fh, dc); |
| 944 | if (ret < 0) |
| 945 | return ret; |
| 946 | |
| 947 | /* Ignore decoder stop command silently in encoder context */ |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 948 | if (ctx->inst_type != CODA_INST_DECODER) |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 949 | return 0; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 950 | |
| 951 | /* Set the strem-end flag on this context */ |
| 952 | ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; |
| 953 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 954 | if ((dev->devtype->product == CODA_960) && |
| 955 | coda_isbusy(dev) && |
| 956 | (ctx->idx == coda_read(dev, CODA_REG_BIT_RUN_INDEX))) { |
| 957 | /* If this context is currently running, update the hardware flag */ |
| 958 | coda_write(dev, ctx->bit_stream_param, CODA_REG_BIT_BIT_STREAM_PARAM); |
| 959 | } |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 960 | ctx->hold = false; |
Michael Olbrich | f3497da | 2014-07-11 06:36:30 -0300 | [diff] [blame] | 961 | v4l2_m2m_try_schedule(ctx->fh.m2m_ctx); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 962 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 963 | return 0; |
| 964 | } |
| 965 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 966 | static int coda_subscribe_event(struct v4l2_fh *fh, |
| 967 | const struct v4l2_event_subscription *sub) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 968 | { |
| 969 | switch (sub->type) { |
| 970 | case V4L2_EVENT_EOS: |
| 971 | return v4l2_event_subscribe(fh, sub, 0, NULL); |
| 972 | default: |
| 973 | return v4l2_ctrl_subscribe_event(fh, sub); |
| 974 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | static const struct v4l2_ioctl_ops coda_ioctl_ops = { |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 978 | .vidioc_querycap = coda_querycap, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 979 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 980 | .vidioc_enum_fmt_vid_cap = coda_enum_fmt_vid_cap, |
| 981 | .vidioc_g_fmt_vid_cap = coda_g_fmt, |
| 982 | .vidioc_try_fmt_vid_cap = coda_try_fmt_vid_cap, |
| 983 | .vidioc_s_fmt_vid_cap = coda_s_fmt_vid_cap, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 984 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 985 | .vidioc_enum_fmt_vid_out = coda_enum_fmt_vid_out, |
| 986 | .vidioc_g_fmt_vid_out = coda_g_fmt, |
| 987 | .vidioc_try_fmt_vid_out = coda_try_fmt_vid_out, |
| 988 | .vidioc_s_fmt_vid_out = coda_s_fmt_vid_out, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 989 | |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 990 | .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, |
| 991 | .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 992 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 993 | .vidioc_qbuf = coda_qbuf, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 994 | .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 995 | .vidioc_dqbuf = coda_dqbuf, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 996 | .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 997 | |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 998 | .vidioc_streamon = v4l2_m2m_ioctl_streamon, |
| 999 | .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1000 | |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 1001 | .vidioc_g_selection = coda_g_selection, |
| 1002 | |
Philipp Zabel | 64ba40a | 2013-09-30 10:34:52 -0300 | [diff] [blame] | 1003 | .vidioc_try_decoder_cmd = coda_try_decoder_cmd, |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 1004 | .vidioc_decoder_cmd = coda_decoder_cmd, |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1005 | |
Philipp Zabel | 2e9e4f1 | 2013-09-30 10:34:50 -0300 | [diff] [blame] | 1006 | .vidioc_subscribe_event = coda_subscribe_event, |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1007 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1008 | }; |
| 1009 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1010 | static int coda_start_decoding(struct coda_ctx *ctx); |
| 1011 | |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1012 | static inline int coda_get_bitstream_payload(struct coda_ctx *ctx) |
| 1013 | { |
| 1014 | return kfifo_len(&ctx->bitstream_fifo); |
| 1015 | } |
| 1016 | |
| 1017 | static void coda_kfifo_sync_from_device(struct coda_ctx *ctx) |
| 1018 | { |
| 1019 | struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; |
| 1020 | struct coda_dev *dev = ctx->dev; |
| 1021 | u32 rd_ptr; |
| 1022 | |
| 1023 | rd_ptr = coda_read(dev, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); |
| 1024 | kfifo->out = (kfifo->in & ~kfifo->mask) | |
| 1025 | (rd_ptr - ctx->bitstream.paddr); |
| 1026 | if (kfifo->out > kfifo->in) |
| 1027 | kfifo->out -= kfifo->mask + 1; |
| 1028 | } |
| 1029 | |
| 1030 | static void coda_kfifo_sync_to_device_full(struct coda_ctx *ctx) |
| 1031 | { |
| 1032 | struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; |
| 1033 | struct coda_dev *dev = ctx->dev; |
| 1034 | u32 rd_ptr, wr_ptr; |
| 1035 | |
| 1036 | rd_ptr = ctx->bitstream.paddr + (kfifo->out & kfifo->mask); |
| 1037 | coda_write(dev, rd_ptr, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); |
| 1038 | wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask); |
| 1039 | coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); |
| 1040 | } |
| 1041 | |
| 1042 | static void coda_kfifo_sync_to_device_write(struct coda_ctx *ctx) |
| 1043 | { |
| 1044 | struct __kfifo *kfifo = &ctx->bitstream_fifo.kfifo; |
| 1045 | struct coda_dev *dev = ctx->dev; |
| 1046 | u32 wr_ptr; |
| 1047 | |
| 1048 | wr_ptr = ctx->bitstream.paddr + (kfifo->in & kfifo->mask); |
| 1049 | coda_write(dev, wr_ptr, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); |
| 1050 | } |
| 1051 | |
| 1052 | static int coda_bitstream_queue(struct coda_ctx *ctx, struct vb2_buffer *src_buf) |
| 1053 | { |
| 1054 | u32 src_size = vb2_get_plane_payload(src_buf, 0); |
| 1055 | u32 n; |
| 1056 | |
| 1057 | n = kfifo_in(&ctx->bitstream_fifo, vb2_plane_vaddr(src_buf, 0), src_size); |
| 1058 | if (n < src_size) |
| 1059 | return -ENOSPC; |
| 1060 | |
| 1061 | dma_sync_single_for_device(&ctx->dev->plat_dev->dev, ctx->bitstream.paddr, |
| 1062 | ctx->bitstream.size, DMA_TO_DEVICE); |
| 1063 | |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 1064 | src_buf->v4l2_buf.sequence = ctx->qsequence++; |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1065 | |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | static bool coda_bitstream_try_queue(struct coda_ctx *ctx, |
| 1070 | struct vb2_buffer *src_buf) |
| 1071 | { |
| 1072 | int ret; |
| 1073 | |
| 1074 | if (coda_get_bitstream_payload(ctx) + |
| 1075 | vb2_get_plane_payload(src_buf, 0) + 512 >= ctx->bitstream.size) |
| 1076 | return false; |
| 1077 | |
| 1078 | if (vb2_plane_vaddr(src_buf, 0) == NULL) { |
| 1079 | v4l2_err(&ctx->dev->v4l2_dev, "trying to queue empty buffer\n"); |
| 1080 | return true; |
| 1081 | } |
| 1082 | |
| 1083 | ret = coda_bitstream_queue(ctx, src_buf); |
| 1084 | if (ret < 0) { |
| 1085 | v4l2_err(&ctx->dev->v4l2_dev, "bitstream buffer overflow\n"); |
| 1086 | return false; |
| 1087 | } |
| 1088 | /* Sync read pointer to device */ |
| 1089 | if (ctx == v4l2_m2m_get_curr_priv(ctx->dev->m2m_dev)) |
| 1090 | coda_kfifo_sync_to_device_write(ctx); |
| 1091 | |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 1092 | ctx->hold = false; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1093 | |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1094 | return true; |
| 1095 | } |
| 1096 | |
| 1097 | static void coda_fill_bitstream(struct coda_ctx *ctx) |
| 1098 | { |
| 1099 | struct vb2_buffer *src_buf; |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 1100 | struct coda_timestamp *ts; |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1101 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1102 | while (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) > 0) { |
| 1103 | src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1104 | |
| 1105 | if (coda_bitstream_try_queue(ctx, src_buf)) { |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 1106 | /* |
| 1107 | * Source buffer is queued in the bitstream ringbuffer; |
| 1108 | * queue the timestamp and mark source buffer as done |
| 1109 | */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1110 | src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 1111 | |
| 1112 | ts = kmalloc(sizeof(*ts), GFP_KERNEL); |
| 1113 | if (ts) { |
| 1114 | ts->sequence = src_buf->v4l2_buf.sequence; |
| 1115 | ts->timecode = src_buf->v4l2_buf.timecode; |
| 1116 | ts->timestamp = src_buf->v4l2_buf.timestamp; |
| 1117 | list_add_tail(&ts->list, &ctx->timestamp_list); |
| 1118 | } |
| 1119 | |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1120 | v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); |
| 1121 | } else { |
| 1122 | break; |
| 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1127 | static void coda_set_gdi_regs(struct coda_ctx *ctx) |
| 1128 | { |
| 1129 | struct gdi_tiled_map *tiled_map = &ctx->tiled_map; |
| 1130 | struct coda_dev *dev = ctx->dev; |
| 1131 | int i; |
| 1132 | |
| 1133 | for (i = 0; i < 16; i++) |
| 1134 | coda_write(dev, tiled_map->xy2ca_map[i], |
| 1135 | CODA9_GDI_XY2_CAS_0 + 4 * i); |
| 1136 | for (i = 0; i < 4; i++) |
| 1137 | coda_write(dev, tiled_map->xy2ba_map[i], |
| 1138 | CODA9_GDI_XY2_BA_0 + 4 * i); |
| 1139 | for (i = 0; i < 16; i++) |
| 1140 | coda_write(dev, tiled_map->xy2ra_map[i], |
| 1141 | CODA9_GDI_XY2_RAS_0 + 4 * i); |
| 1142 | coda_write(dev, tiled_map->xy2rbc_config, CODA9_GDI_XY2_RBC_CONFIG); |
| 1143 | for (i = 0; i < 32; i++) |
| 1144 | coda_write(dev, tiled_map->rbc2axi_map[i], |
| 1145 | CODA9_GDI_RBC2_AXI_0 + 4 * i); |
| 1146 | } |
| 1147 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1148 | /* |
| 1149 | * Mem-to-mem operations. |
| 1150 | */ |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1151 | static int coda_prepare_decode(struct coda_ctx *ctx) |
| 1152 | { |
| 1153 | struct vb2_buffer *dst_buf; |
| 1154 | struct coda_dev *dev = ctx->dev; |
| 1155 | struct coda_q_data *q_data_dst; |
| 1156 | u32 stridey, height; |
| 1157 | u32 picture_y, picture_cb, picture_cr; |
| 1158 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1159 | dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1160 | q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
| 1161 | |
| 1162 | if (ctx->params.rot_mode & CODA_ROT_90) { |
| 1163 | stridey = q_data_dst->height; |
| 1164 | height = q_data_dst->width; |
| 1165 | } else { |
| 1166 | stridey = q_data_dst->width; |
| 1167 | height = q_data_dst->height; |
| 1168 | } |
| 1169 | |
| 1170 | /* Try to copy source buffer contents into the bitstream ringbuffer */ |
| 1171 | mutex_lock(&ctx->bitstream_mutex); |
| 1172 | coda_fill_bitstream(ctx); |
| 1173 | mutex_unlock(&ctx->bitstream_mutex); |
| 1174 | |
| 1175 | if (coda_get_bitstream_payload(ctx) < 512 && |
| 1176 | (!(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) { |
| 1177 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 1178 | "bitstream payload: %d, skipping\n", |
| 1179 | coda_get_bitstream_payload(ctx)); |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1180 | v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1181 | return -EAGAIN; |
| 1182 | } |
| 1183 | |
| 1184 | /* Run coda_start_decoding (again) if not yet initialized */ |
| 1185 | if (!ctx->initialized) { |
| 1186 | int ret = coda_start_decoding(ctx); |
| 1187 | if (ret < 0) { |
| 1188 | v4l2_err(&dev->v4l2_dev, "failed to start decoding\n"); |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1189 | v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1190 | return -EAGAIN; |
| 1191 | } else { |
| 1192 | ctx->initialized = 1; |
| 1193 | } |
| 1194 | } |
| 1195 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1196 | if (dev->devtype->product == CODA_960) |
| 1197 | coda_set_gdi_regs(ctx); |
| 1198 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1199 | /* Set rotator output */ |
| 1200 | picture_y = vb2_dma_contig_plane_dma_addr(dst_buf, 0); |
| 1201 | if (q_data_dst->fourcc == V4L2_PIX_FMT_YVU420) { |
| 1202 | /* Switch Cr and Cb for YVU420 format */ |
| 1203 | picture_cr = picture_y + stridey * height; |
| 1204 | picture_cb = picture_cr + stridey / 2 * height / 2; |
| 1205 | } else { |
| 1206 | picture_cb = picture_y + stridey * height; |
| 1207 | picture_cr = picture_cb + stridey / 2 * height / 2; |
| 1208 | } |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1209 | |
| 1210 | if (dev->devtype->product == CODA_960) { |
| 1211 | /* |
| 1212 | * The CODA960 seems to have an internal list of buffers with |
| 1213 | * 64 entries that includes the registered frame buffers as |
| 1214 | * well as the rotator buffer output. |
| 1215 | * ROT_INDEX needs to be < 0x40, but > ctx->num_internal_frames. |
| 1216 | */ |
| 1217 | coda_write(dev, CODA_MAX_FRAMEBUFFERS + dst_buf->v4l2_buf.index, |
| 1218 | CODA9_CMD_DEC_PIC_ROT_INDEX); |
| 1219 | coda_write(dev, picture_y, CODA9_CMD_DEC_PIC_ROT_ADDR_Y); |
| 1220 | coda_write(dev, picture_cb, CODA9_CMD_DEC_PIC_ROT_ADDR_CB); |
| 1221 | coda_write(dev, picture_cr, CODA9_CMD_DEC_PIC_ROT_ADDR_CR); |
| 1222 | coda_write(dev, stridey, CODA9_CMD_DEC_PIC_ROT_STRIDE); |
| 1223 | } else { |
| 1224 | coda_write(dev, picture_y, CODA_CMD_DEC_PIC_ROT_ADDR_Y); |
| 1225 | coda_write(dev, picture_cb, CODA_CMD_DEC_PIC_ROT_ADDR_CB); |
| 1226 | coda_write(dev, picture_cr, CODA_CMD_DEC_PIC_ROT_ADDR_CR); |
| 1227 | coda_write(dev, stridey, CODA_CMD_DEC_PIC_ROT_STRIDE); |
| 1228 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1229 | coda_write(dev, CODA_ROT_MIR_ENABLE | ctx->params.rot_mode, |
| 1230 | CODA_CMD_DEC_PIC_ROT_MODE); |
| 1231 | |
| 1232 | switch (dev->devtype->product) { |
| 1233 | case CODA_DX6: |
| 1234 | /* TBD */ |
| 1235 | case CODA_7541: |
| 1236 | coda_write(dev, CODA_PRE_SCAN_EN, CODA_CMD_DEC_PIC_OPTION); |
| 1237 | break; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1238 | case CODA_960: |
| 1239 | coda_write(dev, (1 << 10), CODA_CMD_DEC_PIC_OPTION); /* 'hardcode to use interrupt disable mode'? */ |
| 1240 | break; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | coda_write(dev, 0, CODA_CMD_DEC_PIC_SKIP_NUM); |
| 1244 | |
| 1245 | coda_write(dev, 0, CODA_CMD_DEC_PIC_BB_START); |
| 1246 | coda_write(dev, 0, CODA_CMD_DEC_PIC_START_BYTE); |
| 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 1251 | static void coda_prepare_encode(struct coda_ctx *ctx) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1252 | { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1253 | struct coda_q_data *q_data_src, *q_data_dst; |
| 1254 | struct vb2_buffer *src_buf, *dst_buf; |
| 1255 | struct coda_dev *dev = ctx->dev; |
| 1256 | int force_ipicture; |
| 1257 | int quant_param = 0; |
| 1258 | u32 picture_y, picture_cb, picture_cr; |
| 1259 | u32 pic_stream_buffer_addr, pic_stream_buffer_size; |
| 1260 | u32 dst_fourcc; |
| 1261 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1262 | src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); |
| 1263 | dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1264 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 1265 | q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1266 | dst_fourcc = q_data_dst->fourcc; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1267 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1268 | src_buf->v4l2_buf.sequence = ctx->osequence; |
| 1269 | dst_buf->v4l2_buf.sequence = ctx->osequence; |
| 1270 | ctx->osequence++; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1271 | |
| 1272 | /* |
| 1273 | * Workaround coda firmware BUG that only marks the first |
| 1274 | * frame as IDR. This is a problem for some decoders that can't |
| 1275 | * recover when a frame is lost. |
| 1276 | */ |
| 1277 | if (src_buf->v4l2_buf.sequence % ctx->params.gop_size) { |
| 1278 | src_buf->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME; |
| 1279 | src_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_KEYFRAME; |
| 1280 | } else { |
| 1281 | src_buf->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME; |
| 1282 | src_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_PFRAME; |
| 1283 | } |
| 1284 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1285 | if (dev->devtype->product == CODA_960) |
| 1286 | coda_set_gdi_regs(ctx); |
| 1287 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1288 | /* |
| 1289 | * Copy headers at the beginning of the first frame for H.264 only. |
| 1290 | * In MPEG4 they are already copied by the coda. |
| 1291 | */ |
| 1292 | if (src_buf->v4l2_buf.sequence == 0) { |
| 1293 | pic_stream_buffer_addr = |
| 1294 | vb2_dma_contig_plane_dma_addr(dst_buf, 0) + |
| 1295 | ctx->vpu_header_size[0] + |
| 1296 | ctx->vpu_header_size[1] + |
| 1297 | ctx->vpu_header_size[2]; |
| 1298 | pic_stream_buffer_size = CODA_MAX_FRAME_SIZE - |
| 1299 | ctx->vpu_header_size[0] - |
| 1300 | ctx->vpu_header_size[1] - |
| 1301 | ctx->vpu_header_size[2]; |
| 1302 | memcpy(vb2_plane_vaddr(dst_buf, 0), |
| 1303 | &ctx->vpu_header[0][0], ctx->vpu_header_size[0]); |
| 1304 | memcpy(vb2_plane_vaddr(dst_buf, 0) + ctx->vpu_header_size[0], |
| 1305 | &ctx->vpu_header[1][0], ctx->vpu_header_size[1]); |
| 1306 | memcpy(vb2_plane_vaddr(dst_buf, 0) + ctx->vpu_header_size[0] + |
| 1307 | ctx->vpu_header_size[1], &ctx->vpu_header[2][0], |
| 1308 | ctx->vpu_header_size[2]); |
| 1309 | } else { |
| 1310 | pic_stream_buffer_addr = |
| 1311 | vb2_dma_contig_plane_dma_addr(dst_buf, 0); |
| 1312 | pic_stream_buffer_size = CODA_MAX_FRAME_SIZE; |
| 1313 | } |
| 1314 | |
| 1315 | if (src_buf->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) { |
| 1316 | force_ipicture = 1; |
| 1317 | switch (dst_fourcc) { |
| 1318 | case V4L2_PIX_FMT_H264: |
| 1319 | quant_param = ctx->params.h264_intra_qp; |
| 1320 | break; |
| 1321 | case V4L2_PIX_FMT_MPEG4: |
| 1322 | quant_param = ctx->params.mpeg4_intra_qp; |
| 1323 | break; |
| 1324 | default: |
| 1325 | v4l2_warn(&ctx->dev->v4l2_dev, |
| 1326 | "cannot set intra qp, fmt not supported\n"); |
| 1327 | break; |
| 1328 | } |
| 1329 | } else { |
| 1330 | force_ipicture = 0; |
| 1331 | switch (dst_fourcc) { |
| 1332 | case V4L2_PIX_FMT_H264: |
| 1333 | quant_param = ctx->params.h264_inter_qp; |
| 1334 | break; |
| 1335 | case V4L2_PIX_FMT_MPEG4: |
| 1336 | quant_param = ctx->params.mpeg4_inter_qp; |
| 1337 | break; |
| 1338 | default: |
| 1339 | v4l2_warn(&ctx->dev->v4l2_dev, |
| 1340 | "cannot set inter qp, fmt not supported\n"); |
| 1341 | break; |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | /* submit */ |
Philipp Zabel | 8f35c7b | 2012-07-09 04:25:52 -0300 | [diff] [blame] | 1346 | coda_write(dev, CODA_ROT_MIR_ENABLE | ctx->params.rot_mode, CODA_CMD_ENC_PIC_ROT_MODE); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1347 | coda_write(dev, quant_param, CODA_CMD_ENC_PIC_QS); |
| 1348 | |
| 1349 | |
| 1350 | picture_y = vb2_dma_contig_plane_dma_addr(src_buf, 0); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1351 | switch (q_data_src->fourcc) { |
| 1352 | case V4L2_PIX_FMT_YVU420: |
| 1353 | /* Switch Cb and Cr for YVU420 format */ |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 1354 | picture_cr = picture_y + q_data_src->bytesperline * |
| 1355 | q_data_src->height; |
| 1356 | picture_cb = picture_cr + q_data_src->bytesperline / 2 * |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1357 | q_data_src->height / 2; |
| 1358 | break; |
| 1359 | case V4L2_PIX_FMT_YUV420: |
| 1360 | default: |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 1361 | picture_cb = picture_y + q_data_src->bytesperline * |
| 1362 | q_data_src->height; |
| 1363 | picture_cr = picture_cb + q_data_src->bytesperline / 2 * |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1364 | q_data_src->height / 2; |
| 1365 | break; |
| 1366 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1367 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1368 | if (dev->devtype->product == CODA_960) { |
| 1369 | coda_write(dev, 4/*FIXME: 0*/, CODA9_CMD_ENC_PIC_SRC_INDEX); |
| 1370 | coda_write(dev, q_data_src->width, CODA9_CMD_ENC_PIC_SRC_STRIDE); |
| 1371 | coda_write(dev, 0, CODA9_CMD_ENC_PIC_SUB_FRAME_SYNC); |
| 1372 | |
| 1373 | coda_write(dev, picture_y, CODA9_CMD_ENC_PIC_SRC_ADDR_Y); |
| 1374 | coda_write(dev, picture_cb, CODA9_CMD_ENC_PIC_SRC_ADDR_CB); |
| 1375 | coda_write(dev, picture_cr, CODA9_CMD_ENC_PIC_SRC_ADDR_CR); |
| 1376 | } else { |
| 1377 | coda_write(dev, picture_y, CODA_CMD_ENC_PIC_SRC_ADDR_Y); |
| 1378 | coda_write(dev, picture_cb, CODA_CMD_ENC_PIC_SRC_ADDR_CB); |
| 1379 | coda_write(dev, picture_cr, CODA_CMD_ENC_PIC_SRC_ADDR_CR); |
| 1380 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1381 | coda_write(dev, force_ipicture << 1 & 0x2, |
| 1382 | CODA_CMD_ENC_PIC_OPTION); |
| 1383 | |
| 1384 | coda_write(dev, pic_stream_buffer_addr, CODA_CMD_ENC_PIC_BB_START); |
| 1385 | coda_write(dev, pic_stream_buffer_size / 1024, |
| 1386 | CODA_CMD_ENC_PIC_BB_SIZE); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1387 | |
| 1388 | if (!ctx->streamon_out) { |
| 1389 | /* After streamoff on the output side, set the stream end flag */ |
| 1390 | ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; |
| 1391 | coda_write(dev, ctx->bit_stream_param, CODA_REG_BIT_BIT_STREAM_PARAM); |
| 1392 | } |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static void coda_device_run(void *m2m_priv) |
| 1396 | { |
| 1397 | struct coda_ctx *ctx = m2m_priv; |
| 1398 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 1399 | |
| 1400 | queue_work(dev->workqueue, &ctx->pic_run_work); |
| 1401 | } |
| 1402 | |
| 1403 | static void coda_free_framebuffers(struct coda_ctx *ctx); |
| 1404 | static void coda_free_context_buffers(struct coda_ctx *ctx); |
| 1405 | |
| 1406 | static void coda_seq_end_work(struct work_struct *work) |
| 1407 | { |
| 1408 | struct coda_ctx *ctx = container_of(work, struct coda_ctx, seq_end_work); |
| 1409 | struct coda_dev *dev = ctx->dev; |
| 1410 | |
| 1411 | mutex_lock(&ctx->buffer_mutex); |
| 1412 | mutex_lock(&dev->coda_mutex); |
| 1413 | |
| 1414 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 1415 | "%d: %s: sent command 'SEQ_END' to coda\n", ctx->idx, __func__); |
| 1416 | if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) { |
| 1417 | v4l2_err(&dev->v4l2_dev, |
| 1418 | "CODA_COMMAND_SEQ_END failed\n"); |
| 1419 | } |
| 1420 | |
| 1421 | kfifo_init(&ctx->bitstream_fifo, |
| 1422 | ctx->bitstream.vaddr, ctx->bitstream.size); |
| 1423 | |
| 1424 | coda_free_framebuffers(ctx); |
| 1425 | coda_free_context_buffers(ctx); |
| 1426 | |
| 1427 | mutex_unlock(&dev->coda_mutex); |
| 1428 | mutex_unlock(&ctx->buffer_mutex); |
| 1429 | } |
| 1430 | |
| 1431 | static void coda_finish_decode(struct coda_ctx *ctx); |
| 1432 | static void coda_finish_encode(struct coda_ctx *ctx); |
| 1433 | |
| 1434 | static void coda_pic_run_work(struct work_struct *work) |
| 1435 | { |
| 1436 | struct coda_ctx *ctx = container_of(work, struct coda_ctx, pic_run_work); |
| 1437 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1438 | int ret; |
| 1439 | |
| 1440 | mutex_lock(&ctx->buffer_mutex); |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 1441 | mutex_lock(&dev->coda_mutex); |
| 1442 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1443 | if (ctx->inst_type == CODA_INST_DECODER) { |
| 1444 | ret = coda_prepare_decode(ctx); |
| 1445 | if (ret < 0) { |
| 1446 | mutex_unlock(&dev->coda_mutex); |
| 1447 | mutex_unlock(&ctx->buffer_mutex); |
| 1448 | /* job_finish scheduled by prepare_decode */ |
| 1449 | return; |
| 1450 | } |
| 1451 | } else { |
| 1452 | coda_prepare_encode(ctx); |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 1453 | } |
| 1454 | |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1455 | if (dev->devtype->product != CODA_DX6) |
| 1456 | coda_write(dev, ctx->iram_info.axi_sram_use, |
| 1457 | CODA7_REG_BIT_AXI_SRAM_USE); |
| 1458 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1459 | if (ctx->inst_type == CODA_INST_DECODER) |
| 1460 | coda_kfifo_sync_to_device_full(ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1461 | coda_command_async(ctx, CODA_COMMAND_PIC_RUN); |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 1462 | |
| 1463 | if (!wait_for_completion_timeout(&ctx->completion, msecs_to_jiffies(1000))) { |
| 1464 | dev_err(&dev->plat_dev->dev, "CODA PIC_RUN timeout\n"); |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 1465 | |
| 1466 | ctx->hold = true; |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 1467 | |
| 1468 | coda_hw_reset(ctx); |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 1469 | } else if (!ctx->aborting) { |
| 1470 | if (ctx->inst_type == CODA_INST_DECODER) |
| 1471 | coda_finish_decode(ctx); |
| 1472 | else |
| 1473 | coda_finish_encode(ctx); |
| 1474 | } |
| 1475 | |
| 1476 | if (ctx->aborting || (!ctx->streamon_cap && !ctx->streamon_out)) |
| 1477 | queue_work(dev->workqueue, &ctx->seq_end_work); |
| 1478 | |
| 1479 | mutex_unlock(&dev->coda_mutex); |
| 1480 | mutex_unlock(&ctx->buffer_mutex); |
| 1481 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1482 | v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->fh.m2m_ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | static int coda_job_ready(void *m2m_priv) |
| 1486 | { |
| 1487 | struct coda_ctx *ctx = m2m_priv; |
| 1488 | |
| 1489 | /* |
| 1490 | * For both 'P' and 'key' frame cases 1 picture |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1491 | * and 1 frame are needed. In the decoder case, |
| 1492 | * the compressed frame can be in the bitstream. |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1493 | */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1494 | if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) && |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1495 | ctx->inst_type != CODA_INST_DECODER) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1496 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1497 | "not ready: not enough video buffers.\n"); |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1501 | if (!v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx)) { |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 1502 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1503 | "not ready: not enough video capture buffers.\n"); |
| 1504 | return 0; |
| 1505 | } |
| 1506 | |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 1507 | if (ctx->hold || |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1508 | ((ctx->inst_type == CODA_INST_DECODER) && |
| 1509 | (coda_get_bitstream_payload(ctx) < 512) && |
| 1510 | !(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) { |
| 1511 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1512 | "%d: not ready: not enough bitstream data.\n", |
| 1513 | ctx->idx); |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
Philipp Zabel | 3e748268 | 2013-05-23 10:43:01 -0300 | [diff] [blame] | 1517 | if (ctx->aborting) { |
| 1518 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1519 | "not ready: aborting\n"); |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1523 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1524 | "job ready\n"); |
| 1525 | return 1; |
| 1526 | } |
| 1527 | |
| 1528 | static void coda_job_abort(void *priv) |
| 1529 | { |
| 1530 | struct coda_ctx *ctx = priv; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1531 | |
| 1532 | ctx->aborting = 1; |
| 1533 | |
| 1534 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1535 | "Aborting task\n"); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void coda_lock(void *m2m_priv) |
| 1539 | { |
| 1540 | struct coda_ctx *ctx = m2m_priv; |
| 1541 | struct coda_dev *pcdev = ctx->dev; |
| 1542 | mutex_lock(&pcdev->dev_mutex); |
| 1543 | } |
| 1544 | |
| 1545 | static void coda_unlock(void *m2m_priv) |
| 1546 | { |
| 1547 | struct coda_ctx *ctx = m2m_priv; |
| 1548 | struct coda_dev *pcdev = ctx->dev; |
| 1549 | mutex_unlock(&pcdev->dev_mutex); |
| 1550 | } |
| 1551 | |
| 1552 | static struct v4l2_m2m_ops coda_m2m_ops = { |
| 1553 | .device_run = coda_device_run, |
| 1554 | .job_ready = coda_job_ready, |
| 1555 | .job_abort = coda_job_abort, |
| 1556 | .lock = coda_lock, |
| 1557 | .unlock = coda_unlock, |
| 1558 | }; |
| 1559 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1560 | static void coda_set_tiled_map_type(struct coda_ctx *ctx, int tiled_map_type) |
| 1561 | { |
| 1562 | struct gdi_tiled_map *tiled_map = &ctx->tiled_map; |
| 1563 | int luma_map, chro_map, i; |
| 1564 | |
| 1565 | memset(tiled_map, 0, sizeof(*tiled_map)); |
| 1566 | |
| 1567 | luma_map = 64; |
| 1568 | chro_map = 64; |
| 1569 | tiled_map->map_type = tiled_map_type; |
| 1570 | for (i = 0; i < 16; i++) |
| 1571 | tiled_map->xy2ca_map[i] = luma_map << 8 | chro_map; |
| 1572 | for (i = 0; i < 4; i++) |
| 1573 | tiled_map->xy2ba_map[i] = luma_map << 8 | chro_map; |
| 1574 | for (i = 0; i < 16; i++) |
| 1575 | tiled_map->xy2ra_map[i] = luma_map << 8 | chro_map; |
| 1576 | |
| 1577 | if (tiled_map_type == GDI_LINEAR_FRAME_MAP) { |
| 1578 | tiled_map->xy2rbc_config = 0; |
| 1579 | } else { |
| 1580 | dev_err(&ctx->dev->plat_dev->dev, "invalid map type: %d\n", |
| 1581 | tiled_map_type); |
| 1582 | return; |
| 1583 | } |
| 1584 | } |
| 1585 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1586 | static void set_default_params(struct coda_ctx *ctx) |
| 1587 | { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1588 | int max_w; |
| 1589 | int max_h; |
| 1590 | |
| 1591 | ctx->codec = &ctx->dev->devtype->codecs[0]; |
| 1592 | max_w = ctx->codec->max_w; |
| 1593 | max_h = ctx->codec->max_h; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1594 | |
| 1595 | ctx->params.codec_mode = CODA_MODE_INVALID; |
| 1596 | ctx->colorspace = V4L2_COLORSPACE_REC709; |
| 1597 | ctx->params.framerate = 30; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1598 | ctx->aborting = 0; |
| 1599 | |
| 1600 | /* Default formats for output and input queues */ |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1601 | ctx->q_data[V4L2_M2M_SRC].fourcc = ctx->codec->src_fourcc; |
| 1602 | ctx->q_data[V4L2_M2M_DST].fourcc = ctx->codec->dst_fourcc; |
| 1603 | ctx->q_data[V4L2_M2M_SRC].width = max_w; |
| 1604 | ctx->q_data[V4L2_M2M_SRC].height = max_h; |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 1605 | ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 1606 | ctx->q_data[V4L2_M2M_SRC].sizeimage = (max_w * max_h * 3) / 2; |
| 1607 | ctx->q_data[V4L2_M2M_DST].width = max_w; |
| 1608 | ctx->q_data[V4L2_M2M_DST].height = max_h; |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 1609 | ctx->q_data[V4L2_M2M_DST].bytesperline = 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1610 | ctx->q_data[V4L2_M2M_DST].sizeimage = CODA_MAX_FRAME_SIZE; |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 1611 | ctx->q_data[V4L2_M2M_SRC].rect.width = max_w; |
| 1612 | ctx->q_data[V4L2_M2M_SRC].rect.height = max_h; |
| 1613 | ctx->q_data[V4L2_M2M_DST].rect.width = max_w; |
| 1614 | ctx->q_data[V4L2_M2M_DST].rect.height = max_h; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1615 | |
| 1616 | if (ctx->dev->devtype->product == CODA_960) |
| 1617 | coda_set_tiled_map_type(ctx, GDI_LINEAR_FRAME_MAP); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | /* |
| 1621 | * Queue operations |
| 1622 | */ |
| 1623 | static int coda_queue_setup(struct vb2_queue *vq, |
| 1624 | const struct v4l2_format *fmt, |
| 1625 | unsigned int *nbuffers, unsigned int *nplanes, |
| 1626 | unsigned int sizes[], void *alloc_ctxs[]) |
| 1627 | { |
| 1628 | struct coda_ctx *ctx = vb2_get_drv_priv(vq); |
Philipp Zabel | e34db06 | 2012-08-29 08:22:00 -0300 | [diff] [blame] | 1629 | struct coda_q_data *q_data; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1630 | unsigned int size; |
| 1631 | |
Philipp Zabel | e34db06 | 2012-08-29 08:22:00 -0300 | [diff] [blame] | 1632 | q_data = get_q_data(ctx, vq->type); |
| 1633 | size = q_data->sizeimage; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1634 | |
| 1635 | *nplanes = 1; |
| 1636 | sizes[0] = size; |
| 1637 | |
| 1638 | alloc_ctxs[0] = ctx->dev->alloc_ctx; |
| 1639 | |
| 1640 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1641 | "get %d buffer(s) of size %d each.\n", *nbuffers, size); |
| 1642 | |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | static int coda_buf_prepare(struct vb2_buffer *vb) |
| 1647 | { |
| 1648 | struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
| 1649 | struct coda_q_data *q_data; |
| 1650 | |
| 1651 | q_data = get_q_data(ctx, vb->vb2_queue->type); |
| 1652 | |
| 1653 | if (vb2_plane_size(vb, 0) < q_data->sizeimage) { |
| 1654 | v4l2_warn(&ctx->dev->v4l2_dev, |
| 1655 | "%s data will not fit into plane (%lu < %lu)\n", |
| 1656 | __func__, vb2_plane_size(vb, 0), |
| 1657 | (long)q_data->sizeimage); |
| 1658 | return -EINVAL; |
| 1659 | } |
| 1660 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1661 | return 0; |
| 1662 | } |
| 1663 | |
| 1664 | static void coda_buf_queue(struct vb2_buffer *vb) |
| 1665 | { |
| 1666 | struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1667 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1668 | struct coda_q_data *q_data; |
| 1669 | |
| 1670 | q_data = get_q_data(ctx, vb->vb2_queue->type); |
| 1671 | |
| 1672 | /* |
| 1673 | * In the decoder case, immediately try to copy the buffer into the |
| 1674 | * bitstream ringbuffer and mark it as ready to be dequeued. |
| 1675 | */ |
| 1676 | if (q_data->fourcc == V4L2_PIX_FMT_H264 && |
| 1677 | vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 1678 | /* |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 1679 | * For backwards compatibility, queuing an empty buffer marks |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1680 | * the stream end |
| 1681 | */ |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1682 | if (vb2_get_plane_payload(vb, 0) == 0) { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1683 | ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1684 | if ((dev->devtype->product == CODA_960) && |
| 1685 | coda_isbusy(dev) && |
| 1686 | (ctx->idx == coda_read(dev, CODA_REG_BIT_RUN_INDEX))) { |
| 1687 | /* if this decoder instance is running, set the stream end flag */ |
| 1688 | coda_write(dev, ctx->bit_stream_param, CODA_REG_BIT_BIT_STREAM_PARAM); |
| 1689 | } |
| 1690 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1691 | mutex_lock(&ctx->bitstream_mutex); |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1692 | v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1693 | coda_fill_bitstream(ctx); |
| 1694 | mutex_unlock(&ctx->bitstream_mutex); |
| 1695 | } else { |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 1696 | v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1697 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 1698 | } |
| 1699 | |
Philipp Zabel | 86eda90 | 2013-05-23 10:42:57 -0300 | [diff] [blame] | 1700 | static void coda_parabuf_write(struct coda_ctx *ctx, int index, u32 value) |
| 1701 | { |
| 1702 | struct coda_dev *dev = ctx->dev; |
| 1703 | u32 *p = ctx->parabuf.vaddr; |
| 1704 | |
| 1705 | if (dev->devtype->product == CODA_DX6) |
| 1706 | p[index] = value; |
| 1707 | else |
| 1708 | p[index ^ 1] = value; |
| 1709 | } |
| 1710 | |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1711 | static int coda_alloc_aux_buf(struct coda_dev *dev, |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 1712 | struct coda_aux_buf *buf, size_t size, |
| 1713 | const char *name, struct dentry *parent) |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1714 | { |
| 1715 | buf->vaddr = dma_alloc_coherent(&dev->plat_dev->dev, size, &buf->paddr, |
| 1716 | GFP_KERNEL); |
| 1717 | if (!buf->vaddr) |
| 1718 | return -ENOMEM; |
| 1719 | |
| 1720 | buf->size = size; |
| 1721 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 1722 | if (name && parent) { |
| 1723 | buf->blob.data = buf->vaddr; |
| 1724 | buf->blob.size = size; |
| 1725 | buf->dentry = debugfs_create_blob(name, 0644, parent, &buf->blob); |
| 1726 | if (!buf->dentry) |
| 1727 | dev_warn(&dev->plat_dev->dev, |
| 1728 | "failed to create debugfs entry %s\n", name); |
| 1729 | } |
| 1730 | |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1731 | return 0; |
| 1732 | } |
| 1733 | |
| 1734 | static inline int coda_alloc_context_buf(struct coda_ctx *ctx, |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 1735 | struct coda_aux_buf *buf, size_t size, |
| 1736 | const char *name) |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1737 | { |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 1738 | return coda_alloc_aux_buf(ctx->dev, buf, size, name, ctx->debugfs_entry); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | static void coda_free_aux_buf(struct coda_dev *dev, |
| 1742 | struct coda_aux_buf *buf) |
| 1743 | { |
| 1744 | if (buf->vaddr) { |
| 1745 | dma_free_coherent(&dev->plat_dev->dev, buf->size, |
| 1746 | buf->vaddr, buf->paddr); |
| 1747 | buf->vaddr = NULL; |
| 1748 | buf->size = 0; |
| 1749 | } |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 1750 | debugfs_remove(buf->dentry); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | static void coda_free_framebuffers(struct coda_ctx *ctx) |
| 1754 | { |
| 1755 | int i; |
| 1756 | |
| 1757 | for (i = 0; i < CODA_MAX_FRAMEBUFFERS; i++) |
| 1758 | coda_free_aux_buf(ctx->dev, &ctx->internal_frames[i]); |
| 1759 | } |
| 1760 | |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1761 | static int coda_alloc_framebuffers(struct coda_ctx *ctx, struct coda_q_data *q_data, u32 fourcc) |
| 1762 | { |
| 1763 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 7c3df78 | 2014-07-11 06:36:38 -0300 | [diff] [blame] | 1764 | int width, height; |
Philipp Zabel | 86eda90 | 2013-05-23 10:42:57 -0300 | [diff] [blame] | 1765 | dma_addr_t paddr; |
| 1766 | int ysize; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1767 | int ret; |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1768 | int i; |
| 1769 | |
Philipp Zabel | 7c3df78 | 2014-07-11 06:36:38 -0300 | [diff] [blame] | 1770 | if (ctx->codec && (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 || |
| 1771 | ctx->codec->dst_fourcc == V4L2_PIX_FMT_H264)) { |
| 1772 | width = round_up(q_data->width, 16); |
| 1773 | height = round_up(q_data->height, 16); |
| 1774 | } else { |
| 1775 | width = round_up(q_data->width, 8); |
| 1776 | height = q_data->height; |
| 1777 | } |
| 1778 | ysize = width * height; |
Philipp Zabel | 86eda90 | 2013-05-23 10:42:57 -0300 | [diff] [blame] | 1779 | |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1780 | /* Allocate frame buffers */ |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1781 | for (i = 0; i < ctx->num_internal_frames; i++) { |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1782 | size_t size; |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 1783 | char *name; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1784 | |
Philipp Zabel | aed14b0 | 2014-07-11 06:36:15 -0300 | [diff] [blame] | 1785 | size = ysize + ysize / 2; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1786 | if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 && |
| 1787 | dev->devtype->product != CODA_DX6) |
Philipp Zabel | aed14b0 | 2014-07-11 06:36:15 -0300 | [diff] [blame] | 1788 | size += ysize / 4; |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 1789 | name = kasprintf(GFP_KERNEL, "fb%d", i); |
| 1790 | ret = coda_alloc_context_buf(ctx, &ctx->internal_frames[i], |
| 1791 | size, name); |
| 1792 | kfree(name); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1793 | if (ret < 0) { |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1794 | coda_free_framebuffers(ctx); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1795 | return ret; |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | /* Register frame buffers in the parameter buffer */ |
Philipp Zabel | 86eda90 | 2013-05-23 10:42:57 -0300 | [diff] [blame] | 1800 | for (i = 0; i < ctx->num_internal_frames; i++) { |
| 1801 | paddr = ctx->internal_frames[i].paddr; |
| 1802 | coda_parabuf_write(ctx, i * 3 + 0, paddr); /* Y */ |
| 1803 | coda_parabuf_write(ctx, i * 3 + 1, paddr + ysize); /* Cb */ |
| 1804 | coda_parabuf_write(ctx, i * 3 + 2, paddr + ysize + ysize/4); /* Cr */ |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1805 | |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1806 | /* mvcol buffer for h.264 */ |
| 1807 | if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 && |
| 1808 | dev->devtype->product != CODA_DX6) |
| 1809 | coda_parabuf_write(ctx, 96 + i, |
| 1810 | ctx->internal_frames[i].paddr + |
| 1811 | ysize + ysize/4 + ysize/4); |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1812 | } |
| 1813 | |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1814 | /* mvcol buffer for mpeg4 */ |
| 1815 | if ((dev->devtype->product != CODA_DX6) && |
| 1816 | (ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4)) |
| 1817 | coda_parabuf_write(ctx, 97, ctx->internal_frames[i].paddr + |
| 1818 | ysize + ysize/4 + ysize/4); |
| 1819 | |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 1820 | return 0; |
| 1821 | } |
| 1822 | |
Javier Martin | 3f3f5c7 | 2012-10-29 05:20:29 -0300 | [diff] [blame] | 1823 | static int coda_h264_padding(int size, char *p) |
| 1824 | { |
Javier Martin | 3f3f5c7 | 2012-10-29 05:20:29 -0300 | [diff] [blame] | 1825 | int nal_size; |
| 1826 | int diff; |
| 1827 | |
Javier Martin | 832fbb5 | 2012-10-29 08:34:59 -0300 | [diff] [blame] | 1828 | diff = size - (size & ~0x7); |
Javier Martin | 3f3f5c7 | 2012-10-29 05:20:29 -0300 | [diff] [blame] | 1829 | if (diff == 0) |
| 1830 | return 0; |
| 1831 | |
Javier Martin | 832fbb5 | 2012-10-29 08:34:59 -0300 | [diff] [blame] | 1832 | nal_size = coda_filler_size[diff]; |
Javier Martin | 3f3f5c7 | 2012-10-29 05:20:29 -0300 | [diff] [blame] | 1833 | memcpy(p, coda_filler_nal, nal_size); |
| 1834 | |
| 1835 | /* Add rbsp stop bit and trailing at the end */ |
| 1836 | *(p + nal_size - 1) = 0x80; |
| 1837 | |
| 1838 | return nal_size; |
| 1839 | } |
| 1840 | |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1841 | static phys_addr_t coda_iram_alloc(struct coda_iram_info *iram, size_t size) |
| 1842 | { |
| 1843 | phys_addr_t ret; |
| 1844 | |
| 1845 | size = round_up(size, 1024); |
| 1846 | if (size > iram->remaining) |
| 1847 | return 0; |
| 1848 | iram->remaining -= size; |
| 1849 | |
| 1850 | ret = iram->next_paddr; |
| 1851 | iram->next_paddr += size; |
| 1852 | |
| 1853 | return ret; |
| 1854 | } |
| 1855 | |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1856 | static void coda_setup_iram(struct coda_ctx *ctx) |
| 1857 | { |
| 1858 | struct coda_iram_info *iram_info = &ctx->iram_info; |
| 1859 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1860 | int mb_width; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1861 | int dbk_bits; |
| 1862 | int bit_bits; |
| 1863 | int ip_bits; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1864 | |
| 1865 | memset(iram_info, 0, sizeof(*iram_info)); |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1866 | iram_info->next_paddr = dev->iram.paddr; |
| 1867 | iram_info->remaining = dev->iram.size; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1868 | |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1869 | switch (dev->devtype->product) { |
| 1870 | case CODA_7541: |
| 1871 | dbk_bits = CODA7_USE_HOST_DBK_ENABLE | CODA7_USE_DBK_ENABLE; |
| 1872 | bit_bits = CODA7_USE_HOST_BIT_ENABLE | CODA7_USE_BIT_ENABLE; |
| 1873 | ip_bits = CODA7_USE_HOST_IP_ENABLE | CODA7_USE_IP_ENABLE; |
| 1874 | break; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1875 | case CODA_960: |
| 1876 | dbk_bits = CODA9_USE_HOST_DBK_ENABLE | CODA9_USE_DBK_ENABLE; |
| 1877 | bit_bits = CODA9_USE_HOST_BIT_ENABLE | CODA7_USE_BIT_ENABLE; |
| 1878 | ip_bits = CODA9_USE_HOST_IP_ENABLE | CODA7_USE_IP_ENABLE; |
| 1879 | break; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1880 | default: /* CODA_DX6 */ |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1881 | return; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1882 | } |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1883 | |
| 1884 | if (ctx->inst_type == CODA_INST_ENCODER) { |
| 1885 | struct coda_q_data *q_data_src; |
| 1886 | |
| 1887 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 1888 | mb_width = DIV_ROUND_UP(q_data_src->width, 16); |
| 1889 | |
| 1890 | /* Prioritize in case IRAM is too small for everything */ |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1891 | if (dev->devtype->product == CODA_7541) { |
| 1892 | iram_info->search_ram_size = round_up(mb_width * 16 * |
| 1893 | 36 + 2048, 1024); |
| 1894 | iram_info->search_ram_paddr = coda_iram_alloc(iram_info, |
| 1895 | iram_info->search_ram_size); |
| 1896 | if (!iram_info->search_ram_paddr) { |
| 1897 | pr_err("IRAM is smaller than the search ram size\n"); |
| 1898 | goto out; |
| 1899 | } |
| 1900 | iram_info->axi_sram_use |= CODA7_USE_HOST_ME_ENABLE | |
| 1901 | CODA7_USE_ME_ENABLE; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | /* Only H.264BP and H.263P3 are considered */ |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1905 | iram_info->buf_dbk_y_use = coda_iram_alloc(iram_info, 64 * mb_width); |
| 1906 | iram_info->buf_dbk_c_use = coda_iram_alloc(iram_info, 64 * mb_width); |
| 1907 | if (!iram_info->buf_dbk_c_use) |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1908 | goto out; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1909 | iram_info->axi_sram_use |= dbk_bits; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1910 | |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1911 | iram_info->buf_bit_use = coda_iram_alloc(iram_info, 128 * mb_width); |
| 1912 | if (!iram_info->buf_bit_use) |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1913 | goto out; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1914 | iram_info->axi_sram_use |= bit_bits; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1915 | |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1916 | iram_info->buf_ip_ac_dc_use = coda_iram_alloc(iram_info, 128 * mb_width); |
| 1917 | if (!iram_info->buf_ip_ac_dc_use) |
| 1918 | goto out; |
| 1919 | iram_info->axi_sram_use |= ip_bits; |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1920 | |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1921 | /* OVL and BTP disabled for encoder */ |
| 1922 | } else if (ctx->inst_type == CODA_INST_DECODER) { |
| 1923 | struct coda_q_data *q_data_dst; |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1924 | |
| 1925 | q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
| 1926 | mb_width = DIV_ROUND_UP(q_data_dst->width, 16); |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1927 | |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1928 | iram_info->buf_dbk_y_use = coda_iram_alloc(iram_info, 128 * mb_width); |
| 1929 | iram_info->buf_dbk_c_use = coda_iram_alloc(iram_info, 128 * mb_width); |
| 1930 | if (!iram_info->buf_dbk_c_use) |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1931 | goto out; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1932 | iram_info->axi_sram_use |= dbk_bits; |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1933 | |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1934 | iram_info->buf_bit_use = coda_iram_alloc(iram_info, 128 * mb_width); |
| 1935 | if (!iram_info->buf_bit_use) |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1936 | goto out; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1937 | iram_info->axi_sram_use |= bit_bits; |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1938 | |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1939 | iram_info->buf_ip_ac_dc_use = coda_iram_alloc(iram_info, 128 * mb_width); |
| 1940 | if (!iram_info->buf_ip_ac_dc_use) |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1941 | goto out; |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1942 | iram_info->axi_sram_use |= ip_bits; |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1943 | |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 1944 | /* OVL and BTP unused as there is no VC1 support yet */ |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | out: |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1948 | if (!(iram_info->axi_sram_use & CODA7_USE_HOST_IP_ENABLE)) |
| 1949 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 1950 | "IRAM smaller than needed\n"); |
| 1951 | |
| 1952 | if (dev->devtype->product == CODA_7541) { |
| 1953 | /* TODO - Enabling these causes picture errors on CODA7541 */ |
Philipp Zabel | 8358e76 | 2013-06-21 03:55:32 -0300 | [diff] [blame] | 1954 | if (ctx->inst_type == CODA_INST_DECODER) { |
| 1955 | /* fw 1.4.50 */ |
| 1956 | iram_info->axi_sram_use &= ~(CODA7_USE_HOST_IP_ENABLE | |
| 1957 | CODA7_USE_IP_ENABLE); |
| 1958 | } else { |
| 1959 | /* fw 13.4.29 */ |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 1960 | iram_info->axi_sram_use &= ~(CODA7_USE_HOST_IP_ENABLE | |
| 1961 | CODA7_USE_HOST_DBK_ENABLE | |
| 1962 | CODA7_USE_IP_ENABLE | |
| 1963 | CODA7_USE_DBK_ENABLE); |
| 1964 | } |
| 1965 | } |
| 1966 | } |
| 1967 | |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1968 | static void coda_free_context_buffers(struct coda_ctx *ctx) |
| 1969 | { |
| 1970 | struct coda_dev *dev = ctx->dev; |
| 1971 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1972 | coda_free_aux_buf(dev, &ctx->slicebuf); |
| 1973 | coda_free_aux_buf(dev, &ctx->psbuf); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1974 | if (dev->devtype->product != CODA_DX6) |
| 1975 | coda_free_aux_buf(dev, &ctx->workbuf); |
| 1976 | } |
| 1977 | |
| 1978 | static int coda_alloc_context_buffers(struct coda_ctx *ctx, |
| 1979 | struct coda_q_data *q_data) |
| 1980 | { |
| 1981 | struct coda_dev *dev = ctx->dev; |
| 1982 | size_t size; |
| 1983 | int ret; |
| 1984 | |
| 1985 | switch (dev->devtype->product) { |
| 1986 | case CODA_7541: |
| 1987 | size = CODA7_WORK_BUF_SIZE; |
| 1988 | break; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 1989 | case CODA_960: |
| 1990 | size = CODA9_WORK_BUF_SIZE; |
| 1991 | if (q_data->fourcc == V4L2_PIX_FMT_H264) |
| 1992 | size += CODA9_PS_SAVE_SIZE; |
| 1993 | break; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 1994 | default: |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 1998 | if (ctx->psbuf.vaddr) { |
| 1999 | v4l2_err(&dev->v4l2_dev, "psmembuf still allocated\n"); |
| 2000 | return -EBUSY; |
| 2001 | } |
| 2002 | if (ctx->slicebuf.vaddr) { |
| 2003 | v4l2_err(&dev->v4l2_dev, "slicebuf still allocated\n"); |
| 2004 | return -EBUSY; |
| 2005 | } |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 2006 | if (ctx->workbuf.vaddr) { |
| 2007 | v4l2_err(&dev->v4l2_dev, "context buffer still allocated\n"); |
| 2008 | ret = -EBUSY; |
| 2009 | return -ENOMEM; |
| 2010 | } |
| 2011 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2012 | if (q_data->fourcc == V4L2_PIX_FMT_H264) { |
| 2013 | /* worst case slice size */ |
| 2014 | size = (DIV_ROUND_UP(q_data->width, 16) * |
| 2015 | DIV_ROUND_UP(q_data->height, 16)) * 3200 / 8 + 512; |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 2016 | ret = coda_alloc_context_buf(ctx, &ctx->slicebuf, size, "slicebuf"); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2017 | if (ret < 0) { |
| 2018 | v4l2_err(&dev->v4l2_dev, "failed to allocate %d byte slice buffer", |
| 2019 | ctx->slicebuf.size); |
| 2020 | return ret; |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | if (dev->devtype->product == CODA_7541) { |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 2025 | ret = coda_alloc_context_buf(ctx, &ctx->psbuf, CODA7_PS_BUF_SIZE, "psbuf"); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2026 | if (ret < 0) { |
| 2027 | v4l2_err(&dev->v4l2_dev, "failed to allocate psmem buffer"); |
| 2028 | goto err; |
| 2029 | } |
| 2030 | } |
| 2031 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 2032 | ret = coda_alloc_context_buf(ctx, &ctx->workbuf, size, "workbuf"); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 2033 | if (ret < 0) { |
| 2034 | v4l2_err(&dev->v4l2_dev, "failed to allocate %d byte context buffer", |
| 2035 | ctx->workbuf.size); |
| 2036 | goto err; |
| 2037 | } |
| 2038 | |
| 2039 | return 0; |
| 2040 | |
| 2041 | err: |
| 2042 | coda_free_context_buffers(ctx); |
| 2043 | return ret; |
| 2044 | } |
| 2045 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2046 | static int coda_start_decoding(struct coda_ctx *ctx) |
| 2047 | { |
| 2048 | struct coda_q_data *q_data_src, *q_data_dst; |
| 2049 | u32 bitstream_buf, bitstream_size; |
| 2050 | struct coda_dev *dev = ctx->dev; |
| 2051 | int width, height; |
| 2052 | u32 src_fourcc; |
| 2053 | u32 val; |
| 2054 | int ret; |
| 2055 | |
| 2056 | /* Start decoding */ |
| 2057 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 2058 | q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
| 2059 | bitstream_buf = ctx->bitstream.paddr; |
| 2060 | bitstream_size = ctx->bitstream.size; |
| 2061 | src_fourcc = q_data_src->fourcc; |
| 2062 | |
| 2063 | coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); |
| 2064 | |
| 2065 | /* Update coda bitstream read and write pointers from kfifo */ |
| 2066 | coda_kfifo_sync_to_device_full(ctx); |
| 2067 | |
| 2068 | ctx->display_idx = -1; |
| 2069 | ctx->frm_dis_flg = 0; |
| 2070 | coda_write(dev, 0, CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); |
| 2071 | |
| 2072 | coda_write(dev, CODA_BIT_DEC_SEQ_INIT_ESCAPE, |
| 2073 | CODA_REG_BIT_BIT_STREAM_PARAM); |
| 2074 | |
| 2075 | coda_write(dev, bitstream_buf, CODA_CMD_DEC_SEQ_BB_START); |
| 2076 | coda_write(dev, bitstream_size / 1024, CODA_CMD_DEC_SEQ_BB_SIZE); |
| 2077 | val = 0; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2078 | if ((dev->devtype->product == CODA_7541) || |
| 2079 | (dev->devtype->product == CODA_960)) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2080 | val |= CODA_REORDER_ENABLE; |
| 2081 | coda_write(dev, val, CODA_CMD_DEC_SEQ_OPTION); |
| 2082 | |
| 2083 | ctx->params.codec_mode = ctx->codec->mode; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2084 | if (dev->devtype->product == CODA_960 && |
| 2085 | src_fourcc == V4L2_PIX_FMT_MPEG4) |
| 2086 | ctx->params.codec_mode_aux = CODA_MP4_AUX_MPEG4; |
| 2087 | else |
| 2088 | ctx->params.codec_mode_aux = 0; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2089 | if (src_fourcc == V4L2_PIX_FMT_H264) { |
| 2090 | if (dev->devtype->product == CODA_7541) { |
| 2091 | coda_write(dev, ctx->psbuf.paddr, |
| 2092 | CODA_CMD_DEC_SEQ_PS_BB_START); |
| 2093 | coda_write(dev, (CODA7_PS_BUF_SIZE / 1024), |
| 2094 | CODA_CMD_DEC_SEQ_PS_BB_SIZE); |
| 2095 | } |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2096 | if (dev->devtype->product == CODA_960) { |
| 2097 | coda_write(dev, 0, CODA_CMD_DEC_SEQ_X264_MV_EN); |
| 2098 | coda_write(dev, 512, CODA_CMD_DEC_SEQ_SPP_CHUNK_SIZE); |
| 2099 | } |
| 2100 | } |
| 2101 | if (dev->devtype->product != CODA_960) { |
| 2102 | coda_write(dev, 0, CODA_CMD_DEC_SEQ_SRC_SIZE); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | if (coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT)) { |
| 2106 | v4l2_err(&dev->v4l2_dev, "CODA_COMMAND_SEQ_INIT timeout\n"); |
| 2107 | coda_write(dev, 0, CODA_REG_BIT_BIT_STREAM_PARAM); |
| 2108 | return -ETIMEDOUT; |
| 2109 | } |
| 2110 | |
| 2111 | /* Update kfifo out pointer from coda bitstream read pointer */ |
| 2112 | coda_kfifo_sync_from_device(ctx); |
| 2113 | |
| 2114 | coda_write(dev, 0, CODA_REG_BIT_BIT_STREAM_PARAM); |
| 2115 | |
| 2116 | if (coda_read(dev, CODA_RET_DEC_SEQ_SUCCESS) == 0) { |
| 2117 | v4l2_err(&dev->v4l2_dev, |
| 2118 | "CODA_COMMAND_SEQ_INIT failed, error code = %d\n", |
| 2119 | coda_read(dev, CODA_RET_DEC_SEQ_ERR_REASON)); |
| 2120 | return -EAGAIN; |
| 2121 | } |
| 2122 | |
| 2123 | val = coda_read(dev, CODA_RET_DEC_SEQ_SRC_SIZE); |
| 2124 | if (dev->devtype->product == CODA_DX6) { |
| 2125 | width = (val >> CODADX6_PICWIDTH_OFFSET) & CODADX6_PICWIDTH_MASK; |
| 2126 | height = val & CODADX6_PICHEIGHT_MASK; |
| 2127 | } else { |
| 2128 | width = (val >> CODA7_PICWIDTH_OFFSET) & CODA7_PICWIDTH_MASK; |
| 2129 | height = val & CODA7_PICHEIGHT_MASK; |
| 2130 | } |
| 2131 | |
| 2132 | if (width > q_data_dst->width || height > q_data_dst->height) { |
| 2133 | v4l2_err(&dev->v4l2_dev, "stream is %dx%d, not %dx%d\n", |
| 2134 | width, height, q_data_dst->width, q_data_dst->height); |
| 2135 | return -EINVAL; |
| 2136 | } |
| 2137 | |
| 2138 | width = round_up(width, 16); |
| 2139 | height = round_up(height, 16); |
| 2140 | |
| 2141 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "%s instance %d now: %dx%d\n", |
| 2142 | __func__, ctx->idx, width, height); |
| 2143 | |
Philipp Zabel | a500a93 | 2014-07-11 06:36:13 -0300 | [diff] [blame] | 2144 | ctx->num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2145 | if (ctx->num_internal_frames > CODA_MAX_FRAMEBUFFERS) { |
| 2146 | v4l2_err(&dev->v4l2_dev, |
| 2147 | "not enough framebuffers to decode (%d < %d)\n", |
| 2148 | CODA_MAX_FRAMEBUFFERS, ctx->num_internal_frames); |
| 2149 | return -EINVAL; |
| 2150 | } |
| 2151 | |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 2152 | if (src_fourcc == V4L2_PIX_FMT_H264) { |
| 2153 | u32 left_right; |
| 2154 | u32 top_bottom; |
| 2155 | |
| 2156 | left_right = coda_read(dev, CODA_RET_DEC_SEQ_CROP_LEFT_RIGHT); |
| 2157 | top_bottom = coda_read(dev, CODA_RET_DEC_SEQ_CROP_TOP_BOTTOM); |
| 2158 | |
| 2159 | q_data_dst->rect.left = (left_right >> 10) & 0x3ff; |
| 2160 | q_data_dst->rect.top = (top_bottom >> 10) & 0x3ff; |
| 2161 | q_data_dst->rect.width = width - q_data_dst->rect.left - |
| 2162 | (left_right & 0x3ff); |
| 2163 | q_data_dst->rect.height = height - q_data_dst->rect.top - |
| 2164 | (top_bottom & 0x3ff); |
| 2165 | } |
| 2166 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2167 | ret = coda_alloc_framebuffers(ctx, q_data_dst, src_fourcc); |
| 2168 | if (ret < 0) |
| 2169 | return ret; |
| 2170 | |
| 2171 | /* Tell the decoder how many frame buffers we allocated. */ |
| 2172 | coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM); |
| 2173 | coda_write(dev, width, CODA_CMD_SET_FRAME_BUF_STRIDE); |
| 2174 | |
| 2175 | if (dev->devtype->product != CODA_DX6) { |
| 2176 | /* Set secondary AXI IRAM */ |
| 2177 | coda_setup_iram(ctx); |
| 2178 | |
| 2179 | coda_write(dev, ctx->iram_info.buf_bit_use, |
| 2180 | CODA7_CMD_SET_FRAME_AXI_BIT_ADDR); |
| 2181 | coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, |
| 2182 | CODA7_CMD_SET_FRAME_AXI_IPACDC_ADDR); |
| 2183 | coda_write(dev, ctx->iram_info.buf_dbk_y_use, |
| 2184 | CODA7_CMD_SET_FRAME_AXI_DBKY_ADDR); |
| 2185 | coda_write(dev, ctx->iram_info.buf_dbk_c_use, |
| 2186 | CODA7_CMD_SET_FRAME_AXI_DBKC_ADDR); |
| 2187 | coda_write(dev, ctx->iram_info.buf_ovl_use, |
| 2188 | CODA7_CMD_SET_FRAME_AXI_OVL_ADDR); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2189 | if (dev->devtype->product == CODA_960) |
| 2190 | coda_write(dev, ctx->iram_info.buf_btp_use, |
| 2191 | CODA9_CMD_SET_FRAME_AXI_BTP_ADDR); |
| 2192 | } |
| 2193 | |
| 2194 | if (dev->devtype->product == CODA_960) { |
| 2195 | coda_write(dev, -1, CODA9_CMD_SET_FRAME_DELAY); |
| 2196 | |
| 2197 | coda_write(dev, 0x20262024, CODA9_CMD_SET_FRAME_CACHE_SIZE); |
| 2198 | coda_write(dev, 2 << CODA9_CACHE_PAGEMERGE_OFFSET | |
| 2199 | 32 << CODA9_CACHE_LUMA_BUFFER_SIZE_OFFSET | |
| 2200 | 8 << CODA9_CACHE_CB_BUFFER_SIZE_OFFSET | |
| 2201 | 8 << CODA9_CACHE_CR_BUFFER_SIZE_OFFSET, |
| 2202 | CODA9_CMD_SET_FRAME_CACHE_CONFIG); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | if (src_fourcc == V4L2_PIX_FMT_H264) { |
| 2206 | coda_write(dev, ctx->slicebuf.paddr, |
| 2207 | CODA_CMD_SET_FRAME_SLICE_BB_START); |
| 2208 | coda_write(dev, ctx->slicebuf.size / 1024, |
| 2209 | CODA_CMD_SET_FRAME_SLICE_BB_SIZE); |
| 2210 | } |
| 2211 | |
| 2212 | if (dev->devtype->product == CODA_7541) { |
| 2213 | int max_mb_x = 1920 / 16; |
| 2214 | int max_mb_y = 1088 / 16; |
| 2215 | int max_mb_num = max_mb_x * max_mb_y; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2216 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2217 | coda_write(dev, max_mb_num << 16 | max_mb_x << 8 | max_mb_y, |
| 2218 | CODA7_CMD_SET_FRAME_MAX_DEC_SIZE); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2219 | } else if (dev->devtype->product == CODA_960) { |
| 2220 | int max_mb_x = 1920 / 16; |
| 2221 | int max_mb_y = 1088 / 16; |
| 2222 | int max_mb_num = max_mb_x * max_mb_y; |
| 2223 | |
| 2224 | coda_write(dev, max_mb_num << 16 | max_mb_x << 8 | max_mb_y, |
| 2225 | CODA9_CMD_SET_FRAME_MAX_DEC_SIZE); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | if (coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF)) { |
| 2229 | v4l2_err(&ctx->dev->v4l2_dev, |
| 2230 | "CODA_COMMAND_SET_FRAME_BUF timeout\n"); |
| 2231 | return -ETIMEDOUT; |
| 2232 | } |
| 2233 | |
| 2234 | return 0; |
| 2235 | } |
| 2236 | |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2237 | static int coda_encode_header(struct coda_ctx *ctx, struct vb2_buffer *buf, |
| 2238 | int header_code, u8 *header, int *size) |
| 2239 | { |
| 2240 | struct coda_dev *dev = ctx->dev; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2241 | size_t bufsize; |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2242 | int ret; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2243 | int i; |
| 2244 | |
| 2245 | if (dev->devtype->product == CODA_960) |
| 2246 | memset(vb2_plane_vaddr(buf, 0), 0, 64); |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2247 | |
| 2248 | coda_write(dev, vb2_dma_contig_plane_dma_addr(buf, 0), |
| 2249 | CODA_CMD_ENC_HEADER_BB_START); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2250 | bufsize = vb2_plane_size(buf, 0); |
| 2251 | if (dev->devtype->product == CODA_960) |
| 2252 | bufsize /= 1024; |
| 2253 | coda_write(dev, bufsize, CODA_CMD_ENC_HEADER_BB_SIZE); |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2254 | coda_write(dev, header_code, CODA_CMD_ENC_HEADER_CODE); |
| 2255 | ret = coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER); |
| 2256 | if (ret < 0) { |
| 2257 | v4l2_err(&dev->v4l2_dev, "CODA_COMMAND_ENCODE_HEADER timeout\n"); |
| 2258 | return ret; |
| 2259 | } |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2260 | |
| 2261 | if (dev->devtype->product == CODA_960) { |
| 2262 | for (i = 63; i > 0; i--) |
| 2263 | if (((char *)vb2_plane_vaddr(buf, 0))[i] != 0) |
| 2264 | break; |
| 2265 | *size = i + 1; |
| 2266 | } else { |
| 2267 | *size = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)) - |
| 2268 | coda_read(dev, CODA_CMD_ENC_HEADER_BB_START); |
| 2269 | } |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2270 | memcpy(header, vb2_plane_vaddr(buf, 0), *size); |
| 2271 | |
| 2272 | return 0; |
| 2273 | } |
| 2274 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2275 | static int coda_start_encoding(struct coda_ctx *ctx); |
| 2276 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2277 | static int coda_start_streaming(struct vb2_queue *q, unsigned int count) |
| 2278 | { |
| 2279 | struct coda_ctx *ctx = vb2_get_drv_priv(q); |
| 2280 | struct v4l2_device *v4l2_dev = &ctx->dev->v4l2_dev; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2281 | struct coda_dev *dev = ctx->dev; |
| 2282 | struct coda_q_data *q_data_src, *q_data_dst; |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 2283 | u32 dst_fourcc; |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2284 | int ret = 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2285 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2286 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2287 | if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
| 2288 | if (q_data_src->fourcc == V4L2_PIX_FMT_H264) { |
| 2289 | if (coda_get_bitstream_payload(ctx) < 512) |
| 2290 | return -EINVAL; |
| 2291 | } else { |
| 2292 | if (count < 1) |
| 2293 | return -EINVAL; |
| 2294 | } |
| 2295 | |
| 2296 | ctx->streamon_out = 1; |
| 2297 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2298 | if (coda_format_is_yuv(q_data_src->fourcc)) |
| 2299 | ctx->inst_type = CODA_INST_ENCODER; |
| 2300 | else |
| 2301 | ctx->inst_type = CODA_INST_DECODER; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2302 | } else { |
| 2303 | if (count < 1) |
| 2304 | return -EINVAL; |
| 2305 | |
| 2306 | ctx->streamon_cap = 1; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2307 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2308 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2309 | /* Don't start the coda unless both queues are on */ |
| 2310 | if (!(ctx->streamon_out & ctx->streamon_cap)) |
| 2311 | return 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2312 | |
Philipp Zabel | eb10751 | 2013-09-30 10:34:45 -0300 | [diff] [blame] | 2313 | /* Allow decoder device_run with no new buffers queued */ |
| 2314 | if (ctx->inst_type == CODA_INST_DECODER) |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 2315 | v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2316 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2317 | ctx->gopcounter = ctx->params.gop_size - 1; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2318 | q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2319 | dst_fourcc = q_data_dst->fourcc; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2320 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2321 | ctx->codec = coda_find_codec(ctx->dev, q_data_src->fourcc, |
| 2322 | q_data_dst->fourcc); |
| 2323 | if (!ctx->codec) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2324 | v4l2_err(v4l2_dev, "couldn't tell instance type.\n"); |
| 2325 | return -EINVAL; |
| 2326 | } |
| 2327 | |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 2328 | /* Allocate per-instance buffers */ |
| 2329 | ret = coda_alloc_context_buffers(ctx, q_data_src); |
| 2330 | if (ret < 0) |
| 2331 | return ret; |
| 2332 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2333 | if (ctx->inst_type == CODA_INST_DECODER) { |
| 2334 | mutex_lock(&dev->coda_mutex); |
| 2335 | ret = coda_start_decoding(ctx); |
| 2336 | mutex_unlock(&dev->coda_mutex); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2337 | if (ret == -EAGAIN) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2338 | return 0; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2339 | else if (ret < 0) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2340 | return ret; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2341 | } else { |
| 2342 | ret = coda_start_encoding(ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2343 | } |
| 2344 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2345 | ctx->initialized = 1; |
| 2346 | return ret; |
| 2347 | } |
| 2348 | |
| 2349 | static int coda_start_encoding(struct coda_ctx *ctx) |
| 2350 | { |
| 2351 | struct coda_dev *dev = ctx->dev; |
| 2352 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; |
| 2353 | struct coda_q_data *q_data_src, *q_data_dst; |
| 2354 | u32 bitstream_buf, bitstream_size; |
| 2355 | struct vb2_buffer *buf; |
| 2356 | int gamma, ret, value; |
| 2357 | u32 dst_fourcc; |
| 2358 | |
| 2359 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 2360 | q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
| 2361 | dst_fourcc = q_data_dst->fourcc; |
| 2362 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 2363 | buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2364 | bitstream_buf = vb2_dma_contig_plane_dma_addr(buf, 0); |
| 2365 | bitstream_size = q_data_dst->sizeimage; |
| 2366 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2367 | if (!coda_is_initialized(dev)) { |
| 2368 | v4l2_err(v4l2_dev, "coda is not initialized.\n"); |
| 2369 | return -EFAULT; |
| 2370 | } |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2371 | |
| 2372 | mutex_lock(&dev->coda_mutex); |
| 2373 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2374 | coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 2375 | coda_write(dev, bitstream_buf, CODA_REG_BIT_RD_PTR(ctx->reg_idx)); |
| 2376 | coda_write(dev, bitstream_buf, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2377 | switch (dev->devtype->product) { |
| 2378 | case CODA_DX6: |
| 2379 | coda_write(dev, CODADX6_STREAM_BUF_DYNALLOC_EN | |
| 2380 | CODADX6_STREAM_BUF_PIC_RESET, CODA_REG_BIT_STREAM_CTRL); |
| 2381 | break; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2382 | case CODA_960: |
| 2383 | coda_write(dev, 0, CODA9_GDI_WPROT_RGN_EN); |
| 2384 | /* fallthrough */ |
| 2385 | case CODA_7541: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2386 | coda_write(dev, CODA7_STREAM_BUF_DYNALLOC_EN | |
| 2387 | CODA7_STREAM_BUF_PIC_RESET, CODA_REG_BIT_STREAM_CTRL); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2388 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2389 | } |
| 2390 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2391 | value = coda_read(dev, CODA_REG_BIT_FRAME_MEM_CTRL); |
| 2392 | value &= ~(1 << 2 | 0x7 << 9); |
| 2393 | ctx->frame_mem_ctrl = value; |
| 2394 | coda_write(dev, value, CODA_REG_BIT_FRAME_MEM_CTRL); |
| 2395 | |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 2396 | if (dev->devtype->product == CODA_DX6) { |
| 2397 | /* Configure the coda */ |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 2398 | coda_write(dev, dev->iram.paddr, CODADX6_REG_BIT_SEARCH_RAM_BASE_ADDR); |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 2399 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2400 | |
| 2401 | /* Could set rotation here if needed */ |
| 2402 | switch (dev->devtype->product) { |
| 2403 | case CODA_DX6: |
| 2404 | value = (q_data_src->width & CODADX6_PICWIDTH_MASK) << CODADX6_PICWIDTH_OFFSET; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2405 | value |= (q_data_src->height & CODADX6_PICHEIGHT_MASK) << CODA_PICHEIGHT_OFFSET; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2406 | break; |
Philipp Zabel | 7c3df78 | 2014-07-11 06:36:38 -0300 | [diff] [blame] | 2407 | case CODA_7541: |
| 2408 | if (dst_fourcc == V4L2_PIX_FMT_H264) { |
| 2409 | value = (round_up(q_data_src->width, 16) & |
| 2410 | CODA7_PICWIDTH_MASK) << CODA7_PICWIDTH_OFFSET; |
| 2411 | value |= (round_up(q_data_src->height, 16) & |
| 2412 | CODA7_PICHEIGHT_MASK) << CODA_PICHEIGHT_OFFSET; |
| 2413 | break; |
| 2414 | } |
| 2415 | /* fallthrough */ |
| 2416 | case CODA_960: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2417 | value = (q_data_src->width & CODA7_PICWIDTH_MASK) << CODA7_PICWIDTH_OFFSET; |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2418 | value |= (q_data_src->height & CODA7_PICHEIGHT_MASK) << CODA_PICHEIGHT_OFFSET; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2419 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2420 | coda_write(dev, value, CODA_CMD_ENC_SEQ_SRC_SIZE); |
| 2421 | coda_write(dev, ctx->params.framerate, |
| 2422 | CODA_CMD_ENC_SEQ_SRC_F_RATE); |
| 2423 | |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2424 | ctx->params.codec_mode = ctx->codec->mode; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2425 | switch (dst_fourcc) { |
| 2426 | case V4L2_PIX_FMT_MPEG4: |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2427 | if (dev->devtype->product == CODA_960) |
| 2428 | coda_write(dev, CODA9_STD_MPEG4, CODA_CMD_ENC_SEQ_COD_STD); |
| 2429 | else |
| 2430 | coda_write(dev, CODA_STD_MPEG4, CODA_CMD_ENC_SEQ_COD_STD); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2431 | coda_write(dev, 0, CODA_CMD_ENC_SEQ_MP4_PARA); |
| 2432 | break; |
| 2433 | case V4L2_PIX_FMT_H264: |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2434 | if (dev->devtype->product == CODA_960) |
| 2435 | coda_write(dev, CODA9_STD_H264, CODA_CMD_ENC_SEQ_COD_STD); |
| 2436 | else |
| 2437 | coda_write(dev, CODA_STD_H264, CODA_CMD_ENC_SEQ_COD_STD); |
Philipp Zabel | de23b1d | 2014-07-11 06:36:27 -0300 | [diff] [blame] | 2438 | if (ctx->params.h264_deblk_enabled) { |
| 2439 | value = ((ctx->params.h264_deblk_alpha & |
| 2440 | CODA_264PARAM_DEBLKFILTEROFFSETALPHA_MASK) << |
| 2441 | CODA_264PARAM_DEBLKFILTEROFFSETALPHA_OFFSET) | |
| 2442 | ((ctx->params.h264_deblk_beta & |
| 2443 | CODA_264PARAM_DEBLKFILTEROFFSETBETA_MASK) << |
| 2444 | CODA_264PARAM_DEBLKFILTEROFFSETBETA_OFFSET); |
| 2445 | } else { |
| 2446 | value = 1 << CODA_264PARAM_DISABLEDEBLK_OFFSET; |
| 2447 | } |
| 2448 | coda_write(dev, value, CODA_CMD_ENC_SEQ_264_PARA); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2449 | break; |
| 2450 | default: |
| 2451 | v4l2_err(v4l2_dev, |
| 2452 | "dst format (0x%08x) invalid.\n", dst_fourcc); |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2453 | ret = -EINVAL; |
| 2454 | goto out; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2455 | } |
| 2456 | |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 2457 | switch (ctx->params.slice_mode) { |
| 2458 | case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE: |
| 2459 | value = 0; |
| 2460 | break; |
| 2461 | case V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB: |
| 2462 | value = (ctx->params.slice_max_mb & CODA_SLICING_SIZE_MASK) << CODA_SLICING_SIZE_OFFSET; |
| 2463 | value |= (1 & CODA_SLICING_UNIT_MASK) << CODA_SLICING_UNIT_OFFSET; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2464 | value |= 1 & CODA_SLICING_MODE_MASK; |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 2465 | break; |
| 2466 | case V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES: |
| 2467 | value = (ctx->params.slice_max_bits & CODA_SLICING_SIZE_MASK) << CODA_SLICING_SIZE_OFFSET; |
| 2468 | value |= (0 & CODA_SLICING_UNIT_MASK) << CODA_SLICING_UNIT_OFFSET; |
| 2469 | value |= 1 & CODA_SLICING_MODE_MASK; |
| 2470 | break; |
| 2471 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2472 | coda_write(dev, value, CODA_CMD_ENC_SEQ_SLICE_MODE); |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 2473 | value = ctx->params.gop_size & CODA_GOP_SIZE_MASK; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2474 | coda_write(dev, value, CODA_CMD_ENC_SEQ_GOP_SIZE); |
| 2475 | |
| 2476 | if (ctx->params.bitrate) { |
| 2477 | /* Rate control enabled */ |
| 2478 | value = (ctx->params.bitrate & CODA_RATECONTROL_BITRATE_MASK) << CODA_RATECONTROL_BITRATE_OFFSET; |
| 2479 | value |= 1 & CODA_RATECONTROL_ENABLE_MASK; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2480 | if (dev->devtype->product == CODA_960) |
| 2481 | value |= BIT(31); /* disable autoskip */ |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2482 | } else { |
| 2483 | value = 0; |
| 2484 | } |
| 2485 | coda_write(dev, value, CODA_CMD_ENC_SEQ_RC_PARA); |
| 2486 | |
| 2487 | coda_write(dev, 0, CODA_CMD_ENC_SEQ_RC_BUF_SIZE); |
Philipp Zabel | f38f79d5 | 2014-07-11 06:36:28 -0300 | [diff] [blame] | 2488 | coda_write(dev, ctx->params.intra_refresh, |
| 2489 | CODA_CMD_ENC_SEQ_INTRA_REFRESH); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2490 | |
| 2491 | coda_write(dev, bitstream_buf, CODA_CMD_ENC_SEQ_BB_START); |
| 2492 | coda_write(dev, bitstream_size / 1024, CODA_CMD_ENC_SEQ_BB_SIZE); |
| 2493 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2494 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2495 | value = 0; |
| 2496 | if (dev->devtype->product == CODA_960) |
| 2497 | gamma = CODA9_DEFAULT_GAMMA; |
| 2498 | else |
| 2499 | gamma = CODA_DEFAULT_GAMMA; |
| 2500 | if (gamma > 0) { |
| 2501 | coda_write(dev, (gamma & CODA_GAMMA_MASK) << CODA_GAMMA_OFFSET, |
| 2502 | CODA_CMD_ENC_SEQ_RC_GAMMA); |
| 2503 | } |
Philipp Zabel | 1a5567e | 2014-07-11 06:36:26 -0300 | [diff] [blame] | 2504 | |
| 2505 | if (ctx->params.h264_min_qp || ctx->params.h264_max_qp) { |
| 2506 | coda_write(dev, |
| 2507 | ctx->params.h264_min_qp << CODA_QPMIN_OFFSET | |
| 2508 | ctx->params.h264_max_qp << CODA_QPMAX_OFFSET, |
| 2509 | CODA_CMD_ENC_SEQ_RC_QP_MIN_MAX); |
| 2510 | } |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2511 | if (dev->devtype->product == CODA_960) { |
Philipp Zabel | 1a5567e | 2014-07-11 06:36:26 -0300 | [diff] [blame] | 2512 | if (ctx->params.h264_max_qp) |
| 2513 | value |= 1 << CODA9_OPTION_RCQPMAX_OFFSET; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2514 | if (CODA_DEFAULT_GAMMA > 0) |
| 2515 | value |= 1 << CODA9_OPTION_GAMMA_OFFSET; |
Philipp Zabel | fb1fcf1 | 2013-05-23 10:42:53 -0300 | [diff] [blame] | 2516 | } else { |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2517 | if (CODA_DEFAULT_GAMMA > 0) { |
| 2518 | if (dev->devtype->product == CODA_DX6) |
| 2519 | value |= 1 << CODADX6_OPTION_GAMMA_OFFSET; |
| 2520 | else |
| 2521 | value |= 1 << CODA7_OPTION_GAMMA_OFFSET; |
| 2522 | } |
Philipp Zabel | 1a5567e | 2014-07-11 06:36:26 -0300 | [diff] [blame] | 2523 | if (ctx->params.h264_min_qp) |
| 2524 | value |= 1 << CODA7_OPTION_RCQPMIN_OFFSET; |
| 2525 | if (ctx->params.h264_max_qp) |
| 2526 | value |= 1 << CODA7_OPTION_RCQPMAX_OFFSET; |
Philipp Zabel | fb1fcf1 | 2013-05-23 10:42:53 -0300 | [diff] [blame] | 2527 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2528 | coda_write(dev, value, CODA_CMD_ENC_SEQ_OPTION); |
| 2529 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2530 | coda_write(dev, 0, CODA_CMD_ENC_SEQ_RC_INTERVAL_MODE); |
| 2531 | |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 2532 | coda_setup_iram(ctx); |
| 2533 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2534 | if (dst_fourcc == V4L2_PIX_FMT_H264) { |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2535 | switch (dev->devtype->product) { |
| 2536 | case CODA_DX6: |
Philipp Zabel | 0fd84dc | 2013-09-30 10:34:47 -0300 | [diff] [blame] | 2537 | value = FMO_SLICE_SAVE_BUF_SIZE << 7; |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 2538 | coda_write(dev, value, CODADX6_CMD_ENC_SEQ_FMO); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2539 | break; |
| 2540 | case CODA_7541: |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 2541 | coda_write(dev, ctx->iram_info.search_ram_paddr, |
| 2542 | CODA7_CMD_ENC_SEQ_SEARCH_BASE); |
| 2543 | coda_write(dev, ctx->iram_info.search_ram_size, |
| 2544 | CODA7_CMD_ENC_SEQ_SEARCH_SIZE); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2545 | break; |
| 2546 | case CODA_960: |
| 2547 | coda_write(dev, 0, CODA9_CMD_ENC_SEQ_ME_OPTION); |
| 2548 | coda_write(dev, 0, CODA9_CMD_ENC_SEQ_INTRA_WEIGHT); |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 2549 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2550 | } |
| 2551 | |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2552 | ret = coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT); |
| 2553 | if (ret < 0) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2554 | v4l2_err(v4l2_dev, "CODA_COMMAND_SEQ_INIT timeout\n"); |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2555 | goto out; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2556 | } |
| 2557 | |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2558 | if (coda_read(dev, CODA_RET_ENC_SEQ_SUCCESS) == 0) { |
| 2559 | v4l2_err(v4l2_dev, "CODA_COMMAND_SEQ_INIT failed\n"); |
| 2560 | ret = -EFAULT; |
| 2561 | goto out; |
| 2562 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2563 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2564 | if (dev->devtype->product == CODA_960) |
| 2565 | ctx->num_internal_frames = 4; |
| 2566 | else |
| 2567 | ctx->num_internal_frames = 2; |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 2568 | ret = coda_alloc_framebuffers(ctx, q_data_src, dst_fourcc); |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2569 | if (ret < 0) { |
| 2570 | v4l2_err(v4l2_dev, "failed to allocate framebuffers\n"); |
| 2571 | goto out; |
| 2572 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2573 | |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 2574 | coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM); |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 2575 | coda_write(dev, q_data_src->bytesperline, |
| 2576 | CODA_CMD_SET_FRAME_BUF_STRIDE); |
| 2577 | if (dev->devtype->product == CODA_7541) { |
| 2578 | coda_write(dev, q_data_src->bytesperline, |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2579 | CODA7_CMD_SET_FRAME_SOURCE_BUF_STRIDE); |
Philipp Zabel | 2fd6a37 | 2014-07-11 06:36:36 -0300 | [diff] [blame] | 2580 | } |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 2581 | if (dev->devtype->product != CODA_DX6) { |
Philipp Zabel | c2d2251 | 2013-06-21 03:55:28 -0300 | [diff] [blame] | 2582 | coda_write(dev, ctx->iram_info.buf_bit_use, |
| 2583 | CODA7_CMD_SET_FRAME_AXI_BIT_ADDR); |
| 2584 | coda_write(dev, ctx->iram_info.buf_ip_ac_dc_use, |
| 2585 | CODA7_CMD_SET_FRAME_AXI_IPACDC_ADDR); |
| 2586 | coda_write(dev, ctx->iram_info.buf_dbk_y_use, |
| 2587 | CODA7_CMD_SET_FRAME_AXI_DBKY_ADDR); |
| 2588 | coda_write(dev, ctx->iram_info.buf_dbk_c_use, |
| 2589 | CODA7_CMD_SET_FRAME_AXI_DBKC_ADDR); |
| 2590 | coda_write(dev, ctx->iram_info.buf_ovl_use, |
| 2591 | CODA7_CMD_SET_FRAME_AXI_OVL_ADDR); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2592 | if (dev->devtype->product == CODA_960) { |
| 2593 | coda_write(dev, ctx->iram_info.buf_btp_use, |
| 2594 | CODA9_CMD_SET_FRAME_AXI_BTP_ADDR); |
| 2595 | |
| 2596 | /* FIXME */ |
| 2597 | coda_write(dev, ctx->internal_frames[2].paddr, CODA9_CMD_SET_FRAME_SUBSAMP_A); |
| 2598 | coda_write(dev, ctx->internal_frames[3].paddr, CODA9_CMD_SET_FRAME_SUBSAMP_B); |
| 2599 | } |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 2600 | } |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2601 | |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2602 | ret = coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF); |
| 2603 | if (ret < 0) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2604 | v4l2_err(v4l2_dev, "CODA_COMMAND_SET_FRAME_BUF timeout\n"); |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2605 | goto out; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | /* Save stream headers */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 2609 | buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2610 | switch (dst_fourcc) { |
| 2611 | case V4L2_PIX_FMT_H264: |
| 2612 | /* |
| 2613 | * Get SPS in the first frame and copy it to an |
| 2614 | * intermediate buffer. |
| 2615 | */ |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2616 | ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_SPS, |
| 2617 | &ctx->vpu_header[0][0], |
| 2618 | &ctx->vpu_header_size[0]); |
| 2619 | if (ret < 0) |
| 2620 | goto out; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2621 | |
| 2622 | /* |
| 2623 | * Get PPS in the first frame and copy it to an |
| 2624 | * intermediate buffer. |
| 2625 | */ |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2626 | ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_PPS, |
| 2627 | &ctx->vpu_header[1][0], |
| 2628 | &ctx->vpu_header_size[1]); |
| 2629 | if (ret < 0) |
| 2630 | goto out; |
| 2631 | |
Javier Martin | 3f3f5c7 | 2012-10-29 05:20:29 -0300 | [diff] [blame] | 2632 | /* |
| 2633 | * Length of H.264 headers is variable and thus it might not be |
| 2634 | * aligned for the coda to append the encoded frame. In that is |
| 2635 | * the case a filler NAL must be added to header 2. |
| 2636 | */ |
| 2637 | ctx->vpu_header_size[2] = coda_h264_padding( |
| 2638 | (ctx->vpu_header_size[0] + |
| 2639 | ctx->vpu_header_size[1]), |
| 2640 | ctx->vpu_header[2]); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2641 | break; |
| 2642 | case V4L2_PIX_FMT_MPEG4: |
| 2643 | /* |
| 2644 | * Get VOS in the first frame and copy it to an |
| 2645 | * intermediate buffer |
| 2646 | */ |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2647 | ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOS, |
| 2648 | &ctx->vpu_header[0][0], |
| 2649 | &ctx->vpu_header_size[0]); |
| 2650 | if (ret < 0) |
| 2651 | goto out; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2652 | |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2653 | ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VIS, |
| 2654 | &ctx->vpu_header[1][0], |
| 2655 | &ctx->vpu_header_size[1]); |
| 2656 | if (ret < 0) |
| 2657 | goto out; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2658 | |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2659 | ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOL, |
| 2660 | &ctx->vpu_header[2][0], |
| 2661 | &ctx->vpu_header_size[2]); |
| 2662 | if (ret < 0) |
| 2663 | goto out; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2664 | break; |
| 2665 | default: |
| 2666 | /* No more formats need to save headers at the moment */ |
| 2667 | break; |
| 2668 | } |
| 2669 | |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2670 | out: |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 2671 | mutex_unlock(&dev->coda_mutex); |
Philipp Zabel | d35167a | 2013-05-23 10:42:59 -0300 | [diff] [blame] | 2672 | return ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2673 | } |
| 2674 | |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 2675 | static void coda_stop_streaming(struct vb2_queue *q) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2676 | { |
| 2677 | struct coda_ctx *ctx = vb2_get_drv_priv(q); |
Philipp Zabel | 2fb57f0 | 2012-07-25 09:22:07 -0300 | [diff] [blame] | 2678 | struct coda_dev *dev = ctx->dev; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2679 | |
| 2680 | if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2681 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2682 | "%s: output\n", __func__); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2683 | ctx->streamon_out = 0; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2684 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2685 | if (ctx->inst_type == CODA_INST_DECODER && |
| 2686 | coda_isbusy(dev) && ctx->idx == coda_read(dev, CODA_REG_BIT_RUN_INDEX)) { |
| 2687 | /* if this decoder instance is running, set the stream end flag */ |
| 2688 | if (dev->devtype->product == CODA_960) { |
| 2689 | u32 val = coda_read(dev, CODA_REG_BIT_BIT_STREAM_PARAM); |
| 2690 | |
| 2691 | val |= CODA_BIT_STREAM_END_FLAG; |
| 2692 | coda_write(dev, val, CODA_REG_BIT_BIT_STREAM_PARAM); |
| 2693 | ctx->bit_stream_param = val; |
| 2694 | } |
| 2695 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2696 | ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG; |
| 2697 | |
| 2698 | ctx->isequence = 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2699 | } else { |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2700 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2701 | "%s: capture\n", __func__); |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 2702 | ctx->streamon_cap = 0; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2703 | |
| 2704 | ctx->osequence = 0; |
Philipp Zabel | cb2c028 | 2014-07-11 06:36:33 -0300 | [diff] [blame] | 2705 | ctx->sequence_offset = 0; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2706 | } |
| 2707 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2708 | if (!ctx->streamon_out && !ctx->streamon_cap) { |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 2709 | struct coda_timestamp *ts; |
| 2710 | |
| 2711 | while (!list_empty(&ctx->timestamp_list)) { |
| 2712 | ts = list_first_entry(&ctx->timestamp_list, |
| 2713 | struct coda_timestamp, list); |
| 2714 | list_del(&ts->list); |
| 2715 | kfree(ts); |
| 2716 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2717 | kfifo_init(&ctx->bitstream_fifo, |
| 2718 | ctx->bitstream.vaddr, ctx->bitstream.size); |
| 2719 | ctx->runcounter = 0; |
Philipp Zabel | 62bed14 | 2012-07-25 10:40:39 -0300 | [diff] [blame] | 2720 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | static struct vb2_ops coda_qops = { |
| 2724 | .queue_setup = coda_queue_setup, |
| 2725 | .buf_prepare = coda_buf_prepare, |
| 2726 | .buf_queue = coda_buf_queue, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2727 | .start_streaming = coda_start_streaming, |
| 2728 | .stop_streaming = coda_stop_streaming, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 2729 | .wait_prepare = vb2_ops_wait_prepare, |
| 2730 | .wait_finish = vb2_ops_wait_finish, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2731 | }; |
| 2732 | |
| 2733 | static int coda_s_ctrl(struct v4l2_ctrl *ctrl) |
| 2734 | { |
| 2735 | struct coda_ctx *ctx = |
| 2736 | container_of(ctrl->handler, struct coda_ctx, ctrls); |
| 2737 | |
| 2738 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 2739 | "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val); |
| 2740 | |
| 2741 | switch (ctrl->id) { |
Philipp Zabel | 8f35c7b | 2012-07-09 04:25:52 -0300 | [diff] [blame] | 2742 | case V4L2_CID_HFLIP: |
| 2743 | if (ctrl->val) |
| 2744 | ctx->params.rot_mode |= CODA_MIR_HOR; |
| 2745 | else |
| 2746 | ctx->params.rot_mode &= ~CODA_MIR_HOR; |
| 2747 | break; |
| 2748 | case V4L2_CID_VFLIP: |
| 2749 | if (ctrl->val) |
| 2750 | ctx->params.rot_mode |= CODA_MIR_VER; |
| 2751 | else |
| 2752 | ctx->params.rot_mode &= ~CODA_MIR_VER; |
| 2753 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2754 | case V4L2_CID_MPEG_VIDEO_BITRATE: |
| 2755 | ctx->params.bitrate = ctrl->val / 1000; |
| 2756 | break; |
| 2757 | case V4L2_CID_MPEG_VIDEO_GOP_SIZE: |
| 2758 | ctx->params.gop_size = ctrl->val; |
| 2759 | break; |
| 2760 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: |
| 2761 | ctx->params.h264_intra_qp = ctrl->val; |
| 2762 | break; |
| 2763 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: |
| 2764 | ctx->params.h264_inter_qp = ctrl->val; |
| 2765 | break; |
Philipp Zabel | 1a5567e | 2014-07-11 06:36:26 -0300 | [diff] [blame] | 2766 | case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: |
| 2767 | ctx->params.h264_min_qp = ctrl->val; |
| 2768 | break; |
| 2769 | case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: |
| 2770 | ctx->params.h264_max_qp = ctrl->val; |
| 2771 | break; |
Philipp Zabel | de23b1d | 2014-07-11 06:36:27 -0300 | [diff] [blame] | 2772 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA: |
| 2773 | ctx->params.h264_deblk_alpha = ctrl->val; |
| 2774 | break; |
| 2775 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA: |
| 2776 | ctx->params.h264_deblk_beta = ctrl->val; |
| 2777 | break; |
| 2778 | case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: |
| 2779 | ctx->params.h264_deblk_enabled = (ctrl->val == |
| 2780 | V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED); |
| 2781 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2782 | case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: |
| 2783 | ctx->params.mpeg4_intra_qp = ctrl->val; |
| 2784 | break; |
| 2785 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: |
| 2786 | ctx->params.mpeg4_inter_qp = ctrl->val; |
| 2787 | break; |
| 2788 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
| 2789 | ctx->params.slice_mode = ctrl->val; |
| 2790 | break; |
| 2791 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: |
| 2792 | ctx->params.slice_max_mb = ctrl->val; |
| 2793 | break; |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 2794 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: |
| 2795 | ctx->params.slice_max_bits = ctrl->val * 8; |
| 2796 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2797 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: |
| 2798 | break; |
Philipp Zabel | f38f79d5 | 2014-07-11 06:36:28 -0300 | [diff] [blame] | 2799 | case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: |
| 2800 | ctx->params.intra_refresh = ctrl->val; |
| 2801 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2802 | default: |
| 2803 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 2804 | "Invalid control, id=%d, val=%d\n", |
| 2805 | ctrl->id, ctrl->val); |
| 2806 | return -EINVAL; |
| 2807 | } |
| 2808 | |
| 2809 | return 0; |
| 2810 | } |
| 2811 | |
| 2812 | static struct v4l2_ctrl_ops coda_ctrl_ops = { |
| 2813 | .s_ctrl = coda_s_ctrl, |
| 2814 | }; |
| 2815 | |
| 2816 | static int coda_ctrls_setup(struct coda_ctx *ctx) |
| 2817 | { |
| 2818 | v4l2_ctrl_handler_init(&ctx->ctrls, 9); |
| 2819 | |
| 2820 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Philipp Zabel | 8f35c7b | 2012-07-09 04:25:52 -0300 | [diff] [blame] | 2821 | V4L2_CID_HFLIP, 0, 1, 1, 0); |
| 2822 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2823 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
| 2824 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2825 | V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1, 0); |
| 2826 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2827 | V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 60, 1, 16); |
| 2828 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Philipp Zabel | 594a750 | 2014-07-11 06:36:14 -0300 | [diff] [blame] | 2829 | V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 0, 51, 1, 25); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2830 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Philipp Zabel | 594a750 | 2014-07-11 06:36:14 -0300 | [diff] [blame] | 2831 | V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 0, 51, 1, 25); |
Philipp Zabel | 1a5567e | 2014-07-11 06:36:26 -0300 | [diff] [blame] | 2832 | if (ctx->dev->devtype->product != CODA_960) { |
| 2833 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2834 | V4L2_CID_MPEG_VIDEO_H264_MIN_QP, 0, 51, 1, 12); |
| 2835 | } |
| 2836 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2837 | V4L2_CID_MPEG_VIDEO_H264_MAX_QP, 0, 51, 1, 51); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2838 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Philipp Zabel | de23b1d | 2014-07-11 06:36:27 -0300 | [diff] [blame] | 2839 | V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA, 0, 15, 1, 0); |
| 2840 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2841 | V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA, 0, 15, 1, 0); |
| 2842 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
| 2843 | V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE, |
| 2844 | V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED, 0x0, |
| 2845 | V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED); |
| 2846 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2847 | V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP, 1, 31, 1, 2); |
| 2848 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2849 | V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP, 1, 31, 1, 2); |
| 2850 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
| 2851 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE, |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 2852 | V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES, 0x0, |
| 2853 | V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2854 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2855 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB, 1, 0x3fffffff, 1, 1); |
Philipp Zabel | c566c78 | 2012-08-08 11:59:38 -0300 | [diff] [blame] | 2856 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2857 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES, 1, 0x3fffffff, 1, 500); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2858 | v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops, |
| 2859 | V4L2_CID_MPEG_VIDEO_HEADER_MODE, |
| 2860 | V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME, |
| 2861 | (1 << V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE), |
| 2862 | V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME); |
Philipp Zabel | f38f79d5 | 2014-07-11 06:36:28 -0300 | [diff] [blame] | 2863 | v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, |
| 2864 | V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB, 0, 1920 * 1088 / 256, 1, 0); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2865 | |
| 2866 | if (ctx->ctrls.error) { |
| 2867 | v4l2_err(&ctx->dev->v4l2_dev, "control initialization error (%d)", |
| 2868 | ctx->ctrls.error); |
| 2869 | return -EINVAL; |
| 2870 | } |
| 2871 | |
| 2872 | return v4l2_ctrl_handler_setup(&ctx->ctrls); |
| 2873 | } |
| 2874 | |
| 2875 | static int coda_queue_init(void *priv, struct vb2_queue *src_vq, |
| 2876 | struct vb2_queue *dst_vq) |
| 2877 | { |
| 2878 | struct coda_ctx *ctx = priv; |
| 2879 | int ret; |
| 2880 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2881 | src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
Philipp Zabel | 419869c | 2013-05-23 07:06:30 -0300 | [diff] [blame] | 2882 | src_vq->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2883 | src_vq->drv_priv = ctx; |
| 2884 | src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); |
| 2885 | src_vq->ops = &coda_qops; |
| 2886 | src_vq->mem_ops = &vb2_dma_contig_memops; |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 2887 | src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 2888 | src_vq->lock = &ctx->dev->dev_mutex; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2889 | |
| 2890 | ret = vb2_queue_init(src_vq); |
| 2891 | if (ret) |
| 2892 | return ret; |
| 2893 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2894 | dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Philipp Zabel | 419869c | 2013-05-23 07:06:30 -0300 | [diff] [blame] | 2895 | dst_vq->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2896 | dst_vq->drv_priv = ctx; |
| 2897 | dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); |
| 2898 | dst_vq->ops = &coda_qops; |
| 2899 | dst_vq->mem_ops = &vb2_dma_contig_memops; |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 2900 | dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 2901 | dst_vq->lock = &ctx->dev->dev_mutex; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2902 | |
| 2903 | return vb2_queue_init(dst_vq); |
| 2904 | } |
| 2905 | |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 2906 | static int coda_next_free_instance(struct coda_dev *dev) |
| 2907 | { |
Philipp Zabel | 0cddc7e | 2013-09-30 10:34:44 -0300 | [diff] [blame] | 2908 | int idx = ffz(dev->instance_mask); |
| 2909 | |
| 2910 | if ((idx < 0) || |
| 2911 | (dev->devtype->product == CODA_DX6 && idx > CODADX6_MAX_INSTANCES)) |
| 2912 | return -EBUSY; |
| 2913 | |
| 2914 | return idx; |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 2915 | } |
| 2916 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2917 | static int coda_open(struct file *file) |
| 2918 | { |
| 2919 | struct coda_dev *dev = video_drvdata(file); |
| 2920 | struct coda_ctx *ctx = NULL; |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 2921 | char *name; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 2922 | int ret; |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 2923 | int idx; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2924 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2925 | ctx = kzalloc(sizeof *ctx, GFP_KERNEL); |
| 2926 | if (!ctx) |
| 2927 | return -ENOMEM; |
| 2928 | |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 2929 | idx = coda_next_free_instance(dev); |
Philipp Zabel | 0cddc7e | 2013-09-30 10:34:44 -0300 | [diff] [blame] | 2930 | if (idx < 0) { |
| 2931 | ret = idx; |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 2932 | goto err_coda_max; |
| 2933 | } |
| 2934 | set_bit(idx, &dev->instance_mask); |
| 2935 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 2936 | name = kasprintf(GFP_KERNEL, "context%d", idx); |
| 2937 | ctx->debugfs_entry = debugfs_create_dir(name, dev->debugfs_root); |
| 2938 | kfree(name); |
| 2939 | |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 2940 | init_completion(&ctx->completion); |
| 2941 | INIT_WORK(&ctx->pic_run_work, coda_pic_run_work); |
| 2942 | INIT_WORK(&ctx->seq_end_work, coda_seq_end_work); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2943 | v4l2_fh_init(&ctx->fh, video_devdata(file)); |
| 2944 | file->private_data = &ctx->fh; |
| 2945 | v4l2_fh_add(&ctx->fh); |
| 2946 | ctx->dev = dev; |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 2947 | ctx->idx = idx; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 2948 | switch (dev->devtype->product) { |
| 2949 | case CODA_7541: |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 2950 | case CODA_960: |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 2951 | ctx->reg_idx = 0; |
| 2952 | break; |
| 2953 | default: |
| 2954 | ctx->reg_idx = idx; |
| 2955 | } |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 2956 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 2957 | /* Power up and upload firmware if necessary */ |
| 2958 | ret = pm_runtime_get_sync(&dev->plat_dev->dev); |
| 2959 | if (ret < 0) { |
| 2960 | v4l2_err(&dev->v4l2_dev, "failed to power up: %d\n", ret); |
| 2961 | goto err_pm_get; |
| 2962 | } |
| 2963 | |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 2964 | ret = clk_prepare_enable(dev->clk_per); |
| 2965 | if (ret) |
| 2966 | goto err_clk_per; |
| 2967 | |
| 2968 | ret = clk_prepare_enable(dev->clk_ahb); |
| 2969 | if (ret) |
| 2970 | goto err_clk_ahb; |
| 2971 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2972 | set_default_params(ctx); |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 2973 | ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2974 | &coda_queue_init); |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 2975 | if (IS_ERR(ctx->fh.m2m_ctx)) { |
| 2976 | ret = PTR_ERR(ctx->fh.m2m_ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2977 | |
| 2978 | v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n", |
| 2979 | __func__, ret); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 2980 | goto err_ctx_init; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2981 | } |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 2982 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2983 | ret = coda_ctrls_setup(ctx); |
| 2984 | if (ret) { |
| 2985 | v4l2_err(&dev->v4l2_dev, "failed to setup coda controls\n"); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 2986 | goto err_ctrls_setup; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | ctx->fh.ctrl_handler = &ctx->ctrls; |
| 2990 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 2991 | ret = coda_alloc_context_buf(ctx, &ctx->parabuf, CODA_PARA_BUF_SIZE, |
| 2992 | "parabuf"); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 2993 | if (ret < 0) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2994 | v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf"); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 2995 | goto err_dma_alloc; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 2996 | } |
| 2997 | |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 2998 | ctx->bitstream.size = CODA_MAX_FRAME_SIZE; |
| 2999 | ctx->bitstream.vaddr = dma_alloc_writecombine(&dev->plat_dev->dev, |
| 3000 | ctx->bitstream.size, &ctx->bitstream.paddr, GFP_KERNEL); |
| 3001 | if (!ctx->bitstream.vaddr) { |
| 3002 | v4l2_err(&dev->v4l2_dev, "failed to allocate bitstream ringbuffer"); |
| 3003 | ret = -ENOMEM; |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 3004 | goto err_dma_writecombine; |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 3005 | } |
| 3006 | kfifo_init(&ctx->bitstream_fifo, |
| 3007 | ctx->bitstream.vaddr, ctx->bitstream.size); |
| 3008 | mutex_init(&ctx->bitstream_mutex); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3009 | mutex_init(&ctx->buffer_mutex); |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 3010 | INIT_LIST_HEAD(&ctx->timestamp_list); |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 3011 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3012 | coda_lock(ctx); |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 3013 | list_add(&ctx->list, &dev->instances); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3014 | coda_unlock(ctx); |
| 3015 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3016 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Created instance %d (%p)\n", |
| 3017 | ctx->idx, ctx); |
| 3018 | |
| 3019 | return 0; |
| 3020 | |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 3021 | err_dma_writecombine: |
| 3022 | coda_free_context_buffers(ctx); |
| 3023 | if (ctx->dev->devtype->product == CODA_DX6) |
| 3024 | coda_free_aux_buf(dev, &ctx->workbuf); |
| 3025 | coda_free_aux_buf(dev, &ctx->parabuf); |
| 3026 | err_dma_alloc: |
| 3027 | v4l2_ctrl_handler_free(&ctx->ctrls); |
| 3028 | err_ctrls_setup: |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 3029 | v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 3030 | err_ctx_init: |
| 3031 | clk_disable_unprepare(dev->clk_ahb); |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 3032 | err_clk_ahb: |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 3033 | clk_disable_unprepare(dev->clk_per); |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 3034 | err_clk_per: |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3035 | pm_runtime_put_sync(&dev->plat_dev->dev); |
| 3036 | err_pm_get: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3037 | v4l2_fh_del(&ctx->fh); |
| 3038 | v4l2_fh_exit(&ctx->fh); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 3039 | clear_bit(ctx->idx, &dev->instance_mask); |
| 3040 | err_coda_max: |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3041 | kfree(ctx); |
| 3042 | return ret; |
| 3043 | } |
| 3044 | |
| 3045 | static int coda_release(struct file *file) |
| 3046 | { |
| 3047 | struct coda_dev *dev = video_drvdata(file); |
| 3048 | struct coda_ctx *ctx = fh_to_ctx(file->private_data); |
| 3049 | |
| 3050 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n", |
| 3051 | ctx); |
| 3052 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 3053 | debugfs_remove_recursive(ctx->debugfs_entry); |
| 3054 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3055 | /* If this instance is running, call .job_abort and wait for it to end */ |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 3056 | v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3057 | |
| 3058 | /* In case the instance was not running, we still need to call SEQ_END */ |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 3059 | if (ctx->initialized) { |
| 3060 | queue_work(dev->workqueue, &ctx->seq_end_work); |
| 3061 | flush_work(&ctx->seq_end_work); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3062 | } |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3063 | |
| 3064 | coda_free_framebuffers(ctx); |
| 3065 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3066 | coda_lock(ctx); |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 3067 | list_del(&ctx->list); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3068 | coda_unlock(ctx); |
| 3069 | |
Philipp Zabel | 9082a7c | 2013-06-21 03:55:31 -0300 | [diff] [blame] | 3070 | dma_free_writecombine(&dev->plat_dev->dev, ctx->bitstream.size, |
| 3071 | ctx->bitstream.vaddr, ctx->bitstream.paddr); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3072 | coda_free_context_buffers(ctx); |
| 3073 | if (ctx->dev->devtype->product == CODA_DX6) |
| 3074 | coda_free_aux_buf(dev, &ctx->workbuf); |
| 3075 | |
| 3076 | coda_free_aux_buf(dev, &ctx->parabuf); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3077 | v4l2_ctrl_handler_free(&ctx->ctrls); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3078 | clk_disable_unprepare(dev->clk_ahb); |
Fabio Estevam | f82bc20 | 2013-08-21 11:14:16 -0300 | [diff] [blame] | 3079 | clk_disable_unprepare(dev->clk_per); |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3080 | pm_runtime_put_sync(&dev->plat_dev->dev); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3081 | v4l2_fh_del(&ctx->fh); |
| 3082 | v4l2_fh_exit(&ctx->fh); |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 3083 | clear_bit(ctx->idx, &dev->instance_mask); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3084 | kfree(ctx); |
| 3085 | |
| 3086 | return 0; |
| 3087 | } |
| 3088 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3089 | static const struct v4l2_file_operations coda_fops = { |
| 3090 | .owner = THIS_MODULE, |
| 3091 | .open = coda_open, |
| 3092 | .release = coda_release, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 3093 | .poll = v4l2_m2m_fop_poll, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3094 | .unlocked_ioctl = video_ioctl2, |
Philipp Zabel | 152ea1c | 2014-07-11 06:36:21 -0300 | [diff] [blame] | 3095 | .mmap = v4l2_m2m_fop_mmap, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3096 | }; |
| 3097 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3098 | static void coda_finish_decode(struct coda_ctx *ctx) |
| 3099 | { |
| 3100 | struct coda_dev *dev = ctx->dev; |
| 3101 | struct coda_q_data *q_data_src; |
| 3102 | struct coda_q_data *q_data_dst; |
| 3103 | struct vb2_buffer *dst_buf; |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 3104 | struct coda_timestamp *ts; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3105 | int width, height; |
| 3106 | int decoded_idx; |
| 3107 | int display_idx; |
| 3108 | u32 src_fourcc; |
| 3109 | int success; |
Philipp Zabel | 410e5e4 | 2014-07-11 06:36:32 -0300 | [diff] [blame] | 3110 | u32 err_mb; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3111 | u32 val; |
| 3112 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 3113 | dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3114 | |
| 3115 | /* Update kfifo out pointer from coda bitstream read pointer */ |
| 3116 | coda_kfifo_sync_from_device(ctx); |
| 3117 | |
| 3118 | /* |
| 3119 | * in stream-end mode, the read pointer can overshoot the write pointer |
| 3120 | * by up to 512 bytes |
| 3121 | */ |
| 3122 | if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) { |
| 3123 | if (coda_get_bitstream_payload(ctx) >= 0x100000 - 512) |
| 3124 | kfifo_init(&ctx->bitstream_fifo, |
| 3125 | ctx->bitstream.vaddr, ctx->bitstream.size); |
| 3126 | } |
| 3127 | |
| 3128 | q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
| 3129 | src_fourcc = q_data_src->fourcc; |
| 3130 | |
| 3131 | val = coda_read(dev, CODA_RET_DEC_PIC_SUCCESS); |
| 3132 | if (val != 1) |
| 3133 | pr_err("DEC_PIC_SUCCESS = %d\n", val); |
| 3134 | |
| 3135 | success = val & 0x1; |
| 3136 | if (!success) |
| 3137 | v4l2_err(&dev->v4l2_dev, "decode failed\n"); |
| 3138 | |
| 3139 | if (src_fourcc == V4L2_PIX_FMT_H264) { |
| 3140 | if (val & (1 << 3)) |
| 3141 | v4l2_err(&dev->v4l2_dev, |
| 3142 | "insufficient PS buffer space (%d bytes)\n", |
| 3143 | ctx->psbuf.size); |
| 3144 | if (val & (1 << 2)) |
| 3145 | v4l2_err(&dev->v4l2_dev, |
| 3146 | "insufficient slice buffer space (%d bytes)\n", |
| 3147 | ctx->slicebuf.size); |
| 3148 | } |
| 3149 | |
| 3150 | val = coda_read(dev, CODA_RET_DEC_PIC_SIZE); |
| 3151 | width = (val >> 16) & 0xffff; |
| 3152 | height = val & 0xffff; |
| 3153 | |
| 3154 | q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
| 3155 | |
Philipp Zabel | 52c4167 | 2014-07-11 06:36:19 -0300 | [diff] [blame] | 3156 | /* frame crop information */ |
| 3157 | if (src_fourcc == V4L2_PIX_FMT_H264) { |
| 3158 | u32 left_right; |
| 3159 | u32 top_bottom; |
| 3160 | |
| 3161 | left_right = coda_read(dev, CODA_RET_DEC_PIC_CROP_LEFT_RIGHT); |
| 3162 | top_bottom = coda_read(dev, CODA_RET_DEC_PIC_CROP_TOP_BOTTOM); |
| 3163 | |
| 3164 | if (left_right == 0xffffffff && top_bottom == 0xffffffff) { |
| 3165 | /* Keep current crop information */ |
| 3166 | } else { |
| 3167 | struct v4l2_rect *rect = &q_data_dst->rect; |
| 3168 | |
| 3169 | rect->left = left_right >> 16 & 0xffff; |
| 3170 | rect->top = top_bottom >> 16 & 0xffff; |
| 3171 | rect->width = width - rect->left - |
| 3172 | (left_right & 0xffff); |
| 3173 | rect->height = height - rect->top - |
| 3174 | (top_bottom & 0xffff); |
| 3175 | } |
| 3176 | } else { |
| 3177 | /* no cropping */ |
| 3178 | } |
| 3179 | |
Philipp Zabel | 410e5e4 | 2014-07-11 06:36:32 -0300 | [diff] [blame] | 3180 | err_mb = coda_read(dev, CODA_RET_DEC_PIC_ERR_MB); |
| 3181 | if (err_mb > 0) |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3182 | v4l2_err(&dev->v4l2_dev, |
Philipp Zabel | 410e5e4 | 2014-07-11 06:36:32 -0300 | [diff] [blame] | 3183 | "errors in %d macroblocks\n", err_mb); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3184 | |
| 3185 | if (dev->devtype->product == CODA_7541) { |
| 3186 | val = coda_read(dev, CODA_RET_DEC_PIC_OPTION); |
| 3187 | if (val == 0) { |
| 3188 | /* not enough bitstream data */ |
| 3189 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 3190 | "prescan failed: %d\n", val); |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 3191 | ctx->hold = true; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3192 | return; |
| 3193 | } |
| 3194 | } |
| 3195 | |
| 3196 | ctx->frm_dis_flg = coda_read(dev, CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); |
| 3197 | |
| 3198 | /* |
| 3199 | * The previous display frame was copied out by the rotator, |
| 3200 | * now it can be overwritten again |
| 3201 | */ |
| 3202 | if (ctx->display_idx >= 0 && |
| 3203 | ctx->display_idx < ctx->num_internal_frames) { |
| 3204 | ctx->frm_dis_flg &= ~(1 << ctx->display_idx); |
| 3205 | coda_write(dev, ctx->frm_dis_flg, |
| 3206 | CODA_REG_BIT_FRM_DIS_FLG(ctx->reg_idx)); |
| 3207 | } |
| 3208 | |
| 3209 | /* |
| 3210 | * The index of the last decoded frame, not necessarily in |
| 3211 | * display order, and the index of the next display frame. |
| 3212 | * The latter could have been decoded in a previous run. |
| 3213 | */ |
| 3214 | decoded_idx = coda_read(dev, CODA_RET_DEC_PIC_CUR_IDX); |
| 3215 | display_idx = coda_read(dev, CODA_RET_DEC_PIC_FRAME_IDX); |
| 3216 | |
| 3217 | if (decoded_idx == -1) { |
| 3218 | /* no frame was decoded, but we might have a display frame */ |
Philipp Zabel | cb2c028 | 2014-07-11 06:36:33 -0300 | [diff] [blame] | 3219 | if (display_idx >= 0 && display_idx < ctx->num_internal_frames) |
| 3220 | ctx->sequence_offset++; |
| 3221 | else if (ctx->display_idx < 0) |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 3222 | ctx->hold = true; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3223 | } else if (decoded_idx == -2) { |
| 3224 | /* no frame was decoded, we still return the remaining buffers */ |
| 3225 | } else if (decoded_idx < 0 || decoded_idx >= ctx->num_internal_frames) { |
| 3226 | v4l2_err(&dev->v4l2_dev, |
| 3227 | "decoded frame index out of range: %d\n", decoded_idx); |
Philipp Zabel | 1a8b381 | 2014-07-11 06:36:12 -0300 | [diff] [blame] | 3228 | } else { |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 3229 | ts = list_first_entry(&ctx->timestamp_list, |
| 3230 | struct coda_timestamp, list); |
| 3231 | list_del(&ts->list); |
| 3232 | val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM) - 1; |
Philipp Zabel | cb2c028 | 2014-07-11 06:36:33 -0300 | [diff] [blame] | 3233 | val -= ctx->sequence_offset; |
| 3234 | if (val != (ts->sequence & 0xffff)) { |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 3235 | v4l2_err(&dev->v4l2_dev, |
Philipp Zabel | cb2c028 | 2014-07-11 06:36:33 -0300 | [diff] [blame] | 3236 | "sequence number mismatch (%d(%d) != %d)\n", |
| 3237 | val, ctx->sequence_offset, ts->sequence); |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 3238 | } |
| 3239 | ctx->frame_timestamps[decoded_idx] = *ts; |
| 3240 | kfree(ts); |
| 3241 | |
Philipp Zabel | 1a8b381 | 2014-07-11 06:36:12 -0300 | [diff] [blame] | 3242 | val = coda_read(dev, CODA_RET_DEC_PIC_TYPE) & 0x7; |
| 3243 | if (val == 0) |
| 3244 | ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_KEYFRAME; |
| 3245 | else if (val == 1) |
| 3246 | ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_PFRAME; |
| 3247 | else |
| 3248 | ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_BFRAME; |
Philipp Zabel | 410e5e4 | 2014-07-11 06:36:32 -0300 | [diff] [blame] | 3249 | |
| 3250 | ctx->frame_errors[decoded_idx] = err_mb; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | if (display_idx == -1) { |
| 3254 | /* |
| 3255 | * no more frames to be decoded, but there could still |
| 3256 | * be rotator output to dequeue |
| 3257 | */ |
Philipp Zabel | 84e2365 | 2014-07-11 06:36:34 -0300 | [diff] [blame] | 3258 | ctx->hold = true; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3259 | } else if (display_idx == -3) { |
| 3260 | /* possibly prescan failure */ |
| 3261 | } else if (display_idx < 0 || display_idx >= ctx->num_internal_frames) { |
| 3262 | v4l2_err(&dev->v4l2_dev, |
| 3263 | "presentation frame index out of range: %d\n", |
| 3264 | display_idx); |
| 3265 | } |
| 3266 | |
| 3267 | /* If a frame was copied out, return it */ |
| 3268 | if (ctx->display_idx >= 0 && |
| 3269 | ctx->display_idx < ctx->num_internal_frames) { |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 3270 | dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3271 | dst_buf->v4l2_buf.sequence = ctx->osequence++; |
| 3272 | |
Philipp Zabel | 1a8b381 | 2014-07-11 06:36:12 -0300 | [diff] [blame] | 3273 | dst_buf->v4l2_buf.flags &= ~(V4L2_BUF_FLAG_KEYFRAME | |
| 3274 | V4L2_BUF_FLAG_PFRAME | |
| 3275 | V4L2_BUF_FLAG_BFRAME); |
| 3276 | dst_buf->v4l2_buf.flags |= ctx->frame_types[ctx->display_idx]; |
Philipp Zabel | 846ced9 | 2014-07-11 06:36:31 -0300 | [diff] [blame] | 3277 | ts = &ctx->frame_timestamps[ctx->display_idx]; |
| 3278 | dst_buf->v4l2_buf.timecode = ts->timecode; |
| 3279 | dst_buf->v4l2_buf.timestamp = ts->timestamp; |
Philipp Zabel | 1a8b381 | 2014-07-11 06:36:12 -0300 | [diff] [blame] | 3280 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3281 | vb2_set_plane_payload(dst_buf, 0, width * height * 3 / 2); |
| 3282 | |
Philipp Zabel | 410e5e4 | 2014-07-11 06:36:32 -0300 | [diff] [blame] | 3283 | v4l2_m2m_buf_done(dst_buf, ctx->frame_errors[display_idx] ? |
| 3284 | VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3285 | |
| 3286 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 3287 | "job finished: decoding frame (%d) (%s)\n", |
| 3288 | dst_buf->v4l2_buf.sequence, |
| 3289 | (dst_buf->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) ? |
| 3290 | "KEYFRAME" : "PFRAME"); |
| 3291 | } else { |
| 3292 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 3293 | "job finished: no frame decoded\n"); |
| 3294 | } |
| 3295 | |
| 3296 | /* The rotator will copy the current display frame next time */ |
| 3297 | ctx->display_idx = display_idx; |
| 3298 | } |
| 3299 | |
| 3300 | static void coda_finish_encode(struct coda_ctx *ctx) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3301 | { |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 3302 | struct vb2_buffer *src_buf, *dst_buf; |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 3303 | struct coda_dev *dev = ctx->dev; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3304 | u32 wr_ptr, start_ptr; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3305 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 3306 | src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); |
| 3307 | dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3308 | |
| 3309 | /* Get results from the coda */ |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3310 | start_ptr = coda_read(dev, CODA_CMD_ENC_PIC_BB_START); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3311 | wr_ptr = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)); |
| 3312 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3313 | /* Calculate bytesused field */ |
| 3314 | if (dst_buf->v4l2_buf.sequence == 0) { |
Philipp Zabel | 366108f | 2013-06-21 03:55:27 -0300 | [diff] [blame] | 3315 | vb2_set_plane_payload(dst_buf, 0, wr_ptr - start_ptr + |
| 3316 | ctx->vpu_header_size[0] + |
| 3317 | ctx->vpu_header_size[1] + |
| 3318 | ctx->vpu_header_size[2]); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3319 | } else { |
Philipp Zabel | 366108f | 2013-06-21 03:55:27 -0300 | [diff] [blame] | 3320 | vb2_set_plane_payload(dst_buf, 0, wr_ptr - start_ptr); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "frame size = %u\n", |
| 3324 | wr_ptr - start_ptr); |
| 3325 | |
| 3326 | coda_read(dev, CODA_RET_ENC_PIC_SLICE_NUM); |
| 3327 | coda_read(dev, CODA_RET_ENC_PIC_FLAG); |
| 3328 | |
Philipp Zabel | 5166028 | 2013-09-30 10:34:49 -0300 | [diff] [blame] | 3329 | if (coda_read(dev, CODA_RET_ENC_PIC_TYPE) == 0) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3330 | dst_buf->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME; |
| 3331 | dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_PFRAME; |
| 3332 | } else { |
| 3333 | dst_buf->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME; |
| 3334 | dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_KEYFRAME; |
| 3335 | } |
| 3336 | |
Kamil Debski | ccd571c | 2013-04-24 10:38:24 -0300 | [diff] [blame] | 3337 | dst_buf->v4l2_buf.timestamp = src_buf->v4l2_buf.timestamp; |
Sakari Ailus | 309f4d6 | 2014-02-08 14:21:35 -0300 | [diff] [blame] | 3338 | dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK; |
| 3339 | dst_buf->v4l2_buf.flags |= |
| 3340 | src_buf->v4l2_buf.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK; |
Kamil Debski | ccd571c | 2013-04-24 10:38:24 -0300 | [diff] [blame] | 3341 | dst_buf->v4l2_buf.timecode = src_buf->v4l2_buf.timecode; |
| 3342 | |
Philipp Zabel | ec25f68 | 2012-07-20 08:54:29 -0300 | [diff] [blame] | 3343 | v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3344 | |
Philipp Zabel | 14604e3 | 2014-07-11 06:36:22 -0300 | [diff] [blame] | 3345 | dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3346 | v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE); |
| 3347 | |
| 3348 | ctx->gopcounter--; |
| 3349 | if (ctx->gopcounter < 0) |
| 3350 | ctx->gopcounter = ctx->params.gop_size - 1; |
| 3351 | |
| 3352 | v4l2_dbg(1, coda_debug, &dev->v4l2_dev, |
| 3353 | "job finished: encoding frame (%d) (%s)\n", |
| 3354 | dst_buf->v4l2_buf.sequence, |
| 3355 | (dst_buf->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) ? |
| 3356 | "KEYFRAME" : "PFRAME"); |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | static irqreturn_t coda_irq_handler(int irq, void *data) |
| 3360 | { |
| 3361 | struct coda_dev *dev = data; |
| 3362 | struct coda_ctx *ctx; |
| 3363 | |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 3364 | /* read status register to attend the IRQ */ |
| 3365 | coda_read(dev, CODA_REG_BIT_INT_STATUS); |
| 3366 | coda_write(dev, CODA_REG_BIT_INT_CLEAR_SET, |
| 3367 | CODA_REG_BIT_INT_CLEAR); |
| 3368 | |
| 3369 | ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); |
| 3370 | if (ctx == NULL) { |
| 3371 | v4l2_err(&dev->v4l2_dev, "Instance released before the end of transaction\n"); |
| 3372 | mutex_unlock(&dev->coda_mutex); |
| 3373 | return IRQ_HANDLED; |
| 3374 | } |
| 3375 | |
| 3376 | if (ctx->aborting) { |
| 3377 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 3378 | "task has been aborted\n"); |
Philipp Zabel | 477c1cf | 2013-06-21 03:55:33 -0300 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | if (coda_isbusy(ctx->dev)) { |
| 3382 | v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, |
| 3383 | "coda is still busy!!!!\n"); |
| 3384 | return IRQ_NONE; |
| 3385 | } |
| 3386 | |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 3387 | complete(&ctx->completion); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3388 | |
| 3389 | return IRQ_HANDLED; |
| 3390 | } |
| 3391 | |
| 3392 | static u32 coda_supported_firmwares[] = { |
| 3393 | CODA_FIRMWARE_VERNUM(CODA_DX6, 2, 2, 5), |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3394 | CODA_FIRMWARE_VERNUM(CODA_7541, 1, 4, 50), |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3395 | CODA_FIRMWARE_VERNUM(CODA_960, 2, 1, 5), |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3396 | }; |
| 3397 | |
| 3398 | static bool coda_firmware_supported(u32 vernum) |
| 3399 | { |
| 3400 | int i; |
| 3401 | |
| 3402 | for (i = 0; i < ARRAY_SIZE(coda_supported_firmwares); i++) |
| 3403 | if (vernum == coda_supported_firmwares[i]) |
| 3404 | return true; |
| 3405 | return false; |
| 3406 | } |
| 3407 | |
Philipp Zabel | 87048bb | 2012-07-02 07:03:43 -0300 | [diff] [blame] | 3408 | static int coda_hw_init(struct coda_dev *dev) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3409 | { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3410 | u32 data; |
| 3411 | u16 *p; |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 3412 | int i, ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3413 | |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 3414 | ret = clk_prepare_enable(dev->clk_per); |
| 3415 | if (ret) |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3416 | goto err_clk_per; |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 3417 | |
| 3418 | ret = clk_prepare_enable(dev->clk_ahb); |
| 3419 | if (ret) |
| 3420 | goto err_clk_ahb; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3421 | |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 3422 | if (dev->rstc) |
| 3423 | reset_control_reset(dev->rstc); |
| 3424 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3425 | /* |
| 3426 | * Copy the first CODA_ISRAM_SIZE in the internal SRAM. |
Philipp Zabel | 87048bb | 2012-07-02 07:03:43 -0300 | [diff] [blame] | 3427 | * The 16-bit chars in the code buffer are in memory access |
| 3428 | * order, re-sort them to CODA order for register download. |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3429 | * Data in this SRAM survives a reboot. |
| 3430 | */ |
Philipp Zabel | 87048bb | 2012-07-02 07:03:43 -0300 | [diff] [blame] | 3431 | p = (u16 *)dev->codebuf.vaddr; |
| 3432 | if (dev->devtype->product == CODA_DX6) { |
| 3433 | for (i = 0; i < (CODA_ISRAM_SIZE / 2); i++) { |
| 3434 | data = CODA_DOWN_ADDRESS_SET(i) | |
| 3435 | CODA_DOWN_DATA_SET(p[i ^ 1]); |
| 3436 | coda_write(dev, data, CODA_REG_BIT_CODE_DOWN); |
| 3437 | } |
| 3438 | } else { |
| 3439 | for (i = 0; i < (CODA_ISRAM_SIZE / 2); i++) { |
| 3440 | data = CODA_DOWN_ADDRESS_SET(i) | |
| 3441 | CODA_DOWN_DATA_SET(p[round_down(i, 4) + |
| 3442 | 3 - (i % 4)]); |
| 3443 | coda_write(dev, data, CODA_REG_BIT_CODE_DOWN); |
| 3444 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3445 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3446 | |
Philipp Zabel | 9acf769 | 2013-05-23 10:42:56 -0300 | [diff] [blame] | 3447 | /* Clear registers */ |
| 3448 | for (i = 0; i < 64; i++) |
| 3449 | coda_write(dev, 0, CODA_REG_BIT_CODE_BUF_ADDR + i * 4); |
| 3450 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3451 | /* Tell the BIT where to find everything it needs */ |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3452 | if (dev->devtype->product == CODA_960 || |
| 3453 | dev->devtype->product == CODA_7541) { |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3454 | coda_write(dev, dev->tempbuf.paddr, |
| 3455 | CODA_REG_BIT_TEMP_BUF_ADDR); |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3456 | coda_write(dev, 0, CODA_REG_BIT_BIT_STREAM_PARAM); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3457 | } else { |
| 3458 | coda_write(dev, dev->workbuf.paddr, |
| 3459 | CODA_REG_BIT_WORK_BUF_ADDR); |
| 3460 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3461 | coda_write(dev, dev->codebuf.paddr, |
| 3462 | CODA_REG_BIT_CODE_BUF_ADDR); |
| 3463 | coda_write(dev, 0, CODA_REG_BIT_CODE_RUN); |
| 3464 | |
| 3465 | /* Set default values */ |
| 3466 | switch (dev->devtype->product) { |
| 3467 | case CODA_DX6: |
| 3468 | coda_write(dev, CODADX6_STREAM_BUF_PIC_FLUSH, CODA_REG_BIT_STREAM_CTRL); |
| 3469 | break; |
| 3470 | default: |
| 3471 | coda_write(dev, CODA7_STREAM_BUF_PIC_FLUSH, CODA_REG_BIT_STREAM_CTRL); |
| 3472 | } |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3473 | if (dev->devtype->product == CODA_960) |
| 3474 | coda_write(dev, 1 << 12, CODA_REG_BIT_FRAME_MEM_CTRL); |
| 3475 | else |
| 3476 | coda_write(dev, 0, CODA_REG_BIT_FRAME_MEM_CTRL); |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 3477 | |
| 3478 | if (dev->devtype->product != CODA_DX6) |
| 3479 | coda_write(dev, 0, CODA7_REG_BIT_AXI_SRAM_USE); |
| 3480 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3481 | coda_write(dev, CODA_INT_INTERRUPT_ENABLE, |
| 3482 | CODA_REG_BIT_INT_ENABLE); |
| 3483 | |
| 3484 | /* Reset VPU and start processor */ |
| 3485 | data = coda_read(dev, CODA_REG_BIT_CODE_RESET); |
| 3486 | data |= CODA_REG_RESET_ENABLE; |
| 3487 | coda_write(dev, data, CODA_REG_BIT_CODE_RESET); |
| 3488 | udelay(10); |
| 3489 | data &= ~CODA_REG_RESET_ENABLE; |
| 3490 | coda_write(dev, data, CODA_REG_BIT_CODE_RESET); |
| 3491 | coda_write(dev, CODA_REG_RUN_ENABLE, CODA_REG_BIT_CODE_RUN); |
| 3492 | |
Philipp Zabel | fe7554e | 2014-07-11 06:36:24 -0300 | [diff] [blame] | 3493 | clk_disable_unprepare(dev->clk_ahb); |
| 3494 | clk_disable_unprepare(dev->clk_per); |
| 3495 | |
| 3496 | return 0; |
| 3497 | |
| 3498 | err_clk_ahb: |
| 3499 | clk_disable_unprepare(dev->clk_per); |
| 3500 | err_clk_per: |
| 3501 | return ret; |
| 3502 | } |
| 3503 | |
| 3504 | static int coda_check_firmware(struct coda_dev *dev) |
| 3505 | { |
| 3506 | u16 product, major, minor, release; |
| 3507 | u32 data; |
| 3508 | int ret; |
| 3509 | |
| 3510 | ret = clk_prepare_enable(dev->clk_per); |
| 3511 | if (ret) |
| 3512 | goto err_clk_per; |
| 3513 | |
| 3514 | ret = clk_prepare_enable(dev->clk_ahb); |
| 3515 | if (ret) |
| 3516 | goto err_clk_ahb; |
| 3517 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3518 | coda_write(dev, 0, CODA_CMD_FIRMWARE_VERNUM); |
| 3519 | coda_write(dev, CODA_REG_BIT_BUSY_FLAG, CODA_REG_BIT_BUSY); |
| 3520 | coda_write(dev, 0, CODA_REG_BIT_RUN_INDEX); |
| 3521 | coda_write(dev, 0, CODA_REG_BIT_RUN_COD_STD); |
| 3522 | coda_write(dev, CODA_COMMAND_FIRMWARE_GET, CODA_REG_BIT_RUN_COMMAND); |
| 3523 | if (coda_wait_timeout(dev)) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3524 | v4l2_err(&dev->v4l2_dev, "firmware get command error\n"); |
Philipp Zabel | fe7554e | 2014-07-11 06:36:24 -0300 | [diff] [blame] | 3525 | ret = -EIO; |
| 3526 | goto err_run_cmd; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3527 | } |
| 3528 | |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3529 | if (dev->devtype->product == CODA_960) { |
| 3530 | data = coda_read(dev, CODA9_CMD_FIRMWARE_CODE_REV); |
| 3531 | v4l2_info(&dev->v4l2_dev, "Firmware code revision: %d\n", |
| 3532 | data); |
| 3533 | } |
| 3534 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3535 | /* Check we are compatible with the loaded firmware */ |
| 3536 | data = coda_read(dev, CODA_CMD_FIRMWARE_VERNUM); |
| 3537 | product = CODA_FIRMWARE_PRODUCT(data); |
| 3538 | major = CODA_FIRMWARE_MAJOR(data); |
| 3539 | minor = CODA_FIRMWARE_MINOR(data); |
| 3540 | release = CODA_FIRMWARE_RELEASE(data); |
| 3541 | |
| 3542 | clk_disable_unprepare(dev->clk_per); |
| 3543 | clk_disable_unprepare(dev->clk_ahb); |
| 3544 | |
| 3545 | if (product != dev->devtype->product) { |
| 3546 | v4l2_err(&dev->v4l2_dev, "Wrong firmware. Hw: %s, Fw: %s," |
| 3547 | " Version: %u.%u.%u\n", |
| 3548 | coda_product_name(dev->devtype->product), |
| 3549 | coda_product_name(product), major, minor, release); |
| 3550 | return -EINVAL; |
| 3551 | } |
| 3552 | |
| 3553 | v4l2_info(&dev->v4l2_dev, "Initialized %s.\n", |
| 3554 | coda_product_name(product)); |
| 3555 | |
| 3556 | if (coda_firmware_supported(data)) { |
| 3557 | v4l2_info(&dev->v4l2_dev, "Firmware version: %u.%u.%u\n", |
| 3558 | major, minor, release); |
| 3559 | } else { |
| 3560 | v4l2_warn(&dev->v4l2_dev, "Unsupported firmware version: " |
| 3561 | "%u.%u.%u\n", major, minor, release); |
| 3562 | } |
| 3563 | |
| 3564 | return 0; |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 3565 | |
Philipp Zabel | fe7554e | 2014-07-11 06:36:24 -0300 | [diff] [blame] | 3566 | err_run_cmd: |
| 3567 | clk_disable_unprepare(dev->clk_ahb); |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 3568 | err_clk_ahb: |
| 3569 | clk_disable_unprepare(dev->clk_per); |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3570 | err_clk_per: |
Fabio Estevam | 79830db | 2013-08-21 11:14:17 -0300 | [diff] [blame] | 3571 | return ret; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | static void coda_fw_callback(const struct firmware *fw, void *context) |
| 3575 | { |
| 3576 | struct coda_dev *dev = context; |
| 3577 | struct platform_device *pdev = dev->plat_dev; |
| 3578 | int ret; |
| 3579 | |
| 3580 | if (!fw) { |
| 3581 | v4l2_err(&dev->v4l2_dev, "firmware request failed\n"); |
| 3582 | return; |
| 3583 | } |
| 3584 | |
| 3585 | /* allocate auxiliary per-device code buffer for the BIT processor */ |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 3586 | ret = coda_alloc_aux_buf(dev, &dev->codebuf, fw->size, "codebuf", |
| 3587 | dev->debugfs_root); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3588 | if (ret < 0) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3589 | dev_err(&pdev->dev, "failed to allocate code buffer\n"); |
| 3590 | return; |
| 3591 | } |
| 3592 | |
Philipp Zabel | 87048bb | 2012-07-02 07:03:43 -0300 | [diff] [blame] | 3593 | /* Copy the whole firmware image to the code buffer */ |
| 3594 | memcpy(dev->codebuf.vaddr, fw->data, fw->size); |
| 3595 | release_firmware(fw); |
| 3596 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3597 | if (pm_runtime_enabled(&pdev->dev) && pdev->dev.pm_domain) { |
| 3598 | /* |
| 3599 | * Enabling power temporarily will cause coda_hw_init to be |
| 3600 | * called via coda_runtime_resume by the pm domain. |
| 3601 | */ |
| 3602 | ret = pm_runtime_get_sync(&dev->plat_dev->dev); |
| 3603 | if (ret < 0) { |
| 3604 | v4l2_err(&dev->v4l2_dev, "failed to power on: %d\n", |
| 3605 | ret); |
| 3606 | return; |
| 3607 | } |
| 3608 | |
Philipp Zabel | fe7554e | 2014-07-11 06:36:24 -0300 | [diff] [blame] | 3609 | ret = coda_check_firmware(dev); |
| 3610 | if (ret < 0) |
| 3611 | return; |
| 3612 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3613 | pm_runtime_put_sync(&dev->plat_dev->dev); |
| 3614 | } else { |
| 3615 | /* |
| 3616 | * If runtime pm is disabled or pm_domain is not set, |
| 3617 | * initialize once manually. |
| 3618 | */ |
| 3619 | ret = coda_hw_init(dev); |
| 3620 | if (ret < 0) { |
| 3621 | v4l2_err(&dev->v4l2_dev, "HW initialization failed\n"); |
| 3622 | return; |
| 3623 | } |
Philipp Zabel | fe7554e | 2014-07-11 06:36:24 -0300 | [diff] [blame] | 3624 | |
| 3625 | ret = coda_check_firmware(dev); |
| 3626 | if (ret < 0) |
| 3627 | return; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | dev->vfd.fops = &coda_fops, |
| 3631 | dev->vfd.ioctl_ops = &coda_ioctl_ops; |
| 3632 | dev->vfd.release = video_device_release_empty, |
| 3633 | dev->vfd.lock = &dev->dev_mutex; |
| 3634 | dev->vfd.v4l2_dev = &dev->v4l2_dev; |
Hans Verkuil | 954f340 | 2012-09-05 06:05:50 -0300 | [diff] [blame] | 3635 | dev->vfd.vfl_dir = VFL_DIR_M2M; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3636 | snprintf(dev->vfd.name, sizeof(dev->vfd.name), "%s", CODA_NAME); |
| 3637 | video_set_drvdata(&dev->vfd, dev); |
| 3638 | |
| 3639 | dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); |
| 3640 | if (IS_ERR(dev->alloc_ctx)) { |
| 3641 | v4l2_err(&dev->v4l2_dev, "Failed to alloc vb2 context\n"); |
| 3642 | return; |
| 3643 | } |
| 3644 | |
| 3645 | dev->m2m_dev = v4l2_m2m_init(&coda_m2m_ops); |
| 3646 | if (IS_ERR(dev->m2m_dev)) { |
| 3647 | v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n"); |
| 3648 | goto rel_ctx; |
| 3649 | } |
| 3650 | |
| 3651 | ret = video_register_device(&dev->vfd, VFL_TYPE_GRABBER, 0); |
| 3652 | if (ret) { |
| 3653 | v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); |
| 3654 | goto rel_m2m; |
| 3655 | } |
| 3656 | v4l2_info(&dev->v4l2_dev, "codec registered as /dev/video%d\n", |
| 3657 | dev->vfd.num); |
| 3658 | |
| 3659 | return; |
| 3660 | |
| 3661 | rel_m2m: |
| 3662 | v4l2_m2m_release(dev->m2m_dev); |
| 3663 | rel_ctx: |
| 3664 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); |
| 3665 | } |
| 3666 | |
| 3667 | static int coda_firmware_request(struct coda_dev *dev) |
| 3668 | { |
| 3669 | char *fw = dev->devtype->firmware; |
| 3670 | |
| 3671 | dev_dbg(&dev->plat_dev->dev, "requesting firmware '%s' for %s\n", fw, |
| 3672 | coda_product_name(dev->devtype->product)); |
| 3673 | |
| 3674 | return request_firmware_nowait(THIS_MODULE, true, |
| 3675 | fw, &dev->plat_dev->dev, GFP_KERNEL, dev, coda_fw_callback); |
| 3676 | } |
| 3677 | |
| 3678 | enum coda_platform { |
| 3679 | CODA_IMX27, |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 3680 | CODA_IMX53, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3681 | CODA_IMX6Q, |
| 3682 | CODA_IMX6DL, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3683 | }; |
| 3684 | |
Emil Goode | c06d875 | 2012-08-14 17:44:42 -0300 | [diff] [blame] | 3685 | static const struct coda_devtype coda_devdata[] = { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3686 | [CODA_IMX27] = { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 3687 | .firmware = "v4l-codadx6-imx27.bin", |
| 3688 | .product = CODA_DX6, |
| 3689 | .codecs = codadx6_codecs, |
| 3690 | .num_codecs = ARRAY_SIZE(codadx6_codecs), |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3691 | }, |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 3692 | [CODA_IMX53] = { |
Philipp Zabel | b96904e | 2013-05-23 10:42:58 -0300 | [diff] [blame] | 3693 | .firmware = "v4l-coda7541-imx53.bin", |
| 3694 | .product = CODA_7541, |
| 3695 | .codecs = coda7_codecs, |
| 3696 | .num_codecs = ARRAY_SIZE(coda7_codecs), |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 3697 | }, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3698 | [CODA_IMX6Q] = { |
| 3699 | .firmware = "v4l-coda960-imx6q.bin", |
| 3700 | .product = CODA_960, |
| 3701 | .codecs = coda9_codecs, |
| 3702 | .num_codecs = ARRAY_SIZE(coda9_codecs), |
| 3703 | }, |
| 3704 | [CODA_IMX6DL] = { |
| 3705 | .firmware = "v4l-coda960-imx6dl.bin", |
| 3706 | .product = CODA_960, |
| 3707 | .codecs = coda9_codecs, |
| 3708 | .num_codecs = ARRAY_SIZE(coda9_codecs), |
| 3709 | }, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3710 | }; |
| 3711 | |
| 3712 | static struct platform_device_id coda_platform_ids[] = { |
| 3713 | { .name = "coda-imx27", .driver_data = CODA_IMX27 }, |
Fabio Estevam | 4e44cd0 | 2012-10-10 00:07:38 -0300 | [diff] [blame] | 3714 | { .name = "coda-imx53", .driver_data = CODA_IMX53 }, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3715 | { /* sentinel */ } |
| 3716 | }; |
| 3717 | MODULE_DEVICE_TABLE(platform, coda_platform_ids); |
| 3718 | |
| 3719 | #ifdef CONFIG_OF |
| 3720 | static const struct of_device_id coda_dt_ids[] = { |
Alexander Shiyan | 7b0dd9e | 2013-06-15 08:09:57 -0300 | [diff] [blame] | 3721 | { .compatible = "fsl,imx27-vpu", .data = &coda_devdata[CODA_IMX27] }, |
Philipp Zabel | df1e74c | 2012-07-02 06:07:10 -0300 | [diff] [blame] | 3722 | { .compatible = "fsl,imx53-vpu", .data = &coda_devdata[CODA_IMX53] }, |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3723 | { .compatible = "fsl,imx6q-vpu", .data = &coda_devdata[CODA_IMX6Q] }, |
| 3724 | { .compatible = "fsl,imx6dl-vpu", .data = &coda_devdata[CODA_IMX6DL] }, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3725 | { /* sentinel */ } |
| 3726 | }; |
| 3727 | MODULE_DEVICE_TABLE(of, coda_dt_ids); |
| 3728 | #endif |
| 3729 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 3730 | static int coda_probe(struct platform_device *pdev) |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3731 | { |
| 3732 | const struct of_device_id *of_id = |
| 3733 | of_match_device(of_match_ptr(coda_dt_ids), &pdev->dev); |
| 3734 | const struct platform_device_id *pdev_id; |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 3735 | struct coda_platform_data *pdata = pdev->dev.platform_data; |
| 3736 | struct device_node *np = pdev->dev.of_node; |
| 3737 | struct gen_pool *pool; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3738 | struct coda_dev *dev; |
| 3739 | struct resource *res; |
| 3740 | int ret, irq; |
| 3741 | |
| 3742 | dev = devm_kzalloc(&pdev->dev, sizeof *dev, GFP_KERNEL); |
| 3743 | if (!dev) { |
| 3744 | dev_err(&pdev->dev, "Not enough memory for %s\n", |
| 3745 | CODA_NAME); |
| 3746 | return -ENOMEM; |
| 3747 | } |
| 3748 | |
| 3749 | spin_lock_init(&dev->irqlock); |
Philipp Zabel | e11f3e6 | 2012-07-25 09:16:58 -0300 | [diff] [blame] | 3750 | INIT_LIST_HEAD(&dev->instances); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3751 | |
| 3752 | dev->plat_dev = pdev; |
| 3753 | dev->clk_per = devm_clk_get(&pdev->dev, "per"); |
| 3754 | if (IS_ERR(dev->clk_per)) { |
| 3755 | dev_err(&pdev->dev, "Could not get per clock\n"); |
| 3756 | return PTR_ERR(dev->clk_per); |
| 3757 | } |
| 3758 | |
| 3759 | dev->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); |
| 3760 | if (IS_ERR(dev->clk_ahb)) { |
| 3761 | dev_err(&pdev->dev, "Could not get ahb clock\n"); |
| 3762 | return PTR_ERR(dev->clk_ahb); |
| 3763 | } |
| 3764 | |
| 3765 | /* Get memory for physical registers */ |
| 3766 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Philipp Zabel | 611cbbf | 2013-05-21 04:19:27 -0300 | [diff] [blame] | 3767 | dev->regs_base = devm_ioremap_resource(&pdev->dev, res); |
| 3768 | if (IS_ERR(dev->regs_base)) |
| 3769 | return PTR_ERR(dev->regs_base); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3770 | |
| 3771 | /* IRQ */ |
| 3772 | irq = platform_get_irq(pdev, 0); |
| 3773 | if (irq < 0) { |
| 3774 | dev_err(&pdev->dev, "failed to get irq resource\n"); |
| 3775 | return -ENOENT; |
| 3776 | } |
| 3777 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3778 | if (devm_request_threaded_irq(&pdev->dev, irq, NULL, coda_irq_handler, |
Alexander Shiyan | 08a72e4 | 2014-04-26 06:14:46 -0300 | [diff] [blame] | 3779 | IRQF_ONESHOT, dev_name(&pdev->dev), dev) < 0) { |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3780 | dev_err(&pdev->dev, "failed to request irq\n"); |
| 3781 | return -ENOENT; |
| 3782 | } |
| 3783 | |
Philipp Zabel | 8f45284 | 2014-07-11 06:36:35 -0300 | [diff] [blame] | 3784 | dev->rstc = devm_reset_control_get(&pdev->dev, NULL); |
| 3785 | if (IS_ERR(dev->rstc)) { |
| 3786 | ret = PTR_ERR(dev->rstc); |
| 3787 | if (ret == -ENOENT) { |
| 3788 | dev->rstc = NULL; |
| 3789 | } else { |
| 3790 | dev_err(&pdev->dev, "failed get reset control: %d\n", ret); |
| 3791 | return ret; |
| 3792 | } |
| 3793 | } |
| 3794 | |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 3795 | /* Get IRAM pool from device tree or platform data */ |
| 3796 | pool = of_get_named_gen_pool(np, "iram", 0); |
| 3797 | if (!pool && pdata) |
| 3798 | pool = dev_get_gen_pool(pdata->iram_dev); |
| 3799 | if (!pool) { |
| 3800 | dev_err(&pdev->dev, "iram pool not available\n"); |
| 3801 | return -ENOMEM; |
| 3802 | } |
| 3803 | dev->iram_pool = pool; |
| 3804 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3805 | ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); |
| 3806 | if (ret) |
| 3807 | return ret; |
| 3808 | |
| 3809 | mutex_init(&dev->dev_mutex); |
Philipp Zabel | fcb6282 | 2013-05-23 10:43:00 -0300 | [diff] [blame] | 3810 | mutex_init(&dev->coda_mutex); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3811 | |
| 3812 | pdev_id = of_id ? of_id->data : platform_get_device_id(pdev); |
| 3813 | |
| 3814 | if (of_id) { |
| 3815 | dev->devtype = of_id->data; |
| 3816 | } else if (pdev_id) { |
| 3817 | dev->devtype = &coda_devdata[pdev_id->driver_data]; |
| 3818 | } else { |
| 3819 | v4l2_device_unregister(&dev->v4l2_dev); |
| 3820 | return -EINVAL; |
| 3821 | } |
| 3822 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 3823 | dev->debugfs_root = debugfs_create_dir("coda", NULL); |
| 3824 | if (!dev->debugfs_root) |
| 3825 | dev_warn(&pdev->dev, "failed to create debugfs root\n"); |
| 3826 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3827 | /* allocate auxiliary per-device buffers for the BIT processor */ |
| 3828 | switch (dev->devtype->product) { |
| 3829 | case CODA_DX6: |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3830 | ret = coda_alloc_aux_buf(dev, &dev->workbuf, |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 3831 | CODADX6_WORK_BUF_SIZE, "workbuf", |
| 3832 | dev->debugfs_root); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3833 | if (ret < 0) { |
| 3834 | dev_err(&pdev->dev, "failed to allocate work buffer\n"); |
| 3835 | v4l2_device_unregister(&dev->v4l2_dev); |
| 3836 | return ret; |
| 3837 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3838 | break; |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3839 | case CODA_7541: |
| 3840 | dev->tempbuf.size = CODA7_TEMP_BUF_SIZE; |
| 3841 | break; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3842 | case CODA_960: |
| 3843 | dev->tempbuf.size = CODA9_TEMP_BUF_SIZE; |
| 3844 | break; |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3845 | } |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3846 | if (dev->tempbuf.size) { |
| 3847 | ret = coda_alloc_aux_buf(dev, &dev->tempbuf, |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 3848 | dev->tempbuf.size, "tempbuf", |
| 3849 | dev->debugfs_root); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3850 | if (ret < 0) { |
| 3851 | dev_err(&pdev->dev, "failed to allocate temp buffer\n"); |
| 3852 | v4l2_device_unregister(&dev->v4l2_dev); |
| 3853 | return ret; |
| 3854 | } |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3855 | } |
| 3856 | |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3857 | switch (dev->devtype->product) { |
| 3858 | case CODA_DX6: |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 3859 | dev->iram.size = CODADX6_IRAM_SIZE; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3860 | break; |
| 3861 | case CODA_7541: |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 3862 | dev->iram.size = CODA7_IRAM_SIZE; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3863 | break; |
Philipp Zabel | 8954844 | 2014-07-11 06:36:17 -0300 | [diff] [blame] | 3864 | case CODA_960: |
| 3865 | dev->iram.size = CODA9_IRAM_SIZE; |
Philipp Zabel | 918c66f | 2013-06-27 06:59:01 -0300 | [diff] [blame] | 3866 | } |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 3867 | dev->iram.vaddr = gen_pool_dma_alloc(dev->iram_pool, dev->iram.size, |
| 3868 | &dev->iram.paddr); |
| 3869 | if (!dev->iram.vaddr) { |
Philipp Zabel | 657eee7 | 2013-04-29 16:17:14 -0700 | [diff] [blame] | 3870 | dev_err(&pdev->dev, "unable to alloc iram\n"); |
| 3871 | return -ENOMEM; |
Philipp Zabel | 1043667 | 2012-07-02 09:03:55 -0300 | [diff] [blame] | 3872 | } |
| 3873 | |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 3874 | dev->iram.blob.data = dev->iram.vaddr; |
| 3875 | dev->iram.blob.size = dev->iram.size; |
| 3876 | dev->iram.dentry = debugfs_create_blob("iram", 0644, dev->debugfs_root, |
| 3877 | &dev->iram.blob); |
| 3878 | |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 3879 | dev->workqueue = alloc_workqueue("coda", WQ_UNBOUND | WQ_MEM_RECLAIM, 1); |
| 3880 | if (!dev->workqueue) { |
| 3881 | dev_err(&pdev->dev, "unable to alloc workqueue\n"); |
| 3882 | return -ENOMEM; |
| 3883 | } |
| 3884 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3885 | platform_set_drvdata(pdev, dev); |
| 3886 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3887 | pm_runtime_enable(&pdev->dev); |
| 3888 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3889 | return coda_firmware_request(dev); |
| 3890 | } |
| 3891 | |
| 3892 | static int coda_remove(struct platform_device *pdev) |
| 3893 | { |
| 3894 | struct coda_dev *dev = platform_get_drvdata(pdev); |
| 3895 | |
| 3896 | video_unregister_device(&dev->vfd); |
| 3897 | if (dev->m2m_dev) |
| 3898 | v4l2_m2m_release(dev->m2m_dev); |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3899 | pm_runtime_disable(&pdev->dev); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3900 | if (dev->alloc_ctx) |
| 3901 | vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); |
| 3902 | v4l2_device_unregister(&dev->v4l2_dev); |
Philipp Zabel | 32b6f20 | 2014-07-11 06:36:20 -0300 | [diff] [blame] | 3903 | destroy_workqueue(dev->workqueue); |
Philipp Zabel | b313bcc | 2014-07-11 06:36:16 -0300 | [diff] [blame] | 3904 | if (dev->iram.vaddr) |
| 3905 | gen_pool_free(dev->iram_pool, (unsigned long)dev->iram.vaddr, |
| 3906 | dev->iram.size); |
Philipp Zabel | 5677e3b | 2013-06-21 03:55:30 -0300 | [diff] [blame] | 3907 | coda_free_aux_buf(dev, &dev->codebuf); |
| 3908 | coda_free_aux_buf(dev, &dev->tempbuf); |
| 3909 | coda_free_aux_buf(dev, &dev->workbuf); |
Philipp Zabel | f61c0b1 | 2014-07-11 06:36:40 -0300 | [diff] [blame^] | 3910 | debugfs_remove_recursive(dev->debugfs_root); |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3911 | return 0; |
| 3912 | } |
| 3913 | |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3914 | #ifdef CONFIG_PM_RUNTIME |
| 3915 | static int coda_runtime_resume(struct device *dev) |
| 3916 | { |
| 3917 | struct coda_dev *cdev = dev_get_drvdata(dev); |
| 3918 | int ret = 0; |
| 3919 | |
| 3920 | if (dev->pm_domain) { |
| 3921 | ret = coda_hw_init(cdev); |
| 3922 | if (ret) |
| 3923 | v4l2_err(&cdev->v4l2_dev, "HW initialization failed\n"); |
| 3924 | } |
| 3925 | |
| 3926 | return ret; |
| 3927 | } |
| 3928 | #endif |
| 3929 | |
| 3930 | static const struct dev_pm_ops coda_pm_ops = { |
| 3931 | SET_RUNTIME_PM_OPS(NULL, coda_runtime_resume, NULL) |
| 3932 | }; |
| 3933 | |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3934 | static struct platform_driver coda_driver = { |
| 3935 | .probe = coda_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 3936 | .remove = coda_remove, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3937 | .driver = { |
| 3938 | .name = CODA_NAME, |
| 3939 | .owner = THIS_MODULE, |
| 3940 | .of_match_table = of_match_ptr(coda_dt_ids), |
Philipp Zabel | 1e17273 | 2014-07-11 06:36:23 -0300 | [diff] [blame] | 3941 | .pm = &coda_pm_ops, |
Javier Martin | 186b250 | 2012-07-26 05:53:35 -0300 | [diff] [blame] | 3942 | }, |
| 3943 | .id_table = coda_platform_ids, |
| 3944 | }; |
| 3945 | |
| 3946 | module_platform_driver(coda_driver); |
| 3947 | |
| 3948 | MODULE_LICENSE("GPL"); |
| 3949 | MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>"); |
| 3950 | MODULE_DESCRIPTION("Coda multi-standard codec V4L2 driver"); |