From patchwork Fri Feb 12 00:33:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pete Eberlein X-Patchwork-Id: 78975 Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1CLHkpJ007860 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 12 Feb 2010 21:18:22 GMT Received: from 201-13-169-250.dial-up.telesp.net.br ([201.13.169.250] helo=[192.168.30.170]) by bombadil.infradead.org with esmtpsa (Exim 4.69 #1 (Red Hat Linux)) id 1Ng29P-00078r-MV for patchwork-media@patchwork.kernel.org; Fri, 12 Feb 2010 20:30:09 +0000 Resent-From: Mauro Carvalho Chehab Resent-To: Patchwork media Resent-Date: Fri, 12 Feb 2010 18:30:05 -0200 Resent-Message-Id: <4B75BA4D.30305@infradead.org> Resent-User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.22) Gecko/20090609 Red Hat/2.0.0.22-2.el5_3 Lightning/0.9 Thunderbird/2.0.0.22 Received: from bombadil.infradead.org [18.85.46.34] by pedra with IMAP (fetchmail-6.3.6) for (single-drop); Thu, 11 Feb 2010 22:37:20 -0200 (BRST) Received: from vger.kernel.org ([209.132.180.67]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NfjTo-0004K6-Vm; Fri, 12 Feb 2010 00:33:57 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757711Ab0BLAdt (ORCPT + 1 other); Thu, 11 Feb 2010 19:33:49 -0500 Received: from gateway01.websitewelcome.com ([69.56.170.19]:45706 "HELO gateway01.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1757685Ab0BLAds (ORCPT ); Thu, 11 Feb 2010 19:33:48 -0500 Received: (qmail 30179 invoked from network); 12 Feb 2010 00:34:51 -0000 Received: from gator886.hostgator.com (174.120.40.226) by gateway01.websitewelcome.com with SMTP; 12 Feb 2010 00:34:51 -0000 Received: from [66.15.212.169] (port=10330 helo=[10.140.5.12]) by gator886.hostgator.com with esmtpsa (SSLv3:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1NfjTc-0005sP-ID for linux-media@vger.kernel.org; Thu, 11 Feb 2010 18:33:44 -0600 Subject: [PATCH 5/5] ov7640: sensor driver subdev conversion From: Pete Eberlein To: "linux-media@vger.kernel.org" Date: Thu, 11 Feb 2010 16:33:27 -0800 Message-Id: <1265934807.4626.254.camel@pete-desktop> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator886.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - sensoray.com Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 12 Feb 2010 21:18:22 +0000 (UTC) diff -r 378d3bc9a3d6 -r 6d0a37622c1b linux/drivers/media/video/Kconfig --- a/linux/drivers/media/video/Kconfig Thu Feb 11 14:48:26 2010 -0800 +++ b/linux/drivers/media/video/Kconfig Thu Feb 11 14:57:40 2010 -0800 @@ -309,6 +309,13 @@ To compile this driver as a module, choose M here: the module will be called ks0127. +config VIDEO_OV7640 + tristate "OmniVision OV7640 sensor support" + depends on I2C && VIDEO_V4L2 + ---help--- + This is a Video4Linux2 sensor-level driver for the OmniVision + OV7640 camera. It currently only works with the GO7007 driver. + config VIDEO_OV7670 tristate "OmniVision OV7670 sensor support" depends on I2C && VIDEO_V4L2 diff -r 378d3bc9a3d6 -r 6d0a37622c1b linux/drivers/media/video/Makefile --- a/linux/drivers/media/video/Makefile Thu Feb 11 14:48:26 2010 -0800 +++ b/linux/drivers/media/video/Makefile Thu Feb 11 14:57:40 2010 -0800 @@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_CX25840) += cx25840/ obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o +obj-$(CONFIG_VIDEO_OV7640) += ov7640.o obj-$(CONFIG_VIDEO_OV7670) += ov7670.o obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o diff -r 378d3bc9a3d6 -r 6d0a37622c1b linux/drivers/media/video/ov7640.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linux/drivers/media/video/ov7640.c Thu Feb 11 14:57:40 2010 -0800 @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2005-2006 Micronas USA Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License (Version 2) as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. + */ + +#include +#include +#include +#include +#include +#include +#include + +MODULE_DESCRIPTION("OmniVision ov7640 sensor driver"); +MODULE_LICENSE("GPL v2"); + +struct ov7640_info { + struct v4l2_subdev sd; + int brightness; + int contrast; + int saturation; + int hue; +}; + +static inline struct ov7640_info *to_state(struct v4l2_subdev *sd) +{ + return container_of(sd, struct ov7640_info, sd); +} + + +static u8 initial_registers[] = +{ + 0x12, 0x80, + 0x12, 0x54, + 0x14, 0x24, + 0x15, 0x01, + 0x28, 0x20, + 0x75, 0x82, + 0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */ +}; + +static int write_regs(struct i2c_client *client, u8 *regs) +{ + int i; + + for (i = 0; regs[i] != 0xFF; i += 2) + if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0) + return -1; + return 0; +} + + +static int ov7640_g_chip_ident(struct v4l2_subdev *sd, + struct v4l2_dbg_chip_ident *chip) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + + return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_OV7640, 0); +} + +/* ----------------------------------------------------------------------- */ + +static const struct v4l2_subdev_core_ops ov7640_core_ops = { + .g_chip_ident = ov7640_g_chip_ident, +}; + +static const struct v4l2_subdev_ops ov7640_ops = { + .core = &ov7640_core_ops, +}; + +/* ----------------------------------------------------------------------- */ + +static int ov7640_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adapter = client->adapter; + struct v4l2_subdev *sd; + struct ov7640_info *info; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + return -ENODEV; + + info = kzalloc(sizeof(struct ov7640_info), GFP_KERNEL); + if (info == NULL) + return -ENOMEM; + sd = &info->sd; + v4l2_i2c_subdev_init(sd, client, &ov7640_ops); + + client->flags = 0x10; /* I2C_CLIENT_SCCB from wis-i2c.h */ + + v4l_info(client, "chip found @ 0x%02x (%s)\n", + client->addr << 1, client->adapter->name); + + if (write_regs(client, initial_registers) < 0) { + v4l_err(client, "error initializing OV7640\n"); + kfree(info); + return -ENODEV; + } + + return 0; +} + + +static int ov7640_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + + v4l2_device_unregister_subdev(sd); + kfree(to_state(sd)); + return 0; +} + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) +static const struct i2c_device_id ov7640_id[] = { + { "ov7640", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ov7640_id); + +#endif +static struct v4l2_i2c_driver_data v4l2_i2c_data = { + .name = "ov7640", + .probe = ov7640_probe, + .remove = ov7640_remove, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) + .id_table = ov7640_id, +#endif +}; + diff -r 378d3bc9a3d6 -r 6d0a37622c1b linux/drivers/staging/go7007/go7007-usb.c --- a/linux/drivers/staging/go7007/go7007-usb.c Thu Feb 11 14:48:26 2010 -0800 +++ b/linux/drivers/staging/go7007/go7007-usb.c Thu Feb 11 14:57:40 2010 -0800 @@ -265,7 +265,7 @@ .num_i2c_devs = 1, .i2c_devs = { { - .type = "wis_ov7640", + .type = "ov7640", .addr = 0x21, }, }, diff -r 378d3bc9a3d6 -r 6d0a37622c1b linux/include/media/v4l2-chip-ident.h --- a/linux/include/media/v4l2-chip-ident.h Thu Feb 11 14:48:26 2010 -0800 +++ b/linux/include/media/v4l2-chip-ident.h Thu Feb 11 14:57:40 2010 -0800 @@ -65,6 +65,7 @@ V4L2_IDENT_OV9655 = 255, V4L2_IDENT_SOI968 = 256, V4L2_IDENT_OV9640 = 257, + V4L2_IDENT_OV7640 = 258, /* module saa7146: reserved range 300-309 */ V4L2_IDENT_SAA7146 = 300,