Home | History | Annotate | Line # | Download | only in obio
wdc_obio.c revision 1.8
      1  1.8    fredb /*	$NetBSD: wdc_obio.c,v 1.8 2003/12/14 15:31:23 fredb Exp $ */
      2  1.1    shiba 
      3  1.1    shiba /*
      4  1.1    shiba  * Copyright (c) 2002 Takeshi Shibagaki  All rights reserved.
      5  1.1    shiba  *
      6  1.1    shiba  * mac68k OBIO-IDE attachment created by Takeshi Shibagaki
      7  1.1    shiba  *
      8  1.1    shiba  * Redistribution and use in source and binary forms, with or without
      9  1.1    shiba  * modification, are permitted provided that the following conditions
     10  1.1    shiba  * are met:
     11  1.1    shiba  * 1. Redistributions of source code must retain the above copyright
     12  1.1    shiba  *    notice, this list of conditions and the following disclaimer.
     13  1.1    shiba  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1    shiba  *    notice, this list of conditions and the following disclaimer in the
     15  1.1    shiba  *    documentation and/or other materials provided with the distribution.
     16  1.1    shiba  * 3. All advertising materials mentioning features or use of this software
     17  1.1    shiba  *    must display the following acknowledgement:
     18  1.1    shiba  *	This product includes software developed by Charles M. Hannum.
     19  1.1    shiba  * 4. The name of the author may not be used to endorse or promote products
     20  1.1    shiba  *    derived from this software without specific prior written permission.
     21  1.1    shiba  *
     22  1.1    shiba  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1    shiba  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1    shiba  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1    shiba  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1    shiba  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1    shiba  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1    shiba  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1    shiba  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1    shiba  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1    shiba  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1    shiba  */
     33  1.4    lukem 
     34  1.4    lukem #include <sys/cdefs.h>
     35  1.8    fredb __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.8 2003/12/14 15:31:23 fredb Exp $");
     36  1.1    shiba 
     37  1.1    shiba #include <sys/types.h>
     38  1.1    shiba #include <sys/param.h>
     39  1.1    shiba #include <sys/systm.h>
     40  1.1    shiba #include <sys/device.h>
     41  1.1    shiba #include <sys/malloc.h>
     42  1.1    shiba #include <sys/kernel.h>
     43  1.1    shiba #include <sys/callout.h>
     44  1.1    shiba 
     45  1.1    shiba #include <machine/bus.h>
     46  1.1    shiba #include <machine/intr.h>
     47  1.1    shiba #include <machine/cpu.h>
     48  1.1    shiba #include <machine/viareg.h>
     49  1.1    shiba 
     50  1.1    shiba #include <mac68k/obio/obiovar.h>
     51  1.1    shiba 
     52  1.1    shiba #include <dev/ata/atavar.h>
     53  1.1    shiba #include <dev/ic/wdcvar.h>
     54  1.1    shiba 
     55  1.8    fredb #define	WDC_OBIO_REG_NPORTS	0x40
     56  1.1    shiba #define	WDC_OBIO_AUXREG_OFFSET	0x38
     57  1.1    shiba #define	WDC_OBIO_AUXREG_NPORTS	1
     58  1.1    shiba #define	WDC_OBIO_ISR_OFFSET	0x101
     59  1.1    shiba #define	WDC_OBIO_ISR_NPORTS	1
     60  1.1    shiba 
     61  1.1    shiba static u_long	IDEBase = 0x50f1a000;
     62  1.1    shiba 
     63  1.1    shiba /*
     64  1.1    shiba  * XXX This code currently doesn't even try to allow 32-bit data port use.
     65  1.1    shiba  */
     66  1.1    shiba 
     67  1.1    shiba struct wdc_obio_softc {
     68  1.1    shiba 	struct  wdc_softc sc_wdcdev;
     69  1.1    shiba 	struct  channel_softc *wdc_chanptr;
     70  1.1    shiba 	struct  channel_softc wdc_channel;
     71  1.1    shiba 	void    *sc_ih;
     72  1.1    shiba };
     73  1.1    shiba 
     74  1.8    fredb int	wdc_obio_match	(struct device *, struct cfdata *, void *);
     75  1.8    fredb void	wdc_obio_attach	(struct device *, struct device *, void *);
     76  1.8    fredb void	wdc_obio_intr (void *);
     77  1.1    shiba 
     78  1.3  thorpej CFATTACH_DECL(wdc_obio, sizeof(struct wdc_obio_softc),
     79  1.3  thorpej     wdc_obio_match, wdc_obio_attach, NULL, NULL);
     80  1.1    shiba 
     81  1.1    shiba int
     82  1.1    shiba wdc_obio_match(parent, match, aux)
     83  1.1    shiba 	struct device *parent;
     84  1.1    shiba 	struct cfdata *match;
     85  1.1    shiba 	void *aux;
     86  1.1    shiba {
     87  1.1    shiba 	struct obio_attach_args *oa = (struct obio_attach_args *) aux;
     88  1.1    shiba 	struct channel_softc ch;
     89  1.1    shiba 	static int wdc_matched = 0;
     90  1.8    fredb 	int i, result = 0;
     91  1.1    shiba 
     92  1.1    shiba 	memset(&ch, 0, sizeof(ch));
     93  1.1    shiba 
     94  1.1    shiba 	switch (current_mac_model->machineid) {
     95  1.1    shiba 	case MACH_MACPB150:
     96  1.1    shiba 	case MACH_MACPB190:
     97  1.1    shiba 	case MACH_MACPB190CS:
     98  1.1    shiba 	case MACH_MACP580:
     99  1.1    shiba 	case MACH_MACQ630:
    100  1.1    shiba 		ch.cmd_iot = ch.ctl_iot = oa->oa_tag;
    101  1.1    shiba 
    102  1.1    shiba 		if (bus_space_map(ch.cmd_iot, IDEBase, WDC_OBIO_REG_NPORTS,
    103  1.8    fredb 				0, &ch.cmd_baseioh))
    104  1.1    shiba 			return 0;
    105  1.1    shiba 
    106  1.8    fredb 		mac68k_bus_space_handle_swapped(ch.cmd_iot, &ch.cmd_baseioh);
    107  1.1    shiba 
    108  1.8    fredb 		for (i = 0; i < WDC_NREG; i++) {
    109  1.8    fredb 			if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh,
    110  1.8    fredb 					    4 * i, 4, &ch.cmd_iohs[i]) != 0) {
    111  1.8    fredb 				return 0;
    112  1.8    fredb 			}
    113  1.8    fredb 		}
    114  1.8    fredb 
    115  1.8    fredb 
    116  1.8    fredb 		if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh,
    117  1.1    shiba 				        WDC_OBIO_AUXREG_OFFSET,
    118  1.1    shiba 					WDC_OBIO_AUXREG_NPORTS, &ch.ctl_ioh))
    119  1.1    shiba 			return 0;
    120  1.1    shiba 
    121  1.1    shiba 		result = wdcprobe(&ch);
    122  1.1    shiba 
    123  1.8    fredb 		bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh, WDC_OBIO_REG_NPORTS);
    124  1.1    shiba 
    125  1.1    shiba 		if (result)
    126  1.1    shiba 			wdc_matched = 1;
    127  1.1    shiba 		return (result);
    128  1.1    shiba 	}
    129  1.1    shiba 	return 0;
    130  1.1    shiba }
    131  1.1    shiba 
    132  1.1    shiba static bus_space_tag_t		wdc_obio_isr_tag;
    133  1.1    shiba static bus_space_handle_t	wdc_obio_isr_hdl;
    134  1.1    shiba static struct channel_softc	*ch_sc = NULL;
    135  1.1    shiba 
    136  1.1    shiba void
    137  1.1    shiba wdc_obio_intr(arg)
    138  1.1    shiba 	void *arg;
    139  1.1    shiba {
    140  1.1    shiba 	unsigned char status;
    141  1.1    shiba 
    142  1.1    shiba 	status = bus_space_read_1(wdc_obio_isr_tag,
    143  1.1    shiba 				  wdc_obio_isr_hdl, 0);
    144  1.1    shiba 	if (status & 0x20) {
    145  1.1    shiba 		wdcintr(ch_sc);
    146  1.1    shiba 		bus_space_write_1(wdc_obio_isr_tag,
    147  1.1    shiba 				  wdc_obio_isr_hdl, 0, status&~0x20);
    148  1.1    shiba 	}
    149  1.1    shiba }
    150  1.1    shiba 
    151  1.1    shiba void
    152  1.1    shiba wdc_obio_attach(parent, self, aux)
    153  1.1    shiba 	struct device *parent;
    154  1.1    shiba 	struct device *self;
    155  1.1    shiba 	void *aux;
    156  1.1    shiba {
    157  1.1    shiba 	struct wdc_obio_softc *sc = (void *)self;
    158  1.1    shiba 	struct obio_attach_args *oa = aux;
    159  1.1    shiba 	struct channel_softc *chp = &sc->wdc_channel;
    160  1.8    fredb 	int i;
    161  1.1    shiba 
    162  1.1    shiba 	oa->oa_addr = IDEBase;
    163  1.1    shiba 	sc->wdc_channel.cmd_iot = sc->wdc_channel.ctl_iot = oa->oa_tag;
    164  1.1    shiba 
    165  1.1    shiba 	if (bus_space_map(sc->wdc_channel.cmd_iot, oa->oa_addr,
    166  1.8    fredb 		      WDC_OBIO_REG_NPORTS, 0, &sc->wdc_channel.cmd_baseioh)) {
    167  1.1    shiba 		printf("%s: couldn't map registers\n",
    168  1.1    shiba 			sc->sc_wdcdev.sc_dev.dv_xname);
    169  1.1    shiba 		return;
    170  1.1    shiba 	}
    171  1.1    shiba 
    172  1.8    fredb 	mac68k_bus_space_handle_swapped(sc->wdc_channel.cmd_iot,
    173  1.8    fredb 				  &sc->wdc_channel.cmd_baseioh);
    174  1.8    fredb 
    175  1.8    fredb 	for (i = 0; i < WDC_NREG; i++) {
    176  1.8    fredb 		if (bus_space_subregion(sc->wdc_channel.cmd_iot,
    177  1.8    fredb 				    sc->wdc_channel.cmd_baseioh, 4 * i, 4,
    178  1.8    fredb 				    &sc->wdc_channel.cmd_iohs[i]) != 0) {
    179  1.8    fredb 			printf("%s: unable to subregion control register\n",
    180  1.8    fredb 			    sc->sc_wdcdev.sc_dev.dv_xname);
    181  1.8    fredb 			return;
    182  1.8    fredb 		}
    183  1.8    fredb 	}
    184  1.1    shiba 
    185  1.1    shiba 	if (bus_space_subregion(sc->wdc_channel.cmd_iot,
    186  1.8    fredb 				sc->wdc_channel.cmd_baseioh,
    187  1.8    fredb 				WDC_OBIO_AUXREG_OFFSET, WDC_OBIO_AUXREG_NPORTS,
    188  1.8    fredb 				&sc->wdc_channel.ctl_ioh)) {
    189  1.8    fredb 		printf("%s: unable to subregion aux register\n",
    190  1.8    fredb 		    sc->sc_wdcdev.sc_dev.dv_xname);
    191  1.1    shiba 		return;
    192  1.8    fredb 	}
    193  1.1    shiba 
    194  1.1    shiba     	wdc_obio_isr_tag = oa->oa_tag;
    195  1.1    shiba 
    196  1.1    shiba 	if (bus_space_map(wdc_obio_isr_tag,
    197  1.1    shiba 			  oa->oa_addr+WDC_OBIO_ISR_OFFSET,
    198  1.1    shiba 			  WDC_OBIO_ISR_NPORTS, 0, &wdc_obio_isr_hdl)) {
    199  1.1    shiba 		printf("%s: couldn't map intr status register\n",
    200  1.1    shiba 			sc->sc_wdcdev.sc_dev.dv_xname);
    201  1.1    shiba 		return;
    202  1.1    shiba 	}
    203  1.1    shiba 
    204  1.1    shiba 	switch (current_mac_model->machineid) {
    205  1.1    shiba 	case MACH_MACP580:
    206  1.1    shiba 	case MACH_MACQ630:
    207  1.1    shiba 		/*
    208  1.1    shiba 		 * Quadra/Performa IDE generates pseudo Nubus intr at slot F
    209  1.1    shiba 		 */
    210  1.1    shiba 		printf(" (Quadra/Performa series IDE interface)");
    211  1.1    shiba 
    212  1.1    shiba 		add_nubus_intr(0xf, (void (*)(void*))wdc_obio_intr, (void *)sc);
    213  1.1    shiba 
    214  1.1    shiba 		break;
    215  1.1    shiba 	case MACH_MACPB150:
    216  1.1    shiba 	case MACH_MACPB190:
    217  1.1    shiba 	case MACH_MACPB190CS:
    218  1.1    shiba 		/*
    219  1.1    shiba 		 * PowerBook IDE generates pseudo NuBus intr at slot C
    220  1.1    shiba 		 */
    221  1.1    shiba 		printf(" (PowerBook series IDE interface)");
    222  1.1    shiba 
    223  1.1    shiba 		add_nubus_intr(0xc, (void (*)(void*))wdc_obio_intr, (void *)sc);
    224  1.1    shiba 
    225  1.1    shiba 		break;
    226  1.1    shiba 	}
    227  1.1    shiba 
    228  1.1    shiba 	ch_sc = chp;
    229  1.1    shiba 	if (sc->sc_wdcdev.sc_dev.dv_cfdata->cf_flags & WDC_CAPABILITY_NOIRQ)
    230  1.1    shiba 		sc->sc_wdcdev.cap |= WDC_CAPABILITY_NOIRQ;
    231  1.1    shiba 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
    232  1.1    shiba 	sc->sc_wdcdev.PIO_cap = 0;
    233  1.1    shiba 	sc->wdc_chanptr = chp;
    234  1.1    shiba 	sc->sc_wdcdev.channels = &sc->wdc_chanptr;
    235  1.1    shiba 	sc->sc_wdcdev.nchannels = 1;
    236  1.1    shiba 	chp->channel = 0;
    237  1.1    shiba 	chp->wdc = &sc->sc_wdcdev;
    238  1.1    shiba 	chp->ch_queue = malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
    239  1.1    shiba 
    240  1.1    shiba 	if (chp->ch_queue == NULL) {
    241  1.1    shiba 		printf("%s: can't allocate memory for command queue",
    242  1.1    shiba 			sc->sc_wdcdev.sc_dev.dv_xname);
    243  1.1    shiba 		return;
    244  1.1    shiba 	}
    245  1.1    shiba 
    246  1.1    shiba 	printf("\n");
    247  1.1    shiba 
    248  1.7   bouyer 	wdcattach(chp);
    249  1.1    shiba }
    250