i2c: amd-mp2-plat: Refactor _UID handling to use acpi_dev_uid_to_integer()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 13 Sep 2022 16:31:43 +0000 (19:31 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 19 Sep 2022 16:34:42 +0000 (18:34 +0200)
ACPI utils provide acpi_dev_uid_to_integer() helper to extract _UID as
an integer. Use it instead of custom approach.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Wolfram Sang <wsa@kernel.org>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/i2c/busses/i2c-amd-mp2-plat.c

index 84b7e6cbc67b0d08c7f783ad19e4d5e608c20e1f..423fe0c8a471e0b29ae455811a12b379b5f16e2c 100644 (file)
@@ -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);