1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
280fb55a9SJohn Crispin /*
380fb55a9SJohn Crispin *
480fb55a9SJohn Crispin * Parts of this file are based on Ralink's 2.6.21 BSP
580fb55a9SJohn Crispin *
680fb55a9SJohn Crispin * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
780fb55a9SJohn Crispin * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
897b92108SJohn Crispin * Copyright (C) 2013 John Crispin <john@phrozen.org>
980fb55a9SJohn Crispin */
1080fb55a9SJohn Crispin
1180fb55a9SJohn Crispin #include <linux/kernel.h>
1280fb55a9SJohn Crispin #include <linux/init.h>
13*7a26b384SSergio Paracuellos #include <linux/slab.h>
14*7a26b384SSergio Paracuellos #include <linux/sys_soc.h>
1580fb55a9SJohn Crispin
1680fb55a9SJohn Crispin #include <asm/mipsregs.h>
1780fb55a9SJohn Crispin #include <asm/mach-ralink/ralink_regs.h>
1880fb55a9SJohn Crispin #include <asm/mach-ralink/rt288x.h>
1980fb55a9SJohn Crispin
2080fb55a9SJohn Crispin #include "common.h"
2180fb55a9SJohn Crispin
22*7a26b384SSergio Paracuellos static struct ralink_soc_info *soc_info_ptr;
23*7a26b384SSergio Paracuellos
rt2880_get_soc_name0(void)245a5aa151SSergio Paracuellos static unsigned int __init rt2880_get_soc_name0(void)
255a5aa151SSergio Paracuellos {
265a5aa151SSergio Paracuellos return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0);
275a5aa151SSergio Paracuellos }
285a5aa151SSergio Paracuellos
rt2880_get_soc_name1(void)295a5aa151SSergio Paracuellos static unsigned int __init rt2880_get_soc_name1(void)
305a5aa151SSergio Paracuellos {
315a5aa151SSergio Paracuellos return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME1);
325a5aa151SSergio Paracuellos }
335a5aa151SSergio Paracuellos
rt2880_soc_valid(void)345a5aa151SSergio Paracuellos static bool __init rt2880_soc_valid(void)
355a5aa151SSergio Paracuellos {
365a5aa151SSergio Paracuellos if (rt2880_get_soc_name0() == RT2880_CHIP_NAME0 &&
375a5aa151SSergio Paracuellos rt2880_get_soc_name1() == RT2880_CHIP_NAME1)
385a5aa151SSergio Paracuellos return true;
395a5aa151SSergio Paracuellos else
405a5aa151SSergio Paracuellos return false;
415a5aa151SSergio Paracuellos }
425a5aa151SSergio Paracuellos
rt2880_get_soc_name(void)435a5aa151SSergio Paracuellos static const char __init *rt2880_get_soc_name(void)
445a5aa151SSergio Paracuellos {
455a5aa151SSergio Paracuellos if (rt2880_soc_valid())
465a5aa151SSergio Paracuellos return "RT2880";
475a5aa151SSergio Paracuellos else
485a5aa151SSergio Paracuellos return "invalid";
495a5aa151SSergio Paracuellos }
505a5aa151SSergio Paracuellos
rt2880_get_soc_id(void)515a5aa151SSergio Paracuellos static unsigned int __init rt2880_get_soc_id(void)
525a5aa151SSergio Paracuellos {
535a5aa151SSergio Paracuellos return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_ID);
545a5aa151SSergio Paracuellos }
555a5aa151SSergio Paracuellos
rt2880_get_soc_ver(void)565a5aa151SSergio Paracuellos static unsigned int __init rt2880_get_soc_ver(void)
575a5aa151SSergio Paracuellos {
585a5aa151SSergio Paracuellos return (rt2880_get_soc_id() >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK;
595a5aa151SSergio Paracuellos }
605a5aa151SSergio Paracuellos
rt2880_get_soc_rev(void)615a5aa151SSergio Paracuellos static unsigned int __init rt2880_get_soc_rev(void)
625a5aa151SSergio Paracuellos {
635a5aa151SSergio Paracuellos return (rt2880_get_soc_id() & CHIP_ID_REV_MASK);
645a5aa151SSergio Paracuellos }
65*7a26b384SSergio Paracuellos
rt2880_soc_dev_init(void)66*7a26b384SSergio Paracuellos static int __init rt2880_soc_dev_init(void)
67*7a26b384SSergio Paracuellos {
68*7a26b384SSergio Paracuellos struct soc_device *soc_dev;
69*7a26b384SSergio Paracuellos struct soc_device_attribute *soc_dev_attr;
70*7a26b384SSergio Paracuellos
71*7a26b384SSergio Paracuellos soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
72*7a26b384SSergio Paracuellos if (!soc_dev_attr)
73*7a26b384SSergio Paracuellos return -ENOMEM;
74*7a26b384SSergio Paracuellos
75*7a26b384SSergio Paracuellos soc_dev_attr->family = "Ralink";
76*7a26b384SSergio Paracuellos soc_dev_attr->soc_id = rt2880_get_soc_name();
77*7a26b384SSergio Paracuellos
78*7a26b384SSergio Paracuellos soc_dev_attr->data = soc_info_ptr;
79*7a26b384SSergio Paracuellos
80*7a26b384SSergio Paracuellos soc_dev = soc_device_register(soc_dev_attr);
81*7a26b384SSergio Paracuellos if (IS_ERR(soc_dev)) {
82*7a26b384SSergio Paracuellos kfree(soc_dev_attr);
83*7a26b384SSergio Paracuellos return PTR_ERR(soc_dev);
84*7a26b384SSergio Paracuellos }
85*7a26b384SSergio Paracuellos
86*7a26b384SSergio Paracuellos return 0;
87*7a26b384SSergio Paracuellos }
88*7a26b384SSergio Paracuellos device_initcall(rt2880_soc_dev_init);
89*7a26b384SSergio Paracuellos
prom_soc_init(struct ralink_soc_info * soc_info)908eb6eb48SIlya Lipnitskiy void __init prom_soc_init(struct ralink_soc_info *soc_info)
9180fb55a9SJohn Crispin {
925a5aa151SSergio Paracuellos if (rt2880_soc_valid())
9380fb55a9SJohn Crispin soc_info->compatible = "ralink,r2880-soc";
945a5aa151SSergio Paracuellos else
955a5aa151SSergio Paracuellos panic("rt288x: unknown SoC, n0:%08x n1:%08x",
965a5aa151SSergio Paracuellos rt2880_get_soc_name0(), rt2880_get_soc_name1());
9780fb55a9SJohn Crispin
9880fb55a9SJohn Crispin snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
9980fb55a9SJohn Crispin "Ralink %s id:%u rev:%u",
1005a5aa151SSergio Paracuellos rt2880_get_soc_name(),
1015a5aa151SSergio Paracuellos rt2880_get_soc_ver(),
1025a5aa151SSergio Paracuellos rt2880_get_soc_rev());
10338d5b81cSJohn Crispin
10438d5b81cSJohn Crispin soc_info->mem_base = RT2880_SDRAM_BASE;
10538d5b81cSJohn Crispin soc_info->mem_size_min = RT2880_MEM_SIZE_MIN;
10638d5b81cSJohn Crispin soc_info->mem_size_max = RT2880_MEM_SIZE_MAX;
107f576fb6aSJohn Crispin
1080af3a40fSJohn Crispin ralink_soc = RT2880_SOC;
109*7a26b384SSergio Paracuellos soc_info_ptr = soc_info;
11080fb55a9SJohn Crispin }
111