mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] arm: mach-orion5x: ts78xx: simplify support configuration with table
@ 2025-10-12 23:51 Alex Tran
  2025-10-13 12:14 ` Andrew Lunn
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Tran @ 2025-10-12 23:51 UTC (permalink / raw)
  To: alex
  Cc: andrew, sebastian.hesselbarth, gregory.clement, linux,
	linux-arm-kernel, linux-kernel, Alex Tran

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-13 12:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-12 23:51 [PATCH v1] arm: mach-orion5x: ts78xx: simplify support configuration with table Alex Tran
2025-10-13 12:14 ` Andrew Lunn

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®