hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/tty/serial/cpm_uart/cpm_uart_core.c
....@@ -24,14 +24,13 @@
2424 #include <linux/console.h>
2525 #include <linux/sysrq.h>
2626 #include <linux/device.h>
27
-#include <linux/bootmem.h>
27
+#include <linux/memblock.h>
2828 #include <linux/dma-mapping.h>
2929 #include <linux/fs_uart_pd.h>
3030 #include <linux/of_address.h>
3131 #include <linux/of_irq.h>
3232 #include <linux/of_platform.h>
33
-#include <linux/gpio.h>
34
-#include <linux/of_gpio.h>
33
+#include <linux/gpio/consumer.h>
3534 #include <linux/clk.h>
3635
3736 #include <asm/io.h>
....@@ -39,10 +38,6 @@
3938 #include <asm/delay.h>
4039 #include <asm/fs_pd.h>
4140 #include <asm/udbg.h>
42
-
43
-#if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
44
-#define SUPPORT_SYSRQ
45
-#endif
4641
4742 #include <linux/serial_core.h>
4843 #include <linux/kernel.h>
....@@ -92,11 +87,11 @@
9287 struct uart_cpm_port *pinfo =
9388 container_of(port, struct uart_cpm_port, port);
9489
95
- if (pinfo->gpios[GPIO_RTS] >= 0)
96
- gpio_set_value(pinfo->gpios[GPIO_RTS], !(mctrl & TIOCM_RTS));
90
+ if (pinfo->gpios[GPIO_RTS])
91
+ gpiod_set_value(pinfo->gpios[GPIO_RTS], !(mctrl & TIOCM_RTS));
9792
98
- if (pinfo->gpios[GPIO_DTR] >= 0)
99
- gpio_set_value(pinfo->gpios[GPIO_DTR], !(mctrl & TIOCM_DTR));
93
+ if (pinfo->gpios[GPIO_DTR])
94
+ gpiod_set_value(pinfo->gpios[GPIO_DTR], !(mctrl & TIOCM_DTR));
10095 }
10196
10297 static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
....@@ -105,23 +100,23 @@
105100 container_of(port, struct uart_cpm_port, port);
106101 unsigned int mctrl = TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
107102
108
- if (pinfo->gpios[GPIO_CTS] >= 0) {
109
- if (gpio_get_value(pinfo->gpios[GPIO_CTS]))
103
+ if (pinfo->gpios[GPIO_CTS]) {
104
+ if (gpiod_get_value(pinfo->gpios[GPIO_CTS]))
110105 mctrl &= ~TIOCM_CTS;
111106 }
112107
113
- if (pinfo->gpios[GPIO_DSR] >= 0) {
114
- if (gpio_get_value(pinfo->gpios[GPIO_DSR]))
108
+ if (pinfo->gpios[GPIO_DSR]) {
109
+ if (gpiod_get_value(pinfo->gpios[GPIO_DSR]))
115110 mctrl &= ~TIOCM_DSR;
116111 }
117112
118
- if (pinfo->gpios[GPIO_DCD] >= 0) {
119
- if (gpio_get_value(pinfo->gpios[GPIO_DCD]))
113
+ if (pinfo->gpios[GPIO_DCD]) {
114
+ if (gpiod_get_value(pinfo->gpios[GPIO_DCD]))
120115 mctrl &= ~TIOCM_CAR;
121116 }
122117
123
- if (pinfo->gpios[GPIO_RI] >= 0) {
124
- if (!gpio_get_value(pinfo->gpios[GPIO_RI]))
118
+ if (pinfo->gpios[GPIO_RI]) {
119
+ if (!gpiod_get_value(pinfo->gpios[GPIO_RI]))
125120 mctrl |= TIOCM_RNG;
126121 }
127122
....@@ -347,9 +342,7 @@
347342 /* ASSUMPTION: it contains nothing valid */
348343 i = 0;
349344 }
350
-#ifdef SUPPORT_SYSRQ
351345 port->sysrq = 0;
352
-#endif
353346 goto error_return;
354347 }
355348
....@@ -576,8 +569,6 @@
576569 /*
577570 * Set up parity check flag
578571 */
579
-#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
580
-
581572 port->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
582573 if (termios->c_iflag & INPCK)
583574 port->read_status_mask |= BD_SC_FR | BD_SC_PR;
....@@ -1147,6 +1138,7 @@
11471138 {
11481139 const u32 *data;
11491140 void __iomem *mem, *pram;
1141
+ struct device *dev = pinfo->port.dev;
11501142 int len;
11511143 int ret;
11521144 int i;
....@@ -1160,8 +1152,8 @@
11601152 if (!pinfo->clk) {
11611153 data = of_get_property(np, "fsl,cpm-brg", &len);
11621154 if (!data || len != 4) {
1163
- printk(KERN_ERR "CPM UART %s has no/invalid "
1164
- "fsl,cpm-brg property.\n", np->name);
1155
+ printk(KERN_ERR "CPM UART %pOFn has no/invalid "
1156
+ "fsl,cpm-brg property.\n", np);
11651157 return -EINVAL;
11661158 }
11671159 pinfo->brg = *data;
....@@ -1169,8 +1161,8 @@
11691161
11701162 data = of_get_property(np, "fsl,cpm-command", &len);
11711163 if (!data || len != 4) {
1172
- printk(KERN_ERR "CPM UART %s has no/invalid "
1173
- "fsl,cpm-command property.\n", np->name);
1164
+ printk(KERN_ERR "CPM UART %pOFn has no/invalid "
1165
+ "fsl,cpm-command property.\n", np);
11741166 return -EINVAL;
11751167 }
11761168 pinfo->command = *data;
....@@ -1206,7 +1198,8 @@
12061198 pinfo->port.uartclk = ppc_proc_freq;
12071199 pinfo->port.mapbase = (unsigned long)mem;
12081200 pinfo->port.type = PORT_CPM;
1209
- pinfo->port.ops = &cpm_uart_pops,
1201
+ pinfo->port.ops = &cpm_uart_pops;
1202
+ pinfo->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_CPM_CONSOLE);
12101203 pinfo->port.iotype = UPIO_MEM;
12111204 pinfo->port.fifosize = pinfo->tx_nrfifos * pinfo->tx_fifosize;
12121205 spin_lock_init(&pinfo->port.lock);
....@@ -1218,29 +1211,28 @@
12181211 }
12191212
12201213 for (i = 0; i < NUM_GPIOS; i++) {
1221
- int gpio;
1214
+ struct gpio_desc *gpiod;
12221215
1223
- pinfo->gpios[i] = -1;
1216
+ pinfo->gpios[i] = NULL;
12241217
1225
- gpio = of_get_gpio(np, i);
1218
+ gpiod = devm_gpiod_get_index_optional(dev, NULL, i, GPIOD_ASIS);
12261219
1227
- if (gpio_is_valid(gpio)) {
1228
- ret = gpio_request(gpio, "cpm_uart");
1229
- if (ret) {
1230
- pr_err("can't request gpio #%d: %d\n", i, ret);
1231
- continue;
1232
- }
1220
+ if (IS_ERR(gpiod)) {
1221
+ ret = PTR_ERR(gpiod);
1222
+ goto out_irq;
1223
+ }
1224
+
1225
+ if (gpiod) {
12331226 if (i == GPIO_RTS || i == GPIO_DTR)
1234
- ret = gpio_direction_output(gpio, 0);
1227
+ ret = gpiod_direction_output(gpiod, 0);
12351228 else
1236
- ret = gpio_direction_input(gpio);
1229
+ ret = gpiod_direction_input(gpiod);
12371230 if (ret) {
12381231 pr_err("can't set direction for gpio #%d: %d\n",
12391232 i, ret);
1240
- gpio_free(gpio);
12411233 continue;
12421234 }
1243
- pinfo->gpios[i] = gpio;
1235
+ pinfo->gpios[i] = gpiod;
12441236 }
12451237 }
12461238
....@@ -1250,6 +1242,8 @@
12501242
12511243 return cpm_uart_request_port(&pinfo->port);
12521244
1245
+out_irq:
1246
+ irq_dispose_mapping(pinfo->port.irq);
12531247 out_pram:
12541248 cpm_uart_unmap_pram(pinfo, pram);
12551249 out_mem:
....@@ -1269,19 +1263,14 @@
12691263 {
12701264 struct uart_cpm_port *pinfo = &cpm_uart_ports[co->index];
12711265 unsigned long flags;
1272
- int nolock = oops_in_progress;
12731266
1274
- if (unlikely(nolock)) {
1267
+ if (unlikely(oops_in_progress)) {
12751268 local_irq_save(flags);
1276
- } else {
1277
- spin_lock_irqsave(&pinfo->port.lock, flags);
1278
- }
1279
-
1280
- cpm_uart_early_write(pinfo, s, count, true);
1281
-
1282
- if (unlikely(nolock)) {
1269
+ cpm_uart_early_write(pinfo, s, count, true);
12831270 local_irq_restore(flags);
12841271 } else {
1272
+ spin_lock_irqsave(&pinfo->port.lock, flags);
1273
+ cpm_uart_early_write(pinfo, s, count, true);
12851274 spin_unlock_irqrestore(&pinfo->port.lock, flags);
12861275 }
12871276 }
....@@ -1380,6 +1369,7 @@
13801369
13811370 static int __init cpm_uart_console_init(void)
13821371 {
1372
+ cpm_muram_init();
13831373 register_console(&cpm_scc_uart_console);
13841374 return 0;
13851375 }