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

Commit ea621d9f authored by Darren Hart (VMware)'s avatar Darren Hart (VMware)
Browse files

platform/x86: hp-wmi: Refactor redundant HPWMI_READ functions



Several functions perform the same WMI read int with different query
arguments. Refactor this into a single hp_wmi_read_int function.

Signed-off-by: default avatarDarren Hart (VMware) <dvhart@infradead.org>
Tested-by: default avatarCarlo Caione <carlo@endlessm.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
parent d8193cff
Loading
Loading
Loading
Loading
+24 −58
Original line number Diff line number Diff line
@@ -258,55 +258,35 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command,
	return 0;
}

static int hp_wmi_display_state(void)
static int hp_wmi_read_int(int query)
{
	int state = 0;
	int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, HPWMI_READ, &state,
				       sizeof(state), sizeof(state));
	if (ret)
		return ret < 0 ? ret : -EINVAL;
	return state;
}
	int val = 0, ret;

static int hp_wmi_hddtemp_state(void)
{
	int state = 0;
	int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, HPWMI_READ, &state,
				       sizeof(state), sizeof(state));
	if (ret)
		return ret < 0 ? ret : -EINVAL;
	return state;
}
	ret = hp_wmi_perform_query(query, HPWMI_READ, &val,
				   sizeof(val), sizeof(val));

static int hp_wmi_als_state(void)
{
	int state = 0;
	int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_READ, &state,
				       sizeof(state), sizeof(state));
	if (ret)
		return ret < 0 ? ret : -EINVAL;
	return state;

	return val;
}

static int hp_wmi_dock_state(void)
{
	int state = 0;
	int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, HPWMI_READ, &state,
				       sizeof(state), sizeof(state));
	int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY);

	if (ret)
		return ret < 0 ? ret : -EINVAL;
	if (state < 0)
		return state;

	return state & 0x1;
}

static int hp_wmi_tablet_state(void)
{
	int state = 0;
	int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, HPWMI_READ, &state,
				       sizeof(state), sizeof(state));
	if (ret)
		return ret < 0 ? ret : -EINVAL;
	int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY);

	if (state < 0)
		return state;

	return (state & 0x4) ? 1 : 0;
}
@@ -436,20 +416,10 @@ static int hp_wmi_rfkill2_refresh(void)
	return 0;
}

static int hp_wmi_post_code_state(void)
{
	int state = 0;
	int ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, HPWMI_READ, &state,
				       sizeof(state), sizeof(state));
	if (ret)
		return ret < 0 ? ret : -EINVAL;
	return state;
}

static ssize_t show_display(struct device *dev, struct device_attribute *attr,
			    char *buf)
{
	int value = hp_wmi_display_state();
	int value = hp_wmi_read_int(HPWMI_DISPLAY_QUERY);
	if (value < 0)
		return -EINVAL;
	return sprintf(buf, "%d\n", value);
@@ -458,7 +428,7 @@ static ssize_t show_display(struct device *dev, struct device_attribute *attr,
static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
			    char *buf)
{
	int value = hp_wmi_hddtemp_state();
	int value = hp_wmi_read_int(HPWMI_HDDTEMP_QUERY);
	if (value < 0)
		return -EINVAL;
	return sprintf(buf, "%d\n", value);
@@ -467,7 +437,7 @@ static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
static ssize_t show_als(struct device *dev, struct device_attribute *attr,
			char *buf)
{
	int value = hp_wmi_als_state();
	int value = hp_wmi_read_int(HPWMI_ALS_QUERY);
	if (value < 0)
		return -EINVAL;
	return sprintf(buf, "%d\n", value);
@@ -495,7 +465,7 @@ static ssize_t show_postcode(struct device *dev, struct device_attribute *attr,
			 char *buf)
{
	/* Get the POST error code of previous boot failure. */
	int value = hp_wmi_post_code_state();
	int value = hp_wmi_read_int(HPWMI_POSTCODEERROR_QUERY);
	if (value < 0)
		return -EINVAL;
	return sprintf(buf, "0x%x\n", value);
@@ -546,9 +516,9 @@ static void hp_wmi_notify(u32 value, void *context)
	struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
	u32 event_id, event_data;
	union acpi_object *obj;
	int key_code = 0, ret;
	acpi_status status;
	u32 *location;
	int key_code;

	status = wmi_get_event_data(value, &response);
	if (status != AE_OK) {
@@ -599,11 +569,8 @@ static void hp_wmi_notify(u32 value, void *context)
	case HPWMI_SMART_ADAPTER:
		break;
	case HPWMI_BEZEL_BUTTON:
		ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, HPWMI_READ,
					   &key_code,
					   sizeof(key_code),
					   sizeof(key_code));
		if (ret)
		key_code = hp_wmi_read_int(HPWMI_HOTKEY_QUERY);
		if (key_code < 0)
			break;

		if (!sparse_keymap_report_event(hp_wmi_input_dev,
@@ -732,12 +699,11 @@ static void cleanup_sysfs(struct platform_device *device)

static int __init hp_wmi_rfkill_setup(struct platform_device *device)
{
	int err, wireless = 0;
	int err, wireless;

	err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_READ, &wireless,
				   sizeof(wireless), sizeof(wireless));
	if (err)
		return err;
	wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY);
	if (wireless)
		return wireless;

	err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_WRITE, &wireless,
				   sizeof(wireless), 0);