Skip to content

Commit f4c6752

Browse files
andy-shevrafaeljw
authored andcommitted
i2c: amd-mp2-plat: Refactor _UID handling to use acpi_dev_uid_to_integer()
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 <[email protected]> Acked-by: Wolfram Sang <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 197a5ae commit f4c6752

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

drivers/i2c/busses/i2c-amd-mp2-plat.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,18 @@ static const struct i2c_adapter_quirks amd_i2c_dev_quirks = {
244244

245245
static int i2c_amd_probe(struct platform_device *pdev)
246246
{
247+
struct device *dev = &pdev->dev;
247248
int ret;
248249
struct amd_i2c_dev *i2c_dev;
249-
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
250250
struct amd_mp2_dev *mp2_dev;
251-
const char *uid;
251+
u64 uid;
252252

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

256260
/* The ACPI namespace doesn't contain information about which MP2 PCI
257261
* 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)
266270
if (!i2c_dev)
267271
return -ENOMEM;
268272

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

279-
uid = adev->pnp.unique_id;
280-
if (!uid) {
281-
dev_err(&pdev->dev, "missing UID/bus id!\n");
282-
return -EINVAL;
283-
} else if (strcmp(uid, "0") == 0) {
284-
i2c_dev->common.bus_id = 0;
285-
} else if (strcmp(uid, "1") == 0) {
286-
i2c_dev->common.bus_id = 1;
287-
} else {
288-
dev_err(&pdev->dev, "incorrect UID/bus id \"%s\"!\n", uid);
289-
return -EINVAL;
290-
}
291-
dev_dbg(&pdev->dev, "bus id is %u\n", i2c_dev->common.bus_id);
292-
293284
/* Register the adapter */
294285
amd_mp2_pm_runtime_get(mp2_dev);
295286

0 commit comments

Comments
 (0)