Path: blob/main/sys/arm/freescale/imx/imx6_audmux.c
39536 views
/*-1* Copyright (c) 2015 Ruslan Bukin <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526/*27* i.MX6 Digital Audio Multiplexer (AUDMUX)28* Chapter 16, i.MX 6Dual/6Quad Applications Processor Reference Manual,29* Rev. 1, 04/201330*/3132#include <sys/param.h>33#include <sys/systm.h>34#include <sys/bus.h>35#include <sys/kernel.h>36#include <sys/module.h>37#include <sys/malloc.h>38#include <sys/endian.h>39#include <sys/rman.h>40#include <sys/timeet.h>41#include <sys/timetc.h>4243#include <dev/ofw/openfirm.h>44#include <dev/ofw/ofw_bus.h>45#include <dev/ofw/ofw_bus_subr.h>4647#include <machine/bus.h>48#include <machine/cpu.h>49#include <machine/intr.h>5051#define READ4(_sc, _reg) \52bus_space_read_4(_sc->bst, _sc->bsh, _reg)53#define WRITE4(_sc, _reg, _val) \54bus_space_write_4(_sc->bst, _sc->bsh, _reg, _val)5556#define AUDMUX_PTCR(n) (0x8 * (n - 1)) /* Port Timing Control Register */57#define PTCR_TFS_DIR (1 << 31) /* Transmit Frame Sync Direction Control */58#define PTCR_TFSEL_S 27 /* Transmit Frame Sync Select */59#define PTCR_TFSEL_M 0xf60#define PTCR_TCLKDIR (1 << 26) /* Transmit Clock Direction Control */61#define PTCR_TCSEL_S 22 /* Transmit Clock Select. */62#define PTCR_TCSEL_M 0xf63#define PTCR_RFS_DIR (1 << 21) /* Receive Frame Sync Direction Control */64#define PTCR_SYN (1 << 11)65#define AUDMUX_PDCR(n) (0x8 * (n - 1) + 0x4) /* Port Data Control Reg */66#define PDCR_RXDSEL_S 13 /* Receive Data Select */67#define PDCR_RXDSEL_M 0x368#define PDCR_RXDSEL_PORT(n) (n - 1)6970struct audmux_softc {71struct resource *res[1];72bus_space_tag_t bst;73bus_space_handle_t bsh;74void *ih;75};7677static struct resource_spec audmux_spec[] = {78{ SYS_RES_MEMORY, 0, RF_ACTIVE },79{ -1, 0 }80};8182static int83audmux_probe(device_t dev)84{8586if (!ofw_bus_status_okay(dev))87return (ENXIO);8889if (!ofw_bus_is_compatible(dev, "fsl,imx6q-audmux"))90return (ENXIO);9192device_set_desc(dev, "i.MX6 Digital Audio Multiplexer");93return (BUS_PROBE_DEFAULT);94}9596static int97audmux_configure(struct audmux_softc *sc,98int ssi_port, int audmux_port)99{100uint32_t reg;101102/* Direction: output */103reg = (PTCR_TFS_DIR | PTCR_TCLKDIR | PTCR_SYN);104WRITE4(sc, AUDMUX_PTCR(audmux_port), reg);105106/* Select source */107reg = (PDCR_RXDSEL_PORT(ssi_port) << PDCR_RXDSEL_S);108WRITE4(sc, AUDMUX_PDCR(audmux_port), reg);109110return (0);111}112113static int114audmux_attach(device_t dev)115{116struct audmux_softc *sc;117118sc = device_get_softc(dev);119120if (bus_alloc_resources(dev, audmux_spec, sc->res)) {121device_printf(dev, "could not allocate resources\n");122return (ENXIO);123}124125/* Memory interface */126sc->bst = rman_get_bustag(sc->res[0]);127sc->bsh = rman_get_bushandle(sc->res[0]);128129/*130* Direct SSI1 output to AUDMUX5 pins.131* TODO: dehardcore this.132*/133audmux_configure(sc, 1, 5);134135return (0);136};137138static device_method_t audmux_methods[] = {139/* Device interface */140DEVMETHOD(device_probe, audmux_probe),141DEVMETHOD(device_attach, audmux_attach),142{ 0, 0 }143};144145static driver_t audmux_driver = {146"audmux",147audmux_methods,148sizeof(struct audmux_softc),149};150151DRIVER_MODULE(audmux, simplebus, audmux_driver, 0, 0);152153154