From patchwork Mon May 6 11:37: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: 796097 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2134.outbound.protection.outlook.com [40.107.22.134]) (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 9FD74143C65; Mon, 6 May 2024 12:24:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.134 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714998270; cv=fail; b=KtJQSaydWwv2+WyDLUaO5kphcSrZnG39RuRDzjKm3lhaqTDoqatEbNshVwV9HC7B2eic+V17ppmm5Ud1ArwcYNBzwnEMOupTFk1QqjI8sB6QiEtU10XNwmHxG3Icik4Z1LItqmDCdtm9dm1lsp6170gGhx8uldlnApfo+t29IYk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714998270; c=relaxed/simple; bh=/3tU5oEp1PyVb/8VTRLzwNflZMx3jKZpa4G30Kf+HZI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=sGqg1TmCR1iTLHckZKF4gNS5SBrmIK6YAtCUBAuHy85QOXwpM9SpnBEQgN6nS2DJvSCcTb6alQHUhBXpWBf26nQ9eI8nTgyW5p1pkySSeil4RNPJcERrQo0ejY4DLhKwHufC9TPsPxWBFMoY0jwX3JvETmWhrHBS7piuJt572u0= 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=csHEwPi/; arc=fail smtp.client-ip=40.107.22.134 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="csHEwPi/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BQGnprD+sykCMq7SQhxo+p0c4XXA4MNeAkZtotJGml3TxRUvVRkPNrzDzHRada4EieaeN+UNxLp4p9cRoaxTnOIpiLTbsrudJcbSc5UDqlmw2PANFGYlcVVvY1/Kbm1+0KDGIvlzhg4jesraql+3WdbymfP7t0RmgUcj7J05KnBpql0x9pW82hSJkkwqLF7XeOZFOEIOSsWrBVwi9kLlDXn9NoB/os069HMC15CzSg7ArCzSbF7CyeIxZ2VKTjym3VZR57yRKP2g5kAuLivJhNvBfyo2Uu3dTdydX4B+sClntXOQXIKfA701l9pIttF9q0K+zFlaO7Ef2/8Hh41/bQ== 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=rPMpt+YkB7cnmhpDNTVx484n70RADJC0Zbe8qS+2Dgg=; b=VTDSZKj3ZYwM17CoYQXCLfidCfpPI7ZKSfAcbQ+7ISlE6Xm/NXvfA7FwJbjm7HNYVTGftVD18HRzzANQ0SOtDFIp+gdk8pr6OYpovmaOK6YMvu3qFznzw+g94SfKRpGg856Ig7t0q+XejmKe2vldKLHsbVCn4ZHa71Nc9jODFcdFpJPkSrViKgvNg2oP2GScAM7E6vUdgeC3cVsSMqZKiS0sjbpBKtKbsgcYOwe6ORUQFHaa6QqrTEOtaG9nAq85p039Jm+jnVcdHGQa6h7azCOHFzmzih+xFgZfsnODlWMlxe1tslo1ApJtal3fXDc4wMfnoJu3SGd8NVaWHDahAw== 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=rPMpt+YkB7cnmhpDNTVx484n70RADJC0Zbe8qS+2Dgg=; b=csHEwPi/UEvEjAilo67VGPj5RGvUPpm+QitMR1AhCM1WSjieVv3lWCfdy1l8lmyB6tGJfbvn5tCNkFckcJq68qFNpXkI973kkTvdl3DTAHlbFEIo6Sok+fA4Wnw++645gI1oHuyLSU1qZb9kfKO1awlPJr0mfYQeO5/fE8n3i7I= 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 AS8PR04MB9512.eurprd04.prod.outlook.com (2603:10a6:20b:40f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 12:24:19 +0000 Received: from VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::59d9:878d:65f0:3936]) by VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::59d9:878d:65f0:3936%4]) with mapi id 15.20.7544.029; Mon, 6 May 2024 12:24:19 +0000 From: Farouk Bouabid Date: Mon, 06 May 2024 13:37:54 +0200 Subject: [PATCH v2 3/7] i2c: muxes: add support for mule i2c multiplexer Message-Id: <20240506-dev-mule-i2c-mux-v2-3-a91c954f65d7@cherry.de> References: <20240506-dev-mule-i2c-mux-v2-0-a91c954f65d7@cherry.de> In-Reply-To: <20240506-dev-mule-i2c-mux-v2-0-a91c954f65d7@cherry.de> To: Wolfram Sang , Peter Rosin , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Farouk Bouabid , Quentin Schulz , Heiko Stuebner , Quentin Schulz 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: VI1PR0102CA0103.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::44) 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_|AS8PR04MB9512:EE_ X-MS-Office365-Filtering-Correlation-Id: b5359552-88a7-432d-281d-08dc6dc77200 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|366007|7416005|1800799015|52116005|376005|921011|38350700005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?/mjfFhiRTLmHIOj4YzIoWueSEivHInS?= =?utf-8?q?aZfxyQvtDXeINoO5WswYJzEBIb2+qNKyeN+YlQ3/+PX4sK+PORt9s9z61VIC7LuBh?= =?utf-8?q?kHH6xbrHM4O6I1nKrefPEWQkh3AlYlvqcORWTRkXlCzODj8kSUdQVAxRHjiDdQAMq?= =?utf-8?q?dsF8bWFd61wXoXJrxEWtTlg5Fig8u3hhWkBGbrBPN+VM05go5kPXowuP2CsbToCGT?= =?utf-8?q?FICecH5TV6Ta/wTDxpaj7mmuKyGH3YYQfq7znxlhQsmoJSCdBQLmcXLc4IwG9yodI?= =?utf-8?q?OwKY7TYw/pMZWRZ41j5xsRMvonhuh2Agm/c5VrqwnF3ahv4f0lJ8N0CeNhTWvAROJ?= =?utf-8?q?Ht4UC52kVMDzth1JlMOCgnHz7uXvw4POBDg+zlzJ1P3TLt/7KtT4FbPcIHVbQAz78?= =?utf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=?utf-8?q?lyjXT4PoQFIE306T5Iycp4uU9yl5QX2NppBEktjEpc1wf96UxKdLtlZk=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)(366007)(7416005)(1800799015)(52116005)(376005)(921011)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Yeo3HylL1KtjYsR4Dtauyz4rGEUp?= =?utf-8?q?zrMinNU/mkrAhw6f46J8YR9VmJgto49jqi8ApZrIKrVzycqMCx5yZo+dbld4Bqiwm?= =?utf-8?q?GfXfbFHhcaki4hLn9l2PUWUEmgwdzHCw+ZQEoxMYOUO/KUxCPOiJ+pxzW49lFG6OO?= =?utf-8?q?dRlCx4ActtdvOC2zGXO3jlFTyaWjGGKZuizDjMjZCrlp5W2Km1KcItMhG71WWmDWZ?= =?utf-8?q?GEf6ZAYRJtHJCTQUG3WDKnFrUwJMQirZJ1l8SHqfVlzwELLBJX6KlzUuvUvtuve5x?= =?utf-8?q?8kQJAtzHjwsgvmg4zCTyne43wP6PgX59f7bXu5M8bpGnYPZmAQmI3l/gkcYJAJAYK?= =?utf-8?q?h943ZG0EHtSNqDdySURWQhdvJZ47JjrN3wxLar2hUydxfCbmWeiwUE8KhSd7dP1Hj?= =?utf-8?q?+J7F+VL3yM86hpMb1WkYXZ23HrM/Ng8SdIjRkqir+xwO4bDbHlgq96gzA3GaLY0VB?= =?utf-8?q?u1NL4pleJt2df5nPpDvoWKb+DqzoDNhkS82LW1lJZgsomXwbEZo/TTl4bAgorZUms?= =?utf-8?q?1D/AxZw0y1T4QaNjsZirB9AFnQ0b8AH4mLEUaJXl457BxYOQJRbeKsu/urwqst4u2?= =?utf-8?q?EyqRMeyXCIIBMvD4hRy8PaXbCSWnm6Ykm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xV4MxrdrKDx63msZ2DS?= =?utf-8?q?2ICh8NvT2r8VF7QF0E6IWHyWeZxG2MYKkg=3D=3D?= X-OriginatorOrg: cherry.de X-MS-Exchange-CrossTenant-Network-Message-Id: b5359552-88a7-432d-281d-08dc6dc77200 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6382.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2024 12:24:15.9736 (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: fqd67OihrbR7pViEvmpaLbDKREcAH9BLHzvDuUO91LBTGDOCcsEh/utbwzuHF+WQEGqsOpsW8dDfHi7OiggV3UDTAq3kolT54tSvLykrBws= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9512 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 core 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..45d3c5997a4f 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 core 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..781c978276cd --- /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; + bool old_fw; + int ndev, ret; + + /* 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");