aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pps/clients
diff options
context:
space:
mode:
authorAlexander Gordeev <lasaine@lvk.cs.msu.su>2011-01-12 20:00:51 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 11:03:19 -0500
commit5e196d34a776420278e4117b4742cd9d3f2350ed (patch)
tree86187af6a600876506261758a00c7c42e6037283 /drivers/pps/clients
parent6f4229b51106cbc859e9d8209b22c8a2ec749e64 (diff)
pps: access pps device by direct pointer
Using device index as a pointer needs some unnecessary work to be done every time the pointer is needed (in irq handler for example). Using a direct pointer is much more easy (and safe as well). Signed-off-by: Alexander Gordeev <lasaine@lvk.cs.msu.su> Acked-by: Rodolfo Giometti <giometti@linux.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/pps/clients')
-rw-r--r--drivers/pps/clients/pps-ktimer.c30
-rw-r--r--drivers/pps/clients/pps-ldisc.c41
2 files changed, 39 insertions, 32 deletions
diff --git a/drivers/pps/clients/pps-ktimer.c b/drivers/pps/clients/pps-ktimer.c
index e1bdd8bc8c9c..966ead188ee2 100644
--- a/drivers/pps/clients/pps-ktimer.c
+++ b/drivers/pps/clients/pps-ktimer.c
@@ -31,7 +31,7 @@
31 * Global variables 31 * Global variables
32 */ 32 */
33 33
34static int source; 34static struct pps_device *pps;
35static struct timer_list ktimer; 35static struct timer_list ktimer;
36 36
37/* 37/*
@@ -47,7 +47,7 @@ static void pps_ktimer_event(unsigned long ptr)
47 47
48 pr_info("PPS event at %lu\n", jiffies); 48 pr_info("PPS event at %lu\n", jiffies);
49 49
50 pps_event(source, &ts, PPS_CAPTUREASSERT, NULL); 50 pps_event(pps, &ts, PPS_CAPTUREASSERT, NULL);
51 51
52 mod_timer(&ktimer, jiffies + HZ); 52 mod_timer(&ktimer, jiffies + HZ);
53} 53}
@@ -56,12 +56,11 @@ static void pps_ktimer_event(unsigned long ptr)
56 * The echo function 56 * The echo function
57 */ 57 */
58 58
59static void pps_ktimer_echo(int source, int event, void *data) 59static void pps_ktimer_echo(struct pps_device *pps, int event, void *data)
60{ 60{
61 pr_info("echo %s %s for source %d\n", 61 dev_info(pps->dev, "echo %s %s\n",
62 event & PPS_CAPTUREASSERT ? "assert" : "", 62 event & PPS_CAPTUREASSERT ? "assert" : "",
63 event & PPS_CAPTURECLEAR ? "clear" : "", 63 event & PPS_CAPTURECLEAR ? "clear" : "");
64 source);
65} 64}
66 65
67/* 66/*
@@ -84,30 +83,27 @@ static struct pps_source_info pps_ktimer_info = {
84 83
85static void __exit pps_ktimer_exit(void) 84static void __exit pps_ktimer_exit(void)
86{ 85{
87 del_timer_sync(&ktimer); 86 dev_info(pps->dev, "ktimer PPS source unregistered\n");
88 pps_unregister_source(source);
89 87
90 pr_info("ktimer PPS source unregistered\n"); 88 del_timer_sync(&ktimer);
89 pps_unregister_source(pps);
91} 90}
92 91
93static int __init pps_ktimer_init(void) 92static int __init pps_ktimer_init(void)
94{ 93{
95 int ret; 94 pps = pps_register_source(&pps_ktimer_info,
96
97 ret = pps_register_source(&pps_ktimer_info,
98 PPS_CAPTUREASSERT | PPS_OFFSETASSERT); 95 PPS_CAPTUREASSERT | PPS_OFFSETASSERT);
99 if (ret < 0) { 96 if (pps == NULL) {
100 printk(KERN_ERR "cannot register ktimer source\n"); 97 printk(KERN_ERR "cannot register ktimer source\n");
101 return ret; 98 return -ENOMEM;
102 } 99 }
103 source = ret;
104 100
105 setup_timer(&ktimer, pps_ktimer_event, 0); 101 setup_timer(&ktimer, pps_ktimer_event, 0);
106 mod_timer(&ktimer, jiffies + HZ); 102 mod_timer(&ktimer, jiffies + HZ);
107 103
108 pr_info("ktimer PPS source registered at %d\n", source); 104 dev_info(pps->dev, "ktimer PPS source registered\n");
109 105
110 return 0; 106 return 0;
111} 107}
112 108
113module_init(pps_ktimer_init); 109module_init(pps_ktimer_init);
diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c
index 20fc9f7645c8..1517f5498ec0 100644
--- a/drivers/pps/clients/pps-ldisc.c
+++ b/drivers/pps/clients/pps-ldisc.c
@@ -29,7 +29,7 @@
29static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status, 29static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status,
30 struct pps_event_time *ts) 30 struct pps_event_time *ts)
31{ 31{
32 int id = (long)tty->disc_data; 32 struct pps_device *pps = (struct pps_device *)tty->disc_data;
33 struct pps_event_time __ts; 33 struct pps_event_time __ts;
34 34
35 /* First of all we get the time stamp... */ 35 /* First of all we get the time stamp... */
@@ -39,12 +39,14 @@ static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status,
39 if (!ts) /* No. Do it ourself! */ 39 if (!ts) /* No. Do it ourself! */
40 ts = &__ts; 40 ts = &__ts;
41 41
42 BUG_ON(pps == NULL);
43
42 /* Now do the PPS event report */ 44 /* Now do the PPS event report */
43 pps_event(id, ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR, 45 pps_event(pps, ts, status ? PPS_CAPTUREASSERT :
44 NULL); 46 PPS_CAPTURECLEAR, NULL);
45 47
46 pr_debug("PPS %s at %lu on source #%d\n", 48 dev_dbg(pps->dev, "PPS %s at %lu\n",
47 status ? "assert" : "clear", jiffies, id); 49 status ? "assert" : "clear", jiffies);
48} 50}
49 51
50static int (*alias_n_tty_open)(struct tty_struct *tty); 52static int (*alias_n_tty_open)(struct tty_struct *tty);
@@ -54,6 +56,7 @@ static int pps_tty_open(struct tty_struct *tty)
54 struct pps_source_info info; 56 struct pps_source_info info;
55 struct tty_driver *drv = tty->driver; 57 struct tty_driver *drv = tty->driver;
56 int index = tty->index + drv->name_base; 58 int index = tty->index + drv->name_base;
59 struct pps_device *pps;
57 int ret; 60 int ret;
58 61
59 info.owner = THIS_MODULE; 62 info.owner = THIS_MODULE;
@@ -64,34 +67,42 @@ static int pps_tty_open(struct tty_struct *tty)
64 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \ 67 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
65 PPS_CANWAIT | PPS_TSFMT_TSPEC; 68 PPS_CANWAIT | PPS_TSFMT_TSPEC;
66 69
67 ret = pps_register_source(&info, PPS_CAPTUREBOTH | \ 70 pps = pps_register_source(&info, PPS_CAPTUREBOTH | \
68 PPS_OFFSETASSERT | PPS_OFFSETCLEAR); 71 PPS_OFFSETASSERT | PPS_OFFSETCLEAR);
69 if (ret < 0) { 72 if (pps == NULL) {
70 pr_err("cannot register PPS source \"%s\"\n", info.path); 73 pr_err("cannot register PPS source \"%s\"\n", info.path);
71 return ret; 74 return -ENOMEM;
72 } 75 }
73 tty->disc_data = (void *)(long)ret; 76 tty->disc_data = pps;
74 77
75 /* Should open N_TTY ldisc too */ 78 /* Should open N_TTY ldisc too */
76 ret = alias_n_tty_open(tty); 79 ret = alias_n_tty_open(tty);
77 if (ret < 0) 80 if (ret < 0) {
78 pps_unregister_source((long)tty->disc_data); 81 pr_err("cannot open tty ldisc \"%s\"\n", info.path);
82 goto err_unregister;
83 }
79 84
80 pr_info("PPS source #%d \"%s\" added\n", ret, info.path); 85 dev_info(pps->dev, "source \"%s\" added\n", info.path);
81 86
82 return 0; 87 return 0;
88
89err_unregister:
90 tty->disc_data = NULL;
91 pps_unregister_source(pps);
92 return ret;
83} 93}
84 94
85static void (*alias_n_tty_close)(struct tty_struct *tty); 95static void (*alias_n_tty_close)(struct tty_struct *tty);
86 96
87static void pps_tty_close(struct tty_struct *tty) 97static void pps_tty_close(struct tty_struct *tty)
88{ 98{
89 int id = (long)tty->disc_data; 99 struct pps_device *pps = (struct pps_device *)tty->disc_data;
90 100
91 pps_unregister_source(id);
92 alias_n_tty_close(tty); 101 alias_n_tty_close(tty);
93 102
94 pr_info("PPS source #%d removed\n", id); 103 tty->disc_data = NULL;
104 dev_info(pps->dev, "removed\n");
105 pps_unregister_source(pps);
95} 106}
96 107
97static struct tty_ldisc_ops pps_ldisc_ops; 108static struct tty_ldisc_ops pps_ldisc_ops;