1/* 2 * drivers/media/i2c/smiapp/smiapp.h 3 * 4 * Generic driver for SMIA/SMIA++ compliant camera modules 5 * 6 * Copyright (C) 2010--2012 Nokia Corporation 7 * Contact: Sakari Ailus <sakari.ailus@iki.fi> 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * version 2 as published by the Free Software Foundation. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 21 * 02110-1301 USA 22 * 23 */ 24 25#ifndef __SMIAPP_PRIV_H_ 26#define __SMIAPP_PRIV_H_ 27 28#include <linux/mutex.h> 29#include <media/v4l2-ctrls.h> 30#include <media/v4l2-subdev.h> 31#include <media/smiapp.h> 32 33#include "smiapp-pll.h" 34#include "smiapp-reg.h" 35#include "smiapp-regs.h" 36#include "smiapp-quirk.h" 37 38/* 39 * Standard SMIA++ constants 40 */ 41#define SMIA_VERSION_1 10 42#define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */ 43#define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */ 44#define SMIAPP_VERSION_1 10 45 46#define SMIAPP_PROFILE_0 0 47#define SMIAPP_PROFILE_1 1 48#define SMIAPP_PROFILE_2 2 49 50#define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */ 51 52#define SMIAPP_RESET_DELAY_CLOCKS 2400 53#define SMIAPP_RESET_DELAY(clk) \ 54 (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \ 55 + (clk) / 1000 - 1) / ((clk) / 1000)) 56 57#define SMIAPP_COLOUR_COMPONENTS 4 58 59#include "smiapp-limits.h" 60 61struct smiapp_quirk; 62 63#define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0) 64 65struct smiapp_module_ident { 66 u8 manufacturer_id; 67 u16 model_id; 68 u8 revision_number_major; 69 70 u8 flags; 71 72 char *name; 73 const struct smiapp_quirk *quirk; 74}; 75 76struct smiapp_module_info { 77 u32 manufacturer_id; 78 u32 model_id; 79 u32 revision_number_major; 80 u32 revision_number_minor; 81 82 u32 module_year; 83 u32 module_month; 84 u32 module_day; 85 86 u32 sensor_manufacturer_id; 87 u32 sensor_model_id; 88 u32 sensor_revision_number; 89 u32 sensor_firmware_version; 90 91 u32 smia_version; 92 u32 smiapp_version; 93 94 u32 smiapp_profile; 95 96 char *name; 97 const struct smiapp_quirk *quirk; 98}; 99 100#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \ 101 { .manufacturer_id = manufacturer, \ 102 .model_id = model, \ 103 .revision_number_major = rev, \ 104 .flags = fl, \ 105 .name = _name, \ 106 .quirk = _quirk, } 107 108#define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \ 109 { .manufacturer_id = manufacturer, \ 110 .model_id = model, \ 111 .revision_number_major = rev, \ 112 .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ 113 .name = _name, \ 114 .quirk = _quirk, } 115 116#define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \ 117 { .manufacturer_id = manufacturer, \ 118 .model_id = model, \ 119 .revision_number_major = rev, \ 120 .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ 121 .name = _name, } 122 123#define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \ 124 { .manufacturer_id = manufacturer, \ 125 .model_id = model, \ 126 .revision_number_major = rev, \ 127 .flags = 0, \ 128 .name = _name, \ 129 .quirk = _quirk, } 130 131#define SMIAPP_IDENT(manufacturer, model, rev, _name) \ 132 { .manufacturer_id = manufacturer, \ 133 .model_id = model, \ 134 .revision_number_major = rev, \ 135 .flags = 0, \ 136 .name = _name, } 137 138struct smiapp_reg_limits { 139 u32 addr; 140 char *what; 141}; 142 143extern struct smiapp_reg_limits smiapp_reg_limits[]; 144 145struct smiapp_csi_data_format { 146 u32 code; 147 u8 width; 148 u8 compressed; 149 u8 pixel_order; 150}; 151 152#define SMIAPP_SUBDEVS 3 153 154#define SMIAPP_PA_PAD_SRC 0 155#define SMIAPP_PAD_SINK 0 156#define SMIAPP_PAD_SRC 1 157#define SMIAPP_PADS 2 158 159struct smiapp_binning_subtype { 160 u8 horizontal:4; 161 u8 vertical:4; 162} __packed; 163 164struct smiapp_subdev { 165 struct v4l2_subdev sd; 166 struct media_pad pads[2]; 167 struct v4l2_rect sink_fmt; 168 struct v4l2_rect crop[2]; 169 struct v4l2_rect compose; /* compose on sink */ 170 unsigned short sink_pad; 171 unsigned short source_pad; 172 int npads; 173 struct smiapp_sensor *sensor; 174 struct v4l2_ctrl_handler ctrl_handler; 175}; 176 177/* 178 * struct smiapp_sensor - Main device structure 179 */ 180struct smiapp_sensor { 181 /* 182 * "mutex" is used to serialise access to all fields here 183 * except v4l2_ctrls at the end of the struct. "mutex" is also 184 * used to serialise access to file handle specific 185 * information. The exception to this rule is the power_mutex 186 * below. 187 */ 188 struct mutex mutex; 189 /* 190 * power_mutex is used to serialise power management related 191 * activities. Acquiring "mutex" at that time isn't necessary 192 * since there are no other users anyway. 193 */ 194 struct mutex power_mutex; 195 struct smiapp_subdev ssds[SMIAPP_SUBDEVS]; 196 u32 ssds_used; 197 struct smiapp_subdev *src; 198 struct smiapp_subdev *binner; 199 struct smiapp_subdev *scaler; 200 struct smiapp_subdev *pixel_array; 201 struct smiapp_platform_data *platform_data; 202 struct regulator *vana; 203 struct clk *ext_clk; 204 u32 limits[SMIAPP_LIMIT_LAST]; 205 u8 nbinning_subtypes; 206 struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES]; 207 u32 mbus_frame_fmts; 208 const struct smiapp_csi_data_format *csi_format; 209 const struct smiapp_csi_data_format *internal_csi_format; 210 u32 default_mbus_frame_fmts; 211 int default_pixel_order; 212 213 u8 binning_horizontal; 214 u8 binning_vertical; 215 216 u8 scale_m; 217 u8 scaling_mode; 218 219 u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */ 220 u8 flash_capability; 221 u8 frame_skip; 222 223 int power_count; 224 225 bool streaming; 226 bool dev_init_done; 227 228 u8 *nvm; /* nvm memory buffer */ 229 unsigned int nvm_size; /* bytes */ 230 231 struct smiapp_module_info minfo; 232 233 struct smiapp_pll pll; 234 235 /* Pixel array controls */ 236 struct v4l2_ctrl *analog_gain; 237 struct v4l2_ctrl *exposure; 238 struct v4l2_ctrl *hflip; 239 struct v4l2_ctrl *vflip; 240 struct v4l2_ctrl *vblank; 241 struct v4l2_ctrl *hblank; 242 struct v4l2_ctrl *pixel_rate_parray; 243 /* src controls */ 244 struct v4l2_ctrl *link_freq; 245 struct v4l2_ctrl *pixel_rate_csi; 246 /* test pattern colour components */ 247 struct v4l2_ctrl *test_data[SMIAPP_COLOUR_COMPONENTS]; 248}; 249 250#define to_smiapp_subdev(_sd) \ 251 container_of(_sd, struct smiapp_subdev, sd) 252 253#define to_smiapp_sensor(_sd) \ 254 (to_smiapp_subdev(_sd)->sensor) 255 256#endif /* __SMIAPP_PRIV_H_ */ 257