]>
Commit | Line | Data |
---|---|---|
3bb16560 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
5041e791 JG |
2 | /* |
3 | * GPIO driver for the TS-4800 board | |
4 | * | |
5 | * Copyright (c) 2016 - Savoir-faire Linux | |
5041e791 JG |
6 | */ |
7 | ||
8 | #include <linux/gpio/driver.h> | |
7de9a6c7 | 9 | #include <linux/module.h> |
e91d0f05 | 10 | #include <linux/of.h> |
5041e791 JG |
11 | #include <linux/platform_device.h> |
12 | ||
13 | #define DEFAULT_PIN_NUMBER 16 | |
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 device_node *node; | |
21 | struct gpio_chip *chip; | |
5041e791 JG |
22 | void __iomem *base_addr; |
23 | int retval; | |
24 | u32 ngpios; | |
25 | ||
26 | chip = devm_kzalloc(&pdev->dev, sizeof(struct gpio_chip), GFP_KERNEL); | |
27 | if (!chip) | |
28 | return -ENOMEM; | |
29 | ||
f7a6e467 | 30 | base_addr = devm_platform_ioremap_resource(pdev, 0); |
5041e791 JG |
31 | if (IS_ERR(base_addr)) |
32 | return PTR_ERR(base_addr); | |
33 | ||
34 | node = pdev->dev.of_node; | |
35 | if (!node) | |
36 | return -EINVAL; | |
37 | ||
38 | retval = of_property_read_u32(node, "ngpios", &ngpios); | |
39 | if (retval == -EINVAL) | |
40 | ngpios = DEFAULT_PIN_NUMBER; | |
41 | else if (retval) | |
42 | return retval; | |
43 | ||
44 | retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET, | |
45 | base_addr + OUTPUT_REG_OFFSET, NULL, | |
047b2f62 | 46 | base_addr + DIRECTION_REG_OFFSET, NULL, 0); |
5041e791 JG |
47 | if (retval) { |
48 | dev_err(&pdev->dev, "bgpio_init failed\n"); | |
49 | return retval; | |
50 | } | |
51 | ||
5041e791 JG |
52 | chip->ngpio = ngpios; |
53 | ||
54 | platform_set_drvdata(pdev, chip); | |
55 | ||
33ba54ee | 56 | return devm_gpiochip_add_data(&pdev->dev, chip, NULL); |
5041e791 JG |
57 | } |
58 | ||
59 | static const struct of_device_id ts4800_gpio_of_match[] = { | |
60 | { .compatible = "technologic,ts4800-gpio", }, | |
61 | {}, | |
62 | }; | |
91f1551a | 63 | MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match); |
5041e791 JG |
64 | |
65 | static struct platform_driver ts4800_gpio_driver = { | |
66 | .driver = { | |
67 | .name = "ts4800-gpio", | |
68 | .of_match_table = ts4800_gpio_of_match, | |
69 | }, | |
70 | .probe = ts4800_gpio_probe, | |
5041e791 JG |
71 | }; |
72 | ||
73 | module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe); | |
74 | ||
75 | MODULE_AUTHOR("Julien Grossholtz <[email protected]>"); | |
76 | MODULE_DESCRIPTION("TS4800 FPGA GPIO driver"); | |
77 | MODULE_LICENSE("GPL v2"); |