1 /*
2  * Copyright 2009 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 #ifndef _SMC93CX6VAR_H_
42 #define	_SMC93CX6VAR_H_
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 
51 typedef enum {
52 	C46 = 6,
53 	C56_66 = 8
54 } seeprom_chip_t;
55 
56 struct seeprom_descriptor {
57 	ddi_acc_handle_t	sd_handle;
58 	caddr_t			sd_base;
59 	size_t sd_regsize;
60 	size_t sd_control_offset;
61 	size_t sd_status_offset;
62 	size_t sd_dataout_offset;
63 	seeprom_chip_t sd_chip;
64 	uint32_t sd_MS;
65 	uint32_t sd_RDY;
66 	uint32_t sd_CS;
67 	uint32_t sd_CK;
68 	uint32_t sd_DO;
69 	uint32_t sd_DI;
70 };
71 
72 /*
73  * This function will read count 16-bit words from the serial EEPROM and
74  * return their value in buf.  The port address of the aic7xxx serial EEPROM
75  * control register is passed in as offset.  The following parameters are
76  * also passed in:
77  *
78  *   CS  - Chip select
79  *   CK  - Clock
80  *   DO  - Data out
81  *   DI  - Data in
82  *   RDY - SEEPROM ready
83  *   MS  - Memory port mode select
84  *
85  *  A failed read attempt returns 0, and a successful read returns 1.
86  */
87 
88 #define	SEEPROM_INB(sd) \
89 	(((sd)->sd_regsize == 4) \
90 	    ? ddi_get32((sd)->sd_handle, \
91 	    (uint32_t *)((uintptr_t)(sd)->sd_base+ \
92 	    (sd)->sd_control_offset)) \
93 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
94 	    (sd)->sd_control_offset)))
95 
96 #define	SEEPROM_OUTB(sd, value) { \
97 	if ((sd)->sd_regsize == 4) \
98 		ddi_put32((sd)->sd_handle, \
99 		    (uint32_t *)((uintptr_t)(sd)->sd_base+ \
100 		    (sd)->sd_control_offset), (value)); \
101 	else \
102 		ddi_put8((sd)->sd_handle, \
103 		    (uint8_t *)((sd)->sd_base+ \
104 		    (sd)->sd_control_offset), (uint8_t)(value)); \
105 }
106 
107 #define	SEEPROM_STATUS_INB(sd) \
108 	(((sd)->sd_regsize == 4) \
109 	    ? ddi_get32((sd)->sd_handle, \
110 	    (uint32_t *)((uintptr_t)(sd)->sd_base+ \
111 	    (sd)->sd_status_offset)) \
112 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
113 	    (sd)->sd_status_offset)))
114 
115 #define	SEEPROM_DATA_INB(sd) \
116 	(((sd)->sd_regsize == 4) \
117 	    ? ddi_get32((sd)->sd_handle, \
118 	    (uint32_t *)((uintptr_t)(sd)->sd_base+ \
119 	    (sd)->sd_dataout_offset)) \
120 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
121 	    (sd)->sd_dataout_offset)))
122 
123 int read_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
124     size_t start_addr, size_t count);
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif	/* _SMC93CX6VAR_H_ */
130