1 /* 2 * (C) Copyright 2017 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #ifndef _IRQ_GENERIC_H 8 #define _IRQ_GENERIC_H 9 10 #include <asm-generic/gpio.h> 11 #include <common.h> 12 #include <dt-bindings/pinctrl/rockchip.h> 13 14 /* 15 * IRQ line status. 16 * 17 * IRQ_TYPE_NONE - default, unspecified type 18 * IRQ_TYPE_EDGE_RISING - rising edge triggered 19 * IRQ_TYPE_EDGE_FALLING - falling edge triggered 20 * IRQ_TYPE_EDGE_BOTH - rising and falling edge triggered 21 * IRQ_TYPE_LEVEL_HIGH - high level triggered 22 * IRQ_TYPE_LEVEL_LOW - low level triggered 23 * IRQ_TYPE_LEVEL_MASK - mask to filter out the level bits 24 * IRQ_TYPE_SENSE_MASK - mask for all the above bits 25 */ 26 enum { 27 IRQ_TYPE_NONE = 0x00000000, 28 IRQ_TYPE_EDGE_RISING = 0x00000001, 29 IRQ_TYPE_EDGE_FALLING = 0x00000002, 30 IRQ_TYPE_EDGE_BOTH = (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING), 31 IRQ_TYPE_LEVEL_HIGH = 0x00000004, 32 IRQ_TYPE_LEVEL_LOW = 0x00000008, 33 IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH), 34 IRQ_TYPE_SENSE_MASK = 0x0000000f, 35 }; 36 37 /* 38 * struct irq_chip - hardware interrupt chip descriptor 39 * 40 * @name: name for irq chip 41 * @irq_enable: enable the interrupt (defaults to chip->unmask if NULL) 42 * @irq_disable: disable the interrupt 43 * @irq_ack: start of a new interrupt 44 * @irq_eoi: end of interrupt 45 * @irq_set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ 46 */ 47 struct irq_chip { 48 const char *name; 49 int (*irq_init)(void); 50 int (*irq_get)(void); 51 int (*irq_enable)(int irq); 52 int (*irq_disable)(int irq); 53 void (*irq_ack)(int irq); 54 void (*irq_eoi)(int irq); 55 int (*irq_set_type)(int irq, unsigned int flow_type); 56 }; 57 58 /* APIs for irqs */ 59 void irq_install_handler(int irq, interrupt_handler_t *handler, void *data); 60 void irq_free_handler(int irq); 61 int irq_set_irq_type(int irq, unsigned int type); 62 int irq_handler_enable(int irq); 63 int irq_handler_disable(int irq); 64 int gpio_to_irq(struct gpio_desc *gpio); 65 66 /* 67 * Assign gpio to irq directly. Don't use it without special reasons. 68 * 69 * Usage example: 70 * int gpio0_a0, irq; 71 * 72 * gpio = RK_IRQ_GPIO(RK_GPIO0, RK_PA0); 73 * irq = hard_gpio_to_irq(gpio0_a0); 74 * irq_install_handler(irq, ...); 75 */ 76 #define GPIO_BANK_SHIFT 8 77 #define RK_IRQ_GPIO(bank, pin) (((bank) << GPIO_BANK_SHIFT) | (pin)) 78 int hard_gpio_to_irq(unsigned gpio); 79 int phandle_gpio_to_irq(u32 gpio_phandle, u32 pin); 80 81 /* only irq-gpio.c can use it */ 82 void _generic_gpio_handle_irq(int irq); 83 84 #endif /* _IRQ_GENERIC_H */ 85