1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/i2c.h>
18#include <linux/slab.h>
19#include <linux/irq.h>
20#include <linux/interrupt.h>
21#include <linux/delay.h>
22#include <linux/gpio.h>
23#include <linux/regulator/consumer.h>
24#include <linux/videodev2.h>
25#include <media/v4l2-ctrls.h>
26#include <media/v4l2-device.h>
27#include <media/v4l2-subdev.h>
28#include <media/i2c/m5mols.h>
29#include <media/drv-intf/exynos-fimc.h>
30
31#include "m5mols.h"
32#include "m5mols_reg.h"
33
34
35
36
37
38
39
40
41
42
43
44static int m5mols_read_rational(struct v4l2_subdev *sd, u32 addr_num,
45 u32 addr_den, u32 *val)
46{
47 u32 num, den;
48
49 int ret = m5mols_read_u32(sd, addr_num, &num);
50 if (!ret)
51 ret = m5mols_read_u32(sd, addr_den, &den);
52 if (ret)
53 return ret;
54 *val = den == 0 ? 0 : num / den;
55 return ret;
56}
57
58
59
60
61
62
63
64static int m5mols_capture_info(struct m5mols_info *info)
65{
66 struct m5mols_exif *exif = &info->cap.exif;
67 struct v4l2_subdev *sd = &info->sd;
68 int ret;
69
70 ret = m5mols_read_rational(sd, EXIF_INFO_EXPTIME_NU,
71 EXIF_INFO_EXPTIME_DE, &exif->exposure_time);
72 if (ret)
73 return ret;
74 ret = m5mols_read_rational(sd, EXIF_INFO_TV_NU, EXIF_INFO_TV_DE,
75 &exif->shutter_speed);
76 if (ret)
77 return ret;
78 ret = m5mols_read_rational(sd, EXIF_INFO_AV_NU, EXIF_INFO_AV_DE,
79 &exif->aperture);
80 if (ret)
81 return ret;
82 ret = m5mols_read_rational(sd, EXIF_INFO_BV_NU, EXIF_INFO_BV_DE,
83 &exif->brightness);
84 if (ret)
85 return ret;
86 ret = m5mols_read_rational(sd, EXIF_INFO_EBV_NU, EXIF_INFO_EBV_DE,
87 &exif->exposure_bias);
88 if (ret)
89 return ret;
90
91 ret = m5mols_read_u16(sd, EXIF_INFO_ISO, &exif->iso_speed);
92 if (!ret)
93 ret = m5mols_read_u16(sd, EXIF_INFO_FLASH, &exif->flash);
94 if (!ret)
95 ret = m5mols_read_u16(sd, EXIF_INFO_SDR, &exif->sdr);
96 if (!ret)
97 ret = m5mols_read_u16(sd, EXIF_INFO_QVAL, &exif->qval);
98 if (ret)
99 return ret;
100
101 if (!ret)
102 ret = m5mols_read_u32(sd, CAPC_IMAGE_SIZE, &info->cap.main);
103 if (!ret)
104 ret = m5mols_read_u32(sd, CAPC_THUMB_SIZE, &info->cap.thumb);
105 if (!ret)
106 info->cap.total = info->cap.main + info->cap.thumb;
107
108 return ret;
109}
110
111int m5mols_start_capture(struct m5mols_info *info)
112{
113 unsigned int framesize = info->cap.buf_size - M5MOLS_JPEG_TAGS_SIZE;
114 struct v4l2_subdev *sd = &info->sd;
115 int ret;
116
117
118
119
120
121
122 ret = m5mols_set_mode(info, REG_MONITOR);
123 if (!ret)
124 ret = m5mols_restore_controls(info);
125 if (!ret)
126 ret = m5mols_write(sd, CAPP_YUVOUT_MAIN, REG_JPEG);
127 if (!ret)
128 ret = m5mols_write(sd, CAPP_MAIN_IMAGE_SIZE, info->resolution);
129 if (!ret)
130 ret = m5mols_write(sd, CAPP_JPEG_SIZE_MAX, framesize);
131 if (!ret)
132 ret = m5mols_set_mode(info, REG_CAPTURE);
133 if (!ret)
134
135 ret = m5mols_wait_interrupt(sd, REG_INT_CAPTURE, 2000);
136 if (ret)
137 return ret;
138
139
140
141
142 ret = m5mols_write(sd, CAPC_SEL_FRAME, 1);
143 if (!ret)
144 ret = m5mols_write(sd, CAPC_START, REG_CAP_START_MAIN);
145 if (!ret) {
146 bool captured = false;
147 unsigned int size;
148
149
150 ret = m5mols_wait_interrupt(sd, REG_INT_CAPTURE, 2000);
151 if (!ret) {
152 captured = true;
153 ret = m5mols_capture_info(info);
154 }
155 size = captured ? info->cap.main : 0;
156 v4l2_dbg(1, m5mols_debug, sd, "%s: size: %d, thumb.: %d B\n",
157 __func__, size, info->cap.thumb);
158
159 v4l2_subdev_notify(sd, S5P_FIMC_TX_END_NOTIFY, &size);
160 }
161
162 return ret;
163}
164