Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ This driver exports a few files in its own platform device, msi-ec, and is avail
- on: cooler boost function is enabled
- off: cooler boost function is disabled

- `/sys/devices/platform/msi-ec/usb_powershare`
- Description: This entry allows enabling the usb powershare function. It provides power to charge devices via USB ports while device is suspended.
- Access: Read, Write
- Valid values:
- on: usb powershare function is enabled
- off: usb powershare function is disabled

- `/sys/devices/platform/msi-ec/available_shift_modes`
- Description: This entry reports all supported shift modes.
- Access: Read
Expand Down
6 changes: 6 additions & 0 deletions docs/sysfs-platform-msi-ec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Description:
to the maximum speed for quicker cooling.
Valid values: "on", "off".

What: /sys/devices/platform/<platform>/usb_powershare
Description:
Control the usb powershare feature. This feature enables
usb charging while device is suspended or powered off.
Valid values: "on", "off".

What: /sys/devices/platform/<platform>/available_shift_modes
Description:
Read-only, shows the list of available shift modes for
Expand Down
6 changes: 6 additions & 0 deletions ec_memory_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ struct msi_ec_cooler_boost_conf {
int bit;
};

struct msi_ec_usb_powershare_conf {
int address;
int bit;
};

#define MSI_EC_MODE_NULL { NULL, 0 }
struct msi_ec_mode {
const char *name;
Expand Down Expand Up @@ -89,6 +94,7 @@ struct msi_ec_conf {
struct msi_ec_webcam_conf webcam;
struct msi_ec_fn_win_swap_conf fn_win_swap;
struct msi_ec_cooler_boost_conf cooler_boost;
struct msi_ec_usb_powershare_conf usb_powershare;
struct msi_ec_shift_mode_conf shift_mode;
struct msi_ec_super_battery_conf super_battery;
struct msi_ec_fan_mode_conf fan_mode;
Expand Down
120 changes: 120 additions & 0 deletions msi-ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ static struct msi_ec_conf CONF_G1_0 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -157,6 +161,10 @@ static struct msi_ec_conf CONF_G1_1 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -228,6 +236,10 @@ static struct msi_ec_conf CONF_G1_2 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -308,6 +320,10 @@ static struct msi_ec_conf CONF_G1_3 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -378,6 +394,10 @@ static struct msi_ec_conf CONF_G1_4 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -451,6 +471,10 @@ static struct msi_ec_conf CONF_G1_5 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -528,6 +552,10 @@ static struct msi_ec_conf CONF_G1_6 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -609,6 +637,10 @@ static struct msi_ec_conf CONF_G1_7 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -678,6 +710,10 @@ static struct msi_ec_conf CONF_G1_8 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -747,6 +783,10 @@ static struct msi_ec_conf CONF_G1_9 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -814,6 +854,10 @@ static struct msi_ec_conf CONF_G1_10 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -887,6 +931,10 @@ static struct msi_ec_conf CONF_G1_11 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -954,6 +1002,10 @@ static struct msi_ec_conf CONF_G1_13 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xf2,
.modes = {
Expand Down Expand Up @@ -1034,6 +1086,10 @@ static struct msi_ec_conf CONF_G2_0 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xd2,
.modes = {
Expand Down Expand Up @@ -1149,6 +1205,10 @@ static struct msi_ec_conf CONF_G2_1 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xd2,
.modes = {
Expand Down Expand Up @@ -1234,6 +1294,10 @@ static struct msi_ec_conf CONF_G2_2 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xd2,
.modes = {
Expand Down Expand Up @@ -1320,6 +1384,10 @@ static struct msi_ec_conf CONF_G2_3 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = 0xbf,
.bit = 5,
},
.shift_mode = {
.address = 0xd2,
.modes = {
Expand Down Expand Up @@ -1388,6 +1456,10 @@ static struct msi_ec_conf CONF_G2_4 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xd2,
.modes = {
Expand Down Expand Up @@ -1458,6 +1530,10 @@ static struct msi_ec_conf CONF_G2_5 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xd2,
.modes = {
Expand Down Expand Up @@ -1539,6 +1615,10 @@ static struct msi_ec_conf CONF_G2_6 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xd2,
.modes = {
Expand Down Expand Up @@ -1657,6 +1737,10 @@ static struct msi_ec_conf CONF_G2_10 __initdata = {
.address = 0x98,
.bit = 7,
},
.usb_powershare = {
.address = MSI_EC_ADDR_UNKNOWN,
.bit = 5,
},
.shift_mode = {
.address = 0xd2,
.modes = {
Expand Down Expand Up @@ -2194,6 +2278,37 @@ static ssize_t cooler_boost_store(struct device *dev,
return count;
}

static ssize_t usb_powershare_show(struct device *device,
struct device_attribute *attr, char *buf)
{
int result;
bool value;

result = ec_check_bit(conf.usb_powershare.address, conf.usb_powershare.bit, &value);
if (result < 0)
return result;

return sysfs_emit(buf, "%s\n", str_on_off(value));
}

static ssize_t usb_powershare_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
int result;
bool value;

result = kstrtobool(buf, &value);
if (result)
return result;

result = ec_set_bit(conf.usb_powershare.address, conf.usb_powershare.bit, value);
if (result < 0)
return result;

return count;
}

static ssize_t available_shift_modes_show(struct device *device,
struct device_attribute *attr,
char *buf)
Expand Down Expand Up @@ -2413,6 +2528,7 @@ static DEVICE_ATTR_RW(webcam_block);
static DEVICE_ATTR_RW(fn_key);
static DEVICE_ATTR_RW(win_key);
static DEVICE_ATTR_RW(cooler_boost);
static DEVICE_ATTR_RW(usb_powershare);
static DEVICE_ATTR_RO(available_shift_modes);
static DEVICE_ATTR_RW(shift_mode);
static DEVICE_ATTR_RW(super_battery);
Expand All @@ -2427,6 +2543,7 @@ static struct attribute *msi_root_attrs[] = {
&dev_attr_fn_key.attr,
&dev_attr_win_key.attr,
&dev_attr_cooler_boost.attr,
&dev_attr_usb_powershare.attr,
&dev_attr_available_shift_modes.attr,
&dev_attr_shift_mode.attr,
&dev_attr_super_battery.attr,
Expand Down Expand Up @@ -2774,6 +2891,9 @@ static umode_t msi_ec_is_visible(struct kobject *kobj,
else if (attr == &dev_attr_cooler_boost.attr)
address = conf.cooler_boost.address;

else if (attr == &dev_attr_usb_powershare.attr)
address = conf.usb_powershare.address;

else if (attr == &dev_attr_available_shift_modes.attr ||
attr == &dev_attr_shift_mode.attr)
address = conf.shift_mode.address;
Expand Down