* [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib
@ 2026-11-23 12:29 Linus Walleij
2026-11-23 12:29 ` [PATCH 1/3] gpio: convert PC8736x " Linus Walleij
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Linus Walleij @ 2026-11-23 12:29 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Linus Walleij,
Bartosz Golaszewski, Christer Weinigel, Jim Cromie, x86,
Lee Jones, Pavel Machek, Griffin Kroah-Hartman
Cc: linux-gpio, linux-leds
This is an obvious attack patch to see if anyone is really using
the custom API from these deviant drivers/char/* GPIO drivers
from the early 2000s.
Probe PC8736x through the ISA bus API and create the SCx200 GPIO device
from its PCI bridge. Register both controllers with gpiolib using port
I/O. Describe the net48xx and WRAP LED GPIOs with software nodes and
switch both LED drivers to descriptors.
Remove the private GPIO API and per-pin character devices. We assume
there are no remaining users of the old NSC GPIO userspace ABI.
An LLM assisted in the implementation and x86-32 build checks.
---
Linus Walleij (3):
gpio: convert PC8736x to gpiolib
gpio: convert SCx200 to gpiolib and use descriptors for board LEDs
gpio: remove the legacy NSC GPIO API
MAINTAINERS | 6 +-
arch/x86/platform/scx200/scx200_32.c | 90 ++++-----
drivers/char/Kconfig | 33 ----
drivers/char/Makefile | 3 -
drivers/char/nsc_gpio.c | 126 -------------
drivers/char/pc8736x_gpio.c | 352 -----------------------------------
drivers/char/scx200_gpio.c | 138 --------------
drivers/gpio/Kconfig | 22 +++
drivers/gpio/Makefile | 2 +
drivers/gpio/gpio-pc8736x.c | 264 ++++++++++++++++++++++++++
drivers/gpio/gpio-scx200.c | 245 ++++++++++++++++++++++++
drivers/leds/leds-net48xx.c | 85 +++++----
drivers/leds/leds-wrap.c | 143 +++++++-------
include/linux/nsc_gpio.h | 41 ----
include/linux/scx200.h | 1 +
include/linux/scx200_gpio.h | 89 ---------
16 files changed, 697 insertions(+), 943 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261123-b4-nsc-gpio-87547fbbf7b4
Best regards,
--
Linus Walleij <linusw@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] gpio: convert PC8736x to gpiolib
2026-11-23 12:29 [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib Linus Walleij
@ 2026-11-23 12:29 ` Linus Walleij
2026-11-23 12:29 ` [PATCH 2/3] gpio: convert SCx200 to gpiolib and use descriptors for board LEDs Linus Walleij
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2026-11-23 12:29 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Linus Walleij,
Bartosz Golaszewski, Christer Weinigel, Jim Cromie, x86,
Lee Jones, Pavel Machek, Griffin Kroah-Hartman
Cc: linux-gpio, linux-leds
Move the PC8736x over to gpiolib.
Keep the legacy character device during the conversion. Both interfaces
use the same register access and locking.
Link: https://dtsheet.com/doc/85223/nsc-pc87365
Link: https://datasheet4u.com/pdf/36121/PC87366.pdf
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
MAINTAINERS | 2 +-
drivers/char/Kconfig | 13 --
drivers/char/Makefile | 1 -
drivers/char/pc8736x_gpio.c | 352 -----------------------------------------
drivers/gpio/Kconfig | 13 ++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-pc8736x.c | 376 ++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 391 insertions(+), 367 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065..9a047fd0a6a3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -21262,7 +21262,7 @@ F: drivers/hwmon/pc87360.c
PC8736x GPIO DRIVER
M: Jim Cromie <jim.cromie@gmail.com>
S: Maintained
-F: drivers/char/pc8736x_gpio.c
+F: drivers/gpio/gpio-pc8736x.c
PC87427 HARDWARE MONITORING DRIVER
M: Jean Delvare <jdelvare@suse.com>
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 9865227af167..91683c54d509 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -233,19 +233,6 @@ config SCx200_GPIO
If compiled as a module, it will be called scx200_gpio.
-config PC8736x_GPIO
- tristate "NatSemi PC8736x GPIO Support"
- depends on X86_32 && !UML
- default SCx200_GPIO # mostly N
- select NSC_GPIO # needed for support routines
- help
- Give userspace access to the GPIO pins on the National
- Semiconductor PC-8736x (x=[03456]) SuperIO chip. The chip
- has multiple functional units, inc several managed by
- hwmon/pc87360 driver. Tested with PC-87366
-
- If compiled as a module, it will be called pc8736x_gpio.
-
config NSC_GPIO
tristate "NatSemi Base GPIO Support"
depends on X86_32
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index bb3bf66937b3..09ae0a6fba87 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -27,7 +27,6 @@ obj-$(CONFIG_PPDEV) += ppdev.o
obj-$(CONFIG_NWBUTTON) += nwbutton.o
obj-$(CONFIG_NWFLASH) += nwflash.o
obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
-obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
obj-$(CONFIG_TELCLOCK) += tlclk.o
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c
deleted file mode 100644
index 5f4696813cea..000000000000
--- a/drivers/char/pc8736x_gpio.c
+++ /dev/null
@@ -1,352 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/* linux/drivers/char/pc8736x_gpio.c
-
- National Semiconductor PC8736x GPIO driver. Allows a user space
- process to play with the GPIO pins.
-
- Copyright (c) 2005,2006 Jim Cromie <jim.cromie@gmail.com>
-
- adapted from linux/drivers/char/scx200_gpio.c
- Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>,
-*/
-
-#include <linux/fs.h>
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/cdev.h>
-#include <linux/io.h>
-#include <linux/ioport.h>
-#include <linux/mutex.h>
-#include <linux/nsc_gpio.h>
-#include <linux/platform_device.h>
-#include <linux/uaccess.h>
-
-#define DEVNAME "pc8736x_gpio"
-
-MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
-MODULE_DESCRIPTION("NatSemi/Winbond PC-8736x GPIO Pin Driver");
-MODULE_LICENSE("GPL");
-
-static int major; /* default to dynamic major */
-module_param(major, int, 0);
-MODULE_PARM_DESC(major, "Major device number");
-
-static DEFINE_MUTEX(pc8736x_gpio_config_lock);
-static unsigned pc8736x_gpio_base;
-static u8 pc8736x_gpio_shadow[4];
-
-#define SIO_BASE1 0x2E /* 1st command-reg to check */
-#define SIO_BASE2 0x4E /* alt command-reg to check */
-
-#define SIO_SID 0x20 /* SuperI/O ID Register */
-#define SIO_SID_PC87365 0xe5 /* Expected value in ID Register for PC87365 */
-#define SIO_SID_PC87366 0xe9 /* Expected value in ID Register for PC87366 */
-
-#define SIO_CF1 0x21 /* chip config, bit0 is chip enable */
-
-#define PC8736X_GPIO_RANGE 16 /* ioaddr range */
-#define PC8736X_GPIO_CT 32 /* minors matching 4 8 bit ports */
-
-#define SIO_UNIT_SEL 0x7 /* unit select reg */
-#define SIO_UNIT_ACT 0x30 /* unit enable */
-#define SIO_GPIO_UNIT 0x7 /* unit number of GPIO */
-#define SIO_VLM_UNIT 0x0D
-#define SIO_TMS_UNIT 0x0E
-
-/* config-space addrs to read/write each unit's runtime addr */
-#define SIO_BASE_HADDR 0x60
-#define SIO_BASE_LADDR 0x61
-
-/* GPIO config-space pin-control addresses */
-#define SIO_GPIO_PIN_SELECT 0xF0
-#define SIO_GPIO_PIN_CONFIG 0xF1
-#define SIO_GPIO_PIN_EVENT 0xF2
-
-static unsigned char superio_cmd = 0;
-static unsigned char selected_device = 0xFF; /* bogus start val */
-
-/* GPIO port runtime access, functionality */
-static int port_offset[] = { 0, 4, 8, 10 }; /* non-uniform offsets ! */
-/* static int event_capable[] = { 1, 1, 0, 0 }; ports 2,3 are hobbled */
-
-#define PORT_OUT 0
-#define PORT_IN 1
-#define PORT_EVT_EN 2
-#define PORT_EVT_STST 3
-
-static struct platform_device *pdev; /* use in dev_*() */
-
-static inline void superio_outb(int addr, int val)
-{
- outb_p(addr, superio_cmd);
- outb_p(val, superio_cmd + 1);
-}
-
-static inline int superio_inb(int addr)
-{
- outb_p(addr, superio_cmd);
- return inb_p(superio_cmd + 1);
-}
-
-static int pc8736x_superio_present(void)
-{
- int id;
-
- /* try the 2 possible values, read a hardware reg to verify */
- superio_cmd = SIO_BASE1;
- id = superio_inb(SIO_SID);
- if (id == SIO_SID_PC87365 || id == SIO_SID_PC87366)
- return superio_cmd;
-
- superio_cmd = SIO_BASE2;
- id = superio_inb(SIO_SID);
- if (id == SIO_SID_PC87365 || id == SIO_SID_PC87366)
- return superio_cmd;
-
- return 0;
-}
-
-static void device_select(unsigned devldn)
-{
- superio_outb(SIO_UNIT_SEL, devldn);
- selected_device = devldn;
-}
-
-static void select_pin(unsigned iminor)
-{
- /* select GPIO port/pin from device minor number */
- device_select(SIO_GPIO_UNIT);
- superio_outb(SIO_GPIO_PIN_SELECT,
- ((iminor << 1) & 0xF0) | (iminor & 0x7));
-}
-
-static inline u32 pc8736x_gpio_configure_fn(unsigned index, u32 mask, u32 bits,
- u32 func_slct)
-{
- u32 config, new_config;
-
- mutex_lock(&pc8736x_gpio_config_lock);
-
- device_select(SIO_GPIO_UNIT);
- select_pin(index);
-
- /* read current config value */
- config = superio_inb(func_slct);
-
- /* set new config */
- new_config = (config & mask) | bits;
- superio_outb(func_slct, new_config);
-
- mutex_unlock(&pc8736x_gpio_config_lock);
-
- return config;
-}
-
-static u32 pc8736x_gpio_configure(unsigned index, u32 mask, u32 bits)
-{
- return pc8736x_gpio_configure_fn(index, mask, bits,
- SIO_GPIO_PIN_CONFIG);
-}
-
-static int pc8736x_gpio_get(unsigned minor)
-{
- int port, bit, val;
-
- port = minor >> 3;
- bit = minor & 7;
- val = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_IN);
- val >>= bit;
- val &= 1;
-
- dev_dbg(&pdev->dev, "_gpio_get(%d from %x bit %d) == val %d\n",
- minor, pc8736x_gpio_base + port_offset[port] + PORT_IN, bit,
- val);
-
- return val;
-}
-
-static void pc8736x_gpio_set(unsigned minor, int val)
-{
- int port, bit, curval;
-
- minor &= 0x1f;
- port = minor >> 3;
- bit = minor & 7;
- curval = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_OUT);
-
- dev_dbg(&pdev->dev, "addr:%x cur:%x bit-pos:%d cur-bit:%x + new:%d -> bit-new:%d\n",
- pc8736x_gpio_base + port_offset[port] + PORT_OUT,
- curval, bit, (curval & ~(1 << bit)), val, (val << bit));
-
- val = (curval & ~(1 << bit)) | (val << bit);
-
- dev_dbg(&pdev->dev, "gpio_set(minor:%d port:%d bit:%d)"
- " %2x -> %2x\n", minor, port, bit, curval, val);
-
- outb_p(val, pc8736x_gpio_base + port_offset[port] + PORT_OUT);
-
- curval = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_OUT);
- val = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_IN);
-
- dev_dbg(&pdev->dev, "wrote %x, read: %x\n", curval, val);
- pc8736x_gpio_shadow[port] = val;
-}
-
-static int pc8736x_gpio_current(unsigned minor)
-{
- int port, bit;
- minor &= 0x1f;
- port = minor >> 3;
- bit = minor & 7;
- return ((pc8736x_gpio_shadow[port] >> bit) & 0x01);
-}
-
-static void pc8736x_gpio_change(unsigned index)
-{
- pc8736x_gpio_set(index, !pc8736x_gpio_current(index));
-}
-
-static struct nsc_gpio_ops pc8736x_gpio_ops = {
- .owner = THIS_MODULE,
- .gpio_config = pc8736x_gpio_configure,
- .gpio_dump = nsc_gpio_dump,
- .gpio_get = pc8736x_gpio_get,
- .gpio_set = pc8736x_gpio_set,
- .gpio_change = pc8736x_gpio_change,
- .gpio_current = pc8736x_gpio_current
-};
-
-static int pc8736x_gpio_open(struct inode *inode, struct file *file)
-{
- unsigned m = iminor(inode);
- file->private_data = &pc8736x_gpio_ops;
-
- dev_dbg(&pdev->dev, "open %d\n", m);
-
- if (m >= PC8736X_GPIO_CT)
- return -EINVAL;
- return nonseekable_open(inode, file);
-}
-
-static const struct file_operations pc8736x_gpio_fileops = {
- .owner = THIS_MODULE,
- .open = pc8736x_gpio_open,
- .write = nsc_gpio_write,
- .read = nsc_gpio_read,
-};
-
-static void __init pc8736x_init_shadow(void)
-{
- int port;
-
- /* read the current values driven on the GPIO signals */
- for (port = 0; port < 4; ++port)
- pc8736x_gpio_shadow[port]
- = inb_p(pc8736x_gpio_base + port_offset[port]
- + PORT_OUT);
-
-}
-
-static struct cdev pc8736x_gpio_cdev;
-
-static int __init pc8736x_gpio_init(void)
-{
- int rc;
- dev_t devid;
-
- pdev = platform_device_alloc(DEVNAME, 0);
- if (!pdev)
- return -ENOMEM;
-
- rc = platform_device_add(pdev);
- if (rc) {
- rc = -ENODEV;
- goto undo_platform_dev_alloc;
- }
- dev_info(&pdev->dev, "NatSemi pc8736x GPIO Driver Initializing\n");
-
- if (!pc8736x_superio_present()) {
- rc = -ENODEV;
- dev_err(&pdev->dev, "no device found\n");
- goto undo_platform_dev_add;
- }
- pc8736x_gpio_ops.dev = &pdev->dev;
-
- /* Verify that chip and it's GPIO unit are both enabled.
- My BIOS does this, so I take minimum action here
- */
- rc = superio_inb(SIO_CF1);
- if (!(rc & 0x01)) {
- rc = -ENODEV;
- dev_err(&pdev->dev, "device not enabled\n");
- goto undo_platform_dev_add;
- }
- device_select(SIO_GPIO_UNIT);
- if (!superio_inb(SIO_UNIT_ACT)) {
- rc = -ENODEV;
- dev_err(&pdev->dev, "GPIO unit not enabled\n");
- goto undo_platform_dev_add;
- }
-
- /* read the GPIO unit base addr that chip responds to */
- pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8
- | superio_inb(SIO_BASE_LADDR));
-
- if (!request_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE, DEVNAME)) {
- rc = -ENODEV;
- dev_err(&pdev->dev, "GPIO ioport %x busy\n",
- pc8736x_gpio_base);
- goto undo_platform_dev_add;
- }
- dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base);
-
- if (major) {
- devid = MKDEV(major, 0);
- rc = register_chrdev_region(devid, PC8736X_GPIO_CT, DEVNAME);
- } else {
- rc = alloc_chrdev_region(&devid, 0, PC8736X_GPIO_CT, DEVNAME);
- major = MAJOR(devid);
- }
-
- if (rc < 0) {
- dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc);
- goto undo_request_region;
- }
- if (!major) {
- major = rc;
- dev_dbg(&pdev->dev, "got dynamic major %d\n", major);
- }
-
- pc8736x_init_shadow();
-
- /* ignore minor errs, and succeed */
- cdev_init(&pc8736x_gpio_cdev, &pc8736x_gpio_fileops);
- cdev_add(&pc8736x_gpio_cdev, devid, PC8736X_GPIO_CT);
-
- return 0;
-
-undo_request_region:
- release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE);
-undo_platform_dev_add:
- platform_device_del(pdev);
-undo_platform_dev_alloc:
- platform_device_put(pdev);
-
- return rc;
-}
-
-static void __exit pc8736x_gpio_cleanup(void)
-{
- dev_dbg(&pdev->dev, "cleanup\n");
-
- cdev_del(&pc8736x_gpio_cdev);
- unregister_chrdev_region(MKDEV(major,0), PC8736X_GPIO_CT);
- release_region(pc8736x_gpio_base, PC8736X_GPIO_RANGE);
-
- platform_device_unregister(pdev);
-}
-
-module_init(pc8736x_gpio_init);
-module_exit(pc8736x_gpio_cleanup);
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 55e4280029d8..808acc5b7f5c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1093,6 +1093,19 @@ config GPIO_IT87
To compile this driver as a module, choose M here: the module will
be called gpio_it87.
+config PC8736x_GPIO
+ tristate "NatSemi PC87365/PC87366 GPIO support"
+ depends on X86_32
+ default SCx200_GPIO
+ select ISA_BUS_API
+ select NSC_GPIO
+ help
+ Support the GPIO controller in the National Semiconductor
+ PC87365 and PC87366 Super I/O chips. The GPIO logical device
+ must already be enabled by the firmware.
+
+ This driver can also be built as a module called gpio-pc8736x.
+
config GPIO_SCH
tristate "Intel SCH/TunnelCreek/Centerton/Quark X1000 GPIO"
depends on (X86 || COMPILE_TEST) && ACPI
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 88f748846e60..05e8442a6d67 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -142,6 +142,7 @@ obj-$(CONFIG_GPIO_NPCM_SGPIO) += gpio-npcm-sgpio.o
obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o
obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o
obj-$(CONFIG_GPIO_PALMAS) += gpio-palmas.o
+obj-$(CONFIG_PC8736x_GPIO) += gpio-pc8736x.o
obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o
obj-$(CONFIG_GPIO_PCA9570) += gpio-pca9570.o
obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o
diff --git a/drivers/gpio/gpio-pc8736x.c b/drivers/gpio/gpio-pc8736x.c
new file mode 100644
index 000000000000..5c18903b1add
--- /dev/null
+++ b/drivers/gpio/gpio-pc8736x.c
@@ -0,0 +1,376 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * National Semiconductor PC87365/PC87366 GPIO driver.
+ *
+ * Copyright (c) 2005,2006 Jim Cromie <jim.cromie@gmail.com>
+ * Adapted from the SCx200 GPIO driver.
+ * Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
+ */
+
+#include <linux/bitops.h>
+#include <linux/cdev.h>
+#include <linux/cleanup.h>
+#include <linux/fs.h>
+#include <linux/gpio/driver.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/isa.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/nsc_gpio.h>
+#include <linux/pinctrl/pinconf-generic.h>
+
+#define DRVNAME "gpio-pc8736x"
+#define LEGACY_NAME "pc8736x_gpio"
+
+#define SIO_BASE1 0x2e
+#define SIO_BASE2 0x4e
+#define SIO_SID 0x20
+#define SIO_SID_PC87365 0xe5
+#define SIO_SID_PC87366 0xe9
+#define SIO_CF1 0x21
+#define SIO_UNIT_SEL 0x07
+#define SIO_UNIT_ACT 0x30
+#define SIO_GPIO_UNIT 0x07
+#define SIO_BASE_HADDR 0x60
+#define SIO_BASE_LADDR 0x61
+#define SIO_GPIO_PIN_SELECT 0xf0
+#define SIO_GPIO_PIN_CONFIG 0xf1
+
+#define PC8736X_GPIO_RANGE 16
+#define PC8736X_NGPIO 29
+#define LEGACY_NGPIO 32
+#define PC8736X_GPIO_PORT_OUT 0
+#define PC8736X_GPIO_PORT_IN 1
+#define PC8736X_GPIO_OUTPUT_ENABLE BIT(0)
+#define PC8736X_GPIO_PUSH_PULL BIT(1)
+#define PC8736X_GPIO_PULL_UP BIT(2)
+#define PC8736X_GPIO_LOCK BIT(3)
+
+struct pc8736x_gpio {
+ struct gpio_chip gc;
+ struct mutex lock; /* Serializes pin selection and output updates. */
+ unsigned int base;
+ unsigned int sio;
+};
+
+static const unsigned int port_offset[] = { 0, 4, 8, 10 };
+
+static void superio_write(unsigned int sio, u8 reg, u8 value)
+{
+ outb_p(reg, sio);
+ outb_p(value, sio + 1);
+}
+
+static u8 superio_read(unsigned int sio, u8 reg)
+{
+ outb_p(reg, sio);
+ return inb_p(sio + 1);
+}
+
+static bool pc8736x_present(unsigned int sio)
+{
+ u8 id = superio_read(sio, SIO_SID);
+
+ return id == SIO_SID_PC87365 || id == SIO_SID_PC87366;
+}
+
+static u8 pc8736x_select_pin(struct pc8736x_gpio *gpio, unsigned int offset)
+{
+ superio_write(gpio->sio, SIO_UNIT_SEL, SIO_GPIO_UNIT);
+ superio_write(gpio->sio, SIO_GPIO_PIN_SELECT,
+ (offset / 8 << 4) | (offset % 8));
+ return superio_read(gpio->sio, SIO_GPIO_PIN_CONFIG);
+}
+
+static int pc8736x_gpio_get(struct gpio_chip *gc, unsigned int offset)
+{
+ struct pc8736x_gpio *gpio = gpiochip_get_data(gc);
+ unsigned int port = gpio->base + port_offset[offset / 8];
+
+ return !!(inb_p(port + PC8736X_GPIO_PORT_IN) & BIT(offset % 8));
+}
+
+static int pc8736x_gpio_write(struct pc8736x_gpio *gpio, unsigned int offset,
+ int value)
+{
+ unsigned int port = gpio->base + port_offset[offset / 8] +
+ PC8736X_GPIO_PORT_OUT;
+ u8 mask = BIT(offset % 8);
+ u8 data = inb_p(port);
+ u8 new_data = (data & ~mask) | (value ? mask : 0);
+
+ if (new_data == data)
+ return 0;
+
+ outb_p(new_data, port);
+
+ /* The hardware ignores writes to a locked line. */
+ return (inb_p(port) & mask) == (new_data & mask) ? 0 : -EPERM;
+}
+
+static int pc8736x_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
+{
+ struct pc8736x_gpio *gpio = gpiochip_get_data(gc);
+
+ guard(mutex)(&gpio->lock);
+ return pc8736x_gpio_write(gpio, offset, value);
+}
+
+static int pc8736x_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
+{
+ struct pc8736x_gpio *gpio = gpiochip_get_data(gc);
+
+ guard(mutex)(&gpio->lock);
+ return pc8736x_select_pin(gpio, offset) & PC8736X_GPIO_OUTPUT_ENABLE ?
+ GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
+}
+
+static int pc8736x_gpio_update_config(struct pc8736x_gpio *gpio, u8 config,
+ u8 mask, u8 value)
+{
+ u8 new_config = (config & ~mask) | value;
+
+ if (new_config == config)
+ return 0;
+ if (config & PC8736X_GPIO_LOCK)
+ return -EPERM;
+
+ superio_write(gpio->sio, SIO_GPIO_PIN_CONFIG, new_config);
+ return 0;
+}
+
+static int pc8736x_gpio_direction_input(struct gpio_chip *gc, unsigned int offset)
+{
+ struct pc8736x_gpio *gpio = gpiochip_get_data(gc);
+ u8 config;
+
+ guard(mutex)(&gpio->lock);
+ config = pc8736x_select_pin(gpio, offset);
+ return pc8736x_gpio_update_config(gpio, config,
+ PC8736X_GPIO_OUTPUT_ENABLE, 0);
+}
+
+static int pc8736x_gpio_direction_output(struct gpio_chip *gc,
+ unsigned int offset, int value)
+{
+ struct pc8736x_gpio *gpio = gpiochip_get_data(gc);
+ u8 config;
+ int ret;
+
+ guard(mutex)(&gpio->lock);
+ config = pc8736x_select_pin(gpio, offset);
+ if ((config & PC8736X_GPIO_LOCK) && !(config & PC8736X_GPIO_OUTPUT_ENABLE))
+ return -EPERM;
+
+ ret = pc8736x_gpio_write(gpio, offset, value);
+ if (ret)
+ return ret;
+
+ return pc8736x_gpio_update_config(gpio, config, PC8736X_GPIO_OUTPUT_ENABLE,
+ PC8736X_GPIO_OUTPUT_ENABLE);
+}
+
+static int pc8736x_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
+ unsigned long config)
+{
+ struct pc8736x_gpio *gpio = gpiochip_get_data(gc);
+ u8 mask, value, old_config;
+
+ switch (pinconf_to_config_param(config)) {
+ case PIN_CONFIG_DRIVE_OPEN_DRAIN:
+ mask = PC8736X_GPIO_PUSH_PULL;
+ value = 0;
+ break;
+ case PIN_CONFIG_DRIVE_PUSH_PULL:
+ mask = PC8736X_GPIO_PUSH_PULL;
+ value = PC8736X_GPIO_PUSH_PULL;
+ break;
+ case PIN_CONFIG_BIAS_DISABLE:
+ mask = PC8736X_GPIO_PULL_UP;
+ value = 0;
+ break;
+ case PIN_CONFIG_BIAS_PULL_UP:
+ mask = PC8736X_GPIO_PULL_UP;
+ value = PC8736X_GPIO_PULL_UP;
+ break;
+ default:
+ return -ENOTSUPP;
+ }
+
+ guard(mutex)(&gpio->lock);
+ old_config = pc8736x_select_pin(gpio, offset);
+ return pc8736x_gpio_update_config(gpio, old_config, mask, value);
+}
+
+static int major;
+module_param(major, int, 0);
+MODULE_PARM_DESC(major, "Major device number for the legacy interface");
+
+static struct pc8736x_gpio *pc8736x_legacy_gpio;
+static struct cdev pc8736x_gpio_cdev;
+static dev_t pc8736x_devt;
+static u8 pc8736x_legacy_shadow[ARRAY_SIZE(port_offset)];
+
+static u32 pc8736x_legacy_config(unsigned int offset, u32 mask, u32 value)
+{
+ struct pc8736x_gpio *gpio = pc8736x_legacy_gpio;
+ u8 config;
+
+ guard(mutex)(&gpio->lock);
+ config = pc8736x_select_pin(gpio, offset);
+ pc8736x_gpio_update_config(gpio, config, ~mask, value);
+ return config;
+}
+
+static int pc8736x_legacy_get(unsigned int offset)
+{
+ struct pc8736x_gpio *gpio = pc8736x_legacy_gpio;
+
+ return pc8736x_gpio_get(&gpio->gc, offset);
+}
+
+static void pc8736x_legacy_set(unsigned int offset, int value)
+{
+ struct pc8736x_gpio *gpio = pc8736x_legacy_gpio;
+ unsigned int port = offset / 8;
+
+ guard(mutex)(&gpio->lock);
+ pc8736x_gpio_write(gpio, offset, value);
+ pc8736x_legacy_shadow[port] =
+ inb_p(gpio->base + port_offset[port] + PC8736X_GPIO_PORT_IN);
+}
+
+static int pc8736x_legacy_current(unsigned int offset)
+{
+ return !!(READ_ONCE(pc8736x_legacy_shadow[offset / 8]) & BIT(offset % 8));
+}
+
+static struct nsc_gpio_ops pc8736x_legacy_ops = {
+ .gpio_config = pc8736x_legacy_config,
+ .gpio_dump = nsc_gpio_dump,
+ .gpio_get = pc8736x_legacy_get,
+ .gpio_set = pc8736x_legacy_set,
+ .gpio_current = pc8736x_legacy_current,
+};
+
+static int pc8736x_legacy_open(struct inode *inode, struct file *file)
+{
+ file->private_data = &pc8736x_legacy_ops;
+ return nonseekable_open(inode, file);
+}
+
+static const struct file_operations pc8736x_legacy_fops = {
+ .owner = THIS_MODULE,
+ .open = pc8736x_legacy_open,
+ .read = nsc_gpio_read,
+ .write = nsc_gpio_write,
+};
+
+static int pc8736x_legacy_register(struct pc8736x_gpio *gpio)
+{
+ int ret, port;
+
+ for (port = 0; port < ARRAY_SIZE(port_offset); port++)
+ pc8736x_legacy_shadow[port] =
+ inb_p(gpio->base + port_offset[port] + PC8736X_GPIO_PORT_OUT);
+
+ if (major) {
+ pc8736x_devt = MKDEV(major, 0);
+ ret = register_chrdev_region(pc8736x_devt, LEGACY_NGPIO, LEGACY_NAME);
+ } else {
+ ret = alloc_chrdev_region(&pc8736x_devt, 0, LEGACY_NGPIO, LEGACY_NAME);
+ }
+ if (ret)
+ return ret;
+
+ pc8736x_legacy_gpio = gpio;
+ pc8736x_legacy_ops.dev = gpio->gc.parent;
+ cdev_init(&pc8736x_gpio_cdev, &pc8736x_legacy_fops);
+ pc8736x_gpio_cdev.owner = THIS_MODULE;
+ ret = cdev_add(&pc8736x_gpio_cdev, pc8736x_devt, LEGACY_NGPIO);
+ if (ret)
+ unregister_chrdev_region(pc8736x_devt, LEGACY_NGPIO);
+
+ return ret;
+}
+
+static int pc8736x_gpio_probe(struct device *dev, unsigned int id)
+{
+ struct pc8736x_gpio *gpio;
+ unsigned int sio, base;
+ int ret;
+
+ if (pc8736x_present(SIO_BASE1))
+ sio = SIO_BASE1;
+ else if (pc8736x_present(SIO_BASE2))
+ sio = SIO_BASE2;
+ else
+ return -ENODEV;
+
+ if (!(superio_read(sio, SIO_CF1) & BIT(0)))
+ return -ENODEV;
+
+ superio_write(sio, SIO_UNIT_SEL, SIO_GPIO_UNIT);
+ if (!(superio_read(sio, SIO_UNIT_ACT) & BIT(0)))
+ return -ENODEV;
+
+ base = superio_read(sio, SIO_BASE_HADDR) << 8 |
+ superio_read(sio, SIO_BASE_LADDR);
+ if (!base)
+ return -ENODEV;
+
+ gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL);
+ if (!gpio)
+ return -ENOMEM;
+
+ if (!devm_request_region(dev, base, PC8736X_GPIO_RANGE, DRVNAME))
+ return -EBUSY;
+
+ gpio->base = base;
+ gpio->sio = sio;
+ mutex_init(&gpio->lock);
+ gpio->gc = (struct gpio_chip) {
+ .label = DRVNAME,
+ .parent = dev,
+ .owner = THIS_MODULE,
+ .base = -1,
+ .ngpio = PC8736X_NGPIO,
+ .can_sleep = true,
+ .get = pc8736x_gpio_get,
+ .set = pc8736x_gpio_set,
+ .get_direction = pc8736x_gpio_get_direction,
+ .direction_input = pc8736x_gpio_direction_input,
+ .direction_output = pc8736x_gpio_direction_output,
+ .set_config = pc8736x_gpio_set_config,
+ };
+
+ ret = devm_gpiochip_add_data(dev, &gpio->gc, gpio);
+ if (ret)
+ return ret;
+
+ return pc8736x_legacy_register(gpio);
+}
+
+static void pc8736x_gpio_remove(struct device *dev, unsigned int id)
+{
+ cdev_del(&pc8736x_gpio_cdev);
+ unregister_chrdev_region(pc8736x_devt, LEGACY_NGPIO);
+}
+
+static struct isa_driver pc8736x_gpio_driver = {
+ .driver = {
+ .name = DRVNAME,
+ .owner = THIS_MODULE,
+ /* An open legacy GPIO file pins the module, but not the chip. */
+ .suppress_bind_attrs = true,
+ },
+ .probe = pc8736x_gpio_probe,
+ .remove = pc8736x_gpio_remove,
+};
+module_isa_driver(pc8736x_gpio_driver, 1);
+
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_DESCRIPTION("NatSemi/Winbond PC87365/PC87366 GPIO driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS(LEGACY_NAME);
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] gpio: convert SCx200 to gpiolib and use descriptors for board LEDs
2026-11-23 12:29 [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib Linus Walleij
2026-11-23 12:29 ` [PATCH 1/3] gpio: convert PC8736x " Linus Walleij
@ 2026-11-23 12:29 ` Linus Walleij
2026-11-23 12:29 ` [PATCH 3/3] gpio: remove the legacy NSC GPIO API Linus Walleij
2026-11-23 12:54 ` [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib Greg Kroah-Hartman
3 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2026-11-23 12:29 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Linus Walleij,
Bartosz Golaszewski, Christer Weinigel, Jim Cromie, x86,
Lee Jones, Pavel Machek, Griffin Kroah-Hartman
Cc: linux-gpio, linux-leds
Create a platform device for the GPIO I/O ports of the SCx200 PCI
bridge. Keep the configuration block in the PCI driver for the timer,
watchdog and flash drivers.
Expose the first GPIO bank. Exclude the package-reserved pins on the
SC1100 and SCx200 variants. Serialize updates to the output latch and
indexed configuration registers.
Keep the legacy character device
working through the same register operations for now.
Attach a software node to the GPIO provider. Reference that node from
the net48xx and WRAP LED devices and switch both LED drivers to GPIO
descriptors.
Link: https://datasheets.chipdb.org/upload/National/SC1100.pdf
Link: https://cdn.semikey.com/upload/pdfs/8f/b4/8fb489d21840a8793e4f3fe15cf5b5c2.pdf
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
MAINTAINERS | 4 +-
arch/x86/platform/scx200/scx200_32.c | 90 +++-----
drivers/char/Kconfig | 10 -
drivers/char/Makefile | 1 -
drivers/char/scx200_gpio.c | 138 ------------
drivers/gpio/Kconfig | 11 +
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-scx200.c | 400 +++++++++++++++++++++++++++++++++++
drivers/leds/leds-net48xx.c | 85 +++++---
drivers/leds/leds-wrap.c | 143 +++++++------
include/linux/scx200.h | 1 +
include/linux/scx200_gpio.h | 89 --------
12 files changed, 575 insertions(+), 398 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 9a047fd0a6a3..01e5a74a9d8d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25256,8 +25256,8 @@ F: include/linux/scx200.h
SCx200 GPIO DRIVER
M: Jim Cromie <jim.cromie@gmail.com>
S: Maintained
-F: drivers/char/scx200_gpio.c
-F: include/linux/scx200_gpio.h
+F: drivers/gpio/gpio-scx200.c
+F: include/linux/scx200.h
SCx200 HRT CLOCKSOURCE DRIVER
M: Jim Cromie <jim.cromie@gmail.com>
diff --git a/arch/x86/platform/scx200/scx200_32.c b/arch/x86/platform/scx200/scx200_32.c
index 80662b72035d..b60ec11b4398 100644
--- a/arch/x86/platform/scx200/scx200_32.c
+++ b/arch/x86/platform/scx200/scx200_32.c
@@ -9,11 +9,10 @@
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
-#include <linux/mutex.h>
#include <linux/pci.h>
+#include <linux/platform_device.h>
#include <linux/scx200.h>
-#include <linux/scx200_gpio.h>
/* Verify that the configuration block really is there */
#define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))
@@ -22,9 +21,6 @@ MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
MODULE_DESCRIPTION("NatSemi SCx200 Driver");
MODULE_LICENSE("GPL");
-unsigned scx200_gpio_base = 0;
-unsigned long scx200_gpio_shadow[2];
-
unsigned scx200_cb_base = 0;
static struct pci_device_id scx200_tbl[] = {
@@ -44,15 +40,31 @@ static struct pci_driver scx200_pci_driver = {
.probe = scx200_probe,
};
-static DEFINE_MUTEX(scx200_gpio_config_lock);
+static void scx200_unregister_gpio(void *data)
+{
+ platform_device_unregister(data);
+}
-static void scx200_init_shadow(void)
+static int scx200_register_gpio(struct pci_dev *pdev)
{
- int bank;
+ struct resource res = DEFINE_RES_IO(pci_resource_start(pdev, 0),
+ SCx200_GPIO_SIZE);
+ struct platform_device *gpio;
+
+ if (!IS_ENABLED(CONFIG_SCx200_GPIO))
+ return 0;
- /* read the current values driven on the GPIO signals */
- for (bank = 0; bank < 2; ++bank)
- scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
+ if (!(pci_resource_flags(pdev, 0) & IORESOURCE_IO) || !res.start ||
+ pci_resource_len(pdev, 0) < SCx200_GPIO_SIZE)
+ return -ENODEV;
+
+ gpio = platform_device_register_resndata(&pdev->dev, "gpio-scx200",
+ PLATFORM_DEVID_NONE, &res, 1,
+ NULL, 0);
+ if (IS_ERR(gpio))
+ return PTR_ERR(gpio);
+
+ return devm_add_action_or_reset(&pdev->dev, scx200_unregister_gpio, gpio);
}
static int scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -60,55 +72,25 @@ static int scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
unsigned base;
if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
- pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
- base = pci_resource_start(pdev, 0);
- pr_info("GPIO base 0x%x\n", base);
-
- if (!request_region(base, SCx200_GPIO_SIZE,
- "NatSemi SCx200 GPIO")) {
- pr_err("can't allocate I/O for GPIOs\n");
- return -EBUSY;
- }
-
- scx200_gpio_base = base;
- scx200_init_shadow();
+ pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE)
+ return scx200_register_gpio(pdev);
+ /* Find the base of the configuration block. */
+ if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
+ scx200_cb_base = SCx200_CB_BASE_FIXED;
} else {
- /* find the base of the Configuration Block */
- if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
- scx200_cb_base = SCx200_CB_BASE_FIXED;
- } else {
- pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
- if (scx200_cb_probe(base)) {
- scx200_cb_base = base;
- } else {
- pr_warn("Configuration Block not found\n");
- return -ENODEV;
- }
+ pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
+ if (!scx200_cb_probe(base)) {
+ pr_warn("Configuration Block not found\n");
+ return -ENODEV;
}
- pr_info("Configuration Block base 0x%x\n", scx200_cb_base);
+ scx200_cb_base = base;
}
+ pr_info("Configuration Block base 0x%x\n", scx200_cb_base);
return 0;
}
-u32 scx200_gpio_configure(unsigned index, u32 mask, u32 bits)
-{
- u32 config, new_config;
-
- mutex_lock(&scx200_gpio_config_lock);
-
- outl(index, scx200_gpio_base + 0x20);
- config = inl(scx200_gpio_base + 0x24);
-
- new_config = (config & mask) | bits;
- outl(new_config, scx200_gpio_base + 0x24);
-
- mutex_unlock(&scx200_gpio_config_lock);
-
- return config;
-}
-
static int __init scx200_init(void)
{
pr_info("NatSemi SCx200 Driver\n");
@@ -118,13 +100,9 @@ static int __init scx200_init(void)
static void __exit scx200_cleanup(void)
{
pci_unregister_driver(&scx200_pci_driver);
- release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
}
module_init(scx200_init);
module_exit(scx200_cleanup);
-EXPORT_SYMBOL(scx200_gpio_base);
-EXPORT_SYMBOL(scx200_gpio_shadow);
-EXPORT_SYMBOL(scx200_gpio_configure);
EXPORT_SYMBOL(scx200_cb_base);
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 91683c54d509..09cc9b271e93 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -223,16 +223,6 @@ config SONYPI
To compile this driver as a module, choose M here: the
module will be called sonypi.
-config SCx200_GPIO
- tristate "NatSemi SCx200 GPIO Support"
- depends on SCx200
- select NSC_GPIO
- help
- Give userspace access to the GPIO pins on the National
- Semiconductor SCx200 processors.
-
- If compiled as a module, it will be called scx200_gpio.
-
config NSC_GPIO
tristate "NatSemi Base GPIO Support"
depends on X86_32
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 09ae0a6fba87..b743732c525c 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -26,7 +26,6 @@ obj-$(CONFIG_HW_RANDOM) += hw_random/
obj-$(CONFIG_PPDEV) += ppdev.o
obj-$(CONFIG_NWBUTTON) += nwbutton.o
obj-$(CONFIG_NWFLASH) += nwflash.o
-obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
obj-$(CONFIG_TELCLOCK) += tlclk.o
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
deleted file mode 100644
index 3ec17832e9c9..000000000000
--- a/drivers/char/scx200_gpio.c
+++ /dev/null
@@ -1,138 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/* linux/drivers/char/scx200_gpio.c
-
- National Semiconductor SCx200 GPIO driver. Allows a user space
- process to play with the GPIO pins.
-
- Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> */
-
-#include <linux/device.h>
-#include <linux/fs.h>
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/platform_device.h>
-#include <linux/uaccess.h>
-#include <asm/io.h>
-
-#include <linux/types.h>
-#include <linux/cdev.h>
-
-#include <linux/scx200_gpio.h>
-#include <linux/nsc_gpio.h>
-
-#define DRVNAME "scx200_gpio"
-
-static struct platform_device *pdev;
-
-MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
-MODULE_DESCRIPTION("NatSemi/AMD SCx200 GPIO Pin Driver");
-MODULE_LICENSE("GPL");
-
-static int major = 0; /* default to dynamic major */
-module_param(major, int, 0);
-MODULE_PARM_DESC(major, "Major device number");
-
-#define MAX_PINS 32 /* 64 later, when known ok */
-
-struct nsc_gpio_ops scx200_gpio_ops = {
- .owner = THIS_MODULE,
- .gpio_config = scx200_gpio_configure,
- .gpio_dump = nsc_gpio_dump,
- .gpio_get = scx200_gpio_get,
- .gpio_set = scx200_gpio_set,
- .gpio_change = scx200_gpio_change,
- .gpio_current = scx200_gpio_current
-};
-EXPORT_SYMBOL_GPL(scx200_gpio_ops);
-
-static int scx200_gpio_open(struct inode *inode, struct file *file)
-{
- unsigned m = iminor(inode);
- file->private_data = &scx200_gpio_ops;
-
- if (m >= MAX_PINS)
- return -EINVAL;
- return nonseekable_open(inode, file);
-}
-
-static int scx200_gpio_release(struct inode *inode, struct file *file)
-{
- return 0;
-}
-
-static const struct file_operations scx200_gpio_fileops = {
- .owner = THIS_MODULE,
- .write = nsc_gpio_write,
- .read = nsc_gpio_read,
- .open = scx200_gpio_open,
- .release = scx200_gpio_release,
-};
-
-static struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */
-
-static int __init scx200_gpio_init(void)
-{
- int rc;
- dev_t devid;
-
- if (!scx200_gpio_present()) {
- printk(KERN_ERR DRVNAME ": no SCx200 gpio present\n");
- return -ENODEV;
- }
-
- /* support dev_dbg() with pdev->dev */
- pdev = platform_device_alloc(DRVNAME, 0);
- if (!pdev)
- return -ENOMEM;
-
- rc = platform_device_add(pdev);
- if (rc)
- goto undo_malloc;
-
- /* nsc_gpio uses dev_dbg(), so needs this */
- scx200_gpio_ops.dev = &pdev->dev;
-
- if (major) {
- devid = MKDEV(major, 0);
- rc = register_chrdev_region(devid, MAX_PINS, "scx200_gpio");
- } else {
- rc = alloc_chrdev_region(&devid, 0, MAX_PINS, "scx200_gpio");
- major = MAJOR(devid);
- }
- if (rc < 0) {
- dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
- goto undo_platform_device_add;
- }
-
- cdev_init(&scx200_gpio_cdev, &scx200_gpio_fileops);
- rc = cdev_add(&scx200_gpio_cdev, devid, MAX_PINS);
- if (rc) {
- dev_err(&pdev->dev, "cdev_add err: %d\n", rc);
- goto undo_chrdev_region;
- }
-
- return 0; /* succeed */
-
-undo_chrdev_region:
- unregister_chrdev_region(devid, MAX_PINS);
-undo_platform_device_add:
- platform_device_del(pdev);
-undo_malloc:
- platform_device_put(pdev);
-
- return rc;
-}
-
-static void __exit scx200_gpio_cleanup(void)
-{
- cdev_del(&scx200_gpio_cdev);
- /* cdev_put(&scx200_gpio_cdev); */
-
- unregister_chrdev_region(MKDEV(major, 0), MAX_PINS);
- platform_device_unregister(pdev);
-}
-
-module_init(scx200_gpio_init);
-module_exit(scx200_gpio_cleanup);
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 808acc5b7f5c..b78d0cf0781b 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1106,6 +1106,17 @@ config PC8736x_GPIO
This driver can also be built as a module called gpio-pc8736x.
+config SCx200_GPIO
+ tristate "NatSemi SCx200 GPIO support"
+ depends on SCx200 && HAS_IOPORT
+ select NSC_GPIO
+ help
+ Support the GPIO controller on National Semiconductor SCx200 and
+ SC1100 processors. The first bank is exposed to GPIO consumers
+ such as the Soekris and PC Engines board LED drivers.
+
+ This driver can also be built as a module called gpio-scx200.
+
config GPIO_SCH
tristate "Intel SCH/TunnelCreek/Centerton/Quark X1000 GPIO"
depends on (X86 || COMPILE_TEST) && ACPI
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 05e8442a6d67..68f8f5fa49e1 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -171,6 +171,7 @@ obj-$(CONFIG_GPIO_SAMA5D2_PIOBU) += gpio-sama5d2-piobu.o
obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o
obj-$(CONFIG_GPIO_SCH) += gpio-sch.o
obj-$(CONFIG_GPIO_SHARED_PROXY) += gpio-shared-proxy.o
+obj-$(CONFIG_SCx200_GPIO) += gpio-scx200.o
obj-$(CONFIG_GPIO_SIFIVE) += gpio-sifive.o
obj-$(CONFIG_GPIO_SIM) += gpio-sim.o
obj-$(CONFIG_GPIO_SIOX) += gpio-siox.o
diff --git a/drivers/gpio/gpio-scx200.c b/drivers/gpio/gpio-scx200.c
new file mode 100644
index 000000000000..5c0e86474481
--- /dev/null
+++ b/drivers/gpio/gpio-scx200.c
@@ -0,0 +1,400 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * National Semiconductor SCx200 GPIO driver.
+ *
+ * Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
+ */
+
+#include <linux/bitmap.h>
+#include <linux/cdev.h>
+#include <linux/cleanup.h>
+#include <linux/fs.h>
+#include <linux/gpio/driver.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/nsc_gpio.h>
+#include <linux/pci.h>
+#include <linux/pinctrl/pinconf-generic.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/scx200.h>
+#include <linux/spinlock.h>
+
+#define DRVNAME "gpio-scx200"
+#define LEGACY_NAME "scx200_gpio"
+#define SCX200_NGPIO 32
+
+#define SCX200_DATA_OUT 0x00
+#define SCX200_DATA_IN 0x04
+#define SCX200_CONFIG_SELECT 0x20
+#define SCX200_CONFIG_ACCESS 0x24
+
+#define SCX200_GPIO_OUTPUT_ENABLE BIT(0)
+#define SCX200_GPIO_PUSH_PULL BIT(1)
+#define SCX200_GPIO_PULL_UP BIT(2)
+#define SCX200_GPIO_LOCK BIT(3)
+
+struct scx200_gpio {
+ struct gpio_chip gc;
+ raw_spinlock_t lock; /* Serializes the config index and output updates. */
+ unsigned long base;
+};
+
+const struct software_node scx200_gpio_swnode = {
+ .name = DRVNAME,
+};
+EXPORT_SYMBOL_NS_GPL(scx200_gpio_swnode, "SCX200_GPIO");
+
+static u32 scx200_gpio_read_config(struct scx200_gpio *gpio, unsigned int offset)
+{
+ outl(offset, gpio->base + SCX200_CONFIG_SELECT);
+ return inl(gpio->base + SCX200_CONFIG_ACCESS);
+}
+
+static int scx200_gpio_update_config(struct scx200_gpio *gpio, u32 config,
+ u32 mask, u32 value)
+{
+ u32 new_config = (config & ~mask) | value;
+
+ if (new_config == config)
+ return 0;
+ if (config & SCX200_GPIO_LOCK)
+ return -EPERM;
+
+ outl(new_config, gpio->base + SCX200_CONFIG_ACCESS);
+ return 0;
+}
+
+static int scx200_gpio_get(struct gpio_chip *gc, unsigned int offset)
+{
+ struct scx200_gpio *gpio = gpiochip_get_data(gc);
+
+ return !!(inl(gpio->base + SCX200_DATA_IN) & BIT(offset));
+}
+
+static int scx200_gpio_write(struct scx200_gpio *gpio, unsigned int offset,
+ int value)
+{
+ unsigned long port = gpio->base + SCX200_DATA_OUT;
+ u32 mask = BIT(offset);
+ u32 data = inl(port);
+ u32 new_data = (data & ~mask) | (value ? mask : 0);
+
+ if (new_data != data)
+ outl(new_data, port);
+
+ /* The hardware ignores writes to a locked line. */
+ return (inl(port) & mask) == (new_data & mask) ? 0 : -EPERM;
+}
+
+static int scx200_gpio_set(struct gpio_chip *gc, unsigned int offset, int value)
+{
+ struct scx200_gpio *gpio = gpiochip_get_data(gc);
+
+ guard(raw_spinlock_irqsave)(&gpio->lock);
+ return scx200_gpio_write(gpio, offset, value);
+}
+
+static int scx200_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
+{
+ struct scx200_gpio *gpio = gpiochip_get_data(gc);
+
+ guard(raw_spinlock_irqsave)(&gpio->lock);
+ return scx200_gpio_read_config(gpio, offset) & SCX200_GPIO_OUTPUT_ENABLE ?
+ GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
+}
+
+static int scx200_gpio_direction_input(struct gpio_chip *gc, unsigned int offset)
+{
+ struct scx200_gpio *gpio = gpiochip_get_data(gc);
+ u32 config;
+
+ guard(raw_spinlock_irqsave)(&gpio->lock);
+ config = scx200_gpio_read_config(gpio, offset);
+ return scx200_gpio_update_config(gpio, config,
+ SCX200_GPIO_OUTPUT_ENABLE, 0);
+}
+
+static int scx200_gpio_direction_output(struct gpio_chip *gc,
+ unsigned int offset, int value)
+{
+ struct scx200_gpio *gpio = gpiochip_get_data(gc);
+ u32 config;
+ int ret;
+
+ guard(raw_spinlock_irqsave)(&gpio->lock);
+ config = scx200_gpio_read_config(gpio, offset);
+ if ((config & SCX200_GPIO_LOCK) && !(config & SCX200_GPIO_OUTPUT_ENABLE))
+ return -EPERM;
+
+ ret = scx200_gpio_write(gpio, offset, value);
+ if (ret)
+ return ret;
+
+ return scx200_gpio_update_config(gpio, config, SCX200_GPIO_OUTPUT_ENABLE,
+ SCX200_GPIO_OUTPUT_ENABLE);
+}
+
+static int scx200_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
+ unsigned long config)
+{
+ struct scx200_gpio *gpio = gpiochip_get_data(gc);
+ u32 mask, value, old_config;
+
+ switch (pinconf_to_config_param(config)) {
+ case PIN_CONFIG_DRIVE_OPEN_DRAIN:
+ mask = SCX200_GPIO_PUSH_PULL;
+ value = 0;
+ break;
+ case PIN_CONFIG_DRIVE_PUSH_PULL:
+ mask = SCX200_GPIO_PUSH_PULL;
+ value = SCX200_GPIO_PUSH_PULL;
+ break;
+ case PIN_CONFIG_BIAS_DISABLE:
+ mask = SCX200_GPIO_PULL_UP;
+ value = 0;
+ break;
+ case PIN_CONFIG_BIAS_PULL_UP:
+ mask = SCX200_GPIO_PULL_UP;
+ value = SCX200_GPIO_PULL_UP;
+ break;
+ default:
+ return -ENOTSUPP;
+ }
+
+ guard(raw_spinlock_irqsave)(&gpio->lock);
+ old_config = scx200_gpio_read_config(gpio, offset);
+ return scx200_gpio_update_config(gpio, old_config, mask, value);
+}
+
+static int scx200_gpio_init_valid_mask(struct gpio_chip *gc,
+ unsigned long *valid_mask,
+ unsigned int ngpios)
+{
+ struct pci_dev *bridge = to_pci_dev(gc->parent->parent);
+
+ /* The SC1100 bonds out GPIOs 2 and 3 as well. */
+ if (bridge->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE)
+ bitmap_clear(valid_mask, 4, 2);
+ else
+ bitmap_clear(valid_mask, 2, 4);
+
+ bitmap_clear(valid_mask, 21, ngpios - 21);
+ return 0;
+}
+
+static int major;
+module_param(major, int, 0);
+MODULE_PARM_DESC(major, "Major device number for the legacy interface");
+
+static struct cdev scx200_legacy_cdev;
+static dev_t scx200_legacy_devt;
+
+/* Protects the legacy frontend against provider detach during file I/O. */
+static DEFINE_MUTEX(scx200_legacy_lock);
+static struct scx200_gpio *scx200_legacy_gpio;
+
+static u32 scx200_legacy_config(unsigned int offset, u32 mask, u32 value)
+{
+ struct scx200_gpio *gpio = scx200_legacy_gpio;
+ u32 config;
+
+ guard(raw_spinlock_irqsave)(&gpio->lock);
+ config = scx200_gpio_read_config(gpio, offset);
+ scx200_gpio_update_config(gpio, config, ~mask, value);
+ return config;
+}
+
+static int scx200_legacy_get(unsigned int offset)
+{
+ return scx200_gpio_get(&scx200_legacy_gpio->gc, offset);
+}
+
+static void scx200_legacy_set(unsigned int offset, int value)
+{
+ scx200_gpio_set(&scx200_legacy_gpio->gc, offset, value);
+}
+
+static int scx200_legacy_current(unsigned int offset)
+{
+ return !!(inl(scx200_legacy_gpio->base + SCX200_DATA_OUT) & BIT(offset));
+}
+
+static struct nsc_gpio_ops scx200_legacy_ops = {
+ .gpio_config = scx200_legacy_config,
+ .gpio_dump = nsc_gpio_dump,
+ .gpio_get = scx200_legacy_get,
+ .gpio_set = scx200_legacy_set,
+ .gpio_current = scx200_legacy_current,
+};
+
+static int scx200_legacy_open(struct inode *inode, struct file *file)
+{
+ guard(mutex)(&scx200_legacy_lock);
+ if (!scx200_legacy_gpio)
+ return -ENODEV;
+
+ file->private_data = &scx200_legacy_ops;
+ return nonseekable_open(inode, file);
+}
+
+static ssize_t scx200_legacy_read(struct file *file, char __user *buf,
+ size_t len, loff_t *ppos)
+{
+ guard(mutex)(&scx200_legacy_lock);
+ if (!scx200_legacy_gpio)
+ return -ENODEV;
+
+ return nsc_gpio_read(file, buf, len, ppos);
+}
+
+static ssize_t scx200_legacy_write(struct file *file, const char __user *buf,
+ size_t len, loff_t *ppos)
+{
+ guard(mutex)(&scx200_legacy_lock);
+ if (!scx200_legacy_gpio)
+ return -ENODEV;
+
+ return nsc_gpio_write(file, buf, len, ppos);
+}
+
+static const struct file_operations scx200_legacy_fops = {
+ .owner = THIS_MODULE,
+ .open = scx200_legacy_open,
+ .read = scx200_legacy_read,
+ .write = scx200_legacy_write,
+};
+
+static void scx200_legacy_detach(void *data)
+{
+ guard(mutex)(&scx200_legacy_lock);
+ if (scx200_legacy_gpio == data) {
+ scx200_legacy_gpio = NULL;
+ scx200_legacy_ops.dev = NULL;
+ }
+}
+
+static int scx200_legacy_attach(struct scx200_gpio *gpio)
+{
+ struct device *dev = gpio->gc.parent;
+ dev_t devid;
+ int ret;
+
+ ret = devm_add_action(dev, scx200_legacy_detach, gpio);
+ if (ret)
+ return ret;
+
+ guard(mutex)(&scx200_legacy_lock);
+ if (scx200_legacy_gpio)
+ return -EBUSY;
+
+ if (!scx200_legacy_devt) {
+ if (major) {
+ devid = MKDEV(major, 0);
+ ret = register_chrdev_region(devid, SCX200_NGPIO, LEGACY_NAME);
+ } else {
+ ret = alloc_chrdev_region(&devid, 0, SCX200_NGPIO, LEGACY_NAME);
+ }
+ if (ret)
+ return ret;
+
+ cdev_init(&scx200_legacy_cdev, &scx200_legacy_fops);
+ scx200_legacy_cdev.owner = THIS_MODULE;
+ ret = cdev_add(&scx200_legacy_cdev, devid, SCX200_NGPIO);
+ if (ret) {
+ unregister_chrdev_region(devid, SCX200_NGPIO);
+ return ret;
+ }
+
+ scx200_legacy_devt = devid;
+ }
+
+ scx200_legacy_gpio = gpio;
+ scx200_legacy_ops.dev = dev;
+ return 0;
+}
+
+static void scx200_gpio_remove_swnode(void *data)
+{
+ device_remove_software_node(data);
+}
+
+static int scx200_gpio_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct scx200_gpio *gpio;
+ struct resource *res;
+ int ret;
+
+ res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+ if (!res)
+ return -ENODEV;
+
+ gpio = devm_kzalloc(dev, sizeof(*gpio), GFP_KERNEL);
+ if (!gpio)
+ return -ENOMEM;
+
+ if (!devm_request_region(dev, res->start, resource_size(res), DRVNAME))
+ return -EBUSY;
+
+ ret = device_add_software_node(dev, &scx200_gpio_swnode);
+ if (ret)
+ return ret;
+
+ ret = devm_add_action_or_reset(dev, scx200_gpio_remove_swnode, dev);
+ if (ret)
+ return ret;
+
+ gpio->base = res->start;
+ raw_spin_lock_init(&gpio->lock);
+ gpio->gc = (struct gpio_chip) {
+ .label = DRVNAME,
+ .parent = dev,
+ .fwnode = software_node_fwnode(&scx200_gpio_swnode),
+ .owner = THIS_MODULE,
+ .base = -1,
+ .ngpio = SCX200_NGPIO,
+ .get = scx200_gpio_get,
+ .set = scx200_gpio_set,
+ .get_direction = scx200_gpio_get_direction,
+ .direction_input = scx200_gpio_direction_input,
+ .direction_output = scx200_gpio_direction_output,
+ .set_config = scx200_gpio_set_config,
+ .init_valid_mask = scx200_gpio_init_valid_mask,
+ };
+
+ ret = devm_gpiochip_add_data(dev, &gpio->gc, gpio);
+ if (ret)
+ return ret;
+
+ return scx200_legacy_attach(gpio);
+}
+
+static struct platform_driver scx200_gpio_driver = {
+ .driver.name = DRVNAME,
+ .probe = scx200_gpio_probe,
+};
+
+static int __init scx200_gpio_init(void)
+{
+ return platform_driver_register(&scx200_gpio_driver);
+}
+module_init(scx200_gpio_init);
+
+static void __exit scx200_gpio_exit(void)
+{
+ platform_driver_unregister(&scx200_gpio_driver);
+ if (scx200_legacy_devt) {
+ cdev_del(&scx200_legacy_cdev);
+ unregister_chrdev_region(scx200_legacy_devt, SCX200_NGPIO);
+ }
+}
+module_exit(scx200_gpio_exit);
+
+MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
+MODULE_DESCRIPTION("NatSemi/AMD SCx200 GPIO driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:" DRVNAME);
+MODULE_ALIAS(LEGACY_NAME);
diff --git a/drivers/leds/leds-net48xx.c b/drivers/leds/leds-net48xx.c
index a93468c13772..bb09e597a66e 100644
--- a/drivers/leds/leds-net48xx.c
+++ b/drivers/leds/leds-net48xx.c
@@ -7,68 +7,89 @@
* Based on leds-ams-delta.c
*/
-#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/machine.h>
+#include <linux/gpio/property.h>
#include <linux/init.h>
-#include <linux/platform_device.h>
#include <linux/leds.h>
-#include <linux/err.h>
-#include <linux/io.h>
-#include <linux/nsc_gpio.h>
-#include <linux/scx200_gpio.h>
#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/scx200.h>
#define DRVNAME "net48xx-led"
-#define NET48XX_ERROR_LED_GPIO 20
+
+struct net48xx_led {
+ struct led_classdev cdev;
+ struct gpio_desc *gpio;
+};
static struct platform_device *pdev;
static void net48xx_error_led_set(struct led_classdev *led_cdev,
- enum led_brightness value)
+ enum led_brightness value)
{
- scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
+ struct net48xx_led *led = container_of(led_cdev, struct net48xx_led, cdev);
+
+ gpiod_set_value(led->gpio, value != LED_OFF);
}
-static struct led_classdev net48xx_error_led = {
- .name = "net48xx::error",
- .brightness_set = net48xx_error_led_set,
- .flags = LED_CORE_SUSPENDRESUME,
+static const struct property_entry net48xx_led_props[] = {
+ PROPERTY_ENTRY_GPIO("gpios", &scx200_gpio_swnode, 20, GPIO_ACTIVE_HIGH),
+ { }
+};
+
+static const struct software_node net48xx_led_node = {
+ .name = DRVNAME,
+ .properties = net48xx_led_props,
};
static int net48xx_led_probe(struct platform_device *pdev)
{
- return devm_led_classdev_register(&pdev->dev, &net48xx_error_led);
+ struct device *dev = &pdev->dev;
+ struct net48xx_led *led;
+
+ led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
+ if (!led)
+ return -ENOMEM;
+
+ led->gpio = devm_gpiod_get(dev, NULL, GPIOD_ASIS);
+ if (IS_ERR(led->gpio))
+ return dev_err_probe(dev, PTR_ERR(led->gpio), "Failed to get error LED GPIO\n");
+
+ led->cdev.name = "net48xx::error";
+ led->cdev.brightness_set = net48xx_error_led_set;
+ led->cdev.flags = LED_CORE_SUSPENDRESUME;
+
+ return devm_led_classdev_register(dev, &led->cdev);
}
static struct platform_driver net48xx_led_driver = {
- .probe = net48xx_led_probe,
- .driver = {
- .name = DRVNAME,
- },
+ .probe = net48xx_led_probe,
+ .driver.name = DRVNAME,
};
static int __init net48xx_led_init(void)
{
+ const struct platform_device_info info = {
+ .name = DRVNAME,
+ .id = PLATFORM_DEVID_NONE,
+ .swnode = &net48xx_led_node,
+ };
int ret;
- /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
- if (!scx200_gpio_ops.dev) {
- ret = -ENODEV;
- goto out;
- }
-
ret = platform_driver_register(&net48xx_led_driver);
- if (ret < 0)
- goto out;
+ if (ret)
+ return ret;
- pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
+ pdev = platform_device_register_full(&info);
if (IS_ERR(pdev)) {
- ret = PTR_ERR(pdev);
platform_driver_unregister(&net48xx_led_driver);
- goto out;
+ return PTR_ERR(pdev);
}
-out:
- return ret;
+ return 0;
}
static void __exit net48xx_led_exit(void)
@@ -83,4 +104,4 @@ module_exit(net48xx_led_exit);
MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
MODULE_DESCRIPTION("Soekris net48xx LED driver");
MODULE_LICENSE("GPL");
-
+MODULE_IMPORT_NS("SCX200_GPIO");
diff --git a/drivers/leds/leds-wrap.c b/drivers/leds/leds-wrap.c
index 794697e16068..91ebb1ac3578 100644
--- a/drivers/leds/leds-wrap.c
+++ b/drivers/leds/leds-wrap.c
@@ -7,112 +7,115 @@
* Based on leds-net48xx.c
*/
-#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/machine.h>
+#include <linux/gpio/property.h>
#include <linux/init.h>
-#include <linux/platform_device.h>
#include <linux/leds.h>
-#include <linux/err.h>
-#include <linux/io.h>
-#include <linux/scx200_gpio.h>
#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/scx200.h>
#define DRVNAME "wrap-led"
-#define WRAP_POWER_LED_GPIO 2
-#define WRAP_ERROR_LED_GPIO 3
-#define WRAP_EXTRA_LED_GPIO 18
+
+struct wrap_led {
+ struct led_classdev cdev;
+ struct gpio_desc *gpio;
+};
static struct platform_device *pdev;
-static void wrap_power_led_set(struct led_classdev *led_cdev,
- enum led_brightness value)
+static void wrap_led_set(struct led_classdev *led_cdev,
+ enum led_brightness value)
{
- if (value)
- scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
- else
- scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
-}
+ struct wrap_led *led = container_of(led_cdev, struct wrap_led, cdev);
-static void wrap_error_led_set(struct led_classdev *led_cdev,
- enum led_brightness value)
-{
- if (value)
- scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
- else
- scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
+ gpiod_set_value(led->gpio, value != LED_OFF);
}
-static void wrap_extra_led_set(struct led_classdev *led_cdev,
- enum led_brightness value)
-{
- if (value)
- scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
- else
- scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
-}
+static const struct software_node_ref_args wrap_led_gpios[] = {
+ SOFTWARE_NODE_REFERENCE(&scx200_gpio_swnode, 2, GPIO_ACTIVE_LOW),
+ SOFTWARE_NODE_REFERENCE(&scx200_gpio_swnode, 3, GPIO_ACTIVE_LOW),
+ SOFTWARE_NODE_REFERENCE(&scx200_gpio_swnode, 18, GPIO_ACTIVE_LOW),
+};
-static struct led_classdev wrap_power_led = {
- .name = "wrap::power",
- .brightness_set = wrap_power_led_set,
- .default_trigger = "default-on",
- .flags = LED_CORE_SUSPENDRESUME,
+static const struct property_entry wrap_led_props[] = {
+ PROPERTY_ENTRY_REF_ARRAY("gpios", wrap_led_gpios),
+ { }
};
-static struct led_classdev wrap_error_led = {
- .name = "wrap::error",
- .brightness_set = wrap_error_led_set,
- .flags = LED_CORE_SUSPENDRESUME,
+static const struct software_node wrap_led_node = {
+ .name = DRVNAME,
+ .properties = wrap_led_props,
};
-static struct led_classdev wrap_extra_led = {
- .name = "wrap::extra",
- .brightness_set = wrap_extra_led_set,
- .flags = LED_CORE_SUSPENDRESUME,
+static const struct {
+ const char *name;
+ const char *default_trigger;
+} wrap_leds[] = {
+ { "wrap::power", "default-on" },
+ { "wrap::error" },
+ { "wrap::extra" },
};
static int wrap_led_probe(struct platform_device *pdev)
{
- int ret;
-
- ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led);
- if (ret < 0)
- return ret;
-
- ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led);
- if (ret < 0)
- return ret;
+ struct device *dev = &pdev->dev;
+ struct wrap_led *leds;
+ int ret, i;
+
+ leds = devm_kcalloc(dev, ARRAY_SIZE(wrap_leds), sizeof(*leds), GFP_KERNEL);
+ if (!leds)
+ return -ENOMEM;
+
+ for (i = 0; i < ARRAY_SIZE(wrap_leds); i++) {
+ struct wrap_led *led = &leds[i];
+
+ led->gpio = devm_gpiod_get_index(dev, NULL, i, GPIOD_ASIS);
+ if (IS_ERR(led->gpio))
+ return dev_err_probe(dev, PTR_ERR(led->gpio),
+ "Failed to get %s GPIO\n", wrap_leds[i].name);
+
+ led->cdev.name = wrap_leds[i].name;
+ led->cdev.default_trigger = wrap_leds[i].default_trigger;
+ led->cdev.brightness_set = wrap_led_set;
+ led->cdev.flags = LED_CORE_SUSPENDRESUME;
+
+ ret = devm_led_classdev_register(dev, &led->cdev);
+ if (ret)
+ return ret;
+ }
- return devm_led_classdev_register(&pdev->dev, &wrap_extra_led);
+ return 0;
}
static struct platform_driver wrap_led_driver = {
- .probe = wrap_led_probe,
- .driver = {
- .name = DRVNAME,
- },
+ .probe = wrap_led_probe,
+ .driver.name = DRVNAME,
};
static int __init wrap_led_init(void)
{
+ const struct platform_device_info info = {
+ .name = DRVNAME,
+ .id = PLATFORM_DEVID_NONE,
+ .swnode = &wrap_led_node,
+ };
int ret;
- if (!scx200_gpio_present()) {
- ret = -ENODEV;
- goto out;
- }
-
ret = platform_driver_register(&wrap_led_driver);
- if (ret < 0)
- goto out;
+ if (ret)
+ return ret;
- pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
+ pdev = platform_device_register_full(&info);
if (IS_ERR(pdev)) {
- ret = PTR_ERR(pdev);
platform_driver_unregister(&wrap_led_driver);
- goto out;
+ return PTR_ERR(pdev);
}
-out:
- return ret;
+ return 0;
}
static void __exit wrap_led_exit(void)
@@ -127,4 +130,4 @@ module_exit(wrap_led_exit);
MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
MODULE_DESCRIPTION("PCEngines WRAP LED driver");
MODULE_LICENSE("GPL");
-
+MODULE_IMPORT_NS("SCX200_GPIO");
diff --git a/include/linux/scx200.h b/include/linux/scx200.h
index 652ec1a45f7c..8587b7784c57 100644
--- a/include/linux/scx200.h
+++ b/include/linux/scx200.h
@@ -9,6 +9,7 @@
/* Interesting stuff for the National Semiconductor SCx200 CPU */
extern unsigned scx200_cb_base;
+extern const struct software_node scx200_gpio_swnode;
#define scx200_cb_present() (scx200_cb_base!=0)
diff --git a/include/linux/scx200_gpio.h b/include/linux/scx200_gpio.h
deleted file mode 100644
index 6386ddbb6b70..000000000000
--- a/include/linux/scx200_gpio.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-u32 scx200_gpio_configure(unsigned index, u32 set, u32 clear);
-
-extern unsigned scx200_gpio_base;
-extern unsigned long scx200_gpio_shadow[2];
-extern struct nsc_gpio_ops scx200_gpio_ops;
-
-#define scx200_gpio_present() (scx200_gpio_base!=0)
-
-/* Definitions to make sure I do the same thing in all functions */
-#define __SCx200_GPIO_BANK unsigned bank = index>>5
-#define __SCx200_GPIO_IOADDR unsigned short ioaddr = scx200_gpio_base+0x10*bank
-#define __SCx200_GPIO_SHADOW unsigned long *shadow = scx200_gpio_shadow+bank
-#define __SCx200_GPIO_INDEX index &= 31
-
-#define __SCx200_GPIO_OUT __asm__ __volatile__("outsl":"=mS" (shadow):"d" (ioaddr), "0" (shadow))
-
-/* returns the value of the GPIO pin */
-
-static inline int scx200_gpio_get(unsigned index) {
- __SCx200_GPIO_BANK;
- __SCx200_GPIO_IOADDR + 0x04;
- __SCx200_GPIO_INDEX;
-
- return (inl(ioaddr) & (1<<index)) ? 1 : 0;
-}
-
-/* return the value driven on the GPIO signal (the value that will be
- driven if the GPIO is configured as an output, it might not be the
- state of the GPIO right now if the GPIO is configured as an input) */
-
-static inline int scx200_gpio_current(unsigned index) {
- __SCx200_GPIO_BANK;
- __SCx200_GPIO_INDEX;
-
- return (scx200_gpio_shadow[bank] & (1<<index)) ? 1 : 0;
-}
-
-/* drive the GPIO signal high */
-
-static inline void scx200_gpio_set_high(unsigned index) {
- __SCx200_GPIO_BANK;
- __SCx200_GPIO_IOADDR;
- __SCx200_GPIO_SHADOW;
- __SCx200_GPIO_INDEX;
- set_bit(index, shadow); /* __set_bit()? */
- __SCx200_GPIO_OUT;
-}
-
-/* drive the GPIO signal low */
-
-static inline void scx200_gpio_set_low(unsigned index) {
- __SCx200_GPIO_BANK;
- __SCx200_GPIO_IOADDR;
- __SCx200_GPIO_SHADOW;
- __SCx200_GPIO_INDEX;
- clear_bit(index, shadow); /* __clear_bit()? */
- __SCx200_GPIO_OUT;
-}
-
-/* drive the GPIO signal to state */
-
-static inline void scx200_gpio_set(unsigned index, int state) {
- __SCx200_GPIO_BANK;
- __SCx200_GPIO_IOADDR;
- __SCx200_GPIO_SHADOW;
- __SCx200_GPIO_INDEX;
- if (state)
- set_bit(index, shadow);
- else
- clear_bit(index, shadow);
- __SCx200_GPIO_OUT;
-}
-
-/* toggle the GPIO signal */
-static inline void scx200_gpio_change(unsigned index) {
- __SCx200_GPIO_BANK;
- __SCx200_GPIO_IOADDR;
- __SCx200_GPIO_SHADOW;
- __SCx200_GPIO_INDEX;
- change_bit(index, shadow);
- __SCx200_GPIO_OUT;
-}
-
-#undef __SCx200_GPIO_BANK
-#undef __SCx200_GPIO_IOADDR
-#undef __SCx200_GPIO_SHADOW
-#undef __SCx200_GPIO_INDEX
-#undef __SCx200_GPIO_OUT
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] gpio: remove the legacy NSC GPIO API
2026-11-23 12:29 [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib Linus Walleij
2026-11-23 12:29 ` [PATCH 1/3] gpio: convert PC8736x " Linus Walleij
2026-11-23 12:29 ` [PATCH 2/3] gpio: convert SCx200 to gpiolib and use descriptors for board LEDs Linus Walleij
@ 2026-11-23 12:29 ` Linus Walleij
2026-11-23 12:54 ` [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib Greg Kroah-Hartman
3 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2026-11-23 12:29 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Linus Walleij,
Bartosz Golaszewski, Christer Weinigel, Jim Cromie, x86,
Lee Jones, Pavel Machek, Griffin Kroah-Hartman
Cc: linux-gpio, linux-leds
Both controllers now expose the standard GPIO character-device ABI,
and the net48xx and WRAP LED drivers use GPIO descriptors. Remove the
per-pin character devices and their shared file operations.
We assume there are no remaining users of the old NSC GPIO userspace
ABI.
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
drivers/char/Kconfig | 10 ---
drivers/char/Makefile | 1 -
drivers/char/nsc_gpio.c | 126 -----------------------------------
drivers/gpio/Kconfig | 2 -
drivers/gpio/gpio-pc8736x.c | 114 +------------------------------
drivers/gpio/gpio-scx200.c | 159 +-------------------------------------------
include/linux/nsc_gpio.h | 41 ------------
7 files changed, 3 insertions(+), 450 deletions(-)
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 09cc9b271e93..073ac08d08d2 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -223,16 +223,6 @@ config SONYPI
To compile this driver as a module, choose M here: the
module will be called sonypi.
-config NSC_GPIO
- tristate "NatSemi Base GPIO Support"
- depends on X86_32
- # selected by SCx200_GPIO and PC8736x_GPIO
- # what about 2 selectors differing: m != y
- help
- Common support used (and needed) by scx200_gpio and
- pc8736x_gpio drivers. If those drivers are built as
- modules, this one will be too, named nsc_gpio
-
config DEVMEM
bool "/dev/mem virtual device support"
default y
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index b743732c525c..e388a7cbad84 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -26,7 +26,6 @@ obj-$(CONFIG_HW_RANDOM) += hw_random/
obj-$(CONFIG_PPDEV) += ppdev.o
obj-$(CONFIG_NWBUTTON) += nwbutton.o
obj-$(CONFIG_NWFLASH) += nwflash.o
-obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
obj-$(CONFIG_TELCLOCK) += tlclk.o
obj-y += agp/
diff --git a/drivers/char/nsc_gpio.c b/drivers/char/nsc_gpio.c
deleted file mode 100644
index 2c9b12b85435..000000000000
--- a/drivers/char/nsc_gpio.c
+++ /dev/null
@@ -1,126 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/* linux/drivers/char/nsc_gpio.c
-
- National Semiconductor common GPIO device-file/VFS methods.
- Allows a user space process to control the GPIO pins.
-
- Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
- Copyright (c) 2005 Jim Cromie <jim.cromie@gmail.com>
-*/
-
-#include <linux/fs.h>
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/nsc_gpio.h>
-#include <linux/platform_device.h>
-#include <linux/uaccess.h>
-#include <asm/io.h>
-
-#define NAME "nsc_gpio"
-
-void nsc_gpio_dump(struct nsc_gpio_ops *amp, unsigned index)
-{
- /* retrieve current config w/o changing it */
- u32 config = amp->gpio_config(index, ~0, 0);
-
- /* user requested via 'v' command, so its INFO */
- dev_info(amp->dev, "io%02u: 0x%04x %s %s %s %s %s %s %s\tio:%d/%d\n",
- index, config,
- (config & 1) ? "OE" : "TS", /* output-enabled/tristate */
- (config & 2) ? "PP" : "OD", /* push pull / open drain */
- (config & 4) ? "PUE" : "PUD", /* pull up enabled/disabled */
- (config & 8) ? "LOCKED" : "", /* locked / unlocked */
- (config & 16) ? "LEVEL" : "EDGE",/* level/edge input */
- (config & 32) ? "HI" : "LO", /* trigger on rise/fall edge */
- (config & 64) ? "DEBOUNCE" : "", /* debounce */
-
- amp->gpio_get(index), amp->gpio_current(index));
-}
-
-ssize_t nsc_gpio_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos)
-{
- unsigned m = iminor(file_inode(file));
- struct nsc_gpio_ops *amp = file->private_data;
- struct device *dev = amp->dev;
- size_t i;
- int err = 0;
-
- for (i = 0; i < len; ++i) {
- char c;
- if (get_user(c, data + i))
- return -EFAULT;
- switch (c) {
- case '0':
- amp->gpio_set(m, 0);
- break;
- case '1':
- amp->gpio_set(m, 1);
- break;
- case 'O':
- dev_dbg(dev, "GPIO%d output enabled\n", m);
- amp->gpio_config(m, ~1, 1);
- break;
- case 'o':
- dev_dbg(dev, "GPIO%d output disabled\n", m);
- amp->gpio_config(m, ~1, 0);
- break;
- case 'T':
- dev_dbg(dev, "GPIO%d output is push pull\n", m);
- amp->gpio_config(m, ~2, 2);
- break;
- case 't':
- dev_dbg(dev, "GPIO%d output is open drain\n", m);
- amp->gpio_config(m, ~2, 0);
- break;
- case 'P':
- dev_dbg(dev, "GPIO%d pull up enabled\n", m);
- amp->gpio_config(m, ~4, 4);
- break;
- case 'p':
- dev_dbg(dev, "GPIO%d pull up disabled\n", m);
- amp->gpio_config(m, ~4, 0);
- break;
- case 'v':
- /* View Current pin settings */
- amp->gpio_dump(amp, m);
- break;
- case '\n':
- /* end of settings string, do nothing */
- break;
- default:
- dev_err(dev, "io%2d bad setting: chr<0x%2x>\n",
- m, (int)c);
- err++;
- }
- }
- if (err)
- return -EINVAL; /* full string handled, report error */
-
- return len;
-}
-
-ssize_t nsc_gpio_read(struct file *file, char __user * buf,
- size_t len, loff_t * ppos)
-{
- unsigned m = iminor(file_inode(file));
- int value;
- struct nsc_gpio_ops *amp = file->private_data;
-
- value = amp->gpio_get(m);
- if (put_user(value ? '1' : '0', buf))
- return -EFAULT;
-
- return 1;
-}
-
-/* common file-ops routines for both scx200_gpio and pc87360_gpio */
-EXPORT_SYMBOL(nsc_gpio_write);
-EXPORT_SYMBOL(nsc_gpio_read);
-EXPORT_SYMBOL(nsc_gpio_dump);
-
-MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
-MODULE_DESCRIPTION("NatSemi GPIO Common Methods");
-MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index b78d0cf0781b..7b1ed87747f0 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1098,7 +1098,6 @@ config PC8736x_GPIO
depends on X86_32
default SCx200_GPIO
select ISA_BUS_API
- select NSC_GPIO
help
Support the GPIO controller in the National Semiconductor
PC87365 and PC87366 Super I/O chips. The GPIO logical device
@@ -1109,7 +1108,6 @@ config PC8736x_GPIO
config SCx200_GPIO
tristate "NatSemi SCx200 GPIO support"
depends on SCx200 && HAS_IOPORT
- select NSC_GPIO
help
Support the GPIO controller on National Semiconductor SCx200 and
SC1100 processors. The first bank is exposed to GPIO consumers
diff --git a/drivers/gpio/gpio-pc8736x.c b/drivers/gpio/gpio-pc8736x.c
index 5c18903b1add..507100a45ada 100644
--- a/drivers/gpio/gpio-pc8736x.c
+++ b/drivers/gpio/gpio-pc8736x.c
@@ -8,20 +8,16 @@
*/
#include <linux/bitops.h>
-#include <linux/cdev.h>
#include <linux/cleanup.h>
-#include <linux/fs.h>
#include <linux/gpio/driver.h>
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/isa.h>
#include <linux/module.h>
#include <linux/mutex.h>
-#include <linux/nsc_gpio.h>
#include <linux/pinctrl/pinconf-generic.h>
#define DRVNAME "gpio-pc8736x"
-#define LEGACY_NAME "pc8736x_gpio"
#define SIO_BASE1 0x2e
#define SIO_BASE2 0x4e
@@ -39,7 +35,6 @@
#define PC8736X_GPIO_RANGE 16
#define PC8736X_NGPIO 29
-#define LEGACY_NGPIO 32
#define PC8736X_GPIO_PORT_OUT 0
#define PC8736X_GPIO_PORT_IN 1
#define PC8736X_GPIO_OUTPUT_ENABLE BIT(0)
@@ -203,103 +198,10 @@ static int pc8736x_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
return pc8736x_gpio_update_config(gpio, old_config, mask, value);
}
-static int major;
-module_param(major, int, 0);
-MODULE_PARM_DESC(major, "Major device number for the legacy interface");
-
-static struct pc8736x_gpio *pc8736x_legacy_gpio;
-static struct cdev pc8736x_gpio_cdev;
-static dev_t pc8736x_devt;
-static u8 pc8736x_legacy_shadow[ARRAY_SIZE(port_offset)];
-
-static u32 pc8736x_legacy_config(unsigned int offset, u32 mask, u32 value)
-{
- struct pc8736x_gpio *gpio = pc8736x_legacy_gpio;
- u8 config;
-
- guard(mutex)(&gpio->lock);
- config = pc8736x_select_pin(gpio, offset);
- pc8736x_gpio_update_config(gpio, config, ~mask, value);
- return config;
-}
-
-static int pc8736x_legacy_get(unsigned int offset)
-{
- struct pc8736x_gpio *gpio = pc8736x_legacy_gpio;
-
- return pc8736x_gpio_get(&gpio->gc, offset);
-}
-
-static void pc8736x_legacy_set(unsigned int offset, int value)
-{
- struct pc8736x_gpio *gpio = pc8736x_legacy_gpio;
- unsigned int port = offset / 8;
-
- guard(mutex)(&gpio->lock);
- pc8736x_gpio_write(gpio, offset, value);
- pc8736x_legacy_shadow[port] =
- inb_p(gpio->base + port_offset[port] + PC8736X_GPIO_PORT_IN);
-}
-
-static int pc8736x_legacy_current(unsigned int offset)
-{
- return !!(READ_ONCE(pc8736x_legacy_shadow[offset / 8]) & BIT(offset % 8));
-}
-
-static struct nsc_gpio_ops pc8736x_legacy_ops = {
- .gpio_config = pc8736x_legacy_config,
- .gpio_dump = nsc_gpio_dump,
- .gpio_get = pc8736x_legacy_get,
- .gpio_set = pc8736x_legacy_set,
- .gpio_current = pc8736x_legacy_current,
-};
-
-static int pc8736x_legacy_open(struct inode *inode, struct file *file)
-{
- file->private_data = &pc8736x_legacy_ops;
- return nonseekable_open(inode, file);
-}
-
-static const struct file_operations pc8736x_legacy_fops = {
- .owner = THIS_MODULE,
- .open = pc8736x_legacy_open,
- .read = nsc_gpio_read,
- .write = nsc_gpio_write,
-};
-
-static int pc8736x_legacy_register(struct pc8736x_gpio *gpio)
-{
- int ret, port;
-
- for (port = 0; port < ARRAY_SIZE(port_offset); port++)
- pc8736x_legacy_shadow[port] =
- inb_p(gpio->base + port_offset[port] + PC8736X_GPIO_PORT_OUT);
-
- if (major) {
- pc8736x_devt = MKDEV(major, 0);
- ret = register_chrdev_region(pc8736x_devt, LEGACY_NGPIO, LEGACY_NAME);
- } else {
- ret = alloc_chrdev_region(&pc8736x_devt, 0, LEGACY_NGPIO, LEGACY_NAME);
- }
- if (ret)
- return ret;
-
- pc8736x_legacy_gpio = gpio;
- pc8736x_legacy_ops.dev = gpio->gc.parent;
- cdev_init(&pc8736x_gpio_cdev, &pc8736x_legacy_fops);
- pc8736x_gpio_cdev.owner = THIS_MODULE;
- ret = cdev_add(&pc8736x_gpio_cdev, pc8736x_devt, LEGACY_NGPIO);
- if (ret)
- unregister_chrdev_region(pc8736x_devt, LEGACY_NGPIO);
-
- return ret;
-}
-
static int pc8736x_gpio_probe(struct device *dev, unsigned int id)
{
struct pc8736x_gpio *gpio;
unsigned int sio, base;
- int ret;
if (pc8736x_present(SIO_BASE1))
sio = SIO_BASE1;
@@ -345,32 +247,18 @@ static int pc8736x_gpio_probe(struct device *dev, unsigned int id)
.set_config = pc8736x_gpio_set_config,
};
- ret = devm_gpiochip_add_data(dev, &gpio->gc, gpio);
- if (ret)
- return ret;
-
- return pc8736x_legacy_register(gpio);
-}
-
-static void pc8736x_gpio_remove(struct device *dev, unsigned int id)
-{
- cdev_del(&pc8736x_gpio_cdev);
- unregister_chrdev_region(pc8736x_devt, LEGACY_NGPIO);
+ return devm_gpiochip_add_data(dev, &gpio->gc, gpio);
}
static struct isa_driver pc8736x_gpio_driver = {
.driver = {
.name = DRVNAME,
.owner = THIS_MODULE,
- /* An open legacy GPIO file pins the module, but not the chip. */
- .suppress_bind_attrs = true,
},
.probe = pc8736x_gpio_probe,
- .remove = pc8736x_gpio_remove,
};
module_isa_driver(pc8736x_gpio_driver, 1);
MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
MODULE_DESCRIPTION("NatSemi/Winbond PC87365/PC87366 GPIO driver");
MODULE_LICENSE("GPL");
-MODULE_ALIAS(LEGACY_NAME);
diff --git a/drivers/gpio/gpio-scx200.c b/drivers/gpio/gpio-scx200.c
index 5c0e86474481..0174cc7c0e97 100644
--- a/drivers/gpio/gpio-scx200.c
+++ b/drivers/gpio/gpio-scx200.c
@@ -6,15 +6,11 @@
*/
#include <linux/bitmap.h>
-#include <linux/cdev.h>
#include <linux/cleanup.h>
-#include <linux/fs.h>
#include <linux/gpio/driver.h>
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/module.h>
-#include <linux/mutex.h>
-#include <linux/nsc_gpio.h>
#include <linux/pci.h>
#include <linux/pinctrl/pinconf-generic.h>
#include <linux/platform_device.h>
@@ -23,7 +19,6 @@
#include <linux/spinlock.h>
#define DRVNAME "gpio-scx200"
-#define LEGACY_NAME "scx200_gpio"
#define SCX200_NGPIO 32
#define SCX200_DATA_OUT 0x00
@@ -185,137 +180,6 @@ static int scx200_gpio_init_valid_mask(struct gpio_chip *gc,
return 0;
}
-static int major;
-module_param(major, int, 0);
-MODULE_PARM_DESC(major, "Major device number for the legacy interface");
-
-static struct cdev scx200_legacy_cdev;
-static dev_t scx200_legacy_devt;
-
-/* Protects the legacy frontend against provider detach during file I/O. */
-static DEFINE_MUTEX(scx200_legacy_lock);
-static struct scx200_gpio *scx200_legacy_gpio;
-
-static u32 scx200_legacy_config(unsigned int offset, u32 mask, u32 value)
-{
- struct scx200_gpio *gpio = scx200_legacy_gpio;
- u32 config;
-
- guard(raw_spinlock_irqsave)(&gpio->lock);
- config = scx200_gpio_read_config(gpio, offset);
- scx200_gpio_update_config(gpio, config, ~mask, value);
- return config;
-}
-
-static int scx200_legacy_get(unsigned int offset)
-{
- return scx200_gpio_get(&scx200_legacy_gpio->gc, offset);
-}
-
-static void scx200_legacy_set(unsigned int offset, int value)
-{
- scx200_gpio_set(&scx200_legacy_gpio->gc, offset, value);
-}
-
-static int scx200_legacy_current(unsigned int offset)
-{
- return !!(inl(scx200_legacy_gpio->base + SCX200_DATA_OUT) & BIT(offset));
-}
-
-static struct nsc_gpio_ops scx200_legacy_ops = {
- .gpio_config = scx200_legacy_config,
- .gpio_dump = nsc_gpio_dump,
- .gpio_get = scx200_legacy_get,
- .gpio_set = scx200_legacy_set,
- .gpio_current = scx200_legacy_current,
-};
-
-static int scx200_legacy_open(struct inode *inode, struct file *file)
-{
- guard(mutex)(&scx200_legacy_lock);
- if (!scx200_legacy_gpio)
- return -ENODEV;
-
- file->private_data = &scx200_legacy_ops;
- return nonseekable_open(inode, file);
-}
-
-static ssize_t scx200_legacy_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos)
-{
- guard(mutex)(&scx200_legacy_lock);
- if (!scx200_legacy_gpio)
- return -ENODEV;
-
- return nsc_gpio_read(file, buf, len, ppos);
-}
-
-static ssize_t scx200_legacy_write(struct file *file, const char __user *buf,
- size_t len, loff_t *ppos)
-{
- guard(mutex)(&scx200_legacy_lock);
- if (!scx200_legacy_gpio)
- return -ENODEV;
-
- return nsc_gpio_write(file, buf, len, ppos);
-}
-
-static const struct file_operations scx200_legacy_fops = {
- .owner = THIS_MODULE,
- .open = scx200_legacy_open,
- .read = scx200_legacy_read,
- .write = scx200_legacy_write,
-};
-
-static void scx200_legacy_detach(void *data)
-{
- guard(mutex)(&scx200_legacy_lock);
- if (scx200_legacy_gpio == data) {
- scx200_legacy_gpio = NULL;
- scx200_legacy_ops.dev = NULL;
- }
-}
-
-static int scx200_legacy_attach(struct scx200_gpio *gpio)
-{
- struct device *dev = gpio->gc.parent;
- dev_t devid;
- int ret;
-
- ret = devm_add_action(dev, scx200_legacy_detach, gpio);
- if (ret)
- return ret;
-
- guard(mutex)(&scx200_legacy_lock);
- if (scx200_legacy_gpio)
- return -EBUSY;
-
- if (!scx200_legacy_devt) {
- if (major) {
- devid = MKDEV(major, 0);
- ret = register_chrdev_region(devid, SCX200_NGPIO, LEGACY_NAME);
- } else {
- ret = alloc_chrdev_region(&devid, 0, SCX200_NGPIO, LEGACY_NAME);
- }
- if (ret)
- return ret;
-
- cdev_init(&scx200_legacy_cdev, &scx200_legacy_fops);
- scx200_legacy_cdev.owner = THIS_MODULE;
- ret = cdev_add(&scx200_legacy_cdev, devid, SCX200_NGPIO);
- if (ret) {
- unregister_chrdev_region(devid, SCX200_NGPIO);
- return ret;
- }
-
- scx200_legacy_devt = devid;
- }
-
- scx200_legacy_gpio = gpio;
- scx200_legacy_ops.dev = dev;
- return 0;
-}
-
static void scx200_gpio_remove_swnode(void *data)
{
device_remove_software_node(data);
@@ -365,11 +229,7 @@ static int scx200_gpio_probe(struct platform_device *pdev)
.init_valid_mask = scx200_gpio_init_valid_mask,
};
- ret = devm_gpiochip_add_data(dev, &gpio->gc, gpio);
- if (ret)
- return ret;
-
- return scx200_legacy_attach(gpio);
+ return devm_gpiochip_add_data(dev, &gpio->gc, gpio);
}
static struct platform_driver scx200_gpio_driver = {
@@ -377,24 +237,9 @@ static struct platform_driver scx200_gpio_driver = {
.probe = scx200_gpio_probe,
};
-static int __init scx200_gpio_init(void)
-{
- return platform_driver_register(&scx200_gpio_driver);
-}
-module_init(scx200_gpio_init);
-
-static void __exit scx200_gpio_exit(void)
-{
- platform_driver_unregister(&scx200_gpio_driver);
- if (scx200_legacy_devt) {
- cdev_del(&scx200_legacy_cdev);
- unregister_chrdev_region(scx200_legacy_devt, SCX200_NGPIO);
- }
-}
-module_exit(scx200_gpio_exit);
+module_platform_driver(scx200_gpio_driver);
MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
MODULE_DESCRIPTION("NatSemi/AMD SCx200 GPIO driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:" DRVNAME);
-MODULE_ALIAS(LEGACY_NAME);
diff --git a/include/linux/nsc_gpio.h b/include/linux/nsc_gpio.h
deleted file mode 100644
index d7a04a6e3783..000000000000
--- a/include/linux/nsc_gpio.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/**
- nsc_gpio.c
-
- National Semiconductor GPIO common access methods.
-
- struct nsc_gpio_ops abstracts the low-level access
- operations for the GPIO units on 2 NSC chip families; the GEODE
- integrated CPU, and the PC-8736[03456] integrated PC-peripheral
- chips.
-
- The GPIO units on these chips have the same pin architecture, but
- the access methods differ. Thus, scx200_gpio and pc8736x_gpio
- implement their own versions of these routines; and use the common
- file-operations routines implemented in nsc_gpio module.
-
- Copyright (c) 2005 Jim Cromie <jim.cromie@gmail.com>
-
- NB: this work was tested on the Geode SC-1100 and PC-87366 chips.
- NSC sold the GEODE line to AMD, and the PC-8736x line to Winbond.
-*/
-
-struct nsc_gpio_ops {
- struct module* owner;
- u32 (*gpio_config) (unsigned iminor, u32 mask, u32 bits);
- void (*gpio_dump) (struct nsc_gpio_ops *amp, unsigned iminor);
- int (*gpio_get) (unsigned iminor);
- void (*gpio_set) (unsigned iminor, int state);
- void (*gpio_change) (unsigned iminor);
- int (*gpio_current) (unsigned iminor);
- struct device* dev; /* for dev_dbg() support, set in init */
-};
-
-extern ssize_t nsc_gpio_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos);
-
-extern ssize_t nsc_gpio_read(struct file *file, char __user *buf,
- size_t len, loff_t *ppos);
-
-extern void nsc_gpio_dump(struct nsc_gpio_ops *amp, unsigned index);
-
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib
2026-11-23 12:29 [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib Linus Walleij
` (2 preceding siblings ...)
2026-11-23 12:29 ` [PATCH 3/3] gpio: remove the legacy NSC GPIO API Linus Walleij
@ 2026-11-23 12:54 ` Greg Kroah-Hartman
3 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-23 12:54 UTC (permalink / raw)
To: Linus Walleij
Cc: Arnd Bergmann, Bartosz Golaszewski, Christer Weinigel, Jim Cromie,
x86, Lee Jones, Pavel Machek, Griffin Kroah-Hartman, linux-gpio,
linux-leds
On Mon, Nov 23, 2026 at 01:29:52PM +0100, Linus Walleij wrote:
> This is an obvious attack patch to see if anyone is really using
> the custom API from these deviant drivers/char/* GPIO drivers
> from the early 2000s.
>
> Probe PC8736x through the ISA bus API and create the SCx200 GPIO device
> from its PCI bridge. Register both controllers with gpiolib using port
> I/O. Describe the net48xx and WRAP LED GPIOs with software nodes and
> switch both LED drivers to descriptors.
>
> Remove the private GPIO API and per-pin character devices. We assume
> there are no remaining users of the old NSC GPIO userspace ABI.
>
> An LLM assisted in the implementation and x86-32 build checks.
>
> ---
> Linus Walleij (3):
> gpio: convert PC8736x to gpiolib
> gpio: convert SCx200 to gpiolib and use descriptors for board LEDs
> gpio: remove the legacy NSC GPIO API
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-23 12:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 12:29 [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib Linus Walleij
2026-11-23 12:29 ` [PATCH 1/3] gpio: convert PC8736x " Linus Walleij
2026-11-23 12:29 ` [PATCH 2/3] gpio: convert SCx200 to gpiolib and use descriptors for board LEDs Linus Walleij
2026-11-23 12:29 ` [PATCH 3/3] gpio: remove the legacy NSC GPIO API Linus Walleij
2026-11-23 12:54 ` [PATCH 0/3] Convert National Semiconductor GPIO drivers to gpiolib Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox