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/mips/mediatek/mtk_reset.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) 2016 Stanislav Galabov
    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  *    without modification, immediately at the beginning of the file.
   11  * 2. The name of the author may not be used to endorse or promote products
   12  *    derived from this software without specific prior written permission.
   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 FOR
   18  * 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  */
   27 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: stable/12/sys/mips/mediatek/mtk_reset.c 297667 2016-04-07 11:08:50Z sgalabov $");
   30 
   31 #include <sys/param.h>
   32 #include <sys/kernel.h>
   33 #include <sys/bus.h>
   34 #include <sys/module.h>
   35 
   36 #include <dev/fdt/fdt_common.h>
   37 #include <dev/ofw/openfirm.h>
   38 #include <dev/ofw/ofw_bus.h>
   39 #include <dev/ofw/ofw_bus_subr.h>
   40 
   41 #include <mips/mediatek/fdt_reset.h>
   42 #include <mips/mediatek/mtk_sysctl.h>
   43 
   44 #include "fdt_reset_if.h"
   45 
   46 static const struct ofw_compat_data compat_data[] = {
   47         { "ralink,rt2880-reset",        1 },
   48 
   49         /* Sentinel */
   50         { NULL,                         0 }
   51 };
   52 
   53 static int
   54 mtk_reset_probe(device_t dev)
   55 {
   56 
   57         if (!ofw_bus_status_okay(dev))
   58                 return (ENXIO);
   59 
   60         if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
   61                 return (ENXIO);
   62 
   63         device_set_desc(dev, "MTK Reset Controller");
   64 
   65         return (0);
   66 }
   67 
   68 static int
   69 mtk_reset_attach(device_t dev)
   70 {
   71 
   72         if (device_get_unit(dev) != 0) {
   73                 device_printf(dev, "Only one reset control allowed\n");
   74                 return (ENXIO);
   75         }
   76 
   77         fdt_reset_register_provider(dev);
   78 
   79         return (0);
   80 }
   81 
   82 #define RESET_ASSERT    1
   83 #define RESET_DEASSERT  0
   84 
   85 static int
   86 mtk_reset_set(device_t dev, int index, int value)
   87 {
   88         uint32_t mask;
   89 
   90         /* index 0 is SoC reset, indices 1 - 31 are valid peripheral resets */
   91         if (index < 1 || index > 31)
   92                 return (EINVAL);
   93 
   94         mask = (1u << index);
   95 
   96         if (value == RESET_ASSERT)
   97                 mtk_sysctl_clr_set(SYSCTL_RSTCTRL, 0, mask);
   98         else
   99                 mtk_sysctl_clr_set(SYSCTL_RSTCTRL, mask, 0);
  100 
  101         return (0);
  102 }
  103 
  104 static int
  105 mtk_reset_assert(device_t dev, int index)
  106 {
  107 
  108         return mtk_reset_set(dev, index, RESET_ASSERT);
  109 }
  110 
  111 static int
  112 mtk_reset_deassert(device_t dev, int index)
  113 {
  114 
  115         return mtk_reset_set(dev, index, RESET_DEASSERT);
  116 }
  117 
  118 static device_method_t mtk_reset_methods[] = {
  119         DEVMETHOD(device_probe,         mtk_reset_probe),
  120         DEVMETHOD(device_attach,        mtk_reset_attach),
  121 
  122         /* fdt_reset interface */
  123         DEVMETHOD(fdt_reset_assert,     mtk_reset_assert),
  124         DEVMETHOD(fdt_reset_deassert,   mtk_reset_deassert),
  125 
  126         DEVMETHOD_END
  127 };
  128 
  129 static driver_t mtk_reset_driver = {
  130         "rstctrl",
  131         mtk_reset_methods,
  132         0,
  133 };
  134 static devclass_t mtk_reset_devclass;
  135 
  136 EARLY_DRIVER_MODULE(mtk_reset, simplebus, mtk_reset_driver, mtk_reset_devclass,
  137     0, 0, BUS_PASS_INTERRUPT + BUS_PASS_ORDER_EARLY);
  138 
  139 MODULE_DEPEND(mtk_reset, mtk_sysctl, 1, 1, 1);

Cache object: 0b1cb06423c17eabea664e290129dbb1


[ 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.