Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d8658ac authored by Azael Avalos's avatar Azael Avalos Committed by Matthew Garrett
Browse files

toshiba_acpi: Add touchpad enable/disable support-



Toshiba laptops have two ways of letting userspace
know the touchpad has changed state, one with a
button on top of the touchpad that simply emmits
scancodes whenever enabled/disabled, and another one
by pressing Fn-F9 (touchpad toggle) hotkey.

This patch adds support to enable/disable the touchpad
by exposing the _touchpad_ file in sysfs that simply
makes a call to a SCI register, imitating what
Toshiba provided software does on Windows.

Signed-off-by: default avatarAzael Avalos <coproscefalo@gmail.com>
Signed-off-by: default avatarMatthew Garrett <matthew.garrett@nebula.com>
parent 360f0f39
Loading
Loading
Loading
Loading
+81 −0
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ MODULE_LICENSE("GPL");
#define HCI_KBD_ILLUMINATION		0x0095
#define SCI_ILLUMINATION		0x014e
#define SCI_KBD_ILLUM_STATUS		0x015c
#define SCI_TOUCHPAD			0x050e

/* field definitions */
#define HCI_HOTKEY_DISABLE		0x0b
@@ -157,6 +158,7 @@ struct toshiba_acpi_dev {
	unsigned int tr_backlight_supported:1;
	unsigned int kbd_illum_supported:1;
	unsigned int kbd_led_registered:1;
	unsigned int touchpad_supported:1;
	unsigned int sysfs_created:1;

	struct mutex mutex;
@@ -528,6 +530,47 @@ static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
	}
}
 
/* TouchPad support */
static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
{
	u32 result;
	acpi_status status;

	if (!sci_open(dev))
		return -EIO;

	status = sci_write(dev, SCI_TOUCHPAD, state, &result);
	sci_close(dev);
	if (ACPI_FAILURE(status)) {
		pr_err("ACPI call to set the touchpad failed\n");
		return -EIO;
	} else if (result == HCI_NOT_SUPPORTED) {
		return -ENODEV;
	}

	return 0;
}

static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
{
	u32 result;
	acpi_status status;

	if (!sci_open(dev))
		return -EIO;

	status = sci_read(dev, SCI_TOUCHPAD, state, &result);
	sci_close(dev);
	if (ACPI_FAILURE(status)) {
		pr_err("ACPI call to query the touchpad failed\n");
		return -EIO;
	} else if (result == HCI_NOT_SUPPORTED) {
		return -ENODEV;
	}

	return 0;
}

/* Bluetooth rfkill handlers */

static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1131,14 +1174,47 @@ static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
	return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
}
 
static ssize_t toshiba_touchpad_store(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf, size_t count)
{
	struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
	int state;

	/* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
	if (sscanf(buf, "%i", &state) == 1 && (state == 0 || state == 1)) {
		if (toshiba_touchpad_set(toshiba, state) < 0)
			return -EIO;
	}

	return count;
}

static ssize_t toshiba_touchpad_show(struct device *dev,
				     struct device_attribute *attr, char *buf)
{
	struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
	u32 state;
	int ret;

	ret = toshiba_touchpad_get(toshiba, &state);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%i\n", state);
}

static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
		   toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
		   toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
		   toshiba_touchpad_show, toshiba_touchpad_store);

static struct attribute *toshiba_attributes[] = {
	&dev_attr_kbd_backlight_mode.attr,
	&dev_attr_kbd_backlight_timeout.attr,
	&dev_attr_touchpad.attr,
	NULL,
};

@@ -1153,6 +1229,8 @@ static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
		exists = (drv->kbd_illum_supported) ? true : false;
	else if (attr == &dev_attr_kbd_backlight_timeout.attr)
		exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
	else if (attr == &dev_attr_touchpad.attr)
		exists = (drv->touchpad_supported) ? true : false;

	return exists ? attr->mode : 0;
}
@@ -1497,6 +1575,9 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
			dev->kbd_led_registered = 1;
	}
 
	ret = toshiba_touchpad_get(dev, &dummy);
	dev->touchpad_supported = !ret;

	/* Determine whether or not BIOS supports fan and video interfaces */

	ret = get_video_status(dev, &dummy);