diff options
author | Maciej W. Rozycki <macro@linux-mips.org> | 2008-02-07 03:15:15 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-07 11:42:24 -0500 |
commit | f5519caad5c1828b2ab6d14bd9e7a8e047db12e3 (patch) | |
tree | f5a6c29abc9b4b36da93b79372024c21640e66d2 /drivers/serial/dz.c | |
parent | ff11d0780376a3821d790a6ceb8b297d976b14fe (diff) |
dz.c: Use a helper to cast from "struct uart_port *"
Replace all casts from "struct uart_port *" to "struct dz_port *" with a
construct based on container_of(). This makes the conversion work
irrespective of where the former struct is located within the latter.
By popular request I have implemented it as an inline function rather than
a macro this time.
Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/serial/dz.c')
-rw-r--r-- | drivers/serial/dz.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c index 765b700c019c..c054c1bd8b24 100644 --- a/drivers/serial/dz.c +++ b/drivers/serial/dz.c | |||
@@ -68,6 +68,11 @@ struct dz_port { | |||
68 | 68 | ||
69 | static struct dz_port dz_ports[DZ_NB_PORT]; | 69 | static struct dz_port dz_ports[DZ_NB_PORT]; |
70 | 70 | ||
71 | static inline struct dz_port *to_dport(struct uart_port *uport) | ||
72 | { | ||
73 | return container_of(uport, struct dz_port, port); | ||
74 | } | ||
75 | |||
71 | /* | 76 | /* |
72 | * ------------------------------------------------------------ | 77 | * ------------------------------------------------------------ |
73 | * dz_in () and dz_out () | 78 | * dz_in () and dz_out () |
@@ -106,7 +111,7 @@ static inline void dz_out(struct dz_port *dport, unsigned offset, | |||
106 | 111 | ||
107 | static void dz_stop_tx(struct uart_port *uport) | 112 | static void dz_stop_tx(struct uart_port *uport) |
108 | { | 113 | { |
109 | struct dz_port *dport = (struct dz_port *)uport; | 114 | struct dz_port *dport = to_dport(uport); |
110 | unsigned short tmp, mask = 1 << dport->port.line; | 115 | unsigned short tmp, mask = 1 << dport->port.line; |
111 | 116 | ||
112 | tmp = dz_in(dport, DZ_TCR); /* read the TX flag */ | 117 | tmp = dz_in(dport, DZ_TCR); /* read the TX flag */ |
@@ -116,7 +121,7 @@ static void dz_stop_tx(struct uart_port *uport) | |||
116 | 121 | ||
117 | static void dz_start_tx(struct uart_port *uport) | 122 | static void dz_start_tx(struct uart_port *uport) |
118 | { | 123 | { |
119 | struct dz_port *dport = (struct dz_port *)uport; | 124 | struct dz_port *dport = to_dport(uport); |
120 | unsigned short tmp, mask = 1 << dport->port.line; | 125 | unsigned short tmp, mask = 1 << dport->port.line; |
121 | 126 | ||
122 | tmp = dz_in(dport, DZ_TCR); /* read the TX flag */ | 127 | tmp = dz_in(dport, DZ_TCR); /* read the TX flag */ |
@@ -126,7 +131,7 @@ static void dz_start_tx(struct uart_port *uport) | |||
126 | 131 | ||
127 | static void dz_stop_rx(struct uart_port *uport) | 132 | static void dz_stop_rx(struct uart_port *uport) |
128 | { | 133 | { |
129 | struct dz_port *dport = (struct dz_port *)uport; | 134 | struct dz_port *dport = to_dport(uport); |
130 | 135 | ||
131 | dport->cflag &= ~DZ_RXENAB; | 136 | dport->cflag &= ~DZ_RXENAB; |
132 | dz_out(dport, DZ_LPR, dport->cflag); | 137 | dz_out(dport, DZ_LPR, dport->cflag); |
@@ -349,7 +354,7 @@ static unsigned int dz_get_mctrl(struct uart_port *uport) | |||
349 | /* | 354 | /* |
350 | * FIXME: Handle the 3100/5000 as appropriate. --macro | 355 | * FIXME: Handle the 3100/5000 as appropriate. --macro |
351 | */ | 356 | */ |
352 | struct dz_port *dport = (struct dz_port *)uport; | 357 | struct dz_port *dport = to_dport(uport); |
353 | unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; | 358 | unsigned int mctrl = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; |
354 | 359 | ||
355 | if (dport->port.line == DZ_MODEM) { | 360 | if (dport->port.line == DZ_MODEM) { |
@@ -365,7 +370,7 @@ static void dz_set_mctrl(struct uart_port *uport, unsigned int mctrl) | |||
365 | /* | 370 | /* |
366 | * FIXME: Handle the 3100/5000 as appropriate. --macro | 371 | * FIXME: Handle the 3100/5000 as appropriate. --macro |
367 | */ | 372 | */ |
368 | struct dz_port *dport = (struct dz_port *)uport; | 373 | struct dz_port *dport = to_dport(uport); |
369 | unsigned short tmp; | 374 | unsigned short tmp; |
370 | 375 | ||
371 | if (dport->port.line == DZ_MODEM) { | 376 | if (dport->port.line == DZ_MODEM) { |
@@ -387,7 +392,7 @@ static void dz_set_mctrl(struct uart_port *uport, unsigned int mctrl) | |||
387 | */ | 392 | */ |
388 | static int dz_startup(struct uart_port *uport) | 393 | static int dz_startup(struct uart_port *uport) |
389 | { | 394 | { |
390 | struct dz_port *dport = (struct dz_port *)uport; | 395 | struct dz_port *dport = to_dport(uport); |
391 | unsigned long flags; | 396 | unsigned long flags; |
392 | unsigned short tmp; | 397 | unsigned short tmp; |
393 | 398 | ||
@@ -413,7 +418,7 @@ static int dz_startup(struct uart_port *uport) | |||
413 | */ | 418 | */ |
414 | static void dz_shutdown(struct uart_port *uport) | 419 | static void dz_shutdown(struct uart_port *uport) |
415 | { | 420 | { |
416 | struct dz_port *dport = (struct dz_port *)uport; | 421 | struct dz_port *dport = to_dport(uport); |
417 | unsigned long flags; | 422 | unsigned long flags; |
418 | 423 | ||
419 | spin_lock_irqsave(&dport->port.lock, flags); | 424 | spin_lock_irqsave(&dport->port.lock, flags); |
@@ -435,7 +440,7 @@ static void dz_shutdown(struct uart_port *uport) | |||
435 | */ | 440 | */ |
436 | static unsigned int dz_tx_empty(struct uart_port *uport) | 441 | static unsigned int dz_tx_empty(struct uart_port *uport) |
437 | { | 442 | { |
438 | struct dz_port *dport = (struct dz_port *)uport; | 443 | struct dz_port *dport = to_dport(uport); |
439 | unsigned short tmp, mask = 1 << dport->port.line; | 444 | unsigned short tmp, mask = 1 << dport->port.line; |
440 | 445 | ||
441 | tmp = dz_in(dport, DZ_TCR); | 446 | tmp = dz_in(dport, DZ_TCR); |
@@ -450,7 +455,7 @@ static void dz_break_ctl(struct uart_port *uport, int break_state) | |||
450 | * FIXME: Can't access BREAK bits in TDR easily; | 455 | * FIXME: Can't access BREAK bits in TDR easily; |
451 | * reuse the code for polled TX. --macro | 456 | * reuse the code for polled TX. --macro |
452 | */ | 457 | */ |
453 | struct dz_port *dport = (struct dz_port *)uport; | 458 | struct dz_port *dport = to_dport(uport); |
454 | unsigned long flags; | 459 | unsigned long flags; |
455 | unsigned short tmp, mask = 1 << dport->port.line; | 460 | unsigned short tmp, mask = 1 << dport->port.line; |
456 | 461 | ||
@@ -505,7 +510,7 @@ static int dz_encode_baud_rate(unsigned int baud) | |||
505 | static void dz_set_termios(struct uart_port *uport, struct ktermios *termios, | 510 | static void dz_set_termios(struct uart_port *uport, struct ktermios *termios, |
506 | struct ktermios *old_termios) | 511 | struct ktermios *old_termios) |
507 | { | 512 | { |
508 | struct dz_port *dport = (struct dz_port *)uport; | 513 | struct dz_port *dport = to_dport(uport); |
509 | unsigned long flags; | 514 | unsigned long flags; |
510 | unsigned int cflag, baud; | 515 | unsigned int cflag, baud; |
511 | int bflag; | 516 | int bflag; |
@@ -685,7 +690,7 @@ static void dz_reset(struct dz_port *dport) | |||
685 | */ | 690 | */ |
686 | static void dz_console_putchar(struct uart_port *uport, int ch) | 691 | static void dz_console_putchar(struct uart_port *uport, int ch) |
687 | { | 692 | { |
688 | struct dz_port *dport = (struct dz_port *)uport; | 693 | struct dz_port *dport = to_dport(uport); |
689 | unsigned long flags; | 694 | unsigned long flags; |
690 | unsigned short csr, tcr, trdy, mask; | 695 | unsigned short csr, tcr, trdy, mask; |
691 | int loops = 10000; | 696 | int loops = 10000; |