aic77xx.c revision 1.8 1 1.8 dsl /* $NetBSD: aic77xx.c,v 1.8 2009/03/14 15:36:17 dsl Exp $ */
2 1.1 fvdl
3 1.1 fvdl /*
4 1.1 fvdl * Common routines for AHA-27/284X and aic7770 motherboard SCSI controllers.
5 1.1 fvdl *
6 1.1 fvdl * Copyright (c) 1994, 1995, 1996, 1997, 1998 Justin T. Gibbs.
7 1.1 fvdl * All rights reserved.
8 1.1 fvdl *
9 1.1 fvdl * Redistribution and use in source and binary forms, with or without
10 1.1 fvdl * modification, are permitted provided that the following conditions
11 1.1 fvdl * are met:
12 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
13 1.1 fvdl * notice immediately at the beginning of the file, without modification,
14 1.1 fvdl * this list of conditions, and the following disclaimer.
15 1.1 fvdl * 2. The name of the author may not be used to endorse or promote products
16 1.1 fvdl * derived from this software without specific prior written permission.
17 1.1 fvdl *
18 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 1.1 fvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 1.1 fvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 1.1 fvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 1.1 fvdl * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 1.1 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 1.1 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.1 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 1.1 fvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 fvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 fvdl * SUCH DAMAGE.
29 1.1 fvdl *
30 1.1 fvdl * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15 2000/01/29 14:22:19 peter Exp $
31 1.1 fvdl */
32 1.2 lukem
33 1.2 lukem #include <sys/cdefs.h>
34 1.8 dsl __KERNEL_RCSID(0, "$NetBSD: aic77xx.c,v 1.8 2009/03/14 15:36:17 dsl Exp $");
35 1.1 fvdl
36 1.1 fvdl #include <sys/param.h>
37 1.1 fvdl #include <sys/systm.h>
38 1.1 fvdl #include <sys/device.h>
39 1.1 fvdl
40 1.7 ad #include <sys/bus.h>
41 1.7 ad #include <sys/intr.h>
42 1.1 fvdl
43 1.1 fvdl #include <dev/scsipi/scsi_all.h>
44 1.1 fvdl #include <dev/scsipi/scsipi_all.h>
45 1.1 fvdl #include <dev/scsipi/scsiconf.h>
46 1.1 fvdl
47 1.3 fvdl #include <dev/ic/aic7xxx_osm.h>
48 1.3 fvdl #include <dev/ic/aic7xxx_inline.h>
49 1.1 fvdl #include <dev/ic/aic77xxreg.h>
50 1.1 fvdl #include <dev/ic/aic77xxvar.h>
51 1.1 fvdl
52 1.1 fvdl /*
53 1.1 fvdl * Return irq setting of the board, otherwise -1.
54 1.1 fvdl */
55 1.1 fvdl int
56 1.8 dsl ahc_aic77xx_irq(bus_space_tag_t iot, bus_space_handle_t ioh)
57 1.1 fvdl {
58 1.1 fvdl int irq;
59 1.1 fvdl u_int8_t intdef;
60 1.1 fvdl u_int8_t hcntrl;
61 1.1 fvdl
62 1.1 fvdl /* Pause the card preseving the IRQ type */
63 1.1 fvdl hcntrl = bus_space_read_1(iot, ioh, HCNTRL) & IRQMS;
64 1.1 fvdl bus_space_write_1(iot, ioh, HCNTRL, hcntrl | PAUSE);
65 1.5 perry
66 1.1 fvdl intdef = bus_space_read_1(iot, ioh, INTDEF);
67 1.1 fvdl irq = (intdef & INTDEF_IRQ_MASK);
68 1.1 fvdl switch (irq) {
69 1.1 fvdl case 9:
70 1.1 fvdl case 10:
71 1.1 fvdl case 11:
72 1.1 fvdl case 12:
73 1.1 fvdl case 14:
74 1.1 fvdl case 15:
75 1.1 fvdl break;
76 1.1 fvdl default:
77 1.1 fvdl printf("ahc_aic77xx_irq: illegal irq setting %d\n", intdef);
78 1.1 fvdl return (-1);
79 1.1 fvdl }
80 1.1 fvdl
81 1.1 fvdl return (irq);
82 1.1 fvdl }
83 1.1 fvdl
84 1.1 fvdl int
85 1.8 dsl ahc_aic77xx_attach(struct ahc_softc *ahc)
86 1.1 fvdl {
87 1.1 fvdl u_int8_t sblkctl;
88 1.1 fvdl u_int8_t sblkctl_orig;
89 1.1 fvdl u_int8_t hostconf;
90 1.1 fvdl
91 1.1 fvdl /*
92 1.1 fvdl * See if we have a Rev E or higher aic7770. Anything below a
93 1.1 fvdl * Rev E will have a R/O autoflush disable configuration bit.
94 1.1 fvdl */
95 1.1 fvdl sblkctl_orig = ahc_inb(ahc, SBLKCTL);
96 1.1 fvdl sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
97 1.1 fvdl ahc_outb(ahc, SBLKCTL, sblkctl);
98 1.1 fvdl sblkctl = ahc_inb(ahc, SBLKCTL);
99 1.1 fvdl if (sblkctl != sblkctl_orig) {
100 1.4 tsutsui printf("%s: aic7770 >= Rev E: R/O autoflush enabled\n",
101 1.4 tsutsui ahc_name(ahc));
102 1.1 fvdl /*
103 1.1 fvdl * Ensure autoflush is enabled
104 1.1 fvdl */
105 1.1 fvdl sblkctl &= ~AUTOFLUSHDIS;
106 1.1 fvdl ahc_outb(ahc, SBLKCTL, sblkctl);
107 1.4 tsutsui }
108 1.1 fvdl
109 1.1 fvdl /* Setup the FIFO threshold and the bus off time */
110 1.1 fvdl hostconf = ahc_inb(ahc, HOSTCONF);
111 1.1 fvdl ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH);
112 1.1 fvdl ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF);
113 1.1 fvdl
114 1.1 fvdl /*
115 1.1 fvdl * Generic aic7xxx initialization.
116 1.1 fvdl */
117 1.1 fvdl if (ahc_init(ahc)) {
118 1.1 fvdl /*
119 1.1 fvdl * The board's IRQ line is not yet enabled so it's safe
120 1.1 fvdl * to release the irq.
121 1.1 fvdl */
122 1.1 fvdl return (ENXIO);
123 1.1 fvdl }
124 1.1 fvdl
125 1.1 fvdl /*
126 1.1 fvdl * Enable the board's BUS drivers
127 1.1 fvdl */
128 1.1 fvdl ahc_outb(ahc, BCTL, ENABLE);
129 1.1 fvdl
130 1.1 fvdl /* Attach sub-devices - always succeeds */
131 1.1 fvdl ahc_attach(ahc);
132 1.1 fvdl
133 1.1 fvdl return 0;
134 1.1 fvdl }
135