2 * Copyright 2002 by Peter Grehan. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Mac-io ATA controller
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
39 #include <sys/malloc.h>
41 #include <sys/taskqueue.h>
43 #include <machine/stdarg.h>
44 #include <machine/resource.h>
45 #include <machine/bus.h>
48 #include <dev/ata/ata-all.h>
51 #include <dev/ofw/ofw_bus.h>
54 * Offset to control registers from base
56 #define ATA_MACIO_ALTOFFSET 0x160
59 * Define the gap between registers
61 #define ATA_MACIO_REGGAP 16
64 * Define the macio ata bus attachment.
66 static int ata_macio_probe(device_t dev);
67 static void ata_macio_setmode(device_t parent, device_t dev);
69 static device_method_t ata_macio_methods[] = {
70 /* Device interface */
71 DEVMETHOD(device_probe, ata_macio_probe),
72 DEVMETHOD(device_attach, ata_attach),
75 DEVMETHOD(ata_setmode, ata_macio_setmode),
79 static driver_t ata_macio_driver = {
82 sizeof(struct ata_channel),
85 DRIVER_MODULE(ata, macio, ata_macio_driver, ata_devclass, 0, 0);
86 MODULE_DEPEND(ata, ata, 1, 1, 1);
89 ata_macio_probe(device_t dev)
91 const char *type = ofw_bus_get_type(dev);
92 struct ata_channel *ch;
96 if (strcmp(type, "ata") != 0 &&
97 strcmp(type, "ide") != 0)
100 ch = device_get_softc(dev);
101 bzero(ch, sizeof(struct ata_channel));
104 mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
106 device_printf(dev, "could not allocate memory\n");
111 * Set up the resource vectors
113 for (i = ATA_DATA; i <= ATA_COMMAND; i++) {
114 ch->r_io[i].res = mem;
115 ch->r_io[i].offset = i * ATA_MACIO_REGGAP;
117 ch->r_io[ATA_CONTROL].res = mem;
118 ch->r_io[ATA_CONTROL].offset = ATA_MACIO_ALTOFFSET;
119 ata_default_registers(dev);
122 ch->flags |= ATA_USE_16BIT;
125 return (ata_probe(dev));
129 ata_macio_setmode(device_t parent, device_t dev)
131 struct ata_device *atadev = device_get_softc(dev);
133 /* TODO bang macio speed register */
134 atadev->mode = ATA_PIO;