WIP: Simplify keyboard LED code
This commit is contained in:
parent
cef1e2a6ed
commit
3c050e0ee7
57
ap_led.c
57
ap_led.c
|
|
@ -1,9 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* led.c
|
* ap_led.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 Jeremy Soller <jeremy@system76.com>
|
* Copyright (C) 2017 Jeremy Soller <jeremy@system76.com>
|
||||||
* Copyright (C) 2014-2016 Arnoud Willemsen <mail@lynthium.com>
|
|
||||||
* Copyright (C) 2013-2015 TUXEDO Computers GmbH <tux@tuxedocomputers.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -19,26 +17,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static struct workqueue_struct *ap_led_workqueue;
|
|
||||||
|
|
||||||
static struct _ap_led_work {
|
|
||||||
struct work_struct work;
|
|
||||||
int wk;
|
|
||||||
} ap_led_work;
|
|
||||||
|
|
||||||
static void ap_led_update(struct work_struct *work) {
|
|
||||||
u8 byte;
|
|
||||||
struct _ap_led_work *w;
|
|
||||||
|
|
||||||
w = container_of(work, struct _ap_led_work, work);
|
|
||||||
|
|
||||||
ec_read(0xD9, &byte);
|
|
||||||
|
|
||||||
ec_write(0xD9, w->wk ? byte & ~0x40 : byte | 0x40);
|
|
||||||
|
|
||||||
/* wmbb 0x6C 1 (?) */
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum led_brightness ap_led_get(struct led_classdev *led_cdev) {
|
static enum led_brightness ap_led_get(struct led_classdev *led_cdev) {
|
||||||
u8 byte;
|
u8 byte;
|
||||||
|
|
||||||
|
|
@ -47,16 +25,19 @@ static enum led_brightness ap_led_get(struct led_classdev *led_cdev) {
|
||||||
return byte & 0x40 ? LED_OFF : LED_FULL;
|
return byte & 0x40 ? LED_OFF : LED_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* must not sleep */
|
static int ap_led_set(struct led_classdev *led_cdev, enum led_brightness value) {
|
||||||
static void ap_led_set(struct led_classdev *led_cdev, enum led_brightness value) {
|
u8 byte;
|
||||||
ap_led_work.wk = value;
|
|
||||||
queue_work(ap_led_workqueue, &ap_led_work.work);
|
ec_read(0xD9, &byte);
|
||||||
|
ec_write(0xD9, value ? byte & ~0x40 : byte | 0x40);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct led_classdev ap_led = {
|
static struct led_classdev ap_led = {
|
||||||
.name = "system76::airplane",
|
.name = "system76::airplane",
|
||||||
.brightness_get = ap_led_get,
|
.brightness_get = ap_led_get,
|
||||||
.brightness_set = ap_led_set,
|
.brightness_set_blocking = ap_led_set,
|
||||||
.max_brightness = 1,
|
.max_brightness = 1,
|
||||||
.default_trigger = "rfkill-any"
|
.default_trigger = "rfkill-any"
|
||||||
};
|
};
|
||||||
|
|
@ -64,30 +45,16 @@ static struct led_classdev ap_led = {
|
||||||
static int __init ap_led_init(struct device *dev) {
|
static int __init ap_led_init(struct device *dev) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
ap_led_workqueue = create_singlethread_workqueue("ap_led_workqueue");
|
|
||||||
if (unlikely(!ap_led_workqueue)) {
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
INIT_WORK(&ap_led_work.work, ap_led_update);
|
|
||||||
|
|
||||||
err = led_classdev_register(dev, &ap_led);
|
err = led_classdev_register(dev, &ap_led);
|
||||||
if (unlikely(err)) {
|
if (unlikely(err)) {
|
||||||
goto err_destroy_workqueue;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_destroy_workqueue:
|
|
||||||
destroy_workqueue(ap_led_workqueue);
|
|
||||||
ap_led_workqueue = NULL;
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit ap_led_exit(void) {
|
static void __exit ap_led_exit(void) {
|
||||||
if (!IS_ERR_OR_NULL(ap_led.dev))
|
if (!IS_ERR_OR_NULL(ap_led.dev)) {
|
||||||
led_classdev_unregister(&ap_led);
|
led_classdev_unregister(&ap_led);
|
||||||
if (ap_led_workqueue)
|
}
|
||||||
destroy_workqueue(ap_led_workqueue);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
kb.c
11
kb.c
|
|
@ -19,8 +19,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SET_KB_LED 0x67 /* 103 */
|
|
||||||
|
|
||||||
#define COLORS { \
|
#define COLORS { \
|
||||||
C(white, 0xFFFFFF), \
|
C(white, 0xFFFFFF), \
|
||||||
C(blue, 0x0000FF), \
|
C(blue, 0x0000FF), \
|
||||||
|
|
@ -287,15 +285,16 @@ static void kb_full_color__set_color(unsigned left, unsigned center,
|
||||||
|
|
||||||
static void kb_full_color__set_brightness(unsigned i)
|
static void kb_full_color__set_brightness(unsigned i)
|
||||||
{
|
{
|
||||||
|
u8 lvl;
|
||||||
u8 lvl_to_raw[] = { 63, 126, 189, 252 };
|
u8 lvl_to_raw[] = { 63, 126, 189, 252 };
|
||||||
|
|
||||||
i = clamp_t(unsigned, i, 0, ARRAY_SIZE(lvl_to_raw) - 1);
|
i = clamp_t(unsigned, i, 0, ARRAY_SIZE(lvl_to_raw) - 1);
|
||||||
|
|
||||||
led_classdev_notify_brightness_hw_changed(&kb_led, i + 1);
|
lvl = lvl_to_raw[i];
|
||||||
|
|
||||||
if (!s76_wmbb(SET_KB_LED,
|
kb_led_set(&kb_led, lvl);
|
||||||
0xF4000000 | lvl_to_raw[i], NULL))
|
led_classdev_notify_brightness_hw_changed(&kb_led, lvl);
|
||||||
kb_backlight.brightness = i;
|
kb_backlight.brightness = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_full_color__set_mode(unsigned mode)
|
static void kb_full_color__set_mode(unsigned mode)
|
||||||
|
|
|
||||||
52
kb_led.c
52
kb_led.c
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* led.c
|
* kb_led.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 Jeremy Soller <jeremy@system76.com>
|
* Copyright (C) 2017 Jeremy Soller <jeremy@system76.com>
|
||||||
*
|
*
|
||||||
|
|
@ -17,65 +17,43 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static struct workqueue_struct *kb_led_workqueue;
|
#define SET_KB_LED 0x67
|
||||||
|
|
||||||
static struct _kb_led_work {
|
static enum led_brightness kb_led_brightness = LED_OFF;
|
||||||
struct work_struct work;
|
|
||||||
int wk;
|
|
||||||
} kb_led_work;
|
|
||||||
|
|
||||||
static void kb_led_update(struct work_struct *work) {
|
|
||||||
u8 byte;
|
|
||||||
struct _kb_led_work *w;
|
|
||||||
|
|
||||||
w = container_of(work, struct _kb_led_work, work);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum led_brightness kb_led_get(struct led_classdev *led_cdev) {
|
static enum led_brightness kb_led_get(struct led_classdev *led_cdev) {
|
||||||
return LED_OFF;
|
return kb_led_brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* must not sleep */
|
static int kb_led_set(struct led_classdev *led_cdev, enum led_brightness value) {
|
||||||
static void kb_led_set(struct led_classdev *led_cdev, enum led_brightness value) {
|
if (!s76_wmbb(SET_KB_LED, 0xF4000000 | value, NULL)) {
|
||||||
kb_led_work.wk = value;
|
kb_led_brightness = value;
|
||||||
queue_work(kb_led_workqueue, &kb_led_work.work);
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct led_classdev kb_led = {
|
static struct led_classdev kb_led = {
|
||||||
.name = "system76::kbd_backlight",
|
.name = "system76::kbd_backlight",
|
||||||
.flags = LED_BRIGHT_HW_CHANGED,
|
.flags = LED_BRIGHT_HW_CHANGED,
|
||||||
.brightness_get = kb_led_get,
|
.brightness_get = kb_led_get,
|
||||||
.brightness_set = kb_led_set,
|
.brightness_set_blocking = kb_led_set,
|
||||||
.max_brightness = 4,
|
.max_brightness = 255,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init kb_led_init(struct device *dev) {
|
static int __init kb_led_init(struct device *dev) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
kb_led_workqueue = create_singlethread_workqueue("kb_led_workqueue");
|
|
||||||
if (unlikely(!kb_led_workqueue)) {
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
INIT_WORK(&kb_led_work.work, kb_led_update);
|
|
||||||
|
|
||||||
err = led_classdev_register(dev, &kb_led);
|
err = led_classdev_register(dev, &kb_led);
|
||||||
if (unlikely(err)) {
|
if (unlikely(err)) {
|
||||||
goto err_destroy_workqueue;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_destroy_workqueue:
|
|
||||||
destroy_workqueue(kb_led_workqueue);
|
|
||||||
kb_led_workqueue = NULL;
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit kb_led_exit(void) {
|
static void __exit kb_led_exit(void) {
|
||||||
if (!IS_ERR_OR_NULL(kb_led.dev))
|
if (!IS_ERR_OR_NULL(kb_led.dev)) {
|
||||||
led_classdev_unregister(&kb_led);
|
led_classdev_unregister(&kb_led);
|
||||||
if (kb_led_workqueue)
|
}
|
||||||
destroy_workqueue(kb_led_workqueue);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue