12d5e81fbSEmmanuel Vadot /*- 22d5e81fbSEmmanuel Vadot * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 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 * $FreeBSD$ 282d5e81fbSEmmanuel Vadot */ 292d5e81fbSEmmanuel Vadot 302d5e81fbSEmmanuel Vadot #include <sys/cdefs.h> 312d5e81fbSEmmanuel Vadot __FBSDID("$FreeBSD$"); 322d5e81fbSEmmanuel Vadot 332d5e81fbSEmmanuel Vadot #include <sys/param.h> 342d5e81fbSEmmanuel Vadot #include <sys/systm.h> 352d5e81fbSEmmanuel Vadot #include <sys/bus.h> 362d5e81fbSEmmanuel Vadot 372d5e81fbSEmmanuel Vadot #include <sys/kernel.h> 382d5e81fbSEmmanuel Vadot #include <sys/module.h> 392d5e81fbSEmmanuel Vadot #include <sys/rman.h> 402d5e81fbSEmmanuel Vadot #include <sys/lock.h> 412d5e81fbSEmmanuel Vadot #include <sys/mutex.h> 422d5e81fbSEmmanuel Vadot #include <sys/sysctl.h> 432d5e81fbSEmmanuel Vadot 442d5e81fbSEmmanuel Vadot #include <machine/bus.h> 452d5e81fbSEmmanuel Vadot #include <machine/resource.h> 462d5e81fbSEmmanuel Vadot #include <machine/intr.h> 474b84206bSMichal Meloun #include <dev/extres/syscon/syscon.h> 482d5e81fbSEmmanuel Vadot 492d5e81fbSEmmanuel Vadot #include <dev/ofw/ofw_bus.h> 502d5e81fbSEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h> 512d5e81fbSEmmanuel Vadot 524b84206bSMichal Meloun #include "syscon_if.h" 534b84206bSMichal Meloun 544b84206bSMichal Meloun #define CONTROL0 0 /* Offset in config->regs[] array */ 552d5e81fbSEmmanuel Vadot #define CONTROL0_TSEN_START (1 << 0) 562d5e81fbSEmmanuel Vadot #define CONTROL0_TSEN_RESET (1 << 1) 572d5e81fbSEmmanuel Vadot #define CONTROL0_TSEN_EN (1 << 2) 582d5e81fbSEmmanuel Vadot #define CONTROL0_CHANNEL_SHIFT 13 592d5e81fbSEmmanuel Vadot #define CONTROL0_CHANNEL_MASK 0xF 602d5e81fbSEmmanuel Vadot #define CONTROL0_OSR_SHIFT 24 612d5e81fbSEmmanuel Vadot #define CONTROL0_OSR_MAX 3 /* OSR = 512 * 4uS = ~2mS */ 622d5e81fbSEmmanuel Vadot #define CONTROL0_MODE_SHIFT 30 632d5e81fbSEmmanuel Vadot #define CONTROL0_MODE_EXTERNAL 0x2 642d5e81fbSEmmanuel Vadot #define CONTROL0_MODE_MASK 0x3 652d5e81fbSEmmanuel Vadot 664b84206bSMichal Meloun #define CONTROL1 1 /* Offset in config->regs[] array */ 672d5e81fbSEmmanuel Vadot /* This doesn't seems to work */ 682d5e81fbSEmmanuel Vadot #define CONTROL1_TSEN_SENS_SHIFT 21 692d5e81fbSEmmanuel Vadot #define CONTROL1_TSEN_SENS_MASK 0x7 702d5e81fbSEmmanuel Vadot 714b84206bSMichal Meloun #define STATUS 2 /* Offset in config->regs[] array */ 722d5e81fbSEmmanuel Vadot #define STATUS_TEMP_MASK 0x3FF 732d5e81fbSEmmanuel Vadot 742d5e81fbSEmmanuel Vadot enum mv_thermal_type { 752d5e81fbSEmmanuel Vadot MV_AP806 = 1, 762d5e81fbSEmmanuel Vadot MV_CP110, 772d5e81fbSEmmanuel Vadot }; 782d5e81fbSEmmanuel Vadot 792d5e81fbSEmmanuel Vadot struct mv_thermal_config { 802d5e81fbSEmmanuel Vadot enum mv_thermal_type type; 814b84206bSMichal Meloun int regs[3]; 822d5e81fbSEmmanuel Vadot int ncpus; 832d5e81fbSEmmanuel Vadot int64_t calib_mul; 842d5e81fbSEmmanuel Vadot int64_t calib_add; 852d5e81fbSEmmanuel Vadot int64_t calib_div; 862d5e81fbSEmmanuel Vadot uint32_t valid_mask; 872d5e81fbSEmmanuel Vadot bool signed_value; 882d5e81fbSEmmanuel Vadot }; 892d5e81fbSEmmanuel Vadot 902d5e81fbSEmmanuel Vadot struct mv_thermal_softc { 912d5e81fbSEmmanuel Vadot device_t dev; 924b84206bSMichal Meloun struct syscon *syscon; 932d5e81fbSEmmanuel Vadot struct mtx mtx; 942d5e81fbSEmmanuel Vadot 952d5e81fbSEmmanuel Vadot struct mv_thermal_config *config; 962d5e81fbSEmmanuel Vadot int cur_sensor; 972d5e81fbSEmmanuel Vadot }; 982d5e81fbSEmmanuel Vadot 992d5e81fbSEmmanuel Vadot static struct mv_thermal_config mv_ap806_config = { 1002d5e81fbSEmmanuel Vadot .type = MV_AP806, 1014b84206bSMichal Meloun .regs = {0x84, 0x88, 0x8C}, 1022d5e81fbSEmmanuel Vadot .ncpus = 4, 1032d5e81fbSEmmanuel Vadot .calib_mul = 423, 1042d5e81fbSEmmanuel Vadot .calib_add = -150000, 1052d5e81fbSEmmanuel Vadot .calib_div = 100, 1062d5e81fbSEmmanuel Vadot .valid_mask = (1 << 16), 1072d5e81fbSEmmanuel Vadot .signed_value = true, 1082d5e81fbSEmmanuel Vadot }; 1092d5e81fbSEmmanuel Vadot 1102d5e81fbSEmmanuel Vadot static struct mv_thermal_config mv_cp110_config = { 1112d5e81fbSEmmanuel Vadot .type = MV_CP110, 1124b84206bSMichal Meloun .regs = {0x70, 0x74, 0x78}, 1132d5e81fbSEmmanuel Vadot .calib_mul = 2000096, 1142d5e81fbSEmmanuel Vadot .calib_add = 1172499100, 1152d5e81fbSEmmanuel Vadot .calib_div = 420100, 1162d5e81fbSEmmanuel Vadot .valid_mask = (1 << 10), 1172d5e81fbSEmmanuel Vadot .signed_value = false, 1182d5e81fbSEmmanuel Vadot }; 1192d5e81fbSEmmanuel Vadot 1202d5e81fbSEmmanuel Vadot static struct ofw_compat_data compat_data[] = { 1212d5e81fbSEmmanuel Vadot {"marvell,armada-ap806-thermal", (uintptr_t) &mv_ap806_config}, 1222d5e81fbSEmmanuel Vadot {"marvell,armada-cp110-thermal", (uintptr_t) &mv_cp110_config}, 1232d5e81fbSEmmanuel Vadot {NULL, 0} 1242d5e81fbSEmmanuel Vadot }; 1252d5e81fbSEmmanuel Vadot 1264b84206bSMichal Meloun #define RD4(sc, reg) \ 1274b84206bSMichal Meloun SYSCON_READ_4((sc)->syscon, sc->config->regs[reg]) 1284b84206bSMichal Meloun #define WR4(sc, reg, val) \ 1294b84206bSMichal Meloun SYSCON_WRITE_4((sc)->syscon, sc->config->regs[reg], (val)) 1302d5e81fbSEmmanuel Vadot 1312d5e81fbSEmmanuel Vadot static inline int32_t sign_extend(uint32_t value, int index) 1322d5e81fbSEmmanuel Vadot { 1332d5e81fbSEmmanuel Vadot uint8_t shift; 1342d5e81fbSEmmanuel Vadot 1352d5e81fbSEmmanuel Vadot shift = 31 - index; 1362d5e81fbSEmmanuel Vadot return ((int32_t)(value << shift) >> shift); 1372d5e81fbSEmmanuel Vadot } 1382d5e81fbSEmmanuel Vadot 1392d5e81fbSEmmanuel Vadot static int 1402d5e81fbSEmmanuel Vadot mv_thermal_wait_sensor(struct mv_thermal_softc *sc) 1412d5e81fbSEmmanuel Vadot { 1422d5e81fbSEmmanuel Vadot uint32_t reg; 1432d5e81fbSEmmanuel Vadot uint32_t timeout; 1442d5e81fbSEmmanuel Vadot 1452d5e81fbSEmmanuel Vadot timeout = 100000; 1462d5e81fbSEmmanuel Vadot while (--timeout > 0) { 1474b84206bSMichal Meloun reg = RD4(sc, STATUS); 1482d5e81fbSEmmanuel Vadot if ((reg & sc->config->valid_mask) == sc->config->valid_mask) 1492d5e81fbSEmmanuel Vadot break; 1502d5e81fbSEmmanuel Vadot DELAY(100); 1512d5e81fbSEmmanuel Vadot } 1522d5e81fbSEmmanuel Vadot if (timeout == 0) { 1532d5e81fbSEmmanuel Vadot return (ETIMEDOUT); 1542d5e81fbSEmmanuel Vadot } 1552d5e81fbSEmmanuel Vadot 1562d5e81fbSEmmanuel Vadot return (0); 1572d5e81fbSEmmanuel Vadot } 1582d5e81fbSEmmanuel Vadot 1592d5e81fbSEmmanuel Vadot static int 1602d5e81fbSEmmanuel Vadot mv_thermal_select_sensor(struct mv_thermal_softc *sc, int sensor) 1612d5e81fbSEmmanuel Vadot { 1622d5e81fbSEmmanuel Vadot uint32_t reg; 1632d5e81fbSEmmanuel Vadot 1642d5e81fbSEmmanuel Vadot if (sc->cur_sensor == sensor) 1652d5e81fbSEmmanuel Vadot return (0); 1662d5e81fbSEmmanuel Vadot 1672d5e81fbSEmmanuel Vadot /* Stop the current reading and reset the module */ 1684b84206bSMichal Meloun reg = RD4(sc, CONTROL0); 1692d5e81fbSEmmanuel Vadot reg &= ~(CONTROL0_TSEN_START | CONTROL0_TSEN_EN); 1704b84206bSMichal Meloun WR4(sc, CONTROL0, reg); 1712d5e81fbSEmmanuel Vadot 1722d5e81fbSEmmanuel Vadot /* Switch to the selected sensor */ 1732d5e81fbSEmmanuel Vadot /* 1742d5e81fbSEmmanuel Vadot * NOTE : Datasheet says to use CONTROL1 for selecting 1752d5e81fbSEmmanuel Vadot * but when doing so the sensors >0 are never ready 1762d5e81fbSEmmanuel Vadot * Do what Linux does using undocumented bits in CONTROL0 1772d5e81fbSEmmanuel Vadot */ 1782d5e81fbSEmmanuel Vadot /* This reset automatically to the sensor 0 */ 1792d5e81fbSEmmanuel Vadot reg &= ~(CONTROL0_MODE_MASK << CONTROL0_MODE_SHIFT); 1802d5e81fbSEmmanuel Vadot if (sensor) { 1812d5e81fbSEmmanuel Vadot /* Select external sensor */ 1822d5e81fbSEmmanuel Vadot reg |= CONTROL0_MODE_EXTERNAL << CONTROL0_MODE_SHIFT; 1832d5e81fbSEmmanuel Vadot reg &= ~(CONTROL0_CHANNEL_MASK << CONTROL0_CHANNEL_SHIFT); 1842d5e81fbSEmmanuel Vadot reg |= (sensor - 1) << CONTROL0_CHANNEL_SHIFT; 1852d5e81fbSEmmanuel Vadot } 1864b84206bSMichal Meloun WR4(sc, CONTROL0, reg); 1872d5e81fbSEmmanuel Vadot sc->cur_sensor = sensor; 1882d5e81fbSEmmanuel Vadot 1892d5e81fbSEmmanuel Vadot /* Start the reading */ 1904b84206bSMichal Meloun reg = RD4(sc, CONTROL0); 1912d5e81fbSEmmanuel Vadot reg |= CONTROL0_TSEN_START | CONTROL0_TSEN_EN; 1924b84206bSMichal Meloun WR4(sc, CONTROL0, reg); 1932d5e81fbSEmmanuel Vadot 1942d5e81fbSEmmanuel Vadot return (mv_thermal_wait_sensor(sc)); 1952d5e81fbSEmmanuel Vadot } 1962d5e81fbSEmmanuel Vadot 1972d5e81fbSEmmanuel Vadot static int 1982d5e81fbSEmmanuel Vadot mv_thermal_read_sensor(struct mv_thermal_softc *sc, int sensor, int *temp) 1992d5e81fbSEmmanuel Vadot { 2002d5e81fbSEmmanuel Vadot uint32_t reg; 2012d5e81fbSEmmanuel Vadot int64_t sample, rv; 2022d5e81fbSEmmanuel Vadot 2032d5e81fbSEmmanuel Vadot rv = mv_thermal_select_sensor(sc, sensor); 2042d5e81fbSEmmanuel Vadot if (rv != 0) 2052d5e81fbSEmmanuel Vadot return (rv); 2062d5e81fbSEmmanuel Vadot 2074b84206bSMichal Meloun reg = RD4(sc, STATUS) & STATUS_TEMP_MASK; 2082d5e81fbSEmmanuel Vadot 2092d5e81fbSEmmanuel Vadot if (sc->config->signed_value) 2102d5e81fbSEmmanuel Vadot sample = sign_extend(reg, fls(STATUS_TEMP_MASK) - 1); 2112d5e81fbSEmmanuel Vadot else 2122d5e81fbSEmmanuel Vadot sample = reg; 2132d5e81fbSEmmanuel Vadot 2142d5e81fbSEmmanuel Vadot *temp = ((sample * sc->config->calib_mul) - sc->config->calib_add) / 2152d5e81fbSEmmanuel Vadot sc->config->calib_div; 2162d5e81fbSEmmanuel Vadot 2172d5e81fbSEmmanuel Vadot return (0); 2182d5e81fbSEmmanuel Vadot } 2192d5e81fbSEmmanuel Vadot 2202d5e81fbSEmmanuel Vadot static int 2212d5e81fbSEmmanuel Vadot ap806_init(struct mv_thermal_softc *sc) 2222d5e81fbSEmmanuel Vadot { 2232d5e81fbSEmmanuel Vadot uint32_t reg; 2242d5e81fbSEmmanuel Vadot 2252d5e81fbSEmmanuel Vadot /* Start the temp capture/conversion */ 2264b84206bSMichal Meloun reg = RD4(sc, CONTROL0); 2272d5e81fbSEmmanuel Vadot reg &= ~CONTROL0_TSEN_RESET; 2282d5e81fbSEmmanuel Vadot reg |= CONTROL0_TSEN_START | CONTROL0_TSEN_EN; 2292d5e81fbSEmmanuel Vadot 2302d5e81fbSEmmanuel Vadot /* Sample every ~2ms */ 2312d5e81fbSEmmanuel Vadot reg |= CONTROL0_OSR_MAX << CONTROL0_OSR_SHIFT; 2322d5e81fbSEmmanuel Vadot 2334b84206bSMichal Meloun WR4(sc, CONTROL0, reg); 2342d5e81fbSEmmanuel Vadot 2352d5e81fbSEmmanuel Vadot /* Since we just started the module wait for the sensor to be ready */ 2362d5e81fbSEmmanuel Vadot mv_thermal_wait_sensor(sc); 2372d5e81fbSEmmanuel Vadot 2382d5e81fbSEmmanuel Vadot return (0); 2392d5e81fbSEmmanuel Vadot } 2402d5e81fbSEmmanuel Vadot 2412d5e81fbSEmmanuel Vadot static int 2422d5e81fbSEmmanuel Vadot cp110_init(struct mv_thermal_softc *sc) 2432d5e81fbSEmmanuel Vadot { 2442d5e81fbSEmmanuel Vadot uint32_t reg; 2452d5e81fbSEmmanuel Vadot 2464b84206bSMichal Meloun reg = RD4(sc, CONTROL1); 2472d5e81fbSEmmanuel Vadot reg &= (1 << 7); 2482d5e81fbSEmmanuel Vadot reg |= (1 << 8); 2494b84206bSMichal Meloun WR4(sc, CONTROL1, reg); 2502d5e81fbSEmmanuel Vadot 2512d5e81fbSEmmanuel Vadot /* Sample every ~2ms */ 2524b84206bSMichal Meloun reg = RD4(sc, CONTROL0); 2532d5e81fbSEmmanuel Vadot reg |= CONTROL0_OSR_MAX << CONTROL0_OSR_SHIFT; 2544b84206bSMichal Meloun WR4(sc, CONTROL0, reg); 2552d5e81fbSEmmanuel Vadot 2562d5e81fbSEmmanuel Vadot return (0); 2572d5e81fbSEmmanuel Vadot } 2582d5e81fbSEmmanuel Vadot 2592d5e81fbSEmmanuel Vadot static int 2602d5e81fbSEmmanuel Vadot mv_thermal_sysctl(SYSCTL_HANDLER_ARGS) 2612d5e81fbSEmmanuel Vadot { 2622d5e81fbSEmmanuel Vadot struct mv_thermal_softc *sc; 2632d5e81fbSEmmanuel Vadot device_t dev = arg1; 2642d5e81fbSEmmanuel Vadot int sensor = arg2; 2652d5e81fbSEmmanuel Vadot int val = 0; 2662d5e81fbSEmmanuel Vadot 2672d5e81fbSEmmanuel Vadot sc = device_get_softc(dev); 2682d5e81fbSEmmanuel Vadot mtx_lock(&(sc)->mtx); 2692d5e81fbSEmmanuel Vadot 2702d5e81fbSEmmanuel Vadot if (mv_thermal_read_sensor(sc, sensor, &val) == 0) { 2712d5e81fbSEmmanuel Vadot /* Convert to Kelvin */ 2722d5e81fbSEmmanuel Vadot val = val + 2732; 2732d5e81fbSEmmanuel Vadot } else { 2742d5e81fbSEmmanuel Vadot device_printf(dev, "Timeout waiting for sensor\n"); 2752d5e81fbSEmmanuel Vadot } 2762d5e81fbSEmmanuel Vadot 2772d5e81fbSEmmanuel Vadot mtx_unlock(&(sc)->mtx); 2782d5e81fbSEmmanuel Vadot return sysctl_handle_opaque(oidp, &val, sizeof(val), req); 2792d5e81fbSEmmanuel Vadot } 2802d5e81fbSEmmanuel Vadot 2812d5e81fbSEmmanuel Vadot static int 2822d5e81fbSEmmanuel Vadot mv_thermal_probe(device_t dev) 2832d5e81fbSEmmanuel Vadot { 2842d5e81fbSEmmanuel Vadot 2852d5e81fbSEmmanuel Vadot if (!ofw_bus_status_okay(dev)) 2862d5e81fbSEmmanuel Vadot return (ENXIO); 2872d5e81fbSEmmanuel Vadot 2882d5e81fbSEmmanuel Vadot if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) 2892d5e81fbSEmmanuel Vadot return (ENXIO); 2902d5e81fbSEmmanuel Vadot 2912d5e81fbSEmmanuel Vadot device_set_desc(dev, "Marvell Thermal Sensor Controller"); 2922d5e81fbSEmmanuel Vadot return (BUS_PROBE_DEFAULT); 2932d5e81fbSEmmanuel Vadot } 2942d5e81fbSEmmanuel Vadot 2952d5e81fbSEmmanuel Vadot static int 2962d5e81fbSEmmanuel Vadot mv_thermal_attach(device_t dev) 2972d5e81fbSEmmanuel Vadot { 2982d5e81fbSEmmanuel Vadot struct mv_thermal_softc *sc; 2992d5e81fbSEmmanuel Vadot struct sysctl_ctx_list *ctx; 3002d5e81fbSEmmanuel Vadot struct sysctl_oid_list *oid; 3014b84206bSMichal Meloun phandle_t node; 3022d5e81fbSEmmanuel Vadot char name[255]; 3032d5e81fbSEmmanuel Vadot char desc[255]; 3042d5e81fbSEmmanuel Vadot int i; 3052d5e81fbSEmmanuel Vadot 3062d5e81fbSEmmanuel Vadot sc = device_get_softc(dev); 3072d5e81fbSEmmanuel Vadot sc->dev = dev; 3084b84206bSMichal Meloun node = ofw_bus_get_node(dev); 3092d5e81fbSEmmanuel Vadot 3104b84206bSMichal Meloun sc->config = (struct mv_thermal_config *) 3114b84206bSMichal Meloun ofw_bus_search_compatible(dev, compat_data)->ocd_data; 3122d5e81fbSEmmanuel Vadot 3132d5e81fbSEmmanuel Vadot mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); 3142d5e81fbSEmmanuel Vadot 3154b84206bSMichal Meloun 3164b84206bSMichal Meloun if (SYSCON_GET_HANDLE(sc->dev, &sc->syscon) != 0 || 3174b84206bSMichal Meloun sc->syscon == NULL) { 3184b84206bSMichal Meloun device_printf(dev, "cannot get syscon for device\n"); 3192d5e81fbSEmmanuel Vadot return (ENXIO); 3202d5e81fbSEmmanuel Vadot } 3212d5e81fbSEmmanuel Vadot 3222d5e81fbSEmmanuel Vadot sc->cur_sensor = -1; 3232d5e81fbSEmmanuel Vadot switch (sc->config->type) { 3242d5e81fbSEmmanuel Vadot case MV_AP806: 3252d5e81fbSEmmanuel Vadot ap806_init(sc); 3262d5e81fbSEmmanuel Vadot break; 3272d5e81fbSEmmanuel Vadot case MV_CP110: 3282d5e81fbSEmmanuel Vadot cp110_init(sc); 3292d5e81fbSEmmanuel Vadot break; 3302d5e81fbSEmmanuel Vadot } 3312d5e81fbSEmmanuel Vadot 3322d5e81fbSEmmanuel Vadot ctx = device_get_sysctl_ctx(dev); 3332d5e81fbSEmmanuel Vadot oid = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); 3342d5e81fbSEmmanuel Vadot /* There is always at least one sensor */ 3352d5e81fbSEmmanuel Vadot SYSCTL_ADD_PROC(ctx, oid, OID_AUTO, "internal", 336*7029da5cSPawel Biernacki CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, 3372d5e81fbSEmmanuel Vadot dev, 0, mv_thermal_sysctl, 3382d5e81fbSEmmanuel Vadot "IK", 3392d5e81fbSEmmanuel Vadot "Internal Temperature"); 3402d5e81fbSEmmanuel Vadot 3412d5e81fbSEmmanuel Vadot for (i = 0; i < sc->config->ncpus; i++) { 3422d5e81fbSEmmanuel Vadot snprintf(name, sizeof(name), "cpu%d", i); 3432d5e81fbSEmmanuel Vadot snprintf(desc, sizeof(desc), "CPU%d Temperature", i); 3442d5e81fbSEmmanuel Vadot SYSCTL_ADD_PROC(ctx, oid, OID_AUTO, name, 345*7029da5cSPawel Biernacki CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, 3462d5e81fbSEmmanuel Vadot dev, i + 1, mv_thermal_sysctl, 3472d5e81fbSEmmanuel Vadot "IK", 3482d5e81fbSEmmanuel Vadot desc); 3492d5e81fbSEmmanuel Vadot } 3502d5e81fbSEmmanuel Vadot 3512d5e81fbSEmmanuel Vadot return (0); 3522d5e81fbSEmmanuel Vadot } 3532d5e81fbSEmmanuel Vadot 3542d5e81fbSEmmanuel Vadot static int 3552d5e81fbSEmmanuel Vadot mv_thermal_detach(device_t dev) 3562d5e81fbSEmmanuel Vadot { 3572d5e81fbSEmmanuel Vadot struct mv_thermal_softc *sc; 3582d5e81fbSEmmanuel Vadot 3592d5e81fbSEmmanuel Vadot sc = device_get_softc(dev); 3602d5e81fbSEmmanuel Vadot 3612d5e81fbSEmmanuel Vadot return (0); 3622d5e81fbSEmmanuel Vadot } 3632d5e81fbSEmmanuel Vadot 3642d5e81fbSEmmanuel Vadot static device_method_t mv_thermal_methods[] = { 3652d5e81fbSEmmanuel Vadot /* Device interface */ 3662d5e81fbSEmmanuel Vadot DEVMETHOD(device_probe, mv_thermal_probe), 3672d5e81fbSEmmanuel Vadot DEVMETHOD(device_attach, mv_thermal_attach), 3682d5e81fbSEmmanuel Vadot DEVMETHOD(device_detach, mv_thermal_detach), 3692d5e81fbSEmmanuel Vadot 3702d5e81fbSEmmanuel Vadot DEVMETHOD_END 3712d5e81fbSEmmanuel Vadot }; 3722d5e81fbSEmmanuel Vadot 3732d5e81fbSEmmanuel Vadot static devclass_t mv_thermal_devclass; 3742d5e81fbSEmmanuel Vadot 3752d5e81fbSEmmanuel Vadot static driver_t mv_thermal_driver = { 3762d5e81fbSEmmanuel Vadot "mv_thermal", 3772d5e81fbSEmmanuel Vadot mv_thermal_methods, 3782d5e81fbSEmmanuel Vadot sizeof(struct mv_thermal_softc), 3792d5e81fbSEmmanuel Vadot }; 3802d5e81fbSEmmanuel Vadot 3812d5e81fbSEmmanuel Vadot DRIVER_MODULE(mv_thermal, simplebus, mv_thermal_driver, 3822d5e81fbSEmmanuel Vadot mv_thermal_devclass, 0, 0); 383