pwrsw_obio.c revision 1.3
11.3Snonaka/* $NetBSD: pwrsw_obio.c,v 1.3 2012/01/21 19:44:29 nonaka Exp $ */ 21.1Suwe 31.1Suwe/*- 41.3Snonaka * Copyright (C) 2005 NONAKA Kimihiro <nonaka@netbsd.org> 51.1Suwe * All rights reserved. 61.1Suwe * 71.1Suwe * Redistribution and use in source and binary forms, with or without 81.1Suwe * modification, are permitted provided that the following conditions 91.1Suwe * are met: 101.1Suwe * 1. Redistributions of source code must retain the above copyright 111.1Suwe * notice, this list of conditions and the following disclaimer. 121.1Suwe * 2. Redistributions in binary form must reproduce the above copyright 131.1Suwe * notice, this list of conditions and the following disclaimer in the 141.1Suwe * documentation and/or other materials provided with the distribution. 151.1Suwe * 161.3Snonaka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 171.3Snonaka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 181.3Snonaka * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 191.3Snonaka * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 201.3Snonaka * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 211.3Snonaka * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 221.3Snonaka * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 231.3Snonaka * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241.3Snonaka * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 251.3Snonaka * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261.1Suwe */ 271.1Suwe 281.1Suwe#include "btn_obio.h" 291.1Suwe 301.1Suwe#include <sys/cdefs.h> 311.3Snonaka__KERNEL_RCSID(0, "$NetBSD: pwrsw_obio.c,v 1.3 2012/01/21 19:44:29 nonaka Exp $"); 321.1Suwe 331.1Suwe#include <sys/types.h> 341.1Suwe#include <sys/param.h> 351.1Suwe#include <sys/systm.h> 361.1Suwe#include <sys/device.h> 371.1Suwe#include <sys/malloc.h> 381.1Suwe#include <sys/conf.h> 391.1Suwe#include <sys/ioctl.h> 401.1Suwe 411.1Suwe#include <dev/sysmon/sysmonvar.h> 421.1Suwe#include <dev/sysmon/sysmon_taskq.h> 431.1Suwe 441.1Suwe#include <sh3/devreg.h> 451.1Suwe 461.1Suwe#include <landisk/landisk/landiskreg.h> 471.1Suwe#include <landisk/dev/obiovar.h> 481.1Suwe 491.1Suwestruct pwrsw_obio_softc { 501.2Suwe device_t sc_dev; 511.1Suwe void *sc_ih; 521.1Suwe 531.1Suwe struct sysmon_pswitch sc_smpsw; /* our sysmon glue */ 541.1Suwe 551.1Suwe int sc_flags; 561.1Suwe#define SYSMON_ATTACHED 1 571.1Suwe}; 581.1Suwe 591.2Suwestatic int pwrsw_obio_probe(device_t, cfdata_t, void *); 601.2Suwestatic void pwrsw_obio_attach(device_t, device_t, void *); 611.1Suwe 621.1Suwestatic int pwrsw_intr(void *aux); 631.1Suwestatic void pwrsw_pressed_event(void *arg); 641.1Suwe 651.2SuweCFATTACH_DECL_NEW(pwrsw_obio, sizeof(struct pwrsw_obio_softc), 661.1Suwe pwrsw_obio_probe, pwrsw_obio_attach, NULL, NULL); 671.1Suwe 681.1Suwestatic struct pwrsw_obio_softc *pwrsw_softc; 691.1Suwe 701.1Suwestatic int 711.2Suwepwrsw_obio_probe(device_t parent, cfdata_t cfp, void *aux) 721.1Suwe{ 731.1Suwe struct obio_attach_args *oa = aux; 741.1Suwe 751.1Suwe if (pwrsw_softc) 761.1Suwe return (0); 771.1Suwe 781.1Suwe oa->oa_nio = 0; 791.1Suwe oa->oa_niomem = 0; 801.1Suwe oa->oa_nirq = 1; 811.1Suwe oa->oa_irq[0].or_irq = LANDISK_INTR_PWRSW; 821.1Suwe 831.1Suwe return (1); 841.1Suwe} 851.1Suwe 861.1Suwestatic void 871.2Suwepwrsw_obio_attach(device_t parent, device_t self, void *aux) 881.1Suwe{ 891.2Suwe struct pwrsw_obio_softc *sc; 901.1Suwe 911.2Suwe aprint_naive("\n"); 921.2Suwe aprint_normal(": Power Switch\n"); 931.2Suwe 941.2Suwe sc = device_private(self); 951.2Suwe sc->sc_dev = self; 961.1Suwe 971.1Suwe pwrsw_softc = sc; 981.1Suwe 991.2Suwe sc->sc_smpsw.smpsw_name = device_xname(self); 1001.1Suwe sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER; 1011.1Suwe 1021.1Suwe sc->sc_ih = extintr_establish(LANDISK_INTR_PWRSW, IPL_TTY, 1031.1Suwe pwrsw_intr, sc); 1041.1Suwe if (sc->sc_ih == NULL) { 1051.2Suwe aprint_error_dev(self, "unable to establish interrupt"); 1061.1Suwe panic("extintr_establish"); 1071.1Suwe } 1081.1Suwe 1091.1Suwe if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) { 1101.2Suwe aprint_error_dev(self, "unable to register with sysmon\n"); 1111.1Suwe return; 1121.1Suwe } 1131.1Suwe sc->sc_flags |= SYSMON_ATTACHED; 1141.1Suwe} 1151.1Suwe 1161.1Suwestatic int 1171.1Suwepwrsw_intr(void *arg) 1181.1Suwe{ 1191.2Suwe struct pwrsw_obio_softc *sc = arg; 1201.1Suwe int status; 1211.1Suwe 1221.1Suwe status = (int8_t)_reg_read_1(LANDISK_BTNSTAT); 1231.1Suwe if (status == -1) { 1241.1Suwe return (0); 1251.1Suwe } 1261.1Suwe 1271.1Suwe status = ~status; 1281.1Suwe if (status & BTN_POWER_BIT) { 1291.1Suwe if (sc->sc_flags & SYSMON_ATTACHED) { 1301.1Suwe sysmon_task_queue_sched(0, pwrsw_pressed_event, sc); 1311.1Suwe extintr_disable(sc->sc_ih); 1321.1Suwe#if NBTN_OBIO > 0 1331.1Suwe extintr_disable_by_num(LANDISK_INTR_BTN); 1341.1Suwe#endif 1351.1Suwe } else { 1361.2Suwe aprint_normal_dev(sc->sc_dev, "pressed\n"); 1371.1Suwe } 1381.1Suwe _reg_write_1(LANDISK_PWRSW_INTCLR, 1); 1391.1Suwe return (1); 1401.1Suwe } 1411.1Suwe return (0); 1421.1Suwe} 1431.1Suwe 1441.1Suwestatic void 1451.1Suwepwrsw_pressed_event(void *arg) 1461.1Suwe{ 1471.2Suwe struct pwrsw_obio_softc *sc = arg; 1481.1Suwe 1491.1Suwe sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED); 1501.1Suwe} 151