Changes in 4.9.163 USB: serial: option: add Telit ME910 ECM composition USB: serial: cp210x: add ID for Ingenico 3070 USB: serial: ftdi_sio: add ID for Hjelmslund Electronics USB485 cpufreq: Use struct kobj_attribute instead of struct global_attr ncpfs: fix build warning of strncpy isdn: isdn_tty: fix build warning of strncpy staging: comedi: ni_660x: fix missing break in switch statement staging: wilc1000: fix to set correct value for 'vif_num' staging: android: ion: fix sys heap pool's gfp_flags ip6mr: Do not call __IP6_INC_STATS() from preemptible context net-sysfs: Fix mem leak in netdev_register_kobject sky2: Disable MSI on Dell Inspiron 1545 and Gateway P-79 team: Free BPF filter when unregistering netdev bnxt_en: Drop oversize TX packets to prevent errors. hv_netvsc: Fix IP header checksum for coalesced packets net: dsa: mv88e6xxx: Fix u64 statistics netlabel: fix out-of-bounds memory accesses net: netem: fix skb length BUG_ON in __skb_to_sgvec net: nfc: Fix NULL dereference on nfc_llcp_build_tlv fails net: sit: fix memory leak in sit_init_net() xen-netback: don't populate the hash cache on XenBus disconnect xen-netback: fix occasional leak of grant ref mappings under memory pressure net: Add __icmp_send helper. net: avoid use IPCB in cipso_v4_error tun: fix blocking read tun: remove unnecessary memory barrier net: phy: Micrel KSZ8061: link failure after cable connect x86/CPU/AMD: Set the CPB bit unconditionally on F17h applicom: Fix potential Spectre v1 vulnerabilities MIPS: irq: Allocate accurate order pages for irq stack hugetlbfs: fix races and page leaks during migration exec: Fix mem leak in kernel_read_file media: uvcvideo: Fix 'type' check leading to overflow vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel perf core: Fix perf_proc_update_handler() bug perf tools: Handle TOPOLOGY headers with no CPU IB/{hfi1, qib}: Fix WC.byte_len calculation for UD_SEND_WITH_IMM iommu/amd: Call free_iova_fast with pfn in map_sg iommu/amd: Unmap all mapped pages in error path of map_sg ipvs: Fix signed integer overflow when setsockopt timeout iommu/amd: Fix IOMMU page flush when detach device from a domain xtensa: SMP: fix ccount_timer_shutdown xtensa: SMP: fix secondary CPU initialization xtensa: smp_lx200_defconfig: fix vectors clash xtensa: SMP: mark each possible CPU as present xtensa: SMP: limit number of possible CPUs by NR_CPUS net: altera_tse: fix msgdma_tx_completion on non-zero fill_level case net: hns: Fix for missing of_node_put() after of_parse_phandle() net: hns: Fix wrong read accesses via Clause 45 MDIO protocol net: stmmac: dwmac-rk: fix error handling in rk_gmac_powerup() gpio: vf610: Mask all GPIO interrupts nfs: Fix NULL pointer dereference of dev_name qed: Fix VF probe failure while FLR scsi: libfc: free skb when receiving invalid flogi resp platform/x86: Fix unmet dependency warning for SAMSUNG_Q10 cifs: fix computation for MAX_SMB2_HDR_SIZE arm64: kprobe: Always blacklist the KVM world-switch code x86/kexec: Don't setup EFI info if EFI runtime is not enabled x86_64: increase stack size for KASAN_EXTRA mm, memory_hotplug: is_mem_section_removable do not pass the end of a zone mm, memory_hotplug: test_pages_in_a_zone do not pass the end of zone fs/drop_caches.c: avoid softlockups in drop_pagecache_sb() autofs: drop dentry reference only when it is never used autofs: fix error return in autofs_fill_super() soc: fsl: qbman: avoid race in clearing QMan interrupt ARM: pxa: ssp: unneeded to free devm_ allocated data arm64: dts: add msm8996 compatible to gicv3 usb: phy: fix link errors irqchip/mmp: Only touch the PJ4 IRQ & FIQ bits on enable/disable drm/sun4i: tcon: Prepare and enable TCON channel 0 clock at init dmaengine: at_xdmac: Fix wrongfull report of a channel as in use vsock/virtio: fix kernel panic after device hot-unplug vsock/virtio: reset connected sockets on device removal dmaengine: dmatest: Abort test in case of mapping error selftests: netfilter: fix config fragment CONFIG_NF_TABLES_INET selftests: netfilter: add simple masq/redirect test cases netfilter: nf_nat: skip nat clash resolution for same-origin entries s390/qeth: fix use-after-free in error path perf symbols: Filter out hidden symbols from labels MIPS: Remove function size check in get_frame_info() fs: ratelimit __find_get_block_slow() failure message. Input: wacom_serial4 - add support for Wacom ArtPad II tablet Input: elan_i2c - add id for touchpad found in Lenovo s21e-20 iscsi_ibft: Fix missing break in switch statement scsi: aacraid: Fix missing break in switch statement futex,rt_mutex: Restructure rt_mutex_finish_proxy_lock() ARM: dts: exynos: Fix pinctrl definition for eMMC RTSN line on Odroid X2/U3 ARM: dts: exynos: Add minimal clkout parameters to Exynos3250 PMU drm: disable uncached DMA optimization for ARM and arm64 ARM: 8781/1: Fix Thumb-2 syscall return for binutils 2.29+ ARM: dts: exynos: Do not ignore real-world fuse values for thermal zone 0 on Exynos5420 perf/x86/intel: Make cpuc allocations consistent perf/x86/intel: Generalize dynamic constraint creation x86: Add TSX Force Abort CPUID/MSR Linux 4.9.163 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
296 lines
7.2 KiB
C
296 lines
7.2 KiB
C
/*
|
|
* Freescale vf610 GPIO support through PORT and GPIO
|
|
*
|
|
* Copyright (c) 2014 Toradex AG.
|
|
*
|
|
* Author: Stefan Agner <stefan@agner.ch>.
|
|
*
|
|
* 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.
|
|
* 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.
|
|
*/
|
|
|
|
#include <linux/bitops.h>
|
|
#include <linux/err.h>
|
|
#include <linux/gpio.h>
|
|
#include <linux/init.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/io.h>
|
|
#include <linux/ioport.h>
|
|
#include <linux/irq.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_device.h>
|
|
#include <linux/of_irq.h>
|
|
|
|
#define VF610_GPIO_PER_PORT 32
|
|
|
|
struct vf610_gpio_port {
|
|
struct gpio_chip gc;
|
|
void __iomem *base;
|
|
void __iomem *gpio_base;
|
|
u8 irqc[VF610_GPIO_PER_PORT];
|
|
int irq;
|
|
};
|
|
|
|
#define GPIO_PDOR 0x00
|
|
#define GPIO_PSOR 0x04
|
|
#define GPIO_PCOR 0x08
|
|
#define GPIO_PTOR 0x0c
|
|
#define GPIO_PDIR 0x10
|
|
|
|
#define PORT_PCR(n) ((n) * 0x4)
|
|
#define PORT_PCR_IRQC_OFFSET 16
|
|
|
|
#define PORT_ISFR 0xa0
|
|
#define PORT_DFER 0xc0
|
|
#define PORT_DFCR 0xc4
|
|
#define PORT_DFWR 0xc8
|
|
|
|
#define PORT_INT_OFF 0x0
|
|
#define PORT_INT_LOGIC_ZERO 0x8
|
|
#define PORT_INT_RISING_EDGE 0x9
|
|
#define PORT_INT_FALLING_EDGE 0xa
|
|
#define PORT_INT_EITHER_EDGE 0xb
|
|
#define PORT_INT_LOGIC_ONE 0xc
|
|
|
|
static struct irq_chip vf610_gpio_irq_chip;
|
|
|
|
static const struct of_device_id vf610_gpio_dt_ids[] = {
|
|
{ .compatible = "fsl,vf610-gpio" },
|
|
{ /* sentinel */ }
|
|
};
|
|
|
|
static inline void vf610_gpio_writel(u32 val, void __iomem *reg)
|
|
{
|
|
writel_relaxed(val, reg);
|
|
}
|
|
|
|
static inline u32 vf610_gpio_readl(void __iomem *reg)
|
|
{
|
|
return readl_relaxed(reg);
|
|
}
|
|
|
|
static int vf610_gpio_get(struct gpio_chip *gc, unsigned int gpio)
|
|
{
|
|
struct vf610_gpio_port *port = gpiochip_get_data(gc);
|
|
|
|
return !!(vf610_gpio_readl(port->gpio_base + GPIO_PDIR) & BIT(gpio));
|
|
}
|
|
|
|
static void vf610_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
|
|
{
|
|
struct vf610_gpio_port *port = gpiochip_get_data(gc);
|
|
unsigned long mask = BIT(gpio);
|
|
|
|
if (val)
|
|
vf610_gpio_writel(mask, port->gpio_base + GPIO_PSOR);
|
|
else
|
|
vf610_gpio_writel(mask, port->gpio_base + GPIO_PCOR);
|
|
}
|
|
|
|
static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
|
|
{
|
|
return pinctrl_gpio_direction_input(chip->base + gpio);
|
|
}
|
|
|
|
static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
|
|
int value)
|
|
{
|
|
vf610_gpio_set(chip, gpio, value);
|
|
|
|
return pinctrl_gpio_direction_output(chip->base + gpio);
|
|
}
|
|
|
|
static void vf610_gpio_irq_handler(struct irq_desc *desc)
|
|
{
|
|
struct vf610_gpio_port *port =
|
|
gpiochip_get_data(irq_desc_get_handler_data(desc));
|
|
struct irq_chip *chip = irq_desc_get_chip(desc);
|
|
int pin;
|
|
unsigned long irq_isfr;
|
|
|
|
chained_irq_enter(chip, desc);
|
|
|
|
irq_isfr = vf610_gpio_readl(port->base + PORT_ISFR);
|
|
|
|
for_each_set_bit(pin, &irq_isfr, VF610_GPIO_PER_PORT) {
|
|
vf610_gpio_writel(BIT(pin), port->base + PORT_ISFR);
|
|
|
|
generic_handle_irq(irq_find_mapping(port->gc.irqdomain, pin));
|
|
}
|
|
|
|
chained_irq_exit(chip, desc);
|
|
}
|
|
|
|
static void vf610_gpio_irq_ack(struct irq_data *d)
|
|
{
|
|
struct vf610_gpio_port *port =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(d));
|
|
int gpio = d->hwirq;
|
|
|
|
vf610_gpio_writel(BIT(gpio), port->base + PORT_ISFR);
|
|
}
|
|
|
|
static int vf610_gpio_irq_set_type(struct irq_data *d, u32 type)
|
|
{
|
|
struct vf610_gpio_port *port =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(d));
|
|
u8 irqc;
|
|
|
|
switch (type) {
|
|
case IRQ_TYPE_EDGE_RISING:
|
|
irqc = PORT_INT_RISING_EDGE;
|
|
break;
|
|
case IRQ_TYPE_EDGE_FALLING:
|
|
irqc = PORT_INT_FALLING_EDGE;
|
|
break;
|
|
case IRQ_TYPE_EDGE_BOTH:
|
|
irqc = PORT_INT_EITHER_EDGE;
|
|
break;
|
|
case IRQ_TYPE_LEVEL_LOW:
|
|
irqc = PORT_INT_LOGIC_ZERO;
|
|
break;
|
|
case IRQ_TYPE_LEVEL_HIGH:
|
|
irqc = PORT_INT_LOGIC_ONE;
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
port->irqc[d->hwirq] = irqc;
|
|
|
|
if (type & IRQ_TYPE_LEVEL_MASK)
|
|
irq_set_handler_locked(d, handle_level_irq);
|
|
else
|
|
irq_set_handler_locked(d, handle_edge_irq);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void vf610_gpio_irq_mask(struct irq_data *d)
|
|
{
|
|
struct vf610_gpio_port *port =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(d));
|
|
void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
|
|
|
|
vf610_gpio_writel(0, pcr_base);
|
|
}
|
|
|
|
static void vf610_gpio_irq_unmask(struct irq_data *d)
|
|
{
|
|
struct vf610_gpio_port *port =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(d));
|
|
void __iomem *pcr_base = port->base + PORT_PCR(d->hwirq);
|
|
|
|
vf610_gpio_writel(port->irqc[d->hwirq] << PORT_PCR_IRQC_OFFSET,
|
|
pcr_base);
|
|
}
|
|
|
|
static int vf610_gpio_irq_set_wake(struct irq_data *d, u32 enable)
|
|
{
|
|
struct vf610_gpio_port *port =
|
|
gpiochip_get_data(irq_data_get_irq_chip_data(d));
|
|
|
|
if (enable)
|
|
enable_irq_wake(port->irq);
|
|
else
|
|
disable_irq_wake(port->irq);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct irq_chip vf610_gpio_irq_chip = {
|
|
.name = "gpio-vf610",
|
|
.irq_ack = vf610_gpio_irq_ack,
|
|
.irq_mask = vf610_gpio_irq_mask,
|
|
.irq_unmask = vf610_gpio_irq_unmask,
|
|
.irq_set_type = vf610_gpio_irq_set_type,
|
|
.irq_set_wake = vf610_gpio_irq_set_wake,
|
|
};
|
|
|
|
static int vf610_gpio_probe(struct platform_device *pdev)
|
|
{
|
|
struct device *dev = &pdev->dev;
|
|
struct device_node *np = dev->of_node;
|
|
struct vf610_gpio_port *port;
|
|
struct resource *iores;
|
|
struct gpio_chip *gc;
|
|
int i;
|
|
int ret;
|
|
|
|
port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
|
|
if (!port)
|
|
return -ENOMEM;
|
|
|
|
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
port->base = devm_ioremap_resource(dev, iores);
|
|
if (IS_ERR(port->base))
|
|
return PTR_ERR(port->base);
|
|
|
|
iores = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
port->gpio_base = devm_ioremap_resource(dev, iores);
|
|
if (IS_ERR(port->gpio_base))
|
|
return PTR_ERR(port->gpio_base);
|
|
|
|
port->irq = platform_get_irq(pdev, 0);
|
|
if (port->irq < 0)
|
|
return port->irq;
|
|
|
|
gc = &port->gc;
|
|
gc->of_node = np;
|
|
gc->parent = dev;
|
|
gc->label = "vf610-gpio";
|
|
gc->ngpio = VF610_GPIO_PER_PORT;
|
|
gc->base = of_alias_get_id(np, "gpio") * VF610_GPIO_PER_PORT;
|
|
|
|
gc->request = gpiochip_generic_request;
|
|
gc->free = gpiochip_generic_free;
|
|
gc->direction_input = vf610_gpio_direction_input;
|
|
gc->get = vf610_gpio_get;
|
|
gc->direction_output = vf610_gpio_direction_output;
|
|
gc->set = vf610_gpio_set;
|
|
|
|
ret = gpiochip_add_data(gc, port);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
/* Mask all GPIO interrupts */
|
|
for (i = 0; i < gc->ngpio; i++)
|
|
vf610_gpio_writel(0, port->base + PORT_PCR(i));
|
|
|
|
/* Clear the interrupt status register for all GPIO's */
|
|
vf610_gpio_writel(~0, port->base + PORT_ISFR);
|
|
|
|
ret = gpiochip_irqchip_add(gc, &vf610_gpio_irq_chip, 0,
|
|
handle_edge_irq, IRQ_TYPE_NONE);
|
|
if (ret) {
|
|
dev_err(dev, "failed to add irqchip\n");
|
|
gpiochip_remove(gc);
|
|
return ret;
|
|
}
|
|
gpiochip_set_chained_irqchip(gc, &vf610_gpio_irq_chip, port->irq,
|
|
vf610_gpio_irq_handler);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver vf610_gpio_driver = {
|
|
.driver = {
|
|
.name = "gpio-vf610",
|
|
.of_match_table = vf610_gpio_dt_ids,
|
|
},
|
|
.probe = vf610_gpio_probe,
|
|
};
|
|
|
|
static int __init gpio_vf610_init(void)
|
|
{
|
|
return platform_driver_register(&vf610_gpio_driver);
|
|
}
|
|
device_initcall(gpio_vf610_init);
|