Commit | Line | Data |
---|---|---|
eb50fd3a | 1 | // SPDX-License-Identifier: GPL-2.0 |
8db00736 SA |
2 | /* |
3 | * Greybus operations | |
4 | * | |
5 | * Copyright 2015-2016 Google Inc. | |
8db00736 SA |
6 | */ |
7 | ||
8 | #include <linux/string.h> | |
9 | #include <linux/sysfs.h> | |
10 | ||
11 | #include "audio_manager.h" | |
12 | #include "audio_manager_private.h" | |
13 | ||
8478c35a CS |
14 | static ssize_t manager_sysfs_add_store(struct kobject *kobj, |
15 | struct kobj_attribute *attr, | |
16 | const char *buf, size_t count) | |
8db00736 SA |
17 | { |
18 | struct gb_audio_manager_module_descriptor desc = { {0} }; | |
19 | ||
20 | int num = sscanf(buf, | |
21 | "name=%" GB_AUDIO_MANAGER_MODULE_NAME_LEN_SSCANF "s " | |
49b9137a PB |
22 | "vid=%d pid=%d intf_id=%d i/p devices=0x%X o/p devices=0x%X", |
23 | desc.name, &desc.vid, &desc.pid, &desc.intf_id, | |
24 | &desc.ip_devices, &desc.op_devices); | |
8db00736 | 25 | |
a9234bfd | 26 | if (num != 7) |
8db00736 SA |
27 | return -EINVAL; |
28 | ||
29 | num = gb_audio_manager_add(&desc); | |
30 | if (num < 0) | |
31 | return -EINVAL; | |
32 | ||
33 | return count; | |
34 | } | |
35 | ||
36 | static struct kobj_attribute manager_add_attribute = | |
37 | __ATTR(add, 0664, NULL, manager_sysfs_add_store); | |
38 | ||
8478c35a CS |
39 | static ssize_t manager_sysfs_remove_store(struct kobject *kobj, |
40 | struct kobj_attribute *attr, | |
41 | const char *buf, size_t count) | |
8db00736 SA |
42 | { |
43 | int id; | |
44 | ||
f9a21a3f | 45 | int num = kstrtoint(buf, 10, &id); |
8db00736 SA |
46 | |
47 | if (num != 1) | |
48 | return -EINVAL; | |
49 | ||
50 | num = gb_audio_manager_remove(id); | |
51 | if (num) | |
52 | return num; | |
53 | ||
54 | return count; | |
55 | } | |
56 | ||
57 | static struct kobj_attribute manager_remove_attribute = | |
58 | __ATTR(remove, 0664, NULL, manager_sysfs_remove_store); | |
59 | ||
8478c35a CS |
60 | static ssize_t manager_sysfs_dump_store(struct kobject *kobj, |
61 | struct kobj_attribute *attr, | |
62 | const char *buf, size_t count) | |
8db00736 SA |
63 | { |
64 | int id; | |
65 | ||
f9a21a3f | 66 | int num = kstrtoint(buf, 10, &id); |
8db00736 SA |
67 | |
68 | if (num == 1) { | |
69 | num = gb_audio_manager_dump_module(id); | |
70 | if (num) | |
71 | return num; | |
2072763c | 72 | } else if (!strncmp("all", buf, 3)) { |
8db00736 | 73 | gb_audio_manager_dump_all(); |
2072763c | 74 | } else { |
8db00736 | 75 | return -EINVAL; |
2072763c | 76 | } |
8db00736 SA |
77 | |
78 | return count; | |
79 | } | |
80 | ||
81 | static struct kobj_attribute manager_dump_attribute = | |
82 | __ATTR(dump, 0664, NULL, manager_sysfs_dump_store); | |
83 | ||
8478c35a CS |
84 | static void manager_sysfs_init_attribute(struct kobject *kobj, |
85 | struct kobj_attribute *kattr) | |
8db00736 SA |
86 | { |
87 | int err; | |
88 | ||
89 | err = sysfs_create_file(kobj, &kattr->attr); | |
90 | if (err) { | |
91 | pr_warn("creating the sysfs entry for %s failed: %d\n", | |
92 | kattr->attr.name, err); | |
93 | } | |
94 | } | |
95 | ||
96 | void gb_audio_manager_sysfs_init(struct kobject *kobj) | |
97 | { | |
98 | manager_sysfs_init_attribute(kobj, &manager_add_attribute); | |
99 | manager_sysfs_init_attribute(kobj, &manager_remove_attribute); | |
100 | manager_sysfs_init_attribute(kobj, &manager_dump_attribute); | |
101 | } |