struct mutex battery_lock; /* Protects the list of currently registered batteries */
bool last_fn_lock_state;
bool last_super_key_enable_state;
+ bool last_touchpad_toggle_enable_state;
struct mutex super_key_lock; /* Protects the toggling of the super key lock state */
struct list_head batteries;
struct mutex led_lock; /* Protects writes to the lightbar registers */
case EC_ADDR_PWM_2:
case EC_ADDR_TRIGGER:
case EC_ADDR_SWITCH_STATUS:
+ case EC_ADDR_OEM_4:
case EC_ADDR_CHARGE_CTRL:
case EC_ADDR_USB_C_POWER_PRIORITY:
return true;
static DEVICE_ATTR_RW(super_key_enable);
+static int uniwill_write_touchpad_toggle_enable(struct uniwill_data *data, bool status)
+{
+ unsigned int value;
+
+ if (status)
+ value = 0;
+ else
+ value = TOUCHPAD_TOGGLE_OFF;
+
+ return regmap_update_bits(data->regmap, EC_ADDR_OEM_4, TOUCHPAD_TOGGLE_OFF, value);
+}
+
static ssize_t touchpad_toggle_enable_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct uniwill_data *data = dev_get_drvdata(dev);
- unsigned int value;
bool enable;
int ret;
if (ret < 0)
return ret;
- if (enable)
- value = 0;
- else
- value = TOUCHPAD_TOGGLE_OFF;
-
- ret = regmap_update_bits(data->regmap, EC_ADDR_OEM_4, TOUCHPAD_TOGGLE_OFF, value);
+ ret = uniwill_write_touchpad_toggle_enable(data, enable);
if (ret < 0)
return ret;
return count;
}
+static int uniwill_read_touchpad_toggle_enable(struct uniwill_data *data, bool *status)
+{
+ unsigned int value;
+ int ret;
+
+ ret = regmap_read(data->regmap, EC_ADDR_OEM_4, &value);
+ if (ret < 0)
+ return ret;
+
+ *status = !(value & TOUCHPAD_TOGGLE_OFF);
+
+ return 0;
+}
+
static ssize_t touchpad_toggle_enable_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct uniwill_data *data = dev_get_drvdata(dev);
- unsigned int value;
+ bool status;
int ret;
- ret = regmap_read(data->regmap, EC_ADDR_OEM_4, &value);
+ ret = uniwill_read_touchpad_toggle_enable(data, &status);
if (ret < 0)
return ret;
- return sysfs_emit(buf, "%d\n", !(value & TOUCHPAD_TOGGLE_OFF));
+ return sysfs_emit(buf, "%d\n", status);
}
static DEVICE_ATTR_RW(touchpad_toggle_enable);
return uniwill_read_super_key_enable(data, &data->last_super_key_enable_state);
}
+static int uniwill_suspend_touchpad_toggle(struct uniwill_data *data)
+{
+ if (!uniwill_device_supports(data, UNIWILL_FEATURE_TOUCHPAD_TOGGLE))
+ return 0;
+
+ /*
+ * EC_ADDR_OEM_4 is marked as volatile, so we have to restore it
+ * ourselves.
+ */
+ return uniwill_read_touchpad_toggle_enable(data, &data->last_touchpad_toggle_enable_state);
+}
+
static int uniwill_suspend_battery(struct uniwill_data *data)
{
if (!uniwill_device_supports(data, UNIWILL_FEATURE_BATTERY))
if (ret < 0)
return ret;
+ ret = uniwill_suspend_touchpad_toggle(data);
+ if (ret < 0)
+ return ret;
+
ret = uniwill_suspend_battery(data);
if (ret < 0)
return ret;
return uniwill_write_super_key_enable(data, data->last_super_key_enable_state);
}
+static int uniwill_resume_touchpad_toggle(struct uniwill_data *data)
+{
+ if (!uniwill_device_supports(data, UNIWILL_FEATURE_TOUCHPAD_TOGGLE))
+ return 0;
+
+ return uniwill_write_touchpad_toggle_enable(data, data->last_touchpad_toggle_enable_state);
+}
+
static int uniwill_resume_battery(struct uniwill_data *data)
{
if (!uniwill_device_supports(data, UNIWILL_FEATURE_BATTERY))
if (ret < 0)
return ret;
+ ret = uniwill_resume_touchpad_toggle(data);
+ if (ret < 0)
+ return ret;
+
ret = uniwill_resume_battery(data);
if (ret < 0)
return ret;