mirror of
https://github.com/torvalds/linux.git
synced 2024-12-20 18:11:47 +00:00
1eccc6e152
Core infrastructural changes: - Support for natively single-ended GPIO driver stages. This means that if the hardware has registers to configure open drain or open source configuration, we use that rather than (as we did before) try to emulate it by switching the line to an input to get high impedance. This is also documented throughly in Documentation/gpio/driver.txt for those of you who did not understand one word of what I just wrote. - Start to do away with the unnecessarily complex and unitelligible ARCH_REQUIRE_GPIOLIB and ARCH_WANT_OPTIONAL_GPIOLIB, another evolutional artifact from the time when the GPIO subsystem was unmaintained. Archs can now just select GPIOLIB and be done with it, cleanups to arches will trickle in for the next kernel. Some minor archs ACKed the changes immediately so these are included in this pull request. - Advancing the use of the data pointer inside the GPIO device for storing driver data by switching the PowerPC, Super-H Unicore and a few other subarches or subsystem drivers in ALSA SoC, Input, serial, SSB, staging etc to use it. - The initialization now reads the input/output state of the GPIO lines, so that each GPIO descriptor knows - if this callback is implemented - whether the line is input or output. This also reflects nicely in userspace "lsgpio". - It is now possible to name GPIO producer names, line names, from the device tree. (Platform data has been supported for a while.) I bet we will get a similar mechanism for ACPI one of those days. This makes is possible to get sensible producer names for e.g. GPIO rails in "lsgpio" in userspace. New drivers: - New driver for the Loongson1. - The XLP driver now supports Broadcom Vulcan ARM64. - The IT87 driver now supports IT8620 and IT8628. - The PCA953X driver now supports Galileo Gen2. Driver improvements: - MCP23S08 was switched to use the gpiolib irqchip helpers and now also suppors level-triggered interrupts. - 74x164 and RCAR now supports the .set_multiple() callback - AMDPT was converted to use generic GPIO. - TC3589x, TPS65218, SX150X, F7188X, MENZ127, VX855, WM831X, WM8994 support the new single ended callback for open drain and in some cases open source. - Implement the .get_direction() callback for a few more drivers like PL061, Xgene. Cleanups: - Paul Gortmaker combed through the drivers and de-modularized those who are not really modules. - Move the GPIO poweroff DT bindings to the power subdir where they belong. - Rename gpio-generic.c to gpio-mmio.c, which is much more to the point. That's what it is handling, nothing more, nothing less. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABAgAGBQJXOuJ5AAoJEEEQszewGV1zNXsQAII5wtkP69WRJ3goYBKg1dZN DkuLqZyVI4hCgRhptzUW10gDLHKKOCVubfetTJHSpyG/dWDJXPCyH6FHF+pW6lMX y+em8kAvWctKpaosy4EM7O55/IohW0/fNCTOfzfrUNivjydFuA2XwPUiPqC7111O DeKlC/t+W1JEvZTiKMi83pKq+9wqhiHmD0qxRHhV57S+MT8e7mdlSKOp7uUkKPkg LPlerXosnmeFjL2emuSnKl/tq8pOyruU6uaIGG/uwpbo2W86Dok9GY2GWkQ4pANT pDtprc4aJ/Clf6Q0CoKwQbmAozqTDeJo+Und9tRs2KuZRly2bWOcyVE0lyK+Y4s0 544LcKw2q6cB9ARZ6JExEVRJejPISGKMqo9TaHkyNSIJoiiatKYvNS4WVeFtTgbI W+1WfM1svPymNRqVPO1PMLV+3m9dalDH2WjtaFF21uCAQ/G0AuPEHjEDbbx0HIpb qrvWmYzZ97Rm/LdYROFRO53nEdCp2jh6c3n4/2kGYM8H0suvGxXZsB1g4i+Dm+B+ qKVTS282azlDuH9ohXeXizeb6atK6s8TC3Rmew97SmXDO00cUQzEQO/ZquRLHY9r n83afQ4OL2Z9yruAxAk7pCshVSyheOsHuFPuZ7bwPW31VMdoWNRkhnaTUXMjGfYg 3y39IHrCKWNMCCVM1iNl =z4d6 -----END PGP SIGNATURE----- Merge tag 'gpio-v4.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio Pull GPIO updates from Linus Walleij: "This is the bulk of GPIO changes for kernel cycle v4.7: Core infrastructural changes: - Support for natively single-ended GPIO driver stages. This means that if the hardware has registers to configure open drain or open source configuration, we use that rather than (as we did before) try to emulate it by switching the line to an input to get high impedance. This is also documented throughly in Documentation/gpio/driver.txt for those of you who did not understand one word of what I just wrote. - Start to do away with the unnecessarily complex and unitelligible ARCH_REQUIRE_GPIOLIB and ARCH_WANT_OPTIONAL_GPIOLIB, another evolutional artifact from the time when the GPIO subsystem was unmaintained. Archs can now just select GPIOLIB and be done with it, cleanups to arches will trickle in for the next kernel. Some minor archs ACKed the changes immediately so these are included in this pull request. - Advancing the use of the data pointer inside the GPIO device for storing driver data by switching the PowerPC, Super-H Unicore and a few other subarches or subsystem drivers in ALSA SoC, Input, serial, SSB, staging etc to use it. - The initialization now reads the input/output state of the GPIO lines, so that each GPIO descriptor knows - if this callback is implemented - whether the line is input or output. This also reflects nicely in userspace "lsgpio". - It is now possible to name GPIO producer names, line names, from the device tree. (Platform data has been supported for a while). I bet we will get a similar mechanism for ACPI one of those days. This makes is possible to get sensible producer names for e.g. GPIO rails in "lsgpio" in userspace. New drivers: - New driver for the Loongson1. - The XLP driver now supports Broadcom Vulcan ARM64. - The IT87 driver now supports IT8620 and IT8628. - The PCA953X driver now supports Galileo Gen2. Driver improvements: - MCP23S08 was switched to use the gpiolib irqchip helpers and now also suppors level-triggered interrupts. - 74x164 and RCAR now supports the .set_multiple() callback - AMDPT was converted to use generic GPIO. - TC3589x, TPS65218, SX150X, F7188X, MENZ127, VX855, WM831X, WM8994 support the new single ended callback for open drain and in some cases open source. - Implement the .get_direction() callback for a few more drivers like PL061, Xgene. Cleanups: - Paul Gortmaker combed through the drivers and de-modularized those who are not really modules. - Move the GPIO poweroff DT bindings to the power subdir where they belong. - Rename gpio-generic.c to gpio-mmio.c, which is much more to the point. That's what it is handling, nothing more, nothing less" * tag 'gpio-v4.7-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (126 commits) MIPS: do away with ARCH_[WANT_OPTIONAL|REQUIRE]_GPIOLIB gpio: zevio: make it explicitly non-modular gpio: timberdale: make it explicitly non-modular gpio: stmpe: make it explicitly non-modular gpio: sodaville: make it explicitly non-modular pinctrl: sh-pfc: Let gpio_chip.to_irq() return zero on error gpio: dwapb: Add ACPI device ID for DWAPB GPIO controller on X-Gene platforms gpio: dt-bindings: add wd,mbl-gpio bindings gpio: of: make it possible to name GPIO lines gpio: make gpiod_to_irq() return negative for NO_IRQ gpio: xgene: implement .get_direction() gpio: xgene: Enable ACPI support for X-Gene GFC GPIO driver gpio: tegra: Implement gpio_get_direction callback gpio: set up initial state from .get_direction() gpio: rename gpio-generic.c into gpio-mmio.c gpio: generic: fix GPIO_GENERIC_PLATFORM is set to module case gpio: dwapb: add gpio-signaled acpi event support gpio: dwapb: convert device node to fwnode gpio: dwapb: remove name from dwapb_port_property gpio/qoriq: select IRQ_DOMAIN ...
249 lines
6.4 KiB
C
249 lines
6.4 KiB
C
/*
|
|
* AppliedMicro X-Gene SoC GPIO Driver
|
|
*
|
|
* Copyright (c) 2014, Applied Micro Circuits Corporation
|
|
* Author: Feng Kan <fkan@apm.com>.
|
|
*
|
|
* 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.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <linux/acpi.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/io.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/gpio/driver.h>
|
|
#include <linux/types.h>
|
|
#include <linux/bitops.h>
|
|
|
|
#define GPIO_SET_DR_OFFSET 0x0C
|
|
#define GPIO_DATA_OFFSET 0x14
|
|
#define GPIO_BANK_STRIDE 0x0C
|
|
|
|
#define XGENE_GPIOS_PER_BANK 16
|
|
#define XGENE_MAX_GPIO_BANKS 3
|
|
#define XGENE_MAX_GPIOS (XGENE_GPIOS_PER_BANK * XGENE_MAX_GPIO_BANKS)
|
|
|
|
#define GPIO_BIT_OFFSET(x) (x % XGENE_GPIOS_PER_BANK)
|
|
#define GPIO_BANK_OFFSET(x) ((x / XGENE_GPIOS_PER_BANK) * GPIO_BANK_STRIDE)
|
|
|
|
struct xgene_gpio {
|
|
struct gpio_chip chip;
|
|
void __iomem *base;
|
|
spinlock_t lock;
|
|
#ifdef CONFIG_PM
|
|
u32 set_dr_val[XGENE_MAX_GPIO_BANKS];
|
|
#endif
|
|
};
|
|
|
|
static int xgene_gpio_get(struct gpio_chip *gc, unsigned int offset)
|
|
{
|
|
struct xgene_gpio *chip = gpiochip_get_data(gc);
|
|
unsigned long bank_offset;
|
|
u32 bit_offset;
|
|
|
|
bank_offset = GPIO_DATA_OFFSET + GPIO_BANK_OFFSET(offset);
|
|
bit_offset = GPIO_BIT_OFFSET(offset);
|
|
return !!(ioread32(chip->base + bank_offset) & BIT(bit_offset));
|
|
}
|
|
|
|
static void __xgene_gpio_set(struct gpio_chip *gc, unsigned int offset, int val)
|
|
{
|
|
struct xgene_gpio *chip = gpiochip_get_data(gc);
|
|
unsigned long bank_offset;
|
|
u32 setval, bit_offset;
|
|
|
|
bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset);
|
|
bit_offset = GPIO_BIT_OFFSET(offset) + XGENE_GPIOS_PER_BANK;
|
|
|
|
setval = ioread32(chip->base + bank_offset);
|
|
if (val)
|
|
setval |= BIT(bit_offset);
|
|
else
|
|
setval &= ~BIT(bit_offset);
|
|
iowrite32(setval, chip->base + bank_offset);
|
|
}
|
|
|
|
static void xgene_gpio_set(struct gpio_chip *gc, unsigned int offset, int val)
|
|
{
|
|
struct xgene_gpio *chip = gpiochip_get_data(gc);
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&chip->lock, flags);
|
|
__xgene_gpio_set(gc, offset, val);
|
|
spin_unlock_irqrestore(&chip->lock, flags);
|
|
}
|
|
|
|
static int xgene_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
|
|
{
|
|
struct xgene_gpio *chip = gpiochip_get_data(gc);
|
|
unsigned long bank_offset, bit_offset;
|
|
|
|
bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset);
|
|
bit_offset = GPIO_BIT_OFFSET(offset);
|
|
|
|
return !!(ioread32(chip->base + bank_offset) & BIT(bit_offset));
|
|
}
|
|
|
|
static int xgene_gpio_dir_in(struct gpio_chip *gc, unsigned int offset)
|
|
{
|
|
struct xgene_gpio *chip = gpiochip_get_data(gc);
|
|
unsigned long flags, bank_offset;
|
|
u32 dirval, bit_offset;
|
|
|
|
bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset);
|
|
bit_offset = GPIO_BIT_OFFSET(offset);
|
|
|
|
spin_lock_irqsave(&chip->lock, flags);
|
|
|
|
dirval = ioread32(chip->base + bank_offset);
|
|
dirval |= BIT(bit_offset);
|
|
iowrite32(dirval, chip->base + bank_offset);
|
|
|
|
spin_unlock_irqrestore(&chip->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int xgene_gpio_dir_out(struct gpio_chip *gc,
|
|
unsigned int offset, int val)
|
|
{
|
|
struct xgene_gpio *chip = gpiochip_get_data(gc);
|
|
unsigned long flags, bank_offset;
|
|
u32 dirval, bit_offset;
|
|
|
|
bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset);
|
|
bit_offset = GPIO_BIT_OFFSET(offset);
|
|
|
|
spin_lock_irqsave(&chip->lock, flags);
|
|
|
|
dirval = ioread32(chip->base + bank_offset);
|
|
dirval &= ~BIT(bit_offset);
|
|
iowrite32(dirval, chip->base + bank_offset);
|
|
__xgene_gpio_set(gc, offset, val);
|
|
|
|
spin_unlock_irqrestore(&chip->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_PM
|
|
static int xgene_gpio_suspend(struct device *dev)
|
|
{
|
|
struct xgene_gpio *gpio = dev_get_drvdata(dev);
|
|
unsigned long bank_offset;
|
|
unsigned int bank;
|
|
|
|
for (bank = 0; bank < XGENE_MAX_GPIO_BANKS; bank++) {
|
|
bank_offset = GPIO_SET_DR_OFFSET + bank * GPIO_BANK_STRIDE;
|
|
gpio->set_dr_val[bank] = ioread32(gpio->base + bank_offset);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int xgene_gpio_resume(struct device *dev)
|
|
{
|
|
struct xgene_gpio *gpio = dev_get_drvdata(dev);
|
|
unsigned long bank_offset;
|
|
unsigned int bank;
|
|
|
|
for (bank = 0; bank < XGENE_MAX_GPIO_BANKS; bank++) {
|
|
bank_offset = GPIO_SET_DR_OFFSET + bank * GPIO_BANK_STRIDE;
|
|
iowrite32(gpio->set_dr_val[bank], gpio->base + bank_offset);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static SIMPLE_DEV_PM_OPS(xgene_gpio_pm, xgene_gpio_suspend, xgene_gpio_resume);
|
|
#define XGENE_GPIO_PM_OPS (&xgene_gpio_pm)
|
|
#else
|
|
#define XGENE_GPIO_PM_OPS NULL
|
|
#endif
|
|
|
|
static int xgene_gpio_probe(struct platform_device *pdev)
|
|
{
|
|
struct resource *res;
|
|
struct xgene_gpio *gpio;
|
|
int err = 0;
|
|
|
|
gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
|
|
if (!gpio) {
|
|
err = -ENOMEM;
|
|
goto err;
|
|
}
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (!res) {
|
|
err = -EINVAL;
|
|
goto err;
|
|
}
|
|
|
|
gpio->base = devm_ioremap_nocache(&pdev->dev, res->start,
|
|
resource_size(res));
|
|
if (!gpio->base) {
|
|
err = -ENOMEM;
|
|
goto err;
|
|
}
|
|
|
|
gpio->chip.ngpio = XGENE_MAX_GPIOS;
|
|
|
|
spin_lock_init(&gpio->lock);
|
|
gpio->chip.parent = &pdev->dev;
|
|
gpio->chip.get_direction = xgene_gpio_get_direction;
|
|
gpio->chip.direction_input = xgene_gpio_dir_in;
|
|
gpio->chip.direction_output = xgene_gpio_dir_out;
|
|
gpio->chip.get = xgene_gpio_get;
|
|
gpio->chip.set = xgene_gpio_set;
|
|
gpio->chip.label = dev_name(&pdev->dev);
|
|
gpio->chip.base = -1;
|
|
|
|
platform_set_drvdata(pdev, gpio);
|
|
|
|
err = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio);
|
|
if (err) {
|
|
dev_err(&pdev->dev,
|
|
"failed to register gpiochip.\n");
|
|
goto err;
|
|
}
|
|
|
|
dev_info(&pdev->dev, "X-Gene GPIO driver registered.\n");
|
|
return 0;
|
|
err:
|
|
dev_err(&pdev->dev, "X-Gene GPIO driver registration failed.\n");
|
|
return err;
|
|
}
|
|
|
|
static const struct of_device_id xgene_gpio_of_match[] = {
|
|
{ .compatible = "apm,xgene-gpio", },
|
|
{},
|
|
};
|
|
|
|
#ifdef CONFIG_ACPI
|
|
static const struct acpi_device_id xgene_gpio_acpi_match[] = {
|
|
{ "APMC0D14", 0 },
|
|
{ },
|
|
};
|
|
#endif
|
|
|
|
static struct platform_driver xgene_gpio_driver = {
|
|
.driver = {
|
|
.name = "xgene-gpio",
|
|
.of_match_table = xgene_gpio_of_match,
|
|
.acpi_match_table = ACPI_PTR(xgene_gpio_acpi_match),
|
|
.pm = XGENE_GPIO_PM_OPS,
|
|
},
|
|
.probe = xgene_gpio_probe,
|
|
};
|
|
builtin_platform_driver(xgene_gpio_driver);
|