From patchwork Mon Jul 8 16:12:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Farouk Bouabid X-Patchwork-Id: 13726838 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2114.outbound.protection.outlook.com [40.107.20.114]) (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 97EF226AC1; Mon, 8 Jul 2024 16:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.114 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720455198; cv=fail; b=EzHFn8KRsZHx3BywpwA2wEwaQMBe/+dlJbnRQZ4j9YFuNK9z18AWOI7LG/uFASUjqc5la3tSw/GPsPjGz3oh2n4Vli2heDsaHhsCC7a35OsC8LKfkc1rgjaVvEppAIyXdosa6G0tyevHcb7yBpM0AvGkvegC6byR6u5OKc+N/Xk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720455198; c=relaxed/simple; bh=xUOzJhYgGi7tOD03S2/glWYlpwIkiosXRfldjdIrq0E=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=iBrUssVaRP254EA/u5lJxbje4Y+11du2NrzVhmmvRZNZAA0b6/ChVNQJiVkaCWtC/gSSpOCx+Zyz/GChn3fhaTHLKzABQqI/7lwKxYOlwrlNj/qCH5s6gtztCic+uM+icbhkgBj7EXdtZlZhFvfW4/Ie5ZHUWmJtCN5kOemP2HE= 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=AqBfEx14; arc=fail smtp.client-ip=40.107.20.114 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="AqBfEx14" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZLNZrW69qO/h0frXciJzqzLhbf+yUFu9ULG5LDoIeZNVjOx2/+nF+jQ63+cHxWLUmX+c5zAUfzSBZGY2yAe6bu5hlZ77lQE3NznWEMLU0o7z2nGpxv62tGTgB46m+AX6dMbJiGrSlUYJeRfLNcjGZQDPJsdZyaIlndyTk12dVFL2IOBHlgrWtY4FFdBsoUwRRAjnkc0bz2ORbqrPDjOq+OjEmB1L29ZINOZk9T38kcuM396Yi6ifgJeGv5h8J3unnWAIdg9u7NT2kSuywJ7d/8HU01P1xaFrw/gFvq8h76soGK/rl7EqnxxGH72WEvaNUblc4eq5q2FfOSiN/WouJg== 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=8M5rTS0hwBjxoUhV0wrTMNvLyx5reO/n4ovPpVOxKL8=; b=FT3FCZKPZVnj3KM69y0ylE54LBGQdMP+uPpZVOZDoVF87XXrb7tb0gE27eIEZAa7I+RHzWFgA1austm9DJ4hoS831ZWOJIb7Uw6+5yXAs+2obqZpb52fKZjyRvTJdnRDeW6BV9AhgVdiA2/OIMOpy964YXFFaAVbmMB3RKbQFOr2zu5CoMuMOtMuUSxjBeVDSynaSz4bdwEMxa/DfHhIhbiMSHQSwP+vp24g8GFj1Td67HX6NGJh6KEaZeV0fD1hxYNfT1GA04K0ZckEOaTF95y8D164snlHeo8b9hdwO3fJ6zwbStu+eH49kOuEBH5dhR38BM+0tFMvMkCU2R9WQA== 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=8M5rTS0hwBjxoUhV0wrTMNvLyx5reO/n4ovPpVOxKL8=; b=AqBfEx14Hi4j0RGGhpynThyXA5r1ZsLFvQmxIGl3N0icrhhZl9Imr1x5F5YjQZOrCGrMzUATSn8nr/B9EhDYzKOGuzoKM9eIM0MAh9hinbj15t3ppP+ngLTXyetULKF2xw0Zp3QrpGtLB1M6pzhNzCyXODz7eR4HuhozTWO+D5c= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cherry.de; Received: from DU0PR04MB9562.eurprd04.prod.outlook.com (2603:10a6:10:321::10) by GV1PR04MB9055.eurprd04.prod.outlook.com (2603:10a6:150:1e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35; Mon, 8 Jul 2024 16:13:11 +0000 Received: from DU0PR04MB9562.eurprd04.prod.outlook.com ([fe80::ad4d:8d53:1663:d181]) by DU0PR04MB9562.eurprd04.prod.outlook.com ([fe80::ad4d:8d53:1663:d181%4]) with mapi id 15.20.7741.033; Mon, 8 Jul 2024 16:13:11 +0000 From: Farouk Bouabid Date: Mon, 08 Jul 2024 18:12:13 +0200 Subject: [PATCH v5 2/8] i2c: muxes: add support for tsd,mule-i2c multiplexer Message-Id: <20240708-dev-mule-i2c-mux-v5-2-71446d3f0b8d@cherry.de> References: <20240708-dev-mule-i2c-mux-v5-0-71446d3f0b8d@cherry.de> In-Reply-To: <20240708-dev-mule-i2c-mux-v5-0-71446d3f0b8d@cherry.de> To: Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Farouk Bouabid , Quentin Schulz , Peter Rosin , Jean Delvare , Guenter Roeck , Heiko Stuebner Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org X-Mailer: b4 0.14.0 X-ClientProxiedBy: VE1PR03CA0057.eurprd03.prod.outlook.com (2603:10a6:803:118::46) To DU0PR04MB9562.eurprd04.prod.outlook.com (2603:10a6:10:321::10) Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9562:EE_|GV1PR04MB9055:EE_ X-MS-Office365-Filtering-Correlation-Id: 41660f54-5014-41de-1e0b-08dc9f68dd04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|52116014|376014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?oj3wrKWgrk5peqlxh0PBhr6tXMszw9M?= =?utf-8?q?ZZ6RKHRHnBXbeBM+IDL5dIgvc7RLGD/jXAOoyCkXyHYXvll4uGm5djiPK9/9Wb583?= =?utf-8?q?yjGTCO4hlpy7yyyF+bApZ6weIhqP/sxradTXqrHWpi+8k8p7xiZ36bt66XyBW7gVI?= =?utf-8?q?gxXcX5EhjdPfvcMjUXGfxvLTFJLCyntqvzcewT/DL1cMaF8so6BXrxbqkf4L81rdi?= =?utf-8?q?FxF092TgLA7ylDVYHVL3ihzxzkxE7jxu+UCknYaGSavjBaok7yd/XhfgQX9CsOL1j?= =?utf-8?q?QvK2tQtNIzqd1lvQLppHaSs/xki4Ij1l4oJ7ZYwk2H0clQRZk6ppds0n87p0kEifP?= =?utf-8?q?pNGnC1it5ezY3yECTQAPjVG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HMlqgB9vtROMs0sWIOQKZQKvIa6l75UM7/9FizlL7U/jc?= =?utf-8?q?eAelhXRAtWBbCeiJ3kCryUC1keAWLm8CRNB2rQNRWUgJB1B852dNCLccWa5xzZg7h?= =?utf-8?q?OpNYu6ByqyYvTalcxrSzGnrQJ2rTPdDc/5S4botJ9UIF0GflEk0eKxE=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9562.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(7416014)(52116014)(376014)(921020)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?vz/pJx6id8SeNcM/3ZL5fcr0vMvR?= =?utf-8?q?UKR6XbJRleqlZH9Miurv37qGYZTLlFjbI4Jq6TnpRf0RzmnmfiPhAQrHBa4KFOs/l?= =?utf-8?q?AfbWewcLRVhMd6tQcm0hkfenLxNvPJLGFrYbVE/iUcBx+rQ3jkztpoRbdN5TPhjHD?= =?utf-8?q?kyDgjcROE0vFZr73Z3B+hDxYcAXzoM0bhBgEcDkgwPOHLzDwDytQ/EEqulcwoRgrA?= =?utf-8?q?rV2rYQTI9GuTc8dhqsZYL2KA3VtswM1Z7+yzOFT6Eercx/fsKNBE9JyzevQJTVqpY?= =?utf-8?q?3B+9pa1w1T5gI6w9NBY4c+901Lh3QpfjpqGpGxsXDV9t+FUWjbjoSq03K15rj+sWd?= =?utf-8?q?X7y2GAuJi7jK1aQmtMy3S7EMIUvkUxkRq2Zm8En0oPF0uP/sVW+noIMBcreRbFI6G?= =?utf-8?q?TAJbZro0zviOSjBvS+QzEI74vaAdfjVh6X95FhgnMHPrPOmsE3OMMid1lmTsGWr3t?= =?utf-8?q?WxiQoZBoiUB6YwIy7e9rU8QQVCUtN7fpEqEJKVj8RTwzeIfwUMVRldtKx8w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= =?utf-8?q?Ul4ZfdIR0MWLiPxTMYwHD9DwPnbYKkLNVqZistQwxGMZcU9jx3qZ72ksm01zK2egX?= =?utf-8?q?kM1PdlW92lbMeY4qFU2sy27OefBJYeK9gGmNDB3oJqnAmXewEksvvCCyQA3polOSX?= =?utf-8?q?Ve6/Apl4FuWIp20FTZZ1QGLLfUrBa1bdFw=3D=3D?= X-OriginatorOrg: cherry.de X-MS-Exchange-CrossTenant-Network-Message-Id: 41660f54-5014-41de-1e0b-08dc9f68dd04 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9562.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2024 16:13:11.3905 (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: gxKsTB7TSDzDMgmdMzDEzAowUI12z3EuGmq3MnpTtcnn5IK/uXEIVb/Iai6boUjmUC0mQUXlNu6p1f85p5Xvg80kmweChG5eoRLAgCfdM5I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9055 Theobroma Systems Mule is an MCU that emulates a set of I2C devices, among which an amc6821 and devices that are reachable through an I2C-mux. The devices on the mux can be selected by writing the appropriate device number to an I2C config register (amc6821 reg 0xff). This driver is expected to be probed as a platform device with amc6821 as its parent i2c device. Add support for the mule-i2c-mux platform driver. The amc6821 driver support for the mux will be added in a later commit. Signed-off-by: Farouk Bouabid --- drivers/i2c/muxes/Kconfig | 16 ++++ drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-mule.c | 155 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig index db1b9057612a..6d2f66810cdc 100644 --- a/drivers/i2c/muxes/Kconfig +++ b/drivers/i2c/muxes/Kconfig @@ -119,4 +119,20 @@ 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 "Theobroma Systems Mule I2C device multiplexer" + depends on OF && SENSORS_AMC6821 + help + Mule is an MCU that emulates a set of I2C devices, among which + devices that are reachable through an I2C-mux. The devices on the mux + can be selected by writing the appropriate device number to an I2C + configuration register. + + If you say yes to this option, support will be included for a + Theobroma Systems Mule I2C multiplexer. This driver provides access to + I2C devices connected on this 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..062596869651 --- /dev/null +++ b/drivers/i2c/muxes/i2c-mux-mule.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Theobroma Systems Mule I2C device multiplexer + * + * Copyright (C) 2024 Theobroma Systems Design und Consulting GmbH + */ + +#include +#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 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 platform_device *pdev) +{ + struct device *mux_dev = &pdev->dev; + struct mule_i2c_reg_mux *priv; + struct i2c_client *client; + 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(mux_dev->of_node); + dev_dbg(mux_dev, "%d devices on the mux\n", ndev); + + client = to_i2c_client(mux_dev->parent); + + muxc = i2c_mux_alloc(client->adapter, mux_dev, ndev, sizeof(*priv), + I2C_MUX_LOCKED, mux_select, mux_deselect); + if (!muxc) + return dev_err_probe(mux_dev, -ENOMEM, + "Failed to allocate mux struct\n"); + + priv = i2c_mux_priv(muxc); + + priv->regmap = dev_get_regmap(mux_dev->parent, NULL); + if (IS_ERR(priv->regmap)) + return dev_err_probe(mux_dev, PTR_ERR(priv->regmap), + "No parent i2c register map\n"); + + platform_set_drvdata(pdev, muxc); + + /* + * MUX_DEFAULT_DEV 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, MUX_DEFAULT_DEV); + if (ret) + return dev_err_probe(mux_dev, ret, + "Failed to write config register\n"); + + ret = regmap_read(priv->regmap, MUX_CONFIG_REG, &readback); + if (ret) + return dev_err_probe(mux_dev, ret, + "Failed to read config register\n"); + + old_fw = (readback != MUX_DEFAULT_DEV); + + ret = devm_add_action_or_reset(mux_dev, mux_remove, muxc); + if (ret) + return dev_err_probe(mux_dev, ret, + "Failed to register mux remove\n"); + + /* Create device adapters */ + for_each_child_of_node(mux_dev->of_node, dev) { + u32 reg; + + ret = of_property_read_u32(dev, "reg", ®); + if (ret) + return dev_err_probe(mux_dev, ret, + "No reg property found for %s\n", + of_node_full_name(dev)); + + if (old_fw && reg != 0) { + dev_warn(mux_dev, + "Mux is not supported, please update Mule FW\n"); + continue; + } + + ret = mux_select(muxc, reg); + if (ret) { + dev_warn(mux_dev, + "Device %d not supported, please update Mule FW\n", reg); + continue; + } + + ret = i2c_mux_add_adapter(muxc, 0, reg); + if (ret) + return dev_err_probe(mux_dev, ret, + "Failed to add i2c mux adapter %d\n", reg); + } + + 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 platform_driver mule_i2c_mux_driver = { + .driver = { + .name = "mule-i2c-mux", + .of_match_table = mule_i2c_mux_of_match, + }, + .probe = mule_i2c_mux_probe, +}; + +module_platform_driver(mule_i2c_mux_driver); + +MODULE_AUTHOR("Farouk Bouabid "); +MODULE_DESCRIPTION("I2C mux driver for Theobroma Systems Mule"); +MODULE_LICENSE("GPL");