aboutsummaryrefslogtreecommitdiff
path: root/arch/powerpc/platforms/wsp/scom_wsp.c
blob: 4052e2259f3016d904a707ff3e2524e1f2f58ac6 (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
76
77
/*
 *  SCOM backend for WSP
 *
 *  Copyright 2010 Benjamin Herrenschmidt, IBM Corp.
 *
 *  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/cpumask.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/spinlock.h>
#include <linux/types.h>

#include <asm/cputhreads.h>
#include <asm/reg_a2.h>
#include <asm/scom.h>
#include <asm/udbg.h>

#include "wsp.h"


static scom_map_t wsp_scom_map(struct device_node *dev, u64 reg, u64 count)
{
	struct resource r;
	u64 xscom_addr;

	if (!of_get_property(dev, "scom-controller", NULL)) {
		pr_err("%s: device %s is not a SCOM controller\n",
			__func__, dev->full_name);
		return SCOM_MAP_INVALID;
	}

	if (of_address_to_resource(dev, 0, &r)) {
		pr_debug("Failed to find SCOM controller address\n");
		return 0;
	}

	/* Transform the SCOM address into an XSCOM offset */
	xscom_addr = ((reg & 0x7f000000) >> 1) | ((reg & 0xfffff) << 3);

	return (scom_map_t)ioremap(r.start + xscom_addr, count << 3);
}

static void wsp_scom_unmap(scom_map_t map)
{
	iounmap((void *)map);
}

static u64 wsp_scom_read(scom_map_t map, u32 reg)
{
	u64 __iomem *addr = (u64 __iomem *)map;

	return in_be64(addr + reg);
}

static void wsp_scom_write(scom_map_t map, u32 reg, u64 value)
{
	u64 __iomem *addr = (u64 __iomem *)map;

	return out_be64(addr + reg, value);
}

static const struct scom_controller wsp_scom_controller = {
	.map	= wsp_scom_map,
	.unmap	= wsp_scom_unmap,
	.read	= wsp_scom_read,
	.write	= wsp_scom_write
};

void scom_init_wsp(void)
{
	scom_init(&wsp_scom_controller);
}