Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp545784lqp; Tue, 11 Jun 2024 11:49:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIlZS+e1QLi43wJ1LQF7nAzXsu0gV1zyBBR7gc9vmgOeYjJEeASeMRU1nonBgUB4j6pL1qNC/urqxprhDWvYrgdor+M0+usFJqo6f1hw== X-Google-Smtp-Source: AGHT+IEHFbwQ6YRxQS1GLI1SHJdmF9lv1Mg/7laqTukzEd835WmgGJ5ZKXeQgq1RFomSjmP+cm3x X-Received: by 2002:a17:902:d4d2:b0:1f3:dd7:ad42 with SMTP id d9443c01a7336-1f6d021d1famr153039575ad.0.1718131746187; Tue, 11 Jun 2024 11:49:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718131746; cv=pass; d=google.com; s=arc-20160816; b=Tj2O64QAe4hDy0eNCLV0IbzAqcPc9RLmnQXKnobpYzC2zHoHyED03CcOe81tsfuznq gDfzGA1RHY5eha1EQ9YiFFpVV5Doz7XmnaQLVUmxsMMDkrXC6r7qfcMnfwAeXTGvq5T1 mqH1qhxusP22HZAWjV8GagobxBet8YU0nsVUichyCKeEDARmJq8HsoqZ8vdSLATRMBRV mJgD3W4z8IfGmbiKqq3wOtCH+H4Icy12MGKoe/GAqNJaj2BoO6P5AYgAyl3o/0NZEgQU t7hsYpvkoxYXMARmy+0pP5sClav/iqDjan+rR9amUO/OtvrNAMht4WL3Q2Frbl4FsOkW v4aw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=sDXIAi2hNDOjYRm7+B25GTwEHeQQES9Jm3k/yIIxD4A=; fh=jjDYHXx1Ig9VE4KEWNexAEz0I/NilWfZBgFte5qEWKA=; b=v9G4YiSO2mOsq/JTzqYsolxkm5PFrlf9ar7ia19O+JIWPfFixA4Np5DWgt93Z9ChFZ kHLE35/xMwW6y6K5DhTcMx0F5fy8fm9el9Rkl7aeceBja/2H6ln5iZ5B+iX6lLESNq1h L9e+kDHDbGJbOZ1WPnYY9W381RwRwKG7ajdEGPww927dh0kVmm3kXSy+1+lNXeVQMAth rEILy3fn9nZJMYmwbK6ntZoCeaoZwFRlJRIKko3cAnFAOGLtZL0KJlEhAx8c11ubndU6 7Fvv13MLSuIiF46X7hedw5PQJIgfGcwdguqt+FlCFB6fZRSx/OfOmN732HOG9PknpXbm wjwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Oa55rfjK; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-210443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210443-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd7e4c3asi100066605ad.395.2024.06.11.11.49.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 11:49:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Oa55rfjK; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-210443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210443-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 03EB4B22FA5 for ; Tue, 11 Jun 2024 18:33:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 043E014AD3F; Tue, 11 Jun 2024 18:30:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="Oa55rfjK" Received: from smtp.smtpout.orange.fr (smtp-28.smtpout.orange.fr [80.12.242.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B90F778C8E; Tue, 11 Jun 2024 18:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.28 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718130631; cv=none; b=Ff+AWN9ppIIP/9HT2mMxjocdTHrc3s9+i6kGWNCmY8vKO3ld3AK6szn9h4DlS+PDrXP0eRMHlvd/nEWpdB+wTDvfIrjfneOmRCnuGQ0KPuazJZKp2YeBkHPMuDXfB7WPYBBDarONFVvRTxQM96IF1X8upBXtB5hoDHOJh/bdP/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718130631; c=relaxed/simple; bh=Fl1Bcjival52kq6amEO6cSuii7o+jtaAL8znvOQExXQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=BX5CQm0i7FBpVi9MJQNDaj5fUoQYUwYf1YrB2dXR+cW9BgrCTGMYAfLqHo9UM42iQn7ATyLDHOqQGZka+okJWQah0XFxiOm9DSlRTjzjjJOtTKPZLQEQZDuPd7pRsY9V+D9U283UdYzlFZHUFZpsHj+aUCn5/nKzB16Dtsoqnk4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=Oa55rfjK; arc=none smtp.client-ip=80.12.242.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Received: from [192.168.1.37] ([86.243.222.230]) by smtp.orange.fr with ESMTPA id H5j3s2zS3qyvbH5j3s7g8y; Tue, 11 Jun 2024 19:56:09 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1718128569; bh=sDXIAi2hNDOjYRm7+B25GTwEHeQQES9Jm3k/yIIxD4A=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=Oa55rfjKoOk2jGUDVGAj5k36U9b7ZTh+42+oRIKJ/OVI2zf3WKcNTuNITbMX8Je3b WNgoWgLt/cLU/AIMmpIt667NNkS+h5NJn3MMRFjnliyMEVrOHo0lLp5fzfV76muosn 4fqIkmfTv8GYicR6tK8JYfU7QrA+n6pdX08VYsKLB2U2TmMWCoH7tJ33AiPzYWKNcB 5EA3wrgZtW5oE3lQ6yAHtmVZggHv+9D913iG9iBGMCxFnVj2q6uyZPoDGPY0APgSrv Jq7lrNzkwrFjJV5slDP6UM+FKgIi7SkAjNQOr1Vt6PbiiG/t92VI9QUh71yY74wQzV 4NymB7lVfIobA== X-ME-Helo: [192.168.1.37] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 11 Jun 2024 19:56:09 +0200 X-ME-IP: 86.243.222.230 Message-ID: <71609986-9b97-44ee-86a1-b8a8b9d2829b@wanadoo.fr> Date: Tue, 11 Jun 2024 19:56:03 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/7] i2c: muxes: add support for mule i2c multiplexer To: Farouk Bouabid , Wolfram Sang , Peter Rosin , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Quentin Schulz , Heiko Stuebner Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org References: <20240611-dev-mule-i2c-mux-v3-0-08d26a28e001@cherry.de> <20240611-dev-mule-i2c-mux-v3-3-08d26a28e001@cherry.de> Content-Language: en-MW From: Christophe JAILLET In-Reply-To: <20240611-dev-mule-i2c-mux-v3-3-08d26a28e001@cherry.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 11/06/2024 à 13:43, Farouk Bouabid a écrit : > Mule is an MCU that emulates a set of I2C devices which are reachable > through an I2C-mux. > > The emulated devices share a single I2C address with the mux itself > where the requested register is what determines which logic is executed > (mux logic or device logic): > > 1- The devices on the mux can be selected (mux function) by writing the > appropriate device number to an I2C config register (0xff) that is not > used by any device logic. > > 2- Any access to a register other than the config register will be > handled by the previously selected device. > > Signed-off-by: Farouk Bouabid > --- Hi, ... > +static int mule_i2c_mux_probe(struct i2c_client *client) > +{ > + struct i2c_adapter *adap = client->adapter; > + struct mule_i2c_reg_mux *priv; > + struct i2c_mux_core *muxc; > + struct device_node *dev; > + unsigned int readback; > + int ndev, ret; > + bool old_fw; > + > + /* Count devices on the mux */ > + ndev = of_get_child_count(client->dev.of_node); > + dev_dbg(&client->dev, "%u devices on the mux\n", ndev); Should this be %d? > + > + muxc = i2c_mux_alloc(adap, &client->dev, > + ndev, sizeof(*priv), > + I2C_MUX_LOCKED, > + mux_select, mux_deselect); Nitpick: this could be written with less lines. > + if (!muxc) > + return -ENOMEM; > + > + muxc->share_addr_with_children = 1; > + priv = i2c_mux_priv(muxc); > + > + priv->regmap = devm_regmap_init_i2c(client, &mule_regmap_config); > + if (IS_ERR(priv->regmap)) > + return dev_err_probe(&client->dev, PTR_ERR(priv->regmap), > + "Failed to allocate i2c register map\n"); > + > + i2c_set_clientdata(client, muxc); > + > + /* > + * Mux 0 is guaranteed to exist on all old and new mule fw. > + * mule fw without mux support will accept write ops to the > + * config register, but readback returns 0xff (register not updated). > + */ > + ret = mux_select(muxc, 0); Should this 0 be MUX_DEFAULT_DEV (for consistency)? > + if (ret) > + return ret; > + > + ret = regmap_read(priv->regmap, MUX_CONFIG_REG, &readback); > + if (ret) > + return ret; > + > + old_fw = (readback != 0); > + > + ret = devm_add_action_or_reset(&client->dev, mux_remove, muxc); > + if (ret) > + return ret; > + > + /* Create device adapters */ > + for_each_child_of_node(client->dev.of_node, dev) { > + u32 reg; > + > + ret = of_property_read_u32(dev, "reg", ®); > + if (ret) { > + dev_err(&client->dev, "No reg property found for %s: %d\n", > + of_node_full_name(dev), ret); return dev_err_probe() as above? > + return ret; > + } > + > + if (old_fw && reg != 0) { > + dev_warn(&client->dev, > + "Mux %d not supported, please update Mule FW\n", reg); > + continue; > + } > + > + ret = mux_select(muxc, reg); > + if (ret) { > + dev_warn(&client->dev, > + "Mux %d not supported, please update Mule FW\n", reg); > + continue; > + } > + > + ret = i2c_mux_add_adapter(muxc, 0, reg, 0); > + if (ret) { > + dev_err(&client->dev, "Failed to add i2c mux adapter %d: %d\n", reg, ret); return dev_err_probe() as above? > + return ret; > + } > + } > + > + mux_deselect(muxc, MUX_DEFAULT_DEV); > + > + return 0; > +} ...