2018-08-22 22:41:03 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-04-16 02:56:35 +01:00
|
|
|
/*
|
|
|
|
* Generic EP93xx GPIO handling
|
|
|
|
*
|
2011-06-15 14:45:36 +10:00
|
|
|
* Copyright (c) 2008 Ryan Mallon
|
2011-06-08 14:35:33 -07:00
|
|
|
* Copyright (c) 2011 H Hartley Sweeten <hsweeten@visionengravers.com>
|
2008-04-16 02:56:35 +01:00
|
|
|
*
|
|
|
|
* Based on code originally from:
|
|
|
|
* linux/arch/arm/mach-ep93xx/core.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
2011-07-03 13:38:09 -04:00
|
|
|
#include <linux/module.h>
|
2011-06-08 14:35:33 -07:00
|
|
|
#include <linux/platform_device.h>
|
2024-09-09 11:10:50 +03:00
|
|
|
#include <linux/interrupt.h>
|
2008-09-06 12:10:45 +01:00
|
|
|
#include <linux/io.h>
|
2009-07-15 21:31:46 +01:00
|
|
|
#include <linux/irq.h>
|
2011-06-08 14:35:33 -07:00
|
|
|
#include <linux/slab.h>
|
2015-12-04 14:02:58 +01:00
|
|
|
#include <linux/gpio/driver.h>
|
2018-08-22 22:41:08 +02:00
|
|
|
#include <linux/bitops.h>
|
2023-01-25 11:30:25 +03:00
|
|
|
#include <linux/seq_file.h>
|
2018-08-22 22:41:10 +02:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
struct ep93xx_gpio_irq_chip {
|
2024-09-09 11:10:26 +03:00
|
|
|
void __iomem *base;
|
2021-02-09 16:31:04 +03:00
|
|
|
u8 int_unmasked;
|
|
|
|
u8 int_enabled;
|
|
|
|
u8 int_type1;
|
|
|
|
u8 int_type2;
|
|
|
|
u8 int_debounce;
|
2011-06-08 14:35:33 -07:00
|
|
|
};
|
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
struct ep93xx_gpio_chip {
|
2024-09-09 11:10:26 +03:00
|
|
|
void __iomem *base;
|
2021-02-09 16:31:04 +03:00
|
|
|
struct gpio_chip gc;
|
|
|
|
struct ep93xx_gpio_irq_chip *eic;
|
|
|
|
};
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
#define to_ep93xx_gpio_chip(x) container_of(x, struct ep93xx_gpio_chip, gc)
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
static struct ep93xx_gpio_irq_chip *to_ep93xx_gpio_irq_chip(struct gpio_chip *gc)
|
|
|
|
{
|
|
|
|
struct ep93xx_gpio_chip *egc = to_ep93xx_gpio_chip(gc);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
return egc->eic;
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
/*************************************************************************
|
|
|
|
* Interrupt handling for EP93xx on-chip GPIOs
|
|
|
|
*************************************************************************/
|
|
|
|
#define EP93XX_INT_TYPE1_OFFSET 0x00
|
|
|
|
#define EP93XX_INT_TYPE2_OFFSET 0x04
|
|
|
|
#define EP93XX_INT_EOI_OFFSET 0x08
|
|
|
|
#define EP93XX_INT_EN_OFFSET 0x0c
|
|
|
|
#define EP93XX_INT_STATUS_OFFSET 0x10
|
|
|
|
#define EP93XX_INT_RAW_STATUS_OFFSET 0x14
|
|
|
|
#define EP93XX_INT_DEBOUNCE_OFFSET 0x18
|
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
static void ep93xx_gpio_update_int_params(struct ep93xx_gpio_irq_chip *eic)
|
2010-02-23 21:41:17 +01:00
|
|
|
{
|
2024-09-09 11:10:26 +03:00
|
|
|
writeb_relaxed(0, eic->base + EP93XX_INT_EN_OFFSET);
|
2018-08-22 22:41:07 +02:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
writeb_relaxed(eic->int_type2,
|
2024-09-09 11:10:26 +03:00
|
|
|
eic->base + EP93XX_INT_TYPE2_OFFSET);
|
2018-08-22 22:41:07 +02:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
writeb_relaxed(eic->int_type1,
|
2024-09-09 11:10:26 +03:00
|
|
|
eic->base + EP93XX_INT_TYPE1_OFFSET);
|
2018-08-22 22:41:07 +02:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
writeb_relaxed(eic->int_unmasked & eic->int_enabled,
|
2024-09-09 11:10:26 +03:00
|
|
|
eic->base + EP93XX_INT_EN_OFFSET);
|
2018-08-22 22:41:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ep93xx_gpio_int_debounce(struct gpio_chip *gc,
|
|
|
|
unsigned int offset, bool enable)
|
|
|
|
{
|
2021-02-09 16:31:04 +03:00
|
|
|
struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc);
|
2018-08-22 22:41:07 +02:00
|
|
|
int port_mask = BIT(offset);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
|
|
|
if (enable)
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_debounce |= port_mask;
|
2010-02-23 21:41:17 +01:00
|
|
|
else
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_debounce &= ~port_mask;
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
writeb(eic->int_debounce, eic->base + EP93XX_INT_DEBOUNCE_OFFSET);
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
static u32 ep93xx_gpio_ab_irq_handler(struct gpio_chip *gc)
|
2010-02-23 21:41:17 +01:00
|
|
|
{
|
2024-09-09 11:10:26 +03:00
|
|
|
struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc);
|
2018-08-22 22:41:09 +02:00
|
|
|
unsigned long stat;
|
|
|
|
int offset;
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
stat = readb(eic->base + EP93XX_INT_STATUS_OFFSET);
|
2018-08-22 22:41:11 +02:00
|
|
|
for_each_set_bit(offset, &stat, 8)
|
2024-09-09 11:10:26 +03:00
|
|
|
generic_handle_domain_irq(gc->irq.domain, offset);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
return stat;
|
|
|
|
}
|
2018-08-22 22:41:06 +02:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
static irqreturn_t ep93xx_ab_irq_handler(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
return IRQ_RETVAL(ep93xx_gpio_ab_irq_handler(dev_id));
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2015-09-14 10:42:37 +02:00
|
|
|
static void ep93xx_gpio_f_irq_handler(struct irq_desc *desc)
|
2010-02-23 21:41:17 +01:00
|
|
|
{
|
2018-08-22 22:41:06 +02:00
|
|
|
struct irq_chip *irqchip = irq_desc_get_chip(desc);
|
2024-09-09 11:10:26 +03:00
|
|
|
struct gpio_chip *gc = irq_desc_get_handler_data(desc);
|
|
|
|
struct gpio_irq_chip *gic = &gc->irq;
|
|
|
|
unsigned int parent = irq_desc_get_irq(desc);
|
|
|
|
unsigned int i;
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2018-08-22 22:41:06 +02:00
|
|
|
chained_irq_enter(irqchip, desc);
|
2024-09-09 11:10:26 +03:00
|
|
|
for (i = 0; i < gic->num_parents; i++)
|
|
|
|
if (gic->parents[i] == parent)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i < gic->num_parents)
|
|
|
|
generic_handle_domain_irq(gc->irq.domain, i);
|
|
|
|
|
2018-08-22 22:41:06 +02:00
|
|
|
chained_irq_exit(irqchip, desc);
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2010-11-29 10:29:50 +01:00
|
|
|
static void ep93xx_gpio_irq_ack(struct irq_data *d)
|
2010-02-23 21:41:17 +01:00
|
|
|
{
|
2018-08-22 22:41:04 +02:00
|
|
|
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
|
2021-02-09 16:31:04 +03:00
|
|
|
struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc);
|
2024-09-09 11:10:26 +03:00
|
|
|
int port_mask = BIT(irqd_to_hwirq(d));
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2011-03-24 12:45:56 +01:00
|
|
|
if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type2 ^= port_mask; /* switch edge direction */
|
2024-09-09 11:10:26 +03:00
|
|
|
ep93xx_gpio_update_int_params(eic);
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
writeb(port_mask, eic->base + EP93XX_INT_EOI_OFFSET);
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2010-11-29 10:29:50 +01:00
|
|
|
static void ep93xx_gpio_irq_mask_ack(struct irq_data *d)
|
2010-02-23 21:41:17 +01:00
|
|
|
{
|
2018-08-22 22:41:04 +02:00
|
|
|
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
|
2021-02-09 16:31:04 +03:00
|
|
|
struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc);
|
2024-09-09 11:10:50 +03:00
|
|
|
irq_hw_number_t hwirq = irqd_to_hwirq(d);
|
|
|
|
int port_mask = BIT(hwirq);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2011-03-24 12:45:56 +01:00
|
|
|
if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH)
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type2 ^= port_mask; /* switch edge direction */
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_unmasked &= ~port_mask;
|
2024-09-09 11:10:26 +03:00
|
|
|
ep93xx_gpio_update_int_params(eic);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
writeb(port_mask, eic->base + EP93XX_INT_EOI_OFFSET);
|
2024-09-09 11:10:50 +03:00
|
|
|
gpiochip_disable_irq(gc, hwirq);
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2010-11-29 10:29:50 +01:00
|
|
|
static void ep93xx_gpio_irq_mask(struct irq_data *d)
|
2010-02-23 21:41:17 +01:00
|
|
|
{
|
2018-08-22 22:41:04 +02:00
|
|
|
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
|
2021-02-09 16:31:04 +03:00
|
|
|
struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc);
|
2024-09-09 11:10:50 +03:00
|
|
|
irq_hw_number_t hwirq = irqd_to_hwirq(d);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2024-09-09 11:10:50 +03:00
|
|
|
eic->int_unmasked &= ~BIT(hwirq);
|
2024-09-09 11:10:26 +03:00
|
|
|
ep93xx_gpio_update_int_params(eic);
|
2024-09-09 11:10:50 +03:00
|
|
|
gpiochip_disable_irq(gc, hwirq);
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2010-11-29 10:29:50 +01:00
|
|
|
static void ep93xx_gpio_irq_unmask(struct irq_data *d)
|
2010-02-23 21:41:17 +01:00
|
|
|
{
|
2018-08-22 22:41:04 +02:00
|
|
|
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
|
2021-02-09 16:31:04 +03:00
|
|
|
struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc);
|
2024-09-09 11:10:50 +03:00
|
|
|
irq_hw_number_t hwirq = irqd_to_hwirq(d);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2024-09-09 11:10:50 +03:00
|
|
|
gpiochip_enable_irq(gc, hwirq);
|
|
|
|
eic->int_unmasked |= BIT(hwirq);
|
2024-09-09 11:10:26 +03:00
|
|
|
ep93xx_gpio_update_int_params(eic);
|
2010-02-23 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gpio_int_type1 controls whether the interrupt is level (0) or
|
|
|
|
* edge (1) triggered, while gpio_int_type2 controls whether it
|
|
|
|
* triggers on low/falling (0) or high/rising (1).
|
|
|
|
*/
|
2010-11-29 10:29:50 +01:00
|
|
|
static int ep93xx_gpio_irq_type(struct irq_data *d, unsigned int type)
|
2010-02-23 21:41:17 +01:00
|
|
|
{
|
2018-08-22 22:41:04 +02:00
|
|
|
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
|
2021-02-09 16:31:04 +03:00
|
|
|
struct ep93xx_gpio_irq_chip *eic = to_ep93xx_gpio_irq_chip(gc);
|
2024-09-09 11:10:50 +03:00
|
|
|
irq_hw_number_t hwirq = irqd_to_hwirq(d);
|
|
|
|
int port_mask = BIT(hwirq);
|
2011-03-24 12:45:56 +01:00
|
|
|
irq_flow_handler_t handler;
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2024-09-09 11:10:50 +03:00
|
|
|
gc->direction_input(gc, hwirq);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case IRQ_TYPE_EDGE_RISING:
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type1 |= port_mask;
|
|
|
|
eic->int_type2 |= port_mask;
|
2011-03-24 12:45:56 +01:00
|
|
|
handler = handle_edge_irq;
|
2010-02-23 21:41:17 +01:00
|
|
|
break;
|
|
|
|
case IRQ_TYPE_EDGE_FALLING:
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type1 |= port_mask;
|
|
|
|
eic->int_type2 &= ~port_mask;
|
2011-03-24 12:45:56 +01:00
|
|
|
handler = handle_edge_irq;
|
2010-02-23 21:41:17 +01:00
|
|
|
break;
|
|
|
|
case IRQ_TYPE_LEVEL_HIGH:
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type1 &= ~port_mask;
|
|
|
|
eic->int_type2 |= port_mask;
|
2011-03-24 12:45:56 +01:00
|
|
|
handler = handle_level_irq;
|
2010-02-23 21:41:17 +01:00
|
|
|
break;
|
|
|
|
case IRQ_TYPE_LEVEL_LOW:
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type1 &= ~port_mask;
|
|
|
|
eic->int_type2 &= ~port_mask;
|
2011-03-24 12:45:56 +01:00
|
|
|
handler = handle_level_irq;
|
2010-02-23 21:41:17 +01:00
|
|
|
break;
|
|
|
|
case IRQ_TYPE_EDGE_BOTH:
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type1 |= port_mask;
|
2010-02-23 21:41:17 +01:00
|
|
|
/* set initial polarity based on current input level */
|
2024-09-09 11:10:50 +03:00
|
|
|
if (gc->get(gc, hwirq))
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type2 &= ~port_mask; /* falling */
|
2010-02-23 21:41:17 +01:00
|
|
|
else
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_type2 |= port_mask; /* rising */
|
2011-03-24 12:45:56 +01:00
|
|
|
handler = handle_edge_irq;
|
2010-02-23 21:41:17 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:52:38 +02:00
|
|
|
irq_set_handler_locked(d, handler);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2021-02-09 16:31:04 +03:00
|
|
|
eic->int_enabled |= port_mask;
|
2010-02-23 21:41:17 +01:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
ep93xx_gpio_update_int_params(eic);
|
2010-02-23 21:41:17 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-22 22:41:04 +02:00
|
|
|
static int ep93xx_gpio_set_config(struct gpio_chip *gc, unsigned offset,
|
2017-01-23 15:34:34 +03:00
|
|
|
unsigned long config)
|
2008-04-16 02:56:35 +01:00
|
|
|
{
|
2017-01-23 15:34:34 +03:00
|
|
|
u32 debounce;
|
|
|
|
|
|
|
|
if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
|
|
|
|
return -ENOTSUPP;
|
2008-04-16 02:56:35 +01:00
|
|
|
|
2017-01-23 15:34:34 +03:00
|
|
|
debounce = pinconf_to_config_argument(config);
|
2018-08-22 22:41:07 +02:00
|
|
|
ep93xx_gpio_int_debounce(gc, offset, debounce ? true : false);
|
2008-04-16 02:56:35 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-25 11:30:25 +03:00
|
|
|
static void ep93xx_irq_print_chip(struct irq_data *data, struct seq_file *p)
|
2021-02-09 16:31:05 +03:00
|
|
|
{
|
2023-01-25 11:30:25 +03:00
|
|
|
struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
|
|
|
|
|
2024-11-20 13:30:55 +08:00
|
|
|
seq_puts(p, dev_name(gc->parent));
|
2021-02-09 16:31:05 +03:00
|
|
|
}
|
|
|
|
|
2023-01-25 11:30:25 +03:00
|
|
|
static const struct irq_chip gpio_eic_irq_chip = {
|
|
|
|
.name = "ep93xx-gpio-eic",
|
|
|
|
.irq_ack = ep93xx_gpio_irq_ack,
|
|
|
|
.irq_mask = ep93xx_gpio_irq_mask,
|
|
|
|
.irq_unmask = ep93xx_gpio_irq_unmask,
|
|
|
|
.irq_mask_ack = ep93xx_gpio_irq_mask_ack,
|
|
|
|
.irq_set_type = ep93xx_gpio_irq_type,
|
|
|
|
.irq_print_chip = ep93xx_irq_print_chip,
|
|
|
|
.flags = IRQCHIP_IMMUTABLE,
|
|
|
|
GPIOCHIP_IRQ_RESOURCE_HELPERS,
|
|
|
|
};
|
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
static int ep93xx_setup_irqs(struct platform_device *pdev,
|
|
|
|
struct ep93xx_gpio_chip *egc)
|
2008-04-16 02:56:35 +01:00
|
|
|
{
|
2021-02-09 16:31:04 +03:00
|
|
|
struct gpio_chip *gc = &egc->gc;
|
2019-08-12 15:00:00 +02:00
|
|
|
struct device *dev = &pdev->dev;
|
2024-09-09 11:10:26 +03:00
|
|
|
struct gpio_irq_chip *girq = &gc->irq;
|
|
|
|
int ret, irq, i;
|
|
|
|
void __iomem *intr;
|
2019-08-12 15:00:00 +02:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
intr = devm_platform_ioremap_resource_byname(pdev, "intr");
|
|
|
|
if (IS_ERR(intr))
|
|
|
|
return PTR_ERR(intr);
|
|
|
|
|
|
|
|
gc->set_config = ep93xx_gpio_set_config;
|
|
|
|
egc->eic = devm_kzalloc(dev, sizeof(*egc->eic), GFP_KERNEL);
|
|
|
|
if (!egc->eic)
|
|
|
|
return -ENOMEM;
|
2019-08-12 15:00:00 +02:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
egc->eic->base = intr;
|
|
|
|
gpio_irq_chip_set_chip(girq, &gpio_eic_irq_chip);
|
|
|
|
girq->num_parents = platform_irq_count(pdev);
|
|
|
|
if (girq->num_parents == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2024-09-09 11:10:50 +03:00
|
|
|
girq->parents = devm_kcalloc(dev, girq->num_parents, sizeof(*girq->parents),
|
|
|
|
GFP_KERNEL);
|
2024-09-09 11:10:26 +03:00
|
|
|
if (!girq->parents)
|
|
|
|
return -ENOMEM;
|
2019-08-12 15:00:00 +02:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
if (girq->num_parents == 1) { /* A/B irqchips */
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0)
|
|
|
|
return irq;
|
|
|
|
|
|
|
|
ret = devm_request_irq(dev, irq, ep93xx_ab_irq_handler,
|
|
|
|
IRQF_SHARED, gc->label, gc);
|
|
|
|
if (ret)
|
|
|
|
return dev_err_probe(dev, ret, "requesting IRQ: %d\n", irq);
|
|
|
|
|
|
|
|
girq->parents[0] = irq;
|
|
|
|
} else { /* F irqchip */
|
2019-08-12 15:00:00 +02:00
|
|
|
girq->parent_handler = ep93xx_gpio_f_irq_handler;
|
2024-09-09 11:10:26 +03:00
|
|
|
|
2021-02-09 16:31:09 +03:00
|
|
|
for (i = 0; i < girq->num_parents; i++) {
|
2024-09-09 11:10:50 +03:00
|
|
|
irq = platform_get_irq_optional(pdev, i);
|
2024-09-09 11:10:26 +03:00
|
|
|
if (irq < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
girq->parents[i] = irq;
|
2019-08-12 15:00:00 +02:00
|
|
|
}
|
2024-09-09 11:10:26 +03:00
|
|
|
|
|
|
|
girq->map = girq->parents;
|
2019-08-12 15:00:00 +02:00
|
|
|
}
|
2008-04-16 02:56:35 +01:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
girq->default_type = IRQ_TYPE_NONE;
|
|
|
|
/* TODO: replace with handle_bad_irq() once we are fully hierarchical */
|
|
|
|
girq->handler = handle_simple_irq;
|
|
|
|
|
|
|
|
return 0;
|
2008-04-16 02:56:35 +01:00
|
|
|
}
|
|
|
|
|
2012-11-19 13:22:34 -05:00
|
|
|
static int ep93xx_gpio_probe(struct platform_device *pdev)
|
2008-04-16 02:56:35 +01:00
|
|
|
{
|
2024-09-09 11:10:26 +03:00
|
|
|
struct ep93xx_gpio_chip *egc;
|
|
|
|
struct gpio_chip *gc;
|
|
|
|
void __iomem *data;
|
|
|
|
void __iomem *dir;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
egc = devm_kzalloc(&pdev->dev, sizeof(*egc), GFP_KERNEL);
|
|
|
|
if (!egc)
|
2011-06-08 14:35:33 -07:00
|
|
|
return -ENOMEM;
|
2008-04-16 02:56:35 +01:00
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
data = devm_platform_ioremap_resource_byname(pdev, "data");
|
|
|
|
if (IS_ERR(data))
|
|
|
|
return PTR_ERR(data);
|
|
|
|
|
|
|
|
dir = devm_platform_ioremap_resource_byname(pdev, "dir");
|
|
|
|
if (IS_ERR(dir))
|
|
|
|
return PTR_ERR(dir);
|
|
|
|
|
|
|
|
gc = &egc->gc;
|
|
|
|
ret = bgpio_init(gc, &pdev->dev, 1, data, NULL, NULL, dir, NULL, 0);
|
|
|
|
if (ret)
|
|
|
|
return dev_err_probe(&pdev->dev, ret, "unable to init generic GPIO\n");
|
|
|
|
|
|
|
|
gc->label = dev_name(&pdev->dev);
|
|
|
|
if (platform_irq_count(pdev) > 0) {
|
|
|
|
dev_dbg(&pdev->dev, "setting up irqs for %s\n", dev_name(&pdev->dev));
|
|
|
|
ret = ep93xx_setup_irqs(pdev, egc);
|
|
|
|
if (ret)
|
|
|
|
dev_err_probe(&pdev->dev, ret, "setup irqs failed");
|
2008-04-16 02:56:35 +01:00
|
|
|
}
|
|
|
|
|
2024-09-09 11:10:26 +03:00
|
|
|
return devm_gpiochip_add_data(&pdev->dev, gc, egc);
|
2011-06-08 14:35:33 -07:00
|
|
|
}
|
ARM: 6636/1: ep93xx: default multiplexed gpio ports to gpio mode
The EP93xx C and D GPIO ports are multiplexed with the Keypad Interface
peripheral. At power-up they default into non-GPIO mode with the Key
Matrix controller enabled so these ports are unusable for GPIO. Note
that the Keypad Interface peripheral is only available in the EP9307,
EP9312, and EP9315 processor variants.
The keypad support will clear the DeviceConfig bits appropriately to
enable the Keypad Interface when the driver is loaded. And, when the
driver is unloaded it will set the bits to return the ports to GPIO mode.
To make these ports available for GPIO after power-up on all EP93xx
processor variants, set the KEYS and GONK bits in the DeviceConfig
register.
Similarly, the E, G, and H ports are multiplexed with the IDE Interface
peripheral. At power-up these also default into non-GPIO mode. Note
that the IDE peripheral is only available in the EP9312 and EP9315
processor variants.
Since an IDE driver is not even available in mainline, set the EONIDE,
GONIDE, and HONIDE bits in the DeviceConfig register so that these
ports will be available for GPIO use after power-up.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Acked-by: Ryan Mallon <ryan@bluewatersys.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2011-01-25 01:05:35 +01:00
|
|
|
|
2024-09-09 11:10:50 +03:00
|
|
|
static const struct of_device_id ep93xx_gpio_match[] = {
|
|
|
|
{ .compatible = "cirrus,ep9301-gpio" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
2011-06-08 14:35:33 -07:00
|
|
|
static struct platform_driver ep93xx_gpio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "gpio-ep93xx",
|
2024-09-09 11:10:50 +03:00
|
|
|
.of_match_table = ep93xx_gpio_match,
|
2011-06-08 14:35:33 -07:00
|
|
|
},
|
|
|
|
.probe = ep93xx_gpio_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ep93xx_gpio_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&ep93xx_gpio_driver);
|
2008-04-16 02:56:35 +01:00
|
|
|
}
|
2011-06-08 14:35:33 -07:00
|
|
|
postcore_initcall(ep93xx_gpio_init);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Ryan Mallon <ryan@bluewatersys.com> "
|
|
|
|
"H Hartley Sweeten <hsweeten@visionengravers.com>");
|
|
|
|
MODULE_DESCRIPTION("EP93XX GPIO driver");
|
|
|
|
MODULE_LICENSE("GPL");
|