Greg Kroah-Hartman | e3b3d0f | 2017-11-06 18:11:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Serial Port driver for Open Firmware platform devices |
| 4 | * |
| 5 | * Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>, IBM Corp. |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 6 | */ |
Jingchang Lu | 8ad3b13 | 2014-11-11 15:09:05 +0800 | [diff] [blame] | 7 | #include <linux/console.h> |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 8 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Dan Williams | bf03f65 | 2012-04-10 14:10:53 -0700 | [diff] [blame] | 10 | #include <linux/delay.h> |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 11 | #include <linux/serial_core.h> |
Dan Williams | bf03f65 | 2012-04-10 14:10:53 -0700 | [diff] [blame] | 12 | #include <linux/serial_reg.h> |
Grant Likely | f1ca09b | 2010-08-16 23:44:49 -0600 | [diff] [blame] | 13 | #include <linux/of_address.h> |
Rob Herring | 73930a8 | 2010-11-17 17:50:23 -0600 | [diff] [blame] | 14 | #include <linux/of_irq.h> |
Stephen Rothwell | c401b04 | 2008-05-23 16:32:54 +1000 | [diff] [blame] | 15 | #include <linux/of_platform.h> |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 17 | #include <linux/clk.h> |
Joel Stanley | e2860e1 | 2017-05-29 19:27:52 +0930 | [diff] [blame] | 18 | #include <linux/reset.h> |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 19 | |
Peter Ujfalusi | c93a599 | 2015-12-18 15:00:49 +0200 | [diff] [blame] | 20 | #include "8250.h" |
Heikki Krogerus | b0b8c84 | 2013-03-25 15:51:15 +0200 | [diff] [blame] | 21 | |
Ishizaki Kou | e34b9c9 | 2007-05-31 19:33:04 +1000 | [diff] [blame] | 22 | struct of_serial_info { |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 23 | struct clk *clk; |
Joel Stanley | e2860e1 | 2017-05-29 19:27:52 +0930 | [diff] [blame] | 24 | struct reset_control *rst; |
Ishizaki Kou | e34b9c9 | 2007-05-31 19:33:04 +1000 | [diff] [blame] | 25 | int type; |
| 26 | int line; |
| 27 | }; |
| 28 | |
Dan Williams | bf03f65 | 2012-04-10 14:10:53 -0700 | [diff] [blame] | 29 | #ifdef CONFIG_ARCH_TEGRA |
Thierry Reding | 28264eb6 | 2016-04-28 14:47:24 +0200 | [diff] [blame] | 30 | static void tegra_serial_handle_break(struct uart_port *p) |
Dan Williams | bf03f65 | 2012-04-10 14:10:53 -0700 | [diff] [blame] | 31 | { |
| 32 | unsigned int status, tmout = 10000; |
| 33 | |
| 34 | do { |
| 35 | status = p->serial_in(p, UART_LSR); |
| 36 | if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS)) |
| 37 | status = p->serial_in(p, UART_RX); |
| 38 | else |
| 39 | break; |
| 40 | if (--tmout == 0) |
| 41 | break; |
| 42 | udelay(1); |
| 43 | } while (1); |
| 44 | } |
Stephen Warren | f26402e | 2013-01-31 12:01:53 -0700 | [diff] [blame] | 45 | #else |
| 46 | static inline void tegra_serial_handle_break(struct uart_port *port) |
| 47 | { |
| 48 | } |
Dan Williams | bf03f65 | 2012-04-10 14:10:53 -0700 | [diff] [blame] | 49 | #endif |
| 50 | |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 51 | /* |
| 52 | * Fill a struct uart_port for a given device node |
| 53 | */ |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 54 | static int of_platform_serial_setup(struct platform_device *ofdev, |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 55 | int type, struct uart_port *port, |
| 56 | struct of_serial_info *info) |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 57 | { |
| 58 | struct resource resource; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 59 | struct device_node *np = ofdev->dev.of_node; |
Grant Likely | b84e773 | 2011-06-30 12:39:12 -0600 | [diff] [blame] | 60 | u32 clk, spd, prop; |
John Garry | a27d9382 | 2018-08-30 17:08:50 +0800 | [diff] [blame^] | 61 | int ret, irq; |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 62 | |
| 63 | memset(port, 0, sizeof *port); |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 64 | |
| 65 | pm_runtime_enable(&ofdev->dev); |
| 66 | pm_runtime_get_sync(&ofdev->dev); |
| 67 | |
Grant Likely | b84e773 | 2011-06-30 12:39:12 -0600 | [diff] [blame] | 68 | if (of_property_read_u32(np, "clock-frequency", &clk)) { |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 69 | |
| 70 | /* Get clk rate through clk driver if present */ |
Masahiro Yamada | 3a63d22 | 2015-05-25 14:57:43 +0900 | [diff] [blame] | 71 | info->clk = devm_clk_get(&ofdev->dev, NULL); |
Wei Yongjun | 76cc438 | 2012-11-01 13:27:34 +0800 | [diff] [blame] | 72 | if (IS_ERR(info->clk)) { |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 73 | dev_warn(&ofdev->dev, |
| 74 | "clk or clock-frequency not defined\n"); |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 75 | ret = PTR_ERR(info->clk); |
| 76 | goto err_pmruntime; |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Masahiro Yamada | 6f0c309 | 2015-05-25 15:03:32 +0900 | [diff] [blame] | 79 | ret = clk_prepare_enable(info->clk); |
| 80 | if (ret < 0) |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 81 | goto err_pmruntime; |
Masahiro Yamada | 6f0c309 | 2015-05-25 15:03:32 +0900 | [diff] [blame] | 82 | |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 83 | clk = clk_get_rate(info->clk); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 84 | } |
Grant Likely | b84e773 | 2011-06-30 12:39:12 -0600 | [diff] [blame] | 85 | /* If current-speed was set, then try not to change it. */ |
| 86 | if (of_property_read_u32(np, "current-speed", &spd) == 0) |
| 87 | port->custom_divisor = clk / (16 * spd); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 88 | |
| 89 | ret = of_address_to_resource(np, 0, &resource); |
| 90 | if (ret) { |
| 91 | dev_warn(&ofdev->dev, "invalid address\n"); |
Alexey Khoroshilov | fa9ba3ac | 2017-07-19 11:32:37 +0300 | [diff] [blame] | 92 | goto err_unprepare; |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 93 | } |
| 94 | |
John Garry | aa95947 | 2018-04-27 18:36:06 +0800 | [diff] [blame] | 95 | port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | |
| 96 | UPF_FIXED_TYPE; |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 97 | spin_lock_init(&port->lock); |
John Linn | b912b5e | 2008-04-03 10:22:19 +1100 | [diff] [blame] | 98 | |
John Garry | aa95947 | 2018-04-27 18:36:06 +0800 | [diff] [blame] | 99 | if (resource_type(&resource) == IORESOURCE_IO) { |
| 100 | port->iotype = UPIO_PORT; |
| 101 | port->iobase = resource.start; |
| 102 | } else { |
| 103 | port->mapbase = resource.start; |
| 104 | port->mapsize = resource_size(&resource); |
| 105 | |
| 106 | /* Check for shifted address mapping */ |
| 107 | if (of_property_read_u32(np, "reg-offset", &prop) == 0) |
| 108 | port->mapbase += prop; |
| 109 | |
| 110 | port->iotype = UPIO_MEM; |
| 111 | if (of_property_read_u32(np, "reg-io-width", &prop) == 0) { |
| 112 | switch (prop) { |
| 113 | case 1: |
| 114 | port->iotype = UPIO_MEM; |
| 115 | break; |
| 116 | case 2: |
| 117 | port->iotype = UPIO_MEM16; |
| 118 | break; |
| 119 | case 4: |
| 120 | port->iotype = of_device_is_big_endian(np) ? |
| 121 | UPIO_MEM32BE : UPIO_MEM32; |
| 122 | break; |
| 123 | default: |
| 124 | dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n", |
| 125 | prop); |
| 126 | ret = -EINVAL; |
Alexander Sverdlin | b29330d82 | 2018-07-13 16:58:54 +0200 | [diff] [blame] | 127 | goto err_unprepare; |
John Garry | aa95947 | 2018-04-27 18:36:06 +0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | port->flags |= UPF_IOREMAP; |
| 131 | } |
John Linn | b912b5e | 2008-04-03 10:22:19 +1100 | [diff] [blame] | 132 | |
| 133 | /* Check for registers offset within the devices address range */ |
Grant Likely | b84e773 | 2011-06-30 12:39:12 -0600 | [diff] [blame] | 134 | if (of_property_read_u32(np, "reg-shift", &prop) == 0) |
| 135 | port->regshift = prop; |
John Linn | b912b5e | 2008-04-03 10:22:19 +1100 | [diff] [blame] | 136 | |
Heikki Krogerus | 9f1ca06 | 2013-03-25 13:34:45 +0200 | [diff] [blame] | 137 | /* Check for fifo size */ |
| 138 | if (of_property_read_u32(np, "fifo-size", &prop) == 0) |
| 139 | port->fifosize = prop; |
| 140 | |
Lucas Stach | 3239fd3 | 2014-12-05 20:21:57 +0100 | [diff] [blame] | 141 | /* Check for a fixed line number */ |
| 142 | ret = of_alias_get_id(np, "serial"); |
| 143 | if (ret >= 0) |
| 144 | port->line = ret; |
| 145 | |
John Garry | a27d9382 | 2018-08-30 17:08:50 +0800 | [diff] [blame^] | 146 | irq = of_irq_get(np, 0); |
| 147 | if (irq < 0) { |
| 148 | if (irq == -EPROBE_DEFER) { |
| 149 | ret = -EPROBE_DEFER; |
| 150 | goto err_unprepare; |
| 151 | } |
| 152 | /* IRQ support not mandatory */ |
| 153 | irq = 0; |
Alexander Sverdlin | c58caaa | 2018-07-13 17:01:19 +0200 | [diff] [blame] | 154 | } |
Jamie Iles | 7423734 | 2011-06-27 13:32:34 +0100 | [diff] [blame] | 155 | |
John Garry | a27d9382 | 2018-08-30 17:08:50 +0800 | [diff] [blame^] | 156 | port->irq = irq; |
| 157 | |
Joel Stanley | e2860e1 | 2017-05-29 19:27:52 +0930 | [diff] [blame] | 158 | info->rst = devm_reset_control_get_optional_shared(&ofdev->dev, NULL); |
Masahiro Yamada | b9820a3 | 2017-12-27 14:21:05 +0900 | [diff] [blame] | 159 | if (IS_ERR(info->rst)) { |
| 160 | ret = PTR_ERR(info->rst); |
John Garry | a27d9382 | 2018-08-30 17:08:50 +0800 | [diff] [blame^] | 161 | goto err_unprepare; |
Masahiro Yamada | b9820a3 | 2017-12-27 14:21:05 +0900 | [diff] [blame] | 162 | } |
| 163 | |
Joel Stanley | e2860e1 | 2017-05-29 19:27:52 +0930 | [diff] [blame] | 164 | ret = reset_control_deassert(info->rst); |
| 165 | if (ret) |
John Garry | a27d9382 | 2018-08-30 17:08:50 +0800 | [diff] [blame^] | 166 | goto err_unprepare; |
Joel Stanley | e2860e1 | 2017-05-29 19:27:52 +0930 | [diff] [blame] | 167 | |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 168 | port->type = type; |
Grant Likely | b84e773 | 2011-06-30 12:39:12 -0600 | [diff] [blame] | 169 | port->uartclk = clk; |
Kurt Kanzenbach | 54e53b2 | 2018-03-16 12:31:58 +0100 | [diff] [blame] | 170 | port->irqflags |= IRQF_SHARED; |
Gabor Juhos | fde8be2 | 2012-07-17 17:08:31 +0100 | [diff] [blame] | 171 | |
Sergei Shtylyov | 5c98e9c | 2017-08-20 19:51:55 +0300 | [diff] [blame] | 172 | if (of_property_read_bool(np, "no-loopback-test")) |
Gabor Juhos | fde8be2 | 2012-07-17 17:08:31 +0100 | [diff] [blame] | 173 | port->flags |= UPF_SKIP_TEST; |
| 174 | |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 175 | port->dev = &ofdev->dev; |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 176 | |
John Crispin | 9b8777e | 2014-10-16 21:48:21 +0200 | [diff] [blame] | 177 | switch (type) { |
| 178 | case PORT_TEGRA: |
Dan Williams | bf03f65 | 2012-04-10 14:10:53 -0700 | [diff] [blame] | 179 | port->handle_break = tegra_serial_handle_break; |
John Crispin | 9b8777e | 2014-10-16 21:48:21 +0200 | [diff] [blame] | 180 | break; |
| 181 | |
| 182 | case PORT_RT2880: |
| 183 | port->iotype = UPIO_AU; |
| 184 | break; |
| 185 | } |
Dan Williams | bf03f65 | 2012-04-10 14:10:53 -0700 | [diff] [blame] | 186 | |
Scott Wood | d43b54d | 2015-10-07 17:31:21 -0500 | [diff] [blame] | 187 | if (IS_ENABLED(CONFIG_SERIAL_8250_FSL) && |
| 188 | (of_device_is_compatible(np, "fsl,ns16550") || |
| 189 | of_device_is_compatible(np, "fsl,16550-FIFO64"))) |
| 190 | port->handle_irq = fsl8250_handle_irq; |
| 191 | |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 192 | return 0; |
Alexey Khoroshilov | fa9ba3ac | 2017-07-19 11:32:37 +0300 | [diff] [blame] | 193 | err_unprepare: |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 194 | clk_disable_unprepare(info->clk); |
| 195 | err_pmruntime: |
| 196 | pm_runtime_put_sync(&ofdev->dev); |
| 197 | pm_runtime_disable(&ofdev->dev); |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 198 | return ret; |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* |
| 202 | * Try to register a serial port |
| 203 | */ |
Fabian Frederick | ed0bb23 | 2015-03-16 20:17:11 +0100 | [diff] [blame] | 204 | static const struct of_device_id of_platform_serial_table[]; |
Bill Pemberton | 9671f09 | 2012-11-19 13:21:50 -0500 | [diff] [blame] | 205 | static int of_platform_serial_probe(struct platform_device *ofdev) |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 206 | { |
Grant Likely | b1608d6 | 2011-05-18 11:19:24 -0600 | [diff] [blame] | 207 | const struct of_device_id *match; |
Ishizaki Kou | e34b9c9 | 2007-05-31 19:33:04 +1000 | [diff] [blame] | 208 | struct of_serial_info *info; |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 209 | struct uart_8250_port port8250; |
| 210 | u32 tx_threshold; |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 211 | int port_type; |
| 212 | int ret; |
| 213 | |
Grant Likely | b1608d6 | 2011-05-18 11:19:24 -0600 | [diff] [blame] | 214 | match = of_match_device(of_platform_serial_table, &ofdev->dev); |
| 215 | if (!match) |
Grant Likely | 793218d | 2011-02-22 21:10:26 -0700 | [diff] [blame] | 216 | return -EINVAL; |
| 217 | |
Sergei Shtylyov | 5c98e9c | 2017-08-20 19:51:55 +0300 | [diff] [blame] | 218 | if (of_property_read_bool(ofdev->dev.of_node, "used-by-rtas")) |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 219 | return -EBUSY; |
| 220 | |
Jingchang Lu | 7e12e67 | 2014-10-21 16:50:21 +0800 | [diff] [blame] | 221 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
Ishizaki Kou | e34b9c9 | 2007-05-31 19:33:04 +1000 | [diff] [blame] | 222 | if (info == NULL) |
| 223 | return -ENOMEM; |
| 224 | |
Grant Likely | b1608d6 | 2011-05-18 11:19:24 -0600 | [diff] [blame] | 225 | port_type = (unsigned long)match->data; |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 226 | memset(&port8250, 0, sizeof(port8250)); |
| 227 | ret = of_platform_serial_setup(ofdev, port_type, &port8250.port, info); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 228 | if (ret) |
Alexey Khoroshilov | fa9ba3ac | 2017-07-19 11:32:37 +0300 | [diff] [blame] | 229 | goto err_free; |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 230 | |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 231 | if (port8250.port.fifosize) |
| 232 | port8250.capabilities = UART_CAP_FIFO; |
Heikki Krogerus | b0b8c84 | 2013-03-25 15:51:15 +0200 | [diff] [blame] | 233 | |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 234 | /* Check for TX FIFO threshold & set tx_loadsz */ |
| 235 | if ((of_property_read_u32(ofdev->dev.of_node, "tx-threshold", |
| 236 | &tx_threshold) == 0) && |
| 237 | (tx_threshold < port8250.port.fifosize)) |
| 238 | port8250.tx_loadsz = port8250.port.fifosize - tx_threshold; |
Heikki Krogerus | b0b8c84 | 2013-03-25 15:51:15 +0200 | [diff] [blame] | 239 | |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 240 | if (of_property_read_bool(ofdev->dev.of_node, "auto-flow-control")) |
| 241 | port8250.capabilities |= UART_CAP_AFE; |
Thor Thayer | ffea043 | 2016-09-22 14:56:15 -0500 | [diff] [blame] | 242 | |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 243 | ret = serial8250_register_8250_port(&port8250); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 244 | if (ret < 0) |
Alexey Khoroshilov | fa9ba3ac | 2017-07-19 11:32:37 +0300 | [diff] [blame] | 245 | goto err_dispose; |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 246 | |
Ishizaki Kou | e34b9c9 | 2007-05-31 19:33:04 +1000 | [diff] [blame] | 247 | info->type = port_type; |
| 248 | info->line = ret; |
Jingoo Han | 696faed | 2013-05-23 19:39:36 +0900 | [diff] [blame] | 249 | platform_set_drvdata(ofdev, info); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 250 | return 0; |
Alexey Khoroshilov | fa9ba3ac | 2017-07-19 11:32:37 +0300 | [diff] [blame] | 251 | err_dispose: |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 252 | irq_dispose_mapping(port8250.port.irq); |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 253 | pm_runtime_put_sync(&ofdev->dev); |
| 254 | pm_runtime_disable(&ofdev->dev); |
| 255 | clk_disable_unprepare(info->clk); |
Alexey Khoroshilov | fa9ba3ac | 2017-07-19 11:32:37 +0300 | [diff] [blame] | 256 | err_free: |
| 257 | kfree(info); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 258 | return ret; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Release a line |
| 263 | */ |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 264 | static int of_platform_serial_remove(struct platform_device *ofdev) |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 265 | { |
Jingoo Han | 696faed | 2013-05-23 19:39:36 +0900 | [diff] [blame] | 266 | struct of_serial_info *info = platform_get_drvdata(ofdev); |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 267 | |
| 268 | serial8250_unregister_port(info->line); |
Murali Karicheri | 0bbeb3c | 2012-10-22 11:58:01 -0400 | [diff] [blame] | 269 | |
Joel Stanley | e2860e1 | 2017-05-29 19:27:52 +0930 | [diff] [blame] | 270 | reset_control_assert(info->rst); |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 271 | pm_runtime_put_sync(&ofdev->dev); |
| 272 | pm_runtime_disable(&ofdev->dev); |
| 273 | clk_disable_unprepare(info->clk); |
Ishizaki Kou | e34b9c9 | 2007-05-31 19:33:04 +1000 | [diff] [blame] | 274 | kfree(info); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 275 | return 0; |
| 276 | } |
| 277 | |
Jingchang Lu | 8ad3b13 | 2014-11-11 15:09:05 +0800 | [diff] [blame] | 278 | #ifdef CONFIG_PM_SLEEP |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 279 | static int of_serial_suspend(struct device *dev) |
Jingchang Lu | 8ad3b13 | 2014-11-11 15:09:05 +0800 | [diff] [blame] | 280 | { |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 281 | struct of_serial_info *info = dev_get_drvdata(dev); |
Jingchang Lu | 8ad3b13 | 2014-11-11 15:09:05 +0800 | [diff] [blame] | 282 | struct uart_8250_port *port8250 = serial8250_get_port(info->line); |
| 283 | struct uart_port *port = &port8250->port; |
| 284 | |
| 285 | serial8250_suspend_port(info->line); |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 286 | |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 287 | if (!uart_console(port) || console_suspend_enabled) { |
| 288 | pm_runtime_put_sync(dev); |
Jingchang Lu | 8ad3b13 | 2014-11-11 15:09:05 +0800 | [diff] [blame] | 289 | clk_disable_unprepare(info->clk); |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 290 | } |
Jingchang Lu | 8ad3b13 | 2014-11-11 15:09:05 +0800 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static int of_serial_resume(struct device *dev) |
| 295 | { |
| 296 | struct of_serial_info *info = dev_get_drvdata(dev); |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 297 | struct uart_8250_port *port8250 = serial8250_get_port(info->line); |
| 298 | struct uart_port *port = &port8250->port; |
Jingchang Lu | 8ad3b13 | 2014-11-11 15:09:05 +0800 | [diff] [blame] | 299 | |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 300 | if (!uart_console(port) || console_suspend_enabled) { |
| 301 | pm_runtime_get_sync(dev); |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 302 | clk_prepare_enable(info->clk); |
Franklin S Cooper Jr | a2d23eda | 2017-08-16 15:55:36 -0500 | [diff] [blame] | 303 | } |
Arnd Bergmann | aa42db4 | 2017-01-25 23:19:01 +0100 | [diff] [blame] | 304 | |
| 305 | serial8250_resume_port(info->line); |
Jingchang Lu | 8ad3b13 | 2014-11-11 15:09:05 +0800 | [diff] [blame] | 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | #endif |
| 310 | static SIMPLE_DEV_PM_OPS(of_serial_pm_ops, of_serial_suspend, of_serial_resume); |
| 311 | |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 312 | /* |
| 313 | * A few common types, add more as needed. |
| 314 | */ |
Fabian Frederick | ed0bb23 | 2015-03-16 20:17:11 +0100 | [diff] [blame] | 315 | static const struct of_device_id of_platform_serial_table[] = { |
Grant Likely | 8c6e911 | 2011-02-22 19:12:21 -0700 | [diff] [blame] | 316 | { .compatible = "ns8250", .data = (void *)PORT_8250, }, |
| 317 | { .compatible = "ns16450", .data = (void *)PORT_16450, }, |
| 318 | { .compatible = "ns16550a", .data = (void *)PORT_16550A, }, |
| 319 | { .compatible = "ns16550", .data = (void *)PORT_16550, }, |
| 320 | { .compatible = "ns16750", .data = (void *)PORT_16750, }, |
| 321 | { .compatible = "ns16850", .data = (void *)PORT_16850, }, |
Grant Likely | 2e39e5b | 2011-07-05 23:42:36 -0600 | [diff] [blame] | 322 | { .compatible = "nvidia,tegra20-uart", .data = (void *)PORT_TEGRA, }, |
Roland Stigge | e4305f0 | 2012-06-11 21:57:14 +0200 | [diff] [blame] | 323 | { .compatible = "nxp,lpc3220-uart", .data = (void *)PORT_LPC3220, }, |
John Crispin | 9b8777e | 2014-10-16 21:48:21 +0200 | [diff] [blame] | 324 | { .compatible = "ralink,rt2880-uart", .data = (void *)PORT_RT2880, }, |
Ley Foon Tan | e06c93c | 2013-03-07 10:28:37 +0800 | [diff] [blame] | 325 | { .compatible = "altr,16550-FIFO32", |
| 326 | .data = (void *)PORT_ALTR_16550_F32, }, |
| 327 | { .compatible = "altr,16550-FIFO64", |
| 328 | .data = (void *)PORT_ALTR_16550_F64, }, |
| 329 | { .compatible = "altr,16550-FIFO128", |
| 330 | .data = (void *)PORT_ALTR_16550_F128, }, |
Sean Wang | 1c16ae6 | 2017-08-21 01:17:56 +0800 | [diff] [blame] | 331 | { .compatible = "mediatek,mtk-btif", |
| 332 | .data = (void *)PORT_MTK_BTIF, }, |
Rob Herring | 6ad991b | 2015-01-26 22:50:08 -0600 | [diff] [blame] | 333 | { .compatible = "mrvl,mmp-uart", |
| 334 | .data = (void *)PORT_XSCALE, }, |
David Lechner | a2d6a98 | 2017-01-05 12:54:18 -0600 | [diff] [blame] | 335 | { .compatible = "ti,da830-uart", .data = (void *)PORT_DA830, }, |
Joel Stanley | f597fbc | 2018-03-05 22:17:38 +1030 | [diff] [blame] | 336 | { .compatible = "nuvoton,npcm750-uart", .data = (void *)PORT_NPCM, }, |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 337 | { /* end of list */ }, |
| 338 | }; |
Luis de Bethencourt | 8d58db1 | 2015-09-18 20:03:43 +0200 | [diff] [blame] | 339 | MODULE_DEVICE_TABLE(of, of_platform_serial_table); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 340 | |
Grant Likely | 793218d | 2011-02-22 21:10:26 -0700 | [diff] [blame] | 341 | static struct platform_driver of_platform_serial_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 342 | .driver = { |
| 343 | .name = "of_serial", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 344 | .of_match_table = of_platform_serial_table, |
Wang Dongsheng | 434ba16 | 2016-01-21 15:59:53 +0800 | [diff] [blame] | 345 | .pm = &of_serial_pm_ops, |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 346 | }, |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 347 | .probe = of_platform_serial_probe, |
| 348 | .remove = of_platform_serial_remove, |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 349 | }; |
| 350 | |
Grant Likely | 940ab88 | 2011-10-05 11:29:49 -0600 | [diff] [blame] | 351 | module_platform_driver(of_platform_serial_driver); |
Arnd Bergmann | 8d38a5b | 2007-02-13 21:35:38 +0100 | [diff] [blame] | 352 | |
| 353 | MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>"); |
| 354 | MODULE_LICENSE("GPL"); |
| 355 | MODULE_DESCRIPTION("Serial Port driver for Open Firmware platform devices"); |