xref: /netbsd-src/sys/arch/amiga/dev/zz9k_usb.c (revision 8d9149a73d8c60ae0227e10e709e085238bd5944)
1*8d9149a7Sphx /*	$NetBSD: zz9k_usb.c,v 1.1 2023/05/03 13:49:30 phx Exp $ */
2*8d9149a7Sphx 
3*8d9149a7Sphx /*
4*8d9149a7Sphx  * Copyright (c) 2020 The NetBSD Foundation, Inc.
5*8d9149a7Sphx  * All rights reserved.
6*8d9149a7Sphx  *
7*8d9149a7Sphx  * This code is derived from software contributed to The NetBSD Foundation
8*8d9149a7Sphx  * by Alain Runa.
9*8d9149a7Sphx  *
10*8d9149a7Sphx  * Redistribution and use in source and binary forms, with or without
11*8d9149a7Sphx  * modification, are permitted provided that the following conditions
12*8d9149a7Sphx  * are met:
13*8d9149a7Sphx  * 1. Redistributions of source code must retain the above copyright
14*8d9149a7Sphx  *	notice, this list of conditions and the following disclaimer.
15*8d9149a7Sphx  * 2. Redistributions in binary form must reproduce the above copyright
16*8d9149a7Sphx  *	notice, this list of conditions and the following disclaimer in the
17*8d9149a7Sphx  *	documentation and/or other materials provided with the distribution.
18*8d9149a7Sphx  *
19*8d9149a7Sphx  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20*8d9149a7Sphx  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21*8d9149a7Sphx  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22*8d9149a7Sphx  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23*8d9149a7Sphx  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24*8d9149a7Sphx  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*8d9149a7Sphx  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*8d9149a7Sphx  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*8d9149a7Sphx  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28*8d9149a7Sphx  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*8d9149a7Sphx  */
30*8d9149a7Sphx 
31*8d9149a7Sphx #include <sys/cdefs.h>
32*8d9149a7Sphx __KERNEL_RCSID(0, "$NetBSD: zz9k_usb.c,v 1.1 2023/05/03 13:49:30 phx Exp $");
33*8d9149a7Sphx 
34*8d9149a7Sphx /* miscellaneous */
35*8d9149a7Sphx #include <sys/types.h>			/* size_t */
36*8d9149a7Sphx #include <sys/stdint.h>			/* uintXX_t */
37*8d9149a7Sphx #include <sys/stdbool.h>		/* bool */
38*8d9149a7Sphx 
39*8d9149a7Sphx /* driver(9) */
40*8d9149a7Sphx #include <sys/param.h>			/* NODEV */
41*8d9149a7Sphx #include <sys/device.h>			/* CFATTACH_DECL_NEW(), device_priv() */
42*8d9149a7Sphx #include <sys/errno.h>			/* . */
43*8d9149a7Sphx 
44*8d9149a7Sphx /* bus_space(9) and zorro bus */
45*8d9149a7Sphx #include <sys/bus.h>			/* bus_space_xxx(), bus_space_xxx_t */
46*8d9149a7Sphx #include <sys/cpu.h>			/* kvtop() */
47*8d9149a7Sphx #include <sys/systm.h>			/* aprint_xxx() */
48*8d9149a7Sphx 
49*8d9149a7Sphx /* zz9k related */
50*8d9149a7Sphx #include <amiga/dev/zz9kvar.h>		/* zz9kbus_attach_args */
51*8d9149a7Sphx #include <amiga/dev/zz9kreg.h>		/* ZZ9000 registers */
52*8d9149a7Sphx #include "zz9k_usb.h"			/* NZZ9K_USB */
53*8d9149a7Sphx 
54*8d9149a7Sphx 
55*8d9149a7Sphx /* The allmighty softc structure */
56*8d9149a7Sphx struct zzusb_softc {
57*8d9149a7Sphx 	device_t sc_dev;
58*8d9149a7Sphx 	struct bus_space_tag sc_bst;
59*8d9149a7Sphx 	bus_space_tag_t sc_iot;
60*8d9149a7Sphx 	bus_space_handle_t sc_regh;
61*8d9149a7Sphx };
62*8d9149a7Sphx 
63*8d9149a7Sphx /* driver(9) essentials */
64*8d9149a7Sphx static int zzusb_match(device_t parent, cfdata_t match, void *aux);
65*8d9149a7Sphx static void zzusb_attach(device_t parent, device_t self, void *aux);
66*8d9149a7Sphx CFATTACH_DECL_NEW(zz9k_usb, sizeof(struct zzusb_softc),
67*8d9149a7Sphx     zzusb_match, zzusb_attach, NULL, NULL);
68*8d9149a7Sphx 
69*8d9149a7Sphx 
70*8d9149a7Sphx /* Go ahead, make my day. */
71*8d9149a7Sphx 
72*8d9149a7Sphx static int
zzusb_match(device_t parent,cfdata_t match,void * aux)73*8d9149a7Sphx zzusb_match(device_t parent, cfdata_t match, void *aux)
74*8d9149a7Sphx {
75*8d9149a7Sphx 	struct zz9kbus_attach_args *bap = aux;
76*8d9149a7Sphx 
77*8d9149a7Sphx 	if (strcmp(bap->zzaa_name, "zz9k_usb") != 0)
78*8d9149a7Sphx 		return 0;
79*8d9149a7Sphx 
80*8d9149a7Sphx 	return 1;
81*8d9149a7Sphx }
82*8d9149a7Sphx 
83*8d9149a7Sphx static void
zzusb_attach(device_t parent,device_t self,void * aux)84*8d9149a7Sphx zzusb_attach(device_t parent, device_t self, void *aux)
85*8d9149a7Sphx {
86*8d9149a7Sphx 	struct zz9kbus_attach_args *bap = aux;
87*8d9149a7Sphx 	struct zzusb_softc *sc = device_private(self);
88*8d9149a7Sphx 	struct zzusb_softc *psc = device_private(parent);
89*8d9149a7Sphx 
90*8d9149a7Sphx 	sc->sc_dev = self;
91*8d9149a7Sphx 	sc->sc_bst.base = bap->zzaa_base;
92*8d9149a7Sphx 	sc->sc_bst.absm = &amiga_bus_stride_1;
93*8d9149a7Sphx 	sc->sc_iot = &sc->sc_bst;
94*8d9149a7Sphx 	sc->sc_regh = psc->sc_regh;
95*8d9149a7Sphx 
96*8d9149a7Sphx 	uint16_t capacity  = ZZREG_R(ZZ9K_USB_CAPACITY);
97*8d9149a7Sphx 	aprint_normal(": USB device %sdetected.\n",
98*8d9149a7Sphx 	    (capacity == 0) ? "not " : "");
99*8d9149a7Sphx 	aprint_normal_dev (sc->sc_dev,
100*8d9149a7Sphx 	    "MNT ZZ9000 USB driver is not implemented yet.\n");
101*8d9149a7Sphx 
102*8d9149a7Sphx 	aprint_debug_dev(sc->sc_dev, "[DEBUG] registers at %p/%p (pa/va)\n",
103*8d9149a7Sphx 	    (void *)kvtop((void *)sc->sc_regh),
104*8d9149a7Sphx 	    bus_space_vaddr(sc->sc_iot, sc->sc_regh));
105*8d9149a7Sphx 
106*8d9149a7Sphx 	/* to be implemented */
107*8d9149a7Sphx }
108