Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
293840b9 | 2 | /* |
293840b9 JC |
3 | * |
4 | * Parts of this file are based on Ralink's 2.6.21 BSP | |
5 | * | |
6 | * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> | |
7 | * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org> | |
97b92108 | 8 | * Copyright (C) 2013 John Crispin <john@phrozen.org> |
293840b9 JC |
9 | */ |
10 | ||
11 | #include <linux/kernel.h> | |
12 | #include <linux/init.h> | |
2165248f SP |
13 | #include <linux/slab.h> |
14 | #include <linux/sys_soc.h> | |
293840b9 JC |
15 | |
16 | #include <asm/mipsregs.h> | |
17 | #include <asm/mach-ralink/ralink_regs.h> | |
18 | #include <asm/mach-ralink/rt3883.h> | |
19 | ||
20 | #include "common.h" | |
21 | ||
2165248f SP |
22 | static struct ralink_soc_info *soc_info_ptr; |
23 | ||
89f9b304 SP |
24 | static unsigned int __init rt3883_get_soc_name0(void) |
25 | { | |
26 | return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID0_3); | |
27 | } | |
28 | ||
29 | static unsigned int __init rt3883_get_soc_name1(void) | |
30 | { | |
31 | return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID4_7); | |
32 | } | |
33 | ||
34 | static bool __init rt3883_soc_valid(void) | |
35 | { | |
36 | if (rt3883_get_soc_name0() == RT3883_CHIP_NAME0 && | |
37 | rt3883_get_soc_name1() == RT3883_CHIP_NAME1) | |
38 | return true; | |
39 | else | |
40 | return false; | |
41 | } | |
42 | ||
43 | static const char __init *rt3883_get_soc_name(void) | |
44 | { | |
45 | if (rt3883_soc_valid()) | |
46 | return "RT3883"; | |
47 | else | |
48 | return "invalid"; | |
49 | } | |
50 | ||
51 | static unsigned int __init rt3883_get_soc_id(void) | |
293840b9 | 52 | { |
89f9b304 SP |
53 | return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_REVID); |
54 | } | |
293840b9 | 55 | |
89f9b304 SP |
56 | static unsigned int __init rt3883_get_soc_ver(void) |
57 | { | |
58 | return (rt3883_get_soc_id() >> RT3883_REVID_VER_ID_SHIFT) & RT3883_REVID_VER_ID_MASK; | |
59 | } | |
293840b9 | 60 | |
89f9b304 SP |
61 | static unsigned int __init rt3883_get_soc_rev(void) |
62 | { | |
63 | return (rt3883_get_soc_id() & RT3883_REVID_ECO_ID_MASK); | |
64 | } | |
65 | ||
2165248f SP |
66 | static int __init rt3883_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(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 = rt3883_get_soc_name(); | |
77 | ||
78 | soc_dev_attr->data = soc_info_ptr; | |
79 | ||
80 | soc_dev = soc_device_register(soc_dev_attr); | |
81 | if (IS_ERR(soc_dev)) { | |
82 | kfree(soc_dev_attr); | |
83 | return PTR_ERR(soc_dev); | |
84 | } | |
85 | ||
86 | return 0; | |
87 | } | |
88 | device_initcall(rt3883_soc_dev_init); | |
89 | ||
89f9b304 SP |
90 | void __init prom_soc_init(struct ralink_soc_info *soc_info) |
91 | { | |
92 | if (rt3883_soc_valid()) | |
293840b9 | 93 | soc_info->compatible = "ralink,rt3883-soc"; |
89f9b304 SP |
94 | else |
95 | panic("rt3883: unknown SoC, n0:%08x n1:%08x", | |
96 | rt3883_get_soc_name0(), rt3883_get_soc_name1()); | |
293840b9 JC |
97 | |
98 | snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN, | |
99 | "Ralink %s ver:%u eco:%u", | |
89f9b304 SP |
100 | rt3883_get_soc_name(), |
101 | rt3883_get_soc_ver(), | |
102 | rt3883_get_soc_rev()); | |
fe98f612 JC |
103 | |
104 | soc_info->mem_base = RT3883_SDRAM_BASE; | |
105 | soc_info->mem_size_min = RT3883_MEM_SIZE_MIN; | |
106 | soc_info->mem_size_max = RT3883_MEM_SIZE_MAX; | |
f576fb6a | 107 | |
08d90c81 | 108 | ralink_soc = RT3883_SOC; |
2165248f | 109 | soc_info_ptr = soc_info; |
293840b9 | 110 | } |