x86/xen: resume timer irqs early
[linux/fpc-iii.git] / arch / powerpc / platforms / powernv / opal-lpc.c
bloba7614bb14e17b8f4e7772570c60da9e64b3ad37d
1 /*
2 * PowerNV LPC bus handling.
4 * Copyright 2013 IBM Corp.
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.
12 #include <linux/kernel.h>
13 #include <linux/of.h>
14 #include <linux/bug.h>
16 #include <asm/machdep.h>
17 #include <asm/firmware.h>
18 #include <asm/xics.h>
19 #include <asm/opal.h>
21 static int opal_lpc_chip_id = -1;
23 static u8 opal_lpc_inb(unsigned long port)
25 int64_t rc;
26 uint32_t data;
28 if (opal_lpc_chip_id < 0 || port > 0xffff)
29 return 0xff;
30 rc = opal_lpc_read(opal_lpc_chip_id, OPAL_LPC_IO, port, &data, 1);
31 return rc ? 0xff : data;
34 static __le16 __opal_lpc_inw(unsigned long port)
36 int64_t rc;
37 uint32_t data;
39 if (opal_lpc_chip_id < 0 || port > 0xfffe)
40 return 0xffff;
41 if (port & 1)
42 return (__le16)opal_lpc_inb(port) << 8 | opal_lpc_inb(port + 1);
43 rc = opal_lpc_read(opal_lpc_chip_id, OPAL_LPC_IO, port, &data, 2);
44 return rc ? 0xffff : data;
46 static u16 opal_lpc_inw(unsigned long port)
48 return le16_to_cpu(__opal_lpc_inw(port));
51 static __le32 __opal_lpc_inl(unsigned long port)
53 int64_t rc;
54 uint32_t data;
56 if (opal_lpc_chip_id < 0 || port > 0xfffc)
57 return 0xffffffff;
58 if (port & 3)
59 return (__le32)opal_lpc_inb(port ) << 24 |
60 (__le32)opal_lpc_inb(port + 1) << 16 |
61 (__le32)opal_lpc_inb(port + 2) << 8 |
62 opal_lpc_inb(port + 3);
63 rc = opal_lpc_read(opal_lpc_chip_id, OPAL_LPC_IO, port, &data, 4);
64 return rc ? 0xffffffff : data;
67 static u32 opal_lpc_inl(unsigned long port)
69 return le32_to_cpu(__opal_lpc_inl(port));
72 static void opal_lpc_outb(u8 val, unsigned long port)
74 if (opal_lpc_chip_id < 0 || port > 0xffff)
75 return;
76 opal_lpc_write(opal_lpc_chip_id, OPAL_LPC_IO, port, val, 1);
79 static void __opal_lpc_outw(__le16 val, unsigned long port)
81 if (opal_lpc_chip_id < 0 || port > 0xfffe)
82 return;
83 if (port & 1) {
84 opal_lpc_outb(val >> 8, port);
85 opal_lpc_outb(val , port + 1);
86 return;
88 opal_lpc_write(opal_lpc_chip_id, OPAL_LPC_IO, port, val, 2);
91 static void opal_lpc_outw(u16 val, unsigned long port)
93 __opal_lpc_outw(cpu_to_le16(val), port);
96 static void __opal_lpc_outl(__le32 val, unsigned long port)
98 if (opal_lpc_chip_id < 0 || port > 0xfffc)
99 return;
100 if (port & 3) {
101 opal_lpc_outb(val >> 24, port);
102 opal_lpc_outb(val >> 16, port + 1);
103 opal_lpc_outb(val >> 8, port + 2);
104 opal_lpc_outb(val , port + 3);
105 return;
107 opal_lpc_write(opal_lpc_chip_id, OPAL_LPC_IO, port, val, 4);
110 static void opal_lpc_outl(u32 val, unsigned long port)
112 __opal_lpc_outl(cpu_to_le32(val), port);
115 static void opal_lpc_insb(unsigned long p, void *b, unsigned long c)
117 u8 *ptr = b;
119 while(c--)
120 *(ptr++) = opal_lpc_inb(p);
123 static void opal_lpc_insw(unsigned long p, void *b, unsigned long c)
125 __le16 *ptr = b;
127 while(c--)
128 *(ptr++) = __opal_lpc_inw(p);
131 static void opal_lpc_insl(unsigned long p, void *b, unsigned long c)
133 __le32 *ptr = b;
135 while(c--)
136 *(ptr++) = __opal_lpc_inl(p);
139 static void opal_lpc_outsb(unsigned long p, const void *b, unsigned long c)
141 const u8 *ptr = b;
143 while(c--)
144 opal_lpc_outb(*(ptr++), p);
147 static void opal_lpc_outsw(unsigned long p, const void *b, unsigned long c)
149 const __le16 *ptr = b;
151 while(c--)
152 __opal_lpc_outw(*(ptr++), p);
155 static void opal_lpc_outsl(unsigned long p, const void *b, unsigned long c)
157 const __le32 *ptr = b;
159 while(c--)
160 __opal_lpc_outl(*(ptr++), p);
163 static const struct ppc_pci_io opal_lpc_io = {
164 .inb = opal_lpc_inb,
165 .inw = opal_lpc_inw,
166 .inl = opal_lpc_inl,
167 .outb = opal_lpc_outb,
168 .outw = opal_lpc_outw,
169 .outl = opal_lpc_outl,
170 .insb = opal_lpc_insb,
171 .insw = opal_lpc_insw,
172 .insl = opal_lpc_insl,
173 .outsb = opal_lpc_outsb,
174 .outsw = opal_lpc_outsw,
175 .outsl = opal_lpc_outsl,
178 void opal_lpc_init(void)
180 struct device_node *np;
183 * Look for a Power8 LPC bus tagged as "primary",
184 * we currently support only one though the OPAL APIs
185 * support any number.
187 for_each_compatible_node(np, NULL, "ibm,power8-lpc") {
188 if (!of_device_is_available(np))
189 continue;
190 if (!of_get_property(np, "primary", NULL))
191 continue;
192 opal_lpc_chip_id = of_get_ibm_chip_id(np);
193 break;
195 if (opal_lpc_chip_id < 0)
196 return;
198 /* Setup special IO ops */
199 ppc_pci_io = opal_lpc_io;
200 isa_io_special = true;
202 pr_info("OPAL: Power8 LPC bus found, chip ID %d\n", opal_lpc_chip_id);