blob: 74f1432bb248e5ec5b7232d5f19318152e4e0a35 [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.
12 * 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 -050054#ifdef CONFIG_PPC_CPM_NEW_BINDING
55void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
56{
Jochen Friedrich362f9b62007-11-26 18:03:40 +010057 cpm_command(port->command, cmd);
Scott Wood7ae87032007-07-17 17:59:06 -050058}
Laurent Pinchartd464df22008-04-10 17:01:27 +020059
60void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
61 struct device_node *np)
62{
63 return of_iomap(np, 1);
64}
65
66void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
67{
68 iounmap(pram);
69}
70
Scott Wood7ae87032007-07-17 17:59:06 -050071#else
72void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 ushort val;
Scott Wood7ae87032007-07-17 17:59:06 -050075 int line = port - cpm_uart_ports;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 volatile cpm8xx_t *cp = cpmp;
77
78 switch (line) {
79 case UART_SMC1:
80 val = mk_cr_cmd(CPM_CR_CH_SMC1, cmd) | CPM_CR_FLG;
81 break;
82 case UART_SMC2:
83 val = mk_cr_cmd(CPM_CR_CH_SMC2, cmd) | CPM_CR_FLG;
84 break;
85 case UART_SCC1:
86 val = mk_cr_cmd(CPM_CR_CH_SCC1, cmd) | CPM_CR_FLG;
87 break;
88 case UART_SCC2:
89 val = mk_cr_cmd(CPM_CR_CH_SCC2, cmd) | CPM_CR_FLG;
90 break;
91 case UART_SCC3:
92 val = mk_cr_cmd(CPM_CR_CH_SCC3, cmd) | CPM_CR_FLG;
93 break;
94 case UART_SCC4:
95 val = mk_cr_cmd(CPM_CR_CH_SCC4, cmd) | CPM_CR_FLG;
96 break;
97 default:
98 return;
99
100 }
101 cp->cp_cpcr = val;
102 while (cp->cp_cpcr & CPM_CR_FLG) ;
103}
104
105void smc1_lineif(struct uart_cpm_port *pinfo)
106{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 pinfo->brg = 1;
108}
109
110void smc2_lineif(struct uart_cpm_port *pinfo)
111{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 pinfo->brg = 2;
113}
114
115void scc1_lineif(struct uart_cpm_port *pinfo)
116{
117 /* XXX SCC1: insert port configuration here */
118 pinfo->brg = 1;
119}
120
121void scc2_lineif(struct uart_cpm_port *pinfo)
122{
123 /* XXX SCC2: insert port configuration here */
124 pinfo->brg = 2;
125}
126
127void scc3_lineif(struct uart_cpm_port *pinfo)
128{
129 /* XXX SCC3: insert port configuration here */
130 pinfo->brg = 3;
131}
132
133void scc4_lineif(struct uart_cpm_port *pinfo)
134{
135 /* XXX SCC4: insert port configuration here */
136 pinfo->brg = 4;
137}
Scott Wood7ae87032007-07-17 17:59:06 -0500138#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140/*
Kumar Gala311c4622005-08-09 10:08:00 -0700141 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 * receive buffer descriptors from dual port ram, and a character
143 * buffer area from host mem. If we are allocating for the console we need
144 * to do it from bootmem
145 */
146int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
147{
148 int dpmemsz, memsz;
149 u8 *dp_mem;
Timur Tabi4c356302007-05-08 14:46:36 -0500150 unsigned long dp_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 u8 *mem_addr;
152 dma_addr_t dma_addr = 0;
153
154 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
155
156 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
157 dp_offset = cpm_dpalloc(dpmemsz, 8);
Timur Tabi4c356302007-05-08 14:46:36 -0500158 if (IS_ERR_VALUE(dp_offset)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 printk(KERN_ERR
160 "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
161 return -ENOMEM;
162 }
163 dp_mem = cpm_dpram_addr(dp_offset);
164
165 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
166 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
167 if (is_con) {
Kumar Gala311c4622005-08-09 10:08:00 -0700168 /* was hostalloc but changed cause it blows away the */
169 /* large tlb mapping when pinning the kernel area */
Marcelo Tosatti4e4b7952005-07-27 11:46:01 -0700170 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
Vitaly Bordugf25222b2007-01-24 22:40:49 +0300171 dma_addr = (u32)cpm_dpram_phys(mem_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 } else
173 mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
174 GFP_KERNEL);
175
176 if (mem_addr == NULL) {
177 cpm_dpfree(dp_offset);
178 printk(KERN_ERR
179 "cpm_uart_cpm1.c: could not allocate coherent memory\n");
180 return -ENOMEM;
181 }
182
183 pinfo->dp_addr = dp_offset;
Vitaly Bordug09b03b62006-04-25 20:26:46 +0400184 pinfo->mem_addr = mem_addr; /* virtual address*/
185 pinfo->dma_addr = dma_addr; /* physical address*/
186 pinfo->mem_size = memsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 pinfo->rx_buf = mem_addr;
189 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
190 * pinfo->rx_fifosize);
191
Scott Woodc1dcfd92007-07-24 15:53:07 -0500192 pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
194
195 return 0;
196}
197
198void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
199{
200 dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
201 pinfo->rx_fifosize) +
202 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
203 pinfo->tx_fifosize), pinfo->mem_addr,
204 pinfo->dma_addr);
205
206 cpm_dpfree(pinfo->dp_addr);
207}
208
Scott Wood7ae87032007-07-17 17:59:06 -0500209#ifndef CONFIG_PPC_CPM_NEW_BINDING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210/* Setup any dynamic params in the uart desc */
Kumar Gala32a56eb2007-05-09 23:44:58 -0500211int cpm_uart_init_portdesc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 pr_debug("CPM uart[-]:init portdesc\n");
214
215 cpm_uart_nr = 0;
216#ifdef CONFIG_SERIAL_CPM_SMC1
217 cpm_uart_ports[UART_SMC1].smcp = &cpmp->cp_smc[0];
218/*
219 * Is SMC1 being relocated?
220 */
221# ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
222 cpm_uart_ports[UART_SMC1].smcup =
223 (smc_uart_t *) & cpmp->cp_dparam[0x3C0];
224# else
225 cpm_uart_ports[UART_SMC1].smcup =
226 (smc_uart_t *) & cpmp->cp_dparam[PROFF_SMC1];
227# endif
228 cpm_uart_ports[UART_SMC1].port.mapbase =
229 (unsigned long)&cpmp->cp_smc[0];
230 cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
231 cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
Vitaly Bordugf25222b2007-01-24 22:40:49 +0300232 cpm_uart_ports[UART_SMC1].port.uartclk = uart_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
234#endif
235
236#ifdef CONFIG_SERIAL_CPM_SMC2
237 cpm_uart_ports[UART_SMC2].smcp = &cpmp->cp_smc[1];
238 cpm_uart_ports[UART_SMC2].smcup =
239 (smc_uart_t *) & cpmp->cp_dparam[PROFF_SMC2];
240 cpm_uart_ports[UART_SMC2].port.mapbase =
241 (unsigned long)&cpmp->cp_smc[1];
242 cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
243 cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
Vitaly Bordugf25222b2007-01-24 22:40:49 +0300244 cpm_uart_ports[UART_SMC2].port.uartclk = uart_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
246#endif
247
248#ifdef CONFIG_SERIAL_CPM_SCC1
249 cpm_uart_ports[UART_SCC1].sccp = &cpmp->cp_scc[0];
250 cpm_uart_ports[UART_SCC1].sccup =
251 (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC1];
252 cpm_uart_ports[UART_SCC1].port.mapbase =
253 (unsigned long)&cpmp->cp_scc[0];
254 cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
255 ~(UART_SCCM_TX | UART_SCCM_RX);
256 cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
257 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
Vitaly Bordugf25222b2007-01-24 22:40:49 +0300258 cpm_uart_ports[UART_SCC1].port.uartclk = uart_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
260#endif
261
262#ifdef CONFIG_SERIAL_CPM_SCC2
263 cpm_uart_ports[UART_SCC2].sccp = &cpmp->cp_scc[1];
264 cpm_uart_ports[UART_SCC2].sccup =
265 (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC2];
266 cpm_uart_ports[UART_SCC2].port.mapbase =
267 (unsigned long)&cpmp->cp_scc[1];
268 cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
269 ~(UART_SCCM_TX | UART_SCCM_RX);
270 cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
271 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
Vitaly Bordugf25222b2007-01-24 22:40:49 +0300272 cpm_uart_ports[UART_SCC2].port.uartclk = uart_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
274#endif
275
276#ifdef CONFIG_SERIAL_CPM_SCC3
277 cpm_uart_ports[UART_SCC3].sccp = &cpmp->cp_scc[2];
278 cpm_uart_ports[UART_SCC3].sccup =
279 (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC3];
280 cpm_uart_ports[UART_SCC3].port.mapbase =
281 (unsigned long)&cpmp->cp_scc[2];
282 cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
283 ~(UART_SCCM_TX | UART_SCCM_RX);
284 cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
285 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
Vitaly Bordugf25222b2007-01-24 22:40:49 +0300286 cpm_uart_ports[UART_SCC3].port.uartclk = uart_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
288#endif
289
290#ifdef CONFIG_SERIAL_CPM_SCC4
291 cpm_uart_ports[UART_SCC4].sccp = &cpmp->cp_scc[3];
292 cpm_uart_ports[UART_SCC4].sccup =
293 (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC4];
294 cpm_uart_ports[UART_SCC4].port.mapbase =
295 (unsigned long)&cpmp->cp_scc[3];
296 cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
297 ~(UART_SCCM_TX | UART_SCCM_RX);
298 cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
299 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
Vitaly Bordugf25222b2007-01-24 22:40:49 +0300300 cpm_uart_ports[UART_SCC4].port.uartclk = uart_clock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
302#endif
303 return 0;
304}
Scott Wood7ae87032007-07-17 17:59:06 -0500305#endif