2019-05-27 14:55:00 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2013-03-27 19:37:53 +08:00
|
|
|
/*
|
|
|
|
* Xilinx SLCR driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2013 Xilinx Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
2015-03-19 22:24:38 +08:00
|
|
|
#include <linux/reboot.h>
|
2013-11-26 22:41:31 +08:00
|
|
|
#include <linux/mfd/syscon.h>
|
2013-03-27 19:37:53 +08:00
|
|
|
#include <linux/of_address.h>
|
2013-11-26 22:41:31 +08:00
|
|
|
#include <linux/regmap.h>
|
2013-03-27 19:37:53 +08:00
|
|
|
#include <linux/clk/zynq.h>
|
|
|
|
#include "common.h"
|
|
|
|
|
2013-07-18 01:10:14 +08:00
|
|
|
/* register offsets */
|
|
|
|
#define SLCR_UNLOCK_OFFSET 0x8 /* SCLR unlock register */
|
2013-03-20 18:42:15 +08:00
|
|
|
#define SLCR_PS_RST_CTRL_OFFSET 0x200 /* PS Software Reset Control */
|
2013-07-18 01:10:14 +08:00
|
|
|
#define SLCR_A9_CPU_RST_CTRL_OFFSET 0x244 /* CPU Software Reset Control */
|
|
|
|
#define SLCR_REBOOT_STATUS_OFFSET 0x258 /* PS Reboot Status */
|
2013-07-31 15:19:59 +08:00
|
|
|
#define SLCR_PSS_IDCODE 0x530 /* PS IDCODE */
|
2016-02-03 10:30:49 +08:00
|
|
|
#define SLCR_L2C_RAM 0xA1C /* L2C_RAM in AR#54190 */
|
2013-03-20 20:50:12 +08:00
|
|
|
|
2013-07-18 01:10:14 +08:00
|
|
|
#define SLCR_UNLOCK_MAGIC 0xDF0D
|
2013-03-20 20:50:12 +08:00
|
|
|
#define SLCR_A9_CPU_CLKSTOP 0x10
|
|
|
|
#define SLCR_A9_CPU_RST 0x1
|
2013-07-31 15:19:59 +08:00
|
|
|
#define SLCR_PSS_IDCODE_DEVICE_SHIFT 12
|
|
|
|
#define SLCR_PSS_IDCODE_DEVICE_MASK 0x1F
|
2013-03-20 20:50:12 +08:00
|
|
|
|
2013-06-29 15:20:17 +08:00
|
|
|
static void __iomem *zynq_slcr_base;
|
2013-11-26 22:41:31 +08:00
|
|
|
static struct regmap *zynq_slcr_regmap;
|
2013-03-27 19:37:53 +08:00
|
|
|
|
2014-01-06 21:52:02 +08:00
|
|
|
/**
|
|
|
|
* zynq_slcr_write - Write to a register in SLCR block
|
|
|
|
*
|
|
|
|
* @val: Value to write to the register
|
|
|
|
* @offset: Register offset in SLCR block
|
|
|
|
*
|
|
|
|
* Return: a negative value on error, 0 on success
|
|
|
|
*/
|
|
|
|
static int zynq_slcr_write(u32 val, u32 offset)
|
|
|
|
{
|
|
|
|
return regmap_write(zynq_slcr_regmap, offset, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* zynq_slcr_read - Read a register in SLCR block
|
|
|
|
*
|
|
|
|
* @val: Pointer to value to be read from SLCR
|
|
|
|
* @offset: Register offset in SLCR block
|
|
|
|
*
|
|
|
|
* Return: a negative value on error, 0 on success
|
|
|
|
*/
|
|
|
|
static int zynq_slcr_read(u32 *val, u32 offset)
|
|
|
|
{
|
2014-12-11 18:31:30 +08:00
|
|
|
return regmap_read(zynq_slcr_regmap, offset, val);
|
2014-01-06 21:52:02 +08:00
|
|
|
}
|
|
|
|
|
2013-11-26 21:46:58 +08:00
|
|
|
/**
|
|
|
|
* zynq_slcr_unlock - Unlock SLCR registers
|
|
|
|
*
|
|
|
|
* Return: a negative value on error, 0 on success
|
|
|
|
*/
|
|
|
|
static inline int zynq_slcr_unlock(void)
|
|
|
|
{
|
|
|
|
zynq_slcr_write(SLCR_UNLOCK_MAGIC, SLCR_UNLOCK_OFFSET);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-31 15:19:59 +08:00
|
|
|
/**
|
|
|
|
* zynq_slcr_get_device_id - Read device code id
|
|
|
|
*
|
|
|
|
* Return: Device code id
|
|
|
|
*/
|
|
|
|
u32 zynq_slcr_get_device_id(void)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
zynq_slcr_read(&val, SLCR_PSS_IDCODE);
|
|
|
|
val >>= SLCR_PSS_IDCODE_DEVICE_SHIFT;
|
|
|
|
val &= SLCR_PSS_IDCODE_DEVICE_MASK;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-03-20 18:42:15 +08:00
|
|
|
/**
|
2015-03-19 22:24:38 +08:00
|
|
|
* zynq_slcr_system_restart - Restart the entire system.
|
|
|
|
*
|
|
|
|
* @nb: Pointer to restart notifier block (unused)
|
|
|
|
* @action: Reboot mode (unused)
|
|
|
|
* @data: Restart handler private data (unused)
|
|
|
|
*
|
|
|
|
* Return: 0 always
|
2013-03-20 18:42:15 +08:00
|
|
|
*/
|
2015-03-19 22:24:38 +08:00
|
|
|
static
|
|
|
|
int zynq_slcr_system_restart(struct notifier_block *nb,
|
|
|
|
unsigned long action, void *data)
|
2013-03-20 18:42:15 +08:00
|
|
|
{
|
|
|
|
u32 reboot;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear 0x0F000000 bits of reboot status register to workaround
|
|
|
|
* the FSBL not loading the bitstream after soft-reboot
|
|
|
|
* This is a temporary solution until we know more.
|
|
|
|
*/
|
2014-01-06 21:52:02 +08:00
|
|
|
zynq_slcr_read(&reboot, SLCR_REBOOT_STATUS_OFFSET);
|
|
|
|
zynq_slcr_write(reboot & 0xF0FFFFFF, SLCR_REBOOT_STATUS_OFFSET);
|
|
|
|
zynq_slcr_write(1, SLCR_PS_RST_CTRL_OFFSET);
|
2015-03-19 22:24:38 +08:00
|
|
|
return 0;
|
2013-03-20 18:42:15 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 22:24:38 +08:00
|
|
|
static struct notifier_block zynq_slcr_restart_nb = {
|
|
|
|
.notifier_call = zynq_slcr_system_restart,
|
|
|
|
.priority = 192,
|
|
|
|
};
|
|
|
|
|
2013-03-20 20:50:12 +08:00
|
|
|
/**
|
|
|
|
* zynq_slcr_cpu_start - Start cpu
|
|
|
|
* @cpu: cpu number
|
|
|
|
*/
|
|
|
|
void zynq_slcr_cpu_start(int cpu)
|
|
|
|
{
|
2014-01-06 21:52:02 +08:00
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
zynq_slcr_read(®, SLCR_A9_CPU_RST_CTRL_OFFSET);
|
2013-07-18 01:10:15 +08:00
|
|
|
reg &= ~(SLCR_A9_CPU_RST << cpu);
|
2014-01-06 21:52:02 +08:00
|
|
|
zynq_slcr_write(reg, SLCR_A9_CPU_RST_CTRL_OFFSET);
|
2013-07-18 01:10:15 +08:00
|
|
|
reg &= ~(SLCR_A9_CPU_CLKSTOP << cpu);
|
2014-01-06 21:52:02 +08:00
|
|
|
zynq_slcr_write(reg, SLCR_A9_CPU_RST_CTRL_OFFSET);
|
2014-09-03 05:19:12 +08:00
|
|
|
|
|
|
|
zynq_slcr_cpu_state_write(cpu, false);
|
2013-03-20 20:50:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* zynq_slcr_cpu_stop - Stop cpu
|
|
|
|
* @cpu: cpu number
|
|
|
|
*/
|
|
|
|
void zynq_slcr_cpu_stop(int cpu)
|
|
|
|
{
|
2014-01-06 21:52:02 +08:00
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
zynq_slcr_read(®, SLCR_A9_CPU_RST_CTRL_OFFSET);
|
2013-07-18 01:10:15 +08:00
|
|
|
reg |= (SLCR_A9_CPU_CLKSTOP | SLCR_A9_CPU_RST) << cpu;
|
2014-01-06 21:52:02 +08:00
|
|
|
zynq_slcr_write(reg, SLCR_A9_CPU_RST_CTRL_OFFSET);
|
2013-03-20 20:50:12 +08:00
|
|
|
}
|
|
|
|
|
2013-03-27 19:37:53 +08:00
|
|
|
/**
|
2014-09-03 05:19:12 +08:00
|
|
|
* zynq_slcr_cpu_state - Read/write cpu state
|
|
|
|
* @cpu: cpu number
|
2013-11-26 22:41:31 +08:00
|
|
|
*
|
2014-09-03 05:19:12 +08:00
|
|
|
* SLCR_REBOOT_STATUS save upper 2 bits (31/30 cpu states for cpu0 and cpu1)
|
|
|
|
* 0 means cpu is running, 1 cpu is going to die.
|
|
|
|
*
|
|
|
|
* Return: true if cpu is running, false if cpu is going to die
|
|
|
|
*/
|
|
|
|
bool zynq_slcr_cpu_state_read(int cpu)
|
|
|
|
{
|
|
|
|
u32 state;
|
|
|
|
|
|
|
|
state = readl(zynq_slcr_base + SLCR_REBOOT_STATUS_OFFSET);
|
|
|
|
state &= 1 << (31 - cpu);
|
|
|
|
|
|
|
|
return !state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* zynq_slcr_cpu_state - Read/write cpu state
|
|
|
|
* @cpu: cpu number
|
|
|
|
* @die: cpu state - true if cpu is going to die
|
|
|
|
*
|
|
|
|
* SLCR_REBOOT_STATUS save upper 2 bits (31/30 cpu states for cpu0 and cpu1)
|
|
|
|
* 0 means cpu is running, 1 cpu is going to die.
|
|
|
|
*/
|
|
|
|
void zynq_slcr_cpu_state_write(int cpu, bool die)
|
|
|
|
{
|
|
|
|
u32 state, mask;
|
|
|
|
|
|
|
|
state = readl(zynq_slcr_base + SLCR_REBOOT_STATUS_OFFSET);
|
|
|
|
mask = 1 << (31 - cpu);
|
|
|
|
if (die)
|
|
|
|
state |= mask;
|
|
|
|
else
|
|
|
|
state &= ~mask;
|
|
|
|
writel(state, zynq_slcr_base + SLCR_REBOOT_STATUS_OFFSET);
|
|
|
|
}
|
|
|
|
|
2013-11-26 22:41:31 +08:00
|
|
|
/**
|
|
|
|
* zynq_early_slcr_init - Early slcr init function
|
|
|
|
*
|
|
|
|
* Return: 0 on success, negative errno otherwise.
|
|
|
|
*
|
|
|
|
* Called very early during boot from platform code to unlock SLCR.
|
|
|
|
*/
|
|
|
|
int __init zynq_early_slcr_init(void)
|
2013-03-27 19:37:53 +08:00
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "xlnx,zynq-slcr");
|
|
|
|
if (!np) {
|
|
|
|
pr_err("%s: no slcr node found\n", __func__);
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
zynq_slcr_base = of_iomap(np, 0);
|
|
|
|
if (!zynq_slcr_base) {
|
|
|
|
pr_err("%s: Unable to map I/O memory\n", __func__);
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2013-11-26 21:02:44 +08:00
|
|
|
np->data = (__force void *)zynq_slcr_base;
|
|
|
|
|
2014-12-11 18:31:30 +08:00
|
|
|
zynq_slcr_regmap = syscon_regmap_lookup_by_compatible("xlnx,zynq-slcr");
|
|
|
|
if (IS_ERR(zynq_slcr_regmap)) {
|
|
|
|
pr_err("%s: failed to find zynq-slcr\n", __func__);
|
2024-06-12 13:13:20 +08:00
|
|
|
of_node_put(np);
|
2014-12-11 18:31:30 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2013-03-27 19:37:53 +08:00
|
|
|
/* unlock the SLCR so that registers can be changed */
|
2013-11-26 21:46:58 +08:00
|
|
|
zynq_slcr_unlock();
|
2013-03-27 19:37:53 +08:00
|
|
|
|
2016-02-03 10:30:49 +08:00
|
|
|
/* See AR#54190 design advisory */
|
|
|
|
regmap_update_bits(zynq_slcr_regmap, SLCR_L2C_RAM, 0x70707, 0x20202);
|
|
|
|
|
2015-03-19 22:24:38 +08:00
|
|
|
register_restart_handler(&zynq_slcr_restart_nb);
|
|
|
|
|
2018-08-28 09:52:04 +08:00
|
|
|
pr_info("%pOFn mapped to %p\n", np, zynq_slcr_base);
|
2013-03-27 19:37:53 +08:00
|
|
|
|
|
|
|
of_node_put(np);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|