cpm_uart_cpm1.c 4.0 KB

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