Path: blob/master/arch/arm/mach-omap1/ams-delta-fiq.c
10817 views
/*1* Amstrad E3 FIQ handling2*3* Copyright (C) 2009 Janusz Krzysztofik4* Copyright (c) 2006 Matt Callow5* Copyright (c) 2004 Amstrad Plc6* Copyright (C) 2001 RidgeRun, Inc.7*8* Parts of this code are taken from linux/arch/arm/mach-omap/irq.c9* in the MontaVista 2.4 kernel (and the Amstrad changes therein)10*11* This program is free software; you can redistribute it and/or modify it12* under the terms of the GNU General Public License version 2 as published by13* the Free Software Foundation.14*/15#include <linux/gpio.h>16#include <linux/interrupt.h>17#include <linux/irq.h>18#include <linux/module.h>19#include <linux/io.h>2021#include <plat/board-ams-delta.h>2223#include <asm/fiq.h>24#include <mach/ams-delta-fiq.h>2526static struct fiq_handler fh = {27.name = "ams-delta-fiq"28};2930/*31* This buffer is shared between FIQ and IRQ contexts.32* The FIQ and IRQ isrs can both read and write it.33* It is structured as a header section several 32bit slots,34* followed by the circular buffer where the FIQ isr stores35* keystrokes received from the qwerty keyboard.36* See ams-delta-fiq.h for details of offsets.37*/38unsigned int fiq_buffer[1024];39EXPORT_SYMBOL(fiq_buffer);4041static unsigned int irq_counter[16];4243static irqreturn_t deferred_fiq(int irq, void *dev_id)44{45struct irq_desc *irq_desc;46struct irq_chip *irq_chip = NULL;47int gpio, irq_num, fiq_count;4849irq_desc = irq_to_desc(IH_GPIO_BASE);50if (irq_desc)51irq_chip = irq_desc->irq_data.chip;5253/*54* For each handled GPIO interrupt, keep calling its interrupt handler55* until the IRQ counter catches the FIQ incremented interrupt counter.56*/57for (gpio = AMS_DELTA_GPIO_PIN_KEYBRD_CLK;58gpio <= AMS_DELTA_GPIO_PIN_HOOK_SWITCH; gpio++) {59irq_num = gpio_to_irq(gpio);60fiq_count = fiq_buffer[FIQ_CNT_INT_00 + gpio];6162while (irq_counter[gpio] < fiq_count) {63if (gpio != AMS_DELTA_GPIO_PIN_KEYBRD_CLK) {64struct irq_data *d = irq_get_irq_data(irq_num);6566/*67* It looks like handle_edge_irq() that68* OMAP GPIO edge interrupts default to,69* expects interrupt already unmasked.70*/71if (irq_chip && irq_chip->irq_unmask)72irq_chip->irq_unmask(d);73}74generic_handle_irq(irq_num);7576irq_counter[gpio]++;77}78}79return IRQ_HANDLED;80}8182void __init ams_delta_init_fiq(void)83{84void *fiqhandler_start;85unsigned int fiqhandler_length;86struct pt_regs FIQ_regs;87unsigned long val, offset;88int i, retval;8990fiqhandler_start = &qwerty_fiqin_start;91fiqhandler_length = &qwerty_fiqin_end - &qwerty_fiqin_start;92pr_info("Installing fiq handler from %p, length 0x%x\n",93fiqhandler_start, fiqhandler_length);9495retval = claim_fiq(&fh);96if (retval) {97pr_err("ams_delta_init_fiq(): couldn't claim FIQ, ret=%d\n",98retval);99return;100}101102retval = request_irq(INT_DEFERRED_FIQ, deferred_fiq,103IRQ_TYPE_EDGE_RISING, "deferred_fiq", 0);104if (retval < 0) {105pr_err("Failed to get deferred_fiq IRQ, ret=%d\n", retval);106release_fiq(&fh);107return;108}109/*110* Since no set_type() method is provided by OMAP irq chip,111* switch to edge triggered interrupt type manually.112*/113offset = IRQ_ILR0_REG_OFFSET + INT_DEFERRED_FIQ * 0x4;114val = omap_readl(DEFERRED_FIQ_IH_BASE + offset) & ~(1 << 1);115omap_writel(val, DEFERRED_FIQ_IH_BASE + offset);116117set_fiq_handler(fiqhandler_start, fiqhandler_length);118119/*120* Initialise the buffer which is shared121* between FIQ mode and IRQ mode122*/123fiq_buffer[FIQ_GPIO_INT_MASK] = 0;124fiq_buffer[FIQ_MASK] = 0;125fiq_buffer[FIQ_STATE] = 0;126fiq_buffer[FIQ_KEY] = 0;127fiq_buffer[FIQ_KEYS_CNT] = 0;128fiq_buffer[FIQ_KEYS_HICNT] = 0;129fiq_buffer[FIQ_TAIL_OFFSET] = 0;130fiq_buffer[FIQ_HEAD_OFFSET] = 0;131fiq_buffer[FIQ_BUF_LEN] = 256;132fiq_buffer[FIQ_MISSED_KEYS] = 0;133fiq_buffer[FIQ_BUFFER_START] =134(unsigned int) &fiq_buffer[FIQ_CIRC_BUFF];135136for (i = FIQ_CNT_INT_00; i <= FIQ_CNT_INT_15; i++)137fiq_buffer[i] = 0;138139/*140* FIQ mode r9 always points to the fiq_buffer, becauses the FIQ isr141* will run in an unpredictable context. The fiq_buffer is the FIQ isr's142* only means of communication with the IRQ level and other kernel143* context code.144*/145FIQ_regs.ARM_r9 = (unsigned int)fiq_buffer;146set_fiq_regs(&FIQ_regs);147148pr_info("request_fiq(): fiq_buffer = %p\n", fiq_buffer);149150/*151* Redirect GPIO interrupts to FIQ152*/153offset = IRQ_ILR0_REG_OFFSET + INT_GPIO_BANK1 * 0x4;154val = omap_readl(OMAP_IH1_BASE + offset) | 1;155omap_writel(val, OMAP_IH1_BASE + offset);156}157158159