Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | #ifdef pr_fmt |
2 | #undef pr_fmt | |
3 | #endif | |
4 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
5 | ||
6 | ||
7 | ||
8 | #include <linux/version.h> | |
9 | #include <linux/kernel.h> | |
10 | #include <linux/module.h> | |
11 | #include <linux/printk.h> | |
12 | #include <linux/types.h> | |
13 | #include <linux/kobject.h> | |
14 | #include <linux/proc_fs.h> | |
15 | #include <linux/seq_file.h> | |
16 | #include <asm/uaccess.h> | |
17 | #include "mach/mtk_thermal_monitor.h" | |
18 | ||
19 | ||
20 | #define MAX_NUM_INSTANCE_MTK_COOLER_CAM 1 | |
21 | ||
22 | #if 1 | |
23 | #define mtk_cooler_cam_dprintk(fmt, args...) \ | |
24 | do { pr_debug("thermal/cooler/cam " fmt, ##args); } while (0) | |
25 | #else | |
26 | #define mtk_cooler_cam_dprintk(fmt, args...) | |
27 | #endif | |
28 | ||
29 | static struct thermal_cooling_device *cl_cam_dev[MAX_NUM_INSTANCE_MTK_COOLER_CAM] = { 0 }; | |
30 | static unsigned long cl_cam_state[MAX_NUM_INSTANCE_MTK_COOLER_CAM] = { 0 }; | |
31 | ||
32 | static unsigned int _cl_cam; | |
33 | ||
34 | #define MAX_LEN (256) | |
35 | ||
36 | static ssize_t _cl_cam_write(struct file *filp, const char __user *buf, size_t len, loff_t *data) | |
37 | { | |
38 | int ret = 0; | |
39 | char tmp[MAX_LEN] = { 0 }; | |
40 | ||
4b9e9796 | 41 | len = (len < (MAX_LEN-1)) ? len : (MAX_LEN-1); |
6fa3eb70 S |
42 | /* write data to the buffer */ |
43 | if (copy_from_user(tmp, buf, len)) { | |
44 | return -EFAULT; | |
45 | } | |
46 | ||
47 | ret = kstrtouint(tmp, 10, &_cl_cam); | |
48 | if (ret) | |
49 | WARN_ON(1); | |
50 | ||
51 | mtk_cooler_cam_dprintk("%s %s = %d\n", __func__, tmp, _cl_cam); | |
52 | ||
53 | return len; | |
54 | } | |
55 | ||
56 | static int _cl_cam_read(struct seq_file *m, void *v) | |
57 | { | |
58 | seq_printf(m, "%d\n", _cl_cam); | |
59 | mtk_cooler_cam_dprintk("%s %d\n", __func__, _cl_cam); | |
60 | ||
61 | return 0; | |
62 | } | |
63 | ||
64 | static int _cl_cam_open(struct inode *inode, struct file *file) | |
65 | { | |
66 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0) | |
67 | return single_open(file, _cl_cam_read, PDE_DATA(inode)); | |
68 | #else | |
69 | return single_open(file, _cl_cam_read, PDE(inode)->data); | |
70 | #endif | |
71 | } | |
72 | ||
73 | static const struct file_operations _cl_cam_fops = { | |
74 | .owner = THIS_MODULE, | |
75 | .open = _cl_cam_open, | |
76 | .read = seq_read, | |
77 | .llseek = seq_lseek, | |
78 | .write = _cl_cam_write, | |
79 | .release = single_release, | |
80 | }; | |
81 | ||
82 | static int mtk_cl_cam_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state) | |
83 | { | |
84 | *state = 1; | |
85 | /* mtk_cooler_cam_dprintk("mtk_cl_cam_get_max_state() %s %d\n", cdev->type, *state); */ | |
86 | return 0; | |
87 | } | |
88 | ||
89 | static int mtk_cl_cam_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state) | |
90 | { | |
91 | *state = *((unsigned long *)cdev->devdata); | |
92 | /* mtk_cooler_cam_dprintk("mtk_cl_cam_get_cur_state() %s %d\n", cdev->type, *state); */ | |
93 | return 0; | |
94 | } | |
95 | ||
96 | static int mtk_cl_cam_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) | |
97 | { | |
98 | /* mtk_cooler_cam_dprintk("mtk_cl_cam_set_cur_state() %s %d\n", cdev->type, state); */ | |
99 | ||
100 | *((unsigned long *)cdev->devdata) = state; | |
101 | ||
102 | if (1 == state) { | |
103 | _cl_cam = 1; | |
104 | } else { | |
105 | _cl_cam = 0; | |
106 | } | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
111 | /* bind fan callbacks to fan device */ | |
112 | static struct thermal_cooling_device_ops mtk_cl_cam_ops = { | |
113 | .get_max_state = mtk_cl_cam_get_max_state, | |
114 | .get_cur_state = mtk_cl_cam_get_cur_state, | |
115 | .set_cur_state = mtk_cl_cam_set_cur_state, | |
116 | }; | |
117 | ||
118 | static int mtk_cooler_cam_register_ltf(void) | |
119 | { | |
120 | int i; | |
121 | mtk_cooler_cam_dprintk("register ltf\n"); | |
122 | ||
123 | for (i = MAX_NUM_INSTANCE_MTK_COOLER_CAM; i-- > 0;) { | |
124 | char temp[20] = { 0 }; | |
125 | sprintf(temp, "mtk-cl-cam%02d", i); | |
126 | cl_cam_dev[i] = mtk_thermal_cooling_device_register(temp, | |
127 | (void *)&cl_cam_state[i], | |
128 | &mtk_cl_cam_ops); | |
129 | } | |
130 | ||
131 | return 0; | |
132 | } | |
133 | ||
134 | static void mtk_cooler_cam_unregister_ltf(void) | |
135 | { | |
136 | int i; | |
137 | mtk_cooler_cam_dprintk("unregister ltf\n"); | |
138 | ||
139 | for (i = MAX_NUM_INSTANCE_MTK_COOLER_CAM; i-- > 0;) { | |
140 | if (cl_cam_dev[i]) { | |
141 | mtk_thermal_cooling_device_unregister(cl_cam_dev[i]); | |
142 | cl_cam_dev[i] = NULL; | |
143 | cl_cam_state[i] = 0; | |
144 | } | |
145 | } | |
146 | } | |
147 | ||
148 | ||
149 | static int __init mtk_cooler_cam_init(void) | |
150 | { | |
151 | int err = 0; | |
152 | int i; | |
153 | ||
154 | for (i = MAX_NUM_INSTANCE_MTK_COOLER_CAM; i-- > 0;) { | |
155 | cl_cam_dev[i] = NULL; | |
156 | cl_cam_state[i] = 0; | |
157 | } | |
158 | ||
159 | mtk_cooler_cam_dprintk("init\n"); | |
160 | ||
161 | { | |
162 | struct proc_dir_entry *entry; | |
163 | ||
164 | #if 0 | |
165 | entry = create_proc_entry("driver/cl_cam", S_IRUGO | S_IWUSR, NULL); | |
166 | if (NULL != entry) { | |
167 | entry->read_proc = _cl_cam_read; | |
168 | entry->write_proc = _cl_cam_write; | |
169 | } | |
170 | #endif | |
171 | entry = proc_create("driver/cl_cam", S_IRUGO | S_IWUSR, NULL, &_cl_cam_fops); | |
172 | if (!entry) { | |
173 | mtk_cooler_cam_dprintk("%s driver/cl_cam creation failed\n", __func__); | |
174 | } | |
175 | } | |
176 | ||
177 | err = mtk_cooler_cam_register_ltf(); | |
178 | if (err) | |
179 | goto err_unreg; | |
180 | ||
181 | return 0; | |
182 | ||
183 | err_unreg: | |
184 | mtk_cooler_cam_unregister_ltf(); | |
185 | return err; | |
186 | } | |
187 | ||
188 | static void __exit mtk_cooler_cam_exit(void) | |
189 | { | |
190 | mtk_cooler_cam_dprintk("exit\n"); | |
191 | ||
192 | mtk_cooler_cam_unregister_ltf(); | |
193 | } | |
194 | module_init(mtk_cooler_cam_init); | |
195 | module_exit(mtk_cooler_cam_exit); |