1/* $NetBSD: wdc_upc.c,v 1.25 2008/03/18 20:46:36 cube Exp $ */
2/*-
3 * Copyright (c) 2000 Ben Harris
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/* This file is part of NetBSD/arm26 -- a port of NetBSD to ARM2/3 machines. */
29
30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: wdc_upc.c,v 1.25 2008/03/18 20:46:36 cube Exp $");
32
33#include <sys/param.h>
34#include <sys/device.h>
35#include <sys/malloc.h>
36#include <sys/systm.h>
37
38#include <sys/bus.h>
39#include <sys/intr.h>
40
41#include <dev/ata/atavar.h> /* XXX needed by wdcvar.h */
42
43#include <dev/ic/upcvar.h>
44#include <dev/ic/wdcreg.h>
45#include <dev/ic/wdcvar.h>
46
47static int wdc_upc_match(device_t, cfdata_t, void *);
48static void wdc_upc_attach(device_t, device_t, void *);
49
50struct wdc_upc_softc {
51	struct wdc_softc sc_wdc;
52	struct ata_channel *sc_chanlist[1];
53	struct ata_channel sc_channel;
54	struct ata_queue sc_chqueue;
55	struct wdc_regs sc_wdc_regs;
56};
57
58CFATTACH_DECL_NEW(wdc_upc, sizeof(struct wdc_upc_softc),
59    wdc_upc_match, wdc_upc_attach, NULL, NULL);
60
61static int
62wdc_upc_match(device_t parent, cfdata_t cf, void *aux)
63{
64	struct upc_attach_args *ua = aux;
65
66	return !strcmp(ua->ua_devtype, "wdc");
67}
68
69static void
70wdc_upc_attach(device_t parent, device_t self, void *aux)
71{
72	struct wdc_upc_softc *sc = device_private(self);
73	struct wdc_regs *wdr;
74	struct upc_attach_args *ua = aux;
75	int i;
76
77	sc->sc_wdc.sc_atac.atac_dev = self;
78	sc->sc_wdc.regs = wdr = &sc->sc_wdc_regs;
79
80	sc->sc_wdc.sc_atac.atac_cap = ATAC_CAP_DATA16;
81	sc->sc_wdc.sc_atac.atac_pio_cap = 1; /* XXX ??? */
82	sc->sc_wdc.sc_atac.atac_nchannels = 1;
83	sc->sc_chanlist[0] = &sc->sc_channel;
84	sc->sc_wdc.sc_atac.atac_channels = sc->sc_chanlist;
85	wdr->cmd_iot = ua->ua_iot;
86	wdr->cmd_baseioh = ua->ua_ioh;
87	wdr->ctl_iot = ua->ua_iot;
88	wdr->ctl_ioh = ua->ua_ioh2;
89	sc->sc_channel.ch_channel = 0;
90	sc->sc_channel.ch_atac = &sc->sc_wdc.sc_atac;
91	sc->sc_channel.ch_queue = &sc->sc_chqueue;
92	sc->sc_channel.ch_ndrive = 2;
93	for (i = 0; i < WDC_NREG; i++) {
94		if (bus_space_subregion(ua->ua_iot, ua->ua_ioh, i,
95		    i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) {
96			aprint_error_dev(sc->sc_wdc.sc_atac.atac_dev,
97			    "can't subregion I/O space\n");
98			return;
99		}
100	}
101	wdc_init_shadow_regs(&sc->sc_channel);
102
103	upc_intr_establish(ua->ua_irqhandle, IPL_BIO, wdcintr,
104			   &sc->sc_channel);
105
106	aprint_normal("\n");
107	aprint_naive("\n");
108
109	wdcattach(&sc->sc_channel);
110}
111