xref: /freebsd/sys/powerpc/powermac/ata_macio.c (revision 7660b554bc59a07be0431c17e0e33815818baa69)
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 <machine/stdarg.h>
41 #include <machine/resource.h>
42 #include <machine/bus.h>
43 #include <sys/rman.h>
44 #include <sys/ata.h>
45 #include <dev/ata/ata-all.h>
46 
47 #include <dev/ofw/openfirm.h>
48 #include <powerpc/powermac/maciovar.h>
49 
50 /*
51  * Offset to control registers from base
52 */
53 #define ATA_MACIO_ALTOFFSET	0x160
54 
55 /*
56  * Define the gap between registers
57  */
58 #define ATA_MACIO_REGGAP	16
59 
60 /*
61  * Define the macio ata bus attachment.
62  */
63 static  int  ata_macio_probe(device_t dev);
64 
65 static device_method_t ata_macio_methods[] = {
66         /* Device interface */
67 	DEVMETHOD(device_probe,		ata_macio_probe),
68 	DEVMETHOD(device_attach,        ata_attach),
69 
70 	{ 0, 0 }
71 };
72 
73 static driver_t ata_macio_driver = {
74 	"ata",
75 	ata_macio_methods,
76 	sizeof(struct ata_channel),
77 };
78 
79 DRIVER_MODULE(ata, macio, ata_macio_driver, ata_devclass, 0, 0);
80 
81 static void
82 ata_macio_locknoop(struct ata_channel *ch, int type)
83 {
84 	/* XXX SMP ? */
85 }
86 
87 static void
88 ata_macio_setmode(struct ata_device *atadev, int mode)
89 {
90 #if 0
91 	atadev->mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX);
92 #endif
93 	atadev->mode = ATA_PIO;
94 }
95 
96 static int
97 ata_macio_probe(device_t dev)
98 {
99 	char *type = macio_get_devtype(dev);
100 	struct ata_channel *ch;
101 	struct resource *mem;
102 	int rid, i;
103 
104 	if (strcmp(type, "ata") != 0)
105 		return (ENXIO);
106 
107 	ch = device_get_softc(dev);
108 
109 	rid = 0;
110 	mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~1, 1,
111 	    RF_ACTIVE);
112 	if (mem == NULL) {
113 		device_printf(dev, "could not allocate memory\n");
114 		return (ENXIO);
115 	}
116 
117 	/*
118 	 * Set up the resource vectors
119 	 */
120 	for (i = ATA_DATA; i <= ATA_STATUS; i++) {
121 		ch->r_io[i].res = mem;
122 		ch->r_io[i].offset = i * ATA_MACIO_REGGAP;
123 	}
124 	ch->r_io[ATA_ALTSTAT].res = mem;
125 	ch->r_io[ATA_ALTSTAT].offset = ATA_MACIO_ALTOFFSET;
126 
127 	ch->unit = 0;
128 	ch->flags |= ATA_USE_16BIT;
129 	ch->locking = ata_macio_locknoop;
130 	ch->device[MASTER].setmode = ata_macio_setmode;
131 	ch->device[SLAVE].setmode = ata_macio_setmode;
132 
133 	return (ata_probe(dev));
134 }
135 
136