blob: ffaa08d571293246bacbcb80bb5df783f04ab1a6 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (C) 2018 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/kernel.h>
15#include <linux/module.h>
16
17#define MET_USER_EVENT_SUPPORT
18#include "met_drv.h"
19#include "trace.h"
20
21static int met_backlight_enable;
22static DEFINE_SPINLOCK(met_backlight_lock);
23static struct kobject *kobj_met_backlight;
24
25static ssize_t bl_tag_enable_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf);
26static ssize_t bl_tag_enable_store(struct kobject *kobj,
27 struct kobj_attribute *attr, const char *buf, size_t n);
28static struct kobj_attribute bl_tag_enable_attr =
29__ATTR(backlight_tag_enable, 0664, bl_tag_enable_show, bl_tag_enable_store);
30
31int enable_met_backlight_tag_real(void)
32{
33 return met_backlight_enable;
34}
35
36int output_met_backlight_tag_real(int level)
37{
38 int ret;
39 unsigned long flags;
40
41 spin_lock_irqsave(&met_backlight_lock, flags);
42#ifdef CONFIG_MET_MODULE
43 ret = met_tag_oneshot_real(33880, "_MM_BL_", level);
44#else
45 ret = met_tag_oneshot(33880, "_MM_BL_", level);
46#endif
47 spin_unlock_irqrestore(&met_backlight_lock, flags);
48
49 return ret;
50}
51
52static ssize_t bl_tag_enable_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
53{
54 int ret;
55
56 ret = snprintf(buf, PAGE_SIZE, "%d\n", met_backlight_enable);
57
58 return ret;
59}
60
61static ssize_t bl_tag_enable_store(struct kobject *kobj,
62 struct kobj_attribute *attr, const char *buf, size_t n)
63{
64 int value;
65
66 if ((n == 0) || (buf == NULL))
67 return -EINVAL;
68
69 if (kstrtoint(buf, 0, &value) != 0)
70 return -EINVAL;
71
72 if (value < 0)
73 return -EINVAL;
74
75 met_backlight_enable = value;
76
77 return n;
78}
79
80static int met_backlight_create(struct kobject *parent)
81{
82 int ret = 0;
83
84 kobj_met_backlight = parent;
85
86 ret = sysfs_create_file(kobj_met_backlight, &bl_tag_enable_attr.attr);
87 if (ret != 0) {
88 pr_debug("Failed to create montype0 in sysfs\n");
89 return ret;
90 }
91
92 return ret;
93}
94
95static void met_backlight_delete(void)
96{
97 sysfs_remove_file(kobj_met_backlight, &bl_tag_enable_attr.attr);
98 kobj_met_backlight = NULL;
99}
100
101struct metdevice met_backlight = {
102 .name = "backlight",
103 .owner = THIS_MODULE,
104 .type = MET_TYPE_BUS,
105 .create_subfs = met_backlight_create,
106 .delete_subfs = met_backlight_delete,
107 .cpu_related = 0,
108};
109EXPORT_SYMBOL(met_backlight);