Merge branch 'for-linus' of git://git.kernel.dk/linux-block
[deliverable/linux.git] / drivers / media / video / m5mols / m5mols_capture.c
CommitLineData
d5048c9a 1
bc125106
HK
2/*
3 * The Capture code for Fujitsu M-5MOLS ISP
4 *
5 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
c3070113 6 * Author: HeungJun Kim <riverful.kim@samsung.com>
bc125106
HK
7 *
8 * Copyright (C) 2009 Samsung Electronics Co., Ltd.
c3070113 9 * Author: Dongsoo Nathaniel Kim <dongsoo45.kim@samsung.com>
bc125106
HK
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
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>
bc125106
HK
22#include <linux/gpio.h>
23#include <linux/regulator/consumer.h>
24#include <linux/videodev2.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>
d5048c9a 29#include <media/s5p_fimc.h>
bc125106
HK
30
31#include "m5mols.h"
32#include "m5mols_reg.h"
33
bc125106
HK
34/**
35 * m5mols_read_rational - I2C read of a rational number
36 *
37 * Read numerator and denominator from registers @addr_num and @addr_den
38 * respectively and return the division result in @val.
39 */
40static int m5mols_read_rational(struct v4l2_subdev *sd, u32 addr_num,
41 u32 addr_den, u32 *val)
42{
43 u32 num, den;
44
57644f56 45 int ret = m5mols_read_u32(sd, addr_num, &num);
bc125106 46 if (!ret)
57644f56 47 ret = m5mols_read_u32(sd, addr_den, &den);
bc125106
HK
48 if (ret)
49 return ret;
50 *val = den == 0 ? 0 : num / den;
51 return ret;
52}
53
54/**
55 * m5mols_capture_info - Gather captured image information
56 *
57 * For now it gathers only EXIF information and file size.
58 */
59static int m5mols_capture_info(struct m5mols_info *info)
60{
61 struct m5mols_exif *exif = &info->cap.exif;
62 struct v4l2_subdev *sd = &info->sd;
63 int ret;
64
65 ret = m5mols_read_rational(sd, EXIF_INFO_EXPTIME_NU,
66 EXIF_INFO_EXPTIME_DE, &exif->exposure_time);
67 if (ret)
68 return ret;
69 ret = m5mols_read_rational(sd, EXIF_INFO_TV_NU, EXIF_INFO_TV_DE,
70 &exif->shutter_speed);
71 if (ret)
72 return ret;
73 ret = m5mols_read_rational(sd, EXIF_INFO_AV_NU, EXIF_INFO_AV_DE,
74 &exif->aperture);
75 if (ret)
76 return ret;
77 ret = m5mols_read_rational(sd, EXIF_INFO_BV_NU, EXIF_INFO_BV_DE,
78 &exif->brightness);
79 if (ret)
80 return ret;
81 ret = m5mols_read_rational(sd, EXIF_INFO_EBV_NU, EXIF_INFO_EBV_DE,
82 &exif->exposure_bias);
83 if (ret)
84 return ret;
85
57644f56 86 ret = m5mols_read_u16(sd, EXIF_INFO_ISO, &exif->iso_speed);
bc125106 87 if (!ret)
57644f56 88 ret = m5mols_read_u16(sd, EXIF_INFO_FLASH, &exif->flash);
bc125106 89 if (!ret)
57644f56 90 ret = m5mols_read_u16(sd, EXIF_INFO_SDR, &exif->sdr);
bc125106 91 if (!ret)
57644f56 92 ret = m5mols_read_u16(sd, EXIF_INFO_QVAL, &exif->qval);
bc125106
HK
93 if (ret)
94 return ret;
95
96 if (!ret)
57644f56 97 ret = m5mols_read_u32(sd, CAPC_IMAGE_SIZE, &info->cap.main);
bc125106 98 if (!ret)
57644f56 99 ret = m5mols_read_u32(sd, CAPC_THUMB_SIZE, &info->cap.thumb);
bc125106
HK
100 if (!ret)
101 info->cap.total = info->cap.main + info->cap.thumb;
102
103 return ret;
104}
105
106int m5mols_start_capture(struct m5mols_info *info)
107{
108 struct v4l2_subdev *sd = &info->sd;
57644f56 109 u8 resolution = info->resolution;
bc125106
HK
110 int ret;
111
112 /*
92e93a1f
HK
113 * Synchronize the controls, set the capture frame resolution and color
114 * format. The frame capture is initiated during switching from Monitor
115 * to Capture mode.
bc125106
HK
116 */
117 ret = m5mols_mode(info, REG_MONITOR);
118 if (!ret)
5d4294b8 119 ret = m5mols_restore_controls(info);
bc125106 120 if (!ret)
92e93a1f
HK
121 ret = m5mols_write(sd, CAPP_YUVOUT_MAIN, REG_JPEG);
122 if (!ret)
123 ret = m5mols_write(sd, CAPP_MAIN_IMAGE_SIZE, resolution);
bc125106 124 if (!ret)
92e93a1f 125 ret = m5mols_lock_3a(info, true);
bc125106
HK
126 if (!ret)
127 ret = m5mols_mode(info, REG_CAPTURE);
ce808a47 128 if (!ret)
92e93a1f 129 /* Wait until a frame is captured to ISP internal memory */
ce808a47 130 ret = m5mols_wait_interrupt(sd, REG_INT_CAPTURE, 2000);
bc125106
HK
131 if (!ret)
132 ret = m5mols_lock_3a(info, false);
133 if (ret)
134 return ret;
92e93a1f 135
bc125106 136 /*
92e93a1f 137 * Initiate the captured data transfer to a MIPI-CSI receiver.
bc125106
HK
138 */
139 ret = m5mols_write(sd, CAPC_SEL_FRAME, 1);
bc125106
HK
140 if (!ret)
141 ret = m5mols_write(sd, CAPC_START, REG_CAP_START_MAIN);
142 if (!ret) {
d5048c9a
SN
143 bool captured = false;
144 unsigned int size;
145
bc125106 146 /* Wait for the capture completion interrupt */
ce808a47
HK
147 ret = m5mols_wait_interrupt(sd, REG_INT_CAPTURE, 2000);
148 if (!ret) {
d5048c9a 149 captured = true;
bc125106 150 ret = m5mols_capture_info(info);
bc125106 151 }
d5048c9a
SN
152 size = captured ? info->cap.main : 0;
153 v4l2_dbg(1, m5mols_debug, sd, "%s: size: %d, thumb.: %d B\n",
154 __func__, size, info->cap.thumb);
155
156 v4l2_subdev_notify(sd, S5P_FIMC_TX_END_NOTIFY, &size);
bc125106
HK
157 }
158
ce808a47 159 return ret;
bc125106 160}
This page took 0.08112 seconds and 5 git commands to generate.