18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Driver for the mt9m111 sensor
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2008 Erik Andrén
68c2ecf20Sopenharmony_ci * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
78c2ecf20Sopenharmony_ci * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Portions of code to USB interface and ALi driver software,
108c2ecf20Sopenharmony_ci * Copyright (c) 2006 Willem Duinker
118c2ecf20Sopenharmony_ci * v4l2 interface modeled after the V4L2 driver
128c2ecf20Sopenharmony_ci * for SN9C10x PC Camera Controllers
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * Some defines taken from the mt9m111 sensor driver
158c2ecf20Sopenharmony_ci * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr>
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef M5602_MT9M111_H_
198c2ecf20Sopenharmony_ci#define M5602_MT9M111_H_
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "m5602_sensor.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*****************************************************************************/
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define MT9M111_SC_CHIPVER			0x00
268c2ecf20Sopenharmony_ci#define MT9M111_SC_ROWSTART			0x01
278c2ecf20Sopenharmony_ci#define MT9M111_SC_COLSTART			0x02
288c2ecf20Sopenharmony_ci#define MT9M111_SC_WINDOW_HEIGHT		0x03
298c2ecf20Sopenharmony_ci#define MT9M111_SC_WINDOW_WIDTH			0x04
308c2ecf20Sopenharmony_ci#define MT9M111_SC_HBLANK_CONTEXT_B		0x05
318c2ecf20Sopenharmony_ci#define MT9M111_SC_VBLANK_CONTEXT_B		0x06
328c2ecf20Sopenharmony_ci#define MT9M111_SC_HBLANK_CONTEXT_A		0x07
338c2ecf20Sopenharmony_ci#define MT9M111_SC_VBLANK_CONTEXT_A		0x08
348c2ecf20Sopenharmony_ci#define MT9M111_SC_SHUTTER_WIDTH		0x09
358c2ecf20Sopenharmony_ci#define MT9M111_SC_ROW_SPEED			0x0a
368c2ecf20Sopenharmony_ci#define MT9M111_SC_EXTRA_DELAY			0x0b
378c2ecf20Sopenharmony_ci#define MT9M111_SC_SHUTTER_DELAY		0x0c
388c2ecf20Sopenharmony_ci#define MT9M111_SC_RESET			0x0d
398c2ecf20Sopenharmony_ci#define MT9M111_SC_R_MODE_CONTEXT_B		0x20
408c2ecf20Sopenharmony_ci#define MT9M111_SC_R_MODE_CONTEXT_A		0x21
418c2ecf20Sopenharmony_ci#define MT9M111_SC_FLASH_CONTROL		0x23
428c2ecf20Sopenharmony_ci#define MT9M111_SC_GREEN_1_GAIN			0x2b
438c2ecf20Sopenharmony_ci#define MT9M111_SC_BLUE_GAIN			0x2c
448c2ecf20Sopenharmony_ci#define MT9M111_SC_RED_GAIN			0x2d
458c2ecf20Sopenharmony_ci#define MT9M111_SC_GREEN_2_GAIN			0x2e
468c2ecf20Sopenharmony_ci#define MT9M111_SC_GLOBAL_GAIN			0x2f
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define MT9M111_CONTEXT_CONTROL			0xc8
498c2ecf20Sopenharmony_ci#define MT9M111_PAGE_MAP			0xf0
508c2ecf20Sopenharmony_ci#define MT9M111_BYTEWISE_ADDRESS		0xf1
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define MT9M111_CP_OPERATING_MODE_CTL		0x06
538c2ecf20Sopenharmony_ci#define MT9M111_CP_LUMA_OFFSET			0x34
548c2ecf20Sopenharmony_ci#define MT9M111_CP_LUMA_CLIP			0x35
558c2ecf20Sopenharmony_ci#define MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A 0x3a
568c2ecf20Sopenharmony_ci#define MT9M111_CP_LENS_CORRECTION_1		0x3b
578c2ecf20Sopenharmony_ci#define MT9M111_CP_DEFECT_CORR_CONTEXT_A	0x4c
588c2ecf20Sopenharmony_ci#define MT9M111_CP_DEFECT_CORR_CONTEXT_B	0x4d
598c2ecf20Sopenharmony_ci#define MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B 0x9b
608c2ecf20Sopenharmony_ci#define MT9M111_CP_GLOBAL_CLK_CONTROL		0xb3
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18   0x65
638c2ecf20Sopenharmony_ci#define MT9M111_CC_AWB_PARAMETER_7		0x28
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define MT9M111_SENSOR_CORE			0x00
668c2ecf20Sopenharmony_ci#define MT9M111_COLORPIPE			0x01
678c2ecf20Sopenharmony_ci#define MT9M111_CAMERA_CONTROL			0x02
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define MT9M111_RESET				(1 << 0)
708c2ecf20Sopenharmony_ci#define MT9M111_RESTART				(1 << 1)
718c2ecf20Sopenharmony_ci#define MT9M111_ANALOG_STANDBY			(1 << 2)
728c2ecf20Sopenharmony_ci#define MT9M111_CHIP_ENABLE			(1 << 3)
738c2ecf20Sopenharmony_ci#define MT9M111_CHIP_DISABLE			(0 << 3)
748c2ecf20Sopenharmony_ci#define MT9M111_OUTPUT_DISABLE			(1 << 4)
758c2ecf20Sopenharmony_ci#define MT9M111_SHOW_BAD_FRAMES			(1 << 0)
768c2ecf20Sopenharmony_ci#define MT9M111_RESTART_BAD_FRAMES		(1 << 1)
778c2ecf20Sopenharmony_ci#define MT9M111_SYNCHRONIZE_CHANGES		(1 << 7)
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define MT9M111_RMB_OVER_SIZED			(1 << 0)
808c2ecf20Sopenharmony_ci#define MT9M111_RMB_MIRROR_ROWS			(1 << 0)
818c2ecf20Sopenharmony_ci#define MT9M111_RMB_MIRROR_COLS			(1 << 1)
828c2ecf20Sopenharmony_ci#define MT9M111_RMB_ROW_SKIP_2X			(1 << 2)
838c2ecf20Sopenharmony_ci#define MT9M111_RMB_COLUMN_SKIP_2X		(1 << 3)
848c2ecf20Sopenharmony_ci#define MT9M111_RMB_ROW_SKIP_4X			(1 << 4)
858c2ecf20Sopenharmony_ci#define MT9M111_RMB_COLUMN_SKIP_4X		(1 << 5)
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define MT9M111_COLOR_MATRIX_BYPASS		(1 << 4)
888c2ecf20Sopenharmony_ci#define MT9M111_SEL_CONTEXT_B			(1 << 3)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define MT9M111_TRISTATE_PIN_IN_STANDBY		(1 << 1)
918c2ecf20Sopenharmony_ci#define MT9M111_SOC_SOFT_STANDBY		(1 << 0)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define MT9M111_2D_DEFECT_CORRECTION_ENABLE	(1 << 0)
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define INITIAL_MAX_GAIN			64
968c2ecf20Sopenharmony_ci#define MT9M111_DEFAULT_GAIN			283
978c2ecf20Sopenharmony_ci#define MT9M111_GREEN_GAIN_DEFAULT		0x20
988c2ecf20Sopenharmony_ci#define MT9M111_BLUE_GAIN_DEFAULT		0x20
998c2ecf20Sopenharmony_ci#define MT9M111_RED_GAIN_DEFAULT		0x20
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/*****************************************************************************/
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Kernel module parameters */
1048c2ecf20Sopenharmony_ciextern int force_sensor;
1058c2ecf20Sopenharmony_ciextern bool dump_sensor;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciint mt9m111_probe(struct sd *sd);
1088c2ecf20Sopenharmony_ciint mt9m111_init(struct sd *sd);
1098c2ecf20Sopenharmony_ciint mt9m111_init_controls(struct sd *sd);
1108c2ecf20Sopenharmony_ciint mt9m111_start(struct sd *sd);
1118c2ecf20Sopenharmony_civoid mt9m111_disconnect(struct sd *sd);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic const struct m5602_sensor mt9m111 = {
1148c2ecf20Sopenharmony_ci	.name = "MT9M111",
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	.i2c_slave_id = 0xba,
1178c2ecf20Sopenharmony_ci	.i2c_regW = 2,
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	.probe = mt9m111_probe,
1208c2ecf20Sopenharmony_ci	.init = mt9m111_init,
1218c2ecf20Sopenharmony_ci	.init_controls = mt9m111_init_controls,
1228c2ecf20Sopenharmony_ci	.disconnect = mt9m111_disconnect,
1238c2ecf20Sopenharmony_ci	.start = mt9m111_start,
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci#endif
126