1 /* $OpenBSD: smc93cx6var.h,v 1.17 2015/09/12 16:24:14 deraadt Exp $ */ 2 /* $FreeBSD: sys/dev/aic7xxx/93cx6.h,v 1.3 1999/12/29 04:35:33 peter Exp $ */ 3 /* 4 * Interface to the 93C46 serial EEPROM that is used to store BIOS 5 * settings for the aic7xxx based adaptec SCSI controllers. It can 6 * also be used for 93C26 and 93C06 serial EEPROMS. 7 * 8 * Copyright (c) 1994, 1995 Justin T. Gibbs. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification, immediately at the beginning of the file. 17 * 2. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * Where this Software is combined with software released under the terms of 21 * the GNU Public License ("GPL") and the terms of the GPL would require the 22 * combined work to also be released under the terms of the GPL, the terms 23 * and conditions of this License will apply in addition to those of the 24 * GPL with the exception of any terms or conditions of this License that 25 * conflict with, or are expressly prohibited by, the GPL. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 31 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 */ 39 #ifndef _SMC93CX6VAR_H_ 40 #define _SMC93CX6VAR_H_ 41 42 #ifdef _KERNEL 43 44 typedef enum { 45 C46 = 6, 46 C56_66 = 8 47 } seeprom_chip_t; 48 49 struct seeprom_descriptor { 50 bus_space_tag_t sd_tag; 51 bus_space_handle_t sd_bsh; 52 bus_size_t sd_regsize; 53 bus_size_t sd_control_offset; 54 bus_size_t sd_status_offset; 55 bus_size_t sd_dataout_offset; 56 seeprom_chip_t sd_chip; 57 u_int16_t sd_MS; 58 u_int16_t sd_RDY; 59 u_int16_t sd_CS; 60 u_int16_t sd_CK; 61 u_int16_t sd_DO; 62 u_int16_t sd_DI; 63 }; 64 65 /* 66 * This function will read count 16-bit words from the serial EEPROM and 67 * return their value in buf. The port address of the aic7xxx serial EEPROM 68 * control register is passed in as offset. The following parameters are 69 * also passed in: 70 * 71 * CS - Chip select 72 * CK - Clock 73 * DO - Data out 74 * DI - Data in 75 * RDY - SEEPROM ready 76 * MS - Memory port mode select 77 * 78 * A failed read attempt returns 0, and a successful read returns 1. 79 */ 80 81 #define SEEPROM_INB(sd) \ 82 (((sd)->sd_regsize == 4) \ 83 ? bus_space_read_4((sd)->sd_tag, (sd)->sd_bsh, \ 84 (sd)->sd_control_offset) \ 85 : bus_space_read_1((sd)->sd_tag, (sd)->sd_bsh, \ 86 (sd)->sd_control_offset)) 87 88 #define SEEPROM_OUTB(sd, value) \ 89 do { \ 90 if ((sd)->sd_regsize == 4) \ 91 bus_space_write_4((sd)->sd_tag, (sd)->sd_bsh, \ 92 (sd)->sd_control_offset, (value)); \ 93 else \ 94 bus_space_write_1((sd)->sd_tag, (sd)->sd_bsh, \ 95 (sd)->sd_control_offset, (u_int8_t) (value)); \ 96 } while(0) 97 98 #define SEEPROM_STATUS_INB(sd) \ 99 (((sd)->sd_regsize == 4) \ 100 ? bus_space_read_4((sd)->sd_tag, (sd)->sd_bsh, \ 101 (sd)->sd_status_offset) \ 102 : bus_space_read_1((sd)->sd_tag, (sd)->sd_bsh, \ 103 (sd)->sd_status_offset)) 104 105 #define SEEPROM_DATA_INB(sd) \ 106 (((sd)->sd_regsize == 4) \ 107 ? bus_space_read_4((sd)->sd_tag, (sd)->sd_bsh, \ 108 (sd)->sd_dataout_offset) \ 109 : bus_space_read_1((sd)->sd_tag, (sd)->sd_bsh, \ 110 (sd)->sd_dataout_offset)) 111 112 int read_seeprom(struct seeprom_descriptor *, u_int16_t *, 113 bus_size_t, bus_size_t); 114 115 #endif /* _KERNEL */ 116 #endif /* _SMC93CX6VAR_H_ */ 117