summaryrefstree
path: root/kernel/drivers/vision/npu/npu-ver.c
blob: abb5b836bbf9b28ba11bbfb326602fbbbf572a1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * Samsung Exynos SoC series NPU driver
 *
 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
 *              http://www.samsung.com/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <linux/sysfs.h>

#include "npu-device.h"
#include "npu-debug.h"
#include "npu-log.h"
#include "npu-interface.h"
#include "npu-ver-info.h"
#include "npu-ver.h"

#ifdef CONFIG_EXYNOS_NPU_PUBLISH_NPU_BUILD_VER
static ssize_t version_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	/*
	 * sysfs read buffer size is PAGE_SIZE
	 * Ref: http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/mochel.pdf
	 */
	ssize_t remain = PAGE_SIZE - 1;
	ssize_t ret = 0;

	npu_info("start.");

	/* Populate the buffer */
	ret = scnprintf(buf, remain,
		"Build info: %s\n"
		"NCP version: %u\n"
		"Mailbox verison: %d\n"
		"CMD version: %d\n"
		"User API version: %d\n"
		"Signature:\n%s\n",
		npu_build_info,
		NCP_VERSION, MAILBOX_VERSION, COMMAND_VERSION,
		USER_API_VERSION,
		npu_git_hash_str);

	return ret;
}

/*
 * sysfs attribute for version info
 *   name = dev_attr_version,
 *   show = version_show
 */
static DEVICE_ATTR_RO(version);

/* Exported functions */
int npu_ver_probe(struct npu_device *npu_device)
{
	int ret = 0;
	struct device *dev;

	BUG_ON(!npu_device);
	dev = npu_device->dev;
	BUG_ON(!dev);

	ret = sysfs_create_file(&dev->kobj, &dev_attr_version.attr);
	if (ret) {
		npu_err("sysfs_create_file error : ret = %d\n", ret);
		return ret;
	}

	return ret;
}
/* Exported functions */
int npu_ver_release(struct npu_device *npu_device)
{
	struct device *dev;

	BUG_ON(!npu_device);
	dev = npu_device->dev;
	BUG_ON(!dev);

	sysfs_remove_file(&dev->kobj, &dev_attr_version.attr);

	return 0;
}
#else	/* Not CONFIG_EXYNOS_NPU_PUBLISH_NPU_BUILD_VER */

int npu_ver_probe(struct npu_device *npu_device)
{
	/* No OP */
	return 0;
}

int npu_ver_release(struct npu_device *npu_device)
{
	/* No OP */
	return 0;
}
#endif