From patchwork Tue Apr 22 06:24:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lan Tianyu X-Patchwork-Id: 341188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id CDA0C14003E for ; Tue, 22 Apr 2014 16:34:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753667AbaDVGeV (ORCPT ); Tue, 22 Apr 2014 02:34:21 -0400 Received: from mga01.intel.com ([192.55.52.88]:4260 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753291AbaDVGcp (ORCPT ); Tue, 22 Apr 2014 02:32:45 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 21 Apr 2014 23:32:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,901,1389772800"; d="scan'208";a="517067448" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.37.18]) by fmsmga001.fm.intel.com with ESMTP; 21 Apr 2014 23:32:33 -0700 From: Lan Tianyu To: wsa@the-dreams.de, rjw@rjwysocki.net, mika.westerberg@linux.intel.com, awilliam@redhat.com, lenb@kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, tianyu.lan@intel.com Subject: [Resend Patch 6/9] I2C: Add smbus word/block process call helper function Date: Tue, 22 Apr 2014 14:24:12 +0800 Message-Id: <1398147855-9868-7-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1398147855-9868-1-git-send-email-tianyu.lan@intel.com> References: <1397654682-7094-1-git-send-email-tianyu.lan@intel.com> <1398147855-9868-1-git-send-email-tianyu.lan@intel.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add i2c_smbus_word/block_proc_call() helper function. These will be used in the implementation of i2c ACPI address space handler. Signed-off-by: Lan Tianyu Reviewed-by: Mika Westerberg --- drivers/i2c/i2c-core.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 4 ++++ 2 files changed, 60 insertions(+) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 3bf0048..638befd 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -2306,6 +2306,30 @@ s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command, EXPORT_SYMBOL(i2c_smbus_write_word_data); /** + * i2c_smbus_word_proc_call - SMBus "word proc call" protocol + * @client: Handle to slave device + * @command: Byte interpreted by slave + * @value: 16-bit "word" being written + * + * This executes the SMBus "word proc all" protocol, returning negative errno + * else a 16-bit unsigned "word" received from the device. + */ +s32 i2c_smbus_word_proc_call(const struct i2c_client *client, u8 command, + u16 value) +{ + union i2c_smbus_data data; + int status; + + data.word = value; + status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, + I2C_SMBUS_READ, command, + I2C_SMBUS_PROC_CALL, &data); + + return (status < 0) ? status : data.word; +} +EXPORT_SYMBOL(i2c_smbus_word_proc_call); + +/** * i2c_smbus_read_block_data - SMBus "block read" protocol * @client: Handle to slave device * @command: Byte interpreted by slave @@ -2362,6 +2386,38 @@ s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command, } EXPORT_SYMBOL(i2c_smbus_write_block_data); +/** + * i2c_smbus_block_proc_call - SMBus "block write" protocol + * @client: Handle to slave device + * @command: Byte interpreted by slave + * @length: Size of data block; SMBus allows at most 32 bytes + * @values: Byte array which will be written. + * + * This executes the SMBus "block proc call" protocol, returning negative errno + * else the number of read bytes. + */ +s32 i2c_smbus_block_proc_call(const struct i2c_client *client, u8 command, + u8 length, u8 *values) +{ + union i2c_smbus_data data; + int status; + + if (length > I2C_SMBUS_BLOCK_MAX) + length = I2C_SMBUS_BLOCK_MAX; + data.block[0] = length; + memcpy(&data.block[1], values, length); + status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, + I2C_SMBUS_READ, command, + I2C_SMBUS_BLOCK_PROC_CALL, &data); + + if (status < 0) + return status; + + memcpy(values, &data.block[1], data.block[0]); + return data.block[0]; +} +EXPORT_SYMBOL(i2c_smbus_block_proc_call); + /* Returns the number of read bytes */ s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command, u8 length, u8 *values) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 3e6ea90..724440a 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -94,6 +94,10 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command); extern s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command, u16 value); +extern s32 i2c_smbus_word_proc_call(const struct i2c_client *client, + u8 command, u16 value); +extern s32 i2c_smbus_block_proc_call(const struct i2c_client *client, + u8 command, u8 length, u8 *values); static inline s32 i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)