Home | History | Annotate | Line # | Download | only in sunxi
sun50i_h6_ccu.c revision 1.1.4.1
      1  1.1.4.1  christos /* $NetBSD: sun50i_h6_ccu.c,v 1.1.4.1 2019/06/10 22:05:56 christos Exp $ */
      2      1.1  jmcneill 
      3      1.1  jmcneill /*-
      4      1.1  jmcneill  * Copyright (c) 2018 Jared McNeill <jmcneill (at) invisible.ca>
      5      1.1  jmcneill  * All rights reserved.
      6      1.1  jmcneill  *
      7      1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8      1.1  jmcneill  * modification, are permitted provided that the following conditions
      9      1.1  jmcneill  * are met:
     10      1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11      1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12      1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15      1.1  jmcneill  *
     16      1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17      1.1  jmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18      1.1  jmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.1  jmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20      1.1  jmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21      1.1  jmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22      1.1  jmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23      1.1  jmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24      1.1  jmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25      1.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26      1.1  jmcneill  * SUCH DAMAGE.
     27      1.1  jmcneill  */
     28      1.1  jmcneill 
     29      1.1  jmcneill #include <sys/cdefs.h>
     30      1.1  jmcneill 
     31  1.1.4.1  christos __KERNEL_RCSID(1, "$NetBSD: sun50i_h6_ccu.c,v 1.1.4.1 2019/06/10 22:05:56 christos Exp $");
     32      1.1  jmcneill 
     33      1.1  jmcneill #include <sys/param.h>
     34      1.1  jmcneill #include <sys/bus.h>
     35      1.1  jmcneill #include <sys/device.h>
     36      1.1  jmcneill #include <sys/systm.h>
     37      1.1  jmcneill 
     38      1.1  jmcneill #include <dev/fdt/fdtvar.h>
     39      1.1  jmcneill 
     40      1.1  jmcneill #include <arm/sunxi/sunxi_ccu.h>
     41      1.1  jmcneill #include <arm/sunxi/sun50i_h6_ccu.h>
     42      1.1  jmcneill 
     43  1.1.4.1  christos #define	PLL_CPUX_CTRL_REG	0x000
     44      1.1  jmcneill #define	PLL_PERI0_CTRL_REG	0x020
     45  1.1.4.1  christos #define	PSI_AHB1_AHB2_CFG_REG	0x510
     46      1.1  jmcneill #define	AHB3_CFG_REG		0x51c
     47      1.1  jmcneill #define	APB2_CFG_REG		0x524
     48      1.1  jmcneill #define	MBUS_CFG_REG		0x540
     49      1.1  jmcneill #define	DE_BGR_REG		0x60c
     50      1.1  jmcneill #define	DI_BGR_REG		0x62c
     51      1.1  jmcneill #define	GPU_BGR_REG		0x67c
     52      1.1  jmcneill #define	CE_BGR_REG		0x68c
     53      1.1  jmcneill #define	VE_BGR_REG		0x69c
     54      1.1  jmcneill #define	EMCE_BGR_REG		0x6bc
     55      1.1  jmcneill #define	VP9_BGR_REG		0x6cc
     56      1.1  jmcneill #define	DMA_BGR_REG		0x70c
     57      1.1  jmcneill #define	MSGBOX_BGR_REG		0x71c
     58      1.1  jmcneill #define	SPINLOCK_BGR_REG	0x72c
     59      1.1  jmcneill #define	HSTIMER_BGR_REG		0x73c
     60      1.1  jmcneill #define	DBGSYS_BGR_REG		0x78c
     61      1.1  jmcneill #define	PSI_BGR_REG		0x79c
     62      1.1  jmcneill #define	PWM_BGR_REG		0x7ac
     63      1.1  jmcneill #define	DRAM_CLK_REG		0x800
     64      1.1  jmcneill #define	NAND_BGR_REG		0x82c
     65      1.1  jmcneill #define	SMHC0_CLK_REG		0x830
     66      1.1  jmcneill #define	SMHC1_CLK_REG		0x834
     67      1.1  jmcneill #define	SMHC2_CLK_REG		0x838
     68      1.1  jmcneill #define	SMHC_BGR_REG		0x84c
     69      1.1  jmcneill #define	UART_BGR_REG		0x90c
     70      1.1  jmcneill #define	TWI_BGR_REG		0x91c
     71      1.1  jmcneill #define	SCR_BGR_REG		0x93c
     72      1.1  jmcneill #define	SPI_BGR_REG		0x96c
     73      1.1  jmcneill #define	EMAC_BGR_REG		0x97c
     74      1.1  jmcneill #define	TS_BGR_REG		0x9bc
     75      1.1  jmcneill #define	CIRTX_BGR_REG		0x9cc
     76      1.1  jmcneill #define	THS_BGR_REG		0x9fc
     77      1.1  jmcneill #define	I2S_PCM_BGR_REG		0xa1c
     78      1.1  jmcneill #define	OWA_BGR_REG		0xa2c
     79      1.1  jmcneill #define	DMIC_BGR_REG		0xa4c
     80      1.1  jmcneill #define	AUDIO_HUB_BGR_REG	0xa6c
     81      1.1  jmcneill #define	USB0_CLK_REG		0xa70
     82      1.1  jmcneill #define	USB1_CLK_REG		0xa74
     83      1.1  jmcneill #define	USB3_CLK_REG		0xa7c
     84      1.1  jmcneill #define	USB_BGR_REG		0xa8c
     85  1.1.4.1  christos #define	PCIE_REF_CLK_REG	0xab0
     86  1.1.4.1  christos #define	PCIE_AXI_CLK_REG	0xab4
     87  1.1.4.1  christos #define	PCIE_AUX_CLK_REG	0xab8
     88      1.1  jmcneill #define	PCIE_BGR_REG		0xabc
     89      1.1  jmcneill #define	HDMI_BGR_REG		0xb1c
     90      1.1  jmcneill #define	DISPLAY_IF_TOP_BGR_REG	0xb5c
     91      1.1  jmcneill #define	TCON_LCD_BGR_REG	0xb7c
     92      1.1  jmcneill #define	TCON_TV_BGR_REG		0xb9c
     93      1.1  jmcneill #define	CSI_BGR_REG		0xc2c
     94      1.1  jmcneill #define	HDMI_HDCP_BGR_REG	0xc4c
     95      1.1  jmcneill 
     96      1.1  jmcneill static int sun50i_h6_ccu_match(device_t, cfdata_t, void *);
     97      1.1  jmcneill static void sun50i_h6_ccu_attach(device_t, device_t, void *);
     98      1.1  jmcneill 
     99      1.1  jmcneill static const char * const compatible[] = {
    100      1.1  jmcneill 	"allwinner,sun50i-h6-ccu",
    101      1.1  jmcneill 	NULL
    102      1.1  jmcneill };
    103      1.1  jmcneill 
    104      1.1  jmcneill CFATTACH_DECL_NEW(sunxi_h6_ccu, sizeof(struct sunxi_ccu_softc),
    105      1.1  jmcneill 	sun50i_h6_ccu_match, sun50i_h6_ccu_attach, NULL, NULL);
    106      1.1  jmcneill 
    107      1.1  jmcneill static struct sunxi_ccu_reset sun50i_h6_ccu_resets[] = {
    108      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_MBUS, MBUS_CFG_REG, 30),
    109      1.1  jmcneill 
    110      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_DE, DE_BGR_REG, 16),
    111      1.1  jmcneill 
    112      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_DEINTERLACE, DI_BGR_REG, 16),
    113      1.1  jmcneill 
    114      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_GPU, GPU_BGR_REG, 16),
    115      1.1  jmcneill 
    116      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_CE, CE_BGR_REG, 16),
    117      1.1  jmcneill 
    118      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_VE, VE_BGR_REG, 16),
    119      1.1  jmcneill 
    120      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_EMCE, EMCE_BGR_REG, 16),
    121      1.1  jmcneill 
    122      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_VP9, VP9_BGR_REG, 16),
    123      1.1  jmcneill 
    124      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_DMA, DMA_BGR_REG, 16),
    125      1.1  jmcneill 
    126      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_MSGBOX, MSGBOX_BGR_REG, 16),
    127      1.1  jmcneill 
    128      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_SPINLOCK, SPINLOCK_BGR_REG, 16),
    129      1.1  jmcneill 
    130      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_HSTIMER, HSTIMER_BGR_REG, 16),
    131      1.1  jmcneill 
    132      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_DBG, DBGSYS_BGR_REG, 16),
    133      1.1  jmcneill 
    134      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_PSI, PSI_BGR_REG, 16),
    135      1.1  jmcneill 
    136      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_PWM, PWM_BGR_REG, 16),
    137      1.1  jmcneill 
    138      1.1  jmcneill 	/* H6_RST_BUS_IOMMU: No bit defined in user manual */
    139      1.1  jmcneill 
    140      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_DRAM, DRAM_CLK_REG, 30),
    141      1.1  jmcneill 
    142      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_NAND, NAND_BGR_REG, 16),
    143      1.1  jmcneill 
    144      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_MMC0, SMHC_BGR_REG, 16),
    145      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_MMC1, SMHC_BGR_REG, 17),
    146      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_MMC2, SMHC_BGR_REG, 18),
    147      1.1  jmcneill 
    148      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_UART0, UART_BGR_REG, 16),
    149      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_UART1, UART_BGR_REG, 17),
    150      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_UART2, UART_BGR_REG, 18),
    151      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_UART3, UART_BGR_REG, 19),
    152      1.1  jmcneill 
    153      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_I2C0, TWI_BGR_REG, 16),
    154      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_I2C1, TWI_BGR_REG, 17),
    155      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_I2C2, TWI_BGR_REG, 18),
    156      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_I2C3, TWI_BGR_REG, 19),
    157      1.1  jmcneill 
    158      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_SCR0, SCR_BGR_REG, 16),
    159      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_SCR1, SCR_BGR_REG, 17),
    160      1.1  jmcneill 
    161      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_SPI0, SPI_BGR_REG, 16),
    162      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_SPI1, SPI_BGR_REG, 17),
    163      1.1  jmcneill 
    164      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_EMAC, EMAC_BGR_REG, 16),
    165      1.1  jmcneill 
    166      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_TS, TS_BGR_REG, 16),
    167      1.1  jmcneill 
    168      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_IR_TX, CIRTX_BGR_REG, 16),
    169      1.1  jmcneill 
    170      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_THS, THS_BGR_REG, 16),
    171      1.1  jmcneill 
    172      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_I2S0, I2S_PCM_BGR_REG, 16),
    173      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_I2S1, I2S_PCM_BGR_REG, 17),
    174      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_I2S2, I2S_PCM_BGR_REG, 18),
    175      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_I2S3, I2S_PCM_BGR_REG, 19),
    176      1.1  jmcneill 
    177      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_SPDIF, OWA_BGR_REG, 16),
    178      1.1  jmcneill 
    179      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_DMIC, DMIC_BGR_REG, 16),
    180      1.1  jmcneill 
    181      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_AUDIO_HUB, AUDIO_HUB_BGR_REG, 16),
    182      1.1  jmcneill 
    183      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_USB_PHY0, USB0_CLK_REG, 30),
    184      1.1  jmcneill 
    185      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_USB_PHY1, USB1_CLK_REG, 30),
    186      1.1  jmcneill 
    187      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_USB_PHY3, USB3_CLK_REG, 30),
    188      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_USB_HSIC, USB3_CLK_REG, 28),
    189      1.1  jmcneill 
    190      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_OHCI0, USB_BGR_REG, 16),
    191      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_OHCI3, USB_BGR_REG, 19),
    192      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_EHCI0, USB_BGR_REG, 20),
    193      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_XHCI, USB_BGR_REG, 21),
    194      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_EHCI3, USB_BGR_REG, 23),
    195      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_OTG, USB_BGR_REG, 24),
    196      1.1  jmcneill 
    197      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_PCIE, PCIE_BGR_REG, 16),
    198      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_PCIE_POWERUP, PCIE_BGR_REG, 17),
    199      1.1  jmcneill 
    200      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_HDMI, HDMI_BGR_REG, 16),
    201      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_HDMI_SUB, HDMI_BGR_REG, 17),
    202      1.1  jmcneill 
    203      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_TCON_TOP, DISPLAY_IF_TOP_BGR_REG, 16),
    204      1.1  jmcneill 
    205      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_TCON_LCD0, TCON_LCD_BGR_REG, 16),
    206      1.1  jmcneill 
    207      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_TCON_TV0, TCON_TV_BGR_REG, 16),
    208      1.1  jmcneill 
    209      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_CSI, CSI_BGR_REG, 16),
    210      1.1  jmcneill 
    211      1.1  jmcneill 	SUNXI_CCU_RESET(H6_RST_BUS_HDCP, HDMI_HDCP_BGR_REG, 16),
    212      1.1  jmcneill };
    213      1.1  jmcneill 
    214      1.1  jmcneill static const char *ahb3_parents[] = { "hosc", "losc", "psi", "pll_periph0" };
    215      1.1  jmcneill static const char *apb2_parents[] = { "hosc", "losc", "psi", "pll_periph0" };
    216      1.1  jmcneill static const char *mod_parents[] = { "hosc", "pll_periph0_2x", "pll_periph1_2x" };
    217  1.1.4.1  christos static const char *hosc_parent[] = { "hosc" };
    218  1.1.4.1  christos static const char *pll_periph0_parent[] = { "pll_periph0" };
    219  1.1.4.1  christos static const char *psi_ahb1_ahb2_parents[] = { "hosc", "losc", "iosc", "pll_periph0" };
    220      1.1  jmcneill 
    221      1.1  jmcneill static struct sunxi_ccu_clk sun50i_h6_ccu_clks[] = {
    222      1.1  jmcneill 	SUNXI_CCU_FIXED_FACTOR(H6_CLK_OSC12M, "osc12m", "hosc", 2, 1),
    223      1.1  jmcneill 
    224  1.1.4.1  christos 	SUNXI_CCU_NKMP_TABLE(H6_CLK_PLL_CPUX, "pll_cpux", "hosc",
    225  1.1.4.1  christos 	    PLL_CPUX_CTRL_REG,		/* reg */
    226  1.1.4.1  christos 	    __BITS(15,8),		/* n */
    227  1.1.4.1  christos 	    0,				/* k */
    228  1.1.4.1  christos 	    __BITS(1,0),		/* m */
    229  1.1.4.1  christos 	    __BITS(17,16),		/* p */
    230  1.1.4.1  christos 	    __BIT(31),			/* enable */
    231  1.1.4.1  christos 	    __BIT(28),			/* lock */
    232  1.1.4.1  christos 	    NULL,			/* table */
    233  1.1.4.1  christos 	    SUNXI_CCU_NKMP_SCALE_CLOCK | SUNXI_CCU_NKMP_FACTOR_P_POW2),
    234  1.1.4.1  christos 
    235      1.1  jmcneill 	SUNXI_CCU_NKMP(H6_CLK_PLL_PERIPH0_4X, "pll_periph0_4x", "hosc",
    236      1.1  jmcneill 	    PLL_PERI0_CTRL_REG,		/* reg */
    237      1.1  jmcneill 	    __BITS(15,8),		/* n */
    238      1.1  jmcneill 	    0,		 		/* k */
    239      1.1  jmcneill 	    __BIT(1),			/* m */
    240      1.1  jmcneill 	    __BIT(0),			/* p */
    241      1.1  jmcneill 	    __BIT(31),			/* enable */
    242      1.1  jmcneill 	    0),
    243      1.1  jmcneill 	SUNXI_CCU_FIXED_FACTOR(H6_CLK_PLL_PERIPH0_2X, "pll_periph0_2x", "pll_periph0_4x", 2, 1),
    244      1.1  jmcneill 	SUNXI_CCU_FIXED_FACTOR(H6_CLK_PLL_PERIPH0, "pll_periph0", "pll_periph0_4x", 4, 1),
    245      1.1  jmcneill 
    246      1.1  jmcneill 	SUNXI_CCU_NM(H6_CLK_AHB3, "ahb3", ahb3_parents,
    247      1.1  jmcneill 	    AHB3_CFG_REG,	/* reg */
    248      1.1  jmcneill 	    __BITS(9,8),	/* n */
    249      1.1  jmcneill 	    __BITS(1,0),	/* m */
    250      1.1  jmcneill 	    __BITS(25,24),	/* sel */
    251      1.1  jmcneill 	    0,			/* enable */
    252      1.1  jmcneill 	    SUNXI_CCU_NM_POWER_OF_TWO),
    253      1.1  jmcneill 
    254      1.1  jmcneill 	SUNXI_CCU_NM(H6_CLK_APB2, "apb2", apb2_parents,
    255      1.1  jmcneill 	    APB2_CFG_REG,	/* reg */
    256      1.1  jmcneill 	    __BITS(9,8),	/* n */
    257      1.1  jmcneill 	    __BITS(1,0),	/* m */
    258      1.1  jmcneill 	    __BITS(25,24),	/* sel */
    259      1.1  jmcneill 	    0,			/* enable */
    260      1.1  jmcneill 	    SUNXI_CCU_NM_POWER_OF_TWO),
    261      1.1  jmcneill 
    262      1.1  jmcneill 	SUNXI_CCU_NM(H6_CLK_MMC0, "mmc0", mod_parents,
    263      1.1  jmcneill 	    SMHC0_CLK_REG,	/* reg */
    264      1.1  jmcneill 	    __BITS(9,8),	/* n */
    265      1.1  jmcneill 	    __BITS(3,0),	/* m */
    266      1.1  jmcneill 	    __BITS(25,24),	/* sel */
    267      1.1  jmcneill 	    __BIT(31),		/* enable */
    268      1.1  jmcneill 	    SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
    269      1.1  jmcneill 	SUNXI_CCU_NM(H6_CLK_MMC1, "mmc1", mod_parents,
    270      1.1  jmcneill 	    SMHC1_CLK_REG,	/* reg */
    271      1.1  jmcneill 	    __BITS(9,8),	/* n */
    272      1.1  jmcneill 	    __BITS(3,0),	/* m */
    273      1.1  jmcneill 	    __BITS(25,24),	/* sel */
    274      1.1  jmcneill 	    __BIT(31),		/* enable */
    275      1.1  jmcneill 	    SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
    276      1.1  jmcneill 	SUNXI_CCU_NM(H6_CLK_MMC2, "mmc2", mod_parents,
    277      1.1  jmcneill 	    SMHC2_CLK_REG,	/* reg */
    278      1.1  jmcneill 	    __BITS(9,8),	/* n */
    279      1.1  jmcneill 	    __BITS(3,0),	/* m */
    280      1.1  jmcneill 	    __BITS(25,24),	/* sel */
    281      1.1  jmcneill 	    __BIT(31),		/* enable */
    282      1.1  jmcneill 	    SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
    283      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_MMC0, "bus-mmc0", "mmc0",
    284      1.1  jmcneill 	    SMHC_BGR_REG, 0),
    285      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_MMC1, "bus-mmc1", "mmc1",
    286      1.1  jmcneill 	    SMHC_BGR_REG, 1),
    287      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_MMC2, "bus-mmc2", "mmc2",
    288      1.1  jmcneill 	    SMHC_BGR_REG, 2),
    289      1.1  jmcneill 
    290      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_UART0, "bus-uart0", "apb2",
    291      1.1  jmcneill 	    UART_BGR_REG, 0),
    292      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_UART1, "bus-uart1", "apb2",
    293      1.1  jmcneill 	    UART_BGR_REG, 1),
    294      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_UART2, "bus-uart2", "apb2",
    295      1.1  jmcneill 	    UART_BGR_REG, 2),
    296      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_UART3, "bus-uart3", "apb2",
    297      1.1  jmcneill 	    UART_BGR_REG, 3),
    298      1.1  jmcneill 
    299      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_I2C0, "bus-i2c0", "apb2",
    300      1.1  jmcneill 	    TWI_BGR_REG, 0),
    301      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_I2C1, "bus-i2c1", "apb2",
    302      1.1  jmcneill 	    TWI_BGR_REG, 1),
    303      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_I2C2, "bus-i2c2", "apb2",
    304      1.1  jmcneill 	    TWI_BGR_REG, 2),
    305      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_I2C3, "bus-i2c3", "apb2",
    306      1.1  jmcneill 	    TWI_BGR_REG, 3),
    307      1.1  jmcneill 
    308      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_USB_OHCI0, "usb-ohci0", "ahb3",
    309      1.1  jmcneill 	    USB0_CLK_REG, 31),
    310      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_USB_PHY0, "usb-phy0", "ahb3",
    311      1.1  jmcneill 	    USB0_CLK_REG, 29),
    312      1.1  jmcneill 
    313      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_USB_PHY1, "usb-phy1", "ahb3",
    314      1.1  jmcneill 	    USB1_CLK_REG, 29),
    315      1.1  jmcneill 
    316      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_USB_OHCI3, "usb-ohci3", "ahb3",
    317      1.1  jmcneill 	    USB3_CLK_REG, 31),
    318      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_USB_PHY3, "usb-phy3", "ahb3",
    319      1.1  jmcneill 	    USB3_CLK_REG, 29),
    320      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_USB_HSIC_12M, "usb-hsic-12m", "osc12m",
    321      1.1  jmcneill 	    USB3_CLK_REG, 27),
    322      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_USB_HSIC, "usb-hsic", "ahb3",
    323      1.1  jmcneill 	    USB3_CLK_REG, 26),
    324      1.1  jmcneill 
    325      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_OHCI0, "bus-ohci0", "ahb3",
    326      1.1  jmcneill 	    USB_BGR_REG, 0),
    327      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_OHCI3, "bus-ohci3", "ahb3",
    328      1.1  jmcneill 	    USB_BGR_REG, 3),
    329      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_EHCI0, "bus-ehci0", "ahb3",
    330      1.1  jmcneill 	    USB_BGR_REG, 4),
    331      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_XHCI, "bus-xhci", "ahb3",
    332      1.1  jmcneill 	    USB_BGR_REG, 5),
    333      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_EHCI3, "bus-ehci3", "ahb3",
    334      1.1  jmcneill 	    USB_BGR_REG, 7),
    335      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_OTG, "bus-otg", "ahb3",
    336      1.1  jmcneill 	    USB_BGR_REG, 8),
    337      1.1  jmcneill 
    338      1.1  jmcneill 	SUNXI_CCU_GATE(H6_CLK_BUS_EMAC, "bus-emac", "ahb3",
    339      1.1  jmcneill 	    EMAC_BGR_REG, 0),
    340  1.1.4.1  christos 
    341  1.1.4.1  christos 	SUNXI_CCU_FIXED_FACTOR(H6_CLK_PCIE_REF_100M, "pcie_ref_100M",
    342  1.1.4.1  christos 	    "pll_periph0_4x", 24, 1),
    343  1.1.4.1  christos 	SUNXI_CCU_GATE(H6_CLK_PCIE_REF, "pcie_ref", "pcie_ref_100M",
    344  1.1.4.1  christos 	    PCIE_REF_CLK_REG, 31),
    345  1.1.4.1  christos 	SUNXI_CCU_GATE(H6_CLK_PCIE_REF_OUT, "pcie_ref_out", "pcie_ref",
    346  1.1.4.1  christos 	    PCIE_REF_CLK_REG, 30),
    347  1.1.4.1  christos 
    348  1.1.4.1  christos 	SUNXI_CCU_NM(H6_CLK_PSI_AHB1_AHB2, "psi_ahb1_ahb2",
    349  1.1.4.1  christos 	    psi_ahb1_ahb2_parents,
    350  1.1.4.1  christos 	    PSI_AHB1_AHB2_CFG_REG,	/* reg */
    351  1.1.4.1  christos 	    __BITS(9,8),	/* n */
    352  1.1.4.1  christos 	    __BITS(1,0),	/* m */
    353  1.1.4.1  christos 	    __BITS(25,24),	/* sel */
    354  1.1.4.1  christos 	    0,			/* enable */
    355  1.1.4.1  christos 	    SUNXI_CCU_NM_POWER_OF_TWO),
    356  1.1.4.1  christos 	SUNXI_CCU_DIV_GATE(H6_CLK_PCIE_MAXI, "pcie_maxi", pll_periph0_parent,
    357  1.1.4.1  christos 	    PCIE_AXI_CLK_REG,	/* reg */
    358  1.1.4.1  christos 	    __BITS(3,0),	/* div */
    359  1.1.4.1  christos 	    0,			/* sel */
    360  1.1.4.1  christos 	    __BIT(31),		/* enable */
    361  1.1.4.1  christos 	    SUNXI_CCU_DIV_ZERO_IS_ONE),
    362  1.1.4.1  christos 	SUNXI_CCU_DIV_GATE(H6_CLK_PCIE_AUX, "pcie_aux", hosc_parent,
    363  1.1.4.1  christos 	    PCIE_AUX_CLK_REG,	/* reg */
    364  1.1.4.1  christos 	    __BITS(4,0),	/* div */
    365  1.1.4.1  christos 	    0,			/* sel */
    366  1.1.4.1  christos 	    __BIT(31),		/* enable */
    367  1.1.4.1  christos 	    SUNXI_CCU_DIV_ZERO_IS_ONE),
    368  1.1.4.1  christos 
    369  1.1.4.1  christos 	SUNXI_CCU_GATE(H6_CLK_BUS_PCIE, "bus_pcie", "psi_ahb1_ahb2",
    370  1.1.4.1  christos 	    PCIE_BGR_REG, 0),
    371      1.1  jmcneill };
    372      1.1  jmcneill 
    373      1.1  jmcneill static int
    374      1.1  jmcneill sun50i_h6_ccu_match(device_t parent, cfdata_t cf, void *aux)
    375      1.1  jmcneill {
    376      1.1  jmcneill 	struct fdt_attach_args * const faa = aux;
    377      1.1  jmcneill 
    378      1.1  jmcneill 	return of_match_compatible(faa->faa_phandle, compatible);
    379      1.1  jmcneill }
    380      1.1  jmcneill 
    381      1.1  jmcneill static void
    382      1.1  jmcneill sun50i_h6_ccu_attach(device_t parent, device_t self, void *aux)
    383      1.1  jmcneill {
    384      1.1  jmcneill 	struct sunxi_ccu_softc * const sc = device_private(self);
    385      1.1  jmcneill 	struct fdt_attach_args * const faa = aux;
    386      1.1  jmcneill 
    387      1.1  jmcneill 	sc->sc_dev = self;
    388      1.1  jmcneill 	sc->sc_phandle = faa->faa_phandle;
    389      1.1  jmcneill 	sc->sc_bst = faa->faa_bst;
    390      1.1  jmcneill 
    391      1.1  jmcneill 	sc->sc_resets = sun50i_h6_ccu_resets;
    392      1.1  jmcneill 	sc->sc_nresets = __arraycount(sun50i_h6_ccu_resets);
    393      1.1  jmcneill 
    394      1.1  jmcneill 	sc->sc_clks = sun50i_h6_ccu_clks;
    395      1.1  jmcneill 	sc->sc_nclks = __arraycount(sun50i_h6_ccu_clks);
    396      1.1  jmcneill 
    397      1.1  jmcneill 	if (sunxi_ccu_attach(sc) != 0)
    398      1.1  jmcneill 		return;
    399      1.1  jmcneill 
    400      1.1  jmcneill 	aprint_naive("\n");
    401      1.1  jmcneill 	aprint_normal(": H6 CCU\n");
    402      1.1  jmcneill 
    403      1.1  jmcneill 	sunxi_ccu_print(sc);
    404      1.1  jmcneill }
    405