2012-10-09 23:05:56 +07:00
|
|
|
/*
|
|
|
|
* CLPS711X GPIO driver
|
|
|
|
*
|
2013-04-26 22:47:28 +07:00
|
|
|
* Copyright (C) 2012,2013 Alexander Shiyan <shc_work@mail.ru>
|
2012-10-09 23:05:56 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2013-04-26 22:47:28 +07:00
|
|
|
#include <linux/err.h>
|
2012-10-09 23:05:56 +07:00
|
|
|
#include <linux/module.h>
|
2015-12-04 20:02:58 +07:00
|
|
|
#include <linux/gpio/driver.h>
|
2012-10-09 23:05:56 +07:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2013-04-26 22:47:28 +07:00
|
|
|
static int clps711x_gpio_probe(struct platform_device *pdev)
|
2012-10-09 23:05:56 +07:00
|
|
|
{
|
2013-04-26 22:47:30 +07:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2013-04-26 22:47:28 +07:00
|
|
|
void __iomem *dat, *dir;
|
2015-12-04 20:02:58 +07:00
|
|
|
struct gpio_chip *gc;
|
2013-04-26 22:47:28 +07:00
|
|
|
struct resource *res;
|
2016-06-04 14:10:12 +07:00
|
|
|
int err, id;
|
2012-10-09 23:05:56 +07:00
|
|
|
|
2016-06-04 14:10:12 +07:00
|
|
|
if (!np)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
id = of_alias_get_id(np, "gpio");
|
2013-04-26 22:47:28 +07:00
|
|
|
if ((id < 0) || (id > 4))
|
|
|
|
return -ENODEV;
|
2012-10-09 23:05:56 +07:00
|
|
|
|
2015-12-04 20:02:58 +07:00
|
|
|
gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
|
|
|
|
if (!gc)
|
2013-04-26 22:47:28 +07:00
|
|
|
return -ENOMEM;
|
2012-10-09 23:05:56 +07:00
|
|
|
|
2013-04-26 22:47:28 +07:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
dat = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(dat))
|
|
|
|
return PTR_ERR(dat);
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
|
|
dir = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(dir))
|
|
|
|
return PTR_ERR(dir);
|
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case 3:
|
|
|
|
/* PORTD is inverted logic for direction register */
|
2015-12-04 20:02:58 +07:00
|
|
|
err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
|
2013-04-26 22:47:28 +07:00
|
|
|
NULL, dir, 0);
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-04 20:02:58 +07:00
|
|
|
err = bgpio_init(gc, &pdev->dev, 1, dat, NULL, NULL,
|
2013-04-26 22:47:28 +07:00
|
|
|
dir, NULL, 0);
|
|
|
|
break;
|
|
|
|
}
|
2012-10-09 23:05:56 +07:00
|
|
|
|
2013-04-26 22:47:28 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
2012-10-09 23:05:56 +07:00
|
|
|
|
2013-04-26 22:47:28 +07:00
|
|
|
switch (id) {
|
|
|
|
case 4:
|
|
|
|
/* PORTE is 3 lines only */
|
2015-12-04 20:02:58 +07:00
|
|
|
gc->ngpio = 3;
|
2013-04-26 22:47:28 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-24 15:34:46 +07:00
|
|
|
|
2016-06-04 14:10:12 +07:00
|
|
|
gc->base = -1;
|
2015-12-04 20:02:58 +07:00
|
|
|
gc->owner = THIS_MODULE;
|
|
|
|
platform_set_drvdata(pdev, gc);
|
2012-10-24 15:34:46 +07:00
|
|
|
|
2016-02-22 19:13:28 +07:00
|
|
|
return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
|
2012-10-24 15:34:46 +07:00
|
|
|
}
|
|
|
|
|
2013-12-24 21:08:53 +07:00
|
|
|
static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
|
2016-06-04 14:09:59 +07:00
|
|
|
{ .compatible = "cirrus,ep7209-gpio" },
|
2013-04-26 22:47:30 +07:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, clps711x_gpio_ids);
|
|
|
|
|
2013-04-26 22:47:28 +07:00
|
|
|
static struct platform_driver clps711x_gpio_driver = {
|
|
|
|
.driver = {
|
2013-04-26 22:47:30 +07:00
|
|
|
.name = "clps711x-gpio",
|
2013-12-24 21:08:53 +07:00
|
|
|
.of_match_table = of_match_ptr(clps711x_gpio_ids),
|
2013-04-26 22:47:28 +07:00
|
|
|
},
|
|
|
|
.probe = clps711x_gpio_probe,
|
2012-10-09 23:05:56 +07:00
|
|
|
};
|
2013-04-26 22:47:28 +07:00
|
|
|
module_platform_driver(clps711x_gpio_driver);
|
2012-10-09 23:05:56 +07:00
|
|
|
|
2013-04-26 22:47:28 +07:00
|
|
|
MODULE_LICENSE("GPL");
|
2012-10-09 23:05:56 +07:00
|
|
|
MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
|
|
|
|
MODULE_DESCRIPTION("CLPS711X GPIO driver");
|
2014-02-04 16:39:15 +07:00
|
|
|
MODULE_ALIAS("platform:clps711x-gpio");
|