diff --git a/src/tuxedo_keyboard.c b/src/tuxedo_keyboard.c index 4f54c82..4dc6bfc 100644 --- a/src/tuxedo_keyboard.c +++ b/src/tuxedo_keyboard.c @@ -49,7 +49,6 @@ static const struct kernel_param_ops param_ops_brightness_ops = { .get = param_get_int, }; - // Params Variables static uint param_color_left = KB_COLOR_DEFAULT; module_param_named(color_left, param_color_left, uint, S_IRUSR); @@ -73,13 +72,13 @@ MODULE_PARM_DESC(mode, "Set the mode"); static ushort param_brightness = BRIGHTNESS_DEFAULT; module_param_cb(brightness, ¶m_ops_brightness_ops, ¶m_brightness, - S_IRUSR); + S_IRUSR); MODULE_PARM_DESC(brightness, "Set the Keyboard Brightness"); static bool param_state = true; module_param_named(state, param_state, bool, S_IRUSR); MODULE_PARM_DESC(state, - "Set the State of the Keyboard TRUE = ON | FALSE = OFF"); + "Set the State of the Keyboard TRUE = ON | FALSE = OFF"); // Keyboard struct static struct { @@ -99,7 +98,7 @@ static struct { .has_extra = 0,.mode = DEFAULT_MODE,.state = 1,.brightness = BRIGHTNESS_DEFAULT,.color = { .left = KB_COLOR_DEFAULT,.center = KB_COLOR_DEFAULT,.right = - KB_COLOR_DEFAULT,.extra = KB_COLOR_DEFAULT,} + KB_COLOR_DEFAULT,.extra = KB_COLOR_DEFAULT,} }; static struct { @@ -107,7 +106,7 @@ static struct { u32 value; const char *const name; } modes[] = { - { + { .key = 0,.value = 0,.name = "CUSTOM"}, { .key = 1,.value = 0x1002a000,.name = "BREATHE"}, { .key = 2,.value = 0x33010000,.name = "CYCLE"}, { @@ -118,74 +117,66 @@ static struct { .key = 7,.value = 0xB0000000,.name = "WAVE"} }; - // Sysfs Interface Methods // Sysfs Interface for the keyboard state (ON / OFF) -static ssize_t -show_state_fs(struct device *child, struct device_attribute *attr, char *buffer) +static ssize_t show_state_fs(struct device *child, + struct device_attribute *attr, char *buffer) { return sprintf(buffer, "%d\n", keyboard.state); } // Sysfs Interface for the color of the left side (Color as hexvalue) -static ssize_t -show_color_left_fs(struct device *child, struct device_attribute *attr, - char *buffer) +static ssize_t show_color_left_fs(struct device *child, + struct device_attribute *attr, char *buffer) { return sprintf(buffer, "%06x\n", keyboard.color.left); } // Sysfs Interface for the color of the center (Color as hexvalue) -static ssize_t -show_color_center_fs(struct device *child, struct device_attribute *attr, - char *buffer) +static ssize_t show_color_center_fs(struct device *child, + struct device_attribute *attr, char *buffer) { return sprintf(buffer, "%06x\n", keyboard.color.center); } // Sysfs Interface for the color of the right side (Color as hexvalue) -static ssize_t -show_color_right_fs(struct device *child, struct device_attribute *attr, - char *buffer) +static ssize_t show_color_right_fs(struct device *child, + struct device_attribute *attr, char *buffer) { return sprintf(buffer, "%06x\n", keyboard.color.right); } // Sysfs Interface for the color of the extra region (Color as hexvalue) -static ssize_t -show_color_extra_fs(struct device *child, struct device_attribute *attr, - char *buffer) +static ssize_t show_color_extra_fs(struct device *child, + struct device_attribute *attr, char *buffer) { return sprintf(buffer, "%06x\n", keyboard.color.extra); } // Sysfs Interface for the keyboard brightness (unsigned int) -static ssize_t -show_brightness_fs(struct device *child, struct device_attribute *attr, - char *buffer) +static ssize_t show_brightness_fs(struct device *child, + struct device_attribute *attr, char *buffer) { return sprintf(buffer, "%d\n", keyboard.brightness); } // Sysfs Interface for the keyboard mode -static ssize_t -show_mode_fs(struct device *child, struct device_attribute *attr, char *buffer) +static ssize_t show_mode_fs(struct device *child, struct device_attribute *attr, + char *buffer) { return sprintf(buffer, "%d\n", keyboard.mode); } // Sysfs Interface for if the keyboard has extra region -static ssize_t -show_hasextra_fs(struct device *child, struct device_attribute *attr, - char *buffer) +static ssize_t show_hasextra_fs(struct device *child, + struct device_attribute *attr, char *buffer) { return sprintf(buffer, "%d\n", keyboard.has_extra); } -static int -tuxedo_evaluate_wmi_method(u32 method_id, u32 arg, u32 * retval) +static int tuxedo_evaluate_wmi_method(u32 method_id, u32 arg, u32 * retval) { - struct acpi_buffer in = { (acpi_size) sizeof (arg), &arg }; + struct acpi_buffer in = { (acpi_size) sizeof(arg), &arg }; struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj; acpi_status status; @@ -201,7 +192,7 @@ tuxedo_evaluate_wmi_method(u32 method_id, u32 arg, u32 * retval) goto exit; } - obj = (union acpi_object *) out.pointer; + obj = (union acpi_object *)out.pointer; if (obj && obj->type == ACPI_TYPE_INTEGER) { tmp = (u32) obj->integer.value; } else { @@ -216,7 +207,7 @@ tuxedo_evaluate_wmi_method(u32 method_id, u32 arg, u32 * retval) kfree(obj); - exit: +exit: if (unlikely(ACPI_FAILURE(status))) { return -EIO; } @@ -224,17 +215,16 @@ tuxedo_evaluate_wmi_method(u32 method_id, u32 arg, u32 * retval) return 0; } -static void -set_brightness(u8 brightness) +static void set_brightness(u8 brightness) { TUXEDO_INFO("Set brightness on %d", brightness); - if (!tuxedo_evaluate_wmi_method(SET_KB_LED, 0xF4000000 | brightness, NULL)) { + if (!tuxedo_evaluate_wmi_method + (SET_KB_LED, 0xF4000000 | brightness, NULL)) { keyboard.brightness = brightness; } } -static void -set_state(u8 state) +static void set_state(u8 state) { u32 cmd = 0xE0000000; TUXEDO_INFO("Set keyboard state on: %d\n", state); @@ -250,9 +240,8 @@ set_state(u8 state) } } -static ssize_t -set_state_fs(struct device *child, struct device_attribute *attr, - const char *buffer, size_t size) +static ssize_t set_state_fs(struct device *child, struct device_attribute *attr, + const char *buffer, size_t size) { unsigned int val; int ret = kstrtouint(buffer, 0, &val); @@ -268,8 +257,7 @@ set_state_fs(struct device *child, struct device_attribute *attr, return size; } -static int -set_color(u32 region, u32 color) +static int set_color(u32 region, u32 color) { u32 cset = ((color & 0x0000FF) << 16) | ((color & 0xFF0000) >> 8) | @@ -281,8 +269,7 @@ set_color(u32 region, u32 color) return tuxedo_evaluate_wmi_method(SET_KB_LED, cmd, NULL); } -static int -set_color_region(const char *buffer, size_t size, u32 region) +static int set_color_region(const char *buffer, size_t size, u32 region) { u32 val; int ret = kstrtouint(buffer, 0, &val); @@ -311,38 +298,37 @@ set_color_region(const char *buffer, size_t size, u32 region) return size; } -static ssize_t -set_color_left_fs(struct device *child, struct device_attribute *attr, - const char *buffer, size_t size) +static ssize_t set_color_left_fs(struct device *child, + struct device_attribute *attr, + const char *buffer, size_t size) { return set_color_region(buffer, size, REGION_LEFT); } -static ssize_t -set_color_center_fs(struct device *child, struct device_attribute *attr, - const char *buffer, size_t size) +static ssize_t set_color_center_fs(struct device *child, + struct device_attribute *attr, + const char *buffer, size_t size) { return set_color_region(buffer, size, REGION_CENTER); } -static ssize_t -set_color_right_fs(struct device *child, struct device_attribute *attr, - const char *buffer, size_t size) +static ssize_t set_color_right_fs(struct device *child, + struct device_attribute *attr, + const char *buffer, size_t size) { return set_color_region(buffer, size, REGION_RIGHT); } -static ssize_t -set_color_extra_fs(struct device *child, struct device_attribute *attr, - const char *buffer, size_t size) +static ssize_t set_color_extra_fs(struct device *child, + struct device_attribute *attr, + const char *buffer, size_t size) { return set_color_region(buffer, size, REGION_EXTRA); } - -static ssize_t -set_brightness_fs(struct device *child, struct device_attribute *attr, - const char *buffer, size_t size) +static ssize_t set_brightness_fs(struct device *child, + struct device_attribute *attr, + const char *buffer, size_t size) { unsigned int val; // hier unsigned? @@ -358,8 +344,7 @@ set_brightness_fs(struct device *child, struct device_attribute *attr, return size; } -static void -set_mode(u8 mode) +static void set_mode(u8 mode) { TUXEDO_INFO("set_mode on %s", modes[mode].name); @@ -378,10 +363,8 @@ set_mode(u8 mode) } } - -static ssize_t -set_mode_fs(struct device *child, struct device_attribute *attr, - const char *buffer, size_t size) +static ssize_t set_mode_fs(struct device *child, struct device_attribute *attr, + const char *buffer, size_t size) { unsigned int val; int ret = kstrtouint(buffer, 0, &val); @@ -396,8 +379,7 @@ set_mode_fs(struct device *child, struct device_attribute *attr, return size; } -static int -mode_validator(const char *val, const struct kernel_param *kp) +static int mode_validator(const char *val, const struct kernel_param *kp) { int mode = 0; int ret; @@ -410,8 +392,7 @@ mode_validator(const char *val, const struct kernel_param *kp) return param_set_int(val, kp); } -static int -brightness_validator(const char *val, const struct kernel_param *kp) +static int brightness_validator(const char *val, const struct kernel_param *kp) { int brightness = 0; int ret; @@ -425,8 +406,7 @@ brightness_validator(const char *val, const struct kernel_param *kp) return param_set_int(val, kp); } -static void -tuxedo_wmi_notify(u32 value, void *context) +static void tuxedo_wmi_notify(u32 value, void *context) { u32 event; @@ -456,7 +436,7 @@ tuxedo_wmi_notify(u32 value, void *context) case WMI_CODE_NEXT_MODE: set_mode((keyboard.mode + 1) > - (ARRAY_SIZE(modes) - 1) ? 0 : (keyboard.mode + 1)); + (ARRAY_SIZE(modes) - 1) ? 0 : (keyboard.mode + 1)); break; case WMI_CODE_TOGGLE_STATE: @@ -468,20 +448,19 @@ tuxedo_wmi_notify(u32 value, void *context) } } -static int -tuxedo_wmi_probe(struct platform_device *dev) +static int tuxedo_wmi_probe(struct platform_device *dev) { int status; status = wmi_install_notify_handler(CLEVO_EVENT_GUID, tuxedo_wmi_notify, - NULL); + NULL); // neuer name? TUXEDO_DEBUG("clevo_xsm_wmi_probe status: (%0#6x)", status); if (unlikely(ACPI_FAILURE(status))) { TUXEDO_ERROR("Could not register WMI notify handler (%0#6x)\n", - status); + status); return -EIO; } @@ -490,44 +469,40 @@ tuxedo_wmi_probe(struct platform_device *dev) return 0; } -static int -tuxedo_wmi_remove(struct platform_device *dev) +static int tuxedo_wmi_remove(struct platform_device *dev) { wmi_remove_notify_handler(CLEVO_EVENT_GUID); return 0; } -static int -tuxedo_wmi_resume(struct platform_device *dev) +static int tuxedo_wmi_resume(struct platform_device *dev) { tuxedo_evaluate_wmi_method(GET_AP, 0, NULL); return 0; } - static struct platform_driver tuxedo_platform_driver = { .remove = tuxedo_wmi_remove, .resume = tuxedo_wmi_resume, .driver = { - .name = DRIVER_NAME, - .owner = THIS_MODULE, - }, + .name = DRIVER_NAME, + .owner = THIS_MODULE, + }, }; // Sysfs device Attributes static DEVICE_ATTR(state, 0644, show_state_fs, set_state_fs); static DEVICE_ATTR(color_left, 0644, show_color_left_fs, set_color_left_fs); static DEVICE_ATTR(color_center, 0644, show_color_center_fs, - set_color_center_fs); + set_color_center_fs); static DEVICE_ATTR(color_right, 0644, show_color_right_fs, set_color_right_fs); static DEVICE_ATTR(color_extra, 0644, show_color_extra_fs, set_color_extra_fs); static DEVICE_ATTR(brightness, 0644, show_brightness_fs, set_brightness_fs); static DEVICE_ATTR(mode, 0644, show_mode_fs, set_mode_fs); static DEVICE_ATTR(extra, 0444, show_hasextra_fs, NULL); -static int __init -tuxedo_input_init(void) +static int __init tuxedo_input_init(void) { int err; @@ -552,14 +527,13 @@ tuxedo_input_init(void) return 0; - err_free_input_device: +err_free_input_device: input_free_device(tuxedo_input_device); return err; } -static void __exit -tuxedo_input_exit(void) +static void __exit tuxedo_input_exit(void) { if (unlikely(!tuxedo_input_device)) { return; @@ -571,8 +545,7 @@ tuxedo_input_exit(void) } } -static int __init -tuxdeo_keyboard_init(void) +static int __init tuxdeo_keyboard_init(void) { int err; @@ -587,11 +560,11 @@ tuxdeo_keyboard_init(void) } TUXEDO_INFO("Model '%s' found\n", - dmi_get_system_info(DMI_PRODUCT_NAME)); + dmi_get_system_info(DMI_PRODUCT_NAME)); tuxedo_platform_device = platform_create_bundle(&tuxedo_platform_driver, tuxedo_wmi_probe, - NULL, 0, NULL, 0); + NULL, 0, NULL, 0); if (unlikely(IS_ERR(tuxedo_platform_device))) { TUXEDO_ERROR("Can not init Platform driver"); return PTR_ERR(tuxedo_platform_device); @@ -673,15 +646,14 @@ tuxdeo_keyboard_init(void) return 0; } -static void __exit -tuxdeo_keyboard_exit(void) +static void __exit tuxdeo_keyboard_exit(void) { tuxedo_input_exit(); device_remove_file(&tuxedo_platform_device->dev, &dev_attr_state); device_remove_file(&tuxedo_platform_device->dev, &dev_attr_color_left); device_remove_file(&tuxedo_platform_device->dev, - &dev_attr_color_center); + &dev_attr_color_center); device_remove_file(&tuxedo_platform_device->dev, &dev_attr_color_right); device_remove_file(&tuxedo_platform_device->dev, &dev_attr_extra); device_remove_file(&tuxedo_platform_device->dev, &dev_attr_mode); @@ -689,7 +661,7 @@ tuxdeo_keyboard_exit(void) if (keyboard.has_extra == 1) { device_remove_file(&tuxedo_platform_device->dev, - &dev_attr_color_extra); + &dev_attr_color_extra); } platform_device_unregister(tuxedo_platform_device);