[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251012235147.325532-1-alex.t.tran@gmail.com>
Date: Sun, 12 Oct 2025 16:51:47 -0700
From: Alex Tran <alex.t.tran@...il.com>
To: alex@...riz.org.uk
Cc: andrew@...n.ch,
sebastian.hesselbarth@...il.com,
gregory.clement@...tlin.com,
linux@...linux.org.uk,
linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org,
Alex Tran <alex.t.tran@...il.com>
Subject: [PATCH v1] arm: mach-orion5x: ts78xx: simplify support configuration with table
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@...il.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
Powered by blists - more mailing lists