blob: 7d4751474da15c5dab412bb16ef8bae4df99831a [file] [log] [blame]
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001/*
Tomoya MORINAGAeca9dfa2011-10-28 09:38:50 +09002 *Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09003 *
4 *This program is free software; you can redistribute it and/or modify
5 *it under the terms of the GNU General Public License as published by
6 *the Free Software Foundation; version 2 of the License.
7 *
8 *This program is distributed in the hope that it will be useful,
9 *but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 *GNU General Public License for more details.
12 *
13 *You should have received a copy of the GNU General Public License
14 *along with this program; if not, write to the Free Software
15 *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
Uwe Kleine-König0e2adc02011-05-26 10:41:17 +020017#include <linux/kernel.h>
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +090018#include <linux/serial_reg.h>
Andrew Morton023bc8e2011-05-24 17:13:44 -070019#include <linux/slab.h>
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +090020#include <linux/module.h>
21#include <linux/pci.h>
22#include <linux/serial_core.h>
Jiri Slabyee160a32011-09-01 16:20:57 +020023#include <linux/tty.h>
24#include <linux/tty_flip.h>
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +090025#include <linux/interrupt.h>
26#include <linux/io.h>
Denis Turischev6ae705b2011-03-10 15:14:00 +020027#include <linux/dmi.h>
Alexander Steine30f8672011-11-15 15:04:07 -080028#include <linux/console.h>
29#include <linux/nmi.h>
30#include <linux/delay.h>
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +090031
Feng Tangd0114112012-02-06 17:24:43 +080032#include <linux/debugfs.h>
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +090033#include <linux/dmaengine.h>
34#include <linux/pch_dma.h>
35
36enum {
37 PCH_UART_HANDLED_RX_INT_SHIFT,
38 PCH_UART_HANDLED_TX_INT_SHIFT,
39 PCH_UART_HANDLED_RX_ERR_INT_SHIFT,
40 PCH_UART_HANDLED_RX_TRG_INT_SHIFT,
41 PCH_UART_HANDLED_MS_INT_SHIFT,
42};
43
44enum {
45 PCH_UART_8LINE,
46 PCH_UART_2LINE,
47};
48
49#define PCH_UART_DRIVER_DEVICE "ttyPCH"
50
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +090051/* Set the max number of UART port
52 * Intel EG20T PCH: 4 port
Tomoya MORINAGAeca9dfa2011-10-28 09:38:50 +090053 * LAPIS Semiconductor ML7213 IOH: 3 port
54 * LAPIS Semiconductor ML7223 IOH: 2 port
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +090055*/
56#define PCH_UART_NR 4
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +090057
58#define PCH_UART_HANDLED_RX_INT (1<<((PCH_UART_HANDLED_RX_INT_SHIFT)<<1))
59#define PCH_UART_HANDLED_TX_INT (1<<((PCH_UART_HANDLED_TX_INT_SHIFT)<<1))
60#define PCH_UART_HANDLED_RX_ERR_INT (1<<((\
61 PCH_UART_HANDLED_RX_ERR_INT_SHIFT)<<1))
62#define PCH_UART_HANDLED_RX_TRG_INT (1<<((\
63 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1))
64#define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1))
65
66#define PCH_UART_RBR 0x00
67#define PCH_UART_THR 0x00
68
69#define PCH_UART_IER_MASK (PCH_UART_IER_ERBFI|PCH_UART_IER_ETBEI|\
70 PCH_UART_IER_ELSI|PCH_UART_IER_EDSSI)
71#define PCH_UART_IER_ERBFI 0x00000001
72#define PCH_UART_IER_ETBEI 0x00000002
73#define PCH_UART_IER_ELSI 0x00000004
74#define PCH_UART_IER_EDSSI 0x00000008
75
76#define PCH_UART_IIR_IP 0x00000001
77#define PCH_UART_IIR_IID 0x00000006
78#define PCH_UART_IIR_MSI 0x00000000
79#define PCH_UART_IIR_TRI 0x00000002
80#define PCH_UART_IIR_RRI 0x00000004
81#define PCH_UART_IIR_REI 0x00000006
82#define PCH_UART_IIR_TOI 0x00000008
83#define PCH_UART_IIR_FIFO256 0x00000020
84#define PCH_UART_IIR_FIFO64 PCH_UART_IIR_FIFO256
85#define PCH_UART_IIR_FE 0x000000C0
86
87#define PCH_UART_FCR_FIFOE 0x00000001
88#define PCH_UART_FCR_RFR 0x00000002
89#define PCH_UART_FCR_TFR 0x00000004
90#define PCH_UART_FCR_DMS 0x00000008
91#define PCH_UART_FCR_FIFO256 0x00000020
92#define PCH_UART_FCR_RFTL 0x000000C0
93
94#define PCH_UART_FCR_RFTL1 0x00000000
95#define PCH_UART_FCR_RFTL64 0x00000040
96#define PCH_UART_FCR_RFTL128 0x00000080
97#define PCH_UART_FCR_RFTL224 0x000000C0
98#define PCH_UART_FCR_RFTL16 PCH_UART_FCR_RFTL64
99#define PCH_UART_FCR_RFTL32 PCH_UART_FCR_RFTL128
100#define PCH_UART_FCR_RFTL56 PCH_UART_FCR_RFTL224
101#define PCH_UART_FCR_RFTL4 PCH_UART_FCR_RFTL64
102#define PCH_UART_FCR_RFTL8 PCH_UART_FCR_RFTL128
103#define PCH_UART_FCR_RFTL14 PCH_UART_FCR_RFTL224
104#define PCH_UART_FCR_RFTL_SHIFT 6
105
106#define PCH_UART_LCR_WLS 0x00000003
107#define PCH_UART_LCR_STB 0x00000004
108#define PCH_UART_LCR_PEN 0x00000008
109#define PCH_UART_LCR_EPS 0x00000010
110#define PCH_UART_LCR_SP 0x00000020
111#define PCH_UART_LCR_SB 0x00000040
112#define PCH_UART_LCR_DLAB 0x00000080
113#define PCH_UART_LCR_NP 0x00000000
114#define PCH_UART_LCR_OP PCH_UART_LCR_PEN
115#define PCH_UART_LCR_EP (PCH_UART_LCR_PEN | PCH_UART_LCR_EPS)
116#define PCH_UART_LCR_1P (PCH_UART_LCR_PEN | PCH_UART_LCR_SP)
117#define PCH_UART_LCR_0P (PCH_UART_LCR_PEN | PCH_UART_LCR_EPS |\
118 PCH_UART_LCR_SP)
119
120#define PCH_UART_LCR_5BIT 0x00000000
121#define PCH_UART_LCR_6BIT 0x00000001
122#define PCH_UART_LCR_7BIT 0x00000002
123#define PCH_UART_LCR_8BIT 0x00000003
124
125#define PCH_UART_MCR_DTR 0x00000001
126#define PCH_UART_MCR_RTS 0x00000002
127#define PCH_UART_MCR_OUT 0x0000000C
128#define PCH_UART_MCR_LOOP 0x00000010
129#define PCH_UART_MCR_AFE 0x00000020
130
131#define PCH_UART_LSR_DR 0x00000001
132#define PCH_UART_LSR_ERR (1<<7)
133
134#define PCH_UART_MSR_DCTS 0x00000001
135#define PCH_UART_MSR_DDSR 0x00000002
136#define PCH_UART_MSR_TERI 0x00000004
137#define PCH_UART_MSR_DDCD 0x00000008
138#define PCH_UART_MSR_CTS 0x00000010
139#define PCH_UART_MSR_DSR 0x00000020
140#define PCH_UART_MSR_RI 0x00000040
141#define PCH_UART_MSR_DCD 0x00000080
142#define PCH_UART_MSR_DELTA (PCH_UART_MSR_DCTS | PCH_UART_MSR_DDSR |\
143 PCH_UART_MSR_TERI | PCH_UART_MSR_DDCD)
144
145#define PCH_UART_DLL 0x00
146#define PCH_UART_DLM 0x01
147
Feng Tangd0114112012-02-06 17:24:43 +0800148#define PCH_UART_BRCSR 0x0E
149
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900150#define PCH_UART_IID_RLS (PCH_UART_IIR_REI)
151#define PCH_UART_IID_RDR (PCH_UART_IIR_RRI)
152#define PCH_UART_IID_RDR_TO (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI)
153#define PCH_UART_IID_THRE (PCH_UART_IIR_TRI)
154#define PCH_UART_IID_MS (PCH_UART_IIR_MSI)
155
156#define PCH_UART_HAL_PARITY_NONE (PCH_UART_LCR_NP)
157#define PCH_UART_HAL_PARITY_ODD (PCH_UART_LCR_OP)
158#define PCH_UART_HAL_PARITY_EVEN (PCH_UART_LCR_EP)
159#define PCH_UART_HAL_PARITY_FIX1 (PCH_UART_LCR_1P)
160#define PCH_UART_HAL_PARITY_FIX0 (PCH_UART_LCR_0P)
161#define PCH_UART_HAL_5BIT (PCH_UART_LCR_5BIT)
162#define PCH_UART_HAL_6BIT (PCH_UART_LCR_6BIT)
163#define PCH_UART_HAL_7BIT (PCH_UART_LCR_7BIT)
164#define PCH_UART_HAL_8BIT (PCH_UART_LCR_8BIT)
165#define PCH_UART_HAL_STB1 0
166#define PCH_UART_HAL_STB2 (PCH_UART_LCR_STB)
167
168#define PCH_UART_HAL_CLR_TX_FIFO (PCH_UART_FCR_TFR)
169#define PCH_UART_HAL_CLR_RX_FIFO (PCH_UART_FCR_RFR)
170#define PCH_UART_HAL_CLR_ALL_FIFO (PCH_UART_HAL_CLR_TX_FIFO | \
171 PCH_UART_HAL_CLR_RX_FIFO)
172
173#define PCH_UART_HAL_DMA_MODE0 0
174#define PCH_UART_HAL_FIFO_DIS 0
175#define PCH_UART_HAL_FIFO16 (PCH_UART_FCR_FIFOE)
176#define PCH_UART_HAL_FIFO256 (PCH_UART_FCR_FIFOE | \
177 PCH_UART_FCR_FIFO256)
178#define PCH_UART_HAL_FIFO64 (PCH_UART_HAL_FIFO256)
179#define PCH_UART_HAL_TRIGGER1 (PCH_UART_FCR_RFTL1)
180#define PCH_UART_HAL_TRIGGER64 (PCH_UART_FCR_RFTL64)
181#define PCH_UART_HAL_TRIGGER128 (PCH_UART_FCR_RFTL128)
182#define PCH_UART_HAL_TRIGGER224 (PCH_UART_FCR_RFTL224)
183#define PCH_UART_HAL_TRIGGER16 (PCH_UART_FCR_RFTL16)
184#define PCH_UART_HAL_TRIGGER32 (PCH_UART_FCR_RFTL32)
185#define PCH_UART_HAL_TRIGGER56 (PCH_UART_FCR_RFTL56)
186#define PCH_UART_HAL_TRIGGER4 (PCH_UART_FCR_RFTL4)
187#define PCH_UART_HAL_TRIGGER8 (PCH_UART_FCR_RFTL8)
188#define PCH_UART_HAL_TRIGGER14 (PCH_UART_FCR_RFTL14)
189#define PCH_UART_HAL_TRIGGER_L (PCH_UART_FCR_RFTL64)
190#define PCH_UART_HAL_TRIGGER_M (PCH_UART_FCR_RFTL128)
191#define PCH_UART_HAL_TRIGGER_H (PCH_UART_FCR_RFTL224)
192
193#define PCH_UART_HAL_RX_INT (PCH_UART_IER_ERBFI)
194#define PCH_UART_HAL_TX_INT (PCH_UART_IER_ETBEI)
195#define PCH_UART_HAL_RX_ERR_INT (PCH_UART_IER_ELSI)
196#define PCH_UART_HAL_MS_INT (PCH_UART_IER_EDSSI)
197#define PCH_UART_HAL_ALL_INT (PCH_UART_IER_MASK)
198
199#define PCH_UART_HAL_DTR (PCH_UART_MCR_DTR)
200#define PCH_UART_HAL_RTS (PCH_UART_MCR_RTS)
201#define PCH_UART_HAL_OUT (PCH_UART_MCR_OUT)
202#define PCH_UART_HAL_LOOP (PCH_UART_MCR_LOOP)
203#define PCH_UART_HAL_AFE (PCH_UART_MCR_AFE)
204
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +0900205#define PCI_VENDOR_ID_ROHM 0x10DB
206
Alexander Steine30f8672011-11-15 15:04:07 -0800207#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
208
Darren Hart077175f2012-03-09 09:51:49 -0800209#define DEFAULT_UARTCLK 1843200 /* 1.8432 MHz */
210#define CMITC_UARTCLK 192000000 /* 192.0000 MHz */
211#define FRI2_64_UARTCLK 64000000 /* 64.0000 MHz */
212#define FRI2_48_UARTCLK 48000000 /* 48.0000 MHz */
Michael Brunner11bbd5b2012-03-23 11:06:37 +0100213#define NTC1_UARTCLK 64000000 /* 64.0000 MHz */
Alexander Steine30f8672011-11-15 15:04:07 -0800214
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900215struct pch_uart_buffer {
216 unsigned char *buf;
217 int size;
218};
219
220struct eg20t_port {
221 struct uart_port port;
222 int port_type;
223 void __iomem *membase;
224 resource_size_t mapbase;
225 unsigned int iobase;
226 struct pci_dev *pdev;
227 int fifo_size;
Darren Harta8a3ec92012-03-09 09:51:48 -0800228 int uartclk;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900229 int start_tx;
230 int start_rx;
231 int tx_empty;
232 int int_dis_flag;
233 int trigger;
234 int trigger_level;
235 struct pch_uart_buffer rxbuf;
236 unsigned int dmsr;
237 unsigned int fcr;
Tomoya MORINAGA9af71552011-02-23 10:03:17 +0900238 unsigned int mcr;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900239 unsigned int use_dma;
240 unsigned int use_dma_flag;
241 struct dma_async_tx_descriptor *desc_tx;
242 struct dma_async_tx_descriptor *desc_rx;
243 struct pch_dma_slave param_tx;
244 struct pch_dma_slave param_rx;
245 struct dma_chan *chan_tx;
246 struct dma_chan *chan_rx;
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900247 struct scatterlist *sg_tx_p;
248 int nent;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900249 struct scatterlist sg_rx;
250 int tx_dma_use;
251 void *rx_buf_virt;
252 dma_addr_t rx_buf_dma;
Feng Tangd0114112012-02-06 17:24:43 +0800253
254 struct dentry *debugfs;
Darren Hart61df4452012-06-19 14:00:18 -0700255
256 /* protect the eg20t_port private structure and io access to membase */
257 spinlock_t lock;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900258};
259
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +0900260/**
261 * struct pch_uart_driver_data - private data structure for UART-DMA
262 * @port_type: The number of DMA channel
263 * @line_no: UART port line number (0, 1, 2...)
264 */
265struct pch_uart_driver_data {
266 int port_type;
267 int line_no;
268};
269
270enum pch_uart_num_t {
271 pch_et20t_uart0 = 0,
272 pch_et20t_uart1,
273 pch_et20t_uart2,
274 pch_et20t_uart3,
275 pch_ml7213_uart0,
276 pch_ml7213_uart1,
277 pch_ml7213_uart2,
Tomoya MORINAGA177c2cb2011-05-09 17:25:20 +0900278 pch_ml7223_uart0,
279 pch_ml7223_uart1,
Tomoya MORINAGA8249f742011-10-28 09:38:49 +0900280 pch_ml7831_uart0,
281 pch_ml7831_uart1,
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +0900282};
283
284static struct pch_uart_driver_data drv_dat[] = {
285 [pch_et20t_uart0] = {PCH_UART_8LINE, 0},
286 [pch_et20t_uart1] = {PCH_UART_2LINE, 1},
287 [pch_et20t_uart2] = {PCH_UART_2LINE, 2},
288 [pch_et20t_uart3] = {PCH_UART_2LINE, 3},
289 [pch_ml7213_uart0] = {PCH_UART_8LINE, 0},
290 [pch_ml7213_uart1] = {PCH_UART_2LINE, 1},
291 [pch_ml7213_uart2] = {PCH_UART_2LINE, 2},
Tomoya MORINAGA177c2cb2011-05-09 17:25:20 +0900292 [pch_ml7223_uart0] = {PCH_UART_8LINE, 0},
293 [pch_ml7223_uart1] = {PCH_UART_2LINE, 1},
Tomoya MORINAGA8249f742011-10-28 09:38:49 +0900294 [pch_ml7831_uart0] = {PCH_UART_8LINE, 0},
295 [pch_ml7831_uart1] = {PCH_UART_2LINE, 1},
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +0900296};
297
Alexander Steine30f8672011-11-15 15:04:07 -0800298#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
299static struct eg20t_port *pch_uart_ports[PCH_UART_NR];
300#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900301static unsigned int default_baud = 9600;
Darren Hart2a44feb2012-03-09 09:51:50 -0800302static unsigned int user_uartclk = 0;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900303static const int trigger_level_256[4] = { 1, 64, 128, 224 };
304static const int trigger_level_64[4] = { 1, 16, 32, 56 };
305static const int trigger_level_16[4] = { 1, 4, 8, 14 };
306static const int trigger_level_1[4] = { 1, 1, 1, 1 };
307
Feng Tangd0114112012-02-06 17:24:43 +0800308#ifdef CONFIG_DEBUG_FS
309
310#define PCH_REGS_BUFSIZE 1024
Stephen Boyd234e3402012-04-05 14:25:11 -0700311
Feng Tangd0114112012-02-06 17:24:43 +0800312
313static ssize_t port_show_regs(struct file *file, char __user *user_buf,
314 size_t count, loff_t *ppos)
315{
316 struct eg20t_port *priv = file->private_data;
317 char *buf;
318 u32 len = 0;
319 ssize_t ret;
320 unsigned char lcr;
321
322 buf = kzalloc(PCH_REGS_BUFSIZE, GFP_KERNEL);
323 if (!buf)
324 return 0;
325
326 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
327 "PCH EG20T port[%d] regs:\n", priv->port.line);
328
329 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
330 "=================================\n");
331 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
332 "IER: \t0x%02x\n", ioread8(priv->membase + UART_IER));
333 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
334 "IIR: \t0x%02x\n", ioread8(priv->membase + UART_IIR));
335 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
336 "LCR: \t0x%02x\n", ioread8(priv->membase + UART_LCR));
337 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
338 "MCR: \t0x%02x\n", ioread8(priv->membase + UART_MCR));
339 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
340 "LSR: \t0x%02x\n", ioread8(priv->membase + UART_LSR));
341 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
342 "MSR: \t0x%02x\n", ioread8(priv->membase + UART_MSR));
343 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
344 "BRCSR: \t0x%02x\n",
345 ioread8(priv->membase + PCH_UART_BRCSR));
346
347 lcr = ioread8(priv->membase + UART_LCR);
348 iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR);
349 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
350 "DLL: \t0x%02x\n", ioread8(priv->membase + UART_DLL));
351 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
352 "DLM: \t0x%02x\n", ioread8(priv->membase + UART_DLM));
353 iowrite8(lcr, priv->membase + UART_LCR);
354
355 if (len > PCH_REGS_BUFSIZE)
356 len = PCH_REGS_BUFSIZE;
357
358 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
359 kfree(buf);
360 return ret;
361}
362
363static const struct file_operations port_regs_ops = {
364 .owner = THIS_MODULE,
Stephen Boyd234e3402012-04-05 14:25:11 -0700365 .open = simple_open,
Feng Tangd0114112012-02-06 17:24:43 +0800366 .read = port_show_regs,
367 .llseek = default_llseek,
368};
369#endif /* CONFIG_DEBUG_FS */
370
Darren Hart077175f2012-03-09 09:51:49 -0800371/* Return UART clock, checking for board specific clocks. */
372static int pch_uart_get_uartclk(void)
373{
374 const char *cmp;
375
Darren Hart2a44feb2012-03-09 09:51:50 -0800376 if (user_uartclk)
377 return user_uartclk;
378
Darren Hart077175f2012-03-09 09:51:49 -0800379 cmp = dmi_get_system_info(DMI_BOARD_NAME);
380 if (cmp && strstr(cmp, "CM-iTC"))
381 return CMITC_UARTCLK;
382
383 cmp = dmi_get_system_info(DMI_BIOS_VERSION);
384 if (cmp && strnstr(cmp, "FRI2", 4))
385 return FRI2_64_UARTCLK;
386
387 cmp = dmi_get_system_info(DMI_PRODUCT_NAME);
388 if (cmp && strstr(cmp, "Fish River Island II"))
389 return FRI2_48_UARTCLK;
390
Michael Brunner11bbd5b2012-03-23 11:06:37 +0100391 /* Kontron COMe-mTT10 (nanoETXexpress-TT) */
392 cmp = dmi_get_system_info(DMI_BOARD_NAME);
393 if (cmp && (strstr(cmp, "COMe-mTT") ||
394 strstr(cmp, "nanoETXexpress-TT")))
395 return NTC1_UARTCLK;
396
Darren Hart077175f2012-03-09 09:51:49 -0800397 return DEFAULT_UARTCLK;
398}
399
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900400static void pch_uart_hal_enable_interrupt(struct eg20t_port *priv,
401 unsigned int flag)
402{
403 u8 ier = ioread8(priv->membase + UART_IER);
404 ier |= flag & PCH_UART_IER_MASK;
405 iowrite8(ier, priv->membase + UART_IER);
406}
407
408static void pch_uart_hal_disable_interrupt(struct eg20t_port *priv,
409 unsigned int flag)
410{
411 u8 ier = ioread8(priv->membase + UART_IER);
412 ier &= ~(flag & PCH_UART_IER_MASK);
413 iowrite8(ier, priv->membase + UART_IER);
414}
415
416static int pch_uart_hal_set_line(struct eg20t_port *priv, int baud,
417 unsigned int parity, unsigned int bits,
418 unsigned int stb)
419{
420 unsigned int dll, dlm, lcr;
421 int div;
422
Darren Harta8a3ec92012-03-09 09:51:48 -0800423 div = DIV_ROUND_CLOSEST(priv->uartclk / 16, baud);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900424 if (div < 0 || USHRT_MAX <= div) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900425 dev_err(priv->port.dev, "Invalid Baud(div=0x%x)\n", div);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900426 return -EINVAL;
427 }
428
429 dll = (unsigned int)div & 0x00FFU;
430 dlm = ((unsigned int)div >> 8) & 0x00FFU;
431
432 if (parity & ~(PCH_UART_LCR_PEN | PCH_UART_LCR_EPS | PCH_UART_LCR_SP)) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900433 dev_err(priv->port.dev, "Invalid parity(0x%x)\n", parity);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900434 return -EINVAL;
435 }
436
437 if (bits & ~PCH_UART_LCR_WLS) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900438 dev_err(priv->port.dev, "Invalid bits(0x%x)\n", bits);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900439 return -EINVAL;
440 }
441
442 if (stb & ~PCH_UART_LCR_STB) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900443 dev_err(priv->port.dev, "Invalid STB(0x%x)\n", stb);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900444 return -EINVAL;
445 }
446
447 lcr = parity;
448 lcr |= bits;
449 lcr |= stb;
450
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900451 dev_dbg(priv->port.dev, "%s:baud = %d, div = %04x, lcr = %02x (%lu)\n",
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900452 __func__, baud, div, lcr, jiffies);
453 iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR);
454 iowrite8(dll, priv->membase + PCH_UART_DLL);
455 iowrite8(dlm, priv->membase + PCH_UART_DLM);
456 iowrite8(lcr, priv->membase + UART_LCR);
457
458 return 0;
459}
460
461static int pch_uart_hal_fifo_reset(struct eg20t_port *priv,
462 unsigned int flag)
463{
464 if (flag & ~(PCH_UART_FCR_TFR | PCH_UART_FCR_RFR)) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900465 dev_err(priv->port.dev, "%s:Invalid flag(0x%x)\n",
466 __func__, flag);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900467 return -EINVAL;
468 }
469
470 iowrite8(PCH_UART_FCR_FIFOE | priv->fcr, priv->membase + UART_FCR);
471 iowrite8(PCH_UART_FCR_FIFOE | priv->fcr | flag,
472 priv->membase + UART_FCR);
473 iowrite8(priv->fcr, priv->membase + UART_FCR);
474
475 return 0;
476}
477
478static int pch_uart_hal_set_fifo(struct eg20t_port *priv,
479 unsigned int dmamode,
480 unsigned int fifo_size, unsigned int trigger)
481{
482 u8 fcr;
483
484 if (dmamode & ~PCH_UART_FCR_DMS) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900485 dev_err(priv->port.dev, "%s:Invalid DMA Mode(0x%x)\n",
486 __func__, dmamode);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900487 return -EINVAL;
488 }
489
490 if (fifo_size & ~(PCH_UART_FCR_FIFOE | PCH_UART_FCR_FIFO256)) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900491 dev_err(priv->port.dev, "%s:Invalid FIFO SIZE(0x%x)\n",
492 __func__, fifo_size);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900493 return -EINVAL;
494 }
495
496 if (trigger & ~PCH_UART_FCR_RFTL) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900497 dev_err(priv->port.dev, "%s:Invalid TRIGGER(0x%x)\n",
498 __func__, trigger);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900499 return -EINVAL;
500 }
501
502 switch (priv->fifo_size) {
503 case 256:
504 priv->trigger_level =
505 trigger_level_256[trigger >> PCH_UART_FCR_RFTL_SHIFT];
506 break;
507 case 64:
508 priv->trigger_level =
509 trigger_level_64[trigger >> PCH_UART_FCR_RFTL_SHIFT];
510 break;
511 case 16:
512 priv->trigger_level =
513 trigger_level_16[trigger >> PCH_UART_FCR_RFTL_SHIFT];
514 break;
515 default:
516 priv->trigger_level =
517 trigger_level_1[trigger >> PCH_UART_FCR_RFTL_SHIFT];
518 break;
519 }
520 fcr =
521 dmamode | fifo_size | trigger | PCH_UART_FCR_RFR | PCH_UART_FCR_TFR;
522 iowrite8(PCH_UART_FCR_FIFOE, priv->membase + UART_FCR);
523 iowrite8(PCH_UART_FCR_FIFOE | PCH_UART_FCR_RFR | PCH_UART_FCR_TFR,
524 priv->membase + UART_FCR);
525 iowrite8(fcr, priv->membase + UART_FCR);
526 priv->fcr = fcr;
527
528 return 0;
529}
530
531static u8 pch_uart_hal_get_modem(struct eg20t_port *priv)
532{
Feng Tang30c6c6b2012-02-06 17:24:44 +0800533 unsigned int msr = ioread8(priv->membase + UART_MSR);
534 priv->dmsr = msr & PCH_UART_MSR_DELTA;
535 return (u8)msr;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900536}
537
Tomoya MORINAGA18220762011-02-23 10:03:14 +0900538static void pch_uart_hal_write(struct eg20t_port *priv,
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900539 const unsigned char *buf, int tx_size)
540{
541 int i;
542 unsigned int thr;
543
544 for (i = 0; i < tx_size;) {
545 thr = buf[i++];
546 iowrite8(thr, priv->membase + PCH_UART_THR);
547 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900548}
549
550static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf,
551 int rx_size)
552{
553 int i;
554 u8 rbr, lsr;
555
556 lsr = ioread8(priv->membase + UART_LSR);
557 for (i = 0, lsr = ioread8(priv->membase + UART_LSR);
558 i < rx_size && lsr & UART_LSR_DR;
559 lsr = ioread8(priv->membase + UART_LSR)) {
560 rbr = ioread8(priv->membase + PCH_UART_RBR);
561 buf[i++] = rbr;
562 }
563 return i;
564}
565
566static unsigned int pch_uart_hal_get_iid(struct eg20t_port *priv)
567{
568 unsigned int iir;
569 int ret;
570
571 iir = ioread8(priv->membase + UART_IIR);
572 ret = (iir & (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP));
573 return ret;
574}
575
576static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv)
577{
578 return ioread8(priv->membase + UART_LSR);
579}
580
581static void pch_uart_hal_set_break(struct eg20t_port *priv, int on)
582{
583 unsigned int lcr;
584
585 lcr = ioread8(priv->membase + UART_LCR);
586 if (on)
587 lcr |= PCH_UART_LCR_SB;
588 else
589 lcr &= ~PCH_UART_LCR_SB;
590
591 iowrite8(lcr, priv->membase + UART_LCR);
592}
593
594static int push_rx(struct eg20t_port *priv, const unsigned char *buf,
595 int size)
596{
597 struct uart_port *port;
598 struct tty_struct *tty;
599
600 port = &priv->port;
601 tty = tty_port_tty_get(&port->state->port);
602 if (!tty) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900603 dev_dbg(priv->port.dev, "%s:tty is busy now", __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900604 return -EBUSY;
605 }
606
607 tty_insert_flip_string(tty, buf, size);
608 tty_flip_buffer_push(tty);
609 tty_kref_put(tty);
610
611 return 0;
612}
613
614static int pop_tx_x(struct eg20t_port *priv, unsigned char *buf)
615{
Feng Tang30c6c6b2012-02-06 17:24:44 +0800616 int ret = 0;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900617 struct uart_port *port = &priv->port;
618
619 if (port->x_char) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900620 dev_dbg(priv->port.dev, "%s:X character send %02x (%lu)\n",
621 __func__, port->x_char, jiffies);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900622 buf[0] = port->x_char;
623 port->x_char = 0;
624 ret = 1;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900625 }
626
627 return ret;
628}
629
630static int dma_push_rx(struct eg20t_port *priv, int size)
631{
632 struct tty_struct *tty;
633 int room;
634 struct uart_port *port = &priv->port;
635
636 port = &priv->port;
637 tty = tty_port_tty_get(&port->state->port);
638 if (!tty) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900639 dev_dbg(priv->port.dev, "%s:tty is busy now", __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900640 return 0;
641 }
642
643 room = tty_buffer_request_room(tty, size);
644
645 if (room < size)
646 dev_warn(port->dev, "Rx overrun: dropping %u bytes\n",
647 size - room);
648 if (!room)
649 return room;
650
651 tty_insert_flip_string(tty, sg_virt(&priv->sg_rx), size);
652
653 port->icount.rx += room;
654 tty_kref_put(tty);
655
656 return room;
657}
658
659static void pch_free_dma(struct uart_port *port)
660{
661 struct eg20t_port *priv;
662 priv = container_of(port, struct eg20t_port, port);
663
664 if (priv->chan_tx) {
665 dma_release_channel(priv->chan_tx);
666 priv->chan_tx = NULL;
667 }
668 if (priv->chan_rx) {
669 dma_release_channel(priv->chan_rx);
670 priv->chan_rx = NULL;
671 }
672 if (sg_dma_address(&priv->sg_rx))
673 dma_free_coherent(port->dev, port->fifosize,
674 sg_virt(&priv->sg_rx),
675 sg_dma_address(&priv->sg_rx));
676
677 return;
678}
679
680static bool filter(struct dma_chan *chan, void *slave)
681{
682 struct pch_dma_slave *param = slave;
683
684 if ((chan->chan_id == param->chan_id) && (param->dma_dev ==
685 chan->device->dev)) {
686 chan->private = param;
687 return true;
688 } else {
689 return false;
690 }
691}
692
693static void pch_request_dma(struct uart_port *port)
694{
695 dma_cap_mask_t mask;
696 struct dma_chan *chan;
697 struct pci_dev *dma_dev;
698 struct pch_dma_slave *param;
699 struct eg20t_port *priv =
700 container_of(port, struct eg20t_port, port);
701 dma_cap_zero(mask);
702 dma_cap_set(DMA_SLAVE, mask);
703
Tomoya MORINAGA6c4b47d2011-07-20 20:17:49 +0900704 dma_dev = pci_get_bus_and_slot(priv->pdev->bus->number,
705 PCI_DEVFN(0xa, 0)); /* Get DMA's dev
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900706 information */
707 /* Set Tx DMA */
708 param = &priv->param_tx;
709 param->dma_dev = &dma_dev->dev;
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +0900710 param->chan_id = priv->port.line * 2; /* Tx = 0, 2, 4, ... */
711
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900712 param->tx_reg = port->mapbase + UART_TX;
713 chan = dma_request_channel(mask, filter, param);
714 if (!chan) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900715 dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Tx)\n",
716 __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900717 return;
718 }
719 priv->chan_tx = chan;
720
721 /* Set Rx DMA */
722 param = &priv->param_rx;
723 param->dma_dev = &dma_dev->dev;
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +0900724 param->chan_id = priv->port.line * 2 + 1; /* Rx = Tx + 1 */
725
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900726 param->rx_reg = port->mapbase + UART_RX;
727 chan = dma_request_channel(mask, filter, param);
728 if (!chan) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900729 dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Rx)\n",
730 __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900731 dma_release_channel(priv->chan_tx);
Tomoya MORINAGA90f04c22011-11-11 10:55:27 +0900732 priv->chan_tx = NULL;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900733 return;
734 }
735
736 /* Get Consistent memory for DMA */
737 priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
738 &priv->rx_buf_dma, GFP_KERNEL);
739 priv->chan_rx = chan;
740}
741
742static void pch_dma_rx_complete(void *arg)
743{
744 struct eg20t_port *priv = arg;
745 struct uart_port *port = &priv->port;
746 struct tty_struct *tty = tty_port_tty_get(&port->state->port);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900747 int count;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900748
749 if (!tty) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900750 dev_dbg(priv->port.dev, "%s:tty is busy now", __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900751 return;
752 }
753
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900754 dma_sync_sg_for_cpu(port->dev, &priv->sg_rx, 1, DMA_FROM_DEVICE);
755 count = dma_push_rx(priv, priv->trigger_level);
756 if (count)
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900757 tty_flip_buffer_push(tty);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900758 tty_kref_put(tty);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900759 async_tx_ack(priv->desc_rx);
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +0900760 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT |
761 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900762}
763
764static void pch_dma_tx_complete(void *arg)
765{
766 struct eg20t_port *priv = arg;
767 struct uart_port *port = &priv->port;
768 struct circ_buf *xmit = &port->state->xmit;
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900769 struct scatterlist *sg = priv->sg_tx_p;
770 int i;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900771
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900772 for (i = 0; i < priv->nent; i++, sg++) {
773 xmit->tail += sg_dma_len(sg);
774 port->icount.tx += sg_dma_len(sg);
775 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900776 xmit->tail &= UART_XMIT_SIZE - 1;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900777 async_tx_ack(priv->desc_tx);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900778 dma_unmap_sg(port->dev, sg, priv->nent, DMA_TO_DEVICE);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900779 priv->tx_dma_use = 0;
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900780 priv->nent = 0;
781 kfree(priv->sg_tx_p);
Tomoya MORINAGA60d10312011-02-23 10:03:18 +0900782 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_TX_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900783}
784
Tomoya MORINAGA18220762011-02-23 10:03:14 +0900785static int pop_tx(struct eg20t_port *priv, int size)
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900786{
787 int count = 0;
788 struct uart_port *port = &priv->port;
789 struct circ_buf *xmit = &port->state->xmit;
790
791 if (uart_tx_stopped(port) || uart_circ_empty(xmit) || count >= size)
792 goto pop_tx_end;
793
794 do {
795 int cnt_to_end =
796 CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
797 int sz = min(size - count, cnt_to_end);
Tomoya MORINAGA18220762011-02-23 10:03:14 +0900798 pch_uart_hal_write(priv, &xmit->buf[xmit->tail], sz);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900799 xmit->tail = (xmit->tail + sz) & (UART_XMIT_SIZE - 1);
800 count += sz;
801 } while (!uart_circ_empty(xmit) && count < size);
802
803pop_tx_end:
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900804 dev_dbg(priv->port.dev, "%d characters. Remained %d characters.(%lu)\n",
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900805 count, size - count, jiffies);
806
807 return count;
808}
809
810static int handle_rx_to(struct eg20t_port *priv)
811{
812 struct pch_uart_buffer *buf;
813 int rx_size;
814 int ret;
815 if (!priv->start_rx) {
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +0900816 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT |
817 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900818 return 0;
819 }
820 buf = &priv->rxbuf;
821 do {
822 rx_size = pch_uart_hal_read(priv, buf->buf, buf->size);
823 ret = push_rx(priv, buf->buf, rx_size);
824 if (ret)
825 return 0;
826 } while (rx_size == buf->size);
827
828 return PCH_UART_HANDLED_RX_INT;
829}
830
831static int handle_rx(struct eg20t_port *priv)
832{
833 return handle_rx_to(priv);
834}
835
836static int dma_handle_rx(struct eg20t_port *priv)
837{
838 struct uart_port *port = &priv->port;
839 struct dma_async_tx_descriptor *desc;
840 struct scatterlist *sg;
841
842 priv = container_of(port, struct eg20t_port, port);
843 sg = &priv->sg_rx;
844
845 sg_init_table(&priv->sg_rx, 1); /* Initialize SG table */
846
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900847 sg_dma_len(sg) = priv->trigger_level;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900848
849 sg_set_page(&priv->sg_rx, virt_to_page(priv->rx_buf_virt),
Tomoya MORINAGA1c518992010-12-16 16:13:29 +0900850 sg_dma_len(sg), (unsigned long)priv->rx_buf_virt &
851 ~PAGE_MASK);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900852
853 sg_dma_address(sg) = priv->rx_buf_dma;
854
Alexandre Bounine16052822012-03-08 16:11:18 -0500855 desc = dmaengine_prep_slave_sg(priv->chan_rx,
Vinod Koula485df42011-10-14 10:47:38 +0530856 sg, 1, DMA_DEV_TO_MEM,
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900857 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
858
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900859 if (!desc)
860 return 0;
861
862 priv->desc_rx = desc;
863 desc->callback = pch_dma_rx_complete;
864 desc->callback_param = priv;
865 desc->tx_submit(desc);
866 dma_async_issue_pending(priv->chan_rx);
867
868 return PCH_UART_HANDLED_RX_INT;
869}
870
871static unsigned int handle_tx(struct eg20t_port *priv)
872{
873 struct uart_port *port = &priv->port;
874 struct circ_buf *xmit = &port->state->xmit;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900875 int fifo_size;
876 int tx_size;
877 int size;
878 int tx_empty;
879
880 if (!priv->start_tx) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900881 dev_info(priv->port.dev, "%s:Tx isn't started. (%lu)\n",
882 __func__, jiffies);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900883 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
884 priv->tx_empty = 1;
885 return 0;
886 }
887
888 fifo_size = max(priv->fifo_size, 1);
889 tx_empty = 1;
890 if (pop_tx_x(priv, xmit->buf)) {
891 pch_uart_hal_write(priv, xmit->buf, 1);
892 port->icount.tx++;
893 tx_empty = 0;
894 fifo_size--;
895 }
896 size = min(xmit->head - xmit->tail, fifo_size);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900897 if (size < 0)
898 size = fifo_size;
899
Tomoya MORINAGA18220762011-02-23 10:03:14 +0900900 tx_size = pop_tx(priv, size);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900901 if (tx_size > 0) {
Tomoya MORINAGA18220762011-02-23 10:03:14 +0900902 port->icount.tx += tx_size;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900903 tx_empty = 0;
904 }
905
906 priv->tx_empty = tx_empty;
907
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900908 if (tx_empty) {
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900909 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900910 uart_write_wakeup(port);
911 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900912
913 return PCH_UART_HANDLED_TX_INT;
914}
915
916static unsigned int dma_handle_tx(struct eg20t_port *priv)
917{
918 struct uart_port *port = &priv->port;
919 struct circ_buf *xmit = &port->state->xmit;
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900920 struct scatterlist *sg;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900921 int nent;
922 int fifo_size;
923 int tx_empty;
924 struct dma_async_tx_descriptor *desc;
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900925 int num;
926 int i;
927 int bytes;
928 int size;
929 int rem;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900930
931 if (!priv->start_tx) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900932 dev_info(priv->port.dev, "%s:Tx isn't started. (%lu)\n",
933 __func__, jiffies);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900934 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
935 priv->tx_empty = 1;
936 return 0;
937 }
938
Tomoya MORINAGA60d10312011-02-23 10:03:18 +0900939 if (priv->tx_dma_use) {
940 dev_dbg(priv->port.dev, "%s:Tx is not completed. (%lu)\n",
941 __func__, jiffies);
942 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
943 priv->tx_empty = 1;
944 return 0;
945 }
946
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900947 fifo_size = max(priv->fifo_size, 1);
948 tx_empty = 1;
949 if (pop_tx_x(priv, xmit->buf)) {
950 pch_uart_hal_write(priv, xmit->buf, 1);
951 port->icount.tx++;
952 tx_empty = 0;
953 fifo_size--;
954 }
955
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900956 bytes = min((int)CIRC_CNT(xmit->head, xmit->tail,
957 UART_XMIT_SIZE), CIRC_CNT_TO_END(xmit->head,
958 xmit->tail, UART_XMIT_SIZE));
959 if (!bytes) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900960 dev_dbg(priv->port.dev, "%s 0 bytes return\n", __func__);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900961 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
962 uart_write_wakeup(port);
963 return 0;
964 }
965
966 if (bytes > fifo_size) {
967 num = bytes / fifo_size + 1;
968 size = fifo_size;
969 rem = bytes % fifo_size;
970 } else {
971 num = 1;
972 size = bytes;
973 rem = bytes;
974 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900975
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900976 dev_dbg(priv->port.dev, "%s num=%d size=%d rem=%d\n",
977 __func__, num, size, rem);
978
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900979 priv->tx_dma_use = 1;
980
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900981 priv->sg_tx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900982
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900983 sg_init_table(priv->sg_tx_p, num); /* Initialize SG table */
984 sg = priv->sg_tx_p;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900985
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +0900986 for (i = 0; i < num; i++, sg++) {
987 if (i == (num - 1))
988 sg_set_page(sg, virt_to_page(xmit->buf),
989 rem, fifo_size * i);
990 else
991 sg_set_page(sg, virt_to_page(xmit->buf),
992 size, fifo_size * i);
993 }
994
995 sg = priv->sg_tx_p;
996 nent = dma_map_sg(port->dev, sg, num, DMA_TO_DEVICE);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900997 if (!nent) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +0900998 dev_err(priv->port.dev, "%s:dma_map_sg Failed\n", __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +0900999 return 0;
1000 }
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001001 priv->nent = nent;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001002
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001003 for (i = 0; i < nent; i++, sg++) {
1004 sg->offset = (xmit->tail & (UART_XMIT_SIZE - 1)) +
1005 fifo_size * i;
1006 sg_dma_address(sg) = (sg_dma_address(sg) &
1007 ~(UART_XMIT_SIZE - 1)) + sg->offset;
1008 if (i == (nent - 1))
1009 sg_dma_len(sg) = rem;
1010 else
1011 sg_dma_len(sg) = size;
1012 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001013
Alexandre Bounine16052822012-03-08 16:11:18 -05001014 desc = dmaengine_prep_slave_sg(priv->chan_tx,
Vinod Koula485df42011-10-14 10:47:38 +05301015 priv->sg_tx_p, nent, DMA_MEM_TO_DEV,
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001016 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001017 if (!desc) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001018 dev_err(priv->port.dev, "%s:device_prep_slave_sg Failed\n",
1019 __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001020 return 0;
1021 }
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001022 dma_sync_sg_for_device(port->dev, priv->sg_tx_p, nent, DMA_TO_DEVICE);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001023 priv->desc_tx = desc;
1024 desc->callback = pch_dma_tx_complete;
1025 desc->callback_param = priv;
1026
1027 desc->tx_submit(desc);
1028
1029 dma_async_issue_pending(priv->chan_tx);
1030
1031 return PCH_UART_HANDLED_TX_INT;
1032}
1033
1034static void pch_uart_err_ir(struct eg20t_port *priv, unsigned int lsr)
1035{
1036 u8 fcr = ioread8(priv->membase + UART_FCR);
1037
1038 /* Reset FIFO */
1039 fcr |= UART_FCR_CLEAR_RCVR;
1040 iowrite8(fcr, priv->membase + UART_FCR);
1041
1042 if (lsr & PCH_UART_LSR_ERR)
1043 dev_err(&priv->pdev->dev, "Error data in FIFO\n");
1044
1045 if (lsr & UART_LSR_FE)
1046 dev_err(&priv->pdev->dev, "Framing Error\n");
1047
1048 if (lsr & UART_LSR_PE)
1049 dev_err(&priv->pdev->dev, "Parity Error\n");
1050
1051 if (lsr & UART_LSR_OE)
1052 dev_err(&priv->pdev->dev, "Overrun Error\n");
1053}
1054
1055static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1056{
1057 struct eg20t_port *priv = dev_id;
1058 unsigned int handled;
1059 u8 lsr;
1060 int ret = 0;
1061 unsigned int iid;
1062 unsigned long flags;
1063
Darren Hart61df4452012-06-19 14:00:18 -07001064 spin_lock_irqsave(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001065 handled = 0;
1066 while ((iid = pch_uart_hal_get_iid(priv)) > 1) {
1067 switch (iid) {
1068 case PCH_UART_IID_RLS: /* Receiver Line Status */
1069 lsr = pch_uart_hal_get_line_status(priv);
1070 if (lsr & (PCH_UART_LSR_ERR | UART_LSR_FE |
1071 UART_LSR_PE | UART_LSR_OE)) {
1072 pch_uart_err_ir(priv, lsr);
1073 ret = PCH_UART_HANDLED_RX_ERR_INT;
1074 }
1075 break;
1076 case PCH_UART_IID_RDR: /* Received Data Ready */
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001077 if (priv->use_dma) {
1078 pch_uart_hal_disable_interrupt(priv,
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +09001079 PCH_UART_HAL_RX_INT |
1080 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001081 ret = dma_handle_rx(priv);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001082 if (!ret)
1083 pch_uart_hal_enable_interrupt(priv,
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +09001084 PCH_UART_HAL_RX_INT |
1085 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001086 } else {
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001087 ret = handle_rx(priv);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001088 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001089 break;
1090 case PCH_UART_IID_RDR_TO: /* Received Data Ready
1091 (FIFO Timeout) */
1092 ret = handle_rx_to(priv);
1093 break;
1094 case PCH_UART_IID_THRE: /* Transmitter Holding Register
1095 Empty */
1096 if (priv->use_dma)
1097 ret = dma_handle_tx(priv);
1098 else
1099 ret = handle_tx(priv);
1100 break;
1101 case PCH_UART_IID_MS: /* Modem Status */
1102 ret = PCH_UART_HANDLED_MS_INT;
1103 break;
1104 default: /* Never junp to this label */
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001105 dev_err(priv->port.dev, "%s:iid=%d (%lu)\n", __func__,
1106 iid, jiffies);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001107 ret = -1;
1108 break;
1109 }
1110 handled |= (unsigned int)ret;
1111 }
1112 if (handled == 0 && iid <= 1) {
1113 if (priv->int_dis_flag)
1114 priv->int_dis_flag = 0;
1115 }
1116
Darren Hart61df4452012-06-19 14:00:18 -07001117 spin_unlock_irqrestore(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001118 return IRQ_RETVAL(handled);
1119}
1120
1121/* This function tests whether the transmitter fifo and shifter for the port
1122 described by 'port' is empty. */
1123static unsigned int pch_uart_tx_empty(struct uart_port *port)
1124{
1125 struct eg20t_port *priv;
Feng Tang30c6c6b2012-02-06 17:24:44 +08001126
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001127 priv = container_of(port, struct eg20t_port, port);
1128 if (priv->tx_empty)
Feng Tang30c6c6b2012-02-06 17:24:44 +08001129 return TIOCSER_TEMT;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001130 else
Feng Tang30c6c6b2012-02-06 17:24:44 +08001131 return 0;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001132}
1133
1134/* Returns the current state of modem control inputs. */
1135static unsigned int pch_uart_get_mctrl(struct uart_port *port)
1136{
1137 struct eg20t_port *priv;
1138 u8 modem;
1139 unsigned int ret = 0;
1140
1141 priv = container_of(port, struct eg20t_port, port);
1142 modem = pch_uart_hal_get_modem(priv);
1143
1144 if (modem & UART_MSR_DCD)
1145 ret |= TIOCM_CAR;
1146
1147 if (modem & UART_MSR_RI)
1148 ret |= TIOCM_RNG;
1149
1150 if (modem & UART_MSR_DSR)
1151 ret |= TIOCM_DSR;
1152
1153 if (modem & UART_MSR_CTS)
1154 ret |= TIOCM_CTS;
1155
1156 return ret;
1157}
1158
1159static void pch_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
1160{
1161 u32 mcr = 0;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001162 struct eg20t_port *priv = container_of(port, struct eg20t_port, port);
1163
1164 if (mctrl & TIOCM_DTR)
1165 mcr |= UART_MCR_DTR;
1166 if (mctrl & TIOCM_RTS)
1167 mcr |= UART_MCR_RTS;
1168 if (mctrl & TIOCM_LOOP)
1169 mcr |= UART_MCR_LOOP;
1170
Tomoya MORINAGA9af71552011-02-23 10:03:17 +09001171 if (priv->mcr & UART_MCR_AFE)
1172 mcr |= UART_MCR_AFE;
1173
1174 if (mctrl)
1175 iowrite8(mcr, priv->membase + UART_MCR);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001176}
1177
1178static void pch_uart_stop_tx(struct uart_port *port)
1179{
1180 struct eg20t_port *priv;
1181 priv = container_of(port, struct eg20t_port, port);
1182 priv->start_tx = 0;
1183 priv->tx_dma_use = 0;
1184}
1185
1186static void pch_uart_start_tx(struct uart_port *port)
1187{
1188 struct eg20t_port *priv;
1189
1190 priv = container_of(port, struct eg20t_port, port);
1191
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001192 if (priv->use_dma) {
1193 if (priv->tx_dma_use) {
1194 dev_dbg(priv->port.dev, "%s : Tx DMA is NOT empty.\n",
1195 __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001196 return;
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001197 }
1198 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001199
1200 priv->start_tx = 1;
1201 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_TX_INT);
1202}
1203
1204static void pch_uart_stop_rx(struct uart_port *port)
1205{
1206 struct eg20t_port *priv;
1207 priv = container_of(port, struct eg20t_port, port);
1208 priv->start_rx = 0;
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +09001209 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT |
1210 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001211 priv->int_dis_flag = 1;
1212}
1213
1214/* Enable the modem status interrupts. */
1215static void pch_uart_enable_ms(struct uart_port *port)
1216{
1217 struct eg20t_port *priv;
1218 priv = container_of(port, struct eg20t_port, port);
1219 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_MS_INT);
1220}
1221
1222/* Control the transmission of a break signal. */
1223static void pch_uart_break_ctl(struct uart_port *port, int ctl)
1224{
1225 struct eg20t_port *priv;
1226 unsigned long flags;
1227
1228 priv = container_of(port, struct eg20t_port, port);
Darren Hart61df4452012-06-19 14:00:18 -07001229 spin_lock_irqsave(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001230 pch_uart_hal_set_break(priv, ctl);
Darren Hart61df4452012-06-19 14:00:18 -07001231 spin_unlock_irqrestore(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001232}
1233
1234/* Grab any interrupt resources and initialise any low level driver state. */
1235static int pch_uart_startup(struct uart_port *port)
1236{
1237 struct eg20t_port *priv;
1238 int ret;
1239 int fifo_size;
1240 int trigger_level;
1241
1242 priv = container_of(port, struct eg20t_port, port);
1243 priv->tx_empty = 1;
Tomoya MORINAGAaac6c0b2011-02-23 10:03:16 +09001244
1245 if (port->uartclk)
Darren Harta8a3ec92012-03-09 09:51:48 -08001246 priv->uartclk = port->uartclk;
Tomoya MORINAGAaac6c0b2011-02-23 10:03:16 +09001247 else
Darren Harta8a3ec92012-03-09 09:51:48 -08001248 port->uartclk = priv->uartclk;
Tomoya MORINAGAaac6c0b2011-02-23 10:03:16 +09001249
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001250 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1251 ret = pch_uart_hal_set_line(priv, default_baud,
1252 PCH_UART_HAL_PARITY_NONE, PCH_UART_HAL_8BIT,
1253 PCH_UART_HAL_STB1);
1254 if (ret)
1255 return ret;
1256
1257 switch (priv->fifo_size) {
1258 case 256:
1259 fifo_size = PCH_UART_HAL_FIFO256;
1260 break;
1261 case 64:
1262 fifo_size = PCH_UART_HAL_FIFO64;
1263 break;
1264 case 16:
1265 fifo_size = PCH_UART_HAL_FIFO16;
Alan Cox17361b32012-07-02 18:51:38 +01001266 break;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001267 case 1:
1268 default:
1269 fifo_size = PCH_UART_HAL_FIFO_DIS;
1270 break;
1271 }
1272
1273 switch (priv->trigger) {
1274 case PCH_UART_HAL_TRIGGER1:
1275 trigger_level = 1;
1276 break;
1277 case PCH_UART_HAL_TRIGGER_L:
1278 trigger_level = priv->fifo_size / 4;
1279 break;
1280 case PCH_UART_HAL_TRIGGER_M:
1281 trigger_level = priv->fifo_size / 2;
1282 break;
1283 case PCH_UART_HAL_TRIGGER_H:
1284 default:
1285 trigger_level = priv->fifo_size - (priv->fifo_size / 8);
1286 break;
1287 }
1288
1289 priv->trigger_level = trigger_level;
1290 ret = pch_uart_hal_set_fifo(priv, PCH_UART_HAL_DMA_MODE0,
1291 fifo_size, priv->trigger);
1292 if (ret < 0)
1293 return ret;
1294
1295 ret = request_irq(priv->port.irq, pch_uart_interrupt, IRQF_SHARED,
1296 KBUILD_MODNAME, priv);
1297 if (ret < 0)
1298 return ret;
1299
1300 if (priv->use_dma)
1301 pch_request_dma(port);
1302
1303 priv->start_rx = 1;
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +09001304 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT |
1305 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001306 uart_update_timeout(port, CS8, default_baud);
1307
1308 return 0;
1309}
1310
1311static void pch_uart_shutdown(struct uart_port *port)
1312{
1313 struct eg20t_port *priv;
1314 int ret;
1315
1316 priv = container_of(port, struct eg20t_port, port);
1317 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1318 pch_uart_hal_fifo_reset(priv, PCH_UART_HAL_CLR_ALL_FIFO);
1319 ret = pch_uart_hal_set_fifo(priv, PCH_UART_HAL_DMA_MODE0,
1320 PCH_UART_HAL_FIFO_DIS, PCH_UART_HAL_TRIGGER1);
1321 if (ret)
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001322 dev_err(priv->port.dev,
1323 "pch_uart_hal_set_fifo Failed(ret=%d)\n", ret);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001324
Tomoya MORINAGA90f04c22011-11-11 10:55:27 +09001325 pch_free_dma(port);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001326
1327 free_irq(priv->port.irq, priv);
1328}
1329
1330/* Change the port parameters, including word length, parity, stop
1331 *bits. Update read_status_mask and ignore_status_mask to indicate
1332 *the types of events we are interested in receiving. */
1333static void pch_uart_set_termios(struct uart_port *port,
1334 struct ktermios *termios, struct ktermios *old)
1335{
1336 int baud;
1337 int rtn;
1338 unsigned int parity, bits, stb;
1339 struct eg20t_port *priv;
1340 unsigned long flags;
1341
1342 priv = container_of(port, struct eg20t_port, port);
1343 switch (termios->c_cflag & CSIZE) {
1344 case CS5:
1345 bits = PCH_UART_HAL_5BIT;
1346 break;
1347 case CS6:
1348 bits = PCH_UART_HAL_6BIT;
1349 break;
1350 case CS7:
1351 bits = PCH_UART_HAL_7BIT;
1352 break;
1353 default: /* CS8 */
1354 bits = PCH_UART_HAL_8BIT;
1355 break;
1356 }
1357 if (termios->c_cflag & CSTOPB)
1358 stb = PCH_UART_HAL_STB2;
1359 else
1360 stb = PCH_UART_HAL_STB1;
1361
1362 if (termios->c_cflag & PARENB) {
Tomoya MORINAGA3dcb5362012-07-06 17:19:43 +09001363 if (termios->c_cflag & PARODD)
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001364 parity = PCH_UART_HAL_PARITY_ODD;
1365 else
1366 parity = PCH_UART_HAL_PARITY_EVEN;
1367
Feng Tang30c6c6b2012-02-06 17:24:44 +08001368 } else
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001369 parity = PCH_UART_HAL_PARITY_NONE;
Tomoya MORINAGA9af71552011-02-23 10:03:17 +09001370
1371 /* Only UART0 has auto hardware flow function */
1372 if ((termios->c_cflag & CRTSCTS) && (priv->fifo_size == 256))
1373 priv->mcr |= UART_MCR_AFE;
1374 else
1375 priv->mcr &= ~UART_MCR_AFE;
1376
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001377 termios->c_cflag &= ~CMSPAR; /* Mark/Space parity is not supported */
1378
1379 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
1380
Darren Hart61df4452012-06-19 14:00:18 -07001381 spin_lock_irqsave(&priv->lock, flags);
1382 spin_lock(&port->lock);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001383
1384 uart_update_timeout(port, termios->c_cflag, baud);
1385 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb);
1386 if (rtn)
1387 goto out;
1388
Tomoya MORINAGAa1d7cfe2011-10-27 15:45:18 +09001389 pch_uart_set_mctrl(&priv->port, priv->port.mctrl);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001390 /* Don't rewrite B0 */
1391 if (tty_termios_baud_rate(termios))
1392 tty_termios_encode_baud_rate(termios, baud, baud);
1393
1394out:
Darren Hart61df4452012-06-19 14:00:18 -07001395 spin_unlock(&port->lock);
1396 spin_unlock_irqrestore(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001397}
1398
1399static const char *pch_uart_type(struct uart_port *port)
1400{
1401 return KBUILD_MODNAME;
1402}
1403
1404static void pch_uart_release_port(struct uart_port *port)
1405{
1406 struct eg20t_port *priv;
1407
1408 priv = container_of(port, struct eg20t_port, port);
1409 pci_iounmap(priv->pdev, priv->membase);
1410 pci_release_regions(priv->pdev);
1411}
1412
1413static int pch_uart_request_port(struct uart_port *port)
1414{
1415 struct eg20t_port *priv;
1416 int ret;
1417 void __iomem *membase;
1418
1419 priv = container_of(port, struct eg20t_port, port);
1420 ret = pci_request_regions(priv->pdev, KBUILD_MODNAME);
1421 if (ret < 0)
1422 return -EBUSY;
1423
1424 membase = pci_iomap(priv->pdev, 1, 0);
1425 if (!membase) {
1426 pci_release_regions(priv->pdev);
1427 return -EBUSY;
1428 }
1429 priv->membase = port->membase = membase;
1430
1431 return 0;
1432}
1433
1434static void pch_uart_config_port(struct uart_port *port, int type)
1435{
1436 struct eg20t_port *priv;
1437
1438 priv = container_of(port, struct eg20t_port, port);
1439 if (type & UART_CONFIG_TYPE) {
1440 port->type = priv->port_type;
1441 pch_uart_request_port(port);
1442 }
1443}
1444
1445static int pch_uart_verify_port(struct uart_port *port,
1446 struct serial_struct *serinfo)
1447{
1448 struct eg20t_port *priv;
1449
1450 priv = container_of(port, struct eg20t_port, port);
1451 if (serinfo->flags & UPF_LOW_LATENCY) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001452 dev_info(priv->port.dev,
1453 "PCH UART : Use PIO Mode (without DMA)\n");
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001454 priv->use_dma = 0;
1455 serinfo->flags &= ~UPF_LOW_LATENCY;
1456 } else {
1457#ifndef CONFIG_PCH_DMA
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001458 dev_err(priv->port.dev, "%s : PCH DMA is not Loaded.\n",
1459 __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001460 return -EOPNOTSUPP;
1461#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001462 priv->use_dma_flag = 1;
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001463 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n");
Tomoya MORINAGAaf6d17c2012-04-12 10:47:50 +09001464 if (!priv->use_dma)
1465 pch_request_dma(port);
1466 priv->use_dma = 1;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001467 }
1468
1469 return 0;
1470}
1471
1472static struct uart_ops pch_uart_ops = {
1473 .tx_empty = pch_uart_tx_empty,
1474 .set_mctrl = pch_uart_set_mctrl,
1475 .get_mctrl = pch_uart_get_mctrl,
1476 .stop_tx = pch_uart_stop_tx,
1477 .start_tx = pch_uart_start_tx,
1478 .stop_rx = pch_uart_stop_rx,
1479 .enable_ms = pch_uart_enable_ms,
1480 .break_ctl = pch_uart_break_ctl,
1481 .startup = pch_uart_startup,
1482 .shutdown = pch_uart_shutdown,
1483 .set_termios = pch_uart_set_termios,
1484/* .pm = pch_uart_pm, Not supported yet */
1485/* .set_wake = pch_uart_set_wake, Not supported yet */
1486 .type = pch_uart_type,
1487 .release_port = pch_uart_release_port,
1488 .request_port = pch_uart_request_port,
1489 .config_port = pch_uart_config_port,
1490 .verify_port = pch_uart_verify_port
1491};
1492
Alexander Steine30f8672011-11-15 15:04:07 -08001493#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1494
1495/*
1496 * Wait for transmitter & holding register to empty
1497 */
1498static void wait_for_xmitr(struct eg20t_port *up, int bits)
1499{
1500 unsigned int status, tmout = 10000;
1501
1502 /* Wait up to 10ms for the character(s) to be sent. */
1503 for (;;) {
1504 status = ioread8(up->membase + UART_LSR);
1505
1506 if ((status & bits) == bits)
1507 break;
1508 if (--tmout == 0)
1509 break;
1510 udelay(1);
1511 }
1512
1513 /* Wait up to 1s for flow control if necessary */
1514 if (up->port.flags & UPF_CONS_FLOW) {
1515 unsigned int tmout;
1516 for (tmout = 1000000; tmout; tmout--) {
1517 unsigned int msr = ioread8(up->membase + UART_MSR);
1518 if (msr & UART_MSR_CTS)
1519 break;
1520 udelay(1);
1521 touch_nmi_watchdog();
1522 }
1523 }
1524}
1525
1526static void pch_console_putchar(struct uart_port *port, int ch)
1527{
1528 struct eg20t_port *priv =
1529 container_of(port, struct eg20t_port, port);
1530
1531 wait_for_xmitr(priv, UART_LSR_THRE);
1532 iowrite8(ch, priv->membase + PCH_UART_THR);
1533}
1534
1535/*
1536 * Print a string to the serial port trying not to disturb
1537 * any possible real use of the port...
1538 *
1539 * The console_lock must be held when we get here.
1540 */
1541static void
1542pch_console_write(struct console *co, const char *s, unsigned int count)
1543{
1544 struct eg20t_port *priv;
Alexander Steine30f8672011-11-15 15:04:07 -08001545 unsigned long flags;
Darren Hart61df4452012-06-19 14:00:18 -07001546 int priv_locked = 1;
1547 int port_locked = 1;
Alexander Steine30f8672011-11-15 15:04:07 -08001548 u8 ier;
Alexander Steine30f8672011-11-15 15:04:07 -08001549
1550 priv = pch_uart_ports[co->index];
1551
1552 touch_nmi_watchdog();
1553
1554 local_irq_save(flags);
1555 if (priv->port.sysrq) {
Darren Hart61df4452012-06-19 14:00:18 -07001556 spin_lock(&priv->lock);
1557 /* serial8250_handle_port() already took the port lock */
1558 port_locked = 0;
Alexander Steine30f8672011-11-15 15:04:07 -08001559 } else if (oops_in_progress) {
Darren Hart61df4452012-06-19 14:00:18 -07001560 priv_locked = spin_trylock(&priv->lock);
1561 port_locked = spin_trylock(&priv->port.lock);
1562 } else {
1563 spin_lock(&priv->lock);
Alexander Steine30f8672011-11-15 15:04:07 -08001564 spin_lock(&priv->port.lock);
Darren Hart61df4452012-06-19 14:00:18 -07001565 }
Alexander Steine30f8672011-11-15 15:04:07 -08001566
1567 /*
1568 * First save the IER then disable the interrupts
1569 */
1570 ier = ioread8(priv->membase + UART_IER);
1571
1572 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1573
1574 uart_console_write(&priv->port, s, count, pch_console_putchar);
1575
1576 /*
1577 * Finally, wait for transmitter to become empty
1578 * and restore the IER
1579 */
1580 wait_for_xmitr(priv, BOTH_EMPTY);
1581 iowrite8(ier, priv->membase + UART_IER);
1582
Darren Hart61df4452012-06-19 14:00:18 -07001583 if (port_locked)
Alexander Steine30f8672011-11-15 15:04:07 -08001584 spin_unlock(&priv->port.lock);
Darren Hart61df4452012-06-19 14:00:18 -07001585 if (priv_locked)
1586 spin_unlock(&priv->lock);
Alexander Steine30f8672011-11-15 15:04:07 -08001587 local_irq_restore(flags);
1588}
1589
1590static int __init pch_console_setup(struct console *co, char *options)
1591{
1592 struct uart_port *port;
Darren Hart7ce92512012-03-09 09:51:51 -08001593 int baud = default_baud;
Alexander Steine30f8672011-11-15 15:04:07 -08001594 int bits = 8;
1595 int parity = 'n';
1596 int flow = 'n';
1597
1598 /*
1599 * Check whether an invalid uart number has been specified, and
1600 * if so, search for the first available port that does have
1601 * console support.
1602 */
1603 if (co->index >= PCH_UART_NR)
1604 co->index = 0;
1605 port = &pch_uart_ports[co->index]->port;
1606
1607 if (!port || (!port->iobase && !port->membase))
1608 return -ENODEV;
1609
Darren Hart077175f2012-03-09 09:51:49 -08001610 port->uartclk = pch_uart_get_uartclk();
Alexander Steine30f8672011-11-15 15:04:07 -08001611
1612 if (options)
1613 uart_parse_options(options, &baud, &parity, &bits, &flow);
1614
1615 return uart_set_options(port, co, baud, parity, bits, flow);
1616}
1617
1618static struct uart_driver pch_uart_driver;
1619
1620static struct console pch_console = {
1621 .name = PCH_UART_DRIVER_DEVICE,
1622 .write = pch_console_write,
1623 .device = uart_console_device,
1624 .setup = pch_console_setup,
1625 .flags = CON_PRINTBUFFER | CON_ANYTIME,
1626 .index = -1,
1627 .data = &pch_uart_driver,
1628};
1629
1630#define PCH_CONSOLE (&pch_console)
1631#else
1632#define PCH_CONSOLE NULL
1633#endif
1634
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001635static struct uart_driver pch_uart_driver = {
1636 .owner = THIS_MODULE,
1637 .driver_name = KBUILD_MODNAME,
1638 .dev_name = PCH_UART_DRIVER_DEVICE,
1639 .major = 0,
1640 .minor = 0,
1641 .nr = PCH_UART_NR,
Alexander Steine30f8672011-11-15 15:04:07 -08001642 .cons = PCH_CONSOLE,
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001643};
1644
1645static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001646 const struct pci_device_id *id)
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001647{
1648 struct eg20t_port *priv;
1649 int ret;
1650 unsigned int iobase;
1651 unsigned int mapbase;
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001652 unsigned char *rxbuf;
Darren Hart077175f2012-03-09 09:51:49 -08001653 int fifosize;
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001654 int port_type;
1655 struct pch_uart_driver_data *board;
Feng Tangd0114112012-02-06 17:24:43 +08001656 char name[32]; /* for debugfs file name */
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001657
1658 board = &drv_dat[id->driver_data];
1659 port_type = board->port_type;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001660
1661 priv = kzalloc(sizeof(struct eg20t_port), GFP_KERNEL);
1662 if (priv == NULL)
1663 goto init_port_alloc_err;
1664
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001665 rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001666 if (!rxbuf)
1667 goto init_port_free_txbuf;
1668
1669 switch (port_type) {
1670 case PORT_UNKNOWN:
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001671 fifosize = 256; /* EG20T/ML7213: UART0 */
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001672 break;
1673 case PORT_8250:
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001674 fifosize = 64; /* EG20T:UART1~3 ML7213: UART1~2*/
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001675 break;
1676 default:
1677 dev_err(&pdev->dev, "Invalid Port Type(=%d)\n", port_type);
1678 goto init_port_hal_free;
1679 }
1680
Alexander Steine4635952011-07-04 08:58:31 +02001681 pci_enable_msi(pdev);
Tomoya MORINAGA867c9022012-04-02 14:36:22 +09001682 pci_set_master(pdev);
Alexander Steine4635952011-07-04 08:58:31 +02001683
Darren Hart61df4452012-06-19 14:00:18 -07001684 spin_lock_init(&priv->lock);
1685
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001686 iobase = pci_resource_start(pdev, 0);
1687 mapbase = pci_resource_start(pdev, 1);
1688 priv->mapbase = mapbase;
1689 priv->iobase = iobase;
1690 priv->pdev = pdev;
1691 priv->tx_empty = 1;
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001692 priv->rxbuf.buf = rxbuf;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001693 priv->rxbuf.size = PAGE_SIZE;
1694
1695 priv->fifo_size = fifosize;
Darren Hart077175f2012-03-09 09:51:49 -08001696 priv->uartclk = pch_uart_get_uartclk();
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001697 priv->port_type = PORT_MAX_8250 + port_type + 1;
1698 priv->port.dev = &pdev->dev;
1699 priv->port.iobase = iobase;
1700 priv->port.membase = NULL;
1701 priv->port.mapbase = mapbase;
1702 priv->port.irq = pdev->irq;
1703 priv->port.iotype = UPIO_PORT;
1704 priv->port.ops = &pch_uart_ops;
1705 priv->port.flags = UPF_BOOT_AUTOCONF;
1706 priv->port.fifosize = fifosize;
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001707 priv->port.line = board->line_no;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001708 priv->trigger = PCH_UART_HAL_TRIGGER_M;
1709
Tomoya MORINAGA7e461322011-02-23 10:03:13 +09001710 spin_lock_init(&priv->port.lock);
1711
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001712 pci_set_drvdata(pdev, priv);
Feng Tang6f56d0f2012-02-06 17:24:45 +08001713 priv->trigger_level = 1;
1714 priv->fcr = 0;
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001715
Alexander Steine30f8672011-11-15 15:04:07 -08001716#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1717 pch_uart_ports[board->line_no] = priv;
1718#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001719 ret = uart_add_one_port(&pch_uart_driver, &priv->port);
1720 if (ret < 0)
1721 goto init_port_hal_free;
1722
Feng Tangd0114112012-02-06 17:24:43 +08001723#ifdef CONFIG_DEBUG_FS
1724 snprintf(name, sizeof(name), "uart%d_regs", board->line_no);
1725 priv->debugfs = debugfs_create_file(name, S_IFREG | S_IRUGO,
1726 NULL, priv, &port_regs_ops);
1727#endif
1728
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001729 return priv;
1730
1731init_port_hal_free:
Alexander Steine30f8672011-11-15 15:04:07 -08001732#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1733 pch_uart_ports[board->line_no] = NULL;
1734#endif
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001735 free_page((unsigned long)rxbuf);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001736init_port_free_txbuf:
1737 kfree(priv);
1738init_port_alloc_err:
1739
1740 return NULL;
1741}
1742
1743static void pch_uart_exit_port(struct eg20t_port *priv)
1744{
Feng Tangd0114112012-02-06 17:24:43 +08001745
1746#ifdef CONFIG_DEBUG_FS
1747 if (priv->debugfs)
1748 debugfs_remove(priv->debugfs);
1749#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001750 uart_remove_one_port(&pch_uart_driver, &priv->port);
1751 pci_set_drvdata(priv->pdev, NULL);
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001752 free_page((unsigned long)priv->rxbuf.buf);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001753}
1754
1755static void pch_uart_pci_remove(struct pci_dev *pdev)
1756{
Feng Tang6f56d0f2012-02-06 17:24:45 +08001757 struct eg20t_port *priv = pci_get_drvdata(pdev);
Alexander Steine4635952011-07-04 08:58:31 +02001758
1759 pci_disable_msi(pdev);
Alexander Steine30f8672011-11-15 15:04:07 -08001760
1761#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1762 pch_uart_ports[priv->port.line] = NULL;
1763#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001764 pch_uart_exit_port(priv);
1765 pci_disable_device(pdev);
1766 kfree(priv);
1767 return;
1768}
1769#ifdef CONFIG_PM
1770static int pch_uart_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1771{
1772 struct eg20t_port *priv = pci_get_drvdata(pdev);
1773
1774 uart_suspend_port(&pch_uart_driver, &priv->port);
1775
1776 pci_save_state(pdev);
1777 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1778 return 0;
1779}
1780
1781static int pch_uart_pci_resume(struct pci_dev *pdev)
1782{
1783 struct eg20t_port *priv = pci_get_drvdata(pdev);
1784 int ret;
1785
1786 pci_set_power_state(pdev, PCI_D0);
1787 pci_restore_state(pdev);
1788
1789 ret = pci_enable_device(pdev);
1790 if (ret) {
1791 dev_err(&pdev->dev,
1792 "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
1793 return ret;
1794 }
1795
1796 uart_resume_port(&pch_uart_driver, &priv->port);
1797
1798 return 0;
1799}
1800#else
1801#define pch_uart_pci_suspend NULL
1802#define pch_uart_pci_resume NULL
1803#endif
1804
1805static DEFINE_PCI_DEVICE_TABLE(pch_uart_pci_id) = {
1806 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8811),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001807 .driver_data = pch_et20t_uart0},
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001808 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8812),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001809 .driver_data = pch_et20t_uart1},
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001810 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8813),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001811 .driver_data = pch_et20t_uart2},
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001812 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8814),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001813 .driver_data = pch_et20t_uart3},
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001814 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8027),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001815 .driver_data = pch_ml7213_uart0},
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001816 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8028),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001817 .driver_data = pch_ml7213_uart1},
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001818 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8029),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001819 .driver_data = pch_ml7213_uart2},
Tomoya MORINAGA177c2cb2011-05-09 17:25:20 +09001820 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800C),
1821 .driver_data = pch_ml7223_uart0},
1822 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800D),
1823 .driver_data = pch_ml7223_uart1},
Tomoya MORINAGA8249f742011-10-28 09:38:49 +09001824 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8811),
1825 .driver_data = pch_ml7831_uart0},
1826 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8812),
1827 .driver_data = pch_ml7831_uart1},
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001828 {0,},
1829};
1830
1831static int __devinit pch_uart_pci_probe(struct pci_dev *pdev,
1832 const struct pci_device_id *id)
1833{
1834 int ret;
1835 struct eg20t_port *priv;
1836
1837 ret = pci_enable_device(pdev);
1838 if (ret < 0)
1839 goto probe_error;
1840
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001841 priv = pch_uart_init_port(pdev, id);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001842 if (!priv) {
1843 ret = -EBUSY;
1844 goto probe_disable_device;
1845 }
1846 pci_set_drvdata(pdev, priv);
1847
1848 return ret;
1849
1850probe_disable_device:
Alexander Steine4635952011-07-04 08:58:31 +02001851 pci_disable_msi(pdev);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001852 pci_disable_device(pdev);
1853probe_error:
1854 return ret;
1855}
1856
1857static struct pci_driver pch_uart_pci_driver = {
1858 .name = "pch_uart",
1859 .id_table = pch_uart_pci_id,
1860 .probe = pch_uart_pci_probe,
1861 .remove = __devexit_p(pch_uart_pci_remove),
1862 .suspend = pch_uart_pci_suspend,
1863 .resume = pch_uart_pci_resume,
1864};
1865
1866static int __init pch_uart_module_init(void)
1867{
1868 int ret;
1869
1870 /* register as UART driver */
1871 ret = uart_register_driver(&pch_uart_driver);
1872 if (ret < 0)
1873 return ret;
1874
1875 /* register as PCI driver */
1876 ret = pci_register_driver(&pch_uart_pci_driver);
1877 if (ret < 0)
1878 uart_unregister_driver(&pch_uart_driver);
1879
1880 return ret;
1881}
1882module_init(pch_uart_module_init);
1883
1884static void __exit pch_uart_module_exit(void)
1885{
1886 pci_unregister_driver(&pch_uart_pci_driver);
1887 uart_unregister_driver(&pch_uart_driver);
1888}
1889module_exit(pch_uart_module_exit);
1890
1891MODULE_LICENSE("GPL v2");
1892MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver");
1893module_param(default_baud, uint, S_IRUGO);
Darren Harta46f5532012-03-09 09:51:52 -08001894MODULE_PARM_DESC(default_baud,
1895 "Default BAUD for initial driver state and console (default 9600)");
Darren Hart2a44feb2012-03-09 09:51:50 -08001896module_param(user_uartclk, uint, S_IRUGO);
Darren Harta46f5532012-03-09 09:51:52 -08001897MODULE_PARM_DESC(user_uartclk,
1898 "Override UART default or board specific UART clock");