Home | History | Annotate | Line # | Download | only in amlogic
meson8b_clkc.c revision 1.2.2.2
      1  1.2.2.2  pgoyette /* $NetBSD: meson8b_clkc.c,v 1.2.2.2 2019/01/26 21:59:59 pgoyette Exp $ */
      2  1.2.2.2  pgoyette 
      3  1.2.2.2  pgoyette /*-
      4  1.2.2.2  pgoyette  * Copyright (c) 2019 Jared McNeill <jmcneill (at) invisible.ca>
      5  1.2.2.2  pgoyette  * All rights reserved.
      6  1.2.2.2  pgoyette  *
      7  1.2.2.2  pgoyette  * Redistribution and use in source and binary forms, with or without
      8  1.2.2.2  pgoyette  * modification, are permitted provided that the following conditions
      9  1.2.2.2  pgoyette  * are met:
     10  1.2.2.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     11  1.2.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     12  1.2.2.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     14  1.2.2.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     15  1.2.2.2  pgoyette  *
     16  1.2.2.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.2.2.2  pgoyette  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.2.2.2  pgoyette  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.2.2.2  pgoyette  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.2.2.2  pgoyette  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  1.2.2.2  pgoyette  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  1.2.2.2  pgoyette  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  1.2.2.2  pgoyette  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  1.2.2.2  pgoyette  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.2.2.2  pgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.2.2.2  pgoyette  * SUCH DAMAGE.
     27  1.2.2.2  pgoyette  */
     28  1.2.2.2  pgoyette 
     29  1.2.2.2  pgoyette #include <sys/cdefs.h>
     30  1.2.2.2  pgoyette 
     31  1.2.2.2  pgoyette __KERNEL_RCSID(1, "$NetBSD: meson8b_clkc.c,v 1.2.2.2 2019/01/26 21:59:59 pgoyette Exp $");
     32  1.2.2.2  pgoyette 
     33  1.2.2.2  pgoyette #include <sys/param.h>
     34  1.2.2.2  pgoyette #include <sys/bus.h>
     35  1.2.2.2  pgoyette #include <sys/device.h>
     36  1.2.2.2  pgoyette #include <sys/systm.h>
     37  1.2.2.2  pgoyette 
     38  1.2.2.2  pgoyette #include <dev/fdt/fdtvar.h>
     39  1.2.2.2  pgoyette 
     40  1.2.2.2  pgoyette #include <arm/amlogic/meson_clk.h>
     41  1.2.2.2  pgoyette #include <arm/amlogic/meson8b_clkc.h>
     42  1.2.2.2  pgoyette 
     43  1.2.2.2  pgoyette /*
     44  1.2.2.2  pgoyette  * The DT for amlogic,meson8b-clkc defines two reg resources. The first
     45  1.2.2.2  pgoyette  * is not used by this driver.
     46  1.2.2.2  pgoyette  */
     47  1.2.2.2  pgoyette #define	MESON8B_CLKC_REG_INDEX	1
     48  1.2.2.2  pgoyette 
     49  1.2.2.2  pgoyette #define	CBUS_REG(x)	((x) << 2)
     50  1.2.2.2  pgoyette 
     51  1.2.2.2  pgoyette #define	HHI_GCLK_MPEG0		CBUS_REG(0x50)
     52  1.2.2.2  pgoyette #define	HHI_GCLK_MPEG1		CBUS_REG(0x51)
     53  1.2.2.2  pgoyette #define	HHI_GCLK_MPEG2		CBUS_REG(0x52)
     54  1.2.2.2  pgoyette #define	HHI_SYS_CPU_CLK_CNTL1	CBUS_REG(0x57)
     55  1.2.2.2  pgoyette #define	HHI_MPEG_CLK_CNTL	CBUS_REG(0x5d)
     56  1.2.2.2  pgoyette #define	HHI_SYS_CPU_CLK_CNTL0	CBUS_REG(0x67)
     57  1.2.2.2  pgoyette #define	 HHI_SYS_CPU_CLK_CNTL0_CLKSEL	__BIT(7)
     58  1.2.2.2  pgoyette #define	 HHI_SYS_CPU_CLK_CNTL0_SOUTSEL	__BITS(3,2)
     59  1.2.2.2  pgoyette #define	 HHI_SYS_CPU_CLK_CNTL0_PLLSEL	__BITS(1,0)
     60  1.2.2.2  pgoyette #define	HHI_MPLL_CNTL		CBUS_REG(0xa0)
     61  1.2.2.2  pgoyette #define	HHI_MPLL_CNTL2		CBUS_REG(0xa1)
     62  1.2.2.2  pgoyette #define	HHI_MPLL_CNTL5		CBUS_REG(0xa4)
     63  1.2.2.2  pgoyette #define	HHI_MPLL_CNTL6		CBUS_REG(0xa5)
     64  1.2.2.2  pgoyette #define	HHI_MPLL_CNTL7		CBUS_REG(0xa6)
     65  1.2.2.2  pgoyette #define	HHI_MPLL_CNTL8		CBUS_REG(0xa7)
     66  1.2.2.2  pgoyette #define	HHI_MPLL_CNTL9		CBUS_REG(0xa8)
     67  1.2.2.2  pgoyette #define	HHI_SYS_PLL_CNTL	CBUS_REG(0xc0)
     68  1.2.2.2  pgoyette #define	 HHI_SYS_PLL_CNTL_LOCK	__BIT(31)
     69  1.2.2.2  pgoyette #define	 HHI_SYS_PLL_CNTL_OD	__BITS(17,16)
     70  1.2.2.2  pgoyette #define	 HHI_SYS_PLL_CNTL_DIV	__BITS(14,9)
     71  1.2.2.2  pgoyette #define	 HHI_SYS_PLL_CNTL_MUL	__BITS(8,0)
     72  1.2.2.2  pgoyette 
     73  1.2.2.2  pgoyette static int meson8b_clkc_match(device_t, cfdata_t, void *);
     74  1.2.2.2  pgoyette static void meson8b_clkc_attach(device_t, device_t, void *);
     75  1.2.2.2  pgoyette 
     76  1.2.2.2  pgoyette static const char * const compatible[] = {
     77  1.2.2.2  pgoyette 	"amlogic,meson8b-clkc",
     78  1.2.2.2  pgoyette 	NULL
     79  1.2.2.2  pgoyette };
     80  1.2.2.2  pgoyette 
     81  1.2.2.2  pgoyette CFATTACH_DECL_NEW(meson8b_clkc, sizeof(struct meson_clk_softc),
     82  1.2.2.2  pgoyette 	meson8b_clkc_match, meson8b_clkc_attach, NULL, NULL);
     83  1.2.2.2  pgoyette 
     84  1.2.2.2  pgoyette static struct meson_clk_reset meson8b_clkc_resets[] = {
     85  1.2.2.2  pgoyette 	MESON_CLK_RESET(MESON8B_RESET_CPU0_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 24),
     86  1.2.2.2  pgoyette 	MESON_CLK_RESET(MESON8B_RESET_CPU1_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 25),
     87  1.2.2.2  pgoyette 	MESON_CLK_RESET(MESON8B_RESET_CPU2_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 26),
     88  1.2.2.2  pgoyette 	MESON_CLK_RESET(MESON8B_RESET_CPU3_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 27),
     89  1.2.2.2  pgoyette };
     90  1.2.2.2  pgoyette 
     91  1.2.2.2  pgoyette static const char *mpeg_sel_parents[] = { "xtal", NULL, "fclk_div7", "mpll_clkout1", "mpll_clkout2", "fclk_div4", "fclk_div3", "fclk_div5" };
     92  1.2.2.2  pgoyette static const char *cpu_in_sel_parents[] = { "xtal", "sys_pll" };
     93  1.2.2.2  pgoyette static const char *cpu_scale_out_sel_parents[] = { "cpu_in_sel", "cpu_in_div2", "cpu_in_div3", "cpu_scale_div" };
     94  1.2.2.2  pgoyette static const char *cpu_clk_parents[] = { "xtal", "cpu_scale_out_sel" };
     95  1.2.2.2  pgoyette static const char *periph_clk_sel_parents[] = { "cpu_clk_div2", "cpu_clk_div3", "cpu_clk_div4", "cpu_clk_div5", "cpu_clk_div6", "cpu_clk_div7", "cpu_clk_div8" };
     96  1.2.2.2  pgoyette 
     97  1.2.2.2  pgoyette static int
     98  1.2.2.2  pgoyette meson8b_clkc_pll_sys_set_rate(struct meson_clk_softc *sc,
     99  1.2.2.2  pgoyette     struct meson_clk_clk *clk, u_int rate)
    100  1.2.2.2  pgoyette {
    101  1.2.2.2  pgoyette 	struct clk *clkp, *clkp_parent;
    102  1.2.2.2  pgoyette 
    103  1.2.2.2  pgoyette 	KASSERT(clk->type == MESON_CLK_PLL);
    104  1.2.2.2  pgoyette 
    105  1.2.2.2  pgoyette 	clkp = &clk->base;
    106  1.2.2.2  pgoyette 	clkp_parent = clk_get_parent(clkp);
    107  1.2.2.2  pgoyette 	if (clkp_parent == NULL)
    108  1.2.2.2  pgoyette 		return ENXIO;
    109  1.2.2.2  pgoyette 
    110  1.2.2.2  pgoyette 	const u_int old_rate = clk_get_rate(clkp);
    111  1.2.2.2  pgoyette 	if (old_rate == rate)
    112  1.2.2.2  pgoyette 		return 0;
    113  1.2.2.2  pgoyette 
    114  1.2.2.2  pgoyette 	const u_int parent_rate = clk_get_rate(clkp_parent);
    115  1.2.2.2  pgoyette 	if (parent_rate == 0)
    116  1.2.2.2  pgoyette 		return EIO;
    117  1.2.2.2  pgoyette 
    118  1.2.2.2  pgoyette 	uint32_t cntl0 = CLK_READ(sc, HHI_SYS_CPU_CLK_CNTL0);
    119  1.2.2.2  pgoyette 	uint32_t cntl = CLK_READ(sc, HHI_SYS_PLL_CNTL);
    120  1.2.2.2  pgoyette 
    121  1.2.2.2  pgoyette 	u_int new_mul = rate / parent_rate;
    122  1.2.2.2  pgoyette 	u_int new_div = 1;
    123  1.2.2.2  pgoyette 	u_int new_od = 0;
    124  1.2.2.2  pgoyette 
    125  1.2.2.2  pgoyette 	if (rate < 600 * 1000000) {
    126  1.2.2.2  pgoyette 		new_od = 2;
    127  1.2.2.2  pgoyette 		new_mul *= 4;
    128  1.2.2.2  pgoyette 	} else if (rate < 1200 * 1000000) {
    129  1.2.2.2  pgoyette 		new_od = 1;
    130  1.2.2.2  pgoyette 		new_mul *= 2;
    131  1.2.2.2  pgoyette 	}
    132  1.2.2.2  pgoyette 
    133  1.2.2.2  pgoyette 	if ((cntl0 & HHI_SYS_CPU_CLK_CNTL0_CLKSEL) == 0)
    134  1.2.2.2  pgoyette 		return EIO;
    135  1.2.2.2  pgoyette 	if (__SHIFTOUT(cntl0, HHI_SYS_CPU_CLK_CNTL0_PLLSEL) != 1)
    136  1.2.2.2  pgoyette 		return EIO;
    137  1.2.2.2  pgoyette 	if (__SHIFTOUT(cntl0, HHI_SYS_CPU_CLK_CNTL0_SOUTSEL) != 0)
    138  1.2.2.2  pgoyette 		return EIO;
    139  1.2.2.2  pgoyette 
    140  1.2.2.2  pgoyette 	cntl &= ~HHI_SYS_PLL_CNTL_MUL;
    141  1.2.2.2  pgoyette 	cntl |= __SHIFTIN(new_mul, HHI_SYS_PLL_CNTL_MUL);
    142  1.2.2.2  pgoyette 	cntl &= ~HHI_SYS_PLL_CNTL_DIV;
    143  1.2.2.2  pgoyette 	cntl |= __SHIFTIN(new_div, HHI_SYS_PLL_CNTL_DIV);
    144  1.2.2.2  pgoyette 	cntl &= ~HHI_SYS_PLL_CNTL_OD;
    145  1.2.2.2  pgoyette 	cntl |= __SHIFTIN(new_od, HHI_SYS_PLL_CNTL_OD);
    146  1.2.2.2  pgoyette 
    147  1.2.2.2  pgoyette 	/* Switch CPU to XTAL clock */
    148  1.2.2.2  pgoyette 	cntl0 &= ~HHI_SYS_CPU_CLK_CNTL0_CLKSEL;
    149  1.2.2.2  pgoyette 	CLK_WRITE(sc, HHI_SYS_CPU_CLK_CNTL0, cntl0);
    150  1.2.2.2  pgoyette 
    151  1.2.2.2  pgoyette 	delay((100 * old_rate) / parent_rate);
    152  1.2.2.2  pgoyette 
    153  1.2.2.2  pgoyette 	/* Update multiplier */
    154  1.2.2.2  pgoyette 	do {
    155  1.2.2.2  pgoyette 		CLK_WRITE(sc, HHI_SYS_PLL_CNTL, cntl);
    156  1.2.2.2  pgoyette 
    157  1.2.2.2  pgoyette 		/* Switch CPU to sys pll */
    158  1.2.2.2  pgoyette 		cntl0 |= HHI_SYS_CPU_CLK_CNTL0_CLKSEL;
    159  1.2.2.2  pgoyette 		CLK_WRITE(sc, HHI_SYS_CPU_CLK_CNTL0, cntl0);
    160  1.2.2.2  pgoyette 	} while ((CLK_READ(sc, HHI_SYS_PLL_CNTL) & HHI_SYS_PLL_CNTL_LOCK) == 0);
    161  1.2.2.2  pgoyette 
    162  1.2.2.2  pgoyette 	return 0;
    163  1.2.2.2  pgoyette }
    164  1.2.2.2  pgoyette 
    165  1.2.2.2  pgoyette static struct meson_clk_clk meson8b_clkc_clks[] = {
    166  1.2.2.2  pgoyette 
    167  1.2.2.2  pgoyette 	MESON_CLK_FIXED(MESON8B_CLOCK_XTAL, "xtal", 24000000),
    168  1.2.2.2  pgoyette 
    169  1.2.2.2  pgoyette 	MESON_CLK_PLL_RATE(MESON8B_CLOCK_PLL_SYS_DCO, "pll_sys_dco", "xtal",
    170  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(30)),	/* enable */
    171  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BITS(8,0)),	/* m */
    172  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BITS(13,9)),	/* n */
    173  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG_INVALID,				/* frac */
    174  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(31)),	/* l */
    175  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(29)),	/* reset */
    176  1.2.2.2  pgoyette 	    meson8b_clkc_pll_sys_set_rate,
    177  1.2.2.2  pgoyette 	    0),
    178  1.2.2.2  pgoyette 
    179  1.2.2.2  pgoyette 	MESON_CLK_DIV(MESON8B_CLOCK_PLL_SYS, "sys_pll", "pll_sys_dco",
    180  1.2.2.2  pgoyette 	    HHI_SYS_PLL_CNTL,		/* reg */
    181  1.2.2.2  pgoyette 	    __BITS(17,16),		/* div */
    182  1.2.2.2  pgoyette 	    MESON_CLK_DIV_POWER_OF_TWO | MESON_CLK_DIV_SET_RATE_PARENT),
    183  1.2.2.2  pgoyette 
    184  1.2.2.2  pgoyette 	MESON_CLK_MUX(MESON8B_CLOCK_CPU_IN_SEL, "cpu_in_sel", cpu_in_sel_parents,
    185  1.2.2.2  pgoyette 	    HHI_SYS_CPU_CLK_CNTL0,	/* reg */
    186  1.2.2.2  pgoyette 	    __BIT(0),			/* sel */
    187  1.2.2.2  pgoyette 	    0),
    188  1.2.2.2  pgoyette 
    189  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_IN_DIV2, "cpu_in_div2", "cpu_in_sel", 2, 1),
    190  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_IN_DIV3, "cpu_in_div3", "cpu_in_sel", 3, 1),
    191  1.2.2.2  pgoyette 
    192  1.2.2.2  pgoyette 	MESON_CLK_DIV(MESON8B_CLOCK_CPU_SCALE_DIV, "cpu_scale_div", "cpu_in_sel",
    193  1.2.2.2  pgoyette 	    HHI_SYS_CPU_CLK_CNTL1,	/* reg */
    194  1.2.2.2  pgoyette 	    __BITS(29,20),		/* div */
    195  1.2.2.2  pgoyette 	    MESON_CLK_DIV_CPU_SCALE_TABLE | MESON_CLK_DIV_SET_RATE_PARENT),
    196  1.2.2.2  pgoyette 
    197  1.2.2.2  pgoyette 	MESON_CLK_MUX(MESON8B_CLOCK_CPU_SCALE_OUT_SEL, "cpu_scale_out_sel", cpu_scale_out_sel_parents,
    198  1.2.2.2  pgoyette 	    HHI_SYS_CPU_CLK_CNTL0,	/* reg */
    199  1.2.2.2  pgoyette 	    __BITS(3,2),		/* sel */
    200  1.2.2.2  pgoyette 	    0),
    201  1.2.2.2  pgoyette 
    202  1.2.2.2  pgoyette 	MESON_CLK_MUX(MESON8B_CLOCK_CPUCLK, "cpu_clk", cpu_clk_parents,
    203  1.2.2.2  pgoyette 	    HHI_SYS_CPU_CLK_CNTL0,	/* reg */
    204  1.2.2.2  pgoyette 	    __BIT(7),			/* sel */
    205  1.2.2.2  pgoyette 	    0),
    206  1.2.2.2  pgoyette 
    207  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV2, "cpu_clk_div2", "cpu_clk", 2, 1),
    208  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV3, "cpu_clk_div3", "cpu_clk", 3, 1),
    209  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV4, "cpu_clk_div4", "cpu_clk", 4, 1),
    210  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV5, "cpu_clk_div5", "cpu_clk", 5, 1),
    211  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV6, "cpu_clk_div6", "cpu_clk", 6, 1),
    212  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV7, "cpu_clk_div7", "cpu_clk", 7, 1),
    213  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV8, "cpu_clk_div8", "cpu_clk", 8, 1),
    214  1.2.2.2  pgoyette 
    215  1.2.2.2  pgoyette 	MESON_CLK_MUX(MESON8B_CLOCK_PERIPH_SEL, "periph_clk_sel", periph_clk_sel_parents,
    216  1.2.2.2  pgoyette 	    HHI_SYS_CPU_CLK_CNTL1,	/* reg */
    217  1.2.2.2  pgoyette 	    __BITS(8,6),		/* sel */
    218  1.2.2.2  pgoyette 	    0),
    219  1.2.2.2  pgoyette 	MESON_CLK_GATE_FLAGS(MESON8B_CLOCK_PERIPH, "periph_clk_dis", "periph_clk_sel",
    220  1.2.2.2  pgoyette 	    HHI_SYS_CPU_CLK_CNTL1,	/* reg */
    221  1.2.2.2  pgoyette 	    17,				/* bit */
    222  1.2.2.2  pgoyette 	    MESON_CLK_GATE_SET_TO_DISABLE),
    223  1.2.2.2  pgoyette 
    224  1.2.2.2  pgoyette 	MESON_CLK_PLL(MESON8B_CLOCK_PLL_FIXED_DCO, "pll_fixed_dco", "xtal",
    225  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(30)),	/* enable */
    226  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BITS(8,0)),	/* m */
    227  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BITS(13,9)),	/* n */
    228  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL2, __BITS(11,0)),	/* frac */
    229  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(31)),	/* l */
    230  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(29)),	/* reset */
    231  1.2.2.2  pgoyette 	    0),
    232  1.2.2.2  pgoyette 
    233  1.2.2.2  pgoyette 	MESON_CLK_DIV(MESON8B_CLOCK_PLL_FIXED, "pll_fixed", "pll_fixed_dco",
    234  1.2.2.2  pgoyette 	    HHI_MPLL_CNTL,	/* reg */
    235  1.2.2.2  pgoyette 	    __BITS(17,16),	/* div */
    236  1.2.2.2  pgoyette 	    MESON_CLK_DIV_POWER_OF_TWO),
    237  1.2.2.2  pgoyette 
    238  1.2.2.2  pgoyette 	MESON_CLK_DIV(MESON8B_CLOCK_MPLL_PREDIV, "mpll_prediv", "pll_fixed",
    239  1.2.2.2  pgoyette 	    HHI_MPLL_CNTL5,	/* reg */
    240  1.2.2.2  pgoyette 	    __BIT(12),		/* div */
    241  1.2.2.2  pgoyette 	    0),
    242  1.2.2.2  pgoyette 
    243  1.2.2.2  pgoyette 	MESON_CLK_MPLL(MESON8B_CLOCK_MPLL0_DIV, "mpll0_div", "mpll_prediv",
    244  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BITS(13,0)),	/* sdm */
    245  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BIT(15)),	/* sdm_enable */
    246  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BITS(24,16)),	/* n2 */
    247  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(25)),	/* ssen */
    248  1.2.2.2  pgoyette 	    0),
    249  1.2.2.2  pgoyette 	MESON_CLK_MPLL(MESON8B_CLOCK_MPLL1_DIV, "mpll1_div", "mpll_prediv",
    250  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(13,0)),	/* sdm */
    251  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BIT(15)),	/* sdm_enable */
    252  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(24,16)),	/* n2 */
    253  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG_INVALID,				/* ssen */
    254  1.2.2.2  pgoyette 	    0),
    255  1.2.2.2  pgoyette 	MESON_CLK_MPLL(MESON8B_CLOCK_MPLL2_DIV, "mpll2_div", "mpll_prediv",
    256  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(13,0)),	/* sdm */
    257  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BIT(15)),	/* sdm_enable */
    258  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(24,16)),	/* n2 */
    259  1.2.2.2  pgoyette 	    MESON_CLK_PLL_REG_INVALID,				/* ssen */
    260  1.2.2.2  pgoyette 	    0),
    261  1.2.2.2  pgoyette 
    262  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_MPLL0, "mpll0", "mpll0_div", HHI_MPLL_CNTL7, 14),
    263  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_MPLL1, "mpll1", "mpll1_div", HHI_MPLL_CNTL8, 14),
    264  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_MPLL2, "mpll2", "mpll2_div", HHI_MPLL_CNTL9, 14),
    265  1.2.2.2  pgoyette 
    266  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV2_DIV, "fclk_div2_div", "pll_fixed", 2, 1),
    267  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV3_DIV, "fclk_div3_div", "pll_fixed", 3, 1),
    268  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV4_DIV, "fclk_div4_div", "pll_fixed", 4, 1),
    269  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV5_DIV, "fclk_div5_div", "pll_fixed", 5, 1),
    270  1.2.2.2  pgoyette 	MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV7_DIV, "fclk_div7_div", "pll_fixed", 7, 1),
    271  1.2.2.2  pgoyette 
    272  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV2, "fclk_div2", "fclk_div2_div", HHI_MPLL_CNTL6, 27),
    273  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV3, "fclk_div3", "fclk_div3_div", HHI_MPLL_CNTL6, 28),
    274  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV4, "fclk_div4", "fclk_div4_div", HHI_MPLL_CNTL6, 29),
    275  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV5, "fclk_div5", "fclk_div5_div", HHI_MPLL_CNTL6, 30),
    276  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV7, "fclk_div7", "fclk_div7_div", HHI_MPLL_CNTL6, 31),
    277  1.2.2.2  pgoyette 
    278  1.2.2.2  pgoyette 	MESON_CLK_MUX(MESON8B_CLOCK_MPEG_SEL, "mpeg_sel", mpeg_sel_parents,
    279  1.2.2.2  pgoyette 	    HHI_MPEG_CLK_CNTL,	/* reg */
    280  1.2.2.2  pgoyette 	    __BITS(14,12),	/* sel */
    281  1.2.2.2  pgoyette 	    0),
    282  1.2.2.2  pgoyette 
    283  1.2.2.2  pgoyette 	MESON_CLK_DIV(MESON8B_CLOCK_MPEG_DIV, "mpeg_div", "mpeg_sel",
    284  1.2.2.2  pgoyette 	    HHI_MPEG_CLK_CNTL,	/* reg */
    285  1.2.2.2  pgoyette 	    __BITS(6,0),	/* div */
    286  1.2.2.2  pgoyette 	    0),
    287  1.2.2.2  pgoyette 
    288  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_CLK81, "clk81", "mpeg_div", HHI_MPEG_CLK_CNTL, 7),
    289  1.2.2.2  pgoyette 
    290  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_I2C, "i2c", "clk81", HHI_GCLK_MPEG0, 9),
    291  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_SAR_ADC, "sar_adc", "clk81", HHI_GCLK_MPEG0, 10),
    292  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_RNG0, "rng0", "clk81", HHI_GCLK_MPEG0, 12),
    293  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_UART0, "uart0", "clk81", HHI_GCLK_MPEG0, 13),
    294  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_SDHC, "sdhc", "clk81", HHI_GCLK_MPEG0, 14),
    295  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_SDIO, "sdio", "clk81", HHI_GCLK_MPEG0, 17),
    296  1.2.2.2  pgoyette 
    297  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_ETH, "eth", "clk81", HHI_GCLK_MPEG1, 3),
    298  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_UART1, "uart1", "clk81", HHI_GCLK_MPEG1, 16),
    299  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_USB0, "usb0", "clk81", HHI_GCLK_MPEG1, 21),
    300  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_USB1, "usb1", "clk81", HHI_GCLK_MPEG1, 22),
    301  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_USB, "usb", "clk81", HHI_GCLK_MPEG1, 26),
    302  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_EFUSE, "efuse", "clk81", HHI_GCLK_MPEG1, 30),
    303  1.2.2.2  pgoyette 
    304  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_USB1_DDR_BRIDGE, "usb1_ddr_bridge", "clk81", HHI_GCLK_MPEG2, 8),
    305  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_USB0_DDR_BRIDGE, "usb0_ddr_bridge", "clk81", HHI_GCLK_MPEG2, 9),
    306  1.2.2.2  pgoyette 	MESON_CLK_GATE(MESON8B_CLOCK_UART2, "uart2", "clk81", HHI_GCLK_MPEG2, 15),
    307  1.2.2.2  pgoyette };
    308  1.2.2.2  pgoyette 
    309  1.2.2.2  pgoyette static int
    310  1.2.2.2  pgoyette meson8b_clkc_match(device_t parent, cfdata_t cf, void *aux)
    311  1.2.2.2  pgoyette {
    312  1.2.2.2  pgoyette 	struct fdt_attach_args * const faa = aux;
    313  1.2.2.2  pgoyette 
    314  1.2.2.2  pgoyette 	return of_match_compatible(faa->faa_phandle, compatible);
    315  1.2.2.2  pgoyette }
    316  1.2.2.2  pgoyette 
    317  1.2.2.2  pgoyette static void
    318  1.2.2.2  pgoyette meson8b_clkc_attach(device_t parent, device_t self, void *aux)
    319  1.2.2.2  pgoyette {
    320  1.2.2.2  pgoyette 	struct meson_clk_softc * const sc = device_private(self);
    321  1.2.2.2  pgoyette 	struct fdt_attach_args * const faa = aux;
    322  1.2.2.2  pgoyette 
    323  1.2.2.2  pgoyette 	sc->sc_dev = self;
    324  1.2.2.2  pgoyette 	sc->sc_phandle = faa->faa_phandle;
    325  1.2.2.2  pgoyette 	sc->sc_bst = faa->faa_bst;
    326  1.2.2.2  pgoyette 
    327  1.2.2.2  pgoyette 	sc->sc_resets = meson8b_clkc_resets;
    328  1.2.2.2  pgoyette 	sc->sc_nresets = __arraycount(meson8b_clkc_resets);
    329  1.2.2.2  pgoyette 
    330  1.2.2.2  pgoyette 	sc->sc_clks = meson8b_clkc_clks;
    331  1.2.2.2  pgoyette 	sc->sc_nclks = __arraycount(meson8b_clkc_clks);
    332  1.2.2.2  pgoyette 
    333  1.2.2.2  pgoyette 	if (meson_clk_attach(sc, MESON8B_CLKC_REG_INDEX) != 0)
    334  1.2.2.2  pgoyette 		return;
    335  1.2.2.2  pgoyette 
    336  1.2.2.2  pgoyette 	aprint_naive("\n");
    337  1.2.2.2  pgoyette 	aprint_normal(": Meson8b clock controller\n");
    338  1.2.2.2  pgoyette 
    339  1.2.2.2  pgoyette 	meson_clk_print(sc);
    340  1.2.2.2  pgoyette }
    341