xref: /linux/drivers/gpio/gpio-ts4800.c (revision 53597deca0e38c30e6cd4ba2114fa42d2bcd85bb)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * GPIO driver for the TS-4800 board
4  *
5  * Copyright (c) 2016 - Savoir-faire Linux
6  */
7 
8 #include <linux/gpio/driver.h>
9 #include <linux/gpio/generic.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/property.h>
13 
14 #define INPUT_REG_OFFSET        0x00
15 #define OUTPUT_REG_OFFSET       0x02
16 #define DIRECTION_REG_OFFSET    0x04
17 
18 static int ts4800_gpio_probe(struct platform_device *pdev)
19 {
20 	struct gpio_generic_chip_config config;
21 	struct device *dev = &pdev->dev;
22 	struct gpio_generic_chip *chip;
23 	void __iomem *base_addr;
24 	int retval;
25 
26 	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
27 	if (!chip)
28 		return -ENOMEM;
29 
30 	base_addr = devm_platform_ioremap_resource(pdev, 0);
31 	if (IS_ERR(base_addr))
32 		return PTR_ERR(base_addr);
33 
34 	config = (struct gpio_generic_chip_config) {
35 		.dev = dev,
36 		.sz = 2,
37 		.dat = base_addr + INPUT_REG_OFFSET,
38 		.set = base_addr + OUTPUT_REG_OFFSET,
39 		.dirout = base_addr + DIRECTION_REG_OFFSET,
40 	};
41 
42 	retval = gpio_generic_chip_init(chip, &config);
43 	if (retval)
44 		return dev_err_probe(dev, retval,
45 				     "failed to initialize the generic GPIO chip\n");
46 
47 	return devm_gpiochip_add_data(dev, &chip->gc, NULL);
48 }
49 
50 static const struct of_device_id ts4800_gpio_of_match[] = {
51 	{ .compatible = "technologic,ts4800-gpio", },
52 	{},
53 };
54 MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match);
55 
56 static struct platform_driver ts4800_gpio_driver = {
57 	.driver = {
58 		   .name = "ts4800-gpio",
59 		   .of_match_table = ts4800_gpio_of_match,
60 		   },
61 	.probe = ts4800_gpio_probe,
62 };
63 
64 module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe);
65 
66 MODULE_AUTHOR("Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>");
67 MODULE_DESCRIPTION("TS4800 FPGA GPIO driver");
68 MODULE_LICENSE("GPL v2");
69