aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2016-10-24 04:00:29 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-11-10 08:30:08 -0500
commit94cbb6978b63d004502eed24417aceb7b36bc10a (patch)
treea6535edd940a60f52ad5130dcdc125adc438b60f /drivers/tty
parent5131dcd7810806fe4ff81ca23dadb47921285e36 (diff)
serial: 8250_uniphier: hardcode regshift to avoid unneeded memory read
For this driver, uart_port::regshift is always 2. Hardcode the shift value instead of reading ->regshift to get an already known value. (pointed out by Denys Vlasenko) Furthermore, I am using register macros that are already shifted, which will save code a bit. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/serial/8250/8250_uniphier.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/drivers/tty/serial/8250/8250_uniphier.c b/drivers/tty/serial/8250/8250_uniphier.c
index 417d9e7038e1..92e7bb7b3f83 100644
--- a/drivers/tty/serial/8250/8250_uniphier.c
+++ b/drivers/tty/serial/8250/8250_uniphier.c
@@ -24,10 +24,22 @@
24/* Most (but not all) of UniPhier UART devices have 64-depth FIFO. */ 24/* Most (but not all) of UniPhier UART devices have 64-depth FIFO. */
25#define UNIPHIER_UART_DEFAULT_FIFO_SIZE 64 25#define UNIPHIER_UART_DEFAULT_FIFO_SIZE 64
26 26
27#define UNIPHIER_UART_CHAR_FCR 3 /* Character / FIFO Control Register */ 27/*
28#define UNIPHIER_UART_LCR_MCR 4 /* Line/Modem Control Register */ 28 * This hardware is similar to 8250, but its register map is a bit different:
29#define UNIPHIER_UART_LCR_SHIFT 8 29 * - MMIO32 (regshift = 2)
30#define UNIPHIER_UART_DLR 9 /* Divisor Latch Register */ 30 * - FCR is not at 2, but 3
31 * - LCR and MCR are not at 3 and 4, they share 4
32 * - Divisor latch at 9, no divisor latch access bit
33 */
34
35#define UNIPHIER_UART_REGSHIFT 2
36
37/* bit[15:8] = CHAR (not used), bit[7:0] = FCR */
38#define UNIPHIER_UART_CHAR_FCR (3 << (UNIPHIER_UART_REGSHIFT))
39/* bit[15:8] = LCR, bit[7:0] = MCR */
40#define UNIPHIER_UART_LCR_MCR (4 << (UNIPHIER_UART_REGSHIFT))
41/* Divisor Latch Register */
42#define UNIPHIER_UART_DLR (9 << (UNIPHIER_UART_REGSHIFT))
31 43
32struct uniphier8250_priv { 44struct uniphier8250_priv {
33 int line; 45 int line;
@@ -44,7 +56,7 @@ static int __init uniphier_early_console_setup(struct earlycon_device *device,
44 56
45 /* This hardware always expects MMIO32 register interface. */ 57 /* This hardware always expects MMIO32 register interface. */
46 device->port.iotype = UPIO_MEM32; 58 device->port.iotype = UPIO_MEM32;
47 device->port.regshift = 2; 59 device->port.regshift = UNIPHIER_UART_REGSHIFT;
48 60
49 /* 61 /*
50 * Do not touch the divisor register in early_serial8250_setup(); 62 * Do not touch the divisor register in early_serial8250_setup();
@@ -68,17 +80,16 @@ static unsigned int uniphier_serial_in(struct uart_port *p, int offset)
68 80
69 switch (offset) { 81 switch (offset) {
70 case UART_LCR: 82 case UART_LCR:
71 valshift = UNIPHIER_UART_LCR_SHIFT; 83 valshift = 8;
72 /* fall through */ 84 /* fall through */
73 case UART_MCR: 85 case UART_MCR:
74 offset = UNIPHIER_UART_LCR_MCR; 86 offset = UNIPHIER_UART_LCR_MCR;
75 break; 87 break;
76 default: 88 default:
89 offset <<= UNIPHIER_UART_REGSHIFT;
77 break; 90 break;
78 } 91 }
79 92
80 offset <<= p->regshift;
81
82 /* 93 /*
83 * The return value must be masked with 0xff because LCR and MCR reside 94 * The return value must be masked with 0xff because LCR and MCR reside
84 * in the same register that must be accessed by 32-bit write/read. 95 * in the same register that must be accessed by 32-bit write/read.
@@ -97,7 +108,7 @@ static void uniphier_serial_out(struct uart_port *p, int offset, int value)
97 offset = UNIPHIER_UART_CHAR_FCR; 108 offset = UNIPHIER_UART_CHAR_FCR;
98 break; 109 break;
99 case UART_LCR: 110 case UART_LCR:
100 valshift = UNIPHIER_UART_LCR_SHIFT; 111 valshift = 8;
101 /* Divisor latch access bit does not exist. */ 112 /* Divisor latch access bit does not exist. */
102 value &= ~UART_LCR_DLAB; 113 value &= ~UART_LCR_DLAB;
103 /* fall through */ 114 /* fall through */
@@ -106,11 +117,10 @@ static void uniphier_serial_out(struct uart_port *p, int offset, int value)
106 break; 117 break;
107 default: 118 default:
108 normal = true; 119 normal = true;
120 offset <<= UNIPHIER_UART_REGSHIFT;
109 break; 121 break;
110 } 122 }
111 123
112 offset <<= p->regshift;
113
114 if (normal) { 124 if (normal) {
115 writel(value, p->membase + offset); 125 writel(value, p->membase + offset);
116 } else { 126 } else {
@@ -139,16 +149,12 @@ static void uniphier_serial_out(struct uart_port *p, int offset, int value)
139 */ 149 */
140static int uniphier_serial_dl_read(struct uart_8250_port *up) 150static int uniphier_serial_dl_read(struct uart_8250_port *up)
141{ 151{
142 int offset = UNIPHIER_UART_DLR << up->port.regshift; 152 return readl(up->port.membase + UNIPHIER_UART_DLR);
143
144 return readl(up->port.membase + offset);
145} 153}
146 154
147static void uniphier_serial_dl_write(struct uart_8250_port *up, int value) 155static void uniphier_serial_dl_write(struct uart_8250_port *up, int value)
148{ 156{
149 int offset = UNIPHIER_UART_DLR << up->port.regshift; 157 writel(value, up->port.membase + UNIPHIER_UART_DLR);
150
151 writel(value, up->port.membase + offset);
152} 158}
153 159
154static int uniphier_of_serial_setup(struct device *dev, struct uart_port *port, 160static int uniphier_of_serial_setup(struct device *dev, struct uart_port *port,
@@ -234,7 +240,7 @@ static int uniphier_uart_probe(struct platform_device *pdev)
234 240
235 up.port.type = PORT_16550A; 241 up.port.type = PORT_16550A;
236 up.port.iotype = UPIO_MEM32; 242 up.port.iotype = UPIO_MEM32;
237 up.port.regshift = 2; 243 up.port.regshift = UNIPHIER_UART_REGSHIFT;
238 up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE; 244 up.port.flags = UPF_FIXED_PORT | UPF_FIXED_TYPE;
239 up.capabilities = UART_CAP_FIFO; 245 up.capabilities = UART_CAP_FIFO;
240 246