cpm_uart_cpm1.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Driver for CPM (SCC/SMC) serial ports; CPM1 definitions
  4. *
  5. * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
  6. * Pantelis Antoniou (panto@intracom.gr) (CPM1)
  7. *
  8. * Copyright (C) 2004 Freescale Semiconductor, Inc.
  9. * (C) 2004 Intracom, S.A.
  10. * (C) 2006 MontaVista Software, Inc.
  11. * Vitaly Bordug <vbordug@ru.mvista.com>
  12. */
  13. #include <linux/module.h>
  14. #include <linux/tty.h>
  15. #include <linux/gfp.h>
  16. #include <linux/ioport.h>
  17. #include <linux/serial.h>
  18. #include <linux/console.h>
  19. #include <linux/sysrq.h>
  20. #include <linux/device.h>
  21. #include <linux/memblock.h>
  22. #include <linux/dma-mapping.h>
  23. #include <asm/io.h>
  24. #include <asm/irq.h>
  25. #include <asm/fs_pd.h>
  26. #include <linux/serial_core.h>
  27. #include <linux/kernel.h>
  28. #include <linux/of.h>
  29. #include <linux/of_address.h>
  30. #include "cpm_uart.h"
  31. /**************************************************************/
  32. void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
  33. {
  34. cpm_command(port->command, cmd);
  35. }
  36. void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
  37. struct device_node *np)
  38. {
  39. return of_iomap(np, 1);
  40. }
  41. void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
  42. {
  43. iounmap(pram);
  44. }
  45. /*
  46. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  47. * receive buffer descriptors from dual port ram, and a character
  48. * buffer area from host mem. If we are allocating for the console we need
  49. * to do it from bootmem
  50. */
  51. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  52. {
  53. int dpmemsz, memsz;
  54. u8 *dp_mem;
  55. unsigned long dp_offset;
  56. u8 *mem_addr;
  57. dma_addr_t dma_addr = 0;
  58. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  59. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  60. dp_offset = cpm_dpalloc(dpmemsz, 8);
  61. if (IS_ERR_VALUE(dp_offset)) {
  62. printk(KERN_ERR
  63. "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
  64. return -ENOMEM;
  65. }
  66. dp_mem = cpm_dpram_addr(dp_offset);
  67. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  68. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  69. if (is_con) {
  70. /* was hostalloc but changed cause it blows away the */
  71. /* large tlb mapping when pinning the kernel area */
  72. mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
  73. dma_addr = (u32)cpm_dpram_phys(mem_addr);
  74. } else
  75. mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
  76. GFP_KERNEL);
  77. if (mem_addr == NULL) {
  78. cpm_dpfree(dp_offset);
  79. printk(KERN_ERR
  80. "cpm_uart_cpm1.c: could not allocate coherent memory\n");
  81. return -ENOMEM;
  82. }
  83. pinfo->dp_addr = dp_offset;
  84. pinfo->mem_addr = mem_addr; /* virtual address*/
  85. pinfo->dma_addr = dma_addr; /* physical address*/
  86. pinfo->mem_size = memsz;
  87. pinfo->rx_buf = mem_addr;
  88. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  89. * pinfo->rx_fifosize);
  90. pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
  91. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  92. return 0;
  93. }
  94. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  95. {
  96. dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  97. pinfo->rx_fifosize) +
  98. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  99. pinfo->tx_fifosize), pinfo->mem_addr,
  100. pinfo->dma_addr);
  101. cpm_dpfree(pinfo->dp_addr);
  102. }