Commit 4aa497ca authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

Merge branch 'acpi-uid'

Merge ACPI _UID handling unification changes for 6.1-rc1:

 - Introduce acpi_dev_uid_to_integer() to convert a _UID string into an
   integer value (Andy Shevchenko).

 - Use acpi_dev_uid_to_integer() in several places to unify _UID
   handling (Andy Shevchenko).

* acpi-uid:
  efi/dev-path-parser: Refactor _UID handling to use acpi_dev_uid_to_integer()
  spi: pxa2xx: Refactor _UID handling to use acpi_dev_uid_to_integer()
  perf: qcom_l2_pmu: Refactor _UID handling to use acpi_dev_uid_to_integer()
  i2c: mlxbf: Refactor _UID handling to use acpi_dev_uid_to_integer()
  i2c: amd-mp2-plat: Refactor _UID handling to use acpi_dev_uid_to_integer()
  ACPI: x86: Refactor _UID handling to use acpi_dev_uid_to_integer()
  ACPI: LPSS: Refactor _UID handling to use acpi_dev_uid_to_integer()
  ACPI: utils: Add acpi_dev_uid_to_integer() helper to get _UID as integer
parents a7ece531 7fc90e86
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -167,10 +167,10 @@ static struct pwm_lookup byt_pwm_lookup[] = {

static void byt_pwm_setup(struct lpss_private_data *pdata)
{
	struct acpi_device *adev = pdata->adev;
	u64 uid;

	/* Only call pwm_add_table for the first PWM controller */
	if (!adev->pnp.unique_id || strcmp(adev->pnp.unique_id, "1"))
	if (acpi_dev_uid_to_integer(pdata->adev, &uid) || uid != 1)
		return;

	pwm_add_table(byt_pwm_lookup, ARRAY_SIZE(byt_pwm_lookup));
@@ -180,14 +180,13 @@ static void byt_pwm_setup(struct lpss_private_data *pdata)

static void byt_i2c_setup(struct lpss_private_data *pdata)
{
	const char *uid_str = acpi_device_uid(pdata->adev);
	acpi_handle handle = pdata->adev->handle;
	unsigned long long shared_host = 0;
	acpi_status status;
	long uid = 0;
	u64 uid;

	/* Expected to always be true, but better safe then sorry */
	if (uid_str && !kstrtol(uid_str, 10, &uid) && uid) {
	/* Expected to always be successfull, but better safe then sorry */
	if (!acpi_dev_uid_to_integer(pdata->adev, &uid) && uid) {
		/* Detect I2C bus shared with PUNIT and ignore its d3 status */
		status = acpi_evaluate_integer(handle, "_SEM", NULL, &shared_host);
		if (ACPI_SUCCESS(status) && shared_host)
@@ -211,10 +210,10 @@ static struct pwm_lookup bsw_pwm_lookup[] = {

static void bsw_pwm_setup(struct lpss_private_data *pdata)
{
	struct acpi_device *adev = pdata->adev;
	u64 uid;

	/* Only call pwm_add_table for the first PWM controller */
	if (!adev->pnp.unique_id || strcmp(adev->pnp.unique_id, "1"))
	if (acpi_dev_uid_to_integer(pdata->adev, &uid) || uid != 1)
		return;

	pwm_add_table(bsw_pwm_lookup, ARRAY_SIZE(bsw_pwm_lookup));
+24 −0
Original line number Diff line number Diff line
@@ -793,6 +793,30 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev,
}
EXPORT_SYMBOL(acpi_dev_hid_uid_match);

/**
 * acpi_dev_uid_to_integer - treat ACPI device _UID as integer
 * @adev: ACPI device to get _UID from
 * @integer: output buffer for integer
 *
 * Considers _UID as integer and converts it to @integer.
 *
 * Returns 0 on success, or negative error code otherwise.
 */
int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer)
{
	const char *uid;

	if (!adev)
		return -ENODEV;

	uid = acpi_device_uid(adev);
	if (!uid)
		return -ENODATA;

	return kstrtou64(uid, 0, integer);
}
EXPORT_SYMBOL(acpi_dev_uid_to_integer);

/**
 * acpi_dev_found - Detect presence of a given ACPI device in the namespace.
 * @hid: Hardware ID of the device.
+10 −4
Original line number Diff line number Diff line
@@ -368,11 +368,17 @@ int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *s
	struct acpi_device *adev = ACPI_COMPANION(controller_parent);
	const struct dmi_system_id *dmi_id;
	long quirks = 0;
	u64 uid;
	int ret;

	*skip = false;

	/* !dev_is_platform() to not match on PNP enumerated debug UARTs */
	if (!adev || !adev->pnp.unique_id || !dev_is_platform(controller_parent))
	ret = acpi_dev_uid_to_integer(adev, &uid);
	if (ret)
		return 0;

	/* to not match on PNP enumerated debug UARTs */
	if (!dev_is_platform(controller_parent))
		return 0;

	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
@@ -380,10 +386,10 @@ int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *s
		quirks = (unsigned long)dmi_id->driver_data;

	if (quirks & ACPI_QUIRK_UART1_TTY_UART2_SKIP) {
		if (!strcmp(adev->pnp.unique_id, "1"))
		if (uid == 1)
			return -ENODEV; /* Create tty cdev instead of serdev */

		if (!strcmp(adev->pnp.unique_id, "2"))
		if (uid == 2)
			*skip = true;
	}

+6 −4
Original line number Diff line number Diff line
@@ -15,9 +15,11 @@
static long __init parse_acpi_path(const struct efi_dev_path *node,
				   struct device *parent, struct device **child)
{
	char hid[ACPI_ID_LEN], uid[11]; /* UINT_MAX + null byte */
	struct acpi_device *adev;
	struct device *phys_dev;
	char hid[ACPI_ID_LEN];
	u64 uid;
	int ret;

	if (node->header.length != 12)
		return -EINVAL;
@@ -27,12 +29,12 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
		'A' + ((node->acpi.hid >>  5) & 0x1f) - 1,
		'A' + ((node->acpi.hid >>  0) & 0x1f) - 1,
			node->acpi.hid >> 16);
	sprintf(uid, "%u", node->acpi.uid);

	for_each_acpi_dev_match(adev, hid, NULL, -1) {
		if (adev->pnp.unique_id && !strcmp(adev->pnp.unique_id, uid))
		ret = acpi_dev_uid_to_integer(adev, &uid);
		if (ret == 0 && node->acpi.uid == uid)
			break;
		if (!adev->pnp.unique_id && node->acpi.uid == 0)
		if (ret == -ENODATA && node->acpi.uid == 0)
			break;
	}
	if (!adev)
+9 −18
Original line number Diff line number Diff line
@@ -244,14 +244,18 @@ static const struct i2c_adapter_quirks amd_i2c_dev_quirks = {

static int i2c_amd_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	int ret;
	struct amd_i2c_dev *i2c_dev;
	struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
	struct amd_mp2_dev *mp2_dev;
	const char *uid;
	u64 uid;

	if (!adev)
		return -ENODEV;
	ret = acpi_dev_uid_to_integer(ACPI_COMPANION(dev), &uid);
	if (ret)
		return dev_err_probe(dev, ret, "missing UID/bus id!\n");
	if (uid >= 2)
		return dev_err_probe(dev, -EINVAL, "incorrect UID/bus id \"%llu\"!\n", uid);
	dev_dbg(dev, "bus id is %llu\n", uid);

	/* The ACPI namespace doesn't contain information about which MP2 PCI
	 * device an AMDI0011 ACPI device is related to, so assume that there's
@@ -266,6 +270,7 @@ static int i2c_amd_probe(struct platform_device *pdev)
	if (!i2c_dev)
		return -ENOMEM;

	i2c_dev->common.bus_id = uid;
	i2c_dev->common.mp2_dev = mp2_dev;
	i2c_dev->pdev = pdev;
	platform_set_drvdata(pdev, i2c_dev);
@@ -276,20 +281,6 @@ static int i2c_amd_probe(struct platform_device *pdev)
	i2c_dev->common.resume = &i2c_amd_resume;
#endif

	uid = adev->pnp.unique_id;
	if (!uid) {
		dev_err(&pdev->dev, "missing UID/bus id!\n");
		return -EINVAL;
	} else if (strcmp(uid, "0") == 0) {
		i2c_dev->common.bus_id = 0;
	} else if (strcmp(uid, "1") == 0) {
		i2c_dev->common.bus_id = 1;
	} else {
		dev_err(&pdev->dev, "incorrect UID/bus id \"%s\"!\n", uid);
		return -EINVAL;
	}
	dev_dbg(&pdev->dev, "bus id is %u\n", i2c_dev->common.bus_id);

	/* Register the adapter */
	amd_mp2_pm_runtime_get(mp2_dev);

Loading