18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Samsung LSI S5C73M3 8M pixel camera driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2012, Samsung Electronics, Co., Ltd.
68c2ecf20Sopenharmony_ci * Sylwester Nawrocki <s.nawrocki@samsung.com>
78c2ecf20Sopenharmony_ci * Andrzej Hajda <a.hajda@samsung.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef S5C73M3_H_
108c2ecf20Sopenharmony_ci#define S5C73M3_H_
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/clk.h>
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
158c2ecf20Sopenharmony_ci#include <media/v4l2-common.h>
168c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h>
178c2ecf20Sopenharmony_ci#include <media/v4l2-subdev.h>
188c2ecf20Sopenharmony_ci#include <media/i2c/s5c73m3.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define DRIVER_NAME			"S5C73M3"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define S5C73M3_ISP_FMT			MEDIA_BUS_FMT_VYUY8_2X8
238c2ecf20Sopenharmony_ci#define S5C73M3_JPEG_FMT		MEDIA_BUS_FMT_S5C_UYVY_JPEG_1X8
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Subdevs pad index definitions */
268c2ecf20Sopenharmony_cienum s5c73m3_pads {
278c2ecf20Sopenharmony_ci	S5C73M3_ISP_PAD,
288c2ecf20Sopenharmony_ci	S5C73M3_JPEG_PAD,
298c2ecf20Sopenharmony_ci	S5C73M3_NUM_PADS
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cienum s5c73m3_oif_pads {
338c2ecf20Sopenharmony_ci	OIF_ISP_PAD,
348c2ecf20Sopenharmony_ci	OIF_JPEG_PAD,
358c2ecf20Sopenharmony_ci	OIF_SOURCE_PAD,
368c2ecf20Sopenharmony_ci	OIF_NUM_PADS
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define S5C73M3_SENSOR_FW_LEN		6
408c2ecf20Sopenharmony_ci#define S5C73M3_SENSOR_TYPE_LEN		12
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define S5C73M3_REG(_addrh, _addrl) (((_addrh) << 16) | _addrl)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define AHB_MSB_ADDR_PTR			0xfcfc
458c2ecf20Sopenharmony_ci#define REG_CMDWR_ADDRH				0x0050
468c2ecf20Sopenharmony_ci#define REG_CMDWR_ADDRL				0x0054
478c2ecf20Sopenharmony_ci#define REG_CMDRD_ADDRH				0x0058
488c2ecf20Sopenharmony_ci#define REG_CMDRD_ADDRL				0x005c
498c2ecf20Sopenharmony_ci#define REG_CMDBUF_ADDR				0x0f14
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define REG_I2C_SEQ_STATUS			S5C73M3_REG(0x0009, 0x59A6)
528c2ecf20Sopenharmony_ci#define  SEQ_END_PLL				(1<<0x0)
538c2ecf20Sopenharmony_ci#define  SEQ_END_SENSOR				(1<<0x1)
548c2ecf20Sopenharmony_ci#define  SEQ_END_GPIO				(1<<0x2)
558c2ecf20Sopenharmony_ci#define  SEQ_END_FROM				(1<<0x3)
568c2ecf20Sopenharmony_ci#define  SEQ_END_STABLE_AE_AWB			(1<<0x4)
578c2ecf20Sopenharmony_ci#define  SEQ_END_READY_I2C_CMD			(1<<0x5)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define REG_I2C_STATUS				S5C73M3_REG(0x0009, 0x599E)
608c2ecf20Sopenharmony_ci#define  I2C_STATUS_CIS_I2C			(1<<0x0)
618c2ecf20Sopenharmony_ci#define  I2C_STATUS_AF_INIT			(1<<0x1)
628c2ecf20Sopenharmony_ci#define  I2C_STATUS_CAL_DATA			(1<<0x2)
638c2ecf20Sopenharmony_ci#define  I2C_STATUS_FRAME_COUNT			(1<<0x3)
648c2ecf20Sopenharmony_ci#define  I2C_STATUS_FROM_INIT			(1<<0x4)
658c2ecf20Sopenharmony_ci#define  I2C_STATUS_I2C_CIS_STREAM_OFF		(1<<0x5)
668c2ecf20Sopenharmony_ci#define  I2C_STATUS_I2C_N_CMD_OVER		(1<<0x6)
678c2ecf20Sopenharmony_ci#define  I2C_STATUS_I2C_N_CMD_MISMATCH		(1<<0x7)
688c2ecf20Sopenharmony_ci#define  I2C_STATUS_CHECK_BIN_CRC		(1<<0x8)
698c2ecf20Sopenharmony_ci#define  I2C_STATUS_EXCEPTION			(1<<0x9)
708c2ecf20Sopenharmony_ci#define  I2C_STATUS_INIF_INIT_STATE		(0x8)
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#define REG_STATUS				S5C73M3_REG(0x0009, 0x5080)
738c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_SUB_MAIN_ENTER		0xff01
748c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_SRAM_TIMING_OK		0xff02
758c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_INTERRUPTS_EN		0xff03
768c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_R_PLL_DONE		0xff04
778c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_R_PLL_LOCKTIME_DONE	0xff05
788c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_DELAY_COUNT_DONE	0xff06
798c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_I_PLL_DONE		0xff07
808c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_I_PLL_LOCKTIME_DONE	0xff08
818c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_PLL_INIT_OK		0xff09
828c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_SENSOR_INIT_OK		0xff0a
838c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_GPIO_SETTING_OK	0xff0b
848c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_READ_CAL_DATA_OK	0xff0c
858c2ecf20Sopenharmony_ci#define  REG_STATUS_BOOT_STABLE_AE_AWB_OK	0xff0d
868c2ecf20Sopenharmony_ci#define  REG_STATUS_ISP_COMMAND_COMPLETED	0xffff
878c2ecf20Sopenharmony_ci#define  REG_STATUS_EXCEPTION_OCCURED		0xdead
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define COMM_RESULT_OFFSET			S5C73M3_REG(0x0009, 0x5000)
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define COMM_IMG_OUTPUT				0x0902
928c2ecf20Sopenharmony_ci#define  COMM_IMG_OUTPUT_HDR			0x0008
938c2ecf20Sopenharmony_ci#define  COMM_IMG_OUTPUT_YUV			0x0009
948c2ecf20Sopenharmony_ci#define  COMM_IMG_OUTPUT_INTERLEAVED		0x000d
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define COMM_STILL_PRE_FLASH			0x0a00
978c2ecf20Sopenharmony_ci#define  COMM_STILL_PRE_FLASH_FIRE		0x0000
988c2ecf20Sopenharmony_ci#define  COMM_STILL_PRE_FLASH_NON_FIRED		0x0000
998c2ecf20Sopenharmony_ci#define  COMM_STILL_PRE_FLASH_FIRED		0x0001
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define COMM_STILL_MAIN_FLASH			0x0a02
1028c2ecf20Sopenharmony_ci#define  COMM_STILL_MAIN_FLASH_CANCEL		0x0001
1038c2ecf20Sopenharmony_ci#define  COMM_STILL_MAIN_FLASH_FIRE		0x0002
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define COMM_ZOOM_STEP				0x0b00
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define COMM_IMAGE_EFFECT			0x0b0a
1088c2ecf20Sopenharmony_ci#define  COMM_IMAGE_EFFECT_NONE			0x0001
1098c2ecf20Sopenharmony_ci#define  COMM_IMAGE_EFFECT_NEGATIVE		0x0002
1108c2ecf20Sopenharmony_ci#define  COMM_IMAGE_EFFECT_AQUA			0x0003
1118c2ecf20Sopenharmony_ci#define  COMM_IMAGE_EFFECT_SEPIA		0x0004
1128c2ecf20Sopenharmony_ci#define  COMM_IMAGE_EFFECT_MONO			0x0005
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define COMM_IMAGE_QUALITY			0x0b0c
1158c2ecf20Sopenharmony_ci#define  COMM_IMAGE_QUALITY_SUPERFINE		0x0000
1168c2ecf20Sopenharmony_ci#define  COMM_IMAGE_QUALITY_FINE		0x0001
1178c2ecf20Sopenharmony_ci#define  COMM_IMAGE_QUALITY_NORMAL		0x0002
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#define COMM_FLASH_MODE				0x0b0e
1208c2ecf20Sopenharmony_ci#define  COMM_FLASH_MODE_OFF			0x0000
1218c2ecf20Sopenharmony_ci#define  COMM_FLASH_MODE_ON			0x0001
1228c2ecf20Sopenharmony_ci#define  COMM_FLASH_MODE_AUTO			0x0002
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci#define COMM_FLASH_STATUS			0x0b80
1258c2ecf20Sopenharmony_ci#define  COMM_FLASH_STATUS_OFF			0x0001
1268c2ecf20Sopenharmony_ci#define  COMM_FLASH_STATUS_ON			0x0002
1278c2ecf20Sopenharmony_ci#define  COMM_FLASH_STATUS_AUTO			0x0003
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define COMM_FLASH_TORCH			0x0b12
1308c2ecf20Sopenharmony_ci#define  COMM_FLASH_TORCH_OFF			0x0000
1318c2ecf20Sopenharmony_ci#define  COMM_FLASH_TORCH_ON			0x0001
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define COMM_AE_NEEDS_FLASH			0x0cba
1348c2ecf20Sopenharmony_ci#define  COMM_AE_NEEDS_FLASH_OFF		0x0000
1358c2ecf20Sopenharmony_ci#define  COMM_AE_NEEDS_FLASH_ON			0x0001
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define COMM_CHG_MODE				0x0b10
1388c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_NEW			0x8000
1398c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_SUBSAMPLING_HALF		0x2000
1408c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_SUBSAMPLING_QUARTER	0x4000
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_320_240		0x0001
1438c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_640_480		0x0002
1448c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_880_720		0x0003
1458c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_960_720		0x0004
1468c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_1184_666		0x0005
1478c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_1280_720		0x0006
1488c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_1536_864		0x0007
1498c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_1600_1200		0x0008
1508c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_1632_1224		0x0009
1518c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_1920_1080		0x000a
1528c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_1920_1440		0x000b
1538c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_2304_1296		0x000c
1548c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_3264_2448		0x000d
1558c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_352_288		0x000e
1568c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_YUV_1008_672		0x000f
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_640_480		0x0010
1598c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_800_450		0x0020
1608c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_800_600		0x0030
1618c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_1280_720		0x0040
1628c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_1280_960		0x0050
1638c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_1600_900		0x0060
1648c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_1600_1200		0x0070
1658c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_2048_1152		0x0080
1668c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_2048_1536		0x0090
1678c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_2560_1440		0x00a0
1688c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_2560_1920		0x00b0
1698c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_3264_2176		0x00c0
1708c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_1024_768		0x00d0
1718c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_3264_1836		0x00e0
1728c2ecf20Sopenharmony_ci#define  COMM_CHG_MODE_JPEG_3264_2448		0x00f0
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#define COMM_AF_CON				0x0e00
1758c2ecf20Sopenharmony_ci#define  COMM_AF_CON_STOP			0x0000
1768c2ecf20Sopenharmony_ci#define  COMM_AF_CON_SCAN			0x0001 /* Full Search */
1778c2ecf20Sopenharmony_ci#define  COMM_AF_CON_START			0x0002 /* Fast Search */
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci#define COMM_AF_CAL				0x0e06
1808c2ecf20Sopenharmony_ci#define COMM_AF_TOUCH_AF			0x0e0a
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci#define REG_AF_STATUS				S5C73M3_REG(0x0009, 0x5e80)
1838c2ecf20Sopenharmony_ci#define  REG_CAF_STATUS_FIND_SEARCH_DIR		0x0001
1848c2ecf20Sopenharmony_ci#define  REG_CAF_STATUS_FOCUSING		0x0002
1858c2ecf20Sopenharmony_ci#define  REG_CAF_STATUS_FOCUSED			0x0003
1868c2ecf20Sopenharmony_ci#define  REG_CAF_STATUS_UNFOCUSED		0x0004
1878c2ecf20Sopenharmony_ci#define  REG_AF_STATUS_INVALID			0x0010
1888c2ecf20Sopenharmony_ci#define  REG_AF_STATUS_FOCUSING			0x0020
1898c2ecf20Sopenharmony_ci#define  REG_AF_STATUS_FOCUSED			0x0030
1908c2ecf20Sopenharmony_ci#define  REG_AF_STATUS_UNFOCUSED		0x0040
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci#define REG_AF_TOUCH_POSITION			S5C73M3_REG(0x0009, 0x5e8e)
1938c2ecf20Sopenharmony_ci#define COMM_AF_FACE_ZOOM			0x0e10
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#define COMM_AF_MODE				0x0e02
1968c2ecf20Sopenharmony_ci#define  COMM_AF_MODE_NORMAL			0x0000
1978c2ecf20Sopenharmony_ci#define  COMM_AF_MODE_MACRO			0x0001
1988c2ecf20Sopenharmony_ci#define  COMM_AF_MODE_MOVIE_CAF_START		0x0002
1998c2ecf20Sopenharmony_ci#define  COMM_AF_MODE_MOVIE_CAF_STOP		0x0003
2008c2ecf20Sopenharmony_ci#define  COMM_AF_MODE_PREVIEW_CAF_START		0x0004
2018c2ecf20Sopenharmony_ci#define  COMM_AF_MODE_PREVIEW_CAF_STOP		0x0005
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci#define COMM_AF_SOFTLANDING			0x0e16
2048c2ecf20Sopenharmony_ci#define  COMM_AF_SOFTLANDING_ON			0x0000
2058c2ecf20Sopenharmony_ci#define  COMM_AF_SOFTLANDING_RES_COMPLETE	0x0001
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci#define COMM_FACE_DET				0x0e0c
2088c2ecf20Sopenharmony_ci#define  COMM_FACE_DET_OFF			0x0000
2098c2ecf20Sopenharmony_ci#define  COMM_FACE_DET_ON			0x0001
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci#define COMM_FACE_DET_OSD			0x0e0e
2128c2ecf20Sopenharmony_ci#define  COMM_FACE_DET_OSD_OFF			0x0000
2138c2ecf20Sopenharmony_ci#define  COMM_FACE_DET_OSD_ON			0x0001
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci#define COMM_AE_CON				0x0c00
2168c2ecf20Sopenharmony_ci#define  COMM_AE_STOP				0x0000 /* lock */
2178c2ecf20Sopenharmony_ci#define  COMM_AE_START				0x0001 /* unlock */
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci#define COMM_ISO				0x0c02
2208c2ecf20Sopenharmony_ci#define  COMM_ISO_AUTO				0x0000
2218c2ecf20Sopenharmony_ci#define  COMM_ISO_100				0x0001
2228c2ecf20Sopenharmony_ci#define  COMM_ISO_200				0x0002
2238c2ecf20Sopenharmony_ci#define  COMM_ISO_400				0x0003
2248c2ecf20Sopenharmony_ci#define  COMM_ISO_800				0x0004
2258c2ecf20Sopenharmony_ci#define  COMM_ISO_SPORTS			0x0005
2268c2ecf20Sopenharmony_ci#define  COMM_ISO_NIGHT				0x0006
2278c2ecf20Sopenharmony_ci#define  COMM_ISO_INDOOR			0x0007
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci/* 0x00000 (-2.0 EV)...0x0008 (2.0 EV), 0.5EV step */
2308c2ecf20Sopenharmony_ci#define COMM_EV					0x0c04
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci#define COMM_METERING				0x0c06
2338c2ecf20Sopenharmony_ci#define  COMM_METERING_CENTER			0x0000
2348c2ecf20Sopenharmony_ci#define  COMM_METERING_SPOT			0x0001
2358c2ecf20Sopenharmony_ci#define  COMM_METERING_AVERAGE			0x0002
2368c2ecf20Sopenharmony_ci#define  COMM_METERING_SMART			0x0003
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci#define COMM_WDR				0x0c08
2398c2ecf20Sopenharmony_ci#define  COMM_WDR_OFF				0x0000
2408c2ecf20Sopenharmony_ci#define  COMM_WDR_ON				0x0001
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci#define COMM_FLICKER_MODE			0x0c12
2438c2ecf20Sopenharmony_ci#define  COMM_FLICKER_NONE			0x0000
2448c2ecf20Sopenharmony_ci#define  COMM_FLICKER_MANUAL_50HZ		0x0001
2458c2ecf20Sopenharmony_ci#define  COMM_FLICKER_MANUAL_60HZ		0x0002
2468c2ecf20Sopenharmony_ci#define  COMM_FLICKER_AUTO			0x0003
2478c2ecf20Sopenharmony_ci#define  COMM_FLICKER_AUTO_50HZ			0x0004
2488c2ecf20Sopenharmony_ci#define  COMM_FLICKER_AUTO_60HZ			0x0005
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci#define COMM_FRAME_RATE				0x0c1e
2518c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_AUTO_SET		0x0000
2528c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_FIXED_30FPS		0x0002
2538c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_FIXED_20FPS		0x0003
2548c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_FIXED_15FPS		0x0004
2558c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_FIXED_60FPS		0x0007
2568c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_FIXED_120FPS		0x0008
2578c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_FIXED_7FPS		0x0009
2588c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_FIXED_10FPS		0x000a
2598c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_FIXED_90FPS		0x000b
2608c2ecf20Sopenharmony_ci#define  COMM_FRAME_RATE_ANTI_SHAKE		0x0013
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci/* 0x0000...0x0004 -> sharpness: 0, 1, 2, -1, -2 */
2638c2ecf20Sopenharmony_ci#define COMM_SHARPNESS				0x0c14
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/* 0x0000...0x0004 -> saturation: 0, 1, 2, -1, -2 */
2668c2ecf20Sopenharmony_ci#define COMM_SATURATION				0x0c16
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci/* 0x0000...0x0004 -> contrast: 0, 1, 2, -1, -2 */
2698c2ecf20Sopenharmony_ci#define COMM_CONTRAST				0x0c18
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci#define COMM_SCENE_MODE				0x0c1a
2728c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_NONE			0x0000
2738c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_PORTRAIT		0x0001
2748c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_LANDSCAPE		0x0002
2758c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_SPORTS			0x0003
2768c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_INDOOR			0x0004
2778c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_BEACH			0x0005
2788c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_SUNSET			0x0006
2798c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_DAWN			0x0007
2808c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_FALL			0x0008
2818c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_NIGHT			0x0009
2828c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_AGAINST_LIGHT		0x000a
2838c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_FIRE			0x000b
2848c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_TEXT			0x000c
2858c2ecf20Sopenharmony_ci#define  COMM_SCENE_MODE_CANDLE			0x000d
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci#define COMM_AE_AUTO_BRACKET			0x0b14
2888c2ecf20Sopenharmony_ci#define  COMM_AE_AUTO_BRAKET_EV05		0x0080
2898c2ecf20Sopenharmony_ci#define  COMM_AE_AUTO_BRAKET_EV10		0x0100
2908c2ecf20Sopenharmony_ci#define  COMM_AE_AUTO_BRAKET_EV15		0x0180
2918c2ecf20Sopenharmony_ci#define  COMM_AE_AUTO_BRAKET_EV20		0x0200
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci#define COMM_SENSOR_STREAMING			0x090a
2948c2ecf20Sopenharmony_ci#define  COMM_SENSOR_STREAMING_OFF		0x0000
2958c2ecf20Sopenharmony_ci#define  COMM_SENSOR_STREAMING_ON		0x0001
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci#define COMM_AWB_MODE				0x0d02
2988c2ecf20Sopenharmony_ci#define  COMM_AWB_MODE_INCANDESCENT		0x0000
2998c2ecf20Sopenharmony_ci#define  COMM_AWB_MODE_FLUORESCENT1		0x0001
3008c2ecf20Sopenharmony_ci#define  COMM_AWB_MODE_FLUORESCENT2		0x0002
3018c2ecf20Sopenharmony_ci#define  COMM_AWB_MODE_DAYLIGHT			0x0003
3028c2ecf20Sopenharmony_ci#define  COMM_AWB_MODE_CLOUDY			0x0004
3038c2ecf20Sopenharmony_ci#define  COMM_AWB_MODE_AUTO			0x0005
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci#define COMM_AWB_CON				0x0d00
3068c2ecf20Sopenharmony_ci#define  COMM_AWB_STOP				0x0000 /* lock */
3078c2ecf20Sopenharmony_ci#define  COMM_AWB_START				0x0001 /* unlock */
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci#define COMM_FW_UPDATE				0x0906
3108c2ecf20Sopenharmony_ci#define  COMM_FW_UPDATE_NOT_READY		0x0000
3118c2ecf20Sopenharmony_ci#define  COMM_FW_UPDATE_SUCCESS			0x0005
3128c2ecf20Sopenharmony_ci#define  COMM_FW_UPDATE_FAIL			0x0007
3138c2ecf20Sopenharmony_ci#define  COMM_FW_UPDATE_BUSY			0xffff
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci#define S5C73M3_MAX_SUPPLIES			6
3178c2ecf20Sopenharmony_ci#define S5C73M3_DEFAULT_MCLK_FREQ		24000000U
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_cistruct s5c73m3_ctrls {
3208c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler handler;
3218c2ecf20Sopenharmony_ci	struct {
3228c2ecf20Sopenharmony_ci		/* exposure/exposure bias cluster */
3238c2ecf20Sopenharmony_ci		struct v4l2_ctrl *auto_exposure;
3248c2ecf20Sopenharmony_ci		struct v4l2_ctrl *exposure_bias;
3258c2ecf20Sopenharmony_ci		struct v4l2_ctrl *exposure_metering;
3268c2ecf20Sopenharmony_ci	};
3278c2ecf20Sopenharmony_ci	struct {
3288c2ecf20Sopenharmony_ci		/* iso/auto iso cluster */
3298c2ecf20Sopenharmony_ci		struct v4l2_ctrl *auto_iso;
3308c2ecf20Sopenharmony_ci		struct v4l2_ctrl *iso;
3318c2ecf20Sopenharmony_ci	};
3328c2ecf20Sopenharmony_ci	struct v4l2_ctrl *auto_wb;
3338c2ecf20Sopenharmony_ci	struct {
3348c2ecf20Sopenharmony_ci		/* continuous auto focus/auto focus cluster */
3358c2ecf20Sopenharmony_ci		struct v4l2_ctrl *focus_auto;
3368c2ecf20Sopenharmony_ci		struct v4l2_ctrl *af_start;
3378c2ecf20Sopenharmony_ci		struct v4l2_ctrl *af_stop;
3388c2ecf20Sopenharmony_ci		struct v4l2_ctrl *af_status;
3398c2ecf20Sopenharmony_ci		struct v4l2_ctrl *af_distance;
3408c2ecf20Sopenharmony_ci	};
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	struct v4l2_ctrl *aaa_lock;
3438c2ecf20Sopenharmony_ci	struct v4l2_ctrl *colorfx;
3448c2ecf20Sopenharmony_ci	struct v4l2_ctrl *contrast;
3458c2ecf20Sopenharmony_ci	struct v4l2_ctrl *saturation;
3468c2ecf20Sopenharmony_ci	struct v4l2_ctrl *sharpness;
3478c2ecf20Sopenharmony_ci	struct v4l2_ctrl *zoom;
3488c2ecf20Sopenharmony_ci	struct v4l2_ctrl *wdr;
3498c2ecf20Sopenharmony_ci	struct v4l2_ctrl *stabilization;
3508c2ecf20Sopenharmony_ci	struct v4l2_ctrl *jpeg_quality;
3518c2ecf20Sopenharmony_ci	struct v4l2_ctrl *scene_mode;
3528c2ecf20Sopenharmony_ci};
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_cienum s5c73m3_gpio_id {
3558c2ecf20Sopenharmony_ci	STBY,
3568c2ecf20Sopenharmony_ci	RSET,
3578c2ecf20Sopenharmony_ci	GPIO_NUM,
3588c2ecf20Sopenharmony_ci};
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_cienum s5c73m3_resolution_types {
3618c2ecf20Sopenharmony_ci	RES_ISP,
3628c2ecf20Sopenharmony_ci	RES_JPEG,
3638c2ecf20Sopenharmony_ci};
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_cistruct s5c73m3_interval {
3668c2ecf20Sopenharmony_ci	u16 fps_reg;
3678c2ecf20Sopenharmony_ci	struct v4l2_fract interval;
3688c2ecf20Sopenharmony_ci	/* Maximum rectangle for the interval */
3698c2ecf20Sopenharmony_ci	struct v4l2_frmsize_discrete size;
3708c2ecf20Sopenharmony_ci};
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_cistruct s5c73m3 {
3738c2ecf20Sopenharmony_ci	struct v4l2_subdev sensor_sd;
3748c2ecf20Sopenharmony_ci	struct media_pad sensor_pads[S5C73M3_NUM_PADS];
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	struct v4l2_subdev oif_sd;
3778c2ecf20Sopenharmony_ci	struct media_pad oif_pads[OIF_NUM_PADS];
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	struct spi_driver spidrv;
3808c2ecf20Sopenharmony_ci	struct spi_device *spi_dev;
3818c2ecf20Sopenharmony_ci	struct i2c_client *i2c_client;
3828c2ecf20Sopenharmony_ci	u32 i2c_write_address;
3838c2ecf20Sopenharmony_ci	u32 i2c_read_address;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	struct regulator_bulk_data supplies[S5C73M3_MAX_SUPPLIES];
3868c2ecf20Sopenharmony_ci	struct s5c73m3_gpio gpio[GPIO_NUM];
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	struct clk *clock;
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	/* External master clock frequency */
3918c2ecf20Sopenharmony_ci	u32 mclk_frequency;
3928c2ecf20Sopenharmony_ci	/* Video bus type - MIPI-CSI2/parallel */
3938c2ecf20Sopenharmony_ci	enum v4l2_mbus_type bus_type;
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	const struct s5c73m3_frame_size *sensor_pix_size[2];
3968c2ecf20Sopenharmony_ci	const struct s5c73m3_frame_size *oif_pix_size[2];
3978c2ecf20Sopenharmony_ci	u32 mbus_code;
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	const struct s5c73m3_interval *fiv;
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	struct v4l2_mbus_frame_desc frame_desc;
4028c2ecf20Sopenharmony_ci	/* protects the struct members below */
4038c2ecf20Sopenharmony_ci	struct mutex lock;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	struct s5c73m3_ctrls ctrls;
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci	u8 streaming:1;
4088c2ecf20Sopenharmony_ci	u8 apply_fmt:1;
4098c2ecf20Sopenharmony_ci	u8 apply_fiv:1;
4108c2ecf20Sopenharmony_ci	u8 isp_ready:1;
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	short power;
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	char sensor_fw[S5C73M3_SENSOR_FW_LEN + 2];
4158c2ecf20Sopenharmony_ci	char sensor_type[S5C73M3_SENSOR_TYPE_LEN + 2];
4168c2ecf20Sopenharmony_ci	char fw_file_version[2];
4178c2ecf20Sopenharmony_ci	unsigned int fw_size;
4188c2ecf20Sopenharmony_ci};
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_cistruct s5c73m3_frame_size {
4218c2ecf20Sopenharmony_ci	u32 width;
4228c2ecf20Sopenharmony_ci	u32 height;
4238c2ecf20Sopenharmony_ci	u8 reg_val;
4248c2ecf20Sopenharmony_ci};
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ciextern int s5c73m3_dbg;
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ciint s5c73m3_register_spi_driver(struct s5c73m3 *state);
4298c2ecf20Sopenharmony_civoid s5c73m3_unregister_spi_driver(struct s5c73m3 *state);
4308c2ecf20Sopenharmony_ciint s5c73m3_spi_write(struct s5c73m3 *state, const void *addr,
4318c2ecf20Sopenharmony_ci		      const unsigned int len, const unsigned int tx_size);
4328c2ecf20Sopenharmony_ciint s5c73m3_spi_read(struct s5c73m3 *state, void *addr,
4338c2ecf20Sopenharmony_ci		      const unsigned int len, const unsigned int tx_size);
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ciint s5c73m3_read(struct s5c73m3 *state, u32 addr, u16 *data);
4368c2ecf20Sopenharmony_ciint s5c73m3_write(struct s5c73m3 *state, u32 addr, u16 data);
4378c2ecf20Sopenharmony_ciint s5c73m3_isp_command(struct s5c73m3 *state, u16 command, u16 data);
4388c2ecf20Sopenharmony_ciint s5c73m3_init_controls(struct s5c73m3 *state);
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_cistatic inline struct v4l2_subdev *ctrl_to_sensor_sd(struct v4l2_ctrl *ctrl)
4418c2ecf20Sopenharmony_ci{
4428c2ecf20Sopenharmony_ci	return &container_of(ctrl->handler, struct s5c73m3,
4438c2ecf20Sopenharmony_ci			     ctrls.handler)->sensor_sd;
4448c2ecf20Sopenharmony_ci}
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_cistatic inline struct s5c73m3 *sensor_sd_to_s5c73m3(struct v4l2_subdev *sd)
4478c2ecf20Sopenharmony_ci{
4488c2ecf20Sopenharmony_ci	return container_of(sd, struct s5c73m3, sensor_sd);
4498c2ecf20Sopenharmony_ci}
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_cistatic inline struct s5c73m3 *oif_sd_to_s5c73m3(struct v4l2_subdev *sd)
4528c2ecf20Sopenharmony_ci{
4538c2ecf20Sopenharmony_ci	return container_of(sd, struct s5c73m3, oif_sd);
4548c2ecf20Sopenharmony_ci}
4558c2ecf20Sopenharmony_ci#endif	/* S5C73M3_H_ */
456