convert to device_t.

This commit is contained in:
nonaka 2012-03-02 11:41:36 +00:00
parent 2975b78889
commit 8b18844d0e

View File

@ -1,4 +1,4 @@
/* $NetBSD: gcscaudio.c,v 1.11 2011/11/25 12:50:32 jmcneill Exp $ */
/* $NetBSD: gcscaudio.c,v 1.12 2012/03/02 11:41:36 nonaka Exp $ */
/*-
* Copyright (c) 2008 SHIMIZU Ryo <ryo@nerv.org>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: gcscaudio.c,v 1.11 2011/11/25 12:50:32 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: gcscaudio.c,v 1.12 2012/03/02 11:41:36 nonaka Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -84,7 +84,7 @@ struct gcscaudio_softc_ch {
};
struct gcscaudio_softc {
struct device sc_dev;
device_t sc_dev;
kmutex_t sc_lock;
kmutex_t sc_intr_lock;
pci_chipset_tag_t sc_pc;
@ -174,7 +174,7 @@ static int gcscaudio_allocate_dma(struct gcscaudio_softc *, size_t, void **,
bus_dmamap_t *);
CFATTACH_DECL(gcscaudio, sizeof (struct gcscaudio_softc),
CFATTACH_DECL_NEW(gcscaudio, sizeof (struct gcscaudio_softc),
gcscaudio_match, gcscaudio_attach, NULL, NULL);
@ -248,7 +248,7 @@ gcscaudio_append_formats(struct gcscaudio_softc *sc,
const struct audio_format *format)
{
if (sc->sc_nformats >= GCSCAUDIO_MAXFORMATS) {
aprint_error_dev(&sc->sc_dev, "too many formats\n");
aprint_error_dev(sc->sc_dev, "too many formats\n");
return EINVAL;
}
sc->sc_formats[sc->sc_nformats++] = *format;
@ -266,6 +266,8 @@ gcscaudio_attach(device_t parent, device_t self, void *aux)
sc = device_private(self);
sc->sc_dev = self;
aprint_naive(": Audio controller\n");
pa = aux;
@ -281,12 +283,12 @@ gcscaudio_attach(device_t parent, device_t self, void *aux)
if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
&sc->sc_iot, &sc->sc_ioh, NULL, &sc->sc_ios)) {
aprint_error_dev(&sc->sc_dev, "can't map i/o space\n");
aprint_error_dev(sc->sc_dev, "can't map i/o space\n");
return;
}
if (pci_intr_map(pa, &ih)) {
aprint_error_dev(&sc->sc_dev, "couldn't map interrupt\n");
aprint_error_dev(sc->sc_dev, "couldn't map interrupt\n");
goto attach_failure_unmap;
}
intrstr = pci_intr_string(sc->sc_pc, ih);
@ -294,14 +296,14 @@ gcscaudio_attach(device_t parent, device_t self, void *aux)
sc->sc_ih = pci_intr_establish(sc->sc_pc, ih, IPL_AUDIO,
gcscaudio_intr, sc);
if (sc->sc_ih == NULL) {
aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt");
aprint_error_dev(sc->sc_dev, "couldn't establish interrupt");
if (intrstr != NULL)
aprint_error(" at %s", intrstr);
aprint_error("\n");
goto attach_failure_unmap;
}
aprint_normal_dev(&sc->sc_dev, "interrupting at %s\n", intrstr);
aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
if (gcscaudio_allocate_dma(sc, sizeof(*sc->sc_prd.p_prdtables),
@ -317,7 +319,7 @@ gcscaudio_attach(device_t parent, device_t self, void *aux)
sc->host_if.spdif_event = gcscaudio_spdif_event_codec;
if ((rc = ac97_attach(&sc->host_if, self, &sc->sc_lock)) != 0) {
aprint_error_dev(&sc->sc_dev,
aprint_error_dev(sc->sc_dev,
"can't attach codec (error=%d)\n", rc);
goto attach_failure_intr;
}
@ -349,7 +351,7 @@ gcscaudio_attach(device_t parent, device_t self, void *aux)
goto attach_failure_codec;
}
audio_attach_mi(&gcscaudio_hw_if, sc, &sc->sc_dev);
audio_attach_mi(&gcscaudio_hw_if, sc, sc->sc_dev);
return;
attach_failure_codec:
@ -408,7 +410,7 @@ gcscaudio_wait_ready_codec(struct gcscaudio_softc *sc, const char *timeout_msg)
delay(1);
if (i < 0) {
aprint_error_dev(&sc->sc_dev, "%s", timeout_msg);
aprint_error_dev(sc->sc_dev, "%s", timeout_msg);
return 1;
}
@ -432,7 +434,7 @@ gcscaudio_write_codec(void *arg, uint8_t reg, uint16_t val)
return 1;
#ifdef GCSCAUDIO_CODEC_DEBUG
aprint_error_dev(&sc->sc_dev, "codec write: reg=0x%02x, val=0x%04x\n",
aprint_error_dev(sc->sc_dev, "codec write: reg=0x%02x, val=0x%04x\n",
reg, val);
#endif
@ -465,12 +467,12 @@ gcscaudio_read_codec(void *arg, uint8_t reg, uint16_t *val)
}
if (i < 0) {
aprint_error_dev(&sc->sc_dev, "codec read timeout\n");
aprint_error_dev(sc->sc_dev, "codec read timeout\n");
return 1;
}
#ifdef GCSCAUDIO_CODEC_DEBUG
aprint_error_dev(&sc->sc_dev, "codec read: reg=0x%02x, val=0x%04x\n",
aprint_error_dev(sc->sc_dev, "codec read: reg=0x%02x, val=0x%04x\n",
reg, v & ACC_CODEC_STATUS_STS_DATA_MASK);
#endif
@ -778,8 +780,7 @@ build_prdtables(struct gcscaudio_softc *sc, int prdidx,
}
}
if (!paddr) {
aprint_error_dev(&sc->sc_dev,
"bad addr %p\n", addr);
aprint_error_dev(sc->sc_dev, "bad addr %p\n", addr);
return EINVAL;
}
@ -1222,9 +1223,9 @@ gcscaudio_intr(void *arg)
if (intr & ACC_IRQ_STATUS_BM0_IRQ_STS) {
bmstat = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ACC_BM0_STATUS);
if (bmstat & ACC_BMx_STATUS_BM_EOP_ERR)
aprint_normal_dev(&sc->sc_dev, "BM0: Bus Master Error\n");
aprint_normal_dev(sc->sc_dev, "BM0: Bus Master Error\n");
if (!(bmstat & ACC_BMx_STATUS_EOP))
aprint_normal_dev(&sc->sc_dev, "BM0: NO End of Page?\n");
aprint_normal_dev(sc->sc_dev, "BM0: NO End of Page?\n");
if (sc->sc_play.ch_intr) {
sc->sc_play.ch_intr(sc->sc_play.ch_intr_arg);
@ -1237,9 +1238,9 @@ gcscaudio_intr(void *arg)
if (intr & ACC_IRQ_STATUS_BM4_IRQ_STS) {
bmstat = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ACC_BM4_STATUS);
if (bmstat & ACC_BMx_STATUS_BM_EOP_ERR)
aprint_normal_dev(&sc->sc_dev, "BM4: Bus Master Error\n");
aprint_normal_dev(sc->sc_dev, "BM4: Bus Master Error\n");
if (!(bmstat & ACC_BMx_STATUS_EOP))
aprint_normal_dev(&sc->sc_dev, "BM4: NO End of Page?\n");
aprint_normal_dev(sc->sc_dev, "BM4: NO End of Page?\n");
nintr++;
}
@ -1248,9 +1249,9 @@ gcscaudio_intr(void *arg)
if (intr & ACC_IRQ_STATUS_BM6_IRQ_STS) {
bmstat = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ACC_BM6_STATUS);
if (bmstat & ACC_BMx_STATUS_BM_EOP_ERR)
aprint_normal_dev(&sc->sc_dev, "BM6: Bus Master Error\n");
aprint_normal_dev(sc->sc_dev, "BM6: Bus Master Error\n");
if (!(bmstat & ACC_BMx_STATUS_EOP))
aprint_normal_dev(&sc->sc_dev, "BM6: NO End of Page?\n");
aprint_normal_dev(sc->sc_dev, "BM6: NO End of Page?\n");
nintr++;
}
@ -1259,9 +1260,9 @@ gcscaudio_intr(void *arg)
if (intr & ACC_IRQ_STATUS_BM7_IRQ_STS) {
bmstat = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ACC_BM7_STATUS);
if (bmstat & ACC_BMx_STATUS_BM_EOP_ERR)
aprint_normal_dev(&sc->sc_dev, "BM7: Bus Master Error\n");
aprint_normal_dev(sc->sc_dev, "BM7: Bus Master Error\n");
if (!(bmstat & ACC_BMx_STATUS_EOP))
aprint_normal_dev(&sc->sc_dev, "BM7: NO End of Page?\n");
aprint_normal_dev(sc->sc_dev, "BM7: NO End of Page?\n");
nintr++;
}
@ -1270,9 +1271,9 @@ gcscaudio_intr(void *arg)
if (intr & ACC_IRQ_STATUS_BM1_IRQ_STS) {
bmstat = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ACC_BM1_STATUS);
if (bmstat & ACC_BMx_STATUS_BM_EOP_ERR)
aprint_normal_dev(&sc->sc_dev, "BM1: Bus Master Error\n");
aprint_normal_dev(sc->sc_dev, "BM1: Bus Master Error\n");
if (!(bmstat & ACC_BMx_STATUS_EOP))
aprint_normal_dev(&sc->sc_dev, "BM1: NO End of Page?\n");
aprint_normal_dev(sc->sc_dev, "BM1: NO End of Page?\n");
if (sc->sc_rec.ch_intr) {
sc->sc_rec.ch_intr(sc->sc_rec.ch_intr_arg);
@ -1282,15 +1283,15 @@ gcscaudio_intr(void *arg)
#ifdef GCSCAUDIO_DEBUG
if (intr & ACC_IRQ_STATUS_IRQ_STS)
aprint_normal_dev(&sc->sc_dev, "Codec GPIO IRQ Status\n");
aprint_normal_dev(sc->sc_dev, "Codec GPIO IRQ Status\n");
if (intr & ACC_IRQ_STATUS_WU_IRQ_STS)
aprint_normal_dev(&sc->sc_dev, "Codec GPIO Wakeup IRQ Status\n");
aprint_normal_dev(sc->sc_dev, "Codec GPIO Wakeup IRQ Status\n");
if (intr & ACC_IRQ_STATUS_BM2_IRQ_STS)
aprint_normal_dev(&sc->sc_dev, "Audio Bus Master 2 IRQ Status\n");
aprint_normal_dev(sc->sc_dev, "Audio Bus Master 2 IRQ Status\n");
if (intr & ACC_IRQ_STATUS_BM3_IRQ_STS)
aprint_normal_dev(&sc->sc_dev, "Audio Bus Master 3 IRQ Status\n");
aprint_normal_dev(sc->sc_dev, "Audio Bus Master 3 IRQ Status\n");
if (intr & ACC_IRQ_STATUS_BM5_IRQ_STS)
aprint_normal_dev(&sc->sc_dev, "Audio Bus Master 5 IRQ Status\n");
aprint_normal_dev(sc->sc_dev, "Audio Bus Master 5 IRQ Status\n");
#endif
done:
@ -1320,14 +1321,14 @@ gcscaudio_allocate_dma(struct gcscaudio_softc *sc, size_t size, void **addrp,
if ((error = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0, seglist,
nseg, rsegp, BUS_DMA_WAITOK)) != 0) {
aprint_error_dev(&sc->sc_dev,
aprint_error_dev(sc->sc_dev,
"unable to allocate DMA buffer, error=%d\n", error);
goto fail_alloc;
}
if ((error = bus_dmamem_map(sc->sc_dmat, seglist, nseg, size, addrp,
BUS_DMA_WAITOK | BUS_DMA_COHERENT)) != 0) {
aprint_error_dev(&sc->sc_dev,
aprint_error_dev(sc->sc_dev,
"unable to map DMA buffer, error=%d\n",
error);
goto fail_map;
@ -1335,14 +1336,14 @@ gcscaudio_allocate_dma(struct gcscaudio_softc *sc, size_t size, void **addrp,
if ((error = bus_dmamap_create(sc->sc_dmat, size, nseg, size, 0,
BUS_DMA_WAITOK, mapp)) != 0) {
aprint_error_dev(&sc->sc_dev,
aprint_error_dev(sc->sc_dev,
"unable to create DMA map, error=%d\n", error);
goto fail_create;
}
if ((error = bus_dmamap_load(sc->sc_dmat, *mapp, *addrp, size, NULL,
BUS_DMA_WAITOK)) != 0) {
aprint_error_dev(&sc->sc_dev,
aprint_error_dev(sc->sc_dev,
"unable to load DMA map, error=%d\n", error);
goto fail_load;
}