Home | History | Annotate | Line # | Download | only in pci
cs4280.c revision 1.32.2.2
      1  1.32.2.2      kent /*	$NetBSD: cs4280.c,v 1.32.2.2 2005/01/03 16:40:26 kent Exp $	*/
      2       1.1  augustss 
      3       1.1  augustss /*
      4       1.2  augustss  * Copyright (c) 1999, 2000 Tatoku Ogaito.  All rights reserved.
      5       1.1  augustss  *
      6       1.1  augustss  * Redistribution and use in source and binary forms, with or without
      7       1.1  augustss  * modification, are permitted provided that the following conditions
      8       1.1  augustss  * are met:
      9       1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     10       1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     11       1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     13       1.1  augustss  *    documentation and/or other materials provided with the distribution.
     14       1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     15       1.1  augustss  *    must display the following acknowledgement:
     16       1.1  augustss  *	This product includes software developed by Tatoku Ogaito
     17       1.1  augustss  *	for the NetBSD Project.
     18       1.1  augustss  * 4. The name of the author may not be used to endorse or promote products
     19       1.1  augustss  *    derived from this software without specific prior written permission
     20       1.1  augustss  *
     21       1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22       1.1  augustss  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23       1.1  augustss  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24       1.1  augustss  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25       1.1  augustss  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26       1.1  augustss  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27       1.1  augustss  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28       1.1  augustss  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29       1.1  augustss  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30       1.1  augustss  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31       1.1  augustss  */
     32       1.1  augustss 
     33       1.1  augustss /*
     34       1.1  augustss  * Cirrus Logic CS4280 (and maybe CS461x) driver.
     35       1.1  augustss  * Data sheets can be found
     36       1.1  augustss  * http://www.cirrus.com/ftp/pubs/4280.pdf
     37       1.1  augustss  * http://www.cirrus.com/ftp/pubs/4297.pdf
     38       1.1  augustss  * ftp://ftp.alsa-project.org/pub/manuals/cirrus/embedded_audio_spec.pdf
     39       1.1  augustss  * ftp://ftp.alsa-project.org/pub/manuals/cirrus/embedded_audio_spec.doc
     40       1.6  augustss  *
     41      1.14     tacha  * Note:  CS4610/CS4611 + CS423x ISA codec should be worked with
     42       1.6  augustss  *	 wss* at pnpbios?
     43      1.14     tacha  * or
     44      1.14     tacha  *       sb* at pnpbios?
     45      1.14     tacha  * Since I could not find any documents on handling ISA codec,
     46      1.14     tacha  * clcs does not support those chips.
     47       1.1  augustss  */
     48       1.1  augustss 
     49       1.1  augustss /*
     50       1.1  augustss  * TODO
     51       1.1  augustss  * Joystick support
     52       1.1  augustss  */
     53      1.18     lukem 
     54      1.18     lukem #include <sys/cdefs.h>
     55  1.32.2.2      kent __KERNEL_RCSID(0, "$NetBSD: cs4280.c,v 1.32.2.2 2005/01/03 16:40:26 kent Exp $");
     56       1.1  augustss 
     57       1.6  augustss #include "midi.h"
     58       1.6  augustss 
     59       1.1  augustss #include <sys/param.h>
     60       1.1  augustss #include <sys/systm.h>
     61       1.1  augustss #include <sys/kernel.h>
     62       1.1  augustss #include <sys/fcntl.h>
     63       1.1  augustss #include <sys/malloc.h>
     64       1.1  augustss #include <sys/device.h>
     65      1.13  augustss #include <sys/proc.h>
     66       1.1  augustss #include <sys/systm.h>
     67       1.1  augustss 
     68       1.1  augustss #include <dev/pci/pcidevs.h>
     69       1.1  augustss #include <dev/pci/pcivar.h>
     70       1.1  augustss #include <dev/pci/cs4280reg.h>
     71       1.1  augustss #include <dev/pci/cs4280_image.h>
     72      1.14     tacha #include <dev/pci/cs428xreg.h>
     73       1.1  augustss 
     74       1.1  augustss #include <sys/audioio.h>
     75       1.1  augustss #include <dev/audio_if.h>
     76       1.1  augustss #include <dev/midi_if.h>
     77       1.1  augustss #include <dev/mulaw.h>
     78       1.1  augustss #include <dev/auconv.h>
     79       1.4   thorpej 
     80       1.4   thorpej #include <dev/ic/ac97reg.h>
     81       1.3   thorpej #include <dev/ic/ac97var.h>
     82       1.1  augustss 
     83      1.14     tacha #include <dev/pci/cs428x.h>
     84      1.14     tacha 
     85       1.1  augustss #include <machine/bus.h>
     86       1.1  augustss #include <machine/bswap.h>
     87       1.1  augustss 
     88       1.1  augustss #define BA1READ4(sc, r) bus_space_read_4((sc)->ba1t, (sc)->ba1h, (r))
     89       1.1  augustss #define BA1WRITE4(sc, r, x) bus_space_write_4((sc)->ba1t, (sc)->ba1h, (r), (x))
     90       1.1  augustss 
     91      1.14     tacha /* IF functions for audio driver */
     92      1.14     tacha int  cs4280_match(struct device *, struct cfdata *, void *);
     93      1.14     tacha void cs4280_attach(struct device *, struct device *, void *);
     94      1.14     tacha int  cs4280_intr(void *);
     95      1.14     tacha int  cs4280_query_encoding(void *, struct audio_encoding *);
     96  1.32.2.1      kent int  cs4280_set_params(void *, int, int, audio_params_t *, audio_params_t *,
     97  1.32.2.1      kent 		       stream_filter_list_t *, stream_filter_list_t *);
     98      1.14     tacha int  cs4280_halt_output(void *);
     99      1.14     tacha int  cs4280_halt_input(void *);
    100      1.14     tacha int  cs4280_getdev(void *, struct audio_device *);
    101      1.14     tacha int  cs4280_trigger_output(void *, void *, void *, int, void (*)(void *),
    102  1.32.2.1      kent 			   void *, const audio_params_t *);
    103      1.14     tacha int  cs4280_trigger_input(void *, void *, void *, int, void (*)(void *),
    104  1.32.2.1      kent 			  void *, const audio_params_t *);
    105      1.14     tacha 
    106      1.30      kent int cs4280_reset_codec(void *);
    107      1.14     tacha 
    108      1.14     tacha /* For PowerHook */
    109      1.14     tacha void cs4280_power(int, void *);
    110      1.14     tacha 
    111      1.14     tacha /* Internal functions */
    112      1.14     tacha void cs4280_set_adc_rate(struct cs428x_softc *, int );
    113      1.14     tacha void cs4280_set_dac_rate(struct cs428x_softc *, int );
    114      1.14     tacha int  cs4280_download(struct cs428x_softc *, const u_int32_t *, u_int32_t, u_int32_t);
    115      1.14     tacha int  cs4280_download_image(struct cs428x_softc *);
    116      1.14     tacha void cs4280_reset(void *);
    117      1.14     tacha int  cs4280_get_portnum_by_name(struct cs428x_softc *, char *, char *, char *);
    118      1.14     tacha int  cs4280_init(struct cs428x_softc *, int);
    119      1.14     tacha void cs4280_clear_fifos(struct cs428x_softc *);
    120      1.14     tacha 
    121      1.14     tacha #if CS4280_DEBUG > 10
    122      1.14     tacha /* Thease two function is only for checking image loading is succeeded or not. */
    123      1.14     tacha int  cs4280_check_images(struct cs428x_softc *);
    124      1.14     tacha int  cs4280_checkimage(struct cs428x_softc *, u_int32_t *, u_int32_t, u_int32_t);
    125       1.1  augustss #endif
    126       1.1  augustss 
    127      1.31      yamt const struct audio_hw_if cs4280_hw_if = {
    128      1.14     tacha 	cs428x_open,
    129      1.14     tacha 	cs428x_close,
    130       1.1  augustss 	NULL,
    131       1.1  augustss 	cs4280_query_encoding,
    132       1.1  augustss 	cs4280_set_params,
    133      1.14     tacha 	cs428x_round_blocksize,
    134       1.1  augustss 	NULL,
    135       1.1  augustss 	NULL,
    136       1.1  augustss 	NULL,
    137       1.1  augustss 	NULL,
    138       1.1  augustss 	NULL,
    139       1.1  augustss 	cs4280_halt_output,
    140       1.1  augustss 	cs4280_halt_input,
    141       1.1  augustss 	NULL,
    142       1.1  augustss 	cs4280_getdev,
    143       1.1  augustss 	NULL,
    144      1.14     tacha 	cs428x_mixer_set_port,
    145      1.14     tacha 	cs428x_mixer_get_port,
    146      1.14     tacha 	cs428x_query_devinfo,
    147      1.14     tacha 	cs428x_malloc,
    148      1.14     tacha 	cs428x_free,
    149      1.14     tacha 	cs428x_round_buffersize,
    150      1.14     tacha 	cs428x_mappage,
    151      1.14     tacha 	cs428x_get_props,
    152       1.1  augustss 	cs4280_trigger_output,
    153       1.1  augustss 	cs4280_trigger_input,
    154      1.17  augustss 	NULL,
    155       1.1  augustss };
    156       1.1  augustss 
    157       1.1  augustss #if NMIDI > 0
    158      1.14     tacha /* Midi Interface */
    159      1.14     tacha int  cs4280_midi_open(void *, int, void (*)(void *, int),
    160      1.14     tacha                       void (*)(void *), void *);
    161      1.14     tacha void cs4280_midi_close(void*);
    162      1.14     tacha int  cs4280_midi_output(void *, int);
    163      1.14     tacha void cs4280_midi_getinfo(void *, struct midi_info *);
    164      1.14     tacha 
    165      1.31      yamt const struct midi_hw_if cs4280_midi_hw_if = {
    166       1.1  augustss 	cs4280_midi_open,
    167       1.1  augustss 	cs4280_midi_close,
    168       1.1  augustss 	cs4280_midi_output,
    169       1.1  augustss 	cs4280_midi_getinfo,
    170       1.1  augustss 	0,
    171       1.1  augustss };
    172       1.1  augustss #endif
    173       1.1  augustss 
    174      1.22   thorpej CFATTACH_DECL(clcs, sizeof(struct cs428x_softc),
    175      1.23   thorpej     cs4280_match, cs4280_attach, NULL, NULL);
    176       1.1  augustss 
    177       1.1  augustss struct audio_device cs4280_device = {
    178       1.1  augustss 	"CS4280",
    179       1.1  augustss 	"",
    180       1.1  augustss 	"cs4280"
    181       1.1  augustss };
    182       1.1  augustss 
    183       1.1  augustss 
    184       1.1  augustss int
    185       1.1  augustss cs4280_match(parent, match, aux)
    186       1.1  augustss 	struct device *parent;
    187       1.1  augustss 	struct cfdata *match;
    188       1.1  augustss 	void *aux;
    189       1.1  augustss {
    190       1.1  augustss 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    191       1.1  augustss 
    192       1.1  augustss 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_CIRRUS)
    193      1.14     tacha 		return 0;
    194       1.1  augustss 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CIRRUS_CS4280
    195       1.1  augustss #if 0  /* I can't confirm */
    196       1.1  augustss 	    || PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CIRRUS_CS4610
    197       1.1  augustss #endif
    198       1.6  augustss 	    )
    199      1.14     tacha 		return 1;
    200      1.14     tacha 	return 0;
    201       1.1  augustss }
    202       1.1  augustss 
    203       1.1  augustss void
    204       1.1  augustss cs4280_attach(parent, self, aux)
    205       1.1  augustss 	struct device *parent;
    206       1.1  augustss 	struct device *self;
    207       1.1  augustss 	void *aux;
    208       1.1  augustss {
    209      1.14     tacha 	struct cs428x_softc *sc = (struct cs428x_softc *)self;
    210       1.1  augustss 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
    211       1.1  augustss 	pci_chipset_tag_t pc = pa->pa_pc;
    212       1.1  augustss 	char const *intrstr;
    213       1.1  augustss 	pci_intr_handle_t ih;
    214      1.15     tacha 	pcireg_t reg;
    215       1.1  augustss 	char devinfo[256];
    216       1.1  augustss 	u_int32_t mem;
    217      1.15     tacha 	int pci_pwrmgmt_cap_reg, pci_pwrmgmt_csr_reg;
    218      1.14     tacha 
    219      1.25   thorpej 	aprint_naive(": Audio controller\n");
    220      1.25   thorpej 
    221      1.27    itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    222      1.25   thorpej 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
    223      1.25   thorpej 	    PCI_REVISION(pa->pa_class));
    224       1.1  augustss 
    225       1.1  augustss 	/* Map I/O register */
    226      1.14     tacha 	if (pci_mapreg_map(pa, PCI_BA0,
    227      1.14     tacha 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
    228      1.14     tacha 	    &sc->ba0t, &sc->ba0h, NULL, NULL)) {
    229      1.25   thorpej 		aprint_error("%s: can't map BA0 space\n", sc->sc_dev.dv_xname);
    230       1.1  augustss 		return;
    231       1.1  augustss 	}
    232      1.14     tacha 	if (pci_mapreg_map(pa, PCI_BA1,
    233      1.14     tacha 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
    234      1.14     tacha 	    &sc->ba1t, &sc->ba1h, NULL, NULL)) {
    235      1.25   thorpej 		aprint_error("%s: can't map BA1 space\n", sc->sc_dev.dv_xname);
    236       1.1  augustss 		return;
    237       1.1  augustss 	}
    238       1.1  augustss 
    239       1.1  augustss 	sc->sc_dmatag = pa->pa_dmat;
    240       1.1  augustss 
    241      1.15     tacha 	/* Check and set Power State */
    242      1.15     tacha 	if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_PWRMGMT,
    243      1.15     tacha 	    &pci_pwrmgmt_cap_reg, 0)) {
    244      1.24   tsutsui 		pci_pwrmgmt_csr_reg = pci_pwrmgmt_cap_reg + PCI_PMCSR;
    245      1.15     tacha 		reg = pci_conf_read(pa->pa_pc, pa->pa_tag,
    246      1.15     tacha 		    pci_pwrmgmt_csr_reg);
    247      1.15     tacha 		DPRINTF(("%s: Power State is %d\n",
    248      1.15     tacha 		    sc->sc_dev.dv_xname, reg & PCI_PMCSR_STATE_MASK));
    249      1.15     tacha 		if ((reg & PCI_PMCSR_STATE_MASK) != PCI_PMCSR_STATE_D0) {
    250      1.15     tacha 			pci_conf_write(pc, pa->pa_tag, pci_pwrmgmt_csr_reg,
    251      1.15     tacha 			    (reg & ~PCI_PMCSR_STATE_MASK) |
    252      1.15     tacha 			    PCI_PMCSR_STATE_D0);
    253      1.15     tacha 		}
    254      1.15     tacha 	}
    255      1.15     tacha 
    256       1.1  augustss 	/* Enable the device (set bus master flag) */
    257      1.15     tacha 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    258       1.1  augustss 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    259      1.15     tacha 		       reg | PCI_COMMAND_MASTER_ENABLE);
    260       1.1  augustss 
    261       1.1  augustss 	/* LATENCY_TIMER setting */
    262       1.1  augustss 	mem = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
    263       1.1  augustss 	if ( PCI_LATTIMER(mem) < 32 ) {
    264       1.1  augustss 		mem &= 0xffff00ff;
    265       1.1  augustss 		mem |= 0x00002000;
    266       1.1  augustss 		pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG, mem);
    267       1.1  augustss 	}
    268       1.1  augustss 
    269       1.1  augustss 	/* Map and establish the interrupt. */
    270       1.9  sommerfe 	if (pci_intr_map(pa, &ih)) {
    271      1.25   thorpej 		aprint_error("%s: couldn't map interrupt\n",
    272      1.25   thorpej 		    sc->sc_dev.dv_xname);
    273       1.1  augustss 		return;
    274       1.1  augustss 	}
    275       1.1  augustss 	intrstr = pci_intr_string(pc, ih);
    276       1.1  augustss 
    277       1.1  augustss 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_AUDIO, cs4280_intr, sc);
    278       1.1  augustss 	if (sc->sc_ih == NULL) {
    279      1.25   thorpej 		aprint_error("%s: couldn't establish interrupt",
    280      1.25   thorpej 		    sc->sc_dev.dv_xname);
    281       1.1  augustss 		if (intrstr != NULL)
    282      1.25   thorpej 			aprint_normal(" at %s", intrstr);
    283      1.25   thorpej 		aprint_normal("\n");
    284       1.1  augustss 		return;
    285       1.1  augustss 	}
    286      1.25   thorpej 	aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    287       1.1  augustss 
    288       1.1  augustss 	/* Initialization */
    289       1.2  augustss 	if(cs4280_init(sc, 1) != 0)
    290       1.2  augustss 		return;
    291       1.1  augustss 
    292      1.14     tacha 	sc->type = TYPE_CS4280;
    293      1.14     tacha 	sc->halt_input  = cs4280_halt_input;
    294      1.14     tacha 	sc->halt_output = cs4280_halt_output;
    295      1.14     tacha 
    296      1.14     tacha 	/* setup buffer related parameters */
    297      1.14     tacha 	sc->dma_size     = CS4280_DCHUNK;
    298      1.14     tacha 	sc->dma_align    = CS4280_DALIGN;
    299      1.14     tacha 	sc->hw_blocksize = CS4280_ICHUNK;
    300      1.14     tacha 
    301      1.14     tacha 	/* AC 97 attachment */
    302       1.1  augustss 	sc->host_if.arg = sc;
    303      1.14     tacha 	sc->host_if.attach = cs428x_attach_codec;
    304      1.14     tacha 	sc->host_if.read   = cs428x_read_codec;
    305      1.14     tacha 	sc->host_if.write  = cs428x_write_codec;
    306       1.1  augustss 	sc->host_if.reset  = cs4280_reset_codec;
    307  1.32.2.1      kent 	if (ac97_attach(&sc->host_if, self) != 0) {
    308      1.25   thorpej 		aprint_error("%s: ac97_attach failed\n", sc->sc_dev.dv_xname);
    309       1.1  augustss 		return;
    310       1.1  augustss 	}
    311       1.1  augustss 
    312       1.1  augustss 	audio_attach_mi(&cs4280_hw_if, sc, &sc->sc_dev);
    313       1.2  augustss 
    314       1.1  augustss #if NMIDI > 0
    315       1.1  augustss 	midi_attach_mi(&cs4280_midi_hw_if, sc, &sc->sc_dev);
    316       1.1  augustss #endif
    317      1.14     tacha 
    318       1.1  augustss 	sc->sc_suspend = PWR_RESUME;
    319       1.1  augustss 	sc->sc_powerhook = powerhook_establish(cs4280_power, sc);
    320       1.1  augustss }
    321       1.1  augustss 
    322      1.14     tacha /* Interrupt handling function */
    323       1.1  augustss int
    324       1.1  augustss cs4280_intr(p)
    325       1.1  augustss 	void *p;
    326       1.1  augustss {
    327       1.1  augustss 	/*
    328       1.1  augustss 	 * XXX
    329       1.1  augustss 	 *
    330      1.26       wiz 	 * Since CS4280 has only 4kB DMA buffer and
    331       1.1  augustss 	 * interrupt occurs every 2kB block, I create dummy buffer
    332      1.26       wiz 	 * which returns to audio driver and actual DMA buffer
    333       1.1  augustss 	 * using in DMA transfer.
    334       1.1  augustss 	 *
    335       1.1  augustss 	 *
    336       1.1  augustss 	 *  ring buffer in audio.c is pointed by BUFADDR
    337       1.1  augustss 	 *	 <------ ring buffer size == 64kB ------>
    338       1.1  augustss 	 *	 <-----> blksize == 2048*(sc->sc_[pr]count) kB
    339       1.1  augustss 	 *	|= = = =|= = = =|= = = =|= = = =|= = = =|
    340       1.1  augustss 	 *	|	|	|	|	|	| <- call audio_intp every
    341       1.1  augustss 	 *						     sc->sc_[pr]_count time.
    342       1.1  augustss 	 *
    343      1.26       wiz 	 *  actual DMA buffer is pointed by KERNADDR
    344      1.26       wiz 	 *	 <-> DMA buffer size = 4kB
    345       1.1  augustss 	 *	|= =|
    346       1.1  augustss 	 *
    347       1.1  augustss 	 *
    348       1.1  augustss 	 */
    349      1.14     tacha 	struct cs428x_softc *sc = p;
    350       1.1  augustss 	u_int32_t intr, mem;
    351       1.1  augustss 	char * empty_dma;
    352      1.10     perry 	int handled = 0;
    353       1.1  augustss 
    354       1.7  augustss 	/* grab interrupt register then clear it */
    355       1.1  augustss 	intr = BA0READ4(sc, CS4280_HISR);
    356       1.7  augustss 	BA0WRITE4(sc, CS4280_HICR, HICR_CHGM | HICR_IEV);
    357       1.7  augustss 
    358       1.1  augustss 	/* Playback Interrupt */
    359       1.1  augustss 	if (intr & HISR_PINT) {
    360      1.10     perry 		handled = 1;
    361       1.1  augustss 		mem = BA1READ4(sc, CS4280_PFIE);
    362       1.1  augustss 		BA1WRITE4(sc, CS4280_PFIE, (mem & ~PFIE_PI_MASK) | PFIE_PI_DISABLE);
    363      1.28   mycroft 		if (sc->sc_prun) {
    364       1.1  augustss 			if ((sc->sc_pi%sc->sc_pcount) == 0)
    365       1.1  augustss 				sc->sc_pintr(sc->sc_parg);
    366       1.1  augustss 		} else {
    367       1.1  augustss 			printf("unexpected play intr\n");
    368       1.1  augustss 		}
    369       1.1  augustss 		/* copy buffer */
    370       1.1  augustss 		++sc->sc_pi;
    371       1.1  augustss 		empty_dma = sc->sc_pdma->addr;
    372       1.1  augustss 		if (sc->sc_pi&1)
    373      1.14     tacha 			empty_dma += sc->hw_blocksize;
    374      1.14     tacha 		memcpy(empty_dma, sc->sc_pn, sc->hw_blocksize);
    375      1.14     tacha 		sc->sc_pn += sc->hw_blocksize;
    376       1.1  augustss 		if (sc->sc_pn >= sc->sc_pe)
    377       1.1  augustss 			sc->sc_pn = sc->sc_ps;
    378       1.1  augustss 		BA1WRITE4(sc, CS4280_PFIE, mem);
    379       1.1  augustss 	}
    380       1.1  augustss 	/* Capture Interrupt */
    381       1.1  augustss 	if (intr & HISR_CINT) {
    382       1.1  augustss 		int  i;
    383       1.1  augustss 		int16_t rdata;
    384       1.1  augustss 
    385      1.10     perry 		handled = 1;
    386       1.1  augustss 		mem = BA1READ4(sc, CS4280_CIE);
    387       1.1  augustss 		BA1WRITE4(sc, CS4280_CIE, (mem & ~CIE_CI_MASK) | CIE_CI_DISABLE);
    388       1.1  augustss 		++sc->sc_ri;
    389       1.1  augustss 		empty_dma = sc->sc_rdma->addr;
    390       1.1  augustss 		if ((sc->sc_ri&1) == 0)
    391      1.14     tacha 			empty_dma += sc->hw_blocksize;
    392       1.1  augustss 
    393       1.1  augustss 		/*
    394       1.1  augustss 		 * XXX
    395       1.1  augustss 		 * I think this audio data conversion should be
    396       1.1  augustss 		 * happend in upper layer, but I put this here
    397       1.1  augustss 		 * since there is no conversion function available.
    398       1.1  augustss 		 */
    399       1.1  augustss 		switch(sc->sc_rparam) {
    400       1.1  augustss 		case CF_16BIT_STEREO:
    401       1.1  augustss 			/* just copy it */
    402      1.14     tacha 			memcpy(sc->sc_rn, empty_dma, sc->hw_blocksize);
    403      1.14     tacha 			sc->sc_rn += sc->hw_blocksize;
    404       1.1  augustss 			break;
    405       1.1  augustss 		case CF_16BIT_MONO:
    406       1.1  augustss 			for (i = 0; i < 512; i++) {
    407      1.29  drochner 				rdata  = *((int16_t *)empty_dma)>>1;
    408      1.29  drochner 				empty_dma += 2;
    409      1.29  drochner 				rdata += *((int16_t *)empty_dma)>>1;
    410      1.29  drochner 				empty_dma += 2;
    411      1.29  drochner 				*((int16_t *)sc->sc_rn) = rdata;
    412      1.29  drochner 				sc->sc_rn += 2;
    413       1.1  augustss 			}
    414       1.1  augustss 			break;
    415       1.1  augustss 		case CF_8BIT_STEREO:
    416       1.1  augustss 			for (i = 0; i < 512; i++) {
    417      1.29  drochner 				rdata = *((int16_t*)empty_dma);
    418      1.29  drochner 				empty_dma += 2;
    419       1.1  augustss 				*sc->sc_rn++ = rdata >> 8;
    420      1.29  drochner 				rdata = *((int16_t*)empty_dma);
    421      1.29  drochner 				empty_dma += 2;
    422       1.1  augustss 				*sc->sc_rn++ = rdata >> 8;
    423       1.1  augustss 			}
    424       1.1  augustss 			break;
    425       1.1  augustss 		case CF_8BIT_MONO:
    426       1.1  augustss 			for (i = 0; i < 512; i++) {
    427      1.29  drochner 				rdata =	 *((int16_t*)empty_dma) >>1;
    428      1.29  drochner 				empty_dma += 2;
    429      1.29  drochner 				rdata += *((int16_t*)empty_dma) >>1;
    430      1.29  drochner 				empty_dma += 2;
    431       1.1  augustss 				*sc->sc_rn++ = rdata >>8;
    432       1.1  augustss 			}
    433       1.1  augustss 			break;
    434       1.1  augustss 		default:
    435       1.1  augustss 			/* Should not reach here */
    436       1.1  augustss 			printf("unknown sc->sc_rparam: %d\n", sc->sc_rparam);
    437       1.1  augustss 		}
    438       1.1  augustss 		if (sc->sc_rn >= sc->sc_re)
    439       1.1  augustss 			sc->sc_rn = sc->sc_rs;
    440       1.1  augustss 		BA1WRITE4(sc, CS4280_CIE, mem);
    441      1.28   mycroft 		if (sc->sc_rrun) {
    442       1.1  augustss 			if ((sc->sc_ri%(sc->sc_rcount)) == 0)
    443       1.1  augustss 				sc->sc_rintr(sc->sc_rarg);
    444       1.1  augustss 		} else {
    445       1.1  augustss 			printf("unexpected record intr\n");
    446       1.1  augustss 		}
    447       1.1  augustss 	}
    448       1.1  augustss 
    449       1.1  augustss #if NMIDI > 0
    450       1.1  augustss 	/* Midi port Interrupt */
    451       1.1  augustss 	if (intr & HISR_MIDI) {
    452       1.2  augustss 		int data;
    453       1.2  augustss 
    454      1.10     perry 		handled = 1;
    455       1.2  augustss 		DPRINTF(("i: %d: ",
    456       1.2  augustss 			 BA0READ4(sc, CS4280_MIDSR)));
    457       1.2  augustss 		/* Read the received data */
    458       1.2  augustss 		while ((sc->sc_iintr != NULL) &&
    459       1.2  augustss 		       ((BA0READ4(sc, CS4280_MIDSR) & MIDSR_RBE) == 0)) {
    460       1.2  augustss 			data = BA0READ4(sc, CS4280_MIDRP) & MIDRP_MASK;
    461       1.2  augustss 			DPRINTF(("r:%x\n",data));
    462       1.2  augustss 			sc->sc_iintr(sc->sc_arg, data);
    463       1.2  augustss 		}
    464       1.2  augustss 
    465       1.2  augustss 		/* Write the data */
    466       1.2  augustss #if 1
    467       1.2  augustss 		/* XXX:
    468       1.2  augustss 		 * It seems "Transmit Buffer Full" never activate until EOI
    469       1.2  augustss 		 * is deliverd.  Shall I throw EOI top of this routine ?
    470       1.2  augustss 		 */
    471       1.2  augustss 		if ((BA0READ4(sc, CS4280_MIDSR) & MIDSR_TBF) == 0) {
    472       1.2  augustss 			DPRINTF(("w: "));
    473       1.2  augustss 			if (sc->sc_ointr != NULL)
    474       1.2  augustss 				sc->sc_ointr(sc->sc_arg);
    475       1.2  augustss 		}
    476       1.2  augustss #else
    477       1.2  augustss 		while ((sc->sc_ointr != NULL) &&
    478       1.2  augustss 		       ((BA0READ4(sc, CS4280_MIDSR) & MIDSR_TBF) == 0)) {
    479       1.2  augustss 			DPRINTF(("w: "));
    480       1.2  augustss 			sc->sc_ointr(sc->sc_arg);
    481       1.2  augustss 		}
    482       1.2  augustss #endif
    483       1.2  augustss 		DPRINTF(("\n"));
    484       1.1  augustss 	}
    485       1.1  augustss #endif
    486       1.7  augustss 
    487      1.14     tacha 	return handled;
    488       1.1  augustss }
    489       1.1  augustss 
    490       1.1  augustss int
    491      1.14     tacha cs4280_query_encoding(addr, fp)
    492      1.14     tacha 	void *addr;
    493      1.14     tacha 	struct audio_encoding *fp;
    494       1.1  augustss {
    495      1.14     tacha 	switch (fp->index) {
    496      1.14     tacha 	case 0:
    497      1.14     tacha 		strcpy(fp->name, AudioEulinear);
    498      1.14     tacha 		fp->encoding = AUDIO_ENCODING_ULINEAR;
    499      1.14     tacha 		fp->precision = 8;
    500      1.14     tacha 		fp->flags = 0;
    501       1.1  augustss 		break;
    502       1.1  augustss 	case 1:
    503       1.1  augustss 		strcpy(fp->name, AudioEmulaw);
    504       1.1  augustss 		fp->encoding = AUDIO_ENCODING_ULAW;
    505       1.1  augustss 		fp->precision = 8;
    506       1.1  augustss 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    507       1.1  augustss 		break;
    508       1.1  augustss 	case 2:
    509       1.1  augustss 		strcpy(fp->name, AudioEalaw);
    510       1.1  augustss 		fp->encoding = AUDIO_ENCODING_ALAW;
    511       1.1  augustss 		fp->precision = 8;
    512       1.1  augustss 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
    513       1.1  augustss 		break;
    514       1.1  augustss 	case 3:
    515       1.1  augustss 		strcpy(fp->name, AudioEslinear);
    516       1.1  augustss 		fp->encoding = AUDIO_ENCODING_SLINEAR;
    517       1.1  augustss 		fp->precision = 8;
    518       1.1  augustss 		fp->flags = 0;
    519       1.1  augustss 		break;
    520       1.1  augustss 	case 4:
    521       1.1  augustss 		strcpy(fp->name, AudioEslinear_le);
    522       1.1  augustss 		fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
    523       1.1  augustss 		fp->precision = 16;
    524       1.1  augustss 		fp->flags = 0;
    525       1.1  augustss 		break;
    526       1.1  augustss 	case 5:
    527       1.1  augustss 		strcpy(fp->name, AudioEulinear_le);
    528       1.1  augustss 		fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
    529       1.1  augustss 		fp->precision = 16;
    530       1.1  augustss 		fp->flags = 0;
    531       1.1  augustss 		break;
    532       1.1  augustss 	case 6:
    533       1.1  augustss 		strcpy(fp->name, AudioEslinear_be);
    534       1.1  augustss 		fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
    535       1.1  augustss 		fp->precision = 16;
    536       1.1  augustss 		fp->flags = 0;
    537       1.1  augustss 		break;
    538       1.1  augustss 	case 7:
    539       1.1  augustss 		strcpy(fp->name, AudioEulinear_be);
    540       1.1  augustss 		fp->encoding = AUDIO_ENCODING_ULINEAR_BE;
    541       1.1  augustss 		fp->precision = 16;
    542       1.1  augustss 		fp->flags = 0;
    543       1.1  augustss 		break;
    544       1.1  augustss 	default:
    545      1.14     tacha 		return EINVAL;
    546       1.1  augustss 	}
    547      1.14     tacha 	return 0;
    548       1.1  augustss }
    549       1.1  augustss 
    550       1.1  augustss int
    551  1.32.2.1      kent cs4280_set_params(void *addr, int setmode, int usemode,
    552  1.32.2.1      kent 		  audio_params_t *play, audio_params_t *rec,
    553  1.32.2.1      kent 		  stream_filter_list_t *pfil, stream_filter_list_t *rfil)
    554       1.1  augustss {
    555  1.32.2.1      kent 	audio_params_t hw;
    556      1.14     tacha 	struct cs428x_softc *sc = addr;
    557       1.1  augustss 	struct audio_params *p;
    558  1.32.2.1      kent 	stream_filter_list_t *fil;
    559       1.1  augustss 	int mode;
    560       1.1  augustss 
    561       1.1  augustss 	for (mode = AUMODE_RECORD; mode != -1;
    562       1.1  augustss 	    mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1 ) {
    563       1.1  augustss 		if ((setmode & mode) == 0)
    564       1.1  augustss 			continue;
    565  1.32.2.1      kent 
    566       1.1  augustss 		p = mode == AUMODE_PLAY ? play : rec;
    567  1.32.2.1      kent 
    568       1.1  augustss 		if (p == play) {
    569       1.1  augustss 			DPRINTFN(5,("play: sample=%ld precision=%d channels=%d\n",
    570       1.1  augustss 				p->sample_rate, p->precision, p->channels));
    571       1.1  augustss 			/* play back data format may be 8- or 16-bit and
    572       1.1  augustss 			 * either stereo or mono.
    573       1.1  augustss 			 * playback rate may range from 8000Hz to 48000Hz
    574       1.1  augustss 			 */
    575       1.1  augustss 			if (p->sample_rate < 8000 || p->sample_rate > 48000 ||
    576       1.1  augustss 			    (p->precision != 8 && p->precision != 16) ||
    577       1.1  augustss 			    (p->channels != 1  && p->channels != 2) ) {
    578      1.14     tacha 				return EINVAL;
    579       1.1  augustss 			}
    580       1.1  augustss 		} else {
    581       1.1  augustss 			DPRINTFN(5,("rec: sample=%ld precision=%d channels=%d\n",
    582       1.1  augustss 				p->sample_rate, p->precision, p->channels));
    583       1.1  augustss 			/* capture data format must be 16bit stereo
    584       1.1  augustss 			 * and sample rate range from 11025Hz to 48000Hz.
    585       1.1  augustss 			 *
    586       1.1  augustss 			 * XXX: it looks like to work with 8000Hz,
    587       1.1  augustss 			 *	although data sheets say lower limit is
    588       1.1  augustss 			 *	11025 Hz.
    589       1.1  augustss 			 */
    590       1.1  augustss 
    591       1.1  augustss 			if (p->sample_rate < 8000 || p->sample_rate > 48000 ||
    592       1.1  augustss 			    (p->precision != 8 && p->precision != 16) ||
    593       1.1  augustss 			    (p->channels  != 1 && p->channels  != 2) ) {
    594      1.14     tacha 				return EINVAL;
    595       1.1  augustss 			}
    596       1.1  augustss 		}
    597  1.32.2.1      kent 		fil = mode == AUMODE_PLAY ? pfil : rfil;
    598  1.32.2.1      kent 		hw = *p;
    599  1.32.2.1      kent 		hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
    600       1.1  augustss 
    601       1.1  augustss 		/* capturing data is slinear */
    602       1.1  augustss 		switch (p->encoding) {
    603       1.1  augustss 		case AUDIO_ENCODING_SLINEAR_BE:
    604  1.32.2.1      kent 			if (mode == AUMODE_RECORD && p->precision == 16) {
    605  1.32.2.2      kent 				fil->append(fil, swap_bytes, &hw);
    606       1.1  augustss 			}
    607       1.1  augustss 			break;
    608       1.1  augustss 		case AUDIO_ENCODING_SLINEAR_LE:
    609       1.1  augustss 			break;
    610       1.1  augustss 		case AUDIO_ENCODING_ULINEAR_BE:
    611       1.1  augustss 			if (mode == AUMODE_RECORD) {
    612  1.32.2.2      kent 				fil->append(fil, p->precision == 16
    613  1.32.2.2      kent 					    ? swap_bytes_change_sign16
    614  1.32.2.2      kent 					    : change_sign8, &hw);
    615       1.1  augustss 			}
    616       1.1  augustss 			break;
    617       1.1  augustss 		case AUDIO_ENCODING_ULINEAR_LE:
    618       1.1  augustss 			if (mode == AUMODE_RECORD) {
    619  1.32.2.2      kent 				fil->append(fil, p->precision == 16
    620  1.32.2.2      kent 					    ? change_sign16 : change_sign8,
    621  1.32.2.2      kent 					    &hw);
    622       1.1  augustss 			}
    623       1.1  augustss 			break;
    624       1.1  augustss 		case AUDIO_ENCODING_ULAW:
    625       1.1  augustss 			if (mode == AUMODE_PLAY) {
    626  1.32.2.1      kent 				hw.precision = 16;
    627  1.32.2.1      kent 				hw.validbits = 16;
    628  1.32.2.2      kent 				fil->append(fil, mulaw_to_linear16, &hw);
    629       1.1  augustss 			} else {
    630  1.32.2.2      kent 				fil->append(fil, linear8_to_mulaw, &hw);
    631       1.1  augustss 			}
    632       1.1  augustss 			break;
    633       1.1  augustss 		case AUDIO_ENCODING_ALAW:
    634       1.1  augustss 			if (mode == AUMODE_PLAY) {
    635  1.32.2.1      kent 				hw.precision = 16;
    636  1.32.2.1      kent 				hw.validbits = 16;
    637  1.32.2.2      kent 				fil->append(fil, alaw_to_linear16, &hw);
    638       1.1  augustss 			} else {
    639  1.32.2.2      kent 				fil->append(fil, linear8_to_alaw, &hw);
    640       1.1  augustss 			}
    641       1.1  augustss 			break;
    642       1.1  augustss 		default:
    643      1.14     tacha 			return EINVAL;
    644       1.1  augustss 		}
    645       1.1  augustss 	}
    646       1.1  augustss 
    647       1.1  augustss 	/* set sample rate */
    648       1.1  augustss 	cs4280_set_dac_rate(sc, play->sample_rate);
    649       1.1  augustss 	cs4280_set_adc_rate(sc, rec->sample_rate);
    650      1.14     tacha 	return 0;
    651       1.1  augustss }
    652       1.1  augustss 
    653       1.1  augustss int
    654       1.1  augustss cs4280_halt_output(addr)
    655       1.1  augustss 	void *addr;
    656       1.1  augustss {
    657      1.14     tacha 	struct cs428x_softc *sc = addr;
    658       1.1  augustss 	u_int32_t mem;
    659  1.32.2.1      kent 
    660       1.1  augustss 	mem = BA1READ4(sc, CS4280_PCTL);
    661       1.1  augustss 	BA1WRITE4(sc, CS4280_PCTL, mem & ~PCTL_MASK);
    662       1.1  augustss 	sc->sc_prun = 0;
    663      1.14     tacha 	return 0;
    664       1.1  augustss }
    665       1.1  augustss 
    666       1.1  augustss int
    667       1.1  augustss cs4280_halt_input(addr)
    668       1.1  augustss 	void *addr;
    669       1.1  augustss {
    670      1.14     tacha 	struct cs428x_softc *sc = addr;
    671       1.1  augustss 	u_int32_t mem;
    672       1.1  augustss 
    673       1.1  augustss 	mem = BA1READ4(sc, CS4280_CCTL);
    674       1.1  augustss 	BA1WRITE4(sc, CS4280_CCTL, mem & ~CCTL_MASK);
    675       1.1  augustss 	sc->sc_rrun = 0;
    676      1.14     tacha 	return 0;
    677       1.1  augustss }
    678       1.1  augustss 
    679       1.1  augustss int
    680       1.1  augustss cs4280_getdev(addr, retp)
    681       1.1  augustss 	void *addr;
    682       1.1  augustss 	struct audio_device *retp;
    683       1.1  augustss {
    684       1.1  augustss 	*retp = cs4280_device;
    685      1.14     tacha 	return 0;
    686       1.1  augustss }
    687       1.1  augustss 
    688       1.1  augustss int
    689      1.14     tacha cs4280_trigger_output(addr, start, end, blksize, intr, arg, param)
    690       1.1  augustss 	void *addr;
    691      1.14     tacha 	void *start, *end;
    692      1.14     tacha 	int blksize;
    693      1.14     tacha 	void (*intr) __P((void *));
    694      1.14     tacha 	void *arg;
    695  1.32.2.1      kent 	const audio_params_t *param;
    696       1.1  augustss {
    697      1.14     tacha 	struct cs428x_softc *sc = addr;
    698      1.14     tacha 	u_int32_t pfie, pctl, pdtc;
    699      1.14     tacha 	struct cs428x_dma *p;
    700  1.32.2.1      kent 
    701      1.14     tacha #ifdef DIAGNOSTIC
    702      1.14     tacha 	if (sc->sc_prun)
    703      1.14     tacha 		printf("cs4280_trigger_output: already running\n");
    704      1.16     tacha #endif
    705      1.14     tacha 	sc->sc_prun = 1;
    706       1.1  augustss 
    707      1.14     tacha 	DPRINTF(("cs4280_trigger_output: sc=%p start=%p end=%p "
    708      1.14     tacha 	    "blksize=%d intr=%p(%p)\n", addr, start, end, blksize, intr, arg));
    709      1.14     tacha 	sc->sc_pintr = intr;
    710      1.14     tacha 	sc->sc_parg  = arg;
    711       1.1  augustss 
    712      1.14     tacha 	/* stop playback DMA */
    713      1.14     tacha 	BA1WRITE4(sc, CS4280_PCTL, BA1READ4(sc, CS4280_PCTL) & ~PCTL_MASK);
    714       1.1  augustss 
    715      1.14     tacha 	/* setup PDTC */
    716      1.14     tacha 	pdtc = BA1READ4(sc, CS4280_PDTC);
    717      1.14     tacha 	pdtc &= ~PDTC_MASK;
    718      1.14     tacha 	pdtc |= CS4280_MK_PDTC(param->precision * param->channels);
    719      1.14     tacha 	BA1WRITE4(sc, CS4280_PDTC, pdtc);
    720  1.32.2.1      kent 
    721  1.32.2.1      kent 	DPRINTF(("param: precision=%d channels=%d encoding=%d\n",
    722  1.32.2.1      kent 	       param->precision, param->channels, param->encoding));
    723      1.14     tacha 	for (p = sc->sc_dmas; p != NULL && BUFADDR(p) != start; p = p->next)
    724      1.14     tacha 		;
    725      1.14     tacha 	if (p == NULL) {
    726      1.14     tacha 		printf("cs4280_trigger_output: bad addr %p\n", start);
    727      1.14     tacha 		return EINVAL;
    728      1.14     tacha 	}
    729      1.14     tacha 	if (DMAADDR(p) % sc->dma_align != 0 ) {
    730      1.14     tacha 		printf("cs4280_trigger_output: DMAADDR(p)=0x%lx does not start"
    731      1.20  augustss 		       "4kB align\n", (ulong)DMAADDR(p));
    732      1.14     tacha 		return EINVAL;
    733      1.14     tacha 	}
    734      1.14     tacha 
    735      1.14     tacha 	sc->sc_pcount = blksize / sc->hw_blocksize; /* sc->hw_blocksize is fixed hardware blksize*/
    736      1.14     tacha 	sc->sc_ps = (char *)start;
    737      1.14     tacha 	sc->sc_pe = (char *)end;
    738      1.14     tacha 	sc->sc_pdma = p;
    739      1.14     tacha 	sc->sc_pbuf = KERNADDR(p);
    740      1.14     tacha 	sc->sc_pi = 0;
    741      1.14     tacha 	sc->sc_pn = sc->sc_ps;
    742      1.14     tacha 	if (blksize >= sc->dma_size) {
    743      1.14     tacha 		sc->sc_pn = sc->sc_ps + sc->dma_size;
    744      1.14     tacha 		memcpy(sc->sc_pbuf, start, sc->dma_size);
    745      1.14     tacha 		++sc->sc_pi;
    746      1.14     tacha 	} else {
    747      1.14     tacha 		sc->sc_pn = sc->sc_ps + sc->hw_blocksize;
    748      1.14     tacha 		memcpy(sc->sc_pbuf, start, sc->hw_blocksize);
    749      1.14     tacha 	}
    750      1.14     tacha 
    751      1.26       wiz 	/* initiate playback DMA */
    752      1.14     tacha 	BA1WRITE4(sc, CS4280_PBA, DMAADDR(p));
    753      1.14     tacha 
    754      1.14     tacha 	/* set PFIE */
    755      1.14     tacha 	pfie = BA1READ4(sc, CS4280_PFIE) & ~PFIE_MASK;
    756      1.14     tacha 
    757  1.32.2.1      kent 	if (param->precision == 8)
    758      1.14     tacha 		pfie |= PFIE_8BIT;
    759      1.14     tacha 	if (param->channels == 1)
    760      1.14     tacha 		pfie |= PFIE_MONO;
    761      1.14     tacha 
    762      1.14     tacha 	if (param->encoding == AUDIO_ENCODING_ULINEAR_BE ||
    763      1.14     tacha 	    param->encoding == AUDIO_ENCODING_SLINEAR_BE)
    764      1.14     tacha 		pfie |= PFIE_SWAPPED;
    765      1.14     tacha 	if (param->encoding == AUDIO_ENCODING_ULINEAR_BE ||
    766      1.14     tacha 	    param->encoding == AUDIO_ENCODING_ULINEAR_LE)
    767      1.14     tacha 		pfie |= PFIE_UNSIGNED;
    768      1.14     tacha 
    769      1.14     tacha 	BA1WRITE4(sc, CS4280_PFIE, pfie | PFIE_PI_ENABLE);
    770      1.14     tacha 
    771      1.16     tacha 	sc->sc_prate = param->sample_rate;
    772      1.14     tacha 	cs4280_set_dac_rate(sc, param->sample_rate);
    773      1.14     tacha 
    774      1.14     tacha 	pctl = BA1READ4(sc, CS4280_PCTL) & ~PCTL_MASK;
    775      1.14     tacha 	pctl |= sc->pctl;
    776      1.14     tacha 	BA1WRITE4(sc, CS4280_PCTL, pctl);
    777      1.14     tacha 	return 0;
    778      1.14     tacha }
    779       1.1  augustss 
    780       1.1  augustss int
    781      1.14     tacha cs4280_trigger_input(addr, start, end, blksize, intr, arg, param)
    782      1.14     tacha 	void *addr;
    783      1.14     tacha 	void *start, *end;
    784      1.14     tacha 	int blksize;
    785      1.14     tacha 	void (*intr) __P((void *));
    786      1.14     tacha 	void *arg;
    787  1.32.2.1      kent 	const audio_params_t *param;
    788      1.14     tacha {
    789      1.14     tacha 	struct cs428x_softc *sc = addr;
    790      1.14     tacha 	u_int32_t cctl, cie;
    791      1.14     tacha 	struct cs428x_dma *p;
    792  1.32.2.1      kent 
    793      1.14     tacha #ifdef DIAGNOSTIC
    794      1.14     tacha 	if (sc->sc_rrun)
    795      1.14     tacha 		printf("cs4280_trigger_input: already running\n");
    796      1.16     tacha #endif
    797      1.14     tacha 	sc->sc_rrun = 1;
    798      1.16     tacha 
    799      1.14     tacha 	DPRINTF(("cs4280_trigger_input: sc=%p start=%p end=%p "
    800      1.14     tacha 	    "blksize=%d intr=%p(%p)\n", addr, start, end, blksize, intr, arg));
    801      1.14     tacha 	sc->sc_rintr = intr;
    802      1.14     tacha 	sc->sc_rarg  = arg;
    803      1.14     tacha 
    804      1.14     tacha 	/* stop capture DMA */
    805      1.14     tacha 	BA1WRITE4(sc, CS4280_CCTL, BA1READ4(sc, CS4280_CCTL) & ~CCTL_MASK);
    806  1.32.2.1      kent 
    807      1.14     tacha 	for (p = sc->sc_dmas; p && BUFADDR(p) != start; p = p->next)
    808      1.14     tacha 		;
    809      1.14     tacha 	if (p == NULL) {
    810      1.14     tacha 		printf("cs4280_trigger_input: bad addr %p\n", start);
    811      1.14     tacha 		return EINVAL;
    812      1.14     tacha 	}
    813      1.14     tacha 	if (DMAADDR(p) % sc->dma_align != 0) {
    814      1.14     tacha 		printf("cs4280_trigger_input: DMAADDR(p)=0x%lx does not start"
    815      1.20  augustss 		       "4kB align\n", (ulong)DMAADDR(p));
    816      1.14     tacha 		return EINVAL;
    817      1.14     tacha 	}
    818      1.14     tacha 
    819      1.14     tacha 	sc->sc_rcount = blksize / sc->hw_blocksize; /* sc->hw_blocksize is fixed hardware blksize*/
    820      1.14     tacha 	sc->sc_rs = (char *)start;
    821      1.14     tacha 	sc->sc_re = (char *)end;
    822      1.14     tacha 	sc->sc_rdma = p;
    823      1.14     tacha 	sc->sc_rbuf = KERNADDR(p);
    824      1.14     tacha 	sc->sc_ri = 0;
    825      1.14     tacha 	sc->sc_rn = sc->sc_rs;
    826      1.14     tacha 
    827      1.26       wiz 	/* initiate capture DMA */
    828      1.14     tacha 	BA1WRITE4(sc, CS4280_CBA, DMAADDR(p));
    829      1.14     tacha 
    830      1.14     tacha 	/* setup format information for internal converter */
    831      1.14     tacha 	sc->sc_rparam = 0;
    832      1.14     tacha 	if (param->precision == 8) {
    833      1.14     tacha 		sc->sc_rparam += CF_8BIT;
    834      1.14     tacha 		sc->sc_rcount <<= 1;
    835      1.14     tacha 	}
    836      1.14     tacha 	if (param->channels  == 1) {
    837      1.14     tacha 		sc->sc_rparam += CF_MONO;
    838      1.14     tacha 		sc->sc_rcount <<= 1;
    839      1.14     tacha 	}
    840      1.14     tacha 
    841      1.14     tacha 	/* set CIE */
    842      1.14     tacha 	cie = BA1READ4(sc, CS4280_CIE) & ~CIE_CI_MASK;
    843      1.14     tacha 	BA1WRITE4(sc, CS4280_CIE, cie | CIE_CI_ENABLE);
    844      1.14     tacha 
    845      1.16     tacha 	sc->sc_rrate = param->sample_rate;
    846      1.14     tacha 	cs4280_set_adc_rate(sc, param->sample_rate);
    847      1.14     tacha 
    848      1.14     tacha 	cctl = BA1READ4(sc, CS4280_CCTL) & ~CCTL_MASK;
    849      1.14     tacha 	cctl |= sc->cctl;
    850      1.14     tacha 	BA1WRITE4(sc, CS4280_CCTL, cctl);
    851      1.14     tacha 	return 0;
    852       1.1  augustss }
    853       1.1  augustss 
    854      1.14     tacha /* Power Hook */
    855      1.14     tacha void
    856      1.14     tacha cs4280_power(why, v)
    857      1.14     tacha 	int why;
    858      1.14     tacha 	void *v;
    859      1.14     tacha {
    860      1.14     tacha 	struct cs428x_softc *sc = (struct cs428x_softc *)v;
    861      1.16     tacha 	static u_int32_t pctl = 0, pba = 0, pfie = 0, pdtc = 0;
    862      1.16     tacha 	static u_int32_t cctl = 0, cba = 0, cie = 0;
    863      1.14     tacha 
    864      1.14     tacha 	DPRINTF(("%s: cs4280_power why=%d\n",
    865      1.14     tacha 	       sc->sc_dev.dv_xname, why));
    866      1.14     tacha 	switch (why) {
    867      1.14     tacha 	case PWR_SUSPEND:
    868      1.14     tacha 	case PWR_STANDBY:
    869      1.14     tacha 		sc->sc_suspend = why;
    870      1.14     tacha 
    871      1.16     tacha 		/* save current playback status */
    872      1.16     tacha 		if ( sc->sc_prun ) {
    873      1.16     tacha 			pctl = BA1READ4(sc, CS4280_PCTL);
    874      1.16     tacha 			pfie = BA1READ4(sc, CS4280_PFIE);
    875      1.16     tacha 			pba  = BA1READ4(sc, CS4280_PBA);
    876      1.16     tacha 			pdtc = BA1READ4(sc, CS4280_PDTC);
    877      1.16     tacha 			DPRINTF(("pctl=0x%08x pfie=0x%08x pba=0x%08x pdtc=0x%08x\n",
    878      1.16     tacha 			    pctl, pfie, pba, pdtc));
    879      1.16     tacha 		}
    880      1.16     tacha 
    881      1.16     tacha 		/* save current capture status */
    882      1.16     tacha 		if ( sc->sc_rrun ) {
    883      1.16     tacha 			cctl = BA1READ4(sc, CS4280_CCTL);
    884      1.16     tacha 			cie  = BA1READ4(sc, CS4280_CIE);
    885      1.16     tacha 			cba  = BA1READ4(sc, CS4280_CBA);
    886      1.16     tacha 			DPRINTF(("cctl=0x%08x cie=0x%08x cba=0x%08x\n",
    887      1.16     tacha 			    cctl, cie, cba));
    888      1.16     tacha 		}
    889      1.16     tacha 
    890      1.16     tacha 		/* Stop DMA */
    891      1.16     tacha 		BA1WRITE4(sc, CS4280_PCTL, pctl & ~PCTL_MASK);
    892      1.16     tacha 		BA1WRITE4(sc, CS4280_CCTL, BA1READ4(sc, CS4280_CCTL) & ~CCTL_MASK);
    893      1.14     tacha 		break;
    894      1.14     tacha 	case PWR_RESUME:
    895      1.14     tacha 		if (sc->sc_suspend == PWR_RESUME) {
    896      1.14     tacha 			printf("cs4280_power: odd, resume without suspend.\n");
    897      1.14     tacha 			sc->sc_suspend = why;
    898      1.14     tacha 			return;
    899      1.14     tacha 		}
    900      1.14     tacha 		sc->sc_suspend = why;
    901      1.14     tacha 		cs4280_init(sc, 0);
    902      1.14     tacha 		cs4280_reset_codec(sc);
    903       1.1  augustss 
    904      1.16     tacha 		/* restore ac97 registers */
    905      1.14     tacha 		(*sc->codec_if->vtbl->restore_ports)(sc->codec_if);
    906      1.16     tacha 
    907      1.16     tacha 		/* restore DMA related status */
    908      1.16     tacha 		if(sc->sc_prun) {
    909      1.16     tacha 			DPRINTF(("pctl=0x%08x pfie=0x%08x pba=0x%08x pdtc=0x%08x\n",
    910      1.16     tacha 			    pctl, pfie, pba, pdtc));
    911      1.16     tacha 			cs4280_set_dac_rate(sc, sc->sc_prate);
    912      1.16     tacha 			BA1WRITE4(sc, CS4280_PDTC, pdtc);
    913      1.16     tacha 			BA1WRITE4(sc, CS4280_PBA,  pba);
    914      1.16     tacha 			BA1WRITE4(sc, CS4280_PFIE, pfie);
    915      1.16     tacha 			BA1WRITE4(sc, CS4280_PCTL, pctl);
    916      1.16     tacha 		}
    917      1.16     tacha 
    918      1.16     tacha 		if (sc->sc_rrun) {
    919      1.16     tacha 			DPRINTF(("cctl=0x%08x cie=0x%08x cba=0x%08x\n",
    920      1.16     tacha 			    cctl, cie, cba));
    921      1.16     tacha 			cs4280_set_adc_rate(sc, sc->sc_rrate);
    922      1.16     tacha 			BA1WRITE4(sc, CS4280_CBA,  cba);
    923      1.16     tacha 			BA1WRITE4(sc, CS4280_CIE,  cie);
    924      1.16     tacha 			BA1WRITE4(sc, CS4280_CCTL, cctl);
    925      1.16     tacha 		}
    926      1.14     tacha 		break;
    927      1.14     tacha 	case PWR_SOFTSUSPEND:
    928      1.14     tacha 	case PWR_SOFTSTANDBY:
    929      1.14     tacha 	case PWR_SOFTRESUME:
    930      1.14     tacha 		break;
    931       1.1  augustss 	}
    932      1.14     tacha }
    933      1.14     tacha 
    934      1.14     tacha /* control AC97 codec */
    935      1.30      kent int
    936      1.14     tacha cs4280_reset_codec(void *addr)
    937      1.14     tacha {
    938      1.14     tacha 	struct cs428x_softc *sc;
    939      1.14     tacha 	int n;
    940      1.14     tacha 
    941      1.14     tacha 	sc = addr;
    942      1.14     tacha 
    943      1.14     tacha 	/* Reset codec */
    944      1.14     tacha 	BA0WRITE4(sc, CS428X_ACCTL, 0);
    945      1.14     tacha 	delay(100);    /* delay 100us */
    946      1.14     tacha 	BA0WRITE4(sc, CS428X_ACCTL, ACCTL_RSTN);
    947      1.14     tacha 
    948       1.1  augustss 	/*
    949      1.14     tacha 	 * It looks like we do the following procedure, too
    950      1.14     tacha 	 */
    951      1.14     tacha 
    952      1.14     tacha 	/* Enable AC-link sync generation */
    953      1.14     tacha 	BA0WRITE4(sc, CS428X_ACCTL, ACCTL_ESYN | ACCTL_RSTN);
    954      1.14     tacha 	delay(50*1000); /* XXX delay 50ms */
    955      1.14     tacha 
    956      1.14     tacha 	/* Assert valid frame signal */
    957      1.14     tacha 	BA0WRITE4(sc, CS428X_ACCTL, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN);
    958      1.14     tacha 
    959      1.14     tacha 	/* Wait for valid AC97 input slot */
    960      1.14     tacha 	n = 0;
    961      1.14     tacha 	while ((BA0READ4(sc, CS428X_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) !=
    962      1.14     tacha 	       (ACISV_ISV3 | ACISV_ISV4)) {
    963      1.14     tacha 		delay(1000);
    964      1.14     tacha 		if (++n > 1000) {
    965      1.14     tacha 			printf("reset_codec: AC97 inputs slot ready timeout\n");
    966      1.30      kent 			return ETIMEDOUT;
    967      1.14     tacha 		}
    968      1.14     tacha 	}
    969      1.30      kent 	return 0;
    970      1.14     tacha }
    971      1.14     tacha 
    972      1.14     tacha 
    973      1.14     tacha /* Internal functions */
    974      1.14     tacha 
    975      1.14     tacha void
    976      1.14     tacha cs4280_set_adc_rate(sc, rate)
    977      1.14     tacha 	struct cs428x_softc *sc;
    978      1.14     tacha 	int rate;
    979      1.14     tacha {
    980      1.14     tacha 	/* calculate capture rate:
    981      1.14     tacha 	 *
    982      1.14     tacha 	 * capture_coefficient_increment = -round(rate*128*65536/48000;
    983      1.14     tacha 	 * capture_phase_increment	 = floor(48000*65536*1024/rate);
    984      1.14     tacha 	 * cx = round(48000*65536*1024 - capture_phase_increment*rate);
    985      1.14     tacha 	 * cy = floor(cx/200);
    986      1.14     tacha 	 * capture_sample_rate_correction = cx - 200*cy;
    987      1.14     tacha 	 * capture_delay = ceil(24*48000/rate);
    988      1.14     tacha 	 * capture_num_triplets = floor(65536*rate/24000);
    989      1.14     tacha 	 * capture_group_length = 24000/GCD(rate, 24000);
    990      1.14     tacha 	 * where GCD means "Greatest Common Divisor".
    991      1.14     tacha 	 *
    992      1.14     tacha 	 * capture_coefficient_increment, capture_phase_increment and
    993      1.14     tacha 	 * capture_num_triplets are 32-bit signed quantities.
    994      1.14     tacha 	 * capture_sample_rate_correction and capture_group_length are
    995      1.14     tacha 	 * 16-bit signed quantities.
    996      1.14     tacha 	 * capture_delay is a 14-bit unsigned quantity.
    997      1.14     tacha 	 */
    998      1.14     tacha 	u_int32_t cci,cpi,cnt,cx,cy,  tmp1;
    999      1.14     tacha 	u_int16_t csrc, cgl, cdlay;
   1000      1.14     tacha 
   1001      1.14     tacha 	/* XXX
   1002      1.14     tacha 	 * Even though, embedded_audio_spec says capture rate range 11025 to
   1003      1.14     tacha 	 * 48000, dhwiface.cpp says,
   1004      1.14     tacha 	 *
   1005      1.14     tacha 	 * "We can only decimate by up to a factor of 1/9th the hardware rate.
   1006      1.14     tacha 	 *  Return an error if an attempt is made to stray outside that limit."
   1007      1.14     tacha 	 *
   1008      1.14     tacha 	 * so assume range as 48000/9 to 48000
   1009      1.14     tacha 	 */
   1010      1.14     tacha 
   1011      1.14     tacha 	if (rate < 8000)
   1012      1.14     tacha 		rate = 8000;
   1013      1.14     tacha 	if (rate > 48000)
   1014      1.14     tacha 		rate = 48000;
   1015      1.14     tacha 
   1016      1.14     tacha 	cx = rate << 16;
   1017      1.14     tacha 	cci = cx / 48000;
   1018      1.14     tacha 	cx -= cci * 48000;
   1019      1.14     tacha 	cx <<= 7;
   1020      1.14     tacha 	cci <<= 7;
   1021      1.14     tacha 	cci += cx / 48000;
   1022      1.14     tacha 	cci = - cci;
   1023      1.14     tacha 
   1024      1.14     tacha 	cx = 48000 << 16;
   1025      1.14     tacha 	cpi = cx / rate;
   1026      1.14     tacha 	cx -= cpi * rate;
   1027      1.14     tacha 	cx <<= 10;
   1028      1.14     tacha 	cpi <<= 10;
   1029      1.14     tacha 	cy = cx / rate;
   1030      1.14     tacha 	cpi += cy;
   1031      1.14     tacha 	cx -= cy * rate;
   1032      1.14     tacha 
   1033      1.14     tacha 	cy   = cx / 200;
   1034      1.14     tacha 	csrc = cx - 200*cy;
   1035      1.14     tacha 
   1036      1.14     tacha 	cdlay = ((48000 * 24) + rate - 1) / rate;
   1037      1.14     tacha #if 0
   1038      1.14     tacha 	cdlay &= 0x3fff; /* make sure cdlay is 14-bit */
   1039      1.14     tacha #endif
   1040      1.14     tacha 
   1041      1.14     tacha 	cnt  = rate << 16;
   1042      1.14     tacha 	cnt  /= 24000;
   1043      1.14     tacha 
   1044      1.14     tacha 	cgl = 1;
   1045      1.14     tacha 	for (tmp1 = 2; tmp1 <= 64; tmp1 *= 2) {
   1046      1.14     tacha 		if (((rate / tmp1) * tmp1) != rate)
   1047      1.14     tacha 			cgl *= 2;
   1048      1.14     tacha 	}
   1049      1.14     tacha 	if (((rate / 3) * 3) != rate)
   1050      1.14     tacha 		cgl *= 3;
   1051      1.14     tacha 	for (tmp1 = 5; tmp1 <= 125; tmp1 *= 5) {
   1052      1.14     tacha 		if (((rate / tmp1) * tmp1) != rate)
   1053      1.14     tacha 			cgl *= 5;
   1054      1.14     tacha 	}
   1055      1.14     tacha #if 0
   1056      1.14     tacha 	/* XXX what manual says */
   1057      1.14     tacha 	tmp1 = BA1READ4(sc, CS4280_CSRC) & ~CSRC_MASK;
   1058      1.14     tacha 	tmp1 |= csrc<<16;
   1059      1.14     tacha 	BA1WRITE4(sc, CS4280_CSRC, tmp1);
   1060      1.14     tacha #else
   1061      1.14     tacha 	/* suggested by cs461x.c (ALSA driver) */
   1062      1.14     tacha 	BA1WRITE4(sc, CS4280_CSRC, CS4280_MK_CSRC(csrc, cy));
   1063      1.14     tacha #endif
   1064      1.14     tacha 
   1065      1.14     tacha #if 0
   1066      1.14     tacha 	/* I am confused.  The sample rate calculation section says
   1067      1.14     tacha 	 * cci *is* 32-bit signed quantity but in the parameter description
   1068      1.14     tacha 	 * section, CCI only assigned 16bit.
   1069      1.14     tacha 	 * I believe size of the variable.
   1070      1.14     tacha 	 */
   1071      1.14     tacha 	tmp1 = BA1READ4(sc, CS4280_CCI) & ~CCI_MASK;
   1072      1.14     tacha 	tmp1 |= cci<<16;
   1073      1.14     tacha 	BA1WRITE4(sc, CS4280_CCI, tmp1);
   1074      1.14     tacha #else
   1075      1.14     tacha 	BA1WRITE4(sc, CS4280_CCI, cci);
   1076      1.14     tacha #endif
   1077      1.14     tacha 
   1078      1.14     tacha 	tmp1 = BA1READ4(sc, CS4280_CD) & ~CD_MASK;
   1079      1.14     tacha 	tmp1 |= cdlay <<18;
   1080      1.14     tacha 	BA1WRITE4(sc, CS4280_CD, tmp1);
   1081      1.14     tacha 
   1082      1.14     tacha 	BA1WRITE4(sc, CS4280_CPI, cpi);
   1083      1.14     tacha 
   1084      1.14     tacha 	tmp1 = BA1READ4(sc, CS4280_CGL) & ~CGL_MASK;
   1085      1.14     tacha 	tmp1 |= cgl;
   1086      1.14     tacha 	BA1WRITE4(sc, CS4280_CGL, tmp1);
   1087      1.14     tacha 
   1088      1.14     tacha 	BA1WRITE4(sc, CS4280_CNT, cnt);
   1089      1.14     tacha 
   1090      1.14     tacha 	tmp1 = BA1READ4(sc, CS4280_CGC) & ~CGC_MASK;
   1091      1.14     tacha 	tmp1 |= cgl;
   1092      1.14     tacha 	BA1WRITE4(sc, CS4280_CGC, tmp1);
   1093      1.14     tacha }
   1094      1.14     tacha 
   1095      1.14     tacha void
   1096      1.14     tacha cs4280_set_dac_rate(sc, rate)
   1097      1.14     tacha 	struct cs428x_softc *sc;
   1098      1.14     tacha 	int rate;
   1099      1.14     tacha {
   1100      1.14     tacha 	/*
   1101      1.14     tacha 	 * playback rate may range from 8000Hz to 48000Hz
   1102      1.14     tacha 	 *
   1103      1.14     tacha 	 * play_phase_increment = floor(rate*65536*1024/48000)
   1104      1.14     tacha 	 * px = round(rate*65536*1024 - play_phase_incremnt*48000)
   1105      1.14     tacha 	 * py=floor(px/200)
   1106      1.14     tacha 	 * play_sample_rate_correction = px - 200*py
   1107      1.14     tacha 	 *
   1108      1.14     tacha 	 * play_phase_increment is a 32bit signed quantity.
   1109      1.14     tacha 	 * play_sample_rate_correction is a 16bit signed quantity.
   1110       1.1  augustss 	 */
   1111      1.14     tacha 	int32_t ppi;
   1112      1.14     tacha 	int16_t psrc;
   1113      1.14     tacha 	u_int32_t px, py;
   1114      1.14     tacha 
   1115      1.14     tacha 	if (rate < 8000)
   1116      1.14     tacha 		rate = 8000;
   1117      1.14     tacha 	if (rate > 48000)
   1118      1.14     tacha 		rate = 48000;
   1119      1.14     tacha 	px = rate << 16;
   1120      1.14     tacha 	ppi = px/48000;
   1121      1.14     tacha 	px -= ppi*48000;
   1122      1.14     tacha 	ppi <<= 10;
   1123      1.14     tacha 	px  <<= 10;
   1124      1.14     tacha 	py  = px / 48000;
   1125      1.14     tacha 	ppi += py;
   1126      1.14     tacha 	px -= py*48000;
   1127      1.14     tacha 	py  = px/200;
   1128      1.14     tacha 	px -= py*200;
   1129      1.14     tacha 	psrc = px;
   1130      1.14     tacha #if 0
   1131      1.14     tacha 	/* what manual says */
   1132      1.14     tacha 	px = BA1READ4(sc, CS4280_PSRC) & ~PSRC_MASK;
   1133      1.14     tacha 	BA1WRITE4(sc, CS4280_PSRC,
   1134      1.14     tacha 			  ( ((psrc<<16) & PSRC_MASK) | px ));
   1135      1.14     tacha #else
   1136      1.14     tacha 	/* suggested by cs461x.c (ALSA driver) */
   1137      1.14     tacha 	BA1WRITE4(sc, CS4280_PSRC, CS4280_MK_PSRC(psrc,py));
   1138      1.14     tacha #endif
   1139      1.14     tacha 	BA1WRITE4(sc, CS4280_PPI, ppi);
   1140      1.14     tacha }
   1141      1.14     tacha 
   1142      1.14     tacha /* Download Proceessor Code and Data image */
   1143      1.14     tacha int
   1144      1.14     tacha cs4280_download(sc, src, offset, len)
   1145      1.14     tacha 	struct cs428x_softc *sc;
   1146      1.14     tacha 	const u_int32_t *src;
   1147      1.14     tacha 	u_int32_t offset, len;
   1148      1.14     tacha {
   1149      1.14     tacha 	u_int32_t ctr;
   1150      1.14     tacha 
   1151      1.14     tacha #if CS4280_DEBUG > 10
   1152      1.14     tacha 	u_int32_t con, data;
   1153      1.14     tacha 	u_int8_t c0,c1,c2,c3;
   1154      1.14     tacha #endif
   1155      1.14     tacha 	if ((offset&3) || (len&3))
   1156      1.14     tacha 		return -1;
   1157       1.1  augustss 
   1158      1.14     tacha 	len /= sizeof(u_int32_t);
   1159      1.14     tacha 	for (ctr = 0; ctr < len; ctr++) {
   1160      1.14     tacha 		/* XXX:
   1161      1.14     tacha 		 * I cannot confirm this is the right thing or not
   1162      1.14     tacha 		 * on BIG-ENDIAN machines.
   1163      1.14     tacha 		 */
   1164      1.14     tacha 		BA1WRITE4(sc, offset+ctr*4, htole32(*(src+ctr)));
   1165      1.14     tacha #if CS4280_DEBUG > 10
   1166      1.14     tacha 		data = htole32(*(src+ctr));
   1167      1.14     tacha 		c0 = bus_space_read_1(sc->ba1t, sc->ba1h, offset+ctr*4+0);
   1168      1.14     tacha 		c1 = bus_space_read_1(sc->ba1t, sc->ba1h, offset+ctr*4+1);
   1169      1.14     tacha 		c2 = bus_space_read_1(sc->ba1t, sc->ba1h, offset+ctr*4+2);
   1170      1.14     tacha 		c3 = bus_space_read_1(sc->ba1t, sc->ba1h, offset+ctr*4+3);
   1171      1.14     tacha 		con = ( (c3<<24) | (c2<<16) | (c1<<8) | c0 );
   1172      1.14     tacha 		if (data != con ) {
   1173      1.14     tacha 			printf("0x%06x: write=0x%08x read=0x%08x\n",
   1174      1.14     tacha 			       offset+ctr*4, data, con);
   1175      1.14     tacha 			return -1;
   1176      1.14     tacha 		}
   1177      1.14     tacha #endif
   1178       1.1  augustss 	}
   1179      1.14     tacha 	return 0;
   1180       1.1  augustss }
   1181       1.1  augustss 
   1182      1.14     tacha int
   1183      1.14     tacha cs4280_download_image(sc)
   1184      1.14     tacha 	struct cs428x_softc *sc;
   1185       1.1  augustss {
   1186      1.14     tacha 	int idx, err;
   1187      1.14     tacha 	u_int32_t offset = 0;
   1188      1.14     tacha 
   1189      1.14     tacha 	err = 0;
   1190      1.14     tacha 	for (idx = 0; idx < BA1_MEMORY_COUNT; ++idx) {
   1191      1.14     tacha 		err = cs4280_download(sc, &BA1Struct.map[offset],
   1192      1.14     tacha 				  BA1Struct.memory[idx].offset,
   1193      1.14     tacha 				  BA1Struct.memory[idx].size);
   1194      1.14     tacha 		if (err != 0) {
   1195      1.14     tacha 			printf("%s: load_image failed at %d\n",
   1196      1.14     tacha 			       sc->sc_dev.dv_xname, idx);
   1197      1.14     tacha 			return -1;
   1198       1.1  augustss 		}
   1199      1.14     tacha 		offset += BA1Struct.memory[idx].size / sizeof(u_int32_t);
   1200       1.1  augustss 	}
   1201      1.14     tacha 	return err;
   1202       1.1  augustss }
   1203       1.1  augustss 
   1204      1.14     tacha /* Processor Soft Reset */
   1205      1.14     tacha void
   1206      1.14     tacha cs4280_reset(sc_)
   1207      1.14     tacha 	void *sc_;
   1208       1.1  augustss {
   1209      1.14     tacha 	struct cs428x_softc *sc = sc_;
   1210       1.1  augustss 
   1211      1.14     tacha 	/* Set RSTSP bit in SPCR (also clear RUN, RUNFR, and DRQEN) */
   1212      1.14     tacha 	BA1WRITE4(sc, CS4280_SPCR, SPCR_RSTSP);
   1213      1.14     tacha 	delay(100);
   1214      1.14     tacha 	/* Clear RSTSP bit in SPCR */
   1215      1.14     tacha 	BA1WRITE4(sc, CS4280_SPCR, 0);
   1216      1.14     tacha 	/* enable DMA reqest */
   1217      1.14     tacha 	BA1WRITE4(sc, CS4280_SPCR, SPCR_DRQEN);
   1218       1.1  augustss }
   1219       1.1  augustss 
   1220       1.1  augustss int
   1221      1.14     tacha cs4280_get_portnum_by_name(sc, class, device, qualifier)
   1222      1.14     tacha 	struct cs428x_softc *sc;
   1223      1.14     tacha 	char *class, *device, *qualifier;
   1224       1.1  augustss {
   1225      1.14     tacha 	return (sc->codec_if->vtbl->get_portnum_by_name(sc->codec_if, class,
   1226      1.14     tacha 	     device, qualifier));
   1227       1.1  augustss }
   1228       1.1  augustss 
   1229       1.2  augustss int
   1230       1.1  augustss cs4280_init(sc, init)
   1231      1.14     tacha 	struct cs428x_softc *sc;
   1232       1.1  augustss 	int init;
   1233       1.1  augustss {
   1234       1.1  augustss 	int n;
   1235       1.1  augustss 	u_int32_t mem;
   1236       1.1  augustss 
   1237       1.1  augustss 	/* Start PLL out in known state */
   1238       1.1  augustss 	BA0WRITE4(sc, CS4280_CLKCR1, 0);
   1239       1.1  augustss 	/* Start serial ports out in known state */
   1240       1.1  augustss 	BA0WRITE4(sc, CS4280_SERMC1, 0);
   1241       1.1  augustss 
   1242       1.1  augustss 	/* Specify type of CODEC */
   1243       1.6  augustss /* XXX should not be here */
   1244       1.1  augustss #define SERACC_CODEC_TYPE_1_03
   1245       1.1  augustss #ifdef	SERACC_CODEC_TYPE_1_03
   1246       1.1  augustss 	BA0WRITE4(sc, CS4280_SERACC, SERACC_HSP | SERACC_CTYPE_1_03); /* AC 97 1.03 */
   1247       1.1  augustss #else
   1248       1.1  augustss 	BA0WRITE4(sc, CS4280_SERACC, SERACC_HSP | SERACC_CTYPE_2_0);  /* AC 97 2.0 */
   1249       1.1  augustss #endif
   1250       1.1  augustss 
   1251       1.1  augustss 	/* Reset codec */
   1252      1.14     tacha 	BA0WRITE4(sc, CS428X_ACCTL, 0);
   1253       1.1  augustss 	delay(100);    /* delay 100us */
   1254      1.14     tacha 	BA0WRITE4(sc, CS428X_ACCTL, ACCTL_RSTN);
   1255       1.1  augustss 
   1256       1.1  augustss 	/* Enable AC-link sync generation */
   1257      1.14     tacha 	BA0WRITE4(sc, CS428X_ACCTL, ACCTL_ESYN | ACCTL_RSTN);
   1258       1.1  augustss 	delay(50*1000); /* delay 50ms */
   1259       1.1  augustss 
   1260       1.1  augustss 	/* Set the serial port timing configuration */
   1261       1.1  augustss 	BA0WRITE4(sc, CS4280_SERMC1, SERMC1_PTC_AC97);
   1262       1.1  augustss 
   1263       1.1  augustss 	/* Setup clock control */
   1264       1.1  augustss 	BA0WRITE4(sc, CS4280_PLLCC, PLLCC_CDR_STATE|PLLCC_LPF_STATE);
   1265       1.1  augustss 	BA0WRITE4(sc, CS4280_PLLM, PLLM_STATE);
   1266       1.1  augustss 	BA0WRITE4(sc, CS4280_CLKCR2, CLKCR2_PDIVS_8);
   1267       1.1  augustss 
   1268       1.1  augustss 	/* Power up the PLL */
   1269       1.1  augustss 	BA0WRITE4(sc, CS4280_CLKCR1, CLKCR1_PLLP);
   1270       1.1  augustss 	delay(50*1000); /* delay 50ms */
   1271       1.1  augustss 
   1272       1.1  augustss 	/* Turn on clock */
   1273       1.7  augustss 	mem = BA0READ4(sc, CS4280_CLKCR1) | CLKCR1_SWCE;
   1274       1.7  augustss 	BA0WRITE4(sc, CS4280_CLKCR1, mem);
   1275       1.1  augustss 
   1276       1.2  augustss 	/* Set the serial port FIFO pointer to the
   1277       1.2  augustss 	 * first sample in FIFO. (not documented) */
   1278       1.1  augustss 	cs4280_clear_fifos(sc);
   1279       1.2  augustss 
   1280       1.2  augustss #if 0
   1281       1.2  augustss 	/* Set the serial port FIFO pointer to the first sample in the FIFO */
   1282       1.2  augustss 	BA0WRITE4(sc, CS4280_SERBSP, 0);
   1283       1.1  augustss #endif
   1284       1.1  augustss 
   1285       1.1  augustss 	/* Configure the serial port */
   1286       1.1  augustss 	BA0WRITE4(sc, CS4280_SERC1,  SERC1_SO1EN | SERC1_SO1F_AC97);
   1287       1.1  augustss 	BA0WRITE4(sc, CS4280_SERC2,  SERC2_SI1EN | SERC2_SI1F_AC97);
   1288       1.1  augustss 	BA0WRITE4(sc, CS4280_SERMC1, SERMC1_MSPE | SERMC1_PTC_AC97);
   1289       1.1  augustss 
   1290       1.1  augustss 	/* Wait for CODEC ready */
   1291       1.1  augustss 	n = 0;
   1292      1.14     tacha 	while ((BA0READ4(sc, CS428X_ACSTS) & ACSTS_CRDY) == 0) {
   1293       1.2  augustss 		delay(125);
   1294       1.2  augustss 		if (++n > 1000) {
   1295       1.1  augustss 			printf("%s: codec ready timeout\n",
   1296       1.1  augustss 			       sc->sc_dev.dv_xname);
   1297       1.2  augustss 			return(1);
   1298       1.1  augustss 		}
   1299       1.1  augustss 	}
   1300       1.1  augustss 
   1301       1.1  augustss 	/* Assert valid frame signal */
   1302      1.14     tacha 	BA0WRITE4(sc, CS428X_ACCTL, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN);
   1303       1.1  augustss 
   1304       1.1  augustss 	/* Wait for valid AC97 input slot */
   1305       1.1  augustss 	n = 0;
   1306      1.14     tacha 	while ((BA0READ4(sc, CS428X_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) !=
   1307       1.7  augustss 	       (ACISV_ISV3 | ACISV_ISV4)) {
   1308       1.1  augustss 		delay(1000);
   1309       1.1  augustss 		if (++n > 1000) {
   1310       1.1  augustss 			printf("AC97 inputs slot ready timeout\n");
   1311       1.2  augustss 			return(1);
   1312       1.1  augustss 		}
   1313       1.1  augustss 	}
   1314       1.1  augustss 
   1315       1.1  augustss 	/* Set AC97 output slot valid signals */
   1316      1.14     tacha 	BA0WRITE4(sc, CS428X_ACOSV, ACOSV_SLV3 | ACOSV_SLV4);
   1317       1.1  augustss 
   1318       1.1  augustss 	/* reset the processor */
   1319       1.1  augustss 	cs4280_reset(sc);
   1320       1.1  augustss 
   1321       1.1  augustss 	/* Download the image to the processor */
   1322       1.1  augustss 	if (cs4280_download_image(sc) != 0) {
   1323       1.1  augustss 		printf("%s: image download error\n", sc->sc_dev.dv_xname);
   1324       1.2  augustss 		return(1);
   1325       1.1  augustss 	}
   1326       1.1  augustss 
   1327       1.1  augustss 	/* Save playback parameter and then write zero.
   1328       1.1  augustss 	 * this ensures that DMA doesn't immediately occur upon
   1329       1.1  augustss 	 * starting the processor core
   1330       1.1  augustss 	 */
   1331       1.1  augustss 	mem = BA1READ4(sc, CS4280_PCTL);
   1332       1.1  augustss 	sc->pctl = mem & PCTL_MASK; /* save startup value */
   1333      1.16     tacha 	BA1WRITE4(sc, CS4280_PCTL, mem & ~PCTL_MASK);
   1334      1.16     tacha 	if (init != 0)
   1335      1.16     tacha 		sc->sc_prun = 0;
   1336       1.1  augustss 
   1337       1.1  augustss 	/* Save capture parameter and then write zero.
   1338       1.1  augustss 	 * this ensures that DMA doesn't immediately occur upon
   1339       1.1  augustss 	 * starting the processor core
   1340       1.1  augustss 	 */
   1341       1.1  augustss 	mem = BA1READ4(sc, CS4280_CCTL);
   1342       1.1  augustss 	sc->cctl = mem & CCTL_MASK; /* save startup value */
   1343      1.16     tacha 	BA1WRITE4(sc, CS4280_CCTL, mem & ~CCTL_MASK);
   1344      1.16     tacha 	if (init != 0)
   1345      1.16     tacha 		sc->sc_rrun = 0;
   1346       1.1  augustss 
   1347       1.1  augustss 	/* Processor Startup Procedure */
   1348       1.1  augustss 	BA1WRITE4(sc, CS4280_FRMT, FRMT_FTV);
   1349       1.1  augustss 	BA1WRITE4(sc, CS4280_SPCR, SPCR_RUN | SPCR_RUNFR | SPCR_DRQEN);
   1350       1.1  augustss 
   1351       1.1  augustss 	/* Monitor RUNFR bit in SPCR for 1 to 0 transition */
   1352       1.1  augustss 	n = 0;
   1353       1.1  augustss 	while (BA1READ4(sc, CS4280_SPCR) & SPCR_RUNFR) {
   1354       1.1  augustss 		delay(10);
   1355       1.1  augustss 		if (++n > 1000) {
   1356       1.1  augustss 			printf("SPCR 1->0 transition timeout\n");
   1357       1.2  augustss 			return(1);
   1358       1.1  augustss 		}
   1359       1.1  augustss 	}
   1360       1.1  augustss 
   1361       1.1  augustss 	n = 0;
   1362       1.1  augustss 	while (!(BA1READ4(sc, CS4280_SPCS) & SPCS_SPRUN)) {
   1363       1.1  augustss 		delay(10);
   1364       1.1  augustss 		if (++n > 1000) {
   1365       1.1  augustss 			printf("SPCS 0->1 transition timeout\n");
   1366       1.2  augustss 			return(1);
   1367       1.1  augustss 		}
   1368       1.1  augustss 	}
   1369       1.1  augustss 	/* Processor is now running !!! */
   1370       1.1  augustss 
   1371       1.1  augustss 	/* Setup  volume */
   1372       1.1  augustss 	BA1WRITE4(sc, CS4280_PVOL, 0x80008000);
   1373       1.1  augustss 	BA1WRITE4(sc, CS4280_CVOL, 0x80008000);
   1374       1.1  augustss 
   1375       1.1  augustss 	/* Interrupt enable */
   1376       1.1  augustss 	BA0WRITE4(sc, CS4280_HICR, HICR_IEV|HICR_CHGM);
   1377       1.1  augustss 
   1378       1.1  augustss 	/* playback interrupt enable */
   1379       1.1  augustss 	mem = BA1READ4(sc, CS4280_PFIE) & ~PFIE_PI_MASK;
   1380       1.1  augustss 	mem |= PFIE_PI_ENABLE;
   1381       1.1  augustss 	BA1WRITE4(sc, CS4280_PFIE, mem);
   1382       1.1  augustss 	/* capture interrupt enable */
   1383       1.1  augustss 	mem = BA1READ4(sc, CS4280_CIE) & ~CIE_CI_MASK;
   1384       1.1  augustss 	mem |= CIE_CI_ENABLE;
   1385       1.1  augustss 	BA1WRITE4(sc, CS4280_CIE, mem);
   1386       1.2  augustss 
   1387       1.2  augustss #if NMIDI > 0
   1388       1.2  augustss 	/* Reset midi port */
   1389       1.2  augustss 	mem = BA0READ4(sc, CS4280_MIDCR) & ~MIDCR_MASK;
   1390       1.2  augustss 	BA0WRITE4(sc, CS4280_MIDCR, mem | MIDCR_MRST);
   1391       1.2  augustss 	DPRINTF(("midi reset: 0x%x\n", BA0READ4(sc, CS4280_MIDCR)));
   1392       1.2  augustss 	/* midi interrupt enable */
   1393       1.2  augustss 	mem |= MIDCR_TXE | MIDCR_RXE | MIDCR_RIE | MIDCR_TIE;
   1394       1.2  augustss 	BA0WRITE4(sc, CS4280_MIDCR, mem);
   1395       1.2  augustss #endif
   1396       1.2  augustss 	return(0);
   1397       1.1  augustss }
   1398       1.1  augustss 
   1399       1.1  augustss void
   1400       1.1  augustss cs4280_clear_fifos(sc)
   1401      1.14     tacha 	struct cs428x_softc *sc;
   1402       1.1  augustss {
   1403       1.1  augustss 	int pd = 0, cnt, n;
   1404       1.1  augustss 	u_int32_t mem;
   1405       1.1  augustss 
   1406       1.1  augustss 	/*
   1407       1.1  augustss 	 * If device power down, power up the device and keep power down
   1408       1.1  augustss 	 * state.
   1409       1.1  augustss 	 */
   1410       1.1  augustss 	mem = BA0READ4(sc, CS4280_CLKCR1);
   1411       1.1  augustss 	if (!(mem & CLKCR1_SWCE)) {
   1412       1.1  augustss 		printf("cs4280_clear_fifo: power down found.\n");
   1413       1.1  augustss 		BA0WRITE4(sc, CS4280_CLKCR1, mem | CLKCR1_SWCE);
   1414       1.1  augustss 		pd = 1;
   1415       1.1  augustss 	}
   1416       1.1  augustss 	BA0WRITE4(sc, CS4280_SERBWP, 0);
   1417       1.1  augustss 	for (cnt = 0; cnt < 256; cnt++) {
   1418       1.1  augustss 		n = 0;
   1419       1.1  augustss 		while (BA0READ4(sc, CS4280_SERBST) & SERBST_WBSY) {
   1420       1.1  augustss 			delay(1000);
   1421       1.1  augustss 			if (++n > 1000) {
   1422       1.1  augustss 				printf("clear_fifo: fist timeout cnt=%d\n", cnt);
   1423       1.1  augustss 				break;
   1424       1.1  augustss 			}
   1425       1.1  augustss 		}
   1426       1.1  augustss 		BA0WRITE4(sc, CS4280_SERBAD, cnt);
   1427       1.1  augustss 		BA0WRITE4(sc, CS4280_SERBCM, SERBCM_WRC);
   1428       1.1  augustss 	}
   1429       1.1  augustss 	if (pd)
   1430       1.1  augustss 		BA0WRITE4(sc, CS4280_CLKCR1, mem);
   1431       1.1  augustss }
   1432       1.1  augustss 
   1433       1.1  augustss #if NMIDI > 0
   1434       1.1  augustss int
   1435       1.1  augustss cs4280_midi_open(addr, flags, iintr, ointr, arg)
   1436       1.1  augustss 	void *addr;
   1437       1.1  augustss 	int flags;
   1438       1.1  augustss 	void (*iintr)__P((void *, int));
   1439       1.1  augustss 	void (*ointr)__P((void *));
   1440       1.1  augustss 	void *arg;
   1441       1.1  augustss {
   1442      1.14     tacha 	struct cs428x_softc *sc = addr;
   1443       1.1  augustss 	u_int32_t mem;
   1444       1.1  augustss 
   1445       1.1  augustss 	DPRINTF(("midi_open\n"));
   1446       1.1  augustss 	sc->sc_iintr = iintr;
   1447       1.1  augustss 	sc->sc_ointr = ointr;
   1448       1.1  augustss 	sc->sc_arg = arg;
   1449       1.1  augustss 
   1450       1.2  augustss 	/* midi interrupt enable */
   1451       1.2  augustss 	mem = BA0READ4(sc, CS4280_MIDCR) & ~MIDCR_MASK;
   1452       1.1  augustss 	mem |= MIDCR_TXE | MIDCR_RXE | MIDCR_RIE | MIDCR_TIE | MIDCR_MLB;
   1453       1.1  augustss 	BA0WRITE4(sc, CS4280_MIDCR, mem);
   1454       1.2  augustss #ifdef CS4280_DEBUG
   1455       1.2  augustss 	if (mem != BA0READ4(sc, CS4280_MIDCR)) {
   1456       1.2  augustss 		DPRINTF(("midi_open: MIDCR=%d\n", BA0READ4(sc, CS4280_MIDCR)));
   1457       1.2  augustss 		return(EINVAL);
   1458       1.2  augustss 	}
   1459       1.2  augustss 	DPRINTF(("MIDCR=0x%x\n", BA0READ4(sc, CS4280_MIDCR)));
   1460       1.2  augustss #endif
   1461      1.14     tacha 	return 0;
   1462       1.1  augustss }
   1463       1.1  augustss 
   1464       1.1  augustss void
   1465       1.1  augustss cs4280_midi_close(addr)
   1466       1.1  augustss 	void *addr;
   1467       1.1  augustss {
   1468      1.14     tacha 	struct cs428x_softc *sc = addr;
   1469       1.1  augustss 	u_int32_t mem;
   1470       1.1  augustss 
   1471       1.1  augustss 	DPRINTF(("midi_close\n"));
   1472      1.13  augustss 	tsleep(sc, PWAIT, "cs0clm", hz/10); /* give uart a chance to drain */
   1473       1.1  augustss 	mem = BA0READ4(sc, CS4280_MIDCR);
   1474       1.2  augustss 	mem &= ~MIDCR_MASK;
   1475       1.1  augustss 	BA0WRITE4(sc, CS4280_MIDCR, mem);
   1476       1.1  augustss 
   1477       1.1  augustss 	sc->sc_iintr = 0;
   1478       1.1  augustss 	sc->sc_ointr = 0;
   1479       1.1  augustss }
   1480       1.1  augustss 
   1481       1.1  augustss int
   1482       1.1  augustss cs4280_midi_output(addr, d)
   1483       1.1  augustss 	void *addr;
   1484       1.1  augustss 	int d;
   1485       1.1  augustss {
   1486      1.14     tacha 	struct cs428x_softc *sc = addr;
   1487       1.1  augustss 	u_int32_t mem;
   1488       1.1  augustss 	int x;
   1489       1.1  augustss 
   1490       1.1  augustss 	for (x = 0; x != MIDI_BUSY_WAIT; x++) {
   1491       1.2  augustss 		if ((BA0READ4(sc, CS4280_MIDSR) & MIDSR_TBF) == 0) {
   1492       1.2  augustss 			mem = BA0READ4(sc, CS4280_MIDWP) & ~MIDWP_MASK;
   1493       1.2  augustss 			mem |= d & MIDWP_MASK;
   1494       1.2  augustss 			DPRINTFN(5,("midi_output d=0x%08x",d));
   1495       1.1  augustss 			BA0WRITE4(sc, CS4280_MIDWP, mem);
   1496       1.6  augustss #ifdef DIAGNOSTIC
   1497       1.2  augustss 			if (mem != BA0READ4(sc, CS4280_MIDWP)) {
   1498       1.2  augustss 				DPRINTF(("Bad write data: %d %d",
   1499       1.2  augustss 					 mem, BA0READ4(sc, CS4280_MIDWP)));
   1500       1.2  augustss 				return(EIO);
   1501       1.2  augustss 			}
   1502       1.6  augustss #endif
   1503      1.14     tacha 			return 0;
   1504       1.1  augustss 		}
   1505       1.1  augustss 		delay(MIDI_BUSY_DELAY);
   1506       1.1  augustss 	}
   1507       1.1  augustss 	return (EIO);
   1508       1.1  augustss }
   1509       1.1  augustss 
   1510       1.1  augustss void
   1511       1.1  augustss cs4280_midi_getinfo(addr, mi)
   1512       1.1  augustss 	void *addr;
   1513       1.1  augustss 	struct midi_info *mi;
   1514       1.1  augustss {
   1515       1.1  augustss 	mi->name = "CS4280 MIDI UART";
   1516       1.1  augustss 	mi->props = MIDI_PROP_CAN_INPUT | MIDI_PROP_OUT_INTR;
   1517      1.14     tacha }
   1518      1.14     tacha 
   1519      1.14     tacha #endif
   1520      1.14     tacha 
   1521      1.14     tacha /* DEBUG functions */
   1522      1.14     tacha #if CS4280_DEBUG > 10
   1523      1.14     tacha int
   1524      1.14     tacha cs4280_checkimage(sc, src, offset, len)
   1525      1.14     tacha 	struct cs428x_softc *sc;
   1526      1.14     tacha 	u_int32_t *src;
   1527      1.14     tacha 	u_int32_t offset, len;
   1528      1.14     tacha {
   1529      1.14     tacha 	u_int32_t ctr, data;
   1530      1.14     tacha 	int err = 0;
   1531      1.14     tacha 
   1532      1.14     tacha 	if ((offset&3) || (len&3))
   1533      1.14     tacha 		return -1;
   1534      1.14     tacha 
   1535      1.14     tacha 	len /= sizeof(u_int32_t);
   1536      1.14     tacha 	for (ctr = 0; ctr < len; ctr++) {
   1537      1.14     tacha 		/* I cannot confirm this is the right thing
   1538      1.14     tacha 		 * on BIG-ENDIAN machines
   1539      1.14     tacha 		 */
   1540      1.14     tacha 		data = BA1READ4(sc, offset+ctr*4);
   1541      1.14     tacha 		if (data != htole32(*(src+ctr))) {
   1542      1.14     tacha 			printf("0x%06x: 0x%08x(0x%08x)\n",
   1543      1.14     tacha 			       offset+ctr*4, data, *(src+ctr));
   1544      1.14     tacha 			*(src+ctr) = data;
   1545      1.14     tacha 			++err;
   1546      1.14     tacha 		}
   1547      1.14     tacha 	}
   1548      1.14     tacha 	return err;
   1549      1.14     tacha }
   1550      1.14     tacha 
   1551      1.14     tacha int
   1552      1.14     tacha cs4280_check_images(sc)
   1553      1.14     tacha 	struct cs428x_softc *sc;
   1554      1.14     tacha {
   1555      1.14     tacha 	int idx, err;
   1556      1.14     tacha 	u_int32_t offset = 0;
   1557      1.14     tacha 
   1558      1.14     tacha 	err = 0;
   1559      1.14     tacha 	/*for (idx=0; idx < BA1_MEMORY_COUNT; ++idx) { */
   1560      1.14     tacha 	for (idx = 0; idx < 1; ++idx) {
   1561      1.14     tacha 		err = cs4280_checkimage(sc, &BA1Struct.map[offset],
   1562      1.14     tacha 				      BA1Struct.memory[idx].offset,
   1563      1.14     tacha 				      BA1Struct.memory[idx].size);
   1564      1.14     tacha 		if (err != 0) {
   1565      1.14     tacha 			printf("%s: check_image failed at %d\n",
   1566      1.14     tacha 			       sc->sc_dev.dv_xname, idx);
   1567      1.14     tacha 		}
   1568      1.14     tacha 		offset += BA1Struct.memory[idx].size / sizeof(u_int32_t);
   1569      1.14     tacha 	}
   1570      1.14     tacha 	return err;
   1571       1.1  augustss }
   1572       1.1  augustss 
   1573       1.1  augustss #endif
   1574