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