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