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