gttwsi.c revision 1.7 1 1.7 rkujawa /* $NetBSD: gttwsi.c,v 1.7 2013/05/01 12:25:31 rkujawa Exp $ */
2 1.1 kiyohara /*
3 1.1 kiyohara * Copyright (c) 2008 Eiji Kawauchi.
4 1.1 kiyohara * All rights reserved.
5 1.1 kiyohara *
6 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
7 1.1 kiyohara * modification, are permitted provided that the following conditions
8 1.1 kiyohara * are met:
9 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
10 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
11 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
13 1.1 kiyohara * documentation and/or other materials provided with the distribution.
14 1.1 kiyohara * 3. All advertising materials mentioning features or use of this software
15 1.1 kiyohara * must display the following acknowledgement:
16 1.1 kiyohara * This product includes software developed for the NetBSD Project by
17 1.1 kiyohara * Eiji Kawauchi.
18 1.1 kiyohara * 4. The name of the author may not be used to endorse or promote products
19 1.1 kiyohara * derived from this software without specific prior written permission
20 1.1 kiyohara *
21 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 kiyohara * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 kiyohara * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 kiyohara * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 kiyohara * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 kiyohara * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 kiyohara * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 kiyohara * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 kiyohara * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 kiyohara */
32 1.1 kiyohara /*
33 1.1 kiyohara * Copyright (c) 2005 Brocade Communcations, inc.
34 1.1 kiyohara * All rights reserved.
35 1.1 kiyohara *
36 1.1 kiyohara * Written by Matt Thomas for Brocade Communcations, Inc.
37 1.1 kiyohara *
38 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
39 1.1 kiyohara * modification, are permitted provided that the following conditions
40 1.1 kiyohara * are met:
41 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
42 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
43 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
44 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
45 1.1 kiyohara * documentation and/or other materials provided with the distribution.
46 1.1 kiyohara * 3. The name of Brocade Communications, Inc. may not be used to endorse
47 1.1 kiyohara * or promote products derived from this software without specific prior
48 1.1 kiyohara * written permission.
49 1.1 kiyohara *
50 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY BROCADE COMMUNICATIONS, INC. ``AS IS'' AND
51 1.1 kiyohara * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 1.1 kiyohara * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 1.1 kiyohara * ARE DISCLAIMED. IN NO EVENT SHALL EITHER BROCADE COMMUNICATIONS, INC. BE
54 1.1 kiyohara * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
55 1.1 kiyohara * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
56 1.1 kiyohara * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57 1.1 kiyohara * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58 1.1 kiyohara * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59 1.1 kiyohara * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
60 1.1 kiyohara * OF THE POSSIBILITY OF SUCH DAMAGE.
61 1.1 kiyohara */
62 1.1 kiyohara //#define TWSI_DEBUG
63 1.1 kiyohara
64 1.1 kiyohara /*
65 1.1 kiyohara * Marvell Two-Wire Serial Interface (aka I2C) master driver
66 1.1 kiyohara */
67 1.1 kiyohara
68 1.1 kiyohara #include <sys/cdefs.h>
69 1.7 rkujawa __KERNEL_RCSID(0, "$NetBSD: gttwsi.c,v 1.7 2013/05/01 12:25:31 rkujawa Exp $");
70 1.1 kiyohara #include "locators.h"
71 1.1 kiyohara
72 1.1 kiyohara #include <sys/param.h>
73 1.1 kiyohara #include <sys/bus.h>
74 1.1 kiyohara #include <sys/condvar.h>
75 1.1 kiyohara #include <sys/device.h>
76 1.1 kiyohara #include <sys/errno.h>
77 1.1 kiyohara #include <sys/kernel.h>
78 1.1 kiyohara #include <sys/mutex.h>
79 1.1 kiyohara #include <sys/systm.h>
80 1.1 kiyohara
81 1.1 kiyohara #include <machine/cpu.h>
82 1.1 kiyohara #include <machine/param.h>
83 1.1 kiyohara
84 1.1 kiyohara #include <dev/i2c/i2cvar.h>
85 1.1 kiyohara
86 1.1 kiyohara #include <dev/marvell/marvellvar.h>
87 1.1 kiyohara #include <dev/marvell/gttwsireg.h>
88 1.1 kiyohara
89 1.7 rkujawa #include "opt_mvsoc.h"
90 1.7 rkujawa
91 1.1 kiyohara struct gttwsi_softc {
92 1.1 kiyohara device_t sc_dev;
93 1.1 kiyohara bus_space_tag_t sc_bust;
94 1.1 kiyohara bus_space_handle_t sc_bush;
95 1.1 kiyohara uint8_t sc_started;
96 1.1 kiyohara struct i2c_controller sc_i2c;
97 1.1 kiyohara kmutex_t sc_buslock;
98 1.1 kiyohara kmutex_t sc_mtx;
99 1.1 kiyohara kcondvar_t sc_cv;
100 1.1 kiyohara };
101 1.1 kiyohara
102 1.1 kiyohara static int gttwsi_match(device_t, cfdata_t, void *);
103 1.1 kiyohara static void gttwsi_attach(device_t, device_t, void *);
104 1.1 kiyohara
105 1.1 kiyohara static int gttwsi_intr(void *);
106 1.1 kiyohara
107 1.1 kiyohara static int gttwsi_acquire_bus(void *, int);
108 1.1 kiyohara static void gttwsi_release_bus(void *, int);
109 1.1 kiyohara static int gttwsi_send_start(void *v, int flags);
110 1.1 kiyohara static int gttwsi_send_stop(void *v, int flags);
111 1.1 kiyohara static int gttwsi_initiate_xfer(void *v, i2c_addr_t addr, int flags);
112 1.1 kiyohara static int gttwsi_read_byte(void *v, uint8_t *valp, int flags);
113 1.1 kiyohara static int gttwsi_write_byte(void *v, uint8_t val, int flags);
114 1.1 kiyohara
115 1.1 kiyohara static int gttwsi_wait(struct gttwsi_softc *, uint32_t, uint32_t, int);
116 1.1 kiyohara
117 1.1 kiyohara static __inline u_int32_t RREG(struct gttwsi_softc *, u_int32_t);
118 1.1 kiyohara static __inline void WREG(struct gttwsi_softc *, u_int32_t, u_int32_t);
119 1.1 kiyohara
120 1.1 kiyohara
121 1.1 kiyohara CFATTACH_DECL_NEW(gttwsi_gt, sizeof(struct gttwsi_softc),
122 1.1 kiyohara gttwsi_match, gttwsi_attach, NULL, NULL);
123 1.1 kiyohara CFATTACH_DECL_NEW(gttwsi_mbus, sizeof(struct gttwsi_softc),
124 1.1 kiyohara gttwsi_match, gttwsi_attach, NULL, NULL);
125 1.1 kiyohara
126 1.1 kiyohara
127 1.1 kiyohara static __inline u_int32_t
128 1.1 kiyohara RREG(struct gttwsi_softc *sc, u_int32_t reg)
129 1.1 kiyohara {
130 1.1 kiyohara u_int32_t val;
131 1.1 kiyohara
132 1.1 kiyohara val = bus_space_read_4(sc->sc_bust, sc->sc_bush, reg);
133 1.1 kiyohara #ifdef TWSI_DEBUG
134 1.1 kiyohara printf("I2C:R:%02x:%02x\n", reg, val);
135 1.1 kiyohara #else
136 1.1 kiyohara DELAY(TWSI_READ_DELAY);
137 1.1 kiyohara #endif
138 1.1 kiyohara return val;
139 1.1 kiyohara }
140 1.1 kiyohara
141 1.1 kiyohara static __inline void
142 1.1 kiyohara WREG(struct gttwsi_softc *sc, u_int32_t reg, u_int32_t val)
143 1.1 kiyohara {
144 1.1 kiyohara bus_space_write_4(sc->sc_bust, sc->sc_bush, reg, val);
145 1.1 kiyohara #ifdef TWSI_DEBUG
146 1.1 kiyohara printf("I2C:W:%02x:%02x\n", reg, val);
147 1.1 kiyohara #else
148 1.1 kiyohara DELAY(TWSI_WRITE_DELAY);
149 1.1 kiyohara #endif
150 1.1 kiyohara return;
151 1.1 kiyohara }
152 1.1 kiyohara
153 1.1 kiyohara
154 1.1 kiyohara /* ARGSUSED */
155 1.1 kiyohara static int
156 1.1 kiyohara gttwsi_match(device_t parent, cfdata_t match, void *aux)
157 1.1 kiyohara {
158 1.1 kiyohara struct marvell_attach_args *mva = aux;
159 1.1 kiyohara
160 1.1 kiyohara if (strcmp(mva->mva_name, match->cf_name) != 0)
161 1.1 kiyohara return 0;
162 1.2 kiyohara if (mva->mva_offset == MVA_OFFSET_DEFAULT ||
163 1.2 kiyohara mva->mva_irq == MVA_IRQ_DEFAULT)
164 1.1 kiyohara return 0;
165 1.1 kiyohara
166 1.1 kiyohara mva->mva_size = GTTWSI_SIZE;
167 1.1 kiyohara return 1;
168 1.1 kiyohara }
169 1.1 kiyohara
170 1.1 kiyohara /* ARGSUSED */
171 1.1 kiyohara static void
172 1.1 kiyohara gttwsi_attach(device_t parent, device_t self, void *args)
173 1.1 kiyohara {
174 1.1 kiyohara struct gttwsi_softc *sc = device_private(self);
175 1.1 kiyohara struct marvell_attach_args *mva = args;
176 1.1 kiyohara struct i2cbus_attach_args iba;
177 1.1 kiyohara
178 1.1 kiyohara aprint_naive("\n");
179 1.1 kiyohara aprint_normal(": Marvell TWSI controller\n");
180 1.1 kiyohara
181 1.1 kiyohara sc->sc_dev = self;
182 1.1 kiyohara sc->sc_bust = mva->mva_iot;
183 1.1 kiyohara if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, mva->mva_offset,
184 1.1 kiyohara mva->mva_size, &sc->sc_bush)) {
185 1.1 kiyohara aprint_error_dev(self, "Cannot map registers\n");
186 1.1 kiyohara return;
187 1.1 kiyohara }
188 1.1 kiyohara
189 1.1 kiyohara mutex_init(&sc->sc_buslock, MUTEX_DEFAULT, IPL_NONE);
190 1.1 kiyohara mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_BIO);
191 1.1 kiyohara cv_init(&sc->sc_cv, "gttwsi");
192 1.1 kiyohara
193 1.1 kiyohara sc->sc_started = 0;
194 1.1 kiyohara sc->sc_i2c.ic_cookie = sc;
195 1.1 kiyohara sc->sc_i2c.ic_acquire_bus = gttwsi_acquire_bus;
196 1.1 kiyohara sc->sc_i2c.ic_release_bus = gttwsi_release_bus;
197 1.1 kiyohara sc->sc_i2c.ic_exec = NULL;
198 1.1 kiyohara sc->sc_i2c.ic_send_start = gttwsi_send_start;
199 1.1 kiyohara sc->sc_i2c.ic_send_stop = gttwsi_send_stop;
200 1.1 kiyohara sc->sc_i2c.ic_initiate_xfer = gttwsi_initiate_xfer;
201 1.1 kiyohara sc->sc_i2c.ic_read_byte = gttwsi_read_byte;
202 1.1 kiyohara sc->sc_i2c.ic_write_byte = gttwsi_write_byte;
203 1.1 kiyohara
204 1.1 kiyohara marvell_intr_establish(mva->mva_irq, IPL_BIO, gttwsi_intr, sc);
205 1.1 kiyohara
206 1.1 kiyohara /*
207 1.1 kiyohara * Put the controller into Soft Reset.
208 1.1 kiyohara */
209 1.1 kiyohara /* reset */
210 1.1 kiyohara WREG(sc, TWSI_SOFTRESET, SOFTRESET_VAL);
211 1.1 kiyohara
212 1.1 kiyohara memset(&iba, 0, sizeof(iba));
213 1.1 kiyohara iba.iba_tag = &sc->sc_i2c;
214 1.1 kiyohara (void) config_found_ia(sc->sc_dev, "i2cbus", &iba, iicbus_print);
215 1.1 kiyohara }
216 1.1 kiyohara
217 1.1 kiyohara static int
218 1.1 kiyohara gttwsi_intr(void *arg)
219 1.1 kiyohara {
220 1.1 kiyohara struct gttwsi_softc *sc = arg;
221 1.1 kiyohara uint32_t val;
222 1.1 kiyohara
223 1.1 kiyohara val = RREG(sc, TWSI_CONTROL);
224 1.1 kiyohara if (val & CONTROL_IFLG) {
225 1.1 kiyohara WREG(sc, TWSI_CONTROL, val & ~CONTROL_INTEN);
226 1.1 kiyohara mutex_enter(&sc->sc_mtx);
227 1.1 kiyohara cv_signal(&sc->sc_cv);
228 1.1 kiyohara mutex_exit(&sc->sc_mtx);
229 1.1 kiyohara
230 1.1 kiyohara return 1; /* handled */
231 1.1 kiyohara }
232 1.1 kiyohara return 0;
233 1.1 kiyohara }
234 1.1 kiyohara
235 1.1 kiyohara /* ARGSUSED */
236 1.1 kiyohara static int
237 1.1 kiyohara gttwsi_acquire_bus(void *arg, int flags)
238 1.1 kiyohara {
239 1.1 kiyohara struct gttwsi_softc *sc = arg;
240 1.1 kiyohara
241 1.1 kiyohara mutex_enter(&sc->sc_buslock);
242 1.1 kiyohara return 0;
243 1.1 kiyohara }
244 1.1 kiyohara
245 1.1 kiyohara /* ARGSUSED */
246 1.1 kiyohara static void
247 1.1 kiyohara gttwsi_release_bus(void *arg, int flags)
248 1.1 kiyohara {
249 1.1 kiyohara struct gttwsi_softc *sc = arg;
250 1.1 kiyohara
251 1.1 kiyohara mutex_exit(&sc->sc_buslock);
252 1.1 kiyohara }
253 1.1 kiyohara
254 1.1 kiyohara static int
255 1.1 kiyohara gttwsi_send_start(void *v, int flags)
256 1.1 kiyohara {
257 1.1 kiyohara struct gttwsi_softc *sc = v;
258 1.1 kiyohara int expect;
259 1.1 kiyohara
260 1.1 kiyohara if (sc->sc_started)
261 1.1 kiyohara expect = STAT_RSCT;
262 1.1 kiyohara else
263 1.1 kiyohara expect = STAT_SCT;
264 1.1 kiyohara sc->sc_started = 1;
265 1.1 kiyohara return gttwsi_wait(sc, CONTROL_START, expect, flags);
266 1.1 kiyohara }
267 1.1 kiyohara
268 1.1 kiyohara static int
269 1.1 kiyohara gttwsi_send_stop(void *v, int flags)
270 1.1 kiyohara {
271 1.1 kiyohara struct gttwsi_softc *sc = v;
272 1.1 kiyohara int retry = TWSI_RETRY_COUNT;
273 1.1 kiyohara
274 1.1 kiyohara sc->sc_started = 0;
275 1.1 kiyohara
276 1.1 kiyohara /* Interrupt is not generated for STAT_NRS. */
277 1.1 kiyohara WREG(sc, TWSI_CONTROL, CONTROL_STOP | CONTROL_TWSIEN);
278 1.1 kiyohara while (retry > 0) {
279 1.1 kiyohara if (RREG(sc, TWSI_STATUS) == STAT_NRS)
280 1.1 kiyohara return 0;
281 1.1 kiyohara retry--;
282 1.1 kiyohara DELAY(TWSI_STAT_DELAY);
283 1.1 kiyohara }
284 1.1 kiyohara
285 1.1 kiyohara aprint_error_dev(sc->sc_dev, "send STOP failed\n");
286 1.1 kiyohara return -1;
287 1.1 kiyohara }
288 1.1 kiyohara
289 1.1 kiyohara static int
290 1.1 kiyohara gttwsi_initiate_xfer(void *v, i2c_addr_t addr, int flags)
291 1.1 kiyohara {
292 1.1 kiyohara struct gttwsi_softc *sc = v;
293 1.1 kiyohara uint32_t data, expect;
294 1.1 kiyohara int error, read;
295 1.1 kiyohara
296 1.1 kiyohara gttwsi_send_start(v, flags);
297 1.1 kiyohara
298 1.1 kiyohara read = (flags & I2C_F_READ) != 0;
299 1.1 kiyohara if (read)
300 1.1 kiyohara expect = STAT_ARBT_AR;
301 1.1 kiyohara else
302 1.1 kiyohara expect = STAT_AWBT_AR;
303 1.1 kiyohara
304 1.1 kiyohara /*
305 1.1 kiyohara * First byte contains whether this xfer is a read or write.
306 1.1 kiyohara */
307 1.1 kiyohara data = read;
308 1.1 kiyohara if (addr > 0x7f) {
309 1.1 kiyohara /*
310 1.1 kiyohara * If this is a 10bit request, the first address byte is
311 1.1 kiyohara * 0b11110<b9><b8><r/w>.
312 1.1 kiyohara */
313 1.1 kiyohara data |= 0xf0 | ((addr & 0x300) >> 7);
314 1.1 kiyohara WREG(sc, TWSI_DATA, data);
315 1.1 kiyohara error = gttwsi_wait(sc, 0, expect, flags);
316 1.1 kiyohara if (error)
317 1.1 kiyohara return error;
318 1.1 kiyohara /*
319 1.1 kiyohara * The first address byte has been sent, now to send
320 1.1 kiyohara * the second one.
321 1.1 kiyohara */
322 1.1 kiyohara if (read)
323 1.1 kiyohara expect = STAT_SARBT_AR;
324 1.1 kiyohara else
325 1.1 kiyohara expect = STAT_SAWBT_AR;
326 1.1 kiyohara data = (uint8_t)addr;
327 1.1 kiyohara } else
328 1.1 kiyohara data |= (addr << 1);
329 1.1 kiyohara
330 1.1 kiyohara WREG(sc, TWSI_DATA, data);
331 1.1 kiyohara return gttwsi_wait(sc, 0, expect, flags);
332 1.1 kiyohara }
333 1.1 kiyohara
334 1.1 kiyohara static int
335 1.1 kiyohara gttwsi_read_byte(void *v, uint8_t *valp, int flags)
336 1.1 kiyohara {
337 1.1 kiyohara struct gttwsi_softc *sc = v;
338 1.1 kiyohara int error;
339 1.1 kiyohara
340 1.5 kiyohara if (flags & I2C_F_LAST)
341 1.4 kiyohara error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, flags);
342 1.4 kiyohara else
343 1.4 kiyohara error = gttwsi_wait(sc, CONTROL_ACK, STAT_MRRD_AT, flags);
344 1.1 kiyohara if (!error)
345 1.1 kiyohara *valp = RREG(sc, TWSI_DATA);
346 1.7 rkujawa if (flags & I2C_F_LAST) {
347 1.7 rkujawa #if defined(ARMADAXP)
348 1.7 rkujawa error = gttwsi_send_stop(sc, flags);
349 1.7 rkujawa #else
350 1.1 kiyohara WREG(sc, TWSI_CONTROL, 0);
351 1.7 rkujawa #endif
352 1.7 rkujawa }
353 1.1 kiyohara return error;
354 1.1 kiyohara }
355 1.1 kiyohara
356 1.1 kiyohara static int
357 1.1 kiyohara gttwsi_write_byte(void *v, uint8_t val, int flags)
358 1.1 kiyohara {
359 1.1 kiyohara struct gttwsi_softc *sc = v;
360 1.1 kiyohara
361 1.1 kiyohara WREG(sc, TWSI_DATA, val);
362 1.7 rkujawa #if defined(ARMADAXP)
363 1.7 rkujawa if (flags & I2C_F_LAST)
364 1.7 rkujawa gttwsi_send_stop(sc, flags);
365 1.7 rkujawa #endif
366 1.1 kiyohara return gttwsi_wait(sc, 0, STAT_MTDB_AR, flags);
367 1.1 kiyohara }
368 1.1 kiyohara
369 1.1 kiyohara static int
370 1.1 kiyohara gttwsi_wait(struct gttwsi_softc *sc, uint32_t control, uint32_t expect,
371 1.1 kiyohara int flags)
372 1.1 kiyohara {
373 1.1 kiyohara uint32_t status;
374 1.5 kiyohara int timo, error = 0;
375 1.1 kiyohara
376 1.1 kiyohara DELAY(5);
377 1.1 kiyohara if (!(flags & I2C_F_POLL))
378 1.1 kiyohara control |= CONTROL_INTEN;
379 1.1 kiyohara WREG(sc, TWSI_CONTROL, control | CONTROL_TWSIEN);
380 1.1 kiyohara
381 1.5 kiyohara timo = 0;
382 1.1 kiyohara for (;;) {
383 1.1 kiyohara control = RREG(sc, TWSI_CONTROL);
384 1.1 kiyohara if (control & CONTROL_IFLG)
385 1.1 kiyohara break;
386 1.1 kiyohara if (!(flags & I2C_F_POLL)) {
387 1.1 kiyohara mutex_enter(&sc->sc_mtx);
388 1.1 kiyohara error = cv_timedwait_sig(&sc->sc_cv, &sc->sc_mtx, hz);
389 1.1 kiyohara mutex_exit(&sc->sc_mtx);
390 1.1 kiyohara if (error)
391 1.1 kiyohara return error;
392 1.1 kiyohara }
393 1.1 kiyohara DELAY(TWSI_RETRY_DELAY);
394 1.5 kiyohara if (timo++ > 1000000) /* 1sec */
395 1.5 kiyohara break;
396 1.1 kiyohara }
397 1.1 kiyohara
398 1.1 kiyohara status = RREG(sc, TWSI_STATUS);
399 1.1 kiyohara if (status != expect) {
400 1.1 kiyohara aprint_error_dev(sc->sc_dev,
401 1.1 kiyohara "unexpected status 0x%x: expect 0x%x\n", status, expect);
402 1.1 kiyohara return EIO;
403 1.1 kiyohara }
404 1.1 kiyohara
405 1.7 rkujawa #ifndef ARMADAXP
406 1.6 kiyohara if (flags & I2C_F_STOP)
407 1.6 kiyohara switch (expect) {
408 1.6 kiyohara case STAT_SCT:
409 1.6 kiyohara case STAT_RSCT:
410 1.6 kiyohara case STAT_MRRD_AT:
411 1.6 kiyohara case STAT_ARBT_AR:
412 1.6 kiyohara break;
413 1.6 kiyohara default:
414 1.6 kiyohara error = gttwsi_send_stop(sc, flags);
415 1.6 kiyohara }
416 1.7 rkujawa #endif
417 1.1 kiyohara
418 1.1 kiyohara return error;
419 1.1 kiyohara }
420