]> arthur.barton.de Git - ppin.git/blobdiff - ppin.c
Add some examle scripts
[ppin.git] / ppin.c
diff --git a/ppin.c b/ppin.c
index 9fc504d6565712a373bb073f7016b73477da3dbf..52315c838cc77bc5596bace06dc780402d60afee 100644 (file)
--- a/ppin.c
+++ b/ppin.c
@@ -1,15 +1,15 @@
 /*
- *             Parallel Port PIN driver for Linux 2.6: ppin
+ *             Parallel Port Pin driver for Linux 2.6: ppin
  *
  *             This kernel module will register the /dev/ppin (10, 151)
- *             device which controls up to eight PINs through the first
+ *             device which controls up to eight pins through the first
  *             parallel port.
  *
- *             Controlling the PINs is as easy as 'echo Num State >/dev/ppin',
+ *             Controlling the pins is as easy as 'echo Num State >/dev/ppin',
  *             where Num is 0 to 7 and State is one of 'on', 'off'.
- *             For example: "echo 3 on >/dev/ppin" switches the 3rd PIN on.
+ *             For example: "echo 3 on >/dev/ppin" switches the 3rd pin on.
  *
- *             You can read the status of the PINs with 'cat /dev/ppin'.
+ *             You can read the status of the pins with 'cat /dev/ppin'.
  *
  *             This program is free software; you can redistribute it and/or
  *             modify it under the terms of the GNU General Public License
@@ -19,7 +19,7 @@
  * Authors:    Alexander Barton, <alex@barton.de> (for Linux 2.6, 2009)
  *
  *             This work is heavily(!) based on the "devled" driver written by
- *             Konstantinos Natsakis, <cyfex@mail.com> for Linux 2.2/2.4.
+ *             Konstantinos Natsakis, <cyfex@mail.com> (for Linux 2.2/2.4).
  */
 
 #include <linux/module.h>
@@ -47,6 +47,18 @@ MODULE_AUTHOR("Alexander Barton, alex@barton.de");
 MODULE_DESCRIPTION("Driver for controlling the state of parallel port PINs");
 MODULE_LICENSE("GPL");
 
+void
+set_pins(void)
+{
+       if (parport_claim_or_block(parport_pins) < 0) {
+               printk(KERN_ERR
+                      "Could not claim the " PPIN_DEV " parallel port device\n");
+               return;
+       }
+       parport_write_data(parport_pins->port, pin_state);
+       parport_release(parport_pins);
+}
+
 static void
 ppin_attach(struct parport *port)
 {
@@ -81,7 +93,7 @@ static struct parport_driver ppin_driver = {
        PPIN_NAME,
        ppin_attach,
        ppin_detach,
-       NULL
+       {NULL}
 };
 
 static ssize_t
@@ -143,15 +155,7 @@ ppin_write(struct file *file, const char *buf, size_t count, loff_t * ppos)
                return count;
        }
 
-       if (parport_claim_or_block(parport_pins) < 0) {
-               printk(KERN_ERR
-                      "Could not claim the " PPIN_DEV " parallel port device\n");
-               return 0;
-       }
-
-       parport_write_data(parport_pins->port, pin_state);
-
-       parport_release(parport_pins);
+       set_pins();
        return count;
 }
 
@@ -204,6 +208,8 @@ ppin_init(void)
        }
 
        printk(KERN_INFO "" PPIN_NAME " driver v%s loaded\n", PPIN_VERSION);
+
+       set_pins();
        return 0;
 }