Home | History | Annotate | Line # | Download | only in dev
zaudio.c revision 1.19.6.2
      1  1.19.6.2  jdolecek /*	$NetBSD: zaudio.c,v 1.19.6.2 2017/12/03 11:36:52 jdolecek Exp $	*/
      2       1.1      ober /*	$OpenBSD: zaurus_audio.c,v 1.8 2005/08/18 13:23:02 robert Exp $	*/
      3       1.1      ober 
      4       1.1      ober /*
      5       1.1      ober  * Copyright (c) 2005 Christopher Pascoe <pascoe (at) openbsd.org>
      6       1.1      ober  *
      7       1.1      ober  * Permission to use, copy, modify, and distribute this software for any
      8       1.1      ober  * purpose with or without fee is hereby granted, provided that the above
      9       1.1      ober  * copyright notice and this permission notice appear in all copies.
     10       1.1      ober  *
     11       1.1      ober  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12       1.1      ober  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13       1.1      ober  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14       1.1      ober  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15       1.1      ober  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16       1.1      ober  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17       1.1      ober  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18       1.1      ober  */
     19       1.1      ober 
     20      1.10    nonaka /*-
     21      1.17    nonaka  * Copyright (C) 2009 NONAKA Kimihiro <nonaka (at) netbsd.org>
     22      1.10    nonaka  * All rights reserved.
     23      1.10    nonaka  *
     24      1.10    nonaka  * Redistribution and use in source and binary forms, with or without
     25      1.10    nonaka  * modification, are permitted provided that the following conditions
     26      1.10    nonaka  * are met:
     27      1.10    nonaka  * 1. Redistributions of source code must retain the above copyright
     28      1.10    nonaka  *    notice, this list of conditions and the following disclaimer.
     29      1.10    nonaka  * 2. Redistributions in binary form must reproduce the above copyright
     30      1.10    nonaka  *    notice, this list of conditions and the following disclaimer in the
     31      1.10    nonaka  *    documentation and/or other materials provided with the distribution.
     32      1.10    nonaka  *
     33      1.17    nonaka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     34      1.17    nonaka  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     35      1.17    nonaka  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     36      1.17    nonaka  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     37      1.17    nonaka  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     38      1.17    nonaka  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     39      1.17    nonaka  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     40      1.17    nonaka  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     41      1.17    nonaka  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     42      1.17    nonaka  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     43      1.10    nonaka  */
     44      1.10    nonaka 
     45       1.1      ober /*
     46       1.1      ober  * TODO:
     47       1.1      ober  *	- powerhooks (currently only works until first suspend)
     48       1.1      ober  */
     49       1.1      ober 
     50  1.19.6.2  jdolecek #include "opt_cputypes.h"
     51      1.13    nonaka 
     52       1.1      ober #include <sys/cdefs.h>
     53  1.19.6.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: zaudio.c,v 1.19.6.2 2017/12/03 11:36:52 jdolecek Exp $");
     54       1.1      ober 
     55       1.1      ober #include <sys/param.h>
     56       1.1      ober #include <sys/systm.h>
     57  1.19.6.2  jdolecek #include <sys/audioio.h>
     58       1.1      ober #include <sys/callout.h>
     59       1.1      ober #include <sys/device.h>
     60      1.13    nonaka #include <sys/mutex.h>
     61      1.13    nonaka 
     62      1.13    nonaka #include <dev/audio_if.h>
     63       1.1      ober 
     64      1.13    nonaka #include <dev/i2c/i2cvar.h>
     65       1.1      ober 
     66       1.1      ober #include <arm/xscale/pxa2x0reg.h>
     67       1.1      ober #include <arm/xscale/pxa2x0var.h>
     68       1.1      ober #include <arm/xscale/pxa2x0_i2s.h>
     69       1.1      ober 
     70      1.13    nonaka #include <zaurus/zaurus/zaurus_var.h>
     71  1.19.6.2  jdolecek #include <zaurus/dev/zaudiovar.h>
     72  1.19.6.2  jdolecek #if defined(CPU_XSCALE_PXA270)
     73  1.19.6.2  jdolecek #include <zaurus/dev/wm8750var.h>
     74  1.19.6.2  jdolecek #endif
     75  1.19.6.2  jdolecek #if defined(CPU_XSCALE_PXA250)
     76  1.19.6.2  jdolecek #include <zaurus/dev/wm8731var.h>
     77  1.19.6.2  jdolecek #endif
     78      1.13    nonaka 
     79      1.13    nonaka static int	zaudio_match(device_t, cfdata_t, void *);
     80      1.13    nonaka static void	zaudio_attach(device_t, device_t, void *);
     81      1.13    nonaka 
     82       1.6    nonaka CFATTACH_DECL_NEW(zaudio, sizeof(struct zaudio_softc),
     83       1.7    nonaka     zaudio_match, zaudio_attach, NULL, NULL);
     84       1.1      ober 
     85       1.1      ober static int
     86       1.6    nonaka zaudio_match(device_t parent, cfdata_t cf, void *aux)
     87       1.1      ober {
     88      1.13    nonaka 	struct i2c_attach_args *ia = aux;
     89       1.1      ober 
     90  1.19.6.2  jdolecek 	if (ZAURUS_ISC1000 || ZAURUS_ISC3000) {
     91  1.19.6.2  jdolecek #if defined(CPU_XSCALE_PXA270)
     92  1.19.6.2  jdolecek 		return wm8750_match(parent, cf, ia);
     93  1.19.6.2  jdolecek #endif
     94  1.19.6.2  jdolecek 	} else if (ZAURUS_ISC860) {
     95  1.19.6.2  jdolecek #if defined(CPU_XSCALE_PXA250)
     96  1.19.6.2  jdolecek 		return wm8731_match(parent, cf, ia);
     97  1.19.6.2  jdolecek #endif
     98      1.13    nonaka 	}
     99      1.13    nonaka 	return 0;
    100       1.1      ober }
    101       1.1      ober 
    102       1.1      ober static void
    103       1.6    nonaka zaudio_attach(device_t parent, device_t self, void *aux)
    104       1.1      ober {
    105       1.6    nonaka 	struct zaudio_softc *sc = device_private(self);
    106      1.13    nonaka 	struct i2c_attach_args *ia = aux;
    107       1.1      ober 
    108  1.19.6.2  jdolecek 	sc->sc_dev = self;
    109      1.13    nonaka 	sc->sc_i2c = ia->ia_tag;
    110  1.19.6.2  jdolecek 
    111      1.16  jmcneill 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
    112      1.16  jmcneill 	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
    113  1.19.6.2  jdolecek 	callout_init(&sc->sc_to, 0);
    114       1.6    nonaka 
    115      1.13    nonaka 	sc->sc_i2s.sc_iot = &pxa2x0_bs_tag;
    116      1.13    nonaka 	sc->sc_i2s.sc_dmat = &pxa2x0_bus_dma_tag;
    117       1.1      ober 	sc->sc_i2s.sc_size = PXA2X0_I2S_SIZE;
    118      1.16  jmcneill 	sc->sc_i2s.sc_intr_lock = &sc->sc_intr_lock;
    119       1.1      ober 	if (pxa2x0_i2s_attach_sub(&sc->sc_i2s)) {
    120      1.13    nonaka 		aprint_error_dev(self, "unable to attach I2S\n");
    121  1.19.6.2  jdolecek 		return;
    122       1.1      ober 	}
    123       1.1      ober 
    124  1.19.6.2  jdolecek 	if (ZAURUS_ISC1000 || ZAURUS_ISC3000) {
    125  1.19.6.2  jdolecek #if defined(CPU_XSCALE_PXA270)
    126  1.19.6.2  jdolecek 		wm8750_attach(parent, self, ia);
    127  1.19.6.2  jdolecek #endif
    128  1.19.6.2  jdolecek 	} else if (ZAURUS_ISC860) {
    129  1.19.6.2  jdolecek #if defined(CPU_XSCALE_PXA250)
    130  1.19.6.2  jdolecek 		wm8731_attach(parent, self, ia);
    131      1.13    nonaka #endif
    132       1.1      ober 	}
    133       1.2     peter 
    134       1.1      ober 	return;
    135       1.1      ober }
    136       1.1      ober 
    137       1.2     peter /*
    138       1.2     peter  * audio operation functions.
    139       1.2     peter  */
    140  1.19.6.2  jdolecek int
    141       1.1      ober zaudio_open(void *hdl, int flags)
    142       1.1      ober {
    143       1.1      ober 	struct zaudio_softc *sc = hdl;
    144       1.1      ober 
    145       1.1      ober 	/* Power on the I2S bus and codec */
    146       1.1      ober 	pxa2x0_i2s_open(&sc->sc_i2s);
    147       1.1      ober 
    148       1.1      ober 	return 0;
    149       1.1      ober }
    150       1.1      ober 
    151  1.19.6.2  jdolecek void
    152       1.1      ober zaudio_close(void *hdl)
    153       1.1      ober {
    154       1.1      ober 	struct zaudio_softc *sc = hdl;
    155       1.1      ober 
    156       1.1      ober 	/* Power off the I2S bus and codec */
    157       1.1      ober 	pxa2x0_i2s_close(&sc->sc_i2s);
    158       1.1      ober }
    159       1.1      ober 
    160  1.19.6.2  jdolecek int
    161       1.2     peter zaudio_round_blocksize(void *hdl, int bs, int mode, const audio_params_t *param)
    162       1.2     peter {
    163       1.2     peter 	struct zaudio_softc *sc = hdl;
    164       1.1      ober 
    165       1.2     peter 	return pxa2x0_i2s_round_blocksize(&sc->sc_i2s, bs, mode, param);
    166       1.1      ober }
    167       1.1      ober 
    168  1.19.6.2  jdolecek void *
    169      1.16  jmcneill zaudio_allocm(void *hdl, int direction, size_t size)
    170       1.2     peter {
    171       1.2     peter 	struct zaudio_softc *sc = hdl;
    172       1.2     peter 
    173      1.16  jmcneill 	return pxa2x0_i2s_allocm(&sc->sc_i2s, direction, size);
    174       1.2     peter }
    175       1.2     peter 
    176  1.19.6.2  jdolecek void
    177      1.16  jmcneill zaudio_freem(void *hdl, void *ptr, size_t size)
    178       1.2     peter {
    179       1.2     peter 	struct zaudio_softc *sc = hdl;
    180       1.2     peter 
    181      1.16  jmcneill 	return pxa2x0_i2s_freem(&sc->sc_i2s, ptr, size);
    182       1.2     peter }
    183       1.2     peter 
    184  1.19.6.2  jdolecek size_t
    185       1.2     peter zaudio_round_buffersize(void *hdl, int direction, size_t bufsize)
    186       1.2     peter {
    187       1.2     peter 	struct zaudio_softc *sc = hdl;
    188       1.2     peter 
    189       1.2     peter 	return pxa2x0_i2s_round_buffersize(&sc->sc_i2s, direction, bufsize);
    190       1.2     peter }
    191       1.2     peter 
    192  1.19.6.2  jdolecek paddr_t
    193       1.2     peter zaudio_mappage(void *hdl, void *mem, off_t off, int prot)
    194       1.2     peter {
    195       1.2     peter 	struct zaudio_softc *sc = hdl;
    196       1.2     peter 
    197       1.2     peter 	return pxa2x0_i2s_mappage(&sc->sc_i2s, mem, off, prot);
    198       1.2     peter }
    199       1.2     peter 
    200  1.19.6.2  jdolecek int
    201       1.1      ober zaudio_get_props(void *hdl)
    202       1.1      ober {
    203       1.2     peter 
    204      1.10    nonaka 	return AUDIO_PROP_MMAP|AUDIO_PROP_INDEPENDENT;
    205       1.1      ober }
    206       1.1      ober 
    207  1.19.6.2  jdolecek void
    208      1.16  jmcneill zaudio_get_locks(void *hdl, kmutex_t **intr, kmutex_t **thread)
    209      1.16  jmcneill {
    210      1.16  jmcneill 	struct zaudio_softc *sc = hdl;
    211      1.16  jmcneill 
    212      1.16  jmcneill 	*intr = &sc->sc_intr_lock;
    213      1.16  jmcneill 	*thread = &sc->sc_lock;
    214      1.16  jmcneill }
    215