Merge branch 'clockevents/fixes' of git://git.linaro.org/people/daniel.lezcano/linux...
[linux-drm-fsl-dcu.git] / arch / powerpc / platforms / wsp / scom_wsp.c
1 /*
2  *  SCOM backend for WSP
3  *
4  *  Copyright 2010 Benjamin Herrenschmidt, IBM Corp.
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  as published by the Free Software Foundation; either version
9  *  2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/cpumask.h>
13 #include <linux/io.h>
14 #include <linux/of.h>
15 #include <linux/spinlock.h>
16 #include <linux/types.h>
17 #include <linux/of_address.h>
18
19 #include <asm/cputhreads.h>
20 #include <asm/reg_a2.h>
21 #include <asm/scom.h>
22 #include <asm/udbg.h>
23
24 #include "wsp.h"
25
26
27 static scom_map_t wsp_scom_map(struct device_node *dev, u64 reg, u64 count)
28 {
29         struct resource r;
30         u64 xscom_addr;
31
32         if (!of_get_property(dev, "scom-controller", NULL)) {
33                 pr_err("%s: device %s is not a SCOM controller\n",
34                         __func__, dev->full_name);
35                 return SCOM_MAP_INVALID;
36         }
37
38         if (of_address_to_resource(dev, 0, &r)) {
39                 pr_debug("Failed to find SCOM controller address\n");
40                 return 0;
41         }
42
43         /* Transform the SCOM address into an XSCOM offset */
44         xscom_addr = ((reg & 0x7f000000) >> 1) | ((reg & 0xfffff) << 3);
45
46         return (scom_map_t)ioremap(r.start + xscom_addr, count << 3);
47 }
48
49 static void wsp_scom_unmap(scom_map_t map)
50 {
51         iounmap((void *)map);
52 }
53
54 static int wsp_scom_read(scom_map_t map, u64 reg, u64 *value)
55 {
56         u64 __iomem *addr = (u64 __iomem *)map;
57
58         *value = in_be64(addr + reg);
59
60         return 0;
61 }
62
63 static int wsp_scom_write(scom_map_t map, u64 reg, u64 value)
64 {
65         u64 __iomem *addr = (u64 __iomem *)map;
66
67         out_be64(addr + reg, value);
68
69         return 0;
70 }
71
72 static const struct scom_controller wsp_scom_controller = {
73         .map    = wsp_scom_map,
74         .unmap  = wsp_scom_unmap,
75         .read   = wsp_scom_read,
76         .write  = wsp_scom_write
77 };
78
79 void scom_init_wsp(void)
80 {
81         scom_init(&wsp_scom_controller);
82 }