1 // SPDX-License-Identifier: GPL-2.0-only
3 * Input Power Event -> APM Bridge
5 * Copyright (c) 2007 Richard Purdie
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/module.h>
11 #include <linux/input.h>
12 #include <linux/slab.h>
13 #include <linux/init.h>
14 #include <linux/tty.h>
15 #include <linux/delay.h>
17 #include <linux/apm-emulation.h>
19 static void system_power_event(unsigned int keycode
)
23 apm_queue_event(APM_USER_SUSPEND
);
24 pr_info("Requesting system suspend...\n");
31 static void apmpower_event(struct input_handle
*handle
, unsigned int type
,
32 unsigned int code
, int value
)
34 /* only react on key down events */
40 system_power_event(code
);
48 static int apmpower_connect(struct input_handler
*handler
,
49 struct input_dev
*dev
,
50 const struct input_device_id
*id
)
52 struct input_handle
*handle
;
55 handle
= kzalloc(sizeof(struct input_handle
), GFP_KERNEL
);
60 handle
->handler
= handler
;
61 handle
->name
= "apm-power";
63 error
= input_register_handle(handle
);
65 pr_err("Failed to register input power handler, error %d\n",
71 error
= input_open_device(handle
);
73 pr_err("Failed to open input power device, error %d\n", error
);
74 input_unregister_handle(handle
);
82 static void apmpower_disconnect(struct input_handle
*handle
)
84 input_close_device(handle
);
85 input_unregister_handle(handle
);
89 static const struct input_device_id apmpower_ids
[] = {
91 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
,
92 .evbit
= { BIT_MASK(EV_PWR
) },
97 MODULE_DEVICE_TABLE(input
, apmpower_ids
);
99 static struct input_handler apmpower_handler
= {
100 .event
= apmpower_event
,
101 .connect
= apmpower_connect
,
102 .disconnect
= apmpower_disconnect
,
104 .id_table
= apmpower_ids
,
107 static int __init
apmpower_init(void)
109 return input_register_handler(&apmpower_handler
);
112 static void __exit
apmpower_exit(void)
114 input_unregister_handler(&apmpower_handler
);
117 module_init(apmpower_init
);
118 module_exit(apmpower_exit
);
120 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
121 MODULE_DESCRIPTION("Input Power Event -> APM Bridge");
122 MODULE_LICENSE("GPL");