The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm/mv/mv_ts.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2012 Hiroki Sato <hrs@FreeBSD.org>
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  *
   26  * Driver for on-die thermal sensor in 88F6282 and 88F6283.
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __FBSDID("$FreeBSD: releng/11.1/sys/arm/mv/mv_ts.c 300421 2016-05-22 13:58:32Z loos $");
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/kernel.h>
   35 #include <sys/module.h>
   36 #include <sys/bus.h>
   37 #include <sys/sysctl.h>
   38 
   39 #include <dev/fdt/fdt_common.h>
   40 #include <dev/ofw/ofw_bus.h>
   41 #include <dev/ofw/ofw_bus_subr.h>
   42 
   43 #include <arm/mv/mvreg.h>
   44 #include <arm/mv/mvvar.h>
   45 
   46 static struct resource_spec mvts_res[] = {
   47         { SYS_RES_MEMORY,       0,      RF_ACTIVE },
   48         { -1, 0 }
   49 };
   50 
   51 struct mvts_softc {
   52         device_t                sc_dev;
   53         struct resource         *sc_res[sizeof(mvts_res)];
   54 };
   55 
   56 static int
   57 ts_probe(device_t dev)
   58 {
   59         uint32_t d, r;
   60 
   61         if (!ofw_bus_status_okay(dev))
   62                 return (ENXIO);
   63 
   64         if (!ofw_bus_is_compatible(dev, "mrvl,ts"))
   65                 return (ENXIO);
   66         soc_id(&d, &r);
   67         switch (d) {
   68         case MV_DEV_88F6282:
   69                 break;
   70         default:
   71                 device_printf(dev, "unsupported SoC (ID: 0x%08X)!\n", d);
   72                 return (ENXIO);
   73         }
   74         device_set_desc(dev, "Marvell Thermal Sensor");
   75 
   76         return (0);
   77 }
   78 
   79 #define MV_TEMP_VALID_BIT       (1 << 9)
   80 #define MV_TEMP_SENS_OFFS       10
   81 #define MV_TEMP_SENS_MASK       0x1ff
   82 #define MV_TEMP_SENS_READ_MAX   16
   83 #define TZ_ZEROC                2731
   84 #define MV_TEMP_CONVERT(x)      ((((322 - x) * 100000) / 13625) + TZ_ZEROC)
   85 
   86 /*
   87  * MSB                                 LSB
   88  * 0000 0000 0000 0000 0000 0000 0000 0000
   89  *                             ^- valid bit
   90  *                  |---------|
   91  *                         ^--- temperature (9 bits)
   92  */
   93 
   94 static int
   95 ts_sysctl_handler(SYSCTL_HANDLER_ARGS)
   96 {
   97         struct mvts_softc *sc;
   98         device_t dev;
   99         uint32_t ret, ret0;
  100         u_int val;
  101         int i;
  102 
  103         dev = (device_t)arg1;
  104         sc = device_get_softc(dev);
  105         val = TZ_ZEROC;
  106 
  107         ret = bus_read_4(sc->sc_res[0], 0);
  108         if ((ret & MV_TEMP_VALID_BIT) == 0) {
  109                 device_printf(dev, "temperature sensor is broken.\n");
  110                 goto ts_sysctl_handle_int;
  111         }
  112         ret0 = 0;
  113         for (i = 0; i < MV_TEMP_SENS_READ_MAX; i++) {
  114                 ret = bus_read_4(sc->sc_res[0], 0);
  115                 ret = (ret >> MV_TEMP_SENS_OFFS) & MV_TEMP_SENS_MASK;
  116 
  117                 /*
  118                  * Successive reads should returns the same value except
  119                  * for the LSB when the sensor is normal.
  120                  */
  121                 if (((ret0 ^ ret) & 0x1fe) == 0)
  122                         break;
  123                 else
  124                         ret0 = ret;
  125         }
  126         if (i == MV_TEMP_SENS_READ_MAX) {
  127                 device_printf(dev, "temperature sensor is unstable.\n");
  128                 goto ts_sysctl_handle_int;
  129         }
  130         val = (u_int)MV_TEMP_CONVERT(ret);
  131 
  132 ts_sysctl_handle_int:
  133         return (sysctl_handle_int(oidp, &val, 0, req));
  134 }
  135 
  136 static int
  137 ts_attach(device_t dev)
  138 {
  139         struct mvts_softc *sc;
  140         struct sysctl_ctx_list *ctx;
  141         int error;
  142 
  143         sc = device_get_softc(dev);
  144         sc->sc_dev = dev;
  145         error = bus_alloc_resources(dev, mvts_res, sc->sc_res);
  146         if (error) {
  147                 device_printf(dev, "could not allocate resources\n");
  148                 return (ENXIO);
  149         }
  150         ctx = device_get_sysctl_ctx(dev);
  151         SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
  152             OID_AUTO, "temperature", CTLTYPE_INT | CTLFLAG_RD, dev,
  153             0, ts_sysctl_handler, "IK", "Current Temperature");
  154 
  155         return (0);
  156 }
  157 
  158 static int
  159 ts_detach(device_t dev)
  160 {
  161 
  162         return (0);
  163 }
  164 
  165 static device_method_t ts_methods[] = {
  166         DEVMETHOD(device_probe,         ts_probe),
  167         DEVMETHOD(device_attach,        ts_attach),
  168         DEVMETHOD(device_detach,        ts_detach),
  169         {0, 0},
  170 };
  171 
  172 static driver_t ts_driver = {
  173         "mvts",
  174         ts_methods,
  175         sizeof(struct mvts_softc),
  176 };
  177 
  178 static devclass_t ts_devclass;
  179 DRIVER_MODULE(mvts, simplebus, ts_driver, ts_devclass, 0, 0);
  180 MODULE_VERSION(mvts, 1);

Cache object: 91ebb5e7d19206bde589ee322cfbdae4


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.