From 871480933a1c28f8a9fed4c4d34d06c439a7a422 Mon Sep 17 00:00:00 2001 From: Srikant Patnaik Date: Sun, 11 Jan 2015 12:28:04 +0530 Subject: Moved, renamed, and deleted files The original directory structure was scattered and unorganized. Changes are basically to make it look like kernel structure. --- .../media/video/wmt_v4l2/sensors/ov7675/ov7675.c | 321 +++++++++++++++++++++ .../media/video/wmt_v4l2/sensors/ov7675/ov7675.h | 258 +++++++++++++++++ 2 files changed, 579 insertions(+) create mode 100755 drivers/media/video/wmt_v4l2/sensors/ov7675/ov7675.c create mode 100755 drivers/media/video/wmt_v4l2/sensors/ov7675/ov7675.h (limited to 'drivers/media/video/wmt_v4l2/sensors/ov7675') diff --git a/drivers/media/video/wmt_v4l2/sensors/ov7675/ov7675.c b/drivers/media/video/wmt_v4l2/sensors/ov7675/ov7675.c new file mode 100755 index 00000000..89b72f9e --- /dev/null +++ b/drivers/media/video/wmt_v4l2/sensors/ov7675/ov7675.c @@ -0,0 +1,321 @@ +#include "../cmos-subdev.h" +#include "../../wmt-vid.h" +#include "ov7675.h" + +#define sensor_write_array(sd, arr, sz) \ + cmos_init_8bit_addr(arr, sz, (sd)->i2c_addr) + +#define sensor_read(sd, reg) \ + wmt_vid_i2c_read(sd->i2c_addr, reg) + +#define sensor_write(sd, reg, val) \ + wmt_vid_i2c_write(sd->i2c_addr, reg, val) + +struct cmos_win_size { + char *name; + int width; + int height; + uint8_t *regs; + size_t size; +}; + +#define CMOS_WIN_SIZE(n, w, h, r) \ + {.name = n, .width = w , .height = h, .regs = r, .size = ARRAY_SIZE(r) } + +static const struct cmos_win_size cmos_supported_win_sizes[] = { +// CMOS_WIN_SIZE("QVGA", 320, 240, ov7675_320x240), + CMOS_WIN_SIZE("VGA", 640, 480, ov7675_640x480), +}; + +static const struct cmos_win_size *cmos_select_win(u32 *width, u32 *height) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(cmos_supported_win_sizes); i++) { + if (cmos_supported_win_sizes[i].width == *width && + cmos_supported_win_sizes[i].height == *height) { + *width = cmos_supported_win_sizes[i].width; + *height = cmos_supported_win_sizes[i].height; + return &cmos_supported_win_sizes[i]; + } + } + return NULL; +} + +static int sensor_s_wb(struct cmos_subdev *sd, enum v4l2_wb_mode value) +{ + uint8_t *regs; + size_t size; + + switch (value) { + case WHITE_BALANCE_AUTO: + regs = ov7675_wb_auto; + size = ARRAY_SIZE(ov7675_wb_auto); + break; + case WHITE_BALANCE_INCANDESCENCE: + regs = ov7675_wb_incandescent; + size = ARRAY_SIZE(ov7675_wb_incandescent); + break; + case WHITE_BALANCE_DAYLIGHT: + regs = ov7675_wb_daylight; + size = ARRAY_SIZE(ov7675_wb_daylight); + break; + case WHITE_BALANCE_CLOUDY: + regs = ov7675_wb_cloudy; + size = ARRAY_SIZE(ov7675_wb_cloudy); + break; + case WHITE_BALANCE_FLUORESCENT: + regs = ov7675_wb_fluorescent; + size = ARRAY_SIZE(ov7675_wb_fluorescent); + break; + default: + return -EINVAL; + } + + sensor_write_array(sd, regs, size); + return 0; +} + +static int sensor_s_scenemode(struct cmos_subdev *sd, enum v4l2_scene_mode value) +{ + uint8_t *regs; + size_t size; + + switch (value) { + case SCENE_MODE_AUTO: + regs = ov7675_scene_mode_auto; + size = ARRAY_SIZE(ov7675_scene_mode_auto); + break; + case SCENE_MODE_NIGHTSHOT: + regs = ov7675_scene_mode_night; + size = ARRAY_SIZE(ov7675_scene_mode_night); + break; + default: + return -EINVAL; + } + + sensor_write_array(sd, regs, size); + return 0; +} + +static int sensor_s_exposure(struct cmos_subdev *sd, int value) +{ + uint8_t *regs; + size_t size; + + switch (value) { + case -2: + regs = ov7675_exposure_neg6; + size = ARRAY_SIZE(ov7675_exposure_neg6); + break; + case -1: + regs = ov7675_exposure_neg3; + size = ARRAY_SIZE(ov7675_exposure_neg3); + break; + case 0: + regs = ov7675_exposure_zero; + size = ARRAY_SIZE(ov7675_exposure_zero); + break; + case 1: + regs = ov7675_exposure_pos3; + size = ARRAY_SIZE(ov7675_exposure_pos3); + break; + case 2: + regs = ov7675_exposure_pos6; + size = ARRAY_SIZE(ov7675_exposure_pos6); + break; + default: + return -EINVAL; + } + + sensor_write_array(sd, regs, size); + return 0; +} + +static int sensor_s_hflip(struct cmos_subdev *sd, int value) +{ + uint8_t data; + + data = sensor_read(sd, 0x1e); + + switch (value) { + case 0: + data &= ~0x20; + break; + case 1: + data |= 0x20; + break; + default: + return -EINVAL; + } + + sensor_write(sd, 0x1e, data); + msleep(20); + + return 0; +} + +static int sensor_s_vflip(struct cmos_subdev *sd, int value) +{ + uint8_t data; + + data = sensor_read(sd, 0x1e); + + switch (value) { + case 0: + data &= ~0x10; + break; + case 1: + data |= 0x10; + break; + default: + return -EINVAL; + } + + sensor_write(sd, 0x1e, data); + msleep(20); + return 0; +} + +static int sensor_queryctrl(struct cmos_subdev *sd, struct v4l2_queryctrl *qc) +{ + switch (qc->id) { + case V4L2_CID_VFLIP: + case V4L2_CID_HFLIP: + return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0); + case V4L2_CID_CAMERA_SCENE_MODE: + return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0); + case V4L2_CID_DO_WHITE_BALANCE: + return v4l2_ctrl_query_fill(qc, 0, 3, 1, 0); + case V4L2_CID_EXPOSURE: + return v4l2_ctrl_query_fill(qc, -2, 2, 1, 0); + } + return -EINVAL; +} + +static int sensor_s_ctrl(struct cmos_subdev *sd, struct v4l2_control *ctrl) +{ + switch (ctrl->id) { + case V4L2_CID_CAMERA_SCENE_MODE: + return sensor_s_scenemode(sd, ctrl->value); + case V4L2_CID_DO_WHITE_BALANCE: + return sensor_s_wb(sd, ctrl->value); + case V4L2_CID_EXPOSURE: + return sensor_s_exposure(sd, ctrl->value); + case V4L2_CID_HFLIP: + return sensor_s_hflip(sd, ctrl->value); + case V4L2_CID_VFLIP: + return sensor_s_vflip(sd, ctrl->value); + default: + case WMT_V4L2_CID_CAMERA_ANTIBANDING: + return -EINVAL; + } + return -EINVAL; +} + +static int sensor_g_mbus_fmt(struct cmos_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + return -EINVAL; +} + +static int sensor_s_mbus_fmt(struct cmos_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + const struct cmos_win_size *win; + + win = cmos_select_win(&mf->width, &mf->height); + if (!win) { + pr_err("%s, s_mbus_fmt failed, width %d, height %d\n", + sd->name, mf->width, mf->height); + return -EINVAL; + } + + sensor_write_array(sd, win->regs, win->size); + return 0; +} + +static int sensor_try_mbus_fmt(struct cmos_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + return 0; +} + +static int sensor_enum_framesizes(struct cmos_subdev *sd, + struct v4l2_frmsizeenum *fsize) +{ + int i; + int num_valid = -1; + __u32 index = fsize->index; + + for (i = 0; i < ARRAY_SIZE(cmos_supported_win_sizes); i++) { + const struct cmos_win_size *win = &cmos_supported_win_sizes[index]; + if (index == ++num_valid) { + fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; + fsize->discrete.width = win->width; + fsize->discrete.height = win->height; + return 0; + } + } + + return -EINVAL; +} + +static int sensor_identify(struct cmos_subdev *sd) +{ + return (sensor_read(sd, 0x0a) == sd->id) ? 0 : -EINVAL; +} + +static int sensor_init(struct cmos_subdev *sd) +{ + if (sensor_identify(sd)) { + return -1; + } + + sensor_write_array(sd, ov7675_default_regs_init, + ARRAY_SIZE(ov7675_default_regs_init)); + return 0; +} + +static int sensor_exit(struct cmos_subdev *sd) +{ + return 0; +} + +static struct cmos_subdev_ops ov7675_ops = { + .identify = sensor_identify, + .init = sensor_init, + .exit = sensor_exit, + .queryctrl = sensor_queryctrl, + .s_ctrl = sensor_s_ctrl, + .s_mbus_fmt = sensor_s_mbus_fmt, + .g_mbus_fmt = sensor_g_mbus_fmt, + .try_mbus_fmt = sensor_try_mbus_fmt, + .enum_framesizes = sensor_enum_framesizes, +}; + +struct cmos_subdev ov7675 = { + .name = "ov7675", + .i2c_addr = 0x21, + .id = 0x76, + .max_width = 640, + .max_height = 480, + .ops = &ov7675_ops, +}; + +#if 0 +static int __init ov7675_init(void) +{ + return cmos_register_sudbdev(&ov7675); +} + +static void __exit ov7675_exit(void) +{ + return cmos_unregister_subdev(&ov7675); +} + +module_init(ov7675_init); +module_exit(ov7675_exit); + +MODULE_LICENSE("GPL"); +#endif diff --git a/drivers/media/video/wmt_v4l2/sensors/ov7675/ov7675.h b/drivers/media/video/wmt_v4l2/sensors/ov7675/ov7675.h new file mode 100755 index 00000000..160a45ee --- /dev/null +++ b/drivers/media/video/wmt_v4l2/sensors/ov7675/ov7675.h @@ -0,0 +1,258 @@ +#ifndef OV7675_H +#define OV7675_H + + +// Scene Mode +uint8_t ov7675_scene_mode_auto[] = { + +}; + +uint8_t ov7675_scene_mode_night[] = { + +}; + +// White Balance +uint8_t ov7675_wb_auto [] = { + 0x01,0x56, + 0x02,0x44, + 0x13, 0xe7, +}; + +uint8_t ov7675_wb_incandescent [] = { + 0x13, 0xe5, + 0x01,0x9a, + 0x02,0x40, + 0x6A, 0x48, +}; + +uint8_t ov7675_wb_fluorescent [] = { + 0x13, 0xe5, + 0x01,0x8b, + 0x02,0x42, + 0x6A, 0x40, +}; + +uint8_t ov7675_wb_daylight [] = { + 0x13, 0xe5, + 0x01,0x56, + 0x02,0x5c, + 0x6A, 0x42, +}; + +uint8_t ov7675_wb_cloudy [] = { + 0x13, 0xe5, + 0x01,0x58, + 0x02,0x60, + 0x6A, 0x40, +}; + + +// Exposure +uint8_t ov7675_exposure_neg6[] = { + 0x55,0xb0, +}; + +uint8_t ov7675_exposure_neg3[] = { + 0x55,0x98, +}; + +uint8_t ov7675_exposure_zero[] = { + 0x55,0x00, +}; + +uint8_t ov7675_exposure_pos3[] = { + 0x55,0x18, +}; + +uint8_t ov7675_exposure_pos6[] = { + 0x55,0x30, +}; + + +// Resolution +uint8_t ov7675_320x240[]= { + +}; + +uint8_t ov7675_640x480[] = { + 0x17, 0x13, + 0x18, 0x01, + 0x32, 0xbf, + 0x19, 0x03, + 0x1a, 0x7b, + 0x03, 0x0a, +}; + +uint8_t ov7675_default_regs_init[] = { + 0x12, 0x80, + 0x11, 0x80, + 0x2a, 0x00, + 0x2b, 0x00, + 0x92, 0x66, + 0x93, 0x00, + 0x12, 0x00, + 0x3a, 0x04, + 0x3d, 0xC1, + 0x15, 0x00, + 0xc1, 0x7f, + 0x17, 0x13, + 0x18, 0x01, + 0x32, 0xbF, + 0x19, 0x03, + 0x1a, 0x7b, + 0x03, 0x0a, + 0x0c, 0x00, + 0x3e, 0x00, + 0x70, 0x3a, + 0x71, 0x35, + 0x72, 0x11, + 0x73, 0xf0, + 0xa2, 0x02, + 0x13, 0xe0, + 0x10, 0x00, + 0x14, 0x28, + 0xa5, 0x06, + 0xab, 0x07, + 0x24, 0x58, + 0x25, 0x48, + 0x26, 0x93, + 0x9f, 0x78, + 0xa0, 0x68, + 0xa1, 0x03, + 0xa6, 0xD8, + 0xa7, 0xD8, + 0xa8, 0xf0, + 0xa9, 0x90, + 0xaa, 0x14, + 0x13, 0xe5, + 0x0e, 0x61, + 0x0f, 0x4b, + 0x16, 0x02, + 0x1e, 0x17, //0x07//0x27 + 0x21, 0x02, + 0x22, 0x91, + 0x29, 0x07, + 0x33, 0x0b, + 0x35, 0x0b, + 0x37, 0x1d, + 0x38, 0x71, + 0x39, 0x2a, + 0x3c, 0x78, + 0x4d, 0x40, + 0x4e, 0x20, + 0x69, 0x00, + 0x6b, 0x0a, + 0x74, 0x10, + 0x8d, 0x4f, + 0x8e, 0x00, + 0x8f, 0x00, + 0x90, 0x00, + 0x91, 0x00, + 0x96, 0x00, + 0x9a, 0x80, + 0xb0, 0x84, + 0xb1, 0x0c, + 0xb2, 0x0e, + 0xb3, 0x82, + 0xb8, 0x0a, + 0xbb, 0xa1, + 0x0d, 0x60, + 0x42, 0x80, + 0x62, 0x00, + 0x63, 0x00, + 0x64, 0x10, + 0x65, 0x07, + 0x66, 0x05, + 0x94, 0x10, + 0x95, 0x12, + 0x7a, 0x20,// 0x7a, 0x24, + 0x7b, 0x16,// 0x7b, 0x04, + 0x7c, 0x23,// 0x7c, 0x07, + 0x7d, 0x3c,// 0x7d, 0x12, + 0x7e, 0x5c,// 0x7e, 0x2f, + 0x7f, 0x69,// 0x7f, 0x3f, + 0x80, 0x75,// 0x80, 0x4d, + 0x81, 0x7e,// 0x81, 0x5a, + 0x82, 0x88,// 0x82, 0x69, + 0x83, 0x8f,// 0x83, 0x74, + 0x84, 0x96,// 0x84, 0x7f, + 0x85, 0xa3,// 0x85, 0x91, + 0x86, 0xaf,// 0x86, 0x9e, + 0x87, 0xc4,// 0x87, 0xbb, + 0x88, 0xd7,// 0x88, 0xd2, + 0x89, 0xe8,// 0x89, 0xe5, + 0x43, 0x0a, + 0x44, 0xf0, + 0x45, 0x34, + 0x46, 0x58, + 0x47, 0x28, + 0x48, 0x3a, + 0x59, 0x88, + 0x5a, 0x88, + 0x5b, 0xc2, + 0x5c, 0x60, + 0x5d, 0x58, + 0x5e, 0x10, + 0x6c, 0x0a, + 0x6d, 0x55, + 0x6e, 0x11, + 0x6f, 0x9e, + 0x6a, 0x40, + 0x01, 0x56, + 0x02, 0x44, + 0x13, 0xe7, + 0x4f, 0x95, + 0x50, 0x99, + 0x51, 0x04, + 0x52, 0x1a, + 0x53, 0x7f, + 0x54, 0x99, + 0x58, 0x1a, + 0x3f, 0x02, + 0x75, 0x63, + 0x76, 0xe1, + 0x4c, 0x00, + 0x77, 0x04,//0x01 + 0x4b, 0x09, + 0xc9, 0x60, + 0x41, 0x38, + 0x56, 0x40, + 0x34, 0x11, + 0x3b, 0xaa, + 0xa4, 0x88, + 0x96, 0x00, + 0x97, 0x30, + 0x98, 0x20, + 0x99, 0x30, + 0x9a, 0x84, + 0x9b, 0x29, + 0x9c, 0x03, + 0x9d, 0x99, + 0x9e, 0x99, + 0x78, 0x04, + 0x79, 0x01, + 0xc8, 0xf0, + 0x79, 0x0f, + 0xc8, 0x00, + 0x79, 0x10, + 0xc8, 0x7e, + 0x79, 0x0a, + 0xc8, 0x80, + 0x79, 0x0b, + 0xc8, 0x01, + 0x79, 0x0c, + 0xc8, 0x0f, + 0x79, 0x0d, + 0xc8, 0x20, + 0x79, 0x09, + 0xc8, 0x80, + 0x79, 0x02, + 0xc8, 0xc0, + 0x79, 0x03, + 0xc8, 0x40, + 0x79, 0x05, + 0xc8, 0x30, + 0x79, 0x26, +}; + +#endif -- cgit