Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | cb7a01a | 2012-08-14 16:23:43 -0300 | [diff] [blame] | 2 | * drivers/media/i2c/smiapp/smiapp.h |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 3 | * |
| 4 | * Generic driver for SMIA/SMIA++ compliant camera modules |
| 5 | * |
| 6 | * Copyright (C) 2010--2012 Nokia Corporation |
Sakari Ailus | 8c5dff9 | 2012-10-28 06:44:17 -0300 | [diff] [blame] | 7 | * Contact: Sakari Ailus <sakari.ailus@iki.fi> |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 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. |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #ifndef __SMIAPP_PRIV_H_ |
| 20 | #define __SMIAPP_PRIV_H_ |
| 21 | |
| 22 | #include <linux/mutex.h> |
| 23 | #include <media/v4l2-ctrls.h> |
| 24 | #include <media/v4l2-subdev.h> |
Mauro Carvalho Chehab | b5dcee2 | 2015-11-10 12:01:44 -0200 | [diff] [blame] | 25 | #include <media/i2c/smiapp.h> |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 26 | |
Mauro Carvalho Chehab | f9b26cd | 2012-05-15 10:36:09 -0300 | [diff] [blame] | 27 | #include "smiapp-pll.h" |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 28 | #include "smiapp-reg.h" |
| 29 | #include "smiapp-regs.h" |
| 30 | #include "smiapp-quirk.h" |
| 31 | |
| 32 | /* |
| 33 | * Standard SMIA++ constants |
| 34 | */ |
| 35 | #define SMIA_VERSION_1 10 |
| 36 | #define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */ |
| 37 | #define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */ |
| 38 | #define SMIAPP_VERSION_1 10 |
| 39 | |
| 40 | #define SMIAPP_PROFILE_0 0 |
| 41 | #define SMIAPP_PROFILE_1 1 |
| 42 | #define SMIAPP_PROFILE_2 2 |
| 43 | |
| 44 | #define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */ |
| 45 | |
| 46 | #define SMIAPP_RESET_DELAY_CLOCKS 2400 |
| 47 | #define SMIAPP_RESET_DELAY(clk) \ |
| 48 | (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \ |
| 49 | + (clk) / 1000 - 1) / ((clk) / 1000)) |
| 50 | |
Sakari Ailus | 0e2a6b7 | 2014-05-21 16:58:11 -0300 | [diff] [blame] | 51 | #define SMIAPP_COLOUR_COMPONENTS 4 |
| 52 | |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 53 | #include "smiapp-limits.h" |
| 54 | |
| 55 | struct smiapp_quirk; |
| 56 | |
| 57 | #define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0) |
| 58 | |
| 59 | struct smiapp_module_ident { |
| 60 | u8 manufacturer_id; |
| 61 | u16 model_id; |
| 62 | u8 revision_number_major; |
| 63 | |
| 64 | u8 flags; |
| 65 | |
| 66 | char *name; |
| 67 | const struct smiapp_quirk *quirk; |
| 68 | }; |
| 69 | |
| 70 | struct smiapp_module_info { |
| 71 | u32 manufacturer_id; |
| 72 | u32 model_id; |
| 73 | u32 revision_number_major; |
| 74 | u32 revision_number_minor; |
| 75 | |
| 76 | u32 module_year; |
| 77 | u32 module_month; |
| 78 | u32 module_day; |
| 79 | |
| 80 | u32 sensor_manufacturer_id; |
| 81 | u32 sensor_model_id; |
| 82 | u32 sensor_revision_number; |
| 83 | u32 sensor_firmware_version; |
| 84 | |
| 85 | u32 smia_version; |
| 86 | u32 smiapp_version; |
| 87 | |
| 88 | u32 smiapp_profile; |
| 89 | |
| 90 | char *name; |
| 91 | const struct smiapp_quirk *quirk; |
| 92 | }; |
| 93 | |
| 94 | #define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \ |
| 95 | { .manufacturer_id = manufacturer, \ |
| 96 | .model_id = model, \ |
| 97 | .revision_number_major = rev, \ |
| 98 | .flags = fl, \ |
| 99 | .name = _name, \ |
| 100 | .quirk = _quirk, } |
| 101 | |
| 102 | #define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \ |
| 103 | { .manufacturer_id = manufacturer, \ |
| 104 | .model_id = model, \ |
| 105 | .revision_number_major = rev, \ |
| 106 | .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ |
| 107 | .name = _name, \ |
| 108 | .quirk = _quirk, } |
| 109 | |
| 110 | #define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \ |
| 111 | { .manufacturer_id = manufacturer, \ |
| 112 | .model_id = model, \ |
| 113 | .revision_number_major = rev, \ |
| 114 | .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ |
| 115 | .name = _name, } |
| 116 | |
| 117 | #define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \ |
| 118 | { .manufacturer_id = manufacturer, \ |
| 119 | .model_id = model, \ |
| 120 | .revision_number_major = rev, \ |
| 121 | .flags = 0, \ |
| 122 | .name = _name, \ |
| 123 | .quirk = _quirk, } |
| 124 | |
| 125 | #define SMIAPP_IDENT(manufacturer, model, rev, _name) \ |
| 126 | { .manufacturer_id = manufacturer, \ |
| 127 | .model_id = model, \ |
| 128 | .revision_number_major = rev, \ |
| 129 | .flags = 0, \ |
| 130 | .name = _name, } |
| 131 | |
| 132 | struct smiapp_reg_limits { |
| 133 | u32 addr; |
| 134 | char *what; |
| 135 | }; |
| 136 | |
| 137 | extern struct smiapp_reg_limits smiapp_reg_limits[]; |
| 138 | |
| 139 | struct smiapp_csi_data_format { |
| 140 | u32 code; |
| 141 | u8 width; |
| 142 | u8 compressed; |
| 143 | u8 pixel_order; |
| 144 | }; |
| 145 | |
| 146 | #define SMIAPP_SUBDEVS 3 |
| 147 | |
| 148 | #define SMIAPP_PA_PAD_SRC 0 |
| 149 | #define SMIAPP_PAD_SINK 0 |
| 150 | #define SMIAPP_PAD_SRC 1 |
| 151 | #define SMIAPP_PADS 2 |
| 152 | |
| 153 | struct smiapp_binning_subtype { |
| 154 | u8 horizontal:4; |
| 155 | u8 vertical:4; |
| 156 | } __packed; |
| 157 | |
| 158 | struct smiapp_subdev { |
| 159 | struct v4l2_subdev sd; |
Sakari Ailus | df0e403 | 2016-09-07 08:39:52 -0300 | [diff] [blame] | 160 | struct media_pad pads[SMIAPP_PADS]; |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 161 | struct v4l2_rect sink_fmt; |
Sakari Ailus | df0e403 | 2016-09-07 08:39:52 -0300 | [diff] [blame] | 162 | struct v4l2_rect crop[SMIAPP_PADS]; |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 163 | struct v4l2_rect compose; /* compose on sink */ |
| 164 | unsigned short sink_pad; |
| 165 | unsigned short source_pad; |
| 166 | int npads; |
| 167 | struct smiapp_sensor *sensor; |
| 168 | struct v4l2_ctrl_handler ctrl_handler; |
| 169 | }; |
| 170 | |
| 171 | /* |
| 172 | * struct smiapp_sensor - Main device structure |
| 173 | */ |
| 174 | struct smiapp_sensor { |
| 175 | /* |
| 176 | * "mutex" is used to serialise access to all fields here |
| 177 | * except v4l2_ctrls at the end of the struct. "mutex" is also |
| 178 | * used to serialise access to file handle specific |
Sakari Ailus | cbba45d | 2016-09-13 10:01:03 -0300 | [diff] [blame] | 179 | * information. |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 180 | */ |
| 181 | struct mutex mutex; |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 182 | struct smiapp_subdev ssds[SMIAPP_SUBDEVS]; |
| 183 | u32 ssds_used; |
| 184 | struct smiapp_subdev *src; |
| 185 | struct smiapp_subdev *binner; |
| 186 | struct smiapp_subdev *scaler; |
| 187 | struct smiapp_subdev *pixel_array; |
Sakari Ailus | 697a521 | 2016-08-11 07:43:50 -0300 | [diff] [blame] | 188 | struct smiapp_hwconfig *hwcfg; |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 189 | struct regulator *vana; |
Sakari Ailus | 2547428 | 2012-04-22 08:24:33 -0300 | [diff] [blame] | 190 | struct clk *ext_clk; |
Sakari Ailus | 567716c | 2016-08-13 12:46:50 -0300 | [diff] [blame] | 191 | struct gpio_desc *xshutdown; |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 192 | u32 limits[SMIAPP_LIMIT_LAST]; |
| 193 | u8 nbinning_subtypes; |
| 194 | struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES]; |
| 195 | u32 mbus_frame_fmts; |
| 196 | const struct smiapp_csi_data_format *csi_format; |
| 197 | const struct smiapp_csi_data_format *internal_csi_format; |
| 198 | u32 default_mbus_frame_fmts; |
| 199 | int default_pixel_order; |
| 200 | |
| 201 | u8 binning_horizontal; |
| 202 | u8 binning_vertical; |
| 203 | |
| 204 | u8 scale_m; |
| 205 | u8 scaling_mode; |
| 206 | |
| 207 | u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */ |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 208 | u8 frame_skip; |
Sakari Ailus | 3fc34b7 | 2016-09-05 08:18:34 -0300 | [diff] [blame] | 209 | u16 embedded_start; /* embedded data start line */ |
| 210 | u16 embedded_end; |
| 211 | u16 image_start; /* image data start line */ |
| 212 | u16 visible_pixel_start; /* start pixel of the visible image */ |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 213 | |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 214 | bool streaming; |
| 215 | bool dev_init_done; |
Sakari Ailus | 624e989 | 2016-09-06 09:51:17 -0300 | [diff] [blame] | 216 | u8 compressed_min_bpp; |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 217 | |
| 218 | u8 *nvm; /* nvm memory buffer */ |
| 219 | unsigned int nvm_size; /* bytes */ |
| 220 | |
| 221 | struct smiapp_module_info minfo; |
| 222 | |
| 223 | struct smiapp_pll pll; |
| 224 | |
Sakari Ailus | 38a833c7 | 2014-09-17 02:54:37 -0300 | [diff] [blame] | 225 | /* Is a default format supported for a given BPP? */ |
Sakari Ailus | 624e989 | 2016-09-06 09:51:17 -0300 | [diff] [blame] | 226 | unsigned long *valid_link_freqs; |
Sakari Ailus | 38a833c7 | 2014-09-17 02:54:37 -0300 | [diff] [blame] | 227 | |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 228 | /* Pixel array controls */ |
| 229 | struct v4l2_ctrl *analog_gain; |
| 230 | struct v4l2_ctrl *exposure; |
| 231 | struct v4l2_ctrl *hflip; |
| 232 | struct v4l2_ctrl *vflip; |
| 233 | struct v4l2_ctrl *vblank; |
| 234 | struct v4l2_ctrl *hblank; |
| 235 | struct v4l2_ctrl *pixel_rate_parray; |
| 236 | /* src controls */ |
| 237 | struct v4l2_ctrl *link_freq; |
| 238 | struct v4l2_ctrl *pixel_rate_csi; |
Sakari Ailus | 0e2a6b7 | 2014-05-21 16:58:11 -0300 | [diff] [blame] | 239 | /* test pattern colour components */ |
| 240 | struct v4l2_ctrl *test_data[SMIAPP_COLOUR_COMPONENTS]; |
Sakari Ailus | ccfc97b | 2012-03-03 17:19:52 -0300 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | #define to_smiapp_subdev(_sd) \ |
| 244 | container_of(_sd, struct smiapp_subdev, sd) |
| 245 | |
| 246 | #define to_smiapp_sensor(_sd) \ |
| 247 | (to_smiapp_subdev(_sd)->sensor) |
| 248 | |
| 249 | #endif /* __SMIAPP_PRIV_H_ */ |