Lines Matching +full:static +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PTP 1588 clock support - sysfs interface.
12 static ssize_t clock_name_show(struct device *dev, in clock_name_show()
16 return snprintf(page, PAGE_SIZE-1, "%s\n", ptp->info->name); in clock_name_show()
18 static DEVICE_ATTR_RO(clock_name);
21 static ssize_t var##_show(struct device *dev, \
25 return snprintf(page, PAGE_SIZE-1, "%d\n", ptp->info->var); \
27 static DEVICE_ATTR(name, 0444, var##_show, NULL);
36 static ssize_t extts_enable_store(struct device *dev, in extts_enable_store()
41 struct ptp_clock_info *ops = ptp->info; in extts_enable_store()
43 int cnt, enable; in extts_enable_store() local
44 int err = -EINVAL; in extts_enable_store()
46 cnt = sscanf(buf, "%u %d", &req.extts.index, &enable); in extts_enable_store()
49 if (req.extts.index >= ops->n_ext_ts) in extts_enable_store()
52 err = ops->enable(ops, &req, enable ? 1 : 0); in extts_enable_store()
60 static DEVICE_ATTR(extts_enable, 0220, NULL, extts_enable_store);
62 static ssize_t extts_fifo_show(struct device *dev, in extts_fifo_show()
66 struct timestamp_event_queue *queue = &ptp->tsevq; in extts_fifo_show()
74 if (mutex_lock_interruptible(&ptp->tsevq_mux)) in extts_fifo_show()
75 return -ERESTARTSYS; in extts_fifo_show()
77 spin_lock_irqsave(&queue->lock, flags); in extts_fifo_show()
80 event = queue->buf[queue->head]; in extts_fifo_show()
81 queue->head = (queue->head + 1) % PTP_MAX_TIMESTAMPS; in extts_fifo_show()
83 spin_unlock_irqrestore(&queue->lock, flags); in extts_fifo_show()
91 mutex_unlock(&ptp->tsevq_mux); in extts_fifo_show()
94 static DEVICE_ATTR(fifo, 0444, extts_fifo_show, NULL);
96 static ssize_t period_store(struct device *dev, in period_store()
101 struct ptp_clock_info *ops = ptp->info; in period_store()
103 int cnt, enable, err = -EINVAL; in period_store() local
110 if (req.perout.index >= ops->n_per_out) in period_store()
113 enable = req.perout.period.sec || req.perout.period.nsec; in period_store()
114 err = ops->enable(ops, &req, enable); in period_store()
122 static DEVICE_ATTR(period, 0220, NULL, period_store);
124 static ssize_t pps_enable_store(struct device *dev, in pps_enable_store()
129 struct ptp_clock_info *ops = ptp->info; in pps_enable_store()
131 int cnt, enable; in pps_enable_store() local
132 int err = -EINVAL; in pps_enable_store()
135 return -EPERM; in pps_enable_store()
137 cnt = sscanf(buf, "%d", &enable); in pps_enable_store()
141 err = ops->enable(ops, &req, enable ? 1 : 0); in pps_enable_store()
149 static DEVICE_ATTR(pps_enable, 0220, NULL, pps_enable_store);
151 static struct attribute *ptp_attrs[] = {
168 static umode_t ptp_is_attribute_visible(struct kobject *kobj, in ptp_is_attribute_visible()
173 struct ptp_clock_info *info = ptp->info; in ptp_is_attribute_visible()
174 umode_t mode = attr->mode; in ptp_is_attribute_visible()
178 if (!info->n_ext_ts) in ptp_is_attribute_visible()
181 if (!info->n_per_out) in ptp_is_attribute_visible()
184 if (!info->pps) in ptp_is_attribute_visible()
191 static const struct attribute_group ptp_group = {
201 static int ptp_pin_name2index(struct ptp_clock *ptp, const char *name) in ptp_pin_name2index()
204 for (i = 0; i < ptp->info->n_pins; i++) { in ptp_pin_name2index()
205 if (!strcmp(ptp->info->pin_config[i].name, name)) in ptp_pin_name2index()
208 return -1; in ptp_pin_name2index()
211 static ssize_t ptp_pin_show(struct device *dev, struct device_attribute *attr, in ptp_pin_show()
218 index = ptp_pin_name2index(ptp, attr->attr.name); in ptp_pin_show()
220 return -EINVAL; in ptp_pin_show()
222 if (mutex_lock_interruptible(&ptp->pincfg_mux)) in ptp_pin_show()
223 return -ERESTARTSYS; in ptp_pin_show()
225 func = ptp->info->pin_config[index].func; in ptp_pin_show()
226 chan = ptp->info->pin_config[index].chan; in ptp_pin_show()
228 mutex_unlock(&ptp->pincfg_mux); in ptp_pin_show()
233 static ssize_t ptp_pin_store(struct device *dev, struct device_attribute *attr, in ptp_pin_store()
242 return -EINVAL; in ptp_pin_store()
244 index = ptp_pin_name2index(ptp, attr->attr.name); in ptp_pin_store()
246 return -EINVAL; in ptp_pin_store()
248 if (mutex_lock_interruptible(&ptp->pincfg_mux)) in ptp_pin_store()
249 return -ERESTARTSYS; in ptp_pin_store()
251 mutex_unlock(&ptp->pincfg_mux); in ptp_pin_store()
260 struct ptp_clock_info *info = ptp->info; in ptp_populate_pin_groups()
261 int err = -ENOMEM, i, n_pins = info->n_pins; in ptp_populate_pin_groups()
266 ptp->pin_dev_attr = kcalloc(n_pins, sizeof(*ptp->pin_dev_attr), in ptp_populate_pin_groups()
268 if (!ptp->pin_dev_attr) in ptp_populate_pin_groups()
271 ptp->pin_attr = kcalloc(1 + n_pins, sizeof(*ptp->pin_attr), GFP_KERNEL); in ptp_populate_pin_groups()
272 if (!ptp->pin_attr) in ptp_populate_pin_groups()
276 struct device_attribute *da = &ptp->pin_dev_attr[i]; in ptp_populate_pin_groups()
277 sysfs_attr_init(&da->attr); in ptp_populate_pin_groups()
278 da->attr.name = info->pin_config[i].name; in ptp_populate_pin_groups()
279 da->attr.mode = 0644; in ptp_populate_pin_groups()
280 da->show = ptp_pin_show; in ptp_populate_pin_groups()
281 da->store = ptp_pin_store; in ptp_populate_pin_groups()
282 ptp->pin_attr[i] = &da->attr; in ptp_populate_pin_groups()
285 ptp->pin_attr_group.name = "pins"; in ptp_populate_pin_groups()
286 ptp->pin_attr_group.attrs = ptp->pin_attr; in ptp_populate_pin_groups()
288 ptp->pin_attr_groups[0] = &ptp->pin_attr_group; in ptp_populate_pin_groups()
293 kfree(ptp->pin_dev_attr); in ptp_populate_pin_groups()
300 kfree(ptp->pin_attr); in ptp_cleanup_pin_groups()
301 kfree(ptp->pin_dev_attr); in ptp_cleanup_pin_groups()