/* Common OmniVision camera chip definitions * * Copyright (c) 1999-2003 Mark W. McClelland * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied. */ #ifndef __LINUX_OVSENSOR_H #define __LINUX_OVSENSOR_H #include #include #include "id.h" #include "compat.h" #define OVSENSOR_DEBUG #ifdef OVSENSOR_DEBUG extern int ovcamchip_debug; #define PDEBUG(level, fmt, args...) \ if (ovcamchip_debug >= (level)) info("[%s:%d] " fmt, \ __PRETTY_FUNCTION__, __LINE__ , ## args) #else #define PDEBUG(level, fmt, args...) do {} while(0) #endif #if !defined(err) #define err(format, arg...) printk(KERN_ERR __FILE__ ": " format "\n" , ## arg) #endif #if !defined(info) #define info(format, arg...) printk(KERN_INFO __FILE__ ": " format "\n" , \ ## arg) #endif #if !defined(warn) #define warn(format, arg...) printk(KERN_WARNING __FILE__ ": " format "\n" , \ ## arg) #endif /* Number of times to retry chip detection. Increase this if you are getting * "Failed to init sensor" */ #define I2C_DETECT_RETRIES 10 /* --------------------------------- */ /* ENUMERATIONS */ /* --------------------------------- */ /* Controls */ enum { OVSENSOR_CID_CONT, /* Contrast */ OVSENSOR_CID_BRIGHT, /* Brightness */ OVSENSOR_CID_SAT, /* Saturation */ OVSENSOR_CID_HUE, /* Hue */ OVSENSOR_CID_EXP, /* Exposure */ OVSENSOR_CID_FREQ, /* Light frequency */ OVSENSOR_CID_BANDFILT, /* Banding filter */ OVSENSOR_CID_AUTOBRIGHT, /* Auto brightness */ OVSENSOR_CID_AUTOEXP, /* Auto exposure */ OVSENSOR_CID_BACKLIGHT, /* Back light compensation */ OVSENSOR_CID_MIRROR, /* Mirror horizontally */ }; #if defined(HAVE_V4L2) /* Don't use these values from userspace!! They are translated by the * upper-layer driver, and are not guaranteed to remain stable anyway. Instead, * find private controls by name. */ #define OVSENSOR_V4L2_CID_AEC (V4L2_CID_PRIVATE_BASE + 0) #define OVSENSOR_V4L2_CID_LASTP1 (V4L2_CID_PRIVATE_BASE + 1) /* Last + 1 */ #endif /* Sensor types */ #define NUM_SEN_TYPES 10 enum { SEN_UNKNOWN, SEN_OV76BE, SEN_OV7610, SEN_OV7620, SEN_OV7620AE, SEN_OV6620, SEN_OV6630, SEN_OV6630AE, SEN_OV6630AF, SEN_SAA7111A, }; /* --------------------------------- */ /* I2C ADDRESSES */ /* --------------------------------- */ #define OV7xx0_SID (0x42 >> 1) #define OV6xx0_SID (0xC0 >> 1) /* --------------------------------- */ /* API */ /* --------------------------------- */ struct ovsensor_regvals { unsigned char reg; unsigned char val; }; struct ovsensor_control { __u32 id; __s32 value; }; struct ovsensor_ops { int (*init)(struct i2c_client *); int (*free)(struct i2c_client *); int (*command)(struct i2c_client *, unsigned int, void *); }; struct ovsensor_window { int x; int y; int width; int height; int format; int quarter; /* Scale width and height down 2x */ /* This stuff will be removed eventually */ int clockdiv; /* Clock divisor setting */ }; struct ovsensor { struct ovsensor_ops *sops; void *spriv; /* Private data for OV7x10.c etc... */ int subtype; /* = SEN_OV7610 etc... */ int mono; /* Monochrome sensor? (invalid until init) */ int initialized; /* OVSENSOR_CMD_INITIALIZE was successful */ #if defined(HAVE_V4L2) /* V4L2 controls */ struct v4l2_queryctrl qc_brightness; struct v4l2_queryctrl qc_contrast; struct v4l2_queryctrl qc_saturation; struct v4l2_queryctrl qc_red_balance; struct v4l2_queryctrl qc_blue_balance; struct v4l2_queryctrl qc_agc; struct v4l2_queryctrl qc_gain; struct v4l2_queryctrl qc_exposure; struct v4l2_queryctrl qc_awb; /* Private controls */ struct v4l2_queryctrl qc_aec; #endif }; /* Commands */ #define OVCAMCHIP_CMD_Q_SUBTYPE _IOR (0x88, 0x00, int) #define OVCAMCHIP_CMD_INITIALIZE _IOW (0x88, 0x01, int) /* You must call OVCAMCHIP_CMD_INITIALIZE before any of commands below! */ #define OVCAMCHIP_CMD_S_CTRL _IOW (0x88, 0x02, struct ovsensor_control) #define OVCAMCHIP_CMD_G_CTRL _IOWR (0x88, 0x03, struct ovsensor_control) #define OVCAMCHIP_CMD_S_MODE _IOW (0x88, 0x04, struct ovsensor_window) #define OVCAMCHIP_MAX_CMD _IO (0x88, 0x3f) #if 1 /* Temporary aliases, for compatibility with w9968cf driver */ #define OVSENSOR_CMD_Q_SUBTYPE OVCAMCHIP_CMD_Q_SUBTYPE #define OVSENSOR_CMD_INITIALIZE OVCAMCHIP_CMD_INITIALIZE #define OVSENSOR_CMD_S_CTRL OVCAMCHIP_CMD_S_CTRL #define OVSENSOR_CMD_G_CTRL OVCAMCHIP_CMD_G_CTRL #define OVSENSOR_CMD_S_MODE OVCAMCHIP_CMD_S_MODE #endif /* --------------------------------- */ /* I2C I/O */ /* --------------------------------- */ static inline int ov_read(struct i2c_client *c, unsigned char reg, unsigned char *value) { int rc; rc = i2c_smbus_read_byte_data(c, reg); *value = (unsigned char) rc; return rc; } static inline int ov_write(struct i2c_client *c, unsigned char reg, unsigned char value ) { return i2c_smbus_write_byte_data(c, reg, value); } /* --------------------------------- */ /* FUNCTION PROTOTYPES */ /* --------------------------------- */ /* Functions in ovsensor.c */ extern int ov_write_regvals(struct i2c_client *c, struct ovsensor_regvals *rvals); extern int ov_write_mask(struct i2c_client *c, unsigned char reg, unsigned char value, unsigned char mask); #if defined(HAVE_V4L2) extern struct v4l2_queryctrl * ovsensor_get_qc(struct ovsensor *ov, __u32 id); #endif #endif