Skip to content

Commit 2861b2d

Browse files
committed
Add lazy loading symbols in miyoo_kbd
1 parent db0fe2e commit 2861b2d

1 file changed

Lines changed: 33 additions & 19 deletions

File tree

drivers/input/keyboard/miyoo_kbd.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@
1414
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1515
*/
1616
#include <linux/fs.h>
17-
#include <linux/kobject.h>
1817
#include <linux/cdev.h>
1918
#include <linux/init.h>
2019
#include <linux/device.h>
2120
#include <linux/module.h>
22-
#include <linux/delay.h>
2321
#include <linux/timer.h>
2422
#include <linux/gpio.h>
2523
#include <linux/input.h>
2624
#include <linux/kernel.h>
27-
#include <linux/slab.h>
2825
#include <linux/backlight.h>
29-
#include <asm/irq.h>
3026
#include <asm/io.h>
31-
#include <asm/io.h>
32-
#include <asm/arch-suniv/cpu.h>
33-
#include <asm/arch-suniv/gpio.h>
3427
#include <linux/uaccess.h>
35-
#include <linux/unistd.h>
28+
#include <linux/kallsyms.h>
29+
#include <linux/module.h>
30+
31+
static void (*miyoo_increase_volume)(void) = NULL;
32+
static void (*miyoo_decrease_volume)(void) = NULL;
33+
extern void MIYOO_INCREASE_VOLUME(void);
34+
extern void MIYOO_DECREASE_VOLUME(void);
3635

3736
//Hotkeys
3837
#define KILL_HK "/bin/sh", "-c", "/bin/kill -9 $(/bin/ps -al | /bin/grep \"/mnt/\")"
@@ -165,6 +164,12 @@ bool non_hotkey_menu=false;
165164
module_param(miyoo_ver,uint,0660);
166165
module_param(miyoo_layout,uint,0660);
167166

167+
bool is_module_loaded(const char *mod_name)
168+
{
169+
struct module *mod = find_module(mod_name);
170+
return mod != NULL;
171+
}
172+
168173
static int do_input_request(uint32_t pin, const char*name)
169174
{
170175
if(gpio_request(pin, name) < 0){
@@ -235,8 +240,6 @@ static void scan_handler(struct timer_list *timer)
235240
static uint32_t pre=0;
236241
uint32_t scan=0, val=0, debounce=0;
237242
static uint32_t touchRead=0, touchReadPrev=0;
238-
extern void MIYOO_INCREASE_VOLUME(void);
239-
extern void MIYOO_DECREASE_VOLUME(void);
240243
static char * kill_argv[] = {KILL_HK, NULL};
241244
static char * kill_soft_argv[] = {KILL_SOFT_HK, NULL};
242245
static char * shutdown_argv[] = {SHUTDOWN_HK, NULL};
@@ -785,19 +788,27 @@ static void scan_handler(struct timer_list *timer)
785788
}
786789
}
787790
else if((val & MY_R) && (val & MY_UP)){
788-
if(!hotkey_down && !hotkey_custom) {
789-
MIYOO_INCREASE_VOLUME();
790-
hotkey_down = true;
791-
}
791+
if (!hotkey_down && !hotkey_custom) {
792+
if (!miyoo_increase_volume && is_module_loaded("miyoo") ) {
793+
miyoo_increase_volume = symbol_get(MIYOO_INCREASE_VOLUME);
794+
}
795+
if (miyoo_increase_volume)
796+
miyoo_increase_volume();
797+
hotkey_down = true;
798+
}
792799
hotkey_actioned = true;
793800
if (hotkey_custom)
794801
hotkey = hotkey == 0 ? 5 : hotkey;
795802
}
796803
else if((val & MY_R) && (val & MY_DOWN)){
797-
if(!hotkey_down && !hotkey_custom) {
798-
MIYOO_DECREASE_VOLUME();
799-
hotkey_down = true;
800-
}
804+
if (!hotkey_down && !hotkey_custom) {
805+
if (!miyoo_decrease_volume && is_module_loaded("miyoo") ) {
806+
miyoo_decrease_volume = symbol_get(MIYOO_DECREASE_VOLUME);
807+
}
808+
if (miyoo_decrease_volume)
809+
miyoo_decrease_volume();
810+
hotkey_down = true;
811+
}
801812
hotkey_actioned = true;
802813
if (hotkey_custom)
803814
hotkey = hotkey == 0 ? 6 : hotkey;
@@ -1113,7 +1124,10 @@ static void __exit kbd_exit(void)
11131124
{
11141125
input_unregister_device(mydev);
11151126
del_timer(&mytimer);
1116-
1127+
if (miyoo_increase_volume)
1128+
symbol_put(MIYOO_INCREASE_VOLUME);
1129+
if (miyoo_decrease_volume)
1130+
symbol_put(MIYOO_DECREASE_VOLUME);
11171131
device_destroy(myclass, major);
11181132
cdev_del(&mycdev);
11191133
class_destroy(myclass);

0 commit comments

Comments
 (0)