From owner-svn-src-all@freebsd.org Fri Mar 6 21:32:43 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EFB682517C8; Fri, 6 Mar 2020 21:32:43 +0000 (UTC) (envelope-from andreast@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48Z16z3Xspz444C; Fri, 6 Mar 2020 21:32:43 +0000 (UTC) (envelope-from andreast@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7407D2674E; Fri, 6 Mar 2020 21:32:42 +0000 (UTC) (envelope-from andreast@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 026LWglc074428; Fri, 6 Mar 2020 21:32:42 GMT (envelope-from andreast@FreeBSD.org) Received: (from andreast@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 026LWgGA074427; Fri, 6 Mar 2020 21:32:42 GMT (envelope-from andreast@FreeBSD.org) Message-Id: <202003062132.026LWgGA074427@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andreast set sender to andreast@FreeBSD.org using -f From: Andreas Tobler Date: Fri, 6 Mar 2020 21:32:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r358723 - head/sys/dev/iicbus X-SVN-Group: head X-SVN-Commit-Author: andreast X-SVN-Commit-Paths: head/sys/dev/iicbus X-SVN-Commit-Revision: 358723 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Mar 2020 21:32:44 -0000 Author: andreast Date: Fri Mar 6 21:32:42 2020 New Revision: 358723 URL: https://svnweb.freebsd.org/changeset/base/358723 Log: Drop 'All rights reserved' Replace hardcoded sizes by nitems and sizeof Replace CTLFLAG_NEEDGIANT with CTLFLAG_MPSAFE, I run this driver since a few years with CTLFLAG_MPSAFE w/o issues. Add a HACK to handle a special case for a sensor location. Modified: head/sys/dev/iicbus/ad7417.c Modified: head/sys/dev/iicbus/ad7417.c ============================================================================== --- head/sys/dev/iicbus/ad7417.c Fri Mar 6 21:26:35 2020 (r358722) +++ head/sys/dev/iicbus/ad7417.c Fri Mar 6 21:32:42 2020 (r358723) @@ -2,7 +2,6 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2010 Andreas Tobler - * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -143,7 +142,7 @@ ad7417_write(device_t dev, uint32_t addr, uint8_t reg, for (;;) { - if (iicbus_transfer(dev, msg, 1) == 0) + if (iicbus_transfer(dev, msg, nitems(msg)) == 0) return (0); if (++try > 5) { @@ -167,7 +166,7 @@ ad7417_read_1(device_t dev, uint32_t addr, uint8_t reg for (;;) { - err = iicbus_transfer(dev, msg, 2); + err = iicbus_transfer(dev, msg, nitems(msg)); if (err != 0) goto retry; @@ -195,7 +194,7 @@ ad7417_read_2(device_t dev, uint32_t addr, uint8_t reg for (;;) { - err = iicbus_transfer(dev, msg, 2); + err = iicbus_transfer(dev, msg, nitems(msg)); if (err != 0) goto retry; @@ -230,7 +229,7 @@ ad7417_write_read(device_t dev, uint32_t addr, struct for (;;) { - err = iicbus_transfer(dev, msg, 3); + err = iicbus_transfer(dev, msg, nitems(msg)); if (err != 0) goto retry; @@ -258,18 +257,18 @@ ad7417_init_adc(device_t dev, uint32_t addr) /* Clear Config2 */ buf = 0; - err = ad7417_write(dev, addr, AD7417_CONFIG2, &buf, 1); + err = ad7417_write(dev, addr, AD7417_CONFIG2, &buf, sizeof(buf)); /* Read & cache Config1 */ buf = 0; - err = ad7417_write(dev, addr, AD7417_CONFIG, &buf, 1); + err = ad7417_write(dev, addr, AD7417_CONFIG, &buf, sizeof(buf)); err = ad7417_read_1(dev, addr, AD7417_CONFIG, &buf); adc741x_config = (uint8_t)buf; /* Disable shutdown mode */ adc741x_config &= 0xfe; buf = adc741x_config; - err = ad7417_write(dev, addr, AD7417_CONFIG, &buf, 1); + err = ad7417_write(dev, addr, AD7417_CONFIG, &buf, sizeof(buf)); if (err < 0) return (-1); @@ -310,7 +309,7 @@ ad7417_probe(device_t dev) static int ad7417_fill_sensor_prop(device_t dev) { - phandle_t child; + phandle_t child, node; struct ad7417_softc *sc; u_int id[10]; char location[96]; @@ -359,13 +358,27 @@ ad7417_fill_sensor_prop(device_t dev) for (j = 0; j < i; j++) sc->sc_sensors[j].therm.zone = id[j]; + /* Some PowerMac's have the real location of the sensors on + child nodes of the hwsensor-location node. Check for and + fix the name if needed. + This is needed to apply the below HACK with the diode. + */ + j = 0; + for (node = OF_child(child); node != 0; node = OF_peer(node)) { + + OF_getprop(node, "location", location, sizeof(location)); + strcpy(sc->sc_sensors[i].therm.name, location); + j++; + } + /* Finish setting up sensor properties */ for (j = 0; j < i; j++) { sc->sc_sensors[j].dev = dev; /* HACK: Apple wired a random diode to the ADC line */ - if (strstr(sc->sc_sensors[j].therm.name, "DIODE TEMP") - != NULL) { + if ((strstr(sc->sc_sensors[j].therm.name, "DIODE TEMP") + != NULL) + || (strstr(sc->sc_sensors[j].therm.name, "AD1") != NULL)) { sc->sc_sensors[j].type = ADC7417_TEMP_SENSOR; sc->sc_sensors[j].therm.read = (int (*)(struct pmac_therm *))(ad7417_diode_read); @@ -444,10 +457,10 @@ ad7417_attach(device_t dev) } /* I use i to pass the sensor id. */ SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, - unit, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, dev, - i, ad7417_sensor_sysctl, - sc->sc_sensors[i].type == ADC7417_TEMP_SENSOR ? "IK" : "I", - desc); + unit, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, + dev, i, ad7417_sensor_sysctl, + sc->sc_sensors[i].type == ADC7417_TEMP_SENSOR ? + "IK" : "I", desc); } /* Dump sensor location, ID & type. */ if (bootverbose) {