11.13Sthorpej/* $NetBSD: tsdio.c,v 1.13 2021/08/07 16:19:12 thorpej Exp $ */ 21.1Sjoff 31.1Sjoff/*- 41.1Sjoff * Copyright (c) 2005 The NetBSD Foundation, Inc. 51.1Sjoff * All rights reserved. 61.1Sjoff * 71.1Sjoff * This code is derived from software contributed to The NetBSD Foundation 81.1Sjoff * by Jesse Off 91.1Sjoff * 101.1Sjoff * Redistribution and use in source and binary forms, with or without 111.1Sjoff * modification, are permitted provided that the following conditions 121.1Sjoff * are met: 131.1Sjoff * 1. Redistributions of source code must retain the above copyright 141.1Sjoff * notice, this list of conditions and the following disclaimer. 151.1Sjoff * 2. Redistributions in binary form must reproduce the above copyright 161.1Sjoff * notice, this list of conditions and the following disclaimer in the 171.1Sjoff * documentation and/or other materials provided with the distribution. 181.1Sjoff * 191.1Sjoff * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sjoff * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sjoff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sjoff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sjoff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sjoff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sjoff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sjoff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sjoff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sjoff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sjoff * POSSIBILITY OF SUCH DAMAGE. 301.1Sjoff */ 311.1Sjoff 321.1Sjoff#include <sys/cdefs.h> 331.13Sthorpej__KERNEL_RCSID(0, "$NetBSD: tsdio.c,v 1.13 2021/08/07 16:19:12 thorpej Exp $"); 341.1Sjoff 351.1Sjoff#include <sys/param.h> 361.1Sjoff#include <sys/systm.h> 371.1Sjoff#include <sys/device.h> 381.1Sjoff 391.4Sad#include <sys/bus.h> 401.4Sad#include <sys/intr.h> 411.1Sjoff 421.1Sjoff#include <dev/isa/isareg.h> 431.1Sjoff#include <dev/isa/isavar.h> 441.1Sjoff#include <dev/isa/isadmavar.h> 451.1Sjoff#include <dev/isa/tsdiovar.h> 461.1Sjoff 471.10Sceggerint tsdio_probe(device_t, cfdata_t, void *); 481.10Sceggervoid tsdio_attach(device_t, device_t, void *); 491.10Sceggerint tsdio_search(device_t, cfdata_t, const int *, void *); 501.1Sjoffint tsdio_print(void *, const char *); 511.1Sjoff 521.11SchsCFATTACH_DECL_NEW(tsdio, sizeof(struct tsdio_softc), 531.1Sjoff tsdio_probe, tsdio_attach, NULL, NULL); 541.1Sjoff 551.1Sjoffint 561.10Sceggertsdio_probe(device_t parent, cfdata_t cf, void *aux) 571.1Sjoff{ 581.1Sjoff struct isa_attach_args *ia = aux; 591.1Sjoff bus_space_tag_t iot = ia->ia_iot; 601.1Sjoff bus_space_handle_t dioh; 611.1Sjoff int rv = 0, have_io = 0; 621.1Sjoff 631.1Sjoff if (ia->ia_nio < 1) 641.1Sjoff return (0); 651.1Sjoff if (ia->ia_nirq < 1) 661.1Sjoff return (0); 671.1Sjoff 681.1Sjoff if (ISA_DIRECT_CONFIG(ia)) 691.1Sjoff return (0); 701.1Sjoff 711.1Sjoff /* 721.1Sjoff * Disallow wildcarded I/O base. 731.1Sjoff */ 741.1Sjoff if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) 751.1Sjoff return (0); 761.1Sjoff 771.1Sjoff /* 781.1Sjoff * Map the I/O space. 791.1Sjoff */ 801.1Sjoff if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 811.1Sjoff 0, &dioh)) 821.1Sjoff goto out; 831.1Sjoff have_io = 1; 841.1Sjoff 851.1Sjoff if (bus_space_read_1(ia->ia_iot, dioh, 0) != 0x54) { 861.1Sjoff goto out; 871.1Sjoff } 881.1Sjoff 891.1Sjoff rv = 1; 901.1Sjoff ia->ia_nio = 1; 911.1Sjoff ia->ia_io[0].ir_size = 8; 921.1Sjoff ia->ia_niomem = 0; 931.1Sjoff ia->ia_nirq = 0; 941.1Sjoff ia->ia_ndrq = 0; 951.1Sjoff 961.1Sjoff out: 971.1Sjoff if (have_io) 981.1Sjoff bus_space_unmap(iot, dioh, 8); 991.1Sjoff 1001.1Sjoff return (rv); 1011.1Sjoff} 1021.1Sjoff 1031.1Sjoffvoid 1041.10Sceggertsdio_attach(device_t parent, device_t self, void *aux) 1051.1Sjoff{ 1061.11Schs struct tsdio_softc *sc = device_private(self); 1071.1Sjoff struct isa_attach_args *ia = aux; 1081.1Sjoff 1091.1Sjoff sc->sc_iot = ia->ia_iot; 1101.1Sjoff 1111.1Sjoff aprint_normal(": Technologic Systems TS-DIO24\n"); 1121.1Sjoff 1131.1Sjoff /* 1141.1Sjoff * Map the device. 1151.1Sjoff */ 1161.1Sjoff if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 8, 1171.1Sjoff 0, &sc->sc_ioh)) { 1181.11Schs aprint_error_dev(self, "unable to map i/o space\n"); 1191.1Sjoff return; 1201.1Sjoff } 1211.1Sjoff 1221.1Sjoff /* 1231.1Sjoff * Attach sub-devices 1241.1Sjoff */ 1251.12Sthorpej config_search(self, NULL, 1261.13Sthorpej CFARGS(.search = tsdio_search)); 1271.1Sjoff} 1281.1Sjoff 1291.1Sjoffint 1301.10Sceggertsdio_search(device_t parent, cfdata_t cf, const int *l, void *aux) 1311.1Sjoff{ 1321.11Schs struct tsdio_softc *sc = device_private(parent); 1331.1Sjoff struct tsdio_attach_args sa; 1341.1Sjoff 1351.1Sjoff sa.ta_iot = sc->sc_iot; 1361.1Sjoff sa.ta_ioh = sc->sc_ioh; 1371.1Sjoff 1381.12Sthorpej if (config_probe(parent, cf, &sa)) 1391.13Sthorpej config_attach(parent, cf, &sa, tsdio_print, CFARGS_NONE); 1401.1Sjoff 1411.1Sjoff return (0); 1421.1Sjoff} 1431.1Sjoff 1441.1Sjoffint 1451.7Sdsltsdio_print(void *aux, const char *name) 1461.1Sjoff{ 1471.1Sjoff 1481.1Sjoff return (UNCONF); 1491.1Sjoff} 150