18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/**************************************************************************** 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Filename: cpia2.h 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright 2001, STMicrolectronics, Inc. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Contact: steve.miller@st.com 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Description: 118c2ecf20Sopenharmony_ci * This is a USB driver for CPiA2 based video cameras. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * This driver is modelled on the cpia usb driver by 148c2ecf20Sopenharmony_ci * Jochen Scharrlach and Johannes Erdfeldt. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci ****************************************************************************/ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#ifndef __CPIA2_H__ 198c2ecf20Sopenharmony_ci#define __CPIA2_H__ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include <linux/videodev2.h> 228c2ecf20Sopenharmony_ci#include <linux/usb.h> 238c2ecf20Sopenharmony_ci#include <linux/poll.h> 248c2ecf20Sopenharmony_ci#include <media/v4l2-common.h> 258c2ecf20Sopenharmony_ci#include <media/v4l2-device.h> 268c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include "cpia2_registers.h" 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* define for verbose debug output */ 318c2ecf20Sopenharmony_ci//#define _CPIA2_DEBUG_ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/*** 348c2ecf20Sopenharmony_ci * Image defines 358c2ecf20Sopenharmony_ci ***/ 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* Misc constants */ 388c2ecf20Sopenharmony_ci#define ALLOW_CORRUPT 0 /* Causes collater to discard checksum */ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* USB Transfer mode */ 418c2ecf20Sopenharmony_ci#define XFER_ISOC 0 428c2ecf20Sopenharmony_ci#define XFER_BULK 1 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* USB Alternates */ 458c2ecf20Sopenharmony_ci#define USBIF_CMDONLY 0 468c2ecf20Sopenharmony_ci#define USBIF_BULK 1 478c2ecf20Sopenharmony_ci#define USBIF_ISO_1 2 /* 128 bytes/ms */ 488c2ecf20Sopenharmony_ci#define USBIF_ISO_2 3 /* 384 bytes/ms */ 498c2ecf20Sopenharmony_ci#define USBIF_ISO_3 4 /* 640 bytes/ms */ 508c2ecf20Sopenharmony_ci#define USBIF_ISO_4 5 /* 768 bytes/ms */ 518c2ecf20Sopenharmony_ci#define USBIF_ISO_5 6 /* 896 bytes/ms */ 528c2ecf20Sopenharmony_ci#define USBIF_ISO_6 7 /* 1023 bytes/ms */ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci/* Flicker Modes */ 558c2ecf20Sopenharmony_ci#define NEVER_FLICKER 0 568c2ecf20Sopenharmony_ci#define FLICKER_60 60 578c2ecf20Sopenharmony_ci#define FLICKER_50 50 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* Debug flags */ 608c2ecf20Sopenharmony_ci#define DEBUG_NONE 0 618c2ecf20Sopenharmony_ci#define DEBUG_REG 0x00000001 628c2ecf20Sopenharmony_ci#define DEBUG_DUMP_PATCH 0x00000002 638c2ecf20Sopenharmony_ci#define DEBUG_DUMP_REGS 0x00000004 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/*** 668c2ecf20Sopenharmony_ci * Video frame sizes 678c2ecf20Sopenharmony_ci ***/ 688c2ecf20Sopenharmony_cienum { 698c2ecf20Sopenharmony_ci VIDEOSIZE_VGA = 0, /* 640x480 */ 708c2ecf20Sopenharmony_ci VIDEOSIZE_CIF, /* 352x288 */ 718c2ecf20Sopenharmony_ci VIDEOSIZE_QVGA, /* 320x240 */ 728c2ecf20Sopenharmony_ci VIDEOSIZE_QCIF, /* 176x144 */ 738c2ecf20Sopenharmony_ci VIDEOSIZE_288_216, 748c2ecf20Sopenharmony_ci VIDEOSIZE_256_192, 758c2ecf20Sopenharmony_ci VIDEOSIZE_224_168, 768c2ecf20Sopenharmony_ci VIDEOSIZE_192_144, 778c2ecf20Sopenharmony_ci}; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#define STV_IMAGE_CIF_ROWS 288 808c2ecf20Sopenharmony_ci#define STV_IMAGE_CIF_COLS 352 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#define STV_IMAGE_QCIF_ROWS 144 838c2ecf20Sopenharmony_ci#define STV_IMAGE_QCIF_COLS 176 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define STV_IMAGE_VGA_ROWS 480 868c2ecf20Sopenharmony_ci#define STV_IMAGE_VGA_COLS 640 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#define STV_IMAGE_QVGA_ROWS 240 898c2ecf20Sopenharmony_ci#define STV_IMAGE_QVGA_COLS 320 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define JPEG_MARKER_COM (1<<6) /* Comment segment */ 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/*** 948c2ecf20Sopenharmony_ci * Enums 958c2ecf20Sopenharmony_ci ***/ 968c2ecf20Sopenharmony_ci/* Sensor types available with cpia2 asics */ 978c2ecf20Sopenharmony_cienum sensors { 988c2ecf20Sopenharmony_ci CPIA2_SENSOR_410, 998c2ecf20Sopenharmony_ci CPIA2_SENSOR_500 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* Asic types available in the CPiA2 architecture */ 1038c2ecf20Sopenharmony_ci#define CPIA2_ASIC_672 0x67 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* Device types (stv672, stv676, etc) */ 1068c2ecf20Sopenharmony_ci#define DEVICE_STV_672 0x0001 1078c2ecf20Sopenharmony_ci#define DEVICE_STV_676 0x0002 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cienum frame_status { 1108c2ecf20Sopenharmony_ci FRAME_EMPTY, 1118c2ecf20Sopenharmony_ci FRAME_READING, /* In the process of being grabbed into */ 1128c2ecf20Sopenharmony_ci FRAME_READY, /* Ready to be read */ 1138c2ecf20Sopenharmony_ci FRAME_ERROR, 1148c2ecf20Sopenharmony_ci}; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci/*** 1178c2ecf20Sopenharmony_ci * Register access (for USB request byte) 1188c2ecf20Sopenharmony_ci ***/ 1198c2ecf20Sopenharmony_cienum { 1208c2ecf20Sopenharmony_ci CAMERAACCESS_SYSTEM = 0, 1218c2ecf20Sopenharmony_ci CAMERAACCESS_VC, 1228c2ecf20Sopenharmony_ci CAMERAACCESS_VP, 1238c2ecf20Sopenharmony_ci CAMERAACCESS_IDATA 1248c2ecf20Sopenharmony_ci}; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#define CAMERAACCESS_TYPE_BLOCK 0x00 1278c2ecf20Sopenharmony_ci#define CAMERAACCESS_TYPE_RANDOM 0x04 1288c2ecf20Sopenharmony_ci#define CAMERAACCESS_TYPE_MASK 0x08 1298c2ecf20Sopenharmony_ci#define CAMERAACCESS_TYPE_REPEAT 0x0C 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define TRANSFER_READ 0 1328c2ecf20Sopenharmony_ci#define TRANSFER_WRITE 1 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#define DEFAULT_ALT USBIF_ISO_6 1358c2ecf20Sopenharmony_ci#define DEFAULT_BRIGHTNESS 0x46 1368c2ecf20Sopenharmony_ci#define DEFAULT_CONTRAST 0x93 1378c2ecf20Sopenharmony_ci#define DEFAULT_SATURATION 0x7f 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci/* Power state */ 1408c2ecf20Sopenharmony_ci#define HI_POWER_MODE CPIA2_SYSTEM_CONTROL_HIGH_POWER 1418c2ecf20Sopenharmony_ci#define LO_POWER_MODE CPIA2_SYSTEM_CONTROL_LOW_POWER 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/******** 1458c2ecf20Sopenharmony_ci * Commands 1468c2ecf20Sopenharmony_ci *******/ 1478c2ecf20Sopenharmony_cienum { 1488c2ecf20Sopenharmony_ci CPIA2_CMD_NONE = 0, 1498c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VERSION, 1508c2ecf20Sopenharmony_ci CPIA2_CMD_GET_PNP_ID, 1518c2ecf20Sopenharmony_ci CPIA2_CMD_GET_ASIC_TYPE, 1528c2ecf20Sopenharmony_ci CPIA2_CMD_GET_SENSOR, 1538c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VP_DEVICE, 1548c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VP_BRIGHTNESS, 1558c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VP_BRIGHTNESS, 1568c2ecf20Sopenharmony_ci CPIA2_CMD_GET_CONTRAST, 1578c2ecf20Sopenharmony_ci CPIA2_CMD_SET_CONTRAST, 1588c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VP_SATURATION, 1598c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VP_SATURATION, 1608c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VP_GPIO_DIRECTION, 1618c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VP_GPIO_DIRECTION, 1628c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VP_GPIO_DATA, 1638c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VP_GPIO_DATA, 1648c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VC_MP_GPIO_DIRECTION, 1658c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VC_MP_GPIO_DIRECTION, 1668c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VC_MP_GPIO_DATA, 1678c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VC_MP_GPIO_DATA, 1688c2ecf20Sopenharmony_ci CPIA2_CMD_ENABLE_PACKET_CTRL, 1698c2ecf20Sopenharmony_ci CPIA2_CMD_GET_FLICKER_MODES, 1708c2ecf20Sopenharmony_ci CPIA2_CMD_SET_FLICKER_MODES, 1718c2ecf20Sopenharmony_ci CPIA2_CMD_RESET_FIFO, /* clear fifo and enable stream block */ 1728c2ecf20Sopenharmony_ci CPIA2_CMD_SET_HI_POWER, 1738c2ecf20Sopenharmony_ci CPIA2_CMD_SET_LOW_POWER, 1748c2ecf20Sopenharmony_ci CPIA2_CMD_CLEAR_V2W_ERR, 1758c2ecf20Sopenharmony_ci CPIA2_CMD_SET_USER_MODE, 1768c2ecf20Sopenharmony_ci CPIA2_CMD_GET_USER_MODE, 1778c2ecf20Sopenharmony_ci CPIA2_CMD_FRAMERATE_REQ, 1788c2ecf20Sopenharmony_ci CPIA2_CMD_SET_COMPRESSION_STATE, 1798c2ecf20Sopenharmony_ci CPIA2_CMD_GET_WAKEUP, 1808c2ecf20Sopenharmony_ci CPIA2_CMD_SET_WAKEUP, 1818c2ecf20Sopenharmony_ci CPIA2_CMD_GET_PW_CONTROL, 1828c2ecf20Sopenharmony_ci CPIA2_CMD_SET_PW_CONTROL, 1838c2ecf20Sopenharmony_ci CPIA2_CMD_GET_SYSTEM_CTRL, 1848c2ecf20Sopenharmony_ci CPIA2_CMD_SET_SYSTEM_CTRL, 1858c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VP_SYSTEM_STATE, 1868c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VP_SYSTEM_CTRL, 1878c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VP_SYSTEM_CTRL, 1888c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VP_EXP_MODES, 1898c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VP_EXP_MODES, 1908c2ecf20Sopenharmony_ci CPIA2_CMD_GET_DEVICE_CONFIG, 1918c2ecf20Sopenharmony_ci CPIA2_CMD_SET_DEVICE_CONFIG, 1928c2ecf20Sopenharmony_ci CPIA2_CMD_SET_SERIAL_ADDR, 1938c2ecf20Sopenharmony_ci CPIA2_CMD_SET_SENSOR_CR1, 1948c2ecf20Sopenharmony_ci CPIA2_CMD_GET_VC_CONTROL, 1958c2ecf20Sopenharmony_ci CPIA2_CMD_SET_VC_CONTROL, 1968c2ecf20Sopenharmony_ci CPIA2_CMD_SET_TARGET_KB, 1978c2ecf20Sopenharmony_ci CPIA2_CMD_SET_DEF_JPEG_OPT, 1988c2ecf20Sopenharmony_ci CPIA2_CMD_REHASH_VP4, 1998c2ecf20Sopenharmony_ci CPIA2_CMD_GET_USER_EFFECTS, 2008c2ecf20Sopenharmony_ci CPIA2_CMD_SET_USER_EFFECTS 2018c2ecf20Sopenharmony_ci}; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cienum user_cmd { 2048c2ecf20Sopenharmony_ci COMMAND_NONE = 0x00000001, 2058c2ecf20Sopenharmony_ci COMMAND_SET_FPS = 0x00000002, 2068c2ecf20Sopenharmony_ci COMMAND_SET_COLOR_PARAMS = 0x00000004, 2078c2ecf20Sopenharmony_ci COMMAND_GET_COLOR_PARAMS = 0x00000008, 2088c2ecf20Sopenharmony_ci COMMAND_SET_FORMAT = 0x00000010, /* size, etc */ 2098c2ecf20Sopenharmony_ci COMMAND_SET_FLICKER = 0x00000020 2108c2ecf20Sopenharmony_ci}; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci/*** 2138c2ecf20Sopenharmony_ci * Some defines specific to the 676 chip 2148c2ecf20Sopenharmony_ci ***/ 2158c2ecf20Sopenharmony_ci#define CAMACC_CIF 0x01 2168c2ecf20Sopenharmony_ci#define CAMACC_VGA 0x02 2178c2ecf20Sopenharmony_ci#define CAMACC_QCIF 0x04 2188c2ecf20Sopenharmony_ci#define CAMACC_QVGA 0x08 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_cistruct cpia2_register { 2228c2ecf20Sopenharmony_ci u8 index; 2238c2ecf20Sopenharmony_ci u8 value; 2248c2ecf20Sopenharmony_ci}; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_cistruct cpia2_reg_mask { 2278c2ecf20Sopenharmony_ci u8 index; 2288c2ecf20Sopenharmony_ci u8 and_mask; 2298c2ecf20Sopenharmony_ci u8 or_mask; 2308c2ecf20Sopenharmony_ci u8 fill; 2318c2ecf20Sopenharmony_ci}; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_cistruct cpia2_command { 2348c2ecf20Sopenharmony_ci u32 command; 2358c2ecf20Sopenharmony_ci u8 req_mode; /* (Block or random) | registerBank */ 2368c2ecf20Sopenharmony_ci u8 reg_count; 2378c2ecf20Sopenharmony_ci u8 direction; 2388c2ecf20Sopenharmony_ci u8 start; 2398c2ecf20Sopenharmony_ci union reg_types { 2408c2ecf20Sopenharmony_ci struct cpia2_register registers[32]; 2418c2ecf20Sopenharmony_ci struct cpia2_reg_mask masks[16]; 2428c2ecf20Sopenharmony_ci u8 block_data[64]; 2438c2ecf20Sopenharmony_ci u8 *patch_data; /* points to function defined block */ 2448c2ecf20Sopenharmony_ci } buffer; 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_cistruct camera_params { 2488c2ecf20Sopenharmony_ci struct { 2498c2ecf20Sopenharmony_ci u8 firmware_revision_hi; /* For system register set (bank 0) */ 2508c2ecf20Sopenharmony_ci u8 firmware_revision_lo; 2518c2ecf20Sopenharmony_ci u8 asic_id; /* Video Compressor set (bank 1) */ 2528c2ecf20Sopenharmony_ci u8 asic_rev; 2538c2ecf20Sopenharmony_ci u8 vp_device_hi; /* Video Processor set (bank 2) */ 2548c2ecf20Sopenharmony_ci u8 vp_device_lo; 2558c2ecf20Sopenharmony_ci u8 sensor_flags; 2568c2ecf20Sopenharmony_ci u8 sensor_rev; 2578c2ecf20Sopenharmony_ci } version; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci struct { 2608c2ecf20Sopenharmony_ci u32 device_type; /* enumerated from vendor/product ids. 2618c2ecf20Sopenharmony_ci * Currently, either STV_672 or STV_676 */ 2628c2ecf20Sopenharmony_ci u16 vendor; 2638c2ecf20Sopenharmony_ci u16 product; 2648c2ecf20Sopenharmony_ci u16 device_revision; 2658c2ecf20Sopenharmony_ci } pnp_id; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci struct { 2688c2ecf20Sopenharmony_ci u8 brightness; /* CPIA2_VP_EXPOSURE_TARGET */ 2698c2ecf20Sopenharmony_ci u8 contrast; /* Note: this is CPIA2_VP_YRANGE */ 2708c2ecf20Sopenharmony_ci u8 saturation; /* CPIA2_VP_SATURATION */ 2718c2ecf20Sopenharmony_ci } color_params; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci struct { 2748c2ecf20Sopenharmony_ci u8 cam_register; 2758c2ecf20Sopenharmony_ci u8 flicker_mode_req; /* 1 if flicker on, else never flicker */ 2768c2ecf20Sopenharmony_ci } flicker_control; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci struct { 2798c2ecf20Sopenharmony_ci u8 jpeg_options; 2808c2ecf20Sopenharmony_ci u8 creep_period; 2818c2ecf20Sopenharmony_ci u8 user_squeeze; 2828c2ecf20Sopenharmony_ci u8 inhibit_htables; 2838c2ecf20Sopenharmony_ci } compression; 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci struct { 2868c2ecf20Sopenharmony_ci u8 ohsize; /* output image size */ 2878c2ecf20Sopenharmony_ci u8 ovsize; 2888c2ecf20Sopenharmony_ci u8 hcrop; /* cropping start_pos/4 */ 2898c2ecf20Sopenharmony_ci u8 vcrop; 2908c2ecf20Sopenharmony_ci u8 hphase; /* scaling registers */ 2918c2ecf20Sopenharmony_ci u8 vphase; 2928c2ecf20Sopenharmony_ci u8 hispan; 2938c2ecf20Sopenharmony_ci u8 vispan; 2948c2ecf20Sopenharmony_ci u8 hicrop; 2958c2ecf20Sopenharmony_ci u8 vicrop; 2968c2ecf20Sopenharmony_ci u8 hifraction; 2978c2ecf20Sopenharmony_ci u8 vifraction; 2988c2ecf20Sopenharmony_ci } image_size; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci struct { 3018c2ecf20Sopenharmony_ci int width; /* actual window width */ 3028c2ecf20Sopenharmony_ci int height; /* actual window height */ 3038c2ecf20Sopenharmony_ci } roi; 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci struct { 3068c2ecf20Sopenharmony_ci u8 video_mode; 3078c2ecf20Sopenharmony_ci u8 frame_rate; 3088c2ecf20Sopenharmony_ci u8 video_size; /* Not a register, just a convenience for cropped sizes */ 3098c2ecf20Sopenharmony_ci u8 gpio_direction; 3108c2ecf20Sopenharmony_ci u8 gpio_data; 3118c2ecf20Sopenharmony_ci u8 system_ctrl; 3128c2ecf20Sopenharmony_ci u8 system_state; 3138c2ecf20Sopenharmony_ci u8 lowlight_boost; /* Bool: 0 = off, 1 = on */ 3148c2ecf20Sopenharmony_ci u8 device_config; 3158c2ecf20Sopenharmony_ci u8 exposure_modes; 3168c2ecf20Sopenharmony_ci u8 user_effects; 3178c2ecf20Sopenharmony_ci } vp_params; 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci struct { 3208c2ecf20Sopenharmony_ci u8 pw_control; 3218c2ecf20Sopenharmony_ci u8 wakeup; 3228c2ecf20Sopenharmony_ci u8 vc_control; 3238c2ecf20Sopenharmony_ci u8 vc_mp_direction; 3248c2ecf20Sopenharmony_ci u8 vc_mp_data; 3258c2ecf20Sopenharmony_ci u8 quality; 3268c2ecf20Sopenharmony_ci } vc_params; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci struct { 3298c2ecf20Sopenharmony_ci u8 power_mode; 3308c2ecf20Sopenharmony_ci u8 system_ctrl; 3318c2ecf20Sopenharmony_ci u8 stream_mode; /* This is the current alternate for usb drivers */ 3328c2ecf20Sopenharmony_ci u8 allow_corrupt; 3338c2ecf20Sopenharmony_ci } camera_state; 3348c2ecf20Sopenharmony_ci}; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci#define NUM_SBUF 2 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_cistruct cpia2_sbuf { 3398c2ecf20Sopenharmony_ci char *data; 3408c2ecf20Sopenharmony_ci struct urb *urb; 3418c2ecf20Sopenharmony_ci}; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_cistruct framebuf { 3448c2ecf20Sopenharmony_ci u64 ts; 3458c2ecf20Sopenharmony_ci unsigned long seq; 3468c2ecf20Sopenharmony_ci int num; 3478c2ecf20Sopenharmony_ci int length; 3488c2ecf20Sopenharmony_ci int max_length; 3498c2ecf20Sopenharmony_ci volatile enum frame_status status; 3508c2ecf20Sopenharmony_ci u8 *data; 3518c2ecf20Sopenharmony_ci struct framebuf *next; 3528c2ecf20Sopenharmony_ci}; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_cistruct camera_data { 3558c2ecf20Sopenharmony_ci /* locks */ 3568c2ecf20Sopenharmony_ci struct v4l2_device v4l2_dev; 3578c2ecf20Sopenharmony_ci struct mutex v4l2_lock; /* serialize file operations */ 3588c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler hdl; 3598c2ecf20Sopenharmony_ci struct { 3608c2ecf20Sopenharmony_ci /* Lights control cluster */ 3618c2ecf20Sopenharmony_ci struct v4l2_ctrl *top_light; 3628c2ecf20Sopenharmony_ci struct v4l2_ctrl *bottom_light; 3638c2ecf20Sopenharmony_ci }; 3648c2ecf20Sopenharmony_ci struct v4l2_ctrl *usb_alt; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci /* camera status */ 3678c2ecf20Sopenharmony_ci int first_image_seen; 3688c2ecf20Sopenharmony_ci enum sensors sensor_type; 3698c2ecf20Sopenharmony_ci u8 flush; 3708c2ecf20Sopenharmony_ci struct v4l2_fh *stream_fh; 3718c2ecf20Sopenharmony_ci u8 mmapped; 3728c2ecf20Sopenharmony_ci int streaming; /* 0 = no, 1 = yes */ 3738c2ecf20Sopenharmony_ci int xfer_mode; /* XFER_BULK or XFER_ISOC */ 3748c2ecf20Sopenharmony_ci struct camera_params params; /* camera settings */ 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci /* v4l */ 3778c2ecf20Sopenharmony_ci int video_size; /* VIDEO_SIZE_ */ 3788c2ecf20Sopenharmony_ci struct video_device vdev; /* v4l videodev */ 3798c2ecf20Sopenharmony_ci u32 width; 3808c2ecf20Sopenharmony_ci u32 height; /* Its size */ 3818c2ecf20Sopenharmony_ci __u32 pixelformat; /* Format fourcc */ 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci /* USB */ 3848c2ecf20Sopenharmony_ci struct usb_device *dev; 3858c2ecf20Sopenharmony_ci unsigned char iface; 3868c2ecf20Sopenharmony_ci unsigned int cur_alt; 3878c2ecf20Sopenharmony_ci unsigned int old_alt; 3888c2ecf20Sopenharmony_ci struct cpia2_sbuf sbuf[NUM_SBUF]; /* Double buffering */ 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci wait_queue_head_t wq_stream; 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci /* Buffering */ 3938c2ecf20Sopenharmony_ci u32 frame_size; 3948c2ecf20Sopenharmony_ci int num_frames; 3958c2ecf20Sopenharmony_ci unsigned long frame_count; 3968c2ecf20Sopenharmony_ci u8 *frame_buffer; /* frame buffer data */ 3978c2ecf20Sopenharmony_ci struct framebuf *buffers; 3988c2ecf20Sopenharmony_ci struct framebuf * volatile curbuff; 3998c2ecf20Sopenharmony_ci struct framebuf *workbuff; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci /* MJPEG Extension */ 4028c2ecf20Sopenharmony_ci int APPn; /* Number of APP segment to be written, must be 0..15 */ 4038c2ecf20Sopenharmony_ci int APP_len; /* Length of data in JPEG APPn segment */ 4048c2ecf20Sopenharmony_ci char APP_data[60]; /* Data in the JPEG APPn segment. */ 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci int COM_len; /* Length of data in JPEG COM segment */ 4078c2ecf20Sopenharmony_ci char COM_data[60]; /* Data in JPEG COM segment */ 4088c2ecf20Sopenharmony_ci}; 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci/* v4l */ 4118c2ecf20Sopenharmony_ciint cpia2_register_camera(struct camera_data *cam); 4128c2ecf20Sopenharmony_civoid cpia2_unregister_camera(struct camera_data *cam); 4138c2ecf20Sopenharmony_civoid cpia2_camera_release(struct v4l2_device *v4l2_dev); 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci/* core */ 4168c2ecf20Sopenharmony_ciint cpia2_reset_camera(struct camera_data *cam); 4178c2ecf20Sopenharmony_ciint cpia2_set_low_power(struct camera_data *cam); 4188c2ecf20Sopenharmony_civoid cpia2_dbg_dump_registers(struct camera_data *cam); 4198c2ecf20Sopenharmony_ciint cpia2_match_video_size(int width, int height); 4208c2ecf20Sopenharmony_civoid cpia2_set_camera_state(struct camera_data *cam); 4218c2ecf20Sopenharmony_civoid cpia2_save_camera_state(struct camera_data *cam); 4228c2ecf20Sopenharmony_civoid cpia2_set_color_params(struct camera_data *cam); 4238c2ecf20Sopenharmony_civoid cpia2_set_brightness(struct camera_data *cam, unsigned char value); 4248c2ecf20Sopenharmony_civoid cpia2_set_contrast(struct camera_data *cam, unsigned char value); 4258c2ecf20Sopenharmony_civoid cpia2_set_saturation(struct camera_data *cam, unsigned char value); 4268c2ecf20Sopenharmony_ciint cpia2_set_flicker_mode(struct camera_data *cam, int mode); 4278c2ecf20Sopenharmony_civoid cpia2_set_format(struct camera_data *cam); 4288c2ecf20Sopenharmony_ciint cpia2_send_command(struct camera_data *cam, struct cpia2_command *cmd); 4298c2ecf20Sopenharmony_ciint cpia2_do_command(struct camera_data *cam, 4308c2ecf20Sopenharmony_ci unsigned int command, 4318c2ecf20Sopenharmony_ci unsigned char direction, unsigned char param); 4328c2ecf20Sopenharmony_civoid cpia2_deinit_camera_struct(struct camera_data *cam, struct usb_interface *intf); 4338c2ecf20Sopenharmony_cistruct camera_data *cpia2_init_camera_struct(struct usb_interface *intf); 4348c2ecf20Sopenharmony_ciint cpia2_init_camera(struct camera_data *cam); 4358c2ecf20Sopenharmony_ciint cpia2_allocate_buffers(struct camera_data *cam); 4368c2ecf20Sopenharmony_civoid cpia2_free_buffers(struct camera_data *cam); 4378c2ecf20Sopenharmony_cilong cpia2_read(struct camera_data *cam, 4388c2ecf20Sopenharmony_ci char __user *buf, unsigned long count, int noblock); 4398c2ecf20Sopenharmony_ci__poll_t cpia2_poll(struct camera_data *cam, 4408c2ecf20Sopenharmony_ci struct file *filp, poll_table *wait); 4418c2ecf20Sopenharmony_ciint cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma); 4428c2ecf20Sopenharmony_civoid cpia2_set_property_flip(struct camera_data *cam, int prop_val); 4438c2ecf20Sopenharmony_civoid cpia2_set_property_mirror(struct camera_data *cam, int prop_val); 4448c2ecf20Sopenharmony_ciint cpia2_set_gpio(struct camera_data *cam, unsigned char setting); 4458c2ecf20Sopenharmony_ciint cpia2_set_fps(struct camera_data *cam, int framerate); 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci/* usb */ 4488c2ecf20Sopenharmony_ciint cpia2_usb_init(void); 4498c2ecf20Sopenharmony_civoid cpia2_usb_cleanup(void); 4508c2ecf20Sopenharmony_ciint cpia2_usb_transfer_cmd(struct camera_data *cam, void *registers, 4518c2ecf20Sopenharmony_ci u8 request, u8 start, u8 count, u8 direction); 4528c2ecf20Sopenharmony_ciint cpia2_usb_stream_start(struct camera_data *cam, unsigned int alternate); 4538c2ecf20Sopenharmony_ciint cpia2_usb_stream_stop(struct camera_data *cam); 4548c2ecf20Sopenharmony_ciint cpia2_usb_stream_pause(struct camera_data *cam); 4558c2ecf20Sopenharmony_ciint cpia2_usb_stream_resume(struct camera_data *cam); 4568c2ecf20Sopenharmony_ciint cpia2_usb_change_streaming_alternate(struct camera_data *cam, 4578c2ecf20Sopenharmony_ci unsigned int alt); 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci/* ----------------------- debug functions ---------------------- */ 4618c2ecf20Sopenharmony_ci#ifdef _CPIA2_DEBUG_ 4628c2ecf20Sopenharmony_ci#define ALOG(lev, fmt, args...) printk(lev "%s:%d %s(): " fmt, __FILE__, __LINE__, __func__, ## args) 4638c2ecf20Sopenharmony_ci#define LOG(fmt, args...) ALOG(KERN_INFO, fmt, ## args) 4648c2ecf20Sopenharmony_ci#define ERR(fmt, args...) ALOG(KERN_ERR, fmt, ## args) 4658c2ecf20Sopenharmony_ci#define DBG(fmt, args...) ALOG(KERN_DEBUG, fmt, ## args) 4668c2ecf20Sopenharmony_ci#else 4678c2ecf20Sopenharmony_ci#define ALOG(fmt,args...) printk(fmt,##args) 4688c2ecf20Sopenharmony_ci#define LOG(fmt,args...) ALOG(KERN_INFO "cpia2: "fmt,##args) 4698c2ecf20Sopenharmony_ci#define ERR(fmt,args...) ALOG(KERN_ERR "cpia2: "fmt,##args) 4708c2ecf20Sopenharmony_ci#define DBG(fmn,args...) do {} while(0) 4718c2ecf20Sopenharmony_ci#endif 4728c2ecf20Sopenharmony_ci/* No function or lineno, for shorter lines */ 4738c2ecf20Sopenharmony_ci#define KINFO(fmt, args...) printk(KERN_INFO fmt,##args) 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci#endif 476