blob: 814ac006393fabac29f97d0f3cb129fe125f1ee3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/serial/cpm_uart_cpm2.c
3 *
4 * Driver for CPM (SCC/SMC) serial ports; CPM2 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 Gala0d844062008-06-12 07:53:48 -05008 *
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/init.h>
35#include <linux/serial.h>
36#include <linux/console.h>
37#include <linux/sysrq.h>
38#include <linux/device.h>
39#include <linux/bootmem.h>
40#include <linux/dma-mapping.h>
41
42#include <asm/io.h>
43#include <asm/irq.h>
Vitaly Bordug3dd0dcb2006-09-21 17:27:15 +040044#include <asm/fs_pd.h>
Laurent Pinchartd464df22008-04-10 17:01:27 +020045#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#include <linux/serial_core.h>
48#include <linux/kernel.h>
49
50#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 void __iomem *pram;
63 unsigned long offset;
64 struct resource res;
Tobias Klauser23144362010-03-11 14:08:18 -080065 resource_size_t len;
Laurent Pinchartd464df22008-04-10 17:01:27 +020066
67 /* Don't remap parameter RAM if it has already been initialized
68 * during console setup.
69 */
70 if (IS_SMC(port) && port->smcup)
71 return port->smcup;
72 else if (!IS_SMC(port) && port->sccup)
73 return port->sccup;
74
75 if (of_address_to_resource(np, 1, &res))
76 return NULL;
77
Tobias Klauser23144362010-03-11 14:08:18 -080078 len = resource_size(&res);
Laurent Pinchartd464df22008-04-10 17:01:27 +020079 pram = ioremap(res.start, len);
80 if (!pram)
81 return NULL;
82
83 if (!IS_SMC(port))
84 return pram;
85
86 if (len != 2) {
87 printk(KERN_WARNING "cpm_uart[%d]: device tree references "
88 "SMC pram, using boot loader/wrapper pram mapping. "
89 "Please fix your device tree to reference the pram "
90 "base register instead.\n",
91 port->port.line);
92 return pram;
93 }
94
95 offset = cpm_dpalloc(PROFF_SMC_SIZE, 64);
96 out_be16(pram, offset);
97 iounmap(pram);
98 return cpm_muram_addr(offset);
99}
100
101void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
102{
103 if (!IS_SMC(port))
104 iounmap(pram);
105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/*
Kumar Gala0d844062008-06-12 07:53:48 -0500108 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 * receive buffer descriptors from dual port ram, and a character
110 * buffer area from host mem. If we are allocating for the console we need
111 * to do it from bootmem
112 */
113int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
114{
115 int dpmemsz, memsz;
Scott Wood15f8c602007-09-28 14:06:16 -0500116 u8 __iomem *dp_mem;
Timur Tabi4c356302007-05-08 14:46:36 -0500117 unsigned long dp_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 u8 *mem_addr;
119 dma_addr_t dma_addr = 0;
120
121 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
122
123 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
124 dp_offset = cpm_dpalloc(dpmemsz, 8);
Timur Tabi4c356302007-05-08 14:46:36 -0500125 if (IS_ERR_VALUE(dp_offset)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 printk(KERN_ERR
127 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
128 return -ENOMEM;
129 }
130
131 dp_mem = cpm_dpram_addr(dp_offset);
132
133 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
134 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400135 if (is_con) {
Mark Ware6e900de2009-07-20 21:51:03 +1000136 mem_addr = kzalloc(memsz, GFP_NOWAIT);
Vitaly Bordug8e30a9a2006-05-24 21:40:18 +0400137 dma_addr = virt_to_bus(mem_addr);
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 else
Becky Bruce8b05cef2008-09-12 10:42:56 -0500140 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 GFP_KERNEL);
142
143 if (mem_addr == NULL) {
144 cpm_dpfree(dp_offset);
145 printk(KERN_ERR
146 "cpm_uart_cpm.c: could not allocate coherent memory\n");
147 return -ENOMEM;
148 }
149
150 pinfo->dp_addr = dp_offset;
151 pinfo->mem_addr = mem_addr;
152 pinfo->dma_addr = dma_addr;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400153 pinfo->mem_size = memsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 pinfo->rx_buf = mem_addr;
156 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
157 * pinfo->rx_fifosize);
158
Scott Wood15f8c602007-09-28 14:06:16 -0500159 pinfo->rx_bd_base = (cbd_t __iomem *)dp_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
161
162 return 0;
163}
164
165void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
166{
Becky Bruce8b05cef2008-09-12 10:42:56 -0500167 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
168 pinfo->rx_fifosize) +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
Scott Woodc1dcfd92007-07-24 15:53:07 -0500170 pinfo->tx_fifosize), (void __force *)pinfo->mem_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 pinfo->dma_addr);
172
173 cpm_dpfree(pinfo->dp_addr);
174}