mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Tran <alex.t.tran@gmail.com>
To: alex@digriz.org.uk
Cc: andrew@lunn.ch, sebastian.hesselbarth@gmail.com,
	gregory.clement@bootlin.com, linux@armlinux.org.uk,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Alex Tran <alex.t.tran@gmail.com>
Subject: [PATCH v1] arm: mach-orion5x: ts78xx: simplify support configuration with table
Date: Sun, 12 Oct 2025 16:51:47 -0700	[thread overview]
Message-ID: <20251012235147.325532-1-alex.t.tran@gmail.com> (raw)

Replace switch statement based configuration with a lookup table approach.
The table is iterated through matching the correct configuration instead of
setting the configuration on a case by case basis.

Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
---
 arch/arm/mach-orion5x/ts78xx-fpga.h  |  7 ++++
 arch/arm/mach-orion5x/ts78xx-setup.c | 60 +++++++++++++++-------------
 2 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/arch/arm/mach-orion5x/ts78xx-fpga.h b/arch/arm/mach-orion5x/ts78xx-fpga.h
index 2f4fe3ca5c1a..e35c63382b4c 100644
--- a/arch/arm/mach-orion5x/ts78xx-fpga.h
+++ b/arch/arm/mach-orion5x/ts78xx-fpga.h
@@ -40,3 +40,10 @@ struct ts78xx_fpga_data {
 
 	struct fpga_devices	supports;
 };
+
+struct ts78xx_fpga_support_config {
+	u32 id;
+	bool rtc_present;
+	bool nand_present;
+	bool rng_present;
+};
diff --git a/arch/arm/mach-orion5x/ts78xx-setup.c b/arch/arm/mach-orion5x/ts78xx-setup.c
index af810e7ccd79..cd8e15cf6a13 100644
--- a/arch/arm/mach-orion5x/ts78xx-setup.c
+++ b/arch/arm/mach-orion5x/ts78xx-setup.c
@@ -325,6 +325,18 @@ static void ts78xx_ts_rng_unload(void)
 /*****************************************************************************
  * FPGA 'hotplug' support code
  ****************************************************************************/
+static const struct ts78xx_fpga_support_config ts78xx_fpga_support_table[] = {
+	{ TS7800_REV_1, 1, 1, 1 },
+	{ TS7800_REV_2, 1, 1, 1 },
+	{ TS7800_REV_3, 1, 1, 1 },
+	{ TS7800_REV_4, 1, 1, 1 },
+	{ TS7800_REV_5, 1, 1, 1 },
+	{ TS7800_REV_6, 1, 1, 1 },
+	{ TS7800_REV_7, 1, 1, 1 },
+	{ TS7800_REV_8, 1, 1, 1 },
+	{ TS7800_REV_9, 1, 1, 1 },
+};
+
 static void ts78xx_fpga_devices_zero_init(void)
 {
 	ts78xx_fpga.supports.ts_rtc.init = 0;
@@ -334,36 +346,30 @@ static void ts78xx_fpga_devices_zero_init(void)
 
 static void ts78xx_fpga_supports(void)
 {
-	/* TODO: put this 'table' into ts78xx-fpga.h */
-	switch (ts78xx_fpga.id) {
-	case TS7800_REV_1:
-	case TS7800_REV_2:
-	case TS7800_REV_3:
-	case TS7800_REV_4:
-	case TS7800_REV_5:
-	case TS7800_REV_6:
-	case TS7800_REV_7:
-	case TS7800_REV_8:
-	case TS7800_REV_9:
+	const struct ts78xx_fpga_support_config *cfg = NULL;
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(ts78xx_fpga_support_table); i++) {
+		if (ts78xx_fpga_support_table[i].id == ts78xx_fpga.id) {
+			cfg = &ts78xx_fpga_support_table[i];
+			break;
+		}
+	}
+
+	if (cfg) {
+		ts78xx_fpga.supports.ts_rtc.present = cfg->rtc_present;
+		ts78xx_fpga.supports.ts_nand.present = cfg->nand_present;
+		ts78xx_fpga.supports.ts_rng.present = cfg->rng_present;
+	} else if (((ts78xx_fpga.id >> 8) & 0xffffff) == TS7800_FPGA_MAGIC) {
+		pr_warn("unrecognised FPGA revision 0x%.2x\n",
+			ts78xx_fpga.id & 0xff);
 		ts78xx_fpga.supports.ts_rtc.present = 1;
 		ts78xx_fpga.supports.ts_nand.present = 1;
 		ts78xx_fpga.supports.ts_rng.present = 1;
-		break;
-	default:
-		/* enable devices if magic matches */
-		switch ((ts78xx_fpga.id >> 8) & 0xffffff) {
-		case TS7800_FPGA_MAGIC:
-			pr_warn("unrecognised FPGA revision 0x%.2x\n",
-				ts78xx_fpga.id & 0xff);
-			ts78xx_fpga.supports.ts_rtc.present = 1;
-			ts78xx_fpga.supports.ts_nand.present = 1;
-			ts78xx_fpga.supports.ts_rng.present = 1;
-			break;
-		default:
-			ts78xx_fpga.supports.ts_rtc.present = 0;
-			ts78xx_fpga.supports.ts_nand.present = 0;
-			ts78xx_fpga.supports.ts_rng.present = 0;
-		}
+	} else {
+		ts78xx_fpga.supports.ts_rtc.present = 0;
+		ts78xx_fpga.supports.ts_nand.present = 0;
+		ts78xx_fpga.supports.ts_rng.present = 0;
 	}
 }
 
-- 
2.51.0


             reply	other threads:[~2025-10-12 23:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-12 23:51 Alex Tran [this message]
2025-10-13 12:14 ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251012235147.325532-1-alex.t.tran@gmail.com \
    --to=alex.t.tran@gmail.com \
    --cc=alex@digriz.org.uk \
    --cc=andrew@lunn.ch \
    --cc=gregory.clement@bootlin.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=sebastian.hesselbarth@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®