Skip to content

Commit 6a533ed

Browse files
andy-shevgregkh
authored andcommitted
serial: 8250_dw: Deduplicate LCR checks
All callers of dw8250_check_lcr() perform the same check. Deduplicate it by moving them into respective call. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5cb90c6 commit 6a533ed

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

drivers/tty/serial/8250/8250_dw.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,18 @@ static void dw8250_force_idle(struct uart_port *p)
100100
(void)p->serial_in(p, UART_RX);
101101
}
102102

103-
static void dw8250_check_lcr(struct uart_port *p, int value)
103+
static void dw8250_check_lcr(struct uart_port *p, int offset, int value)
104104
{
105-
void __iomem *offset = p->membase + (UART_LCR << p->regshift);
105+
struct dw8250_data *d = to_dw8250_data(p->private_data);
106+
void __iomem *addr = p->membase + (offset << p->regshift);
106107
int tries = 1000;
107108

109+
if (offset != UART_LCR || d->uart_16550_compatible)
110+
return;
111+
108112
/* Make sure LCR write wasn't ignored */
109113
while (tries--) {
110-
unsigned int lcr = p->serial_in(p, UART_LCR);
114+
unsigned int lcr = p->serial_in(p, offset);
111115

112116
if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR))
113117
return;
@@ -116,15 +120,15 @@ static void dw8250_check_lcr(struct uart_port *p, int value)
116120

117121
#ifdef CONFIG_64BIT
118122
if (p->type == PORT_OCTEON)
119-
__raw_writeq(value & 0xff, offset);
123+
__raw_writeq(value & 0xff, addr);
120124
else
121125
#endif
122126
if (p->iotype == UPIO_MEM32)
123-
writel(value, offset);
127+
writel(value, addr);
124128
else if (p->iotype == UPIO_MEM32BE)
125-
iowrite32be(value, offset);
129+
iowrite32be(value, addr);
126130
else
127-
writeb(value, offset);
131+
writeb(value, addr);
128132
}
129133
/*
130134
* FIXME: this deadlocks if port->lock is already held
@@ -158,12 +162,8 @@ static void dw8250_tx_wait_empty(struct uart_port *p)
158162

159163
static void dw8250_serial_out(struct uart_port *p, int offset, int value)
160164
{
161-
struct dw8250_data *d = to_dw8250_data(p->private_data);
162-
163165
writeb(value, p->membase + (offset << p->regshift));
164-
165-
if (offset == UART_LCR && !d->uart_16550_compatible)
166-
dw8250_check_lcr(p, value);
166+
dw8250_check_lcr(p, offset, value);
167167
}
168168

169169
static void dw8250_serial_out38x(struct uart_port *p, int offset, int value)
@@ -194,26 +194,19 @@ static unsigned int dw8250_serial_inq(struct uart_port *p, int offset)
194194

195195
static void dw8250_serial_outq(struct uart_port *p, int offset, int value)
196196
{
197-
struct dw8250_data *d = to_dw8250_data(p->private_data);
198-
199197
value &= 0xff;
200198
__raw_writeq(value, p->membase + (offset << p->regshift));
201199
/* Read back to ensure register write ordering. */
202200
__raw_readq(p->membase + (UART_LCR << p->regshift));
203201

204-
if (offset == UART_LCR && !d->uart_16550_compatible)
205-
dw8250_check_lcr(p, value);
202+
dw8250_check_lcr(p, offset, value);
206203
}
207204
#endif /* CONFIG_64BIT */
208205

209206
static void dw8250_serial_out32(struct uart_port *p, int offset, int value)
210207
{
211-
struct dw8250_data *d = to_dw8250_data(p->private_data);
212-
213208
writel(value, p->membase + (offset << p->regshift));
214-
215-
if (offset == UART_LCR && !d->uart_16550_compatible)
216-
dw8250_check_lcr(p, value);
209+
dw8250_check_lcr(p, offset, value);
217210
}
218211

219212
static unsigned int dw8250_serial_in32(struct uart_port *p, int offset)
@@ -225,12 +218,8 @@ static unsigned int dw8250_serial_in32(struct uart_port *p, int offset)
225218

226219
static void dw8250_serial_out32be(struct uart_port *p, int offset, int value)
227220
{
228-
struct dw8250_data *d = to_dw8250_data(p->private_data);
229-
230221
iowrite32be(value, p->membase + (offset << p->regshift));
231-
232-
if (offset == UART_LCR && !d->uart_16550_compatible)
233-
dw8250_check_lcr(p, value);
222+
dw8250_check_lcr(p, offset, value);
234223
}
235224

236225
static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset)

0 commit comments

Comments
 (0)