From patchwork Mon Nov 11 22:02:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2009940 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=IlCNTPmV; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=VKutWb2w; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XnNpm5Q67z1xwF for ; Tue, 12 Nov 2024 09:03:28 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4J7CtLD+Av9Iz36ZYVjGDlrlFce+Kqp2SyqUS8ptQhE=; b=IlCNTPmVzNF6Nc zbJszq7xK7qancHAYuL3xXu3kwjfdoBcfeAG7fIovZOvKlzp6Te1edwuhYp1srnS7ex9Oq227m7EO HoYG0FyYKe30idUxLdpMdFSS/wo/I6KsXS2CH1pvHk5i3U+RoU5eeBgRAVouQS8zWNUoSgY5fNzL/ H/YfAiDX/6qcBxi/PTw9mecL1UQACYAdWptH2YBSGSM0t/F/y5SlSPTlP3l4kzxd6s7YDU44HwIJd zA80p3AEsmySVEqGFDs/VXibDAKUjhYMDGpFNOy9VCmHGvnGrVVVWHjKsPG9WveDVGGwCC+zkTDC/ eFITGPphpKT+sL5plcAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAcVE-00000001RSU-0ARz; Mon, 11 Nov 2024 22:03:20 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAcV7-00000001RO3-3yex for opensbi@lists.infradead.org; Mon, 11 Nov 2024 22:03:15 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-20ca1b6a80aso53322925ad.2 for ; Mon, 11 Nov 2024 14:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731362593; x=1731967393; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H8649rlh4jfqfSG3EFGw96deB1ol3jSGUhJFBQ3uXvQ=; b=VKutWb2wscg1ijXP98C0cR7urJXZ4WxSFTn7gzU3yTptOaMcT+EzBlGcD3kThjBfJT tqbPmeShmrDsnIX7r80joPxqDTPBUSX38LQBVLpCKzS6QIBZjax17Xne8r4ZrVvNgbfg k7dHkrDyeU3+POXBgnxSb1BiyYroZI0yA9/NmlgCeqn1+uB1f7K+81mIDnQfwpRM0SOC oXk9cOBJZ3URzByI7lUDFqw688kmtczh42dd+f5z2U9c+MFVKmjPZ/JfFWNwwLgLJOd5 hNv9LXFoQLoS+vuZgS8yeIAHuguhMeNWsMehqsn31lcJ6Lie0HpquD+YHe3j4nvBCvG6 lxxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731362593; x=1731967393; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H8649rlh4jfqfSG3EFGw96deB1ol3jSGUhJFBQ3uXvQ=; b=o3oUF+Siyj7RxEdFeEbfwnDs44yAwt+vsmknA6hSwyj+hTny7YUSXG8QcPHGo7lV2d h/CWdxIgl+pmHC2KUDFLACtrEtNk8TnJBSRp47WIZ8HGhb08oQr1k/i8j4GY3Iop5xqu YSOPhTAD3vL8t4lU95MhR5QTbrU7kYXyjImrDegmfaHruZwtmbuJWJCzfIE0Y/nZ3NXE 1CaGsDvJoIyrfGTe1YXYpws5rxvpJY5IOQJVV3WYsDCiJXbfTYRZLvoD6/cH97KSpT39 WQPAaAm+moON2wYkohNIDbGZaaXj1hK9VRL7t8ZE2tjdaEMwHuoZurIL/h3N8rYRNE9G sj9Q== X-Gm-Message-State: AOJu0YyRsSSt/oMyPjSvCZ7FTkgRyyC4yIMXdctd/GqVbsdknPyQgL4E IVIBAvTqlWT1p0UmmREYL9SSa/MDYuD2CMXgWUnc+1sqb8b9KLIi7v905RsNG4OUs814EwuObXO jpO9NuoMD0IXJBgUj7tsOd45FdUc7n7j8VJblWHTZAERLOoquMosVzV/GEULL2zzWy+/Jm88yOy /ZIYKrvYOnEQsUTFtCrGAnb4w8OADiC8UBSTBRLSStHWD+R6HDKws= X-Google-Smtp-Source: AGHT+IGGZ9FqN0oVoQ5ld/8NYdmNk6dYaCv9OfU0E+TTtoDgjX/A05aeyg8KAkknFEuozz2MqLY5jQ== X-Received: by 2002:a17:903:41c6:b0:202:cbf:2d6f with SMTP id d9443c01a7336-21183db6b71mr161696625ad.57.1731362592820; Mon, 11 Nov 2024 14:03:12 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58316sm80832635ad.188.2024.11.11.14.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 14:03:12 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH v2 06/11] lib: utils/i2c: Use fdt_driver for initialization Date: Mon, 11 Nov 2024 14:02:50 -0800 Message-ID: <20241111220304.1228821-7-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241111220304.1228821-1-samuel.holland@sifive.com> References: <20241111220304.1228821-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_140314_149355_2B1DD34B X-CRM114-Status: GOOD ( 13.89 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The i2c driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland --- Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:634 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The i2c driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- (no changes since v1) include/sbi_utils/i2c/fdt_i2c.h | 8 +----- lib/utils/i2c/fdt_i2c.c | 30 ++------------------ lib/utils/i2c/fdt_i2c_adapter_drivers.carray | 2 +- lib/utils/i2c/fdt_i2c_dw.c | 2 +- lib/utils/i2c/fdt_i2c_sifive.c | 2 +- 5 files changed, 7 insertions(+), 37 deletions(-) diff --git a/include/sbi_utils/i2c/fdt_i2c.h b/include/sbi_utils/i2c/fdt_i2c.h index 65758ec2..8cae4c2a 100644 --- a/include/sbi_utils/i2c/fdt_i2c.h +++ b/include/sbi_utils/i2c/fdt_i2c.h @@ -10,15 +10,9 @@ #ifndef __FDT_I2C_H__ #define __FDT_I2C_H__ +#include #include -/** FDT based I2C adapter driver */ -struct fdt_i2c_adapter { - const struct fdt_match *match_table; - int (*init)(const void *fdt, int nodeoff, - const struct fdt_match *match); -}; - /** Get I2C adapter identified by nodeoff */ int fdt_i2c_adapter_get(const void *fdt, int nodeoff, struct i2c_adapter **out_adapter); diff --git a/lib/utils/i2c/fdt_i2c.c b/lib/utils/i2c/fdt_i2c.c index 56891a0a..d5d36c21 100644 --- a/lib/utils/i2c/fdt_i2c.c +++ b/lib/utils/i2c/fdt_i2c.c @@ -11,36 +11,11 @@ * Anup Patel */ -#include #include -#include #include /* List of FDT i2c adapter drivers generated at compile time */ -extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[]; - -static int fdt_i2c_adapter_init(const void *fdt, int nodeoff) -{ - int pos, rc; - struct fdt_i2c_adapter *drv; - const struct fdt_match *match; - - /* Try all I2C drivers one-by-one */ - for (pos = 0; fdt_i2c_adapter_drivers[pos]; pos++) { - drv = fdt_i2c_adapter_drivers[pos]; - match = fdt_match_node(fdt, nodeoff, drv->match_table); - if (match && drv->init) { - rc = drv->init(fdt, nodeoff, match); - if (rc == SBI_ENODEV) - continue; - if (rc) - return rc; - return 0; - } - } - - return SBI_ENOSYS; -} +extern const struct fdt_driver *const fdt_i2c_adapter_drivers[]; static int fdt_i2c_adapter_find(const void *fdt, int nodeoff, struct i2c_adapter **out_adapter) @@ -50,7 +25,8 @@ static int fdt_i2c_adapter_find(const void *fdt, int nodeoff, if (!adapter) { /* I2C adapter not found so initialize matching driver */ - rc = fdt_i2c_adapter_init(fdt, nodeoff); + rc = fdt_driver_init_by_offset(fdt, nodeoff, + fdt_i2c_adapter_drivers); if (rc) return rc; diff --git a/lib/utils/i2c/fdt_i2c_adapter_drivers.carray b/lib/utils/i2c/fdt_i2c_adapter_drivers.carray index fd51ae1a..0e8c73a4 100644 --- a/lib/utils/i2c/fdt_i2c_adapter_drivers.carray +++ b/lib/utils/i2c/fdt_i2c_adapter_drivers.carray @@ -1,3 +1,3 @@ HEADER: sbi_utils/i2c/fdt_i2c.h -TYPE: struct fdt_i2c_adapter +TYPE: const struct fdt_driver NAME: fdt_i2c_adapter_drivers diff --git a/lib/utils/i2c/fdt_i2c_dw.c b/lib/utils/i2c/fdt_i2c_dw.c index 7d14ea0d..b0905e7b 100644 --- a/lib/utils/i2c/fdt_i2c_dw.c +++ b/lib/utils/i2c/fdt_i2c_dw.c @@ -49,7 +49,7 @@ static const struct fdt_match fdt_dw_i2c_match[] = { { }, }; -struct fdt_i2c_adapter fdt_i2c_adapter_dw = { +const struct fdt_driver fdt_i2c_adapter_dw = { .match_table = fdt_dw_i2c_match, .init = fdt_dw_i2c_init, }; diff --git a/lib/utils/i2c/fdt_i2c_sifive.c b/lib/utils/i2c/fdt_i2c_sifive.c index b420a7da..40811cb4 100644 --- a/lib/utils/i2c/fdt_i2c_sifive.c +++ b/lib/utils/i2c/fdt_i2c_sifive.c @@ -265,7 +265,7 @@ static const struct fdt_match sifive_i2c_match[] = { { }, }; -struct fdt_i2c_adapter fdt_i2c_adapter_sifive = { +const struct fdt_driver fdt_i2c_adapter_sifive = { .match_table = sifive_i2c_match, .init = sifive_i2c_init, };