22 #include <linux/kernel.h>
23 #include <linux/export.h>
27 #ifdef CONFIG_PPC_DCR_MMIO
33 for (par = of_node_get(node); par;) {
48 #if defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO)
50 bool dcr_map_ok_generic(dcr_host_t
host)
52 if (host.type == DCR_HOST_NATIVE)
53 return dcr_map_ok_native(host.host.native);
54 else if (host.type == DCR_HOST_MMIO)
55 return dcr_map_ok_mmio(host.host.mmio);
69 host.type = DCR_HOST_INVALID;
71 dp = find_dcr_parent(dev);
77 pr_debug(
"dcr_map_generic(dcr-access-method = %s)\n", prop);
79 if (!
strcmp(prop,
"native")) {
80 host.type = DCR_HOST_NATIVE;
81 host.host.native = dcr_map_native(dev, dcr_n, dcr_c);
82 }
else if (!
strcmp(prop,
"mmio")) {
83 host.type = DCR_HOST_MMIO;
84 host.host.mmio = dcr_map_mmio(dev, dcr_n, dcr_c);
92 void dcr_unmap_generic(dcr_host_t host,
unsigned int dcr_c)
94 if (host.type == DCR_HOST_NATIVE)
95 dcr_unmap_native(host.host.native, dcr_c);
96 else if (host.type == DCR_HOST_MMIO)
97 dcr_unmap_mmio(host.host.mmio, dcr_c);
103 u32 dcr_read_generic(dcr_host_t host,
unsigned int dcr_n)
105 if (host.type == DCR_HOST_NATIVE)
106 return dcr_read_native(host.host.native, dcr_n);
107 else if (host.type == DCR_HOST_MMIO)
108 return dcr_read_mmio(host.host.mmio, dcr_n);
115 void dcr_write_generic(dcr_host_t host,
unsigned int dcr_n,
u32 value)
117 if (host.type == DCR_HOST_NATIVE)
118 dcr_write_native(host.host.native, dcr_n, value);
119 else if (host.type == DCR_HOST_MMIO)
120 dcr_write_mmio(host.host.mmio, dcr_n, value);
134 if (dr ==
NULL || ds & 1 || index >= (ds / 8))
137 return dr[index * 2];
146 if (dr ==
NULL || ds & 1 || index >= (ds / 8))
149 return dr[index * 2 + 1];
153 #ifdef CONFIG_PPC_DCR_MMIO
157 unsigned int *out_stride)
164 dp = find_dcr_parent(dev);
170 stride = (p ==
NULL) ? 0x10 : *p;
181 if (ret != OF_BAD_ADDR)
182 ret += (
u64)(stride) * (
u64)dcr_n;
184 *out_stride = stride;
191 dcr_host_mmio_t dcr_map_mmio(
struct device_node *dev,
195 dcr_host_mmio_t ret = { .token =
NULL, .stride = 0, .base = dcr_n };
198 pr_debug(
"dcr_map(%s, 0x%x, 0x%x)\n",
201 addr = of_translate_dcr_address(dev, dcr_n, &ret.stride);
202 pr_debug(
"translates to addr: 0x%llx, stride: 0x%x\n",
203 (
unsigned long long) addr, ret.stride);
204 if (addr == OF_BAD_ADDR)
206 pr_debug(
"mapping 0x%x bytes\n", dcr_c * ret.stride);
207 ret.token =
ioremap(addr, dcr_c * ret.stride);
208 if (ret.token ==
NULL)
210 pr_debug(
"mapped at 0x%p -> base is 0x%p\n",
211 ret.token, ret.token - dcr_n * ret.stride);
212 ret.token -= dcr_n * ret.stride;
217 void dcr_unmap_mmio(dcr_host_mmio_t host,
unsigned int dcr_c)
219 dcr_host_mmio_t
h = host;
223 h.token += host.base * h.stride;
231 #ifdef CONFIG_PPC_DCR_NATIVE