diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-powerpc/dcr-generic.h | 49 | ||||
-rw-r--r-- | include/asm-powerpc/dcr-mmio.h | 20 | ||||
-rw-r--r-- | include/asm-powerpc/dcr-native.h | 16 | ||||
-rw-r--r-- | include/asm-powerpc/dcr.h | 39 |
4 files changed, 110 insertions, 14 deletions
diff --git a/include/asm-powerpc/dcr-generic.h b/include/asm-powerpc/dcr-generic.h new file mode 100644 index 000000000000..35b71599ec46 --- /dev/null +++ b/include/asm-powerpc/dcr-generic.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * (c) Copyright 2006 Benjamin Herrenschmidt, IBM Corp. | ||
3 | * <benh@kernel.crashing.org> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
13 | * the GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #ifndef _ASM_POWERPC_DCR_GENERIC_H | ||
21 | #define _ASM_POWERPC_DCR_GENERIC_H | ||
22 | #ifdef __KERNEL__ | ||
23 | #ifndef __ASSEMBLY__ | ||
24 | |||
25 | enum host_type_t {DCR_HOST_MMIO, DCR_HOST_NATIVE, DCR_HOST_INVALID}; | ||
26 | |||
27 | typedef struct { | ||
28 | enum host_type_t type; | ||
29 | union { | ||
30 | dcr_host_mmio_t mmio; | ||
31 | dcr_host_native_t native; | ||
32 | } host; | ||
33 | } dcr_host_t; | ||
34 | |||
35 | extern bool dcr_map_ok_generic(dcr_host_t host); | ||
36 | |||
37 | extern dcr_host_t dcr_map_generic(struct device_node *dev, unsigned int dcr_n, | ||
38 | unsigned int dcr_c); | ||
39 | extern void dcr_unmap_generic(dcr_host_t host, unsigned int dcr_c); | ||
40 | |||
41 | extern u32 dcr_read_generic(dcr_host_t host, unsigned int dcr_n); | ||
42 | |||
43 | extern void dcr_write_generic(dcr_host_t host, unsigned int dcr_n, u32 value); | ||
44 | |||
45 | #endif /* __ASSEMBLY__ */ | ||
46 | #endif /* __KERNEL__ */ | ||
47 | #endif /* _ASM_POWERPC_DCR_GENERIC_H */ | ||
48 | |||
49 | |||
diff --git a/include/asm-powerpc/dcr-mmio.h b/include/asm-powerpc/dcr-mmio.h index 08532ff1899c..acd491dbd45a 100644 --- a/include/asm-powerpc/dcr-mmio.h +++ b/include/asm-powerpc/dcr-mmio.h | |||
@@ -27,20 +27,26 @@ typedef struct { | |||
27 | void __iomem *token; | 27 | void __iomem *token; |
28 | unsigned int stride; | 28 | unsigned int stride; |
29 | unsigned int base; | 29 | unsigned int base; |
30 | } dcr_host_t; | 30 | } dcr_host_mmio_t; |
31 | 31 | ||
32 | #define DCR_MAP_OK(host) ((host).token != NULL) | 32 | static inline bool dcr_map_ok_mmio(dcr_host_mmio_t host) |
33 | { | ||
34 | return host.token != NULL; | ||
35 | } | ||
33 | 36 | ||
34 | extern dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n, | 37 | extern dcr_host_mmio_t dcr_map_mmio(struct device_node *dev, |
35 | unsigned int dcr_c); | 38 | unsigned int dcr_n, |
36 | extern void dcr_unmap(dcr_host_t host, unsigned int dcr_c); | 39 | unsigned int dcr_c); |
40 | extern void dcr_unmap_mmio(dcr_host_mmio_t host, unsigned int dcr_c); | ||
37 | 41 | ||
38 | static inline u32 dcr_read(dcr_host_t host, unsigned int dcr_n) | 42 | static inline u32 dcr_read_mmio(dcr_host_mmio_t host, unsigned int dcr_n) |
39 | { | 43 | { |
40 | return in_be32(host.token + ((host.base + dcr_n) * host.stride)); | 44 | return in_be32(host.token + ((host.base + dcr_n) * host.stride)); |
41 | } | 45 | } |
42 | 46 | ||
43 | static inline void dcr_write(dcr_host_t host, unsigned int dcr_n, u32 value) | 47 | static inline void dcr_write_mmio(dcr_host_mmio_t host, |
48 | unsigned int dcr_n, | ||
49 | u32 value) | ||
44 | { | 50 | { |
45 | out_be32(host.token + ((host.base + dcr_n) * host.stride), value); | 51 | out_be32(host.token + ((host.base + dcr_n) * host.stride), value); |
46 | } | 52 | } |
diff --git a/include/asm-powerpc/dcr-native.h b/include/asm-powerpc/dcr-native.h index f8398ce80372..72d2b72c7390 100644 --- a/include/asm-powerpc/dcr-native.h +++ b/include/asm-powerpc/dcr-native.h | |||
@@ -26,14 +26,18 @@ | |||
26 | 26 | ||
27 | typedef struct { | 27 | typedef struct { |
28 | unsigned int base; | 28 | unsigned int base; |
29 | } dcr_host_t; | 29 | } dcr_host_native_t; |
30 | 30 | ||
31 | #define DCR_MAP_OK(host) (1) | 31 | static inline bool dcr_map_ok_native(dcr_host_native_t host) |
32 | { | ||
33 | return 1; | ||
34 | } | ||
32 | 35 | ||
33 | #define dcr_map(dev, dcr_n, dcr_c) ((dcr_host_t){ .base = (dcr_n) }) | 36 | #define dcr_map_native(dev, dcr_n, dcr_c) \ |
34 | #define dcr_unmap(host, dcr_c) do {} while (0) | 37 | ((dcr_host_native_t){ .base = (dcr_n) }) |
35 | #define dcr_read(host, dcr_n) mfdcr(dcr_n + host.base) | 38 | #define dcr_unmap_native(host, dcr_c) do {} while (0) |
36 | #define dcr_write(host, dcr_n, value) mtdcr(dcr_n + host.base, value) | 39 | #define dcr_read_native(host, dcr_n) mfdcr(dcr_n + host.base) |
40 | #define dcr_write_native(host, dcr_n, value) mtdcr(dcr_n + host.base, value) | ||
37 | 41 | ||
38 | /* Device Control Registers */ | 42 | /* Device Control Registers */ |
39 | void __mtdcr(int reg, unsigned int val); | 43 | void __mtdcr(int reg, unsigned int val); |
diff --git a/include/asm-powerpc/dcr.h b/include/asm-powerpc/dcr.h index 9338d50538f1..53b283050ab3 100644 --- a/include/asm-powerpc/dcr.h +++ b/include/asm-powerpc/dcr.h | |||
@@ -20,14 +20,50 @@ | |||
20 | #ifndef _ASM_POWERPC_DCR_H | 20 | #ifndef _ASM_POWERPC_DCR_H |
21 | #define _ASM_POWERPC_DCR_H | 21 | #define _ASM_POWERPC_DCR_H |
22 | #ifdef __KERNEL__ | 22 | #ifdef __KERNEL__ |
23 | #ifndef __ASSEMBLY__ | ||
23 | #ifdef CONFIG_PPC_DCR | 24 | #ifdef CONFIG_PPC_DCR |
24 | 25 | ||
25 | #ifdef CONFIG_PPC_DCR_NATIVE | 26 | #ifdef CONFIG_PPC_DCR_NATIVE |
26 | #include <asm/dcr-native.h> | 27 | #include <asm/dcr-native.h> |
27 | #else | 28 | #endif |
29 | |||
30 | #ifdef CONFIG_PPC_DCR_MMIO | ||
28 | #include <asm/dcr-mmio.h> | 31 | #include <asm/dcr-mmio.h> |
29 | #endif | 32 | #endif |
30 | 33 | ||
34 | |||
35 | /* Indirection layer for providing both NATIVE and MMIO support. */ | ||
36 | |||
37 | #if defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO) | ||
38 | |||
39 | #include <asm/dcr-generic.h> | ||
40 | |||
41 | #define DCR_MAP_OK(host) dcr_map_ok_generic(host) | ||
42 | #define dcr_map(dev, dcr_n, dcr_c) dcr_map_generic(dev, dcr_n, dcr_c) | ||
43 | #define dcr_unmap(host, dcr_c) dcr_unmap_generic(host, dcr_c) | ||
44 | #define dcr_read(host, dcr_n) dcr_read_generic(host, dcr_n) | ||
45 | #define dcr_write(host, dcr_n, value) dcr_write_generic(host, dcr_n, value) | ||
46 | |||
47 | #else | ||
48 | |||
49 | #ifdef CONFIG_PPC_DCR_NATIVE | ||
50 | typedef dcr_host_native_t dcr_host_t; | ||
51 | #define DCR_MAP_OK(host) dcr_map_ok_native(host) | ||
52 | #define dcr_map(dev, dcr_n, dcr_c) dcr_map_native(dev, dcr_n, dcr_c) | ||
53 | #define dcr_unmap(host, dcr_c) dcr_unmap_native(host, dcr_c) | ||
54 | #define dcr_read(host, dcr_n) dcr_read_native(host, dcr_n) | ||
55 | #define dcr_write(host, dcr_n, value) dcr_write_native(host, dcr_n, value) | ||
56 | #else | ||
57 | typedef dcr_host_mmio_t dcr_host_t; | ||
58 | #define DCR_MAP_OK(host) dcr_map_ok_mmio(host) | ||
59 | #define dcr_map(dev, dcr_n, dcr_c) dcr_map_mmio(dev, dcr_n, dcr_c) | ||
60 | #define dcr_unmap(host, dcr_c) dcr_unmap_mmio(host, dcr_c) | ||
61 | #define dcr_read(host, dcr_n) dcr_read_mmio(host, dcr_n) | ||
62 | #define dcr_write(host, dcr_n, value) dcr_write_mmio(host, dcr_n, value) | ||
63 | #endif | ||
64 | |||
65 | #endif /* defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO) */ | ||
66 | |||
31 | /* | 67 | /* |
32 | * On CONFIG_PPC_MERGE, we have additional helpers to read the DCR | 68 | * On CONFIG_PPC_MERGE, we have additional helpers to read the DCR |
33 | * base from the device-tree | 69 | * base from the device-tree |
@@ -41,5 +77,6 @@ extern unsigned int dcr_resource_len(struct device_node *np, | |||
41 | #endif /* CONFIG_PPC_MERGE */ | 77 | #endif /* CONFIG_PPC_MERGE */ |
42 | 78 | ||
43 | #endif /* CONFIG_PPC_DCR */ | 79 | #endif /* CONFIG_PPC_DCR */ |
80 | #endif /* __ASSEMBLY__ */ | ||
44 | #endif /* __KERNEL__ */ | 81 | #endif /* __KERNEL__ */ |
45 | #endif /* _ASM_POWERPC_DCR_H */ | 82 | #endif /* _ASM_POWERPC_DCR_H */ |