From 1e688601d18d3d872ffaad70c599e8c1a1d788a0 Mon Sep 17 00:00:00 2001 From: Sergio Paracuellos Date: Mon, 27 Feb 2023 11:58:01 +0100 Subject: mips: ralink: rt288x: define RT2880_SYSC_BASE with __iomem So that RT2880_SYSC_BASE can be used later in multiple functions without needing to repeat this __iomem declaration each time Signed-off-by: Sergio Paracuellos Signed-off-by: Thomas Bogendoerfer --- arch/mips/ralink/rt288x.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'arch/mips/ralink/rt288x.c') diff --git a/arch/mips/ralink/rt288x.c b/arch/mips/ralink/rt288x.c index 493335db2fe1..12f339138c4c 100644 --- a/arch/mips/ralink/rt288x.c +++ b/arch/mips/ralink/rt288x.c @@ -59,15 +59,14 @@ void __init ralink_of_remap(void) void __init prom_soc_init(struct ralink_soc_info *soc_info) { - void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT2880_SYSC_BASE); const char *name; u32 n0; u32 n1; u32 id; - n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0); - n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1); - id = __raw_readl(sysc + SYSC_REG_CHIP_ID); + n0 = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0); + n1 = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1); + id = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID); if (n0 == RT2880_CHIP_NAME0 && n1 == RT2880_CHIP_NAME1) { soc_info->compatible = "ralink,r2880-soc"; -- cgit v1.2.3 From 5a5aa151bdccea934d4a84086661538b60a09a42 Mon Sep 17 00:00:00 2001 From: Sergio Paracuellos Date: Mon, 27 Feb 2023 11:58:02 +0100 Subject: mips: ralink: rt288x: soc queries and tests as functions Move the SoC register value queries and tests to specific functions, to remove repetition of logic. No functional changes intended Signed-off-by: Sergio Paracuellos Signed-off-by: Thomas Bogendoerfer --- arch/mips/ralink/rt288x.c | 63 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 16 deletions(-) (limited to 'arch/mips/ralink/rt288x.c') diff --git a/arch/mips/ralink/rt288x.c b/arch/mips/ralink/rt288x.c index 12f339138c4c..a417b8b89b94 100644 --- a/arch/mips/ralink/rt288x.c +++ b/arch/mips/ralink/rt288x.c @@ -57,29 +57,60 @@ void __init ralink_of_remap(void) panic("Failed to remap core resources"); } -void __init prom_soc_init(struct ralink_soc_info *soc_info) +static unsigned int __init rt2880_get_soc_name0(void) { - const char *name; - u32 n0; - u32 n1; - u32 id; + return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0); +} - n0 = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0); - n1 = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1); - id = __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID); +static unsigned int __init rt2880_get_soc_name1(void) +{ + return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1); +} - if (n0 == RT2880_CHIP_NAME0 && n1 == RT2880_CHIP_NAME1) { +static bool __init rt2880_soc_valid(void) +{ + if (rt2880_get_soc_name0() == RT2880_CHIP_NAME0 && + rt2880_get_soc_name1() == RT2880_CHIP_NAME1) + return true; + else + return false; +} + +static const char __init *rt2880_get_soc_name(void) +{ + if (rt2880_soc_valid()) + return "RT2880"; + else + return "invalid"; +} + +static unsigned int __init rt2880_get_soc_id(void) +{ + return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID); +} + +static unsigned int __init rt2880_get_soc_ver(void) +{ + return (rt2880_get_soc_id() >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK; +} + +static unsigned int __init rt2880_get_soc_rev(void) +{ + return (rt2880_get_soc_id() & CHIP_ID_REV_MASK); +} +void __init prom_soc_init(struct ralink_soc_info *soc_info) +{ + if (rt2880_soc_valid()) soc_info->compatible = "ralink,r2880-soc"; - name = "RT2880"; - } else { - panic("rt288x: unknown SoC, n0:%08x n1:%08x", n0, n1); - } + else + panic("rt288x: unknown SoC, n0:%08x n1:%08x", + rt2880_get_soc_name0(), rt2880_get_soc_name1()); snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN, "Ralink %s id:%u rev:%u", - name, - (id >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK, - (id & CHIP_ID_REV_MASK)); + rt2880_get_soc_name(), + rt2880_get_soc_ver(), + rt2880_get_soc_rev()); soc_info->mem_base = RT2880_SDRAM_BASE; soc_info->mem_size_min = RT2880_MEM_SIZE_MIN; -- cgit v1.2.3 From 7a26b384c44cfa9ea65799dc375619c96608ecad Mon Sep 17 00:00:00 2001 From: Sergio Paracuellos Date: Mon, 27 Feb 2023 11:58:03 +0100 Subject: mips: ralink: rt288x: introduce 'soc_device' initialization RT288X SoCs have their own 'ralink_soc_info' structure with some information about the soc itself. In order to be able to retrieve this information from driver code and avoid architecture dependencies for retrieving these details introduce this 'soc_device'. Set 'data' pointer points to the struct 'ralink_soc_info' to be able to export also current soc information using this mechanism. We need to select 'SOC_BUS' in Kconfig configuration for these SoCs. Signed-off-by: Sergio Paracuellos Signed-off-by: Thomas Bogendoerfer --- arch/mips/ralink/rt288x.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'arch/mips/ralink/rt288x.c') diff --git a/arch/mips/ralink/rt288x.c b/arch/mips/ralink/rt288x.c index a417b8b89b94..456ba0b2599e 100644 --- a/arch/mips/ralink/rt288x.c +++ b/arch/mips/ralink/rt288x.c @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include @@ -17,6 +19,8 @@ #include "common.h" +static struct ralink_soc_info *soc_info_ptr; + void __init ralink_clk_init(void) { unsigned long cpu_rate, wmac_rate = 40000000; @@ -98,6 +102,31 @@ static unsigned int __init rt2880_get_soc_rev(void) { return (rt2880_get_soc_id() & CHIP_ID_REV_MASK); } + +static int __init rt2880_soc_dev_init(void) +{ + struct soc_device *soc_dev; + struct soc_device_attribute *soc_dev_attr; + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + soc_dev_attr->family = "Ralink"; + soc_dev_attr->soc_id = rt2880_get_soc_name(); + + soc_dev_attr->data = soc_info_ptr; + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree(soc_dev_attr); + return PTR_ERR(soc_dev); + } + + return 0; +} +device_initcall(rt2880_soc_dev_init); + void __init prom_soc_init(struct ralink_soc_info *soc_info) { if (rt2880_soc_valid()) @@ -117,4 +146,5 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info) soc_info->mem_size_max = RT2880_MEM_SIZE_MAX; ralink_soc = RT2880_SOC; + soc_info_ptr = soc_info; } -- cgit v1.2.3