Make media-bay CD detachable.

This commit is contained in:
tsubai 1999-10-04 22:58:10 +00:00
parent adff5c3f3c
commit eb1c1bdb92
2 changed files with 143 additions and 38 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mediabay.c,v 1.1 1999/07/21 19:20:04 tsubai Exp $ */
/* $NetBSD: mediabay.c,v 1.2 1999/10/04 22:58:10 tsubai Exp $ */
/*-
* Copyright (C) 1999 Tsubai Masanari. All rights reserved.
@ -27,8 +27,12 @@
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/systm.h>
#include <dev/ofw/openfirm.h>
#include <machine/autoconf.h>
#include <machine/pio.h>
@ -38,17 +42,28 @@ struct mediabay_softc {
int sc_node;
u_int *sc_addr;
u_int *sc_fcr;
u_int sc_baseaddr;
struct device *sc_content;
struct proc *sc_kthread;
};
static void mediabay_attach __P((struct device *, struct device *, void *));
static int mediabay_match __P((struct device *, struct cfdata *, void *));
static int mediabay_print __P((void *, const char *));
void mediabay_attach __P((struct device *, struct device *, void *));
int mediabay_match __P((struct device *, struct cfdata *, void *));
int mediabay_print __P((void *, const char *));
void mediabay_attach_content __P((struct mediabay_softc *));
int mediabay_intr __P((void *));
void mediabay_create_kthread __P((void *));
void mediabay_kthread __P((void *));
struct cfattach mediabay_ca = {
sizeof(struct mediabay_softc), mediabay_match, mediabay_attach
};
int mediabay_intr __P((void *));
#ifdef MEDIABAY_DEBUG
# define DPRINTF printf
#else
# define DPRINTF while (0) printf
#endif
#define FCR_MEDIABAY_RESET 0x00000002
#define FCR_MEDIABAY_IDE_ENABLE 0x00000008
@ -56,7 +71,7 @@ int mediabay_intr __P((void *));
#define FCR_MEDIABAY_ENABLE 0x00000080
#define FCR_MEDIABAY_CD_POWER 0x00800000
#define MEDIABAY_ID(x) ((x >> 12) & 0xf)
#define MEDIABAY_ID(x) (((x) >> 12) & 0xf)
#define MEDIABAY_ID_FD 0
#define MEDIABAY_ID_CD 3
#define MEDIABAY_ID_NONE 7
@ -84,22 +99,39 @@ mediabay_attach(parent, self, aux)
void *aux;
{
struct mediabay_softc *sc = (struct mediabay_softc *)self;
struct confargs ca;
int irq, child;
u_int fcr;
u_int reg[20], intr[5];
char name[32];
struct confargs *ca = aux;
int irq;
bcopy(aux, &ca, sizeof(ca));
ca.ca_reg[0] += ca.ca_baseaddr;
sc->sc_addr = mapiodev(ca.ca_reg[0], NBPG);
ca->ca_reg[0] += ca->ca_baseaddr;
sc->sc_addr = mapiodev(ca->ca_reg[0], NBPG);
sc->sc_fcr = sc->sc_addr + 1;
sc->sc_node = ca.ca_node;
irq = ca.ca_intr[0];
sc->sc_node = ca->ca_node;
sc->sc_baseaddr = ca->ca_baseaddr;
irq = ca->ca_intr[0];
printf(" irq %d\n", irq);
intr_establish(irq, IST_LEVEL, IPL_BIO, mediabay_intr, sc);
kthread_create(mediabay_create_kthread, sc);
sc->sc_content = NULL;
if (MEDIABAY_ID(in32rb(sc->sc_addr)) != MEDIABAY_ID_NONE)
mediabay_attach_content(sc);
}
void
mediabay_attach_content(sc)
struct mediabay_softc *sc;
{
int child;
u_int fcr;
struct device *content;
struct confargs ca;
u_int reg[20], intr[5];
char name[32];
fcr = in32rb(sc->sc_fcr);
fcr |= FCR_MEDIABAY_ENABLE | FCR_MEDIABAY_RESET;
out32rb(sc->sc_fcr, fcr);
@ -113,16 +145,13 @@ mediabay_attach(parent, self, aux)
out32rb(sc->sc_fcr, fcr);
delay(50000);
/* XXX */
if (MEDIABAY_ID(in32rb(sc->sc_addr)) == MEDIABAY_ID_NONE)
return;
for (child = OF_child(sc->sc_node); child; child = OF_peer(child)) {
bzero(name, sizeof(name));
if (OF_getprop(child, "name", name, sizeof(name)) == -1)
continue;
ca.ca_name = name;
ca.ca_node = child;
ca.ca_baseaddr = sc->sc_baseaddr;
ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
@ -133,8 +162,17 @@ mediabay_attach(parent, self, aux)
ca.ca_reg = reg;
ca.ca_intr = intr;
config_found(self, &ca, mediabay_print);
content = config_found(&sc->sc_dev, &ca, mediabay_print);
if (content) {
sc->sc_content = content;
return;
}
}
/* No devices found. Disable media-bay. */
fcr &= ~(FCR_MEDIABAY_ENABLE | FCR_MEDIABAY_IDE_ENABLE |
FCR_MEDIABAY_CD_POWER | FCR_MEDIABAY_FD_ENABLE);
out32rb(sc->sc_fcr, fcr);
}
int
@ -144,13 +182,10 @@ mediabay_print(aux, mediabay)
{
struct confargs *ca = aux;
if (mediabay)
printf("%s at %s", ca->ca_name, mediabay);
if (ca->ca_nreg > 0)
if (mediabay == NULL && ca->ca_nreg > 0)
printf(" offset 0x%x", ca->ca_reg[0]);
return UNCONF;
return QUIET;
}
int
@ -158,26 +193,67 @@ mediabay_intr(v)
void *v;
{
struct mediabay_softc *sc = v;
u_int x;
printf("%s: ", sc->sc_dev.dv_xname);
wakeup(&sc->sc_kthread);
return 1;
}
void
mediabay_create_kthread(v)
void *v;
{
struct mediabay_softc *sc = v;
kthread_create1(mediabay_kthread, sc, &sc->sc_kthread, "media-bay");
}
void
mediabay_kthread(v)
void *v;
{
struct mediabay_softc *sc = v;
u_int x, fcr;
sleep:
tsleep(&sc->sc_kthread, PRIBIO, "mbayev", 0);
/* sleep 0.25 sec */
tsleep(mediabay_kthread, PRIBIO, "mbayev", hz/4);
DPRINTF("%s: ", sc->sc_dev.dv_xname);
x = in32rb(sc->sc_addr);
switch (MEDIABAY_ID(x)) {
case MEDIABAY_ID_NONE:
printf("removed\n");
DPRINTF("removed\n");
if (sc->sc_content != NULL) {
config_detach(sc->sc_content, DETACH_FORCE);
DPRINTF("%s: detach done\n", sc->sc_dev.dv_xname);
sc->sc_content = NULL;
/* disable media-bay */
fcr = in32rb(sc->sc_fcr);
fcr &= ~(FCR_MEDIABAY_ENABLE |
FCR_MEDIABAY_IDE_ENABLE |
FCR_MEDIABAY_CD_POWER |
FCR_MEDIABAY_FD_ENABLE);
out32rb(sc->sc_fcr, fcr);
}
break;
case MEDIABAY_ID_FD:
printf("FD inserted\n");
DPRINTF("FD inserted\n");
break;
case MEDIABAY_ID_CD:
printf("CD inserted\n");
DPRINTF("CD inserted\n");
if (sc->sc_content == NULL)
mediabay_attach_content(sc);
break;
default:
printf("unknown event (0x%x)\n", x);
}
return 1;
goto sleep;
}
/* PBG3: 0x7025X0c0 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: wdc_obio.c,v 1.4 1999/06/14 08:53:06 tsubai Exp $ */
/* $NetBSD: wdc_obio.c,v 1.5 1999/10/04 22:58:10 tsubai Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -68,13 +68,16 @@ struct wdc_obio_softc {
struct channel_softc wdc_channel;
dbdma_regmap_t *sc_dmareg;
dbdma_command_t *sc_dmacmd;
void *sc_ih;
};
int wdc_obio_probe __P((struct device *, struct cfdata *, void *));
void wdc_obio_attach __P((struct device *, struct device *, void *));
int wdc_obio_probe __P((struct device *, struct cfdata *, void *));
void wdc_obio_attach __P((struct device *, struct device *, void *));
int wdc_obio_detach __P((struct device *, int));
struct cfattach wdc_obio_ca = {
sizeof(struct wdc_obio_softc), wdc_obio_probe, wdc_obio_attach
sizeof(struct wdc_obio_softc), wdc_obio_probe, wdc_obio_attach,
wdc_obio_detach, wdcactivate
};
static int wdc_obio_dma_init __P((void *, int, int, void *, size_t, int));
@ -152,7 +155,7 @@ wdc_obio_attach(parent, self, aux)
chp->data32ioh = chp->cmd_ioh;
#endif
intr_establish(intr, IST_LEVEL, IPL_BIO, wdcintr, chp);
sc->sc_ih = intr_establish(intr, IST_LEVEL, IPL_BIO, wdcintr, chp);
if (use_dma) {
sc->sc_dmacmd = dbdma_alloc(sizeof(dbdma_command_t) * 20);
@ -182,6 +185,32 @@ wdc_obio_attach(parent, self, aux)
wdcattach(chp);
}
int
wdc_obio_detach(self, flags)
struct device *self;
int flags;
{
struct wdc_obio_softc *sc = (void *)self;
struct channel_softc *chp = &sc->wdc_channel;
int error;
if ((error = wdcdetach(self, flags)) != 0)
return error;
intr_disestablish(sc->sc_ih);
free(sc->wdc_channel.ch_queue, M_DEVBUF);
/* Unmap our i/o space. */
bus_space_unmap(chp->cmd_iot, chp->cmd_ioh, WDC_REG_NPORTS);
/* Unmap DMA registers. */
/* XXX unmapiodev(sc->sc_dmareg); */
/* XXX free(sc->sc_dmacmd); */
return 0;
}
static int
wdc_obio_dma_init(v, channel, drive, databuf, datalen, read)
void *v;