18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * SMP support for R-Mobile / SH-Mobile - r8a7779 portion
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2011  Renesas Solutions Corp.
68c2ecf20Sopenharmony_ci * Copyright (C) 2011  Magnus Damm
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci#include <linux/kernel.h>
98c2ecf20Sopenharmony_ci#include <linux/init.h>
108c2ecf20Sopenharmony_ci#include <linux/smp.h>
118c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
128c2ecf20Sopenharmony_ci#include <linux/io.h>
138c2ecf20Sopenharmony_ci#include <linux/delay.h>
148c2ecf20Sopenharmony_ci#include <linux/soc/renesas/rcar-sysc.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <asm/cacheflush.h>
178c2ecf20Sopenharmony_ci#include <asm/smp_plat.h>
188c2ecf20Sopenharmony_ci#include <asm/smp_scu.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "common.h"
218c2ecf20Sopenharmony_ci#include "r8a7779.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define AVECR IOMEM(0xfe700040)
248c2ecf20Sopenharmony_ci#define R8A7779_SCU_BASE 0xf0000000
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic int r8a7779_boot_secondary(unsigned int cpu, struct task_struct *idle)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	int ret = -EIO;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	cpu = cpu_logical_map(cpu);
318c2ecf20Sopenharmony_ci	if (cpu)
328c2ecf20Sopenharmony_ci		ret = rcar_sysc_power_up_cpu(cpu);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	return ret;
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic void __init r8a7779_smp_prepare_cpus(unsigned int max_cpus)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	/* Map the reset vector (in headsmp-scu.S, headsmp.S) */
408c2ecf20Sopenharmony_ci	__raw_writel(__pa(shmobile_boot_vector), AVECR);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	/* setup r8a7779 specific SCU bits */
438c2ecf20Sopenharmony_ci	shmobile_smp_scu_prepare_cpus(R8A7779_SCU_BASE, max_cpus);
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#ifdef CONFIG_HOTPLUG_CPU
478c2ecf20Sopenharmony_cistatic int r8a7779_platform_cpu_kill(unsigned int cpu)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	int ret = -EIO;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	cpu = cpu_logical_map(cpu);
528c2ecf20Sopenharmony_ci	if (cpu)
538c2ecf20Sopenharmony_ci		ret = rcar_sysc_power_down_cpu(cpu);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	return ret ? ret : 1;
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic int r8a7779_cpu_kill(unsigned int cpu)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	if (shmobile_smp_scu_cpu_kill(cpu))
618c2ecf20Sopenharmony_ci		return r8a7779_platform_cpu_kill(cpu);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	return 0;
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_ci#endif /* CONFIG_HOTPLUG_CPU */
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciconst struct smp_operations r8a7779_smp_ops  __initconst = {
688c2ecf20Sopenharmony_ci	.smp_prepare_cpus	= r8a7779_smp_prepare_cpus,
698c2ecf20Sopenharmony_ci	.smp_boot_secondary	= r8a7779_boot_secondary,
708c2ecf20Sopenharmony_ci#ifdef CONFIG_HOTPLUG_CPU
718c2ecf20Sopenharmony_ci	.cpu_die		= shmobile_smp_scu_cpu_die,
728c2ecf20Sopenharmony_ci	.cpu_kill		= r8a7779_cpu_kill,
738c2ecf20Sopenharmony_ci#endif
748c2ecf20Sopenharmony_ci};
75