Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/i2c move the fcu driver into arch/macppc where it be...
details: https://anonhg.NetBSD.org/src/rev/c79c71a499bc
branches: trunk
changeset: 984882:c79c71a499bc
user: macallan <macallan%NetBSD.org@localhost>
date: Tue Jul 27 20:23:41 2021 +0000
description:
move the fcu driver into arch/macppc where it belongs
diffstat:
sys/arch/macppc/conf/files.macppc | 7 +-
sys/arch/macppc/dev/fcu.c | 493 ++++++++++++++++++++++++++++++++++++++
sys/dev/i2c/fcu.c | 493 --------------------------------------
sys/dev/i2c/files.i2c | 7 +-
4 files changed, 500 insertions(+), 500 deletions(-)
diffs (truncated from 1033 to 300 lines):
diff -r fa1ed246b356 -r c79c71a499bc sys/arch/macppc/conf/files.macppc
--- a/sys/arch/macppc/conf/files.macppc Tue Jul 27 15:29:22 2021 +0000
+++ b/sys/arch/macppc/conf/files.macppc Tue Jul 27 20:23:41 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.macppc,v 1.119 2021/06/18 22:24:51 macallan Exp $
+# $NetBSD: files.macppc,v 1.120 2021/07/27 20:23:41 macallan Exp $
#
# macppc-specific configuration info
@@ -326,3 +326,8 @@
attach lmu at iic
file arch/macppc/dev/lmu.c lmu
defflag opt_lmu.h LMU_DEBUG
+
+# Apple Fan Control Unit found in some G5
+device fcu: sysmon_envsys
+attach fcu at iic
+file arch/macppc/dev/fcu.c fcu needs-flag
diff -r fa1ed246b356 -r c79c71a499bc sys/arch/macppc/dev/fcu.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/macppc/dev/fcu.c Tue Jul 27 20:23:41 2021 +0000
@@ -0,0 +1,493 @@
+/* $NetBSD: fcu.c,v 1.1 2021/07/27 20:23:41 macallan Exp $ */
+
+/*-
+ * Copyright (c) 2018 Michael Lorenz
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.1 2021/07/27 20:23:41 macallan Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/bus.h>
+#include <sys/kthread.h>
+
+#include <dev/i2c/i2cvar.h>
+
+#include <dev/sysmon/sysmonvar.h>
+
+#include <dev/ofw/openfirm.h>
+
+//#define FCU_DEBUG
+#ifdef FCU_DEBUG
+#define DPRINTF printf
+#else
+#define DPRINTF if (0) printf
+#endif
+
+/* FCU registers, from OpenBSD's fcu.c */
+#define FCU_FAN_FAIL 0x0b /* fans states in bits 0<1-6>7 */
+#define FCU_FAN_ACTIVE 0x0d
+#define FCU_FANREAD(x) 0x11 + (x)*2
+#define FCU_FANSET(x) 0x10 + (x)*2
+#define FCU_PWM_FAIL 0x2b
+#define FCU_PWM_ACTIVE 0x2d
+#define FCU_PWMREAD(x) 0x30 + (x)*2
+
+#define FCU_MAX_FANS 10
+
+typedef struct _fcu_zone {
+ bool (*filter)(const envsys_data_t *);
+ int nfans;
+ int fans[FCU_MAX_FANS];
+ int threshold;
+} fcu_zone_t;
+
+typedef struct _fcu_fan {
+ int target;
+ int reg;
+ int base_rpm, max_rpm;
+ int step;
+ int duty; /* for pwm fans */
+} fcu_fan_t;
+
+#define FCU_ZONE_CPU 0
+#define FCU_ZONE_CASE 1
+#define FCU_ZONE_DRIVEBAY 2
+#define FCU_ZONE_COUNT 3
+
+struct fcu_softc {
+ device_t sc_dev;
+ i2c_tag_t sc_i2c;
+ i2c_addr_t sc_addr;
+
+ struct sysmon_envsys *sc_sme;
+ envsys_data_t sc_sensors[32];
+ int sc_nsensors;
+ fcu_zone_t sc_zones[FCU_ZONE_COUNT];
+ fcu_fan_t sc_fans[FCU_MAX_FANS];
+ int sc_nfans;
+ lwp_t *sc_thread;
+ bool sc_dying, sc_pwm;
+ uint8_t sc_eeprom0[160];
+ uint8_t sc_eeprom1[160];
+};
+
+static int fcu_match(device_t, cfdata_t, void *);
+static void fcu_attach(device_t, device_t, void *);
+
+static void fcu_sensors_refresh(struct sysmon_envsys *, envsys_data_t *);
+
+static bool is_cpu(const envsys_data_t *);
+static bool is_case(const envsys_data_t *);
+static bool is_drive(const envsys_data_t *);
+
+static void fcu_set_fan_rpm(struct fcu_softc *, fcu_fan_t *, int);
+static void fcu_adjust_zone(struct fcu_softc *, int);
+static void fcu_adjust(void *);
+
+CFATTACH_DECL_NEW(fcu, sizeof(struct fcu_softc),
+ fcu_match, fcu_attach, NULL, NULL);
+
+static const struct device_compatible_entry compat_data[] = {
+ { .compat = "fcu" },
+ DEVICE_COMPAT_EOL
+};
+
+static int
+fcu_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct i2c_attach_args *ia = aux;
+ int match_result;
+
+ if (iic_use_direct_match(ia, match, compat_data, &match_result))
+ return match_result;
+
+ if (ia->ia_addr == 0x2f)
+ return I2C_MATCH_ADDRESS_ONLY;
+
+ return 0;
+}
+
+static void
+fcu_attach(device_t parent, device_t self, void *aux)
+{
+ struct fcu_softc *sc = device_private(self);
+ struct i2c_attach_args *ia = aux;
+ int have_eeprom1 = 1;
+
+ sc->sc_dev = self;
+ sc->sc_i2c = ia->ia_tag;
+ sc->sc_addr = ia->ia_addr;
+
+ aprint_naive("\n");
+ aprint_normal(": Fan Control Unit\n");
+
+ if (get_cpuid(0, sc->sc_eeprom0) < 160) {
+ /*
+ * XXX this should never happen, we depend on the EEPROM for
+ * calibration data to make sense of temperature and voltage
+ * sensors elsewhere, and fan parameters here.
+ */
+ aprint_error_dev(self, "no EEPROM data for CPU 0\n");
+ return;
+ }
+ if (get_cpuid(1, sc->sc_eeprom1) < 160)
+ have_eeprom1 = 0;
+
+ /* init zones */
+ sc->sc_zones[FCU_ZONE_CPU].filter = is_cpu;
+ sc->sc_zones[FCU_ZONE_CPU].threshold = 50;
+ sc->sc_zones[FCU_ZONE_CPU].nfans = 0;
+ sc->sc_zones[FCU_ZONE_CASE].filter = is_case;
+ sc->sc_zones[FCU_ZONE_CASE].threshold = 50;
+ sc->sc_zones[FCU_ZONE_CASE].nfans = 0;
+ sc->sc_zones[FCU_ZONE_DRIVEBAY].filter = is_drive;
+ sc->sc_zones[FCU_ZONE_DRIVEBAY].threshold = 30;
+ sc->sc_zones[FCU_ZONE_DRIVEBAY].nfans = 0;
+
+ sc->sc_sme = sysmon_envsys_create();
+ sc->sc_sme->sme_name = device_xname(self);
+ sc->sc_sme->sme_cookie = sc;
+ sc->sc_sme->sme_refresh = fcu_sensors_refresh;
+
+ sc->sc_sensors[0].units = ENVSYS_SFANRPM;
+ sc->sc_sensors[1].state = ENVSYS_SINVALID;
+ sc->sc_nfans = 0;
+
+ /* round up sensors */
+ int ch;
+
+ sc->sc_nsensors = 0;
+ ch = OF_child(ia->ia_cookie);
+ while (ch != 0) {
+ char type[32], descr[32];
+ uint32_t reg;
+
+ envsys_data_t *s = &sc->sc_sensors[sc->sc_nsensors];
+
+ s->state = ENVSYS_SINVALID;
+
+ if (OF_getprop(ch, "device_type", type, 32) <= 0)
+ goto next;
+
+ if (strcmp(type, "fan-rpm-control") == 0) {
+ s->units = ENVSYS_SFANRPM;
+ } else if (strcmp(type, "fan-pwm-control") == 0) {
+ /* XXX we get the type from the register number */
+ s->units = ENVSYS_SFANRPM;
+/* skip those for now since we don't really know how to interpret them */
+#if 0
+ } else if (strcmp(type, "power-sensor") == 0) {
+ s->units = ENVSYS_SVOLTS_DC;
+#endif
+ } else if (strcmp(type, "gpi-sensor") == 0) {
+ s->units = ENVSYS_INDICATOR;
+ } else {
+ /* ignore other types for now */
+ goto next;
+ }
+
+ if (OF_getprop(ch, "reg", ®, sizeof(reg)) <= 0)
+ goto next;
+ s->private = reg;
+
+ if (OF_getprop(ch, "location", descr, 32) <= 0)
+ goto next;
+ strcpy(s->desc, descr);
+
+ if (s->units == ENVSYS_SFANRPM) {
+ fcu_fan_t *fan = &sc->sc_fans[sc->sc_nfans];
+ uint8_t *eeprom = NULL;
+ uint16_t rmin, rmax;
+
+ if (strstr(descr, "CPU A") != NULL)
+ eeprom = sc->sc_eeprom0;
+ if (strstr(descr, "CPU B") != NULL) {
+ /*
+ * XXX
+ * this should never happen
+ */
+ if (have_eeprom1 == 0) {
+ eeprom = sc->sc_eeprom0;
+ } else
+ eeprom = sc->sc_eeprom1;
+ }
+
+ fan->reg = reg;
+ fan->target = 0;
+ fan->duty = 0x80;
+
+ /* speed settings from EEPROM */
+ if (strstr(descr, "PUMP") != NULL) {
+ KASSERT(eeprom != NULL);
+ memcpy(&rmin, &eeprom[0x54], 2);
+ memcpy(&rmax, &eeprom[0x56], 2);
+ fan->base_rpm = rmin;
+ fan->max_rpm = rmax;
+ fan->step = (rmax - rmin) / 30;
+ } else if (strstr(descr, "INTAKE") != NULL) {
+ KASSERT(eeprom != NULL);
+ memcpy(&rmin, &eeprom[0x4c], 2);
+ memcpy(&rmax, &eeprom[0x4e], 2);
+ fan->base_rpm = rmin;
+ fan->max_rpm = rmax;
+ fan->step = (rmax - rmin) / 30;
+ } else if (strstr(descr, "EXHAUST") != NULL) {
+ KASSERT(eeprom != NULL);
+ memcpy(&rmin, &eeprom[0x50], 2);
+ memcpy(&rmax, &eeprom[0x52], 2);
+ fan->base_rpm = rmin;
+ fan->max_rpm = rmax;
+ fan->step = (rmax - rmin) / 30;
+ } else if (strstr(descr, "DRIVE") != NULL ) {
+ fan->base_rpm = 1000;
+ fan->max_rpm = 3000;
+ fan->step = 100;
+ } else {
+ fan->base_rpm = 1000;
+ fan->max_rpm = 3000;
+ fan->step = 100;
+ }
+ DPRINTF("fan %s: %d - %d rpm, step %d\n",
+ descr, fan->base_rpm, fan->max_rpm, fan->step);
+
Home |
Main Index |
Thread Index |
Old Index