blob: 1b94c56ec23914a0c7a44acd04ebe61594f39273 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/serial/cpm_uart.c
3 *
4 * Driver for CPM (SCC/SMC) serial ports; CPM1 definitions
5 *
Kumar Gala4c8d3d92005-11-13 16:06:30 -08006 * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
Kumar Gala311c4622005-08-09 10:08:00 -07008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Copyright (C) 2004 Freescale Semiconductor, Inc.
10 * (C) 2004 Intracom, S.A.
Vitaly Bordug6e1976962006-04-29 23:06:00 +040011 * (C) 2006 MontaVista Software, Inc.
Kumar Gala0d844062008-06-12 07:53:48 -050012 * Vitaly Bordug <vbordug@ru.mvista.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/tty.h>
32#include <linux/ioport.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
41#include <asm/io.h>
42#include <asm/irq.h>
Vitaly Bordugf25222b2007-01-24 22:40:49 +030043#include <asm/fs_pd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#include <linux/serial_core.h>
46#include <linux/kernel.h>
47
Laurent Pinchartd464df22008-04-10 17:01:27 +020048#include <linux/of.h>
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include "cpm_uart.h"
51
52/**************************************************************/
53
Scott Wood7ae87032007-07-17 17:59:06 -050054void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
55{
Jochen Friedrich362f9b62007-11-26 18:03:40 +010056 cpm_command(port->command, cmd);
Scott Wood7ae87032007-07-17 17:59:06 -050057}
Laurent Pinchartd464df22008-04-10 17:01:27 +020058
59void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
60 struct device_node *np)
61{
62 return of_iomap(np, 1);
63}
64
65void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
66{
67 iounmap(pram);
68}
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/*
Kumar Gala311c4622005-08-09 10:08:00 -070071 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * receive buffer descriptors from dual port ram, and a character
73 * buffer area from host mem. If we are allocating for the console we need
74 * to do it from bootmem
75 */
76int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
77{
78 int dpmemsz, memsz;
79 u8 *dp_mem;
Timur Tabi4c356302007-05-08 14:46:36 -050080 unsigned long dp_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 u8 *mem_addr;
82 dma_addr_t dma_addr = 0;
83
84 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
85
86 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
87 dp_offset = cpm_dpalloc(dpmemsz, 8);
Timur Tabi4c356302007-05-08 14:46:36 -050088 if (IS_ERR_VALUE(dp_offset)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 printk(KERN_ERR
90 "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
91 return -ENOMEM;
92 }
93 dp_mem = cpm_dpram_addr(dp_offset);
94
95 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
96 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
97 if (is_con) {
Kumar Gala311c4622005-08-09 10:08:00 -070098 /* was hostalloc but changed cause it blows away the */
99 /* large tlb mapping when pinning the kernel area */
Marcelo Tosatti4e4b7952005-07-27 11:46:01 -0700100 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
Vitaly Bordugf25222b2007-01-24 22:40:49 +0300101 dma_addr = (u32)cpm_dpram_phys(mem_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 } else
Becky Bruce8b05cef2008-09-12 10:42:56 -0500103 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 GFP_KERNEL);
105
106 if (mem_addr == NULL) {
107 cpm_dpfree(dp_offset);
108 printk(KERN_ERR
109 "cpm_uart_cpm1.c: could not allocate coherent memory\n");
110 return -ENOMEM;
111 }
112
113 pinfo->dp_addr = dp_offset;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400114 pinfo->mem_addr = mem_addr; /* virtual address*/
115 pinfo->dma_addr = dma_addr; /* physical address*/
116 pinfo->mem_size = memsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 pinfo->rx_buf = mem_addr;
119 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
120 * pinfo->rx_fifosize);
121
Scott Woodc1dcfd92007-07-24 15:53:07 -0500122 pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
124
125 return 0;
126}
127
128void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
129{
Becky Bruce8b05cef2008-09-12 10:42:56 -0500130 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
131 pinfo->rx_fifosize) +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
133 pinfo->tx_fifosize), pinfo->mem_addr,
134 pinfo->dma_addr);
135
136 cpm_dpfree(pinfo->dp_addr);
137}