From patchwork Tue May 18 09:23:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Zhang X-Patchwork-Id: 100379 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4I9PCHA004794 for ; Tue, 18 May 2010 09:25:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756747Ab0ERJZL (ORCPT ); Tue, 18 May 2010 05:25:11 -0400 Received: from mga14.intel.com ([143.182.124.37]:8493 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756712Ab0ERJZK convert rfc822-to-8bit (ORCPT ); Tue, 18 May 2010 05:25:10 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 18 May 2010 02:25:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.53,254,1272870000"; d="scan'208,223";a="278374670" Received: from pgsmsx602.gar.corp.intel.com ([10.221.43.81]) by azsmga001.ch.intel.com with ESMTP; 18 May 2010 02:25:08 -0700 Received: from shsmsx602.ccr.corp.intel.com (10.239.4.104) by pgsmsx602.gar.corp.intel.com (10.221.43.81) with Microsoft SMTP Server (TLS) id 8.2.176.0; Tue, 18 May 2010 17:24:01 +0800 Received: from shsmsx501.ccr.corp.intel.com ([10.239.4.141]) by SHSMSX602.ccr.corp.intel.com ([10.239.4.104]) with mapi; Tue, 18 May 2010 17:24:01 +0800 From: "Zhang, Xiaolin" To: "linux-media@vger.kernel.org" Date: Tue, 18 May 2010 17:23:56 +0800 Subject: [PATCH v3 8/8] V4L2 subdev patchset for Intel Moorestown Camera Imaging Subsystem Thread-Topic: [PATCH v3 8/8] V4L2 subdev patchset for Intel Moorestown Camera Imaging Subsystem Thread-Index: Acr2a9clQxJH2tl/TqCsTv6gZsCcNg== Message-ID: <33AB447FBD802F4E932063B962385B351E895735@shsmsx501.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-cr-puzzleid: {E8704FF2-EF95-4402-B86F-FEA9C9A3D460} x-cr-hashedpuzzle: AkLp AtLH BVuy ER01 EcxB EgmK GsTZ H4Zk Jq8F KO0c KTDA Kga6 LQ3b L1ON MBtA MHGI; 1; bABpAG4AdQB4AC0AbQBlAGQAaQBhAEAAdgBnAGUAcgAuAGsAZQByAG4AZQBsAC4AbwByAGcA; Sosha1_v1; 7; {E8704FF2-EF95-4402-B86F-FEA9C9A3D460}; eABpAGEAbwBsAGkAbgAuAHoAaABhAG4AZwBAAGkAbgB0AGUAbAAuAGMAbwBtAA==; Tue, 18 May 2010 09:23:56 GMT; WwBQAEEAVABDAEgAIAB2ADMAIAA4AC8AOABdACAAVgA0AEwAMgAgAHMAdQBiAGQAZQB2ACAAcABhAHQAYwBoAHMAZQB0ACAAZgBvAHIAIABJAG4AdABlAGwAIABNAG8AbwByAGUAcwB0AG8AdwBuACAAQwBhAG0AZQByAGEAIABJAG0AYQBnAGkAbgBnACAAUwB1AGIAcwB5AHMAdABlAG0A acceptlanguage: en-US MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 18 May 2010 09:25:12 +0000 (UTC) diff --git a/drivers/media/video/mrstflash.c b/drivers/media/video/mrstflash.c new file mode 100644 index 0000000..927939b --- /dev/null +++ b/drivers/media/video/mrstflash.c @@ -0,0 +1,151 @@ +/* + * Support for Moorestown Langwell Camera Imaging camera flash. + * + * Copyright (c) 2009 Intel Corporation. All Rights Reserved. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * + * Xiaolin Zhang + */ + +#include +#include +#include +#include +#include + +static int debug; +module_param(debug, bool, 0644); +MODULE_PARM_DESC(debug, "Debug level (0-1)"); + +MODULE_AUTHOR("Xiaolin Zhang "); +MODULE_DESCRIPTION("A low-level driver for mrst flash"); +MODULE_LICENSE("GPL"); + +static int flash_g_chip_ident(struct v4l2_subdev *sd, + struct v4l2_dbg_chip_ident *chip) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + + #define V4L2_IDENT_MRST_FLASH 8248 + return v4l2_chip_ident_i2c_client(client, chip, + V4L2_IDENT_MRST_FLASH, 0); +} + +static const struct v4l2_subdev_core_ops flash_core_ops = { + .g_chip_ident = flash_g_chip_ident, +}; +static const struct v4l2_subdev_ops flash_ops = { + .core = &flash_core_ops, +}; + +static int flash_detect(struct i2c_client *client) +{ + struct i2c_adapter *adapter = client->adapter; + u8 pid; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + return -ENODEV; + + if (adapter->nr != 0) + return -ENODEV; + + pid = i2c_smbus_read_byte_data(client, 0x10); + if (pid == 0x18) { + printk(KERN_ERR "camera flash device found\n"); + v4l_dbg(1, debug, client, "found camera flash device"); + } else { + printk(KERN_ERR "no camera flash device found\n"); + return -ENODEV; + } + + return 0; +} + +static int flash_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + u8 pid, ver; + int ret = -1; + struct v4l2_subdev *sd; + + v4l_info(client, "chip found @ 0x%x (%s)\n", + client->addr << 1, client->adapter->name); + + sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); + ret = flash_detect(client); + if (ret) + return -ENODEV; + + v4l2_i2c_subdev_init(sd, client, &flash_ops); + + ver = i2c_smbus_read_byte_data(client, 0x50); + v4l_dbg(1, debug, client, "detect:CST from device is 0x%x", ver); + pid = i2c_smbus_read_byte_data(client, 0x20); + v4l_dbg(1, debug, client, "detect:MFPC from device is 0x%x", pid); + pid = i2c_smbus_read_byte_data(client, 0xA0); + v4l_dbg(1, debug, client, "detect:TCC from device is 0x%x", pid); + pid = i2c_smbus_read_byte_data(client, 0xB0); + v4l_dbg(1, debug, client, "detect:FCC from device is 0x%x", pid); + pid = i2c_smbus_read_byte_data(client, 0xC0); + v4l_dbg(1, debug, client, "detect:FDC from device is 0x%x", pid); + i2c_smbus_write_byte_data(client, 0xc0, 0xff); /*set FST to 1000us*/ + pid = i2c_smbus_read_byte_data(client, 0xc0); + v4l_dbg(1, debug, client, "FDC from device is 0x%x", pid); + + v4l_dbg(1, debug, client, + "successfully load camera flash device driver"); + return 0; +} + +static int flash_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + + v4l2_device_unregister_subdev(sd); + kfree(sd); + + return 0; +} + +static const struct i2c_device_id flash_id[] = { + {"mrst_camera_flash", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, flash_id); + +static struct i2c_driver flash_i2c_driver = { + .driver = { + .name = "mrst_camera_flash", + }, + .probe = flash_probe, + .remove = flash_remove, + .id_table = flash_id, +}; + +static int __init flash_drv_init(void) +{ + return i2c_add_driver(&flash_i2c_driver); +} + +static void __exit flash_drv_cleanup(void) +{ + i2c_del_driver(&flash_i2c_driver); +} + +module_init(flash_drv_init); +module_exit(flash_drv_cleanup);