xref: /linux/drivers/tty/serial/8250/8250_exar.c (revision ef4e281ecccd5bc824a52a4b1e8fbdff3614c852)
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  */
94076cf08SJan Kiszka #include <linux/acpi.h>
10413058dfSJan Kiszka #include <linux/dmi.h>
11d0aeaa83SSudip Mukherjee #include <linux/io.h>
12d0aeaa83SSudip Mukherjee #include <linux/kernel.h>
13d0aeaa83SSudip Mukherjee #include <linux/module.h>
14d0aeaa83SSudip Mukherjee #include <linux/pci.h>
15380b1e2fSJan Kiszka #include <linux/property.h>
16d0aeaa83SSudip Mukherjee #include <linux/serial_core.h>
17d0aeaa83SSudip Mukherjee #include <linux/serial_reg.h>
18d0aeaa83SSudip Mukherjee #include <linux/slab.h>
19d0aeaa83SSudip Mukherjee #include <linux/string.h>
20d0aeaa83SSudip Mukherjee #include <linux/tty.h>
21d0aeaa83SSudip Mukherjee #include <linux/8250_pci.h>
22d0aeaa83SSudip Mukherjee 
23d0aeaa83SSudip Mukherjee #include <asm/byteorder.h>
24d0aeaa83SSudip Mukherjee 
25d0aeaa83SSudip Mukherjee #include "8250.h"
26d0aeaa83SSudip Mukherjee 
27fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_4224PCI335	0x0002
28fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_4222PCI335	0x0004
29fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_2324PCI335	0x000a
30fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_2328PCI335	0x000b
31d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_COMMTECH_4224PCIE		0x0020
32d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_COMMTECH_4228PCIE		0x0021
33d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_COMMTECH_4222PCIE		0x0022
34d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_EXAR_XR17V4358		0x4358
35d0aeaa83SSudip Mukherjee #define PCI_DEVICE_ID_EXAR_XR17V8358		0x8358
36d0aeaa83SSudip Mukherjee 
37c7e1b405SAaron Sierra #define UART_EXAR_INT0		0x80
387e12357eSJan Kiszka #define UART_EXAR_8XMODE	0x88	/* 8X sampling rate select */
39*ef4e281eSAndy Shevchenko #define UART_EXAR_SLEEP		0x8b	/* Sleep mode */
406be254c2SAndy Shevchenko #define UART_EXAR_DVID		0x8d	/* Device identification */
417e12357eSJan Kiszka 
427e12357eSJan Kiszka #define UART_EXAR_FCTR		0x08	/* Feature Control Register */
437e12357eSJan Kiszka #define UART_FCTR_EXAR_IRDA	0x10	/* IrDa data encode select */
447e12357eSJan Kiszka #define UART_FCTR_EXAR_485	0x20	/* Auto 485 half duplex dir ctl */
457e12357eSJan Kiszka #define UART_FCTR_EXAR_TRGA	0x00	/* FIFO trigger table A */
467e12357eSJan Kiszka #define UART_FCTR_EXAR_TRGB	0x60	/* FIFO trigger table B */
477e12357eSJan Kiszka #define UART_FCTR_EXAR_TRGC	0x80	/* FIFO trigger table C */
487e12357eSJan Kiszka #define UART_FCTR_EXAR_TRGD	0xc0	/* FIFO trigger table D programmable */
497e12357eSJan Kiszka 
507e12357eSJan Kiszka #define UART_EXAR_TXTRG		0x0a	/* Tx FIFO trigger level write-only */
517e12357eSJan Kiszka #define UART_EXAR_RXTRG		0x0b	/* Rx FIFO trigger level write-only */
527e12357eSJan Kiszka 
53d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINT_7_0	0x8f	/* MPIOINT[7:0] */
54d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOLVL_7_0	0x90	/* MPIOLVL[7:0] */
55d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIO3T_7_0	0x91	/* MPIO3T[7:0] */
56d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINV_7_0	0x92	/* MPIOINV[7:0] */
57d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOSEL_7_0	0x93	/* MPIOSEL[7:0] */
58d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOOD_7_0	0x94	/* MPIOOD[7:0] */
59d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINT_15_8	0x95	/* MPIOINT[15:8] */
60d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOLVL_15_8	0x96	/* MPIOLVL[15:8] */
61d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIO3T_15_8	0x97	/* MPIO3T[15:8] */
62d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINV_15_8	0x98	/* MPIOINV[15:8] */
63d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOSEL_15_8	0x99	/* MPIOSEL[15:8] */
64d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOOD_15_8	0x9a	/* MPIOOD[15:8] */
65d0aeaa83SSudip Mukherjee 
66413058dfSJan Kiszka #define UART_EXAR_RS485_DLY(x)	((x) << 4)
67413058dfSJan Kiszka 
68413058dfSJan Kiszka /*
69413058dfSJan Kiszka  * IOT2040 MPIO wiring semantics:
70413058dfSJan Kiszka  *
71413058dfSJan Kiszka  * MPIO		Port	Function
72413058dfSJan Kiszka  * ----		----	--------
73413058dfSJan Kiszka  * 0		2 	Mode bit 0
74413058dfSJan Kiszka  * 1		2	Mode bit 1
75413058dfSJan Kiszka  * 2		2	Terminate bus
76413058dfSJan Kiszka  * 3		-	<reserved>
77413058dfSJan Kiszka  * 4		3	Mode bit 0
78413058dfSJan Kiszka  * 5		3	Mode bit 1
79413058dfSJan Kiszka  * 6		3	Terminate bus
80413058dfSJan Kiszka  * 7		-	<reserved>
81413058dfSJan Kiszka  * 8		2	Enable
82413058dfSJan Kiszka  * 9		3	Enable
83413058dfSJan Kiszka  * 10		-	Red LED
84413058dfSJan Kiszka  * 11..15	-	<unused>
85413058dfSJan Kiszka  */
86413058dfSJan Kiszka 
87413058dfSJan Kiszka /* IOT2040 MPIOs 0..7 */
88413058dfSJan Kiszka #define IOT2040_UART_MODE_RS232		0x01
89413058dfSJan Kiszka #define IOT2040_UART_MODE_RS485		0x02
90413058dfSJan Kiszka #define IOT2040_UART_MODE_RS422		0x03
91413058dfSJan Kiszka #define IOT2040_UART_TERMINATE_BUS	0x04
92413058dfSJan Kiszka 
93413058dfSJan Kiszka #define IOT2040_UART1_MASK		0x0f
94413058dfSJan Kiszka #define IOT2040_UART2_SHIFT		4
95413058dfSJan Kiszka 
96413058dfSJan Kiszka #define IOT2040_UARTS_DEFAULT_MODE	0x11	/* both RS232 */
97413058dfSJan Kiszka #define IOT2040_UARTS_GPIO_LO_MODE	0x88	/* reserved pins as input */
98413058dfSJan Kiszka 
99413058dfSJan Kiszka /* IOT2040 MPIOs 8..15 */
100413058dfSJan Kiszka #define IOT2040_UARTS_ENABLE		0x03
101413058dfSJan Kiszka #define IOT2040_UARTS_GPIO_HI_MODE	0xF8	/* enable & LED as outputs */
102413058dfSJan Kiszka 
103d0aeaa83SSudip Mukherjee struct exar8250;
104d0aeaa83SSudip Mukherjee 
1050d963ebfSJan Kiszka struct exar8250_platform {
1060d963ebfSJan Kiszka 	int (*rs485_config)(struct uart_port *, struct serial_rs485 *);
1070d963ebfSJan Kiszka 	int (*register_gpio)(struct pci_dev *, struct uart_8250_port *);
1080d963ebfSJan Kiszka };
1090d963ebfSJan Kiszka 
110d0aeaa83SSudip Mukherjee /**
111d0aeaa83SSudip Mukherjee  * struct exar8250_board - board information
112d0aeaa83SSudip Mukherjee  * @num_ports: number of serial ports
113d0aeaa83SSudip Mukherjee  * @reg_shift: describes UART register mapping in PCI memory
11426f22d57SAndy Shevchenko  * @setup: quirk run at ->probe() stage
11526f22d57SAndy Shevchenko  * @exit: quirk run at ->remove() stage
116d0aeaa83SSudip Mukherjee  */
117d0aeaa83SSudip Mukherjee struct exar8250_board {
118d0aeaa83SSudip Mukherjee 	unsigned int num_ports;
119d0aeaa83SSudip Mukherjee 	unsigned int reg_shift;
120d0aeaa83SSudip Mukherjee 	int	(*setup)(struct exar8250 *, struct pci_dev *,
121d0aeaa83SSudip Mukherjee 			 struct uart_8250_port *, int);
122d0aeaa83SSudip Mukherjee 	void	(*exit)(struct pci_dev *pcidev);
123d0aeaa83SSudip Mukherjee };
124d0aeaa83SSudip Mukherjee 
125d0aeaa83SSudip Mukherjee struct exar8250 {
126d0aeaa83SSudip Mukherjee 	unsigned int		nr;
127d0aeaa83SSudip Mukherjee 	struct exar8250_board	*board;
128c7e1b405SAaron Sierra 	void __iomem		*virt;
129d0aeaa83SSudip Mukherjee 	int			line[0];
130d0aeaa83SSudip Mukherjee };
131d0aeaa83SSudip Mukherjee 
132*ef4e281eSAndy Shevchenko static void exar_pm(struct uart_port *port, unsigned int state, unsigned int old)
133*ef4e281eSAndy Shevchenko {
134*ef4e281eSAndy Shevchenko 	/*
135*ef4e281eSAndy Shevchenko 	 * Exar UARTs have a SLEEP register that enables or disables each UART
136*ef4e281eSAndy Shevchenko 	 * to enter sleep mode separately. On the XR17V35x the register
137*ef4e281eSAndy Shevchenko 	 * is accessible to each UART at the UART_EXAR_SLEEP offset, but
138*ef4e281eSAndy Shevchenko 	 * the UART channel may only write to the corresponding bit.
139*ef4e281eSAndy Shevchenko 	 */
140*ef4e281eSAndy Shevchenko 	serial_port_out(port, UART_EXAR_SLEEP, state ? 0xff : 0);
141*ef4e281eSAndy Shevchenko }
142*ef4e281eSAndy Shevchenko 
143d0aeaa83SSudip Mukherjee static int default_setup(struct exar8250 *priv, struct pci_dev *pcidev,
144d0aeaa83SSudip Mukherjee 			 int idx, unsigned int offset,
145d0aeaa83SSudip Mukherjee 			 struct uart_8250_port *port)
146d0aeaa83SSudip Mukherjee {
147d0aeaa83SSudip Mukherjee 	const struct exar8250_board *board = priv->board;
148d0aeaa83SSudip Mukherjee 	unsigned int bar = 0;
1496be254c2SAndy Shevchenko 	unsigned char status;
150d0aeaa83SSudip Mukherjee 
151d0aeaa83SSudip Mukherjee 	port->port.iotype = UPIO_MEM;
152d0aeaa83SSudip Mukherjee 	port->port.mapbase = pci_resource_start(pcidev, bar) + offset;
153c7e1b405SAaron Sierra 	port->port.membase = priv->virt + offset;
154d0aeaa83SSudip Mukherjee 	port->port.regshift = board->reg_shift;
155d0aeaa83SSudip Mukherjee 
1566be254c2SAndy Shevchenko 	/*
1576be254c2SAndy Shevchenko 	 * XR17V35x UARTs have an extra divisor register, DLD that gets enabled
1586be254c2SAndy Shevchenko 	 * with when DLAB is set which will cause the device to incorrectly match
1596be254c2SAndy Shevchenko 	 * and assign port type to PORT_16650. The EFR for this UART is found
1606be254c2SAndy Shevchenko 	 * at offset 0x09. Instead check the Deice ID (DVID) register
1616be254c2SAndy Shevchenko 	 * for a 2, 4 or 8 port UART.
1626be254c2SAndy Shevchenko 	 */
1636be254c2SAndy Shevchenko 	status = readb(port->port.membase + UART_EXAR_DVID);
1646be254c2SAndy Shevchenko 	if (status == 0x82 || status == 0x84 || status == 0x88) {
1656be254c2SAndy Shevchenko 		port->port.type = PORT_XR17V35X;
1666be254c2SAndy Shevchenko 	} else {
1676be254c2SAndy Shevchenko 		port->port.type = PORT_XR17D15X;
1686be254c2SAndy Shevchenko 	}
1696be254c2SAndy Shevchenko 
170*ef4e281eSAndy Shevchenko 	port->port.pm = exar_pm;
171*ef4e281eSAndy Shevchenko 
172d0aeaa83SSudip Mukherjee 	return 0;
173d0aeaa83SSudip Mukherjee }
174d0aeaa83SSudip Mukherjee 
175d0aeaa83SSudip Mukherjee static int
176fc6cc961SJan Kiszka pci_fastcom335_setup(struct exar8250 *priv, struct pci_dev *pcidev,
177fc6cc961SJan Kiszka 		     struct uart_8250_port *port, int idx)
178fc6cc961SJan Kiszka {
179fc6cc961SJan Kiszka 	unsigned int offset = idx * 0x200;
180fc6cc961SJan Kiszka 	unsigned int baud = 1843200;
181fc6cc961SJan Kiszka 	u8 __iomem *p;
182fc6cc961SJan Kiszka 	int err;
183fc6cc961SJan Kiszka 
184fc6cc961SJan Kiszka 	port->port.uartclk = baud * 16;
185fc6cc961SJan Kiszka 
186fc6cc961SJan Kiszka 	err = default_setup(priv, pcidev, idx, offset, port);
187fc6cc961SJan Kiszka 	if (err)
188fc6cc961SJan Kiszka 		return err;
189fc6cc961SJan Kiszka 
190fc6cc961SJan Kiszka 	p = port->port.membase;
191fc6cc961SJan Kiszka 
192fc6cc961SJan Kiszka 	writeb(0x00, p + UART_EXAR_8XMODE);
193fc6cc961SJan Kiszka 	writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR);
194fc6cc961SJan Kiszka 	writeb(32, p + UART_EXAR_TXTRG);
195fc6cc961SJan Kiszka 	writeb(32, p + UART_EXAR_RXTRG);
196fc6cc961SJan Kiszka 
197fc6cc961SJan Kiszka 	/*
198fc6cc961SJan Kiszka 	 * Setup Multipurpose Input/Output pins.
199fc6cc961SJan Kiszka 	 */
200fc6cc961SJan Kiszka 	if (idx == 0) {
201fc6cc961SJan Kiszka 		switch (pcidev->device) {
202fc6cc961SJan Kiszka 		case PCI_DEVICE_ID_COMMTECH_4222PCI335:
203fc6cc961SJan Kiszka 		case PCI_DEVICE_ID_COMMTECH_4224PCI335:
204fc6cc961SJan Kiszka 			writeb(0x78, p + UART_EXAR_MPIOLVL_7_0);
205fc6cc961SJan Kiszka 			writeb(0x00, p + UART_EXAR_MPIOINV_7_0);
206fc6cc961SJan Kiszka 			writeb(0x00, p + UART_EXAR_MPIOSEL_7_0);
207fc6cc961SJan Kiszka 			break;
208fc6cc961SJan Kiszka 		case PCI_DEVICE_ID_COMMTECH_2324PCI335:
209fc6cc961SJan Kiszka 		case PCI_DEVICE_ID_COMMTECH_2328PCI335:
210fc6cc961SJan Kiszka 			writeb(0x00, p + UART_EXAR_MPIOLVL_7_0);
211fc6cc961SJan Kiszka 			writeb(0xc0, p + UART_EXAR_MPIOINV_7_0);
212fc6cc961SJan Kiszka 			writeb(0xc0, p + UART_EXAR_MPIOSEL_7_0);
213fc6cc961SJan Kiszka 			break;
214fc6cc961SJan Kiszka 		}
215fc6cc961SJan Kiszka 		writeb(0x00, p + UART_EXAR_MPIOINT_7_0);
216fc6cc961SJan Kiszka 		writeb(0x00, p + UART_EXAR_MPIO3T_7_0);
217fc6cc961SJan Kiszka 		writeb(0x00, p + UART_EXAR_MPIOOD_7_0);
218fc6cc961SJan Kiszka 	}
219fc6cc961SJan Kiszka 
220fc6cc961SJan Kiszka 	return 0;
221fc6cc961SJan Kiszka }
222fc6cc961SJan Kiszka 
223fc6cc961SJan Kiszka static int
224d0aeaa83SSudip Mukherjee pci_connect_tech_setup(struct exar8250 *priv, struct pci_dev *pcidev,
225d0aeaa83SSudip Mukherjee 		       struct uart_8250_port *port, int idx)
226d0aeaa83SSudip Mukherjee {
227d0aeaa83SSudip Mukherjee 	unsigned int offset = idx * 0x200;
228d0aeaa83SSudip Mukherjee 	unsigned int baud = 1843200;
229d0aeaa83SSudip Mukherjee 
230d0aeaa83SSudip Mukherjee 	port->port.uartclk = baud * 16;
231d0aeaa83SSudip Mukherjee 	return default_setup(priv, pcidev, idx, offset, port);
232d0aeaa83SSudip Mukherjee }
233d0aeaa83SSudip Mukherjee 
234d0aeaa83SSudip Mukherjee static int
235d0aeaa83SSudip Mukherjee pci_xr17c154_setup(struct exar8250 *priv, struct pci_dev *pcidev,
236d0aeaa83SSudip Mukherjee 		   struct uart_8250_port *port, int idx)
237d0aeaa83SSudip Mukherjee {
238d0aeaa83SSudip Mukherjee 	unsigned int offset = idx * 0x200;
239d0aeaa83SSudip Mukherjee 	unsigned int baud = 921600;
240d0aeaa83SSudip Mukherjee 
241d0aeaa83SSudip Mukherjee 	port->port.uartclk = baud * 16;
242d0aeaa83SSudip Mukherjee 	return default_setup(priv, pcidev, idx, offset, port);
243d0aeaa83SSudip Mukherjee }
244d0aeaa83SSudip Mukherjee 
245bea8be65SJan Kiszka static void setup_gpio(struct pci_dev *pcidev, u8 __iomem *p)
246d0aeaa83SSudip Mukherjee {
247bea8be65SJan Kiszka 	/*
248bea8be65SJan Kiszka 	 * The Commtech adapters required the MPIOs to be driven low. The Exar
249bea8be65SJan Kiszka 	 * devices will export them as GPIOs, so we pre-configure them safely
250bea8be65SJan Kiszka 	 * as inputs.
251bea8be65SJan Kiszka 	 */
252bea8be65SJan Kiszka 	u8 dir = pcidev->vendor == PCI_VENDOR_ID_EXAR ? 0xff : 0x00;
253bea8be65SJan Kiszka 
254d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOINT_7_0);
255d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOLVL_7_0);
256d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIO3T_7_0);
257d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOINV_7_0);
258bea8be65SJan Kiszka 	writeb(dir,  p + UART_EXAR_MPIOSEL_7_0);
259d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOOD_7_0);
260d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOINT_15_8);
261d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOLVL_15_8);
262d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIO3T_15_8);
263d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOINV_15_8);
264bea8be65SJan Kiszka 	writeb(dir,  p + UART_EXAR_MPIOSEL_15_8);
265d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_MPIOOD_15_8);
266d0aeaa83SSudip Mukherjee }
267d0aeaa83SSudip Mukherjee 
268d0aeaa83SSudip Mukherjee static void *
269380b1e2fSJan Kiszka __xr17v35x_register_gpio(struct pci_dev *pcidev,
270380b1e2fSJan Kiszka 			 const struct property_entry *properties)
271d0aeaa83SSudip Mukherjee {
272d0aeaa83SSudip Mukherjee 	struct platform_device *pdev;
273d0aeaa83SSudip Mukherjee 
274d0aeaa83SSudip Mukherjee 	pdev = platform_device_alloc("gpio_exar", PLATFORM_DEVID_AUTO);
275d0aeaa83SSudip Mukherjee 	if (!pdev)
276d0aeaa83SSudip Mukherjee 		return NULL;
277d0aeaa83SSudip Mukherjee 
278d3936d74SJan Kiszka 	pdev->dev.parent = &pcidev->dev;
2794076cf08SJan Kiszka 	ACPI_COMPANION_SET(&pdev->dev, ACPI_COMPANION(&pcidev->dev));
280d3936d74SJan Kiszka 
281380b1e2fSJan Kiszka 	if (platform_device_add_properties(pdev, properties) < 0 ||
282380b1e2fSJan Kiszka 	    platform_device_add(pdev) < 0) {
283d0aeaa83SSudip Mukherjee 		platform_device_put(pdev);
284d0aeaa83SSudip Mukherjee 		return NULL;
285d0aeaa83SSudip Mukherjee 	}
286d0aeaa83SSudip Mukherjee 
287d0aeaa83SSudip Mukherjee 	return pdev;
288d0aeaa83SSudip Mukherjee }
289d0aeaa83SSudip Mukherjee 
290380b1e2fSJan Kiszka static const struct property_entry exar_gpio_properties[] = {
291a589e211SJan Kiszka 	PROPERTY_ENTRY_U32("exar,first-pin", 0),
292380b1e2fSJan Kiszka 	PROPERTY_ENTRY_U32("ngpios", 16),
293380b1e2fSJan Kiszka 	{ }
294380b1e2fSJan Kiszka };
295380b1e2fSJan Kiszka 
2960d963ebfSJan Kiszka static int xr17v35x_register_gpio(struct pci_dev *pcidev,
2970d963ebfSJan Kiszka 				  struct uart_8250_port *port)
2980d963ebfSJan Kiszka {
2990d963ebfSJan Kiszka 	if (pcidev->vendor == PCI_VENDOR_ID_EXAR)
3000d963ebfSJan Kiszka 		port->port.private_data =
301380b1e2fSJan Kiszka 			__xr17v35x_register_gpio(pcidev, exar_gpio_properties);
3020d963ebfSJan Kiszka 
3030d963ebfSJan Kiszka 	return 0;
3040d963ebfSJan Kiszka }
3050d963ebfSJan Kiszka 
3069d939894SDaniel Golle static int generic_rs485_config(struct uart_port *port,
3079d939894SDaniel Golle 				struct serial_rs485 *rs485)
3089d939894SDaniel Golle {
3099d939894SDaniel Golle 	bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
3109d939894SDaniel Golle 	u8 __iomem *p = port->membase;
3119d939894SDaniel Golle 	u8 value;
3129d939894SDaniel Golle 
3139d939894SDaniel Golle 	value = readb(p + UART_EXAR_FCTR);
3149d939894SDaniel Golle 	if (is_rs485)
3159d939894SDaniel Golle 		value |= UART_FCTR_EXAR_485;
3169d939894SDaniel Golle 	else
3179d939894SDaniel Golle 		value &= ~UART_FCTR_EXAR_485;
3189d939894SDaniel Golle 
3199d939894SDaniel Golle 	writeb(value, p + UART_EXAR_FCTR);
3209d939894SDaniel Golle 
3219d939894SDaniel Golle 	if (is_rs485)
3229d939894SDaniel Golle 		writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR);
3239d939894SDaniel Golle 
3249d939894SDaniel Golle 	port->rs485 = *rs485;
3259d939894SDaniel Golle 
3269d939894SDaniel Golle 	return 0;
3279d939894SDaniel Golle }
3289d939894SDaniel Golle 
3290d963ebfSJan Kiszka static const struct exar8250_platform exar8250_default_platform = {
3300d963ebfSJan Kiszka 	.register_gpio = xr17v35x_register_gpio,
3319d939894SDaniel Golle 	.rs485_config = generic_rs485_config,
3320d963ebfSJan Kiszka };
3330d963ebfSJan Kiszka 
334413058dfSJan Kiszka static int iot2040_rs485_config(struct uart_port *port,
335413058dfSJan Kiszka 				struct serial_rs485 *rs485)
336413058dfSJan Kiszka {
337413058dfSJan Kiszka 	bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
338413058dfSJan Kiszka 	u8 __iomem *p = port->membase;
339413058dfSJan Kiszka 	u8 mask = IOT2040_UART1_MASK;
340413058dfSJan Kiszka 	u8 mode, value;
341413058dfSJan Kiszka 
342413058dfSJan Kiszka 	if (is_rs485) {
343413058dfSJan Kiszka 		if (rs485->flags & SER_RS485_RX_DURING_TX)
344413058dfSJan Kiszka 			mode = IOT2040_UART_MODE_RS422;
345413058dfSJan Kiszka 		else
346413058dfSJan Kiszka 			mode = IOT2040_UART_MODE_RS485;
347413058dfSJan Kiszka 
348413058dfSJan Kiszka 		if (rs485->flags & SER_RS485_TERMINATE_BUS)
349413058dfSJan Kiszka 			mode |= IOT2040_UART_TERMINATE_BUS;
350413058dfSJan Kiszka 	} else {
351413058dfSJan Kiszka 		mode = IOT2040_UART_MODE_RS232;
352413058dfSJan Kiszka 	}
353413058dfSJan Kiszka 
354413058dfSJan Kiszka 	if (port->line == 3) {
355413058dfSJan Kiszka 		mask <<= IOT2040_UART2_SHIFT;
356413058dfSJan Kiszka 		mode <<= IOT2040_UART2_SHIFT;
357413058dfSJan Kiszka 	}
358413058dfSJan Kiszka 
359413058dfSJan Kiszka 	value = readb(p + UART_EXAR_MPIOLVL_7_0);
360413058dfSJan Kiszka 	value &= ~mask;
361413058dfSJan Kiszka 	value |= mode;
362413058dfSJan Kiszka 	writeb(value, p + UART_EXAR_MPIOLVL_7_0);
363413058dfSJan Kiszka 
3649d939894SDaniel Golle 	return generic_rs485_config(port, rs485);
365413058dfSJan Kiszka }
366413058dfSJan Kiszka 
367413058dfSJan Kiszka static const struct property_entry iot2040_gpio_properties[] = {
368a589e211SJan Kiszka 	PROPERTY_ENTRY_U32("exar,first-pin", 10),
369413058dfSJan Kiszka 	PROPERTY_ENTRY_U32("ngpios", 1),
370413058dfSJan Kiszka 	{ }
371413058dfSJan Kiszka };
372413058dfSJan Kiszka 
373413058dfSJan Kiszka static int iot2040_register_gpio(struct pci_dev *pcidev,
374413058dfSJan Kiszka 			      struct uart_8250_port *port)
375413058dfSJan Kiszka {
376413058dfSJan Kiszka 	u8 __iomem *p = port->port.membase;
377413058dfSJan Kiszka 
378413058dfSJan Kiszka 	writeb(IOT2040_UARTS_DEFAULT_MODE, p + UART_EXAR_MPIOLVL_7_0);
379413058dfSJan Kiszka 	writeb(IOT2040_UARTS_GPIO_LO_MODE, p + UART_EXAR_MPIOSEL_7_0);
380413058dfSJan Kiszka 	writeb(IOT2040_UARTS_ENABLE, p + UART_EXAR_MPIOLVL_15_8);
381413058dfSJan Kiszka 	writeb(IOT2040_UARTS_GPIO_HI_MODE, p + UART_EXAR_MPIOSEL_15_8);
382413058dfSJan Kiszka 
383413058dfSJan Kiszka 	port->port.private_data =
384413058dfSJan Kiszka 		__xr17v35x_register_gpio(pcidev, iot2040_gpio_properties);
385413058dfSJan Kiszka 
386413058dfSJan Kiszka 	return 0;
387413058dfSJan Kiszka }
388413058dfSJan Kiszka 
389413058dfSJan Kiszka static const struct exar8250_platform iot2040_platform = {
390413058dfSJan Kiszka 	.rs485_config = iot2040_rs485_config,
391413058dfSJan Kiszka 	.register_gpio = iot2040_register_gpio,
392413058dfSJan Kiszka };
393413058dfSJan Kiszka 
3943e51ceeaSSu Bao Cheng /*
3953e51ceeaSSu Bao Cheng  * For SIMATIC IOT2000, only IOT2040 and its variants have the Exar device,
3963e51ceeaSSu Bao Cheng  * IOT2020 doesn't have. Therefore it is sufficient to match on the common
3973e51ceeaSSu Bao Cheng  * board name after the device was found.
3983e51ceeaSSu Bao Cheng  */
399413058dfSJan Kiszka static const struct dmi_system_id exar_platforms[] = {
400413058dfSJan Kiszka 	{
401413058dfSJan Kiszka 		.matches = {
402413058dfSJan Kiszka 			DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"),
403413058dfSJan Kiszka 		},
404413058dfSJan Kiszka 		.driver_data = (void *)&iot2040_platform,
405413058dfSJan Kiszka 	},
406413058dfSJan Kiszka 	{}
407413058dfSJan Kiszka };
408413058dfSJan Kiszka 
409d0aeaa83SSudip Mukherjee static int
410d0aeaa83SSudip Mukherjee pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev,
411d0aeaa83SSudip Mukherjee 		   struct uart_8250_port *port, int idx)
412d0aeaa83SSudip Mukherjee {
4130d963ebfSJan Kiszka 	const struct exar8250_platform *platform;
414413058dfSJan Kiszka 	const struct dmi_system_id *dmi_match;
415d0aeaa83SSudip Mukherjee 	unsigned int offset = idx * 0x400;
416d0aeaa83SSudip Mukherjee 	unsigned int baud = 7812500;
417d0aeaa83SSudip Mukherjee 	u8 __iomem *p;
418d0aeaa83SSudip Mukherjee 	int ret;
419d0aeaa83SSudip Mukherjee 
420413058dfSJan Kiszka 	dmi_match = dmi_first_match(exar_platforms);
421413058dfSJan Kiszka 	if (dmi_match)
422413058dfSJan Kiszka 		platform = dmi_match->driver_data;
423413058dfSJan Kiszka 	else
4240d963ebfSJan Kiszka 		platform = &exar8250_default_platform;
4250d963ebfSJan Kiszka 
426d0aeaa83SSudip Mukherjee 	port->port.uartclk = baud * 16;
4270d963ebfSJan Kiszka 	port->port.rs485_config = platform->rs485_config;
4280d963ebfSJan Kiszka 
429d0aeaa83SSudip Mukherjee 	/*
430328c11f2SAndy Shevchenko 	 * Setup the UART clock for the devices on expansion slot to
431d0aeaa83SSudip Mukherjee 	 * half the clock speed of the main chip (which is 125MHz)
432d0aeaa83SSudip Mukherjee 	 */
433328c11f2SAndy Shevchenko 	if (idx >= 8)
434d0aeaa83SSudip Mukherjee 		port->port.uartclk /= 2;
435d0aeaa83SSudip Mukherjee 
4365b5f252dSJan Kiszka 	ret = default_setup(priv, pcidev, idx, offset, port);
4375b5f252dSJan Kiszka 	if (ret)
4385b5f252dSJan Kiszka 		return ret;
439d0aeaa83SSudip Mukherjee 
4405b5f252dSJan Kiszka 	p = port->port.membase;
441d0aeaa83SSudip Mukherjee 
442d0aeaa83SSudip Mukherjee 	writeb(0x00, p + UART_EXAR_8XMODE);
443d0aeaa83SSudip Mukherjee 	writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR);
444d0aeaa83SSudip Mukherjee 	writeb(128, p + UART_EXAR_TXTRG);
445d0aeaa83SSudip Mukherjee 	writeb(128, p + UART_EXAR_RXTRG);
446d0aeaa83SSudip Mukherjee 
4475b5f252dSJan Kiszka 	if (idx == 0) {
4485b5f252dSJan Kiszka 		/* Setup Multipurpose Input/Output pins. */
449bea8be65SJan Kiszka 		setup_gpio(pcidev, p);
450d0aeaa83SSudip Mukherjee 
4510d963ebfSJan Kiszka 		ret = platform->register_gpio(pcidev, port);
4525b5f252dSJan Kiszka 	}
453d0aeaa83SSudip Mukherjee 
4540d963ebfSJan Kiszka 	return ret;
455d0aeaa83SSudip Mukherjee }
456d0aeaa83SSudip Mukherjee 
457d0aeaa83SSudip Mukherjee static void pci_xr17v35x_exit(struct pci_dev *pcidev)
458d0aeaa83SSudip Mukherjee {
459d0aeaa83SSudip Mukherjee 	struct exar8250 *priv = pci_get_drvdata(pcidev);
460d0aeaa83SSudip Mukherjee 	struct uart_8250_port *port = serial8250_get_port(priv->line[0]);
461d0aeaa83SSudip Mukherjee 	struct platform_device *pdev = port->port.private_data;
462d0aeaa83SSudip Mukherjee 
463d0aeaa83SSudip Mukherjee 	platform_device_unregister(pdev);
464d0aeaa83SSudip Mukherjee 	port->port.private_data = NULL;
465d0aeaa83SSudip Mukherjee }
466d0aeaa83SSudip Mukherjee 
467c7e1b405SAaron Sierra /*
468c7e1b405SAaron Sierra  * These Exar UARTs have an extra interrupt indicator that could fire for a
469c7e1b405SAaron Sierra  * few interrupts that are not presented/cleared through IIR.  One of which is
470c7e1b405SAaron Sierra  * a wakeup interrupt when coming out of sleep.  These interrupts are only
471c7e1b405SAaron Sierra  * cleared by reading global INT0 or INT1 registers as interrupts are
472c7e1b405SAaron Sierra  * associated with channel 0. The INT[3:0] registers _are_ accessible from each
473c7e1b405SAaron Sierra  * channel's address space, but for the sake of bus efficiency we register a
474c7e1b405SAaron Sierra  * dedicated handler at the PCI device level to handle them.
475c7e1b405SAaron Sierra  */
476c7e1b405SAaron Sierra static irqreturn_t exar_misc_handler(int irq, void *data)
477c7e1b405SAaron Sierra {
478c7e1b405SAaron Sierra 	struct exar8250 *priv = data;
479c7e1b405SAaron Sierra 
480c7e1b405SAaron Sierra 	/* Clear all PCI interrupts by reading INT0. No effect on IIR */
48160ab0fafSAaron Sierra 	readb(priv->virt + UART_EXAR_INT0);
48260ab0fafSAaron Sierra 
48360ab0fafSAaron Sierra 	/* Clear INT0 for Expansion Interface slave ports, too */
48460ab0fafSAaron Sierra 	if (priv->board->num_ports > 8)
48560ab0fafSAaron Sierra 		readb(priv->virt + 0x2000 + UART_EXAR_INT0);
486c7e1b405SAaron Sierra 
487c7e1b405SAaron Sierra 	return IRQ_HANDLED;
488c7e1b405SAaron Sierra }
489c7e1b405SAaron Sierra 
490d0aeaa83SSudip Mukherjee static int
491d0aeaa83SSudip Mukherjee exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
492d0aeaa83SSudip Mukherjee {
493d0aeaa83SSudip Mukherjee 	unsigned int nr_ports, i, bar = 0, maxnr;
494d0aeaa83SSudip Mukherjee 	struct exar8250_board *board;
495d0aeaa83SSudip Mukherjee 	struct uart_8250_port uart;
496d0aeaa83SSudip Mukherjee 	struct exar8250 *priv;
497d0aeaa83SSudip Mukherjee 	int rc;
498d0aeaa83SSudip Mukherjee 
499d0aeaa83SSudip Mukherjee 	board = (struct exar8250_board *)ent->driver_data;
500d0aeaa83SSudip Mukherjee 	if (!board)
501d0aeaa83SSudip Mukherjee 		return -EINVAL;
502d0aeaa83SSudip Mukherjee 
503d0aeaa83SSudip Mukherjee 	rc = pcim_enable_device(pcidev);
504d0aeaa83SSudip Mukherjee 	if (rc)
505d0aeaa83SSudip Mukherjee 		return rc;
506d0aeaa83SSudip Mukherjee 
507d0aeaa83SSudip Mukherjee 	maxnr = pci_resource_len(pcidev, bar) >> (board->reg_shift + 3);
508d0aeaa83SSudip Mukherjee 
509d0aeaa83SSudip Mukherjee 	nr_ports = board->num_ports ? board->num_ports : pcidev->device & 0x0f;
510d0aeaa83SSudip Mukherjee 
511df60a8afSAndy Shevchenko 	priv = devm_kzalloc(&pcidev->dev, struct_size(priv, line, nr_ports), GFP_KERNEL);
512d0aeaa83SSudip Mukherjee 	if (!priv)
513d0aeaa83SSudip Mukherjee 		return -ENOMEM;
514d0aeaa83SSudip Mukherjee 
515d0aeaa83SSudip Mukherjee 	priv->board = board;
516c7e1b405SAaron Sierra 	priv->virt = pcim_iomap(pcidev, bar, 0);
517c7e1b405SAaron Sierra 	if (!priv->virt)
518c7e1b405SAaron Sierra 		return -ENOMEM;
519d0aeaa83SSudip Mukherjee 
520172c33cbSJan Kiszka 	pci_set_master(pcidev);
521172c33cbSJan Kiszka 
522172c33cbSJan Kiszka 	rc = pci_alloc_irq_vectors(pcidev, 1, 1, PCI_IRQ_ALL_TYPES);
523172c33cbSJan Kiszka 	if (rc < 0)
524172c33cbSJan Kiszka 		return rc;
525172c33cbSJan Kiszka 
526d0aeaa83SSudip Mukherjee 	memset(&uart, 0, sizeof(uart));
5276be254c2SAndy Shevchenko 	uart.port.flags = UPF_SHARE_IRQ | UPF_EXAR_EFR | UPF_FIXED_TYPE | UPF_FIXED_PORT;
528172c33cbSJan Kiszka 	uart.port.irq = pci_irq_vector(pcidev, 0);
529d0aeaa83SSudip Mukherjee 	uart.port.dev = &pcidev->dev;
530d0aeaa83SSudip Mukherjee 
531c7e1b405SAaron Sierra 	rc = devm_request_irq(&pcidev->dev, uart.port.irq, exar_misc_handler,
532c7e1b405SAaron Sierra 			 IRQF_SHARED, "exar_uart", priv);
533c7e1b405SAaron Sierra 	if (rc)
534c7e1b405SAaron Sierra 		return rc;
535c7e1b405SAaron Sierra 
536d0aeaa83SSudip Mukherjee 	for (i = 0; i < nr_ports && i < maxnr; i++) {
537d0aeaa83SSudip Mukherjee 		rc = board->setup(priv, pcidev, &uart, i);
538d0aeaa83SSudip Mukherjee 		if (rc) {
539d0aeaa83SSudip Mukherjee 			dev_err(&pcidev->dev, "Failed to setup port %u\n", i);
540d0aeaa83SSudip Mukherjee 			break;
541d0aeaa83SSudip Mukherjee 		}
542d0aeaa83SSudip Mukherjee 
543d0aeaa83SSudip Mukherjee 		dev_dbg(&pcidev->dev, "Setup PCI port: port %lx, irq %d, type %d\n",
544d0aeaa83SSudip Mukherjee 			uart.port.iobase, uart.port.irq, uart.port.iotype);
545d0aeaa83SSudip Mukherjee 
546d0aeaa83SSudip Mukherjee 		priv->line[i] = serial8250_register_8250_port(&uart);
547d0aeaa83SSudip Mukherjee 		if (priv->line[i] < 0) {
548d0aeaa83SSudip Mukherjee 			dev_err(&pcidev->dev,
549d0aeaa83SSudip Mukherjee 				"Couldn't register serial port %lx, irq %d, type %d, error %d\n",
550d0aeaa83SSudip Mukherjee 				uart.port.iobase, uart.port.irq,
551d0aeaa83SSudip Mukherjee 				uart.port.iotype, priv->line[i]);
552d0aeaa83SSudip Mukherjee 			break;
553d0aeaa83SSudip Mukherjee 		}
554d0aeaa83SSudip Mukherjee 	}
555d0aeaa83SSudip Mukherjee 	priv->nr = i;
556d0aeaa83SSudip Mukherjee 	pci_set_drvdata(pcidev, priv);
557d0aeaa83SSudip Mukherjee 	return 0;
558d0aeaa83SSudip Mukherjee }
559d0aeaa83SSudip Mukherjee 
560d0aeaa83SSudip Mukherjee static void exar_pci_remove(struct pci_dev *pcidev)
561d0aeaa83SSudip Mukherjee {
562d0aeaa83SSudip Mukherjee 	struct exar8250 *priv = pci_get_drvdata(pcidev);
563d0aeaa83SSudip Mukherjee 	unsigned int i;
564d0aeaa83SSudip Mukherjee 
565d0aeaa83SSudip Mukherjee 	for (i = 0; i < priv->nr; i++)
566d0aeaa83SSudip Mukherjee 		serial8250_unregister_port(priv->line[i]);
567d0aeaa83SSudip Mukherjee 
568d0aeaa83SSudip Mukherjee 	if (priv->board->exit)
569d0aeaa83SSudip Mukherjee 		priv->board->exit(pcidev);
570d0aeaa83SSudip Mukherjee }
571d0aeaa83SSudip Mukherjee 
572d0aeaa83SSudip Mukherjee static int __maybe_unused exar_suspend(struct device *dev)
573d0aeaa83SSudip Mukherjee {
574d0aeaa83SSudip Mukherjee 	struct pci_dev *pcidev = to_pci_dev(dev);
575d0aeaa83SSudip Mukherjee 	struct exar8250 *priv = pci_get_drvdata(pcidev);
576d0aeaa83SSudip Mukherjee 	unsigned int i;
577d0aeaa83SSudip Mukherjee 
578d0aeaa83SSudip Mukherjee 	for (i = 0; i < priv->nr; i++)
579d0aeaa83SSudip Mukherjee 		if (priv->line[i] >= 0)
580d0aeaa83SSudip Mukherjee 			serial8250_suspend_port(priv->line[i]);
581d0aeaa83SSudip Mukherjee 
582d0aeaa83SSudip Mukherjee 	/* Ensure that every init quirk is properly torn down */
583d0aeaa83SSudip Mukherjee 	if (priv->board->exit)
584d0aeaa83SSudip Mukherjee 		priv->board->exit(pcidev);
585d0aeaa83SSudip Mukherjee 
586d0aeaa83SSudip Mukherjee 	return 0;
587d0aeaa83SSudip Mukherjee }
588d0aeaa83SSudip Mukherjee 
589d0aeaa83SSudip Mukherjee static int __maybe_unused exar_resume(struct device *dev)
590d0aeaa83SSudip Mukherjee {
59176b4106cSChuhong Yuan 	struct exar8250 *priv = dev_get_drvdata(dev);
592d0aeaa83SSudip Mukherjee 	unsigned int i;
593d0aeaa83SSudip Mukherjee 
594d0aeaa83SSudip Mukherjee 	for (i = 0; i < priv->nr; i++)
595d0aeaa83SSudip Mukherjee 		if (priv->line[i] >= 0)
596d0aeaa83SSudip Mukherjee 			serial8250_resume_port(priv->line[i]);
597d0aeaa83SSudip Mukherjee 
598d0aeaa83SSudip Mukherjee 	return 0;
599d0aeaa83SSudip Mukherjee }
600d0aeaa83SSudip Mukherjee 
601d0aeaa83SSudip Mukherjee static SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume);
602d0aeaa83SSudip Mukherjee 
603fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_2 = {
604fc6cc961SJan Kiszka 	.num_ports	= 2,
605fc6cc961SJan Kiszka 	.setup		= pci_fastcom335_setup,
606fc6cc961SJan Kiszka };
607fc6cc961SJan Kiszka 
608fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_4 = {
609fc6cc961SJan Kiszka 	.num_ports	= 4,
610fc6cc961SJan Kiszka 	.setup		= pci_fastcom335_setup,
611fc6cc961SJan Kiszka };
612fc6cc961SJan Kiszka 
613fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_8 = {
614fc6cc961SJan Kiszka 	.num_ports	= 8,
615fc6cc961SJan Kiszka 	.setup		= pci_fastcom335_setup,
616fc6cc961SJan Kiszka };
617fc6cc961SJan Kiszka 
618d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_connect = {
619d0aeaa83SSudip Mukherjee 	.setup		= pci_connect_tech_setup,
620d0aeaa83SSudip Mukherjee };
621d0aeaa83SSudip Mukherjee 
622d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_ibm_saturn = {
623d0aeaa83SSudip Mukherjee 	.num_ports	= 1,
624d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17c154_setup,
625d0aeaa83SSudip Mukherjee };
626d0aeaa83SSudip Mukherjee 
627d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17C15x = {
628d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17c154_setup,
629d0aeaa83SSudip Mukherjee };
630d0aeaa83SSudip Mukherjee 
631d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V35x = {
632d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17v35x_setup,
633d0aeaa83SSudip Mukherjee 	.exit		= pci_xr17v35x_exit,
634d0aeaa83SSudip Mukherjee };
635d0aeaa83SSudip Mukherjee 
636d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V4358 = {
637d0aeaa83SSudip Mukherjee 	.num_ports	= 12,
638d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17v35x_setup,
639d0aeaa83SSudip Mukherjee 	.exit		= pci_xr17v35x_exit,
640d0aeaa83SSudip Mukherjee };
641d0aeaa83SSudip Mukherjee 
642d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V8358 = {
643d0aeaa83SSudip Mukherjee 	.num_ports	= 16,
644d0aeaa83SSudip Mukherjee 	.setup		= pci_xr17v35x_setup,
645d0aeaa83SSudip Mukherjee 	.exit		= pci_xr17v35x_exit,
646d0aeaa83SSudip Mukherjee };
647d0aeaa83SSudip Mukherjee 
648d0aeaa83SSudip Mukherjee #define CONNECT_DEVICE(devid, sdevid, bd) {				\
649d0aeaa83SSudip Mukherjee 	PCI_DEVICE_SUB(							\
650d0aeaa83SSudip Mukherjee 		PCI_VENDOR_ID_EXAR,					\
651d0aeaa83SSudip Mukherjee 		PCI_DEVICE_ID_EXAR_##devid,				\
652d0aeaa83SSudip Mukherjee 		PCI_SUBVENDOR_ID_CONNECT_TECH,				\
653d0aeaa83SSudip Mukherjee 		PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_##sdevid), 0, 0,	\
654d0aeaa83SSudip Mukherjee 		(kernel_ulong_t)&bd					\
655d0aeaa83SSudip Mukherjee 	}
656d0aeaa83SSudip Mukherjee 
657d0aeaa83SSudip Mukherjee #define EXAR_DEVICE(vend, devid, bd) {					\
658d0aeaa83SSudip Mukherjee 	PCI_VDEVICE(vend, PCI_DEVICE_ID_##devid), (kernel_ulong_t)&bd	\
659d0aeaa83SSudip Mukherjee 	}
660d0aeaa83SSudip Mukherjee 
661d0aeaa83SSudip Mukherjee #define IBM_DEVICE(devid, sdevid, bd) {			\
662d0aeaa83SSudip Mukherjee 	PCI_DEVICE_SUB(					\
663d0aeaa83SSudip Mukherjee 		PCI_VENDOR_ID_EXAR,			\
664d0aeaa83SSudip Mukherjee 		PCI_DEVICE_ID_EXAR_##devid,		\
665d0aeaa83SSudip Mukherjee 		PCI_VENDOR_ID_IBM,			\
666d0aeaa83SSudip Mukherjee 		PCI_SUBDEVICE_ID_IBM_##sdevid), 0, 0,	\
667d0aeaa83SSudip Mukherjee 		(kernel_ulong_t)&bd			\
668d0aeaa83SSudip Mukherjee 	}
669d0aeaa83SSudip Mukherjee 
6703637c460SArvind Yadav static const struct pci_device_id exar_pci_tbl[] = {
671d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C152, UART_2_232, pbn_connect),
672d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C154, UART_4_232, pbn_connect),
673d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C158, UART_8_232, pbn_connect),
674d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C152, UART_1_1, pbn_connect),
675d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C154, UART_2_2, pbn_connect),
676d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C158, UART_4_4, pbn_connect),
677d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C152, UART_2, pbn_connect),
678d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C154, UART_4, pbn_connect),
679d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C158, UART_8, pbn_connect),
680d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C152, UART_2_485, pbn_connect),
681d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C154, UART_4_485, pbn_connect),
682d0aeaa83SSudip Mukherjee 	CONNECT_DEVICE(XR17C158, UART_8_485, pbn_connect),
683d0aeaa83SSudip Mukherjee 
684d0aeaa83SSudip Mukherjee 	IBM_DEVICE(XR17C152, SATURN_SERIAL_ONE_PORT, pbn_exar_ibm_saturn),
685d0aeaa83SSudip Mukherjee 
686d0aeaa83SSudip Mukherjee 	/* Exar Corp. XR17C15[248] Dual/Quad/Octal UART */
687d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(EXAR, EXAR_XR17C152, pbn_exar_XR17C15x),
688d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(EXAR, EXAR_XR17C154, pbn_exar_XR17C15x),
689d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(EXAR, EXAR_XR17C158, pbn_exar_XR17C15x),
690d0aeaa83SSudip Mukherjee 
691d0aeaa83SSudip Mukherjee 	/* Exar Corp. XR17V[48]35[248] Dual/Quad/Octal/Hexa PCIe UARTs */
692d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(EXAR, EXAR_XR17V352, pbn_exar_XR17V35x),
693d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(EXAR, EXAR_XR17V354, pbn_exar_XR17V35x),
694d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(EXAR, EXAR_XR17V358, pbn_exar_XR17V35x),
695d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(EXAR, EXAR_XR17V4358, pbn_exar_XR17V4358),
696d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(EXAR, EXAR_XR17V8358, pbn_exar_XR17V8358),
697d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(COMMTECH, COMMTECH_4222PCIE, pbn_exar_XR17V35x),
698d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(COMMTECH, COMMTECH_4224PCIE, pbn_exar_XR17V35x),
699d0aeaa83SSudip Mukherjee 	EXAR_DEVICE(COMMTECH, COMMTECH_4228PCIE, pbn_exar_XR17V35x),
700fc6cc961SJan Kiszka 
701fc6cc961SJan Kiszka 	EXAR_DEVICE(COMMTECH, COMMTECH_4222PCI335, pbn_fastcom335_2),
702fc6cc961SJan Kiszka 	EXAR_DEVICE(COMMTECH, COMMTECH_4224PCI335, pbn_fastcom335_4),
703fc6cc961SJan Kiszka 	EXAR_DEVICE(COMMTECH, COMMTECH_2324PCI335, pbn_fastcom335_4),
704fc6cc961SJan Kiszka 	EXAR_DEVICE(COMMTECH, COMMTECH_2328PCI335, pbn_fastcom335_8),
705d0aeaa83SSudip Mukherjee 	{ 0, }
706d0aeaa83SSudip Mukherjee };
707d0aeaa83SSudip Mukherjee MODULE_DEVICE_TABLE(pci, exar_pci_tbl);
708d0aeaa83SSudip Mukherjee 
709d0aeaa83SSudip Mukherjee static struct pci_driver exar_pci_driver = {
710d0aeaa83SSudip Mukherjee 	.name		= "exar_serial",
711d0aeaa83SSudip Mukherjee 	.probe		= exar_pci_probe,
712d0aeaa83SSudip Mukherjee 	.remove		= exar_pci_remove,
713d0aeaa83SSudip Mukherjee 	.driver         = {
714d0aeaa83SSudip Mukherjee 		.pm     = &exar_pci_pm,
715d0aeaa83SSudip Mukherjee 	},
716d0aeaa83SSudip Mukherjee 	.id_table	= exar_pci_tbl,
717d0aeaa83SSudip Mukherjee };
718d0aeaa83SSudip Mukherjee module_pci_driver(exar_pci_driver);
719d0aeaa83SSudip Mukherjee 
720d0aeaa83SSudip Mukherjee MODULE_LICENSE("GPL");
7212b57b7ffSAndy Shevchenko MODULE_DESCRIPTION("Exar Serial Driver");
722d0aeaa83SSudip Mukherjee MODULE_AUTHOR("Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>");
723