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

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/bus.h>
32 #include <sys/kernel.h>
33 #include <sys/lock.h>
34 #include <sys/module.h>
35 #include <sys/mutex.h>
36 #include <sys/rman.h>
53 #include <dev/syscon/syscon.h>
57 static uint32_t simple_mfd_syscon_read_4(struct syscon *syscon,
59 static int simple_mfd_syscon_write_4(struct syscon *syscon, bus_size_t offset,
61 static int simple_mfd_syscon_modify_4(struct syscon *syscon, bus_size_t offset,
64 #define SYSCON_LOCK(_sc) mtx_lock_spin(&(_sc)->mtx)
65 #define SYSCON_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->mtx)
66 #define SYSCON_LOCK_INIT(_sc) mtx_init(&(_sc)->mtx, \
67 device_get_nameunit((_sc)->dev), "syscon", MTX_SPIN)
68 #define SYSCON_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx);
69 #define SYSCON_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED);
70 #define SYSCON_ASSERT_UNLOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_NOTOWNED);
83 simple_mfd_syscon_read_4(struct syscon *syscon, bus_size_t offset) in simple_mfd_syscon_read_4() argument
88 sc = device_get_softc(syscon->pdev); in simple_mfd_syscon_read_4()
90 val = bus_read_4(sc->mem_res, offset); in simple_mfd_syscon_read_4()
95 simple_mfd_syscon_write_4(struct syscon *syscon, bus_size_t offset, in simple_mfd_syscon_write_4() argument
100 sc = device_get_softc(syscon->pdev); in simple_mfd_syscon_write_4()
102 bus_write_4(sc->mem_res, offset, val); in simple_mfd_syscon_write_4()
107 simple_mfd_syscon_modify_4(struct syscon *syscon, bus_size_t offset, in simple_mfd_syscon_modify_4() argument
113 sc = device_get_softc(syscon->pdev); in simple_mfd_syscon_modify_4()
115 val = bus_read_4(sc->mem_res, offset); in simple_mfd_syscon_modify_4()
118 bus_write_4(sc->mem_res, offset, val); in simple_mfd_syscon_modify_4()
123 simple_mfd_syscon_get_handle(device_t dev, struct syscon **syscon) in simple_mfd_syscon_get_handle() argument
128 *syscon = sc->syscon; in simple_mfd_syscon_get_handle()
129 if (*syscon == NULL) in simple_mfd_syscon_get_handle()
158 if (!ofw_bus_is_compatible(dev, "simple-mfd")) in simple_mfd_probe()
161 device_set_desc(dev, "Simple MFD (Multi-Functions Device)"); in simple_mfd_probe()
176 sc->dev = dev; in simple_mfd_attach()
179 /* Parse address-cells and size-cells from the parent node as a fallback */ in simple_mfd_attach()
180 if (OF_getencprop(node, "#address-cells", &sc->sc.acells, in simple_mfd_attach()
181 sizeof(sc->sc.acells)) == -1) { in simple_mfd_attach()
182 if (OF_getencprop(OF_parent(node), "#address-cells", &sc->sc.acells, in simple_mfd_attach()
183 sizeof(sc->sc.acells)) == -1) { in simple_mfd_attach()
184 sc->sc.acells = 2; in simple_mfd_attach()
187 if (OF_getencprop(node, "#size-cells", &sc->sc.scells, in simple_mfd_attach()
188 sizeof(sc->sc.scells)) == -1) { in simple_mfd_attach()
189 if (OF_getencprop(OF_parent(node), "#size-cells", &sc->sc.scells, in simple_mfd_attach()
190 sizeof(sc->sc.scells)) == -1) { in simple_mfd_attach()
191 sc->sc.scells = 1; in simple_mfd_attach()
197 if (simplebus_fill_ranges(node, &sc->sc) < 0) { in simple_mfd_attach()
205 (void)simple_mfd_add_device(dev, child, 0, NULL, -1, NULL); in simple_mfd_attach()
208 if (ofw_bus_is_compatible(dev, "syscon")) { in simple_mfd_attach()
209 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in simple_mfd_attach()
211 if (sc->mem_res == NULL) { in simple_mfd_attach()
218 sc->syscon = syscon_create_ofw_node(dev, in simple_mfd_attach()
220 if (sc->syscon == NULL) { in simple_mfd_attach()
222 "Failed to create/register syscon\n"); in simple_mfd_attach()
236 if (ofw_bus_is_compatible(dev, "syscon")) { in simple_mfd_detach()
237 if (sc->syscon != NULL) { in simple_mfd_detach()
238 syscon_unregister(sc->syscon); in simple_mfd_detach()
239 free(sc->syscon, M_SYSCON); in simple_mfd_detach()
244 if (sc->mem_res != NULL) in simple_mfd_detach()
246 sc->mem_res); in simple_mfd_detach()
263 if (ofw_bus_gen_setup_devinfo(&ndi->obdinfo, node) != 0) { in simple_mfd_setup_dinfo()
270 resource_list_init(&ndi->rl); in simple_mfd_setup_dinfo()
271 ofw_bus_reg_to_rl(dev, OF_parent(node), sc->acells, sc->scells, &ndi->rl); in simple_mfd_setup_dinfo()
272 ofw_bus_intr_to_rl(dev, node, &ndi->rl, NULL); in simple_mfd_setup_dinfo()
289 ndi->obdinfo.obd_name); in simple_mfd_add_device()
290 resource_list_free(&ndi->rl); in simple_mfd_add_device()
291 ofw_bus_gen_destroy_devinfo(&ndi->obdinfo); in simple_mfd_add_device()
302 /* syscon interface */