162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2001 Jean-Fredric Clere, Nikolas Zimmermann, Georg Acher
462306a36Sopenharmony_ci *		      Mark Cave-Ayland, Carlo E Prelz, Dick Streefland
562306a36Sopenharmony_ci * Copyright (c) 2002, 2003 Tuukka Toivonen
662306a36Sopenharmony_ci * Copyright (c) 2008 Erik Andrén
762306a36Sopenharmony_ci * Copyright (c) 2008 Chia-I Wu
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * P/N 861037:      Sensor HDCS1000        ASIC STV0600
1062306a36Sopenharmony_ci * P/N 861050-0010: Sensor HDCS1000        ASIC STV0600
1162306a36Sopenharmony_ci * P/N 861050-0020: Sensor Photobit PB100  ASIC STV0600-1 - QuickCam Express
1262306a36Sopenharmony_ci * P/N 861055:      Sensor ST VV6410       ASIC STV0610   - LEGO cam
1362306a36Sopenharmony_ci * P/N 861075-0040: Sensor HDCS1000        ASIC
1462306a36Sopenharmony_ci * P/N 961179-0700: Sensor ST VV6410       ASIC STV0602   - Dexxa WebCam USB
1562306a36Sopenharmony_ci * P/N 861040-0000: Sensor ST VV6410       ASIC STV0610   - QuickCam Web
1662306a36Sopenharmony_ci */
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#ifndef STV06XX_HDCS_H_
1962306a36Sopenharmony_ci#define STV06XX_HDCS_H_
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#include "stv06xx_sensor.h"
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define HDCS_REG_CONFIG(sd)	(IS_1020(sd) ? HDCS20_CONFIG : HDCS00_CONFIG)
2462306a36Sopenharmony_ci#define HDCS_REG_CONTROL(sd)	(IS_1020(sd) ? HDCS20_CONTROL : HDCS00_CONTROL)
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define HDCS_1X00_DEF_WIDTH	360
2762306a36Sopenharmony_ci#define HDCS_1X00_DEF_HEIGHT	296
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define HDCS_1020_DEF_WIDTH	352
3062306a36Sopenharmony_ci#define HDCS_1020_DEF_HEIGHT	292
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define HDCS_1020_BOTTOM_Y_SKIP	4
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define HDCS_CLK_FREQ_MHZ	25
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define HDCS_ADC_START_SIG_DUR	3
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* LSB bit of I2C or register address signifies write (0) or read (1) */
3962306a36Sopenharmony_ci/* I2C Registers common for both HDCS-1000/1100 and HDCS-1020 */
4062306a36Sopenharmony_ci/* Identifications Register */
4162306a36Sopenharmony_ci#define HDCS_IDENT		(0x00 << 1)
4262306a36Sopenharmony_ci/* Status Register */
4362306a36Sopenharmony_ci#define HDCS_STATUS		(0x01 << 1)
4462306a36Sopenharmony_ci/* Interrupt Mask Register */
4562306a36Sopenharmony_ci#define HDCS_IMASK		(0x02 << 1)
4662306a36Sopenharmony_ci/* Pad Control Register */
4762306a36Sopenharmony_ci#define HDCS_PCTRL		(0x03 << 1)
4862306a36Sopenharmony_ci/* Pad Drive Control Register */
4962306a36Sopenharmony_ci#define HDCS_PDRV		(0x04 << 1)
5062306a36Sopenharmony_ci/* Interface Control Register */
5162306a36Sopenharmony_ci#define HDCS_ICTRL		(0x05 << 1)
5262306a36Sopenharmony_ci/* Interface Timing Register */
5362306a36Sopenharmony_ci#define HDCS_ITMG		(0x06 << 1)
5462306a36Sopenharmony_ci/* Baud Fraction Register */
5562306a36Sopenharmony_ci#define HDCS_BFRAC		(0x07 << 1)
5662306a36Sopenharmony_ci/* Baud Rate Register */
5762306a36Sopenharmony_ci#define HDCS_BRATE		(0x08 << 1)
5862306a36Sopenharmony_ci/* ADC Control Register */
5962306a36Sopenharmony_ci#define HDCS_ADCCTRL		(0x09 << 1)
6062306a36Sopenharmony_ci/* First Window Row Register */
6162306a36Sopenharmony_ci#define HDCS_FWROW		(0x0a << 1)
6262306a36Sopenharmony_ci/* First Window Column Register */
6362306a36Sopenharmony_ci#define HDCS_FWCOL		(0x0b << 1)
6462306a36Sopenharmony_ci/* Last Window Row Register */
6562306a36Sopenharmony_ci#define HDCS_LWROW		(0x0c << 1)
6662306a36Sopenharmony_ci/* Last Window Column Register */
6762306a36Sopenharmony_ci#define HDCS_LWCOL		(0x0d << 1)
6862306a36Sopenharmony_ci/* Timing Control Register */
6962306a36Sopenharmony_ci#define HDCS_TCTRL		(0x0e << 1)
7062306a36Sopenharmony_ci/* PGA Gain Register: Even Row, Even Column */
7162306a36Sopenharmony_ci#define HDCS_ERECPGA		(0x0f << 1)
7262306a36Sopenharmony_ci/* PGA Gain Register: Even Row, Odd Column */
7362306a36Sopenharmony_ci#define HDCS_EROCPGA		(0x10 << 1)
7462306a36Sopenharmony_ci/* PGA Gain Register: Odd Row, Even Column */
7562306a36Sopenharmony_ci#define HDCS_ORECPGA		(0x11 << 1)
7662306a36Sopenharmony_ci/* PGA Gain Register: Odd Row, Odd Column */
7762306a36Sopenharmony_ci#define HDCS_OROCPGA		(0x12 << 1)
7862306a36Sopenharmony_ci/* Row Exposure Low Register */
7962306a36Sopenharmony_ci#define HDCS_ROWEXPL		(0x13 << 1)
8062306a36Sopenharmony_ci/* Row Exposure High Register */
8162306a36Sopenharmony_ci#define HDCS_ROWEXPH		(0x14 << 1)
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/* I2C Registers only for HDCS-1000/1100 */
8462306a36Sopenharmony_ci/* Sub-Row Exposure Low Register */
8562306a36Sopenharmony_ci#define HDCS00_SROWEXPL		(0x15 << 1)
8662306a36Sopenharmony_ci/* Sub-Row Exposure High Register */
8762306a36Sopenharmony_ci#define HDCS00_SROWEXPH		(0x16 << 1)
8862306a36Sopenharmony_ci/* Configuration Register */
8962306a36Sopenharmony_ci#define HDCS00_CONFIG		(0x17 << 1)
9062306a36Sopenharmony_ci/* Control Register */
9162306a36Sopenharmony_ci#define HDCS00_CONTROL		(0x18 << 1)
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/* I2C Registers only for HDCS-1020 */
9462306a36Sopenharmony_ci/* Sub-Row Exposure Register */
9562306a36Sopenharmony_ci#define HDCS20_SROWEXP		(0x15 << 1)
9662306a36Sopenharmony_ci/* Error Control Register */
9762306a36Sopenharmony_ci#define HDCS20_ERROR		(0x16 << 1)
9862306a36Sopenharmony_ci/* Interface Timing 2 Register */
9962306a36Sopenharmony_ci#define HDCS20_ITMG2		(0x17 << 1)
10062306a36Sopenharmony_ci/* Interface Control 2 Register	*/
10162306a36Sopenharmony_ci#define HDCS20_ICTRL2		(0x18 << 1)
10262306a36Sopenharmony_ci/* Horizontal Blank Register */
10362306a36Sopenharmony_ci#define HDCS20_HBLANK		(0x19 << 1)
10462306a36Sopenharmony_ci/* Vertical Blank Register */
10562306a36Sopenharmony_ci#define HDCS20_VBLANK		(0x1a << 1)
10662306a36Sopenharmony_ci/* Configuration Register */
10762306a36Sopenharmony_ci#define HDCS20_CONFIG		(0x1b << 1)
10862306a36Sopenharmony_ci/* Control Register */
10962306a36Sopenharmony_ci#define HDCS20_CONTROL		(0x1c << 1)
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci#define HDCS_RUN_ENABLE		(1 << 2)
11262306a36Sopenharmony_ci#define HDCS_SLEEP_MODE		(1 << 1)
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#define HDCS_DEFAULT_EXPOSURE	48
11562306a36Sopenharmony_ci#define HDCS_DEFAULT_GAIN	50
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_cistatic int hdcs_probe_1x00(struct sd *sd);
11862306a36Sopenharmony_cistatic int hdcs_probe_1020(struct sd *sd);
11962306a36Sopenharmony_cistatic int hdcs_start(struct sd *sd);
12062306a36Sopenharmony_cistatic int hdcs_init(struct sd *sd);
12162306a36Sopenharmony_cistatic int hdcs_init_controls(struct sd *sd);
12262306a36Sopenharmony_cistatic int hdcs_stop(struct sd *sd);
12362306a36Sopenharmony_cistatic int hdcs_dump(struct sd *sd);
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_cistatic int hdcs_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
12662306a36Sopenharmony_cistatic int hdcs_set_gain(struct gspca_dev *gspca_dev, __s32 val);
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ciconst struct stv06xx_sensor stv06xx_sensor_hdcs1x00 = {
12962306a36Sopenharmony_ci	.name = "HP HDCS-1000/1100",
13062306a36Sopenharmony_ci	.i2c_flush = 0,
13162306a36Sopenharmony_ci	.i2c_addr = (0x55 << 1),
13262306a36Sopenharmony_ci	.i2c_len = 1,
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci	/* FIXME (see if we can lower min_packet_size, needs testing, and also
13562306a36Sopenharmony_ci	   adjusting framerate when the bandwidth gets lower) */
13662306a36Sopenharmony_ci	.min_packet_size = { 847 },
13762306a36Sopenharmony_ci	.max_packet_size = { 847 },
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci	.init = hdcs_init,
14062306a36Sopenharmony_ci	.init_controls = hdcs_init_controls,
14162306a36Sopenharmony_ci	.probe = hdcs_probe_1x00,
14262306a36Sopenharmony_ci	.start = hdcs_start,
14362306a36Sopenharmony_ci	.stop = hdcs_stop,
14462306a36Sopenharmony_ci	.dump = hdcs_dump,
14562306a36Sopenharmony_ci};
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ciconst struct stv06xx_sensor stv06xx_sensor_hdcs1020 = {
14862306a36Sopenharmony_ci	.name = "HDCS-1020",
14962306a36Sopenharmony_ci	.i2c_flush = 0,
15062306a36Sopenharmony_ci	.i2c_addr = (0x55 << 1),
15162306a36Sopenharmony_ci	.i2c_len = 1,
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci	/* FIXME (see if we can lower min_packet_size, needs testing, and also
15462306a36Sopenharmony_ci	   adjusting framerate when the bandwidthm gets lower) */
15562306a36Sopenharmony_ci	.min_packet_size = { 847 },
15662306a36Sopenharmony_ci	.max_packet_size = { 847 },
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci	.init = hdcs_init,
15962306a36Sopenharmony_ci	.init_controls = hdcs_init_controls,
16062306a36Sopenharmony_ci	.probe = hdcs_probe_1020,
16162306a36Sopenharmony_ci	.start = hdcs_start,
16262306a36Sopenharmony_ci	.stop = hdcs_stop,
16362306a36Sopenharmony_ci	.dump = hdcs_dump,
16462306a36Sopenharmony_ci};
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_cistatic const u16 stv_bridge_init[][2] = {
16762306a36Sopenharmony_ci	{STV_ISO_ENABLE, 0},
16862306a36Sopenharmony_ci	{STV_REG23, 0},
16962306a36Sopenharmony_ci	{STV_REG00, 0x1d},
17062306a36Sopenharmony_ci	{STV_REG01, 0xb5},
17162306a36Sopenharmony_ci	{STV_REG02, 0xa8},
17262306a36Sopenharmony_ci	{STV_REG03, 0x95},
17362306a36Sopenharmony_ci	{STV_REG04, 0x07},
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci	{STV_SCAN_RATE, 0x20},
17662306a36Sopenharmony_ci	{STV_Y_CTRL, 0x01},
17762306a36Sopenharmony_ci	{STV_X_CTRL, 0x0a}
17862306a36Sopenharmony_ci};
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_cistatic const u8 stv_sensor_init[][2] = {
18162306a36Sopenharmony_ci	/* Clear status (writing 1 will clear the corresponding status bit) */
18262306a36Sopenharmony_ci	{HDCS_STATUS, BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1)},
18362306a36Sopenharmony_ci	/* Disable all interrupts */
18462306a36Sopenharmony_ci	{HDCS_IMASK, 0x00},
18562306a36Sopenharmony_ci	{HDCS_PCTRL, BIT(6) | BIT(5) | BIT(1) | BIT(0)},
18662306a36Sopenharmony_ci	{HDCS_PDRV,  0x00},
18762306a36Sopenharmony_ci	{HDCS_ICTRL, BIT(5)},
18862306a36Sopenharmony_ci	{HDCS_ITMG,  BIT(4) | BIT(1)},
18962306a36Sopenharmony_ci	/* ADC output resolution to 10 bits */
19062306a36Sopenharmony_ci	{HDCS_ADCCTRL, 10}
19162306a36Sopenharmony_ci};
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci#endif
194