aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/tc
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/tc')
-rw-r--r--drivers/tc/Makefile23
-rw-r--r--drivers/tc/lk201-map.c_shipped265
-rw-r--r--drivers/tc/lk201-map.map356
-rw-r--r--drivers/tc/lk201-remap.c172
-rw-r--r--drivers/tc/lk201.c441
-rw-r--r--drivers/tc/lk201.h125
-rw-r--r--drivers/tc/tc.c260
-rw-r--r--drivers/tc/zs.c2253
-rw-r--r--drivers/tc/zs.h405
9 files changed, 4300 insertions, 0 deletions
diff --git a/drivers/tc/Makefile b/drivers/tc/Makefile
new file mode 100644
index 000000000000..83b5bd75ce26
--- /dev/null
+++ b/drivers/tc/Makefile
@@ -0,0 +1,23 @@
1#
2# Makefile for the linux kernel.
3#
4
5# Object file lists.
6
7obj-$(CONFIG_TC) += tc.o
8obj-$(CONFIG_ZS) += zs.o
9obj-$(CONFIG_VT) += lk201.o lk201-map.o lk201-remap.o
10
11$(obj)/lk201-map.o: $(obj)/lk201-map.c
12
13# Uncomment if you're changing the keymap and have an appropriate
14# loadkeys version for the map. By default, we'll use the shipped
15# versions.
16# GENERATE_KEYMAP := 1
17
18ifdef GENERATE_KEYMAP
19
20$(obj)/lk201-map.c: $(obj)/%.c: $(src)/%.map
21 loadkeys --mktable $< > $@
22
23endif
diff --git a/drivers/tc/lk201-map.c_shipped b/drivers/tc/lk201-map.c_shipped
new file mode 100644
index 000000000000..a9df8f5bf62b
--- /dev/null
+++ b/drivers/tc/lk201-map.c_shipped
@@ -0,0 +1,265 @@
1
2/* Do not edit this file! It was automatically generated by */
3/* loadkeys --mktable defkeymap.map > defkeymap.c */
4
5#include <linux/types.h>
6#include <linux/keyboard.h>
7#include <linux/kd.h>
8
9u_short plain_map[NR_KEYS] = {
10 0xf200, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104, 0xf105, 0xf106,
11 0xf107, 0xf108, 0xf109, 0xf10a, 0xf10b, 0xf10c, 0xf10d, 0xf11b,
12 0xf11c, 0xf110, 0xf111, 0xf112, 0xf113, 0xf060, 0xf031, 0xf032,
13 0xf033, 0xf034, 0xf035, 0xf036, 0xf037, 0xf038, 0xf039, 0xf030,
14 0xf02d, 0xf03d, 0xf07f, 0xf114, 0xf115, 0xf116, 0xf200, 0xf200,
15 0xf200, 0xf200, 0xf009, 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74,
16 0xfb79, 0xfb75, 0xfb69, 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201,
17 0xf117, 0xf118, 0xf119, 0xf307, 0xf308, 0xf309, 0xf30b, 0xf702,
18 0xf207, 0xfb61, 0xfb73, 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a,
19 0xfb6b, 0xfb6c, 0xf03b, 0xf027, 0xf05c, 0xf603, 0xf304, 0xf305,
20 0xf306, 0xf200, 0xf700, 0xf03e, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
21 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf200, 0xf601,
22 0xf600, 0xf602, 0xf301, 0xf302, 0xf303, 0xf30e, 0xf200, 0xf703,
23 0xf020, 0xf200, 0xf200, 0xf300, 0xf310, 0xf200, 0xf200, 0xf200,
24 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
25 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
26};
27
28static u_short shift_map[NR_KEYS] = {
29 0xf200, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104, 0xf105, 0xf106,
30 0xf107, 0xf108, 0xf109, 0xf10a, 0xf10b, 0xf10c, 0xf10d, 0xf203,
31 0xf11c, 0xf110, 0xf111, 0xf112, 0xf113, 0xf07e, 0xf021, 0xf040,
32 0xf023, 0xf024, 0xf025, 0xf05e, 0xf026, 0xf02a, 0xf028, 0xf029,
33 0xf05f, 0xf02b, 0xf07f, 0xf114, 0xf115, 0xf116, 0xf200, 0xf200,
34 0xf200, 0xf200, 0xf009, 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54,
35 0xfb59, 0xfb55, 0xfb49, 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201,
36 0xf117, 0xf20b, 0xf20a, 0xf307, 0xf308, 0xf309, 0xf30b, 0xf702,
37 0xf207, 0xfb41, 0xfb53, 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a,
38 0xfb4b, 0xfb4c, 0xf03a, 0xf022, 0xf07c, 0xf603, 0xf304, 0xf305,
39 0xf306, 0xf200, 0xf700, 0xf03c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
40 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf200, 0xf601,
41 0xf600, 0xf602, 0xf301, 0xf302, 0xf303, 0xf30e, 0xf200, 0xf703,
42 0xf020, 0xf200, 0xf200, 0xf300, 0xf310, 0xf200, 0xf200, 0xf200,
43 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
44 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
45};
46
47static u_short altgr_map[NR_KEYS] = {
48 0xf200, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104, 0xf105, 0xf106,
49 0xf107, 0xf108, 0xf109, 0xf10a, 0xf10b, 0xf10c, 0xf10d, 0xf202,
50 0xf11c, 0xf110, 0xf111, 0xf112, 0xf113, 0xf200, 0xf200, 0xf040,
51 0xf200, 0xf024, 0xf200, 0xf200, 0xf07b, 0xf05b, 0xf05d, 0xf07d,
52 0xf05c, 0xf200, 0xf200, 0xf114, 0xf115, 0xf116, 0xf200, 0xf200,
53 0xf200, 0xf200, 0xf200, 0xfb71, 0xfb77, 0xf918, 0xfb72, 0xfb74,
54 0xfb79, 0xfb75, 0xfb69, 0xfb6f, 0xfb70, 0xf200, 0xf07e, 0xf201,
55 0xf117, 0xf118, 0xf119, 0xf911, 0xf912, 0xf913, 0xf30b, 0xf702,
56 0xf207, 0xf914, 0xfb73, 0xf917, 0xf919, 0xfb67, 0xfb68, 0xfb6a,
57 0xfb6b, 0xfb6c, 0xf200, 0xf200, 0xf200, 0xf603, 0xf90e, 0xf90f,
58 0xf910, 0xf200, 0xf700, 0xf200, 0xfb7a, 0xfb78, 0xf916, 0xfb76,
59 0xf915, 0xfb6e, 0xfb6d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf601,
60 0xf600, 0xf602, 0xf90b, 0xf90c, 0xf90d, 0xf30e, 0xf200, 0xf703,
61 0xf200, 0xf200, 0xf200, 0xf90a, 0xf310, 0xf200, 0xf200, 0xf200,
62 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
63 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
64};
65
66static u_short ctrl_map[NR_KEYS] = {
67 0xf200, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104, 0xf105, 0xf106,
68 0xf107, 0xf108, 0xf109, 0xf10a, 0xf10b, 0xf10c, 0xf10d, 0xf204,
69 0xf11c, 0xf110, 0xf111, 0xf112, 0xf113, 0xf81b, 0xf200, 0xf000,
70 0xf01b, 0xf01c, 0xf01d, 0xf01e, 0xf01f, 0xf07f, 0xf200, 0xf200,
71 0xf01f, 0xf200, 0xf008, 0xf114, 0xf115, 0xf116, 0xf200, 0xf200,
72 0xf200, 0xf200, 0xf200, 0xf011, 0xf017, 0xf005, 0xf012, 0xf014,
73 0xf019, 0xf015, 0xf009, 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf201,
74 0xf117, 0xf118, 0xf119, 0xf307, 0xf308, 0xf309, 0xf30b, 0xf702,
75 0xf207, 0xf001, 0xf013, 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a,
76 0xf00b, 0xf00c, 0xf200, 0xf007, 0xf01c, 0xf603, 0xf304, 0xf305,
77 0xf306, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
78 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf20e, 0xf07f, 0xf200, 0xf601,
79 0xf600, 0xf602, 0xf301, 0xf302, 0xf303, 0xf30e, 0xf200, 0xf703,
80 0xf000, 0xf200, 0xf200, 0xf300, 0xf310, 0xf200, 0xf200, 0xf200,
81 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
82 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
83};
84
85static u_short shift_ctrl_map[NR_KEYS] = {
86 0xf200, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104, 0xf105, 0xf106,
87 0xf107, 0xf108, 0xf109, 0xf10a, 0xf10b, 0xf10c, 0xf10d, 0xf200,
88 0xf11c, 0xf110, 0xf111, 0xf112, 0xf113, 0xf200, 0xf200, 0xf000,
89 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
90 0xf01f, 0xf200, 0xf200, 0xf114, 0xf115, 0xf116, 0xf200, 0xf200,
91 0xf200, 0xf200, 0xf200, 0xf011, 0xf017, 0xf005, 0xf012, 0xf014,
92 0xf019, 0xf015, 0xf009, 0xf00f, 0xf010, 0xf200, 0xf200, 0xf201,
93 0xf117, 0xf118, 0xf119, 0xf307, 0xf308, 0xf309, 0xf30b, 0xf702,
94 0xf207, 0xf001, 0xf013, 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a,
95 0xf00b, 0xf00c, 0xf200, 0xf200, 0xf200, 0xf603, 0xf304, 0xf305,
96 0xf306, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
97 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf601,
98 0xf600, 0xf602, 0xf301, 0xf302, 0xf303, 0xf30e, 0xf200, 0xf703,
99 0xf200, 0xf200, 0xf200, 0xf300, 0xf310, 0xf200, 0xf200, 0xf200,
100 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
101 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
102};
103
104static u_short alt_map[NR_KEYS] = {
105 0xf200, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504, 0xf505, 0xf506,
106 0xf507, 0xf508, 0xf509, 0xf50a, 0xf50b, 0xf50c, 0xf50d, 0xf200,
107 0xf11c, 0xf510, 0xf511, 0xf512, 0xf513, 0xf01b, 0xf831, 0xf832,
108 0xf833, 0xf834, 0xf835, 0xf836, 0xf837, 0xf838, 0xf839, 0xf830,
109 0xf82d, 0xf83d, 0xf87f, 0xf114, 0xf115, 0xf116, 0xf200, 0xf200,
110 0xf200, 0xf200, 0xf809, 0xf871, 0xf877, 0xf865, 0xf872, 0xf874,
111 0xf879, 0xf875, 0xf869, 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d,
112 0xf117, 0xf118, 0xf119, 0xf907, 0xf908, 0xf909, 0xf30b, 0xf702,
113 0xf207, 0xf861, 0xf873, 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a,
114 0xf86b, 0xf86c, 0xf83b, 0xf827, 0xf85c, 0xf603, 0xf904, 0xf905,
115 0xf906, 0xf200, 0xf700, 0xf200, 0xf87a, 0xf878, 0xf863, 0xf876,
116 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf200, 0xf210,
117 0xf600, 0xf211, 0xf901, 0xf902, 0xf903, 0xf30e, 0xf200, 0xf703,
118 0xf820, 0xf200, 0xf200, 0xf900, 0xf310, 0xf200, 0xf200, 0xf200,
119 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
120 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
121};
122
123static u_short ctrl_alt_map[NR_KEYS] = {
124 0xf200, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504, 0xf505, 0xf506,
125 0xf507, 0xf508, 0xf509, 0xf50a, 0xf50b, 0xf50c, 0xf50d, 0xf200,
126 0xf11c, 0xf510, 0xf511, 0xf512, 0xf513, 0xf200, 0xf200, 0xf200,
127 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
128 0xf200, 0xf200, 0xf200, 0xf114, 0xf115, 0xf20c, 0xf200, 0xf200,
129 0xf200, 0xf200, 0xf200, 0xf811, 0xf817, 0xf805, 0xf812, 0xf814,
130 0xf819, 0xf815, 0xf809, 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201,
131 0xf117, 0xf118, 0xf119, 0xf307, 0xf308, 0xf309, 0xf30b, 0xf702,
132 0xf207, 0xf801, 0xf813, 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a,
133 0xf80b, 0xf80c, 0xf200, 0xf200, 0xf200, 0xf603, 0xf304, 0xf305,
134 0xf306, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
135 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf601,
136 0xf600, 0xf602, 0xf301, 0xf302, 0xf303, 0xf30e, 0xf200, 0xf703,
137 0xf200, 0xf200, 0xf200, 0xf300, 0xf20c, 0xf200, 0xf200, 0xf200,
138 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
139 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
140};
141
142ushort *key_maps[MAX_NR_KEYMAPS] = {
143 plain_map, shift_map, altgr_map, 0,
144 ctrl_map, shift_ctrl_map, 0, 0,
145 alt_map, 0, 0, 0,
146 ctrl_alt_map, 0
147};
148
149unsigned int keymap_count = 7;
150
151
152/*
153 * Philosophy: most people do not define more strings, but they who do
154 * often want quite a lot of string space. So, we statically allocate
155 * the default and allocate dynamically in chunks of 512 bytes.
156 */
157
158char func_buf[] = {
159 '\033', '[', '[', 'A', 0,
160 '\033', '[', '[', 'B', 0,
161 '\033', '[', '[', 'C', 0,
162 '\033', '[', '[', 'D', 0,
163 '\033', '[', '[', 'E', 0,
164 '\033', '[', '1', '7', '~', 0,
165 '\033', '[', '1', '8', '~', 0,
166 '\033', '[', '1', '9', '~', 0,
167 '\033', '[', '2', '0', '~', 0,
168 '\033', '[', '2', '1', '~', 0,
169 '\033', '[', '2', '3', '~', 0,
170 '\033', '[', '2', '4', '~', 0,
171 '\033', '[', '2', '5', '~', 0,
172 '\033', '[', '2', '6', '~', 0,
173 '\033', '[', '2', '8', '~', 0,
174 '\033', '[', '2', '9', '~', 0,
175 '\033', '[', '3', '1', '~', 0,
176 '\033', '[', '3', '2', '~', 0,
177 '\033', '[', '3', '3', '~', 0,
178 '\033', '[', '3', '4', '~', 0,
179 '\033', '[', '1', '~', 0,
180 '\033', '[', '2', '~', 0,
181 '\033', '[', '3', '~', 0,
182 '\033', '[', '4', '~', 0,
183 '\033', '[', '5', '~', 0,
184 '\033', '[', '6', '~', 0,
185 '\033', '[', 'M', 0,
186 '\033', '[', 'P', 0,
187};
188
189
190char *funcbufptr = func_buf;
191int funcbufsize = sizeof(func_buf);
192int funcbufleft = 0; /* space left */
193
194char *func_table[MAX_NR_FUNC] = {
195 func_buf + 0,
196 func_buf + 5,
197 func_buf + 10,
198 func_buf + 15,
199 func_buf + 20,
200 func_buf + 25,
201 func_buf + 31,
202 func_buf + 37,
203 func_buf + 43,
204 func_buf + 49,
205 func_buf + 55,
206 func_buf + 61,
207 func_buf + 67,
208 func_buf + 73,
209 func_buf + 79,
210 func_buf + 85,
211 func_buf + 91,
212 func_buf + 97,
213 func_buf + 103,
214 func_buf + 109,
215 func_buf + 115,
216 func_buf + 120,
217 func_buf + 125,
218 func_buf + 130,
219 func_buf + 135,
220 func_buf + 140,
221 func_buf + 145,
222 0,
223 0,
224 func_buf + 149,
225 0,
226};
227
228struct kbdiacr accent_table[MAX_DIACR] = {
229 {'`', 'A', 'À'}, {'`', 'a', 'à'},
230 {'\'', 'A', 'Á'}, {'\'', 'a', 'á'},
231 {'^', 'A', 'Â'}, {'^', 'a', 'â'},
232 {'~', 'A', 'Ã'}, {'~', 'a', 'ã'},
233 {'"', 'A', 'Ä'}, {'"', 'a', 'ä'},
234 {'O', 'A', 'Å'}, {'o', 'a', 'å'},
235 {'0', 'A', 'Å'}, {'0', 'a', 'å'},
236 {'A', 'A', 'Å'}, {'a', 'a', 'å'},
237 {'A', 'E', 'Æ'}, {'a', 'e', 'æ'},
238 {',', 'C', 'Ç'}, {',', 'c', 'ç'},
239 {'`', 'E', 'È'}, {'`', 'e', 'è'},
240 {'\'', 'E', 'É'}, {'\'', 'e', 'é'},
241 {'^', 'E', 'Ê'}, {'^', 'e', 'ê'},
242 {'"', 'E', 'Ë'}, {'"', 'e', 'ë'},
243 {'`', 'I', 'Ì'}, {'`', 'i', 'ì'},
244 {'\'', 'I', 'Í'}, {'\'', 'i', 'í'},
245 {'^', 'I', 'Î'}, {'^', 'i', 'î'},
246 {'"', 'I', 'Ï'}, {'"', 'i', 'ï'},
247 {'-', 'D', 'Ð'}, {'-', 'd', 'ð'},
248 {'~', 'N', 'Ñ'}, {'~', 'n', 'ñ'},
249 {'`', 'O', 'Ò'}, {'`', 'o', 'ò'},
250 {'\'', 'O', 'Ó'}, {'\'', 'o', 'ó'},
251 {'^', 'O', 'Ô'}, {'^', 'o', 'ô'},
252 {'~', 'O', 'Õ'}, {'~', 'o', 'õ'},
253 {'"', 'O', 'Ö'}, {'"', 'o', 'ö'},
254 {'/', 'O', 'Ø'}, {'/', 'o', 'ø'},
255 {'`', 'U', 'Ù'}, {'`', 'u', 'ù'},
256 {'\'', 'U', 'Ú'}, {'\'', 'u', 'ú'},
257 {'^', 'U', 'Û'}, {'^', 'u', 'û'},
258 {'"', 'U', 'Ü'}, {'"', 'u', 'ü'},
259 {'\'', 'Y', 'Ý'}, {'\'', 'y', 'ý'},
260 {'T', 'H', 'Þ'}, {'t', 'h', 'þ'},
261 {'s', 's', 'ß'}, {'"', 'y', 'ÿ'},
262 {'s', 'z', 'ß'}, {'i', 'j', 'ÿ'},
263};
264
265unsigned int accent_table_size = 68;
diff --git a/drivers/tc/lk201-map.map b/drivers/tc/lk201-map.map
new file mode 100644
index 000000000000..2c636b4b7823
--- /dev/null
+++ b/drivers/tc/lk201-map.map
@@ -0,0 +1,356 @@
1# Default kernel keymap. This uses 7 modifier combinations.
2keymaps 0-2,4-5,8,12
3# Change the above line into
4# keymaps 0-2,4-6,8,12
5# in case you want the entries
6# altgr control keycode 83 = Boot
7# altgr control keycode 111 = Boot
8# below.
9#
10# In fact AltGr is used very little, and one more keymap can
11# be saved by mapping AltGr to Alt (and adapting a few entries):
12# keycode 100 = Alt
13#
14keycode 0x15 = grave tilde
15 alt keycode 0x15 = Escape
16 control keycode 0x15 = Meta_Escape
17keycode 0x16 = one exclam
18 alt keycode 0x16 = Meta_one
19keycode 0x17 = two at at
20 control keycode 0x17 = nul
21 shift control keycode 0x17 = nul
22 alt keycode 0x17 = Meta_two
23keycode 0x18 = three numbersign
24 control keycode 0x18 = Escape
25 alt keycode 0x18 = Meta_three
26keycode 0x19 = four dollar dollar
27 control keycode 0x19 = Control_backslash
28 alt keycode 0x19 = Meta_four
29keycode 0x1a = five percent
30 control keycode 0x1a = Control_bracketright
31 alt keycode 0x1a = Meta_five
32keycode 0x1b = six asciicircum
33 control keycode 0x1b = Control_asciicircum
34 alt keycode 0x1b = Meta_six
35keycode 0x1c = seven ampersand braceleft
36 control keycode 0x1c = Control_underscore
37 alt keycode 0x1c = Meta_seven
38keycode 0x1d = eight asterisk bracketleft
39 control keycode 0x1d = Delete
40 alt keycode 0x1d = Meta_eight
41keycode 0x1e = nine parenleft bracketright
42 alt keycode 0x1e = Meta_nine
43keycode 0x1f = zero parenright braceright
44 alt keycode 0x1f = Meta_zero
45keycode 0x20 = minus underscore backslash
46 control keycode 0x20 = Control_underscore
47 shift control keycode 0x20 = Control_underscore
48 alt keycode 0x20 = Meta_minus
49keycode 0x21 = equal plus
50 alt keycode 0x21 = Meta_equal
51keycode 0x22 = Delete Delete
52 control keycode 0x22 = BackSpace
53 alt keycode 0x22 = Meta_Delete
54keycode 0x2a = Tab Tab
55 alt keycode 0x2a = Meta_Tab
56keycode 0x2b = q
57keycode 0x2c = w
58keycode 0x2d = e
59 altgr keycode 0x2d = Hex_E
60keycode 0x2e = r
61keycode 0x2f = t
62keycode 0x30 = y
63keycode 0x31 = u
64keycode 0x32 = i
65keycode 0x33 = o
66keycode 0x34 = p
67keycode 0x35 = bracketleft braceleft
68 control keycode 0x35 = Escape
69 alt keycode 0x35 = Meta_bracketleft
70keycode 0x36 = bracketright braceright asciitilde
71 control keycode 0x36 = Control_bracketright
72 alt keycode 0x36 = Meta_bracketright
73keycode 0x37 = Return
74 alt keycode 0x37 = Meta_Control_m
75keycode 0x3f = Control
76keycode 0x41 = a
77 altgr keycode 0x41 = Hex_A
78keycode 0x42 = s
79keycode 0x43 = d
80 altgr keycode 0x43 = Hex_D
81keycode 0x44 = f
82 altgr keycode 0x44 = Hex_F
83keycode 0x45 = g
84keycode 0x46 = h
85keycode 0x47 = j
86keycode 0x48 = k
87keycode 0x49 = l
88keycode 0x4a = semicolon colon
89 alt keycode 0x4a = Meta_semicolon
90keycode 0x4b = apostrophe quotedbl
91 control keycode 0x4b = Control_g
92 alt keycode 0x4b = Meta_apostrophe
93# keycode 41 = grave asciitilde
94# control keycode 41 = nul
95# alt keycode 41 = Meta_grave
96keycode 0x52 = Shift
97keycode 0x4c = backslash bar
98 control keycode 0x4c = Control_backslash
99 alt keycode 0x4c = Meta_backslash
100keycode 0x53 = greater less
101keycode 0x54 = z
102keycode 0x55 = x
103keycode 0x56 = c
104 altgr keycode 0x56 = Hex_C
105keycode 0x57 = v
106keycode 0x58 = b
107 altgr keycode 0x58 = Hex_B
108keycode 0x59 = n
109keycode 0x5a = m
110keycode 0x5b = comma less
111 alt keycode 0x5b = Meta_comma
112keycode 0x5c = period greater
113 control keycode 0x5c = Compose
114 alt keycode 0x5c = Meta_period
115keycode 0x5d = slash question
116 control keycode 0x5d = Delete
117 alt keycode 0x5d = Meta_slash
118
119keycode 0x67 = Alt
120keycode 0x68 = space space
121 control keycode 0x68 = nul
122 alt keycode 0x68 = Meta_space
123keycode 0x40 = Caps_Lock
124keycode 0x01 = F1
125 control keycode 0x01 = F1
126 alt keycode 0x01 = Console_1
127 control alt keycode 0x01 = Console_1
128keycode 0x02 = F2
129 control keycode 0x02 = F2
130 alt keycode 0x02 = Console_2
131 control alt keycode 0x02 = Console_2
132keycode 0x03 = F3
133 control keycode 0x03 = F3
134 alt keycode 0x03 = Console_3
135 control alt keycode 0x03 = Console_3
136keycode 0x04 = F4
137 control keycode 0x04 = F4
138 alt keycode 0x04 = Console_4
139 control alt keycode 0x04 = Console_4
140keycode 0x05 = F5
141 control keycode 0x05 = F5
142 alt keycode 0x05 = Console_5
143 control alt keycode 0x05 = Console_5
144keycode 0x06 = F6
145 control keycode 0x06 = F6
146 alt keycode 0x06 = Console_6
147 control alt keycode 0x06 = Console_6
148keycode 0x07 = F7
149 control keycode 0x07 = F7
150 alt keycode 0x07 = Console_7
151 control alt keycode 0x07 = Console_7
152keycode 0x08 = F8
153 control keycode 0x08 = F8
154 alt keycode 0x08 = Console_8
155 control alt keycode 0x08 = Console_8
156keycode 0x09 = F9
157 control keycode 0x09 = F9
158 alt keycode 0x09 = Console_9
159 control alt keycode 0x09 = Console_9
160keycode 0x0a = F10
161 control keycode 0x0a = F10
162 alt keycode 0x0a = Console_10
163 control alt keycode 0x0a = Console_10
164keycode 0x0b = F11
165 control keycode 0x0b = F11
166 alt keycode 0x0b = Console_11
167 control alt keycode 0x0b = Console_11
168keycode 0x0c = F12
169 control keycode 0x0c = F12
170 alt keycode 0x0c = Console_12
171 control alt keycode 0x0c = Console_12
172keycode 0x0d = F13
173 control keycode 0x0d = F13
174 alt keycode 0x0d = Console_13
175 control alt keycode 0x0d = Console_13
176keycode 0x0e = F14
177 control keycode 0x0e = F14
178 alt keycode 0x0e = Console_14
179 control alt keycode 0x0e = Console_14
180
181keycode 0x11 = F17
182 control keycode 0x11 = F17
183 alt keycode 0x11 = Console_17
184 control alt keycode 0x11 = Console_17
185keycode 0x12 = F18
186 control keycode 0x12 = F18
187 alt keycode 0x12 = Console_18
188 control alt keycode 0x12 = Console_18
189keycode 0x13 = F19
190 control keycode 0x13 = F19
191 alt keycode 0x13 = Console_19
192 control alt keycode 0x13 = Console_19
193keycode 0x14 = F20
194 control keycode 0x14 = F20
195 alt keycode 0x14 = Console_20
196 control alt keycode 0x14 = Console_20
197
198
199keycode 0x3b = KP_7
200 alt keycode 0x3b = Ascii_7
201 altgr keycode 0x3b = Hex_7
202keycode 0x3c = KP_8
203 alt keycode 0x3c = Ascii_8
204 altgr keycode 0x3c = Hex_8
205keycode 0x3d = KP_9
206 alt keycode 0x3d = Ascii_9
207 altgr keycode 0x3d = Hex_9
208keycode 0x3e = KP_Subtract
209keycode 0x4e = KP_4
210 alt keycode 0x4e = Ascii_4
211 altgr keycode 0x4e = Hex_4
212keycode 0x4f = KP_5
213 alt keycode 0x4f = Ascii_5
214 altgr keycode 0x4f = Hex_5
215keycode 0x50 = KP_6
216 alt keycode 0x50 = Ascii_6
217 altgr keycode 0x50 = Hex_6
218keycode 0x62 = KP_1
219 alt keycode 0x62 = Ascii_1
220 altgr keycode 0x62 = Hex_1
221keycode 0x63 = KP_2
222 alt keycode 0x63 = Ascii_2
223 altgr keycode 0x63 = Hex_2
224keycode 0x64 = KP_3
225 alt keycode 0x64 = Ascii_3
226 altgr keycode 0x64 = Hex_3
227keycode 0x6b = KP_0
228 alt keycode 0x6b = Ascii_0
229 altgr keycode 0x6b = Hex_0
230keycode 0x6c = KP_Period
231# altgr control keycode 0x6c = Boot
232 control alt keycode 0x6c = Boot
233keycode 0x65 = KP_Enter
234
235keycode 0x3f = Control
236
237# keycode 100 = AltGr
238
239keycode 0x23 = Find
240keycode 0x4d = Up
241keycode 0x39 = Prior
242 shift keycode 0x39 = Scroll_Backward
243keycode 0x5f = Left
244 alt keycode 0x5f = Decr_Console
245keycode 0x61 = Right
246 alt keycode 0x61 = Incr_Console
247keycode 0x38 = Select
248keycode 0x60 = Down
249keycode 0x3a = Next
250 shift keycode 0x3a = Scroll_Forward
251keycode 0x24 = Insert
252keycode 0x25 = Remove
253# altgr control keycode 0x25 = Boot
254 control alt keycode 0x25 = Boot
255
256keycode 0x0f = Help Show_Memory Show_Registers
257 control keycode 0x0f = Show_State
258
259keycode 0x10 = Do
260
261string F1 = "\033[[A"
262string F2 = "\033[[B"
263string F3 = "\033[[C"
264string F4 = "\033[[D"
265string F5 = "\033[[E"
266string F6 = "\033[17~"
267string F7 = "\033[18~"
268string F8 = "\033[19~"
269string F9 = "\033[20~"
270string F10 = "\033[21~"
271string F11 = "\033[23~"
272string F12 = "\033[24~"
273string F13 = "\033[25~"
274string F14 = "\033[26~"
275string F15 = "\033[28~"
276string F16 = "\033[29~"
277string F17 = "\033[31~"
278string F18 = "\033[32~"
279string F19 = "\033[33~"
280string F20 = "\033[34~"
281string Find = "\033[1~"
282string Insert = "\033[2~"
283string Remove = "\033[3~"
284string Select = "\033[4~"
285string Prior = "\033[5~"
286string Next = "\033[6~"
287string Macro = "\033[M"
288string Pause = "\033[P"
289compose '`' 'A' to 'À'
290compose '`' 'a' to 'à'
291compose '\'' 'A' to 'Á'
292compose '\'' 'a' to 'á'
293compose '^' 'A' to 'Â'
294compose '^' 'a' to 'â'
295compose '~' 'A' to 'Ã'
296compose '~' 'a' to 'ã'
297compose '"' 'A' to 'Ä'
298compose '"' 'a' to 'ä'
299compose 'O' 'A' to 'Å'
300compose 'o' 'a' to 'å'
301compose '0' 'A' to 'Å'
302compose '0' 'a' to 'å'
303compose 'A' 'A' to 'Å'
304compose 'a' 'a' to 'å'
305compose 'A' 'E' to 'Æ'
306compose 'a' 'e' to 'æ'
307compose ',' 'C' to 'Ç'
308compose ',' 'c' to 'ç'
309compose '`' 'E' to 'È'
310compose '`' 'e' to 'è'
311compose '\'' 'E' to 'É'
312compose '\'' 'e' to 'é'
313compose '^' 'E' to 'Ê'
314compose '^' 'e' to 'ê'
315compose '"' 'E' to 'Ë'
316compose '"' 'e' to 'ë'
317compose '`' 'I' to 'Ì'
318compose '`' 'i' to 'ì'
319compose '\'' 'I' to 'Í'
320compose '\'' 'i' to 'í'
321compose '^' 'I' to 'Î'
322compose '^' 'i' to 'î'
323compose '"' 'I' to 'Ï'
324compose '"' 'i' to 'ï'
325compose '-' 'D' to 'Ð'
326compose '-' 'd' to 'ð'
327compose '~' 'N' to 'Ñ'
328compose '~' 'n' to 'ñ'
329compose '`' 'O' to 'Ò'
330compose '`' 'o' to 'ò'
331compose '\'' 'O' to 'Ó'
332compose '\'' 'o' to 'ó'
333compose '^' 'O' to 'Ô'
334compose '^' 'o' to 'ô'
335compose '~' 'O' to 'Õ'
336compose '~' 'o' to 'õ'
337compose '"' 'O' to 'Ö'
338compose '"' 'o' to 'ö'
339compose '/' 'O' to 'Ø'
340compose '/' 'o' to 'ø'
341compose '`' 'U' to 'Ù'
342compose '`' 'u' to 'ù'
343compose '\'' 'U' to 'Ú'
344compose '\'' 'u' to 'ú'
345compose '^' 'U' to 'Û'
346compose '^' 'u' to 'û'
347compose '"' 'U' to 'Ü'
348compose '"' 'u' to 'ü'
349compose '\'' 'Y' to 'Ý'
350compose '\'' 'y' to 'ý'
351compose 'T' 'H' to 'Þ'
352compose 't' 'h' to 'þ'
353compose 's' 's' to 'ß'
354compose '"' 'y' to 'ÿ'
355compose 's' 'z' to 'ß'
356compose 'i' 'j' to 'ÿ'
diff --git a/drivers/tc/lk201-remap.c b/drivers/tc/lk201-remap.c
new file mode 100644
index 000000000000..d39098c2720e
--- /dev/null
+++ b/drivers/tc/lk201-remap.c
@@ -0,0 +1,172 @@
1/*
2 * Keyboard mappings for DEC LK201/401/501 keyboards
3 *
4 * 17.05.99 Michael Engel (engel@unix-ag.org)
5 *
6 * DEC US keyboards generate keycodes in the range 0x55 - 0xfb
7 *
8 * This conflicts with Linux scancode conventions which define
9 * 0x00-0x7f as "normal" and 0x80-0xff as "shifted" scancodes, so we
10 * have to remap the keycodes to 0x00-0x7f with the scancodeRemap
11 * array. The generated scancode is simply the number of the key counted
12 * from the left upper to the right lower corner of the keyboard ...
13 *
14 * These scancodes are then being remapped (I hope ;-)) with the
15 * lk501*map[] arrays which define scancode -> Linux code mapping
16 *
17 * Oh man is this horrible ;-)
18 *
19 * Scancodes with dual labels exist for keyboards as follows:
20 *
21 * code: left label / right label
22 *
23 * 0x73: LKx01, LK421 / LK443, LK444
24 * 0x74: LKx01, LK421 / LK443, LK444
25 * 0x7c: LKx01, LK421 / LK443, LK444
26 * 0x8a: LKx01, LK421 / LK443, LK444
27 * 0x8b: LKx01, LK421 / LK443, LK444
28 * 0x8c: LKx01, LK421 / LK443, LK444
29 * 0x8d: LKx01, LK421 / LK443, LK444
30 * 0x8e: LKx01, LK421 / LK443, LK444
31 * 0x8f: LKx01, LK421 / LK443, LK444
32 * 0x9c: LKx01, LK421 / LK443, LK444
33 * 0xa1: LKx01, LK421 / LK443, LK444
34 * 0xa2: LKx01, LK421 / LK443, LK444
35 * 0xa3: LKx01, LK421 / LK443, LK444
36 * 0xa4: LKx01, LK421 / LK443, LK444
37 * 0xad: LK421 / LK443, LK444
38 * 0xc9: LKx01, LK421, LK443 / LK444
39 * 0xf7: LKx01, LK443 / LK444
40 */
41
42unsigned char scancodeRemap[256] = {
43/* ----- */
44/* 0 */ 0, 0, 0, 0,
45/* ----- */
46/* 4 */ 0, 0, 0, 0,
47/* ----- */
48/* 8 */ 0, 0, 0, 0,
49/* ----- */
50/* c */ 0, 0, 0, 0,
51/* ----- */
52/* 10 */ 0, 0, 0, 0,
53/* ----- */
54/* 14 */ 0, 0, 0, 0,
55/* ----- */
56/* 18 */ 0, 0, 0, 0,
57/* ----- */
58/* 1c */ 0, 0, 0, 0,
59/* ----- */
60/* 20 */ 0, 0, 0, 0,
61/* ----- */
62/* 24 */ 0, 0, 0, 0,
63/* ----- */
64/* 28 */ 0, 0, 0, 0,
65/* ----- */
66/* 2c */ 0, 0, 0, 0,
67/* ----- */
68/* 30 */ 0, 0, 0, 0,
69/* ----- */
70/* 34 */ 0, 0, 0, 0,
71/* ----- */
72/* 38 */ 0, 0, 0, 0,
73/* ----- */
74/* 3c */ 0, 0, 0, 0,
75/* ----- */
76/* 40 */ 0, 0, 0, 0,
77/* ----- */
78/* 44 */ 0, 0, 0, 0,
79/* ----- */
80/* 48 */ 0, 0, 0, 0,
81/* ----- */
82/* 4c */ 0, 0, 0, 0,
83/* ----- */
84/* 50 */ 0, 0, 0, 0,
85/* ----- ESC F1 F2 */
86/* 54 */ 0, 0, 0x01, 0x02,
87/* ----- F3 F4 F5 */
88/* 58 */ 0x03, 0x04, 0x05, 0,
89/* ----- */
90/* 5c */ 0, 0, 0, 0,
91/* ----- */
92/* 60 */ 0, 0, 0, 0,
93/* ----- F6 F7 F8 F9 */
94/* 64 */ 0x06, 0x07, 0x08, 0x09,
95/* ----- F10 */
96/* 68 */ 0x0a, 0, 0, 0,
97/* ----- */
98/* 6c */ 0, 0, 0, 0,
99/* ----- F11 F12 F13/PRNT SCRN */
100/* 70 */ 0, 0x0b, 0x0c, 0x0d,
101/* ----- F14/SCRL LCK */
102/* 74 */ 0x0e, 0, 0, 0,
103/* ----- */
104/* 78 */ 0, 0, 0, 0,
105/* ----- HELP/PAUSE DO */
106/* 7c */ 0x0f, 0x10, 0, 0,
107/* ----- F17 F18 F19 F20 */
108/* 80 */ 0x11, 0x12, 0x13, 0x14,
109/* ----- */
110/* 84 */ 0, 0, 0, 0,
111/* ----- FIND/INSERT INSERT/HOME */
112/* 88 */ 0, 0, 0x23, 0x24,
113/* ----- REMOVE/PG UP SELECT/DELETE PREVIOUS/END NEXT/PG DN */
114/* 8c */ 0x25, 0x38, 0x39, 0x3a,
115/* ----- KP 0 */
116/* 90 */ 0, 0, 0x6b, 0,
117/* ----- KP . KP ENTER KP 1 KP 2 */
118/* 94 */ 0x6c, 0x65, 0x62, 0x63,
119/* ----- KP 3 KP 4 KP 5 KP 6 */
120/* 98 */ 0x64, 0x4e, 0x4f, 0x50,
121/* ----- KP ,/KP + KP 7 KP 8 KP 9 */
122/* 9c */ 0x51, 0x3b, 0x3c, 0x3d,
123/* ----- KP - KP F1/NUM LCK KP F2/KP / KP F3/KP * */
124/* a0 */ 0x3e, 0x26, 0x27, 0x28,
125/* ----- KP F4/KP - LEFT */
126/* a4 */ 0x29, 0, 0, 0x5f,
127/* ----- RIGHT DOWN UP SHIFT Rt */
128/* a8 */ 0x61, 0x60, 0x4d, 0x5e,
129/* ----- ALT COMP Rt/CTRL Rt SHIFT CONTROL */
130/* ac */ 0, 0, 0x52, 0x3f,
131/* ----- CAPS COMPOSE ALT Rt */
132/* b0 */ 0x40, 0x67, 0, 0,
133/* ----- */
134/* b4 */ 0, 0, 0, 0,
135/* ----- */
136/* b8 */ 0, 0, 0, 0,
137/* ----- BKSP RET TAB ` */
138/* bc */ 0x22, 0x37, 0x2a, 0x15,
139/* ----- 1 q a z */
140/* c0 */ 0x16, 0x2b, 0x41, 0x54,
141/* ----- 2 w s */
142/* c4 */ 0, 0x17, 0x2c, 0x42,
143/* ----- x </\\ 3 */
144/* c8 */ 0x55, 0x53, 0, 0x18,
145/* ----- e d c */
146/* cc */ 0x2d, 0x43, 0x56, 0,
147/* ----- 4 r f v */
148/* d0 */ 0x19, 0x2e, 0x44, 0x57,
149/* ----- SPACE 5 t */
150/* d4 */ 0x68, 0, 0x1a, 0x2f,
151/* ----- g b 6 */
152/* d8 */ 0x45, 0x58, 0, 0x1b,
153/* ----- y h n */
154/* dc */ 0x30, 0x46, 0x59, 0,
155/* ----- 7 u j m */
156/* e0 */ 0x1c, 0x31, 0x47, 0x5a,
157/* ----- 8 i k */
158/* e4 */ 0, 0x1d, 0x32, 0x48,
159/* ----- , 9 o */
160/* e8 */ 0x5b, 0, 0x1e, 0x33,
161/* ----- l . 0 */
162/* ec */ 0x49, 0x5c, 0, 0x1f,
163/* ----- p ; / */
164/* f0 */ 0x34, 0, 0x4a, 0x5d,
165/* ----- = ] \\/\' */
166/* f4 */ 0, 0x21, 0x36, 0x4c,
167/* ----- - [ \' */
168/* f8 */ 0, 0x20, 0x35, 0x4b,
169/* ----- */
170/* fc */ 0, 0, 0, 0,
171};
172
diff --git a/drivers/tc/lk201.c b/drivers/tc/lk201.c
new file mode 100644
index 000000000000..cf10d5cdfb93
--- /dev/null
+++ b/drivers/tc/lk201.c
@@ -0,0 +1,441 @@
1/*
2 *
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
5 * for more details.
6 *
7 * Copyright (C) 1999-2002 Harald Koerfgen <hkoerfg@web.de>
8 * Copyright (C) 2001, 2002, 2003, 2004 Maciej W. Rozycki
9 */
10
11#include <linux/config.h>
12
13#include <linux/errno.h>
14#include <linux/sched.h>
15#include <linux/tty.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/kbd_ll.h>
20#include <linux/kbd_kern.h>
21#include <linux/vt_kern.h>
22
23#include <asm/keyboard.h>
24#include <asm/dec/tc.h>
25#include <asm/dec/machtype.h>
26#include <asm/dec/serial.h>
27
28#include "lk201.h"
29
30/*
31 * Only handle DECstations that have an LK201 interface.
32 * Maxine uses LK501 at the Access.Bus and various DECsystems
33 * have no keyboard interface at all.
34 */
35#define LK_IFACE (mips_machtype == MACH_DS23100 || \
36 mips_machtype == MACH_DS5000_200 || \
37 mips_machtype == MACH_DS5000_1XX || \
38 mips_machtype == MACH_DS5000_2X0)
39/*
40 * These use the Z8530 SCC. Others use the DZ11.
41 */
42#define LK_IFACE_ZS (mips_machtype == MACH_DS5000_1XX || \
43 mips_machtype == MACH_DS5000_2X0)
44
45/* Simple translation table for the SysRq keys */
46
47#ifdef CONFIG_MAGIC_SYSRQ
48/*
49 * Actually no translation at all, at least until we figure out
50 * how to define SysRq for LK201 and friends. --macro
51 */
52unsigned char lk201_sysrq_xlate[128];
53unsigned char *kbd_sysrq_xlate = lk201_sysrq_xlate;
54
55unsigned char kbd_sysrq_key = -1;
56#endif
57
58#define KEYB_LINE 3
59
60static int __init lk201_init(void *);
61static void __init lk201_info(void *);
62static void lk201_rx_char(unsigned char, unsigned char);
63
64static struct dec_serial_hook lk201_hook = {
65 .init_channel = lk201_init,
66 .init_info = lk201_info,
67 .rx_char = NULL,
68 .poll_rx_char = NULL,
69 .poll_tx_char = NULL,
70 .cflags = B4800 | CS8 | CSTOPB | CLOCAL,
71};
72
73/*
74 * This is used during keyboard initialisation
75 */
76static unsigned char lk201_reset_string[] = {
77 LK_CMD_SET_DEFAULTS,
78 LK_CMD_MODE(LK_MODE_RPT_DOWN, 1),
79 LK_CMD_MODE(LK_MODE_RPT_DOWN, 2),
80 LK_CMD_MODE(LK_MODE_RPT_DOWN, 3),
81 LK_CMD_MODE(LK_MODE_RPT_DOWN, 4),
82 LK_CMD_MODE(LK_MODE_DOWN_UP, 5),
83 LK_CMD_MODE(LK_MODE_DOWN_UP, 6),
84 LK_CMD_MODE(LK_MODE_RPT_DOWN, 7),
85 LK_CMD_MODE(LK_MODE_RPT_DOWN, 8),
86 LK_CMD_MODE(LK_MODE_RPT_DOWN, 9),
87 LK_CMD_MODE(LK_MODE_RPT_DOWN, 10),
88 LK_CMD_MODE(LK_MODE_RPT_DOWN, 11),
89 LK_CMD_MODE(LK_MODE_RPT_DOWN, 12),
90 LK_CMD_MODE(LK_MODE_DOWN, 13),
91 LK_CMD_MODE(LK_MODE_RPT_DOWN, 14),
92 LK_CMD_DIS_KEYCLK,
93 LK_CMD_ENB_BELL, LK_PARAM_VOLUME(4),
94};
95
96static void *lk201_handle;
97
98static int lk201_send(unsigned char ch)
99{
100 if (lk201_hook.poll_tx_char(lk201_handle, ch)) {
101 printk(KERN_ERR "lk201: transmit timeout\n");
102 return -EIO;
103 }
104 return 0;
105}
106
107static inline int lk201_get_id(void)
108{
109 return lk201_send(LK_CMD_REQ_ID);
110}
111
112static int lk201_reset(void)
113{
114 int i, r;
115
116 for (i = 0; i < sizeof(lk201_reset_string); i++) {
117 r = lk201_send(lk201_reset_string[i]);
118 if (r < 0)
119 return r;
120 }
121 return 0;
122}
123
124static void lk201_report(unsigned char id[6])
125{
126 char *report = "lk201: keyboard attached, ";
127
128 switch (id[2]) {
129 case LK_STAT_PWRUP_OK:
130 printk(KERN_INFO "%sself-test OK\n", report);
131 break;
132 case LK_STAT_PWRUP_KDOWN:
133 /* The keyboard will resend the power-up ID
134 after all keys are released, so we don't
135 bother handling the error specially. Still
136 there may be a short-circuit inside.
137 */
138 printk(KERN_ERR "%skey down (stuck?), code: 0x%02x\n",
139 report, id[3]);
140 break;
141 case LK_STAT_PWRUP_ERROR:
142 printk(KERN_ERR "%sself-test failure\n", report);
143 break;
144 default:
145 printk(KERN_ERR "%sunknown error: 0x%02x\n",
146 report, id[2]);
147 }
148}
149
150static void lk201_id(unsigned char id[6])
151{
152 /*
153 * Report whether there is an LK201 or an LK401
154 * The LK401 has ALT keys...
155 */
156 switch (id[4]) {
157 case 1:
158 printk(KERN_INFO "lk201: LK201 detected\n");
159 break;
160 case 2:
161 printk(KERN_INFO "lk201: LK401 detected\n");
162 break;
163 case 3:
164 printk(KERN_INFO "lk201: LK443 detected\n");
165 break;
166 case 4:
167 printk(KERN_INFO "lk201: LK421 detected\n");
168 break;
169 default:
170 printk(KERN_WARNING
171 "lk201: unknown keyboard detected, ID %d\n", id[4]);
172 printk(KERN_WARNING "lk201: ... please report to "
173 "<linux-mips@linux-mips.org>\n");
174 }
175}
176
177#define DEFAULT_KEYB_REP_DELAY (250/5) /* [5ms] */
178#define DEFAULT_KEYB_REP_RATE 30 /* [cps] */
179
180static struct kbd_repeat kbdrate = {
181 DEFAULT_KEYB_REP_DELAY,
182 DEFAULT_KEYB_REP_RATE
183};
184
185static void parse_kbd_rate(struct kbd_repeat *r)
186{
187 if (r->delay <= 0)
188 r->delay = kbdrate.delay;
189 if (r->rate <= 0)
190 r->rate = kbdrate.rate;
191
192 if (r->delay < 5)
193 r->delay = 5;
194 if (r->delay > 630)
195 r->delay = 630;
196 if (r->rate < 12)
197 r->rate = 12;
198 if (r->rate > 127)
199 r->rate = 127;
200 if (r->rate == 125)
201 r->rate = 124;
202}
203
204static int write_kbd_rate(struct kbd_repeat *rep)
205{
206 int delay, rate;
207 int i;
208
209 delay = rep->delay / 5;
210 rate = rep->rate;
211 for (i = 0; i < 4; i++) {
212 if (lk201_hook.poll_tx_char(lk201_handle,
213 LK_CMD_RPT_RATE(i)))
214 return 1;
215 if (lk201_hook.poll_tx_char(lk201_handle,
216 LK_PARAM_DELAY(delay)))
217 return 1;
218 if (lk201_hook.poll_tx_char(lk201_handle,
219 LK_PARAM_RATE(rate)))
220 return 1;
221 }
222 return 0;
223}
224
225static int lk201_kbd_rate(struct kbd_repeat *rep)
226{
227 if (rep == NULL)
228 return -EINVAL;
229
230 parse_kbd_rate(rep);
231
232 if (write_kbd_rate(rep)) {
233 memcpy(rep, &kbdrate, sizeof(struct kbd_repeat));
234 return -EIO;
235 }
236
237 memcpy(&kbdrate, rep, sizeof(struct kbd_repeat));
238
239 return 0;
240}
241
242static void lk201_kd_mksound(unsigned int hz, unsigned int ticks)
243{
244 if (!ticks)
245 return;
246
247 /*
248 * Can't set frequency and we "approximate"
249 * duration by volume. ;-)
250 */
251 ticks /= HZ / 32;
252 if (ticks > 7)
253 ticks = 7;
254 ticks = 7 - ticks;
255
256 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_ENB_BELL))
257 return;
258 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_VOLUME(ticks)))
259 return;
260 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_BELL))
261 return;
262}
263
264void kbd_leds(unsigned char leds)
265{
266 unsigned char l = 0;
267
268 if (!lk201_handle) /* FIXME */
269 return;
270
271 /* FIXME -- Only Hold and Lock LEDs for now. --macro */
272 if (leds & LED_SCR)
273 l |= LK_LED_HOLD;
274 if (leds & LED_CAP)
275 l |= LK_LED_LOCK;
276
277 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_LEDS_ON))
278 return;
279 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_LED_MASK(l)))
280 return;
281 if (lk201_hook.poll_tx_char(lk201_handle, LK_CMD_LEDS_OFF))
282 return;
283 if (lk201_hook.poll_tx_char(lk201_handle, LK_PARAM_LED_MASK(~l)))
284 return;
285}
286
287int kbd_setkeycode(unsigned int scancode, unsigned int keycode)
288{
289 return -EINVAL;
290}
291
292int kbd_getkeycode(unsigned int scancode)
293{
294 return -EINVAL;
295}
296
297int kbd_translate(unsigned char scancode, unsigned char *keycode,
298 char raw_mode)
299{
300 *keycode = scancode;
301 return 1;
302}
303
304char kbd_unexpected_up(unsigned char keycode)
305{
306 return 0x80;
307}
308
309static void lk201_rx_char(unsigned char ch, unsigned char fl)
310{
311 static unsigned char id[6];
312 static int id_i;
313
314 static int shift_state = 0;
315 static int prev_scancode;
316 unsigned char c = scancodeRemap[ch];
317
318 if (fl != TTY_NORMAL && fl != TTY_OVERRUN) {
319 printk(KERN_ERR "lk201: keyboard receive error: 0x%02x\n", fl);
320 return;
321 }
322
323 /* Assume this is a power-up ID. */
324 if (ch == LK_STAT_PWRUP_ID && !id_i) {
325 id[id_i++] = ch;
326 return;
327 }
328
329 /* Handle the power-up sequence. */
330 if (id_i) {
331 id[id_i++] = ch;
332 if (id_i == 4) {
333 /* OK, the power-up concluded. */
334 lk201_report(id);
335 if (id[2] == LK_STAT_PWRUP_OK)
336 lk201_get_id();
337 else {
338 id_i = 0;
339 printk(KERN_ERR "lk201: keyboard power-up "
340 "error, skipping initialization\n");
341 }
342 } else if (id_i == 6) {
343 /* We got the ID; report it and start operation. */
344 id_i = 0;
345 lk201_id(id);
346 lk201_reset();
347 }
348 return;
349 }
350
351 /* Everything else is a scancode/status response. */
352 id_i = 0;
353 switch (ch) {
354 case LK_STAT_RESUME_ERR:
355 case LK_STAT_ERROR:
356 case LK_STAT_INHIBIT_ACK:
357 case LK_STAT_TEST_ACK:
358 case LK_STAT_MODE_KEYDOWN:
359 case LK_STAT_MODE_ACK:
360 break;
361 case LK_KEY_LOCK:
362 shift_state ^= LK_LOCK;
363 handle_scancode(c, (shift_state & LK_LOCK) ? 1 : 0);
364 break;
365 case LK_KEY_SHIFT:
366 shift_state ^= LK_SHIFT;
367 handle_scancode(c, (shift_state & LK_SHIFT) ? 1 : 0);
368 break;
369 case LK_KEY_CTRL:
370 shift_state ^= LK_CTRL;
371 handle_scancode(c, (shift_state & LK_CTRL) ? 1 : 0);
372 break;
373 case LK_KEY_COMP:
374 shift_state ^= LK_COMP;
375 handle_scancode(c, (shift_state & LK_COMP) ? 1 : 0);
376 break;
377 case LK_KEY_RELEASE:
378 if (shift_state & LK_SHIFT)
379 handle_scancode(scancodeRemap[LK_KEY_SHIFT], 0);
380 if (shift_state & LK_CTRL)
381 handle_scancode(scancodeRemap[LK_KEY_CTRL], 0);
382 if (shift_state & LK_COMP)
383 handle_scancode(scancodeRemap[LK_KEY_COMP], 0);
384 if (shift_state & LK_LOCK)
385 handle_scancode(scancodeRemap[LK_KEY_LOCK], 0);
386 shift_state = 0;
387 break;
388 case LK_KEY_REPEAT:
389 handle_scancode(prev_scancode, 1);
390 break;
391 default:
392 prev_scancode = c;
393 handle_scancode(c, 1);
394 break;
395 }
396 tasklet_schedule(&keyboard_tasklet);
397}
398
399static void __init lk201_info(void *handle)
400{
401}
402
403static int __init lk201_init(void *handle)
404{
405 /* First install handlers. */
406 lk201_handle = handle;
407 kbd_rate = lk201_kbd_rate;
408 kd_mksound = lk201_kd_mksound;
409
410 lk201_hook.rx_char = lk201_rx_char;
411
412 /* Then just issue a reset -- the handlers will do the rest. */
413 lk201_send(LK_CMD_POWER_UP);
414
415 return 0;
416}
417
418void __init kbd_init_hw(void)
419{
420 /* Maxine uses LK501 at the Access.Bus. */
421 if (!LK_IFACE)
422 return;
423
424 printk(KERN_INFO "lk201: DECstation LK keyboard driver v0.05.\n");
425
426 if (LK_IFACE_ZS) {
427 /*
428 * kbd_init_hw() is being called before
429 * rs_init() so just register the kbd hook
430 * and let zs_init do the rest :-)
431 */
432 if (!register_dec_serial_hook(KEYB_LINE, &lk201_hook))
433 unregister_dec_serial_hook(KEYB_LINE);
434 } else {
435 /*
436 * TODO: modify dz.c to allow similar hooks
437 * for LK201 handling on DS2100, DS3100, and DS5000/200
438 */
439 printk(KERN_ERR "lk201: support for DZ11 not yet ready.\n");
440 }
441}
diff --git a/drivers/tc/lk201.h b/drivers/tc/lk201.h
new file mode 100644
index 000000000000..99f3203c41b8
--- /dev/null
+++ b/drivers/tc/lk201.h
@@ -0,0 +1,125 @@
1/*
2 * Commands to the keyboard processor
3 */
4
5#define LK_PARAM 0x80 /* start/end parameter list */
6
7#define LK_CMD_RESUME 0x8b /* resume transmission to the host */
8#define LK_CMD_INHIBIT 0x89 /* stop transmission to the host */
9#define LK_CMD_LEDS_ON 0x13 /* light LEDs */
10 /* 1st param: led bitmask */
11#define LK_CMD_LEDS_OFF 0x11 /* turn off LEDs */
12 /* 1st param: led bitmask */
13#define LK_CMD_DIS_KEYCLK 0x99 /* disable the keyclick */
14#define LK_CMD_ENB_KEYCLK 0x1b /* enable the keyclick */
15 /* 1st param: volume */
16#define LK_CMD_DIS_CTLCLK 0xb9 /* disable the Ctrl keyclick */
17#define LK_CMD_ENB_CTLCLK 0xbb /* enable the Ctrl keyclick */
18#define LK_CMD_SOUND_CLK 0x9f /* emit a keyclick */
19#define LK_CMD_DIS_BELL 0xa1 /* disable the bell */
20#define LK_CMD_ENB_BELL 0x23 /* enable the bell */
21 /* 1st param: volume */
22#define LK_CMD_BELL 0xa7 /* emit a bell */
23#define LK_CMD_TMP_NORPT 0xd1 /* disable typematic */
24 /* for the currently pressed key */
25#define LK_CMD_ENB_RPT 0xe3 /* enable typematic */
26 /* for RPT_DOWN groups */
27#define LK_CMD_DIS_RPT 0xe1 /* disable typematic */
28 /* for RPT_DOWN groups */
29#define LK_CMD_RPT_TO_DOWN 0xd9 /* set RPT_DOWN groups to DOWN */
30#define LK_CMD_REQ_ID 0xab /* request the keyboard ID */
31#define LK_CMD_POWER_UP 0xfd /* init power-up sequence */
32#define LK_CMD_TEST_MODE 0xcb /* enter the factory test mode */
33#define LK_CMD_TEST_EXIT 0x80 /* exit the factory test mode */
34#define LK_CMD_SET_DEFAULTS 0xd3 /* set power-up defaults */
35
36#define LK_CMD_MODE(m,div) (LK_PARAM|(((div)&0xf)<<3)|(((m)&0x3)<<1))
37 /* select the repeat mode */
38 /* for the selected key group */
39#define LK_CMD_MODE_AR(m,div) ((((div)&0xf)<<3)|(((m)&0x3)<<1))
40 /* select the repeat mode */
41 /* and the repeat register */
42 /* for the selected key group */
43 /* 1st param: register number */
44#define LK_CMD_RPT_RATE(r) (0x78|(((r)&0x3)<<1))
45 /* set the delay and repeat rate */
46 /* for the selected repeat register */
47 /* 1st param: initial delay */
48 /* 2nd param: repeat rate */
49
50/* there are 4 leds, represent them in the low 4 bits of a byte */
51#define LK_PARAM_LED_MASK(ledbmap) (LK_PARAM|((ledbmap)&0xf))
52#define LK_LED_WAIT 0x1 /* Wait LED */
53#define LK_LED_COMP 0x2 /* Compose LED */
54#define LK_LED_LOCK 0x4 /* Lock LED */
55#define LK_LED_HOLD 0x8 /* Hold Screen LED */
56
57/* max volume is 0, lowest is 0x7 */
58#define LK_PARAM_VOLUME(v) (LK_PARAM|((v)&0x7))
59
60/* mode set command details, div is a key group number */
61#define LK_MODE_DOWN 0x0 /* make only */
62#define LK_MODE_RPT_DOWN 0x1 /* make and typematic */
63#define LK_MODE_DOWN_UP 0x3 /* make and release */
64
65/* there are 4 repeat registers */
66#define LK_PARAM_AR(r) (LK_PARAM|((v)&0x3))
67
68/*
69 * Mappings between key groups and keycodes are as follows:
70 *
71 * 1: 0xbf - 0xff -- alphanumeric,
72 * 2: 0x91 - 0xa5 -- numeric keypad,
73 * 3: 0xbc -- Backspace,
74 * 4: 0xbd - 0xbe -- Tab, Return,
75 * 5: 0xb0 - 0xb2 -- Lock, Compose Character,
76 * 6: 0xad - 0xaf -- Ctrl, Shift,
77 * 7: 0xa6 - 0xa8 -- Left Arrow, Right Arrow,
78 * 8: 0xa9 - 0xac -- Up Arrow, Down Arrow, Right Shift,
79 * 9: 0x88 - 0x90 -- editor keypad,
80 * 10: 0x56 - 0x62 -- F1 - F5,
81 * 11: 0x63 - 0x6e -- F6 - F10,
82 * 12: 0x6f - 0x7a -- F11 - F14,
83 * 13: 0x7b - 0x7d -- Help, Do,
84 * 14: 0x7e - 0x87 -- F17 - F20.
85 *
86 * Notes:
87 * 1. Codes in the 0x00 - 0x40 range are reserved.
88 * 2. The assignment of the 0x41 - 0x55 range is undiscovered, probably 10.
89 */
90
91/* delay is 5 - 630 ms; 0x00 and 0x7f are reserved */
92#define LK_PARAM_DELAY(t) ((t)&0x7f)
93
94/* rate is 12 - 127 Hz; 0x00 - 0x0b and 0x7d (power-up!) are reserved */
95#define LK_PARAM_RATE(r) (LK_PARAM|((r)&0x7f))
96
97#define LK_SHIFT 1<<0
98#define LK_CTRL 1<<1
99#define LK_LOCK 1<<2
100#define LK_COMP 1<<3
101
102#define LK_KEY_SHIFT 0xae
103#define LK_KEY_CTRL 0xaf
104#define LK_KEY_LOCK 0xb0
105#define LK_KEY_COMP 0xb1
106
107#define LK_KEY_RELEASE 0xb3 /* all keys released */
108#define LK_KEY_REPEAT 0xb4 /* repeat the last key */
109
110/* status responses */
111#define LK_STAT_RESUME_ERR 0xb5 /* keystrokes lost while inhibited */
112#define LK_STAT_ERROR 0xb6 /* an invalid command received */
113#define LK_STAT_INHIBIT_ACK 0xb7 /* transmission inhibited */
114#define LK_STAT_TEST_ACK 0xb8 /* the factory test mode entered */
115#define LK_STAT_MODE_KEYDOWN 0xb9 /* a key is down on a change */
116 /* to the DOWN_UP mode; */
117 /* the keycode follows */
118#define LK_STAT_MODE_ACK 0xba /* the mode command succeeded */
119
120#define LK_STAT_PWRUP_ID 0x01 /* the power-up response start mark */
121#define LK_STAT_PWRUP_OK 0x00 /* the power-up self test OK */
122#define LK_STAT_PWRUP_KDOWN 0x3d /* a key was down during the test */
123#define LK_STAT_PWRUP_ERROR 0x3e /* keyboard self test failure */
124
125extern unsigned char scancodeRemap[256];
diff --git a/drivers/tc/tc.c b/drivers/tc/tc.c
new file mode 100644
index 000000000000..a89ef4df80c3
--- /dev/null
+++ b/drivers/tc/tc.c
@@ -0,0 +1,260 @@
1/*
2 * tc-init: We assume the TURBOchannel to be up and running so
3 * just probe for Modules and fill in the global data structure
4 * tc_bus.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 *
10 * Copyright (c) Harald Koerfgen, 1998
11 * Copyright (c) 2001, 2003 Maciej W. Rozycki
12 */
13#include <linux/string.h>
14#include <linux/init.h>
15#include <linux/ioport.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18
19#include <asm/addrspace.h>
20#include <asm/errno.h>
21#include <asm/dec/machtype.h>
22#include <asm/dec/prom.h>
23#include <asm/dec/tcinfo.h>
24#include <asm/dec/tcmodule.h>
25#include <asm/dec/interrupts.h>
26#include <asm/paccess.h>
27#include <asm/ptrace.h>
28
29#define TC_DEBUG
30
31MODULE_LICENSE("GPL");
32slot_info tc_bus[MAX_SLOT];
33static int num_tcslots;
34static tcinfo *info;
35
36unsigned long system_base;
37
38/*
39 * Interface to the world. Read comment in include/asm-mips/tc.h.
40 */
41
42int search_tc_card(const char *name)
43{
44 int slot;
45 slot_info *sip;
46
47 for (slot = 0; slot < num_tcslots; slot++) {
48 sip = &tc_bus[slot];
49 if ((sip->flags & FREE) &&
50 (strncmp(sip->name, name, strlen(name)) == 0)) {
51 return slot;
52 }
53 }
54
55 return -ENODEV;
56}
57
58void claim_tc_card(int slot)
59{
60 if (tc_bus[slot].flags & IN_USE) {
61 printk("claim_tc_card: attempting to claim a card already in use\n");
62 return;
63 }
64 tc_bus[slot].flags &= ~FREE;
65 tc_bus[slot].flags |= IN_USE;
66}
67
68void release_tc_card(int slot)
69{
70 if (tc_bus[slot].flags & FREE) {
71 printk("release_tc_card: "
72 "attempting to release a card already free\n");
73 return;
74 }
75 tc_bus[slot].flags &= ~IN_USE;
76 tc_bus[slot].flags |= FREE;
77}
78
79unsigned long get_tc_base_addr(int slot)
80{
81 return tc_bus[slot].base_addr;
82}
83
84unsigned long get_tc_irq_nr(int slot)
85{
86 return tc_bus[slot].interrupt;
87}
88
89unsigned long get_tc_speed(void)
90{
91 return 100000 * (10000 / (unsigned long)info->clk_period);
92}
93
94/*
95 * Probing for TURBOchannel modules
96 */
97static void __init tc_probe(unsigned long startaddr, unsigned long size,
98 int slots)
99{
100 int i, slot, err;
101 long offset;
102 unsigned char pattern[4];
103 unsigned char *module;
104
105 for (slot = 0; slot < slots; slot++) {
106 module = (char *)(startaddr + slot * size);
107
108 offset = OLDCARD;
109
110 err = 0;
111 err |= get_dbe(pattern[0], module + OLDCARD + TC_PATTERN0);
112 err |= get_dbe(pattern[1], module + OLDCARD + TC_PATTERN1);
113 err |= get_dbe(pattern[2], module + OLDCARD + TC_PATTERN2);
114 err |= get_dbe(pattern[3], module + OLDCARD + TC_PATTERN3);
115 if (err)
116 continue;
117
118 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
119 pattern[2] != 0xaa || pattern[3] != 0xff) {
120 offset = NEWCARD;
121
122 err = 0;
123 err |= get_dbe(pattern[0], module + TC_PATTERN0);
124 err |= get_dbe(pattern[1], module + TC_PATTERN1);
125 err |= get_dbe(pattern[2], module + TC_PATTERN2);
126 err |= get_dbe(pattern[3], module + TC_PATTERN3);
127 if (err)
128 continue;
129 }
130
131 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
132 pattern[2] != 0xaa || pattern[3] != 0xff)
133 continue;
134
135 tc_bus[slot].base_addr = (unsigned long)module;
136 for(i = 0; i < 8; i++) {
137 tc_bus[slot].firmware[i] =
138 module[TC_FIRM_VER + offset + 4 * i];
139 tc_bus[slot].vendor[i] =
140 module[TC_VENDOR + offset + 4 * i];
141 tc_bus[slot].name[i] =
142 module[TC_MODULE + offset + 4 * i];
143 }
144 tc_bus[slot].firmware[8] = 0;
145 tc_bus[slot].vendor[8] = 0;
146 tc_bus[slot].name[8] = 0;
147 /*
148 * Looks unneccesary, but we may change
149 * TC? in the future
150 */
151 switch (slot) {
152 case 0:
153 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC0];
154 break;
155 case 1:
156 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC1];
157 break;
158 case 2:
159 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC2];
160 break;
161 /*
162 * Yuck! DS5000/200 onboard devices
163 */
164 case 5:
165 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC5];
166 break;
167 case 6:
168 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC6];
169 break;
170 default:
171 tc_bus[slot].interrupt = -1;
172 break;
173 }
174 }
175}
176
177/*
178 * the main entry
179 */
180void __init tc_init(void)
181{
182 int tc_clock;
183 int i;
184 unsigned long slot0addr;
185 unsigned long slot_size;
186
187 if (!TURBOCHANNEL)
188 return;
189
190 for (i = 0; i < MAX_SLOT; i++) {
191 tc_bus[i].base_addr = 0;
192 tc_bus[i].name[0] = 0;
193 tc_bus[i].vendor[0] = 0;
194 tc_bus[i].firmware[0] = 0;
195 tc_bus[i].interrupt = -1;
196 tc_bus[i].flags = FREE;
197 }
198
199 info = (tcinfo *) rex_gettcinfo();
200 slot0addr = (unsigned long)KSEG1ADDR(rex_slot_address(0));
201
202 switch (mips_machtype) {
203 case MACH_DS5000_200:
204 num_tcslots = 7;
205 break;
206 case MACH_DS5000_1XX:
207 case MACH_DS5000_2X0:
208 case MACH_DS5900:
209 num_tcslots = 3;
210 break;
211 case MACH_DS5000_XX:
212 default:
213 num_tcslots = 2;
214 break;
215 }
216
217 tc_clock = 10000 / info->clk_period;
218
219 if (TURBOCHANNEL && info->slot_size && slot0addr) {
220 printk("TURBOchannel rev. %1d at %2d.%1d MHz ", info->revision,
221 tc_clock / 10, tc_clock % 10);
222 printk("(with%s parity)\n", info->parity ? "" : "out");
223
224 slot_size = info->slot_size << 20;
225
226 tc_probe(slot0addr, slot_size, num_tcslots);
227
228 /*
229 * All TURBOchannel DECstations have the onboard devices
230 * where the (num_tcslots + 0 or 1 on DS5k/xx) Option Module
231 * would be.
232 */
233 if(mips_machtype == MACH_DS5000_XX)
234 i = 1;
235 else
236 i = 0;
237
238 system_base = slot0addr + slot_size * (num_tcslots + i);
239
240#ifdef TC_DEBUG
241 for (i = 0; i < num_tcslots; i++)
242 if (tc_bus[i].base_addr) {
243 printk(" slot %d: ", i);
244 printk("%s %s %s\n", tc_bus[i].vendor,
245 tc_bus[i].name, tc_bus[i].firmware);
246 }
247#endif
248 ioport_resource.end = KSEG2 - 1;
249 }
250}
251
252subsys_initcall(tc_init);
253
254EXPORT_SYMBOL(search_tc_card);
255EXPORT_SYMBOL(claim_tc_card);
256EXPORT_SYMBOL(release_tc_card);
257EXPORT_SYMBOL(get_tc_base_addr);
258EXPORT_SYMBOL(get_tc_irq_nr);
259EXPORT_SYMBOL(get_tc_speed);
260EXPORT_SYMBOL(system_base);
diff --git a/drivers/tc/zs.c b/drivers/tc/zs.c
new file mode 100644
index 000000000000..4382ee60b6a8
--- /dev/null
+++ b/drivers/tc/zs.c
@@ -0,0 +1,2253 @@
1/*
2 * decserial.c: Serial port driver for IOASIC DECstations.
3 *
4 * Derived from drivers/sbus/char/sunserial.c by Paul Mackerras.
5 * Derived from drivers/macintosh/macserial.c by Harald Koerfgen.
6 *
7 * DECstation changes
8 * Copyright (C) 1998-2000 Harald Koerfgen
9 * Copyright (C) 2000, 2001, 2002, 2003, 2004 Maciej W. Rozycki
10 *
11 * For the rest of the code the original Copyright applies:
12 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
13 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
14 *
15 *
16 * Note: for IOASIC systems the wiring is as follows:
17 *
18 * mouse/keyboard:
19 * DIN-7 MJ-4 signal SCC
20 * 2 1 TxD <- A.TxD
21 * 3 4 RxD -> A.RxD
22 *
23 * EIA-232/EIA-423:
24 * DB-25 MMJ-6 signal SCC
25 * 2 2 TxD <- B.TxD
26 * 3 5 RxD -> B.RxD
27 * 4 RTS <- ~A.RTS
28 * 5 CTS -> ~B.CTS
29 * 6 6 DSR -> ~A.SYNC
30 * 8 CD -> ~B.DCD
31 * 12 DSRS(DCE) -> ~A.CTS (*)
32 * 15 TxC -> B.TxC
33 * 17 RxC -> B.RxC
34 * 20 1 DTR <- ~A.DTR
35 * 22 RI -> ~A.DCD
36 * 23 DSRS(DTE) <- ~B.RTS
37 *
38 * (*) EIA-232 defines the signal at this pin to be SCD, while DSRS(DCE)
39 * is shared with DSRS(DTE) at pin 23.
40 */
41
42#include <linux/config.h>
43#include <linux/errno.h>
44#include <linux/signal.h>
45#include <linux/sched.h>
46#include <linux/timer.h>
47#include <linux/interrupt.h>
48#include <linux/tty.h>
49#include <linux/tty_flip.h>
50#include <linux/major.h>
51#include <linux/string.h>
52#include <linux/fcntl.h>
53#include <linux/mm.h>
54#include <linux/kernel.h>
55#include <linux/delay.h>
56#include <linux/init.h>
57#include <linux/ioport.h>
58#ifdef CONFIG_SERIAL_DEC_CONSOLE
59#include <linux/console.h>
60#endif
61
62#include <asm/io.h>
63#include <asm/pgtable.h>
64#include <asm/irq.h>
65#include <asm/system.h>
66#include <asm/uaccess.h>
67#include <asm/bootinfo.h>
68#include <asm/dec/serial.h>
69
70#ifdef CONFIG_MACH_DECSTATION
71#include <asm/dec/interrupts.h>
72#include <asm/dec/machtype.h>
73#include <asm/dec/tc.h>
74#include <asm/dec/ioasic_addrs.h>
75#endif
76#ifdef CONFIG_KGDB
77#include <asm/kgdb.h>
78#endif
79#ifdef CONFIG_MAGIC_SYSRQ
80#include <linux/sysrq.h>
81#endif
82
83#include "zs.h"
84
85/*
86 * It would be nice to dynamically allocate everything that
87 * depends on NUM_SERIAL, so we could support any number of
88 * Z8530s, but for now...
89 */
90#define NUM_SERIAL 2 /* Max number of ZS chips supported */
91#define NUM_CHANNELS (NUM_SERIAL * 2) /* 2 channels per chip */
92#define CHANNEL_A_NR (zs_parms->channel_a_offset > zs_parms->channel_b_offset)
93 /* Number of channel A in the chip */
94#define ZS_CHAN_IO_SIZE 8
95#define ZS_CLOCK 7372800 /* Z8530 RTxC input clock rate */
96
97#define RECOVERY_DELAY udelay(2)
98
99struct zs_parms {
100 unsigned long scc0;
101 unsigned long scc1;
102 int channel_a_offset;
103 int channel_b_offset;
104 int irq0;
105 int irq1;
106 int clock;
107};
108
109static struct zs_parms *zs_parms;
110
111#ifdef CONFIG_MACH_DECSTATION
112static struct zs_parms ds_parms = {
113 scc0 : IOASIC_SCC0,
114 scc1 : IOASIC_SCC1,
115 channel_a_offset : 1,
116 channel_b_offset : 9,
117 irq0 : -1,
118 irq1 : -1,
119 clock : ZS_CLOCK
120};
121#endif
122
123#ifdef CONFIG_MACH_DECSTATION
124#define DS_BUS_PRESENT (IOASIC)
125#else
126#define DS_BUS_PRESENT 0
127#endif
128
129#define BUS_PRESENT (DS_BUS_PRESENT)
130
131struct dec_zschannel zs_channels[NUM_CHANNELS];
132struct dec_serial zs_soft[NUM_CHANNELS];
133int zs_channels_found;
134struct dec_serial *zs_chain; /* list of all channels */
135
136struct tty_struct zs_ttys[NUM_CHANNELS];
137
138#ifdef CONFIG_SERIAL_DEC_CONSOLE
139static struct console sercons;
140#endif
141#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
142 !defined(MODULE)
143static unsigned long break_pressed; /* break, really ... */
144#endif
145
146static unsigned char zs_init_regs[16] __initdata = {
147 0, /* write 0 */
148 0, /* write 1 */
149 0, /* write 2 */
150 0, /* write 3 */
151 (X16CLK), /* write 4 */
152 0, /* write 5 */
153 0, 0, 0, /* write 6, 7, 8 */
154 (MIE | DLC | NV), /* write 9 */
155 (NRZ), /* write 10 */
156 (TCBR | RCBR), /* write 11 */
157 0, 0, /* BRG time constant, write 12 + 13 */
158 (BRSRC | BRENABL), /* write 14 */
159 0 /* write 15 */
160};
161
162DECLARE_TASK_QUEUE(tq_zs_serial);
163
164static struct tty_driver *serial_driver;
165
166/* serial subtype definitions */
167#define SERIAL_TYPE_NORMAL 1
168
169/* number of characters left in xmit buffer before we ask for more */
170#define WAKEUP_CHARS 256
171
172/*
173 * Debugging.
174 */
175#undef SERIAL_DEBUG_OPEN
176#undef SERIAL_DEBUG_FLOW
177#undef SERIAL_DEBUG_THROTTLE
178#undef SERIAL_PARANOIA_CHECK
179
180#undef ZS_DEBUG_REGS
181
182#ifdef SERIAL_DEBUG_THROTTLE
183#define _tty_name(tty,buf) tty_name(tty,buf)
184#endif
185
186#define RS_STROBE_TIME 10
187#define RS_ISR_PASS_LIMIT 256
188
189#define _INLINE_ inline
190
191static void probe_sccs(void);
192static void change_speed(struct dec_serial *info);
193static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
194
195/*
196 * tmp_buf is used as a temporary buffer by serial_write. We need to
197 * lock it in case the copy_from_user blocks while swapping in a page,
198 * and some other program tries to do a serial write at the same time.
199 * Since the lock will only come under contention when the system is
200 * swapping and available memory is low, it makes sense to share one
201 * buffer across all the serial ports, since it significantly saves
202 * memory if large numbers of serial ports are open.
203 */
204static unsigned char tmp_buf[4096]; /* This is cheating */
205static DECLARE_MUTEX(tmp_buf_sem);
206
207static inline int serial_paranoia_check(struct dec_serial *info,
208 char *name, const char *routine)
209{
210#ifdef SERIAL_PARANOIA_CHECK
211 static const char *badmagic =
212 "Warning: bad magic number for serial struct %s in %s\n";
213 static const char *badinfo =
214 "Warning: null mac_serial for %s in %s\n";
215
216 if (!info) {
217 printk(badinfo, name, routine);
218 return 1;
219 }
220 if (info->magic != SERIAL_MAGIC) {
221 printk(badmagic, name, routine);
222 return 1;
223 }
224#endif
225 return 0;
226}
227
228/*
229 * This is used to figure out the divisor speeds and the timeouts
230 */
231static int baud_table[] = {
232 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
233 9600, 19200, 38400, 57600, 115200, 0 };
234
235/*
236 * Reading and writing Z8530 registers.
237 */
238static inline unsigned char read_zsreg(struct dec_zschannel *channel,
239 unsigned char reg)
240{
241 unsigned char retval;
242
243 if (reg != 0) {
244 *channel->control = reg & 0xf;
245 fast_iob(); RECOVERY_DELAY;
246 }
247 retval = *channel->control;
248 RECOVERY_DELAY;
249 return retval;
250}
251
252static inline void write_zsreg(struct dec_zschannel *channel,
253 unsigned char reg, unsigned char value)
254{
255 if (reg != 0) {
256 *channel->control = reg & 0xf;
257 fast_iob(); RECOVERY_DELAY;
258 }
259 *channel->control = value;
260 fast_iob(); RECOVERY_DELAY;
261 return;
262}
263
264static inline unsigned char read_zsdata(struct dec_zschannel *channel)
265{
266 unsigned char retval;
267
268 retval = *channel->data;
269 RECOVERY_DELAY;
270 return retval;
271}
272
273static inline void write_zsdata(struct dec_zschannel *channel,
274 unsigned char value)
275{
276 *channel->data = value;
277 fast_iob(); RECOVERY_DELAY;
278 return;
279}
280
281static inline void load_zsregs(struct dec_zschannel *channel,
282 unsigned char *regs)
283{
284/* ZS_CLEARERR(channel);
285 ZS_CLEARFIFO(channel); */
286 /* Load 'em up */
287 write_zsreg(channel, R3, regs[R3] & ~RxENABLE);
288 write_zsreg(channel, R5, regs[R5] & ~TxENAB);
289 write_zsreg(channel, R4, regs[R4]);
290 write_zsreg(channel, R9, regs[R9]);
291 write_zsreg(channel, R1, regs[R1]);
292 write_zsreg(channel, R2, regs[R2]);
293 write_zsreg(channel, R10, regs[R10]);
294 write_zsreg(channel, R11, regs[R11]);
295 write_zsreg(channel, R12, regs[R12]);
296 write_zsreg(channel, R13, regs[R13]);
297 write_zsreg(channel, R14, regs[R14]);
298 write_zsreg(channel, R15, regs[R15]);
299 write_zsreg(channel, R3, regs[R3]);
300 write_zsreg(channel, R5, regs[R5]);
301 return;
302}
303
304/* Sets or clears DTR/RTS on the requested line */
305static inline void zs_rtsdtr(struct dec_serial *info, int which, int set)
306{
307 unsigned long flags;
308
309
310 save_flags(flags); cli();
311 if (info->zs_channel != info->zs_chan_a) {
312 if (set) {
313 info->zs_chan_a->curregs[5] |= (which & (RTS | DTR));
314 } else {
315 info->zs_chan_a->curregs[5] &= ~(which & (RTS | DTR));
316 }
317 write_zsreg(info->zs_chan_a, 5, info->zs_chan_a->curregs[5]);
318 }
319 restore_flags(flags);
320}
321
322/* Utility routines for the Zilog */
323static inline int get_zsbaud(struct dec_serial *ss)
324{
325 struct dec_zschannel *channel = ss->zs_channel;
326 int brg;
327
328 /* The baud rate is split up between two 8-bit registers in
329 * what is termed 'BRG time constant' format in my docs for
330 * the chip, it is a function of the clk rate the chip is
331 * receiving which happens to be constant.
332 */
333 brg = (read_zsreg(channel, 13) << 8);
334 brg |= read_zsreg(channel, 12);
335 return BRG_TO_BPS(brg, (zs_parms->clock/(ss->clk_divisor)));
336}
337
338/* On receive, this clears errors and the receiver interrupts */
339static inline void rs_recv_clear(struct dec_zschannel *zsc)
340{
341 write_zsreg(zsc, 0, ERR_RES);
342 write_zsreg(zsc, 0, RES_H_IUS); /* XXX this is unnecessary */
343}
344
345/*
346 * ----------------------------------------------------------------------
347 *
348 * Here starts the interrupt handling routines. All of the following
349 * subroutines are declared as inline and are folded into
350 * rs_interrupt(). They were separated out for readability's sake.
351 *
352 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
353 * -----------------------------------------------------------------------
354 */
355
356/*
357 * This routine is used by the interrupt handler to schedule
358 * processing in the software interrupt portion of the driver.
359 */
360static _INLINE_ void rs_sched_event(struct dec_serial *info,
361 int event)
362{
363 info->event |= 1 << event;
364 queue_task(&info->tqueue, &tq_zs_serial);
365 mark_bh(SERIAL_BH);
366}
367
368static _INLINE_ void receive_chars(struct dec_serial *info,
369 struct pt_regs *regs)
370{
371 struct tty_struct *tty = info->tty;
372 unsigned char ch, stat, flag;
373
374 while ((read_zsreg(info->zs_channel, R0) & Rx_CH_AV) != 0) {
375
376 stat = read_zsreg(info->zs_channel, R1);
377 ch = read_zsdata(info->zs_channel);
378
379 if (!tty && (!info->hook || !info->hook->rx_char))
380 continue;
381
382 flag = TTY_NORMAL;
383 if (info->tty_break) {
384 info->tty_break = 0;
385 flag = TTY_BREAK;
386 if (info->flags & ZILOG_SAK)
387 do_SAK(tty);
388 /* Ignore the null char got when BREAK is removed. */
389 if (ch == 0)
390 continue;
391 } else {
392 if (stat & Rx_OVR) {
393 flag = TTY_OVERRUN;
394 } else if (stat & FRM_ERR) {
395 flag = TTY_FRAME;
396 } else if (stat & PAR_ERR) {
397 flag = TTY_PARITY;
398 }
399 if (flag != TTY_NORMAL)
400 /* reset the error indication */
401 write_zsreg(info->zs_channel, R0, ERR_RES);
402 }
403
404#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
405 !defined(MODULE)
406 if (break_pressed && info->line == sercons.index) {
407 /* Ignore the null char got when BREAK is removed. */
408 if (ch == 0)
409 continue;
410 if (time_before(jiffies, break_pressed + HZ * 5)) {
411 handle_sysrq(ch, regs, NULL);
412 break_pressed = 0;
413 continue;
414 }
415 break_pressed = 0;
416 }
417#endif
418
419 if (info->hook && info->hook->rx_char) {
420 (*info->hook->rx_char)(ch, flag);
421 return;
422 }
423
424 tty_insert_flip_char(tty, ch, flag);
425 }
426 if (tty)
427 tty_flip_buffer_push(tty);
428}
429
430static void transmit_chars(struct dec_serial *info)
431{
432 if ((read_zsreg(info->zs_channel, R0) & Tx_BUF_EMP) == 0)
433 return;
434 info->tx_active = 0;
435
436 if (info->x_char) {
437 /* Send next char */
438 write_zsdata(info->zs_channel, info->x_char);
439 info->x_char = 0;
440 info->tx_active = 1;
441 return;
442 }
443
444 if ((info->xmit_cnt <= 0) || (info->tty && info->tty->stopped)
445 || info->tx_stopped) {
446 write_zsreg(info->zs_channel, R0, RES_Tx_P);
447 return;
448 }
449 /* Send char */
450 write_zsdata(info->zs_channel, info->xmit_buf[info->xmit_tail++]);
451 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
452 info->xmit_cnt--;
453 info->tx_active = 1;
454
455 if (info->xmit_cnt < WAKEUP_CHARS)
456 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
457}
458
459static _INLINE_ void status_handle(struct dec_serial *info)
460{
461 unsigned char stat;
462
463 /* Get status from Read Register 0 */
464 stat = read_zsreg(info->zs_channel, R0);
465
466 if ((stat & BRK_ABRT) && !(info->read_reg_zero & BRK_ABRT)) {
467#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
468 !defined(MODULE)
469 if (info->line == sercons.index) {
470 if (!break_pressed)
471 break_pressed = jiffies;
472 } else
473#endif
474 info->tty_break = 1;
475 }
476
477 if (info->zs_channel != info->zs_chan_a) {
478
479 /* Check for DCD transitions */
480 if (info->tty && !C_CLOCAL(info->tty) &&
481 ((stat ^ info->read_reg_zero) & DCD) != 0 ) {
482 if (stat & DCD) {
483 wake_up_interruptible(&info->open_wait);
484 } else {
485 tty_hangup(info->tty);
486 }
487 }
488
489 /* Check for CTS transitions */
490 if (info->tty && C_CRTSCTS(info->tty)) {
491 if ((stat & CTS) != 0) {
492 if (info->tx_stopped) {
493 info->tx_stopped = 0;
494 if (!info->tx_active)
495 transmit_chars(info);
496 }
497 } else {
498 info->tx_stopped = 1;
499 }
500 }
501
502 }
503
504 /* Clear status condition... */
505 write_zsreg(info->zs_channel, R0, RES_EXT_INT);
506 info->read_reg_zero = stat;
507}
508
509/*
510 * This is the serial driver's generic interrupt routine
511 */
512void rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
513{
514 struct dec_serial *info = (struct dec_serial *) dev_id;
515 unsigned char zs_intreg;
516 int shift;
517
518 /* NOTE: The read register 3, which holds the irq status,
519 * does so for both channels on each chip. Although
520 * the status value itself must be read from the A
521 * channel and is only valid when read from channel A.
522 * Yes... broken hardware...
523 */
524#define CHAN_IRQMASK (CHBRxIP | CHBTxIP | CHBEXT)
525
526 if (info->zs_chan_a == info->zs_channel)
527 shift = 3; /* Channel A */
528 else
529 shift = 0; /* Channel B */
530
531 for (;;) {
532 zs_intreg = read_zsreg(info->zs_chan_a, R3) >> shift;
533 if ((zs_intreg & CHAN_IRQMASK) == 0)
534 break;
535
536 if (zs_intreg & CHBRxIP) {
537 receive_chars(info, regs);
538 }
539 if (zs_intreg & CHBTxIP) {
540 transmit_chars(info);
541 }
542 if (zs_intreg & CHBEXT) {
543 status_handle(info);
544 }
545 }
546
547 /* Why do we need this ? */
548 write_zsreg(info->zs_channel, 0, RES_H_IUS);
549}
550
551#ifdef ZS_DEBUG_REGS
552void zs_dump (void) {
553 int i, j;
554 for (i = 0; i < zs_channels_found; i++) {
555 struct dec_zschannel *ch = &zs_channels[i];
556 if ((long)ch->control == UNI_IO_BASE+UNI_SCC1A_CTRL) {
557 for (j = 0; j < 15; j++) {
558 printk("W%d = 0x%x\t",
559 j, (int)ch->curregs[j]);
560 }
561 for (j = 0; j < 15; j++) {
562 printk("R%d = 0x%x\t",
563 j, (int)read_zsreg(ch,j));
564 }
565 printk("\n\n");
566 }
567 }
568}
569#endif
570
571/*
572 * -------------------------------------------------------------------
573 * Here ends the serial interrupt routines.
574 * -------------------------------------------------------------------
575 */
576
577/*
578 * ------------------------------------------------------------
579 * rs_stop() and rs_start()
580 *
581 * This routines are called before setting or resetting tty->stopped.
582 * ------------------------------------------------------------
583 */
584static void rs_stop(struct tty_struct *tty)
585{
586 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
587 unsigned long flags;
588
589 if (serial_paranoia_check(info, tty->name, "rs_stop"))
590 return;
591
592#if 1
593 save_flags(flags); cli();
594 if (info->zs_channel->curregs[5] & TxENAB) {
595 info->zs_channel->curregs[5] &= ~TxENAB;
596 write_zsreg(info->zs_channel, 5, info->zs_channel->curregs[5]);
597 }
598 restore_flags(flags);
599#endif
600}
601
602static void rs_start(struct tty_struct *tty)
603{
604 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
605 unsigned long flags;
606
607 if (serial_paranoia_check(info, tty->name, "rs_start"))
608 return;
609
610 save_flags(flags); cli();
611#if 1
612 if (info->xmit_cnt && info->xmit_buf && !(info->zs_channel->curregs[5] & TxENAB)) {
613 info->zs_channel->curregs[5] |= TxENAB;
614 write_zsreg(info->zs_channel, 5, info->zs_channel->curregs[5]);
615 }
616#else
617 if (info->xmit_cnt && info->xmit_buf && !info->tx_active) {
618 transmit_chars(info);
619 }
620#endif
621 restore_flags(flags);
622}
623
624/*
625 * This routine is used to handle the "bottom half" processing for the
626 * serial driver, known also the "software interrupt" processing.
627 * This processing is done at the kernel interrupt level, after the
628 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
629 * is where time-consuming activities which can not be done in the
630 * interrupt driver proper are done; the interrupt driver schedules
631 * them using rs_sched_event(), and they get done here.
632 */
633static void do_serial_bh(void)
634{
635 run_task_queue(&tq_zs_serial);
636}
637
638static void do_softint(void *private_)
639{
640 struct dec_serial *info = (struct dec_serial *) private_;
641 struct tty_struct *tty;
642
643 tty = info->tty;
644 if (!tty)
645 return;
646
647 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
648 tty_wakeup(tty);
649 }
650}
651
652int zs_startup(struct dec_serial * info)
653{
654 unsigned long flags;
655
656 if (info->flags & ZILOG_INITIALIZED)
657 return 0;
658
659 if (!info->xmit_buf) {
660 info->xmit_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
661 if (!info->xmit_buf)
662 return -ENOMEM;
663 }
664
665 save_flags(flags); cli();
666
667#ifdef SERIAL_DEBUG_OPEN
668 printk("starting up ttyS%d (irq %d)...", info->line, info->irq);
669#endif
670
671 /*
672 * Clear the receive FIFO.
673 */
674 ZS_CLEARFIFO(info->zs_channel);
675 info->xmit_fifo_size = 1;
676
677 /*
678 * Clear the interrupt registers.
679 */
680 write_zsreg(info->zs_channel, R0, ERR_RES);
681 write_zsreg(info->zs_channel, R0, RES_H_IUS);
682
683 /*
684 * Set the speed of the serial port
685 */
686 change_speed(info);
687
688 /*
689 * Turn on RTS and DTR.
690 */
691 zs_rtsdtr(info, RTS | DTR, 1);
692
693 /*
694 * Finally, enable sequencing and interrupts
695 */
696 info->zs_channel->curregs[R1] &= ~RxINT_MASK;
697 info->zs_channel->curregs[R1] |= (RxINT_ALL | TxINT_ENAB |
698 EXT_INT_ENAB);
699 info->zs_channel->curregs[R3] |= RxENABLE;
700 info->zs_channel->curregs[R5] |= TxENAB;
701 info->zs_channel->curregs[R15] |= (DCDIE | CTSIE | TxUIE | BRKIE);
702 write_zsreg(info->zs_channel, R1, info->zs_channel->curregs[R1]);
703 write_zsreg(info->zs_channel, R3, info->zs_channel->curregs[R3]);
704 write_zsreg(info->zs_channel, R5, info->zs_channel->curregs[R5]);
705 write_zsreg(info->zs_channel, R15, info->zs_channel->curregs[R15]);
706
707 /*
708 * And clear the interrupt registers again for luck.
709 */
710 write_zsreg(info->zs_channel, R0, ERR_RES);
711 write_zsreg(info->zs_channel, R0, RES_H_IUS);
712
713 /* Save the current value of RR0 */
714 info->read_reg_zero = read_zsreg(info->zs_channel, R0);
715
716 if (info->tty)
717 clear_bit(TTY_IO_ERROR, &info->tty->flags);
718 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
719
720 info->flags |= ZILOG_INITIALIZED;
721 restore_flags(flags);
722 return 0;
723}
724
725/*
726 * This routine will shutdown a serial port; interrupts are disabled, and
727 * DTR is dropped if the hangup on close termio flag is on.
728 */
729static void shutdown(struct dec_serial * info)
730{
731 unsigned long flags;
732
733 if (!(info->flags & ZILOG_INITIALIZED))
734 return;
735
736#ifdef SERIAL_DEBUG_OPEN
737 printk("Shutting down serial port %d (irq %d)....", info->line,
738 info->irq);
739#endif
740
741 save_flags(flags); cli(); /* Disable interrupts */
742
743 if (info->xmit_buf) {
744 free_page((unsigned long) info->xmit_buf);
745 info->xmit_buf = 0;
746 }
747
748 info->zs_channel->curregs[1] = 0;
749 write_zsreg(info->zs_channel, 1, info->zs_channel->curregs[1]); /* no interrupts */
750
751 info->zs_channel->curregs[3] &= ~RxENABLE;
752 write_zsreg(info->zs_channel, 3, info->zs_channel->curregs[3]);
753
754 info->zs_channel->curregs[5] &= ~TxENAB;
755 write_zsreg(info->zs_channel, 5, info->zs_channel->curregs[5]);
756 if (!info->tty || C_HUPCL(info->tty)) {
757 zs_rtsdtr(info, RTS | DTR, 0);
758 }
759
760 if (info->tty)
761 set_bit(TTY_IO_ERROR, &info->tty->flags);
762
763 info->flags &= ~ZILOG_INITIALIZED;
764 restore_flags(flags);
765}
766
767/*
768 * This routine is called to set the UART divisor registers to match
769 * the specified baud rate for a serial port.
770 */
771static void change_speed(struct dec_serial *info)
772{
773 unsigned cflag;
774 int i;
775 int brg, bits;
776 unsigned long flags;
777
778 if (!info->hook) {
779 if (!info->tty || !info->tty->termios)
780 return;
781 cflag = info->tty->termios->c_cflag;
782 if (!info->port)
783 return;
784 } else {
785 cflag = info->hook->cflags;
786 }
787
788 i = cflag & CBAUD;
789 if (i & CBAUDEX) {
790 i &= ~CBAUDEX;
791 if (i < 1 || i > 2) {
792 if (!info->hook)
793 info->tty->termios->c_cflag &= ~CBAUDEX;
794 else
795 info->hook->cflags &= ~CBAUDEX;
796 } else
797 i += 15;
798 }
799
800 save_flags(flags); cli();
801 info->zs_baud = baud_table[i];
802 if (info->zs_baud) {
803 brg = BPS_TO_BRG(info->zs_baud, zs_parms->clock/info->clk_divisor);
804 info->zs_channel->curregs[12] = (brg & 255);
805 info->zs_channel->curregs[13] = ((brg >> 8) & 255);
806 zs_rtsdtr(info, DTR, 1);
807 } else {
808 zs_rtsdtr(info, RTS | DTR, 0);
809 return;
810 }
811
812 /* byte size and parity */
813 info->zs_channel->curregs[3] &= ~RxNBITS_MASK;
814 info->zs_channel->curregs[5] &= ~TxNBITS_MASK;
815 switch (cflag & CSIZE) {
816 case CS5:
817 bits = 7;
818 info->zs_channel->curregs[3] |= Rx5;
819 info->zs_channel->curregs[5] |= Tx5;
820 break;
821 case CS6:
822 bits = 8;
823 info->zs_channel->curregs[3] |= Rx6;
824 info->zs_channel->curregs[5] |= Tx6;
825 break;
826 case CS7:
827 bits = 9;
828 info->zs_channel->curregs[3] |= Rx7;
829 info->zs_channel->curregs[5] |= Tx7;
830 break;
831 case CS8:
832 default: /* defaults to 8 bits */
833 bits = 10;
834 info->zs_channel->curregs[3] |= Rx8;
835 info->zs_channel->curregs[5] |= Tx8;
836 break;
837 }
838
839 info->timeout = ((info->xmit_fifo_size*HZ*bits) / info->zs_baud);
840 info->timeout += HZ/50; /* Add .02 seconds of slop */
841
842 info->zs_channel->curregs[4] &= ~(SB_MASK | PAR_ENA | PAR_EVEN);
843 if (cflag & CSTOPB) {
844 info->zs_channel->curregs[4] |= SB2;
845 } else {
846 info->zs_channel->curregs[4] |= SB1;
847 }
848 if (cflag & PARENB) {
849 info->zs_channel->curregs[4] |= PAR_ENA;
850 }
851 if (!(cflag & PARODD)) {
852 info->zs_channel->curregs[4] |= PAR_EVEN;
853 }
854
855 if (!(cflag & CLOCAL)) {
856 if (!(info->zs_channel->curregs[15] & DCDIE))
857 info->read_reg_zero = read_zsreg(info->zs_channel, 0);
858 info->zs_channel->curregs[15] |= DCDIE;
859 } else
860 info->zs_channel->curregs[15] &= ~DCDIE;
861 if (cflag & CRTSCTS) {
862 info->zs_channel->curregs[15] |= CTSIE;
863 if ((read_zsreg(info->zs_channel, 0) & CTS) == 0)
864 info->tx_stopped = 1;
865 } else {
866 info->zs_channel->curregs[15] &= ~CTSIE;
867 info->tx_stopped = 0;
868 }
869
870 /* Load up the new values */
871 load_zsregs(info->zs_channel, info->zs_channel->curregs);
872
873 restore_flags(flags);
874}
875
876static void rs_flush_chars(struct tty_struct *tty)
877{
878 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
879 unsigned long flags;
880
881 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
882 return;
883
884 if (info->xmit_cnt <= 0 || tty->stopped || info->tx_stopped ||
885 !info->xmit_buf)
886 return;
887
888 /* Enable transmitter */
889 save_flags(flags); cli();
890 transmit_chars(info);
891 restore_flags(flags);
892}
893
894static int rs_write(struct tty_struct * tty,
895 const unsigned char *buf, int count)
896{
897 int c, total = 0;
898 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
899 unsigned long flags;
900
901 if (serial_paranoia_check(info, tty->name, "rs_write"))
902 return 0;
903
904 if (!tty || !info->xmit_buf)
905 return 0;
906
907 save_flags(flags);
908 while (1) {
909 cli();
910 c = min(count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
911 SERIAL_XMIT_SIZE - info->xmit_head));
912 if (c <= 0)
913 break;
914
915 if (from_user) {
916 down(&tmp_buf_sem);
917 copy_from_user(tmp_buf, buf, c);
918 c = min(c, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
919 SERIAL_XMIT_SIZE - info->xmit_head));
920 memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
921 up(&tmp_buf_sem);
922 } else
923 memcpy(info->xmit_buf + info->xmit_head, buf, c);
924 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
925 info->xmit_cnt += c;
926 restore_flags(flags);
927 buf += c;
928 count -= c;
929 total += c;
930 }
931
932 if (info->xmit_cnt && !tty->stopped && !info->tx_stopped
933 && !info->tx_active)
934 transmit_chars(info);
935 restore_flags(flags);
936 return total;
937}
938
939static int rs_write_room(struct tty_struct *tty)
940{
941 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
942 int ret;
943
944 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
945 return 0;
946 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
947 if (ret < 0)
948 ret = 0;
949 return ret;
950}
951
952static int rs_chars_in_buffer(struct tty_struct *tty)
953{
954 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
955
956 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
957 return 0;
958 return info->xmit_cnt;
959}
960
961static void rs_flush_buffer(struct tty_struct *tty)
962{
963 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
964
965 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
966 return;
967 cli();
968 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
969 sti();
970 tty_wakeup(tty);
971}
972
973/*
974 * ------------------------------------------------------------
975 * rs_throttle()
976 *
977 * This routine is called by the upper-layer tty layer to signal that
978 * incoming characters should be throttled.
979 * ------------------------------------------------------------
980 */
981static void rs_throttle(struct tty_struct * tty)
982{
983 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
984 unsigned long flags;
985
986#ifdef SERIAL_DEBUG_THROTTLE
987 char buf[64];
988
989 printk("throttle %s: %d....\n", _tty_name(tty, buf),
990 tty->ldisc.chars_in_buffer(tty));
991#endif
992
993 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
994 return;
995
996 if (I_IXOFF(tty)) {
997 save_flags(flags); cli();
998 info->x_char = STOP_CHAR(tty);
999 if (!info->tx_active)
1000 transmit_chars(info);
1001 restore_flags(flags);
1002 }
1003
1004 if (C_CRTSCTS(tty)) {
1005 zs_rtsdtr(info, RTS, 0);
1006 }
1007}
1008
1009static void rs_unthrottle(struct tty_struct * tty)
1010{
1011 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
1012 unsigned long flags;
1013
1014#ifdef SERIAL_DEBUG_THROTTLE
1015 char buf[64];
1016
1017 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1018 tty->ldisc.chars_in_buffer(tty));
1019#endif
1020
1021 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1022 return;
1023
1024 if (I_IXOFF(tty)) {
1025 save_flags(flags); cli();
1026 if (info->x_char)
1027 info->x_char = 0;
1028 else {
1029 info->x_char = START_CHAR(tty);
1030 if (!info->tx_active)
1031 transmit_chars(info);
1032 }
1033 restore_flags(flags);
1034 }
1035
1036 if (C_CRTSCTS(tty)) {
1037 zs_rtsdtr(info, RTS, 1);
1038 }
1039}
1040
1041/*
1042 * ------------------------------------------------------------
1043 * rs_ioctl() and friends
1044 * ------------------------------------------------------------
1045 */
1046
1047static int get_serial_info(struct dec_serial * info,
1048 struct serial_struct * retinfo)
1049{
1050 struct serial_struct tmp;
1051
1052 if (!retinfo)
1053 return -EFAULT;
1054 memset(&tmp, 0, sizeof(tmp));
1055 tmp.type = info->type;
1056 tmp.line = info->line;
1057 tmp.port = info->port;
1058 tmp.irq = info->irq;
1059 tmp.flags = info->flags;
1060 tmp.baud_base = info->baud_base;
1061 tmp.close_delay = info->close_delay;
1062 tmp.closing_wait = info->closing_wait;
1063 tmp.custom_divisor = info->custom_divisor;
1064 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
1065}
1066
1067static int set_serial_info(struct dec_serial * info,
1068 struct serial_struct * new_info)
1069{
1070 struct serial_struct new_serial;
1071 struct dec_serial old_info;
1072 int retval = 0;
1073
1074 if (!new_info)
1075 return -EFAULT;
1076 copy_from_user(&new_serial,new_info,sizeof(new_serial));
1077 old_info = *info;
1078
1079 if (!capable(CAP_SYS_ADMIN)) {
1080 if ((new_serial.baud_base != info->baud_base) ||
1081 (new_serial.type != info->type) ||
1082 (new_serial.close_delay != info->close_delay) ||
1083 ((new_serial.flags & ~ZILOG_USR_MASK) !=
1084 (info->flags & ~ZILOG_USR_MASK)))
1085 return -EPERM;
1086 info->flags = ((info->flags & ~ZILOG_USR_MASK) |
1087 (new_serial.flags & ZILOG_USR_MASK));
1088 info->custom_divisor = new_serial.custom_divisor;
1089 goto check_and_exit;
1090 }
1091
1092 if (info->count > 1)
1093 return -EBUSY;
1094
1095 /*
1096 * OK, past this point, all the error checking has been done.
1097 * At this point, we start making changes.....
1098 */
1099
1100 info->baud_base = new_serial.baud_base;
1101 info->flags = ((info->flags & ~ZILOG_FLAGS) |
1102 (new_serial.flags & ZILOG_FLAGS));
1103 info->type = new_serial.type;
1104 info->close_delay = new_serial.close_delay;
1105 info->closing_wait = new_serial.closing_wait;
1106
1107check_and_exit:
1108 retval = zs_startup(info);
1109 return retval;
1110}
1111
1112/*
1113 * get_lsr_info - get line status register info
1114 *
1115 * Purpose: Let user call ioctl() to get info when the UART physically
1116 * is emptied. On bus types like RS485, the transmitter must
1117 * release the bus after transmitting. This must be done when
1118 * the transmit shift register is empty, not be done when the
1119 * transmit holding register is empty. This functionality
1120 * allows an RS485 driver to be written in user space.
1121 */
1122static int get_lsr_info(struct dec_serial * info, unsigned int *value)
1123{
1124 unsigned char status;
1125
1126 cli();
1127 status = read_zsreg(info->zs_channel, 0);
1128 sti();
1129 put_user(status,value);
1130 return 0;
1131}
1132
1133static int rs_tiocmget(struct tty_struct *tty, struct file *file)
1134{
1135 struct dec_serial * info = (struct dec_serial *)tty->driver_data;
1136 unsigned char control, status_a, status_b;
1137 unsigned int result;
1138
1139 if (info->hook)
1140 return -ENODEV;
1141
1142 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
1143 return -ENODEV;
1144
1145 if (tty->flags & (1 << TTY_IO_ERROR))
1146 return -EIO;
1147
1148 if (info->zs_channel == info->zs_chan_a)
1149 result = 0;
1150 else {
1151 cli();
1152 control = info->zs_chan_a->curregs[5];
1153 status_a = read_zsreg(info->zs_chan_a, 0);
1154 status_b = read_zsreg(info->zs_channel, 0);
1155 sti();
1156 result = ((control & RTS) ? TIOCM_RTS: 0)
1157 | ((control & DTR) ? TIOCM_DTR: 0)
1158 | ((status_b & DCD) ? TIOCM_CAR: 0)
1159 | ((status_a & DCD) ? TIOCM_RNG: 0)
1160 | ((status_a & SYNC_HUNT) ? TIOCM_DSR: 0)
1161 | ((status_b & CTS) ? TIOCM_CTS: 0);
1162 }
1163 return result;
1164}
1165
1166static int rs_tiocmset(struct tty_struct *tty, struct file *file,
1167 unsigned int set, unsigned int clear)
1168{
1169 struct dec_serial * info = (struct dec_serial *)tty->driver_data;
1170 int error;
1171 unsigned int arg, bits;
1172
1173 if (info->hook)
1174 return -ENODEV;
1175
1176 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
1177 return -ENODEV;
1178
1179 if (tty->flags & (1 << TTY_IO_ERROR))
1180 return -EIO;
1181
1182 if (info->zs_channel == info->zs_chan_a)
1183 return 0;
1184
1185 get_user(arg, value);
1186 cli();
1187 if (set & TIOCM_RTS)
1188 info->zs_chan_a->curregs[5] |= RTS;
1189 if (set & TIOCM_DTR)
1190 info->zs_chan_a->curregs[5] |= DTR;
1191 if (clear & TIOCM_RTS)
1192 info->zs_chan_a->curregs[5] &= ~RTS;
1193 if (clear & TIOCM_DTR)
1194 info->zs_chan_a->curregs[5] &= ~DTR;
1195 write_zsreg(info->zs_chan_a, 5, info->zs_chan_a->curregs[5]);
1196 sti();
1197 return 0;
1198}
1199
1200/*
1201 * rs_break - turn transmit break condition on/off
1202 */
1203static void rs_break(struct tty_struct *tty, int break_state)
1204{
1205 struct dec_serial *info = (struct dec_serial *) tty->driver_data;
1206 unsigned long flags;
1207
1208 if (serial_paranoia_check(info, tty->name, "rs_break"))
1209 return;
1210 if (!info->port)
1211 return;
1212
1213 save_flags(flags); cli();
1214 if (break_state == -1)
1215 info->zs_channel->curregs[5] |= SND_BRK;
1216 else
1217 info->zs_channel->curregs[5] &= ~SND_BRK;
1218 write_zsreg(info->zs_channel, 5, info->zs_channel->curregs[5]);
1219 restore_flags(flags);
1220}
1221
1222static int rs_ioctl(struct tty_struct *tty, struct file * file,
1223 unsigned int cmd, unsigned long arg)
1224{
1225 int error;
1226 struct dec_serial * info = (struct dec_serial *)tty->driver_data;
1227
1228 if (info->hook)
1229 return -ENODEV;
1230
1231 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1232 return -ENODEV;
1233
1234 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1235 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1236 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
1237 if (tty->flags & (1 << TTY_IO_ERROR))
1238 return -EIO;
1239 }
1240
1241 switch (cmd) {
1242 case TIOCGSERIAL:
1243 if (!access_ok(VERIFY_WRITE, (void *)arg,
1244 sizeof(struct serial_struct)))
1245 return -EFAULT;
1246 return get_serial_info(info, (struct serial_struct *)arg);
1247
1248 case TIOCSSERIAL:
1249 return set_serial_info(info, (struct serial_struct *)arg);
1250
1251 case TIOCSERGETLSR: /* Get line status register */
1252 if (!access_ok(VERIFY_WRITE, (void *)arg,
1253 sizeof(unsigned int)))
1254 return -EFAULT;
1255 return get_lsr_info(info, (unsigned int *)arg);
1256
1257 case TIOCSERGSTRUCT:
1258 if (!access_ok(VERIFY_WRITE, (void *)arg,
1259 sizeof(struct dec_serial)))
1260 return -EFAULT;
1261 copy_from_user((struct dec_serial *)arg, info,
1262 sizeof(struct dec_serial));
1263 return 0;
1264
1265 default:
1266 return -ENOIOCTLCMD;
1267 }
1268 return 0;
1269}
1270
1271static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1272{
1273 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
1274 int was_stopped;
1275
1276 if (tty->termios->c_cflag == old_termios->c_cflag)
1277 return;
1278 was_stopped = info->tx_stopped;
1279
1280 change_speed(info);
1281
1282 if (was_stopped && !info->tx_stopped)
1283 rs_start(tty);
1284}
1285
1286/*
1287 * ------------------------------------------------------------
1288 * rs_close()
1289 *
1290 * This routine is called when the serial port gets closed.
1291 * Wait for the last remaining data to be sent.
1292 * ------------------------------------------------------------
1293 */
1294static void rs_close(struct tty_struct *tty, struct file * filp)
1295{
1296 struct dec_serial * info = (struct dec_serial *)tty->driver_data;
1297 unsigned long flags;
1298
1299 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1300 return;
1301
1302 save_flags(flags); cli();
1303
1304 if (tty_hung_up_p(filp)) {
1305 restore_flags(flags);
1306 return;
1307 }
1308
1309#ifdef SERIAL_DEBUG_OPEN
1310 printk("rs_close ttyS%d, count = %d\n", info->line, info->count);
1311#endif
1312 if ((tty->count == 1) && (info->count != 1)) {
1313 /*
1314 * Uh, oh. tty->count is 1, which means that the tty
1315 * structure will be freed. Info->count should always
1316 * be one in these conditions. If it's greater than
1317 * one, we've got real problems, since it means the
1318 * serial port won't be shutdown.
1319 */
1320 printk("rs_close: bad serial port count; tty->count is 1, "
1321 "info->count is %d\n", info->count);
1322 info->count = 1;
1323 }
1324 if (--info->count < 0) {
1325 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1326 info->line, info->count);
1327 info->count = 0;
1328 }
1329 if (info->count) {
1330 restore_flags(flags);
1331 return;
1332 }
1333 info->flags |= ZILOG_CLOSING;
1334 /*
1335 * Now we wait for the transmit buffer to clear; and we notify
1336 * the line discipline to only process XON/XOFF characters.
1337 */
1338 tty->closing = 1;
1339 if (info->closing_wait != ZILOG_CLOSING_WAIT_NONE)
1340 tty_wait_until_sent(tty, info->closing_wait);
1341 /*
1342 * At this point we stop accepting input. To do this, we
1343 * disable the receiver and receive interrupts.
1344 */
1345 info->zs_channel->curregs[3] &= ~RxENABLE;
1346 write_zsreg(info->zs_channel, 3, info->zs_channel->curregs[3]);
1347 info->zs_channel->curregs[1] = 0; /* disable any rx ints */
1348 write_zsreg(info->zs_channel, 1, info->zs_channel->curregs[1]);
1349 ZS_CLEARFIFO(info->zs_channel);
1350 if (info->flags & ZILOG_INITIALIZED) {
1351 /*
1352 * Before we drop DTR, make sure the SCC transmitter
1353 * has completely drained.
1354 */
1355 rs_wait_until_sent(tty, info->timeout);
1356 }
1357
1358 shutdown(info);
1359 if (tty->driver->flush_buffer)
1360 tty->driver->flush_buffer(tty);
1361 tty_ldisc_flush(tty);
1362 tty->closing = 0;
1363 info->event = 0;
1364 info->tty = 0;
1365 if (info->blocked_open) {
1366 if (info->close_delay) {
1367 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1368 }
1369 wake_up_interruptible(&info->open_wait);
1370 }
1371 info->flags &= ~(ZILOG_NORMAL_ACTIVE|ZILOG_CLOSING);
1372 wake_up_interruptible(&info->close_wait);
1373 restore_flags(flags);
1374}
1375
1376/*
1377 * rs_wait_until_sent() --- wait until the transmitter is empty
1378 */
1379static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1380{
1381 struct dec_serial *info = (struct dec_serial *) tty->driver_data;
1382 unsigned long orig_jiffies;
1383 int char_time;
1384
1385 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
1386 return;
1387
1388 orig_jiffies = jiffies;
1389 /*
1390 * Set the check interval to be 1/5 of the estimated time to
1391 * send a single character, and make it at least 1. The check
1392 * interval should also be less than the timeout.
1393 */
1394 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
1395 char_time = char_time / 5;
1396 if (char_time == 0)
1397 char_time = 1;
1398 if (timeout)
1399 char_time = min(char_time, timeout);
1400 while ((read_zsreg(info->zs_channel, 1) & Tx_BUF_EMP) == 0) {
1401 msleep_interruptible(jiffies_to_msecs(char_time));
1402 if (signal_pending(current))
1403 break;
1404 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1405 break;
1406 }
1407 current->state = TASK_RUNNING;
1408}
1409
1410/*
1411 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1412 */
1413void rs_hangup(struct tty_struct *tty)
1414{
1415 struct dec_serial * info = (struct dec_serial *)tty->driver_data;
1416
1417 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
1418 return;
1419
1420 rs_flush_buffer(tty);
1421 shutdown(info);
1422 info->event = 0;
1423 info->count = 0;
1424 info->flags &= ~ZILOG_NORMAL_ACTIVE;
1425 info->tty = 0;
1426 wake_up_interruptible(&info->open_wait);
1427}
1428
1429/*
1430 * ------------------------------------------------------------
1431 * rs_open() and friends
1432 * ------------------------------------------------------------
1433 */
1434static int block_til_ready(struct tty_struct *tty, struct file * filp,
1435 struct dec_serial *info)
1436{
1437 DECLARE_WAITQUEUE(wait, current);
1438 int retval;
1439 int do_clocal = 0;
1440
1441 /*
1442 * If the device is in the middle of being closed, then block
1443 * until it's done, and then try again.
1444 */
1445 if (info->flags & ZILOG_CLOSING) {
1446 interruptible_sleep_on(&info->close_wait);
1447#ifdef SERIAL_DO_RESTART
1448 return ((info->flags & ZILOG_HUP_NOTIFY) ?
1449 -EAGAIN : -ERESTARTSYS);
1450#else
1451 return -EAGAIN;
1452#endif
1453 }
1454
1455 /*
1456 * If non-blocking mode is set, or the port is not enabled,
1457 * then make the check up front and then exit.
1458 */
1459 if ((filp->f_flags & O_NONBLOCK) ||
1460 (tty->flags & (1 << TTY_IO_ERROR))) {
1461 info->flags |= ZILOG_NORMAL_ACTIVE;
1462 return 0;
1463 }
1464
1465 if (tty->termios->c_cflag & CLOCAL)
1466 do_clocal = 1;
1467
1468 /*
1469 * Block waiting for the carrier detect and the line to become
1470 * free (i.e., not in use by the callout). While we are in
1471 * this loop, info->count is dropped by one, so that
1472 * rs_close() knows when to free things. We restore it upon
1473 * exit, either normal or abnormal.
1474 */
1475 retval = 0;
1476 add_wait_queue(&info->open_wait, &wait);
1477#ifdef SERIAL_DEBUG_OPEN
1478 printk("block_til_ready before block: ttyS%d, count = %d\n",
1479 info->line, info->count);
1480#endif
1481 cli();
1482 if (!tty_hung_up_p(filp))
1483 info->count--;
1484 sti();
1485 info->blocked_open++;
1486 while (1) {
1487 cli();
1488 if (tty->termios->c_cflag & CBAUD)
1489 zs_rtsdtr(info, RTS | DTR, 1);
1490 sti();
1491 set_current_state(TASK_INTERRUPTIBLE);
1492 if (tty_hung_up_p(filp) ||
1493 !(info->flags & ZILOG_INITIALIZED)) {
1494#ifdef SERIAL_DO_RESTART
1495 if (info->flags & ZILOG_HUP_NOTIFY)
1496 retval = -EAGAIN;
1497 else
1498 retval = -ERESTARTSYS;
1499#else
1500 retval = -EAGAIN;
1501#endif
1502 break;
1503 }
1504 if (!(info->flags & ZILOG_CLOSING) &&
1505 (do_clocal || (read_zsreg(info->zs_channel, 0) & DCD)))
1506 break;
1507 if (signal_pending(current)) {
1508 retval = -ERESTARTSYS;
1509 break;
1510 }
1511#ifdef SERIAL_DEBUG_OPEN
1512 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1513 info->line, info->count);
1514#endif
1515 schedule();
1516 }
1517 current->state = TASK_RUNNING;
1518 remove_wait_queue(&info->open_wait, &wait);
1519 if (!tty_hung_up_p(filp))
1520 info->count++;
1521 info->blocked_open--;
1522#ifdef SERIAL_DEBUG_OPEN
1523 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1524 info->line, info->count);
1525#endif
1526 if (retval)
1527 return retval;
1528 info->flags |= ZILOG_NORMAL_ACTIVE;
1529 return 0;
1530}
1531
1532/*
1533 * This routine is called whenever a serial port is opened. It
1534 * enables interrupts for a serial port, linking in its ZILOG structure into
1535 * the IRQ chain. It also performs the serial-specific
1536 * initialization for the tty structure.
1537 */
1538int rs_open(struct tty_struct *tty, struct file * filp)
1539{
1540 struct dec_serial *info;
1541 int retval, line;
1542
1543 line = tty->index;
1544 if ((line < 0) || (line >= zs_channels_found))
1545 return -ENODEV;
1546 info = zs_soft + line;
1547
1548 if (info->hook)
1549 return -ENODEV;
1550
1551 if (serial_paranoia_check(info, tty->name, "rs_open"))
1552 return -ENODEV;
1553#ifdef SERIAL_DEBUG_OPEN
1554 printk("rs_open %s, count = %d\n", tty->name, info->count);
1555#endif
1556
1557 info->count++;
1558 tty->driver_data = info;
1559 info->tty = tty;
1560
1561 /*
1562 * If the port is the middle of closing, bail out now
1563 */
1564 if (tty_hung_up_p(filp) ||
1565 (info->flags & ZILOG_CLOSING)) {
1566 if (info->flags & ZILOG_CLOSING)
1567 interruptible_sleep_on(&info->close_wait);
1568#ifdef SERIAL_DO_RESTART
1569 return ((info->flags & ZILOG_HUP_NOTIFY) ?
1570 -EAGAIN : -ERESTARTSYS);
1571#else
1572 return -EAGAIN;
1573#endif
1574 }
1575
1576 /*
1577 * Start up serial port
1578 */
1579 retval = zs_startup(info);
1580 if (retval)
1581 return retval;
1582
1583 retval = block_til_ready(tty, filp, info);
1584 if (retval) {
1585#ifdef SERIAL_DEBUG_OPEN
1586 printk("rs_open returning after block_til_ready with %d\n",
1587 retval);
1588#endif
1589 return retval;
1590 }
1591
1592#ifdef CONFIG_SERIAL_DEC_CONSOLE
1593 if (sercons.cflag && sercons.index == line) {
1594 tty->termios->c_cflag = sercons.cflag;
1595 sercons.cflag = 0;
1596 change_speed(info);
1597 }
1598#endif
1599
1600#ifdef SERIAL_DEBUG_OPEN
1601 printk("rs_open %s successful...", tty->name);
1602#endif
1603/* tty->low_latency = 1; */
1604 return 0;
1605}
1606
1607/* Finally, routines used to initialize the serial driver. */
1608
1609static void __init show_serial_version(void)
1610{
1611 printk("DECstation Z8530 serial driver version 0.09\n");
1612}
1613
1614/* Initialize Z8530s zs_channels
1615 */
1616
1617static void __init probe_sccs(void)
1618{
1619 struct dec_serial **pp;
1620 int i, n, n_chips = 0, n_channels, chip, channel;
1621 unsigned long flags;
1622
1623 /*
1624 * did we get here by accident?
1625 */
1626 if(!BUS_PRESENT) {
1627 printk("Not on JUNKIO machine, skipping probe_sccs\n");
1628 return;
1629 }
1630
1631 /*
1632 * When serial console is activated, tc_init has not been called yet
1633 * and system_base is undefined. Unfortunately we have to hardcode
1634 * system_base for this case :-(. HK
1635 */
1636 switch(mips_machtype) {
1637#ifdef CONFIG_MACH_DECSTATION
1638 case MACH_DS5000_2X0:
1639 case MACH_DS5900:
1640 system_base = KSEG1ADDR(0x1f800000);
1641 n_chips = 2;
1642 zs_parms = &ds_parms;
1643 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0];
1644 zs_parms->irq1 = dec_interrupt[DEC_IRQ_SCC1];
1645 break;
1646 case MACH_DS5000_1XX:
1647 system_base = KSEG1ADDR(0x1c000000);
1648 n_chips = 2;
1649 zs_parms = &ds_parms;
1650 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0];
1651 zs_parms->irq1 = dec_interrupt[DEC_IRQ_SCC1];
1652 break;
1653 case MACH_DS5000_XX:
1654 system_base = KSEG1ADDR(0x1c000000);
1655 n_chips = 1;
1656 zs_parms = &ds_parms;
1657 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0];
1658 break;
1659#endif
1660 default:
1661 panic("zs: unsupported bus");
1662 }
1663 if (!zs_parms)
1664 panic("zs: uninitialized parms");
1665
1666 pp = &zs_chain;
1667
1668 n_channels = 0;
1669
1670 for (chip = 0; chip < n_chips; chip++) {
1671 for (channel = 0; channel <= 1; channel++) {
1672 /*
1673 * The sccs reside on the high byte of the 16 bit IOBUS
1674 */
1675 zs_channels[n_channels].control =
1676 (volatile unsigned char *)system_base +
1677 (0 == chip ? zs_parms->scc0 : zs_parms->scc1) +
1678 (0 == channel ? zs_parms->channel_a_offset :
1679 zs_parms->channel_b_offset);
1680 zs_channels[n_channels].data =
1681 zs_channels[n_channels].control + 4;
1682
1683#ifndef CONFIG_SERIAL_DEC_CONSOLE
1684 /*
1685 * We're called early and memory managment isn't up, yet.
1686 * Thus check_region would fail.
1687 */
1688 if (!request_region((unsigned long)
1689 zs_channels[n_channels].control,
1690 ZS_CHAN_IO_SIZE, "SCC"))
1691 panic("SCC I/O region is not free");
1692#endif
1693 zs_soft[n_channels].zs_channel = &zs_channels[n_channels];
1694 /* HACK alert! */
1695 if (!(chip & 1))
1696 zs_soft[n_channels].irq = zs_parms->irq0;
1697 else
1698 zs_soft[n_channels].irq = zs_parms->irq1;
1699
1700 /*
1701 * Identification of channel A. Location of channel A
1702 * inside chip depends on mapping of internal address
1703 * the chip decodes channels by.
1704 * CHANNEL_A_NR returns either 0 (in case of
1705 * DECstations) or 1 (in case of Baget).
1706 */
1707 if (CHANNEL_A_NR == channel)
1708 zs_soft[n_channels].zs_chan_a =
1709 &zs_channels[n_channels+1-2*CHANNEL_A_NR];
1710 else
1711 zs_soft[n_channels].zs_chan_a =
1712 &zs_channels[n_channels];
1713
1714 *pp = &zs_soft[n_channels];
1715 pp = &zs_soft[n_channels].zs_next;
1716 n_channels++;
1717 }
1718 }
1719
1720 *pp = 0;
1721 zs_channels_found = n_channels;
1722
1723 for (n = 0; n < zs_channels_found; n++) {
1724 for (i = 0; i < 16; i++) {
1725 zs_soft[n].zs_channel->curregs[i] = zs_init_regs[i];
1726 }
1727 }
1728
1729 save_and_cli(flags);
1730 for (n = 0; n < zs_channels_found; n++) {
1731 if (n % 2 == 0) {
1732 write_zsreg(zs_soft[n].zs_chan_a, R9, FHWRES);
1733 udelay(10);
1734 write_zsreg(zs_soft[n].zs_chan_a, R9, 0);
1735 }
1736 load_zsregs(zs_soft[n].zs_channel,
1737 zs_soft[n].zs_channel->curregs);
1738 }
1739 restore_flags(flags);
1740}
1741
1742static struct tty_operations serial_ops = {
1743 .open = rs_open,
1744 .close = rs_close,
1745 .write = rs_write,
1746 .flush_chars = rs_flush_chars,
1747 .write_room = rs_write_room,
1748 .chars_in_buffer = rs_chars_in_buffer,
1749 .flush_buffer = rs_flush_buffer,
1750 .ioctl = rs_ioctl,
1751 .throttle = rs_throttle,
1752 .unthrottle = rs_unthrottle,
1753 .set_termios = rs_set_termios,
1754 .stop = rs_stop,
1755 .start = rs_start,
1756 .hangup = rs_hangup,
1757 .break_ctl = rs_break,
1758 .wait_until_sent = rs_wait_until_sent,
1759 .tiocmget = rs_tiocmget,
1760 .tiocmset = rs_tiocmset,
1761};
1762
1763/* zs_init inits the driver */
1764int __init zs_init(void)
1765{
1766 int channel, i;
1767 struct dec_serial *info;
1768
1769 if(!BUS_PRESENT)
1770 return -ENODEV;
1771
1772 /* Setup base handler, and timer table. */
1773 init_bh(SERIAL_BH, do_serial_bh);
1774
1775 /* Find out how many Z8530 SCCs we have */
1776 if (zs_chain == 0)
1777 probe_sccs();
1778 serial_driver = alloc_tty_driver(zs_channels_found);
1779 if (!serial_driver)
1780 return -ENOMEM;
1781
1782 show_serial_version();
1783
1784 /* Initialize the tty_driver structure */
1785 /* Not all of this is exactly right for us. */
1786
1787 serial_driver->owner = THIS_MODULE;
1788 serial_driver->devfs_name = "tts/";
1789 serial_driver->name = "ttyS";
1790 serial_driver->major = TTY_MAJOR;
1791 serial_driver->minor_start = 64;
1792 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1793 serial_driver->subtype = SERIAL_TYPE_NORMAL;
1794 serial_driver->init_termios = tty_std_termios;
1795 serial_driver->init_termios.c_cflag =
1796 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1797 serial_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
1798 tty_set_operations(serial_driver, &serial_ops);
1799
1800 if (tty_register_driver(serial_driver))
1801 panic("Couldn't register serial driver");
1802
1803 for (info = zs_chain, i = 0; info; info = info->zs_next, i++) {
1804
1805 /* Needed before interrupts are enabled. */
1806 info->tty = 0;
1807 info->x_char = 0;
1808
1809 if (info->hook && info->hook->init_info) {
1810 (*info->hook->init_info)(info);
1811 continue;
1812 }
1813
1814 info->magic = SERIAL_MAGIC;
1815 info->port = (int) info->zs_channel->control;
1816 info->line = i;
1817 info->custom_divisor = 16;
1818 info->close_delay = 50;
1819 info->closing_wait = 3000;
1820 info->event = 0;
1821 info->count = 0;
1822 info->blocked_open = 0;
1823 info->tqueue.routine = do_softint;
1824 info->tqueue.data = info;
1825 init_waitqueue_head(&info->open_wait);
1826 init_waitqueue_head(&info->close_wait);
1827 printk("ttyS%02d at 0x%08x (irq = %d) is a Z85C30 SCC\n",
1828 info->line, info->port, info->irq);
1829 tty_register_device(serial_driver, info->line, NULL);
1830
1831 }
1832
1833 for (channel = 0; channel < zs_channels_found; ++channel) {
1834 zs_soft[channel].clk_divisor = 16;
1835 zs_soft[channel].zs_baud = get_zsbaud(&zs_soft[channel]);
1836
1837 if (request_irq(zs_soft[channel].irq, rs_interrupt, SA_SHIRQ,
1838 "scc", &zs_soft[channel]))
1839 printk(KERN_ERR "decserial: can't get irq %d\n",
1840 zs_soft[channel].irq);
1841
1842 if (zs_soft[channel].hook) {
1843 zs_startup(&zs_soft[channel]);
1844 if (zs_soft[channel].hook->init_channel)
1845 (*zs_soft[channel].hook->init_channel)
1846 (&zs_soft[channel]);
1847 }
1848 }
1849
1850 return 0;
1851}
1852
1853/*
1854 * polling I/O routines
1855 */
1856static int
1857zs_poll_tx_char(void *handle, unsigned char ch)
1858{
1859 struct dec_serial *info = handle;
1860 struct dec_zschannel *chan = info->zs_channel;
1861 int ret;
1862
1863 if(chan) {
1864 int loops = 10000;
1865
1866 while (loops && !(read_zsreg(chan, 0) & Tx_BUF_EMP))
1867 loops--;
1868
1869 if (loops) {
1870 write_zsdata(chan, ch);
1871 ret = 0;
1872 } else
1873 ret = -EAGAIN;
1874
1875 return ret;
1876 } else
1877 return -ENODEV;
1878}
1879
1880static int
1881zs_poll_rx_char(void *handle)
1882{
1883 struct dec_serial *info = handle;
1884 struct dec_zschannel *chan = info->zs_channel;
1885 int ret;
1886
1887 if(chan) {
1888 int loops = 10000;
1889
1890 while (loops && !(read_zsreg(chan, 0) & Rx_CH_AV))
1891 loops--;
1892
1893 if (loops)
1894 ret = read_zsdata(chan);
1895 else
1896 ret = -EAGAIN;
1897
1898 return ret;
1899 } else
1900 return -ENODEV;
1901}
1902
1903int register_zs_hook(unsigned int channel, struct dec_serial_hook *hook)
1904{
1905 struct dec_serial *info = &zs_soft[channel];
1906
1907 if (info->hook) {
1908 printk("%s: line %d has already a hook registered\n",
1909 __FUNCTION__, channel);
1910
1911 return 0;
1912 } else {
1913 hook->poll_rx_char = zs_poll_rx_char;
1914 hook->poll_tx_char = zs_poll_tx_char;
1915 info->hook = hook;
1916
1917 return 1;
1918 }
1919}
1920
1921int unregister_zs_hook(unsigned int channel)
1922{
1923 struct dec_serial *info = &zs_soft[channel];
1924
1925 if (info->hook) {
1926 info->hook = NULL;
1927 return 1;
1928 } else {
1929 printk("%s: trying to unregister hook on line %d,"
1930 " but none is registered\n", __FUNCTION__, channel);
1931 return 0;
1932 }
1933}
1934
1935/*
1936 * ------------------------------------------------------------
1937 * Serial console driver
1938 * ------------------------------------------------------------
1939 */
1940#ifdef CONFIG_SERIAL_DEC_CONSOLE
1941
1942
1943/*
1944 * Print a string to the serial port trying not to disturb
1945 * any possible real use of the port...
1946 */
1947static void serial_console_write(struct console *co, const char *s,
1948 unsigned count)
1949{
1950 struct dec_serial *info;
1951 int i;
1952
1953 info = zs_soft + co->index;
1954
1955 for (i = 0; i < count; i++, s++) {
1956 if(*s == '\n')
1957 zs_poll_tx_char(info, '\r');
1958 zs_poll_tx_char(info, *s);
1959 }
1960}
1961
1962static struct tty_driver *serial_console_device(struct console *c, int *index)
1963{
1964 *index = c->index;
1965 return serial_driver;
1966}
1967
1968/*
1969 * Setup initial baud/bits/parity. We do two things here:
1970 * - construct a cflag setting for the first rs_open()
1971 * - initialize the serial port
1972 * Return non-zero if we didn't find a serial port.
1973 */
1974static int __init serial_console_setup(struct console *co, char *options)
1975{
1976 struct dec_serial *info;
1977 int baud = 9600;
1978 int bits = 8;
1979 int parity = 'n';
1980 int cflag = CREAD | HUPCL | CLOCAL;
1981 int clk_divisor = 16;
1982 int brg;
1983 char *s;
1984 unsigned long flags;
1985
1986 if(!BUS_PRESENT)
1987 return -ENODEV;
1988
1989 info = zs_soft + co->index;
1990
1991 if (zs_chain == 0)
1992 probe_sccs();
1993
1994 info->is_cons = 1;
1995
1996 if (options) {
1997 baud = simple_strtoul(options, NULL, 10);
1998 s = options;
1999 while(*s >= '0' && *s <= '9')
2000 s++;
2001 if (*s)
2002 parity = *s++;
2003 if (*s)
2004 bits = *s - '0';
2005 }
2006
2007 /*
2008 * Now construct a cflag setting.
2009 */
2010 switch(baud) {
2011 case 1200:
2012 cflag |= B1200;
2013 break;
2014 case 2400:
2015 cflag |= B2400;
2016 break;
2017 case 4800:
2018 cflag |= B4800;
2019 break;
2020 case 19200:
2021 cflag |= B19200;
2022 break;
2023 case 38400:
2024 cflag |= B38400;
2025 break;
2026 case 57600:
2027 cflag |= B57600;
2028 break;
2029 case 115200:
2030 cflag |= B115200;
2031 break;
2032 case 9600:
2033 default:
2034 cflag |= B9600;
2035 /*
2036 * Set this to a sane value to prevent a divide error.
2037 */
2038 baud = 9600;
2039 break;
2040 }
2041 switch(bits) {
2042 case 7:
2043 cflag |= CS7;
2044 break;
2045 default:
2046 case 8:
2047 cflag |= CS8;
2048 break;
2049 }
2050 switch(parity) {
2051 case 'o': case 'O':
2052 cflag |= PARODD;
2053 break;
2054 case 'e': case 'E':
2055 cflag |= PARENB;
2056 break;
2057 }
2058 co->cflag = cflag;
2059
2060 save_and_cli(flags);
2061
2062 /*
2063 * Set up the baud rate generator.
2064 */
2065 brg = BPS_TO_BRG(baud, zs_parms->clock / clk_divisor);
2066 info->zs_channel->curregs[R12] = (brg & 255);
2067 info->zs_channel->curregs[R13] = ((brg >> 8) & 255);
2068
2069 /*
2070 * Set byte size and parity.
2071 */
2072 if (bits == 7) {
2073 info->zs_channel->curregs[R3] |= Rx7;
2074 info->zs_channel->curregs[R5] |= Tx7;
2075 } else {
2076 info->zs_channel->curregs[R3] |= Rx8;
2077 info->zs_channel->curregs[R5] |= Tx8;
2078 }
2079 if (cflag & PARENB) {
2080 info->zs_channel->curregs[R4] |= PAR_ENA;
2081 }
2082 if (!(cflag & PARODD)) {
2083 info->zs_channel->curregs[R4] |= PAR_EVEN;
2084 }
2085 info->zs_channel->curregs[R4] |= SB1;
2086
2087 /*
2088 * Turn on RTS and DTR.
2089 */
2090 zs_rtsdtr(info, RTS | DTR, 1);
2091
2092 /*
2093 * Finally, enable sequencing.
2094 */
2095 info->zs_channel->curregs[R3] |= RxENABLE;
2096 info->zs_channel->curregs[R5] |= TxENAB;
2097
2098 /*
2099 * Clear the interrupt registers.
2100 */
2101 write_zsreg(info->zs_channel, R0, ERR_RES);
2102 write_zsreg(info->zs_channel, R0, RES_H_IUS);
2103
2104 /*
2105 * Load up the new values.
2106 */
2107 load_zsregs(info->zs_channel, info->zs_channel->curregs);
2108
2109 /* Save the current value of RR0 */
2110 info->read_reg_zero = read_zsreg(info->zs_channel, R0);
2111
2112 zs_soft[co->index].clk_divisor = clk_divisor;
2113 zs_soft[co->index].zs_baud = get_zsbaud(&zs_soft[co->index]);
2114
2115 restore_flags(flags);
2116
2117 return 0;
2118}
2119
2120static struct console sercons = {
2121 .name = "ttyS",
2122 .write = serial_console_write,
2123 .device = serial_console_device,
2124 .setup = serial_console_setup,
2125 .flags = CON_PRINTBUFFER,
2126 .index = -1,
2127};
2128
2129/*
2130 * Register console.
2131 */
2132void __init zs_serial_console_init(void)
2133{
2134 register_console(&sercons);
2135}
2136#endif /* ifdef CONFIG_SERIAL_DEC_CONSOLE */
2137
2138#ifdef CONFIG_KGDB
2139struct dec_zschannel *zs_kgdbchan;
2140static unsigned char scc_inittab[] = {
2141 9, 0x80, /* reset A side (CHRA) */
2142 13, 0, /* set baud rate divisor */
2143 12, 1,
2144 14, 1, /* baud rate gen enable, src=rtxc (BRENABL) */
2145 11, 0x50, /* clocks = br gen (RCBR | TCBR) */
2146 5, 0x6a, /* tx 8 bits, assert RTS (Tx8 | TxENAB | RTS) */
2147 4, 0x44, /* x16 clock, 1 stop (SB1 | X16CLK)*/
2148 3, 0xc1, /* rx enable, 8 bits (RxENABLE | Rx8)*/
2149};
2150
2151/* These are for receiving and sending characters under the kgdb
2152 * source level kernel debugger.
2153 */
2154void putDebugChar(char kgdb_char)
2155{
2156 struct dec_zschannel *chan = zs_kgdbchan;
2157 while ((read_zsreg(chan, 0) & Tx_BUF_EMP) == 0)
2158 RECOVERY_DELAY;
2159 write_zsdata(chan, kgdb_char);
2160}
2161char getDebugChar(void)
2162{
2163 struct dec_zschannel *chan = zs_kgdbchan;
2164 while((read_zsreg(chan, 0) & Rx_CH_AV) == 0)
2165 eieio(); /*barrier();*/
2166 return read_zsdata(chan);
2167}
2168void kgdb_interruptible(int yes)
2169{
2170 struct dec_zschannel *chan = zs_kgdbchan;
2171 int one, nine;
2172 nine = read_zsreg(chan, 9);
2173 if (yes == 1) {
2174 one = EXT_INT_ENAB|RxINT_ALL;
2175 nine |= MIE;
2176 printk("turning serial ints on\n");
2177 } else {
2178 one = RxINT_DISAB;
2179 nine &= ~MIE;
2180 printk("turning serial ints off\n");
2181 }
2182 write_zsreg(chan, 1, one);
2183 write_zsreg(chan, 9, nine);
2184}
2185
2186static int kgdbhook_init_channel(void *handle)
2187{
2188 return 0;
2189}
2190
2191static void kgdbhook_init_info(void *handle)
2192{
2193}
2194
2195static void kgdbhook_rx_char(void *handle, unsigned char ch, unsigned char fl)
2196{
2197 struct dec_serial *info = handle;
2198
2199 if (fl != TTY_NORMAL)
2200 return;
2201 if (ch == 0x03 || ch == '$')
2202 breakpoint();
2203}
2204
2205/* This sets up the serial port we're using, and turns on
2206 * interrupts for that channel, so kgdb is usable once we're done.
2207 */
2208static inline void kgdb_chaninit(struct dec_zschannel *ms, int intson, int bps)
2209{
2210 int brg;
2211 int i, x;
2212 volatile char *sccc = ms->control;
2213 brg = BPS_TO_BRG(bps, zs_parms->clock/16);
2214 printk("setting bps on kgdb line to %d [brg=%x]\n", bps, brg);
2215 for (i = 20000; i != 0; --i) {
2216 x = *sccc; eieio();
2217 }
2218 for (i = 0; i < sizeof(scc_inittab); ++i) {
2219 write_zsreg(ms, scc_inittab[i], scc_inittab[i+1]);
2220 i++;
2221 }
2222}
2223/* This is called at boot time to prime the kgdb serial debugging
2224 * serial line. The 'tty_num' argument is 0 for /dev/ttya and 1
2225 * for /dev/ttyb which is determined in setup_arch() from the
2226 * boot command line flags.
2227 */
2228struct dec_serial_hook zs_kgdbhook = {
2229 .init_channel = kgdbhook_init_channel,
2230 .init_info = kgdbhook_init_info,
2231 .rx_char = kgdbhook_rx_char,
2232 .cflags = B38400 | CS8 | CLOCAL,
2233}
2234
2235void __init zs_kgdb_hook(int tty_num)
2236{
2237 /* Find out how many Z8530 SCCs we have */
2238 if (zs_chain == 0)
2239 probe_sccs();
2240 zs_soft[tty_num].zs_channel = &zs_channels[tty_num];
2241 zs_kgdbchan = zs_soft[tty_num].zs_channel;
2242 zs_soft[tty_num].change_needed = 0;
2243 zs_soft[tty_num].clk_divisor = 16;
2244 zs_soft[tty_num].zs_baud = 38400;
2245 zs_soft[tty_num].hook = &zs_kgdbhook; /* This runs kgdb */
2246 /* Turn on transmitter/receiver at 8-bits/char */
2247 kgdb_chaninit(zs_soft[tty_num].zs_channel, 1, 38400);
2248 printk("KGDB: on channel %d initialized\n", tty_num);
2249 set_debug_traps(); /* init stub */
2250}
2251#endif /* ifdef CONFIG_KGDB */
2252
2253
diff --git a/drivers/tc/zs.h b/drivers/tc/zs.h
new file mode 100644
index 000000000000..c52edffa6049
--- /dev/null
+++ b/drivers/tc/zs.h
@@ -0,0 +1,405 @@
1/*
2 * drivers/tc/zs.h: Definitions for the DECstation Z85C30 serial driver.
3 *
4 * Adapted from drivers/sbus/char/sunserial.h by Paul Mackerras.
5 * Adapted from drivers/macintosh/macserial.h by Harald Koerfgen.
6 *
7 * Copyright (C) 1996 Paul Mackerras (Paul.Mackerras@cs.anu.edu.au)
8 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
9 * Copyright (C) 2004 Maciej W. Rozycki
10 */
11#ifndef _DECSERIAL_H
12#define _DECSERIAL_H
13
14#include <asm/dec/serial.h>
15
16#define NUM_ZSREGS 16
17
18struct serial_struct {
19 int type;
20 int line;
21 int port;
22 int irq;
23 int flags;
24 int xmit_fifo_size;
25 int custom_divisor;
26 int baud_base;
27 unsigned short close_delay;
28 char reserved_char[2];
29 int hub6;
30 unsigned short closing_wait; /* time to wait before closing */
31 unsigned short closing_wait2; /* no longer used... */
32 int reserved[4];
33};
34
35/*
36 * For the close wait times, 0 means wait forever for serial port to
37 * flush its output. 65535 means don't wait at all.
38 */
39#define ZILOG_CLOSING_WAIT_INF 0
40#define ZILOG_CLOSING_WAIT_NONE 65535
41
42/*
43 * Definitions for ZILOG_struct (and serial_struct) flags field
44 */
45#define ZILOG_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes
46 on the callout port */
47#define ZILOG_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */
48#define ZILOG_SAK 0x0004 /* Secure Attention Key (Orange book) */
49#define ZILOG_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
50
51#define ZILOG_SPD_MASK 0x0030
52#define ZILOG_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */
53
54#define ZILOG_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */
55#define ZILOG_SPD_CUST 0x0030 /* Use user-specified divisor */
56
57#define ZILOG_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */
58#define ZILOG_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */
59#define ZILOG_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
60#define ZILOG_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */
61#define ZILOG_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */
62
63#define ZILOG_FLAGS 0x0FFF /* Possible legal ZILOG flags */
64#define ZILOG_USR_MASK 0x0430 /* Legal flags that non-privileged
65 * users can set or reset */
66
67/* Internal flags used only by kernel/chr_drv/serial.c */
68#define ZILOG_INITIALIZED 0x80000000 /* Serial port was initialized */
69#define ZILOG_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */
70#define ZILOG_NORMAL_ACTIVE 0x20000000 /* Normal device is active */
71#define ZILOG_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */
72#define ZILOG_CLOSING 0x08000000 /* Serial port is closing */
73#define ZILOG_CTS_FLOW 0x04000000 /* Do CTS flow control */
74#define ZILOG_CHECK_CD 0x02000000 /* i.e., CLOCAL */
75
76/* Software state per channel */
77
78#ifdef __KERNEL__
79/*
80 * This is our internal structure for each serial port's state.
81 *
82 * Many fields are paralleled by the structure used by the serial_struct
83 * structure.
84 *
85 * For definitions of the flags field, see tty.h
86 */
87
88struct dec_zschannel {
89 volatile unsigned char *control;
90 volatile unsigned char *data;
91
92 /* Current write register values */
93 unsigned char curregs[NUM_ZSREGS];
94};
95
96struct dec_serial {
97 struct dec_serial *zs_next; /* For IRQ servicing chain. */
98 struct dec_zschannel *zs_channel; /* Channel registers. */
99 struct dec_zschannel *zs_chan_a; /* A side registers. */
100 unsigned char read_reg_zero;
101
102 struct dec_serial_hook *hook; /* Hook on this channel. */
103 int tty_break; /* Set on BREAK condition. */
104 int is_cons; /* Is this our console. */
105 int tx_active; /* Char is being xmitted. */
106 int tx_stopped; /* Output is suspended. */
107
108 /*
109 * We need to know the current clock divisor
110 * to read the bps rate the chip has currently loaded.
111 */
112 int clk_divisor; /* May be 1, 16, 32, or 64. */
113 int zs_baud;
114
115 char change_needed;
116
117 int magic;
118 int baud_base;
119 int port;
120 int irq;
121 int flags; /* Defined in tty.h. */
122 int type; /* UART type. */
123 struct tty_struct *tty;
124 int read_status_mask;
125 int ignore_status_mask;
126 int timeout;
127 int xmit_fifo_size;
128 int custom_divisor;
129 int x_char; /* XON/XOFF character. */
130 int close_delay;
131 unsigned short closing_wait;
132 unsigned short closing_wait2;
133 unsigned long event;
134 unsigned long last_active;
135 int line;
136 int count; /* # of fds on device. */
137 int blocked_open; /* # of blocked opens. */
138 unsigned char *xmit_buf;
139 int xmit_head;
140 int xmit_tail;
141 int xmit_cnt;
142 struct tq_struct tqueue;
143 struct tq_struct tqueue_hangup;
144 wait_queue_head_t open_wait;
145 wait_queue_head_t close_wait;
146};
147
148
149#define SERIAL_MAGIC 0x5301
150
151/*
152 * The size of the serial xmit buffer is 1 page, or 4096 bytes
153 */
154#define SERIAL_XMIT_SIZE 4096
155
156/*
157 * Events are used to schedule things to happen at timer-interrupt
158 * time, instead of at rs interrupt time.
159 */
160#define RS_EVENT_WRITE_WAKEUP 0
161
162#endif /* __KERNEL__ */
163
164/* Conversion routines to/from brg time constants from/to bits
165 * per second.
166 */
167#define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
168#define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
169
170/* The Zilog register set */
171
172#define FLAG 0x7e
173
174/* Write Register 0 */
175#define R0 0 /* Register selects */
176#define R1 1
177#define R2 2
178#define R3 3
179#define R4 4
180#define R5 5
181#define R6 6
182#define R7 7
183#define R8 8
184#define R9 9
185#define R10 10
186#define R11 11
187#define R12 12
188#define R13 13
189#define R14 14
190#define R15 15
191
192#define NULLCODE 0 /* Null Code */
193#define POINT_HIGH 0x8 /* Select upper half of registers */
194#define RES_EXT_INT 0x10 /* Reset Ext. Status Interrupts */
195#define SEND_ABORT 0x18 /* HDLC Abort */
196#define RES_RxINT_FC 0x20 /* Reset RxINT on First Character */
197#define RES_Tx_P 0x28 /* Reset TxINT Pending */
198#define ERR_RES 0x30 /* Error Reset */
199#define RES_H_IUS 0x38 /* Reset highest IUS */
200
201#define RES_Rx_CRC 0x40 /* Reset Rx CRC Checker */
202#define RES_Tx_CRC 0x80 /* Reset Tx CRC Checker */
203#define RES_EOM_L 0xC0 /* Reset EOM latch */
204
205/* Write Register 1 */
206
207#define EXT_INT_ENAB 0x1 /* Ext Int Enable */
208#define TxINT_ENAB 0x2 /* Tx Int Enable */
209#define PAR_SPEC 0x4 /* Parity is special condition */
210
211#define RxINT_DISAB 0 /* Rx Int Disable */
212#define RxINT_FCERR 0x8 /* Rx Int on First Character Only or Error */
213#define RxINT_ALL 0x10 /* Int on all Rx Characters or error */
214#define RxINT_ERR 0x18 /* Int on error only */
215#define RxINT_MASK 0x18
216
217#define WT_RDY_RT 0x20 /* Wait/Ready on R/T */
218#define WT_FN_RDYFN 0x40 /* Wait/FN/Ready FN */
219#define WT_RDY_ENAB 0x80 /* Wait/Ready Enable */
220
221/* Write Register #2 (Interrupt Vector) */
222
223/* Write Register 3 */
224
225#define RxENABLE 0x1 /* Rx Enable */
226#define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */
227#define ADD_SM 0x4 /* Address Search Mode (SDLC) */
228#define RxCRC_ENAB 0x8 /* Rx CRC Enable */
229#define ENT_HM 0x10 /* Enter Hunt Mode */
230#define AUTO_ENAB 0x20 /* Auto Enables */
231#define Rx5 0x0 /* Rx 5 Bits/Character */
232#define Rx7 0x40 /* Rx 7 Bits/Character */
233#define Rx6 0x80 /* Rx 6 Bits/Character */
234#define Rx8 0xc0 /* Rx 8 Bits/Character */
235#define RxNBITS_MASK 0xc0
236
237/* Write Register 4 */
238
239#define PAR_ENA 0x1 /* Parity Enable */
240#define PAR_EVEN 0x2 /* Parity Even/Odd* */
241
242#define SYNC_ENAB 0 /* Sync Modes Enable */
243#define SB1 0x4 /* 1 stop bit/char */
244#define SB15 0x8 /* 1.5 stop bits/char */
245#define SB2 0xc /* 2 stop bits/char */
246#define SB_MASK 0xc
247
248#define MONSYNC 0 /* 8 Bit Sync character */
249#define BISYNC 0x10 /* 16 bit sync character */
250#define SDLC 0x20 /* SDLC Mode (01111110 Sync Flag) */
251#define EXTSYNC 0x30 /* External Sync Mode */
252
253#define X1CLK 0x0 /* x1 clock mode */
254#define X16CLK 0x40 /* x16 clock mode */
255#define X32CLK 0x80 /* x32 clock mode */
256#define X64CLK 0xC0 /* x64 clock mode */
257#define XCLK_MASK 0xC0
258
259/* Write Register 5 */
260
261#define TxCRC_ENAB 0x1 /* Tx CRC Enable */
262#define RTS 0x2 /* RTS */
263#define SDLC_CRC 0x4 /* SDLC/CRC-16 */
264#define TxENAB 0x8 /* Tx Enable */
265#define SND_BRK 0x10 /* Send Break */
266#define Tx5 0x0 /* Tx 5 bits (or less)/character */
267#define Tx7 0x20 /* Tx 7 bits/character */
268#define Tx6 0x40 /* Tx 6 bits/character */
269#define Tx8 0x60 /* Tx 8 bits/character */
270#define TxNBITS_MASK 0x60
271#define DTR 0x80 /* DTR */
272
273/* Write Register 6 (Sync bits 0-7/SDLC Address Field) */
274
275/* Write Register 7 (Sync bits 8-15/SDLC 01111110) */
276
277/* Write Register 8 (transmit buffer) */
278
279/* Write Register 9 (Master interrupt control) */
280#define VIS 1 /* Vector Includes Status */
281#define NV 2 /* No Vector */
282#define DLC 4 /* Disable Lower Chain */
283#define MIE 8 /* Master Interrupt Enable */
284#define STATHI 0x10 /* Status high */
285#define SOFTACK 0x20 /* Software Interrupt Acknowledge */
286#define NORESET 0 /* No reset on write to R9 */
287#define CHRB 0x40 /* Reset channel B */
288#define CHRA 0x80 /* Reset channel A */
289#define FHWRES 0xc0 /* Force hardware reset */
290
291/* Write Register 10 (misc control bits) */
292#define BIT6 1 /* 6 bit/8bit sync */
293#define LOOPMODE 2 /* SDLC Loop mode */
294#define ABUNDER 4 /* Abort/flag on SDLC xmit underrun */
295#define MARKIDLE 8 /* Mark/flag on idle */
296#define GAOP 0x10 /* Go active on poll */
297#define NRZ 0 /* NRZ mode */
298#define NRZI 0x20 /* NRZI mode */
299#define FM1 0x40 /* FM1 (transition = 1) */
300#define FM0 0x60 /* FM0 (transition = 0) */
301#define CRCPS 0x80 /* CRC Preset I/O */
302
303/* Write Register 11 (Clock Mode control) */
304#define TRxCXT 0 /* TRxC = Xtal output */
305#define TRxCTC 1 /* TRxC = Transmit clock */
306#define TRxCBR 2 /* TRxC = BR Generator Output */
307#define TRxCDP 3 /* TRxC = DPLL output */
308#define TRxCOI 4 /* TRxC O/I */
309#define TCRTxCP 0 /* Transmit clock = RTxC pin */
310#define TCTRxCP 8 /* Transmit clock = TRxC pin */
311#define TCBR 0x10 /* Transmit clock = BR Generator output */
312#define TCDPLL 0x18 /* Transmit clock = DPLL output */
313#define RCRTxCP 0 /* Receive clock = RTxC pin */
314#define RCTRxCP 0x20 /* Receive clock = TRxC pin */
315#define RCBR 0x40 /* Receive clock = BR Generator output */
316#define RCDPLL 0x60 /* Receive clock = DPLL output */
317#define RTxCX 0x80 /* RTxC Xtal/No Xtal */
318
319/* Write Register 12 (lower byte of baud rate generator time constant) */
320
321/* Write Register 13 (upper byte of baud rate generator time constant) */
322
323/* Write Register 14 (Misc control bits) */
324#define BRENABL 1 /* Baud rate generator enable */
325#define BRSRC 2 /* Baud rate generator source */
326#define DTRREQ 4 /* DTR/Request function */
327#define AUTOECHO 8 /* Auto Echo */
328#define LOOPBAK 0x10 /* Local loopback */
329#define SEARCH 0x20 /* Enter search mode */
330#define RMC 0x40 /* Reset missing clock */
331#define DISDPLL 0x60 /* Disable DPLL */
332#define SSBR 0x80 /* Set DPLL source = BR generator */
333#define SSRTxC 0xa0 /* Set DPLL source = RTxC */
334#define SFMM 0xc0 /* Set FM mode */
335#define SNRZI 0xe0 /* Set NRZI mode */
336
337/* Write Register 15 (external/status interrupt control) */
338#define ZCIE 2 /* Zero count IE */
339#define DCDIE 8 /* DCD IE */
340#define SYNCIE 0x10 /* Sync/hunt IE */
341#define CTSIE 0x20 /* CTS IE */
342#define TxUIE 0x40 /* Tx Underrun/EOM IE */
343#define BRKIE 0x80 /* Break/Abort IE */
344
345
346/* Read Register 0 */
347#define Rx_CH_AV 0x1 /* Rx Character Available */
348#define ZCOUNT 0x2 /* Zero count */
349#define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
350#define DCD 0x8 /* DCD */
351#define SYNC_HUNT 0x10 /* Sync/hunt */
352#define CTS 0x20 /* CTS */
353#define TxEOM 0x40 /* Tx underrun */
354#define BRK_ABRT 0x80 /* Break/Abort */
355
356/* Read Register 1 */
357#define ALL_SNT 0x1 /* All sent */
358/* Residue Data for 8 Rx bits/char programmed */
359#define RES3 0x8 /* 0/3 */
360#define RES4 0x4 /* 0/4 */
361#define RES5 0xc /* 0/5 */
362#define RES6 0x2 /* 0/6 */
363#define RES7 0xa /* 0/7 */
364#define RES8 0x6 /* 0/8 */
365#define RES18 0xe /* 1/8 */
366#define RES28 0x0 /* 2/8 */
367/* Special Rx Condition Interrupts */
368#define PAR_ERR 0x10 /* Parity error */
369#define Rx_OVR 0x20 /* Rx Overrun Error */
370#define FRM_ERR 0x40 /* CRC/Framing Error */
371#define END_FR 0x80 /* End of Frame (SDLC) */
372
373/* Read Register 2 (channel b only) - Interrupt vector */
374
375/* Read Register 3 (interrupt pending register) ch a only */
376#define CHBEXT 0x1 /* Channel B Ext/Stat IP */
377#define CHBTxIP 0x2 /* Channel B Tx IP */
378#define CHBRxIP 0x4 /* Channel B Rx IP */
379#define CHAEXT 0x8 /* Channel A Ext/Stat IP */
380#define CHATxIP 0x10 /* Channel A Tx IP */
381#define CHARxIP 0x20 /* Channel A Rx IP */
382
383/* Read Register 8 (receive data register) */
384
385/* Read Register 10 (misc status bits) */
386#define ONLOOP 2 /* On loop */
387#define LOOPSEND 0x10 /* Loop sending */
388#define CLK2MIS 0x40 /* Two clocks missing */
389#define CLK1MIS 0x80 /* One clock missing */
390
391/* Read Register 12 (lower byte of baud rate generator constant) */
392
393/* Read Register 13 (upper byte of baud rate generator constant) */
394
395/* Read Register 15 (value of WR 15) */
396
397/* Misc macros */
398#define ZS_CLEARERR(channel) (write_zsreg(channel, 0, ERR_RES))
399#define ZS_CLEARFIFO(channel) do { volatile unsigned char garbage; \
400 garbage = read_zsdata(channel); \
401 garbage = read_zsdata(channel); \
402 garbage = read_zsdata(channel); \
403 } while(0)
404
405#endif /* !(_DECSERIAL_H) */