Format code
Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
parent
5ea0d7de14
commit
c81a34d0fc
57
src/ap-led.c
57
src/ap-led.c
|
|
@ -21,18 +21,20 @@ static enum led_brightness ap_led_brightness = 1;
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
ec_read(0xD9, &byte);
|
||||
|
||||
|
||||
if (value > 0) {
|
||||
ap_led_brightness = 1;
|
||||
|
||||
|
||||
if (ap_led_invert) {
|
||||
byte &= ~0x40;
|
||||
} else {
|
||||
|
|
@ -40,32 +42,34 @@ static int ap_led_set(struct led_classdev *led_cdev, enum led_brightness value)
|
|||
}
|
||||
} else {
|
||||
ap_led_brightness = 0;
|
||||
|
||||
|
||||
if (ap_led_invert) {
|
||||
byte |= 0x40;
|
||||
} else {
|
||||
byte &= ~0x40;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ec_write(0xD9, byte);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct led_classdev ap_led = {
|
||||
.name = "system76::airplane",
|
||||
.brightness_get = ap_led_get,
|
||||
.brightness_set_blocking = ap_led_set,
|
||||
.max_brightness = 1,
|
||||
.default_trigger = "rfkill-any"
|
||||
.name = "system76::airplane",
|
||||
.brightness_get = ap_led_get,
|
||||
.brightness_set_blocking = ap_led_set,
|
||||
.max_brightness = 1,
|
||||
.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);
|
||||
}
|
||||
|
||||
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;
|
||||
int ret;
|
||||
enum led_brightness brightness;
|
||||
|
|
@ -74,17 +78,17 @@ static ssize_t ap_led_invert_store(struct device *dev, struct device_attribute *
|
|||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
brightness = ap_led_get(&ap_led);
|
||||
|
||||
|
||||
if (val) {
|
||||
ap_led_invert = TRUE;
|
||||
} else {
|
||||
ap_led_invert = FALSE;
|
||||
}
|
||||
|
||||
|
||||
ap_led_set(&ap_led, brightness);
|
||||
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
@ -97,30 +101,33 @@ static struct device_attribute ap_led_invert_dev_attr = {
|
|||
.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);
|
||||
}
|
||||
|
||||
static int __init ap_led_init(struct device *dev) {
|
||||
static int __init ap_led_init(struct device *dev)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = led_classdev_register(dev, &ap_led);
|
||||
if (unlikely(err)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
if (device_create_file(ap_led.dev, &ap_led_invert_dev_attr) != 0) {
|
||||
S76_ERROR("failed to create ap_led_invert\n");
|
||||
}
|
||||
|
||||
|
||||
ap_led_resume();
|
||||
|
||||
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);
|
||||
|
||||
|
||||
if (!IS_ERR_OR_NULL(ap_led.dev)) {
|
||||
led_classdev_unregister(&ap_led);
|
||||
}
|
||||
|
|
|
|||
109
src/hwmon.c
109
src/hwmon.c
|
|
@ -22,14 +22,15 @@
|
|||
#define EXPERIMENTAL
|
||||
|
||||
#if S76_HAS_HWMON
|
||||
|
||||
struct s76_hwmon {
|
||||
struct device *dev;
|
||||
};
|
||||
|
||||
static struct s76_hwmon *s76_hwmon = NULL;
|
||||
|
||||
static int
|
||||
s76_read_fan(int idx) {
|
||||
static int s76_read_fan(int idx)
|
||||
{
|
||||
u8 value;
|
||||
int raw_rpm;
|
||||
ec_read(0xd0 + 0x2 * idx, &value);
|
||||
|
|
@ -41,43 +42,40 @@ s76_read_fan(int idx) {
|
|||
return 2156220 / raw_rpm;
|
||||
}
|
||||
|
||||
static int
|
||||
s76_read_pwm(int idx) {
|
||||
static int s76_read_pwm(int idx)
|
||||
{
|
||||
u8 value;
|
||||
ec_read(0xce + idx, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
static int
|
||||
s76_write_pwm(int idx, u8 duty) {
|
||||
static int s76_write_pwm(int idx, u8 duty)
|
||||
{
|
||||
u8 values[] = {idx + 1, duty};
|
||||
return ec_transaction(0x99, values, sizeof(values), NULL, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
s76_write_pwm_auto(int idx) {
|
||||
static int s76_write_pwm_auto(int idx)
|
||||
{
|
||||
u8 values[] = {0xff, idx + 1};
|
||||
return ec_transaction(0x99, values, sizeof(values), NULL, 0);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_show_name(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
static ssize_t s76_hwmon_show_name(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, S76_DRIVER_NAME "\n");
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_show_fan_input(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
static ssize_t s76_hwmon_show_fan_input(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int index = to_sensor_dev_attr(attr)->index;
|
||||
return sprintf(buf, "%i\n", s76_read_fan(index));
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_show_fan_label(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
static ssize_t s76_hwmon_show_fan_label(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
switch (to_sensor_dev_attr(attr)->index) {
|
||||
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 ssize_t
|
||||
s76_hwmon_show_pwm(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
static ssize_t s76_hwmon_show_pwm(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int index = to_sensor_dev_attr(attr)->index;
|
||||
return sprintf(buf, "%i\n", s76_read_pwm(index));
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_set_pwm(struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
static ssize_t s76_hwmon_set_pwm(struct device *dev,
|
||||
struct device_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
u32 value;
|
||||
int err;
|
||||
int index = to_sensor_dev_attr(attr)->index;
|
||||
|
||||
err = kstrtou32(buf, 10, &value);
|
||||
if (err) return err;
|
||||
if (value > 255) return -EINVAL;
|
||||
if (err)
|
||||
return err;
|
||||
if (value > 255)
|
||||
return -EINVAL;
|
||||
err = s76_write_pwm(index, value);
|
||||
if (err) return err;
|
||||
if (err)
|
||||
return err;
|
||||
pwm_enabled[index] = 1;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_show_pwm_enable(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
static ssize_t s76_hwmon_show_pwm_enable(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int index = to_sensor_dev_attr(attr)->index;
|
||||
return sprintf(buf, "%i\n", pwm_enabled[index]);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_set_pwm_enable(struct device *dev, struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
static ssize_t s76_hwmon_set_pwm_enable(struct device *dev,
|
||||
struct device_attribute *attr, const char *buf, size_t count)
|
||||
{
|
||||
u32 value;
|
||||
int err;
|
||||
int index = to_sensor_dev_attr(attr)->index;
|
||||
|
||||
err = kstrtou32(buf, 10, &value);
|
||||
if (err) return err;
|
||||
if (err)
|
||||
return err;
|
||||
if (value == 0) {
|
||||
err = s76_write_pwm(index, 255);
|
||||
if (err) return err;
|
||||
if (err)
|
||||
return err;
|
||||
pwm_enabled[index] = value;
|
||||
return count;
|
||||
}
|
||||
if (value == 1) {
|
||||
err = s76_write_pwm(index, 0);
|
||||
if (err) return err;
|
||||
if (err)
|
||||
return err;
|
||||
pwm_enabled[index] = value;
|
||||
return count;
|
||||
}
|
||||
if (value == 2) {
|
||||
err = s76_write_pwm_auto(index);
|
||||
if (err) return err;
|
||||
if (err)
|
||||
return err;
|
||||
pwm_enabled[index] = value;
|
||||
return count;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_show_temp1_input(struct device *dev, struct device_attribute *attr, char *buf) {
|
||||
static ssize_t s76_hwmon_show_temp1_input(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
u8 value;
|
||||
ec_read(0x07, &value);
|
||||
return sprintf(buf, "%i\n", value * 1000);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_show_temp1_label(struct device *dev, struct device_attribute *attr, char *buf) {
|
||||
static ssize_t s76_hwmon_show_temp1_label(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "CPU temperature\n");
|
||||
}
|
||||
|
||||
#ifdef EXPERIMENTAL
|
||||
static ssize_t
|
||||
s76_hwmon_show_temp2_input(struct device *dev, struct device_attribute *attr, char *buf) {
|
||||
static ssize_t s76_hwmon_show_temp2_input(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
u8 value;
|
||||
ec_read(0xcd, &value);
|
||||
return sprintf(buf, "%i\n", value * 1000);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
s76_hwmon_show_temp2_label(struct device *dev, struct device_attribute *attr, char *buf) {
|
||||
static ssize_t s76_hwmon_show_temp2_label(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "GPU temperature\n");
|
||||
}
|
||||
#endif
|
||||
|
|
@ -224,7 +229,8 @@ static const struct attribute_group hwmon_default_attrgroup = {
|
|||
};
|
||||
|
||||
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);
|
||||
#ifdef EXPERIMENTAL
|
||||
s76_write_pwm_auto(1);
|
||||
|
|
@ -236,8 +242,8 @@ static struct notifier_block s76_hwmon_reboot_notifier = {
|
|||
.notifier_call = s76_hwmon_reboot_callback
|
||||
};
|
||||
|
||||
static int
|
||||
s76_hwmon_init(struct device *dev) {
|
||||
static int s76_hwmon_init(struct device *dev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
s76_hwmon = kzalloc(sizeof(*s76_hwmon), GFP_KERNEL);
|
||||
|
|
@ -257,18 +263,18 @@ s76_hwmon_init(struct device *dev) {
|
|||
register_reboot_notifier(&s76_hwmon_reboot_notifier);
|
||||
s76_write_pwm_auto(0);
|
||||
#ifdef EXPERIMENTAL
|
||||
s76_write_pwm_auto(1);
|
||||
s76_write_pwm_auto(1);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
s76_hwmon_fini(struct device *dev) {
|
||||
static int s76_hwmon_fini(struct device *dev)
|
||||
{
|
||||
if (!s76_hwmon || !s76_hwmon->dev)
|
||||
return 0;
|
||||
s76_write_pwm_auto(0);
|
||||
#ifdef EXPERIMENTAL
|
||||
s76_write_pwm_auto(1);
|
||||
s76_write_pwm_auto(1);
|
||||
#endif
|
||||
unregister_reboot_notifier(&s76_hwmon_reboot_notifier);
|
||||
sysfs_remove_group(&s76_hwmon->dev->kobj, &hwmon_default_attrgroup);
|
||||
|
|
@ -276,4 +282,5 @@ s76_hwmon_fini(struct device *dev) {
|
|||
kfree(s76_hwmon);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#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 void s76_input_key(unsigned int code) {
|
||||
static void s76_input_key(unsigned int code)
|
||||
{
|
||||
S76_DEBUG("Send key %x\n", code);
|
||||
|
||||
mutex_lock(&s76_input_report_mutex);
|
||||
|
|
@ -70,7 +71,8 @@ static void s76_input_key(unsigned int code) {
|
|||
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",
|
||||
current->pid, param_poll_freq);
|
||||
|
||||
|
|
@ -94,19 +96,22 @@ static int s76_input_polling_thread(void *data) {
|
|||
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_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_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;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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))) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -135,7 +141,8 @@ static void s76_input_close(struct input_dev *dev) {
|
|||
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;
|
||||
u8 byte;
|
||||
|
||||
|
|
@ -176,7 +183,8 @@ err_free_input_device:
|
|||
return err;
|
||||
}
|
||||
|
||||
static void __exit s76_input_exit(void) {
|
||||
static void __exit s76_input_exit(void)
|
||||
{
|
||||
if (unlikely(!s76_input_device)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
80
src/kb-led.c
80
src/kb-led.c
|
|
@ -25,10 +25,10 @@ union kb_led_color {
|
|||
};
|
||||
|
||||
enum kb_led_region {
|
||||
KB_LED_REGION_LEFT,
|
||||
KB_LED_REGION_CENTER,
|
||||
KB_LED_REGION_RIGHT,
|
||||
KB_LED_REGION_EXTRA,
|
||||
KB_LED_REGION_LEFT,
|
||||
KB_LED_REGION_CENTER,
|
||||
KB_LED_REGION_RIGHT,
|
||||
KB_LED_REGION_EXTRA,
|
||||
};
|
||||
|
||||
static enum led_brightness kb_led_brightness = 0;
|
||||
|
|
@ -56,11 +56,13 @@ static union kb_led_color kb_led_colors[] = {
|
|||
{ .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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
int ret;
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -146,11 +153,13 @@ static struct device_attribute kb_led_color_left_dev_attr = {
|
|||
.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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -163,11 +172,13 @@ static struct device_attribute kb_led_color_center_dev_attr = {
|
|||
.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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -180,11 +191,13 @@ static struct device_attribute kb_led_color_right_dev_attr = {
|
|||
.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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -197,26 +210,30 @@ static struct device_attribute kb_led_color_extra_dev_attr = {
|
|||
.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_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_wmbb(SET_KB_LED, 0xE0003001, NULL);
|
||||
}
|
||||
|
||||
static void kb_led_suspend(void) {
|
||||
static void kb_led_suspend(void)
|
||||
{
|
||||
S76_DEBUG("kb_led_suspend\n");
|
||||
|
||||
// Disable keyboard backlight
|
||||
kb_led_disable();
|
||||
}
|
||||
|
||||
static void kb_led_resume(void) {
|
||||
static void kb_led_resume(void)
|
||||
{
|
||||
enum kb_led_region region;
|
||||
|
||||
S76_DEBUG("kb_led_resume\n");
|
||||
|
|
@ -236,7 +253,8 @@ static void kb_led_resume(void) {
|
|||
kb_led_enable();
|
||||
}
|
||||
|
||||
static int __init kb_led_init(struct device *dev) {
|
||||
static int __init kb_led_init(struct device *dev)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = led_classdev_register(dev, &kb_led);
|
||||
|
|
@ -265,7 +283,8 @@ static int __init kb_led_init(struct device *dev) {
|
|||
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_right_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);
|
||||
|
||||
kb_led_set(&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) {
|
||||
kb_led_toggle_brightness = kb_led_brightness;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
kb_led_colors_i += 1;
|
||||
|
|
|
|||
204
src/nv_hda.c
204
src/nv_hda.c
|
|
@ -17,160 +17,166 @@
|
|||
*/
|
||||
|
||||
enum {
|
||||
CARD_UNCHANGED = -1,
|
||||
CARD_OFF = 0,
|
||||
CARD_ON = 1,
|
||||
CARD_UNCHANGED = -1,
|
||||
CARD_OFF = 0,
|
||||
CARD_ON = 1,
|
||||
};
|
||||
|
||||
static struct pci_dev *dis_dev;
|
||||
static struct pci_dev *sub_dev = NULL;
|
||||
|
||||
// Returns 1 if the card is disabled, 0 if enabled
|
||||
static int is_card_disabled(void) {
|
||||
//check for: 1.bit is set 2.sub-function is available.
|
||||
u32 cfg_word;
|
||||
struct pci_dev *tmp_dev = NULL;
|
||||
static int is_card_disabled(void)
|
||||
{
|
||||
// check for: 1.bit is set 2.sub-function is available.
|
||||
u32 cfg_word;
|
||||
struct pci_dev *tmp_dev = NULL;
|
||||
|
||||
sub_dev = NULL;
|
||||
sub_dev = NULL;
|
||||
|
||||
// read config word at 0x488
|
||||
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
||||
if ((cfg_word & 0x2000000)==0x2000000) {
|
||||
//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) {
|
||||
int pci_class = tmp_dev->class >> 8;
|
||||
// read config word at 0x488
|
||||
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
||||
if ((cfg_word & 0x2000000)==0x2000000) {
|
||||
// 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) {
|
||||
int pci_class = tmp_dev->class >> 8;
|
||||
|
||||
if (pci_class != 0x403)
|
||||
continue;
|
||||
if (pci_class != 0x403)
|
||||
continue;
|
||||
|
||||
if (tmp_dev->vendor == PCI_VENDOR_ID_NVIDIA) {
|
||||
sub_dev = tmp_dev;
|
||||
S76_INFO("Found NVIDIA audio device %s\n", dev_name(&tmp_dev->dev));
|
||||
}
|
||||
}
|
||||
if (tmp_dev->vendor == PCI_VENDOR_ID_NVIDIA) {
|
||||
sub_dev = tmp_dev;
|
||||
S76_INFO("Found NVIDIA audio device %s\n", dev_name(&tmp_dev->dev));
|
||||
}
|
||||
}
|
||||
|
||||
if (sub_dev == NULL) {
|
||||
S76_INFO("No NVIDIA audio device found, unsetting config bit.\n");
|
||||
cfg_word|=0x2000000;
|
||||
pci_write_config_dword(dis_dev, 0x488, cfg_word);
|
||||
return 1;
|
||||
}
|
||||
if (sub_dev == NULL) {
|
||||
S76_INFO("No NVIDIA audio device found, unsetting config bit.\n");
|
||||
cfg_word|=0x2000000;
|
||||
pci_write_config_dword(dis_dev, 0x488, cfg_word);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void nv_hda_off(void) {
|
||||
u32 cfg_word;
|
||||
if (is_card_disabled()) {
|
||||
return;
|
||||
}
|
||||
static void nv_hda_off(void)
|
||||
{
|
||||
u32 cfg_word;
|
||||
if (is_card_disabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//remove device
|
||||
pci_dev_put(sub_dev);
|
||||
pci_stop_and_remove_bus_device(sub_dev);
|
||||
// remove device
|
||||
pci_dev_put(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
|
||||
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
||||
cfg_word&=0xfdffffff;
|
||||
pci_write_config_dword(dis_dev, 0x488, cfg_word);
|
||||
// setting bit to turn off
|
||||
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
||||
cfg_word&=0xfdffffff;
|
||||
pci_write_config_dword(dis_dev, 0x488, cfg_word);
|
||||
}
|
||||
|
||||
static void nv_hda_on(void) {
|
||||
u32 cfg_word;
|
||||
u8 hdr_type;
|
||||
static void nv_hda_on(void)
|
||||
{
|
||||
u32 cfg_word;
|
||||
u8 hdr_type;
|
||||
|
||||
if (!is_card_disabled()) {
|
||||
return;
|
||||
}
|
||||
if (!is_card_disabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
S76_INFO("NVIDIA audio: enabling\n");
|
||||
S76_INFO("NVIDIA audio: enabling\n");
|
||||
|
||||
// read,set bit, write config word at 0x488
|
||||
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
||||
cfg_word|=0x2000000;
|
||||
pci_write_config_dword(dis_dev, 0x488, cfg_word);
|
||||
// read,set bit, write config word at 0x488
|
||||
pci_read_config_dword(dis_dev, 0x488, &cfg_word);
|
||||
cfg_word|=0x2000000;
|
||||
pci_write_config_dword(dis_dev, 0x488, cfg_word);
|
||||
|
||||
//pci_scan_single_device
|
||||
//pci_scan_single_device
|
||||
pci_read_config_byte(dis_dev, PCI_HEADER_TYPE, &hdr_type);
|
||||
|
||||
if (!(hdr_type & 0x80)) {
|
||||
S76_ERROR("NVIDIA not multifunction, no audio\n");
|
||||
S76_ERROR("NVIDIA not multifunction, no audio\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sub_dev = pci_scan_single_device(dis_dev->bus, 1);
|
||||
if (!sub_dev) {
|
||||
S76_ERROR("No NVIDIA audio device found\n");
|
||||
S76_ERROR("No NVIDIA audio device found\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
S76_INFO("NVIDIA audio found, adding\n");
|
||||
S76_INFO("NVIDIA audio found, adding\n");
|
||||
pci_assign_unassigned_bus_resources(dis_dev->bus);
|
||||
pci_bus_add_devices(dis_dev->bus);
|
||||
pci_dev_get(sub_dev);
|
||||
pci_dev_get(sub_dev);
|
||||
}
|
||||
|
||||
/* power bus so we can read PCI configuration space */
|
||||
static void dis_dev_get(void) {
|
||||
if (dis_dev->bus && dis_dev->bus->self) {
|
||||
pm_runtime_get_sync(&dis_dev->bus->self->dev);
|
||||
}
|
||||
static void dis_dev_get(void)
|
||||
{
|
||||
if (dis_dev->bus && dis_dev->bus->self) {
|
||||
pm_runtime_get_sync(&dis_dev->bus->self->dev);
|
||||
}
|
||||
}
|
||||
|
||||
static void dis_dev_put(void) {
|
||||
if (dis_dev->bus && dis_dev->bus->self) {
|
||||
pm_runtime_put_sync(&dis_dev->bus->self->dev);
|
||||
}
|
||||
static void dis_dev_put(void)
|
||||
{
|
||||
if (dis_dev->bus && dis_dev->bus->self) {
|
||||
pm_runtime_put_sync(&dis_dev->bus->self->dev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int __init nv_hda_init(struct device *dev) {
|
||||
struct pci_dev *pdev = NULL;
|
||||
static int __init nv_hda_init(struct device *dev)
|
||||
{
|
||||
struct pci_dev *pdev = NULL;
|
||||
|
||||
while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
|
||||
int pci_class = pdev->class >> 8;
|
||||
while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
|
||||
int pci_class = pdev->class >> 8;
|
||||
|
||||
if (pci_class != PCI_CLASS_DISPLAY_VGA && pci_class != PCI_CLASS_DISPLAY_3D) {
|
||||
continue;
|
||||
}
|
||||
if (pci_class != PCI_CLASS_DISPLAY_VGA && pci_class != PCI_CLASS_DISPLAY_3D) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pdev->vendor == PCI_VENDOR_ID_NVIDIA) {
|
||||
dis_dev = pdev;
|
||||
S76_INFO("NVIDIA device %s\n", dev_name(&pdev->dev));
|
||||
}
|
||||
}
|
||||
if (pdev->vendor == PCI_VENDOR_ID_NVIDIA) {
|
||||
dis_dev = pdev;
|
||||
S76_INFO("NVIDIA device %s\n", dev_name(&pdev->dev));
|
||||
}
|
||||
}
|
||||
|
||||
if (dis_dev == NULL) {
|
||||
S76_ERROR("No NVIDIA device found\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
if (dis_dev == NULL) {
|
||||
S76_ERROR("No NVIDIA device found\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
dis_dev_get();
|
||||
dis_dev_get();
|
||||
|
||||
nv_hda_on();
|
||||
nv_hda_on();
|
||||
|
||||
S76_INFO("NVIDIA Audio %s is %s\n", dev_name(&dis_dev->dev), is_card_disabled() ? "off" : "on");
|
||||
S76_INFO("NVIDIA Audio %s is %s\n", dev_name(&dis_dev->dev), is_card_disabled() ? "off" : "on");
|
||||
|
||||
dis_dev_put();
|
||||
dis_dev_put();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit nv_hda_exit(void) {
|
||||
if (dis_dev == NULL)
|
||||
return;
|
||||
static void __exit nv_hda_exit(void)
|
||||
{
|
||||
if (dis_dev == NULL)
|
||||
return;
|
||||
|
||||
dis_dev_get();
|
||||
dis_dev_get();
|
||||
|
||||
nv_hda_off();
|
||||
nv_hda_off();
|
||||
|
||||
pr_info("NVIDIA Audio %s is %s\n", dev_name(&dis_dev->dev), is_card_disabled() ? "off" : "on");
|
||||
|
||||
dis_dev_put();
|
||||
pr_info("NVIDIA Audio %s is %s\n", dev_name(&dis_dev->dev), is_card_disabled() ? "off" : "on");
|
||||
|
||||
dis_dev_put();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ static uint64_t driver_flags = 0;
|
|||
|
||||
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 out = { ACPI_ALLOCATE_BUFFER, NULL };
|
||||
union acpi_object *obj;
|
||||
|
|
@ -111,10 +112,11 @@ static int s76_wmbb(u32 method_id, u32 arg, u32 *retval) {
|
|||
#include "nv_hda.c"
|
||||
|
||||
#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
|
||||
static void s76_wmi_notify(u32 value, void *context) {
|
||||
static void s76_wmi_notify(u32 value, void *context)
|
||||
#endif
|
||||
{
|
||||
u32 event;
|
||||
|
||||
#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;
|
||||
|
||||
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)
|
||||
static void s76_remove(struct platform_device *dev) {
|
||||
static void s76_remove(struct platform_device *dev)
|
||||
#else
|
||||
static int s76_remove(struct platform_device *dev) {
|
||||
static int s76_remove(struct platform_device *dev)
|
||||
#endif
|
||||
{
|
||||
wmi_remove_notify_handler(S76_EVENT_GUID);
|
||||
|
||||
nv_hda_exit();
|
||||
|
|
@ -263,7 +267,8 @@ static int s76_remove(struct platform_device *dev) {
|
|||
#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");
|
||||
|
||||
if (driver_flags & DRIVER_KB_LED) {
|
||||
|
|
@ -273,7 +278,8 @@ static int s76_suspend(struct platform_device *dev, pm_message_t status) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int s76_resume(struct platform_device *dev) {
|
||||
static int s76_resume(struct platform_device *dev)
|
||||
{
|
||||
S76_DEBUG("s76_resume\n");
|
||||
|
||||
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);
|
||||
driver_flags = (uint64_t)id->driver_data;
|
||||
return 1;
|
||||
|
|
@ -366,7 +373,8 @@ static struct dmi_system_id s76_dmi_table[] __initdata = {
|
|||
|
||||
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)) {
|
||||
S76_INFO("Model does not utilize this driver");
|
||||
return -ENODEV;
|
||||
|
|
@ -397,7 +405,8 @@ static int __init s76_init(void) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void __exit s76_exit(void) {
|
||||
static void __exit s76_exit(void)
|
||||
{
|
||||
platform_device_unregister(s76_platform_device);
|
||||
platform_driver_unregister(&s76_platform_driver);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue