kbled: Check if using white or RGB keyboard
Use RGBKB-DET# to determine the type of keyboard connected. If a white keyboard is attached, always set the color to white, and always return white for the color. Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
committed by
Jeremy Soller
parent
c71a58f7cf
commit
598aef8c4a
@ -5,6 +5,13 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
enum KbledKind {
|
||||||
|
KBLED_NONE = 0,
|
||||||
|
KBLED_WHITE = 1,
|
||||||
|
KBLED_RGB = 2,
|
||||||
|
};
|
||||||
|
extern enum KbledKind kbled_kind;
|
||||||
|
|
||||||
// Must be specified by board
|
// Must be specified by board
|
||||||
void kbled_init(void);
|
void kbled_init(void);
|
||||||
void kbled_reset(void);
|
void kbled_reset(void);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include <board/kbled.h>
|
#include <board/kbled.h>
|
||||||
#include <common/macro.h>
|
#include <common/macro.h>
|
||||||
|
|
||||||
|
enum KbledKind kbled_kind = KBLED_NONE;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static uint8_t LEVEL_I = 1;
|
static uint8_t LEVEL_I = 1;
|
||||||
static const uint8_t __code LEVELS[] = {
|
static const uint8_t __code LEVELS[] = {
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <ec/smbus.h>
|
#include <ec/smbus.h>
|
||||||
|
|
||||||
void kbled_init(void) {
|
void kbled_init(void) {
|
||||||
|
kbled_kind = KBLED_RGB;
|
||||||
|
|
||||||
i2c_reset(&I2C_DGPU, true);
|
i2c_reset(&I2C_DGPU, true);
|
||||||
|
|
||||||
// Force SMBUS B design to 100kHZ
|
// Force SMBUS B design to 100kHZ
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
#include <arch/delay.h>
|
#include <arch/delay.h>
|
||||||
|
#include <board/gpio.h>
|
||||||
#include <board/kbled.h>
|
#include <board/kbled.h>
|
||||||
#include <common/macro.h>
|
#include <common/macro.h>
|
||||||
#include <ec/i2c.h>
|
#include <ec/i2c.h>
|
||||||
@ -9,6 +10,12 @@
|
|||||||
#define kbled_i2c_set(A, D, L) i2c_set(&I2C_KBLED, 0x68, A, D, L)
|
#define kbled_i2c_set(A, D, L) i2c_set(&I2C_KBLED, 0x68, A, D, L)
|
||||||
|
|
||||||
void kbled_init(void) {
|
void kbled_init(void) {
|
||||||
|
if (!gpio_get(&RGBKB_DET_N)) {
|
||||||
|
kbled_kind = KBLED_RGB;
|
||||||
|
} else {
|
||||||
|
kbled_kind = KBLED_WHITE;
|
||||||
|
}
|
||||||
|
|
||||||
i2c_reset(&I2C_KBLED, true);
|
i2c_reset(&I2C_KBLED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +55,9 @@ void kbled_set(uint8_t level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t kbled_get_color(void) {
|
uint32_t kbled_get_color(void) {
|
||||||
|
if (kbled_kind == KBLED_WHITE)
|
||||||
|
return 0xFFFFFF;
|
||||||
|
|
||||||
// Get blue component from channel 0
|
// Get blue component from channel 0
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
kbled_i2c_get(0x02, &value, 1);
|
kbled_i2c_get(0x02, &value, 1);
|
||||||
@ -65,6 +75,9 @@ uint32_t kbled_get_color(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void kbled_set_color(uint32_t color) {
|
void kbled_set_color(uint32_t color) {
|
||||||
|
if (kbled_kind == KBLED_WHITE)
|
||||||
|
color = 0xFFFFFF;
|
||||||
|
|
||||||
// Set channel 0 - 2 to blue component
|
// Set channel 0 - 2 to blue component
|
||||||
uint8_t value = (uint8_t)(color);
|
uint8_t value = (uint8_t)(color);
|
||||||
kbled_i2c_set(0x02, &value, 1);
|
kbled_i2c_set(0x02, &value, 1);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
#include <arch/delay.h>
|
#include <arch/delay.h>
|
||||||
|
#include <board/gpio.h>
|
||||||
#include <board/kbled.h>
|
#include <board/kbled.h>
|
||||||
#include <common/macro.h>
|
#include <common/macro.h>
|
||||||
#include <ec/i2c.h>
|
#include <ec/i2c.h>
|
||||||
@ -9,6 +10,12 @@
|
|||||||
#define kbled_i2c_set(A, D, L) i2c_set(&I2C_KBLED, 0x68, A, D, L)
|
#define kbled_i2c_set(A, D, L) i2c_set(&I2C_KBLED, 0x68, A, D, L)
|
||||||
|
|
||||||
void kbled_init(void) {
|
void kbled_init(void) {
|
||||||
|
if (!gpio_get(&RGBKB_DET_N)) {
|
||||||
|
kbled_kind = KBLED_RGB;
|
||||||
|
} else {
|
||||||
|
kbled_kind = KBLED_WHITE;
|
||||||
|
}
|
||||||
|
|
||||||
i2c_reset(&I2C_KBLED, true);
|
i2c_reset(&I2C_KBLED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +55,9 @@ void kbled_set(uint8_t level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t kbled_get_color(void) {
|
uint32_t kbled_get_color(void) {
|
||||||
|
if (kbled_kind == KBLED_WHITE)
|
||||||
|
return 0xFFFFFF;
|
||||||
|
|
||||||
// Get blue component
|
// Get blue component
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
kbled_i2c_get(0x02, &value, 1);
|
kbled_i2c_get(0x02, &value, 1);
|
||||||
@ -65,6 +75,9 @@ uint32_t kbled_get_color(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void kbled_set_color(uint32_t color) {
|
void kbled_set_color(uint32_t color) {
|
||||||
|
if (kbled_kind == KBLED_WHITE)
|
||||||
|
color = 0xFFFFFF;
|
||||||
|
|
||||||
// Set blue component
|
// Set blue component
|
||||||
uint8_t value = (uint8_t)(color);
|
uint8_t value = (uint8_t)(color);
|
||||||
kbled_i2c_set(0x02, &value, 1);
|
kbled_i2c_set(0x02, &value, 1);
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
#include <board/gpio.h>
|
||||||
#include <board/kbled.h>
|
#include <board/kbled.h>
|
||||||
#include <ec/pwm.h>
|
#include <ec/pwm.h>
|
||||||
|
|
||||||
void kbled_init(void) {
|
void kbled_init(void) {
|
||||||
|
if (!gpio_get(&RGBKB_DET_N)) {
|
||||||
|
kbled_kind = KBLED_RGB;
|
||||||
|
} else {
|
||||||
|
kbled_kind = KBLED_WHITE;
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: enable PWMs
|
//TODO: enable PWMs
|
||||||
kbled_reset();
|
kbled_reset();
|
||||||
}
|
}
|
||||||
@ -29,6 +36,9 @@ void kbled_set(uint8_t level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t kbled_get_color(void) {
|
uint32_t kbled_get_color(void) {
|
||||||
|
if (kbled_kind == KBLED_WHITE)
|
||||||
|
return 0xFFFFFF;
|
||||||
|
|
||||||
// Get PWM of blue component
|
// Get PWM of blue component
|
||||||
uint32_t color = (uint32_t)DCR7;
|
uint32_t color = (uint32_t)DCR7;
|
||||||
|
|
||||||
@ -42,6 +52,9 @@ uint32_t kbled_get_color(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void kbled_set_color(uint32_t color) {
|
void kbled_set_color(uint32_t color) {
|
||||||
|
if (kbled_kind == KBLED_WHITE)
|
||||||
|
color = 0xFFFFFF;
|
||||||
|
|
||||||
// Set PWM for blue component
|
// Set PWM for blue component
|
||||||
DCR7 = (uint8_t)(color);
|
DCR7 = (uint8_t)(color);
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ static uint8_t __code levels[] = {
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
void kbled_init(void) {
|
void kbled_init(void) {
|
||||||
|
kbled_kind = KBLED_WHITE;
|
||||||
|
|
||||||
// Enable DAC used for KBLIGHT_ADJ
|
// Enable DAC used for KBLIGHT_ADJ
|
||||||
DACPDREG &= ~BIT(KBLED_DAC);
|
DACPDREG &= ~BIT(KBLED_DAC);
|
||||||
kbled_reset();
|
kbled_reset();
|
||||||
|
Reference in New Issue
Block a user