18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Probe module for 8250/16550-type Exar chips PCI serial ports. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Based on drivers/tty/serial/8250/8250_pci.c, 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 2017 Sudip Mukherjee, All Rights Reserved. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#include <linux/acpi.h> 108c2ecf20Sopenharmony_ci#include <linux/dmi.h> 118c2ecf20Sopenharmony_ci#include <linux/io.h> 128c2ecf20Sopenharmony_ci#include <linux/kernel.h> 138c2ecf20Sopenharmony_ci#include <linux/module.h> 148c2ecf20Sopenharmony_ci#include <linux/pci.h> 158c2ecf20Sopenharmony_ci#include <linux/property.h> 168c2ecf20Sopenharmony_ci#include <linux/serial_core.h> 178c2ecf20Sopenharmony_ci#include <linux/serial_reg.h> 188c2ecf20Sopenharmony_ci#include <linux/slab.h> 198c2ecf20Sopenharmony_ci#include <linux/string.h> 208c2ecf20Sopenharmony_ci#include <linux/tty.h> 218c2ecf20Sopenharmony_ci#include <linux/8250_pci.h> 228c2ecf20Sopenharmony_ci#include <linux/delay.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include "8250.h" 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ACCESSIO_COM_2S 0x1052 298c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ACCESSIO_COM_4S 0x105d 308c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ACCESSIO_COM_8S 0x106c 318c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ACCESSIO_COM232_8 0x10a8 328c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ACCESSIO_COM_2SM 0x10d2 338c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ACCESSIO_COM_4SM 0x10db 348c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_ACCESSIO_COM_8SM 0x10ea 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_COMMTECH_4224PCI335 0x0002 378c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_COMMTECH_4222PCI335 0x0004 388c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_COMMTECH_2324PCI335 0x000a 398c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_COMMTECH_2328PCI335 0x000b 408c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_COMMTECH_4224PCIE 0x0020 418c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_COMMTECH_4228PCIE 0x0021 428c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_COMMTECH_4222PCIE 0x0022 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_EXAR_XR17V4358 0x4358 458c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_EXAR_XR17V8358 0x8358 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define PCI_SUBDEVICE_ID_USR_2980 0x0128 488c2ecf20Sopenharmony_ci#define PCI_SUBDEVICE_ID_USR_2981 0x0129 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_SEALEVEL_710xC 0x1001 518c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_SEALEVEL_720xC 0x1002 528c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_SEALEVEL_740xC 0x1004 538c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_SEALEVEL_780xC 0x1008 548c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_SEALEVEL_716xC 0x1010 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define UART_EXAR_INT0 0x80 578c2ecf20Sopenharmony_ci#define UART_EXAR_8XMODE 0x88 /* 8X sampling rate select */ 588c2ecf20Sopenharmony_ci#define UART_EXAR_SLEEP 0x8b /* Sleep mode */ 598c2ecf20Sopenharmony_ci#define UART_EXAR_DVID 0x8d /* Device identification */ 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define UART_EXAR_FCTR 0x08 /* Feature Control Register */ 628c2ecf20Sopenharmony_ci#define UART_FCTR_EXAR_IRDA 0x10 /* IrDa data encode select */ 638c2ecf20Sopenharmony_ci#define UART_FCTR_EXAR_485 0x20 /* Auto 485 half duplex dir ctl */ 648c2ecf20Sopenharmony_ci#define UART_FCTR_EXAR_TRGA 0x00 /* FIFO trigger table A */ 658c2ecf20Sopenharmony_ci#define UART_FCTR_EXAR_TRGB 0x60 /* FIFO trigger table B */ 668c2ecf20Sopenharmony_ci#define UART_FCTR_EXAR_TRGC 0x80 /* FIFO trigger table C */ 678c2ecf20Sopenharmony_ci#define UART_FCTR_EXAR_TRGD 0xc0 /* FIFO trigger table D programmable */ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define UART_EXAR_TXTRG 0x0a /* Tx FIFO trigger level write-only */ 708c2ecf20Sopenharmony_ci#define UART_EXAR_RXTRG 0x0b /* Rx FIFO trigger level write-only */ 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOINT_7_0 0x8f /* MPIOINT[7:0] */ 738c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOLVL_7_0 0x90 /* MPIOLVL[7:0] */ 748c2ecf20Sopenharmony_ci#define UART_EXAR_MPIO3T_7_0 0x91 /* MPIO3T[7:0] */ 758c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOINV_7_0 0x92 /* MPIOINV[7:0] */ 768c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOSEL_7_0 0x93 /* MPIOSEL[7:0] */ 778c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOOD_7_0 0x94 /* MPIOOD[7:0] */ 788c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOINT_15_8 0x95 /* MPIOINT[15:8] */ 798c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOLVL_15_8 0x96 /* MPIOLVL[15:8] */ 808c2ecf20Sopenharmony_ci#define UART_EXAR_MPIO3T_15_8 0x97 /* MPIO3T[15:8] */ 818c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOINV_15_8 0x98 /* MPIOINV[15:8] */ 828c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOSEL_15_8 0x99 /* MPIOSEL[15:8] */ 838c2ecf20Sopenharmony_ci#define UART_EXAR_MPIOOD_15_8 0x9a /* MPIOOD[15:8] */ 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define UART_EXAR_RS485_DLY(x) ((x) << 4) 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* 888c2ecf20Sopenharmony_ci * IOT2040 MPIO wiring semantics: 898c2ecf20Sopenharmony_ci * 908c2ecf20Sopenharmony_ci * MPIO Port Function 918c2ecf20Sopenharmony_ci * ---- ---- -------- 928c2ecf20Sopenharmony_ci * 0 2 Mode bit 0 938c2ecf20Sopenharmony_ci * 1 2 Mode bit 1 948c2ecf20Sopenharmony_ci * 2 2 Terminate bus 958c2ecf20Sopenharmony_ci * 3 - <reserved> 968c2ecf20Sopenharmony_ci * 4 3 Mode bit 0 978c2ecf20Sopenharmony_ci * 5 3 Mode bit 1 988c2ecf20Sopenharmony_ci * 6 3 Terminate bus 998c2ecf20Sopenharmony_ci * 7 - <reserved> 1008c2ecf20Sopenharmony_ci * 8 2 Enable 1018c2ecf20Sopenharmony_ci * 9 3 Enable 1028c2ecf20Sopenharmony_ci * 10 - Red LED 1038c2ecf20Sopenharmony_ci * 11..15 - <unused> 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* IOT2040 MPIOs 0..7 */ 1078c2ecf20Sopenharmony_ci#define IOT2040_UART_MODE_RS232 0x01 1088c2ecf20Sopenharmony_ci#define IOT2040_UART_MODE_RS485 0x02 1098c2ecf20Sopenharmony_ci#define IOT2040_UART_MODE_RS422 0x03 1108c2ecf20Sopenharmony_ci#define IOT2040_UART_TERMINATE_BUS 0x04 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define IOT2040_UART1_MASK 0x0f 1138c2ecf20Sopenharmony_ci#define IOT2040_UART2_SHIFT 4 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define IOT2040_UARTS_DEFAULT_MODE 0x11 /* both RS232 */ 1168c2ecf20Sopenharmony_ci#define IOT2040_UARTS_GPIO_LO_MODE 0x88 /* reserved pins as input */ 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci/* IOT2040 MPIOs 8..15 */ 1198c2ecf20Sopenharmony_ci#define IOT2040_UARTS_ENABLE 0x03 1208c2ecf20Sopenharmony_ci#define IOT2040_UARTS_GPIO_HI_MODE 0xF8 /* enable & LED as outputs */ 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistruct exar8250; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistruct exar8250_platform { 1258c2ecf20Sopenharmony_ci int (*rs485_config)(struct uart_port *, struct serial_rs485 *); 1268c2ecf20Sopenharmony_ci const struct serial_rs485 *rs485_supported; 1278c2ecf20Sopenharmony_ci int (*register_gpio)(struct pci_dev *, struct uart_8250_port *); 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/** 1318c2ecf20Sopenharmony_ci * struct exar8250_board - board information 1328c2ecf20Sopenharmony_ci * @num_ports: number of serial ports 1338c2ecf20Sopenharmony_ci * @reg_shift: describes UART register mapping in PCI memory 1348c2ecf20Sopenharmony_ci * @setup: quirk run at ->probe() stage 1358c2ecf20Sopenharmony_ci * @exit: quirk run at ->remove() stage 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_cistruct exar8250_board { 1388c2ecf20Sopenharmony_ci unsigned int num_ports; 1398c2ecf20Sopenharmony_ci unsigned int reg_shift; 1408c2ecf20Sopenharmony_ci int (*setup)(struct exar8250 *, struct pci_dev *, 1418c2ecf20Sopenharmony_ci struct uart_8250_port *, int); 1428c2ecf20Sopenharmony_ci void (*exit)(struct pci_dev *pcidev); 1438c2ecf20Sopenharmony_ci}; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistruct exar8250 { 1468c2ecf20Sopenharmony_ci unsigned int nr; 1478c2ecf20Sopenharmony_ci struct exar8250_board *board; 1488c2ecf20Sopenharmony_ci void __iomem *virt; 1498c2ecf20Sopenharmony_ci int line[]; 1508c2ecf20Sopenharmony_ci}; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistatic void exar_pm(struct uart_port *port, unsigned int state, unsigned int old) 1538c2ecf20Sopenharmony_ci{ 1548c2ecf20Sopenharmony_ci /* 1558c2ecf20Sopenharmony_ci * Exar UARTs have a SLEEP register that enables or disables each UART 1568c2ecf20Sopenharmony_ci * to enter sleep mode separately. On the XR17V35x the register 1578c2ecf20Sopenharmony_ci * is accessible to each UART at the UART_EXAR_SLEEP offset, but 1588c2ecf20Sopenharmony_ci * the UART channel may only write to the corresponding bit. 1598c2ecf20Sopenharmony_ci */ 1608c2ecf20Sopenharmony_ci serial_port_out(port, UART_EXAR_SLEEP, state ? 0xff : 0); 1618c2ecf20Sopenharmony_ci} 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci/* 1648c2ecf20Sopenharmony_ci * XR17V35x UARTs have an extra fractional divisor register (DLD) 1658c2ecf20Sopenharmony_ci * Calculate divisor with extra 4-bit fractional portion 1668c2ecf20Sopenharmony_ci */ 1678c2ecf20Sopenharmony_cistatic unsigned int xr17v35x_get_divisor(struct uart_port *p, unsigned int baud, 1688c2ecf20Sopenharmony_ci unsigned int *frac) 1698c2ecf20Sopenharmony_ci{ 1708c2ecf20Sopenharmony_ci unsigned int quot_16; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci quot_16 = DIV_ROUND_CLOSEST(p->uartclk, baud); 1738c2ecf20Sopenharmony_ci *frac = quot_16 & 0x0f; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci return quot_16 >> 4; 1768c2ecf20Sopenharmony_ci} 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistatic void xr17v35x_set_divisor(struct uart_port *p, unsigned int baud, 1798c2ecf20Sopenharmony_ci unsigned int quot, unsigned int quot_frac) 1808c2ecf20Sopenharmony_ci{ 1818c2ecf20Sopenharmony_ci serial8250_do_set_divisor(p, baud, quot, quot_frac); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci /* Preserve bits not related to baudrate; DLD[7:4]. */ 1848c2ecf20Sopenharmony_ci quot_frac |= serial_port_in(p, 0x2) & 0xf0; 1858c2ecf20Sopenharmony_ci serial_port_out(p, 0x2, quot_frac); 1868c2ecf20Sopenharmony_ci} 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_cistatic int xr17v35x_startup(struct uart_port *port) 1898c2ecf20Sopenharmony_ci{ 1908c2ecf20Sopenharmony_ci /* 1918c2ecf20Sopenharmony_ci * First enable access to IER [7:5], ISR [5:4], FCR [5:4], 1928c2ecf20Sopenharmony_ci * MCR [7:5] and MSR [7:0] 1938c2ecf20Sopenharmony_ci */ 1948c2ecf20Sopenharmony_ci serial_port_out(port, UART_XR_EFR, UART_EFR_ECB); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci /* 1978c2ecf20Sopenharmony_ci * Make sure all interrups are masked until initialization is 1988c2ecf20Sopenharmony_ci * complete and the FIFOs are cleared 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_ci serial_port_out(port, UART_IER, 0); 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci return serial8250_do_startup(port); 2038c2ecf20Sopenharmony_ci} 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cistatic void exar_shutdown(struct uart_port *port) 2068c2ecf20Sopenharmony_ci{ 2078c2ecf20Sopenharmony_ci unsigned char lsr; 2088c2ecf20Sopenharmony_ci bool tx_complete = false; 2098c2ecf20Sopenharmony_ci struct uart_8250_port *up = up_to_u8250p(port); 2108c2ecf20Sopenharmony_ci struct circ_buf *xmit = &port->state->xmit; 2118c2ecf20Sopenharmony_ci int i = 0; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci do { 2148c2ecf20Sopenharmony_ci lsr = serial_in(up, UART_LSR); 2158c2ecf20Sopenharmony_ci if (lsr & (UART_LSR_TEMT | UART_LSR_THRE)) 2168c2ecf20Sopenharmony_ci tx_complete = true; 2178c2ecf20Sopenharmony_ci else 2188c2ecf20Sopenharmony_ci tx_complete = false; 2198c2ecf20Sopenharmony_ci usleep_range(1000, 1100); 2208c2ecf20Sopenharmony_ci } while (!uart_circ_empty(xmit) && !tx_complete && i++ < 1000); 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci serial8250_do_shutdown(port); 2238c2ecf20Sopenharmony_ci} 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cistatic int default_setup(struct exar8250 *priv, struct pci_dev *pcidev, 2268c2ecf20Sopenharmony_ci int idx, unsigned int offset, 2278c2ecf20Sopenharmony_ci struct uart_8250_port *port) 2288c2ecf20Sopenharmony_ci{ 2298c2ecf20Sopenharmony_ci const struct exar8250_board *board = priv->board; 2308c2ecf20Sopenharmony_ci unsigned int bar = 0; 2318c2ecf20Sopenharmony_ci unsigned char status; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci port->port.iotype = UPIO_MEM; 2348c2ecf20Sopenharmony_ci port->port.mapbase = pci_resource_start(pcidev, bar) + offset; 2358c2ecf20Sopenharmony_ci port->port.membase = priv->virt + offset; 2368c2ecf20Sopenharmony_ci port->port.regshift = board->reg_shift; 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci /* 2398c2ecf20Sopenharmony_ci * XR17V35x UARTs have an extra divisor register, DLD that gets enabled 2408c2ecf20Sopenharmony_ci * with when DLAB is set which will cause the device to incorrectly match 2418c2ecf20Sopenharmony_ci * and assign port type to PORT_16650. The EFR for this UART is found 2428c2ecf20Sopenharmony_ci * at offset 0x09. Instead check the Deice ID (DVID) register 2438c2ecf20Sopenharmony_ci * for a 2, 4 or 8 port UART. 2448c2ecf20Sopenharmony_ci */ 2458c2ecf20Sopenharmony_ci status = readb(port->port.membase + UART_EXAR_DVID); 2468c2ecf20Sopenharmony_ci if (status == 0x82 || status == 0x84 || status == 0x88) { 2478c2ecf20Sopenharmony_ci port->port.type = PORT_XR17V35X; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci port->port.get_divisor = xr17v35x_get_divisor; 2508c2ecf20Sopenharmony_ci port->port.set_divisor = xr17v35x_set_divisor; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci port->port.startup = xr17v35x_startup; 2538c2ecf20Sopenharmony_ci } else { 2548c2ecf20Sopenharmony_ci port->port.type = PORT_XR17D15X; 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci port->port.pm = exar_pm; 2588c2ecf20Sopenharmony_ci port->port.shutdown = exar_shutdown; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci return 0; 2618c2ecf20Sopenharmony_ci} 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cistatic int 2648c2ecf20Sopenharmony_cipci_fastcom335_setup(struct exar8250 *priv, struct pci_dev *pcidev, 2658c2ecf20Sopenharmony_ci struct uart_8250_port *port, int idx) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci unsigned int offset = idx * 0x200; 2688c2ecf20Sopenharmony_ci unsigned int baud = 1843200; 2698c2ecf20Sopenharmony_ci u8 __iomem *p; 2708c2ecf20Sopenharmony_ci int err; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci port->port.uartclk = baud * 16; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci err = default_setup(priv, pcidev, idx, offset, port); 2758c2ecf20Sopenharmony_ci if (err) 2768c2ecf20Sopenharmony_ci return err; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci p = port->port.membase; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_8XMODE); 2818c2ecf20Sopenharmony_ci writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR); 2828c2ecf20Sopenharmony_ci writeb(32, p + UART_EXAR_TXTRG); 2838c2ecf20Sopenharmony_ci writeb(32, p + UART_EXAR_RXTRG); 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci /* 2868c2ecf20Sopenharmony_ci * Setup Multipurpose Input/Output pins. 2878c2ecf20Sopenharmony_ci */ 2888c2ecf20Sopenharmony_ci if (idx == 0) { 2898c2ecf20Sopenharmony_ci switch (pcidev->device) { 2908c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_COMMTECH_4222PCI335: 2918c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_COMMTECH_4224PCI335: 2928c2ecf20Sopenharmony_ci writeb(0x78, p + UART_EXAR_MPIOLVL_7_0); 2938c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOINV_7_0); 2948c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOSEL_7_0); 2958c2ecf20Sopenharmony_ci break; 2968c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_COMMTECH_2324PCI335: 2978c2ecf20Sopenharmony_ci case PCI_DEVICE_ID_COMMTECH_2328PCI335: 2988c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOLVL_7_0); 2998c2ecf20Sopenharmony_ci writeb(0xc0, p + UART_EXAR_MPIOINV_7_0); 3008c2ecf20Sopenharmony_ci writeb(0xc0, p + UART_EXAR_MPIOSEL_7_0); 3018c2ecf20Sopenharmony_ci break; 3028c2ecf20Sopenharmony_ci } 3038c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOINT_7_0); 3048c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIO3T_7_0); 3058c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOOD_7_0); 3068c2ecf20Sopenharmony_ci } 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci return 0; 3098c2ecf20Sopenharmony_ci} 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_cistatic int 3128c2ecf20Sopenharmony_cipci_connect_tech_setup(struct exar8250 *priv, struct pci_dev *pcidev, 3138c2ecf20Sopenharmony_ci struct uart_8250_port *port, int idx) 3148c2ecf20Sopenharmony_ci{ 3158c2ecf20Sopenharmony_ci unsigned int offset = idx * 0x200; 3168c2ecf20Sopenharmony_ci unsigned int baud = 1843200; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci port->port.uartclk = baud * 16; 3198c2ecf20Sopenharmony_ci return default_setup(priv, pcidev, idx, offset, port); 3208c2ecf20Sopenharmony_ci} 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_cistatic int 3238c2ecf20Sopenharmony_cipci_xr17c154_setup(struct exar8250 *priv, struct pci_dev *pcidev, 3248c2ecf20Sopenharmony_ci struct uart_8250_port *port, int idx) 3258c2ecf20Sopenharmony_ci{ 3268c2ecf20Sopenharmony_ci unsigned int offset = idx * 0x200; 3278c2ecf20Sopenharmony_ci unsigned int baud = 921600; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci port->port.uartclk = baud * 16; 3308c2ecf20Sopenharmony_ci return default_setup(priv, pcidev, idx, offset, port); 3318c2ecf20Sopenharmony_ci} 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_cistatic void setup_gpio(struct pci_dev *pcidev, u8 __iomem *p) 3348c2ecf20Sopenharmony_ci{ 3358c2ecf20Sopenharmony_ci /* 3368c2ecf20Sopenharmony_ci * The Commtech adapters required the MPIOs to be driven low. The Exar 3378c2ecf20Sopenharmony_ci * devices will export them as GPIOs, so we pre-configure them safely 3388c2ecf20Sopenharmony_ci * as inputs. 3398c2ecf20Sopenharmony_ci */ 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci u8 dir = 0x00; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci if ((pcidev->vendor == PCI_VENDOR_ID_EXAR) && 3448c2ecf20Sopenharmony_ci (pcidev->subsystem_vendor != PCI_VENDOR_ID_SEALEVEL)) { 3458c2ecf20Sopenharmony_ci // Configure GPIO as inputs for Commtech adapters 3468c2ecf20Sopenharmony_ci dir = 0xff; 3478c2ecf20Sopenharmony_ci } else { 3488c2ecf20Sopenharmony_ci // Configure GPIO as outputs for SeaLevel adapters 3498c2ecf20Sopenharmony_ci dir = 0x00; 3508c2ecf20Sopenharmony_ci } 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOINT_7_0); 3538c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOLVL_7_0); 3548c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIO3T_7_0); 3558c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOINV_7_0); 3568c2ecf20Sopenharmony_ci writeb(dir, p + UART_EXAR_MPIOSEL_7_0); 3578c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOOD_7_0); 3588c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOINT_15_8); 3598c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOLVL_15_8); 3608c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIO3T_15_8); 3618c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOINV_15_8); 3628c2ecf20Sopenharmony_ci writeb(dir, p + UART_EXAR_MPIOSEL_15_8); 3638c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_MPIOOD_15_8); 3648c2ecf20Sopenharmony_ci} 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_cistatic void * 3678c2ecf20Sopenharmony_ci__xr17v35x_register_gpio(struct pci_dev *pcidev, 3688c2ecf20Sopenharmony_ci const struct property_entry *properties) 3698c2ecf20Sopenharmony_ci{ 3708c2ecf20Sopenharmony_ci struct platform_device *pdev; 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci pdev = platform_device_alloc("gpio_exar", PLATFORM_DEVID_AUTO); 3738c2ecf20Sopenharmony_ci if (!pdev) 3748c2ecf20Sopenharmony_ci return NULL; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci pdev->dev.parent = &pcidev->dev; 3778c2ecf20Sopenharmony_ci ACPI_COMPANION_SET(&pdev->dev, ACPI_COMPANION(&pcidev->dev)); 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci if (platform_device_add_properties(pdev, properties) < 0 || 3808c2ecf20Sopenharmony_ci platform_device_add(pdev) < 0) { 3818c2ecf20Sopenharmony_ci platform_device_put(pdev); 3828c2ecf20Sopenharmony_ci return NULL; 3838c2ecf20Sopenharmony_ci } 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci return pdev; 3868c2ecf20Sopenharmony_ci} 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_cistatic const struct property_entry exar_gpio_properties[] = { 3898c2ecf20Sopenharmony_ci PROPERTY_ENTRY_U32("exar,first-pin", 0), 3908c2ecf20Sopenharmony_ci PROPERTY_ENTRY_U32("ngpios", 16), 3918c2ecf20Sopenharmony_ci { } 3928c2ecf20Sopenharmony_ci}; 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_cistatic int xr17v35x_register_gpio(struct pci_dev *pcidev, 3958c2ecf20Sopenharmony_ci struct uart_8250_port *port) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci if (pcidev->vendor == PCI_VENDOR_ID_EXAR) 3988c2ecf20Sopenharmony_ci port->port.private_data = 3998c2ecf20Sopenharmony_ci __xr17v35x_register_gpio(pcidev, exar_gpio_properties); 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci return 0; 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_cistatic int generic_rs485_config(struct uart_port *port, 4058c2ecf20Sopenharmony_ci struct serial_rs485 *rs485) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED); 4088c2ecf20Sopenharmony_ci u8 __iomem *p = port->membase; 4098c2ecf20Sopenharmony_ci u8 value; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci value = readb(p + UART_EXAR_FCTR); 4128c2ecf20Sopenharmony_ci if (is_rs485) 4138c2ecf20Sopenharmony_ci value |= UART_FCTR_EXAR_485; 4148c2ecf20Sopenharmony_ci else 4158c2ecf20Sopenharmony_ci value &= ~UART_FCTR_EXAR_485; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci writeb(value, p + UART_EXAR_FCTR); 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci if (is_rs485) 4208c2ecf20Sopenharmony_ci writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR); 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci port->rs485 = *rs485; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci return 0; 4258c2ecf20Sopenharmony_ci} 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_cistatic const struct serial_rs485 generic_rs485_supported = { 4288c2ecf20Sopenharmony_ci .flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND, 4298c2ecf20Sopenharmony_ci}; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_cistatic const struct exar8250_platform exar8250_default_platform = { 4328c2ecf20Sopenharmony_ci .register_gpio = xr17v35x_register_gpio, 4338c2ecf20Sopenharmony_ci .rs485_config = generic_rs485_config, 4348c2ecf20Sopenharmony_ci .rs485_supported = &generic_rs485_supported, 4358c2ecf20Sopenharmony_ci}; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_cistatic int iot2040_rs485_config(struct uart_port *port, 4388c2ecf20Sopenharmony_ci struct serial_rs485 *rs485) 4398c2ecf20Sopenharmony_ci{ 4408c2ecf20Sopenharmony_ci bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED); 4418c2ecf20Sopenharmony_ci u8 __iomem *p = port->membase; 4428c2ecf20Sopenharmony_ci u8 mask = IOT2040_UART1_MASK; 4438c2ecf20Sopenharmony_ci u8 mode, value; 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci if (is_rs485) { 4468c2ecf20Sopenharmony_ci if (rs485->flags & SER_RS485_RX_DURING_TX) 4478c2ecf20Sopenharmony_ci mode = IOT2040_UART_MODE_RS422; 4488c2ecf20Sopenharmony_ci else 4498c2ecf20Sopenharmony_ci mode = IOT2040_UART_MODE_RS485; 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci if (rs485->flags & SER_RS485_TERMINATE_BUS) 4528c2ecf20Sopenharmony_ci mode |= IOT2040_UART_TERMINATE_BUS; 4538c2ecf20Sopenharmony_ci } else { 4548c2ecf20Sopenharmony_ci mode = IOT2040_UART_MODE_RS232; 4558c2ecf20Sopenharmony_ci } 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci if (port->line == 3) { 4588c2ecf20Sopenharmony_ci mask <<= IOT2040_UART2_SHIFT; 4598c2ecf20Sopenharmony_ci mode <<= IOT2040_UART2_SHIFT; 4608c2ecf20Sopenharmony_ci } 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci value = readb(p + UART_EXAR_MPIOLVL_7_0); 4638c2ecf20Sopenharmony_ci value &= ~mask; 4648c2ecf20Sopenharmony_ci value |= mode; 4658c2ecf20Sopenharmony_ci writeb(value, p + UART_EXAR_MPIOLVL_7_0); 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci return generic_rs485_config(port, rs485); 4688c2ecf20Sopenharmony_ci} 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_cistatic const struct serial_rs485 iot2040_rs485_supported = { 4718c2ecf20Sopenharmony_ci .flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | 4728c2ecf20Sopenharmony_ci SER_RS485_RX_DURING_TX | SER_RS485_TERMINATE_BUS, 4738c2ecf20Sopenharmony_ci}; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_cistatic const struct property_entry iot2040_gpio_properties[] = { 4768c2ecf20Sopenharmony_ci PROPERTY_ENTRY_U32("exar,first-pin", 10), 4778c2ecf20Sopenharmony_ci PROPERTY_ENTRY_U32("ngpios", 1), 4788c2ecf20Sopenharmony_ci { } 4798c2ecf20Sopenharmony_ci}; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_cistatic int iot2040_register_gpio(struct pci_dev *pcidev, 4828c2ecf20Sopenharmony_ci struct uart_8250_port *port) 4838c2ecf20Sopenharmony_ci{ 4848c2ecf20Sopenharmony_ci u8 __iomem *p = port->port.membase; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci writeb(IOT2040_UARTS_DEFAULT_MODE, p + UART_EXAR_MPIOLVL_7_0); 4878c2ecf20Sopenharmony_ci writeb(IOT2040_UARTS_GPIO_LO_MODE, p + UART_EXAR_MPIOSEL_7_0); 4888c2ecf20Sopenharmony_ci writeb(IOT2040_UARTS_ENABLE, p + UART_EXAR_MPIOLVL_15_8); 4898c2ecf20Sopenharmony_ci writeb(IOT2040_UARTS_GPIO_HI_MODE, p + UART_EXAR_MPIOSEL_15_8); 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci port->port.private_data = 4928c2ecf20Sopenharmony_ci __xr17v35x_register_gpio(pcidev, iot2040_gpio_properties); 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci return 0; 4958c2ecf20Sopenharmony_ci} 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_cistatic const struct exar8250_platform iot2040_platform = { 4988c2ecf20Sopenharmony_ci .rs485_config = iot2040_rs485_config, 4998c2ecf20Sopenharmony_ci .rs485_supported = &iot2040_rs485_supported, 5008c2ecf20Sopenharmony_ci .register_gpio = iot2040_register_gpio, 5018c2ecf20Sopenharmony_ci}; 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci/* 5048c2ecf20Sopenharmony_ci * For SIMATIC IOT2000, only IOT2040 and its variants have the Exar device, 5058c2ecf20Sopenharmony_ci * IOT2020 doesn't have. Therefore it is sufficient to match on the common 5068c2ecf20Sopenharmony_ci * board name after the device was found. 5078c2ecf20Sopenharmony_ci */ 5088c2ecf20Sopenharmony_cistatic const struct dmi_system_id exar_platforms[] = { 5098c2ecf20Sopenharmony_ci { 5108c2ecf20Sopenharmony_ci .matches = { 5118c2ecf20Sopenharmony_ci DMI_EXACT_MATCH(DMI_BOARD_NAME, "SIMATIC IOT2000"), 5128c2ecf20Sopenharmony_ci }, 5138c2ecf20Sopenharmony_ci .driver_data = (void *)&iot2040_platform, 5148c2ecf20Sopenharmony_ci }, 5158c2ecf20Sopenharmony_ci {} 5168c2ecf20Sopenharmony_ci}; 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_cistatic int 5198c2ecf20Sopenharmony_cipci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev, 5208c2ecf20Sopenharmony_ci struct uart_8250_port *port, int idx) 5218c2ecf20Sopenharmony_ci{ 5228c2ecf20Sopenharmony_ci const struct exar8250_platform *platform; 5238c2ecf20Sopenharmony_ci const struct dmi_system_id *dmi_match; 5248c2ecf20Sopenharmony_ci unsigned int offset = idx * 0x400; 5258c2ecf20Sopenharmony_ci unsigned int baud = 7812500; 5268c2ecf20Sopenharmony_ci u8 __iomem *p; 5278c2ecf20Sopenharmony_ci int ret; 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci dmi_match = dmi_first_match(exar_platforms); 5308c2ecf20Sopenharmony_ci if (dmi_match) 5318c2ecf20Sopenharmony_ci platform = dmi_match->driver_data; 5328c2ecf20Sopenharmony_ci else 5338c2ecf20Sopenharmony_ci platform = &exar8250_default_platform; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci port->port.uartclk = baud * 16; 5368c2ecf20Sopenharmony_ci port->port.rs485_config = platform->rs485_config; 5378c2ecf20Sopenharmony_ci port->port.rs485_supported = platform->rs485_supported; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci /* 5408c2ecf20Sopenharmony_ci * Setup the UART clock for the devices on expansion slot to 5418c2ecf20Sopenharmony_ci * half the clock speed of the main chip (which is 125MHz) 5428c2ecf20Sopenharmony_ci */ 5438c2ecf20Sopenharmony_ci if (idx >= 8) 5448c2ecf20Sopenharmony_ci port->port.uartclk /= 2; 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci ret = default_setup(priv, pcidev, idx, offset, port); 5478c2ecf20Sopenharmony_ci if (ret) 5488c2ecf20Sopenharmony_ci return ret; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci p = port->port.membase; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci writeb(0x00, p + UART_EXAR_8XMODE); 5538c2ecf20Sopenharmony_ci writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR); 5548c2ecf20Sopenharmony_ci writeb(128, p + UART_EXAR_TXTRG); 5558c2ecf20Sopenharmony_ci writeb(128, p + UART_EXAR_RXTRG); 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci if (idx == 0) { 5588c2ecf20Sopenharmony_ci /* Setup Multipurpose Input/Output pins. */ 5598c2ecf20Sopenharmony_ci setup_gpio(pcidev, p); 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci ret = platform->register_gpio(pcidev, port); 5628c2ecf20Sopenharmony_ci } 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci return ret; 5658c2ecf20Sopenharmony_ci} 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_cistatic void pci_xr17v35x_exit(struct pci_dev *pcidev) 5688c2ecf20Sopenharmony_ci{ 5698c2ecf20Sopenharmony_ci struct exar8250 *priv = pci_get_drvdata(pcidev); 5708c2ecf20Sopenharmony_ci struct uart_8250_port *port = serial8250_get_port(priv->line[0]); 5718c2ecf20Sopenharmony_ci struct platform_device *pdev = port->port.private_data; 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci platform_device_unregister(pdev); 5748c2ecf20Sopenharmony_ci port->port.private_data = NULL; 5758c2ecf20Sopenharmony_ci} 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_cistatic inline void exar_misc_clear(struct exar8250 *priv) 5788c2ecf20Sopenharmony_ci{ 5798c2ecf20Sopenharmony_ci /* Clear all PCI interrupts by reading INT0. No effect on IIR */ 5808c2ecf20Sopenharmony_ci readb(priv->virt + UART_EXAR_INT0); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci /* Clear INT0 for Expansion Interface slave ports, too */ 5838c2ecf20Sopenharmony_ci if (priv->board->num_ports > 8) 5848c2ecf20Sopenharmony_ci readb(priv->virt + 0x2000 + UART_EXAR_INT0); 5858c2ecf20Sopenharmony_ci} 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci/* 5888c2ecf20Sopenharmony_ci * These Exar UARTs have an extra interrupt indicator that could fire for a 5898c2ecf20Sopenharmony_ci * few interrupts that are not presented/cleared through IIR. One of which is 5908c2ecf20Sopenharmony_ci * a wakeup interrupt when coming out of sleep. These interrupts are only 5918c2ecf20Sopenharmony_ci * cleared by reading global INT0 or INT1 registers as interrupts are 5928c2ecf20Sopenharmony_ci * associated with channel 0. The INT[3:0] registers _are_ accessible from each 5938c2ecf20Sopenharmony_ci * channel's address space, but for the sake of bus efficiency we register a 5948c2ecf20Sopenharmony_ci * dedicated handler at the PCI device level to handle them. 5958c2ecf20Sopenharmony_ci */ 5968c2ecf20Sopenharmony_cistatic irqreturn_t exar_misc_handler(int irq, void *data) 5978c2ecf20Sopenharmony_ci{ 5988c2ecf20Sopenharmony_ci exar_misc_clear(data); 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci return IRQ_HANDLED; 6018c2ecf20Sopenharmony_ci} 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_cistatic int 6048c2ecf20Sopenharmony_ciexar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) 6058c2ecf20Sopenharmony_ci{ 6068c2ecf20Sopenharmony_ci unsigned int nr_ports, i, bar = 0, maxnr; 6078c2ecf20Sopenharmony_ci struct exar8250_board *board; 6088c2ecf20Sopenharmony_ci struct uart_8250_port uart; 6098c2ecf20Sopenharmony_ci struct exar8250 *priv; 6108c2ecf20Sopenharmony_ci int rc; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_ci board = (struct exar8250_board *)ent->driver_data; 6138c2ecf20Sopenharmony_ci if (!board) 6148c2ecf20Sopenharmony_ci return -EINVAL; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci rc = pcim_enable_device(pcidev); 6178c2ecf20Sopenharmony_ci if (rc) 6188c2ecf20Sopenharmony_ci return rc; 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci maxnr = pci_resource_len(pcidev, bar) >> (board->reg_shift + 3); 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci if (pcidev->vendor == PCI_VENDOR_ID_ACCESSIO) 6238c2ecf20Sopenharmony_ci nr_ports = BIT(((pcidev->device & 0x38) >> 3) - 1); 6248c2ecf20Sopenharmony_ci else if (board->num_ports) 6258c2ecf20Sopenharmony_ci nr_ports = board->num_ports; 6268c2ecf20Sopenharmony_ci else if (pcidev->vendor == PCI_VENDOR_ID_SEALEVEL) 6278c2ecf20Sopenharmony_ci nr_ports = pcidev->device & 0xff; 6288c2ecf20Sopenharmony_ci else 6298c2ecf20Sopenharmony_ci nr_ports = pcidev->device & 0x0f; 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci priv = devm_kzalloc(&pcidev->dev, struct_size(priv, line, nr_ports), GFP_KERNEL); 6328c2ecf20Sopenharmony_ci if (!priv) 6338c2ecf20Sopenharmony_ci return -ENOMEM; 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci priv->board = board; 6368c2ecf20Sopenharmony_ci priv->virt = pcim_iomap(pcidev, bar, 0); 6378c2ecf20Sopenharmony_ci if (!priv->virt) 6388c2ecf20Sopenharmony_ci return -ENOMEM; 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci pci_set_master(pcidev); 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci rc = pci_alloc_irq_vectors(pcidev, 1, 1, PCI_IRQ_ALL_TYPES); 6438c2ecf20Sopenharmony_ci if (rc < 0) 6448c2ecf20Sopenharmony_ci return rc; 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci memset(&uart, 0, sizeof(uart)); 6478c2ecf20Sopenharmony_ci uart.port.flags = UPF_SHARE_IRQ | UPF_EXAR_EFR | UPF_FIXED_TYPE | UPF_FIXED_PORT; 6488c2ecf20Sopenharmony_ci uart.port.irq = pci_irq_vector(pcidev, 0); 6498c2ecf20Sopenharmony_ci uart.port.dev = &pcidev->dev; 6508c2ecf20Sopenharmony_ci 6518c2ecf20Sopenharmony_ci rc = devm_request_irq(&pcidev->dev, uart.port.irq, exar_misc_handler, 6528c2ecf20Sopenharmony_ci IRQF_SHARED, "exar_uart", priv); 6538c2ecf20Sopenharmony_ci if (rc) 6548c2ecf20Sopenharmony_ci return rc; 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci /* Clear interrupts */ 6578c2ecf20Sopenharmony_ci exar_misc_clear(priv); 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci for (i = 0; i < nr_ports && i < maxnr; i++) { 6608c2ecf20Sopenharmony_ci rc = board->setup(priv, pcidev, &uart, i); 6618c2ecf20Sopenharmony_ci if (rc) { 6628c2ecf20Sopenharmony_ci dev_err(&pcidev->dev, "Failed to setup port %u\n", i); 6638c2ecf20Sopenharmony_ci break; 6648c2ecf20Sopenharmony_ci } 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci dev_dbg(&pcidev->dev, "Setup PCI port: port %lx, irq %d, type %d\n", 6678c2ecf20Sopenharmony_ci uart.port.iobase, uart.port.irq, uart.port.iotype); 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci priv->line[i] = serial8250_register_8250_port(&uart); 6708c2ecf20Sopenharmony_ci if (priv->line[i] < 0) { 6718c2ecf20Sopenharmony_ci dev_err(&pcidev->dev, 6728c2ecf20Sopenharmony_ci "Couldn't register serial port %lx, irq %d, type %d, error %d\n", 6738c2ecf20Sopenharmony_ci uart.port.iobase, uart.port.irq, 6748c2ecf20Sopenharmony_ci uart.port.iotype, priv->line[i]); 6758c2ecf20Sopenharmony_ci break; 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci } 6788c2ecf20Sopenharmony_ci priv->nr = i; 6798c2ecf20Sopenharmony_ci pci_set_drvdata(pcidev, priv); 6808c2ecf20Sopenharmony_ci return 0; 6818c2ecf20Sopenharmony_ci} 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_cistatic void exar_pci_remove(struct pci_dev *pcidev) 6848c2ecf20Sopenharmony_ci{ 6858c2ecf20Sopenharmony_ci struct exar8250 *priv = pci_get_drvdata(pcidev); 6868c2ecf20Sopenharmony_ci unsigned int i; 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci for (i = 0; i < priv->nr; i++) 6898c2ecf20Sopenharmony_ci serial8250_unregister_port(priv->line[i]); 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci if (priv->board->exit) 6928c2ecf20Sopenharmony_ci priv->board->exit(pcidev); 6938c2ecf20Sopenharmony_ci} 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_cistatic int __maybe_unused exar_suspend(struct device *dev) 6968c2ecf20Sopenharmony_ci{ 6978c2ecf20Sopenharmony_ci struct pci_dev *pcidev = to_pci_dev(dev); 6988c2ecf20Sopenharmony_ci struct exar8250 *priv = pci_get_drvdata(pcidev); 6998c2ecf20Sopenharmony_ci unsigned int i; 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci for (i = 0; i < priv->nr; i++) 7028c2ecf20Sopenharmony_ci if (priv->line[i] >= 0) 7038c2ecf20Sopenharmony_ci serial8250_suspend_port(priv->line[i]); 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci /* Ensure that every init quirk is properly torn down */ 7068c2ecf20Sopenharmony_ci if (priv->board->exit) 7078c2ecf20Sopenharmony_ci priv->board->exit(pcidev); 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci return 0; 7108c2ecf20Sopenharmony_ci} 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_cistatic int __maybe_unused exar_resume(struct device *dev) 7138c2ecf20Sopenharmony_ci{ 7148c2ecf20Sopenharmony_ci struct exar8250 *priv = dev_get_drvdata(dev); 7158c2ecf20Sopenharmony_ci unsigned int i; 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci exar_misc_clear(priv); 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci for (i = 0; i < priv->nr; i++) 7208c2ecf20Sopenharmony_ci if (priv->line[i] >= 0) 7218c2ecf20Sopenharmony_ci serial8250_resume_port(priv->line[i]); 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci return 0; 7248c2ecf20Sopenharmony_ci} 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume); 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_fastcom335_2 = { 7298c2ecf20Sopenharmony_ci .num_ports = 2, 7308c2ecf20Sopenharmony_ci .setup = pci_fastcom335_setup, 7318c2ecf20Sopenharmony_ci}; 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_fastcom335_4 = { 7348c2ecf20Sopenharmony_ci .num_ports = 4, 7358c2ecf20Sopenharmony_ci .setup = pci_fastcom335_setup, 7368c2ecf20Sopenharmony_ci}; 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_fastcom335_8 = { 7398c2ecf20Sopenharmony_ci .num_ports = 8, 7408c2ecf20Sopenharmony_ci .setup = pci_fastcom335_setup, 7418c2ecf20Sopenharmony_ci}; 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_connect = { 7448c2ecf20Sopenharmony_ci .setup = pci_connect_tech_setup, 7458c2ecf20Sopenharmony_ci}; 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_exar_ibm_saturn = { 7488c2ecf20Sopenharmony_ci .num_ports = 1, 7498c2ecf20Sopenharmony_ci .setup = pci_xr17c154_setup, 7508c2ecf20Sopenharmony_ci}; 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_exar_XR17C15x = { 7538c2ecf20Sopenharmony_ci .setup = pci_xr17c154_setup, 7548c2ecf20Sopenharmony_ci}; 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_exar_XR17V35x = { 7578c2ecf20Sopenharmony_ci .setup = pci_xr17v35x_setup, 7588c2ecf20Sopenharmony_ci .exit = pci_xr17v35x_exit, 7598c2ecf20Sopenharmony_ci}; 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_fastcom35x_2 = { 7628c2ecf20Sopenharmony_ci .num_ports = 2, 7638c2ecf20Sopenharmony_ci .setup = pci_xr17v35x_setup, 7648c2ecf20Sopenharmony_ci .exit = pci_xr17v35x_exit, 7658c2ecf20Sopenharmony_ci}; 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_fastcom35x_4 = { 7688c2ecf20Sopenharmony_ci .num_ports = 4, 7698c2ecf20Sopenharmony_ci .setup = pci_xr17v35x_setup, 7708c2ecf20Sopenharmony_ci .exit = pci_xr17v35x_exit, 7718c2ecf20Sopenharmony_ci}; 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_fastcom35x_8 = { 7748c2ecf20Sopenharmony_ci .num_ports = 8, 7758c2ecf20Sopenharmony_ci .setup = pci_xr17v35x_setup, 7768c2ecf20Sopenharmony_ci .exit = pci_xr17v35x_exit, 7778c2ecf20Sopenharmony_ci}; 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_exar_XR17V4358 = { 7808c2ecf20Sopenharmony_ci .num_ports = 12, 7818c2ecf20Sopenharmony_ci .setup = pci_xr17v35x_setup, 7828c2ecf20Sopenharmony_ci .exit = pci_xr17v35x_exit, 7838c2ecf20Sopenharmony_ci}; 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_cistatic const struct exar8250_board pbn_exar_XR17V8358 = { 7868c2ecf20Sopenharmony_ci .num_ports = 16, 7878c2ecf20Sopenharmony_ci .setup = pci_xr17v35x_setup, 7888c2ecf20Sopenharmony_ci .exit = pci_xr17v35x_exit, 7898c2ecf20Sopenharmony_ci}; 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci#define CONNECT_DEVICE(devid, sdevid, bd) { \ 7928c2ecf20Sopenharmony_ci PCI_DEVICE_SUB( \ 7938c2ecf20Sopenharmony_ci PCI_VENDOR_ID_EXAR, \ 7948c2ecf20Sopenharmony_ci PCI_DEVICE_ID_EXAR_##devid, \ 7958c2ecf20Sopenharmony_ci PCI_SUBVENDOR_ID_CONNECT_TECH, \ 7968c2ecf20Sopenharmony_ci PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_##sdevid), 0, 0, \ 7978c2ecf20Sopenharmony_ci (kernel_ulong_t)&bd \ 7988c2ecf20Sopenharmony_ci } 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci#define EXAR_DEVICE(vend, devid, bd) { PCI_DEVICE_DATA(vend, devid, &bd) } 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci#define IBM_DEVICE(devid, sdevid, bd) { \ 8038c2ecf20Sopenharmony_ci PCI_DEVICE_SUB( \ 8048c2ecf20Sopenharmony_ci PCI_VENDOR_ID_EXAR, \ 8058c2ecf20Sopenharmony_ci PCI_DEVICE_ID_EXAR_##devid, \ 8068c2ecf20Sopenharmony_ci PCI_VENDOR_ID_IBM, \ 8078c2ecf20Sopenharmony_ci PCI_SUBDEVICE_ID_IBM_##sdevid), 0, 0, \ 8088c2ecf20Sopenharmony_ci (kernel_ulong_t)&bd \ 8098c2ecf20Sopenharmony_ci } 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci#define USR_DEVICE(devid, sdevid, bd) { \ 8128c2ecf20Sopenharmony_ci PCI_DEVICE_SUB( \ 8138c2ecf20Sopenharmony_ci PCI_VENDOR_ID_USR, \ 8148c2ecf20Sopenharmony_ci PCI_DEVICE_ID_EXAR_##devid, \ 8158c2ecf20Sopenharmony_ci PCI_VENDOR_ID_EXAR, \ 8168c2ecf20Sopenharmony_ci PCI_SUBDEVICE_ID_USR_##sdevid), 0, 0, \ 8178c2ecf20Sopenharmony_ci (kernel_ulong_t)&bd \ 8188c2ecf20Sopenharmony_ci } 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_cistatic const struct pci_device_id exar_pci_tbl[] = { 8218c2ecf20Sopenharmony_ci EXAR_DEVICE(ACCESSIO, COM_2S, pbn_exar_XR17C15x), 8228c2ecf20Sopenharmony_ci EXAR_DEVICE(ACCESSIO, COM_4S, pbn_exar_XR17C15x), 8238c2ecf20Sopenharmony_ci EXAR_DEVICE(ACCESSIO, COM_8S, pbn_exar_XR17C15x), 8248c2ecf20Sopenharmony_ci EXAR_DEVICE(ACCESSIO, COM232_8, pbn_exar_XR17C15x), 8258c2ecf20Sopenharmony_ci EXAR_DEVICE(ACCESSIO, COM_2SM, pbn_exar_XR17C15x), 8268c2ecf20Sopenharmony_ci EXAR_DEVICE(ACCESSIO, COM_4SM, pbn_exar_XR17C15x), 8278c2ecf20Sopenharmony_ci EXAR_DEVICE(ACCESSIO, COM_8SM, pbn_exar_XR17C15x), 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C152, UART_2_232, pbn_connect), 8308c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C154, UART_4_232, pbn_connect), 8318c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C158, UART_8_232, pbn_connect), 8328c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C152, UART_1_1, pbn_connect), 8338c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C154, UART_2_2, pbn_connect), 8348c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C158, UART_4_4, pbn_connect), 8358c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C152, UART_2, pbn_connect), 8368c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C154, UART_4, pbn_connect), 8378c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C158, UART_8, pbn_connect), 8388c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C152, UART_2_485, pbn_connect), 8398c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C154, UART_4_485, pbn_connect), 8408c2ecf20Sopenharmony_ci CONNECT_DEVICE(XR17C158, UART_8_485, pbn_connect), 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci IBM_DEVICE(XR17C152, SATURN_SERIAL_ONE_PORT, pbn_exar_ibm_saturn), 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci /* USRobotics USR298x-OEM PCI Modems */ 8458c2ecf20Sopenharmony_ci USR_DEVICE(XR17C152, 2980, pbn_exar_XR17C15x), 8468c2ecf20Sopenharmony_ci USR_DEVICE(XR17C152, 2981, pbn_exar_XR17C15x), 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ci /* Exar Corp. XR17C15[248] Dual/Quad/Octal UART */ 8498c2ecf20Sopenharmony_ci EXAR_DEVICE(EXAR, XR17C152, pbn_exar_XR17C15x), 8508c2ecf20Sopenharmony_ci EXAR_DEVICE(EXAR, XR17C154, pbn_exar_XR17C15x), 8518c2ecf20Sopenharmony_ci EXAR_DEVICE(EXAR, XR17C158, pbn_exar_XR17C15x), 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_ci /* Exar Corp. XR17V[48]35[248] Dual/Quad/Octal/Hexa PCIe UARTs */ 8548c2ecf20Sopenharmony_ci EXAR_DEVICE(EXAR, XR17V352, pbn_exar_XR17V35x), 8558c2ecf20Sopenharmony_ci EXAR_DEVICE(EXAR, XR17V354, pbn_exar_XR17V35x), 8568c2ecf20Sopenharmony_ci EXAR_DEVICE(EXAR, XR17V358, pbn_exar_XR17V35x), 8578c2ecf20Sopenharmony_ci EXAR_DEVICE(EXAR, XR17V4358, pbn_exar_XR17V4358), 8588c2ecf20Sopenharmony_ci EXAR_DEVICE(EXAR, XR17V8358, pbn_exar_XR17V8358), 8598c2ecf20Sopenharmony_ci EXAR_DEVICE(COMMTECH, 4222PCIE, pbn_fastcom35x_2), 8608c2ecf20Sopenharmony_ci EXAR_DEVICE(COMMTECH, 4224PCIE, pbn_fastcom35x_4), 8618c2ecf20Sopenharmony_ci EXAR_DEVICE(COMMTECH, 4228PCIE, pbn_fastcom35x_8), 8628c2ecf20Sopenharmony_ci 8638c2ecf20Sopenharmony_ci EXAR_DEVICE(COMMTECH, 4222PCI335, pbn_fastcom335_2), 8648c2ecf20Sopenharmony_ci EXAR_DEVICE(COMMTECH, 4224PCI335, pbn_fastcom335_4), 8658c2ecf20Sopenharmony_ci EXAR_DEVICE(COMMTECH, 2324PCI335, pbn_fastcom335_4), 8668c2ecf20Sopenharmony_ci EXAR_DEVICE(COMMTECH, 2328PCI335, pbn_fastcom335_8), 8678c2ecf20Sopenharmony_ci 8688c2ecf20Sopenharmony_ci EXAR_DEVICE(SEALEVEL, 710xC, pbn_exar_XR17V35x), 8698c2ecf20Sopenharmony_ci EXAR_DEVICE(SEALEVEL, 720xC, pbn_exar_XR17V35x), 8708c2ecf20Sopenharmony_ci EXAR_DEVICE(SEALEVEL, 740xC, pbn_exar_XR17V35x), 8718c2ecf20Sopenharmony_ci EXAR_DEVICE(SEALEVEL, 780xC, pbn_exar_XR17V35x), 8728c2ecf20Sopenharmony_ci EXAR_DEVICE(SEALEVEL, 716xC, pbn_exar_XR17V35x), 8738c2ecf20Sopenharmony_ci { 0, } 8748c2ecf20Sopenharmony_ci}; 8758c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, exar_pci_tbl); 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_cistatic struct pci_driver exar_pci_driver = { 8788c2ecf20Sopenharmony_ci .name = "exar_serial", 8798c2ecf20Sopenharmony_ci .probe = exar_pci_probe, 8808c2ecf20Sopenharmony_ci .remove = exar_pci_remove, 8818c2ecf20Sopenharmony_ci .driver = { 8828c2ecf20Sopenharmony_ci .pm = &exar_pci_pm, 8838c2ecf20Sopenharmony_ci }, 8848c2ecf20Sopenharmony_ci .id_table = exar_pci_tbl, 8858c2ecf20Sopenharmony_ci}; 8868c2ecf20Sopenharmony_cimodule_pci_driver(exar_pci_driver); 8878c2ecf20Sopenharmony_ci 8888c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 8898c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Exar Serial Driver"); 8908c2ecf20Sopenharmony_ciMODULE_AUTHOR("Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>"); 891