1*a748aedcSkiyohara /* $NetBSD: gtintrvar.h,v 1.1 2010/04/28 13:51:56 kiyohara Exp $ */
2*a748aedcSkiyohara /*
3*a748aedcSkiyohara * Copyright (c) 2009 KIYOHARA Takashi
4*a748aedcSkiyohara * All rights reserved.
5*a748aedcSkiyohara *
6*a748aedcSkiyohara * Redistribution and use in source and binary forms, with or without
7*a748aedcSkiyohara * modification, are permitted provided that the following conditions
8*a748aedcSkiyohara * are met:
9*a748aedcSkiyohara * 1. Redistributions of source code must retain the above copyright
10*a748aedcSkiyohara * notice, this list of conditions and the following disclaimer.
11*a748aedcSkiyohara * 2. Redistributions in binary form must reproduce the above copyright
12*a748aedcSkiyohara * notice, this list of conditions and the following disclaimer in the
13*a748aedcSkiyohara * documentation and/or other materials provided with the distribution.
14*a748aedcSkiyohara *
15*a748aedcSkiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*a748aedcSkiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*a748aedcSkiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*a748aedcSkiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19*a748aedcSkiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20*a748aedcSkiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21*a748aedcSkiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*a748aedcSkiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23*a748aedcSkiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24*a748aedcSkiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*a748aedcSkiyohara * POSSIBILITY OF SUCH DAMAGE.
26*a748aedcSkiyohara */
27*a748aedcSkiyohara #ifndef _MARVELL_GTINTRVAR_H_
28*a748aedcSkiyohara #define _MARVELL_GTINTRVAR_H_
29*a748aedcSkiyohara
30*a748aedcSkiyohara #include <dev/marvell/gtreg.h>
31*a748aedcSkiyohara
32*a748aedcSkiyohara /*
33*a748aedcSkiyohara * Main Interrupt related functions
34*a748aedcSkiyohara */
35*a748aedcSkiyohara
36*a748aedcSkiyohara static __inline uint32_t
discovery_enable_intr(struct gt_softc * sc,int irq)37*a748aedcSkiyohara discovery_enable_intr(struct gt_softc *sc, int irq)
38*a748aedcSkiyohara {
39*a748aedcSkiyohara bus_size_t reg;
40*a748aedcSkiyohara uint32_t cim;
41*a748aedcSkiyohara
42*a748aedcSkiyohara reg = (irq < 32) ? ICR_CIM_LO : ICR_CIM_HI;
43*a748aedcSkiyohara cim = bus_space_read_4(sc->sc_iot, sc->sc_ioh, reg);
44*a748aedcSkiyohara cim |= 1 << (irq & 31);
45*a748aedcSkiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, reg, cim);
46*a748aedcSkiyohara return cim;
47*a748aedcSkiyohara }
48*a748aedcSkiyohara
49*a748aedcSkiyohara static __inline uint32_t
discovery_disable_intr(struct gt_softc * sc,int irq)50*a748aedcSkiyohara discovery_disable_intr(struct gt_softc *sc, int irq)
51*a748aedcSkiyohara {
52*a748aedcSkiyohara bus_size_t reg;
53*a748aedcSkiyohara uint32_t cim;
54*a748aedcSkiyohara
55*a748aedcSkiyohara reg = (irq < 32) ? ICR_CIM_LO : ICR_CIM_HI;
56*a748aedcSkiyohara cim = bus_space_read_4(sc->sc_iot, sc->sc_ioh, reg);
57*a748aedcSkiyohara cim &= ~(1 << (irq & 31));
58*a748aedcSkiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, reg, cim);
59*a748aedcSkiyohara return cim;
60*a748aedcSkiyohara }
61*a748aedcSkiyohara
62*a748aedcSkiyohara static __inline int
discovery_mic_low(struct gt_softc * sc)63*a748aedcSkiyohara discovery_mic_low(struct gt_softc *sc)
64*a748aedcSkiyohara {
65*a748aedcSkiyohara
66*a748aedcSkiyohara return bus_space_read_4(sc->sc_iot, sc->sc_ioh, ICR_MIC_LO);
67*a748aedcSkiyohara }
68*a748aedcSkiyohara
69*a748aedcSkiyohara static __inline int
discovery_mic_high(struct gt_softc * sc)70*a748aedcSkiyohara discovery_mic_high(struct gt_softc *sc)
71*a748aedcSkiyohara {
72*a748aedcSkiyohara
73*a748aedcSkiyohara return bus_space_read_4(sc->sc_iot, sc->sc_ioh, ICR_MIC_HI);
74*a748aedcSkiyohara }
75*a748aedcSkiyohara
76*a748aedcSkiyohara
77*a748aedcSkiyohara /*
78*a748aedcSkiyohara * GPP Interrupt related functions
79*a748aedcSkiyohara */
80*a748aedcSkiyohara
81*a748aedcSkiyohara static __inline uint32_t
discovery_gpp_enable_intr(struct gt_softc * sc,int pin)82*a748aedcSkiyohara discovery_gpp_enable_intr(struct gt_softc *sc, int pin)
83*a748aedcSkiyohara {
84*a748aedcSkiyohara uint32_t gppim;
85*a748aedcSkiyohara
86*a748aedcSkiyohara gppim = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Mask);
87*a748aedcSkiyohara gppim |= 1 << pin;
88*a748aedcSkiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Mask, gppim);
89*a748aedcSkiyohara return gppim;
90*a748aedcSkiyohara }
91*a748aedcSkiyohara
92*a748aedcSkiyohara static __inline uint32_t
discovery_gpp_disable_intr(struct gt_softc * sc,int pin)93*a748aedcSkiyohara discovery_gpp_disable_intr(struct gt_softc *sc, int pin)
94*a748aedcSkiyohara {
95*a748aedcSkiyohara uint32_t gppim;
96*a748aedcSkiyohara
97*a748aedcSkiyohara gppim = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Mask);
98*a748aedcSkiyohara gppim &= ~(1 << pin);
99*a748aedcSkiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Mask, gppim);
100*a748aedcSkiyohara return gppim;
101*a748aedcSkiyohara }
102*a748aedcSkiyohara
103*a748aedcSkiyohara static __inline void
discovery_gpp_clear_cause(struct gt_softc * sc,int pin)104*a748aedcSkiyohara discovery_gpp_clear_cause(struct gt_softc *sc, int pin)
105*a748aedcSkiyohara {
106*a748aedcSkiyohara uint32_t gppic;
107*a748aedcSkiyohara
108*a748aedcSkiyohara gppic =
109*a748aedcSkiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Cause);
110*a748aedcSkiyohara gppic &= ~(1 << pin);
111*a748aedcSkiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Cause,
112*a748aedcSkiyohara gppic);
113*a748aedcSkiyohara }
114*a748aedcSkiyohara
115*a748aedcSkiyohara static __inline int
discovery_gpp_cause(struct gt_softc * sc)116*a748aedcSkiyohara discovery_gpp_cause(struct gt_softc *sc)
117*a748aedcSkiyohara {
118*a748aedcSkiyohara
119*a748aedcSkiyohara return bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Cause);
120*a748aedcSkiyohara }
121*a748aedcSkiyohara
122*a748aedcSkiyohara static __inline int
discovery_gpp_mask(struct gt_softc * sc)123*a748aedcSkiyohara discovery_gpp_mask(struct gt_softc *sc)
124*a748aedcSkiyohara {
125*a748aedcSkiyohara
126*a748aedcSkiyohara return bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Mask);
127*a748aedcSkiyohara }
128*a748aedcSkiyohara #endif /* _MARVELL_GTINTRVAR_H_ */
129