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