]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/powerpc/platforms/powernv/opal-xscom.c
arm: imx6: defconfig: update tx6 defconfigs
[karo-tx-linux.git] / arch / powerpc / platforms / powernv / opal-xscom.c
1 /*
2  * PowerNV LPC bus handling.
3  *
4  * Copyright 2013 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/kernel.h>
13 #include <linux/of.h>
14 #include <linux/bug.h>
15 #include <linux/gfp.h>
16 #include <linux/slab.h>
17
18 #include <asm/machdep.h>
19 #include <asm/firmware.h>
20 #include <asm/opal.h>
21 #include <asm/scom.h>
22
23 /*
24  * We could probably fit that inside the scom_map_t
25  * which is a void* after all but it's really too ugly
26  * so let's kmalloc it for now
27  */
28 struct opal_scom_map {
29         uint32_t chip;
30         uint32_t addr;
31 };
32
33 static scom_map_t opal_scom_map(struct device_node *dev, u64 reg, u64 count)
34 {
35         struct opal_scom_map *m;
36         const __be32 *gcid;
37
38         if (!of_get_property(dev, "scom-controller", NULL)) {
39                 pr_err("%s: device %s is not a SCOM controller\n",
40                         __func__, dev->full_name);
41                 return SCOM_MAP_INVALID;
42         }
43         gcid = of_get_property(dev, "ibm,chip-id", NULL);
44         if (!gcid) {
45                 pr_err("%s: device %s has no ibm,chip-id\n",
46                         __func__, dev->full_name);
47                 return SCOM_MAP_INVALID;
48         }
49         m = kmalloc(sizeof(struct opal_scom_map), GFP_KERNEL);
50         if (!m)
51                 return NULL;
52         m->chip = be32_to_cpup(gcid);
53         m->addr = reg;
54
55         return (scom_map_t)m;
56 }
57
58 static void opal_scom_unmap(scom_map_t map)
59 {
60         kfree(map);
61 }
62
63 static int opal_xscom_err_xlate(int64_t rc)
64 {
65         switch(rc) {
66         case 0:
67                 return 0;
68         /* Add more translations if necessary */
69         default:
70                 return -EIO;
71         }
72 }
73
74 static int opal_scom_read(scom_map_t map, u32 reg, u64 *value)
75 {
76         struct opal_scom_map *m = map;
77         int64_t rc;
78
79         rc = opal_xscom_read(m->chip, m->addr + reg, (uint64_t *)__pa(value));
80         return opal_xscom_err_xlate(rc);
81 }
82
83 static int opal_scom_write(scom_map_t map, u32 reg, u64 value)
84 {
85         struct opal_scom_map *m = map;
86         int64_t rc;
87
88         rc = opal_xscom_write(m->chip, m->addr + reg, value);
89         return opal_xscom_err_xlate(rc);
90 }
91
92 static const struct scom_controller opal_scom_controller = {
93         .map    = opal_scom_map,
94         .unmap  = opal_scom_unmap,
95         .read   = opal_scom_read,
96         .write  = opal_scom_write
97 };
98
99 static int opal_xscom_init(void)
100 {
101         if (firmware_has_feature(FW_FEATURE_OPALv3))
102                 scom_init(&opal_scom_controller);
103         return 0;
104 }
105 arch_initcall(opal_xscom_init);