Lines Matching +full:attr +full:- +full:max +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PTP 1588 clock support - sysfs interface.
14 struct device_attribute *attr, char *page) in clock_name_show() argument
17 return sysfs_emit(page, "%s\n", ptp->info->name); in clock_name_show()
22 struct device_attribute *attr, in max_phase_adjustment_show() argument
27 return snprintf(page, PAGE_SIZE - 1, "%d\n", in max_phase_adjustment_show()
28 ptp->info->getmaxphase(ptp->info)); in max_phase_adjustment_show()
32 #define PTP_SHOW_INT(name, var) \ argument
34 struct device_attribute *attr, char *page) \
37 return snprintf(page, PAGE_SIZE-1, "%d\n", ptp->info->var); \
39 static DEVICE_ATTR(name, 0444, var##_show, NULL);
49 struct device_attribute *attr, in extts_enable_store() argument
53 struct ptp_clock_info *ops = ptp->info; in extts_enable_store()
56 int err = -EINVAL; in extts_enable_store()
61 if (req.extts.index >= ops->n_ext_ts) in extts_enable_store()
64 err = ops->enable(ops, &req, enable ? 1 : 0); in extts_enable_store()
75 struct device_attribute *attr, char *page) in extts_fifo_show() argument
84 cnt = list_count_nodes(&ptp->tsevqs); in extts_fifo_show()
89 queue = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue, in extts_fifo_show()
93 spin_lock_irqsave(&queue->lock, flags); in extts_fifo_show()
96 event = queue->buf[queue->head]; in extts_fifo_show()
98 WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS); in extts_fifo_show()
100 spin_unlock_irqrestore(&queue->lock, flags); in extts_fifo_show()
113 struct device_attribute *attr, in period_store() argument
117 struct ptp_clock_info *ops = ptp->info; in period_store()
119 int cnt, enable, err = -EINVAL; in period_store()
126 if (req.perout.index >= ops->n_per_out) in period_store()
130 err = ops->enable(ops, &req, enable); in period_store()
141 struct device_attribute *attr, in pps_enable_store() argument
145 struct ptp_clock_info *ops = ptp->info; in pps_enable_store()
148 int err = -EINVAL; in pps_enable_store()
151 return -EPERM; in pps_enable_store()
157 err = ops->enable(ops, &req, enable ? 1 : 0); in pps_enable_store()
170 struct ptp_clock_info *info = ptp->info; in unregister_vclock()
175 dev_info(dev->parent, "delete virtual clock ptp%d\n", in unregister_vclock()
176 vclock->clock->index); in unregister_vclock()
179 (*num)--; in unregister_vclock()
183 return -EINVAL; in unregister_vclock()
189 struct device_attribute *attr, char *page) in n_vclocks_show() argument
194 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in n_vclocks_show()
195 return -ERESTARTSYS; in n_vclocks_show()
197 size = snprintf(page, PAGE_SIZE - 1, "%u\n", ptp->n_vclocks); in n_vclocks_show()
199 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_show()
205 struct device_attribute *attr, in n_vclocks_store() argument
210 int err = -EINVAL; in n_vclocks_store()
216 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in n_vclocks_store()
217 return -ERESTARTSYS; in n_vclocks_store()
219 if (num > ptp->max_vclocks) { in n_vclocks_store()
220 dev_err(dev, "max value is %d\n", ptp->max_vclocks); in n_vclocks_store()
225 if (num > ptp->n_vclocks) { in n_vclocks_store()
226 for (i = 0; i < num - ptp->n_vclocks; i++) { in n_vclocks_store()
231 *(ptp->vclock_index + ptp->n_vclocks + i) = in n_vclocks_store()
232 vclock->clock->index; in n_vclocks_store()
235 vclock->clock->index); in n_vclocks_store()
240 if (num < ptp->n_vclocks) { in n_vclocks_store()
241 i = ptp->n_vclocks - num; in n_vclocks_store()
245 for (i = 1; i <= ptp->n_vclocks - num; i++) in n_vclocks_store()
246 *(ptp->vclock_index + ptp->n_vclocks - i) = -1; in n_vclocks_store()
250 if (!ptp->has_cycles) { in n_vclocks_store()
257 ptp->n_vclocks = num; in n_vclocks_store()
258 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_store()
262 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_store()
268 struct device_attribute *attr, char *page) in max_vclocks_show() argument
273 size = snprintf(page, PAGE_SIZE - 1, "%u\n", ptp->max_vclocks); in max_vclocks_show()
279 struct device_attribute *attr, in max_vclocks_store() argument
284 int err = -EINVAL; in max_vclocks_store()
286 u32 max; in max_vclocks_store() local
288 if (kstrtou32(buf, 0, &max) || max == 0) in max_vclocks_store()
289 return -EINVAL; in max_vclocks_store()
291 if (max == ptp->max_vclocks) in max_vclocks_store()
294 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in max_vclocks_store()
295 return -ERESTARTSYS; in max_vclocks_store()
297 if (max < ptp->n_vclocks) in max_vclocks_store()
300 size = sizeof(int) * max; in max_vclocks_store()
303 err = -ENOMEM; in max_vclocks_store()
307 size = sizeof(int) * ptp->n_vclocks; in max_vclocks_store()
308 memcpy(vclock_index, ptp->vclock_index, size); in max_vclocks_store()
310 kfree(ptp->vclock_index); in max_vclocks_store()
311 ptp->vclock_index = vclock_index; in max_vclocks_store()
312 ptp->max_vclocks = max; in max_vclocks_store()
314 mutex_unlock(&ptp->n_vclocks_mux); in max_vclocks_store()
318 mutex_unlock(&ptp->n_vclocks_mux); in max_vclocks_store()
324 &dev_attr_clock_name.attr,
326 &dev_attr_max_adjustment.attr,
327 &dev_attr_max_phase_adjustment.attr,
328 &dev_attr_n_alarms.attr,
329 &dev_attr_n_external_timestamps.attr,
330 &dev_attr_n_periodic_outputs.attr,
331 &dev_attr_n_programmable_pins.attr,
332 &dev_attr_pps_available.attr,
334 &dev_attr_extts_enable.attr,
335 &dev_attr_fifo.attr,
336 &dev_attr_period.attr,
337 &dev_attr_pps_enable.attr,
338 &dev_attr_n_vclocks.attr,
339 &dev_attr_max_vclocks.attr,
344 struct attribute *attr, int n) in ptp_is_attribute_visible() argument
348 struct ptp_clock_info *info = ptp->info; in ptp_is_attribute_visible()
349 umode_t mode = attr->mode; in ptp_is_attribute_visible()
351 if (attr == &dev_attr_extts_enable.attr || in ptp_is_attribute_visible()
352 attr == &dev_attr_fifo.attr) { in ptp_is_attribute_visible()
353 if (!info->n_ext_ts) in ptp_is_attribute_visible()
355 } else if (attr == &dev_attr_period.attr) { in ptp_is_attribute_visible()
356 if (!info->n_per_out) in ptp_is_attribute_visible()
358 } else if (attr == &dev_attr_pps_enable.attr) { in ptp_is_attribute_visible()
359 if (!info->pps) in ptp_is_attribute_visible()
361 } else if (attr == &dev_attr_n_vclocks.attr || in ptp_is_attribute_visible()
362 attr == &dev_attr_max_vclocks.attr) { in ptp_is_attribute_visible()
363 if (ptp->is_virtual_clock) in ptp_is_attribute_visible()
365 } else if (attr == &dev_attr_max_phase_adjustment.attr) { in ptp_is_attribute_visible()
366 if (!info->adjphase || !info->getmaxphase) in ptp_is_attribute_visible()
383 static int ptp_pin_name2index(struct ptp_clock *ptp, const char *name) in ptp_pin_name2index() argument
386 for (i = 0; i < ptp->info->n_pins; i++) { in ptp_pin_name2index()
387 if (!strcmp(ptp->info->pin_config[i].name, name)) in ptp_pin_name2index()
390 return -1; in ptp_pin_name2index()
393 static ssize_t ptp_pin_show(struct device *dev, struct device_attribute *attr, in ptp_pin_show() argument
400 index = ptp_pin_name2index(ptp, attr->attr.name); in ptp_pin_show()
402 return -EINVAL; in ptp_pin_show()
404 if (mutex_lock_interruptible(&ptp->pincfg_mux)) in ptp_pin_show()
405 return -ERESTARTSYS; in ptp_pin_show()
407 func = ptp->info->pin_config[index].func; in ptp_pin_show()
408 chan = ptp->info->pin_config[index].chan; in ptp_pin_show()
410 mutex_unlock(&ptp->pincfg_mux); in ptp_pin_show()
415 static ssize_t ptp_pin_store(struct device *dev, struct device_attribute *attr, in ptp_pin_store() argument
424 return -EINVAL; in ptp_pin_store()
426 index = ptp_pin_name2index(ptp, attr->attr.name); in ptp_pin_store()
428 return -EINVAL; in ptp_pin_store()
430 if (mutex_lock_interruptible(&ptp->pincfg_mux)) in ptp_pin_store()
431 return -ERESTARTSYS; in ptp_pin_store()
433 mutex_unlock(&ptp->pincfg_mux); in ptp_pin_store()
442 struct ptp_clock_info *info = ptp->info; in ptp_populate_pin_groups()
443 int err = -ENOMEM, i, n_pins = info->n_pins; in ptp_populate_pin_groups()
448 ptp->pin_dev_attr = kcalloc(n_pins, sizeof(*ptp->pin_dev_attr), in ptp_populate_pin_groups()
450 if (!ptp->pin_dev_attr) in ptp_populate_pin_groups()
453 ptp->pin_attr = kcalloc(1 + n_pins, sizeof(*ptp->pin_attr), GFP_KERNEL); in ptp_populate_pin_groups()
454 if (!ptp->pin_attr) in ptp_populate_pin_groups()
458 struct device_attribute *da = &ptp->pin_dev_attr[i]; in ptp_populate_pin_groups()
459 sysfs_attr_init(&da->attr); in ptp_populate_pin_groups()
460 da->attr.name = info->pin_config[i].name; in ptp_populate_pin_groups()
461 da->attr.mode = 0644; in ptp_populate_pin_groups()
462 da->show = ptp_pin_show; in ptp_populate_pin_groups()
463 da->store = ptp_pin_store; in ptp_populate_pin_groups()
464 ptp->pin_attr[i] = &da->attr; in ptp_populate_pin_groups()
467 ptp->pin_attr_group.name = "pins"; in ptp_populate_pin_groups()
468 ptp->pin_attr_group.attrs = ptp->pin_attr; in ptp_populate_pin_groups()
470 ptp->pin_attr_groups[0] = &ptp->pin_attr_group; in ptp_populate_pin_groups()
475 kfree(ptp->pin_dev_attr); in ptp_populate_pin_groups()
482 kfree(ptp->pin_attr); in ptp_cleanup_pin_groups()
483 kfree(ptp->pin_dev_attr); in ptp_cleanup_pin_groups()