xref: /netbsd-src/sys/arch/mips/cavium/dev/octeon_pow.c (revision 7cfbdc5be92d87a593315a9b8f4d90200afdf934)
1*7cfbdc5bSsimonb /*	$NetBSD: octeon_pow.c,v 1.10 2020/06/23 05:15:33 simonb Exp $	*/
2f693c922Shikaru 
3f693c922Shikaru /*
4f693c922Shikaru  * Copyright (c) 2007 Internet Initiative Japan, Inc.
5f693c922Shikaru  * All rights reserved.
6f693c922Shikaru  *
7f693c922Shikaru  * Redistribution and use in source and binary forms, with or without
8f693c922Shikaru  * modification, are permitted provided that the following conditions
9f693c922Shikaru  * are met:
10f693c922Shikaru  * 1. Redistributions of source code must retain the above copyright
11f693c922Shikaru  *    notice, this list of conditions and the following disclaimer.
12f693c922Shikaru  * 2. Redistributions in binary form must reproduce the above copyright
13f693c922Shikaru  *    notice, this list of conditions and the following disclaimer in the
14f693c922Shikaru  *    documentation and/or other materials provided with the distribution.
15f693c922Shikaru  *
16f693c922Shikaru  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17f693c922Shikaru  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f693c922Shikaru  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f693c922Shikaru  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20f693c922Shikaru  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f693c922Shikaru  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f693c922Shikaru  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f693c922Shikaru  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f693c922Shikaru  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f693c922Shikaru  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f693c922Shikaru  * SUCH DAMAGE.
27f693c922Shikaru  */
28f693c922Shikaru 
29f693c922Shikaru #include <sys/cdefs.h>
30*7cfbdc5bSsimonb __KERNEL_RCSID(0, "$NetBSD: octeon_pow.c,v 1.10 2020/06/23 05:15:33 simonb Exp $");
31f693c922Shikaru 
32f693c922Shikaru #include <sys/param.h>
33f693c922Shikaru #include <sys/systm.h>
34f693c922Shikaru 
35f693c922Shikaru #include <mips/include/locore.h>
36f693c922Shikaru #include <mips/cavium/octeonvar.h>
37f693c922Shikaru #include <mips/cavium/include/iobusvar.h>
38f693c922Shikaru #include <mips/cavium/dev/octeon_powreg.h>
39f693c922Shikaru #include <mips/cavium/dev/octeon_powvar.h>
40f693c922Shikaru 
413f508e4dSsimonb void			octpow_bootstrap(struct octeon_config *);
42f693c922Shikaru 
433f508e4dSsimonb static void		octpow_init(struct octpow_softc *);
443f508e4dSsimonb static void		octpow_init_regs(struct octpow_softc *);
45*7cfbdc5bSsimonb static inline void      octpow_config_int(struct octpow_softc *, int,
46*7cfbdc5bSsimonb 			    uint64_t, uint64_t, uint64_t);
47f693c922Shikaru 
483f508e4dSsimonb struct octpow_softc	octpow_softc;
49f693c922Shikaru 
50f693c922Shikaru /* -------------------------------------------------------------------------- */
51f693c922Shikaru 
52f693c922Shikaru /* ---- initialization and configuration */
53f693c922Shikaru 
54f693c922Shikaru void
octpow_bootstrap(struct octeon_config * mcp)553f508e4dSsimonb octpow_bootstrap(struct octeon_config *mcp)
56f693c922Shikaru {
573f508e4dSsimonb 	struct octpow_softc *sc = &octpow_softc;
58f693c922Shikaru 
59f693c922Shikaru 	sc->sc_regt = &mcp->mc_iobus_bust;
60f693c922Shikaru 	/* XXX */
61f693c922Shikaru 
623f508e4dSsimonb 	octpow_init(sc);
63f693c922Shikaru }
64f693c922Shikaru 
65f693c922Shikaru static inline void
octpow_config_int(struct octpow_softc * sc,int group,uint64_t tc_thr,uint64_t ds_thr,uint64_t iq_thr)663f508e4dSsimonb octpow_config_int(struct octpow_softc *sc, int group, uint64_t tc_thr,
673f508e4dSsimonb     uint64_t ds_thr, uint64_t iq_thr)
68f693c922Shikaru {
69b9fcd28bSsimonb 	uint64_t wq_int_thr =
70f693c922Shikaru 	    POW_WQ_INT_THRX_TC_EN |
71b9fcd28bSsimonb 	    __SHIFTIN(tc_thr, POW_WQ_INT_THRX_TC_THR) |
72b9fcd28bSsimonb 	    __SHIFTIN(ds_thr, POW_WQ_INT_THRX_DS_THR) |
73b9fcd28bSsimonb 	    __SHIFTIN(iq_thr, POW_WQ_INT_THRX_IQ_THR);
74b9fcd28bSsimonb 
75f693c922Shikaru 	_POW_WR8(sc, POW_WQ_INT_THR0_OFFSET + (group * 8), wq_int_thr);
76f693c922Shikaru }
77f693c922Shikaru 
78f693c922Shikaru /*
79f693c922Shikaru  * interrupt threshold configuration
80f693c922Shikaru  *
81f693c922Shikaru  * => DS / IQ
82f693c922Shikaru  *    => ...
83f693c922Shikaru  * => time counter threshold
84f693c922Shikaru  *    => unit is 1msec
85f693c922Shikaru  *    => each group can set timeout
86f693c922Shikaru  * => temporary disable bit
87f693c922Shikaru  *    => use CIU generic timer
88f693c922Shikaru  */
89f693c922Shikaru 
90f693c922Shikaru void
octpow_config(struct octpow_softc * sc,int group)913f508e4dSsimonb octpow_config(struct octpow_softc *sc, int group)
92f693c922Shikaru {
93f693c922Shikaru 
943f508e4dSsimonb 	octpow_config_int(sc, group,
95f693c922Shikaru 	    0x0f,		/* TC */
96f693c922Shikaru 	    0x00,		/* DS */
97f693c922Shikaru 	    0x00);		/* IQ */
98f693c922Shikaru }
99f693c922Shikaru 
100f693c922Shikaru void
octpow_init(struct octpow_softc * sc)1013f508e4dSsimonb octpow_init(struct octpow_softc *sc)
102f693c922Shikaru {
1033f508e4dSsimonb 	octpow_init_regs(sc);
104f693c922Shikaru 
105f693c922Shikaru 	sc->sc_int_pc_base = 10000;
1063f508e4dSsimonb 	octpow_config_int_pc(sc, sc->sc_int_pc_base);
107f693c922Shikaru }
108f693c922Shikaru 
109f693c922Shikaru void
octpow_init_regs(struct octpow_softc * sc)1103f508e4dSsimonb octpow_init_regs(struct octpow_softc *sc)
111f693c922Shikaru {
112f693c922Shikaru 	int status;
113f693c922Shikaru 
114f693c922Shikaru 	status = bus_space_map(sc->sc_regt, POW_BASE, POW_SIZE, 0,
115f693c922Shikaru 	    &sc->sc_regh);
116f693c922Shikaru 	if (status != 0)
117f693c922Shikaru 		panic("can't map %s space", "pow register");
118f693c922Shikaru }
119