From patchwork Tue Jul 17 15:02:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Delvare X-Patchwork-Id: 1205551 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7F06E3FC8E for ; Tue, 17 Jul 2012 15:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755386Ab2GQPC4 (ORCPT ); Tue, 17 Jul 2012 11:02:56 -0400 Received: from zoneX.GCU-Squad.org ([194.213.125.0]:14619 "EHLO services.gcu-squad.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753811Ab2GQPC4 (ORCPT ); Tue, 17 Jul 2012 11:02:56 -0400 Received: from jdelvare.pck.nerim.net ([62.212.121.182] helo=endymion.delvare) by services.gcu-squad.org (GCU Mailer Daemon) with esmtpsa id 1Sr9IX-00068j-Bd (TLSv1:AES128-SHA:128) (envelope-from ) ; Tue, 17 Jul 2012 17:02:49 +0200 Date: Tue, 17 Jul 2012 17:02:43 +0200 From: Jean Delvare To: Laurent Pinchart Cc: linux-i2c@vger.kernel.org, linux-omap@vger.kernel.org Subject: Re: [RFC/PATCH 2/3] i2c: Fall back to emulated SMBus if the operation isn't supported natively Message-ID: <20120717170243.5def41a3@endymion.delvare> In-Reply-To: <1340720229-30356-3-git-send-email-laurent.pinchart@ideasonboard.com> References: <1340720229-30356-1-git-send-email-laurent.pinchart@ideasonboard.com> <1340720229-30356-3-git-send-email-laurent.pinchart@ideasonboard.com> X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.7; x86_64-suse-linux-gnu) Mime-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Hi Laurent, On Tue, 26 Jun 2012 16:17:08 +0200, Laurent Pinchart wrote: > Adapter drivers might support only a subset of the SMBus operations > natively. Those drivers currently have to manually emulate unsupported > operations using I2C. > > Make the i2c_smbus_xfer() function fall back to > i2c_smbus_xfer_emulated() when the adapter's .smbus_xfer() operation > returns -EOPNOTSUPP, like it already does when the .smbus_xfer() > operation isn't available at all. > > Signed-off-by: Laurent Pinchart > --- > drivers/i2c/i2c-core.c | 9 +++++++-- > 1 files changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c > index 8cfa660..16e750e 100644 > --- a/drivers/i2c/i2c-core.c > +++ b/drivers/i2c/i2c-core.c > @@ -2113,8 +2113,8 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, > union i2c_smbus_data *data) > { > unsigned long orig_jiffies; > + s32 res = -EOPNOTSUPP; > int try; > - s32 res; > > flags &= I2C_M_TEN | I2C_CLIENT_PEC | I2C_CLIENT_SCCB; > > @@ -2134,7 +2134,12 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, > break; > } > i2c_unlock_adapter(adapter); > - } else > + } > + > + /* Fall back to i2c_smbus_xfer_emulated of the adapter doesn't implement > + * native support for the SMBus operation. > + */ > + if (res == -EOPNOTSUPP && adapter->algo->master_xfer) > res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, > command, protocol, data); > Looks good overall, but maybe the following variant would be preferable from a performance perspective: What do you think? The advantage is that we can skip the tests for adapters which only implement adapter->algo->master_xfer(). --- linux-3.5-rc7.orig/drivers/i2c/i2c-core.c 2012-07-17 16:35:42.566799611 +0200 +++ linux-3.5-rc7/drivers/i2c/i2c-core.c 2012-07-17 16:59:55.334530352 +0200 @@ -2140,11 +2140,17 @@ s32 i2c_smbus_xfer(struct i2c_adapter *a break; } i2c_unlock_adapter(adapter); - } else - res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, - command, protocol, data); - return res; + if (res != -EOPNOTSUPP || !adapter->algo->master_xfer) + return res; + /* + * Fall back to i2c_smbus_xfer_emulated if the adapter doesn't implement + * native support for the SMBus operation. + */ + } + + return i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, + command, protocol, data); } EXPORT_SYMBOL(i2c_smbus_xfer);