2 * GPIO driver for the TS-4800 board
4 * Copyright (c) 2016 - Savoir-faire Linux
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
11 #include <linux/gpio/driver.h>
12 #include <linux/module.h>
13 #include <linux/of_address.h>
14 #include <linux/of_device.h>
15 #include <linux/platform_device.h>
17 #define DEFAULT_PIN_NUMBER 16
18 #define INPUT_REG_OFFSET 0x00
19 #define OUTPUT_REG_OFFSET 0x02
20 #define DIRECTION_REG_OFFSET 0x04
22 static int ts4800_gpio_probe(struct platform_device *pdev)
24 struct device_node *node;
25 struct gpio_chip *chip;
26 void __iomem *base_addr;
30 chip = devm_kzalloc(&pdev->dev, sizeof(struct gpio_chip), GFP_KERNEL);
34 base_addr = devm_platform_ioremap_resource(pdev, 0);
35 if (IS_ERR(base_addr))
36 return PTR_ERR(base_addr);
38 node = pdev->dev.of_node;
42 retval = of_property_read_u32(node, "ngpios", &ngpios);
43 if (retval == -EINVAL)
44 ngpios = DEFAULT_PIN_NUMBER;
48 retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET,
49 base_addr + OUTPUT_REG_OFFSET, NULL,
50 base_addr + DIRECTION_REG_OFFSET, NULL, 0);
52 dev_err(&pdev->dev, "bgpio_init failed\n");
58 platform_set_drvdata(pdev, chip);
60 return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
63 static const struct of_device_id ts4800_gpio_of_match[] = {
64 { .compatible = "technologic,ts4800-gpio", },
67 MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match);
69 static struct platform_driver ts4800_gpio_driver = {
71 .name = "ts4800-gpio",
72 .of_match_table = ts4800_gpio_of_match,
74 .probe = ts4800_gpio_probe,
77 module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe);
79 MODULE_AUTHOR("Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>");
80 MODULE_DESCRIPTION("TS4800 FPGA GPIO driver");
81 MODULE_LICENSE("GPL v2");