1d0aeaa83SSudip Mukherjee /* 2d0aeaa83SSudip Mukherjee * Probe module for 8250/16550-type Exar chips PCI serial ports. 3d0aeaa83SSudip Mukherjee * 4d0aeaa83SSudip Mukherjee * Based on drivers/tty/serial/8250/8250_pci.c, 5d0aeaa83SSudip Mukherjee * 6d0aeaa83SSudip Mukherjee * Copyright (C) 2017 Sudip Mukherjee, All Rights Reserved. 7d0aeaa83SSudip Mukherjee * 8d0aeaa83SSudip Mukherjee * This program is free software; you can redistribute it and/or modify 9d0aeaa83SSudip Mukherjee * it under the terms of the GNU General Public License as published by 10d0aeaa83SSudip Mukherjee * the Free Software Foundation; either version 2 of the License. 11d0aeaa83SSudip Mukherjee */ 12d0aeaa83SSudip Mukherjee #include <linux/io.h> 13d0aeaa83SSudip Mukherjee #include <linux/kernel.h> 14d0aeaa83SSudip Mukherjee #include <linux/module.h> 15d0aeaa83SSudip Mukherjee #include <linux/pci.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 27*fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_4224PCI335 0x0002 28*fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_4222PCI335 0x0004 29*fc6cc961SJan Kiszka #define PCI_DEVICE_ID_COMMTECH_2324PCI335 0x000a 30*fc6cc961SJan 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 37d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINT_7_0 0x8f /* MPIOINT[7:0] */ 38d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOLVL_7_0 0x90 /* MPIOLVL[7:0] */ 39d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIO3T_7_0 0x91 /* MPIO3T[7:0] */ 40d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINV_7_0 0x92 /* MPIOINV[7:0] */ 41d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOSEL_7_0 0x93 /* MPIOSEL[7:0] */ 42d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOOD_7_0 0x94 /* MPIOOD[7:0] */ 43d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINT_15_8 0x95 /* MPIOINT[15:8] */ 44d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOLVL_15_8 0x96 /* MPIOLVL[15:8] */ 45d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIO3T_15_8 0x97 /* MPIO3T[15:8] */ 46d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOINV_15_8 0x98 /* MPIOINV[15:8] */ 47d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOSEL_15_8 0x99 /* MPIOSEL[15:8] */ 48d0aeaa83SSudip Mukherjee #define UART_EXAR_MPIOOD_15_8 0x9a /* MPIOOD[15:8] */ 49d0aeaa83SSudip Mukherjee 50d0aeaa83SSudip Mukherjee struct exar8250; 51d0aeaa83SSudip Mukherjee 52d0aeaa83SSudip Mukherjee /** 53d0aeaa83SSudip Mukherjee * struct exar8250_board - board information 54d0aeaa83SSudip Mukherjee * @num_ports: number of serial ports 55d0aeaa83SSudip Mukherjee * @reg_shift: describes UART register mapping in PCI memory 56d0aeaa83SSudip Mukherjee */ 57d0aeaa83SSudip Mukherjee struct exar8250_board { 58d0aeaa83SSudip Mukherjee unsigned int num_ports; 59d0aeaa83SSudip Mukherjee unsigned int reg_shift; 60d0aeaa83SSudip Mukherjee bool has_slave; 61d0aeaa83SSudip Mukherjee int (*setup)(struct exar8250 *, struct pci_dev *, 62d0aeaa83SSudip Mukherjee struct uart_8250_port *, int); 63d0aeaa83SSudip Mukherjee void (*exit)(struct pci_dev *pcidev); 64d0aeaa83SSudip Mukherjee }; 65d0aeaa83SSudip Mukherjee 66d0aeaa83SSudip Mukherjee struct exar8250 { 67d0aeaa83SSudip Mukherjee unsigned int nr; 68d0aeaa83SSudip Mukherjee struct exar8250_board *board; 69d0aeaa83SSudip Mukherjee int line[0]; 70d0aeaa83SSudip Mukherjee }; 71d0aeaa83SSudip Mukherjee 72d0aeaa83SSudip Mukherjee static int default_setup(struct exar8250 *priv, struct pci_dev *pcidev, 73d0aeaa83SSudip Mukherjee int idx, unsigned int offset, 74d0aeaa83SSudip Mukherjee struct uart_8250_port *port) 75d0aeaa83SSudip Mukherjee { 76d0aeaa83SSudip Mukherjee const struct exar8250_board *board = priv->board; 77d0aeaa83SSudip Mukherjee unsigned int bar = 0; 78d0aeaa83SSudip Mukherjee 7924572af4SJan Kiszka if (!pcim_iomap_table(pcidev)[bar] && !pcim_iomap(pcidev, bar, 0)) 8024572af4SJan Kiszka return -ENOMEM; 8124572af4SJan Kiszka 82d0aeaa83SSudip Mukherjee port->port.iotype = UPIO_MEM; 83d0aeaa83SSudip Mukherjee port->port.mapbase = pci_resource_start(pcidev, bar) + offset; 84d0aeaa83SSudip Mukherjee port->port.membase = pcim_iomap_table(pcidev)[bar] + offset; 85d0aeaa83SSudip Mukherjee port->port.regshift = board->reg_shift; 86d0aeaa83SSudip Mukherjee 87d0aeaa83SSudip Mukherjee return 0; 88d0aeaa83SSudip Mukherjee } 89d0aeaa83SSudip Mukherjee 90d0aeaa83SSudip Mukherjee static int 91*fc6cc961SJan Kiszka pci_fastcom335_setup(struct exar8250 *priv, struct pci_dev *pcidev, 92*fc6cc961SJan Kiszka struct uart_8250_port *port, int idx) 93*fc6cc961SJan Kiszka { 94*fc6cc961SJan Kiszka unsigned int offset = idx * 0x200; 95*fc6cc961SJan Kiszka unsigned int baud = 1843200; 96*fc6cc961SJan Kiszka u8 __iomem *p; 97*fc6cc961SJan Kiszka int err; 98*fc6cc961SJan Kiszka 99*fc6cc961SJan Kiszka port->port.flags |= UPF_EXAR_EFR; 100*fc6cc961SJan Kiszka port->port.uartclk = baud * 16; 101*fc6cc961SJan Kiszka 102*fc6cc961SJan Kiszka err = default_setup(priv, pcidev, idx, offset, port); 103*fc6cc961SJan Kiszka if (err) 104*fc6cc961SJan Kiszka return err; 105*fc6cc961SJan Kiszka 106*fc6cc961SJan Kiszka p = port->port.membase; 107*fc6cc961SJan Kiszka 108*fc6cc961SJan Kiszka writeb(0x00, p + UART_EXAR_8XMODE); 109*fc6cc961SJan Kiszka writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR); 110*fc6cc961SJan Kiszka writeb(32, p + UART_EXAR_TXTRG); 111*fc6cc961SJan Kiszka writeb(32, p + UART_EXAR_RXTRG); 112*fc6cc961SJan Kiszka 113*fc6cc961SJan Kiszka /* 114*fc6cc961SJan Kiszka * Setup Multipurpose Input/Output pins. 115*fc6cc961SJan Kiszka */ 116*fc6cc961SJan Kiszka if (idx == 0) { 117*fc6cc961SJan Kiszka switch (pcidev->device) { 118*fc6cc961SJan Kiszka case PCI_DEVICE_ID_COMMTECH_4222PCI335: 119*fc6cc961SJan Kiszka case PCI_DEVICE_ID_COMMTECH_4224PCI335: 120*fc6cc961SJan Kiszka writeb(0x78, p + UART_EXAR_MPIOLVL_7_0); 121*fc6cc961SJan Kiszka writeb(0x00, p + UART_EXAR_MPIOINV_7_0); 122*fc6cc961SJan Kiszka writeb(0x00, p + UART_EXAR_MPIOSEL_7_0); 123*fc6cc961SJan Kiszka break; 124*fc6cc961SJan Kiszka case PCI_DEVICE_ID_COMMTECH_2324PCI335: 125*fc6cc961SJan Kiszka case PCI_DEVICE_ID_COMMTECH_2328PCI335: 126*fc6cc961SJan Kiszka writeb(0x00, p + UART_EXAR_MPIOLVL_7_0); 127*fc6cc961SJan Kiszka writeb(0xc0, p + UART_EXAR_MPIOINV_7_0); 128*fc6cc961SJan Kiszka writeb(0xc0, p + UART_EXAR_MPIOSEL_7_0); 129*fc6cc961SJan Kiszka break; 130*fc6cc961SJan Kiszka } 131*fc6cc961SJan Kiszka writeb(0x00, p + UART_EXAR_MPIOINT_7_0); 132*fc6cc961SJan Kiszka writeb(0x00, p + UART_EXAR_MPIO3T_7_0); 133*fc6cc961SJan Kiszka writeb(0x00, p + UART_EXAR_MPIOOD_7_0); 134*fc6cc961SJan Kiszka } 135*fc6cc961SJan Kiszka 136*fc6cc961SJan Kiszka return 0; 137*fc6cc961SJan Kiszka } 138*fc6cc961SJan Kiszka 139*fc6cc961SJan Kiszka static int 140d0aeaa83SSudip Mukherjee pci_connect_tech_setup(struct exar8250 *priv, struct pci_dev *pcidev, 141d0aeaa83SSudip Mukherjee struct uart_8250_port *port, int idx) 142d0aeaa83SSudip Mukherjee { 143d0aeaa83SSudip Mukherjee unsigned int offset = idx * 0x200; 144d0aeaa83SSudip Mukherjee unsigned int baud = 1843200; 145d0aeaa83SSudip Mukherjee 146d0aeaa83SSudip Mukherjee port->port.uartclk = baud * 16; 147d0aeaa83SSudip Mukherjee return default_setup(priv, pcidev, idx, offset, port); 148d0aeaa83SSudip Mukherjee } 149d0aeaa83SSudip Mukherjee 150d0aeaa83SSudip Mukherjee static int 151d0aeaa83SSudip Mukherjee pci_xr17c154_setup(struct exar8250 *priv, struct pci_dev *pcidev, 152d0aeaa83SSudip Mukherjee struct uart_8250_port *port, int idx) 153d0aeaa83SSudip Mukherjee { 154d0aeaa83SSudip Mukherjee unsigned int offset = idx * 0x200; 155d0aeaa83SSudip Mukherjee unsigned int baud = 921600; 156d0aeaa83SSudip Mukherjee 157d0aeaa83SSudip Mukherjee port->port.uartclk = baud * 16; 158d0aeaa83SSudip Mukherjee return default_setup(priv, pcidev, idx, offset, port); 159d0aeaa83SSudip Mukherjee } 160d0aeaa83SSudip Mukherjee 161d0aeaa83SSudip Mukherjee static void setup_gpio(u8 __iomem *p) 162d0aeaa83SSudip Mukherjee { 163d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOINT_7_0); 164d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOLVL_7_0); 165d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIO3T_7_0); 166d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOINV_7_0); 167d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOSEL_7_0); 168d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOOD_7_0); 169d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOINT_15_8); 170d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOLVL_15_8); 171d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIO3T_15_8); 172d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOINV_15_8); 173d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOSEL_15_8); 174d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_MPIOOD_15_8); 175d0aeaa83SSudip Mukherjee } 176d0aeaa83SSudip Mukherjee 177d0aeaa83SSudip Mukherjee static void * 178d0aeaa83SSudip Mukherjee xr17v35x_register_gpio(struct pci_dev *pcidev) 179d0aeaa83SSudip Mukherjee { 180d0aeaa83SSudip Mukherjee struct platform_device *pdev; 181d0aeaa83SSudip Mukherjee 182d0aeaa83SSudip Mukherjee pdev = platform_device_alloc("gpio_exar", PLATFORM_DEVID_AUTO); 183d0aeaa83SSudip Mukherjee if (!pdev) 184d0aeaa83SSudip Mukherjee return NULL; 185d0aeaa83SSudip Mukherjee 186d0aeaa83SSudip Mukherjee platform_set_drvdata(pdev, pcidev); 187d0aeaa83SSudip Mukherjee if (platform_device_add(pdev) < 0) { 188d0aeaa83SSudip Mukherjee platform_device_put(pdev); 189d0aeaa83SSudip Mukherjee return NULL; 190d0aeaa83SSudip Mukherjee } 191d0aeaa83SSudip Mukherjee 192d0aeaa83SSudip Mukherjee return pdev; 193d0aeaa83SSudip Mukherjee } 194d0aeaa83SSudip Mukherjee 195d0aeaa83SSudip Mukherjee static int 196d0aeaa83SSudip Mukherjee pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev, 197d0aeaa83SSudip Mukherjee struct uart_8250_port *port, int idx) 198d0aeaa83SSudip Mukherjee { 199d0aeaa83SSudip Mukherjee const struct exar8250_board *board = priv->board; 200d0aeaa83SSudip Mukherjee unsigned int offset = idx * 0x400; 201d0aeaa83SSudip Mukherjee unsigned int baud = 7812500; 202d0aeaa83SSudip Mukherjee u8 __iomem *p; 203d0aeaa83SSudip Mukherjee int ret; 204d0aeaa83SSudip Mukherjee 205d0aeaa83SSudip Mukherjee port->port.uartclk = baud * 16; 206d0aeaa83SSudip Mukherjee /* 207d0aeaa83SSudip Mukherjee * Setup the uart clock for the devices on expansion slot to 208d0aeaa83SSudip Mukherjee * half the clock speed of the main chip (which is 125MHz) 209d0aeaa83SSudip Mukherjee */ 210d0aeaa83SSudip Mukherjee if (board->has_slave && idx >= 8) 211d0aeaa83SSudip Mukherjee port->port.uartclk /= 2; 212d0aeaa83SSudip Mukherjee 2135b5f252dSJan Kiszka ret = default_setup(priv, pcidev, idx, offset, port); 2145b5f252dSJan Kiszka if (ret) 2155b5f252dSJan Kiszka return ret; 216d0aeaa83SSudip Mukherjee 2175b5f252dSJan Kiszka p = port->port.membase; 218d0aeaa83SSudip Mukherjee 219d0aeaa83SSudip Mukherjee writeb(0x00, p + UART_EXAR_8XMODE); 220d0aeaa83SSudip Mukherjee writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR); 221d0aeaa83SSudip Mukherjee writeb(128, p + UART_EXAR_TXTRG); 222d0aeaa83SSudip Mukherjee writeb(128, p + UART_EXAR_RXTRG); 223d0aeaa83SSudip Mukherjee 2245b5f252dSJan Kiszka if (idx == 0) { 2255b5f252dSJan Kiszka /* Setup Multipurpose Input/Output pins. */ 2265b5f252dSJan Kiszka setup_gpio(p); 227d0aeaa83SSudip Mukherjee 2285b5f252dSJan Kiszka port->port.private_data = xr17v35x_register_gpio(pcidev); 2295b5f252dSJan Kiszka } 230d0aeaa83SSudip Mukherjee 231d0aeaa83SSudip Mukherjee return 0; 232d0aeaa83SSudip Mukherjee } 233d0aeaa83SSudip Mukherjee 234d0aeaa83SSudip Mukherjee static void pci_xr17v35x_exit(struct pci_dev *pcidev) 235d0aeaa83SSudip Mukherjee { 236d0aeaa83SSudip Mukherjee struct exar8250 *priv = pci_get_drvdata(pcidev); 237d0aeaa83SSudip Mukherjee struct uart_8250_port *port = serial8250_get_port(priv->line[0]); 238d0aeaa83SSudip Mukherjee struct platform_device *pdev = port->port.private_data; 239d0aeaa83SSudip Mukherjee 240d0aeaa83SSudip Mukherjee platform_device_unregister(pdev); 241d0aeaa83SSudip Mukherjee port->port.private_data = NULL; 242d0aeaa83SSudip Mukherjee } 243d0aeaa83SSudip Mukherjee 244d0aeaa83SSudip Mukherjee static int 245d0aeaa83SSudip Mukherjee exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) 246d0aeaa83SSudip Mukherjee { 247d0aeaa83SSudip Mukherjee unsigned int nr_ports, i, bar = 0, maxnr; 248d0aeaa83SSudip Mukherjee struct exar8250_board *board; 249d0aeaa83SSudip Mukherjee struct uart_8250_port uart; 250d0aeaa83SSudip Mukherjee struct exar8250 *priv; 251d0aeaa83SSudip Mukherjee int rc; 252d0aeaa83SSudip Mukherjee 253d0aeaa83SSudip Mukherjee board = (struct exar8250_board *)ent->driver_data; 254d0aeaa83SSudip Mukherjee if (!board) 255d0aeaa83SSudip Mukherjee return -EINVAL; 256d0aeaa83SSudip Mukherjee 257d0aeaa83SSudip Mukherjee rc = pcim_enable_device(pcidev); 258d0aeaa83SSudip Mukherjee if (rc) 259d0aeaa83SSudip Mukherjee return rc; 260d0aeaa83SSudip Mukherjee 261d0aeaa83SSudip Mukherjee maxnr = pci_resource_len(pcidev, bar) >> (board->reg_shift + 3); 262d0aeaa83SSudip Mukherjee 263d0aeaa83SSudip Mukherjee nr_ports = board->num_ports ? board->num_ports : pcidev->device & 0x0f; 264d0aeaa83SSudip Mukherjee 265d0aeaa83SSudip Mukherjee priv = devm_kzalloc(&pcidev->dev, sizeof(*priv) + 266d0aeaa83SSudip Mukherjee sizeof(unsigned int) * nr_ports, 267d0aeaa83SSudip Mukherjee GFP_KERNEL); 268d0aeaa83SSudip Mukherjee if (!priv) 269d0aeaa83SSudip Mukherjee return -ENOMEM; 270d0aeaa83SSudip Mukherjee 271d0aeaa83SSudip Mukherjee priv->board = board; 272d0aeaa83SSudip Mukherjee 273d0aeaa83SSudip Mukherjee memset(&uart, 0, sizeof(uart)); 274d0aeaa83SSudip Mukherjee uart.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ 275d0aeaa83SSudip Mukherjee | UPF_EXAR_EFR; 276d0aeaa83SSudip Mukherjee uart.port.irq = pcidev->irq; 277d0aeaa83SSudip Mukherjee uart.port.dev = &pcidev->dev; 278d0aeaa83SSudip Mukherjee 279d0aeaa83SSudip Mukherjee for (i = 0; i < nr_ports && i < maxnr; i++) { 280d0aeaa83SSudip Mukherjee rc = board->setup(priv, pcidev, &uart, i); 281d0aeaa83SSudip Mukherjee if (rc) { 282d0aeaa83SSudip Mukherjee dev_err(&pcidev->dev, "Failed to setup port %u\n", i); 283d0aeaa83SSudip Mukherjee break; 284d0aeaa83SSudip Mukherjee } 285d0aeaa83SSudip Mukherjee 286d0aeaa83SSudip Mukherjee dev_dbg(&pcidev->dev, "Setup PCI port: port %lx, irq %d, type %d\n", 287d0aeaa83SSudip Mukherjee uart.port.iobase, uart.port.irq, uart.port.iotype); 288d0aeaa83SSudip Mukherjee 289d0aeaa83SSudip Mukherjee priv->line[i] = serial8250_register_8250_port(&uart); 290d0aeaa83SSudip Mukherjee if (priv->line[i] < 0) { 291d0aeaa83SSudip Mukherjee dev_err(&pcidev->dev, 292d0aeaa83SSudip Mukherjee "Couldn't register serial port %lx, irq %d, type %d, error %d\n", 293d0aeaa83SSudip Mukherjee uart.port.iobase, uart.port.irq, 294d0aeaa83SSudip Mukherjee uart.port.iotype, priv->line[i]); 295d0aeaa83SSudip Mukherjee break; 296d0aeaa83SSudip Mukherjee } 297d0aeaa83SSudip Mukherjee } 298d0aeaa83SSudip Mukherjee priv->nr = i; 299d0aeaa83SSudip Mukherjee pci_set_drvdata(pcidev, priv); 300d0aeaa83SSudip Mukherjee return 0; 301d0aeaa83SSudip Mukherjee } 302d0aeaa83SSudip Mukherjee 303d0aeaa83SSudip Mukherjee static void exar_pci_remove(struct pci_dev *pcidev) 304d0aeaa83SSudip Mukherjee { 305d0aeaa83SSudip Mukherjee struct exar8250 *priv = pci_get_drvdata(pcidev); 306d0aeaa83SSudip Mukherjee unsigned int i; 307d0aeaa83SSudip Mukherjee 308d0aeaa83SSudip Mukherjee for (i = 0; i < priv->nr; i++) 309d0aeaa83SSudip Mukherjee serial8250_unregister_port(priv->line[i]); 310d0aeaa83SSudip Mukherjee 311d0aeaa83SSudip Mukherjee if (priv->board->exit) 312d0aeaa83SSudip Mukherjee priv->board->exit(pcidev); 313d0aeaa83SSudip Mukherjee } 314d0aeaa83SSudip Mukherjee 315d0aeaa83SSudip Mukherjee static int __maybe_unused exar_suspend(struct device *dev) 316d0aeaa83SSudip Mukherjee { 317d0aeaa83SSudip Mukherjee struct pci_dev *pcidev = to_pci_dev(dev); 318d0aeaa83SSudip Mukherjee struct exar8250 *priv = pci_get_drvdata(pcidev); 319d0aeaa83SSudip Mukherjee unsigned int i; 320d0aeaa83SSudip Mukherjee 321d0aeaa83SSudip Mukherjee for (i = 0; i < priv->nr; i++) 322d0aeaa83SSudip Mukherjee if (priv->line[i] >= 0) 323d0aeaa83SSudip Mukherjee serial8250_suspend_port(priv->line[i]); 324d0aeaa83SSudip Mukherjee 325d0aeaa83SSudip Mukherjee /* Ensure that every init quirk is properly torn down */ 326d0aeaa83SSudip Mukherjee if (priv->board->exit) 327d0aeaa83SSudip Mukherjee priv->board->exit(pcidev); 328d0aeaa83SSudip Mukherjee 329d0aeaa83SSudip Mukherjee return 0; 330d0aeaa83SSudip Mukherjee } 331d0aeaa83SSudip Mukherjee 332d0aeaa83SSudip Mukherjee static int __maybe_unused exar_resume(struct device *dev) 333d0aeaa83SSudip Mukherjee { 334d0aeaa83SSudip Mukherjee struct pci_dev *pcidev = to_pci_dev(dev); 335d0aeaa83SSudip Mukherjee struct exar8250 *priv = pci_get_drvdata(pcidev); 336d0aeaa83SSudip Mukherjee unsigned int i; 337d0aeaa83SSudip Mukherjee 338d0aeaa83SSudip Mukherjee for (i = 0; i < priv->nr; i++) 339d0aeaa83SSudip Mukherjee if (priv->line[i] >= 0) 340d0aeaa83SSudip Mukherjee serial8250_resume_port(priv->line[i]); 341d0aeaa83SSudip Mukherjee 342d0aeaa83SSudip Mukherjee return 0; 343d0aeaa83SSudip Mukherjee } 344d0aeaa83SSudip Mukherjee 345d0aeaa83SSudip Mukherjee static SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume); 346d0aeaa83SSudip Mukherjee 347*fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_2 = { 348*fc6cc961SJan Kiszka .num_ports = 2, 349*fc6cc961SJan Kiszka .setup = pci_fastcom335_setup, 350*fc6cc961SJan Kiszka }; 351*fc6cc961SJan Kiszka 352*fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_4 = { 353*fc6cc961SJan Kiszka .num_ports = 4, 354*fc6cc961SJan Kiszka .setup = pci_fastcom335_setup, 355*fc6cc961SJan Kiszka }; 356*fc6cc961SJan Kiszka 357*fc6cc961SJan Kiszka static const struct exar8250_board pbn_fastcom335_8 = { 358*fc6cc961SJan Kiszka .num_ports = 8, 359*fc6cc961SJan Kiszka .setup = pci_fastcom335_setup, 360*fc6cc961SJan Kiszka }; 361*fc6cc961SJan Kiszka 362d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_connect = { 363d0aeaa83SSudip Mukherjee .setup = pci_connect_tech_setup, 364d0aeaa83SSudip Mukherjee }; 365d0aeaa83SSudip Mukherjee 366d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_ibm_saturn = { 367d0aeaa83SSudip Mukherjee .num_ports = 1, 368d0aeaa83SSudip Mukherjee .setup = pci_xr17c154_setup, 369d0aeaa83SSudip Mukherjee }; 370d0aeaa83SSudip Mukherjee 371d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17C15x = { 372d0aeaa83SSudip Mukherjee .setup = pci_xr17c154_setup, 373d0aeaa83SSudip Mukherjee }; 374d0aeaa83SSudip Mukherjee 375d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V35x = { 376d0aeaa83SSudip Mukherjee .setup = pci_xr17v35x_setup, 377d0aeaa83SSudip Mukherjee .exit = pci_xr17v35x_exit, 378d0aeaa83SSudip Mukherjee }; 379d0aeaa83SSudip Mukherjee 380d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V4358 = { 381d0aeaa83SSudip Mukherjee .num_ports = 12, 382d0aeaa83SSudip Mukherjee .has_slave = true, 383d0aeaa83SSudip Mukherjee .setup = pci_xr17v35x_setup, 384d0aeaa83SSudip Mukherjee .exit = pci_xr17v35x_exit, 385d0aeaa83SSudip Mukherjee }; 386d0aeaa83SSudip Mukherjee 387d0aeaa83SSudip Mukherjee static const struct exar8250_board pbn_exar_XR17V8358 = { 388d0aeaa83SSudip Mukherjee .num_ports = 16, 389d0aeaa83SSudip Mukherjee .has_slave = true, 390d0aeaa83SSudip Mukherjee .setup = pci_xr17v35x_setup, 391d0aeaa83SSudip Mukherjee .exit = pci_xr17v35x_exit, 392d0aeaa83SSudip Mukherjee }; 393d0aeaa83SSudip Mukherjee 394d0aeaa83SSudip Mukherjee #define CONNECT_DEVICE(devid, sdevid, bd) { \ 395d0aeaa83SSudip Mukherjee PCI_DEVICE_SUB( \ 396d0aeaa83SSudip Mukherjee PCI_VENDOR_ID_EXAR, \ 397d0aeaa83SSudip Mukherjee PCI_DEVICE_ID_EXAR_##devid, \ 398d0aeaa83SSudip Mukherjee PCI_SUBVENDOR_ID_CONNECT_TECH, \ 399d0aeaa83SSudip Mukherjee PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_##sdevid), 0, 0, \ 400d0aeaa83SSudip Mukherjee (kernel_ulong_t)&bd \ 401d0aeaa83SSudip Mukherjee } 402d0aeaa83SSudip Mukherjee 403d0aeaa83SSudip Mukherjee #define EXAR_DEVICE(vend, devid, bd) { \ 404d0aeaa83SSudip Mukherjee PCI_VDEVICE(vend, PCI_DEVICE_ID_##devid), (kernel_ulong_t)&bd \ 405d0aeaa83SSudip Mukherjee } 406d0aeaa83SSudip Mukherjee 407d0aeaa83SSudip Mukherjee #define IBM_DEVICE(devid, sdevid, bd) { \ 408d0aeaa83SSudip Mukherjee PCI_DEVICE_SUB( \ 409d0aeaa83SSudip Mukherjee PCI_VENDOR_ID_EXAR, \ 410d0aeaa83SSudip Mukherjee PCI_DEVICE_ID_EXAR_##devid, \ 411d0aeaa83SSudip Mukherjee PCI_VENDOR_ID_IBM, \ 412d0aeaa83SSudip Mukherjee PCI_SUBDEVICE_ID_IBM_##sdevid), 0, 0, \ 413d0aeaa83SSudip Mukherjee (kernel_ulong_t)&bd \ 414d0aeaa83SSudip Mukherjee } 415d0aeaa83SSudip Mukherjee 416d0aeaa83SSudip Mukherjee static struct pci_device_id exar_pci_tbl[] = { 417d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C152, UART_2_232, pbn_connect), 418d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C154, UART_4_232, pbn_connect), 419d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C158, UART_8_232, pbn_connect), 420d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C152, UART_1_1, pbn_connect), 421d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C154, UART_2_2, pbn_connect), 422d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C158, UART_4_4, pbn_connect), 423d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C152, UART_2, pbn_connect), 424d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C154, UART_4, pbn_connect), 425d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C158, UART_8, pbn_connect), 426d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C152, UART_2_485, pbn_connect), 427d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C154, UART_4_485, pbn_connect), 428d0aeaa83SSudip Mukherjee CONNECT_DEVICE(XR17C158, UART_8_485, pbn_connect), 429d0aeaa83SSudip Mukherjee 430d0aeaa83SSudip Mukherjee IBM_DEVICE(XR17C152, SATURN_SERIAL_ONE_PORT, pbn_exar_ibm_saturn), 431d0aeaa83SSudip Mukherjee 432d0aeaa83SSudip Mukherjee /* Exar Corp. XR17C15[248] Dual/Quad/Octal UART */ 433d0aeaa83SSudip Mukherjee EXAR_DEVICE(EXAR, EXAR_XR17C152, pbn_exar_XR17C15x), 434d0aeaa83SSudip Mukherjee EXAR_DEVICE(EXAR, EXAR_XR17C154, pbn_exar_XR17C15x), 435d0aeaa83SSudip Mukherjee EXAR_DEVICE(EXAR, EXAR_XR17C158, pbn_exar_XR17C15x), 436d0aeaa83SSudip Mukherjee 437d0aeaa83SSudip Mukherjee /* Exar Corp. XR17V[48]35[248] Dual/Quad/Octal/Hexa PCIe UARTs */ 438d0aeaa83SSudip Mukherjee EXAR_DEVICE(EXAR, EXAR_XR17V352, pbn_exar_XR17V35x), 439d0aeaa83SSudip Mukherjee EXAR_DEVICE(EXAR, EXAR_XR17V354, pbn_exar_XR17V35x), 440d0aeaa83SSudip Mukherjee EXAR_DEVICE(EXAR, EXAR_XR17V358, pbn_exar_XR17V35x), 441d0aeaa83SSudip Mukherjee EXAR_DEVICE(EXAR, EXAR_XR17V4358, pbn_exar_XR17V4358), 442d0aeaa83SSudip Mukherjee EXAR_DEVICE(EXAR, EXAR_XR17V8358, pbn_exar_XR17V8358), 443d0aeaa83SSudip Mukherjee EXAR_DEVICE(COMMTECH, COMMTECH_4222PCIE, pbn_exar_XR17V35x), 444d0aeaa83SSudip Mukherjee EXAR_DEVICE(COMMTECH, COMMTECH_4224PCIE, pbn_exar_XR17V35x), 445d0aeaa83SSudip Mukherjee EXAR_DEVICE(COMMTECH, COMMTECH_4228PCIE, pbn_exar_XR17V35x), 446*fc6cc961SJan Kiszka 447*fc6cc961SJan Kiszka EXAR_DEVICE(COMMTECH, COMMTECH_4222PCI335, pbn_fastcom335_2), 448*fc6cc961SJan Kiszka EXAR_DEVICE(COMMTECH, COMMTECH_4224PCI335, pbn_fastcom335_4), 449*fc6cc961SJan Kiszka EXAR_DEVICE(COMMTECH, COMMTECH_2324PCI335, pbn_fastcom335_4), 450*fc6cc961SJan Kiszka EXAR_DEVICE(COMMTECH, COMMTECH_2328PCI335, pbn_fastcom335_8), 451d0aeaa83SSudip Mukherjee { 0, } 452d0aeaa83SSudip Mukherjee }; 453d0aeaa83SSudip Mukherjee MODULE_DEVICE_TABLE(pci, exar_pci_tbl); 454d0aeaa83SSudip Mukherjee 455d0aeaa83SSudip Mukherjee static struct pci_driver exar_pci_driver = { 456d0aeaa83SSudip Mukherjee .name = "exar_serial", 457d0aeaa83SSudip Mukherjee .probe = exar_pci_probe, 458d0aeaa83SSudip Mukherjee .remove = exar_pci_remove, 459d0aeaa83SSudip Mukherjee .driver = { 460d0aeaa83SSudip Mukherjee .pm = &exar_pci_pm, 461d0aeaa83SSudip Mukherjee }, 462d0aeaa83SSudip Mukherjee .id_table = exar_pci_tbl, 463d0aeaa83SSudip Mukherjee }; 464d0aeaa83SSudip Mukherjee module_pci_driver(exar_pci_driver); 465d0aeaa83SSudip Mukherjee 466d0aeaa83SSudip Mukherjee MODULE_LICENSE("GPL"); 467d0aeaa83SSudip Mukherjee MODULE_DESCRIPTION("Exar Serial Dricer"); 468d0aeaa83SSudip Mukherjee MODULE_AUTHOR("Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>"); 469