From patchwork Mon Sep 2 16:38:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Farouk Bouabid X-Patchwork-Id: 13787492 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2042.outbound.protection.outlook.com [40.107.20.42]) (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 063F01A3026; Mon, 2 Sep 2024 16:38:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725295124; cv=fail; b=F3L9TAII8s0GOinyxmpHORzc/mXRVqhOFPPch2WQzR9Gku9CqWIxYkImUqonT6WwiBxV0itUqi+V6NuloSfoxxfk1e7Nuc0JXBMCqBPZ6PfNQ7DP+GdmLDwXVI1dPu0jCUUGUkiNvsxQMb2AfKi9NGXqq3IQNX/uaS4CR4hosdo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725295124; c=relaxed/simple; bh=fC7wtRjMw2WUSRvtwur4bVVqzmDSHraDrnKTddTLH2E=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=XCvSpG3OwjjtwJrFZ8roIaL92mVN5Fhhbfp1tBmHDUqxoetHf9ZdPKZZ/0zek6ok1mUmXlxJJ9LBRgsNo9YPBQMyi8V56GzunTAzd0r7t6KPPhNDap+WpS1L3UGtV3SK8grIKjzaCc6CSYMf4lSFYOkNCZBCQgsEeamW5Gy0g24= 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=DeATiyKY; arc=fail smtp.client-ip=40.107.20.42 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="DeATiyKY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H/Dh5RV+5nJF8BXFSx4h5BMbjF1bAas0LVw5W0LczmA/SBJTO+j1+jmIf/DRP7W2vRoCHPXmE3M1/nUO1XIkuAna8uswVbq0E/FrJC69TxckDdp892bgTEG/VNEI2hXzA77Pv6ub/18fg9AgecNPZ1ALSCZXQHc3monzro7vlCQb4vQmnxDjjBWIYh9hbQfmPscwDJYmZyxf6GGXuUjCL6GgBJEsZkO9F7ECaK0LJ3YhvQlcu9h//6ivv3UZ3karZU1/eyIiMw9gFPW6/N0Ha+rWTdeoZ7GQdTD+K3MvD2qCZeqWBhmZJJnKsGjvJaJSXuYgim5Zf2bF2gRs8U9JUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=UcCuFOjTGlWzlp1gGW8rLBBx1JsJ8UOIW0H4v78wFv0=; b=gz5NeNChUoMKXgzg93I1pFPKj+R50UtKml1K1aWMRBKzzO6p4hxJCRxIS3Vk0rZjCdIGlkUMFTL4FdIX0F5NBKZ5cctVRwlazwbBDop9lMnqTxAYIlRVUPDrAhVlipQDtsYGfaRiZHR+I6l7IysvSmbGQ1aI8PuSYc9lf7xGkktJhfmvcLnTl0UV7yXqJ4dMoDswaaDhCs/GIbxunyOBdZS8GuSoStarJLIS0XGgZ+0+qMMpB/Q7CeJYKqSDPRjO5emxoz+YmHtHbwHvU4PiGNca9GvVpqvX6aJiyEXdoq8xztMk984tiyIgGoDGjUdyb1/HkiIQaft0pLcwMWrGyA== 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=UcCuFOjTGlWzlp1gGW8rLBBx1JsJ8UOIW0H4v78wFv0=; b=DeATiyKYhi5USasD+4f1AwUsTGQn3nlbA76rCn9VAxn1LmUfdZmX/tmZDwlLl7fbMsvXjJgvzmqWArtQ7yTlm5Mqt5ERTCu3WOtBvKHkEYkku0rMnx+PV/xUf2KaHZ/vAHFlaVEZAZiukWCmXKltcRqVLLp5yYXIOcfZcjB3g+o= 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 DB9PR04MB9645.eurprd04.prod.outlook.com (2603:10a6:10:309::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.24; Mon, 2 Sep 2024 16:38:34 +0000 Received: from DU0PR04MB9562.eurprd04.prod.outlook.com ([fe80::ad4d:8d53:1663:d181]) by DU0PR04MB9562.eurprd04.prod.outlook.com ([fe80::ad4d:8d53:1663:d181%6]) with mapi id 15.20.7918.020; Mon, 2 Sep 2024 16:38:34 +0000 From: Farouk Bouabid Date: Mon, 02 Sep 2024 18:38:15 +0200 Subject: [PATCH v7 2/8] i2c: muxes: add support for tsd,mule-i2c multiplexer Message-Id: <20240902-dev-mule-i2c-mux-v7-2-bf7b8f5385ed@cherry.de> References: <20240902-dev-mule-i2c-mux-v7-0-bf7b8f5385ed@cherry.de> In-Reply-To: <20240902-dev-mule-i2c-mux-v7-0-bf7b8f5385ed@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, Wolfram Sang X-Mailer: b4 0.15-dev-99b12 X-ClientProxiedBy: VI1PR0502CA0001.eurprd05.prod.outlook.com (2603:10a6:803:1::14) 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_|DB9PR04MB9645:EE_ X-MS-Office365-Filtering-Correlation-Id: 90a4fc52-cf83-429c-855e-08dccb6db022 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|7416014|376014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?hxAZ7qrczwoKD5lQ02L+FG1Mi32nMdB?= =?utf-8?q?CKXbeJN49g52XL25BtdAzxDH5wxlXE5bD1e338fMd2Z1QPZrGXXYgQbDPhgYHjawS?= =?utf-8?q?YSbTSQ4cxV5MQVN7yFg4Q910nhQMYlGfpmxWrvocaGT0VXUOhNE9/hFN9kxwfA9h2?= =?utf-8?q?PU2oNy1FojcioyTfXPwdz19vQHVNpWzTkx89N9YQFv5Z5jmJVUNyK/Pt0ZnFE/7Oe?= =?utf-8?q?Ix7WuTw3sX0HiKyVgCS2KNhv3Xl0QZ4p7YaE1QEGq6Y1seIEEby0gyBjieljRJ1p1?= =?utf-8?q?mbu82Bgzd94l/+NSvbvfTX6BibJajb2OVDwUJ8BOfOGZ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wFQ03hsNFCUJAXSko?= =?utf-8?q?EGx6kSyoldLYxELrR1Isjuv0sQZlx7WK7KA6JBtyXgWImHK3C8VLX9TEBIhsr5ctG?= =?utf-8?q?2yOwL8pIch9U2G+ITG4map7YFCDlAndbJThxNkKpxN/Y92Ip8al6D0MDTAfeotZv9?= =?utf-8?q?8cUHU9JQjqGtFw+/kWuiTJcngZRMWDn++Y4z8oSqtXsJs+1ETkT/qn4=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)(52116014)(7416014)(376014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?qujqCShsAau/7wl6UaKnPBiezH4L?= =?utf-8?q?E9a4n812Lj7hk61GoF+nDj2x1XiL/Q82DRp6bY9aizdT19nbXeXCeXo6SZ3njKB+j?= =?utf-8?q?Mz5LSZpCNRyuik12cyGFTRVRDBdM6TIQZKKiHVoVMa2N0G5LQe9NASzN3d3gnLht5?= =?utf-8?q?o88QaOTu64fdhtedZ5GNhDC0m+Qe0rSWtahXk3Y8WouSjzMxTqVB4jtHTPSWgq2D7?= =?utf-8?q?G90qRicEhf0EKsER8YB/+cdc9WdXDGk/4F/TuO7gz7xC16CHAkNi6HccNk1VwLB+n?= =?utf-8?q?1kQ+2lSKfkoWE2gCai0FNrjWLn5lqDgbVs7z+qo1AKMmJbpM2vuXyPN3K0u6t1+49?= =?utf-8?q?nljnw0acfaDbslE+bRe7QA/rYgK/tMigKOw230+guJuxoiz7nHHkL2uyJLcOx4LFy?= =?utf-8?q?9cRn/LPttLUT6u2v9UbG4G3eMFCBtreqdSujrfTLii8VfmnQPBxFTvamufTkb0+Ve?= =?utf-8?q?7ww75epEBn2UvbqTIJNt8dUu4my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xqj2HVyYhf82//LPC4Wj7B5Jul?= =?utf-8?q?4kDGWWzPK8zV7aXkode+vezCcOr9SNi+lGWT2fICHS5aFZ1k2lR13pQvpgnW45Lx9?= =?utf-8?q?6fl6iCemscYW+GWjHmeQvkQgqoYCuyEfKSas+K1n1tCnTcI8zM1EkLl6N8uYfEzaF?= =?utf-8?q?D33BMPYmKEZG+WFEk0BJDaxCa803o8S30A=3D=3D?= X-OriginatorOrg: cherry.de X-MS-Exchange-CrossTenant-Network-Message-Id: 90a4fc52-cf83-429c-855e-08dccb6db022 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9562.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2024 16:38:34.7390 (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: MG/k6KYgv1p2b0xrhmOcHTlu4pP3aerFH2U8ZAHyk9woyjn2vowOrqgLlR8zdXakGuTKxe23MUTY3+gT30qxhP4ttO9QWoFsozXht07M01Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9645 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. Reviewed-by: Wolfram Sang Signed-off-by: Farouk Bouabid --- drivers/i2c/muxes/Kconfig | 16 +++++ drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-mule.c | 148 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 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..e4e8992d4a09 --- /dev/null +++ b/drivers/i2c/muxes/i2c-mux-mule.c @@ -0,0 +1,148 @@ +// 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 int mux_select(struct i2c_mux_core *muxc, u32 dev) +{ + struct mule_i2c_reg_mux *mux = muxc->priv; + + return regmap_write(mux->regmap, MUX_CONFIG_REG, 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 -ENOMEM; + + 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 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 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");