led(4): Turn this into a module. Only used by acpi_thinkpad and acpi_asus.
authorImre Vadász <imre@vdsz.com>
Sun, 21 Jan 2018 16:48:53 +0000 (17:48 +0100)
committerImre Vadász <imre@vdsz.com>
Sun, 28 Jan 2018 15:45:19 +0000 (16:45 +0100)
sys/conf/files
sys/config/LINT64
sys/dev/acpica/acpi_asus/acpi_asus.c
sys/dev/acpica/acpi_thinkpad/acpi_thinkpad.c
sys/dev/misc/Makefile
sys/dev/misc/led/Makefile [new file with mode: 0644]
sys/dev/misc/led/led.c

index 74cd732..8664e52 100644 (file)
@@ -1029,7 +1029,7 @@ dev/misc/ipmi/ipmi_smbus.c        optional ipmi smbus
 dev/misc/ipmi/ipmi_smbios.c    optional ipmi
 dev/misc/ipmi/ipmi_ssif.c      optional ipmi smbus
 dev/misc/ipmi/ipmi_pci.c       optional ipmi pci
-dev/misc/led/led.c             standard
+dev/misc/led/led.c             optional led
 dev/disk/md/md.c               optional md
 dev/raid/mfi/mfi.c             optional mfi
 dev/raid/mfi/mfi_debug.c       optional mfi
index a740502..a1c46a1 100644 (file)
@@ -2261,4 +2261,5 @@ options   ALTQ_DEBUG      #for debugging
 options                WDOG_DISABLE_ON_PANIC   # Automatically disable watchdogs on panic
 
 # LED
+device         led
 options                ERROR_LED_ON_PANIC      # If an error led is present, light it up on panic
index 219753b..1bdfab2 100644 (file)
@@ -539,6 +539,7 @@ static devclass_t acpi_asus_devclass;
 
 DRIVER_MODULE(acpi_asus, acpi, acpi_asus_driver, acpi_asus_devclass, NULL, NULL);
 MODULE_DEPEND(acpi_asus, acpi, 1, 1, 1);
+MODULE_DEPEND(acpi_asus, led, 1, 1, 1);
 
 static int
 acpi_asus_probe(device_t dev)
index 49693f0..09d4387 100644 (file)
@@ -328,6 +328,7 @@ static devclass_t acpi_thinkpad_devclass;
 DRIVER_MODULE(acpi_thinkpad, acpi, acpi_thinkpad_driver,
     acpi_thinkpad_devclass, NULL, NULL);
 MODULE_DEPEND(acpi_thinkpad, acpi, 1, 1, 1);
+MODULE_DEPEND(acpi_thinkpad, led, 1, 1, 1);
 static char    *thinkpad_ids[] = {"IBM0068", "LEN0068", NULL};
 
 static void
index 3edca17..968c4d9 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIR= amdsbwd cmx cpuctl dcons ecc ichwd ipmi joy kbdmux lpbb \
+SUBDIR= amdsbwd cmx cpuctl dcons ecc ichwd ipmi joy kbdmux led lpbb \
        nmdm pcfclock putter snp syscons tbridge coremctl dimm aperf
 
 .if ${MACHINE_ARCH} == "x86_64"
diff --git a/sys/dev/misc/led/Makefile b/sys/dev/misc/led/Makefile
new file mode 100644 (file)
index 0000000..98a6d58
--- /dev/null
@@ -0,0 +1,4 @@
+KMOD=  led
+SRCS=  led.c
+
+.include <bsd.kmod.mk>
index eb007e2..c49c462 100644 (file)
@@ -21,6 +21,7 @@
 #include <dev/misc/led/led.h>
 #include <sys/uio.h>
 #include <sys/device.h>
+#include <sys/module.h>
 
 struct ledsc {
        LIST_ENTRY(ledsc)       list;
@@ -339,14 +340,59 @@ led_destroy(struct cdev *dev)
        lockmgr(&led_lock2, LK_RELEASE);
 }
 
-static void
-led_drvinit(void *unused)
+static int
+led_drvinit(void)
 {
 
        led_unit = new_unrhdr(0, INT_MAX, NULL);
        lockinit(&led_lock, "LED lock", 0, LK_CANRECURSE);
        lockinit(&led_lock2, "LED lock2", 0, LK_CANRECURSE);
        callout_init_mp(&led_ch);
+       return 0;
 }
 
-SYSINIT(leddev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, led_drvinit, NULL);
+static int
+led_drvexit(void)
+{
+       int error = 0;
+
+       lockmgr(&led_lock, LK_EXCLUSIVE);
+       /* A minimal sanity check, before unloading. */
+       if (!LIST_EMPTY(&led_list))
+               error = EINVAL;
+       lockmgr(&led_lock, LK_RELEASE);
+       if (error == 0) {
+               callout_stop_sync(&led_ch);
+               delete_unrhdr(led_unit);
+               lockuninit(&led_lock);
+               lockuninit(&led_lock2);
+       }
+       return error;
+}
+
+static int
+led_modevent(module_t mod, int type, void *unused)
+{
+       int error;
+
+       switch (type) {
+       case MOD_LOAD:
+               error = led_drvinit();
+               break;
+        case MOD_UNLOAD:
+               error = led_drvexit();
+               break;
+       default:
+               error = EINVAL;
+               break;
+       }
+       return error;
+}
+
+static moduledata_t led_mod = {
+       "led",
+       led_modevent,
+       0
+};
+DECLARE_MODULE(led, led_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
+MODULE_VERSION(led, 1);