aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/sh-sci.c
diff options
context:
space:
mode:
authorMichael Trimarchi <trimarchimichael@yahoo.it>2008-11-13 04:18:35 -0500
committerPaul Mundt <lethal@linux-sh.org>2008-12-22 04:42:52 -0500
commite7c98dc76d5823444059205e0c7aca49743679f3 (patch)
treea5ae3e0e91cfbdee445122985c0a01749e97fd33 /drivers/serial/sh-sci.c
parentaf505b1eab55445e832bebbe5686f5bd22f1b717 (diff)
serial: sh-sci: Codestyle cleanup patch.
Trivial coding style cleanups. Signed-off-by: Michael Trimarchi <trimarchimichael@yahoo.it> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'drivers/serial/sh-sci.c')
-rw-r--r--drivers/serial/sh-sci.c130
1 files changed, 74 insertions, 56 deletions
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 165fc010978c..31532e97fb96 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -101,6 +101,12 @@ static void sci_stop_tx(struct uart_port *port);
101static struct sci_port sci_ports[SCI_NPORTS]; 101static struct sci_port sci_ports[SCI_NPORTS];
102static struct uart_driver sci_uart_driver; 102static struct uart_driver sci_uart_driver;
103 103
104static inline struct sci_port *
105to_sci_port(struct uart_port *uart)
106{
107 return container_of(uart, struct sci_port, port);
108}
109
104#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && \ 110#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && \
105 defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB) 111 defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
106static inline void handle_error(struct uart_port *port) 112static inline void handle_error(struct uart_port *port)
@@ -124,7 +130,8 @@ static int get_char(struct uart_port *port)
124 } 130 }
125 } while (!(status & SCxSR_RDxF(port))); 131 } while (!(status & SCxSR_RDxF(port)));
126 c = sci_in(port, SCxRDR); 132 c = sci_in(port, SCxRDR);
127 sci_in(port, SCxSR); /* Dummy read */ 133 /* Dummy read */
134 sci_in(port, SCxSR);
128 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 135 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
129 spin_unlock_irqrestore(&port->lock, flags); 136 spin_unlock_irqrestore(&port->lock, flags);
130 137
@@ -161,7 +168,7 @@ static void put_string(struct sci_port *sci_port, const char *buffer, int count)
161 168
162#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB) 169#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
163 int checksum; 170 int checksum;
164 int usegdb=0; 171 int usegdb = 0;
165 172
166#ifdef CONFIG_SH_STANDARD_BIOS 173#ifdef CONFIG_SH_STANDARD_BIOS
167 /* This call only does a trap the first time it is 174 /* This call only does a trap the first time it is
@@ -181,7 +188,8 @@ static void put_string(struct sci_port *sci_port, const char *buffer, int count)
181 put_char(port, 'O'); /* 'O'utput to console */ 188 put_char(port, 'O'); /* 'O'utput to console */
182 checksum = 'O'; 189 checksum = 'O';
183 190
184 for (i=0; i<count; i++) { /* Don't use run length encoding */ 191 /* Don't use run length encoding */
192 for (i = 0; i < count; i++) {
185 int h, l; 193 int h, l;
186 194
187 c = *p++; 195 c = *p++;
@@ -197,7 +205,7 @@ static void put_string(struct sci_port *sci_port, const char *buffer, int count)
197 } while (get_char(port) != '+'); 205 } while (get_char(port) != '+');
198 } else 206 } else
199#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */ 207#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
200 for (i=0; i<count; i++) { 208 for (i = 0; i < count; i++) {
201 if (*p == 10) 209 if (*p == 10)
202 put_char(port, '\r'); 210 put_char(port, '\r');
203 put_char(port, *p++); 211 put_char(port, *p++);
@@ -208,35 +216,34 @@ static void put_string(struct sci_port *sci_port, const char *buffer, int count)
208#ifdef CONFIG_SH_KGDB 216#ifdef CONFIG_SH_KGDB
209static int kgdb_sci_getchar(void) 217static int kgdb_sci_getchar(void)
210{ 218{
211 int c; 219 int c;
212 220
213 /* Keep trying to read a character, this could be neater */ 221 /* Keep trying to read a character, this could be neater */
214 while ((c = get_char(&kgdb_sci_port->port)) < 0) 222 while ((c = get_char(&kgdb_sci_port->port)) < 0)
215 cpu_relax(); 223 cpu_relax();
216 224
217 return c; 225 return c;
218} 226}
219 227
220static inline void kgdb_sci_putchar(int c) 228static inline void kgdb_sci_putchar(int c)
221{ 229{
222 put_char(&kgdb_sci_port->port, c); 230 put_char(&kgdb_sci_port->port, c);
223} 231}
224#endif /* CONFIG_SH_KGDB */ 232#endif /* CONFIG_SH_KGDB */
225 233
226#if defined(__H8300S__) 234#if defined(__H8300S__)
227enum { sci_disable, sci_enable }; 235enum { sci_disable, sci_enable };
228 236
229static void h8300_sci_config(struct uart_port* port, unsigned int ctrl) 237static void h8300_sci_config(struct uart_port *port, unsigned int ctrl)
230{ 238{
231 volatile unsigned char *mstpcrl=(volatile unsigned char *)MSTPCRL; 239 volatile unsigned char *mstpcrl = (volatile unsigned char *)MSTPCRL;
232 int ch = (port->mapbase - SMR0) >> 3; 240 int ch = (port->mapbase - SMR0) >> 3;
233 unsigned char mask = 1 << (ch+1); 241 unsigned char mask = 1 << (ch+1);
234 242
235 if (ctrl == sci_disable) { 243 if (ctrl == sci_disable)
236 *mstpcrl |= mask; 244 *mstpcrl |= mask;
237 } else { 245 else
238 *mstpcrl &= ~mask; 246 *mstpcrl &= ~mask;
239 }
240} 247}
241 248
242static inline void h8300_sci_enable(struct uart_port *port) 249static inline void h8300_sci_enable(struct uart_port *port)
@@ -251,7 +258,7 @@ static inline void h8300_sci_disable(struct uart_port *port)
251#endif 258#endif
252 259
253#if defined(__H8300H__) || defined(__H8300S__) 260#if defined(__H8300H__) || defined(__H8300S__)
254static void sci_init_pins_sci(struct uart_port* port, unsigned int cflag) 261static void sci_init_pins_sci(struct uart_port *port, unsigned int cflag)
255{ 262{
256 int ch = (port->mapbase - SMR0) >> 3; 263 int ch = (port->mapbase - SMR0) >> 3;
257 264
@@ -285,14 +292,13 @@ static void sci_init_pins_irda(struct uart_port *port, unsigned int cflag)
285#endif 292#endif
286 293
287#if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712) 294#if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
288static void sci_init_pins_scif(struct uart_port* port, unsigned int cflag) 295static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
289{ 296{
290 unsigned int fcr_val = 0; 297 unsigned int fcr_val = 0;
291 298
292 set_sh771x_scif_pfc(port); 299 set_sh771x_scif_pfc(port);
293 if (cflag & CRTSCTS) { 300 if (cflag & CRTSCTS)
294 fcr_val |= SCFCR_MCE; 301 fcr_val |= SCFCR_MCE;
295 }
296 sci_out(port, SCFCR, fcr_val); 302 sci_out(port, SCFCR, fcr_val);
297} 303}
298#elif defined(CONFIG_CPU_SUBTYPE_SH7720) || defined(CONFIG_CPU_SUBTYPE_SH7721) 304#elif defined(CONFIG_CPU_SUBTYPE_SH7720) || defined(CONFIG_CPU_SUBTYPE_SH7721)
@@ -419,18 +425,26 @@ static inline int scif_rxroom(struct uart_port *port)
419#elif defined(CONFIG_CPU_SUBTYPE_SH7763) 425#elif defined(CONFIG_CPU_SUBTYPE_SH7763)
420static inline int scif_txroom(struct uart_port *port) 426static inline int scif_txroom(struct uart_port *port)
421{ 427{
422 if((port->mapbase == 0xffe00000) || (port->mapbase == 0xffe08000)) /* SCIF0/1*/ 428 if ((port->mapbase == 0xffe00000) ||
429 (port->mapbase == 0xffe08000)) {
430 /* SCIF0/1*/
423 return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0xff); 431 return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0xff);
424 else /* SCIF2 */ 432 } else {
433 /* SCIF2 */
425 return SCIF2_TXROOM_MAX - (sci_in(port, SCFDR) >> 8); 434 return SCIF2_TXROOM_MAX - (sci_in(port, SCFDR) >> 8);
435 }
426} 436}
427 437
428static inline int scif_rxroom(struct uart_port *port) 438static inline int scif_rxroom(struct uart_port *port)
429{ 439{
430 if((port->mapbase == 0xffe00000) || (port->mapbase == 0xffe08000)) /* SCIF0/1*/ 440 if ((port->mapbase == 0xffe00000) ||
441 (port->mapbase == 0xffe08000)) {
442 /* SCIF0/1*/
431 return sci_in(port, SCRFDR) & 0xff; 443 return sci_in(port, SCRFDR) & 0xff;
432 else /* SCIF2 */ 444 } else {
445 /* SCIF2 */
433 return sci_in(port, SCFDR) & SCIF2_RFDC_MASK; 446 return sci_in(port, SCFDR) & SCIF2_RFDC_MASK;
447 }
434} 448}
435#else 449#else
436static inline int scif_txroom(struct uart_port *port) 450static inline int scif_txroom(struct uart_port *port)
@@ -446,12 +460,12 @@ static inline int scif_rxroom(struct uart_port *port)
446 460
447static inline int sci_txroom(struct uart_port *port) 461static inline int sci_txroom(struct uart_port *port)
448{ 462{
449 return ((sci_in(port, SCxSR) & SCI_TDRE) != 0); 463 return (sci_in(port, SCxSR) & SCI_TDRE) != 0;
450} 464}
451 465
452static inline int sci_rxroom(struct uart_port *port) 466static inline int sci_rxroom(struct uart_port *port)
453{ 467{
454 return ((sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0); 468 return (sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0;
455} 469}
456 470
457/* ********************************************************************** * 471/* ********************************************************************** *
@@ -469,11 +483,10 @@ static void sci_transmit_chars(struct uart_port *port)
469 status = sci_in(port, SCxSR); 483 status = sci_in(port, SCxSR);
470 if (!(status & SCxSR_TDxE(port))) { 484 if (!(status & SCxSR_TDxE(port))) {
471 ctrl = sci_in(port, SCSCR); 485 ctrl = sci_in(port, SCSCR);
472 if (uart_circ_empty(xmit)) { 486 if (uart_circ_empty(xmit))
473 ctrl &= ~SCI_CTRL_FLAGS_TIE; 487 ctrl &= ~SCI_CTRL_FLAGS_TIE;
474 } else { 488 else
475 ctrl |= SCI_CTRL_FLAGS_TIE; 489 ctrl |= SCI_CTRL_FLAGS_TIE;
476 }
477 sci_out(port, SCSCR, ctrl); 490 sci_out(port, SCSCR, ctrl);
478 return; 491 return;
479 } 492 }
@@ -521,11 +534,11 @@ static void sci_transmit_chars(struct uart_port *port)
521} 534}
522 535
523/* On SH3, SCIF may read end-of-break as a space->mark char */ 536/* On SH3, SCIF may read end-of-break as a space->mark char */
524#define STEPFN(c) ({int __c=(c); (((__c-1)|(__c)) == -1); }) 537#define STEPFN(c) ({int __c = (c); (((__c-1)|(__c)) == -1); })
525 538
526static inline void sci_receive_chars(struct uart_port *port) 539static inline void sci_receive_chars(struct uart_port *port)
527{ 540{
528 struct sci_port *sci_port = (struct sci_port *)port; 541 struct sci_port *sci_port = to_sci_port(port);
529 struct tty_struct *tty = port->info->port.tty; 542 struct tty_struct *tty = port->info->port.tty;
530 int i, count, copied = 0; 543 int i, count, copied = 0;
531 unsigned short status; 544 unsigned short status;
@@ -550,13 +563,13 @@ static inline void sci_receive_chars(struct uart_port *port)
550 563
551 if (port->type == PORT_SCI) { 564 if (port->type == PORT_SCI) {
552 char c = sci_in(port, SCxRDR); 565 char c = sci_in(port, SCxRDR);
553 if (uart_handle_sysrq_char(port, c) || sci_port->break_flag) 566 if (uart_handle_sysrq_char(port, c) ||
567 sci_port->break_flag)
554 count = 0; 568 count = 0;
555 else { 569 else
556 tty_insert_flip_char(tty, c, TTY_NORMAL); 570 tty_insert_flip_char(tty, c, TTY_NORMAL);
557 }
558 } else { 571 } else {
559 for (i=0; i<count; i++) { 572 for (i = 0; i < count; i++) {
560 char c = sci_in(port, SCxRDR); 573 char c = sci_in(port, SCxRDR);
561 status = sci_in(port, SCxSR); 574 status = sci_in(port, SCxSR);
562#if defined(CONFIG_CPU_SH3) 575#if defined(CONFIG_CPU_SH3)
@@ -657,7 +670,7 @@ static inline int sci_handle_errors(struct uart_port *port)
657 if (status & SCxSR_FER(port)) { 670 if (status & SCxSR_FER(port)) {
658 if (sci_rxd_in(port) == 0) { 671 if (sci_rxd_in(port) == 0) {
659 /* Notify of BREAK */ 672 /* Notify of BREAK */
660 struct sci_port *sci_port = (struct sci_port *)port; 673 struct sci_port *sci_port = to_sci_port(port);
661 674
662 if (!sci_port->break_flag) { 675 if (!sci_port->break_flag) {
663 sci_port->break_flag = 1; 676 sci_port->break_flag = 1;
@@ -666,10 +679,11 @@ static inline int sci_handle_errors(struct uart_port *port)
666 /* Do sysrq handling. */ 679 /* Do sysrq handling. */
667 if (uart_handle_break(port)) 680 if (uart_handle_break(port))
668 return 0; 681 return 0;
669 pr_debug("sci: BREAK detected\n"); 682 pr_debug("sci: BREAK detected\n");
670 if (tty_insert_flip_char(tty, 0, TTY_BREAK)) 683 if (tty_insert_flip_char(tty, 0, TTY_BREAK))
671 copied++; 684 copied++;
672 } 685 }
686
673 } else { 687 } else {
674 /* frame error */ 688 /* frame error */
675 if (tty_insert_flip_char(tty, 0, TTY_FRAME)) 689 if (tty_insert_flip_char(tty, 0, TTY_FRAME))
@@ -764,7 +778,7 @@ static irqreturn_t sci_er_interrupt(int irq, void *ptr)
764 } 778 }
765 } else { 779 } else {
766#if defined(SCIF_ORER) 780#if defined(SCIF_ORER)
767 if((sci_in(port, SCLSR) & SCIF_ORER) != 0) { 781 if ((sci_in(port, SCLSR) & SCIF_ORER) != 0) {
768 struct tty_struct *tty = port->info->port.tty; 782 struct tty_struct *tty = port->info->port.tty;
769 783
770 sci_out(port, SCLSR, 0); 784 sci_out(port, SCLSR, 0);
@@ -801,8 +815,8 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
801 struct uart_port *port = ptr; 815 struct uart_port *port = ptr;
802 irqreturn_t ret = IRQ_NONE; 816 irqreturn_t ret = IRQ_NONE;
803 817
804 ssr_status = sci_in(port,SCxSR); 818 ssr_status = sci_in(port, SCxSR);
805 scr_status = sci_in(port,SCSCR); 819 scr_status = sci_in(port, SCSCR);
806 820
807 /* Tx Interrupt */ 821 /* Tx Interrupt */
808 if ((ssr_status & 0x0020) && (scr_status & SCI_CTRL_FLAGS_TIE)) 822 if ((ssr_status & 0x0020) && (scr_status & SCI_CTRL_FLAGS_TIE))
@@ -832,7 +846,7 @@ static int sci_notifier(struct notifier_block *self,
832 int i; 846 int i;
833 847
834 if ((phase == CPUFREQ_POSTCHANGE) || 848 if ((phase == CPUFREQ_POSTCHANGE) ||
835 (phase == CPUFREQ_RESUMECHANGE)){ 849 (phase == CPUFREQ_RESUMECHANGE)) {
836 for (i = 0; i < SCI_NPORTS; i++) { 850 for (i = 0; i < SCI_NPORTS; i++) {
837 struct uart_port *port = &sci_ports[i].port; 851 struct uart_port *port = &sci_ports[i].port;
838 struct clk *clk; 852 struct clk *clk;
@@ -904,12 +918,12 @@ static void sci_free_irq(struct sci_port *port)
904{ 918{
905 int i; 919 int i;
906 920
907 if (port->irqs[0] == port->irqs[1]) { 921 if (port->irqs[0] == port->irqs[1]) {
908 if (!port->irqs[0]) 922 if (!port->irqs[0])
909 printk("sci: sci_free_irq error\n"); 923 printk(KERN_ERR "sci: sci_free_irq error\n");
910 else 924 else
911 free_irq(port->irqs[0], port); 925 free_irq(port->irqs[0], port);
912 } else { 926 } else {
913 for (i = 0; i < ARRAY_SIZE(port->irqs); i++) { 927 for (i = 0; i < ARRAY_SIZE(port->irqs); i++) {
914 if (!port->irqs[i]) 928 if (!port->irqs[i])
915 continue; 929 continue;
@@ -1060,12 +1074,12 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1060 sci_out(port, SCSMR, smr_val); 1074 sci_out(port, SCSMR, smr_val);
1061 1075
1062 if (t > 0) { 1076 if (t > 0) {
1063 if(t >= 256) { 1077 if (t >= 256) {
1064 sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1); 1078 sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1);
1065 t >>= 2; 1079 t >>= 2;
1066 } else { 1080 } else
1067 sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3); 1081 sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3);
1068 } 1082
1069 sci_out(port, SCBRR, t); 1083 sci_out(port, SCBRR, t);
1070 udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */ 1084 udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
1071 } 1085 }
@@ -1076,16 +1090,20 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1076 sci_out(port, SCSCR, SCSCR_INIT(port)); 1090 sci_out(port, SCSCR, SCSCR_INIT(port));
1077 1091
1078 if ((termios->c_cflag & CREAD) != 0) 1092 if ((termios->c_cflag & CREAD) != 0)
1079 sci_start_rx(port,0); 1093 sci_start_rx(port, 0);
1080} 1094}
1081 1095
1082static const char *sci_type(struct uart_port *port) 1096static const char *sci_type(struct uart_port *port)
1083{ 1097{
1084 switch (port->type) { 1098 switch (port->type) {
1085 case PORT_SCI: return "sci"; 1099 case PORT_IRDA:
1086 case PORT_SCIF: return "scif"; 1100 return "irda";
1087 case PORT_IRDA: return "irda"; 1101 case PORT_SCI:
1088 case PORT_SCIFA: return "scifa"; 1102 return "sci";
1103 case PORT_SCIF:
1104 return "scif";
1105 case PORT_SCIFA:
1106 return "scifa";
1089 } 1107 }
1090 1108
1091 return NULL; 1109 return NULL;
@@ -1387,9 +1405,9 @@ console_initcall(kgdb_console_init);
1387#endif /* CONFIG_SH_KGDB_CONSOLE */ 1405#endif /* CONFIG_SH_KGDB_CONSOLE */
1388 1406
1389#if defined(CONFIG_SH_KGDB_CONSOLE) 1407#if defined(CONFIG_SH_KGDB_CONSOLE)
1390#define SCI_CONSOLE &kgdb_console 1408#define SCI_CONSOLE (&kgdb_console)
1391#elif defined(CONFIG_SERIAL_SH_SCI_CONSOLE) 1409#elif defined(CONFIG_SERIAL_SH_SCI_CONSOLE)
1392#define SCI_CONSOLE &serial_console 1410#define SCI_CONSOLE (&serial_console)
1393#else 1411#else
1394#define SCI_CONSOLE 0 1412#define SCI_CONSOLE 0
1395#endif 1413#endif