]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/pps/clients/pps-ldisc.c
Merge tag 'v2.6.38' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[mv-sheeva.git] / drivers / pps / clients / pps-ldisc.c
index 8e1932d29fd4b1ee2d5ef1320846a56010d09909..79451f2dea6a59a3fe11d1ee55bd5cf2466fa7d3 100644 (file)
@@ -19,6 +19,8 @@
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/serial_core.h>
 #include <linux/tty.h>
 #define PPS_TTY_MAGIC          0x0001
 
 static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status,
-                               struct timespec *ts)
+                               struct pps_event_time *ts)
 {
-       int id = (long)tty->disc_data;
-       struct timespec __ts;
-       struct pps_ktime pps_ts;
-
-       /* First of all we get the time stamp... */
-       getnstimeofday(&__ts);
-
-       /* Does caller give us a timestamp? */
-       if (ts) {       /* Yes. Let's use it! */
-               pps_ts.sec = ts->tv_sec;
-               pps_ts.nsec = ts->tv_nsec;
-       } else {        /* No. Do it ourself! */
-               pps_ts.sec = __ts.tv_sec;
-               pps_ts.nsec = __ts.tv_nsec;
-       }
+       struct pps_device *pps = (struct pps_device *)tty->disc_data;
+
+       BUG_ON(pps == NULL);
 
        /* Now do the PPS event report */
-       pps_event(id, &pps_ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR,
-                       NULL);
+       pps_event(pps, ts, status ? PPS_CAPTUREASSERT :
+                       PPS_CAPTURECLEAR, NULL);
 
-       pr_debug("PPS %s at %lu on source #%d\n",
-                       status ? "assert" : "clear", jiffies, id);
+       dev_dbg(pps->dev, "PPS %s at %lu\n",
+                       status ? "assert" : "clear", jiffies);
 }
 
 static int (*alias_n_tty_open)(struct tty_struct *tty);
@@ -60,6 +50,7 @@ static int pps_tty_open(struct tty_struct *tty)
        struct pps_source_info info;
        struct tty_driver *drv = tty->driver;
        int index = tty->index + drv->name_base;
+       struct pps_device *pps;
        int ret;
 
        info.owner = THIS_MODULE;
@@ -70,34 +61,42 @@ static int pps_tty_open(struct tty_struct *tty)
                        PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
                        PPS_CANWAIT | PPS_TSFMT_TSPEC;
 
-       ret = pps_register_source(&info, PPS_CAPTUREBOTH | \
+       pps = pps_register_source(&info, PPS_CAPTUREBOTH | \
                                PPS_OFFSETASSERT | PPS_OFFSETCLEAR);
-       if (ret < 0) {
+       if (pps == NULL) {
                pr_err("cannot register PPS source \"%s\"\n", info.path);
-               return ret;
+               return -ENOMEM;
        }
-       tty->disc_data = (void *)(long)ret;
+       tty->disc_data = pps;
 
        /* Should open N_TTY ldisc too */
        ret = alias_n_tty_open(tty);
-       if (ret < 0)
-               pps_unregister_source((long)tty->disc_data);
+       if (ret < 0) {
+               pr_err("cannot open tty ldisc \"%s\"\n", info.path);
+               goto err_unregister;
+       }
 
-       pr_info("PPS source #%d \"%s\" added\n", ret, info.path);
+       dev_info(pps->dev, "source \"%s\" added\n", info.path);
 
        return 0;
+
+err_unregister:
+       tty->disc_data = NULL;
+       pps_unregister_source(pps);
+       return ret;
 }
 
 static void (*alias_n_tty_close)(struct tty_struct *tty);
 
 static void pps_tty_close(struct tty_struct *tty)
 {
-       int id = (long)tty->disc_data;
+       struct pps_device *pps = (struct pps_device *)tty->disc_data;
 
-       pps_unregister_source(id);
        alias_n_tty_close(tty);
 
-       pr_info("PPS source #%d removed\n", id);
+       tty->disc_data = NULL;
+       dev_info(pps->dev, "removed\n");
+       pps_unregister_source(pps);
 }
 
 static struct tty_ldisc_ops pps_ldisc_ops;