blob: 0fbbb0edc0ba754e5de9f860bdc0411ecf8ba7b2 [file] [log] [blame]
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +04001/*
2 * CLPS711X GPIO driver
3 *
Alexander Shiyan55fe14a2013-04-26 19:47:28 +04004 * Copyright (C) 2012,2013 Alexander Shiyan <shc_work@mail.ru>
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +04005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040012#include <linux/err.h>
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040013#include <linux/module.h>
Linus Walleij0f4630f2015-12-04 14:02:58 +010014#include <linux/gpio/driver.h>
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040015#include <linux/platform_device.h>
16
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040017static int clps711x_gpio_probe(struct platform_device *pdev)
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040018{
Alexander Shiyana1801322013-04-26 19:47:30 +040019 struct device_node *np = pdev->dev.of_node;
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040020 void __iomem *dat, *dir;
Linus Walleij0f4630f2015-12-04 14:02:58 +010021 struct gpio_chip *gc;
Alexander Shiyan1bdb5c82016-06-04 10:10:12 +030022 int err, id;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040023
Alexander Shiyan1bdb5c82016-06-04 10:10:12 +030024 if (!np)
25 return -ENODEV;
26
27 id = of_alias_get_id(np, "gpio");
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040028 if ((id < 0) || (id > 4))
29 return -ENODEV;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040030
Linus Walleij0f4630f2015-12-04 14:02:58 +010031 gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
32 if (!gc)
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040033 return -ENOMEM;
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040034
Enrico Weigelt, metux IT consult09ec4732019-03-11 19:54:46 +010035 dat = devm_platform_ioremap_resource(pdev, 0);
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040036 if (IS_ERR(dat))
37 return PTR_ERR(dat);
38
Enrico Weigelt, metux IT consult09ec4732019-03-11 19:54:46 +010039 dir = devm_platform_ioremap_resource(pdev, 1);
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040040 if (IS_ERR(dir))
41 return PTR_ERR(dir);
42
43 switch (id) {
44 case 3:
45 /* PORTD is inverted logic for direction register */
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 NULL, dir, 0);
48 break;
49 default:
Linus Walleij0f4630f2015-12-04 14:02:58 +010050 err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040051 dir, NULL, 0);
52 break;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040053 }
54
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040055 if (err)
56 return err;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040057
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040058 switch (id) {
59 case 4:
60 /* PORTE is 3 lines only */
Linus Walleij0f4630f2015-12-04 14:02:58 +010061 gc->ngpio = 3;
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040062 break;
63 default:
64 break;
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040065 }
66
Alexander Shiyan1bdb5c82016-06-04 10:10:12 +030067 gc->base = -1;
Linus Walleij0f4630f2015-12-04 14:02:58 +010068 gc->owner = THIS_MODULE;
69 platform_set_drvdata(pdev, gc);
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040070
Laxman Dewanganda9d6702016-02-22 17:43:28 +053071 return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040072}
73
Alexander Shiyane8b49e02013-12-24 18:08:53 +040074static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
Alexander Shiyan1a4d4582016-06-04 10:09:59 +030075 { .compatible = "cirrus,ep7209-gpio" },
Alexander Shiyana1801322013-04-26 19:47:30 +040076 { }
77};
78MODULE_DEVICE_TABLE(of, clps711x_gpio_ids);
79
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040080static struct platform_driver clps711x_gpio_driver = {
81 .driver = {
Alexander Shiyana1801322013-04-26 19:47:30 +040082 .name = "clps711x-gpio",
Alexander Shiyane8b49e02013-12-24 18:08:53 +040083 .of_match_table = of_match_ptr(clps711x_gpio_ids),
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040084 },
85 .probe = clps711x_gpio_probe,
Alexander Shiyan55fe14a2013-04-26 19:47:28 +040086};
87module_platform_driver(clps711x_gpio_driver);
88
89MODULE_LICENSE("GPL");
Alexander Shiyana3b8d4a2012-10-09 20:05:56 +040090MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
91MODULE_DESCRIPTION("CLPS711X GPIO driver");
Axel Lin21708c92014-02-04 17:39:15 +080092MODULE_ALIAS("platform:clps711x-gpio");