18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci//
38c2ecf20Sopenharmony_ci// Copyright(c) 2020 Intel Corporation. All rights reserved.
48c2ecf20Sopenharmony_ci//
58c2ecf20Sopenharmony_ci// Author: Cezary Rojewski <cezary.rojewski@intel.com>
68c2ecf20Sopenharmony_ci//
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h>
98c2ecf20Sopenharmony_ci#include "core.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistatic ssize_t fw_version_show(struct device *dev,
128c2ecf20Sopenharmony_ci			       struct device_attribute *attr, char *buf)
138c2ecf20Sopenharmony_ci{
148c2ecf20Sopenharmony_ci	struct catpt_dev *cdev = dev_get_drvdata(dev);
158c2ecf20Sopenharmony_ci	struct catpt_fw_version version;
168c2ecf20Sopenharmony_ci	int ret;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	pm_runtime_get_sync(cdev->dev);
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	ret = catpt_ipc_get_fw_version(cdev, &version);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci	pm_runtime_mark_last_busy(cdev->dev);
238c2ecf20Sopenharmony_ci	pm_runtime_put_autosuspend(cdev->dev);
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	if (ret)
268c2ecf20Sopenharmony_ci		return CATPT_IPC_ERROR(ret);
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	return sprintf(buf, "%d.%d.%d.%d\n", version.type, version.major,
298c2ecf20Sopenharmony_ci		       version.minor, version.build);
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_cistatic DEVICE_ATTR_RO(fw_version);
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cistatic ssize_t fw_info_show(struct device *dev,
348c2ecf20Sopenharmony_ci			    struct device_attribute *attr, char *buf)
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	struct catpt_dev *cdev = dev_get_drvdata(dev);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	return sprintf(buf, "%s\n", cdev->ipc.config.fw_info);
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_cistatic DEVICE_ATTR_RO(fw_info);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic struct attribute *catpt_attrs[] = {
438c2ecf20Sopenharmony_ci	&dev_attr_fw_version.attr,
448c2ecf20Sopenharmony_ci	&dev_attr_fw_info.attr,
458c2ecf20Sopenharmony_ci	NULL
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic const struct attribute_group catpt_attr_group = {
498c2ecf20Sopenharmony_ci	.attrs = catpt_attrs,
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciconst struct attribute_group *catpt_attr_groups[] = {
538c2ecf20Sopenharmony_ci	&catpt_attr_group,
548c2ecf20Sopenharmony_ci	NULL
558c2ecf20Sopenharmony_ci};
56