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