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;
89 unsigned int eeprom_base_addr;
91 int (*power_on)(struct camera_common_power_rail *pw);
92 int (*power_off)(struct camera_common_power_rail *pw);
93 struct camera_common_regulators regulators;
98 struct camera_common_eeprom_data {
99 struct i2c_client *i2c_client;
100 struct i2c_adapter *adap;
101 struct i2c_board_info brd;
102 struct regmap *regmap;
106 regmap_util_write_table_8(struct regmap *regmap,
107 const struct reg_8 table[],
108 const struct reg_8 override_list[],
109 int num_override_regs,
110 u16 wait_ms_addr, u16 end_addr);
113 regmap_util_write_table_16_as_8(struct regmap *regmap,
114 const struct reg_16 table[],
115 const struct reg_16 override_list[],
116 int num_override_regs,
117 u16 wait_ms_addr, u16 end_addr);
124 static const s64 switch_ctrl_qmenu[] = {
125 SWITCH_OFF, SWITCH_ON
128 struct camera_common_frmfmt {
129 struct v4l2_frmsize_discrete size;
134 struct camera_common_colorfmt {
135 enum v4l2_mbus_pixelcode code;
136 enum v4l2_colorspace colorspace;
139 struct camera_common_data;
141 struct camera_common_sensor_ops {
142 int (*power_on)(struct camera_common_data *s_data);
143 int (*power_off)(struct camera_common_data *s_data);
144 int (*write_reg)(struct camera_common_data *s_data,
146 int (*read_reg)(struct camera_common_data *s_data,
150 struct camera_common_data {
151 struct camera_common_sensor_ops *ops;
152 struct v4l2_ctrl_handler *ctrl_handler;
153 struct i2c_client *i2c_client;
154 const struct camera_common_frmfmt *frmfmt;
155 const struct camera_common_colorfmt *colorfmt;
156 struct dentry *debugdir;
157 struct camera_common_power_rail *power;
159 struct v4l2_subdev subdev;
160 struct v4l2_ctrl **ctrls;
169 int def_mode, def_width, def_height;
171 int fmt_width, fmt_height;
174 static inline void msleep_range(unsigned int delay_base)
176 usleep_range(delay_base * 1000, delay_base * 1000 + 500);
179 static inline struct camera_common_data *to_camera_common_data(
180 const struct i2c_client *client)
182 return container_of(i2c_get_clientdata(client),
183 struct camera_common_data, subdev);
186 int camera_common_g_ctrl(struct camera_common_data *s_data,
187 struct v4l2_control *control);
189 int camera_common_regulator_get(struct i2c_client *client,
190 struct regulator **vreg, const char *vreg_name);
192 int camera_common_debugfs_show(struct seq_file *s, void *unused);
193 ssize_t camera_common_debugfs_write(
195 char const __user *buf,
198 int camera_common_debugfs_open(struct inode *inode, struct file *file);
199 void camera_common_remove_debugfs(struct camera_common_data *s_data);
200 void camera_common_create_debugfs(struct camera_common_data *s_data,
203 const struct camera_common_colorfmt *camera_common_find_datafmt(
204 enum v4l2_mbus_pixelcode code);
205 int camera_common_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
206 enum v4l2_mbus_pixelcode *code);
207 int camera_common_try_fmt(struct v4l2_subdev *sd,
208 struct v4l2_mbus_framefmt *mf);
209 int camera_common_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
210 int camera_common_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
211 int camera_common_g_chip_ident(struct v4l2_subdev *sd,
212 struct v4l2_dbg_chip_ident *id);
213 int camera_common_s_power(struct v4l2_subdev *sd, int on);
214 int camera_common_g_mbus_config(struct v4l2_subdev *sd,
215 struct v4l2_mbus_config *cfg);
218 #endif /* __camera_common__ */