]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/atheros/uart_dev_ar933x.c
Add AR934x specific GPIO functions and output MUX configuration.
[FreeBSD/FreeBSD.git] / sys / mips / atheros / uart_dev_ar933x.c
1 /*-
2  * Copyright (c) 2013 Adrian Chadd <adrian@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/conf.h>
34 #include <machine/bus.h>
35
36 #include <dev/uart/uart.h>
37 #include <dev/uart/uart_cpu.h>
38 #include <dev/uart/uart_bus.h>
39
40 #include <mips/atheros/ar933x_uart.h>
41
42 #include "uart_if.h"
43
44 /*
45  * Default system clock is 25MHz; see ar933x_chip.c for how
46  * the startup process determines whether it's 25MHz or 40MHz.
47  */
48 #define DEFAULT_RCLK    (25 * 1000 * 1000)
49
50 #define ar933x_getreg(bas, reg)           \
51         bus_space_read_4((bas)->bst, (bas)->bsh, reg)
52 #define ar933x_setreg(bas, reg, value)    \
53         bus_space_write_4((bas)->bst, (bas)->bsh, reg, value)
54
55
56
57 static int
58 ar933x_drain(struct uart_bas *bas, int what)
59 {
60         int limit;
61
62         if (what & UART_DRAIN_TRANSMITTER) {
63                 limit = 10*1024;
64
65                 /* Loop over until the TX FIFO shows entirely clear */
66                 while (--limit) {
67                         if ((ar933x_getreg(bas, AR933X_UART_CS_REG)
68                             & AR933X_UART_CS_TX_BUSY) == 0)
69                                 break;
70                 }
71                 if (limit == 0) {
72                         return (EIO);
73                 }
74         }
75
76         if (what & UART_DRAIN_RECEIVER) {
77                 limit=10*4096;
78                 while (--limit) {
79
80                         /* XXX duplicated from ar933x_getc() */
81                         /* XXX TODO: refactor! */
82
83                         /* If there's nothing to read, stop! */
84                         if ((ar933x_getreg(bas, AR933X_UART_DATA_REG) &
85                             AR933X_UART_DATA_RX_CSR) == 0) {
86                                 break;
87                         }
88
89                         /* Read the top of the RX FIFO */
90                         (void) ar933x_getreg(bas, AR933X_UART_DATA_REG);
91
92                         /* Remove that entry from said RX FIFO */
93                         ar933x_setreg(bas, AR933X_UART_DATA_REG,
94                             AR933X_UART_DATA_RX_CSR);
95
96                         uart_barrier(bas);
97                         DELAY(2);
98                 }
99                 if (limit == 0) {
100                         return (EIO);
101                 }
102         }
103         return (0);
104 }
105
106 /*
107  * Calculate the baud from the given chip configuration parameters.
108  */
109 static unsigned long
110 ar933x_uart_get_baud(unsigned int clk, unsigned int scale,
111     unsigned int step)
112 {
113         uint64_t t;
114         uint32_t div;
115
116         div = (2 << 16) * (scale + 1);
117         t = clk;
118         t *= step;
119         t += (div / 2);
120         t = t / div;
121
122         return (t);
123 }
124
125 /*
126  * Calculate the scale/step with the lowest possible deviation from
127  * the target baudrate.
128  */
129 static void
130 ar933x_uart_get_scale_step(struct uart_bas *bas, unsigned int baud,
131     unsigned int *scale, unsigned int *step)
132 {
133         unsigned int tscale;
134         uint32_t clk;
135         long min_diff;
136
137         clk = bas->rclk;
138         *scale = 0;
139         *step = 0;
140
141         min_diff = baud;
142         for (tscale = 0; tscale < AR933X_UART_MAX_SCALE; tscale++) {
143                 uint64_t tstep;
144                 int diff;
145
146                 tstep = baud * (tscale + 1);
147                 tstep *= (2 << 16);
148                 tstep = tstep / clk;
149
150                 if (tstep > AR933X_UART_MAX_STEP)
151                         break;
152
153                 diff = abs(ar933x_uart_get_baud(clk, tscale, tstep) - baud);
154                 if (diff < min_diff) {
155                         min_diff = diff;
156                         *scale = tscale;
157                         *step = tstep;
158                 }
159         }
160 }
161
162 static int
163 ar933x_param(struct uart_bas *bas, int baudrate, int databits, int stopbits,
164     int parity)
165 {
166         /* UART always 8 bits */
167
168         /* UART always 1 stop bit */
169
170         /* UART parity is controllable by bits 0:1, ignore for now */
171
172         /* Set baudrate if required. */
173         if (baudrate > 0) {
174                 uint32_t clock_scale, clock_step;
175
176                 /* Find the best fit for the given baud rate */
177                 ar933x_uart_get_scale_step(bas, baudrate, &clock_scale,
178                     &clock_step);
179
180                 /*
181                  * Program the clock register in its entirety - no need
182                  * for Read-Modify-Write.
183                  */
184                 ar933x_setreg(bas, AR933X_UART_CLOCK_REG,
185                     ((clock_scale & AR933X_UART_CLOCK_SCALE_M)
186                       << AR933X_UART_CLOCK_SCALE_S) |
187                     (clock_step & AR933X_UART_CLOCK_STEP_M));
188         }
189
190         uart_barrier(bas);
191         return (0);
192 }
193
194
195 /*
196  * Low-level UART interface.
197  */
198 static int ar933x_probe(struct uart_bas *bas);
199 static void ar933x_init(struct uart_bas *bas, int, int, int, int);
200 static void ar933x_term(struct uart_bas *bas);
201 static void ar933x_putc(struct uart_bas *bas, int);
202 static int ar933x_rxready(struct uart_bas *bas);
203 static int ar933x_getc(struct uart_bas *bas, struct mtx *);
204
205 static struct uart_ops uart_ar933x_ops = {
206         .probe = ar933x_probe,
207         .init = ar933x_init,
208         .term = ar933x_term,
209         .putc = ar933x_putc,
210         .rxready = ar933x_rxready,
211         .getc = ar933x_getc,
212 };
213
214 static int
215 ar933x_probe(struct uart_bas *bas)
216 {
217
218         /* We always know this will be here */
219         return (0);
220 }
221
222 static void
223 ar933x_init(struct uart_bas *bas, int baudrate, int databits, int stopbits,
224     int parity)
225 {
226         uint32_t reg;
227
228         /* Setup default parameters */
229         ar933x_param(bas, baudrate, databits, stopbits, parity);
230
231         /* XXX Force enable UART in case it was disabled */
232
233         /* Disable all interrupts */
234         ar933x_setreg(bas, AR933X_UART_INT_EN_REG, 0x00000000);
235
236         /* Disable the host interrupt */
237         reg = ar933x_getreg(bas, AR933X_UART_CS_REG);
238         reg &= ~AR933X_UART_CS_HOST_INT_EN;
239         ar933x_setreg(bas, AR933X_UART_CS_REG, reg);
240
241         uart_barrier(bas);
242
243         /* XXX Set RTS/DTR? */
244 }
245
246 /*
247  * Detach from console.
248  */
249 static void
250 ar933x_term(struct uart_bas *bas)
251 {
252
253         /* XXX TODO */
254 }
255
256 static void
257 ar933x_putc(struct uart_bas *bas, int c)
258 {
259         int limit;
260
261         limit = 250000;
262
263         /* Wait for space in the TX FIFO */
264         while ( ((ar933x_getreg(bas, AR933X_UART_DATA_REG) &
265             AR933X_UART_DATA_TX_CSR) == 0) && --limit)
266                 DELAY(4);
267
268         /* Write the actual byte */
269         ar933x_setreg(bas, AR933X_UART_DATA_REG,
270             (c & 0xff) | AR933X_UART_DATA_TX_CSR);
271 }
272
273 static int
274 ar933x_rxready(struct uart_bas *bas)
275 {
276
277         /* Wait for a character to come ready */
278         return (!!(ar933x_getreg(bas, AR933X_UART_DATA_REG)
279             & AR933X_UART_DATA_RX_CSR));
280 }
281
282 static int
283 ar933x_getc(struct uart_bas *bas, struct mtx *hwmtx)
284 {
285         int c;
286
287         uart_lock(hwmtx);
288
289         /* Wait for a character to come ready */
290         while ((ar933x_getreg(bas, AR933X_UART_DATA_REG) &
291             AR933X_UART_DATA_RX_CSR) == 0) {
292                 uart_unlock(hwmtx);
293                 DELAY(4);
294                 uart_lock(hwmtx);
295         }
296
297         /* Read the top of the RX FIFO */
298         c = ar933x_getreg(bas, AR933X_UART_DATA_REG) & 0xff;
299
300         /* Remove that entry from said RX FIFO */
301         ar933x_setreg(bas, AR933X_UART_DATA_REG, AR933X_UART_DATA_RX_CSR);
302
303         uart_unlock(hwmtx);
304
305         return (c);
306 }
307
308 /*
309  * High-level UART interface.
310  */
311 struct ar933x_softc {
312         struct uart_softc base;
313
314         uint32_t        u_ier;
315 };
316
317 static int ar933x_bus_attach(struct uart_softc *);
318 static int ar933x_bus_detach(struct uart_softc *);
319 static int ar933x_bus_flush(struct uart_softc *, int);
320 static int ar933x_bus_getsig(struct uart_softc *);
321 static int ar933x_bus_ioctl(struct uart_softc *, int, intptr_t);
322 static int ar933x_bus_ipend(struct uart_softc *);
323 static int ar933x_bus_param(struct uart_softc *, int, int, int, int);
324 static int ar933x_bus_probe(struct uart_softc *);
325 static int ar933x_bus_receive(struct uart_softc *);
326 static int ar933x_bus_setsig(struct uart_softc *, int);
327 static int ar933x_bus_transmit(struct uart_softc *);
328 static void ar933x_bus_grab(struct uart_softc *);
329 static void ar933x_bus_ungrab(struct uart_softc *);
330
331 static kobj_method_t ar933x_methods[] = {
332         KOBJMETHOD(uart_attach,         ar933x_bus_attach),
333         KOBJMETHOD(uart_detach,         ar933x_bus_detach),
334         KOBJMETHOD(uart_flush,          ar933x_bus_flush),
335         KOBJMETHOD(uart_getsig,         ar933x_bus_getsig),
336         KOBJMETHOD(uart_ioctl,          ar933x_bus_ioctl),
337         KOBJMETHOD(uart_ipend,          ar933x_bus_ipend),
338         KOBJMETHOD(uart_param,          ar933x_bus_param),
339         KOBJMETHOD(uart_probe,          ar933x_bus_probe),
340         KOBJMETHOD(uart_receive,        ar933x_bus_receive),
341         KOBJMETHOD(uart_setsig,         ar933x_bus_setsig),
342         KOBJMETHOD(uart_transmit,       ar933x_bus_transmit),
343         KOBJMETHOD(uart_grab,           ar933x_bus_grab),
344         KOBJMETHOD(uart_ungrab,         ar933x_bus_ungrab),
345         { 0, 0 }
346 };
347
348 struct uart_class uart_ar933x_class = {
349         "ar933x",
350         ar933x_methods,
351         sizeof(struct ar933x_softc),
352         .uc_ops = &uart_ar933x_ops,
353         .uc_range = 8,
354         .uc_rclk = DEFAULT_RCLK
355 };
356
357 #define SIGCHG(c, i, s, d)                              \
358         if (c) {                                        \
359                 i |= (i & s) ? s : s | d;               \
360         } else {                                        \
361                 i = (i & s) ? (i & ~s) | d : i;         \
362         }
363
364 static int
365 ar933x_bus_attach(struct uart_softc *sc)
366 {
367         struct ar933x_softc *u = (struct ar933x_softc *)sc;
368         struct uart_bas *bas = &sc->sc_bas;
369         uint32_t reg;
370
371         /* XXX TODO: flush transmitter */
372
373         /*
374          * Setup initial interrupt notifications.
375          *
376          * XXX for now, just RX FIFO valid.
377          * Later on (when they're handled), also handle
378          * RX errors/overflow.
379          */
380         u->u_ier = AR933X_UART_INT_RX_VALID;
381
382         /* Enable RX interrupts to kick-start things */
383         ar933x_setreg(bas, AR933X_UART_INT_EN_REG, u->u_ier);
384
385         /* Enable the host interrupt now */
386         reg = ar933x_getreg(bas, AR933X_UART_CS_REG);
387         reg |= AR933X_UART_CS_HOST_INT_EN;
388         ar933x_setreg(bas, AR933X_UART_CS_REG, reg);
389
390         return (0);
391 }
392
393 static int
394 ar933x_bus_detach(struct uart_softc *sc)
395 {
396         struct uart_bas *bas = &sc->sc_bas;
397         uint32_t reg;
398
399         /* Disable all interrupts */
400         ar933x_setreg(bas, AR933X_UART_INT_EN_REG, 0x00000000);
401
402         /* Disable the host interrupt */
403         reg = ar933x_getreg(bas, AR933X_UART_CS_REG);
404         reg &= ~AR933X_UART_CS_HOST_INT_EN;
405         ar933x_setreg(bas, AR933X_UART_CS_REG, reg);
406         uart_barrier(bas);
407
408         return (0);
409 }
410
411 static int
412 ar933x_bus_flush(struct uart_softc *sc, int what)
413 {
414         struct uart_bas *bas;
415
416         bas = &sc->sc_bas;
417         uart_lock(sc->sc_hwmtx);
418         ar933x_drain(bas, what);
419         uart_unlock(sc->sc_hwmtx);
420
421         return (0);
422 }
423
424 static int
425 ar933x_bus_getsig(struct uart_softc *sc)
426 {
427         uint32_t sig = sc->sc_hwsig;
428
429         /*
430          * For now, let's just return that DSR/DCD/CTS is asserted.
431          */
432         SIGCHG(1, sig, SER_DSR, SER_DDSR);
433         SIGCHG(1, sig, SER_CTS, SER_DCTS);
434         SIGCHG(1, sig, SER_DCD, SER_DDCD);
435         SIGCHG(1, sig,  SER_RI,  SER_DRI);
436
437         sc->sc_hwsig = sig & ~SER_MASK_DELTA;
438
439         return (sig);
440 }
441
442 /*
443  * XXX TODO: actually implement the rest of this!
444  */
445 static int
446 ar933x_bus_ioctl(struct uart_softc *sc, int request, intptr_t data)
447 {
448         int error = 0;
449
450         /* XXX lock */
451         switch (request) {
452         case UART_IOCTL_BREAK:
453         case UART_IOCTL_IFLOW:
454         case UART_IOCTL_OFLOW:
455                 break;
456         case UART_IOCTL_BAUD:
457                 *(int*)data = 115200;
458                 break;
459         default:
460                 error = EINVAL;
461                 break;
462         }
463
464         /* XXX unlock */
465
466         return (error);
467 }
468
469 /*
470  * Bus interrupt handler.
471  *
472  * For now, system interrupts are disabled.
473  * So this is just called from a callout in uart_core.c
474  * to poll various state.
475  */
476 static int
477 ar933x_bus_ipend(struct uart_softc *sc)
478 {
479         struct ar933x_softc *u = (struct ar933x_softc *)sc;
480         struct uart_bas *bas = &sc->sc_bas;
481         int ipend = 0;
482         uint32_t isr;
483
484         uart_lock(sc->sc_hwmtx);
485
486         /*
487          * Fetch/ACK the ISR status.
488          */
489         isr = ar933x_getreg(bas, AR933X_UART_INT_REG);
490         ar933x_setreg(bas, AR933X_UART_INT_REG, isr);
491         uart_barrier(bas);
492
493         /*
494          * RX ready - notify upper layer.
495          */
496         if (isr & AR933X_UART_INT_RX_VALID) {
497                 ipend |= SER_INT_RXREADY;
498         }
499
500         /*
501          * If we get this interrupt, we should disable
502          * it from the interrupt mask and inform the uart
503          * driver appropriately.
504          *
505          * We can't keep setting SER_INT_TXIDLE or SER_INT_SIGCHG
506          * all the time or IO stops working.  So we will always
507          * clear this interrupt if we get it, then we only signal
508          * the upper layer if we were doing active TX in the
509          * first place.
510          *
511          * Also, the name is misleading.  This actually means
512          * "the FIFO is almost empty."  So if we just write some
513          * more data to the FIFO without checking whether it can
514          * take said data, we'll overflow the thing.
515          *
516          * Unfortunately the FreeBSD uart device has no concept of
517          * partial UART writes - it expects that the whole buffer
518          * is written to the hardware.  Thus for now, ar933x_bus_transmit()
519          * will wait for the FIFO to finish draining before it pushes
520          * more frames into it.
521          */
522         if (isr & AR933X_UART_INT_TX_EMPTY) {
523                 /*
524                  * Update u_ier to disable TX notifications; update hardware
525                  */
526                 u->u_ier &= ~AR933X_UART_INT_TX_EMPTY;
527                 ar933x_setreg(bas, AR933X_UART_INT_EN_REG, u->u_ier);
528                 uart_barrier(bas);
529         }
530
531         /*
532          * Only signal TX idle if we're not busy transmitting.
533          *
534          * XXX I never get _out_ of txbusy? Debug that!
535          */
536         if (sc->sc_txbusy) {
537                 if (isr & AR933X_UART_INT_TX_EMPTY) {
538                         ipend |= SER_INT_TXIDLE;
539                 } else {
540                         ipend |= SER_INT_SIGCHG;
541                 }
542         }
543
544         uart_unlock(sc->sc_hwmtx);
545         return (ipend);
546 }
547
548 static int
549 ar933x_bus_param(struct uart_softc *sc, int baudrate, int databits,
550     int stopbits, int parity)
551 {
552         struct uart_bas *bas;
553         int error;
554
555         bas = &sc->sc_bas;
556         uart_lock(sc->sc_hwmtx);
557         error = ar933x_param(bas, baudrate, databits, stopbits, parity);
558         uart_unlock(sc->sc_hwmtx);
559         return (error);
560 }
561
562 static int
563 ar933x_bus_probe(struct uart_softc *sc)
564 {
565         struct uart_bas *bas;
566         int error;
567
568         bas = &sc->sc_bas;
569
570         error = ar933x_probe(bas);
571         if (error)
572                 return (error);
573
574         /* Reset FIFOs. */
575         ar933x_drain(bas, UART_FLUSH_RECEIVER|UART_FLUSH_TRANSMITTER);
576
577         /* XXX TODO: actually find out what the FIFO depth is! */
578         sc->sc_rxfifosz = 16;
579         sc->sc_txfifosz = 16;
580
581         return (0);
582 }
583
584 static int
585 ar933x_bus_receive(struct uart_softc *sc)
586 {
587         struct uart_bas *bas = &sc->sc_bas;
588         int xc;
589
590         uart_lock(sc->sc_hwmtx);
591
592         /* Loop over until we are full, or no data is available */
593         while (ar933x_rxready(bas)) {
594                 if (uart_rx_full(sc)) {
595                         sc->sc_rxbuf[sc->sc_rxput] = UART_STAT_OVERRUN;
596                         break;
597                 }
598
599                 /* Read the top of the RX FIFO */
600                 xc = ar933x_getreg(bas, AR933X_UART_DATA_REG) & 0xff;
601
602                 /* Remove that entry from said RX FIFO */
603                 ar933x_setreg(bas, AR933X_UART_DATA_REG,
604                     AR933X_UART_DATA_RX_CSR);
605                 uart_barrier(bas);
606
607                 /* XXX frame, parity error */
608                 uart_rx_put(sc, xc);
609         }
610
611         /*
612          * XXX TODO: Discard everything left in the Rx FIFO?
613          * XXX only if we've hit an overrun condition?
614          */
615
616         uart_unlock(sc->sc_hwmtx);
617
618         return (0);
619 }
620
621 static int
622 ar933x_bus_setsig(struct uart_softc *sc, int sig)
623 {
624 #if 0
625         struct ar933x_softc *ns8250 = (struct ar933x_softc*)sc;
626         struct uart_bas *bas;
627         uint32_t new, old;
628
629         bas = &sc->sc_bas;
630         do {
631                 old = sc->sc_hwsig;
632                 new = old;
633                 if (sig & SER_DDTR) {
634                         SIGCHG(sig & SER_DTR, new, SER_DTR,
635                             SER_DDTR);
636                 }
637                 if (sig & SER_DRTS) {
638                         SIGCHG(sig & SER_RTS, new, SER_RTS,
639                             SER_DRTS);
640                 }
641         } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new));
642         uart_lock(sc->sc_hwmtx);
643         ns8250->mcr &= ~(MCR_DTR|MCR_RTS);
644         if (new & SER_DTR)
645                 ns8250->mcr |= MCR_DTR;
646         if (new & SER_RTS)
647                 ns8250->mcr |= MCR_RTS;
648         uart_setreg(bas, REG_MCR, ns8250->mcr);
649         uart_barrier(bas);
650         uart_unlock(sc->sc_hwmtx);
651 #endif
652         return (0);
653 }
654
655 /*
656  * Write the current transmit buffer to the TX FIFO.
657  *
658  * Unfortunately the FreeBSD uart device has no concept of
659  * partial UART writes - it expects that the whole buffer
660  * is written to the hardware.  Thus for now, this will wait for
661  * the FIFO to finish draining before it pushes more frames into it.
662  *
663  * If non-blocking operation is truely needed here, either
664  * the FreeBSD uart device will need to handle partial writes
665  * in xxx_bus_transmit(), or we'll need to do TX FIFO buffering
666  * of our own here.
667  */
668 static int
669 ar933x_bus_transmit(struct uart_softc *sc)
670 {
671         struct uart_bas *bas = &sc->sc_bas;
672         struct ar933x_softc *u = (struct ar933x_softc *)sc;
673         int i;
674
675         uart_lock(sc->sc_hwmtx);
676
677         /* Wait for the FIFO to be clear - see above */
678         while (ar933x_getreg(bas, AR933X_UART_CS_REG) &
679             AR933X_UART_CS_TX_BUSY)
680                 ;
681
682         /*
683          * Write some data!
684          */
685         for (i = 0; i < sc->sc_txdatasz; i++) {
686                 /* Write the TX data */
687                 ar933x_setreg(bas, AR933X_UART_DATA_REG,
688                     (sc->sc_txbuf[i] & 0xff) | AR933X_UART_DATA_TX_CSR);
689                 uart_barrier(bas);
690         }
691
692         /*
693          * Now that we're transmitting, get interrupt notification
694          * when the FIFO is (almost) empty - see above.
695          */
696         u->u_ier |= AR933X_UART_INT_TX_EMPTY;
697         ar933x_setreg(bas, AR933X_UART_INT_EN_REG, u->u_ier);
698         uart_barrier(bas);
699
700         /*
701          * Inform the upper layer that we are presently transmitting
702          * data to the hardware; this will be cleared when the
703          * TXIDLE interrupt occurs.
704          */
705         sc->sc_txbusy = 1;
706         uart_unlock(sc->sc_hwmtx);
707
708         return (0);
709 }
710
711 static void
712 ar933x_bus_grab(struct uart_softc *sc)
713 {
714         struct uart_bas *bas = &sc->sc_bas;
715         uint32_t reg;
716
717         /* Disable the host interrupt now */
718         uart_lock(sc->sc_hwmtx);
719         reg = ar933x_getreg(bas, AR933X_UART_CS_REG);
720         reg &= ~AR933X_UART_CS_HOST_INT_EN;
721         ar933x_setreg(bas, AR933X_UART_CS_REG, reg);
722         uart_unlock(sc->sc_hwmtx);
723 }
724
725 static void
726 ar933x_bus_ungrab(struct uart_softc *sc)
727 {
728         struct uart_bas *bas = &sc->sc_bas;
729         uint32_t reg;
730
731         /* Enable the host interrupt now */
732         uart_lock(sc->sc_hwmtx);
733         reg = ar933x_getreg(bas, AR933X_UART_CS_REG);
734         reg |= AR933X_UART_CS_HOST_INT_EN;
735         ar933x_setreg(bas, AR933X_UART_CS_REG, reg);
736         uart_unlock(sc->sc_hwmtx);
737 }