1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 *
4 * Parts of this file are based on Ralink's 2.6.21 BSP
5 *
6 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
7 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
8 * Copyright (C) 2013 John Crispin <john@phrozen.org>
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/slab.h>
14#include <linux/sys_soc.h>
15
16#include <asm/mipsregs.h>
17#include <asm/mach-ralink/ralink_regs.h>
18#include <asm/mach-ralink/rt288x.h>
19
20#include "common.h"
21
22static struct ralink_soc_info *soc_info_ptr;
23
24static unsigned int __init rt2880_get_soc_name0(void)
25{
26 return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0);
27}
28
29static unsigned int __init rt2880_get_soc_name1(void)
30{
31 return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1);
32}
33
34static bool __init rt2880_soc_valid(void)
35{
36 if (rt2880_get_soc_name0() == RT2880_CHIP_NAME0 &&
37 rt2880_get_soc_name1() == RT2880_CHIP_NAME1)
38 return true;
39 else
40 return false;
41}
42
43static const char __init *rt2880_get_soc_name(void)
44{
45 if (rt2880_soc_valid())
46 return "RT2880";
47 else
48 return "invalid";
49}
50
51static unsigned int __init rt2880_get_soc_id(void)
52{
53 return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID);
54}
55
56static unsigned int __init rt2880_get_soc_ver(void)
57{
58 return (rt2880_get_soc_id() >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK;
59}
60
61static unsigned int __init rt2880_get_soc_rev(void)
62{
63 return (rt2880_get_soc_id() & CHIP_ID_REV_MASK);
64}
65
66static int __init rt2880_soc_dev_init(void)
67{
68 struct soc_device *soc_dev;
69 struct soc_device_attribute *soc_dev_attr;
70
71 soc_dev_attr = kzalloc(size: sizeof(*soc_dev_attr), GFP_KERNEL);
72 if (!soc_dev_attr)
73 return -ENOMEM;
74
75 soc_dev_attr->family = "Ralink";
76 soc_dev_attr->soc_id = rt2880_get_soc_name();
77
78 soc_dev_attr->data = soc_info_ptr;
79
80 soc_dev = soc_device_register(soc_plat_dev_attr: soc_dev_attr);
81 if (IS_ERR(ptr: soc_dev)) {
82 kfree(objp: soc_dev_attr);
83 return PTR_ERR(ptr: soc_dev);
84 }
85
86 return 0;
87}
88device_initcall(rt2880_soc_dev_init);
89
90void __init prom_soc_init(struct ralink_soc_info *soc_info)
91{
92 if (rt2880_soc_valid())
93 soc_info->compatible = "ralink,r2880-soc";
94 else
95 panic(fmt: "rt288x: unknown SoC, n0:%08x n1:%08x",
96 rt2880_get_soc_name0(), rt2880_get_soc_name1());
97
98 snprintf(buf: soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
99 fmt: "Ralink %s id:%u rev:%u",
100 rt2880_get_soc_name(),
101 rt2880_get_soc_ver(),
102 rt2880_get_soc_rev());
103
104 soc_info->mem_base = RT2880_SDRAM_BASE;
105 soc_info->mem_size_min = RT2880_MEM_SIZE_MIN;
106 soc_info->mem_size_max = RT2880_MEM_SIZE_MAX;
107
108 ralink_soc = RT2880_SOC;
109 soc_info_ptr = soc_info;
110}
111

source code of linux/arch/mips/ralink/rt288x.c