Format code
Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
parent
5ea0d7de14
commit
c81a34d0fc
21
src/ap-led.c
21
src/ap-led.c
|
|
@ -21,11 +21,13 @@ static enum led_brightness ap_led_brightness = 1;
|
||||||
|
|
||||||
static bool ap_led_invert = TRUE;
|
static bool ap_led_invert = TRUE;
|
||||||
|
|
||||||
static enum led_brightness ap_led_get(struct led_classdev *led_cdev) {
|
static enum led_brightness ap_led_get(struct led_classdev *led_cdev)
|
||||||
|
{
|
||||||
return ap_led_brightness;
|
return ap_led_brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ap_led_set(struct led_classdev *led_cdev, enum led_brightness value) {
|
static int ap_led_set(struct led_classdev *led_cdev, enum led_brightness value)
|
||||||
|
{
|
||||||
u8 byte;
|
u8 byte;
|
||||||
|
|
||||||
ec_read(0xD9, &byte);
|
ec_read(0xD9, &byte);
|
||||||
|
|
@ -61,11 +63,13 @@ static struct led_classdev ap_led = {
|
||||||
.default_trigger = "rfkill-any"
|
.default_trigger = "rfkill-any"
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssize_t ap_led_invert_show(struct device *dev, struct device_attribute *attr, char *buf) {
|
static ssize_t ap_led_invert_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
return sprintf(buf, "%d\n", (int)ap_led_invert);
|
return sprintf(buf, "%d\n", (int)ap_led_invert);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t ap_led_invert_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) {
|
static ssize_t ap_led_invert_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
|
||||||
|
{
|
||||||
unsigned int val;
|
unsigned int val;
|
||||||
int ret;
|
int ret;
|
||||||
enum led_brightness brightness;
|
enum led_brightness brightness;
|
||||||
|
|
@ -97,11 +101,13 @@ static struct device_attribute ap_led_invert_dev_attr = {
|
||||||
.store = ap_led_invert_store,
|
.store = ap_led_invert_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ap_led_resume(void) {
|
static void ap_led_resume(void)
|
||||||
|
{
|
||||||
ap_led_set(&ap_led, ap_led_brightness);
|
ap_led_set(&ap_led, ap_led_brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init ap_led_init(struct device *dev) {
|
static int __init ap_led_init(struct device *dev)
|
||||||
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = led_classdev_register(dev, &ap_led);
|
err = led_classdev_register(dev, &ap_led);
|
||||||
|
|
@ -118,7 +124,8 @@ static int __init ap_led_init(struct device *dev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit ap_led_exit(void) {
|
static void __exit ap_led_exit(void)
|
||||||
|
{
|
||||||
device_remove_file(ap_led.dev, &ap_led_invert_dev_attr);
|
device_remove_file(ap_led.dev, &ap_led_invert_dev_attr);
|
||||||
|
|
||||||
if (!IS_ERR_OR_NULL(ap_led.dev)) {
|
if (!IS_ERR_OR_NULL(ap_led.dev)) {
|
||||||
|
|
|
||||||
105
src/hwmon.c
105
src/hwmon.c
|
|
@ -22,14 +22,15 @@
|
||||||
#define EXPERIMENTAL
|
#define EXPERIMENTAL
|
||||||
|
|
||||||
#if S76_HAS_HWMON
|
#if S76_HAS_HWMON
|
||||||
|
|
||||||
struct s76_hwmon {
|
struct s76_hwmon {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct s76_hwmon *s76_hwmon = NULL;
|
static struct s76_hwmon *s76_hwmon = NULL;
|
||||||
|
|
||||||
static int
|
static int s76_read_fan(int idx)
|
||||||
s76_read_fan(int idx) {
|
{
|
||||||
u8 value;
|
u8 value;
|
||||||
int raw_rpm;
|
int raw_rpm;
|
||||||
ec_read(0xd0 + 0x2 * idx, &value);
|
ec_read(0xd0 + 0x2 * idx, &value);
|
||||||
|
|
@ -41,43 +42,40 @@ s76_read_fan(int idx) {
|
||||||
return 2156220 / raw_rpm;
|
return 2156220 / raw_rpm;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s76_read_pwm(int idx)
|
||||||
s76_read_pwm(int idx) {
|
{
|
||||||
u8 value;
|
u8 value;
|
||||||
ec_read(0xce + idx, &value);
|
ec_read(0xce + idx, &value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s76_write_pwm(int idx, u8 duty)
|
||||||
s76_write_pwm(int idx, u8 duty) {
|
{
|
||||||
u8 values[] = {idx + 1, duty};
|
u8 values[] = {idx + 1, duty};
|
||||||
return ec_transaction(0x99, values, sizeof(values), NULL, 0);
|
return ec_transaction(0x99, values, sizeof(values), NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s76_write_pwm_auto(int idx)
|
||||||
s76_write_pwm_auto(int idx) {
|
{
|
||||||
u8 values[] = {0xff, idx + 1};
|
u8 values[] = {0xff, idx + 1};
|
||||||
return ec_transaction(0x99, values, sizeof(values), NULL, 0);
|
return ec_transaction(0x99, values, sizeof(values), NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_name(struct device *dev,
|
||||||
s76_hwmon_show_name(struct device *dev, struct device_attribute *attr,
|
struct device_attribute *attr, char *buf)
|
||||||
char *buf)
|
|
||||||
{
|
{
|
||||||
return sprintf(buf, S76_DRIVER_NAME "\n");
|
return sprintf(buf, S76_DRIVER_NAME "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_fan_input(struct device *dev,
|
||||||
s76_hwmon_show_fan_input(struct device *dev, struct device_attribute *attr,
|
struct device_attribute *attr, char *buf)
|
||||||
char *buf)
|
|
||||||
{
|
{
|
||||||
int index = to_sensor_dev_attr(attr)->index;
|
int index = to_sensor_dev_attr(attr)->index;
|
||||||
return sprintf(buf, "%i\n", s76_read_fan(index));
|
return sprintf(buf, "%i\n", s76_read_fan(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_fan_label(struct device *dev,
|
||||||
s76_hwmon_show_fan_label(struct device *dev, struct device_attribute *attr,
|
struct device_attribute *attr, char *buf)
|
||||||
char *buf)
|
|
||||||
{
|
{
|
||||||
switch (to_sensor_dev_attr(attr)->index) {
|
switch (to_sensor_dev_attr(attr)->index) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -90,92 +88,99 @@ s76_hwmon_show_fan_label(struct device *dev, struct device_attribute *attr,
|
||||||
|
|
||||||
static int pwm_enabled[] = {2, 2};
|
static int pwm_enabled[] = {2, 2};
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_pwm(struct device *dev,
|
||||||
s76_hwmon_show_pwm(struct device *dev, struct device_attribute *attr,
|
struct device_attribute *attr, char *buf)
|
||||||
char *buf)
|
|
||||||
{
|
{
|
||||||
int index = to_sensor_dev_attr(attr)->index;
|
int index = to_sensor_dev_attr(attr)->index;
|
||||||
return sprintf(buf, "%i\n", s76_read_pwm(index));
|
return sprintf(buf, "%i\n", s76_read_pwm(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_set_pwm(struct device *dev,
|
||||||
s76_hwmon_set_pwm(struct device *dev, struct device_attribute *attr,
|
struct device_attribute *attr, const char *buf, size_t count)
|
||||||
const char *buf, size_t count)
|
|
||||||
{
|
{
|
||||||
u32 value;
|
u32 value;
|
||||||
int err;
|
int err;
|
||||||
int index = to_sensor_dev_attr(attr)->index;
|
int index = to_sensor_dev_attr(attr)->index;
|
||||||
|
|
||||||
err = kstrtou32(buf, 10, &value);
|
err = kstrtou32(buf, 10, &value);
|
||||||
if (err) return err;
|
if (err)
|
||||||
if (value > 255) return -EINVAL;
|
return err;
|
||||||
|
if (value > 255)
|
||||||
|
return -EINVAL;
|
||||||
err = s76_write_pwm(index, value);
|
err = s76_write_pwm(index, value);
|
||||||
if (err) return err;
|
if (err)
|
||||||
|
return err;
|
||||||
pwm_enabled[index] = 1;
|
pwm_enabled[index] = 1;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_pwm_enable(struct device *dev,
|
||||||
s76_hwmon_show_pwm_enable(struct device *dev, struct device_attribute *attr,
|
struct device_attribute *attr, char *buf)
|
||||||
char *buf)
|
|
||||||
{
|
{
|
||||||
int index = to_sensor_dev_attr(attr)->index;
|
int index = to_sensor_dev_attr(attr)->index;
|
||||||
return sprintf(buf, "%i\n", pwm_enabled[index]);
|
return sprintf(buf, "%i\n", pwm_enabled[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_set_pwm_enable(struct device *dev,
|
||||||
s76_hwmon_set_pwm_enable(struct device *dev, struct device_attribute *attr,
|
struct device_attribute *attr, const char *buf, size_t count)
|
||||||
const char *buf, size_t count)
|
|
||||||
{
|
{
|
||||||
u32 value;
|
u32 value;
|
||||||
int err;
|
int err;
|
||||||
int index = to_sensor_dev_attr(attr)->index;
|
int index = to_sensor_dev_attr(attr)->index;
|
||||||
|
|
||||||
err = kstrtou32(buf, 10, &value);
|
err = kstrtou32(buf, 10, &value);
|
||||||
if (err) return err;
|
if (err)
|
||||||
|
return err;
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
err = s76_write_pwm(index, 255);
|
err = s76_write_pwm(index, 255);
|
||||||
if (err) return err;
|
if (err)
|
||||||
|
return err;
|
||||||
pwm_enabled[index] = value;
|
pwm_enabled[index] = value;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
if (value == 1) {
|
if (value == 1) {
|
||||||
err = s76_write_pwm(index, 0);
|
err = s76_write_pwm(index, 0);
|
||||||
if (err) return err;
|
if (err)
|
||||||
|
return err;
|
||||||
pwm_enabled[index] = value;
|
pwm_enabled[index] = value;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
if (value == 2) {
|
if (value == 2) {
|
||||||
err = s76_write_pwm_auto(index);
|
err = s76_write_pwm_auto(index);
|
||||||
if (err) return err;
|
if (err)
|
||||||
|
return err;
|
||||||
pwm_enabled[index] = value;
|
pwm_enabled[index] = value;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_temp1_input(struct device *dev,
|
||||||
s76_hwmon_show_temp1_input(struct device *dev, struct device_attribute *attr, char *buf) {
|
struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
u8 value;
|
u8 value;
|
||||||
ec_read(0x07, &value);
|
ec_read(0x07, &value);
|
||||||
return sprintf(buf, "%i\n", value * 1000);
|
return sprintf(buf, "%i\n", value * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_temp1_label(struct device *dev,
|
||||||
s76_hwmon_show_temp1_label(struct device *dev, struct device_attribute *attr, char *buf) {
|
struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
return sprintf(buf, "CPU temperature\n");
|
return sprintf(buf, "CPU temperature\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL
|
#ifdef EXPERIMENTAL
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_temp2_input(struct device *dev,
|
||||||
s76_hwmon_show_temp2_input(struct device *dev, struct device_attribute *attr, char *buf) {
|
struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
u8 value;
|
u8 value;
|
||||||
ec_read(0xcd, &value);
|
ec_read(0xcd, &value);
|
||||||
return sprintf(buf, "%i\n", value * 1000);
|
return sprintf(buf, "%i\n", value * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t s76_hwmon_show_temp2_label(struct device *dev,
|
||||||
s76_hwmon_show_temp2_label(struct device *dev, struct device_attribute *attr, char *buf) {
|
struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
return sprintf(buf, "GPU temperature\n");
|
return sprintf(buf, "GPU temperature\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -224,7 +229,8 @@ static const struct attribute_group hwmon_default_attrgroup = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static int s76_hwmon_reboot_callback(struct notifier_block *nb,
|
static int s76_hwmon_reboot_callback(struct notifier_block *nb,
|
||||||
unsigned long action, void *data) {
|
unsigned long action, void *data)
|
||||||
|
{
|
||||||
s76_write_pwm_auto(0);
|
s76_write_pwm_auto(0);
|
||||||
#ifdef EXPERIMENTAL
|
#ifdef EXPERIMENTAL
|
||||||
s76_write_pwm_auto(1);
|
s76_write_pwm_auto(1);
|
||||||
|
|
@ -236,8 +242,8 @@ static struct notifier_block s76_hwmon_reboot_notifier = {
|
||||||
.notifier_call = s76_hwmon_reboot_callback
|
.notifier_call = s76_hwmon_reboot_callback
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int s76_hwmon_init(struct device *dev)
|
||||||
s76_hwmon_init(struct device *dev) {
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
s76_hwmon = kzalloc(sizeof(*s76_hwmon), GFP_KERNEL);
|
s76_hwmon = kzalloc(sizeof(*s76_hwmon), GFP_KERNEL);
|
||||||
|
|
@ -262,8 +268,8 @@ s76_hwmon_init(struct device *dev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s76_hwmon_fini(struct device *dev)
|
||||||
s76_hwmon_fini(struct device *dev) {
|
{
|
||||||
if (!s76_hwmon || !s76_hwmon->dev)
|
if (!s76_hwmon || !s76_hwmon->dev)
|
||||||
return 0;
|
return 0;
|
||||||
s76_write_pwm_auto(0);
|
s76_write_pwm_auto(0);
|
||||||
|
|
@ -276,4 +282,5 @@ s76_hwmon_fini(struct device *dev) {
|
||||||
kfree(s76_hwmon);
|
kfree(s76_hwmon);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // S76_HAS_HWMON
|
#endif // S76_HAS_HWMON
|
||||||
|
|
|
||||||
24
src/input.c
24
src/input.c
|
|
@ -56,7 +56,8 @@ MODULE_PARM_DESC(poll_freq, "Set polling frequency");
|
||||||
|
|
||||||
static struct task_struct *s76_input_polling_task;
|
static struct task_struct *s76_input_polling_task;
|
||||||
|
|
||||||
static void s76_input_key(unsigned int code) {
|
static void s76_input_key(unsigned int code)
|
||||||
|
{
|
||||||
S76_DEBUG("Send key %x\n", code);
|
S76_DEBUG("Send key %x\n", code);
|
||||||
|
|
||||||
mutex_lock(&s76_input_report_mutex);
|
mutex_lock(&s76_input_report_mutex);
|
||||||
|
|
@ -70,7 +71,8 @@ static void s76_input_key(unsigned int code) {
|
||||||
mutex_unlock(&s76_input_report_mutex);
|
mutex_unlock(&s76_input_report_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s76_input_polling_thread(void *data) {
|
static int s76_input_polling_thread(void *data)
|
||||||
|
{
|
||||||
S76_DEBUG("Polling thread started (PID: %i), polling at %i Hz\n",
|
S76_DEBUG("Polling thread started (PID: %i), polling at %i Hz\n",
|
||||||
current->pid, param_poll_freq);
|
current->pid, param_poll_freq);
|
||||||
|
|
||||||
|
|
@ -94,19 +96,22 @@ static int s76_input_polling_thread(void *data) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void s76_input_airplane_wmi(void) {
|
static void s76_input_airplane_wmi(void)
|
||||||
|
{
|
||||||
S76_DEBUG("Airplane-Mode Hotkey pressed (WMI)\n");
|
S76_DEBUG("Airplane-Mode Hotkey pressed (WMI)\n");
|
||||||
|
|
||||||
s76_input_key(AIRPLANE_KEY);
|
s76_input_key(AIRPLANE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void s76_input_screen_wmi(void) {
|
static void s76_input_screen_wmi(void)
|
||||||
|
{
|
||||||
S76_DEBUG("Screen Hotkey pressed (WMI)\n");
|
S76_DEBUG("Screen Hotkey pressed (WMI)\n");
|
||||||
|
|
||||||
s76_input_key(SCREEN_KEY);
|
s76_input_key(SCREEN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s76_input_open(struct input_dev *dev) {
|
static int s76_input_open(struct input_dev *dev)
|
||||||
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
// Run polling thread if AP key driver is used and WMI is not supported
|
// Run polling thread if AP key driver is used and WMI is not supported
|
||||||
|
|
@ -126,7 +131,8 @@ static int s76_input_open(struct input_dev *dev) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void s76_input_close(struct input_dev *dev) {
|
static void s76_input_close(struct input_dev *dev)
|
||||||
|
{
|
||||||
if (unlikely(IS_ERR_OR_NULL(s76_input_polling_task))) {
|
if (unlikely(IS_ERR_OR_NULL(s76_input_polling_task))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -135,7 +141,8 @@ static void s76_input_close(struct input_dev *dev) {
|
||||||
s76_input_polling_task = NULL;
|
s76_input_polling_task = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init s76_input_init(struct device *dev) {
|
static int __init s76_input_init(struct device *dev)
|
||||||
|
{
|
||||||
int err;
|
int err;
|
||||||
u8 byte;
|
u8 byte;
|
||||||
|
|
||||||
|
|
@ -176,7 +183,8 @@ err_free_input_device:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit s76_input_exit(void) {
|
static void __exit s76_input_exit(void)
|
||||||
|
{
|
||||||
if (unlikely(!s76_input_device)) {
|
if (unlikely(!s76_input_device)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
72
src/kb-led.c
72
src/kb-led.c
|
|
@ -56,11 +56,13 @@ static union kb_led_color kb_led_colors[] = {
|
||||||
{ .rgb = 0xFFFF00 }
|
{ .rgb = 0xFFFF00 }
|
||||||
};
|
};
|
||||||
|
|
||||||
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 kb_led_brightness;
|
return kb_led_brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kb_led_set(struct led_classdev *led_cdev, enum led_brightness value) {
|
static int kb_led_set(struct led_classdev *led_cdev, enum led_brightness value)
|
||||||
|
{
|
||||||
S76_DEBUG("kb_led_set %d\n", (int)value);
|
S76_DEBUG("kb_led_set %d\n", (int)value);
|
||||||
|
|
||||||
if (!s76_wmbb(SET_KB_LED, 0xF4000000 | value, NULL)) {
|
if (!s76_wmbb(SET_KB_LED, 0xF4000000 | value, NULL)) {
|
||||||
|
|
@ -70,7 +72,8 @@ static int kb_led_set(struct led_classdev *led_cdev, enum led_brightness value)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_led_color_set(enum kb_led_region region, union kb_led_color color) {
|
static void kb_led_color_set(enum kb_led_region region, union kb_led_color color)
|
||||||
|
{
|
||||||
u32 cmd;
|
u32 cmd;
|
||||||
|
|
||||||
S76_DEBUG("kb_led_color_set %d %06X\n", (int)region, (int)color.rgb);
|
S76_DEBUG("kb_led_color_set %d %06X\n", (int)region, (int)color.rgb);
|
||||||
|
|
@ -109,11 +112,13 @@ static struct led_classdev kb_led = {
|
||||||
.max_brightness = 255,
|
.max_brightness = 255,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssize_t kb_led_color_show(enum kb_led_region region, char *buf) {
|
static ssize_t kb_led_color_show(enum kb_led_region region, char *buf)
|
||||||
|
{
|
||||||
return sprintf(buf, "%06X\n", (int)kb_led_regions[region].rgb);
|
return sprintf(buf, "%06X\n", (int)kb_led_regions[region].rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t kb_led_color_store(enum kb_led_region region, const char *buf, size_t size) {
|
static ssize_t kb_led_color_store(enum kb_led_region region, const char *buf, size_t size)
|
||||||
|
{
|
||||||
unsigned int val;
|
unsigned int val;
|
||||||
int ret;
|
int ret;
|
||||||
union kb_led_color color;
|
union kb_led_color color;
|
||||||
|
|
@ -129,11 +134,13 @@ static ssize_t kb_led_color_store(enum kb_led_region region, const char *buf, si
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t kb_led_color_left_show(struct device *dev, struct device_attribute *attr, char *buf) {
|
static ssize_t kb_led_color_left_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
return kb_led_color_show(KB_LED_REGION_LEFT, buf);
|
return kb_led_color_show(KB_LED_REGION_LEFT, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t kb_led_color_left_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) {
|
static ssize_t kb_led_color_left_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
|
||||||
|
{
|
||||||
return kb_led_color_store(KB_LED_REGION_LEFT, buf, size);
|
return kb_led_color_store(KB_LED_REGION_LEFT, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,11 +153,13 @@ static struct device_attribute kb_led_color_left_dev_attr = {
|
||||||
.store = kb_led_color_left_store,
|
.store = kb_led_color_left_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssize_t kb_led_color_center_show(struct device *dev, struct device_attribute *attr, char *buf) {
|
static ssize_t kb_led_color_center_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
return kb_led_color_show(KB_LED_REGION_CENTER, buf);
|
return kb_led_color_show(KB_LED_REGION_CENTER, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t kb_led_color_center_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) {
|
static ssize_t kb_led_color_center_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
|
||||||
|
{
|
||||||
return kb_led_color_store(KB_LED_REGION_CENTER, buf, size);
|
return kb_led_color_store(KB_LED_REGION_CENTER, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,11 +172,13 @@ static struct device_attribute kb_led_color_center_dev_attr = {
|
||||||
.store = kb_led_color_center_store,
|
.store = kb_led_color_center_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssize_t kb_led_color_right_show(struct device *dev, struct device_attribute *attr, char *buf) {
|
static ssize_t kb_led_color_right_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
return kb_led_color_show(KB_LED_REGION_RIGHT, buf);
|
return kb_led_color_show(KB_LED_REGION_RIGHT, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t kb_led_color_right_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) {
|
static ssize_t kb_led_color_right_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
|
||||||
|
{
|
||||||
return kb_led_color_store(KB_LED_REGION_RIGHT, buf, size);
|
return kb_led_color_store(KB_LED_REGION_RIGHT, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,11 +191,13 @@ static struct device_attribute kb_led_color_right_dev_attr = {
|
||||||
.store = kb_led_color_right_store,
|
.store = kb_led_color_right_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssize_t kb_led_color_extra_show(struct device *dev, struct device_attribute *attr, char *buf) {
|
static ssize_t kb_led_color_extra_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
return kb_led_color_show(KB_LED_REGION_EXTRA, buf);
|
return kb_led_color_show(KB_LED_REGION_EXTRA, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t kb_led_color_extra_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) {
|
static ssize_t kb_led_color_extra_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
|
||||||
|
{
|
||||||
return kb_led_color_store(KB_LED_REGION_EXTRA, buf, size);
|
return kb_led_color_store(KB_LED_REGION_EXTRA, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,26 +210,30 @@ static struct device_attribute kb_led_color_extra_dev_attr = {
|
||||||
.store = kb_led_color_extra_store,
|
.store = kb_led_color_extra_store,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void kb_led_enable(void) {
|
static void kb_led_enable(void)
|
||||||
|
{
|
||||||
S76_DEBUG("kb_led_enable\n");
|
S76_DEBUG("kb_led_enable\n");
|
||||||
|
|
||||||
s76_wmbb(SET_KB_LED, 0xE007F001, NULL);
|
s76_wmbb(SET_KB_LED, 0xE007F001, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_led_disable(void) {
|
static void kb_led_disable(void)
|
||||||
|
{
|
||||||
S76_DEBUG("kb_led_disable\n");
|
S76_DEBUG("kb_led_disable\n");
|
||||||
|
|
||||||
s76_wmbb(SET_KB_LED, 0xE0003001, NULL);
|
s76_wmbb(SET_KB_LED, 0xE0003001, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_led_suspend(void) {
|
static void kb_led_suspend(void)
|
||||||
|
{
|
||||||
S76_DEBUG("kb_led_suspend\n");
|
S76_DEBUG("kb_led_suspend\n");
|
||||||
|
|
||||||
// Disable keyboard backlight
|
// Disable keyboard backlight
|
||||||
kb_led_disable();
|
kb_led_disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_led_resume(void) {
|
static void kb_led_resume(void)
|
||||||
|
{
|
||||||
enum kb_led_region region;
|
enum kb_led_region region;
|
||||||
|
|
||||||
S76_DEBUG("kb_led_resume\n");
|
S76_DEBUG("kb_led_resume\n");
|
||||||
|
|
@ -236,7 +253,8 @@ static void kb_led_resume(void) {
|
||||||
kb_led_enable();
|
kb_led_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init kb_led_init(struct device *dev) {
|
static int __init kb_led_init(struct device *dev)
|
||||||
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = led_classdev_register(dev, &kb_led);
|
err = led_classdev_register(dev, &kb_led);
|
||||||
|
|
@ -265,7 +283,8 @@ static int __init kb_led_init(struct device *dev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit kb_led_exit(void) {
|
static void __exit kb_led_exit(void)
|
||||||
|
{
|
||||||
device_remove_file(kb_led.dev, &kb_led_color_extra_dev_attr);
|
device_remove_file(kb_led.dev, &kb_led_color_extra_dev_attr);
|
||||||
device_remove_file(kb_led.dev, &kb_led_color_right_dev_attr);
|
device_remove_file(kb_led.dev, &kb_led_color_right_dev_attr);
|
||||||
device_remove_file(kb_led.dev, &kb_led_color_center_dev_attr);
|
device_remove_file(kb_led.dev, &kb_led_color_center_dev_attr);
|
||||||
|
|
@ -276,14 +295,16 @@ static void __exit kb_led_exit(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_wmi_brightness(enum led_brightness value) {
|
static void kb_wmi_brightness(enum led_brightness value)
|
||||||
|
{
|
||||||
S76_DEBUG("kb_wmi_brightness %d\n", (int)value);
|
S76_DEBUG("kb_wmi_brightness %d\n", (int)value);
|
||||||
|
|
||||||
kb_led_set(&kb_led, value);
|
kb_led_set(&kb_led, value);
|
||||||
led_classdev_notify_brightness_hw_changed(&kb_led, value);
|
led_classdev_notify_brightness_hw_changed(&kb_led, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_wmi_toggle(void) {
|
static void kb_wmi_toggle(void)
|
||||||
|
{
|
||||||
if (kb_led_brightness > 0) {
|
if (kb_led_brightness > 0) {
|
||||||
kb_led_toggle_brightness = kb_led_brightness;
|
kb_led_toggle_brightness = kb_led_brightness;
|
||||||
kb_wmi_brightness(LED_OFF);
|
kb_wmi_brightness(LED_OFF);
|
||||||
|
|
@ -292,7 +313,8 @@ static void kb_wmi_toggle(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_wmi_dec(void) {
|
static void kb_wmi_dec(void)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (kb_led_brightness > 0) {
|
if (kb_led_brightness > 0) {
|
||||||
|
|
@ -307,7 +329,8 @@ static void kb_wmi_dec(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_wmi_inc(void) {
|
static void kb_wmi_inc(void)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (kb_led_brightness > 0) {
|
if (kb_led_brightness > 0) {
|
||||||
|
|
@ -322,7 +345,8 @@ static void kb_wmi_inc(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kb_wmi_color(void) {
|
static void kb_wmi_color(void)
|
||||||
|
{
|
||||||
enum kb_led_region region;
|
enum kb_led_region region;
|
||||||
|
|
||||||
kb_led_colors_i += 1;
|
kb_led_colors_i += 1;
|
||||||
|
|
|
||||||
30
src/nv_hda.c
30
src/nv_hda.c
|
|
@ -26,8 +26,9 @@ static struct pci_dev *dis_dev;
|
||||||
static struct pci_dev *sub_dev = NULL;
|
static struct pci_dev *sub_dev = NULL;
|
||||||
|
|
||||||
// Returns 1 if the card is disabled, 0 if enabled
|
// Returns 1 if the card is disabled, 0 if enabled
|
||||||
static int is_card_disabled(void) {
|
static int is_card_disabled(void)
|
||||||
//check for: 1.bit is set 2.sub-function is available.
|
{
|
||||||
|
// check for: 1.bit is set 2.sub-function is available.
|
||||||
u32 cfg_word;
|
u32 cfg_word;
|
||||||
struct pci_dev *tmp_dev = NULL;
|
struct pci_dev *tmp_dev = NULL;
|
||||||
|
|
||||||
|
|
@ -36,7 +37,7 @@ static int is_card_disabled(void) {
|
||||||
// read config word at 0x488
|
// read config word at 0x488
|
||||||
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
||||||
if ((cfg_word & 0x2000000)==0x2000000) {
|
if ((cfg_word & 0x2000000)==0x2000000) {
|
||||||
//check for subdevice. read first config dword of sub function 1
|
// check for subdevice. read first config dword of sub function 1
|
||||||
while ((tmp_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, tmp_dev)) != NULL) {
|
while ((tmp_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, tmp_dev)) != NULL) {
|
||||||
int pci_class = tmp_dev->class >> 8;
|
int pci_class = tmp_dev->class >> 8;
|
||||||
|
|
||||||
|
|
@ -62,25 +63,27 @@ static int is_card_disabled(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nv_hda_off(void) {
|
static void nv_hda_off(void)
|
||||||
|
{
|
||||||
u32 cfg_word;
|
u32 cfg_word;
|
||||||
if (is_card_disabled()) {
|
if (is_card_disabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove device
|
// remove device
|
||||||
pci_dev_put(sub_dev);
|
pci_dev_put(sub_dev);
|
||||||
pci_stop_and_remove_bus_device(sub_dev);
|
pci_stop_and_remove_bus_device(sub_dev);
|
||||||
|
|
||||||
S76_INFO("NVIDIA audio: disabling\n");
|
S76_INFO("NVIDIA audio: disabling\n");
|
||||||
|
|
||||||
//setting bit to turn off
|
// setting bit to turn off
|
||||||
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
||||||
cfg_word&=0xfdffffff;
|
cfg_word&=0xfdffffff;
|
||||||
pci_write_config_dword(dis_dev, 0x488, cfg_word);
|
pci_write_config_dword(dis_dev, 0x488, cfg_word);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nv_hda_on(void) {
|
static void nv_hda_on(void)
|
||||||
|
{
|
||||||
u32 cfg_word;
|
u32 cfg_word;
|
||||||
u8 hdr_type;
|
u8 hdr_type;
|
||||||
|
|
||||||
|
|
@ -116,20 +119,23 @@ static void nv_hda_on(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* power bus so we can read PCI configuration space */
|
/* power bus so we can read PCI configuration space */
|
||||||
static void dis_dev_get(void) {
|
static void dis_dev_get(void)
|
||||||
|
{
|
||||||
if (dis_dev->bus && dis_dev->bus->self) {
|
if (dis_dev->bus && dis_dev->bus->self) {
|
||||||
pm_runtime_get_sync(&dis_dev->bus->self->dev);
|
pm_runtime_get_sync(&dis_dev->bus->self->dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dis_dev_put(void) {
|
static void dis_dev_put(void)
|
||||||
|
{
|
||||||
if (dis_dev->bus && dis_dev->bus->self) {
|
if (dis_dev->bus && dis_dev->bus->self) {
|
||||||
pm_runtime_put_sync(&dis_dev->bus->self->dev);
|
pm_runtime_put_sync(&dis_dev->bus->self->dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int __init nv_hda_init(struct device *dev) {
|
static int __init nv_hda_init(struct device *dev)
|
||||||
|
{
|
||||||
struct pci_dev *pdev = NULL;
|
struct pci_dev *pdev = NULL;
|
||||||
|
|
||||||
while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
|
while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
|
||||||
|
|
@ -161,7 +167,8 @@ static int __init nv_hda_init(struct device *dev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit nv_hda_exit(void) {
|
static void __exit nv_hda_exit(void)
|
||||||
|
{
|
||||||
if (dis_dev == NULL)
|
if (dis_dev == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -172,5 +179,4 @@ static void __exit nv_hda_exit(void) {
|
||||||
pr_info("NVIDIA Audio %s is %s\n", dev_name(&dis_dev->dev), is_card_disabled() ? "off" : "on");
|
pr_info("NVIDIA Audio %s is %s\n", dev_name(&dis_dev->dev), is_card_disabled() ? "off" : "on");
|
||||||
|
|
||||||
dis_dev_put();
|
dis_dev_put();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,8 @@ static uint64_t driver_flags = 0;
|
||||||
|
|
||||||
struct platform_device *s76_platform_device;
|
struct platform_device *s76_platform_device;
|
||||||
|
|
||||||
static int s76_wmbb(u32 method_id, u32 arg, u32 *retval) {
|
static int s76_wmbb(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 };
|
struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
|
||||||
union acpi_object *obj;
|
union acpi_object *obj;
|
||||||
|
|
@ -111,10 +112,11 @@ static int s76_wmbb(u32 method_id, u32 arg, u32 *retval) {
|
||||||
#include "nv_hda.c"
|
#include "nv_hda.c"
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,12,0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,12,0)
|
||||||
static void s76_wmi_notify(union acpi_object *obj, void *context) {
|
static void s76_wmi_notify(union acpi_object *obj, void *context)
|
||||||
#else
|
#else
|
||||||
static void s76_wmi_notify(u32 value, void *context) {
|
static void s76_wmi_notify(u32 value, void *context)
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
u32 event;
|
u32 event;
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,12,0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,12,0)
|
||||||
|
|
@ -183,7 +185,8 @@ static void s76_wmi_notify(u32 value, void *context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init s76_probe(struct platform_device *dev) {
|
static int __init s76_probe(struct platform_device *dev)
|
||||||
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (driver_flags & DRIVER_AP_LED) {
|
if (driver_flags & DRIVER_AP_LED) {
|
||||||
|
|
@ -236,10 +239,11 @@ static int __init s76_probe(struct platform_device *dev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,11,0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,11,0)
|
||||||
static void s76_remove(struct platform_device *dev) {
|
static void s76_remove(struct platform_device *dev)
|
||||||
#else
|
#else
|
||||||
static int s76_remove(struct platform_device *dev) {
|
static int s76_remove(struct platform_device *dev)
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
wmi_remove_notify_handler(S76_EVENT_GUID);
|
wmi_remove_notify_handler(S76_EVENT_GUID);
|
||||||
|
|
||||||
nv_hda_exit();
|
nv_hda_exit();
|
||||||
|
|
@ -263,7 +267,8 @@ static int s76_remove(struct platform_device *dev) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s76_suspend(struct platform_device *dev, pm_message_t status) {
|
static int s76_suspend(struct platform_device *dev, pm_message_t status)
|
||||||
|
{
|
||||||
S76_DEBUG("s76_suspend\n");
|
S76_DEBUG("s76_suspend\n");
|
||||||
|
|
||||||
if (driver_flags & DRIVER_KB_LED) {
|
if (driver_flags & DRIVER_KB_LED) {
|
||||||
|
|
@ -273,7 +278,8 @@ static int s76_suspend(struct platform_device *dev, pm_message_t status) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s76_resume(struct platform_device *dev) {
|
static int s76_resume(struct platform_device *dev)
|
||||||
|
{
|
||||||
S76_DEBUG("s76_resume\n");
|
S76_DEBUG("s76_resume\n");
|
||||||
|
|
||||||
msleep(2000);
|
msleep(2000);
|
||||||
|
|
@ -306,7 +312,8 @@ static struct platform_driver s76_platform_driver = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init s76_dmi_matched(const struct dmi_system_id *id) {
|
static int __init s76_dmi_matched(const struct dmi_system_id *id)
|
||||||
|
{
|
||||||
S76_INFO("Model %s found\n", id->ident);
|
S76_INFO("Model %s found\n", id->ident);
|
||||||
driver_flags = (uint64_t)id->driver_data;
|
driver_flags = (uint64_t)id->driver_data;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -366,7 +373,8 @@ static struct dmi_system_id s76_dmi_table[] __initdata = {
|
||||||
|
|
||||||
MODULE_DEVICE_TABLE(dmi, s76_dmi_table);
|
MODULE_DEVICE_TABLE(dmi, s76_dmi_table);
|
||||||
|
|
||||||
static int __init s76_init(void) {
|
static int __init s76_init(void)
|
||||||
|
{
|
||||||
if (!dmi_check_system(s76_dmi_table)) {
|
if (!dmi_check_system(s76_dmi_table)) {
|
||||||
S76_INFO("Model does not utilize this driver");
|
S76_INFO("Model does not utilize this driver");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
@ -397,7 +405,8 @@ static int __init s76_init(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit s76_exit(void) {
|
static void __exit s76_exit(void)
|
||||||
|
{
|
||||||
platform_device_unregister(s76_platform_device);
|
platform_device_unregister(s76_platform_device);
|
||||||
platform_driver_unregister(&s76_platform_driver);
|
platform_driver_unregister(&s76_platform_driver);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue