1 1.1 phx /* $NetBSD: zz9k.c,v 1.1 2023/05/03 13:49:30 phx Exp $ */ 2 1.1 phx 3 1.1 phx /* 4 1.1 phx * Copyright (c) 2020 The NetBSD Foundation, Inc. 5 1.1 phx * All rights reserved. 6 1.1 phx * 7 1.1 phx * This code is derived from software contributed to The NetBSD Foundation 8 1.1 phx * by Alain Runa. 9 1.1 phx * 10 1.1 phx * Redistribution and use in source and binary forms, with or without 11 1.1 phx * modification, are permitted provided that the following conditions 12 1.1 phx * are met: 13 1.1 phx * 1. Redistributions of source code must retain the above copyright 14 1.1 phx * notice, this list of conditions and the following disclaimer. 15 1.1 phx * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 phx * notice, this list of conditions and the following disclaimer in the 17 1.1 phx * documentation and/or other materials provided with the distribution. 18 1.1 phx * 19 1.1 phx * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 1.1 phx * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 1.1 phx * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 1.1 phx * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 1.1 phx * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 1.1 phx * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 1.1 phx * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 1.1 phx * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 1.1 phx * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 1.1 phx * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 1.1 phx */ 30 1.1 phx 31 1.1 phx #include <sys/cdefs.h> 32 1.1 phx __KERNEL_RCSID(0, "$NetBSD: zz9k.c,v 1.1 2023/05/03 13:49:30 phx Exp $"); 33 1.1 phx 34 1.1 phx /* miscellaneous */ 35 1.1 phx #include <sys/types.h> /* size_t */ 36 1.1 phx #include <sys/stdint.h> /* uintXX_t */ 37 1.1 phx #include <sys/stdbool.h> /* bool */ 38 1.1 phx 39 1.1 phx /* driver(9) includes */ 40 1.1 phx #include <sys/param.h> /* NODEV */ 41 1.1 phx #include <sys/device.h> /* CFATTACH_DECL_NEW(), device_priv() */ 42 1.1 phx #include <sys/errno.h> /* . */ 43 1.1 phx 44 1.1 phx /* bus_space(9) and zorro bus includes */ 45 1.1 phx #include <sys/bus.h> /* bus_space_xxx(), bus_space_xxx */ 46 1.1 phx #include <sys/cpu.h> /* kvtop() */ 47 1.1 phx #include <sys/systm.h> /* aprint_xxx() */ 48 1.1 phx #include <amiga/dev/zbusvar.h> /* zbus_args */ 49 1.1 phx 50 1.1 phx /* zz9k and amiga related */ 51 1.1 phx #include <amiga/amiga/device.h> /* amiga_realconfig */ 52 1.1 phx #include <amiga/dev/zz9kvar.h> /* zz9k_softc */ 53 1.1 phx #include <amiga/dev/zz9kreg.h> /* ZZ9000 registers */ 54 1.1 phx #include "zz9k.h" /* NZZ9K */ 55 1.1 phx 56 1.1 phx 57 1.1 phx /* helper functions */ 58 1.1 phx static int zz9k_print(void *aux, const char *pnp); 59 1.1 phx 60 1.1 phx /* driver(9) essentials */ 61 1.1 phx static int zz9k_match(device_t parent, cfdata_t match, void *aux); 62 1.1 phx static void zz9k_attach(device_t parent, device_t self, void *aux); 63 1.1 phx CFATTACH_DECL_NEW( 64 1.1 phx zz9k, sizeof(struct zz9k_softc), zz9k_match, zz9k_attach, NULL, NULL); 65 1.1 phx 66 1.1 phx bool zz9k_exists = false; /* required by zz9k_fb ZZFB_CONSOLE */ 67 1.1 phx 68 1.1 phx 69 1.1 phx /* It's the year 2020. And so it begins... */ 70 1.1 phx 71 1.1 phx static int 72 1.1 phx zz9k_match(device_t parent, cfdata_t match, void *aux) 73 1.1 phx { 74 1.1 phx struct zbus_args *zap = aux; 75 1.1 phx bool found = false; 76 1.1 phx 77 1.1 phx if (zap->manid == ZZ9K_MANID) { 78 1.1 phx switch (zap->prodid) { 79 1.1 phx case ZZ9K_PRODID_Z2: 80 1.1 phx case ZZ9K_PRODID_Z3: 81 1.1 phx found = true; 82 1.1 phx break; 83 1.1 phx } 84 1.1 phx } 85 1.1 phx 86 1.1 phx if (amiga_realconfig == 0) { /* pre-config, just flag if zz9k exists. */ 87 1.1 phx zz9k_exists = found; 88 1.1 phx return 0; /* 0, as we don't need zz9k_attach() this round. */ 89 1.1 phx } 90 1.1 phx 91 1.1 phx return found; 92 1.1 phx } 93 1.1 phx 94 1.1 phx static void 95 1.1 phx zz9k_attach(device_t parent, device_t self, void *aux) 96 1.1 phx { 97 1.1 phx struct zbus_args *zap = aux; 98 1.1 phx struct zz9k_softc *sc = device_private(self); 99 1.1 phx struct zz9kbus_attach_args zz9k_fb; /* Graphics */ 100 1.1 phx struct zz9kbus_attach_args zz9k_if; /* Ethernet */ 101 1.1 phx struct zz9kbus_attach_args zz9k_ax; /* Audio */ 102 1.1 phx struct zz9kbus_attach_args zz9k_usb; /* USB */ 103 1.1 phx 104 1.1 phx const bus_addr_t regBase = ZZ9K_REG_BASE; 105 1.1 phx const bus_size_t regSize = ZZ9K_REG_SIZE; 106 1.1 phx 107 1.1 phx sc->sc_dev = self; 108 1.1 phx sc->sc_bst.base = (bus_addr_t)zap->va; 109 1.1 phx sc->sc_bst.absm = &amiga_bus_stride_1; 110 1.1 phx sc->sc_iot = &sc->sc_bst; 111 1.1 phx sc->sc_zsize = zap->size; 112 1.1 phx 113 1.1 phx if (bus_space_map(sc->sc_iot, regBase, regSize, 0, &sc->sc_regh)) { 114 1.1 phx aprint_error("Failed to map MNT ZZ9000 registers.\n"); 115 1.1 phx return; 116 1.1 phx } 117 1.1 phx 118 1.1 phx uint16_t hwVer = ZZREG_R(ZZ9K_HW_VERSION); 119 1.1 phx uint16_t fwVer = ZZREG_R(ZZ9K_FW_VERSION); 120 1.1 phx 121 1.1 phx aprint_normal(": MNT ZZ9000 Zorro %s (HW: %i.%i, FW: %i.%i)\n", 122 1.1 phx (zap->prodid == ZZ9K_PRODID_Z3) ? "III" : "II", 123 1.1 phx hwVer >> 8, hwVer & 0x00ff, fwVer >> 8, fwVer & 0x00ff); 124 1.1 phx 125 1.1 phx if (fwVer < ZZ9K_FW_VER_MIN) { 126 1.1 phx aprint_error("Firmware version is not supported. " 127 1.1 phx "Please update to newer firmware from:\n"); 128 1.1 phx aprint_error( 129 1.1 phx "https://source.mnt.re/amiga/zz9000-firmware/-/releases\n"); 130 1.1 phx return; 131 1.1 phx } 132 1.1 phx 133 1.1 phx uint16_t tcore = ZZREG_R(ZZ9K_TEMPERATURE); 134 1.1 phx uint16_t vcore = ZZREG_R(ZZ9K_VOLTAGE_CORE); 135 1.1 phx uint16_t vaux = ZZREG_R(ZZ9K_VOLTAGE_AUX); 136 1.1 phx 137 1.1 phx aprint_normal_dev(sc->sc_dev, "Hardware status " 138 1.1 phx "<Tcore: %i.%i C, Vcore: %i.%i V, Vaux: %i.%i V>\n", 139 1.1 phx tcore/10, tcore%10, vcore/100, vcore%100, vaux/100, vaux%100); 140 1.1 phx 141 1.1 phx aprint_debug_dev(sc->sc_dev, "[DEBUG] registers at %p/%p (pa/va), " 142 1.1 phx "MNT ZZ9000 is mapped with %i MB in Zorro %s space.\n", 143 1.1 phx (void *)kvtop((void *)sc->sc_regh), 144 1.1 phx bus_space_vaddr(sc->sc_iot, sc->sc_regh), 145 1.1 phx zap->size / (1024 * 1024), 146 1.1 phx (zap->prodid == ZZ9K_PRODID_Z3) ? "III" : "II"); 147 1.1 phx 148 1.1 phx if (fwVer > ZZ9K_FW_VER) { 149 1.1 phx aprint_normal_dev(sc->sc_dev, "The firmware is newer than " 150 1.1 phx "%i.%i and may not be supported yet.\n", 151 1.1 phx ZZ9K_FW_VER >> 8, ZZ9K_FW_VER & 0x00ff); 152 1.1 phx } 153 1.1 phx 154 1.1 phx /* Add framebuffer */ 155 1.1 phx zz9k_fb.zzaa_base = (bus_addr_t)zap->va; 156 1.1 phx strcpy(zz9k_fb.zzaa_name, "zz9k_fb"); 157 1.1 phx config_found(sc->sc_dev, &zz9k_fb, zz9k_print, CFARGS_NONE); 158 1.1 phx 159 1.1 phx /* Add zz* ethernet interface */ 160 1.1 phx zz9k_if.zzaa_base = (bus_addr_t)zap->va; 161 1.1 phx strcpy(zz9k_if.zzaa_name, "zz9k_if"); 162 1.1 phx config_found(sc->sc_dev, &zz9k_if, zz9k_print, CFARGS_NONE); 163 1.1 phx 164 1.1 phx /* Add AX audio interface */ 165 1.1 phx zz9k_ax.zzaa_base = (bus_addr_t)zap->va; 166 1.1 phx strcpy(zz9k_ax.zzaa_name, "zz9k_ax"); 167 1.1 phx config_found(sc->sc_dev, &zz9k_ax, zz9k_print, CFARGS_NONE); 168 1.1 phx 169 1.1 phx /* Add USB interface */ 170 1.1 phx zz9k_usb.zzaa_base = (bus_addr_t)zap->va; 171 1.1 phx strcpy(zz9k_usb.zzaa_name, "zz9k_usb"); 172 1.1 phx config_found(sc->sc_dev, &zz9k_usb, zz9k_print, CFARGS_NONE); 173 1.1 phx } 174 1.1 phx 175 1.1 phx static int 176 1.1 phx zz9k_print(void *aux, const char *pnp) 177 1.1 phx { 178 1.1 phx return 0; 179 1.1 phx } 180