From patchwork Tue Jun 11 11:43:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Farouk Bouabid X-Patchwork-Id: 803987 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2109.outbound.protection.outlook.com [40.107.22.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A37F17BB2A; Tue, 11 Jun 2024 11:44:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.109 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718106281; cv=fail; b=QTdlk30JABWkBQyZ789ATfORpBHheNYtjnRMnbDbPLzG7pd2/Ed6yOEBsNlYFQDgdTROtLN6I/ZRcay3ZWWtGKKf7Wr/gRyYSXAvKLehUlHwy87QpSnaNksCB55YBLTcc2d7xDPIi36ydj32SeHIK6mWKQDKxp1SEnUy6lBq1iI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718106281; c=relaxed/simple; bh=YJnDzYkWp6xamdl6WBWo3TjkQ/xXtTuf8Ga+2yf/MyE=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=ugGt7htlY1plcoldEkHvzyoCR3SSliDYinKCaJcRJCf4z1IwyfRWJVi3RQwXF2hUMq1uWcvsY+uGSX9zdxLx1rR1NivTfKHIKTvmQhxBMISu+dUiQn7HSbqgQQKsQqhQBTR5yiTTQ0naj1LKu4j7v7UKxbvCvCj/StqRukvtsRc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cherry.de; spf=pass smtp.mailfrom=cherry.de; dkim=pass (1024-bit key) header.d=cherry.de header.i=@cherry.de header.b=i9Iym5c3; arc=fail smtp.client-ip=40.107.22.109 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=cherry.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cherry.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cherry.de header.i=@cherry.de header.b="i9Iym5c3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f3X8r3FK/dRm+YsHJg+xS/RDFGH1BXjDDB2M1AByUXNZVXYKllKuTshZ1iQ+wgN3BTCWkBPdiK6ujjb2Te7sWDha6l/1TtuKuKqeyq9U6/YjcH0HJzUqUlUVZwb7gSE3lSjoDgZ5HdhWGGEAP9rwJ3JNbeHH0mUOTWSidmt9wgFZ9+vvddPA+1c77hLPS0hVPWKytudWyfRhDDkEDukyVkEreLDIobWSMDK/Ywpep1JhvdMnfZwI09tNAFFMBRiJ0SYtoZkNAPfUjaF3PQlfbdWk4WUN2ZciJzAJZ3INDDSbE16pbkZMFGjaIc6UdX+s1/r/bhRMmvfnuPxHxEm3eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NoJOV7uyxx3z8OrFykyBkgyA9vpenxJYExyJWNS5Da8=; b=nXYvmhEhgdbOM5ViOP1ol/TMYDqLIWqB79ly1jscKL1xbw1liMzBnbDeavX8ZcZVBK/vm8vZuMTJR6LLocKiX6RAhZm0q+tb1P8c47nUc0bIKR8xBB9YPRjDGK56dxycaJ2OpsXS09uUKbNaGz1WyyUg0Ep9BY6W1GA9MID71NF+nhCdFRlKdCylPrgqVjowMC2yCnwYjVlL4Mm9zcvagYpec4HPpMERldNxrj8YB54ssY3BJlkR7r4Ka+R6ep0YY4dd4a7OpETUDOrNFL5VFJx6eHw5Gei4nNHZmw7aCvbNP5Agxr+wPBi7ucv97JJ+ozTnjzprTqlEBQYiSD3u4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cherry.de; dmarc=pass action=none header.from=cherry.de; dkim=pass header.d=cherry.de; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cherry.de; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NoJOV7uyxx3z8OrFykyBkgyA9vpenxJYExyJWNS5Da8=; b=i9Iym5c3cSQFoVRm4Uf5L2HzNkQ9EXR4WVdanYXz4CV+jAt79s/bwzzUsctOcpSQAXDH/BFGpft/+XAbRYRttyhqXwCbh3FuVk9TOM+iBCmmwUEBGpOgMZg2olynpeG0+efIzIqPseEyG5FIr/m2yutgWebC+dBzZgyM1dUtVL4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cherry.de; Received: from VE1PR04MB6382.eurprd04.prod.outlook.com (2603:10a6:803:122::31) by GVXPR04MB10301.eurprd04.prod.outlook.com (2603:10a6:150:1dd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Tue, 11 Jun 2024 11:44:30 +0000 Received: from VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::2a24:328:711:5cd6]) by VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::2a24:328:711:5cd6%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 11:44:30 +0000 From: Farouk Bouabid Date: Tue, 11 Jun 2024 13:43:54 +0200 Subject: [PATCH v3 3/7] i2c: muxes: add support for mule i2c multiplexer Message-Id: <20240611-dev-mule-i2c-mux-v3-3-08d26a28e001@cherry.de> References: <20240611-dev-mule-i2c-mux-v3-0-08d26a28e001@cherry.de> In-Reply-To: <20240611-dev-mule-i2c-mux-v3-0-08d26a28e001@cherry.de> To: Wolfram Sang , Peter Rosin , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Farouk Bouabid , 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 X-Mailer: b4 0.13.0 X-ClientProxiedBy: VI1PR0902CA0050.eurprd09.prod.outlook.com (2603:10a6:802:1::39) To VE1PR04MB6382.eurprd04.prod.outlook.com (2603:10a6:803:122::31) Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6382:EE_|GVXPR04MB10301:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ae0d7fc-eb38-4066-dd6f-08dc8a0bda65 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|52116005|1800799015|376005|7416005|366007|38350700005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?q/TYx5h13goty0pZUZmJYhrGEpAcTyQ?= =?utf-8?q?3HIgpeScYlb04nFnxsA/VPhfoNqBOnujUQo+0yZBjjvpGpP1aP4UHfQgu78OdDMzV?= =?utf-8?q?44aN43Li7Cg+mDtG1mHTZUN2jNUQjpeZ8UxHJNToaUAOQdqCvsOBr31x7GY7dizlp?= =?utf-8?q?4XklaC3FGpZ0ouNWh0PXXcL8ODkuW+Aell6lXvaTsAhJJw1QZkjNpFuBJWVdWJqjh?= =?utf-8?q?jb6ocNfCosfw3DFY5ReHyLxt1d4tHBfWYWpg4VE1vkqdPOctdUidjn3BwOU6FFKmD?= =?utf-8?q?oHzVjVLlE/27S12XtVsY6gdd+VZetr4QpoysfIis89czx5W+vUwa0gqiUU7OqKc8M?= =?utf-8?q?hbAxHtwdvAMAQx3CJ1WEJzB1X7F0SNdjtpZ1du3wN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6Ch3OVhy2E7/4DFW93zUh1Lv?= =?utf-8?q?ZjC3eAwyirpNOdMDX5BTxT+7XTtmyQ5ftg1+2+yogfdcpvawFzyToJhY=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6382.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(52116005)(1800799015)(376005)(7416005)(366007)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HEAJ7k9pOv/1nd6bnibQ9mlTiLCq?= =?utf-8?q?ub0Ya7XFIz2quPRfd+FdluelLngxlgew1jlv712Eg7nT0eaALbNg2jZvFpmm4ML5o?= =?utf-8?q?ZrmLiyBFo/idjqnuIVp8qOAs6Apyye/tEeo6Ax6qVlijZrfVEsGLfKVyiCBseqcmC?= =?utf-8?q?IXClTBsamFIgV6+AIBsV6sJta5W47/B2cHfCg740kCAYl1UPrOaW2Izb2bgjWE/YJ?= =?utf-8?q?c9yFUDS3487mtK45RslaQfVyzYlWDsWb/5UaULaC1kZGG56sAeOZhcfmFisdhwD0C?= =?utf-8?q?LEKr+hjgS0+X7lvzpHkPyExPiM6N0Uf8UPrzMSmvpr1ZmyPFhs/ZvdqoQ1L/0PLVX?= =?utf-8?q?K3onBWKClbdGgZVM2ziZfkBOQyYS4VGU4Lzew6N79QVX3MVZEIIdWhaswWV9+UYMi?= =?utf-8?q?ySecm0Le6suonrxMkY2oe5s1L2tPb7JPaJ5RmmAoXZ3Xvo6VvipmIMasomZ5a43Sh?= =?utf-8?q?rsVxliIyWgROWkwk/fGlv2HGKCl3WAbIyM5XgwiSwXWZ6ryaMcfIh4WTAX33ZBUYL?= =?utf-8?q?qYWytjc7nI8bgBdR5QB6WZ8XcCbD8qar/Zc7vkOUWb85NXHOeTzXuuBP688CQz8IW?= =?utf-8?q?MJ+D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EVjU3tz5UIYf4OaXwz+meULNKW1lMhfMDAYmFu1oRiyAEMD1Bd?= =?utf-8?q?vhQMZbkpk41GusBcDnKh3bAngEFApMs+GA=3D=3D?= X-OriginatorOrg: cherry.de X-MS-Exchange-CrossTenant-Network-Message-Id: 3ae0d7fc-eb38-4066-dd6f-08dc8a0bda65 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6382.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 11:44:29.7217 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5e0e1b52-21b5-4e7b-83bb-514ec460677e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ean+9eWTceK6NLpi++7Xezd5LC79ytJ4U5XLdeIGqI9dKucsvW54g7AqXobCJVbG+YJiDGhG7Je9RBxLEujyzD+5T7Yc7qRqAlJ3i/0DJs4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB10301 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 --- drivers/i2c/muxes/Kconfig | 18 +++++ drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-mule.c | 157 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig index db1b9057612a..70876259796d 100644 --- a/drivers/i2c/muxes/Kconfig +++ b/drivers/i2c/muxes/Kconfig @@ -119,4 +119,22 @@ config I2C_MUX_MLXCPLD This driver can also be built as a module. If so, the module will be called i2c-mux-mlxcpld. +config I2C_MUX_MULE + tristate "Mule I2C device multiplexer" + depends on OF + help + 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). + + If you say yes to this option, support will be included for a + Mule I2C device multiplexer. This driver provides access to + I2C devices connected on the Mule I2C mux. + + This driver can also be built as a module. If so, the module + will be called i2c-mux-mule. + endmenu diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile index 6d9d865e8518..4b24f49515a7 100644 --- a/drivers/i2c/muxes/Makefile +++ b/drivers/i2c/muxes/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o obj-$(CONFIG_I2C_MUX_GPMUX) += i2c-mux-gpmux.o obj-$(CONFIG_I2C_MUX_LTC4306) += i2c-mux-ltc4306.o obj-$(CONFIG_I2C_MUX_MLXCPLD) += i2c-mux-mlxcpld.o +obj-$(CONFIG_I2C_MUX_MULE) += i2c-mux-mule.o obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o obj-$(CONFIG_I2C_MUX_PINCTRL) += i2c-mux-pinctrl.o diff --git a/drivers/i2c/muxes/i2c-mux-mule.c b/drivers/i2c/muxes/i2c-mux-mule.c new file mode 100644 index 000000000000..db27fa560995 --- /dev/null +++ b/drivers/i2c/muxes/i2c-mux-mule.c @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Mule I2C device multiplexer + * + * Copyright (C) 2024 Theobroma Systems Design und Consulting GmbH + */ + +#include +#include +#include +#include +#include +#include + +#define MUX_CONFIG_REG 0xff +#define MUX_DEFAULT_DEV 0x0 + +struct mule_i2c_reg_mux { + struct regmap *regmap; +}; + +static const struct regmap_config mule_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static inline int __mux_select(struct regmap *regmap, u32 dev) +{ + return regmap_write(regmap, MUX_CONFIG_REG, dev); +} + +static int mux_select(struct i2c_mux_core *muxc, u32 dev) +{ + struct mule_i2c_reg_mux *mux = muxc->priv; + + return __mux_select(mux->regmap, dev); +} + +static int mux_deselect(struct i2c_mux_core *muxc, u32 dev) +{ + return mux_select(muxc, MUX_DEFAULT_DEV); +} + +static void mux_remove(void *data) +{ + struct i2c_mux_core *muxc = data; + + i2c_mux_del_adapters(muxc); + + mux_deselect(muxc, MUX_DEFAULT_DEV); +} + +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); + + muxc = i2c_mux_alloc(adap, &client->dev, + ndev, sizeof(*priv), + I2C_MUX_LOCKED, + mux_select, mux_deselect); + 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); + 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 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 ret; + } + } + + mux_deselect(muxc, MUX_DEFAULT_DEV); + + return 0; +} + +static const struct of_device_id mule_i2c_mux_of_match[] = { + {.compatible = "tsd,mule-i2c-mux",}, + {}, +}; +MODULE_DEVICE_TABLE(of, mule_i2c_mux_of_match); + +static struct i2c_driver mule_i2c_mux_driver = { + .driver = { + .name = "mule-i2c-mux", + .of_match_table = mule_i2c_mux_of_match, + }, + .probe = mule_i2c_mux_probe, +}; + +module_i2c_driver(mule_i2c_mux_driver); + +MODULE_AUTHOR("Farouk Bouabid "); +MODULE_DESCRIPTION("I2C mux driver for Mule"); +MODULE_LICENSE("GPL");