diff options
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/i2c/files.i2c | 7 | ||||
-rw-r--r-- | sys/dev/i2c/spdmem_i2c.c | 123 | ||||
-rw-r--r-- | sys/dev/spdmem.c (renamed from sys/dev/i2c/spdmem.c) | 194 | ||||
-rw-r--r-- | sys/dev/spdmemvar.h | 69 |
4 files changed, 269 insertions, 124 deletions
diff --git a/sys/dev/i2c/files.i2c b/sys/dev/i2c/files.i2c index d1c69642cd5..ae5e5376af5 100644 --- a/sys/dev/i2c/files.i2c +++ b/sys/dev/i2c/files.i2c @@ -1,4 +1,4 @@ -# $OpenBSD: files.i2c,v 1.48 2009/08/12 20:41:21 deraadt Exp $ +# $OpenBSD: files.i2c,v 1.49 2010/03/22 21:20:58 miod Exp $ # $NetBSD: files.i2c,v 1.3 2003/10/20 16:24:10 briggs Exp $ define i2c {[addr = -1], [size = -1]} @@ -149,9 +149,8 @@ attach thmc at i2c file dev/i2c/thmc50.c thmc # SPD Memory EEPROM -device spdmem -attach spdmem at i2c -file dev/i2c/spdmem.c spdmem +attach spdmem at i2c with spdmem_iic +file dev/i2c/spdmem_i2c.c spdmem # SO-DIMM (JC-42.4) temperature sensor device sdtemp diff --git a/sys/dev/i2c/spdmem_i2c.c b/sys/dev/i2c/spdmem_i2c.c new file mode 100644 index 00000000000..d4df0d8b647 --- /dev/null +++ b/sys/dev/i2c/spdmem_i2c.c @@ -0,0 +1,123 @@ +/* $OpenBSD: spdmem_i2c.c,v 1.1 2010/03/22 21:20:58 miod Exp $ */ +/* $NetBSD: spdmem.c,v 1.3 2007/09/20 23:09:59 xtraeme Exp $ */ + +/* + * Copyright (c) 2007 Jonathan Gray <jsg@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Copyright (c) 2007 Nicolas Joly + * Copyright (c) 2007 Paul Goyette + * Copyright (c) 2007 Tobias Nygren + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Serial Presence Detect (SPD) memory identification + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> + +#include <dev/spdmemvar.h> +#include <dev/i2c/i2cvar.h> + +struct spdmem_iic_softc { + struct spdmem_softc sc_base; + i2c_tag_t sc_tag; + i2c_addr_t sc_addr; +}; + +int spdmem_iic_match(struct device *, void *, void *); +void spdmem_iic_attach(struct device *, struct device *, void *); +uint8_t spdmem_iic_read(struct spdmem_softc *, uint8_t); + +struct cfattach spdmem_iic_ca = { + sizeof(struct spdmem_iic_softc), spdmem_iic_match, spdmem_iic_attach +}; + +int +spdmem_iic_match(struct device *parent, void *match, void *aux) +{ + struct i2c_attach_args *ia = aux; + struct spdmem_iic_softc sc; + + /* clever attachments like openfirmware informed macppc */ + if (strcmp(ia->ia_name, "spd") == 0) + return (1); + + /* dumb, need sanity checks */ + if (strcmp(ia->ia_name, "eeprom") != 0) + return (0); + + sc.sc_tag = ia->ia_tag; + sc.sc_addr = ia->ia_addr; + sc.sc_base.sc_read = spdmem_iic_read; + + return spdmem_probe(&sc.sc_base); +} + +void +spdmem_iic_attach(struct device *parent, struct device *self, void *aux) +{ + struct spdmem_iic_softc *sc = (struct spdmem_iic_softc *)self; + struct i2c_attach_args *ia = aux; + + sc->sc_tag = ia->ia_tag; + sc->sc_addr = ia->ia_addr; + sc->sc_base.sc_read = spdmem_iic_read; + + printf(":"); + + spdmem_attach_common(&sc->sc_base); +} + +uint8_t +spdmem_iic_read(struct spdmem_softc *v, uint8_t reg) +{ + struct spdmem_iic_softc *sc = (struct spdmem_iic_softc *)v; + uint8_t val = 0xff; + + iic_acquire_bus(sc->sc_tag,0); + iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, + ®, sizeof reg, &val, sizeof val, 0); + iic_release_bus(sc->sc_tag, 0); + + return val; +} diff --git a/sys/dev/i2c/spdmem.c b/sys/dev/spdmem.c index 48bc924751a..01af573d8d0 100644 --- a/sys/dev/i2c/spdmem.c +++ b/sys/dev/spdmem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spdmem.c,v 1.33 2009/09/13 23:36:10 jsg Exp $ */ +/* $OpenBSD: spdmem.c,v 1.1 2010/03/22 21:20:56 miod Exp $ */ /* $NetBSD: spdmem.c,v 1.3 2007/09/20 23:09:59 xtraeme Exp $ */ /* @@ -55,7 +55,7 @@ #include <sys/systm.h> #include <sys/device.h> -#include <dev/i2c/i2cvar.h> +#include <dev/spdmemvar.h> /* Encodings of the size used/total byte for certain memory types */ #define SPDMEM_SPDSIZE_MASK 0x0F /* SPD EEPROM Size */ @@ -230,36 +230,17 @@ static const uint8_t ddr2_cycle_tenths[] = { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 25, 33, 66, 75, 0, 0 }; -struct spdmem { - uint8_t sm_len; - uint8_t sm_size; - uint8_t sm_type; - uint8_t sm_data[60]; - uint8_t sm_cksum; -} __packed; - #define SPDMEM_TYPE_MAXLEN 16 -struct spdmem_softc { - struct device sc_dev; - i2c_tag_t sc_tag; - i2c_addr_t sc_addr; - struct spdmem sc_spd_data; -}; -uint16_t spdmem_crc16(struct spdmem_softc *, int); -int spdmem_match(struct device *, void *, void *); -void spdmem_attach(struct device *, struct device *, void *); -uint8_t spdmem_read(struct spdmem_softc *, uint8_t); -void spdmem_sdram_decode(struct spdmem_softc *, struct spdmem *); -void spdmem_rdr_decode(struct spdmem_softc *, struct spdmem *); -void spdmem_ddr_decode(struct spdmem_softc *, struct spdmem *); -void spdmem_ddr2_decode(struct spdmem_softc *, struct spdmem *); -void spdmem_fbdimm_decode(struct spdmem_softc *, struct spdmem *); -void spdmem_ddr3_decode(struct spdmem_softc *, struct spdmem *); - -struct cfattach spdmem_ca = { - sizeof(struct spdmem_softc), spdmem_match, spdmem_attach -}; +uint16_t spdmem_crc16(struct spdmem_softc *, int); +static inline +uint8_t spdmem_read(struct spdmem_softc *, uint8_t); +void spdmem_sdram_decode(struct spdmem_softc *, struct spdmem *); +void spdmem_rdr_decode(struct spdmem_softc *, struct spdmem *); +void spdmem_ddr_decode(struct spdmem_softc *, struct spdmem *); +void spdmem_ddr2_decode(struct spdmem_softc *, struct spdmem *); +void spdmem_fbdimm_decode(struct spdmem_softc *, struct spdmem *); +void spdmem_ddr3_decode(struct spdmem_softc *, struct spdmem *); struct cfdriver spdmem_cd = { NULL, "spdmem", DV_DULL @@ -301,6 +282,12 @@ static const char *spdmem_parity_types[] = { "cmd/addr/data parity, data ECC" }; +static inline uint8_t +spdmem_read(struct spdmem_softc *sc, uint8_t reg) +{ + return (*sc->sc_read)(sc, reg); +} + /* CRC functions used for certain memory types */ uint16_t spdmem_crc16(struct spdmem_softc *sc, int count) @@ -321,75 +308,6 @@ spdmem_crc16(struct spdmem_softc *sc, int count) return (crc & 0xFFFF); } -int -spdmem_match(struct device *parent, void *match, void *aux) -{ - struct i2c_attach_args *ia = aux; - struct spdmem_softc sc; - uint8_t i, val, type; - int cksum = 0; - int spd_len, spd_crc_cover; - uint16_t crc_calc, crc_spd; - - /* clever attachments like openfirmware informed macppc */ - if (strcmp(ia->ia_name, "spd") == 0) - return (1); - - /* dumb, need sanity checks */ - if (strcmp(ia->ia_name, "eeprom") != 0) - return (0); - - sc.sc_tag = ia->ia_tag; - sc.sc_addr = ia->ia_addr; - - type = spdmem_read(&sc, 2); - /* For older memory types, validate the checksum over 1st 63 bytes */ - if (type <= SPDMEM_MEMTYPE_DDR2SDRAM) { - for (i = 0; i < 63; i++) - cksum += spdmem_read(&sc, i); - - val = spdmem_read(&sc, 63); - - if (cksum == 0 || (cksum & 0xff) != val) { - return 0; - } else - return 1; - } - - /* For DDR3 and FBDIMM, verify the CRC */ - else if (type <= SPDMEM_MEMTYPE_DDR3SDRAM) { - spd_len = spdmem_read(&sc, 0); - if (spd_len && SPDMEM_SPDCRC_116) - spd_crc_cover = 116; - else - spd_crc_cover = 125; - switch (spd_len & SPDMEM_SPDLEN_MASK) { - case SPDMEM_SPDLEN_128: - spd_len = 128; - break; - case SPDMEM_SPDLEN_176: - spd_len = 176; - break; - case SPDMEM_SPDLEN_256: - spd_len = 256; - break; - default: - return 0; - } - if (spd_crc_cover > spd_len) - return 0; - crc_calc = spdmem_crc16(&sc, spd_crc_cover); - crc_spd = spdmem_read(&sc, 127) << 8; - crc_spd |= spdmem_read(&sc, 126); - if (crc_calc != crc_spd) { - return 0; - } - return 1; - } - - return (0); -} - void spdmem_sdram_decode(struct spdmem_softc *sc, struct spdmem *s) { @@ -765,19 +683,68 @@ spdmem_ddr3_decode(struct spdmem_softc *sc, struct spdmem *s) printf(" with thermal sensor"); } +int +spdmem_probe(struct spdmem_softc *sc) +{ + uint8_t i, val, type; + int cksum = 0; + int spd_len, spd_crc_cover; + uint16_t crc_calc, crc_spd; + + type = spdmem_read(sc, 2); + /* For older memory types, validate the checksum over 1st 63 bytes */ + if (type <= SPDMEM_MEMTYPE_DDR2SDRAM) { + for (i = 0; i < 63; i++) + cksum += spdmem_read(sc, i); + + val = spdmem_read(sc, 63); + + if (cksum == 0 || (cksum & 0xff) != val) { + return 0; + } else + return 1; + } + + /* For DDR3 and FBDIMM, verify the CRC */ + else if (type <= SPDMEM_MEMTYPE_DDR3SDRAM) { + spd_len = spdmem_read(sc, 0); + if (spd_len && SPDMEM_SPDCRC_116) + spd_crc_cover = 116; + else + spd_crc_cover = 125; + switch (spd_len & SPDMEM_SPDLEN_MASK) { + case SPDMEM_SPDLEN_128: + spd_len = 128; + break; + case SPDMEM_SPDLEN_176: + spd_len = 176; + break; + case SPDMEM_SPDLEN_256: + spd_len = 256; + break; + default: + return 0; + } + if (spd_crc_cover > spd_len) + return 0; + crc_calc = spdmem_crc16(sc, spd_crc_cover); + crc_spd = spdmem_read(sc, 127) << 8; + crc_spd |= spdmem_read(sc, 126); + if (crc_calc != crc_spd) { + return 0; + } + return 1; + } + + return 0; +} + void -spdmem_attach(struct device *parent, struct device *self, void *aux) +spdmem_attach_common(struct spdmem_softc *sc) { - struct spdmem_softc *sc = (struct spdmem_softc *)self; - struct i2c_attach_args *ia = aux; struct spdmem *s = &(sc->sc_spd_data); int i; - sc->sc_tag = ia->ia_tag; - sc->sc_addr = ia->ia_addr; - - printf(":"); - /* All SPD have at least 64 bytes of data including checksum */ for (i = 0; i < 64; i++) { ((uint8_t *)s)[i] = spdmem_read(sc, i); @@ -825,16 +792,3 @@ spdmem_attach(struct device *parent, struct device *self, void *aux) printf("\n"); } - -uint8_t -spdmem_read(struct spdmem_softc *sc, uint8_t reg) -{ - uint8_t val = 0xff; - - iic_acquire_bus(sc->sc_tag,0); - iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, - ®, sizeof reg, &val, sizeof val, 0); - iic_release_bus(sc->sc_tag, 0); - - return val; -} diff --git a/sys/dev/spdmemvar.h b/sys/dev/spdmemvar.h new file mode 100644 index 00000000000..a5623253675 --- /dev/null +++ b/sys/dev/spdmemvar.h @@ -0,0 +1,69 @@ +/* $OpenBSD: spdmemvar.h,v 1.1 2010/03/22 21:20:56 miod Exp $ */ +/* $NetBSD: spdmem.c,v 1.3 2007/09/20 23:09:59 xtraeme Exp $ */ + +/* + * Copyright (c) 2007 Jonathan Gray <jsg@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Copyright (c) 2007 Nicolas Joly + * Copyright (c) 2007 Paul Goyette + * Copyright (c) 2007 Tobias Nygren + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Serial Presence Detect (SPD) memory identification + */ + +struct spdmem { + uint8_t sm_len; + uint8_t sm_size; + uint8_t sm_type; + uint8_t sm_data[60]; + uint8_t sm_cksum; +} __packed; + +struct spdmem_softc { + struct device sc_dev; + uint8_t (*sc_read)(struct spdmem_softc *, uint8_t); + struct spdmem sc_spd_data; +}; + +void spdmem_attach_common(struct spdmem_softc *); +int spdmem_probe(struct spdmem_softc *); |