xref: /titanic_41/usr/src/uts/common/io/rtw/smc93cx6var.h (revision 8475e04352e630e4bd0f59a283286ee2475a14ce)
1 /*
2  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Interface to the 93C46 serial EEPROM that is used to store BIOS
8  * settings for the aic7xxx based adaptec SCSI controllers.  It can
9  * also be used for 93C26 and 93C06 serial EEPROMS.
10  *
11  * Copyright (c) 1994, 1995 Justin T. Gibbs.
12  * All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions, and the following disclaimer,
19  *    without modification.
20  * 2. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * Alternatively, this software may be distributed under the terms of the
24  * the GNU Public License ("GPL").
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
30  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.c,v 1.40 2000/01/07 23:08:17gibbs Exp $
39  */
40 
41 #pragma ident	"%Z%%M%	%I%	%E% SMI"
42 
43 #ifndef _SMC93CX6VAR_H_
44 #define	_SMC93CX6VAR_H_
45 
46 
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 
50 typedef enum {
51 	C46 = 6,
52 	C56_66 = 8
53 } seeprom_chip_t;
54 
55 struct seeprom_descriptor {
56 	ddi_acc_handle_t	sd_handle;
57 	caddr_t			sd_base;
58 	size_t sd_regsize;
59 	size_t sd_control_offset;
60 	size_t sd_status_offset;
61 	size_t sd_dataout_offset;
62 	seeprom_chip_t sd_chip;
63 	uint32_t sd_MS;
64 	uint32_t sd_RDY;
65 	uint32_t sd_CS;
66 	uint32_t sd_CK;
67 	uint32_t sd_DO;
68 	uint32_t sd_DI;
69 };
70 
71 /*
72  * This function will read count 16-bit words from the serial EEPROM and
73  * return their value in buf.  The port address of the aic7xxx serial EEPROM
74  * control register is passed in as offset.  The following parameters are
75  * also passed in:
76  *
77  *   CS  - Chip select
78  *   CK  - Clock
79  *   DO  - Data out
80  *   DI  - Data in
81  *   RDY - SEEPROM ready
82  *   MS  - Memory port mode select
83  *
84  *  A failed read attempt returns 0, and a successful read returns 1.
85  */
86 
87 #define	SEEPROM_INB(sd) \
88 	(((sd)->sd_regsize == 4) \
89 	    ? ddi_get32((sd)->sd_handle, \
90 	    (uint32_t *)((uintptr_t)(sd)->sd_base+ \
91 	    (sd)->sd_control_offset)) \
92 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
93 	    (sd)->sd_control_offset)))
94 
95 #define	SEEPROM_OUTB(sd, value) { \
96 	if ((sd)->sd_regsize == 4) \
97 		ddi_put32((sd)->sd_handle, \
98 		    (uint32_t *)((uintptr_t)(sd)->sd_base+ \
99 		    (sd)->sd_control_offset), (value)); \
100 	else \
101 		ddi_put8((sd)->sd_handle, \
102 		    (uint8_t *)((sd)->sd_base+ \
103 		    (sd)->sd_control_offset), (uint8_t)(value)); \
104 }
105 
106 #define	SEEPROM_STATUS_INB(sd) \
107 	(((sd)->sd_regsize == 4) \
108 	    ? ddi_get32((sd)->sd_handle, \
109 	    (uint32_t *)((uintptr_t)(sd)->sd_base+ \
110 	    (sd)->sd_status_offset)) \
111 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
112 	    (sd)->sd_status_offset)))
113 
114 #define	SEEPROM_DATA_INB(sd) \
115 	(((sd)->sd_regsize == 4) \
116 	    ? ddi_get32((sd)->sd_handle, \
117 	    (uint32_t *)((uintptr_t)(sd)->sd_base+ \
118 	    (sd)->sd_dataout_offset)) \
119 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
120 	    (sd)->sd_dataout_offset)))
121 
122 int read_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
123     size_t start_addr, size_t count);
124 #endif	/* _SMC93CX6VAR_H_ */
125