Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1351198lqh; Mon, 6 May 2024 05:25:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWA51k9qkkkJ/2u/pvu7oG9TmQr82/uk+LyBgnDjUNTi665fGIFZ9Gb++AMLzojqvpY/7nOv/B/n2l8tqtjTFwGSO44y7wEIqi6coX3/g== X-Google-Smtp-Source: AGHT+IHvvBNrwHKPtJOZlKEyfhw8wPbP2xXd4/7RRgsKsq/vZC5A7SCqk+SH0oBXZkCOnPfPfC7E X-Received: by 2002:a05:620a:2949:b0:790:9dab:e408 with SMTP id n9-20020a05620a294900b007909dabe408mr14066296qkp.5.1714998319403; Mon, 06 May 2024 05:25:19 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x18-20020a05620a0b5200b00792920062bcsi3633491qkg.482.2024.05.06.05.25.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 05:25:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169802-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@cherry.de header.s=selector1 header.b="csHEwPi/"; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-169802-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169802-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cherry.de 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 165551C237B9 for ; Mon, 6 May 2024 12:25:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCE40144D12; Mon, 6 May 2024 12:24:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cherry.de header.i=@cherry.de header.b="csHEwPi/" 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 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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-kernel@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?B?L21qZkZoaVJUTG1ISU9qNFl6SW9XdWVTRWl2SEluU2FaZnh5UXZ0RFhlSU5v?= =?utf-8?B?TzVXc3dZSnpFQkliMitxTkt5ZU4rWWxRMy8rUFg0c0srUE9SdDlzOXo2MVZJ?= =?utf-8?B?QzdMdUJoa0hINnhickhNNE82STFuS3JlZlBFV1FraDNBbFlsdnFjT1JXVFJr?= =?utf-8?B?WGxDek9EajhrU1VkUVZBeFJIamlEZFFBTXFkc0Y4YldGZDYxd1hvWEpyeEVX?= =?utf-8?B?dFRsZzVGaWc4dTNoaFdrQkdickJQTitWTTA1Z281a1BYb3d1UDJDc2JUb0NH?= =?utf-8?B?VEZJQ2VjSDVUVjZUYS93VER4cGFqN21tdUt5R0gzWVlRZnE3em54bGhRc21v?= =?utf-8?B?SlNDZEJRTG1jWExjNEl3Rzl5b2RJT3dLWTdUW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Za0YwcDBudmNjRTA1djJMOUFWSG1qQXdK?= =?utf-8?B?NU8rKy9BSFd4R1JNdnhaQS9pdjdwcHBrTzRFRUhCMkJMY2UvZHhOS1c0RDFl?= =?utf-8?B?V0phemRBMEI3aW8xZWVvZHcrdm5abHZjTS9mOExlNGZZTmN4NTdpanBrSHEy?= =?utf-8?B?b1ZoWTlGcWp3WVh2MjRUQkNPTTlyYTYwdVg0UlVwN2JQN2tOZUJDeWJwN1dk?= =?utf-8?B?SklHVzBBUm9oWGxCYWlNeC8zOVRJbndwY1ZqcGJqNkkzeUtnN052Y2YvRHBp?= =?utf-8?B?aWJIb2FjU1dXK3RvYVRlTlFSYWdHZE1QUDF5TCthWDRyZFpIdnYxbWh4RTVR?= =?utf-8?B?RG52VGRHZUNMMmFQTU5MbHlaRThNbDV3Z1BKUTdaM3U3T3hGZ3Y5aTVBZjd6?= =?utf-8?B?Tk5hZlRHbURTcEgycExUU29nSjNnZC9Vc1lER09UT3hRWmdONnRXcDkwTWQ2?= =?utf-8?B?UGs2UTJGaXhHc3hwclpQd0hTYkhiS2d1YkpseWpYVDRQb1FGSUUzMDZUNUl5?= =?utf-8?Q?cp4uU9yl5QX2NppBEktjEpc1wf96UxKdLtlZk=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?B?WWVvM0h5bEwxS3RqWXNSNER0YXV5ejRyR0VVcHpyTWluTlUvbWtyQWh3NmY0?= =?utf-8?B?Nko4WVI5Vm1KZ3RvNDlqcWk4QXBacklLclZ6eWNxTUN4NXlabytkYmxkNEJx?= =?utf-8?B?aXdtR2ZYZmJGSGhj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lcTgxVWVZNlBj?= =?utf-8?B?bFBWcGR5b0t1SjJzVlNOZkpCU0xwL1pqR0M2aWNMd2sydDY5amxqajJmdXlo?= =?utf-8?B?NUVXVnh6b3BpL2JzOFMza1VrcEk1cjZxc3BGdGtJTzk2c3lXQnF5aUlHZ09E?= =?utf-8?B?b2NaL0lqdThlUGcrYlAyOU05TlNaLzk1VHhCdHZBY0t5Qm1NWTQweFY0TXhy?= =?utf-8?B?ZHJLRHg2M21zWjJEUzJJQ2g4TnZUMnI4VkY3UUYwRTZJV0h5V2VaeEcyTVlL?= =?utf-8?B?a2c9PQ==?= 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"); -- 2.34.1