cpm_uart_cpm2.c 4.6 KB

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