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 sysfs_emit(page, "%d\n", ptp->info->getmaxphase(ptp->info)); in max_phase_adjustment_show()
31 #define PTP_SHOW_INT(name, var) \ argument
33 struct device_attribute *attr, char *page) \
36 return sysfs_emit(page, "%d\n", ptp->info->var); \
38 static DEVICE_ATTR(name, 0444, var##_show, NULL);
48 struct device_attribute *attr, in extts_enable_store() argument
52 struct ptp_clock_info *ops = ptp->info; in extts_enable_store()
55 int err = -EINVAL; in extts_enable_store()
60 if (req.extts.index >= ops->n_ext_ts) in extts_enable_store()
63 err = ops->enable(ops, &req, enable ? 1 : 0); in extts_enable_store()
74 struct device_attribute *attr, char *page) in extts_fifo_show() argument
83 cnt = list_count_nodes(&ptp->tsevqs); in extts_fifo_show()
88 queue = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue, in extts_fifo_show()
92 spin_lock_irqsave(&queue->lock, flags); in extts_fifo_show()
95 event = queue->buf[queue->head]; in extts_fifo_show()
97 WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS); in extts_fifo_show()
99 spin_unlock_irqrestore(&queue->lock, flags); in extts_fifo_show()
112 struct device_attribute *attr, in period_store() argument
116 struct ptp_clock_info *ops = ptp->info; in period_store()
118 int cnt, enable, err = -EINVAL; in period_store()
125 if (req.perout.index >= ops->n_per_out) in period_store()
129 err = ops->enable(ops, &req, enable); in period_store()
140 struct device_attribute *attr, in pps_enable_store() argument
144 struct ptp_clock_info *ops = ptp->info; in pps_enable_store()
147 int err = -EINVAL; in pps_enable_store()
150 return -EPERM; in pps_enable_store()
156 err = ops->enable(ops, &req, enable ? 1 : 0); in pps_enable_store()
169 struct ptp_clock_info *info = ptp->info; in unregister_vclock()
174 dev_info(dev->parent, "delete virtual clock ptp%d\n", in unregister_vclock()
175 vclock->clock->index); in unregister_vclock()
178 (*num)--; in unregister_vclock()
182 return -EINVAL; in unregister_vclock()
188 struct device_attribute *attr, char *page) in n_vclocks_show() argument
193 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in n_vclocks_show()
194 return -ERESTARTSYS; in n_vclocks_show()
196 size = sysfs_emit(page, "%u\n", ptp->n_vclocks); in n_vclocks_show()
198 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_show()
204 struct device_attribute *attr, in n_vclocks_store() argument
209 int err = -EINVAL; in n_vclocks_store()
215 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in n_vclocks_store()
216 return -ERESTARTSYS; in n_vclocks_store()
218 if (num > ptp->max_vclocks) { in n_vclocks_store()
219 dev_err(dev, "max value is %d\n", ptp->max_vclocks); in n_vclocks_store()
224 if (num > ptp->n_vclocks) { in n_vclocks_store()
225 for (i = 0; i < num - ptp->n_vclocks; i++) { in n_vclocks_store()
230 *(ptp->vclock_index + ptp->n_vclocks + i) = in n_vclocks_store()
231 vclock->clock->index; in n_vclocks_store()
234 vclock->clock->index); in n_vclocks_store()
239 if (num < ptp->n_vclocks) { in n_vclocks_store()
240 i = ptp->n_vclocks - num; in n_vclocks_store()
244 for (i = 1; i <= ptp->n_vclocks - num; i++) in n_vclocks_store()
245 *(ptp->vclock_index + ptp->n_vclocks - i) = -1; in n_vclocks_store()
249 if (!ptp->has_cycles) { in n_vclocks_store()
256 ptp->n_vclocks = num; in n_vclocks_store()
257 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_store()
261 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_store()
267 struct device_attribute *attr, char *page) in max_vclocks_show() argument
272 size = sysfs_emit(page, "%u\n", ptp->max_vclocks); in max_vclocks_show()
278 struct device_attribute *attr, in max_vclocks_store() argument
283 int err = -EINVAL; in max_vclocks_store()
285 u32 max; in max_vclocks_store() local
287 if (kstrtou32(buf, 0, &max) || max == 0) in max_vclocks_store()
288 return -EINVAL; in max_vclocks_store()
290 if (max == ptp->max_vclocks) in max_vclocks_store()
293 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in max_vclocks_store()
294 return -ERESTARTSYS; in max_vclocks_store()
296 if (max < ptp->n_vclocks) in max_vclocks_store()
299 vclock_index = kcalloc(max, sizeof(int), GFP_KERNEL); in max_vclocks_store()
301 err = -ENOMEM; in max_vclocks_store()
305 size = sizeof(int) * ptp->n_vclocks; in max_vclocks_store()
306 memcpy(vclock_index, ptp->vclock_index, size); in max_vclocks_store()
308 kfree(ptp->vclock_index); in max_vclocks_store()
309 ptp->vclock_index = vclock_index; in max_vclocks_store()
310 ptp->max_vclocks = max; in max_vclocks_store()
312 mutex_unlock(&ptp->n_vclocks_mux); in max_vclocks_store()
316 mutex_unlock(&ptp->n_vclocks_mux); in max_vclocks_store()
322 &dev_attr_clock_name.attr,
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,
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,
342 struct attribute *attr, int n) in ptp_is_attribute_visible() argument
346 struct ptp_clock_info *info = ptp->info; in ptp_is_attribute_visible()
347 umode_t mode = attr->mode; in ptp_is_attribute_visible()
349 if (attr == &dev_attr_extts_enable.attr || in ptp_is_attribute_visible()
350 attr == &dev_attr_fifo.attr) { in ptp_is_attribute_visible()
351 if (!info->n_ext_ts) in ptp_is_attribute_visible()
353 } else if (attr == &dev_attr_period.attr) { in ptp_is_attribute_visible()
354 if (!info->n_per_out) in ptp_is_attribute_visible()
356 } else if (attr == &dev_attr_pps_enable.attr) { in ptp_is_attribute_visible()
357 if (!info->pps) in ptp_is_attribute_visible()
359 } else if (attr == &dev_attr_n_vclocks.attr || in ptp_is_attribute_visible()
360 attr == &dev_attr_max_vclocks.attr) { in ptp_is_attribute_visible()
361 if (ptp->is_virtual_clock) in ptp_is_attribute_visible()
363 } else if (attr == &dev_attr_max_phase_adjustment.attr) { in ptp_is_attribute_visible()
364 if (!info->adjphase || !info->getmaxphase) in ptp_is_attribute_visible()
381 static int ptp_pin_name2index(struct ptp_clock *ptp, const char *name) in ptp_pin_name2index() argument
384 for (i = 0; i < ptp->info->n_pins; i++) { in ptp_pin_name2index()
385 if (!strcmp(ptp->info->pin_config[i].name, name)) in ptp_pin_name2index()
388 return -1; in ptp_pin_name2index()
391 static ssize_t ptp_pin_show(struct device *dev, struct device_attribute *attr, in ptp_pin_show() argument
398 index = ptp_pin_name2index(ptp, attr->attr.name); in ptp_pin_show()
400 return -EINVAL; in ptp_pin_show()
402 if (mutex_lock_interruptible(&ptp->pincfg_mux)) in ptp_pin_show()
403 return -ERESTARTSYS; in ptp_pin_show()
405 func = ptp->info->pin_config[index].func; in ptp_pin_show()
406 chan = ptp->info->pin_config[index].chan; in ptp_pin_show()
408 mutex_unlock(&ptp->pincfg_mux); in ptp_pin_show()
413 static ssize_t ptp_pin_store(struct device *dev, struct device_attribute *attr, in ptp_pin_store() argument
422 return -EINVAL; in ptp_pin_store()
424 index = ptp_pin_name2index(ptp, attr->attr.name); in ptp_pin_store()
426 return -EINVAL; in ptp_pin_store()
428 if (mutex_lock_interruptible(&ptp->pincfg_mux)) in ptp_pin_store()
429 return -ERESTARTSYS; in ptp_pin_store()
431 mutex_unlock(&ptp->pincfg_mux); in ptp_pin_store()
440 struct ptp_clock_info *info = ptp->info; in ptp_populate_pin_groups()
441 int err = -ENOMEM, i, n_pins = info->n_pins; in ptp_populate_pin_groups()
446 ptp->pin_dev_attr = kcalloc(n_pins, sizeof(*ptp->pin_dev_attr), in ptp_populate_pin_groups()
448 if (!ptp->pin_dev_attr) in ptp_populate_pin_groups()
451 ptp->pin_attr = kcalloc(1 + n_pins, sizeof(*ptp->pin_attr), GFP_KERNEL); in ptp_populate_pin_groups()
452 if (!ptp->pin_attr) in ptp_populate_pin_groups()
456 struct device_attribute *da = &ptp->pin_dev_attr[i]; in ptp_populate_pin_groups()
457 sysfs_attr_init(&da->attr); in ptp_populate_pin_groups()
458 da->attr.name = info->pin_config[i].name; in ptp_populate_pin_groups()
459 da->attr.mode = 0644; in ptp_populate_pin_groups()
460 da->show = ptp_pin_show; in ptp_populate_pin_groups()
461 da->store = ptp_pin_store; in ptp_populate_pin_groups()
462 ptp->pin_attr[i] = &da->attr; in ptp_populate_pin_groups()
465 ptp->pin_attr_group.name = "pins"; in ptp_populate_pin_groups()
466 ptp->pin_attr_group.attrs = ptp->pin_attr; in ptp_populate_pin_groups()
468 ptp->pin_attr_groups[0] = &ptp->pin_attr_group; in ptp_populate_pin_groups()
473 kfree(ptp->pin_dev_attr); in ptp_populate_pin_groups()
480 kfree(ptp->pin_attr); in ptp_cleanup_pin_groups()
481 kfree(ptp->pin_dev_attr); in ptp_cleanup_pin_groups()