Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/serial/cpm_uart.c |
| 3 | * |
| 4 | * Driver for CPM (SCC/SMC) serial ports; CPM1 definitions |
| 5 | * |
Kumar Gala | 4c8d3d9 | 2005-11-13 16:06:30 -0800 | [diff] [blame] | 6 | * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Pantelis Antoniou (panto@intracom.gr) (CPM1) |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Copyright (C) 2004 Freescale Semiconductor, Inc. |
| 10 | * (C) 2004 Intracom, S.A. |
Vitaly Bordug | 6e197696 | 2006-04-29 23:06:00 +0400 | [diff] [blame] | 11 | * (C) 2006 MontaVista Software, Inc. |
Kumar Gala | 0d84406 | 2008-06-12 07:53:48 -0500 | [diff] [blame] | 12 | * Vitaly Bordug <vbordug@ru.mvista.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/tty.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/ioport.h> |
| 34 | #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 Bordug | f25222b | 2007-01-24 22:40:49 +0300 | [diff] [blame] | 44 | #include <asm/fs_pd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #include <linux/serial_core.h> |
| 47 | #include <linux/kernel.h> |
| 48 | |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 49 | #include <linux/of.h> |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include "cpm_uart.h" |
| 52 | |
| 53 | /**************************************************************/ |
| 54 | |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 55 | void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd) |
| 56 | { |
Jochen Friedrich | 362f9b6 | 2007-11-26 18:03:40 +0100 | [diff] [blame] | 57 | cpm_command(port->command, cmd); |
Scott Wood | 7ae8703 | 2007-07-17 17:59:06 -0500 | [diff] [blame] | 58 | } |
Laurent Pinchart | d464df2 | 2008-04-10 17:01:27 +0200 | [diff] [blame] | 59 | |
| 60 | void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port, |
| 61 | struct device_node *np) |
| 62 | { |
| 63 | return of_iomap(np, 1); |
| 64 | } |
| 65 | |
| 66 | void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram) |
| 67 | { |
| 68 | iounmap(pram); |
| 69 | } |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 72 | * 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] | 73 | * receive buffer descriptors from dual port ram, and a character |
| 74 | * buffer area from host mem. If we are allocating for the console we need |
| 75 | * to do it from bootmem |
| 76 | */ |
| 77 | int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con) |
| 78 | { |
| 79 | int dpmemsz, memsz; |
| 80 | u8 *dp_mem; |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 81 | unsigned long dp_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | u8 *mem_addr; |
| 83 | dma_addr_t dma_addr = 0; |
| 84 | |
| 85 | pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line); |
| 86 | |
| 87 | dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos); |
| 88 | dp_offset = cpm_dpalloc(dpmemsz, 8); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 89 | if (IS_ERR_VALUE(dp_offset)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | printk(KERN_ERR |
| 91 | "cpm_uart_cpm1.c: could not allocate buffer descriptors\n"); |
| 92 | return -ENOMEM; |
| 93 | } |
| 94 | dp_mem = cpm_dpram_addr(dp_offset); |
| 95 | |
| 96 | memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) + |
| 97 | L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize); |
| 98 | if (is_con) { |
Kumar Gala | 311c462 | 2005-08-09 10:08:00 -0700 | [diff] [blame] | 99 | /* was hostalloc but changed cause it blows away the */ |
| 100 | /* large tlb mapping when pinning the kernel area */ |
Marcelo Tosatti | 4e4b795 | 2005-07-27 11:46:01 -0700 | [diff] [blame] | 101 | mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8)); |
Vitaly Bordug | f25222b | 2007-01-24 22:40:49 +0300 | [diff] [blame] | 102 | dma_addr = (u32)cpm_dpram_phys(mem_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } else |
Becky Bruce | 8b05cef | 2008-09-12 10:42:56 -0500 | [diff] [blame] | 104 | mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | GFP_KERNEL); |
| 106 | |
| 107 | if (mem_addr == NULL) { |
| 108 | cpm_dpfree(dp_offset); |
| 109 | printk(KERN_ERR |
| 110 | "cpm_uart_cpm1.c: could not allocate coherent memory\n"); |
| 111 | return -ENOMEM; |
| 112 | } |
| 113 | |
| 114 | pinfo->dp_addr = dp_offset; |
Vitaly Bordug | 09b03b6 | 2006-04-25 20:26:46 +0400 | [diff] [blame] | 115 | pinfo->mem_addr = mem_addr; /* virtual address*/ |
| 116 | pinfo->dma_addr = dma_addr; /* physical address*/ |
| 117 | pinfo->mem_size = memsz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | pinfo->rx_buf = mem_addr; |
| 120 | pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos |
| 121 | * pinfo->rx_fifosize); |
| 122 | |
Scott Wood | c1dcfd9 | 2007-07-24 15:53:07 -0500 | [diff] [blame] | 123 | pinfo->rx_bd_base = (cbd_t __iomem __force *)dp_mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos; |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | void cpm_uart_freebuf(struct uart_cpm_port *pinfo) |
| 130 | { |
Becky Bruce | 8b05cef | 2008-09-12 10:42:56 -0500 | [diff] [blame] | 131 | dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos * |
| 132 | pinfo->rx_fifosize) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | L1_CACHE_ALIGN(pinfo->tx_nrfifos * |
| 134 | pinfo->tx_fifosize), pinfo->mem_addr, |
| 135 | pinfo->dma_addr); |
| 136 | |
| 137 | cpm_dpfree(pinfo->dp_addr); |
| 138 | } |