summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTobias Weingartner <weingart@cvs.openbsd.org>2000-01-31 01:50:56 +0000
committerTobias Weingartner <weingart@cvs.openbsd.org>2000-01-31 01:50:56 +0000
commitc827a625a3d6045d846af0a2d96f0f16bd0fed32 (patch)
tree6a9f0eedf34b040e2b5a630f12b4e06db5163370 /sys
parent32f4ef221000444572249016353881f0be0cf193 (diff)
Add support for 93C66 and 93C56 SEEPROM chips.
Adapted from FreeBSD code.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/ic/smc93cx6.c62
-rw-r--r--sys/dev/ic/smc93cx6var.h81
-rw-r--r--sys/dev/pci/ahc_pci.c16
3 files changed, 89 insertions, 70 deletions
diff --git a/sys/dev/ic/smc93cx6.c b/sys/dev/ic/smc93cx6.c
index 704310b0adf..f8aa62d3b34 100644
--- a/sys/dev/ic/smc93cx6.c
+++ b/sys/dev/ic/smc93cx6.c
@@ -1,10 +1,9 @@
-/* $OpenBSD: smc93cx6.c,v 1.6 1996/11/28 23:27:53 niklas Exp $ */
-/* $NetBSD: smc93cx6.c,v 1.5 1996/10/21 22:34:38 thorpej Exp $ */
-
+/* $OpenBSD: smc93cx6.c,v 1.7 2000/01/31 01:50:54 weingart Exp $ */
+/* $FreeBSD: sys/dev/aic7xxx/93cx6.c,v 1.5 2000/01/07 23:08:17 gibbs Exp $ */
/*
- * Interface for the 93C46/26/06 serial eeprom parts.
+ * Interface for the 93C66/56/46/26/06 serial eeprom parts.
*
- * Copyright (c) 1995 Daniel M. Eischen
+ * Copyright (c) 1995, 1996 Daniel M. Eischen
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,10 +22,10 @@
*/
/*
- * The instruction set of the 93C46/26/06 chips are as follows:
+ * The instruction set of the 93C66/56/46/26/06 chips are as follows:
*
- * Start OP
- * Function Bit Code Address Data Description
+ * Start OP *
+ * Function Bit Code Address** Data Description
* -------------------------------------------------------------------
* READ 1 10 A5 - A0 Reads data stored in memory,
* starting at specified address
@@ -39,12 +38,14 @@
* EWDS 1 00 00XXXX Disables all programming
* instructions
* *Note: A value of X for address is a don't care condition.
+ * **Note: There are 8 address bits for the 93C56/66 chips unlike
+ * the 93C46/26/06 chips which have 6 address bits.
*
* The 93C46 has a four wire interface: clock, chip select, data in, and
* data out. In order to perform one of the above functions, you need
* to enable the chip select for a clock period (typically a minimum of
* 1 usec, with the clock high and low a minimum of 750 and 250 nsec
- * respectively. While the chip select remains high, you can clock in
+ * respectively). While the chip select remains high, you can clock in
* the instructions (above) starting with the start bit, followed by the
* OP code, Address, and Data (if needed). For the READ instruction, the
* requested 16-bit register contents is read from the data out line but
@@ -56,11 +57,14 @@
#include <sys/param.h>
#include <sys/systm.h>
-#if defined(__FreeBSD__)
-#include <machine/clock.h>
-#include <i386/scsi/93cx6.h>
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
+#if !(defined(__NetBSD__) || defined(__OpenBSD__))
+#include <machine/bus_memio.h>
+#include <machine/bus_pio.h>
+#endif
#include <machine/bus.h>
+#if !(defined(__NetBSD__) || defined(__OpenBSD__))
+#include <dev/aic7xxx/93cx6.h>
+#else
#include <dev/ic/smc93cx6var.h>
#endif
@@ -76,10 +80,11 @@ static struct seeprom_cmd {
/*
* Wait for the SEERDY to go high; about 800 ns.
*/
-#define CLOCK_PULSE(sd, rdy) \
- while ((SEEPROM_INB(sd) & rdy) == 0) { \
- ; /* Do nothing */ \
- }
+#define CLOCK_PULSE(sd, rdy) \
+ while ((SEEPROM_STATUS_INB(sd) & rdy) == 0) { \
+ ; /* Do nothing */ \
+ } \
+ (void)SEEPROM_INB(sd); /* Clear clock */
/*
* Read the serial EEPROM and returns 1 if successful and 0 if
@@ -89,15 +94,11 @@ int
read_seeprom(sd, buf, start_addr, count)
struct seeprom_descriptor *sd;
u_int16_t *buf;
-#if defined(__FreeBSD__)
- u_int start_addr;
- int count;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
bus_size_t start_addr;
bus_size_t count;
-#endif
{
- int i = 0, k = 0;
+ int i = 0;
+ u_int k = 0;
u_int16_t v;
u_int8_t temp;
@@ -125,8 +126,8 @@ read_seeprom(sd, buf, start_addr, count)
if (seeprom_read.bits[i] != 0)
temp ^= sd->sd_DO;
}
- /* Send the 6 bit address (MSB first, LSB last). */
- for (i = 5; i >= 0; i--) {
+ /* Send the 6 or 8 bit address (MSB first, LSB last). */
+ for (i = (sd->sd_chip - 1); i >= 0; i--) {
if ((k & (1 << i)) != 0)
temp ^= sd->sd_DO;
SEEPROM_OUTB(sd, temp);
@@ -148,7 +149,7 @@ read_seeprom(sd, buf, start_addr, count)
SEEPROM_OUTB(sd, temp);
CLOCK_PULSE(sd, sd->sd_RDY);
v <<= 1;
- if (SEEPROM_INB(sd) & sd->sd_DI)
+ if (SEEPROM_DATA_INB(sd) & sd->sd_DI)
v |= 1;
SEEPROM_OUTB(sd, temp ^ sd->sd_CK);
CLOCK_PULSE(sd, sd->sd_RDY);
@@ -165,12 +166,11 @@ read_seeprom(sd, buf, start_addr, count)
SEEPROM_OUTB(sd, temp);
CLOCK_PULSE(sd, sd->sd_RDY);
}
-#if 0
- printf ("Serial EEPROM:");
+#ifdef AHC_DUMP_EEPROM
+ printf("\nSerial EEPROM:\n\t");
for (k = 0; k < count; k = k + 1) {
- if (((k % 8) == 0) && (k != 0))
- {
- printf ("\n ");
+ if (((k % 8) == 0) && (k != 0)) {
+ printf ("\n\t");
}
printf (" 0x%x", buf[k]);
}
diff --git a/sys/dev/ic/smc93cx6var.h b/sys/dev/ic/smc93cx6var.h
index 644fd75ee1b..0ef1610f229 100644
--- a/sys/dev/ic/smc93cx6var.h
+++ b/sys/dev/ic/smc93cx6var.h
@@ -1,6 +1,5 @@
-/* $OpenBSD: smc93cx6var.h,v 1.5 1996/11/28 23:27:53 niklas Exp $ */
-/* $NetBSD: smc93cx6var.h,v 1.3 1996/10/21 22:34:41 thorpej Exp $ */
-
+/* $OpenBSD: smc93cx6var.h,v 1.6 2000/01/31 01:50:54 weingart Exp $ */
+/* $FreeBSD: sys/dev/aic7xxx/93cx6.h,v 1.3 1999/12/29 04:35:33 peter Exp $ */
/*
* Interface to the 93C46 serial EEPROM that is used to store BIOS
* settings for the aic7xxx based adaptec SCSI controllers. It can
@@ -13,15 +12,29 @@
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
- * notice immediately at the beginning of the file, without modification,
- * this list of conditions, and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Absolutely no warranty of function or purpose is made by the author
- * Justin T. Gibbs.
- * 4. Modifications may be freely made to this file if the above conditions
- * are met.
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * Where this Software is combined with software released under the terms of
+ * the GNU Public License ("GPL") and the terms of the GPL would require the
+ * combined work to also be released under the terms of the GPL, the terms
+ * and conditions of this License will apply in addition to those of the
+ * GPL with the exception of any terms or conditions of this License that
+ * conflict with, or are expressly prohibited by, the GPL.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
*/
#include <sys/param.h>
@@ -29,14 +42,20 @@
#include <sys/systm.h>
#endif
+#ifdef _KERNEL
+
+typedef enum {
+ C46 = 6,
+ C56_66 = 8
+} seeprom_chip_t;
+
struct seeprom_descriptor {
-#if defined(__FreeBSD__)
- u_long sd_iobase;
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
- bus_space_tag_t sd_iot;
- bus_space_handle_t sd_ioh;
- bus_size_t sd_offset;
-#endif
+ bus_space_tag_t sd_tag;
+ bus_space_handle_t sd_bsh;
+ bus_size_t sd_control_offset;
+ bus_size_t sd_status_offset;
+ bus_size_t sd_dataout_offset;
+ seeprom_chip_t sd_chip;
u_int16_t sd_MS;
u_int16_t sd_RDY;
u_int16_t sd_CS;
@@ -61,20 +80,16 @@ struct seeprom_descriptor {
* A failed read attempt returns 0, and a successful read returns 1.
*/
-#if defined(__FreeBSD__)
-#define SEEPROM_INB(sd) inb(sd->sd_iobase)
-#define SEEPROM_OUTB(sd, value) outb(sd->sd_iobase, value)
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
#define SEEPROM_INB(sd) \
- bus_space_read_1(sd->sd_iot, sd->sd_ioh, sd->sd_offset)
+ bus_space_read_1(sd->sd_tag, sd->sd_bsh, sd->sd_control_offset)
#define SEEPROM_OUTB(sd, value) \
- bus_space_write_1(sd->sd_iot, sd->sd_ioh, sd->sd_offset, value)
-#endif
+ bus_space_write_1(sd->sd_tag, sd->sd_bsh, sd->sd_control_offset, value)
+#define SEEPROM_STATUS_INB(sd) \
+ bus_space_read_1(sd->sd_tag, sd->sd_bsh, sd->sd_status_offset)
+#define SEEPROM_DATA_INB(sd) \
+ bus_space_read_1(sd->sd_tag, sd->sd_bsh, sd->sd_dataout_offset)
-#if defined(__FreeBSD__)
-int read_seeprom __P((struct seeprom_descriptor *sd,
- u_int16_t *buf, u_int start_addr, int count));
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
-int read_seeprom __P((struct seeprom_descriptor *sd,
- u_int16_t *buf, bus_size_t start_addr, bus_size_t count));
-#endif
+int read_seeprom(struct seeprom_descriptor *sd, u_int16_t *buf,
+ bus_size_t start_addr, bus_size_t count);
+
+#endif /* _KERNEL */
diff --git a/sys/dev/pci/ahc_pci.c b/sys/dev/pci/ahc_pci.c
index 0d6a9998e53..a4f9091a754 100644
--- a/sys/dev/pci/ahc_pci.c
+++ b/sys/dev/pci/ahc_pci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ahc_pci.c,v 1.11 1999/09/22 21:57:08 deraadt Exp $ */
+/* $OpenBSD: ahc_pci.c,v 1.12 2000/01/31 01:50:55 weingart Exp $ */
/* $NetBSD: ahc_pci.c,v 1.9 1996/10/21 22:56:24 thorpej Exp $ */
/*
@@ -626,10 +626,14 @@ load_seeprom(ahc)
#if defined(__FreeBSD__)
sd.sd_iobase = ahc->baseport + SEECTL;
#elif defined(__NetBSD__) || defined(__OpenBSD__)
- sd.sd_iot = ahc->sc_iot;
- sd.sd_ioh = ahc->sc_ioh;
- sd.sd_offset = SEECTL;
+ sd.sd_tag = ahc->sc_iot;
+ sd.sd_bsh = ahc->sc_ioh;
+ sd.sd_control_offset = SEECTL;
+ sd.sd_status_offset = SEECTL;
+ sd.sd_dataout_offset = SEECTL;
#endif
+ sd.sd_chip = C46; /* XXX - backwards compat */
+
sd.sd_MS = SEEMS;
sd.sd_RDY = SEERDY;
sd.sd_CS = SEECS;
@@ -724,10 +728,10 @@ acquire_seeprom(sd)
*/
SEEPROM_OUTB(sd, sd->sd_MS);
wait = 1000; /* 1 second timeout in msec */
- while (--wait && ((SEEPROM_INB(sd) & sd->sd_RDY) == 0)) {
+ while (--wait && ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0)) {
DELAY (1000); /* delay 1 msec */
}
- if ((SEEPROM_INB(sd) & sd->sd_RDY) == 0) {
+ if ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0) {
SEEPROM_OUTB(sd, 0);
return (0);
}