Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/macppc/dev SMU support, from Phileas Fogg
details: https://anonhg.NetBSD.org/src/rev/0947af2c89be
branches: trunk
changeset: 354182:0947af2c89be
user: macallan <macallan%NetBSD.org@localhost>
date: Tue Jun 06 15:58:17 2017 +0000
description:
SMU support, from Phileas Fogg
diffstat:
sys/arch/macppc/dev/smu.c | 827 ++++++++++++++++++++++++++++++++++++++++
sys/arch/macppc/dev/smuiic.c | 113 +++++
sys/arch/macppc/dev/smuiicvar.h | 38 +
sys/arch/macppc/dev/smusat.c | 387 ++++++++++++++++++
sys/arch/macppc/dev/smuvar.h | 40 +
5 files changed, 1405 insertions(+), 0 deletions(-)
diffs (truncated from 1425 to 300 lines):
diff -r 2728f6720616 -r 0947af2c89be sys/arch/macppc/dev/smu.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/macppc/dev/smu.c Tue Jun 06 15:58:17 2017 +0000
@@ -0,0 +1,827 @@
+/*-
+ * Copyright (c) 2013 Phileas Fogg
+ * 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/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <sys/proc.h>
+#include <sys/mutex.h>
+#include <sys/time.h>
+#include <sys/reboot.h>
+#include <sys/sysctl.h>
+
+#include <machine/autoconf.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/i2c/i2cvar.h>
+#include <dev/clock_subr.h>
+#include <dev/sysmon/sysmonvar.h>
+#include <dev/sysmon/sysmon_taskq.h>
+
+#include <macppc/dev/obiovar.h>
+#include <macppc/dev/smuvar.h>
+
+#include "opt_smu.h"
+
+struct smu_softc;
+
+struct smu_cmd {
+ u_char cmd;
+ u_char len;
+ u_char data[254];
+};
+
+struct smu_fan {
+ struct smu_softc* sc;
+
+ char location[32];
+ int reg;
+ int zone;
+ int rpm_ctl;
+ int min_rpm;
+ int max_rpm;
+ int default_rpm;
+ int current_rpm;
+ time_t last_update;
+};
+
+struct smu_iicbus {
+ struct smu_softc* sc;
+
+ int reg;
+ struct i2c_controller i2c;
+};
+
+#define SMU_MAX_FANS 8
+#define SMU_MAX_IICBUS 3
+#define SMU_MAX_SME_SENSORS SMU_MAX_FANS
+
+struct smu_softc {
+ device_t sc_dev;
+ int sc_node;
+ struct sysctlnode *sc_sysctl_me;
+
+ kmutex_t sc_cmd_lock;
+ struct smu_cmd *sc_cmd;
+ paddr_t sc_cmd_paddr;
+ int sc_dbell_mbox;
+ int sc_dbell_gpio;
+
+ int sc_num_fans;
+ struct smu_fan sc_fans[SMU_MAX_FANS];
+
+ kmutex_t sc_iicbus_lock;
+ int sc_num_iicbus;
+ struct smu_iicbus sc_iicbus[SMU_MAX_IICBUS];
+
+ struct todr_chip_handle sc_todr;
+
+ struct sysmon_envsys *sc_sme;
+ envsys_data_t sc_sme_sensors[SMU_MAX_SME_SENSORS];
+};
+
+#define SMU_CMD_FAN 0x4a
+#define SMU_CMD_RTC 0x8e
+#define SMU_CMD_I2C 0x9a
+#define SMU_CMD_POWER 0xaa
+
+#ifdef SMU_DEBUG
+#define DPRINTF printf
+#else
+#define DPRINTF while (0) printf
+#endif
+
+static int smu_match(device_t, struct cfdata *, void *);
+static void smu_attach(device_t, device_t, void *);
+static int smu_setup_doorbell(struct smu_softc *);
+static void smu_setup_fans(struct smu_softc *);
+static void smu_setup_iicbus(struct smu_softc *);
+static void smu_setup_sme(struct smu_softc *);
+static int smu_iicbus_print(void *, const char *);
+static void smu_sme_refresh(struct sysmon_envsys *, envsys_data_t *);
+static int smu_do_cmd(struct smu_softc *, struct smu_cmd *, int);
+static int smu_dbell_gpio_intr(void *);
+static int smu_todr_gettime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
+static int smu_todr_settime_ymdhms(todr_chip_handle_t, struct clock_ymdhms *);
+static int smu_fan_update_rpm(struct smu_fan *);
+static int smu_fan_get_rpm(struct smu_fan *, int *);
+static int smu_fan_set_rpm(struct smu_fan *, int);
+static int smu_iicbus_acquire_bus(void *, int);
+static void smu_iicbus_release_bus(void *, int);
+static int smu_iicbus_exec(void *, i2c_op_t, i2c_addr_t, const void *,
+ size_t, void *, size_t, int);
+static int smu_sysctl_fan_rpm(SYSCTLFN_ARGS);
+
+CFATTACH_DECL_NEW(smu, sizeof(struct smu_softc),
+ smu_match, smu_attach, NULL, NULL);
+
+static struct smu_softc *smu0 = NULL;
+
+static int
+smu_match(device_t parent, struct cfdata *cf, void *aux)
+{
+ struct confargs *ca = aux;
+
+ if (strcmp(ca->ca_name, "smu") == 0)
+ return 5;
+
+ return 0;
+}
+
+static void
+smu_attach(device_t parent, device_t self, void *aux)
+{
+ struct confargs *ca = aux;
+ struct smu_softc *sc = device_private(self);
+
+ sc->sc_dev = self;
+ sc->sc_node = ca->ca_node;
+
+ sysctl_createv(NULL, 0, NULL, (void *) &sc->sc_sysctl_me,
+ CTLFLAG_READWRITE,
+ CTLTYPE_NODE, device_xname(sc->sc_dev), NULL,
+ NULL, 0, NULL, 0,
+ CTL_MACHDEP, CTL_CREATE, CTL_EOL);
+
+ if (smu_setup_doorbell(sc) != 0) {
+ aprint_normal(": unable to set up doorbell\n");
+ return;
+ }
+
+ smu_setup_fans(sc);
+ smu_setup_iicbus(sc);
+
+ sc->sc_todr.todr_gettime_ymdhms = smu_todr_gettime_ymdhms;
+ sc->sc_todr.todr_settime_ymdhms = smu_todr_settime_ymdhms;
+ sc->sc_todr.cookie = sc;
+ todr_attach(&sc->sc_todr);
+
+ smu_setup_sme(sc);
+
+ if (smu0 == NULL)
+ smu0 = sc;
+
+ printf("\n");
+}
+
+static int
+smu_setup_doorbell(struct smu_softc *sc)
+{
+ int node, parent, reg[4], gpio_base, irq;
+
+ mutex_init(&sc->sc_cmd_lock, MUTEX_DEFAULT, IPL_NONE);
+ sc->sc_cmd = malloc(4096, M_DEVBUF, M_NOWAIT);
+ sc->sc_cmd_paddr = vtophys((vaddr_t) sc->sc_cmd);
+
+ DPRINTF("%s: cmd vaddr 0x%x paddr 0x%x\n",
+ __func__, (unsigned int) sc->sc_cmd,
+ (unsigned int) sc->sc_cmd_paddr);
+
+ if (OF_getprop(sc->sc_node, "platform-doorbell-buff",
+ &node, sizeof(node)) <= 0)
+ return -1;
+
+ if (OF_getprop(node, "platform-do-doorbell-buff",
+ reg, sizeof(reg)) < sizeof(reg))
+ return -1;
+
+ sc->sc_dbell_mbox = reg[3];
+
+ if (OF_getprop(sc->sc_node, "platform-doorbell-ack",
+ &node, sizeof(node)) <= 0)
+ return -1;
+
+ parent = OF_parent(node);
+ if (parent == 0)
+ return -1;
+
+ if (OF_getprop(parent, "reg", &gpio_base, sizeof(gpio_base)) <= 0)
+ return -1;
+
+ if (OF_getprop(node, "reg", reg, sizeof(reg)) <= 0)
+ return -1;
+
+ if (OF_getprop(node, "interrupts", &irq, sizeof(irq)) <= 0)
+ return -1;
+
+ sc->sc_dbell_gpio = gpio_base + reg[0];
+
+ aprint_normal(" mbox 0x%x gpio 0x%x irq %d",
+ sc->sc_dbell_mbox, sc->sc_dbell_gpio, irq);
+
+ intr_establish(irq, IST_EDGE_FALLING, IPL_TTY, smu_dbell_gpio_intr, sc);
+
+ return 0;
+}
+
+static void
+smu_setup_fans(struct smu_softc *sc)
+{
+ struct smu_fan *fan;
+ struct sysctlnode *sysctl_fans, *sysctl_fan, *sysctl_node;
+ char type[32], sysctl_fan_name[32];
+ int node, i, j;
+
+ node = of_getnode_byname(sc->sc_node, "fans");
+ for (node = OF_child(node);
+ (node != 0) && (sc->sc_num_fans < SMU_MAX_FANS);
+ node = OF_peer(node)) {
+ fan = &sc->sc_fans[sc->sc_num_fans];
+ fan->sc = sc;
+
+ memset(fan->location, 0, sizeof(fan->location));
+ OF_getprop(node, "location", fan->location,
+ sizeof(fan->location));
+
+ if (OF_getprop(node, "reg", &fan->reg,
+ sizeof(fan->reg)) <= 0)
+ continue;
+
+ if (OF_getprop(node, "zone", &fan->zone,
+ sizeof(fan->zone)) <= 0)
+ continue;
+
+ memset(type, 0, sizeof(type));
+ OF_getprop(node, "device_type", type, sizeof(type));
+ if (strcmp(type, "fan-rpm-control") == 0)
+ fan->rpm_ctl = 1;
+ else
+ fan->rpm_ctl = 0;
+
+ if (OF_getprop(node, "min-value", &fan->min_rpm,
+ sizeof(fan->min_rpm)) <= 0)
+ fan->min_rpm = 0;
+
+ if (OF_getprop(node, "max-value", &fan->max_rpm,
+ sizeof(fan->max_rpm)) <= 0)
+ fan->max_rpm = 0xffff;
+
+ if (OF_getprop(node, "unmanage-value", &fan->default_rpm,
+ sizeof(fan->default_rpm)) <= 0)
+ fan->default_rpm = fan->max_rpm;
+
+ DPRINTF("fan: location %s reg %x zone %d rpm_ctl %d "
+ "min_rpm %d max_rpm %d default_rpm %d\n",
+ fan->location, fan->reg, fan->zone, fan->rpm_ctl,
+ fan->min_rpm, fan->max_rpm, fan->default_rpm);
+
+ sc->sc_num_fans++;
+ }
+
+ for (i = 0; i < sc->sc_num_fans; i++) {
Home |
Main Index |
Thread Index |
Old Index