2020-12-09 13:17:20 +01:00
|
|
|
/*!
|
|
|
|
* Copyright (c) 2018-2020 TUXEDO Computers GmbH <tux@tuxedocomputers.com>
|
|
|
|
*
|
|
|
|
* This file is part of tuxedo-keyboard.
|
|
|
|
*
|
|
|
|
* tuxedo-keyboard is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this software. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-05-29 16:20:02 +02:00
|
|
|
#define pr_fmt(fmt) "tuxedo_keyboard" ": " fmt
|
2019-08-04 01:28:08 +02:00
|
|
|
|
2020-05-27 17:08:40 +02:00
|
|
|
#include "tuxedo_keyboard_common.h"
|
|
|
|
#include "clevo_keyboard.h"
|
2020-05-29 16:20:02 +02:00
|
|
|
#include "uniwill_keyboard.h"
|
2021-03-15 11:30:45 +01:00
|
|
|
#include <linux/mutex.h>
|
2020-04-14 12:47:05 +02:00
|
|
|
|
2020-05-19 15:42:50 +02:00
|
|
|
MODULE_AUTHOR("TUXEDO Computers GmbH <tux@tuxedocomputers.com>");
|
2020-05-20 13:15:05 +02:00
|
|
|
MODULE_DESCRIPTION("TUXEDO Computers keyboard & keyboard backlight Driver");
|
2018-06-08 11:56:32 +02:00
|
|
|
MODULE_LICENSE("GPL");
|
2021-07-09 12:54:21 +02:00
|
|
|
MODULE_VERSION("3.0.8");
|
2018-06-08 11:56:32 +02:00
|
|
|
|
2021-03-15 11:30:45 +01:00
|
|
|
static DEFINE_MUTEX(tuxedo_keyboard_init_driver_lock);
|
|
|
|
|
2021-09-15 17:58:06 +02:00
|
|
|
// static struct tuxedo_keyboard_driver *driver_list[] = { };
|
2020-05-29 16:20:02 +02:00
|
|
|
|
2020-05-28 18:35:46 +02:00
|
|
|
static int tuxedo_input_init(const struct key_entry key_map[])
|
2019-05-31 19:39:20 +02:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
tuxedo_input_device = input_allocate_device();
|
|
|
|
if (unlikely(!tuxedo_input_device)) {
|
|
|
|
TUXEDO_ERROR("Error allocating input device\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
tuxedo_input_device->name = "TUXEDO Keyboard";
|
|
|
|
tuxedo_input_device->phys = DRIVER_NAME "/input0";
|
|
|
|
tuxedo_input_device->id.bustype = BUS_HOST;
|
|
|
|
tuxedo_input_device->dev.parent = &tuxedo_platform_device->dev;
|
|
|
|
|
2020-05-27 18:04:08 +02:00
|
|
|
if (key_map != NULL) {
|
|
|
|
err = sparse_keymap_setup(tuxedo_input_device, key_map, NULL);
|
|
|
|
if (err) {
|
|
|
|
TUXEDO_ERROR("Failed to setup sparse keymap\n");
|
|
|
|
goto err_free_input_device;
|
|
|
|
}
|
2019-12-19 10:34:56 +01:00
|
|
|
}
|
2019-05-31 19:39:20 +02:00
|
|
|
|
|
|
|
err = input_register_device(tuxedo_input_device);
|
|
|
|
if (unlikely(err)) {
|
|
|
|
TUXEDO_ERROR("Error registering input device\n");
|
|
|
|
goto err_free_input_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2019-06-04 19:32:30 +02:00
|
|
|
err_free_input_device:
|
2019-05-31 19:39:20 +02:00
|
|
|
input_free_device(tuxedo_input_device);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-12-02 17:25:43 +01:00
|
|
|
struct platform_device *tuxedo_keyboard_init_driver(struct tuxedo_keyboard_driver *tk_driver)
|
|
|
|
{
|
|
|
|
int err;
|
2021-04-19 14:13:48 +02:00
|
|
|
struct platform_device *new_platform_device = NULL;
|
|
|
|
|
2020-12-02 17:25:43 +01:00
|
|
|
TUXEDO_DEBUG("init driver start\n");
|
|
|
|
|
2021-03-15 11:30:45 +01:00
|
|
|
mutex_lock(&tuxedo_keyboard_init_driver_lock);
|
|
|
|
|
2020-12-02 17:25:43 +01:00
|
|
|
if (!IS_ERR_OR_NULL(tuxedo_platform_device)) {
|
2021-03-15 11:30:45 +01:00
|
|
|
// If already initialized, don't proceed
|
|
|
|
TUXEDO_DEBUG("platform device already initialized\n");
|
|
|
|
goto init_driver_exit;
|
|
|
|
} else {
|
|
|
|
// Otherwise, attempt to initialize structures
|
|
|
|
TUXEDO_DEBUG("create platform bundle\n");
|
2021-04-19 14:13:48 +02:00
|
|
|
new_platform_device = platform_create_bundle(
|
2021-03-15 11:30:45 +01:00
|
|
|
tk_driver->platform_driver, tk_driver->probe, NULL, 0, NULL, 0);
|
|
|
|
|
2021-04-19 14:13:48 +02:00
|
|
|
tuxedo_platform_device = new_platform_device;
|
|
|
|
|
2021-03-15 11:30:45 +01:00
|
|
|
if (IS_ERR_OR_NULL(tuxedo_platform_device)) {
|
|
|
|
// Normal case probe failed, no init
|
|
|
|
goto init_driver_exit;
|
|
|
|
}
|
2020-12-02 17:25:43 +01:00
|
|
|
|
2021-03-15 11:30:45 +01:00
|
|
|
TUXEDO_DEBUG("initialize input device\n");
|
|
|
|
if (tk_driver->key_map != NULL) {
|
|
|
|
err = tuxedo_input_init(tk_driver->key_map);
|
|
|
|
if (unlikely(err)) {
|
|
|
|
TUXEDO_ERROR("Could not register input device\n");
|
|
|
|
tk_driver->input_device = NULL;
|
|
|
|
} else {
|
|
|
|
TUXEDO_DEBUG("input device registered\n");
|
|
|
|
tk_driver->input_device = tuxedo_input_device;
|
|
|
|
}
|
2020-12-02 17:25:43 +01:00
|
|
|
}
|
|
|
|
|
2021-03-15 11:30:45 +01:00
|
|
|
current_driver = tk_driver;
|
|
|
|
}
|
2020-12-02 17:25:43 +01:00
|
|
|
|
2021-03-15 11:30:45 +01:00
|
|
|
init_driver_exit:
|
|
|
|
mutex_unlock(&tuxedo_keyboard_init_driver_lock);
|
2021-04-19 14:13:48 +02:00
|
|
|
return new_platform_device;
|
2020-12-02 17:25:43 +01:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tuxedo_keyboard_init_driver);
|
|
|
|
|
2019-06-04 19:32:30 +02:00
|
|
|
static void __exit tuxedo_input_exit(void)
|
2019-05-31 19:39:20 +02:00
|
|
|
{
|
|
|
|
if (unlikely(!tuxedo_input_device)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_unregister_device(tuxedo_input_device);
|
|
|
|
{
|
|
|
|
tuxedo_input_device = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-15 17:58:06 +02:00
|
|
|
void tuxedo_keyboard_remove_driver(struct tuxedo_keyboard_driver *tk_driver)
|
2019-05-31 19:39:20 +02:00
|
|
|
{
|
2021-09-15 17:58:06 +02:00
|
|
|
bool specified_driver_differ_from_used =
|
|
|
|
tk_driver != NULL &&
|
|
|
|
(
|
|
|
|
strcmp(
|
|
|
|
tk_driver->platform_driver->driver.name,
|
|
|
|
current_driver->platform_driver->driver.name
|
|
|
|
) != 0
|
|
|
|
);
|
|
|
|
|
|
|
|
if (specified_driver_differ_from_used)
|
|
|
|
return;
|
2020-05-29 16:20:02 +02:00
|
|
|
|
2021-09-15 17:58:06 +02:00
|
|
|
TUXEDO_DEBUG("tuxedo_input_exit()\n");
|
|
|
|
tuxedo_input_exit();
|
|
|
|
TUXEDO_DEBUG("platform_device_unregister()\n");
|
|
|
|
if (!IS_ERR_OR_NULL(tuxedo_platform_device)) {
|
|
|
|
platform_device_unregister(tuxedo_platform_device);
|
|
|
|
tuxedo_platform_device = NULL;
|
|
|
|
}
|
|
|
|
TUXEDO_DEBUG("platform_driver_unregister()\n");
|
|
|
|
if (!IS_ERR_OR_NULL(current_driver)) {
|
|
|
|
platform_driver_unregister(current_driver->platform_driver);
|
2020-12-02 17:25:43 +01:00
|
|
|
current_driver = NULL;
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
2021-09-15 17:58:06 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(tuxedo_keyboard_remove_driver);
|
|
|
|
|
|
|
|
static int __init tuxedo_keyboard_init(void)
|
|
|
|
{
|
|
|
|
TUXEDO_INFO("module init\n");
|
2019-05-31 19:39:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-15 11:30:45 +01:00
|
|
|
static void __exit tuxedo_keyboard_exit(void)
|
2019-05-31 19:39:20 +02:00
|
|
|
{
|
2021-09-15 17:58:06 +02:00
|
|
|
TUXEDO_INFO("module exit\n");
|
2020-12-02 17:25:43 +01:00
|
|
|
|
2021-09-15 17:58:06 +02:00
|
|
|
if (tuxedo_platform_device != NULL)
|
|
|
|
tuxedo_keyboard_remove_driver(NULL);
|
2019-05-31 19:39:20 +02:00
|
|
|
}
|
|
|
|
|
2021-03-15 11:30:45 +01:00
|
|
|
module_init(tuxedo_keyboard_init);
|
|
|
|
module_exit(tuxedo_keyboard_exit);
|