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