1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/device.h>
26#include <linux/init.h>
27#include <linux/spinlock.h>
28#include <linux/pps_kernel.h>
29
30#include "kc.h"
31
32
33
34
35
36
37static DEFINE_SPINLOCK(pps_kc_hardpps_lock);
38
39static struct pps_device *pps_kc_hardpps_dev;
40static int pps_kc_hardpps_mode;
41
42
43
44
45
46
47
48
49int pps_kc_bind(struct pps_device *pps, struct pps_bind_args *bind_args)
50{
51
52 spin_lock_irq(&pps_kc_hardpps_lock);
53
54 if (bind_args->edge == 0)
55 if (pps_kc_hardpps_dev == pps) {
56 pps_kc_hardpps_mode = 0;
57 pps_kc_hardpps_dev = NULL;
58 spin_unlock_irq(&pps_kc_hardpps_lock);
59 dev_info(pps->dev, "unbound kernel"
60 " consumer\n");
61 } else {
62 spin_unlock_irq(&pps_kc_hardpps_lock);
63 dev_err(pps->dev, "selected kernel consumer"
64 " is not bound\n");
65 return -EINVAL;
66 }
67 else
68 if (pps_kc_hardpps_dev == NULL ||
69 pps_kc_hardpps_dev == pps) {
70 pps_kc_hardpps_mode = bind_args->edge;
71 pps_kc_hardpps_dev = pps;
72 spin_unlock_irq(&pps_kc_hardpps_lock);
73 dev_info(pps->dev, "bound kernel consumer: "
74 "edge=0x%x\n", bind_args->edge);
75 } else {
76 spin_unlock_irq(&pps_kc_hardpps_lock);
77 dev_err(pps->dev, "another kernel consumer"
78 " is already bound\n");
79 return -EINVAL;
80 }
81
82 return 0;
83}
84
85
86
87
88
89
90
91
92void pps_kc_remove(struct pps_device *pps)
93{
94 spin_lock_irq(&pps_kc_hardpps_lock);
95 if (pps == pps_kc_hardpps_dev) {
96 pps_kc_hardpps_mode = 0;
97 pps_kc_hardpps_dev = NULL;
98 spin_unlock_irq(&pps_kc_hardpps_lock);
99 dev_info(pps->dev, "unbound kernel consumer"
100 " on device removal\n");
101 } else
102 spin_unlock_irq(&pps_kc_hardpps_lock);
103}
104
105
106
107
108
109
110
111
112void pps_kc_event(struct pps_device *pps, struct pps_event_time *ts,
113 int event)
114{
115 unsigned long flags;
116
117
118 spin_lock_irqsave(&pps_kc_hardpps_lock, flags);
119 if (pps == pps_kc_hardpps_dev && event & pps_kc_hardpps_mode)
120 hardpps(&ts->ts_real, &ts->ts_raw);
121 spin_unlock_irqrestore(&pps_kc_hardpps_lock, flags);
122}
123