From 8a7b179781e865ca2c7fe4ce9a7976f45c070f53 Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Wed, 3 Jul 2019 00:32:45 +0200 Subject: gpio: stp-xway: simplify error handling in xway_stp_probe() Return early if devm_gpiochip_add_data() returns an error instead of having two consecutive "if (!ret) ..." statements. Also make xway_stp_hw_init() return void because it unconditionally returns 0. While here also update the kerneldoc comment for xway_stp_hw_init(). These changes makes the error handling within the driver consistent. No functional changes intended. Signed-off-by: Martin Blumenstingl Link: https://lore.kernel.org/r/20190702223248.31934-2-martin.blumenstingl@googlemail.com Signed-off-by: Linus Walleij --- drivers/gpio/gpio-stp-xway.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'drivers/gpio/gpio-stp-xway.c') diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c index 8a319d56c5de..3606af901ace 100644 --- a/drivers/gpio/gpio-stp-xway.c +++ b/drivers/gpio/gpio-stp-xway.c @@ -159,9 +159,9 @@ static int xway_stp_request(struct gpio_chip *gc, unsigned gpio) /** * xway_stp_hw_init() - Configure the STP unit and enable the clock gate - * @virt: pointer to the remapped register range + * @chip: Pointer to the xway_stp chip structure */ -static int xway_stp_hw_init(struct xway_stp *chip) +static void xway_stp_hw_init(struct xway_stp *chip) { /* sane defaults */ xway_stp_w32(chip->virt, 0, XWAY_STP_AR); @@ -204,8 +204,6 @@ static int xway_stp_hw_init(struct xway_stp *chip) if (chip->reserved) xway_stp_w32_mask(chip->virt, XWAY_STP_UPD_MASK, XWAY_STP_UPD_FPI, XWAY_STP_CON1); - - return 0; } static int xway_stp_probe(struct platform_device *pdev) @@ -268,14 +266,15 @@ static int xway_stp_probe(struct platform_device *pdev) } clk_enable(clk); - ret = xway_stp_hw_init(chip); - if (!ret) - ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); + xway_stp_hw_init(chip); - if (!ret) - dev_info(&pdev->dev, "Init done\n"); + ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); + if (ret) + return ret; - return ret; + dev_info(&pdev->dev, "Init done\n"); + + return 0; } static const struct of_device_id xway_stp_match[] = { -- cgit v1.2.3 From bd791c48808a1f39a768a0096940d71e05bb0889 Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Wed, 3 Jul 2019 00:32:46 +0200 Subject: gpio: stp-xway: improve module clock error handling Three module clock error handling improvements: - use devm_clk_get() so the clock instance can be freed if devm_gpiochip_add_data() fails later on - switch to clk_prepare_enable() so the driver is ready whenever the lantiq target switches to the common clock framework - disable the clock again (using clk_disable_unprepare()) if devm_gpiochip_add_data() All of these are virtually no-ops with the current lantiq target. However, these will be relevant if we switch to the common clock framework. Signed-off-by: Martin Blumenstingl Link: https://lore.kernel.org/r/20190702223248.31934-3-martin.blumenstingl@googlemail.com Signed-off-by: Linus Walleij --- drivers/gpio/gpio-stp-xway.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'drivers/gpio/gpio-stp-xway.c') diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c index 3606af901ace..cbdeba9144c1 100644 --- a/drivers/gpio/gpio-stp-xway.c +++ b/drivers/gpio/gpio-stp-xway.c @@ -259,18 +259,23 @@ static int xway_stp_probe(struct platform_device *pdev) if (!of_find_property(pdev->dev.of_node, "lantiq,rising", NULL)) chip->edge = XWAY_STP_FALLING; - clk = clk_get(&pdev->dev, NULL); + clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(clk)) { dev_err(&pdev->dev, "Failed to get clock\n"); return PTR_ERR(clk); } - clk_enable(clk); + + ret = clk_prepare_enable(clk); + if (ret) + return ret; xway_stp_hw_init(chip); ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); - if (ret) + if (ret) { + clk_disable_unprepare(clk); return ret; + } dev_info(&pdev->dev, "Init done\n"); -- cgit v1.2.3 From c0ec7012385939d0c885c976c8849084d7aeb2fb Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Wed, 3 Jul 2019 00:32:47 +0200 Subject: gpio: stp-xway: get rid of the #include dependency Use the xway_stp_{r,w}32 helpers in xway_stp_w32_mask instead of relying on ltq_{r,w}32 from the architecture specific . This will allow the driver to be compile-tested on all architectures that support MMIO. Signed-off-by: Martin Blumenstingl Link: https://lore.kernel.org/r/20190702223248.31934-4-martin.blumenstingl@googlemail.com Signed-off-by: Linus Walleij --- drivers/gpio/gpio-stp-xway.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'drivers/gpio/gpio-stp-xway.c') diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c index cbdeba9144c1..d946d0ece14a 100644 --- a/drivers/gpio/gpio-stp-xway.c +++ b/drivers/gpio/gpio-stp-xway.c @@ -18,8 +18,6 @@ #include #include -#include - /* * The Serial To Parallel (STP) is found on MIPS based Lantiq socs. It is a * peripheral controller used to drive external shift register cascades. At most @@ -74,8 +72,7 @@ #define xway_stp_r32(m, reg) __raw_readl(m + reg) #define xway_stp_w32(m, val, reg) __raw_writel(val, m + reg) #define xway_stp_w32_mask(m, clear, set, reg) \ - ltq_w32((ltq_r32(m + reg) & ~(clear)) | (set), \ - m + reg) + xway_stp_w32(m, (xway_stp_r32(m, reg) & ~(clear)) | (set), reg) struct xway_stp { struct gpio_chip gc; -- cgit v1.2.3