Wed May 5 10:24:04 2021 UTC ()
Add support for Allwinner V3s, from Rui-Xiang Guo.


(jmcneill)
diff -r1.68 -r1.69 src/sys/arch/arm/sunxi/files.sunxi
diff -r1.14 -r1.15 src/sys/arch/arm/sunxi/sun6i_dma.c
diff -r0 -r1.1 src/sys/arch/arm/sunxi/sun8i_v3s_ccu.c
diff -r0 -r1.1 src/sys/arch/arm/sunxi/sun8i_v3s_ccu.h
diff -r0 -r1.1 src/sys/arch/arm/sunxi/sun8i_v3s_codec.c
diff -r1.12 -r1.13 src/sys/arch/arm/sunxi/sunxi_codec.c
diff -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_codec.h
diff -r1.96 -r1.97 src/sys/arch/evbarm/conf/GENERIC

cvs diff -r1.68 -r1.69 src/sys/arch/arm/sunxi/files.sunxi (expand / switch to unified diff)

--- src/sys/arch/arm/sunxi/files.sunxi 2020/03/24 22:09:50 1.68
+++ src/sys/arch/arm/sunxi/files.sunxi 2021/05/05 10:24:04 1.69
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: files.sunxi,v 1.68 2020/03/24 22:09:50 tnn Exp $ 1# $NetBSD: files.sunxi,v 1.69 2021/05/05 10:24:04 jmcneill Exp $
2# 2#
3# Configuration info for Allwinner sunxi family SoCs 3# Configuration info for Allwinner sunxi family SoCs
4# 4#
5# 5#
6 6
7file arch/arm/sunxi/sunxi_platform.c soc_sunxi 7file arch/arm/sunxi/sunxi_platform.c soc_sunxi
8 8
9file arch/arm/sunxi/sunxi_mc_smp.c soc_sunxi_mc 9file arch/arm/sunxi/sunxi_mc_smp.c soc_sunxi_mc
10file arch/arm/sunxi/sunxi_mc_mpstart.S soc_sunxi_mc 10file arch/arm/sunxi/sunxi_mc_mpstart.S soc_sunxi_mc
11 11
12# CCU 12# CCU
13define sunxi_ccu 13define sunxi_ccu
14file arch/arm/sunxi/sunxi_ccu.c sunxi_ccu 14file arch/arm/sunxi/sunxi_ccu.c sunxi_ccu
@@ -42,26 +42,31 @@ device sun8ia83tccu: sunxi_ccu @@ -42,26 +42,31 @@ device sun8ia83tccu: sunxi_ccu
42attach sun8ia83tccu at fdt with sunxi_a83t_ccu 42attach sun8ia83tccu at fdt with sunxi_a83t_ccu
43file arch/arm/sunxi/sun8i_a83t_ccu.c sunxi_a83t_ccu 43file arch/arm/sunxi/sun8i_a83t_ccu.c sunxi_a83t_ccu
44 44
45# CCU (H3) 45# CCU (H3)
46device sun8ih3ccu: sunxi_ccu 46device sun8ih3ccu: sunxi_ccu
47attach sun8ih3ccu at fdt with sunxi_h3_ccu 47attach sun8ih3ccu at fdt with sunxi_h3_ccu
48file arch/arm/sunxi/sun8i_h3_ccu.c sunxi_h3_ccu 48file arch/arm/sunxi/sun8i_h3_ccu.c sunxi_h3_ccu
49 49
50# CCU (H3 PRCM) 50# CCU (H3 PRCM)
51device sun8ih3rccu: sunxi_ccu 51device sun8ih3rccu: sunxi_ccu
52attach sun8ih3rccu at fdt with sunxi_h3_r_ccu 52attach sun8ih3rccu at fdt with sunxi_h3_r_ccu
53file arch/arm/sunxi/sun8i_h3_r_ccu.c sunxi_h3_r_ccu 53file arch/arm/sunxi/sun8i_h3_r_ccu.c sunxi_h3_r_ccu
54 54
 55# CCU (V3s)
 56device sun8iv3sccu: sunxi_ccu
 57attach sun8iv3sccu at fdt with sunxi_v3s_ccu
 58file arch/arm/sunxi/sun8i_v3s_ccu.c sunxi_v3s_ccu
 59
55# CCU (A80) 60# CCU (A80)
56device sun9ia80ccu: sunxi_ccu 61device sun9ia80ccu: sunxi_ccu
57attach sun9ia80ccu at fdt with sunxi_a80_ccu 62attach sun9ia80ccu at fdt with sunxi_a80_ccu
58file arch/arm/sunxi/sun9i_a80_ccu.c sunxi_a80_ccu 63file arch/arm/sunxi/sun9i_a80_ccu.c sunxi_a80_ccu
59 64
60# CCU (A64) 65# CCU (A64)
61device sun50ia64ccu: sunxi_ccu 66device sun50ia64ccu: sunxi_ccu
62attach sun50ia64ccu at fdt with sunxi_a64_ccu 67attach sun50ia64ccu at fdt with sunxi_a64_ccu
63file arch/arm/sunxi/sun50i_a64_ccu.c sunxi_a64_ccu 68file arch/arm/sunxi/sun50i_a64_ccu.c sunxi_a64_ccu
64 69
65# CCU (A64 PRCM) 70# CCU (A64 PRCM)
66device sun50ia64rccu: sunxi_ccu 71device sun50ia64rccu: sunxi_ccu
67attach sun50ia64rccu at fdt with sunxi_a64_r_ccu 72attach sun50ia64rccu at fdt with sunxi_a64_r_ccu
@@ -223,26 +228,31 @@ file arch/arm/sunxi/sunxi_codec.c sunxi @@ -223,26 +228,31 @@ file arch/arm/sunxi/sunxi_codec.c sunxi
223file arch/arm/sunxi/sun4i_a10_codec.c sunxi_codec 228file arch/arm/sunxi/sun4i_a10_codec.c sunxi_codec
224file arch/arm/sunxi/sun6i_a31_codec.c sunxi_codec 229file arch/arm/sunxi/sun6i_a31_codec.c sunxi_codec
225 230
226# Audio codec (sun8i) 231# Audio codec (sun8i)
227device sun8icodec 232device sun8icodec
228attach sun8icodec at fdt with sun8i_codec 233attach sun8icodec at fdt with sun8i_codec
229file arch/arm/sunxi/sun8i_codec.c sun8i_codec 234file arch/arm/sunxi/sun8i_codec.c sun8i_codec
230 235
231# H3 Audio codec (analog part) 236# H3 Audio codec (analog part)
232device h3codec 237device h3codec
233attach h3codec at fdt with h3_codec 238attach h3codec at fdt with h3_codec
234file arch/arm/sunxi/sun8i_h3_codec.c h3_codec needs-flag 239file arch/arm/sunxi/sun8i_h3_codec.c h3_codec needs-flag
235 240
 241# V3s Audio codec (analog part)
 242device v3scodec
 243attach v3scodec at fdt with v3s_codec
 244file arch/arm/sunxi/sun8i_v3s_codec.c v3s_codec needs-flag
 245
236# A64 Audio codec (analog part) 246# A64 Audio codec (analog part)
237device a64acodec 247device a64acodec
238attach a64acodec at fdt with a64_acodec 248attach a64acodec at fdt with a64_acodec
239file arch/arm/sunxi/sun50i_a64_acodec.c a64_acodec 249file arch/arm/sunxi/sun50i_a64_acodec.c a64_acodec
240 250
241# I2S/PCM controller 251# I2S/PCM controller
242device sunxii2s 252device sunxii2s
243attach sunxii2s at fdt with sunxi_i2s 253attach sunxii2s at fdt with sunxi_i2s
244file arch/arm/sunxi/sunxi_i2s.c sunxi_i2s 254file arch/arm/sunxi/sunxi_i2s.c sunxi_i2s
245 255
246# A10/A20 LCD/TV timing controller (TCON) 256# A10/A20 LCD/TV timing controller (TCON)
247device sunxitcon 257device sunxitcon
248attach sunxitcon at fdt with sunxi_tcon 258attach sunxitcon at fdt with sunxi_tcon
@@ -365,19 +375,20 @@ file arch/arm/sunxi/sun8i_crypto.c sun8 @@ -365,19 +375,20 @@ file arch/arm/sunxi/sun8i_crypto.c sun8
365defflag opt_soc.h SOC_SUNXI 375defflag opt_soc.h SOC_SUNXI
366defflag opt_soc.h SOC_SUNXI_MC 376defflag opt_soc.h SOC_SUNXI_MC
367defflag opt_soc.h SOC_SUN4I: SOC_SUNXI 377defflag opt_soc.h SOC_SUN4I: SOC_SUNXI
368defflag opt_soc.h SOC_SUN4I_A10: SOC_SUN4I 378defflag opt_soc.h SOC_SUN4I_A10: SOC_SUN4I
369defflag opt_soc.h SOC_SUN5I: SOC_SUNXI 379defflag opt_soc.h SOC_SUN5I: SOC_SUNXI
370defflag opt_soc.h SOC_SUN5I_A13: SOC_SUN5I 380defflag opt_soc.h SOC_SUN5I_A13: SOC_SUN5I
371defflag opt_soc.h SOC_SUN6I: SOC_SUNXI 381defflag opt_soc.h SOC_SUN6I: SOC_SUNXI
372defflag opt_soc.h SOC_SUN6I_A31: SOC_SUN6I 382defflag opt_soc.h SOC_SUN6I_A31: SOC_SUN6I
373defflag opt_soc.h SOC_SUN7I: SOC_SUNXI 383defflag opt_soc.h SOC_SUN7I: SOC_SUNXI
374defflag opt_soc.h SOC_SUN7I_A20: SOC_SUN7I 384defflag opt_soc.h SOC_SUN7I_A20: SOC_SUN7I
375defflag opt_soc.h SOC_SUN8I: SOC_SUNXI 385defflag opt_soc.h SOC_SUN8I: SOC_SUNXI
376defflag opt_soc.h SOC_SUN8I_A83T: SOC_SUN8I, SOC_SUNXI_MC 386defflag opt_soc.h SOC_SUN8I_A83T: SOC_SUN8I, SOC_SUNXI_MC
377defflag opt_soc.h SOC_SUN8I_H3: SOC_SUN8I 387defflag opt_soc.h SOC_SUN8I_H3: SOC_SUN8I
 388defflag opt_soc.h SOC_SUN8I_V3S: SOC_SUN8I
378defflag opt_soc.h SOC_SUN9I: SOC_SUNXI 389defflag opt_soc.h SOC_SUN9I: SOC_SUNXI
379defflag opt_soc.h SOC_SUN9I_A80: SOC_SUN9I, SOC_SUNXI_MC 390defflag opt_soc.h SOC_SUN9I_A80: SOC_SUN9I, SOC_SUNXI_MC
380defflag opt_soc.h SOC_SUN50I: SOC_SUNXI 391defflag opt_soc.h SOC_SUN50I: SOC_SUNXI
381defflag opt_soc.h SOC_SUN50I_A64: SOC_SUN50I 392defflag opt_soc.h SOC_SUN50I_A64: SOC_SUN50I
382defflag opt_soc.h SOC_SUN50I_H5: SOC_SUN50I, SOC_SUN8I_H3 393defflag opt_soc.h SOC_SUN50I_H5: SOC_SUN50I, SOC_SUN8I_H3
383defflag opt_soc.h SOC_SUN50I_H6: SOC_SUN50I 394defflag opt_soc.h SOC_SUN50I_H6: SOC_SUN50I

cvs diff -r1.14 -r1.15 src/sys/arch/arm/sunxi/sun6i_dma.c (expand / switch to unified diff)

--- src/sys/arch/arm/sunxi/sun6i_dma.c 2021/01/27 03:10:20 1.14
+++ src/sys/arch/arm/sunxi/sun6i_dma.c 2021/05/05 10:24:04 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sun6i_dma.c,v 1.14 2021/01/27 03:10:20 thorpej Exp $ */ 1/* $NetBSD: sun6i_dma.c,v 1.15 2021/05/05 10:24:04 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include "opt_ddb.h" 29#include "opt_ddb.h"
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.14 2021/01/27 03:10:20 thorpej Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: sun6i_dma.c,v 1.15 2021/05/05 10:24:04 jmcneill Exp $");
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/bus.h> 35#include <sys/bus.h>
36#include <sys/device.h> 36#include <sys/device.h>
37#include <sys/intr.h> 37#include <sys/intr.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39#include <sys/mutex.h> 39#include <sys/mutex.h>
40#include <sys/bitops.h> 40#include <sys/bitops.h>
41#include <sys/kmem.h> 41#include <sys/kmem.h>
42 42
43#include <dev/fdt/fdtvar.h> 43#include <dev/fdt/fdtvar.h>
44 44
45#define DMA_IRQ_EN_REG0_REG 0x0000 45#define DMA_IRQ_EN_REG0_REG 0x0000
@@ -131,43 +131,55 @@ static const struct sun6idma_config sun8 @@ -131,43 +131,55 @@ static const struct sun6idma_config sun8
131 .widths = WIDTHS_1_2_4, 131 .widths = WIDTHS_1_2_4,
132}; 132};
133 133
134static const struct sun6idma_config sun8i_h3_dma_config = { 134static const struct sun6idma_config sun8i_h3_dma_config = {
135 .num_channels = 12, 135 .num_channels = 12,
136 .autogate = true, 136 .autogate = true,
137 .autogate_reg = 0x28, 137 .autogate_reg = 0x28,
138 .autogate_mask = 0x4, 138 .autogate_mask = 0x4,
139 .burst_mask = __BITS(7,6), 139 .burst_mask = __BITS(7,6),
140 .bursts = BURSTS_1_4_8_16, 140 .bursts = BURSTS_1_4_8_16,
141 .widths = WIDTHS_1_2_4_8, 141 .widths = WIDTHS_1_2_4_8,
142}; 142};
143 143
 144static const struct sun6idma_config sun8i_v3s_dma_config = {
 145 .num_channels = 8,
 146 .autogate = true,
 147 .autogate_reg = 0x20,
 148 .autogate_mask = 0x4,
 149 .burst_mask = __BITS(8,7),
 150 .bursts = BURSTS_1_8,
 151 .widths = WIDTHS_1_2_4,
 152};
 153
144static const struct sun6idma_config sun50i_a64_dma_config = { 154static const struct sun6idma_config sun50i_a64_dma_config = {
145 .num_channels = 8, 155 .num_channels = 8,
146 .autogate = true, 156 .autogate = true,
147 .autogate_reg = 0x28, 157 .autogate_reg = 0x28,
148 .autogate_mask = 0x4, 158 .autogate_mask = 0x4,
149 .burst_mask = __BITS(7,6), 159 .burst_mask = __BITS(7,6),
150 .bursts = BURSTS_1_4_8_16, 160 .bursts = BURSTS_1_4_8_16,
151 .widths = WIDTHS_1_2_4_8, 161 .widths = WIDTHS_1_2_4_8,
152}; 162};
153 163
154static const struct device_compatible_entry compat_data[] = { 164static const struct device_compatible_entry compat_data[] = {
155 { .compat = "allwinner,sun6i-a31-dma", 165 { .compat = "allwinner,sun6i-a31-dma",
156 .data = &sun6i_a31_dma_config }, 166 .data = &sun6i_a31_dma_config },
157 { .compat = "allwinner,sun8i-a83t-dma", 167 { .compat = "allwinner,sun8i-a83t-dma",
158 .data = &sun8i_a83t_dma_config }, 168 .data = &sun8i_a83t_dma_config },
159 { .compat = "allwinner,sun8i-h3-dma", 169 { .compat = "allwinner,sun8i-h3-dma",
160 .data = &sun8i_h3_dma_config }, 170 .data = &sun8i_h3_dma_config },
 171 { .compat = "allwinner,sun8i-v3s-dma",
 172 .data = &sun8i_v3s_dma_config },
161 { .compat = "allwinner,sun50i-a64-dma", 173 { .compat = "allwinner,sun50i-a64-dma",
162 .data = &sun50i_a64_dma_config }, 174 .data = &sun50i_a64_dma_config },
163 175
164 DEVICE_COMPAT_EOL 176 DEVICE_COMPAT_EOL
165}; 177};
166 178
167struct sun6idma_channel { 179struct sun6idma_channel {
168 uint8_t ch_index; 180 uint8_t ch_index;
169 void (*ch_callback)(void *); 181 void (*ch_callback)(void *);
170 void *ch_callbackarg; 182 void *ch_callbackarg;
171 u_int ch_portid; 183 u_int ch_portid;
172 void *ch_dmadesc; 184 void *ch_dmadesc;
173}; 185};

File Added: src/sys/arch/arm/sunxi/sun8i_v3s_ccu.c
/* $NetBSD: sun8i_v3s_ccu.c,v 1.1 2021/05/05 10:24:04 jmcneill Exp $ */

/*-
 * Copyright (c) 2021 Rui-Xiang Guo
 * Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca>
 * 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.
 */

#include <sys/cdefs.h>

__KERNEL_RCSID(1, "$NetBSD: sun8i_v3s_ccu.c,v 1.1 2021/05/05 10:24:04 jmcneill Exp $");

#include <sys/param.h>
#include <sys/bus.h>
#include <sys/device.h>
#include <sys/systm.h>

#include <dev/fdt/fdtvar.h>

#include <arm/sunxi/sunxi_ccu.h>
#include <arm/sunxi/sun8i_v3s_ccu.h>

#define	PLL_CPU_CTRL_REG	0x000
#define	PLL_AUDIO_CTRL_REG	0x008
#define	PLL_VIDEO_CTRL_REG	0x010
#define	PLL_PERIPH0_CTRL_REG	0x028
#define	AHB1_APB1_CFG_REG	0x054
#define	APB2_CFG_REG		0x058
#define	AHB2_CFG_REG		0x05c
#define	 AHB2_CLK_CFG		__BITS(1,0)
#define	 AHB2_CLK_CFG_PLL_PERIPH0_2	1
#define	BUS_CLK_GATING_REG0	0x060
#define	BUS_CLK_GATING_REG1	0x064
#define	BUS_CLK_GATING_REG2	0x068
#define	BUS_CLK_GATING_REG3	0x06c
#define	BUS_CLK_GATING_REG4	0x070
#define	SDMMC0_CLK_REG		0x088
#define	SDMMC1_CLK_REG		0x08c
#define	SDMMC2_CLK_REG		0x090
#define	SPI_CLK_REG		0x0a0
#define	USBPHY_CFG_REG		0x0cc
#define	MBUS_RST_REG		0x0fc
#define	DE_CLK_REG		0x104
#define	TCON_CLK_REG		0x118
#define	AC_DIG_CLK_REG		0x140
#define	BUS_SOFT_RST_REG0	0x2c0
#define	BUS_SOFT_RST_REG1	0x2c4
#define	BUS_SOFT_RST_REG2	0x2c8
#define	BUS_SOFT_RST_REG3	0x2d0
#define	BUS_SOFT_RST_REG4	0x2d8

static int sun8i_v3s_ccu_match(device_t, cfdata_t, void *);
static void sun8i_v3s_ccu_attach(device_t, device_t, void *);

static const struct device_compatible_entry compat_data[] = {
	{ .compat = "allwinner,sun8i-v3s-ccu" },
	DEVICE_COMPAT_EOL
};

CFATTACH_DECL_NEW(sunxi_v3s_ccu, sizeof(struct sunxi_ccu_softc),
	sun8i_v3s_ccu_match, sun8i_v3s_ccu_attach, NULL, NULL);

static struct sunxi_ccu_reset sun8i_v3s_ccu_resets[] = {
	SUNXI_CCU_RESET(V3S_RST_USBPHY, USBPHY_CFG_REG, 0),

	SUNXI_CCU_RESET(V3S_RST_MBUS, MBUS_RST_REG, 31),

	SUNXI_CCU_RESET(V3S_RST_BUS_CE, BUS_SOFT_RST_REG0, 5),
	SUNXI_CCU_RESET(V3S_RST_BUS_DMA, BUS_SOFT_RST_REG0, 6),
	SUNXI_CCU_RESET(V3S_RST_BUS_MMC0, BUS_SOFT_RST_REG0, 8),
	SUNXI_CCU_RESET(V3S_RST_BUS_MMC1, BUS_SOFT_RST_REG0, 9),
	SUNXI_CCU_RESET(V3S_RST_BUS_MMC2, BUS_SOFT_RST_REG0, 10),
	SUNXI_CCU_RESET(V3S_RST_BUS_DRAM, BUS_SOFT_RST_REG0, 14),
	SUNXI_CCU_RESET(V3S_RST_BUS_EMAC, BUS_SOFT_RST_REG0, 17),
	SUNXI_CCU_RESET(V3S_RST_BUS_HSTIMER, BUS_SOFT_RST_REG0, 19),
	SUNXI_CCU_RESET(V3S_RST_BUS_SPI, BUS_SOFT_RST_REG0, 20),
	SUNXI_CCU_RESET(V3S_RST_BUS_OTG, BUS_SOFT_RST_REG0, 24),
	SUNXI_CCU_RESET(V3S_RST_BUS_EHCI, BUS_SOFT_RST_REG0, 26),
	SUNXI_CCU_RESET(V3S_RST_BUS_OHCI, BUS_SOFT_RST_REG0, 29),
        
	SUNXI_CCU_RESET(V3S_RST_BUS_VE, BUS_SOFT_RST_REG1, 0),
	SUNXI_CCU_RESET(V3S_RST_BUS_TCON, BUS_SOFT_RST_REG1, 4),
	SUNXI_CCU_RESET(V3S_RST_BUS_CSI, BUS_SOFT_RST_REG1, 8),
	SUNXI_CCU_RESET(V3S_RST_BUS_DE, BUS_SOFT_RST_REG1, 12),
	SUNXI_CCU_RESET(V3S_RST_BUS_DBG, BUS_SOFT_RST_REG1, 31),

	SUNXI_CCU_RESET(V3S_RST_BUS_EPHY, BUS_SOFT_RST_REG2, 2),

	SUNXI_CCU_RESET(V3S_RST_BUS_CODEC, BUS_SOFT_RST_REG3, 0),

	SUNXI_CCU_RESET(V3S_RST_BUS_I2C0, BUS_SOFT_RST_REG4, 0),
	SUNXI_CCU_RESET(V3S_RST_BUS_I2C1, BUS_SOFT_RST_REG4, 1),
	SUNXI_CCU_RESET(V3S_RST_BUS_UART0, BUS_SOFT_RST_REG4, 16),
	SUNXI_CCU_RESET(V3S_RST_BUS_UART1, BUS_SOFT_RST_REG4, 17),
	SUNXI_CCU_RESET(V3S_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18),
};

static const char *ahb1_parents[] = { "losc", "hosc", "axi", "pll_periph0" };
static const char *ahb2_parents[] = { "ahb1", "pll_periph0" };
static const char *apb1_parents[] = { "ahb1" };
static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
static const char *mod_parents[] = { "hosc", "pll_periph0", "pll_periph1" };
static const char *tcon_parents[] = { "pll_video" };

static const struct sunxi_ccu_nkmp_tbl sun8i_v3s_cpu_table[] = {
	{ 60000000, 9, 0, 0, 2 },
	{ 66000000, 10, 0, 0, 2 },
	{ 72000000, 11, 0, 0, 2 },
	{ 78000000, 12, 0, 0, 2 },
	{ 84000000, 13, 0, 0, 2 },
	{ 90000000, 14, 0, 0, 2 },
	{ 96000000, 15, 0, 0, 2 },
	{ 102000000, 16, 0, 0, 2 },
	{ 108000000, 17, 0, 0, 2 },
	{ 114000000, 18, 0, 0, 2 },
	{ 120000000, 9, 0, 0, 1 },
	{ 132000000, 10, 0, 0, 1 },
	{ 144000000, 11, 0, 0, 1 },
	{ 156000000, 12, 0, 0, 1 },
	{ 168000000, 13, 0, 0, 1 },
	{ 180000000, 14, 0, 0, 1 },
	{ 192000000, 15, 0, 0, 1 },
	{ 204000000, 16, 0, 0, 1 },
	{ 216000000, 17, 0, 0, 1 },
	{ 228000000, 18, 0, 0, 1 },
	{ 240000000, 9, 0, 0, 0 },
	{ 264000000, 10, 0, 0, 0 },
	{ 288000000, 11, 0, 0, 0 },
	{ 312000000, 12, 0, 0, 0 },
	{ 336000000, 13, 0, 0, 0 },
	{ 360000000, 14, 0, 0, 0 },
	{ 384000000, 15, 0, 0, 0 },
	{ 408000000, 16, 0, 0, 0 },
	{ 432000000, 17, 0, 0, 0 },
	{ 456000000, 18, 0, 0, 0 },
	{ 480000000, 19, 0, 0, 0 },
	{ 504000000, 20, 0, 0, 0 },
	{ 528000000, 21, 0, 0, 0 },
	{ 552000000, 22, 0, 0, 0 },
	{ 576000000, 23, 0, 0, 0 },
	{ 600000000, 24, 0, 0, 0 },
	{ 624000000, 25, 0, 0, 0 },
	{ 648000000, 26, 0, 0, 0 },
	{ 672000000, 27, 0, 0, 0 },
	{ 696000000, 28, 0, 0, 0 },
	{ 720000000, 29, 0, 0, 0 },
	{ 768000000, 15, 1, 0, 0 },
	{ 792000000, 10, 2, 0, 0 },
	{ 816000000, 16, 1, 0, 0 },
	{ 864000000, 17, 1, 0, 0 },
	{ 912000000, 18, 1, 0, 0 },
	{ 936000000, 12, 2, 0, 0 },
	{ 960000000, 19, 1, 0, 0 },
	{ 1008000000, 20, 1, 0, 0 },
	{ 1056000000, 21, 1, 0, 0 },
	{ 1080000000, 14, 2, 0, 0 },
	{ 1104000000, 22, 1, 0, 0 },
	{ 1152000000, 23, 1, 0, 0 },
	{ 1200000000, 24, 1, 0, 0 },
	{ 1224000000, 16, 2, 0, 0 },
	{ 1248000000, 25, 1, 0, 0 },
	{ 1296000000, 26, 1, 0, 0 },
	{ 1344000000, 27, 1, 0, 0 },
	{ 1368000000, 18, 2, 0, 0 },
	{ 1392000000, 28, 1, 0, 0 },
	{ 1440000000, 29, 1, 0, 0 },
	{ 1512000000, 20, 2, 0, 0 },
	{ 1536000000, 15, 3, 0, 0 },
	{ 1584000000, 21, 2, 0, 0 },
	{ 1632000000, 16, 3, 0, 0 },
	{ 1656000000, 22, 2, 0, 0 },
	{ 1728000000, 23, 2, 0, 0 },
	{ 1800000000, 24, 2, 0, 0 },
	{ 1824000000, 18, 3, 0, 0 },
	{ 1872000000, 25, 2, 0, 0 },
	{ 0 }
};

static const struct sunxi_ccu_nkmp_tbl sun8i_v3s_ac_dig_table[] = {
	{ 24576000, 13, 0, 0, 13 },
	{ 0 }
};

static struct sunxi_ccu_clk sun8i_v3s_ccu_clks[] = {
	SUNXI_CCU_NKMP_TABLE(V3S_CLK_CPU, "pll_cpu", "hosc",
	    PLL_CPU_CTRL_REG,		/* reg */
	    __BITS(12,8),		/* n */
	    __BITS(5,4),		/* k */
	    __BITS(1,0),		/* m */
	    __BITS(17,16),		/* p */
	    __BIT(31),			/* enable */
	    __BIT(28),			/* lock */
	    sun8i_v3s_cpu_table,	/* table */
	    SUNXI_CCU_NKMP_SCALE_CLOCK | SUNXI_CCU_NKMP_FACTOR_P_POW2),
	
	SUNXI_CCU_NKMP(V3S_CLK_PLL_PERIPH0, "pll_periph0", "hosc",
	    PLL_PERIPH0_CTRL_REG,	/* reg */
	    __BITS(12,8),		/* n */
	    __BITS(5,4), 		/* k */
	    0,				/* m */
	    __BITS(17,16),		/* p */
	    __BIT(31),			/* enable */
	    SUNXI_CCU_NKMP_DIVIDE_BY_TWO),

	SUNXI_CCU_FIXED_FACTOR(V3S_CLK_PLL_PERIPH0_2X, "pll_periph0_2x", "pll_periph0", 1, 2),

	SUNXI_CCU_FRACTIONAL(V3S_CLK_PLL_VIDEO, "pll_video", "hosc",
	    PLL_VIDEO_CTRL_REG,		/* reg */
	    __BITS(14,8),		/* m */
	    16,				/* m_min */
	    50,				/* m_max */
	    __BIT(24),			/* div_en */
	    __BIT(25),			/* frac_sel */
	    270000000, 297000000,	/* frac values */
	    __BITS(3,0),		/* prediv */
	    4,				/* prediv_val */
	    __BIT(31),			/* enable */
	    SUNXI_CCU_FRACTIONAL_PLUSONE | SUNXI_CCU_FRACTIONAL_SET_ENABLE),

	SUNXI_CCU_NKMP_TABLE(V3S_CLK_PLL_AUDIO_BASE, "pll_audio", "hosc",
	    PLL_AUDIO_CTRL_REG,		/* reg */
	    __BITS(14,8),		/* n */
	    0,				/* k */
	    __BITS(4,0),		/* m */
	    __BITS(19,16),		/* p */
	    __BIT(31),			/* enable */
	    __BIT(28),			/* lock */
	    sun8i_v3s_ac_dig_table,	/* table */
	    0),

	SUNXI_CCU_PREDIV(V3S_CLK_AHB1, "ahb1", ahb1_parents,
	    AHB1_APB1_CFG_REG,	/* reg */
	    __BITS(7,6),	/* prediv */
	    __BIT(3),		/* prediv_sel */
	    __BITS(5,4),	/* div */
	    __BITS(13,12),	/* sel */
	    SUNXI_CCU_PREDIV_POWER_OF_TWO),

	SUNXI_CCU_PREDIV(V3S_CLK_AHB2, "ahb2", ahb2_parents,
	    AHB2_CFG_REG,	/* reg */
	    0,			/* prediv */
	    __BIT(1),		/* prediv_sel */
	    0,			/* div */
	    __BITS(1,0),	/* sel */
	    SUNXI_CCU_PREDIV_DIVIDE_BY_TWO),

	SUNXI_CCU_DIV(V3S_CLK_APB1, "apb1", apb1_parents,
	    AHB1_APB1_CFG_REG,	/* reg */
	    __BITS(9,8),	/* div */
	    0,			/* sel */
	    SUNXI_CCU_DIV_POWER_OF_TWO|SUNXI_CCU_DIV_ZERO_IS_ONE),

	SUNXI_CCU_NM(V3S_CLK_APB2, "apb2", apb2_parents,
	    APB2_CFG_REG,	/* reg */
	    __BITS(17,16),	/* n */
	    __BITS(4,0),	/* m */
	    __BITS(25,24),	/* sel */
	    0,			/* enable */
	    SUNXI_CCU_NM_POWER_OF_TWO),

	SUNXI_CCU_NM(V3S_CLK_MMC0, "mmc0", mod_parents,
	    SDMMC0_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
	    SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
	SUNXI_CCU_PHASE(V3S_CLK_MMC0_SAMPLE, "mmc0_sample", "mmc0",
	    SDMMC0_CLK_REG, __BITS(22,20)),
	SUNXI_CCU_PHASE(V3S_CLK_MMC0_OUTPUT, "mmc0_output", "mmc0",
	    SDMMC0_CLK_REG, __BITS(10,8)),
	SUNXI_CCU_NM(V3S_CLK_MMC1, "mmc1", mod_parents,
	    SDMMC1_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
	    SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
	SUNXI_CCU_PHASE(V3S_CLK_MMC1_SAMPLE, "mmc1_sample", "mmc1",
	    SDMMC1_CLK_REG, __BITS(22,20)),
	SUNXI_CCU_PHASE(V3S_CLK_MMC1_OUTPUT, "mmc1_output", "mmc1",
	    SDMMC1_CLK_REG, __BITS(10,8)),
	SUNXI_CCU_NM(V3S_CLK_MMC2, "mmc2", mod_parents,
	    SDMMC2_CLK_REG, __BITS(17, 16), __BITS(3,0), __BITS(25, 24), __BIT(31),
	    SUNXI_CCU_NM_POWER_OF_TWO|SUNXI_CCU_NM_ROUND_DOWN),
	SUNXI_CCU_PHASE(V3S_CLK_MMC2_SAMPLE, "mmc2_sample", "mmc2",
	    SDMMC2_CLK_REG, __BITS(22,20)),
	SUNXI_CCU_PHASE(V3S_CLK_MMC2_OUTPUT, "mmc2_output", "mmc2",
	    SDMMC2_CLK_REG, __BITS(10,8)),

	SUNXI_CCU_NM(V3S_CLK_SPI, "spi", mod_parents,
	    SPI_CLK_REG,	/* reg */
	    __BITS(17,16),	/* n */
	    __BITS(3,0),	/* m */
	    __BITS(25,24),	/* sel */
	    __BIT(31),		/* enable */
	    SUNXI_CCU_NM_ROUND_DOWN),

	SUNXI_CCU_GATE(V3S_CLK_AC_DIG, "ac_dig", "pll_audio",
	    AC_DIG_CLK_REG, 31),

	SUNXI_CCU_DIV_GATE(V3S_CLK_TCON, "tcon", tcon_parents,
	    TCON_CLK_REG,	/* reg */
	    __BITS(3,0),	/* div */
	    __BITS(26,24),	/* sel */
	    __BIT(31),		/* enable */
	    0),

	SUNXI_CCU_GATE(V3S_CLK_BUS_DMA, "bus-dma", "ahb1",
	    BUS_CLK_GATING_REG0, 6),
	SUNXI_CCU_GATE(V3S_CLK_BUS_MMC0, "bus-mmc0", "ahb1",
	    BUS_CLK_GATING_REG0, 8),
	SUNXI_CCU_GATE(V3S_CLK_BUS_MMC1, "bus-mmc1", "ahb1",
	    BUS_CLK_GATING_REG0, 9),
	SUNXI_CCU_GATE(V3S_CLK_BUS_MMC2, "bus-mmc2", "ahb1",
	    BUS_CLK_GATING_REG0, 10),
	SUNXI_CCU_GATE(V3S_CLK_BUS_EMAC, "bus-emac", "ahb2",
	    BUS_CLK_GATING_REG0, 17),
	SUNXI_CCU_GATE(V3S_CLK_BUS_SPI, "bus-spi", "ahb1",
	    BUS_CLK_GATING_REG0, 20),
	SUNXI_CCU_GATE(V3S_CLK_BUS_OTG, "bus-otg", "ahb1",
	    BUS_CLK_GATING_REG0, 24),
	SUNXI_CCU_GATE(V3S_CLK_BUS_EHCI, "bus-ehci", "ahb1",
	    BUS_CLK_GATING_REG0, 26),
	SUNXI_CCU_GATE(V3S_CLK_BUS_OHCI, "bus-ohci", "ahb1",
	    BUS_CLK_GATING_REG0, 29),

	SUNXI_CCU_GATE(V3S_CLK_BUS_TCON, "bus-tcon", "ahb1",
	    BUS_CLK_GATING_REG1, 4),
	SUNXI_CCU_GATE(V3S_CLK_BUS_DE, "bus-de", "ahb1",
	    BUS_CLK_GATING_REG1, 12),

	SUNXI_CCU_GATE(V3S_CLK_BUS_CODEC, "bus-codec", "apb1",
	    BUS_CLK_GATING_REG2, 0),
	SUNXI_CCU_GATE(V3S_CLK_BUS_PIO, "bus-pio", "apb1",
	    BUS_CLK_GATING_REG2, 5),

	SUNXI_CCU_GATE(V3S_CLK_BUS_I2C0, "bus-i2c0", "apb2",
	    BUS_CLK_GATING_REG3, 0),
	SUNXI_CCU_GATE(V3S_CLK_BUS_I2C1, "bus-i2c1", "apb2",
	    BUS_CLK_GATING_REG3, 1),
	SUNXI_CCU_GATE(V3S_CLK_BUS_UART0, "bus-uart0", "apb2",
	    BUS_CLK_GATING_REG3, 16),
	SUNXI_CCU_GATE(V3S_CLK_BUS_UART1, "bus-uart1", "apb2",
	    BUS_CLK_GATING_REG3, 17),
	SUNXI_CCU_GATE(V3S_CLK_BUS_UART2, "bus-uart2", "apb2",
	    BUS_CLK_GATING_REG3, 18),

	SUNXI_CCU_GATE(V3S_CLK_BUS_EPHY, "bus-ephy", "ahb1",
	    BUS_CLK_GATING_REG4, 0),

	SUNXI_CCU_GATE(V3S_CLK_USBPHY, "usb-phy", "hosc",
	    USBPHY_CFG_REG, 8),
	SUNXI_CCU_GATE(V3S_CLK_USBOHCI, "usb-ohci", "hosc",
	    USBPHY_CFG_REG, 16),
};

static void
sun8i_v3s_ccu_init(struct sunxi_ccu_softc *sc)
{
	uint32_t val;

	/* Set AHB2 source to PLL_PERIPH/2 */
	val = CCU_READ(sc, AHB2_CFG_REG);
	val &= ~AHB2_CLK_CFG;
	val |= __SHIFTIN(AHB2_CLK_CFG_PLL_PERIPH0_2, AHB2_CLK_CFG);
	CCU_WRITE(sc, AHB2_CFG_REG, val);
}

static int
sun8i_v3s_ccu_match(device_t parent, cfdata_t cf, void *aux)
{
	struct fdt_attach_args * const faa = aux;

	return of_compatible_match(faa->faa_phandle, compat_data);
}

static void
sun8i_v3s_ccu_attach(device_t parent, device_t self, void *aux)
{
	struct sunxi_ccu_softc * const sc = device_private(self);
	struct fdt_attach_args * const faa = aux;

	sc->sc_dev = self;
	sc->sc_phandle = faa->faa_phandle;
	sc->sc_bst = faa->faa_bst;

	sc->sc_resets = sun8i_v3s_ccu_resets;
	sc->sc_nresets = __arraycount(sun8i_v3s_ccu_resets);

	sc->sc_clks = sun8i_v3s_ccu_clks;
	sc->sc_nclks = __arraycount(sun8i_v3s_ccu_clks);

	if (sunxi_ccu_attach(sc) != 0)
		return;

	aprint_naive("\n");
	aprint_normal(": V3s CCU\n");

	sun8i_v3s_ccu_init(sc);

	sunxi_ccu_print(sc);
}

File Added: src/sys/arch/arm/sunxi/sun8i_v3s_ccu.h
/* $NetBSD: sun8i_v3s_ccu.h,v 1.1 2021/05/05 10:24:04 jmcneill Exp $ */

/*-
 * Copyright (c) 2021 Rui-Xiang Guo
 * 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.
 */

#ifndef __CCU_V3S_H__
#define __CCU_V3S_H__

#define	V3S_CLK_PLL_CPU		0
#define	V3S_CLK_PLL_AUDIO_BASE	1
#define	V3S_CLK_PLL_AUDIO	2
#define	V3S_CLK_PLL_AUDIO_2X	3
#define	V3S_CLK_PLL_AUDIO_4X	4
#define	V3S_CLK_PLL_AUDIO_8X	5
#define	V3S_CLK_PLL_VIDEO	6
#define	V3S_CLK_PLL_VE		7
#define	V3S_CLK_PLL_DDR		8
#define	V3S_CLK_PLL_PERIPH0	9
#define	V3S_CLK_PLL_PERIPH0_2X	10
#define	V3S_CLK_PLL_ISP		11
#define	V3S_CLK_PLL_PERIPH1	12
#define	V3S_CLK_CPU		14
#define	V3S_CLK_AXI		15
#define	V3S_CLK_AHB1		16
#define	V3S_CLK_APB1		17
#define	V3S_CLK_APB2		18
#define	V3S_CLK_AHB2		19
#define	V3S_CLK_BUS_CE		20
#define	V3S_CLK_BUS_DMA		21
#define	V3S_CLK_BUS_MMC0	22
#define	V3S_CLK_BUS_MMC1	23
#define	V3S_CLK_BUS_MMC2	24
#define	V3S_CLK_BUS_DRAM	25
#define	V3S_CLK_BUS_EMAC	26
#define	V3S_CLK_BUS_HSTIMER	27
#define	V3S_CLK_BUS_SPI		28
#define	V3S_CLK_BUS_OTG		29
#define	V3S_CLK_BUS_EHCI	30
#define	V3S_CLK_BUS_OHCI	31
#define	V3S_CLK_BUS_VE		32
#define	V3S_CLK_BUS_TCON	33
#define	V3S_CLK_BUS_CSI		34
#define	V3S_CLK_BUS_DE		35
#define	V3S_CLK_BUS_CODEC	36
#define	V3S_CLK_BUS_PIO		37
#define	V3S_CLK_BUS_I2C0	38
#define	V3S_CLK_BUS_I2C1	39
#define	V3S_CLK_BUS_UART0	40
#define	V3S_CLK_BUS_UART1	41
#define	V3S_CLK_BUS_UART2	42
#define	V3S_CLK_BUS_EPHY	43
#define	V3S_CLK_BUS_DBG		44
#define	V3S_CLK_MMC0		45
#define	V3S_CLK_MMC0_SAMPLE	46
#define	V3S_CLK_MMC0_OUTPUT	47
#define	V3S_CLK_MMC1		48
#define	V3S_CLK_MMC1_SAMPLE	49
#define	V3S_CLK_MMC1_OUTPUT	50
#define	V3S_CLK_MMC2		51
#define	V3S_CLK_MMC2_SAMPLE	52
#define	V3S_CLK_MMC2_OUTPUT	53
#define	V3S_CLK_CE		54
#define	V3S_CLK_SPI		55
#define	V3S_CLK_USBPHY		56
#define	V3S_CLK_USBOHCI		57
#define	V3S_CLK_DRAM		58
#define	V3S_CLK_DRAM_VE		59
#define	V3S_CLK_DRAM_CSI	60
#define	V3S_CLK_DRAM_EHCI	61
#define	V3S_CLK_DRAM_OHCI	62
#define	V3S_CLK_DE		63
#define	V3S_CLK_TCON		64
#define	V3S_CLK_CSI_MISC	65
#define	V3S_CLK_CSI0_MCLK	66
#define	V3S_CLK_CSI1_SCLK	67
#define	V3S_CLK_CSI1_MCLK	68
#define	V3S_CLK_VE		69
#define	V3S_CLK_AC_DIG		70
#define	V3S_CLK_AVS		71
#define	V3S_CLK_MBUS		72
#define	V3S_CLK_MIPI_CSI	73

#define	V3S_RST_USBPHY		0
#define	V3S_RST_MBUS		1
#define	V3S_RST_BUS_CE		5
#define	V3S_RST_BUS_DMA		6
#define	V3S_RST_BUS_MMC0	7
#define	V3S_RST_BUS_MMC1	8
#define	V3S_RST_BUS_MMC2	9
#define	V3S_RST_BUS_DRAM	11
#define	V3S_RST_BUS_EMAC	12
#define	V3S_RST_BUS_HSTIMER	14
#define	V3S_RST_BUS_SPI		15
#define	V3S_RST_BUS_OTG		17
#define	V3S_RST_BUS_EHCI	18
#define	V3S_RST_BUS_OHCI	22
#define	V3S_RST_BUS_VE		26
#define	V3S_RST_BUS_TCON	27
#define	V3S_RST_BUS_CSI		30
#define	V3S_RST_BUS_DE		34
#define	V3S_RST_BUS_DBG		38
#define	V3S_RST_BUS_EPHY	39
#define	V3S_RST_BUS_CODEC	40
#define	V3S_RST_BUS_I2C0	46
#define	V3S_RST_BUS_I2C1	47
#define	V3S_RST_BUS_UART0	49
#define	V3S_RST_BUS_UART1	50
#define	V3S_RST_BUS_UART2	51

#endif /* __CCU_V3S_H__ */

File Added: src/sys/arch/arm/sunxi/sun8i_v3s_codec.c
/* $NetBSD: sun8i_v3s_codec.c,v 1.1 2021/05/05 10:24:04 jmcneill Exp $ */

/*-
 * Copyright (c) 2021 Rui-Xiang Guo
 * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca>
 * 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.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sun8i_v3s_codec.c,v 1.1 2021/05/05 10:24:04 jmcneill Exp $");

#include <sys/param.h>
#include <sys/bus.h>
#include <sys/cpu.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <sys/bitops.h>

#include <sys/audioio.h>
#include <dev/audio/audio_if.h>

#include <arm/sunxi/sunxi_codec.h>

#define	V3S_PR_CFG		0x00
#define	 V3S_PR_RST		__BIT(28)
#define	 V3S_PR_RW		__BIT(24)
#define	 V3S_PR_ADDR		__BITS(20,16)
#define	 V3S_ADDA_PR_WDAT	__BITS(15,8)
#define	 V3S_ADDA_PR_RDAT	__BITS(7,0)

#define	V3S_PAG_HPV		0x00
#define	 V3S_HPVOL		__BITS(5,0)

#define	V3S_LMIXMUTE		0x01
#define	 V3S_LMIXMUTE_LDAC	__BIT(1)
#define	V3S_RMIXMUTE		0x02
#define	 V3S_RMIXMUTE_RDAC	__BIT(1)
#define	V3S_DAC_PA_SRC		0x03
#define	 V3S_DACAREN		__BIT(7)
#define	 V3S_DACALEN		__BIT(6)
#define	 V3S_RMIXEN		__BIT(5)
#define	 V3S_LMIXEN		__BIT(4)
#define	 V3S_RHPPAMUTE		__BIT(3)
#define	 V3S_LHPPAMUTE		__BIT(2)
#define	V3S_MIC_GCTR		0x06
#define	 V3S_MIC_GAIN		__BITS(6,4)
#define	V3S_HP_CTRL		0x07
#define	 V3S_HPPAEN		__BIT(7)
#define	V3S_LADCMIXMUTE		0x0c
#define	V3S_RADCMIXMUTE		0x0d
#define	 V3S_ADCMIXMUTE_MIC	__BIT(6)
#define	 V3S_ADCMIXMUTE_MIXER	__BITS(1,0)
#define	V3S_ADC_CTRL		0x0f
#define	 V3S_ADCREN		__BIT(7)
#define	 V3S_ADCLEN		__BIT(6)
#define	 V3S_ADCG		__BITS(2,0)

struct v3s_codec_softc {
	device_t		sc_dev;
	bus_space_tag_t		sc_bst;
	bus_space_handle_t	sc_bsh;
	int			sc_phandle;
};

enum v3s_codec_mixer_ctrl {
	V3S_CODEC_OUTPUT_CLASS,
	V3S_CODEC_INPUT_CLASS,
	V3S_CODEC_RECORD_CLASS,

	V3S_CODEC_OUTPUT_MASTER_VOLUME,
	V3S_CODEC_INPUT_MIC_VOLUME,
	V3S_CODEC_RECORD_AGC_VOLUME,
	V3S_CODEC_RECORD_SOURCE,

	V3S_CODEC_MIXER_CTRL_LAST
};

static const struct v3s_codec_mixer {
	const char *			name;
	enum v3s_codec_mixer_ctrl	mixer_class;
	u_int				reg;
	u_int				mask;
} v3s_codec_mixers[V3S_CODEC_MIXER_CTRL_LAST] = {
	[V3S_CODEC_OUTPUT_MASTER_VOLUME]	= { AudioNmaster,
	    V3S_CODEC_OUTPUT_CLASS, V3S_PAG_HPV, V3S_HPVOL },
	[V3S_CODEC_INPUT_MIC_VOLUME]	= { "mic",
	    V3S_CODEC_INPUT_CLASS, V3S_MIC_GCTR, V3S_MIC_GAIN },
	[V3S_CODEC_RECORD_AGC_VOLUME]	= { AudioNagc,
	    V3S_CODEC_RECORD_CLASS, V3S_ADC_CTRL, V3S_ADCG },
};

#define	RD4(sc, reg)			\
	bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
#define	WR4(sc, reg, val)		\
	bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))

static struct v3s_codec_softc *
v3s_codec_find(int phandle)
{
	struct v3s_codec_softc *csc;
	device_t dev;

	dev = device_find_by_driver_unit("v3scodec", 0);
	if (dev == NULL)
		return NULL;
	csc = device_private(dev);
	if (csc->sc_phandle != phandle)
		return NULL;

	return csc;
}

static u_int
v3s_codec_pr_read(struct v3s_codec_softc *csc, u_int addr)
{
	uint32_t val;

	/* Read current value */
	val = RD4(csc, V3S_PR_CFG);

	/* De-assert reset */
	val |= V3S_PR_RST;
	WR4(csc, V3S_PR_CFG, val);

	/* Read mode */
	val &= ~V3S_PR_RW;
	WR4(csc, V3S_PR_CFG, val);

	/* Set address */
	val &= ~V3S_PR_ADDR;
	val |= __SHIFTIN(addr, V3S_PR_ADDR);
	WR4(csc, V3S_PR_CFG, val);

	/* Read data */
	return __SHIFTOUT(RD4(csc, V3S_PR_CFG), V3S_ADDA_PR_RDAT);
}

static void
v3s_codec_pr_write(struct v3s_codec_softc *csc, u_int addr, u_int data)
{
	uint32_t val;

	/* Read current value */
	val = RD4(csc, V3S_PR_CFG);

	/* De-assert reset */
	val |= V3S_PR_RST;
	WR4(csc, V3S_PR_CFG, val);

	/* Set address */
	val &= ~V3S_PR_ADDR;
	val |= __SHIFTIN(addr, V3S_PR_ADDR);
	WR4(csc, V3S_PR_CFG, val);

	/* Write data */
	val &= ~V3S_ADDA_PR_WDAT;
	val |= __SHIFTIN(data, V3S_ADDA_PR_WDAT);
	WR4(csc, V3S_PR_CFG, val);

	/* Write mode */
	val |= V3S_PR_RW;
	WR4(csc, V3S_PR_CFG, val);

	/* Clear write mode */
	val &= ~V3S_PR_RW;
	WR4(csc, V3S_PR_CFG, val);
}

static void
v3s_codec_pr_set_clear(struct v3s_codec_softc *csc, u_int addr, u_int set, u_int clr)
{
	u_int old, new;

	old = v3s_codec_pr_read(csc, addr);
	new = set | (old & ~clr);
	v3s_codec_pr_write(csc, addr, new);
}

static int
v3s_codec_init(struct sunxi_codec_softc *sc)
{
	struct v3s_codec_softc *csc;
	int phandle;

	/* Lookup the codec analog controls phandle */
	phandle = fdtbus_get_phandle(sc->sc_phandle,
	    "allwinner,codec-analog-controls");
	if (phandle < 0) {
		aprint_error_dev(sc->sc_dev,
		    "missing allwinner,codec-analog-controls property\n");
		return ENXIO;
	}

	/* Find a matching v3scodec instance */
	sc->sc_codec_priv = v3s_codec_find(phandle);
	if (sc->sc_codec_priv == NULL) {
		aprint_error_dev(sc->sc_dev, "couldn't find codec analog controls\n");
		return ENOENT;
	}
	csc = sc->sc_codec_priv;

	/* Right & Left Headphone enable */
	v3s_codec_pr_set_clear(csc, V3S_HP_CTRL, V3S_HPPAEN, 0);

	return 0;
}

static void
v3s_codec_mute(struct sunxi_codec_softc *sc, int mute, u_int mode)
{
	struct v3s_codec_softc * const csc = sc->sc_codec_priv;

	if (mode == AUMODE_PLAY) {
		if (mute) {
			/* Mute DAC l/r channels to output mixer */
			v3s_codec_pr_set_clear(csc, V3S_LMIXMUTE,
			    0, V3S_LMIXMUTE_LDAC);
			v3s_codec_pr_set_clear(csc, V3S_RMIXMUTE,
			    0, V3S_RMIXMUTE_RDAC);
			/* Disable DAC analog l/r channels and output mixer */
			v3s_codec_pr_set_clear(csc, V3S_DAC_PA_SRC,
			    0, V3S_DACAREN | V3S_DACALEN | V3S_RMIXEN | V3S_LMIXEN | V3S_RHPPAMUTE | V3S_LHPPAMUTE);
		} else {
			/* Enable DAC analog l/r channels and output mixer */
			v3s_codec_pr_set_clear(csc, V3S_DAC_PA_SRC,
			    V3S_DACAREN | V3S_DACALEN | V3S_RMIXEN | V3S_LMIXEN | V3S_RHPPAMUTE | V3S_LHPPAMUTE, 0);
			/* Unmute DAC l/r channels to output mixer */
			v3s_codec_pr_set_clear(csc, V3S_LMIXMUTE, V3S_LMIXMUTE_LDAC, 0);
			v3s_codec_pr_set_clear(csc, V3S_RMIXMUTE, V3S_RMIXMUTE_RDAC, 0);
		}
	} else {
		if (mute) {
			/* Disable ADC analog l/r channels */
			v3s_codec_pr_set_clear(csc, V3S_ADC_CTRL,
			    0, V3S_ADCREN | V3S_ADCLEN);
		} else {
			/* Enable ADC analog l/r channels */
			v3s_codec_pr_set_clear(csc, V3S_ADC_CTRL,
			    V3S_ADCREN | V3S_ADCLEN, 0);
		}
	}
}

static int
v3s_codec_set_port(struct sunxi_codec_softc *sc, mixer_ctrl_t *mc)
{
	struct v3s_codec_softc * const csc = sc->sc_codec_priv;
	const struct v3s_codec_mixer *mix;
	u_int val, shift;
	int nvol;

	switch (mc->dev) {
	case V3S_CODEC_OUTPUT_MASTER_VOLUME:
	case V3S_CODEC_INPUT_MIC_VOLUME:
	case V3S_CODEC_RECORD_AGC_VOLUME:
		mix = &v3s_codec_mixers[mc->dev];
		val = v3s_codec_pr_read(csc, mix->reg);
		shift = 8 - fls32(__SHIFTOUT_MASK(mix->mask));
		nvol = mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] >> shift;
		val &= ~mix->mask;
		val |= __SHIFTIN(nvol, mix->mask);
		v3s_codec_pr_write(csc, mix->reg, val);
		return 0;

	case V3S_CODEC_RECORD_SOURCE:
		v3s_codec_pr_write(csc, V3S_LADCMIXMUTE, mc->un.mask);
		v3s_codec_pr_write(csc, V3S_RADCMIXMUTE, mc->un.mask);
		return 0;
	}

	return ENXIO;
}

static int
v3s_codec_get_port(struct sunxi_codec_softc *sc, mixer_ctrl_t *mc)
{
	struct v3s_codec_softc * const csc = sc->sc_codec_priv;
	const struct v3s_codec_mixer *mix;
	u_int val, shift;
	int nvol;

	switch (mc->dev) {
	case V3S_CODEC_OUTPUT_MASTER_VOLUME:
	case V3S_CODEC_INPUT_MIC_VOLUME:
	case V3S_CODEC_RECORD_AGC_VOLUME:
		mix = &v3s_codec_mixers[mc->dev];
		val = v3s_codec_pr_read(csc, mix->reg);
		shift = 8 - fls32(__SHIFTOUT_MASK(mix->mask));
		nvol = __SHIFTOUT(val, mix->mask) << shift;
		mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = nvol;
		mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = nvol;
		return 0;

	case V3S_CODEC_RECORD_SOURCE:
		mc->un.mask =
		    v3s_codec_pr_read(csc, V3S_LADCMIXMUTE) |
		    v3s_codec_pr_read(csc, V3S_RADCMIXMUTE);
		return 0;
	}

	return ENXIO;
}

static int
v3s_codec_query_devinfo(struct sunxi_codec_softc *sc, mixer_devinfo_t *di)
{
	const struct v3s_codec_mixer *mix;

	switch (di->index) {
	case V3S_CODEC_OUTPUT_CLASS:
		di->mixer_class = di->index;
		strcpy(di->label.name, AudioCoutputs);
		di->type = AUDIO_MIXER_CLASS;
		di->next = di->prev = AUDIO_MIXER_LAST;
		return 0;

	case V3S_CODEC_INPUT_CLASS:
		di->mixer_class = di->index;
		strcpy(di->label.name, AudioCinputs);
		di->type = AUDIO_MIXER_CLASS;
		di->next = di->prev = AUDIO_MIXER_LAST;
		return 0;

	case V3S_CODEC_RECORD_CLASS:
		di->mixer_class = di->index;
		strcpy(di->label.name, AudioCrecord);
		di->type = AUDIO_MIXER_CLASS;
		di->next = di->prev = AUDIO_MIXER_LAST;
		return 0;

	case V3S_CODEC_OUTPUT_MASTER_VOLUME:
	case V3S_CODEC_INPUT_MIC_VOLUME:
	case V3S_CODEC_RECORD_AGC_VOLUME:
		mix = &v3s_codec_mixers[di->index];
		di->mixer_class = mix->mixer_class;
		strcpy(di->label.name, mix->name);
		di->un.v.delta =
		    256 / (__SHIFTOUT_MASK(mix->mask) + 1);
		di->type = AUDIO_MIXER_VALUE;
		di->next = di->prev = AUDIO_MIXER_LAST;
		di->un.v.num_channels = 2;
		strcpy(di->un.v.units.name, AudioNvolume);
		return 0;

	case V3S_CODEC_RECORD_SOURCE:
		di->mixer_class = V3S_CODEC_RECORD_CLASS;
		strcpy(di->label.name, AudioNsource);
		di->type = AUDIO_MIXER_SET;
		di->next = di->prev = AUDIO_MIXER_LAST;
		di->un.s.num_mem = 2;
		strcpy(di->un.s.member[0].label.name, "mic");
		di->un.s.member[1].mask = V3S_ADCMIXMUTE_MIC;
		strcpy(di->un.s.member[1].label.name, AudioNdac);
		di->un.s.member[3].mask = V3S_ADCMIXMUTE_MIXER;
		return 0;

	}

	return ENXIO;
}

const struct sunxi_codec_conf sun8i_v3s_codecconf = {
	.name = "V3s Audio Codec",

	.init = v3s_codec_init,
	.mute = v3s_codec_mute,
	.set_port = v3s_codec_set_port,
	.get_port = v3s_codec_get_port,
	.query_devinfo = v3s_codec_query_devinfo,

	.DPC		= 0x00,
	.DAC_FIFOC	= 0x04,
	.DAC_FIFOS	= 0x08,
	.DAC_TXDATA	= 0x20,
	.ADC_FIFOC	= 0x10,
	.ADC_FIFOS	= 0x14,
	.ADC_RXDATA	= 0x18,
	.DAC_CNT	= 0x40,
	.ADC_CNT	= 0x44,
};

/*
 * Device glue, only here to claim resources on behalf of the sunxi_codec driver.
 */

static const struct device_compatible_entry compat_data[] = {
	{ .compat = "allwinner,sun8i-v3s-codec-analog" },
	DEVICE_COMPAT_EOL
};

static int
v3s_codec_match(device_t parent, cfdata_t cf, void *aux)
{
	struct fdt_attach_args * const faa = aux;

	return of_compatible_match(faa->faa_phandle, compat_data);
}

static void
v3s_codec_attach(device_t parent, device_t self, void *aux)
{
	struct v3s_codec_softc * const sc = device_private(self);
	struct fdt_attach_args * const faa = aux;
	const int phandle = faa->faa_phandle;
	bus_addr_t addr;
	bus_size_t size;

	sc->sc_dev = self;
	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
		aprint_error(": couldn't get registers\n");
		return;
	}
	sc->sc_bst = faa->faa_bst;
	if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
		aprint_error(": couldn't map registers\n");
		return;
	}

	sc->sc_phandle = phandle;

	aprint_naive("\n");
	aprint_normal(": V3s Audio Codec (analog part)\n");
}

CFATTACH_DECL_NEW(v3s_codec, sizeof(struct v3s_codec_softc),
    v3s_codec_match, v3s_codec_attach, NULL, NULL);

cvs diff -r1.12 -r1.13 src/sys/arch/arm/sunxi/sunxi_codec.c (expand / switch to unified diff)

--- src/sys/arch/arm/sunxi/sunxi_codec.c 2021/01/27 03:10:20 1.12
+++ src/sys/arch/arm/sunxi/sunxi_codec.c 2021/05/05 10:24:04 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sunxi_codec.c,v 1.12 2021/01/27 03:10:20 thorpej Exp $ */ 1/* $NetBSD: sunxi_codec.c,v 1.13 2021/05/05 10:24:04 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include "opt_ddb.h" 29#include "opt_ddb.h"
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.12 2021/01/27 03:10:20 thorpej Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: sunxi_codec.c,v 1.13 2021/05/05 10:24:04 jmcneill Exp $");
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/bus.h> 35#include <sys/bus.h>
36#include <sys/cpu.h> 36#include <sys/cpu.h>
37#include <sys/device.h> 37#include <sys/device.h>
38#include <sys/kmem.h> 38#include <sys/kmem.h>
39#include <sys/gpio.h> 39#include <sys/gpio.h>
40 40
41#include <sys/audioio.h> 41#include <sys/audioio.h>
42#include <dev/audio/audio_if.h> 42#include <dev/audio/audio_if.h>
43 43
44#include <dev/fdt/fdtvar.h> 44#include <dev/fdt/fdtvar.h>
45 45
@@ -82,26 +82,27 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_codec. @@ -82,26 +82,27 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_codec.
82#define ADC_FIFOC_MONO_EN __BIT(7) 82#define ADC_FIFOC_MONO_EN __BIT(7)
83#define ADC_FIFOC_RX_BITS __BIT(6) 83#define ADC_FIFOC_RX_BITS __BIT(6)
84#define ADC_FIFOC_DRQ_EN __BIT(4) 84#define ADC_FIFOC_DRQ_EN __BIT(4)
85#define ADC_FIFOC_FIFO_FLUSH __BIT(0) 85#define ADC_FIFOC_FIFO_FLUSH __BIT(0)
86#define AC_ADC_FIFOS(_sc) ((_sc)->sc_cfg->ADC_FIFOS) 86#define AC_ADC_FIFOS(_sc) ((_sc)->sc_cfg->ADC_FIFOS)
87#define AC_ADC_RXDATA(_sc) ((_sc)->sc_cfg->ADC_RXDATA) 87#define AC_ADC_RXDATA(_sc) ((_sc)->sc_cfg->ADC_RXDATA)
88#define AC_DAC_CNT(_sc) ((_sc)->sc_cfg->DAC_CNT) 88#define AC_DAC_CNT(_sc) ((_sc)->sc_cfg->DAC_CNT)
89#define AC_ADC_CNT(_sc) ((_sc)->sc_cfg->ADC_CNT) 89#define AC_ADC_CNT(_sc) ((_sc)->sc_cfg->ADC_CNT)
90 90
91static const struct device_compatible_entry compat_data[] = { 91static const struct device_compatible_entry compat_data[] = {
92 A10_CODEC_COMPATDATA, 92 A10_CODEC_COMPATDATA,
93 A31_CODEC_COMPATDATA, 93 A31_CODEC_COMPATDATA,
94 H3_CODEC_COMPATDATA, 94 H3_CODEC_COMPATDATA,
 95 V3S_CODEC_COMPATDATA,
95 96
96 DEVICE_COMPAT_EOL 97 DEVICE_COMPAT_EOL
97}; 98};
98 99
99#define CODEC_READ(sc, reg) \ 100#define CODEC_READ(sc, reg) \
100 bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg)) 101 bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
101#define CODEC_WRITE(sc, reg, val) \ 102#define CODEC_WRITE(sc, reg, val) \
102 bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val)) 103 bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
103 104
104static int 105static int
105sunxi_codec_allocdma(struct sunxi_codec_softc *sc, size_t size, 106sunxi_codec_allocdma(struct sunxi_codec_softc *sc, size_t size,
106 size_t align, struct sunxi_codec_dma *dma) 107 size_t align, struct sunxi_codec_dma *dma)
107{ 108{

cvs diff -r1.6 -r1.7 src/sys/arch/arm/sunxi/sunxi_codec.h (expand / switch to unified diff)

--- src/sys/arch/arm/sunxi/sunxi_codec.h 2021/01/18 02:35:49 1.6
+++ src/sys/arch/arm/sunxi/sunxi_codec.h 2021/05/05 10:24:04 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sunxi_codec.h,v 1.6 2021/01/18 02:35:49 thorpej Exp $ */ 1/* $NetBSD: sunxi_codec.h,v 1.7 2021/05/05 10:24:04 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2014-2017 Jared McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -25,26 +25,27 @@ @@ -25,26 +25,27 @@
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#ifndef _ARM_SUNXI_CODEC_H 29#ifndef _ARM_SUNXI_CODEC_H
30#define _ARM_SUNXI_CODEC_H 30#define _ARM_SUNXI_CODEC_H
31 31
32#include <sys/audioio.h> 32#include <sys/audioio.h>
33#include <dev/audio/audio_if.h> 33#include <dev/audio/audio_if.h>
34 34
35#include <dev/fdt/fdtvar.h> 35#include <dev/fdt/fdtvar.h>
36 36
37#include "h3_codec.h" 37#include "h3_codec.h"
 38#include "v3s_codec.h"
38 39
39struct sunxi_codec_softc; 40struct sunxi_codec_softc;
40 41
41struct sunxi_codec_conf { 42struct sunxi_codec_conf {
42 const char *name; 43 const char *name;
43 44
44 /* initialize codec */ 45 /* initialize codec */
45 int (*init)(struct sunxi_codec_softc *); 46 int (*init)(struct sunxi_codec_softc *);
46 /* toggle DAC/ADC mute */ 47 /* toggle DAC/ADC mute */
47 void (*mute)(struct sunxi_codec_softc *, int, u_int); 48 void (*mute)(struct sunxi_codec_softc *, int, u_int);
48 /* mixer controls */ 49 /* mixer controls */
49 int (*set_port)(struct sunxi_codec_softc *, 50 int (*set_port)(struct sunxi_codec_softc *,
50 mixer_ctrl_t *); 51 mixer_ctrl_t *);
@@ -115,26 +116,35 @@ struct sunxi_codec_softc { @@ -115,26 +116,35 @@ struct sunxi_codec_softc {
115 struct sunxi_codec_chan sc_pchan; 116 struct sunxi_codec_chan sc_pchan;
116 struct sunxi_codec_chan sc_rchan; 117 struct sunxi_codec_chan sc_rchan;
117}; 118};
118 119
119#if NH3_CODEC > 0 120#if NH3_CODEC > 0
120extern const struct sunxi_codec_conf sun8i_h3_codecconf; 121extern const struct sunxi_codec_conf sun8i_h3_codecconf;
121#define H3_CODEC_COMPATDATA \ 122#define H3_CODEC_COMPATDATA \
122 { .compat = "allwinner,sun8i-h3-codec", \ 123 { .compat = "allwinner,sun8i-h3-codec", \
123 .data = &sun8i_h3_codecconf } 124 .data = &sun8i_h3_codecconf }
124#else 125#else
125#define H3_CODEC_COMPATDATA 126#define H3_CODEC_COMPATDATA
126#endif 127#endif
127 128
 129#if NV3S_CODEC > 0
 130extern const struct sunxi_codec_conf sun8i_v3s_codecconf;
 131#define V3S_CODEC_COMPATDATA \
 132 { .compat = "allwinner,sun8i-v3s-codec", \
 133 .data = &sun8i_v3s_codecconf }
 134#else
 135#define V3S_CODEC_COMPATDATA
 136#endif
 137
128extern const struct sunxi_codec_conf sun4i_a10_codecconf; 138extern const struct sunxi_codec_conf sun4i_a10_codecconf;
129#define A10_CODEC_COMPATDATA \ 139#define A10_CODEC_COMPATDATA \
130 { .compat = "allwinner,sun4i-a10-codec", \ 140 { .compat = "allwinner,sun4i-a10-codec", \
131 .data = &sun4i_a10_codecconf }, \ 141 .data = &sun4i_a10_codecconf }, \
132 { .compat = "allwinner,sun7i-a20-codec", \ 142 { .compat = "allwinner,sun7i-a20-codec", \
133 .data = &sun4i_a10_codecconf } 143 .data = &sun4i_a10_codecconf }
134 144
135extern const struct sunxi_codec_conf sun6i_a31_codecconf; 145extern const struct sunxi_codec_conf sun6i_a31_codecconf;
136#define A31_CODEC_COMPATDATA \ 146#define A31_CODEC_COMPATDATA \
137 { .compat = "allwinner,sun6i-a31-codec", \ 147 { .compat = "allwinner,sun6i-a31-codec", \
138 .data = &sun6i_a31_codecconf } 148 .data = &sun6i_a31_codecconf }
139 149
140#endif /* !_ARM_SUNXI_CODEC_H */ 150#endif /* !_ARM_SUNXI_CODEC_H */

cvs diff -r1.96 -r1.97 src/sys/arch/evbarm/conf/GENERIC (expand / switch to unified diff)

--- src/sys/arch/evbarm/conf/GENERIC 2021/04/28 16:57:05 1.96
+++ src/sys/arch/evbarm/conf/GENERIC 2021/05/05 10:24:04 1.97
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1# 1#
2# $NetBSD: GENERIC,v 1.96 2021/04/28 16:57:05 bad Exp $ 2# $NetBSD: GENERIC,v 1.97 2021/05/05 10:24:04 jmcneill Exp $
3# 3#
4# GENERIC ARM (aarch32) kernel 4# GENERIC ARM (aarch32) kernel
5# 5#
6 6
7include "arch/evbarm/conf/std.generic" 7include "arch/evbarm/conf/std.generic"
8include "arch/evbarm/conf/files.generic" 8include "arch/evbarm/conf/files.generic"
9include "arch/evbarm/conf/GENERIC.common" 9include "arch/evbarm/conf/GENERIC.common"
10 10
11options CPU_CORTEX 11options CPU_CORTEX
12 12
13options SOC_AM33XX 13options SOC_AM33XX
14options SOC_BCM2836 14options SOC_BCM2836
15options SOC_EXYNOS5422 15options SOC_EXYNOS5422
@@ -130,26 +130,27 @@ exy5410clk* at fdt? pass 3 # Exynos541 @@ -130,26 +130,27 @@ exy5410clk* at fdt? pass 3 # Exynos541
130exy5422clk* at fdt? pass 3 # Exynos5422 clock controller 130exy5422clk* at fdt? pass 3 # Exynos5422 clock controller
131imx6ccm* at fdt? pass 1 # i.MX6 CCM 131imx6ccm* at fdt? pass 1 # i.MX6 CCM
132imx7dccm* at fdt? pass 2 # i.MX7D CCM 132imx7dccm* at fdt? pass 2 # i.MX7D CCM
133meson8bclkc* at fdt? pass 2 # Amlogic Meson8b clock controller 133meson8bclkc* at fdt? pass 2 # Amlogic Meson8b clock controller
134mesonresets* at fdt? pass 2 # Amlogic Meson misc. clock resets 134mesonresets* at fdt? pass 2 # Amlogic Meson misc. clock resets
135omap3cm* at fdt? pass 1 # TI OMAP3 CM 135omap3cm* at fdt? pass 1 # TI OMAP3 CM
136omap3prm* at fdt? pass 1 # TI OMAP3 PRM 136omap3prm* at fdt? pass 1 # TI OMAP3 PRM
137sun4ia10ccu* at fdt? pass 2 # Allwinner A10/A20 CCU 137sun4ia10ccu* at fdt? pass 2 # Allwinner A10/A20 CCU
138sun5ia13ccu* at fdt? pass 2 # Allwinner A13 CCU 138sun5ia13ccu* at fdt? pass 2 # Allwinner A13 CCU
139sun6ia31ccu* at fdt? pass 2 # Allwinner A31 CCU 139sun6ia31ccu* at fdt? pass 2 # Allwinner A31 CCU
140sun8ia83tccu* at fdt? pass 2 # Allwinner A83T CCU 140sun8ia83tccu* at fdt? pass 2 # Allwinner A83T CCU
141sun8ih3ccu* at fdt? pass 2 # Allwinner H3 CCU 141sun8ih3ccu* at fdt? pass 2 # Allwinner H3 CCU
142sun8ih3rccu* at fdt? pass 2 # Allwinner H3 CCU (PRCM) 142sun8ih3rccu* at fdt? pass 2 # Allwinner H3 CCU (PRCM)
 143sun8iv3sccu* at fdt? pass 2 # Allwinner V3s CCU
143sun9ia80ccu* at fdt? pass 2 # Allwinner A80 CCU 144sun9ia80ccu* at fdt? pass 2 # Allwinner A80 CCU
144sunxiresets* at fdt? pass 1 # Allwinner Misc. clock resets 145sunxiresets* at fdt? pass 1 # Allwinner Misc. clock resets
145sunxigates* at fdt? pass 1 # Allwinner Misc. clock gates 146sunxigates* at fdt? pass 1 # Allwinner Misc. clock gates
146sunxigmacclk* at fdt? pass 2 # Allwinner GMAC MII/RGMII clock mux 147sunxigmacclk* at fdt? pass 2 # Allwinner GMAC MII/RGMII clock mux
147sun8iapbclk* at fdt? pass 2 # Allwinner A23 APB0 148sun8iapbclk* at fdt? pass 2 # Allwinner A23 APB0
148sun9icpusclk* at fdt? pass 2 # Allwinner A80 CPUS 149sun9icpusclk* at fdt? pass 2 # Allwinner A80 CPUS
149sun9immcclk* at fdt? pass 2 # Allwinner A80 SD/MMC-COMM 150sun9immcclk* at fdt? pass 2 # Allwinner A80 SD/MMC-COMM
150sun9iusbclk* at fdt? pass 2 # Allwinner A80 USB HCI 151sun9iusbclk* at fdt? pass 2 # Allwinner A80 USB HCI
151tegra124car* at fdt? pass 3 # NVIDIA Tegra CAR (T124) 152tegra124car* at fdt? pass 3 # NVIDIA Tegra CAR (T124)
152tegra210car* at fdt? pass 3 # NVIDIA Tegra CAR (T210) 153tegra210car* at fdt? pass 3 # NVIDIA Tegra CAR (T210)
153tidivclk* at fdt? pass 1 # TI divider clock 154tidivclk* at fdt? pass 1 # TI divider clock
154tidpllclk* at fdt? pass 2 # TI DPLL clock 155tidpllclk* at fdt? pass 2 # TI DPLL clock
155timuxclk* at fdt? pass 1 # TI mux clock 156timuxclk* at fdt? pass 1 # TI mux clock
@@ -416,26 +417,27 @@ tegrartc* at fdt? # NVIDIA Tegra RTC @@ -416,26 +417,27 @@ tegrartc* at fdt? # NVIDIA Tegra RTC
416 417
417# Thermal sensor 418# Thermal sensor
418sunxithermal* at fdt? # Thermal sensor controller 419sunxithermal* at fdt? # Thermal sensor controller
419 420
420# BCM2835 VCHIQ, etc 421# BCM2835 VCHIQ, etc
421vchiq0 at fdt? 422vchiq0 at fdt?
422vcaudio0 at vchiq0 423vcaudio0 at vchiq0
423 424
424# Audio 425# Audio
425a64acodec* at fdt? # Allwinner A64 audio codec (analog part) 426a64acodec* at fdt? # Allwinner A64 audio codec (analog part)
426aaci* at fdt? # ARM PrimeCell AACI 427aaci* at fdt? # ARM PrimeCell AACI
427ausoc* at fdt? # Simple SoC audio card 428ausoc* at fdt? # Simple SoC audio card
428h3codec* at fdt? # Allwinner H3 audio codec (analog part) 429h3codec* at fdt? # Allwinner H3 audio codec (analog part)
 430v3scodec* at fdt? # Allwinner V3s audio codec (analog part)
429hdaudio* at fdt? # Intel HDA 431hdaudio* at fdt? # Intel HDA
430hdafg* at hdaudiobus? 432hdafg* at hdaudiobus?
431options HDAUDIOVERBOSE 433options HDAUDIOVERBOSE
432options HDAUDIO_ENABLE_HDMI 434options HDAUDIO_ENABLE_HDMI
433options HDAUDIO_ENABLE_DISPLAYPORT 435options HDAUDIO_ENABLE_DISPLAYPORT
434sun8icodec* at fdt? # Audio codec (sun8i) 436sun8icodec* at fdt? # Audio codec (sun8i)
435sunxicodec* at fdt? # Allwinner audio codec 437sunxicodec* at fdt? # Allwinner audio codec
436sunxii2s* at fdt? # I2S/PCM 438sunxii2s* at fdt? # I2S/PCM
437audio* at audiobus? 439audio* at audiobus?
438spkr* at audio? 440spkr* at audio?
439 441
440# SDMMC 442# SDMMC
441bcmsdhost* at fdt? # Broadcom BCM283x SD Host Interface 443bcmsdhost* at fdt? # Broadcom BCM283x SD Host Interface