12d5e81fbSEmmanuel Vadot /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
32d5e81fbSEmmanuel Vadot *
42d5e81fbSEmmanuel Vadot * Copyright (c) 2018 Rubicon Communications, LLC (Netgate)
52d5e81fbSEmmanuel Vadot *
62d5e81fbSEmmanuel Vadot * Redistribution and use in source and binary forms, with or without
72d5e81fbSEmmanuel Vadot * modification, are permitted provided that the following conditions
82d5e81fbSEmmanuel Vadot * are met:
92d5e81fbSEmmanuel Vadot * 1. Redistributions of source code must retain the above copyright
102d5e81fbSEmmanuel Vadot * notice, this list of conditions and the following disclaimer.
112d5e81fbSEmmanuel Vadot * 2. Redistributions in binary form must reproduce the above copyright
122d5e81fbSEmmanuel Vadot * notice, this list of conditions and the following disclaimer in the
132d5e81fbSEmmanuel Vadot * documentation and/or other materials provided with the distribution.
142d5e81fbSEmmanuel Vadot *
152d5e81fbSEmmanuel Vadot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
162d5e81fbSEmmanuel Vadot * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
172d5e81fbSEmmanuel Vadot * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
182d5e81fbSEmmanuel Vadot * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
192d5e81fbSEmmanuel Vadot * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
202d5e81fbSEmmanuel Vadot * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
212d5e81fbSEmmanuel Vadot * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
222d5e81fbSEmmanuel Vadot * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
232d5e81fbSEmmanuel Vadot * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
242d5e81fbSEmmanuel Vadot * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
252d5e81fbSEmmanuel Vadot * SUCH DAMAGE.
262d5e81fbSEmmanuel Vadot */
272d5e81fbSEmmanuel Vadot
282d5e81fbSEmmanuel Vadot #include <sys/param.h>
292d5e81fbSEmmanuel Vadot #include <sys/systm.h>
302d5e81fbSEmmanuel Vadot #include <sys/bus.h>
312d5e81fbSEmmanuel Vadot
322d5e81fbSEmmanuel Vadot #include <sys/kernel.h>
332d5e81fbSEmmanuel Vadot #include <sys/module.h>
342d5e81fbSEmmanuel Vadot #include <sys/rman.h>
352d5e81fbSEmmanuel Vadot #include <sys/lock.h>
362d5e81fbSEmmanuel Vadot #include <sys/mutex.h>
372d5e81fbSEmmanuel Vadot #include <sys/sysctl.h>
382d5e81fbSEmmanuel Vadot
392d5e81fbSEmmanuel Vadot #include <machine/bus.h>
402d5e81fbSEmmanuel Vadot #include <machine/resource.h>
412d5e81fbSEmmanuel Vadot #include <machine/intr.h>
42*62e8ccc3SEmmanuel Vadot #include <dev/syscon/syscon.h>
432d5e81fbSEmmanuel Vadot
442d5e81fbSEmmanuel Vadot #include <dev/ofw/ofw_bus.h>
452d5e81fbSEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h>
462d5e81fbSEmmanuel Vadot
474b84206bSMichal Meloun #include "syscon_if.h"
484b84206bSMichal Meloun
494b84206bSMichal Meloun #define CONTROL0 0 /* Offset in config->regs[] array */
502d5e81fbSEmmanuel Vadot #define CONTROL0_TSEN_START (1 << 0)
512d5e81fbSEmmanuel Vadot #define CONTROL0_TSEN_RESET (1 << 1)
522d5e81fbSEmmanuel Vadot #define CONTROL0_TSEN_EN (1 << 2)
532d5e81fbSEmmanuel Vadot #define CONTROL0_CHANNEL_SHIFT 13
542d5e81fbSEmmanuel Vadot #define CONTROL0_CHANNEL_MASK 0xF
552d5e81fbSEmmanuel Vadot #define CONTROL0_OSR_SHIFT 24
562d5e81fbSEmmanuel Vadot #define CONTROL0_OSR_MAX 3 /* OSR = 512 * 4uS = ~2mS */
572d5e81fbSEmmanuel Vadot #define CONTROL0_MODE_SHIFT 30
582d5e81fbSEmmanuel Vadot #define CONTROL0_MODE_EXTERNAL 0x2
592d5e81fbSEmmanuel Vadot #define CONTROL0_MODE_MASK 0x3
602d5e81fbSEmmanuel Vadot
614b84206bSMichal Meloun #define CONTROL1 1 /* Offset in config->regs[] array */
622d5e81fbSEmmanuel Vadot /* This doesn't seems to work */
632d5e81fbSEmmanuel Vadot #define CONTROL1_TSEN_SENS_SHIFT 21
642d5e81fbSEmmanuel Vadot #define CONTROL1_TSEN_SENS_MASK 0x7
652d5e81fbSEmmanuel Vadot
664b84206bSMichal Meloun #define STATUS 2 /* Offset in config->regs[] array */
672d5e81fbSEmmanuel Vadot #define STATUS_TEMP_MASK 0x3FF
682d5e81fbSEmmanuel Vadot
692d5e81fbSEmmanuel Vadot enum mv_thermal_type {
702d5e81fbSEmmanuel Vadot MV_AP806 = 1,
712d5e81fbSEmmanuel Vadot MV_CP110,
722d5e81fbSEmmanuel Vadot };
732d5e81fbSEmmanuel Vadot
742d5e81fbSEmmanuel Vadot struct mv_thermal_config {
752d5e81fbSEmmanuel Vadot enum mv_thermal_type type;
764b84206bSMichal Meloun int regs[3];
772d5e81fbSEmmanuel Vadot int ncpus;
782d5e81fbSEmmanuel Vadot int64_t calib_mul;
792d5e81fbSEmmanuel Vadot int64_t calib_add;
802d5e81fbSEmmanuel Vadot int64_t calib_div;
812d5e81fbSEmmanuel Vadot uint32_t valid_mask;
822d5e81fbSEmmanuel Vadot bool signed_value;
832d5e81fbSEmmanuel Vadot };
842d5e81fbSEmmanuel Vadot
852d5e81fbSEmmanuel Vadot struct mv_thermal_softc {
862d5e81fbSEmmanuel Vadot device_t dev;
874b84206bSMichal Meloun struct syscon *syscon;
882d5e81fbSEmmanuel Vadot struct mtx mtx;
892d5e81fbSEmmanuel Vadot
902d5e81fbSEmmanuel Vadot struct mv_thermal_config *config;
912d5e81fbSEmmanuel Vadot int cur_sensor;
922d5e81fbSEmmanuel Vadot };
932d5e81fbSEmmanuel Vadot
942d5e81fbSEmmanuel Vadot static struct mv_thermal_config mv_ap806_config = {
952d5e81fbSEmmanuel Vadot .type = MV_AP806,
964b84206bSMichal Meloun .regs = {0x84, 0x88, 0x8C},
972d5e81fbSEmmanuel Vadot .ncpus = 4,
982d5e81fbSEmmanuel Vadot .calib_mul = 423,
992d5e81fbSEmmanuel Vadot .calib_add = -150000,
1002d5e81fbSEmmanuel Vadot .calib_div = 100,
1012d5e81fbSEmmanuel Vadot .valid_mask = (1 << 16),
1022d5e81fbSEmmanuel Vadot .signed_value = true,
1032d5e81fbSEmmanuel Vadot };
1042d5e81fbSEmmanuel Vadot
1052d5e81fbSEmmanuel Vadot static struct mv_thermal_config mv_cp110_config = {
1062d5e81fbSEmmanuel Vadot .type = MV_CP110,
1074b84206bSMichal Meloun .regs = {0x70, 0x74, 0x78},
1082d5e81fbSEmmanuel Vadot .calib_mul = 2000096,
1092d5e81fbSEmmanuel Vadot .calib_add = 1172499100,
1102d5e81fbSEmmanuel Vadot .calib_div = 420100,
1112d5e81fbSEmmanuel Vadot .valid_mask = (1 << 10),
1122d5e81fbSEmmanuel Vadot .signed_value = false,
1132d5e81fbSEmmanuel Vadot };
1142d5e81fbSEmmanuel Vadot
1152d5e81fbSEmmanuel Vadot static struct ofw_compat_data compat_data[] = {
1162d5e81fbSEmmanuel Vadot {"marvell,armada-ap806-thermal", (uintptr_t) &mv_ap806_config},
1172d5e81fbSEmmanuel Vadot {"marvell,armada-cp110-thermal", (uintptr_t) &mv_cp110_config},
1182d5e81fbSEmmanuel Vadot {NULL, 0}
1192d5e81fbSEmmanuel Vadot };
1202d5e81fbSEmmanuel Vadot
1214b84206bSMichal Meloun #define RD4(sc, reg) \
1224b84206bSMichal Meloun SYSCON_READ_4((sc)->syscon, sc->config->regs[reg])
1234b84206bSMichal Meloun #define WR4(sc, reg, val) \
1244b84206bSMichal Meloun SYSCON_WRITE_4((sc)->syscon, sc->config->regs[reg], (val))
1252d5e81fbSEmmanuel Vadot
sign_extend(uint32_t value,int index)1262d5e81fbSEmmanuel Vadot static inline int32_t sign_extend(uint32_t value, int index)
1272d5e81fbSEmmanuel Vadot {
1282d5e81fbSEmmanuel Vadot uint8_t shift;
1292d5e81fbSEmmanuel Vadot
1302d5e81fbSEmmanuel Vadot shift = 31 - index;
1312d5e81fbSEmmanuel Vadot return ((int32_t)(value << shift) >> shift);
1322d5e81fbSEmmanuel Vadot }
1332d5e81fbSEmmanuel Vadot
1342d5e81fbSEmmanuel Vadot static int
mv_thermal_wait_sensor(struct mv_thermal_softc * sc)1352d5e81fbSEmmanuel Vadot mv_thermal_wait_sensor(struct mv_thermal_softc *sc)
1362d5e81fbSEmmanuel Vadot {
1372d5e81fbSEmmanuel Vadot uint32_t reg;
1382d5e81fbSEmmanuel Vadot uint32_t timeout;
1392d5e81fbSEmmanuel Vadot
1402d5e81fbSEmmanuel Vadot timeout = 100000;
1412d5e81fbSEmmanuel Vadot while (--timeout > 0) {
1424b84206bSMichal Meloun reg = RD4(sc, STATUS);
1432d5e81fbSEmmanuel Vadot if ((reg & sc->config->valid_mask) == sc->config->valid_mask)
1442d5e81fbSEmmanuel Vadot break;
1452d5e81fbSEmmanuel Vadot DELAY(100);
1462d5e81fbSEmmanuel Vadot }
1472d5e81fbSEmmanuel Vadot if (timeout == 0) {
1482d5e81fbSEmmanuel Vadot return (ETIMEDOUT);
1492d5e81fbSEmmanuel Vadot }
1502d5e81fbSEmmanuel Vadot
1512d5e81fbSEmmanuel Vadot return (0);
1522d5e81fbSEmmanuel Vadot }
1532d5e81fbSEmmanuel Vadot
1542d5e81fbSEmmanuel Vadot static int
mv_thermal_select_sensor(struct mv_thermal_softc * sc,int sensor)1552d5e81fbSEmmanuel Vadot mv_thermal_select_sensor(struct mv_thermal_softc *sc, int sensor)
1562d5e81fbSEmmanuel Vadot {
1572d5e81fbSEmmanuel Vadot uint32_t reg;
1582d5e81fbSEmmanuel Vadot
1592d5e81fbSEmmanuel Vadot if (sc->cur_sensor == sensor)
1602d5e81fbSEmmanuel Vadot return (0);
1612d5e81fbSEmmanuel Vadot
1622d5e81fbSEmmanuel Vadot /* Stop the current reading and reset the module */
1634b84206bSMichal Meloun reg = RD4(sc, CONTROL0);
1642d5e81fbSEmmanuel Vadot reg &= ~(CONTROL0_TSEN_START | CONTROL0_TSEN_EN);
1654b84206bSMichal Meloun WR4(sc, CONTROL0, reg);
1662d5e81fbSEmmanuel Vadot
1672d5e81fbSEmmanuel Vadot /* Switch to the selected sensor */
1682d5e81fbSEmmanuel Vadot /*
1692d5e81fbSEmmanuel Vadot * NOTE : Datasheet says to use CONTROL1 for selecting
1702d5e81fbSEmmanuel Vadot * but when doing so the sensors >0 are never ready
1712d5e81fbSEmmanuel Vadot * Do what Linux does using undocumented bits in CONTROL0
1722d5e81fbSEmmanuel Vadot */
1732d5e81fbSEmmanuel Vadot /* This reset automatically to the sensor 0 */
1742d5e81fbSEmmanuel Vadot reg &= ~(CONTROL0_MODE_MASK << CONTROL0_MODE_SHIFT);
1752d5e81fbSEmmanuel Vadot if (sensor) {
1762d5e81fbSEmmanuel Vadot /* Select external sensor */
1772d5e81fbSEmmanuel Vadot reg |= CONTROL0_MODE_EXTERNAL << CONTROL0_MODE_SHIFT;
1782d5e81fbSEmmanuel Vadot reg &= ~(CONTROL0_CHANNEL_MASK << CONTROL0_CHANNEL_SHIFT);
1792d5e81fbSEmmanuel Vadot reg |= (sensor - 1) << CONTROL0_CHANNEL_SHIFT;
1802d5e81fbSEmmanuel Vadot }
1814b84206bSMichal Meloun WR4(sc, CONTROL0, reg);
1822d5e81fbSEmmanuel Vadot sc->cur_sensor = sensor;
1832d5e81fbSEmmanuel Vadot
1842d5e81fbSEmmanuel Vadot /* Start the reading */
1854b84206bSMichal Meloun reg = RD4(sc, CONTROL0);
1862d5e81fbSEmmanuel Vadot reg |= CONTROL0_TSEN_START | CONTROL0_TSEN_EN;
1874b84206bSMichal Meloun WR4(sc, CONTROL0, reg);
1882d5e81fbSEmmanuel Vadot
1892d5e81fbSEmmanuel Vadot return (mv_thermal_wait_sensor(sc));
1902d5e81fbSEmmanuel Vadot }
1912d5e81fbSEmmanuel Vadot
1922d5e81fbSEmmanuel Vadot static int
mv_thermal_read_sensor(struct mv_thermal_softc * sc,int sensor,int * temp)1932d5e81fbSEmmanuel Vadot mv_thermal_read_sensor(struct mv_thermal_softc *sc, int sensor, int *temp)
1942d5e81fbSEmmanuel Vadot {
1952d5e81fbSEmmanuel Vadot uint32_t reg;
1962d5e81fbSEmmanuel Vadot int64_t sample, rv;
1972d5e81fbSEmmanuel Vadot
1982d5e81fbSEmmanuel Vadot rv = mv_thermal_select_sensor(sc, sensor);
1992d5e81fbSEmmanuel Vadot if (rv != 0)
2002d5e81fbSEmmanuel Vadot return (rv);
2012d5e81fbSEmmanuel Vadot
2024b84206bSMichal Meloun reg = RD4(sc, STATUS) & STATUS_TEMP_MASK;
2032d5e81fbSEmmanuel Vadot
2042d5e81fbSEmmanuel Vadot if (sc->config->signed_value)
2052d5e81fbSEmmanuel Vadot sample = sign_extend(reg, fls(STATUS_TEMP_MASK) - 1);
2062d5e81fbSEmmanuel Vadot else
2072d5e81fbSEmmanuel Vadot sample = reg;
2082d5e81fbSEmmanuel Vadot
2092d5e81fbSEmmanuel Vadot *temp = ((sample * sc->config->calib_mul) - sc->config->calib_add) /
2102d5e81fbSEmmanuel Vadot sc->config->calib_div;
2112d5e81fbSEmmanuel Vadot
2122d5e81fbSEmmanuel Vadot return (0);
2132d5e81fbSEmmanuel Vadot }
2142d5e81fbSEmmanuel Vadot
2152d5e81fbSEmmanuel Vadot static int
ap806_init(struct mv_thermal_softc * sc)2162d5e81fbSEmmanuel Vadot ap806_init(struct mv_thermal_softc *sc)
2172d5e81fbSEmmanuel Vadot {
2182d5e81fbSEmmanuel Vadot uint32_t reg;
2192d5e81fbSEmmanuel Vadot
2202d5e81fbSEmmanuel Vadot /* Start the temp capture/conversion */
2214b84206bSMichal Meloun reg = RD4(sc, CONTROL0);
2222d5e81fbSEmmanuel Vadot reg &= ~CONTROL0_TSEN_RESET;
2232d5e81fbSEmmanuel Vadot reg |= CONTROL0_TSEN_START | CONTROL0_TSEN_EN;
2242d5e81fbSEmmanuel Vadot
2252d5e81fbSEmmanuel Vadot /* Sample every ~2ms */
2262d5e81fbSEmmanuel Vadot reg |= CONTROL0_OSR_MAX << CONTROL0_OSR_SHIFT;
2272d5e81fbSEmmanuel Vadot
2284b84206bSMichal Meloun WR4(sc, CONTROL0, reg);
2292d5e81fbSEmmanuel Vadot
2302d5e81fbSEmmanuel Vadot /* Since we just started the module wait for the sensor to be ready */
2312d5e81fbSEmmanuel Vadot mv_thermal_wait_sensor(sc);
2322d5e81fbSEmmanuel Vadot
2332d5e81fbSEmmanuel Vadot return (0);
2342d5e81fbSEmmanuel Vadot }
2352d5e81fbSEmmanuel Vadot
2362d5e81fbSEmmanuel Vadot static int
cp110_init(struct mv_thermal_softc * sc)2372d5e81fbSEmmanuel Vadot cp110_init(struct mv_thermal_softc *sc)
2382d5e81fbSEmmanuel Vadot {
2392d5e81fbSEmmanuel Vadot uint32_t reg;
2402d5e81fbSEmmanuel Vadot
2414b84206bSMichal Meloun reg = RD4(sc, CONTROL1);
2422d5e81fbSEmmanuel Vadot reg &= (1 << 7);
2432d5e81fbSEmmanuel Vadot reg |= (1 << 8);
2444b84206bSMichal Meloun WR4(sc, CONTROL1, reg);
2452d5e81fbSEmmanuel Vadot
2462d5e81fbSEmmanuel Vadot /* Sample every ~2ms */
2474b84206bSMichal Meloun reg = RD4(sc, CONTROL0);
2482d5e81fbSEmmanuel Vadot reg |= CONTROL0_OSR_MAX << CONTROL0_OSR_SHIFT;
2494b84206bSMichal Meloun WR4(sc, CONTROL0, reg);
2502d5e81fbSEmmanuel Vadot
2512d5e81fbSEmmanuel Vadot return (0);
2522d5e81fbSEmmanuel Vadot }
2532d5e81fbSEmmanuel Vadot
2542d5e81fbSEmmanuel Vadot static int
mv_thermal_sysctl(SYSCTL_HANDLER_ARGS)2552d5e81fbSEmmanuel Vadot mv_thermal_sysctl(SYSCTL_HANDLER_ARGS)
2562d5e81fbSEmmanuel Vadot {
2572d5e81fbSEmmanuel Vadot struct mv_thermal_softc *sc;
2582d5e81fbSEmmanuel Vadot device_t dev = arg1;
2592d5e81fbSEmmanuel Vadot int sensor = arg2;
2602d5e81fbSEmmanuel Vadot int val = 0;
2612d5e81fbSEmmanuel Vadot
2622d5e81fbSEmmanuel Vadot sc = device_get_softc(dev);
2632d5e81fbSEmmanuel Vadot mtx_lock(&(sc)->mtx);
2642d5e81fbSEmmanuel Vadot
2652d5e81fbSEmmanuel Vadot if (mv_thermal_read_sensor(sc, sensor, &val) == 0) {
2662d5e81fbSEmmanuel Vadot /* Convert to Kelvin */
2672d5e81fbSEmmanuel Vadot val = val + 2732;
2682d5e81fbSEmmanuel Vadot } else {
2692d5e81fbSEmmanuel Vadot device_printf(dev, "Timeout waiting for sensor\n");
2702d5e81fbSEmmanuel Vadot }
2712d5e81fbSEmmanuel Vadot
2722d5e81fbSEmmanuel Vadot mtx_unlock(&(sc)->mtx);
2732d5e81fbSEmmanuel Vadot return sysctl_handle_opaque(oidp, &val, sizeof(val), req);
2742d5e81fbSEmmanuel Vadot }
2752d5e81fbSEmmanuel Vadot
2762d5e81fbSEmmanuel Vadot static int
mv_thermal_probe(device_t dev)2772d5e81fbSEmmanuel Vadot mv_thermal_probe(device_t dev)
2782d5e81fbSEmmanuel Vadot {
2792d5e81fbSEmmanuel Vadot
2802d5e81fbSEmmanuel Vadot if (!ofw_bus_status_okay(dev))
2812d5e81fbSEmmanuel Vadot return (ENXIO);
2822d5e81fbSEmmanuel Vadot
2832d5e81fbSEmmanuel Vadot if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
2842d5e81fbSEmmanuel Vadot return (ENXIO);
2852d5e81fbSEmmanuel Vadot
2862d5e81fbSEmmanuel Vadot device_set_desc(dev, "Marvell Thermal Sensor Controller");
2872d5e81fbSEmmanuel Vadot return (BUS_PROBE_DEFAULT);
2882d5e81fbSEmmanuel Vadot }
2892d5e81fbSEmmanuel Vadot
2902d5e81fbSEmmanuel Vadot static int
mv_thermal_attach(device_t dev)2912d5e81fbSEmmanuel Vadot mv_thermal_attach(device_t dev)
2922d5e81fbSEmmanuel Vadot {
2932d5e81fbSEmmanuel Vadot struct mv_thermal_softc *sc;
2942d5e81fbSEmmanuel Vadot struct sysctl_ctx_list *ctx;
2952d5e81fbSEmmanuel Vadot struct sysctl_oid_list *oid;
2962d5e81fbSEmmanuel Vadot char name[255];
2972d5e81fbSEmmanuel Vadot char desc[255];
2982d5e81fbSEmmanuel Vadot int i;
2992d5e81fbSEmmanuel Vadot
3002d5e81fbSEmmanuel Vadot sc = device_get_softc(dev);
3012d5e81fbSEmmanuel Vadot sc->dev = dev;
3022d5e81fbSEmmanuel Vadot
3034b84206bSMichal Meloun sc->config = (struct mv_thermal_config *)
3044b84206bSMichal Meloun ofw_bus_search_compatible(dev, compat_data)->ocd_data;
3052d5e81fbSEmmanuel Vadot
3062d5e81fbSEmmanuel Vadot mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF);
3072d5e81fbSEmmanuel Vadot
3084b84206bSMichal Meloun if (SYSCON_GET_HANDLE(sc->dev, &sc->syscon) != 0 ||
3094b84206bSMichal Meloun sc->syscon == NULL) {
3104b84206bSMichal Meloun device_printf(dev, "cannot get syscon for device\n");
3112d5e81fbSEmmanuel Vadot return (ENXIO);
3122d5e81fbSEmmanuel Vadot }
3132d5e81fbSEmmanuel Vadot
3142d5e81fbSEmmanuel Vadot sc->cur_sensor = -1;
3152d5e81fbSEmmanuel Vadot switch (sc->config->type) {
3162d5e81fbSEmmanuel Vadot case MV_AP806:
3172d5e81fbSEmmanuel Vadot ap806_init(sc);
3182d5e81fbSEmmanuel Vadot break;
3192d5e81fbSEmmanuel Vadot case MV_CP110:
3202d5e81fbSEmmanuel Vadot cp110_init(sc);
3212d5e81fbSEmmanuel Vadot break;
3222d5e81fbSEmmanuel Vadot }
3232d5e81fbSEmmanuel Vadot
3242d5e81fbSEmmanuel Vadot ctx = device_get_sysctl_ctx(dev);
3252d5e81fbSEmmanuel Vadot oid = SYSCTL_CHILDREN(device_get_sysctl_tree(dev));
3262d5e81fbSEmmanuel Vadot /* There is always at least one sensor */
3272d5e81fbSEmmanuel Vadot SYSCTL_ADD_PROC(ctx, oid, OID_AUTO, "internal",
3287029da5cSPawel Biernacki CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
3292d5e81fbSEmmanuel Vadot dev, 0, mv_thermal_sysctl,
3302d5e81fbSEmmanuel Vadot "IK",
3312d5e81fbSEmmanuel Vadot "Internal Temperature");
3322d5e81fbSEmmanuel Vadot
3332d5e81fbSEmmanuel Vadot for (i = 0; i < sc->config->ncpus; i++) {
3342d5e81fbSEmmanuel Vadot snprintf(name, sizeof(name), "cpu%d", i);
3352d5e81fbSEmmanuel Vadot snprintf(desc, sizeof(desc), "CPU%d Temperature", i);
3362d5e81fbSEmmanuel Vadot SYSCTL_ADD_PROC(ctx, oid, OID_AUTO, name,
3377029da5cSPawel Biernacki CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
3382d5e81fbSEmmanuel Vadot dev, i + 1, mv_thermal_sysctl,
3392d5e81fbSEmmanuel Vadot "IK",
3402d5e81fbSEmmanuel Vadot desc);
3412d5e81fbSEmmanuel Vadot }
3422d5e81fbSEmmanuel Vadot
3432d5e81fbSEmmanuel Vadot return (0);
3442d5e81fbSEmmanuel Vadot }
3452d5e81fbSEmmanuel Vadot
3462d5e81fbSEmmanuel Vadot static int
mv_thermal_detach(device_t dev)3472d5e81fbSEmmanuel Vadot mv_thermal_detach(device_t dev)
3482d5e81fbSEmmanuel Vadot {
3492d5e81fbSEmmanuel Vadot return (0);
3502d5e81fbSEmmanuel Vadot }
3512d5e81fbSEmmanuel Vadot
3522d5e81fbSEmmanuel Vadot static device_method_t mv_thermal_methods[] = {
3532d5e81fbSEmmanuel Vadot /* Device interface */
3542d5e81fbSEmmanuel Vadot DEVMETHOD(device_probe, mv_thermal_probe),
3552d5e81fbSEmmanuel Vadot DEVMETHOD(device_attach, mv_thermal_attach),
3562d5e81fbSEmmanuel Vadot DEVMETHOD(device_detach, mv_thermal_detach),
3572d5e81fbSEmmanuel Vadot
3582d5e81fbSEmmanuel Vadot DEVMETHOD_END
3592d5e81fbSEmmanuel Vadot };
3602d5e81fbSEmmanuel Vadot
3612d5e81fbSEmmanuel Vadot static driver_t mv_thermal_driver = {
3622d5e81fbSEmmanuel Vadot "mv_thermal",
3632d5e81fbSEmmanuel Vadot mv_thermal_methods,
3642d5e81fbSEmmanuel Vadot sizeof(struct mv_thermal_softc),
3652d5e81fbSEmmanuel Vadot };
3662d5e81fbSEmmanuel Vadot
367a3b866cbSJohn Baldwin DRIVER_MODULE(mv_thermal, simplebus, mv_thermal_driver, 0, 0);
368