From patchwork Sun Nov 17 18:56:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 291874 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 D2C502C00A4 for ; Mon, 18 Nov 2013 05:56:28 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752161Ab3KQS41 (ORCPT ); Sun, 17 Nov 2013 13:56:27 -0500 Received: from mail-pb0-f50.google.com ([209.85.160.50]:56542 "EHLO mail-pb0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751236Ab3KQS41 (ORCPT ); Sun, 17 Nov 2013 13:56:27 -0500 Received: by mail-pb0-f50.google.com with SMTP id xb12so5731823pbc.37 for ; Sun, 17 Nov 2013 10:56:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=BDbgt34jspAUTnLHOzm6oSrgbhy9FhS/1K5FKkC1Jsk=; b=EN8Hl9qU9PcrRmNSQYZKolPYJmKHJ/C7VX2QWwGfbaxaPqr1WdxL8ftKpHs1zSioLZ h4GgVYPzXA0R2pzJnxsuBDixKjP585VYQQvEYJeZMOzJomnU0e5PyiwNPMpQnDCBK2Ez db8iSOpYclbtArxi61zzZ3RO39ZGj7+ciJK01O3YVxYa/wddBfGsOLsw7hvDrT6QbztW zbqJqpVYqkXR5TBusaAPGVYQaxaOefVtoxWpkXKxLBd+5BTOuyuCxp5RNgwjM9NDNKhC 0TwdBhl+rCyaJ2V8Aenawmen49zsk3Nh4nlujqJGUWq7ixy0XT3fKtjHcJl4pw0ffY6w JUug== X-Received: by 10.66.159.234 with SMTP id xf10mr18309pab.139.1384714586719; Sun, 17 Nov 2013 10:56:26 -0800 (PST) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by mx.google.com with ESMTPSA id g6sm12531385pat.2.2013.11.17.10.56.25 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 17 Nov 2013 10:56:26 -0800 (PST) Date: Sun, 17 Nov 2013 10:56:24 -0800 From: Guenter Roeck To: Jean Delvare Cc: linux-i2c@vger.kernel.org Subject: Re: Problem with multiple i2c multiplexers on one bus, and mux bus naming Message-ID: <20131117185624.GA23639@roeck-us.net> References: <5287B9E4.1020107@roeck-us.net> <20131116214116.3d035b76@endymion.delvare> <20131116214318.1d101d35@endymion.delvare> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20131116214318.1d101d35@endymion.delvare> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On Sat, Nov 16, 2013 at 09:43:18PM +0100, Jean Delvare wrote: > Oh, I forgot to mention... > > > On Sat, 16 Nov 2013 10:31:00 -0800, Guenter Roeck wrote: > > > I understand this may require an API change, as the mux chip is not necessarily an i2c > > > and the i2c-mux core code doesn't really care what the mux chip is. > > Such an API change would be perfectly acceptable. Mux drivers are few > and i2c-mux is still relatively new. Unique i2c adapter name is > something important, definitely worth changing the API if needed. > I managed to do it without changing the API; see patch below. This results in i2c-0/name:MPC adapter at 0xfff703000 i2c-1/name:MPC adapter at 0xfff703100 i2c-10/name:i2c-2-mux-75 (chan_id 7) i2c-11/name:i2c-2-mux-76 (chan_id 0) i2c-12/name:i2c-2-mux-76 (chan_id 1) i2c-13/name:i2c-2-mux-76 (chan_id 2) i2c-14/name:i2c-2-mux-76 (chan_id 3) i2c-15/name:i2c-2-mux-76 (chan_id 4) i2c-16/name:i2c-2-mux-76 (chan_id 5) i2c-17/name:i2c-2-mux-76 (chan_id 6) i2c-18/name:i2c-2-mux-76 (chan_id 7) i2c-19/name:i2c-0-mux (chan_id 1) i2c-2/name:i2c-0-mux (chan_id 0) i2c-20/name:i2c-0-mux (chan_id 2) i2c-21/name:i2c-0-mux (chan_id 3) i2c-22/name:i2c-0-mux (chan_id 4) i2c-23/name:i2c-0-mux (chan_id 5) i2c-24/name:i2c-0-mux (chan_id 6) i2c-25/name:i2c-0-mux (chan_id 7) i2c-3/name:i2c-2-mux-75 (chan_id 0) i2c-4/name:i2c-2-mux-75 (chan_id 1) i2c-5/name:i2c-2-mux-75 (chan_id 2) i2c-6/name:i2c-2-mux-75 (chan_id 3) i2c-7/name:i2c-2-mux-75 (chan_id 4) i2c-8/name:i2c-2-mux-75 (chan_id 5) i2c-9/name:i2c-2-mux-75 (chan_id 6) This retains the old mux name if the mux is not an i2c device, and adds the i2c device address if it is. This solves the problem for me. Comments ? Thanks, Guenter --- From 592db23cd3a769a5369e15260ffa6924acf91ddb Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 17 Nov 2013 09:25:21 -0800 Subject: [PATCH] i2c: mux: Create unique i2c mux name if the parent is an i2c device If an i2c mux parent is an i2c device, there can be more than one such device on a single i2c bus. The current mux naming scheme does not take this into account and creates multiple i2c adapters with the same name. Expand the mux adapter name to include the i2c client's I2C address to solve the problem. Signed-off-by: Guenter Roeck --- drivers/i2c/i2c-mux.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index 797e311..9a49fe9 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -109,7 +109,9 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, int (*deselect) (struct i2c_adapter *, void *, u32)) { + struct i2c_client *client = i2c_verify_client(mux_dev); struct i2c_mux_priv *priv; + char client_addr[8]; int ret; priv = kzalloc(sizeof(struct i2c_mux_priv), GFP_KERNEL); @@ -133,8 +135,15 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, priv->algo.functionality = i2c_mux_functionality; /* Now fill out new adapter structure */ + if (client) + scnprintf(client_addr, sizeof(client_addr), "-%02x", + client->addr); + else + client_addr[0] = '\0'; + snprintf(priv->adap.name, sizeof(priv->adap.name), - "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id); + "i2c-%d-mux%s (chan_id %d)", i2c_adapter_id(parent), + client_addr, chan_id); priv->adap.owner = THIS_MODULE; priv->adap.algo = &priv->algo; priv->adap.algo_data = priv;