Commit | Line | Data |
---|---|---|
5fd039ac SS |
1 | /* |
2 | * Samsung Exynos5 SoC series Sensor driver | |
3 | * | |
4 | * | |
5 | * Copyright (c) 2018 Samsung Electronics Co., Ltd | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
11 | ||
12 | #include <linux/i2c.h> | |
13 | #include <linux/slab.h> | |
14 | #include <linux/irq.h> | |
15 | #include <linux/interrupt.h> | |
16 | #include <linux/delay.h> | |
17 | #include <linux/version.h> | |
18 | #include <linux/gpio.h> | |
19 | #include <linux/clk.h> | |
20 | #include <linux/regulator/consumer.h> | |
21 | #include <linux/videodev2.h> | |
22 | #include <linux/videodev2_exynos_camera.h> | |
23 | #include <linux/module.h> | |
24 | #include <linux/moduleparam.h> | |
25 | #include <linux/platform_device.h> | |
26 | #include <linux/of_gpio.h> | |
27 | #include <media/v4l2-ctrls.h> | |
28 | #include <media/v4l2-device.h> | |
29 | #include <media/v4l2-subdev.h> | |
30 | ||
31 | #include <exynos-fimc-is-sensor.h> | |
32 | #include "fimc-is-hw.h" | |
33 | #include "fimc-is-core.h" | |
34 | #include "fimc-is-device-sensor.h" | |
35 | #include "fimc-is-device-sensor-peri.h" | |
36 | #include "fimc-is-resourcemgr.h" | |
37 | #include "fimc-is-dt.h" | |
38 | ||
39 | #include "fimc-is-device-module-base.h" | |
40 | ||
b95661ba WK |
41 | #define MAX_5E9_SETPIN_CNT 2 |
42 | ||
5fd039ac SS |
43 | static struct fimc_is_sensor_cfg config_module_5e9[] = { |
44 | /* 2592x1944@30fps */ | |
91942429 | 45 | FIMC_IS_SENSOR_CFG(2592, 1944, 30, 0, 0, CSI_DATA_LANES_2, 871, CSI_MODE_VC_ONLY, PD_NONE, |
5fd039ac SS |
46 | VC_IN(0, HW_FORMAT_RAW10, 2592, 1944), VC_OUT(HW_FORMAT_RAW10, VC_NOTHING, 0, 0), |
47 | VC_IN(1, HW_FORMAT_UNKNOWN, 0, 0), VC_OUT(HW_FORMAT_UNKNOWN, VC_NOTHING, 0, 0), | |
48 | VC_IN(2, HW_FORMAT_UNKNOWN, 0, 0), VC_OUT(HW_FORMAT_UNKNOWN, VC_NOTHING, 0, 0), | |
49 | VC_IN(3, HW_FORMAT_UNKNOWN, 0, 0), VC_OUT(HW_FORMAT_UNKNOWN, VC_NOTHING, 0, 0)), | |
5fd039ac SS |
50 | }; |
51 | ||
52 | static const struct v4l2_subdev_core_ops core_ops = { | |
53 | .init = sensor_module_init, | |
54 | .g_ctrl = sensor_module_g_ctrl, | |
55 | .s_ctrl = sensor_module_s_ctrl, | |
56 | .g_ext_ctrls = sensor_module_g_ext_ctrls, | |
57 | .s_ext_ctrls = sensor_module_s_ext_ctrls, | |
58 | .ioctl = sensor_module_ioctl, | |
59 | .log_status = sensor_module_log_status, | |
60 | }; | |
61 | ||
62 | static const struct v4l2_subdev_video_ops video_ops = { | |
63 | .s_routing = sensor_module_s_routing, | |
64 | .s_stream = sensor_module_s_stream, | |
65 | .s_parm = sensor_module_s_param | |
66 | }; | |
67 | ||
68 | static const struct v4l2_subdev_pad_ops pad_ops = { | |
69 | .set_fmt = sensor_module_s_format | |
70 | }; | |
71 | ||
72 | static const struct v4l2_subdev_ops subdev_ops = { | |
73 | .core = &core_ops, | |
74 | .video = &video_ops, | |
75 | .pad = &pad_ops | |
76 | }; | |
77 | ||
b95661ba | 78 | static int sensor_module_5e9_power_setpin_0(struct device *dev, |
5fd039ac SS |
79 | struct exynos_platform_fimc_is_module *pdata) |
80 | { | |
81 | struct device_node *dnode; | |
82 | int gpio_reset = 0; | |
83 | int gpio_none = 0; | |
46ed5470 | 84 | int gpio_iovdd_en = 0; |
72cb262e | 85 | int gpio_mclk = 0; |
5fd039ac SS |
86 | struct fimc_is_core *core; |
87 | ||
88 | FIMC_BUG(!dev); | |
89 | ||
90 | dnode = dev->of_node; | |
91 | ||
92 | core = (struct fimc_is_core *)dev_get_drvdata(fimc_is_dev); | |
93 | if (!core) { | |
94 | err("core is NULL"); | |
95 | return -EINVAL; | |
96 | } | |
97 | ||
98 | dev_info(dev, "%s E v4\n", __func__); | |
99 | ||
100 | gpio_reset = of_get_named_gpio(dnode, "gpio_reset", 0); | |
101 | if (!gpio_is_valid(gpio_reset)) { | |
102 | dev_err(dev, "failed to get gpio_reset\n"); | |
103 | } else { | |
104 | gpio_request_one(gpio_reset, GPIOF_OUT_INIT_LOW, "CAM_GPIO_OUTPUT_LOW"); | |
105 | gpio_free(gpio_reset); | |
106 | } | |
107 | ||
46ed5470 | 108 | gpio_iovdd_en = of_get_named_gpio(dnode, "gpio_iovdd_en", 0); |
109 | if (gpio_is_valid(gpio_iovdd_en)) { | |
110 | if (gpio_request_one(gpio_iovdd_en, GPIOF_OUT_INIT_LOW, "CAM_IOVDD_EN_LOW")) { | |
111 | dev_err(dev, "%s: failed to gpio request iovdd_en\n", __func__); | |
112 | return -ENODEV; | |
113 | } | |
114 | gpio_free(gpio_iovdd_en); | |
115 | } else { | |
116 | dev_err(dev, "%s: failed to get iovdd_en\n", __func__); | |
117 | return -EINVAL; | |
118 | } | |
5fd039ac | 119 | |
72cb262e DK |
120 | gpio_mclk = of_get_named_gpio(dnode, "gpio_mclk", 0); |
121 | if (gpio_is_valid(gpio_mclk)) { | |
122 | if (gpio_request_one(gpio_mclk, GPIOF_OUT_INIT_LOW, "CAM_MCLK_OUTPUT_LOW")) { | |
123 | dev_err(dev, "%s: failed to gpio request mclk\n", __func__); | |
124 | return -ENODEV; | |
125 | } | |
126 | gpio_free(gpio_mclk); | |
127 | } else { | |
128 | dev_err(dev, "%s: failed to get mclk\n", __func__); | |
129 | return -EINVAL; | |
130 | } | |
131 | ||
5fd039ac SS |
132 | SET_PIN_INIT(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON); |
133 | SET_PIN_INIT(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF); | |
46ed5470 | 134 | SET_PIN_INIT(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON); |
135 | SET_PIN_INIT(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF); | |
5fd039ac SS |
136 | |
137 | /* Normal On */ | |
138 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_reset, "sen_rst low", PIN_OUTPUT, 0, 0); | |
46ed5470 | 139 | |
140 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_none, "VLDO44_PMIC_DCAM_DVDD_1P2", PIN_REGULATOR, 1, 0); | |
141 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_none, "VLDO41_PMIC_FCAM_AVDD_2P8", PIN_REGULATOR, 1, 0); | |
8a7c99ba | 142 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_iovdd_en, "iovdd_en", PIN_OUTPUT, 1, 1000); |
5fd039ac SS |
143 | SET_PIN_SHARED(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, SRT_ACQUIRE, |
144 | &core->shared_rsc_slock[SHARED_PIN0], &core->shared_rsc_count[SHARED_PIN0], 1); | |
145 | ||
46ed5470 | 146 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_reset, "sen_rst high", PIN_OUTPUT, 1, 0); |
8a7c99ba | 147 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_none, "pin", PIN_FUNCTION, 2, 2000); |
46ed5470 | 148 | |
5fd039ac SS |
149 | /* Normal Off */ |
150 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 0, 0); | |
151 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 1, 0); | |
5fd039ac SS |
152 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 0, 0); |
153 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_reset, "sen_rst", PIN_OUTPUT, 0, 0); | |
46ed5470 | 154 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "VLDO44_PMIC_DCAM_DVDD_1P2", PIN_REGULATOR, 0, 0); |
46ed5470 | 155 | |
156 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "VLDO41_PMIC_FCAM_AVDD_2P8", PIN_REGULATOR, 0, 0); | |
157 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_iovdd_en, "iovdd_en", PIN_OUTPUT, 0, 0); | |
158 | SET_PIN_SHARED(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, SRT_RELEASE, | |
159 | &core->shared_rsc_slock[SHARED_PIN0], &core->shared_rsc_count[SHARED_PIN0], 0); | |
160 | ||
161 | /* SENSOR FACTORY TEST - POWER ON */ | |
162 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_reset, "sen_rst low", PIN_OUTPUT, 0, 0); | |
46ed5470 | 163 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_none, "VLDO44_PMIC_DCAM_DVDD_1P2", PIN_REGULATOR, 1, 0); |
164 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_none, "VLDO41_PMIC_FCAM_AVDD_2P8", PIN_REGULATOR, 1, 0); | |
8a7c99ba | 165 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_iovdd_en, "iovdd_en", PIN_OUTPUT, 1, 1000); |
46ed5470 | 166 | SET_PIN_SHARED(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, SRT_ACQUIRE, |
167 | &core->shared_rsc_slock[SHARED_PIN0], &core->shared_rsc_count[SHARED_PIN0], 1); | |
168 | ||
169 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_reset, "sen_rst high", PIN_OUTPUT, 1, 0); | |
8a7c99ba | 170 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_none, "pin", PIN_FUNCTION, 2, 2000); |
46ed5470 | 171 | |
172 | /* SENSOR FACTORY TEST - POWER Off */ | |
173 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 0, 0); | |
174 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 1, 0); | |
175 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 0, 0); | |
176 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_reset, "sen_rst", PIN_OUTPUT, 0, 0); | |
177 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "VLDO44_PMIC_DCAM_DVDD_1P2", PIN_REGULATOR, 0, 0); | |
46ed5470 | 178 | |
179 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "VLDO41_PMIC_FCAM_AVDD_2P8", PIN_REGULATOR, 0, 0); | |
180 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_iovdd_en, "iovdd_en", PIN_OUTPUT, 0, 0); | |
181 | SET_PIN_SHARED(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, SRT_RELEASE, | |
182 | &core->shared_rsc_slock[SHARED_PIN0], &core->shared_rsc_count[SHARED_PIN0], 0); | |
5fd039ac SS |
183 | |
184 | dev_info(dev, "%s X v4\n", __func__); | |
185 | ||
186 | return 0; | |
187 | } | |
188 | ||
b95661ba WK |
189 | static int sensor_module_5e9_power_setpin_1(struct device *dev, |
190 | struct exynos_platform_fimc_is_module *pdata) | |
191 | { | |
192 | struct device_node *dnode; | |
193 | int gpio_reset = 0; | |
194 | int gpio_none = 0; | |
195 | int gpio_avdd_en = 0; | |
196 | int gpio_iovdd_en = 0; | |
2fbec74c | 197 | int gpio_mclk = 0; |
b95661ba WK |
198 | struct fimc_is_core *core; |
199 | ||
200 | FIMC_BUG(!dev); | |
201 | ||
202 | dnode = dev->of_node; | |
203 | ||
204 | core = (struct fimc_is_core *)dev_get_drvdata(fimc_is_dev); | |
205 | if (!core) { | |
206 | err("core is NULL"); | |
207 | return -EINVAL; | |
208 | } | |
209 | ||
210 | dev_info(dev, "%s E v4\n", __func__); | |
211 | ||
212 | gpio_reset = of_get_named_gpio(dnode, "gpio_reset", 0); | |
213 | if (!gpio_is_valid(gpio_reset)) { | |
214 | dev_err(dev, "failed to get gpio_reset\n"); | |
215 | } else { | |
216 | gpio_request_one(gpio_reset, GPIOF_OUT_INIT_LOW, "CAM_GPIO_OUTPUT_LOW"); | |
217 | gpio_free(gpio_reset); | |
218 | } | |
219 | ||
220 | gpio_avdd_en = of_get_named_gpio(dnode, "gpio_avdd_en", 0); | |
221 | if (gpio_is_valid(gpio_avdd_en)) { | |
222 | if (gpio_request_one(gpio_avdd_en, GPIOF_OUT_INIT_LOW, "CAM_AVDD_EN_LOW")) { | |
223 | dev_err(dev, "%s: failed to gpio request avdd_en\n", __func__); | |
224 | return -ENODEV; | |
225 | } | |
226 | gpio_free(gpio_avdd_en); | |
227 | } else { | |
228 | dev_err(dev, "%s: failed to get avdd_en\n", __func__); | |
229 | return -EINVAL; | |
230 | } | |
231 | ||
232 | gpio_iovdd_en = of_get_named_gpio(dnode, "gpio_iovdd_en", 0); | |
233 | if (gpio_is_valid(gpio_iovdd_en)) { | |
234 | if (gpio_request_one(gpio_iovdd_en, GPIOF_OUT_INIT_LOW, "CAM_IOVDD_EN_LOW")) { | |
235 | dev_err(dev, "%s: failed to gpio request iovdd_en\n", __func__); | |
236 | return -ENODEV; | |
237 | } | |
238 | gpio_free(gpio_iovdd_en); | |
239 | } else { | |
240 | dev_err(dev, "%s: failed to get iovdd_en\n", __func__); | |
241 | return -EINVAL; | |
242 | } | |
243 | ||
2fbec74c DK |
244 | gpio_mclk = of_get_named_gpio(dnode, "gpio_mclk", 0); |
245 | if (gpio_is_valid(gpio_mclk)) { | |
246 | if (gpio_request_one(gpio_mclk, GPIOF_OUT_INIT_LOW, "CAM_MCLK_OUTPUT_LOW")) { | |
247 | dev_err(dev, "%s: failed to gpio request mclk\n", __func__); | |
248 | return -ENODEV; | |
249 | } | |
250 | gpio_free(gpio_mclk); | |
251 | } else { | |
252 | dev_err(dev, "%s: failed to get mclk\n", __func__); | |
253 | return -EINVAL; | |
254 | } | |
255 | ||
b95661ba WK |
256 | SET_PIN_INIT(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON); |
257 | SET_PIN_INIT(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF); | |
4931f907 WK |
258 | SET_PIN_INIT(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON); |
259 | SET_PIN_INIT(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF); | |
b95661ba WK |
260 | |
261 | /* Normal On */ | |
32525acf | 262 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_reset, "sen_rst low", PIN_OUTPUT, 0, 100); |
b95661ba WK |
263 | |
264 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_none, "VLDO44_PMIC_DCAM_DVDD_1P2", PIN_REGULATOR, 1, 0); | |
265 | /* TODO: need to check */ | |
266 | /* SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_none, "VLDO41_PMIC_FCAM_AVDD_2P8", PIN_REGULATOR, 1, 0); */ | |
267 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_avdd_en, "avdd_en", PIN_OUTPUT, 1, 0); | |
6d7646e7 | 268 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_iovdd_en, "iovdd_en", PIN_OUTPUT, 1, 1000); |
b95661ba WK |
269 | SET_PIN_SHARED(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, SRT_ACQUIRE, |
270 | &core->shared_rsc_slock[SHARED_PIN0], &core->shared_rsc_count[SHARED_PIN0], 1); | |
271 | ||
6d7646e7 | 272 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_none, "pin", PIN_FUNCTION, 2, 1000); |
273 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_reset, "sen_rst high", PIN_OUTPUT, 1, 2000); | |
14ee40af | 274 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, gpio_none, "retry delay", PIN_RETRY, 0, 2000); |
b95661ba WK |
275 | |
276 | /* Normal Off */ | |
6d7646e7 | 277 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_reset, "sen_rst", PIN_OUTPUT, 0, 1000); |
b95661ba WK |
278 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 0, 0); |
279 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 1, 0); | |
6d7646e7 | 280 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 0, 1000); |
791d0dc6 | 281 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "VLDO44_PMIC_DCAM_DVDD_1P2", PIN_REGULATOR, 0, 0); |
b95661ba WK |
282 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_avdd_en, "avdd_en", PIN_OUTPUT, 0, 0); |
283 | /* TODO: need to check */ | |
284 | /* SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_none, "VLDO41_PMIC_FCAM_AVDD_2P8", PIN_REGULATOR, 0, 0); */ | |
285 | SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, gpio_iovdd_en, "iovdd_en", PIN_OUTPUT, 0, 0); | |
286 | SET_PIN_SHARED(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, SRT_RELEASE, | |
287 | &core->shared_rsc_slock[SHARED_PIN0], &core->shared_rsc_count[SHARED_PIN0], 0); | |
288 | ||
4931f907 | 289 | /* SENSOR FACTORY TEST - POWER ON */ |
32525acf | 290 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_reset, "sen_rst low", PIN_OUTPUT, 0, 100); |
4931f907 WK |
291 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_none, "VLDO44_PMIC_DCAM_DVDD_1P2", PIN_REGULATOR, 1, 0); |
292 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_avdd_en, "avdd_en", PIN_OUTPUT, 1, 0); | |
6d7646e7 | 293 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_iovdd_en, "iovdd_en", PIN_OUTPUT, 1, 1000); |
294 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_none, "pin", PIN_FUNCTION, 2, 1000); | |
295 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_reset, "sen_rst high", PIN_OUTPUT, 1, 2000); | |
14ee40af | 296 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_ON, gpio_none, "retry delay", PIN_RETRY, 0, 2000); |
4931f907 WK |
297 | |
298 | /* Normal Off */ | |
6d7646e7 | 299 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_reset, "sen_rst", PIN_OUTPUT, 0, 1000); |
4931f907 WK |
300 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 0, 0); |
301 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 1, 0); | |
6d7646e7 | 302 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "pin", PIN_FUNCTION, 0, 1000); |
791d0dc6 | 303 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_none, "VLDO44_PMIC_DCAM_DVDD_1P2", PIN_REGULATOR, 0, 0); |
4931f907 WK |
304 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_avdd_en, "avdd_en", PIN_OUTPUT, 0, 0); |
305 | SET_PIN(pdata, SENSOR_SCENARIO_FACTORY, GPIO_SCENARIO_OFF, gpio_iovdd_en, "iovdd_en", PIN_OUTPUT, 0, 0); | |
b95661ba WK |
306 | |
307 | dev_info(dev, "%s X v4\n", __func__); | |
308 | ||
309 | return 0; | |
310 | } | |
311 | ||
312 | static int (* sensor_module_5e9_power_setpin[MAX_5E9_SETPIN_CNT])(struct device *dev, | |
313 | struct exynos_platform_fimc_is_module *pdata) = { | |
314 | sensor_module_5e9_power_setpin_0, | |
315 | sensor_module_5e9_power_setpin_1 | |
316 | }; | |
5fd039ac SS |
317 | |
318 | static int __init sensor_module_5e9_probe(struct platform_device *pdev) | |
319 | { | |
320 | int ret = 0; | |
321 | struct fimc_is_core *core; | |
322 | struct v4l2_subdev *subdev_module; | |
323 | struct fimc_is_module_enum *module; | |
324 | struct fimc_is_device_sensor *device; | |
325 | struct sensor_open_extended *ext; | |
326 | struct exynos_platform_fimc_is_module *pdata; | |
327 | struct device *dev; | |
328 | struct pinctrl_state *s; | |
b95661ba | 329 | int power_seq_idx = 0; |
46ed5470 | 330 | int setfile_idx = 0; |
5fd039ac SS |
331 | |
332 | FIMC_BUG(!fimc_is_dev); | |
333 | ||
334 | core = (struct fimc_is_core *)dev_get_drvdata(fimc_is_dev); | |
335 | if (!core) { | |
336 | probe_info("core device is not yet probed"); | |
337 | return -EPROBE_DEFER; | |
338 | } | |
339 | ||
340 | dev = &pdev->dev; | |
341 | ||
b95661ba WK |
342 | if (of_property_read_bool(dev->of_node, "power_seq_idx")) { |
343 | ret = of_property_read_u32(dev->of_node, "power_seq_idx", &power_seq_idx); | |
344 | if (ret) { | |
345 | warn("power_seq_idx read is fail(%d)", ret); | |
346 | } else { | |
347 | if (power_seq_idx >= MAX_5E9_SETPIN_CNT) { | |
348 | warn("wrong power_seq_idx(%d >= %d) set as default\n", | |
349 | power_seq_idx, MAX_5E9_SETPIN_CNT); | |
350 | power_seq_idx = 0; | |
351 | } | |
352 | } | |
353 | } else { | |
354 | power_seq_idx = 0; | |
355 | } | |
356 | probe_info("%s power_seq_idx(%d)\n", __func__, power_seq_idx); | |
357 | ||
358 | fimc_is_module_parse_dt(dev, sensor_module_5e9_power_setpin[power_seq_idx]); | |
5fd039ac | 359 | |
46ed5470 | 360 | if (of_property_read_bool(dev->of_node, "setfile_idx")) { |
361 | ret = of_property_read_u32(dev->of_node, "setfile_idx", &setfile_idx); | |
362 | if (ret) { | |
363 | warn("setfile_idx read is fail(%d)", ret); | |
364 | setfile_idx = 0; | |
365 | } | |
366 | } else { | |
367 | setfile_idx = 0; | |
368 | } | |
369 | probe_info("%s setfile_idx(%d)\n", __func__, setfile_idx); | |
370 | ||
5fd039ac SS |
371 | pdata = dev_get_platdata(dev); |
372 | device = &core->sensor[pdata->id]; | |
373 | ||
374 | subdev_module = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); | |
375 | if (!subdev_module) { | |
376 | ret = -ENOMEM; | |
377 | goto p_err; | |
378 | } | |
379 | ||
380 | probe_info("%s pdta->id(%d), module_enum id = %d\n", __func__, pdata->id, atomic_read(&device->module_count)); | |
381 | module = &device->module_enum[atomic_read(&device->module_count)]; | |
382 | atomic_inc(&device->module_count); | |
383 | clear_bit(FIMC_IS_MODULE_GPIO_ON, &module->state); | |
384 | module->pdata = pdata; | |
385 | module->dev = dev; | |
386 | module->sensor_id = SENSOR_NAME_S5K5E9; | |
387 | module->subdev = subdev_module; | |
388 | module->device = pdata->id; | |
389 | module->client = NULL; | |
390 | module->active_width = 2592; | |
391 | module->active_height = 1944; | |
392 | module->margin_left = 0; | |
393 | module->margin_right = 0; | |
394 | module->margin_top = 0; | |
395 | module->margin_bottom = 0; | |
396 | module->pixel_width = module->active_width; | |
397 | module->pixel_height = module->active_height; | |
398 | module->max_framerate = 120; | |
399 | module->position = pdata->position; | |
400 | module->bitwidth = 10; | |
401 | module->sensor_maker = "SLSI"; | |
402 | module->sensor_name = "S5K5E9"; | |
46ed5470 | 403 | if (setfile_idx) |
404 | module->setfile_name = "setfile_5e9_troika.bin"; | |
405 | else | |
406 | module->setfile_name = "setfile_5e9.bin"; | |
5fd039ac SS |
407 | module->cfgs = ARRAY_SIZE(config_module_5e9); |
408 | module->cfg = config_module_5e9; | |
409 | module->ops = NULL; | |
410 | /* Sensor peri */ | |
411 | module->private_data = kzalloc(sizeof(struct fimc_is_device_sensor_peri), GFP_KERNEL); | |
412 | if (!module->private_data) { | |
413 | ret = -ENOMEM; | |
414 | goto p_err; | |
415 | } | |
416 | fimc_is_sensor_peri_probe((struct fimc_is_device_sensor_peri *)module->private_data); | |
417 | PERI_SET_MODULE(module); | |
418 | ||
419 | ext = &module->ext; | |
420 | ||
421 | ext->sensor_con.product_name = module->sensor_id; | |
422 | ext->sensor_con.peri_type = SE_I2C; | |
423 | ext->sensor_con.peri_setting.i2c.channel = pdata->sensor_i2c_ch; | |
424 | ext->sensor_con.peri_setting.i2c.slave_address = pdata->sensor_i2c_addr; | |
425 | ext->sensor_con.peri_setting.i2c.speed = 400000; | |
426 | ||
427 | if (pdata->af_product_name != ACTUATOR_NAME_NOTHING) { | |
428 | ext->actuator_con.product_name = pdata->af_product_name; | |
429 | ext->actuator_con.peri_type = SE_I2C; | |
430 | ext->actuator_con.peri_setting.i2c.channel = pdata->af_i2c_ch; | |
431 | ext->actuator_con.peri_setting.i2c.slave_address = pdata->af_i2c_addr; | |
432 | ext->actuator_con.peri_setting.i2c.speed = 400000; | |
433 | } | |
434 | ||
435 | if (pdata->flash_product_name != FLADRV_NAME_NOTHING) { | |
436 | ext->flash_con.product_name = pdata->flash_product_name; | |
437 | ext->flash_con.peri_type = SE_GPIO; | |
438 | ext->flash_con.peri_setting.gpio.first_gpio_port_no = pdata->flash_first_gpio; | |
439 | ext->flash_con.peri_setting.gpio.second_gpio_port_no = pdata->flash_second_gpio; | |
440 | } | |
441 | ||
442 | ext->from_con.product_name = FROMDRV_NAME_NOTHING; | |
443 | ||
444 | if (pdata->preprocessor_product_name != PREPROCESSOR_NAME_NOTHING) { | |
445 | ext->preprocessor_con.product_name = pdata->preprocessor_product_name; | |
446 | ext->preprocessor_con.peri_info0.valid = true; | |
447 | ext->preprocessor_con.peri_info0.peri_type = SE_SPI; | |
448 | ext->preprocessor_con.peri_info0.peri_setting.spi.channel = pdata->preprocessor_spi_channel; | |
449 | ext->preprocessor_con.peri_info1.valid = true; | |
450 | ext->preprocessor_con.peri_info1.peri_type = SE_I2C; | |
451 | ext->preprocessor_con.peri_info1.peri_setting.i2c.channel = pdata->preprocessor_i2c_ch; | |
452 | ext->preprocessor_con.peri_info1.peri_setting.i2c.slave_address = pdata->preprocessor_i2c_addr; | |
453 | ext->preprocessor_con.peri_info1.peri_setting.i2c.speed = 400000; | |
454 | ext->preprocessor_con.peri_info2.valid = true; | |
455 | ext->preprocessor_con.peri_info2.peri_type = SE_DMA; | |
456 | ext->preprocessor_con.peri_info2.peri_setting.dma.channel = FLITE_ID_D; | |
457 | } else { | |
458 | ext->preprocessor_con.product_name = pdata->preprocessor_product_name; | |
459 | } | |
460 | ||
461 | if (pdata->ois_product_name != OIS_NAME_NOTHING) { | |
462 | ext->ois_con.product_name = pdata->ois_product_name; | |
463 | ext->ois_con.peri_type = SE_I2C; | |
464 | ext->ois_con.peri_setting.i2c.channel = pdata->ois_i2c_ch; | |
465 | ext->ois_con.peri_setting.i2c.slave_address = pdata->ois_i2c_addr; | |
466 | ext->ois_con.peri_setting.i2c.speed = 400000; | |
467 | } else { | |
468 | ext->ois_con.product_name = pdata->ois_product_name; | |
469 | ext->ois_con.peri_type = SE_NULL; | |
470 | } | |
471 | ||
dae39a87 | 472 | if (pdata->eeprom_product_name != EEPROM_NAME_NOTHING) { |
473 | ext->eeprom_con.product_name = pdata->eeprom_product_name; | |
474 | ext->eeprom_con.peri_type = SE_I2C; | |
475 | ext->eeprom_con.peri_setting.i2c.channel = pdata->eeprom_i2c_ch; | |
476 | ext->eeprom_con.peri_setting.i2c.slave_address = pdata->eeprom_i2c_addr; | |
477 | ext->eeprom_con.peri_setting.i2c.speed = 400000; | |
478 | } else { | |
479 | ext->eeprom_con.product_name = pdata->eeprom_product_name; | |
480 | ext->eeprom_con.peri_type = SE_NULL; | |
481 | } | |
482 | ||
5fd039ac SS |
483 | v4l2_subdev_init(subdev_module, &subdev_ops); |
484 | ||
485 | v4l2_set_subdevdata(subdev_module, module); | |
486 | v4l2_set_subdev_hostdata(subdev_module, device); | |
487 | snprintf(subdev_module->name, V4L2_SUBDEV_NAME_SIZE, "sensor-subdev.%d", module->sensor_id); | |
488 | ||
489 | s = pinctrl_lookup_state(pdata->pinctrl, "release"); | |
490 | ||
491 | if (pinctrl_select_state(pdata->pinctrl, s) < 0) { | |
492 | probe_err("pinctrl_select_state is fail\n"); | |
493 | goto p_err; | |
494 | } | |
495 | ||
496 | probe_info("%s done\n", __func__); | |
497 | ||
498 | p_err: | |
499 | return ret; | |
500 | } | |
501 | ||
502 | static const struct of_device_id exynos_fimc_is_sensor_module_5e9_match[] = { | |
503 | { | |
504 | .compatible = "samsung,sensor-module-5e9", | |
505 | }, | |
506 | {}, | |
507 | }; | |
508 | MODULE_DEVICE_TABLE(of, exynos_fimc_is_sensor_module_5e9_match); | |
509 | ||
510 | static struct platform_driver sensor_module_5e9_driver = { | |
511 | .driver = { | |
512 | .name = "FIMC-IS-SENSOR-MODULE-5E9", | |
513 | .owner = THIS_MODULE, | |
514 | .of_match_table = exynos_fimc_is_sensor_module_5e9_match, | |
515 | } | |
516 | }; | |
517 | ||
518 | static int __init fimc_is_sensor_module_5e9_init(void) | |
519 | { | |
520 | int ret; | |
521 | ||
522 | ret = platform_driver_probe(&sensor_module_5e9_driver, | |
523 | sensor_module_5e9_probe); | |
524 | if (ret) | |
525 | err("failed to probe %s driver: %d\n", | |
526 | sensor_module_5e9_driver.driver.name, ret); | |
527 | ||
528 | return ret; | |
529 | } | |
530 | late_initcall(fimc_is_sensor_module_5e9_init); |