cpm_uart_cpm2.c 4.6 KB

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