Home | History | Annotate | Line # | Download | only in obio
wdc_obio.c revision 1.20.4.1
      1  1.20.4.1   simonb /*	$NetBSD: wdc_obio.c,v 1.20.4.1 2006/04/22 11:37:41 simonb 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.20.4.1   simonb __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.20.4.1 2006/04/22 11:37:41 simonb 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.16  thorpej 	struct  ata_channel *sc_chanlist[1];
     70      1.16  thorpej 	struct  ata_channel sc_channel;
     71      1.16  thorpej 	struct	ata_queue sc_chqueue;
     72      1.16  thorpej 	struct	wdc_regs sc_wdc_regs;
     73       1.1    shiba 	void    *sc_ih;
     74       1.1    shiba };
     75       1.1    shiba 
     76      1.18      chs int	wdc_obio_match(struct device *, struct cfdata *, void *);
     77      1.18      chs void	wdc_obio_attach(struct device *, struct device *, void *);
     78      1.18      chs void	wdc_obio_intr(void *);
     79       1.1    shiba 
     80       1.3  thorpej CFATTACH_DECL(wdc_obio, sizeof(struct wdc_obio_softc),
     81       1.3  thorpej     wdc_obio_match, wdc_obio_attach, NULL, NULL);
     82       1.1    shiba 
     83      1.18      chs static bus_space_tag_t		wdc_obio_isr_tag;
     84      1.18      chs static bus_space_handle_t	wdc_obio_isr_hdl;
     85      1.18      chs static struct ata_channel	*ch_sc;
     86      1.18      chs 
     87       1.1    shiba int
     88      1.18      chs wdc_obio_match(struct device *parent, struct cfdata *match, void *aux)
     89       1.1    shiba {
     90       1.1    shiba 	struct obio_attach_args *oa = (struct obio_attach_args *) aux;
     91      1.16  thorpej 	struct ata_channel ch;
     92      1.16  thorpej 	struct wdc_softc wdc;
     93      1.16  thorpej 	struct wdc_regs wdr;
     94       1.1    shiba 	static int wdc_matched = 0;
     95       1.8    fredb 	int i, result = 0;
     96       1.1    shiba 
     97      1.16  thorpej 	memset(&wdc, 0, sizeof(wdc));
     98       1.1    shiba 	memset(&ch, 0, sizeof(ch));
     99      1.17  thorpej 	ch.ch_atac = &wdc.sc_atac;
    100      1.16  thorpej 	wdc.regs = &wdr;
    101       1.1    shiba 
    102       1.1    shiba 	switch (current_mac_model->machineid) {
    103       1.1    shiba 	case MACH_MACPB150:
    104       1.1    shiba 	case MACH_MACPB190:
    105       1.1    shiba 	case MACH_MACPB190CS:
    106       1.1    shiba 	case MACH_MACP580:
    107       1.1    shiba 	case MACH_MACQ630:
    108      1.16  thorpej 		wdr.cmd_iot = wdr.ctl_iot = oa->oa_tag;
    109       1.1    shiba 
    110      1.16  thorpej 		if (bus_space_map(wdr.cmd_iot, IDEBase, WDC_OBIO_REG_NPORTS,
    111      1.16  thorpej 				0, &wdr.cmd_baseioh))
    112       1.1    shiba 			return 0;
    113       1.1    shiba 
    114      1.16  thorpej 		mac68k_bus_space_handle_swapped(wdr.cmd_iot, &wdr.cmd_baseioh);
    115       1.1    shiba 
    116       1.8    fredb 		for (i = 0; i < WDC_NREG; i++) {
    117      1.16  thorpej 			if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh,
    118      1.16  thorpej 					    4 * i, 4, &wdr.cmd_iohs[i]) != 0) {
    119       1.8    fredb 				return 0;
    120       1.8    fredb 			}
    121       1.8    fredb 		}
    122      1.15  thorpej 		wdc_init_shadow_regs(&ch);
    123       1.8    fredb 
    124       1.8    fredb 
    125      1.16  thorpej 		if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh,
    126       1.1    shiba 				        WDC_OBIO_AUXREG_OFFSET,
    127      1.13       he 					WDC_OBIO_AUXREG_NPORTS,
    128      1.16  thorpej 					&wdr.ctl_ioh))
    129       1.1    shiba 			return 0;
    130       1.1    shiba 
    131       1.1    shiba 		result = wdcprobe(&ch);
    132       1.1    shiba 
    133      1.16  thorpej 		bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_OBIO_REG_NPORTS);
    134       1.1    shiba 
    135       1.1    shiba 		if (result)
    136       1.1    shiba 			wdc_matched = 1;
    137       1.1    shiba 		return (result);
    138       1.1    shiba 	}
    139       1.1    shiba 	return 0;
    140       1.1    shiba }
    141       1.1    shiba 
    142       1.1    shiba void
    143      1.18      chs wdc_obio_attach(struct device *parent, struct device *self, void *aux)
    144       1.1    shiba {
    145       1.1    shiba 	struct wdc_obio_softc *sc = (void *)self;
    146      1.16  thorpej 	struct wdc_regs *wdr;
    147       1.1    shiba 	struct obio_attach_args *oa = aux;
    148      1.16  thorpej 	struct ata_channel *chp = &sc->sc_channel;
    149       1.8    fredb 	int i;
    150       1.1    shiba 
    151      1.16  thorpej 	sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
    152      1.16  thorpej 
    153       1.1    shiba 	oa->oa_addr = IDEBase;
    154      1.16  thorpej 	wdr->cmd_iot = wdr->ctl_iot = oa->oa_tag;
    155       1.1    shiba 
    156      1.16  thorpej 	if (bus_space_map(wdr->cmd_iot, oa->oa_addr,
    157      1.16  thorpej 		      WDC_OBIO_REG_NPORTS, 0, &wdr->cmd_baseioh)) {
    158       1.1    shiba 		printf("%s: couldn't map registers\n",
    159      1.17  thorpej 			sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    160       1.1    shiba 		return;
    161       1.1    shiba 	}
    162       1.1    shiba 
    163      1.16  thorpej 	mac68k_bus_space_handle_swapped(wdr->cmd_iot,
    164      1.16  thorpej 				  &wdr->cmd_baseioh);
    165       1.8    fredb 
    166       1.8    fredb 	for (i = 0; i < WDC_NREG; i++) {
    167      1.16  thorpej 		if (bus_space_subregion(wdr->cmd_iot,
    168      1.16  thorpej 				    wdr->cmd_baseioh, 4 * i, 4,
    169      1.16  thorpej 				    &wdr->cmd_iohs[i]) != 0) {
    170       1.8    fredb 			printf("%s: unable to subregion control register\n",
    171      1.17  thorpej 			    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    172       1.8    fredb 			return;
    173       1.8    fredb 		}
    174       1.8    fredb 	}
    175      1.16  thorpej 	wdc_init_shadow_regs(&sc->sc_channel);
    176       1.1    shiba 
    177      1.16  thorpej 	if (bus_space_subregion(wdr->cmd_iot,
    178      1.16  thorpej 				wdr->cmd_baseioh,
    179       1.8    fredb 				WDC_OBIO_AUXREG_OFFSET, WDC_OBIO_AUXREG_NPORTS,
    180      1.16  thorpej 				&wdr->ctl_ioh)) {
    181       1.8    fredb 		printf("%s: unable to subregion aux register\n",
    182      1.17  thorpej 		    sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    183       1.1    shiba 		return;
    184       1.8    fredb 	}
    185       1.1    shiba 
    186       1.1    shiba     	wdc_obio_isr_tag = oa->oa_tag;
    187       1.1    shiba 
    188       1.1    shiba 	if (bus_space_map(wdc_obio_isr_tag,
    189       1.1    shiba 			  oa->oa_addr+WDC_OBIO_ISR_OFFSET,
    190       1.1    shiba 			  WDC_OBIO_ISR_NPORTS, 0, &wdc_obio_isr_hdl)) {
    191       1.1    shiba 		printf("%s: couldn't map intr status register\n",
    192      1.17  thorpej 			sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
    193       1.1    shiba 		return;
    194       1.1    shiba 	}
    195       1.1    shiba 
    196       1.1    shiba 	switch (current_mac_model->machineid) {
    197       1.1    shiba 	case MACH_MACP580:
    198       1.1    shiba 	case MACH_MACQ630:
    199       1.1    shiba 		/*
    200       1.1    shiba 		 * Quadra/Performa IDE generates pseudo Nubus intr at slot F
    201       1.1    shiba 		 */
    202       1.1    shiba 		printf(" (Quadra/Performa series IDE interface)");
    203       1.1    shiba 
    204       1.1    shiba 		add_nubus_intr(0xf, (void (*)(void*))wdc_obio_intr, (void *)sc);
    205       1.1    shiba 
    206       1.1    shiba 		break;
    207       1.1    shiba 	case MACH_MACPB150:
    208       1.1    shiba 	case MACH_MACPB190:
    209       1.1    shiba 	case MACH_MACPB190CS:
    210       1.1    shiba 		/*
    211       1.1    shiba 		 * PowerBook IDE generates pseudo NuBus intr at slot C
    212       1.1    shiba 		 */
    213       1.1    shiba 		printf(" (PowerBook series IDE interface)");
    214       1.1    shiba 
    215       1.1    shiba 		add_nubus_intr(0xc, (void (*)(void*))wdc_obio_intr, (void *)sc);
    216       1.1    shiba 
    217       1.1    shiba 		break;
    218       1.1    shiba 	}
    219       1.1    shiba 
    220       1.1    shiba 	ch_sc = chp;
    221  1.20.4.1   simonb 	if (device_cfdata(&sc->sc_wdcdev.sc_atac.atac_dev)->cf_flags &
    222  1.20.4.1   simonb 	    ATAC_CAP_NOIRQ)
    223      1.17  thorpej 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
    224      1.17  thorpej 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    225      1.17  thorpej 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    226      1.16  thorpej 	sc->sc_chanlist[0] = chp;
    227      1.17  thorpej 	sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
    228      1.17  thorpej 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    229      1.12  thorpej 	chp->ch_channel = 0;
    230      1.17  thorpej 	chp->ch_atac = &sc->sc_wdcdev.sc_atac;
    231      1.16  thorpej 	chp->ch_queue = &sc->sc_chqueue;
    232      1.20   bouyer 	chp->ch_ndrive = 2;
    233       1.1    shiba 
    234       1.1    shiba 	printf("\n");
    235       1.1    shiba 
    236       1.7   bouyer 	wdcattach(chp);
    237       1.1    shiba }
    238      1.18      chs 
    239      1.18      chs void
    240      1.18      chs wdc_obio_intr(void *arg)
    241      1.18      chs {
    242      1.18      chs 	unsigned char status;
    243      1.18      chs 
    244      1.18      chs 	status = bus_space_read_1(wdc_obio_isr_tag,
    245      1.18      chs 				  wdc_obio_isr_hdl, 0);
    246      1.18      chs 	if (status & 0x20) {
    247      1.18      chs 		wdcintr(ch_sc);
    248      1.18      chs 		bus_space_write_1(wdc_obio_isr_tag,
    249      1.18      chs 				  wdc_obio_isr_hdl, 0, status&~0x20);
    250      1.18      chs 	}
    251      1.18      chs }
    252