diff options
author | Vineet Gupta <Vineet.Gupta1@synopsys.com> | 2014-06-24 04:25:07 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-07-10 18:43:27 -0400 |
commit | 12d15e6f6377fe46b1f9dc51133890a732f1ae05 (patch) | |
tree | 0b15e413389fc91f461fa029fc7f5a734e2a7d3b /drivers/tty | |
parent | 3bce1b70d6f2cdb83c9323c553b2336974b8516f (diff) |
serial/arc: Refactor by referencing to uart_port where possible
The ARC UART MMIO helpers would take arc_uart_port and then reference
generic uart_port->membase member. So change them to difrectly refer to
uart_port and fix call sites accordingly.
This removes the need for to_arc_port() converion almost eveeywhere and
makes code a bit easier to read.
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r-- | drivers/tty/serial/arc_uart.c | 155 |
1 files changed, 69 insertions, 86 deletions
diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c index b4859598e157..b58544de4e86 100644 --- a/drivers/tty/serial/arc_uart.c +++ b/drivers/tty/serial/arc_uart.c | |||
@@ -72,7 +72,7 @@ | |||
72 | #define RXOERR 0x02 /* OverFlow Err: Char recv but RXFULL still set */ | 72 | #define RXOERR 0x02 /* OverFlow Err: Char recv but RXFULL still set */ |
73 | 73 | ||
74 | /* Uart bit fiddling helpers: lowest level */ | 74 | /* Uart bit fiddling helpers: lowest level */ |
75 | #define RBASE(uart, reg) (uart->port.membase + reg) | 75 | #define RBASE(port, reg) (port->membase + reg) |
76 | #define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r)) | 76 | #define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r)) |
77 | #define UART_REG_GET(u, r) readb(RBASE(u, r)) | 77 | #define UART_REG_GET(u, r) readb(RBASE(u, r)) |
78 | 78 | ||
@@ -129,19 +129,15 @@ static struct uart_driver arc_uart_driver = { | |||
129 | 129 | ||
130 | static void arc_serial_stop_rx(struct uart_port *port) | 130 | static void arc_serial_stop_rx(struct uart_port *port) |
131 | { | 131 | { |
132 | struct arc_uart_port *uart = to_arc_port(port); | 132 | UART_RX_IRQ_DISABLE(port); |
133 | |||
134 | UART_RX_IRQ_DISABLE(uart); | ||
135 | } | 133 | } |
136 | 134 | ||
137 | static void arc_serial_stop_tx(struct uart_port *port) | 135 | static void arc_serial_stop_tx(struct uart_port *port) |
138 | { | 136 | { |
139 | struct arc_uart_port *uart = to_arc_port(port); | 137 | while (!(UART_GET_STATUS(port) & TXEMPTY)) |
140 | |||
141 | while (!(UART_GET_STATUS(uart) & TXEMPTY)) | ||
142 | cpu_relax(); | 138 | cpu_relax(); |
143 | 139 | ||
144 | UART_TX_IRQ_DISABLE(uart); | 140 | UART_TX_IRQ_DISABLE(port); |
145 | } | 141 | } |
146 | 142 | ||
147 | /* | 143 | /* |
@@ -149,10 +145,9 @@ static void arc_serial_stop_tx(struct uart_port *port) | |||
149 | */ | 145 | */ |
150 | static unsigned int arc_serial_tx_empty(struct uart_port *port) | 146 | static unsigned int arc_serial_tx_empty(struct uart_port *port) |
151 | { | 147 | { |
152 | struct arc_uart_port *uart = to_arc_port(port); | ||
153 | unsigned int stat; | 148 | unsigned int stat; |
154 | 149 | ||
155 | stat = UART_GET_STATUS(uart); | 150 | stat = UART_GET_STATUS(port); |
156 | if (stat & TXEMPTY) | 151 | if (stat & TXEMPTY) |
157 | return TIOCSER_TEMT; | 152 | return TIOCSER_TEMT; |
158 | 153 | ||
@@ -166,24 +161,24 @@ static unsigned int arc_serial_tx_empty(struct uart_port *port) | |||
166 | * = by uart_start( ) before calling us | 161 | * = by uart_start( ) before calling us |
167 | * = tx_ist checks that too before calling | 162 | * = tx_ist checks that too before calling |
168 | */ | 163 | */ |
169 | static void arc_serial_tx_chars(struct arc_uart_port *uart) | 164 | static void arc_serial_tx_chars(struct uart_port *port) |
170 | { | 165 | { |
171 | struct circ_buf *xmit = &uart->port.state->xmit; | 166 | struct circ_buf *xmit = &port->state->xmit; |
172 | int sent = 0; | 167 | int sent = 0; |
173 | unsigned char ch; | 168 | unsigned char ch; |
174 | 169 | ||
175 | if (unlikely(uart->port.x_char)) { | 170 | if (unlikely(port->x_char)) { |
176 | UART_SET_DATA(uart, uart->port.x_char); | 171 | UART_SET_DATA(port, port->x_char); |
177 | uart->port.icount.tx++; | 172 | port->icount.tx++; |
178 | uart->port.x_char = 0; | 173 | port->x_char = 0; |
179 | sent = 1; | 174 | sent = 1; |
180 | } else if (xmit->tail != xmit->head) { /* TODO: uart_circ_empty */ | 175 | } else if (xmit->tail != xmit->head) { /* TODO: uart_circ_empty */ |
181 | ch = xmit->buf[xmit->tail]; | 176 | ch = xmit->buf[xmit->tail]; |
182 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); | 177 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
183 | uart->port.icount.tx++; | 178 | port->icount.tx++; |
184 | while (!(UART_GET_STATUS(uart) & TXEMPTY)) | 179 | while (!(UART_GET_STATUS(port) & TXEMPTY)) |
185 | cpu_relax(); | 180 | cpu_relax(); |
186 | UART_SET_DATA(uart, ch); | 181 | UART_SET_DATA(port, ch); |
187 | sent = 1; | 182 | sent = 1; |
188 | } | 183 | } |
189 | 184 | ||
@@ -192,10 +187,10 @@ static void arc_serial_tx_chars(struct arc_uart_port *uart) | |||
192 | * By Hard ISR to schedule processing in software interrupt part | 187 | * By Hard ISR to schedule processing in software interrupt part |
193 | */ | 188 | */ |
194 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) | 189 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
195 | uart_write_wakeup(&uart->port); | 190 | uart_write_wakeup(port); |
196 | 191 | ||
197 | if (sent) | 192 | if (sent) |
198 | UART_TX_IRQ_ENABLE(uart); | 193 | UART_TX_IRQ_ENABLE(port); |
199 | } | 194 | } |
200 | 195 | ||
201 | /* | 196 | /* |
@@ -204,12 +199,10 @@ static void arc_serial_tx_chars(struct arc_uart_port *uart) | |||
204 | */ | 199 | */ |
205 | static void arc_serial_start_tx(struct uart_port *port) | 200 | static void arc_serial_start_tx(struct uart_port *port) |
206 | { | 201 | { |
207 | struct arc_uart_port *uart = to_arc_port(port); | 202 | arc_serial_tx_chars(port); |
208 | |||
209 | arc_serial_tx_chars(uart); | ||
210 | } | 203 | } |
211 | 204 | ||
212 | static void arc_serial_rx_chars(struct arc_uart_port *uart, unsigned int status) | 205 | static void arc_serial_rx_chars(struct uart_port *port, unsigned int status) |
213 | { | 206 | { |
214 | unsigned int ch, flg = 0; | 207 | unsigned int ch, flg = 0; |
215 | 208 | ||
@@ -229,15 +222,15 @@ static void arc_serial_rx_chars(struct arc_uart_port *uart, unsigned int status) | |||
229 | */ | 222 | */ |
230 | if (unlikely(status & (RXOERR | RXFERR))) { | 223 | if (unlikely(status & (RXOERR | RXFERR))) { |
231 | if (status & RXOERR) { | 224 | if (status & RXOERR) { |
232 | uart->port.icount.overrun++; | 225 | port->icount.overrun++; |
233 | flg = TTY_OVERRUN; | 226 | flg = TTY_OVERRUN; |
234 | UART_CLR_STATUS(uart, RXOERR); | 227 | UART_CLR_STATUS(port, RXOERR); |
235 | } | 228 | } |
236 | 229 | ||
237 | if (status & RXFERR) { | 230 | if (status & RXFERR) { |
238 | uart->port.icount.frame++; | 231 | port->icount.frame++; |
239 | flg = TTY_FRAME; | 232 | flg = TTY_FRAME; |
240 | UART_CLR_STATUS(uart, RXFERR); | 233 | UART_CLR_STATUS(port, RXFERR); |
241 | } | 234 | } |
242 | } else | 235 | } else |
243 | flg = TTY_NORMAL; | 236 | flg = TTY_NORMAL; |
@@ -245,16 +238,16 @@ static void arc_serial_rx_chars(struct arc_uart_port *uart, unsigned int status) | |||
245 | if (status & RXEMPTY) | 238 | if (status & RXEMPTY) |
246 | continue; | 239 | continue; |
247 | 240 | ||
248 | ch = UART_GET_DATA(uart); | 241 | ch = UART_GET_DATA(port); |
249 | uart->port.icount.rx++; | 242 | port->icount.rx++; |
250 | 243 | ||
251 | if (!(uart_handle_sysrq_char(&uart->port, ch))) | 244 | if (!(uart_handle_sysrq_char(port, ch))) |
252 | uart_insert_char(&uart->port, status, RXOERR, ch, flg); | 245 | uart_insert_char(port, status, RXOERR, ch, flg); |
253 | 246 | ||
254 | spin_unlock(&uart->port.lock); | 247 | spin_unlock(&port->lock); |
255 | tty_flip_buffer_push(&uart->port.state->port); | 248 | tty_flip_buffer_push(&port->state->port); |
256 | spin_lock(&uart->port.lock); | 249 | spin_lock(&port->lock); |
257 | } while (!((status = UART_GET_STATUS(uart)) & RXEMPTY)); | 250 | } while (!((status = UART_GET_STATUS(port)) & RXEMPTY)); |
258 | } | 251 | } |
259 | 252 | ||
260 | /* | 253 | /* |
@@ -287,10 +280,10 @@ static void arc_serial_rx_chars(struct arc_uart_port *uart, unsigned int status) | |||
287 | 280 | ||
288 | static irqreturn_t arc_serial_isr(int irq, void *dev_id) | 281 | static irqreturn_t arc_serial_isr(int irq, void *dev_id) |
289 | { | 282 | { |
290 | struct arc_uart_port *uart = dev_id; | 283 | struct uart_port *port = dev_id; |
291 | unsigned int status; | 284 | unsigned int status; |
292 | 285 | ||
293 | status = UART_GET_STATUS(uart); | 286 | status = UART_GET_STATUS(port); |
294 | 287 | ||
295 | /* | 288 | /* |
296 | * Single IRQ for both Rx (data available) Tx (room available) Interrupt | 289 | * Single IRQ for both Rx (data available) Tx (room available) Interrupt |
@@ -300,9 +293,9 @@ static irqreturn_t arc_serial_isr(int irq, void *dev_id) | |||
300 | if (status & RXIENB) { | 293 | if (status & RXIENB) { |
301 | 294 | ||
302 | /* already in ISR, no need of xx_irqsave */ | 295 | /* already in ISR, no need of xx_irqsave */ |
303 | spin_lock(&uart->port.lock); | 296 | spin_lock(&port->lock); |
304 | arc_serial_rx_chars(uart, status); | 297 | arc_serial_rx_chars(port, status); |
305 | spin_unlock(&uart->port.lock); | 298 | spin_unlock(&port->lock); |
306 | } | 299 | } |
307 | 300 | ||
308 | if ((status & TXIENB) && (status & TXEMPTY)) { | 301 | if ((status & TXIENB) && (status & TXEMPTY)) { |
@@ -310,14 +303,14 @@ static irqreturn_t arc_serial_isr(int irq, void *dev_id) | |||
310 | /* Unconditionally disable further Tx-Interrupts. | 303 | /* Unconditionally disable further Tx-Interrupts. |
311 | * will be enabled by tx_chars() if needed. | 304 | * will be enabled by tx_chars() if needed. |
312 | */ | 305 | */ |
313 | UART_TX_IRQ_DISABLE(uart); | 306 | UART_TX_IRQ_DISABLE(port); |
314 | 307 | ||
315 | spin_lock(&uart->port.lock); | 308 | spin_lock(&port->lock); |
316 | 309 | ||
317 | if (!uart_tx_stopped(&uart->port)) | 310 | if (!uart_tx_stopped(port)) |
318 | arc_serial_tx_chars(uart); | 311 | arc_serial_tx_chars(port); |
319 | 312 | ||
320 | spin_unlock(&uart->port.lock); | 313 | spin_unlock(&port->lock); |
321 | } | 314 | } |
322 | 315 | ||
323 | return IRQ_HANDLED; | 316 | return IRQ_HANDLED; |
@@ -347,18 +340,15 @@ static void arc_serial_break_ctl(struct uart_port *port, int break_state) | |||
347 | 340 | ||
348 | static int arc_serial_startup(struct uart_port *port) | 341 | static int arc_serial_startup(struct uart_port *port) |
349 | { | 342 | { |
350 | struct arc_uart_port *uart = to_arc_port(port); | ||
351 | |||
352 | /* Before we hook up the ISR, Disable all UART Interrupts */ | 343 | /* Before we hook up the ISR, Disable all UART Interrupts */ |
353 | UART_ALL_IRQ_DISABLE(uart); | 344 | UART_ALL_IRQ_DISABLE(port); |
354 | 345 | ||
355 | if (request_irq(uart->port.irq, arc_serial_isr, 0, "arc uart rx-tx", | 346 | if (request_irq(port->irq, arc_serial_isr, 0, "arc uart rx-tx", port)) { |
356 | uart)) { | 347 | dev_warn(port->dev, "Unable to attach ARC UART intr\n"); |
357 | dev_warn(uart->port.dev, "Unable to attach ARC UART intr\n"); | ||
358 | return -EBUSY; | 348 | return -EBUSY; |
359 | } | 349 | } |
360 | 350 | ||
361 | UART_RX_IRQ_ENABLE(uart); /* Only Rx IRQ enabled to begin with */ | 351 | UART_RX_IRQ_ENABLE(port); /* Only Rx IRQ enabled to begin with */ |
362 | 352 | ||
363 | return 0; | 353 | return 0; |
364 | } | 354 | } |
@@ -366,8 +356,7 @@ static int arc_serial_startup(struct uart_port *port) | |||
366 | /* This is not really needed */ | 356 | /* This is not really needed */ |
367 | static void arc_serial_shutdown(struct uart_port *port) | 357 | static void arc_serial_shutdown(struct uart_port *port) |
368 | { | 358 | { |
369 | struct arc_uart_port *uart = to_arc_port(port); | 359 | free_irq(port->irq, port); |
370 | free_irq(uart->port.irq, uart); | ||
371 | } | 360 | } |
372 | 361 | ||
373 | static void | 362 | static void |
@@ -404,12 +393,12 @@ arc_serial_set_termios(struct uart_port *port, struct ktermios *new, | |||
404 | 393 | ||
405 | spin_lock_irqsave(&port->lock, flags); | 394 | spin_lock_irqsave(&port->lock, flags); |
406 | 395 | ||
407 | UART_ALL_IRQ_DISABLE(uart); | 396 | UART_ALL_IRQ_DISABLE(port); |
408 | 397 | ||
409 | UART_SET_BAUDL(uart, uartl); | 398 | UART_SET_BAUDL(port, uartl); |
410 | UART_SET_BAUDH(uart, uarth); | 399 | UART_SET_BAUDH(port, uarth); |
411 | 400 | ||
412 | UART_RX_IRQ_ENABLE(uart); | 401 | UART_RX_IRQ_ENABLE(port); |
413 | 402 | ||
414 | /* | 403 | /* |
415 | * UART doesn't support Parity/Hardware Flow Control; | 404 | * UART doesn't support Parity/Hardware Flow Control; |
@@ -432,9 +421,7 @@ arc_serial_set_termios(struct uart_port *port, struct ktermios *new, | |||
432 | 421 | ||
433 | static const char *arc_serial_type(struct uart_port *port) | 422 | static const char *arc_serial_type(struct uart_port *port) |
434 | { | 423 | { |
435 | struct arc_uart_port *uart = to_arc_port(port); | 424 | return port->type == PORT_ARC ? DRIVER_NAME : NULL; |
436 | |||
437 | return uart->port.type == PORT_ARC ? DRIVER_NAME : NULL; | ||
438 | } | 425 | } |
439 | 426 | ||
440 | static void arc_serial_release_port(struct uart_port *port) | 427 | static void arc_serial_release_port(struct uart_port *port) |
@@ -463,35 +450,30 @@ arc_serial_verify_port(struct uart_port *port, struct serial_struct *ser) | |||
463 | */ | 450 | */ |
464 | static void arc_serial_config_port(struct uart_port *port, int flags) | 451 | static void arc_serial_config_port(struct uart_port *port, int flags) |
465 | { | 452 | { |
466 | struct arc_uart_port *uart = to_arc_port(port); | ||
467 | |||
468 | if (flags & UART_CONFIG_TYPE) | 453 | if (flags & UART_CONFIG_TYPE) |
469 | uart->port.type = PORT_ARC; | 454 | port->type = PORT_ARC; |
470 | } | 455 | } |
471 | 456 | ||
472 | #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_ARC_CONSOLE) | 457 | #if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_ARC_CONSOLE) |
473 | 458 | ||
474 | static void arc_serial_poll_putchar(struct uart_port *port, int chr) | 459 | static void arc_serial_poll_putchar(struct uart_port *port, int chr) |
475 | { | 460 | { |
476 | struct arc_uart_port *uart = to_arc_port(port); | 461 | while (!(UART_GET_STATUS(port) & TXEMPTY)) |
477 | |||
478 | while (!(UART_GET_STATUS(uart) & TXEMPTY)) | ||
479 | cpu_relax(); | 462 | cpu_relax(); |
480 | 463 | ||
481 | UART_SET_DATA(uart, (unsigned char)chr); | 464 | UART_SET_DATA(port, (unsigned char)chr); |
482 | } | 465 | } |
483 | #endif | 466 | #endif |
484 | 467 | ||
485 | #ifdef CONFIG_CONSOLE_POLL | 468 | #ifdef CONFIG_CONSOLE_POLL |
486 | static int arc_serial_poll_getchar(struct uart_port *port) | 469 | static int arc_serial_poll_getchar(struct uart_port *port) |
487 | { | 470 | { |
488 | struct arc_uart_port *uart = to_arc_port(port); | ||
489 | unsigned char chr; | 471 | unsigned char chr; |
490 | 472 | ||
491 | while (!(UART_GET_STATUS(uart) & RXEMPTY)) | 473 | while (!(UART_GET_STATUS(port) & RXEMPTY)) |
492 | cpu_relax(); | 474 | cpu_relax(); |
493 | 475 | ||
494 | chr = UART_GET_DATA(uart); | 476 | chr = UART_GET_DATA(port); |
495 | return chr; | 477 | return chr; |
496 | } | 478 | } |
497 | #endif | 479 | #endif |
@@ -524,6 +506,7 @@ arc_uart_init_one(struct platform_device *pdev, int dev_id) | |||
524 | struct resource *res, *res2; | 506 | struct resource *res, *res2; |
525 | unsigned long *plat_data; | 507 | unsigned long *plat_data; |
526 | struct arc_uart_port *uart = &arc_uart_ports[dev_id]; | 508 | struct arc_uart_port *uart = &arc_uart_ports[dev_id]; |
509 | struct uart_port *port = &uart->port; | ||
527 | 510 | ||
528 | plat_data = dev_get_platdata(&pdev->dev); | 511 | plat_data = dev_get_platdata(&pdev->dev); |
529 | if (!plat_data) | 512 | if (!plat_data) |
@@ -532,7 +515,7 @@ arc_uart_init_one(struct platform_device *pdev, int dev_id) | |||
532 | uart->is_emulated = !!plat_data[0]; /* workaround ISS bug */ | 515 | uart->is_emulated = !!plat_data[0]; /* workaround ISS bug */ |
533 | 516 | ||
534 | if (is_early_platform_device(pdev)) { | 517 | if (is_early_platform_device(pdev)) { |
535 | uart->port.uartclk = plat_data[1]; | 518 | port->uartclk = plat_data[1]; |
536 | uart->baud = plat_data[2]; | 519 | uart->baud = plat_data[2]; |
537 | } else { | 520 | } else { |
538 | struct device_node *np = pdev->dev.of_node; | 521 | struct device_node *np = pdev->dev.of_node; |
@@ -542,7 +525,7 @@ arc_uart_init_one(struct platform_device *pdev, int dev_id) | |||
542 | dev_err(&pdev->dev, "clock-frequency property NOTset\n"); | 525 | dev_err(&pdev->dev, "clock-frequency property NOTset\n"); |
543 | return -EINVAL; | 526 | return -EINVAL; |
544 | } | 527 | } |
545 | uart->port.uartclk = val; | 528 | port->uartclk = val; |
546 | 529 | ||
547 | if (of_property_read_u32(np, "current-speed", &val)) { | 530 | if (of_property_read_u32(np, "current-speed", &val)) { |
548 | dev_err(&pdev->dev, "current-speed property NOT set\n"); | 531 | dev_err(&pdev->dev, "current-speed property NOT set\n"); |
@@ -559,26 +542,26 @@ arc_uart_init_one(struct platform_device *pdev, int dev_id) | |||
559 | if (!res2) | 542 | if (!res2) |
560 | return -ENODEV; | 543 | return -ENODEV; |
561 | 544 | ||
562 | uart->port.mapbase = res->start; | 545 | port->mapbase = res->start; |
563 | uart->port.membase = ioremap_nocache(res->start, resource_size(res)); | 546 | port->membase = ioremap_nocache(res->start, resource_size(res)); |
564 | if (!uart->port.membase) | 547 | if (!port->membase) |
565 | /* No point of dev_err since UART itself is hosed here */ | 548 | /* No point of dev_err since UART itself is hosed here */ |
566 | return -ENXIO; | 549 | return -ENXIO; |
567 | 550 | ||
568 | uart->port.irq = res2->start; | 551 | port->irq = res2->start; |
569 | uart->port.dev = &pdev->dev; | 552 | port->dev = &pdev->dev; |
570 | uart->port.iotype = UPIO_MEM; | 553 | port->iotype = UPIO_MEM; |
571 | uart->port.flags = UPF_BOOT_AUTOCONF; | 554 | port->flags = UPF_BOOT_AUTOCONF; |
572 | uart->port.line = dev_id; | 555 | port->line = dev_id; |
573 | uart->port.ops = &arc_serial_pops; | 556 | port->ops = &arc_serial_pops; |
574 | 557 | ||
575 | uart->port.fifosize = ARC_UART_TX_FIFO_SIZE; | 558 | port->fifosize = ARC_UART_TX_FIFO_SIZE; |
576 | 559 | ||
577 | /* | 560 | /* |
578 | * uart_insert_char( ) uses it in decideding whether to ignore a | 561 | * uart_insert_char( ) uses it in decideding whether to ignore a |
579 | * char or not. Explicitly setting it here, removes the subtelty | 562 | * char or not. Explicitly setting it here, removes the subtelty |
580 | */ | 563 | */ |
581 | uart->port.ignore_status_mask = 0; | 564 | port->ignore_status_mask = 0; |
582 | 565 | ||
583 | return 0; | 566 | return 0; |
584 | } | 567 | } |