Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  *  Driver for CPM (SCC/SMC) serial ports; CPM1 definitions
0004  *
0005  *  Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
0006  *              Pantelis Antoniou (panto@intracom.gr) (CPM1)
0007  *
0008  *  Copyright (C) 2004 Freescale Semiconductor, Inc.
0009  *            (C) 2004 Intracom, S.A.
0010  *            (C) 2006 MontaVista Software, Inc.
0011  *      Vitaly Bordug <vbordug@ru.mvista.com>
0012  */
0013 
0014 #include <linux/module.h>
0015 #include <linux/tty.h>
0016 #include <linux/gfp.h>
0017 #include <linux/ioport.h>
0018 #include <linux/serial.h>
0019 #include <linux/console.h>
0020 #include <linux/sysrq.h>
0021 #include <linux/device.h>
0022 #include <linux/memblock.h>
0023 #include <linux/dma-mapping.h>
0024 
0025 #include <asm/io.h>
0026 #include <asm/irq.h>
0027 #include <asm/fs_pd.h>
0028 
0029 #include <linux/serial_core.h>
0030 #include <linux/kernel.h>
0031 
0032 #include <linux/of.h>
0033 #include <linux/of_address.h>
0034 
0035 #include "cpm_uart.h"
0036 
0037 /**************************************************************/
0038 
0039 void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
0040 {
0041     cpm_command(port->command, cmd);
0042 }
0043 
0044 void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
0045                 struct device_node *np)
0046 {
0047     return of_iomap(np, 1);
0048 }
0049 
0050 void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
0051 {
0052     iounmap(pram);
0053 }
0054 
0055 /*
0056  * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
0057  * receive buffer descriptors from dual port ram, and a character
0058  * buffer area from host mem. If we are allocating for the console we need
0059  * to do it from bootmem
0060  */
0061 int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
0062 {
0063     int dpmemsz, memsz;
0064     u8 *dp_mem;
0065     unsigned long dp_offset;
0066     u8 *mem_addr;
0067     dma_addr_t dma_addr = 0;
0068 
0069     pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
0070 
0071     dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
0072     dp_offset = cpm_dpalloc(dpmemsz, 8);
0073     if (IS_ERR_VALUE(dp_offset)) {
0074         printk(KERN_ERR
0075                "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
0076         return -ENOMEM;
0077     }
0078     dp_mem = cpm_dpram_addr(dp_offset);
0079 
0080     memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
0081         L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
0082     if (is_con) {
0083         /* was hostalloc but changed cause it blows away the */
0084         /* large tlb mapping when pinning the kernel area    */
0085         mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
0086         dma_addr = (u32)cpm_dpram_phys(mem_addr);
0087     } else
0088         mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
0089                           GFP_KERNEL);
0090 
0091     if (mem_addr == NULL) {
0092         cpm_dpfree(dp_offset);
0093         printk(KERN_ERR
0094                "cpm_uart_cpm1.c: could not allocate coherent memory\n");
0095         return -ENOMEM;
0096     }
0097 
0098     pinfo->dp_addr = dp_offset;
0099     pinfo->mem_addr = mem_addr;             /*  virtual address*/
0100     pinfo->dma_addr = dma_addr;             /*  physical address*/
0101     pinfo->mem_size = memsz;
0102 
0103     pinfo->rx_buf = mem_addr;
0104     pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
0105                                * pinfo->rx_fifosize);
0106 
0107     pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
0108     pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
0109 
0110     return 0;
0111 }
0112 
0113 void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
0114 {
0115     dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
0116                               pinfo->rx_fifosize) +
0117               L1_CACHE_ALIGN(pinfo->tx_nrfifos *
0118                      pinfo->tx_fifosize), pinfo->mem_addr,
0119               pinfo->dma_addr);
0120 
0121     cpm_dpfree(pinfo->dp_addr);
0122 }