Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/powerpc/powermac/pswitch.c
39536 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (C) 2002 Benno Rice.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
17
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#include "opt_ddb.h"
29
30
#include <sys/param.h>
31
#include <sys/systm.h>
32
#include <sys/kdb.h>
33
#include <sys/kernel.h>
34
#include <sys/module.h>
35
#include <sys/malloc.h>
36
#include <sys/bus.h>
37
#include <machine/bus.h>
38
#include <sys/rman.h>
39
40
#include <machine/resource.h>
41
42
#include <dev/ofw/ofw_bus.h>
43
#include <dev/ofw/openfirm.h>
44
45
#include <powerpc/powermac/maciovar.h>
46
47
struct pswitch_softc {
48
int sc_irq_rid;
49
struct resource *sc_irq;
50
void *sc_ih;
51
};
52
53
static int pswitch_probe(device_t);
54
static int pswitch_attach(device_t);
55
56
static int pswitch_intr(void *);
57
58
static device_method_t pswitch_methods[] = {
59
/* Device interface */
60
DEVMETHOD(device_probe, pswitch_probe),
61
DEVMETHOD(device_attach, pswitch_attach),
62
{ 0, 0 }
63
};
64
65
static driver_t pswitch_driver = {
66
"pswitch",
67
pswitch_methods,
68
sizeof(struct pswitch_softc)
69
};
70
71
EARLY_DRIVER_MODULE(pswitch, macgpio, pswitch_driver, 0, 0, BUS_PASS_RESOURCE);
72
73
static int
74
pswitch_probe(device_t dev)
75
{
76
const char *type = ofw_bus_get_type(dev);
77
78
if (strcmp(type, "programmer-switch") != 0)
79
return (ENXIO);
80
81
device_set_desc(dev, "GPIO Programmer's Switch");
82
return (0);
83
}
84
85
static int
86
pswitch_attach(device_t dev)
87
{
88
struct pswitch_softc *sc;
89
90
sc = device_get_softc(dev);
91
92
sc->sc_irq_rid = 0;
93
sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
94
&sc->sc_irq_rid, RF_ACTIVE);
95
if (sc->sc_irq == NULL) {
96
device_printf(dev, "could not allocate interrupt\n");
97
return (ENXIO);
98
}
99
100
if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_EXCL,
101
pswitch_intr, NULL, dev, &sc->sc_ih) != 0) {
102
device_printf(dev, "could not setup interrupt\n");
103
bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irq_rid,
104
sc->sc_irq);
105
return (ENXIO);
106
}
107
108
return (0);
109
}
110
111
static int
112
pswitch_intr(void *arg)
113
{
114
device_t dev;
115
116
dev = (device_t)arg;
117
118
kdb_enter(KDB_WHY_POWERPC, device_get_nameunit(dev));
119
return (FILTER_HANDLED);
120
}
121
122