rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2019 MediaTek Inc. |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/string.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/string.h> |
| 17 | |
| 18 | #include "interface.h" |
| 19 | #include "met_drv.h" |
| 20 | |
| 21 | static struct kobject *kobj_met_dummy; |
| 22 | static char header_str[PAGE_SIZE]; |
| 23 | static int header_str_len; |
| 24 | struct metdevice met_dummy_header; |
| 25 | |
| 26 | static ssize_t dummy_str_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); |
| 27 | static ssize_t dummy_str_store(struct kobject *kobj, |
| 28 | struct kobj_attribute *attr, const char *buf, size_t n); |
| 29 | static struct kobj_attribute dummy_attr = __ATTR(dummy_str, 0664, dummy_str_show, dummy_str_store); |
| 30 | |
| 31 | |
| 32 | static ssize_t dummy_str_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
| 33 | { |
| 34 | int ret; |
| 35 | |
| 36 | ret = snprintf(buf, PAGE_SIZE, "%s", header_str); |
| 37 | |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | static ssize_t dummy_str_store(struct kobject *kobj, |
| 42 | struct kobj_attribute *attr, const char *buf, size_t n) |
| 43 | { |
| 44 | int ret = 0; |
| 45 | char *ptr = header_str; |
| 46 | |
| 47 | if ((header_str_len + strlen(buf)) < PAGE_SIZE) { |
| 48 | ret = snprintf(ptr + header_str_len, PAGE_SIZE - header_str_len, "%s\n", buf); |
| 49 | header_str_len += ret; |
| 50 | } |
| 51 | met_dummy_header.mode = 1; |
| 52 | |
| 53 | return n; |
| 54 | } |
| 55 | |
| 56 | static int dummy_reset(void) |
| 57 | { |
| 58 | met_dummy_header.mode = 0; |
| 59 | memset(header_str, 0x00, PAGE_SIZE); |
| 60 | header_str_len = 0; |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int dummy_print_header(char *buf, int len) |
| 66 | { |
| 67 | if (header_str_len > 0) |
| 68 | len = snprintf(buf, PAGE_SIZE, "%s", header_str); |
| 69 | else |
| 70 | len = snprintf(buf, PAGE_SIZE, "# dummy header is empty\n"); |
| 71 | |
| 72 | return len; |
| 73 | } |
| 74 | |
| 75 | static int dummy_create(struct kobject *parent) |
| 76 | { |
| 77 | int ret = 0; |
| 78 | |
| 79 | kobj_met_dummy = parent; |
| 80 | ret = sysfs_create_file(kobj_met_dummy, &dummy_attr.attr); |
| 81 | if (ret != 0) { |
| 82 | pr_debug("Failed to create montype0 in sysfs\n"); |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | static void dummy_delete(void) |
| 90 | { |
| 91 | sysfs_remove_file(kobj_met_dummy, &dummy_attr.attr); |
| 92 | kobj_met_dummy = NULL; |
| 93 | } |
| 94 | |
| 95 | struct metdevice met_dummy_header = { |
| 96 | .name = "dummy_header", |
| 97 | .type = MET_TYPE_MISC, |
| 98 | .cpu_related = 0, |
| 99 | .start = NULL, |
| 100 | .stop = NULL, |
| 101 | .reset = dummy_reset, |
| 102 | .polling_interval = 0, |
| 103 | .timed_polling = NULL, |
| 104 | .print_help = NULL, |
| 105 | .print_header = dummy_print_header, |
| 106 | .create_subfs = dummy_create, |
| 107 | .delete_subfs = dummy_delete, |
| 108 | }; |