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
78 struct timestamp_event_queue *queue = &ptp->tsevq; in extts_fifo_show()
86 if (mutex_lock_interruptible(&ptp->tsevq_mux)) in extts_fifo_show()
87 return -ERESTARTSYS; in extts_fifo_show()
89 spin_lock_irqsave(&queue->lock, flags); in extts_fifo_show()
92 event = queue->buf[queue->head]; in extts_fifo_show()
94 WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS); in extts_fifo_show()
96 spin_unlock_irqrestore(&queue->lock, flags); in extts_fifo_show()
104 mutex_unlock(&ptp->tsevq_mux); in extts_fifo_show()
110 struct device_attribute *attr, in period_store() argument
114 struct ptp_clock_info *ops = ptp->info; in period_store()
116 int cnt, enable, err = -EINVAL; in period_store()
123 if (req.perout.index >= ops->n_per_out) in period_store()
127 err = ops->enable(ops, &req, enable); in period_store()
138 struct device_attribute *attr, in pps_enable_store() argument
142 struct ptp_clock_info *ops = ptp->info; in pps_enable_store()
145 int err = -EINVAL; in pps_enable_store()
148 return -EPERM; in pps_enable_store()
154 err = ops->enable(ops, &req, enable ? 1 : 0); in pps_enable_store()
167 struct ptp_clock_info *info = ptp->info; in unregister_vclock()
172 dev_info(dev->parent, "delete virtual clock ptp%d\n", in unregister_vclock()
173 vclock->clock->index); in unregister_vclock()
176 (*num)--; in unregister_vclock()
180 return -EINVAL; in unregister_vclock()
186 struct device_attribute *attr, char *page) in n_vclocks_show() argument
191 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in n_vclocks_show()
192 return -ERESTARTSYS; in n_vclocks_show()
194 size = snprintf(page, PAGE_SIZE - 1, "%u\n", ptp->n_vclocks); in n_vclocks_show()
196 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_show()
202 struct device_attribute *attr, in n_vclocks_store() argument
207 int err = -EINVAL; in n_vclocks_store()
213 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in n_vclocks_store()
214 return -ERESTARTSYS; in n_vclocks_store()
216 if (num > ptp->max_vclocks) { in n_vclocks_store()
217 dev_err(dev, "max value is %d\n", ptp->max_vclocks); in n_vclocks_store()
222 if (num > ptp->n_vclocks) { in n_vclocks_store()
223 for (i = 0; i < num - ptp->n_vclocks; i++) { in n_vclocks_store()
228 *(ptp->vclock_index + ptp->n_vclocks + i) = in n_vclocks_store()
229 vclock->clock->index; in n_vclocks_store()
232 vclock->clock->index); in n_vclocks_store()
237 if (num < ptp->n_vclocks) { in n_vclocks_store()
238 i = ptp->n_vclocks - num; in n_vclocks_store()
242 for (i = 1; i <= ptp->n_vclocks - num; i++) in n_vclocks_store()
243 *(ptp->vclock_index + ptp->n_vclocks - i) = -1; in n_vclocks_store()
247 if (!ptp->has_cycles) { in n_vclocks_store()
254 ptp->n_vclocks = num; in n_vclocks_store()
255 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_store()
259 mutex_unlock(&ptp->n_vclocks_mux); in n_vclocks_store()
265 struct device_attribute *attr, char *page) in max_vclocks_show() argument
270 size = snprintf(page, PAGE_SIZE - 1, "%u\n", ptp->max_vclocks); in max_vclocks_show()
276 struct device_attribute *attr, in max_vclocks_store() argument
281 int err = -EINVAL; in max_vclocks_store()
283 u32 max; in max_vclocks_store() local
285 if (kstrtou32(buf, 0, &max) || max == 0) in max_vclocks_store()
286 return -EINVAL; in max_vclocks_store()
288 if (max == ptp->max_vclocks) in max_vclocks_store()
291 if (mutex_lock_interruptible(&ptp->n_vclocks_mux)) in max_vclocks_store()
292 return -ERESTARTSYS; in max_vclocks_store()
294 if (max < ptp->n_vclocks) in max_vclocks_store()
297 vclock_index = kcalloc(max, sizeof(int), GFP_KERNEL); in max_vclocks_store()
299 err = -ENOMEM; in max_vclocks_store()
303 size = sizeof(int) * ptp->n_vclocks; in max_vclocks_store()
304 memcpy(vclock_index, ptp->vclock_index, size); in max_vclocks_store()
306 kfree(ptp->vclock_index); in max_vclocks_store()
307 ptp->vclock_index = vclock_index; in max_vclocks_store()
308 ptp->max_vclocks = max; in max_vclocks_store()
310 mutex_unlock(&ptp->n_vclocks_mux); in max_vclocks_store()
314 mutex_unlock(&ptp->n_vclocks_mux); in max_vclocks_store()
320 &dev_attr_clock_name.attr,
322 &dev_attr_max_adjustment.attr,
323 &dev_attr_max_phase_adjustment.attr,
324 &dev_attr_n_alarms.attr,
325 &dev_attr_n_external_timestamps.attr,
326 &dev_attr_n_periodic_outputs.attr,
327 &dev_attr_n_programmable_pins.attr,
328 &dev_attr_pps_available.attr,
330 &dev_attr_extts_enable.attr,
331 &dev_attr_fifo.attr,
332 &dev_attr_period.attr,
333 &dev_attr_pps_enable.attr,
334 &dev_attr_n_vclocks.attr,
335 &dev_attr_max_vclocks.attr,
340 struct attribute *attr, int n) in ptp_is_attribute_visible() argument
344 struct ptp_clock_info *info = ptp->info; in ptp_is_attribute_visible()
345 umode_t mode = attr->mode; in ptp_is_attribute_visible()
347 if (attr == &dev_attr_extts_enable.attr || in ptp_is_attribute_visible()
348 attr == &dev_attr_fifo.attr) { in ptp_is_attribute_visible()
349 if (!info->n_ext_ts) in ptp_is_attribute_visible()
351 } else if (attr == &dev_attr_period.attr) { in ptp_is_attribute_visible()
352 if (!info->n_per_out) in ptp_is_attribute_visible()
354 } else if (attr == &dev_attr_pps_enable.attr) { in ptp_is_attribute_visible()
355 if (!info->pps) in ptp_is_attribute_visible()
357 } else if (attr == &dev_attr_n_vclocks.attr || in ptp_is_attribute_visible()
358 attr == &dev_attr_max_vclocks.attr) { in ptp_is_attribute_visible()
359 if (ptp->is_virtual_clock) in ptp_is_attribute_visible()
361 } else if (attr == &dev_attr_max_phase_adjustment.attr) { in ptp_is_attribute_visible()
362 if (!info->adjphase || !info->getmaxphase) in ptp_is_attribute_visible()
379 static int ptp_pin_name2index(struct ptp_clock *ptp, const char *name) in ptp_pin_name2index() argument
382 for (i = 0; i < ptp->info->n_pins; i++) { in ptp_pin_name2index()
383 if (!strcmp(ptp->info->pin_config[i].name, name)) in ptp_pin_name2index()
386 return -1; in ptp_pin_name2index()
389 static ssize_t ptp_pin_show(struct device *dev, struct device_attribute *attr, in ptp_pin_show() argument
396 index = ptp_pin_name2index(ptp, attr->attr.name); in ptp_pin_show()
398 return -EINVAL; in ptp_pin_show()
400 if (mutex_lock_interruptible(&ptp->pincfg_mux)) in ptp_pin_show()
401 return -ERESTARTSYS; in ptp_pin_show()
403 func = ptp->info->pin_config[index].func; in ptp_pin_show()
404 chan = ptp->info->pin_config[index].chan; in ptp_pin_show()
406 mutex_unlock(&ptp->pincfg_mux); in ptp_pin_show()
411 static ssize_t ptp_pin_store(struct device *dev, struct device_attribute *attr, in ptp_pin_store() argument
420 return -EINVAL; in ptp_pin_store()
422 index = ptp_pin_name2index(ptp, attr->attr.name); in ptp_pin_store()
424 return -EINVAL; in ptp_pin_store()
426 if (mutex_lock_interruptible(&ptp->pincfg_mux)) in ptp_pin_store()
427 return -ERESTARTSYS; in ptp_pin_store()
429 mutex_unlock(&ptp->pincfg_mux); in ptp_pin_store()
438 struct ptp_clock_info *info = ptp->info; in ptp_populate_pin_groups()
439 int err = -ENOMEM, i, n_pins = info->n_pins; in ptp_populate_pin_groups()
444 ptp->pin_dev_attr = kcalloc(n_pins, sizeof(*ptp->pin_dev_attr), in ptp_populate_pin_groups()
446 if (!ptp->pin_dev_attr) in ptp_populate_pin_groups()
449 ptp->pin_attr = kcalloc(1 + n_pins, sizeof(*ptp->pin_attr), GFP_KERNEL); in ptp_populate_pin_groups()
450 if (!ptp->pin_attr) in ptp_populate_pin_groups()
454 struct device_attribute *da = &ptp->pin_dev_attr[i]; in ptp_populate_pin_groups()
455 sysfs_attr_init(&da->attr); in ptp_populate_pin_groups()
456 da->attr.name = info->pin_config[i].name; in ptp_populate_pin_groups()
457 da->attr.mode = 0644; in ptp_populate_pin_groups()
458 da->show = ptp_pin_show; in ptp_populate_pin_groups()
459 da->store = ptp_pin_store; in ptp_populate_pin_groups()
460 ptp->pin_attr[i] = &da->attr; in ptp_populate_pin_groups()
463 ptp->pin_attr_group.name = "pins"; in ptp_populate_pin_groups()
464 ptp->pin_attr_group.attrs = ptp->pin_attr; in ptp_populate_pin_groups()
466 ptp->pin_attr_groups[0] = &ptp->pin_attr_group; in ptp_populate_pin_groups()
471 kfree(ptp->pin_dev_attr); in ptp_populate_pin_groups()
478 kfree(ptp->pin_attr); in ptp_cleanup_pin_groups()
479 kfree(ptp->pin_dev_attr); in ptp_cleanup_pin_groups()