1 // SPDX-License-Identifier: GPL-2.0-only
3 * Delta TN48M CPLD GPIO driver
5 * Copyright (C) 2021 Sartura Ltd.
7 * Author: Robert Marko <robert.marko@sartura.hr>
10 #include <linux/device.h>
11 #include <linux/gpio/driver.h>
12 #include <linux/gpio/regmap.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/regmap.h>
18 enum tn48m_gpio_type {
23 struct tn48m_gpio_config {
26 enum tn48m_gpio_type type;
29 static const struct tn48m_gpio_config tn48m_gpo_config = {
35 static const struct tn48m_gpio_config tn48m_gpi_config = {
41 static int tn48m_gpio_probe(struct platform_device *pdev)
43 const struct tn48m_gpio_config *gpio_config;
44 struct gpio_regmap_config config = {};
45 struct regmap *regmap;
49 if (!pdev->dev.parent)
52 gpio_config = device_get_match_data(&pdev->dev);
56 ret = device_property_read_u32(&pdev->dev, "reg", &base);
60 regmap = dev_get_regmap(pdev->dev.parent, NULL);
64 config.regmap = regmap;
65 config.parent = &pdev->dev;
66 config.ngpio = gpio_config->ngpio;
67 config.ngpio_per_reg = gpio_config->ngpio_per_reg;
68 switch (gpio_config->type) {
70 config.reg_set_base = base;
73 config.reg_dat_base = base;
79 return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&pdev->dev, &config));
82 static const struct of_device_id tn48m_gpio_of_match[] = {
83 { .compatible = "delta,tn48m-gpo", .data = &tn48m_gpo_config },
84 { .compatible = "delta,tn48m-gpi", .data = &tn48m_gpi_config },
87 MODULE_DEVICE_TABLE(of, tn48m_gpio_of_match);
89 static struct platform_driver tn48m_gpio_driver = {
91 .name = "delta-tn48m-gpio",
92 .of_match_table = tn48m_gpio_of_match,
94 .probe = tn48m_gpio_probe,
96 module_platform_driver(tn48m_gpio_driver);
98 MODULE_AUTHOR("Robert Marko <robert.marko@sartura.hr>");
99 MODULE_DESCRIPTION("Delta TN48M CPLD GPIO driver");
100 MODULE_LICENSE("GPL");