Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Driver for CPM (SCC/SMC) serial ports; CPM2 definitions |
| 3 | * |
Kumar Gala | 4c8d3d9 | 2005-11-13 16:06:30 -0800 | [diff] [blame] | 4 | * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Pantelis Antoniou (panto@intracom.gr) (CPM1) |
Kumar Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Copyright (C) 2004 Freescale Semiconductor, Inc. |
| 8 | * (C) 2004 Intracom, S.A. |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 9 | * (C) 2006 MontaVista Software, Inc. |
Kumar Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 10 | * Vitaly Bordug <vbordug@ru.mvista.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/tty.h> |
| 30 | #include <linux/ioport.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #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 Bordug | 3dd0dcb | 2006-09-21 17:27:15 +0400 | [diff] [blame] | 41 | #include <asm/fs_pd.h> |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 42 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #include <linux/serial_core.h> |
| 45 | #include <linux/kernel.h> |
| 46 | |
| 47 | #include "cpm_uart.h" |
| 48 | |
| 49 | /**************************************************************/ |
| 50 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 51 | void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd) |
| 52 | { |
Jochen Friedrich | 362f9b6 | 2007-11-26 18:03:40 +0100 | [diff] [blame] | 53 | cpm_command(port->command, cmd); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 54 | } |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 55 | |
| 56 | void __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 Klauser | 2314436 | 2010-03-11 14:08:18 -0800 | [diff] [blame] | 62 | resource_size_t len; |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 63 | |
| 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 Klauser | 2314436 | 2010-03-11 14:08:18 -0800 | [diff] [blame] | 75 | len = resource_size(&res); |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 76 | 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 | |
| 98 | void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram) |
| 99 | { |
| 100 | if (!IS_SMC(port)) |
| 101 | iounmap(pram); |
| 102 | } |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* |
Kumar Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 105 | * Allocate DP-Ram and memory buffers. We need to allocate a transmit and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | * 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 | */ |
| 110 | int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con) |
| 111 | { |
| 112 | int dpmemsz, memsz; |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 113 | u8 __iomem *dp_mem; |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 114 | unsigned long dp_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | 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 Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 122 | if (IS_ERR_VALUE(dp_offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | 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 Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 132 | if (is_con) { |
Mark Ware | 6e900de | 2009-07-20 21:51:03 +1000 | [diff] [blame] | 133 | mem_addr = kzalloc(memsz, GFP_NOWAIT); |
Vitaly Bordug | 8e30a9a | 2006-05-24 21:40:18 +0400 | [diff] [blame] | 134 | dma_addr = virt_to_bus(mem_addr); |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | else |
Becky Bruce | 8b05cef | 2008-09-12 10:42:56 -0500 | [diff] [blame] | 137 | mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | 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 Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 150 | pinfo->mem_size = memsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 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 Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 156 | pinfo->rx_bd_base = (cbd_t __iomem *)dp_mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos; |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | void cpm_uart_freebuf(struct uart_cpm_port *pinfo) |
| 163 | { |
Becky Bruce | 8b05cef | 2008-09-12 10:42:56 -0500 | [diff] [blame] | 164 | dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos * |
| 165 | pinfo->rx_fifosize) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | L1_CACHE_ALIGN(pinfo->tx_nrfifos * |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 167 | pinfo->tx_fifosize), (void __force *)pinfo->mem_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | pinfo->dma_addr); |
| 169 | |
| 170 | cpm_dpfree(pinfo->dp_addr); |
| 171 | } |