cpm_uart_cpm2.c 4.6 KB

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