Commit | Line | Data |
---|---|---|
ccfc97bd SA |
1 | /* |
2 | * drivers/media/video/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@maxwell.research.nokia.com> | |
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 | ||
f9b26cd8 | 33 | #include "smiapp-pll.h" |
ccfc97bd SA |
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 | #include "smiapp-limits.h" | |
58 | ||
59 | struct smiapp_quirk; | |
60 | ||
61 | #define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0) | |
62 | ||
63 | struct smiapp_module_ident { | |
64 | u8 manufacturer_id; | |
65 | u16 model_id; | |
66 | u8 revision_number_major; | |
67 | ||
68 | u8 flags; | |
69 | ||
70 | char *name; | |
71 | const struct smiapp_quirk *quirk; | |
72 | }; | |
73 | ||
74 | struct smiapp_module_info { | |
75 | u32 manufacturer_id; | |
76 | u32 model_id; | |
77 | u32 revision_number_major; | |
78 | u32 revision_number_minor; | |
79 | ||
80 | u32 module_year; | |
81 | u32 module_month; | |
82 | u32 module_day; | |
83 | ||
84 | u32 sensor_manufacturer_id; | |
85 | u32 sensor_model_id; | |
86 | u32 sensor_revision_number; | |
87 | u32 sensor_firmware_version; | |
88 | ||
89 | u32 smia_version; | |
90 | u32 smiapp_version; | |
91 | ||
92 | u32 smiapp_profile; | |
93 | ||
94 | char *name; | |
95 | const struct smiapp_quirk *quirk; | |
96 | }; | |
97 | ||
98 | #define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \ | |
99 | { .manufacturer_id = manufacturer, \ | |
100 | .model_id = model, \ | |
101 | .revision_number_major = rev, \ | |
102 | .flags = fl, \ | |
103 | .name = _name, \ | |
104 | .quirk = _quirk, } | |
105 | ||
106 | #define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \ | |
107 | { .manufacturer_id = manufacturer, \ | |
108 | .model_id = model, \ | |
109 | .revision_number_major = rev, \ | |
110 | .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ | |
111 | .name = _name, \ | |
112 | .quirk = _quirk, } | |
113 | ||
114 | #define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \ | |
115 | { .manufacturer_id = manufacturer, \ | |
116 | .model_id = model, \ | |
117 | .revision_number_major = rev, \ | |
118 | .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ | |
119 | .name = _name, } | |
120 | ||
121 | #define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \ | |
122 | { .manufacturer_id = manufacturer, \ | |
123 | .model_id = model, \ | |
124 | .revision_number_major = rev, \ | |
125 | .flags = 0, \ | |
126 | .name = _name, \ | |
127 | .quirk = _quirk, } | |
128 | ||
129 | #define SMIAPP_IDENT(manufacturer, model, rev, _name) \ | |
130 | { .manufacturer_id = manufacturer, \ | |
131 | .model_id = model, \ | |
132 | .revision_number_major = rev, \ | |
133 | .flags = 0, \ | |
134 | .name = _name, } | |
135 | ||
136 | struct smiapp_reg_limits { | |
137 | u32 addr; | |
138 | char *what; | |
139 | }; | |
140 | ||
141 | extern struct smiapp_reg_limits smiapp_reg_limits[]; | |
142 | ||
143 | struct smiapp_csi_data_format { | |
144 | u32 code; | |
145 | u8 width; | |
146 | u8 compressed; | |
147 | u8 pixel_order; | |
148 | }; | |
149 | ||
150 | #define SMIAPP_SUBDEVS 3 | |
151 | ||
152 | #define SMIAPP_PA_PAD_SRC 0 | |
153 | #define SMIAPP_PAD_SINK 0 | |
154 | #define SMIAPP_PAD_SRC 1 | |
155 | #define SMIAPP_PADS 2 | |
156 | ||
157 | struct smiapp_binning_subtype { | |
158 | u8 horizontal:4; | |
159 | u8 vertical:4; | |
160 | } __packed; | |
161 | ||
162 | struct smiapp_subdev { | |
163 | struct v4l2_subdev sd; | |
164 | struct media_pad pads[2]; | |
165 | struct v4l2_rect sink_fmt; | |
166 | struct v4l2_rect crop[2]; | |
167 | struct v4l2_rect compose; /* compose on sink */ | |
168 | unsigned short sink_pad; | |
169 | unsigned short source_pad; | |
170 | int npads; | |
171 | struct smiapp_sensor *sensor; | |
172 | struct v4l2_ctrl_handler ctrl_handler; | |
173 | }; | |
174 | ||
175 | /* | |
176 | * struct smiapp_sensor - Main device structure | |
177 | */ | |
178 | struct smiapp_sensor { | |
179 | /* | |
180 | * "mutex" is used to serialise access to all fields here | |
181 | * except v4l2_ctrls at the end of the struct. "mutex" is also | |
182 | * used to serialise access to file handle specific | |
183 | * information. The exception to this rule is the power_mutex | |
184 | * below. | |
185 | */ | |
186 | struct mutex mutex; | |
187 | /* | |
188 | * power_mutex is used to serialise power management related | |
189 | * activities. Acquiring "mutex" at that time isn't necessary | |
190 | * since there are no other users anyway. | |
191 | */ | |
192 | struct mutex power_mutex; | |
193 | struct smiapp_subdev ssds[SMIAPP_SUBDEVS]; | |
194 | u32 ssds_used; | |
195 | struct smiapp_subdev *src; | |
196 | struct smiapp_subdev *binner; | |
197 | struct smiapp_subdev *scaler; | |
198 | struct smiapp_subdev *pixel_array; | |
199 | struct smiapp_platform_data *platform_data; | |
200 | struct regulator *vana; | |
2547428d | 201 | struct clk *ext_clk; |
ccfc97bd SA |
202 | u32 limits[SMIAPP_LIMIT_LAST]; |
203 | u8 nbinning_subtypes; | |
204 | struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES]; | |
205 | u32 mbus_frame_fmts; | |
206 | const struct smiapp_csi_data_format *csi_format; | |
207 | const struct smiapp_csi_data_format *internal_csi_format; | |
208 | u32 default_mbus_frame_fmts; | |
209 | int default_pixel_order; | |
210 | ||
211 | u8 binning_horizontal; | |
212 | u8 binning_vertical; | |
213 | ||
214 | u8 scale_m; | |
215 | u8 scaling_mode; | |
216 | ||
217 | u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */ | |
218 | u8 flash_capability; | |
219 | u8 frame_skip; | |
220 | ||
221 | int power_count; | |
222 | ||
223 | bool streaming; | |
224 | bool dev_init_done; | |
225 | ||
226 | u8 *nvm; /* nvm memory buffer */ | |
227 | unsigned int nvm_size; /* bytes */ | |
228 | ||
229 | struct smiapp_module_info minfo; | |
230 | ||
231 | struct smiapp_pll pll; | |
232 | ||
233 | /* Pixel array controls */ | |
234 | struct v4l2_ctrl *analog_gain; | |
235 | struct v4l2_ctrl *exposure; | |
236 | struct v4l2_ctrl *hflip; | |
237 | struct v4l2_ctrl *vflip; | |
238 | struct v4l2_ctrl *vblank; | |
239 | struct v4l2_ctrl *hblank; | |
240 | struct v4l2_ctrl *pixel_rate_parray; | |
241 | /* src controls */ | |
242 | struct v4l2_ctrl *link_freq; | |
243 | struct v4l2_ctrl *pixel_rate_csi; | |
244 | }; | |
245 | ||
246 | #define to_smiapp_subdev(_sd) \ | |
247 | container_of(_sd, struct smiapp_subdev, sd) | |
248 | ||
249 | #define to_smiapp_sensor(_sd) \ | |
250 | (to_smiapp_subdev(_sd)->sensor) | |
251 | ||
252 | #endif /* __SMIAPP_PRIV_H_ */ |