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