1 // SPDX-License-Identifier: GPL-2.0-only
3 * GPIO driver for the TS-4800 board
5 * Copyright (c) 2016 - Savoir-faire Linux
8 #include <linux/gpio/driver.h>
9 #include <linux/module.h>
10 #include <linux/of_address.h>
11 #include <linux/of_device.h>
12 #include <linux/platform_device.h>
14 #define DEFAULT_PIN_NUMBER 16
15 #define INPUT_REG_OFFSET 0x00
16 #define OUTPUT_REG_OFFSET 0x02
17 #define DIRECTION_REG_OFFSET 0x04
19 static int ts4800_gpio_probe(struct platform_device *pdev)
21 struct device_node *node;
22 struct gpio_chip *chip;
23 void __iomem *base_addr;
27 chip = devm_kzalloc(&pdev->dev, sizeof(struct gpio_chip), GFP_KERNEL);
31 base_addr = devm_platform_ioremap_resource(pdev, 0);
32 if (IS_ERR(base_addr))
33 return PTR_ERR(base_addr);
35 node = pdev->dev.of_node;
39 retval = of_property_read_u32(node, "ngpios", &ngpios);
40 if (retval == -EINVAL)
41 ngpios = DEFAULT_PIN_NUMBER;
45 retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET,
46 base_addr + OUTPUT_REG_OFFSET, NULL,
47 base_addr + DIRECTION_REG_OFFSET, NULL, 0);
49 dev_err(&pdev->dev, "bgpio_init failed\n");
55 platform_set_drvdata(pdev, chip);
57 return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
60 static const struct of_device_id ts4800_gpio_of_match[] = {
61 { .compatible = "technologic,ts4800-gpio", },
64 MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match);
66 static struct platform_driver ts4800_gpio_driver = {
68 .name = "ts4800-gpio",
69 .of_match_table = ts4800_gpio_of_match,
71 .probe = ts4800_gpio_probe,
74 module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe);
76 MODULE_AUTHOR("Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>");
77 MODULE_DESCRIPTION("TS4800 FPGA GPIO driver");
78 MODULE_LICENSE("GPL v2");