Deleted Added
full compact
uart_cpu_mips_xlr.c (198607) uart_cpu_mips_xlr.c (198625)
1/*-
2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@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 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 *
26 * $Id: uart_cpu_mips_xlr.c,v 1.5 2008-07-16 20:22:39 jayachandranc Exp $
27 */
28/*
29 * Skeleton of this file was based on respective code for ARM
30 * code written by Olivier Houchard.
31 */
32/*
1/*-
2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@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 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 *
26 * $Id: uart_cpu_mips_xlr.c,v 1.5 2008-07-16 20:22:39 jayachandranc Exp $
27 */
28/*
29 * Skeleton of this file was based on respective code for ARM
30 * code written by Olivier Houchard.
31 */
32/*
33 * XLRMIPS: This file is hacked from arm/...
33 * XLRMIPS: This file is hacked from arm/...
34 */
35#include "opt_uart.h"
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD$");
39
40#include <sys/param.h>
41#include <sys/systm.h>

--- 8 unchanged lines hidden (view full) ---

50#include <sys/kernel.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>
53
54static int xlr_uart_probe(struct uart_bas *bas);
55static void xlr_uart_init(struct uart_bas *bas, int, int, int, int);
56static void xlr_uart_term(struct uart_bas *bas);
57static void xlr_uart_putc(struct uart_bas *bas, int);
34 */
35#include "opt_uart.h"
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD$");
39
40#include <sys/param.h>
41#include <sys/systm.h>

--- 8 unchanged lines hidden (view full) ---

50#include <sys/kernel.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>
53
54static int xlr_uart_probe(struct uart_bas *bas);
55static void xlr_uart_init(struct uart_bas *bas, int, int, int, int);
56static void xlr_uart_term(struct uart_bas *bas);
57static void xlr_uart_putc(struct uart_bas *bas, int);
58
58/*static int xlr_uart_poll(struct uart_bas *bas);*/
59static int xlr_uart_getc(struct uart_bas *bas, struct mtx *hwmtx);
59/*static int xlr_uart_poll(struct uart_bas *bas);*/
60static int xlr_uart_getc(struct uart_bas *bas, struct mtx *hwmtx);
60struct mtx xlr_uart_mtx; /*UartLock*/
61struct mtx xlr_uart_mtx; /* UartLock */
61
62extern struct uart_ops uart_ns8250_ops;
63
64struct uart_ops xlr_uart_ns8250_ops = {
65 .probe = xlr_uart_probe,
66 .init = xlr_uart_init,
67 .term = xlr_uart_term,
68 .putc = xlr_uart_putc,
62
63extern struct uart_ops uart_ns8250_ops;
64
65struct uart_ops xlr_uart_ns8250_ops = {
66 .probe = xlr_uart_probe,
67 .init = xlr_uart_init,
68 .term = xlr_uart_term,
69 .putc = xlr_uart_putc,
69 /* .poll = xlr_uart_poll, ?? */
70 /* .poll = xlr_uart_poll, ?? */
70 .getc = xlr_uart_getc,
71};
72
73bus_space_tag_t uart_bus_space_io;
74bus_space_tag_t uart_bus_space_mem;
75
71 .getc = xlr_uart_getc,
72};
73
74bus_space_tag_t uart_bus_space_io;
75bus_space_tag_t uart_bus_space_mem;
76
76static __inline void xlr_uart_lock(struct mtx *hwmtx)
77static __inline void
78xlr_uart_lock(struct mtx *hwmtx)
77{
79{
78 if(!mtx_initialized(hwmtx))
80 if (!mtx_initialized(hwmtx))
79 return;
81 return;
80 if(!kdb_active && hwmtx != NULL)
81 mtx_lock_spin(hwmtx);
82 if (!kdb_active && hwmtx != NULL)
83 mtx_lock_spin(hwmtx);
82}
83
84}
85
84static __inline void xlr_uart_unlock(struct mtx *hwmtx)
86static __inline void
87xlr_uart_unlock(struct mtx *hwmtx)
85{
88{
86 if(!mtx_initialized(hwmtx))
89 if (!mtx_initialized(hwmtx))
87 return;
90 return;
88 if(!kdb_active && hwmtx != NULL)
89 mtx_unlock_spin(hwmtx);
91 if (!kdb_active && hwmtx != NULL)
92 mtx_unlock_spin(hwmtx);
90}
91
92
93}
94
95
93static int xlr_uart_probe(struct uart_bas *bas)
96static int
97xlr_uart_probe(struct uart_bas *bas)
94{
95 int res;
98{
99 int res;
100
96 xlr_uart_lock(&xlr_uart_mtx);
97 res = uart_ns8250_ops.probe(bas);
98 xlr_uart_unlock(&xlr_uart_mtx);
99 return res;
100}
101
101 xlr_uart_lock(&xlr_uart_mtx);
102 res = uart_ns8250_ops.probe(bas);
103 xlr_uart_unlock(&xlr_uart_mtx);
104 return res;
105}
106
102static void xlr_uart_init(struct uart_bas *bas, int baudrate, int databits,
103 int stopbits, int parity)
104
107static void
108xlr_uart_init(struct uart_bas *bas, int baudrate, int databits,
109 int stopbits, int parity)
105{
106 xlr_uart_lock(&xlr_uart_mtx);
110{
111 xlr_uart_lock(&xlr_uart_mtx);
107 uart_ns8250_ops.init(bas,baudrate,databits,stopbits,parity);
112 uart_ns8250_ops.init(bas, baudrate, databits, stopbits, parity);
108 xlr_uart_unlock(&xlr_uart_mtx);
109}
110
113 xlr_uart_unlock(&xlr_uart_mtx);
114}
115
111static void xlr_uart_term(struct uart_bas *bas)
116static void
117xlr_uart_term(struct uart_bas *bas)
112{
113 xlr_uart_lock(&xlr_uart_mtx);
114 uart_ns8250_ops.term(bas);
115 xlr_uart_unlock(&xlr_uart_mtx);
116}
117
118{
119 xlr_uart_lock(&xlr_uart_mtx);
120 uart_ns8250_ops.term(bas);
121 xlr_uart_unlock(&xlr_uart_mtx);
122}
123
118static void xlr_uart_putc(struct uart_bas *bas, int c)
124static void
125xlr_uart_putc(struct uart_bas *bas, int c)
119{
120 xlr_uart_lock(&xlr_uart_mtx);
126{
127 xlr_uart_lock(&xlr_uart_mtx);
121 uart_ns8250_ops.putc(bas,c);
128 uart_ns8250_ops.putc(bas, c);
122 xlr_uart_unlock(&xlr_uart_mtx);
123}
129 xlr_uart_unlock(&xlr_uart_mtx);
130}
131
124/*
125static int xlr_uart_poll(struct uart_bas *bas)
126{
127 int res;
128 xlr_uart_lock(&xlr_uart_mtx);
129 res = uart_ns8250_ops.poll(bas);
130 xlr_uart_unlock(&xlr_uart_mtx);
131 return res;
132}
133*/
134
132/*
133static int xlr_uart_poll(struct uart_bas *bas)
134{
135 int res;
136 xlr_uart_lock(&xlr_uart_mtx);
137 res = uart_ns8250_ops.poll(bas);
138 xlr_uart_unlock(&xlr_uart_mtx);
139 return res;
140}
141*/
142
135static int xlr_uart_getc(struct uart_bas *bas, struct mtx *hwmtx)
143static int
144xlr_uart_getc(struct uart_bas *bas, struct mtx *hwmtx)
136{
137 return uart_ns8250_ops.getc(bas, hwmtx);
138}
139
140int
141uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
142{
143 return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0);
144}
145
146
147int
148uart_cpu_getdev(int devtype, struct uart_devinfo *di)
149{
150 di->ops = &xlr_uart_ns8250_ops;
151 di->bas.chan = 0;
152 di->bas.bst = uart_bus_space_mem;
153 /* TODO Need to call bus_space_map() here */
145{
146 return uart_ns8250_ops.getc(bas, hwmtx);
147}
148
149int
150uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2)
151{
152 return ((b1->bsh == b2->bsh && b1->bst == b2->bst) ? 1 : 0);
153}
154
155
156int
157uart_cpu_getdev(int devtype, struct uart_devinfo *di)
158{
159 di->ops = &xlr_uart_ns8250_ops;
160 di->bas.chan = 0;
161 di->bas.bst = uart_bus_space_mem;
162 /* TODO Need to call bus_space_map() here */
154 di->bas.bsh = 0xbef14000; /* Try with UART0 */
163 di->bas.bsh = 0xbef14000; /* Try with UART0 */
155 di->bas.regshft = 2;
156 /* divisor = rclk / (baudrate * 16); */
157 di->bas.rclk = 66000000;
158
159 di->baudrate = 38400;
160 di->databits = 8;
161 di->stopbits = 1;
162 di->parity = UART_PARITY_NONE;
163
164 /* TODO: Read env variables for all console parameters */
165
166 return (0);
167}
168
164 di->bas.regshft = 2;
165 /* divisor = rclk / (baudrate * 16); */
166 di->bas.rclk = 66000000;
167
168 di->baudrate = 38400;
169 di->databits = 8;
170 di->stopbits = 1;
171 di->parity = UART_PARITY_NONE;
172
173 /* TODO: Read env variables for all console parameters */
174
175 return (0);
176}
177
169static void xlr_uart_mtx_init(void *dummy __unused)
178static void
179xlr_uart_mtx_init(void *dummy __unused)
170{
180{
171 mtx_init(&xlr_uart_mtx, "uart lock",NULL,MTX_SPIN);
181 mtx_init(&xlr_uart_mtx, "uart lock", NULL, MTX_SPIN);
172}
182}
173SYSINIT(xlr_init_uart_mtx, SI_SUB_LOCK, SI_ORDER_ANY, xlr_uart_mtx_init, NULL);
174
183
184SYSINIT(xlr_init_uart_mtx, SI_SUB_LOCK, SI_ORDER_ANY, xlr_uart_mtx_init, NULL);