// SPDX-License-Identifier: GPL-2.0+ /* * Linux GPIOlib driver for the VIA VX855 integrated southbridge GPIO * * Copyright (C) 2009 VIA Technologies, Inc. * Copyright (C) 2010 One Laptop per Child * Author: Harald Welte <HaraldWelte@viatech.com> * All rights reserved.
*/ #include <linux/kernel.h> #include <linux/module.h> #include <linux/gpio/driver.h> #include <linux/slab.h> #include <linux/device.h> #include <linux/platform_device.h> #include <linux/pci.h> #include <linux/io.h>
#define MODULE_NAME "vx855_gpio"
/* The VX855 south bridge has the following GPIO pins: * GPI 0...13 General Purpose Input * GPO 0...12 General Purpose Output * GPIO 0...14 General Purpose I/O (Open-Drain)
*/
/* resolve a GPIx into the corresponding bit position */ staticinline u_int32_t gpi_i_bit(int i)
{ if (i < 10) return 1 << i; else return 1 << (i + 14);
}
staticinline u_int32_t gpo_o_bit(int i)
{ if (i < 11) return 1 << i; else return 1 << (i + 14);
}
staticinline u_int32_t gpio_i_bit(int i)
{ if (i < 14) return 1 << (i + 10); else return 1 << (i + 14);
}
staticinline u_int32_t gpio_o_bit(int i)
{ if (i < 14) return 1 << (i + 11); else return 1 << (i + 13);
}
/* Mapping between numeric GPIO ID and the actual GPIO hardware numbering: * 0..13 GPI 0..13 * 14..26 GPO 0..12 * 27..41 GPIO 0..14
*/
/* Real GPI bits are always in input direction */ if (nr < NR_VX855_GPI) return 0;
/* Real GPO bits cannot be put in output direction */ if (nr < NR_VX855_GPInO) return -EINVAL;
/* Open Drain GPIO have to be set to one */
spin_lock_irqsave(&vg->lock, flags);
reg_out = inl(vg->io_gpo);
reg_out |= gpio_o_bit(nr - NR_VX855_GPInO);
outl(reg_out, vg->io_gpo);
spin_unlock_irqrestore(&vg->lock, flags);
return 0;
}
staticint vx855gpio_get(struct gpio_chip *gpio, unsignedint nr)
{ struct vx855_gpio *vg = gpiochip_get_data(gpio);
u_int32_t reg_in; int ret = 0;
if (nr < NR_VX855_GPI) {
reg_in = inl(vg->io_gpi); if (reg_in & gpi_i_bit(nr))
ret = 1;
} elseif (nr < NR_VX855_GPInO) { /* GPO don't have an input bit, we need to read it
* back from the output register */
reg_in = inl(vg->io_gpo); if (reg_in & gpo_o_bit(nr - NR_VX855_GPI))
ret = 1;
} else {
reg_in = inl(vg->io_gpi); if (reg_in & gpio_i_bit(nr - NR_VX855_GPInO))
ret = 1;
}
staticint vx855gpio_direction_output(struct gpio_chip *gpio, unsignedint nr, int val)
{ /* True GPI cannot be switched to output mode */ if (nr < NR_VX855_GPI) return -EINVAL;
/* True GPO don't need to be switched to output mode, * and GPIO are open-drain, i.e. also need no switching,
* so all we do is set the level */
vx855gpio_set(gpio, nr, val);
/* * A single byte is used to control various GPIO ports on the VX855, * and in the case of the OLPC XO-1.5, some of those ports are used * for switches that are interpreted and exposed through ACPI. ACPI * will have reserved the region, so our own reservation will not * succeed. Ignore and continue.
*/
if (!devm_request_region(&pdev->dev, res_gpi->start,
resource_size(res_gpi), MODULE_NAME "_gpi"))
dev_warn(&pdev->dev, "GPI I/O resource busy, probably claimed by ACPI\n");
if (!devm_request_region(&pdev->dev, res_gpo->start,
resource_size(res_gpo), MODULE_NAME "_gpo"))
dev_warn(&pdev->dev, "GPO I/O resource busy, probably claimed by ACPI\n");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Harald Welte ");
MODULE_DESCRIPTION("GPIO driver for the VIA VX855 chipset");
MODULE_ALIAS("platform:vx855_gpio");
Messung V0.5
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.