Lines Matching +full:sys +full:- +full:syscon

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
30 * This is a generic syscon driver, whose purpose is to provide access to
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/bus.h>
39 #include <sys/kernel.h>
40 #include <sys/lock.h>
41 #include <sys/module.h>
42 #include <sys/mutex.h>
43 #include <sys/rman.h>
51 #include "syscon.h"
56 static uint32_t syscon_generic_unlocked_read_4(struct syscon *syscon,
58 static int syscon_generic_unlocked_write_4(struct syscon *syscon,
60 static int syscon_generic_unlocked_modify_4(struct syscon *syscon,
64 * Generic syscon driver (FDT)
67 {"syscon", 1},
71 #define SYSCON_LOCK(_sc) mtx_lock_spin(&(_sc)->mtx)
72 #define SYSCON_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->mtx)
73 #define SYSCON_LOCK_INIT(_sc) mtx_init(&(_sc)->mtx, \
74 device_get_nameunit((_sc)->dev), "syscon", MTX_SPIN)
75 #define SYSCON_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx);
76 #define SYSCON_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED);
77 #define SYSCON_ASSERT_UNLOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_NOTOWNED);
90 syscon_generic_unlocked_read_4(struct syscon *syscon, bus_size_t offset)
95 sc = device_get_softc(syscon->pdev);
97 val = bus_read_4(sc->mem_res, offset);
102 syscon_generic_unlocked_write_4(struct syscon *syscon, bus_size_t offset, uint32_t val)
106 sc = device_get_softc(syscon->pdev);
108 bus_write_4(sc->mem_res, offset, val);
113 syscon_generic_unlocked_modify_4(struct syscon *syscon, bus_size_t offset,
119 sc = device_get_softc(syscon->pdev);
121 val = bus_read_4(sc->mem_res, offset);
124 bus_write_4(sc->mem_res, offset, val);
152 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
155 device_set_desc(dev, "syscon");
169 sc->dev = dev;
172 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
174 if (sc->mem_res == NULL) {
180 sc->syscon = syscon_create_ofw_node(dev, &syscon_generic_class,
182 if (sc->syscon == NULL) {
183 device_printf(dev, "Failed to create/register syscon\n");
187 if (ofw_bus_is_compatible(dev, "simple-bus")) {
188 rv = simplebus_attach_impl(sc->dev);
194 sc->simplebus_attached = true;
207 if (sc->syscon != NULL) {
208 syscon_unregister(sc->syscon);
209 free(sc->syscon, M_SYSCON);
211 if (sc->simplebus_attached)
215 if (sc->mem_res != NULL)
216 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res);