From 823f7923833c6cc2b16e601546d607dcfb368004 Mon Sep 17 00:00:00 2001 From: Alexander Gerasiov Date: Sun, 4 Feb 2018 02:50:22 +0300 Subject: parport_pc: Add support for WCH CH382L PCI-E single parallel port card. WCH CH382L is a PCI-E adapter with 1 parallel port. It is similair to CH382 but serial ports are not soldered on board. Detected as Serial controller: Device 1c00:3050 (rev 10) (prog-if 05 [16850]) Signed-off-by: Alexander Gerasiov Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_pc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c index 489492b608cf..380916bff9e0 100644 --- a/drivers/parport/parport_pc.c +++ b/drivers/parport/parport_pc.c @@ -2646,6 +2646,7 @@ enum parport_pc_pci_cards { netmos_9901, netmos_9865, quatech_sppxp100, + wch_ch382l, }; @@ -2708,6 +2709,7 @@ static struct parport_pc_pci { /* netmos_9901 */ { 1, { { 0, -1 }, } }, /* netmos_9865 */ { 1, { { 0, -1 }, } }, /* quatech_sppxp100 */ { 1, { { 0, 1 }, } }, + /* wch_ch382l */ { 1, { { 2, -1 }, } }, }; static const struct pci_device_id parport_pc_pci_tbl[] = { @@ -2797,6 +2799,8 @@ static const struct pci_device_id parport_pc_pci_tbl[] = { /* Quatech SPPXP-100 Parallel port PCI ExpressCard */ { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 }, + /* WCH CH382L PCI-E single parallel port card */ + { 0x1c00, 0x3050, 0x1c00, 0x3050, 0, 0, wch_ch382l }, { 0, } /* terminate list */ }; MODULE_DEVICE_TABLE(pci, parport_pc_pci_tbl); -- cgit From d6906e7efa8071f911fd92a35cec57473bca3074 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Wed, 7 Feb 2018 19:47:48 +0000 Subject: parport: ax88796: Delete an error message for a failed memory allocation in parport_ax88796_probe() Omit an extra message for a memory allocation failure in this function. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_ax88796.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_ax88796.c b/drivers/parport/parport_ax88796.c index 2fc91edb058d..ef0aec4b55f3 100644 --- a/drivers/parport/parport_ax88796.c +++ b/drivers/parport/parport_ax88796.c @@ -281,10 +281,8 @@ static int parport_ax88796_probe(struct platform_device *pdev) int ret; dd = kzalloc(sizeof(struct ax_drvdata), GFP_KERNEL); - if (dd == NULL) { - dev_err(_dev, "no memory for private data\n"); + if (!dd) return -ENOMEM; - } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res == NULL) { -- cgit From 5e50654da591efecb02fd9dab032152e4c5d0ca2 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Wed, 7 Feb 2018 19:47:49 +0000 Subject: parport: ax88796: Improve a size determination in parport_ax88796_probe() Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_ax88796.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_ax88796.c b/drivers/parport/parport_ax88796.c index ef0aec4b55f3..09788d8cf467 100644 --- a/drivers/parport/parport_ax88796.c +++ b/drivers/parport/parport_ax88796.c @@ -280,7 +280,7 @@ static int parport_ax88796_probe(struct platform_device *pdev) int irq; int ret; - dd = kzalloc(sizeof(struct ax_drvdata), GFP_KERNEL); + dd = kzalloc(sizeof(*dd), GFP_KERNEL); if (!dd) return -ENOMEM; -- cgit From 520656c03c545011d1da702a261e2c782808b79f Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Wed, 7 Feb 2018 19:47:50 +0000 Subject: parport: ax88796: Delete an unnecessary variable initialisation in parport_ax88796_probe() The local variable "pp" will eventually be set to an appropriate pointer a bit later. Thus omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_ax88796.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_ax88796.c b/drivers/parport/parport_ax88796.c index 09788d8cf467..bfe97c2a8d4c 100644 --- a/drivers/parport/parport_ax88796.c +++ b/drivers/parport/parport_ax88796.c @@ -273,7 +273,7 @@ static int parport_ax88796_probe(struct platform_device *pdev) { struct device *_dev = &pdev->dev; struct ax_drvdata *dd; - struct parport *pp = NULL; + struct parport *pp; struct resource *res; unsigned long size; int spacing; -- cgit From ec8e3893b41d56293f98d499de7dc123d362b2d5 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 7 Feb 2018 19:47:51 +0000 Subject: parport: Add support for BrainBoxes PX272/PX306 MIO card This adds support for BrainBoxes Multi I/O cards (4+1 serial + 1 parallel port): 02:00.0 0702: 135a:4100 (rev 02) Subsystem: 135a:0443 Flags: fast devsel, IRQ 18 Memory at f7d02000 (32-bit, non-prefetchable) [size=128] I/O ports at e000 [size=128] I/O ports at e080 [size=64] I/O ports at e0c0 [size=16] Memory at f7d01000 (32-bit, non-prefetchable) [size=128] Memory at f7d00000 (32-bit, non-prefetchable) [size=128] Capabilities: [50] MSI: Enable- Count=1/4 Maskable- 64bit+ Capabilities: [78] Power Management version 3 Capabilities: [80] Express Legacy Endpoint, MSI 01 Capabilities: [100] Virtual Channel Capabilities: [800] Advanced Error Reporting Reported-by: Nikola Ciprich Tested-by: Nikola Ciprich Signed-off-by: Andy Shevchenko Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_serial.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index e15b4845f7c6..53a3eae65ade 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -65,6 +65,7 @@ enum parport_pc_pci_cards { wch_ch353_1s1p, wch_ch353_2s1p, wch_ch382_2s1p, + brainboxes_5s1p, sunix_2s1p, }; @@ -153,6 +154,7 @@ static struct parport_pc_pci cards[] = { /* wch_ch353_1s1p*/ { 1, { { 1, -1}, } }, /* wch_ch353_2s1p*/ { 1, { { 2, -1}, } }, /* wch_ch382_2s1p*/ { 1, { { 2, -1}, } }, + /* brainboxes_5s1p */ { 1, { { 3, -1 }, } }, /* sunix_2s1p */ { 1, { { 3, -1 }, } }, }; @@ -261,6 +263,10 @@ static struct pci_device_id parport_serial_pci_tbl[] = { { 0x4348, 0x7053, 0x4348, 0x3253, 0, 0, wch_ch353_2s1p}, { 0x1c00, 0x3250, 0x1c00, 0x3250, 0, 0, wch_ch382_2s1p}, + /* BrainBoxes PX272/PX306 MIO card */ + { PCI_VENDOR_ID_INTASHIELD, 0x4100, + PCI_ANY_ID, PCI_ANY_ID, 0, 0, brainboxes_5s1p }, + /* * More SUNIX variations. At least one of these has part number * '5079A but subdevice 0x102. That board reports 0x0708 as @@ -504,6 +510,12 @@ static struct pciserial_board pci_parport_serial_boards[] = { .uart_offset = 8, .first_offset = 0xC0, }, + [brainboxes_5s1p] = { + .flags = FL_BASE2, + .num_ports = 5, + .base_baud = 921600, + .uart_offset = 8, + }, [sunix_2s1p] = { .flags = FL_BASE0|FL_BASE_BARS, .num_ports = 2, -- cgit From 1089c91111a13e93955057e37f6772c0af629a2a Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 7 Feb 2018 19:47:52 +0000 Subject: parport: PCI core handles power state for us There is no need to repeat the work that is already done in the PCI driver core. The patch removes excerpts from suspend and resume callbacks. Note that there is no more calls performed to enable or disable a PCI device during suspend-resume cycle. Nowadays they seems to be superflous. Someone can read more in [1]. While here, convert calls to new driver API. [1] https://www.kernel.org/doc/ols/2009/ols2009-pages-319-330.pdf Tested-by: Nikola Ciprich Signed-off-by: Andy Shevchenko Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_serial.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index 53a3eae65ade..d0a5bc542bac 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -664,57 +664,41 @@ static void parport_serial_pci_remove(struct pci_dev *dev) return; } -#ifdef CONFIG_PM -static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state) +static int __maybe_unused parport_serial_pci_suspend(struct device *dev) { - struct parport_serial_private *priv = pci_get_drvdata(dev); + struct pci_dev *pdev = to_pci_dev(dev); + struct parport_serial_private *priv = pci_get_drvdata(pdev); if (priv->serial) pciserial_suspend_ports(priv->serial); /* FIXME: What about parport? */ - - pci_save_state(dev); - pci_set_power_state(dev, pci_choose_state(dev, state)); return 0; } -static int parport_serial_pci_resume(struct pci_dev *dev) +static int __maybe_unused parport_serial_pci_resume(struct device *dev) { - struct parport_serial_private *priv = pci_get_drvdata(dev); - int err; - - pci_set_power_state(dev, PCI_D0); - pci_restore_state(dev); - - /* - * The device may have been disabled. Re-enable it. - */ - err = pci_enable_device(dev); - if (err) { - printk(KERN_ERR "parport_serial: %s: error enabling " - "device for resume (%d)\n", pci_name(dev), err); - return err; - } + struct pci_dev *pdev = to_pci_dev(dev); + struct parport_serial_private *priv = pci_get_drvdata(pdev); if (priv->serial) pciserial_resume_ports(priv->serial); /* FIXME: What about parport? */ - return 0; } -#endif + +static SIMPLE_DEV_PM_OPS(parport_serial_pm_ops, + parport_serial_pci_suspend, parport_serial_pci_resume); static struct pci_driver parport_serial_pci_driver = { .name = "parport_serial", .id_table = parport_serial_pci_tbl, .probe = parport_serial_pci_probe, .remove = parport_serial_pci_remove, -#ifdef CONFIG_PM - .suspend = parport_serial_pci_suspend, - .resume = parport_serial_pci_resume, -#endif + .driver = { + .pm = &parport_serial_pm_ops, + }, }; -- cgit From ad8ce834bfec77c8ae2fbb3a0593ae87bdecebcb Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 7 Feb 2018 19:47:53 +0000 Subject: parport: Convert to use managed functions pcim_* and devm_* This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier. Tested-by: Nikola Ciprich Signed-off-by: Andy Shevchenko Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_serial.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index d0a5bc542bac..050eeb06913a 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -620,27 +620,23 @@ static int parport_serial_pci_probe(struct pci_dev *dev, struct parport_serial_private *priv; int err; - priv = kzalloc (sizeof *priv, GFP_KERNEL); + priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; + pci_set_drvdata (dev, priv); - err = pci_enable_device (dev); - if (err) { - kfree (priv); + err = pcim_enable_device(dev); + if (err) return err; - } - if (parport_register (dev, id)) { - kfree (priv); + if (parport_register(dev, id)) return -ENODEV; - } if (serial_register (dev, id)) { int i; for (i = 0; i < priv->num_par; i++) parport_pc_unregister_port (priv->port[i]); - kfree (priv); return -ENODEV; } @@ -660,7 +656,6 @@ static void parport_serial_pci_remove(struct pci_dev *dev) for (i = 0; i < priv->num_par; i++) parport_pc_unregister_port (priv->port[i]); - kfree (priv); return; } -- cgit From 96edf5376e9250eb61d2bbc5432c13846878edb2 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 7 Feb 2018 19:47:54 +0000 Subject: parport: Don't shadow error codes in ->probe() When ->probe() calls helper functions return theirs error codes instead of shadowing them. Tested-by: Nikola Ciprich Signed-off-by: Andy Shevchenko Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_serial.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index 050eeb06913a..c222698410c2 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -539,12 +539,10 @@ static int serial_register(struct pci_dev *dev, const struct pci_device_id *id) struct serial_private *serial; board = &pci_parport_serial_boards[id->driver_data]; - if (board->num_ports == 0) return 0; serial = pciserial_init_ports(dev, board); - if (IS_ERR(serial)) return PTR_ERR(serial); @@ -630,14 +628,16 @@ static int parport_serial_pci_probe(struct pci_dev *dev, if (err) return err; - if (parport_register(dev, id)) - return -ENODEV; + err = parport_register(dev, id); + if (err) + return err; - if (serial_register (dev, id)) { + err = serial_register(dev, id); + if (err) { int i; for (i = 0; i < priv->num_par; i++) parport_pc_unregister_port (priv->port[i]); - return -ENODEV; + return err; } return 0; -- cgit From 82dfabf1c4d5f76d2ed854ae30e4af7f7291bf0c Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 7 Feb 2018 19:47:55 +0000 Subject: parport: Convert printk(KERN_WARN) to dev_warn() dev_warn() will print device name with associated driver, no need to keep this open coded. While here, adjust indentation in the rest of dev_dbg() calls. Tested-by: Nikola Ciprich Signed-off-by: Andy Shevchenko Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_serial.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index c222698410c2..c56bb06b82d0 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -571,10 +571,9 @@ static int parport_register(struct pci_dev *dev, const struct pci_device_id *id) int irq; if (priv->num_par == ARRAY_SIZE (priv->port)) { - printk (KERN_WARNING - "parport_serial: %s: only %zu parallel ports " - "supported (%d reported)\n", pci_name (dev), - ARRAY_SIZE(priv->port), card->numports); + dev_warn(&dev->dev, + "only %zu parallel ports supported (%d reported)\n", + ARRAY_SIZE(priv->port), card->numports); break; } @@ -590,12 +589,12 @@ static int parport_register(struct pci_dev *dev, const struct pci_device_id *id) irq = dev->irq; if (irq == IRQ_NONE) { dev_dbg(&dev->dev, - "PCI parallel port detected: I/O at %#lx(%#lx)\n", + "PCI parallel port detected: I/O at %#lx(%#lx)\n", io_lo, io_hi); irq = PARPORT_IRQ_NONE; } else { dev_dbg(&dev->dev, - "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n", + "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n", io_lo, io_hi, irq); } port = parport_pc_probe_port (io_lo, io_hi, irq, -- cgit From b0b0a6438ea5d20ff4b0f64af0f210029d146079 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 7 Feb 2018 19:47:56 +0000 Subject: parport: Switch to use module_pci_driver() macro Eliminate some boilerplate code by using module_pci_driver() instead of init/exit, moving the salient bits from init into probe. Tested-by: Nikola Ciprich Signed-off-by: Andy Shevchenko Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_serial.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index c56bb06b82d0..08e218e67101 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -694,22 +694,8 @@ static struct pci_driver parport_serial_pci_driver = { .pm = &parport_serial_pm_ops, }, }; - - -static int __init parport_serial_init (void) -{ - return pci_register_driver (&parport_serial_pci_driver); -} - -static void __exit parport_serial_exit (void) -{ - pci_unregister_driver (&parport_serial_pci_driver); - return; -} +module_pci_driver(parport_serial_pci_driver); MODULE_AUTHOR("Tim Waugh "); MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards"); MODULE_LICENSE("GPL"); - -module_init(parport_serial_init); -module_exit(parport_serial_exit); -- cgit From 4af5781ad1245fdc8b2faaef72b5ce756639b0c2 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 7 Feb 2018 19:47:57 +0000 Subject: parport: Sort headers alphabetically While here, remove init.h inclusion since we are not using it directly and module.h will do this for us. No functional changes intended. Tested-by: Nikola Ciprich Signed-off-by: Andy Shevchenko Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_serial.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index 08e218e67101..d141e31a52db 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -17,14 +17,14 @@ * */ -#include -#include -#include -#include -#include #include +#include #include #include +#include +#include +#include + #include enum parport_pc_pci_cards { -- cgit From fecae16e696933c8ef5bf971a3fde2aadeaee613 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 7 Feb 2018 19:47:58 +0000 Subject: parport: Replace short License header by SPDX identifier No functional changes involved. Tested-by: Nikola Ciprich Signed-off-by: Andy Shevchenko Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_serial.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'drivers/parport') diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c index d141e31a52db..4f8b26033460 100644 --- a/drivers/parport/parport_serial.c +++ b/drivers/parport/parport_serial.c @@ -1,20 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * Support for common PCI multi-I/O cards (which is most of them) * * Copyright (C) 2001 Tim Waugh * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version - * 2 of the License, or (at your option) any later version. - * - * * Multi-function PCI cards are supposed to present separate logical * devices on the bus. A common thing to do seems to be to just use * one logical device with lots of base address registers for both * parallel ports and serial ports. This driver is for dealing with * that. - * */ #include -- cgit