Linux Audio

Check our new training course

Real-Time Linux with PREEMPT_RT training

Feb 18-20, 2025
Register
Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * PTP 1588 clock support - sysfs interface.
  4 *
  5 * Copyright (C) 2010 OMICRON electronics GmbH
  6 * Copyright 2021 NXP
 
 
 
 
 
 
 
 
 
 
 
 
 
  7 */
  8#include <linux/capability.h>
  9#include <linux/slab.h>
 10
 11#include "ptp_private.h"
 12
 13static ssize_t clock_name_show(struct device *dev,
 14			       struct device_attribute *attr, char *page)
 15{
 16	struct ptp_clock *ptp = dev_get_drvdata(dev);
 17	return sysfs_emit(page, "%s\n", ptp->info->name);
 18}
 19static DEVICE_ATTR_RO(clock_name);
 20
 21static ssize_t max_phase_adjustment_show(struct device *dev,
 22					 struct device_attribute *attr,
 23					 char *page)
 24{
 25	struct ptp_clock *ptp = dev_get_drvdata(dev);
 26
 27	return sysfs_emit(page, "%d\n", ptp->info->getmaxphase(ptp->info));
 28}
 29static DEVICE_ATTR_RO(max_phase_adjustment);
 30
 31#define PTP_SHOW_INT(name, var)						\
 32static ssize_t var##_show(struct device *dev,				\
 33			   struct device_attribute *attr, char *page)	\
 34{									\
 35	struct ptp_clock *ptp = dev_get_drvdata(dev);			\
 36	return sysfs_emit(page, "%d\n", ptp->info->var);	\
 37}									\
 38static DEVICE_ATTR(name, 0444, var##_show, NULL);
 39
 40PTP_SHOW_INT(max_adjustment, max_adj);
 41PTP_SHOW_INT(n_alarms, n_alarm);
 42PTP_SHOW_INT(n_external_timestamps, n_ext_ts);
 43PTP_SHOW_INT(n_periodic_outputs, n_per_out);
 44PTP_SHOW_INT(n_programmable_pins, n_pins);
 45PTP_SHOW_INT(pps_available, pps);
 
 
 
 
 
 
 
 
 
 
 
 
 
 46
 47static ssize_t extts_enable_store(struct device *dev,
 48				  struct device_attribute *attr,
 49				  const char *buf, size_t count)
 50{
 51	struct ptp_clock *ptp = dev_get_drvdata(dev);
 52	struct ptp_clock_info *ops = ptp->info;
 53	struct ptp_clock_request req = { .type = PTP_CLK_REQ_EXTTS };
 54	int cnt, enable;
 55	int err = -EINVAL;
 56
 57	cnt = sscanf(buf, "%u %d", &req.extts.index, &enable);
 58	if (cnt != 2)
 59		goto out;
 60	if (req.extts.index >= ops->n_ext_ts)
 61		goto out;
 62
 63	err = ops->enable(ops, &req, enable ? 1 : 0);
 64	if (err)
 65		goto out;
 66
 67	return count;
 68out:
 69	return err;
 70}
 71static DEVICE_ATTR(extts_enable, 0220, NULL, extts_enable_store);
 72
 73static ssize_t extts_fifo_show(struct device *dev,
 74			       struct device_attribute *attr, char *page)
 75{
 76	struct ptp_clock *ptp = dev_get_drvdata(dev);
 77	struct timestamp_event_queue *queue;
 78	struct ptp_extts_event event;
 79	unsigned long flags;
 80	size_t qcnt;
 81	int cnt = 0;
 82
 83	cnt = list_count_nodes(&ptp->tsevqs);
 84	if (cnt <= 0)
 85		goto out;
 86
 87	/* The sysfs fifo will always draw from the fist queue */
 88	queue = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue,
 89				 qlist);
 90
 91	memset(&event, 0, sizeof(event));
 92	spin_lock_irqsave(&queue->lock, flags);
 93	qcnt = queue_cnt(queue);
 94	if (qcnt) {
 95		event = queue->buf[queue->head];
 96		/* Paired with READ_ONCE() in queue_cnt() */
 97		WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS);
 98	}
 99	spin_unlock_irqrestore(&queue->lock, flags);
100
101	if (!qcnt)
102		goto out;
103
104	cnt = sysfs_emit(page, "%u %lld %u\n",
105			 event.index, event.t.sec, event.t.nsec);
106out:
 
107	return cnt;
108}
109static DEVICE_ATTR(fifo, 0444, extts_fifo_show, NULL);
110
111static ssize_t period_store(struct device *dev,
112			    struct device_attribute *attr,
113			    const char *buf, size_t count)
114{
115	struct ptp_clock *ptp = dev_get_drvdata(dev);
116	struct ptp_clock_info *ops = ptp->info;
117	struct ptp_clock_request req = { .type = PTP_CLK_REQ_PEROUT };
118	int cnt, enable, err = -EINVAL;
119
120	cnt = sscanf(buf, "%u %lld %u %lld %u", &req.perout.index,
121		     &req.perout.start.sec, &req.perout.start.nsec,
122		     &req.perout.period.sec, &req.perout.period.nsec);
123	if (cnt != 5)
124		goto out;
125	if (req.perout.index >= ops->n_per_out)
126		goto out;
127
128	enable = req.perout.period.sec || req.perout.period.nsec;
129	err = ops->enable(ops, &req, enable);
130	if (err)
131		goto out;
132
133	return count;
134out:
135	return err;
136}
137static DEVICE_ATTR(period, 0220, NULL, period_store);
138
139static ssize_t pps_enable_store(struct device *dev,
140				struct device_attribute *attr,
141				const char *buf, size_t count)
142{
143	struct ptp_clock *ptp = dev_get_drvdata(dev);
144	struct ptp_clock_info *ops = ptp->info;
145	struct ptp_clock_request req = { .type = PTP_CLK_REQ_PPS };
146	int cnt, enable;
147	int err = -EINVAL;
148
149	if (!capable(CAP_SYS_TIME))
150		return -EPERM;
151
152	cnt = sscanf(buf, "%d", &enable);
153	if (cnt != 1)
154		goto out;
155
156	err = ops->enable(ops, &req, enable ? 1 : 0);
157	if (err)
158		goto out;
159
160	return count;
161out:
162	return err;
163}
164static DEVICE_ATTR(pps_enable, 0220, NULL, pps_enable_store);
165
166static int unregister_vclock(struct device *dev, void *data)
167{
168	struct ptp_clock *ptp = dev_get_drvdata(dev);
169	struct ptp_clock_info *info = ptp->info;
170	struct ptp_vclock *vclock;
171	u32 *num = data;
172
173	vclock = info_to_vclock(info);
174	dev_info(dev->parent, "delete virtual clock ptp%d\n",
175		 vclock->clock->index);
176
177	ptp_vclock_unregister(vclock);
178	(*num)--;
179
180	/* For break. Not error. */
181	if (*num == 0)
182		return -EINVAL;
183
184	return 0;
185}
186
187static ssize_t n_vclocks_show(struct device *dev,
188			      struct device_attribute *attr, char *page)
189{
190	struct ptp_clock *ptp = dev_get_drvdata(dev);
191	ssize_t size;
192
193	if (mutex_lock_interruptible(&ptp->n_vclocks_mux))
194		return -ERESTARTSYS;
195
196	size = sysfs_emit(page, "%u\n", ptp->n_vclocks);
197
198	mutex_unlock(&ptp->n_vclocks_mux);
199
200	return size;
201}
202
203static ssize_t n_vclocks_store(struct device *dev,
204			       struct device_attribute *attr,
205			       const char *buf, size_t count)
206{
207	struct ptp_clock *ptp = dev_get_drvdata(dev);
208	struct ptp_vclock *vclock;
209	int err = -EINVAL;
210	u32 num, i;
211
212	if (kstrtou32(buf, 0, &num))
213		return err;
214
215	if (mutex_lock_interruptible(&ptp->n_vclocks_mux))
216		return -ERESTARTSYS;
217
218	if (num > ptp->max_vclocks) {
219		dev_err(dev, "max value is %d\n", ptp->max_vclocks);
220		goto out;
221	}
222
223	/* Need to create more vclocks */
224	if (num > ptp->n_vclocks) {
225		for (i = 0; i < num - ptp->n_vclocks; i++) {
226			vclock = ptp_vclock_register(ptp);
227			if (!vclock)
228				goto out;
229
230			*(ptp->vclock_index + ptp->n_vclocks + i) =
231				vclock->clock->index;
232
233			dev_info(dev, "new virtual clock ptp%d\n",
234				 vclock->clock->index);
235		}
236	}
237
238	/* Need to delete vclocks */
239	if (num < ptp->n_vclocks) {
240		i = ptp->n_vclocks - num;
241		device_for_each_child_reverse(dev, &i,
242					      unregister_vclock);
243
244		for (i = 1; i <= ptp->n_vclocks - num; i++)
245			*(ptp->vclock_index + ptp->n_vclocks - i) = -1;
246	}
247
248	/* Need to inform about changed physical clock behavior */
249	if (!ptp->has_cycles) {
250		if (num == 0)
251			dev_info(dev, "only physical clock in use now\n");
252		else
253			dev_info(dev, "guarantee physical clock free running\n");
254	}
255
256	ptp->n_vclocks = num;
257	mutex_unlock(&ptp->n_vclocks_mux);
258
259	return count;
260out:
261	mutex_unlock(&ptp->n_vclocks_mux);
262	return err;
263}
264static DEVICE_ATTR_RW(n_vclocks);
265
266static ssize_t max_vclocks_show(struct device *dev,
267				struct device_attribute *attr, char *page)
268{
269	struct ptp_clock *ptp = dev_get_drvdata(dev);
270	ssize_t size;
271
272	size = sysfs_emit(page, "%u\n", ptp->max_vclocks);
273
274	return size;
275}
276
277static ssize_t max_vclocks_store(struct device *dev,
278				 struct device_attribute *attr,
279				 const char *buf, size_t count)
280{
281	struct ptp_clock *ptp = dev_get_drvdata(dev);
282	unsigned int *vclock_index;
283	int err = -EINVAL;
284	size_t size;
285	u32 max;
286
287	if (kstrtou32(buf, 0, &max) || max == 0)
288		return -EINVAL;
289
290	if (max == ptp->max_vclocks)
291		return count;
292
293	if (mutex_lock_interruptible(&ptp->n_vclocks_mux))
294		return -ERESTARTSYS;
295
296	if (max < ptp->n_vclocks)
297		goto out;
298
299	vclock_index = kcalloc(max, sizeof(int), GFP_KERNEL);
300	if (!vclock_index) {
301		err = -ENOMEM;
302		goto out;
303	}
304
305	size = sizeof(int) * ptp->n_vclocks;
306	memcpy(vclock_index, ptp->vclock_index, size);
307
308	kfree(ptp->vclock_index);
309	ptp->vclock_index = vclock_index;
310	ptp->max_vclocks = max;
311
312	mutex_unlock(&ptp->n_vclocks_mux);
313
314	return count;
315out:
316	mutex_unlock(&ptp->n_vclocks_mux);
317	return err;
318}
319static DEVICE_ATTR_RW(max_vclocks);
320
321static struct attribute *ptp_attrs[] = {
322	&dev_attr_clock_name.attr,
323
324	&dev_attr_max_adjustment.attr,
325	&dev_attr_max_phase_adjustment.attr,
326	&dev_attr_n_alarms.attr,
327	&dev_attr_n_external_timestamps.attr,
328	&dev_attr_n_periodic_outputs.attr,
329	&dev_attr_n_programmable_pins.attr,
330	&dev_attr_pps_available.attr,
331
332	&dev_attr_extts_enable.attr,
333	&dev_attr_fifo.attr,
334	&dev_attr_period.attr,
335	&dev_attr_pps_enable.attr,
336	&dev_attr_n_vclocks.attr,
337	&dev_attr_max_vclocks.attr,
338	NULL
339};
340
341static umode_t ptp_is_attribute_visible(struct kobject *kobj,
342					struct attribute *attr, int n)
343{
344	struct device *dev = kobj_to_dev(kobj);
345	struct ptp_clock *ptp = dev_get_drvdata(dev);
346	struct ptp_clock_info *info = ptp->info;
347	umode_t mode = attr->mode;
348
349	if (attr == &dev_attr_extts_enable.attr ||
350	    attr == &dev_attr_fifo.attr) {
351		if (!info->n_ext_ts)
352			mode = 0;
353	} else if (attr == &dev_attr_period.attr) {
354		if (!info->n_per_out)
355			mode = 0;
356	} else if (attr == &dev_attr_pps_enable.attr) {
357		if (!info->pps)
358			mode = 0;
359	} else if (attr == &dev_attr_n_vclocks.attr ||
360		   attr == &dev_attr_max_vclocks.attr) {
361		if (ptp->is_virtual_clock)
362			mode = 0;
363	} else if (attr == &dev_attr_max_phase_adjustment.attr) {
364		if (!info->adjphase || !info->getmaxphase)
365			mode = 0;
366	}
367
368	return mode;
369}
370
371static const struct attribute_group ptp_group = {
372	.is_visible	= ptp_is_attribute_visible,
373	.attrs		= ptp_attrs,
374};
375
376const struct attribute_group *ptp_groups[] = {
377	&ptp_group,
378	NULL
379};
380
381static int ptp_pin_name2index(struct ptp_clock *ptp, const char *name)
382{
383	int i;
384	for (i = 0; i < ptp->info->n_pins; i++) {
385		if (!strcmp(ptp->info->pin_config[i].name, name))
386			return i;
387	}
388	return -1;
389}
390
391static ssize_t ptp_pin_show(struct device *dev, struct device_attribute *attr,
392			    char *page)
393{
394	struct ptp_clock *ptp = dev_get_drvdata(dev);
395	unsigned int func, chan;
396	int index;
397
398	index = ptp_pin_name2index(ptp, attr->attr.name);
399	if (index < 0)
400		return -EINVAL;
401
402	if (mutex_lock_interruptible(&ptp->pincfg_mux))
403		return -ERESTARTSYS;
404
405	func = ptp->info->pin_config[index].func;
406	chan = ptp->info->pin_config[index].chan;
407
408	mutex_unlock(&ptp->pincfg_mux);
409
410	return sysfs_emit(page, "%u %u\n", func, chan);
411}
412
413static ssize_t ptp_pin_store(struct device *dev, struct device_attribute *attr,
414			     const char *buf, size_t count)
415{
416	struct ptp_clock *ptp = dev_get_drvdata(dev);
417	unsigned int func, chan;
418	int cnt, err, index;
419
420	cnt = sscanf(buf, "%u %u", &func, &chan);
421	if (cnt != 2)
422		return -EINVAL;
423
424	index = ptp_pin_name2index(ptp, attr->attr.name);
425	if (index < 0)
426		return -EINVAL;
427
428	if (mutex_lock_interruptible(&ptp->pincfg_mux))
429		return -ERESTARTSYS;
430	err = ptp_set_pinfunc(ptp, index, func, chan);
431	mutex_unlock(&ptp->pincfg_mux);
432	if (err)
433		return err;
434
435	return count;
436}
437
438int ptp_populate_pin_groups(struct ptp_clock *ptp)
439{
 
440	struct ptp_clock_info *info = ptp->info;
441	int err = -ENOMEM, i, n_pins = info->n_pins;
442
443	if (!n_pins)
444		return 0;
445
446	ptp->pin_dev_attr = kcalloc(n_pins, sizeof(*ptp->pin_dev_attr),
447				    GFP_KERNEL);
448	if (!ptp->pin_dev_attr)
449		goto no_dev_attr;
450
451	ptp->pin_attr = kcalloc(1 + n_pins, sizeof(*ptp->pin_attr), GFP_KERNEL);
452	if (!ptp->pin_attr)
453		goto no_pin_attr;
454
455	for (i = 0; i < n_pins; i++) {
456		struct device_attribute *da = &ptp->pin_dev_attr[i];
457		sysfs_attr_init(&da->attr);
458		da->attr.name = info->pin_config[i].name;
459		da->attr.mode = 0644;
460		da->show = ptp_pin_show;
461		da->store = ptp_pin_store;
462		ptp->pin_attr[i] = &da->attr;
463	}
464
465	ptp->pin_attr_group.name = "pins";
466	ptp->pin_attr_group.attrs = ptp->pin_attr;
467
468	ptp->pin_attr_groups[0] = &ptp->pin_attr_group;
469
470	return 0;
471
472no_pin_attr:
473	kfree(ptp->pin_dev_attr);
474no_dev_attr:
 
 
 
 
 
 
475	return err;
476}
477
478void ptp_cleanup_pin_groups(struct ptp_clock *ptp)
479{
480	kfree(ptp->pin_attr);
481	kfree(ptp->pin_dev_attr);
482}
v3.1
 
  1/*
  2 * PTP 1588 clock support - sysfs interface.
  3 *
  4 * Copyright (C) 2010 OMICRON electronics GmbH
  5 *
  6 *  This program is free software; you can redistribute it and/or modify
  7 *  it under the terms of the GNU General Public License as published by
  8 *  the Free Software Foundation; either version 2 of the License, or
  9 *  (at your option) any later version.
 10 *
 11 *  This program is distributed in the hope that it will be useful,
 12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 *  GNU General Public License for more details.
 15 *
 16 *  You should have received a copy of the GNU General Public License
 17 *  along with this program; if not, write to the Free Software
 18 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 19 */
 20#include <linux/capability.h>
 
 21
 22#include "ptp_private.h"
 23
 24static ssize_t clock_name_show(struct device *dev,
 25			       struct device_attribute *attr, char *page)
 26{
 27	struct ptp_clock *ptp = dev_get_drvdata(dev);
 28	return snprintf(page, PAGE_SIZE-1, "%s\n", ptp->info->name);
 
 
 
 
 
 
 
 
 
 
 29}
 
 30
 31#define PTP_SHOW_INT(name)						\
 32static ssize_t name##_show(struct device *dev,				\
 33			   struct device_attribute *attr, char *page)	\
 34{									\
 35	struct ptp_clock *ptp = dev_get_drvdata(dev);			\
 36	return snprintf(page, PAGE_SIZE-1, "%d\n", ptp->info->name);	\
 37}
 38
 39PTP_SHOW_INT(max_adj);
 40PTP_SHOW_INT(n_alarm);
 41PTP_SHOW_INT(n_ext_ts);
 42PTP_SHOW_INT(n_per_out);
 43PTP_SHOW_INT(pps);
 44
 45#define PTP_RO_ATTR(_var, _name) {				\
 46	.attr	= { .name = __stringify(_name), .mode = 0444 },	\
 47	.show	= _var##_show,					\
 48}
 49
 50struct device_attribute ptp_dev_attrs[] = {
 51	PTP_RO_ATTR(clock_name,	clock_name),
 52	PTP_RO_ATTR(max_adj,	max_adjustment),
 53	PTP_RO_ATTR(n_alarm,	n_alarms),
 54	PTP_RO_ATTR(n_ext_ts,	n_external_timestamps),
 55	PTP_RO_ATTR(n_per_out,	n_periodic_outputs),
 56	PTP_RO_ATTR(pps,	pps_available),
 57	__ATTR_NULL,
 58};
 59
 60static ssize_t extts_enable_store(struct device *dev,
 61				  struct device_attribute *attr,
 62				  const char *buf, size_t count)
 63{
 64	struct ptp_clock *ptp = dev_get_drvdata(dev);
 65	struct ptp_clock_info *ops = ptp->info;
 66	struct ptp_clock_request req = { .type = PTP_CLK_REQ_EXTTS };
 67	int cnt, enable;
 68	int err = -EINVAL;
 69
 70	cnt = sscanf(buf, "%u %d", &req.extts.index, &enable);
 71	if (cnt != 2)
 72		goto out;
 73	if (req.extts.index >= ops->n_ext_ts)
 74		goto out;
 75
 76	err = ops->enable(ops, &req, enable ? 1 : 0);
 77	if (err)
 78		goto out;
 79
 80	return count;
 81out:
 82	return err;
 83}
 
 84
 85static ssize_t extts_fifo_show(struct device *dev,
 86			       struct device_attribute *attr, char *page)
 87{
 88	struct ptp_clock *ptp = dev_get_drvdata(dev);
 89	struct timestamp_event_queue *queue = &ptp->tsevq;
 90	struct ptp_extts_event event;
 91	unsigned long flags;
 92	size_t qcnt;
 93	int cnt = 0;
 94
 95	memset(&event, 0, sizeof(event));
 
 
 96
 97	if (mutex_lock_interruptible(&ptp->tsevq_mux))
 98		return -ERESTARTSYS;
 
 99
 
100	spin_lock_irqsave(&queue->lock, flags);
101	qcnt = queue_cnt(queue);
102	if (qcnt) {
103		event = queue->buf[queue->head];
104		queue->head = (queue->head + 1) % PTP_MAX_TIMESTAMPS;
 
105	}
106	spin_unlock_irqrestore(&queue->lock, flags);
107
108	if (!qcnt)
109		goto out;
110
111	cnt = snprintf(page, PAGE_SIZE, "%u %lld %u\n",
112		       event.index, event.t.sec, event.t.nsec);
113out:
114	mutex_unlock(&ptp->tsevq_mux);
115	return cnt;
116}
 
117
118static ssize_t period_store(struct device *dev,
119			    struct device_attribute *attr,
120			    const char *buf, size_t count)
121{
122	struct ptp_clock *ptp = dev_get_drvdata(dev);
123	struct ptp_clock_info *ops = ptp->info;
124	struct ptp_clock_request req = { .type = PTP_CLK_REQ_PEROUT };
125	int cnt, enable, err = -EINVAL;
126
127	cnt = sscanf(buf, "%u %lld %u %lld %u", &req.perout.index,
128		     &req.perout.start.sec, &req.perout.start.nsec,
129		     &req.perout.period.sec, &req.perout.period.nsec);
130	if (cnt != 5)
131		goto out;
132	if (req.perout.index >= ops->n_per_out)
133		goto out;
134
135	enable = req.perout.period.sec || req.perout.period.nsec;
136	err = ops->enable(ops, &req, enable);
137	if (err)
138		goto out;
139
140	return count;
141out:
142	return err;
143}
 
144
145static ssize_t pps_enable_store(struct device *dev,
146				struct device_attribute *attr,
147				const char *buf, size_t count)
148{
149	struct ptp_clock *ptp = dev_get_drvdata(dev);
150	struct ptp_clock_info *ops = ptp->info;
151	struct ptp_clock_request req = { .type = PTP_CLK_REQ_PPS };
152	int cnt, enable;
153	int err = -EINVAL;
154
155	if (!capable(CAP_SYS_TIME))
156		return -EPERM;
157
158	cnt = sscanf(buf, "%d", &enable);
159	if (cnt != 1)
160		goto out;
161
162	err = ops->enable(ops, &req, enable ? 1 : 0);
163	if (err)
164		goto out;
165
166	return count;
167out:
168	return err;
169}
 
170
171static DEVICE_ATTR(extts_enable, 0220, NULL, extts_enable_store);
172static DEVICE_ATTR(fifo,         0444, extts_fifo_show, NULL);
173static DEVICE_ATTR(period,       0220, NULL, period_store);
174static DEVICE_ATTR(pps_enable,   0220, NULL, pps_enable_store);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
176int ptp_cleanup_sysfs(struct ptp_clock *ptp)
 
177{
178	struct device *dev = ptp->dev;
 
179	struct ptp_clock_info *info = ptp->info;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
181	if (info->n_ext_ts) {
182		device_remove_file(dev, &dev_attr_extts_enable);
183		device_remove_file(dev, &dev_attr_fifo);
 
 
 
184	}
185	if (info->n_per_out)
186		device_remove_file(dev, &dev_attr_period);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
188	if (info->pps)
189		device_remove_file(dev, &dev_attr_pps_enable);
 
 
 
 
190
191	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192}
193
194int ptp_populate_sysfs(struct ptp_clock *ptp)
195{
196	struct device *dev = ptp->dev;
197	struct ptp_clock_info *info = ptp->info;
198	int err;
 
 
 
199
200	if (info->n_ext_ts) {
201		err = device_create_file(dev, &dev_attr_extts_enable);
202		if (err)
203			goto out1;
204		err = device_create_file(dev, &dev_attr_fifo);
205		if (err)
206			goto out2;
207	}
208	if (info->n_per_out) {
209		err = device_create_file(dev, &dev_attr_period);
210		if (err)
211			goto out3;
212	}
213	if (info->pps) {
214		err = device_create_file(dev, &dev_attr_pps_enable);
215		if (err)
216			goto out4;
217	}
 
 
 
 
 
 
218	return 0;
219out4:
220	if (info->n_per_out)
221		device_remove_file(dev, &dev_attr_period);
222out3:
223	if (info->n_ext_ts)
224		device_remove_file(dev, &dev_attr_fifo);
225out2:
226	if (info->n_ext_ts)
227		device_remove_file(dev, &dev_attr_extts_enable);
228out1:
229	return err;
 
 
 
 
 
 
230}