Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.105 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796118375; b=NmJyRAT6BsZIJxl3Zwu4zHWnZRmI3RFYfTE6GqtjpcSzpKwnvSE+1RV/VCkC3MUqOV+u whPpufr8ET3jN21ABoIz609GrKu/3s/Xvtv/WTpPCfKiCcuudZ7jwufxFw/44HxOKIFvt okyylsxNJCfp4PQfjJFLOUw8NPYeRr22ATriwqJH7GE2v8MXTCQPXXh8PieSbL+B/rl3t kpJttwg2B1WuWyKASvB/okbXbDk8kBZCtZGtUIpuK9lbFUoSwTXDKaEhH3a/fs3NYipKv Qh6hkpKHEg0HBcPvCfmX4gA90d75s+vl0ENcbllOlYMXKiY+HbL2ch+4NrChn8HcI+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796118375; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=19LMjn8Zgh8YD6gw5NtODr8zZxyfr6f6qPbfU3612mg=; b=hXpjZwRc1/nWCIXUH6kkKx2PG5g9y/ulyCe8ruRayQBkmBfXuNqDiU6G55evPhNTgw74 VCKQYWL4ZnPgw3XFIEnJ+/5RVgOfrM/+AzkVYXLaTRr1Aqp6UaCXS8tbSclkk0pQlKnsI nBzTzQEPambi9igaRHHxS1ZZhCNLZOJM9lT8pOpWAf2++CyzU06UM8zMzUeIqH/V4giyJ RwMDrQcur8u+BjDeVZdF/Cog9wRklARwcjawkOqJwTOOZ/8GpOXUVYwNsn9fyp1569RSi zc6dAuuHQ2LmXY22vPEmNhB3TP97siEatWqmmYF/nbGIeUIxJIYnx1ykoT4rIz80kPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=a1zzNJsZ; arc=none smtp.remote-ip=95.215.58.105 Received: from mta1.migadu.com (out-105.mta1.migadu.com [95.215.58.105]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FB47606A6B9 for ; Tue, 1 Dec 2026 09:46:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2FB47606A6B9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=a1zzNJsZ X-Envelope-To: linux-i2c@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=eiTOdLpZ+u1sA5TxtcTuxu17HITtnZ6WVpyBl6tCtQQ=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796118373; v=1; x=1796723173; b=a1zzNJsZFMaNMor49OAzWol0hUAc1cuPztNOClgnslH+lwE+kFDfbgEDsLFudI3Npeco1u1Q E6ydFrNLE+azKONNeXWIlJr93KVobzP/w6s4utcLGgC++4l92AWDixRylG2nRKUXHpHiyDrVCjx KjQNqNMskTTQ6yOMRrMtE6mg= X-Envelope-To: linux-i2c@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 7079dd1b20096a9f; Tue, 01 Dec 2026 09:46:13 +0000 X-Mizu-Trace-ID: 7079dd1b20096a9f X-Migadu-Flow: FLOW_OUT From: Peng Fan Date: Tue, 01 Dec 2026 17:45:51 +0800 Subject: [PATCH 1/2] i2c: add subsys_i2c_driver() macro X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261201-add-i2c-subsys-mfd-v1-1-e7b1db408abf@nxp.com> References: <20261201-add-i2c-subsys-mfd-v1-0-e7b1db408abf@nxp.com> In-Reply-To: <20261201-add-i2c-subsys-mfd-v1-0-e7b1db408abf@nxp.com> To: Andi Shyti , Lee Jones , Support Opensource , Charles Keepax , Richard Fitzgerald , Chanwoo Choi , Krzysztof Kozlowski , Aaro Koskinen , Andreas Kemnade , Kevin Hilman , Roger Quadros , Tony Lindgren , Matti Vaittinen , Wolfram Sang Cc: linux-i2c@vger.kernel.org, mfd@lists.linux.dev, patches@opensource.cirrus.com, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, Peng Fan X-Mailer: b4 0.14.3 From: Peng Fan Add subsys_i2c_driver() and subsys_i2c_driver_probe() macros so that I2C drivers registered at the subsys_initcall() level can avoid the open-coded init/exit boilerplate. subsys_i2c_driver() replaces subsys_initcall() plus module_exit() for drivers that need an unregister path. subsys_i2c_driver_probe() replaces subsys_initcall() for drivers without an exit callback. Signed-off-by: Peng Fan --- include/linux/i2c.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 6a847fc88d25..f26bb2e0ba0d 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -915,6 +915,29 @@ void i2c_del_driver(struct i2c_driver *driver); #define i2c_add_driver(driver) \ i2c_register_driver(THIS_MODULE, driver) +/* + * subsys_i2c_driver() - Helper macro for i2c drivers that don't do anything + * special in module init/exit but need to register earlier, at + * subsys_initcall level, when built in. This eliminates a lot of + * boilerplate. Each driver may only use this macro once, and calling it + * replaces subsys_initcall() and module_exit(). + */ +#define subsys_i2c_driver(__i2c_driver) \ + subsys_driver(__i2c_driver, i2c_add_driver, i2c_del_driver) + +/* + * subsys_i2c_driver_probe() - Helper macro for drivers that don't do + * anything special in driver register and have no exit, but need to register + * earlier, at subsys_initcall level. This eliminates some boilerplate. Each + * driver may only use this macro once, and using it replaces subsys_initcall. + */ +#define subsys_i2c_driver_probe(__i2c_driver) \ +static int __init __i2c_driver##_init(void) \ +{ \ + return i2c_add_driver(&__i2c_driver); \ +} \ +subsys_initcall(__i2c_driver##_init) + static inline bool i2c_client_has_driver(struct i2c_client *client) { return !IS_ERR_OR_NULL(client) && client->dev.driver; -- 2.56.0