aboutsummaryrefslogtreecommitdiff
path: root/cds9k-gpio.c
blob: cb8b4be10e2e7fcc91558e1477afa2acdc93cf21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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)
{
	struct gpio_regmap_config config = {};
	struct regmap *regmap;
	u32 base;
	int ret;

	if (!pdev->dev.parent)
		return -ENODEV;

	ret = device_property_read_u32(&pdev->dev, "reg", &base);
	if (ret)
		return -EINVAL;

	regmap = dev_get_regmap(pdev->dev.parent, NULL);
	if (!regmap)
		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 = 16;
	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;

	return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(&pdev->dev, &config));
}

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");