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_H_
188c2ecf20Sopenharmony_ci#define STV06XX_H_
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <linux/slab.h>
218c2ecf20Sopenharmony_ci#include "gspca.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define MODULE_NAME "STV06xx"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define STV_ISOC_ENDPOINT_ADDR		0x81
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define STV_R                           0x0509
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define STV_REG23			0x0423
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* Control registers of the STV0600 ASIC */
328c2ecf20Sopenharmony_ci#define STV_I2C_PARTNER			0x1420
338c2ecf20Sopenharmony_ci#define STV_I2C_VAL_REG_VAL_PAIRS_MIN1	0x1421
348c2ecf20Sopenharmony_ci#define STV_I2C_READ_WRITE_TOGGLE	0x1422
358c2ecf20Sopenharmony_ci#define STV_I2C_FLUSH			0x1423
368c2ecf20Sopenharmony_ci#define STV_I2C_SUCC_READ_REG_VALS	0x1424
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define STV_ISO_ENABLE			0x1440
398c2ecf20Sopenharmony_ci#define STV_SCAN_RATE			0x1443
408c2ecf20Sopenharmony_ci#define STV_LED_CTRL			0x1445
418c2ecf20Sopenharmony_ci#define STV_STV0600_EMULATION		0x1446
428c2ecf20Sopenharmony_ci#define STV_REG00			0x1500
438c2ecf20Sopenharmony_ci#define STV_REG01			0x1501
448c2ecf20Sopenharmony_ci#define STV_REG02			0x1502
458c2ecf20Sopenharmony_ci#define STV_REG03			0x1503
468c2ecf20Sopenharmony_ci#define STV_REG04			0x1504
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define STV_ISO_SIZE_L			0x15c1
498c2ecf20Sopenharmony_ci#define STV_ISO_SIZE_H			0x15c2
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* Refers to the CIF 352x288 and QCIF 176x144 */
528c2ecf20Sopenharmony_ci/* 1: 288 lines, 2: 144 lines */
538c2ecf20Sopenharmony_ci#define STV_Y_CTRL			0x15c3
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define STV_RESET                       0x1620
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* 0xa: 352 columns, 0x6: 176 columns */
588c2ecf20Sopenharmony_ci#define STV_X_CTRL			0x1680
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define STV06XX_URB_MSG_TIMEOUT		5000
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#define I2C_MAX_BYTES			16
638c2ecf20Sopenharmony_ci#define I2C_MAX_WORDS			8
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define I2C_BUFFER_LENGTH		0x23
668c2ecf20Sopenharmony_ci#define I2C_READ_CMD			3
678c2ecf20Sopenharmony_ci#define I2C_WRITE_CMD			1
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define LED_ON				1
708c2ecf20Sopenharmony_ci#define LED_OFF				0
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* STV06xx device descriptor */
738c2ecf20Sopenharmony_cistruct sd {
748c2ecf20Sopenharmony_ci	struct gspca_dev gspca_dev;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	/* A pointer to the currently connected sensor */
778c2ecf20Sopenharmony_ci	const struct stv06xx_sensor *sensor;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	/* Sensor private data */
808c2ecf20Sopenharmony_ci	void *sensor_priv;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	/* The first 4 lines produced by the stv6422 are no good, this keeps
838c2ecf20Sopenharmony_ci	   track of how many bytes we still need to skip during a frame */
848c2ecf20Sopenharmony_ci	int to_skip;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	/* Bridge / Camera type */
878c2ecf20Sopenharmony_ci	u8 bridge;
888c2ecf20Sopenharmony_ci	#define BRIDGE_STV600 0
898c2ecf20Sopenharmony_ci	#define BRIDGE_STV602 1
908c2ecf20Sopenharmony_ci	#define BRIDGE_STV610 2
918c2ecf20Sopenharmony_ci	#define BRIDGE_ST6422 3 /* With integrated sensor */
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ciint stv06xx_write_bridge(struct sd *sd, u16 address, u16 i2c_data);
958c2ecf20Sopenharmony_ciint stv06xx_read_bridge(struct sd *sd, u16 address, u8 *i2c_data);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciint stv06xx_write_sensor_bytes(struct sd *sd, const u8 *data, u8 len);
988c2ecf20Sopenharmony_ciint stv06xx_write_sensor_words(struct sd *sd, const u16 *data, u8 len);
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ciint stv06xx_read_sensor(struct sd *sd, const u8 address, u16 *value);
1018c2ecf20Sopenharmony_ciint stv06xx_write_sensor(struct sd *sd, u8 address, u16 value);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#endif
104