/*-
* Copyright (c) 2006 Shigeyuki Fukushima.
* All rights reserved.
*
* Written by Shigeyuki Fukushima.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
for (i = 0 ; aupsc_protos[i].name != NULL ; i++) {
struct aupsc_protocol_device p;
uint32_t s;
pa.aupsc_name = aupsc_protos[i].name;
p.sc_dev = sc->sc_dev;
p.sc_ctrl = ctrl;
aupsc_enable(&p, aupsc_protos[i].protocol);
s = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPSC_STAT);
aupsc_disable(&p);
if (s & AUPSC_STAT_SR) {
config_found(self, &pa, aupsc_print,
CFARGS(.submatch = aupsc_submatch));
}
}
}
static int
aupsc_submatch(device_t parent, struct cfdata *cf, const int *ldesc, void *aux)
{
return config_match(parent, cf, aux);
}
static int
aupsc_print(void *aux, const char *pnp)
{
/*
* By default we don't want to print anything, because
* otherwise we see complaints about protocols that aren't
* configured on every port. (E.g. each PSC can support 4
* protocols, but on a typical design, only one protocol can
* be configured per board.)
*
* Basically, this whole thing should be replaced with an
* indirect configuration mechanism. Direct configuration
* doesn't make sense when we absolutely require kernel
* configuration to operate.
*
* Alternatively, a board-specific configuration mechanism
* could determine this, and provide direct configuration as
* we do for PCMCIA.
*/
return QUIET;
}
static void
aupsc_enable(void *arg, int proto)
{
struct aupsc_protocol_device *sc = arg;
int i;
/* XXX: (TODO) setting clock AUPSC_SEL_CLK */
switch (proto) {
case AUPSC_SEL_SPI:
case AUPSC_SEL_I2S:
case AUPSC_SEL_AC97:
case AUPSC_SEL_SMBUS:
break;
case AUPSC_SEL_DISABLE:
aupsc_disable(arg);
break;
default:
printf("%s: aupsc_enable: unsupported protocol.\n",
device_xname(sc->sc_dev));
return;
}
/* wait up to a whole second, but test every 10us */
for (i = 1000000; i; i -= 10) {
if (bus_space_read_4(sc->sc_ctrl.psc_bust,
sc->sc_ctrl.psc_bush, AUPSC_STAT) & AUPSC_STAT_SR)
return;
delay(10);
}
}