Greg Kroah-Hartman | e3b3d0f | 2017-11-06 18:11:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jovi Zhang | 99edb3d | 2011-03-30 05:30:41 -0400 | [diff] [blame] | 2 | /* |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 3 | * Driver core for Samsung SoC onboard UARTs. |
| 4 | * |
Ben Dooks | ccae941 | 2009-11-13 22:54:14 +0000 | [diff] [blame] | 5 | * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 6 | * http://armlinux.simtec.co.uk/ |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* Hote on 2410 error handling |
| 10 | * |
| 11 | * The s3c2410 manual has a love/hate affair with the contents of the |
| 12 | * UERSTAT register in the UART blocks, and keeps marking some of the |
| 13 | * error bits as reserved. Having checked with the s3c2410x01, |
| 14 | * it copes with BREAKs properly, so I am happy to ignore the RESERVED |
| 15 | * feature from the latter versions of the manual. |
| 16 | * |
| 17 | * If it becomes aparrent that latter versions of the 2410 remove these |
| 18 | * bits, then action will have to be taken to differentiate the versions |
| 19 | * and change the policy on BREAK |
| 20 | * |
| 21 | * BJD, 04-Nov-2004 |
| 22 | */ |
| 23 | |
| 24 | #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) |
| 25 | #define SUPPORT_SYSRQ |
| 26 | #endif |
| 27 | |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 28 | #include <linux/dmaengine.h> |
| 29 | #include <linux/dma-mapping.h> |
| 30 | #include <linux/slab.h> |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/ioport.h> |
| 33 | #include <linux/io.h> |
| 34 | #include <linux/platform_device.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/sysrq.h> |
| 37 | #include <linux/console.h> |
| 38 | #include <linux/tty.h> |
| 39 | #include <linux/tty_flip.h> |
| 40 | #include <linux/serial_core.h> |
| 41 | #include <linux/serial.h> |
Arnd Bergmann | 9ee51f0 | 2013-04-11 02:04:48 +0200 | [diff] [blame] | 42 | #include <linux/serial_s3c.h> |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 43 | #include <linux/delay.h> |
| 44 | #include <linux/clk.h> |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 45 | #include <linux/cpufreq.h> |
Thomas Abraham | 26c919e | 2011-11-06 22:10:44 +0530 | [diff] [blame] | 46 | #include <linux/of.h> |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 47 | #include <asm/irq.h> |
| 48 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 49 | /* UART name and device definitions */ |
| 50 | |
| 51 | #define S3C24XX_SERIAL_NAME "ttySAC" |
| 52 | #define S3C24XX_SERIAL_MAJOR 204 |
| 53 | #define S3C24XX_SERIAL_MINOR 64 |
| 54 | |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 55 | #define S3C24XX_TX_PIO 1 |
| 56 | #define S3C24XX_TX_DMA 2 |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 57 | #define S3C24XX_RX_PIO 1 |
| 58 | #define S3C24XX_RX_DMA 2 |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 59 | /* macros to change one thing to another */ |
| 60 | |
| 61 | #define tx_enabled(port) ((port)->unused[0]) |
| 62 | #define rx_enabled(port) ((port)->unused[1]) |
| 63 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 64 | /* flag to ignore all characters coming in */ |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 65 | #define RXSTAT_DUMMY_READ (0x10000000) |
| 66 | |
Greg Kroah-Hartman | 43df170 | 2019-12-10 15:37:01 +0100 | [diff] [blame] | 67 | struct s3c24xx_uart_info { |
| 68 | char *name; |
| 69 | unsigned int type; |
| 70 | unsigned int fifosize; |
| 71 | unsigned long rx_fifomask; |
| 72 | unsigned long rx_fifoshift; |
| 73 | unsigned long rx_fifofull; |
| 74 | unsigned long tx_fifomask; |
| 75 | unsigned long tx_fifoshift; |
| 76 | unsigned long tx_fifofull; |
| 77 | unsigned int def_clk_sel; |
| 78 | unsigned long num_clks; |
| 79 | unsigned long clksel_mask; |
| 80 | unsigned long clksel_shift; |
| 81 | |
| 82 | /* uart port features */ |
| 83 | |
| 84 | unsigned int has_divslot:1; |
| 85 | }; |
| 86 | |
| 87 | struct s3c24xx_serial_drv_data { |
| 88 | struct s3c24xx_uart_info *info; |
| 89 | struct s3c2410_uartcfg *def_cfg; |
| 90 | unsigned int fifosize[CONFIG_SERIAL_SAMSUNG_UARTS]; |
| 91 | }; |
| 92 | |
| 93 | struct s3c24xx_uart_dma { |
| 94 | unsigned int rx_chan_id; |
| 95 | unsigned int tx_chan_id; |
| 96 | |
| 97 | struct dma_slave_config rx_conf; |
| 98 | struct dma_slave_config tx_conf; |
| 99 | |
| 100 | struct dma_chan *rx_chan; |
| 101 | struct dma_chan *tx_chan; |
| 102 | |
| 103 | dma_addr_t rx_addr; |
| 104 | dma_addr_t tx_addr; |
| 105 | |
| 106 | dma_cookie_t rx_cookie; |
| 107 | dma_cookie_t tx_cookie; |
| 108 | |
| 109 | char *rx_buf; |
| 110 | |
| 111 | dma_addr_t tx_transfer_addr; |
| 112 | |
| 113 | size_t rx_size; |
| 114 | size_t tx_size; |
| 115 | |
| 116 | struct dma_async_tx_descriptor *tx_desc; |
| 117 | struct dma_async_tx_descriptor *rx_desc; |
| 118 | |
| 119 | int tx_bytes_requested; |
| 120 | int rx_bytes_requested; |
| 121 | }; |
| 122 | |
| 123 | struct s3c24xx_uart_port { |
| 124 | unsigned char rx_claimed; |
| 125 | unsigned char tx_claimed; |
| 126 | unsigned int pm_level; |
| 127 | unsigned long baudclk_rate; |
| 128 | unsigned int min_dma_size; |
| 129 | |
| 130 | unsigned int rx_irq; |
| 131 | unsigned int tx_irq; |
| 132 | |
| 133 | unsigned int tx_in_progress; |
| 134 | unsigned int tx_mode; |
| 135 | unsigned int rx_mode; |
| 136 | |
| 137 | struct s3c24xx_uart_info *info; |
| 138 | struct clk *clk; |
| 139 | struct clk *baudclk; |
| 140 | struct uart_port port; |
| 141 | struct s3c24xx_serial_drv_data *drv_data; |
| 142 | |
| 143 | /* reference to platform data */ |
| 144 | struct s3c2410_uartcfg *cfg; |
| 145 | |
| 146 | struct s3c24xx_uart_dma *dma; |
| 147 | |
| 148 | #ifdef CONFIG_ARM_S3C24XX_CPUFREQ |
| 149 | struct notifier_block freq_transition; |
| 150 | #endif |
| 151 | }; |
| 152 | |
| 153 | /* conversion functions */ |
| 154 | |
| 155 | #define s3c24xx_dev_to_port(__dev) dev_get_drvdata(__dev) |
| 156 | |
| 157 | /* register access controls */ |
| 158 | |
| 159 | #define portaddr(port, reg) ((port)->membase + (reg)) |
| 160 | #define portaddrl(port, reg) \ |
| 161 | ((unsigned long *)(unsigned long)((port)->membase + (reg))) |
| 162 | |
| 163 | #define rd_regb(port, reg) (readb_relaxed(portaddr(port, reg))) |
| 164 | #define rd_regl(port, reg) (readl_relaxed(portaddr(port, reg))) |
| 165 | |
| 166 | #define wr_regb(port, reg, val) writeb_relaxed(val, portaddr(port, reg)) |
| 167 | #define wr_regl(port, reg, val) writel_relaxed(val, portaddr(port, reg)) |
| 168 | |
| 169 | /* Byte-order aware bit setting/clearing functions. */ |
| 170 | |
| 171 | static inline void s3c24xx_set_bit(struct uart_port *port, int idx, |
| 172 | unsigned int reg) |
| 173 | { |
| 174 | unsigned long flags; |
| 175 | u32 val; |
| 176 | |
| 177 | local_irq_save(flags); |
| 178 | val = rd_regl(port, reg); |
| 179 | val |= (1 << idx); |
| 180 | wr_regl(port, reg, val); |
| 181 | local_irq_restore(flags); |
| 182 | } |
| 183 | |
| 184 | static inline void s3c24xx_clear_bit(struct uart_port *port, int idx, |
| 185 | unsigned int reg) |
| 186 | { |
| 187 | unsigned long flags; |
| 188 | u32 val; |
| 189 | |
| 190 | local_irq_save(flags); |
| 191 | val = rd_regl(port, reg); |
| 192 | val &= ~(1 << idx); |
| 193 | wr_regl(port, reg, val); |
| 194 | local_irq_restore(flags); |
| 195 | } |
| 196 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 197 | static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port) |
| 198 | { |
| 199 | return container_of(port, struct s3c24xx_uart_port, port); |
| 200 | } |
| 201 | |
| 202 | /* translate a port to the device name */ |
| 203 | |
| 204 | static inline const char *s3c24xx_serial_portname(struct uart_port *port) |
| 205 | { |
| 206 | return to_platform_device(port->dev)->name; |
| 207 | } |
| 208 | |
| 209 | static int s3c24xx_serial_txempty_nofifo(struct uart_port *port) |
| 210 | { |
Sachin Kamat | 9303ac1 | 2012-09-05 10:30:11 +0530 | [diff] [blame] | 211 | return rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 212 | } |
| 213 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 214 | /* |
| 215 | * s3c64xx and later SoC's include the interrupt mask and status registers in |
| 216 | * the controller itself, unlike the s3c24xx SoC's which have these registers |
| 217 | * in the interrupt controller. Check if the port type is s3c64xx or higher. |
| 218 | */ |
| 219 | static int s3c24xx_serial_has_interrupt_mask(struct uart_port *port) |
| 220 | { |
| 221 | return to_ourport(port)->info->type == PORT_S3C6400; |
| 222 | } |
| 223 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 224 | static void s3c24xx_serial_rx_enable(struct uart_port *port) |
| 225 | { |
| 226 | unsigned long flags; |
| 227 | unsigned int ucon, ufcon; |
| 228 | int count = 10000; |
| 229 | |
| 230 | spin_lock_irqsave(&port->lock, flags); |
| 231 | |
| 232 | while (--count && !s3c24xx_serial_txempty_nofifo(port)) |
| 233 | udelay(100); |
| 234 | |
| 235 | ufcon = rd_regl(port, S3C2410_UFCON); |
| 236 | ufcon |= S3C2410_UFCON_RESETRX; |
| 237 | wr_regl(port, S3C2410_UFCON, ufcon); |
| 238 | |
| 239 | ucon = rd_regl(port, S3C2410_UCON); |
| 240 | ucon |= S3C2410_UCON_RXIRQMODE; |
| 241 | wr_regl(port, S3C2410_UCON, ucon); |
| 242 | |
| 243 | rx_enabled(port) = 1; |
| 244 | spin_unlock_irqrestore(&port->lock, flags); |
| 245 | } |
| 246 | |
| 247 | static void s3c24xx_serial_rx_disable(struct uart_port *port) |
| 248 | { |
| 249 | unsigned long flags; |
| 250 | unsigned int ucon; |
| 251 | |
| 252 | spin_lock_irqsave(&port->lock, flags); |
| 253 | |
| 254 | ucon = rd_regl(port, S3C2410_UCON); |
| 255 | ucon &= ~S3C2410_UCON_RXIRQMODE; |
| 256 | wr_regl(port, S3C2410_UCON, ucon); |
| 257 | |
| 258 | rx_enabled(port) = 0; |
| 259 | spin_unlock_irqrestore(&port->lock, flags); |
| 260 | } |
| 261 | |
| 262 | static void s3c24xx_serial_stop_tx(struct uart_port *port) |
| 263 | { |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 264 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 265 | struct s3c24xx_uart_dma *dma = ourport->dma; |
| 266 | struct circ_buf *xmit = &port->state->xmit; |
| 267 | struct dma_tx_state state; |
| 268 | int count; |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 269 | |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 270 | if (!tx_enabled(port)) |
| 271 | return; |
| 272 | |
| 273 | if (s3c24xx_serial_has_interrupt_mask(port)) |
Matthew Leach | bbb5ff9 | 2016-06-22 17:57:03 +0100 | [diff] [blame] | 274 | s3c24xx_set_bit(port, S3C64XX_UINTM_TXD, S3C64XX_UINTM); |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 275 | else |
| 276 | disable_irq_nosync(ourport->tx_irq); |
| 277 | |
| 278 | if (dma && dma->tx_chan && ourport->tx_in_progress == S3C24XX_TX_DMA) { |
| 279 | dmaengine_pause(dma->tx_chan); |
| 280 | dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state); |
| 281 | dmaengine_terminate_all(dma->tx_chan); |
| 282 | dma_sync_single_for_cpu(ourport->port.dev, |
| 283 | dma->tx_transfer_addr, dma->tx_size, DMA_TO_DEVICE); |
| 284 | async_tx_ack(dma->tx_desc); |
| 285 | count = dma->tx_bytes_requested - state.residue; |
| 286 | xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); |
| 287 | port->icount.tx += count; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 288 | } |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 289 | |
| 290 | tx_enabled(port) = 0; |
| 291 | ourport->tx_in_progress = 0; |
| 292 | |
| 293 | if (port->flags & UPF_CONS_FLOW) |
| 294 | s3c24xx_serial_rx_enable(port); |
| 295 | |
| 296 | ourport->tx_mode = 0; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 299 | static void s3c24xx_serial_start_next_tx(struct s3c24xx_uart_port *ourport); |
| 300 | |
| 301 | static void s3c24xx_serial_tx_dma_complete(void *args) |
| 302 | { |
| 303 | struct s3c24xx_uart_port *ourport = args; |
| 304 | struct uart_port *port = &ourport->port; |
| 305 | struct circ_buf *xmit = &port->state->xmit; |
| 306 | struct s3c24xx_uart_dma *dma = ourport->dma; |
| 307 | struct dma_tx_state state; |
| 308 | unsigned long flags; |
| 309 | int count; |
| 310 | |
| 311 | |
| 312 | dmaengine_tx_status(dma->tx_chan, dma->tx_cookie, &state); |
| 313 | count = dma->tx_bytes_requested - state.residue; |
| 314 | async_tx_ack(dma->tx_desc); |
| 315 | |
| 316 | dma_sync_single_for_cpu(ourport->port.dev, dma->tx_transfer_addr, |
| 317 | dma->tx_size, DMA_TO_DEVICE); |
| 318 | |
| 319 | spin_lock_irqsave(&port->lock, flags); |
| 320 | |
| 321 | xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1); |
| 322 | port->icount.tx += count; |
| 323 | ourport->tx_in_progress = 0; |
| 324 | |
| 325 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) |
| 326 | uart_write_wakeup(port); |
| 327 | |
| 328 | s3c24xx_serial_start_next_tx(ourport); |
| 329 | spin_unlock_irqrestore(&port->lock, flags); |
| 330 | } |
| 331 | |
| 332 | static void enable_tx_dma(struct s3c24xx_uart_port *ourport) |
| 333 | { |
| 334 | struct uart_port *port = &ourport->port; |
| 335 | u32 ucon; |
| 336 | |
| 337 | /* Mask Tx interrupt */ |
| 338 | if (s3c24xx_serial_has_interrupt_mask(port)) |
Matthew Leach | bbb5ff9 | 2016-06-22 17:57:03 +0100 | [diff] [blame] | 339 | s3c24xx_set_bit(port, S3C64XX_UINTM_TXD, S3C64XX_UINTM); |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 340 | else |
| 341 | disable_irq_nosync(ourport->tx_irq); |
| 342 | |
| 343 | /* Enable tx dma mode */ |
| 344 | ucon = rd_regl(port, S3C2410_UCON); |
| 345 | ucon &= ~(S3C64XX_UCON_TXBURST_MASK | S3C64XX_UCON_TXMODE_MASK); |
| 346 | ucon |= (dma_get_cache_alignment() >= 16) ? |
| 347 | S3C64XX_UCON_TXBURST_16 : S3C64XX_UCON_TXBURST_1; |
| 348 | ucon |= S3C64XX_UCON_TXMODE_DMA; |
| 349 | wr_regl(port, S3C2410_UCON, ucon); |
| 350 | |
| 351 | ourport->tx_mode = S3C24XX_TX_DMA; |
| 352 | } |
| 353 | |
| 354 | static void enable_tx_pio(struct s3c24xx_uart_port *ourport) |
| 355 | { |
| 356 | struct uart_port *port = &ourport->port; |
| 357 | u32 ucon, ufcon; |
| 358 | |
| 359 | /* Set ufcon txtrig */ |
| 360 | ourport->tx_in_progress = S3C24XX_TX_PIO; |
| 361 | ufcon = rd_regl(port, S3C2410_UFCON); |
| 362 | wr_regl(port, S3C2410_UFCON, ufcon); |
| 363 | |
| 364 | /* Enable tx pio mode */ |
| 365 | ucon = rd_regl(port, S3C2410_UCON); |
| 366 | ucon &= ~(S3C64XX_UCON_TXMODE_MASK); |
| 367 | ucon |= S3C64XX_UCON_TXMODE_CPU; |
| 368 | wr_regl(port, S3C2410_UCON, ucon); |
| 369 | |
| 370 | /* Unmask Tx interrupt */ |
| 371 | if (s3c24xx_serial_has_interrupt_mask(port)) |
Matthew Leach | bbb5ff9 | 2016-06-22 17:57:03 +0100 | [diff] [blame] | 372 | s3c24xx_clear_bit(port, S3C64XX_UINTM_TXD, |
| 373 | S3C64XX_UINTM); |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 374 | else |
| 375 | enable_irq(ourport->tx_irq); |
| 376 | |
| 377 | ourport->tx_mode = S3C24XX_TX_PIO; |
| 378 | } |
| 379 | |
| 380 | static void s3c24xx_serial_start_tx_pio(struct s3c24xx_uart_port *ourport) |
| 381 | { |
| 382 | if (ourport->tx_mode != S3C24XX_TX_PIO) |
| 383 | enable_tx_pio(ourport); |
| 384 | } |
| 385 | |
| 386 | static int s3c24xx_serial_start_tx_dma(struct s3c24xx_uart_port *ourport, |
| 387 | unsigned int count) |
| 388 | { |
| 389 | struct uart_port *port = &ourport->port; |
| 390 | struct circ_buf *xmit = &port->state->xmit; |
| 391 | struct s3c24xx_uart_dma *dma = ourport->dma; |
| 392 | |
| 393 | |
| 394 | if (ourport->tx_mode != S3C24XX_TX_DMA) |
| 395 | enable_tx_dma(ourport); |
| 396 | |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 397 | dma->tx_size = count & ~(dma_get_cache_alignment() - 1); |
| 398 | dma->tx_transfer_addr = dma->tx_addr + xmit->tail; |
| 399 | |
| 400 | dma_sync_single_for_device(ourport->port.dev, dma->tx_transfer_addr, |
| 401 | dma->tx_size, DMA_TO_DEVICE); |
| 402 | |
| 403 | dma->tx_desc = dmaengine_prep_slave_single(dma->tx_chan, |
| 404 | dma->tx_transfer_addr, dma->tx_size, |
| 405 | DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT); |
| 406 | if (!dma->tx_desc) { |
| 407 | dev_err(ourport->port.dev, "Unable to get desc for Tx\n"); |
| 408 | return -EIO; |
| 409 | } |
| 410 | |
| 411 | dma->tx_desc->callback = s3c24xx_serial_tx_dma_complete; |
| 412 | dma->tx_desc->callback_param = ourport; |
| 413 | dma->tx_bytes_requested = dma->tx_size; |
| 414 | |
| 415 | ourport->tx_in_progress = S3C24XX_TX_DMA; |
| 416 | dma->tx_cookie = dmaengine_submit(dma->tx_desc); |
| 417 | dma_async_issue_pending(dma->tx_chan); |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static void s3c24xx_serial_start_next_tx(struct s3c24xx_uart_port *ourport) |
| 422 | { |
| 423 | struct uart_port *port = &ourport->port; |
| 424 | struct circ_buf *xmit = &port->state->xmit; |
| 425 | unsigned long count; |
| 426 | |
| 427 | /* Get data size up to the end of buffer */ |
| 428 | count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); |
| 429 | |
| 430 | if (!count) { |
| 431 | s3c24xx_serial_stop_tx(port); |
| 432 | return; |
| 433 | } |
| 434 | |
Marek Szyprowski | 81ccb2a | 2015-07-31 10:58:27 +0200 | [diff] [blame] | 435 | if (!ourport->dma || !ourport->dma->tx_chan || |
Robert Baldyga | 736cd79 | 2015-07-31 10:58:28 +0200 | [diff] [blame] | 436 | count < ourport->min_dma_size || |
| 437 | xmit->tail & (dma_get_cache_alignment() - 1)) |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 438 | s3c24xx_serial_start_tx_pio(ourport); |
| 439 | else |
| 440 | s3c24xx_serial_start_tx_dma(ourport, count); |
| 441 | } |
| 442 | |
Krzysztof Kozlowski | 7578197 | 2015-05-02 00:40:04 +0900 | [diff] [blame] | 443 | static void s3c24xx_serial_start_tx(struct uart_port *port) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 444 | { |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 445 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 446 | struct circ_buf *xmit = &port->state->xmit; |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 447 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 448 | if (!tx_enabled(port)) { |
| 449 | if (port->flags & UPF_CONS_FLOW) |
| 450 | s3c24xx_serial_rx_disable(port); |
| 451 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 452 | tx_enabled(port) = 1; |
Robert Baldyga | ba019a3 | 2015-01-28 14:44:23 +0100 | [diff] [blame] | 453 | if (!ourport->dma || !ourport->dma->tx_chan) |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 454 | s3c24xx_serial_start_tx_pio(ourport); |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | if (ourport->dma && ourport->dma->tx_chan) { |
| 458 | if (!uart_circ_empty(xmit) && !ourport->tx_in_progress) |
| 459 | s3c24xx_serial_start_next_tx(ourport); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 463 | static void s3c24xx_uart_copy_rx_to_tty(struct s3c24xx_uart_port *ourport, |
| 464 | struct tty_port *tty, int count) |
| 465 | { |
| 466 | struct s3c24xx_uart_dma *dma = ourport->dma; |
| 467 | int copied; |
| 468 | |
| 469 | if (!count) |
| 470 | return; |
| 471 | |
| 472 | dma_sync_single_for_cpu(ourport->port.dev, dma->rx_addr, |
| 473 | dma->rx_size, DMA_FROM_DEVICE); |
| 474 | |
| 475 | ourport->port.icount.rx += count; |
| 476 | if (!tty) { |
| 477 | dev_err(ourport->port.dev, "No tty port\n"); |
| 478 | return; |
| 479 | } |
| 480 | copied = tty_insert_flip_string(tty, |
| 481 | ((unsigned char *)(ourport->dma->rx_buf)), count); |
| 482 | if (copied != count) { |
| 483 | WARN_ON(1); |
| 484 | dev_err(ourport->port.dev, "RxData copy to tty layer failed\n"); |
| 485 | } |
| 486 | } |
| 487 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 488 | static void s3c24xx_serial_stop_rx(struct uart_port *port) |
| 489 | { |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 490 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 491 | struct s3c24xx_uart_dma *dma = ourport->dma; |
| 492 | struct tty_port *t = &port->state->port; |
| 493 | struct dma_tx_state state; |
| 494 | enum dma_status dma_status; |
| 495 | unsigned int received; |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 496 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 497 | if (rx_enabled(port)) { |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 498 | dev_dbg(port->dev, "stopping rx\n"); |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 499 | if (s3c24xx_serial_has_interrupt_mask(port)) |
Matthew Leach | bbb5ff9 | 2016-06-22 17:57:03 +0100 | [diff] [blame] | 500 | s3c24xx_set_bit(port, S3C64XX_UINTM_RXD, |
| 501 | S3C64XX_UINTM); |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 502 | else |
| 503 | disable_irq_nosync(ourport->rx_irq); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 504 | rx_enabled(port) = 0; |
| 505 | } |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 506 | if (dma && dma->rx_chan) { |
| 507 | dmaengine_pause(dma->tx_chan); |
| 508 | dma_status = dmaengine_tx_status(dma->rx_chan, |
| 509 | dma->rx_cookie, &state); |
| 510 | if (dma_status == DMA_IN_PROGRESS || |
| 511 | dma_status == DMA_PAUSED) { |
| 512 | received = dma->rx_bytes_requested - state.residue; |
| 513 | dmaengine_terminate_all(dma->rx_chan); |
| 514 | s3c24xx_uart_copy_rx_to_tty(ourport, t, received); |
| 515 | } |
| 516 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 517 | } |
| 518 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 519 | static inline struct s3c24xx_uart_info |
| 520 | *s3c24xx_port_to_info(struct uart_port *port) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 521 | { |
| 522 | return to_ourport(port)->info; |
| 523 | } |
| 524 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 525 | static inline struct s3c2410_uartcfg |
| 526 | *s3c24xx_port_to_cfg(struct uart_port *port) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 527 | { |
Thomas Abraham | 4d84e97 | 2011-10-24 11:47:25 +0200 | [diff] [blame] | 528 | struct s3c24xx_uart_port *ourport; |
| 529 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 530 | if (port->dev == NULL) |
| 531 | return NULL; |
| 532 | |
Thomas Abraham | 4d84e97 | 2011-10-24 11:47:25 +0200 | [diff] [blame] | 533 | ourport = container_of(port, struct s3c24xx_uart_port, port); |
| 534 | return ourport->cfg; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport, |
| 538 | unsigned long ufstat) |
| 539 | { |
| 540 | struct s3c24xx_uart_info *info = ourport->info; |
| 541 | |
| 542 | if (ufstat & info->rx_fifofull) |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 543 | return ourport->port.fifosize; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 544 | |
| 545 | return (ufstat & info->rx_fifomask) >> info->rx_fifoshift; |
| 546 | } |
| 547 | |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 548 | static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport); |
| 549 | static void s3c24xx_serial_rx_dma_complete(void *args) |
| 550 | { |
| 551 | struct s3c24xx_uart_port *ourport = args; |
| 552 | struct uart_port *port = &ourport->port; |
| 553 | |
| 554 | struct s3c24xx_uart_dma *dma = ourport->dma; |
| 555 | struct tty_port *t = &port->state->port; |
| 556 | struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port); |
| 557 | |
| 558 | struct dma_tx_state state; |
| 559 | unsigned long flags; |
| 560 | int received; |
| 561 | |
| 562 | dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state); |
| 563 | received = dma->rx_bytes_requested - state.residue; |
| 564 | async_tx_ack(dma->rx_desc); |
| 565 | |
| 566 | spin_lock_irqsave(&port->lock, flags); |
| 567 | |
| 568 | if (received) |
| 569 | s3c24xx_uart_copy_rx_to_tty(ourport, t, received); |
| 570 | |
| 571 | if (tty) { |
| 572 | tty_flip_buffer_push(t); |
| 573 | tty_kref_put(tty); |
| 574 | } |
| 575 | |
| 576 | s3c64xx_start_rx_dma(ourport); |
| 577 | |
| 578 | spin_unlock_irqrestore(&port->lock, flags); |
| 579 | } |
| 580 | |
| 581 | static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport) |
| 582 | { |
| 583 | struct s3c24xx_uart_dma *dma = ourport->dma; |
| 584 | |
| 585 | dma_sync_single_for_device(ourport->port.dev, dma->rx_addr, |
| 586 | dma->rx_size, DMA_FROM_DEVICE); |
| 587 | |
| 588 | dma->rx_desc = dmaengine_prep_slave_single(dma->rx_chan, |
| 589 | dma->rx_addr, dma->rx_size, DMA_DEV_TO_MEM, |
| 590 | DMA_PREP_INTERRUPT); |
| 591 | if (!dma->rx_desc) { |
| 592 | dev_err(ourport->port.dev, "Unable to get desc for Rx\n"); |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | dma->rx_desc->callback = s3c24xx_serial_rx_dma_complete; |
| 597 | dma->rx_desc->callback_param = ourport; |
| 598 | dma->rx_bytes_requested = dma->rx_size; |
| 599 | |
| 600 | dma->rx_cookie = dmaengine_submit(dma->rx_desc); |
| 601 | dma_async_issue_pending(dma->rx_chan); |
| 602 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 603 | |
| 604 | /* ? - where has parity gone?? */ |
| 605 | #define S3C2410_UERSTAT_PARITY (0x1000) |
| 606 | |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 607 | static void enable_rx_dma(struct s3c24xx_uart_port *ourport) |
| 608 | { |
| 609 | struct uart_port *port = &ourport->port; |
| 610 | unsigned int ucon; |
| 611 | |
| 612 | /* set Rx mode to DMA mode */ |
| 613 | ucon = rd_regl(port, S3C2410_UCON); |
| 614 | ucon &= ~(S3C64XX_UCON_RXBURST_MASK | |
| 615 | S3C64XX_UCON_TIMEOUT_MASK | |
| 616 | S3C64XX_UCON_EMPTYINT_EN | |
| 617 | S3C64XX_UCON_DMASUS_EN | |
| 618 | S3C64XX_UCON_TIMEOUT_EN | |
| 619 | S3C64XX_UCON_RXMODE_MASK); |
| 620 | ucon |= S3C64XX_UCON_RXBURST_16 | |
| 621 | 0xf << S3C64XX_UCON_TIMEOUT_SHIFT | |
| 622 | S3C64XX_UCON_EMPTYINT_EN | |
| 623 | S3C64XX_UCON_TIMEOUT_EN | |
| 624 | S3C64XX_UCON_RXMODE_DMA; |
| 625 | wr_regl(port, S3C2410_UCON, ucon); |
| 626 | |
| 627 | ourport->rx_mode = S3C24XX_RX_DMA; |
| 628 | } |
| 629 | |
| 630 | static void enable_rx_pio(struct s3c24xx_uart_port *ourport) |
| 631 | { |
| 632 | struct uart_port *port = &ourport->port; |
| 633 | unsigned int ucon; |
| 634 | |
| 635 | /* set Rx mode to DMA mode */ |
| 636 | ucon = rd_regl(port, S3C2410_UCON); |
| 637 | ucon &= ~(S3C64XX_UCON_TIMEOUT_MASK | |
| 638 | S3C64XX_UCON_EMPTYINT_EN | |
| 639 | S3C64XX_UCON_DMASUS_EN | |
| 640 | S3C64XX_UCON_TIMEOUT_EN | |
| 641 | S3C64XX_UCON_RXMODE_MASK); |
| 642 | ucon |= 0xf << S3C64XX_UCON_TIMEOUT_SHIFT | |
| 643 | S3C64XX_UCON_TIMEOUT_EN | |
| 644 | S3C64XX_UCON_RXMODE_CPU; |
| 645 | wr_regl(port, S3C2410_UCON, ucon); |
| 646 | |
| 647 | ourport->rx_mode = S3C24XX_RX_PIO; |
| 648 | } |
| 649 | |
Robert Baldyga | 09557c0 | 2015-09-15 14:49:00 +0200 | [diff] [blame] | 650 | static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport); |
| 651 | |
Robert Baldyga | e4678af | 2015-09-15 14:48:57 +0200 | [diff] [blame] | 652 | static irqreturn_t s3c24xx_serial_rx_chars_dma(void *dev_id) |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 653 | { |
Chen Wandun | 98aee0c | 2019-11-22 20:04:18 +0800 | [diff] [blame] | 654 | unsigned int utrstat, received; |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 655 | struct s3c24xx_uart_port *ourport = dev_id; |
| 656 | struct uart_port *port = &ourport->port; |
| 657 | struct s3c24xx_uart_dma *dma = ourport->dma; |
| 658 | struct tty_struct *tty = tty_port_tty_get(&ourport->port.state->port); |
| 659 | struct tty_port *t = &port->state->port; |
| 660 | unsigned long flags; |
| 661 | struct dma_tx_state state; |
| 662 | |
| 663 | utrstat = rd_regl(port, S3C2410_UTRSTAT); |
Chen Wandun | 98aee0c | 2019-11-22 20:04:18 +0800 | [diff] [blame] | 664 | rd_regl(port, S3C2410_UFSTAT); |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 665 | |
| 666 | spin_lock_irqsave(&port->lock, flags); |
| 667 | |
| 668 | if (!(utrstat & S3C2410_UTRSTAT_TIMEOUT)) { |
| 669 | s3c64xx_start_rx_dma(ourport); |
| 670 | if (ourport->rx_mode == S3C24XX_RX_PIO) |
| 671 | enable_rx_dma(ourport); |
| 672 | goto finish; |
| 673 | } |
| 674 | |
| 675 | if (ourport->rx_mode == S3C24XX_RX_DMA) { |
| 676 | dmaengine_pause(dma->rx_chan); |
| 677 | dmaengine_tx_status(dma->rx_chan, dma->rx_cookie, &state); |
| 678 | dmaengine_terminate_all(dma->rx_chan); |
| 679 | received = dma->rx_bytes_requested - state.residue; |
| 680 | s3c24xx_uart_copy_rx_to_tty(ourport, t, received); |
| 681 | |
| 682 | enable_rx_pio(ourport); |
| 683 | } |
| 684 | |
Robert Baldyga | 09557c0 | 2015-09-15 14:49:00 +0200 | [diff] [blame] | 685 | s3c24xx_serial_rx_drain_fifo(ourport); |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 686 | |
| 687 | if (tty) { |
| 688 | tty_flip_buffer_push(t); |
| 689 | tty_kref_put(tty); |
| 690 | } |
| 691 | |
| 692 | wr_regl(port, S3C2410_UTRSTAT, S3C2410_UTRSTAT_TIMEOUT); |
| 693 | |
| 694 | finish: |
| 695 | spin_unlock_irqrestore(&port->lock, flags); |
| 696 | |
| 697 | return IRQ_HANDLED; |
| 698 | } |
| 699 | |
Robert Baldyga | 01732dd | 2015-09-15 14:48:59 +0200 | [diff] [blame] | 700 | static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 701 | { |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 702 | struct uart_port *port = &ourport->port; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 703 | unsigned int ufcon, ch, flag, ufstat, uerstat; |
Youngmin Nam | aba06e9 | 2016-03-05 19:36:32 +0900 | [diff] [blame] | 704 | unsigned int fifocnt = 0; |
Robert Baldyga | 57850a5 | 2014-11-24 07:56:24 +0100 | [diff] [blame] | 705 | int max_count = port->fifosize; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 706 | |
| 707 | while (max_count-- > 0) { |
Youngmin Nam | aba06e9 | 2016-03-05 19:36:32 +0900 | [diff] [blame] | 708 | /* |
| 709 | * Receive all characters known to be in FIFO |
| 710 | * before reading FIFO level again |
| 711 | */ |
| 712 | if (fifocnt == 0) { |
| 713 | ufstat = rd_regl(port, S3C2410_UFSTAT); |
| 714 | fifocnt = s3c24xx_serial_rx_fifocnt(ourport, ufstat); |
| 715 | if (fifocnt == 0) |
| 716 | break; |
| 717 | } |
| 718 | fifocnt--; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 719 | |
| 720 | uerstat = rd_regl(port, S3C2410_UERSTAT); |
| 721 | ch = rd_regb(port, S3C2410_URXH); |
| 722 | |
| 723 | if (port->flags & UPF_CONS_FLOW) { |
| 724 | int txe = s3c24xx_serial_txempty_nofifo(port); |
| 725 | |
| 726 | if (rx_enabled(port)) { |
| 727 | if (!txe) { |
| 728 | rx_enabled(port) = 0; |
| 729 | continue; |
| 730 | } |
| 731 | } else { |
| 732 | if (txe) { |
Youngmin Nam | aba06e9 | 2016-03-05 19:36:32 +0900 | [diff] [blame] | 733 | ufcon = rd_regl(port, S3C2410_UFCON); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 734 | ufcon |= S3C2410_UFCON_RESETRX; |
| 735 | wr_regl(port, S3C2410_UFCON, ufcon); |
| 736 | rx_enabled(port) = 1; |
Robert Baldyga | 01732dd | 2015-09-15 14:48:59 +0200 | [diff] [blame] | 737 | return; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 738 | } |
| 739 | continue; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /* insert the character into the buffer */ |
| 744 | |
| 745 | flag = TTY_NORMAL; |
| 746 | port->icount.rx++; |
| 747 | |
| 748 | if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) { |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 749 | dev_dbg(port->dev, |
| 750 | "rxerr: port ch=0x%02x, rxs=0x%08x\n", |
| 751 | ch, uerstat); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 752 | |
| 753 | /* check for break */ |
| 754 | if (uerstat & S3C2410_UERSTAT_BREAK) { |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 755 | dev_dbg(port->dev, "break!\n"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 756 | port->icount.brk++; |
| 757 | if (uart_handle_break(port)) |
Robert Baldyga | 620bb21 | 2015-09-15 14:48:58 +0200 | [diff] [blame] | 758 | continue; /* Ignore character */ |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | if (uerstat & S3C2410_UERSTAT_FRAME) |
| 762 | port->icount.frame++; |
| 763 | if (uerstat & S3C2410_UERSTAT_OVERRUN) |
| 764 | port->icount.overrun++; |
| 765 | |
| 766 | uerstat &= port->read_status_mask; |
| 767 | |
| 768 | if (uerstat & S3C2410_UERSTAT_BREAK) |
| 769 | flag = TTY_BREAK; |
| 770 | else if (uerstat & S3C2410_UERSTAT_PARITY) |
| 771 | flag = TTY_PARITY; |
| 772 | else if (uerstat & (S3C2410_UERSTAT_FRAME | |
| 773 | S3C2410_UERSTAT_OVERRUN)) |
| 774 | flag = TTY_FRAME; |
| 775 | } |
| 776 | |
| 777 | if (uart_handle_sysrq_char(port, ch)) |
Robert Baldyga | 620bb21 | 2015-09-15 14:48:58 +0200 | [diff] [blame] | 778 | continue; /* Ignore character */ |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 779 | |
| 780 | uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN, |
| 781 | ch, flag); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 782 | } |
Viresh Kumar | f5693ea | 2013-08-19 20:14:26 +0530 | [diff] [blame] | 783 | |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 784 | tty_flip_buffer_push(&port->state->port); |
Robert Baldyga | 01732dd | 2015-09-15 14:48:59 +0200 | [diff] [blame] | 785 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 786 | |
Robert Baldyga | 01732dd | 2015-09-15 14:48:59 +0200 | [diff] [blame] | 787 | static irqreturn_t s3c24xx_serial_rx_chars_pio(void *dev_id) |
| 788 | { |
| 789 | struct s3c24xx_uart_port *ourport = dev_id; |
| 790 | struct uart_port *port = &ourport->port; |
| 791 | unsigned long flags; |
| 792 | |
| 793 | spin_lock_irqsave(&port->lock, flags); |
| 794 | s3c24xx_serial_rx_drain_fifo(ourport); |
| 795 | spin_unlock_irqrestore(&port->lock, flags); |
| 796 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 797 | return IRQ_HANDLED; |
| 798 | } |
| 799 | |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 800 | |
| 801 | static irqreturn_t s3c24xx_serial_rx_chars(int irq, void *dev_id) |
| 802 | { |
| 803 | struct s3c24xx_uart_port *ourport = dev_id; |
| 804 | |
| 805 | if (ourport->dma && ourport->dma->rx_chan) |
Robert Baldyga | e4678af | 2015-09-15 14:48:57 +0200 | [diff] [blame] | 806 | return s3c24xx_serial_rx_chars_dma(dev_id); |
| 807 | return s3c24xx_serial_rx_chars_pio(dev_id); |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 810 | static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id) |
| 811 | { |
| 812 | struct s3c24xx_uart_port *ourport = id; |
| 813 | struct uart_port *port = &ourport->port; |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 814 | struct circ_buf *xmit = &port->state->xmit; |
Thomas Abraham | c15c374 | 2012-11-22 18:06:28 +0530 | [diff] [blame] | 815 | unsigned long flags; |
Robert Baldyga | 736cd79 | 2015-07-31 10:58:28 +0200 | [diff] [blame] | 816 | int count, dma_count = 0; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 817 | |
Thomas Abraham | c15c374 | 2012-11-22 18:06:28 +0530 | [diff] [blame] | 818 | spin_lock_irqsave(&port->lock, flags); |
| 819 | |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 820 | count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); |
| 821 | |
Marek Szyprowski | 81ccb2a | 2015-07-31 10:58:27 +0200 | [diff] [blame] | 822 | if (ourport->dma && ourport->dma->tx_chan && |
| 823 | count >= ourport->min_dma_size) { |
Robert Baldyga | 736cd79 | 2015-07-31 10:58:28 +0200 | [diff] [blame] | 824 | int align = dma_get_cache_alignment() - |
| 825 | (xmit->tail & (dma_get_cache_alignment() - 1)); |
| 826 | if (count-align >= ourport->min_dma_size) { |
| 827 | dma_count = count-align; |
| 828 | count = align; |
| 829 | } |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 830 | } |
| 831 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 832 | if (port->x_char) { |
| 833 | wr_regb(port, S3C2410_UTXH, port->x_char); |
| 834 | port->icount.tx++; |
| 835 | port->x_char = 0; |
| 836 | goto out; |
| 837 | } |
| 838 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 839 | /* if there isn't anything more to transmit, or the uart is now |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 840 | * stopped, disable the uart and exit |
| 841 | */ |
| 842 | |
| 843 | if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { |
| 844 | s3c24xx_serial_stop_tx(port); |
| 845 | goto out; |
| 846 | } |
| 847 | |
| 848 | /* try and drain the buffer... */ |
| 849 | |
Robert Baldyga | 736cd79 | 2015-07-31 10:58:28 +0200 | [diff] [blame] | 850 | if (count > port->fifosize) { |
| 851 | count = port->fifosize; |
| 852 | dma_count = 0; |
| 853 | } |
| 854 | |
| 855 | while (!uart_circ_empty(xmit) && count > 0) { |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 856 | if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull) |
| 857 | break; |
| 858 | |
| 859 | wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]); |
| 860 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); |
| 861 | port->icount.tx++; |
Robert Baldyga | 736cd79 | 2015-07-31 10:58:28 +0200 | [diff] [blame] | 862 | count--; |
| 863 | } |
| 864 | |
| 865 | if (!count && dma_count) { |
| 866 | s3c24xx_serial_start_tx_dma(ourport, dma_count); |
| 867 | goto out; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 868 | } |
| 869 | |
Thomas Abraham | c15c374 | 2012-11-22 18:06:28 +0530 | [diff] [blame] | 870 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) { |
| 871 | spin_unlock(&port->lock); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 872 | uart_write_wakeup(port); |
Thomas Abraham | c15c374 | 2012-11-22 18:06:28 +0530 | [diff] [blame] | 873 | spin_lock(&port->lock); |
| 874 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 875 | |
| 876 | if (uart_circ_empty(xmit)) |
| 877 | s3c24xx_serial_stop_tx(port); |
| 878 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 879 | out: |
Thomas Abraham | c15c374 | 2012-11-22 18:06:28 +0530 | [diff] [blame] | 880 | spin_unlock_irqrestore(&port->lock, flags); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 881 | return IRQ_HANDLED; |
| 882 | } |
| 883 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 884 | /* interrupt handler for s3c64xx and later SoC's.*/ |
| 885 | static irqreturn_t s3c64xx_serial_handle_irq(int irq, void *id) |
| 886 | { |
| 887 | struct s3c24xx_uart_port *ourport = id; |
| 888 | struct uart_port *port = &ourport->port; |
| 889 | unsigned int pend = rd_regl(port, S3C64XX_UINTP); |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 890 | irqreturn_t ret = IRQ_HANDLED; |
| 891 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 892 | if (pend & S3C64XX_UINTM_RXD_MSK) { |
| 893 | ret = s3c24xx_serial_rx_chars(irq, id); |
| 894 | wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_RXD_MSK); |
| 895 | } |
| 896 | if (pend & S3C64XX_UINTM_TXD_MSK) { |
| 897 | ret = s3c24xx_serial_tx_chars(irq, id); |
| 898 | wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_TXD_MSK); |
| 899 | } |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 900 | return ret; |
| 901 | } |
| 902 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 903 | static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port) |
| 904 | { |
| 905 | struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); |
| 906 | unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT); |
| 907 | unsigned long ufcon = rd_regl(port, S3C2410_UFCON); |
| 908 | |
| 909 | if (ufcon & S3C2410_UFCON_FIFOMODE) { |
| 910 | if ((ufstat & info->tx_fifomask) != 0 || |
| 911 | (ufstat & info->tx_fifofull)) |
| 912 | return 0; |
| 913 | |
| 914 | return 1; |
| 915 | } |
| 916 | |
| 917 | return s3c24xx_serial_txempty_nofifo(port); |
| 918 | } |
| 919 | |
| 920 | /* no modem control lines */ |
| 921 | static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port) |
| 922 | { |
| 923 | unsigned int umstat = rd_regb(port, S3C2410_UMSTAT); |
| 924 | |
| 925 | if (umstat & S3C2410_UMSTAT_CTS) |
| 926 | return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS; |
| 927 | else |
| 928 | return TIOCM_CAR | TIOCM_DSR; |
| 929 | } |
| 930 | |
| 931 | static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| 932 | { |
José Miguel Gonçalves | 2d1e5a4 | 2013-09-18 16:52:49 +0100 | [diff] [blame] | 933 | unsigned int umcon = rd_regl(port, S3C2410_UMCON); |
| 934 | |
| 935 | if (mctrl & TIOCM_RTS) |
| 936 | umcon |= S3C2410_UMCOM_RTS_LOW; |
| 937 | else |
| 938 | umcon &= ~S3C2410_UMCOM_RTS_LOW; |
| 939 | |
| 940 | wr_regl(port, S3C2410_UMCON, umcon); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state) |
| 944 | { |
| 945 | unsigned long flags; |
| 946 | unsigned int ucon; |
| 947 | |
| 948 | spin_lock_irqsave(&port->lock, flags); |
| 949 | |
| 950 | ucon = rd_regl(port, S3C2410_UCON); |
| 951 | |
| 952 | if (break_state) |
| 953 | ucon |= S3C2410_UCON_SBREAK; |
| 954 | else |
| 955 | ucon &= ~S3C2410_UCON_SBREAK; |
| 956 | |
| 957 | wr_regl(port, S3C2410_UCON, ucon); |
| 958 | |
| 959 | spin_unlock_irqrestore(&port->lock, flags); |
| 960 | } |
| 961 | |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 962 | static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p) |
| 963 | { |
| 964 | struct s3c24xx_uart_dma *dma = p->dma; |
Marek Szyprowski | d8db840 | 2018-05-17 13:37:14 +0200 | [diff] [blame] | 965 | struct dma_slave_caps dma_caps; |
| 966 | const char *reason = NULL; |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 967 | int ret; |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 968 | |
| 969 | /* Default slave configuration parameters */ |
| 970 | dma->rx_conf.direction = DMA_DEV_TO_MEM; |
| 971 | dma->rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 972 | dma->rx_conf.src_addr = p->port.mapbase + S3C2410_URXH; |
Marek Szyprowski | aa2f80e | 2018-05-10 08:41:13 +0200 | [diff] [blame] | 973 | dma->rx_conf.src_maxburst = 1; |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 974 | |
| 975 | dma->tx_conf.direction = DMA_MEM_TO_DEV; |
| 976 | dma->tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 977 | dma->tx_conf.dst_addr = p->port.mapbase + S3C2410_UTXH; |
Marek Szyprowski | aa2f80e | 2018-05-10 08:41:13 +0200 | [diff] [blame] | 978 | dma->tx_conf.dst_maxburst = 1; |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 979 | |
Marek Szyprowski | ba3d6f8 | 2016-12-16 10:56:53 +0100 | [diff] [blame] | 980 | dma->rx_chan = dma_request_chan(p->port.dev, "rx"); |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 981 | |
Marek Szyprowski | d8db840 | 2018-05-17 13:37:14 +0200 | [diff] [blame] | 982 | if (IS_ERR(dma->rx_chan)) { |
| 983 | reason = "DMA RX channel request failed"; |
| 984 | ret = PTR_ERR(dma->rx_chan); |
| 985 | goto err_warn; |
| 986 | } |
| 987 | |
| 988 | ret = dma_get_slave_caps(dma->rx_chan, &dma_caps); |
| 989 | if (ret < 0 || |
| 990 | dma_caps.residue_granularity < DMA_RESIDUE_GRANULARITY_BURST) { |
| 991 | reason = "insufficient DMA RX engine capabilities"; |
| 992 | ret = -EOPNOTSUPP; |
| 993 | goto err_release_rx; |
| 994 | } |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 995 | |
| 996 | dmaengine_slave_config(dma->rx_chan, &dma->rx_conf); |
| 997 | |
Marek Szyprowski | ba3d6f8 | 2016-12-16 10:56:53 +0100 | [diff] [blame] | 998 | dma->tx_chan = dma_request_chan(p->port.dev, "tx"); |
| 999 | if (IS_ERR(dma->tx_chan)) { |
Marek Szyprowski | d8db840 | 2018-05-17 13:37:14 +0200 | [diff] [blame] | 1000 | reason = "DMA TX channel request failed"; |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 1001 | ret = PTR_ERR(dma->tx_chan); |
| 1002 | goto err_release_rx; |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
Marek Szyprowski | d8db840 | 2018-05-17 13:37:14 +0200 | [diff] [blame] | 1005 | ret = dma_get_slave_caps(dma->tx_chan, &dma_caps); |
| 1006 | if (ret < 0 || |
| 1007 | dma_caps.residue_granularity < DMA_RESIDUE_GRANULARITY_BURST) { |
| 1008 | reason = "insufficient DMA TX engine capabilities"; |
| 1009 | ret = -EOPNOTSUPP; |
| 1010 | goto err_release_tx; |
| 1011 | } |
| 1012 | |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1013 | dmaengine_slave_config(dma->tx_chan, &dma->tx_conf); |
| 1014 | |
| 1015 | /* RX buffer */ |
| 1016 | dma->rx_size = PAGE_SIZE; |
| 1017 | |
| 1018 | dma->rx_buf = kmalloc(dma->rx_size, GFP_KERNEL); |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1019 | if (!dma->rx_buf) { |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 1020 | ret = -ENOMEM; |
| 1021 | goto err_release_tx; |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
Marek Szyprowski | 768d64f | 2017-04-03 08:20:59 +0200 | [diff] [blame] | 1024 | dma->rx_addr = dma_map_single(p->port.dev, dma->rx_buf, |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1025 | dma->rx_size, DMA_FROM_DEVICE); |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 1026 | if (dma_mapping_error(p->port.dev, dma->rx_addr)) { |
Marek Szyprowski | d8db840 | 2018-05-17 13:37:14 +0200 | [diff] [blame] | 1027 | reason = "DMA mapping error for RX buffer"; |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 1028 | ret = -EIO; |
| 1029 | goto err_free_rx; |
| 1030 | } |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1031 | |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1032 | /* TX buffer */ |
Marek Szyprowski | 768d64f | 2017-04-03 08:20:59 +0200 | [diff] [blame] | 1033 | dma->tx_addr = dma_map_single(p->port.dev, p->port.state->xmit.buf, |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1034 | UART_XMIT_SIZE, DMA_TO_DEVICE); |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 1035 | if (dma_mapping_error(p->port.dev, dma->tx_addr)) { |
Marek Szyprowski | d8db840 | 2018-05-17 13:37:14 +0200 | [diff] [blame] | 1036 | reason = "DMA mapping error for TX buffer"; |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 1037 | ret = -EIO; |
| 1038 | goto err_unmap_rx; |
| 1039 | } |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1040 | |
| 1041 | return 0; |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 1042 | |
| 1043 | err_unmap_rx: |
| 1044 | dma_unmap_single(p->port.dev, dma->rx_addr, dma->rx_size, |
| 1045 | DMA_FROM_DEVICE); |
| 1046 | err_free_rx: |
| 1047 | kfree(dma->rx_buf); |
| 1048 | err_release_tx: |
| 1049 | dma_release_channel(dma->tx_chan); |
| 1050 | err_release_rx: |
| 1051 | dma_release_channel(dma->rx_chan); |
Marek Szyprowski | d8db840 | 2018-05-17 13:37:14 +0200 | [diff] [blame] | 1052 | err_warn: |
| 1053 | if (reason) |
| 1054 | dev_warn(p->port.dev, "%s, DMA will not be used\n", reason); |
Marek Szyprowski | 500fcc0 | 2017-04-03 08:21:00 +0200 | [diff] [blame] | 1055 | return ret; |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p) |
| 1059 | { |
| 1060 | struct s3c24xx_uart_dma *dma = p->dma; |
| 1061 | |
| 1062 | if (dma->rx_chan) { |
| 1063 | dmaengine_terminate_all(dma->rx_chan); |
Marek Szyprowski | 768d64f | 2017-04-03 08:20:59 +0200 | [diff] [blame] | 1064 | dma_unmap_single(p->port.dev, dma->rx_addr, |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1065 | dma->rx_size, DMA_FROM_DEVICE); |
| 1066 | kfree(dma->rx_buf); |
| 1067 | dma_release_channel(dma->rx_chan); |
| 1068 | dma->rx_chan = NULL; |
| 1069 | } |
| 1070 | |
| 1071 | if (dma->tx_chan) { |
| 1072 | dmaengine_terminate_all(dma->tx_chan); |
Marek Szyprowski | 768d64f | 2017-04-03 08:20:59 +0200 | [diff] [blame] | 1073 | dma_unmap_single(p->port.dev, dma->tx_addr, |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1074 | UART_XMIT_SIZE, DMA_TO_DEVICE); |
| 1075 | dma_release_channel(dma->tx_chan); |
| 1076 | dma->tx_chan = NULL; |
| 1077 | } |
| 1078 | } |
| 1079 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1080 | static void s3c24xx_serial_shutdown(struct uart_port *port) |
| 1081 | { |
| 1082 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
| 1083 | |
| 1084 | if (ourport->tx_claimed) { |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1085 | if (!s3c24xx_serial_has_interrupt_mask(port)) |
| 1086 | free_irq(ourport->tx_irq, ourport); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1087 | tx_enabled(port) = 0; |
| 1088 | ourport->tx_claimed = 0; |
Javier Martinez Canillas | e91d863 | 2015-03-13 12:38:51 +0100 | [diff] [blame] | 1089 | ourport->tx_mode = 0; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | if (ourport->rx_claimed) { |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1093 | if (!s3c24xx_serial_has_interrupt_mask(port)) |
| 1094 | free_irq(ourport->rx_irq, ourport); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1095 | ourport->rx_claimed = 0; |
| 1096 | rx_enabled(port) = 0; |
| 1097 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1098 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1099 | /* Clear pending interrupts and mask all interrupts */ |
| 1100 | if (s3c24xx_serial_has_interrupt_mask(port)) { |
Tomasz Figa | b6ad293 | 2013-03-26 15:57:35 +0100 | [diff] [blame] | 1101 | free_irq(port->irq, ourport); |
| 1102 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1103 | wr_regl(port, S3C64XX_UINTP, 0xf); |
| 1104 | wr_regl(port, S3C64XX_UINTM, 0xf); |
| 1105 | } |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1106 | |
| 1107 | if (ourport->dma) |
| 1108 | s3c24xx_serial_release_dma(ourport); |
| 1109 | |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 1110 | ourport->tx_in_progress = 0; |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1111 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1112 | |
| 1113 | static int s3c24xx_serial_startup(struct uart_port *port) |
| 1114 | { |
| 1115 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
| 1116 | int ret; |
| 1117 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1118 | rx_enabled(port) = 1; |
| 1119 | |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 1120 | ret = request_irq(ourport->rx_irq, s3c24xx_serial_rx_chars, 0, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1121 | s3c24xx_serial_portname(port), ourport); |
| 1122 | |
| 1123 | if (ret != 0) { |
Sachin Kamat | d20925e | 2012-09-05 10:30:10 +0530 | [diff] [blame] | 1124 | dev_err(port->dev, "cannot get irq %d\n", ourport->rx_irq); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1125 | return ret; |
| 1126 | } |
| 1127 | |
| 1128 | ourport->rx_claimed = 1; |
| 1129 | |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1130 | dev_dbg(port->dev, "requesting tx irq...\n"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1131 | |
| 1132 | tx_enabled(port) = 1; |
| 1133 | |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 1134 | ret = request_irq(ourport->tx_irq, s3c24xx_serial_tx_chars, 0, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1135 | s3c24xx_serial_portname(port), ourport); |
| 1136 | |
| 1137 | if (ret) { |
Sachin Kamat | d20925e | 2012-09-05 10:30:10 +0530 | [diff] [blame] | 1138 | dev_err(port->dev, "cannot get irq %d\n", ourport->tx_irq); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1139 | goto err; |
| 1140 | } |
| 1141 | |
| 1142 | ourport->tx_claimed = 1; |
| 1143 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1144 | /* the port reset code should have done the correct |
| 1145 | * register setup for the port controls */ |
| 1146 | |
| 1147 | return ret; |
| 1148 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1149 | err: |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1150 | s3c24xx_serial_shutdown(port); |
| 1151 | return ret; |
| 1152 | } |
| 1153 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1154 | static int s3c64xx_serial_startup(struct uart_port *port) |
| 1155 | { |
| 1156 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
Robert Baldyga | b543c30 | 2014-12-10 12:49:27 +0100 | [diff] [blame] | 1157 | unsigned long flags; |
| 1158 | unsigned int ufcon; |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1159 | int ret; |
| 1160 | |
Tomasz Figa | b6ad293 | 2013-03-26 15:57:35 +0100 | [diff] [blame] | 1161 | wr_regl(port, S3C64XX_UINTM, 0xf); |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1162 | if (ourport->dma) { |
| 1163 | ret = s3c24xx_serial_request_dma(ourport); |
| 1164 | if (ret < 0) { |
Krzysztof Kozlowski | f98c7bc | 2017-02-25 18:36:44 +0200 | [diff] [blame] | 1165 | devm_kfree(port->dev, ourport->dma); |
| 1166 | ourport->dma = NULL; |
Robert Baldyga | 62c37ee | 2014-12-10 12:49:25 +0100 | [diff] [blame] | 1167 | } |
| 1168 | } |
Tomasz Figa | b6ad293 | 2013-03-26 15:57:35 +0100 | [diff] [blame] | 1169 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1170 | ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED, |
| 1171 | s3c24xx_serial_portname(port), ourport); |
| 1172 | if (ret) { |
Sachin Kamat | d20925e | 2012-09-05 10:30:10 +0530 | [diff] [blame] | 1173 | dev_err(port->dev, "cannot get irq %d\n", port->irq); |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1174 | return ret; |
| 1175 | } |
| 1176 | |
| 1177 | /* For compatibility with s3c24xx Soc's */ |
| 1178 | rx_enabled(port) = 1; |
| 1179 | ourport->rx_claimed = 1; |
| 1180 | tx_enabled(port) = 0; |
| 1181 | ourport->tx_claimed = 1; |
| 1182 | |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 1183 | spin_lock_irqsave(&port->lock, flags); |
| 1184 | |
| 1185 | ufcon = rd_regl(port, S3C2410_UFCON); |
Robert Baldyga | 31c6ba9 | 2015-04-17 08:43:09 +0200 | [diff] [blame] | 1186 | ufcon |= S3C2410_UFCON_RESETRX | S5PV210_UFCON_RXTRIG8; |
| 1187 | if (!uart_console(port)) |
| 1188 | ufcon |= S3C2410_UFCON_RESETTX; |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 1189 | wr_regl(port, S3C2410_UFCON, ufcon); |
| 1190 | |
| 1191 | enable_rx_pio(ourport); |
| 1192 | |
| 1193 | spin_unlock_irqrestore(&port->lock, flags); |
| 1194 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1195 | /* Enable Rx Interrupt */ |
Matthew Leach | bbb5ff9 | 2016-06-22 17:57:03 +0100 | [diff] [blame] | 1196 | s3c24xx_clear_bit(port, S3C64XX_UINTM_RXD, S3C64XX_UINTM); |
Robert Baldyga | 29bef79 | 2014-12-10 12:49:26 +0100 | [diff] [blame] | 1197 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1198 | return ret; |
| 1199 | } |
| 1200 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1201 | /* power power management control */ |
| 1202 | |
| 1203 | static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level, |
| 1204 | unsigned int old) |
| 1205 | { |
| 1206 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
Robert Baldyga | 1ff383a | 2014-11-24 07:56:21 +0100 | [diff] [blame] | 1207 | int timeout = 10000; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1208 | |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1209 | ourport->pm_level = level; |
| 1210 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1211 | switch (level) { |
| 1212 | case 3: |
Robert Baldyga | 1ff383a | 2014-11-24 07:56:21 +0100 | [diff] [blame] | 1213 | while (--timeout && !s3c24xx_serial_txempty_nofifo(port)) |
| 1214 | udelay(100); |
| 1215 | |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 1216 | if (!IS_ERR(ourport->baudclk)) |
Thomas Abraham | 9484b00 | 2012-10-03 07:40:04 +0900 | [diff] [blame] | 1217 | clk_disable_unprepare(ourport->baudclk); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1218 | |
Thomas Abraham | 9484b00 | 2012-10-03 07:40:04 +0900 | [diff] [blame] | 1219 | clk_disable_unprepare(ourport->clk); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1220 | break; |
| 1221 | |
| 1222 | case 0: |
Thomas Abraham | 9484b00 | 2012-10-03 07:40:04 +0900 | [diff] [blame] | 1223 | clk_prepare_enable(ourport->clk); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1224 | |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 1225 | if (!IS_ERR(ourport->baudclk)) |
Thomas Abraham | 9484b00 | 2012-10-03 07:40:04 +0900 | [diff] [blame] | 1226 | clk_prepare_enable(ourport->baudclk); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1227 | |
| 1228 | break; |
| 1229 | default: |
Sachin Kamat | d20925e | 2012-09-05 10:30:10 +0530 | [diff] [blame] | 1230 | dev_err(port->dev, "s3c24xx_serial: unknown pm %d\n", level); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | /* baud rate calculation |
| 1235 | * |
| 1236 | * The UARTs on the S3C2410/S3C2440 can take their clocks from a number |
| 1237 | * of different sources, including the peripheral clock ("pclk") and an |
| 1238 | * external clock ("uclk"). The S3C2440 also adds the core clock ("fclk") |
| 1239 | * with a programmable extra divisor. |
| 1240 | * |
| 1241 | * The following code goes through the clock sources, and calculates the |
| 1242 | * baud clocks (and the resultant actual baud rates) and then tries to |
| 1243 | * pick the closest one and select that. |
| 1244 | * |
| 1245 | */ |
| 1246 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1247 | #define MAX_CLK_NAME_LENGTH 15 |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1248 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1249 | static inline int s3c24xx_serial_getsource(struct uart_port *port) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1250 | { |
| 1251 | struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1252 | unsigned int ucon; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1253 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1254 | if (info->num_clks == 1) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1255 | return 0; |
| 1256 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1257 | ucon = rd_regl(port, S3C2410_UCON); |
| 1258 | ucon &= info->clksel_mask; |
| 1259 | return ucon >> info->clksel_shift; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1260 | } |
| 1261 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1262 | static void s3c24xx_serial_setsource(struct uart_port *port, |
| 1263 | unsigned int clk_sel) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1264 | { |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1265 | struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); |
| 1266 | unsigned int ucon; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1267 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1268 | if (info->num_clks == 1) |
| 1269 | return; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1270 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1271 | ucon = rd_regl(port, S3C2410_UCON); |
| 1272 | if ((ucon & info->clksel_mask) >> info->clksel_shift == clk_sel) |
| 1273 | return; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1274 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1275 | ucon &= ~info->clksel_mask; |
| 1276 | ucon |= clk_sel << info->clksel_shift; |
| 1277 | wr_regl(port, S3C2410_UCON, ucon); |
| 1278 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1279 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1280 | static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport, |
| 1281 | unsigned int req_baud, struct clk **best_clk, |
| 1282 | unsigned int *clk_num) |
| 1283 | { |
| 1284 | struct s3c24xx_uart_info *info = ourport->info; |
| 1285 | struct clk *clk; |
| 1286 | unsigned long rate; |
| 1287 | unsigned int cnt, baud, quot, clk_sel, best_quot = 0; |
| 1288 | char clkname[MAX_CLK_NAME_LENGTH]; |
| 1289 | int calc_deviation, deviation = (1 << 30) - 1; |
| 1290 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1291 | clk_sel = (ourport->cfg->clk_sel) ? ourport->cfg->clk_sel : |
| 1292 | ourport->info->def_clk_sel; |
| 1293 | for (cnt = 0; cnt < info->num_clks; cnt++) { |
| 1294 | if (!(clk_sel & (1 << cnt))) |
| 1295 | continue; |
| 1296 | |
| 1297 | sprintf(clkname, "clk_uart_baud%d", cnt); |
| 1298 | clk = clk_get(ourport->port.dev, clkname); |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 1299 | if (IS_ERR(clk)) |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1300 | continue; |
| 1301 | |
| 1302 | rate = clk_get_rate(clk); |
| 1303 | if (!rate) |
| 1304 | continue; |
| 1305 | |
| 1306 | if (ourport->info->has_divslot) { |
| 1307 | unsigned long div = rate / req_baud; |
| 1308 | |
| 1309 | /* The UDIVSLOT register on the newer UARTs allows us to |
| 1310 | * get a divisor adjustment of 1/16th on the baud clock. |
| 1311 | * |
| 1312 | * We don't keep the UDIVSLOT value (the 16ths we |
| 1313 | * calculated by not multiplying the baud by 16) as it |
| 1314 | * is easy enough to recalculate. |
| 1315 | */ |
| 1316 | |
| 1317 | quot = div / 16; |
| 1318 | baud = rate / div; |
| 1319 | } else { |
| 1320 | quot = (rate + (8 * req_baud)) / (16 * req_baud); |
| 1321 | baud = rate / (quot * 16); |
| 1322 | } |
| 1323 | quot--; |
| 1324 | |
| 1325 | calc_deviation = req_baud - baud; |
| 1326 | if (calc_deviation < 0) |
| 1327 | calc_deviation = -calc_deviation; |
| 1328 | |
| 1329 | if (calc_deviation < deviation) { |
| 1330 | *best_clk = clk; |
| 1331 | best_quot = quot; |
| 1332 | *clk_num = cnt; |
| 1333 | deviation = calc_deviation; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1337 | return best_quot; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1338 | } |
| 1339 | |
Ben Dooks | 090f848d | 2008-12-12 00:24:21 +0000 | [diff] [blame] | 1340 | /* udivslot_table[] |
| 1341 | * |
| 1342 | * This table takes the fractional value of the baud divisor and gives |
| 1343 | * the recommended setting for the UDIVSLOT register. |
| 1344 | */ |
| 1345 | static u16 udivslot_table[16] = { |
| 1346 | [0] = 0x0000, |
| 1347 | [1] = 0x0080, |
| 1348 | [2] = 0x0808, |
| 1349 | [3] = 0x0888, |
| 1350 | [4] = 0x2222, |
| 1351 | [5] = 0x4924, |
| 1352 | [6] = 0x4A52, |
| 1353 | [7] = 0x54AA, |
| 1354 | [8] = 0x5555, |
| 1355 | [9] = 0xD555, |
| 1356 | [10] = 0xD5D5, |
| 1357 | [11] = 0xDDD5, |
| 1358 | [12] = 0xDDDD, |
| 1359 | [13] = 0xDFDD, |
| 1360 | [14] = 0xDFDF, |
| 1361 | [15] = 0xFFDF, |
| 1362 | }; |
| 1363 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1364 | static void s3c24xx_serial_set_termios(struct uart_port *port, |
| 1365 | struct ktermios *termios, |
| 1366 | struct ktermios *old) |
| 1367 | { |
| 1368 | struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port); |
| 1369 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 1370 | struct clk *clk = ERR_PTR(-EINVAL); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1371 | unsigned long flags; |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1372 | unsigned int baud, quot, clk_sel = 0; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1373 | unsigned int ulcon; |
| 1374 | unsigned int umcon; |
Ben Dooks | 090f848d | 2008-12-12 00:24:21 +0000 | [diff] [blame] | 1375 | unsigned int udivslot = 0; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1376 | |
| 1377 | /* |
| 1378 | * We don't support modem control lines. |
| 1379 | */ |
| 1380 | termios->c_cflag &= ~(HUPCL | CMSPAR); |
| 1381 | termios->c_cflag |= CLOCAL; |
| 1382 | |
| 1383 | /* |
| 1384 | * Ask the core to calculate the divisor for us. |
| 1385 | */ |
| 1386 | |
Seung-Woo Kim | ec18f48 | 2018-12-14 12:34:09 +0100 | [diff] [blame] | 1387 | baud = uart_get_baud_rate(port, termios, old, 0, 3000000); |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1388 | quot = s3c24xx_serial_getclk(ourport, baud, &clk, &clk_sel); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1389 | if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) |
| 1390 | quot = port->custom_divisor; |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 1391 | if (IS_ERR(clk)) |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1392 | return; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1393 | |
| 1394 | /* check to see if we need to change clock source */ |
| 1395 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1396 | if (ourport->baudclk != clk) { |
Chanwoo Choi | b8995f5 | 2016-04-21 18:58:31 +0900 | [diff] [blame] | 1397 | clk_prepare_enable(clk); |
| 1398 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 1399 | s3c24xx_serial_setsource(port, clk_sel); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1400 | |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 1401 | if (!IS_ERR(ourport->baudclk)) { |
Thomas Abraham | 9484b00 | 2012-10-03 07:40:04 +0900 | [diff] [blame] | 1402 | clk_disable_unprepare(ourport->baudclk); |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 1403 | ourport->baudclk = ERR_PTR(-EINVAL); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1404 | } |
| 1405 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1406 | ourport->baudclk = clk; |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1407 | ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1408 | } |
| 1409 | |
Ben Dooks | 090f848d | 2008-12-12 00:24:21 +0000 | [diff] [blame] | 1410 | if (ourport->info->has_divslot) { |
| 1411 | unsigned int div = ourport->baudclk_rate / baud; |
| 1412 | |
Jongpill Lee | 8b526ae | 2010-07-16 10:19:41 +0900 | [diff] [blame] | 1413 | if (cfg->has_fracval) { |
| 1414 | udivslot = (div & 15); |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1415 | dev_dbg(port->dev, "fracval = %04x\n", udivslot); |
Jongpill Lee | 8b526ae | 2010-07-16 10:19:41 +0900 | [diff] [blame] | 1416 | } else { |
| 1417 | udivslot = udivslot_table[div & 15]; |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1418 | dev_dbg(port->dev, "udivslot = %04x (div %d)\n", |
| 1419 | udivslot, div & 15); |
Jongpill Lee | 8b526ae | 2010-07-16 10:19:41 +0900 | [diff] [blame] | 1420 | } |
Ben Dooks | 090f848d | 2008-12-12 00:24:21 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1423 | switch (termios->c_cflag & CSIZE) { |
| 1424 | case CS5: |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1425 | dev_dbg(port->dev, "config: 5bits/char\n"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1426 | ulcon = S3C2410_LCON_CS5; |
| 1427 | break; |
| 1428 | case CS6: |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1429 | dev_dbg(port->dev, "config: 6bits/char\n"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1430 | ulcon = S3C2410_LCON_CS6; |
| 1431 | break; |
| 1432 | case CS7: |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1433 | dev_dbg(port->dev, "config: 7bits/char\n"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1434 | ulcon = S3C2410_LCON_CS7; |
| 1435 | break; |
| 1436 | case CS8: |
| 1437 | default: |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1438 | dev_dbg(port->dev, "config: 8bits/char\n"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1439 | ulcon = S3C2410_LCON_CS8; |
| 1440 | break; |
| 1441 | } |
| 1442 | |
| 1443 | /* preserve original lcon IR settings */ |
| 1444 | ulcon |= (cfg->ulcon & S3C2410_LCON_IRM); |
| 1445 | |
| 1446 | if (termios->c_cflag & CSTOPB) |
| 1447 | ulcon |= S3C2410_LCON_STOPB; |
| 1448 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1449 | if (termios->c_cflag & PARENB) { |
| 1450 | if (termios->c_cflag & PARODD) |
| 1451 | ulcon |= S3C2410_LCON_PODD; |
| 1452 | else |
| 1453 | ulcon |= S3C2410_LCON_PEVEN; |
| 1454 | } else { |
| 1455 | ulcon |= S3C2410_LCON_PNONE; |
| 1456 | } |
| 1457 | |
| 1458 | spin_lock_irqsave(&port->lock, flags); |
| 1459 | |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1460 | dev_dbg(port->dev, |
| 1461 | "setting ulcon to %08x, brddiv to %d, udivslot %08x\n", |
| 1462 | ulcon, quot, udivslot); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1463 | |
| 1464 | wr_regl(port, S3C2410_ULCON, ulcon); |
| 1465 | wr_regl(port, S3C2410_UBRDIV, quot); |
José Miguel Gonçalves | 2d1e5a4 | 2013-09-18 16:52:49 +0100 | [diff] [blame] | 1466 | |
Beomho Seo | 31e9336 | 2018-12-14 12:34:08 +0100 | [diff] [blame] | 1467 | port->status &= ~UPSTAT_AUTOCTS; |
| 1468 | |
José Miguel Gonçalves | 2d1e5a4 | 2013-09-18 16:52:49 +0100 | [diff] [blame] | 1469 | umcon = rd_regl(port, S3C2410_UMCON); |
| 1470 | if (termios->c_cflag & CRTSCTS) { |
| 1471 | umcon |= S3C2410_UMCOM_AFC; |
| 1472 | /* Disable RTS when RX FIFO contains 63 bytes */ |
| 1473 | umcon &= ~S3C2412_UMCON_AFC_8; |
Beomho Seo | 31e9336 | 2018-12-14 12:34:08 +0100 | [diff] [blame] | 1474 | port->status = UPSTAT_AUTOCTS; |
José Miguel Gonçalves | 2d1e5a4 | 2013-09-18 16:52:49 +0100 | [diff] [blame] | 1475 | } else { |
| 1476 | umcon &= ~S3C2410_UMCOM_AFC; |
| 1477 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1478 | wr_regl(port, S3C2410_UMCON, umcon); |
| 1479 | |
Ben Dooks | 090f848d | 2008-12-12 00:24:21 +0000 | [diff] [blame] | 1480 | if (ourport->info->has_divslot) |
| 1481 | wr_regl(port, S3C2443_DIVSLOT, udivslot); |
| 1482 | |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1483 | dev_dbg(port->dev, |
| 1484 | "uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n", |
| 1485 | rd_regl(port, S3C2410_ULCON), |
| 1486 | rd_regl(port, S3C2410_UCON), |
| 1487 | rd_regl(port, S3C2410_UFCON)); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1488 | |
| 1489 | /* |
| 1490 | * Update the per-port timeout. |
| 1491 | */ |
| 1492 | uart_update_timeout(port, termios->c_cflag, baud); |
| 1493 | |
| 1494 | /* |
| 1495 | * Which character status flags are we interested in? |
| 1496 | */ |
| 1497 | port->read_status_mask = S3C2410_UERSTAT_OVERRUN; |
| 1498 | if (termios->c_iflag & INPCK) |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1499 | port->read_status_mask |= S3C2410_UERSTAT_FRAME | |
| 1500 | S3C2410_UERSTAT_PARITY; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1501 | /* |
| 1502 | * Which character status flags should we ignore? |
| 1503 | */ |
| 1504 | port->ignore_status_mask = 0; |
| 1505 | if (termios->c_iflag & IGNPAR) |
| 1506 | port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN; |
| 1507 | if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR) |
| 1508 | port->ignore_status_mask |= S3C2410_UERSTAT_FRAME; |
| 1509 | |
| 1510 | /* |
| 1511 | * Ignore all characters if CREAD is not set. |
| 1512 | */ |
| 1513 | if ((termios->c_cflag & CREAD) == 0) |
| 1514 | port->ignore_status_mask |= RXSTAT_DUMMY_READ; |
| 1515 | |
| 1516 | spin_unlock_irqrestore(&port->lock, flags); |
| 1517 | } |
| 1518 | |
| 1519 | static const char *s3c24xx_serial_type(struct uart_port *port) |
| 1520 | { |
| 1521 | switch (port->type) { |
| 1522 | case PORT_S3C2410: |
| 1523 | return "S3C2410"; |
| 1524 | case PORT_S3C2440: |
| 1525 | return "S3C2440"; |
| 1526 | case PORT_S3C2412: |
| 1527 | return "S3C2412"; |
Ben Dooks | b690ace | 2008-10-21 14:07:03 +0100 | [diff] [blame] | 1528 | case PORT_S3C6400: |
| 1529 | return "S3C6400/10"; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1530 | default: |
| 1531 | return NULL; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | #define MAP_SIZE (0x100) |
| 1536 | |
| 1537 | static void s3c24xx_serial_release_port(struct uart_port *port) |
| 1538 | { |
| 1539 | release_mem_region(port->mapbase, MAP_SIZE); |
| 1540 | } |
| 1541 | |
| 1542 | static int s3c24xx_serial_request_port(struct uart_port *port) |
| 1543 | { |
| 1544 | const char *name = s3c24xx_serial_portname(port); |
| 1545 | return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY; |
| 1546 | } |
| 1547 | |
| 1548 | static void s3c24xx_serial_config_port(struct uart_port *port, int flags) |
| 1549 | { |
| 1550 | struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); |
| 1551 | |
| 1552 | if (flags & UART_CONFIG_TYPE && |
| 1553 | s3c24xx_serial_request_port(port) == 0) |
| 1554 | port->type = info->type; |
| 1555 | } |
| 1556 | |
| 1557 | /* |
| 1558 | * verify the new serial_struct (for TIOCSSERIAL). |
| 1559 | */ |
| 1560 | static int |
| 1561 | s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 1562 | { |
| 1563 | struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); |
| 1564 | |
| 1565 | if (ser->type != PORT_UNKNOWN && ser->type != info->type) |
| 1566 | return -EINVAL; |
| 1567 | |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
| 1571 | |
| 1572 | #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE |
| 1573 | |
| 1574 | static struct console s3c24xx_serial_console; |
| 1575 | |
Julien Pichon | 93b5c03 | 2012-09-21 23:22:31 -0700 | [diff] [blame] | 1576 | static int __init s3c24xx_serial_console_init(void) |
| 1577 | { |
| 1578 | register_console(&s3c24xx_serial_console); |
| 1579 | return 0; |
| 1580 | } |
| 1581 | console_initcall(s3c24xx_serial_console_init); |
| 1582 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1583 | #define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console |
| 1584 | #else |
| 1585 | #define S3C24XX_SERIAL_CONSOLE NULL |
| 1586 | #endif |
| 1587 | |
Arnd Bergmann | 84f57d9 | 2013-04-11 02:04:49 +0200 | [diff] [blame] | 1588 | #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL) |
Julien Pichon | 93b5c03 | 2012-09-21 23:22:31 -0700 | [diff] [blame] | 1589 | static int s3c24xx_serial_get_poll_char(struct uart_port *port); |
| 1590 | static void s3c24xx_serial_put_poll_char(struct uart_port *port, |
| 1591 | unsigned char c); |
| 1592 | #endif |
| 1593 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1594 | static struct uart_ops s3c24xx_serial_ops = { |
| 1595 | .pm = s3c24xx_serial_pm, |
| 1596 | .tx_empty = s3c24xx_serial_tx_empty, |
| 1597 | .get_mctrl = s3c24xx_serial_get_mctrl, |
| 1598 | .set_mctrl = s3c24xx_serial_set_mctrl, |
| 1599 | .stop_tx = s3c24xx_serial_stop_tx, |
| 1600 | .start_tx = s3c24xx_serial_start_tx, |
| 1601 | .stop_rx = s3c24xx_serial_stop_rx, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1602 | .break_ctl = s3c24xx_serial_break_ctl, |
| 1603 | .startup = s3c24xx_serial_startup, |
| 1604 | .shutdown = s3c24xx_serial_shutdown, |
| 1605 | .set_termios = s3c24xx_serial_set_termios, |
| 1606 | .type = s3c24xx_serial_type, |
| 1607 | .release_port = s3c24xx_serial_release_port, |
| 1608 | .request_port = s3c24xx_serial_request_port, |
| 1609 | .config_port = s3c24xx_serial_config_port, |
| 1610 | .verify_port = s3c24xx_serial_verify_port, |
Arnd Bergmann | 84f57d9 | 2013-04-11 02:04:49 +0200 | [diff] [blame] | 1611 | #if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL) |
Julien Pichon | 93b5c03 | 2012-09-21 23:22:31 -0700 | [diff] [blame] | 1612 | .poll_get_char = s3c24xx_serial_get_poll_char, |
| 1613 | .poll_put_char = s3c24xx_serial_put_poll_char, |
| 1614 | #endif |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1615 | }; |
| 1616 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1617 | static struct uart_driver s3c24xx_uart_drv = { |
| 1618 | .owner = THIS_MODULE, |
Darius Augulis | 2cf0c58 | 2011-01-12 14:50:51 +0900 | [diff] [blame] | 1619 | .driver_name = "s3c2410_serial", |
Ben Dooks | bdd4915 | 2008-11-03 19:51:42 +0000 | [diff] [blame] | 1620 | .nr = CONFIG_SERIAL_SAMSUNG_UARTS, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1621 | .cons = S3C24XX_SERIAL_CONSOLE, |
Darius Augulis | 2cf0c58 | 2011-01-12 14:50:51 +0900 | [diff] [blame] | 1622 | .dev_name = S3C24XX_SERIAL_NAME, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1623 | .major = S3C24XX_SERIAL_MAJOR, |
| 1624 | .minor = S3C24XX_SERIAL_MINOR, |
| 1625 | }; |
| 1626 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1627 | #define __PORT_LOCK_UNLOCKED(i) \ |
| 1628 | __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[i].port.lock) |
| 1629 | static struct s3c24xx_uart_port |
| 1630 | s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = { |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1631 | [0] = { |
| 1632 | .port = { |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1633 | .lock = __PORT_LOCK_UNLOCKED(0), |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1634 | .iotype = UPIO_MEM, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1635 | .uartclk = 0, |
| 1636 | .fifosize = 16, |
| 1637 | .ops = &s3c24xx_serial_ops, |
| 1638 | .flags = UPF_BOOT_AUTOCONF, |
| 1639 | .line = 0, |
| 1640 | } |
| 1641 | }, |
| 1642 | [1] = { |
| 1643 | .port = { |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1644 | .lock = __PORT_LOCK_UNLOCKED(1), |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1645 | .iotype = UPIO_MEM, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1646 | .uartclk = 0, |
| 1647 | .fifosize = 16, |
| 1648 | .ops = &s3c24xx_serial_ops, |
| 1649 | .flags = UPF_BOOT_AUTOCONF, |
| 1650 | .line = 1, |
| 1651 | } |
| 1652 | }, |
Ben Dooks | 03d5e77 | 2008-11-03 09:21:23 +0000 | [diff] [blame] | 1653 | #if CONFIG_SERIAL_SAMSUNG_UARTS > 2 |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1654 | |
| 1655 | [2] = { |
| 1656 | .port = { |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1657 | .lock = __PORT_LOCK_UNLOCKED(2), |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1658 | .iotype = UPIO_MEM, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1659 | .uartclk = 0, |
| 1660 | .fifosize = 16, |
| 1661 | .ops = &s3c24xx_serial_ops, |
| 1662 | .flags = UPF_BOOT_AUTOCONF, |
| 1663 | .line = 2, |
| 1664 | } |
Ben Dooks | 03d5e77 | 2008-11-03 09:21:23 +0000 | [diff] [blame] | 1665 | }, |
| 1666 | #endif |
| 1667 | #if CONFIG_SERIAL_SAMSUNG_UARTS > 3 |
| 1668 | [3] = { |
| 1669 | .port = { |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1670 | .lock = __PORT_LOCK_UNLOCKED(3), |
Ben Dooks | 03d5e77 | 2008-11-03 09:21:23 +0000 | [diff] [blame] | 1671 | .iotype = UPIO_MEM, |
Ben Dooks | 03d5e77 | 2008-11-03 09:21:23 +0000 | [diff] [blame] | 1672 | .uartclk = 0, |
| 1673 | .fifosize = 16, |
| 1674 | .ops = &s3c24xx_serial_ops, |
| 1675 | .flags = UPF_BOOT_AUTOCONF, |
| 1676 | .line = 3, |
| 1677 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1678 | } |
| 1679 | #endif |
| 1680 | }; |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1681 | #undef __PORT_LOCK_UNLOCKED |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1682 | |
| 1683 | /* s3c24xx_serial_resetport |
| 1684 | * |
Thomas Abraham | 0dfb3b4 | 2011-10-24 11:48:21 +0200 | [diff] [blame] | 1685 | * reset the fifos and other the settings. |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1686 | */ |
| 1687 | |
Thomas Abraham | 0dfb3b4 | 2011-10-24 11:48:21 +0200 | [diff] [blame] | 1688 | static void s3c24xx_serial_resetport(struct uart_port *port, |
| 1689 | struct s3c2410_uartcfg *cfg) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1690 | { |
| 1691 | struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); |
Thomas Abraham | 0dfb3b4 | 2011-10-24 11:48:21 +0200 | [diff] [blame] | 1692 | unsigned long ucon = rd_regl(port, S3C2410_UCON); |
| 1693 | unsigned int ucon_mask; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1694 | |
Thomas Abraham | 0dfb3b4 | 2011-10-24 11:48:21 +0200 | [diff] [blame] | 1695 | ucon_mask = info->clksel_mask; |
| 1696 | if (info->type == PORT_S3C2440) |
| 1697 | ucon_mask |= S3C2440_UCON0_DIVMASK; |
| 1698 | |
| 1699 | ucon &= ucon_mask; |
| 1700 | wr_regl(port, S3C2410_UCON, ucon | cfg->ucon); |
| 1701 | |
| 1702 | /* reset both fifos */ |
| 1703 | wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH); |
| 1704 | wr_regl(port, S3C2410_UFCON, cfg->ufcon); |
| 1705 | |
| 1706 | /* some delay is required after fifo reset */ |
| 1707 | udelay(1); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1710 | |
Krzysztof Kozlowski | ebaa81c | 2016-06-27 13:59:08 +0200 | [diff] [blame] | 1711 | #ifdef CONFIG_ARM_S3C24XX_CPUFREQ |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1712 | |
| 1713 | static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb, |
| 1714 | unsigned long val, void *data) |
| 1715 | { |
| 1716 | struct s3c24xx_uart_port *port; |
| 1717 | struct uart_port *uport; |
| 1718 | |
| 1719 | port = container_of(nb, struct s3c24xx_uart_port, freq_transition); |
| 1720 | uport = &port->port; |
| 1721 | |
| 1722 | /* check to see if port is enabled */ |
| 1723 | |
| 1724 | if (port->pm_level != 0) |
| 1725 | return 0; |
| 1726 | |
| 1727 | /* try and work out if the baudrate is changing, we can detect |
| 1728 | * a change in rate, but we do not have support for detecting |
| 1729 | * a disturbance in the clock-rate over the change. |
| 1730 | */ |
| 1731 | |
Kyoungil Kim | 25f04ad | 2012-05-20 17:49:31 +0900 | [diff] [blame] | 1732 | if (IS_ERR(port->baudclk)) |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1733 | goto exit; |
| 1734 | |
Kyoungil Kim | 25f04ad | 2012-05-20 17:49:31 +0900 | [diff] [blame] | 1735 | if (port->baudclk_rate == clk_get_rate(port->baudclk)) |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1736 | goto exit; |
| 1737 | |
| 1738 | if (val == CPUFREQ_PRECHANGE) { |
| 1739 | /* we should really shut the port down whilst the |
| 1740 | * frequency change is in progress. */ |
| 1741 | |
| 1742 | } else if (val == CPUFREQ_POSTCHANGE) { |
| 1743 | struct ktermios *termios; |
| 1744 | struct tty_struct *tty; |
| 1745 | |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 1746 | if (uport->state == NULL) |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1747 | goto exit; |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1748 | |
Alan Cox | ebd2c8f | 2009-09-19 13:13:28 -0700 | [diff] [blame] | 1749 | tty = uport->state->port.tty; |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1750 | |
Ben Dooks | 7de40c2 | 2008-12-14 23:11:02 +0000 | [diff] [blame] | 1751 | if (tty == NULL) |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1752 | goto exit; |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1753 | |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 1754 | termios = &tty->termios; |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1755 | |
| 1756 | if (termios == NULL) { |
Sachin Kamat | d20925e | 2012-09-05 10:30:10 +0530 | [diff] [blame] | 1757 | dev_warn(uport->dev, "%s: no termios?\n", __func__); |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1758 | goto exit; |
| 1759 | } |
| 1760 | |
| 1761 | s3c24xx_serial_set_termios(uport, termios, NULL); |
| 1762 | } |
| 1763 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1764 | exit: |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1765 | return 0; |
| 1766 | } |
| 1767 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1768 | static inline int |
| 1769 | s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port) |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1770 | { |
| 1771 | port->freq_transition.notifier_call = s3c24xx_serial_cpufreq_transition; |
| 1772 | |
| 1773 | return cpufreq_register_notifier(&port->freq_transition, |
| 1774 | CPUFREQ_TRANSITION_NOTIFIER); |
| 1775 | } |
| 1776 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1777 | static inline void |
| 1778 | s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port) |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1779 | { |
| 1780 | cpufreq_unregister_notifier(&port->freq_transition, |
| 1781 | CPUFREQ_TRANSITION_NOTIFIER); |
| 1782 | } |
| 1783 | |
| 1784 | #else |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1785 | static inline int |
| 1786 | s3c24xx_serial_cpufreq_register(struct s3c24xx_uart_port *port) |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1787 | { |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
Robert Baldyga | ef4aca7 | 2014-11-24 07:56:22 +0100 | [diff] [blame] | 1791 | static inline void |
| 1792 | s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *port) |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 1793 | { |
| 1794 | } |
| 1795 | #endif |
| 1796 | |
Stuart Menefy | 5086e0a | 2019-02-12 21:40:22 +0000 | [diff] [blame] | 1797 | static int s3c24xx_serial_enable_baudclk(struct s3c24xx_uart_port *ourport) |
| 1798 | { |
| 1799 | struct device *dev = ourport->port.dev; |
| 1800 | struct s3c24xx_uart_info *info = ourport->info; |
| 1801 | char clk_name[MAX_CLK_NAME_LENGTH]; |
| 1802 | unsigned int clk_sel; |
| 1803 | struct clk *clk; |
| 1804 | int clk_num; |
| 1805 | int ret; |
| 1806 | |
| 1807 | clk_sel = ourport->cfg->clk_sel ? : info->def_clk_sel; |
| 1808 | for (clk_num = 0; clk_num < info->num_clks; clk_num++) { |
| 1809 | if (!(clk_sel & (1 << clk_num))) |
| 1810 | continue; |
| 1811 | |
| 1812 | sprintf(clk_name, "clk_uart_baud%d", clk_num); |
| 1813 | clk = clk_get(dev, clk_name); |
| 1814 | if (IS_ERR(clk)) |
| 1815 | continue; |
| 1816 | |
| 1817 | ret = clk_prepare_enable(clk); |
| 1818 | if (ret) { |
| 1819 | clk_put(clk); |
| 1820 | continue; |
| 1821 | } |
| 1822 | |
| 1823 | ourport->baudclk = clk; |
| 1824 | ourport->baudclk_rate = clk_get_rate(clk); |
| 1825 | s3c24xx_serial_setsource(&ourport->port, clk_num); |
| 1826 | |
| 1827 | return 0; |
| 1828 | } |
| 1829 | |
| 1830 | return -EINVAL; |
| 1831 | } |
| 1832 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1833 | /* s3c24xx_serial_init_port |
| 1834 | * |
| 1835 | * initialise a single serial port from the platform device given |
| 1836 | */ |
| 1837 | |
| 1838 | static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1839 | struct platform_device *platdev) |
| 1840 | { |
| 1841 | struct uart_port *port = &ourport->port; |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 1842 | struct s3c2410_uartcfg *cfg = ourport->cfg; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1843 | struct resource *res; |
| 1844 | int ret; |
| 1845 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1846 | if (platdev == NULL) |
| 1847 | return -ENODEV; |
| 1848 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1849 | if (port->mapbase != 0) |
Krzysztof Kozlowski | e51e4d8 | 2016-06-16 08:27:35 +0200 | [diff] [blame] | 1850 | return -EINVAL; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1851 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1852 | /* setup info for port */ |
| 1853 | port->dev = &platdev->dev; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1854 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1855 | /* Startup sequence is different for s3c64xx and higher SoC's */ |
| 1856 | if (s3c24xx_serial_has_interrupt_mask(port)) |
| 1857 | s3c24xx_serial_ops.startup = s3c64xx_serial_startup; |
| 1858 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1859 | port->uartclk = 1; |
| 1860 | |
| 1861 | if (cfg->uart_flags & UPF_CONS_FLOW) { |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1862 | dev_dbg(port->dev, "enabling flow control\n"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1863 | port->flags |= UPF_CONS_FLOW; |
| 1864 | } |
| 1865 | |
| 1866 | /* sort our the physical and virtual addresses for each UART */ |
| 1867 | |
| 1868 | res = platform_get_resource(platdev, IORESOURCE_MEM, 0); |
| 1869 | if (res == NULL) { |
Sachin Kamat | d20925e | 2012-09-05 10:30:10 +0530 | [diff] [blame] | 1870 | dev_err(port->dev, "failed to find memory resource for uart\n"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1871 | return -EINVAL; |
| 1872 | } |
| 1873 | |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1874 | dev_dbg(port->dev, "resource %pR)\n", res); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1875 | |
Thomas Abraham | 41147bf | 2013-01-01 00:21:55 -0800 | [diff] [blame] | 1876 | port->membase = devm_ioremap(port->dev, res->start, resource_size(res)); |
| 1877 | if (!port->membase) { |
| 1878 | dev_err(port->dev, "failed to remap controller address\n"); |
| 1879 | return -EBUSY; |
| 1880 | } |
| 1881 | |
Ben Dooks | b690ace | 2008-10-21 14:07:03 +0100 | [diff] [blame] | 1882 | port->mapbase = res->start; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1883 | ret = platform_get_irq(platdev, 0); |
| 1884 | if (ret < 0) |
| 1885 | port->irq = 0; |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 1886 | else { |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1887 | port->irq = ret; |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 1888 | ourport->rx_irq = ret; |
| 1889 | ourport->tx_irq = ret + 1; |
| 1890 | } |
Sachin Kamat | 9303ac1 | 2012-09-05 10:30:11 +0530 | [diff] [blame] | 1891 | |
Ben Dooks | b73c289c | 2008-10-21 14:07:04 +0100 | [diff] [blame] | 1892 | ret = platform_get_irq(platdev, 1); |
| 1893 | if (ret > 0) |
| 1894 | ourport->tx_irq = ret; |
Robert Baldyga | 658c9d2b7 | 2014-12-10 12:49:23 +0100 | [diff] [blame] | 1895 | /* |
| 1896 | * DMA is currently supported only on DT platforms, if DMA properties |
| 1897 | * are specified. |
| 1898 | */ |
| 1899 | if (platdev->dev.of_node && of_find_property(platdev->dev.of_node, |
| 1900 | "dmas", NULL)) { |
| 1901 | ourport->dma = devm_kzalloc(port->dev, |
| 1902 | sizeof(*ourport->dma), |
| 1903 | GFP_KERNEL); |
Krzysztof Kozlowski | e51e4d8 | 2016-06-16 08:27:35 +0200 | [diff] [blame] | 1904 | if (!ourport->dma) { |
| 1905 | ret = -ENOMEM; |
| 1906 | goto err; |
| 1907 | } |
Robert Baldyga | 658c9d2b7 | 2014-12-10 12:49:23 +0100 | [diff] [blame] | 1908 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1909 | |
| 1910 | ourport->clk = clk_get(&platdev->dev, "uart"); |
Chander Kashyap | 60e9357 | 2013-05-28 18:32:07 +0530 | [diff] [blame] | 1911 | if (IS_ERR(ourport->clk)) { |
| 1912 | pr_err("%s: Controller clock not found\n", |
| 1913 | dev_name(&platdev->dev)); |
Krzysztof Kozlowski | e51e4d8 | 2016-06-16 08:27:35 +0200 | [diff] [blame] | 1914 | ret = PTR_ERR(ourport->clk); |
| 1915 | goto err; |
Chander Kashyap | 60e9357 | 2013-05-28 18:32:07 +0530 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | ret = clk_prepare_enable(ourport->clk); |
| 1919 | if (ret) { |
| 1920 | pr_err("uart: clock failed to prepare+enable: %d\n", ret); |
| 1921 | clk_put(ourport->clk); |
Krzysztof Kozlowski | e51e4d8 | 2016-06-16 08:27:35 +0200 | [diff] [blame] | 1922 | goto err; |
Chander Kashyap | 60e9357 | 2013-05-28 18:32:07 +0530 | [diff] [blame] | 1923 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1924 | |
Stuart Menefy | 5086e0a | 2019-02-12 21:40:22 +0000 | [diff] [blame] | 1925 | ret = s3c24xx_serial_enable_baudclk(ourport); |
| 1926 | if (ret) |
| 1927 | pr_warn("uart: failed to enable baudclk\n"); |
| 1928 | |
Thomas Abraham | 88bb4ea | 2011-08-10 15:51:19 +0530 | [diff] [blame] | 1929 | /* Keep all interrupts masked and cleared */ |
| 1930 | if (s3c24xx_serial_has_interrupt_mask(port)) { |
| 1931 | wr_regl(port, S3C64XX_UINTM, 0xf); |
| 1932 | wr_regl(port, S3C64XX_UINTP, 0xf); |
| 1933 | wr_regl(port, S3C64XX_UINTSP, 0xf); |
| 1934 | } |
| 1935 | |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 1936 | dev_dbg(port->dev, "port: map=%pa, mem=%p, irq=%d (%d,%d), clock=%u\n", |
| 1937 | &port->mapbase, port->membase, port->irq, |
| 1938 | ourport->rx_irq, ourport->tx_irq, port->uartclk); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1939 | |
| 1940 | /* reset the fifos (and setup the uart) */ |
| 1941 | s3c24xx_serial_resetport(port, cfg); |
Krzysztof Kozlowski | e51e4d8 | 2016-06-16 08:27:35 +0200 | [diff] [blame] | 1942 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1943 | return 0; |
Krzysztof Kozlowski | e51e4d8 | 2016-06-16 08:27:35 +0200 | [diff] [blame] | 1944 | |
| 1945 | err: |
| 1946 | port->mapbase = 0; |
| 1947 | return ret; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1950 | /* Device driver serial port probe */ |
| 1951 | |
Greg Kroah-Hartman | 06674e5 | 2019-12-10 15:36:58 +0100 | [diff] [blame] | 1952 | #ifdef CONFIG_OF |
Thomas Abraham | 26c919e | 2011-11-06 22:10:44 +0530 | [diff] [blame] | 1953 | static const struct of_device_id s3c24xx_uart_dt_match[]; |
Greg Kroah-Hartman | 06674e5 | 2019-12-10 15:36:58 +0100 | [diff] [blame] | 1954 | #endif |
| 1955 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1956 | static int probe_index; |
| 1957 | |
Thomas Abraham | 26c919e | 2011-11-06 22:10:44 +0530 | [diff] [blame] | 1958 | static inline struct s3c24xx_serial_drv_data *s3c24xx_get_driver_data( |
| 1959 | struct platform_device *pdev) |
| 1960 | { |
| 1961 | #ifdef CONFIG_OF |
| 1962 | if (pdev->dev.of_node) { |
| 1963 | const struct of_device_id *match; |
| 1964 | match = of_match_node(s3c24xx_uart_dt_match, pdev->dev.of_node); |
| 1965 | return (struct s3c24xx_serial_drv_data *)match->data; |
| 1966 | } |
| 1967 | #endif |
| 1968 | return (struct s3c24xx_serial_drv_data *) |
| 1969 | platform_get_device_id(pdev)->driver_data; |
| 1970 | } |
| 1971 | |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 1972 | static int s3c24xx_serial_probe(struct platform_device *pdev) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1973 | { |
Naveen Krishna Chatradhi | 4622eb6 | 2014-07-14 17:07:18 +0530 | [diff] [blame] | 1974 | struct device_node *np = pdev->dev.of_node; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1975 | struct s3c24xx_uart_port *ourport; |
Tomasz Figa | 13a9f6c6 | 2014-06-26 13:24:34 +0200 | [diff] [blame] | 1976 | int index = probe_index; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1977 | int ret; |
| 1978 | |
Naveen Krishna Chatradhi | 4622eb6 | 2014-07-14 17:07:18 +0530 | [diff] [blame] | 1979 | if (np) { |
| 1980 | ret = of_alias_get_id(np, "serial"); |
Tomasz Figa | 13a9f6c6 | 2014-06-26 13:24:34 +0200 | [diff] [blame] | 1981 | if (ret >= 0) |
| 1982 | index = ret; |
| 1983 | } |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 1984 | |
Geert Uytterhoeven | 49ee23b | 2018-02-23 14:38:34 +0100 | [diff] [blame] | 1985 | if (index >= ARRAY_SIZE(s3c24xx_serial_ports)) { |
| 1986 | dev_err(&pdev->dev, "serial%d out of range\n", index); |
| 1987 | return -EINVAL; |
| 1988 | } |
Tomasz Figa | 13a9f6c6 | 2014-06-26 13:24:34 +0200 | [diff] [blame] | 1989 | ourport = &s3c24xx_serial_ports[index]; |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 1990 | |
Thomas Abraham | 26c919e | 2011-11-06 22:10:44 +0530 | [diff] [blame] | 1991 | ourport->drv_data = s3c24xx_get_driver_data(pdev); |
| 1992 | if (!ourport->drv_data) { |
| 1993 | dev_err(&pdev->dev, "could not find driver data\n"); |
| 1994 | return -ENODEV; |
| 1995 | } |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 1996 | |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 1997 | ourport->baudclk = ERR_PTR(-EINVAL); |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 1998 | ourport->info = ourport->drv_data->info; |
Jingoo Han | 574de55 | 2013-07-30 17:06:57 +0900 | [diff] [blame] | 1999 | ourport->cfg = (dev_get_platdata(&pdev->dev)) ? |
Jingoo Han | d4aab20 | 2013-09-09 14:10:30 +0900 | [diff] [blame] | 2000 | dev_get_platdata(&pdev->dev) : |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2001 | ourport->drv_data->def_cfg; |
| 2002 | |
Naveen Krishna Chatradhi | 4622eb6 | 2014-07-14 17:07:18 +0530 | [diff] [blame] | 2003 | if (np) |
| 2004 | of_property_read_u32(np, |
Naveen Krishna Chatradhi | 135f07c | 2014-07-14 17:07:16 +0530 | [diff] [blame] | 2005 | "samsung,uart-fifosize", &ourport->port.fifosize); |
| 2006 | |
Robert Baldyga | 2f1ba72 | 2014-11-24 07:56:23 +0100 | [diff] [blame] | 2007 | if (ourport->drv_data->fifosize[index]) |
| 2008 | ourport->port.fifosize = ourport->drv_data->fifosize[index]; |
| 2009 | else if (ourport->info->fifosize) |
| 2010 | ourport->port.fifosize = ourport->info->fifosize; |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2011 | |
Marek Szyprowski | 81ccb2a | 2015-07-31 10:58:27 +0200 | [diff] [blame] | 2012 | /* |
| 2013 | * DMA transfers must be aligned at least to cache line size, |
| 2014 | * so find minimal transfer size suitable for DMA mode |
| 2015 | */ |
| 2016 | ourport->min_dma_size = max_t(int, ourport->port.fifosize, |
| 2017 | dma_get_cache_alignment()); |
| 2018 | |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 2019 | dev_dbg(&pdev->dev, "%s: initialising port %p...\n", __func__, ourport); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2020 | |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2021 | ret = s3c24xx_serial_init_port(ourport, pdev); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2022 | if (ret < 0) |
Tushar Behera | 8ad711a | 2014-06-23 11:32:14 +0530 | [diff] [blame] | 2023 | return ret; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2024 | |
Tushar Behera | 6f134c3c | 2014-01-20 14:32:34 +0530 | [diff] [blame] | 2025 | if (!s3c24xx_uart_drv.state) { |
| 2026 | ret = uart_register_driver(&s3c24xx_uart_drv); |
| 2027 | if (ret < 0) { |
| 2028 | pr_err("Failed to register Samsung UART driver\n"); |
| 2029 | return ret; |
| 2030 | } |
| 2031 | } |
| 2032 | |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 2033 | dev_dbg(&pdev->dev, "%s: adding port\n", __func__); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2034 | uart_add_one_port(&s3c24xx_uart_drv, &ourport->port); |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2035 | platform_set_drvdata(pdev, &ourport->port); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2036 | |
Heiko Stübner | 0da3336 | 2013-12-05 00:54:38 +0100 | [diff] [blame] | 2037 | /* |
| 2038 | * Deactivate the clock enabled in s3c24xx_serial_init_port here, |
| 2039 | * so that a potential re-enablement through the pm-callback overlaps |
| 2040 | * and keeps the clock enabled in this case. |
| 2041 | */ |
| 2042 | clk_disable_unprepare(ourport->clk); |
Stuart Menefy | 5086e0a | 2019-02-12 21:40:22 +0000 | [diff] [blame] | 2043 | if (!IS_ERR(ourport->baudclk)) |
| 2044 | clk_disable_unprepare(ourport->baudclk); |
Heiko Stübner | 0da3336 | 2013-12-05 00:54:38 +0100 | [diff] [blame] | 2045 | |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 2046 | ret = s3c24xx_serial_cpufreq_register(ourport); |
| 2047 | if (ret < 0) |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2048 | dev_err(&pdev->dev, "failed to add cpufreq notifier\n"); |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 2049 | |
Krzysztof Kozlowski | 926b7b5 | 2016-06-16 08:27:36 +0200 | [diff] [blame] | 2050 | probe_index++; |
| 2051 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2052 | return 0; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2053 | } |
| 2054 | |
Bill Pemberton | ae8d8a1 | 2012-11-19 13:26:18 -0500 | [diff] [blame] | 2055 | static int s3c24xx_serial_remove(struct platform_device *dev) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2056 | { |
| 2057 | struct uart_port *port = s3c24xx_dev_to_port(&dev->dev); |
| 2058 | |
| 2059 | if (port) { |
Ben Dooks | 3055547 | 2008-10-21 14:06:36 +0100 | [diff] [blame] | 2060 | s3c24xx_serial_cpufreq_deregister(to_ourport(port)); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2061 | uart_remove_one_port(&s3c24xx_uart_drv, port); |
| 2062 | } |
| 2063 | |
Tushar Behera | 6f134c3c | 2014-01-20 14:32:34 +0530 | [diff] [blame] | 2064 | uart_unregister_driver(&s3c24xx_uart_drv); |
| 2065 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2066 | return 0; |
| 2067 | } |
| 2068 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2069 | /* UART power management code */ |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2070 | #ifdef CONFIG_PM_SLEEP |
| 2071 | static int s3c24xx_serial_suspend(struct device *dev) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2072 | { |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2073 | struct uart_port *port = s3c24xx_dev_to_port(dev); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2074 | |
| 2075 | if (port) |
| 2076 | uart_suspend_port(&s3c24xx_uart_drv, port); |
| 2077 | |
| 2078 | return 0; |
| 2079 | } |
| 2080 | |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2081 | static int s3c24xx_serial_resume(struct device *dev) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2082 | { |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2083 | struct uart_port *port = s3c24xx_dev_to_port(dev); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2084 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
| 2085 | |
| 2086 | if (port) { |
Thomas Abraham | 9484b00 | 2012-10-03 07:40:04 +0900 | [diff] [blame] | 2087 | clk_prepare_enable(ourport->clk); |
Marek Szyprowski | 1ff3652 | 2018-09-13 10:21:25 +0200 | [diff] [blame] | 2088 | if (!IS_ERR(ourport->baudclk)) |
| 2089 | clk_prepare_enable(ourport->baudclk); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2090 | s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port)); |
Marek Szyprowski | 1ff3652 | 2018-09-13 10:21:25 +0200 | [diff] [blame] | 2091 | if (!IS_ERR(ourport->baudclk)) |
| 2092 | clk_disable_unprepare(ourport->baudclk); |
Thomas Abraham | 9484b00 | 2012-10-03 07:40:04 +0900 | [diff] [blame] | 2093 | clk_disable_unprepare(ourport->clk); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2094 | |
| 2095 | uart_resume_port(&s3c24xx_uart_drv, port); |
| 2096 | } |
| 2097 | |
| 2098 | return 0; |
| 2099 | } |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2100 | |
Michael Spang | d09a730 | 2013-03-27 19:34:24 -0400 | [diff] [blame] | 2101 | static int s3c24xx_serial_resume_noirq(struct device *dev) |
| 2102 | { |
| 2103 | struct uart_port *port = s3c24xx_dev_to_port(dev); |
남영민 | a8a1781 | 2017-02-01 19:25:46 +0900 | [diff] [blame] | 2104 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
Michael Spang | d09a730 | 2013-03-27 19:34:24 -0400 | [diff] [blame] | 2105 | |
| 2106 | if (port) { |
| 2107 | /* restore IRQ mask */ |
| 2108 | if (s3c24xx_serial_has_interrupt_mask(port)) { |
| 2109 | unsigned int uintm = 0xf; |
| 2110 | if (tx_enabled(port)) |
| 2111 | uintm &= ~S3C64XX_UINTM_TXD_MSK; |
| 2112 | if (rx_enabled(port)) |
| 2113 | uintm &= ~S3C64XX_UINTM_RXD_MSK; |
남영민 | a8a1781 | 2017-02-01 19:25:46 +0900 | [diff] [blame] | 2114 | clk_prepare_enable(ourport->clk); |
Marek Szyprowski | 1ff3652 | 2018-09-13 10:21:25 +0200 | [diff] [blame] | 2115 | if (!IS_ERR(ourport->baudclk)) |
| 2116 | clk_prepare_enable(ourport->baudclk); |
Michael Spang | d09a730 | 2013-03-27 19:34:24 -0400 | [diff] [blame] | 2117 | wr_regl(port, S3C64XX_UINTM, uintm); |
Marek Szyprowski | 1ff3652 | 2018-09-13 10:21:25 +0200 | [diff] [blame] | 2118 | if (!IS_ERR(ourport->baudclk)) |
| 2119 | clk_disable_unprepare(ourport->baudclk); |
남영민 | a8a1781 | 2017-02-01 19:25:46 +0900 | [diff] [blame] | 2120 | clk_disable_unprepare(ourport->clk); |
Michael Spang | d09a730 | 2013-03-27 19:34:24 -0400 | [diff] [blame] | 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | return 0; |
| 2125 | } |
| 2126 | |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2127 | static const struct dev_pm_ops s3c24xx_serial_pm_ops = { |
| 2128 | .suspend = s3c24xx_serial_suspend, |
| 2129 | .resume = s3c24xx_serial_resume, |
Michael Spang | d09a730 | 2013-03-27 19:34:24 -0400 | [diff] [blame] | 2130 | .resume_noirq = s3c24xx_serial_resume_noirq, |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2131 | }; |
Kukjin Kim | b882fc1 | 2011-07-28 08:50:38 +0900 | [diff] [blame] | 2132 | #define SERIAL_SAMSUNG_PM_OPS (&s3c24xx_serial_pm_ops) |
| 2133 | |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2134 | #else /* !CONFIG_PM_SLEEP */ |
Kukjin Kim | b882fc1 | 2011-07-28 08:50:38 +0900 | [diff] [blame] | 2135 | |
| 2136 | #define SERIAL_SAMSUNG_PM_OPS NULL |
MyungJoo Ham | aef7fe5 | 2011-06-29 15:28:24 +0900 | [diff] [blame] | 2137 | #endif /* CONFIG_PM_SLEEP */ |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2138 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2139 | /* Console code */ |
| 2140 | |
| 2141 | #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE |
| 2142 | |
| 2143 | static struct uart_port *cons_uart; |
| 2144 | |
| 2145 | static int |
| 2146 | s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon) |
| 2147 | { |
| 2148 | struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); |
| 2149 | unsigned long ufstat, utrstat; |
| 2150 | |
| 2151 | if (ufcon & S3C2410_UFCON_FIFOMODE) { |
Uwe Kleine-König | 9ddc5b6 | 2010-01-20 17:02:24 +0100 | [diff] [blame] | 2152 | /* fifo mode - check amount of data in fifo registers... */ |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2153 | |
| 2154 | ufstat = rd_regl(port, S3C2410_UFSTAT); |
| 2155 | return (ufstat & info->tx_fifofull) ? 0 : 1; |
| 2156 | } |
| 2157 | |
| 2158 | /* in non-fifo mode, we go and use the tx buffer empty */ |
| 2159 | |
| 2160 | utrstat = rd_regl(port, S3C2410_UTRSTAT); |
| 2161 | return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0; |
| 2162 | } |
| 2163 | |
Michael Spang | 38adbc5 | 2013-03-27 19:34:25 -0400 | [diff] [blame] | 2164 | static bool |
| 2165 | s3c24xx_port_configured(unsigned int ucon) |
| 2166 | { |
| 2167 | /* consider the serial port configured if the tx/rx mode set */ |
| 2168 | return (ucon & 0xf) != 0; |
| 2169 | } |
| 2170 | |
Julien Pichon | 93b5c03 | 2012-09-21 23:22:31 -0700 | [diff] [blame] | 2171 | #ifdef CONFIG_CONSOLE_POLL |
| 2172 | /* |
| 2173 | * Console polling routines for writing and reading from the uart while |
| 2174 | * in an interrupt or debug context. |
| 2175 | */ |
| 2176 | |
| 2177 | static int s3c24xx_serial_get_poll_char(struct uart_port *port) |
| 2178 | { |
| 2179 | struct s3c24xx_uart_port *ourport = to_ourport(port); |
| 2180 | unsigned int ufstat; |
| 2181 | |
| 2182 | ufstat = rd_regl(port, S3C2410_UFSTAT); |
| 2183 | if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0) |
| 2184 | return NO_POLL_CHAR; |
| 2185 | |
| 2186 | return rd_regb(port, S3C2410_URXH); |
| 2187 | } |
| 2188 | |
| 2189 | static void s3c24xx_serial_put_poll_char(struct uart_port *port, |
| 2190 | unsigned char c) |
| 2191 | { |
Doug Anderson | bb7f09b | 2014-04-21 09:40:34 -0700 | [diff] [blame] | 2192 | unsigned int ufcon = rd_regl(port, S3C2410_UFCON); |
| 2193 | unsigned int ucon = rd_regl(port, S3C2410_UCON); |
Michael Spang | 38adbc5 | 2013-03-27 19:34:25 -0400 | [diff] [blame] | 2194 | |
| 2195 | /* not possible to xmit on unconfigured port */ |
| 2196 | if (!s3c24xx_port_configured(ucon)) |
| 2197 | return; |
Julien Pichon | 93b5c03 | 2012-09-21 23:22:31 -0700 | [diff] [blame] | 2198 | |
| 2199 | while (!s3c24xx_serial_console_txrdy(port, ufcon)) |
| 2200 | cpu_relax(); |
Doug Anderson | bb7f09b | 2014-04-21 09:40:34 -0700 | [diff] [blame] | 2201 | wr_regb(port, S3C2410_UTXH, c); |
Julien Pichon | 93b5c03 | 2012-09-21 23:22:31 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | #endif /* CONFIG_CONSOLE_POLL */ |
| 2205 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2206 | static void |
| 2207 | s3c24xx_serial_console_putchar(struct uart_port *port, int ch) |
| 2208 | { |
Doug Anderson | bb7f09b | 2014-04-21 09:40:34 -0700 | [diff] [blame] | 2209 | unsigned int ufcon = rd_regl(port, S3C2410_UFCON); |
Michael Spang | 38adbc5 | 2013-03-27 19:34:25 -0400 | [diff] [blame] | 2210 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2211 | while (!s3c24xx_serial_console_txrdy(port, ufcon)) |
Doug Anderson | f94b057 | 2014-04-21 09:40:36 -0700 | [diff] [blame] | 2212 | cpu_relax(); |
Doug Anderson | bb7f09b | 2014-04-21 09:40:34 -0700 | [diff] [blame] | 2213 | wr_regb(port, S3C2410_UTXH, ch); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | static void |
| 2217 | s3c24xx_serial_console_write(struct console *co, const char *s, |
| 2218 | unsigned int count) |
| 2219 | { |
Doug Anderson | ab88c8d | 2014-04-21 09:40:35 -0700 | [diff] [blame] | 2220 | unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON); |
| 2221 | |
| 2222 | /* not possible to xmit on unconfigured port */ |
| 2223 | if (!s3c24xx_port_configured(ucon)) |
| 2224 | return; |
| 2225 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2226 | uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar); |
| 2227 | } |
| 2228 | |
| 2229 | static void __init |
| 2230 | s3c24xx_serial_get_options(struct uart_port *port, int *baud, |
| 2231 | int *parity, int *bits) |
| 2232 | { |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2233 | struct clk *clk; |
| 2234 | unsigned int ulcon; |
| 2235 | unsigned int ucon; |
| 2236 | unsigned int ubrdiv; |
| 2237 | unsigned long rate; |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 2238 | unsigned int clk_sel; |
| 2239 | char clk_name[MAX_CLK_NAME_LENGTH]; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2240 | |
| 2241 | ulcon = rd_regl(port, S3C2410_ULCON); |
| 2242 | ucon = rd_regl(port, S3C2410_UCON); |
| 2243 | ubrdiv = rd_regl(port, S3C2410_UBRDIV); |
| 2244 | |
Michael Spang | 38adbc5 | 2013-03-27 19:34:25 -0400 | [diff] [blame] | 2245 | if (s3c24xx_port_configured(ucon)) { |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2246 | switch (ulcon & S3C2410_LCON_CSMASK) { |
| 2247 | case S3C2410_LCON_CS5: |
| 2248 | *bits = 5; |
| 2249 | break; |
| 2250 | case S3C2410_LCON_CS6: |
| 2251 | *bits = 6; |
| 2252 | break; |
| 2253 | case S3C2410_LCON_CS7: |
| 2254 | *bits = 7; |
| 2255 | break; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2256 | case S3C2410_LCON_CS8: |
Naveen Krishna Chatradhi | 3bcce59 | 2014-07-14 17:07:17 +0530 | [diff] [blame] | 2257 | default: |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2258 | *bits = 8; |
| 2259 | break; |
| 2260 | } |
| 2261 | |
| 2262 | switch (ulcon & S3C2410_LCON_PMASK) { |
| 2263 | case S3C2410_LCON_PEVEN: |
| 2264 | *parity = 'e'; |
| 2265 | break; |
| 2266 | |
| 2267 | case S3C2410_LCON_PODD: |
| 2268 | *parity = 'o'; |
| 2269 | break; |
| 2270 | |
| 2271 | case S3C2410_LCON_PNONE: |
| 2272 | default: |
| 2273 | *parity = 'n'; |
| 2274 | } |
| 2275 | |
| 2276 | /* now calculate the baud rate */ |
| 2277 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 2278 | clk_sel = s3c24xx_serial_getsource(port); |
| 2279 | sprintf(clk_name, "clk_uart_baud%d", clk_sel); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2280 | |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 2281 | clk = clk_get(port->dev, clk_name); |
Kyoungil Kim | 7cd8883 | 2012-05-20 17:45:54 +0900 | [diff] [blame] | 2282 | if (!IS_ERR(clk)) |
Thomas Abraham | 5f5a7a5 | 2011-10-24 11:47:46 +0200 | [diff] [blame] | 2283 | rate = clk_get_rate(clk); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2284 | else |
| 2285 | rate = 1; |
| 2286 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2287 | *baud = rate / (16 * (ubrdiv + 1)); |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 2288 | dev_dbg(port->dev, "calculated baud %d\n", *baud); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | } |
| 2292 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2293 | static int __init |
| 2294 | s3c24xx_serial_console_setup(struct console *co, char *options) |
| 2295 | { |
| 2296 | struct uart_port *port; |
| 2297 | int baud = 9600; |
| 2298 | int bits = 8; |
| 2299 | int parity = 'n'; |
| 2300 | int flow = 'n'; |
| 2301 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2302 | /* is this a valid port */ |
| 2303 | |
Ben Dooks | 03d5e77 | 2008-11-03 09:21:23 +0000 | [diff] [blame] | 2304 | if (co->index == -1 || co->index >= CONFIG_SERIAL_SAMSUNG_UARTS) |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2305 | co->index = 0; |
| 2306 | |
| 2307 | port = &s3c24xx_serial_ports[co->index].port; |
| 2308 | |
| 2309 | /* is the port configured? */ |
| 2310 | |
Thomas Abraham | ee430f1 | 2011-06-14 19:12:26 +0900 | [diff] [blame] | 2311 | if (port->mapbase == 0x0) |
| 2312 | return -ENODEV; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2313 | |
| 2314 | cons_uart = port; |
| 2315 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2316 | /* |
| 2317 | * Check whether an invalid uart number has been specified, and |
| 2318 | * if so, search for the first available port that does have |
| 2319 | * console support. |
| 2320 | */ |
| 2321 | if (options) |
| 2322 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
| 2323 | else |
| 2324 | s3c24xx_serial_get_options(port, &baud, &parity, &bits); |
| 2325 | |
Greg Kroah-Hartman | a05025d | 2019-12-10 15:37:03 +0100 | [diff] [blame] | 2326 | dev_dbg(port->dev, "baud %d\n", baud); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2327 | |
| 2328 | return uart_set_options(port, co, baud, parity, bits, flow); |
| 2329 | } |
| 2330 | |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2331 | static struct console s3c24xx_serial_console = { |
| 2332 | .name = S3C24XX_SERIAL_NAME, |
| 2333 | .device = uart_console_device, |
| 2334 | .flags = CON_PRINTBUFFER, |
| 2335 | .index = -1, |
| 2336 | .write = s3c24xx_serial_console_write, |
Thomas Abraham | 5822a5d | 2011-06-14 19:12:26 +0900 | [diff] [blame] | 2337 | .setup = s3c24xx_serial_console_setup, |
| 2338 | .data = &s3c24xx_uart_drv, |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2339 | }; |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2340 | #endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */ |
| 2341 | |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2342 | #ifdef CONFIG_CPU_S3C2410 |
| 2343 | static struct s3c24xx_serial_drv_data s3c2410_serial_drv_data = { |
| 2344 | .info = &(struct s3c24xx_uart_info) { |
| 2345 | .name = "Samsung S3C2410 UART", |
| 2346 | .type = PORT_S3C2410, |
| 2347 | .fifosize = 16, |
| 2348 | .rx_fifomask = S3C2410_UFSTAT_RXMASK, |
| 2349 | .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT, |
| 2350 | .rx_fifofull = S3C2410_UFSTAT_RXFULL, |
| 2351 | .tx_fifofull = S3C2410_UFSTAT_TXFULL, |
| 2352 | .tx_fifomask = S3C2410_UFSTAT_TXMASK, |
| 2353 | .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT, |
| 2354 | .def_clk_sel = S3C2410_UCON_CLKSEL0, |
| 2355 | .num_clks = 2, |
| 2356 | .clksel_mask = S3C2410_UCON_CLKMASK, |
| 2357 | .clksel_shift = S3C2410_UCON_CLKSHIFT, |
| 2358 | }, |
| 2359 | .def_cfg = &(struct s3c2410_uartcfg) { |
| 2360 | .ucon = S3C2410_UCON_DEFAULT, |
| 2361 | .ufcon = S3C2410_UFCON_DEFAULT, |
| 2362 | }, |
| 2363 | }; |
| 2364 | #define S3C2410_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2410_serial_drv_data) |
| 2365 | #else |
| 2366 | #define S3C2410_SERIAL_DRV_DATA (kernel_ulong_t)NULL |
| 2367 | #endif |
| 2368 | |
| 2369 | #ifdef CONFIG_CPU_S3C2412 |
| 2370 | static struct s3c24xx_serial_drv_data s3c2412_serial_drv_data = { |
| 2371 | .info = &(struct s3c24xx_uart_info) { |
| 2372 | .name = "Samsung S3C2412 UART", |
| 2373 | .type = PORT_S3C2412, |
| 2374 | .fifosize = 64, |
| 2375 | .has_divslot = 1, |
| 2376 | .rx_fifomask = S3C2440_UFSTAT_RXMASK, |
| 2377 | .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT, |
| 2378 | .rx_fifofull = S3C2440_UFSTAT_RXFULL, |
| 2379 | .tx_fifofull = S3C2440_UFSTAT_TXFULL, |
| 2380 | .tx_fifomask = S3C2440_UFSTAT_TXMASK, |
| 2381 | .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT, |
| 2382 | .def_clk_sel = S3C2410_UCON_CLKSEL2, |
| 2383 | .num_clks = 4, |
| 2384 | .clksel_mask = S3C2412_UCON_CLKMASK, |
| 2385 | .clksel_shift = S3C2412_UCON_CLKSHIFT, |
| 2386 | }, |
| 2387 | .def_cfg = &(struct s3c2410_uartcfg) { |
| 2388 | .ucon = S3C2410_UCON_DEFAULT, |
| 2389 | .ufcon = S3C2410_UFCON_DEFAULT, |
| 2390 | }, |
| 2391 | }; |
| 2392 | #define S3C2412_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2412_serial_drv_data) |
| 2393 | #else |
| 2394 | #define S3C2412_SERIAL_DRV_DATA (kernel_ulong_t)NULL |
| 2395 | #endif |
| 2396 | |
| 2397 | #if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2416) || \ |
Denis 'GNUtoo' Carikli | b26469a | 2012-02-23 08:23:52 +0100 | [diff] [blame] | 2398 | defined(CONFIG_CPU_S3C2443) || defined(CONFIG_CPU_S3C2442) |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2399 | static struct s3c24xx_serial_drv_data s3c2440_serial_drv_data = { |
| 2400 | .info = &(struct s3c24xx_uart_info) { |
| 2401 | .name = "Samsung S3C2440 UART", |
| 2402 | .type = PORT_S3C2440, |
| 2403 | .fifosize = 64, |
| 2404 | .has_divslot = 1, |
| 2405 | .rx_fifomask = S3C2440_UFSTAT_RXMASK, |
| 2406 | .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT, |
| 2407 | .rx_fifofull = S3C2440_UFSTAT_RXFULL, |
| 2408 | .tx_fifofull = S3C2440_UFSTAT_TXFULL, |
| 2409 | .tx_fifomask = S3C2440_UFSTAT_TXMASK, |
| 2410 | .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT, |
| 2411 | .def_clk_sel = S3C2410_UCON_CLKSEL2, |
| 2412 | .num_clks = 4, |
| 2413 | .clksel_mask = S3C2412_UCON_CLKMASK, |
| 2414 | .clksel_shift = S3C2412_UCON_CLKSHIFT, |
| 2415 | }, |
| 2416 | .def_cfg = &(struct s3c2410_uartcfg) { |
| 2417 | .ucon = S3C2410_UCON_DEFAULT, |
| 2418 | .ufcon = S3C2410_UFCON_DEFAULT, |
| 2419 | }, |
| 2420 | }; |
| 2421 | #define S3C2440_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2440_serial_drv_data) |
| 2422 | #else |
| 2423 | #define S3C2440_SERIAL_DRV_DATA (kernel_ulong_t)NULL |
| 2424 | #endif |
| 2425 | |
Kukjin Kim | 953b53a | 2014-07-01 06:32:22 +0900 | [diff] [blame] | 2426 | #if defined(CONFIG_CPU_S3C6400) || defined(CONFIG_CPU_S3C6410) |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2427 | static struct s3c24xx_serial_drv_data s3c6400_serial_drv_data = { |
| 2428 | .info = &(struct s3c24xx_uart_info) { |
| 2429 | .name = "Samsung S3C6400 UART", |
| 2430 | .type = PORT_S3C6400, |
| 2431 | .fifosize = 64, |
| 2432 | .has_divslot = 1, |
| 2433 | .rx_fifomask = S3C2440_UFSTAT_RXMASK, |
| 2434 | .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT, |
| 2435 | .rx_fifofull = S3C2440_UFSTAT_RXFULL, |
| 2436 | .tx_fifofull = S3C2440_UFSTAT_TXFULL, |
| 2437 | .tx_fifomask = S3C2440_UFSTAT_TXMASK, |
| 2438 | .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT, |
| 2439 | .def_clk_sel = S3C2410_UCON_CLKSEL2, |
| 2440 | .num_clks = 4, |
| 2441 | .clksel_mask = S3C6400_UCON_CLKMASK, |
| 2442 | .clksel_shift = S3C6400_UCON_CLKSHIFT, |
| 2443 | }, |
| 2444 | .def_cfg = &(struct s3c2410_uartcfg) { |
| 2445 | .ucon = S3C2410_UCON_DEFAULT, |
| 2446 | .ufcon = S3C2410_UFCON_DEFAULT, |
| 2447 | }, |
| 2448 | }; |
| 2449 | #define S3C6400_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c6400_serial_drv_data) |
| 2450 | #else |
| 2451 | #define S3C6400_SERIAL_DRV_DATA (kernel_ulong_t)NULL |
| 2452 | #endif |
| 2453 | |
| 2454 | #ifdef CONFIG_CPU_S5PV210 |
| 2455 | static struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = { |
| 2456 | .info = &(struct s3c24xx_uart_info) { |
| 2457 | .name = "Samsung S5PV210 UART", |
| 2458 | .type = PORT_S3C6400, |
| 2459 | .has_divslot = 1, |
| 2460 | .rx_fifomask = S5PV210_UFSTAT_RXMASK, |
| 2461 | .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, |
| 2462 | .rx_fifofull = S5PV210_UFSTAT_RXFULL, |
| 2463 | .tx_fifofull = S5PV210_UFSTAT_TXFULL, |
| 2464 | .tx_fifomask = S5PV210_UFSTAT_TXMASK, |
| 2465 | .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, |
| 2466 | .def_clk_sel = S3C2410_UCON_CLKSEL0, |
| 2467 | .num_clks = 2, |
| 2468 | .clksel_mask = S5PV210_UCON_CLKMASK, |
| 2469 | .clksel_shift = S5PV210_UCON_CLKSHIFT, |
| 2470 | }, |
| 2471 | .def_cfg = &(struct s3c2410_uartcfg) { |
| 2472 | .ucon = S5PV210_UCON_DEFAULT, |
| 2473 | .ufcon = S5PV210_UFCON_DEFAULT, |
| 2474 | }, |
| 2475 | .fifosize = { 256, 64, 16, 16 }, |
| 2476 | }; |
| 2477 | #define S5PV210_SERIAL_DRV_DATA ((kernel_ulong_t)&s5pv210_serial_drv_data) |
| 2478 | #else |
| 2479 | #define S5PV210_SERIAL_DRV_DATA (kernel_ulong_t)NULL |
| 2480 | #endif |
| 2481 | |
Chander Kashyap | 33f8813 | 2013-06-19 00:29:34 +0900 | [diff] [blame] | 2482 | #if defined(CONFIG_ARCH_EXYNOS) |
Chanwoo Choi | 31ec77a | 2014-12-02 17:49:54 +0900 | [diff] [blame] | 2483 | #define EXYNOS_COMMON_SERIAL_DRV_DATA \ |
| 2484 | .info = &(struct s3c24xx_uart_info) { \ |
| 2485 | .name = "Samsung Exynos UART", \ |
| 2486 | .type = PORT_S3C6400, \ |
| 2487 | .has_divslot = 1, \ |
| 2488 | .rx_fifomask = S5PV210_UFSTAT_RXMASK, \ |
| 2489 | .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \ |
| 2490 | .rx_fifofull = S5PV210_UFSTAT_RXFULL, \ |
| 2491 | .tx_fifofull = S5PV210_UFSTAT_TXFULL, \ |
| 2492 | .tx_fifomask = S5PV210_UFSTAT_TXMASK, \ |
| 2493 | .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, \ |
| 2494 | .def_clk_sel = S3C2410_UCON_CLKSEL0, \ |
| 2495 | .num_clks = 1, \ |
| 2496 | .clksel_mask = 0, \ |
| 2497 | .clksel_shift = 0, \ |
| 2498 | }, \ |
| 2499 | .def_cfg = &(struct s3c2410_uartcfg) { \ |
| 2500 | .ucon = S5PV210_UCON_DEFAULT, \ |
| 2501 | .ufcon = S5PV210_UFCON_DEFAULT, \ |
| 2502 | .has_fracval = 1, \ |
| 2503 | } \ |
| 2504 | |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2505 | static struct s3c24xx_serial_drv_data exynos4210_serial_drv_data = { |
Chanwoo Choi | 31ec77a | 2014-12-02 17:49:54 +0900 | [diff] [blame] | 2506 | EXYNOS_COMMON_SERIAL_DRV_DATA, |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2507 | .fifosize = { 256, 64, 16, 16 }, |
| 2508 | }; |
Chanwoo Choi | 31ec77a | 2014-12-02 17:49:54 +0900 | [diff] [blame] | 2509 | |
| 2510 | static struct s3c24xx_serial_drv_data exynos5433_serial_drv_data = { |
| 2511 | EXYNOS_COMMON_SERIAL_DRV_DATA, |
| 2512 | .fifosize = { 64, 256, 16, 256 }, |
| 2513 | }; |
| 2514 | |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2515 | #define EXYNOS4210_SERIAL_DRV_DATA ((kernel_ulong_t)&exynos4210_serial_drv_data) |
Chanwoo Choi | 31ec77a | 2014-12-02 17:49:54 +0900 | [diff] [blame] | 2516 | #define EXYNOS5433_SERIAL_DRV_DATA ((kernel_ulong_t)&exynos5433_serial_drv_data) |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2517 | #else |
| 2518 | #define EXYNOS4210_SERIAL_DRV_DATA (kernel_ulong_t)NULL |
Chanwoo Choi | 31ec77a | 2014-12-02 17:49:54 +0900 | [diff] [blame] | 2519 | #define EXYNOS5433_SERIAL_DRV_DATA (kernel_ulong_t)NULL |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2520 | #endif |
| 2521 | |
Krzysztof Kozlowski | 24ee4df | 2015-05-02 00:40:05 +0900 | [diff] [blame] | 2522 | static const struct platform_device_id s3c24xx_serial_driver_ids[] = { |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2523 | { |
| 2524 | .name = "s3c2410-uart", |
| 2525 | .driver_data = S3C2410_SERIAL_DRV_DATA, |
| 2526 | }, { |
| 2527 | .name = "s3c2412-uart", |
| 2528 | .driver_data = S3C2412_SERIAL_DRV_DATA, |
| 2529 | }, { |
| 2530 | .name = "s3c2440-uart", |
| 2531 | .driver_data = S3C2440_SERIAL_DRV_DATA, |
| 2532 | }, { |
| 2533 | .name = "s3c6400-uart", |
| 2534 | .driver_data = S3C6400_SERIAL_DRV_DATA, |
| 2535 | }, { |
| 2536 | .name = "s5pv210-uart", |
| 2537 | .driver_data = S5PV210_SERIAL_DRV_DATA, |
| 2538 | }, { |
| 2539 | .name = "exynos4210-uart", |
| 2540 | .driver_data = EXYNOS4210_SERIAL_DRV_DATA, |
Chanwoo Choi | 31ec77a | 2014-12-02 17:49:54 +0900 | [diff] [blame] | 2541 | }, { |
| 2542 | .name = "exynos5433-uart", |
| 2543 | .driver_data = EXYNOS5433_SERIAL_DRV_DATA, |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2544 | }, |
| 2545 | { }, |
| 2546 | }; |
| 2547 | MODULE_DEVICE_TABLE(platform, s3c24xx_serial_driver_ids); |
| 2548 | |
Thomas Abraham | 26c919e | 2011-11-06 22:10:44 +0530 | [diff] [blame] | 2549 | #ifdef CONFIG_OF |
| 2550 | static const struct of_device_id s3c24xx_uart_dt_match[] = { |
Heiko Stübner | 666ca0b | 2012-11-22 11:37:44 +0100 | [diff] [blame] | 2551 | { .compatible = "samsung,s3c2410-uart", |
| 2552 | .data = (void *)S3C2410_SERIAL_DRV_DATA }, |
| 2553 | { .compatible = "samsung,s3c2412-uart", |
| 2554 | .data = (void *)S3C2412_SERIAL_DRV_DATA }, |
| 2555 | { .compatible = "samsung,s3c2440-uart", |
| 2556 | .data = (void *)S3C2440_SERIAL_DRV_DATA }, |
| 2557 | { .compatible = "samsung,s3c6400-uart", |
| 2558 | .data = (void *)S3C6400_SERIAL_DRV_DATA }, |
| 2559 | { .compatible = "samsung,s5pv210-uart", |
| 2560 | .data = (void *)S5PV210_SERIAL_DRV_DATA }, |
Thomas Abraham | 26c919e | 2011-11-06 22:10:44 +0530 | [diff] [blame] | 2561 | { .compatible = "samsung,exynos4210-uart", |
Mark Brown | a169a88 | 2011-11-08 17:00:14 +0900 | [diff] [blame] | 2562 | .data = (void *)EXYNOS4210_SERIAL_DRV_DATA }, |
Chanwoo Choi | 31ec77a | 2014-12-02 17:49:54 +0900 | [diff] [blame] | 2563 | { .compatible = "samsung,exynos5433-uart", |
| 2564 | .data = (void *)EXYNOS5433_SERIAL_DRV_DATA }, |
Thomas Abraham | 26c919e | 2011-11-06 22:10:44 +0530 | [diff] [blame] | 2565 | {}, |
| 2566 | }; |
| 2567 | MODULE_DEVICE_TABLE(of, s3c24xx_uart_dt_match); |
Thomas Abraham | 26c919e | 2011-11-06 22:10:44 +0530 | [diff] [blame] | 2568 | #endif |
| 2569 | |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2570 | static struct platform_driver samsung_serial_driver = { |
| 2571 | .probe = s3c24xx_serial_probe, |
Bill Pemberton | 2d47b71 | 2012-11-19 13:21:34 -0500 | [diff] [blame] | 2572 | .remove = s3c24xx_serial_remove, |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2573 | .id_table = s3c24xx_serial_driver_ids, |
| 2574 | .driver = { |
| 2575 | .name = "samsung-uart", |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2576 | .pm = SERIAL_SAMSUNG_PM_OPS, |
Sachin Kamat | 905f4ba | 2013-01-07 09:50:42 +0530 | [diff] [blame] | 2577 | .of_match_table = of_match_ptr(s3c24xx_uart_dt_match), |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2578 | }, |
| 2579 | }; |
| 2580 | |
Tushar Behera | 6f134c3c | 2014-01-20 14:32:34 +0530 | [diff] [blame] | 2581 | module_platform_driver(samsung_serial_driver); |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2582 | |
Marek Szyprowski | c3bda29 | 2015-02-02 10:47:35 +0100 | [diff] [blame] | 2583 | #ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE |
Tomasz Figa | b94ba03 | 2015-01-23 14:47:41 +0100 | [diff] [blame] | 2584 | /* |
| 2585 | * Early console. |
| 2586 | */ |
| 2587 | |
| 2588 | struct samsung_early_console_data { |
| 2589 | u32 txfull_mask; |
| 2590 | }; |
| 2591 | |
| 2592 | static void samsung_early_busyuart(struct uart_port *port) |
| 2593 | { |
| 2594 | while (!(readl(port->membase + S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXFE)) |
| 2595 | ; |
| 2596 | } |
| 2597 | |
| 2598 | static void samsung_early_busyuart_fifo(struct uart_port *port) |
| 2599 | { |
| 2600 | struct samsung_early_console_data *data = port->private_data; |
| 2601 | |
| 2602 | while (readl(port->membase + S3C2410_UFSTAT) & data->txfull_mask) |
| 2603 | ; |
| 2604 | } |
| 2605 | |
| 2606 | static void samsung_early_putc(struct uart_port *port, int c) |
| 2607 | { |
| 2608 | if (readl(port->membase + S3C2410_UFCON) & S3C2410_UFCON_FIFOMODE) |
| 2609 | samsung_early_busyuart_fifo(port); |
| 2610 | else |
| 2611 | samsung_early_busyuart(port); |
| 2612 | |
| 2613 | writeb(c, port->membase + S3C2410_UTXH); |
| 2614 | } |
| 2615 | |
Greg Kroah-Hartman | 90ece85 | 2019-12-10 15:37:04 +0100 | [diff] [blame^] | 2616 | static void samsung_early_write(struct console *con, const char *s, |
| 2617 | unsigned int n) |
Tomasz Figa | b94ba03 | 2015-01-23 14:47:41 +0100 | [diff] [blame] | 2618 | { |
| 2619 | struct earlycon_device *dev = con->data; |
| 2620 | |
| 2621 | uart_console_write(&dev->port, s, n, samsung_early_putc); |
| 2622 | } |
| 2623 | |
| 2624 | static int __init samsung_early_console_setup(struct earlycon_device *device, |
| 2625 | const char *opt) |
| 2626 | { |
| 2627 | if (!device->port.membase) |
| 2628 | return -ENODEV; |
| 2629 | |
| 2630 | device->con->write = samsung_early_write; |
| 2631 | return 0; |
| 2632 | } |
| 2633 | |
| 2634 | /* S3C2410 */ |
| 2635 | static struct samsung_early_console_data s3c2410_early_console_data = { |
| 2636 | .txfull_mask = S3C2410_UFSTAT_TXFULL, |
| 2637 | }; |
| 2638 | |
| 2639 | static int __init s3c2410_early_console_setup(struct earlycon_device *device, |
| 2640 | const char *opt) |
| 2641 | { |
| 2642 | device->port.private_data = &s3c2410_early_console_data; |
| 2643 | return samsung_early_console_setup(device, opt); |
| 2644 | } |
| 2645 | OF_EARLYCON_DECLARE(s3c2410, "samsung,s3c2410-uart", |
| 2646 | s3c2410_early_console_setup); |
Tomasz Figa | b94ba03 | 2015-01-23 14:47:41 +0100 | [diff] [blame] | 2647 | |
| 2648 | /* S3C2412, S3C2440, S3C64xx */ |
| 2649 | static struct samsung_early_console_data s3c2440_early_console_data = { |
| 2650 | .txfull_mask = S3C2440_UFSTAT_TXFULL, |
| 2651 | }; |
| 2652 | |
| 2653 | static int __init s3c2440_early_console_setup(struct earlycon_device *device, |
| 2654 | const char *opt) |
| 2655 | { |
| 2656 | device->port.private_data = &s3c2440_early_console_data; |
| 2657 | return samsung_early_console_setup(device, opt); |
| 2658 | } |
| 2659 | OF_EARLYCON_DECLARE(s3c2412, "samsung,s3c2412-uart", |
| 2660 | s3c2440_early_console_setup); |
| 2661 | OF_EARLYCON_DECLARE(s3c2440, "samsung,s3c2440-uart", |
| 2662 | s3c2440_early_console_setup); |
| 2663 | OF_EARLYCON_DECLARE(s3c6400, "samsung,s3c6400-uart", |
| 2664 | s3c2440_early_console_setup); |
Tomasz Figa | b94ba03 | 2015-01-23 14:47:41 +0100 | [diff] [blame] | 2665 | |
| 2666 | /* S5PV210, EXYNOS */ |
| 2667 | static struct samsung_early_console_data s5pv210_early_console_data = { |
| 2668 | .txfull_mask = S5PV210_UFSTAT_TXFULL, |
| 2669 | }; |
| 2670 | |
| 2671 | static int __init s5pv210_early_console_setup(struct earlycon_device *device, |
| 2672 | const char *opt) |
| 2673 | { |
| 2674 | device->port.private_data = &s5pv210_early_console_data; |
| 2675 | return samsung_early_console_setup(device, opt); |
| 2676 | } |
| 2677 | OF_EARLYCON_DECLARE(s5pv210, "samsung,s5pv210-uart", |
| 2678 | s5pv210_early_console_setup); |
| 2679 | OF_EARLYCON_DECLARE(exynos4210, "samsung,exynos4210-uart", |
| 2680 | s5pv210_early_console_setup); |
Marek Szyprowski | c3bda29 | 2015-02-02 10:47:35 +0100 | [diff] [blame] | 2681 | #endif |
Tomasz Figa | b94ba03 | 2015-01-23 14:47:41 +0100 | [diff] [blame] | 2682 | |
Thomas Abraham | da12150 | 2011-11-02 19:23:25 +0900 | [diff] [blame] | 2683 | MODULE_ALIAS("platform:samsung-uart"); |
Ben Dooks | b497549 | 2008-07-03 12:32:51 +0100 | [diff] [blame] | 2684 | MODULE_DESCRIPTION("Samsung SoC Serial port driver"); |
| 2685 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); |
| 2686 | MODULE_LICENSE("GPL v2"); |