blob: f46d2ca872096c0aa26e754a36cfb71d1c53f509 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Driver for CPM (SCC/SMC) serial ports; CPM2 definitions
3 *
Kumar Gala4c8d3d92005-11-13 16:06:30 -08004 * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
Kumar Gala0d844062008-06-12 07:53:48 -05006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Copyright (C) 2004 Freescale Semiconductor, Inc.
8 * (C) 2004 Intracom, S.A.
Vitaly Bordug6e1976962006-04-29 23:06:00 +04009 * (C) 2006 MontaVista Software, Inc.
Kumar Gala0d844062008-06-12 07:53:48 -050010 * Vitaly Bordug <vbordug@ru.mvista.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/tty.h>
30#include <linux/ioport.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#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
39#include <asm/io.h>
40#include <asm/irq.h>
Vitaly Bordug3dd0dcb2006-09-21 17:27:15 +040041#include <asm/fs_pd.h>
Laurent Pinchartd464df22008-04-10 17:01:27 +020042#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#include <linux/serial_core.h>
45#include <linux/kernel.h>
46
47#include "cpm_uart.h"
48
49/**************************************************************/
50
Scott Wood7ae87032007-07-17 17:59:06 -050051void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
52{
Jochen Friedrich362f9b62007-11-26 18:03:40 +010053 cpm_command(port->command, cmd);
Scott Wood7ae87032007-07-17 17:59:06 -050054}
Laurent Pinchartd464df22008-04-10 17:01:27 +020055
56void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
57 struct device_node *np)
58{
59 void __iomem *pram;
60 unsigned long offset;
61 struct resource res;
Tobias Klauser23144362010-03-11 14:08:18 -080062 resource_size_t len;
Laurent Pinchartd464df22008-04-10 17:01:27 +020063
64 /* Don't remap parameter RAM if it has already been initialized
65 * during console setup.
66 */
67 if (IS_SMC(port) && port->smcup)
68 return port->smcup;
69 else if (!IS_SMC(port) && port->sccup)
70 return port->sccup;
71
72 if (of_address_to_resource(np, 1, &res))
73 return NULL;
74
Tobias Klauser23144362010-03-11 14:08:18 -080075 len = resource_size(&res);
Laurent Pinchartd464df22008-04-10 17:01:27 +020076 pram = ioremap(res.start, len);
77 if (!pram)
78 return NULL;
79
80 if (!IS_SMC(port))
81 return pram;
82
83 if (len != 2) {
84 printk(KERN_WARNING "cpm_uart[%d]: device tree references "
85 "SMC pram, using boot loader/wrapper pram mapping. "
86 "Please fix your device tree to reference the pram "
87 "base register instead.\n",
88 port->port.line);
89 return pram;
90 }
91
92 offset = cpm_dpalloc(PROFF_SMC_SIZE, 64);
93 out_be16(pram, offset);
94 iounmap(pram);
95 return cpm_muram_addr(offset);
96}
97
98void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
99{
100 if (!IS_SMC(port))
101 iounmap(pram);
102}
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104/*
Kumar Gala0d844062008-06-12 07:53:48 -0500105 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 * receive buffer descriptors from dual port ram, and a character
107 * buffer area from host mem. If we are allocating for the console we need
108 * to do it from bootmem
109 */
110int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
111{
112 int dpmemsz, memsz;
Scott Wood15f8c602007-09-28 14:06:16 -0500113 u8 __iomem *dp_mem;
Timur Tabi4c356302007-05-08 14:46:36 -0500114 unsigned long dp_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 u8 *mem_addr;
116 dma_addr_t dma_addr = 0;
117
118 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
119
120 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
121 dp_offset = cpm_dpalloc(dpmemsz, 8);
Timur Tabi4c356302007-05-08 14:46:36 -0500122 if (IS_ERR_VALUE(dp_offset)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 printk(KERN_ERR
124 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
125 return -ENOMEM;
126 }
127
128 dp_mem = cpm_dpram_addr(dp_offset);
129
130 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
131 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400132 if (is_con) {
Mark Ware6e900de2009-07-20 21:51:03 +1000133 mem_addr = kzalloc(memsz, GFP_NOWAIT);
Vitaly Bordug8e30a9a2006-05-24 21:40:18 +0400134 dma_addr = virt_to_bus(mem_addr);
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 else
Becky Bruce8b05cef2008-09-12 10:42:56 -0500137 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 GFP_KERNEL);
139
140 if (mem_addr == NULL) {
141 cpm_dpfree(dp_offset);
142 printk(KERN_ERR
143 "cpm_uart_cpm.c: could not allocate coherent memory\n");
144 return -ENOMEM;
145 }
146
147 pinfo->dp_addr = dp_offset;
148 pinfo->mem_addr = mem_addr;
149 pinfo->dma_addr = dma_addr;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400150 pinfo->mem_size = memsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 pinfo->rx_buf = mem_addr;
153 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
154 * pinfo->rx_fifosize);
155
Scott Wood15f8c602007-09-28 14:06:16 -0500156 pinfo->rx_bd_base = (cbd_t __iomem *)dp_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
158
159 return 0;
160}
161
162void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
163{
Becky Bruce8b05cef2008-09-12 10:42:56 -0500164 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
165 pinfo->rx_fifosize) +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
Scott Woodc1dcfd92007-07-24 15:53:07 -0500167 pinfo->tx_fifosize), (void __force *)pinfo->mem_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 pinfo->dma_addr);
169
170 cpm_dpfree(pinfo->dp_addr);
171}