2011-01-05 04:28:15 +08:00
|
|
|
/*
|
|
|
|
* Atheros AR71XX/AR724X/AR913X GPIO API support
|
|
|
|
*
|
2012-03-14 17:45:23 +08:00
|
|
|
* Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
|
|
|
|
* Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
|
2011-01-05 04:28:15 +08:00
|
|
|
* Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
|
|
|
|
*
|
2012-03-14 17:45:23 +08:00
|
|
|
* Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
|
|
|
|
*
|
2011-01-05 04:28:15 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
|
|
* by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
2015-09-01 17:38:02 +08:00
|
|
|
#include <linux/gpio/driver.h>
|
2015-05-31 08:18:24 +08:00
|
|
|
#include <linux/platform_data/gpio-ath79.h>
|
|
|
|
#include <linux/of_device.h>
|
2011-01-05 04:28:15 +08:00
|
|
|
|
2016-01-29 03:44:30 +08:00
|
|
|
#define AR71XX_GPIO_REG_OE 0x00
|
|
|
|
#define AR71XX_GPIO_REG_IN 0x04
|
|
|
|
#define AR71XX_GPIO_REG_SET 0x0c
|
|
|
|
#define AR71XX_GPIO_REG_CLEAR 0x10
|
2011-01-05 04:28:15 +08:00
|
|
|
|
2015-09-01 17:38:02 +08:00
|
|
|
struct ath79_gpio_ctrl {
|
2016-01-29 03:44:29 +08:00
|
|
|
struct gpio_chip gc;
|
2015-09-01 17:38:02 +08:00
|
|
|
void __iomem *base;
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
|
|
|
|
2015-05-31 08:18:24 +08:00
|
|
|
static const struct of_device_id ath79_gpio_of_match[] = {
|
|
|
|
{ .compatible = "qca,ar7100-gpio" },
|
|
|
|
{ .compatible = "qca,ar9340-gpio" },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ath79_gpio_probe(struct platform_device *pdev)
|
2011-01-05 04:28:15 +08:00
|
|
|
{
|
2015-11-23 23:23:18 +08:00
|
|
|
struct ath79_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2015-05-31 08:18:24 +08:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2015-09-01 17:38:02 +08:00
|
|
|
struct ath79_gpio_ctrl *ctrl;
|
2015-05-31 08:18:24 +08:00
|
|
|
struct resource *res;
|
2015-09-01 17:38:02 +08:00
|
|
|
u32 ath79_gpio_count;
|
2015-05-31 08:18:24 +08:00
|
|
|
bool oe_inverted;
|
2011-01-05 04:28:15 +08:00
|
|
|
int err;
|
|
|
|
|
2015-09-01 17:38:02 +08:00
|
|
|
ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL);
|
|
|
|
if (!ctrl)
|
|
|
|
return -ENOMEM;
|
2016-01-29 03:44:31 +08:00
|
|
|
platform_set_drvdata(pdev, ctrl);
|
2015-09-01 17:38:02 +08:00
|
|
|
|
2015-05-31 08:18:24 +08:00
|
|
|
if (np) {
|
|
|
|
err = of_property_read_u32(np, "ngpios", &ath79_gpio_count);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "ngpios property is not valid\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (ath79_gpio_count >= 32) {
|
|
|
|
dev_err(&pdev->dev, "ngpios must be less than 32\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
oe_inverted = of_device_is_compatible(np, "qca,ar9340-gpio");
|
|
|
|
} else if (pdata) {
|
|
|
|
ath79_gpio_count = pdata->ngpios;
|
|
|
|
oe_inverted = pdata->oe_inverted;
|
|
|
|
} else {
|
|
|
|
dev_err(&pdev->dev, "No DT node or platform data found\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2015-09-01 17:38:02 +08:00
|
|
|
ctrl->base = devm_ioremap_nocache(
|
2015-05-31 08:18:24 +08:00
|
|
|
&pdev->dev, res->start, resource_size(res));
|
2015-09-01 17:38:02 +08:00
|
|
|
if (!ctrl->base)
|
2015-05-31 08:18:24 +08:00
|
|
|
return -ENOMEM;
|
2011-01-05 04:28:15 +08:00
|
|
|
|
2015-09-01 17:38:02 +08:00
|
|
|
spin_lock_init(&ctrl->lock);
|
2016-01-29 03:44:29 +08:00
|
|
|
err = bgpio_init(&ctrl->gc, &pdev->dev, 4,
|
|
|
|
ctrl->base + AR71XX_GPIO_REG_IN,
|
|
|
|
ctrl->base + AR71XX_GPIO_REG_SET,
|
|
|
|
ctrl->base + AR71XX_GPIO_REG_CLEAR,
|
|
|
|
oe_inverted ? NULL : ctrl->base + AR71XX_GPIO_REG_OE,
|
|
|
|
oe_inverted ? ctrl->base + AR71XX_GPIO_REG_OE : NULL,
|
|
|
|
0);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "bgpio_init failed\n");
|
|
|
|
return err;
|
2012-03-14 17:45:23 +08:00
|
|
|
}
|
2016-01-29 03:44:29 +08:00
|
|
|
/* Use base 0 to stay compatible with legacy platforms */
|
|
|
|
ctrl->gc.base = 0;
|
2011-01-05 04:28:15 +08:00
|
|
|
|
2016-01-29 03:44:29 +08:00
|
|
|
err = gpiochip_add_data(&ctrl->gc, ctrl);
|
2015-05-31 08:18:24 +08:00
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"cannot add AR71xx GPIO chip, error=%d", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-01-05 04:28:15 +08:00
|
|
|
}
|
|
|
|
|
2016-01-29 03:44:31 +08:00
|
|
|
static int ath79_gpio_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct ath79_gpio_ctrl *ctrl = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
gpiochip_remove(&ctrl->gc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-31 08:18:24 +08:00
|
|
|
static struct platform_driver ath79_gpio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "ath79-gpio",
|
|
|
|
.of_match_table = ath79_gpio_of_match,
|
|
|
|
},
|
|
|
|
.probe = ath79_gpio_probe,
|
2016-01-29 03:44:31 +08:00
|
|
|
.remove = ath79_gpio_remove,
|
2015-05-31 08:18:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(ath79_gpio_driver);
|