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