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