Skip to content

Commit debf950

Browse files
committed
serial: sh-sci: Generalize overrun handling.
This consolidates all of the broken out overrun handling and ensures that we have sensible defaults per-port type, in addition to making sure that overruns are flagged appropriately in the error mask for parts that haven't explicitly disabled support for it. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent b030340 commit debf950

3 files changed

Lines changed: 77 additions & 56 deletions

File tree

‎drivers/tty/serial/sh-sci.c‎

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,19 @@ static int sci_handle_errors(struct uart_port *port)
563563
int copied = 0;
564564
unsigned short status = sci_in(port, SCxSR);
565565
struct tty_struct *tty = port->state->port.tty;
566+
struct sci_port *s = to_sci_port(port);
566567

567-
if (status & SCxSR_ORER(port)) {
568-
/* overrun error */
569-
if (tty_insert_flip_char(tty, 0, TTY_OVERRUN))
570-
copied++;
568+
/*
569+
* Handle overruns, if supported.
570+
*/
571+
if (s->cfg->overrun_bit != SCIx_NOT_SUPPORTED) {
572+
if (status & (1 << s->cfg->overrun_bit)) {
573+
/* overrun error */
574+
if (tty_insert_flip_char(tty, 0, TTY_OVERRUN))
575+
copied++;
571576

572-
dev_notice(port->dev, "overrun error");
577+
dev_notice(port->dev, "overrun error");
578+
}
573579
}
574580

575581
if (status & SCxSR_FER(port)) {
@@ -617,12 +623,19 @@ static int sci_handle_errors(struct uart_port *port)
617623
static int sci_handle_fifo_overrun(struct uart_port *port)
618624
{
619625
struct tty_struct *tty = port->state->port.tty;
626+
struct sci_port *s = to_sci_port(port);
620627
int copied = 0;
621628

629+
/*
630+
* XXX: Technically not limited to non-SCIFs, it's simply the
631+
* SCLSR check that is for the moment SCIF-specific. This
632+
* probably wants to be revisited for SCIFA/B as well as for
633+
* factoring in SCI overrun detection.
634+
*/
622635
if (port->type != PORT_SCIF)
623636
return 0;
624637

625-
if ((sci_in(port, SCLSR) & SCIF_ORER) != 0) {
638+
if ((sci_in(port, SCLSR) & (1 << s->cfg->overrun_bit))) {
626639
sci_out(port, SCLSR, 0);
627640

628641
tty_insert_flip_char(tty, 0, TTY_OVERRUN);
@@ -1755,6 +1768,32 @@ static int __devinit sci_init_single(struct platform_device *dev,
17551768
sci_port->break_timer.function = sci_break_timer;
17561769
init_timer(&sci_port->break_timer);
17571770

1771+
/*
1772+
* Establish some sensible defaults for the error detection.
1773+
*/
1774+
if (!p->error_mask)
1775+
p->error_mask = (p->type == PORT_SCI) ?
1776+
SCI_DEFAULT_ERROR_MASK : SCIF_DEFAULT_ERROR_MASK;
1777+
1778+
/*
1779+
* Establish sensible defaults for the overrun detection, unless
1780+
* the part has explicitly disabled support for it.
1781+
*/
1782+
if (p->overrun_bit != SCIx_NOT_SUPPORTED) {
1783+
if (p->type == PORT_SCI)
1784+
p->overrun_bit = 5;
1785+
else if (p->scbrr_algo_id == SCBRR_ALGO_4)
1786+
p->overrun_bit = 9;
1787+
else
1788+
p->overrun_bit = 0;
1789+
1790+
/*
1791+
* Make the error mask inclusive of overrun detection, if
1792+
* supported.
1793+
*/
1794+
p->error_mask |= (1 << p->overrun_bit);
1795+
}
1796+
17581797
sci_port->cfg = p;
17591798

17601799
port->mapbase = p->mapbase;

‎drivers/tty/serial/sh-sci.h‎

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
defined(CONFIG_ARCH_SH7372)
2020
# define PORT_PTCR 0xA405011EUL
2121
# define PORT_PVCR 0xA4050122UL
22-
# define SCIF_ORER 0x0200 /* overrun error bit */
2322
#elif defined(CONFIG_SH_RTS7751R2D)
2423
# define SCSPTR1 0xFFE0001C /* 8 bit SCIF */
2524
# define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
26-
# define SCIF_ORER 0x0001 /* overrun error bit */
2725
#elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
2826
defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
2927
defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
@@ -32,124 +30,78 @@
3230
defined(CONFIG_CPU_SUBTYPE_SH7751R)
3331
# define SCSPTR1 0xffe0001c /* 8 bit SCI */
3432
# define SCSPTR2 0xFFE80020 /* 16 bit SCIF */
35-
# define SCIF_ORER 0x0001 /* overrun error bit */
3633
#elif defined(CONFIG_CPU_SUBTYPE_SH7760)
3734
# define SCSPTR0 0xfe600024 /* 16 bit SCIF */
3835
# define SCSPTR1 0xfe610024 /* 16 bit SCIF */
3936
# define SCSPTR2 0xfe620024 /* 16 bit SCIF */
40-
# define SCIF_ORER 0x0001 /* overrun error bit */
4137
#elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
4238
# define SCSPTR0 0xA4400000 /* 16 bit SCIF */
43-
# define SCIF_ORER 0x0001 /* overrun error bit */
4439
# define PACR 0xa4050100
4540
# define PBCR 0xa4050102
4641
#elif defined(CONFIG_CPU_SUBTYPE_SH7343)
4742
# define SCSPTR0 0xffe00010 /* 16 bit SCIF */
4843
#elif defined(CONFIG_CPU_SUBTYPE_SH7722)
4944
# define PWDR 0xA4050166
5045
# define PSCR 0xA405011E
51-
# define SCIF_ORER 0x0001 /* overrun error bit */
5246
#elif defined(CONFIG_CPU_SUBTYPE_SH7366)
5347
# define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
5448
# define SCSPTR0 SCPDR0
55-
# define SCIF_ORER 0x0001 /* overrun error bit */
5649
#elif defined(CONFIG_CPU_SUBTYPE_SH7723)
5750
# define SCSPTR0 0xa4050160
58-
# define SCIF_ORER 0x0001 /* overrun error bit */
59-
#elif defined(CONFIG_CPU_SUBTYPE_SH7724)
60-
# define SCIF_ORER 0x0001 /* overrun error bit */
6151
#elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
6252
# define SCSPTR2 0xffe80020 /* 16 bit SCIF */
63-
# define SCIF_ORER 0x0001 /* overrun error bit */
6453
#elif defined(CONFIG_CPU_SUBTYPE_SH7757)
6554
# define SCSPTR0 0xfe4b0020
66-
# define SCIF_ORER 0x0001
6755
#elif defined(CONFIG_CPU_SUBTYPE_SH7763)
6856
# define SCSPTR0 0xffe00024 /* 16 bit SCIF */
69-
# define SCIF_ORER 0x0001 /* overrun error bit */
7057
#elif defined(CONFIG_CPU_SUBTYPE_SH7770)
7158
# define SCSPTR0 0xff923020 /* 16 bit SCIF */
72-
# define SCIF_ORER 0x0001 /* overrun error bit */
7359
#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
7460
# define SCSPTR0 0xffe00024 /* 16 bit SCIF */
75-
# define SCIF_ORER 0x0001 /* Overrun error bit */
7661
#elif defined(CONFIG_CPU_SUBTYPE_SH7785) || \
7762
defined(CONFIG_CPU_SUBTYPE_SH7786)
7863
# define SCSPTR0 0xffea0024 /* 16 bit SCIF */
79-
# define SCIF_ORER 0x0001 /* Overrun error bit */
8064
#elif defined(CONFIG_CPU_SUBTYPE_SH7201) || \
8165
defined(CONFIG_CPU_SUBTYPE_SH7203) || \
8266
defined(CONFIG_CPU_SUBTYPE_SH7206) || \
8367
defined(CONFIG_CPU_SUBTYPE_SH7263)
8468
# define SCSPTR0 0xfffe8020 /* 16 bit SCIF */
8569
#elif defined(CONFIG_CPU_SUBTYPE_SH7619)
8670
# define SCSPTR0 0xf8400020 /* 16 bit SCIF */
87-
# define SCIF_ORER 0x0001 /* overrun error bit */
8871
#elif defined(CONFIG_CPU_SUBTYPE_SHX3)
8972
# define SCSPTR0 0xffc30020 /* 16 bit SCIF */
90-
# define SCIF_ORER 0x0001 /* Overrun error bit */
9173
#else
9274
# error CPU subtype not defined
9375
#endif
9476

95-
/* SCxSR SCI */
96-
#define SCI_TDRE 0x80 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
97-
#define SCI_RDRF 0x40 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
98-
#define SCI_ORER 0x20 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
99-
#define SCI_FER 0x10 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
100-
#define SCI_PER 0x08 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
101-
#define SCI_TEND 0x04 /* 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
102-
/* SCI_MPB 0x02 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
103-
/* SCI_MPBT 0x01 * 7707 SCI, 7708 SCI, 7709 SCI, 7750 SCI */
104-
105-
#define SCI_ERRORS ( SCI_PER | SCI_FER | SCI_ORER)
106-
107-
/* SCxSR SCIF */
108-
#define SCIF_ER 0x0080 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
109-
#define SCIF_TEND 0x0040 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
110-
#define SCIF_TDFE 0x0020 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
111-
#define SCIF_BRK 0x0010 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
112-
#define SCIF_FER 0x0008 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
113-
#define SCIF_PER 0x0004 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
114-
#define SCIF_RDF 0x0002 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
115-
#define SCIF_DR 0x0001 /* 7705 SCIF, 7707 SCIF, 7709 SCIF, 7750 SCIF */
116-
11777
#if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
11878
defined(CONFIG_CPU_SUBTYPE_SH7720) || \
11979
defined(CONFIG_CPU_SUBTYPE_SH7721) || \
12080
defined(CONFIG_ARCH_SH73A0) || \
12181
defined(CONFIG_ARCH_SH7367) || \
12282
defined(CONFIG_ARCH_SH7377) || \
12383
defined(CONFIG_ARCH_SH7372)
124-
# define SCIF_ORER 0x0200
125-
# define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK | SCIF_ORER)
12684
# define SCIF_RFDC_MASK 0x007f
12785
# define SCIF_TXROOM_MAX 64
12886
#elif defined(CONFIG_CPU_SUBTYPE_SH7763)
129-
# define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK )
13087
# define SCIF_RFDC_MASK 0x007f
13188
# define SCIF_TXROOM_MAX 64
13289
/* SH7763 SCIF2 support */
13390
# define SCIF2_RFDC_MASK 0x001f
13491
# define SCIF2_TXROOM_MAX 16
13592
#else
136-
# define SCIF_ERRORS ( SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
13793
# define SCIF_RFDC_MASK 0x001f
13894
# define SCIF_TXROOM_MAX 16
13995
#endif
14096

141-
#ifndef SCIF_ORER
142-
#define SCIF_ORER 0x0000
143-
#endif
144-
14597
#define SCxSR_TEND(port) (((port)->type == PORT_SCI) ? SCI_TEND : SCIF_TEND)
146-
#define SCxSR_ERRORS(port) (((port)->type == PORT_SCI) ? SCI_ERRORS : SCIF_ERRORS)
14798
#define SCxSR_RDxF(port) (((port)->type == PORT_SCI) ? SCI_RDRF : SCIF_RDF)
14899
#define SCxSR_TDxE(port) (((port)->type == PORT_SCI) ? SCI_TDRE : SCIF_TDFE)
149100
#define SCxSR_FER(port) (((port)->type == PORT_SCI) ? SCI_FER : SCIF_FER)
150101
#define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER)
151102
#define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK)
152-
#define SCxSR_ORER(port) (((port)->type == PORT_SCI) ? SCI_ORER : SCIF_ORER)
103+
104+
#define SCxSR_ERRORS(port) (to_sci_port(port)->cfg->error_mask)
153105

154106
#if defined(CONFIG_CPU_SUBTYPE_SH7705) || \
155107
defined(CONFIG_CPU_SUBTYPE_SH7720) || \

‎include/linux/serial_sci.h‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Generic header for SuperH SCI(F) (used by sh/sh64/h8300 and related parts)
99
*/
1010

11+
#define SCIx_NOT_SUPPORTED (-1)
12+
1113
enum {
1214
SCBRR_ALGO_1, /* ((clk + 16 * bps) / (16 * bps) - 1) */
1315
SCBRR_ALGO_2, /* ((clk + 16 * bps) / (32 * bps) - 1) */
@@ -25,6 +27,28 @@ enum {
2527
#define SCSCR_CKE1 (1 << 1)
2628
#define SCSCR_CKE0 (1 << 0)
2729

30+
/* SCxSR SCI */
31+
#define SCI_TDRE 0x80
32+
#define SCI_RDRF 0x40
33+
#define SCI_ORER 0x20
34+
#define SCI_FER 0x10
35+
#define SCI_PER 0x08
36+
#define SCI_TEND 0x04
37+
38+
#define SCI_DEFAULT_ERROR_MASK (SCI_PER | SCI_FER)
39+
40+
/* SCxSR SCIF */
41+
#define SCIF_ER 0x0080
42+
#define SCIF_TEND 0x0040
43+
#define SCIF_TDFE 0x0020
44+
#define SCIF_BRK 0x0010
45+
#define SCIF_FER 0x0008
46+
#define SCIF_PER 0x0004
47+
#define SCIF_RDF 0x0002
48+
#define SCIF_DR 0x0001
49+
50+
#define SCIF_DEFAULT_ERROR_MASK (SCIF_PER | SCIF_FER | SCIF_ER | SCIF_BRK)
51+
2852
/* Offsets into the sci_port->irqs array */
2953
enum {
3054
SCIx_ERI_IRQ,
@@ -56,6 +80,12 @@ struct plat_sci_port {
5680
unsigned int scbrr_algo_id; /* SCBRR calculation algo */
5781
unsigned int scscr; /* SCSCR initialization */
5882

83+
/*
84+
* Platform overrides if necessary, defaults otherwise.
85+
*/
86+
int overrun_bit;
87+
unsigned int error_mask;
88+
5989
struct device *dma_dev;
6090

6191
unsigned int dma_slave_tx;

0 commit comments

Comments
 (0)