Skip to content

Commit

Permalink
gpio: gpio-xilinx: Add clock support
Browse files Browse the repository at this point in the history
Adds clock support to the Xilinx GPIO driver.

Signed-off-by: Srinivas Neeli <srinivas.neeli@xilinx.com>
Acked-by: Michal Simek <michal.simek@xilinx.com>
Link: https://lore.kernel.org/r/1605201148-4508-4-git-send-email-srinivas.neeli@xilinx.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Srinivas Neeli authored and Linus Walleij committed Nov 17, 2020
1 parent 700a2b5 commit 65bbe53
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions drivers/gpio/gpio-xilinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/errno.h>
#include <linux/gpio/driver.h>
#include <linux/init.h>
Expand Down Expand Up @@ -38,6 +39,7 @@
* @gpio_state: GPIO state shadow register
* @gpio_dir: GPIO direction shadow register
* @gpio_lock: Lock used for synchronization
* @clk: clock resource for this driver
*/
struct xgpio_instance {
struct gpio_chip gc;
Expand All @@ -46,6 +48,7 @@ struct xgpio_instance {
u32 gpio_state[2];
u32 gpio_dir[2];
spinlock_t gpio_lock[2];
struct clk *clk;
};

static inline int xgpio_index(struct xgpio_instance *chip, int gpio)
Expand Down Expand Up @@ -334,11 +337,25 @@ static int xgpio_probe(struct platform_device *pdev)
return PTR_ERR(chip->regs);
}

chip->clk = devm_clk_get_optional(&pdev->dev, NULL);
if (IS_ERR(chip->clk)) {
if (PTR_ERR(chip->clk) != -EPROBE_DEFER)
dev_dbg(&pdev->dev, "Input clock not found\n");
return PTR_ERR(chip->clk);
}

status = clk_prepare_enable(chip->clk);
if (status < 0) {
dev_err(&pdev->dev, "Failed to prepare clk\n");
return status;
}

xgpio_save_regs(chip);

status = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip);
if (status) {
dev_err(&pdev->dev, "failed to add GPIO chip\n");
clk_disable_unprepare(chip->clk);
return status;
}

Expand Down

0 comments on commit 65bbe53

Please sign in to comment.