xref: /netbsd-src/sys/arch/evbarm/tsarm/wdc_ts.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: wdc_ts.c,v 1.11 2017/10/20 07:06:06 jdolecek 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.11 2017/10/20 07:06:06 jdolecek Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/malloc.h>
39 
40 #include <sys/bus.h>
41 #include <machine/intr.h>
42 
43 #include <arm/ep93xx/ep93xxvar.h>
44 
45 #include <dev/ic/wdcreg.h>
46 #include <dev/ata/atavar.h>
47 #include <dev/ic/wdcvar.h>
48 #include <evbarm/tsarm/tspldvar.h>
49 
50 struct wdc_ts_softc {
51 	struct	wdc_softc sc_wdcdev;
52 	struct	ata_channel *wdc_chanlist[1];
53 	struct	ata_channel ata_channel;
54 	struct	wdc_regs wdc_regs;
55 	void	*sc_ih;
56 };
57 
58 static int	wdc_ts_probe(device_t, cfdata_t, void *);
59 static void	wdc_ts_attach(device_t, device_t, void *);
60 
61 CFATTACH_DECL_NEW(wdc_ts, sizeof(struct wdc_ts_softc),
62     wdc_ts_probe, wdc_ts_attach, NULL, NULL);
63 
64 static int
65 wdc_ts_probe(device_t parent, cfdata_t match, void *aux)
66 {
67 	return 1;
68 }
69 
70 static void
71 wdc_ts_attach(device_t parent, device_t self, void *aux)
72 {
73 	struct wdc_ts_softc *sc = device_private(self);
74 	struct wdc_regs *wdr;
75 	struct tspld_attach_args *ta = aux;
76 	int i;
77 
78 	sc->sc_wdcdev.sc_atac.atac_dev = self;
79 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
80 	wdr->cmd_iot = ta->ta_iot;
81 	wdr->ctl_iot = ta->ta_iot;
82 	if (bus_space_map(wdr->cmd_iot, 0x11000000, 8, 0, &wdr->cmd_baseioh) ||
83 	    bus_space_map(wdr->ctl_iot, 0x10400006, 1, 0, &wdr->ctl_ioh)) {
84 		aprint_error(": couldn't map registers\n");
85 		return;
86 	}
87 
88 	for (i = 0; i < 8; i++) {
89 		if (bus_space_subregion(wdr->cmd_iot,
90 		      wdr->cmd_baseioh, i, 1, &wdr->cmd_iohs[i]) != 0) {
91 			aprint_error(": couldn't subregion registers\n");
92 			return;
93 		}
94 	}
95 
96 
97 	if (bus_space_map(wdr->cmd_iot, 0x21000000, 2, 0, &wdr->cmd_iohs[0])) {
98 		aprint_error(": couldn't map registers\n");
99 		return;
100 	}
101 
102 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_PREATA;
103 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
104 
105 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
106 	sc->wdc_chanlist[0] = &sc->ata_channel;
107 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
108 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
109 	sc->sc_wdcdev.wdc_maxdrives = 2;
110 	sc->ata_channel.ch_channel = 0;
111 	sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
112 
113 	wdc_init_shadow_regs(wdr);
114 
115 	aprint_normal("\n");
116 
117 	sc->sc_ih = ep93xx_intr_establish(32, IPL_BIO, wdcintr, &sc->ata_channel);
118 
119 	wdcattach(&sc->ata_channel);
120 }
121