Commit ccfc97bd authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

[media] smiapp: Add driver

Add driver for SMIA++/SMIA image sensors. The driver exposes the sensor as
three subdevs, pixel array, binner and scaler --- in case the device has a
scaler.

Currently it relies on the board code for external clock handling. There is
no fast way out of this dependency before the ISP drivers (omap3isp) among
others will be able to export that clock through the clock framework
instead.
Signed-off-by: default avatarSakari Ailus <sakari.ailus@maxwell.research.nokia.com>
Acked-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent cf1c5fae
......@@ -559,6 +559,8 @@ config VIDEO_S5K6AA
This is a V4L2 sensor-level driver for Samsung S5K6AA(FX) 1.3M
camera sensor with an embedded SoC image signal processor.
source "drivers/media/video/smiapp/Kconfig"
comment "Flash devices"
config VIDEO_ADP1653
......
......@@ -79,6 +79,7 @@ obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o
obj-$(CONFIG_VIDEO_NOON010PC30) += noon010pc30.o
obj-$(CONFIG_VIDEO_M5MOLS) += m5mols/
obj-$(CONFIG_VIDEO_S5K6AA) += s5k6aa.o
obj-$(CONFIG_VIDEO_SMIAPP) += smiapp/
obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o
obj-$(CONFIG_VIDEO_AS3645A) += as3645a.o
......
......@@ -22,6 +22,8 @@
*
*/
#include "smiapp/smiapp-debug.h"
#include <linux/gcd.h>
#include <linux/lcm.h>
#include <linux/module.h>
......
config VIDEO_SMIAPP
tristate "SMIA++/SMIA sensor support"
depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
select VIDEO_SMIAPP_PLL
---help---
This is a generic driver for SMIA++/SMIA camera modules.
config VIDEO_SMIAPP_DEBUG
bool "Enable debugging for the generic SMIA++/SMIA driver"
depends on VIDEO_SMIAPP
---help---
Enable debugging output in the generic SMIA++/SMIA driver. If you
are developing the driver you might want to enable this.
smiapp-objs += smiapp-core.o smiapp-regs.o \
smiapp-quirk.o smiapp-limits.o
obj-$(CONFIG_VIDEO_SMIAPP) += smiapp.o
This diff is collapsed.
/*
* drivers/media/video/smiapp/smiapp-debug.h
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef SMIAPP_DEBUG_H
#define SMIAPP_DEBUG_H
#ifdef CONFIG_VIDEO_SMIAPP_DEBUG
#define DEBUG
#endif
#endif
/*
* drivers/media/video/smiapp/smiapp-limits.c
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include "smiapp.h"
struct smiapp_reg_limits smiapp_reg_limits[] = {
{ SMIAPP_REG_U16_ANALOGUE_GAIN_CAPABILITY, "analogue_gain_capability" }, /* 0 */
{ SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_MIN, "analogue_gain_code_min" },
{ SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_MAX, "analogue_gain_code_max" },
{ SMIAPP_REG_U8_THS_ZERO_MIN, "ths_zero_min" },
{ SMIAPP_REG_U8_TCLK_TRAIL_MIN, "tclk_trail_min" },
{ SMIAPP_REG_U16_INTEGRATION_TIME_CAPABILITY, "integration_time_capability" }, /* 5 */
{ SMIAPP_REG_U16_COARSE_INTEGRATION_TIME_MIN, "coarse_integration_time_min" },
{ SMIAPP_REG_U16_COARSE_INTEGRATION_TIME_MAX_MARGIN, "coarse_integration_time_max_margin" },
{ SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MIN, "fine_integration_time_min" },
{ SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MAX_MARGIN, "fine_integration_time_max_margin" },
{ SMIAPP_REG_U16_DIGITAL_GAIN_CAPABILITY, "digital_gain_capability" }, /* 10 */
{ SMIAPP_REG_U16_DIGITAL_GAIN_MIN, "digital_gain_min" },
{ SMIAPP_REG_U16_DIGITAL_GAIN_MAX, "digital_gain_max" },
{ SMIAPP_REG_F32_MIN_EXT_CLK_FREQ_HZ, "min_ext_clk_freq_hz" },
{ SMIAPP_REG_F32_MAX_EXT_CLK_FREQ_HZ, "max_ext_clk_freq_hz" },
{ SMIAPP_REG_U16_MIN_PRE_PLL_CLK_DIV, "min_pre_pll_clk_div" }, /* 15 */
{ SMIAPP_REG_U16_MAX_PRE_PLL_CLK_DIV, "max_pre_pll_clk_div" },
{ SMIAPP_REG_F32_MIN_PLL_IP_FREQ_HZ, "min_pll_ip_freq_hz" },
{ SMIAPP_REG_F32_MAX_PLL_IP_FREQ_HZ, "max_pll_ip_freq_hz" },
{ SMIAPP_REG_U16_MIN_PLL_MULTIPLIER, "min_pll_multiplier" },
{ SMIAPP_REG_U16_MAX_PLL_MULTIPLIER, "max_pll_multiplier" }, /* 20 */
{ SMIAPP_REG_F32_MIN_PLL_OP_FREQ_HZ, "min_pll_op_freq_hz" },
{ SMIAPP_REG_F32_MAX_PLL_OP_FREQ_HZ, "max_pll_op_freq_hz" },
{ SMIAPP_REG_U16_MIN_VT_SYS_CLK_DIV, "min_vt_sys_clk_div" },
{ SMIAPP_REG_U16_MAX_VT_SYS_CLK_DIV, "max_vt_sys_clk_div" },
{ SMIAPP_REG_F32_MIN_VT_SYS_CLK_FREQ_HZ, "min_vt_sys_clk_freq_hz" }, /* 25 */
{ SMIAPP_REG_F32_MAX_VT_SYS_CLK_FREQ_HZ, "max_vt_sys_clk_freq_hz" },
{ SMIAPP_REG_F32_MIN_VT_PIX_CLK_FREQ_HZ, "min_vt_pix_clk_freq_hz" },
{ SMIAPP_REG_F32_MAX_VT_PIX_CLK_FREQ_HZ, "max_vt_pix_clk_freq_hz" },
{ SMIAPP_REG_U16_MIN_VT_PIX_CLK_DIV, "min_vt_pix_clk_div" },
{ SMIAPP_REG_U16_MAX_VT_PIX_CLK_DIV, "max_vt_pix_clk_div" }, /* 30 */
{ SMIAPP_REG_U16_MIN_FRAME_LENGTH_LINES, "min_frame_length_lines" },
{ SMIAPP_REG_U16_MAX_FRAME_LENGTH_LINES, "max_frame_length_lines" },
{ SMIAPP_REG_U16_MIN_LINE_LENGTH_PCK, "min_line_length_pck" },
{ SMIAPP_REG_U16_MAX_LINE_LENGTH_PCK, "max_line_length_pck" },
{ SMIAPP_REG_U16_MIN_LINE_BLANKING_PCK, "min_line_blanking_pck" }, /* 35 */
{ SMIAPP_REG_U16_MIN_FRAME_BLANKING_LINES, "min_frame_blanking_lines" },
{ SMIAPP_REG_U8_MIN_LINE_LENGTH_PCK_STEP_SIZE, "min_line_length_pck_step_size" },
{ SMIAPP_REG_U16_MIN_OP_SYS_CLK_DIV, "min_op_sys_clk_div" },
{ SMIAPP_REG_U16_MAX_OP_SYS_CLK_DIV, "max_op_sys_clk_div" },
{ SMIAPP_REG_F32_MIN_OP_SYS_CLK_FREQ_HZ, "min_op_sys_clk_freq_hz" }, /* 40 */
{ SMIAPP_REG_F32_MAX_OP_SYS_CLK_FREQ_HZ, "max_op_sys_clk_freq_hz" },
{ SMIAPP_REG_U16_MIN_OP_PIX_CLK_DIV, "min_op_pix_clk_div" },
{ SMIAPP_REG_U16_MAX_OP_PIX_CLK_DIV, "max_op_pix_clk_div" },
{ SMIAPP_REG_F32_MIN_OP_PIX_CLK_FREQ_HZ, "min_op_pix_clk_freq_hz" },
{ SMIAPP_REG_F32_MAX_OP_PIX_CLK_FREQ_HZ, "max_op_pix_clk_freq_hz" }, /* 45 */
{ SMIAPP_REG_U16_X_ADDR_MIN, "x_addr_min" },
{ SMIAPP_REG_U16_Y_ADDR_MIN, "y_addr_min" },
{ SMIAPP_REG_U16_X_ADDR_MAX, "x_addr_max" },
{ SMIAPP_REG_U16_Y_ADDR_MAX, "y_addr_max" },
{ SMIAPP_REG_U16_MIN_X_OUTPUT_SIZE, "min_x_output_size" }, /* 50 */
{ SMIAPP_REG_U16_MIN_Y_OUTPUT_SIZE, "min_y_output_size" },
{ SMIAPP_REG_U16_MAX_X_OUTPUT_SIZE, "max_x_output_size" },
{ SMIAPP_REG_U16_MAX_Y_OUTPUT_SIZE, "max_y_output_size" },
{ SMIAPP_REG_U16_MIN_EVEN_INC, "min_even_inc" },
{ SMIAPP_REG_U16_MAX_EVEN_INC, "max_even_inc" }, /* 55 */
{ SMIAPP_REG_U16_MIN_ODD_INC, "min_odd_inc" },
{ SMIAPP_REG_U16_MAX_ODD_INC, "max_odd_inc" },
{ SMIAPP_REG_U16_SCALING_CAPABILITY, "scaling_capability" },
{ SMIAPP_REG_U16_SCALER_M_MIN, "scaler_m_min" },
{ SMIAPP_REG_U16_SCALER_M_MAX, "scaler_m_max" }, /* 60 */
{ SMIAPP_REG_U16_SCALER_N_MIN, "scaler_n_min" },
{ SMIAPP_REG_U16_SCALER_N_MAX, "scaler_n_max" },
{ SMIAPP_REG_U16_SPATIAL_SAMPLING_CAPABILITY, "spatial_sampling_capability" },
{ SMIAPP_REG_U8_DIGITAL_CROP_CAPABILITY, "digital_crop_capability" },
{ SMIAPP_REG_U16_COMPRESSION_CAPABILITY, "compression_capability" }, /* 65 */
{ SMIAPP_REG_U8_FIFO_SUPPORT_CAPABILITY, "fifo_support_capability" },
{ SMIAPP_REG_U8_DPHY_CTRL_CAPABILITY, "dphy_ctrl_capability" },
{ SMIAPP_REG_U8_CSI_LANE_MODE_CAPABILITY, "csi_lane_mode_capability" },
{ SMIAPP_REG_U8_CSI_SIGNALLING_MODE_CAPABILITY, "csi_signalling_mode_capability" },
{ SMIAPP_REG_U8_FAST_STANDBY_CAPABILITY, "fast_standby_capability" }, /* 70 */
{ SMIAPP_REG_U8_CCI_ADDRESS_CONTROL_CAPABILITY, "cci_address_control_capability" },
{ SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_1_LANE_MODE_MBPS, "max_per_lane_bitrate_1_lane_mode_mbps" },
{ SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_2_LANE_MODE_MBPS, "max_per_lane_bitrate_2_lane_mode_mbps" },
{ SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_3_LANE_MODE_MBPS, "max_per_lane_bitrate_3_lane_mode_mbps" },
{ SMIAPP_REG_U32_MAX_PER_LANE_BITRATE_4_LANE_MODE_MBPS, "max_per_lane_bitrate_4_lane_mode_mbps" }, /* 75 */
{ SMIAPP_REG_U8_TEMP_SENSOR_CAPABILITY, "temp_sensor_capability" },
{ SMIAPP_REG_U16_MIN_FRAME_LENGTH_LINES_BIN, "min_frame_length_lines_bin" },
{ SMIAPP_REG_U16_MAX_FRAME_LENGTH_LINES_BIN, "max_frame_length_lines_bin" },
{ SMIAPP_REG_U16_MIN_LINE_LENGTH_PCK_BIN, "min_line_length_pck_bin" },
{ SMIAPP_REG_U16_MAX_LINE_LENGTH_PCK_BIN, "max_line_length_pck_bin" }, /* 80 */
{ SMIAPP_REG_U16_MIN_LINE_BLANKING_PCK_BIN, "min_line_blanking_pck_bin" },
{ SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MIN_BIN, "fine_integration_time_min_bin" },
{ SMIAPP_REG_U16_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN, "fine_integration_time_max_margin_bin" },
{ SMIAPP_REG_U8_BINNING_CAPABILITY, "binning_capability" },
{ SMIAPP_REG_U8_BINNING_WEIGHTING_CAPABILITY, "binning_weighting_capability" }, /* 85 */
{ SMIAPP_REG_U8_DATA_TRANSFER_IF_CAPABILITY, "data_transfer_if_capability" },
{ SMIAPP_REG_U8_SHADING_CORRECTION_CAPABILITY, "shading_correction_capability" },
{ SMIAPP_REG_U8_GREEN_IMBALANCE_CAPABILITY, "green_imbalance_capability" },
{ SMIAPP_REG_U8_BLACK_LEVEL_CAPABILITY, "black_level_capability" },
{ SMIAPP_REG_U8_MODULE_SPECIFIC_CORRECTION_CAPABILITY, "module_specific_correction_capability" }, /* 90 */
{ SMIAPP_REG_U16_DEFECT_CORRECTION_CAPABILITY, "defect_correction_capability" },
{ SMIAPP_REG_U16_DEFECT_CORRECTION_CAPABILITY_2, "defect_correction_capability_2" },
{ SMIAPP_REG_U8_EDOF_CAPABILITY, "edof_capability" },
{ SMIAPP_REG_U8_COLOUR_FEEDBACK_CAPABILITY, "colour_feedback_capability" },
{ SMIAPP_REG_U8_ESTIMATION_MODE_CAPABILITY, "estimation_mode_capability" }, /* 95 */
{ SMIAPP_REG_U8_ESTIMATION_ZONE_CAPABILITY, "estimation_zone_capability" },
{ SMIAPP_REG_U16_CAPABILITY_TRDY_MIN, "capability_trdy_min" },
{ SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, "flash_mode_capability" },
{ SMIAPP_REG_U8_ACTUATOR_CAPABILITY, "actuator_capability" },
{ SMIAPP_REG_U8_BRACKETING_LUT_CAPABILITY_1, "bracketing_lut_capability_1" }, /* 100 */
{ SMIAPP_REG_U8_BRACKETING_LUT_CAPABILITY_2, "bracketing_lut_capability_2" },
{ SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_STEP, "analogue_gain_code_step" },
{ 0, NULL },
};
/*
* drivers/media/video/smiapp/smiapp-limits.h
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#define SMIAPP_LIMIT_ANALOGUE_GAIN_CAPABILITY 0
#define SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN 1
#define SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX 2
#define SMIAPP_LIMIT_THS_ZERO_MIN 3
#define SMIAPP_LIMIT_TCLK_TRAIL_MIN 4
#define SMIAPP_LIMIT_INTEGRATION_TIME_CAPABILITY 5
#define SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MIN 6
#define SMIAPP_LIMIT_COARSE_INTEGRATION_TIME_MAX_MARGIN 7
#define SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN 8
#define SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN 9
#define SMIAPP_LIMIT_DIGITAL_GAIN_CAPABILITY 10
#define SMIAPP_LIMIT_DIGITAL_GAIN_MIN 11
#define SMIAPP_LIMIT_DIGITAL_GAIN_MAX 12
#define SMIAPP_LIMIT_MIN_EXT_CLK_FREQ_HZ 13
#define SMIAPP_LIMIT_MAX_EXT_CLK_FREQ_HZ 14
#define SMIAPP_LIMIT_MIN_PRE_PLL_CLK_DIV 15
#define SMIAPP_LIMIT_MAX_PRE_PLL_CLK_DIV 16
#define SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ 17
#define SMIAPP_LIMIT_MAX_PLL_IP_FREQ_HZ 18
#define SMIAPP_LIMIT_MIN_PLL_MULTIPLIER 19
#define SMIAPP_LIMIT_MAX_PLL_MULTIPLIER 20
#define SMIAPP_LIMIT_MIN_PLL_OP_FREQ_HZ 21
#define SMIAPP_LIMIT_MAX_PLL_OP_FREQ_HZ 22
#define SMIAPP_LIMIT_MIN_VT_SYS_CLK_DIV 23
#define SMIAPP_LIMIT_MAX_VT_SYS_CLK_DIV 24
#define SMIAPP_LIMIT_MIN_VT_SYS_CLK_FREQ_HZ 25
#define SMIAPP_LIMIT_MAX_VT_SYS_CLK_FREQ_HZ 26
#define SMIAPP_LIMIT_MIN_VT_PIX_CLK_FREQ_HZ 27
#define SMIAPP_LIMIT_MAX_VT_PIX_CLK_FREQ_HZ 28
#define SMIAPP_LIMIT_MIN_VT_PIX_CLK_DIV 29
#define SMIAPP_LIMIT_MAX_VT_PIX_CLK_DIV 30
#define SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES 31
#define SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES 32
#define SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK 33
#define SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK 34
#define SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK 35
#define SMIAPP_LIMIT_MIN_FRAME_BLANKING_LINES 36
#define SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_STEP_SIZE 37
#define SMIAPP_LIMIT_MIN_OP_SYS_CLK_DIV 38
#define SMIAPP_LIMIT_MAX_OP_SYS_CLK_DIV 39
#define SMIAPP_LIMIT_MIN_OP_SYS_CLK_FREQ_HZ 40
#define SMIAPP_LIMIT_MAX_OP_SYS_CLK_FREQ_HZ 41
#define SMIAPP_LIMIT_MIN_OP_PIX_CLK_DIV 42
#define SMIAPP_LIMIT_MAX_OP_PIX_CLK_DIV 43
#define SMIAPP_LIMIT_MIN_OP_PIX_CLK_FREQ_HZ 44
#define SMIAPP_LIMIT_MAX_OP_PIX_CLK_FREQ_HZ 45
#define SMIAPP_LIMIT_X_ADDR_MIN 46
#define SMIAPP_LIMIT_Y_ADDR_MIN 47
#define SMIAPP_LIMIT_X_ADDR_MAX 48
#define SMIAPP_LIMIT_Y_ADDR_MAX 49
#define SMIAPP_LIMIT_MIN_X_OUTPUT_SIZE 50
#define SMIAPP_LIMIT_MIN_Y_OUTPUT_SIZE 51
#define SMIAPP_LIMIT_MAX_X_OUTPUT_SIZE 52
#define SMIAPP_LIMIT_MAX_Y_OUTPUT_SIZE 53
#define SMIAPP_LIMIT_MIN_EVEN_INC 54
#define SMIAPP_LIMIT_MAX_EVEN_INC 55
#define SMIAPP_LIMIT_MIN_ODD_INC 56
#define SMIAPP_LIMIT_MAX_ODD_INC 57
#define SMIAPP_LIMIT_SCALING_CAPABILITY 58
#define SMIAPP_LIMIT_SCALER_M_MIN 59
#define SMIAPP_LIMIT_SCALER_M_MAX 60
#define SMIAPP_LIMIT_SCALER_N_MIN 61
#define SMIAPP_LIMIT_SCALER_N_MAX 62
#define SMIAPP_LIMIT_SPATIAL_SAMPLING_CAPABILITY 63
#define SMIAPP_LIMIT_DIGITAL_CROP_CAPABILITY 64
#define SMIAPP_LIMIT_COMPRESSION_CAPABILITY 65
#define SMIAPP_LIMIT_FIFO_SUPPORT_CAPABILITY 66
#define SMIAPP_LIMIT_DPHY_CTRL_CAPABILITY 67
#define SMIAPP_LIMIT_CSI_LANE_MODE_CAPABILITY 68
#define SMIAPP_LIMIT_CSI_SIGNALLING_MODE_CAPABILITY 69
#define SMIAPP_LIMIT_FAST_STANDBY_CAPABILITY 70
#define SMIAPP_LIMIT_CCI_ADDRESS_CONTROL_CAPABILITY 71
#define SMIAPP_LIMIT_MAX_PER_LANE_BITRATE_1_LANE_MODE_MBPS 72
#define SMIAPP_LIMIT_MAX_PER_LANE_BITRATE_2_LANE_MODE_MBPS 73
#define SMIAPP_LIMIT_MAX_PER_LANE_BITRATE_3_LANE_MODE_MBPS 74
#define SMIAPP_LIMIT_MAX_PER_LANE_BITRATE_4_LANE_MODE_MBPS 75
#define SMIAPP_LIMIT_TEMP_SENSOR_CAPABILITY 76
#define SMIAPP_LIMIT_MIN_FRAME_LENGTH_LINES_BIN 77
#define SMIAPP_LIMIT_MAX_FRAME_LENGTH_LINES_BIN 78
#define SMIAPP_LIMIT_MIN_LINE_LENGTH_PCK_BIN 79
#define SMIAPP_LIMIT_MAX_LINE_LENGTH_PCK_BIN 80
#define SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN 81
#define SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MIN_BIN 82
#define SMIAPP_LIMIT_FINE_INTEGRATION_TIME_MAX_MARGIN_BIN 83
#define SMIAPP_LIMIT_BINNING_CAPABILITY 84
#define SMIAPP_LIMIT_BINNING_WEIGHTING_CAPABILITY 85
#define SMIAPP_LIMIT_DATA_TRANSFER_IF_CAPABILITY 86
#define SMIAPP_LIMIT_SHADING_CORRECTION_CAPABILITY 87
#define SMIAPP_LIMIT_GREEN_IMBALANCE_CAPABILITY 88
#define SMIAPP_LIMIT_BLACK_LEVEL_CAPABILITY 89
#define SMIAPP_LIMIT_MODULE_SPECIFIC_CORRECTION_CAPABILITY 90
#define SMIAPP_LIMIT_DEFECT_CORRECTION_CAPABILITY 91
#define SMIAPP_LIMIT_DEFECT_CORRECTION_CAPABILITY_2 92
#define SMIAPP_LIMIT_EDOF_CAPABILITY 93
#define SMIAPP_LIMIT_COLOUR_FEEDBACK_CAPABILITY 94
#define SMIAPP_LIMIT_ESTIMATION_MODE_CAPABILITY 95
#define SMIAPP_LIMIT_ESTIMATION_ZONE_CAPABILITY 96
#define SMIAPP_LIMIT_CAPABILITY_TRDY_MIN 97
#define SMIAPP_LIMIT_FLASH_MODE_CAPABILITY 98
#define SMIAPP_LIMIT_ACTUATOR_CAPABILITY 99
#define SMIAPP_LIMIT_BRACKETING_LUT_CAPABILITY_1 100
#define SMIAPP_LIMIT_BRACKETING_LUT_CAPABILITY_2 101
#define SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_STEP 102
#define SMIAPP_LIMIT_LAST 103
/*
* drivers/media/video/smiapp/smiapp-quirk.c
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include "smiapp-debug.h"
#include <linux/delay.h>
#include "smiapp.h"
static int smiapp_write_8(struct smiapp_sensor *sensor, u16 reg, u8 val)
{
struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
return smiapp_write(client, (SMIA_REG_8BIT << 16) | reg, val);
}
static int smiapp_write_8s(struct smiapp_sensor *sensor,
struct smiapp_reg_8 *regs, int len)
{
struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
int rval;
for (; len > 0; len--, regs++) {
rval = smiapp_write_8(sensor, regs->reg, regs->val);
if (rval < 0) {
dev_err(&client->dev,
"error %d writing reg 0x%4.4x, val 0x%2.2x",
rval, regs->reg, regs->val);
return rval;
}
}
return 0;
}
void smiapp_replace_limit(struct smiapp_sensor *sensor,
u32 limit, u32 val)
{
struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
dev_dbg(&client->dev, "quirk: 0x%8.8x \"%s\" = %d, 0x%x\n",
smiapp_reg_limits[limit].addr,
smiapp_reg_limits[limit].what, val, val);
sensor->limits[limit] = val;
}
int smiapp_replace_limit_at(struct smiapp_sensor *sensor,
u32 reg, u32 val)
{
struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
int i;
for (i = 0; smiapp_reg_limits[i].addr; i++) {
if ((smiapp_reg_limits[i].addr & 0xffff) != reg)
continue;
smiapp_replace_limit(sensor, i, val);
return 0;
}
dev_dbg(&client->dev, "quirk: bad register 0x%4.4x\n", reg);
return -EINVAL;
}
static int jt8ew9_limits(struct smiapp_sensor *sensor)
{
if (sensor->minfo.revision_number_major < 0x03)
sensor->frame_skip = 1;
/* Below 24 gain doesn't have effect at all, */
/* but ~59 is needed for full dynamic range */
smiapp_replace_limit(sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN, 59);
smiapp_replace_limit(
sensor, SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX, 6000);
return 0;
}
static int jt8ew9_post_poweron(struct smiapp_sensor *sensor)
{
struct smiapp_reg_8 regs[] = {
{ 0x30a3, 0xd8 }, /* Output port control : LVDS ports only */
{ 0x30ae, 0x00 }, /* 0x0307 pll_multiplier maximum value on PLL input 9.6MHz ( 19.2MHz is divided on pre_pll_div) */
{ 0x30af, 0xd0 }, /* 0x0307 pll_multiplier maximum value on PLL input 9.6MHz ( 19.2MHz is divided on pre_pll_div) */
{ 0x322d, 0x04 }, /* Adjusting Processing Image Size to Scaler Toshiba Recommendation Setting */
{ 0x3255, 0x0f }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
{ 0x3256, 0x15 }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
{ 0x3258, 0x70 }, /* Analog Gain Control Toshiba Recommendation Setting */
{ 0x3259, 0x70 }, /* Analog Gain Control Toshiba Recommendation Setting */
{ 0x325f, 0x7c }, /* Analog Gain Control Toshiba Recommendation Setting */
{ 0x3302, 0x06 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
{ 0x3304, 0x00 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
{ 0x3307, 0x22 }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
{ 0x3308, 0x8d }, /* Pixel Reference Voltage Control Toshiba Recommendation Setting */
{ 0x331e, 0x0f }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
{ 0x3320, 0x30 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
{ 0x3321, 0x11 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
{ 0x3322, 0x98 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
{ 0x3323, 0x64 }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
{ 0x3325, 0x83 }, /* Read Out Timing Control Toshiba Recommendation Setting */
{ 0x3330, 0x18 }, /* Read Out Timing Control Toshiba Recommendation Setting */
{ 0x333c, 0x01 }, /* Read Out Timing Control Toshiba Recommendation Setting */
{ 0x3345, 0x2f }, /* Black Hole Sun Correction Control Toshiba Recommendation Setting */
{ 0x33de, 0x38 }, /* Horizontal Noise Reduction Control Toshiba Recommendation Setting */
/* Taken from v03. No idea what the rest are. */
{ 0x32e0, 0x05 },
{ 0x32e1, 0x05 },
{ 0x32e2, 0x04 },
{ 0x32e5, 0x04 },
{ 0x32e6, 0x04 },
};
return smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
}
const struct smiapp_quirk smiapp_jt8ew9_quirk = {
.limits = jt8ew9_limits,
.post_poweron = jt8ew9_post_poweron,
};
static int imx125es_post_poweron(struct smiapp_sensor *sensor)
{
/* Taken from v02. No idea what the other two are. */
struct smiapp_reg_8 regs[] = {
/*
* 0x3302: clk during frame blanking:
* 0x00 - HS mode, 0x01 - LP11
*/
{ 0x3302, 0x01 },
{ 0x302d, 0x00 },
{ 0x3b08, 0x8c },
};
return smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
}
const struct smiapp_quirk smiapp_imx125es_quirk = {
.post_poweron = imx125es_post_poweron,
};
static int jt8ev1_limits(struct smiapp_sensor *sensor)
{
smiapp_replace_limit(sensor, SMIAPP_LIMIT_X_ADDR_MAX, 4271);
smiapp_replace_limit(sensor,
SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN, 184);
return 0;
}
static int jt8ev1_post_poweron(struct smiapp_sensor *sensor)
{
struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
int rval;
struct smiapp_reg_8 regs[] = {
{ 0x3031, 0xcd }, /* For digital binning (EQ_MONI) */
{ 0x30a3, 0xd0 }, /* FLASH STROBE enable */
{ 0x3237, 0x00 }, /* For control of pulse timing for ADC */
{ 0x3238, 0x43 },
{ 0x3301, 0x06 }, /* For analog bias for sensor */
{ 0x3302, 0x06 },
{ 0x3304, 0x00 },
{ 0x3305, 0x88 },
{ 0x332a, 0x14 },
{ 0x332c, 0x6b },
{ 0x3336, 0x01 },
{ 0x333f, 0x1f },
{ 0x3355, 0x00 },
{ 0x3356, 0x20 },
{ 0x33bf, 0x20 }, /* Adjust the FBC speed */
{ 0x33c9, 0x20 },
{ 0x33ce, 0x30 }, /* Adjust the parameter for logic function */
{ 0x33cf, 0xec }, /* For Black sun */
{ 0x3328, 0x80 }, /* Ugh. No idea what's this. */
};
struct smiapp_reg_8 regs_96[] = {
{ 0x30ae, 0x00 }, /* For control of ADC clock */
{ 0x30af, 0xd0 },
{ 0x30b0, 0x01 },
};
rval = smiapp_write_8s(sensor, regs, ARRAY_SIZE(regs));
if (rval < 0)
return rval;
switch (sensor->platform_data->ext_clk) {
case 9600000:
return smiapp_write_8s(sensor, regs_96,
ARRAY_SIZE(regs_96));
default:
dev_warn(&client->dev, "no MSRs for %d Hz ext_clk\n",
sensor->platform_data->ext_clk);
return 0;
}
}
static int jt8ev1_pre_streamon(struct smiapp_sensor *sensor)
{
return smiapp_write_8(sensor, 0x3328, 0x00);
}
static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)
{
int rval;
/* Workaround: allows fast standby to work properly */
rval = smiapp_write_8(sensor, 0x3205, 0x04);
if (rval < 0)
return rval;
/* Wait for 1 ms + one line => 2 ms is likely enough */
usleep_range(2000, 2000);
/* Restore it */
rval = smiapp_write_8(sensor, 0x3205, 0x00);
if (rval < 0)
return rval;
return smiapp_write_8(sensor, 0x3328, 0x80);
}
const struct smiapp_quirk smiapp_jt8ev1_quirk = {
.limits = jt8ev1_limits,
.post_poweron = jt8ev1_post_poweron,
.pre_streamon = jt8ev1_pre_streamon,
.post_streamoff = jt8ev1_post_streamoff,
.flags = SMIAPP_QUIRK_FLAG_OP_PIX_CLOCK_PER_LANE,
};
static int tcm8500md_limits(struct smiapp_sensor *sensor)
{
smiapp_replace_limit(sensor, SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ, 2700000);
return 0;
}
const struct smiapp_quirk smiapp_tcm8500md_quirk = {
.limits = tcm8500md_limits,
};
/*
* drivers/media/video/smiapp/smiapp-quirk.h
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef __SMIAPP_QUIRK__
#define __SMIAPP_QUIRK__
struct smiapp_sensor;
/**
* struct smiapp_quirk - quirks for sensors that deviate from SMIA++ standard
*
* @limits: Replace sensor->limits with values which can't be read from
* sensor registers. Called the first time the sensor is powered up.
* @post_poweron: Called always after the sensor has been fully powered on.
* @pre_streamon: Called just before streaming is enabled.
* @post_streamon: Called right after stopping streaming.
*/
struct smiapp_quirk {
int (*limits)(struct smiapp_sensor *sensor);
int (*post_poweron)(struct smiapp_sensor *sensor);
int (*pre_streamon)(struct smiapp_sensor *sensor);
int (*post_streamoff)(struct smiapp_sensor *sensor);
unsigned long flags;
};
/* op pix clock is for all lanes in total normally */
#define SMIAPP_QUIRK_FLAG_OP_PIX_CLOCK_PER_LANE (1 << 0)
struct smiapp_reg_8 {
u16 reg;
u8 val;
};
void smiapp_replace_limit(struct smiapp_sensor *sensor,
u32 limit, u32 val);
#define smiapp_call_quirk(_sensor, _quirk, ...) \
(_sensor->minfo.quirk && \
_sensor->minfo.quirk->_quirk ? \
_sensor->minfo.quirk->_quirk(_sensor, ##__VA_ARGS__) : 0)
#define smiapp_needs_quirk(_sensor, _quirk) \
(_sensor->minfo.quirk ? \
_sensor->minfo.quirk->flags & _quirk : 0)
extern const struct smiapp_quirk smiapp_jt8ev1_quirk;
extern const struct smiapp_quirk smiapp_imx125es_quirk;
extern const struct smiapp_quirk smiapp_jt8ew9_quirk;
extern const struct smiapp_quirk smiapp_tcm8500md_quirk;
#endif /* __SMIAPP_QUIRK__ */
This diff is collapsed.
/*
* drivers/media/video/smiapp/smiapp-reg.h
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef __SMIAPP_REG_H_
#define __SMIAPP_REG_H_
#include "smiapp-reg-defs.h"
/* Bits for above register */
#define SMIAPP_IMAGE_ORIENTATION_HFLIP (1 << 0)
#define SMIAPP_IMAGE_ORIENTATION_VFLIP (1 << 1)
#define SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN (1 << 0)
#define SMIAPP_DATA_TRANSFER_IF_1_CTRL_RD_EN (0 << 1)
#define SMIAPP_DATA_TRANSFER_IF_1_CTRL_WR_EN (1 << 1)
#define SMIAPP_DATA_TRANSFER_IF_1_CTRL_ERR_CLEAR (1 << 2)
#define SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY (1 << 0)
#define SMIAPP_DATA_TRANSFER_IF_1_STATUS_WR_READY (1 << 1)
#define SMIAPP_DATA_TRANSFER_IF_1_STATUS_EDATA (1 << 2)
#define SMIAPP_DATA_TRANSFER_IF_1_STATUS_EUSAGE (1 << 3)
#define SMIAPP_SOFTWARE_RESET (1 << 0)
#define SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE (1 << 0)
#define SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE (1 << 1)
#define SMIAPP_DPHY_CTRL_AUTOMATIC 0
/* DPHY control based on REQUESTED_LINK_BIT_RATE_MBPS */
#define SMIAPP_DPHY_CTRL_UI 1
#define SMIAPP_DPHY_CTRL_REGISTER 2
#define SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR 1
#define SMIAPP_COMPRESSION_MODE_ADVANCED_PREDICTOR 2
#define SMIAPP_MODE_SELECT_SOFTWARE_STANDBY 0
#define SMIAPP_MODE_SELECT_STREAMING 1
#define SMIAPP_SCALING_MODE_NONE 0
#define SMIAPP_SCALING_MODE_HORIZONTAL 1
#define SMIAPP_SCALING_MODE_BOTH 2
#define SMIAPP_SCALING_CAPABILITY_NONE 0
#define SMIAPP_SCALING_CAPABILITY_HORIZONTAL 1
#define SMIAPP_SCALING_CAPABILITY_BOTH 2 /* horizontal/both */
/* digital crop right before scaler */
#define SMIAPP_DIGITAL_CROP_CAPABILITY_NONE 0
#define SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP 1
#define SMIAPP_BINNING_CAPABILITY_NO 0
#define SMIAPP_BINNING_CAPABILITY_YES 1
/* Maximum number of binning subtypes */
#define SMIAPP_BINNING_SUBTYPES 253
#define SMIAPP_PIXEL_ORDER_GRBG 0
#define SMIAPP_PIXEL_ORDER_RGGB 1
#define SMIAPP_PIXEL_ORDER_BGGR 2
#define SMIAPP_PIXEL_ORDER_GBRG 3
#define SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL 1
#define SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED 2
#define SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL_N 8
#define SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED_N 16
#define SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE 0x01
#define SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE 0x02
#define SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NROWS_MASK 0x0f
#define SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_MASK 0xf0
#define SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_SHIFT 4
#define SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_MASK 0xf000
#define SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_SHIFT 12
#define SMIAPP_FRAME_FORMAT_DESC_2_PIXELS_MASK 0x0fff
#define SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_MASK 0xf0000000
#define SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_SHIFT 28
#define SMIAPP_FRAME_FORMAT_DESC_4_PIXELS_MASK 0x0000ffff
#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED 1
#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DUMMY 2
#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_BLACK 3
#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DARK 4
#define SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE 5
#define SMIAPP_FAST_STANDBY_CTRL_COMPLETE_FRAMES 0
#define SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE 1
/* Scaling N factor */
#define SMIAPP_SCALE_N 16
/* Image statistics registers */
/* Registers 0x2000 to 0x2fff are reserved for future
* use for statistics features.
*/
/* Manufacturer Specific Registers: 0x3000 to 0x3fff
* The manufacturer specifies these as a black box.
*/
#endif /* __SMIAPP_REG_H_ */
/*
* drivers/media/video/smiapp/smiapp-regs.c
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include "smiapp-debug.h"
#include <linux/delay.h>
#include <linux/i2c.h>
#include "smiapp-regs.h"
static uint32_t float_to_u32_mul_1000000(struct i2c_client *client,
uint32_t phloat)
{
int32_t exp;
uint64_t man;
if (phloat >= 0x80000000) {
dev_err(&client->dev, "this is a negative number\n");
return 0;
}
if (phloat == 0x7f800000)
return ~0; /* Inf. */
if ((phloat & 0x7f800000) == 0x7f800000) {
dev_err(&client->dev, "NaN or other special number\n");
return 0;
}
/* Valid cases begin here */
if (phloat == 0)
return 0; /* Valid zero */
if (phloat > 0x4f800000)
return ~0; /* larger than 4294967295 */
/*
* Unbias exponent (note how phloat is now guaranteed to
* have 0 in the high bit)
*/
exp = ((int32_t)phloat >> 23) - 127;
/* Extract mantissa, add missing '1' bit and it's in MHz */
man = ((phloat & 0x7fffff) | 0x800000) * 1000000ULL;
if (exp < 0)
man >>= -exp;
else
man <<= exp;
man >>= 23; /* Remove mantissa bias */
return man & 0xffffffff;
}
/*
* Read a 8/16/32-bit i2c register. The value is returned in 'val'.
* Returns zero if successful, or non-zero otherwise.
*/
int smiapp_read(struct i2c_client *client, u32 reg, u32 *val)
{
struct i2c_msg msg;
unsigned char data[4];
unsigned int len = (u8)(reg >> 16);
u16 offset = reg;
int r;
if (len != SMIA_REG_8BIT && len != SMIA_REG_16BIT
&& len != SMIA_REG_32BIT)
return -EINVAL;
msg.addr = client->addr;
msg.flags = 0;
msg.len = 2;
msg.buf = data;
/* high byte goes out first */
data[0] = (u8) (offset >> 8);
data[1] = (u8) offset;
r = i2c_transfer(client->adapter, &msg, 1);
if (r != 1) {
if (r >= 0)
r = -EBUSY;
goto err;
}
msg.len = len;
msg.flags = I2C_M_RD;
r = i2c_transfer(client->adapter, &msg, 1);
if (r != 1) {
if (r >= 0)
r = -EBUSY;
goto err;
}
*val = 0;
/* high byte comes first */
switch (len) {
case SMIA_REG_32BIT:
*val = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) +
data[3];
break;
case SMIA_REG_16BIT:
*val = (data[0] << 8) + data[1];
break;
case SMIA_REG_8BIT:
*val = data[0];
break;
default:
BUG();
}
if (reg & SMIA_REG_FLAG_FLOAT)
*val = float_to_u32_mul_1000000(client, *val);
return 0;
err:
dev_err(&client->dev, "read from offset 0x%x error %d\n", offset, r);
return r;
}
/*
* Write to a 8/16-bit register.
* Returns zero if successful, or non-zero otherwise.
*/
int smiapp_write(struct i2c_client *client, u32 reg, u32 val)
{
struct i2c_msg msg;
unsigned char data[6];
unsigned int retries;
unsigned int flags = reg >> 24;
unsigned int len = (u8)(reg >> 16);
u16 offset = reg;
int r;
if ((len != SMIA_REG_8BIT && len != SMIA_REG_16BIT &&
len != SMIA_REG_32BIT) || flags)
return -EINVAL;
msg.addr = client->addr;
msg.flags = 0; /* Write */
msg.len = 2 + len;
msg.buf = data;
/* high byte goes out first */
data[0] = (u8) (reg >> 8);
data[1] = (u8) (reg & 0xff);
switch (len) {
case SMIA_REG_8BIT:
data[2] = val;
break;
case SMIA_REG_16BIT:
data[2] = val >> 8;
data[3] = val;
break;
case SMIA_REG_32BIT:
data[2] = val >> 24;
data[3] = val >> 16;
data[4] = val >> 8;
data[5] = val;
break;
default:
BUG();
}
for (retries = 0; retries < 5; retries++) {
/*
* Due to unknown reason sensor stops responding. This
* loop is a temporaty solution until the root cause
* is found.
*/
r = i2c_transfer(client->adapter, &msg, 1);
if (r == 1) {
if (retries)
dev_err(&client->dev,
"sensor i2c stall encountered. "
"retries: %d\n", retries);
return 0;
}
usleep_range(2000, 2000);
}
dev_err(&client->dev,
"wrote 0x%x to offset 0x%x error %d\n", val, offset, r);
return r;
}
/*
* include/media/smiapp/smiapp-regs.h
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef SMIAPP_REGS_H
#define SMIAPP_REGS_H
#include <linux/i2c.h>
#include <linux/types.h>
/* Use upper 8 bits of the type field for flags */
#define SMIA_REG_FLAG_FLOAT (1 << 24)
#define SMIA_REG_8BIT 1
#define SMIA_REG_16BIT 2
#define SMIA_REG_32BIT 4
struct smia_reg {
u16 type;
u16 reg; /* 16-bit offset */
u32 val; /* 8/16/32-bit value */
};
int smiapp_read(struct i2c_client *client, u32 reg, u32 *val);
int smiapp_write(struct i2c_client *client, u32 reg, u32 val);
#endif
/*
* drivers/media/video/smiapp/smiapp.h
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2010--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef __SMIAPP_PRIV_H_
#define __SMIAPP_PRIV_H_
#include <linux/mutex.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-subdev.h>
#include <media/smiapp.h>
#include "../smiapp-pll.h"
#include "smiapp-reg.h"
#include "smiapp-regs.h"
#include "smiapp-quirk.h"
/*
* Standard SMIA++ constants
*/
#define SMIA_VERSION_1 10
#define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */
#define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */
#define SMIAPP_VERSION_1 10
#define SMIAPP_PROFILE_0 0
#define SMIAPP_PROFILE_1 1
#define SMIAPP_PROFILE_2 2
#define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */
#define SMIAPP_RESET_DELAY_CLOCKS 2400
#define SMIAPP_RESET_DELAY(clk) \
(1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \
+ (clk) / 1000 - 1) / ((clk) / 1000))
#include "smiapp-limits.h"
struct smiapp_quirk;
#define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)
struct smiapp_module_ident {
u8 manufacturer_id;
u16 model_id;
u8 revision_number_major;
u8 flags;
char *name;
const struct smiapp_quirk *quirk;
};
struct smiapp_module_info {
u32 manufacturer_id;
u32 model_id;
u32 revision_number_major;
u32 revision_number_minor;
u32 module_year;
u32 module_month;
u32 module_day;
u32 sensor_manufacturer_id;
u32 sensor_model_id;
u32 sensor_revision_number;
u32 sensor_firmware_version;
u32 smia_version;
u32 smiapp_version;
u32 smiapp_profile;
char *name;
const struct smiapp_quirk *quirk;
};
#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \
{ .manufacturer_id = manufacturer, \
.model_id = model, \
.revision_number_major = rev, \
.flags = fl, \
.name = _name, \
.quirk = _quirk, }
#define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \
{ .manufacturer_id = manufacturer, \
.model_id = model, \
.revision_number_major = rev, \
.flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
.name = _name, \
.quirk = _quirk, }
#define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \
{ .manufacturer_id = manufacturer, \
.model_id = model, \
.revision_number_major = rev, \
.flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
.name = _name, }
#define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \
{ .manufacturer_id = manufacturer, \
.model_id = model, \
.revision_number_major = rev, \
.flags = 0, \
.name = _name, \
.quirk = _quirk, }
#define SMIAPP_IDENT(manufacturer, model, rev, _name) \
{ .manufacturer_id = manufacturer, \
.model_id = model, \
.revision_number_major = rev, \
.flags = 0, \
.name = _name, }
struct smiapp_reg_limits {
u32 addr;
char *what;
};
extern struct smiapp_reg_limits smiapp_reg_limits[];
struct smiapp_csi_data_format {
u32 code;
u8 width;
u8 compressed;
u8 pixel_order;
};
#define SMIAPP_SUBDEVS 3
#define SMIAPP_PA_PAD_SRC 0
#define SMIAPP_PAD_SINK 0
#define SMIAPP_PAD_SRC 1
#define SMIAPP_PADS 2
struct smiapp_binning_subtype {
u8 horizontal:4;
u8 vertical:4;
} __packed;
struct smiapp_subdev {
struct v4l2_subdev sd;
struct media_pad pads[2];
struct v4l2_rect sink_fmt;
struct v4l2_rect crop[2];
struct v4l2_rect compose; /* compose on sink */
unsigned short sink_pad;
unsigned short source_pad;
int npads;
struct smiapp_sensor *sensor;
struct v4l2_ctrl_handler ctrl_handler;
};
/*
* struct smiapp_sensor - Main device structure
*/
struct smiapp_sensor {
/*
* "mutex" is used to serialise access to all fields here
* except v4l2_ctrls at the end of the struct. "mutex" is also
* used to serialise access to file handle specific
* information. The exception to this rule is the power_mutex
* below.
*/
struct mutex mutex;
/*
* power_mutex is used to serialise power management related
* activities. Acquiring "mutex" at that time isn't necessary
* since there are no other users anyway.
*/
struct mutex power_mutex;
struct smiapp_subdev ssds[SMIAPP_SUBDEVS];
u32 ssds_used;
struct smiapp_subdev *src;
struct smiapp_subdev *binner;
struct smiapp_subdev *scaler;
struct smiapp_subdev *pixel_array;
struct smiapp_platform_data *platform_data;
struct regulator *vana;
u32 limits[SMIAPP_LIMIT_LAST];
u8 nbinning_subtypes;
struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
u32 mbus_frame_fmts;
const struct smiapp_csi_data_format *csi_format;
const struct smiapp_csi_data_format *internal_csi_format;
u32 default_mbus_frame_fmts;
int default_pixel_order;
u8 binning_horizontal;
u8 binning_vertical;
u8 scale_m;
u8 scaling_mode;
u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
u8 flash_capability;
u8 frame_skip;
int power_count;
bool streaming;
bool dev_init_done;
u8 *nvm; /* nvm memory buffer */
unsigned int nvm_size; /* bytes */
struct smiapp_module_info minfo;
struct smiapp_pll pll;
/* Pixel array controls */
struct v4l2_ctrl *analog_gain;
struct v4l2_ctrl *exposure;
struct v4l2_ctrl *hflip;
struct v4l2_ctrl *vflip;
struct v4l2_ctrl *vblank;
struct v4l2_ctrl *hblank;
struct v4l2_ctrl *pixel_rate_parray;
/* src controls */
struct v4l2_ctrl *link_freq;
struct v4l2_ctrl *pixel_rate_csi;
};
#define to_smiapp_subdev(_sd) \
container_of(_sd, struct smiapp_subdev, sd)
#define to_smiapp_sensor(_sd) \
(to_smiapp_subdev(_sd)->sensor)
#endif /* __SMIAPP_PRIV_H_ */
/*
* include/media/smiapp.h
*
* Generic driver for SMIA/SMIA++ compliant camera modules
*
* Copyright (C) 2011--2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef __SMIAPP_H_
#define __SMIAPP_H_
#include <media/v4l2-subdev.h>
#define SMIAPP_NAME "smiapp"
#define SMIAPP_DFL_I2C_ADDR (0x20 >> 1) /* Default I2C Address */
#define SMIAPP_ALT_I2C_ADDR (0x6e >> 1) /* Alternate I2C Address */
#define SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_CLOCK 0
#define SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_STROBE 1
#define SMIAPP_CSI_SIGNALLING_MODE_CSI2 2
#define SMIAPP_NO_XSHUTDOWN -1
/*
* Sometimes due to board layout considerations the camera module can be
* mounted rotated. The typical rotation used is 180 degrees which can be
* corrected by giving a default H-FLIP and V-FLIP in the sensor readout.
* FIXME: rotation also changes the bayer pattern.
*/
enum smiapp_module_board_orient {
SMIAPP_MODULE_BOARD_ORIENT_0 = 0,
SMIAPP_MODULE_BOARD_ORIENT_180,
};
struct smiapp_flash_strobe_parms {
u8 mode;
u32 strobe_width_high_us;
u16 strobe_delay;
u16 stobe_start_point;
u8 trigger;
};
struct smiapp_platform_data {
/*
* Change the cci address if i2c_addr_alt is set.
* Both default and alternate cci addr need to be present
*/
unsigned short i2c_addr_dfl; /* Default i2c addr */
unsigned short i2c_addr_alt; /* Alternate i2c addr */
unsigned int nvm_size; /* bytes */
unsigned int ext_clk; /* sensor external clk */
unsigned int lanes; /* Number of CSI-2 lanes */
u8 csi_signalling_mode; /* SMIAPP_CSI_SIGNALLING_MODE_* */
const s64 *op_sys_clock;
enum smiapp_module_board_orient module_board_orient;
struct smiapp_flash_strobe_parms *strobe_setup;
int (*set_xclk)(struct v4l2_subdev *sd, int hz);
int xshutdown; /* gpio or SMIAPP_NO_XSHUTDOWN */
};
#endif /* __SMIAPP_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment