From 72cf7c99c34b89f585316a247bce1658a46cc6e3 Mon Sep 17 00:00:00 2001 From: Manish Bhardwaj Date: Tue, 14 Mar 2023 00:58:14 +0530 Subject: [PATCH] mttcan: fix kernel compilation issue fix compilation issue when building mttcan driver with 6.3-rc1 upstream kernel. Bug 4014315 Signed-off-by: Manish Bhardwaj Change-Id: I33c15af15fa8db1ac0cbb1c619db5429a6495a80 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2868425 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Sandeep Trasi GVS: Gerrit_Virtual_Submit --- .../net/can/mttcan/include/m_ttcan_linux.h | 4 +++ drivers/net/can/mttcan/native/m_ttcan_linux.c | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/net/can/mttcan/include/m_ttcan_linux.h b/drivers/net/can/mttcan/include/m_ttcan_linux.h index adc9cab8..0e76c49a 100644 --- a/drivers/net/can/mttcan/include/m_ttcan_linux.h +++ b/drivers/net/can/mttcan/include/m_ttcan_linux.h @@ -73,7 +73,11 @@ struct tegra_mttcan_soc_info { }; struct can_gpio { +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) int gpio; +#else + struct gpio_desc *gpio; +#endif int active_low; }; diff --git a/drivers/net/can/mttcan/native/m_ttcan_linux.c b/drivers/net/can/mttcan/native/m_ttcan_linux.c index 2d477c8d..d5f8359b 100644 --- a/drivers/net/can/mttcan/native/m_ttcan_linux.c +++ b/drivers/net/can/mttcan/native/m_ttcan_linux.c @@ -1250,6 +1250,7 @@ static int mttcan_power_up(struct mttcan_priv *priv) int level; mttcan_pm_runtime_get_sync(priv); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) if (gpio_is_valid(priv->gpio_can_stb.gpio)) { level = !priv->gpio_can_stb.active_low; gpio_direction_output(priv->gpio_can_stb.gpio, level); @@ -1259,7 +1260,17 @@ static int mttcan_power_up(struct mttcan_priv *priv) level = !priv->gpio_can_en.active_low; gpio_direction_output(priv->gpio_can_en.gpio, level); } +#else + if (priv->gpio_can_stb.gpio) { + level = !priv->gpio_can_stb.active_low; + gpiod_direction_output(priv->gpio_can_stb.gpio, level); + } + if (priv->gpio_can_en.gpio) { + level = !priv->gpio_can_en.active_low; + gpiod_direction_output(priv->gpio_can_en.gpio, level); + } +#endif return ttcan_set_power(priv->ttcan, 1); } @@ -1271,6 +1282,7 @@ static int mttcan_power_down(struct net_device *dev) if (ttcan_set_power(priv->ttcan, 0)) return -ETIMEDOUT; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) if (gpio_is_valid(priv->gpio_can_stb.gpio)) { level = priv->gpio_can_stb.active_low; gpio_direction_output(priv->gpio_can_stb.gpio, level); @@ -1280,6 +1292,17 @@ static int mttcan_power_down(struct net_device *dev) level = priv->gpio_can_en.active_low; gpio_direction_output(priv->gpio_can_en.gpio, level); } +#else + if (priv->gpio_can_stb.gpio) { + level = priv->gpio_can_stb.active_low; + gpiod_direction_output(priv->gpio_can_stb.gpio, level); + } + + if (priv->gpio_can_en.gpio) { + level = priv->gpio_can_en.active_low; + gpiod_direction_output(priv->gpio_can_en.gpio, level); + } +#endif mttcan_pm_runtime_put_sync(priv); @@ -1698,7 +1721,9 @@ static int mttcan_probe(struct platform_device *pdev) { int ret = 0; int irq = 0; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) enum of_gpio_flags flags; +#endif void __iomem *regs = NULL, *xregs = NULL; void __iomem *mram_addr = NULL; struct net_device *dev; @@ -1779,12 +1804,21 @@ static int mttcan_probe(struct platform_device *pdev) goto exit_free_device; /* set device-tree properties */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) + priv->gpio_can_en.gpio = devm_gpiod_get_optional(&pdev->dev, + "gpio_can_en", 0); + priv->gpio_can_en.active_low = GPIOD_OUT_LOW; + priv->gpio_can_stb.gpio = devm_gpiod_get_optional(&pdev->dev, + "gpio_can_stb", 0); + priv->gpio_can_stb.active_low = GPIOD_OUT_LOW; +#else priv->gpio_can_en.gpio = of_get_named_gpio_flags(np, "gpio_can_en", 0, &flags); priv->gpio_can_en.active_low = flags & OF_GPIO_ACTIVE_LOW; priv->gpio_can_stb.gpio = of_get_named_gpio_flags(np, "gpio_can_stb", 0, &flags); priv->gpio_can_stb.active_low = flags & OF_GPIO_ACTIVE_LOW; +#endif priv->instance = of_alias_get_id(np, "mttcan"); priv->poll = of_property_read_bool(np, "use-polling"); @@ -1808,6 +1842,7 @@ static int mttcan_probe(struct platform_device *pdev) goto exit_free_device; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) if (gpio_is_valid(priv->gpio_can_stb.gpio)) { if (devm_gpio_request(priv->device, priv->gpio_can_stb.gpio, "gpio_can_stb") < 0) { @@ -1822,6 +1857,7 @@ static int mttcan_probe(struct platform_device *pdev) goto exit_free_device; } } +#endif /* allocate controller struct memory and set fields */