Skip to content

Commit 0e125a5

Browse files
Shawn Guogregkh
authored andcommitted
tty: amba-pl011: define flag register bits for ZTE device
For some reason we do not really understand, ZTE hardware designers choose to define PL011 Flag Register bit positions differently from standard ones as below. Bit Standard ZTE ----------------------------------- CTS 0 1 DSR 1 3 BUSY 3 8 RI 8 0 Let's define these bits into vendor data and get ZTE PL011 supported properly. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 694d0d0 commit 0e125a5

2 files changed

Lines changed: 44 additions & 10 deletions

File tree

‎drivers/tty/serial/amba-pl011.c‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ static u16 pl011_std_offsets[REG_ARRAY_SIZE] = {
9393
struct vendor_data {
9494
const u16 *reg_offset;
9595
unsigned int ifls;
96+
unsigned int fr_busy;
97+
unsigned int fr_dsr;
98+
unsigned int fr_cts;
99+
unsigned int fr_ri;
96100
bool access_32b;
97101
bool oversampling;
98102
bool dma_threshold;
@@ -111,6 +115,10 @@ static unsigned int get_fifosize_arm(struct amba_device *dev)
111115
static struct vendor_data vendor_arm = {
112116
.reg_offset = pl011_std_offsets,
113117
.ifls = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8,
118+
.fr_busy = UART01x_FR_BUSY,
119+
.fr_dsr = UART01x_FR_DSR,
120+
.fr_cts = UART01x_FR_CTS,
121+
.fr_ri = UART011_FR_RI,
114122
.oversampling = false,
115123
.dma_threshold = false,
116124
.cts_event_workaround = false,
@@ -121,6 +129,10 @@ static struct vendor_data vendor_arm = {
121129

122130
static struct vendor_data vendor_sbsa = {
123131
.reg_offset = pl011_std_offsets,
132+
.fr_busy = UART01x_FR_BUSY,
133+
.fr_dsr = UART01x_FR_DSR,
134+
.fr_cts = UART01x_FR_CTS,
135+
.fr_ri = UART011_FR_RI,
124136
.access_32b = true,
125137
.oversampling = false,
126138
.dma_threshold = false,
@@ -164,6 +176,10 @@ static unsigned int get_fifosize_st(struct amba_device *dev)
164176
static struct vendor_data vendor_st = {
165177
.reg_offset = pl011_st_offsets,
166178
.ifls = UART011_IFLS_RX_HALF|UART011_IFLS_TX_HALF,
179+
.fr_busy = UART01x_FR_BUSY,
180+
.fr_dsr = UART01x_FR_DSR,
181+
.fr_cts = UART01x_FR_CTS,
182+
.fr_ri = UART011_FR_RI,
167183
.oversampling = true,
168184
.dma_threshold = true,
169185
.cts_event_workaround = true,
@@ -192,6 +208,10 @@ static struct vendor_data vendor_zte __maybe_unused = {
192208
.reg_offset = pl011_zte_offsets,
193209
.access_32b = true,
194210
.ifls = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8,
211+
.fr_busy = ZX_UART01x_FR_BUSY,
212+
.fr_dsr = ZX_UART01x_FR_DSR,
213+
.fr_cts = ZX_UART01x_FR_CTS,
214+
.fr_ri = ZX_UART011_FR_RI,
195215
.get_fifosize = get_fifosize_arm,
196216
};
197217

@@ -1167,7 +1187,7 @@ static void pl011_dma_shutdown(struct uart_amba_port *uap)
11671187
return;
11681188

11691189
/* Disable RX and TX DMA */
1170-
while (pl011_read(uap, REG_FR) & UART01x_FR_BUSY)
1190+
while (pl011_read(uap, REG_FR) & uap->vendor->fr_busy)
11711191
cpu_relax();
11721192

11731193
spin_lock_irq(&uap->port.lock);
@@ -1416,11 +1436,12 @@ static void pl011_modem_status(struct uart_amba_port *uap)
14161436
if (delta & UART01x_FR_DCD)
14171437
uart_handle_dcd_change(&uap->port, status & UART01x_FR_DCD);
14181438

1419-
if (delta & UART01x_FR_DSR)
1439+
if (delta & uap->vendor->fr_dsr)
14201440
uap->port.icount.dsr++;
14211441

1422-
if (delta & UART01x_FR_CTS)
1423-
uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS);
1442+
if (delta & uap->vendor->fr_cts)
1443+
uart_handle_cts_change(&uap->port,
1444+
status & uap->vendor->fr_cts);
14241445

14251446
wake_up_interruptible(&uap->port.state->port.delta_msr_wait);
14261447
}
@@ -1493,7 +1514,8 @@ static unsigned int pl011_tx_empty(struct uart_port *port)
14931514
struct uart_amba_port *uap =
14941515
container_of(port, struct uart_amba_port, port);
14951516
unsigned int status = pl011_read(uap, REG_FR);
1496-
return status & (UART01x_FR_BUSY|UART01x_FR_TXFF) ? 0 : TIOCSER_TEMT;
1517+
return status & (uap->vendor->fr_busy | UART01x_FR_TXFF) ?
1518+
0 : TIOCSER_TEMT;
14971519
}
14981520

14991521
static unsigned int pl011_get_mctrl(struct uart_port *port)
@@ -1508,9 +1530,9 @@ static unsigned int pl011_get_mctrl(struct uart_port *port)
15081530
result |= tiocmbit
15091531

15101532
TIOCMBIT(UART01x_FR_DCD, TIOCM_CAR);
1511-
TIOCMBIT(UART01x_FR_DSR, TIOCM_DSR);
1512-
TIOCMBIT(UART01x_FR_CTS, TIOCM_CTS);
1513-
TIOCMBIT(UART011_FR_RI, TIOCM_RNG);
1533+
TIOCMBIT(uap->vendor->fr_dsr, TIOCM_DSR);
1534+
TIOCMBIT(uap->vendor->fr_cts, TIOCM_CTS);
1535+
TIOCMBIT(uap->vendor->fr_ri, TIOCM_RNG);
15141536
#undef TIOCMBIT
15151537
return result;
15161538
}
@@ -2191,7 +2213,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
21912213
* Finally, wait for transmitter to become empty
21922214
* and restore the TCR
21932215
*/
2194-
while (pl011_read(uap, REG_FR) & UART01x_FR_BUSY)
2216+
while (pl011_read(uap, REG_FR) & uap->vendor->fr_busy)
21952217
cpu_relax();
21962218
if (!uap->vendor->always_enabled)
21972219
pl011_write(old_cr, uap, REG_CR);
@@ -2303,13 +2325,16 @@ static struct console amba_console = {
23032325

23042326
static void pl011_putc(struct uart_port *port, int c)
23052327
{
2328+
struct uart_amba_port *uap =
2329+
container_of(port, struct uart_amba_port, port);
2330+
23062331
while (readl(port->membase + UART01x_FR) & UART01x_FR_TXFF)
23072332
cpu_relax();
23082333
if (port->iotype == UPIO_MEM32)
23092334
writel(c, port->membase + UART01x_DR);
23102335
else
23112336
writeb(c, port->membase + UART01x_DR);
2312-
while (readl(port->membase + UART01x_FR) & UART01x_FR_BUSY)
2337+
while (readl(port->membase + UART01x_FR) & uap->vendor->fr_busy)
23132338
cpu_relax();
23142339
}
23152340

‎include/linux/amba/serial.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@
104104
#define UART01x_FR_CTS 0x001
105105
#define UART01x_FR_TMSK (UART01x_FR_TXFF + UART01x_FR_BUSY)
106106

107+
/*
108+
* Some bits of Flag Register on ZTE device have different position from
109+
* standard ones.
110+
*/
111+
#define ZX_UART01x_FR_BUSY 0x100
112+
#define ZX_UART01x_FR_DSR 0x008
113+
#define ZX_UART01x_FR_CTS 0x002
114+
#define ZX_UART011_FR_RI 0x001
115+
107116
#define UART011_CR_CTSEN 0x8000 /* CTS hardware flow control */
108117
#define UART011_CR_RTSEN 0x4000 /* RTS hardware flow control */
109118
#define UART011_CR_OUT2 0x2000 /* OUT2 */

0 commit comments

Comments
 (0)