1 /* 2 * Copyright (c) 2004 M. Warner Losh. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions, and the following disclaimer, 10 * without modification, immediately at the beginning of the file. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 32 #include <sys/param.h> 33 #include <sys/bio.h> 34 #include <sys/bus.h> 35 #include <sys/kernel.h> 36 #include <sys/module.h> 37 #include <sys/rman.h> 38 #include <sys/systm.h> 39 40 #include <dev/fdc/fdcvar.h> 41 #include <dev/fdc/fdcreg.h> 42 43 #include <isa/isavar.h> 44 #include <isa/isareg.h> 45 46 static int fdc_isa_probe(device_t); 47 static void fdctl_wr_isa(fdc_p, u_int8_t); 48 49 static struct isa_pnp_id fdc_ids[] = { 50 {0x0007d041, "PC standard floppy disk controller"}, /* PNP0700 */ 51 {0x0107d041, "Standard floppy controller supporting MS Device Bay Spec"}, /* PNP0701 */ 52 {0} 53 }; 54 55 static void 56 fdctl_wr_isa(fdc_p fdc, u_int8_t v) 57 { 58 bus_space_write_1(fdc->ctlt, fdc->ctlh, 0, v); 59 } 60 61 static int 62 fdc_isa_probe(device_t dev) 63 { 64 int error, ic_type; 65 struct fdc_data *fdc; 66 67 fdc = device_get_softc(dev); 68 bzero(fdc, sizeof *fdc); 69 fdc->fdc_dev = dev; 70 fdc->fdctl_wr = fdctl_wr_isa; 71 72 /* Check pnp ids */ 73 error = ISA_PNP_PROBE(device_get_parent(dev), dev, fdc_ids); 74 if (error == ENXIO) 75 return ENXIO; 76 if (error == 0) 77 fdc->flags |= FDC_ISPNP; 78 79 /* Attempt to allocate our resources for the duration of the probe */ 80 error = fdc_alloc_resources(fdc); 81 if (error) 82 goto out; 83 84 /* First - lets reset the floppy controller */ 85 fdout_wr(fdc, 0); 86 DELAY(100); 87 fdout_wr(fdc, FDO_FRST); 88 89 /* see if it can handle a command */ 90 if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240), 91 NE7_SPEC_2(2, 0), 0)) { 92 error = ENXIO; 93 goto out; 94 } 95 96 if (fd_cmd(fdc, 1, NE7CMD_VERSION, 1, &ic_type) == 0) { 97 ic_type = (u_char)ic_type; 98 switch (ic_type) { 99 case 0x80: 100 device_set_desc(dev, "NEC 765 or clone"); 101 fdc->fdct = FDC_NE765; 102 break; 103 case 0x81: /* not mentioned in any hardware doc */ 104 case 0x90: 105 device_set_desc(dev, 106 "Enhanced floppy controller (i82077, NE72065 or clone)"); 107 fdc->fdct = FDC_ENHANCED; 108 break; 109 default: 110 device_set_desc(dev, "Generic floppy controller"); 111 fdc->fdct = FDC_UNKNOWN; 112 break; 113 } 114 } 115 116 out: 117 fdc_release_resources(fdc); 118 return (error); 119 } 120 121 static device_method_t fdc_methods[] = { 122 /* Device interface */ 123 DEVMETHOD(device_probe, fdc_isa_probe), 124 DEVMETHOD(device_attach, fdc_attach), 125 DEVMETHOD(device_detach, fdc_detach), 126 DEVMETHOD(device_shutdown, bus_generic_shutdown), 127 DEVMETHOD(device_suspend, bus_generic_suspend), 128 DEVMETHOD(device_resume, bus_generic_resume), 129 130 /* Bus interface */ 131 DEVMETHOD(bus_print_child, fdc_print_child), 132 DEVMETHOD(bus_read_ivar, fdc_read_ivar), 133 /* Our children never use any other bus interface methods. */ 134 135 { 0, 0 } 136 }; 137 138 static driver_t fdc_driver = { 139 "fdc", 140 fdc_methods, 141 sizeof(struct fdc_data) 142 }; 143 144 DRIVER_MODULE(fdc, isa, fdc_driver, fdc_devclass, 0, 0); 145 DRIVER_MODULE(fdc, acpi, fdc_driver, fdc_devclass, 0, 0); 146