From owner-svn-src-projects@FreeBSD.ORG Thu Oct 15 21:07:00 2009 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 00747106568F; Thu, 15 Oct 2009 21:07:00 +0000 (UTC) (envelope-from rrs@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E36928FC0C; Thu, 15 Oct 2009 21:06:59 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n9FL6x2x084750; Thu, 15 Oct 2009 21:06:59 GMT (envelope-from rrs@svn.freebsd.org) Received: (from rrs@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n9FL6xXY084746; Thu, 15 Oct 2009 21:06:59 GMT (envelope-from rrs@svn.freebsd.org) Message-Id: <200910152106.n9FL6xXY084746@svn.freebsd.org> From: Randall Stewart Date: Thu, 15 Oct 2009 21:06:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r198156 - projects/mips/sys/dev/iicbus X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Oct 2009 21:07:00 -0000 Author: rrs Date: Thu Oct 15 21:06:59 2009 New Revision: 198156 URL: http://svn.freebsd.org/changeset/base/198156 Log: These don't compile yet, but they are some of the first drivers that will need working on to fit from 6.x -> head. But first I must get the base to compile (wanted to get as much in the tree as I could before my flight to India). Added: projects/mips/sys/dev/iicbus/xlr_eeprom.c projects/mips/sys/dev/iicbus/xlr_rtc.c projects/mips/sys/dev/iicbus/xlr_temperature.c Added: projects/mips/sys/dev/iicbus/xlr_eeprom.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/mips/sys/dev/iicbus/xlr_eeprom.c Thu Oct 15 21:06:59 2009 (r198156) @@ -0,0 +1,156 @@ +/*- + * Copyright (c) 2003-2009 RMI Corporation + * 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. Neither the name of RMI Corporation, nor the names of its contributors, + * may 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 AUTHOR 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. + * + * RMI_BSD */ + +#include +/* + * reading eeprom for the mac address . + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "iicbus_if.h" + +#define IIC_M_WR 0 /* write operation */ +#define XLR_EEPROM_ADDR 0xa0 /* slave address */ +#define XLR_EEPROM_ETH_MAC_ADDR 0x20 + + +struct xlr_eeprom_softc { + device_t sc_dev; + struct mtx sc_mtx; + uint8_t mac_address[6]; +}; + +static void xlr_eeprom_read_mac(struct xlr_eeprom_softc *); + +static int +xlr_eeprom_probe(device_t dev) +{ + /* XXX really probe? */ + device_set_desc(dev, "reading eeprom for mac address"); + return (0); +} + +static int +xlr_eeprom_mac_sysctl(SYSCTL_HANDLER_ARGS) +{ + struct xlr_eeprom_softc *sc = arg1; + int temp ; + + xlr_eeprom_read_mac(sc); + return sysctl_handle_int(oidp, &temp, 0, req); +} + + +static int +xlr_eeprom_attach(device_t dev) +{ + struct xlr_eeprom_softc *sc = device_get_softc(dev); + struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev); + struct sysctl_oid *tree = device_get_sysctl_tree(dev); + + sc->sc_dev = dev; + + + mtx_init(&sc->sc_mtx, "eeprom", "eeprom", MTX_DEF); + + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "eeprom-mac", CTLTYPE_INT | CTLFLAG_RD, sc, 0, + xlr_eeprom_mac_sysctl, "I", "mac address"); + + return (0); +} + +static int +xlr_eeprom_read(device_t dev, int reg) +{ + uint8_t addr = reg; + uint8_t data[1]; + struct iic_msg msgs[2] = { + { XLR_EEPROM_ADDR, IIC_M_WR, 1, &addr }, + { XLR_EEPROM_ADDR, IIC_M_RD, 1, data }, + }; + + return iicbus_transfer(dev, msgs, 2) != 0 ? -1 : data[0]; +} + + +static void +xlr_eeprom_read_mac(struct xlr_eeprom_softc *sc) +{ + int v; + int i; + + mtx_lock(&sc->sc_mtx); + printf("\nmac address is: \n"); + for(i=0; i<6; i++){ + v = xlr_eeprom_read(sc->sc_dev, XLR_EEPROM_ETH_MAC_ADDR+i); + sc->mac_address[i] = v; + if(i != 5) + printf("%x:", sc->mac_address[i]); + else + printf("%x\n", sc->mac_address[i]); + } + mtx_unlock(&sc->sc_mtx); +} + +static device_method_t xlr_eeprom_methods[] = { + DEVMETHOD(device_probe, xlr_eeprom_probe), + DEVMETHOD(device_attach, xlr_eeprom_attach), + + {0, 0}, +}; + +static driver_t xlr_eeprom_driver = { + "xlr_eeprom", + xlr_eeprom_methods, + sizeof(struct xlr_eeprom_softc), +}; +static devclass_t xlr_eeprom_devclass; + +DRIVER_MODULE(xlr_eeprom, iicbus, xlr_eeprom_driver, xlr_eeprom_devclass, 0, 0); +MODULE_VERSION(xlr_eeprom, 1); +MODULE_DEPEND(xlr_eeprom, iicbus, 1, 1, 1); Added: projects/mips/sys/dev/iicbus/xlr_rtc.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/mips/sys/dev/iicbus/xlr_rtc.c Thu Oct 15 21:06:59 2009 (r198156) @@ -0,0 +1,140 @@ +/*- + * Copyright (c) 2003-2009 RMI Corporation + * 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. Neither the name of RMI Corporation, nor the names of its contributors, + * may 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 AUTHOR 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. + * + * RMI_BSD */ + +#include +/* + * RTC chip sitting on the I2C bus. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "iicbus_if.h" +#include "clock_if.h" + +#define IIC_M_WR 0 /* write operation */ +#define XLR_SLAVE_ADDR (0xd0 ) /* slave address */ +#define XLR_RTC_COUNTER 0 /* counter (bytes 0-3) */ +#define NANOSEC 1000000000 + +struct xlr_rtc_softc { + device_t sc_dev; +}; + +static int +xlr_rtc_probe(device_t dev) +{ + device_set_desc(dev, "RTC on XLR board"); + return (0); +} + +static int +xlr_rtc_attach(device_t dev) +{ + struct xlr_rtc_softc *sc = device_get_softc(dev); + + sc->sc_dev = dev; + + clock_register(dev, 1000); + return (0); +} + +static int +xlr_rtc_gettime(device_t dev, struct timespec *ts) +{ + uint8_t addr[1] = { XLR_RTC_COUNTER }; + uint8_t secs[4]; + struct iic_msg msgs[2] = { + { XLR_SLAVE_ADDR, IIC_M_WR, 1, addr }, + { XLR_SLAVE_ADDR, IIC_M_RD, 4, secs }, + }; + int error; + + error = iicbus_transfer(dev, msgs, 2); + if (error == 0) { + /* counter has seconds since epoch */ + ts->tv_sec = (secs[3] << 24) | (secs[2] << 16) + | (secs[1] << 8) | (secs[0] << 0); + ts->tv_nsec = NANOSEC / 2; + } + return error; +} + +static int +xlr_rtc_settime(device_t dev, struct timespec *ts) +{ + /* NB: register pointer precedes actual data */ + uint8_t data[5] = { XLR_RTC_COUNTER }; + struct iic_msg msgs[1] = { + { XLR_SLAVE_ADDR, IIC_M_WR, 5, data }, + }; + + data[1] = (ts->tv_sec >> 0) & 0xff; + data[2] = (ts->tv_sec >> 8) & 0xff; + data[3] = (ts->tv_sec >> 16) & 0xff; + data[4] = (ts->tv_sec >> 24) & 0xff; + + return iicbus_transfer(dev, msgs, 1); +} + +static device_method_t xlr_rtc_methods[] = { + DEVMETHOD(device_probe, xlr_rtc_probe), + DEVMETHOD(device_attach, xlr_rtc_attach), + + DEVMETHOD(clock_gettime, xlr_rtc_gettime), + DEVMETHOD(clock_settime, xlr_rtc_settime), + + {0, 0}, +}; + +static driver_t xlr_rtc_driver = { + "xlr_rtc", + xlr_rtc_methods, + sizeof(struct xlr_rtc_softc), +}; +static devclass_t xlr_rtc_devclass; + +DRIVER_MODULE(xlr_rtc, iicbus, xlr_rtc_driver, xlr_rtc_devclass, 0, 0); +MODULE_VERSION(xlr_rtc, 1); +MODULE_DEPEND(xlr_rtc, iicbus, 1, 1, 1); Added: projects/mips/sys/dev/iicbus/xlr_temperature.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/mips/sys/dev/iicbus/xlr_temperature.c Thu Oct 15 21:06:59 2009 (r198156) @@ -0,0 +1,161 @@ +/*- + * Copyright (c) 2003-2009 RMI Corporation + * 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. Neither the name of RMI Corporation, nor the names of its contributors, + * may 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 AUTHOR 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. + * + * RMI_BSD */ + +#include +/* + * temperature sensor chip sitting on the I2C bus. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "iicbus_if.h" + +#define IIC_M_WR 0 /* write operation */ +#define XLR_TEMPSENSOR_ADDR 0x98 /* slave address */ +#define XLR_ATX8_TEMPSENSOR_ADDR 0x9a /* slave address */ +#define XLR_TEMPSENSOR_EXT_TEMP 1 + + +struct xlr_temperature_softc { + device_t sc_dev; + struct mtx sc_mtx; + int sc_curtemp; + int sc_lastupdate; /* in ticks */ +}; + +static void xlr_temperature_update(struct xlr_temperature_softc *); + +static int +xlr_temperature_probe(device_t dev) +{ + /* XXX really probe? */ + device_set_desc(dev, "temperature sensor on XLR"); + return (0); +} + +static int +xlr_temperature_sysctl_temp(SYSCTL_HANDLER_ARGS) +{ + struct xlr_temperature_softc *sc = arg1; + int temp; + + xlr_temperature_update(sc); + temp = sc->sc_curtemp ; + return sysctl_handle_int(oidp, &temp, 0, req); +} + + +static int +xlr_temperature_attach(device_t dev) +{ + struct xlr_temperature_softc *sc = device_get_softc(dev); + struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(dev); + struct sysctl_oid *tree = device_get_sysctl_tree(dev); + + sc->sc_dev = dev; + mtx_init(&sc->sc_mtx, "xlr_temperature", "xlr_temperature", MTX_DEF); + + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "temp", CTLTYPE_INT | CTLFLAG_RD, sc, 0, + xlr_temperature_sysctl_temp, "I", "operating temperature"); + + return (0); +} + +static int +xlr_temperature_read(device_t dev, int reg) +{ + uint8_t addr = reg; + uint8_t data[1]; + struct iic_msg msgs[2] = { + { XLR_TEMPSENSOR_ADDR, IIC_M_WR, 1, &addr }, + { XLR_TEMPSENSOR_ADDR, IIC_M_RD, 1, data }, + }; + + if(xlr_boot1_info.board_major_version == RMI_XLR_BOARD_ARIZONA_VIII) + { + msgs[0].slave = XLR_ATX8_TEMPSENSOR_ADDR ; + msgs[1].slave = XLR_ATX8_TEMPSENSOR_ADDR ; + } + + return iicbus_transfer(dev, msgs, 2) != 0 ? -1 : data[0]; +} + + +static void +xlr_temperature_update(struct xlr_temperature_softc *sc) +{ + int v; + + mtx_lock(&sc->sc_mtx); + /* NB: no point in updating any faster than the chip */ + if (ticks - sc->sc_lastupdate > hz) { + v = xlr_temperature_read(sc->sc_dev, XLR_TEMPSENSOR_EXT_TEMP); + if (v >= 0) + sc->sc_curtemp = v; + sc->sc_lastupdate = ticks; + } + mtx_unlock(&sc->sc_mtx); +} + +static device_method_t xlr_temperature_methods[] = { + DEVMETHOD(device_probe, xlr_temperature_probe), + DEVMETHOD(device_attach, xlr_temperature_attach), + + {0, 0}, +}; + +static driver_t xlr_temperature_driver = { + "xlr_temperature", + xlr_temperature_methods, + sizeof(struct xlr_temperature_softc), +}; +static devclass_t xlr_temperature_devclass; + +DRIVER_MODULE(xlr_temperature, iicbus, xlr_temperature_driver, xlr_temperature_devclass, 0, 0); +MODULE_VERSION(xlr_temperature, 1); +MODULE_DEPEND(xlr_temperature, iicbus, 1, 1, 1);