1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Synopsys DesignWare 8250 driver. 4 * 5 * Copyright 2011 Picochip, Jamie Iles. 6 * Copyright 2013 Intel Corporation 7 * 8 * The Synopsys DesignWare 8250 has an extra feature whereby it detects if the 9 * LCR is written whilst busy. If it is, then a busy detect interrupt is 10 * raised, the LCR needs to be rewritten and the uart status register read. 11 */ 12 #include <linux/clk.h> 13 #include <linux/delay.h> 14 #include <linux/device.h> 15 #include <linux/io.h> 16 #include <linux/mod_devicetable.h> 17 #include <linux/module.h> 18 #include <linux/notifier.h> 19 #include <linux/platform_device.h> 20 #include <linux/pm_runtime.h> 21 #include <linux/property.h> 22 #include <linux/reset.h> 23 #include <linux/slab.h> 24 #include <linux/workqueue.h> 25 26 #include <asm/byteorder.h> 27 28 #include <linux/serial_8250.h> 29 #include <linux/serial_reg.h> 30 31 #include "8250_dwlib.h" 32 33 /* Offsets for the DesignWare specific registers */ 34 #define DW_UART_USR 0x1f /* UART Status Register */ 35 #define DW_UART_DMASA 0xa8 /* DMA Software Ack */ 36 37 #define OCTEON_UART_USR 0x27 /* UART Status Register */ 38 39 #define RZN1_UART_TDMACR 0x10c /* DMA Control Register Transmit Mode */ 40 #define RZN1_UART_RDMACR 0x110 /* DMA Control Register Receive Mode */ 41 42 /* DesignWare specific register fields */ 43 #define DW_UART_MCR_SIRE BIT(6) 44 45 /* Renesas specific register fields */ 46 #define RZN1_UART_xDMACR_DMA_EN BIT(0) 47 #define RZN1_UART_xDMACR_1_WORD_BURST (0 << 1) 48 #define RZN1_UART_xDMACR_4_WORD_BURST (1 << 1) 49 #define RZN1_UART_xDMACR_8_WORD_BURST (2 << 1) 50 #define RZN1_UART_xDMACR_BLK_SZ(x) ((x) << 3) 51 52 /* Quirks */ 53 #define DW_UART_QUIRK_OCTEON BIT(0) 54 #define DW_UART_QUIRK_ARMADA_38X BIT(1) 55 #define DW_UART_QUIRK_SKIP_SET_RATE BIT(2) 56 #define DW_UART_QUIRK_IS_DMA_FC BIT(3) 57 #define DW_UART_QUIRK_APMC0D08 BIT(4) 58 59 static inline struct dw8250_data *clk_to_dw8250_data(struct notifier_block *nb) 60 { 61 return container_of(nb, struct dw8250_data, clk_notifier); 62 } 63 64 static inline struct dw8250_data *work_to_dw8250_data(struct work_struct *work) 65 { 66 return container_of(work, struct dw8250_data, clk_work); 67 } 68 69 static inline int dw8250_modify_msr(struct uart_port *p, int offset, int value) 70 { 71 struct dw8250_data *d = to_dw8250_data(p->private_data); 72 73 /* Override any modem control signals if needed */ 74 if (offset == UART_MSR) { 75 value |= d->msr_mask_on; 76 value &= ~d->msr_mask_off; 77 } 78 79 return value; 80 } 81 82 static void dw8250_force_idle(struct uart_port *p) 83 { 84 struct uart_8250_port *up = up_to_u8250p(p); 85 unsigned int lsr; 86 87 serial8250_clear_and_reinit_fifos(up); 88 89 /* 90 * With PSLVERR_RESP_EN parameter set to 1, the device generates an 91 * error response when an attempt to read an empty RBR with FIFO 92 * enabled. 93 */ 94 if (up->fcr & UART_FCR_ENABLE_FIFO) { 95 lsr = p->serial_in(p, UART_LSR); 96 if (!(lsr & UART_LSR_DR)) 97 return; 98 } 99 100 (void)p->serial_in(p, UART_RX); 101 } 102 103 static void dw8250_check_lcr(struct uart_port *p, int offset, int value) 104 { 105 struct dw8250_data *d = to_dw8250_data(p->private_data); 106 void __iomem *addr = p->membase + (offset << p->regshift); 107 int tries = 1000; 108 109 if (offset != UART_LCR || d->uart_16550_compatible) 110 return; 111 112 /* Make sure LCR write wasn't ignored */ 113 while (tries--) { 114 unsigned int lcr = p->serial_in(p, offset); 115 116 if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR)) 117 return; 118 119 dw8250_force_idle(p); 120 121 #ifdef CONFIG_64BIT 122 if (p->type == PORT_OCTEON) 123 __raw_writeq(value & 0xff, addr); 124 else 125 #endif 126 if (p->iotype == UPIO_MEM32) 127 writel(value, addr); 128 else if (p->iotype == UPIO_MEM32BE) 129 iowrite32be(value, addr); 130 else 131 writeb(value, addr); 132 } 133 /* 134 * FIXME: this deadlocks if port->lock is already held 135 * dev_err(p->dev, "Couldn't set LCR to %d\n", value); 136 */ 137 } 138 139 /* Returns once the transmitter is empty or we run out of retries */ 140 static void dw8250_tx_wait_empty(struct uart_port *p) 141 { 142 struct uart_8250_port *up = up_to_u8250p(p); 143 unsigned int tries = 20000; 144 unsigned int delay_threshold = tries - 1000; 145 unsigned int lsr; 146 147 while (tries--) { 148 lsr = readb (p->membase + (UART_LSR << p->regshift)); 149 up->lsr_saved_flags |= lsr & up->lsr_save_mask; 150 151 if (lsr & UART_LSR_TEMT) 152 break; 153 154 /* The device is first given a chance to empty without delay, 155 * to avoid slowdowns at high bitrates. If after 1000 tries 156 * the buffer has still not emptied, allow more time for low- 157 * speed links. */ 158 if (tries < delay_threshold) 159 udelay (1); 160 } 161 } 162 163 static void dw8250_serial_out(struct uart_port *p, int offset, int value) 164 { 165 writeb(value, p->membase + (offset << p->regshift)); 166 dw8250_check_lcr(p, offset, value); 167 } 168 169 static void dw8250_serial_out38x(struct uart_port *p, int offset, int value) 170 { 171 /* Allow the TX to drain before we reconfigure */ 172 if (offset == UART_LCR) 173 dw8250_tx_wait_empty(p); 174 175 dw8250_serial_out(p, offset, value); 176 } 177 178 static unsigned int dw8250_serial_in(struct uart_port *p, int offset) 179 { 180 unsigned int value = readb(p->membase + (offset << p->regshift)); 181 182 return dw8250_modify_msr(p, offset, value); 183 } 184 185 #ifdef CONFIG_64BIT 186 static unsigned int dw8250_serial_inq(struct uart_port *p, int offset) 187 { 188 u8 value = __raw_readq(p->membase + (offset << p->regshift)); 189 190 return dw8250_modify_msr(p, offset, value); 191 } 192 193 static void dw8250_serial_outq(struct uart_port *p, int offset, int value) 194 { 195 value &= 0xff; 196 __raw_writeq(value, p->membase + (offset << p->regshift)); 197 /* Read back to ensure register write ordering. */ 198 __raw_readq(p->membase + (UART_LCR << p->regshift)); 199 200 dw8250_check_lcr(p, offset, value); 201 } 202 #endif /* CONFIG_64BIT */ 203 204 static void dw8250_serial_out32(struct uart_port *p, int offset, int value) 205 { 206 writel(value, p->membase + (offset << p->regshift)); 207 dw8250_check_lcr(p, offset, value); 208 } 209 210 static unsigned int dw8250_serial_in32(struct uart_port *p, int offset) 211 { 212 unsigned int value = readl(p->membase + (offset << p->regshift)); 213 214 return dw8250_modify_msr(p, offset, value); 215 } 216 217 static void dw8250_serial_out32be(struct uart_port *p, int offset, int value) 218 { 219 iowrite32be(value, p->membase + (offset << p->regshift)); 220 dw8250_check_lcr(p, offset, value); 221 } 222 223 static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset) 224 { 225 unsigned int value = ioread32be(p->membase + (offset << p->regshift)); 226 227 return dw8250_modify_msr(p, offset, value); 228 } 229 230 231 static int dw8250_handle_irq(struct uart_port *p) 232 { 233 struct uart_8250_port *up = up_to_u8250p(p); 234 struct dw8250_data *d = to_dw8250_data(p->private_data); 235 unsigned int iir = p->serial_in(p, UART_IIR); 236 bool rx_timeout = (iir & 0x3f) == UART_IIR_RX_TIMEOUT; 237 unsigned int quirks = d->pdata->quirks; 238 unsigned int status; 239 unsigned long flags; 240 241 /* 242 * There are ways to get Designware-based UARTs into a state where 243 * they are asserting UART_IIR_RX_TIMEOUT but there is no actual 244 * data available. If we see such a case then we'll do a bogus 245 * read. If we don't do this then the "RX TIMEOUT" interrupt will 246 * fire forever. 247 * 248 * This problem has only been observed so far when not in DMA mode 249 * so we limit the workaround only to non-DMA mode. 250 */ 251 if (!up->dma && rx_timeout) { 252 uart_port_lock_irqsave(p, &flags); 253 status = serial_lsr_in(up); 254 255 if (!(status & (UART_LSR_DR | UART_LSR_BI))) 256 (void) p->serial_in(p, UART_RX); 257 258 uart_port_unlock_irqrestore(p, flags); 259 } 260 261 /* Manually stop the Rx DMA transfer when acting as flow controller */ 262 if (quirks & DW_UART_QUIRK_IS_DMA_FC && up->dma && up->dma->rx_running && rx_timeout) { 263 uart_port_lock_irqsave(p, &flags); 264 status = serial_lsr_in(up); 265 uart_port_unlock_irqrestore(p, flags); 266 267 if (status & (UART_LSR_DR | UART_LSR_BI)) { 268 dw8250_writel_ext(p, RZN1_UART_RDMACR, 0); 269 dw8250_writel_ext(p, DW_UART_DMASA, 1); 270 } 271 } 272 273 if (serial8250_handle_irq(p, iir)) 274 return 1; 275 276 if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) { 277 /* Clear the USR */ 278 (void)p->serial_in(p, d->pdata->usr_reg); 279 280 return 1; 281 } 282 283 return 0; 284 } 285 286 static void dw8250_clk_work_cb(struct work_struct *work) 287 { 288 struct dw8250_data *d = work_to_dw8250_data(work); 289 struct uart_8250_port *up; 290 unsigned long rate; 291 292 rate = clk_get_rate(d->clk); 293 if (rate <= 0) 294 return; 295 296 up = serial8250_get_port(d->data.line); 297 298 serial8250_update_uartclk(&up->port, rate); 299 } 300 301 static int dw8250_clk_notifier_cb(struct notifier_block *nb, 302 unsigned long event, void *data) 303 { 304 struct dw8250_data *d = clk_to_dw8250_data(nb); 305 306 /* 307 * We have no choice but to defer the uartclk update due to two 308 * deadlocks. First one is caused by a recursive mutex lock which 309 * happens when clk_set_rate() is called from dw8250_set_termios(). 310 * Second deadlock is more tricky and is caused by an inverted order of 311 * the clk and tty-port mutexes lock. It happens if clock rate change 312 * is requested asynchronously while set_termios() is executed between 313 * tty-port mutex lock and clk_set_rate() function invocation and 314 * vise-versa. Anyway if we didn't have the reference clock alteration 315 * in the dw8250_set_termios() method we wouldn't have needed this 316 * deferred event handling complication. 317 */ 318 if (event == POST_RATE_CHANGE) { 319 queue_work(system_unbound_wq, &d->clk_work); 320 return NOTIFY_OK; 321 } 322 323 return NOTIFY_DONE; 324 } 325 326 static void 327 dw8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) 328 { 329 if (!state) 330 pm_runtime_get_sync(port->dev); 331 332 serial8250_do_pm(port, state, old); 333 334 if (state) 335 pm_runtime_put_sync_suspend(port->dev); 336 } 337 338 static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios, 339 const struct ktermios *old) 340 { 341 unsigned long newrate = tty_termios_baud_rate(termios) * 16; 342 struct dw8250_data *d = to_dw8250_data(p->private_data); 343 long rate; 344 int ret; 345 346 clk_disable_unprepare(d->clk); 347 rate = clk_round_rate(d->clk, newrate); 348 if (rate > 0) { 349 /* 350 * Note that any clock-notifer worker will block in 351 * serial8250_update_uartclk() until we are done. 352 */ 353 ret = clk_set_rate(d->clk, newrate); 354 if (!ret) 355 p->uartclk = rate; 356 } 357 clk_prepare_enable(d->clk); 358 359 dw8250_do_set_termios(p, termios, old); 360 } 361 362 static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios) 363 { 364 struct uart_8250_port *up = up_to_u8250p(p); 365 unsigned int mcr = p->serial_in(p, UART_MCR); 366 367 if (up->capabilities & UART_CAP_IRDA) { 368 if (termios->c_line == N_IRDA) 369 mcr |= DW_UART_MCR_SIRE; 370 else 371 mcr &= ~DW_UART_MCR_SIRE; 372 373 p->serial_out(p, UART_MCR, mcr); 374 } 375 serial8250_do_set_ldisc(p, termios); 376 } 377 378 /* 379 * dw8250_fallback_dma_filter will prevent the UART from getting just any free 380 * channel on platforms that have DMA engines, but don't have any channels 381 * assigned to the UART. 382 * 383 * REVISIT: This is a work around for limitation in the DMA Engine API. Once the 384 * core problem is fixed, this function is no longer needed. 385 */ 386 static bool dw8250_fallback_dma_filter(struct dma_chan *chan, void *param) 387 { 388 return false; 389 } 390 391 static bool dw8250_idma_filter(struct dma_chan *chan, void *param) 392 { 393 return param == chan->device->dev; 394 } 395 396 static u32 dw8250_rzn1_get_dmacr_burst(int max_burst) 397 { 398 if (max_burst >= 8) 399 return RZN1_UART_xDMACR_8_WORD_BURST; 400 else if (max_burst >= 4) 401 return RZN1_UART_xDMACR_4_WORD_BURST; 402 else 403 return RZN1_UART_xDMACR_1_WORD_BURST; 404 } 405 406 static void dw8250_prepare_tx_dma(struct uart_8250_port *p) 407 { 408 struct uart_port *up = &p->port; 409 struct uart_8250_dma *dma = p->dma; 410 u32 val; 411 412 dw8250_writel_ext(up, RZN1_UART_TDMACR, 0); 413 val = dw8250_rzn1_get_dmacr_burst(dma->txconf.dst_maxburst) | 414 RZN1_UART_xDMACR_BLK_SZ(dma->tx_size) | 415 RZN1_UART_xDMACR_DMA_EN; 416 dw8250_writel_ext(up, RZN1_UART_TDMACR, val); 417 } 418 419 static void dw8250_prepare_rx_dma(struct uart_8250_port *p) 420 { 421 struct uart_port *up = &p->port; 422 struct uart_8250_dma *dma = p->dma; 423 u32 val; 424 425 dw8250_writel_ext(up, RZN1_UART_RDMACR, 0); 426 val = dw8250_rzn1_get_dmacr_burst(dma->rxconf.src_maxburst) | 427 RZN1_UART_xDMACR_BLK_SZ(dma->rx_size) | 428 RZN1_UART_xDMACR_DMA_EN; 429 dw8250_writel_ext(up, RZN1_UART_RDMACR, val); 430 } 431 432 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) 433 { 434 unsigned int quirks = data->pdata ? data->pdata->quirks : 0; 435 436 #ifdef CONFIG_64BIT 437 if (quirks & DW_UART_QUIRK_OCTEON) { 438 p->serial_in = dw8250_serial_inq; 439 p->serial_out = dw8250_serial_outq; 440 p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE; 441 p->type = PORT_OCTEON; 442 data->skip_autocfg = true; 443 } 444 #endif 445 446 if (quirks & DW_UART_QUIRK_ARMADA_38X) 447 p->serial_out = dw8250_serial_out38x; 448 if (quirks & DW_UART_QUIRK_SKIP_SET_RATE) 449 p->set_termios = dw8250_do_set_termios; 450 if (quirks & DW_UART_QUIRK_IS_DMA_FC) { 451 data->data.dma.txconf.device_fc = 1; 452 data->data.dma.rxconf.device_fc = 1; 453 data->data.dma.prepare_tx_dma = dw8250_prepare_tx_dma; 454 data->data.dma.prepare_rx_dma = dw8250_prepare_rx_dma; 455 } 456 if (quirks & DW_UART_QUIRK_APMC0D08) { 457 p->iotype = UPIO_MEM32; 458 p->regshift = 2; 459 p->serial_in = dw8250_serial_in32; 460 data->uart_16550_compatible = true; 461 } 462 463 /* Platforms with iDMA 64-bit */ 464 if (platform_get_resource_byname(to_platform_device(p->dev), 465 IORESOURCE_MEM, "lpss_priv")) { 466 data->data.dma.rx_param = p->dev->parent; 467 data->data.dma.tx_param = p->dev->parent; 468 data->data.dma.fn = dw8250_idma_filter; 469 } 470 } 471 472 static void dw8250_reset_control_assert(void *data) 473 { 474 reset_control_assert(data); 475 } 476 477 static int dw8250_probe(struct platform_device *pdev) 478 { 479 struct uart_8250_port uart = {}, *up = &uart; 480 struct uart_port *p = &up->port; 481 struct device *dev = &pdev->dev; 482 struct dw8250_data *data; 483 struct resource *regs; 484 int err; 485 486 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 487 if (!regs) 488 return dev_err_probe(dev, -EINVAL, "no registers defined\n"); 489 490 spin_lock_init(&p->lock); 491 p->handle_irq = dw8250_handle_irq; 492 p->pm = dw8250_do_pm; 493 p->type = PORT_8250; 494 p->flags = UPF_FIXED_PORT; 495 p->dev = dev; 496 p->set_ldisc = dw8250_set_ldisc; 497 p->set_termios = dw8250_set_termios; 498 499 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 500 if (!data) 501 return -ENOMEM; 502 503 data->data.dma.fn = dw8250_fallback_dma_filter; 504 data->pdata = device_get_match_data(p->dev); 505 p->private_data = &data->data; 506 507 data->uart_16550_compatible = device_property_read_bool(dev, 508 "snps,uart-16550-compatible"); 509 510 p->mapbase = regs->start; 511 p->mapsize = resource_size(regs); 512 513 p->membase = devm_ioremap(dev, p->mapbase, p->mapsize); 514 if (!p->membase) 515 return -ENOMEM; 516 517 err = uart_read_port_properties(p); 518 /* no interrupt -> fall back to polling */ 519 if (err == -ENXIO) 520 err = 0; 521 if (err) 522 return err; 523 524 switch (p->iotype) { 525 case UPIO_MEM: 526 p->serial_in = dw8250_serial_in; 527 p->serial_out = dw8250_serial_out; 528 break; 529 case UPIO_MEM32: 530 p->serial_in = dw8250_serial_in32; 531 p->serial_out = dw8250_serial_out32; 532 break; 533 case UPIO_MEM32BE: 534 p->serial_in = dw8250_serial_in32be; 535 p->serial_out = dw8250_serial_out32be; 536 break; 537 default: 538 return -ENODEV; 539 } 540 541 if (device_property_read_bool(dev, "dcd-override")) { 542 /* Always report DCD as active */ 543 data->msr_mask_on |= UART_MSR_DCD; 544 data->msr_mask_off |= UART_MSR_DDCD; 545 } 546 547 if (device_property_read_bool(dev, "dsr-override")) { 548 /* Always report DSR as active */ 549 data->msr_mask_on |= UART_MSR_DSR; 550 data->msr_mask_off |= UART_MSR_DDSR; 551 } 552 553 if (device_property_read_bool(dev, "cts-override")) { 554 /* Always report CTS as active */ 555 data->msr_mask_on |= UART_MSR_CTS; 556 data->msr_mask_off |= UART_MSR_DCTS; 557 } 558 559 if (device_property_read_bool(dev, "ri-override")) { 560 /* Always report Ring indicator as inactive */ 561 data->msr_mask_off |= UART_MSR_RI; 562 data->msr_mask_off |= UART_MSR_TERI; 563 } 564 565 /* If there is separate baudclk, get the rate from it. */ 566 data->clk = devm_clk_get_optional_enabled(dev, "baudclk"); 567 if (data->clk == NULL) 568 data->clk = devm_clk_get_optional_enabled(dev, NULL); 569 if (IS_ERR(data->clk)) 570 return dev_err_probe(dev, PTR_ERR(data->clk), 571 "failed to get baudclk\n"); 572 573 INIT_WORK(&data->clk_work, dw8250_clk_work_cb); 574 data->clk_notifier.notifier_call = dw8250_clk_notifier_cb; 575 576 if (data->clk) 577 p->uartclk = clk_get_rate(data->clk); 578 579 /* If no clock rate is defined, fail. */ 580 if (!p->uartclk) 581 return dev_err_probe(dev, -EINVAL, "clock rate not defined\n"); 582 583 data->pclk = devm_clk_get_optional_enabled(dev, "apb_pclk"); 584 if (IS_ERR(data->pclk)) 585 return PTR_ERR(data->pclk); 586 587 data->rst = devm_reset_control_get_optional_exclusive(dev, NULL); 588 if (IS_ERR(data->rst)) 589 return PTR_ERR(data->rst); 590 591 reset_control_deassert(data->rst); 592 593 err = devm_add_action_or_reset(dev, dw8250_reset_control_assert, data->rst); 594 if (err) 595 return err; 596 597 dw8250_quirks(p, data); 598 599 /* If the Busy Functionality is not implemented, don't handle it */ 600 if (data->uart_16550_compatible) 601 p->handle_irq = NULL; 602 603 if (!data->skip_autocfg) 604 dw8250_setup_port(p); 605 606 /* If we have a valid fifosize, try hooking up DMA */ 607 if (p->fifosize) { 608 data->data.dma.rxconf.src_maxburst = p->fifosize / 4; 609 data->data.dma.txconf.dst_maxburst = p->fifosize / 4; 610 up->dma = &data->data.dma; 611 } 612 613 data->data.line = serial8250_register_8250_port(up); 614 if (data->data.line < 0) 615 return data->data.line; 616 617 /* 618 * Some platforms may provide a reference clock shared between several 619 * devices. In this case any clock state change must be known to the 620 * UART port at least post factum. 621 */ 622 if (data->clk) { 623 err = clk_notifier_register(data->clk, &data->clk_notifier); 624 if (err) 625 return dev_err_probe(dev, err, "Failed to set the clock notifier\n"); 626 queue_work(system_unbound_wq, &data->clk_work); 627 } 628 629 platform_set_drvdata(pdev, data); 630 631 pm_runtime_set_active(dev); 632 pm_runtime_enable(dev); 633 634 return 0; 635 } 636 637 static void dw8250_remove(struct platform_device *pdev) 638 { 639 struct dw8250_data *data = platform_get_drvdata(pdev); 640 struct device *dev = &pdev->dev; 641 642 pm_runtime_get_sync(dev); 643 644 if (data->clk) { 645 clk_notifier_unregister(data->clk, &data->clk_notifier); 646 647 flush_work(&data->clk_work); 648 } 649 650 serial8250_unregister_port(data->data.line); 651 652 pm_runtime_disable(dev); 653 pm_runtime_put_noidle(dev); 654 } 655 656 static int dw8250_suspend(struct device *dev) 657 { 658 struct dw8250_data *data = dev_get_drvdata(dev); 659 660 serial8250_suspend_port(data->data.line); 661 662 return 0; 663 } 664 665 static int dw8250_resume(struct device *dev) 666 { 667 struct dw8250_data *data = dev_get_drvdata(dev); 668 669 serial8250_resume_port(data->data.line); 670 671 return 0; 672 } 673 674 static int dw8250_runtime_suspend(struct device *dev) 675 { 676 struct dw8250_data *data = dev_get_drvdata(dev); 677 678 clk_disable_unprepare(data->clk); 679 680 clk_disable_unprepare(data->pclk); 681 682 return 0; 683 } 684 685 static int dw8250_runtime_resume(struct device *dev) 686 { 687 struct dw8250_data *data = dev_get_drvdata(dev); 688 689 clk_prepare_enable(data->pclk); 690 691 clk_prepare_enable(data->clk); 692 693 return 0; 694 } 695 696 static const struct dev_pm_ops dw8250_pm_ops = { 697 SYSTEM_SLEEP_PM_OPS(dw8250_suspend, dw8250_resume) 698 RUNTIME_PM_OPS(dw8250_runtime_suspend, dw8250_runtime_resume, NULL) 699 }; 700 701 static const struct dw8250_platform_data dw8250_dw_apb = { 702 .usr_reg = DW_UART_USR, 703 }; 704 705 static const struct dw8250_platform_data dw8250_octeon_3860_data = { 706 .usr_reg = OCTEON_UART_USR, 707 .quirks = DW_UART_QUIRK_OCTEON, 708 }; 709 710 static const struct dw8250_platform_data dw8250_armada_38x_data = { 711 .usr_reg = DW_UART_USR, 712 .quirks = DW_UART_QUIRK_ARMADA_38X, 713 }; 714 715 static const struct dw8250_platform_data dw8250_renesas_rzn1_data = { 716 .usr_reg = DW_UART_USR, 717 .cpr_val = 0x00012f32, 718 .quirks = DW_UART_QUIRK_IS_DMA_FC, 719 }; 720 721 static const struct dw8250_platform_data dw8250_starfive_jh7100_data = { 722 .usr_reg = DW_UART_USR, 723 .quirks = DW_UART_QUIRK_SKIP_SET_RATE, 724 }; 725 726 static const struct of_device_id dw8250_of_match[] = { 727 { .compatible = "snps,dw-apb-uart", .data = &dw8250_dw_apb }, 728 { .compatible = "cavium,octeon-3860-uart", .data = &dw8250_octeon_3860_data }, 729 { .compatible = "marvell,armada-38x-uart", .data = &dw8250_armada_38x_data }, 730 { .compatible = "renesas,rzn1-uart", .data = &dw8250_renesas_rzn1_data }, 731 { .compatible = "starfive,jh7100-uart", .data = &dw8250_starfive_jh7100_data }, 732 { /* Sentinel */ } 733 }; 734 MODULE_DEVICE_TABLE(of, dw8250_of_match); 735 736 static const struct dw8250_platform_data dw8250_apmc0d08 = { 737 .usr_reg = DW_UART_USR, 738 .quirks = DW_UART_QUIRK_APMC0D08, 739 }; 740 741 static const struct acpi_device_id dw8250_acpi_match[] = { 742 { "80860F0A", (kernel_ulong_t)&dw8250_dw_apb }, 743 { "8086228A", (kernel_ulong_t)&dw8250_dw_apb }, 744 { "AMD0020", (kernel_ulong_t)&dw8250_dw_apb }, 745 { "AMDI0020", (kernel_ulong_t)&dw8250_dw_apb }, 746 { "AMDI0022", (kernel_ulong_t)&dw8250_dw_apb }, 747 { "APMC0D08", (kernel_ulong_t)&dw8250_apmc0d08 }, 748 { "BRCM2032", (kernel_ulong_t)&dw8250_dw_apb }, 749 { "HISI0031", (kernel_ulong_t)&dw8250_dw_apb }, 750 { "INT33C4", (kernel_ulong_t)&dw8250_dw_apb }, 751 { "INT33C5", (kernel_ulong_t)&dw8250_dw_apb }, 752 { "INT3434", (kernel_ulong_t)&dw8250_dw_apb }, 753 { "INT3435", (kernel_ulong_t)&dw8250_dw_apb }, 754 { "INTC10EE", (kernel_ulong_t)&dw8250_dw_apb }, 755 { }, 756 }; 757 MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match); 758 759 static struct platform_driver dw8250_platform_driver = { 760 .driver = { 761 .name = "dw-apb-uart", 762 .pm = pm_ptr(&dw8250_pm_ops), 763 .of_match_table = dw8250_of_match, 764 .acpi_match_table = dw8250_acpi_match, 765 }, 766 .probe = dw8250_probe, 767 .remove_new = dw8250_remove, 768 }; 769 770 module_platform_driver(dw8250_platform_driver); 771 772 MODULE_AUTHOR("Jamie Iles"); 773 MODULE_LICENSE("GPL"); 774 MODULE_DESCRIPTION("Synopsys DesignWare 8250 serial port driver"); 775 MODULE_ALIAS("platform:dw-apb-uart"); 776