Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/sys Pull up following revision(s) (requested by jmcneill ...
details: https://anonhg.NetBSD.org/src/rev/9d37d6fecfc3
branches: netbsd-8
changeset: 433986:9d37d6fecfc3
user: snj <snj%NetBSD.org@localhost>
date: Fri Jun 09 16:59:20 2017 +0000
description:
Pull up following revision(s) (requested by jmcneill in ticket #17):
sys/arch/arm/fdt/aaci_fdt.c: revision 1.1
sys/arch/arm/fdt/files.fdt: revision 1.10
sys/arch/evbarm/conf/VEXPRESS_A15: revisions 1.14, 1.15
sys/conf/files: revision 1.1174
sys/dev/ic/pl041.c: revisions 1.1-1.3
sys/dev/ic/pl041var.h: revision 1.1
Add driver for ARM PrimeCell Advanced Audio CODEC interface (PL041).
Don't expect this driver to work on real hardware, but QEMU emulates it.
--
Add fdt glue for ARM PrimeCell Advanced Audio CODEC interface (PL041).
--
Add aaci at fdt, commented out for now. Driver should work (tm) but QEMU
and my old Thinkpad can't seem to keep up.
--
Fix two bugs:
- Inverted test for fifo status in aaci_write_data
- Return success from trigger_output (thanks nat)
--
Enable aaci
--
bus_space_write_multi_4 takes a count, not number of bytes. With this,
audio works in qemu.
diffstat:
sys/arch/arm/fdt/aaci_fdt.c | 106 +++++++++++
sys/arch/arm/fdt/files.fdt | 5 +-
sys/arch/evbarm/conf/VEXPRESS_A15 | 7 +-
sys/conf/files | 6 +-
sys/dev/ic/pl041.c | 358 ++++++++++++++++++++++++++++++++++++++
sys/dev/ic/pl041var.h | 60 ++++++
6 files changed, 539 insertions(+), 3 deletions(-)
diffs (truncated from 596 to 300 lines):
diff -r 12bdae93a6e6 -r 9d37d6fecfc3 sys/arch/arm/fdt/aaci_fdt.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/fdt/aaci_fdt.c Fri Jun 09 16:59:20 2017 +0000
@@ -0,0 +1,106 @@
+/* $NetBSD: aaci_fdt.c,v 1.1.2.2 2017/06/09 16:59:20 snj Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * 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: aaci_fdt.c,v 1.1.2.2 2017/06/09 16:59:20 snj Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#include <dev/ic/pl041var.h>
+
+static int aaci_fdt_match(device_t, cfdata_t, void *);
+static void aaci_fdt_attach(device_t, device_t, void *);
+
+static const char * const compatible[] = {
+ "arm,pl041",
+ NULL
+};
+
+CFATTACH_DECL_NEW(aaci_fdt, sizeof(struct aaci_softc),
+ aaci_fdt_match, aaci_fdt_attach, NULL, NULL);
+
+static int
+aaci_fdt_match(device_t parent, cfdata_t cf, void *aux)
+{
+ struct fdt_attach_args * const faa = aux;
+
+ return of_compatible(faa->faa_phandle, compatible) >= 0;
+}
+
+static void
+aaci_fdt_attach(device_t parent, device_t self, void *aux)
+{
+ struct aaci_softc * const sc = device_private(self);
+ struct fdt_attach_args * const faa = aux;
+ const int phandle = faa->faa_phandle;
+ char intrstr[128];
+ struct clk *clk;
+ bus_addr_t addr;
+ bus_size_t size;
+ void *ih;
+
+ if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
+ aprint_error(": missing 'reg' property\n");
+ return;
+ }
+
+ if (!fdtbus_intr_str(phandle, 0, intrstr, sizeof(intrstr))) {
+ aprint_error_dev(self, "failed to decode interrupt\n");
+ return;
+ }
+
+ for (int i = 0; (clk = fdtbus_clock_get_index(phandle, i)); i++)
+ if (clk_enable(clk) != 0) {
+ aprint_error(": couldn't enable clock #%d\n", i);
+ return;
+ }
+
+ sc->sc_dev = self;
+ sc->sc_bst = faa->faa_bst;
+ if (bus_space_map(faa->faa_bst, addr, size, 0, &sc->sc_bsh)) {
+ aprint_error(": couldn't map device\n");
+ return;
+ }
+
+ ih = fdtbus_intr_establish(phandle, 0, IPL_AUDIO, FDT_INTR_MPSAFE,
+ aaci_intr, sc);
+ if (ih == NULL) {
+ aprint_error_dev(self, "couldn't install interrupt handler\n");
+ return;
+ }
+
+ aaci_attach(sc);
+
+ aprint_normal_dev(self, "interrupting on %s\n", intrstr);
+}
diff -r 12bdae93a6e6 -r 9d37d6fecfc3 sys/arch/arm/fdt/files.fdt
--- a/sys/arch/arm/fdt/files.fdt Fri Jun 09 16:55:05 2017 +0000
+++ b/sys/arch/arm/fdt/files.fdt Fri Jun 09 16:59:20 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.9 2017/06/03 17:05:23 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.9.2.1 2017/06/09 16:59:20 snj Exp $
include "dev/pckbport/files.pckbport"
@@ -32,5 +32,8 @@
attach smsh at fdt with smsh_fdt
file arch/arm/fdt/smsh_fdt.c smsh_fdt
+attach aaci at fdt with aaci_fdt
+file arch/arm/fdt/aaci_fdt.c aaci_fdt
+
# Console parameters
defparam opt_fdt_arm.h CONSADDR
diff -r 12bdae93a6e6 -r 9d37d6fecfc3 sys/arch/evbarm/conf/VEXPRESS_A15
--- a/sys/arch/evbarm/conf/VEXPRESS_A15 Fri Jun 09 16:55:05 2017 +0000
+++ b/sys/arch/evbarm/conf/VEXPRESS_A15 Fri Jun 09 16:59:20 2017 +0000
@@ -1,5 +1,5 @@
#
-# $NetBSD: VEXPRESS_A15,v 1.12.2.1 2017/06/06 16:26:53 snj Exp $
+# $NetBSD: VEXPRESS_A15,v 1.12.2.2 2017/06/09 16:59:20 snj Exp $
#
# ARM Versatile Express A15
#
@@ -63,6 +63,11 @@
ld3 at sdmmc3
ld* at sdmmc?
+# Audio
+aaci* at fdt? # ARM PrimeCell AACI
+audio* at audiobus?
+spkr* at audio? # PC speaker (synthesized)
+
# Framebuffer
genfb* at fdt?
wsdisplay* at genfb?
diff -r 12bdae93a6e6 -r 9d37d6fecfc3 sys/conf/files
--- a/sys/conf/files Fri Jun 09 16:55:05 2017 +0000
+++ b/sys/conf/files Fri Jun 09 16:59:20 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1173 2017/06/03 17:03:36 jmcneill Exp $
+# $NetBSD: files,v 1.1173.2.1 2017/06/09 16:59:20 snj Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20150846
@@ -1315,6 +1315,10 @@
device dwcmmc: sdmmcbus
file dev/ic/dwc_mmc.c dwcmmc
+# ARM PrimeCell PL041 (AACI) Advanced Audio CODEC interface
+device aaci: audiobus, auconv, aurateconv, mulaw, ac97
+file dev/ic/pl041.c aaci
+
# ARM PrimeCell PL050 (KMI) PS2 keyboard/mouse interface
device plkmi: pckbport
file dev/ic/pl050.c plkmi
diff -r 12bdae93a6e6 -r 9d37d6fecfc3 sys/dev/ic/pl041.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/pl041.c Fri Jun 09 16:59:20 2017 +0000
@@ -0,0 +1,358 @@
+/* $NetBSD: pl041.c,v 1.3.2.2 2017/06/09 16:59:20 snj Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * 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: pl041.c,v 1.3.2.2 2017/06/09 16:59:20 snj Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+#include <sys/bus.h>
+#include <sys/audioio.h>
+
+#include <dev/audio_if.h>
+#include <dev/auconv.h>
+
+#include <dev/ic/ac97var.h>
+#include <dev/ic/ac97reg.h>
+
+#include <dev/ic/pl041var.h>
+
+#define AACIRXCR 0x00
+#define AACITXCR 0x04
+#define AACITXCR_TXFEN __BIT(16)
+#define AACITXCR_TXCM __BIT(15)
+#define AACITXCR_TSIZE __BITS(14,13)
+#define AACITXCR_TSIZE_16 __SHIFTIN(0, AACITXCR_TSIZE)
+#define AACITXCR_TX(n) __BIT(n)
+#define AACITXCR_TXEN __BIT(0)
+#define AACISR 0x08
+#define AACISR_TXFF __BIT(5)
+#define AACISR_TXHE __BIT(3)
+#define AACIISR 0x0c
+#define AACIISR_URINTR __BIT(5)
+#define AACIISR_TXINTR __BIT(2)
+#define AACIIE 0x10
+#define AACIIE_TXUIE __BIT(5)
+#define AACIIE_TXIE __BIT(2)
+#define AACISL1RX 0x50
+#define AACISL1TX 0x54
+#define AACISL2RX 0x58
+#define AACISL2TX 0x5c
+#define AACISLFR 0x68
+#define AACISLISTAT 0x6c
+#define AACISLIEN 0x70
+#define AACIINTCLR 0x74
+#define AACIMAINCR 0x78
+#define AACIRESET 0x7c
+#define AACISYNC 0x80
+#define AACIALLINTS 0x84
+#define AACIMAINFR 0x88
+#define AACIDR 0x90
+
+#define AACI_FIFO_DEPTH 512
+#define AACI_BLOCK_ALIGN 4
+
+#define AACI_READ(sc, reg) \
+ bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
+#define AACI_WRITE(sc, reg, val) \
+ bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
+#define AACI_WRITE_MULTI(sc, reg, val, cnt) \
+ bus_space_write_multi_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val), (cnt))
+
+static const struct audio_format aaci_format = {
+ .mode = AUMODE_PLAY,
+ .encoding = AUDIO_ENCODING_SLINEAR_LE,
+ .validbits = 16,
+ .precision = 16,
+ .channels = 2,
+ .channel_mask = AUFMT_STEREO,
+ .frequency_type = 0,
+ .frequency = { 48000, 48000 }
+};
+
+static void
+aaci_write_data(struct aaci_softc *sc)
+{
+ KASSERT(mutex_owned(&sc->sc_intr_lock));
+
+ if (sc->sc_pint == NULL)
+ return;
+
+ while ((AACI_READ(sc, AACISR) & AACISR_TXHE) != 0) {
+ const int len = min(AACI_FIFO_DEPTH / 2, min(sc->sc_pblkresid,
+ (uintptr_t)sc->sc_pend - (uintptr_t)sc->sc_pcur));
+ KASSERT((len & 3) == 0);
+ AACI_WRITE_MULTI(sc, AACIDR, sc->sc_pcur, len >> 2);
+ sc->sc_pcur += (len >> 2);
+ if (sc->sc_pcur == sc->sc_pend)
+ sc->sc_pcur = sc->sc_pstart;
+ sc->sc_pblkresid -= len;
+ if (sc->sc_pblkresid == 0) {
+ sc->sc_pblkresid = sc->sc_pblksize;
+ sc->sc_pint(sc->sc_pintarg);
+ }
+ }
+}
+
+static int
+aaci_query_encoding(void *priv, struct audio_encoding *enc)
+{
Home |
Main Index |
Thread Index |
Old Index