From e94f3bb6d8a60807f4a3dcece21ad4bc35a2093e Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Fri, 15 Dec 2023 09:08:23 +0000 Subject: [PATCH] {isc,cdi}_mgr: Use gpiod_count() for getting number of GPIO The API gpiod_count() returns the number of the GPIO in given property. This API is supported from long and continue to support. Use this API instead of of_gpio_named_count() which is deprecated from Linux 6.2. Bug 4387902 Change-Id: I2b647b8645e0dd8ff743515ac999fe035e636dc5 Signed-off-by: Laxman Dewangan Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3035503 (cherry picked from commit 6627276f82eb24494a6f920b862c1f44c4e6c8be) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3051588 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/media/platform/tegra/cdi/cdi_mgr.c | 19 +++++++++---------- drivers/media/platform/tegra/isc/isc_mgr.c | 19 +++++++++---------- scripts/conftest/Makefile | 1 - scripts/conftest/conftest.sh | 21 --------------------- 4 files changed, 18 insertions(+), 42 deletions(-) diff --git a/drivers/media/platform/tegra/cdi/cdi_mgr.c b/drivers/media/platform/tegra/cdi/cdi_mgr.c index b128aa3a..78069c20 100644 --- a/drivers/media/platform/tegra/cdi/cdi_mgr.c +++ b/drivers/media/platform/tegra/cdi/cdi_mgr.c @@ -1328,22 +1328,21 @@ static int cdi_mgr_of_get_grp_gpio( struct device *dev, struct device_node *np, const char *name, int size, u32 *grp, u32 *flags) { + char prop_name[32]; /* 32 is max size of property name */ int num, i; -#if defined(NV_OF_GPIO_NAMED_COUNT_PRESENT) /* Linux 6.2 */ - num = of_gpio_named_count(np, name); -#else - num = of_count_phandle_with_args(np, name, "#gpio-cells"); -#endif - dev_dbg(dev, " num gpios of %s: %d\n", name, num); + snprintf(prop_name, sizeof(prop_name), "%s-gpios", name); + + num = gpiod_count(dev, name); + dev_dbg(dev, " num gpios of %s: %d\n", prop_name, num); if (num < 0) return 0; for (i = 0; (i < num) && (i < size); i++) { #if defined(NV_OF_GET_NAMED_GPIO_FLAGS_PRESENT) /* Linux 6.2 */ - grp[i] = of_get_named_gpio_flags(np, name, i, &flags[i]); + grp[i] = of_get_named_gpio_flags(np, prop_name, i, &flags[i]); #else - grp[i] = of_get_named_gpio(np, name, i); + grp[i] = of_get_named_gpio(np, prop_name, i); flags[i] = 0; #endif if ((int)grp[i] < 0) { @@ -1455,13 +1454,13 @@ static struct cdi_mgr_platform_data *of_cdi_mgr_pdata(struct platform_device dev_dbg(&pdev->dev, " csiport: %d\n", pd->csi_port); pd->num_pwr_gpios = cdi_mgr_of_get_grp_gpio( - &pdev->dev, child_np, "pwdn-gpios", + &pdev->dev, child_np, "pwdn", ARRAY_SIZE(pd->pwr_gpios), pd->pwr_gpios, pd->pwr_flags); if (pd->num_pwr_gpios < 0) return ERR_PTR(pd->num_pwr_gpios); pd->num_mcdi_gpios = cdi_mgr_of_get_grp_gpio( - &pdev->dev, child_np, "mcdi-gpios", + &pdev->dev, child_np, "mcdi", ARRAY_SIZE(pd->mcdi_gpios), pd->mcdi_gpios, pd->mcdi_flags); if (pd->num_mcdi_gpios < 0) return ERR_PTR(pd->num_mcdi_gpios); diff --git a/drivers/media/platform/tegra/isc/isc_mgr.c b/drivers/media/platform/tegra/isc/isc_mgr.c index 1796601f..92bd05f6 100644 --- a/drivers/media/platform/tegra/isc/isc_mgr.c +++ b/drivers/media/platform/tegra/isc/isc_mgr.c @@ -813,22 +813,21 @@ static int isc_mgr_of_get_grp_gpio( struct device *dev, struct device_node *np, const char *name, int size, u32 *grp, u32 *flags) { + char prop_name[32]; /* 32 is max size of property name */ int num, i; -#if defined(NV_OF_GPIO_NAMED_COUNT_PRESENT) /* Linux 6.2 */ - num = of_gpio_named_count(np, name); -#else - num = of_count_phandle_with_args(np, name, "#gpio-cells"); -#endif - dev_dbg(dev, " num gpios of %s: %d\n", name, num); + snprintf(prop_name, sizeof(prop_name), "%s-gpios", name); + + num = gpiod_count(dev, name); + dev_dbg(dev, " num gpios of %s: %d\n", prop_name, num); if (num < 0) return 0; for (i = 0; (i < num) && (i < size); i++) { #if defined(NV_OF_GET_NAMED_GPIO_FLAGS_PRESENT) /* Linux 6.2 */ - grp[i] = of_get_named_gpio_flags(np, name, i, &flags[i]); + grp[i] = of_get_named_gpio_flags(np, prop_name, i, &flags[i]); #else - grp[i] = of_get_named_gpio(np, name, i); + grp[i] = of_get_named_gpio(np, prop_name, i); flags[i] = 0; #endif if ((int)grp[i] < 0) { @@ -933,13 +932,13 @@ static struct isc_mgr_platform_data *of_isc_mgr_pdata(struct platform_device dev_dbg(&pdev->dev, " csiport: %d\n", pd->csi_port); pd->num_pwr_gpios = isc_mgr_of_get_grp_gpio( - &pdev->dev, np, "pwdn-gpios", + &pdev->dev, np, "pwdn", ARRAY_SIZE(pd->pwr_gpios), pd->pwr_gpios, pd->pwr_flags); if (pd->num_pwr_gpios < 0) return ERR_PTR(pd->num_pwr_gpios); pd->num_misc_gpios = isc_mgr_of_get_grp_gpio( - &pdev->dev, np, "misc-gpios", + &pdev->dev, np, "misc", ARRAY_SIZE(pd->misc_gpios), pd->misc_gpios, pd->misc_flags); if (pd->num_misc_gpios < 0) return ERR_PTR(pd->num_misc_gpios); diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index ccb6eccb..a42bbd4e 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -125,7 +125,6 @@ NV_CONFTEST_FUNCTION_COMPILE_TESTS += mii_bus_struct_has_write_c45 NV_CONFTEST_FUNCTION_COMPILE_TESTS += netif_set_tso_max_size NV_CONFTEST_FUNCTION_COMPILE_TESTS += netif_napi_add_weight NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_get_named_gpio_flags -NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_gpio_named_count NV_CONFTEST_FUNCTION_COMPILE_TESTS += gpio_chip_struct_has_of_node_present NV_CONFTEST_FUNCTION_COMPILE_TESTS += gpiochip_find NV_CONFTEST_FUNCTION_COMPILE_TESTS += pde_data diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index 89263426..54e11707 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -5439,27 +5439,6 @@ compile_test() { compile_check_conftest "$CODE" "NV_OF_GET_NAMED_GPIO_FLAGS_PRESENT" "" "functions" ;; - of_gpio_named_count) - # - # Determine if of_gpio_named_count() function is present - # - # This APIS is removed in commit c7835652a85 ("gpiolib: of: stop - # exporting of_gpio_named_count()") - # in Linux 6.2. - # - CODE=" - #if defined(NV_LINUX_OF_GPIO_H_PRESENT) - #include - #endif - void conftest_of_gpio_named_count(void) - { - of_gpio_named_count(); - } - " - - compile_check_conftest "$CODE" "NV_OF_GPIO_NAMED_COUNT_PRESENT" "" "functions" - ;; - gpio_chip_struct_has_of_node_present) # # Determine if struct gpio_chip has the of_node member or not.