diff options
author | David Phillips <david@yeah.nah.nz> | 2021-05-09 11:52:38 +1200 |
---|---|---|
committer | David Phillips <david@yeah.nah.nz> | 2021-05-09 11:53:01 +1200 |
commit | 3b81e5b0b54e9a5adb6ae9014e60253dbe94401d (patch) | |
tree | fcbd3303b58f97d411b2c943ef9e3f7f42246b32 | |
parent | ed609a3eb31f99ee02f7dbfbd6067a288e56b0b1 (diff) | |
download | cds9k-3b81e5b0b54e9a5adb6ae9014e60253dbe94401d.tar.xz |
Add driver for CDS9K GPIO IP block
-rw-r--r-- | cds9k-gpio.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/cds9k-gpio.c b/cds9k-gpio.c new file mode 100644 index 0000000..80b56ac --- /dev/null +++ b/cds9k-gpio.c @@ -0,0 +1,69 @@ +#include <linux/device.h> +#include <linux/module.h> +#include <linux/of_platform.h> +#include <linux/regmap.h> +#include <linux/gpio/regmap.h> + +#define GPIO_REG_PORT 0x0 +#define GPIO_REG_DIR 0x1 + +static int cds9k_gpio_probe(struct platform_device *pdev) +{ + printk("Hello from the GPIO driver. Pdev name is %s\n", pdev->name); + struct gpio_regmap_config config = {}; + struct regmap *regmap; + u32 base; + int ret; + const char *parent_name = dev_name(pdev->dev.parent); + + if (!pdev->dev.parent) { + printk("NULL parent to platform device\n"); + return -ENODEV; + } + + ret = device_property_read_u32(&pdev->dev, "reg", &base); + if (ret) { + printk("Failed to get u32 reg property on platform device\n"); + return -EINVAL; + } + + regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!regmap) { + printk("dev_get_regmap failed\n"); + return -ENODEV; + } + + config.parent = &pdev->dev; + config.regmap = regmap; + /* XXX would be nice to use these if specified in DT + config.names = + config.label = + */ + config.ngpio = 8; + config.reg_dat_base = base + GPIO_REG_PORT; + config.reg_set_base = base + GPIO_REG_PORT; + config.reg_dir_out_base = base + GPIO_REG_DIR; + + printk("About to return from probe\n"); + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&pdev->dev, &config)); + //0; +} + +static struct of_device_id cds9k_gpio_of_match[] = { + { .compatible = "david,cds9k-gpio" }, + {} +}; +MODULE_DEVICE_TABLE(of, cds9k_gpio_of_match); + +static struct platform_driver cds9k_gpio = { + .driver = { + .name = "cds9k-gpio", + .of_match_table = cds9k_gpio_of_match, + }, + .probe = cds9k_gpio_probe +}; +module_platform_driver(cds9k_gpio); + +MODULE_AUTHOR("David Phillips <david@yeah.nah.nz>"); +MODULE_DESCRIPTION("GPIO driver for the CDS9K board controller"); +MODULE_LICENSE("GPL v2"); |