nslu2_buttons.c revision 1.1
1/* $NetBSD: nslu2_buttons.c,v 1.1 2006/02/28 20:40:33 scw Exp $ */ 2 3/*- 4 * Copyright (c) 2006 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Steve C. Woodford. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/cdefs.h> 40__KERNEL_RCSID(0, "$NetBSD: nslu2_buttons.c,v 1.1 2006/02/28 20:40:33 scw Exp $"); 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/device.h> 45 46#include <dev/sysmon/sysmonvar.h> 47#include <dev/sysmon/sysmon_taskq.h> 48 49#include <arm/xscale/ixp425reg.h> 50#include <arm/xscale/ixp425var.h> 51 52#include <evbarm/nslu2/nslu2reg.h> 53 54struct slugbutt_softc { 55 struct device sc_dev; 56 struct sysmon_pswitch sc_smpwr; 57 struct sysmon_pswitch sc_smrst; 58}; 59 60static int slugbutt_attached; 61 62static void 63power_event(void *arg) 64{ 65 struct slugbutt_softc *sc = arg; 66 67 sysmon_pswitch_event(&sc->sc_smpwr, PSWITCH_EVENT_PRESSED); 68} 69 70static int 71power_intr(void *arg) 72{ 73 struct slugbutt_softc *sc = arg; 74 int rv; 75 76 GPIO_CONF_WRITE_4(ixp425_softc, IXP425_GPIO_GPISR, 77 1u << GPIO_BUTTON_PWR); 78 79 rv = sysmon_task_queue_sched(0, power_event, sc); 80 if (rv) { 81 printf("%s: WARNING: unable to queue power button " 82 "callback: %d\n", sc->sc_dev.dv_xname, rv); 83 } 84 85 return (1); 86} 87 88static void 89reset_event(void *arg) 90{ 91 struct slugbutt_softc *sc = arg; 92 93 sysmon_pswitch_event(&sc->sc_smrst, PSWITCH_EVENT_PRESSED); 94} 95 96static int 97reset_intr(void *arg) 98{ 99 struct slugbutt_softc *sc = arg; 100 int rv; 101 102 GPIO_CONF_WRITE_4(ixp425_softc, IXP425_GPIO_GPISR, 103 1u << GPIO_BUTTON_RST); 104 105 rv = sysmon_task_queue_sched(0, reset_event, sc); 106 if (rv) { 107 printf("%s: WARNING: unable to queue reset button " 108 "callback: %d\n", sc->sc_dev.dv_xname, rv); 109 } 110 111 return (1); 112} 113 114static void 115slugbutt_deferred(struct device *self) 116{ 117 struct slugbutt_softc *sc = (struct slugbutt_softc *) self; 118 struct ixp425_softc *ixsc = ixp425_softc; 119 uint32_t reg; 120 121 /* Configure the GPIO pins as inputs */ 122 reg = GPIO_CONF_READ_4(ixsc, IXP425_GPIO_GPOER); 123 reg |= GPIO_BUTTON_PWR | GPIO_BUTTON_RST; 124 GPIO_CONF_WRITE_4(ixsc, IXP425_GPIO_GPOER, reg); 125 126 /* Configure the input type: Falling edge */ 127 reg = GPIO_CONF_READ_4(ixsc, GPIO_TYPE_REG(GPIO_BUTTON_PWR)); 128 reg &= ~GPIO_TYPE(GPIO_BUTTON_PWR, GPIO_TYPE_MASK); 129 reg |= GPIO_TYPE(GPIO_BUTTON_PWR, GPIO_TYPE_EDG_FALLING); 130 GPIO_CONF_WRITE_4(ixsc, GPIO_TYPE_REG(GPIO_BUTTON_PWR), reg); 131 132 reg = GPIO_CONF_READ_4(ixsc, GPIO_TYPE_REG(GPIO_BUTTON_RST)); 133 reg &= ~GPIO_TYPE(GPIO_BUTTON_RST, GPIO_TYPE_MASK); 134 reg |= GPIO_TYPE(GPIO_BUTTON_RST, GPIO_TYPE_EDG_FALLING); 135 GPIO_CONF_WRITE_4(ixsc, GPIO_TYPE_REG(GPIO_BUTTON_RST), reg); 136 137 /* Clear any existing interrupt */ 138 GPIO_CONF_WRITE_4(ixsc, IXP425_GPIO_GPISR, (1u << GPIO_BUTTON_PWR) | 139 (1u << GPIO_BUTTON_RST)); 140 141 sysmon_task_queue_init(); 142 143 sc->sc_smpwr.smpsw_name = sc->sc_dev.dv_xname; 144 sc->sc_smpwr.smpsw_type = PSWITCH_TYPE_POWER; 145 146 if (sysmon_pswitch_register(&sc->sc_smpwr) != 0) { 147 printf("%s: unable to register power button with sysmon\n", 148 sc->sc_dev.dv_xname); 149 return; 150 } 151 152 sc->sc_smrst.smpsw_name = sc->sc_dev.dv_xname; 153 sc->sc_smrst.smpsw_type = PSWITCH_TYPE_RESET; 154 155 if (sysmon_pswitch_register(&sc->sc_smrst) != 0) { 156 printf("%s: unable to register reset button with sysmon\n", 157 sc->sc_dev.dv_xname); 158 return; 159 } 160 161 /* Hook the interrupts */ 162 ixp425_intr_establish(BUTTON_PWR_INT, IPL_TTY, power_intr, sc); 163 ixp425_intr_establish(BUTTON_RST_INT, IPL_TTY, reset_intr, sc); 164} 165 166 167static int 168slugbutt_match(struct device *parent, struct cfdata *cf, void *arg) 169{ 170 171 return (slugbutt_attached == 0); 172} 173 174static void 175slugbutt_attach(struct device *parent, struct device *self, void *arg) 176{ 177 178 slugbutt_attached = 1; 179 180 aprint_normal(": Power and Reset buttons\n"); 181 182 /* Defer, to ensure ixp425_softc has been initialised */ 183 config_interrupts(self, slugbutt_deferred); 184} 185 186CFATTACH_DECL(slugbutt, sizeof(struct slugbutt_softc), 187 slugbutt_match, slugbutt_attach, NULL, NULL); 188