Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1 | /* |
Sylwester Nawrocki | 0c9204d | 2012-04-25 06:55:42 -0300 | [diff] [blame] | 2 | * Copyright (C) 2010 - 2012 Samsung Electronics Co., Ltd. |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #ifndef FIMC_CORE_H_ |
| 10 | #define FIMC_CORE_H_ |
| 11 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 12 | /*#define DEBUG*/ |
| 13 | |
Sylwester Nawrocki | 2319c53 | 2011-07-26 18:29:50 -0300 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Sylwester Nawrocki | aee7126 | 2010-11-22 14:49:06 -0300 | [diff] [blame] | 15 | #include <linux/sched.h> |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 16 | #include <linux/spinlock.h> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 17 | #include <linux/types.h> |
Sylwester Nawrocki | aee7126 | 2010-11-22 14:49:06 -0300 | [diff] [blame] | 18 | #include <linux/videodev2.h> |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 19 | #include <linux/io.h> |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 20 | #include <asm/sizes.h> |
Sylwester Nawrocki | 574e171 | 2011-07-26 18:08:21 -0300 | [diff] [blame] | 21 | |
| 22 | #include <media/media-entity.h> |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 23 | #include <media/videobuf2-core.h> |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 24 | #include <media/v4l2-ctrls.h> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 25 | #include <media/v4l2-device.h> |
| 26 | #include <media/v4l2-mem2mem.h> |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 27 | #include <media/v4l2-mediabus.h> |
Sylwester Nawrocki | df7e09a | 2010-12-27 14:42:15 -0300 | [diff] [blame] | 28 | #include <media/s5p_fimc.h> |
Sylwester Nawrocki | aee7126 | 2010-11-22 14:49:06 -0300 | [diff] [blame] | 29 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 30 | #define err(fmt, args...) \ |
| 31 | printk(KERN_ERR "%s:%d: " fmt "\n", __func__, __LINE__, ##args) |
| 32 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 33 | #define dbg(fmt, args...) \ |
Sylwester Nawrocki | 1e00469 | 2011-02-23 08:17:57 -0300 | [diff] [blame] | 34 | pr_debug("%s:%d: " fmt "\n", __func__, __LINE__, ##args) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 35 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 36 | /* Time to wait for next frame VSYNC interrupt while stopping operation. */ |
| 37 | #define FIMC_SHUTDOWN_TIMEOUT ((100*HZ)/1000) |
Sylwester Nawrocki | ebdfea8 | 2011-06-10 15:36:45 -0300 | [diff] [blame] | 38 | #define MAX_FIMC_CLOCKS 2 |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 39 | #define FIMC_MODULE_NAME "s5p-fimc" |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 40 | #define FIMC_MAX_DEVS 4 |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 41 | #define FIMC_MAX_OUT_BUFS 4 |
| 42 | #define SCALER_MAX_HRATIO 64 |
| 43 | #define SCALER_MAX_VRATIO 64 |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 44 | #define DMA_MIN_SIZE 8 |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 45 | #define FIMC_CAMIF_MAX_HEIGHT 0x2000 |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 46 | |
Sylwester Nawrocki | a25be18 | 2010-12-27 15:34:43 -0300 | [diff] [blame] | 47 | /* indices to the clocks array */ |
| 48 | enum { |
| 49 | CLK_BUS, |
| 50 | CLK_GATE, |
Sylwester Nawrocki | a25be18 | 2010-12-27 15:34:43 -0300 | [diff] [blame] | 51 | }; |
| 52 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 53 | enum fimc_dev_flags { |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 54 | ST_LPM, |
| 55 | /* m2m node */ |
| 56 | ST_M2M_RUN, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 57 | ST_M2M_PEND, |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 58 | ST_M2M_SUSPENDING, |
| 59 | ST_M2M_SUSPENDED, |
| 60 | /* capture node */ |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 61 | ST_CAPT_PEND, |
| 62 | ST_CAPT_RUN, |
| 63 | ST_CAPT_STREAM, |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 64 | ST_CAPT_ISP_STREAM, |
Sylwester Nawrocki | 3e4748d | 2011-08-24 20:45:34 -0300 | [diff] [blame] | 65 | ST_CAPT_SUSPENDED, |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 66 | ST_CAPT_SHUT, |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 67 | ST_CAPT_BUSY, |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 68 | ST_CAPT_APPLY_CFG, |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 69 | ST_CAPT_JPEG, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 70 | }; |
| 71 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 72 | #define fimc_m2m_active(dev) test_bit(ST_M2M_RUN, &(dev)->state) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 73 | #define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state) |
| 74 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 75 | #define fimc_capture_running(dev) test_bit(ST_CAPT_RUN, &(dev)->state) |
| 76 | #define fimc_capture_pending(dev) test_bit(ST_CAPT_PEND, &(dev)->state) |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 77 | #define fimc_capture_busy(dev) test_bit(ST_CAPT_BUSY, &(dev)->state) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 78 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 79 | enum fimc_datapath { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 80 | FIMC_IO_NONE, |
| 81 | FIMC_IO_CAMERA, |
| 82 | FIMC_IO_DMA, |
| 83 | FIMC_IO_LCDFIFO, |
| 84 | FIMC_IO_WRITEBACK, |
| 85 | FIMC_IO_ISP, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | enum fimc_color_fmt { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 89 | FIMC_FMT_RGB444 = 0x10, |
| 90 | FIMC_FMT_RGB555, |
| 91 | FIMC_FMT_RGB565, |
| 92 | FIMC_FMT_RGB666, |
| 93 | FIMC_FMT_RGB888, |
| 94 | FIMC_FMT_RGB30_LOCAL, |
| 95 | FIMC_FMT_YCBCR420 = 0x20, |
| 96 | FIMC_FMT_YCBYCR422, |
| 97 | FIMC_FMT_YCRYCB422, |
| 98 | FIMC_FMT_CBYCRY422, |
| 99 | FIMC_FMT_CRYCBY422, |
| 100 | FIMC_FMT_YCBCR444_LOCAL, |
| 101 | FIMC_FMT_JPEG = 0x40, |
| 102 | FIMC_FMT_RAW8 = 0x80, |
| 103 | FIMC_FMT_RAW10, |
| 104 | FIMC_FMT_RAW12, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 105 | }; |
| 106 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 107 | #define fimc_fmt_is_rgb(x) (!!((x) & 0x10)) |
| 108 | #define fimc_fmt_is_jpeg(x) (!!((x) & 0x40)) |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 109 | |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 110 | #define IS_M2M(__strt) ((__strt) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || \ |
| 111 | __strt == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) |
| 112 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 113 | /* The hardware context state. */ |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 114 | #define FIMC_PARAMS (1 << 0) |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 115 | #define FIMC_SRC_FMT (1 << 3) |
| 116 | #define FIMC_DST_FMT (1 << 4) |
Sylwester Nawrocki | fed07f8 | 2012-04-29 17:46:03 -0300 | [diff] [blame^] | 117 | #define FIMC_COMPOSE (1 << 5) |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 118 | #define FIMC_CTX_M2M (1 << 16) |
| 119 | #define FIMC_CTX_CAP (1 << 17) |
| 120 | #define FIMC_CTX_SHUT (1 << 18) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 121 | |
| 122 | /* Image conversion flags */ |
| 123 | #define FIMC_IN_DMA_ACCESS_TILED (1 << 0) |
| 124 | #define FIMC_IN_DMA_ACCESS_LINEAR (0 << 0) |
| 125 | #define FIMC_OUT_DMA_ACCESS_TILED (1 << 1) |
| 126 | #define FIMC_OUT_DMA_ACCESS_LINEAR (0 << 1) |
| 127 | #define FIMC_SCAN_MODE_PROGRESSIVE (0 << 2) |
| 128 | #define FIMC_SCAN_MODE_INTERLACED (1 << 2) |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 129 | /* |
| 130 | * YCbCr data dynamic range for RGB-YUV color conversion. |
| 131 | * Y/Cb/Cr: (0 ~ 255) */ |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 132 | #define FIMC_COLOR_RANGE_WIDE (0 << 3) |
| 133 | /* Y (16 ~ 235), Cb/Cr (16 ~ 240) */ |
| 134 | #define FIMC_COLOR_RANGE_NARROW (1 << 3) |
| 135 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 136 | /** |
| 137 | * struct fimc_fmt - the driver's internal color format data |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 138 | * @mbus_code: Media Bus pixel code, -1 if not applicable |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 139 | * @name: format description |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 140 | * @fourcc: the fourcc code for this format, 0 if not applicable |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 141 | * @color: the corresponding fimc_color_fmt |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 142 | * @memplanes: number of physically non-contiguous data planes |
| 143 | * @colplanes: number of physically contiguous data planes |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 144 | * @depth: per plane driver's private 'number of bits per pixel' |
| 145 | * @flags: flags indicating which operation mode format applies to |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 146 | */ |
| 147 | struct fimc_fmt { |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 148 | enum v4l2_mbus_pixelcode mbus_code; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 149 | char *name; |
| 150 | u32 fourcc; |
| 151 | u32 color; |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 152 | u16 memplanes; |
| 153 | u16 colplanes; |
| 154 | u8 depth[VIDEO_MAX_PLANES]; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 155 | u16 flags; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 156 | #define FMT_FLAGS_CAM (1 << 0) |
| 157 | #define FMT_FLAGS_M2M_IN (1 << 1) |
| 158 | #define FMT_FLAGS_M2M_OUT (1 << 2) |
| 159 | #define FMT_FLAGS_M2M (1 << 1 | 1 << 2) |
| 160 | #define FMT_HAS_ALPHA (1 << 3) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | /** |
| 164 | * struct fimc_dma_offset - pixel offset information for DMA |
| 165 | * @y_h: y value horizontal offset |
| 166 | * @y_v: y value vertical offset |
| 167 | * @cb_h: cb value horizontal offset |
| 168 | * @cb_v: cb value vertical offset |
| 169 | * @cr_h: cr value horizontal offset |
| 170 | * @cr_v: cr value vertical offset |
| 171 | */ |
| 172 | struct fimc_dma_offset { |
| 173 | int y_h; |
| 174 | int y_v; |
| 175 | int cb_h; |
| 176 | int cb_v; |
| 177 | int cr_h; |
| 178 | int cr_v; |
| 179 | }; |
| 180 | |
| 181 | /** |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 182 | * struct fimc_effect - color effect information |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 183 | * @type: effect type |
| 184 | * @pat_cb: cr value when type is "arbitrary" |
| 185 | * @pat_cr: cr value when type is "arbitrary" |
| 186 | */ |
| 187 | struct fimc_effect { |
| 188 | u32 type; |
| 189 | u8 pat_cb; |
| 190 | u8 pat_cr; |
| 191 | }; |
| 192 | |
| 193 | /** |
| 194 | * struct fimc_scaler - the configuration data for FIMC inetrnal scaler |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 195 | * @scaleup_h: flag indicating scaling up horizontally |
| 196 | * @scaleup_v: flag indicating scaling up vertically |
| 197 | * @copy_mode: flag indicating transparent DMA transfer (no scaling |
| 198 | * and color format conversion) |
| 199 | * @enabled: flag indicating if the scaler is used |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 200 | * @hfactor: horizontal shift factor |
| 201 | * @vfactor: vertical shift factor |
| 202 | * @pre_hratio: horizontal ratio of the prescaler |
| 203 | * @pre_vratio: vertical ratio of the prescaler |
| 204 | * @pre_dst_width: the prescaler's destination width |
| 205 | * @pre_dst_height: the prescaler's destination height |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 206 | * @main_hratio: the main scaler's horizontal ratio |
| 207 | * @main_vratio: the main scaler's vertical ratio |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 208 | * @real_width: source pixel (width - offset) |
| 209 | * @real_height: source pixel (height - offset) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 210 | */ |
| 211 | struct fimc_scaler { |
Sylwester Nawrocki | dda7ae7 | 2010-10-22 04:10:57 -0300 | [diff] [blame] | 212 | unsigned int scaleup_h:1; |
| 213 | unsigned int scaleup_v:1; |
| 214 | unsigned int copy_mode:1; |
| 215 | unsigned int enabled:1; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 216 | u32 hfactor; |
| 217 | u32 vfactor; |
| 218 | u32 pre_hratio; |
| 219 | u32 pre_vratio; |
| 220 | u32 pre_dst_width; |
| 221 | u32 pre_dst_height; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 222 | u32 main_hratio; |
| 223 | u32 main_vratio; |
| 224 | u32 real_width; |
| 225 | u32 real_height; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | /** |
| 229 | * struct fimc_addr - the FIMC physical address set for DMA |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 230 | * @y: luminance plane physical address |
| 231 | * @cb: Cb plane physical address |
| 232 | * @cr: Cr plane physical address |
| 233 | */ |
| 234 | struct fimc_addr { |
| 235 | u32 y; |
| 236 | u32 cb; |
| 237 | u32 cr; |
| 238 | }; |
| 239 | |
| 240 | /** |
| 241 | * struct fimc_vid_buffer - the driver's video buffer |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 242 | * @vb: v4l videobuf buffer |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 243 | * @list: linked list structure for buffer queue |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 244 | * @paddr: precalculated physical address set |
| 245 | * @index: buffer index for the output DMA engine |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 246 | */ |
| 247 | struct fimc_vid_buffer { |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 248 | struct vb2_buffer vb; |
| 249 | struct list_head list; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 250 | struct fimc_addr paddr; |
| 251 | int index; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | /** |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 255 | * struct fimc_frame - source/target frame properties |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 256 | * @f_width: image full width (virtual screen size) |
| 257 | * @f_height: image full height (virtual screen size) |
| 258 | * @o_width: original image width as set by S_FMT |
| 259 | * @o_height: original image height as set by S_FMT |
| 260 | * @offs_h: image horizontal pixel offset |
| 261 | * @offs_v: image vertical pixel offset |
| 262 | * @width: image pixel width |
| 263 | * @height: image pixel weight |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 264 | * @payload: image size in bytes (w x h x bpp) |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 265 | * @paddr: image frame buffer physical addresses |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 266 | * @dma_offset: DMA offset in bytes |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 267 | * @fmt: fimc color format pointer |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 268 | */ |
| 269 | struct fimc_frame { |
| 270 | u32 f_width; |
| 271 | u32 f_height; |
| 272 | u32 o_width; |
| 273 | u32 o_height; |
| 274 | u32 offs_h; |
| 275 | u32 offs_v; |
| 276 | u32 width; |
| 277 | u32 height; |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 278 | unsigned long payload[VIDEO_MAX_PLANES]; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 279 | struct fimc_addr paddr; |
| 280 | struct fimc_dma_offset dma_offset; |
| 281 | struct fimc_fmt *fmt; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 282 | u8 alpha; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | /** |
| 286 | * struct fimc_m2m_device - v4l2 memory-to-memory device data |
| 287 | * @vfd: the video device node for v4l2 m2m mode |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 288 | * @m2m_dev: v4l2 memory-to-memory device data |
| 289 | * @ctx: hardware context data |
| 290 | * @refcnt: the reference counter |
| 291 | */ |
| 292 | struct fimc_m2m_device { |
| 293 | struct video_device *vfd; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 294 | struct v4l2_m2m_dev *m2m_dev; |
| 295 | struct fimc_ctx *ctx; |
| 296 | int refcnt; |
| 297 | }; |
| 298 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 299 | #define FIMC_SD_PAD_SINK 0 |
| 300 | #define FIMC_SD_PAD_SOURCE 1 |
| 301 | #define FIMC_SD_PADS_NUM 2 |
| 302 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 303 | /** |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 304 | * struct fimc_vid_cap - camera capture device information |
| 305 | * @ctx: hardware context data |
| 306 | * @vfd: video device node for camera capture mode |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 307 | * @subdev: subdev exposing the FIMC processing block |
Sylwester Nawrocki | 574e171 | 2011-07-26 18:08:21 -0300 | [diff] [blame] | 308 | * @vd_pad: fimc video capture node pad |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 309 | * @sd_pads: fimc video processing block pads |
| 310 | * @mf: media bus format at the FIMC camera input (and the scaler output) pad |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 311 | * @pending_buf_q: the pending buffer queue head |
| 312 | * @active_buf_q: the queue head of buffers scheduled in hardware |
| 313 | * @vbq: the capture am video buffer queue |
| 314 | * @active_buf_cnt: number of video buffers scheduled in hardware |
| 315 | * @buf_index: index for managing the output DMA buffers |
| 316 | * @frame_count: the frame counter for statistics |
| 317 | * @reqbufs_count: the number of buffers requested in REQBUFS ioctl |
| 318 | * @input_index: input (camera sensor) index |
| 319 | * @refcnt: driver's private reference counter |
Sylwester Nawrocki | d09a7dc | 2011-08-24 19:28:18 -0300 | [diff] [blame] | 320 | * @input: capture input type, grp_id of the attached subdev |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 321 | * @user_subdev_api: true if subdevs are not configured by the host driver |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 322 | */ |
| 323 | struct fimc_vid_cap { |
| 324 | struct fimc_ctx *ctx; |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 325 | struct vb2_alloc_ctx *alloc_ctx; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 326 | struct video_device *vfd; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 327 | struct v4l2_subdev subdev; |
Sylwester Nawrocki | 574e171 | 2011-07-26 18:08:21 -0300 | [diff] [blame] | 328 | struct media_pad vd_pad; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 329 | struct v4l2_mbus_framefmt mf; |
| 330 | struct media_pad sd_pads[FIMC_SD_PADS_NUM]; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 331 | struct list_head pending_buf_q; |
| 332 | struct list_head active_buf_q; |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 333 | struct vb2_queue vbq; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 334 | int active_buf_cnt; |
| 335 | int buf_index; |
| 336 | unsigned int frame_count; |
| 337 | unsigned int reqbufs_count; |
| 338 | int input_index; |
| 339 | int refcnt; |
Sylwester Nawrocki | d09a7dc | 2011-08-24 19:28:18 -0300 | [diff] [blame] | 340 | u32 input; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 341 | bool user_subdev_api; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | /** |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 345 | * struct fimc_pix_limit - image pixel size limits in various IP configurations |
| 346 | * |
| 347 | * @scaler_en_w: max input pixel width when the scaler is enabled |
| 348 | * @scaler_dis_w: max input pixel width when the scaler is disabled |
| 349 | * @in_rot_en_h: max input width with the input rotator is on |
| 350 | * @in_rot_dis_w: max input width with the input rotator is off |
| 351 | * @out_rot_en_w: max output width with the output rotator on |
| 352 | * @out_rot_dis_w: max output width with the output rotator off |
| 353 | */ |
| 354 | struct fimc_pix_limit { |
| 355 | u16 scaler_en_w; |
| 356 | u16 scaler_dis_w; |
| 357 | u16 in_rot_en_h; |
| 358 | u16 in_rot_dis_w; |
| 359 | u16 out_rot_en_w; |
| 360 | u16 out_rot_dis_w; |
| 361 | }; |
| 362 | |
| 363 | /** |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 364 | * struct fimc_variant - FIMC device variant information |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 365 | * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes |
| 366 | * @has_inp_rot: set if has input rotator |
| 367 | * @has_out_rot: set if has output rotator |
Sylwester Nawrocki | 798174a | 2010-11-25 10:49:21 -0300 | [diff] [blame] | 368 | * @has_cistatus2: 1 if CISTATUS2 register is present in this IP revision |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 369 | * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register |
| 370 | * are present in this IP revision |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 371 | * @has_cam_if: set if this instance has a camera input interface |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 372 | * @pix_limit: pixel size constraints for the scaler |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 373 | * @min_inp_pixsize: minimum input pixel size |
| 374 | * @min_out_pixsize: minimum output pixel size |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 375 | * @hor_offs_align: horizontal pixel offset aligment |
Sylwester Nawrocki | 9c63afc | 2011-05-27 13:12:23 -0300 | [diff] [blame] | 376 | * @min_vsize_align: minimum vertical pixel size alignment |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 377 | * @out_buf_count: the number of buffers in output DMA sequence |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 378 | */ |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 379 | struct fimc_variant { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 380 | unsigned int pix_hoff:1; |
| 381 | unsigned int has_inp_rot:1; |
| 382 | unsigned int has_out_rot:1; |
Sylwester Nawrocki | 798174a | 2010-11-25 10:49:21 -0300 | [diff] [blame] | 383 | unsigned int has_cistatus2:1; |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 384 | unsigned int has_mainscaler_ext:1; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 385 | unsigned int has_cam_if:1; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 386 | unsigned int has_alpha:1; |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 387 | struct fimc_pix_limit *pix_limit; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 388 | u16 min_inp_pixsize; |
| 389 | u16 min_out_pixsize; |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 390 | u16 hor_offs_align; |
Sylwester Nawrocki | 9c63afc | 2011-05-27 13:12:23 -0300 | [diff] [blame] | 391 | u16 min_vsize_align; |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 392 | u16 out_buf_count; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | /** |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 396 | * struct fimc_drvdata - per device type driver data |
| 397 | * @variant: variant information for this device |
| 398 | * @num_entities: number of fimc instances available in a SoC |
| 399 | * @lclk_frequency: local bus clock frequency |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 400 | */ |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 401 | struct fimc_drvdata { |
| 402 | struct fimc_variant *variant[FIMC_MAX_DEVS]; |
| 403 | int num_entities; |
| 404 | unsigned long lclk_frequency; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 405 | }; |
| 406 | |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 407 | #define fimc_get_drvdata(_pdev) \ |
| 408 | ((struct fimc_drvdata *) platform_get_device_id(_pdev)->driver_data) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 409 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 410 | struct fimc_ctx; |
| 411 | |
| 412 | /** |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 413 | * struct fimc_dev - abstraction for FIMC entity |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 414 | * @slock: the spinlock protecting this data structure |
| 415 | * @lock: the mutex protecting this data structure |
| 416 | * @pdev: pointer to the FIMC platform device |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 417 | * @pdata: pointer to the device platform data |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 418 | * @variant: the IP variant information |
Sylwester Nawrocki | a25be18 | 2010-12-27 15:34:43 -0300 | [diff] [blame] | 419 | * @id: FIMC device index (0..FIMC_MAX_DEVS) |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 420 | * @clock: clocks required for FIMC operation |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 421 | * @regs: the mapped hardware registers |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 422 | * @irq_queue: interrupt handler waitqueue |
Sylwester Nawrocki | 30c9939 | 2011-06-10 15:36:48 -0300 | [diff] [blame] | 423 | * @v4l2_dev: root v4l2_device |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 424 | * @m2m: memory-to-memory V4L2 device information |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 425 | * @vid_cap: camera capture device information |
| 426 | * @state: flags used to synchronize m2m and capture mode operation |
Sylwester Nawrocki | 3495dce | 2011-05-20 06:14:59 -0300 | [diff] [blame] | 427 | * @alloc_ctx: videobuf2 memory allocator context |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 428 | * @pipeline: fimc video capture pipeline data structure |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 429 | */ |
| 430 | struct fimc_dev { |
| 431 | spinlock_t slock; |
| 432 | struct mutex lock; |
| 433 | struct platform_device *pdev; |
Sylwester Nawrocki | df7e09a | 2010-12-27 14:42:15 -0300 | [diff] [blame] | 434 | struct s5p_platform_fimc *pdata; |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 435 | struct fimc_variant *variant; |
Sylwester Nawrocki | a25be18 | 2010-12-27 15:34:43 -0300 | [diff] [blame] | 436 | u16 id; |
Sylwester Nawrocki | a25be18 | 2010-12-27 15:34:43 -0300 | [diff] [blame] | 437 | struct clk *clock[MAX_FIMC_CLOCKS]; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 438 | void __iomem *regs; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 439 | wait_queue_head_t irq_queue; |
Sylwester Nawrocki | 30c9939 | 2011-06-10 15:36:48 -0300 | [diff] [blame] | 440 | struct v4l2_device *v4l2_dev; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 441 | struct fimc_m2m_device m2m; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 442 | struct fimc_vid_cap vid_cap; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 443 | unsigned long state; |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 444 | struct vb2_alloc_ctx *alloc_ctx; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 445 | struct fimc_pipeline pipeline; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 446 | }; |
| 447 | |
| 448 | /** |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 449 | * struct fimc_ctrls - v4l2 controls structure |
| 450 | * @handler: the control handler |
| 451 | * @colorfx: image effect control |
| 452 | * @colorfx_cbcr: Cb/Cr coefficients control |
| 453 | * @rotate: image rotation control |
| 454 | * @hflip: horizontal flip control |
| 455 | * @vflip: vertical flip control |
| 456 | * @alpha: RGB alpha control |
| 457 | * @ready: true if @handler is initialized |
| 458 | */ |
| 459 | struct fimc_ctrls { |
| 460 | struct v4l2_ctrl_handler handler; |
| 461 | struct { |
| 462 | struct v4l2_ctrl *colorfx; |
| 463 | struct v4l2_ctrl *colorfx_cbcr; |
| 464 | }; |
| 465 | struct v4l2_ctrl *rotate; |
| 466 | struct v4l2_ctrl *hflip; |
| 467 | struct v4l2_ctrl *vflip; |
| 468 | struct v4l2_ctrl *alpha; |
| 469 | bool ready; |
| 470 | }; |
| 471 | |
| 472 | /** |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 473 | * fimc_ctx - the device context data |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 474 | * @s_frame: source frame properties |
| 475 | * @d_frame: destination frame properties |
| 476 | * @out_order_1p: output 1-plane YCBCR order |
| 477 | * @out_order_2p: output 2-plane YCBCR order |
| 478 | * @in_order_1p input 1-plane YCBCR order |
| 479 | * @in_order_2p: input 2-plane YCBCR order |
| 480 | * @in_path: input mode (DMA or camera) |
| 481 | * @out_path: output mode (DMA or FIFO) |
| 482 | * @scaler: image scaler properties |
| 483 | * @effect: image effect |
| 484 | * @rotation: image clockwise rotation in degrees |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 485 | * @hflip: indicates image horizontal flip if set |
| 486 | * @vflip: indicates image vertical flip if set |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 487 | * @flags: additional flags for image conversion |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 488 | * @state: flags to keep track of user configuration |
| 489 | * @fimc_dev: the FIMC device this context applies to |
| 490 | * @m2m_ctx: memory-to-memory device context |
Sylwester Nawrocki | e578588 | 2011-06-10 15:36:50 -0300 | [diff] [blame] | 491 | * @fh: v4l2 file handle |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 492 | * @ctrls: v4l2 controls structure |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 493 | */ |
| 494 | struct fimc_ctx { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 495 | struct fimc_frame s_frame; |
| 496 | struct fimc_frame d_frame; |
| 497 | u32 out_order_1p; |
| 498 | u32 out_order_2p; |
| 499 | u32 in_order_1p; |
| 500 | u32 in_order_2p; |
| 501 | enum fimc_datapath in_path; |
| 502 | enum fimc_datapath out_path; |
| 503 | struct fimc_scaler scaler; |
| 504 | struct fimc_effect effect; |
| 505 | int rotation; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 506 | unsigned int hflip:1; |
| 507 | unsigned int vflip:1; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 508 | u32 flags; |
| 509 | u32 state; |
| 510 | struct fimc_dev *fimc_dev; |
| 511 | struct v4l2_m2m_ctx *m2m_ctx; |
Sylwester Nawrocki | e578588 | 2011-06-10 15:36:50 -0300 | [diff] [blame] | 512 | struct v4l2_fh fh; |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 513 | struct fimc_ctrls ctrls; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 514 | }; |
| 515 | |
Sylwester Nawrocki | e578588 | 2011-06-10 15:36:50 -0300 | [diff] [blame] | 516 | #define fh_to_ctx(__fh) container_of(__fh, struct fimc_ctx, fh) |
| 517 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 518 | static inline void set_frame_bounds(struct fimc_frame *f, u32 width, u32 height) |
| 519 | { |
| 520 | f->o_width = width; |
| 521 | f->o_height = height; |
| 522 | f->f_width = width; |
| 523 | f->f_height = height; |
| 524 | } |
| 525 | |
| 526 | static inline void set_frame_crop(struct fimc_frame *f, |
| 527 | u32 left, u32 top, u32 width, u32 height) |
| 528 | { |
| 529 | f->offs_h = left; |
| 530 | f->offs_v = top; |
| 531 | f->width = width; |
| 532 | f->height = height; |
| 533 | } |
| 534 | |
| 535 | static inline u32 fimc_get_format_depth(struct fimc_fmt *ff) |
| 536 | { |
| 537 | u32 i, depth = 0; |
| 538 | |
| 539 | if (ff != NULL) |
| 540 | for (i = 0; i < ff->colplanes; i++) |
| 541 | depth += ff->depth[i]; |
| 542 | return depth; |
| 543 | } |
| 544 | |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 545 | static inline bool fimc_capture_active(struct fimc_dev *fimc) |
| 546 | { |
| 547 | unsigned long flags; |
| 548 | bool ret; |
| 549 | |
| 550 | spin_lock_irqsave(&fimc->slock, flags); |
| 551 | ret = !!(fimc->state & (1 << ST_CAPT_RUN) || |
| 552 | fimc->state & (1 << ST_CAPT_PEND)); |
| 553 | spin_unlock_irqrestore(&fimc->slock, flags); |
| 554 | return ret; |
| 555 | } |
| 556 | |
Sylwester Nawrocki | efb13c3 | 2012-03-19 13:11:40 -0300 | [diff] [blame] | 557 | static inline void fimc_ctx_state_set(u32 state, struct fimc_ctx *ctx) |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 558 | { |
| 559 | unsigned long flags; |
| 560 | |
Sylwester Nawrocki | efb13c3 | 2012-03-19 13:11:40 -0300 | [diff] [blame] | 561 | spin_lock_irqsave(&ctx->fimc_dev->slock, flags); |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 562 | ctx->state |= state; |
Sylwester Nawrocki | efb13c3 | 2012-03-19 13:11:40 -0300 | [diff] [blame] | 563 | spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags); |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static inline bool fimc_ctx_state_is_set(u32 mask, struct fimc_ctx *ctx) |
| 567 | { |
| 568 | unsigned long flags; |
| 569 | bool ret; |
| 570 | |
Sylwester Nawrocki | efb13c3 | 2012-03-19 13:11:40 -0300 | [diff] [blame] | 571 | spin_lock_irqsave(&ctx->fimc_dev->slock, flags); |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 572 | ret = (ctx->state & mask) == mask; |
Sylwester Nawrocki | efb13c3 | 2012-03-19 13:11:40 -0300 | [diff] [blame] | 573 | spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags); |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 574 | return ret; |
| 575 | } |
| 576 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 577 | static inline int tiled_fmt(struct fimc_fmt *fmt) |
| 578 | { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 579 | return fmt->fourcc == V4L2_PIX_FMT_NV12MT; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 580 | } |
| 581 | |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 582 | /* Return the alpha component bit mask */ |
| 583 | static inline int fimc_get_alpha_mask(struct fimc_fmt *fmt) |
| 584 | { |
| 585 | switch (fmt->color) { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 586 | case FIMC_FMT_RGB444: return 0x0f; |
| 587 | case FIMC_FMT_RGB555: return 0x01; |
| 588 | case FIMC_FMT_RGB888: return 0xff; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 589 | default: return 0; |
| 590 | }; |
| 591 | } |
| 592 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 593 | static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx, |
| 594 | enum v4l2_buf_type type) |
Pawel Osciak | 03e30ca | 2010-08-06 10:50:46 -0300 | [diff] [blame] | 595 | { |
| 596 | struct fimc_frame *frame; |
| 597 | |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 598 | if (V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE == type) { |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 599 | if (fimc_ctx_state_is_set(FIMC_CTX_M2M, ctx)) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 600 | frame = &ctx->s_frame; |
| 601 | else |
| 602 | return ERR_PTR(-EINVAL); |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 603 | } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) { |
Pawel Osciak | 03e30ca | 2010-08-06 10:50:46 -0300 | [diff] [blame] | 604 | frame = &ctx->d_frame; |
| 605 | } else { |
Sylwester Nawrocki | 30c9939 | 2011-06-10 15:36:48 -0300 | [diff] [blame] | 606 | v4l2_err(ctx->fimc_dev->v4l2_dev, |
Pawel Osciak | 03e30ca | 2010-08-06 10:50:46 -0300 | [diff] [blame] | 607 | "Wrong buffer/video queue type (%d)\n", type); |
| 608 | return ERR_PTR(-EINVAL); |
| 609 | } |
| 610 | |
| 611 | return frame; |
| 612 | } |
| 613 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 614 | /* -----------------------------------------------------*/ |
| 615 | /* fimc-core.c */ |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 616 | int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv, |
| 617 | struct v4l2_fmtdesc *f); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 618 | int fimc_ctrls_create(struct fimc_ctx *ctx); |
| 619 | void fimc_ctrls_delete(struct fimc_ctx *ctx); |
| 620 | void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active); |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 621 | void fimc_alpha_ctrl_update(struct fimc_ctx *ctx); |
Sylwester Nawrocki | e578588 | 2011-06-10 15:36:50 -0300 | [diff] [blame] | 622 | int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f); |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 623 | void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height, |
| 624 | struct v4l2_pix_format_mplane *pix); |
Sylwester Nawrocki | 63746be | 2012-04-22 17:07:09 -0300 | [diff] [blame] | 625 | struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code, |
Sylwester Nawrocki | cf52df8 | 2011-06-13 11:09:40 -0300 | [diff] [blame] | 626 | unsigned int mask, int index); |
Sylwester Nawrocki | 97d9742 | 2012-05-08 15:51:24 -0300 | [diff] [blame] | 627 | struct fimc_fmt *fimc_get_format(unsigned int index); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 628 | |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 629 | int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh, |
| 630 | int dw, int dh, int rotation); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 631 | int fimc_set_scaler_info(struct fimc_ctx *ctx); |
| 632 | int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags); |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 633 | int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb, |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 634 | struct fimc_frame *frame, struct fimc_addr *paddr); |
Sylwester Nawrocki | 9e803a0 | 2011-06-10 15:36:53 -0300 | [diff] [blame] | 635 | void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f); |
| 636 | void fimc_set_yuv_order(struct fimc_ctx *ctx); |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 637 | void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f); |
Sylwester Nawrocki | 97d9742 | 2012-05-08 15:51:24 -0300 | [diff] [blame] | 638 | void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf); |
Sylwester Nawrocki | 9e803a0 | 2011-06-10 15:36:53 -0300 | [diff] [blame] | 639 | |
Sylwester Nawrocki | 30c9939 | 2011-06-10 15:36:48 -0300 | [diff] [blame] | 640 | int fimc_register_m2m_device(struct fimc_dev *fimc, |
| 641 | struct v4l2_device *v4l2_dev); |
| 642 | void fimc_unregister_m2m_device(struct fimc_dev *fimc); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 643 | int fimc_register_driver(void); |
| 644 | void fimc_unregister_driver(void); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 645 | |
| 646 | /* -----------------------------------------------------*/ |
Sylwester Nawrocki | 97d9742 | 2012-05-08 15:51:24 -0300 | [diff] [blame] | 647 | /* fimc-m2m.c */ |
| 648 | void fimc_m2m_job_finish(struct fimc_ctx *ctx, int vb_state); |
| 649 | |
| 650 | /* -----------------------------------------------------*/ |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 651 | /* fimc-capture.c */ |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 652 | int fimc_initialize_capture_subdev(struct fimc_dev *fimc); |
| 653 | void fimc_unregister_capture_subdev(struct fimc_dev *fimc); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 654 | int fimc_capture_ctrls_create(struct fimc_dev *fimc); |
Sylwester Nawrocki | e1d72f4 | 2011-06-10 15:36:58 -0300 | [diff] [blame] | 655 | void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification, |
| 656 | void *arg); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 657 | int fimc_capture_suspend(struct fimc_dev *fimc); |
| 658 | int fimc_capture_resume(struct fimc_dev *fimc); |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 659 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 660 | /* |
Sylwester Nawrocki | 0295202 | 2011-06-10 15:36:59 -0300 | [diff] [blame] | 661 | * Buffer list manipulation functions. Must be called with fimc.slock held. |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 662 | */ |
Sylwester Nawrocki | 0295202 | 2011-06-10 15:36:59 -0300 | [diff] [blame] | 663 | |
| 664 | /** |
| 665 | * fimc_active_queue_add - add buffer to the capture active buffers queue |
| 666 | * @buf: buffer to add to the active buffers list |
| 667 | */ |
| 668 | static inline void fimc_active_queue_add(struct fimc_vid_cap *vid_cap, |
| 669 | struct fimc_vid_buffer *buf) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 670 | { |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 671 | list_add_tail(&buf->list, &vid_cap->active_buf_q); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 672 | vid_cap->active_buf_cnt++; |
| 673 | } |
| 674 | |
Sylwester Nawrocki | 0295202 | 2011-06-10 15:36:59 -0300 | [diff] [blame] | 675 | /** |
| 676 | * fimc_active_queue_pop - pop buffer from the capture active buffers queue |
| 677 | * |
| 678 | * The caller must assure the active_buf_q list is not empty. |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 679 | */ |
Sylwester Nawrocki | 0295202 | 2011-06-10 15:36:59 -0300 | [diff] [blame] | 680 | static inline struct fimc_vid_buffer *fimc_active_queue_pop( |
| 681 | struct fimc_vid_cap *vid_cap) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 682 | { |
| 683 | struct fimc_vid_buffer *buf; |
| 684 | buf = list_entry(vid_cap->active_buf_q.next, |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 685 | struct fimc_vid_buffer, list); |
| 686 | list_del(&buf->list); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 687 | vid_cap->active_buf_cnt--; |
| 688 | return buf; |
| 689 | } |
| 690 | |
Sylwester Nawrocki | 0295202 | 2011-06-10 15:36:59 -0300 | [diff] [blame] | 691 | /** |
| 692 | * fimc_pending_queue_add - add buffer to the capture pending buffers queue |
| 693 | * @buf: buffer to add to the pending buffers list |
| 694 | */ |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 695 | static inline void fimc_pending_queue_add(struct fimc_vid_cap *vid_cap, |
| 696 | struct fimc_vid_buffer *buf) |
| 697 | { |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 698 | list_add_tail(&buf->list, &vid_cap->pending_buf_q); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 699 | } |
| 700 | |
Sylwester Nawrocki | 0295202 | 2011-06-10 15:36:59 -0300 | [diff] [blame] | 701 | /** |
| 702 | * fimc_pending_queue_pop - pop buffer from the capture pending buffers queue |
| 703 | * |
| 704 | * The caller must assure the pending_buf_q list is not empty. |
| 705 | */ |
| 706 | static inline struct fimc_vid_buffer *fimc_pending_queue_pop( |
| 707 | struct fimc_vid_cap *vid_cap) |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 708 | { |
| 709 | struct fimc_vid_buffer *buf; |
| 710 | buf = list_entry(vid_cap->pending_buf_q.next, |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 711 | struct fimc_vid_buffer, list); |
| 712 | list_del(&buf->list); |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 713 | return buf; |
| 714 | } |
| 715 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 716 | #endif /* FIMC_CORE_H_ */ |