cpm_uart_cpm2.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * linux/drivers/serial/cpm_uart_cpm2.c
  3. *
  4. * Driver for CPM (SCC/SMC) serial ports; CPM2 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 <asm/prom.h>
  43. #include <linux/serial_core.h>
  44. #include <linux/kernel.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. void __iomem *pram;
  55. unsigned long offset;
  56. struct resource res;
  57. unsigned long len;
  58. /* Don't remap parameter RAM if it has already been initialized
  59. * during console setup.
  60. */
  61. if (IS_SMC(port) && port->smcup)
  62. return port->smcup;
  63. else if (!IS_SMC(port) && port->sccup)
  64. return port->sccup;
  65. if (of_address_to_resource(np, 1, &res))
  66. return NULL;
  67. len = 1 + res.end - res.start;
  68. pram = ioremap(res.start, len);
  69. if (!pram)
  70. return NULL;
  71. if (!IS_SMC(port))
  72. return pram;
  73. if (len != 2) {
  74. printk(KERN_WARNING "cpm_uart[%d]: device tree references "
  75. "SMC pram, using boot loader/wrapper pram mapping. "
  76. "Please fix your device tree to reference the pram "
  77. "base register instead.\n",
  78. port->port.line);
  79. return pram;
  80. }
  81. offset = cpm_dpalloc(PROFF_SMC_SIZE, 64);
  82. out_be16(pram, offset);
  83. iounmap(pram);
  84. return cpm_muram_addr(offset);
  85. }
  86. void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
  87. {
  88. if (!IS_SMC(port))
  89. iounmap(pram);
  90. }
  91. /*
  92. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  93. * receive buffer descriptors from dual port ram, and a character
  94. * buffer area from host mem. If we are allocating for the console we need
  95. * to do it from bootmem
  96. */
  97. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  98. {
  99. int dpmemsz, memsz;
  100. u8 __iomem *dp_mem;
  101. unsigned long dp_offset;
  102. u8 *mem_addr;
  103. dma_addr_t dma_addr = 0;
  104. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  105. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  106. dp_offset = cpm_dpalloc(dpmemsz, 8);
  107. if (IS_ERR_VALUE(dp_offset)) {
  108. printk(KERN_ERR
  109. "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
  110. return -ENOMEM;
  111. }
  112. dp_mem = cpm_dpram_addr(dp_offset);
  113. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  114. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  115. if (is_con) {
  116. mem_addr = alloc_bootmem(memsz);
  117. dma_addr = virt_to_bus(mem_addr);
  118. }
  119. else
  120. mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
  121. GFP_KERNEL);
  122. if (mem_addr == NULL) {
  123. cpm_dpfree(dp_offset);
  124. printk(KERN_ERR
  125. "cpm_uart_cpm.c: could not allocate coherent memory\n");
  126. return -ENOMEM;
  127. }
  128. pinfo->dp_addr = dp_offset;
  129. pinfo->mem_addr = mem_addr;
  130. pinfo->dma_addr = dma_addr;
  131. pinfo->mem_size = memsz;
  132. pinfo->rx_buf = mem_addr;
  133. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  134. * pinfo->rx_fifosize);
  135. pinfo->rx_bd_base = (cbd_t __iomem *)dp_mem;
  136. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  137. return 0;
  138. }
  139. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  140. {
  141. dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  142. pinfo->rx_fifosize) +
  143. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  144. pinfo->tx_fifosize), (void __force *)pinfo->mem_addr,
  145. pinfo->dma_addr);
  146. cpm_dpfree(pinfo->dp_addr);
  147. }