blob: 317067184bfa407c7cc862b634215b1835e8cbe6 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 *Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
4 */
5#if defined(CONFIG_SERIAL_PCH_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
6#define SUPPORT_SYSRQ
7#endif
8#include <linux/kernel.h>
9#include <linux/serial_reg.h>
10#include <linux/slab.h>
11#include <linux/module.h>
12#include <linux/pci.h>
13#include <linux/console.h>
14#include <linux/serial_core.h>
15#include <linux/tty.h>
16#include <linux/tty_flip.h>
17#include <linux/interrupt.h>
18#include <linux/io.h>
19#include <linux/dmi.h>
20#include <linux/nmi.h>
21#include <linux/delay.h>
22#include <linux/of.h>
23
24#include <linux/debugfs.h>
25#include <linux/dmaengine.h>
26#include <linux/pch_dma.h>
27
28enum {
29 PCH_UART_HANDLED_RX_INT_SHIFT,
30 PCH_UART_HANDLED_TX_INT_SHIFT,
31 PCH_UART_HANDLED_RX_ERR_INT_SHIFT,
32 PCH_UART_HANDLED_RX_TRG_INT_SHIFT,
33 PCH_UART_HANDLED_MS_INT_SHIFT,
34 PCH_UART_HANDLED_LS_INT_SHIFT,
35};
36
37#define PCH_UART_DRIVER_DEVICE "ttyPCH"
38
39/* Set the max number of UART port
40 * Intel EG20T PCH: 4 port
41 * LAPIS Semiconductor ML7213 IOH: 3 port
42 * LAPIS Semiconductor ML7223 IOH: 2 port
43*/
44#define PCH_UART_NR 4
45
46#define PCH_UART_HANDLED_RX_INT (1<<((PCH_UART_HANDLED_RX_INT_SHIFT)<<1))
47#define PCH_UART_HANDLED_TX_INT (1<<((PCH_UART_HANDLED_TX_INT_SHIFT)<<1))
48#define PCH_UART_HANDLED_RX_ERR_INT (1<<((\
49 PCH_UART_HANDLED_RX_ERR_INT_SHIFT)<<1))
50#define PCH_UART_HANDLED_RX_TRG_INT (1<<((\
51 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1))
52#define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1))
53
54#define PCH_UART_HANDLED_LS_INT (1<<((PCH_UART_HANDLED_LS_INT_SHIFT)<<1))
55
56#define PCH_UART_RBR 0x00
57#define PCH_UART_THR 0x00
58
59#define PCH_UART_IER_MASK (PCH_UART_IER_ERBFI|PCH_UART_IER_ETBEI|\
60 PCH_UART_IER_ELSI|PCH_UART_IER_EDSSI)
61#define PCH_UART_IER_ERBFI 0x00000001
62#define PCH_UART_IER_ETBEI 0x00000002
63#define PCH_UART_IER_ELSI 0x00000004
64#define PCH_UART_IER_EDSSI 0x00000008
65
66#define PCH_UART_IIR_IP 0x00000001
67#define PCH_UART_IIR_IID 0x00000006
68#define PCH_UART_IIR_MSI 0x00000000
69#define PCH_UART_IIR_TRI 0x00000002
70#define PCH_UART_IIR_RRI 0x00000004
71#define PCH_UART_IIR_REI 0x00000006
72#define PCH_UART_IIR_TOI 0x00000008
73#define PCH_UART_IIR_FIFO256 0x00000020
74#define PCH_UART_IIR_FIFO64 PCH_UART_IIR_FIFO256
75#define PCH_UART_IIR_FE 0x000000C0
76
77#define PCH_UART_FCR_FIFOE 0x00000001
78#define PCH_UART_FCR_RFR 0x00000002
79#define PCH_UART_FCR_TFR 0x00000004
80#define PCH_UART_FCR_DMS 0x00000008
81#define PCH_UART_FCR_FIFO256 0x00000020
82#define PCH_UART_FCR_RFTL 0x000000C0
83
84#define PCH_UART_FCR_RFTL1 0x00000000
85#define PCH_UART_FCR_RFTL64 0x00000040
86#define PCH_UART_FCR_RFTL128 0x00000080
87#define PCH_UART_FCR_RFTL224 0x000000C0
88#define PCH_UART_FCR_RFTL16 PCH_UART_FCR_RFTL64
89#define PCH_UART_FCR_RFTL32 PCH_UART_FCR_RFTL128
90#define PCH_UART_FCR_RFTL56 PCH_UART_FCR_RFTL224
91#define PCH_UART_FCR_RFTL4 PCH_UART_FCR_RFTL64
92#define PCH_UART_FCR_RFTL8 PCH_UART_FCR_RFTL128
93#define PCH_UART_FCR_RFTL14 PCH_UART_FCR_RFTL224
94#define PCH_UART_FCR_RFTL_SHIFT 6
95
96#define PCH_UART_LCR_WLS 0x00000003
97#define PCH_UART_LCR_STB 0x00000004
98#define PCH_UART_LCR_PEN 0x00000008
99#define PCH_UART_LCR_EPS 0x00000010
100#define PCH_UART_LCR_SP 0x00000020
101#define PCH_UART_LCR_SB 0x00000040
102#define PCH_UART_LCR_DLAB 0x00000080
103#define PCH_UART_LCR_NP 0x00000000
104#define PCH_UART_LCR_OP PCH_UART_LCR_PEN
105#define PCH_UART_LCR_EP (PCH_UART_LCR_PEN | PCH_UART_LCR_EPS)
106#define PCH_UART_LCR_1P (PCH_UART_LCR_PEN | PCH_UART_LCR_SP)
107#define PCH_UART_LCR_0P (PCH_UART_LCR_PEN | PCH_UART_LCR_EPS |\
108 PCH_UART_LCR_SP)
109
110#define PCH_UART_LCR_5BIT 0x00000000
111#define PCH_UART_LCR_6BIT 0x00000001
112#define PCH_UART_LCR_7BIT 0x00000002
113#define PCH_UART_LCR_8BIT 0x00000003
114
115#define PCH_UART_MCR_DTR 0x00000001
116#define PCH_UART_MCR_RTS 0x00000002
117#define PCH_UART_MCR_OUT 0x0000000C
118#define PCH_UART_MCR_LOOP 0x00000010
119#define PCH_UART_MCR_AFE 0x00000020
120
121#define PCH_UART_LSR_DR 0x00000001
122#define PCH_UART_LSR_ERR (1<<7)
123
124#define PCH_UART_MSR_DCTS 0x00000001
125#define PCH_UART_MSR_DDSR 0x00000002
126#define PCH_UART_MSR_TERI 0x00000004
127#define PCH_UART_MSR_DDCD 0x00000008
128#define PCH_UART_MSR_CTS 0x00000010
129#define PCH_UART_MSR_DSR 0x00000020
130#define PCH_UART_MSR_RI 0x00000040
131#define PCH_UART_MSR_DCD 0x00000080
132#define PCH_UART_MSR_DELTA (PCH_UART_MSR_DCTS | PCH_UART_MSR_DDSR |\
133 PCH_UART_MSR_TERI | PCH_UART_MSR_DDCD)
134
135#define PCH_UART_DLL 0x00
136#define PCH_UART_DLM 0x01
137
138#define PCH_UART_BRCSR 0x0E
139
140#define PCH_UART_IID_RLS (PCH_UART_IIR_REI)
141#define PCH_UART_IID_RDR (PCH_UART_IIR_RRI)
142#define PCH_UART_IID_RDR_TO (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI)
143#define PCH_UART_IID_THRE (PCH_UART_IIR_TRI)
144#define PCH_UART_IID_MS (PCH_UART_IIR_MSI)
145
146#define PCH_UART_HAL_PARITY_NONE (PCH_UART_LCR_NP)
147#define PCH_UART_HAL_PARITY_ODD (PCH_UART_LCR_OP)
148#define PCH_UART_HAL_PARITY_EVEN (PCH_UART_LCR_EP)
149#define PCH_UART_HAL_PARITY_FIX1 (PCH_UART_LCR_1P)
150#define PCH_UART_HAL_PARITY_FIX0 (PCH_UART_LCR_0P)
151#define PCH_UART_HAL_5BIT (PCH_UART_LCR_5BIT)
152#define PCH_UART_HAL_6BIT (PCH_UART_LCR_6BIT)
153#define PCH_UART_HAL_7BIT (PCH_UART_LCR_7BIT)
154#define PCH_UART_HAL_8BIT (PCH_UART_LCR_8BIT)
155#define PCH_UART_HAL_STB1 0
156#define PCH_UART_HAL_STB2 (PCH_UART_LCR_STB)
157
158#define PCH_UART_HAL_CLR_TX_FIFO (PCH_UART_FCR_TFR)
159#define PCH_UART_HAL_CLR_RX_FIFO (PCH_UART_FCR_RFR)
160#define PCH_UART_HAL_CLR_ALL_FIFO (PCH_UART_HAL_CLR_TX_FIFO | \
161 PCH_UART_HAL_CLR_RX_FIFO)
162
163#define PCH_UART_HAL_DMA_MODE0 0
164#define PCH_UART_HAL_FIFO_DIS 0
165#define PCH_UART_HAL_FIFO16 (PCH_UART_FCR_FIFOE)
166#define PCH_UART_HAL_FIFO256 (PCH_UART_FCR_FIFOE | \
167 PCH_UART_FCR_FIFO256)
168#define PCH_UART_HAL_FIFO64 (PCH_UART_HAL_FIFO256)
169#define PCH_UART_HAL_TRIGGER1 (PCH_UART_FCR_RFTL1)
170#define PCH_UART_HAL_TRIGGER64 (PCH_UART_FCR_RFTL64)
171#define PCH_UART_HAL_TRIGGER128 (PCH_UART_FCR_RFTL128)
172#define PCH_UART_HAL_TRIGGER224 (PCH_UART_FCR_RFTL224)
173#define PCH_UART_HAL_TRIGGER16 (PCH_UART_FCR_RFTL16)
174#define PCH_UART_HAL_TRIGGER32 (PCH_UART_FCR_RFTL32)
175#define PCH_UART_HAL_TRIGGER56 (PCH_UART_FCR_RFTL56)
176#define PCH_UART_HAL_TRIGGER4 (PCH_UART_FCR_RFTL4)
177#define PCH_UART_HAL_TRIGGER8 (PCH_UART_FCR_RFTL8)
178#define PCH_UART_HAL_TRIGGER14 (PCH_UART_FCR_RFTL14)
179#define PCH_UART_HAL_TRIGGER_L (PCH_UART_FCR_RFTL64)
180#define PCH_UART_HAL_TRIGGER_M (PCH_UART_FCR_RFTL128)
181#define PCH_UART_HAL_TRIGGER_H (PCH_UART_FCR_RFTL224)
182
183#define PCH_UART_HAL_RX_INT (PCH_UART_IER_ERBFI)
184#define PCH_UART_HAL_TX_INT (PCH_UART_IER_ETBEI)
185#define PCH_UART_HAL_RX_ERR_INT (PCH_UART_IER_ELSI)
186#define PCH_UART_HAL_MS_INT (PCH_UART_IER_EDSSI)
187#define PCH_UART_HAL_ALL_INT (PCH_UART_IER_MASK)
188
189#define PCH_UART_HAL_DTR (PCH_UART_MCR_DTR)
190#define PCH_UART_HAL_RTS (PCH_UART_MCR_RTS)
191#define PCH_UART_HAL_OUT (PCH_UART_MCR_OUT)
192#define PCH_UART_HAL_LOOP (PCH_UART_MCR_LOOP)
193#define PCH_UART_HAL_AFE (PCH_UART_MCR_AFE)
194
195#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
196
197#define DEFAULT_UARTCLK 1843200 /* 1.8432 MHz */
198#define CMITC_UARTCLK 192000000 /* 192.0000 MHz */
199#define FRI2_64_UARTCLK 64000000 /* 64.0000 MHz */
200#define FRI2_48_UARTCLK 48000000 /* 48.0000 MHz */
201#define NTC1_UARTCLK 64000000 /* 64.0000 MHz */
202#define MINNOW_UARTCLK 50000000 /* 50.0000 MHz */
203
204struct pch_uart_buffer {
205 unsigned char *buf;
206 int size;
207};
208
209struct eg20t_port {
210 struct uart_port port;
211 int port_type;
212 void __iomem *membase;
213 resource_size_t mapbase;
214 unsigned int iobase;
215 struct pci_dev *pdev;
216 int fifo_size;
217 unsigned int uartclk;
218 int start_tx;
219 int start_rx;
220 int tx_empty;
221 int trigger;
222 int trigger_level;
223 struct pch_uart_buffer rxbuf;
224 unsigned int dmsr;
225 unsigned int fcr;
226 unsigned int mcr;
227 unsigned int use_dma;
228 struct dma_async_tx_descriptor *desc_tx;
229 struct dma_async_tx_descriptor *desc_rx;
230 struct pch_dma_slave param_tx;
231 struct pch_dma_slave param_rx;
232 struct dma_chan *chan_tx;
233 struct dma_chan *chan_rx;
234 struct scatterlist *sg_tx_p;
235 int nent;
236 int orig_nent;
237 struct scatterlist sg_rx;
238 int tx_dma_use;
239 void *rx_buf_virt;
240 dma_addr_t rx_buf_dma;
241
242 struct dentry *debugfs;
243#define IRQ_NAME_SIZE 17
244 char irq_name[IRQ_NAME_SIZE];
245
246 /* protect the eg20t_port private structure and io access to membase */
247 spinlock_t lock;
248};
249
250/**
251 * struct pch_uart_driver_data - private data structure for UART-DMA
252 * @port_type: The type of UART port
253 * @line_no: UART port line number (0, 1, 2...)
254 */
255struct pch_uart_driver_data {
256 int port_type;
257 int line_no;
258};
259
260enum pch_uart_num_t {
261 pch_et20t_uart0 = 0,
262 pch_et20t_uart1,
263 pch_et20t_uart2,
264 pch_et20t_uart3,
265 pch_ml7213_uart0,
266 pch_ml7213_uart1,
267 pch_ml7213_uart2,
268 pch_ml7223_uart0,
269 pch_ml7223_uart1,
270 pch_ml7831_uart0,
271 pch_ml7831_uart1,
272};
273
274static struct pch_uart_driver_data drv_dat[] = {
275 [pch_et20t_uart0] = {PORT_PCH_8LINE, 0},
276 [pch_et20t_uart1] = {PORT_PCH_2LINE, 1},
277 [pch_et20t_uart2] = {PORT_PCH_2LINE, 2},
278 [pch_et20t_uart3] = {PORT_PCH_2LINE, 3},
279 [pch_ml7213_uart0] = {PORT_PCH_8LINE, 0},
280 [pch_ml7213_uart1] = {PORT_PCH_2LINE, 1},
281 [pch_ml7213_uart2] = {PORT_PCH_2LINE, 2},
282 [pch_ml7223_uart0] = {PORT_PCH_8LINE, 0},
283 [pch_ml7223_uart1] = {PORT_PCH_2LINE, 1},
284 [pch_ml7831_uart0] = {PORT_PCH_8LINE, 0},
285 [pch_ml7831_uart1] = {PORT_PCH_2LINE, 1},
286};
287
288#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
289static struct eg20t_port *pch_uart_ports[PCH_UART_NR];
290#endif
291static unsigned int default_baud = 9600;
292static unsigned int user_uartclk = 0;
293static const int trigger_level_256[4] = { 1, 64, 128, 224 };
294static const int trigger_level_64[4] = { 1, 16, 32, 56 };
295static const int trigger_level_16[4] = { 1, 4, 8, 14 };
296static const int trigger_level_1[4] = { 1, 1, 1, 1 };
297
298#ifdef CONFIG_DEBUG_FS
299
300#define PCH_REGS_BUFSIZE 1024
301
302
303static ssize_t port_show_regs(struct file *file, char __user *user_buf,
304 size_t count, loff_t *ppos)
305{
306 struct eg20t_port *priv = file->private_data;
307 char *buf;
308 u32 len = 0;
309 ssize_t ret;
310 unsigned char lcr;
311
312 buf = kzalloc(PCH_REGS_BUFSIZE, GFP_KERNEL);
313 if (!buf)
314 return 0;
315
316 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
317 "PCH EG20T port[%d] regs:\n", priv->port.line);
318
319 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
320 "=================================\n");
321 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
322 "IER: \t0x%02x\n", ioread8(priv->membase + UART_IER));
323 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
324 "IIR: \t0x%02x\n", ioread8(priv->membase + UART_IIR));
325 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
326 "LCR: \t0x%02x\n", ioread8(priv->membase + UART_LCR));
327 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
328 "MCR: \t0x%02x\n", ioread8(priv->membase + UART_MCR));
329 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
330 "LSR: \t0x%02x\n", ioread8(priv->membase + UART_LSR));
331 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
332 "MSR: \t0x%02x\n", ioread8(priv->membase + UART_MSR));
333 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
334 "BRCSR: \t0x%02x\n",
335 ioread8(priv->membase + PCH_UART_BRCSR));
336
337 lcr = ioread8(priv->membase + UART_LCR);
338 iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR);
339 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
340 "DLL: \t0x%02x\n", ioread8(priv->membase + UART_DLL));
341 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
342 "DLM: \t0x%02x\n", ioread8(priv->membase + UART_DLM));
343 iowrite8(lcr, priv->membase + UART_LCR);
344
345 if (len > PCH_REGS_BUFSIZE)
346 len = PCH_REGS_BUFSIZE;
347
348 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
349 kfree(buf);
350 return ret;
351}
352
353static const struct file_operations port_regs_ops = {
354 .owner = THIS_MODULE,
355 .open = simple_open,
356 .read = port_show_regs,
357 .llseek = default_llseek,
358};
359#endif /* CONFIG_DEBUG_FS */
360
361static const struct dmi_system_id pch_uart_dmi_table[] = {
362 {
363 .ident = "CM-iTC",
364 {
365 DMI_MATCH(DMI_BOARD_NAME, "CM-iTC"),
366 },
367 (void *)CMITC_UARTCLK,
368 },
369 {
370 .ident = "FRI2",
371 {
372 DMI_MATCH(DMI_BIOS_VERSION, "FRI2"),
373 },
374 (void *)FRI2_64_UARTCLK,
375 },
376 {
377 .ident = "Fish River Island II",
378 {
379 DMI_MATCH(DMI_PRODUCT_NAME, "Fish River Island II"),
380 },
381 (void *)FRI2_48_UARTCLK,
382 },
383 {
384 .ident = "COMe-mTT",
385 {
386 DMI_MATCH(DMI_BOARD_NAME, "COMe-mTT"),
387 },
388 (void *)NTC1_UARTCLK,
389 },
390 {
391 .ident = "nanoETXexpress-TT",
392 {
393 DMI_MATCH(DMI_BOARD_NAME, "nanoETXexpress-TT"),
394 },
395 (void *)NTC1_UARTCLK,
396 },
397 {
398 .ident = "MinnowBoard",
399 {
400 DMI_MATCH(DMI_BOARD_NAME, "MinnowBoard"),
401 },
402 (void *)MINNOW_UARTCLK,
403 },
404 { }
405};
406
407/* Return UART clock, checking for board specific clocks. */
408static unsigned int pch_uart_get_uartclk(void)
409{
410 const struct dmi_system_id *d;
411
412 if (user_uartclk)
413 return user_uartclk;
414
415 d = dmi_first_match(pch_uart_dmi_table);
416 if (d)
417 return (unsigned long)d->driver_data;
418
419 return DEFAULT_UARTCLK;
420}
421
422static void pch_uart_hal_enable_interrupt(struct eg20t_port *priv,
423 unsigned int flag)
424{
425 u8 ier = ioread8(priv->membase + UART_IER);
426 ier |= flag & PCH_UART_IER_MASK;
427 iowrite8(ier, priv->membase + UART_IER);
428}
429
430static void pch_uart_hal_disable_interrupt(struct eg20t_port *priv,
431 unsigned int flag)
432{
433 u8 ier = ioread8(priv->membase + UART_IER);
434 ier &= ~(flag & PCH_UART_IER_MASK);
435 iowrite8(ier, priv->membase + UART_IER);
436}
437
438static int pch_uart_hal_set_line(struct eg20t_port *priv, unsigned int baud,
439 unsigned int parity, unsigned int bits,
440 unsigned int stb)
441{
442 unsigned int dll, dlm, lcr;
443 int div;
444
445 div = DIV_ROUND_CLOSEST(priv->uartclk / 16, baud);
446 if (div < 0 || USHRT_MAX <= div) {
447 dev_err(priv->port.dev, "Invalid Baud(div=0x%x)\n", div);
448 return -EINVAL;
449 }
450
451 dll = (unsigned int)div & 0x00FFU;
452 dlm = ((unsigned int)div >> 8) & 0x00FFU;
453
454 if (parity & ~(PCH_UART_LCR_PEN | PCH_UART_LCR_EPS | PCH_UART_LCR_SP)) {
455 dev_err(priv->port.dev, "Invalid parity(0x%x)\n", parity);
456 return -EINVAL;
457 }
458
459 if (bits & ~PCH_UART_LCR_WLS) {
460 dev_err(priv->port.dev, "Invalid bits(0x%x)\n", bits);
461 return -EINVAL;
462 }
463
464 if (stb & ~PCH_UART_LCR_STB) {
465 dev_err(priv->port.dev, "Invalid STB(0x%x)\n", stb);
466 return -EINVAL;
467 }
468
469 lcr = parity;
470 lcr |= bits;
471 lcr |= stb;
472
473 dev_dbg(priv->port.dev, "%s:baud = %u, div = %04x, lcr = %02x (%lu)\n",
474 __func__, baud, div, lcr, jiffies);
475 iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR);
476 iowrite8(dll, priv->membase + PCH_UART_DLL);
477 iowrite8(dlm, priv->membase + PCH_UART_DLM);
478 iowrite8(lcr, priv->membase + UART_LCR);
479
480 return 0;
481}
482
483static int pch_uart_hal_fifo_reset(struct eg20t_port *priv,
484 unsigned int flag)
485{
486 if (flag & ~(PCH_UART_FCR_TFR | PCH_UART_FCR_RFR)) {
487 dev_err(priv->port.dev, "%s:Invalid flag(0x%x)\n",
488 __func__, flag);
489 return -EINVAL;
490 }
491
492 iowrite8(PCH_UART_FCR_FIFOE | priv->fcr, priv->membase + UART_FCR);
493 iowrite8(PCH_UART_FCR_FIFOE | priv->fcr | flag,
494 priv->membase + UART_FCR);
495 iowrite8(priv->fcr, priv->membase + UART_FCR);
496
497 return 0;
498}
499
500static int pch_uart_hal_set_fifo(struct eg20t_port *priv,
501 unsigned int dmamode,
502 unsigned int fifo_size, unsigned int trigger)
503{
504 u8 fcr;
505
506 if (dmamode & ~PCH_UART_FCR_DMS) {
507 dev_err(priv->port.dev, "%s:Invalid DMA Mode(0x%x)\n",
508 __func__, dmamode);
509 return -EINVAL;
510 }
511
512 if (fifo_size & ~(PCH_UART_FCR_FIFOE | PCH_UART_FCR_FIFO256)) {
513 dev_err(priv->port.dev, "%s:Invalid FIFO SIZE(0x%x)\n",
514 __func__, fifo_size);
515 return -EINVAL;
516 }
517
518 if (trigger & ~PCH_UART_FCR_RFTL) {
519 dev_err(priv->port.dev, "%s:Invalid TRIGGER(0x%x)\n",
520 __func__, trigger);
521 return -EINVAL;
522 }
523
524 switch (priv->fifo_size) {
525 case 256:
526 priv->trigger_level =
527 trigger_level_256[trigger >> PCH_UART_FCR_RFTL_SHIFT];
528 break;
529 case 64:
530 priv->trigger_level =
531 trigger_level_64[trigger >> PCH_UART_FCR_RFTL_SHIFT];
532 break;
533 case 16:
534 priv->trigger_level =
535 trigger_level_16[trigger >> PCH_UART_FCR_RFTL_SHIFT];
536 break;
537 default:
538 priv->trigger_level =
539 trigger_level_1[trigger >> PCH_UART_FCR_RFTL_SHIFT];
540 break;
541 }
542 fcr =
543 dmamode | fifo_size | trigger | PCH_UART_FCR_RFR | PCH_UART_FCR_TFR;
544 iowrite8(PCH_UART_FCR_FIFOE, priv->membase + UART_FCR);
545 iowrite8(PCH_UART_FCR_FIFOE | PCH_UART_FCR_RFR | PCH_UART_FCR_TFR,
546 priv->membase + UART_FCR);
547 iowrite8(fcr, priv->membase + UART_FCR);
548 priv->fcr = fcr;
549
550 return 0;
551}
552
553static u8 pch_uart_hal_get_modem(struct eg20t_port *priv)
554{
555 unsigned int msr = ioread8(priv->membase + UART_MSR);
556 priv->dmsr = msr & PCH_UART_MSR_DELTA;
557 return (u8)msr;
558}
559
560static void pch_uart_hal_write(struct eg20t_port *priv,
561 const unsigned char *buf, int tx_size)
562{
563 int i;
564 unsigned int thr;
565
566 for (i = 0; i < tx_size;) {
567 thr = buf[i++];
568 iowrite8(thr, priv->membase + PCH_UART_THR);
569 }
570}
571
572static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf,
573 int rx_size)
574{
575 int i;
576 u8 rbr, lsr;
577 struct uart_port *port = &priv->port;
578
579 lsr = ioread8(priv->membase + UART_LSR);
580 for (i = 0, lsr = ioread8(priv->membase + UART_LSR);
581 i < rx_size && lsr & (UART_LSR_DR | UART_LSR_BI);
582 lsr = ioread8(priv->membase + UART_LSR)) {
583 rbr = ioread8(priv->membase + PCH_UART_RBR);
584
585 if (lsr & UART_LSR_BI) {
586 port->icount.brk++;
587 if (uart_handle_break(port))
588 continue;
589 }
590#ifdef SUPPORT_SYSRQ
591 if (port->sysrq) {
592 if (uart_handle_sysrq_char(port, rbr))
593 continue;
594 }
595#endif
596
597 buf[i++] = rbr;
598 }
599 return i;
600}
601
602static unsigned char pch_uart_hal_get_iid(struct eg20t_port *priv)
603{
604 return ioread8(priv->membase + UART_IIR) &\
605 (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP);
606}
607
608static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv)
609{
610 return ioread8(priv->membase + UART_LSR);
611}
612
613static void pch_uart_hal_set_break(struct eg20t_port *priv, int on)
614{
615 unsigned int lcr;
616
617 lcr = ioread8(priv->membase + UART_LCR);
618 if (on)
619 lcr |= PCH_UART_LCR_SB;
620 else
621 lcr &= ~PCH_UART_LCR_SB;
622
623 iowrite8(lcr, priv->membase + UART_LCR);
624}
625
626static int push_rx(struct eg20t_port *priv, const unsigned char *buf,
627 int size)
628{
629 struct uart_port *port = &priv->port;
630 struct tty_port *tport = &port->state->port;
631
632 tty_insert_flip_string(tport, buf, size);
633 tty_flip_buffer_push(tport);
634
635 return 0;
636}
637
638static int dma_push_rx(struct eg20t_port *priv, int size)
639{
640 int room;
641 struct uart_port *port = &priv->port;
642 struct tty_port *tport = &port->state->port;
643
644 room = tty_buffer_request_room(tport, size);
645
646 if (room < size)
647 dev_warn(port->dev, "Rx overrun: dropping %u bytes\n",
648 size - room);
649 if (!room)
650 return 0;
651
652 tty_insert_flip_string(tport, sg_virt(&priv->sg_rx), size);
653
654 port->icount.rx += room;
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
673 if (priv->rx_buf_dma) {
674 dma_free_coherent(port->dev, port->fifosize, priv->rx_buf_virt,
675 priv->rx_buf_dma);
676 priv->rx_buf_virt = NULL;
677 priv->rx_buf_dma = 0;
678 }
679
680 return;
681}
682
683static bool filter(struct dma_chan *chan, void *slave)
684{
685 struct pch_dma_slave *param = slave;
686
687 if ((chan->chan_id == param->chan_id) && (param->dma_dev ==
688 chan->device->dev)) {
689 chan->private = param;
690 return true;
691 } else {
692 return false;
693 }
694}
695
696static void pch_request_dma(struct uart_port *port)
697{
698 dma_cap_mask_t mask;
699 struct dma_chan *chan;
700 struct pci_dev *dma_dev;
701 struct pch_dma_slave *param;
702 struct eg20t_port *priv =
703 container_of(port, struct eg20t_port, port);
704 dma_cap_zero(mask);
705 dma_cap_set(DMA_SLAVE, mask);
706
707 /* Get DMA's dev information */
708 dma_dev = pci_get_slot(priv->pdev->bus,
709 PCI_DEVFN(PCI_SLOT(priv->pdev->devfn), 0));
710
711 /* Set Tx DMA */
712 param = &priv->param_tx;
713 param->dma_dev = &dma_dev->dev;
714 param->chan_id = priv->port.line * 2; /* Tx = 0, 2, 4, ... */
715
716 param->tx_reg = port->mapbase + UART_TX;
717 chan = dma_request_channel(mask, filter, param);
718 if (!chan) {
719 dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Tx)\n",
720 __func__);
721 pci_dev_put(dma_dev);
722 return;
723 }
724 priv->chan_tx = chan;
725
726 /* Set Rx DMA */
727 param = &priv->param_rx;
728 param->dma_dev = &dma_dev->dev;
729 param->chan_id = priv->port.line * 2 + 1; /* Rx = Tx + 1 */
730
731 param->rx_reg = port->mapbase + UART_RX;
732 chan = dma_request_channel(mask, filter, param);
733 if (!chan) {
734 dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Rx)\n",
735 __func__);
736 dma_release_channel(priv->chan_tx);
737 priv->chan_tx = NULL;
738 pci_dev_put(dma_dev);
739 return;
740 }
741
742 /* Get Consistent memory for DMA */
743 priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
744 &priv->rx_buf_dma, GFP_KERNEL);
745 priv->chan_rx = chan;
746
747 pci_dev_put(dma_dev);
748}
749
750static void pch_dma_rx_complete(void *arg)
751{
752 struct eg20t_port *priv = arg;
753 struct uart_port *port = &priv->port;
754 int count;
755
756 dma_sync_sg_for_cpu(port->dev, &priv->sg_rx, 1, DMA_FROM_DEVICE);
757 count = dma_push_rx(priv, priv->trigger_level);
758 if (count)
759 tty_flip_buffer_push(&port->state->port);
760 async_tx_ack(priv->desc_rx);
761 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT |
762 PCH_UART_HAL_RX_ERR_INT);
763}
764
765static void pch_dma_tx_complete(void *arg)
766{
767 struct eg20t_port *priv = arg;
768 struct uart_port *port = &priv->port;
769 struct circ_buf *xmit = &port->state->xmit;
770 struct scatterlist *sg = priv->sg_tx_p;
771 int i;
772
773 for (i = 0; i < priv->nent; i++, sg++) {
774 xmit->tail += sg_dma_len(sg);
775 port->icount.tx += sg_dma_len(sg);
776 }
777 xmit->tail &= UART_XMIT_SIZE - 1;
778 async_tx_ack(priv->desc_tx);
779 dma_unmap_sg(port->dev, priv->sg_tx_p, priv->orig_nent, DMA_TO_DEVICE);
780 priv->tx_dma_use = 0;
781 priv->nent = 0;
782 priv->orig_nent = 0;
783 kfree(priv->sg_tx_p);
784 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_TX_INT);
785}
786
787static int pop_tx(struct eg20t_port *priv, int size)
788{
789 int count = 0;
790 struct uart_port *port = &priv->port;
791 struct circ_buf *xmit = &port->state->xmit;
792
793 if (uart_tx_stopped(port) || uart_circ_empty(xmit) || count >= size)
794 goto pop_tx_end;
795
796 do {
797 int cnt_to_end =
798 CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
799 int sz = min(size - count, cnt_to_end);
800 pch_uart_hal_write(priv, &xmit->buf[xmit->tail], sz);
801 xmit->tail = (xmit->tail + sz) & (UART_XMIT_SIZE - 1);
802 count += sz;
803 } while (!uart_circ_empty(xmit) && count < size);
804
805pop_tx_end:
806 dev_dbg(priv->port.dev, "%d characters. Remained %d characters.(%lu)\n",
807 count, size - count, jiffies);
808
809 return count;
810}
811
812static int handle_rx_to(struct eg20t_port *priv)
813{
814 struct pch_uart_buffer *buf;
815 int rx_size;
816 int ret;
817 if (!priv->start_rx) {
818 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT |
819 PCH_UART_HAL_RX_ERR_INT);
820 return 0;
821 }
822 buf = &priv->rxbuf;
823 do {
824 rx_size = pch_uart_hal_read(priv, buf->buf, buf->size);
825 ret = push_rx(priv, buf->buf, rx_size);
826 if (ret)
827 return 0;
828 } while (rx_size == buf->size);
829
830 return PCH_UART_HANDLED_RX_INT;
831}
832
833static int handle_rx(struct eg20t_port *priv)
834{
835 return handle_rx_to(priv);
836}
837
838static int dma_handle_rx(struct eg20t_port *priv)
839{
840 struct uart_port *port = &priv->port;
841 struct dma_async_tx_descriptor *desc;
842 struct scatterlist *sg;
843
844 priv = container_of(port, struct eg20t_port, port);
845 sg = &priv->sg_rx;
846
847 sg_init_table(&priv->sg_rx, 1); /* Initialize SG table */
848
849 sg_dma_len(sg) = priv->trigger_level;
850
851 sg_set_page(&priv->sg_rx, virt_to_page(priv->rx_buf_virt),
852 sg_dma_len(sg), offset_in_page(priv->rx_buf_virt));
853
854 sg_dma_address(sg) = priv->rx_buf_dma;
855
856 desc = dmaengine_prep_slave_sg(priv->chan_rx,
857 sg, 1, DMA_DEV_TO_MEM,
858 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
859
860 if (!desc)
861 return 0;
862
863 priv->desc_rx = desc;
864 desc->callback = pch_dma_rx_complete;
865 desc->callback_param = priv;
866 desc->tx_submit(desc);
867 dma_async_issue_pending(priv->chan_rx);
868
869 return PCH_UART_HANDLED_RX_INT;
870}
871
872static unsigned int handle_tx(struct eg20t_port *priv)
873{
874 struct uart_port *port = &priv->port;
875 struct circ_buf *xmit = &port->state->xmit;
876 int fifo_size;
877 int tx_size;
878 int size;
879 int tx_empty;
880
881 if (!priv->start_tx) {
882 dev_info(priv->port.dev, "%s:Tx isn't started. (%lu)\n",
883 __func__, jiffies);
884 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
885 priv->tx_empty = 1;
886 return 0;
887 }
888
889 fifo_size = max(priv->fifo_size, 1);
890 tx_empty = 1;
891 if (port->x_char) {
892 pch_uart_hal_write(priv, &port->x_char, 1);
893 port->icount.tx++;
894 port->x_char = 0;
895 tx_empty = 0;
896 fifo_size--;
897 }
898 size = min(xmit->head - xmit->tail, fifo_size);
899 if (size < 0)
900 size = fifo_size;
901
902 tx_size = pop_tx(priv, size);
903 if (tx_size > 0) {
904 port->icount.tx += tx_size;
905 tx_empty = 0;
906 }
907
908 priv->tx_empty = tx_empty;
909
910 if (tx_empty) {
911 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
912 uart_write_wakeup(port);
913 }
914
915 return PCH_UART_HANDLED_TX_INT;
916}
917
918static unsigned int dma_handle_tx(struct eg20t_port *priv)
919{
920 struct uart_port *port = &priv->port;
921 struct circ_buf *xmit = &port->state->xmit;
922 struct scatterlist *sg;
923 int nent;
924 int fifo_size;
925 struct dma_async_tx_descriptor *desc;
926 int num;
927 int i;
928 int bytes;
929 int size;
930 int rem;
931
932 if (!priv->start_tx) {
933 dev_info(priv->port.dev, "%s:Tx isn't started. (%lu)\n",
934 __func__, jiffies);
935 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
936 priv->tx_empty = 1;
937 return 0;
938 }
939
940 if (priv->tx_dma_use) {
941 dev_dbg(priv->port.dev, "%s:Tx is not completed. (%lu)\n",
942 __func__, jiffies);
943 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
944 priv->tx_empty = 1;
945 return 0;
946 }
947
948 fifo_size = max(priv->fifo_size, 1);
949
950 if (port->x_char) {
951 pch_uart_hal_write(priv, &port->x_char, 1);
952 port->icount.tx++;
953 port->x_char = 0;
954 fifo_size--;
955 }
956
957 bytes = min((int)CIRC_CNT(xmit->head, xmit->tail,
958 UART_XMIT_SIZE), CIRC_CNT_TO_END(xmit->head,
959 xmit->tail, UART_XMIT_SIZE));
960 if (!bytes) {
961 dev_dbg(priv->port.dev, "%s 0 bytes return\n", __func__);
962 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_TX_INT);
963 uart_write_wakeup(port);
964 return 0;
965 }
966
967 if (bytes > fifo_size) {
968 num = bytes / fifo_size + 1;
969 size = fifo_size;
970 rem = bytes % fifo_size;
971 } else {
972 num = 1;
973 size = bytes;
974 rem = bytes;
975 }
976
977 dev_dbg(priv->port.dev, "%s num=%d size=%d rem=%d\n",
978 __func__, num, size, rem);
979
980 priv->tx_dma_use = 1;
981
982 priv->sg_tx_p = kcalloc(num, sizeof(struct scatterlist), GFP_ATOMIC);
983 if (!priv->sg_tx_p) {
984 dev_err(priv->port.dev, "%s:kzalloc Failed\n", __func__);
985 return 0;
986 }
987
988 sg_init_table(priv->sg_tx_p, num); /* Initialize SG table */
989 sg = priv->sg_tx_p;
990
991 for (i = 0; i < num; i++, sg++) {
992 if (i == (num - 1))
993 sg_set_page(sg, virt_to_page(xmit->buf),
994 rem, fifo_size * i);
995 else
996 sg_set_page(sg, virt_to_page(xmit->buf),
997 size, fifo_size * i);
998 }
999
1000 sg = priv->sg_tx_p;
1001 nent = dma_map_sg(port->dev, sg, num, DMA_TO_DEVICE);
1002 if (!nent) {
1003 dev_err(priv->port.dev, "%s:dma_map_sg Failed\n", __func__);
1004 return 0;
1005 }
1006 priv->orig_nent = num;
1007 priv->nent = nent;
1008
1009 for (i = 0; i < nent; i++, sg++) {
1010 sg->offset = (xmit->tail & (UART_XMIT_SIZE - 1)) +
1011 fifo_size * i;
1012 sg_dma_address(sg) = (sg_dma_address(sg) &
1013 ~(UART_XMIT_SIZE - 1)) + sg->offset;
1014 if (i == (nent - 1))
1015 sg_dma_len(sg) = rem;
1016 else
1017 sg_dma_len(sg) = size;
1018 }
1019
1020 desc = dmaengine_prep_slave_sg(priv->chan_tx,
1021 priv->sg_tx_p, nent, DMA_MEM_TO_DEV,
1022 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1023 if (!desc) {
1024 dev_err(priv->port.dev, "%s:dmaengine_prep_slave_sg Failed\n",
1025 __func__);
1026 return 0;
1027 }
1028 dma_sync_sg_for_device(port->dev, priv->sg_tx_p, nent, DMA_TO_DEVICE);
1029 priv->desc_tx = desc;
1030 desc->callback = pch_dma_tx_complete;
1031 desc->callback_param = priv;
1032
1033 desc->tx_submit(desc);
1034
1035 dma_async_issue_pending(priv->chan_tx);
1036
1037 return PCH_UART_HANDLED_TX_INT;
1038}
1039
1040static void pch_uart_err_ir(struct eg20t_port *priv, unsigned int lsr)
1041{
1042 struct uart_port *port = &priv->port;
1043 struct tty_struct *tty = tty_port_tty_get(&port->state->port);
1044 char *error_msg[5] = {};
1045 int i = 0;
1046
1047 if (lsr & PCH_UART_LSR_ERR)
1048 error_msg[i++] = "Error data in FIFO\n";
1049
1050 if (lsr & UART_LSR_FE) {
1051 port->icount.frame++;
1052 error_msg[i++] = " Framing Error\n";
1053 }
1054
1055 if (lsr & UART_LSR_PE) {
1056 port->icount.parity++;
1057 error_msg[i++] = " Parity Error\n";
1058 }
1059
1060 if (lsr & UART_LSR_OE) {
1061 port->icount.overrun++;
1062 error_msg[i++] = " Overrun Error\n";
1063 }
1064
1065 if (tty == NULL) {
1066 for (i = 0; error_msg[i] != NULL; i++)
1067 dev_err(&priv->pdev->dev, error_msg[i]);
1068 } else {
1069 tty_kref_put(tty);
1070 }
1071}
1072
1073static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1074{
1075 struct eg20t_port *priv = dev_id;
1076 unsigned int handled;
1077 u8 lsr;
1078 int ret = 0;
1079 unsigned char iid;
1080 unsigned long flags;
1081 int next = 1;
1082 u8 msr;
1083
1084 spin_lock_irqsave(&priv->lock, flags);
1085 handled = 0;
1086 while (next) {
1087 iid = pch_uart_hal_get_iid(priv);
1088 if (iid & PCH_UART_IIR_IP) /* No Interrupt */
1089 break;
1090 switch (iid) {
1091 case PCH_UART_IID_RLS: /* Receiver Line Status */
1092 lsr = pch_uart_hal_get_line_status(priv);
1093 if (lsr & (PCH_UART_LSR_ERR | UART_LSR_FE |
1094 UART_LSR_PE | UART_LSR_OE)) {
1095 pch_uart_err_ir(priv, lsr);
1096 ret = PCH_UART_HANDLED_RX_ERR_INT;
1097 } else {
1098 ret = PCH_UART_HANDLED_LS_INT;
1099 }
1100 break;
1101 case PCH_UART_IID_RDR: /* Received Data Ready */
1102 if (priv->use_dma) {
1103 pch_uart_hal_disable_interrupt(priv,
1104 PCH_UART_HAL_RX_INT |
1105 PCH_UART_HAL_RX_ERR_INT);
1106 ret = dma_handle_rx(priv);
1107 if (!ret)
1108 pch_uart_hal_enable_interrupt(priv,
1109 PCH_UART_HAL_RX_INT |
1110 PCH_UART_HAL_RX_ERR_INT);
1111 } else {
1112 ret = handle_rx(priv);
1113 }
1114 break;
1115 case PCH_UART_IID_RDR_TO: /* Received Data Ready
1116 (FIFO Timeout) */
1117 ret = handle_rx_to(priv);
1118 break;
1119 case PCH_UART_IID_THRE: /* Transmitter Holding Register
1120 Empty */
1121 if (priv->use_dma)
1122 ret = dma_handle_tx(priv);
1123 else
1124 ret = handle_tx(priv);
1125 break;
1126 case PCH_UART_IID_MS: /* Modem Status */
1127 msr = pch_uart_hal_get_modem(priv);
1128 next = 0; /* MS ir prioirty is the lowest. So, MS ir
1129 means final interrupt */
1130 if ((msr & UART_MSR_ANY_DELTA) == 0)
1131 break;
1132 ret |= PCH_UART_HANDLED_MS_INT;
1133 break;
1134 default: /* Never junp to this label */
1135 dev_err(priv->port.dev, "%s:iid=%02x (%lu)\n", __func__,
1136 iid, jiffies);
1137 ret = -1;
1138 next = 0;
1139 break;
1140 }
1141 handled |= (unsigned int)ret;
1142 }
1143
1144 spin_unlock_irqrestore(&priv->lock, flags);
1145 return IRQ_RETVAL(handled);
1146}
1147
1148/* This function tests whether the transmitter fifo and shifter for the port
1149 described by 'port' is empty. */
1150static unsigned int pch_uart_tx_empty(struct uart_port *port)
1151{
1152 struct eg20t_port *priv;
1153
1154 priv = container_of(port, struct eg20t_port, port);
1155 if (priv->tx_empty)
1156 return TIOCSER_TEMT;
1157 else
1158 return 0;
1159}
1160
1161/* Returns the current state of modem control inputs. */
1162static unsigned int pch_uart_get_mctrl(struct uart_port *port)
1163{
1164 struct eg20t_port *priv;
1165 u8 modem;
1166 unsigned int ret = 0;
1167
1168 priv = container_of(port, struct eg20t_port, port);
1169 modem = pch_uart_hal_get_modem(priv);
1170
1171 if (modem & UART_MSR_DCD)
1172 ret |= TIOCM_CAR;
1173
1174 if (modem & UART_MSR_RI)
1175 ret |= TIOCM_RNG;
1176
1177 if (modem & UART_MSR_DSR)
1178 ret |= TIOCM_DSR;
1179
1180 if (modem & UART_MSR_CTS)
1181 ret |= TIOCM_CTS;
1182
1183 return ret;
1184}
1185
1186static void pch_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
1187{
1188 u32 mcr = 0;
1189 struct eg20t_port *priv = container_of(port, struct eg20t_port, port);
1190
1191 if (mctrl & TIOCM_DTR)
1192 mcr |= UART_MCR_DTR;
1193 if (mctrl & TIOCM_RTS)
1194 mcr |= UART_MCR_RTS;
1195 if (mctrl & TIOCM_LOOP)
1196 mcr |= UART_MCR_LOOP;
1197
1198 if (priv->mcr & UART_MCR_AFE)
1199 mcr |= UART_MCR_AFE;
1200
1201 if (mctrl)
1202 iowrite8(mcr, priv->membase + UART_MCR);
1203}
1204
1205static void pch_uart_stop_tx(struct uart_port *port)
1206{
1207 struct eg20t_port *priv;
1208 priv = container_of(port, struct eg20t_port, port);
1209 priv->start_tx = 0;
1210 priv->tx_dma_use = 0;
1211}
1212
1213static void pch_uart_start_tx(struct uart_port *port)
1214{
1215 struct eg20t_port *priv;
1216
1217 priv = container_of(port, struct eg20t_port, port);
1218
1219 if (priv->use_dma) {
1220 if (priv->tx_dma_use) {
1221 dev_dbg(priv->port.dev, "%s : Tx DMA is NOT empty.\n",
1222 __func__);
1223 return;
1224 }
1225 }
1226
1227 priv->start_tx = 1;
1228 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_TX_INT);
1229}
1230
1231static void pch_uart_stop_rx(struct uart_port *port)
1232{
1233 struct eg20t_port *priv;
1234 priv = container_of(port, struct eg20t_port, port);
1235 priv->start_rx = 0;
1236 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT |
1237 PCH_UART_HAL_RX_ERR_INT);
1238}
1239
1240/* Enable the modem status interrupts. */
1241static void pch_uart_enable_ms(struct uart_port *port)
1242{
1243 struct eg20t_port *priv;
1244 priv = container_of(port, struct eg20t_port, port);
1245 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_MS_INT);
1246}
1247
1248/* Control the transmission of a break signal. */
1249static void pch_uart_break_ctl(struct uart_port *port, int ctl)
1250{
1251 struct eg20t_port *priv;
1252 unsigned long flags;
1253
1254 priv = container_of(port, struct eg20t_port, port);
1255 spin_lock_irqsave(&priv->lock, flags);
1256 pch_uart_hal_set_break(priv, ctl);
1257 spin_unlock_irqrestore(&priv->lock, flags);
1258}
1259
1260/* Grab any interrupt resources and initialise any low level driver state. */
1261static int pch_uart_startup(struct uart_port *port)
1262{
1263 struct eg20t_port *priv;
1264 int ret;
1265 int fifo_size;
1266 int trigger_level;
1267
1268 priv = container_of(port, struct eg20t_port, port);
1269 priv->tx_empty = 1;
1270
1271 if (port->uartclk)
1272 priv->uartclk = port->uartclk;
1273 else
1274 port->uartclk = priv->uartclk;
1275
1276 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1277 ret = pch_uart_hal_set_line(priv, default_baud,
1278 PCH_UART_HAL_PARITY_NONE, PCH_UART_HAL_8BIT,
1279 PCH_UART_HAL_STB1);
1280 if (ret)
1281 return ret;
1282
1283 switch (priv->fifo_size) {
1284 case 256:
1285 fifo_size = PCH_UART_HAL_FIFO256;
1286 break;
1287 case 64:
1288 fifo_size = PCH_UART_HAL_FIFO64;
1289 break;
1290 case 16:
1291 fifo_size = PCH_UART_HAL_FIFO16;
1292 break;
1293 case 1:
1294 default:
1295 fifo_size = PCH_UART_HAL_FIFO_DIS;
1296 break;
1297 }
1298
1299 switch (priv->trigger) {
1300 case PCH_UART_HAL_TRIGGER1:
1301 trigger_level = 1;
1302 break;
1303 case PCH_UART_HAL_TRIGGER_L:
1304 trigger_level = priv->fifo_size / 4;
1305 break;
1306 case PCH_UART_HAL_TRIGGER_M:
1307 trigger_level = priv->fifo_size / 2;
1308 break;
1309 case PCH_UART_HAL_TRIGGER_H:
1310 default:
1311 trigger_level = priv->fifo_size - (priv->fifo_size / 8);
1312 break;
1313 }
1314
1315 priv->trigger_level = trigger_level;
1316 ret = pch_uart_hal_set_fifo(priv, PCH_UART_HAL_DMA_MODE0,
1317 fifo_size, priv->trigger);
1318 if (ret < 0)
1319 return ret;
1320
1321 ret = request_irq(priv->port.irq, pch_uart_interrupt, IRQF_SHARED,
1322 priv->irq_name, priv);
1323 if (ret < 0)
1324 return ret;
1325
1326 if (priv->use_dma)
1327 pch_request_dma(port);
1328
1329 priv->start_rx = 1;
1330 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT |
1331 PCH_UART_HAL_RX_ERR_INT);
1332 uart_update_timeout(port, CS8, default_baud);
1333
1334 return 0;
1335}
1336
1337static void pch_uart_shutdown(struct uart_port *port)
1338{
1339 struct eg20t_port *priv;
1340 int ret;
1341
1342 priv = container_of(port, struct eg20t_port, port);
1343 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1344 pch_uart_hal_fifo_reset(priv, PCH_UART_HAL_CLR_ALL_FIFO);
1345 ret = pch_uart_hal_set_fifo(priv, PCH_UART_HAL_DMA_MODE0,
1346 PCH_UART_HAL_FIFO_DIS, PCH_UART_HAL_TRIGGER1);
1347 if (ret)
1348 dev_err(priv->port.dev,
1349 "pch_uart_hal_set_fifo Failed(ret=%d)\n", ret);
1350
1351 pch_free_dma(port);
1352
1353 free_irq(priv->port.irq, priv);
1354}
1355
1356/* Change the port parameters, including word length, parity, stop
1357 *bits. Update read_status_mask and ignore_status_mask to indicate
1358 *the types of events we are interested in receiving. */
1359static void pch_uart_set_termios(struct uart_port *port,
1360 struct ktermios *termios, struct ktermios *old)
1361{
1362 int rtn;
1363 unsigned int baud, parity, bits, stb;
1364 struct eg20t_port *priv;
1365 unsigned long flags;
1366
1367 priv = container_of(port, struct eg20t_port, port);
1368 switch (termios->c_cflag & CSIZE) {
1369 case CS5:
1370 bits = PCH_UART_HAL_5BIT;
1371 break;
1372 case CS6:
1373 bits = PCH_UART_HAL_6BIT;
1374 break;
1375 case CS7:
1376 bits = PCH_UART_HAL_7BIT;
1377 break;
1378 default: /* CS8 */
1379 bits = PCH_UART_HAL_8BIT;
1380 break;
1381 }
1382 if (termios->c_cflag & CSTOPB)
1383 stb = PCH_UART_HAL_STB2;
1384 else
1385 stb = PCH_UART_HAL_STB1;
1386
1387 if (termios->c_cflag & PARENB) {
1388 if (termios->c_cflag & PARODD)
1389 parity = PCH_UART_HAL_PARITY_ODD;
1390 else
1391 parity = PCH_UART_HAL_PARITY_EVEN;
1392
1393 } else
1394 parity = PCH_UART_HAL_PARITY_NONE;
1395
1396 /* Only UART0 has auto hardware flow function */
1397 if ((termios->c_cflag & CRTSCTS) && (priv->fifo_size == 256))
1398 priv->mcr |= UART_MCR_AFE;
1399 else
1400 priv->mcr &= ~UART_MCR_AFE;
1401
1402 termios->c_cflag &= ~CMSPAR; /* Mark/Space parity is not supported */
1403
1404 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
1405
1406 spin_lock_irqsave(&priv->lock, flags);
1407 spin_lock(&port->lock);
1408
1409 uart_update_timeout(port, termios->c_cflag, baud);
1410 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb);
1411 if (rtn)
1412 goto out;
1413
1414 pch_uart_set_mctrl(&priv->port, priv->port.mctrl);
1415 /* Don't rewrite B0 */
1416 if (tty_termios_baud_rate(termios))
1417 tty_termios_encode_baud_rate(termios, baud, baud);
1418
1419out:
1420 spin_unlock(&port->lock);
1421 spin_unlock_irqrestore(&priv->lock, flags);
1422}
1423
1424static const char *pch_uart_type(struct uart_port *port)
1425{
1426 return KBUILD_MODNAME;
1427}
1428
1429static void pch_uart_release_port(struct uart_port *port)
1430{
1431 struct eg20t_port *priv;
1432
1433 priv = container_of(port, struct eg20t_port, port);
1434 pci_iounmap(priv->pdev, priv->membase);
1435 pci_release_regions(priv->pdev);
1436}
1437
1438static int pch_uart_request_port(struct uart_port *port)
1439{
1440 struct eg20t_port *priv;
1441 int ret;
1442 void __iomem *membase;
1443
1444 priv = container_of(port, struct eg20t_port, port);
1445 ret = pci_request_regions(priv->pdev, KBUILD_MODNAME);
1446 if (ret < 0)
1447 return -EBUSY;
1448
1449 membase = pci_iomap(priv->pdev, 1, 0);
1450 if (!membase) {
1451 pci_release_regions(priv->pdev);
1452 return -EBUSY;
1453 }
1454 priv->membase = port->membase = membase;
1455
1456 return 0;
1457}
1458
1459static void pch_uart_config_port(struct uart_port *port, int type)
1460{
1461 struct eg20t_port *priv;
1462
1463 priv = container_of(port, struct eg20t_port, port);
1464 if (type & UART_CONFIG_TYPE) {
1465 port->type = priv->port_type;
1466 pch_uart_request_port(port);
1467 }
1468}
1469
1470static int pch_uart_verify_port(struct uart_port *port,
1471 struct serial_struct *serinfo)
1472{
1473 struct eg20t_port *priv;
1474
1475 priv = container_of(port, struct eg20t_port, port);
1476 if (serinfo->flags & UPF_LOW_LATENCY) {
1477 dev_info(priv->port.dev,
1478 "PCH UART : Use PIO Mode (without DMA)\n");
1479 priv->use_dma = 0;
1480 serinfo->flags &= ~UPF_LOW_LATENCY;
1481 } else {
1482#ifndef CONFIG_PCH_DMA
1483 dev_err(priv->port.dev, "%s : PCH DMA is not Loaded.\n",
1484 __func__);
1485 return -EOPNOTSUPP;
1486#endif
1487 if (!priv->use_dma) {
1488 pch_request_dma(port);
1489 if (priv->chan_rx)
1490 priv->use_dma = 1;
1491 }
1492 dev_info(priv->port.dev, "PCH UART: %s\n",
1493 priv->use_dma ?
1494 "Use DMA Mode" : "No DMA");
1495 }
1496
1497 return 0;
1498}
1499
1500#if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_PCH_UART_CONSOLE)
1501/*
1502 * Wait for transmitter & holding register to empty
1503 */
1504static void wait_for_xmitr(struct eg20t_port *up, int bits)
1505{
1506 unsigned int status, tmout = 10000;
1507
1508 /* Wait up to 10ms for the character(s) to be sent. */
1509 for (;;) {
1510 status = ioread8(up->membase + UART_LSR);
1511
1512 if ((status & bits) == bits)
1513 break;
1514 if (--tmout == 0)
1515 break;
1516 udelay(1);
1517 }
1518
1519 /* Wait up to 1s for flow control if necessary */
1520 if (up->port.flags & UPF_CONS_FLOW) {
1521 unsigned int tmout;
1522 for (tmout = 1000000; tmout; tmout--) {
1523 unsigned int msr = ioread8(up->membase + UART_MSR);
1524 if (msr & UART_MSR_CTS)
1525 break;
1526 udelay(1);
1527 touch_nmi_watchdog();
1528 }
1529 }
1530}
1531#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_PCH_UART_CONSOLE */
1532
1533#ifdef CONFIG_CONSOLE_POLL
1534/*
1535 * Console polling routines for communicate via uart while
1536 * in an interrupt or debug context.
1537 */
1538static int pch_uart_get_poll_char(struct uart_port *port)
1539{
1540 struct eg20t_port *priv =
1541 container_of(port, struct eg20t_port, port);
1542 u8 lsr = ioread8(priv->membase + UART_LSR);
1543
1544 if (!(lsr & UART_LSR_DR))
1545 return NO_POLL_CHAR;
1546
1547 return ioread8(priv->membase + PCH_UART_RBR);
1548}
1549
1550
1551static void pch_uart_put_poll_char(struct uart_port *port,
1552 unsigned char c)
1553{
1554 unsigned int ier;
1555 struct eg20t_port *priv =
1556 container_of(port, struct eg20t_port, port);
1557
1558 /*
1559 * First save the IER then disable the interrupts
1560 */
1561 ier = ioread8(priv->membase + UART_IER);
1562 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1563
1564 wait_for_xmitr(priv, UART_LSR_THRE);
1565 /*
1566 * Send the character out.
1567 */
1568 iowrite8(c, priv->membase + PCH_UART_THR);
1569
1570 /*
1571 * Finally, wait for transmitter to become empty
1572 * and restore the IER
1573 */
1574 wait_for_xmitr(priv, BOTH_EMPTY);
1575 iowrite8(ier, priv->membase + UART_IER);
1576}
1577#endif /* CONFIG_CONSOLE_POLL */
1578
1579static const struct uart_ops pch_uart_ops = {
1580 .tx_empty = pch_uart_tx_empty,
1581 .set_mctrl = pch_uart_set_mctrl,
1582 .get_mctrl = pch_uart_get_mctrl,
1583 .stop_tx = pch_uart_stop_tx,
1584 .start_tx = pch_uart_start_tx,
1585 .stop_rx = pch_uart_stop_rx,
1586 .enable_ms = pch_uart_enable_ms,
1587 .break_ctl = pch_uart_break_ctl,
1588 .startup = pch_uart_startup,
1589 .shutdown = pch_uart_shutdown,
1590 .set_termios = pch_uart_set_termios,
1591/* .pm = pch_uart_pm, Not supported yet */
1592 .type = pch_uart_type,
1593 .release_port = pch_uart_release_port,
1594 .request_port = pch_uart_request_port,
1595 .config_port = pch_uart_config_port,
1596 .verify_port = pch_uart_verify_port,
1597#ifdef CONFIG_CONSOLE_POLL
1598 .poll_get_char = pch_uart_get_poll_char,
1599 .poll_put_char = pch_uart_put_poll_char,
1600#endif
1601};
1602
1603#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1604
1605static void pch_console_putchar(struct uart_port *port, int ch)
1606{
1607 struct eg20t_port *priv =
1608 container_of(port, struct eg20t_port, port);
1609
1610 wait_for_xmitr(priv, UART_LSR_THRE);
1611 iowrite8(ch, priv->membase + PCH_UART_THR);
1612}
1613
1614/*
1615 * Print a string to the serial port trying not to disturb
1616 * any possible real use of the port...
1617 *
1618 * The console_lock must be held when we get here.
1619 */
1620static void
1621pch_console_write(struct console *co, const char *s, unsigned int count)
1622{
1623 struct eg20t_port *priv;
1624 unsigned long flags;
1625 int priv_locked = 1;
1626 int port_locked = 1;
1627 u8 ier;
1628
1629 priv = pch_uart_ports[co->index];
1630
1631 touch_nmi_watchdog();
1632
1633 local_irq_save(flags);
1634 if (priv->port.sysrq) {
1635 /* call to uart_handle_sysrq_char already took the priv lock */
1636 priv_locked = 0;
1637 /* serial8250_handle_port() already took the port lock */
1638 port_locked = 0;
1639 } else if (oops_in_progress) {
1640 priv_locked = spin_trylock(&priv->lock);
1641 port_locked = spin_trylock(&priv->port.lock);
1642 } else {
1643 spin_lock(&priv->lock);
1644 spin_lock(&priv->port.lock);
1645 }
1646
1647 /*
1648 * First save the IER then disable the interrupts
1649 */
1650 ier = ioread8(priv->membase + UART_IER);
1651
1652 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1653
1654 uart_console_write(&priv->port, s, count, pch_console_putchar);
1655
1656 /*
1657 * Finally, wait for transmitter to become empty
1658 * and restore the IER
1659 */
1660 wait_for_xmitr(priv, BOTH_EMPTY);
1661 iowrite8(ier, priv->membase + UART_IER);
1662
1663 if (port_locked)
1664 spin_unlock(&priv->port.lock);
1665 if (priv_locked)
1666 spin_unlock(&priv->lock);
1667 local_irq_restore(flags);
1668}
1669
1670static int __init pch_console_setup(struct console *co, char *options)
1671{
1672 struct uart_port *port;
1673 int baud = default_baud;
1674 int bits = 8;
1675 int parity = 'n';
1676 int flow = 'n';
1677
1678 /*
1679 * Check whether an invalid uart number has been specified, and
1680 * if so, search for the first available port that does have
1681 * console support.
1682 */
1683 if (co->index >= PCH_UART_NR)
1684 co->index = 0;
1685 port = &pch_uart_ports[co->index]->port;
1686
1687 if (!port || (!port->iobase && !port->membase))
1688 return -ENODEV;
1689
1690 port->uartclk = pch_uart_get_uartclk();
1691
1692 if (options)
1693 uart_parse_options(options, &baud, &parity, &bits, &flow);
1694
1695 return uart_set_options(port, co, baud, parity, bits, flow);
1696}
1697
1698static struct uart_driver pch_uart_driver;
1699
1700static struct console pch_console = {
1701 .name = PCH_UART_DRIVER_DEVICE,
1702 .write = pch_console_write,
1703 .device = uart_console_device,
1704 .setup = pch_console_setup,
1705 .flags = CON_PRINTBUFFER | CON_ANYTIME,
1706 .index = -1,
1707 .data = &pch_uart_driver,
1708};
1709
1710#define PCH_CONSOLE (&pch_console)
1711#else
1712#define PCH_CONSOLE NULL
1713#endif /* CONFIG_SERIAL_PCH_UART_CONSOLE */
1714
1715static struct uart_driver pch_uart_driver = {
1716 .owner = THIS_MODULE,
1717 .driver_name = KBUILD_MODNAME,
1718 .dev_name = PCH_UART_DRIVER_DEVICE,
1719 .major = 0,
1720 .minor = 0,
1721 .nr = PCH_UART_NR,
1722 .cons = PCH_CONSOLE,
1723};
1724
1725static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
1726 const struct pci_device_id *id)
1727{
1728 struct eg20t_port *priv;
1729 int ret;
1730 unsigned int iobase;
1731 unsigned int mapbase;
1732 unsigned char *rxbuf;
1733 int fifosize;
1734 int port_type;
1735 struct pch_uart_driver_data *board;
1736#ifdef CONFIG_DEBUG_FS
1737 char name[32]; /* for debugfs file name */
1738#endif
1739
1740 board = &drv_dat[id->driver_data];
1741 port_type = board->port_type;
1742
1743 priv = kzalloc(sizeof(struct eg20t_port), GFP_KERNEL);
1744 if (priv == NULL)
1745 goto init_port_alloc_err;
1746
1747 rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
1748 if (!rxbuf)
1749 goto init_port_free_txbuf;
1750
1751 switch (port_type) {
1752 case PORT_PCH_8LINE:
1753 fifosize = 256; /* EG20T/ML7213: UART0 */
1754 break;
1755 case PORT_PCH_2LINE:
1756 fifosize = 64; /* EG20T:UART1~3 ML7213: UART1~2*/
1757 break;
1758 default:
1759 dev_err(&pdev->dev, "Invalid Port Type(=%d)\n", port_type);
1760 goto init_port_hal_free;
1761 }
1762
1763 pci_enable_msi(pdev);
1764 pci_set_master(pdev);
1765
1766 spin_lock_init(&priv->lock);
1767
1768 iobase = pci_resource_start(pdev, 0);
1769 mapbase = pci_resource_start(pdev, 1);
1770 priv->mapbase = mapbase;
1771 priv->iobase = iobase;
1772 priv->pdev = pdev;
1773 priv->tx_empty = 1;
1774 priv->rxbuf.buf = rxbuf;
1775 priv->rxbuf.size = PAGE_SIZE;
1776
1777 priv->fifo_size = fifosize;
1778 priv->uartclk = pch_uart_get_uartclk();
1779 priv->port_type = port_type;
1780 priv->port.dev = &pdev->dev;
1781 priv->port.iobase = iobase;
1782 priv->port.membase = NULL;
1783 priv->port.mapbase = mapbase;
1784 priv->port.irq = pdev->irq;
1785 priv->port.iotype = UPIO_PORT;
1786 priv->port.ops = &pch_uart_ops;
1787 priv->port.flags = UPF_BOOT_AUTOCONF;
1788 priv->port.fifosize = fifosize;
1789 priv->port.line = board->line_no;
1790 priv->trigger = PCH_UART_HAL_TRIGGER_M;
1791
1792 snprintf(priv->irq_name, IRQ_NAME_SIZE,
1793 KBUILD_MODNAME ":" PCH_UART_DRIVER_DEVICE "%d",
1794 priv->port.line);
1795
1796 spin_lock_init(&priv->port.lock);
1797
1798 pci_set_drvdata(pdev, priv);
1799 priv->trigger_level = 1;
1800 priv->fcr = 0;
1801
1802 if (pdev->dev.of_node)
1803 of_property_read_u32(pdev->dev.of_node, "clock-frequency"
1804 , &user_uartclk);
1805
1806#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1807 pch_uart_ports[board->line_no] = priv;
1808#endif
1809 ret = uart_add_one_port(&pch_uart_driver, &priv->port);
1810 if (ret < 0)
1811 goto init_port_hal_free;
1812
1813#ifdef CONFIG_DEBUG_FS
1814 snprintf(name, sizeof(name), "uart%d_regs", board->line_no);
1815 priv->debugfs = debugfs_create_file(name, S_IFREG | S_IRUGO,
1816 NULL, priv, &port_regs_ops);
1817#endif
1818
1819 return priv;
1820
1821init_port_hal_free:
1822#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1823 pch_uart_ports[board->line_no] = NULL;
1824#endif
1825 free_page((unsigned long)rxbuf);
1826init_port_free_txbuf:
1827 kfree(priv);
1828init_port_alloc_err:
1829
1830 return NULL;
1831}
1832
1833static void pch_uart_exit_port(struct eg20t_port *priv)
1834{
1835
1836#ifdef CONFIG_DEBUG_FS
1837 debugfs_remove(priv->debugfs);
1838#endif
1839 uart_remove_one_port(&pch_uart_driver, &priv->port);
1840 free_page((unsigned long)priv->rxbuf.buf);
1841}
1842
1843static void pch_uart_pci_remove(struct pci_dev *pdev)
1844{
1845 struct eg20t_port *priv = pci_get_drvdata(pdev);
1846
1847 pci_disable_msi(pdev);
1848
1849#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1850 pch_uart_ports[priv->port.line] = NULL;
1851#endif
1852 pch_uart_exit_port(priv);
1853 pci_disable_device(pdev);
1854 kfree(priv);
1855 return;
1856}
1857#ifdef CONFIG_PM
1858static int pch_uart_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1859{
1860 struct eg20t_port *priv = pci_get_drvdata(pdev);
1861
1862 uart_suspend_port(&pch_uart_driver, &priv->port);
1863
1864 pci_save_state(pdev);
1865 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1866 return 0;
1867}
1868
1869static int pch_uart_pci_resume(struct pci_dev *pdev)
1870{
1871 struct eg20t_port *priv = pci_get_drvdata(pdev);
1872 int ret;
1873
1874 pci_set_power_state(pdev, PCI_D0);
1875 pci_restore_state(pdev);
1876
1877 ret = pci_enable_device(pdev);
1878 if (ret) {
1879 dev_err(&pdev->dev,
1880 "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
1881 return ret;
1882 }
1883
1884 uart_resume_port(&pch_uart_driver, &priv->port);
1885
1886 return 0;
1887}
1888#else
1889#define pch_uart_pci_suspend NULL
1890#define pch_uart_pci_resume NULL
1891#endif
1892
1893static const struct pci_device_id pch_uart_pci_id[] = {
1894 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8811),
1895 .driver_data = pch_et20t_uart0},
1896 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8812),
1897 .driver_data = pch_et20t_uart1},
1898 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8813),
1899 .driver_data = pch_et20t_uart2},
1900 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x8814),
1901 .driver_data = pch_et20t_uart3},
1902 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8027),
1903 .driver_data = pch_ml7213_uart0},
1904 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8028),
1905 .driver_data = pch_ml7213_uart1},
1906 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8029),
1907 .driver_data = pch_ml7213_uart2},
1908 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800C),
1909 .driver_data = pch_ml7223_uart0},
1910 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800D),
1911 .driver_data = pch_ml7223_uart1},
1912 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8811),
1913 .driver_data = pch_ml7831_uart0},
1914 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8812),
1915 .driver_data = pch_ml7831_uart1},
1916 {0,},
1917};
1918
1919static int pch_uart_pci_probe(struct pci_dev *pdev,
1920 const struct pci_device_id *id)
1921{
1922 int ret;
1923 struct eg20t_port *priv;
1924
1925 ret = pci_enable_device(pdev);
1926 if (ret < 0)
1927 goto probe_error;
1928
1929 priv = pch_uart_init_port(pdev, id);
1930 if (!priv) {
1931 ret = -EBUSY;
1932 goto probe_disable_device;
1933 }
1934 pci_set_drvdata(pdev, priv);
1935
1936 return ret;
1937
1938probe_disable_device:
1939 pci_disable_msi(pdev);
1940 pci_disable_device(pdev);
1941probe_error:
1942 return ret;
1943}
1944
1945static struct pci_driver pch_uart_pci_driver = {
1946 .name = "pch_uart",
1947 .id_table = pch_uart_pci_id,
1948 .probe = pch_uart_pci_probe,
1949 .remove = pch_uart_pci_remove,
1950 .suspend = pch_uart_pci_suspend,
1951 .resume = pch_uart_pci_resume,
1952};
1953
1954static int __init pch_uart_module_init(void)
1955{
1956 int ret;
1957
1958 /* register as UART driver */
1959 ret = uart_register_driver(&pch_uart_driver);
1960 if (ret < 0)
1961 return ret;
1962
1963 /* register as PCI driver */
1964 ret = pci_register_driver(&pch_uart_pci_driver);
1965 if (ret < 0)
1966 uart_unregister_driver(&pch_uart_driver);
1967
1968 return ret;
1969}
1970module_init(pch_uart_module_init);
1971
1972static void __exit pch_uart_module_exit(void)
1973{
1974 pci_unregister_driver(&pch_uart_pci_driver);
1975 uart_unregister_driver(&pch_uart_driver);
1976}
1977module_exit(pch_uart_module_exit);
1978
1979MODULE_LICENSE("GPL v2");
1980MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver");
1981MODULE_DEVICE_TABLE(pci, pch_uart_pci_id);
1982
1983module_param(default_baud, uint, S_IRUGO);
1984MODULE_PARM_DESC(default_baud,
1985 "Default BAUD for initial driver state and console (default 9600)");
1986module_param(user_uartclk, uint, S_IRUGO);
1987MODULE_PARM_DESC(user_uartclk,
1988 "Override UART default or board specific UART clock");