2011-10-28 21:50:44 +07:00
|
|
|
|
2011-05-20 12:27:28 +07:00
|
|
|
/*
|
|
|
|
* The Capture code for Fujitsu M-5MOLS ISP
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Samsung Electronics Co., Ltd.
|
2011-06-07 12:00:58 +07:00
|
|
|
* Author: HeungJun Kim <riverful.kim@samsung.com>
|
2011-05-20 12:27:28 +07:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Samsung Electronics Co., Ltd.
|
2011-06-07 12:00:58 +07:00
|
|
|
* Author: Dongsoo Nathaniel Kim <dongsoo45.kim@samsung.com>
|
2011-05-20 12:27:28 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include <media/v4l2-ctrls.h>
|
|
|
|
#include <media/v4l2-device.h>
|
|
|
|
#include <media/v4l2-subdev.h>
|
2015-11-10 21:01:44 +07:00
|
|
|
#include <media/i2c/m5mols.h>
|
2015-11-14 04:40:07 +07:00
|
|
|
#include <media/drv-intf/exynos-fimc.h>
|
2011-05-20 12:27:28 +07:00
|
|
|
|
|
|
|
#include "m5mols.h"
|
|
|
|
#include "m5mols_reg.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* m5mols_read_rational - I2C read of a rational number
|
|
|
|
*
|
|
|
|
* Read numerator and denominator from registers @addr_num and @addr_den
|
|
|
|
* respectively and return the division result in @val.
|
|
|
|
*/
|
|
|
|
static int m5mols_read_rational(struct v4l2_subdev *sd, u32 addr_num,
|
|
|
|
u32 addr_den, u32 *val)
|
|
|
|
{
|
|
|
|
u32 num, den;
|
|
|
|
|
2011-05-31 13:44:19 +07:00
|
|
|
int ret = m5mols_read_u32(sd, addr_num, &num);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
2011-05-31 13:44:19 +07:00
|
|
|
ret = m5mols_read_u32(sd, addr_den, &den);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
*val = den == 0 ? 0 : num / den;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* m5mols_capture_info - Gather captured image information
|
|
|
|
*
|
|
|
|
* For now it gathers only EXIF information and file size.
|
|
|
|
*/
|
|
|
|
static int m5mols_capture_info(struct m5mols_info *info)
|
|
|
|
{
|
|
|
|
struct m5mols_exif *exif = &info->cap.exif;
|
|
|
|
struct v4l2_subdev *sd = &info->sd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = m5mols_read_rational(sd, EXIF_INFO_EXPTIME_NU,
|
|
|
|
EXIF_INFO_EXPTIME_DE, &exif->exposure_time);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = m5mols_read_rational(sd, EXIF_INFO_TV_NU, EXIF_INFO_TV_DE,
|
|
|
|
&exif->shutter_speed);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = m5mols_read_rational(sd, EXIF_INFO_AV_NU, EXIF_INFO_AV_DE,
|
|
|
|
&exif->aperture);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = m5mols_read_rational(sd, EXIF_INFO_BV_NU, EXIF_INFO_BV_DE,
|
|
|
|
&exif->brightness);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = m5mols_read_rational(sd, EXIF_INFO_EBV_NU, EXIF_INFO_EBV_DE,
|
|
|
|
&exif->exposure_bias);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-05-31 13:44:19 +07:00
|
|
|
ret = m5mols_read_u16(sd, EXIF_INFO_ISO, &exif->iso_speed);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
2011-05-31 13:44:19 +07:00
|
|
|
ret = m5mols_read_u16(sd, EXIF_INFO_FLASH, &exif->flash);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
2011-05-31 13:44:19 +07:00
|
|
|
ret = m5mols_read_u16(sd, EXIF_INFO_SDR, &exif->sdr);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
2011-05-31 13:44:19 +07:00
|
|
|
ret = m5mols_read_u16(sd, EXIF_INFO_QVAL, &exif->qval);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!ret)
|
2011-05-31 13:44:19 +07:00
|
|
|
ret = m5mols_read_u32(sd, CAPC_IMAGE_SIZE, &info->cap.main);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
2011-05-31 13:44:19 +07:00
|
|
|
ret = m5mols_read_u32(sd, CAPC_THUMB_SIZE, &info->cap.thumb);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
|
|
|
info->cap.total = info->cap.main + info->cap.thumb;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int m5mols_start_capture(struct m5mols_info *info)
|
|
|
|
{
|
2012-09-18 16:18:43 +07:00
|
|
|
unsigned int framesize = info->cap.buf_size - M5MOLS_JPEG_TAGS_SIZE;
|
2011-05-20 12:27:28 +07:00
|
|
|
struct v4l2_subdev *sd = &info->sd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
2011-12-03 21:18:57 +07:00
|
|
|
* Synchronize the controls, set the capture frame resolution and color
|
|
|
|
* format. The frame capture is initiated during switching from Monitor
|
|
|
|
* to Capture mode.
|
2011-05-20 12:27:28 +07:00
|
|
|
*/
|
2012-04-09 23:51:56 +07:00
|
|
|
ret = m5mols_set_mode(info, REG_MONITOR);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
2011-12-13 01:45:56 +07:00
|
|
|
ret = m5mols_restore_controls(info);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
2011-12-03 21:18:57 +07:00
|
|
|
ret = m5mols_write(sd, CAPP_YUVOUT_MAIN, REG_JPEG);
|
|
|
|
if (!ret)
|
2012-05-09 21:53:09 +07:00
|
|
|
ret = m5mols_write(sd, CAPP_MAIN_IMAGE_SIZE, info->resolution);
|
2012-09-18 16:18:43 +07:00
|
|
|
if (!ret)
|
|
|
|
ret = m5mols_write(sd, CAPP_JPEG_SIZE_MAX, framesize);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (!ret)
|
2012-04-09 23:51:56 +07:00
|
|
|
ret = m5mols_set_mode(info, REG_CAPTURE);
|
2011-12-03 07:53:20 +07:00
|
|
|
if (!ret)
|
2011-12-03 21:18:57 +07:00
|
|
|
/* Wait until a frame is captured to ISP internal memory */
|
2011-12-03 07:53:20 +07:00
|
|
|
ret = m5mols_wait_interrupt(sd, REG_INT_CAPTURE, 2000);
|
2011-05-20 12:27:28 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-12-03 21:18:57 +07:00
|
|
|
|
2011-05-20 12:27:28 +07:00
|
|
|
/*
|
2011-12-03 21:18:57 +07:00
|
|
|
* Initiate the captured data transfer to a MIPI-CSI receiver.
|
2011-05-20 12:27:28 +07:00
|
|
|
*/
|
|
|
|
ret = m5mols_write(sd, CAPC_SEL_FRAME, 1);
|
|
|
|
if (!ret)
|
|
|
|
ret = m5mols_write(sd, CAPC_START, REG_CAP_START_MAIN);
|
|
|
|
if (!ret) {
|
2011-10-28 21:50:44 +07:00
|
|
|
bool captured = false;
|
|
|
|
unsigned int size;
|
|
|
|
|
2011-05-20 12:27:28 +07:00
|
|
|
/* Wait for the capture completion interrupt */
|
2011-12-03 07:53:20 +07:00
|
|
|
ret = m5mols_wait_interrupt(sd, REG_INT_CAPTURE, 2000);
|
|
|
|
if (!ret) {
|
2011-10-28 21:50:44 +07:00
|
|
|
captured = true;
|
2011-05-20 12:27:28 +07:00
|
|
|
ret = m5mols_capture_info(info);
|
|
|
|
}
|
2011-10-28 21:50:44 +07:00
|
|
|
size = captured ? info->cap.main : 0;
|
|
|
|
v4l2_dbg(1, m5mols_debug, sd, "%s: size: %d, thumb.: %d B\n",
|
|
|
|
__func__, size, info->cap.thumb);
|
|
|
|
|
|
|
|
v4l2_subdev_notify(sd, S5P_FIMC_TX_END_NOTIFY, &size);
|
2011-05-20 12:27:28 +07:00
|
|
|
}
|
|
|
|
|
2011-12-03 07:53:20 +07:00
|
|
|
return ret;
|
2011-05-20 12:27:28 +07:00
|
|
|
}
|