18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * OmniVision OV96xx Camera Header File
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2009 Marek Vasut <marek.vasut@gmail.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef	__DRIVERS_MEDIA_VIDEO_OV9640_H__
98c2ecf20Sopenharmony_ci#define	__DRIVERS_MEDIA_VIDEO_OV9640_H__
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* Register definitions */
128c2ecf20Sopenharmony_ci#define	OV9640_GAIN	0x00
138c2ecf20Sopenharmony_ci#define	OV9640_BLUE	0x01
148c2ecf20Sopenharmony_ci#define	OV9640_RED	0x02
158c2ecf20Sopenharmony_ci#define	OV9640_VFER	0x03
168c2ecf20Sopenharmony_ci#define	OV9640_COM1	0x04
178c2ecf20Sopenharmony_ci#define	OV9640_BAVE	0x05
188c2ecf20Sopenharmony_ci#define	OV9640_GEAVE	0x06
198c2ecf20Sopenharmony_ci#define	OV9640_RSID	0x07
208c2ecf20Sopenharmony_ci#define	OV9640_RAVE	0x08
218c2ecf20Sopenharmony_ci#define	OV9640_COM2	0x09
228c2ecf20Sopenharmony_ci#define	OV9640_PID	0x0a
238c2ecf20Sopenharmony_ci#define	OV9640_VER	0x0b
248c2ecf20Sopenharmony_ci#define	OV9640_COM3	0x0c
258c2ecf20Sopenharmony_ci#define	OV9640_COM4	0x0d
268c2ecf20Sopenharmony_ci#define	OV9640_COM5	0x0e
278c2ecf20Sopenharmony_ci#define	OV9640_COM6	0x0f
288c2ecf20Sopenharmony_ci#define	OV9640_AECH	0x10
298c2ecf20Sopenharmony_ci#define	OV9640_CLKRC	0x11
308c2ecf20Sopenharmony_ci#define	OV9640_COM7	0x12
318c2ecf20Sopenharmony_ci#define	OV9640_COM8	0x13
328c2ecf20Sopenharmony_ci#define	OV9640_COM9	0x14
338c2ecf20Sopenharmony_ci#define	OV9640_COM10	0x15
348c2ecf20Sopenharmony_ci/* 0x16 - RESERVED */
358c2ecf20Sopenharmony_ci#define	OV9640_HSTART	0x17
368c2ecf20Sopenharmony_ci#define	OV9640_HSTOP	0x18
378c2ecf20Sopenharmony_ci#define	OV9640_VSTART	0x19
388c2ecf20Sopenharmony_ci#define	OV9640_VSTOP	0x1a
398c2ecf20Sopenharmony_ci#define	OV9640_PSHFT	0x1b
408c2ecf20Sopenharmony_ci#define	OV9640_MIDH	0x1c
418c2ecf20Sopenharmony_ci#define	OV9640_MIDL	0x1d
428c2ecf20Sopenharmony_ci#define	OV9640_MVFP	0x1e
438c2ecf20Sopenharmony_ci#define	OV9640_LAEC	0x1f
448c2ecf20Sopenharmony_ci#define	OV9640_BOS	0x20
458c2ecf20Sopenharmony_ci#define	OV9640_GBOS	0x21
468c2ecf20Sopenharmony_ci#define	OV9640_GROS	0x22
478c2ecf20Sopenharmony_ci#define	OV9640_ROS	0x23
488c2ecf20Sopenharmony_ci#define	OV9640_AEW	0x24
498c2ecf20Sopenharmony_ci#define	OV9640_AEB	0x25
508c2ecf20Sopenharmony_ci#define	OV9640_VPT	0x26
518c2ecf20Sopenharmony_ci#define	OV9640_BBIAS	0x27
528c2ecf20Sopenharmony_ci#define	OV9640_GBBIAS	0x28
538c2ecf20Sopenharmony_ci/* 0x29 - RESERVED */
548c2ecf20Sopenharmony_ci#define	OV9640_EXHCH	0x2a
558c2ecf20Sopenharmony_ci#define	OV9640_EXHCL	0x2b
568c2ecf20Sopenharmony_ci#define	OV9640_RBIAS	0x2c
578c2ecf20Sopenharmony_ci#define	OV9640_ADVFL	0x2d
588c2ecf20Sopenharmony_ci#define	OV9640_ADVFH	0x2e
598c2ecf20Sopenharmony_ci#define	OV9640_YAVE	0x2f
608c2ecf20Sopenharmony_ci#define	OV9640_HSYST	0x30
618c2ecf20Sopenharmony_ci#define	OV9640_HSYEN	0x31
628c2ecf20Sopenharmony_ci#define	OV9640_HREF	0x32
638c2ecf20Sopenharmony_ci#define	OV9640_CHLF	0x33
648c2ecf20Sopenharmony_ci#define	OV9640_ARBLM	0x34
658c2ecf20Sopenharmony_ci/* 0x35..0x36 - RESERVED */
668c2ecf20Sopenharmony_ci#define	OV9640_ADC	0x37
678c2ecf20Sopenharmony_ci#define	OV9640_ACOM	0x38
688c2ecf20Sopenharmony_ci#define	OV9640_OFON	0x39
698c2ecf20Sopenharmony_ci#define	OV9640_TSLB	0x3a
708c2ecf20Sopenharmony_ci#define	OV9640_COM11	0x3b
718c2ecf20Sopenharmony_ci#define	OV9640_COM12	0x3c
728c2ecf20Sopenharmony_ci#define	OV9640_COM13	0x3d
738c2ecf20Sopenharmony_ci#define	OV9640_COM14	0x3e
748c2ecf20Sopenharmony_ci#define	OV9640_EDGE	0x3f
758c2ecf20Sopenharmony_ci#define	OV9640_COM15	0x40
768c2ecf20Sopenharmony_ci#define	OV9640_COM16	0x41
778c2ecf20Sopenharmony_ci#define	OV9640_COM17	0x42
788c2ecf20Sopenharmony_ci/* 0x43..0x4e - RESERVED */
798c2ecf20Sopenharmony_ci#define	OV9640_MTX1	0x4f
808c2ecf20Sopenharmony_ci#define	OV9640_MTX2	0x50
818c2ecf20Sopenharmony_ci#define	OV9640_MTX3	0x51
828c2ecf20Sopenharmony_ci#define	OV9640_MTX4	0x52
838c2ecf20Sopenharmony_ci#define	OV9640_MTX5	0x53
848c2ecf20Sopenharmony_ci#define	OV9640_MTX6	0x54
858c2ecf20Sopenharmony_ci#define	OV9640_MTX7	0x55
868c2ecf20Sopenharmony_ci#define	OV9640_MTX8	0x56
878c2ecf20Sopenharmony_ci#define	OV9640_MTX9	0x57
888c2ecf20Sopenharmony_ci#define	OV9640_MTXS	0x58
898c2ecf20Sopenharmony_ci/* 0x59..0x61 - RESERVED */
908c2ecf20Sopenharmony_ci#define	OV9640_LCC1	0x62
918c2ecf20Sopenharmony_ci#define	OV9640_LCC2	0x63
928c2ecf20Sopenharmony_ci#define	OV9640_LCC3	0x64
938c2ecf20Sopenharmony_ci#define	OV9640_LCC4	0x65
948c2ecf20Sopenharmony_ci#define	OV9640_LCC5	0x66
958c2ecf20Sopenharmony_ci#define	OV9640_MANU	0x67
968c2ecf20Sopenharmony_ci#define	OV9640_MANV	0x68
978c2ecf20Sopenharmony_ci#define	OV9640_HV	0x69
988c2ecf20Sopenharmony_ci#define	OV9640_MBD	0x6a
998c2ecf20Sopenharmony_ci#define	OV9640_DBLV	0x6b
1008c2ecf20Sopenharmony_ci#define	OV9640_GSP	0x6c	/* ... till 0x7b */
1018c2ecf20Sopenharmony_ci#define	OV9640_GST	0x7c	/* ... till 0x8a */
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define	OV9640_CLKRC_DPLL_EN	0x80
1048c2ecf20Sopenharmony_ci#define	OV9640_CLKRC_DIRECT	0x40
1058c2ecf20Sopenharmony_ci#define	OV9640_CLKRC_DIV(x)	((x) & 0x3f)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define	OV9640_PSHFT_VAL(x)	((x) & 0xff)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define	OV9640_ACOM_2X_ANALOG	0x80
1108c2ecf20Sopenharmony_ci#define	OV9640_ACOM_RSVD	0x12
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define	OV9640_MVFP_V		0x10
1138c2ecf20Sopenharmony_ci#define	OV9640_MVFP_H		0x20
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#define	OV9640_COM1_HREF_NOSKIP	0x00
1168c2ecf20Sopenharmony_ci#define	OV9640_COM1_HREF_2SKIP	0x04
1178c2ecf20Sopenharmony_ci#define	OV9640_COM1_HREF_3SKIP	0x08
1188c2ecf20Sopenharmony_ci#define	OV9640_COM1_QQFMT	0x20
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#define	OV9640_COM2_SSM		0x10
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#define	OV9640_COM3_VP		0x04
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci#define	OV9640_COM4_QQ_VP	0x80
1258c2ecf20Sopenharmony_ci#define	OV9640_COM4_RSVD	0x40
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define	OV9640_COM5_SYSCLK	0x80
1288c2ecf20Sopenharmony_ci#define	OV9640_COM5_LONGEXP	0x01
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define	OV9640_COM6_OPT_BLC	0x40
1318c2ecf20Sopenharmony_ci#define	OV9640_COM6_ADBLC_BIAS	0x08
1328c2ecf20Sopenharmony_ci#define	OV9640_COM6_FMT_RST	0x82
1338c2ecf20Sopenharmony_ci#define	OV9640_COM6_ADBLC_OPTEN	0x01
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define	OV9640_COM7_RAW_RGB	0x01
1368c2ecf20Sopenharmony_ci#define	OV9640_COM7_RGB		0x04
1378c2ecf20Sopenharmony_ci#define	OV9640_COM7_QCIF	0x08
1388c2ecf20Sopenharmony_ci#define	OV9640_COM7_QVGA	0x10
1398c2ecf20Sopenharmony_ci#define	OV9640_COM7_CIF		0x20
1408c2ecf20Sopenharmony_ci#define	OV9640_COM7_VGA		0x40
1418c2ecf20Sopenharmony_ci#define	OV9640_COM7_SCCB_RESET	0x80
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci#define	OV9640_TSLB_YVYU_YUYV	0x04
1448c2ecf20Sopenharmony_ci#define	OV9640_TSLB_YUYV_UYVY	0x08
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define	OV9640_COM12_YUV_AVG	0x04
1478c2ecf20Sopenharmony_ci#define	OV9640_COM12_RSVD	0x40
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define	OV9640_COM13_GAMMA_NONE	0x00
1508c2ecf20Sopenharmony_ci#define	OV9640_COM13_GAMMA_Y	0x40
1518c2ecf20Sopenharmony_ci#define	OV9640_COM13_GAMMA_RAW	0x80
1528c2ecf20Sopenharmony_ci#define	OV9640_COM13_RGB_AVG	0x20
1538c2ecf20Sopenharmony_ci#define	OV9640_COM13_MATRIX_EN	0x10
1548c2ecf20Sopenharmony_ci#define	OV9640_COM13_Y_DELAY_EN	0x08
1558c2ecf20Sopenharmony_ci#define	OV9640_COM13_YUV_DLY(x)	((x) & 0x07)
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define	OV9640_COM15_OR_00FF	0x00
1588c2ecf20Sopenharmony_ci#define	OV9640_COM15_OR_01FE	0x40
1598c2ecf20Sopenharmony_ci#define	OV9640_COM15_OR_10F0	0xc0
1608c2ecf20Sopenharmony_ci#define	OV9640_COM15_RGB_NORM	0x00
1618c2ecf20Sopenharmony_ci#define	OV9640_COM15_RGB_565	0x10
1628c2ecf20Sopenharmony_ci#define	OV9640_COM15_RGB_555	0x30
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define	OV9640_COM16_RB_AVG	0x01
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/* IDs */
1678c2ecf20Sopenharmony_ci#define	OV9640_V2		0x9648
1688c2ecf20Sopenharmony_ci#define	OV9640_V3		0x9649
1698c2ecf20Sopenharmony_ci#define	VERSION(pid, ver)	(((pid) << 8) | ((ver) & 0xFF))
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* supported resolutions */
1728c2ecf20Sopenharmony_cienum {
1738c2ecf20Sopenharmony_ci	W_QQCIF	= 88,
1748c2ecf20Sopenharmony_ci	W_QQVGA	= 160,
1758c2ecf20Sopenharmony_ci	W_QCIF	= 176,
1768c2ecf20Sopenharmony_ci	W_QVGA	= 320,
1778c2ecf20Sopenharmony_ci	W_CIF	= 352,
1788c2ecf20Sopenharmony_ci	W_VGA	= 640,
1798c2ecf20Sopenharmony_ci	W_SXGA	= 1280
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci#define	H_SXGA	960
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* Misc. structures */
1848c2ecf20Sopenharmony_cistruct ov9640_reg_alt {
1858c2ecf20Sopenharmony_ci	u8	com7;
1868c2ecf20Sopenharmony_ci	u8	com12;
1878c2ecf20Sopenharmony_ci	u8	com13;
1888c2ecf20Sopenharmony_ci	u8	com15;
1898c2ecf20Sopenharmony_ci};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistruct ov9640_reg {
1928c2ecf20Sopenharmony_ci	u8	reg;
1938c2ecf20Sopenharmony_ci	u8	val;
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistruct ov9640_priv {
1978c2ecf20Sopenharmony_ci	struct v4l2_subdev		subdev;
1988c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler	hdl;
1998c2ecf20Sopenharmony_ci	struct v4l2_clk			*clk;
2008c2ecf20Sopenharmony_ci	struct gpio_desc		*gpio_power;
2018c2ecf20Sopenharmony_ci	struct gpio_desc		*gpio_reset;
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	int				model;
2048c2ecf20Sopenharmony_ci	int				revision;
2058c2ecf20Sopenharmony_ci};
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci#endif	/* __DRIVERS_MEDIA_VIDEO_OV9640_H__ */
208