Introduce intel_pinctrl_get_soc_data() internal API to simplify drivers, which are using ACPI _UID to distinguish which SoC data needs to be used when being probed. Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> --- drivers/pinctrl/intel/pinctrl-intel.c | 38 +++++++++++++++++++++++++++ drivers/pinctrl/intel/pinctrl-intel.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c index a356a5b8bab2..08a48a03eb65 100644 --- a/drivers/pinctrl/intel/pinctrl-intel.c +++ b/drivers/pinctrl/intel/pinctrl-intel.c @@ -7,6 +7,7 @@ * Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx> */ +#include <linux/acpi.h> #include <linux/module.h> #include <linux/interrupt.h> #include <linux/gpio/driver.h> @@ -1314,6 +1315,43 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl) return 0; } +int intel_pinctrl_get_soc_data(struct platform_device *pdev, + const struct intel_pinctrl_soc_data **soc_data) +{ + const struct intel_pinctrl_soc_data *data = NULL; + const struct intel_pinctrl_soc_data **table; + struct acpi_device *adev; + unsigned int i; + + adev = ACPI_COMPANION(&pdev->dev); + if (adev) { + const void *match = device_get_match_data(&pdev->dev); + + table = (const struct intel_pinctrl_soc_data **)match; + for (i = 0; table[i]; i++) { + if (!strcmp(adev->pnp.unique_id, table[i]->uid)) { + data = table[i]; + break; + } + } + } else { + const struct platform_device_id *id; + + id = platform_get_device_id(pdev); + if (!id) + return -ENODEV; + + table = (const struct intel_pinctrl_soc_data **)id->driver_data; + data = table[pdev->id]; + } + if (!data) + return -ENODEV; + + *soc_data = data; + return 0; +} +EXPORT_SYMBOL_GPL(intel_pinctrl_get_soc_data); + int intel_pinctrl_probe(struct platform_device *pdev, const struct intel_pinctrl_soc_data *soc_data) { diff --git a/drivers/pinctrl/intel/pinctrl-intel.h b/drivers/pinctrl/intel/pinctrl-intel.h index 1785abf157e4..9ad15198d0db 100644 --- a/drivers/pinctrl/intel/pinctrl-intel.h +++ b/drivers/pinctrl/intel/pinctrl-intel.h @@ -171,6 +171,8 @@ struct intel_pinctrl_soc_data { size_t ncommunities; }; +int intel_pinctrl_get_soc_data(struct platform_device *pdev, + const struct intel_pinctrl_soc_data **soc_data); int intel_pinctrl_probe(struct platform_device *pdev, const struct intel_pinctrl_soc_data *soc_data); #ifdef CONFIG_PM_SLEEP -- 2.18.0