Received: by 10.213.65.68 with SMTP id h4csp809210imn; Tue, 20 Mar 2018 16:19:01 -0700 (PDT) X-Google-Smtp-Source: AG47ELs59fJ40pP4RMI32WSyd3KSSZL0epcq2T4OQEm0H0sZvLS8t7qUwdchyU+fZlSEN1R+wNQY X-Received: by 2002:a17:902:8214:: with SMTP id x20-v6mr18604716pln.182.1521587941742; Tue, 20 Mar 2018 16:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521587941; cv=none; d=google.com; s=arc-20160816; b=znKZ0mIEw1/cUGheO/qoTMbU78NgF914F9o3tAdGt1p1HDakrd0sSHlUJqBqzFb8nd JzC5Vwgf8ZiutlLwKZBS7PQX5C2790oWUp87KwaPZSRKW4rOP8OTBKHbAq/iGNlekiad 56OfUsD3TwURCbDDWIWvxSFtZUED4nBAcFIPez2gLvKItgBTSbec6Kh3QOVvlPUNdZEI RyekjWY6lsN1dz6RTEDNgPAB/++AogUZ9YHPNLH15lwpCMAEh6vfYRrRR/+uDclVuZPy nzxjtCMUVITutEsrD/RPpGvo8mHrcYF+F1XswTVxkN7M8kJgNz2Te6PUdRQW931doyyr oEpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=aGDBma54Pl2XEQLeUI4FO0Jzlac0uWztOnpLkCy/rPA=; b=KKHuCS1CNlXYrmVDYLRGKl4VVQ/69MUXWu1ME77uzsVdhjjpwMWv/bu6iDri9B2t3k 6pO1i5iunU97Nh1aGIQxZzq7XsVIhTe436KJztE/E2ofQV3pp3MONH0ftF+/ztgM9/oN +Dst5z2OQfbEgMAiejIVu7I4lp7yM1HoHoFj7groOAgm1DKiJ1oNzm/IDoCdoIHmKXNe QOmFCtBUOrc8X000hm4CSEqvpRaii80kiL+FhMRp8b2svyamuSt4f6926LdAUjqhaM6m sBED0p2DdzMrAFHjvyF0dIooGialIgrL5Wau1sLwtVJhWTCDcLp6Xpz781r/OBOMEcLU NwNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si1828378pgc.571.2018.03.20.16.18.47; Tue, 20 Mar 2018 16:19:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751539AbeCTXRn (ORCPT + 99 others); Tue, 20 Mar 2018 19:17:43 -0400 Received: from mleia.com ([178.79.152.223]:59218 "EHLO mail.mleia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751448AbeCTXRm (ORCPT ); Tue, 20 Mar 2018 19:17:42 -0400 Received: from mail.mleia.com (localhost [127.0.0.1]) by mail.mleia.com (Postfix) with ESMTP id 0B13E3FA091; Tue, 20 Mar 2018 23:17:41 +0000 (GMT) Subject: Re: [PATCH 3/3] i2c: mux: pca9541: prepare for PCA9641 support To: Peter Rosin , linux-kernel@vger.kernel.org, Ken Chen Cc: Guenter Roeck , Wolfram Sang , joel@jms.id.au, linux-i2c@vger.kernel.org References: <20180320061909.5775-1-chen.kenyy@inventec.com> <20180320093200.19179-1-peda@axentia.se> <20180320093200.19179-4-peda@axentia.se> From: Vladimir Zapolskiy Message-ID: Date: Wed, 21 Mar 2018 01:17:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180320093200.19179-4-peda@axentia.se> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-49551924 X-CRM114-CacheID: sfid-20180320_231741_066847_5957B7AF X-CRM114-Status: GOOD ( 27.72 ) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, Ken, On 03/20/2018 11:32 AM, Peter Rosin wrote: > Make the arbitrate and release_bus implementation chip specific. > by chance I took a look at the original implementation done by Ken, and I would say that this 3/3 change is an overkill as a too generic one. Is there any next observable extension? And do two abstracted (*arbitrate) and (*release_bus) cover it well? Probably no. At first it would be simpler to add a new chip id field into struct pca9541 (struct rename would be needed of course), and do a selection of specific pca9x41_arbitrate() and pca9x41_release_bus() depending on it: ----8<---- diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c index 47685eb..a40e6d8 100644 --- a/drivers/i2c/muxes/i2c-mux-pca9541.c +++ b/drivers/i2c/muxes/i2c-mux-pca9541.c @@ -70,8 +70,13 @@ #define SELECT_DELAY_SHORT 50 #define SELECT_DELAY_LONG 1000 +enum chip_id { + pca9541, +}; + struct pca9541 { struct i2c_client *client; + enum chip_id id; unsigned long select_timeout; unsigned long arb_timeout; }; @@ -188,10 +193,13 @@ static int pca9541_reg_read(struct i2c_client *client, u8 command) */ /* Release bus. Also reset NTESTON and BUSINIT if it was set. */ -static void pca9541_release_bus(struct i2c_client *client) +static void pca9541_release_bus(struct i2c_client *client, enum chip_id id) { int reg; + if (id != pca9541) + return; + reg = pca9541_reg_read(client, PCA9541_CONTROL); if (reg >= 0 && !pca9541_busoff(reg) && pca9541_mybus(reg)) pca9541_reg_write(client, PCA9541_CONTROL, @@ -235,12 +243,15 @@ static const u8 pca9541_control[16] = { * 0 : bus not acquired * 1 : bus acquired */ -static int pca9541_arbitrate(struct i2c_client *client) +static int pca9541_arbitrate(struct i2c_client *client, enum chip_id id) { struct i2c_mux_core *muxc = i2c_get_clientdata(client); struct pca9541 *data = i2c_mux_priv(muxc); int reg; + if (id != pca9541) + return -EOPNOTSUPP; + reg = pca9541_reg_read(client, PCA9541_CONTROL); if (reg < 0) return reg; @@ -318,7 +329,7 @@ static int pca9541_select_chan(struct i2c_mux_core *muxc, u32 chan) /* force bus ownership after this time */ do { - ret = pca9541_arbitrate(client); + ret = pca9541_arbitrate(client, data->id); if (ret) return ret < 0 ? ret : 0; @@ -336,7 +347,7 @@ static int pca9541_release_chan(struct i2c_mux_core *muxc, u32 chan) struct pca9541 *data = i2c_mux_priv(muxc); struct i2c_client *client = data->client; - pca9541_release_bus(client); + pca9541_release_bus(client, data->id); return 0; } @@ -361,7 +372,7 @@ static int pca9541_probe(struct i2c_client *client, * We have to lock the adapter before releasing the bus. */ i2c_lock_adapter(adap); - pca9541_release_bus(client); + pca9541_release_bus(client, pca9541); i2c_unlock_adapter(adap); /* Create mux adapter */ @@ -377,6 +388,7 @@ static int pca9541_probe(struct i2c_client *client, data = i2c_mux_priv(muxc); data->client = client; + data->id = pca9541; i2c_set_clientdata(client, muxc); ----8<---- > Signed-off-by: Peter Rosin > --- > drivers/i2c/muxes/i2c-mux-pca9541.c | 62 +++++++++++++++++++++++++++---------- > 1 file changed, 45 insertions(+), 17 deletions(-) > The change above is trivial and it does not cancel any further extensions similar to your idea, the open question is if there is a demand right at the moment. > diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c > index 47685eb4e0e9..cac629e36bf8 100644 > --- a/drivers/i2c/muxes/i2c-mux-pca9541.c > +++ b/drivers/i2c/muxes/i2c-mux-pca9541.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -70,26 +71,22 @@ > #define SELECT_DELAY_SHORT 50 > #define SELECT_DELAY_LONG 1000 > > -struct pca9541 { > - struct i2c_client *client; > - unsigned long select_timeout; > - unsigned long arb_timeout; > +enum chip_name { chip_name sound like a string storage, chip_id might be better here. > + pca9541, > }; > -- With best wishes, Vladimir