exb.c revision 1.1.2.1 1 1.1.2.1 uebayasi /* $Id: exb.c,v 1.1.2.1 2010/08/11 13:53:22 uebayasi Exp $ */
2 1.1.2.1 uebayasi
3 1.1.2.1 uebayasi /*-
4 1.1.2.1 uebayasi * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 1.1.2.1 uebayasi * All rights reserved.
6 1.1.2.1 uebayasi *
7 1.1.2.1 uebayasi * This code is derived from software developed for The NetBSD Foundation
8 1.1.2.1 uebayasi * by Masao Uebayashi.
9 1.1.2.1 uebayasi *
10 1.1.2.1 uebayasi * Redistribution and use in source and binary forms, with or without
11 1.1.2.1 uebayasi * modification, are permitted provided that the following conditions
12 1.1.2.1 uebayasi * are met:
13 1.1.2.1 uebayasi * 1. Redistributions of source code must retain the above copyright
14 1.1.2.1 uebayasi * notice, this list of conditions and the following disclaimer.
15 1.1.2.1 uebayasi * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.1 uebayasi * notice, this list of conditions and the following disclaimer in the
17 1.1.2.1 uebayasi * documentation and/or other materials provided with the distribution.
18 1.1.2.1 uebayasi *
19 1.1.2.1 uebayasi * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.2.1 uebayasi * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.2.1 uebayasi * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.2.1 uebayasi * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.2.1 uebayasi * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.2.1 uebayasi * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.2.1 uebayasi * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.2.1 uebayasi * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.2.1 uebayasi * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.2.1 uebayasi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.2.1 uebayasi * POSSIBILITY OF SUCH DAMAGE.
30 1.1.2.1 uebayasi */
31 1.1.2.1 uebayasi
32 1.1.2.1 uebayasi #include <sys/cdefs.h>
33 1.1.2.1 uebayasi __KERNEL_RCSID(0, "$NetBSD: exb.c,v 1.1.2.1 2010/08/11 13:53:22 uebayasi Exp $");
34 1.1.2.1 uebayasi
35 1.1.2.1 uebayasi #include "locators.h"
36 1.1.2.1 uebayasi
37 1.1.2.1 uebayasi #include <sys/param.h>
38 1.1.2.1 uebayasi #include <sys/systm.h>
39 1.1.2.1 uebayasi #include <sys/device.h>
40 1.1.2.1 uebayasi #include <sys/extent.h>
41 1.1.2.1 uebayasi #include <sys/bus.h>
42 1.1.2.1 uebayasi
43 1.1.2.1 uebayasi #include <powerpc/ibm4xx/dcr4xx.h>
44 1.1.2.1 uebayasi #include <powerpc/ibm4xx/dev/exbvar.h>
45 1.1.2.1 uebayasi
46 1.1.2.1 uebayasi /* XXX board specific */
47 1.1.2.1 uebayasi static const struct exb_conf exb_confs[] = {
48 1.1.2.1 uebayasi { "flash", 0xff800000 + 0x00000000, 0x00010000 }, // 0xff800000
49 1.1.2.1 uebayasi { "flash", 0xff800000 + 0x00010000, 0x007b0000 }, // 0xff810000
50 1.1.2.1 uebayasi #if 0 /* XXX extent(9) */
51 1.1.2.1 uebayasi { "flash", 0xff800000 + 0x007c0000, 0x00040000 }, // 0xfffc0000
52 1.1.2.1 uebayasi #endif
53 1.1.2.1 uebayasi { NULL }
54 1.1.2.1 uebayasi };
55 1.1.2.1 uebayasi
56 1.1.2.1 uebayasi struct exb_softc {
57 1.1.2.1 uebayasi };
58 1.1.2.1 uebayasi
59 1.1.2.1 uebayasi static int exb_match(device_t, struct cfdata *, void *);
60 1.1.2.1 uebayasi static void exb_attach(device_t, struct device *, void *);
61 1.1.2.1 uebayasi static int exb_print(void *, const char *);
62 1.1.2.1 uebayasi
63 1.1.2.1 uebayasi CFATTACH_DECL_NEW(exb, sizeof(struct exb_softc), exb_match, exb_attach,
64 1.1.2.1 uebayasi NULL, NULL);
65 1.1.2.1 uebayasi
66 1.1.2.1 uebayasi static struct powerpc_bus_space exb_bus_space_tag =
67 1.1.2.1 uebayasi { _BUS_SPACE_BIG_ENDIAN | _BUS_SPACE_MEM_TYPE, 0 };
68 1.1.2.1 uebayasi
69 1.1.2.1 uebayasi static int
70 1.1.2.1 uebayasi exb_match(device_t parent, struct cfdata *cf, void *aux)
71 1.1.2.1 uebayasi {
72 1.1.2.1 uebayasi
73 1.1.2.1 uebayasi return 1;
74 1.1.2.1 uebayasi }
75 1.1.2.1 uebayasi
76 1.1.2.1 uebayasi static void
77 1.1.2.1 uebayasi exb_attach(device_t parent, device_t self, void *aux)
78 1.1.2.1 uebayasi {
79 1.1.2.1 uebayasi const struct exb_conf *ec = exb_confs;
80 1.1.2.1 uebayasi uint32_t ebc0_bNcr;
81 1.1.2.1 uebayasi bus_addr_t base, size;
82 1.1.2.1 uebayasi int locs[EXBCF_NLOCS];
83 1.1.2.1 uebayasi
84 1.1.2.1 uebayasi printf("\n");
85 1.1.2.1 uebayasi
86 1.1.2.1 uebayasi /* mtdcr needs a constant */
87 1.1.2.1 uebayasi switch (device_unit(self)) {
88 1.1.2.1 uebayasi case 0: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B0CR); break;
89 1.1.2.1 uebayasi case 1: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B1CR); break;
90 1.1.2.1 uebayasi case 2: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B2CR); break;
91 1.1.2.1 uebayasi case 3: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B3CR); break;
92 1.1.2.1 uebayasi case 4: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B4CR); break;
93 1.1.2.1 uebayasi case 5: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B5CR); break;
94 1.1.2.1 uebayasi case 6: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B6CR); break;
95 1.1.2.1 uebayasi case 7: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B7CR); break;
96 1.1.2.1 uebayasi }
97 1.1.2.1 uebayasi ebc0_bNcr = mfdcr(DCR_EBC0_CFGDATA);
98 1.1.2.1 uebayasi base = ebc0_bNcr & 0xfff00000;
99 1.1.2.1 uebayasi size = 0x00100000 << ((ebc0_bNcr & 0x000e0000) >> 17);
100 1.1.2.1 uebayasi
101 1.1.2.1 uebayasi exb_bus_space_tag.pbs_base = base;
102 1.1.2.1 uebayasi exb_bus_space_tag.pbs_limit = base + size - 1;
103 1.1.2.1 uebayasi
104 1.1.2.1 uebayasi while (ec->ec_name) {
105 1.1.2.1 uebayasi struct exb_conf ec1;
106 1.1.2.1 uebayasi
107 1.1.2.1 uebayasi locs[EXBCF_ADDR] = ec->ec_addr;
108 1.1.2.1 uebayasi
109 1.1.2.1 uebayasi ec1 = *ec;
110 1.1.2.1 uebayasi ec1.ec_bust = exb_get_bus_space_tag();
111 1.1.2.1 uebayasi
112 1.1.2.1 uebayasi config_found_sm_loc(self, "exb", locs, &ec1, exb_print,
113 1.1.2.1 uebayasi config_stdsubmatch);
114 1.1.2.1 uebayasi ec++;
115 1.1.2.1 uebayasi }
116 1.1.2.1 uebayasi }
117 1.1.2.1 uebayasi
118 1.1.2.1 uebayasi static int
119 1.1.2.1 uebayasi exb_print(void *aux, const char *bus)
120 1.1.2.1 uebayasi {
121 1.1.2.1 uebayasi struct exb_conf *ec = aux;
122 1.1.2.1 uebayasi
123 1.1.2.1 uebayasi if (bus)
124 1.1.2.1 uebayasi return QUIET;
125 1.1.2.1 uebayasi
126 1.1.2.1 uebayasi if (ec->ec_addr)
127 1.1.2.1 uebayasi printf(" addr %"PRIxBUSADDR, ec->ec_addr);
128 1.1.2.1 uebayasi
129 1.1.2.1 uebayasi return UNCONF;
130 1.1.2.1 uebayasi }
131 1.1.2.1 uebayasi
132 1.1.2.1 uebayasi bus_space_tag_t
133 1.1.2.1 uebayasi exb_get_bus_space_tag(void)
134 1.1.2.1 uebayasi {
135 1.1.2.1 uebayasi static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
136 1.1.2.1 uebayasi __attribute__((aligned(8)));
137 1.1.2.1 uebayasi static int exb_bus_space_tag_inited;
138 1.1.2.1 uebayasi
139 1.1.2.1 uebayasi if (exb_bus_space_tag_inited == 0) {
140 1.1.2.1 uebayasi if (bus_space_init(&exb_bus_space_tag, "exbtag",
141 1.1.2.1 uebayasi ex_storage, sizeof(ex_storage)))
142 1.1.2.1 uebayasi panic("exb_attach: Failed to initialise exb_bus_space_tag");
143 1.1.2.1 uebayasi exb_bus_space_tag_inited = 1;
144 1.1.2.1 uebayasi }
145 1.1.2.1 uebayasi return &exb_bus_space_tag;
146 1.1.2.1 uebayasi }
147