| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (c) 2019 MediaTek Inc. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/string.h> |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/string.h> |
| 9 | |
| 10 | #include "interface.h" |
| 11 | #include "met_drv.h" |
| 12 | |
| 13 | static struct kobject *kobj_met_dummy; |
| 14 | static char header_str[PAGE_SIZE]; |
| 15 | static int header_str_len; |
| 16 | struct metdevice met_dummy_header; |
| 17 | |
| 18 | static ssize_t dummy_str_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); |
| 19 | static ssize_t dummy_str_store(struct kobject *kobj, |
| 20 | struct kobj_attribute *attr, const char *buf, size_t n); |
| 21 | static struct kobj_attribute dummy_attr = __ATTR(dummy_str, 0664, dummy_str_show, dummy_str_store); |
| 22 | |
| 23 | |
| 24 | static ssize_t dummy_str_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
| 25 | { |
| 26 | int ret; |
| 27 | |
| 28 | ret = snprintf(buf, PAGE_SIZE, "%s", header_str); |
| 29 | |
| 30 | return ret; |
| 31 | } |
| 32 | |
| 33 | static ssize_t dummy_str_store(struct kobject *kobj, |
| 34 | struct kobj_attribute *attr, const char *buf, size_t n) |
| 35 | { |
| 36 | int ret = 0; |
| 37 | char *ptr = header_str; |
| 38 | |
| 39 | if ((header_str_len + strlen(buf)) < PAGE_SIZE) { |
| 40 | ret = snprintf(ptr + header_str_len, PAGE_SIZE - header_str_len, "%s\n", buf); |
| 41 | header_str_len += ret; |
| 42 | } |
| 43 | met_dummy_header.mode = 1; |
| 44 | |
| 45 | return n; |
| 46 | } |
| 47 | |
| 48 | static int dummy_reset(void) |
| 49 | { |
| 50 | met_dummy_header.mode = 0; |
| 51 | memset(header_str, 0x00, PAGE_SIZE); |
| 52 | header_str_len = 0; |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int dummy_print_header(char *buf, int len) |
| 58 | { |
| 59 | if (header_str_len > 0) |
| 60 | len = snprintf(buf, PAGE_SIZE, "%s", header_str); |
| 61 | else |
| 62 | len = snprintf(buf, PAGE_SIZE, "# dummy header is empty\n"); |
| 63 | |
| 64 | return len; |
| 65 | } |
| 66 | |
| 67 | static int dummy_create(struct kobject *parent) |
| 68 | { |
| 69 | int ret = 0; |
| 70 | |
| 71 | kobj_met_dummy = parent; |
| 72 | ret = sysfs_create_file(kobj_met_dummy, &dummy_attr.attr); |
| 73 | if (ret != 0) { |
| 74 | pr_debug("Failed to create montype0 in sysfs\n"); |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | static void dummy_delete(void) |
| 82 | { |
| 83 | sysfs_remove_file(kobj_met_dummy, &dummy_attr.attr); |
| 84 | kobj_met_dummy = NULL; |
| 85 | } |
| 86 | |
| 87 | struct metdevice met_dummy_header = { |
| 88 | .name = "dummy_header", |
| 89 | .type = MET_TYPE_MISC, |
| 90 | .cpu_related = 0, |
| 91 | .start = NULL, |
| 92 | .stop = NULL, |
| 93 | .reset = dummy_reset, |
| 94 | .polling_interval = 0, |
| 95 | .timed_polling = NULL, |
| 96 | .print_help = NULL, |
| 97 | .print_header = dummy_print_header, |
| 98 | .create_subfs = dummy_create, |
| 99 | .delete_subfs = dummy_delete, |
| 100 | }; |