summaryrefslogtreecommitdiff
path: root/sys/arch/arm/xscale/becc_button.c
blob: 481acbf4a1c0d86fe6e02763e6e6ac7fb7428383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*	$NetBSD: becc_button.c,v 1.4 2012/02/12 16:31:01 matt Exp $	*/

/*
 * Copyright (c) 2003 Wasabi Systems, Inc.
 * All rights reserved.
 *
 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed for the NetBSD Project by
 *	Wasabi Systems, Inc.
 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Driver for the reset button on the ADI Engineering, Inc. Big Endian
 * Companion Chip.
 *
 * When pressed for two seconds, the reset button performs a hard reset
 * of the system.  Shorter presses result in an interrupt being generated,
 * which the operating system can use to trigger a graceful reboot.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: becc_button.c,v 1.4 2012/02/12 16:31:01 matt Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <arm/xscale/beccreg.h>
#include <arm/xscale/beccvar.h>

#include <dev/sysmon/sysmonvar.h>
#include <dev/sysmon/sysmon_taskq.h>

static int beccbut_attached;	/* there can be only one */

struct beccbut_softc {
	device_t sc_dev;
	struct sysmon_pswitch sc_smpsw;
	void *sc_ih;
};

static void
beccbut_pressed_event(void *arg)
{
	struct beccbut_softc *sc = arg;

	sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED);
}

static int
beccbut_intr(void *arg)
{
	struct beccbut_softc *sc = arg;
	int rv;

	rv = sysmon_task_queue_sched(0, beccbut_pressed_event, sc);
	if (rv != 0)
		printf("%s: WARNING: unable to queue button pressed "
		    "callback: %d\n", device_xname(sc->sc_dev), rv);

	return (1);
}

static int
beccbut_match(device_t parent, cfdata_t match, void *aux)
{

	return (beccbut_attached == 0);
}

static void
beccbut_attach(device_t parent, device_t self, void *aux)
{
	struct beccbut_softc *sc = device_private(self);

	aprint_normal(": Reset button\n");
	aprint_naive(": Reset button\n");

	beccbut_attached = 1;
	sc->sc_dev = self;

	sysmon_task_queue_init();

	sc->sc_smpsw.smpsw_name = device_xname(sc->sc_dev);
	sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_RESET;

	if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) {
		aprint_error_dev(sc->sc_dev,
		    "unable to register with sysmon\n");
		return;
	}

	sc->sc_ih = becc_intr_establish(ICU_PUSHBUTTON, IPL_TTY,
	    beccbut_intr, sc);
	if (sc->sc_ih == NULL)
		aprint_error_dev(sc->sc_dev,
		    "unable to establish interrupt handler\n");
}

CFATTACH_DECL_NEW(beccbut, sizeof(struct beccbut_softc),
    beccbut_match, beccbut_attach, NULL, NULL);