blob: 75f6f8d4323e9a30632bde6685693c055e4cdd50 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +04002/*
3 * CLPS711X GPIO driver
4 *
Alexander Shiyan55fe14a2013-04-26 19:47:28 +04005 * Copyright (C) 2012,2013 Alexander Shiyan <shc_work@mail.ru>
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +04006 */
7
Alexander Shiyan55fe14a2013-04-26 19:47:28 +04008#include <linux/err.h>
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +04009#include <linux/module.h>
Linus Walleij0f4630f2015-12-04 14:02:58 +010010#include <linux/gpio/driver.h>
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040011#include <linux/platform_device.h>
12
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040013static int clps711x_gpio_probe(struct platform_device *pdev)
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040014{
Alexander Shiyana1801322013-04-26 19:47:30 +040015 struct device_node *np = pdev->dev.of_node;
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040016 void __iomem *dat, *dir;
Linus Walleij0f4630f2015-12-04 14:02:58 +010017 struct gpio_chip *gc;
Alexander Shiyan1bdb5c82016-06-04 10:10:12 +030018 int err, id;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040019
Alexander Shiyan1bdb5c82016-06-04 10:10:12 +030020 if (!np)
21 return -ENODEV;
22
23 id = of_alias_get_id(np, "gpio");
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040024 if ((id < 0) || (id > 4))
25 return -ENODEV;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040026
Linus Walleij0f4630f2015-12-04 14:02:58 +010027 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
28 if (!gc)
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040029 return -ENOMEM;
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040030
Enrico Weigelt, metux IT consult09ec4732019-03-11 19:54:46 +010031 dat = devm_platform_ioremap_resource(pdev, 0);
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040032 if (IS_ERR(dat))
33 return PTR_ERR(dat);
34
Enrico Weigelt, metux IT consult09ec4732019-03-11 19:54:46 +010035 dir = devm_platform_ioremap_resource(pdev, 1);
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040036 if (IS_ERR(dir))
37 return PTR_ERR(dir);
38
39 switch (id) {
40 case 3:
41 /* PORTD is inverted logic for direction register */
Linus Walleij0f4630f2015-12-04 14:02:58 +010042 err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040043 NULL, dir, 0);
44 break;
45 default:
Linus Walleij0f4630f2015-12-04 14:02:58 +010046 err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040047 dir, NULL, 0);
48 break;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040049 }
50
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040051 if (err)
52 return err;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040053
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040054 switch (id) {
55 case 4:
56 /* PORTE is 3 lines only */
Linus Walleij0f4630f2015-12-04 14:02:58 +010057 gc->ngpio = 3;
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040058 break;
59 default:
60 break;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040061 }
62
Alexander Shiyan1bdb5c82016-06-04 10:10:12 +030063 gc->base = -1;
Linus Walleij0f4630f2015-12-04 14:02:58 +010064 gc->owner = THIS_MODULE;
65 platform_set_drvdata(pdev, gc);
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040066
Laxman Dewanganda9d6702016-02-22 17:43:28 +053067 return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040068}
69
Alexander Shiyane8b49e02013-12-24 18:08:53 +040070static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
Alexander Shiyan1a4d4582016-06-04 10:09:59 +030071 { .compatible = "cirrus,ep7209-gpio" },
Alexander Shiyana1801322013-04-26 19:47:30 +040072 { }
73};
74MODULE_DEVICE_TABLE(of, clps711x_gpio_ids);
75
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040076static struct platform_driver clps711x_gpio_driver = {
77 .driver = {
Alexander Shiyana1801322013-04-26 19:47:30 +040078 .name = "clps711x-gpio",
Alexander Shiyane8b49e02013-12-24 18:08:53 +040079 .of_match_table = of_match_ptr(clps711x_gpio_ids),
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040080 },
81 .probe = clps711x_gpio_probe,
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040082};
83module_platform_driver(clps711x_gpio_driver);
84
85MODULE_LICENSE("GPL");
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040086MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
87MODULE_DESCRIPTION("CLPS711X GPIO driver");
Axel Lin21708c92014-02-04 17:39:15 +080088MODULE_ALIAS("platform:clps711x-gpio");