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 *
88c2ecf20Sopenharmony_ci * P/N 861037:      Sensor HDCS1000        ASIC STV0600
98c2ecf20Sopenharmony_ci * P/N 861050-0010: Sensor HDCS1000        ASIC STV0600
108c2ecf20Sopenharmony_ci * P/N 861050-0020: Sensor Photobit PB100  ASIC STV0600-1 - QuickCam Express
118c2ecf20Sopenharmony_ci * P/N 861055:      Sensor ST VV6410       ASIC STV0610   - LEGO cam
128c2ecf20Sopenharmony_ci * P/N 861075-0040: Sensor HDCS1000        ASIC
138c2ecf20Sopenharmony_ci * P/N 961179-0700: Sensor ST VV6410       ASIC STV0602   - Dexxa WebCam USB
148c2ecf20Sopenharmony_ci * P/N 861040-0000: Sensor ST VV6410       ASIC STV0610   - QuickCam Web
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#ifndef STV06XX_VV6410_H_
188c2ecf20Sopenharmony_ci#define STV06XX_VV6410_H_
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "stv06xx_sensor.h"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define VV6410_COLS			416
238c2ecf20Sopenharmony_ci#define VV6410_ROWS			320
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Status registers */
268c2ecf20Sopenharmony_ci/* Chip identification number including revision indicator */
278c2ecf20Sopenharmony_ci#define VV6410_DEVICEH			0x00
288c2ecf20Sopenharmony_ci#define VV6410_DEVICEL			0x01
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* User can determine whether timed I2C data
318c2ecf20Sopenharmony_ci   has been consumed by interrogating flag states */
328c2ecf20Sopenharmony_ci#define VV6410_STATUS0			0x02
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* Current line counter value */
358c2ecf20Sopenharmony_ci#define VV6410_LINECOUNTH		0x03
368c2ecf20Sopenharmony_ci#define VV6410_LINECOUNTL		0x04
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* End x coordinate of image size */
398c2ecf20Sopenharmony_ci#define VV6410_XENDH			0x05
408c2ecf20Sopenharmony_ci#define VV6410_XENDL			0x06
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/* End y coordinate of image size */
438c2ecf20Sopenharmony_ci#define VV6410_YENDH			0x07
448c2ecf20Sopenharmony_ci#define VV6410_YENDL			0x08
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/* This is the average pixel value returned from the
478c2ecf20Sopenharmony_ci   dark line offset cancellation algorithm */
488c2ecf20Sopenharmony_ci#define VV6410_DARKAVGH			0x09
498c2ecf20Sopenharmony_ci#define VV6410_DARKAVGL			0x0a
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* This is the average pixel value returned from the
528c2ecf20Sopenharmony_ci   black line offset cancellation algorithm  */
538c2ecf20Sopenharmony_ci#define VV6410_BLACKAVGH		0x0b
548c2ecf20Sopenharmony_ci#define VV6410_BLACKAVGL		0x0c
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* Flags to indicate whether the x or y image coordinates have been clipped */
578c2ecf20Sopenharmony_ci#define VV6410_STATUS1			0x0d
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* Setup registers */
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/* Low-power/sleep modes & video timing */
628c2ecf20Sopenharmony_ci#define VV6410_SETUP0			0x10
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* Various parameters */
658c2ecf20Sopenharmony_ci#define VV6410_SETUP1			0x11
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/* Contains pixel counter reset value used by external sync */
688c2ecf20Sopenharmony_ci#define VV6410_SYNCVALUE		0x12
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/* Frame grabbing modes (FST, LST and QCK) */
718c2ecf20Sopenharmony_ci#define VV6410_FGMODES			0x14
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* FST and QCK mapping modes. */
748c2ecf20Sopenharmony_ci#define VV6410_PINMAPPING		0x15
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/* Data resolution */
778c2ecf20Sopenharmony_ci#define VV6410_DATAFORMAT		0x16
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* Output coding formats */
808c2ecf20Sopenharmony_ci#define VV6410_OPFORMAT			0x17
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/* Various mode select bits */
838c2ecf20Sopenharmony_ci#define VV6410_MODESELECT		0x18
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* Exposure registers */
868c2ecf20Sopenharmony_ci/* Fine exposure. */
878c2ecf20Sopenharmony_ci#define VV6410_FINEH			0x20
888c2ecf20Sopenharmony_ci#define VV6410_FINEL			0x21
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* Coarse exposure */
918c2ecf20Sopenharmony_ci#define VV6410_COARSEH			0x22
928c2ecf20Sopenharmony_ci#define VV6410_COARSEL			0x23
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* Analog gain setting */
958c2ecf20Sopenharmony_ci#define VV6410_ANALOGGAIN		0x24
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* Clock division */
988c2ecf20Sopenharmony_ci#define VV6410_CLKDIV			0x25
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* Dark line offset cancellation value */
1018c2ecf20Sopenharmony_ci#define VV6410_DARKOFFSETH		0x2c
1028c2ecf20Sopenharmony_ci#define VV6410_DARKOFFSETL		0x2d
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* Dark line offset cancellation enable */
1058c2ecf20Sopenharmony_ci#define VV6410_DARKOFFSETSETUP		0x2e
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/* Video timing registers */
1088c2ecf20Sopenharmony_ci/* Line Length (Pixel Clocks) */
1098c2ecf20Sopenharmony_ci#define VV6410_LINELENGTHH		0x52
1108c2ecf20Sopenharmony_ci#define VV6410_LINELENGTHL		0x53
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* X-co-ordinate of top left corner of region of interest (x-offset) */
1138c2ecf20Sopenharmony_ci#define VV6410_XOFFSETH			0x57
1148c2ecf20Sopenharmony_ci#define VV6410_XOFFSETL			0x58
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/* Y-coordinate of top left corner of region of interest (y-offset) */
1178c2ecf20Sopenharmony_ci#define VV6410_YOFFSETH			0x59
1188c2ecf20Sopenharmony_ci#define VV6410_YOFFSETL			0x5a
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/* Field length (Lines) */
1218c2ecf20Sopenharmony_ci#define VV6410_FIELDLENGTHH		0x61
1228c2ecf20Sopenharmony_ci#define VV6410_FIELDLENGTHL		0x62
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/* System registers */
1258c2ecf20Sopenharmony_ci/* Black offset cancellation default value */
1268c2ecf20Sopenharmony_ci#define VV6410_BLACKOFFSETH		0x70
1278c2ecf20Sopenharmony_ci#define VV6410_BLACKOFFSETL		0x71
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/* Black offset cancellation setup */
1308c2ecf20Sopenharmony_ci#define VV6410_BLACKOFFSETSETUP		0x72
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci/* Analog Control Register 0 */
1338c2ecf20Sopenharmony_ci#define VV6410_CR0			0x75
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/* Analog Control Register 1 */
1368c2ecf20Sopenharmony_ci#define VV6410_CR1			0x76
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/* ADC Setup Register */
1398c2ecf20Sopenharmony_ci#define VV6410_AS0			0x77
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/* Analog Test Register */
1428c2ecf20Sopenharmony_ci#define VV6410_AT0			0x78
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/* Audio Amplifier Setup Register */
1458c2ecf20Sopenharmony_ci#define VV6410_AT1			0x79
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#define VV6410_HFLIP			(1 << 3)
1488c2ecf20Sopenharmony_ci#define VV6410_VFLIP			(1 << 4)
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#define VV6410_LOW_POWER_MODE		(1 << 0)
1518c2ecf20Sopenharmony_ci#define VV6410_SOFT_RESET		(1 << 2)
1528c2ecf20Sopenharmony_ci#define VV6410_PAL_25_FPS		(0 << 3)
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#define VV6410_CLK_DIV_2		(1 << 1)
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#define VV6410_FINE_EXPOSURE		320
1578c2ecf20Sopenharmony_ci#define VV6410_COARSE_EXPOSURE		192
1588c2ecf20Sopenharmony_ci#define VV6410_DEFAULT_GAIN		5
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define VV6410_SUBSAMPLE		0x01
1618c2ecf20Sopenharmony_ci#define VV6410_CROP_TO_QVGA		0x02
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#define VV6410_CIF_LINELENGTH		415
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic int vv6410_probe(struct sd *sd);
1668c2ecf20Sopenharmony_cistatic int vv6410_start(struct sd *sd);
1678c2ecf20Sopenharmony_cistatic int vv6410_init(struct sd *sd);
1688c2ecf20Sopenharmony_cistatic int vv6410_init_controls(struct sd *sd);
1698c2ecf20Sopenharmony_cistatic int vv6410_stop(struct sd *sd);
1708c2ecf20Sopenharmony_cistatic int vv6410_dump(struct sd *sd);
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/* V4L2 controls supported by the driver */
1738c2ecf20Sopenharmony_cistatic int vv6410_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
1748c2ecf20Sopenharmony_cistatic int vv6410_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
1758c2ecf20Sopenharmony_cistatic int vv6410_set_analog_gain(struct gspca_dev *gspca_dev, __s32 val);
1768c2ecf20Sopenharmony_cistatic int vv6410_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ciconst struct stv06xx_sensor stv06xx_sensor_vv6410 = {
1798c2ecf20Sopenharmony_ci	.name = "ST VV6410",
1808c2ecf20Sopenharmony_ci	.i2c_flush = 5,
1818c2ecf20Sopenharmony_ci	.i2c_addr = 0x20,
1828c2ecf20Sopenharmony_ci	.i2c_len = 1,
1838c2ecf20Sopenharmony_ci	/* FIXME (see if we can lower packet_size-s, needs testing, and also
1848c2ecf20Sopenharmony_ci	   adjusting framerate when the bandwidth gets lower) */
1858c2ecf20Sopenharmony_ci	.min_packet_size = { 1023 },
1868c2ecf20Sopenharmony_ci	.max_packet_size = { 1023 },
1878c2ecf20Sopenharmony_ci	.init = vv6410_init,
1888c2ecf20Sopenharmony_ci	.init_controls = vv6410_init_controls,
1898c2ecf20Sopenharmony_ci	.probe = vv6410_probe,
1908c2ecf20Sopenharmony_ci	.start = vv6410_start,
1918c2ecf20Sopenharmony_ci	.stop = vv6410_stop,
1928c2ecf20Sopenharmony_ci	.dump = vv6410_dump,
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/* If NULL, only single value to write, stored in len */
1968c2ecf20Sopenharmony_cistruct stv_init {
1978c2ecf20Sopenharmony_ci	u16 addr;
1988c2ecf20Sopenharmony_ci	u8 data;
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistatic const struct stv_init stv_bridge_init[] = {
2028c2ecf20Sopenharmony_ci	/* This reg is written twice. Some kind of reset? */
2038c2ecf20Sopenharmony_ci	{STV_RESET, 0x80},
2048c2ecf20Sopenharmony_ci	{STV_RESET, 0x00},
2058c2ecf20Sopenharmony_ci	{STV_SCAN_RATE, 0x00},
2068c2ecf20Sopenharmony_ci	{STV_I2C_FLUSH, 0x04},
2078c2ecf20Sopenharmony_ci	{STV_REG00, 0x0b},
2088c2ecf20Sopenharmony_ci	{STV_REG01, 0xa7},
2098c2ecf20Sopenharmony_ci	{STV_REG02, 0xb7},
2108c2ecf20Sopenharmony_ci	{STV_REG03, 0x00},
2118c2ecf20Sopenharmony_ci	{STV_REG04, 0x00},
2128c2ecf20Sopenharmony_ci	{0x1536, 0x02},
2138c2ecf20Sopenharmony_ci	{0x1537, 0x00},
2148c2ecf20Sopenharmony_ci	{0x1538, 0x60},
2158c2ecf20Sopenharmony_ci	{0x1539, 0x01},
2168c2ecf20Sopenharmony_ci	{0x153a, 0x20},
2178c2ecf20Sopenharmony_ci	{0x153b, 0x01},
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic const u8 vv6410_sensor_init[][2] = {
2218c2ecf20Sopenharmony_ci	/* Setup registers */
2228c2ecf20Sopenharmony_ci	{VV6410_SETUP0,	VV6410_SOFT_RESET},
2238c2ecf20Sopenharmony_ci	{VV6410_SETUP0,	VV6410_LOW_POWER_MODE},
2248c2ecf20Sopenharmony_ci	/* Use shuffled read-out mode */
2258c2ecf20Sopenharmony_ci	{VV6410_SETUP1,	BIT(6)},
2268c2ecf20Sopenharmony_ci	/* All modes to 1, FST, Fast QCK, Free running QCK, Free running LST, FST will qualify visible pixels */
2278c2ecf20Sopenharmony_ci	{VV6410_FGMODES, BIT(6) | BIT(4) | BIT(2) | BIT(0)},
2288c2ecf20Sopenharmony_ci	{VV6410_PINMAPPING, 0x00},
2298c2ecf20Sopenharmony_ci	/* Pre-clock generator divide off */
2308c2ecf20Sopenharmony_ci	{VV6410_DATAFORMAT, BIT(7) | BIT(0)},
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	{VV6410_CLKDIV,	VV6410_CLK_DIV_2},
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	/* System registers */
2358c2ecf20Sopenharmony_ci	/* Enable voltage doubler */
2368c2ecf20Sopenharmony_ci	{VV6410_AS0, BIT(6) | BIT(4) | BIT(3) | BIT(2) | BIT(1)},
2378c2ecf20Sopenharmony_ci	{VV6410_AT0, 0x00},
2388c2ecf20Sopenharmony_ci	/* Power up audio, differential */
2398c2ecf20Sopenharmony_ci	{VV6410_AT1, BIT(4) | BIT(0)},
2408c2ecf20Sopenharmony_ci};
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci#endif
243