162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * USB Driver for ALi m5602 based webcams
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2008 Erik Andrén
662306a36Sopenharmony_ci * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
762306a36Sopenharmony_ci * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Portions of code to USB interface and ALi driver software,
1062306a36Sopenharmony_ci * Copyright (c) 2006 Willem Duinker
1162306a36Sopenharmony_ci * v4l2 interface modeled after the V4L2 driver
1262306a36Sopenharmony_ci * for SN9C10x PC Camera Controllers
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#ifndef M5602_BRIDGE_H_
1662306a36Sopenharmony_ci#define M5602_BRIDGE_H_
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include <linux/slab.h>
1962306a36Sopenharmony_ci#include "gspca.h"
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define MODULE_NAME "ALi m5602"
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/*****************************************************************************/
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#define M5602_XB_SENSOR_TYPE		0x00
2662306a36Sopenharmony_ci#define M5602_XB_SENSOR_CTRL		0x01
2762306a36Sopenharmony_ci#define M5602_XB_LINE_OF_FRAME_H	0x02
2862306a36Sopenharmony_ci#define M5602_XB_LINE_OF_FRAME_L	0x03
2962306a36Sopenharmony_ci#define M5602_XB_PIX_OF_LINE_H		0x04
3062306a36Sopenharmony_ci#define M5602_XB_PIX_OF_LINE_L		0x05
3162306a36Sopenharmony_ci#define M5602_XB_VSYNC_PARA		0x06
3262306a36Sopenharmony_ci#define M5602_XB_HSYNC_PARA		0x07
3362306a36Sopenharmony_ci#define M5602_XB_TEST_MODE_1		0x08
3462306a36Sopenharmony_ci#define M5602_XB_TEST_MODE_2		0x09
3562306a36Sopenharmony_ci#define M5602_XB_SIG_INI		0x0a
3662306a36Sopenharmony_ci#define M5602_XB_DS_PARA		0x0e
3762306a36Sopenharmony_ci#define M5602_XB_TRIG_PARA		0x0f
3862306a36Sopenharmony_ci#define M5602_XB_CLK_PD			0x10
3962306a36Sopenharmony_ci#define M5602_XB_MCU_CLK_CTRL		0x12
4062306a36Sopenharmony_ci#define M5602_XB_MCU_CLK_DIV		0x13
4162306a36Sopenharmony_ci#define M5602_XB_SEN_CLK_CTRL		0x14
4262306a36Sopenharmony_ci#define M5602_XB_SEN_CLK_DIV		0x15
4362306a36Sopenharmony_ci#define M5602_XB_AUD_CLK_CTRL		0x16
4462306a36Sopenharmony_ci#define M5602_XB_AUD_CLK_DIV		0x17
4562306a36Sopenharmony_ci#define M5602_OB_AC_LINK_STATE		0x22
4662306a36Sopenharmony_ci#define M5602_OB_PCM_SLOT_INDEX		0x24
4762306a36Sopenharmony_ci#define M5602_OB_GPIO_SLOT_INDEX	0x25
4862306a36Sopenharmony_ci#define M5602_OB_ACRX_STATUS_ADDRESS_H	0x28
4962306a36Sopenharmony_ci#define M5602_OB_ACRX_STATUS_DATA_L	0x29
5062306a36Sopenharmony_ci#define M5602_OB_ACRX_STATUS_DATA_H	0x2a
5162306a36Sopenharmony_ci#define M5602_OB_ACTX_COMMAND_ADDRESS	0x31
5262306a36Sopenharmony_ci#define M5602_OB_ACRX_COMMAND_DATA_L	0x32
5362306a36Sopenharmony_ci#define M5602_OB_ACTX_COMMAND_DATA_H	0X33
5462306a36Sopenharmony_ci#define M5602_XB_DEVCTR1		0x41
5562306a36Sopenharmony_ci#define M5602_XB_EPSETR0		0x42
5662306a36Sopenharmony_ci#define M5602_XB_EPAFCTR		0x47
5762306a36Sopenharmony_ci#define M5602_XB_EPBFCTR		0x49
5862306a36Sopenharmony_ci#define M5602_XB_EPEFCTR		0x4f
5962306a36Sopenharmony_ci#define M5602_XB_TEST_REG		0x53
6062306a36Sopenharmony_ci#define M5602_XB_ALT2SIZE		0x54
6162306a36Sopenharmony_ci#define M5602_XB_ALT3SIZE		0x55
6262306a36Sopenharmony_ci#define M5602_XB_OBSFRAME		0x56
6362306a36Sopenharmony_ci#define M5602_XB_PWR_CTL		0x59
6462306a36Sopenharmony_ci#define M5602_XB_ADC_CTRL		0x60
6562306a36Sopenharmony_ci#define M5602_XB_ADC_DATA		0x61
6662306a36Sopenharmony_ci#define M5602_XB_MISC_CTRL		0x62
6762306a36Sopenharmony_ci#define M5602_XB_SNAPSHOT		0x63
6862306a36Sopenharmony_ci#define M5602_XB_SCRATCH_1		0x64
6962306a36Sopenharmony_ci#define M5602_XB_SCRATCH_2		0x65
7062306a36Sopenharmony_ci#define M5602_XB_SCRATCH_3		0x66
7162306a36Sopenharmony_ci#define M5602_XB_SCRATCH_4		0x67
7262306a36Sopenharmony_ci#define M5602_XB_I2C_CTRL		0x68
7362306a36Sopenharmony_ci#define M5602_XB_I2C_CLK_DIV		0x69
7462306a36Sopenharmony_ci#define M5602_XB_I2C_DEV_ADDR		0x6a
7562306a36Sopenharmony_ci#define M5602_XB_I2C_REG_ADDR		0x6b
7662306a36Sopenharmony_ci#define M5602_XB_I2C_DATA		0x6c
7762306a36Sopenharmony_ci#define M5602_XB_I2C_STATUS		0x6d
7862306a36Sopenharmony_ci#define M5602_XB_GPIO_DAT_H		0x70
7962306a36Sopenharmony_ci#define M5602_XB_GPIO_DAT_L		0x71
8062306a36Sopenharmony_ci#define M5602_XB_GPIO_DIR_H		0x72
8162306a36Sopenharmony_ci#define M5602_XB_GPIO_DIR_L		0x73
8262306a36Sopenharmony_ci#define M5602_XB_GPIO_EN_H		0x74
8362306a36Sopenharmony_ci#define M5602_XB_GPIO_EN_L		0x75
8462306a36Sopenharmony_ci#define M5602_XB_GPIO_DAT		0x76
8562306a36Sopenharmony_ci#define M5602_XB_GPIO_DIR		0x77
8662306a36Sopenharmony_ci#define M5602_XB_SEN_CLK_CONTROL	0x80
8762306a36Sopenharmony_ci#define M5602_XB_SEN_CLK_DIVISION	0x81
8862306a36Sopenharmony_ci#define M5602_XB_CPR_CLK_CONTROL	0x82
8962306a36Sopenharmony_ci#define M5602_XB_CPR_CLK_DIVISION	0x83
9062306a36Sopenharmony_ci#define M5602_XB_MCU_CLK_CONTROL	0x84
9162306a36Sopenharmony_ci#define M5602_XB_MCU_CLK_DIVISION	0x85
9262306a36Sopenharmony_ci#define M5602_XB_DCT_CLK_CONTROL	0x86
9362306a36Sopenharmony_ci#define M5602_XB_DCT_CLK_DIVISION	0x87
9462306a36Sopenharmony_ci#define M5602_XB_EC_CLK_CONTROL		0x88
9562306a36Sopenharmony_ci#define M5602_XB_EC_CLK_DIVISION	0x89
9662306a36Sopenharmony_ci#define M5602_XB_LBUF_CLK_CONTROL	0x8a
9762306a36Sopenharmony_ci#define M5602_XB_LBUF_CLK_DIVISION	0x8b
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci#define I2C_BUSY 0x80
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/*****************************************************************************/
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* Driver info */
10462306a36Sopenharmony_ci#define DRIVER_AUTHOR "ALi m5602 Linux Driver Project"
10562306a36Sopenharmony_ci#define DRIVER_DESC "ALi m5602 webcam driver"
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci#define M5602_ISOC_ENDPOINT_ADDR 0x81
10862306a36Sopenharmony_ci#define M5602_INTR_ENDPOINT_ADDR 0x82
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci#define M5602_URB_MSG_TIMEOUT   5000
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/*****************************************************************************/
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_cistruct sd {
11562306a36Sopenharmony_ci	struct gspca_dev gspca_dev;
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci	/* A pointer to the currently connected sensor */
11862306a36Sopenharmony_ci	const struct m5602_sensor *sensor;
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	/* The current frame's id, used to detect frame boundaries */
12162306a36Sopenharmony_ci	u8 frame_id;
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci	/* The current frame count */
12462306a36Sopenharmony_ci	u32 frame_count;
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci	/* Camera rotation polling thread for "flipable" cams */
12762306a36Sopenharmony_ci	struct task_struct *rotation_thread;
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	struct { /* auto-white-bal + green/red/blue balance control cluster */
13062306a36Sopenharmony_ci		struct v4l2_ctrl *auto_white_bal;
13162306a36Sopenharmony_ci		struct v4l2_ctrl *red_bal;
13262306a36Sopenharmony_ci		struct v4l2_ctrl *blue_bal;
13362306a36Sopenharmony_ci		struct v4l2_ctrl *green_bal;
13462306a36Sopenharmony_ci	};
13562306a36Sopenharmony_ci	struct { /* autoexpo / expo cluster */
13662306a36Sopenharmony_ci		struct v4l2_ctrl *autoexpo;
13762306a36Sopenharmony_ci		struct v4l2_ctrl *expo;
13862306a36Sopenharmony_ci	};
13962306a36Sopenharmony_ci	struct { /* autogain / gain cluster */
14062306a36Sopenharmony_ci		struct v4l2_ctrl *autogain;
14162306a36Sopenharmony_ci		struct v4l2_ctrl *gain;
14262306a36Sopenharmony_ci	};
14362306a36Sopenharmony_ci	struct { /* hflip/vflip cluster */
14462306a36Sopenharmony_ci		struct v4l2_ctrl *hflip;
14562306a36Sopenharmony_ci		struct v4l2_ctrl *vflip;
14662306a36Sopenharmony_ci	};
14762306a36Sopenharmony_ci};
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ciint m5602_read_bridge(
15062306a36Sopenharmony_ci	struct sd *sd, const u8 address, u8 *i2c_data);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ciint m5602_write_bridge(
15362306a36Sopenharmony_ci	struct sd *sd, const u8 address, const u8 i2c_data);
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ciint m5602_write_sensor(struct sd *sd, const u8 address,
15662306a36Sopenharmony_ci		       u8 *i2c_data, const u8 len);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ciint m5602_read_sensor(struct sd *sd, const u8 address,
15962306a36Sopenharmony_ci		      u8 *i2c_data, const u8 len);
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci#endif
162