Commit | Line | Data |
---|---|---|
bc125106 HK |
1 | /* |
2 | * Driver for M-5MOLS 8M Pixel camera sensor with ISP | |
3 | * | |
4 | * Copyright (C) 2011 Samsung Electronics Co., Ltd. | |
c3070113 | 5 | * Author: HeungJun Kim <riverful.kim@samsung.com> |
bc125106 HK |
6 | * |
7 | * Copyright (C) 2009 Samsung Electronics Co., Ltd. | |
c3070113 | 8 | * Author: Dongsoo Nathaniel Kim <dongsoo45.kim@samsung.com> |
bc125106 HK |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | */ | |
15 | ||
16 | #include <linux/i2c.h> | |
17 | #include <linux/slab.h> | |
18 | #include <linux/irq.h> | |
19 | #include <linux/interrupt.h> | |
20 | #include <linux/delay.h> | |
bc125106 HK |
21 | #include <linux/gpio.h> |
22 | #include <linux/regulator/consumer.h> | |
23 | #include <linux/videodev2.h> | |
7a707b89 | 24 | #include <linux/module.h> |
bc125106 HK |
25 | #include <media/v4l2-ctrls.h> |
26 | #include <media/v4l2-device.h> | |
27 | #include <media/v4l2-subdev.h> | |
28 | #include <media/m5mols.h> | |
29 | ||
30 | #include "m5mols.h" | |
31 | #include "m5mols_reg.h" | |
32 | ||
33 | int m5mols_debug; | |
34 | module_param(m5mols_debug, int, 0644); | |
35 | ||
36 | #define MODULE_NAME "M5MOLS" | |
37 | #define M5MOLS_I2C_CHECK_RETRY 500 | |
38 | ||
39 | /* The regulator consumer names for external voltage regulators */ | |
40 | static struct regulator_bulk_data supplies[] = { | |
41 | { | |
42 | .supply = "core", /* ARM core power, 1.2V */ | |
43 | }, { | |
44 | .supply = "dig_18", /* digital power 1, 1.8V */ | |
45 | }, { | |
46 | .supply = "d_sensor", /* sensor power 1, 1.8V */ | |
47 | }, { | |
48 | .supply = "dig_28", /* digital power 2, 2.8V */ | |
49 | }, { | |
50 | .supply = "a_sensor", /* analog power */ | |
51 | }, { | |
52 | .supply = "dig_12", /* digital power 3, 1.2V */ | |
53 | }, | |
54 | }; | |
55 | ||
56 | static struct v4l2_mbus_framefmt m5mols_default_ffmt[M5MOLS_RESTYPE_MAX] = { | |
57 | [M5MOLS_RESTYPE_MONITOR] = { | |
58 | .width = 1920, | |
59 | .height = 1080, | |
60 | .code = V4L2_MBUS_FMT_VYUY8_2X8, | |
61 | .field = V4L2_FIELD_NONE, | |
62 | .colorspace = V4L2_COLORSPACE_JPEG, | |
63 | }, | |
64 | [M5MOLS_RESTYPE_CAPTURE] = { | |
65 | .width = 1920, | |
66 | .height = 1080, | |
67 | .code = V4L2_MBUS_FMT_JPEG_1X8, | |
68 | .field = V4L2_FIELD_NONE, | |
69 | .colorspace = V4L2_COLORSPACE_JPEG, | |
70 | }, | |
71 | }; | |
72 | #define SIZE_DEFAULT_FFMT ARRAY_SIZE(m5mols_default_ffmt) | |
73 | ||
74 | static const struct m5mols_resolution m5mols_reg_res[] = { | |
75 | { 0x01, M5MOLS_RESTYPE_MONITOR, 128, 96 }, /* SUB-QCIF */ | |
76 | { 0x03, M5MOLS_RESTYPE_MONITOR, 160, 120 }, /* QQVGA */ | |
77 | { 0x05, M5MOLS_RESTYPE_MONITOR, 176, 144 }, /* QCIF */ | |
78 | { 0x06, M5MOLS_RESTYPE_MONITOR, 176, 176 }, | |
79 | { 0x08, M5MOLS_RESTYPE_MONITOR, 240, 320 }, /* QVGA */ | |
80 | { 0x09, M5MOLS_RESTYPE_MONITOR, 320, 240 }, /* QVGA */ | |
81 | { 0x0c, M5MOLS_RESTYPE_MONITOR, 240, 400 }, /* WQVGA */ | |
82 | { 0x0d, M5MOLS_RESTYPE_MONITOR, 400, 240 }, /* WQVGA */ | |
83 | { 0x0e, M5MOLS_RESTYPE_MONITOR, 352, 288 }, /* CIF */ | |
84 | { 0x13, M5MOLS_RESTYPE_MONITOR, 480, 360 }, | |
85 | { 0x15, M5MOLS_RESTYPE_MONITOR, 640, 360 }, /* qHD */ | |
86 | { 0x17, M5MOLS_RESTYPE_MONITOR, 640, 480 }, /* VGA */ | |
87 | { 0x18, M5MOLS_RESTYPE_MONITOR, 720, 480 }, | |
88 | { 0x1a, M5MOLS_RESTYPE_MONITOR, 800, 480 }, /* WVGA */ | |
89 | { 0x1f, M5MOLS_RESTYPE_MONITOR, 800, 600 }, /* SVGA */ | |
90 | { 0x21, M5MOLS_RESTYPE_MONITOR, 1280, 720 }, /* HD */ | |
91 | { 0x25, M5MOLS_RESTYPE_MONITOR, 1920, 1080 }, /* 1080p */ | |
92 | { 0x29, M5MOLS_RESTYPE_MONITOR, 3264, 2448 }, /* 2.63fps 8M */ | |
93 | { 0x39, M5MOLS_RESTYPE_MONITOR, 800, 602 }, /* AHS_MON debug */ | |
94 | ||
95 | { 0x02, M5MOLS_RESTYPE_CAPTURE, 320, 240 }, /* QVGA */ | |
96 | { 0x04, M5MOLS_RESTYPE_CAPTURE, 400, 240 }, /* WQVGA */ | |
97 | { 0x07, M5MOLS_RESTYPE_CAPTURE, 480, 360 }, | |
98 | { 0x08, M5MOLS_RESTYPE_CAPTURE, 640, 360 }, /* qHD */ | |
99 | { 0x09, M5MOLS_RESTYPE_CAPTURE, 640, 480 }, /* VGA */ | |
100 | { 0x0a, M5MOLS_RESTYPE_CAPTURE, 800, 480 }, /* WVGA */ | |
101 | { 0x10, M5MOLS_RESTYPE_CAPTURE, 1280, 720 }, /* HD */ | |
102 | { 0x14, M5MOLS_RESTYPE_CAPTURE, 1280, 960 }, /* 1M */ | |
103 | { 0x17, M5MOLS_RESTYPE_CAPTURE, 1600, 1200 }, /* 2M */ | |
104 | { 0x19, M5MOLS_RESTYPE_CAPTURE, 1920, 1080 }, /* Full-HD */ | |
105 | { 0x1a, M5MOLS_RESTYPE_CAPTURE, 2048, 1152 }, /* 3Mega */ | |
106 | { 0x1b, M5MOLS_RESTYPE_CAPTURE, 2048, 1536 }, | |
107 | { 0x1c, M5MOLS_RESTYPE_CAPTURE, 2560, 1440 }, /* 4Mega */ | |
108 | { 0x1d, M5MOLS_RESTYPE_CAPTURE, 2560, 1536 }, | |
109 | { 0x1f, M5MOLS_RESTYPE_CAPTURE, 2560, 1920 }, /* 5Mega */ | |
110 | { 0x21, M5MOLS_RESTYPE_CAPTURE, 3264, 1836 }, /* 6Mega */ | |
111 | { 0x22, M5MOLS_RESTYPE_CAPTURE, 3264, 1960 }, | |
112 | { 0x25, M5MOLS_RESTYPE_CAPTURE, 3264, 2448 }, /* 8Mega */ | |
113 | }; | |
114 | ||
115 | /** | |
116 | * m5mols_swap_byte - an byte array to integer conversion function | |
117 | * @size: size in bytes of I2C packet defined in the M-5MOLS datasheet | |
118 | * | |
119 | * Convert I2C data byte array with performing any required byte | |
120 | * reordering to assure proper values for each data type, regardless | |
121 | * of the architecture endianness. | |
122 | */ | |
123 | static u32 m5mols_swap_byte(u8 *data, u8 length) | |
124 | { | |
125 | if (length == 1) | |
126 | return *data; | |
127 | else if (length == 2) | |
128 | return be16_to_cpu(*((u16 *)data)); | |
129 | else | |
130 | return be32_to_cpu(*((u32 *)data)); | |
131 | } | |
132 | ||
133 | /** | |
134 | * m5mols_read - I2C read function | |
135 | * @reg: combination of size, category and command for the I2C packet | |
57644f56 | 136 | * @size: desired size of I2C packet |
bc125106 | 137 | * @val: read value |
0f2ee1dd HK |
138 | * |
139 | * Returns 0 on success, or else negative errno. | |
bc125106 | 140 | */ |
57644f56 | 141 | static int m5mols_read(struct v4l2_subdev *sd, u32 size, u32 reg, u32 *val) |
bc125106 HK |
142 | { |
143 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
0f2ee1dd | 144 | struct m5mols_info *info = to_m5mols(sd); |
bc125106 | 145 | u8 rbuf[M5MOLS_I2C_MAX_SIZE + 1]; |
bc125106 HK |
146 | u8 category = I2C_CATEGORY(reg); |
147 | u8 cmd = I2C_COMMAND(reg); | |
148 | struct i2c_msg msg[2]; | |
149 | u8 wbuf[5]; | |
150 | int ret; | |
151 | ||
152 | if (!client->adapter) | |
153 | return -ENODEV; | |
154 | ||
bc125106 HK |
155 | msg[0].addr = client->addr; |
156 | msg[0].flags = 0; | |
157 | msg[0].len = 5; | |
158 | msg[0].buf = wbuf; | |
159 | wbuf[0] = 5; | |
160 | wbuf[1] = M5MOLS_BYTE_READ; | |
161 | wbuf[2] = category; | |
162 | wbuf[3] = cmd; | |
163 | wbuf[4] = size; | |
164 | ||
165 | msg[1].addr = client->addr; | |
166 | msg[1].flags = I2C_M_RD; | |
167 | msg[1].len = size + 1; | |
168 | msg[1].buf = rbuf; | |
169 | ||
170 | /* minimum stabilization time */ | |
171 | usleep_range(200, 200); | |
172 | ||
173 | ret = i2c_transfer(client->adapter, msg, 2); | |
0f2ee1dd HK |
174 | |
175 | if (ret == 2) { | |
176 | *val = m5mols_swap_byte(&rbuf[1], size); | |
177 | return 0; | |
bc125106 HK |
178 | } |
179 | ||
0f2ee1dd HK |
180 | if (info->isp_ready) |
181 | v4l2_err(sd, "read failed: size:%d cat:%02x cmd:%02x. %d\n", | |
182 | size, category, cmd, ret); | |
bc125106 | 183 | |
0f2ee1dd | 184 | return ret < 0 ? ret : -EIO; |
bc125106 HK |
185 | } |
186 | ||
57644f56 HK |
187 | int m5mols_read_u8(struct v4l2_subdev *sd, u32 reg, u8 *val) |
188 | { | |
189 | u32 val_32; | |
190 | int ret; | |
191 | ||
192 | if (I2C_SIZE(reg) != 1) { | |
193 | v4l2_err(sd, "Wrong data size\n"); | |
194 | return -EINVAL; | |
195 | } | |
196 | ||
197 | ret = m5mols_read(sd, I2C_SIZE(reg), reg, &val_32); | |
198 | if (ret) | |
199 | return ret; | |
200 | ||
201 | *val = (u8)val_32; | |
202 | return ret; | |
203 | } | |
204 | ||
205 | int m5mols_read_u16(struct v4l2_subdev *sd, u32 reg, u16 *val) | |
206 | { | |
207 | u32 val_32; | |
208 | int ret; | |
209 | ||
210 | if (I2C_SIZE(reg) != 2) { | |
211 | v4l2_err(sd, "Wrong data size\n"); | |
212 | return -EINVAL; | |
213 | } | |
214 | ||
215 | ret = m5mols_read(sd, I2C_SIZE(reg), reg, &val_32); | |
216 | if (ret) | |
217 | return ret; | |
218 | ||
219 | *val = (u16)val_32; | |
220 | return ret; | |
221 | } | |
222 | ||
223 | int m5mols_read_u32(struct v4l2_subdev *sd, u32 reg, u32 *val) | |
224 | { | |
225 | if (I2C_SIZE(reg) != 4) { | |
226 | v4l2_err(sd, "Wrong data size\n"); | |
227 | return -EINVAL; | |
228 | } | |
229 | ||
230 | return m5mols_read(sd, I2C_SIZE(reg), reg, val); | |
231 | } | |
232 | ||
bc125106 HK |
233 | /** |
234 | * m5mols_write - I2C command write function | |
235 | * @reg: combination of size, category and command for the I2C packet | |
236 | * @val: value to write | |
0f2ee1dd HK |
237 | * |
238 | * Returns 0 on success, or else negative errno. | |
bc125106 HK |
239 | */ |
240 | int m5mols_write(struct v4l2_subdev *sd, u32 reg, u32 val) | |
241 | { | |
242 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
0f2ee1dd | 243 | struct m5mols_info *info = to_m5mols(sd); |
bc125106 HK |
244 | u8 wbuf[M5MOLS_I2C_MAX_SIZE + 4]; |
245 | u8 category = I2C_CATEGORY(reg); | |
246 | u8 cmd = I2C_COMMAND(reg); | |
247 | u8 size = I2C_SIZE(reg); | |
248 | u32 *buf = (u32 *)&wbuf[4]; | |
249 | struct i2c_msg msg[1]; | |
250 | int ret; | |
251 | ||
252 | if (!client->adapter) | |
253 | return -ENODEV; | |
254 | ||
255 | if (size != 1 && size != 2 && size != 4) { | |
256 | v4l2_err(sd, "Wrong data size\n"); | |
257 | return -EINVAL; | |
258 | } | |
259 | ||
260 | msg->addr = client->addr; | |
261 | msg->flags = 0; | |
262 | msg->len = (u16)size + 4; | |
263 | msg->buf = wbuf; | |
264 | wbuf[0] = size + 4; | |
265 | wbuf[1] = M5MOLS_BYTE_WRITE; | |
266 | wbuf[2] = category; | |
267 | wbuf[3] = cmd; | |
268 | ||
269 | *buf = m5mols_swap_byte((u8 *)&val, size); | |
270 | ||
271 | usleep_range(200, 200); | |
272 | ||
273 | ret = i2c_transfer(client->adapter, msg, 1); | |
0f2ee1dd HK |
274 | if (ret == 1) |
275 | return 0; | |
bc125106 | 276 | |
0f2ee1dd HK |
277 | if (info->isp_ready) |
278 | v4l2_err(sd, "write failed: cat:%02x cmd:%02x ret:%d\n", | |
279 | category, cmd, ret); | |
280 | ||
281 | return ret < 0 ? ret : -EIO; | |
bc125106 HK |
282 | } |
283 | ||
575d6252 HK |
284 | /** |
285 | * m5mols_busy_wait - Busy waiting with I2C register polling | |
286 | * @reg: the I2C_REG() address of an 8-bit status register to check | |
287 | * @value: expected status register value | |
288 | * @mask: bit mask for the read status register value | |
289 | * @timeout: timeout in miliseconds, or -1 for default timeout | |
290 | * | |
291 | * The @reg register value is ORed with @mask before comparing with @value. | |
292 | * | |
293 | * Return: 0 if the requested condition became true within less than | |
294 | * @timeout ms, or else negative errno. | |
295 | */ | |
296 | int m5mols_busy_wait(struct v4l2_subdev *sd, u32 reg, u32 value, u32 mask, | |
297 | int timeout) | |
bc125106 | 298 | { |
575d6252 HK |
299 | int ms = timeout < 0 ? M5MOLS_BUSY_WAIT_DEF_TIMEOUT : timeout; |
300 | unsigned long end = jiffies + msecs_to_jiffies(ms); | |
301 | u8 status; | |
bc125106 | 302 | |
575d6252 HK |
303 | do { |
304 | int ret = m5mols_read_u8(sd, reg, &status); | |
305 | ||
306 | if (ret < 0 && !(mask & M5MOLS_I2C_RDY_WAIT_FL)) | |
bc125106 | 307 | return ret; |
575d6252 | 308 | if (!ret && (status & mask & 0xff) == (value & 0xff)) |
bc125106 | 309 | return 0; |
575d6252 HK |
310 | usleep_range(100, 250); |
311 | } while (ms > 0 && time_is_after_jiffies(end)); | |
312 | ||
bc125106 HK |
313 | return -EBUSY; |
314 | } | |
315 | ||
316 | /** | |
317 | * m5mols_enable_interrupt - Clear interrupt pending bits and unmask interrupts | |
318 | * | |
319 | * Before writing desired interrupt value the INT_FACTOR register should | |
320 | * be read to clear pending interrupts. | |
321 | */ | |
57644f56 | 322 | int m5mols_enable_interrupt(struct v4l2_subdev *sd, u8 reg) |
bc125106 HK |
323 | { |
324 | struct m5mols_info *info = to_m5mols(sd); | |
57644f56 HK |
325 | u8 mask = is_available_af(info) ? REG_INT_AF : 0; |
326 | u8 dummy; | |
bc125106 HK |
327 | int ret; |
328 | ||
57644f56 | 329 | ret = m5mols_read_u8(sd, SYSTEM_INT_FACTOR, &dummy); |
bc125106 HK |
330 | if (!ret) |
331 | ret = m5mols_write(sd, SYSTEM_INT_ENABLE, reg & ~mask); | |
332 | return ret; | |
333 | } | |
334 | ||
ce808a47 HK |
335 | int m5mols_wait_interrupt(struct v4l2_subdev *sd, u8 irq_mask, u32 timeout) |
336 | { | |
337 | struct m5mols_info *info = to_m5mols(sd); | |
338 | ||
339 | int ret = wait_event_interruptible_timeout(info->irq_waitq, | |
340 | atomic_add_unless(&info->irq_done, -1, 0), | |
341 | msecs_to_jiffies(timeout)); | |
342 | if (ret <= 0) | |
343 | return ret ? ret : -ETIMEDOUT; | |
344 | ||
345 | return m5mols_busy_wait(sd, SYSTEM_INT_FACTOR, irq_mask, | |
346 | M5MOLS_I2C_RDY_WAIT_FL | irq_mask, -1); | |
347 | } | |
348 | ||
bc125106 HK |
349 | /** |
350 | * m5mols_reg_mode - Write the mode and check busy status | |
351 | * | |
352 | * It always accompanies a little delay changing the M-5MOLS mode, so it is | |
353 | * needed checking current busy status to guarantee right mode. | |
354 | */ | |
57644f56 | 355 | static int m5mols_reg_mode(struct v4l2_subdev *sd, u8 mode) |
bc125106 HK |
356 | { |
357 | int ret = m5mols_write(sd, SYSTEM_SYSMODE, mode); | |
575d6252 HK |
358 | if (ret < 0) |
359 | return ret; | |
360 | return m5mols_busy_wait(sd, SYSTEM_SYSMODE, mode, 0xff, | |
361 | M5MOLS_MODE_CHANGE_TIMEOUT); | |
bc125106 HK |
362 | } |
363 | ||
364 | /** | |
365 | * m5mols_mode - manage the M-5MOLS's mode | |
366 | * @mode: the required operation mode | |
367 | * | |
368 | * The commands of M-5MOLS are grouped into specific modes. Each functionality | |
369 | * can be guaranteed only when the sensor is operating in mode which which | |
370 | * a command belongs to. | |
371 | */ | |
57644f56 | 372 | int m5mols_mode(struct m5mols_info *info, u8 mode) |
bc125106 HK |
373 | { |
374 | struct v4l2_subdev *sd = &info->sd; | |
375 | int ret = -EINVAL; | |
57644f56 | 376 | u8 reg; |
bc125106 | 377 | |
a32390d8 | 378 | if (mode < REG_PARAMETER || mode > REG_CAPTURE) |
bc125106 HK |
379 | return ret; |
380 | ||
57644f56 | 381 | ret = m5mols_read_u8(sd, SYSTEM_SYSMODE, ®); |
630caa23 | 382 | if (ret || reg == mode) |
bc125106 HK |
383 | return ret; |
384 | ||
385 | switch (reg) { | |
386 | case REG_PARAMETER: | |
387 | ret = m5mols_reg_mode(sd, REG_MONITOR); | |
630caa23 | 388 | if (mode == REG_MONITOR) |
bc125106 HK |
389 | break; |
390 | if (!ret) | |
391 | ret = m5mols_reg_mode(sd, REG_CAPTURE); | |
392 | break; | |
393 | ||
394 | case REG_MONITOR: | |
395 | if (mode == REG_PARAMETER) { | |
396 | ret = m5mols_reg_mode(sd, REG_PARAMETER); | |
397 | break; | |
398 | } | |
399 | ||
400 | ret = m5mols_reg_mode(sd, REG_CAPTURE); | |
401 | break; | |
402 | ||
403 | case REG_CAPTURE: | |
404 | ret = m5mols_reg_mode(sd, REG_MONITOR); | |
630caa23 | 405 | if (mode == REG_MONITOR) |
bc125106 HK |
406 | break; |
407 | if (!ret) | |
408 | ret = m5mols_reg_mode(sd, REG_PARAMETER); | |
409 | break; | |
410 | ||
411 | default: | |
412 | v4l2_warn(sd, "Wrong mode: %d\n", mode); | |
413 | } | |
414 | ||
415 | if (!ret) | |
416 | info->mode = mode; | |
417 | ||
418 | return ret; | |
419 | } | |
420 | ||
421 | /** | |
422 | * m5mols_get_version - retrieve full revisions information of M-5MOLS | |
423 | * | |
424 | * The version information includes revisions of hardware and firmware, | |
425 | * AutoFocus alghorithm version and the version string. | |
426 | */ | |
427 | static int m5mols_get_version(struct v4l2_subdev *sd) | |
428 | { | |
429 | struct m5mols_info *info = to_m5mols(sd); | |
a6354d2e HK |
430 | struct m5mols_version *ver = &info->ver; |
431 | u8 *str = ver->str; | |
432 | int i; | |
bc125106 HK |
433 | int ret; |
434 | ||
a6354d2e HK |
435 | ret = m5mols_read_u8(sd, SYSTEM_VER_CUSTOMER, &ver->customer); |
436 | if (!ret) | |
437 | ret = m5mols_read_u8(sd, SYSTEM_VER_PROJECT, &ver->project); | |
438 | if (!ret) | |
439 | ret = m5mols_read_u16(sd, SYSTEM_VER_FIRMWARE, &ver->fw); | |
440 | if (!ret) | |
441 | ret = m5mols_read_u16(sd, SYSTEM_VER_HARDWARE, &ver->hw); | |
442 | if (!ret) | |
443 | ret = m5mols_read_u16(sd, SYSTEM_VER_PARAMETER, &ver->param); | |
444 | if (!ret) | |
445 | ret = m5mols_read_u16(sd, SYSTEM_VER_AWB, &ver->awb); | |
446 | if (!ret) | |
447 | ret = m5mols_read_u8(sd, AF_VERSION, &ver->af); | |
448 | if (ret) | |
449 | return ret; | |
bc125106 | 450 | |
a6354d2e HK |
451 | for (i = 0; i < VERSION_STRING_SIZE; i++) { |
452 | ret = m5mols_read_u8(sd, SYSTEM_VER_STRING, &str[i]); | |
bc125106 HK |
453 | if (ret) |
454 | return ret; | |
a6354d2e | 455 | } |
bc125106 | 456 | |
a6354d2e HK |
457 | ver->fw = be16_to_cpu(ver->fw); |
458 | ver->hw = be16_to_cpu(ver->hw); | |
459 | ver->param = be16_to_cpu(ver->param); | |
460 | ver->awb = be16_to_cpu(ver->awb); | |
bc125106 HK |
461 | |
462 | v4l2_info(sd, "Manufacturer\t[%s]\n", | |
463 | is_manufacturer(info, REG_SAMSUNG_ELECTRO) ? | |
464 | "Samsung Electro-Machanics" : | |
465 | is_manufacturer(info, REG_SAMSUNG_OPTICS) ? | |
466 | "Samsung Fiber-Optics" : | |
467 | is_manufacturer(info, REG_SAMSUNG_TECHWIN) ? | |
468 | "Samsung Techwin" : "None"); | |
469 | v4l2_info(sd, "Customer/Project\t[0x%02x/0x%02x]\n", | |
470 | info->ver.customer, info->ver.project); | |
471 | ||
472 | if (!is_available_af(info)) | |
473 | v4l2_info(sd, "No support Auto Focus on this firmware\n"); | |
474 | ||
475 | return ret; | |
476 | } | |
477 | ||
478 | /** | |
479 | * __find_restype - Lookup M-5MOLS resolution type according to pixel code | |
480 | * @code: pixel code | |
481 | */ | |
482 | static enum m5mols_restype __find_restype(enum v4l2_mbus_pixelcode code) | |
483 | { | |
484 | enum m5mols_restype type = M5MOLS_RESTYPE_MONITOR; | |
485 | ||
486 | do { | |
487 | if (code == m5mols_default_ffmt[type].code) | |
488 | return type; | |
489 | } while (type++ != SIZE_DEFAULT_FFMT); | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
494 | /** | |
495 | * __find_resolution - Lookup preset and type of M-5MOLS's resolution | |
496 | * @mf: pixel format to find/negotiate the resolution preset for | |
497 | * @type: M-5MOLS resolution type | |
498 | * @resolution: M-5MOLS resolution preset register value | |
499 | * | |
500 | * Find nearest resolution matching resolution preset and adjust mf | |
501 | * to supported values. | |
502 | */ | |
503 | static int __find_resolution(struct v4l2_subdev *sd, | |
504 | struct v4l2_mbus_framefmt *mf, | |
505 | enum m5mols_restype *type, | |
506 | u32 *resolution) | |
507 | { | |
508 | const struct m5mols_resolution *fsize = &m5mols_reg_res[0]; | |
509 | const struct m5mols_resolution *match = NULL; | |
510 | enum m5mols_restype stype = __find_restype(mf->code); | |
511 | int i = ARRAY_SIZE(m5mols_reg_res); | |
512 | unsigned int min_err = ~0; | |
513 | ||
514 | while (i--) { | |
515 | int err; | |
516 | if (stype == fsize->type) { | |
517 | err = abs(fsize->width - mf->width) | |
518 | + abs(fsize->height - mf->height); | |
519 | ||
520 | if (err < min_err) { | |
521 | min_err = err; | |
522 | match = fsize; | |
523 | } | |
524 | } | |
525 | fsize++; | |
526 | } | |
527 | if (match) { | |
528 | mf->width = match->width; | |
529 | mf->height = match->height; | |
530 | *resolution = match->reg; | |
531 | *type = stype; | |
532 | return 0; | |
533 | } | |
534 | ||
535 | return -EINVAL; | |
536 | } | |
537 | ||
538 | static struct v4l2_mbus_framefmt *__find_format(struct m5mols_info *info, | |
539 | struct v4l2_subdev_fh *fh, | |
540 | enum v4l2_subdev_format_whence which, | |
541 | enum m5mols_restype type) | |
542 | { | |
543 | if (which == V4L2_SUBDEV_FORMAT_TRY) | |
544 | return fh ? v4l2_subdev_get_try_format(fh, 0) : NULL; | |
545 | ||
546 | return &info->ffmt[type]; | |
547 | } | |
548 | ||
549 | static int m5mols_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, | |
550 | struct v4l2_subdev_format *fmt) | |
551 | { | |
552 | struct m5mols_info *info = to_m5mols(sd); | |
553 | struct v4l2_mbus_framefmt *format; | |
554 | ||
bc125106 HK |
555 | format = __find_format(info, fh, fmt->which, info->res_type); |
556 | if (!format) | |
557 | return -EINVAL; | |
558 | ||
559 | fmt->format = *format; | |
560 | return 0; | |
561 | } | |
562 | ||
563 | static int m5mols_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, | |
564 | struct v4l2_subdev_format *fmt) | |
565 | { | |
566 | struct m5mols_info *info = to_m5mols(sd); | |
567 | struct v4l2_mbus_framefmt *format = &fmt->format; | |
568 | struct v4l2_mbus_framefmt *sfmt; | |
569 | enum m5mols_restype type; | |
570 | u32 resolution = 0; | |
571 | int ret; | |
572 | ||
bc125106 HK |
573 | ret = __find_resolution(sd, format, &type, &resolution); |
574 | if (ret < 0) | |
575 | return ret; | |
576 | ||
577 | sfmt = __find_format(info, fh, fmt->which, type); | |
578 | if (!sfmt) | |
579 | return 0; | |
580 | ||
fbe78ddd SN |
581 | |
582 | format->code = m5mols_default_ffmt[type].code; | |
583 | format->colorspace = V4L2_COLORSPACE_JPEG; | |
584 | format->field = V4L2_FIELD_NONE; | |
bc125106 HK |
585 | |
586 | if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { | |
fbe78ddd | 587 | *sfmt = *format; |
bc125106 | 588 | info->resolution = resolution; |
bc125106 HK |
589 | info->res_type = type; |
590 | } | |
591 | ||
592 | return 0; | |
593 | } | |
594 | ||
595 | static int m5mols_enum_mbus_code(struct v4l2_subdev *sd, | |
596 | struct v4l2_subdev_fh *fh, | |
597 | struct v4l2_subdev_mbus_code_enum *code) | |
598 | { | |
599 | if (!code || code->index >= SIZE_DEFAULT_FFMT) | |
600 | return -EINVAL; | |
601 | ||
602 | code->code = m5mols_default_ffmt[code->index].code; | |
603 | ||
604 | return 0; | |
605 | } | |
606 | ||
607 | static struct v4l2_subdev_pad_ops m5mols_pad_ops = { | |
608 | .enum_mbus_code = m5mols_enum_mbus_code, | |
609 | .get_fmt = m5mols_get_fmt, | |
610 | .set_fmt = m5mols_set_fmt, | |
611 | }; | |
612 | ||
613 | /** | |
5d4294b8 | 614 | * m5mols_restore_controls - Apply current control values to the registers |
bc125106 | 615 | * |
5d4294b8 SN |
616 | * m5mols_do_scenemode() handles all parameters for which there is yet no |
617 | * individual control. It should be replaced at some point by setting each | |
618 | * control individually, in required register set up order. | |
bc125106 | 619 | */ |
5d4294b8 | 620 | int m5mols_restore_controls(struct m5mols_info *info) |
bc125106 | 621 | { |
5d4294b8 | 622 | int ret; |
bc125106 | 623 | |
5d4294b8 SN |
624 | if (info->ctrl_sync) |
625 | return 0; | |
bc125106 | 626 | |
5d4294b8 SN |
627 | ret = m5mols_do_scenemode(info, REG_SCENE_NORMAL); |
628 | if (ret) | |
629 | return ret; | |
630 | ||
631 | ret = v4l2_ctrl_handler_setup(&info->handle); | |
632 | info->ctrl_sync = !ret; | |
bc125106 HK |
633 | |
634 | return ret; | |
635 | } | |
636 | ||
637 | /** | |
638 | * m5mols_start_monitor - Start the monitor mode | |
639 | * | |
640 | * Before applying the controls setup the resolution and frame rate | |
641 | * in PARAMETER mode, and then switch over to MONITOR mode. | |
642 | */ | |
643 | static int m5mols_start_monitor(struct m5mols_info *info) | |
644 | { | |
645 | struct v4l2_subdev *sd = &info->sd; | |
646 | int ret; | |
647 | ||
648 | ret = m5mols_mode(info, REG_PARAMETER); | |
649 | if (!ret) | |
650 | ret = m5mols_write(sd, PARM_MON_SIZE, info->resolution); | |
651 | if (!ret) | |
652 | ret = m5mols_write(sd, PARM_MON_FPS, REG_FPS_30); | |
653 | if (!ret) | |
654 | ret = m5mols_mode(info, REG_MONITOR); | |
655 | if (!ret) | |
5d4294b8 | 656 | ret = m5mols_restore_controls(info); |
bc125106 HK |
657 | |
658 | return ret; | |
659 | } | |
660 | ||
661 | static int m5mols_s_stream(struct v4l2_subdev *sd, int enable) | |
662 | { | |
663 | struct m5mols_info *info = to_m5mols(sd); | |
fbe78ddd | 664 | u32 code = info->ffmt[info->res_type].code; |
bc125106 HK |
665 | |
666 | if (enable) { | |
667 | int ret = -EINVAL; | |
668 | ||
fbe78ddd | 669 | if (is_code(code, M5MOLS_RESTYPE_MONITOR)) |
bc125106 | 670 | ret = m5mols_start_monitor(info); |
fbe78ddd | 671 | if (is_code(code, M5MOLS_RESTYPE_CAPTURE)) |
bc125106 HK |
672 | ret = m5mols_start_capture(info); |
673 | ||
674 | return ret; | |
675 | } | |
676 | ||
677 | return m5mols_mode(info, REG_PARAMETER); | |
678 | } | |
679 | ||
680 | static const struct v4l2_subdev_video_ops m5mols_video_ops = { | |
681 | .s_stream = m5mols_s_stream, | |
682 | }; | |
683 | ||
684 | static int m5mols_s_ctrl(struct v4l2_ctrl *ctrl) | |
685 | { | |
686 | struct v4l2_subdev *sd = to_sd(ctrl); | |
687 | struct m5mols_info *info = to_m5mols(sd); | |
aa1f4601 SN |
688 | int ispstate = info->mode; |
689 | int ret; | |
bc125106 | 690 | |
aa1f4601 SN |
691 | /* |
692 | * If needed, defer restoring the controls until | |
693 | * the device is fully initialized. | |
694 | */ | |
695 | if (!info->isp_ready) { | |
696 | info->ctrl_sync = 0; | |
697 | return 0; | |
698 | } | |
bc125106 | 699 | |
aa1f4601 SN |
700 | ret = m5mols_mode(info, REG_PARAMETER); |
701 | if (ret < 0) | |
702 | return ret; | |
703 | ret = m5mols_set_ctrl(ctrl); | |
704 | if (ret < 0) | |
705 | return ret; | |
706 | return m5mols_mode(info, ispstate); | |
bc125106 HK |
707 | } |
708 | ||
709 | static const struct v4l2_ctrl_ops m5mols_ctrl_ops = { | |
710 | .s_ctrl = m5mols_s_ctrl, | |
711 | }; | |
712 | ||
713 | static int m5mols_sensor_power(struct m5mols_info *info, bool enable) | |
714 | { | |
715 | struct v4l2_subdev *sd = &info->sd; | |
716 | struct i2c_client *client = v4l2_get_subdevdata(sd); | |
717 | const struct m5mols_platform_data *pdata = info->pdata; | |
718 | int ret; | |
719 | ||
0f2ee1dd HK |
720 | if (info->power == enable) |
721 | return 0; | |
bc125106 | 722 | |
0f2ee1dd | 723 | if (enable) { |
bc125106 HK |
724 | if (info->set_power) { |
725 | ret = info->set_power(&client->dev, 1); | |
726 | if (ret) | |
727 | return ret; | |
728 | } | |
729 | ||
730 | ret = regulator_bulk_enable(ARRAY_SIZE(supplies), supplies); | |
731 | if (ret) { | |
732 | info->set_power(&client->dev, 0); | |
733 | return ret; | |
734 | } | |
735 | ||
736 | gpio_set_value(pdata->gpio_reset, !pdata->reset_polarity); | |
0f2ee1dd | 737 | info->power = 1; |
bc125106 HK |
738 | |
739 | return ret; | |
740 | } | |
741 | ||
bc125106 HK |
742 | ret = regulator_bulk_disable(ARRAY_SIZE(supplies), supplies); |
743 | if (ret) | |
744 | return ret; | |
745 | ||
746 | if (info->set_power) | |
747 | info->set_power(&client->dev, 0); | |
748 | ||
749 | gpio_set_value(pdata->gpio_reset, pdata->reset_polarity); | |
0f2ee1dd HK |
750 | |
751 | info->isp_ready = 0; | |
752 | info->power = 0; | |
bc125106 HK |
753 | |
754 | return ret; | |
755 | } | |
756 | ||
757 | /* m5mols_update_fw - optional firmware update routine */ | |
758 | int __attribute__ ((weak)) m5mols_update_fw(struct v4l2_subdev *sd, | |
759 | int (*set_power)(struct m5mols_info *, bool)) | |
760 | { | |
761 | return 0; | |
762 | } | |
763 | ||
764 | /** | |
0f2ee1dd | 765 | * m5mols_fw_start - M-5MOLS internal ARM controller initialization |
bc125106 | 766 | * |
0f2ee1dd HK |
767 | * Execute the M-5MOLS internal ARM controller initialization sequence. |
768 | * This function should be called after the supply voltage has been | |
769 | * applied and before any requests to the device are made. | |
bc125106 | 770 | */ |
0f2ee1dd | 771 | static int m5mols_fw_start(struct v4l2_subdev *sd) |
bc125106 | 772 | { |
0f2ee1dd | 773 | struct m5mols_info *info = to_m5mols(sd); |
bc125106 HK |
774 | int ret; |
775 | ||
0f2ee1dd HK |
776 | atomic_set(&info->irq_done, 0); |
777 | /* Wait until I2C slave is initialized in Flash Writer mode */ | |
778 | ret = m5mols_busy_wait(sd, FLASH_CAM_START, REG_IN_FLASH_MODE, | |
779 | M5MOLS_I2C_RDY_WAIT_FL | 0xff, -1); | |
780 | if (!ret) | |
781 | ret = m5mols_write(sd, FLASH_CAM_START, REG_START_ARM_BOOT); | |
782 | if (!ret) | |
783 | ret = m5mols_wait_interrupt(sd, REG_INT_MODE, 2000); | |
bc125106 HK |
784 | if (ret < 0) |
785 | return ret; | |
786 | ||
0f2ee1dd | 787 | info->isp_ready = 1; |
bc125106 HK |
788 | |
789 | ret = m5mols_get_version(sd); | |
790 | if (!ret) | |
791 | ret = m5mols_update_fw(sd, m5mols_sensor_power); | |
792 | if (ret) | |
793 | return ret; | |
794 | ||
795 | v4l2_dbg(1, m5mols_debug, sd, "Success ARM Booting\n"); | |
796 | ||
797 | ret = m5mols_write(sd, PARM_INTERFACE, REG_INTERFACE_MIPI); | |
798 | if (!ret) | |
92e93a1f HK |
799 | ret = m5mols_enable_interrupt(sd, |
800 | REG_INT_AF | REG_INT_CAPTURE); | |
bc125106 HK |
801 | |
802 | return ret; | |
803 | } | |
804 | ||
805 | static int m5mols_init_controls(struct m5mols_info *info) | |
806 | { | |
807 | struct v4l2_subdev *sd = &info->sd; | |
808 | u16 max_exposure; | |
809 | u16 step_zoom; | |
810 | int ret; | |
811 | ||
812 | /* Determine value's range & step of controls for various FW version */ | |
57644f56 | 813 | ret = m5mols_read_u16(sd, AE_MAX_GAIN_MON, &max_exposure); |
bc125106 HK |
814 | if (!ret) |
815 | step_zoom = is_manufacturer(info, REG_SAMSUNG_OPTICS) ? 31 : 1; | |
816 | if (ret) | |
817 | return ret; | |
818 | ||
819 | v4l2_ctrl_handler_init(&info->handle, 6); | |
820 | info->autowb = v4l2_ctrl_new_std(&info->handle, | |
821 | &m5mols_ctrl_ops, V4L2_CID_AUTO_WHITE_BALANCE, | |
822 | 0, 1, 1, 0); | |
823 | info->saturation = v4l2_ctrl_new_std(&info->handle, | |
824 | &m5mols_ctrl_ops, V4L2_CID_SATURATION, | |
825 | 1, 5, 1, 3); | |
826 | info->zoom = v4l2_ctrl_new_std(&info->handle, | |
827 | &m5mols_ctrl_ops, V4L2_CID_ZOOM_ABSOLUTE, | |
828 | 1, 70, step_zoom, 1); | |
829 | info->exposure = v4l2_ctrl_new_std(&info->handle, | |
830 | &m5mols_ctrl_ops, V4L2_CID_EXPOSURE, | |
831 | 0, max_exposure, 1, (int)max_exposure/2); | |
832 | info->colorfx = v4l2_ctrl_new_std_menu(&info->handle, | |
833 | &m5mols_ctrl_ops, V4L2_CID_COLORFX, | |
834 | 4, (1 << V4L2_COLORFX_BW), V4L2_COLORFX_NONE); | |
835 | info->autoexposure = v4l2_ctrl_new_std_menu(&info->handle, | |
836 | &m5mols_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, | |
837 | 1, 0, V4L2_EXPOSURE_MANUAL); | |
838 | ||
839 | sd->ctrl_handler = &info->handle; | |
840 | if (info->handle.error) { | |
841 | v4l2_err(sd, "Failed to initialize controls: %d\n", ret); | |
842 | v4l2_ctrl_handler_free(&info->handle); | |
843 | return info->handle.error; | |
844 | } | |
845 | ||
846 | v4l2_ctrl_cluster(2, &info->autoexposure); | |
847 | ||
848 | return 0; | |
849 | } | |
850 | ||
851 | /** | |
852 | * m5mols_s_power - Main sensor power control function | |
853 | * | |
854 | * To prevent breaking the lens when the sensor is powered off the Soft-Landing | |
855 | * algorithm is called where available. The Soft-Landing algorithm availability | |
856 | * dependends on the firmware provider. | |
857 | */ | |
858 | static int m5mols_s_power(struct v4l2_subdev *sd, int on) | |
859 | { | |
860 | struct m5mols_info *info = to_m5mols(sd); | |
861 | int ret; | |
862 | ||
863 | if (on) { | |
864 | ret = m5mols_sensor_power(info, true); | |
865 | if (!ret) | |
0f2ee1dd | 866 | ret = m5mols_fw_start(sd); |
bc125106 HK |
867 | if (ret) |
868 | return ret; | |
869 | ||
870 | info->ffmt[M5MOLS_RESTYPE_MONITOR] = | |
871 | m5mols_default_ffmt[M5MOLS_RESTYPE_MONITOR]; | |
872 | info->ffmt[M5MOLS_RESTYPE_CAPTURE] = | |
873 | m5mols_default_ffmt[M5MOLS_RESTYPE_CAPTURE]; | |
874 | return ret; | |
875 | } | |
876 | ||
877 | if (is_manufacturer(info, REG_SAMSUNG_TECHWIN)) { | |
878 | ret = m5mols_mode(info, REG_MONITOR); | |
879 | if (!ret) | |
880 | ret = m5mols_write(sd, AF_EXECUTE, REG_AF_STOP); | |
881 | if (!ret) | |
882 | ret = m5mols_write(sd, AF_MODE, REG_AF_POWEROFF); | |
883 | if (!ret) | |
575d6252 HK |
884 | ret = m5mols_busy_wait(sd, SYSTEM_STATUS, REG_AF_IDLE, |
885 | 0xff, -1); | |
886 | if (ret < 0) | |
887 | v4l2_warn(sd, "Soft landing lens failed\n"); | |
bc125106 HK |
888 | } |
889 | ||
890 | ret = m5mols_sensor_power(info, false); | |
aa1f4601 | 891 | info->ctrl_sync = 0; |
bc125106 HK |
892 | |
893 | return ret; | |
894 | } | |
895 | ||
896 | static int m5mols_log_status(struct v4l2_subdev *sd) | |
897 | { | |
898 | struct m5mols_info *info = to_m5mols(sd); | |
899 | ||
900 | v4l2_ctrl_handler_log_status(&info->handle, sd->name); | |
901 | ||
902 | return 0; | |
903 | } | |
904 | ||
905 | static const struct v4l2_subdev_core_ops m5mols_core_ops = { | |
906 | .s_power = m5mols_s_power, | |
907 | .g_ctrl = v4l2_subdev_g_ctrl, | |
908 | .s_ctrl = v4l2_subdev_s_ctrl, | |
909 | .queryctrl = v4l2_subdev_queryctrl, | |
910 | .querymenu = v4l2_subdev_querymenu, | |
911 | .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, | |
912 | .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, | |
913 | .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, | |
914 | .log_status = m5mols_log_status, | |
915 | }; | |
916 | ||
aa1f4601 SN |
917 | /* |
918 | * V4L2 subdev internal operations | |
919 | */ | |
920 | static int m5mols_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) | |
921 | { | |
922 | struct v4l2_mbus_framefmt *format = v4l2_subdev_get_try_format(fh, 0); | |
923 | ||
924 | *format = m5mols_default_ffmt[0]; | |
925 | return 0; | |
926 | } | |
927 | ||
928 | static const struct v4l2_subdev_internal_ops m5mols_subdev_internal_ops = { | |
929 | .open = m5mols_open, | |
930 | }; | |
931 | ||
bc125106 HK |
932 | static const struct v4l2_subdev_ops m5mols_ops = { |
933 | .core = &m5mols_core_ops, | |
934 | .pad = &m5mols_pad_ops, | |
935 | .video = &m5mols_video_ops, | |
936 | }; | |
937 | ||
bc125106 HK |
938 | static irqreturn_t m5mols_irq_handler(int irq, void *data) |
939 | { | |
ce808a47 | 940 | struct m5mols_info *info = to_m5mols(data); |
bc125106 | 941 | |
ce808a47 HK |
942 | atomic_set(&info->irq_done, 1); |
943 | wake_up_interruptible(&info->irq_waitq); | |
bc125106 HK |
944 | |
945 | return IRQ_HANDLED; | |
946 | } | |
947 | ||
948 | static int __devinit m5mols_probe(struct i2c_client *client, | |
949 | const struct i2c_device_id *id) | |
950 | { | |
951 | const struct m5mols_platform_data *pdata = client->dev.platform_data; | |
952 | struct m5mols_info *info; | |
953 | struct v4l2_subdev *sd; | |
954 | int ret; | |
955 | ||
956 | if (pdata == NULL) { | |
957 | dev_err(&client->dev, "No platform data\n"); | |
958 | return -EINVAL; | |
959 | } | |
960 | ||
961 | if (!gpio_is_valid(pdata->gpio_reset)) { | |
962 | dev_err(&client->dev, "No valid RESET GPIO specified\n"); | |
963 | return -EINVAL; | |
964 | } | |
965 | ||
5b3bdfce | 966 | if (!client->irq) { |
bc125106 HK |
967 | dev_err(&client->dev, "Interrupt not assigned\n"); |
968 | return -EINVAL; | |
969 | } | |
970 | ||
971 | info = kzalloc(sizeof(struct m5mols_info), GFP_KERNEL); | |
972 | if (!info) | |
973 | return -ENOMEM; | |
974 | ||
975 | info->pdata = pdata; | |
976 | info->set_power = pdata->set_power; | |
977 | ||
978 | ret = gpio_request(pdata->gpio_reset, "M5MOLS_NRST"); | |
979 | if (ret) { | |
980 | dev_err(&client->dev, "Failed to request gpio: %d\n", ret); | |
981 | goto out_free; | |
982 | } | |
983 | gpio_direction_output(pdata->gpio_reset, pdata->reset_polarity); | |
984 | ||
985 | ret = regulator_bulk_get(&client->dev, ARRAY_SIZE(supplies), supplies); | |
986 | if (ret) { | |
987 | dev_err(&client->dev, "Failed to get regulators: %d\n", ret); | |
988 | goto out_gpio; | |
989 | } | |
990 | ||
991 | sd = &info->sd; | |
992 | strlcpy(sd->name, MODULE_NAME, sizeof(sd->name)); | |
993 | v4l2_i2c_subdev_init(sd, client, &m5mols_ops); | |
994 | ||
aa1f4601 | 995 | sd->internal_ops = &m5mols_subdev_internal_ops; |
bc125106 HK |
996 | info->pad.flags = MEDIA_PAD_FL_SOURCE; |
997 | ret = media_entity_init(&sd->entity, 1, &info->pad, 0); | |
998 | if (ret < 0) | |
999 | goto out_reg; | |
1000 | sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR; | |
1001 | ||
1002 | init_waitqueue_head(&info->irq_waitq); | |
5b3bdfce | 1003 | ret = request_irq(client->irq, m5mols_irq_handler, |
bc125106 HK |
1004 | IRQF_TRIGGER_RISING, MODULE_NAME, sd); |
1005 | if (ret) { | |
1006 | dev_err(&client->dev, "Interrupt request failed: %d\n", ret); | |
1007 | goto out_me; | |
1008 | } | |
1009 | info->res_type = M5MOLS_RESTYPE_MONITOR; | |
ce808a47 | 1010 | |
aa1f4601 SN |
1011 | ret = m5mols_sensor_power(info, true); |
1012 | if (ret) | |
1013 | goto out_me; | |
1014 | ||
1015 | ret = m5mols_fw_start(sd); | |
1016 | if (!ret) | |
1017 | ret = m5mols_init_controls(info); | |
1018 | ||
1019 | m5mols_sensor_power(info, false); | |
1020 | if (!ret) | |
1021 | return 0; | |
bc125106 HK |
1022 | out_me: |
1023 | media_entity_cleanup(&sd->entity); | |
1024 | out_reg: | |
1025 | regulator_bulk_free(ARRAY_SIZE(supplies), supplies); | |
1026 | out_gpio: | |
1027 | gpio_free(pdata->gpio_reset); | |
1028 | out_free: | |
1029 | kfree(info); | |
1030 | return ret; | |
1031 | } | |
1032 | ||
1033 | static int __devexit m5mols_remove(struct i2c_client *client) | |
1034 | { | |
1035 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | |
1036 | struct m5mols_info *info = to_m5mols(sd); | |
1037 | ||
1038 | v4l2_device_unregister_subdev(sd); | |
aa1f4601 | 1039 | v4l2_ctrl_handler_free(sd->ctrl_handler); |
5b3bdfce | 1040 | free_irq(client->irq, sd); |
bc125106 HK |
1041 | |
1042 | regulator_bulk_free(ARRAY_SIZE(supplies), supplies); | |
1043 | gpio_free(info->pdata->gpio_reset); | |
1044 | media_entity_cleanup(&sd->entity); | |
1045 | kfree(info); | |
1046 | return 0; | |
1047 | } | |
1048 | ||
1049 | static const struct i2c_device_id m5mols_id[] = { | |
1050 | { MODULE_NAME, 0 }, | |
1051 | { }, | |
1052 | }; | |
1053 | MODULE_DEVICE_TABLE(i2c, m5mols_id); | |
1054 | ||
1055 | static struct i2c_driver m5mols_i2c_driver = { | |
1056 | .driver = { | |
1057 | .name = MODULE_NAME, | |
1058 | }, | |
1059 | .probe = m5mols_probe, | |
1060 | .remove = __devexit_p(m5mols_remove), | |
1061 | .id_table = m5mols_id, | |
1062 | }; | |
1063 | ||
1064 | static int __init m5mols_mod_init(void) | |
1065 | { | |
1066 | return i2c_add_driver(&m5mols_i2c_driver); | |
1067 | } | |
1068 | ||
1069 | static void __exit m5mols_mod_exit(void) | |
1070 | { | |
1071 | i2c_del_driver(&m5mols_i2c_driver); | |
1072 | } | |
1073 | ||
1074 | module_init(m5mols_mod_init); | |
1075 | module_exit(m5mols_mod_exit); | |
1076 | ||
1077 | MODULE_AUTHOR("HeungJun Kim <riverful.kim@samsung.com>"); | |
1078 | MODULE_AUTHOR("Dongsoo Kim <dongsoo45.kim@samsung.com>"); | |
1079 | MODULE_DESCRIPTION("Fujitsu M-5MOLS 8M Pixel camera driver"); | |
1080 | MODULE_LICENSE("GPL"); |