]> git.itanic.dy.fi Git - linux-stable/commitdiff
mips: ralink: mt7620: introduce 'soc_device' initialization
authorSergio Paracuellos <sergio.paracuellos@gmail.com>
Mon, 27 Feb 2023 10:58:06 +0000 (11:58 +0100)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Tue, 14 Mar 2023 16:13:51 +0000 (17:13 +0100)
MT7620 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 <sergio.paracuellos@gmail.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
arch/mips/ralink/Kconfig
arch/mips/ralink/mt7620.c

index e8b8fb35d33df573375b4c471f0b24b95c5e794d..08c012a2591f9dcbec225e0bda8e154ef3356cda 100644 (file)
@@ -44,6 +44,7 @@ choice
                bool "MT7620/8"
                select CPU_MIPSR2_IRQ_VI
                select HAVE_PCI
+               select SOC_BUS
 
        config SOC_MT7621
                bool "MT7621"
index 8604d91f3375157794ba85df41ed08d20e447566..4435f50b8d243d80fec5a5e5efdc15f8a5e1fbfa 100644 (file)
@@ -11,6 +11,8 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/bug.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
 
 #include <asm/mipsregs.h>
 #include <asm/mach-ralink/ralink_regs.h>
@@ -49,6 +51,8 @@
 /* does the board have sdram or ddram */
 static int dram_type;
 
+static struct ralink_soc_info *soc_info_ptr;
+
 static __init u32
 mt7620_calc_rate(u32 ref_rate, u32 mul, u32 div)
 {
@@ -410,6 +414,44 @@ static const char __init *mt7620_get_soc_name(struct ralink_soc_info *soc_info)
        }
 }
 
+static const char __init *mt7620_get_soc_id_name(void)
+{
+       if (ralink_soc == MT762X_SOC_MT7620A)
+               return "mt7620a";
+       else if (ralink_soc == MT762X_SOC_MT7620N)
+               return "mt7620n";
+       else if (ralink_soc == MT762X_SOC_MT7688)
+               return "mt7688";
+       else if (ralink_soc == MT762X_SOC_MT7628AN)
+               return "mt7628n";
+       else
+               return "invalid";
+}
+
+static int __init mt7620_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 = mt7620_get_soc_id_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(mt7620_soc_dev_init);
+
 void __init prom_soc_init(struct ralink_soc_info *soc_info)
 {
        const char *name = mt7620_get_soc_name(soc_info);
@@ -444,4 +486,6 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info)
                (pmu0 & PMU_SW_SET) ? ("sw") : ("hw"));
        pr_info("Digital PMU set to %s control\n",
                (pmu1 & DIG_SW_SEL) ? ("sw") : ("hw"));
+
+       soc_info_ptr = soc_info;
 }