2 *Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
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.
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.
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.
17 #include <linux/kernel.h>
18 #include <linux/serial_reg.h>
19 #include <linux/slab.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/serial_core.h>
23 #include <linux/tty.h>
24 #include <linux/tty_flip.h>
25 #include <linux/interrupt.h>
27 #include <linux/dmi.h>
28 #include <linux/console.h>
29 #include <linux/nmi.h>
30 #include <linux/delay.h>
32 #include <linux/dmaengine.h>
33 #include <linux/pch_dma.h>
36 PCH_UART_HANDLED_RX_INT_SHIFT
,
37 PCH_UART_HANDLED_TX_INT_SHIFT
,
38 PCH_UART_HANDLED_RX_ERR_INT_SHIFT
,
39 PCH_UART_HANDLED_RX_TRG_INT_SHIFT
,
40 PCH_UART_HANDLED_MS_INT_SHIFT
,
48 #define PCH_UART_DRIVER_DEVICE "ttyPCH"
50 /* Set the max number of UART port
51 * Intel EG20T PCH: 4 port
52 * LAPIS Semiconductor ML7213 IOH: 3 port
53 * LAPIS Semiconductor ML7223 IOH: 2 port
57 #define PCH_UART_HANDLED_RX_INT (1<<((PCH_UART_HANDLED_RX_INT_SHIFT)<<1))
58 #define PCH_UART_HANDLED_TX_INT (1<<((PCH_UART_HANDLED_TX_INT_SHIFT)<<1))
59 #define PCH_UART_HANDLED_RX_ERR_INT (1<<((\
60 PCH_UART_HANDLED_RX_ERR_INT_SHIFT)<<1))
61 #define PCH_UART_HANDLED_RX_TRG_INT (1<<((\
62 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1))
63 #define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1))
65 #define PCH_UART_RBR 0x00
66 #define PCH_UART_THR 0x00
68 #define PCH_UART_IER_MASK (PCH_UART_IER_ERBFI|PCH_UART_IER_ETBEI|\
69 PCH_UART_IER_ELSI|PCH_UART_IER_EDSSI)
70 #define PCH_UART_IER_ERBFI 0x00000001
71 #define PCH_UART_IER_ETBEI 0x00000002
72 #define PCH_UART_IER_ELSI 0x00000004
73 #define PCH_UART_IER_EDSSI 0x00000008
75 #define PCH_UART_IIR_IP 0x00000001
76 #define PCH_UART_IIR_IID 0x00000006
77 #define PCH_UART_IIR_MSI 0x00000000
78 #define PCH_UART_IIR_TRI 0x00000002
79 #define PCH_UART_IIR_RRI 0x00000004
80 #define PCH_UART_IIR_REI 0x00000006
81 #define PCH_UART_IIR_TOI 0x00000008
82 #define PCH_UART_IIR_FIFO256 0x00000020
83 #define PCH_UART_IIR_FIFO64 PCH_UART_IIR_FIFO256
84 #define PCH_UART_IIR_FE 0x000000C0
86 #define PCH_UART_FCR_FIFOE 0x00000001
87 #define PCH_UART_FCR_RFR 0x00000002
88 #define PCH_UART_FCR_TFR 0x00000004
89 #define PCH_UART_FCR_DMS 0x00000008
90 #define PCH_UART_FCR_FIFO256 0x00000020
91 #define PCH_UART_FCR_RFTL 0x000000C0
93 #define PCH_UART_FCR_RFTL1 0x00000000
94 #define PCH_UART_FCR_RFTL64 0x00000040
95 #define PCH_UART_FCR_RFTL128 0x00000080
96 #define PCH_UART_FCR_RFTL224 0x000000C0
97 #define PCH_UART_FCR_RFTL16 PCH_UART_FCR_RFTL64
98 #define PCH_UART_FCR_RFTL32 PCH_UART_FCR_RFTL128
99 #define PCH_UART_FCR_RFTL56 PCH_UART_FCR_RFTL224
100 #define PCH_UART_FCR_RFTL4 PCH_UART_FCR_RFTL64
101 #define PCH_UART_FCR_RFTL8 PCH_UART_FCR_RFTL128
102 #define PCH_UART_FCR_RFTL14 PCH_UART_FCR_RFTL224
103 #define PCH_UART_FCR_RFTL_SHIFT 6
105 #define PCH_UART_LCR_WLS 0x00000003
106 #define PCH_UART_LCR_STB 0x00000004
107 #define PCH_UART_LCR_PEN 0x00000008
108 #define PCH_UART_LCR_EPS 0x00000010
109 #define PCH_UART_LCR_SP 0x00000020
110 #define PCH_UART_LCR_SB 0x00000040
111 #define PCH_UART_LCR_DLAB 0x00000080
112 #define PCH_UART_LCR_NP 0x00000000
113 #define PCH_UART_LCR_OP PCH_UART_LCR_PEN
114 #define PCH_UART_LCR_EP (PCH_UART_LCR_PEN | PCH_UART_LCR_EPS)
115 #define PCH_UART_LCR_1P (PCH_UART_LCR_PEN | PCH_UART_LCR_SP)
116 #define PCH_UART_LCR_0P (PCH_UART_LCR_PEN | PCH_UART_LCR_EPS |\
119 #define PCH_UART_LCR_5BIT 0x00000000
120 #define PCH_UART_LCR_6BIT 0x00000001
121 #define PCH_UART_LCR_7BIT 0x00000002
122 #define PCH_UART_LCR_8BIT 0x00000003
124 #define PCH_UART_MCR_DTR 0x00000001
125 #define PCH_UART_MCR_RTS 0x00000002
126 #define PCH_UART_MCR_OUT 0x0000000C
127 #define PCH_UART_MCR_LOOP 0x00000010
128 #define PCH_UART_MCR_AFE 0x00000020
130 #define PCH_UART_LSR_DR 0x00000001
131 #define PCH_UART_LSR_ERR (1<<7)
133 #define PCH_UART_MSR_DCTS 0x00000001
134 #define PCH_UART_MSR_DDSR 0x00000002
135 #define PCH_UART_MSR_TERI 0x00000004
136 #define PCH_UART_MSR_DDCD 0x00000008
137 #define PCH_UART_MSR_CTS 0x00000010
138 #define PCH_UART_MSR_DSR 0x00000020
139 #define PCH_UART_MSR_RI 0x00000040
140 #define PCH_UART_MSR_DCD 0x00000080
141 #define PCH_UART_MSR_DELTA (PCH_UART_MSR_DCTS | PCH_UART_MSR_DDSR |\
142 PCH_UART_MSR_TERI | PCH_UART_MSR_DDCD)
144 #define PCH_UART_DLL 0x00
145 #define PCH_UART_DLM 0x01
147 #define PCH_UART_IID_RLS (PCH_UART_IIR_REI)
148 #define PCH_UART_IID_RDR (PCH_UART_IIR_RRI)
149 #define PCH_UART_IID_RDR_TO (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI)
150 #define PCH_UART_IID_THRE (PCH_UART_IIR_TRI)
151 #define PCH_UART_IID_MS (PCH_UART_IIR_MSI)
153 #define PCH_UART_HAL_PARITY_NONE (PCH_UART_LCR_NP)
154 #define PCH_UART_HAL_PARITY_ODD (PCH_UART_LCR_OP)
155 #define PCH_UART_HAL_PARITY_EVEN (PCH_UART_LCR_EP)
156 #define PCH_UART_HAL_PARITY_FIX1 (PCH_UART_LCR_1P)
157 #define PCH_UART_HAL_PARITY_FIX0 (PCH_UART_LCR_0P)
158 #define PCH_UART_HAL_5BIT (PCH_UART_LCR_5BIT)
159 #define PCH_UART_HAL_6BIT (PCH_UART_LCR_6BIT)
160 #define PCH_UART_HAL_7BIT (PCH_UART_LCR_7BIT)
161 #define PCH_UART_HAL_8BIT (PCH_UART_LCR_8BIT)
162 #define PCH_UART_HAL_STB1 0
163 #define PCH_UART_HAL_STB2 (PCH_UART_LCR_STB)
165 #define PCH_UART_HAL_CLR_TX_FIFO (PCH_UART_FCR_TFR)
166 #define PCH_UART_HAL_CLR_RX_FIFO (PCH_UART_FCR_RFR)
167 #define PCH_UART_HAL_CLR_ALL_FIFO (PCH_UART_HAL_CLR_TX_FIFO | \
168 PCH_UART_HAL_CLR_RX_FIFO)
170 #define PCH_UART_HAL_DMA_MODE0 0
171 #define PCH_UART_HAL_FIFO_DIS 0
172 #define PCH_UART_HAL_FIFO16 (PCH_UART_FCR_FIFOE)
173 #define PCH_UART_HAL_FIFO256 (PCH_UART_FCR_FIFOE | \
174 PCH_UART_FCR_FIFO256)
175 #define PCH_UART_HAL_FIFO64 (PCH_UART_HAL_FIFO256)
176 #define PCH_UART_HAL_TRIGGER1 (PCH_UART_FCR_RFTL1)
177 #define PCH_UART_HAL_TRIGGER64 (PCH_UART_FCR_RFTL64)
178 #define PCH_UART_HAL_TRIGGER128 (PCH_UART_FCR_RFTL128)
179 #define PCH_UART_HAL_TRIGGER224 (PCH_UART_FCR_RFTL224)
180 #define PCH_UART_HAL_TRIGGER16 (PCH_UART_FCR_RFTL16)
181 #define PCH_UART_HAL_TRIGGER32 (PCH_UART_FCR_RFTL32)
182 #define PCH_UART_HAL_TRIGGER56 (PCH_UART_FCR_RFTL56)
183 #define PCH_UART_HAL_TRIGGER4 (PCH_UART_FCR_RFTL4)
184 #define PCH_UART_HAL_TRIGGER8 (PCH_UART_FCR_RFTL8)
185 #define PCH_UART_HAL_TRIGGER14 (PCH_UART_FCR_RFTL14)
186 #define PCH_UART_HAL_TRIGGER_L (PCH_UART_FCR_RFTL64)
187 #define PCH_UART_HAL_TRIGGER_M (PCH_UART_FCR_RFTL128)
188 #define PCH_UART_HAL_TRIGGER_H (PCH_UART_FCR_RFTL224)
190 #define PCH_UART_HAL_RX_INT (PCH_UART_IER_ERBFI)
191 #define PCH_UART_HAL_TX_INT (PCH_UART_IER_ETBEI)
192 #define PCH_UART_HAL_RX_ERR_INT (PCH_UART_IER_ELSI)
193 #define PCH_UART_HAL_MS_INT (PCH_UART_IER_EDSSI)
194 #define PCH_UART_HAL_ALL_INT (PCH_UART_IER_MASK)
196 #define PCH_UART_HAL_DTR (PCH_UART_MCR_DTR)
197 #define PCH_UART_HAL_RTS (PCH_UART_MCR_RTS)
198 #define PCH_UART_HAL_OUT (PCH_UART_MCR_OUT)
199 #define PCH_UART_HAL_LOOP (PCH_UART_MCR_LOOP)
200 #define PCH_UART_HAL_AFE (PCH_UART_MCR_AFE)
202 #define PCI_VENDOR_ID_ROHM 0x10DB
204 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
206 #define DEFAULT_BAUD_RATE 1843200 /* 1.8432MHz */
208 struct pch_uart_buffer
{
214 struct uart_port port
;
216 void __iomem
*membase
;
217 resource_size_t mapbase
;
219 struct pci_dev
*pdev
;
228 struct pch_uart_buffer rxbuf
;
232 unsigned int use_dma
;
233 unsigned int use_dma_flag
;
234 struct dma_async_tx_descriptor
*desc_tx
;
235 struct dma_async_tx_descriptor
*desc_rx
;
236 struct pch_dma_slave param_tx
;
237 struct pch_dma_slave param_rx
;
238 struct dma_chan
*chan_tx
;
239 struct dma_chan
*chan_rx
;
240 struct scatterlist
*sg_tx_p
;
242 struct scatterlist sg_rx
;
245 dma_addr_t rx_buf_dma
;
249 * struct pch_uart_driver_data - private data structure for UART-DMA
250 * @port_type: The number of DMA channel
251 * @line_no: UART port line number (0, 1, 2...)
253 struct pch_uart_driver_data
{
258 enum pch_uart_num_t
{
272 static struct pch_uart_driver_data drv_dat
[] = {
273 [pch_et20t_uart0
] = {PCH_UART_8LINE
, 0},
274 [pch_et20t_uart1
] = {PCH_UART_2LINE
, 1},
275 [pch_et20t_uart2
] = {PCH_UART_2LINE
, 2},
276 [pch_et20t_uart3
] = {PCH_UART_2LINE
, 3},
277 [pch_ml7213_uart0
] = {PCH_UART_8LINE
, 0},
278 [pch_ml7213_uart1
] = {PCH_UART_2LINE
, 1},
279 [pch_ml7213_uart2
] = {PCH_UART_2LINE
, 2},
280 [pch_ml7223_uart0
] = {PCH_UART_8LINE
, 0},
281 [pch_ml7223_uart1
] = {PCH_UART_2LINE
, 1},
282 [pch_ml7831_uart0
] = {PCH_UART_8LINE
, 0},
283 [pch_ml7831_uart1
] = {PCH_UART_2LINE
, 1},
286 #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
287 static struct eg20t_port
*pch_uart_ports
[PCH_UART_NR
];
289 static unsigned int default_baud
= 9600;
290 static const int trigger_level_256
[4] = { 1, 64, 128, 224 };
291 static const int trigger_level_64
[4] = { 1, 16, 32, 56 };
292 static const int trigger_level_16
[4] = { 1, 4, 8, 14 };
293 static const int trigger_level_1
[4] = { 1, 1, 1, 1 };
295 static void pch_uart_hal_request(struct pci_dev
*pdev
, int fifosize
,
298 struct eg20t_port
*priv
= pci_get_drvdata(pdev
);
300 priv
->trigger_level
= 1;
304 static unsigned int get_msr(struct eg20t_port
*priv
, void __iomem
*base
)
306 unsigned int msr
= ioread8(base
+ UART_MSR
);
307 priv
->dmsr
|= msr
& PCH_UART_MSR_DELTA
;
312 static void pch_uart_hal_enable_interrupt(struct eg20t_port
*priv
,
315 u8 ier
= ioread8(priv
->membase
+ UART_IER
);
316 ier
|= flag
& PCH_UART_IER_MASK
;
317 iowrite8(ier
, priv
->membase
+ UART_IER
);
320 static void pch_uart_hal_disable_interrupt(struct eg20t_port
*priv
,
323 u8 ier
= ioread8(priv
->membase
+ UART_IER
);
324 ier
&= ~(flag
& PCH_UART_IER_MASK
);
325 iowrite8(ier
, priv
->membase
+ UART_IER
);
328 static int pch_uart_hal_set_line(struct eg20t_port
*priv
, int baud
,
329 unsigned int parity
, unsigned int bits
,
332 unsigned int dll
, dlm
, lcr
;
335 div
= DIV_ROUND_CLOSEST(priv
->base_baud
/ 16, baud
);
336 if (div
< 0 || USHRT_MAX
<= div
) {
337 dev_err(priv
->port
.dev
, "Invalid Baud(div=0x%x)\n", div
);
341 dll
= (unsigned int)div
& 0x00FFU
;
342 dlm
= ((unsigned int)div
>> 8) & 0x00FFU
;
344 if (parity
& ~(PCH_UART_LCR_PEN
| PCH_UART_LCR_EPS
| PCH_UART_LCR_SP
)) {
345 dev_err(priv
->port
.dev
, "Invalid parity(0x%x)\n", parity
);
349 if (bits
& ~PCH_UART_LCR_WLS
) {
350 dev_err(priv
->port
.dev
, "Invalid bits(0x%x)\n", bits
);
354 if (stb
& ~PCH_UART_LCR_STB
) {
355 dev_err(priv
->port
.dev
, "Invalid STB(0x%x)\n", stb
);
363 dev_dbg(priv
->port
.dev
, "%s:baud = %d, div = %04x, lcr = %02x (%lu)\n",
364 __func__
, baud
, div
, lcr
, jiffies
);
365 iowrite8(PCH_UART_LCR_DLAB
, priv
->membase
+ UART_LCR
);
366 iowrite8(dll
, priv
->membase
+ PCH_UART_DLL
);
367 iowrite8(dlm
, priv
->membase
+ PCH_UART_DLM
);
368 iowrite8(lcr
, priv
->membase
+ UART_LCR
);
373 static int pch_uart_hal_fifo_reset(struct eg20t_port
*priv
,
376 if (flag
& ~(PCH_UART_FCR_TFR
| PCH_UART_FCR_RFR
)) {
377 dev_err(priv
->port
.dev
, "%s:Invalid flag(0x%x)\n",
382 iowrite8(PCH_UART_FCR_FIFOE
| priv
->fcr
, priv
->membase
+ UART_FCR
);
383 iowrite8(PCH_UART_FCR_FIFOE
| priv
->fcr
| flag
,
384 priv
->membase
+ UART_FCR
);
385 iowrite8(priv
->fcr
, priv
->membase
+ UART_FCR
);
390 static int pch_uart_hal_set_fifo(struct eg20t_port
*priv
,
391 unsigned int dmamode
,
392 unsigned int fifo_size
, unsigned int trigger
)
396 if (dmamode
& ~PCH_UART_FCR_DMS
) {
397 dev_err(priv
->port
.dev
, "%s:Invalid DMA Mode(0x%x)\n",
402 if (fifo_size
& ~(PCH_UART_FCR_FIFOE
| PCH_UART_FCR_FIFO256
)) {
403 dev_err(priv
->port
.dev
, "%s:Invalid FIFO SIZE(0x%x)\n",
404 __func__
, fifo_size
);
408 if (trigger
& ~PCH_UART_FCR_RFTL
) {
409 dev_err(priv
->port
.dev
, "%s:Invalid TRIGGER(0x%x)\n",
414 switch (priv
->fifo_size
) {
416 priv
->trigger_level
=
417 trigger_level_256
[trigger
>> PCH_UART_FCR_RFTL_SHIFT
];
420 priv
->trigger_level
=
421 trigger_level_64
[trigger
>> PCH_UART_FCR_RFTL_SHIFT
];
424 priv
->trigger_level
=
425 trigger_level_16
[trigger
>> PCH_UART_FCR_RFTL_SHIFT
];
428 priv
->trigger_level
=
429 trigger_level_1
[trigger
>> PCH_UART_FCR_RFTL_SHIFT
];
433 dmamode
| fifo_size
| trigger
| PCH_UART_FCR_RFR
| PCH_UART_FCR_TFR
;
434 iowrite8(PCH_UART_FCR_FIFOE
, priv
->membase
+ UART_FCR
);
435 iowrite8(PCH_UART_FCR_FIFOE
| PCH_UART_FCR_RFR
| PCH_UART_FCR_TFR
,
436 priv
->membase
+ UART_FCR
);
437 iowrite8(fcr
, priv
->membase
+ UART_FCR
);
443 static u8
pch_uart_hal_get_modem(struct eg20t_port
*priv
)
446 return get_msr(priv
, priv
->membase
);
449 static void pch_uart_hal_write(struct eg20t_port
*priv
,
450 const unsigned char *buf
, int tx_size
)
455 for (i
= 0; i
< tx_size
;) {
457 iowrite8(thr
, priv
->membase
+ PCH_UART_THR
);
461 static int pch_uart_hal_read(struct eg20t_port
*priv
, unsigned char *buf
,
467 lsr
= ioread8(priv
->membase
+ UART_LSR
);
468 for (i
= 0, lsr
= ioread8(priv
->membase
+ UART_LSR
);
469 i
< rx_size
&& lsr
& UART_LSR_DR
;
470 lsr
= ioread8(priv
->membase
+ UART_LSR
)) {
471 rbr
= ioread8(priv
->membase
+ PCH_UART_RBR
);
477 static unsigned int pch_uart_hal_get_iid(struct eg20t_port
*priv
)
482 iir
= ioread8(priv
->membase
+ UART_IIR
);
483 ret
= (iir
& (PCH_UART_IIR_IID
| PCH_UART_IIR_TOI
| PCH_UART_IIR_IP
));
487 static u8
pch_uart_hal_get_line_status(struct eg20t_port
*priv
)
489 return ioread8(priv
->membase
+ UART_LSR
);
492 static void pch_uart_hal_set_break(struct eg20t_port
*priv
, int on
)
496 lcr
= ioread8(priv
->membase
+ UART_LCR
);
498 lcr
|= PCH_UART_LCR_SB
;
500 lcr
&= ~PCH_UART_LCR_SB
;
502 iowrite8(lcr
, priv
->membase
+ UART_LCR
);
505 static int push_rx(struct eg20t_port
*priv
, const unsigned char *buf
,
508 struct uart_port
*port
;
509 struct tty_struct
*tty
;
512 tty
= tty_port_tty_get(&port
->state
->port
);
514 dev_dbg(priv
->port
.dev
, "%s:tty is busy now", __func__
);
518 tty_insert_flip_string(tty
, buf
, size
);
519 tty_flip_buffer_push(tty
);
525 static int pop_tx_x(struct eg20t_port
*priv
, unsigned char *buf
)
528 struct uart_port
*port
= &priv
->port
;
531 dev_dbg(priv
->port
.dev
, "%s:X character send %02x (%lu)\n",
532 __func__
, port
->x_char
, jiffies
);
533 buf
[0] = port
->x_char
;
543 static int dma_push_rx(struct eg20t_port
*priv
, int size
)
545 struct tty_struct
*tty
;
547 struct uart_port
*port
= &priv
->port
;
550 tty
= tty_port_tty_get(&port
->state
->port
);
552 dev_dbg(priv
->port
.dev
, "%s:tty is busy now", __func__
);
556 room
= tty_buffer_request_room(tty
, size
);
559 dev_warn(port
->dev
, "Rx overrun: dropping %u bytes\n",
564 tty_insert_flip_string(tty
, sg_virt(&priv
->sg_rx
), size
);
566 port
->icount
.rx
+= room
;
572 static void pch_free_dma(struct uart_port
*port
)
574 struct eg20t_port
*priv
;
575 priv
= container_of(port
, struct eg20t_port
, port
);
578 dma_release_channel(priv
->chan_tx
);
579 priv
->chan_tx
= NULL
;
582 dma_release_channel(priv
->chan_rx
);
583 priv
->chan_rx
= NULL
;
585 if (sg_dma_address(&priv
->sg_rx
))
586 dma_free_coherent(port
->dev
, port
->fifosize
,
587 sg_virt(&priv
->sg_rx
),
588 sg_dma_address(&priv
->sg_rx
));
593 static bool filter(struct dma_chan
*chan
, void *slave
)
595 struct pch_dma_slave
*param
= slave
;
597 if ((chan
->chan_id
== param
->chan_id
) && (param
->dma_dev
==
598 chan
->device
->dev
)) {
599 chan
->private = param
;
606 static void pch_request_dma(struct uart_port
*port
)
609 struct dma_chan
*chan
;
610 struct pci_dev
*dma_dev
;
611 struct pch_dma_slave
*param
;
612 struct eg20t_port
*priv
=
613 container_of(port
, struct eg20t_port
, port
);
615 dma_cap_set(DMA_SLAVE
, mask
);
617 dma_dev
= pci_get_bus_and_slot(priv
->pdev
->bus
->number
,
618 PCI_DEVFN(0xa, 0)); /* Get DMA's dev
621 param
= &priv
->param_tx
;
622 param
->dma_dev
= &dma_dev
->dev
;
623 param
->chan_id
= priv
->port
.line
* 2; /* Tx = 0, 2, 4, ... */
625 param
->tx_reg
= port
->mapbase
+ UART_TX
;
626 chan
= dma_request_channel(mask
, filter
, param
);
628 dev_err(priv
->port
.dev
, "%s:dma_request_channel FAILS(Tx)\n",
632 priv
->chan_tx
= chan
;
635 param
= &priv
->param_rx
;
636 param
->dma_dev
= &dma_dev
->dev
;
637 param
->chan_id
= priv
->port
.line
* 2 + 1; /* Rx = Tx + 1 */
639 param
->rx_reg
= port
->mapbase
+ UART_RX
;
640 chan
= dma_request_channel(mask
, filter
, param
);
642 dev_err(priv
->port
.dev
, "%s:dma_request_channel FAILS(Rx)\n",
644 dma_release_channel(priv
->chan_tx
);
645 priv
->chan_tx
= NULL
;
649 /* Get Consistent memory for DMA */
650 priv
->rx_buf_virt
= dma_alloc_coherent(port
->dev
, port
->fifosize
,
651 &priv
->rx_buf_dma
, GFP_KERNEL
);
652 priv
->chan_rx
= chan
;
655 static void pch_dma_rx_complete(void *arg
)
657 struct eg20t_port
*priv
= arg
;
658 struct uart_port
*port
= &priv
->port
;
659 struct tty_struct
*tty
= tty_port_tty_get(&port
->state
->port
);
663 dev_dbg(priv
->port
.dev
, "%s:tty is busy now", __func__
);
667 dma_sync_sg_for_cpu(port
->dev
, &priv
->sg_rx
, 1, DMA_FROM_DEVICE
);
668 count
= dma_push_rx(priv
, priv
->trigger_level
);
670 tty_flip_buffer_push(tty
);
672 async_tx_ack(priv
->desc_rx
);
673 pch_uart_hal_enable_interrupt(priv
, PCH_UART_HAL_RX_INT
);
676 static void pch_dma_tx_complete(void *arg
)
678 struct eg20t_port
*priv
= arg
;
679 struct uart_port
*port
= &priv
->port
;
680 struct circ_buf
*xmit
= &port
->state
->xmit
;
681 struct scatterlist
*sg
= priv
->sg_tx_p
;
684 for (i
= 0; i
< priv
->nent
; i
++, sg
++) {
685 xmit
->tail
+= sg_dma_len(sg
);
686 port
->icount
.tx
+= sg_dma_len(sg
);
688 xmit
->tail
&= UART_XMIT_SIZE
- 1;
689 async_tx_ack(priv
->desc_tx
);
690 dma_unmap_sg(port
->dev
, sg
, priv
->nent
, DMA_TO_DEVICE
);
691 priv
->tx_dma_use
= 0;
693 kfree(priv
->sg_tx_p
);
694 pch_uart_hal_enable_interrupt(priv
, PCH_UART_HAL_TX_INT
);
697 static int pop_tx(struct eg20t_port
*priv
, int size
)
700 struct uart_port
*port
= &priv
->port
;
701 struct circ_buf
*xmit
= &port
->state
->xmit
;
703 if (uart_tx_stopped(port
) || uart_circ_empty(xmit
) || count
>= size
)
708 CIRC_CNT_TO_END(xmit
->head
, xmit
->tail
, UART_XMIT_SIZE
);
709 int sz
= min(size
- count
, cnt_to_end
);
710 pch_uart_hal_write(priv
, &xmit
->buf
[xmit
->tail
], sz
);
711 xmit
->tail
= (xmit
->tail
+ sz
) & (UART_XMIT_SIZE
- 1);
713 } while (!uart_circ_empty(xmit
) && count
< size
);
716 dev_dbg(priv
->port
.dev
, "%d characters. Remained %d characters.(%lu)\n",
717 count
, size
- count
, jiffies
);
722 static int handle_rx_to(struct eg20t_port
*priv
)
724 struct pch_uart_buffer
*buf
;
727 if (!priv
->start_rx
) {
728 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_RX_INT
);
733 rx_size
= pch_uart_hal_read(priv
, buf
->buf
, buf
->size
);
734 ret
= push_rx(priv
, buf
->buf
, rx_size
);
737 } while (rx_size
== buf
->size
);
739 return PCH_UART_HANDLED_RX_INT
;
742 static int handle_rx(struct eg20t_port
*priv
)
744 return handle_rx_to(priv
);
747 static int dma_handle_rx(struct eg20t_port
*priv
)
749 struct uart_port
*port
= &priv
->port
;
750 struct dma_async_tx_descriptor
*desc
;
751 struct scatterlist
*sg
;
753 priv
= container_of(port
, struct eg20t_port
, port
);
756 sg_init_table(&priv
->sg_rx
, 1); /* Initialize SG table */
758 sg_dma_len(sg
) = priv
->trigger_level
;
760 sg_set_page(&priv
->sg_rx
, virt_to_page(priv
->rx_buf_virt
),
761 sg_dma_len(sg
), (unsigned long)priv
->rx_buf_virt
&
764 sg_dma_address(sg
) = priv
->rx_buf_dma
;
766 desc
= priv
->chan_rx
->device
->device_prep_slave_sg(priv
->chan_rx
,
767 sg
, 1, DMA_DEV_TO_MEM
,
768 DMA_PREP_INTERRUPT
| DMA_CTRL_ACK
);
773 priv
->desc_rx
= desc
;
774 desc
->callback
= pch_dma_rx_complete
;
775 desc
->callback_param
= priv
;
776 desc
->tx_submit(desc
);
777 dma_async_issue_pending(priv
->chan_rx
);
779 return PCH_UART_HANDLED_RX_INT
;
782 static unsigned int handle_tx(struct eg20t_port
*priv
)
784 struct uart_port
*port
= &priv
->port
;
785 struct circ_buf
*xmit
= &port
->state
->xmit
;
791 if (!priv
->start_tx
) {
792 dev_info(priv
->port
.dev
, "%s:Tx isn't started. (%lu)\n",
794 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_TX_INT
);
799 fifo_size
= max(priv
->fifo_size
, 1);
801 if (pop_tx_x(priv
, xmit
->buf
)) {
802 pch_uart_hal_write(priv
, xmit
->buf
, 1);
807 size
= min(xmit
->head
- xmit
->tail
, fifo_size
);
811 tx_size
= pop_tx(priv
, size
);
813 port
->icount
.tx
+= tx_size
;
817 priv
->tx_empty
= tx_empty
;
820 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_TX_INT
);
821 uart_write_wakeup(port
);
824 return PCH_UART_HANDLED_TX_INT
;
827 static unsigned int dma_handle_tx(struct eg20t_port
*priv
)
829 struct uart_port
*port
= &priv
->port
;
830 struct circ_buf
*xmit
= &port
->state
->xmit
;
831 struct scatterlist
*sg
;
835 struct dma_async_tx_descriptor
*desc
;
842 if (!priv
->start_tx
) {
843 dev_info(priv
->port
.dev
, "%s:Tx isn't started. (%lu)\n",
845 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_TX_INT
);
850 if (priv
->tx_dma_use
) {
851 dev_dbg(priv
->port
.dev
, "%s:Tx is not completed. (%lu)\n",
853 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_TX_INT
);
858 fifo_size
= max(priv
->fifo_size
, 1);
860 if (pop_tx_x(priv
, xmit
->buf
)) {
861 pch_uart_hal_write(priv
, xmit
->buf
, 1);
867 bytes
= min((int)CIRC_CNT(xmit
->head
, xmit
->tail
,
868 UART_XMIT_SIZE
), CIRC_CNT_TO_END(xmit
->head
,
869 xmit
->tail
, UART_XMIT_SIZE
));
871 dev_dbg(priv
->port
.dev
, "%s 0 bytes return\n", __func__
);
872 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_TX_INT
);
873 uart_write_wakeup(port
);
877 if (bytes
> fifo_size
) {
878 num
= bytes
/ fifo_size
+ 1;
880 rem
= bytes
% fifo_size
;
887 dev_dbg(priv
->port
.dev
, "%s num=%d size=%d rem=%d\n",
888 __func__
, num
, size
, rem
);
890 priv
->tx_dma_use
= 1;
892 priv
->sg_tx_p
= kzalloc(sizeof(struct scatterlist
)*num
, GFP_ATOMIC
);
894 sg_init_table(priv
->sg_tx_p
, num
); /* Initialize SG table */
897 for (i
= 0; i
< num
; i
++, sg
++) {
899 sg_set_page(sg
, virt_to_page(xmit
->buf
),
902 sg_set_page(sg
, virt_to_page(xmit
->buf
),
903 size
, fifo_size
* i
);
907 nent
= dma_map_sg(port
->dev
, sg
, num
, DMA_TO_DEVICE
);
909 dev_err(priv
->port
.dev
, "%s:dma_map_sg Failed\n", __func__
);
914 for (i
= 0; i
< nent
; i
++, sg
++) {
915 sg
->offset
= (xmit
->tail
& (UART_XMIT_SIZE
- 1)) +
917 sg_dma_address(sg
) = (sg_dma_address(sg
) &
918 ~(UART_XMIT_SIZE
- 1)) + sg
->offset
;
920 sg_dma_len(sg
) = rem
;
922 sg_dma_len(sg
) = size
;
925 desc
= priv
->chan_tx
->device
->device_prep_slave_sg(priv
->chan_tx
,
926 priv
->sg_tx_p
, nent
, DMA_MEM_TO_DEV
,
927 DMA_PREP_INTERRUPT
| DMA_CTRL_ACK
);
929 dev_err(priv
->port
.dev
, "%s:device_prep_slave_sg Failed\n",
933 dma_sync_sg_for_device(port
->dev
, priv
->sg_tx_p
, nent
, DMA_TO_DEVICE
);
934 priv
->desc_tx
= desc
;
935 desc
->callback
= pch_dma_tx_complete
;
936 desc
->callback_param
= priv
;
938 desc
->tx_submit(desc
);
940 dma_async_issue_pending(priv
->chan_tx
);
942 return PCH_UART_HANDLED_TX_INT
;
945 static void pch_uart_err_ir(struct eg20t_port
*priv
, unsigned int lsr
)
947 u8 fcr
= ioread8(priv
->membase
+ UART_FCR
);
950 fcr
|= UART_FCR_CLEAR_RCVR
;
951 iowrite8(fcr
, priv
->membase
+ UART_FCR
);
953 if (lsr
& PCH_UART_LSR_ERR
)
954 dev_err(&priv
->pdev
->dev
, "Error data in FIFO\n");
956 if (lsr
& UART_LSR_FE
)
957 dev_err(&priv
->pdev
->dev
, "Framing Error\n");
959 if (lsr
& UART_LSR_PE
)
960 dev_err(&priv
->pdev
->dev
, "Parity Error\n");
962 if (lsr
& UART_LSR_OE
)
963 dev_err(&priv
->pdev
->dev
, "Overrun Error\n");
966 static irqreturn_t
pch_uart_interrupt(int irq
, void *dev_id
)
968 struct eg20t_port
*priv
= dev_id
;
969 unsigned int handled
;
975 spin_lock_irqsave(&priv
->port
.lock
, flags
);
977 while ((iid
= pch_uart_hal_get_iid(priv
)) > 1) {
979 case PCH_UART_IID_RLS
: /* Receiver Line Status */
980 lsr
= pch_uart_hal_get_line_status(priv
);
981 if (lsr
& (PCH_UART_LSR_ERR
| UART_LSR_FE
|
982 UART_LSR_PE
| UART_LSR_OE
)) {
983 pch_uart_err_ir(priv
, lsr
);
984 ret
= PCH_UART_HANDLED_RX_ERR_INT
;
987 case PCH_UART_IID_RDR
: /* Received Data Ready */
989 pch_uart_hal_disable_interrupt(priv
,
990 PCH_UART_HAL_RX_INT
);
991 ret
= dma_handle_rx(priv
);
993 pch_uart_hal_enable_interrupt(priv
,
994 PCH_UART_HAL_RX_INT
);
996 ret
= handle_rx(priv
);
999 case PCH_UART_IID_RDR_TO
: /* Received Data Ready
1001 ret
= handle_rx_to(priv
);
1003 case PCH_UART_IID_THRE
: /* Transmitter Holding Register
1006 ret
= dma_handle_tx(priv
);
1008 ret
= handle_tx(priv
);
1010 case PCH_UART_IID_MS
: /* Modem Status */
1011 ret
= PCH_UART_HANDLED_MS_INT
;
1013 default: /* Never junp to this label */
1014 dev_err(priv
->port
.dev
, "%s:iid=%d (%lu)\n", __func__
,
1019 handled
|= (unsigned int)ret
;
1021 if (handled
== 0 && iid
<= 1) {
1022 if (priv
->int_dis_flag
)
1023 priv
->int_dis_flag
= 0;
1026 spin_unlock_irqrestore(&priv
->port
.lock
, flags
);
1027 return IRQ_RETVAL(handled
);
1030 /* This function tests whether the transmitter fifo and shifter for the port
1031 described by 'port' is empty. */
1032 static unsigned int pch_uart_tx_empty(struct uart_port
*port
)
1034 struct eg20t_port
*priv
;
1036 priv
= container_of(port
, struct eg20t_port
, port
);
1045 /* Returns the current state of modem control inputs. */
1046 static unsigned int pch_uart_get_mctrl(struct uart_port
*port
)
1048 struct eg20t_port
*priv
;
1050 unsigned int ret
= 0;
1052 priv
= container_of(port
, struct eg20t_port
, port
);
1053 modem
= pch_uart_hal_get_modem(priv
);
1055 if (modem
& UART_MSR_DCD
)
1058 if (modem
& UART_MSR_RI
)
1061 if (modem
& UART_MSR_DSR
)
1064 if (modem
& UART_MSR_CTS
)
1070 static void pch_uart_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
1073 struct eg20t_port
*priv
= container_of(port
, struct eg20t_port
, port
);
1075 if (mctrl
& TIOCM_DTR
)
1076 mcr
|= UART_MCR_DTR
;
1077 if (mctrl
& TIOCM_RTS
)
1078 mcr
|= UART_MCR_RTS
;
1079 if (mctrl
& TIOCM_LOOP
)
1080 mcr
|= UART_MCR_LOOP
;
1082 if (priv
->mcr
& UART_MCR_AFE
)
1083 mcr
|= UART_MCR_AFE
;
1086 iowrite8(mcr
, priv
->membase
+ UART_MCR
);
1089 static void pch_uart_stop_tx(struct uart_port
*port
)
1091 struct eg20t_port
*priv
;
1092 priv
= container_of(port
, struct eg20t_port
, port
);
1094 priv
->tx_dma_use
= 0;
1097 static void pch_uart_start_tx(struct uart_port
*port
)
1099 struct eg20t_port
*priv
;
1101 priv
= container_of(port
, struct eg20t_port
, port
);
1103 if (priv
->use_dma
) {
1104 if (priv
->tx_dma_use
) {
1105 dev_dbg(priv
->port
.dev
, "%s : Tx DMA is NOT empty.\n",
1112 pch_uart_hal_enable_interrupt(priv
, PCH_UART_HAL_TX_INT
);
1115 static void pch_uart_stop_rx(struct uart_port
*port
)
1117 struct eg20t_port
*priv
;
1118 priv
= container_of(port
, struct eg20t_port
, port
);
1120 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_RX_INT
);
1121 priv
->int_dis_flag
= 1;
1124 /* Enable the modem status interrupts. */
1125 static void pch_uart_enable_ms(struct uart_port
*port
)
1127 struct eg20t_port
*priv
;
1128 priv
= container_of(port
, struct eg20t_port
, port
);
1129 pch_uart_hal_enable_interrupt(priv
, PCH_UART_HAL_MS_INT
);
1132 /* Control the transmission of a break signal. */
1133 static void pch_uart_break_ctl(struct uart_port
*port
, int ctl
)
1135 struct eg20t_port
*priv
;
1136 unsigned long flags
;
1138 priv
= container_of(port
, struct eg20t_port
, port
);
1139 spin_lock_irqsave(&port
->lock
, flags
);
1140 pch_uart_hal_set_break(priv
, ctl
);
1141 spin_unlock_irqrestore(&port
->lock
, flags
);
1144 /* Grab any interrupt resources and initialise any low level driver state. */
1145 static int pch_uart_startup(struct uart_port
*port
)
1147 struct eg20t_port
*priv
;
1152 priv
= container_of(port
, struct eg20t_port
, port
);
1156 priv
->base_baud
= port
->uartclk
;
1158 port
->uartclk
= priv
->base_baud
;
1160 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_ALL_INT
);
1161 ret
= pch_uart_hal_set_line(priv
, default_baud
,
1162 PCH_UART_HAL_PARITY_NONE
, PCH_UART_HAL_8BIT
,
1167 switch (priv
->fifo_size
) {
1169 fifo_size
= PCH_UART_HAL_FIFO256
;
1172 fifo_size
= PCH_UART_HAL_FIFO64
;
1175 fifo_size
= PCH_UART_HAL_FIFO16
;
1178 fifo_size
= PCH_UART_HAL_FIFO_DIS
;
1182 switch (priv
->trigger
) {
1183 case PCH_UART_HAL_TRIGGER1
:
1186 case PCH_UART_HAL_TRIGGER_L
:
1187 trigger_level
= priv
->fifo_size
/ 4;
1189 case PCH_UART_HAL_TRIGGER_M
:
1190 trigger_level
= priv
->fifo_size
/ 2;
1192 case PCH_UART_HAL_TRIGGER_H
:
1194 trigger_level
= priv
->fifo_size
- (priv
->fifo_size
/ 8);
1198 priv
->trigger_level
= trigger_level
;
1199 ret
= pch_uart_hal_set_fifo(priv
, PCH_UART_HAL_DMA_MODE0
,
1200 fifo_size
, priv
->trigger
);
1204 ret
= request_irq(priv
->port
.irq
, pch_uart_interrupt
, IRQF_SHARED
,
1205 KBUILD_MODNAME
, priv
);
1210 pch_request_dma(port
);
1213 pch_uart_hal_enable_interrupt(priv
, PCH_UART_HAL_RX_INT
);
1214 uart_update_timeout(port
, CS8
, default_baud
);
1219 static void pch_uart_shutdown(struct uart_port
*port
)
1221 struct eg20t_port
*priv
;
1224 priv
= container_of(port
, struct eg20t_port
, port
);
1225 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_ALL_INT
);
1226 pch_uart_hal_fifo_reset(priv
, PCH_UART_HAL_CLR_ALL_FIFO
);
1227 ret
= pch_uart_hal_set_fifo(priv
, PCH_UART_HAL_DMA_MODE0
,
1228 PCH_UART_HAL_FIFO_DIS
, PCH_UART_HAL_TRIGGER1
);
1230 dev_err(priv
->port
.dev
,
1231 "pch_uart_hal_set_fifo Failed(ret=%d)\n", ret
);
1235 free_irq(priv
->port
.irq
, priv
);
1238 /* Change the port parameters, including word length, parity, stop
1239 *bits. Update read_status_mask and ignore_status_mask to indicate
1240 *the types of events we are interested in receiving. */
1241 static void pch_uart_set_termios(struct uart_port
*port
,
1242 struct ktermios
*termios
, struct ktermios
*old
)
1246 unsigned int parity
, bits
, stb
;
1247 struct eg20t_port
*priv
;
1248 unsigned long flags
;
1250 priv
= container_of(port
, struct eg20t_port
, port
);
1251 switch (termios
->c_cflag
& CSIZE
) {
1253 bits
= PCH_UART_HAL_5BIT
;
1256 bits
= PCH_UART_HAL_6BIT
;
1259 bits
= PCH_UART_HAL_7BIT
;
1262 bits
= PCH_UART_HAL_8BIT
;
1265 if (termios
->c_cflag
& CSTOPB
)
1266 stb
= PCH_UART_HAL_STB2
;
1268 stb
= PCH_UART_HAL_STB1
;
1270 if (termios
->c_cflag
& PARENB
) {
1271 if (!(termios
->c_cflag
& PARODD
))
1272 parity
= PCH_UART_HAL_PARITY_ODD
;
1274 parity
= PCH_UART_HAL_PARITY_EVEN
;
1277 parity
= PCH_UART_HAL_PARITY_NONE
;
1280 /* Only UART0 has auto hardware flow function */
1281 if ((termios
->c_cflag
& CRTSCTS
) && (priv
->fifo_size
== 256))
1282 priv
->mcr
|= UART_MCR_AFE
;
1284 priv
->mcr
&= ~UART_MCR_AFE
;
1286 termios
->c_cflag
&= ~CMSPAR
; /* Mark/Space parity is not supported */
1288 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/ 16);
1290 spin_lock_irqsave(&port
->lock
, flags
);
1292 uart_update_timeout(port
, termios
->c_cflag
, baud
);
1293 rtn
= pch_uart_hal_set_line(priv
, baud
, parity
, bits
, stb
);
1297 pch_uart_set_mctrl(&priv
->port
, priv
->port
.mctrl
);
1298 /* Don't rewrite B0 */
1299 if (tty_termios_baud_rate(termios
))
1300 tty_termios_encode_baud_rate(termios
, baud
, baud
);
1303 spin_unlock_irqrestore(&port
->lock
, flags
);
1306 static const char *pch_uart_type(struct uart_port
*port
)
1308 return KBUILD_MODNAME
;
1311 static void pch_uart_release_port(struct uart_port
*port
)
1313 struct eg20t_port
*priv
;
1315 priv
= container_of(port
, struct eg20t_port
, port
);
1316 pci_iounmap(priv
->pdev
, priv
->membase
);
1317 pci_release_regions(priv
->pdev
);
1320 static int pch_uart_request_port(struct uart_port
*port
)
1322 struct eg20t_port
*priv
;
1324 void __iomem
*membase
;
1326 priv
= container_of(port
, struct eg20t_port
, port
);
1327 ret
= pci_request_regions(priv
->pdev
, KBUILD_MODNAME
);
1331 membase
= pci_iomap(priv
->pdev
, 1, 0);
1333 pci_release_regions(priv
->pdev
);
1336 priv
->membase
= port
->membase
= membase
;
1341 static void pch_uart_config_port(struct uart_port
*port
, int type
)
1343 struct eg20t_port
*priv
;
1345 priv
= container_of(port
, struct eg20t_port
, port
);
1346 if (type
& UART_CONFIG_TYPE
) {
1347 port
->type
= priv
->port_type
;
1348 pch_uart_request_port(port
);
1352 static int pch_uart_verify_port(struct uart_port
*port
,
1353 struct serial_struct
*serinfo
)
1355 struct eg20t_port
*priv
;
1357 priv
= container_of(port
, struct eg20t_port
, port
);
1358 if (serinfo
->flags
& UPF_LOW_LATENCY
) {
1359 dev_info(priv
->port
.dev
,
1360 "PCH UART : Use PIO Mode (without DMA)\n");
1362 serinfo
->flags
&= ~UPF_LOW_LATENCY
;
1364 #ifndef CONFIG_PCH_DMA
1365 dev_err(priv
->port
.dev
, "%s : PCH DMA is not Loaded.\n",
1369 priv
->use_dma_flag
= 1;
1370 dev_info(priv
->port
.dev
, "PCH UART : Use DMA Mode\n");
1372 pch_request_dma(port
);
1379 static struct uart_ops pch_uart_ops
= {
1380 .tx_empty
= pch_uart_tx_empty
,
1381 .set_mctrl
= pch_uart_set_mctrl
,
1382 .get_mctrl
= pch_uart_get_mctrl
,
1383 .stop_tx
= pch_uart_stop_tx
,
1384 .start_tx
= pch_uart_start_tx
,
1385 .stop_rx
= pch_uart_stop_rx
,
1386 .enable_ms
= pch_uart_enable_ms
,
1387 .break_ctl
= pch_uart_break_ctl
,
1388 .startup
= pch_uart_startup
,
1389 .shutdown
= pch_uart_shutdown
,
1390 .set_termios
= pch_uart_set_termios
,
1391 /* .pm = pch_uart_pm, Not supported yet */
1392 /* .set_wake = pch_uart_set_wake, Not supported yet */
1393 .type
= pch_uart_type
,
1394 .release_port
= pch_uart_release_port
,
1395 .request_port
= pch_uart_request_port
,
1396 .config_port
= pch_uart_config_port
,
1397 .verify_port
= pch_uart_verify_port
1400 #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1403 * Wait for transmitter & holding register to empty
1405 static void wait_for_xmitr(struct eg20t_port
*up
, int bits
)
1407 unsigned int status
, tmout
= 10000;
1409 /* Wait up to 10ms for the character(s) to be sent. */
1411 status
= ioread8(up
->membase
+ UART_LSR
);
1413 if ((status
& bits
) == bits
)
1420 /* Wait up to 1s for flow control if necessary */
1421 if (up
->port
.flags
& UPF_CONS_FLOW
) {
1423 for (tmout
= 1000000; tmout
; tmout
--) {
1424 unsigned int msr
= ioread8(up
->membase
+ UART_MSR
);
1425 if (msr
& UART_MSR_CTS
)
1428 touch_nmi_watchdog();
1433 static void pch_console_putchar(struct uart_port
*port
, int ch
)
1435 struct eg20t_port
*priv
=
1436 container_of(port
, struct eg20t_port
, port
);
1438 wait_for_xmitr(priv
, UART_LSR_THRE
);
1439 iowrite8(ch
, priv
->membase
+ PCH_UART_THR
);
1443 * Print a string to the serial port trying not to disturb
1444 * any possible real use of the port...
1446 * The console_lock must be held when we get here.
1449 pch_console_write(struct console
*co
, const char *s
, unsigned int count
)
1451 struct eg20t_port
*priv
;
1453 unsigned long flags
;
1457 priv
= pch_uart_ports
[co
->index
];
1459 touch_nmi_watchdog();
1461 local_irq_save(flags
);
1462 if (priv
->port
.sysrq
) {
1463 /* serial8250_handle_port() already took the lock */
1465 } else if (oops_in_progress
) {
1466 locked
= spin_trylock(&priv
->port
.lock
);
1468 spin_lock(&priv
->port
.lock
);
1471 * First save the IER then disable the interrupts
1473 ier
= ioread8(priv
->membase
+ UART_IER
);
1475 pch_uart_hal_disable_interrupt(priv
, PCH_UART_HAL_ALL_INT
);
1477 uart_console_write(&priv
->port
, s
, count
, pch_console_putchar
);
1480 * Finally, wait for transmitter to become empty
1481 * and restore the IER
1483 wait_for_xmitr(priv
, BOTH_EMPTY
);
1484 iowrite8(ier
, priv
->membase
+ UART_IER
);
1487 spin_unlock(&priv
->port
.lock
);
1488 local_irq_restore(flags
);
1491 static int __init
pch_console_setup(struct console
*co
, char *options
)
1493 struct uart_port
*port
;
1500 * Check whether an invalid uart number has been specified, and
1501 * if so, search for the first available port that does have
1504 if (co
->index
>= PCH_UART_NR
)
1506 port
= &pch_uart_ports
[co
->index
]->port
;
1508 if (!port
|| (!port
->iobase
&& !port
->membase
))
1511 /* setup uartclock */
1512 port
->uartclk
= DEFAULT_BAUD_RATE
;
1515 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1517 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
1520 static struct uart_driver pch_uart_driver
;
1522 static struct console pch_console
= {
1523 .name
= PCH_UART_DRIVER_DEVICE
,
1524 .write
= pch_console_write
,
1525 .device
= uart_console_device
,
1526 .setup
= pch_console_setup
,
1527 .flags
= CON_PRINTBUFFER
| CON_ANYTIME
,
1529 .data
= &pch_uart_driver
,
1532 #define PCH_CONSOLE (&pch_console)
1534 #define PCH_CONSOLE NULL
1537 static struct uart_driver pch_uart_driver
= {
1538 .owner
= THIS_MODULE
,
1539 .driver_name
= KBUILD_MODNAME
,
1540 .dev_name
= PCH_UART_DRIVER_DEVICE
,
1544 .cons
= PCH_CONSOLE
,
1547 static struct eg20t_port
*pch_uart_init_port(struct pci_dev
*pdev
,
1548 const struct pci_device_id
*id
)
1550 struct eg20t_port
*priv
;
1552 unsigned int iobase
;
1553 unsigned int mapbase
;
1554 unsigned char *rxbuf
;
1555 int fifosize
, base_baud
;
1557 struct pch_uart_driver_data
*board
;
1558 const char *board_name
;
1560 board
= &drv_dat
[id
->driver_data
];
1561 port_type
= board
->port_type
;
1563 priv
= kzalloc(sizeof(struct eg20t_port
), GFP_KERNEL
);
1565 goto init_port_alloc_err
;
1567 rxbuf
= (unsigned char *)__get_free_page(GFP_KERNEL
);
1569 goto init_port_free_txbuf
;
1571 base_baud
= DEFAULT_BAUD_RATE
;
1573 /* quirk for CM-iTC board */
1574 board_name
= dmi_get_system_info(DMI_BOARD_NAME
);
1575 if (board_name
&& strstr(board_name
, "CM-iTC"))
1576 base_baud
= 192000000; /* 192.0MHz */
1578 switch (port_type
) {
1580 fifosize
= 256; /* EG20T/ML7213: UART0 */
1583 fifosize
= 64; /* EG20T:UART1~3 ML7213: UART1~2*/
1586 dev_err(&pdev
->dev
, "Invalid Port Type(=%d)\n", port_type
);
1587 goto init_port_hal_free
;
1590 pci_enable_msi(pdev
);
1591 pci_set_master(pdev
);
1593 iobase
= pci_resource_start(pdev
, 0);
1594 mapbase
= pci_resource_start(pdev
, 1);
1595 priv
->mapbase
= mapbase
;
1596 priv
->iobase
= iobase
;
1599 priv
->rxbuf
.buf
= rxbuf
;
1600 priv
->rxbuf
.size
= PAGE_SIZE
;
1602 priv
->fifo_size
= fifosize
;
1603 priv
->base_baud
= base_baud
;
1604 priv
->port_type
= PORT_MAX_8250
+ port_type
+ 1;
1605 priv
->port
.dev
= &pdev
->dev
;
1606 priv
->port
.iobase
= iobase
;
1607 priv
->port
.membase
= NULL
;
1608 priv
->port
.mapbase
= mapbase
;
1609 priv
->port
.irq
= pdev
->irq
;
1610 priv
->port
.iotype
= UPIO_PORT
;
1611 priv
->port
.ops
= &pch_uart_ops
;
1612 priv
->port
.flags
= UPF_BOOT_AUTOCONF
;
1613 priv
->port
.fifosize
= fifosize
;
1614 priv
->port
.line
= board
->line_no
;
1615 priv
->trigger
= PCH_UART_HAL_TRIGGER_M
;
1617 spin_lock_init(&priv
->port
.lock
);
1619 pci_set_drvdata(pdev
, priv
);
1620 pch_uart_hal_request(pdev
, fifosize
, base_baud
);
1622 #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1623 pch_uart_ports
[board
->line_no
] = priv
;
1625 ret
= uart_add_one_port(&pch_uart_driver
, &priv
->port
);
1627 goto init_port_hal_free
;
1632 #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1633 pch_uart_ports
[board
->line_no
] = NULL
;
1635 free_page((unsigned long)rxbuf
);
1636 init_port_free_txbuf
:
1638 init_port_alloc_err
:
1643 static void pch_uart_exit_port(struct eg20t_port
*priv
)
1645 uart_remove_one_port(&pch_uart_driver
, &priv
->port
);
1646 pci_set_drvdata(priv
->pdev
, NULL
);
1647 free_page((unsigned long)priv
->rxbuf
.buf
);
1650 static void pch_uart_pci_remove(struct pci_dev
*pdev
)
1652 struct eg20t_port
*priv
;
1654 priv
= (struct eg20t_port
*)pci_get_drvdata(pdev
);
1656 pci_disable_msi(pdev
);
1658 #ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1659 pch_uart_ports
[priv
->port
.line
] = NULL
;
1661 pch_uart_exit_port(priv
);
1662 pci_disable_device(pdev
);
1667 static int pch_uart_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1669 struct eg20t_port
*priv
= pci_get_drvdata(pdev
);
1671 uart_suspend_port(&pch_uart_driver
, &priv
->port
);
1673 pci_save_state(pdev
);
1674 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
1678 static int pch_uart_pci_resume(struct pci_dev
*pdev
)
1680 struct eg20t_port
*priv
= pci_get_drvdata(pdev
);
1683 pci_set_power_state(pdev
, PCI_D0
);
1684 pci_restore_state(pdev
);
1686 ret
= pci_enable_device(pdev
);
1689 "%s-pci_enable_device failed(ret=%d) ", __func__
, ret
);
1693 uart_resume_port(&pch_uart_driver
, &priv
->port
);
1698 #define pch_uart_pci_suspend NULL
1699 #define pch_uart_pci_resume NULL
1702 static DEFINE_PCI_DEVICE_TABLE(pch_uart_pci_id
) = {
1703 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x8811),
1704 .driver_data
= pch_et20t_uart0
},
1705 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x8812),
1706 .driver_data
= pch_et20t_uart1
},
1707 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x8813),
1708 .driver_data
= pch_et20t_uart2
},
1709 {PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x8814),
1710 .driver_data
= pch_et20t_uart3
},
1711 {PCI_DEVICE(PCI_VENDOR_ID_ROHM
, 0x8027),
1712 .driver_data
= pch_ml7213_uart0
},
1713 {PCI_DEVICE(PCI_VENDOR_ID_ROHM
, 0x8028),
1714 .driver_data
= pch_ml7213_uart1
},
1715 {PCI_DEVICE(PCI_VENDOR_ID_ROHM
, 0x8029),
1716 .driver_data
= pch_ml7213_uart2
},
1717 {PCI_DEVICE(PCI_VENDOR_ID_ROHM
, 0x800C),
1718 .driver_data
= pch_ml7223_uart0
},
1719 {PCI_DEVICE(PCI_VENDOR_ID_ROHM
, 0x800D),
1720 .driver_data
= pch_ml7223_uart1
},
1721 {PCI_DEVICE(PCI_VENDOR_ID_ROHM
, 0x8811),
1722 .driver_data
= pch_ml7831_uart0
},
1723 {PCI_DEVICE(PCI_VENDOR_ID_ROHM
, 0x8812),
1724 .driver_data
= pch_ml7831_uart1
},
1728 static int __devinit
pch_uart_pci_probe(struct pci_dev
*pdev
,
1729 const struct pci_device_id
*id
)
1732 struct eg20t_port
*priv
;
1734 ret
= pci_enable_device(pdev
);
1738 priv
= pch_uart_init_port(pdev
, id
);
1741 goto probe_disable_device
;
1743 pci_set_drvdata(pdev
, priv
);
1747 probe_disable_device
:
1748 pci_disable_msi(pdev
);
1749 pci_disable_device(pdev
);
1754 static struct pci_driver pch_uart_pci_driver
= {
1756 .id_table
= pch_uart_pci_id
,
1757 .probe
= pch_uart_pci_probe
,
1758 .remove
= __devexit_p(pch_uart_pci_remove
),
1759 .suspend
= pch_uart_pci_suspend
,
1760 .resume
= pch_uart_pci_resume
,
1763 static int __init
pch_uart_module_init(void)
1767 /* register as UART driver */
1768 ret
= uart_register_driver(&pch_uart_driver
);
1772 /* register as PCI driver */
1773 ret
= pci_register_driver(&pch_uart_pci_driver
);
1775 uart_unregister_driver(&pch_uart_driver
);
1779 module_init(pch_uart_module_init
);
1781 static void __exit
pch_uart_module_exit(void)
1783 pci_unregister_driver(&pch_uart_pci_driver
);
1784 uart_unregister_driver(&pch_uart_driver
);
1786 module_exit(pch_uart_module_exit
);
1788 MODULE_LICENSE("GPL v2");
1789 MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver");
1790 module_param(default_baud
, uint
, S_IRUGO
);