xref: /openbmc/linux/arch/mips/ralink/rt288x.c (revision ffcdf473)
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 
22 static struct ralink_soc_info *soc_info_ptr;
23 
24 void __init ralink_of_remap(void)
25 {
26 	rt_sysc_membase = plat_of_remap_node("ralink,rt2880-sysc");
27 	rt_memc_membase = plat_of_remap_node("ralink,rt2880-memc");
28 
29 	if (!rt_sysc_membase || !rt_memc_membase)
30 		panic("Failed to remap core resources");
31 }
32 
33 static unsigned int __init rt2880_get_soc_name0(void)
34 {
35 	return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0);
36 }
37 
38 static unsigned int __init rt2880_get_soc_name1(void)
39 {
40 	return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1);
41 }
42 
43 static bool __init rt2880_soc_valid(void)
44 {
45 	if (rt2880_get_soc_name0() == RT2880_CHIP_NAME0 &&
46 	    rt2880_get_soc_name1() == RT2880_CHIP_NAME1)
47 		return true;
48 	else
49 		return false;
50 }
51 
52 static const char __init *rt2880_get_soc_name(void)
53 {
54 	if (rt2880_soc_valid())
55 		return "RT2880";
56 	else
57 		return "invalid";
58 }
59 
60 static unsigned int __init rt2880_get_soc_id(void)
61 {
62 	return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID);
63 }
64 
65 static unsigned int __init rt2880_get_soc_ver(void)
66 {
67 	return (rt2880_get_soc_id() >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK;
68 }
69 
70 static unsigned int __init rt2880_get_soc_rev(void)
71 {
72 	return (rt2880_get_soc_id() & CHIP_ID_REV_MASK);
73 }
74 
75 static int __init rt2880_soc_dev_init(void)
76 {
77 	struct soc_device *soc_dev;
78 	struct soc_device_attribute *soc_dev_attr;
79 
80 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
81 	if (!soc_dev_attr)
82 		return -ENOMEM;
83 
84 	soc_dev_attr->family = "Ralink";
85 	soc_dev_attr->soc_id = rt2880_get_soc_name();
86 
87 	soc_dev_attr->data = soc_info_ptr;
88 
89 	soc_dev = soc_device_register(soc_dev_attr);
90 	if (IS_ERR(soc_dev)) {
91 		kfree(soc_dev_attr);
92 		return PTR_ERR(soc_dev);
93 	}
94 
95 	return 0;
96 }
97 device_initcall(rt2880_soc_dev_init);
98 
99 void __init prom_soc_init(struct ralink_soc_info *soc_info)
100 {
101 	if (rt2880_soc_valid())
102 		soc_info->compatible = "ralink,r2880-soc";
103 	else
104 		panic("rt288x: unknown SoC, n0:%08x n1:%08x",
105 		      rt2880_get_soc_name0(), rt2880_get_soc_name1());
106 
107 	snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
108 		"Ralink %s id:%u rev:%u",
109 		rt2880_get_soc_name(),
110 		rt2880_get_soc_ver(),
111 		rt2880_get_soc_rev());
112 
113 	soc_info->mem_base = RT2880_SDRAM_BASE;
114 	soc_info->mem_size_min = RT2880_MEM_SIZE_MIN;
115 	soc_info->mem_size_max = RT2880_MEM_SIZE_MAX;
116 
117 	ralink_soc = RT2880_SOC;
118 	soc_info_ptr = soc_info;
119 }
120