2019-05-27 09:55:01 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2012-10-09 20:05:56 +04:00
|
|
|
/*
|
|
|
|
* CLPS711X GPIO driver
|
|
|
|
*
|
2013-04-26 19:47:28 +04:00
|
|
|
* Copyright (C) 2012,2013 Alexander Shiyan <shc_work@mail.ru>
|
2012-10-09 20:05:56 +04:00
|
|
|
*/
|
|
|
|
|
2013-04-26 19:47:28 +04:00
|
|
|
#include <linux/err.h>
|
2012-10-09 20:05:56 +04:00
|
|
|
#include <linux/module.h>
|
2015-12-04 16:02:58 +03:00
|
|
|
#include <linux/gpio/driver.h>
|
2012-10-09 20:05:56 +04:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2013-04-26 19:47:28 +04:00
|
|
|
static int clps711x_gpio_probe(struct platform_device *pdev)
|
2012-10-09 20:05:56 +04:00
|
|
|
{
|
2013-04-26 19:47:30 +04:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2013-04-26 19:47:28 +04:00
|
|
|
void __iomem *dat, *dir;
|
2015-12-04 16:02:58 +03:00
|
|
|
struct gpio_chip *gc;
|
2016-06-04 10:10:12 +03:00
|
|
|
int err, id;
|
2012-10-09 20:05:56 +04:00
|
|
|
|
2016-06-04 10:10:12 +03:00
|
|
|
if (!np)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
id = of_alias_get_id(np, "gpio");
|
2013-04-26 19:47:28 +04:00
|
|
|
if ((id < 0) || (id > 4))
|
|
|
|
return -ENODEV;
|
2012-10-09 20:05:56 +04:00
|
|
|
|
2015-12-04 16:02:58 +03:00
|
|
|
gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
|
|
|
|
if (!gc)
|
2013-04-26 19:47:28 +04:00
|
|
|
return -ENOMEM;
|
2012-10-09 20:05:56 +04:00
|
|
|
|
2019-03-11 21:54:46 +03:00
|
|
|
dat = devm_platform_ioremap_resource(pdev, 0);
|
2013-04-26 19:47:28 +04:00
|
|
|
if (IS_ERR(dat))
|
|
|
|
return PTR_ERR(dat);
|
|
|
|
|
2019-03-11 21:54:46 +03:00
|
|
|
dir = devm_platform_ioremap_resource(pdev, 1);
|
2013-04-26 19:47:28 +04:00
|
|
|
if (IS_ERR(dir))
|
|
|
|
return PTR_ERR(dir);
|
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case 3:
|
|
|
|
/* PORTD is inverted logic for direction register */
|
2015-12-04 16:02:58 +03:00
|
|
|
err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
|
2013-04-26 19:47:28 +04:00
|
|
|
NULL, dir, 0);
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-04 16:02:58 +03:00
|
|
|
err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
|
2013-04-26 19:47:28 +04:00
|
|
|
dir, NULL, 0);
|
|
|
|
break;
|
|
|
|
}
|
2012-10-09 20:05:56 +04:00
|
|
|
|
2013-04-26 19:47:28 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
2012-10-09 20:05:56 +04:00
|
|
|
|
2013-04-26 19:47:28 +04:00
|
|
|
switch (id) {
|
|
|
|
case 4:
|
|
|
|
/* PORTE is 3 lines only */
|
2015-12-04 16:02:58 +03:00
|
|
|
gc->ngpio = 3;
|
2013-04-26 19:47:28 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-24 12:34:46 +04:00
|
|
|
|
2016-06-04 10:10:12 +03:00
|
|
|
gc->base = -1;
|
2015-12-04 16:02:58 +03:00
|
|
|
gc->owner = THIS_MODULE;
|
|
|
|
platform_set_drvdata(pdev, gc);
|
2012-10-24 12:34:46 +04:00
|
|
|
|
2016-02-22 15:13:28 +03:00
|
|
|
return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
|
2012-10-24 12:34:46 +04:00
|
|
|
}
|
|
|
|
|
2013-12-24 18:08:53 +04:00
|
|
|
static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
|
2016-06-04 10:09:59 +03:00
|
|
|
{ .compatible = "cirrus,ep7209-gpio" },
|
2013-04-26 19:47:30 +04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, clps711x_gpio_ids);
|
|
|
|
|
2013-04-26 19:47:28 +04:00
|
|
|
static struct platform_driver clps711x_gpio_driver = {
|
|
|
|
.driver = {
|
2013-04-26 19:47:30 +04:00
|
|
|
.name = "clps711x-gpio",
|
2013-12-24 18:08:53 +04:00
|
|
|
.of_match_table = of_match_ptr(clps711x_gpio_ids),
|
2013-04-26 19:47:28 +04:00
|
|
|
},
|
|
|
|
.probe = clps711x_gpio_probe,
|
2012-10-09 20:05:56 +04:00
|
|
|
};
|
2013-04-26 19:47:28 +04:00
|
|
|
module_platform_driver(clps711x_gpio_driver);
|
2012-10-09 20:05:56 +04:00
|
|
|
|
2013-04-26 19:47:28 +04:00
|
|
|
MODULE_LICENSE("GPL");
|
2012-10-09 20:05:56 +04:00
|
|
|
MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
|
|
|
|
MODULE_DESCRIPTION("CLPS711X GPIO driver");
|
2014-02-04 13:39:15 +04:00
|
|
|
MODULE_ALIAS("platform:clps711x-gpio");
|