18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Interface for the 93C66/56/46/26/06 serial eeprom parts. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 1995, 1996 Daniel M. Eischen 58c2ecf20Sopenharmony_ci * All rights reserved. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 88c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 98c2ecf20Sopenharmony_ci * are met: 108c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 118c2ecf20Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 128c2ecf20Sopenharmony_ci * without modification. 138c2ecf20Sopenharmony_ci * 2. The name of the author may not be used to endorse or promote products 148c2ecf20Sopenharmony_ci * derived from this software without specific prior written permission. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 178c2ecf20Sopenharmony_ci * GNU General Public License ("GPL"). 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 208c2ecf20Sopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 218c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 228c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 238c2ecf20Sopenharmony_ci * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 248c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 258c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 268c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 278c2ecf20Sopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 288c2ecf20Sopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 298c2ecf20Sopenharmony_ci * SUCH DAMAGE. 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_93cx6.c#19 $ 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* 358c2ecf20Sopenharmony_ci * The instruction set of the 93C66/56/46/26/06 chips are as follows: 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci * Start OP * 388c2ecf20Sopenharmony_ci * Function Bit Code Address** Data Description 398c2ecf20Sopenharmony_ci * ------------------------------------------------------------------- 408c2ecf20Sopenharmony_ci * READ 1 10 A5 - A0 Reads data stored in memory, 418c2ecf20Sopenharmony_ci * starting at specified address 428c2ecf20Sopenharmony_ci * EWEN 1 00 11XXXX Write enable must precede 438c2ecf20Sopenharmony_ci * all programming modes 448c2ecf20Sopenharmony_ci * ERASE 1 11 A5 - A0 Erase register A5A4A3A2A1A0 458c2ecf20Sopenharmony_ci * WRITE 1 01 A5 - A0 D15 - D0 Writes register 468c2ecf20Sopenharmony_ci * ERAL 1 00 10XXXX Erase all registers 478c2ecf20Sopenharmony_ci * WRAL 1 00 01XXXX D15 - D0 Writes to all registers 488c2ecf20Sopenharmony_ci * EWDS 1 00 00XXXX Disables all programming 498c2ecf20Sopenharmony_ci * instructions 508c2ecf20Sopenharmony_ci * *Note: A value of X for address is a don't care condition. 518c2ecf20Sopenharmony_ci * **Note: There are 8 address bits for the 93C56/66 chips unlike 528c2ecf20Sopenharmony_ci * the 93C46/26/06 chips which have 6 address bits. 538c2ecf20Sopenharmony_ci * 548c2ecf20Sopenharmony_ci * The 93C46 has a four wire interface: clock, chip select, data in, and 558c2ecf20Sopenharmony_ci * data out. In order to perform one of the above functions, you need 568c2ecf20Sopenharmony_ci * to enable the chip select for a clock period (typically a minimum of 578c2ecf20Sopenharmony_ci * 1 usec, with the clock high and low a minimum of 750 and 250 nsec 588c2ecf20Sopenharmony_ci * respectively). While the chip select remains high, you can clock in 598c2ecf20Sopenharmony_ci * the instructions (above) starting with the start bit, followed by the 608c2ecf20Sopenharmony_ci * OP code, Address, and Data (if needed). For the READ instruction, the 618c2ecf20Sopenharmony_ci * requested 16-bit register contents is read from the data out line but 628c2ecf20Sopenharmony_ci * is preceded by an initial zero (leading 0, followed by 16-bits, MSB 638c2ecf20Sopenharmony_ci * first). The clock cycling from low to high initiates the next data 648c2ecf20Sopenharmony_ci * bit to be sent from the chip. 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#include "aic7xxx_osm.h" 688c2ecf20Sopenharmony_ci#include "aic7xxx_inline.h" 698c2ecf20Sopenharmony_ci#include "aic7xxx_93cx6.h" 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/* 728c2ecf20Sopenharmony_ci * Right now, we only have to read the SEEPROM. But we make it easier to 738c2ecf20Sopenharmony_ci * add other 93Cx6 functions. 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistruct seeprom_cmd { 768c2ecf20Sopenharmony_ci uint8_t len; 778c2ecf20Sopenharmony_ci uint8_t bits[11]; 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Short opcodes for the c46 */ 818c2ecf20Sopenharmony_cistatic const struct seeprom_cmd seeprom_ewen = {9, {1, 0, 0, 1, 1, 0, 0, 0, 0}}; 828c2ecf20Sopenharmony_cistatic const struct seeprom_cmd seeprom_ewds = {9, {1, 0, 0, 0, 0, 0, 0, 0, 0}}; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* Long opcodes for the C56/C66 */ 858c2ecf20Sopenharmony_cistatic const struct seeprom_cmd seeprom_long_ewen = {11, {1, 0, 0, 1, 1, 0, 0, 0, 0}}; 868c2ecf20Sopenharmony_cistatic const struct seeprom_cmd seeprom_long_ewds = {11, {1, 0, 0, 0, 0, 0, 0, 0, 0}}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* Common opcodes */ 898c2ecf20Sopenharmony_cistatic const struct seeprom_cmd seeprom_write = {3, {1, 0, 1}}; 908c2ecf20Sopenharmony_cistatic const struct seeprom_cmd seeprom_read = {3, {1, 1, 0}}; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* 938c2ecf20Sopenharmony_ci * Wait for the SEERDY to go high; about 800 ns. 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_ci#define CLOCK_PULSE(sd, rdy) \ 968c2ecf20Sopenharmony_ci while ((SEEPROM_STATUS_INB(sd) & rdy) == 0) { \ 978c2ecf20Sopenharmony_ci ; /* Do nothing */ \ 988c2ecf20Sopenharmony_ci } \ 998c2ecf20Sopenharmony_ci (void)SEEPROM_INB(sd); /* Clear clock */ 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* 1028c2ecf20Sopenharmony_ci * Send a START condition and the given command 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_cistatic void 1058c2ecf20Sopenharmony_cisend_seeprom_cmd(struct seeprom_descriptor *sd, const struct seeprom_cmd *cmd) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci uint8_t temp; 1088c2ecf20Sopenharmony_ci int i = 0; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci /* Send chip select for one clock cycle. */ 1118c2ecf20Sopenharmony_ci temp = sd->sd_MS ^ sd->sd_CS; 1128c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 1138c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci for (i = 0; i < cmd->len; i++) { 1168c2ecf20Sopenharmony_ci if (cmd->bits[i] != 0) 1178c2ecf20Sopenharmony_ci temp ^= sd->sd_DO; 1188c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 1198c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1208c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 1218c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1228c2ecf20Sopenharmony_ci if (cmd->bits[i] != 0) 1238c2ecf20Sopenharmony_ci temp ^= sd->sd_DO; 1248c2ecf20Sopenharmony_ci } 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/* 1288c2ecf20Sopenharmony_ci * Clear CS put the chip in the reset state, where it can wait for new commands. 1298c2ecf20Sopenharmony_ci */ 1308c2ecf20Sopenharmony_cistatic void 1318c2ecf20Sopenharmony_cireset_seeprom(struct seeprom_descriptor *sd) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci uint8_t temp; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci temp = sd->sd_MS; 1368c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 1378c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1388c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 1398c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1408c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 1418c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/* 1458c2ecf20Sopenharmony_ci * Read the serial EEPROM and returns 1 if successful and 0 if 1468c2ecf20Sopenharmony_ci * not successful. 1478c2ecf20Sopenharmony_ci */ 1488c2ecf20Sopenharmony_ciint 1498c2ecf20Sopenharmony_ciahc_read_seeprom(struct seeprom_descriptor *sd, uint16_t *buf, 1508c2ecf20Sopenharmony_ci u_int start_addr, u_int count) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci int i = 0; 1538c2ecf20Sopenharmony_ci u_int k = 0; 1548c2ecf20Sopenharmony_ci uint16_t v; 1558c2ecf20Sopenharmony_ci uint8_t temp; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci /* 1588c2ecf20Sopenharmony_ci * Read the requested registers of the seeprom. The loop 1598c2ecf20Sopenharmony_ci * will range from 0 to count-1. 1608c2ecf20Sopenharmony_ci */ 1618c2ecf20Sopenharmony_ci for (k = start_addr; k < count + start_addr; k++) { 1628c2ecf20Sopenharmony_ci /* 1638c2ecf20Sopenharmony_ci * Now we're ready to send the read command followed by the 1648c2ecf20Sopenharmony_ci * address of the 16-bit register we want to read. 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_ci send_seeprom_cmd(sd, &seeprom_read); 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci /* Send the 6 or 8 bit address (MSB first, LSB last). */ 1698c2ecf20Sopenharmony_ci temp = sd->sd_MS ^ sd->sd_CS; 1708c2ecf20Sopenharmony_ci for (i = (sd->sd_chip - 1); i >= 0; i--) { 1718c2ecf20Sopenharmony_ci if ((k & (1 << i)) != 0) 1728c2ecf20Sopenharmony_ci temp ^= sd->sd_DO; 1738c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 1748c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1758c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 1768c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1778c2ecf20Sopenharmony_ci if ((k & (1 << i)) != 0) 1788c2ecf20Sopenharmony_ci temp ^= sd->sd_DO; 1798c2ecf20Sopenharmony_ci } 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci /* 1828c2ecf20Sopenharmony_ci * Now read the 16 bit register. An initial 0 precedes the 1838c2ecf20Sopenharmony_ci * register contents which begins with bit 15 (MSB) and ends 1848c2ecf20Sopenharmony_ci * with bit 0 (LSB). The initial 0 will be shifted off the 1858c2ecf20Sopenharmony_ci * top of our word as we let the loop run from 0 to 16. 1868c2ecf20Sopenharmony_ci */ 1878c2ecf20Sopenharmony_ci v = 0; 1888c2ecf20Sopenharmony_ci for (i = 16; i >= 0; i--) { 1898c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 1908c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1918c2ecf20Sopenharmony_ci v <<= 1; 1928c2ecf20Sopenharmony_ci if (SEEPROM_DATA_INB(sd) & sd->sd_DI) 1938c2ecf20Sopenharmony_ci v |= 1; 1948c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 1958c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 1968c2ecf20Sopenharmony_ci } 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci buf[k - start_addr] = v; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci /* Reset the chip select for the next command cycle. */ 2018c2ecf20Sopenharmony_ci reset_seeprom(sd); 2028c2ecf20Sopenharmony_ci } 2038c2ecf20Sopenharmony_ci#ifdef AHC_DUMP_EEPROM 2048c2ecf20Sopenharmony_ci printk("\nSerial EEPROM:\n\t"); 2058c2ecf20Sopenharmony_ci for (k = 0; k < count; k = k + 1) { 2068c2ecf20Sopenharmony_ci if (((k % 8) == 0) && (k != 0)) { 2078c2ecf20Sopenharmony_ci printk(KERN_CONT "\n\t"); 2088c2ecf20Sopenharmony_ci } 2098c2ecf20Sopenharmony_ci printk(KERN_CONT " 0x%x", buf[k]); 2108c2ecf20Sopenharmony_ci } 2118c2ecf20Sopenharmony_ci printk(KERN_CONT "\n"); 2128c2ecf20Sopenharmony_ci#endif 2138c2ecf20Sopenharmony_ci return (1); 2148c2ecf20Sopenharmony_ci} 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/* 2178c2ecf20Sopenharmony_ci * Write the serial EEPROM and return 1 if successful and 0 if 2188c2ecf20Sopenharmony_ci * not successful. 2198c2ecf20Sopenharmony_ci */ 2208c2ecf20Sopenharmony_ciint 2218c2ecf20Sopenharmony_ciahc_write_seeprom(struct seeprom_descriptor *sd, uint16_t *buf, 2228c2ecf20Sopenharmony_ci u_int start_addr, u_int count) 2238c2ecf20Sopenharmony_ci{ 2248c2ecf20Sopenharmony_ci const struct seeprom_cmd *ewen, *ewds; 2258c2ecf20Sopenharmony_ci uint16_t v; 2268c2ecf20Sopenharmony_ci uint8_t temp; 2278c2ecf20Sopenharmony_ci int i, k; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci /* Place the chip into write-enable mode */ 2308c2ecf20Sopenharmony_ci if (sd->sd_chip == C46) { 2318c2ecf20Sopenharmony_ci ewen = &seeprom_ewen; 2328c2ecf20Sopenharmony_ci ewds = &seeprom_ewds; 2338c2ecf20Sopenharmony_ci } else if (sd->sd_chip == C56_66) { 2348c2ecf20Sopenharmony_ci ewen = &seeprom_long_ewen; 2358c2ecf20Sopenharmony_ci ewds = &seeprom_long_ewds; 2368c2ecf20Sopenharmony_ci } else { 2378c2ecf20Sopenharmony_ci printk("ahc_write_seeprom: unsupported seeprom type %d\n", 2388c2ecf20Sopenharmony_ci sd->sd_chip); 2398c2ecf20Sopenharmony_ci return (0); 2408c2ecf20Sopenharmony_ci } 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci send_seeprom_cmd(sd, ewen); 2438c2ecf20Sopenharmony_ci reset_seeprom(sd); 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci /* Write all requested data out to the seeprom. */ 2468c2ecf20Sopenharmony_ci temp = sd->sd_MS ^ sd->sd_CS; 2478c2ecf20Sopenharmony_ci for (k = start_addr; k < count + start_addr; k++) { 2488c2ecf20Sopenharmony_ci /* Send the write command */ 2498c2ecf20Sopenharmony_ci send_seeprom_cmd(sd, &seeprom_write); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci /* Send the 6 or 8 bit address (MSB first). */ 2528c2ecf20Sopenharmony_ci for (i = (sd->sd_chip - 1); i >= 0; i--) { 2538c2ecf20Sopenharmony_ci if ((k & (1 << i)) != 0) 2548c2ecf20Sopenharmony_ci temp ^= sd->sd_DO; 2558c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 2568c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 2578c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 2588c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 2598c2ecf20Sopenharmony_ci if ((k & (1 << i)) != 0) 2608c2ecf20Sopenharmony_ci temp ^= sd->sd_DO; 2618c2ecf20Sopenharmony_ci } 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci /* Write the 16 bit value, MSB first */ 2648c2ecf20Sopenharmony_ci v = buf[k - start_addr]; 2658c2ecf20Sopenharmony_ci for (i = 15; i >= 0; i--) { 2668c2ecf20Sopenharmony_ci if ((v & (1 << i)) != 0) 2678c2ecf20Sopenharmony_ci temp ^= sd->sd_DO; 2688c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 2698c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 2708c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 2718c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 2728c2ecf20Sopenharmony_ci if ((v & (1 << i)) != 0) 2738c2ecf20Sopenharmony_ci temp ^= sd->sd_DO; 2748c2ecf20Sopenharmony_ci } 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci /* Wait for the chip to complete the write */ 2778c2ecf20Sopenharmony_ci temp = sd->sd_MS; 2788c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 2798c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 2808c2ecf20Sopenharmony_ci temp = sd->sd_MS ^ sd->sd_CS; 2818c2ecf20Sopenharmony_ci do { 2828c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp); 2838c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 2848c2ecf20Sopenharmony_ci SEEPROM_OUTB(sd, temp ^ sd->sd_CK); 2858c2ecf20Sopenharmony_ci CLOCK_PULSE(sd, sd->sd_RDY); 2868c2ecf20Sopenharmony_ci } while ((SEEPROM_DATA_INB(sd) & sd->sd_DI) == 0); 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci reset_seeprom(sd); 2898c2ecf20Sopenharmony_ci } 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci /* Put the chip back into write-protect mode */ 2928c2ecf20Sopenharmony_ci send_seeprom_cmd(sd, ewds); 2938c2ecf20Sopenharmony_ci reset_seeprom(sd); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci return (1); 2968c2ecf20Sopenharmony_ci} 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ciint 2998c2ecf20Sopenharmony_ciahc_verify_cksum(struct seeprom_config *sc) 3008c2ecf20Sopenharmony_ci{ 3018c2ecf20Sopenharmony_ci int i; 3028c2ecf20Sopenharmony_ci int maxaddr; 3038c2ecf20Sopenharmony_ci uint32_t checksum; 3048c2ecf20Sopenharmony_ci uint16_t *scarray; 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci maxaddr = (sizeof(*sc)/2) - 1; 3078c2ecf20Sopenharmony_ci checksum = 0; 3088c2ecf20Sopenharmony_ci scarray = (uint16_t *)sc; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci for (i = 0; i < maxaddr; i++) 3118c2ecf20Sopenharmony_ci checksum = checksum + scarray[i]; 3128c2ecf20Sopenharmony_ci if (checksum == 0 3138c2ecf20Sopenharmony_ci || (checksum & 0xFFFF) != sc->checksum) { 3148c2ecf20Sopenharmony_ci return (0); 3158c2ecf20Sopenharmony_ci } else { 3168c2ecf20Sopenharmony_ci return(1); 3178c2ecf20Sopenharmony_ci } 3188c2ecf20Sopenharmony_ci} 319