John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1 | /* |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 2 | * Cadence UART driver (found in Xilinx Zynq) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 3 | * |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 4 | * 2011 - 2014 (C) Xilinx Inc. |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it |
| 7 | * and/or modify it under the terms of the GNU General Public |
| 8 | * License as published by the Free Software Foundation; |
| 9 | * either version 2 of the License, or (at your option) any |
| 10 | * later version. |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 11 | * |
| 12 | * This driver has originally been pushed by Xilinx using a Zynq-branding. This |
| 13 | * still shows in the naming of this file, the kconfig symbols and some symbols |
| 14 | * in the code. |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 15 | */ |
| 16 | |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 17 | #if defined(CONFIG_SERIAL_XILINX_PS_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 18 | #define SUPPORT_SYSRQ |
| 19 | #endif |
| 20 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 22 | #include <linux/serial.h> |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 23 | #include <linux/console.h> |
Jiri Slaby | ee160a3 | 2011-09-01 16:20:57 +0200 | [diff] [blame] | 24 | #include <linux/serial_core.h> |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 25 | #include <linux/slab.h> |
Jiri Slaby | ee160a3 | 2011-09-01 16:20:57 +0200 | [diff] [blame] | 26 | #include <linux/tty.h> |
| 27 | #include <linux/tty_flip.h> |
Josh Cartwright | 2326669c | 2013-01-21 19:57:41 +0100 | [diff] [blame] | 28 | #include <linux/clk.h> |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 29 | #include <linux/irq.h> |
| 30 | #include <linux/io.h> |
| 31 | #include <linux/of.h> |
Paul Gortmaker | 578b9ce | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 32 | #include <linux/module.h> |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 33 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 34 | #define CDNS_UART_TTY_NAME "ttyPS" |
| 35 | #define CDNS_UART_NAME "xuartps" |
| 36 | #define CDNS_UART_MAJOR 0 /* use dynamic node allocation */ |
| 37 | #define CDNS_UART_MINOR 0 /* works best with devtmpfs */ |
| 38 | #define CDNS_UART_NR_PORTS 2 |
| 39 | #define CDNS_UART_FIFO_SIZE 64 /* FIFO size */ |
| 40 | #define CDNS_UART_REGISTER_SPACE 0xFFF |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 41 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 42 | #define cdns_uart_readl(offset) ioread32(port->membase + offset) |
| 43 | #define cdns_uart_writel(val, offset) iowrite32(val, port->membase + offset) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 44 | |
Suneel | 85baf54 | 2013-10-17 14:08:08 -0700 | [diff] [blame] | 45 | /* Rx Trigger level */ |
| 46 | static int rx_trigger_level = 56; |
| 47 | module_param(rx_trigger_level, uint, S_IRUGO); |
| 48 | MODULE_PARM_DESC(rx_trigger_level, "Rx trigger level, 1-63 bytes"); |
| 49 | |
| 50 | /* Rx Timeout */ |
| 51 | static int rx_timeout = 10; |
| 52 | module_param(rx_timeout, uint, S_IRUGO); |
| 53 | MODULE_PARM_DESC(rx_timeout, "Rx timeout, 1-255"); |
| 54 | |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 55 | /* Register offsets for the UART. */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 56 | #define CDNS_UART_CR_OFFSET 0x00 /* Control Register */ |
| 57 | #define CDNS_UART_MR_OFFSET 0x04 /* Mode Register */ |
| 58 | #define CDNS_UART_IER_OFFSET 0x08 /* Interrupt Enable */ |
| 59 | #define CDNS_UART_IDR_OFFSET 0x0C /* Interrupt Disable */ |
| 60 | #define CDNS_UART_IMR_OFFSET 0x10 /* Interrupt Mask */ |
| 61 | #define CDNS_UART_ISR_OFFSET 0x14 /* Interrupt Status */ |
| 62 | #define CDNS_UART_BAUDGEN_OFFSET 0x18 /* Baud Rate Generator */ |
| 63 | #define CDNS_UART_RXTOUT_OFFSET 0x1C /* RX Timeout */ |
| 64 | #define CDNS_UART_RXWM_OFFSET 0x20 /* RX FIFO Trigger Level */ |
| 65 | #define CDNS_UART_MODEMCR_OFFSET 0x24 /* Modem Control */ |
| 66 | #define CDNS_UART_MODEMSR_OFFSET 0x28 /* Modem Status */ |
| 67 | #define CDNS_UART_SR_OFFSET 0x2C /* Channel Status */ |
| 68 | #define CDNS_UART_FIFO_OFFSET 0x30 /* FIFO */ |
| 69 | #define CDNS_UART_BAUDDIV_OFFSET 0x34 /* Baud Rate Divider */ |
| 70 | #define CDNS_UART_FLOWDEL_OFFSET 0x38 /* Flow Delay */ |
| 71 | #define CDNS_UART_IRRX_PWIDTH_OFFSET 0x3C /* IR Min Received Pulse Width */ |
| 72 | #define CDNS_UART_IRTX_PWIDTH_OFFSET 0x40 /* IR Transmitted pulse Width */ |
| 73 | #define CDNS_UART_TXWM_OFFSET 0x44 /* TX FIFO Trigger Level */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 74 | |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 75 | /* Control Register Bit Definitions */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 76 | #define CDNS_UART_CR_STOPBRK 0x00000100 /* Stop TX break */ |
| 77 | #define CDNS_UART_CR_STARTBRK 0x00000080 /* Set TX break */ |
| 78 | #define CDNS_UART_CR_TX_DIS 0x00000020 /* TX disabled. */ |
| 79 | #define CDNS_UART_CR_TX_EN 0x00000010 /* TX enabled */ |
| 80 | #define CDNS_UART_CR_RX_DIS 0x00000008 /* RX disabled. */ |
| 81 | #define CDNS_UART_CR_RX_EN 0x00000004 /* RX enabled */ |
| 82 | #define CDNS_UART_CR_TXRST 0x00000002 /* TX logic reset */ |
| 83 | #define CDNS_UART_CR_RXRST 0x00000001 /* RX logic reset */ |
| 84 | #define CDNS_UART_CR_RST_TO 0x00000040 /* Restart Timeout Counter */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 85 | |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Mode Register: |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 88 | * The mode register (MR) defines the mode of transfer as well as the data |
| 89 | * format. If this register is modified during transmission or reception, |
| 90 | * data validity cannot be guaranteed. |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 91 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 92 | #define CDNS_UART_MR_CLKSEL 0x00000001 /* Pre-scalar selection */ |
| 93 | #define CDNS_UART_MR_CHMODE_L_LOOP 0x00000200 /* Local loop back mode */ |
| 94 | #define CDNS_UART_MR_CHMODE_NORM 0x00000000 /* Normal mode */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 95 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 96 | #define CDNS_UART_MR_STOPMODE_2_BIT 0x00000080 /* 2 stop bits */ |
| 97 | #define CDNS_UART_MR_STOPMODE_1_BIT 0x00000000 /* 1 stop bit */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 98 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 99 | #define CDNS_UART_MR_PARITY_NONE 0x00000020 /* No parity mode */ |
| 100 | #define CDNS_UART_MR_PARITY_MARK 0x00000018 /* Mark parity mode */ |
| 101 | #define CDNS_UART_MR_PARITY_SPACE 0x00000010 /* Space parity mode */ |
| 102 | #define CDNS_UART_MR_PARITY_ODD 0x00000008 /* Odd parity mode */ |
| 103 | #define CDNS_UART_MR_PARITY_EVEN 0x00000000 /* Even parity mode */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 104 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 105 | #define CDNS_UART_MR_CHARLEN_6_BIT 0x00000006 /* 6 bits data */ |
| 106 | #define CDNS_UART_MR_CHARLEN_7_BIT 0x00000004 /* 7 bits data */ |
| 107 | #define CDNS_UART_MR_CHARLEN_8_BIT 0x00000000 /* 8 bits data */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 108 | |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 109 | /* |
| 110 | * Interrupt Registers: |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 111 | * Interrupt control logic uses the interrupt enable register (IER) and the |
| 112 | * interrupt disable register (IDR) to set the value of the bits in the |
| 113 | * interrupt mask register (IMR). The IMR determines whether to pass an |
| 114 | * interrupt to the interrupt status register (ISR). |
| 115 | * Writing a 1 to IER Enables an interrupt, writing a 1 to IDR disables an |
| 116 | * interrupt. IMR and ISR are read only, and IER and IDR are write only. |
| 117 | * Reading either IER or IDR returns 0x00. |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 118 | * All four registers have the same bit definitions. |
| 119 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 120 | #define CDNS_UART_IXR_TOUT 0x00000100 /* RX Timeout error interrupt */ |
| 121 | #define CDNS_UART_IXR_PARITY 0x00000080 /* Parity error interrupt */ |
| 122 | #define CDNS_UART_IXR_FRAMING 0x00000040 /* Framing error interrupt */ |
| 123 | #define CDNS_UART_IXR_OVERRUN 0x00000020 /* Overrun error interrupt */ |
| 124 | #define CDNS_UART_IXR_TXFULL 0x00000010 /* TX FIFO Full interrupt */ |
| 125 | #define CDNS_UART_IXR_TXEMPTY 0x00000008 /* TX FIFO empty interrupt */ |
| 126 | #define CDNS_UART_ISR_RXEMPTY 0x00000002 /* RX FIFO empty interrupt */ |
| 127 | #define CDNS_UART_IXR_RXTRIG 0x00000001 /* RX FIFO trigger interrupt */ |
| 128 | #define CDNS_UART_IXR_RXFULL 0x00000004 /* RX FIFO full interrupt. */ |
| 129 | #define CDNS_UART_IXR_RXEMPTY 0x00000002 /* RX FIFO empty interrupt. */ |
| 130 | #define CDNS_UART_IXR_MASK 0x00001FFF /* Valid bit mask */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 131 | |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 132 | /* Goes in read_status_mask for break detection as the HW doesn't do it*/ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 133 | #define CDNS_UART_IXR_BRK 0x80000000 |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 134 | |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 135 | /* |
Lars-Peter Clausen | 19038ad | 2014-11-05 13:35:16 +0100 | [diff] [blame] | 136 | * Modem Control register: |
| 137 | * The read/write Modem Control register controls the interface with the modem |
| 138 | * or data set, or a peripheral device emulating a modem. |
| 139 | */ |
| 140 | #define CDNS_UART_MODEMCR_FCM 0x00000020 /* Automatic flow control mode */ |
| 141 | #define CDNS_UART_MODEMCR_RTS 0x00000002 /* Request to send output control */ |
| 142 | #define CDNS_UART_MODEMCR_DTR 0x00000001 /* Data Terminal Ready */ |
| 143 | |
| 144 | /* |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 145 | * Channel Status Register: |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 146 | * The channel status register (CSR) is provided to enable the control logic |
| 147 | * to monitor the status of bits in the channel interrupt status register, |
| 148 | * even if these are masked out by the interrupt mask register. |
| 149 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 150 | #define CDNS_UART_SR_RXEMPTY 0x00000002 /* RX FIFO empty */ |
| 151 | #define CDNS_UART_SR_TXEMPTY 0x00000008 /* TX FIFO empty */ |
| 152 | #define CDNS_UART_SR_TXFULL 0x00000010 /* TX FIFO full */ |
| 153 | #define CDNS_UART_SR_RXTRIG 0x00000001 /* Rx Trigger */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 154 | |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 155 | /* baud dividers min/max values */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 156 | #define CDNS_UART_BDIV_MIN 4 |
| 157 | #define CDNS_UART_BDIV_MAX 255 |
| 158 | #define CDNS_UART_CD_MAX 65535 |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 159 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 160 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 161 | * struct cdns_uart - device data |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 162 | * @port: Pointer to the UART port |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 163 | * @uartclk: Reference clock |
| 164 | * @pclk: APB clock |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 165 | * @baud: Current baud rate |
| 166 | * @clk_rate_change_nb: Notifier block for clock changes |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 167 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 168 | struct cdns_uart { |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 169 | struct uart_port *port; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 170 | struct clk *uartclk; |
| 171 | struct clk *pclk; |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 172 | unsigned int baud; |
| 173 | struct notifier_block clk_rate_change_nb; |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 174 | }; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 175 | #define to_cdns_uart(_nb) container_of(_nb, struct cdns_uart, \ |
| 176 | clk_rate_change_nb); |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 177 | |
| 178 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 179 | * cdns_uart_isr - Interrupt handler |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 180 | * @irq: Irq number |
| 181 | * @dev_id: Id of the port |
| 182 | * |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 183 | * Return: IRQHANDLED |
| 184 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 185 | static irqreturn_t cdns_uart_isr(int irq, void *dev_id) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 186 | { |
| 187 | struct uart_port *port = (struct uart_port *)dev_id; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 188 | unsigned long flags; |
| 189 | unsigned int isrstatus, numbytes; |
| 190 | unsigned int data; |
| 191 | char status = TTY_NORMAL; |
| 192 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 193 | spin_lock_irqsave(&port->lock, flags); |
| 194 | |
| 195 | /* Read the interrupt status register to determine which |
| 196 | * interrupt(s) is/are active. |
| 197 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 198 | isrstatus = cdns_uart_readl(CDNS_UART_ISR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 199 | |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 200 | /* |
| 201 | * There is no hardware break detection, so we interpret framing |
| 202 | * error with all-zeros data as a break sequence. Most of the time, |
| 203 | * there's another non-zero byte at the end of the sequence. |
| 204 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 205 | if (isrstatus & CDNS_UART_IXR_FRAMING) { |
| 206 | while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & |
| 207 | CDNS_UART_SR_RXEMPTY)) { |
| 208 | if (!cdns_uart_readl(CDNS_UART_FIFO_OFFSET)) { |
| 209 | port->read_status_mask |= CDNS_UART_IXR_BRK; |
| 210 | isrstatus &= ~CDNS_UART_IXR_FRAMING; |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 213 | cdns_uart_writel(CDNS_UART_IXR_FRAMING, CDNS_UART_ISR_OFFSET); |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 214 | } |
| 215 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 216 | /* drop byte with parity error if IGNPAR specified */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 217 | if (isrstatus & port->ignore_status_mask & CDNS_UART_IXR_PARITY) |
| 218 | isrstatus &= ~(CDNS_UART_IXR_RXTRIG | CDNS_UART_IXR_TOUT); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 219 | |
| 220 | isrstatus &= port->read_status_mask; |
| 221 | isrstatus &= ~port->ignore_status_mask; |
| 222 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 223 | if ((isrstatus & CDNS_UART_IXR_TOUT) || |
| 224 | (isrstatus & CDNS_UART_IXR_RXTRIG)) { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 225 | /* Receive Timeout Interrupt */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 226 | while ((cdns_uart_readl(CDNS_UART_SR_OFFSET) & |
| 227 | CDNS_UART_SR_RXEMPTY) != CDNS_UART_SR_RXEMPTY) { |
| 228 | data = cdns_uart_readl(CDNS_UART_FIFO_OFFSET); |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 229 | |
| 230 | /* Non-NULL byte after BREAK is garbage (99%) */ |
| 231 | if (data && (port->read_status_mask & |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 232 | CDNS_UART_IXR_BRK)) { |
| 233 | port->read_status_mask &= ~CDNS_UART_IXR_BRK; |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 234 | port->icount.brk++; |
| 235 | if (uart_handle_break(port)) |
| 236 | continue; |
| 237 | } |
| 238 | |
Soren Brinkmann | c2db11e | 2013-12-02 11:38:38 -0800 | [diff] [blame] | 239 | #ifdef SUPPORT_SYSRQ |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 240 | /* |
| 241 | * uart_handle_sysrq_char() doesn't work if |
| 242 | * spinlocked, for some reason |
| 243 | */ |
| 244 | if (port->sysrq) { |
| 245 | spin_unlock(&port->lock); |
| 246 | if (uart_handle_sysrq_char(port, |
| 247 | (unsigned char)data)) { |
| 248 | spin_lock(&port->lock); |
| 249 | continue; |
| 250 | } |
| 251 | spin_lock(&port->lock); |
| 252 | } |
Soren Brinkmann | c2db11e | 2013-12-02 11:38:38 -0800 | [diff] [blame] | 253 | #endif |
Vlad Lungu | 0c0c47b | 2013-10-17 14:08:06 -0700 | [diff] [blame] | 254 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 255 | port->icount.rx++; |
| 256 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 257 | if (isrstatus & CDNS_UART_IXR_PARITY) { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 258 | port->icount.parity++; |
| 259 | status = TTY_PARITY; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 260 | } else if (isrstatus & CDNS_UART_IXR_FRAMING) { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 261 | port->icount.frame++; |
| 262 | status = TTY_FRAME; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 263 | } else if (isrstatus & CDNS_UART_IXR_OVERRUN) { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 264 | port->icount.overrun++; |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 265 | } |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 266 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 267 | uart_insert_char(port, isrstatus, CDNS_UART_IXR_OVERRUN, |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 268 | data, status); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 269 | } |
| 270 | spin_unlock(&port->lock); |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 271 | tty_flip_buffer_push(&port->state->port); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 272 | spin_lock(&port->lock); |
| 273 | } |
| 274 | |
| 275 | /* Dispatch an appropriate handler */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 276 | if ((isrstatus & CDNS_UART_IXR_TXEMPTY) == CDNS_UART_IXR_TXEMPTY) { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 277 | if (uart_circ_empty(&port->state->xmit)) { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 278 | cdns_uart_writel(CDNS_UART_IXR_TXEMPTY, |
| 279 | CDNS_UART_IDR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 280 | } else { |
| 281 | numbytes = port->fifosize; |
| 282 | /* Break if no more data available in the UART buffer */ |
| 283 | while (numbytes--) { |
| 284 | if (uart_circ_empty(&port->state->xmit)) |
| 285 | break; |
| 286 | /* Get the data from the UART circular buffer |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 287 | * and write it to the cdns_uart's TX_FIFO |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 288 | * register. |
| 289 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 290 | cdns_uart_writel( |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 291 | port->state->xmit.buf[port->state->xmit. |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 292 | tail], CDNS_UART_FIFO_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 293 | |
| 294 | port->icount.tx++; |
| 295 | |
| 296 | /* Adjust the tail of the UART buffer and wrap |
| 297 | * the buffer if it reaches limit. |
| 298 | */ |
| 299 | port->state->xmit.tail = |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 300 | (port->state->xmit.tail + 1) & |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 301 | (UART_XMIT_SIZE - 1); |
| 302 | } |
| 303 | |
| 304 | if (uart_circ_chars_pending( |
| 305 | &port->state->xmit) < WAKEUP_CHARS) |
| 306 | uart_write_wakeup(port); |
| 307 | } |
| 308 | } |
| 309 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 310 | cdns_uart_writel(isrstatus, CDNS_UART_ISR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 311 | |
| 312 | /* be sure to release the lock and tty before leaving */ |
| 313 | spin_unlock_irqrestore(&port->lock, flags); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 314 | |
| 315 | return IRQ_HANDLED; |
| 316 | } |
| 317 | |
| 318 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 319 | * cdns_uart_calc_baud_divs - Calculate baud rate divisors |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 320 | * @clk: UART module input clock |
| 321 | * @baud: Desired baud rate |
| 322 | * @rbdiv: BDIV value (return value) |
| 323 | * @rcd: CD value (return value) |
| 324 | * @div8: Value for clk_sel bit in mod (return value) |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 325 | * Return: baud rate, requested baud when possible, or actual baud when there |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 326 | * was too much error, zero if no valid divisors are found. |
| 327 | * |
| 328 | * Formula to obtain baud rate is |
| 329 | * baud_tx/rx rate = clk/CD * (BDIV + 1) |
| 330 | * input_clk = (Uart User Defined Clock or Apb Clock) |
| 331 | * depends on UCLKEN in MR Reg |
| 332 | * clk = input_clk or input_clk/8; |
| 333 | * depends on CLKS in MR reg |
| 334 | * CD and BDIV depends on values in |
| 335 | * baud rate generate register |
| 336 | * baud rate clock divisor register |
| 337 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 338 | static unsigned int cdns_uart_calc_baud_divs(unsigned int clk, |
| 339 | unsigned int baud, u32 *rbdiv, u32 *rcd, int *div8) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 340 | { |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 341 | u32 cd, bdiv; |
| 342 | unsigned int calc_baud; |
| 343 | unsigned int bestbaud = 0; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 344 | unsigned int bauderror; |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 345 | unsigned int besterror = ~0; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 346 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 347 | if (baud < clk / ((CDNS_UART_BDIV_MAX + 1) * CDNS_UART_CD_MAX)) { |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 348 | *div8 = 1; |
| 349 | clk /= 8; |
| 350 | } else { |
| 351 | *div8 = 0; |
| 352 | } |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 353 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 354 | for (bdiv = CDNS_UART_BDIV_MIN; bdiv <= CDNS_UART_BDIV_MAX; bdiv++) { |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 355 | cd = DIV_ROUND_CLOSEST(clk, baud * (bdiv + 1)); |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 356 | if (cd < 1 || cd > CDNS_UART_CD_MAX) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 357 | continue; |
| 358 | |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 359 | calc_baud = clk / (cd * (bdiv + 1)); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 360 | |
| 361 | if (baud > calc_baud) |
| 362 | bauderror = baud - calc_baud; |
| 363 | else |
| 364 | bauderror = calc_baud - baud; |
| 365 | |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 366 | if (besterror > bauderror) { |
| 367 | *rbdiv = bdiv; |
| 368 | *rcd = cd; |
| 369 | bestbaud = calc_baud; |
| 370 | besterror = bauderror; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 371 | } |
| 372 | } |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 373 | /* use the values when percent error is acceptable */ |
| 374 | if (((besterror * 100) / baud) < 3) |
| 375 | bestbaud = baud; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 376 | |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 377 | return bestbaud; |
| 378 | } |
| 379 | |
| 380 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 381 | * cdns_uart_set_baud_rate - Calculate and set the baud rate |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 382 | * @port: Handle to the uart port structure |
| 383 | * @baud: Baud rate to set |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 384 | * Return: baud rate, requested baud when possible, or actual baud when there |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 385 | * was too much error, zero if no valid divisors are found. |
| 386 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 387 | static unsigned int cdns_uart_set_baud_rate(struct uart_port *port, |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 388 | unsigned int baud) |
| 389 | { |
| 390 | unsigned int calc_baud; |
Soren Brinkmann | d54b181 | 2013-10-21 16:40:59 -0700 | [diff] [blame] | 391 | u32 cd = 0, bdiv = 0; |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 392 | u32 mreg; |
| 393 | int div8; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 394 | struct cdns_uart *cdns_uart = port->private_data; |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 395 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 396 | calc_baud = cdns_uart_calc_baud_divs(port->uartclk, baud, &bdiv, &cd, |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 397 | &div8); |
| 398 | |
| 399 | /* Write new divisors to hardware */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 400 | mreg = cdns_uart_readl(CDNS_UART_MR_OFFSET); |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 401 | if (div8) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 402 | mreg |= CDNS_UART_MR_CLKSEL; |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 403 | else |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 404 | mreg &= ~CDNS_UART_MR_CLKSEL; |
| 405 | cdns_uart_writel(mreg, CDNS_UART_MR_OFFSET); |
| 406 | cdns_uart_writel(cd, CDNS_UART_BAUDGEN_OFFSET); |
| 407 | cdns_uart_writel(bdiv, CDNS_UART_BAUDDIV_OFFSET); |
| 408 | cdns_uart->baud = baud; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 409 | |
| 410 | return calc_baud; |
| 411 | } |
| 412 | |
Soren Brinkmann | 7ac5734 | 2013-10-21 16:41:01 -0700 | [diff] [blame] | 413 | #ifdef CONFIG_COMMON_CLK |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 414 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 415 | * cdns_uart_clk_notitifer_cb - Clock notifier callback |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 416 | * @nb: Notifier block |
| 417 | * @event: Notify event |
| 418 | * @data: Notifier data |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 419 | * Return: NOTIFY_OK or NOTIFY_DONE on success, NOTIFY_BAD on error. |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 420 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 421 | static int cdns_uart_clk_notifier_cb(struct notifier_block *nb, |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 422 | unsigned long event, void *data) |
| 423 | { |
| 424 | u32 ctrl_reg; |
| 425 | struct uart_port *port; |
| 426 | int locked = 0; |
| 427 | struct clk_notifier_data *ndata = data; |
| 428 | unsigned long flags = 0; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 429 | struct cdns_uart *cdns_uart = to_cdns_uart(nb); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 430 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 431 | port = cdns_uart->port; |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 432 | if (port->suspended) |
| 433 | return NOTIFY_OK; |
| 434 | |
| 435 | switch (event) { |
| 436 | case PRE_RATE_CHANGE: |
| 437 | { |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 438 | u32 bdiv, cd; |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 439 | int div8; |
| 440 | |
| 441 | /* |
| 442 | * Find out if current baud-rate can be achieved with new clock |
| 443 | * frequency. |
| 444 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 445 | if (!cdns_uart_calc_baud_divs(ndata->new_rate, cdns_uart->baud, |
Soren Brinkmann | 5ce15d2 | 2014-04-04 17:23:40 -0700 | [diff] [blame] | 446 | &bdiv, &cd, &div8)) { |
| 447 | dev_warn(port->dev, "clock rate change rejected\n"); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 448 | return NOTIFY_BAD; |
Soren Brinkmann | 5ce15d2 | 2014-04-04 17:23:40 -0700 | [diff] [blame] | 449 | } |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 450 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 451 | spin_lock_irqsave(&cdns_uart->port->lock, flags); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 452 | |
| 453 | /* Disable the TX and RX to set baud rate */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 454 | ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 455 | ctrl_reg |= CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS; |
| 456 | cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 457 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 458 | spin_unlock_irqrestore(&cdns_uart->port->lock, flags); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 459 | |
| 460 | return NOTIFY_OK; |
| 461 | } |
| 462 | case POST_RATE_CHANGE: |
| 463 | /* |
| 464 | * Set clk dividers to generate correct baud with new clock |
| 465 | * frequency. |
| 466 | */ |
| 467 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 468 | spin_lock_irqsave(&cdns_uart->port->lock, flags); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 469 | |
| 470 | locked = 1; |
| 471 | port->uartclk = ndata->new_rate; |
| 472 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 473 | cdns_uart->baud = cdns_uart_set_baud_rate(cdns_uart->port, |
| 474 | cdns_uart->baud); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 475 | /* fall through */ |
| 476 | case ABORT_RATE_CHANGE: |
| 477 | if (!locked) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 478 | spin_lock_irqsave(&cdns_uart->port->lock, flags); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 479 | |
| 480 | /* Set TX/RX Reset */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 481 | ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 482 | ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST; |
| 483 | cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 484 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 485 | while (cdns_uart_readl(CDNS_UART_CR_OFFSET) & |
| 486 | (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST)) |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 487 | cpu_relax(); |
| 488 | |
| 489 | /* |
| 490 | * Clear the RX disable and TX disable bits and then set the TX |
| 491 | * enable bit and RX enable bit to enable the transmitter and |
| 492 | * receiver. |
| 493 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 494 | cdns_uart_writel(rx_timeout, CDNS_UART_RXTOUT_OFFSET); |
| 495 | ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 496 | ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS); |
| 497 | ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN; |
| 498 | cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 499 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 500 | spin_unlock_irqrestore(&cdns_uart->port->lock, flags); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 501 | |
| 502 | return NOTIFY_OK; |
| 503 | default: |
| 504 | return NOTIFY_DONE; |
| 505 | } |
| 506 | } |
Soren Brinkmann | 7ac5734 | 2013-10-21 16:41:01 -0700 | [diff] [blame] | 507 | #endif |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 508 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 509 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 510 | * cdns_uart_start_tx - Start transmitting bytes |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 511 | * @port: Handle to the uart port structure |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 512 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 513 | static void cdns_uart_start_tx(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 514 | { |
| 515 | unsigned int status, numbytes = port->fifosize; |
| 516 | |
| 517 | if (uart_circ_empty(&port->state->xmit) || uart_tx_stopped(port)) |
| 518 | return; |
| 519 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 520 | status = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 521 | /* Set the TX enable bit and clear the TX disable bit to enable the |
| 522 | * transmitter. |
| 523 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 524 | cdns_uart_writel((status & ~CDNS_UART_CR_TX_DIS) | CDNS_UART_CR_TX_EN, |
| 525 | CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 526 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 527 | while (numbytes-- && ((cdns_uart_readl(CDNS_UART_SR_OFFSET) & |
| 528 | CDNS_UART_SR_TXFULL)) != CDNS_UART_SR_TXFULL) { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 529 | /* Break if no more data available in the UART buffer */ |
| 530 | if (uart_circ_empty(&port->state->xmit)) |
| 531 | break; |
| 532 | |
| 533 | /* Get the data from the UART circular buffer and |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 534 | * write it to the cdns_uart's TX_FIFO register. |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 535 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 536 | cdns_uart_writel( |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 537 | port->state->xmit.buf[port->state->xmit.tail], |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 538 | CDNS_UART_FIFO_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 539 | port->icount.tx++; |
| 540 | |
| 541 | /* Adjust the tail of the UART buffer and wrap |
| 542 | * the buffer if it reaches limit. |
| 543 | */ |
| 544 | port->state->xmit.tail = (port->state->xmit.tail + 1) & |
| 545 | (UART_XMIT_SIZE - 1); |
| 546 | } |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 547 | cdns_uart_writel(CDNS_UART_IXR_TXEMPTY, CDNS_UART_ISR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 548 | /* Enable the TX Empty interrupt */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 549 | cdns_uart_writel(CDNS_UART_IXR_TXEMPTY, CDNS_UART_IER_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 550 | |
| 551 | if (uart_circ_chars_pending(&port->state->xmit) < WAKEUP_CHARS) |
| 552 | uart_write_wakeup(port); |
| 553 | } |
| 554 | |
| 555 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 556 | * cdns_uart_stop_tx - Stop TX |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 557 | * @port: Handle to the uart port structure |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 558 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 559 | static void cdns_uart_stop_tx(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 560 | { |
| 561 | unsigned int regval; |
| 562 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 563 | regval = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 564 | regval |= CDNS_UART_CR_TX_DIS; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 565 | /* Disable the transmitter */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 566 | cdns_uart_writel(regval, CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 570 | * cdns_uart_stop_rx - Stop RX |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 571 | * @port: Handle to the uart port structure |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 572 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 573 | static void cdns_uart_stop_rx(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 574 | { |
| 575 | unsigned int regval; |
| 576 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 577 | regval = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 578 | regval |= CDNS_UART_CR_RX_DIS; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 579 | /* Disable the receiver */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 580 | cdns_uart_writel(regval, CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 584 | * cdns_uart_tx_empty - Check whether TX is empty |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 585 | * @port: Handle to the uart port structure |
| 586 | * |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 587 | * Return: TIOCSER_TEMT on success, 0 otherwise |
| 588 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 589 | static unsigned int cdns_uart_tx_empty(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 590 | { |
| 591 | unsigned int status; |
| 592 | |
Lars-Peter Clausen | 6731af5 | 2014-09-05 09:45:17 +0200 | [diff] [blame] | 593 | status = cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_TXEMPTY; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 594 | return status ? TIOCSER_TEMT : 0; |
| 595 | } |
| 596 | |
| 597 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 598 | * cdns_uart_break_ctl - Based on the input ctl we have to start or stop |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 599 | * transmitting char breaks |
| 600 | * @port: Handle to the uart port structure |
| 601 | * @ctl: Value based on which start or stop decision is taken |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 602 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 603 | static void cdns_uart_break_ctl(struct uart_port *port, int ctl) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 604 | { |
| 605 | unsigned int status; |
| 606 | unsigned long flags; |
| 607 | |
| 608 | spin_lock_irqsave(&port->lock, flags); |
| 609 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 610 | status = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 611 | |
| 612 | if (ctl == -1) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 613 | cdns_uart_writel(CDNS_UART_CR_STARTBRK | status, |
| 614 | CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 615 | else { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 616 | if ((status & CDNS_UART_CR_STOPBRK) == 0) |
| 617 | cdns_uart_writel(CDNS_UART_CR_STOPBRK | status, |
| 618 | CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 619 | } |
| 620 | spin_unlock_irqrestore(&port->lock, flags); |
| 621 | } |
| 622 | |
| 623 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 624 | * cdns_uart_set_termios - termios operations, handling data length, parity, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 625 | * stop bits, flow control, baud rate |
| 626 | * @port: Handle to the uart port structure |
| 627 | * @termios: Handle to the input termios structure |
| 628 | * @old: Values of the previously saved termios structure |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 629 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 630 | static void cdns_uart_set_termios(struct uart_port *port, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 631 | struct ktermios *termios, struct ktermios *old) |
| 632 | { |
| 633 | unsigned int cval = 0; |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 634 | unsigned int baud, minbaud, maxbaud; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 635 | unsigned long flags; |
| 636 | unsigned int ctrl_reg, mode_reg; |
| 637 | |
| 638 | spin_lock_irqsave(&port->lock, flags); |
| 639 | |
Nathan Rossi | 6ecde47 | 2015-01-16 13:49:25 +0100 | [diff] [blame] | 640 | /* Wait for the transmit FIFO to empty before making changes */ |
| 641 | if (!(cdns_uart_readl(CDNS_UART_CR_OFFSET) & CDNS_UART_CR_TX_DIS)) { |
| 642 | while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & |
| 643 | CDNS_UART_SR_TXEMPTY)) { |
| 644 | cpu_relax(); |
| 645 | } |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /* Disable the TX and RX to set baud rate */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 649 | ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 650 | ctrl_reg |= CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS; |
| 651 | cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 652 | |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 653 | /* |
| 654 | * Min baud rate = 6bps and Max Baud Rate is 10Mbps for 100Mhz clk |
| 655 | * min and max baud should be calculated here based on port->uartclk. |
| 656 | * this way we get a valid baud and can safely call set_baud() |
| 657 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 658 | minbaud = port->uartclk / |
| 659 | ((CDNS_UART_BDIV_MAX + 1) * CDNS_UART_CD_MAX * 8); |
| 660 | maxbaud = port->uartclk / (CDNS_UART_BDIV_MIN + 1); |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 661 | baud = uart_get_baud_rate(port, termios, old, minbaud, maxbaud); |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 662 | baud = cdns_uart_set_baud_rate(port, baud); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 663 | if (tty_termios_baud_rate(termios)) |
| 664 | tty_termios_encode_baud_rate(termios, baud, baud); |
| 665 | |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 666 | /* Update the per-port timeout. */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 667 | uart_update_timeout(port, termios->c_cflag, baud); |
| 668 | |
| 669 | /* Set TX/RX Reset */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 670 | ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 671 | ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST; |
| 672 | cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 673 | |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 674 | /* |
| 675 | * Clear the RX disable and TX disable bits and then set the TX enable |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 676 | * bit and RX enable bit to enable the transmitter and receiver. |
| 677 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 678 | ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 679 | ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS); |
| 680 | ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN; |
| 681 | cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 682 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 683 | cdns_uart_writel(rx_timeout, CDNS_UART_RXTOUT_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 684 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 685 | port->read_status_mask = CDNS_UART_IXR_TXEMPTY | CDNS_UART_IXR_RXTRIG | |
| 686 | CDNS_UART_IXR_OVERRUN | CDNS_UART_IXR_TOUT; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 687 | port->ignore_status_mask = 0; |
| 688 | |
| 689 | if (termios->c_iflag & INPCK) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 690 | port->read_status_mask |= CDNS_UART_IXR_PARITY | |
| 691 | CDNS_UART_IXR_FRAMING; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 692 | |
| 693 | if (termios->c_iflag & IGNPAR) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 694 | port->ignore_status_mask |= CDNS_UART_IXR_PARITY | |
| 695 | CDNS_UART_IXR_FRAMING | CDNS_UART_IXR_OVERRUN; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 696 | |
| 697 | /* ignore all characters if CREAD is not set */ |
| 698 | if ((termios->c_cflag & CREAD) == 0) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 699 | port->ignore_status_mask |= CDNS_UART_IXR_RXTRIG | |
| 700 | CDNS_UART_IXR_TOUT | CDNS_UART_IXR_PARITY | |
| 701 | CDNS_UART_IXR_FRAMING | CDNS_UART_IXR_OVERRUN; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 702 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 703 | mode_reg = cdns_uart_readl(CDNS_UART_MR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 704 | |
| 705 | /* Handling Data Size */ |
| 706 | switch (termios->c_cflag & CSIZE) { |
| 707 | case CS6: |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 708 | cval |= CDNS_UART_MR_CHARLEN_6_BIT; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 709 | break; |
| 710 | case CS7: |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 711 | cval |= CDNS_UART_MR_CHARLEN_7_BIT; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 712 | break; |
| 713 | default: |
| 714 | case CS8: |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 715 | cval |= CDNS_UART_MR_CHARLEN_8_BIT; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 716 | termios->c_cflag &= ~CSIZE; |
| 717 | termios->c_cflag |= CS8; |
| 718 | break; |
| 719 | } |
| 720 | |
| 721 | /* Handling Parity and Stop Bits length */ |
| 722 | if (termios->c_cflag & CSTOPB) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 723 | cval |= CDNS_UART_MR_STOPMODE_2_BIT; /* 2 STOP bits */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 724 | else |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 725 | cval |= CDNS_UART_MR_STOPMODE_1_BIT; /* 1 STOP bit */ |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 726 | |
| 727 | if (termios->c_cflag & PARENB) { |
| 728 | /* Mark or Space parity */ |
| 729 | if (termios->c_cflag & CMSPAR) { |
| 730 | if (termios->c_cflag & PARODD) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 731 | cval |= CDNS_UART_MR_PARITY_MARK; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 732 | else |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 733 | cval |= CDNS_UART_MR_PARITY_SPACE; |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 734 | } else { |
| 735 | if (termios->c_cflag & PARODD) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 736 | cval |= CDNS_UART_MR_PARITY_ODD; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 737 | else |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 738 | cval |= CDNS_UART_MR_PARITY_EVEN; |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 739 | } |
| 740 | } else { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 741 | cval |= CDNS_UART_MR_PARITY_NONE; |
Soren Brinkmann | e6b39bf | 2013-10-17 14:08:10 -0700 | [diff] [blame] | 742 | } |
| 743 | cval |= mode_reg & 1; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 744 | cdns_uart_writel(cval, CDNS_UART_MR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 745 | |
| 746 | spin_unlock_irqrestore(&port->lock, flags); |
| 747 | } |
| 748 | |
| 749 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 750 | * cdns_uart_startup - Called when an application opens a cdns_uart port |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 751 | * @port: Handle to the uart port structure |
| 752 | * |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 753 | * Return: 0 on success, negative errno otherwise |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 754 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 755 | static int cdns_uart_startup(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 756 | { |
| 757 | unsigned int retval = 0, status = 0; |
| 758 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 759 | retval = request_irq(port->irq, cdns_uart_isr, 0, CDNS_UART_NAME, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 760 | (void *)port); |
| 761 | if (retval) |
| 762 | return retval; |
| 763 | |
| 764 | /* Disable the TX and RX */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 765 | cdns_uart_writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS, |
| 766 | CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 767 | |
| 768 | /* Set the Control Register with TX/RX Enable, TX/RX Reset, |
| 769 | * no break chars. |
| 770 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 771 | cdns_uart_writel(CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST, |
| 772 | CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 773 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 774 | status = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 775 | |
| 776 | /* Clear the RX disable and TX disable bits and then set the TX enable |
| 777 | * bit and RX enable bit to enable the transmitter and receiver. |
| 778 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 779 | cdns_uart_writel((status & ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS)) |
| 780 | | (CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN | |
| 781 | CDNS_UART_CR_STOPBRK), CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 782 | |
| 783 | /* Set the Mode Register with normal mode,8 data bits,1 stop bit, |
| 784 | * no parity. |
| 785 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 786 | cdns_uart_writel(CDNS_UART_MR_CHMODE_NORM | CDNS_UART_MR_STOPMODE_1_BIT |
| 787 | | CDNS_UART_MR_PARITY_NONE | CDNS_UART_MR_CHARLEN_8_BIT, |
| 788 | CDNS_UART_MR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 789 | |
Suneel | 85baf54 | 2013-10-17 14:08:08 -0700 | [diff] [blame] | 790 | /* |
| 791 | * Set the RX FIFO Trigger level to use most of the FIFO, but it |
| 792 | * can be tuned with a module parameter |
| 793 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 794 | cdns_uart_writel(rx_trigger_level, CDNS_UART_RXWM_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 795 | |
Suneel | 85baf54 | 2013-10-17 14:08:08 -0700 | [diff] [blame] | 796 | /* |
| 797 | * Receive Timeout register is enabled but it |
| 798 | * can be tuned with a module parameter |
| 799 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 800 | cdns_uart_writel(rx_timeout, CDNS_UART_RXTOUT_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 801 | |
John Linn | 855f6fd | 2013-03-22 18:49:27 +0100 | [diff] [blame] | 802 | /* Clear out any pending interrupts before enabling them */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 803 | cdns_uart_writel(cdns_uart_readl(CDNS_UART_ISR_OFFSET), |
| 804 | CDNS_UART_ISR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 805 | |
| 806 | /* Set the Interrupt Registers with desired interrupts */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 807 | cdns_uart_writel(CDNS_UART_IXR_TXEMPTY | CDNS_UART_IXR_PARITY | |
| 808 | CDNS_UART_IXR_FRAMING | CDNS_UART_IXR_OVERRUN | |
| 809 | CDNS_UART_IXR_RXTRIG | CDNS_UART_IXR_TOUT, |
| 810 | CDNS_UART_IER_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 811 | |
| 812 | return retval; |
| 813 | } |
| 814 | |
| 815 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 816 | * cdns_uart_shutdown - Called when an application closes a cdns_uart port |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 817 | * @port: Handle to the uart port structure |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 818 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 819 | static void cdns_uart_shutdown(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 820 | { |
| 821 | int status; |
| 822 | |
| 823 | /* Disable interrupts */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 824 | status = cdns_uart_readl(CDNS_UART_IMR_OFFSET); |
| 825 | cdns_uart_writel(status, CDNS_UART_IDR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 826 | |
| 827 | /* Disable the TX and RX */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 828 | cdns_uart_writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS, |
| 829 | CDNS_UART_CR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 830 | free_irq(port->irq, port); |
| 831 | } |
| 832 | |
| 833 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 834 | * cdns_uart_type - Set UART type to cdns_uart port |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 835 | * @port: Handle to the uart port structure |
| 836 | * |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 837 | * Return: string on success, NULL otherwise |
| 838 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 839 | static const char *cdns_uart_type(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 840 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 841 | return port->type == PORT_XUARTPS ? CDNS_UART_NAME : NULL; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 845 | * cdns_uart_verify_port - Verify the port params |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 846 | * @port: Handle to the uart port structure |
| 847 | * @ser: Handle to the structure whose members are compared |
| 848 | * |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 849 | * Return: 0 on success, negative errno otherwise. |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 850 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 851 | static int cdns_uart_verify_port(struct uart_port *port, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 852 | struct serial_struct *ser) |
| 853 | { |
| 854 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_XUARTPS) |
| 855 | return -EINVAL; |
| 856 | if (port->irq != ser->irq) |
| 857 | return -EINVAL; |
| 858 | if (ser->io_type != UPIO_MEM) |
| 859 | return -EINVAL; |
| 860 | if (port->iobase != ser->port) |
| 861 | return -EINVAL; |
| 862 | if (ser->hub6 != 0) |
| 863 | return -EINVAL; |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 868 | * cdns_uart_request_port - Claim the memory region attached to cdns_uart port, |
| 869 | * called when the driver adds a cdns_uart port via |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 870 | * uart_add_one_port() |
| 871 | * @port: Handle to the uart port structure |
| 872 | * |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 873 | * Return: 0 on success, negative errno otherwise. |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 874 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 875 | static int cdns_uart_request_port(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 876 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 877 | if (!request_mem_region(port->mapbase, CDNS_UART_REGISTER_SPACE, |
| 878 | CDNS_UART_NAME)) { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 879 | return -ENOMEM; |
| 880 | } |
| 881 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 882 | port->membase = ioremap(port->mapbase, CDNS_UART_REGISTER_SPACE); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 883 | if (!port->membase) { |
| 884 | dev_err(port->dev, "Unable to map registers\n"); |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 885 | release_mem_region(port->mapbase, CDNS_UART_REGISTER_SPACE); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 886 | return -ENOMEM; |
| 887 | } |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 892 | * cdns_uart_release_port - Release UART port |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 893 | * @port: Handle to the uart port structure |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 894 | * |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 895 | * Release the memory region attached to a cdns_uart port. Called when the |
| 896 | * driver removes a cdns_uart port via uart_remove_one_port(). |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 897 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 898 | static void cdns_uart_release_port(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 899 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 900 | release_mem_region(port->mapbase, CDNS_UART_REGISTER_SPACE); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 901 | iounmap(port->membase); |
| 902 | port->membase = NULL; |
| 903 | } |
| 904 | |
| 905 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 906 | * cdns_uart_config_port - Configure UART port |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 907 | * @port: Handle to the uart port structure |
| 908 | * @flags: If any |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 909 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 910 | static void cdns_uart_config_port(struct uart_port *port, int flags) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 911 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 912 | if (flags & UART_CONFIG_TYPE && cdns_uart_request_port(port) == 0) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 913 | port->type = PORT_XUARTPS; |
| 914 | } |
| 915 | |
| 916 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 917 | * cdns_uart_get_mctrl - Get the modem control state |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 918 | * @port: Handle to the uart port structure |
| 919 | * |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 920 | * Return: the modem control state |
| 921 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 922 | static unsigned int cdns_uart_get_mctrl(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 923 | { |
| 924 | return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR; |
| 925 | } |
| 926 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 927 | static void cdns_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 928 | { |
Lars-Peter Clausen | 19038ad | 2014-11-05 13:35:16 +0100 | [diff] [blame] | 929 | u32 val; |
| 930 | |
| 931 | val = cdns_uart_readl(CDNS_UART_MODEMCR_OFFSET); |
| 932 | |
| 933 | val &= ~(CDNS_UART_MODEMCR_RTS | CDNS_UART_MODEMCR_DTR); |
| 934 | |
| 935 | if (mctrl & TIOCM_RTS) |
| 936 | val |= CDNS_UART_MODEMCR_RTS; |
| 937 | if (mctrl & TIOCM_DTR) |
| 938 | val |= CDNS_UART_MODEMCR_DTR; |
| 939 | |
| 940 | cdns_uart_writel(val, CDNS_UART_MODEMCR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 941 | } |
| 942 | |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 943 | #ifdef CONFIG_CONSOLE_POLL |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 944 | static int cdns_uart_poll_get_char(struct uart_port *port) |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 945 | { |
| 946 | u32 imr; |
| 947 | int c; |
| 948 | |
| 949 | /* Disable all interrupts */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 950 | imr = cdns_uart_readl(CDNS_UART_IMR_OFFSET); |
| 951 | cdns_uart_writel(imr, CDNS_UART_IDR_OFFSET); |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 952 | |
| 953 | /* Check if FIFO is empty */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 954 | if (cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_RXEMPTY) |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 955 | c = NO_POLL_CHAR; |
| 956 | else /* Read a character */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 957 | c = (unsigned char) cdns_uart_readl(CDNS_UART_FIFO_OFFSET); |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 958 | |
| 959 | /* Enable interrupts */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 960 | cdns_uart_writel(imr, CDNS_UART_IER_OFFSET); |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 961 | |
| 962 | return c; |
| 963 | } |
| 964 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 965 | static void cdns_uart_poll_put_char(struct uart_port *port, unsigned char c) |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 966 | { |
| 967 | u32 imr; |
| 968 | |
| 969 | /* Disable all interrupts */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 970 | imr = cdns_uart_readl(CDNS_UART_IMR_OFFSET); |
| 971 | cdns_uart_writel(imr, CDNS_UART_IDR_OFFSET); |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 972 | |
| 973 | /* Wait until FIFO is empty */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 974 | while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_TXEMPTY)) |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 975 | cpu_relax(); |
| 976 | |
| 977 | /* Write a character */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 978 | cdns_uart_writel(c, CDNS_UART_FIFO_OFFSET); |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 979 | |
| 980 | /* Wait until FIFO is empty */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 981 | while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_TXEMPTY)) |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 982 | cpu_relax(); |
| 983 | |
| 984 | /* Enable interrupts */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 985 | cdns_uart_writel(imr, CDNS_UART_IER_OFFSET); |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 986 | |
| 987 | return; |
| 988 | } |
| 989 | #endif |
| 990 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 991 | static struct uart_ops cdns_uart_ops = { |
| 992 | .set_mctrl = cdns_uart_set_mctrl, |
| 993 | .get_mctrl = cdns_uart_get_mctrl, |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 994 | .start_tx = cdns_uart_start_tx, |
| 995 | .stop_tx = cdns_uart_stop_tx, |
| 996 | .stop_rx = cdns_uart_stop_rx, |
| 997 | .tx_empty = cdns_uart_tx_empty, |
| 998 | .break_ctl = cdns_uart_break_ctl, |
| 999 | .set_termios = cdns_uart_set_termios, |
| 1000 | .startup = cdns_uart_startup, |
| 1001 | .shutdown = cdns_uart_shutdown, |
| 1002 | .type = cdns_uart_type, |
| 1003 | .verify_port = cdns_uart_verify_port, |
| 1004 | .request_port = cdns_uart_request_port, |
| 1005 | .release_port = cdns_uart_release_port, |
| 1006 | .config_port = cdns_uart_config_port, |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 1007 | #ifdef CONFIG_CONSOLE_POLL |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1008 | .poll_get_char = cdns_uart_poll_get_char, |
| 1009 | .poll_put_char = cdns_uart_poll_put_char, |
Vlad Lungu | 6ee04c6 | 2013-10-17 14:08:07 -0700 | [diff] [blame] | 1010 | #endif |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1011 | }; |
| 1012 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1013 | static struct uart_port cdns_uart_port[2]; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1014 | |
| 1015 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1016 | * cdns_uart_get_port - Configure the port from platform device resource info |
Michal Simek | 928e926 | 2014-04-04 17:23:38 -0700 | [diff] [blame] | 1017 | * @id: Port id |
| 1018 | * |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1019 | * Return: a pointer to a uart_port or NULL for failure |
| 1020 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1021 | static struct uart_port *cdns_uart_get_port(int id) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1022 | { |
| 1023 | struct uart_port *port; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1024 | |
Michal Simek | 928e926 | 2014-04-04 17:23:38 -0700 | [diff] [blame] | 1025 | /* Try the given port id if failed use default method */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1026 | if (cdns_uart_port[id].mapbase != 0) { |
Michal Simek | 928e926 | 2014-04-04 17:23:38 -0700 | [diff] [blame] | 1027 | /* Find the next unused port */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1028 | for (id = 0; id < CDNS_UART_NR_PORTS; id++) |
| 1029 | if (cdns_uart_port[id].mapbase == 0) |
Michal Simek | 928e926 | 2014-04-04 17:23:38 -0700 | [diff] [blame] | 1030 | break; |
| 1031 | } |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1032 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1033 | if (id >= CDNS_UART_NR_PORTS) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1034 | return NULL; |
| 1035 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1036 | port = &cdns_uart_port[id]; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1037 | |
| 1038 | /* At this point, we've got an empty uart_port struct, initialize it */ |
| 1039 | spin_lock_init(&port->lock); |
| 1040 | port->membase = NULL; |
| 1041 | port->iobase = 1; /* mark port in use */ |
| 1042 | port->irq = 0; |
| 1043 | port->type = PORT_UNKNOWN; |
| 1044 | port->iotype = UPIO_MEM32; |
| 1045 | port->flags = UPF_BOOT_AUTOCONF; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1046 | port->ops = &cdns_uart_ops; |
| 1047 | port->fifosize = CDNS_UART_FIFO_SIZE; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1048 | port->line = id; |
| 1049 | port->dev = NULL; |
| 1050 | return port; |
| 1051 | } |
| 1052 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1053 | #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE |
| 1054 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1055 | * cdns_uart_console_wait_tx - Wait for the TX to be full |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1056 | * @port: Handle to the uart port structure |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1057 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1058 | static void cdns_uart_console_wait_tx(struct uart_port *port) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1059 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1060 | while ((cdns_uart_readl(CDNS_UART_SR_OFFSET) & CDNS_UART_SR_TXEMPTY) |
| 1061 | != CDNS_UART_SR_TXEMPTY) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1062 | barrier(); |
| 1063 | } |
| 1064 | |
| 1065 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1066 | * cdns_uart_console_putchar - write the character to the FIFO buffer |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1067 | * @port: Handle to the uart port structure |
| 1068 | * @ch: Character to be written |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1069 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1070 | static void cdns_uart_console_putchar(struct uart_port *port, int ch) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1071 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1072 | cdns_uart_console_wait_tx(port); |
| 1073 | cdns_uart_writel(ch, CDNS_UART_FIFO_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1074 | } |
| 1075 | |
Michal Simek | 6fa62fc | 2014-09-10 12:43:02 +0200 | [diff] [blame] | 1076 | static void cdns_early_write(struct console *con, const char *s, unsigned n) |
| 1077 | { |
| 1078 | struct earlycon_device *dev = con->data; |
| 1079 | |
| 1080 | uart_console_write(&dev->port, s, n, cdns_uart_console_putchar); |
| 1081 | } |
| 1082 | |
| 1083 | static int __init cdns_early_console_setup(struct earlycon_device *device, |
| 1084 | const char *opt) |
| 1085 | { |
| 1086 | if (!device->port.membase) |
| 1087 | return -ENODEV; |
| 1088 | |
| 1089 | device->con->write = cdns_early_write; |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | EARLYCON_DECLARE(cdns, cdns_early_console_setup); |
| 1094 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1095 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1096 | * cdns_uart_console_write - perform write operation |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1097 | * @co: Console handle |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1098 | * @s: Pointer to character array |
| 1099 | * @count: No of characters |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1100 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1101 | static void cdns_uart_console_write(struct console *co, const char *s, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1102 | unsigned int count) |
| 1103 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1104 | struct uart_port *port = &cdns_uart_port[co->index]; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1105 | unsigned long flags; |
Lars-Peter Clausen | d3755f5 | 2013-10-17 14:08:09 -0700 | [diff] [blame] | 1106 | unsigned int imr, ctrl; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1107 | int locked = 1; |
| 1108 | |
| 1109 | if (oops_in_progress) |
| 1110 | locked = spin_trylock_irqsave(&port->lock, flags); |
| 1111 | else |
| 1112 | spin_lock_irqsave(&port->lock, flags); |
| 1113 | |
| 1114 | /* save and disable interrupt */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1115 | imr = cdns_uart_readl(CDNS_UART_IMR_OFFSET); |
| 1116 | cdns_uart_writel(imr, CDNS_UART_IDR_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1117 | |
Lars-Peter Clausen | d3755f5 | 2013-10-17 14:08:09 -0700 | [diff] [blame] | 1118 | /* |
| 1119 | * Make sure that the tx part is enabled. Set the TX enable bit and |
| 1120 | * clear the TX disable bit to enable the transmitter. |
| 1121 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1122 | ctrl = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 1123 | cdns_uart_writel((ctrl & ~CDNS_UART_CR_TX_DIS) | CDNS_UART_CR_TX_EN, |
| 1124 | CDNS_UART_CR_OFFSET); |
Lars-Peter Clausen | d3755f5 | 2013-10-17 14:08:09 -0700 | [diff] [blame] | 1125 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1126 | uart_console_write(port, s, count, cdns_uart_console_putchar); |
| 1127 | cdns_uart_console_wait_tx(port); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1128 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1129 | cdns_uart_writel(ctrl, CDNS_UART_CR_OFFSET); |
Lars-Peter Clausen | d3755f5 | 2013-10-17 14:08:09 -0700 | [diff] [blame] | 1130 | |
Soren Brinkmann | b494a5f | 2014-04-04 17:23:42 -0700 | [diff] [blame] | 1131 | /* restore interrupt state */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1132 | cdns_uart_writel(imr, CDNS_UART_IER_OFFSET); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1133 | |
| 1134 | if (locked) |
| 1135 | spin_unlock_irqrestore(&port->lock, flags); |
| 1136 | } |
| 1137 | |
| 1138 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1139 | * cdns_uart_console_setup - Initialize the uart to default config |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1140 | * @co: Console handle |
| 1141 | * @options: Initial settings of uart |
| 1142 | * |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 1143 | * Return: 0 on success, negative errno otherwise. |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1144 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1145 | static int __init cdns_uart_console_setup(struct console *co, char *options) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1146 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1147 | struct uart_port *port = &cdns_uart_port[co->index]; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1148 | int baud = 9600; |
| 1149 | int bits = 8; |
| 1150 | int parity = 'n'; |
| 1151 | int flow = 'n'; |
| 1152 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1153 | if (co->index < 0 || co->index >= CDNS_UART_NR_PORTS) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1154 | return -EINVAL; |
| 1155 | |
| 1156 | if (!port->mapbase) { |
Peter Crosthwaite | f641549 | 2015-02-24 15:13:57 -0800 | [diff] [blame^] | 1157 | pr_debug("console on " CDNS_UART_TTY_NAME "%i not present\n", |
| 1158 | co->index); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1159 | return -ENODEV; |
| 1160 | } |
| 1161 | |
| 1162 | if (options) |
| 1163 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 1164 | |
| 1165 | return uart_set_options(port, co, baud, parity, bits, flow); |
| 1166 | } |
| 1167 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1168 | static struct uart_driver cdns_uart_uart_driver; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1169 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1170 | static struct console cdns_uart_console = { |
| 1171 | .name = CDNS_UART_TTY_NAME, |
| 1172 | .write = cdns_uart_console_write, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1173 | .device = uart_console_device, |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1174 | .setup = cdns_uart_console_setup, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1175 | .flags = CON_PRINTBUFFER, |
| 1176 | .index = -1, /* Specified on the cmdline (e.g. console=ttyPS ) */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1177 | .data = &cdns_uart_uart_driver, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1178 | }; |
| 1179 | |
| 1180 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1181 | * cdns_uart_console_init - Initialization call |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1182 | * |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 1183 | * Return: 0 on success, negative errno otherwise |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1184 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1185 | static int __init cdns_uart_console_init(void) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1186 | { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1187 | register_console(&cdns_uart_console); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1188 | return 0; |
| 1189 | } |
| 1190 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1191 | console_initcall(cdns_uart_console_init); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1192 | |
| 1193 | #endif /* CONFIG_SERIAL_XILINX_PS_UART_CONSOLE */ |
| 1194 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1195 | static struct uart_driver cdns_uart_uart_driver = { |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 1196 | .owner = THIS_MODULE, |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1197 | .driver_name = CDNS_UART_NAME, |
| 1198 | .dev_name = CDNS_UART_TTY_NAME, |
| 1199 | .major = CDNS_UART_MAJOR, |
| 1200 | .minor = CDNS_UART_MINOR, |
| 1201 | .nr = CDNS_UART_NR_PORTS, |
Soren Brinkmann | d3641f6 | 2013-10-21 16:41:00 -0700 | [diff] [blame] | 1202 | #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1203 | .cons = &cdns_uart_console, |
Soren Brinkmann | d3641f6 | 2013-10-21 16:41:00 -0700 | [diff] [blame] | 1204 | #endif |
| 1205 | }; |
| 1206 | |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1207 | #ifdef CONFIG_PM_SLEEP |
| 1208 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1209 | * cdns_uart_suspend - suspend event |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1210 | * @device: Pointer to the device structure |
| 1211 | * |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1212 | * Return: 0 |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1213 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1214 | static int cdns_uart_suspend(struct device *device) |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1215 | { |
| 1216 | struct uart_port *port = dev_get_drvdata(device); |
| 1217 | struct tty_struct *tty; |
| 1218 | struct device *tty_dev; |
| 1219 | int may_wake = 0; |
| 1220 | |
| 1221 | /* Get the tty which could be NULL so don't assume it's valid */ |
| 1222 | tty = tty_port_tty_get(&port->state->port); |
| 1223 | if (tty) { |
| 1224 | tty_dev = tty->dev; |
| 1225 | may_wake = device_may_wakeup(tty_dev); |
| 1226 | tty_kref_put(tty); |
| 1227 | } |
| 1228 | |
| 1229 | /* |
| 1230 | * Call the API provided in serial_core.c file which handles |
| 1231 | * the suspend. |
| 1232 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1233 | uart_suspend_port(&cdns_uart_uart_driver, port); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1234 | if (console_suspend_enabled && !may_wake) { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1235 | struct cdns_uart *cdns_uart = port->private_data; |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1236 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1237 | clk_disable(cdns_uart->uartclk); |
| 1238 | clk_disable(cdns_uart->pclk); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1239 | } else { |
| 1240 | unsigned long flags = 0; |
| 1241 | |
| 1242 | spin_lock_irqsave(&port->lock, flags); |
| 1243 | /* Empty the receive FIFO 1st before making changes */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1244 | while (!(cdns_uart_readl(CDNS_UART_SR_OFFSET) & |
| 1245 | CDNS_UART_SR_RXEMPTY)) |
| 1246 | cdns_uart_readl(CDNS_UART_FIFO_OFFSET); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1247 | /* set RX trigger level to 1 */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1248 | cdns_uart_writel(1, CDNS_UART_RXWM_OFFSET); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1249 | /* disable RX timeout interrups */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1250 | cdns_uart_writel(CDNS_UART_IXR_TOUT, CDNS_UART_IDR_OFFSET); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1251 | spin_unlock_irqrestore(&port->lock, flags); |
| 1252 | } |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1258 | * cdns_uart_resume - Resume after a previous suspend |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1259 | * @device: Pointer to the device structure |
| 1260 | * |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1261 | * Return: 0 |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1262 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1263 | static int cdns_uart_resume(struct device *device) |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1264 | { |
| 1265 | struct uart_port *port = dev_get_drvdata(device); |
| 1266 | unsigned long flags = 0; |
| 1267 | u32 ctrl_reg; |
| 1268 | struct tty_struct *tty; |
| 1269 | struct device *tty_dev; |
| 1270 | int may_wake = 0; |
| 1271 | |
| 1272 | /* Get the tty which could be NULL so don't assume it's valid */ |
| 1273 | tty = tty_port_tty_get(&port->state->port); |
| 1274 | if (tty) { |
| 1275 | tty_dev = tty->dev; |
| 1276 | may_wake = device_may_wakeup(tty_dev); |
| 1277 | tty_kref_put(tty); |
| 1278 | } |
| 1279 | |
| 1280 | if (console_suspend_enabled && !may_wake) { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1281 | struct cdns_uart *cdns_uart = port->private_data; |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1282 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1283 | clk_enable(cdns_uart->pclk); |
| 1284 | clk_enable(cdns_uart->uartclk); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1285 | |
| 1286 | spin_lock_irqsave(&port->lock, flags); |
| 1287 | |
| 1288 | /* Set TX/RX Reset */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1289 | ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 1290 | ctrl_reg |= CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST; |
| 1291 | cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); |
| 1292 | while (cdns_uart_readl(CDNS_UART_CR_OFFSET) & |
| 1293 | (CDNS_UART_CR_TXRST | CDNS_UART_CR_RXRST)) |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1294 | cpu_relax(); |
| 1295 | |
| 1296 | /* restore rx timeout value */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1297 | cdns_uart_writel(rx_timeout, CDNS_UART_RXTOUT_OFFSET); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1298 | /* Enable Tx/Rx */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1299 | ctrl_reg = cdns_uart_readl(CDNS_UART_CR_OFFSET); |
| 1300 | ctrl_reg &= ~(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS); |
| 1301 | ctrl_reg |= CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN; |
| 1302 | cdns_uart_writel(ctrl_reg, CDNS_UART_CR_OFFSET); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1303 | |
| 1304 | spin_unlock_irqrestore(&port->lock, flags); |
| 1305 | } else { |
| 1306 | spin_lock_irqsave(&port->lock, flags); |
| 1307 | /* restore original rx trigger level */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1308 | cdns_uart_writel(rx_trigger_level, CDNS_UART_RXWM_OFFSET); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1309 | /* enable RX timeout interrupt */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1310 | cdns_uart_writel(CDNS_UART_IXR_TOUT, CDNS_UART_IER_OFFSET); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1311 | spin_unlock_irqrestore(&port->lock, flags); |
| 1312 | } |
| 1313 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1314 | return uart_resume_port(&cdns_uart_uart_driver, port); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1315 | } |
| 1316 | #endif /* ! CONFIG_PM_SLEEP */ |
| 1317 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1318 | static SIMPLE_DEV_PM_OPS(cdns_uart_dev_pm_ops, cdns_uart_suspend, |
| 1319 | cdns_uart_resume); |
Soren Brinkmann | 4b47d9a | 2013-10-17 14:08:12 -0700 | [diff] [blame] | 1320 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1321 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1322 | * cdns_uart_probe - Platform driver probe |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1323 | * @pdev: Pointer to the platform device structure |
| 1324 | * |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 1325 | * Return: 0 on success, negative errno otherwise |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1326 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1327 | static int cdns_uart_probe(struct platform_device *pdev) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1328 | { |
Michal Simek | 928e926 | 2014-04-04 17:23:38 -0700 | [diff] [blame] | 1329 | int rc, id; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1330 | struct uart_port *port; |
| 1331 | struct resource *res, *res2; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1332 | struct cdns_uart *cdns_uart_data; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1333 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1334 | cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data), |
Soren Brinkmann | c03cae1 | 2013-10-17 14:08:05 -0700 | [diff] [blame] | 1335 | GFP_KERNEL); |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1336 | if (!cdns_uart_data) |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1337 | return -ENOMEM; |
| 1338 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1339 | cdns_uart_data->pclk = devm_clk_get(&pdev->dev, "pclk"); |
| 1340 | if (IS_ERR(cdns_uart_data->pclk)) { |
| 1341 | cdns_uart_data->pclk = devm_clk_get(&pdev->dev, "aper_clk"); |
| 1342 | if (!IS_ERR(cdns_uart_data->pclk)) |
| 1343 | dev_err(&pdev->dev, "clock name 'aper_clk' is deprecated.\n"); |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1344 | } |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1345 | if (IS_ERR(cdns_uart_data->pclk)) { |
| 1346 | dev_err(&pdev->dev, "pclk clock not found.\n"); |
| 1347 | return PTR_ERR(cdns_uart_data->pclk); |
Josh Cartwright | 2326669c | 2013-01-21 19:57:41 +0100 | [diff] [blame] | 1348 | } |
| 1349 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1350 | cdns_uart_data->uartclk = devm_clk_get(&pdev->dev, "uart_clk"); |
| 1351 | if (IS_ERR(cdns_uart_data->uartclk)) { |
| 1352 | cdns_uart_data->uartclk = devm_clk_get(&pdev->dev, "ref_clk"); |
| 1353 | if (!IS_ERR(cdns_uart_data->uartclk)) |
| 1354 | dev_err(&pdev->dev, "clock name 'ref_clk' is deprecated.\n"); |
| 1355 | } |
| 1356 | if (IS_ERR(cdns_uart_data->uartclk)) { |
| 1357 | dev_err(&pdev->dev, "uart_clk clock not found.\n"); |
| 1358 | return PTR_ERR(cdns_uart_data->uartclk); |
| 1359 | } |
| 1360 | |
| 1361 | rc = clk_prepare_enable(cdns_uart_data->pclk); |
Josh Cartwright | 2326669c | 2013-01-21 19:57:41 +0100 | [diff] [blame] | 1362 | if (rc) { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1363 | dev_err(&pdev->dev, "Unable to enable pclk clock.\n"); |
Soren Brinkmann | c03cae1 | 2013-10-17 14:08:05 -0700 | [diff] [blame] | 1364 | return rc; |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1365 | } |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1366 | rc = clk_prepare_enable(cdns_uart_data->uartclk); |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1367 | if (rc) { |
| 1368 | dev_err(&pdev->dev, "Unable to enable device clock.\n"); |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1369 | goto err_out_clk_dis_pclk; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1373 | if (!res) { |
| 1374 | rc = -ENODEV; |
| 1375 | goto err_out_clk_disable; |
| 1376 | } |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1377 | |
| 1378 | res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1379 | if (!res2) { |
| 1380 | rc = -ENODEV; |
| 1381 | goto err_out_clk_disable; |
| 1382 | } |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1383 | |
Soren Brinkmann | 7ac5734 | 2013-10-21 16:41:01 -0700 | [diff] [blame] | 1384 | #ifdef CONFIG_COMMON_CLK |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1385 | cdns_uart_data->clk_rate_change_nb.notifier_call = |
| 1386 | cdns_uart_clk_notifier_cb; |
| 1387 | if (clk_notifier_register(cdns_uart_data->uartclk, |
| 1388 | &cdns_uart_data->clk_rate_change_nb)) |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 1389 | dev_warn(&pdev->dev, "Unable to register clock notifier.\n"); |
Soren Brinkmann | 7ac5734 | 2013-10-21 16:41:01 -0700 | [diff] [blame] | 1390 | #endif |
Michal Simek | 928e926 | 2014-04-04 17:23:38 -0700 | [diff] [blame] | 1391 | /* Look for a serialN alias */ |
| 1392 | id = of_alias_get_id(pdev->dev.of_node, "serial"); |
| 1393 | if (id < 0) |
| 1394 | id = 0; |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 1395 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1396 | /* Initialize the port structure */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1397 | port = cdns_uart_get_port(id); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1398 | |
| 1399 | if (!port) { |
| 1400 | dev_err(&pdev->dev, "Cannot get uart_port structure\n"); |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1401 | rc = -ENODEV; |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 1402 | goto err_out_notif_unreg; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1403 | } else { |
| 1404 | /* Register the port. |
| 1405 | * This function also registers this device with the tty layer |
| 1406 | * and triggers invocation of the config_port() entry point. |
| 1407 | */ |
| 1408 | port->mapbase = res->start; |
| 1409 | port->irq = res2->start; |
| 1410 | port->dev = &pdev->dev; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1411 | port->uartclk = clk_get_rate(cdns_uart_data->uartclk); |
| 1412 | port->private_data = cdns_uart_data; |
| 1413 | cdns_uart_data->port = port; |
Jingoo Han | 696faed | 2013-05-23 19:39:36 +0900 | [diff] [blame] | 1414 | platform_set_drvdata(pdev, port); |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1415 | rc = uart_add_one_port(&cdns_uart_uart_driver, port); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1416 | if (rc) { |
| 1417 | dev_err(&pdev->dev, |
| 1418 | "uart_add_one_port() failed; err=%i\n", rc); |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 1419 | goto err_out_notif_unreg; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1420 | } |
| 1421 | return 0; |
| 1422 | } |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1423 | |
Soren Brinkmann | c4b0510 | 2013-10-17 14:08:11 -0700 | [diff] [blame] | 1424 | err_out_notif_unreg: |
Soren Brinkmann | 7ac5734 | 2013-10-21 16:41:01 -0700 | [diff] [blame] | 1425 | #ifdef CONFIG_COMMON_CLK |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1426 | clk_notifier_unregister(cdns_uart_data->uartclk, |
| 1427 | &cdns_uart_data->clk_rate_change_nb); |
Soren Brinkmann | 7ac5734 | 2013-10-21 16:41:01 -0700 | [diff] [blame] | 1428 | #endif |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1429 | err_out_clk_disable: |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1430 | clk_disable_unprepare(cdns_uart_data->uartclk); |
| 1431 | err_out_clk_dis_pclk: |
| 1432 | clk_disable_unprepare(cdns_uart_data->pclk); |
Soren Brinkmann | 30e1e28 | 2013-05-13 10:46:38 -0700 | [diff] [blame] | 1433 | |
| 1434 | return rc; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | /** |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1438 | * cdns_uart_remove - called when the platform driver is unregistered |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1439 | * @pdev: Pointer to the platform device structure |
| 1440 | * |
Soren Brinkmann | e555a21 | 2014-04-04 17:23:39 -0700 | [diff] [blame] | 1441 | * Return: 0 on success, negative errno otherwise |
Michal Simek | 489810a1 | 2014-04-04 17:23:37 -0700 | [diff] [blame] | 1442 | */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1443 | static int cdns_uart_remove(struct platform_device *pdev) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1444 | { |
Jingoo Han | 696faed | 2013-05-23 19:39:36 +0900 | [diff] [blame] | 1445 | struct uart_port *port = platform_get_drvdata(pdev); |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1446 | struct cdns_uart *cdns_uart_data = port->private_data; |
Josh Cartwright | 2326669c | 2013-01-21 19:57:41 +0100 | [diff] [blame] | 1447 | int rc; |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1448 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1449 | /* Remove the cdns_uart port from the serial core */ |
Soren Brinkmann | 7ac5734 | 2013-10-21 16:41:01 -0700 | [diff] [blame] | 1450 | #ifdef CONFIG_COMMON_CLK |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1451 | clk_notifier_unregister(cdns_uart_data->uartclk, |
| 1452 | &cdns_uart_data->clk_rate_change_nb); |
Soren Brinkmann | 7ac5734 | 2013-10-21 16:41:01 -0700 | [diff] [blame] | 1453 | #endif |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1454 | rc = uart_remove_one_port(&cdns_uart_uart_driver, port); |
Josh Cartwright | 2326669c | 2013-01-21 19:57:41 +0100 | [diff] [blame] | 1455 | port->mapbase = 0; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1456 | clk_disable_unprepare(cdns_uart_data->uartclk); |
| 1457 | clk_disable_unprepare(cdns_uart_data->pclk); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1458 | return rc; |
| 1459 | } |
| 1460 | |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1461 | /* Match table for of_platform binding */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1462 | static struct of_device_id cdns_uart_of_match[] = { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1463 | { .compatible = "xlnx,xuartps", }, |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1464 | { .compatible = "cdns,uart-r1p8", }, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1465 | {} |
| 1466 | }; |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1467 | MODULE_DEVICE_TABLE(of, cdns_uart_of_match); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1468 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1469 | static struct platform_driver cdns_uart_platform_driver = { |
| 1470 | .probe = cdns_uart_probe, |
| 1471 | .remove = cdns_uart_remove, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1472 | .driver = { |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1473 | .name = CDNS_UART_NAME, |
| 1474 | .of_match_table = cdns_uart_of_match, |
| 1475 | .pm = &cdns_uart_dev_pm_ops, |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1476 | }, |
| 1477 | }; |
| 1478 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1479 | static int __init cdns_uart_init(void) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1480 | { |
| 1481 | int retval = 0; |
| 1482 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1483 | /* Register the cdns_uart driver with the serial core */ |
| 1484 | retval = uart_register_driver(&cdns_uart_uart_driver); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1485 | if (retval) |
| 1486 | return retval; |
| 1487 | |
| 1488 | /* Register the platform driver */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1489 | retval = platform_driver_register(&cdns_uart_platform_driver); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1490 | if (retval) |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1491 | uart_unregister_driver(&cdns_uart_uart_driver); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1492 | |
| 1493 | return retval; |
| 1494 | } |
| 1495 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1496 | static void __exit cdns_uart_exit(void) |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1497 | { |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1498 | /* Unregister the platform driver */ |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1499 | platform_driver_unregister(&cdns_uart_platform_driver); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1500 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1501 | /* Unregister the cdns_uart driver */ |
| 1502 | uart_unregister_driver(&cdns_uart_uart_driver); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1503 | } |
| 1504 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1505 | module_init(cdns_uart_init); |
| 1506 | module_exit(cdns_uart_exit); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1507 | |
Soren Brinkmann | d9bb3fb | 2014-04-04 17:23:43 -0700 | [diff] [blame] | 1508 | MODULE_DESCRIPTION("Driver for Cadence UART"); |
John Linn | 61ec901 | 2011-04-30 00:07:43 -0400 | [diff] [blame] | 1509 | MODULE_AUTHOR("Xilinx Inc."); |
| 1510 | MODULE_LICENSE("GPL"); |