18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Parts of this file are based on Ralink's 2.6.21 BSP
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
78c2ecf20Sopenharmony_ci * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
88c2ecf20Sopenharmony_ci * Copyright (C) 2013 John Crispin <john@phrozen.org>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/kernel.h>
128c2ecf20Sopenharmony_ci#include <linux/init.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <asm/mipsregs.h>
158c2ecf20Sopenharmony_ci#include <asm/mach-ralink/ralink_regs.h>
168c2ecf20Sopenharmony_ci#include <asm/mach-ralink/rt288x.h>
178c2ecf20Sopenharmony_ci#include <asm/mach-ralink/pinmux.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "common.h"
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic struct rt2880_pmx_func i2c_func[] = { FUNC("i2c", 0, 1, 2) };
228c2ecf20Sopenharmony_cistatic struct rt2880_pmx_func spi_func[] = { FUNC("spi", 0, 3, 4) };
238c2ecf20Sopenharmony_cistatic struct rt2880_pmx_func uartlite_func[] = { FUNC("uartlite", 0, 7, 8) };
248c2ecf20Sopenharmony_cistatic struct rt2880_pmx_func jtag_func[] = { FUNC("jtag", 0, 17, 5) };
258c2ecf20Sopenharmony_cistatic struct rt2880_pmx_func mdio_func[] = { FUNC("mdio", 0, 22, 2) };
268c2ecf20Sopenharmony_cistatic struct rt2880_pmx_func sdram_func[] = { FUNC("sdram", 0, 24, 16) };
278c2ecf20Sopenharmony_cistatic struct rt2880_pmx_func pci_func[] = { FUNC("pci", 0, 40, 32) };
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic struct rt2880_pmx_group rt2880_pinmux_data_act[] = {
308c2ecf20Sopenharmony_ci	GRP("i2c", i2c_func, 1, RT2880_GPIO_MODE_I2C),
318c2ecf20Sopenharmony_ci	GRP("spi", spi_func, 1, RT2880_GPIO_MODE_SPI),
328c2ecf20Sopenharmony_ci	GRP("uartlite", uartlite_func, 1, RT2880_GPIO_MODE_UART0),
338c2ecf20Sopenharmony_ci	GRP("jtag", jtag_func, 1, RT2880_GPIO_MODE_JTAG),
348c2ecf20Sopenharmony_ci	GRP("mdio", mdio_func, 1, RT2880_GPIO_MODE_MDIO),
358c2ecf20Sopenharmony_ci	GRP("sdram", sdram_func, 1, RT2880_GPIO_MODE_SDRAM),
368c2ecf20Sopenharmony_ci	GRP("pci", pci_func, 1, RT2880_GPIO_MODE_PCI),
378c2ecf20Sopenharmony_ci	{ 0 }
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_civoid __init ralink_clk_init(void)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci	unsigned long cpu_rate, wmac_rate = 40000000;
438c2ecf20Sopenharmony_ci	u32 t = rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG);
448c2ecf20Sopenharmony_ci	t = ((t >> SYSTEM_CONFIG_CPUCLK_SHIFT) & SYSTEM_CONFIG_CPUCLK_MASK);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	switch (t) {
478c2ecf20Sopenharmony_ci	case SYSTEM_CONFIG_CPUCLK_250:
488c2ecf20Sopenharmony_ci		cpu_rate = 250000000;
498c2ecf20Sopenharmony_ci		break;
508c2ecf20Sopenharmony_ci	case SYSTEM_CONFIG_CPUCLK_266:
518c2ecf20Sopenharmony_ci		cpu_rate = 266666667;
528c2ecf20Sopenharmony_ci		break;
538c2ecf20Sopenharmony_ci	case SYSTEM_CONFIG_CPUCLK_280:
548c2ecf20Sopenharmony_ci		cpu_rate = 280000000;
558c2ecf20Sopenharmony_ci		break;
568c2ecf20Sopenharmony_ci	case SYSTEM_CONFIG_CPUCLK_300:
578c2ecf20Sopenharmony_ci		cpu_rate = 300000000;
588c2ecf20Sopenharmony_ci		break;
598c2ecf20Sopenharmony_ci	}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	ralink_clk_add("cpu", cpu_rate);
628c2ecf20Sopenharmony_ci	ralink_clk_add("300100.timer", cpu_rate / 2);
638c2ecf20Sopenharmony_ci	ralink_clk_add("300120.watchdog", cpu_rate / 2);
648c2ecf20Sopenharmony_ci	ralink_clk_add("300500.uart", cpu_rate / 2);
658c2ecf20Sopenharmony_ci	ralink_clk_add("300900.i2c", cpu_rate / 2);
668c2ecf20Sopenharmony_ci	ralink_clk_add("300c00.uartlite", cpu_rate / 2);
678c2ecf20Sopenharmony_ci	ralink_clk_add("400000.ethernet", cpu_rate / 2);
688c2ecf20Sopenharmony_ci	ralink_clk_add("480000.wmac", wmac_rate);
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_civoid __init ralink_of_remap(void)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	rt_sysc_membase = plat_of_remap_node("ralink,rt2880-sysc");
748c2ecf20Sopenharmony_ci	rt_memc_membase = plat_of_remap_node("ralink,rt2880-memc");
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	if (!rt_sysc_membase || !rt_memc_membase)
778c2ecf20Sopenharmony_ci		panic("Failed to remap core resources");
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_civoid prom_soc_init(struct ralink_soc_info *soc_info)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT2880_SYSC_BASE);
838c2ecf20Sopenharmony_ci	const char *name;
848c2ecf20Sopenharmony_ci	u32 n0;
858c2ecf20Sopenharmony_ci	u32 n1;
868c2ecf20Sopenharmony_ci	u32 id;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
898c2ecf20Sopenharmony_ci	n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
908c2ecf20Sopenharmony_ci	id = __raw_readl(sysc + SYSC_REG_CHIP_ID);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	if (n0 == RT2880_CHIP_NAME0 && n1 == RT2880_CHIP_NAME1) {
938c2ecf20Sopenharmony_ci		soc_info->compatible = "ralink,r2880-soc";
948c2ecf20Sopenharmony_ci		name = "RT2880";
958c2ecf20Sopenharmony_ci	} else {
968c2ecf20Sopenharmony_ci		panic("rt288x: unknown SoC, n0:%08x n1:%08x", n0, n1);
978c2ecf20Sopenharmony_ci	}
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
1008c2ecf20Sopenharmony_ci		"Ralink %s id:%u rev:%u",
1018c2ecf20Sopenharmony_ci		name,
1028c2ecf20Sopenharmony_ci		(id >> CHIP_ID_ID_SHIFT) & CHIP_ID_ID_MASK,
1038c2ecf20Sopenharmony_ci		(id & CHIP_ID_REV_MASK));
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	soc_info->mem_base = RT2880_SDRAM_BASE;
1068c2ecf20Sopenharmony_ci	soc_info->mem_size_min = RT2880_MEM_SIZE_MIN;
1078c2ecf20Sopenharmony_ci	soc_info->mem_size_max = RT2880_MEM_SIZE_MAX;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	rt2880_pinmux_data = rt2880_pinmux_data_act;
1108c2ecf20Sopenharmony_ci	ralink_soc = RT2880_SOC;
1118c2ecf20Sopenharmony_ci}
112