cpm_uart_cpm1.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Driver for CPM (SCC/SMC) serial ports; CPM1 definitions
  3. *
  4. * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
  5. * Pantelis Antoniou (panto@intracom.gr) (CPM1)
  6. *
  7. * Copyright (C) 2004 Freescale Semiconductor, Inc.
  8. * (C) 2004 Intracom, S.A.
  9. * (C) 2006 MontaVista Software, Inc.
  10. * Vitaly Bordug <vbordug@ru.mvista.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #include <linux/module.h>
  28. #include <linux/tty.h>
  29. #include <linux/gfp.h>
  30. #include <linux/ioport.h>
  31. #include <linux/init.h>
  32. #include <linux/serial.h>
  33. #include <linux/console.h>
  34. #include <linux/sysrq.h>
  35. #include <linux/device.h>
  36. #include <linux/bootmem.h>
  37. #include <linux/dma-mapping.h>
  38. #include <asm/io.h>
  39. #include <asm/irq.h>
  40. #include <asm/fs_pd.h>
  41. #include <linux/serial_core.h>
  42. #include <linux/kernel.h>
  43. #include <linux/of.h>
  44. #include "cpm_uart.h"
  45. /**************************************************************/
  46. void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
  47. {
  48. cpm_command(port->command, cmd);
  49. }
  50. void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
  51. struct device_node *np)
  52. {
  53. return of_iomap(np, 1);
  54. }
  55. void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
  56. {
  57. iounmap(pram);
  58. }
  59. /*
  60. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  61. * receive buffer descriptors from dual port ram, and a character
  62. * buffer area from host mem. If we are allocating for the console we need
  63. * to do it from bootmem
  64. */
  65. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  66. {
  67. int dpmemsz, memsz;
  68. u8 *dp_mem;
  69. unsigned long dp_offset;
  70. u8 *mem_addr;
  71. dma_addr_t dma_addr = 0;
  72. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  73. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  74. dp_offset = cpm_dpalloc(dpmemsz, 8);
  75. if (IS_ERR_VALUE(dp_offset)) {
  76. printk(KERN_ERR
  77. "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
  78. return -ENOMEM;
  79. }
  80. dp_mem = cpm_dpram_addr(dp_offset);
  81. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  82. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  83. if (is_con) {
  84. /* was hostalloc but changed cause it blows away the */
  85. /* large tlb mapping when pinning the kernel area */
  86. mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
  87. dma_addr = (u32)cpm_dpram_phys(mem_addr);
  88. } else
  89. mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
  90. GFP_KERNEL);
  91. if (mem_addr == NULL) {
  92. cpm_dpfree(dp_offset);
  93. printk(KERN_ERR
  94. "cpm_uart_cpm1.c: could not allocate coherent memory\n");
  95. return -ENOMEM;
  96. }
  97. pinfo->dp_addr = dp_offset;
  98. pinfo->mem_addr = mem_addr; /* virtual address*/
  99. pinfo->dma_addr = dma_addr; /* physical address*/
  100. pinfo->mem_size = memsz;
  101. pinfo->rx_buf = mem_addr;
  102. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  103. * pinfo->rx_fifosize);
  104. pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
  105. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  106. return 0;
  107. }
  108. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  109. {
  110. dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  111. pinfo->rx_fifosize) +
  112. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  113. pinfo->tx_fifosize), pinfo->mem_addr,
  114. pinfo->dma_addr);
  115. cpm_dpfree(pinfo->dp_addr);
  116. }