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 for the 93C66/56/46/26/06 serial eeprom parts. 8a72f7ea6Sql147931 * 9a72f7ea6Sql147931 * Copyright (c) 1995, 1996 Daniel M. Eischen 10a72f7ea6Sql147931 * All rights reserved. 11a72f7ea6Sql147931 * 12a72f7ea6Sql147931 * Redistribution and use in source and binary forms, with or without 13a72f7ea6Sql147931 * modification, are permitted provided that the following conditions 14a72f7ea6Sql147931 * are met: 15a72f7ea6Sql147931 * 1. Redistributions of source code must retain the above copyright 16a72f7ea6Sql147931 * notice immediately at the beginning of the file, without modification, 17a72f7ea6Sql147931 * this list of conditions, and the following disclaimer. 18a72f7ea6Sql147931 * 2. Redistributions in binary form must reproduce the above copyright 19a72f7ea6Sql147931 * notice, this list of conditions and the following disclaimer in the 20a72f7ea6Sql147931 * documentation and/or other materials provided with the distribution. 21a72f7ea6Sql147931 * 3. Absolutely no warranty of function or purpose is made by the author 22a72f7ea6Sql147931 * Daniel M. Eischen. 23a72f7ea6Sql147931 * 4. Modifications may be freely made to this file if the above conditions 24a72f7ea6Sql147931 * are met. 25a72f7ea6Sql147931 * 26a72f7ea6Sql147931 * $FreeBSD: src/sys/dev/aic7xxx/93cx6.c,v 1.5 2000/01/07 23:08:17 gibbs Exp $ 27a72f7ea6Sql147931 */ 28a72f7ea6Sql147931 29a72f7ea6Sql147931 /* 30a72f7ea6Sql147931 * The instruction set of the 93C66/56/46/26/06 chips are as follows: 31a72f7ea6Sql147931 * 32a72f7ea6Sql147931 * Start OP * 33a72f7ea6Sql147931 * Function Bit Code Address** Data Description 34a72f7ea6Sql147931 * ------------------------------------------------------------------- 35a72f7ea6Sql147931 * READ 1 10 A5 - A0 Reads data stored in memory, 36a72f7ea6Sql147931 * starting at specified address 37a72f7ea6Sql147931 * EWEN 1 00 11XXXX Write enable must precede 38a72f7ea6Sql147931 * all programming modes 39a72f7ea6Sql147931 * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0 40a72f7ea6Sql147931 * WRITE 1 01 A5 - A0 D15 - D0 Writes register 41a72f7ea6Sql147931 * ERAL 1 00 10XXXX Erase all registers 42a72f7ea6Sql147931 * WRAL 1 00 01XXXX D15 - D0 Writes to all registers 43a72f7ea6Sql147931 * EWDS 1 00 00XXXX Disables all programming 44a72f7ea6Sql147931 * instructions 45a72f7ea6Sql147931 * *Note: A value of X for address is a don't care condition. 46a72f7ea6Sql147931 * **Note: There are 8 address bits for the 93C56/66 chips unlike 47a72f7ea6Sql147931 * the 93C46/26/06 chips which have 6 address bits. 48a72f7ea6Sql147931 * 49a72f7ea6Sql147931 * The 93C46 has a four wire interface: clock, chip select, data in, and 50a72f7ea6Sql147931 * data out. In order to perform one of the above functions, you need 51a72f7ea6Sql147931 * to enable the chip select for a clock period (typically a minimum of 52a72f7ea6Sql147931 * 1 usec, with the clock high and low a minimum of 750 and 250 nsec 53a72f7ea6Sql147931 * respectively). While the chip select remains high, you can clock in 54a72f7ea6Sql147931 * the instructions (above) starting with the start bit, followed by the 55a72f7ea6Sql147931 * OP code, Address, and Data (if needed). For the READ instruction, the 56a72f7ea6Sql147931 * requested 16-bit register contents is read from the data out line but 57a72f7ea6Sql147931 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB 58a72f7ea6Sql147931 * first). The clock cycling from low to high initiates the next data 59a72f7ea6Sql147931 * bit to be sent from the chip. 60a72f7ea6Sql147931 * 61a72f7ea6Sql147931 */ 62a72f7ea6Sql147931 #include <sys/sunddi.h> 63a72f7ea6Sql147931 #include "smc93cx6var.h" 64a72f7ea6Sql147931 /* 65a72f7ea6Sql147931 * Right now, we only have to read the SEEPROM. But we make it easier to 66a72f7ea6Sql147931 * add other 93Cx6 functions. 67a72f7ea6Sql147931 */ 68a72f7ea6Sql147931 static struct seeprom_cmd { 69a72f7ea6Sql147931 unsigned char len; 70a72f7ea6Sql147931 unsigned char bits[3]; 71a72f7ea6Sql147931 } seeprom_read = {3, {1, 1, 0}}; 72a72f7ea6Sql147931 73a72f7ea6Sql147931 #define CLOCK_PULSE(sd, rdy) { \ 74a72f7ea6Sql147931 /* \ 75a72f7ea6Sql147931 * Wait for the SEERDY to go high; about 800 ns. \ 76a72f7ea6Sql147931 */ \ 77a72f7ea6Sql147931 int cpi = 1000; \ 78a72f7ea6Sql147931 if (rdy == 0) { \ 79a72f7ea6Sql147931 DELAY(4); /* more than long enough */ \ 80a72f7ea6Sql147931 } else { \ 81a72f7ea6Sql147931 while ((SEEPROM_STATUS_INB(sd) & rdy) == 0 && \ 82a72f7ea6Sql147931 cpi-- > 0) { \ 83a72f7ea6Sql147931 cpi = cpi; /* for lint */ \ 84a72f7ea6Sql147931 } \ 85a72f7ea6Sql147931 (void) SEEPROM_INB(sd); /* Clear clock */ \ 86a72f7ea6Sql147931 } \ 87a72f7ea6Sql147931 } 88a72f7ea6Sql147931 89a72f7ea6Sql147931 /* 90a72f7ea6Sql147931 * Read the serial EEPROM and returns 1 if successful and 0 if 91a72f7ea6Sql147931 * not successful. 92a72f7ea6Sql147931 */ 93a72f7ea6Sql147931 int 94a72f7ea6Sql147931 read_seeprom(sd, buf, start_addr, count) 95a72f7ea6Sql147931 struct seeprom_descriptor *sd; 96a72f7ea6Sql147931 uint16_t *buf; 97a72f7ea6Sql147931 size_t start_addr; 98a72f7ea6Sql147931 size_t count; 99a72f7ea6Sql147931 { 100a72f7ea6Sql147931 int i = 0; 101a72f7ea6Sql147931 size_t k = 0; 102a72f7ea6Sql147931 uint16_t v; 103a72f7ea6Sql147931 uint32_t temp; 104a72f7ea6Sql147931 105a72f7ea6Sql147931 /* 106a72f7ea6Sql147931 * Read the requested registers of the seeprom. The loop 107a72f7ea6Sql147931 * will range from 0 to count-1. 108a72f7ea6Sql147931 */ 109a72f7ea6Sql147931 for (k = start_addr; k < count + start_addr; k++) { 110a72f7ea6Sql147931 /* Send chip select for one clock cycle. */ 111a72f7ea6Sql147931 temp = sd->sd_MS ^ sd->sd_CS; 112a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 113a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 114a72f7ea6Sql147931 115a72f7ea6Sql147931 /* 116a72f7ea6Sql147931 * Now we're ready to send the read command followed by the 117a72f7ea6Sql147931 * address of the 16-bit register we want to read. 118a72f7ea6Sql147931 */ 119a72f7ea6Sql147931 for (i = 0; i < seeprom_read.len; i++) { 120a72f7ea6Sql147931 if (seeprom_read.bits[i] != 0) 121a72f7ea6Sql147931 temp ^= sd->sd_DO; 122a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp); 123a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 124a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 125a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 126a72f7ea6Sql147931 if (seeprom_read.bits[i] != 0) 127a72f7ea6Sql147931 temp ^= sd->sd_DO; 128a72f7ea6Sql147931 } 129a72f7ea6Sql147931 /* Send the 6 or 8 bit address (MSB first, LSB last). */ 130a72f7ea6Sql147931 for (i = (sd->sd_chip - 1); i >= 0; i--) { 131a72f7ea6Sql147931 if ((k & (1 << i)) != 0) 132a72f7ea6Sql147931 temp ^= sd->sd_DO; 133a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp); 134a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 135a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 136a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 137a72f7ea6Sql147931 if ((k & (1 << i)) != 0) 138a72f7ea6Sql147931 temp ^= sd->sd_DO; 139a72f7ea6Sql147931 } 140a72f7ea6Sql147931 141a72f7ea6Sql147931 /* 142a72f7ea6Sql147931 * Now read the 16 bit register. An initial 0 precedes the 143a72f7ea6Sql147931 * register contents which begins with bit 15 (MSB) and ends 144a72f7ea6Sql147931 * with bit 0 (LSB). The initial 0 will be shifted off the 145a72f7ea6Sql147931 * top of our word as we let the loop run from 0 to 16. 146a72f7ea6Sql147931 */ 147a72f7ea6Sql147931 v = 0; 148a72f7ea6Sql147931 for (i = 16; i >= 0; i--) { 149a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp); 150a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 151a72f7ea6Sql147931 v <<= 1; 152a72f7ea6Sql147931 if (SEEPROM_DATA_INB(sd) & sd->sd_DI) 153a72f7ea6Sql147931 v |= 1; 154a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 155a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 156a72f7ea6Sql147931 } 157a72f7ea6Sql147931 158a72f7ea6Sql147931 buf[k - start_addr] = v; 159a72f7ea6Sql147931 160a72f7ea6Sql147931 /* Reset the chip select for the next command cycle. */ 161a72f7ea6Sql147931 temp = sd->sd_MS; 162a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp); 163a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 164a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 165a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 166a72f7ea6Sql147931 SEEPROM_OUTB(sd, temp); 167a72f7ea6Sql147931 CLOCK_PULSE(sd, sd->sd_RDY); 168a72f7ea6Sql147931 } 169a72f7ea6Sql147931 #ifdef AHC_DUMP_EEPROM 170a72f7ea6Sql147931 cmn_err(CE_NOTE, "\nSerial EEPROM:\n\t"); 171a72f7ea6Sql147931 for (k = 0; k < count; k = k + 1) { 172a72f7ea6Sql147931 cmn_err(CE_NOTE, " 0x%x", buf[k]); 173a72f7ea6Sql147931 } 174a72f7ea6Sql147931 #endif 175a72f7ea6Sql147931 return (1); 176a72f7ea6Sql147931 } 177