Allwinner: Add clock driver for ccu_sun8i_r

SUN8I and SUN50I (H3, H5, A83T and A64) have a second clock controller
unit. It controls the clocks for the second gpio controller, the IR
controller etc ...
Support for A83T is not supported.

Tested On: OrangePi One, Pine64
This commit is contained in:
Emmanuel Vadot 2017-10-07 16:48:42 +00:00
parent 313a64359d
commit ac9297c128
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=324383
5 changed files with 178 additions and 3 deletions

View File

@ -64,10 +64,12 @@ __FBSDID("$FreeBSD$");
#if defined(SOC_ALLWINNER_A64)
#include <arm/allwinner/clkng/ccu_a64.h>
#include <arm/allwinner/clkng/ccu_sun8i_r.h>
#endif
#if defined(SOC_ALLWINNER_H3) || defined(SOC_ALLWINNER_H5)
#include <arm/allwinner/clkng/ccu_h3.h>
#include <arm/allwinner/clkng/ccu_sun8i_r.h>
#endif
#include "clkdev_if.h"
@ -79,26 +81,30 @@ static struct resource_spec aw_ccung_spec[] = {
};
#if defined(SOC_ALLWINNER_H3) || defined(SOC_ALLWINNER_H5)
#define H3_CCU 1
#define H3_CCU 1
#define H3_R_CCU 2
#endif
#if defined(SOC_ALLWINNER_A31)
#define A31_CCU 2
#define A31_CCU 3
#endif
#if defined(SOC_ALLWINNER_A64)
#define A64_CCU 2
#define A64_CCU 4
#define A64_R_CCU 5
#endif
static struct ofw_compat_data compat_data[] = {
#if defined(SOC_ALLWINNER_H3) || defined(SOC_ALLWINNER_H5)
{ "allwinner,sun8i-h3-ccu", H3_CCU },
{ "allwinner,sun8i-h3-r-ccu", H3_R_CCU },
#endif
#if defined(SOC_ALLWINNER_A31)
{ "allwinner,sun6i-a31-ccu", A31_CCU },
#endif
#if defined(SOC_ALLWINNER_A64)
{ "allwinner,sun50i-a64-ccu", A64_CCU },
{ "allwinner,sun50i-a64-r-ccu", A64_R_CCU },
#endif
{NULL, 0 }
};
@ -320,6 +326,9 @@ aw_ccung_attach(device_t dev)
case H3_CCU:
ccu_h3_register_clocks(sc);
break;
case H3_R_CCU:
ccu_sun8i_r_register_clocks(sc);
break;
#endif
#if defined(SOC_ALLWINNER_A31)
case A31_CCU:
@ -330,6 +339,9 @@ aw_ccung_attach(device_t dev)
case A64_CCU:
ccu_a64_register_clocks(sc);
break;
case A64_R_CCU:
ccu_sun8i_r_register_clocks(sc);
break;
#endif
}

View File

@ -0,0 +1,127 @@
/*-
* Copyright (c) 2017 Emmanuel Vadot <manu@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <dev/extres/clk/clk_div.h>
#include <dev/extres/clk/clk_fixed.h>
#include <dev/extres/clk/clk_mux.h>
#include <arm/allwinner/clkng/aw_ccung.h>
#include <arm/allwinner/clkng/aw_clk.h>
#include <arm/allwinner/clkng/aw_clk_nm.h>
#include <arm/allwinner/clkng/aw_clk_nkmp.h>
#include <arm/allwinner/clkng/aw_clk_prediv_mux.h>
#include <arm/allwinner/clkng/ccu_sun8i_r.h>
#include <gnu/dts/include/dt-bindings/clock/sun8i-r-ccu.h>
#include <gnu/dts/include/dt-bindings/reset/sun8i-r-ccu.h>
/* Non-exported clocks */
#define CLK_AHB0 1
#define CLK_APB0 2
static struct aw_ccung_reset ccu_sun8i_r_resets[] = {
CCU_RESET(RST_APB0_IR, 0xb0, 1)
CCU_RESET(RST_APB0_TIMER, 0xb0, 2)
CCU_RESET(RST_APB0_RSB, 0xb0, 4)
CCU_RESET(RST_APB0_UART, 0xb0, 6)
};
static struct aw_ccung_gate ccu_sun8i_r_gates[] = {
CCU_GATE(CLK_APB0_PIO, "apb0-pio", "apb0", 0x28, 0)
CCU_GATE(CLK_APB0_IR, "apb0-ir", "apb0", 0x28, 1)
CCU_GATE(CLK_APB0_TIMER, "apb0-timer", "apb0", 0x28, 2)
CCU_GATE(CLK_APB0_RSB, "apb0-rsb", "apb0", 0x28, 3)
CCU_GATE(CLK_APB0_UART, "apb0-uart", "apb0", 0x28, 4)
CCU_GATE(CLK_APB0_I2C, "apb0-i2c", "apb0", 0x28, 6)
CCU_GATE(CLK_APB0_TWD, "apb0-twd", "apb0", 0x28, 7)
};
static const char *ar100_parents[] = {"osc32k", "osc24M", "pll_periph0", "iosc"};
PREDIV_CLK(ar100_clk, CLK_AR100, /* id */
"ar100", ar100_parents, /* name, parents */
0x00, /* offset */
16, 2, /* mux */
4, 2, 0, AW_CLK_FACTOR_POWER_OF_TWO, /* div */
8, 5, 0, AW_CLK_FACTOR_HAS_COND, /* prediv */
16, 2, 2); /* prediv condition */
static const char *ahb0_parents[] = {"ar100"};
FIXED_CLK(ahb0_clk,
CLK_AHB0, /* id */
"ahb0", /* name */
ahb0_parents, /* parent */
0, /* freq */
1, /* mult */
1, /* div */
0); /* flags */
static const char *apb0_parents[] = {"ahb0"};
DIV_CLK(apb0_clk,
CLK_APB0, /* id */
"apb0", apb0_parents, /* name, parents */
0x0c, /* offset */
0, 2, /* shift, width */
0, NULL); /* flags, div table */
static struct aw_clk_prediv_mux_def *prediv_mux_clks[] = {
&ar100_clk,
};
static struct clk_div_def *div_clks[] = {
&apb0_clk,
};
static struct clk_fixed_def *fixed_factor_clks[] = {
&ahb0_clk,
};
void
ccu_sun8i_r_register_clocks(struct aw_ccung_softc *sc)
{
int i;
sc->resets = ccu_sun8i_r_resets;
sc->nresets = nitems(ccu_sun8i_r_resets);
sc->gates = ccu_sun8i_r_gates;
sc->ngates = nitems(ccu_sun8i_r_gates);
for (i = 0; i < nitems(prediv_mux_clks); i++)
aw_clk_prediv_mux_register(sc->clkdom, prediv_mux_clks[i]);
for (i = 0; i < nitems(div_clks); i++)
clknode_div_register(sc->clkdom, div_clks[i]);
for (i = 0; i < nitems(fixed_factor_clks); i++)
clknode_fixed_register(sc->clkdom, fixed_factor_clks[i]);
}

View File

@ -0,0 +1,34 @@
/*-
* Copyright (c) 2017 Emmanuel Vadot <manu@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef __CCU_SUN8I_R_H__
#define __CCU_SUN8I_R_H__
void ccu_sun8i_r_register_clocks(struct aw_ccung_softc *sc);
#endif /* __CCU_SUN8I_R_H__ */

View File

@ -1,5 +1,6 @@
# $FreeBSD$
arm/allwinner/clkng/ccu_h3.c standard
arm/allwinner/clkng/ccu_sun8i_r.c standard
arm/allwinner/h3/h3_padconf.c standard
arm/allwinner/h3/h3_r_padconf.c standard

View File

@ -43,6 +43,7 @@ arm/allwinner/clkng/aw_clk_nm.c optional aw_ccu fdt
arm/allwinner/clkng/aw_clk_prediv_mux.c optional aw_ccu fdt
arm/allwinner/clkng/ccu_a64.c optional aw_ccu fdt
arm/allwinner/clkng/ccu_h3.c optional aw_ccu fdt
arm/allwinner/clkng/ccu_sun8i_r.c optional aw_ccu fdt
arm/allwinner/if_awg.c optional awg fdt
arm/annapurna/alpine/alpine_ccu.c optional al_ccu fdt