blob: 2e99f7959b963b15aa540836ec6232cf030bc75f [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);
Liang Li5d2a2c72013-01-19 17:52:10 +08001037 struct uart_port *port = &priv->port;
1038 struct tty_struct *tty = tty_port_tty_get(&port->state->port);
1039 char *error_msg[5] = {};
1040 int i = 0;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001041
1042 /* Reset FIFO */
1043 fcr |= UART_FCR_CLEAR_RCVR;
1044 iowrite8(fcr, priv->membase + UART_FCR);
1045
1046 if (lsr & PCH_UART_LSR_ERR)
Liang Li5d2a2c72013-01-19 17:52:10 +08001047 error_msg[i++] = "Error data in FIFO\n";
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001048
Liang Li5d2a2c72013-01-19 17:52:10 +08001049 if (lsr & UART_LSR_FE) {
1050 port->icount.frame++;
1051 error_msg[i++] = " Framing Error\n";
1052 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001053
Liang Li5d2a2c72013-01-19 17:52:10 +08001054 if (lsr & UART_LSR_PE) {
1055 port->icount.parity++;
1056 error_msg[i++] = " Parity Error\n";
1057 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001058
Liang Li5d2a2c72013-01-19 17:52:10 +08001059 if (lsr & UART_LSR_OE) {
1060 port->icount.overrun++;
1061 error_msg[i++] = " Overrun Error\n";
1062 }
1063
1064 if (tty == NULL) {
1065 for (i = 0; error_msg[i] != NULL; i++)
1066 dev_err(&priv->pdev->dev, error_msg[i]);
1067 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001068}
1069
1070static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1071{
1072 struct eg20t_port *priv = dev_id;
1073 unsigned int handled;
1074 u8 lsr;
1075 int ret = 0;
1076 unsigned int iid;
1077 unsigned long flags;
1078
Darren Hart61df4452012-06-19 14:00:18 -07001079 spin_lock_irqsave(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001080 handled = 0;
1081 while ((iid = pch_uart_hal_get_iid(priv)) > 1) {
1082 switch (iid) {
1083 case PCH_UART_IID_RLS: /* Receiver Line Status */
1084 lsr = pch_uart_hal_get_line_status(priv);
1085 if (lsr & (PCH_UART_LSR_ERR | UART_LSR_FE |
1086 UART_LSR_PE | UART_LSR_OE)) {
1087 pch_uart_err_ir(priv, lsr);
1088 ret = PCH_UART_HANDLED_RX_ERR_INT;
1089 }
1090 break;
1091 case PCH_UART_IID_RDR: /* Received Data Ready */
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001092 if (priv->use_dma) {
1093 pch_uart_hal_disable_interrupt(priv,
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +09001094 PCH_UART_HAL_RX_INT |
1095 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001096 ret = dma_handle_rx(priv);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001097 if (!ret)
1098 pch_uart_hal_enable_interrupt(priv,
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +09001099 PCH_UART_HAL_RX_INT |
1100 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001101 } else {
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001102 ret = handle_rx(priv);
Tomoya MORINAGAda3564e2011-02-23 10:03:12 +09001103 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001104 break;
1105 case PCH_UART_IID_RDR_TO: /* Received Data Ready
1106 (FIFO Timeout) */
1107 ret = handle_rx_to(priv);
1108 break;
1109 case PCH_UART_IID_THRE: /* Transmitter Holding Register
1110 Empty */
1111 if (priv->use_dma)
1112 ret = dma_handle_tx(priv);
1113 else
1114 ret = handle_tx(priv);
1115 break;
1116 case PCH_UART_IID_MS: /* Modem Status */
1117 ret = PCH_UART_HANDLED_MS_INT;
1118 break;
1119 default: /* Never junp to this label */
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001120 dev_err(priv->port.dev, "%s:iid=%d (%lu)\n", __func__,
1121 iid, jiffies);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001122 ret = -1;
1123 break;
1124 }
1125 handled |= (unsigned int)ret;
1126 }
1127 if (handled == 0 && iid <= 1) {
1128 if (priv->int_dis_flag)
1129 priv->int_dis_flag = 0;
1130 }
1131
Darren Hart61df4452012-06-19 14:00:18 -07001132 spin_unlock_irqrestore(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001133 return IRQ_RETVAL(handled);
1134}
1135
1136/* This function tests whether the transmitter fifo and shifter for the port
1137 described by 'port' is empty. */
1138static unsigned int pch_uart_tx_empty(struct uart_port *port)
1139{
1140 struct eg20t_port *priv;
Feng Tang30c6c6b2012-02-06 17:24:44 +08001141
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001142 priv = container_of(port, struct eg20t_port, port);
1143 if (priv->tx_empty)
Feng Tang30c6c6b2012-02-06 17:24:44 +08001144 return TIOCSER_TEMT;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001145 else
Feng Tang30c6c6b2012-02-06 17:24:44 +08001146 return 0;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001147}
1148
1149/* Returns the current state of modem control inputs. */
1150static unsigned int pch_uart_get_mctrl(struct uart_port *port)
1151{
1152 struct eg20t_port *priv;
1153 u8 modem;
1154 unsigned int ret = 0;
1155
1156 priv = container_of(port, struct eg20t_port, port);
1157 modem = pch_uart_hal_get_modem(priv);
1158
1159 if (modem & UART_MSR_DCD)
1160 ret |= TIOCM_CAR;
1161
1162 if (modem & UART_MSR_RI)
1163 ret |= TIOCM_RNG;
1164
1165 if (modem & UART_MSR_DSR)
1166 ret |= TIOCM_DSR;
1167
1168 if (modem & UART_MSR_CTS)
1169 ret |= TIOCM_CTS;
1170
1171 return ret;
1172}
1173
1174static void pch_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
1175{
1176 u32 mcr = 0;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001177 struct eg20t_port *priv = container_of(port, struct eg20t_port, port);
1178
1179 if (mctrl & TIOCM_DTR)
1180 mcr |= UART_MCR_DTR;
1181 if (mctrl & TIOCM_RTS)
1182 mcr |= UART_MCR_RTS;
1183 if (mctrl & TIOCM_LOOP)
1184 mcr |= UART_MCR_LOOP;
1185
Tomoya MORINAGA9af71552011-02-23 10:03:17 +09001186 if (priv->mcr & UART_MCR_AFE)
1187 mcr |= UART_MCR_AFE;
1188
1189 if (mctrl)
1190 iowrite8(mcr, priv->membase + UART_MCR);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001191}
1192
1193static void pch_uart_stop_tx(struct uart_port *port)
1194{
1195 struct eg20t_port *priv;
1196 priv = container_of(port, struct eg20t_port, port);
1197 priv->start_tx = 0;
1198 priv->tx_dma_use = 0;
1199}
1200
1201static void pch_uart_start_tx(struct uart_port *port)
1202{
1203 struct eg20t_port *priv;
1204
1205 priv = container_of(port, struct eg20t_port, port);
1206
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001207 if (priv->use_dma) {
1208 if (priv->tx_dma_use) {
1209 dev_dbg(priv->port.dev, "%s : Tx DMA is NOT empty.\n",
1210 __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001211 return;
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001212 }
1213 }
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001214
1215 priv->start_tx = 1;
1216 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_TX_INT);
1217}
1218
1219static void pch_uart_stop_rx(struct uart_port *port)
1220{
1221 struct eg20t_port *priv;
1222 priv = container_of(port, struct eg20t_port, port);
1223 priv->start_rx = 0;
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +09001224 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT |
1225 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001226 priv->int_dis_flag = 1;
1227}
1228
1229/* Enable the modem status interrupts. */
1230static void pch_uart_enable_ms(struct uart_port *port)
1231{
1232 struct eg20t_port *priv;
1233 priv = container_of(port, struct eg20t_port, port);
1234 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_MS_INT);
1235}
1236
1237/* Control the transmission of a break signal. */
1238static void pch_uart_break_ctl(struct uart_port *port, int ctl)
1239{
1240 struct eg20t_port *priv;
1241 unsigned long flags;
1242
1243 priv = container_of(port, struct eg20t_port, port);
Darren Hart61df4452012-06-19 14:00:18 -07001244 spin_lock_irqsave(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001245 pch_uart_hal_set_break(priv, ctl);
Darren Hart61df4452012-06-19 14:00:18 -07001246 spin_unlock_irqrestore(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001247}
1248
1249/* Grab any interrupt resources and initialise any low level driver state. */
1250static int pch_uart_startup(struct uart_port *port)
1251{
1252 struct eg20t_port *priv;
1253 int ret;
1254 int fifo_size;
1255 int trigger_level;
1256
1257 priv = container_of(port, struct eg20t_port, port);
1258 priv->tx_empty = 1;
Tomoya MORINAGAaac6c0b2011-02-23 10:03:16 +09001259
1260 if (port->uartclk)
Darren Harta8a3ec92012-03-09 09:51:48 -08001261 priv->uartclk = port->uartclk;
Tomoya MORINAGAaac6c0b2011-02-23 10:03:16 +09001262 else
Darren Harta8a3ec92012-03-09 09:51:48 -08001263 port->uartclk = priv->uartclk;
Tomoya MORINAGAaac6c0b2011-02-23 10:03:16 +09001264
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001265 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1266 ret = pch_uart_hal_set_line(priv, default_baud,
1267 PCH_UART_HAL_PARITY_NONE, PCH_UART_HAL_8BIT,
1268 PCH_UART_HAL_STB1);
1269 if (ret)
1270 return ret;
1271
1272 switch (priv->fifo_size) {
1273 case 256:
1274 fifo_size = PCH_UART_HAL_FIFO256;
1275 break;
1276 case 64:
1277 fifo_size = PCH_UART_HAL_FIFO64;
1278 break;
1279 case 16:
1280 fifo_size = PCH_UART_HAL_FIFO16;
Alan Cox17361b32012-07-02 18:51:38 +01001281 break;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001282 case 1:
1283 default:
1284 fifo_size = PCH_UART_HAL_FIFO_DIS;
1285 break;
1286 }
1287
1288 switch (priv->trigger) {
1289 case PCH_UART_HAL_TRIGGER1:
1290 trigger_level = 1;
1291 break;
1292 case PCH_UART_HAL_TRIGGER_L:
1293 trigger_level = priv->fifo_size / 4;
1294 break;
1295 case PCH_UART_HAL_TRIGGER_M:
1296 trigger_level = priv->fifo_size / 2;
1297 break;
1298 case PCH_UART_HAL_TRIGGER_H:
1299 default:
1300 trigger_level = priv->fifo_size - (priv->fifo_size / 8);
1301 break;
1302 }
1303
1304 priv->trigger_level = trigger_level;
1305 ret = pch_uart_hal_set_fifo(priv, PCH_UART_HAL_DMA_MODE0,
1306 fifo_size, priv->trigger);
1307 if (ret < 0)
1308 return ret;
1309
1310 ret = request_irq(priv->port.irq, pch_uart_interrupt, IRQF_SHARED,
1311 KBUILD_MODNAME, priv);
1312 if (ret < 0)
1313 return ret;
1314
1315 if (priv->use_dma)
1316 pch_request_dma(port);
1317
1318 priv->start_rx = 1;
Tomoya MORINAGA439ec7b2012-07-06 17:19:42 +09001319 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT |
1320 PCH_UART_HAL_RX_ERR_INT);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001321 uart_update_timeout(port, CS8, default_baud);
1322
1323 return 0;
1324}
1325
1326static void pch_uart_shutdown(struct uart_port *port)
1327{
1328 struct eg20t_port *priv;
1329 int ret;
1330
1331 priv = container_of(port, struct eg20t_port, port);
1332 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1333 pch_uart_hal_fifo_reset(priv, PCH_UART_HAL_CLR_ALL_FIFO);
1334 ret = pch_uart_hal_set_fifo(priv, PCH_UART_HAL_DMA_MODE0,
1335 PCH_UART_HAL_FIFO_DIS, PCH_UART_HAL_TRIGGER1);
1336 if (ret)
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001337 dev_err(priv->port.dev,
1338 "pch_uart_hal_set_fifo Failed(ret=%d)\n", ret);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001339
Tomoya MORINAGA90f04c22011-11-11 10:55:27 +09001340 pch_free_dma(port);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001341
1342 free_irq(priv->port.irq, priv);
1343}
1344
1345/* Change the port parameters, including word length, parity, stop
1346 *bits. Update read_status_mask and ignore_status_mask to indicate
1347 *the types of events we are interested in receiving. */
1348static void pch_uart_set_termios(struct uart_port *port,
1349 struct ktermios *termios, struct ktermios *old)
1350{
1351 int baud;
1352 int rtn;
1353 unsigned int parity, bits, stb;
1354 struct eg20t_port *priv;
1355 unsigned long flags;
1356
1357 priv = container_of(port, struct eg20t_port, port);
1358 switch (termios->c_cflag & CSIZE) {
1359 case CS5:
1360 bits = PCH_UART_HAL_5BIT;
1361 break;
1362 case CS6:
1363 bits = PCH_UART_HAL_6BIT;
1364 break;
1365 case CS7:
1366 bits = PCH_UART_HAL_7BIT;
1367 break;
1368 default: /* CS8 */
1369 bits = PCH_UART_HAL_8BIT;
1370 break;
1371 }
1372 if (termios->c_cflag & CSTOPB)
1373 stb = PCH_UART_HAL_STB2;
1374 else
1375 stb = PCH_UART_HAL_STB1;
1376
1377 if (termios->c_cflag & PARENB) {
Tomoya MORINAGA3dcb5362012-07-06 17:19:43 +09001378 if (termios->c_cflag & PARODD)
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001379 parity = PCH_UART_HAL_PARITY_ODD;
1380 else
1381 parity = PCH_UART_HAL_PARITY_EVEN;
1382
Feng Tang30c6c6b2012-02-06 17:24:44 +08001383 } else
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001384 parity = PCH_UART_HAL_PARITY_NONE;
Tomoya MORINAGA9af71552011-02-23 10:03:17 +09001385
1386 /* Only UART0 has auto hardware flow function */
1387 if ((termios->c_cflag & CRTSCTS) && (priv->fifo_size == 256))
1388 priv->mcr |= UART_MCR_AFE;
1389 else
1390 priv->mcr &= ~UART_MCR_AFE;
1391
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001392 termios->c_cflag &= ~CMSPAR; /* Mark/Space parity is not supported */
1393
1394 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
1395
Darren Hart61df4452012-06-19 14:00:18 -07001396 spin_lock_irqsave(&priv->lock, flags);
1397 spin_lock(&port->lock);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001398
1399 uart_update_timeout(port, termios->c_cflag, baud);
1400 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb);
1401 if (rtn)
1402 goto out;
1403
Tomoya MORINAGAa1d7cfe2011-10-27 15:45:18 +09001404 pch_uart_set_mctrl(&priv->port, priv->port.mctrl);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001405 /* Don't rewrite B0 */
1406 if (tty_termios_baud_rate(termios))
1407 tty_termios_encode_baud_rate(termios, baud, baud);
1408
1409out:
Darren Hart61df4452012-06-19 14:00:18 -07001410 spin_unlock(&port->lock);
1411 spin_unlock_irqrestore(&priv->lock, flags);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001412}
1413
1414static const char *pch_uart_type(struct uart_port *port)
1415{
1416 return KBUILD_MODNAME;
1417}
1418
1419static void pch_uart_release_port(struct uart_port *port)
1420{
1421 struct eg20t_port *priv;
1422
1423 priv = container_of(port, struct eg20t_port, port);
1424 pci_iounmap(priv->pdev, priv->membase);
1425 pci_release_regions(priv->pdev);
1426}
1427
1428static int pch_uart_request_port(struct uart_port *port)
1429{
1430 struct eg20t_port *priv;
1431 int ret;
1432 void __iomem *membase;
1433
1434 priv = container_of(port, struct eg20t_port, port);
1435 ret = pci_request_regions(priv->pdev, KBUILD_MODNAME);
1436 if (ret < 0)
1437 return -EBUSY;
1438
1439 membase = pci_iomap(priv->pdev, 1, 0);
1440 if (!membase) {
1441 pci_release_regions(priv->pdev);
1442 return -EBUSY;
1443 }
1444 priv->membase = port->membase = membase;
1445
1446 return 0;
1447}
1448
1449static void pch_uart_config_port(struct uart_port *port, int type)
1450{
1451 struct eg20t_port *priv;
1452
1453 priv = container_of(port, struct eg20t_port, port);
1454 if (type & UART_CONFIG_TYPE) {
1455 port->type = priv->port_type;
1456 pch_uart_request_port(port);
1457 }
1458}
1459
1460static int pch_uart_verify_port(struct uart_port *port,
1461 struct serial_struct *serinfo)
1462{
1463 struct eg20t_port *priv;
1464
1465 priv = container_of(port, struct eg20t_port, port);
1466 if (serinfo->flags & UPF_LOW_LATENCY) {
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001467 dev_info(priv->port.dev,
1468 "PCH UART : Use PIO Mode (without DMA)\n");
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001469 priv->use_dma = 0;
1470 serinfo->flags &= ~UPF_LOW_LATENCY;
1471 } else {
1472#ifndef CONFIG_PCH_DMA
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001473 dev_err(priv->port.dev, "%s : PCH DMA is not Loaded.\n",
1474 __func__);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001475 return -EOPNOTSUPP;
1476#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001477 priv->use_dma_flag = 1;
Tomoya MORINAGA23877fd2011-02-23 10:03:15 +09001478 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n");
Tomoya MORINAGAaf6d17c2012-04-12 10:47:50 +09001479 if (!priv->use_dma)
1480 pch_request_dma(port);
1481 priv->use_dma = 1;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001482 }
1483
1484 return 0;
1485}
1486
1487static struct uart_ops pch_uart_ops = {
1488 .tx_empty = pch_uart_tx_empty,
1489 .set_mctrl = pch_uart_set_mctrl,
1490 .get_mctrl = pch_uart_get_mctrl,
1491 .stop_tx = pch_uart_stop_tx,
1492 .start_tx = pch_uart_start_tx,
1493 .stop_rx = pch_uart_stop_rx,
1494 .enable_ms = pch_uart_enable_ms,
1495 .break_ctl = pch_uart_break_ctl,
1496 .startup = pch_uart_startup,
1497 .shutdown = pch_uart_shutdown,
1498 .set_termios = pch_uart_set_termios,
1499/* .pm = pch_uart_pm, Not supported yet */
1500/* .set_wake = pch_uart_set_wake, Not supported yet */
1501 .type = pch_uart_type,
1502 .release_port = pch_uart_release_port,
1503 .request_port = pch_uart_request_port,
1504 .config_port = pch_uart_config_port,
1505 .verify_port = pch_uart_verify_port
1506};
1507
Alexander Steine30f8672011-11-15 15:04:07 -08001508#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1509
1510/*
1511 * Wait for transmitter & holding register to empty
1512 */
1513static void wait_for_xmitr(struct eg20t_port *up, int bits)
1514{
1515 unsigned int status, tmout = 10000;
1516
1517 /* Wait up to 10ms for the character(s) to be sent. */
1518 for (;;) {
1519 status = ioread8(up->membase + UART_LSR);
1520
1521 if ((status & bits) == bits)
1522 break;
1523 if (--tmout == 0)
1524 break;
1525 udelay(1);
1526 }
1527
1528 /* Wait up to 1s for flow control if necessary */
1529 if (up->port.flags & UPF_CONS_FLOW) {
1530 unsigned int tmout;
1531 for (tmout = 1000000; tmout; tmout--) {
1532 unsigned int msr = ioread8(up->membase + UART_MSR);
1533 if (msr & UART_MSR_CTS)
1534 break;
1535 udelay(1);
1536 touch_nmi_watchdog();
1537 }
1538 }
1539}
1540
1541static void pch_console_putchar(struct uart_port *port, int ch)
1542{
1543 struct eg20t_port *priv =
1544 container_of(port, struct eg20t_port, port);
1545
1546 wait_for_xmitr(priv, UART_LSR_THRE);
1547 iowrite8(ch, priv->membase + PCH_UART_THR);
1548}
1549
1550/*
1551 * Print a string to the serial port trying not to disturb
1552 * any possible real use of the port...
1553 *
1554 * The console_lock must be held when we get here.
1555 */
1556static void
1557pch_console_write(struct console *co, const char *s, unsigned int count)
1558{
1559 struct eg20t_port *priv;
Alexander Steine30f8672011-11-15 15:04:07 -08001560 unsigned long flags;
Darren Hart61df4452012-06-19 14:00:18 -07001561 int priv_locked = 1;
1562 int port_locked = 1;
Alexander Steine30f8672011-11-15 15:04:07 -08001563 u8 ier;
Alexander Steine30f8672011-11-15 15:04:07 -08001564
1565 priv = pch_uart_ports[co->index];
1566
1567 touch_nmi_watchdog();
1568
1569 local_irq_save(flags);
1570 if (priv->port.sysrq) {
Darren Hart61df4452012-06-19 14:00:18 -07001571 spin_lock(&priv->lock);
1572 /* serial8250_handle_port() already took the port lock */
1573 port_locked = 0;
Alexander Steine30f8672011-11-15 15:04:07 -08001574 } else if (oops_in_progress) {
Darren Hart61df4452012-06-19 14:00:18 -07001575 priv_locked = spin_trylock(&priv->lock);
1576 port_locked = spin_trylock(&priv->port.lock);
1577 } else {
1578 spin_lock(&priv->lock);
Alexander Steine30f8672011-11-15 15:04:07 -08001579 spin_lock(&priv->port.lock);
Darren Hart61df4452012-06-19 14:00:18 -07001580 }
Alexander Steine30f8672011-11-15 15:04:07 -08001581
1582 /*
1583 * First save the IER then disable the interrupts
1584 */
1585 ier = ioread8(priv->membase + UART_IER);
1586
1587 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1588
1589 uart_console_write(&priv->port, s, count, pch_console_putchar);
1590
1591 /*
1592 * Finally, wait for transmitter to become empty
1593 * and restore the IER
1594 */
1595 wait_for_xmitr(priv, BOTH_EMPTY);
1596 iowrite8(ier, priv->membase + UART_IER);
1597
Darren Hart61df4452012-06-19 14:00:18 -07001598 if (port_locked)
Alexander Steine30f8672011-11-15 15:04:07 -08001599 spin_unlock(&priv->port.lock);
Darren Hart61df4452012-06-19 14:00:18 -07001600 if (priv_locked)
1601 spin_unlock(&priv->lock);
Alexander Steine30f8672011-11-15 15:04:07 -08001602 local_irq_restore(flags);
1603}
1604
1605static int __init pch_console_setup(struct console *co, char *options)
1606{
1607 struct uart_port *port;
Darren Hart7ce92512012-03-09 09:51:51 -08001608 int baud = default_baud;
Alexander Steine30f8672011-11-15 15:04:07 -08001609 int bits = 8;
1610 int parity = 'n';
1611 int flow = 'n';
1612
1613 /*
1614 * Check whether an invalid uart number has been specified, and
1615 * if so, search for the first available port that does have
1616 * console support.
1617 */
1618 if (co->index >= PCH_UART_NR)
1619 co->index = 0;
1620 port = &pch_uart_ports[co->index]->port;
1621
1622 if (!port || (!port->iobase && !port->membase))
1623 return -ENODEV;
1624
Darren Hart077175f2012-03-09 09:51:49 -08001625 port->uartclk = pch_uart_get_uartclk();
Alexander Steine30f8672011-11-15 15:04:07 -08001626
1627 if (options)
1628 uart_parse_options(options, &baud, &parity, &bits, &flow);
1629
1630 return uart_set_options(port, co, baud, parity, bits, flow);
1631}
1632
1633static struct uart_driver pch_uart_driver;
1634
1635static struct console pch_console = {
1636 .name = PCH_UART_DRIVER_DEVICE,
1637 .write = pch_console_write,
1638 .device = uart_console_device,
1639 .setup = pch_console_setup,
1640 .flags = CON_PRINTBUFFER | CON_ANYTIME,
1641 .index = -1,
1642 .data = &pch_uart_driver,
1643};
1644
1645#define PCH_CONSOLE (&pch_console)
1646#else
1647#define PCH_CONSOLE NULL
1648#endif
1649
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001650static struct uart_driver pch_uart_driver = {
1651 .owner = THIS_MODULE,
1652 .driver_name = KBUILD_MODNAME,
1653 .dev_name = PCH_UART_DRIVER_DEVICE,
1654 .major = 0,
1655 .minor = 0,
1656 .nr = PCH_UART_NR,
Alexander Steine30f8672011-11-15 15:04:07 -08001657 .cons = PCH_CONSOLE,
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001658};
1659
1660static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001661 const struct pci_device_id *id)
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001662{
1663 struct eg20t_port *priv;
1664 int ret;
1665 unsigned int iobase;
1666 unsigned int mapbase;
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001667 unsigned char *rxbuf;
Darren Hart077175f2012-03-09 09:51:49 -08001668 int fifosize;
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001669 int port_type;
1670 struct pch_uart_driver_data *board;
Feng Tangd0114112012-02-06 17:24:43 +08001671 char name[32]; /* for debugfs file name */
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001672
1673 board = &drv_dat[id->driver_data];
1674 port_type = board->port_type;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001675
1676 priv = kzalloc(sizeof(struct eg20t_port), GFP_KERNEL);
1677 if (priv == NULL)
1678 goto init_port_alloc_err;
1679
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001680 rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001681 if (!rxbuf)
1682 goto init_port_free_txbuf;
1683
1684 switch (port_type) {
1685 case PORT_UNKNOWN:
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001686 fifosize = 256; /* EG20T/ML7213: UART0 */
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001687 break;
1688 case PORT_8250:
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001689 fifosize = 64; /* EG20T:UART1~3 ML7213: UART1~2*/
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001690 break;
1691 default:
1692 dev_err(&pdev->dev, "Invalid Port Type(=%d)\n", port_type);
1693 goto init_port_hal_free;
1694 }
1695
Alexander Steine4635952011-07-04 08:58:31 +02001696 pci_enable_msi(pdev);
Tomoya MORINAGA867c9022012-04-02 14:36:22 +09001697 pci_set_master(pdev);
Alexander Steine4635952011-07-04 08:58:31 +02001698
Darren Hart61df4452012-06-19 14:00:18 -07001699 spin_lock_init(&priv->lock);
1700
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001701 iobase = pci_resource_start(pdev, 0);
1702 mapbase = pci_resource_start(pdev, 1);
1703 priv->mapbase = mapbase;
1704 priv->iobase = iobase;
1705 priv->pdev = pdev;
1706 priv->tx_empty = 1;
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001707 priv->rxbuf.buf = rxbuf;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001708 priv->rxbuf.size = PAGE_SIZE;
1709
1710 priv->fifo_size = fifosize;
Darren Hart077175f2012-03-09 09:51:49 -08001711 priv->uartclk = pch_uart_get_uartclk();
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001712 priv->port_type = PORT_MAX_8250 + port_type + 1;
1713 priv->port.dev = &pdev->dev;
1714 priv->port.iobase = iobase;
1715 priv->port.membase = NULL;
1716 priv->port.mapbase = mapbase;
1717 priv->port.irq = pdev->irq;
1718 priv->port.iotype = UPIO_PORT;
1719 priv->port.ops = &pch_uart_ops;
1720 priv->port.flags = UPF_BOOT_AUTOCONF;
1721 priv->port.fifosize = fifosize;
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001722 priv->port.line = board->line_no;
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001723 priv->trigger = PCH_UART_HAL_TRIGGER_M;
1724
Tomoya MORINAGA7e461322011-02-23 10:03:13 +09001725 spin_lock_init(&priv->port.lock);
1726
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001727 pci_set_drvdata(pdev, priv);
Feng Tang6f56d0f2012-02-06 17:24:45 +08001728 priv->trigger_level = 1;
1729 priv->fcr = 0;
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001730
Alexander Steine30f8672011-11-15 15:04:07 -08001731#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1732 pch_uart_ports[board->line_no] = priv;
1733#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001734 ret = uart_add_one_port(&pch_uart_driver, &priv->port);
1735 if (ret < 0)
1736 goto init_port_hal_free;
1737
Feng Tangd0114112012-02-06 17:24:43 +08001738#ifdef CONFIG_DEBUG_FS
1739 snprintf(name, sizeof(name), "uart%d_regs", board->line_no);
1740 priv->debugfs = debugfs_create_file(name, S_IFREG | S_IRUGO,
1741 NULL, priv, &port_regs_ops);
1742#endif
1743
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001744 return priv;
1745
1746init_port_hal_free:
Alexander Steine30f8672011-11-15 15:04:07 -08001747#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1748 pch_uart_ports[board->line_no] = NULL;
1749#endif
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001750 free_page((unsigned long)rxbuf);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001751init_port_free_txbuf:
1752 kfree(priv);
1753init_port_alloc_err:
1754
1755 return NULL;
1756}
1757
1758static void pch_uart_exit_port(struct eg20t_port *priv)
1759{
Feng Tangd0114112012-02-06 17:24:43 +08001760
1761#ifdef CONFIG_DEBUG_FS
1762 if (priv->debugfs)
1763 debugfs_remove(priv->debugfs);
1764#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001765 uart_remove_one_port(&pch_uart_driver, &priv->port);
1766 pci_set_drvdata(priv->pdev, NULL);
Tomoya MORINAGA1c518992010-12-16 16:13:29 +09001767 free_page((unsigned long)priv->rxbuf.buf);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001768}
1769
1770static void pch_uart_pci_remove(struct pci_dev *pdev)
1771{
Feng Tang6f56d0f2012-02-06 17:24:45 +08001772 struct eg20t_port *priv = pci_get_drvdata(pdev);
Alexander Steine4635952011-07-04 08:58:31 +02001773
1774 pci_disable_msi(pdev);
Alexander Steine30f8672011-11-15 15:04:07 -08001775
1776#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1777 pch_uart_ports[priv->port.line] = NULL;
1778#endif
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001779 pch_uart_exit_port(priv);
1780 pci_disable_device(pdev);
1781 kfree(priv);
1782 return;
1783}
1784#ifdef CONFIG_PM
1785static int pch_uart_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1786{
1787 struct eg20t_port *priv = pci_get_drvdata(pdev);
1788
1789 uart_suspend_port(&pch_uart_driver, &priv->port);
1790
1791 pci_save_state(pdev);
1792 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1793 return 0;
1794}
1795
1796static int pch_uart_pci_resume(struct pci_dev *pdev)
1797{
1798 struct eg20t_port *priv = pci_get_drvdata(pdev);
1799 int ret;
1800
1801 pci_set_power_state(pdev, PCI_D0);
1802 pci_restore_state(pdev);
1803
1804 ret = pci_enable_device(pdev);
1805 if (ret) {
1806 dev_err(&pdev->dev,
1807 "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
1808 return ret;
1809 }
1810
1811 uart_resume_port(&pch_uart_driver, &priv->port);
1812
1813 return 0;
1814}
1815#else
1816#define pch_uart_pci_suspend NULL
1817#define pch_uart_pci_resume NULL
1818#endif
1819
1820static DEFINE_PCI_DEVICE_TABLE(pch_uart_pci_id) = {
1821 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8811),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001822 .driver_data = pch_et20t_uart0},
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001823 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8812),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001824 .driver_data = pch_et20t_uart1},
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001825 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8813),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001826 .driver_data = pch_et20t_uart2},
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001827 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8814),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001828 .driver_data = pch_et20t_uart3},
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001829 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8027),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001830 .driver_data = pch_ml7213_uart0},
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001831 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8028),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001832 .driver_data = pch_ml7213_uart1},
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001833 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8029),
Tomoya MORINAGAfec38d12011-02-23 10:03:19 +09001834 .driver_data = pch_ml7213_uart2},
Tomoya MORINAGA177c2cb2011-05-09 17:25:20 +09001835 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800C),
1836 .driver_data = pch_ml7223_uart0},
1837 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800D),
1838 .driver_data = pch_ml7223_uart1},
Tomoya MORINAGA8249f742011-10-28 09:38:49 +09001839 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8811),
1840 .driver_data = pch_ml7831_uart0},
1841 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8812),
1842 .driver_data = pch_ml7831_uart1},
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001843 {0,},
1844};
1845
1846static int __devinit pch_uart_pci_probe(struct pci_dev *pdev,
1847 const struct pci_device_id *id)
1848{
1849 int ret;
1850 struct eg20t_port *priv;
1851
1852 ret = pci_enable_device(pdev);
1853 if (ret < 0)
1854 goto probe_error;
1855
Tomoya MORINAGA4564e1e2011-01-28 18:00:01 +09001856 priv = pch_uart_init_port(pdev, id);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001857 if (!priv) {
1858 ret = -EBUSY;
1859 goto probe_disable_device;
1860 }
1861 pci_set_drvdata(pdev, priv);
1862
1863 return ret;
1864
1865probe_disable_device:
Alexander Steine4635952011-07-04 08:58:31 +02001866 pci_disable_msi(pdev);
Tomoya MORINAGA3c6a4832010-11-17 09:55:54 +09001867 pci_disable_device(pdev);
1868probe_error:
1869 return ret;
1870}
1871
1872static struct pci_driver pch_uart_pci_driver = {
1873 .name = "pch_uart",
1874 .id_table = pch_uart_pci_id,
1875 .probe = pch_uart_pci_probe,
1876 .remove = __devexit_p(pch_uart_pci_remove),
1877 .suspend = pch_uart_pci_suspend,
1878 .resume = pch_uart_pci_resume,
1879};
1880
1881static int __init pch_uart_module_init(void)
1882{
1883 int ret;
1884
1885 /* register as UART driver */
1886 ret = uart_register_driver(&pch_uart_driver);
1887 if (ret < 0)
1888 return ret;
1889
1890 /* register as PCI driver */
1891 ret = pci_register_driver(&pch_uart_pci_driver);
1892 if (ret < 0)
1893 uart_unregister_driver(&pch_uart_driver);
1894
1895 return ret;
1896}
1897module_init(pch_uart_module_init);
1898
1899static void __exit pch_uart_module_exit(void)
1900{
1901 pci_unregister_driver(&pch_uart_pci_driver);
1902 uart_unregister_driver(&pch_uart_driver);
1903}
1904module_exit(pch_uart_module_exit);
1905
1906MODULE_LICENSE("GPL v2");
1907MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver");
1908module_param(default_baud, uint, S_IRUGO);
Darren Harta46f5532012-03-09 09:51:52 -08001909MODULE_PARM_DESC(default_baud,
1910 "Default BAUD for initial driver state and console (default 9600)");
Darren Hart2a44feb2012-03-09 09:51:50 -08001911module_param(user_uartclk, uint, S_IRUGO);
Darren Harta46f5532012-03-09 09:51:52 -08001912MODULE_PARM_DESC(user_uartclk,
1913 "Override UART default or board specific UART clock");