summaryrefslogtreecommitdiff
path: root/drivers/gpio
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2018-04-13 13:05:36 +0300
committerLinus Walleij <linus.walleij@linaro.org>2018-05-16 15:35:24 +0300
commit70e703e7410c40b99499b214567c1b6c324e26c6 (patch)
tree72bd5d3f3ef49b261d228bee43aba4bfbfb88ffe /drivers/gpio
parentf105edf70011859b33c3309f9c5ea96395cb616c (diff)
downloadlinux-70e703e7410c40b99499b214567c1b6c324e26c6.tar.xz
gpio: loongson: Create a dynamic platform device
It is pretty helpful to create some kind of device for backing the GPIO chips, especially when preparing the driver for using GENERIC_GPIO, so let's create a simple platform device and a simple platform device driver and create the gpiochip in the .probe() routine for the device driver. Keep all at the core initcall so the behaviour is the same as before. Cc: Keguang Zhang <keguang.zhang@gmail.com> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com> Cc: Huacai Chen <chenhc@lemote.com> Cc: linux-mips@linux-mips.org Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-loongson.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/drivers/gpio/gpio-loongson.c b/drivers/gpio/gpio-loongson.c
index 973d82a29442..3c9d4f3ed550 100644
--- a/drivers/gpio/gpio-loongson.c
+++ b/drivers/gpio/gpio-loongson.c
@@ -18,6 +18,7 @@
#include <linux/spinlock.h>
#include <linux/err.h>
#include <linux/gpio/driver.h>
+#include <linux/platform_device.h>
#include <asm/types.h>
#include <loongson.h>
@@ -97,19 +98,45 @@ static int loongson_gpio_direction_output(struct gpio_chip *chip,
return 0;
}
-static struct gpio_chip loongson_chip = {
- .label = "Loongson-gpio-chip",
- .direction_input = loongson_gpio_direction_input,
- .get = loongson_gpio_get_value,
- .direction_output = loongson_gpio_direction_output,
- .set = loongson_gpio_set_value,
- .base = 0,
- .ngpio = LOONGSON_N_GPIO,
- .can_sleep = false,
+static int loongson_gpio_probe(struct platform_device *pdev)
+{
+ struct gpio_chip *gc;
+ struct device *dev = &pdev->dev;
+
+ gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
+ if (!gc)
+ return -ENOMEM;
+
+ gc->label = "loongson-gpio-chip";
+ gc->base = 0;
+ gc->ngpio = LOONGSON_N_GPIO;
+ gc->get = loongson_gpio_get_value;
+ gc->set = loongson_gpio_set_value;
+ gc->direction_input = loongson_gpio_direction_input;
+ gc->direction_output = loongson_gpio_direction_output;
+
+ return gpiochip_add_data(gc, NULL);
+}
+
+static struct platform_driver loongson_gpio_driver = {
+ .driver = {
+ .name = "loongson-gpio",
+ },
+ .probe = loongson_gpio_probe,
};
static int __init loongson_gpio_setup(void)
{
- return gpiochip_add_data(&loongson_chip, NULL);
+ struct platform_device *pdev;
+ int ret;
+
+ ret = platform_driver_register(&loongson_gpio_driver);
+ if (ret) {
+ pr_err("error registering loongson GPIO driver\n");
+ return ret;
+ }
+
+ pdev = platform_device_register_simple("loongson-gpio", -1, NULL, 0);
+ return PTR_ERR_OR_ZERO(pdev);
}
postcore_initcall(loongson_gpio_setup);