xref: /openbmc/linux/arch/mips/ralink/rt3883.c (revision fd99ac50)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2293840b9SJohn Crispin /*
3293840b9SJohn Crispin  *
4293840b9SJohn Crispin  * Parts of this file are based on Ralink's 2.6.21 BSP
5293840b9SJohn Crispin  *
6293840b9SJohn Crispin  * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7293840b9SJohn Crispin  * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
897b92108SJohn Crispin  * Copyright (C) 2013 John Crispin <john@phrozen.org>
9293840b9SJohn Crispin  */
10293840b9SJohn Crispin 
11293840b9SJohn Crispin #include <linux/kernel.h>
12293840b9SJohn Crispin #include <linux/init.h>
13*2165248fSSergio Paracuellos #include <linux/slab.h>
14*2165248fSSergio Paracuellos #include <linux/sys_soc.h>
15293840b9SJohn Crispin 
16293840b9SJohn Crispin #include <asm/mipsregs.h>
17293840b9SJohn Crispin #include <asm/mach-ralink/ralink_regs.h>
18293840b9SJohn Crispin #include <asm/mach-ralink/rt3883.h>
19293840b9SJohn Crispin 
20293840b9SJohn Crispin #include "common.h"
21293840b9SJohn Crispin 
22*2165248fSSergio Paracuellos static struct ralink_soc_info *soc_info_ptr;
23*2165248fSSergio Paracuellos 
rt3883_get_soc_name0(void)2489f9b304SSergio Paracuellos static unsigned int __init rt3883_get_soc_name0(void)
2589f9b304SSergio Paracuellos {
2689f9b304SSergio Paracuellos 	return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID0_3);
2789f9b304SSergio Paracuellos }
2889f9b304SSergio Paracuellos 
rt3883_get_soc_name1(void)2989f9b304SSergio Paracuellos static unsigned int __init rt3883_get_soc_name1(void)
3089f9b304SSergio Paracuellos {
3189f9b304SSergio Paracuellos 	return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID4_7);
3289f9b304SSergio Paracuellos }
3389f9b304SSergio Paracuellos 
rt3883_soc_valid(void)3489f9b304SSergio Paracuellos static bool __init rt3883_soc_valid(void)
3589f9b304SSergio Paracuellos {
3689f9b304SSergio Paracuellos 	if (rt3883_get_soc_name0() == RT3883_CHIP_NAME0 &&
3789f9b304SSergio Paracuellos 	    rt3883_get_soc_name1() == RT3883_CHIP_NAME1)
3889f9b304SSergio Paracuellos 		return true;
3989f9b304SSergio Paracuellos 	else
4089f9b304SSergio Paracuellos 		return false;
4189f9b304SSergio Paracuellos }
4289f9b304SSergio Paracuellos 
rt3883_get_soc_name(void)4389f9b304SSergio Paracuellos static const char __init *rt3883_get_soc_name(void)
4489f9b304SSergio Paracuellos {
4589f9b304SSergio Paracuellos 	if (rt3883_soc_valid())
4689f9b304SSergio Paracuellos 		return "RT3883";
4789f9b304SSergio Paracuellos 	else
4889f9b304SSergio Paracuellos 		return "invalid";
4989f9b304SSergio Paracuellos }
5089f9b304SSergio Paracuellos 
rt3883_get_soc_id(void)5189f9b304SSergio Paracuellos static unsigned int __init rt3883_get_soc_id(void)
5289f9b304SSergio Paracuellos {
5389f9b304SSergio Paracuellos 	return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_REVID);
5489f9b304SSergio Paracuellos }
5589f9b304SSergio Paracuellos 
rt3883_get_soc_ver(void)5689f9b304SSergio Paracuellos static unsigned int __init rt3883_get_soc_ver(void)
5789f9b304SSergio Paracuellos {
5889f9b304SSergio Paracuellos 	return (rt3883_get_soc_id() >> RT3883_REVID_VER_ID_SHIFT) & RT3883_REVID_VER_ID_MASK;
5989f9b304SSergio Paracuellos }
6089f9b304SSergio Paracuellos 
rt3883_get_soc_rev(void)6189f9b304SSergio Paracuellos static unsigned int __init rt3883_get_soc_rev(void)
6289f9b304SSergio Paracuellos {
6389f9b304SSergio Paracuellos 	return (rt3883_get_soc_id() & RT3883_REVID_ECO_ID_MASK);
6489f9b304SSergio Paracuellos }
6589f9b304SSergio Paracuellos 
rt3883_soc_dev_init(void)66*2165248fSSergio Paracuellos static int __init rt3883_soc_dev_init(void)
67*2165248fSSergio Paracuellos {
68*2165248fSSergio Paracuellos 	struct soc_device *soc_dev;
69*2165248fSSergio Paracuellos 	struct soc_device_attribute *soc_dev_attr;
70*2165248fSSergio Paracuellos 
71*2165248fSSergio Paracuellos 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
72*2165248fSSergio Paracuellos 	if (!soc_dev_attr)
73*2165248fSSergio Paracuellos 		return -ENOMEM;
74*2165248fSSergio Paracuellos 
75*2165248fSSergio Paracuellos 	soc_dev_attr->family = "Ralink";
76*2165248fSSergio Paracuellos 	soc_dev_attr->soc_id = rt3883_get_soc_name();
77*2165248fSSergio Paracuellos 
78*2165248fSSergio Paracuellos 	soc_dev_attr->data = soc_info_ptr;
79*2165248fSSergio Paracuellos 
80*2165248fSSergio Paracuellos 	soc_dev = soc_device_register(soc_dev_attr);
81*2165248fSSergio Paracuellos 	if (IS_ERR(soc_dev)) {
82*2165248fSSergio Paracuellos 		kfree(soc_dev_attr);
83*2165248fSSergio Paracuellos 		return PTR_ERR(soc_dev);
84*2165248fSSergio Paracuellos 	}
85*2165248fSSergio Paracuellos 
86*2165248fSSergio Paracuellos 	return 0;
87*2165248fSSergio Paracuellos }
88*2165248fSSergio Paracuellos device_initcall(rt3883_soc_dev_init);
89*2165248fSSergio Paracuellos 
prom_soc_init(struct ralink_soc_info * soc_info)908eb6eb48SIlya Lipnitskiy void __init prom_soc_init(struct ralink_soc_info *soc_info)
91293840b9SJohn Crispin {
9289f9b304SSergio Paracuellos 	if (rt3883_soc_valid())
93293840b9SJohn Crispin 		soc_info->compatible = "ralink,rt3883-soc";
9489f9b304SSergio Paracuellos 	else
9589f9b304SSergio Paracuellos 		panic("rt3883: unknown SoC, n0:%08x n1:%08x",
9689f9b304SSergio Paracuellos 		      rt3883_get_soc_name0(), rt3883_get_soc_name1());
97293840b9SJohn Crispin 
98293840b9SJohn Crispin 	snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
99293840b9SJohn Crispin 		"Ralink %s ver:%u eco:%u",
10089f9b304SSergio Paracuellos 		rt3883_get_soc_name(),
10189f9b304SSergio Paracuellos 		rt3883_get_soc_ver(),
10289f9b304SSergio Paracuellos 		rt3883_get_soc_rev());
103fe98f612SJohn Crispin 
104fe98f612SJohn Crispin 	soc_info->mem_base = RT3883_SDRAM_BASE;
105fe98f612SJohn Crispin 	soc_info->mem_size_min = RT3883_MEM_SIZE_MIN;
106fe98f612SJohn Crispin 	soc_info->mem_size_max = RT3883_MEM_SIZE_MAX;
107f576fb6aSJohn Crispin 
10808d90c81SColin Ian King 	ralink_soc = RT3883_SOC;
109*2165248fSSergio Paracuellos 	soc_info_ptr = soc_info;
110293840b9SJohn Crispin }
111