]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/powerpc/powermac/ata_macio.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / powerpc / powermac / ata_macio.c
1 /*-
2  * Copyright 2002 by Peter Grehan. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29
30 /*
31  * Mac-io ATA controller
32  */
33 #include "opt_ata.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/bus.h>
39 #include <sys/malloc.h>
40 #include <sys/sema.h>
41 #include <sys/taskqueue.h>
42 #include <vm/uma.h>
43 #include <machine/stdarg.h>
44 #include <machine/resource.h>
45 #include <machine/bus.h>
46 #include <sys/rman.h>
47 #include <sys/ata.h>
48 #include <dev/ata/ata-all.h>
49 #include <ata_if.h>
50
51 #include <dev/ofw/ofw_bus.h>
52
53 /*
54  * Offset to control registers from base
55  */
56 #define ATA_MACIO_ALTOFFSET     0x160
57
58 /*
59  * Define the gap between registers
60  */
61 #define ATA_MACIO_REGGAP        16
62
63 /*
64  * Define the macio ata bus attachment.
65  */
66 static  int  ata_macio_probe(device_t dev);
67 static  void ata_macio_setmode(device_t parent, device_t dev);
68
69 static device_method_t ata_macio_methods[] = {
70         /* Device interface */
71         DEVMETHOD(device_probe,         ata_macio_probe),
72         DEVMETHOD(device_attach,        ata_attach),
73
74         /* ATA interface */
75         DEVMETHOD(ata_setmode,          ata_macio_setmode),
76         { 0, 0 }
77 };
78
79 static driver_t ata_macio_driver = {
80         "ata",
81         ata_macio_methods,
82         sizeof(struct ata_channel),
83 };
84
85 DRIVER_MODULE(ata, macio, ata_macio_driver, ata_devclass, 0, 0);
86 MODULE_DEPEND(ata, ata, 1, 1, 1);
87
88 static int
89 ata_macio_probe(device_t dev)
90 {
91         const char *type = ofw_bus_get_type(dev);
92         struct ata_channel *ch;
93         struct resource *mem;
94         int rid, i;
95
96         if (strcmp(type, "ata") != 0 &&
97             strcmp(type, "ide") != 0)
98                 return (ENXIO);
99
100         ch = device_get_softc(dev);
101         bzero(ch, sizeof(struct ata_channel));
102
103         rid = 0;
104         mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
105         if (mem == NULL) {
106                 device_printf(dev, "could not allocate memory\n");
107                 return (ENXIO);
108         }
109
110         /*
111          * Set up the resource vectors
112          */
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;
116         }
117         ch->r_io[ATA_CONTROL].res = mem;
118         ch->r_io[ATA_CONTROL].offset = ATA_MACIO_ALTOFFSET;
119         ata_default_registers(dev);
120
121         ch->unit = 0;
122         ch->flags |= ATA_USE_16BIT;
123         ata_generic_hw(dev);
124
125         return (ata_probe(dev));
126 }
127
128 static void
129 ata_macio_setmode(device_t parent, device_t dev)
130 {
131         struct ata_device *atadev = device_get_softc(dev);
132
133         /* TODO bang macio speed register */
134         atadev->mode = ATA_PIO;
135 }
136