• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * linux-5.4/drivers/media/platform/sunxi-vin/modules/actuator/actuator.h
3  *
4  * Copyright (c) 2007-2017 Allwinnertech Co., Ltd.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16 
17 
18 /*
19  ******************************************************************************
20  *
21  * actuator.h
22  *
23  * Hawkview ISP - actuator.h module
24  *
25  * Copyright (c) 2015 by Allwinnertech Co., Ltd.  http://www.allwinnertech.com
26  *
27  * Version        Author         Date            Description
28  *
29  *   3.0          Yang Feng     2015/12/02  ISP Tuning Tools Support
30  *
31  ******************************************************************************
32  */
33 
34 #ifndef __ACTUATOR__H__
35 #define __ACTUATOR__H__
36 
37 #include <linux/module.h>
38 #include <linux/errno.h>
39 #include <linux/kernel.h>
40 #include <linux/init.h>
41 #include <linux/sched.h>
42 #include <linux/slab.h>
43 #include <linux/version.h>
44 #include <linux/mutex.h>
45 #include <linux/videodev2.h>
46 #include <linux/clk.h>
47 #include <linux/delay.h>
48 
49 #include <media/v4l2-device.h>
50 #include <media/v4l2-ioctl.h>
51 #include <media/v4l2-common.h>
52 #include <linux/io.h>
53 #include <linux/platform_device.h>
54 #include <linux/interrupt.h>
55 #include <linux/i2c.h>
56 #include <media/v4l2-subdev.h>
57 #include <linux/moduleparam.h>
58 #include "../../vin-cci/cci_helper.h"
59 
60 struct actuator_ctrl_t;
61 
62 #define ACT_DEV_MIN_CODE 0
63 #define ACT_DEV_MAX_CODE 1023
64 
65 #define MOVE_NEAR   0
66 #define MOVE_FAR    1
67 
68 #define ACT_DEV_DBG_EN 0
69 #define act_err(x, arg...) pr_err("[%s] error, "x, SUNXI_ACT_NAME, ##arg)
70 #if ACT_DEV_DBG_EN
71 #define act_dbg(x, arg...) printk(KERN_DEBUG"[%s]"x, SUNXI_ACT_NAME, ##arg)
72 #else
73 #define act_dbg(x, arg...)
74 #endif
75 
76 typedef enum tag_ACT_SUBDEV_CMD {
77 	ACT_INIT,
78 	ACT_PWDN,
79 	ACT_SOFT_PWDN,
80 
81 	ACT_RELEASE,
82 
83 	ACT_SET_CODE_RANGE,
84 	ACT_GET_CODE_RANGE,
85 	ACT_SET_CODE,
86 	ACT_GET_CODE,
87 
88 	ACT_SET_POS,
89 	ACT_GET_POS,
90 	ACT_MOV_POS,
91 
92 	ACT_MOV_NEAR,
93 	ACT_MOV_FAR,
94 	ACT_MOV_NEAREST,
95 	ACT_MOV_FARTHEST,
96 } __act_subdev_cmd_t;
97 
98 struct actuator_para_t {
99 	unsigned short active_min;
100 	unsigned short active_max;
101 	unsigned short ext_tbl_en;  /*0-disable 1- en*/
102 	unsigned short ext_tbl_steps;
103 	unsigned short *ext_tbl;
104 };
105 
106 struct actuator_ctrl_word_t {
107 	unsigned short pwdn;
108 	unsigned short code;
109 	unsigned short sr;
110 };
111 
112 struct actuator_ctrl_step_t {
113 	unsigned short step;
114 	unsigned short dir;
115 };
116 
117 struct actuator_set_info_t {
118 	unsigned int total_steps;
119 	unsigned short gross_steps;
120 	unsigned short fine_steps;
121 };
122 
123 struct actuator_get_info_t {
124 	unsigned int focal_length_num;
125 	unsigned int focal_length_den;
126 	unsigned int f_number_num;
127 	unsigned int f_number_den;
128 	unsigned int f_pix_num;
129 	unsigned int f_pix_den;
130 	unsigned int total_f_dist_num;
131 	unsigned int total_f_dist_den;
132 	unsigned int hor_view_angle_num;
133 	unsigned int hor_view_angle_den;
134 	unsigned int ver_view_angle_num;
135 	unsigned int ver_view_angle_den;
136 };
137 
138 struct actuator_move_params_t {
139 	char dir;
140 	int num_steps;
141 };
142 
143 struct actuator_cfg_data {
144 	int cfgtype;
145 	unsigned char is_af_supported;
146 	union {
147 		struct actuator_move_params_t move;
148 		struct actuator_set_info_t set_info;
149 		struct actuator_get_info_t get_info;
150 	} cfg;
151 };
152 
153 struct actuator_func_tbl {
154 	int (*actuator_init)(struct actuator_ctrl_t *,
155 				struct actuator_para_t *);
156 	int (*actuator_pwdn)(struct actuator_ctrl_t *, unsigned short);
157 	int (*actuator_init_table)(struct actuator_ctrl_t *,
158 				unsigned short,
159 				unsigned short, unsigned short *);
160 	int (*actuator_release)(struct actuator_ctrl_t *,
161 				struct actuator_ctrl_word_t *);
162 	int (*actuator_move_pos)(struct actuator_ctrl_t *,
163 				unsigned short, unsigned short);
164 	int (*actuator_set_pos)(struct actuator_ctrl_t *, unsigned short);
165 	int (*actuator_set_code)(struct actuator_ctrl_t *,
166 				unsigned short, unsigned short);
167 	int (*actuator_i2c_write)(struct actuator_ctrl_t *,
168 				unsigned short, void *);
169 };
170 
171 typedef enum tag_ACT_STA {
172 	ACT_STA_HW_PWDN,
173 	ACT_STA_SOFT_PWDN,
174 	ACT_STA_IDLE,
175 	ACT_STA_BUSY,
176 	ACT_STA_ERR,
177 	ACT_STA_SCANNING,
178 	ACT_STA_HALT, /*paused to specific pos*/
179 } __act_sta_t;
180 
181 struct actuator_ctrl_t {
182 	unsigned int i2c_addr;
183 	struct i2c_driver *i2c_driver;
184 	struct i2c_client *i2c_client;
185 	struct mutex *actuator_mutex;
186 	struct actuator_func_tbl func_tbl;
187 	struct v4l2_subdev sdev;
188 	struct v4l2_subdev_ops *sdev_ops;
189 	struct actuator_set_info_t set_info;
190 	struct actuator_get_info_t get_info;
191 
192 	int work_status;
193 
194 	unsigned short active_min;
195 	unsigned short active_max;
196 	unsigned short total_steps;
197 
198 	unsigned short curr_pos;
199 	unsigned short curr_code;
200 
201 	unsigned short *step_position_table;
202 
203 };
204 
205 int actuator_move_pos(struct actuator_ctrl_t *a_ctrl,
206 			int num_steps, int direction);
207 
208 int actuator_write_focus(struct actuator_ctrl_t *a_ctrl,
209 			unsigned short pos);
210 long sunxi_actuator_ioctl(struct v4l2_subdev *sd,
211 			unsigned int cmd, void *arg);
212 
213 #endif /*__ACTUATOR__H__*/
214