obs600_machdep.c revision 1.6 1 1.6 matt /* $NetBSD: obs600_machdep.c,v 1.6 2011/06/18 06:44:26 matt Exp $ */
2 1.1 kiyohara /* Original: md_machdep.c,v 1.3 2005/01/24 18:47:37 shige Exp $ */
3 1.1 kiyohara
4 1.1 kiyohara /*
5 1.1 kiyohara * Copyright 2001, 2002 Wasabi Systems, Inc.
6 1.1 kiyohara * All rights reserved.
7 1.1 kiyohara *
8 1.1 kiyohara * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
9 1.1 kiyohara *
10 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
11 1.1 kiyohara * modification, are permitted provided that the following conditions
12 1.1 kiyohara * are met:
13 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
14 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
15 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
17 1.1 kiyohara * documentation and/or other materials provided with the distribution.
18 1.1 kiyohara * 3. All advertising materials mentioning features or use of this software
19 1.1 kiyohara * must display the following acknowledgement:
20 1.1 kiyohara * This product includes software developed for the NetBSD Project by
21 1.1 kiyohara * Wasabi Systems, Inc.
22 1.1 kiyohara * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 1.1 kiyohara * or promote products derived from this software without specific prior
24 1.1 kiyohara * written permission.
25 1.1 kiyohara *
26 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 1.1 kiyohara * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 kiyohara * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 kiyohara * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 1.1 kiyohara * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 kiyohara * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 kiyohara * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 kiyohara * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 kiyohara * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 kiyohara * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 kiyohara * POSSIBILITY OF SUCH DAMAGE.
37 1.1 kiyohara */
38 1.1 kiyohara
39 1.1 kiyohara /*
40 1.1 kiyohara * Copyright (C) 1995, 1996 Wolfgang Solfrank.
41 1.1 kiyohara * Copyright (C) 1995, 1996 TooLs GmbH.
42 1.1 kiyohara * All rights reserved.
43 1.1 kiyohara *
44 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
45 1.1 kiyohara * modification, are permitted provided that the following conditions
46 1.1 kiyohara * are met:
47 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
48 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
49 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
50 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
51 1.1 kiyohara * documentation and/or other materials provided with the distribution.
52 1.1 kiyohara * 3. All advertising materials mentioning features or use of this software
53 1.1 kiyohara * must display the following acknowledgement:
54 1.1 kiyohara * This product includes software developed by TooLs GmbH.
55 1.1 kiyohara * 4. The name of TooLs GmbH may not be used to endorse or promote products
56 1.1 kiyohara * derived from this software without specific prior written permission.
57 1.1 kiyohara *
58 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
59 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 1.1 kiyohara * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 1.1 kiyohara * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62 1.1 kiyohara * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
63 1.1 kiyohara * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
64 1.1 kiyohara * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
65 1.1 kiyohara * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
66 1.1 kiyohara * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
67 1.1 kiyohara * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 1.1 kiyohara */
69 1.1 kiyohara
70 1.1 kiyohara #include <sys/cdefs.h>
71 1.6 matt __KERNEL_RCSID(0, "$NetBSD: obs600_machdep.c,v 1.6 2011/06/18 06:44:26 matt Exp $");
72 1.1 kiyohara
73 1.1 kiyohara #include "opt_compat_netbsd.h"
74 1.1 kiyohara #include "opt_ddb.h"
75 1.1 kiyohara #include "opt_ipkdb.h"
76 1.1 kiyohara #include "opt_modular.h"
77 1.1 kiyohara
78 1.1 kiyohara #include <sys/param.h>
79 1.1 kiyohara #include <sys/bus.h>
80 1.1 kiyohara #include <sys/errno.h>
81 1.1 kiyohara #include <sys/kernel.h>
82 1.1 kiyohara #include <sys/ksyms.h>
83 1.1 kiyohara #include <sys/mount.h>
84 1.1 kiyohara #include <sys/reboot.h>
85 1.1 kiyohara #include <sys/systm.h>
86 1.1 kiyohara #include <sys/device.h>
87 1.4 mrg #include <sys/module.h>
88 1.6 matt #include <sys/bus.h>
89 1.6 matt #include <sys/cpu.h>
90 1.1 kiyohara
91 1.1 kiyohara #include <uvm/uvm_extern.h>
92 1.1 kiyohara
93 1.1 kiyohara #include <machine/obs600.h>
94 1.1 kiyohara
95 1.1 kiyohara #include <powerpc/ibm4xx/amcc405ex.h>
96 1.6 matt #include <powerpc/ibm4xx/cpu.h>
97 1.1 kiyohara #include <powerpc/ibm4xx/dcr4xx.h>
98 1.1 kiyohara #include <powerpc/ibm4xx/dev/comopbvar.h>
99 1.1 kiyohara #include <powerpc/ibm4xx/dev/gpiicreg.h>
100 1.1 kiyohara #include <powerpc/ibm4xx/dev/opbvar.h>
101 1.6 matt
102 1.6 matt #include <powerpc/spr.h>
103 1.1 kiyohara #include <powerpc/ibm4xx/spr.h>
104 1.1 kiyohara
105 1.1 kiyohara #include <dev/ic/comreg.h>
106 1.1 kiyohara
107 1.1 kiyohara #include "ksyms.h"
108 1.1 kiyohara
109 1.1 kiyohara #include "com.h"
110 1.1 kiyohara #if (NCOM > 0)
111 1.1 kiyohara #include <sys/termios.h>
112 1.1 kiyohara
113 1.1 kiyohara #ifndef CONADDR
114 1.1 kiyohara #define CONADDR AMCC405EX_UART0_BASE
115 1.1 kiyohara #endif
116 1.1 kiyohara #ifndef CONSPEED
117 1.1 kiyohara #define CONSPEED B115200
118 1.1 kiyohara #endif
119 1.1 kiyohara #ifndef CONMODE
120 1.1 kiyohara /* 8N1 */
121 1.1 kiyohara #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
122 1.1 kiyohara #endif
123 1.1 kiyohara #endif /* NCOM */
124 1.1 kiyohara
125 1.1 kiyohara /*
126 1.1 kiyohara * XXXX:
127 1.1 kiyohara * It is very troublesome though we can calculate from various registers. X-<
128 1.1 kiyohara */
129 1.1 kiyohara #define OBS600_CPU_FREQ (600 * 1000 * 1000)
130 1.1 kiyohara #define OBS600_MEM_SIZE (1 * 1024 * 1024 * 1024)
131 1.1 kiyohara
132 1.1 kiyohara #define TLB_PG_SIZE (16 * 1024 * 1024)
133 1.1 kiyohara
134 1.1 kiyohara /*
135 1.1 kiyohara * Global variables used here and there
136 1.1 kiyohara */
137 1.1 kiyohara char bootpath[256];
138 1.1 kiyohara
139 1.1 kiyohara extern paddr_t msgbuf_paddr;
140 1.1 kiyohara
141 1.1 kiyohara #if NKSYMS || defined(DDB) || defined(MODULAR)
142 1.1 kiyohara void *startsym, *endsym;
143 1.1 kiyohara #endif
144 1.1 kiyohara
145 1.1 kiyohara void initppc(u_int, u_int, int, char *[], char *);
146 1.1 kiyohara static int read_eeprom(int, char *);
147 1.1 kiyohara
148 1.1 kiyohara
149 1.1 kiyohara void
150 1.1 kiyohara initppc(u_int startkernel, u_int endkernel, int argc, char *argv[],
151 1.1 kiyohara char *argstr)
152 1.1 kiyohara {
153 1.1 kiyohara vaddr_t va;
154 1.1 kiyohara u_int memsize;
155 1.1 kiyohara
156 1.1 kiyohara memsize = OBS600_MEM_SIZE;
157 1.1 kiyohara
158 1.1 kiyohara /* Linear map kernel memory */
159 1.1 kiyohara for (va = 0; va < endkernel; va += TLB_PG_SIZE)
160 1.1 kiyohara ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
161 1.1 kiyohara
162 1.1 kiyohara /*
163 1.1 kiyohara * Map console and I2C after RAM. (see pmap_tlbmiss())
164 1.1 kiyohara * All peripherals mapped on a page.
165 1.1 kiyohara */
166 1.1 kiyohara ppc4xx_tlb_reserve(AMCC405EX_OPB_BASE, roundup(memsize, TLB_PG_SIZE),
167 1.1 kiyohara TLB_PG_SIZE, TLB_I | TLB_G);
168 1.1 kiyohara
169 1.1 kiyohara /* Initialize AMCC 405EX CPU */
170 1.1 kiyohara ibm40x_memsize_init(memsize, startkernel);
171 1.1 kiyohara ibm4xx_init((void (*)(void))ext_intr);
172 1.1 kiyohara
173 1.1 kiyohara /* Disable Watchdog, PIT and FIT interrupts. (u-boot uses PIT...) */
174 1.1 kiyohara mtspr(SPR_TCR, 0);
175 1.1 kiyohara
176 1.1 kiyohara /*
177 1.1 kiyohara * Set the page size.
178 1.1 kiyohara */
179 1.1 kiyohara uvm_setpagesize();
180 1.1 kiyohara
181 1.1 kiyohara /*
182 1.1 kiyohara * Initialize pmap module.
183 1.1 kiyohara */
184 1.1 kiyohara pmap_bootstrap(startkernel, endkernel);
185 1.1 kiyohara
186 1.1 kiyohara
187 1.1 kiyohara #if NKSYMS || defined(DDB) || defined(MODULAR)
188 1.1 kiyohara ksyms_addsyms_elf((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
189 1.1 kiyohara #endif
190 1.1 kiyohara #ifdef DDB
191 1.1 kiyohara if (boothowto & RB_KDB)
192 1.1 kiyohara Debugger();
193 1.1 kiyohara #endif
194 1.1 kiyohara #ifdef IPKDB
195 1.1 kiyohara /*
196 1.1 kiyohara * Now trap to IPKDB
197 1.1 kiyohara */
198 1.1 kiyohara ipkdb_init();
199 1.1 kiyohara if (boothowto & RB_KDB)
200 1.1 kiyohara ipkdb_connect(0);
201 1.1 kiyohara #endif
202 1.4 mrg
203 1.4 mrg /*
204 1.4 mrg * Look for the ibm4xx modules in the right place.
205 1.4 mrg */
206 1.4 mrg module_machine = module_machine_ibm4xx;
207 1.1 kiyohara }
208 1.1 kiyohara
209 1.1 kiyohara void
210 1.1 kiyohara consinit(void)
211 1.1 kiyohara {
212 1.1 kiyohara
213 1.1 kiyohara #if (NCOM > 0)
214 1.1 kiyohara com_opb_cnattach(OBS600_COM_FREQ, CONADDR, CONSPEED, CONMODE);
215 1.1 kiyohara #endif /* NCOM */
216 1.1 kiyohara }
217 1.1 kiyohara
218 1.1 kiyohara /*
219 1.1 kiyohara * Machine dependent startup code.
220 1.1 kiyohara */
221 1.1 kiyohara void
222 1.1 kiyohara cpu_startup(void)
223 1.1 kiyohara {
224 1.1 kiyohara prop_number_t pn;
225 1.1 kiyohara prop_data_t pd;
226 1.1 kiyohara u_char *macaddr, *macaddr1;
227 1.1 kiyohara static u_char buf[16]; /* MAC address x2 buffer */
228 1.1 kiyohara
229 1.1 kiyohara /*
230 1.1 kiyohara * cpu common startup
231 1.1 kiyohara */
232 1.1 kiyohara ibm4xx_cpu_startup("OpenBlockS600 AMCC PowerPC 405EX Board");
233 1.1 kiyohara
234 1.1 kiyohara /*
235 1.1 kiyohara * Set up the board properties database.
236 1.1 kiyohara */
237 1.1 kiyohara board_info_init();
238 1.1 kiyohara
239 1.1 kiyohara read_eeprom(sizeof(buf), buf);
240 1.1 kiyohara macaddr = &buf[0];
241 1.1 kiyohara macaddr1 = &buf[8];
242 1.1 kiyohara
243 1.1 kiyohara pn = prop_number_create_integer(OBS600_CPU_FREQ);
244 1.1 kiyohara KASSERT(pn != NULL);
245 1.1 kiyohara if (prop_dictionary_set(board_properties, "processor-frequency", pn) ==
246 1.1 kiyohara false)
247 1.1 kiyohara panic("setting processor-frequency");
248 1.1 kiyohara prop_object_release(pn);
249 1.1 kiyohara
250 1.1 kiyohara pn = prop_number_create_integer(OBS600_MEM_SIZE);
251 1.1 kiyohara KASSERT(pn != NULL);
252 1.1 kiyohara if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
253 1.1 kiyohara panic("setting mem-size");
254 1.1 kiyohara prop_object_release(pn);
255 1.1 kiyohara
256 1.1 kiyohara #define ETHER_ADDR_LEN 6
257 1.1 kiyohara
258 1.1 kiyohara pd = prop_data_create_data_nocopy(macaddr, ETHER_ADDR_LEN);
259 1.1 kiyohara KASSERT(pd != NULL);
260 1.1 kiyohara if (prop_dictionary_set(board_properties, "emac0-mac-addr", pd) ==
261 1.1 kiyohara false)
262 1.1 kiyohara panic("setting emac0-mac-addr");
263 1.1 kiyohara prop_object_release(pd);
264 1.1 kiyohara pd = prop_data_create_data_nocopy(macaddr1, ETHER_ADDR_LEN);
265 1.1 kiyohara KASSERT(pd != NULL);
266 1.1 kiyohara if (prop_dictionary_set(board_properties, "emac1-mac-addr", pd) ==
267 1.1 kiyohara false)
268 1.1 kiyohara panic("setting emac1-mac-addr");
269 1.1 kiyohara prop_object_release(pd);
270 1.1 kiyohara
271 1.1 kiyohara /* emac0 connects to phy 2 and emac1 to phy 3 via RGMII. */
272 1.1 kiyohara pn = prop_number_create_integer(2);
273 1.1 kiyohara KASSERT(pn != NULL);
274 1.1 kiyohara if (prop_dictionary_set(board_properties, "emac0-mii-phy", pn) == false)
275 1.1 kiyohara panic("setting emac0-mii-phy");
276 1.1 kiyohara prop_object_release(pn);
277 1.1 kiyohara pn = prop_number_create_integer(3);
278 1.1 kiyohara KASSERT(pn != NULL);
279 1.1 kiyohara if (prop_dictionary_set(board_properties, "emac1-mii-phy", pn) == false)
280 1.1 kiyohara panic("setting emac1-mii-phy");
281 1.1 kiyohara prop_object_release(pn);
282 1.1 kiyohara
283 1.1 kiyohara /*
284 1.1 kiyohara * Now that we have VM, malloc()s are OK in bus_space.
285 1.1 kiyohara */
286 1.1 kiyohara bus_space_mallocok();
287 1.1 kiyohara
288 1.1 kiyohara /*
289 1.1 kiyohara * no fake mapiodev
290 1.1 kiyohara */
291 1.1 kiyohara fake_mapiodev = 0;
292 1.3 kiyohara
293 1.3 kiyohara splraise(-1);
294 1.1 kiyohara }
295 1.1 kiyohara
296 1.1 kiyohara /*
297 1.1 kiyohara * Halt or reboot the machine after syncing/dumping according to howto.
298 1.1 kiyohara */
299 1.1 kiyohara void
300 1.1 kiyohara cpu_reboot(int howto, char *what)
301 1.1 kiyohara {
302 1.1 kiyohara static int syncing;
303 1.1 kiyohara static char str[256];
304 1.1 kiyohara char *ap = str, *ap1 = ap;
305 1.1 kiyohara
306 1.1 kiyohara boothowto = howto;
307 1.1 kiyohara if (!cold && !(howto & RB_NOSYNC) && !syncing) {
308 1.1 kiyohara syncing = 1;
309 1.1 kiyohara vfs_shutdown(); /* sync */
310 1.1 kiyohara resettodr(); /* set wall clock */
311 1.1 kiyohara }
312 1.1 kiyohara
313 1.1 kiyohara splhigh();
314 1.1 kiyohara
315 1.1 kiyohara if (!cold && (howto & RB_DUMP))
316 1.1 kiyohara ibm4xx_dumpsys();
317 1.1 kiyohara
318 1.1 kiyohara doshutdownhooks();
319 1.1 kiyohara
320 1.1 kiyohara pmf_system_shutdown(boothowto);
321 1.1 kiyohara
322 1.1 kiyohara if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
323 1.1 kiyohara /* Power off here if we know how...*/
324 1.1 kiyohara }
325 1.1 kiyohara
326 1.1 kiyohara if (howto & RB_HALT) {
327 1.1 kiyohara printf("halted\n\n");
328 1.1 kiyohara
329 1.1 kiyohara #if 0
330 1.1 kiyohara goto reboot; /* XXX for now... */
331 1.1 kiyohara #endif
332 1.1 kiyohara
333 1.1 kiyohara #ifdef DDB
334 1.1 kiyohara printf("dropping to debugger\n");
335 1.1 kiyohara while(1)
336 1.1 kiyohara Debugger();
337 1.1 kiyohara #endif
338 1.1 kiyohara }
339 1.1 kiyohara
340 1.1 kiyohara printf("rebooting\n\n");
341 1.1 kiyohara if (what && *what) {
342 1.1 kiyohara if (strlen(what) > sizeof str - 5)
343 1.1 kiyohara printf("boot string too large, ignored\n");
344 1.1 kiyohara else {
345 1.1 kiyohara strcpy(str, what);
346 1.1 kiyohara ap1 = ap = str + strlen(str);
347 1.1 kiyohara *ap++ = ' ';
348 1.1 kiyohara }
349 1.1 kiyohara }
350 1.1 kiyohara *ap++ = '-';
351 1.1 kiyohara if (howto & RB_SINGLE)
352 1.1 kiyohara *ap++ = 's';
353 1.1 kiyohara if (howto & RB_KDB)
354 1.1 kiyohara *ap++ = 'd';
355 1.1 kiyohara *ap++ = 0;
356 1.1 kiyohara if (ap[-2] == '-')
357 1.1 kiyohara *ap1 = 0;
358 1.1 kiyohara
359 1.1 kiyohara /* flush cache for msgbuf */
360 1.1 kiyohara __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
361 1.1 kiyohara
362 1.1 kiyohara #if 0
363 1.1 kiyohara reboot:
364 1.1 kiyohara #endif
365 1.1 kiyohara ppc4xx_reset();
366 1.1 kiyohara
367 1.1 kiyohara printf("ppc4xx_reset() failed!\n");
368 1.1 kiyohara #ifdef DDB
369 1.1 kiyohara while(1)
370 1.1 kiyohara Debugger();
371 1.1 kiyohara #else
372 1.1 kiyohara while (1)
373 1.1 kiyohara /* nothing */;
374 1.1 kiyohara #endif
375 1.1 kiyohara }
376 1.1 kiyohara
377 1.1 kiyohara /* This function assume already initialized for I2C... */
378 1.1 kiyohara static int
379 1.1 kiyohara read_eeprom(int len, char *buf)
380 1.1 kiyohara {
381 1.1 kiyohara bus_space_tag_t bst = opb_get_bus_space_tag();
382 1.1 kiyohara bus_space_handle_t bsh;
383 1.1 kiyohara uint8_t mdcntl, sts;
384 1.1 kiyohara int cnt, i = 0;
385 1.1 kiyohara
386 1.1 kiyohara #define I2C_EEPROM_ADDR 0x52
387 1.1 kiyohara
388 1.1 kiyohara if (bus_space_map(bst, AMCC405EX_IIC0_BASE, IIC_NREG, 0, &bsh))
389 1.1 kiyohara return ENOMEM; /* ??? */
390 1.1 kiyohara
391 1.1 kiyohara /* Clear Stop Complete Bit */
392 1.1 kiyohara bus_space_write_1(bst, bsh, IIC_STS, IIC_STS_SCMP);
393 1.1 kiyohara /* Check init */
394 1.1 kiyohara do {
395 1.1 kiyohara /* Get status */
396 1.1 kiyohara sts = bus_space_read_1(bst, bsh, IIC_STS);
397 1.1 kiyohara } while ((sts & IIC_STS_PT));
398 1.1 kiyohara
399 1.1 kiyohara mdcntl = bus_space_read_1(bst, bsh, IIC_MDCNTL);
400 1.1 kiyohara bus_space_write_1(bst, bsh, IIC_MDCNTL,
401 1.1 kiyohara mdcntl | IIC_MDCNTL_FMDB | IIC_MDCNTL_FSDB);
402 1.1 kiyohara
403 1.1 kiyohara /* 7-bit adressing */
404 1.1 kiyohara bus_space_write_1(bst, bsh, IIC_HMADR, 0);
405 1.1 kiyohara bus_space_write_1(bst, bsh, IIC_LMADR, I2C_EEPROM_ADDR << 1);
406 1.1 kiyohara
407 1.1 kiyohara bus_space_write_1(bst, bsh, IIC_MDBUF, 0);
408 1.1 kiyohara bus_space_write_1(bst, bsh, IIC_CNTL, IIC_CNTL_PT);
409 1.1 kiyohara do {
410 1.1 kiyohara /* Get status */
411 1.1 kiyohara sts = bus_space_read_1(bst, bsh, IIC_STS);
412 1.1 kiyohara } while ((sts & IIC_STS_PT) && !(sts & IIC_STS_ERR));
413 1.1 kiyohara
414 1.1 kiyohara cnt = 0;
415 1.1 kiyohara while (cnt < len) {
416 1.1 kiyohara /* always read 4byte */
417 1.1 kiyohara bus_space_write_1(bst, bsh, IIC_CNTL,
418 1.1 kiyohara IIC_CNTL_PT | IIC_CNTL_RW | IIC_CNTL_TCT);
419 1.1 kiyohara do {
420 1.1 kiyohara /* Get status */
421 1.1 kiyohara sts = bus_space_read_1(bst, bsh, IIC_STS);
422 1.1 kiyohara } while ((sts & IIC_STS_PT) && !(sts & IIC_STS_ERR));
423 1.1 kiyohara
424 1.1 kiyohara if ((sts & IIC_STS_PT) || (sts & IIC_STS_ERR))
425 1.1 kiyohara break;
426 1.1 kiyohara if (sts & IIC_STS_MDBS) {
427 1.1 kiyohara delay(1);
428 1.1 kiyohara /* read 4byte */
429 1.1 kiyohara for (i = 0; i < 4 && cnt < len; i++, cnt++)
430 1.1 kiyohara buf[cnt] =
431 1.1 kiyohara bus_space_read_1(bst, bsh, IIC_MDBUF);
432 1.1 kiyohara }
433 1.1 kiyohara }
434 1.1 kiyohara for ( ; i < 4; i++)
435 1.1 kiyohara (void) bus_space_read_1(bst, bsh, IIC_MDBUF);
436 1.1 kiyohara
437 1.1 kiyohara bus_space_unmap(bst, bsh, IIC_NREG);
438 1.1 kiyohara
439 1.1 kiyohara return (cnt == len) ? 0 : EINVAL;
440 1.1 kiyohara }
441