1 1.12 thorpej /* $NetBSD: wdc_obio.c,v 1.12 2023/12/20 13:55:17 thorpej Exp $ */ 2 1.1 rearnsha 3 1.1 rearnsha /*- 4 1.1 rearnsha * Copyright (c) 1998, 2003, 2005 The NetBSD Foundation, Inc. 5 1.1 rearnsha * All rights reserved. 6 1.1 rearnsha * 7 1.1 rearnsha * This code is derived from software contributed to The NetBSD Foundation 8 1.1 rearnsha * by Charles M. Hannum and by Onno van der Linden. 9 1.1 rearnsha * 10 1.1 rearnsha * Redistribution and use in source and binary forms, with or without 11 1.1 rearnsha * modification, are permitted provided that the following conditions 12 1.1 rearnsha * are met: 13 1.1 rearnsha * 1. Redistributions of source code must retain the above copyright 14 1.1 rearnsha * notice, this list of conditions and the following disclaimer. 15 1.1 rearnsha * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 rearnsha * notice, this list of conditions and the following disclaimer in the 17 1.1 rearnsha * documentation and/or other materials provided with the distribution. 18 1.1 rearnsha * 19 1.1 rearnsha * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 rearnsha * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 rearnsha * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 rearnsha * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 rearnsha * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 rearnsha * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 rearnsha * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 rearnsha * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 rearnsha * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 rearnsha * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 rearnsha * POSSIBILITY OF SUCH DAMAGE. 30 1.1 rearnsha */ 31 1.1 rearnsha 32 1.1 rearnsha #include <sys/cdefs.h> 33 1.12 thorpej __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.12 2023/12/20 13:55:17 thorpej Exp $"); 34 1.1 rearnsha 35 1.1 rearnsha #include <sys/param.h> 36 1.1 rearnsha #include <sys/systm.h> 37 1.1 rearnsha #include <sys/device.h> 38 1.1 rearnsha 39 1.6 dyoung #include <sys/bus.h> 40 1.1 rearnsha #include <machine/intr.h> 41 1.1 rearnsha 42 1.1 rearnsha #include <arm/xscale/i80321var.h> 43 1.1 rearnsha #include <evbarm/iq80321/iq80321reg.h> 44 1.1 rearnsha #include <evbarm/iq80321/obiovar.h> 45 1.1 rearnsha 46 1.1 rearnsha #include <evbarm/iq31244/iq31244reg.h> 47 1.1 rearnsha 48 1.1 rearnsha #include <dev/ic/wdcreg.h> 49 1.1 rearnsha #include <dev/ata/atavar.h> 50 1.1 rearnsha #include <dev/ic/wdcvar.h> 51 1.1 rearnsha 52 1.1 rearnsha struct wdc_obio_softc { 53 1.1 rearnsha struct wdc_softc sc_wdcdev; 54 1.1 rearnsha struct ata_channel *wdc_chanlist[1]; 55 1.1 rearnsha struct ata_channel ata_channel; 56 1.1 rearnsha struct wdc_regs wdc_regs; 57 1.1 rearnsha void *sc_ih; 58 1.1 rearnsha }; 59 1.1 rearnsha 60 1.4 cube static int wdc_obio_probe(device_t, cfdata_t, void *); 61 1.4 cube static void wdc_obio_attach(device_t, device_t, void *); 62 1.1 rearnsha 63 1.4 cube CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc), 64 1.1 rearnsha wdc_obio_probe, wdc_obio_attach, NULL, NULL); 65 1.1 rearnsha 66 1.1 rearnsha static int 67 1.4 cube wdc_obio_probe(device_t parent, cfdata_t match, void *aux) 68 1.1 rearnsha { 69 1.1 rearnsha return 1; 70 1.1 rearnsha } 71 1.1 rearnsha 72 1.1 rearnsha static void 73 1.4 cube wdc_obio_attach(device_t parent, device_t self, void *aux) 74 1.1 rearnsha { 75 1.4 cube struct wdc_obio_softc *sc = device_private(self); 76 1.1 rearnsha struct wdc_regs *wdr; 77 1.1 rearnsha struct obio_attach_args *oba = aux; 78 1.1 rearnsha int i; 79 1.1 rearnsha 80 1.4 cube sc->sc_wdcdev.sc_atac.atac_dev = self; 81 1.1 rearnsha sc->sc_wdcdev.regs = wdr = &sc->wdc_regs; 82 1.1 rearnsha wdr->cmd_iot = oba->oba_st; 83 1.1 rearnsha wdr->ctl_iot = oba->oba_st; 84 1.1 rearnsha if (bus_space_map(wdr->cmd_iot, oba->oba_addr, IQ31244_CFLASH_SIZE, 85 1.1 rearnsha 0, &wdr->cmd_baseioh)) { 86 1.4 cube aprint_error(": couldn't map registers\n"); 87 1.1 rearnsha return; 88 1.1 rearnsha } 89 1.1 rearnsha 90 1.1 rearnsha for (i = 0; i < 8; i++) { 91 1.1 rearnsha if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh, 92 1.1 rearnsha IQ31244_CFLASH_CMD_BASE + i, 1, &wdr->cmd_iohs[i]) != 0) { 93 1.4 cube aprint_error(": couldn't subregion registers\n"); 94 1.1 rearnsha return; 95 1.1 rearnsha } 96 1.1 rearnsha } 97 1.1 rearnsha 98 1.1 rearnsha if (bus_space_subregion(wdr->ctl_iot, wdr->cmd_baseioh, 99 1.1 rearnsha IQ31244_CFLASH_CTL_BASE, 1, &wdr->ctl_ioh) != 0) { 100 1.4 cube aprint_error(": couldn't subregion registers\n"); 101 1.1 rearnsha return; 102 1.1 rearnsha } 103 1.1 rearnsha 104 1.1 rearnsha sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16; 105 1.1 rearnsha 106 1.1 rearnsha sc->sc_wdcdev.sc_atac.atac_pio_cap = 0; 107 1.1 rearnsha sc->wdc_chanlist[0] = &sc->ata_channel; 108 1.1 rearnsha sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist; 109 1.1 rearnsha sc->sc_wdcdev.sc_atac.atac_nchannels = 1; 110 1.9 bouyer sc->sc_wdcdev.wdc_maxdrives = 2; 111 1.1 rearnsha sc->ata_channel.ch_channel = 0; 112 1.1 rearnsha sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac; 113 1.11 jdolecek 114 1.10 jdolecek wdc_init_shadow_regs(wdr); 115 1.1 rearnsha 116 1.4 cube aprint_normal("\n"); 117 1.1 rearnsha 118 1.1 rearnsha /* 119 1.1 rearnsha * The interrupt line is controlled by a jumper. We can't detect 120 1.1 rearnsha * this, except by allowing a request to time out, so assume that 121 1.1 rearnsha * if the config file hasn't specified the IRQ, then the jumper isn't 122 1.1 rearnsha * fitted. 123 1.1 rearnsha */ 124 1.1 rearnsha if (oba->oba_irq != -1) 125 1.1 rearnsha sc->sc_ih = i80321_intr_establish(oba->oba_irq, IPL_BIO, 126 1.1 rearnsha wdcintr, &sc->ata_channel); 127 1.1 rearnsha else { 128 1.1 rearnsha sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ; 129 1.4 cube aprint_normal_dev(self, "Using polled I/O\n"); 130 1.1 rearnsha } 131 1.1 rearnsha 132 1.1 rearnsha wdcattach(&sc->ata_channel); 133 1.1 rearnsha } 134