drivers/platform/x86/inspur_platform_profile.c

Source file repositories/reference/linux-study-clean/drivers/platform/x86/inspur_platform_profile.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/x86/inspur_platform_profile.c
Extension
.c
Size
5206 bytes
Lines
221
Domain
Driver Families
Bucket
drivers/platform
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct inspur_wmi_priv {
	struct wmi_device *wdev;
	struct device *ppdev;
};

static int inspur_wmi_perform_query(struct wmi_device *wdev,
				    enum inspur_wmi_method_ids query_id,
				    void *buffer, size_t insize,
				    size_t outsize)
{
	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
	struct acpi_buffer input = { insize, buffer};
	union acpi_object *obj;
	acpi_status status;
	int ret = 0;

	status = wmidev_evaluate_method(wdev, 0, query_id, &input, &output);
	if (ACPI_FAILURE(status)) {
		dev_err(&wdev->dev, "EC Powermode control failed: %s\n",
			acpi_format_exception(status));
		return -EIO;
	}

	obj = output.pointer;
	if (!obj)
		return -EINVAL;

	if (obj->type != ACPI_TYPE_BUFFER ||
	    obj->buffer.length != outsize) {
		ret = -EINVAL;
		goto out_free;
	}

	memcpy(buffer, obj->buffer.pointer, obj->buffer.length);

out_free:
	kfree(obj);
	return ret;
}

/*
 * Set Power Mode to EC RAM. If Power Mode value greater than 0x3,
 * return error
 * Method ID: 0x3
 * Arg: 4 Bytes
 * Byte [0]: Power Mode:
 *         0x0: Balance Mode
 *         0x1: Performance Mode
 *         0x2: Power Saver Mode
 * Return Value: 4 Bytes
 * Byte [0]: Return Code
 *         0x0: No Error
 *         0x1: Error
 */
static int inspur_platform_profile_set(struct device *dev,
				       enum platform_profile_option profile)
{
	struct inspur_wmi_priv *priv = dev_get_drvdata(dev);
	u8 ret_code[4] = {0, 0, 0, 0};
	int ret;

	switch (profile) {
	case PLATFORM_PROFILE_BALANCED:
		ret_code[0] = INSPUR_TMP_PROFILE_BALANCE;
		break;
	case PLATFORM_PROFILE_PERFORMANCE:
		ret_code[0] = INSPUR_TMP_PROFILE_PERFORMANCE;
		break;
	case PLATFORM_PROFILE_LOW_POWER:
		ret_code[0] = INSPUR_TMP_PROFILE_POWERSAVE;
		break;
	default:
		return -EOPNOTSUPP;
	}

	ret = inspur_wmi_perform_query(priv->wdev, INSPUR_WMI_SET_POWERMODE,
				       ret_code, sizeof(ret_code),
				       sizeof(ret_code));

	if (ret < 0)
		return ret;

	if (ret_code[0])
		return -EBADRQC;

	return 0;
}

/*
 * Get Power Mode from EC RAM, If Power Mode value greater than 0x3,

Annotation

Implementation Notes