18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * USB Driver for ALi m5602 based webcams
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
158c2ecf20Sopenharmony_ci#ifndef M5602_BRIDGE_H_
168c2ecf20Sopenharmony_ci#define M5602_BRIDGE_H_
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/slab.h>
198c2ecf20Sopenharmony_ci#include "gspca.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define MODULE_NAME "ALi m5602"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*****************************************************************************/
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define M5602_XB_SENSOR_TYPE		0x00
268c2ecf20Sopenharmony_ci#define M5602_XB_SENSOR_CTRL		0x01
278c2ecf20Sopenharmony_ci#define M5602_XB_LINE_OF_FRAME_H	0x02
288c2ecf20Sopenharmony_ci#define M5602_XB_LINE_OF_FRAME_L	0x03
298c2ecf20Sopenharmony_ci#define M5602_XB_PIX_OF_LINE_H		0x04
308c2ecf20Sopenharmony_ci#define M5602_XB_PIX_OF_LINE_L		0x05
318c2ecf20Sopenharmony_ci#define M5602_XB_VSYNC_PARA		0x06
328c2ecf20Sopenharmony_ci#define M5602_XB_HSYNC_PARA		0x07
338c2ecf20Sopenharmony_ci#define M5602_XB_TEST_MODE_1		0x08
348c2ecf20Sopenharmony_ci#define M5602_XB_TEST_MODE_2		0x09
358c2ecf20Sopenharmony_ci#define M5602_XB_SIG_INI		0x0a
368c2ecf20Sopenharmony_ci#define M5602_XB_DS_PARA		0x0e
378c2ecf20Sopenharmony_ci#define M5602_XB_TRIG_PARA		0x0f
388c2ecf20Sopenharmony_ci#define M5602_XB_CLK_PD			0x10
398c2ecf20Sopenharmony_ci#define M5602_XB_MCU_CLK_CTRL		0x12
408c2ecf20Sopenharmony_ci#define M5602_XB_MCU_CLK_DIV		0x13
418c2ecf20Sopenharmony_ci#define M5602_XB_SEN_CLK_CTRL		0x14
428c2ecf20Sopenharmony_ci#define M5602_XB_SEN_CLK_DIV		0x15
438c2ecf20Sopenharmony_ci#define M5602_XB_AUD_CLK_CTRL		0x16
448c2ecf20Sopenharmony_ci#define M5602_XB_AUD_CLK_DIV		0x17
458c2ecf20Sopenharmony_ci#define M5602_OB_AC_LINK_STATE		0x22
468c2ecf20Sopenharmony_ci#define M5602_OB_PCM_SLOT_INDEX		0x24
478c2ecf20Sopenharmony_ci#define M5602_OB_GPIO_SLOT_INDEX	0x25
488c2ecf20Sopenharmony_ci#define M5602_OB_ACRX_STATUS_ADDRESS_H	0x28
498c2ecf20Sopenharmony_ci#define M5602_OB_ACRX_STATUS_DATA_L	0x29
508c2ecf20Sopenharmony_ci#define M5602_OB_ACRX_STATUS_DATA_H	0x2a
518c2ecf20Sopenharmony_ci#define M5602_OB_ACTX_COMMAND_ADDRESS	0x31
528c2ecf20Sopenharmony_ci#define M5602_OB_ACRX_COMMAND_DATA_L	0x32
538c2ecf20Sopenharmony_ci#define M5602_OB_ACTX_COMMAND_DATA_H	0X33
548c2ecf20Sopenharmony_ci#define M5602_XB_DEVCTR1		0x41
558c2ecf20Sopenharmony_ci#define M5602_XB_EPSETR0		0x42
568c2ecf20Sopenharmony_ci#define M5602_XB_EPAFCTR		0x47
578c2ecf20Sopenharmony_ci#define M5602_XB_EPBFCTR		0x49
588c2ecf20Sopenharmony_ci#define M5602_XB_EPEFCTR		0x4f
598c2ecf20Sopenharmony_ci#define M5602_XB_TEST_REG		0x53
608c2ecf20Sopenharmony_ci#define M5602_XB_ALT2SIZE		0x54
618c2ecf20Sopenharmony_ci#define M5602_XB_ALT3SIZE		0x55
628c2ecf20Sopenharmony_ci#define M5602_XB_OBSFRAME		0x56
638c2ecf20Sopenharmony_ci#define M5602_XB_PWR_CTL		0x59
648c2ecf20Sopenharmony_ci#define M5602_XB_ADC_CTRL		0x60
658c2ecf20Sopenharmony_ci#define M5602_XB_ADC_DATA		0x61
668c2ecf20Sopenharmony_ci#define M5602_XB_MISC_CTRL		0x62
678c2ecf20Sopenharmony_ci#define M5602_XB_SNAPSHOT		0x63
688c2ecf20Sopenharmony_ci#define M5602_XB_SCRATCH_1		0x64
698c2ecf20Sopenharmony_ci#define M5602_XB_SCRATCH_2		0x65
708c2ecf20Sopenharmony_ci#define M5602_XB_SCRATCH_3		0x66
718c2ecf20Sopenharmony_ci#define M5602_XB_SCRATCH_4		0x67
728c2ecf20Sopenharmony_ci#define M5602_XB_I2C_CTRL		0x68
738c2ecf20Sopenharmony_ci#define M5602_XB_I2C_CLK_DIV		0x69
748c2ecf20Sopenharmony_ci#define M5602_XB_I2C_DEV_ADDR		0x6a
758c2ecf20Sopenharmony_ci#define M5602_XB_I2C_REG_ADDR		0x6b
768c2ecf20Sopenharmony_ci#define M5602_XB_I2C_DATA		0x6c
778c2ecf20Sopenharmony_ci#define M5602_XB_I2C_STATUS		0x6d
788c2ecf20Sopenharmony_ci#define M5602_XB_GPIO_DAT_H		0x70
798c2ecf20Sopenharmony_ci#define M5602_XB_GPIO_DAT_L		0x71
808c2ecf20Sopenharmony_ci#define M5602_XB_GPIO_DIR_H		0x72
818c2ecf20Sopenharmony_ci#define M5602_XB_GPIO_DIR_L		0x73
828c2ecf20Sopenharmony_ci#define M5602_XB_GPIO_EN_H		0x74
838c2ecf20Sopenharmony_ci#define M5602_XB_GPIO_EN_L		0x75
848c2ecf20Sopenharmony_ci#define M5602_XB_GPIO_DAT		0x76
858c2ecf20Sopenharmony_ci#define M5602_XB_GPIO_DIR		0x77
868c2ecf20Sopenharmony_ci#define M5602_XB_SEN_CLK_CONTROL	0x80
878c2ecf20Sopenharmony_ci#define M5602_XB_SEN_CLK_DIVISION	0x81
888c2ecf20Sopenharmony_ci#define M5602_XB_CPR_CLK_CONTROL	0x82
898c2ecf20Sopenharmony_ci#define M5602_XB_CPR_CLK_DIVISION	0x83
908c2ecf20Sopenharmony_ci#define M5602_XB_MCU_CLK_CONTROL	0x84
918c2ecf20Sopenharmony_ci#define M5602_XB_MCU_CLK_DIVISION	0x85
928c2ecf20Sopenharmony_ci#define M5602_XB_DCT_CLK_CONTROL	0x86
938c2ecf20Sopenharmony_ci#define M5602_XB_DCT_CLK_DIVISION	0x87
948c2ecf20Sopenharmony_ci#define M5602_XB_EC_CLK_CONTROL		0x88
958c2ecf20Sopenharmony_ci#define M5602_XB_EC_CLK_DIVISION	0x89
968c2ecf20Sopenharmony_ci#define M5602_XB_LBUF_CLK_CONTROL	0x8a
978c2ecf20Sopenharmony_ci#define M5602_XB_LBUF_CLK_DIVISION	0x8b
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define I2C_BUSY 0x80
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/*****************************************************************************/
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Driver info */
1048c2ecf20Sopenharmony_ci#define DRIVER_AUTHOR "ALi m5602 Linux Driver Project"
1058c2ecf20Sopenharmony_ci#define DRIVER_DESC "ALi m5602 webcam driver"
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define M5602_ISOC_ENDPOINT_ADDR 0x81
1088c2ecf20Sopenharmony_ci#define M5602_INTR_ENDPOINT_ADDR 0x82
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define M5602_URB_MSG_TIMEOUT   5000
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/*****************************************************************************/
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistruct sd {
1158c2ecf20Sopenharmony_ci	struct gspca_dev gspca_dev;
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	/* A pointer to the currently connected sensor */
1188c2ecf20Sopenharmony_ci	const struct m5602_sensor *sensor;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	/* The current frame's id, used to detect frame boundaries */
1218c2ecf20Sopenharmony_ci	u8 frame_id;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	/* The current frame count */
1248c2ecf20Sopenharmony_ci	u32 frame_count;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	/* Camera rotation polling thread for "flipable" cams */
1278c2ecf20Sopenharmony_ci	struct task_struct *rotation_thread;
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	struct { /* auto-white-bal + green/red/blue balance control cluster */
1308c2ecf20Sopenharmony_ci		struct v4l2_ctrl *auto_white_bal;
1318c2ecf20Sopenharmony_ci		struct v4l2_ctrl *red_bal;
1328c2ecf20Sopenharmony_ci		struct v4l2_ctrl *blue_bal;
1338c2ecf20Sopenharmony_ci		struct v4l2_ctrl *green_bal;
1348c2ecf20Sopenharmony_ci	};
1358c2ecf20Sopenharmony_ci	struct { /* autoexpo / expo cluster */
1368c2ecf20Sopenharmony_ci		struct v4l2_ctrl *autoexpo;
1378c2ecf20Sopenharmony_ci		struct v4l2_ctrl *expo;
1388c2ecf20Sopenharmony_ci	};
1398c2ecf20Sopenharmony_ci	struct { /* autogain / gain cluster */
1408c2ecf20Sopenharmony_ci		struct v4l2_ctrl *autogain;
1418c2ecf20Sopenharmony_ci		struct v4l2_ctrl *gain;
1428c2ecf20Sopenharmony_ci	};
1438c2ecf20Sopenharmony_ci	struct { /* hflip/vflip cluster */
1448c2ecf20Sopenharmony_ci		struct v4l2_ctrl *hflip;
1458c2ecf20Sopenharmony_ci		struct v4l2_ctrl *vflip;
1468c2ecf20Sopenharmony_ci	};
1478c2ecf20Sopenharmony_ci};
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ciint m5602_read_bridge(
1508c2ecf20Sopenharmony_ci	struct sd *sd, const u8 address, u8 *i2c_data);
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ciint m5602_write_bridge(
1538c2ecf20Sopenharmony_ci	struct sd *sd, const u8 address, const u8 i2c_data);
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ciint m5602_write_sensor(struct sd *sd, const u8 address,
1568c2ecf20Sopenharmony_ci		       u8 *i2c_data, const u8 len);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciint m5602_read_sensor(struct sd *sd, const u8 address,
1598c2ecf20Sopenharmony_ci		      u8 *i2c_data, const u8 len);
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#endif
162