adm5120_obio.c revision 1.1.2.2 1 1.1.2.2 yamt /* $NetBSD: adm5120_obio.c,v 1.1.2.2 2007/03/24 14:54:49 yamt Exp $ */
2 1.1.2.2 yamt
3 1.1.2.2 yamt /*-
4 1.1.2.2 yamt * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
5 1.1.2.2 yamt * All rights reserved.
6 1.1.2.2 yamt *
7 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or
8 1.1.2.2 yamt * without modification, are permitted provided that the following
9 1.1.2.2 yamt * conditions are met:
10 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above
13 1.1.2.2 yamt * copyright notice, this list of conditions and the following
14 1.1.2.2 yamt * disclaimer in the documentation and/or other materials provided
15 1.1.2.2 yamt * with the distribution.
16 1.1.2.2 yamt * 3. The names of the authors may not be used to endorse or promote
17 1.1.2.2 yamt * products derived from this software without specific prior
18 1.1.2.2 yamt * written permission.
19 1.1.2.2 yamt *
20 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
21 1.1.2.2 yamt * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 1.1.2.2 yamt * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 1.1.2.2 yamt * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
24 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25 1.1.2.2 yamt * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 1.1.2.2 yamt * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 1.1.2.2 yamt * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1.2.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
29 1.1.2.2 yamt * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 1.1.2.2 yamt * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 1.1.2.2 yamt * OF SUCH DAMAGE.
32 1.1.2.2 yamt */
33 1.1.2.2 yamt /*
34 1.1.2.2 yamt * Copyright 2002 Wasabi Systems, Inc.
35 1.1.2.2 yamt * All rights reserved.
36 1.1.2.2 yamt *
37 1.1.2.2 yamt * Written by Simon Burge for Wasabi Systems, Inc.
38 1.1.2.2 yamt *
39 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
40 1.1.2.2 yamt * modification, are permitted provided that the following conditions
41 1.1.2.2 yamt * are met:
42 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
43 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
44 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
45 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
46 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
47 1.1.2.2 yamt * 3. All advertising materials mentioning features or use of this software
48 1.1.2.2 yamt * must display the following acknowledgement:
49 1.1.2.2 yamt * This product includes software developed for the NetBSD Project by
50 1.1.2.2 yamt * Wasabi Systems, Inc.
51 1.1.2.2 yamt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
52 1.1.2.2 yamt * or promote products derived from this software without specific prior
53 1.1.2.2 yamt * written permission.
54 1.1.2.2 yamt *
55 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
56 1.1.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
59 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60 1.1.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61 1.1.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62 1.1.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
66 1.1.2.2 yamt */
67 1.1.2.2 yamt
68 1.1.2.2 yamt #include <sys/cdefs.h>
69 1.1.2.2 yamt __KERNEL_RCSID(0, "$NetBSD: adm5120_obio.c,v 1.1.2.2 2007/03/24 14:54:49 yamt Exp $");
70 1.1.2.2 yamt
71 1.1.2.2 yamt #include <sys/param.h>
72 1.1.2.2 yamt #include <sys/systm.h>
73 1.1.2.2 yamt #include <sys/device.h>
74 1.1.2.2 yamt
75 1.1.2.2 yamt #include <machine/bus.h>
76 1.1.2.2 yamt
77 1.1.2.2 yamt #include <mips/cache.h>
78 1.1.2.2 yamt #include <mips/cpuregs.h>
79 1.1.2.2 yamt
80 1.1.2.2 yamt #include <mips/adm5120/include/adm5120reg.h>
81 1.1.2.2 yamt #include <mips/adm5120/include/adm5120var.h>
82 1.1.2.2 yamt #include <mips/adm5120/include/adm5120_mainbusvar.h>
83 1.1.2.2 yamt #include <mips/adm5120/include/adm5120_obiovar.h>
84 1.1.2.2 yamt
85 1.1.2.2 yamt #include "locators.h"
86 1.1.2.2 yamt
87 1.1.2.2 yamt #ifdef OBIO_DEBUG
88 1.1.2.2 yamt int obio_debug = 1;
89 1.1.2.2 yamt #define OBIO_DPRINTF(__fmt, ...) \
90 1.1.2.2 yamt do { \
91 1.1.2.2 yamt if (obio_debug) \
92 1.1.2.2 yamt printf((__fmt), __VA_ARGS__); \
93 1.1.2.2 yamt } while (/*CONSTCOND*/0)
94 1.1.2.2 yamt #else /* !OBIO_DEBUG */
95 1.1.2.2 yamt #define OBIO_DPRINTF(__fmt, ...) do { } while (/*CONSTCOND*/0)
96 1.1.2.2 yamt #endif /* OBIO_DEBUG */
97 1.1.2.2 yamt
98 1.1.2.2 yamt static int obio_match(struct device *, struct cfdata *, void *);
99 1.1.2.2 yamt static void obio_attach(struct device *, struct device *, void *);
100 1.1.2.2 yamt static int obio_submatch(struct device *, struct cfdata *,
101 1.1.2.2 yamt const int *, void *);
102 1.1.2.2 yamt static int obio_print(void *, const char *);
103 1.1.2.2 yamt
104 1.1.2.2 yamt CFATTACH_DECL(obio, sizeof(struct device), obio_match, obio_attach, NULL, NULL);
105 1.1.2.2 yamt
106 1.1.2.2 yamt /* There can be only one. */
107 1.1.2.2 yamt int obio_found;
108 1.1.2.2 yamt
109 1.1.2.2 yamt struct obiodev {
110 1.1.2.2 yamt const char *od_name;
111 1.1.2.2 yamt bus_addr_t od_addr;
112 1.1.2.2 yamt int od_irq;
113 1.1.2.2 yamt uint32_t od_gpio_mask;
114 1.1.2.2 yamt };
115 1.1.2.2 yamt
116 1.1.2.2 yamt struct obiodev obiodevs[] = {
117 1.1.2.2 yamt {"uart", ADM5120_BASE_UART0, 1, 0x0},
118 1.1.2.2 yamt {"uart", ADM5120_BASE_UART1, 2, 0x0},
119 1.1.2.2 yamt {"admsw", ADM5120_BASE_SWITCH, 9, 0x0},
120 1.1.2.2 yamt {"ahci", ADM5120_BASE_USB, 3, 0x0},
121 1.1.2.2 yamt {"admflash", ADM5120_BASE_SRAM0, 0, 0x0},
122 1.1.2.2 yamt {NULL, 0, 0, 0x0},
123 1.1.2.2 yamt };
124 1.1.2.2 yamt
125 1.1.2.2 yamt static int
126 1.1.2.2 yamt obio_match(struct device *parent, struct cfdata *match, void *aux)
127 1.1.2.2 yamt {
128 1.1.2.2 yamt return !obio_found;
129 1.1.2.2 yamt }
130 1.1.2.2 yamt
131 1.1.2.2 yamt static void
132 1.1.2.2 yamt obio_attach_args_create(struct obio_attach_args *oa, struct obiodev *od,
133 1.1.2.2 yamt void *gpio, bus_dma_tag_t dmat, bus_space_tag_t st)
134 1.1.2.2 yamt {
135 1.1.2.2 yamt oa->oba_name = od->od_name;
136 1.1.2.2 yamt oa->oba_addr = od->od_addr;
137 1.1.2.2 yamt oa->oba_irq = od->od_irq;
138 1.1.2.2 yamt oa->oba_dt = dmat;
139 1.1.2.2 yamt oa->oba_st = st;
140 1.1.2.2 yamt oa->oba_gpio = gpio;
141 1.1.2.2 yamt oa->oba_gpio_mask = od->od_gpio_mask;
142 1.1.2.2 yamt }
143 1.1.2.2 yamt
144 1.1.2.2 yamt static void
145 1.1.2.2 yamt obio_attach(struct device *parent, struct device *self, void *aux)
146 1.1.2.2 yamt {
147 1.1.2.2 yamt struct mainbus_attach_args *ma = (struct mainbus_attach_args *)aux;
148 1.1.2.2 yamt struct obio_attach_args oa;
149 1.1.2.2 yamt struct obiodev *od;
150 1.1.2.2 yamt
151 1.1.2.2 yamt obio_found = 1;
152 1.1.2.2 yamt printf("\n");
153 1.1.2.2 yamt
154 1.1.2.2 yamt OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
155 1.1.2.2 yamt
156 1.1.2.2 yamt OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
157 1.1.2.2 yamt for (od = obiodevs; od->od_name != NULL; od++) {
158 1.1.2.2 yamt OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
159 1.1.2.2 yamt obio_attach_args_create(&oa, od, ma->ma_gpio, ma->ma_dmat,
160 1.1.2.2 yamt ma->ma_obiot);
161 1.1.2.2 yamt OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
162 1.1.2.2 yamt (void)config_found_sm_loc(self, "obio", NULL, &oa, obio_print,
163 1.1.2.2 yamt obio_submatch);
164 1.1.2.2 yamt }
165 1.1.2.2 yamt OBIO_DPRINTF("%s: %d\n", __func__, __LINE__);
166 1.1.2.2 yamt }
167 1.1.2.2 yamt
168 1.1.2.2 yamt static int
169 1.1.2.2 yamt obio_submatch(struct device *parent, struct cfdata *cf,
170 1.1.2.2 yamt const int *ldesc, void *aux)
171 1.1.2.2 yamt {
172 1.1.2.2 yamt struct obio_attach_args *oa = aux;
173 1.1.2.2 yamt
174 1.1.2.2 yamt if (cf->cf_loc[OBIOCF_ADDR] != OBIOCF_ADDR_DEFAULT &&
175 1.1.2.2 yamt cf->cf_loc[OBIOCF_ADDR] != oa->oba_addr)
176 1.1.2.2 yamt return 0;
177 1.1.2.2 yamt
178 1.1.2.2 yamt return config_match(parent, cf, aux);
179 1.1.2.2 yamt }
180 1.1.2.2 yamt
181 1.1.2.2 yamt static int
182 1.1.2.2 yamt obio_print(void *aux, const char *pnp)
183 1.1.2.2 yamt {
184 1.1.2.2 yamt struct obio_attach_args *oa = aux;
185 1.1.2.2 yamt
186 1.1.2.2 yamt if (pnp != NULL)
187 1.1.2.2 yamt aprint_normal("%s at %s", oa->oba_name, pnp);
188 1.1.2.2 yamt if (oa->oba_addr != OBIOCF_ADDR_DEFAULT)
189 1.1.2.2 yamt aprint_normal(" addr 0x%lx", oa->oba_addr);
190 1.1.2.2 yamt if (oa->oba_gpio_mask != OBIOCF_GPIO_MASK_DEFAULT)
191 1.1.2.2 yamt aprint_normal(" gpio_mask 0x%02x", oa->oba_gpio_mask);
192 1.1.2.2 yamt
193 1.1.2.2 yamt return UNCONF;
194 1.1.2.2 yamt }
195