4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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"
20 #define MAX_NUM_INSTANCE_MTK_COOLER_CAM 1
23 #define mtk_cooler_cam_dprintk(fmt, args...) \
24 do { pr_debug("thermal/cooler/cam " fmt, ##args); } while (0)
26 #define mtk_cooler_cam_dprintk(fmt, args...)
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 };
32 static unsigned int _cl_cam
;
36 static ssize_t
_cl_cam_write(struct file
*filp
, const char __user
*buf
, size_t len
, loff_t
*data
)
39 char tmp
[MAX_LEN
] = { 0 };
41 len
= (len
< (MAX_LEN
-1)) ? len
: (MAX_LEN
-1);
42 /* write data to the buffer */
43 if (copy_from_user(tmp
, buf
, len
)) {
47 ret
= kstrtouint(tmp
, 10, &_cl_cam
);
51 mtk_cooler_cam_dprintk("%s %s = %d\n", __func__
, tmp
, _cl_cam
);
56 static int _cl_cam_read(struct seq_file
*m
, void *v
)
58 seq_printf(m
, "%d\n", _cl_cam
);
59 mtk_cooler_cam_dprintk("%s %d\n", __func__
, _cl_cam
);
64 static int _cl_cam_open(struct inode
*inode
, struct file
*file
)
66 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
67 return single_open(file
, _cl_cam_read
, PDE_DATA(inode
));
69 return single_open(file
, _cl_cam_read
, PDE(inode
)->data
);
73 static const struct file_operations _cl_cam_fops
= {
78 .write
= _cl_cam_write
,
79 .release
= single_release
,
82 static int mtk_cl_cam_get_max_state(struct thermal_cooling_device
*cdev
, unsigned long *state
)
85 /* mtk_cooler_cam_dprintk("mtk_cl_cam_get_max_state() %s %d\n", cdev->type, *state); */
89 static int mtk_cl_cam_get_cur_state(struct thermal_cooling_device
*cdev
, unsigned long *state
)
91 *state
= *((unsigned long *)cdev
->devdata
);
92 /* mtk_cooler_cam_dprintk("mtk_cl_cam_get_cur_state() %s %d\n", cdev->type, *state); */
96 static int mtk_cl_cam_set_cur_state(struct thermal_cooling_device
*cdev
, unsigned long state
)
98 /* mtk_cooler_cam_dprintk("mtk_cl_cam_set_cur_state() %s %d\n", cdev->type, state); */
100 *((unsigned long *)cdev
->devdata
) = state
;
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
,
118 static int mtk_cooler_cam_register_ltf(void)
121 mtk_cooler_cam_dprintk("register ltf\n");
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
],
134 static void mtk_cooler_cam_unregister_ltf(void)
137 mtk_cooler_cam_dprintk("unregister ltf\n");
139 for (i
= MAX_NUM_INSTANCE_MTK_COOLER_CAM
; i
-- > 0;) {
141 mtk_thermal_cooling_device_unregister(cl_cam_dev
[i
]);
142 cl_cam_dev
[i
] = NULL
;
149 static int __init
mtk_cooler_cam_init(void)
154 for (i
= MAX_NUM_INSTANCE_MTK_COOLER_CAM
; i
-- > 0;) {
155 cl_cam_dev
[i
] = NULL
;
159 mtk_cooler_cam_dprintk("init\n");
162 struct proc_dir_entry
*entry
;
165 entry
= create_proc_entry("driver/cl_cam", S_IRUGO
| S_IWUSR
, NULL
);
167 entry
->read_proc
= _cl_cam_read
;
168 entry
->write_proc
= _cl_cam_write
;
171 entry
= proc_create("driver/cl_cam", S_IRUGO
| S_IWUSR
, NULL
, &_cl_cam_fops
);
173 mtk_cooler_cam_dprintk("%s driver/cl_cam creation failed\n", __func__
);
177 err
= mtk_cooler_cam_register_ltf();
184 mtk_cooler_cam_unregister_ltf();
188 static void __exit
mtk_cooler_cam_exit(void)
190 mtk_cooler_cam_dprintk("exit\n");
192 mtk_cooler_cam_unregister_ltf();
194 module_init(mtk_cooler_cam_init
);
195 module_exit(mtk_cooler_cam_exit
);