PageRenderTime 24ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/media/usb/cpia2/cpia2.h

https://gitlab.com/openbar/rpi-linux
C Header | 487 lines | 356 code | 60 blank | 71 comment | 0 complexity | aea7e60fec26ab412c5e264c5cfd6ec9 MD5 | raw file
  1. /****************************************************************************
  2. *
  3. * Filename: cpia2.h
  4. *
  5. * Copyright 2001, STMicrolectronics, Inc.
  6. *
  7. * Contact: steve.miller@st.com
  8. *
  9. * Description:
  10. * This is a USB driver for CPiA2 based video cameras.
  11. *
  12. * This driver is modelled on the cpia usb driver by
  13. * Jochen Scharrlach and Johannes Erdfeldt.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. *
  29. ****************************************************************************/
  30. #ifndef __CPIA2_H__
  31. #define __CPIA2_H__
  32. #include <linux/videodev2.h>
  33. #include <linux/usb.h>
  34. #include <linux/poll.h>
  35. #include <media/v4l2-common.h>
  36. #include <media/v4l2-device.h>
  37. #include <media/v4l2-ctrls.h>
  38. #include "cpia2_registers.h"
  39. /* define for verbose debug output */
  40. //#define _CPIA2_DEBUG_
  41. /***
  42. * Image defines
  43. ***/
  44. /* Misc constants */
  45. #define ALLOW_CORRUPT 0 /* Causes collater to discard checksum */
  46. /* USB Transfer mode */
  47. #define XFER_ISOC 0
  48. #define XFER_BULK 1
  49. /* USB Alternates */
  50. #define USBIF_CMDONLY 0
  51. #define USBIF_BULK 1
  52. #define USBIF_ISO_1 2 /* 128 bytes/ms */
  53. #define USBIF_ISO_2 3 /* 384 bytes/ms */
  54. #define USBIF_ISO_3 4 /* 640 bytes/ms */
  55. #define USBIF_ISO_4 5 /* 768 bytes/ms */
  56. #define USBIF_ISO_5 6 /* 896 bytes/ms */
  57. #define USBIF_ISO_6 7 /* 1023 bytes/ms */
  58. /* Flicker Modes */
  59. #define NEVER_FLICKER 0
  60. #define FLICKER_60 60
  61. #define FLICKER_50 50
  62. /* Debug flags */
  63. #define DEBUG_NONE 0
  64. #define DEBUG_REG 0x00000001
  65. #define DEBUG_DUMP_PATCH 0x00000002
  66. #define DEBUG_DUMP_REGS 0x00000004
  67. /***
  68. * Video frame sizes
  69. ***/
  70. enum {
  71. VIDEOSIZE_VGA = 0, /* 640x480 */
  72. VIDEOSIZE_CIF, /* 352x288 */
  73. VIDEOSIZE_QVGA, /* 320x240 */
  74. VIDEOSIZE_QCIF, /* 176x144 */
  75. VIDEOSIZE_288_216,
  76. VIDEOSIZE_256_192,
  77. VIDEOSIZE_224_168,
  78. VIDEOSIZE_192_144,
  79. };
  80. #define STV_IMAGE_CIF_ROWS 288
  81. #define STV_IMAGE_CIF_COLS 352
  82. #define STV_IMAGE_QCIF_ROWS 144
  83. #define STV_IMAGE_QCIF_COLS 176
  84. #define STV_IMAGE_VGA_ROWS 480
  85. #define STV_IMAGE_VGA_COLS 640
  86. #define STV_IMAGE_QVGA_ROWS 240
  87. #define STV_IMAGE_QVGA_COLS 320
  88. #define JPEG_MARKER_COM (1<<6) /* Comment segment */
  89. /***
  90. * Enums
  91. ***/
  92. /* Sensor types available with cpia2 asics */
  93. enum sensors {
  94. CPIA2_SENSOR_410,
  95. CPIA2_SENSOR_500
  96. };
  97. /* Asic types available in the CPiA2 architecture */
  98. #define CPIA2_ASIC_672 0x67
  99. /* Device types (stv672, stv676, etc) */
  100. #define DEVICE_STV_672 0x0001
  101. #define DEVICE_STV_676 0x0002
  102. enum frame_status {
  103. FRAME_EMPTY,
  104. FRAME_READING, /* In the process of being grabbed into */
  105. FRAME_READY, /* Ready to be read */
  106. FRAME_ERROR,
  107. };
  108. /***
  109. * Register access (for USB request byte)
  110. ***/
  111. enum {
  112. CAMERAACCESS_SYSTEM = 0,
  113. CAMERAACCESS_VC,
  114. CAMERAACCESS_VP,
  115. CAMERAACCESS_IDATA
  116. };
  117. #define CAMERAACCESS_TYPE_BLOCK 0x00
  118. #define CAMERAACCESS_TYPE_RANDOM 0x04
  119. #define CAMERAACCESS_TYPE_MASK 0x08
  120. #define CAMERAACCESS_TYPE_REPEAT 0x0C
  121. #define TRANSFER_READ 0
  122. #define TRANSFER_WRITE 1
  123. #define DEFAULT_ALT USBIF_ISO_6
  124. #define DEFAULT_BRIGHTNESS 0x46
  125. #define DEFAULT_CONTRAST 0x93
  126. #define DEFAULT_SATURATION 0x7f
  127. /* Power state */
  128. #define HI_POWER_MODE CPIA2_SYSTEM_CONTROL_HIGH_POWER
  129. #define LO_POWER_MODE CPIA2_SYSTEM_CONTROL_LOW_POWER
  130. /********
  131. * Commands
  132. *******/
  133. enum {
  134. CPIA2_CMD_NONE = 0,
  135. CPIA2_CMD_GET_VERSION,
  136. CPIA2_CMD_GET_PNP_ID,
  137. CPIA2_CMD_GET_ASIC_TYPE,
  138. CPIA2_CMD_GET_SENSOR,
  139. CPIA2_CMD_GET_VP_DEVICE,
  140. CPIA2_CMD_GET_VP_BRIGHTNESS,
  141. CPIA2_CMD_SET_VP_BRIGHTNESS,
  142. CPIA2_CMD_GET_CONTRAST,
  143. CPIA2_CMD_SET_CONTRAST,
  144. CPIA2_CMD_GET_VP_SATURATION,
  145. CPIA2_CMD_SET_VP_SATURATION,
  146. CPIA2_CMD_GET_VP_GPIO_DIRECTION,
  147. CPIA2_CMD_SET_VP_GPIO_DIRECTION,
  148. CPIA2_CMD_GET_VP_GPIO_DATA,
  149. CPIA2_CMD_SET_VP_GPIO_DATA,
  150. CPIA2_CMD_GET_VC_MP_GPIO_DIRECTION,
  151. CPIA2_CMD_SET_VC_MP_GPIO_DIRECTION,
  152. CPIA2_CMD_GET_VC_MP_GPIO_DATA,
  153. CPIA2_CMD_SET_VC_MP_GPIO_DATA,
  154. CPIA2_CMD_ENABLE_PACKET_CTRL,
  155. CPIA2_CMD_GET_FLICKER_MODES,
  156. CPIA2_CMD_SET_FLICKER_MODES,
  157. CPIA2_CMD_RESET_FIFO, /* clear fifo and enable stream block */
  158. CPIA2_CMD_SET_HI_POWER,
  159. CPIA2_CMD_SET_LOW_POWER,
  160. CPIA2_CMD_CLEAR_V2W_ERR,
  161. CPIA2_CMD_SET_USER_MODE,
  162. CPIA2_CMD_GET_USER_MODE,
  163. CPIA2_CMD_FRAMERATE_REQ,
  164. CPIA2_CMD_SET_COMPRESSION_STATE,
  165. CPIA2_CMD_GET_WAKEUP,
  166. CPIA2_CMD_SET_WAKEUP,
  167. CPIA2_CMD_GET_PW_CONTROL,
  168. CPIA2_CMD_SET_PW_CONTROL,
  169. CPIA2_CMD_GET_SYSTEM_CTRL,
  170. CPIA2_CMD_SET_SYSTEM_CTRL,
  171. CPIA2_CMD_GET_VP_SYSTEM_STATE,
  172. CPIA2_CMD_GET_VP_SYSTEM_CTRL,
  173. CPIA2_CMD_SET_VP_SYSTEM_CTRL,
  174. CPIA2_CMD_GET_VP_EXP_MODES,
  175. CPIA2_CMD_SET_VP_EXP_MODES,
  176. CPIA2_CMD_GET_DEVICE_CONFIG,
  177. CPIA2_CMD_SET_DEVICE_CONFIG,
  178. CPIA2_CMD_SET_SERIAL_ADDR,
  179. CPIA2_CMD_SET_SENSOR_CR1,
  180. CPIA2_CMD_GET_VC_CONTROL,
  181. CPIA2_CMD_SET_VC_CONTROL,
  182. CPIA2_CMD_SET_TARGET_KB,
  183. CPIA2_CMD_SET_DEF_JPEG_OPT,
  184. CPIA2_CMD_REHASH_VP4,
  185. CPIA2_CMD_GET_USER_EFFECTS,
  186. CPIA2_CMD_SET_USER_EFFECTS
  187. };
  188. enum user_cmd {
  189. COMMAND_NONE = 0x00000001,
  190. COMMAND_SET_FPS = 0x00000002,
  191. COMMAND_SET_COLOR_PARAMS = 0x00000004,
  192. COMMAND_GET_COLOR_PARAMS = 0x00000008,
  193. COMMAND_SET_FORMAT = 0x00000010, /* size, etc */
  194. COMMAND_SET_FLICKER = 0x00000020
  195. };
  196. /***
  197. * Some defines specific to the 676 chip
  198. ***/
  199. #define CAMACC_CIF 0x01
  200. #define CAMACC_VGA 0x02
  201. #define CAMACC_QCIF 0x04
  202. #define CAMACC_QVGA 0x08
  203. struct cpia2_register {
  204. u8 index;
  205. u8 value;
  206. };
  207. struct cpia2_reg_mask {
  208. u8 index;
  209. u8 and_mask;
  210. u8 or_mask;
  211. u8 fill;
  212. };
  213. struct cpia2_command {
  214. u32 command;
  215. u8 req_mode; /* (Block or random) | registerBank */
  216. u8 reg_count;
  217. u8 direction;
  218. u8 start;
  219. union reg_types {
  220. struct cpia2_register registers[32];
  221. struct cpia2_reg_mask masks[16];
  222. u8 block_data[64];
  223. u8 *patch_data; /* points to function defined block */
  224. } buffer;
  225. };
  226. struct camera_params {
  227. struct {
  228. u8 firmware_revision_hi; /* For system register set (bank 0) */
  229. u8 firmware_revision_lo;
  230. u8 asic_id; /* Video Compressor set (bank 1) */
  231. u8 asic_rev;
  232. u8 vp_device_hi; /* Video Processor set (bank 2) */
  233. u8 vp_device_lo;
  234. u8 sensor_flags;
  235. u8 sensor_rev;
  236. } version;
  237. struct {
  238. u32 device_type; /* enumerated from vendor/product ids.
  239. * Currently, either STV_672 or STV_676 */
  240. u16 vendor;
  241. u16 product;
  242. u16 device_revision;
  243. } pnp_id;
  244. struct {
  245. u8 brightness; /* CPIA2_VP_EXPOSURE_TARGET */
  246. u8 contrast; /* Note: this is CPIA2_VP_YRANGE */
  247. u8 saturation; /* CPIA2_VP_SATURATION */
  248. } color_params;
  249. struct {
  250. u8 cam_register;
  251. u8 flicker_mode_req; /* 1 if flicker on, else never flicker */
  252. } flicker_control;
  253. struct {
  254. u8 jpeg_options;
  255. u8 creep_period;
  256. u8 user_squeeze;
  257. u8 inhibit_htables;
  258. } compression;
  259. struct {
  260. u8 ohsize; /* output image size */
  261. u8 ovsize;
  262. u8 hcrop; /* cropping start_pos/4 */
  263. u8 vcrop;
  264. u8 hphase; /* scaling registers */
  265. u8 vphase;
  266. u8 hispan;
  267. u8 vispan;
  268. u8 hicrop;
  269. u8 vicrop;
  270. u8 hifraction;
  271. u8 vifraction;
  272. } image_size;
  273. struct {
  274. int width; /* actual window width */
  275. int height; /* actual window height */
  276. } roi;
  277. struct {
  278. u8 video_mode;
  279. u8 frame_rate;
  280. u8 video_size; /* Not a register, just a convenience for cropped sizes */
  281. u8 gpio_direction;
  282. u8 gpio_data;
  283. u8 system_ctrl;
  284. u8 system_state;
  285. u8 lowlight_boost; /* Bool: 0 = off, 1 = on */
  286. u8 device_config;
  287. u8 exposure_modes;
  288. u8 user_effects;
  289. } vp_params;
  290. struct {
  291. u8 pw_control;
  292. u8 wakeup;
  293. u8 vc_control;
  294. u8 vc_mp_direction;
  295. u8 vc_mp_data;
  296. u8 quality;
  297. } vc_params;
  298. struct {
  299. u8 power_mode;
  300. u8 system_ctrl;
  301. u8 stream_mode; /* This is the current alternate for usb drivers */
  302. u8 allow_corrupt;
  303. } camera_state;
  304. };
  305. #define NUM_SBUF 2
  306. struct cpia2_sbuf {
  307. char *data;
  308. struct urb *urb;
  309. };
  310. struct framebuf {
  311. struct timeval timestamp;
  312. unsigned long seq;
  313. int num;
  314. int length;
  315. int max_length;
  316. volatile enum frame_status status;
  317. u8 *data;
  318. struct framebuf *next;
  319. };
  320. struct camera_data {
  321. /* locks */
  322. struct v4l2_device v4l2_dev;
  323. struct mutex v4l2_lock; /* serialize file operations */
  324. struct v4l2_ctrl_handler hdl;
  325. struct {
  326. /* Lights control cluster */
  327. struct v4l2_ctrl *top_light;
  328. struct v4l2_ctrl *bottom_light;
  329. };
  330. struct v4l2_ctrl *usb_alt;
  331. /* camera status */
  332. int first_image_seen;
  333. enum sensors sensor_type;
  334. u8 flush;
  335. struct v4l2_fh *stream_fh;
  336. u8 mmapped;
  337. int streaming; /* 0 = no, 1 = yes */
  338. int xfer_mode; /* XFER_BULK or XFER_ISOC */
  339. struct camera_params params; /* camera settings */
  340. /* v4l */
  341. int video_size; /* VIDEO_SIZE_ */
  342. struct video_device vdev; /* v4l videodev */
  343. u32 width;
  344. u32 height; /* Its size */
  345. __u32 pixelformat; /* Format fourcc */
  346. /* USB */
  347. struct usb_device *dev;
  348. unsigned char iface;
  349. unsigned int cur_alt;
  350. unsigned int old_alt;
  351. struct cpia2_sbuf sbuf[NUM_SBUF]; /* Double buffering */
  352. wait_queue_head_t wq_stream;
  353. /* Buffering */
  354. u32 frame_size;
  355. int num_frames;
  356. unsigned long frame_count;
  357. u8 *frame_buffer; /* frame buffer data */
  358. struct framebuf *buffers;
  359. struct framebuf * volatile curbuff;
  360. struct framebuf *workbuff;
  361. /* MJPEG Extension */
  362. int APPn; /* Number of APP segment to be written, must be 0..15 */
  363. int APP_len; /* Length of data in JPEG APPn segment */
  364. char APP_data[60]; /* Data in the JPEG APPn segment. */
  365. int COM_len; /* Length of data in JPEG COM segment */
  366. char COM_data[60]; /* Data in JPEG COM segment */
  367. };
  368. /* v4l */
  369. int cpia2_register_camera(struct camera_data *cam);
  370. void cpia2_unregister_camera(struct camera_data *cam);
  371. void cpia2_camera_release(struct v4l2_device *v4l2_dev);
  372. /* core */
  373. int cpia2_reset_camera(struct camera_data *cam);
  374. int cpia2_set_low_power(struct camera_data *cam);
  375. void cpia2_dbg_dump_registers(struct camera_data *cam);
  376. int cpia2_match_video_size(int width, int height);
  377. void cpia2_set_camera_state(struct camera_data *cam);
  378. void cpia2_save_camera_state(struct camera_data *cam);
  379. void cpia2_set_color_params(struct camera_data *cam);
  380. void cpia2_set_brightness(struct camera_data *cam, unsigned char value);
  381. void cpia2_set_contrast(struct camera_data *cam, unsigned char value);
  382. void cpia2_set_saturation(struct camera_data *cam, unsigned char value);
  383. int cpia2_set_flicker_mode(struct camera_data *cam, int mode);
  384. void cpia2_set_format(struct camera_data *cam);
  385. int cpia2_send_command(struct camera_data *cam, struct cpia2_command *cmd);
  386. int cpia2_do_command(struct camera_data *cam,
  387. unsigned int command,
  388. unsigned char direction, unsigned char param);
  389. struct camera_data *cpia2_init_camera_struct(struct usb_interface *intf);
  390. int cpia2_init_camera(struct camera_data *cam);
  391. int cpia2_allocate_buffers(struct camera_data *cam);
  392. void cpia2_free_buffers(struct camera_data *cam);
  393. long cpia2_read(struct camera_data *cam,
  394. char __user *buf, unsigned long count, int noblock);
  395. unsigned int cpia2_poll(struct camera_data *cam,
  396. struct file *filp, poll_table *wait);
  397. int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma);
  398. void cpia2_set_property_flip(struct camera_data *cam, int prop_val);
  399. void cpia2_set_property_mirror(struct camera_data *cam, int prop_val);
  400. int cpia2_set_gpio(struct camera_data *cam, unsigned char setting);
  401. int cpia2_set_fps(struct camera_data *cam, int framerate);
  402. /* usb */
  403. int cpia2_usb_init(void);
  404. void cpia2_usb_cleanup(void);
  405. int cpia2_usb_transfer_cmd(struct camera_data *cam, void *registers,
  406. u8 request, u8 start, u8 count, u8 direction);
  407. int cpia2_usb_stream_start(struct camera_data *cam, unsigned int alternate);
  408. int cpia2_usb_stream_stop(struct camera_data *cam);
  409. int cpia2_usb_stream_pause(struct camera_data *cam);
  410. int cpia2_usb_stream_resume(struct camera_data *cam);
  411. int cpia2_usb_change_streaming_alternate(struct camera_data *cam,
  412. unsigned int alt);
  413. /* ----------------------- debug functions ---------------------- */
  414. #ifdef _CPIA2_DEBUG_
  415. #define ALOG(lev, fmt, args...) printk(lev "%s:%d %s(): " fmt, __FILE__, __LINE__, __func__, ## args)
  416. #define LOG(fmt, args...) ALOG(KERN_INFO, fmt, ## args)
  417. #define ERR(fmt, args...) ALOG(KERN_ERR, fmt, ## args)
  418. #define DBG(fmt, args...) ALOG(KERN_DEBUG, fmt, ## args)
  419. #else
  420. #define ALOG(fmt,args...) printk(fmt,##args)
  421. #define LOG(fmt,args...) ALOG(KERN_INFO "cpia2: "fmt,##args)
  422. #define ERR(fmt,args...) ALOG(KERN_ERR "cpia2: "fmt,##args)
  423. #define DBG(fmn,args...) do {} while(0)
  424. #endif
  425. /* No function or lineno, for shorter lines */
  426. #define KINFO(fmt, args...) printk(KERN_INFO fmt,##args)
  427. #endif