aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-zynq/efuse.c
blob: d31a5822ec65df539fe36311c09c9c0c4aebb5de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Xilinx EFUSE driver
 *
 * Copyright (c) 2016 Xilinx Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/io.h>
#include <linux/of_address.h>
#include "common.h"

#define EFUSE_STATUS_OFFSET	0x10

/* 0 means cpu1 is working, 1 means cpu1 is broken */
#define EFUSE_STATUS_CPU_BIT	BIT(7)

void __iomem *zynq_efuse_base;

/**
 * zynq_efuse_cpu_state - Read/write cpu state
 * @cpu:	cpu number
 *
 * Return: true if cpu is running, false if cpu is broken
 */
bool zynq_efuse_cpu_state(int cpu)
{
	u32 state;

	if (!cpu)
		return true;

	state = readl(zynq_efuse_base + EFUSE_STATUS_OFFSET);
	state &= EFUSE_STATUS_CPU_BIT;

	if (!state)
		return true;

	return false;
}

/**
 * zynq_early_efuse_init - Early efuse init function
 *
 * Return:	0 on success, negative errno otherwise.
 *
 * Called very early during boot from platform code.
 */
int __init zynq_early_efuse_init(void)
{
	struct device_node *np;

	np = of_find_compatible_node(NULL, NULL, "xlnx,zynq-efuse");
	if (!np) {
		pr_err("%s: no efuse node found\n", __func__);
		BUG();
	}

	zynq_efuse_base = of_iomap(np, 0);
	if (!zynq_efuse_base) {
		pr_err("%s: Unable to map I/O memory\n", __func__);
		BUG();
	}

	np->data = (__force void *)zynq_efuse_base;

	pr_info("%s mapped to %p\n", np->name, zynq_efuse_base);

	of_node_put(np);

	return 0;
}