xref: /linux/drivers/tty/serial/8250/8250_exar.c (revision b86ae40ffcf5a16b9569b1016da4a08c4f352ca2)
1e3b3d0f5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2d0aeaa83SSudip Mukherjee /*
3d0aeaa83SSudip Mukherjee  *  Probe module for 8250/16550-type Exar chips PCI serial ports.
4d0aeaa83SSudip Mukherjee  *
5d0aeaa83SSudip Mukherjee  *  Based on drivers/tty/serial/8250/8250_pci.c,
6d0aeaa83SSudip Mukherjee  *
7d0aeaa83SSudip Mukherjee  *  Copyright (C) 2017 Sudip Mukherjee, All Rights Reserved.
8d0aeaa83SSudip Mukherjee  */
966c736daSAndy Shevchenko #include <linux/bits.h>
1066c736daSAndy Shevchenko #include <linux/delay.h>
1166c736daSAndy Shevchenko #include <linux/device.h>
12413058dfSJan Kiszka #include <linux/dmi.h>
1366c736daSAndy Shevchenko #include <linux/interrupt.h>
14d0aeaa83SSudip Mukherjee #include <linux/io.h>
1566c736daSAndy Shevchenko #include <linux/math.h>
16d0aeaa83SSudip Mukherjee #include <linux/module.h>
17d0aeaa83SSudip Mukherjee #include <linux/pci.h>
1873f76db8SAndy Shevchenko #include <linux/platform_device.h>
1982f9cefaSAndy Shevchenko #include <linux/pm.h>
20380b1e2fSJan Kiszka #include <linux/property.h>
2166c736daSAndy Shevchenko #include <linux/string.h>
2266c736daSAndy Shevchenko #include <linux/types.h>
2366c736daSAndy Shevchenko 
2466c736daSAndy Shevchenko #include <linux/serial_8250.h>
25d0aeaa83SSudip Mukherjee #include <linux/serial_core.h>
26d0aeaa83SSudip Mukherjee #include <linux/serial_reg.h>
27d0aeaa83SSudip Mukherjee 
28d0aeaa83SSudip Mukherjee #include <asm/byteorder.h>
29d0aeaa83SSudip Mukherjee 
30d0aeaa83SSudip Mukherjee #include "8250.h"
31d813d900SAndy Shevchenko #include "8250_pcilib.h"
32d0aeaa83SSudip Mukherjee 
3324637007SAndy Shevchenko #define PCI_DEVICE_ID_ACCESSIO_COM_2S		0x1052
3424637007SAndy Shevchenko #define PCI_DEVICE_ID_ACCESSIO_COM_4S		0x105d
3524637007SAndy Shevchenko #define PCI_DEVICE_ID_ACCESSIO_COM_8S		0x106c
3624637007SAndy Shevchenko #define PCI_DEVICE_ID_ACCESSIO_COM232_8		0x10a8
3724637007SAndy Shevchenko #define PCI_DEVICE_ID_ACCESSIO_COM_2SM		0x10d2
3824637007SAndy Shevchenko #define PCI_DEVICE_ID_ACCESSIO_COM_4SM		0x10db
3924637007SAndy Shevchenko #define PCI_DEVICE_ID_ACCESSIO_COM_8SM		0x10ea
4010c5ccc3SJay Dolan 
41fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_4224PCI335	0x0002
42fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_4222PCI335	0x0004
43fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_2324PCI335	0x000a
44fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_2328PCI335	0x000b
45d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_COMMTECH_4224PCIE		0x0020
46d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_COMMTECH_4228PCIE		0x0021
47d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_COMMTECH_4222PCIE		0x0022
4895d69886SAndrew Davis 
49*b86ae40fSParker Newman #define PCI_VENDOR_ID_CONNECT_TECH				0x12c4
50*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_SP_OPTO        0x0340
51*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_SP_OPTO_A      0x0341
52*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_SP_OPTO_B      0x0342
53*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_XPRS           0x0350
54*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_XPRS_A         0x0351
55*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_XPRS_B         0x0352
56*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_XPRS           0x0353
57*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_16_XPRS_A        0x0354
58*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_16_XPRS_B        0x0355
59*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_XPRS_OPTO      0x0360
60*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_XPRS_OPTO_A    0x0361
61*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_XPRS_OPTO_B    0x0362
62*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_SP             0x0370
63*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_SP_232         0x0371
64*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_SP_485         0x0372
65*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_4_SP           0x0373
66*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_6_2_SP           0x0374
67*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_6_SP           0x0375
68*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_SP_232_NS      0x0376
69*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_XP_OPTO_LEFT   0x0380
70*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_XP_OPTO_RIGHT  0x0381
71*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_XP_OPTO        0x0382
72*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_4_XPRS_OPTO    0x0392
73*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_XPRS_LP        0x03A0
74*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_XPRS_LP_232    0x03A1
75*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_XPRS_LP_485    0x03A2
76*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_XPRS_LP_232_NS 0x03A3
77*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCIE_XEG001               0x0602
78*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCIE_XR35X_BASE           0x1000
79*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCIE_XR35X_2              0x1002
80*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCIE_XR35X_4              0x1004
81*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCIE_XR35X_8              0x1008
82*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCIE_XR35X_12             0x100C
83*b86ae40fSParker Newman #define PCI_SUBDEVICE_ID_CONNECT_TECH_PCIE_XR35X_16             0x1010
84*b86ae40fSParker Newman #define PCI_DEVICE_ID_CONNECT_TECH_PCI_XR79X_12_XIG00X          0x110c
85*b86ae40fSParker Newman #define PCI_DEVICE_ID_CONNECT_TECH_PCI_XR79X_12_XIG01X          0x110d
86*b86ae40fSParker Newman #define PCI_DEVICE_ID_CONNECT_TECH_PCI_XR79X_16                 0x1110
87*b86ae40fSParker Newman 
88d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_EXAR_XR17V4358		0x4358
89d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_EXAR_XR17V8358		0x8358
90*b86ae40fSParker Newman #define PCI_DEVICE_ID_EXAR_XR17V252		0x0252
91*b86ae40fSParker Newman #define PCI_DEVICE_ID_EXAR_XR17V254		0x0254
92*b86ae40fSParker Newman #define PCI_DEVICE_ID_EXAR_XR17V258		0x0258
93d0aeaa83SSudip Mukherjee 
9495d69886SAndrew Davis #define PCI_SUBDEVICE_ID_USR_2980		0x0128
9595d69886SAndrew Davis #define PCI_SUBDEVICE_ID_USR_2981		0x0129
9695d69886SAndrew Davis 
97c7e1b405SAaron Sierra #define UART_EXAR_INT0		0x80
987e12357eSJan Kiszka #define UART_EXAR_8XMODE	0x88	/* 8X sampling rate select */
99ef4e281eSAndy Shevchenko #define UART_EXAR_SLEEP		0x8b	/* Sleep mode */
1006be254c2SAndy Shevchenko #define UART_EXAR_DVID		0x8d	/* Device identification */
1017e12357eSJan Kiszka 
1027e12357eSJan Kiszka #define UART_EXAR_FCTR		0x08	/* Feature Control Register */
1037e12357eSJan Kiszka #define UART_FCTR_EXAR_IRDA	0x10	/* IrDa data encode select */
1047e12357eSJan Kiszka #define UART_FCTR_EXAR_485	0x20	/* Auto 485 half duplex dir ctl */
1057e12357eSJan Kiszka #define UART_FCTR_EXAR_TRGA	0x00	/* FIFO trigger table A */
1067e12357eSJan Kiszka #define UART_FCTR_EXAR_TRGB	0x60	/* FIFO trigger table B */
1077e12357eSJan Kiszka #define UART_FCTR_EXAR_TRGC	0x80	/* FIFO trigger table C */
1087e12357eSJan Kiszka #define UART_FCTR_EXAR_TRGD	0xc0	/* FIFO trigger table D programmable */
1097e12357eSJan Kiszka 
1107e12357eSJan Kiszka #define UART_EXAR_TXTRG		0x0a	/* Tx FIFO trigger level write-only */
1117e12357eSJan Kiszka #define UART_EXAR_RXTRG		0x0b	/* Rx FIFO trigger level write-only */
1127e12357eSJan Kiszka 
113d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINT_7_0	0x8f	/* MPIOINT[7:0] */
114d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOLVL_7_0	0x90	/* MPIOLVL[7:0] */
115d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIO3T_7_0	0x91	/* MPIO3T[7:0] */
116d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINV_7_0	0x92	/* MPIOINV[7:0] */
117d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOSEL_7_0	0x93	/* MPIOSEL[7:0] */
118d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOOD_7_0	0x94	/* MPIOOD[7:0] */
119d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINT_15_8	0x95	/* MPIOINT[15:8] */
120d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOLVL_15_8	0x96	/* MPIOLVL[15:8] */
121d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIO3T_15_8	0x97	/* MPIO3T[15:8] */
122d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINV_15_8	0x98	/* MPIOINV[15:8] */
123d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOSEL_15_8	0x99	/* MPIOSEL[15:8] */
124d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOOD_15_8	0x9a	/* MPIOOD[15:8] */
125d0aeaa83SSudip Mukherjee 
126413058dfSJan Kiszka #define UART_EXAR_RS485_DLY(x)	((x) << 4)
127413058dfSJan Kiszka 
128687911b3SMatthew Howell #define UART_EXAR_DLD			0x02 /* Divisor Fractional */
129687911b3SMatthew Howell #define UART_EXAR_DLD_485_POLARITY	0x80 /* RS-485 Enable Signal Polarity */
130687911b3SMatthew Howell 
131413058dfSJan Kiszka /*
132413058dfSJan Kiszka  * IOT2040 MPIO wiring semantics:
133413058dfSJan Kiszka  *
134413058dfSJan Kiszka  * MPIO		Port	Function
135413058dfSJan Kiszka  * ----		----	--------
136413058dfSJan Kiszka  * 0		2 	Mode bit 0
137413058dfSJan Kiszka  * 1		2	Mode bit 1
138413058dfSJan Kiszka  * 2		2	Terminate bus
139413058dfSJan Kiszka  * 3		-	<reserved>
140413058dfSJan Kiszka  * 4		3	Mode bit 0
141413058dfSJan Kiszka  * 5		3	Mode bit 1
142413058dfSJan Kiszka  * 6		3	Terminate bus
143413058dfSJan Kiszka  * 7		-	<reserved>
144413058dfSJan Kiszka  * 8		2	Enable
145413058dfSJan Kiszka  * 9		3	Enable
146413058dfSJan Kiszka  * 10		-	Red LED
147413058dfSJan Kiszka  * 11..15	-	<unused>
148413058dfSJan Kiszka  */
149413058dfSJan Kiszka 
150413058dfSJan Kiszka /* IOT2040 MPIOs 0..7 */
151413058dfSJan Kiszka #define IOT2040_UART_MODE_RS232		0x01
152413058dfSJan Kiszka #define IOT2040_UART_MODE_RS485		0x02
153413058dfSJan Kiszka #define IOT2040_UART_MODE_RS422		0x03
154413058dfSJan Kiszka #define IOT2040_UART_TERMINATE_BUS	0x04
155413058dfSJan Kiszka 
156413058dfSJan Kiszka #define IOT2040_UART1_MASK		0x0f
157413058dfSJan Kiszka #define IOT2040_UART2_SHIFT		4
158413058dfSJan Kiszka 
159413058dfSJan Kiszka #define IOT2040_UARTS_DEFAULT_MODE	0x11	/* both RS232 */
160413058dfSJan Kiszka #define IOT2040_UARTS_GPIO_LO_MODE	0x88	/* reserved pins as input */
161413058dfSJan Kiszka 
162413058dfSJan Kiszka /* IOT2040 MPIOs 8..15 */
163413058dfSJan Kiszka #define IOT2040_UARTS_ENABLE		0x03
164413058dfSJan Kiszka #define IOT2040_UARTS_GPIO_HI_MODE	0xF8	/* enable & LED as outputs */
165413058dfSJan Kiszka 
166d0aeaa83SSudip Mukherjee struct exar8250;
167d0aeaa83SSudip Mukherjee 
1680d963ebfSJan Kiszka struct exar8250_platform {
169ae50bb27SIlpo Järvinen 	int (*rs485_config)(struct uart_port *port, struct ktermios *termios,
170ae50bb27SIlpo Järvinen 			    struct serial_rs485 *rs485);
17159c221f8SIlpo Järvinen 	const struct serial_rs485 *rs485_supported;
1720d963ebfSJan Kiszka 	int (*register_gpio)(struct pci_dev *, struct uart_8250_port *);
17333969db7SAndy Shevchenko 	void (*unregister_gpio)(struct uart_8250_port *);
1740d963ebfSJan Kiszka };
1750d963ebfSJan Kiszka 
176d0aeaa83SSudip Mukherjee /**
177d0aeaa83SSudip Mukherjee  * struct exar8250_board - board information
178d0aeaa83SSudip Mukherjee  * @num_ports: number of serial ports
179d0aeaa83SSudip Mukherjee  * @reg_shift: describes UART register mapping in PCI memory
18026f22d57SAndy Shevchenko  * @setup: quirk run at ->probe() stage
18126f22d57SAndy Shevchenko  * @exit: quirk run at ->remove() stage
182d0aeaa83SSudip Mukherjee  */
183d0aeaa83SSudip Mukherjee struct exar8250_board {
184d0aeaa83SSudip Mukherjee 	unsigned int num_ports;
185d0aeaa83SSudip Mukherjee 	unsigned int reg_shift;
186d0aeaa83SSudip Mukherjee 	int	(*setup)(struct exar8250 *, struct pci_dev *,
187d0aeaa83SSudip Mukherjee 			 struct uart_8250_port *, int);
188d0aeaa83SSudip Mukherjee 	void	(*exit)(struct pci_dev *pcidev);
189d0aeaa83SSudip Mukherjee };
190d0aeaa83SSudip Mukherjee 
191d0aeaa83SSudip Mukherjee struct exar8250 {
192d0aeaa83SSudip Mukherjee 	unsigned int		nr;
193d0aeaa83SSudip Mukherjee 	struct exar8250_board	*board;
194c7e1b405SAaron Sierra 	void __iomem		*virt;
19500d963abSGustavo A. R. Silva 	int			line[];
196d0aeaa83SSudip Mukherjee };
197d0aeaa83SSudip Mukherjee 
198ef4e281eSAndy Shevchenko static void exar_pm(struct uart_port *port, unsigned int state, unsigned int old)
199ef4e281eSAndy Shevchenko {
200ef4e281eSAndy Shevchenko 	/*
201ef4e281eSAndy Shevchenko 	 * Exar UARTs have a SLEEP register that enables or disables each UART
202ef4e281eSAndy Shevchenko 	 * to enter sleep mode separately. On the XR17V35x the register
203ef4e281eSAndy Shevchenko 	 * is accessible to each UART at the UART_EXAR_SLEEP offset, but
204ef4e281eSAndy Shevchenko 	 * the UART channel may only write to the corresponding bit.
205ef4e281eSAndy Shevchenko 	 */
206ef4e281eSAndy Shevchenko 	serial_port_out(port, UART_EXAR_SLEEP, state ? 0xff : 0);
207ef4e281eSAndy Shevchenko }
208ef4e281eSAndy Shevchenko 
209b2b4b8edSAndy Shevchenko /*
210b2b4b8edSAndy Shevchenko  * XR17V35x UARTs have an extra fractional divisor register (DLD)
211b2b4b8edSAndy Shevchenko  * Calculate divisor with extra 4-bit fractional portion
212b2b4b8edSAndy Shevchenko  */
213b2b4b8edSAndy Shevchenko static unsigned int xr17v35x_get_divisor(struct uart_port *p, unsigned int baud,
214b2b4b8edSAndy Shevchenko 					 unsigned int *frac)
215b2b4b8edSAndy Shevchenko {
216b2b4b8edSAndy Shevchenko 	unsigned int quot_16;
217b2b4b8edSAndy Shevchenko 
218b2b4b8edSAndy Shevchenko 	quot_16 = DIV_ROUND_CLOSEST(p->uartclk, baud);
219b2b4b8edSAndy Shevchenko 	*frac = quot_16 & 0x0f;
220b2b4b8edSAndy Shevchenko 
221b2b4b8edSAndy Shevchenko 	return quot_16 >> 4;
222b2b4b8edSAndy Shevchenko }
223b2b4b8edSAndy Shevchenko 
224b2b4b8edSAndy Shevchenko static void xr17v35x_set_divisor(struct uart_port *p, unsigned int baud,
225b2b4b8edSAndy Shevchenko 				 unsigned int quot, unsigned int quot_frac)
226b2b4b8edSAndy Shevchenko {
227b2b4b8edSAndy Shevchenko 	serial8250_do_set_divisor(p, baud, quot, quot_frac);
228b2b4b8edSAndy Shevchenko 
229b2b4b8edSAndy Shevchenko 	/* Preserve bits not related to baudrate; DLD[7:4]. */
230b2b4b8edSAndy Shevchenko 	quot_frac |= serial_port_in(p, 0x2) & 0xf0;
231b2b4b8edSAndy Shevchenko 	serial_port_out(p, 0x2, quot_frac);
232b2b4b8edSAndy Shevchenko }
233b2b4b8edSAndy Shevchenko 
2346e731137SAndy Shevchenko static int xr17v35x_startup(struct uart_port *port)
2356e731137SAndy Shevchenko {
2366e731137SAndy Shevchenko 	/*
2376e731137SAndy Shevchenko 	 * First enable access to IER [7:5], ISR [5:4], FCR [5:4],
2386e731137SAndy Shevchenko 	 * MCR [7:5] and MSR [7:0]
2396e731137SAndy Shevchenko 	 */
2406e731137SAndy Shevchenko 	serial_port_out(port, UART_XR_EFR, UART_EFR_ECB);
2416e731137SAndy Shevchenko 
2426e731137SAndy Shevchenko 	/*
2436e731137SAndy Shevchenko 	 * Make sure all interrups are masked until initialization is
2446e731137SAndy Shevchenko 	 * complete and the FIFOs are cleared
245b1207d86SJohn Ogness 	 *
246b1207d86SJohn Ogness 	 * Synchronize UART_IER access against the console.
2476e731137SAndy Shevchenko 	 */
2482b71b31fSThomas Gleixner 	uart_port_lock_irq(port);
2496e731137SAndy Shevchenko 	serial_port_out(port, UART_IER, 0);
2502b71b31fSThomas Gleixner 	uart_port_unlock_irq(port);
2516e731137SAndy Shevchenko 
2526e731137SAndy Shevchenko 	return serial8250_do_startup(port);
2536e731137SAndy Shevchenko }
2546e731137SAndy Shevchenko 
255653d00c8SAndy Shevchenko static void exar_shutdown(struct uart_port *port)
256653d00c8SAndy Shevchenko {
25767e977f3SZheng Bin 	bool tx_complete = false;
258653d00c8SAndy Shevchenko 	struct uart_8250_port *up = up_to_u8250p(port);
2591788cf6aSJiri Slaby (SUSE) 	struct tty_port *tport = &port->state->port;
260653d00c8SAndy Shevchenko 	int i = 0;
261f8ba5680SIlpo Järvinen 	u16 lsr;
262653d00c8SAndy Shevchenko 
263653d00c8SAndy Shevchenko 	do {
264653d00c8SAndy Shevchenko 		lsr = serial_in(up, UART_LSR);
265653d00c8SAndy Shevchenko 		if (lsr & (UART_LSR_TEMT | UART_LSR_THRE))
26667e977f3SZheng Bin 			tx_complete = true;
267653d00c8SAndy Shevchenko 		else
26867e977f3SZheng Bin 			tx_complete = false;
2693f72879eSAndy Shevchenko 		usleep_range(1000, 1100);
2701788cf6aSJiri Slaby (SUSE) 	} while (!kfifo_is_empty(&tport->xmit_fifo) &&
2711788cf6aSJiri Slaby (SUSE) 			!tx_complete && i++ < 1000);
272653d00c8SAndy Shevchenko 
273653d00c8SAndy Shevchenko 	serial8250_do_shutdown(port);
274653d00c8SAndy Shevchenko }
275653d00c8SAndy Shevchenko 
276d0aeaa83SSudip Mukherjee static int default_setup(struct exar8250 *priv, struct pci_dev *pcidev,
277d0aeaa83SSudip Mukherjee 			 int idx, unsigned int offset,
278d0aeaa83SSudip Mukherjee 			 struct uart_8250_port *port)
279d0aeaa83SSudip Mukherjee {
280d0aeaa83SSudip Mukherjee 	const struct exar8250_board *board = priv->board;
2816be254c2SAndy Shevchenko 	unsigned char status;
282d813d900SAndy Shevchenko 	int err;
283d0aeaa83SSudip Mukherjee 
284d813d900SAndy Shevchenko 	err = serial8250_pci_setup_port(pcidev, port, 0, offset, board->reg_shift);
285d813d900SAndy Shevchenko 	if (err)
286d813d900SAndy Shevchenko 		return err;
287d0aeaa83SSudip Mukherjee 
2886be254c2SAndy Shevchenko 	/*
2896be254c2SAndy Shevchenko 	 * XR17V35x UARTs have an extra divisor register, DLD that gets enabled
2906be254c2SAndy Shevchenko 	 * with when DLAB is set which will cause the device to incorrectly match
2916be254c2SAndy Shevchenko 	 * and assign port type to PORT_16650. The EFR for this UART is found
2926be254c2SAndy Shevchenko 	 * at offset 0x09. Instead check the Deice ID (DVID) register
2936be254c2SAndy Shevchenko 	 * for a 2, 4 or 8 port UART.
2946be254c2SAndy Shevchenko 	 */
2956be254c2SAndy Shevchenko 	status = readb(port->port.membase + UART_EXAR_DVID);
2966be254c2SAndy Shevchenko 	if (status == 0x82 || status == 0x84 || status == 0x88) {
2976be254c2SAndy Shevchenko 		port->port.type = PORT_XR17V35X;
298b2b4b8edSAndy Shevchenko 
299b2b4b8edSAndy Shevchenko 		port->port.get_divisor = xr17v35x_get_divisor;
300b2b4b8edSAndy Shevchenko 		port->port.set_divisor = xr17v35x_set_divisor;
3016e731137SAndy Shevchenko 
3026e731137SAndy Shevchenko 		port->port.startup = xr17v35x_startup;
3036be254c2SAndy Shevchenko 	} else {
3046be254c2SAndy Shevchenko 		port->port.type = PORT_XR17D15X;
3056be254c2SAndy Shevchenko 	}
3066be254c2SAndy Shevchenko 
307ef4e281eSAndy Shevchenko 	port->port.pm = exar_pm;
308653d00c8SAndy Shevchenko 	port->port.shutdown = exar_shutdown;
309ef4e281eSAndy Shevchenko 
310d0aeaa83SSudip Mukherjee 	return 0;
311d0aeaa83SSudip Mukherjee }
312d0aeaa83SSudip Mukherjee 
313d0aeaa83SSudip Mukherjee static int
314fc6cc961SJan Kiszka pci_fastcom335_setup(struct exar8250 *priv, struct pci_dev *pcidev,
315fc6cc961SJan Kiszka 		     struct uart_8250_port *port, int idx)
316fc6cc961SJan Kiszka {
317fc6cc961SJan Kiszka 	unsigned int offset = idx * 0x200;
318fc6cc961SJan Kiszka 	unsigned int baud = 1843200;
319fc6cc961SJan Kiszka 	u8 __iomem *p;
320fc6cc961SJan Kiszka 	int err;
321fc6cc961SJan Kiszka 
322fc6cc961SJan Kiszka 	port->port.uartclk = baud * 16;
323fc6cc961SJan Kiszka 
324fc6cc961SJan Kiszka 	err = default_setup(priv, pcidev, idx, offset, port);
325fc6cc961SJan Kiszka 	if (err)
326fc6cc961SJan Kiszka 		return err;
327fc6cc961SJan Kiszka 
328fc6cc961SJan Kiszka 	p = port->port.membase;
329fc6cc961SJan Kiszka 
330fc6cc961SJan Kiszka 	writeb(0x00, p + UART_EXAR_8XMODE);
331fc6cc961SJan Kiszka 	writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR);
332fc6cc961SJan Kiszka 	writeb(32, p + UART_EXAR_TXTRG);
333fc6cc961SJan Kiszka 	writeb(32, p + UART_EXAR_RXTRG);
334fc6cc961SJan Kiszka 
335fc6cc961SJan Kiszka 	/*
336fc6cc961SJan Kiszka 	 * Setup Multipurpose Input/Output pins.
337fc6cc961SJan Kiszka 	 */
338fc6cc961SJan Kiszka 	if (idx == 0) {
339fc6cc961SJan Kiszka 		switch (pcidev->device) {
340fc6cc961SJan Kiszka 		case PCI_DEVICE_ID_COMMTECH_4222PCI335:
341fc6cc961SJan Kiszka 		case PCI_DEVICE_ID_COMMTECH_4224PCI335:
342fc6cc961SJan Kiszka 			writeb(0x78, p + UART_EXAR_MPIOLVL_7_0);
343fc6cc961SJan Kiszka 			writeb(0x00, p + UART_EXAR_MPIOINV_7_0);
344fc6cc961SJan Kiszka 			writeb(0x00, p + UART_EXAR_MPIOSEL_7_0);
345fc6cc961SJan Kiszka 			break;
346fc6cc961SJan Kiszka 		case PCI_DEVICE_ID_COMMTECH_2324PCI335:
347fc6cc961SJan Kiszka 		case PCI_DEVICE_ID_COMMTECH_2328PCI335:
348fc6cc961SJan Kiszka 			writeb(0x00, p + UART_EXAR_MPIOLVL_7_0);
349fc6cc961SJan Kiszka 			writeb(0xc0, p + UART_EXAR_MPIOINV_7_0);
350fc6cc961SJan Kiszka 			writeb(0xc0, p + UART_EXAR_MPIOSEL_7_0);
351fc6cc961SJan Kiszka 			break;
352fc6cc961SJan Kiszka 		}
353fc6cc961SJan Kiszka 		writeb(0x00, p + UART_EXAR_MPIOINT_7_0);
354fc6cc961SJan Kiszka 		writeb(0x00, p + UART_EXAR_MPIO3T_7_0);
355fc6cc961SJan Kiszka 		writeb(0x00, p + UART_EXAR_MPIOOD_7_0);
356fc6cc961SJan Kiszka 	}
357fc6cc961SJan Kiszka 
358fc6cc961SJan Kiszka 	return 0;
359fc6cc961SJan Kiszka }
360fc6cc961SJan Kiszka 
361fc6cc961SJan Kiszka static int
362d0aeaa83SSudip Mukherjee pci_connect_tech_setup(struct exar8250 *priv, struct pci_dev *pcidev,
363d0aeaa83SSudip Mukherjee 		       struct uart_8250_port *port, int idx)
364d0aeaa83SSudip Mukherjee {
365d0aeaa83SSudip Mukherjee 	unsigned int offset = idx * 0x200;
366d0aeaa83SSudip Mukherjee 	unsigned int baud = 1843200;
367d0aeaa83SSudip Mukherjee 
368d0aeaa83SSudip Mukherjee 	port->port.uartclk = baud * 16;
369d0aeaa83SSudip Mukherjee 	return default_setup(priv, pcidev, idx, offset, port);
370d0aeaa83SSudip Mukherjee }
371d0aeaa83SSudip Mukherjee 
372d0aeaa83SSudip Mukherjee static int
373d0aeaa83SSudip Mukherjee pci_xr17c154_setup(struct exar8250 *priv, struct pci_dev *pcidev,
374d0aeaa83SSudip Mukherjee 		   struct uart_8250_port *port, int idx)
375d0aeaa83SSudip Mukherjee {
376d0aeaa83SSudip Mukherjee 	unsigned int offset = idx * 0x200;
377d0aeaa83SSudip Mukherjee 	unsigned int baud = 921600;
378d0aeaa83SSudip Mukherjee 
379d0aeaa83SSudip Mukherjee 	port->port.uartclk = baud * 16;
380d0aeaa83SSudip Mukherjee 	return default_setup(priv, pcidev, idx, offset, port);
381d0aeaa83SSudip Mukherjee }
382d0aeaa83SSudip Mukherjee 
383bea8be65SJan Kiszka static void setup_gpio(struct pci_dev *pcidev, u8 __iomem *p)
384d0aeaa83SSudip Mukherjee {
385bea8be65SJan Kiszka 	/*
386bea8be65SJan Kiszka 	 * The Commtech adapters required the MPIOs to be driven low. The Exar
387bea8be65SJan Kiszka 	 * devices will export them as GPIOs, so we pre-configure them safely
388bea8be65SJan Kiszka 	 * as inputs.
389bea8be65SJan Kiszka 	 */
3905fdbe136SMatthew Howell 
3915fdbe136SMatthew Howell 	u8 dir = 0x00;
3925fdbe136SMatthew Howell 
3935fdbe136SMatthew Howell 	if  ((pcidev->vendor == PCI_VENDOR_ID_EXAR) &&
3945fdbe136SMatthew Howell 		(pcidev->subsystem_vendor != PCI_VENDOR_ID_SEALEVEL)) {
3955fdbe136SMatthew Howell 		// Configure GPIO as inputs for Commtech adapters
3965fdbe136SMatthew Howell 		dir = 0xff;
3975fdbe136SMatthew Howell 	} else {
3985fdbe136SMatthew Howell 		// Configure GPIO as outputs for SeaLevel adapters
3995fdbe136SMatthew Howell 		dir = 0x00;
4005fdbe136SMatthew Howell 	}
401bea8be65SJan Kiszka 
402d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOINT_7_0);
403d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOLVL_7_0);
404d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIO3T_7_0);
405d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOINV_7_0);
406bea8be65SJan Kiszka 	writeb(dir,  p + UART_EXAR_MPIOSEL_7_0);
407d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOOD_7_0);
408d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOINT_15_8);
409d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOLVL_15_8);
410d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIO3T_15_8);
411d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOINV_15_8);
412bea8be65SJan Kiszka 	writeb(dir,  p + UART_EXAR_MPIOSEL_15_8);
413d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOOD_15_8);
414d0aeaa83SSudip Mukherjee }
415d0aeaa83SSudip Mukherjee 
41633969db7SAndy Shevchenko static struct platform_device *__xr17v35x_register_gpio(struct pci_dev *pcidev,
41781171e7dSHeikki Krogerus 							const struct software_node *node)
418d0aeaa83SSudip Mukherjee {
419d0aeaa83SSudip Mukherjee 	struct platform_device *pdev;
420d0aeaa83SSudip Mukherjee 
421d0aeaa83SSudip Mukherjee 	pdev = platform_device_alloc("gpio_exar", PLATFORM_DEVID_AUTO);
422d0aeaa83SSudip Mukherjee 	if (!pdev)
423d0aeaa83SSudip Mukherjee 		return NULL;
424d0aeaa83SSudip Mukherjee 
425d3936d74SJan Kiszka 	pdev->dev.parent = &pcidev->dev;
42673f76db8SAndy Shevchenko 	device_set_node(&pdev->dev, dev_fwnode(&pcidev->dev));
427d3936d74SJan Kiszka 
42881171e7dSHeikki Krogerus 	if (device_add_software_node(&pdev->dev, node) < 0 ||
429380b1e2fSJan Kiszka 	    platform_device_add(pdev) < 0) {
430d0aeaa83SSudip Mukherjee 		platform_device_put(pdev);
431d0aeaa83SSudip Mukherjee 		return NULL;
432d0aeaa83SSudip Mukherjee 	}
433d0aeaa83SSudip Mukherjee 
434d0aeaa83SSudip Mukherjee 	return pdev;
435d0aeaa83SSudip Mukherjee }
436d0aeaa83SSudip Mukherjee 
43733969db7SAndy Shevchenko static void __xr17v35x_unregister_gpio(struct platform_device *pdev)
43833969db7SAndy Shevchenko {
43933969db7SAndy Shevchenko 	device_remove_software_node(&pdev->dev);
44033969db7SAndy Shevchenko 	platform_device_unregister(pdev);
44133969db7SAndy Shevchenko }
44233969db7SAndy Shevchenko 
443380b1e2fSJan Kiszka static const struct property_entry exar_gpio_properties[] = {
444a589e211SJan Kiszka 	PROPERTY_ENTRY_U32("exar,first-pin", 0),
445380b1e2fSJan Kiszka 	PROPERTY_ENTRY_U32("ngpios", 16),
446380b1e2fSJan Kiszka 	{ }
447380b1e2fSJan Kiszka };
448380b1e2fSJan Kiszka 
44981171e7dSHeikki Krogerus static const struct software_node exar_gpio_node = {
45081171e7dSHeikki Krogerus 	.properties = exar_gpio_properties,
45181171e7dSHeikki Krogerus };
45281171e7dSHeikki Krogerus 
45333969db7SAndy Shevchenko static int xr17v35x_register_gpio(struct pci_dev *pcidev, struct uart_8250_port *port)
4540d963ebfSJan Kiszka {
4550d963ebfSJan Kiszka 	if (pcidev->vendor == PCI_VENDOR_ID_EXAR)
4560d963ebfSJan Kiszka 		port->port.private_data =
45781171e7dSHeikki Krogerus 			__xr17v35x_register_gpio(pcidev, &exar_gpio_node);
4580d963ebfSJan Kiszka 
4590d963ebfSJan Kiszka 	return 0;
4600d963ebfSJan Kiszka }
4610d963ebfSJan Kiszka 
46233969db7SAndy Shevchenko static void xr17v35x_unregister_gpio(struct uart_8250_port *port)
46333969db7SAndy Shevchenko {
46433969db7SAndy Shevchenko 	if (!port->port.private_data)
46533969db7SAndy Shevchenko 		return;
46633969db7SAndy Shevchenko 
46733969db7SAndy Shevchenko 	__xr17v35x_unregister_gpio(port->port.private_data);
46833969db7SAndy Shevchenko 	port->port.private_data = NULL;
46933969db7SAndy Shevchenko }
47033969db7SAndy Shevchenko 
471ae50bb27SIlpo Järvinen static int generic_rs485_config(struct uart_port *port, struct ktermios *termios,
4729d939894SDaniel Golle 				struct serial_rs485 *rs485)
4739d939894SDaniel Golle {
4749d939894SDaniel Golle 	bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
4759d939894SDaniel Golle 	u8 __iomem *p = port->membase;
4769d939894SDaniel Golle 	u8 value;
4779d939894SDaniel Golle 
4789d939894SDaniel Golle 	value = readb(p + UART_EXAR_FCTR);
4799d939894SDaniel Golle 	if (is_rs485)
4809d939894SDaniel Golle 		value |= UART_FCTR_EXAR_485;
4819d939894SDaniel Golle 	else
4829d939894SDaniel Golle 		value &= ~UART_FCTR_EXAR_485;
4839d939894SDaniel Golle 
4849d939894SDaniel Golle 	writeb(value, p + UART_EXAR_FCTR);
4859d939894SDaniel Golle 
4869d939894SDaniel Golle 	if (is_rs485)
4879d939894SDaniel Golle 		writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR);
4889d939894SDaniel Golle 
4899d939894SDaniel Golle 	return 0;
4909d939894SDaniel Golle }
4919d939894SDaniel Golle 
492687911b3SMatthew Howell static int sealevel_rs485_config(struct uart_port *port, struct ktermios *termios,
493687911b3SMatthew Howell 				  struct serial_rs485 *rs485)
494687911b3SMatthew Howell {
495687911b3SMatthew Howell 	u8 __iomem *p = port->membase;
496687911b3SMatthew Howell 	u8 old_lcr;
497687911b3SMatthew Howell 	u8 efr;
498687911b3SMatthew Howell 	u8 dld;
499687911b3SMatthew Howell 	int ret;
500687911b3SMatthew Howell 
501687911b3SMatthew Howell 	ret = generic_rs485_config(port, termios, rs485);
502687911b3SMatthew Howell 	if (ret)
503687911b3SMatthew Howell 		return ret;
504687911b3SMatthew Howell 
505687911b3SMatthew Howell 	if (rs485->flags & SER_RS485_ENABLED) {
506687911b3SMatthew Howell 		old_lcr = readb(p + UART_LCR);
507687911b3SMatthew Howell 
508687911b3SMatthew Howell 		/* Set EFR[4]=1 to enable enhanced feature registers */
509687911b3SMatthew Howell 		efr = readb(p + UART_XR_EFR);
510687911b3SMatthew Howell 		efr |= UART_EFR_ECB;
511687911b3SMatthew Howell 		writeb(efr, p + UART_XR_EFR);
512687911b3SMatthew Howell 
513687911b3SMatthew Howell 		/* Set MCR to use DTR as Auto-RS485 Enable signal */
514687911b3SMatthew Howell 		writeb(UART_MCR_OUT1, p + UART_MCR);
515687911b3SMatthew Howell 
516687911b3SMatthew Howell 		/* Set LCR[7]=1 to enable access to DLD register */
517687911b3SMatthew Howell 		writeb(old_lcr | UART_LCR_DLAB, p + UART_LCR);
518687911b3SMatthew Howell 
519687911b3SMatthew Howell 		/* Set DLD[7]=1 for inverted RS485 Enable logic */
520687911b3SMatthew Howell 		dld = readb(p + UART_EXAR_DLD);
521687911b3SMatthew Howell 		dld |= UART_EXAR_DLD_485_POLARITY;
522687911b3SMatthew Howell 		writeb(dld, p + UART_EXAR_DLD);
523687911b3SMatthew Howell 
524687911b3SMatthew Howell 		writeb(old_lcr, p + UART_LCR);
525687911b3SMatthew Howell 	}
526687911b3SMatthew Howell 
527687911b3SMatthew Howell 	return 0;
528687911b3SMatthew Howell }
529687911b3SMatthew Howell 
53059c221f8SIlpo Järvinen static const struct serial_rs485 generic_rs485_supported = {
5310c2a5f47SLino Sanfilippo 	.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
53259c221f8SIlpo Järvinen };
53359c221f8SIlpo Järvinen 
5340d963ebfSJan Kiszka static const struct exar8250_platform exar8250_default_platform = {
5350d963ebfSJan Kiszka 	.register_gpio = xr17v35x_register_gpio,
53633969db7SAndy Shevchenko 	.unregister_gpio = xr17v35x_unregister_gpio,
5379d939894SDaniel Golle 	.rs485_config = generic_rs485_config,
53859c221f8SIlpo Järvinen 	.rs485_supported = &generic_rs485_supported,
5390d963ebfSJan Kiszka };
5400d963ebfSJan Kiszka 
541ae50bb27SIlpo Järvinen static int iot2040_rs485_config(struct uart_port *port, struct ktermios *termios,
542413058dfSJan Kiszka 				struct serial_rs485 *rs485)
543413058dfSJan Kiszka {
544413058dfSJan Kiszka 	bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
545413058dfSJan Kiszka 	u8 __iomem *p = port->membase;
546413058dfSJan Kiszka 	u8 mask = IOT2040_UART1_MASK;
547413058dfSJan Kiszka 	u8 mode, value;
548413058dfSJan Kiszka 
549413058dfSJan Kiszka 	if (is_rs485) {
550413058dfSJan Kiszka 		if (rs485->flags & SER_RS485_RX_DURING_TX)
551413058dfSJan Kiszka 			mode = IOT2040_UART_MODE_RS422;
552413058dfSJan Kiszka 		else
553413058dfSJan Kiszka 			mode = IOT2040_UART_MODE_RS485;
554413058dfSJan Kiszka 
555413058dfSJan Kiszka 		if (rs485->flags & SER_RS485_TERMINATE_BUS)
556413058dfSJan Kiszka 			mode |= IOT2040_UART_TERMINATE_BUS;
557413058dfSJan Kiszka 	} else {
558413058dfSJan Kiszka 		mode = IOT2040_UART_MODE_RS232;
559413058dfSJan Kiszka 	}
560413058dfSJan Kiszka 
561413058dfSJan Kiszka 	if (port->line == 3) {
562413058dfSJan Kiszka 		mask <<= IOT2040_UART2_SHIFT;
563413058dfSJan Kiszka 		mode <<= IOT2040_UART2_SHIFT;
564413058dfSJan Kiszka 	}
565413058dfSJan Kiszka 
566413058dfSJan Kiszka 	value = readb(p + UART_EXAR_MPIOLVL_7_0);
567413058dfSJan Kiszka 	value &= ~mask;
568413058dfSJan Kiszka 	value |= mode;
569413058dfSJan Kiszka 	writeb(value, p + UART_EXAR_MPIOLVL_7_0);
570413058dfSJan Kiszka 
571ae50bb27SIlpo Järvinen 	return generic_rs485_config(port, termios, rs485);
572413058dfSJan Kiszka }
573413058dfSJan Kiszka 
57459c221f8SIlpo Järvinen static const struct serial_rs485 iot2040_rs485_supported = {
5750c2a5f47SLino Sanfilippo 	.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND |
5760c2a5f47SLino Sanfilippo 		 SER_RS485_RX_DURING_TX | SER_RS485_TERMINATE_BUS,
57759c221f8SIlpo Järvinen };
57859c221f8SIlpo Järvinen 
579413058dfSJan Kiszka static const struct property_entry iot2040_gpio_properties[] = {
580a589e211SJan Kiszka 	PROPERTY_ENTRY_U32("exar,first-pin", 10),
581413058dfSJan Kiszka 	PROPERTY_ENTRY_U32("ngpios", 1),
582413058dfSJan Kiszka 	{ }
583413058dfSJan Kiszka };
584413058dfSJan Kiszka 
58581171e7dSHeikki Krogerus static const struct software_node iot2040_gpio_node = {
58681171e7dSHeikki Krogerus 	.properties = iot2040_gpio_properties,
58781171e7dSHeikki Krogerus };
58881171e7dSHeikki Krogerus 
589413058dfSJan Kiszka static int iot2040_register_gpio(struct pci_dev *pcidev,
590413058dfSJan Kiszka 			      struct uart_8250_port *port)
591413058dfSJan Kiszka {
592413058dfSJan Kiszka 	u8 __iomem *p = port->port.membase;
593413058dfSJan Kiszka 
594413058dfSJan Kiszka 	writeb(IOT2040_UARTS_DEFAULT_MODE, p + UART_EXAR_MPIOLVL_7_0);
595413058dfSJan Kiszka 	writeb(IOT2040_UARTS_GPIO_LO_MODE, p + UART_EXAR_MPIOSEL_7_0);
596413058dfSJan Kiszka 	writeb(IOT2040_UARTS_ENABLE, p + UART_EXAR_MPIOLVL_15_8);
597413058dfSJan Kiszka 	writeb(IOT2040_UARTS_GPIO_HI_MODE, p + UART_EXAR_MPIOSEL_15_8);
598413058dfSJan Kiszka 
599413058dfSJan Kiszka 	port->port.private_data =
60081171e7dSHeikki Krogerus 		__xr17v35x_register_gpio(pcidev, &iot2040_gpio_node);
601413058dfSJan Kiszka 
602413058dfSJan Kiszka 	return 0;
603413058dfSJan Kiszka }
604413058dfSJan Kiszka 
605413058dfSJan Kiszka static const struct exar8250_platform iot2040_platform = {
606413058dfSJan Kiszka 	.rs485_config = iot2040_rs485_config,
60759c221f8SIlpo Järvinen 	.rs485_supported = &iot2040_rs485_supported,
608413058dfSJan Kiszka 	.register_gpio = iot2040_register_gpio,
60933969db7SAndy Shevchenko 	.unregister_gpio = xr17v35x_unregister_gpio,
610413058dfSJan Kiszka };
611413058dfSJan Kiszka 
6123e51ceeaSSu Bao Cheng /*
6133e51ceeaSSu Bao Cheng  * For SIMATIC IOT2000, only IOT2040 and its variants have the Exar device,
6143e51ceeaSSu Bao Cheng  * IOT2020 doesn't have. Therefore it is sufficient to match on the common
6153e51ceeaSSu Bao Cheng  * board name after the device was found.
6163e51ceeaSSu Bao Cheng  */
617413058dfSJan Kiszka static const struct dmi_system_id exar_platforms[] = {
618413058dfSJan Kiszka 	{
619413058dfSJan Kiszka 		.matches = {
620413058dfSJan Kiszka 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
621413058dfSJan Kiszka 		},
622413058dfSJan Kiszka 		.driver_data = (void *)&iot2040_platform,
623413058dfSJan Kiszka 	},
624413058dfSJan Kiszka 	{}
625413058dfSJan Kiszka };
626413058dfSJan Kiszka 
6277d356a43SAndy Shevchenko static const struct exar8250_platform *exar_get_platform(void)
6287d356a43SAndy Shevchenko {
6297d356a43SAndy Shevchenko 	const struct dmi_system_id *dmi_match;
6307d356a43SAndy Shevchenko 
6317d356a43SAndy Shevchenko 	dmi_match = dmi_first_match(exar_platforms);
6327d356a43SAndy Shevchenko 	if (dmi_match)
6337d356a43SAndy Shevchenko 		return dmi_match->driver_data;
6347d356a43SAndy Shevchenko 
6357d356a43SAndy Shevchenko 	return &exar8250_default_platform;
6367d356a43SAndy Shevchenko }
6377d356a43SAndy Shevchenko 
638d0aeaa83SSudip Mukherjee static int
639d0aeaa83SSudip Mukherjee pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev,
640d0aeaa83SSudip Mukherjee 		   struct uart_8250_port *port, int idx)
641d0aeaa83SSudip Mukherjee {
6427d356a43SAndy Shevchenko 	const struct exar8250_platform *platform = exar_get_platform();
643d0aeaa83SSudip Mukherjee 	unsigned int offset = idx * 0x400;
644d0aeaa83SSudip Mukherjee 	unsigned int baud = 7812500;
645d0aeaa83SSudip Mukherjee 	u8 __iomem *p;
646d0aeaa83SSudip Mukherjee 	int ret;
647d0aeaa83SSudip Mukherjee 
648d0aeaa83SSudip Mukherjee 	port->port.uartclk = baud * 16;
6490d963ebfSJan Kiszka 	port->port.rs485_config = platform->rs485_config;
6500139da50SIlpo Järvinen 	port->port.rs485_supported = *(platform->rs485_supported);
6510d963ebfSJan Kiszka 
652687911b3SMatthew Howell 	if (pcidev->subsystem_vendor == PCI_VENDOR_ID_SEALEVEL)
653687911b3SMatthew Howell 		port->port.rs485_config = sealevel_rs485_config;
654687911b3SMatthew Howell 
655d0aeaa83SSudip Mukherjee 	/*
656328c11f2SAndy Shevchenko 	 * Setup the UART clock for the devices on expansion slot to
657d0aeaa83SSudip Mukherjee 	 * half the clock speed of the main chip (which is 125MHz)
658d0aeaa83SSudip Mukherjee 	 */
659328c11f2SAndy Shevchenko 	if (idx >= 8)
660d0aeaa83SSudip Mukherjee 		port->port.uartclk /= 2;
661d0aeaa83SSudip Mukherjee 
6625b5f252dSJan Kiszka 	ret = default_setup(priv, pcidev, idx, offset, port);
6635b5f252dSJan Kiszka 	if (ret)
6645b5f252dSJan Kiszka 		return ret;
665d0aeaa83SSudip Mukherjee 
6665b5f252dSJan Kiszka 	p = port->port.membase;
667d0aeaa83SSudip Mukherjee 
668d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_8XMODE);
669d0aeaa83SSudip Mukherjee 	writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR);
670d0aeaa83SSudip Mukherjee 	writeb(128, p + UART_EXAR_TXTRG);
671d0aeaa83SSudip Mukherjee 	writeb(128, p + UART_EXAR_RXTRG);
672d0aeaa83SSudip Mukherjee 
6735b5f252dSJan Kiszka 	if (idx == 0) {
6745b5f252dSJan Kiszka 		/* Setup Multipurpose Input/Output pins. */
675bea8be65SJan Kiszka 		setup_gpio(pcidev, p);
676d0aeaa83SSudip Mukherjee 
6770d963ebfSJan Kiszka 		ret = platform->register_gpio(pcidev, port);
6785b5f252dSJan Kiszka 	}
679d0aeaa83SSudip Mukherjee 
6800d963ebfSJan Kiszka 	return ret;
681d0aeaa83SSudip Mukherjee }
682d0aeaa83SSudip Mukherjee 
683d0aeaa83SSudip Mukherjee static void pci_xr17v35x_exit(struct pci_dev *pcidev)
684d0aeaa83SSudip Mukherjee {
68533969db7SAndy Shevchenko 	const struct exar8250_platform *platform = exar_get_platform();
686d0aeaa83SSudip Mukherjee 	struct exar8250 *priv = pci_get_drvdata(pcidev);
687d0aeaa83SSudip Mukherjee 	struct uart_8250_port *port = serial8250_get_port(priv->line[0]);
6887c3e8d9dSAndy Shevchenko 
68933969db7SAndy Shevchenko 	platform->unregister_gpio(port);
690d0aeaa83SSudip Mukherjee }
691d0aeaa83SSudip Mukherjee 
69272169e42SAaron Sierra static inline void exar_misc_clear(struct exar8250 *priv)
69372169e42SAaron Sierra {
69472169e42SAaron Sierra 	/* Clear all PCI interrupts by reading INT0. No effect on IIR */
69572169e42SAaron Sierra 	readb(priv->virt + UART_EXAR_INT0);
69672169e42SAaron Sierra 
69772169e42SAaron Sierra 	/* Clear INT0 for Expansion Interface slave ports, too */
69872169e42SAaron Sierra 	if (priv->board->num_ports > 8)
69972169e42SAaron Sierra 		readb(priv->virt + 0x2000 + UART_EXAR_INT0);
70072169e42SAaron Sierra }
70172169e42SAaron Sierra 
702c7e1b405SAaron Sierra /*
703c7e1b405SAaron Sierra  * These Exar UARTs have an extra interrupt indicator that could fire for a
704c7e1b405SAaron Sierra  * few interrupts that are not presented/cleared through IIR.  One of which is
705c7e1b405SAaron Sierra  * a wakeup interrupt when coming out of sleep.  These interrupts are only
706c7e1b405SAaron Sierra  * cleared by reading global INT0 or INT1 registers as interrupts are
707c7e1b405SAaron Sierra  * associated with channel 0. The INT[3:0] registers _are_ accessible from each
708c7e1b405SAaron Sierra  * channel's address space, but for the sake of bus efficiency we register a
709c7e1b405SAaron Sierra  * dedicated handler at the PCI device level to handle them.
710c7e1b405SAaron Sierra  */
711c7e1b405SAaron Sierra static irqreturn_t exar_misc_handler(int irq, void *data)
712c7e1b405SAaron Sierra {
71372169e42SAaron Sierra 	exar_misc_clear(data);
714c7e1b405SAaron Sierra 
715c7e1b405SAaron Sierra 	return IRQ_HANDLED;
716c7e1b405SAaron Sierra }
717c7e1b405SAaron Sierra 
718d0aeaa83SSudip Mukherjee static int
719d0aeaa83SSudip Mukherjee exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
720d0aeaa83SSudip Mukherjee {
721d0aeaa83SSudip Mukherjee 	unsigned int nr_ports, i, bar = 0, maxnr;
722d0aeaa83SSudip Mukherjee 	struct exar8250_board *board;
723d0aeaa83SSudip Mukherjee 	struct uart_8250_port uart;
724d0aeaa83SSudip Mukherjee 	struct exar8250 *priv;
725d0aeaa83SSudip Mukherjee 	int rc;
726d0aeaa83SSudip Mukherjee 
727d0aeaa83SSudip Mukherjee 	board = (struct exar8250_board *)ent->driver_data;
728d0aeaa83SSudip Mukherjee 	if (!board)
729d0aeaa83SSudip Mukherjee 		return -EINVAL;
730d0aeaa83SSudip Mukherjee 
731d0aeaa83SSudip Mukherjee 	rc = pcim_enable_device(pcidev);
732d0aeaa83SSudip Mukherjee 	if (rc)
733d0aeaa83SSudip Mukherjee 		return rc;
734d0aeaa83SSudip Mukherjee 
735d0aeaa83SSudip Mukherjee 	maxnr = pci_resource_len(pcidev, bar) >> (board->reg_shift + 3);
736d0aeaa83SSudip Mukherjee 
7378e4413aaSAndy Shevchenko 	if (pcidev->vendor == PCI_VENDOR_ID_ACCESSIO)
7388e4413aaSAndy Shevchenko 		nr_ports = BIT(((pcidev->device & 0x38) >> 3) - 1);
7398e4413aaSAndy Shevchenko 	else if (board->num_ports)
7408e4413aaSAndy Shevchenko 		nr_ports = board->num_ports;
7418e4413aaSAndy Shevchenko 	else
7428e4413aaSAndy Shevchenko 		nr_ports = pcidev->device & 0x0f;
743d0aeaa83SSudip Mukherjee 
744df60a8afSAndy Shevchenko 	priv = devm_kzalloc(&pcidev->dev, struct_size(priv, line, nr_ports), GFP_KERNEL);
745d0aeaa83SSudip Mukherjee 	if (!priv)
746d0aeaa83SSudip Mukherjee 		return -ENOMEM;
747d0aeaa83SSudip Mukherjee 
748d0aeaa83SSudip Mukherjee 	priv->board = board;
749c7e1b405SAaron Sierra 	priv->virt = pcim_iomap(pcidev, bar, 0);
750c7e1b405SAaron Sierra 	if (!priv->virt)
751c7e1b405SAaron Sierra 		return -ENOMEM;
752d0aeaa83SSudip Mukherjee 
753172c33cbSJan Kiszka 	pci_set_master(pcidev);
754172c33cbSJan Kiszka 
755172c33cbSJan Kiszka 	rc = pci_alloc_irq_vectors(pcidev, 1, 1, PCI_IRQ_ALL_TYPES);
756172c33cbSJan Kiszka 	if (rc < 0)
757172c33cbSJan Kiszka 		return rc;
758172c33cbSJan Kiszka 
759d0aeaa83SSudip Mukherjee 	memset(&uart, 0, sizeof(uart));
7606be254c2SAndy Shevchenko 	uart.port.flags = UPF_SHARE_IRQ | UPF_EXAR_EFR | UPF_FIXED_TYPE | UPF_FIXED_PORT;
761172c33cbSJan Kiszka 	uart.port.irq = pci_irq_vector(pcidev, 0);
762d0aeaa83SSudip Mukherjee 	uart.port.dev = &pcidev->dev;
763d0aeaa83SSudip Mukherjee 
7645bc430afSAndy Shevchenko 	/* Clear interrupts */
7655bc430afSAndy Shevchenko 	exar_misc_clear(priv);
7665bc430afSAndy Shevchenko 
767c7e1b405SAaron Sierra 	rc = devm_request_irq(&pcidev->dev, uart.port.irq, exar_misc_handler,
768c7e1b405SAaron Sierra 			 IRQF_SHARED, "exar_uart", priv);
769c7e1b405SAaron Sierra 	if (rc)
770c7e1b405SAaron Sierra 		return rc;
771c7e1b405SAaron Sierra 
772d0aeaa83SSudip Mukherjee 	for (i = 0; i < nr_ports && i < maxnr; i++) {
773d0aeaa83SSudip Mukherjee 		rc = board->setup(priv, pcidev, &uart, i);
774d0aeaa83SSudip Mukherjee 		if (rc) {
775d0aeaa83SSudip Mukherjee 			dev_err(&pcidev->dev, "Failed to setup port %u\n", i);
776d0aeaa83SSudip Mukherjee 			break;
777d0aeaa83SSudip Mukherjee 		}
778d0aeaa83SSudip Mukherjee 
779d0aeaa83SSudip Mukherjee 		dev_dbg(&pcidev->dev, "Setup PCI port: port %lx, irq %d, type %d\n",
780d0aeaa83SSudip Mukherjee 			uart.port.iobase, uart.port.irq, uart.port.iotype);
781d0aeaa83SSudip Mukherjee 
782d0aeaa83SSudip Mukherjee 		priv->line[i] = serial8250_register_8250_port(&uart);
783d0aeaa83SSudip Mukherjee 		if (priv->line[i] < 0) {
784d0aeaa83SSudip Mukherjee 			dev_err(&pcidev->dev,
785d0aeaa83SSudip Mukherjee 				"Couldn't register serial port %lx, irq %d, type %d, error %d\n",
786d0aeaa83SSudip Mukherjee 				uart.port.iobase, uart.port.irq,
787d0aeaa83SSudip Mukherjee 				uart.port.iotype, priv->line[i]);
788d0aeaa83SSudip Mukherjee 			break;
789d0aeaa83SSudip Mukherjee 		}
790d0aeaa83SSudip Mukherjee 	}
791d0aeaa83SSudip Mukherjee 	priv->nr = i;
792d0aeaa83SSudip Mukherjee 	pci_set_drvdata(pcidev, priv);
793d0aeaa83SSudip Mukherjee 	return 0;
794d0aeaa83SSudip Mukherjee }
795d0aeaa83SSudip Mukherjee 
796d0aeaa83SSudip Mukherjee static void exar_pci_remove(struct pci_dev *pcidev)
797d0aeaa83SSudip Mukherjee {
798d0aeaa83SSudip Mukherjee 	struct exar8250 *priv = pci_get_drvdata(pcidev);
799d0aeaa83SSudip Mukherjee 	unsigned int i;
800d0aeaa83SSudip Mukherjee 
801d0aeaa83SSudip Mukherjee 	for (i = 0; i < priv->nr; i++)
802d0aeaa83SSudip Mukherjee 		serial8250_unregister_port(priv->line[i]);
803d0aeaa83SSudip Mukherjee 
80473b5a5c0SAndy Shevchenko 	/* Ensure that every init quirk is properly torn down */
805d0aeaa83SSudip Mukherjee 	if (priv->board->exit)
806d0aeaa83SSudip Mukherjee 		priv->board->exit(pcidev);
807d0aeaa83SSudip Mukherjee }
808d0aeaa83SSudip Mukherjee 
80982f9cefaSAndy Shevchenko static int exar_suspend(struct device *dev)
810d0aeaa83SSudip Mukherjee {
8117a345dc1SAndy Shevchenko 	struct exar8250 *priv = dev_get_drvdata(dev);
812d0aeaa83SSudip Mukherjee 	unsigned int i;
813d0aeaa83SSudip Mukherjee 
814d0aeaa83SSudip Mukherjee 	for (i = 0; i < priv->nr; i++)
815d0aeaa83SSudip Mukherjee 		if (priv->line[i] >= 0)
816d0aeaa83SSudip Mukherjee 			serial8250_suspend_port(priv->line[i]);
817d0aeaa83SSudip Mukherjee 
818d0aeaa83SSudip Mukherjee 	return 0;
819d0aeaa83SSudip Mukherjee }
820d0aeaa83SSudip Mukherjee 
82182f9cefaSAndy Shevchenko static int exar_resume(struct device *dev)
822d0aeaa83SSudip Mukherjee {
82376b4106cSChuhong Yuan 	struct exar8250 *priv = dev_get_drvdata(dev);
824d0aeaa83SSudip Mukherjee 	unsigned int i;
825d0aeaa83SSudip Mukherjee 
82672169e42SAaron Sierra 	exar_misc_clear(priv);
82772169e42SAaron Sierra 
828d0aeaa83SSudip Mukherjee 	for (i = 0; i < priv->nr; i++)
829d0aeaa83SSudip Mukherjee 		if (priv->line[i] >= 0)
830d0aeaa83SSudip Mukherjee 			serial8250_resume_port(priv->line[i]);
831d0aeaa83SSudip Mukherjee 
832d0aeaa83SSudip Mukherjee 	return 0;
833d0aeaa83SSudip Mukherjee }
834d0aeaa83SSudip Mukherjee 
83582f9cefaSAndy Shevchenko static DEFINE_SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume);
836d0aeaa83SSudip Mukherjee 
837fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_2 = {
838fc6cc961SJan Kiszka 	.num_ports	= 2,
839fc6cc961SJan Kiszka 	.setup		= pci_fastcom335_setup,
840fc6cc961SJan Kiszka };
841fc6cc961SJan Kiszka 
842fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_4 = {
843fc6cc961SJan Kiszka 	.num_ports	= 4,
844fc6cc961SJan Kiszka 	.setup		= pci_fastcom335_setup,
845fc6cc961SJan Kiszka };
846fc6cc961SJan Kiszka 
847fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_8 = {
848fc6cc961SJan Kiszka 	.num_ports	= 8,
849fc6cc961SJan Kiszka 	.setup		= pci_fastcom335_setup,
850fc6cc961SJan Kiszka };
851fc6cc961SJan Kiszka 
852d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_connect = {
853d0aeaa83SSudip Mukherjee 	.setup		= pci_connect_tech_setup,
854d0aeaa83SSudip Mukherjee };
855d0aeaa83SSudip Mukherjee 
856d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_ibm_saturn = {
857d0aeaa83SSudip Mukherjee 	.num_ports	= 1,
858d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17c154_setup,
859d0aeaa83SSudip Mukherjee };
860d0aeaa83SSudip Mukherjee 
861d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17C15x = {
862d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17c154_setup,
863d0aeaa83SSudip Mukherjee };
864d0aeaa83SSudip Mukherjee 
865d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V35x = {
866d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17v35x_setup,
867d0aeaa83SSudip Mukherjee 	.exit		= pci_xr17v35x_exit,
868d0aeaa83SSudip Mukherjee };
869d0aeaa83SSudip Mukherjee 
870c6b9e95dSValmer Huhn static const struct exar8250_board pbn_fastcom35x_2 = {
871c6b9e95dSValmer Huhn 	.num_ports	= 2,
872c6b9e95dSValmer Huhn 	.setup		= pci_xr17v35x_setup,
873c6b9e95dSValmer Huhn 	.exit		= pci_xr17v35x_exit,
874c6b9e95dSValmer Huhn };
875c6b9e95dSValmer Huhn 
876c6b9e95dSValmer Huhn static const struct exar8250_board pbn_fastcom35x_4 = {
877c6b9e95dSValmer Huhn 	.num_ports	= 4,
878c6b9e95dSValmer Huhn 	.setup		= pci_xr17v35x_setup,
879c6b9e95dSValmer Huhn 	.exit		= pci_xr17v35x_exit,
880c6b9e95dSValmer Huhn };
881c6b9e95dSValmer Huhn 
882c6b9e95dSValmer Huhn static const struct exar8250_board pbn_fastcom35x_8 = {
883c6b9e95dSValmer Huhn 	.num_ports	= 8,
884c6b9e95dSValmer Huhn 	.setup		= pci_xr17v35x_setup,
885c6b9e95dSValmer Huhn 	.exit		= pci_xr17v35x_exit,
886c6b9e95dSValmer Huhn };
887c6b9e95dSValmer Huhn 
888d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V4358 = {
889d0aeaa83SSudip Mukherjee 	.num_ports	= 12,
890d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17v35x_setup,
891d0aeaa83SSudip Mukherjee 	.exit		= pci_xr17v35x_exit,
892d0aeaa83SSudip Mukherjee };
893d0aeaa83SSudip Mukherjee 
894d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V8358 = {
895d0aeaa83SSudip Mukherjee 	.num_ports	= 16,
896d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17v35x_setup,
897d0aeaa83SSudip Mukherjee 	.exit		= pci_xr17v35x_exit,
898d0aeaa83SSudip Mukherjee };
899d0aeaa83SSudip Mukherjee 
900d0aeaa83SSudip Mukherjee #define CONNECT_DEVICE(devid, sdevid, bd) {				\
901d0aeaa83SSudip Mukherjee 	PCI_DEVICE_SUB(							\
902d0aeaa83SSudip Mukherjee 		PCI_VENDOR_ID_EXAR,					\
903d0aeaa83SSudip Mukherjee 		PCI_DEVICE_ID_EXAR_##devid,				\
904d0aeaa83SSudip Mukherjee 		PCI_SUBVENDOR_ID_CONNECT_TECH,				\
905d0aeaa83SSudip Mukherjee 		PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_##sdevid), 0, 0,	\
906d0aeaa83SSudip Mukherjee 		(kernel_ulong_t)&bd					\
907d0aeaa83SSudip Mukherjee 	}
908d0aeaa83SSudip Mukherjee 
90924637007SAndy Shevchenko #define EXAR_DEVICE(vend, devid, bd) { PCI_DEVICE_DATA(vend, devid, &bd) }
910d0aeaa83SSudip Mukherjee 
911d0aeaa83SSudip Mukherjee #define IBM_DEVICE(devid, sdevid, bd) {			\
912d0aeaa83SSudip Mukherjee 	PCI_DEVICE_SUB(					\
913d0aeaa83SSudip Mukherjee 		PCI_VENDOR_ID_EXAR,			\
914d0aeaa83SSudip Mukherjee 		PCI_DEVICE_ID_EXAR_##devid,		\
915d0aeaa83SSudip Mukherjee 		PCI_VENDOR_ID_IBM,			\
916d0aeaa83SSudip Mukherjee 		PCI_SUBDEVICE_ID_IBM_##sdevid), 0, 0,	\
917d0aeaa83SSudip Mukherjee 		(kernel_ulong_t)&bd			\
918d0aeaa83SSudip Mukherjee 	}
919d0aeaa83SSudip Mukherjee 
92095d69886SAndrew Davis #define USR_DEVICE(devid, sdevid, bd) {			\
92195d69886SAndrew Davis 	PCI_DEVICE_SUB(					\
92295d69886SAndrew Davis 		PCI_VENDOR_ID_USR,			\
92395d69886SAndrew Davis 		PCI_DEVICE_ID_EXAR_##devid,		\
92495d69886SAndrew Davis 		PCI_VENDOR_ID_EXAR,			\
92595d69886SAndrew Davis 		PCI_SUBDEVICE_ID_USR_##sdevid), 0, 0,	\
92695d69886SAndrew Davis 		(kernel_ulong_t)&bd			\
92795d69886SAndrew Davis 	}
92895d69886SAndrew Davis 
9293637c460SArvind Yadav static const struct pci_device_id exar_pci_tbl[] = {
9308e4413aaSAndy Shevchenko 	EXAR_DEVICE(ACCESSIO, COM_2S, pbn_exar_XR17C15x),
9318e4413aaSAndy Shevchenko 	EXAR_DEVICE(ACCESSIO, COM_4S, pbn_exar_XR17C15x),
9328e4413aaSAndy Shevchenko 	EXAR_DEVICE(ACCESSIO, COM_8S, pbn_exar_XR17C15x),
9338e4413aaSAndy Shevchenko 	EXAR_DEVICE(ACCESSIO, COM232_8, pbn_exar_XR17C15x),
9348e4413aaSAndy Shevchenko 	EXAR_DEVICE(ACCESSIO, COM_2SM, pbn_exar_XR17C15x),
9358e4413aaSAndy Shevchenko 	EXAR_DEVICE(ACCESSIO, COM_4SM, pbn_exar_XR17C15x),
9368e4413aaSAndy Shevchenko 	EXAR_DEVICE(ACCESSIO, COM_8SM, pbn_exar_XR17C15x),
93710c5ccc3SJay Dolan 
938d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C152, UART_2_232, pbn_connect),
939d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C154, UART_4_232, pbn_connect),
940d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C158, UART_8_232, pbn_connect),
941d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C152, UART_1_1, pbn_connect),
942d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C154, UART_2_2, pbn_connect),
943d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C158, UART_4_4, pbn_connect),
944d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C152, UART_2, pbn_connect),
945d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C154, UART_4, pbn_connect),
946d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C158, UART_8, pbn_connect),
947d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C152, UART_2_485, pbn_connect),
948d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C154, UART_4_485, pbn_connect),
949d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C158, UART_8_485, pbn_connect),
950d0aeaa83SSudip Mukherjee 
951d0aeaa83SSudip Mukherjee 	IBM_DEVICE(XR17C152, SATURN_SERIAL_ONE_PORT, pbn_exar_ibm_saturn),
952d0aeaa83SSudip Mukherjee 
95395d69886SAndrew Davis 	/* USRobotics USR298x-OEM PCI Modems */
95495d69886SAndrew Davis 	USR_DEVICE(XR17C152, 2980, pbn_exar_XR17C15x),
95595d69886SAndrew Davis 	USR_DEVICE(XR17C152, 2981, pbn_exar_XR17C15x),
95695d69886SAndrew Davis 
957d0aeaa83SSudip Mukherjee 	/* Exar Corp. XR17C15[248] Dual/Quad/Octal UART */
95824637007SAndy Shevchenko 	EXAR_DEVICE(EXAR, XR17C152, pbn_exar_XR17C15x),
95924637007SAndy Shevchenko 	EXAR_DEVICE(EXAR, XR17C154, pbn_exar_XR17C15x),
96024637007SAndy Shevchenko 	EXAR_DEVICE(EXAR, XR17C158, pbn_exar_XR17C15x),
961d0aeaa83SSudip Mukherjee 
962d0aeaa83SSudip Mukherjee 	/* Exar Corp. XR17V[48]35[248] Dual/Quad/Octal/Hexa PCIe UARTs */
96324637007SAndy Shevchenko 	EXAR_DEVICE(EXAR, XR17V352, pbn_exar_XR17V35x),
96424637007SAndy Shevchenko 	EXAR_DEVICE(EXAR, XR17V354, pbn_exar_XR17V35x),
96524637007SAndy Shevchenko 	EXAR_DEVICE(EXAR, XR17V358, pbn_exar_XR17V35x),
96624637007SAndy Shevchenko 	EXAR_DEVICE(EXAR, XR17V4358, pbn_exar_XR17V4358),
96724637007SAndy Shevchenko 	EXAR_DEVICE(EXAR, XR17V8358, pbn_exar_XR17V8358),
968c6b9e95dSValmer Huhn 	EXAR_DEVICE(COMMTECH, 4222PCIE, pbn_fastcom35x_2),
969c6b9e95dSValmer Huhn 	EXAR_DEVICE(COMMTECH, 4224PCIE, pbn_fastcom35x_4),
970c6b9e95dSValmer Huhn 	EXAR_DEVICE(COMMTECH, 4228PCIE, pbn_fastcom35x_8),
971fc6cc961SJan Kiszka 
97224637007SAndy Shevchenko 	EXAR_DEVICE(COMMTECH, 4222PCI335, pbn_fastcom335_2),
97324637007SAndy Shevchenko 	EXAR_DEVICE(COMMTECH, 4224PCI335, pbn_fastcom335_4),
97424637007SAndy Shevchenko 	EXAR_DEVICE(COMMTECH, 2324PCI335, pbn_fastcom335_4),
97524637007SAndy Shevchenko 	EXAR_DEVICE(COMMTECH, 2328PCI335, pbn_fastcom335_8),
976d0aeaa83SSudip Mukherjee 	{ 0, }
977d0aeaa83SSudip Mukherjee };
978d0aeaa83SSudip Mukherjee MODULE_DEVICE_TABLE(pci, exar_pci_tbl);
979d0aeaa83SSudip Mukherjee 
980d0aeaa83SSudip Mukherjee static struct pci_driver exar_pci_driver = {
981d0aeaa83SSudip Mukherjee 	.name		= "exar_serial",
982d0aeaa83SSudip Mukherjee 	.probe		= exar_pci_probe,
983d0aeaa83SSudip Mukherjee 	.remove		= exar_pci_remove,
984d0aeaa83SSudip Mukherjee 	.driver         = {
98582f9cefaSAndy Shevchenko 		.pm     = pm_sleep_ptr(&exar_pci_pm),
986d0aeaa83SSudip Mukherjee 	},
987d0aeaa83SSudip Mukherjee 	.id_table	= exar_pci_tbl,
988d0aeaa83SSudip Mukherjee };
989d0aeaa83SSudip Mukherjee module_pci_driver(exar_pci_driver);
990d0aeaa83SSudip Mukherjee 
991d813d900SAndy Shevchenko MODULE_IMPORT_NS(SERIAL_8250_PCI);
992d0aeaa83SSudip Mukherjee MODULE_LICENSE("GPL");
9932b57b7ffSAndy Shevchenko MODULE_DESCRIPTION("Exar Serial Driver");
994d0aeaa83SSudip Mukherjee MODULE_AUTHOR("Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>");
995