Merge tag 'i2c-for-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa...
[linux-2.6-block.git] / drivers / gpio / gpio-clps711x.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
a3b8d4a5
AS
2/*
3 * CLPS711X GPIO driver
4 *
55fe14ab 5 * Copyright (C) 2012,2013 Alexander Shiyan <shc_work@mail.ru>
a3b8d4a5
AS
6 */
7
55fe14ab 8#include <linux/err.h>
a3b8d4a5 9#include <linux/module.h>
0f4630f3 10#include <linux/gpio/driver.h>
a3b8d4a5
AS
11#include <linux/platform_device.h>
12
55fe14ab 13static int clps711x_gpio_probe(struct platform_device *pdev)
a3b8d4a5 14{
a180132f 15 struct device_node *np = pdev->dev.of_node;
55fe14ab 16 void __iomem *dat, *dir;
0f4630f3 17 struct gpio_chip *gc;
1bdb5c8e 18 int err, id;
a3b8d4a5 19
1bdb5c8e
AS
20 if (!np)
21 return -ENODEV;
22
23 id = of_alias_get_id(np, "gpio");
55fe14ab
AS
24 if ((id < 0) || (id > 4))
25 return -ENODEV;
a3b8d4a5 26
0f4630f3
LW
27 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
28 if (!gc)
55fe14ab 29 return -ENOMEM;
a3b8d4a5 30
09ec4735 31 dat = devm_platform_ioremap_resource(pdev, 0);
55fe14ab
AS
32 if (IS_ERR(dat))
33 return PTR_ERR(dat);
34
09ec4735 35 dir = devm_platform_ioremap_resource(pdev, 1);
55fe14ab
AS
36 if (IS_ERR(dir))
37 return PTR_ERR(dir);
38
39 switch (id) {
40 case 3:
41 /* PORTD is inverted logic for direction register */
0f4630f3 42 err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
55fe14ab
AS
43 NULL, dir, 0);
44 break;
45 default:
0f4630f3 46 err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
55fe14ab
AS
47 dir, NULL, 0);
48 break;
49 }
a3b8d4a5 50
55fe14ab
AS
51 if (err)
52 return err;
a3b8d4a5 53
55fe14ab
AS
54 switch (id) {
55 case 4:
56 /* PORTE is 3 lines only */
0f4630f3 57 gc->ngpio = 3;
55fe14ab
AS
58 break;
59 default:
60 break;
61 }
d6a2fa04 62
1bdb5c8e 63 gc->base = -1;
0f4630f3
LW
64 gc->owner = THIS_MODULE;
65 platform_set_drvdata(pdev, gc);
d6a2fa04 66
da9d6700 67 return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
d6a2fa04
AS
68}
69
a0d22277 70static const struct of_device_id clps711x_gpio_ids[] = {
1a4d458b 71 { .compatible = "cirrus,ep7209-gpio" },
a180132f
AS
72 { }
73};
74MODULE_DEVICE_TABLE(of, clps711x_gpio_ids);
75
55fe14ab
AS
76static struct platform_driver clps711x_gpio_driver = {
77 .driver = {
a180132f 78 .name = "clps711x-gpio",
a0d22277 79 .of_match_table = clps711x_gpio_ids,
55fe14ab
AS
80 },
81 .probe = clps711x_gpio_probe,
a3b8d4a5 82};
55fe14ab 83module_platform_driver(clps711x_gpio_driver);
a3b8d4a5 84
55fe14ab 85MODULE_LICENSE("GPL");
a3b8d4a5
AS
86MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
87MODULE_DESCRIPTION("CLPS711X GPIO driver");
21708c99 88MODULE_ALIAS("platform:clps711x-gpio");