1 /*
2  * Copyright 2007 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, (uint32_t *)((sd)->sd_base+ \
90 	    (sd)->sd_control_offset)) \
91 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
92 	    (sd)->sd_control_offset)))
93 
94 #define	SEEPROM_OUTB(sd, value) { \
95 	if ((sd)->sd_regsize == 4) \
96 		ddi_put32((sd)->sd_handle, (uint32_t *)((sd)->sd_base+ \
97 		    (sd)->sd_control_offset), (value)); \
98 	else \
99 		ddi_put8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
100 		    (sd)->sd_control_offset), (uint8_t)(value)); \
101 }
102 
103 #define	SEEPROM_STATUS_INB(sd) \
104 	(((sd)->sd_regsize == 4) \
105 	    ? ddi_get32((sd)->sd_handle, (uint32_t *)((sd)->sd_base+ \
106 	    (sd)->sd_status_offset)) \
107 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
108 	    (sd)->sd_status_offset)))
109 
110 #define	SEEPROM_DATA_INB(sd) \
111 	(((sd)->sd_regsize == 4) \
112 	    ? ddi_get32((sd)->sd_handle, (uint32_t *)((sd)->sd_base+ \
113 	    (sd)->sd_dataout_offset)) \
114 	    : ddi_get8((sd)->sd_handle, (uint8_t *)((sd)->sd_base+ \
115 	    (sd)->sd_dataout_offset)))
116 
117 int read_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
118     size_t start_addr, size_t count);
119 #endif	/* _SMC93CX6VAR_H_ */
120