]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - include/media/camera_common.h
media: soc_camera: add ov13860 v4l2 driver
[sojka/nv-tegra/linux-3.10.git] / include / media / camera_common.h
1 /**
2  * camera_common.h - utilities for tegra camera driver
3  *
4  * Copyright (c) 2015, NVIDIA Corporation.  All rights reserved.
5  *
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.
9  *
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
13  * more details.
14  *
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/>.
17  */
18
19 #ifndef __camera_common__
20 #define __camera_common__
21
22 #include <linux/delay.h>
23 #include <linux/fs.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>
29
30 #include <linux/kernel.h>
31 #include <linux/debugfs.h>
32
33 #include <media/v4l2-device.h>
34 #include <media/v4l2-subdev.h>
35 #include <media/v4l2-ctrls.h>
36 #include <media/soc_camera.h>
37
38 #define V4L2_CID_TEGRA_CAMERA_BASE      (V4L2_CTRL_CLASS_CAMERA | 0x2000)
39
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)
48
49 #define V4L2_CID_TEGRA_CAMERA_LAST      (V4L2_CID_TEGRA_CAMERA_BASE+8)
50
51 #define MAX_BUFFER_SIZE                 32
52
53 struct reg_8 {
54         u16 addr;
55         u8 val;
56 };
57
58 struct reg_16 {
59         u16 addr;
60         u16 val;
61 };
62
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;
70         struct clk *mclk;
71         unsigned int pwdn_gpio;
72         unsigned int reset_gpio;
73         unsigned int af_gpio;
74         bool state;
75 };
76
77 struct camera_common_regulators {
78         const char *avdd;
79         const char *dvdd;
80         const char *iovdd;
81         const char *vcmvdd;
82 };
83
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;
88         unsigned int af_gpio;
89         unsigned int eeprom_base_addr;
90         bool ext_reg;
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;
94         bool use_cam_gpio;
95         bool has_eeprom;
96 };
97
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;
103 };
104
105 int
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);
111
112 int
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);
118
119 enum switch_state {
120         SWITCH_OFF,
121         SWITCH_ON,
122 };
123
124 static const s64 switch_ctrl_qmenu[] = {
125         SWITCH_OFF, SWITCH_ON
126 };
127
128 struct camera_common_frmfmt {
129         struct v4l2_frmsize_discrete    size;
130         bool    hdr_en;
131         int     mode;
132 };
133
134 struct camera_common_colorfmt {
135         enum v4l2_mbus_pixelcode        code;
136         enum v4l2_colorspace            colorspace;
137 };
138
139 struct camera_common_data;
140
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,
145           u16 addr, u8 val);
146         int (*read_reg)(struct camera_common_data *s_data,
147           u16 addr, u8 *val);
148 };
149
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;
158
159         struct v4l2_subdev                      subdev;
160         struct v4l2_ctrl                        **ctrls;
161
162         void    *priv;
163         int     ident;
164         int     numctrls;
165         int csi_port;
166         int numlanes;
167         int     mode;
168         int     numfmts;
169         int     def_mode, def_width, def_height;
170         int     def_clk_freq;
171         int     fmt_width, fmt_height;
172 };
173
174 static inline void msleep_range(unsigned int delay_base)
175 {
176         usleep_range(delay_base * 1000, delay_base * 1000 + 500);
177 }
178
179 static inline struct camera_common_data *to_camera_common_data(
180         const struct i2c_client *client)
181 {
182         return container_of(i2c_get_clientdata(client),
183                             struct camera_common_data, subdev);
184 }
185
186 int camera_common_g_ctrl(struct camera_common_data *s_data,
187                          struct v4l2_control *control);
188
189 int camera_common_regulator_get(struct i2c_client *client,
190                        struct regulator **vreg, const char *vreg_name);
191
192 int camera_common_debugfs_show(struct seq_file *s, void *unused);
193 ssize_t camera_common_debugfs_write(
194         struct file *file,
195         char const __user *buf,
196         size_t count,
197         loff_t *offset);
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,
201                 const char *name);
202
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);
216
217
218 #endif /* __camera_common__ */