From owner-svn-src-head@FreeBSD.ORG Fri Jun 3 18:58:33 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 25A9A106566C; Fri, 3 Jun 2011 18:58:33 +0000 (UTC) (envelope-from andreast@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EFD348FC0A; Fri, 3 Jun 2011 18:58:32 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p53IwWmI076195; Fri, 3 Jun 2011 18:58:32 GMT (envelope-from andreast@svn.freebsd.org) Received: (from andreast@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p53IwW9b076193; Fri, 3 Jun 2011 18:58:32 GMT (envelope-from andreast@svn.freebsd.org) Message-Id: <201106031858.p53IwW9b076193@svn.freebsd.org> From: Andreas Tobler Date: Fri, 3 Jun 2011 18:58:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222658 - head/sys/dev/iicbus X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jun 2011 18:58:33 -0000 Author: andreast Date: Fri Jun 3 18:58:32 2011 New Revision: 222658 URL: http://svn.freebsd.org/changeset/base/222658 Log: - Improve error handling. - Add a retry loop for the i2c sensor reading. - Update the sensor handling for sensors which do not have a location entry. [1] Submitted by: [1] Justin Hibbits. Approved by: nwhitehorn (mentor) Modified: head/sys/dev/iicbus/ds1775.c Modified: head/sys/dev/iicbus/ds1775.c ============================================================================== --- head/sys/dev/iicbus/ds1775.c Fri Jun 3 18:18:54 2011 (r222657) +++ head/sys/dev/iicbus/ds1775.c Fri Jun 3 18:58:32 2011 (r222658) @@ -95,20 +95,28 @@ static int ds1775_read_2(device_t dev, uint32_t addr, uint8_t reg, uint16_t *data) { uint8_t buf[4]; + int err, try = 0; struct iic_msg msg[2] = { { addr, IIC_M_WR | IIC_M_NOSTOP, 1, ® }, { addr, IIC_M_RD, 2, buf }, }; - if (iicbus_transfer(dev, msg, 2) != 0) { - device_printf(dev, "iicbus read failed\n"); - return (EIO); + for (;;) + { + err = iicbus_transfer(dev, msg, 2); + if (err != 0) + goto retry; + + *data = *((uint16_t*)buf); + return (0); + retry: + if (++try > 5) { + device_printf(dev, "iicbus read failed\n"); + return (-1); + } + pause("ds1775_read_2", hz); } - - *data = *((uint16_t*)buf); - - return (0); } static int @@ -182,7 +190,10 @@ ds1775_start(void *xdev) ctx = device_get_sysctl_ctx(dev); sensroot_oid = device_get_sysctl_tree(dev); - OF_getprop(child, "hwsensor-zone", &sc->sc_sensor.zone, sizeof(int)); + if (OF_getprop(child, "hwsensor-zone", &sc->sc_sensor.zone, + sizeof(int)) < 0) + sc->sc_sensor.zone = 0; + plen = OF_getprop(child, "hwsensor-location", sc->sc_sensor.name, sizeof(sc->sc_sensor.name)); units = "C"; @@ -199,8 +210,14 @@ ds1775_start(void *xdev) } /* Make up target temperatures. These are low, for the drive bay. */ - sc->sc_sensor.target_temp = 300 + FCU_ZERO_C_TO_K; - sc->sc_sensor.max_temp = 600 + FCU_ZERO_C_TO_K; + if (sc->sc_sensor.zone == 0) { + sc->sc_sensor.target_temp = 500 + FCU_ZERO_C_TO_K; + sc->sc_sensor.max_temp = 600 + FCU_ZERO_C_TO_K; + } + else { + sc->sc_sensor.target_temp = 300 + FCU_ZERO_C_TO_K; + sc->sc_sensor.max_temp = 600 + FCU_ZERO_C_TO_K; + } sc->sc_sensor.read = (int (*)(struct pmac_therm *sc))(ds1775_sensor_read); @@ -220,8 +237,11 @@ ds1775_sensor_read(struct ds1775_softc * { uint16_t buf[2]; uint16_t read; + int err; - ds1775_read_2(sc->sc_dev, sc->sc_addr, DS1775_TEMP, buf); + err = ds1775_read_2(sc->sc_dev, sc->sc_addr, DS1775_TEMP, buf); + if (err < 0) + return (-1); read = *((int16_t *)buf); @@ -243,6 +263,8 @@ ds1775_sensor_sysctl(SYSCTL_HANDLER_ARGS sc = device_get_softc(dev); temp = ds1775_sensor_read(sc); + if (temp < 0) + return (EIO); error = sysctl_handle_int(oidp, &temp, 0, req);