/** * hte_ts_put() - Release and disable timestamp for the given desc. * * @desc: timestamp descriptor. * * Context: debugfs_remove_recursive() function call may use sleeping locks, * not suitable from atomic context. * Returns: 0 on success or a negative error code on failure.
*/ int hte_ts_put(struct hte_ts_desc *desc)
{ int ret = 0; unsignedlong flag; struct hte_device *gdev; struct hte_ts_info *ei;
if (!desc) return -EINVAL;
ei = desc->hte_data;
if (!ei || !ei->gdev) return -EINVAL;
gdev = ei->gdev;
mutex_lock(&ei->req_mlock);
if (unlikely(!test_bit(HTE_TS_REQ, &ei->flags) &&
!test_bit(HTE_TS_REGISTERED, &ei->flags))) {
dev_info(gdev->sdev, "id:%d is not requested\n",
desc->attr.line_id);
ret = -EINVAL; goto unlock;
}
if (unlikely(!test_bit(HTE_TS_REQ, &ei->flags) &&
test_bit(HTE_TS_REGISTERED, &ei->flags))) {
dev_info(gdev->sdev, "id:%d is registered but not requested\n",
desc->attr.line_id);
ret = -EINVAL; goto unlock;
}
if (test_bit(HTE_TS_REQ, &ei->flags) &&
!test_bit(HTE_TS_REGISTERED, &ei->flags)) {
clear_bit(HTE_TS_REQ, &ei->flags);
desc->hte_data = NULL;
ret = 0; goto mod_put;
}
ret = gdev->chip->ops->release(gdev->chip, desc, ei->xlated_id); if (ret) {
dev_err(gdev->sdev, "id: %d free failed\n",
desc->attr.line_id); goto unlock;
}
kfree(ei->line_name); if (ei->free_attr_name)
kfree_const(desc->attr.name);
debugfs_remove_recursive(ei->ts_dbg_root);
spin_lock_irqsave(&ei->slock, flag);
if (test_bit(HTE_TS_QUEUE_WK, &ei->flags)) {
spin_unlock_irqrestore(&ei->slock, flag);
flush_work(&ei->cb_work);
spin_lock_irqsave(&ei->slock, flag);
}
/** * hte_disable_ts() - Disable timestamp on given descriptor. * * The API does not release any resources associated with desc. * * @desc: ts descriptor, this is the same as returned by the request API. * * Context: Holds mutex lock, not suitable from atomic context. * Returns: 0 on success or a negative error code on failure.
*/ int hte_disable_ts(struct hte_ts_desc *desc)
{ return hte_ts_dis_en_common(desc, false);
}
EXPORT_SYMBOL_GPL(hte_disable_ts);
/** * hte_enable_ts() - Enable timestamp on given descriptor. * * @desc: ts descriptor, this is the same as returned by the request API. * * Context: Holds mutex lock, not suitable from atomic context. * Returns: 0 on success or a negative error code on failure.
*/ int hte_enable_ts(struct hte_ts_desc *desc)
{ return hte_ts_dis_en_common(desc, true);
}
EXPORT_SYMBOL_GPL(hte_enable_ts);
list_for_each_entry(gdev, &hte_devices, list) if (gdev->chip && gdev->chip->match_from_linedata) { if (!gdev->chip->match_from_linedata(gdev->chip, desc)) continue;
spin_unlock(&hte_lock); return gdev;
}
spin_unlock(&hte_lock);
return ERR_PTR(-ENODEV);
}
/** * of_hte_req_count - Return the number of entities to timestamp. * * The function returns the total count of the requested entities to timestamp * by parsing device tree. * * @dev: The HTE consumer. * * Returns: Positive number on success, -ENOENT if no entries, * -EINVAL for other errors.
*/ int of_hte_req_count(struct device *dev)
{ int count;
if (!of_property_present(np, "timestamp-names")) { /* Let hte core construct it during request time */
desc->attr.name = NULL;
} else {
ret = of_property_read_string_index(np, "timestamp-names",
index, &desc->attr.name); if (ret) {
pr_err("can't parse \"timestamp-names\" property\n"); return ERR_PTR(ret);
}
*free_name = false; if (desc->attr.name) {
temp = skip_spaces(desc->attr.name); if (!*temp)
desc->attr.name = NULL;
}
}
ret = of_parse_phandle_with_args(np, "timestamps", "#timestamp-cells",
index, args); if (ret) {
pr_err("%s(): can't parse \"timestamps\" property\n",
__func__); return ERR_PTR(ret);
}
of_node_put(args->np);
return of_node_to_htedevice(args->np);
}
/** * hte_ts_get() - The function to initialize and obtain HTE desc. * * The function initializes the consumer provided HTE descriptor. If consumer * has device tree node, index is used to parse the line id and other details. * The function needs to be called before using any request APIs. * * @dev: HTE consumer/client device, used in case of parsing device tree node. * @desc: Pre-allocated timestamp descriptor. * @index: The index will be used as an index to parse line_id from the * device tree node if node is present. * * Context: Holds mutex lock. * Returns: Returns 0 on success or negative error code on failure.
*/ int hte_ts_get(struct device *dev, struct hte_ts_desc *desc, int index)
{ struct hte_device *gdev; struct hte_ts_info *ei; conststruct fwnode_handle *fwnode; struct of_phandle_args args;
u32 xlated_id; int ret; bool free_name = false;
if (IS_ERR(gdev)) {
pr_err("%s() no hte dev found\n", __func__); return PTR_ERR(gdev);
}
if (!try_module_get(gdev->owner)) return -ENODEV;
if (!gdev->chip) {
pr_err("%s(): requested id does not have provider\n",
__func__);
ret = -ENODEV; goto put;
}
if (is_of_node(fwnode)) { if (!gdev->chip->xlate_of)
ret = -EINVAL; else
ret = gdev->chip->xlate_of(gdev->chip, &args,
desc, &xlated_id);
} else { if (!gdev->chip->xlate_plat)
ret = -EINVAL; else
ret = gdev->chip->xlate_plat(gdev->chip, desc,
&xlated_id);
}
if (ret < 0) goto put;
ei = &gdev->ei[xlated_id];
ret = hte_bind_ts_info_locked(ei, desc, xlated_id); if (ret) goto put;
/** * hte_request_ts_ns() - The API to request and enable hardware timestamp in * nanoseconds. * * The entity is provider specific for example, GPIO lines, signals, buses * etc...The API allocates necessary resources and enables the timestamp. * * @desc: Pre-allocated and initialized timestamp descriptor. * @cb: Callback to push the timestamp data to consumer. * @tcb: Optional callback. If its provided, subsystem initializes * workqueue. It is called when cb returns HTE_RUN_SECOND_CB. * @data: Client data, used during cb and tcb callbacks. * * Context: Holds mutex lock. * Returns: Returns 0 on success or negative error code on failure.
*/ int hte_request_ts_ns(struct hte_ts_desc *desc, hte_ts_cb_t cb,
hte_ts_sec_cb_t tcb, void *data)
{ int ret; struct hte_ts_info *ei;
if (!desc || !desc->hte_data || !cb) return -EINVAL;
ei = desc->hte_data; if (!ei || !ei->gdev) return -EINVAL;
ret = __hte_req_ts(desc, cb, tcb, data); if (ret < 0) {
dev_err(ei->gdev->chip->dev, "failed to request id: %d\n", desc->attr.line_id); return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(hte_request_ts_ns);
/** * devm_hte_request_ts_ns() - Resource managed API to request and enable * hardware timestamp in nanoseconds. * * The entity is provider specific for example, GPIO lines, signals, buses * etc...The API allocates necessary resources and enables the timestamp. It * deallocates and disables automatically when the consumer exits. * * @dev: HTE consumer/client device. * @desc: Pre-allocated and initialized timestamp descriptor. * @cb: Callback to push the timestamp data to consumer. * @tcb: Optional callback. If its provided, subsystem initializes * workqueue. It is called when cb returns HTE_RUN_SECOND_CB. * @data: Client data, used during cb and tcb callbacks. * * Context: Holds mutex lock. * Returns: Returns 0 on success or negative error code on failure.
*/ int devm_hte_request_ts_ns(struct device *dev, struct hte_ts_desc *desc,
hte_ts_cb_t cb, hte_ts_sec_cb_t tcb, void *data)
{ int err;
if (!dev) return -EINVAL;
err = hte_request_ts_ns(desc, cb, tcb, data); if (err) return err;
err = devm_add_action_or_reset(dev, __devm_hte_release_ts, desc); if (err) return err;
/** * hte_init_line_attr() - Initialize line attributes. * * Zeroes out line attributes and initializes with provided arguments. * The function needs to be called before calling any consumer facing * functions. * * @desc: Pre-allocated timestamp descriptor. * @line_id: line id. * @edge_flags: edge flags related to line_id. * @name: name of the line. * @data: line data related to line_id. * * Context: Any. * Returns: 0 on success or negative error code for the failure.
*/ int hte_init_line_attr(struct hte_ts_desc *desc, u32 line_id, unsignedlong edge_flags, constchar *name, void *data)
{ if (!desc) return -EINVAL;
memset(&desc->attr, 0, sizeof(desc->attr));
desc->attr.edge_flags = edge_flags;
desc->attr.line_id = line_id;
desc->attr.line_data = data; if (name) {
name = kstrdup_const(name, GFP_KERNEL); if (!name) return -ENOMEM;
}
/** * hte_get_clk_src_info() - Get the clock source information for a ts * descriptor. * * @desc: ts descriptor, same as returned from request API. * @ci: The API fills this structure with the clock information data. * * Context: Any context. * Returns: 0 on success else negative error code on failure.
*/ int hte_get_clk_src_info(conststruct hte_ts_desc *desc, struct hte_clk_info *ci)
{ struct hte_chip *chip; struct hte_ts_info *ei;
/** * hte_push_ts_ns() - Push timestamp data in nanoseconds. * * It is used by the provider to push timestamp data. * * @chip: The HTE chip, used during the registration. * @xlated_id: entity id understood by both subsystem and provider, this is * obtained from xlate callback during request API. * @data: timestamp data. * * Returns: 0 on success or a negative error code on failure.
*/ int hte_push_ts_ns(conststruct hte_chip *chip, u32 xlated_id, struct hte_ts_data *data)
{ enum hte_return ret; int st = 0; struct hte_ts_info *ei; unsignedlong flag;
if (!chip || !data || !chip->gdev) return -EINVAL;
/** * devm_hte_register_chip() - Resource managed API to register HTE chip. * * It is used by the provider to register itself with the HTE subsystem. * The unregistration is done automatically when the provider exits. * * @chip: the HTE chip to add to subsystem. * * Returns: 0 on success or a negative error code on failure.
*/ int devm_hte_register_chip(struct hte_chip *chip)
{ int err;
err = hte_register_chip(chip); if (err) return err;
err = devm_add_action_or_reset(chip->dev, _hte_devm_unregister_chip,
chip); if (err) return err;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.