socsvn commit: r288828 - in soc2015/pratiksinghal: . cubie-head/sys/arm/allwinner
pratiksinghal at FreeBSD.org
pratiksinghal at FreeBSD.org
Tue Jul 28 05:36:22 UTC 2015
Author: pratiksinghal
Date: Tue Jul 28 05:36:21 2015
New Revision: 288828
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=288828
Log:
Added the ac97_c file with preliminary code
Added:
soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.c (contents, props changed)
Modified:
soc2015/pratiksinghal/ (props changed)
soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.h
Added: soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.c Tue Jul 28 05:36:21 2015 (r288828)
@@ -0,0 +1,179 @@
+/*-
+ * Copyright (c) 2015 Pratik Singhal
+ * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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/param.h>
+#include <sys/bus.h>
+#include <sys/gpio.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/rman.h>
+#include <sys/types.H>
+#include <sys/systm.h>
+
+#include <dev/sound/pcm/sound.h>
+
+#include <dev/sound/ac97/ac97.h>
+
+#include "a10_ac97.h"
+
+/* TODO :- Add DMA support after the pio mode works corectly. */
+
+struct a10_ac97_info
+{
+ device_t ac_dev;
+ struct resource * mem_res;
+ struct resource * irq_res;
+ int mem_rid;
+ int irq_rid;
+ void * intr_handle;
+ bus_space_handle_t ac97_bsh;
+ bus_space_tag_t ac97_bst;
+ struct mtx ac97_mtx;
+ struct ac97_info *codec;
+
+ uint32_t ienab;
+ uint32_t use_dma;
+};
+
+#define AC97_READ(_sc, _reg) \
+ bus_space_read_4((_sc)->ac97_bst, (_sc)->ac97_bsh, _reg)
+#define AC97_WRITE(_sc, _reg, _value) \
+ bus_space_write_4((_sc)->ac97_bst, (_sc)->ac97_bsh, _reg, _value)
+#define AC97_LOCK(_sc) \
+ mtx_lock((_sc)->ac97_mtx)
+#define AC97_UNLOCK(_sc) \
+ mtx_unlock((_sc)->ac97_mtx)
+
+
+static int
+ac97_probe(device_t dev)
+{
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+ if (!ofw_bus_is_compatible(dev, "allwinner,sun4i-a10-ac97"))
+ return (ENXIO);
+ device_set_desc(dev, "Allwinner AC97 Controller");
+
+ return (BUS_PROBE_DEFAULT);
+}
+
+/* After cold reset perform the following steps :-
+ * set GPIO and release INTMASK/SUBINTMASK bits ( How to do that ? )
+ * Enable Codec Ready interrupt
+ */
+
+static ac97_attach(device_t dev)
+{
+ struct a10_ac97_info *sc;
+ device_t gpio;
+ int error;
+
+ sc = device_get_softc(dev);
+ sc->ac_dev = dev;
+ sc->use_dma = 0;
+ error = 0;
+ ienab = 0;
+
+ sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, RF_ACTIVE);
+ if (sc->mem_res == NULL) {
+ device_printf(dev, "Cannot allocate memory resource\n");
+ goto fail;
+ }
+ sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, RF_ACTIVE | RF_SHAREABLE);
+ if (sc->irq_res == NULL) {
+ device_printf(dev, "Cannot allocate IRQ resource\n");
+ goto fail;
+ }
+ error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC | INTR_MPSAFE,
+ NULL, ac97_intr, &sc->intr_handle);
+ if (error) {
+ device_printf(dev, "Cannot setup interrupt handler %d\n", error);
+ goto fail;
+ }
+ sc->ac97_bst = rman_get_bustag(sc->mem_res);
+ sc->ac97_bsh = rman_get_bushandle(sc->mem_res);
+
+ mtx_init(&sc->ac97_mtx, device_get_nameunit(dev), "a10_ac97", MTX_DEF);
+
+ device_printf("Before resetting device");
+
+ uint32_t val,total;
+ AC97_WRITE(sc, AC_CTL, AC_WARM_RST)
+ total = 0;
+ while (1) {
+ val = AC97_READ(sc, AC_CTL);
+ if ((val >> 1) & 1 == 0)
+ break;
+ else
+ DELAY(2)
+ total += 2;
+ if (total > 40)
+ break;
+ }
+ if (total > 40)
+ device_printf(dev, "Device timedout\n");
+ else
+ device_printf(dev, "Device reset succesfully after %d seconds\n",total);
+ sc->ienab = AC_CODEC_READY_INT_EN;
+ AC97_WRITE(sc, AC_INT, 0);
+ AC97_WRITE(sc, AC_INT, sc->ienab);
+
+ return (0);
+
+fail:
+ if (sc->mem_res != NULL)
+ bus_release_resouce(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res);
+ if (sc->irq_res != NULL) {
+ bus_teardown_intr(dev, sc->irq_res, sc->intr_handle);
+ bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res);
+ }
+ mtx_destroy(&sc->ac97_mtx);
+
+ return (ENXIO);
+}
+
+static ac97_detach(device_t dev)
+{
+ return (EBUSY);
+}
+
+static device_method_t a10_ac97_methods[] = {
+ DEVMETHOD(device_probe, ac97_probe),
+ DEVMETHOD(device_attach, ac97_attach),
+ DEVMETHOD(device_detach, ac97_detach),
+
+ DEVMETHOD_END
+ };
+
+static devclass_t a10_ac97_devclass;
+
+static driver_t a10_ac97_driver = {
+ "a10_ac97",
+ a10_ac97_methods,
+ sizeof(struct a10_ac97_info);
+};
+
+DRIVER_MODULE(a10_ac97, pci, a10_ac97_driver, a10_ac97_devclass, 0, 0);
Modified: soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.h
==============================================================================
--- soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.h Tue Jul 28 04:54:05 2015 (r288827)
+++ soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.h Tue Jul 28 05:36:21 2015 (r288828)
@@ -49,21 +49,21 @@
#define AC_RX_CNT 0x2C /* AC97 RX counter register */
/* AC_CTL */
-#define AC_CODEC_FULL (1U << 18)
+#define AC_CODEC_FULL (1U << 18)
#define AC_CMD_FULL (1U << 17)
-#define AC_RX_MIC_IN (1U << 16)
-#define AC_RX_MODE_MIC (1U << 9)
+#define AC_RX_MIC_IN (1U << 16)
+#define AC_RX_MODE_MIC (1U << 9)
#define AC_TX_EN (1U << 7)
#define AC_RX_EN (1U << 6)
#define AC_LINK_EN (1U << 5)
-#define AC_GLOBAL_EN (1U << 4)
+#define AC_GLOBAL_EN (1U << 4)
#define AC_WARM_RST (1U << 1)
/* AC_FAT */
#define AC_TX_MODE_2 (0)
#define AC_TX_MODE_6 (0U << 8)|(1U << 7)
-#define AC_DRA_1 (1U << 6)
-#define AC_VRA_MODE (1U << 4)
+#define AC_DRA_1 (1U << 6)
+#define AC_VRA_MODE (1U << 4)
#define AC_TX_RES_16 (0U << 2)
#define AC_TX_RES_18 (2U << 2)
#define AC_TX_RES_20 (1U << 3)
@@ -72,4 +72,24 @@
#define AC_RX_RES_20 (1U << 1)
/* AC_CMD */
-#define AC_CMD_READ (1U << 23)
+#define AC_CMD_READ (1U << 23)
+
+/* AC_INT */
+#define AC_CODEC_GPIO_INT_EN (1U << 9)
+#define AC_CODEC_READY_INT_EN (1U << 8)
+#define AC_TX_EMPTY_DRQ_EN (1U << 7)
+#define AC_TX_UN_INT_EN (1U << 6)
+#define AC_TX_ON_INT_EN (1U << 5)
+#define AC_TX_EMPTY_INT_EN (1U << 4)
+#define AC_RX_DATA_DRQ_EN (1U << 2)
+#define AC_RX_ON_INT_EN (1U << 1)
+#define AC_RX_DATA_INT_EN (1U << 0)
+
+/* AC_ISTA */
+#define AC_CODEC_GPIO_INT (1U << 9)
+#define AC_CODEC_READY_INT (1U << 8)
+#define AC_TX_UN_INT (1U << 6)
+#define AC_TX_ON_INT (1U << 5)
+#define AC_TX_EMPTY_INT (1U << 4)
+#define AC_RX_ON_INT (1U << 1)
+#define AC_RX_DATa_INT (1U << 0)
More information about the svn-soc-all
mailing list