aboutsummaryrefslogtreecommitdiff
path: root/cds9k-gpio.c
blob: 563f3a09a38224110328be616693fc1d34d595d0 (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
60
#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;
	const char *parent_name = dev_name(pdev->dev.parent);

	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 = 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;

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