svn commit: r358723 - head/sys/dev/iicbus
Andreas Tobler
andreast at FreeBSD.org
Fri Mar 6 21:32:44 UTC 2020
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) {
More information about the svn-src-all
mailing list