xref: /freebsd/sys/powerpc/powermac/ata_macio.c (revision 6b3455a7665208c366849f0b2b3bc916fb97516e)
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 
50 #include <dev/ofw/openfirm.h>
51 #include <powerpc/powermac/maciovar.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 
68 static device_method_t ata_macio_methods[] = {
69         /* Device interface */
70 	DEVMETHOD(device_probe,		ata_macio_probe),
71 	DEVMETHOD(device_attach,        ata_attach),
72 
73 	{ 0, 0 }
74 };
75 
76 static driver_t ata_macio_driver = {
77 	"ata",
78 	ata_macio_methods,
79 	sizeof(struct ata_channel),
80 };
81 
82 DRIVER_MODULE(ata, macio, ata_macio_driver, ata_devclass, 0, 0);
83 
84 static void
85 ata_macio_locknoop(struct ata_channel *ch, int type)
86 {
87 	/* XXX SMP ? */
88 }
89 
90 static void
91 ata_macio_setmode(struct ata_device *atadev, int mode)
92 {
93 #if 0
94 	atadev->mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX);
95 #endif
96 	atadev->mode = ATA_PIO;
97 }
98 
99 static int
100 ata_macio_probe(device_t dev)
101 {
102 	char *type = macio_get_devtype(dev);
103 	struct ata_channel *ch;
104 	struct resource *mem;
105 	int rid, i;
106 
107 	if (strcmp(type, "ata") != 0 &&
108 	    strcmp(type, "ide") != 0)
109 		return (ENXIO);
110 
111 	ch = device_get_softc(dev);
112 	bzero(ch, sizeof(struct ata_channel));
113 
114 	rid = 0;
115 	mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
116 	if (mem == NULL) {
117 		device_printf(dev, "could not allocate memory\n");
118 		return (ENXIO);
119 	}
120 
121 	/*
122 	 * Set up the resource vectors
123 	 */
124 	for (i = ATA_DATA; i <= ATA_STATUS; i++) {
125 		ch->r_io[i].res = mem;
126 		ch->r_io[i].offset = i * ATA_MACIO_REGGAP;
127 	}
128 	ch->r_io[ATA_ALTSTAT].res = mem;
129 	ch->r_io[ATA_ALTSTAT].offset = ATA_MACIO_ALTOFFSET;
130 
131 	ch->unit = 0;
132 	ch->flags |= ATA_USE_16BIT;
133 	ch->locking = ata_macio_locknoop;
134 	ch->device[MASTER].setmode = ata_macio_setmode;
135 	ch->device[SLAVE].setmode = ata_macio_setmode;
136 	ata_generic_hw(ch);
137 
138 	return (ata_probe(dev));
139 }
140 
141