[PATCH 11/22] platform/chrome: cros_typec_switch: Use fwnode instead of ACPI APIs

From: Stephen Boyd
Date: Sat Feb 10 2024 - 02:13:55 EST


Use fwnode APIs instead of ACPI ones because this driver will soon
support devicetree firmwares. Using fwnode APIs makes it easier to
support either ACPI or DT.

Cc: Prashant Malani <pmalani@xxxxxxxxxxxx>
Cc: Benson Leung <bleung@xxxxxxxxxxxx>
Cc: Tzung-Bi Shih <tzungbi@xxxxxxxxxx>
Cc: <chrome-platform@xxxxxxxxxxxxxxx>
Cc: Pin-yen Lin <treapking@xxxxxxxxxxxx>
Signed-off-by: Stephen Boyd <swboyd@xxxxxxxxxxxx>
---
drivers/platform/chrome/cros_typec_switch.c | 24 +++++++++++----------
1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/platform/chrome/cros_typec_switch.c b/drivers/platform/chrome/cros_typec_switch.c
index 1a718b661203..373e0e86ebfc 100644
--- a/drivers/platform/chrome/cros_typec_switch.c
+++ b/drivers/platform/chrome/cros_typec_switch.c
@@ -207,29 +207,31 @@ static int cros_typec_register_port(struct cros_typec_switch_data *sdata,
struct cros_typec_port *port;
struct device *dev = sdata->dev;
struct acpi_device *adev;
- unsigned long long index;
+ u32 index;
int ret;
+ const char *prop_name;

port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
if (!port)
return -ENOMEM;

adev = to_acpi_device_node(fwnode);
- if (adev) {
- ret = acpi_evaluate_integer(adev->handle, "_ADR", NULL, &index);
- if (ACPI_FAILURE(ret)) {
- dev_err(fwnode->dev, "_ADR wasn't evaluated\n");
- return -ENODATA;
- }
- }
+ if (adev)
+ prop_name = "_ADR";

if (!adev) {
dev_err(fwnode->dev, "Couldn't get ACPI handle\n");
return -ENODEV;
}

+ ret = fwnode_property_read_u32(fwnode, prop_name, &index);
+ if (ret) {
+ dev_err(fwnode->dev, "%s property wasn't found\n", prop_name);
+ return ret;
+ }
+
if (index >= EC_USB_PD_MAX_PORTS) {
- dev_err(fwnode->dev, "Invalid port index number: %llu\n", index);
+ dev_err(fwnode->dev, "Invalid port index number: %u\n", index);
return -EINVAL;
}
port->sdata = sdata;
@@ -243,7 +245,7 @@ static int cros_typec_register_port(struct cros_typec_switch_data *sdata,
return ret;
}

- dev_dbg(dev, "Retimer switch registered for index %llu\n", index);
+ dev_dbg(dev, "Retimer switch registered for index %u\n", index);
}

if (!fwnode_property_present(fwnode, "mode-switch"))
@@ -255,7 +257,7 @@ static int cros_typec_register_port(struct cros_typec_switch_data *sdata,
return ret;
}

- dev_dbg(dev, "Mode switch registered for index %llu\n", index);
+ dev_dbg(dev, "Mode switch registered for index %u\n", index);

return ret;
}
--
https://chromeos.dev