Path: blob/master/arch/mips/pmc-sierra/msp71xx/msp_hwbutton.c
15118 views
/*1* Sets up interrupt handlers for various hardware switches which are2* connected to interrupt lines.3*4* Copyright 2005-2207 PMC-Sierra, Inc.5*6* This program is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License as published by the8* Free Software Foundation; either version 2 of the License, or (at your9* option) any later version.10*11* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED12* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF13* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN14* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,15* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT16* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF17* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON18* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT19* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF20* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.21*22* You should have received a copy of the GNU General Public License along23* with this program; if not, write to the Free Software Foundation, Inc.,24* 675 Mass Ave, Cambridge, MA 02139, USA.25*/2627#include <linux/kernel.h>28#include <linux/init.h>29#include <linux/interrupt.h>3031#include <msp_int.h>32#include <msp_regs.h>33#include <msp_regops.h>3435/* For hwbutton_interrupt->initial_state */36#define HWBUTTON_HI 0x137#define HWBUTTON_LO 0x23839/*40* This struct describes a hardware button41*/42struct hwbutton_interrupt {43char *name; /* Name of button */44int irq; /* Actual LINUX IRQ */45int eirq; /* Extended IRQ number (0-7) */46int initial_state; /* The "normal" state of the switch */47void (*handle_hi)(void *); /* Handler: switch input has gone HI */48void (*handle_lo)(void *); /* Handler: switch input has gone LO */49void *data; /* Optional data to pass to handler */50};5152#ifdef CONFIG_PMC_MSP7120_GW53extern void msp_restart(char *);5455static void softreset_push(void *data)56{57printk(KERN_WARNING "SOFTRESET switch was pushed\n");5859/*60* In the future you could move this to the release handler,61* timing the difference between the 'push' and 'release', and only62* doing this ungraceful restart if the button has been down for63* a certain amount of time; otherwise doing a graceful restart.64*/6566msp_restart(NULL);67}6869static void softreset_release(void *data)70{71printk(KERN_WARNING "SOFTRESET switch was released\n");7273/* Do nothing */74}7576static void standby_on(void *data)77{78printk(KERN_WARNING "STANDBY switch was set to ON (not implemented)\n");7980/* TODO: Put board in standby mode */81}8283static void standby_off(void *data)84{85printk(KERN_WARNING86"STANDBY switch was set to OFF (not implemented)\n");8788/* TODO: Take out of standby mode */89}9091static struct hwbutton_interrupt softreset_sw = {92.name = "Softreset button",93.irq = MSP_INT_EXT0,94.eirq = 0,95.initial_state = HWBUTTON_HI,96.handle_hi = softreset_release,97.handle_lo = softreset_push,98.data = NULL,99};100101static struct hwbutton_interrupt standby_sw = {102.name = "Standby switch",103.irq = MSP_INT_EXT1,104.eirq = 1,105.initial_state = HWBUTTON_HI,106.handle_hi = standby_off,107.handle_lo = standby_on,108.data = NULL,109};110#endif /* CONFIG_PMC_MSP7120_GW */111112static irqreturn_t hwbutton_handler(int irq, void *data)113{114struct hwbutton_interrupt *hirq = data;115unsigned long cic_ext = *CIC_EXT_CFG_REG;116117if (CIC_EXT_IS_ACTIVE_HI(cic_ext, hirq->eirq)) {118/* Interrupt: pin is now HI */119CIC_EXT_SET_ACTIVE_LO(cic_ext, hirq->eirq);120hirq->handle_hi(hirq->data);121} else {122/* Interrupt: pin is now LO */123CIC_EXT_SET_ACTIVE_HI(cic_ext, hirq->eirq);124hirq->handle_lo(hirq->data);125}126127/*128* Invert the POLARITY of this level interrupt to ack the interrupt129* Thus next state change will invoke the opposite message130*/131*CIC_EXT_CFG_REG = cic_ext;132133return IRQ_HANDLED;134}135136static int msp_hwbutton_register(struct hwbutton_interrupt *hirq)137{138unsigned long cic_ext;139140if (hirq->handle_hi == NULL || hirq->handle_lo == NULL)141return -EINVAL;142143cic_ext = *CIC_EXT_CFG_REG;144CIC_EXT_SET_TRIGGER_LEVEL(cic_ext, hirq->eirq);145if (hirq->initial_state == HWBUTTON_HI)146CIC_EXT_SET_ACTIVE_LO(cic_ext, hirq->eirq);147else148CIC_EXT_SET_ACTIVE_HI(cic_ext, hirq->eirq);149*CIC_EXT_CFG_REG = cic_ext;150151return request_irq(hirq->irq, hwbutton_handler, IRQF_DISABLED,152hirq->name, hirq);153}154155static int __init msp_hwbutton_setup(void)156{157#ifdef CONFIG_PMC_MSP7120_GW158msp_hwbutton_register(&softreset_sw);159msp_hwbutton_register(&standby_sw);160#endif161return 0;162}163164subsys_initcall(msp_hwbutton_setup);165166167