mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-29 15:43:59 +08:00
2ec98f5678
Core: - When a gpio_chip request GPIOs from itself, it can now fully control the line characteristics, both machine and consumer flags. This makes a lot of sense, but took some time before I figured out that this is how it has to work. - Several smallish documentation fixes. New drivers: - The PCA953x driver now supports the TI TCA9539. - The DaVinci driver now supports the K3 AM654 SoCs. Driver improvements: - Major overhaul and hardening of the OMAP driver by Russell King. - Starting to move some drivers to the new API passing irq_chip along with the gpio_chip when adding the gpio_chip instead of adding it separately. Unrelated: - Delete the FMC subsystem. -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEElDRnuGcz/wPCXQWMQRCzN7AZXXMFAl0i7gEACgkQQRCzN7AZ XXOeUA/+JKyI2zebTWBcgtxhn6VQCufMCtFmQl2JkEcy4pT7aBJcGWqFQCBW2Szf VTtqc8nNa90SZoOzsNbkeQgRjNKGZruMbh0ARUPcW4v3ZJHtUNUEDLTo8c3iyTgS 9k/FTeaTLt4WSZujeAO0O7G4KNnOOlTKLh58dr0PmXUR+0v+fbMhcJqJ9ABueV+V qENdpkTuG1ZcvzgLhBBEXdt3Plw9ICLWmPXtwY+784ewucVPbyQX7jV4+bBZ25fL DerCuMIgL5vRWWdiFO6/Jp603rHzZpTnjLJJocXUFiD6zA5rvU2jTWxsnUttjisg 8cTLMyQspsDvBxhEhCJVTuIKotbKH900TSaz+vx20W72/A1euy4y6uVi8FGZo4Ww KDkzB7anwHyEFKGnlYgHzDrfctgZrhQoyFz808DQRYg1JseZB5oGVDvScrPBD43j nbNDd8gwG4yp3tFnDx9xjIwQy3Ax4d510rAZyUN2801IlbA1bueq4t6Z2cCucWzX XA1gCKlXe4BUeitRAoZtqZNZG1ymEysW4jXy1V8xrwtAf8+QSN+xO98akz3VpnQL ae9q+HtF76fDBY1xFSXT37Ma3+4OR2vMF9QWuo4TCb9j1cL7llf8ZxtUq9LEHbDu erKLSSnwSFmqJNGSEA5SulGOCR/tRPkClngE9x0XEM6gOD+bs6E= =8zSV -----END PGP SIGNATURE----- Merge tag 'gpio-v5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio Pull GPIO updates from Linus Walleij: "This is the big slew of GPIO changes for the v5.3 kernel cycle. This is mostly incremental work this time. Three important things: - The FMC subsystem is deleted through my tree. This happens through GPIO as its demise was discussed in relation to a patch decoupling its GPIO implementation from the standard way of handling GPIO. As it turns out, that is not the only subsystem it reimplements and the authors think it is better do scratch it and start over using the proper kernel subsystems than try to polish the rust shiny. See the commit (ACKed by the maintainers) for details. - Arnd made a small devres patch that was ACKed by Greg and goes into the device core. - SPDX header change colissions may happen, because at times I've seen that quite a lot changed during the -rc:s in regards to SPDX. (It is good stuff, tglx has me convinced, and it is worth the occasional pain.) Apart from this is is nothing controversial or problematic. Summary: Core: - When a gpio_chip request GPIOs from itself, it can now fully control the line characteristics, both machine and consumer flags. This makes a lot of sense, but took some time before I figured out that this is how it has to work. - Several smallish documentation fixes. New drivers: - The PCA953x driver now supports the TI TCA9539. - The DaVinci driver now supports the K3 AM654 SoCs. Driver improvements: - Major overhaul and hardening of the OMAP driver by Russell King. - Starting to move some drivers to the new API passing irq_chip along with the gpio_chip when adding the gpio_chip instead of adding it separately. Unrelated: - Delete the FMC subsystem" * tag 'gpio-v5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (87 commits) Revert "gpio: tegra: Clean-up debugfs initialisation" gpiolib: Use spinlock_t instead of struct spinlock gpio: stp-xway: allow compile-testing gpio: stp-xway: get rid of the #include <lantiq_soc.h> dependency gpio: stp-xway: improve module clock error handling gpio: stp-xway: simplify error handling in xway_stp_probe() gpiolib: Clarify use of non-sleeping functions gpiolib: Fix references to gpiod_[gs]et_*value_cansleep() variants gpiolib: Document new gpio_chip.init_valid_mask field Documentation: gpio: Fix reference to gpiod_get_array() gpio: pl061: drop duplicate printing of device name gpio: altera: Pass irqchip when adding gpiochip gpio: siox: Use devm_ managed gpiochip gpio: siox: Add struct device *dev helper variable gpio: siox: Pass irqchip when adding gpiochip drivers: gpio: amd-fch: make resource struct const devres: allow const resource arguments gpio: ath79: Pass irqchip when adding gpiochip gpio: tegra: Clean-up debugfs initialisation gpio: siox: Switch to IRQ_TYPE_NONE ...
201 lines
4.3 KiB
C
201 lines
4.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Janz MODULbus VMOD-TTL GPIO Driver
|
|
*
|
|
* Copyright (c) 2010 Ira W. Snyder <iws@ovro.caltech.edu>
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/io.h>
|
|
#include <linux/gpio/driver.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/mfd/janz.h>
|
|
|
|
#define DRV_NAME "janz-ttl"
|
|
|
|
#define PORTA_DIRECTION 0x23
|
|
#define PORTB_DIRECTION 0x2B
|
|
#define PORTC_DIRECTION 0x06
|
|
#define PORTA_IOCTL 0x24
|
|
#define PORTB_IOCTL 0x2C
|
|
#define PORTC_IOCTL 0x07
|
|
|
|
#define MASTER_INT_CTL 0x00
|
|
#define MASTER_CONF_CTL 0x01
|
|
|
|
#define CONF_PAE BIT(2)
|
|
#define CONF_PBE BIT(7)
|
|
#define CONF_PCE BIT(4)
|
|
|
|
struct ttl_control_regs {
|
|
__be16 portc;
|
|
__be16 portb;
|
|
__be16 porta;
|
|
__be16 control;
|
|
};
|
|
|
|
struct ttl_module {
|
|
struct gpio_chip gpio;
|
|
|
|
/* base address of registers */
|
|
struct ttl_control_regs __iomem *regs;
|
|
|
|
u8 portc_shadow;
|
|
u8 portb_shadow;
|
|
u8 porta_shadow;
|
|
|
|
spinlock_t lock;
|
|
};
|
|
|
|
static int ttl_get_value(struct gpio_chip *gpio, unsigned offset)
|
|
{
|
|
struct ttl_module *mod = dev_get_drvdata(gpio->parent);
|
|
u8 *shadow;
|
|
int ret;
|
|
|
|
if (offset < 8) {
|
|
shadow = &mod->porta_shadow;
|
|
} else if (offset < 16) {
|
|
shadow = &mod->portb_shadow;
|
|
offset -= 8;
|
|
} else {
|
|
shadow = &mod->portc_shadow;
|
|
offset -= 16;
|
|
}
|
|
|
|
spin_lock(&mod->lock);
|
|
ret = *shadow & BIT(offset);
|
|
spin_unlock(&mod->lock);
|
|
return !!ret;
|
|
}
|
|
|
|
static void ttl_set_value(struct gpio_chip *gpio, unsigned offset, int value)
|
|
{
|
|
struct ttl_module *mod = dev_get_drvdata(gpio->parent);
|
|
void __iomem *port;
|
|
u8 *shadow;
|
|
|
|
if (offset < 8) {
|
|
port = &mod->regs->porta;
|
|
shadow = &mod->porta_shadow;
|
|
} else if (offset < 16) {
|
|
port = &mod->regs->portb;
|
|
shadow = &mod->portb_shadow;
|
|
offset -= 8;
|
|
} else {
|
|
port = &mod->regs->portc;
|
|
shadow = &mod->portc_shadow;
|
|
offset -= 16;
|
|
}
|
|
|
|
spin_lock(&mod->lock);
|
|
if (value)
|
|
*shadow |= BIT(offset);
|
|
else
|
|
*shadow &= ~BIT(offset);
|
|
|
|
iowrite16be(*shadow, port);
|
|
spin_unlock(&mod->lock);
|
|
}
|
|
|
|
static void ttl_write_reg(struct ttl_module *mod, u8 reg, u16 val)
|
|
{
|
|
iowrite16be(reg, &mod->regs->control);
|
|
iowrite16be(val, &mod->regs->control);
|
|
}
|
|
|
|
static void ttl_setup_device(struct ttl_module *mod)
|
|
{
|
|
/* reset the device to a known state */
|
|
iowrite16be(0x0000, &mod->regs->control);
|
|
iowrite16be(0x0001, &mod->regs->control);
|
|
iowrite16be(0x0000, &mod->regs->control);
|
|
|
|
/* put all ports in open-drain mode */
|
|
ttl_write_reg(mod, PORTA_IOCTL, 0x00ff);
|
|
ttl_write_reg(mod, PORTB_IOCTL, 0x00ff);
|
|
ttl_write_reg(mod, PORTC_IOCTL, 0x000f);
|
|
|
|
/* set all ports as outputs */
|
|
ttl_write_reg(mod, PORTA_DIRECTION, 0x0000);
|
|
ttl_write_reg(mod, PORTB_DIRECTION, 0x0000);
|
|
ttl_write_reg(mod, PORTC_DIRECTION, 0x0000);
|
|
|
|
/* set all ports to drive zeroes */
|
|
iowrite16be(0x0000, &mod->regs->porta);
|
|
iowrite16be(0x0000, &mod->regs->portb);
|
|
iowrite16be(0x0000, &mod->regs->portc);
|
|
|
|
/* enable all ports */
|
|
ttl_write_reg(mod, MASTER_CONF_CTL, CONF_PAE | CONF_PBE | CONF_PCE);
|
|
}
|
|
|
|
static int ttl_probe(struct platform_device *pdev)
|
|
{
|
|
struct janz_platform_data *pdata;
|
|
struct ttl_module *mod;
|
|
struct gpio_chip *gpio;
|
|
int ret;
|
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
|
if (!pdata) {
|
|
dev_err(&pdev->dev, "no platform data\n");
|
|
return -ENXIO;
|
|
}
|
|
|
|
mod = devm_kzalloc(&pdev->dev, sizeof(*mod), GFP_KERNEL);
|
|
if (!mod)
|
|
return -ENOMEM;
|
|
|
|
platform_set_drvdata(pdev, mod);
|
|
spin_lock_init(&mod->lock);
|
|
|
|
/* get access to the MODULbus registers for this module */
|
|
mod->regs = devm_platform_ioremap_resource(pdev, 0);
|
|
if (IS_ERR(mod->regs))
|
|
return PTR_ERR(mod->regs);
|
|
|
|
ttl_setup_device(mod);
|
|
|
|
/* Initialize the GPIO data structures */
|
|
gpio = &mod->gpio;
|
|
gpio->parent = &pdev->dev;
|
|
gpio->label = pdev->name;
|
|
gpio->get = ttl_get_value;
|
|
gpio->set = ttl_set_value;
|
|
gpio->owner = THIS_MODULE;
|
|
|
|
/* request dynamic allocation */
|
|
gpio->base = -1;
|
|
gpio->ngpio = 20;
|
|
|
|
ret = devm_gpiochip_add_data(&pdev->dev, gpio, NULL);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "unable to add GPIO chip\n");
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver ttl_driver = {
|
|
.driver = {
|
|
.name = DRV_NAME,
|
|
},
|
|
.probe = ttl_probe,
|
|
};
|
|
|
|
module_platform_driver(ttl_driver);
|
|
|
|
MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>");
|
|
MODULE_DESCRIPTION("Janz MODULbus VMOD-TTL Driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("platform:janz-ttl");
|