18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2001 Jean-Fredric Clere, Nikolas Zimmermann, Georg Acher
48c2ecf20Sopenharmony_ci *		      Mark Cave-Ayland, Carlo E Prelz, Dick Streefland
58c2ecf20Sopenharmony_ci * Copyright (c) 2002, 2003 Tuukka Toivonen
68c2ecf20Sopenharmony_ci * Copyright (c) 2008 Erik Andrén
78c2ecf20Sopenharmony_ci * Copyright (c) 2008 Chia-I Wu
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * P/N 861037:      Sensor HDCS1000        ASIC STV0600
108c2ecf20Sopenharmony_ci * P/N 861050-0010: Sensor HDCS1000        ASIC STV0600
118c2ecf20Sopenharmony_ci * P/N 861050-0020: Sensor Photobit PB100  ASIC STV0600-1 - QuickCam Express
128c2ecf20Sopenharmony_ci * P/N 861055:      Sensor ST VV6410       ASIC STV0610   - LEGO cam
138c2ecf20Sopenharmony_ci * P/N 861075-0040: Sensor HDCS1000        ASIC
148c2ecf20Sopenharmony_ci * P/N 961179-0700: Sensor ST VV6410       ASIC STV0602   - Dexxa WebCam USB
158c2ecf20Sopenharmony_ci * P/N 861040-0000: Sensor ST VV6410       ASIC STV0610   - QuickCam Web
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef STV06XX_HDCS_H_
198c2ecf20Sopenharmony_ci#define STV06XX_HDCS_H_
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "stv06xx_sensor.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define HDCS_REG_CONFIG(sd)	(IS_1020(sd) ? HDCS20_CONFIG : HDCS00_CONFIG)
248c2ecf20Sopenharmony_ci#define HDCS_REG_CONTROL(sd)	(IS_1020(sd) ? HDCS20_CONTROL : HDCS00_CONTROL)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define HDCS_1X00_DEF_WIDTH	360
278c2ecf20Sopenharmony_ci#define HDCS_1X00_DEF_HEIGHT	296
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define HDCS_1020_DEF_WIDTH	352
308c2ecf20Sopenharmony_ci#define HDCS_1020_DEF_HEIGHT	292
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define HDCS_1020_BOTTOM_Y_SKIP	4
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define HDCS_CLK_FREQ_MHZ	25
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define HDCS_ADC_START_SIG_DUR	3
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* LSB bit of I2C or register address signifies write (0) or read (1) */
398c2ecf20Sopenharmony_ci/* I2C Registers common for both HDCS-1000/1100 and HDCS-1020 */
408c2ecf20Sopenharmony_ci/* Identifications Register */
418c2ecf20Sopenharmony_ci#define HDCS_IDENT		(0x00 << 1)
428c2ecf20Sopenharmony_ci/* Status Register */
438c2ecf20Sopenharmony_ci#define HDCS_STATUS		(0x01 << 1)
448c2ecf20Sopenharmony_ci/* Interrupt Mask Register */
458c2ecf20Sopenharmony_ci#define HDCS_IMASK		(0x02 << 1)
468c2ecf20Sopenharmony_ci/* Pad Control Register */
478c2ecf20Sopenharmony_ci#define HDCS_PCTRL		(0x03 << 1)
488c2ecf20Sopenharmony_ci/* Pad Drive Control Register */
498c2ecf20Sopenharmony_ci#define HDCS_PDRV		(0x04 << 1)
508c2ecf20Sopenharmony_ci/* Interface Control Register */
518c2ecf20Sopenharmony_ci#define HDCS_ICTRL		(0x05 << 1)
528c2ecf20Sopenharmony_ci/* Interface Timing Register */
538c2ecf20Sopenharmony_ci#define HDCS_ITMG		(0x06 << 1)
548c2ecf20Sopenharmony_ci/* Baud Fraction Register */
558c2ecf20Sopenharmony_ci#define HDCS_BFRAC		(0x07 << 1)
568c2ecf20Sopenharmony_ci/* Baud Rate Register */
578c2ecf20Sopenharmony_ci#define HDCS_BRATE		(0x08 << 1)
588c2ecf20Sopenharmony_ci/* ADC Control Register */
598c2ecf20Sopenharmony_ci#define HDCS_ADCCTRL		(0x09 << 1)
608c2ecf20Sopenharmony_ci/* First Window Row Register */
618c2ecf20Sopenharmony_ci#define HDCS_FWROW		(0x0a << 1)
628c2ecf20Sopenharmony_ci/* First Window Column Register */
638c2ecf20Sopenharmony_ci#define HDCS_FWCOL		(0x0b << 1)
648c2ecf20Sopenharmony_ci/* Last Window Row Register */
658c2ecf20Sopenharmony_ci#define HDCS_LWROW		(0x0c << 1)
668c2ecf20Sopenharmony_ci/* Last Window Column Register */
678c2ecf20Sopenharmony_ci#define HDCS_LWCOL		(0x0d << 1)
688c2ecf20Sopenharmony_ci/* Timing Control Register */
698c2ecf20Sopenharmony_ci#define HDCS_TCTRL		(0x0e << 1)
708c2ecf20Sopenharmony_ci/* PGA Gain Register: Even Row, Even Column */
718c2ecf20Sopenharmony_ci#define HDCS_ERECPGA		(0x0f << 1)
728c2ecf20Sopenharmony_ci/* PGA Gain Register: Even Row, Odd Column */
738c2ecf20Sopenharmony_ci#define HDCS_EROCPGA		(0x10 << 1)
748c2ecf20Sopenharmony_ci/* PGA Gain Register: Odd Row, Even Column */
758c2ecf20Sopenharmony_ci#define HDCS_ORECPGA		(0x11 << 1)
768c2ecf20Sopenharmony_ci/* PGA Gain Register: Odd Row, Odd Column */
778c2ecf20Sopenharmony_ci#define HDCS_OROCPGA		(0x12 << 1)
788c2ecf20Sopenharmony_ci/* Row Exposure Low Register */
798c2ecf20Sopenharmony_ci#define HDCS_ROWEXPL		(0x13 << 1)
808c2ecf20Sopenharmony_ci/* Row Exposure High Register */
818c2ecf20Sopenharmony_ci#define HDCS_ROWEXPH		(0x14 << 1)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* I2C Registers only for HDCS-1000/1100 */
848c2ecf20Sopenharmony_ci/* Sub-Row Exposure Low Register */
858c2ecf20Sopenharmony_ci#define HDCS00_SROWEXPL		(0x15 << 1)
868c2ecf20Sopenharmony_ci/* Sub-Row Exposure High Register */
878c2ecf20Sopenharmony_ci#define HDCS00_SROWEXPH		(0x16 << 1)
888c2ecf20Sopenharmony_ci/* Configuration Register */
898c2ecf20Sopenharmony_ci#define HDCS00_CONFIG		(0x17 << 1)
908c2ecf20Sopenharmony_ci/* Control Register */
918c2ecf20Sopenharmony_ci#define HDCS00_CONTROL		(0x18 << 1)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* I2C Registers only for HDCS-1020 */
948c2ecf20Sopenharmony_ci/* Sub-Row Exposure Register */
958c2ecf20Sopenharmony_ci#define HDCS20_SROWEXP		(0x15 << 1)
968c2ecf20Sopenharmony_ci/* Error Control Register */
978c2ecf20Sopenharmony_ci#define HDCS20_ERROR		(0x16 << 1)
988c2ecf20Sopenharmony_ci/* Interface Timing 2 Register */
998c2ecf20Sopenharmony_ci#define HDCS20_ITMG2		(0x17 << 1)
1008c2ecf20Sopenharmony_ci/* Interface Control 2 Register	*/
1018c2ecf20Sopenharmony_ci#define HDCS20_ICTRL2		(0x18 << 1)
1028c2ecf20Sopenharmony_ci/* Horizontal Blank Register */
1038c2ecf20Sopenharmony_ci#define HDCS20_HBLANK		(0x19 << 1)
1048c2ecf20Sopenharmony_ci/* Vertical Blank Register */
1058c2ecf20Sopenharmony_ci#define HDCS20_VBLANK		(0x1a << 1)
1068c2ecf20Sopenharmony_ci/* Configuration Register */
1078c2ecf20Sopenharmony_ci#define HDCS20_CONFIG		(0x1b << 1)
1088c2ecf20Sopenharmony_ci/* Control Register */
1098c2ecf20Sopenharmony_ci#define HDCS20_CONTROL		(0x1c << 1)
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define HDCS_RUN_ENABLE		(1 << 2)
1128c2ecf20Sopenharmony_ci#define HDCS_SLEEP_MODE		(1 << 1)
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define HDCS_DEFAULT_EXPOSURE	48
1158c2ecf20Sopenharmony_ci#define HDCS_DEFAULT_GAIN	50
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic int hdcs_probe_1x00(struct sd *sd);
1188c2ecf20Sopenharmony_cistatic int hdcs_probe_1020(struct sd *sd);
1198c2ecf20Sopenharmony_cistatic int hdcs_start(struct sd *sd);
1208c2ecf20Sopenharmony_cistatic int hdcs_init(struct sd *sd);
1218c2ecf20Sopenharmony_cistatic int hdcs_init_controls(struct sd *sd);
1228c2ecf20Sopenharmony_cistatic int hdcs_stop(struct sd *sd);
1238c2ecf20Sopenharmony_cistatic int hdcs_dump(struct sd *sd);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistatic int hdcs_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
1268c2ecf20Sopenharmony_cistatic int hdcs_set_gain(struct gspca_dev *gspca_dev, __s32 val);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ciconst struct stv06xx_sensor stv06xx_sensor_hdcs1x00 = {
1298c2ecf20Sopenharmony_ci	.name = "HP HDCS-1000/1100",
1308c2ecf20Sopenharmony_ci	.i2c_flush = 0,
1318c2ecf20Sopenharmony_ci	.i2c_addr = (0x55 << 1),
1328c2ecf20Sopenharmony_ci	.i2c_len = 1,
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	/* FIXME (see if we can lower min_packet_size, needs testing, and also
1358c2ecf20Sopenharmony_ci	   adjusting framerate when the bandwidth gets lower) */
1368c2ecf20Sopenharmony_ci	.min_packet_size = { 847 },
1378c2ecf20Sopenharmony_ci	.max_packet_size = { 847 },
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	.init = hdcs_init,
1408c2ecf20Sopenharmony_ci	.init_controls = hdcs_init_controls,
1418c2ecf20Sopenharmony_ci	.probe = hdcs_probe_1x00,
1428c2ecf20Sopenharmony_ci	.start = hdcs_start,
1438c2ecf20Sopenharmony_ci	.stop = hdcs_stop,
1448c2ecf20Sopenharmony_ci	.dump = hdcs_dump,
1458c2ecf20Sopenharmony_ci};
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ciconst struct stv06xx_sensor stv06xx_sensor_hdcs1020 = {
1488c2ecf20Sopenharmony_ci	.name = "HDCS-1020",
1498c2ecf20Sopenharmony_ci	.i2c_flush = 0,
1508c2ecf20Sopenharmony_ci	.i2c_addr = (0x55 << 1),
1518c2ecf20Sopenharmony_ci	.i2c_len = 1,
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	/* FIXME (see if we can lower min_packet_size, needs testing, and also
1548c2ecf20Sopenharmony_ci	   adjusting framerate when the bandwidthm gets lower) */
1558c2ecf20Sopenharmony_ci	.min_packet_size = { 847 },
1568c2ecf20Sopenharmony_ci	.max_packet_size = { 847 },
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	.init = hdcs_init,
1598c2ecf20Sopenharmony_ci	.init_controls = hdcs_init_controls,
1608c2ecf20Sopenharmony_ci	.probe = hdcs_probe_1020,
1618c2ecf20Sopenharmony_ci	.start = hdcs_start,
1628c2ecf20Sopenharmony_ci	.stop = hdcs_stop,
1638c2ecf20Sopenharmony_ci	.dump = hdcs_dump,
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_cistatic const u16 stv_bridge_init[][2] = {
1678c2ecf20Sopenharmony_ci	{STV_ISO_ENABLE, 0},
1688c2ecf20Sopenharmony_ci	{STV_REG23, 0},
1698c2ecf20Sopenharmony_ci	{STV_REG00, 0x1d},
1708c2ecf20Sopenharmony_ci	{STV_REG01, 0xb5},
1718c2ecf20Sopenharmony_ci	{STV_REG02, 0xa8},
1728c2ecf20Sopenharmony_ci	{STV_REG03, 0x95},
1738c2ecf20Sopenharmony_ci	{STV_REG04, 0x07},
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	{STV_SCAN_RATE, 0x20},
1768c2ecf20Sopenharmony_ci	{STV_Y_CTRL, 0x01},
1778c2ecf20Sopenharmony_ci	{STV_X_CTRL, 0x0a}
1788c2ecf20Sopenharmony_ci};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic const u8 stv_sensor_init[][2] = {
1818c2ecf20Sopenharmony_ci	/* Clear status (writing 1 will clear the corresponding status bit) */
1828c2ecf20Sopenharmony_ci	{HDCS_STATUS, BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1)},
1838c2ecf20Sopenharmony_ci	/* Disable all interrupts */
1848c2ecf20Sopenharmony_ci	{HDCS_IMASK, 0x00},
1858c2ecf20Sopenharmony_ci	{HDCS_PCTRL, BIT(6) | BIT(5) | BIT(1) | BIT(0)},
1868c2ecf20Sopenharmony_ci	{HDCS_PDRV,  0x00},
1878c2ecf20Sopenharmony_ci	{HDCS_ICTRL, BIT(5)},
1888c2ecf20Sopenharmony_ci	{HDCS_ITMG,  BIT(4) | BIT(1)},
1898c2ecf20Sopenharmony_ci	/* ADC output resolution to 10 bits */
1908c2ecf20Sopenharmony_ci	{HDCS_ADCCTRL, 10}
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#endif
194