Commit 56578abfd16a1a7554f64000d5fc0a377d4dda6a
Committed by
Linus Torvalds
1 parent
dfa7c4d869
Exists in
master
and in
7 other branches
bfin_jtag_comm: clean up printk usage
The original patch garned some feedback and a v2 was posted, but that version seems to have been missed when merging the driver. At any rate, this cleans up the printk usage as suggested by Jiri Slaby. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 15 additions and 15 deletions Inline Diff
drivers/char/bfin_jtag_comm.c
1 | /* | 1 | /* |
2 | * TTY over Blackfin JTAG Communication | 2 | * TTY over Blackfin JTAG Communication |
3 | * | 3 | * |
4 | * Copyright 2008-2009 Analog Devices Inc. | 4 | * Copyright 2008-2009 Analog Devices Inc. |
5 | * | 5 | * |
6 | * Enter bugs at http://blackfin.uclinux.org/ | 6 | * Enter bugs at http://blackfin.uclinux.org/ |
7 | * | 7 | * |
8 | * Licensed under the GPL-2 or later. | 8 | * Licensed under the GPL-2 or later. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #define DRV_NAME "bfin-jtag-comm" | ||
12 | #define DEV_NAME "ttyBFJC" | ||
13 | #define pr_fmt(fmt) DRV_NAME ": " fmt | ||
14 | |||
11 | #include <linux/circ_buf.h> | 15 | #include <linux/circ_buf.h> |
12 | #include <linux/console.h> | 16 | #include <linux/console.h> |
13 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
14 | #include <linux/err.h> | 18 | #include <linux/err.h> |
15 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
16 | #include <linux/kthread.h> | 20 | #include <linux/kthread.h> |
17 | #include <linux/module.h> | 21 | #include <linux/module.h> |
18 | #include <linux/mutex.h> | 22 | #include <linux/mutex.h> |
19 | #include <linux/sched.h> | 23 | #include <linux/sched.h> |
20 | #include <linux/tty.h> | 24 | #include <linux/tty.h> |
21 | #include <linux/tty_driver.h> | 25 | #include <linux/tty_driver.h> |
22 | #include <linux/tty_flip.h> | 26 | #include <linux/tty_flip.h> |
23 | #include <asm/atomic.h> | 27 | #include <asm/atomic.h> |
24 | 28 | ||
29 | #define pr_init(fmt, args...) ({ static const __initconst char __fmt[] = fmt; printk(__fmt, ## args); }) | ||
30 | |||
25 | /* See the Debug/Emulation chapter in the HRM */ | 31 | /* See the Debug/Emulation chapter in the HRM */ |
26 | #define EMUDOF 0x00000001 /* EMUDAT_OUT full & valid */ | 32 | #define EMUDOF 0x00000001 /* EMUDAT_OUT full & valid */ |
27 | #define EMUDIF 0x00000002 /* EMUDAT_IN full & valid */ | 33 | #define EMUDIF 0x00000002 /* EMUDAT_IN full & valid */ |
28 | #define EMUDOOVF 0x00000004 /* EMUDAT_OUT overflow */ | 34 | #define EMUDOOVF 0x00000004 /* EMUDAT_OUT overflow */ |
29 | #define EMUDIOVF 0x00000008 /* EMUDAT_IN overflow */ | 35 | #define EMUDIOVF 0x00000008 /* EMUDAT_IN overflow */ |
30 | 36 | ||
31 | #define DRV_NAME "bfin-jtag-comm" | ||
32 | #define DEV_NAME "ttyBFJC" | ||
33 | |||
34 | #define pr_init(fmt, args...) ({ static const __initdata char __fmt[] = fmt; printk(__fmt, ## args); }) | ||
35 | #define debug(fmt, args...) pr_debug(DRV_NAME ": " fmt, ## args) | ||
36 | |||
37 | static inline uint32_t bfin_write_emudat(uint32_t emudat) | 37 | static inline uint32_t bfin_write_emudat(uint32_t emudat) |
38 | { | 38 | { |
39 | __asm__ __volatile__("emudat = %0;" : : "d"(emudat)); | 39 | __asm__ __volatile__("emudat = %0;" : : "d"(emudat)); |
40 | return emudat; | 40 | return emudat; |
41 | } | 41 | } |
42 | 42 | ||
43 | static inline uint32_t bfin_read_emudat(void) | 43 | static inline uint32_t bfin_read_emudat(void) |
44 | { | 44 | { |
45 | uint32_t emudat; | 45 | uint32_t emudat; |
46 | __asm__ __volatile__("%0 = emudat;" : "=d"(emudat)); | 46 | __asm__ __volatile__("%0 = emudat;" : "=d"(emudat)); |
47 | return emudat; | 47 | return emudat; |
48 | } | 48 | } |
49 | 49 | ||
50 | static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d) | 50 | static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d) |
51 | { | 51 | { |
52 | return bfin_write_emudat((a << 0) | (b << 8) | (c << 16) | (d << 24)); | 52 | return bfin_write_emudat((a << 0) | (b << 8) | (c << 16) | (d << 24)); |
53 | } | 53 | } |
54 | 54 | ||
55 | #define CIRC_SIZE 2048 /* see comment in tty_io.c:do_tty_write() */ | 55 | #define CIRC_SIZE 2048 /* see comment in tty_io.c:do_tty_write() */ |
56 | #define CIRC_MASK (CIRC_SIZE - 1) | 56 | #define CIRC_MASK (CIRC_SIZE - 1) |
57 | #define circ_empty(circ) ((circ)->head == (circ)->tail) | 57 | #define circ_empty(circ) ((circ)->head == (circ)->tail) |
58 | #define circ_free(circ) CIRC_SPACE((circ)->head, (circ)->tail, CIRC_SIZE) | 58 | #define circ_free(circ) CIRC_SPACE((circ)->head, (circ)->tail, CIRC_SIZE) |
59 | #define circ_cnt(circ) CIRC_CNT((circ)->head, (circ)->tail, CIRC_SIZE) | 59 | #define circ_cnt(circ) CIRC_CNT((circ)->head, (circ)->tail, CIRC_SIZE) |
60 | #define circ_byte(circ, idx) ((circ)->buf[(idx) & CIRC_MASK]) | 60 | #define circ_byte(circ, idx) ((circ)->buf[(idx) & CIRC_MASK]) |
61 | 61 | ||
62 | static struct tty_driver *bfin_jc_driver; | 62 | static struct tty_driver *bfin_jc_driver; |
63 | static struct task_struct *bfin_jc_kthread; | 63 | static struct task_struct *bfin_jc_kthread; |
64 | static struct tty_struct * volatile bfin_jc_tty; | 64 | static struct tty_struct * volatile bfin_jc_tty; |
65 | static unsigned long bfin_jc_count; | 65 | static unsigned long bfin_jc_count; |
66 | static DEFINE_MUTEX(bfin_jc_tty_mutex); | 66 | static DEFINE_MUTEX(bfin_jc_tty_mutex); |
67 | static volatile struct circ_buf bfin_jc_write_buf; | 67 | static volatile struct circ_buf bfin_jc_write_buf; |
68 | 68 | ||
69 | static int | 69 | static int |
70 | bfin_jc_emudat_manager(void *arg) | 70 | bfin_jc_emudat_manager(void *arg) |
71 | { | 71 | { |
72 | uint32_t inbound_len = 0, outbound_len = 0; | 72 | uint32_t inbound_len = 0, outbound_len = 0; |
73 | 73 | ||
74 | while (!kthread_should_stop()) { | 74 | while (!kthread_should_stop()) { |
75 | /* no one left to give data to, so sleep */ | 75 | /* no one left to give data to, so sleep */ |
76 | if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) { | 76 | if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) { |
77 | debug("waiting for readers\n"); | 77 | pr_debug("waiting for readers\n"); |
78 | __set_current_state(TASK_UNINTERRUPTIBLE); | 78 | __set_current_state(TASK_UNINTERRUPTIBLE); |
79 | schedule(); | 79 | schedule(); |
80 | __set_current_state(TASK_RUNNING); | 80 | __set_current_state(TASK_RUNNING); |
81 | } | 81 | } |
82 | 82 | ||
83 | /* no data available, so just chill */ | 83 | /* no data available, so just chill */ |
84 | if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { | 84 | if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { |
85 | debug("waiting for data (in_len = %i) (circ: %i %i)\n", | 85 | pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n", |
86 | inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); | 86 | inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); |
87 | if (inbound_len) | 87 | if (inbound_len) |
88 | schedule(); | 88 | schedule(); |
89 | else | 89 | else |
90 | schedule_timeout_interruptible(HZ); | 90 | schedule_timeout_interruptible(HZ); |
91 | continue; | 91 | continue; |
92 | } | 92 | } |
93 | 93 | ||
94 | /* if incoming data is ready, eat it */ | 94 | /* if incoming data is ready, eat it */ |
95 | if (bfin_read_DBGSTAT() & EMUDIF) { | 95 | if (bfin_read_DBGSTAT() & EMUDIF) { |
96 | struct tty_struct *tty; | 96 | struct tty_struct *tty; |
97 | mutex_lock(&bfin_jc_tty_mutex); | 97 | mutex_lock(&bfin_jc_tty_mutex); |
98 | tty = (struct tty_struct *)bfin_jc_tty; | 98 | tty = (struct tty_struct *)bfin_jc_tty; |
99 | if (tty != NULL) { | 99 | if (tty != NULL) { |
100 | uint32_t emudat = bfin_read_emudat(); | 100 | uint32_t emudat = bfin_read_emudat(); |
101 | if (inbound_len == 0) { | 101 | if (inbound_len == 0) { |
102 | debug("incoming length: 0x%08x\n", emudat); | 102 | pr_debug("incoming length: 0x%08x\n", emudat); |
103 | inbound_len = emudat; | 103 | inbound_len = emudat; |
104 | } else { | 104 | } else { |
105 | size_t num_chars = (4 <= inbound_len ? 4 : inbound_len); | 105 | size_t num_chars = (4 <= inbound_len ? 4 : inbound_len); |
106 | debug(" incoming data: 0x%08x (pushing %zu)\n", emudat, num_chars); | 106 | pr_debug(" incoming data: 0x%08x (pushing %zu)\n", emudat, num_chars); |
107 | inbound_len -= num_chars; | 107 | inbound_len -= num_chars; |
108 | tty_insert_flip_string(tty, (unsigned char *)&emudat, num_chars); | 108 | tty_insert_flip_string(tty, (unsigned char *)&emudat, num_chars); |
109 | tty_flip_buffer_push(tty); | 109 | tty_flip_buffer_push(tty); |
110 | } | 110 | } |
111 | } | 111 | } |
112 | mutex_unlock(&bfin_jc_tty_mutex); | 112 | mutex_unlock(&bfin_jc_tty_mutex); |
113 | } | 113 | } |
114 | 114 | ||
115 | /* if outgoing data is ready, post it */ | 115 | /* if outgoing data is ready, post it */ |
116 | if (!(bfin_read_DBGSTAT() & EMUDOF) && !circ_empty(&bfin_jc_write_buf)) { | 116 | if (!(bfin_read_DBGSTAT() & EMUDOF) && !circ_empty(&bfin_jc_write_buf)) { |
117 | if (outbound_len == 0) { | 117 | if (outbound_len == 0) { |
118 | outbound_len = circ_cnt(&bfin_jc_write_buf); | 118 | outbound_len = circ_cnt(&bfin_jc_write_buf); |
119 | bfin_write_emudat(outbound_len); | 119 | bfin_write_emudat(outbound_len); |
120 | debug("outgoing length: 0x%08x\n", outbound_len); | 120 | pr_debug("outgoing length: 0x%08x\n", outbound_len); |
121 | } else { | 121 | } else { |
122 | struct tty_struct *tty; | 122 | struct tty_struct *tty; |
123 | int tail = bfin_jc_write_buf.tail; | 123 | int tail = bfin_jc_write_buf.tail; |
124 | size_t ate = (4 <= outbound_len ? 4 : outbound_len); | 124 | size_t ate = (4 <= outbound_len ? 4 : outbound_len); |
125 | uint32_t emudat = | 125 | uint32_t emudat = |
126 | bfin_write_emudat_chars( | 126 | bfin_write_emudat_chars( |
127 | circ_byte(&bfin_jc_write_buf, tail + 0), | 127 | circ_byte(&bfin_jc_write_buf, tail + 0), |
128 | circ_byte(&bfin_jc_write_buf, tail + 1), | 128 | circ_byte(&bfin_jc_write_buf, tail + 1), |
129 | circ_byte(&bfin_jc_write_buf, tail + 2), | 129 | circ_byte(&bfin_jc_write_buf, tail + 2), |
130 | circ_byte(&bfin_jc_write_buf, tail + 3) | 130 | circ_byte(&bfin_jc_write_buf, tail + 3) |
131 | ); | 131 | ); |
132 | bfin_jc_write_buf.tail += ate; | 132 | bfin_jc_write_buf.tail += ate; |
133 | outbound_len -= ate; | 133 | outbound_len -= ate; |
134 | mutex_lock(&bfin_jc_tty_mutex); | 134 | mutex_lock(&bfin_jc_tty_mutex); |
135 | tty = (struct tty_struct *)bfin_jc_tty; | 135 | tty = (struct tty_struct *)bfin_jc_tty; |
136 | if (tty) | 136 | if (tty) |
137 | tty_wakeup(tty); | 137 | tty_wakeup(tty); |
138 | mutex_unlock(&bfin_jc_tty_mutex); | 138 | mutex_unlock(&bfin_jc_tty_mutex); |
139 | debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); | 139 | pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | __set_current_state(TASK_RUNNING); | 144 | __set_current_state(TASK_RUNNING); |
145 | return 0; | 145 | return 0; |
146 | } | 146 | } |
147 | 147 | ||
148 | static int | 148 | static int |
149 | bfin_jc_open(struct tty_struct *tty, struct file *filp) | 149 | bfin_jc_open(struct tty_struct *tty, struct file *filp) |
150 | { | 150 | { |
151 | mutex_lock(&bfin_jc_tty_mutex); | 151 | mutex_lock(&bfin_jc_tty_mutex); |
152 | debug("open %lu\n", bfin_jc_count); | 152 | pr_debug("open %lu\n", bfin_jc_count); |
153 | ++bfin_jc_count; | 153 | ++bfin_jc_count; |
154 | bfin_jc_tty = tty; | 154 | bfin_jc_tty = tty; |
155 | wake_up_process(bfin_jc_kthread); | 155 | wake_up_process(bfin_jc_kthread); |
156 | mutex_unlock(&bfin_jc_tty_mutex); | 156 | mutex_unlock(&bfin_jc_tty_mutex); |
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | 159 | ||
160 | static void | 160 | static void |
161 | bfin_jc_close(struct tty_struct *tty, struct file *filp) | 161 | bfin_jc_close(struct tty_struct *tty, struct file *filp) |
162 | { | 162 | { |
163 | mutex_lock(&bfin_jc_tty_mutex); | 163 | mutex_lock(&bfin_jc_tty_mutex); |
164 | debug("close %lu\n", bfin_jc_count); | 164 | pr_debug("close %lu\n", bfin_jc_count); |
165 | if (--bfin_jc_count == 0) | 165 | if (--bfin_jc_count == 0) |
166 | bfin_jc_tty = NULL; | 166 | bfin_jc_tty = NULL; |
167 | wake_up_process(bfin_jc_kthread); | 167 | wake_up_process(bfin_jc_kthread); |
168 | mutex_unlock(&bfin_jc_tty_mutex); | 168 | mutex_unlock(&bfin_jc_tty_mutex); |
169 | } | 169 | } |
170 | 170 | ||
171 | /* XXX: we dont handle the put_char() case where we must handle count = 1 */ | 171 | /* XXX: we dont handle the put_char() case where we must handle count = 1 */ |
172 | static int | 172 | static int |
173 | bfin_jc_circ_write(const unsigned char *buf, int count) | 173 | bfin_jc_circ_write(const unsigned char *buf, int count) |
174 | { | 174 | { |
175 | int i; | 175 | int i; |
176 | count = min(count, circ_free(&bfin_jc_write_buf)); | 176 | count = min(count, circ_free(&bfin_jc_write_buf)); |
177 | debug("going to write chunk of %i bytes\n", count); | 177 | pr_debug("going to write chunk of %i bytes\n", count); |
178 | for (i = 0; i < count; ++i) | 178 | for (i = 0; i < count; ++i) |
179 | circ_byte(&bfin_jc_write_buf, bfin_jc_write_buf.head + i) = buf[i]; | 179 | circ_byte(&bfin_jc_write_buf, bfin_jc_write_buf.head + i) = buf[i]; |
180 | bfin_jc_write_buf.head += i; | 180 | bfin_jc_write_buf.head += i; |
181 | return i; | 181 | return i; |
182 | } | 182 | } |
183 | 183 | ||
184 | #ifndef CONFIG_BFIN_JTAG_COMM_CONSOLE | 184 | #ifndef CONFIG_BFIN_JTAG_COMM_CONSOLE |
185 | # define acquire_console_sem() | 185 | # define acquire_console_sem() |
186 | # define release_console_sem() | 186 | # define release_console_sem() |
187 | #endif | 187 | #endif |
188 | static int | 188 | static int |
189 | bfin_jc_write(struct tty_struct *tty, const unsigned char *buf, int count) | 189 | bfin_jc_write(struct tty_struct *tty, const unsigned char *buf, int count) |
190 | { | 190 | { |
191 | int i; | 191 | int i; |
192 | acquire_console_sem(); | 192 | acquire_console_sem(); |
193 | i = bfin_jc_circ_write(buf, count); | 193 | i = bfin_jc_circ_write(buf, count); |
194 | release_console_sem(); | 194 | release_console_sem(); |
195 | wake_up_process(bfin_jc_kthread); | 195 | wake_up_process(bfin_jc_kthread); |
196 | return i; | 196 | return i; |
197 | } | 197 | } |
198 | 198 | ||
199 | static void | 199 | static void |
200 | bfin_jc_flush_chars(struct tty_struct *tty) | 200 | bfin_jc_flush_chars(struct tty_struct *tty) |
201 | { | 201 | { |
202 | wake_up_process(bfin_jc_kthread); | 202 | wake_up_process(bfin_jc_kthread); |
203 | } | 203 | } |
204 | 204 | ||
205 | static int | 205 | static int |
206 | bfin_jc_write_room(struct tty_struct *tty) | 206 | bfin_jc_write_room(struct tty_struct *tty) |
207 | { | 207 | { |
208 | return circ_free(&bfin_jc_write_buf); | 208 | return circ_free(&bfin_jc_write_buf); |
209 | } | 209 | } |
210 | 210 | ||
211 | static int | 211 | static int |
212 | bfin_jc_chars_in_buffer(struct tty_struct *tty) | 212 | bfin_jc_chars_in_buffer(struct tty_struct *tty) |
213 | { | 213 | { |
214 | return circ_cnt(&bfin_jc_write_buf); | 214 | return circ_cnt(&bfin_jc_write_buf); |
215 | } | 215 | } |
216 | 216 | ||
217 | static void | 217 | static void |
218 | bfin_jc_wait_until_sent(struct tty_struct *tty, int timeout) | 218 | bfin_jc_wait_until_sent(struct tty_struct *tty, int timeout) |
219 | { | 219 | { |
220 | unsigned long expire = jiffies + timeout; | 220 | unsigned long expire = jiffies + timeout; |
221 | while (!circ_empty(&bfin_jc_write_buf)) { | 221 | while (!circ_empty(&bfin_jc_write_buf)) { |
222 | if (signal_pending(current)) | 222 | if (signal_pending(current)) |
223 | break; | 223 | break; |
224 | if (time_after(jiffies, expire)) | 224 | if (time_after(jiffies, expire)) |
225 | break; | 225 | break; |
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
229 | static struct tty_operations bfin_jc_ops = { | 229 | static struct tty_operations bfin_jc_ops = { |
230 | .open = bfin_jc_open, | 230 | .open = bfin_jc_open, |
231 | .close = bfin_jc_close, | 231 | .close = bfin_jc_close, |
232 | .write = bfin_jc_write, | 232 | .write = bfin_jc_write, |
233 | /*.put_char = bfin_jc_put_char,*/ | 233 | /*.put_char = bfin_jc_put_char,*/ |
234 | .flush_chars = bfin_jc_flush_chars, | 234 | .flush_chars = bfin_jc_flush_chars, |
235 | .write_room = bfin_jc_write_room, | 235 | .write_room = bfin_jc_write_room, |
236 | .chars_in_buffer = bfin_jc_chars_in_buffer, | 236 | .chars_in_buffer = bfin_jc_chars_in_buffer, |
237 | .wait_until_sent = bfin_jc_wait_until_sent, | 237 | .wait_until_sent = bfin_jc_wait_until_sent, |
238 | }; | 238 | }; |
239 | 239 | ||
240 | static int __init bfin_jc_init(void) | 240 | static int __init bfin_jc_init(void) |
241 | { | 241 | { |
242 | int ret; | 242 | int ret; |
243 | 243 | ||
244 | bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME); | 244 | bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME); |
245 | if (IS_ERR(bfin_jc_kthread)) | 245 | if (IS_ERR(bfin_jc_kthread)) |
246 | return PTR_ERR(bfin_jc_kthread); | 246 | return PTR_ERR(bfin_jc_kthread); |
247 | 247 | ||
248 | ret = -ENOMEM; | 248 | ret = -ENOMEM; |
249 | 249 | ||
250 | bfin_jc_write_buf.head = bfin_jc_write_buf.tail = 0; | 250 | bfin_jc_write_buf.head = bfin_jc_write_buf.tail = 0; |
251 | bfin_jc_write_buf.buf = kmalloc(CIRC_SIZE, GFP_KERNEL); | 251 | bfin_jc_write_buf.buf = kmalloc(CIRC_SIZE, GFP_KERNEL); |
252 | if (!bfin_jc_write_buf.buf) | 252 | if (!bfin_jc_write_buf.buf) |
253 | goto err; | 253 | goto err; |
254 | 254 | ||
255 | bfin_jc_driver = alloc_tty_driver(1); | 255 | bfin_jc_driver = alloc_tty_driver(1); |
256 | if (!bfin_jc_driver) | 256 | if (!bfin_jc_driver) |
257 | goto err; | 257 | goto err; |
258 | 258 | ||
259 | bfin_jc_driver->owner = THIS_MODULE; | 259 | bfin_jc_driver->owner = THIS_MODULE; |
260 | bfin_jc_driver->driver_name = DRV_NAME; | 260 | bfin_jc_driver->driver_name = DRV_NAME; |
261 | bfin_jc_driver->name = DEV_NAME; | 261 | bfin_jc_driver->name = DEV_NAME; |
262 | bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL; | 262 | bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL; |
263 | bfin_jc_driver->subtype = SERIAL_TYPE_NORMAL; | 263 | bfin_jc_driver->subtype = SERIAL_TYPE_NORMAL; |
264 | bfin_jc_driver->init_termios = tty_std_termios; | 264 | bfin_jc_driver->init_termios = tty_std_termios; |
265 | tty_set_operations(bfin_jc_driver, &bfin_jc_ops); | 265 | tty_set_operations(bfin_jc_driver, &bfin_jc_ops); |
266 | 266 | ||
267 | ret = tty_register_driver(bfin_jc_driver); | 267 | ret = tty_register_driver(bfin_jc_driver); |
268 | if (ret) | 268 | if (ret) |
269 | goto err; | 269 | goto err; |
270 | 270 | ||
271 | pr_init(KERN_INFO DRV_NAME ": initialized\n"); | 271 | pr_init(KERN_INFO DRV_NAME ": initialized\n"); |
272 | 272 | ||
273 | return 0; | 273 | return 0; |
274 | 274 | ||
275 | err: | 275 | err: |
276 | put_tty_driver(bfin_jc_driver); | 276 | put_tty_driver(bfin_jc_driver); |
277 | kfree(bfin_jc_write_buf.buf); | 277 | kfree(bfin_jc_write_buf.buf); |
278 | kthread_stop(bfin_jc_kthread); | 278 | kthread_stop(bfin_jc_kthread); |
279 | return ret; | 279 | return ret; |
280 | } | 280 | } |
281 | module_init(bfin_jc_init); | 281 | module_init(bfin_jc_init); |
282 | 282 | ||
283 | static void __exit bfin_jc_exit(void) | 283 | static void __exit bfin_jc_exit(void) |
284 | { | 284 | { |
285 | kthread_stop(bfin_jc_kthread); | 285 | kthread_stop(bfin_jc_kthread); |
286 | kfree(bfin_jc_write_buf.buf); | 286 | kfree(bfin_jc_write_buf.buf); |
287 | tty_unregister_driver(bfin_jc_driver); | 287 | tty_unregister_driver(bfin_jc_driver); |
288 | put_tty_driver(bfin_jc_driver); | 288 | put_tty_driver(bfin_jc_driver); |
289 | } | 289 | } |
290 | module_exit(bfin_jc_exit); | 290 | module_exit(bfin_jc_exit); |
291 | 291 | ||
292 | #if defined(CONFIG_BFIN_JTAG_COMM_CONSOLE) || defined(CONFIG_EARLY_PRINTK) | 292 | #if defined(CONFIG_BFIN_JTAG_COMM_CONSOLE) || defined(CONFIG_EARLY_PRINTK) |
293 | static void | 293 | static void |
294 | bfin_jc_straight_buffer_write(const char *buf, unsigned count) | 294 | bfin_jc_straight_buffer_write(const char *buf, unsigned count) |
295 | { | 295 | { |
296 | unsigned ate = 0; | 296 | unsigned ate = 0; |
297 | while (bfin_read_DBGSTAT() & EMUDOF) | 297 | while (bfin_read_DBGSTAT() & EMUDOF) |
298 | continue; | 298 | continue; |
299 | bfin_write_emudat(count); | 299 | bfin_write_emudat(count); |
300 | while (ate < count) { | 300 | while (ate < count) { |
301 | while (bfin_read_DBGSTAT() & EMUDOF) | 301 | while (bfin_read_DBGSTAT() & EMUDOF) |
302 | continue; | 302 | continue; |
303 | bfin_write_emudat_chars(buf[ate], buf[ate+1], buf[ate+2], buf[ate+3]); | 303 | bfin_write_emudat_chars(buf[ate], buf[ate+1], buf[ate+2], buf[ate+3]); |
304 | ate += 4; | 304 | ate += 4; |
305 | } | 305 | } |
306 | } | 306 | } |
307 | #endif | 307 | #endif |
308 | 308 | ||
309 | #ifdef CONFIG_BFIN_JTAG_COMM_CONSOLE | 309 | #ifdef CONFIG_BFIN_JTAG_COMM_CONSOLE |
310 | static void | 310 | static void |
311 | bfin_jc_console_write(struct console *co, const char *buf, unsigned count) | 311 | bfin_jc_console_write(struct console *co, const char *buf, unsigned count) |
312 | { | 312 | { |
313 | if (bfin_jc_kthread == NULL) | 313 | if (bfin_jc_kthread == NULL) |
314 | bfin_jc_straight_buffer_write(buf, count); | 314 | bfin_jc_straight_buffer_write(buf, count); |
315 | else | 315 | else |
316 | bfin_jc_circ_write(buf, count); | 316 | bfin_jc_circ_write(buf, count); |
317 | } | 317 | } |
318 | 318 | ||
319 | static struct tty_driver * | 319 | static struct tty_driver * |
320 | bfin_jc_console_device(struct console *co, int *index) | 320 | bfin_jc_console_device(struct console *co, int *index) |
321 | { | 321 | { |
322 | *index = co->index; | 322 | *index = co->index; |
323 | return bfin_jc_driver; | 323 | return bfin_jc_driver; |
324 | } | 324 | } |
325 | 325 | ||
326 | static struct console bfin_jc_console = { | 326 | static struct console bfin_jc_console = { |
327 | .name = DEV_NAME, | 327 | .name = DEV_NAME, |
328 | .write = bfin_jc_console_write, | 328 | .write = bfin_jc_console_write, |
329 | .device = bfin_jc_console_device, | 329 | .device = bfin_jc_console_device, |
330 | .flags = CON_ANYTIME | CON_PRINTBUFFER, | 330 | .flags = CON_ANYTIME | CON_PRINTBUFFER, |
331 | .index = -1, | 331 | .index = -1, |
332 | }; | 332 | }; |
333 | 333 | ||
334 | static int __init bfin_jc_console_init(void) | 334 | static int __init bfin_jc_console_init(void) |
335 | { | 335 | { |
336 | register_console(&bfin_jc_console); | 336 | register_console(&bfin_jc_console); |
337 | return 0; | 337 | return 0; |
338 | } | 338 | } |
339 | console_initcall(bfin_jc_console_init); | 339 | console_initcall(bfin_jc_console_init); |
340 | #endif | 340 | #endif |
341 | 341 | ||
342 | #ifdef CONFIG_EARLY_PRINTK | 342 | #ifdef CONFIG_EARLY_PRINTK |
343 | static void __init | 343 | static void __init |
344 | bfin_jc_early_write(struct console *co, const char *buf, unsigned int count) | 344 | bfin_jc_early_write(struct console *co, const char *buf, unsigned int count) |
345 | { | 345 | { |
346 | bfin_jc_straight_buffer_write(buf, count); | 346 | bfin_jc_straight_buffer_write(buf, count); |
347 | } | 347 | } |
348 | 348 | ||
349 | static struct __initdata console bfin_jc_early_console = { | 349 | static struct __initdata console bfin_jc_early_console = { |
350 | .name = "early_BFJC", | 350 | .name = "early_BFJC", |
351 | .write = bfin_jc_early_write, | 351 | .write = bfin_jc_early_write, |
352 | .flags = CON_ANYTIME | CON_PRINTBUFFER, | 352 | .flags = CON_ANYTIME | CON_PRINTBUFFER, |
353 | .index = -1, | 353 | .index = -1, |
354 | }; | 354 | }; |
355 | 355 | ||
356 | struct console * __init | 356 | struct console * __init |
357 | bfin_jc_early_init(unsigned int port, unsigned int cflag) | 357 | bfin_jc_early_init(unsigned int port, unsigned int cflag) |
358 | { | 358 | { |
359 | return &bfin_jc_early_console; | 359 | return &bfin_jc_early_console; |
360 | } | 360 | } |