18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * stk-webcam.h : Driver for Syntek 1125 USB webcam controller 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2006 Nicolas VIVIEN 68c2ecf20Sopenharmony_ci * Copyright 2007-2008 Jaime Velasco Juan <jsagarribay@gmail.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef STKWEBCAM_H 108c2ecf20Sopenharmony_ci#define STKWEBCAM_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/usb.h> 138c2ecf20Sopenharmony_ci#include <media/v4l2-device.h> 148c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h> 158c2ecf20Sopenharmony_ci#include <media/v4l2-common.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define DRIVER_VERSION "v0.0.1" 188c2ecf20Sopenharmony_ci#define DRIVER_VERSION_NUM 0x000001 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define MAX_ISO_BUFS 3 218c2ecf20Sopenharmony_ci#define ISO_FRAMES_PER_DESC 16 228c2ecf20Sopenharmony_ci#define ISO_MAX_FRAME_SIZE 3 * 1024 238c2ecf20Sopenharmony_ci#define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistruct stk_iso_buf { 268c2ecf20Sopenharmony_ci void *data; 278c2ecf20Sopenharmony_ci int length; 288c2ecf20Sopenharmony_ci int read; 298c2ecf20Sopenharmony_ci struct urb *urb; 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* Streaming IO buffers */ 338c2ecf20Sopenharmony_cistruct stk_sio_buffer { 348c2ecf20Sopenharmony_ci struct v4l2_buffer v4lbuf; 358c2ecf20Sopenharmony_ci char *buffer; 368c2ecf20Sopenharmony_ci int mapcount; 378c2ecf20Sopenharmony_ci struct stk_camera *dev; 388c2ecf20Sopenharmony_ci struct list_head list; 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cienum stk_mode {MODE_VGA, MODE_SXGA, MODE_CIF, MODE_QVGA, MODE_QCIF}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistruct stk_video { 448c2ecf20Sopenharmony_ci enum stk_mode mode; 458c2ecf20Sopenharmony_ci __u32 palette; 468c2ecf20Sopenharmony_ci int hflip; 478c2ecf20Sopenharmony_ci int vflip; 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cienum stk_status { 518c2ecf20Sopenharmony_ci S_PRESENT = 1, 528c2ecf20Sopenharmony_ci S_INITIALISED = 2, 538c2ecf20Sopenharmony_ci S_MEMALLOCD = 4, 548c2ecf20Sopenharmony_ci S_STREAMING = 8, 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci#define is_present(dev) ((dev)->status & S_PRESENT) 578c2ecf20Sopenharmony_ci#define is_initialised(dev) ((dev)->status & S_INITIALISED) 588c2ecf20Sopenharmony_ci#define is_streaming(dev) ((dev)->status & S_STREAMING) 598c2ecf20Sopenharmony_ci#define is_memallocd(dev) ((dev)->status & S_MEMALLOCD) 608c2ecf20Sopenharmony_ci#define set_present(dev) ((dev)->status = S_PRESENT) 618c2ecf20Sopenharmony_ci#define unset_present(dev) ((dev)->status &= \ 628c2ecf20Sopenharmony_ci ~(S_PRESENT|S_INITIALISED|S_STREAMING)) 638c2ecf20Sopenharmony_ci#define set_initialised(dev) ((dev)->status |= S_INITIALISED) 648c2ecf20Sopenharmony_ci#define unset_initialised(dev) ((dev)->status &= ~S_INITIALISED) 658c2ecf20Sopenharmony_ci#define set_memallocd(dev) ((dev)->status |= S_MEMALLOCD) 668c2ecf20Sopenharmony_ci#define unset_memallocd(dev) ((dev)->status &= ~S_MEMALLOCD) 678c2ecf20Sopenharmony_ci#define set_streaming(dev) ((dev)->status |= S_STREAMING) 688c2ecf20Sopenharmony_ci#define unset_streaming(dev) ((dev)->status &= ~S_STREAMING) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct regval { 718c2ecf20Sopenharmony_ci unsigned reg; 728c2ecf20Sopenharmony_ci unsigned val; 738c2ecf20Sopenharmony_ci}; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistruct stk_camera { 768c2ecf20Sopenharmony_ci struct v4l2_device v4l2_dev; 778c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler hdl; 788c2ecf20Sopenharmony_ci struct video_device vdev; 798c2ecf20Sopenharmony_ci struct usb_device *udev; 808c2ecf20Sopenharmony_ci struct usb_interface *interface; 818c2ecf20Sopenharmony_ci int webcam_model; 828c2ecf20Sopenharmony_ci struct file *owner; 838c2ecf20Sopenharmony_ci struct mutex lock; 848c2ecf20Sopenharmony_ci int first_init; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci u8 isoc_ep; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci /* Not sure if this is right */ 898c2ecf20Sopenharmony_ci atomic_t urbs_used; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci struct stk_video vsettings; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci enum stk_status status; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci spinlock_t spinlock; 968c2ecf20Sopenharmony_ci wait_queue_head_t wait_frame; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci struct stk_iso_buf *isobufs; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci int frame_size; 1018c2ecf20Sopenharmony_ci /* Streaming buffers */ 1028c2ecf20Sopenharmony_ci int reading; 1038c2ecf20Sopenharmony_ci unsigned int n_sbufs; 1048c2ecf20Sopenharmony_ci struct stk_sio_buffer *sio_bufs; 1058c2ecf20Sopenharmony_ci struct list_head sio_avail; 1068c2ecf20Sopenharmony_ci struct list_head sio_full; 1078c2ecf20Sopenharmony_ci unsigned sequence; 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci#define vdev_to_camera(d) container_of(d, struct stk_camera, vdev) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciint stk_camera_write_reg(struct stk_camera *, u16, u8); 1138c2ecf20Sopenharmony_ciint stk_camera_read_reg(struct stk_camera *, u16, u8 *); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ciint stk_sensor_init(struct stk_camera *); 1168c2ecf20Sopenharmony_ciint stk_sensor_configure(struct stk_camera *); 1178c2ecf20Sopenharmony_ciint stk_sensor_sleep(struct stk_camera *dev); 1188c2ecf20Sopenharmony_ciint stk_sensor_wakeup(struct stk_camera *dev); 1198c2ecf20Sopenharmony_ciint stk_sensor_set_brightness(struct stk_camera *dev, int br); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#endif 122