blob: ec5d6aecc44defbfdf8f3f3d8a27756c57c7f4f2 [file] [log] [blame]
Erik Lilliebjerg96db5692012-02-16 17:59:32 -07001/* Copyright (C) 2012 NVIDIA Corporation.
Erik Lilliebjergbdce0122011-11-23 03:12:24 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
15 * 02111-1307, USA
16 */
17
18#ifndef __NVC_H__
19#define __NVC_H__
20
21#include <linux/ioctl.h>
22
Erik Lilliebjerg87873742012-03-20 03:56:00 -070023#define NVC_INT2FLOAT_DIVISOR_1K 1000
24#define NVC_INT2FLOAT_DIVISOR_1M 1000000
25#define NVC_INT2FLOAT_DIVISOR 1000
26
Erik Lilliebjergbdce0122011-11-23 03:12:24 -070027struct nvc_param {
28 int param;
29 __u32 sizeofvalue;
30 void *p_value;
31} __packed;
32
Erik Lilliebjerg87873742012-03-20 03:56:00 -070033enum nvc_params {
34 NVC_PARAM_EXPOSURE = 0,
35 NVC_PARAM_GAIN,
36 NVC_PARAM_FRAMERATE,
37 NVC_PARAM_MAX_FRAMERATE,
38 NVC_PARAM_INPUT_CLOCK,
39 NVC_PARAM_LOCUS,
40 NVC_PARAM_FLASH_CAPS,
41 NVC_PARAM_FLASH_LEVEL,
42 NVC_PARAM_FLASH_PIN_STATE,
43 NVC_PARAM_TORCH_CAPS,
44 NVC_PARAM_TORCH_LEVEL,
45 NVC_PARAM_FOCAL_LEN,
46 NVC_PARAM_MAX_APERTURE,
47 NVC_PARAM_FNUMBER,
48 NVC_PARAM_EXPOSURE_LIMITS,
49 NVC_PARAM_GAIN_LIMITS,
50 NVC_PARAM_FRAMERATE_LIMITS,
51 NVC_PARAM_FRAME_RATES,
52 NVC_PARAM_CLOCK_LIMITS,
53 NVC_PARAM_EXP_LATCH_TIME,
54 NVC_PARAM_REGION_USED,
55 NVC_PARAM_CALIBRATION_DATA,
56 NVC_PARAM_CALIBRATION_OVERRIDES,
57 NVC_PARAM_SELF_TEST,
58 NVC_PARAM_STS,
59 NVC_PARAM_TESTMODE,
60 NVC_PARAM_EXPECTED_VALUES,
61 NVC_PARAM_RESET,
62 NVC_PARAM_OPTIMIZE_RES,
63 NVC_PARAM_DETECT_COLOR_TEMP,
64 NVC_PARAM_LINES_PER_SEC,
65 NVC_PARAM_CAPS,
66 NVC_PARAM_CUSTOM_BLOCK_INFO,
67 NVC_PARAM_STEREO_CAP,
68 NVC_PARAM_FOCUS_STEREO,
69 NVC_PARAM_STEREO,
70 NVC_PARAM_INHERENT_GAIN,
71 NVC_PARAM_VIEW_ANGLE_H,
72 NVC_PARAM_VIEW_ANGLE_V,
73 NVC_PARAM_ISP_SETTING,
74 NVC_PARAM_OPERATION_MODE,
75 NVC_PARAM_SUPPORT_ISP,
76 NVC_PARAM_AWB_LOCK,
77 NVC_PARAM_AE_LOCK,
78 NVC_PARAM_RES_CHANGE_WAIT_TIME,
79 NVC_PARAM_FACTORY_CALIBRATION_DATA,
80 NVC_PARAM_DEV_ID,
81 NVC_PARAM_GROUP_HOLD,
Charlie Huang74d8c7c2012-11-02 16:16:04 -070082 NVC_PARAM_SET_SENSOR_FLASH_MODE,
Erik Lilliebjerg87873742012-03-20 03:56:00 -070083 NVC_PARAM_BEGIN_VENDOR_EXTENSIONS = 0x10000000,
84 NVC_PARAM_CALIBRATION_STATUS,
85 NVC_PARAM_TEST_PATTERN,
86 NVC_PARAM_MODULE_INFO,
87 NVC_PARAM_FLASH_MAX_POWER,
88 NVC_PARAM_DIRECTION,
89 NVC_PARAM_SENSOR_TYPE,
90 NVC_PARAM_DLI_CHECK,
91 NVC_PARAM_PARALLEL_DLI_CHECK,
92 NVC_PARAM_BRACKET_CAPS,
93 NVC_PARAM_NUM,
94 NVC_PARAM_I2C,
95 NVC_PARAM_FORCE32 = 0x7FFFFFFF
96};
Erik Lilliebjergbdce0122011-11-23 03:12:24 -070097
98/* sync off */
99#define NVC_SYNC_OFF 0
100/* use only this device (the one receiving the call) */
101#define NVC_SYNC_MASTER 1
102/* use only the synced device (the "other" device) */
103#define NVC_SYNC_SLAVE 2
104/* use both synced devices at the same time */
105#define NVC_SYNC_STEREO 3
106
107#define NVC_RESET_HARD 0
108#define NVC_RESET_SOFT 1
109
Erik Lilliebjerg87873742012-03-20 03:56:00 -0700110struct nvc_param_isp {
111 int attr;
112 void *p_data;
113 __u32 data_size;
114} __packed;
115
116struct nvc_isp_focus_param {
117 __s32 min_pos;
118 __s32 max_pos;
119 __s32 hyperfocal;
120 __s32 macro;
121 __s32 powersave;
122} __packed;
123
124struct nvc_isp_focus_pos {
125 __u32 is_auto;
126 __s32 value;
127} __packed;
128
129struct nvc_isp_focus_region {
130 __u32 num_region;
131 __s32 value;
132} __packed;
133
134enum nvc_params_isp {
135 NVC_PARAM_ISP_FOCUS_CAF = 16389,
136 NVC_PARAM_ISP_FOCUS_CAF_PAUSE,
137 NVC_PARAM_ISP_FOCUS_CAF_STS,
138 NVC_PARAM_ISP_FOCUS_POS = 16407,
139 NVC_PARAM_ISP_FOCUS_RANGE,
140 NVC_PARAM_ISP_FOCUS_AF_RGN = 16413,
141 NVC_PARAM_ISP_FOCUS_AF_RGN_MASK,
142 NVC_PARAM_ISP_FOCUS_AF_RGN_STS,
143 NVC_PARAM_ISP_FOCUS_CTRL = 16424,
144 NVC_PARAM_ISP_FOCUS_TRGR,
145 NVC_PARAM_ISP_FOCUS_STS,
146};
147
148#define NVC_PARAM_ISP_FOCUS_STS_BUSY 0
149#define NVC_PARAM_ISP_FOCUS_STS_LOCKD 1
150#define NVC_PARAM_ISP_FOCUS_STS_FAILD 2
151#define NVC_PARAM_ISP_FOCUS_STS_ERR 3
152
153#define NVC_PARAM_ISP_FOCUS_CTRL_ON 0
154#define NVC_PARAM_ISP_FOCUS_CTRL_OFF 1
155#define NVC_PARAM_ISP_FOCUS_CTRL_AUTO 2
156#define NVC_PARAM_ISP_FOCUS_CTRL_ALOCK 3
157
158#define NVC_PARAM_ISP_FOCUS_CAF_CONVRG 1
159#define NVC_PARAM_ISP_FOCUS_CAF_SEARCH 2
160
161#define NVC_PARAM_ISP_FOCUS_POS_INF 0
162
163
Erik Lilliebjergbdce0122011-11-23 03:12:24 -0700164#define NVC_IOCTL_PWR_WR _IOW('o', 102, int)
165#define NVC_IOCTL_PWR_RD _IOW('o', 103, int)
166#define NVC_IOCTL_PARAM_WR _IOW('o', 104, struct nvc_param)
167#define NVC_IOCTL_PARAM_RD _IOWR('o', 105, struct nvc_param)
Erik Lilliebjerg87873742012-03-20 03:56:00 -0700168#define NVC_IOCTL_PARAM_ISP_RD _IOWR('o', 200, struct nvc_param_isp)
169#define NVC_IOCTL_PARAM_ISP_WR _IOWR('o', 201, struct nvc_param_isp)
Erik Lilliebjergbdce0122011-11-23 03:12:24 -0700170
171
172#ifdef __KERNEL__
173
174#include <linux/regulator/consumer.h>
175
176/* The NVC_CFG_ defines are for the .cfg entry in the
177 * platform data structure.
178 */
179/* Device not registered if not found */
180#define NVC_CFG_NODEV (1 << 0)
181/* Don't return errors */
182#define NVC_CFG_NOERR (1 << 1)
183/* Always go to _PWR_STDBY instead of _PWR_OFF */
184#define NVC_CFG_OFF2STDBY (1 << 2)
185/* Init device at sys boot */
186#define NVC_CFG_BOOT_INIT (1 << 3)
187/* Sync mode uses an I2C MUX to send at same time */
188#define NVC_CFG_SYNC_I2C_MUX (1 << 4)
189
190/* Expected higher level power calls are:
191 * 1 = OFF
192 * 2 = STANDBY
193 * 3 = ON
194 * These will be multiplied by 2 before given to the driver's PM code that
195 * uses the _PWR_ defines. This allows us to insert defines to give more power
196 * granularity and still remain linear with regards to the power usage and
197 * full power state transition latency for easy implementation of PM
198 * algorithms.
199 * The PM actions:
200 * _PWR_ERR = Non-valid state.
Erik Lilliebjerg96db5692012-02-16 17:59:32 -0700201 * _PWR_OFF_FORCE = _PWR_OFF is forced regardless of standby mechanisms.
Erik Lilliebjergbdce0122011-11-23 03:12:24 -0700202 * _PWR_OFF = Device, regulators, clocks, etc is turned off. The longest
203 * transition time to _PWR_ON is from this state.
204 * _PWR_STDBY_OFF = Device is useless but powered. No communication possible.
205 * Device does not retain programming. Main purpose is for
206 * faster return to _PWR_ON without regulator delays.
207 * _PWR_STDBY = Device is in standby. Device retains programming.
208 * _PWR_COMM = Device is powered enough to communicate with the device.
209 * _PWR_ON = Device is at full power with active output.
210 *
Erik Lilliebjerg96db5692012-02-16 17:59:32 -0700211 * The kernel drivers treat these calls as Guaranteed Level Of Service.
Erik Lilliebjergbdce0122011-11-23 03:12:24 -0700212 */
213
214#define NVC_PWR_ERR 0
Erik Lilliebjergf5a39392011-12-15 19:36:43 -0700215#define NVC_PWR_OFF_FORCE 1
Erik Lilliebjergbdce0122011-11-23 03:12:24 -0700216#define NVC_PWR_OFF 2
217#define NVC_PWR_STDBY_OFF 3
218#define NVC_PWR_STDBY 4
219#define NVC_PWR_COMM 5
220#define NVC_PWR_ON 6
221
Erik Lilliebjerg87873742012-03-20 03:56:00 -0700222struct nvc_regulator_init {
223 unsigned vreg_num;
224 const char *vreg_name;
225};
226
Erik Lilliebjergbdce0122011-11-23 03:12:24 -0700227struct nvc_regulator {
228 bool vreg_flag;
229 struct regulator *vreg;
230 const char *vreg_name;
231};
232
Erik Lilliebjerg96db5692012-02-16 17:59:32 -0700233/* The GPIO mechanism uses the _gpio_type in the device's header file as a key
234 * to define all the possible GPIO's the device will need. The key is used to
235 * combine the GPIO's defined in the platform board file using the
236 * nvc_gpio_pdata structure with the nvc_gpio structure in the nvc kernel
237 * driver.
238 */
239struct nvc_gpio_pdata {
240 /* use a _gpio_type enum from the device's header file */
241 unsigned gpio_type;
242 /* the GPIO system number */
243 unsigned gpio;
244 /* init_en is typically set to true for all GPIO's used by the driver.
245 * However, some GPIO's are used by multiple drivers (CSI MUX, reset,
246 * etc.). In this case, this is set true for only one of the drivers
247 * that uses the GPIO and false for the others. If the platform board
248 * file initializes the GPIO, then this is false for all of the drivers
249 * using the GPIO.
250 */
251 bool init_en;
252 /* this defines the assert level for the general purpose GPIO's
253 * (_GPIO_TYPE_GPx, etc.). The _GPIO_TYPE_GPx can be used for a GPIO
254 * that the driver doesn't know about but is needed in order for the
255 * device to work (CSI select, regulator, etc.). The driver will
256 * blindly assert the GPIO when the device is operational and deassert
257 * when the device is turned off.
258 */
259 bool active_high;
260};
261
262struct nvc_gpio_init {
263 /* key to match in nvc_gpio_pdata */
264 unsigned gpio_type;
265 /* same as in gpio.h */
266 unsigned long flags;
267 /* same as in gpio.h */
268 const char *label;
269 /* used instead of nvc_gpio_pdata.active_high if use_flags true */
270 bool active_high;
271 /* false if nvc_gpio_pdata.active_high used else flags is used */
272 bool use_flags;
273};
274
275struct nvc_gpio {
276 unsigned gpio; /* system GPIO number */
277 bool own; /* gets set if driver initializes */
278 bool active_high; /* used for GP GPIOs */
Erik Lilliebjergac319ed2012-04-02 22:45:49 -0700279 bool valid; /* set if struct data is valid */
Erik Lilliebjerg96db5692012-02-16 17:59:32 -0700280 bool flag; /* scratch flag for driver implementation */
281};
282
Erik Lilliebjergbdce0122011-11-23 03:12:24 -0700283#endif /* __KERNEL__ */
284
285#endif /* __NVC_H__ */
286