2 * camera_common.h - utilities for tegra camera driver
4 * Copyright (c) 2015, NVIDIA Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef __camera_common__
20 #define __camera_common__
22 #include <linux/delay.h>
24 #include <linux/i2c.h>
25 #include <linux/regmap.h>
26 #include <linux/clk.h>
27 #include <linux/regulator/consumer.h>
28 #include <linux/videodev2.h>
30 #include <linux/kernel.h>
31 #include <linux/debugfs.h>
33 #include <media/v4l2-device.h>
34 #include <media/v4l2-subdev.h>
35 #include <media/v4l2-ctrls.h>
36 #include <media/soc_camera.h>
38 #define V4L2_CID_TEGRA_CAMERA_BASE (V4L2_CTRL_CLASS_CAMERA | 0x2000)
40 #define V4L2_CID_FRAME_LENGTH (V4L2_CID_TEGRA_CAMERA_BASE+0)
41 #define V4L2_CID_COARSE_TIME (V4L2_CID_TEGRA_CAMERA_BASE+1)
42 #define V4L2_CID_COARSE_TIME_SHORT (V4L2_CID_TEGRA_CAMERA_BASE+2)
43 #define V4L2_CID_GROUP_HOLD (V4L2_CID_TEGRA_CAMERA_BASE+3)
44 #define V4L2_CID_HDR_EN (V4L2_CID_TEGRA_CAMERA_BASE+4)
45 #define V4L2_CID_EEPROM_DATA (V4L2_CID_TEGRA_CAMERA_BASE+5)
46 #define V4L2_CID_OTP_DATA (V4L2_CID_TEGRA_CAMERA_BASE+6)
47 #define V4L2_CID_FUSE_ID (V4L2_CID_TEGRA_CAMERA_BASE+7)
49 #define V4L2_CID_TEGRA_CAMERA_LAST (V4L2_CID_TEGRA_CAMERA_BASE+8)
51 #define MAX_BUFFER_SIZE 32
63 struct camera_common_power_rail {
64 struct regulator *dvdd;
65 struct regulator *avdd;
66 struct regulator *iovdd;
67 struct regulator *ext_reg1;
68 struct regulator *ext_reg2;
69 struct regulator *vcmvdd;
71 unsigned int pwdn_gpio;
72 unsigned int reset_gpio;
77 struct camera_common_regulators {
84 struct camera_common_pdata {
85 const char *mclk_name; /* NULL for default default_mclk */
86 unsigned int pwdn_gpio;
87 unsigned int reset_gpio;
90 int (*power_on)(struct camera_common_power_rail *pw);
91 int (*power_off)(struct camera_common_power_rail *pw);
92 struct camera_common_regulators regulators;
97 struct camera_common_eeprom_data {
98 struct i2c_client *i2c_client;
99 struct i2c_adapter *adap;
100 struct i2c_board_info brd;
101 struct regmap *regmap;
105 regmap_util_write_table_8(struct regmap *regmap,
106 const struct reg_8 table[],
107 const struct reg_8 override_list[],
108 int num_override_regs,
109 u16 wait_ms_addr, u16 end_addr);
112 regmap_util_write_table_16_as_8(struct regmap *regmap,
113 const struct reg_16 table[],
114 const struct reg_16 override_list[],
115 int num_override_regs,
116 u16 wait_ms_addr, u16 end_addr);
123 static const s64 switch_ctrl_qmenu[] = {
124 SWITCH_OFF, SWITCH_ON
127 struct camera_common_frmfmt {
128 struct v4l2_frmsize_discrete size;
133 struct camera_common_colorfmt {
134 enum v4l2_mbus_pixelcode code;
135 enum v4l2_colorspace colorspace;
138 struct camera_common_data;
140 struct camera_common_sensor_ops {
141 int (*power_on)(struct camera_common_data *s_data);
142 int (*power_off)(struct camera_common_data *s_data);
143 int (*write_reg)(struct camera_common_data *s_data,
145 int (*read_reg)(struct camera_common_data *s_data,
149 struct camera_common_data {
150 struct camera_common_sensor_ops *ops;
151 struct v4l2_ctrl_handler *ctrl_handler;
152 struct i2c_client *i2c_client;
153 const struct camera_common_frmfmt *frmfmt;
154 const struct camera_common_colorfmt *colorfmt;
155 struct dentry *debugdir;
156 struct camera_common_power_rail *power;
158 struct v4l2_subdev subdev;
159 struct v4l2_ctrl **ctrls;
168 int def_mode, def_width, def_height;
170 int fmt_width, fmt_height;
173 static inline void msleep_range(unsigned int delay_base)
175 usleep_range(delay_base * 1000, delay_base * 1000 + 500);
178 static inline struct camera_common_data *to_camera_common_data(
179 const struct i2c_client *client)
181 return container_of(i2c_get_clientdata(client),
182 struct camera_common_data, subdev);
185 int camera_common_g_ctrl(struct camera_common_data *s_data,
186 struct v4l2_control *control);
188 int camera_common_regulator_get(struct i2c_client *client,
189 struct regulator **vreg, const char *vreg_name);
191 int camera_common_debugfs_show(struct seq_file *s, void *unused);
192 ssize_t camera_common_debugfs_write(
194 char const __user *buf,
197 int camera_common_debugfs_open(struct inode *inode, struct file *file);
198 void camera_common_remove_debugfs(struct camera_common_data *s_data);
199 void camera_common_create_debugfs(struct camera_common_data *s_data,
202 const struct camera_common_colorfmt *camera_common_find_datafmt(
203 enum v4l2_mbus_pixelcode code);
204 int camera_common_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
205 enum v4l2_mbus_pixelcode *code);
206 int camera_common_try_fmt(struct v4l2_subdev *sd,
207 struct v4l2_mbus_framefmt *mf);
208 int camera_common_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
209 int camera_common_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
210 int camera_common_g_chip_ident(struct v4l2_subdev *sd,
211 struct v4l2_dbg_chip_ident *id);
212 int camera_common_s_power(struct v4l2_subdev *sd, int on);
213 int camera_common_g_mbus_config(struct v4l2_subdev *sd,
214 struct v4l2_mbus_config *cfg);
217 #endif /* __camera_common__ */